array<integer> C_nextFree112
integer C_firstFree137
integer C_maxIndex160
array<integer> C_typeId114


integer C_firstFree137 = 0
integer C_maxIndex160 = 0


function initGlobals129() { 
    C_firstFree_137 = 0;
    C_maxIndex_160 = 0;
}


function main946() { 
    initGlobals129();
    init_test333();
}


function config135() { 
}


function init_test333() { 
    local array<integer> cs328
    local integer i164
    local integer j153
    local integer k160
    i_164 = 0;
    loop {
        exitwhen (i_164 > 6000);
        cs_328[i_164] = new_C799();
        i_164 = (i_164 + 1);
    };
    j_153 = 0;
    loop {
        exitwhen (j_153 > 6000);
        dispatch_C_destroyC414(cs_328[j_153]);
        j_153 = (j_153 + 1);
    };
    k_160 = 0;
    loop {
        exitwhen (k_160 > 6000);
        cs_328[k_160] = new_C799();
        k_160 = (k_160 + 1);
    };
    if ((cs_328[6000] castTo integer) <= 6001) {
        testSuccess990();
    } else {
    };
}


IS_NATIVE function testSuccess990() { 
}


function C_init169(integer this110) { 
}


function new_C799() returns integer { 
    local integer this152
    this_152 = alloc_C405();
    construct_C165(this_152);
    return this_152;
}


function construct_C165(integer this840) { 
    C_init169(this_840);
}


function C_onDestroy179(integer this171) { 
}


function destroyC489(integer this197) { 
    C_onDestroy179(this_197);
    dealloc_C142(this_197);
}


function alloc_C405() returns integer { 
    local integer this410
    if (C_firstFree_137 == 0) {
        if (C_maxIndex_160 < 32768) {
            C_maxIndex_160 = (C_maxIndex_160 + 1);
            this_410 = C_maxIndex_160;
            C_typeId_114[this_410] = 1;
        } else {
            error203("Out of memory: Could not create C.");
            this_410 = 0;
        };
    } else {
        C_firstFree_137 = (C_firstFree_137 - 1);
        this_410 = C_nextFree_112[C_firstFree_137];
        C_typeId_114[this_410] = 1;
    };
    return this_410;
}


function error203(string msg622) { 
    $debugPrint198((msg_622 + ("
" + #getStackTrace())));
}


function dealloc_C142(integer obj205) { 
    if (C_typeId_114[obj_205] == 0) {
        error203("Double free: object of type C");
    } else {
        C_nextFree_112[C_firstFree_137] = obj_205;
        C_firstFree_137 = (C_firstFree_137 + 1);
        C_typeId_114[obj_205] = 0;
    };
}


function dispatch_C_destroyC414(integer this585) { 
    if (C_typeId_114[this_585] == 0) {
        if (this_585 == 0) {
            error203("Nullpointer exception when calling C.C");
        } else {
            error203("Called C.C on invalid object.");
        };
    } else {
    };
    destroyC489(this_585);
}