#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
extern long F7228_FreeMemory();
extern void F1956_EndProgram();
extern void F7317_MAIN_CopyBytes_Alt();
extern void F1966_DebugEnter();
extern void F1967_DebugExit();
extern unsigned char** F7227_RequestMemoryHandle();
extern unsigned char* F7229_();


unsigned char* G3680_[100];
unsigned char* G3679_apuc_AllocatedMemoryBlocks[100];
int16_t G3678_i_AllocatedMemoryBlockCount;
#ifdef MEDIA772_SU1E
int16_t G3681_ = 20;
#endif
#ifdef MEDIA763_AU1E_AU2E
int16_t G3681_ = 50;
#endif


long F1886_Memory(int16_t P5692_, int16_t P5693_, ...) {
        long L5553_;
        long L5741_l_Unreferenced;
        int16_t L5554_;
        int16_t L5744_i_Unreferenced;
        char* L5555_;


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(15, P5693_);
#endif
        switch (P5693_) {
                case C01_INITIALIZE:
                        G3678_i_AllocatedMemoryBlockCount = 0;
                        for (L5554_ = 0; L5554_ < 100; L5554_++) {
                                G3679_apuc_AllocatedMemoryBlocks[L5554_] = NULL;
                                G3680_[L5554_] = NULL;
                        }
                        F1824_AllocateMemoryHeap(100, 50);
                        break;
                case C02_UNINITIALIZE:
                        F1825_FreeMemoryHeap();
                        break;
                case C13_GET_BLOCK_COUNT:
                        L5553_ = G3678_i_AllocatedMemoryBlockCount;
                        break;
                case C16_ALLOCATE_AND_INITIALIZE:
                case C14_ALLOCATE:
                        if (*(long*)(&P5693_ + 1) > 65535) {
                                F1956_EndProgram(P5692_, 18, 44L);
                        }
#ifdef MEDIA772_SU1E
                        L5555_ = (char*)F7227_RequestMemoryHandle(*(long*)(&P5693_ + 1), MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5741_l_Unreferenced = F1886_Memory(P5692_, 25);
                        L5555_ = (char*)F7227_RequestMemoryHandle(*(long*)(&P5693_ + 1), (int16_t)L5741_l_Unreferenced);
#endif
                        if ((L5555_ == NULL) != 0) {
                                F1956_EndProgram(P5692_, 18, 45L);
                        }
                        L5553_ = (long)F7229_(L5555_);
                        G3679_apuc_AllocatedMemoryBlocks[G3678_i_AllocatedMemoryBlockCount] = (unsigned char*)L5553_;
                        G3680_[G3678_i_AllocatedMemoryBlockCount] = L5555_;
                        G3678_i_AllocatedMemoryBlockCount++;
                        if (G3678_i_AllocatedMemoryBlockCount > G3681_) {
#ifdef MEDIA772_SU1E
                                G3681_ += 4;
#endif
#ifdef MEDIA763_AU1E_AU2E
                                G3681_ += 5;
#endif
                        }
                        if (G3678_i_AllocatedMemoryBlockCount > 100) {
                                F1956_EndProgram(P5692_, 18, 98L);
                        }
                        break;
                case C20_FREE:
                        L5555_ = NULL;
                        for (L5554_ = 0; L5554_ < G3678_i_AllocatedMemoryBlockCount; L5554_++) {
                                if ((*(unsigned char**)(&P5693_ + 1)) != G3679_apuc_AllocatedMemoryBlocks[L5554_]) {
                                        continue;
                                }
                                L5555_ = G3680_[L5554_];
                                G3678_i_AllocatedMemoryBlockCount--;
                                if (L5554_ < G3678_i_AllocatedMemoryBlockCount) {
                                        G3679_apuc_AllocatedMemoryBlocks[L5554_] = G3679_apuc_AllocatedMemoryBlocks[G3678_i_AllocatedMemoryBlockCount];
                                        G3680_[L5554_] = G3680_[G3678_i_AllocatedMemoryBlockCount];
                                }
                                G3679_apuc_AllocatedMemoryBlocks[G3678_i_AllocatedMemoryBlockCount] = NULL;
                                G3680_[G3678_i_AllocatedMemoryBlockCount] = NULL;
                        }
                        if (L5555_ == 0) {
                                F1956_EndProgram(P5692_, 18, 97L);
                        }
                        F7230_(L5555_);
                        F7228_FreeMemory(L5555_);
                        break;
#ifdef MEDIA763_AU1E_AU2E
                case 25:
                        switch (P5692_) {
                                case 8:
                                        L5553_ = 0x10;
                                        break;
                                case 6:
                                        L5553_ = 0x08;
                                        break;
                                case 22:
                                        L5553_ = 0x20;
                                        break;
                                case 20:
                                        L5553_ = 0x80;
                                        break;
                                default:
                                        L5553_ = 0x400;
                        }
                        break;
#endif
                case C26_COPY_BYTES:
                        F7317_MAIN_CopyBytes_Alt((*(char**)(&P5693_ + 1)), (*(char**)(&P5693_ + 3)), 0, 0, (*(long*)(&P5693_ + 5)));
                        break;
                default:
                        F1956_EndProgram(P5692_, 18, 47L);
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(15, P5693_);
#endif
        return L5553_;
}
#endif
