parse

decompiled_code:
double __fastcall parse(char *dest, _DWORD *a2)
{
char *v2; // rax
double result; // xmm0_8
char v4[80]; // [rsp+0h] [rbp-78h] BYREF
__m128i v5; // [rsp+50h] [rbp-28h] BYREF

error = 0;
isformula = 0;
input = v4;
v2 = strcpy(v4, dest);
strupr(v2);
stacktop = -1;
v5.m128i_i8[0] = 0;
v5.m128i_i64[1] = 0LL;
push(&v5);
tokentype = nexttoken();
while ( 2 )
{
switch ( LOBYTE(stack[stacktop]) )
{
case 0:
case 9:
case 0xC:
case 0xD:
case 0xE:
case 0xF:
case 0x10:
case 0x14:
switch ( tokentype )
{
case 8:
goto LABEL_8;
case 9:
goto LABEL_9;
case 10:
goto LABEL_10;
case 1:
shift(5);
goto LABEL_25;
case 6:
goto LABEL_12;
}
error = 1;
goto LABEL_83;
case 1:
if ( tokentype != 11 )
{
if ( tokentype )
{
if ( tokentype != 1 )
{
error = 1;
goto LABEL_83;
}
LABEL_79:
shift(13);
}
else
{
LABEL_78:
shift(12);
}
LABEL_25:
if ( error )
goto LABEL_83;
continue;
}
if ( error )
{
LABEL_83:
*a2 = 0;
result = 0.0;
}
else
{
*a2 = 1 - ((isformula == 0) - 1);
strcpy(dest, v4);
result = *((double *)&stack[stacktop] + 1);
}
return result;
case 2:
if ( tokentype == 2 )
goto LABEL_67;
if ( tokentype == 3 )
goto LABEL_68;
reduce(3);
goto LABEL_25;
case 3:
reduce(6);
goto LABEL_25;
case 4:
if ( tokentype == 4 )
shift(16);
else
reduce(8);
goto LABEL_25;
case 5:
switch ( tokentype )
{
case 8:
LABEL_8:
shift(10);
break;
case 9:
LABEL_9:
shift(7);
break;
case 10:
LABEL_10:
shift(11);
break;
case 6:
LABEL_12:
shift(9);
break;
default:
error = 1;
goto LABEL_83;
}
goto LABEL_25;
case 6:
reduce(10);
goto LABEL_25;
case 7:
if ( tokentype == 5 )
shift(18);
else
reduce(13);
goto LABEL_25;
case 8:
reduce(12);
goto LABEL_25;
case 0xA:
reduce(15);
goto LABEL_25;
case 0xB:
if ( tokentype != 6 )
{
error = 1;
goto LABEL_83;
}
shift(20);
goto LABEL_25;
case 0x11:
reduce(9);
goto LABEL_25;
case 0x12:
if ( tokentype != 9 )
{
error = 1;
goto LABEL_83;
}
shift(26);
goto LABEL_25;
case 0x13:
if ( !tokentype )
goto LABEL_78;
if ( tokentype == 1 )
goto LABEL_79;
if ( tokentype != 7 )
{
error = 1;
goto LABEL_83;
}
shift(27);
goto LABEL_25;
case 0x15:
if ( tokentype == 2 )
goto LABEL_67;
if ( tokentype == 3 )
goto LABEL_68;
reduce(1);
goto LABEL_25;
case 0x16:
if ( tokentype == 2 )
{
LABEL_67:
shift(14);
}
else if ( tokentype == 3 )
{
LABEL_68:
shift(15);
}
else
{
reduce(2);
}
goto LABEL_25;
case 0x17:
reduce(4);
goto LABEL_25;
case 0x18:
reduce(5);
goto LABEL_25;
case 0x19:
reduce(7);
goto LABEL_25;
case 0x1A:
reduce(11);
goto LABEL_25;
case 0x1B:
reduce(14);
goto LABEL_25;
case 0x1C:
if ( !tokentype )
goto LABEL_78;
if ( tokentype == 1 )
goto LABEL_79;
if ( tokentype != 7 )
{
error = 1;
goto LABEL_83;
}
shift(29);
goto LABEL_25;
case 0x1D:
reduce(16);
goto LABEL_25;
case 0x1E:
error = 1;
goto LABEL_83;
default:
goto LABEL_25;
}
}
}

canonical_decompiled_code:
double __fastcall func8(char *dest, _DWORD *a2)
{
char *v2; // rax
double result; // xmm0_8
char v4[80]; // [rsp+0h] [rbp-78h] BYREF
__m128i v5; // [rsp+50h] [rbp-28h] BYREF

error = 0;
isformula = 0;
input = v4;
v2 = strcpy(v4, dest);
strupr(v2);
stacktop = -1;
v5.m128i_i8[0] = 0;
v5.m128i_i64[1] = 0LL;
func2(&v5);
tokentype = func1();
while ( 2 )
{
switch ( LOBYTE(stack[stacktop]) )
{
case 0:
case 9:
case 0xC:
case 0xD:
case 0xE:
case 0xF:
case 0x10:
case 0x14:
switch ( tokentype )
{
case 8:
goto LABEL_8;
case 9:
goto LABEL_9;
case 10:
goto LABEL_10;
case 1:
func6(5);
goto LABEL_25;
case 6:
goto LABEL_12;
}
error = 1;
goto LABEL_83;
case 1:
if ( tokentype != 11 )
{
if ( tokentype )
{
if ( tokentype != 1 )
{
error = 1;
goto LABEL_83;
}
LABEL_79:
func6(13);
}
else
{
LABEL_78:
func6(12);
}
LABEL_25:
if ( error )
goto LABEL_83;
continue;
}
if ( error )
{
LABEL_83:
*a2 = 0;
result = 0.0;
}
else
{
*a2 = 1 - ((isformula == 0) - 1);
strcpy(dest, v4);
result = *((double *)&stack[stacktop] + 1);
}
return result;
case 2:
if ( tokentype == 2 )
goto LABEL_67;
if ( tokentype == 3 )
goto LABEL_68;
func7(3);
goto LABEL_25;
case 3:
func7(6);
goto LABEL_25;
case 4:
if ( tokentype == 4 )
func6(16);
else
func7(8);
goto LABEL_25;
case 5:
switch ( tokentype )
{
case 8:
LABEL_8:
func6(10);
break;
case 9:
LABEL_9:
func6(7);
break;
case 10:
LABEL_10:
func6(11);
break;
case 6:
LABEL_12:
func6(9);
break;
default:
error = 1;
goto LABEL_83;
}
goto LABEL_25;
case 6:
func7(10);
goto LABEL_25;
case 7:
if ( tokentype == 5 )
func6(18);
else
func7(13);
goto LABEL_25;
case 8:
func7(12);
goto LABEL_25;
case 0xA:
func7(15);
goto LABEL_25;
case 0xB:
if ( tokentype != 6 )
{
error = 1;
goto LABEL_83;
}
func6(20);
goto LABEL_25;
case 0x11:
func7(9);
goto LABEL_25;
case 0x12:
if ( tokentype != 9 )
{
error = 1;
goto LABEL_83;
}
func6(26);
goto LABEL_25;
case 0x13:
if ( !tokentype )
goto LABEL_78;
if ( tokentype == 1 )
goto LABEL_79;
if ( tokentype != 7 )
{
error = 1;
goto LABEL_83;
}
func6(27);
goto LABEL_25;
case 0x15:
if ( tokentype == 2 )
goto LABEL_67;
if ( tokentype == 3 )
goto LABEL_68;
func7(1);
goto LABEL_25;
case 0x16:
if ( tokentype == 2 )
{
LABEL_67:
func6(14);
}
else if ( tokentype == 3 )
{
LABEL_68:
func6(15);
}
else
{
func7(2);
}
goto LABEL_25;
case 0x17:
func7(4);
goto LABEL_25;
case 0x18:
func7(5);
goto LABEL_25;
case 0x19:
func7(7);
goto LABEL_25;
case 0x1A:
func7(11);
goto LABEL_25;
case 0x1B:
func7(14);
goto LABEL_25;
case 0x1C:
if ( !tokentype )
goto LABEL_78;
if ( tokentype == 1 )
goto LABEL_79;
if ( tokentype != 7 )
{
error = 1;
goto LABEL_83;
}
func6(29);
goto LABEL_25;
case 0x1D:
func7(16);
goto LABEL_25;
case 0x1E:
error = 1;
goto LABEL_83;
default:
goto LABEL_25;
}
}
}

original_code:
double parse(char *s, int *att)
{
    struct TOKENREC firsttoken;
    char accepted = 0;
    char copy[80];
    error = 0;
    isformula = 0;
    input = copy;
    strupr(strcpy(copy, s));
    stacktop = -1;
    firsttoken.state = 0;
    firsttoken.x.value = 0;
    push(&firsttoken);
    tokentype = nexttoken();
    do {
        switch (stack[stacktop].state) {
            case 0 :
            case 9 :
            case 12 :
            case 13 :
            case 14 :
            case 15 :
            case 16 :
            case 20 :
                if (tokentype == 8)
                    shift(10);
                else if (tokentype == 9)
                    shift(7);
                else if (tokentype == 10)
                    shift(11);
                else if (tokentype == 1)
                    shift(5);
                else if (tokentype == 6)
                    shift(9);
                else
                    error = 1;
                break;
            case 1 :
                if (tokentype == 11)
                    accepted = 1;
                else if (tokentype == 0)
                    shift(12);
                else if (tokentype == 1)
                    shift(13);
                else
                    error = 1;
                break;
            case 2 :
                if (tokentype == 2)
                    shift(14);
                else if (tokentype == 3)
                    shift(15);
                else
                    reduce(3);
                break;
            case 3 :
                reduce(6);
                break;
            case 4 :
                if (tokentype == 4)
                    shift(16);
                else
                    reduce(8);
                break;
            case 5 :
                if (tokentype == 8)
                    shift(10);
                else if (tokentype == 9)
                    shift(7);
                else if (tokentype == 10)
                    shift(11);
                else if (tokentype == 6)
                    shift(9);
                else
                    error = 1;
                break;
            case 6 :
                reduce(10);
                break;
            case 7 :
                if (tokentype == 5)
                    shift(18);
                else
                    reduce(13);
                break;
            case 8 :
                reduce(12);
                break;
            case 10 :
                reduce(15);
                break;
            case 11 :
                if (tokentype == 6)
                    shift(20);
                else
                    error = 1;
                break;
            case 17 :
                reduce(9);
                break;
            case 18 :
                if (tokentype == 9)
                    shift(26);
                else
                    error = 1;
                break;
            case 19 :
                if (tokentype == 0)
                    shift(12);
                else if (tokentype == 1)
                    shift(13);
                else if (tokentype == 7)
                    shift(27);
                else
                    error = 1;
                break;
            case 21 :
                if (tokentype == 2)
                    shift(14);
                else if (tokentype == 3)
                    shift(15);
                else
                    reduce(1);
                break;
            case 22 :
                if (tokentype == 2)
                    shift(14);
                else if (tokentype == 3)
                    shift(15);
                else
                    reduce(2);
                break;
            case 23 :
                reduce(4);
                break;
            case 24 :
                reduce(5);
                break;
            case 25 :
                reduce(7);
                break;
            case 26 :
                reduce(11);
                break;
            case 27 :
                reduce(14);
                break;
            case 28 :
                if (tokentype == 0)
                    shift(12);
                else if (tokentype == 1)
                    shift(13);
                else if (tokentype == 7)
                    shift(29);
                else
                    error = 1;
                break;
            case 29 :
                reduce(16);
                break;
            case 30 :
                error = 1;
                break;
        }
    }
    while ((!accepted) && (!error));
    if (error) {
        *att = 0;
        return(0);
    }
    if (isformula)
        *att = 2;
    else
        *att = 1;
    strcpy(s, copy);
    return(stack[stacktop].x.value);
}

variable_types:
s
char *

variable_types:
att
int *

variable_types: accepted char

variable_types:
copy
char [80]

user_defined_types: struct TOKENREC { char state; union { double value; struct { int row; } c; char funcname[-1]; } x; }


repo: lornix/tcalc

decompiled_code:
void finish_atexit(void)
{
endwin();
}

canonical_decompiled_code:
void func0(void)
{
endwin();
}

original_code:
static void finish_atexit(void)
{
    endwin();
}

canonical_original_code:
static void finish_atexit()
{
    endwin();
}

return_type: void


decompiled_code:
void finish_signal()
{
finish_atexit();
}

canonical_decompiled_code:
void func1()
{
func0();
}

original_code:
static void finish_signal(int sig __attribute__((unused)))
{
    finish_atexit();
}

canonical_original_code:
static void finish_signal(int sig)
{
    finish_atexit();
}

variable_types: sig int


strupr

decompiled_code:
const char *__fastcall strupr(const char *a1)
{
int v2; // eax
int v3; // ebp
const __int32_t **v4; // rdi
char *v5; // rax

v2 = strlen(a1);
if ( v2 >= 0 )
{
v3 = v2;
v4 = _ctype_toupper_loc();
v5 = (char *)&a1[v3];
do
{
*v5 = (*v4)[*v5];
--v5;
}
while ( v5 != &a1[v3 - 1 - v3] );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
int v2; // eax
int v3; // ebp
const __int32_t **v4; // rdi
char *v5; // rax

v2 = strlen(a1);
if ( v2 >= 0 )
{
v3 = v2;
v4 = _ctype_toupper_loc();
v5 = (char *)&a1[v3];
do
{
*v5 = (*v4)[*v5];
--v5;
}
while ( v5 != &a1[v3 - 1 - v3] );
}
return a1;
}

original_code:
char* strupr(char* s)
{
    int l=strlen(s);
    while (l>=0) {
        s[l]=toupper(s[l]);
        l--;
    }
    return s;
}

canonical_original_code:
char *strupr(char *s)
{
    int l = strlen(s);
    while (l>=0) {
        s[l]=toupper(s[l]);
        l--;
    }
    return s;
}

variable_types: l int

return_type: char *


decompiled_code:
double __fastcall pow10(double a1)
{
return pow(10.0, a1);
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
return pow(10.0, a1);
}

original_code:
double pow10(double p)
{
    return pow(10.0f,p);
}

variable_types: p double

return_type: double


bioskey

decompiled_code:
int bioskey()
{
int result; // eax

result = wgetch(stdscr);
switch ( result )
{
case 258:
result = 336;
return (result - 256) << 8;
case 259:
result = 328;
return (result - 256) << 8;
case 260:
result = 331;
return (result - 256) << 8;
case 261:
result = 333;
return (result - 256) << 8;
case 262:
result = 327;
return (result - 256) << 8;
case 263:
return 8;
case 265:
result = 315;
return (result - 256) << 8;
case 266:
result = 316;
return (result - 256) << 8;
case 267:
result = 317;
return (result - 256) << 8;
case 268:
result = 318;
return (result - 256) << 8;
case 269:
result = 319;
return (result - 256) << 8;
case 270:
result = 320;
return (result - 256) << 8;
case 271:
result = 321;
return (result - 256) << 8;
case 272:
result = 322;
return (result - 256) << 8;
case 273:
result = 323;
return (result - 256) << 8;
case 274:
result = 324;
return (result - 256) << 8;
case 330:
result = 339;
return (result - 256) << 8;
case 331:
result = 338;
return (result - 256) << 8;
case 332:
return 27;
case 338:
result = 337;
return (result - 256) << 8;
case 339:
result = 329;
return (result - 256) << 8;
case 343:
return 13;
case 360:
result = 335;
return (result - 256) << 8;
case 393:
result = 371;
return (result - 256) << 8;
case 402:
result = 372;
return (result - 256) << 8;
default:
if ( result > 255 )
return (result - 256) << 8;
return result;
}
}

canonical_decompiled_code:
int func4()
{
int result; // eax

result = wgetch(stdscr);
switch ( result )
{
case 258:
result = 336;
return (result - 256) << 8;
case 259:
result = 328;
return (result - 256) << 8;
case 260:
result = 331;
return (result - 256) << 8;
case 261:
result = 333;
return (result - 256) << 8;
case 262:
result = 327;
return (result - 256) << 8;
case 263:
return 8;
case 265:
result = 315;
return (result - 256) << 8;
case 266:
result = 316;
return (result - 256) << 8;
case 267:
result = 317;
return (result - 256) << 8;
case 268:
result = 318;
return (result - 256) << 8;
case 269:
result = 319;
return (result - 256) << 8;
case 270:
result = 320;
return (result - 256) << 8;
case 271:
result = 321;
return (result - 256) << 8;
case 272:
result = 322;
return (result - 256) << 8;
case 273:
result = 323;
return (result - 256) << 8;
case 274:
result = 324;
return (result - 256) << 8;
case 330:
result = 339;
return (result - 256) << 8;
case 331:
result = 338;
return (result - 256) << 8;
case 332:
return 27;
case 338:
result = 337;
return (result - 256) << 8;
case 339:
result = 329;
return (result - 256) << 8;
case 343:
return 13;
case 360:
result = 335;
return (result - 256) << 8;
case 393:
result = 371;
return (result - 256) << 8;
case 402:
result = 372;
return (result - 256) << 8;
default:
if ( result > 255 )
return (result - 256) << 8;
return result;
}
}

original_code:
int bioskey(int cmd __attribute__((unused)))
{
    int key=wgetch(stdscr);
    switch (key) {
        case 0406: key=327; break;
        case 0550: key=335; break;
        case 0513: key=338; break;
        case 0404: key=331; break;
        case 0405: key=333; break;
        case 0407: key=8; break;
        case 0512: key=339; break;
        case 0527: key=13; break;
        case 0403: key=328; break;
        case 0402: key=336; break;
        case 0514: key=27; break;
        case 0523: key=329; break;
        case 0522: key=337; break;
        case 0611: key=371; break;
        case 0622: key=372; break;
        case (0410 +(1)): key=315; break;
        case (0410 +(2)): key=316; break;
        case (0410 +(3)): key=317; break;
        case (0410 +(4)): key=318; break;
        case (0410 +(5)): key=319; break;
        case (0410 +(6)): key=320; break;
        case (0410 +(7)): key=321; break;
        case (0410 +(8)): key=322; break;
        case (0410 +(9)): key=323; break;
        case (0410 +(10)): key=324; break;
        default: break;
    }
    if (key>255) {
        key=(key-256)*256;
    }
    return key;
}

canonical_original_code:
int bioskey(int cmd)
{
    int key = wgetch(stdscr);
    switch (key) {
        case 0406: key=327; break;
        case 0550: key=335; break;
        case 0513: key=338; break;
        case 0404: key=331; break;
        case 0405: key=333; break;
        case 0407: key=8; break;
        case 0512: key=339; break;
        case 0527: key=13; break;
        case 0403: key=328; break;
        case 0402: key=336; break;
        case 0514: key=27; break;
        case 0523: key=329; break;
        case 0522: key=337; break;
        case 0611: key=371; break;
        case 0622: key=372; break;
        case (0410 +(1)): key=315; break;
        case (0410 +(2)): key=316; break;
        case (0410 +(3)): key=317; break;
        case (0410 +(4)): key=318; break;
        case (0410 +(5)): key=319; break;
        case (0410 +(6)): key=320; break;
        case (0410 +(7)): key=321; break;
        case (0410 +(8)): key=322; break;
        case (0410 +(9)): key=323; break;
        case (0410 +(10)): key=324; break;
        default: break;
    }
    if (key>255) {
        key=(key-256)*256;
    }
    return key;
}

variable_types: cmd int

variable_types: key int

return_type: int


refreshscreen

decompiled_code:
int refreshscreen()
{
int v0; // edx

v0 = -1;
if ( nwin )
v0 = nwin->_maxy + 1;
return wredrawln(nwin, 0, v0);
}

canonical_decompiled_code:
int func5()
{
int v0; // edx

v0 = -1;
if ( nwin )
v0 = nwin->_maxy + 1;
return wredrawln(nwin, 0, v0);
}

original_code:
void refreshscreen()
{
    wredrawln(nwin, 0, ((0 != (const void *)((nwin))) ? (nwin)->_maxy+1 : -1));
}

canonical_original_code:
void refreshscreen()
{
    wredrawln(nwin, 0, ((0 != (void *)((nwin))) ? (nwin)->_maxy+1 : -1));
}


cputs

decompiled_code:
__int64 __fastcall cputs(char *a1)
{
wattrset(stdscr, (unsigned __int8)byte_4C4 << 8);
if ( wmove(stdscr, (unsigned __int8)byte_4CA, (unsigned __int8)byte_4C9) != -1 )
waddnstr(stdscr, a1, -1);
wrefresh(stdscr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
wattrset(stdscr, (unsigned __int8)byte_4C4 << 8);
if ( wmove(stdscr, (unsigned __int8)byte_4CA, (unsigned __int8)byte_4C9) != -1 )
waddnstr(stdscr, a1, -1);
wrefresh(stdscr);
return 0LL;
}

original_code:
int cputs(const char* str)
{
    wattrset(stdscr,((((chtype)(((master_text_info.attribute))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
    (wmove((stdscr),((master_text_info.cury)),((master_text_info.curx))) == (-1) ? (-1) : waddnstr((stdscr),((str)),-1));
    wrefresh(stdscr);
    return 0;
}

canonical_original_code:
int cputs(char *str)
{
    wattrset(stdscr,((((chtype)(((master_text_info.attribute))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
    (wmove((stdscr),((master_text_info.cury)),((master_text_info.curx))) == (-1) ? (-1) : waddnstr((stdscr),((str)),-1));
    wrefresh(stdscr);
    return 0;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall int86(unsigned int a1, unsigned int *a2, __int64 a3)
{
char v3; // al

if ( a1 == 16 )
{
v3 = *((_BYTE *)a2 + 1);
if ( v3 == 1 )
{
cursorshape_0 = a2[2];
return a1;
}
if ( v3 == 3 )
{
*(_DWORD *)(a3 + 8) = cursorshape_0;
return a1;
}
}
fprintf(stderr, "int86: %04x AX: %04x\n", a1, *a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int *a2, __int64 a3)
{
char v3; // al

if ( a1 == 16 )
{
v3 = *((_BYTE *)a2 + 1);
if ( v3 == 1 )
{
cursorshape_0 = a2[2];
return a1;
}
if ( v3 == 3 )
{
*(_DWORD *)(a3 + 8) = cursorshape_0;
return a1;
}
}
fprintf(stderr, "int86: %04x AX: %04x\n", a1, *a2);
return a1;
}

original_code:
int int86(int intno, union REGS* inregs, union REGS* outregs)
{
    static int cursorshape=0xFFFF;
    switch (intno) {
        case 0x10:
            if (inregs->h.ah==1) {
                cursorshape=inregs->x.cx;
                break;
            }
            else if (inregs->h.ah==3) {
                outregs->x.cx=cursorshape;
                break;
            }
        default:
            fprintf(stderr,"int86: %04x AX: %04x\n",intno,inregs->x.ax);
    }
    return intno;
}

canonical_original_code:
int int86(int intno, union REGS *inregs, union REGS *outregs)
{
    static int cursorshape = 0xFFFF;
    switch (intno) {
        case 0x10:
            if (inregs->h.ah==1) {
                cursorshape=inregs->x.cx;
                break;
            }
            else if (inregs->h.ah==3) {
                outregs->x.cx=cursorshape;
                break;
            }
        default:
            fprintf(stderr,"int86: %04x AX: %04x\n",intno,inregs->x.ax);
    }
    return intno;
}

variable_types: intno int

variable_types: union REGS { struct WORDREGS { unsigned int ax; } x; struct BYTEREGS { unsigned char al; } h; } *

variable_types:
outregs
union REGS *

variable_types: cursorshape int

user_defined_types: union REGS { struct WORDREGS x; struct BYTEREGS h; }


movetext

decompiled_code:
__int64 __fastcall movetext(int a1, int a2, int a3, int a4, int a5, int a6)
{
return (unsigned int)(a1 + a5 + a4 + a3 + a2 + a6);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3, int a4, int a5, int a6)
{
return (unsigned int)(a1 + a5 + a4 + a3 + a2 + a6);
}

original_code:
int movetext(int left, int top, int right, int bottom, int destleft, int desttop)
{
    return top+right+bottom+destleft+left+desttop;
}

variable_types: left int

variable_types: top int

variable_types: right int

variable_types: bottom int

variable_types: destleft int

variable_types: desttop int


gotoxy

decompiled_code:
void __fastcall gotoxy(char a1, char a2)
{
byte_4C9 = a1 - 1;
byte_4CA = a2 - 1;
}

canonical_decompiled_code:
void __fastcall func10(char a1, char a2)
{
byte_4C9 = a1 - 1;
byte_4CA = a2 - 1;
}

original_code:
void gotoxy(int x, int y)
{
    master_text_info.curx=x-1;
    master_text_info.cury=y-1;
}

variable_types: x int

variable_types: y int


clrscr

decompiled_code:
__int64 clrscr()
{
int v0; // edx
int v1; // ebx
__int64 result; // rax
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

byte_4C9 = 1;
byte_4CA = 1;
v0 = (unsigned __int8)byte_4C2 - (unsigned __int8)master_text_info + 1;
if ( v0 > 255 )
v0 = 255;
sprintf(v3, "%*s", v0, (const char *)&unk_96E);
v1 = (unsigned __int8)byte_4C1;
result = (unsigned __int8)byte_4C3;
if ( (unsigned __int8)byte_4C1 <= (int)(unsigned __int8)byte_4C3 )
{
do
{
gotoxy(master_text_info, v1);
cputs(v3);
++v1;
result = (unsigned __int8)*(&master_text_info + 3);
}
while ( (int)result >= v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // edx
int v1; // ebx
__int64 result; // rax
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

byte_4C9 = 1;
byte_4CA = 1;
v0 = (unsigned __int8)byte_4C2 - (unsigned __int8)master_text_info + 1;
if ( v0 > 255 )
v0 = 255;
sprintf(v3, "%*s", v0, (const char *)&unk_96E);
v1 = (unsigned __int8)byte_4C1;
result = (unsigned __int8)byte_4C3;
if ( (unsigned __int8)byte_4C1 <= (int)(unsigned __int8)byte_4C3 )
{
do
{
func10(master_text_info, v1);
func6(v3);
++v1;
result = (unsigned __int8)*(&master_text_info + 3);
}
while ( (int)result >= v1 );
}
return result;
}

original_code:
void clrscr(void)
{
    int row;
    static const int MAXBLANKS=255;
    char blankstr[MAXBLANKS+1];
    master_text_info.curx=1;
    master_text_info.cury=1;
    row=master_text_info.winright-master_text_info.winleft+1;
    if (row>MAXBLANKS)
        row=MAXBLANKS;
    sprintf(blankstr,"%*s",row,"");
    for (row=master_text_info.wintop; row<=master_text_info.winbottom; row++) {
        gotoxy(master_text_info.winleft,row);
        cputs(blankstr);
    }
}

canonical_original_code:
void clrscr()
{
    int row;
    static int MAXBLANKS = 255;
    char blankstr[-1];
    master_text_info.curx=1;
    master_text_info.cury=1;
    row=master_text_info.winright-master_text_info.winleft+1;
    if (row>MAXBLANKS)
        row=MAXBLANKS;
    sprintf(blankstr,"%*s",row,"");
    for (row=master_text_info.wintop; row<=master_text_info.winbottom; row++) {
        gotoxy(master_text_info.winleft,row);
        cputs(blankstr);
    }
}

variable_types: row int

variable_types: MAXBLANKS int

variable_types:
blankstr
char [-1]


movmem

decompiled_code:
void *__fastcall movmem(void *src, void *dest, size_t n)
{
return memmove(dest, src, (unsigned int)n);
}

canonical_decompiled_code:
void *__fastcall func12(void *src, void *dest, size_t n)
{
return memmove(dest, src, (unsigned int)n);
}

original_code:
void movmem(void* src, void* dest, unsigned length)
{
    memmove(dest,src,length);
}

canonical_original_code:
void movmem(void *src, void *dest, unsigned int length)
{
    memmove(dest,src,length);
}

variable_types:
src
void *

variable_types:
dest
void *

variable_types:
length
unsigned int


setmem

decompiled_code:
void *__fastcall setmem(void *a1, unsigned int a2, char a3)
{
return memset(a1, a3, a2);
}

canonical_decompiled_code:
void *__fastcall func13(void *a1, unsigned int a2, char a3)
{
return memset(a1, a3, a2);
}

original_code:
void setmem(void* dest, unsigned length, char value)
{
    memset(dest,value,length);
}

canonical_original_code:
void setmem(void *dest, unsigned int length, char value)
{
    memset(dest,value,length);
}

variable_types: value char


textattr

decompiled_code:
void __fastcall textattr(char a1)
{
byte_4C4 = a1;
}

canonical_decompiled_code:
void __fastcall func14(char a1)
{
byte_4C4 = a1;
}

original_code:
void textattr(int newattr)
{
    master_text_info.attribute=newattr;
}

variable_types: newattr int


window

decompiled_code:
void __fastcall window(char a1, char a2, char a3, char a4)
{
int i; // ebx

if ( !donesetup )
{
byte_4C4 = 7;
byte_4C5 = 7;
byte_4C6 = 3;
byte_4C7 = 24;
byte_4C8 = 80;
signal(2, (__sighandler_t)finish_signal);
atexit(finish_atexit);
nwin = initscr();
start_color();
for ( i = 1; i != 256; ++i )
init_pair(i, i & 0xF, (i >> 4) & 0xF);
keypad(stdscr, 1);
nonl();
cbreak();
echo();
donesetup = 1;
}
byte_4C9 = a1;
byte_4CA = a2;
master_text_info = a1;
byte_4C1 = a2;
byte_4C2 = a3;
byte_4C3 = a4;
}

canonical_decompiled_code:
void __fastcall func15(char a1, char a2, char a3, char a4)
{
int i; // ebx

if ( !donesetup )
{
byte_4C4 = 7;
byte_4C5 = 7;
byte_4C6 = 3;
byte_4C7 = 24;
byte_4C8 = 80;
signal(2, (__sighandler_t)finish_signal);
atexit(finish_atexit);
nwin = initscr();
start_color();
for ( i = 1; i != 256; ++i )
init_pair(i, i & 0xF, (i >> 4) & 0xF);
keypad(stdscr, 1);
nonl();
cbreak();
echo();
donesetup = 1;
}
byte_4C9 = a1;
byte_4CA = a2;
master_text_info = a1;
byte_4C1 = a2;
byte_4C2 = a3;
byte_4C3 = a4;
}

original_code:
void window(int left, int top, int right, int bottom)
{
    if (!donesetup) {
        int color;
        master_text_info.attribute=7;
        master_text_info.normattr=7;
        master_text_info.currmode=C80;
        master_text_info.screenheight=24;
        master_text_info.screenwidth=80;
        signal(2, finish_signal);
        atexit(finish_atexit);
        nwin=initscr();
        start_color();
        for (color=1; color<256; color++) {
            init_pair(color,(color&0x0f),(color>>4)&0x0f);
        }
        keypad(stdscr, 1);
        nonl();
        cbreak();
        echo();
        donesetup=1;
    }
    master_text_info.curx=left;
    master_text_info.cury=top;
    master_text_info.winleft=left;
    master_text_info.wintop=top;
    master_text_info.winright=right;
    master_text_info.winbottom=bottom;
}

variable_types: color int


coreleft

decompiled_code:
__int64 coreleft()
{
return 31457280LL;
}

original_code:
unsigned long coreleft(void)
{
    return 30*1024*1024;
}

canonical_original_code:
unsigned long coreleft()
{
    return 30*1024*1024;
}

return_type: unsigned long


getkey

decompiled_code:
__int64 getkey()
{
__int64 result; // rax
unsigned __int8 v1; // bh

LODWORD(result) = bioskey(0LL);
v1 = BYTE1(result);
if ( (_DWORD)result == 12 )
{
refreshscreen();
result = 12LL;
}
else
{
result = (unsigned __int8)result;
if ( !(_BYTE)result )
result = (unsigned int)v1 + 256;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
unsigned __int8 v1; // bh

LODWORD(result) = bioskey(0LL);
v1 = BYTE1(result);
if ( (_DWORD)result == 12 )
{
refreshscreen();
result = 12LL;
}
else
{
result = (unsigned __int8)result;
if ( !(_BYTE)result )
result = (unsigned int)v1 + 256;
}
return result;
}

original_code:
int getkey(void)
{
    int key, lo, hi;
    key = bioskey(0);
    if (key==12)
        refreshscreen();
    lo = key & 0X00FF;
    hi = (key & 0XFF00) >> 8;
    return((lo == 0) ? hi + 256 : lo);
}

canonical_original_code:
int getkey()
{
    int key; int lo; int hi;
    key = bioskey(0);
    if (key==12)
        refreshscreen();
    lo = key & 0X00FF;
    hi = (key & 0XFF00) >> 8;
    return((lo == 0) ? hi + 256 : lo);
}

variable_types: key int

variable_types: lo int

variable_types: hi int


editstring

decompiled_code:
_BOOL8 __fastcall editstring(const char *a1, const char *a2, int a3)
{
int v3; // ebp
int v4; // er14
unsigned int v5; // er15
int v7; // eax
int v8; // ebx

v3 = strlen(a1);
v4 = v3;
changecursor(1LL);
v5 = 1;
do
{
writef(1LL, 25LL, 15LL, 79LL, &unk_4AF, a1);
gotoxy((unsigned int)(v3 + 1), 25LL);
v7 = getkey();
v8 = v7;
if ( v7 > 339 )
goto LABEL_4;
if ( v7 > 326 )
{
switch ( v7 )
{
case 327:
v3 = 0;
goto LABEL_15;
case 328:
case 336:
goto LABEL_8;
case 331:
v3 -= v3 > 0;
goto LABEL_15;
case 333:
if ( v4 > v3 )
++v3;
goto LABEL_15;
case 335:
v3 = v4;
goto LABEL_15;
case 338:
v5 ^= 1u;
changecursor(v5);
goto LABEL_15;
case 339:
if ( v4 > v3 )
{
movmem(&a1[v3 + 1], &a1[v3], (unsigned int)(v4 - v3));
--v4;
}
goto LABEL_15;
default:
goto LABEL_4;
}
}
if ( v7 == 8 )
{
if ( v3 > 0 )
{
movmem(&a1[v3], &a1[v3 - 1], (unsigned int)(v4 - v3 + 1));
--v3;
--v4;
}
goto LABEL_15;
}
if ( v7 > 7 && (v7 == 13 || v7 == 27) )
{
a1[v4] = 0;
}
else
{
LABEL_4:
if ( (!*a2 || strchr(a2, v7)) && (unsigned int)(v8 - 32) <= 0x5E && v4 < a3 )
{
if ( v5 )
{
memmove((void *)&a1[v3 + 1], &a1[v3], v4 - v3 + 1);
++v4;
}
else
{
v4 += v4 <= v3;
}
a1[v3++] = v8;
LABEL_15:
a1[v4] = 0;
continue;
}
LABEL_8:
a1[v4] = 0;
if ( ((v8 - 328) & 0xFFFFFFF7) == 0 )
break;
}
}
while ( v8 != 13 && v8 != 27 );
clearinput();
changecursor(0LL);
setcursor(nocursor);
return v8 != 27;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1, const char *a2, int a3)
{
int v3; // ebp
int v4; // er14
unsigned int v5; // er15
int v7; // eax
int v8; // ebx

v3 = strlen(a1);
v4 = v3;
changecursor(1LL);
v5 = 1;
do
{
writef(1LL, 25LL, 15LL, 79LL, &unk_4AF, a1);
gotoxy((unsigned int)(v3 + 1), 25LL);
v7 = func0();
v8 = v7;
if ( v7 > 339 )
goto LABEL_4;
if ( v7 > 326 )
{
switch ( v7 )
{
case 327:
v3 = 0;
goto LABEL_15;
case 328:
case 336:
goto LABEL_8;
case 331:
v3 -= v3 > 0;
goto LABEL_15;
case 333:
if ( v4 > v3 )
++v3;
goto LABEL_15;
case 335:
v3 = v4;
goto LABEL_15;
case 338:
v5 ^= 1u;
changecursor(v5);
goto LABEL_15;
case 339:
if ( v4 > v3 )
{
movmem(&a1[v3 + 1], &a1[v3], (unsigned int)(v4 - v3));
--v4;
}
goto LABEL_15;
default:
goto LABEL_4;
}
}
if ( v7 == 8 )
{
if ( v3 > 0 )
{
movmem(&a1[v3], &a1[v3 - 1], (unsigned int)(v4 - v3 + 1));
--v3;
--v4;
}
goto LABEL_15;
}
if ( v7 > 7 && (v7 == 13 || v7 == 27) )
{
a1[v4] = 0;
}
else
{
LABEL_4:
if ( (!*a2 || strchr(a2, v7)) && (unsigned int)(v8 - 32) <= 0x5E && v4 < a3 )
{
if ( v5 )
{
memmove((void *)&a1[v3 + 1], &a1[v3], v4 - v3 + 1);
++v4;
}
else
{
v4 += v4 <= v3;
}
a1[v3++] = v8;
LABEL_15:
a1[v4] = 0;
continue;
}
LABEL_8:
a1[v4] = 0;
if ( ((v8 - 328) & 0xFFFFFFF7) == 0 )
break;
}
}
while ( v8 != 13 && v8 != 27 );
clearinput();
changecursor(0LL);
setcursor(nocursor);
return v8 != 27;
}

original_code:
int editstring(char *s, char *legal, int maxlength)
{
    int c, len = strlen(s), pos = len, insert = 1;
    changecursor(insert);
    do {
        writef(1, 25, WHITE, 79, "%s", s);
        gotoxy(pos + 1, 25);
        switch(c = getkey()) {
            case 327 :
                pos = 0;
                break;
            case 335 :
                pos = len;
                break;
            case 338 :
                insert = !insert;
                changecursor(insert);
                break;
            case 331 :
                if (pos > 0)
                    pos--;
                break;
            case 333 :
                if (pos < len)
                    pos++;
                break;
            case 8 :
                if (pos > 0) {
                    movmem(&s[pos], &s[pos - 1], len - pos + 1);
                    pos--;
                    len--;
                }
                break;
            case 339 :
                if (pos < len) {
                    movmem(&s[pos + 1], &s[pos], len - pos);
                    len--;
                }
                break;
            case 13 :
                break;
            case 328 :
                break;
            case 336 :
                break;
            case 27 :
                break;
            default :
                if (((legal[0] == 0) || (strchr(legal, c) != ((void *)0))) &&
                        ((c >= ' ') && (c <= '~')) &&
                        (len < maxlength)) {
                    if (insert) {
                        memmove(&s[pos + 1], &s[pos], len - pos + 1);
                        len++;
                    }
                    else if (pos >= len)
                        len++;
                    s[pos++] = c;
                }
                break;
        }
        s[len] = 0;
    }
    while ((c!=328)&&(c!=336)&&(c!=13)&&(c!=27));
    clearinput();
    changecursor(0);
    setcursor(nocursor);
    return(c != 27);
}

canonical_original_code:
int editstring(char *s, char *legal, int maxlength)
{
    int c; int len = strlen(s); int pos = len; int insert = 1;
    changecursor(insert);
    do {
        writef(1, 25, WHITE, 79, "%s", s);
        gotoxy(pos + 1, 25);
        switch(c = getkey()) {
            case 327 :
                pos = 0;
                break;
            case 335 :
                pos = len;
                break;
            case 338 :
                insert = !insert;
                changecursor(insert);
                break;
            case 331 :
                if (pos > 0)
                    pos--;
                break;
            case 333 :
                if (pos < len)
                    pos++;
                break;
            case 8 :
                if (pos > 0) {
                    movmem(&s[pos], &s[pos - 1], len - pos + 1);
                    pos--;
                    len--;
                }
                break;
            case 339 :
                if (pos < len) {
                    movmem(&s[pos + 1], &s[pos], len - pos);
                    len--;
                }
                break;
            case 13 :
                break;
            case 328 :
                break;
            case 336 :
                break;
            case 27 :
                break;
            default :
                if (((legal[0] == 0) || (strchr(legal, c) != ((void *)0))) &&
                        ((c >= ' ') && (c <= '~')) &&
                        (len < maxlength)) {
                    if (insert) {
                        memmove(&s[pos + 1], &s[pos], len - pos + 1);
                        len++;
                    }
                    else if (pos >= len)
                        len++;
                    s[pos++] = c;
                }
                break;
        }
        s[len] = 0;
    }
    while ((c!=328)&&(c!=336)&&(c!=13)&&(c!=27));
    clearinput();
    changecursor(0);
    setcursor(nocursor);
    return(c != 27);
}

variable_types:
s
char *

variable_types:
legal
char *

variable_types: maxlength int

variable_types: c int

variable_types: len int

variable_types: pos int

variable_types: insert int


getinput

decompiled_code:
__int64 __fastcall getinput(char a1)
{
__int64 result; // rax
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v2[0] = a1;
v2[1] = 0;
result = editstring(v2, (const char *)&unk_4B2, 79);
if ( (_DWORD)result )
{
if ( v2[0] )
{
result = act(v2);
changed = 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
__int64 result; // rax
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v2[0] = a1;
v2[1] = 0;
result = func1(v2, (const char *)&unk_4B2, 79);
if ( (_DWORD)result )
{
if ( v2[0] )
{
result = act(v2);
changed = 1;
}
}
return result;
}

original_code:
void getinput(int c)
{
    char s[79 +1];
    s[0]=c;
    s[1]=0;
    if (!editstring(s,"",79)||(s[0]==0))
        return;
    act(s);
    changed=1;
}

canonical_original_code:
void getinput(int c)
{
    char s[-1];
    s[0]=c;
    s[1]=0;
    if (!editstring(s,"",79)||(s[0]==0))
        return;
    act(s);
    changed=1;
}

variable_types:
s
char [-1]


getint

decompiled_code:
_BOOL8 __fastcall getint(int *a1, int a2, int a3)
{
_BOOL8 result; // rax
int v5; // eax
char v6[91]; // [rsp+0h] [rbp-78h] BYREF
char nptr[29]; // [rsp+5Bh] [rbp-1Dh] BYREF

nptr[0] = 0;
sprintf(v6, "You must enter a number from %d to %d.", (unsigned int)a2, (unsigned int)a3);
while ( 1 )
{
result = editstring(nptr, "1234567890", 4);
if ( !result )
break;
v5 = atoi(nptr);
if ( a2 <= v5 && a3 >= v5 )
{
*a1 = v5;
return 1LL;
}
errormsg(v6);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int *a1, int a2, int a3)
{
_BOOL8 result; // rax
int v5; // eax
char v6[91]; // [rsp+0h] [rbp-78h] BYREF
char nptr[29]; // [rsp+5Bh] [rbp-1Dh] BYREF

nptr[0] = 0;
sprintf(v6, "You must enter a number from %d to %d.", (unsigned int)a2, (unsigned int)a3);
while ( 1 )
{
result = func1(nptr, "1234567890", 4);
if ( !result )
break;
v5 = atoi(nptr);
if ( a2 <= v5 && a3 >= v5 )
{
*a1 = v5;
return 1LL;
}
errormsg(v6);
}
return result;
}

original_code:
int getint(int *number, int low, int high)
{
    int i, good = 0;
    char s[5], message[81];
    s[0] = 0;
    sprintf(message, "You must enter a number from %d to %d.", low, high);
    do {
        if (!editstring(s, "1234567890", 4))
            return(0);
        i = atoi(s);
        if ((good = ((i >= low) && (i <= high))) == 0)
            errormsg(message);
    }
    while (!good);
    *number = i;
    return(1);
}

canonical_original_code:
int getint(int *number, int low, int high)
{
    int i; int good = 0;
    char s[5]; char message[81];
    s[0] = 0;
    sprintf(message, "You must enter a number from %d to %d.", low, high);
    do {
        if (!editstring(s, "1234567890", 4))
            return(0);
        i = atoi(s);
        if ((good = ((i >= low) && (i <= high))) == 0)
            errormsg(message);
    }
    while (!good);
    *number = i;
    return(1);
}

variable_types:
number
int *

variable_types: low int

variable_types: high int

variable_types: i int

variable_types: good int

variable_types:
s
char [5]

variable_types:
message
char [81]


getcell

decompiled_code:
_BOOL8 __fastcall getcell(int *a1, int *a2)
{
int v3; // er12
_BOOL8 result; // rax
const __int32_t **v5; // rbp
int v6; // ebx
const unsigned __int16 **v7; // rax
__int64 v8; // rdx
char *v9; // rsi
int v10; // ebx
char *v11; // rbx
int v12; // ebp
char *v13; // rcx
int v14; // eax
int v15; // [rsp+8h] [rbp-50h]
int v16; // [rsp+Ch] [rbp-4Ch]
char dest[6]; // [rsp+10h] [rbp-48h] BYREF
char v18; // [rsp+16h] [rbp-42h] BYREF
char src; // [rsp+17h] [rbp-41h] BYREF
char v20; // [rsp+18h] [rbp-40h] BYREF

v3 = rowwidth(100LL);
v16 = *a1;
v15 = *a2;
v18 = 0;
while ( 1 )
{
result = editstring(&v18, (const char *)&unk_4B2, v3 + 2);
if ( !result )
break;
v5 = _ctype_toupper_loc();
v6 = (*v5)[v18] - 65;
*a1 = v6;
v7 = _ctype_b_loc();
v8 = src;
v9 = &src;
if ( ((*v7)[src] & 0x400) != 0 )
{
v10 = 26 * v6;
*a1 = v10;
*a1 = v10 + (*v5)[v8] - 39;
v9 = &v20;
}
if ( *a1 <= 99 && v3 > 0 )
{
v11 = v9;
v12 = 0;
while ( 1 )
{
v13 = v11++;
if ( ((*v7)[*(v11 - 1)] & 0x800) == 0 )
break;
if ( v3 == ++v12 )
goto LABEL_12;
}
if ( !v12 )
goto LABEL_4;
v11 = v13;
LABEL_12:
strncpy(dest, v9, v12);
dest[v12] = 0;
v14 = atoi(dest) - 1;
*a2 = v14;
if ( v14 <= 99 && v14 != -1 && !*v11 )
return 1LL;
}
LABEL_4:
errormsg("That is not a legal cell.");
}
*a1 = v16;
*a2 = v15;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int *a1, int *a2)
{
int v3; // er12
_BOOL8 result; // rax
const __int32_t **v5; // rbp
int v6; // ebx
const unsigned __int16 **v7; // rax
__int64 v8; // rdx
char *v9; // rsi
int v10; // ebx
char *v11; // rbx
int v12; // ebp
char *v13; // rcx
int v14; // eax
int v15; // [rsp+8h] [rbp-50h]
int v16; // [rsp+Ch] [rbp-4Ch]
char dest[6]; // [rsp+10h] [rbp-48h] BYREF
char v18; // [rsp+16h] [rbp-42h] BYREF
char src; // [rsp+17h] [rbp-41h] BYREF
char v20; // [rsp+18h] [rbp-40h] BYREF

v3 = rowwidth(100LL);
v16 = *a1;
v15 = *a2;
v18 = 0;
while ( 1 )
{
result = func1(&v18, (const char *)&unk_4B2, v3 + 2);
if ( !result )
break;
v5 = _ctype_toupper_loc();
v6 = (*v5)[v18] - 65;
*a1 = v6;
v7 = _ctype_b_loc();
v8 = src;
v9 = &src;
if ( ((*v7)[src] & 0x400) != 0 )
{
v10 = 26 * v6;
*a1 = v10;
*a1 = v10 + (*v5)[v8] - 39;
v9 = &v20;
}
if ( *a1 <= 99 && v3 > 0 )
{
v11 = v9;
v12 = 0;
while ( 1 )
{
v13 = v11++;
if ( ((*v7)[*(v11 - 1)] & 0x800) == 0 )
break;
if ( v3 == ++v12 )
goto LABEL_12;
}
if ( !v12 )
goto LABEL_4;
v11 = v13;
LABEL_12:
strncpy(dest, v9, v12);
dest[v12] = 0;
v14 = atoi(dest) - 1;
*a2 = v14;
if ( v14 <= 99 && v14 != -1 && !*v11 )
return 1LL;
}
LABEL_4:
errormsg("That is not a legal cell.");
}
*a1 = v16;
*a2 = v15;
return result;
}

original_code:
int getcell(int *col, int *row)
{
    int first = 1, good = 0, len, numlen = rowwidth(100),
        oldcol = *col, oldrow = *row;
    char data[10], *input, *start, numstring[6];
    data[0] = 0;
    do {
        if (!first)
            errormsg("That is not a legal cell.");
        first = 0;
        input = data;
        if (!editstring(data, "", numlen + 2)) {
            *col = oldcol;
            *row = oldrow;
            return(0);
        }
        *col = toupper(*(input++)) - 'A';
        if (((*__ctype_b_loc ())[(int) ((*input))] & (unsigned short int) _ISalpha)) {
            *col *= 26;
            *col += toupper(*(input++)) - 'A' + 26;
        }
        if (*col >= 100)
            continue;
        start = input;
        for (len = 0; len < numlen; len++) {
            if (!((*__ctype_b_loc ())[(int) ((*(input++)))] & (unsigned short int) _ISdigit)) {
                input--;
                break;
            }
        }
        if (len == 0)
            continue;
        strncpy(numstring, start, len);
        numstring[len] = 0;
        *row = atoi(numstring) - 1;
        if ((*row >= 100) || (*row == -1) || (*input != 0))
            continue;
        good = 1;
    }
    while (!good);
    return(1);
}

canonical_original_code:
int getcell(int *col, int *row)
{
    int first = 1; int good = 0; int len; int numlen = rowwidth(100); int oldcol = *col; int oldrow = *row;
    char data[10]; char *input; char *start; char numstring[6];
    data[0] = 0;
    do {
        if (!first)
            errormsg("That is not a legal cell.");
        first = 0;
        input = data;
        if (!editstring(data, "", numlen + 2)) {
            *col = oldcol;
            *row = oldrow;
            return(0);
        }
        *col = toupper(*(input++)) - 'A';
        if (((*__ctype_b_loc ())[(int) ((*input))] & (unsigned short) _ISalpha)) {
            *col *= 26;
            *col += toupper(*(input++)) - 'A' + 26;
        }
        if (*col >= 100)
            continue;
        start = input;
        for (len = 0; len < numlen; len++) {
            if (!((*__ctype_b_loc ())[(int) ((*(input++)))] & (unsigned short) _ISdigit)) {
                input--;
                break;
            }
        }
        if (len == 0)
            continue;
        strncpy(numstring, start, len);
        numstring[len] = 0;
        *row = atoi(numstring) - 1;
        if ((*row >= 100) || (*row == -1) || (*input != 0))
            continue;
        good = 1;
    }
    while (!good);
    return(1);
}

variable_types:
col
int *

variable_types:
row
int *

variable_types: first int

variable_types: numlen int

variable_types: oldcol int

variable_types: oldrow int

variable_types:
data
char [10]

variable_types:
input
char *

variable_types:
start
char *

variable_types:
numstring
char [6]


getyesno

decompiled_code:
__int64 __fastcall getyesno(int *a1, __int64 a2)
{
int v2; // eax
int v3; // esi

writeprompt(a2);
setcursor(shortcursor);
while ( 1 )
{
v2 = getkey();
v3 = toupper(v2);
*a1 = v3;
if ( v3 == 27 )
break;
if ( strchr("YN", v3) )
{
setcursor(nocursor);
return 1LL;
}
}
setcursor(nocursor);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, __int64 a2)
{
int v2; // eax
int v3; // esi

writeprompt(a2);
setcursor(shortcursor);
while ( 1 )
{
v2 = func0();
v3 = toupper(v2);
*a1 = v3;
if ( v3 == 27 )
break;
if ( strchr("YN", v3) )
{
setcursor(nocursor);
return 1LL;
}
}
setcursor(nocursor);
return 0LL;
}

original_code:
int getyesno(int *yesno, char *prompt)
{
    writeprompt(prompt);
    setcursor(shortcursor);
    do {
        *yesno = toupper(getkey());
        if (*yesno == 27) {
            setcursor(nocursor);
            return(0);
        }
    }
    while (strchr("YN", *yesno) == ((void *)0));
    setcursor(nocursor);
    return(1);
}

variable_types:
yesno
int *

variable_types:
prompt
char *


repo: lotabout/c-interfaces

decompiled_code:
__int64 __fastcall node_add_after(_QWORD *a1, __int64 *a2)
{
__int64 result; // rax

*a1 = *a2;
a1[1] = a2;
result = *a2;
*(_QWORD *)(*a2 + 8) = a1;
*a2 = (__int64)a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 *a2)
{
__int64 result; // rax

*a1 = *a2;
a1[1] = a2;
result = *a2;
*(_QWORD *)(*a2 + 8) = a1;
*a2 = (__int64)a1;
return result;
}

original_code:
static inline void node_add_after(struct node *new, struct node *n)
{
    new->next = n->next;
    new->prev = n;
    n->next->prev = new;
    n->next = new;
}

variable_types: struct node { struct node *next; struct node *prev; void *value; } *

variable_types:
n
struct node *


decompiled_code:
__int64 ring_new()
{
__int64 result; // rax

result = zcalloc(1LL, 32LL);
*(_QWORD *)result = result;
*(_QWORD *)(result + 8) = result;
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 24) = 0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

result = zcalloc(1LL, 32LL);
*(_QWORD *)result = result;
*(_QWORD *)(result + 8) = result;
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 24) = 0;
return result;
}

original_code:
ring_t ring_new(void)
{
    ring_t ring;
    ring = (ring_t)zcalloc(1, sizeof(*ring));
    ring->head.next = &ring->head;
    ring->head.prev = &ring->head;
    ring->head.value = ((void *)0);
    ring->length = 0;
    return ring;
}

canonical_original_code:
struct ring_t *ring_new()
{
    struct ring_t *ring;
    ring = (struct ring_t *)zcalloc(1, sizeof(*ring));
    ring->head.next = &ring->head;
    ring->head.prev = &ring->head;
    ring->head.value = ((void *)0);
    ring->length = 0;
    return ring;
}

variable_types: struct ring_t { struct node { struct node *next; struct node *prev; void *value; } head; int length; } *

user_defined_types: struct ring_t { struct node head; int length; }


decompiled_code:
void __fastcall ring_free(void **a1)
{
_QWORD **v2; // rbp
_QWORD *v3; // rbx
_QWORD *v4; // rdi

v2 = (_QWORD **)*a1;
v3 = *(_QWORD **)*a1;
if ( *a1 != v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
zfree(v4);
}
while ( v2 != v3 );
}
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
_QWORD **v2; // rbp
_QWORD *v3; // rbx
_QWORD *v4; // rdi

v2 = (_QWORD **)*a1;
v3 = *(_QWORD **)*a1;
if ( *a1 != v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
zfree(v4);
}
while ( v2 != v3 );
}
free(*a1);
*a1 = 0LL;
}

original_code:
void ring_free(ring_t *ring)
{
    struct node *p;
    struct node *q;
    struct node *head = &((*ring)->head);
    ((void) (0));
    for (p=head->next; p != head; p = q) {
        q = p->next;
        zfree(p);
    }
    free(*ring);
    *ring = ((void *)0);
}

canonical_original_code:
void ring_free(struct ring_t **ring)
{
    struct node *p;
    struct node *q;
    struct node *head = &((*ring)->head);
    ((void) (0));
    for (p=head->next; p != head; p = q) {
        q = p->next;
        zfree(p);
    }
    free(*ring);
    *ring = ((void *)0);
}

variable_types: struct ring_t { struct node { struct node *next; struct node *prev; void *value; } head; int length; } **


decompiled_code:
__int64 __fastcall ring_length(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
int ring_length(ring_t ring)
{
    ((void) (0));
    return ring->length;
}

canonical_original_code:
int ring_length(struct ring_t *ring)
{
    ((void) (0));
    return ring->length;
}

user_defined_types: struct node { struct node *next; struct node *prev; void *value; }


decompiled_code:
__int64 __fastcall ring_get(__int64 a1, int a2)
{
return ring_get_node(a1, a2)[2];
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return ring_get_node(a1, a2)[2];
}

original_code:
void *ring_get(ring_t ring, int idx)
{
    struct node *p;
    ((void) (0));
    ((void) (0));
    p = ring_get_node(ring, idx);
    return p->value;
}

canonical_original_code:
void *ring_get(struct ring_t *ring, int idx)
{
    struct node *p;
    ((void) (0));
    ((void) (0));
    p = ring_get_node(ring, idx);
    return p->value;
}

variable_types: idx int

return_type: void *


decompiled_code:
__int64 __fastcall ring_set(__int64 a1, int a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx

v4 = ring_get_node(a1, a2);
v5 = v4[2];
v4[2] = a3;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx

v4 = ring_get_node(a1, a2);
v5 = v4[2];
v4[2] = a3;
return v5;
}

original_code:
void *ring_set(ring_t ring, int idx, void *x)
{
    struct node *p;
    void *old_val;
    ((void) (0));
    ((void) (0));
    p = ring_get_node(ring, idx);
    old_val = p->value;
    p->value = x;
    return old_val;
}

canonical_original_code:
void *ring_set(struct ring_t *ring, int idx, void *x)
{
    struct node *p;
    void *old_val;
    ((void) (0));
    ((void) (0));
    p = ring_get_node(ring, idx);
    old_val = p->value;
    p->value = x;
    return old_val;
}

variable_types:
x
void *


decompiled_code:
__int64 __fastcall ring_add_before(__int64 a1, int a2, __int64 a3)
{
_QWORD *v4; // r12
_QWORD *v5; // rax

v4 = (_QWORD *)zalloc(24LL);
v4[2] = a3;
v5 = ring_get_node(a1, a2);
node_add_before(v4, (__int64)v5);
++*(_DWORD *)(a1 + 24);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, __int64 a3)
{
_QWORD *v4; // r12
_QWORD *v5; // rax

v4 = (_QWORD *)zalloc(24LL);
v4[2] = a3;
v5 = ring_get_node(a1, a2);
node_add_before(v4, (__int64)v5);
++*(_DWORD *)(a1 + 24);
return a3;
}

original_code:
void *ring_add_before(ring_t ring, int idx, void *x)
{
    ((void) (0));
    ((void) (0));
    struct node *p;
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    struct node *old;
    old = ring_get_node(ring, idx);
    node_add_before(p, old);
    ring->length ++;
    return x;
}

canonical_original_code:
void *ring_add_before(struct ring_t *ring, int idx, void *x)
{
    ((void) (0));
    ((void) (0));
    struct node *p;
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    struct node *old;
    old = ring_get_node(ring, idx);
    node_add_before(p, old);
    ring->length ++;
    return x;
}


decompiled_code:
__int64 __fastcall ring_add_after(__int64 a1, int a2, __int64 a3)
{
_QWORD *v4; // r12
__int64 *v5; // rax

v4 = (_QWORD *)zalloc(24LL);
v4[2] = a3;
v5 = ring_get_node(a1, a2);
node_add_after(v4, v5);
++*(_DWORD *)(a1 + 24);
return a3;
}

original_code:
void *ring_add_after(ring_t ring, int idx, void *x)
{
    ((void) (0));
    ((void) (0));
    struct node *p;
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    struct node *old;
    old = ring_get_node(ring, idx);
    node_add_after(p, old);
    ring->length ++;
    return x;
}

canonical_original_code:
void *ring_add_after(struct ring_t *ring, int idx, void *x)
{
    ((void) (0));
    ((void) (0));
    struct node *p;
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    struct node *old;
    old = ring_get_node(ring, idx);
    node_add_after(p, old);
    ring->length ++;
    return x;
}


decompiled_code:
__int64 __fastcall ring_addlo(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)zalloc(24LL);
v2[2] = a2;
node_add_after(v2, (__int64 *)a1);
++*(_DWORD *)(a1 + 24);
return a2;
}

original_code:
void *ring_addlo(ring_t ring, void *x)
{
    struct node *p;
    struct node *head = &(ring->head);
    ((void) (0));
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    node_add_after(p, head);
    ring->length++;
    return x;
}

canonical_original_code:
void *ring_addlo(struct ring_t *ring, void *x)
{
    struct node *p;
    struct node *head = &(ring->head);
    ((void) (0));
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    node_add_after(p, head);
    ring->length++;
    return x;
}


decompiled_code:
__int64 __fastcall ring_addhi(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)zalloc(24LL);
v2[2] = a2;
node_add_before(v2, a1);
++*(_DWORD *)(a1 + 24);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)zalloc(24LL);
v2[2] = a2;
node_add_before(v2, a1);
++*(_DWORD *)(a1 + 24);
return a2;
}

original_code:
void *ring_addhi(ring_t ring, void *x)
{
    struct node *p;
    struct node *head = &(ring->head);
    ((void) (0));
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    node_add_before(p, head);
    ring->length++;
    return x;
}

canonical_original_code:
void *ring_addhi(struct ring_t *ring, void *x)
{
    struct node *p;
    struct node *head = &(ring->head);
    ((void) (0));
    p = (struct node *)zalloc(sizeof(*p));
    p->value = x;
    node_add_before(p, head);
    ring->length++;
    return x;
}


decompiled_code:
__int64 __fastcall ring_remove(__int64 a1, int a2)
{
_QWORD *v2; // rbp
__int64 v3; // r12

v2 = ring_get_node(a1, a2);
v3 = v2[2];
node_del(v2);
zfree(v2);
--*(_DWORD *)(a1 + 24);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
_QWORD *v2; // rbp
__int64 v3; // r12

v2 = ring_get_node(a1, a2);
v3 = v2[2];
node_del(v2);
zfree(v2);
--*(_DWORD *)(a1 + 24);
return v3;
}

original_code:
void *ring_remove(ring_t ring, int idx)
{
    ((void) (0));
    ((void) (0));
    ((void) (0));
    void *x;
    struct node *p;
    p = ring_get_node(ring, idx);
    x = p->value;
    node_del(p);
    zfree(p);
    ring->length --;
    return x;
}

canonical_original_code:
void *ring_remove(struct ring_t *ring, int idx)
{
    ((void) (0));
    ((void) (0));
    ((void) (0));
    void *x;
    struct node *p;
    p = ring_get_node(ring, idx);
    x = p->value;
    node_del(p);
    zfree(p);
    ring->length --;
    return x;
}


decompiled_code:
__int64 __fastcall ring_remlo(_DWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // r12

v1 = *(_QWORD *)a1;
v2 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
node_del(*(_QWORD **)a1);
zfree(v1);
--a1[6];
return v2;
}

original_code:
void *ring_remlo(ring_t ring)
{
    ((void) (0));
    ((void) (0));
    void *x;
    struct node *p;
    p = ring->head.next;
    x = p->value;
    node_del(p);
    zfree(p);
    ring->length --;
    return x;
}

canonical_original_code:
void *ring_remlo(struct ring_t *ring)
{
    ((void) (0));
    ((void) (0));
    void *x;
    struct node *p;
    p = ring->head.next;
    x = p->value;
    node_del(p);
    zfree(p);
    ring->length --;
    return x;
}


original_code:
void *ring_remhi(ring_t ring)
{
    ((void) (0));
    ((void) (0));
    void *x;
    struct node *p;
    p = ring->head.prev;
    x = p->value;
    node_del(p);
    zfree(p);
    ring->length --;
    return x;
}

canonical_original_code:
void *ring_remhi(struct ring_t *ring)
{
    ((void) (0));
    ((void) (0));
    void *x;
    struct node *p;
    p = ring->head.prev;
    x = p->value;
    node_del(p);
    zfree(p);
    ring->length --;
    return x;
}


decompiled_code:
unsigned __int64 __fastcall default_hash(unsigned __int64 a1)
{
return a1 >> 2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1)
{
return a1 >> 2;
}

original_code:
static unsigned default_hash(const void *key)
{
    return (unsigned long)key >> 2;
}

canonical_original_code:
static unsigned int default_hash(void *key)
{
    return (unsigned long)key >> 2;
}

variable_types:
key
void *

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall default_cmp(__int64 a1, __int64 a2)
{
return a2 != a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
return a2 != a1;
}

original_code:
static int default_cmp(const void *a, const void *b)
{
    return a != b;
}

canonical_original_code:
static int default_cmp(void *a, void *b)
{
    return a != b;
}

variable_types:
a
void *

variable_types:
b
void *


original_code:
set_t set_new(int hint, int cmp(const void *a, const void *b),
          unsigned hash(const void *x))
{
    set_t set;
    int i;
    static int primes[] = {509, 509, 1021, 2053, 4093, 8191, 16381, 32771,
        65521, 0x7fffffff};
    ((void) (0));
    for (i = 1; primes[i] < hint; i++) {
    }
    set = (set_t)zalloc(sizeof(*set) + primes[i-1]*sizeof(set->buckets[0]));
    set->size = primes[i-1];
    set->cmp = cmp ? cmp : default_cmp;
    set->hash = hash ? hash : default_hash;
    set->buckets = (struct member **)(set + 1);
    for (i = 0; i < set->size; i++) {
        set->buckets[i] = ((void *)0);
    }
    set->length = 0;
    set->timestamp = 0;
    return set;
}

canonical_original_code:
struct set_t *set_new(int hint, int cmp(void *a, void *b), unsigned int hash(void *x))
{
    struct set_t *set;
    int i;
    static int primes[] = {509, 509, 1021, 2053, 4093, 8191, 16381, 32771,
        65521, 0x7fffffff};
    ((void) (0));
    for (i = 1; primes[i] < hint; i++) {
    }
    set = (struct set_t *)zalloc(sizeof(*set) + primes[i-1]*sizeof(set->buckets[0]));
    set->size = primes[i-1];
    set->cmp = cmp ? cmp : default_cmp;
    set->hash = hash ? hash : default_hash;
    set->buckets = (struct member **)(set + 1);
    for (i = 0; i < set->size; i++) {
        set->buckets[i] = ((void *)0);
    }
    set->length = 0;
    set->timestamp = 0;
    return set;
}

variable_types: hint int

variable_types:
cmp
int (void *a, void *b)

variable_types:
hash
unsigned int (void *x)

variable_types: struct set_t { int length; unsigned int timestamp; int (*cmp)(void *a, void *b); unsigned int (*hash)(void *x); int size; struct member { struct member *link; void *member; } **buckets; } *

variable_types: i int

variable_types:
primes
int []

user_defined_types: struct set_t { int length; unsigned int timestamp; int (*cmp)(void *a, void *b); unsigned int (*hash)(void *x); int size; struct member **buckets; }


decompiled_code:
bool __fastcall set_member(__int64 a1, __int64 a2)
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(*(_QWORD *)(a1 + 32)
+ 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 24)));
i;
i = (_QWORD *)*i )
{
if ( !(*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, i[1]) )
break;
}
return i != 0LL;
}

original_code:
_Bool set_member(set_t set, const void *member)
{
    struct member *p = ((void *)0);
    ((void) (0));
    ((void) (0));
    unsigned hash_val = 0;
    hash_val = (*set->hash)(member) % set->size;
    for (p = set->buckets[hash_val]; p; p = p->link) {
        if ((*set->cmp)(member, p->member) == 0) {
            break;
        }
    }
    return p != ((void *)0);
}

canonical_original_code:
_Bool set_member(struct set_t *set, void *member)
{
    struct member *p = ((void *)0);
    ((void) (0));
    ((void) (0));
    unsigned int hash_val = 0;
    hash_val = (*set->hash)(member) % set->size;
    for (p = set->buckets[hash_val]; p; p = p->link) {
        if ((*set->cmp)(member, p->member) == 0) {
            break;
        }
    }
    return p != ((void *)0);
}

variable_types:
member
void *

variable_types: struct member { struct member *link; void *member; } *


decompiled_code:
__int64 __fastcall set_length(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
return *a1;
}

original_code:
int set_length(set_t set)
{
    ((void) (0));
    return set->length;
}

canonical_original_code:
int set_length(struct set_t *set)
{
    ((void) (0));
    return set->length;
}

user_defined_types: struct member { struct member *link; void *member; }


decompiled_code:
__int64 __fastcall set_map(__int64 a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
__int64 v4; // r13
__int64 result; // rax
_QWORD *i; // rbx

if ( *(int *)(a1 + 24) > 0 )
{
v4 = 0LL;
do
{
result = *(_QWORD *)(a1 + 32);
for ( i = *(_QWORD **)(result + 8 * v4); i; i = (_QWORD *)*i )
result = a2(i[1], a3);
++v4;
}
while ( *(_DWORD *)(a1 + 24) > (int)v4 );
}
return result;
}

original_code:
void set_map(set_t set, void apply(const void *member, void *cl), void *cl)
{
    int i;
    struct member *p;
    ((void) (0));
    ((void) (0));
    unsigned timestamp = set->timestamp;
    for (i = 0; i < set->size; i++) {
        for (p=set->buckets[i]; p; p=p->link) {
            apply(p->member, cl);
            ((void) (0));
        }
    }
}

canonical_original_code:
void set_map(struct set_t *set, void apply(void *member, void *cl), void *cl)
{
    int i;
    struct member *p;
    ((void) (0));
    ((void) (0));
    unsigned int timestamp = set->timestamp;
    for (i = 0; i < set->size; i++) {
        for (p=set->buckets[i]; p; p=p->link) {
            apply(p->member, cl);
            ((void) (0));
        }
    }
}

variable_types:
apply
void (void *member, void *cl)

variable_types:
cl
void *

variable_types:
timestamp
unsigned int


original_code:
set_t set_minus(set_t s, set_t t)
{
    if (s == ((void *)0)) {
        ((void) (0));
        return set_new(t->size, t->cmp, t->hash);
    } else if (t == ((void *)0)) {
        ((void) (0));
        return copy(s, s->size);
    } else {
        set_t set = set_new(s->size, s->cmp, s->hash);
        ((void) (0));
        int i;
        struct member *q;
        struct member *p;
        unsigned hash_val;
        for (i = 0; i < s->size; i++) {
            for (q = s->buckets[i]; q; q = q->link) {
                if (!set_member(t, q->member)) {
                    p = (struct member *)zalloc(sizeof(*p));
                    p->member = q->member;
                    hash_val = set->hash(p->member) % set->size;
                    p->link = set->buckets[hash_val];
                    set->buckets[hash_val] = p;
                    set->length ++;
                }
            }
        }
        return set;
    }
}

canonical_original_code:
struct set_t *set_minus(struct set_t *s, struct set_t *t)
{
    if (s == ((void *)0)) {
        ((void) (0));
        return set_new(t->size, t->cmp, t->hash);
    } else if (t == ((void *)0)) {
        ((void) (0));
        return copy(s, s->size);
    } else {
        struct set_t *set = set_new(s->size, s->cmp, s->hash);
        ((void) (0));
        int i;
        struct member *q;
        struct member *p;
        unsigned int hash_val;
        for (i = 0; i < s->size; i++) {
            for (q = s->buckets[i]; q; q = q->link) {
                if (!set_member(t, q->member)) {
                    p = (struct member *)zalloc(sizeof(*p));
                    p->member = q->member;
                    hash_val = set->hash(p->member) % set->size;
                    p->link = set->buckets[hash_val];
                    set->buckets[hash_val] = p;
                    set->length ++;
                }
            }
        }
        return set;
    }
}

variable_types:
s
struct set_t *

variable_types:
t
struct set_t *

return_type: struct set_t { int length; unsigned int timestamp; int (*cmp)(void *a, void *b); unsigned int (*hash)(void *x); int size; struct member { struct member *link; void *member; } **buckets; } *


original_code:
set_t set_diff(set_t s, set_t t)
{
    if (s == ((void *)0)) {
        ((void) (0));
        return copy(t, t->size);
    } else if (t == ((void *)0)) {
        return copy(s, s->size);
    } else {
        set_t set = set_new(min(s->size, t->size), s->cmp, t->hash);
        ((void) (0));
        int i;
        struct member *p;
        struct member *q;
        unsigned hash_val = 0;
        for (i = 0; i < s->size; i++) {
            for (p = s->buckets[i]; p; p = p->link) {
                if (! set_member(t, p->member)) {
                    q = (struct member *)zalloc(sizeof(*q));
                    q->member = p->member;
                    hash_val = set->hash(q->member) % set->size;
                    q->link = set->buckets[hash_val];
                    set->buckets[hash_val] = q;
                    set->length ++;
                }
            }
        }
        set_t u = t;
        t = s;
        s = u;
        for (i = 0; i < s->size; i++) {
            for (p = s->buckets[i]; p; p = p->link) {
                if (! set_member(t, p->member)) {
                    q = (struct member *)zalloc(sizeof(*q));
                    q->member = p->member;
                    hash_val = set->hash(q->member) % set->size;
                    q->link = set->buckets[hash_val];
                    set->buckets[hash_val] = q;
                    set->length ++;
                }
            }
        }
        return set;
    }
}

canonical_original_code:
struct set_t *set_diff(struct set_t *s, struct set_t *t)
{
    if (s == ((void *)0)) {
        ((void) (0));
        return copy(t, t->size);
    } else if (t == ((void *)0)) {
        return copy(s, s->size);
    } else {
        struct set_t *set = set_new(min(s->size, t->size), s->cmp, t->hash);
        ((void) (0));
        int i;
        struct member *p;
        struct member *q;
        unsigned int hash_val = 0;
        for (i = 0; i < s->size; i++) {
            for (p = s->buckets[i]; p; p = p->link) {
                if (! set_member(t, p->member)) {
                    q = (struct member *)zalloc(sizeof(*q));
                    q->member = p->member;
                    hash_val = set->hash(q->member) % set->size;
                    q->link = set->buckets[hash_val];
                    set->buckets[hash_val] = q;
                    set->length ++;
                }
            }
        }
        struct set_t *u = t;
        t = s;
        s = u;
        for (i = 0; i < s->size; i++) {
            for (p = s->buckets[i]; p; p = p->link) {
                if (! set_member(t, p->member)) {
                    q = (struct member *)zalloc(sizeof(*q));
                    q->member = p->member;
                    hash_val = set->hash(q->member) % set->size;
                    q->link = set->buckets[hash_val];
                    set->buckets[hash_val] = q;
                    set->length ++;
                }
            }
        }
        return set;
    }
}


copy

original_code:
static set_t copy(set_t t, int hint)
{
    set_t set;
    ((void) (0));
    set = set_new(hint, t->cmp, t->hash);
    int i;
    struct member *q;
    struct member *p;
    unsigned hash_val = 0;
    for (i = 0; i < t->size; i++) {
        for (q = t->buckets[i]; q; q = q->link) {
            p = (struct member *)zalloc(sizeof(*p));
            p->member = q->member;
            hash_val = set->hash(p->member) % set->size;
            p->link = set->buckets[hash_val];
            set->buckets[hash_val] = p;
            set->length ++;
        }
    }
    return set;
}

canonical_original_code:
static struct set_t *copy(struct set_t *t, int hint)
{
    struct set_t *set;
    ((void) (0));
    set = set_new(hint, t->cmp, t->hash);
    int i;
    struct member *q;
    struct member *p;
    unsigned int hash_val = 0;
    for (i = 0; i < t->size; i++) {
        for (q = t->buckets[i]; q; q = q->link) {
            p = (struct member *)zalloc(sizeof(*p));
            p->member = q->member;
            hash_val = set->hash(p->member) % set->size;
            p->link = set->buckets[hash_val];
            set->buckets[hash_val] = p;
            set->length ++;
        }
    }
    return set;
}


original_code:
seq_t seq_new(int hint)
{
    seq_t seq;
    ((void) (0));
    seq = (seq_t)zcalloc(1, sizeof(*seq));
    if (hint == 0) {
        hint = 16;
    }
    seq->data = (void **)zcalloc(hint, sizeof(*seq->data));
    seq->nmemb = hint;
    seq->length = 0;
    seq->head = 0;
    return seq;
}

canonical_original_code:
struct seq_t *seq_new(int hint)
{
    struct seq_t *seq;
    ((void) (0));
    seq = (struct seq_t *)zcalloc(1, sizeof(*seq));
    if (hint == 0) {
        hint = 16;
    }
    seq->data = (void **)zcalloc(hint, sizeof(*seq->data));
    seq->nmemb = hint;
    seq->length = 0;
    seq->head = 0;
    return seq;
}

variable_types: struct seq_t { void **data; int nmemb; int length; int head; } *


decompiled_code:
__int64 __fastcall seq_length(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int seq_length(seq_t seq)
{
    ((void) (0));
    return seq->length;
}

canonical_original_code:
int seq_length(struct seq_t *seq)
{
    ((void) (0));
    return seq->length;
}

user_defined_types: struct seq_t { void **data; int nmemb; int length; int head; }


original_code:
void *seq_get(seq_t seq, int idx)
{
    ((void) (0));
    ((void) (0));
    return (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
}

canonical_original_code:
void *seq_get(struct seq_t *seq, int idx)
{
    ((void) (0));
    ((void) (0));
    return (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
}

variable_types: idx int


original_code:
void *seq_put(seq_t seq, int idx, void *x)
{
    ((void) (0));
    ((void) (0));
    void *prev = (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
    (seq->data[(seq->head + (idx)) % (seq->nmemb)]) = x;
    return prev;
}

canonical_original_code:
void *seq_put(struct seq_t *seq, int idx, void *x)
{
    ((void) (0));
    ((void) (0));
    void *prev = (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
    (seq->data[(seq->head + (idx)) % (seq->nmemb)]) = x;
    return prev;
}

variable_types:
x
void *

variable_types:
prev
void *


original_code:
void *seq_remlo(seq_t seq)
{
    int idx = 0;
    void *x;
    ((void) (0));
    ((void) (0));
    x = (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
    seq->head = (seq->head + 1) % seq->nmemb;
    --seq->length;
    return x;
}

canonical_original_code:
void *seq_remlo(struct seq_t *seq)
{
    int idx = 0;
    void *x;
    ((void) (0));
    ((void) (0));
    x = (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
    seq->head = (seq->head + 1) % seq->nmemb;
    --seq->length;
    return x;
}


original_code:
void *seq_remhi(seq_t seq)
{
    ((void) (0));
    ((void) (0));
    int idx;
    idx = --seq->length;
    return (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
}

canonical_original_code:
void *seq_remhi(struct seq_t *seq)
{
    ((void) (0));
    ((void) (0));
    int idx;
    idx = --seq->length;
    return (seq->data[(seq->head + (idx)) % (seq->nmemb)]);
}


original_code:
void *seq_addhi(seq_t seq, void *x)
{
    ((void) (0));
    if (seq->length == seq->nmemb) {
        seq_expand(seq);
    }
    int idx = seq->length ++;
    (seq->data[(seq->head + (idx)) % (seq->nmemb)]) = x;
    return x;
}

canonical_original_code:
void *seq_addhi(struct seq_t *seq, void *x)
{
    ((void) (0));
    if (seq->length == seq->nmemb) {
        seq_expand(seq);
    }
    int idx = seq->length ++;
    (seq->data[(seq->head + (idx)) % (seq->nmemb)]) = x;
    return x;
}


original_code:
void *seq_addlo(seq_t seq, void *x)
{
    int idx = 0;
    ((void) (0));
    if (seq->length == seq->nmemb) {
        seq_expand(seq);
    }
    if (--seq->head < 0) {
        seq->head = seq->nmemb - 1;
    }
    seq->length ++;
    (seq->data[(seq->head + (idx)) % (seq->nmemb)]) = x;
    return x;
}

canonical_original_code:
void *seq_addlo(struct seq_t *seq, void *x)
{
    int idx = 0;
    ((void) (0));
    if (seq->length == seq->nmemb) {
        seq_expand(seq);
    }
    if (--seq->head < 0) {
        seq->head = seq->nmemb - 1;
    }
    seq->length ++;
    (seq->data[(seq->head + (idx)) % (seq->nmemb)]) = x;
    return x;
}


decompiled_code:
__int64 __fastcall set_cmp_int(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int set_cmp_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

canonical_original_code:
int set_cmp_int(void *a, void *b)
{
    return *(int *)a - *(int *)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall set_hash_int(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned set_hash_int(const void *x)
{
    return *(int *)x;
}

canonical_original_code:
unsigned int set_hash_int(void *x)
{
    return *(int *)x;
}


decompiled_code:
__int64 __fastcall cmp_int(const void *a1, const void *a2)
{
return (unsigned int)(**(_DWORD **)a1 - **(_DWORD **)a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(const void *a1, const void *a2)
{
return (unsigned int)(**(_DWORD **)a1 - **(_DWORD **)a2);
}

original_code:
int cmp_int(const void *a, const void *b)
{
    return **(int **)a - **(int **)b;
}

canonical_original_code:
int cmp_int(void *a, void *b)
{
    return **(int **)a - **(int **)b;
}


cmp

decompiled_code:
int __fastcall cmp(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func5(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
int cmp(const void *a, const void *b)
{
    return strcmp(*(char **)a, *(char **)b);
}

canonical_original_code:
int cmp(void *a, void *b)
{
    return strcmp(*(char **)a, *(char **)b);
}


decompiled_code:
const char *test_resize()
{
const char *result; // rax
_DWORD *v1; // rdx

array_resize(ary_a, 5LL);
if ( (unsigned int)array_size(ary_a) == 4 )
{
if ( (unsigned int)array_length(ary_a) == 5 )
{
if ( *(_DWORD *)array_get(ary_a, 0LL) )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 61LL);
result = "array_resize error";
}
else if ( *(_DWORD *)array_get(ary_a, 1LL) == 1 )
{
if ( *(_DWORD *)array_get(ary_a, 2LL) == 2 )
{
if ( *(_DWORD *)array_get(ary_a, 3LL) == 3 )
{
v1 = (_DWORD *)array_get(ary_a, 4LL);
result = 0LL;
if ( *v1 != 4 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 69LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 67LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 65LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 63LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error.\n", "tests/array_tests.c", 57LL);
result = "array_resize error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error.\n", "tests/array_tests.c", 56LL);
result = "array_resize error.\n";
}
return result;
}

canonical_decompiled_code:
const char *func9()
{
const char *result; // rax
_DWORD *v1; // rdx

func20(ary_a, 5LL);
if ( (unsigned int)func19(ary_a) == 4 )
{
if ( (unsigned int)func18(ary_a) == 5 )
{
if ( *(_DWORD *)func16(ary_a, 0LL) )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 61LL);
result = "array_resize error";
}
else if ( *(_DWORD *)func16(ary_a, 1LL) == 1 )
{
if ( *(_DWORD *)func16(ary_a, 2LL) == 2 )
{
if ( *(_DWORD *)func16(ary_a, 3LL) == 3 )
{
v1 = (_DWORD *)func16(ary_a, 4LL);
result = 0LL;
if ( *v1 != 4 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 69LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 67LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 65LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 63LL);
result = "array_resize error";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error.\n", "tests/array_tests.c", 57LL);
result = "array_resize error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error.\n", "tests/array_tests.c", 56LL);
result = "array_resize error.\n";
}
return result;
}

original_code:
char *test_resize()
{
    array_resize(ary_a, 5);
    if (!(array_size(ary_a)==sizeof(int))) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_resize error.\n", "tests/array_tests.c", 56);; return "array_resize error.\n"; };
    if (!(array_length(ary_a)==5)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_resize error.\n", "tests/array_tests.c", 57);; return "array_resize error.\n"; };
    int *x;
    x = (int *)array_get(ary_a, 0);
    if (!(*x == 0)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_resize error", "tests/array_tests.c", 61);; return "array_resize error"; }
    x = (int *)array_get(ary_a, 1);
    if (!(*x == 1)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_resize error", "tests/array_tests.c", 63);; return "array_resize error"; }
    x = (int *)array_get(ary_a, 2);
    if (!(*x == 2)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_resize error", "tests/array_tests.c", 65);; return "array_resize error"; }
    x = (int *)array_get(ary_a, 3);
    if (!(*x == 3)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_resize error", "tests/array_tests.c", 67);; return "array_resize error"; }
    x = (int *)array_get(ary_a, 4);
    if (!(*x == 4)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_resize error", "tests/array_tests.c", 69);; return "array_resize error"; }
    return ((void *)0);
}

variable_types:
x
int *


decompiled_code:
__int64 __fastcall array_get(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * a2;
}

original_code:
void *array_get(array_t array, int idx)
{
    ((void) (0));
    ((void) (0));
    return array->array + idx * array->size;
}

canonical_original_code:
void *array_get(struct array_t *array, int idx)
{
    ((void) (0));
    ((void) (0));
    return array->array + idx * array->size;
}

variable_types: struct array_t { int nmemb; int size; char *array; } *


decompiled_code:
const void *__fastcall array_put(__int64 a1, int a2, const void *a3)
{
memcpy((void *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * a2), a3, *(int *)(a1 + 4));
return a3;
}

canonical_decompiled_code:
const void *__fastcall func17(__int64 a1, int a2, const void *a3)
{
memcpy((void *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * a2), a3, *(int *)(a1 + 4));
return a3;
}

original_code:
void *array_put(array_t array, int idx, void *elem)
{
    ((void) (0));
    ((void) (0));
    ((void) (0));
    memcpy(array->array + idx*array->size, elem, array->size);
    return elem;
}

canonical_original_code:
void *array_put(struct array_t *array, int idx, void *elem)
{
    ((void) (0));
    ((void) (0));
    ((void) (0));
    memcpy(array->array + idx*array->size, elem, array->size);
    return elem;
}

variable_types:
elem
void *

user_defined_types: struct array_t { int nmemb; int size; char *array; }


decompiled_code:
__int64 __fastcall array_length(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int *a1)
{
return *a1;
}

original_code:
int array_length(array_t array)
{
    ((void) (0));
    return array->nmemb;
}

canonical_original_code:
int array_length(struct array_t *array)
{
    ((void) (0));
    return array->nmemb;
}


decompiled_code:
__int64 __fastcall array_size(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int array_size(array_t array)
{
    ((void) (0));
    return array->size;
}

canonical_original_code:
int array_size(struct array_t *array)
{
    ((void) (0));
    return array->size;
}


decompiled_code:
__int64 __fastcall array_resize(__int64 a1, signed int a2)
{
__int64 result; // rax
void *v3; // r12
int v4; // eax

if ( a2 )
{
if ( *(_DWORD *)a1 )
{
v3 = (void *)zcalloc(a2, *(int *)(a1 + 4));
v4 = min(*(_DWORD *)a1, a2);
memcpy(v3, *(const void **)(a1 + 8), *(_DWORD *)(a1 + 4) * v4);
result = zfree(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = v3;
}
else
{
result = zalloc(*(_DWORD *)(a1 + 4) * a2);
*(_QWORD *)(a1 + 8) = result;
}
}
else
{
result = zfree(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
}
*(_DWORD *)a1 = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, signed int a2)
{
__int64 result; // rax
void *v3; // r12
int v4; // eax

if ( a2 )
{
if ( *(_DWORD *)a1 )
{
v3 = (void *)func24(a2, *(int *)(a1 + 4));
v4 = func13(*(_DWORD *)a1, a2);
memcpy(v3, *(const void **)(a1 + 8), *(_DWORD *)(a1 + 4) * v4);
result = func23(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = v3;
}
else
{
result = func22(*(_DWORD *)(a1 + 4) * a2);
*(_QWORD *)(a1 + 8) = result;
}
}
else
{
result = func23(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
}
*(_DWORD *)a1 = a2;
return result;
}

original_code:
void array_resize(array_t array, int nmemb)
{
    ((void) (0));
    ((void) (0));
    if (nmemb == 0) {
        zfree(array->array);
        array->array = ((void *)0);
    } else if (array->nmemb == 0) {
        array->array =(char *)zalloc(nmemb * array->size);
    } else {
        void *p = zcalloc(nmemb, array->size);
        memcpy(p, array->array, min(array->nmemb, nmemb) * array->size);
        zfree(array->array);
        array->array = (char *)p;
    }
    array->nmemb = nmemb;
}

canonical_original_code:
void array_resize(struct array_t *array, int nmemb)
{
    ((void) (0));
    ((void) (0));
    if (nmemb == 0) {
        zfree(array->array);
        array->array = ((void *)0);
    } else if (array->nmemb == 0) {
        array->array =(char *)zalloc(nmemb * array->size);
    } else {
        void *p = zcalloc(nmemb, array->size);
        memcpy(p, array->array, min(array->nmemb, nmemb) * array->size);
        zfree(array->array);
        array->array = (char *)p;
    }
    array->nmemb = nmemb;
}

variable_types: nmemb int

variable_types:
p
void *


zalloc

decompiled_code:
void *__fastcall zalloc(size_t a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func22(size_t a1)
{
return malloc(a1);
}

original_code:
void *zalloc(size_t size)
{
    void *p = malloc(size);
    ((void) (0));
    return p;
}

canonical_original_code:
void *zalloc(unsigned long size)
{
    void *p = malloc(size);
    ((void) (0));
    return p;
}

variable_types:
size
unsigned long


zfree

decompiled_code:
void __fastcall zfree(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func23(void *a1)
{
free(a1);
}

original_code:
void zfree(void *ptr)
{
    ((void) (0));
    free(ptr);
}

variable_types:
ptr
void *


zcalloc

decompiled_code:
void *__fastcall zcalloc(size_t a1, size_t a2)
{
return calloc(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func24(size_t a1, size_t a2)
{
return calloc(a1, a2);
}

original_code:
void *zcalloc(size_t nmemb, size_t size)
{
    void *p = calloc(nmemb, size);
    ((void) (0));
    return p;
}

canonical_original_code:
void *zcalloc(unsigned long nmemb, unsigned long size)
{
    void *p = calloc(nmemb, size);
    ((void) (0));
    return p;
}

variable_types:
nmemb
unsigned long


decompiled_code:
const char *test_new()
{
__int64 v0; // rax
const char *result; // rax
int v2; // edx

v0 = array_new(10LL, 4LL);
ary_a = v0;
if ( v0 )
{
if ( (unsigned int)array_length(v0) == 10 )
{
v2 = array_size(ary_a);
result = 0LL;
if ( v2 != 4 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_new error.\n", "tests/array_tests.c", 13LL);
result = "array_new error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_new error.\n", "tests/array_tests.c", 12LL);
result = "array_new error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_new error.\n", "tests/array_tests.c", 11LL);
result = "array_new error.\n";
}
return result;
}

canonical_decompiled_code:
const char *func7()
{
__int64 v0; // rax
const char *result; // rax
int v2; // edx

v0 = func14(10LL, 4LL);
ary_a = v0;
if ( v0 )
{
if ( (unsigned int)func18(v0) == 10 )
{
v2 = func19(ary_a);
result = 0LL;
if ( v2 != 4 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_new error.\n", "tests/array_tests.c", 13LL);
result = "array_new error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_new error.\n", "tests/array_tests.c", 12LL);
result = "array_new error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_new error.\n", "tests/array_tests.c", 11LL);
result = "array_new error.\n";
}
return result;
}

original_code:
char *test_new()
{
    ary_a = array_new(10, sizeof(int));
    if (!(ary_a != ((void *)0))) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_new error.\n", "tests/array_tests.c", 11);; return "array_new error.\n"; };
    if (!(array_length(ary_a) == 10)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_new error.\n", "tests/array_tests.c", 12);; return "array_new error.\n"; };
    if (!(array_size(ary_a) == sizeof(int))) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_new error.\n", "tests/array_tests.c", 13);; return "array_new error.\n"; };
    return ((void *)0);
}


decompiled_code:
const char *test_put_get()
{
const char *result; // rax
_DWORD *v1; // rdx

if ( (_UNKNOWN *)array_put(ary_a, 0LL, &int_vals) == &int_vals )
{
if ( (_UNKNOWN *)array_put(ary_a, 1LL, &unk_404084) == &unk_404084 )
{
if ( (_UNKNOWN *)array_put(ary_a, 2LL, &unk_404088) == &unk_404088 )
{
if ( (_UNKNOWN *)array_put(ary_a, 3LL, &unk_40408C) == &unk_40408C )
{
if ( (_UNKNOWN *)array_put(ary_a, 4LL, &unk_404090) == &unk_404090 )
{
if ( (_UNKNOWN *)array_put(ary_a, 5LL, &unk_404094) == &unk_404094 )
{
if ( (_UNKNOWN *)array_put(ary_a, 6LL, &unk_404098) == &unk_404098 )
{
if ( *(_DWORD *)array_get(ary_a, 0LL) )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 36LL);
result = "array_get error.\n";
}
else if ( *(_DWORD *)array_get(ary_a, 1LL) == 1 )
{
if ( *(_DWORD *)array_get(ary_a, 2LL) == 2 )
{
if ( *(_DWORD *)array_get(ary_a, 3LL) == 3 )
{
if ( *(_DWORD *)array_get(ary_a, 4LL) == 4 )
{
if ( *(_DWORD *)array_get(ary_a, 5LL) == 5 )
{
v1 = (_DWORD *)array_get(ary_a, 6LL);
result = 0LL;
if ( *v1 != 6 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 48LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 46LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 44LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 42LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 40LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 38LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 33LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 31LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 29LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 27LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 25LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 23LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 21LL);
result = "array_put error.\n";
}
return result;
}

canonical_decompiled_code:
const char *func8()
{
const char *result; // rax
_DWORD *v1; // rdx

if ( (_UNKNOWN *)func17(ary_a, 0LL, &int_vals) == &int_vals )
{
if ( (_UNKNOWN *)func17(ary_a, 1LL, &unk_404084) == &unk_404084 )
{
if ( (_UNKNOWN *)func17(ary_a, 2LL, &unk_404088) == &unk_404088 )
{
if ( (_UNKNOWN *)func17(ary_a, 3LL, &unk_40408C) == &unk_40408C )
{
if ( (_UNKNOWN *)func17(ary_a, 4LL, &unk_404090) == &unk_404090 )
{
if ( (_UNKNOWN *)func17(ary_a, 5LL, &unk_404094) == &unk_404094 )
{
if ( (_UNKNOWN *)func17(ary_a, 6LL, &unk_404098) == &unk_404098 )
{
if ( *(_DWORD *)func16(ary_a, 0LL) )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 36LL);
result = "array_get error.\n";
}
else if ( *(_DWORD *)func16(ary_a, 1LL) == 1 )
{
if ( *(_DWORD *)func16(ary_a, 2LL) == 2 )
{
if ( *(_DWORD *)func16(ary_a, 3LL) == 3 )
{
if ( *(_DWORD *)func16(ary_a, 4LL) == 4 )
{
if ( *(_DWORD *)func16(ary_a, 5LL) == 5 )
{
v1 = (_DWORD *)func16(ary_a, 6LL);
result = 0LL;
if ( *v1 != 6 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 48LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 46LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 44LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 42LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 40LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_get error.\n", "tests/array_tests.c", 38LL);
result = "array_get error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 33LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 31LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 29LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 27LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 25LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 23LL);
result = "array_put error.\n";
}
}
else
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_put error.\n", "tests/array_tests.c", 21LL);
result = "array_put error.\n";
}
return result;
}

original_code:
char *test_put_get()
{
    int * x;
    x = (int *)array_put(ary_a, 0, &int_vals[0]);
    if (!(x == &int_vals[0])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 21);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 1, &int_vals[1]);
    if (!(x == &int_vals[1])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 23);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 2, &int_vals[2]);
    if (!(x == &int_vals[2])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 25);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 3, &int_vals[3]);
    if (!(x == &int_vals[3])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 27);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 4, &int_vals[4]);
    if (!(x == &int_vals[4])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 29);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 5, &int_vals[5]);
    if (!(x == &int_vals[5])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 31);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 6, &int_vals[6]);
    if (!(x == &int_vals[6])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 33);; return "array_put error.\n"; };
    x = (int *)array_get(ary_a, 0);
    if (!(*x == 0)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 36);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 1);
    if (!(*x == 1)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 38);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 2);
    if (!(*x == 2)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 40);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 3);
    if (!(*x == 3)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 42);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 4);
    if (!(*x == 4)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 44);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 5);
    if (!(*x == 5)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 46);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 6);
    if (!(*x == 6)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 48);; return "array_get error.\n"; }
    return ((void *)0);
}

canonical_original_code:
char *test_put_get()
{
    int *x;
    x = (int *)array_put(ary_a, 0, &int_vals[0]);
    if (!(x == &int_vals[0])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 21);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 1, &int_vals[1]);
    if (!(x == &int_vals[1])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 23);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 2, &int_vals[2]);
    if (!(x == &int_vals[2])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 25);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 3, &int_vals[3]);
    if (!(x == &int_vals[3])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 27);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 4, &int_vals[4]);
    if (!(x == &int_vals[4])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 29);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 5, &int_vals[5]);
    if (!(x == &int_vals[5])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 31);; return "array_put error.\n"; };
    x = (int *)array_put(ary_a, 6, &int_vals[6]);
    if (!(x == &int_vals[6])) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_put error.\n", "tests/array_tests.c", 33);; return "array_put error.\n"; };
    x = (int *)array_get(ary_a, 0);
    if (!(*x == 0)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 36);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 1);
    if (!(*x == 1)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 38);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 2);
    if (!(*x == 2)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 40);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 3);
    if (!(*x == 3)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 42);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 4);
    if (!(*x == 4)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 44);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 5);
    if (!(*x == 5)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 46);; return "array_get error.\n"; }
    x = (int *)array_get(ary_a, 6);
    if (!(*x == 6)) { fprintf(stderr, "[ERROR] (%s:%d:) " "array_get error.\n", "tests/array_tests.c", 48);; return "array_get error.\n"; }
    return ((void *)0);
}