array<integer> A_nextFree675
integer A_firstFree550
integer A_maxIndex441
array<integer> A_typeId198
array<integer> D_c188


integer A_firstFree550 = 0
integer A_maxIndex441 = 0


function initGlobals196() { 
    A_firstFree_550 = 0;
    A_maxIndex_441 = 0;
}


function main111() { 
    initGlobals196();
    init_Test932();
}


function config171() { 
}


function init_Test932() { 
    local integer d107
    d_107 = new_D668(0);
    dispatch_D_destroyD467(d_107);
}


IS_NATIVE function testSuccess152() { 
}


function A_init189(integer this648) { 
}


function construct_A212(integer this678) { 
    A_init189(this_678);
}


function A_onDestroy253(integer this878) { 
}


function B_init129(integer this357) { 
}


function construct_B380(integer this178) { 
    construct_A212(this_178);
    B_init129(this_178);
}


function B_onDestroy154(integer this206) { 
    A_onDestroy253(this_206);
}


function C_init304(integer this829) { 
}


function construct_C118(integer this104) { 
    construct_B380(this_104);
    C_init304(this_104);
}


function C_onDestroy507(integer this136) { 
    testSuccess152();
    B_onDestroy154(this_136);
}


function destroyD194(integer this397) { 
    D_onDestroy690(this_397);
    dealloc_D856(this_397);
}


function D_init635(integer this157) { 
}


function new_D668(integer i996) returns integer { 
    local integer this167
    this_167 = alloc_D770();
    construct_D851(this_167, i_996);
    return this_167;
}


function construct_D851(integer this719, integer i106) { 
    construct_C118(this_719);
    D_init635(this_719);
    D_c_188[this_719] = i_106;
}


function D_onDestroy690(integer this115) { 
    loop {
        exitwhen (not (D_c_188[this_115] < 4));
        D_c_188[this_115] = (D_c_188[this_115] + 1);
    };
    C_onDestroy507(this_115);
}


function error480(string msg789) { 
    $debugPrint622((msg_789 + ("
" + #getStackTrace())));
}


function alloc_D770() returns integer { 
    local integer this211
    if (A_firstFree_550 == 0) {
        if (A_maxIndex_441 < 32768) {
            A_maxIndex_441 = (A_maxIndex_441 + 1);
            this_211 = A_maxIndex_441;
            A_typeId_198[this_211] = 4;
        } else {
            error480("Out of memory: Could not create D.");
            this_211 = 0;
        };
    } else {
        A_firstFree_550 = (A_firstFree_550 - 1);
        this_211 = A_nextFree_675[A_firstFree_550];
        A_typeId_198[this_211] = 4;
    };
    return this_211;
}


function dealloc_D856(integer obj559) { 
    if (A_typeId_198[obj_559] == 0) {
        error480("Double free: object of type D");
    } else {
        A_nextFree_675[A_firstFree_550] = obj_559;
        A_firstFree_550 = (A_firstFree_550 + 1);
        A_typeId_198[obj_559] = 0;
    };
}


function dispatch_D_destroyD467(integer this935) { 
    if (A_typeId_198[this_935] == 0) {
        if (this_935 == 0) {
            error480("Nullpointer exception when calling D.D");
        } else {
            error480("Called D.D on invalid object.");
        };
    } else {
    };
    destroyD194(this_935);
}