integer test_x899
array<integer> B_nextFree122
integer B_firstFree135
integer B_maxIndex895
array<integer> B_typeId287


integer test_x899 = 2
integer B_firstFree135 = 0
integer B_maxIndex895 = 0


function initGlobals187() { 
    B_firstFree_135 = 0;
    B_maxIndex_895 = 0;
}


function main116() { 
    initGlobals187();
    init_test140();
}


function config819() { 
}


function init_test140() { 
    local integer a104
    test_x_899 = 2;
    a_104 = new_X949();
    dispatch_A_destroyA212(a_104);
    if (test_x_899 == 6) {
        testSuccess163();
    } else {
    };
}


IS_NATIVE function testSuccess163() { 
}


function destroyA606(integer this707) { 
    A_onDestroy340(this_707);
    dealloc_A144(this_707);
}


function A_init381(integer this329) { 
}


function construct_A907(integer this112) { 
    construct_B213(this_112);
    A_init381(this_112);
}


function A_onDestroy340(integer this198) { 
    test_x_899 = (test_x_899 + 1);
    B_onDestroy730(this_198);
}


function B_init134(integer this179) { 
}


function construct_B213(integer this937) { 
    B_init134(this_937);
}


function B_onDestroy730(integer this198) { 
    test_x_899 = (test_x_899 * 2);
}


function X_init185(integer this111) { 
}


function new_X949() returns integer { 
    local integer this114
    this_114 = alloc_X157();
    construct_X219(this_114);
    return this_114;
}


function construct_X219(integer this448) { 
    construct_A907(this_448);
    X_init185(this_448);
}


function error176(string msg814) { 
    $debugPrint153((msg_814 + ("
" + #getStackTrace())));
}


function dealloc_A144(integer obj835) { 
    if (B_typeId_287[obj_835] == 0) {
        error176("Double free: object of type A");
    } else {
        B_nextFree_122[B_firstFree_135] = obj_835;
        B_firstFree_135 = (B_firstFree_135 + 1);
        B_typeId_287[obj_835] = 0;
    };
}


function alloc_X157() returns integer { 
    local integer this302
    if (B_firstFree_135 == 0) {
        if (B_maxIndex_895 < 32768) {
            B_maxIndex_895 = (B_maxIndex_895 + 1);
            this_302 = B_maxIndex_895;
            B_typeId_287[this_302] = 3;
        } else {
            error176("Out of memory: Could not create X.");
            this_302 = 0;
        };
    } else {
        B_firstFree_135 = (B_firstFree_135 - 1);
        this_302 = B_nextFree_122[B_firstFree_135];
        B_typeId_287[this_302] = 3;
    };
    return this_302;
}


function dispatch_A_destroyA212(integer this196) { 
    if (B_typeId_287[this_196] == 0) {
        if (this_196 == 0) {
            error176("Nullpointer exception when calling A.A");
        } else {
            error176("Called A.A on invalid object.");
        };
    } else {
    };
    destroyA606(this_196);
}