reduce

decompiled_code:
__int64 __fastcall reduce(__int64 a1)
{
double v1; // rdx
double v2; // rdx
__int64 v4; // rdx
double v5; // rdx
double v6; // rdx
double v7; // rdx
double v8; // rdx
double v9; // rdx
double v10; // rdx
double v11; // rdx
double v12; // rdx
double v13; // rdx
int v14; // ecx
int v15; // er8
__int64 v16; // rdx
__int64 v17; // rdx
__int64 v18; // rdx
double v19; // rdx
double v20; // rdx
double v21; // rdx
double v22; // xmm1_8
int v23; // ecx
int v24; // edx
double v25; // xmm1_8
int v26; // er8
double y[2]; // [rsp+8h] [rbp-30h] BYREF
double x; // [rsp+18h] [rbp-20h]

switch ( (int)a1 )
{
case 1:
pop(a1);
y[0] = v1;
pop(a1);
pop(a1);
x = v2;
*(double *)::x = y[0] + v2;
goto LABEL_3;
case 2:
((void (*)(void))pop)();
y[0] = v20;
pop(a1);
pop(a1);
x = v21;
*(double *)::x = v21 - y[0];
goto LABEL_3;
case 3:
case 6:
case 8:
case 10:
case 12:
case 15:
curtoken = pop(a1);
*(_QWORD *)::x = v4;
goto LABEL_3;
case 4:
pop(a1);
y[0] = v5;
pop(a1);
pop(a1);
x = v6;
*(double *)::x = y[0] * v6;
goto LABEL_3;
case 5:
pop(a1);
y[0] = v7;
pop(a1);
pop(a1);
x = v8;
if ( y[0] == 0.0 )
*(_QWORD *)::x = LC22;
else
*(double *)::x = x / y[0];
goto LABEL_3;
case 7:
pop(a1);
y[0] = v9;
pop(a1);
pop(a1);
x = v10;
*(_QWORD *)::x = pow(v10, y[0]);
goto LABEL_3;
case 9:
pop(a1);
y[0] = v11;
pop(a1);
*(_QWORD *)::x = *(_QWORD *)&y[0] ^ LC23;
goto LABEL_3;
case 11:
pop(a1);
y[0] = v12;
pop(a1);
pop(a1);
v14 = LODWORD(y[0]);
v15 = HIDWORD(y[0]);
*(_QWORD *)::x = 0LL;
x = v13;
if ( LODWORD(y[0]) != LODWORD(v13) )
{
if ( HIDWORD(y[0]) == HIDWORD(x) && SLODWORD(y[0]) >= SLODWORD(v13) )
{
v22 = 0.0;
do
{
v22 = v22 + cellvalue(v15, SLODWORD(v13));
*(double *)::x = v22;
}
while ( LODWORD(v13) != v23 );
goto LABEL_3;
}
LABEL_12:
error = 1;
goto LABEL_3;
}
v24 = HIDWORD(x);
if ( SHIDWORD(y[0]) < SHIDWORD(x) )
goto LABEL_12;
v25 = 0.0;
do
{
v25 = v25 + cellvalue(v24, v14);
*(double *)::x = v25;
}
while ( v24 != v26 );
LABEL_3:
LOBYTE(curtoken) = gotostate(a1);
return push((const __m128i *)&curtoken);
case 13:
curtoken = pop(a1);
*(_QWORD *)::x = v16;
*(_QWORD *)::x = cellvalue(SHIDWORD(v16), v16);
goto LABEL_3;
case 14:
pop(a1);
curtoken = pop(a1);
*(_QWORD *)::x = v17;
pop(a1);
goto LABEL_3;
case 16:
pop(a1);
curtoken = pop(a1);
*(_QWORD *)::x = v18;
pop(a1);
pop(a1);
y[0] = v19;
if ( LODWORD(v19) == 5456449 )
{
*(_QWORD *)::x &= LC24;
}
else if ( LODWORD(y[0]) != 1397703489 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) != 1313428289 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) != 1312904257 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) != 1213419331 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) == 5459779 )
{
*(_QWORD *)::x = cos(*(double *)::x);
}
else if ( LODWORD(y[0]) == 5265477 )
{
*(_QWORD *)::x = exp(*(double *)::x);
}
else if ( !strcmp((const char *)y, "LOG10") )
{
*(_QWORD *)::x = log10(*(double *)::x);
}
else if ( LODWORD(y[0]) == 4673356 )
{
*(_QWORD *)::x = log(*(double *)::x);
}
else if ( !strcmp((const char *)y, "ROUND") )
{
*(double *)::x = (double)(int)(*(double *)::x + 0.5);
}
else if ( !strcmp((const char *)y, "POW10") )
{
*(_QWORD *)::x = pow10(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SINH") )
{
*(_QWORD *)::x = sinh(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SIN") )
{
*(_QWORD *)::x = sin(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SQRT") )
{
*(_QWORD *)::x = sqrt(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SQR") )
{
*(double *)::x = *(double *)::x * *(double *)::x;
}
else if ( !strcmp((const char *)y, "TANH") )
{
*(_QWORD *)::x = tanh(*(double *)::x);
}
else if ( !strcmp((const char *)y, "TAN") )
{
*(_QWORD *)::x = tan(*(double *)::x);
}
else if ( !strcmp((const char *)y, "TRUNC") )
{
*(double *)::x = (double)(int)*(double *)::x;
}
}
else
{
*(_QWORD *)::x = cosh(*(double *)::x);
}
}
else
{
*(_QWORD *)::x = atan(*(double *)::x);
}
}
else
{
*(_QWORD *)::x = asin(*(double *)::x);
}
}
else
{
*(_QWORD *)::x = acos(*(double *)::x);
}
goto LABEL_3;
default:
goto LABEL_3;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
double v1; // rdx
double v2; // rdx
__int64 v4; // rdx
double v5; // rdx
double v6; // rdx
double v7; // rdx
double v8; // rdx
double v9; // rdx
double v10; // rdx
double v11; // rdx
double v12; // rdx
double v13; // rdx
int v14; // ecx
int v15; // er8
__int64 v16; // rdx
__int64 v17; // rdx
__int64 v18; // rdx
double v19; // rdx
double v20; // rdx
double v21; // rdx
double v22; // xmm1_8
int v23; // ecx
int v24; // edx
double v25; // xmm1_8
int v26; // er8
double y[2]; // [rsp+8h] [rbp-30h] BYREF
double x; // [rsp+18h] [rbp-20h]

switch ( (int)a1 )
{
case 1:
func3(a1);
y[0] = v1;
func3(a1);
func3(a1);
x = v2;
*(double *)::x = y[0] + v2;
goto LABEL_3;
case 2:
((void (*)(void))pop)();
y[0] = v20;
func3(a1);
func3(a1);
x = v21;
*(double *)::x = v21 - y[0];
goto LABEL_3;
case 3:
case 6:
case 8:
case 10:
case 12:
case 15:
curtoken = func3(a1);
*(_QWORD *)::x = v4;
goto LABEL_3;
case 4:
func3(a1);
y[0] = v5;
func3(a1);
func3(a1);
x = v6;
*(double *)::x = y[0] * v6;
goto LABEL_3;
case 5:
func3(a1);
y[0] = v7;
func3(a1);
func3(a1);
x = v8;
if ( y[0] == 0.0 )
*(_QWORD *)::x = LC22;
else
*(double *)::x = x / y[0];
goto LABEL_3;
case 7:
func3(a1);
y[0] = v9;
func3(a1);
func3(a1);
x = v10;
*(_QWORD *)::x = pow(v10, y[0]);
goto LABEL_3;
case 9:
func3(a1);
y[0] = v11;
func3(a1);
*(_QWORD *)::x = *(_QWORD *)&y[0] ^ LC23;
goto LABEL_3;
case 11:
func3(a1);
y[0] = v12;
func3(a1);
func3(a1);
v14 = LODWORD(y[0]);
v15 = HIDWORD(y[0]);
*(_QWORD *)::x = 0LL;
x = v13;
if ( LODWORD(y[0]) != LODWORD(v13) )
{
if ( HIDWORD(y[0]) == HIDWORD(x) && SLODWORD(y[0]) >= SLODWORD(v13) )
{
v22 = 0.0;
do
{
v22 = v22 + func5(v15, SLODWORD(v13));
*(double *)::x = v22;
}
while ( LODWORD(v13) != v23 );
goto LABEL_3;
}
LABEL_12:
error = 1;
goto LABEL_3;
}
v24 = HIDWORD(x);
if ( SHIDWORD(y[0]) < SHIDWORD(x) )
goto LABEL_12;
v25 = 0.0;
do
{
v25 = v25 + func5(v24, v14);
*(double *)::x = v25;
}
while ( v24 != v26 );
LABEL_3:
LOBYTE(curtoken) = func4(a1);
return func2((const __m128i *)&curtoken);
case 13:
curtoken = func3(a1);
*(_QWORD *)::x = v16;
*(_QWORD *)::x = func5(SHIDWORD(v16), v16);
goto LABEL_3;
case 14:
func3(a1);
curtoken = func3(a1);
*(_QWORD *)::x = v17;
func3(a1);
goto LABEL_3;
case 16:
func3(a1);
curtoken = func3(a1);
*(_QWORD *)::x = v18;
func3(a1);
func3(a1);
y[0] = v19;
if ( LODWORD(v19) == 5456449 )
{
*(_QWORD *)::x &= LC24;
}
else if ( LODWORD(y[0]) != 1397703489 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) != 1313428289 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) != 1312904257 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) != 1213419331 || BYTE4(y[0]) )
{
if ( LODWORD(y[0]) == 5459779 )
{
*(_QWORD *)::x = cos(*(double *)::x);
}
else if ( LODWORD(y[0]) == 5265477 )
{
*(_QWORD *)::x = exp(*(double *)::x);
}
else if ( !strcmp((const char *)y, "LOG10") )
{
*(_QWORD *)::x = log10(*(double *)::x);
}
else if ( LODWORD(y[0]) == 4673356 )
{
*(_QWORD *)::x = log(*(double *)::x);
}
else if ( !strcmp((const char *)y, "ROUND") )
{
*(double *)::x = (double)(int)(*(double *)::x + 0.5);
}
else if ( !strcmp((const char *)y, "POW10") )
{
*(_QWORD *)::x = pow10(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SINH") )
{
*(_QWORD *)::x = sinh(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SIN") )
{
*(_QWORD *)::x = sin(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SQRT") )
{
*(_QWORD *)::x = sqrt(*(double *)::x);
}
else if ( !strcmp((const char *)y, "SQR") )
{
*(double *)::x = *(double *)::x * *(double *)::x;
}
else if ( !strcmp((const char *)y, "TANH") )
{
*(_QWORD *)::x = tanh(*(double *)::x);
}
else if ( !strcmp((const char *)y, "TAN") )
{
*(_QWORD *)::x = tan(*(double *)::x);
}
else if ( !strcmp((const char *)y, "TRUNC") )
{
*(double *)::x = (double)(int)*(double *)::x;
}
}
else
{
*(_QWORD *)::x = cosh(*(double *)::x);
}
}
else
{
*(_QWORD *)::x = atan(*(double *)::x);
}
}
else
{
*(_QWORD *)::x = asin(*(double *)::x);
}
}
else
{
*(_QWORD *)::x = acos(*(double *)::x);
}
goto LABEL_3;
default:
goto LABEL_3;
}
}

original_code:
void reduce(int reduction)
{
    struct TOKENREC token1, token2;
    int counter;
    switch (reduction) {
        case 1 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = token1.x.value + token2.x.value;
            break;
        case 2 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = token2.x.value - token1.x.value;
            break;
        case 4 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = token1.x.value * token2.x.value;
            break;
        case 5 :
            token1 = pop();
            pop();
            token2 = pop();
            if (token1.x.value == 0)
                curtoken.x.value = (__builtin_huge_val ());
            else
                curtoken.x.value = token2.x.value / token1.x.value;
            break;
        case 7 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = pow(token2.x.value, token1.x.value);
            break;
        case 9 :
            token1 = pop();
            pop();
            curtoken.x.value = -token1.x.value;
            break;
        case 11 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = 0;
            if (token1.x.c.row == token2.x.c.row) {
                if (token1.x.c.col < token2.x.c.col)
                    error = 1;
                else {
                    for (counter = token2.x.c.col; counter <= token1.x.c.col; counter++)
                        curtoken.x.value += cellvalue(counter, token1.x.c.row);
                }
            }
            else if (token1.x.c.col == token2.x.c.col) {
                if (token1.x.c.row < token2.x.c.row)
                    error = 1;
                else {
                    for (counter = token2.x.c.row; counter <= token1.x.c.row; counter++)
                        curtoken.x.value += cellvalue(token1.x.c.col, counter);
                }
            }
            else
                error = 1;
            break;
        case 13 :
            curtoken = pop();
            curtoken.x.value = cellvalue(curtoken.x.c.col, curtoken.x.c.row);
            break;
        case 14 :
            pop();
            curtoken = pop();
            pop();
            break;
        case 16 :
            pop();
            curtoken = pop();
            pop();
            token1 = pop();
            if (strcmp(token1.x.funcname, "ABS") == 0)
                curtoken.x.value = fabs(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ACOS") == 0)
                curtoken.x.value = acos(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ASIN") == 0)
                curtoken.x.value = asin(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ATAN") == 0)
                curtoken.x.value = atan(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "COSH") == 0)
                curtoken.x.value = cosh(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "COS") == 0)
                curtoken.x.value = cos(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "EXP") == 0)
                curtoken.x.value = exp(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "LOG10") == 0)
                curtoken.x.value = log10(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "LOG") == 0)
                curtoken.x.value = log(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ROUND") == 0)
                curtoken.x.value = (int)(curtoken.x.value + 0.5);
            else if (strcmp(token1.x.funcname, "POW10") == 0)
                curtoken.x.value = pow10(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SINH") == 0)
                curtoken.x.value = sinh(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SIN") == 0)
                curtoken.x.value = sin(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SQRT") == 0)
                curtoken.x.value = sqrt(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SQR") == 0)
                curtoken.x.value *= curtoken.x.value;
            else if (strcmp(token1.x.funcname, "TANH") == 0)
                curtoken.x.value = tanh(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "TAN") == 0)
                curtoken.x.value = tan(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "TRUNC") == 0)
                curtoken.x.value = (int)curtoken.x.value;
            break;
        case 3 :
        case 6 :
        case 8 :
        case 10 :
        case 12 :
        case 15 :
            curtoken = pop();
            break;
    }
    curtoken.state = gotostate(reduction);
    push(&curtoken);
}

canonical_original_code:
void reduce(int reduction)
{
    struct TOKENREC token1; struct TOKENREC token2;
    int counter;
    switch (reduction) {
        case 1 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = token1.x.value + token2.x.value;
            break;
        case 2 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = token2.x.value - token1.x.value;
            break;
        case 4 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = token1.x.value * token2.x.value;
            break;
        case 5 :
            token1 = pop();
            pop();
            token2 = pop();
            if (token1.x.value == 0)
                curtoken.x.value = (__builtin_huge_val ());
            else
                curtoken.x.value = token2.x.value / token1.x.value;
            break;
        case 7 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = pow(token2.x.value, token1.x.value);
            break;
        case 9 :
            token1 = pop();
            pop();
            curtoken.x.value = -token1.x.value;
            break;
        case 11 :
            token1 = pop();
            pop();
            token2 = pop();
            curtoken.x.value = 0;
            if (token1.x.c.row == token2.x.c.row) {
                if (token1.x.c.col < token2.x.c.col)
                    error = 1;
                else {
                    for (counter = token2.x.c.col; counter <= token1.x.c.col; counter++)
                        curtoken.x.value += cellvalue(counter, token1.x.c.row);
                }
            }
            else if (token1.x.c.col == token2.x.c.col) {
                if (token1.x.c.row < token2.x.c.row)
                    error = 1;
                else {
                    for (counter = token2.x.c.row; counter <= token1.x.c.row; counter++)
                        curtoken.x.value += cellvalue(token1.x.c.col, counter);
                }
            }
            else
                error = 1;
            break;
        case 13 :
            curtoken = pop();
            curtoken.x.value = cellvalue(curtoken.x.c.col, curtoken.x.c.row);
            break;
        case 14 :
            pop();
            curtoken = pop();
            pop();
            break;
        case 16 :
            pop();
            curtoken = pop();
            pop();
            token1 = pop();
            if (strcmp(token1.x.funcname, "ABS") == 0)
                curtoken.x.value = fabs(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ACOS") == 0)
                curtoken.x.value = acos(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ASIN") == 0)
                curtoken.x.value = asin(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ATAN") == 0)
                curtoken.x.value = atan(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "COSH") == 0)
                curtoken.x.value = cosh(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "COS") == 0)
                curtoken.x.value = cos(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "EXP") == 0)
                curtoken.x.value = exp(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "LOG10") == 0)
                curtoken.x.value = log10(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "LOG") == 0)
                curtoken.x.value = log(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "ROUND") == 0)
                curtoken.x.value = (int)(curtoken.x.value + 0.5);
            else if (strcmp(token1.x.funcname, "POW10") == 0)
                curtoken.x.value = pow10(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SINH") == 0)
                curtoken.x.value = sinh(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SIN") == 0)
                curtoken.x.value = sin(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SQRT") == 0)
                curtoken.x.value = sqrt(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "SQR") == 0)
                curtoken.x.value *= curtoken.x.value;
            else if (strcmp(token1.x.funcname, "TANH") == 0)
                curtoken.x.value = tanh(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "TAN") == 0)
                curtoken.x.value = tan(curtoken.x.value);
            else if (strcmp(token1.x.funcname, "TRUNC") == 0)
                curtoken.x.value = (int)curtoken.x.value;
            break;
        case 3 :
        case 6 :
        case 8 :
        case 10 :
        case 12 :
        case 15 :
            curtoken = pop();
            break;
    }
    curtoken.state = gotostate(reduction);
    push(&curtoken);
}

variable_types: reduction int

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

variable_types: counter int


parse

repo: lornix/tcalc

decompiled_code:
double __fastcall parse(char *dest, _DWORD *a2)
{
int v2; // eax
double result; // xmm0_8
__m128i v4; // [rsp+0h] [rbp-78h] BYREF
char desta[104]; // [rsp+10h] [rbp-68h] BYREF

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

canonical_decompiled_code:
double __fastcall func8(char *dest, _DWORD *a2)
{
int v2; // eax
double result; // xmm0_8
__m128i v4; // [rsp+0h] [rbp-78h] BYREF
char desta[104]; // [rsp+10h] [rbp-68h] BYREF

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

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]

return_type: double

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


decompiled_code:
// attributes: thunk
int finish_atexit(void)
{
return endwin();
}

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

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

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

return_type: void


decompiled_code:
// attributes: thunk
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
unsigned int v3; // ebx
__int64 v4; // rsi
const __int32_t **v5; // rdi
char *v6; // rax
char *v7; // rsi
__int64 v8; // rcx

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

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
int v2; // eax
unsigned int v3; // ebx
__int64 v4; // rsi
const __int32_t **v5; // rdi
char *v6; // rax
char *v7; // rsi
__int64 v8; // rcx

v2 = strlen(a1);
if ( v2 >= 0 )
{
v3 = v2;
v4 = (__int64)&a1[v2 - 1];
v5 = _ctype_toupper_loc();
v6 = (char *)&a1[v3];
v7 = (char *)(v4 - v3);
do
{
v8 = *v6--;
v6[1] = (*v5)[v8];
}
while ( v7 != v6 );
}
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:
void __fastcall pow10(double a1)
{
pow(10.0, a1);
}

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

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

variable_types: p double


bioskey

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

result = wgetch(stdscr);
switch ( result )
{
case 258:
result = 20480;
break;
case 259:
result = 18432;
break;
case 260:
result = 19200;
break;
case 261:
result = 19712;
break;
case 262:
result = 18176;
break;
case 263:
result = 8;
break;
case 265:
result = 15104;
break;
case 266:
result = 15360;
break;
case 267:
result = 15616;
break;
case 268:
result = 15872;
break;
case 269:
result = 16128;
break;
case 270:
result = 0x4000;
break;
case 271:
result = 16640;
break;
case 272:
result = 16896;
break;
case 273:
result = 17152;
break;
case 274:
result = 17408;
break;
case 330:
result = 21248;
break;
case 331:
result = 20992;
break;
case 332:
result = 27;
break;
case 338:
result = 20736;
break;
case 339:
result = 18688;
break;
case 343:
result = 13;
break;
case 360:
result = 20224;
break;
case 393:
result = 29440;
break;
case 402:
result = 29696;
break;
default:
if ( result > 255 )
result = (result - 256) << 8;
break;
}
return result;
}

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

result = wgetch(stdscr);
switch ( result )
{
case 258:
result = 20480;
break;
case 259:
result = 18432;
break;
case 260:
result = 19200;
break;
case 261:
result = 19712;
break;
case 262:
result = 18176;
break;
case 263:
result = 8;
break;
case 265:
result = 15104;
break;
case 266:
result = 15360;
break;
case 267:
result = 15616;
break;
case 268:
result = 15872;
break;
case 269:
result = 16128;
break;
case 270:
result = 0x4000;
break;
case 271:
result = 16640;
break;
case 272:
result = 16896;
break;
case 273:
result = 17152;
break;
case 274:
result = 17408;
break;
case 330:
result = 21248;
break;
case 331:
result = 20992;
break;
case 332:
result = 27;
break;
case 338:
result = 20736;
break;
case 339:
result = 18688;
break;
case 343:
result = 13;
break;
case 360:
result = 20224;
break;
case 393:
result = 29440;
break;
case 402:
result = 29696;
break;
default:
if ( result > 255 )
result = (result - 256) << 8;
break;
}
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, BYTE4(master_text_info) << 8);
if ( wmove(stdscr, (unsigned __int8)byte_4AA, HIBYTE(word_4A8)) != -1 )
waddnstr(stdscr, a1, -1);
wrefresh(stdscr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
wattrset(stdscr, BYTE4(master_text_info) << 8);
if ( wmove(stdscr, (unsigned __int8)byte_4AA, HIBYTE(word_4A8)) != -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
__int64 result; // rax

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

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

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

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)
{
HIBYTE(word_4A8) = a1 - 1;
byte_4AA = a2 - 1;
}

canonical_decompiled_code:
void __fastcall func10(char a1, char a2)
{
HIBYTE(word_4A8) = a1 - 1;
byte_4AA = 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; // eax
__int64 v1; // rdx
__int64 result; // rax
int v3; // ebx
char v4; // si
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

*(__int16 *)((char *)&word_4A8 + 1) = 257;
v0 = BYTE2(master_text_info) - (unsigned __int8)master_text_info;
v1 = (unsigned int)(v0 + 1);
if ( v0 == 255 )
v1 = 255LL;
sprintf(v5, "%*s", v1, &unk_94E);
result = BYTE1(master_text_info);
v3 = BYTE1(master_text_info);
if ( BYTE3(master_text_info) >= BYTE1(master_text_info) )
{
do
{
v4 = v3++;
gotoxy(master_text_info, v4);
cputs(v5);
result = BYTE3(master_text_info);
}
while ( BYTE3(master_text_info) >= v3 );
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
__int64 v1; // rdx
__int64 result; // rax
int v3; // ebx
char v4; // si
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

*(__int16 *)((char *)&word_4A8 + 1) = 257;
v0 = BYTE2(master_text_info) - (unsigned __int8)master_text_info;
v1 = (unsigned int)(v0 + 1);
if ( v0 == 255 )
v1 = 255LL;
sprintf(v5, "%*s", v1, &unk_94E);
result = BYTE1(master_text_info);
v3 = BYTE1(master_text_info);
if ( BYTE3(master_text_info) >= BYTE1(master_text_info) )
{
do
{
v4 = v3++;
func10(master_text_info, v4);
func6(v5);
result = BYTE3(master_text_info);
}
while ( BYTE3(master_text_info) >= v3 );
}
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)
{
BYTE4(master_text_info) = a1;
}

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

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

variable_types: newattr int


window

decompiled_code:
int __fastcall window(char a1, char a2, char a3, char a4)
{
int result; // eax
int v9; // ebx
int v10; // edx
char v11; // si
__int16 v12; // di

result = donesetup;
if ( !donesetup )
{
HIDWORD(master_text_info) = 402851591;
v9 = 1;
LOBYTE(word_4A8) = 80;
signal(2, (__sighandler_t)finish_signal);
atexit((void (*)(void))finish_atexit);
nwin = initscr();
start_color();
do
{
v10 = v9;
v11 = v9;
v12 = v9++;
init_pair(v12, v11 & 0xF, v10 >> 4);
}
while ( v9 != 256 );
keypad(stdscr, 1);
nonl();
cbreak();
result = echo();
donesetup = 1;
}
HIBYTE(word_4A8) = a1;
byte_4AA = a2;
LOBYTE(master_text_info) = a1;
BYTE1(master_text_info) = a2;
BYTE2(master_text_info) = a3;
BYTE3(master_text_info) = a4;
return result;
}

canonical_decompiled_code:
int __fastcall func15(char a1, char a2, char a3, char a4)
{
int result; // eax
int v9; // ebx
int v10; // edx
char v11; // si
__int16 v12; // di

result = donesetup;
if ( !donesetup )
{
HIDWORD(master_text_info) = 402851591;
v9 = 1;
LOBYTE(word_4A8) = 80;
signal(2, (__sighandler_t)finish_signal);
atexit((void (*)(void))finish_atexit);
nwin = initscr();
start_color();
do
{
v10 = v9;
v11 = v9;
v12 = v9++;
init_pair(v12, v11 & 0xF, v10 >> 4);
}
while ( v9 != 256 );
keypad(stdscr, 1);
nonl();
cbreak();
result = echo();
donesetup = 1;
}
HIBYTE(word_4A8) = a1;
byte_4AA = a2;
LOBYTE(master_text_info) = a1;
BYTE1(master_text_info) = a2;
BYTE2(master_text_info) = a3;
BYTE3(master_text_info) = a4;
return result;
}

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()
{
int v0; // eax
unsigned int v1; // er8
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
unsigned int v1; // er8
__int64 result; // rax

v0 = bioskey(0LL);
if ( v0 == 12 )
{
refreshscreen();
result = 12LL;
}
else
{
v1 = (unsigned __int8)v0;
if ( !(_BYTE)v0 )
v1 = BYTE1(v0) + 256;
result = v1;
}
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)
{
unsigned int v3; // er14
int v5; // er12
int v6; // ebp
int v7; // eax
int v8; // ebx
bool v9; // r15
int v11; // edx
int v12; // edx
__int64 v13; // rsi
const char *v14; // rdi
char *v15; // rsi
int v16; // edx
int v17; // edx

v3 = 1;
v5 = strlen(a1);
v6 = v5;
changecursor(1LL);
while ( 1 )
{
while ( 1 )
{
writef(1LL, 25LL, 15LL, 79LL, &unk_55C, a1);
gotoxy((unsigned int)(v6 + 1), 25LL);
v7 = getkey();
v8 = v7;
if ( v7 <= 339 )
{
if ( v7 > 326 )
{
switch ( v7 )
{
case 327:
v6 = 0;
goto LABEL_18;
case 328:
case 336:
goto LABEL_12;
case 331:
v6 -= v6 > 0;
goto LABEL_18;
case 333:
if ( v5 > v6 )
++v6;
goto LABEL_18;
case 335:
v6 = v5;
goto LABEL_18;
case 338:
v3 ^= 1u;
changecursor(v3);
goto LABEL_18;
case 339:
if ( v5 > v6 )
{
v16 = v5--;
movmem(&a1[v6 + 1], &a1[v6], (unsigned int)(v16 - v6));
}
goto LABEL_18;
default:
goto LABEL_8;
}
}
if ( v7 == 8 )
{
if ( v6 > 0 )
{
v11 = v5--;
v12 = v11 - v6;
v13 = (__int64)&a1[v6 - 1];
v14 = &a1[v6--];
movmem(v14, v13, (unsigned int)(v12 + 1));
}
LABEL_18:
a1[v5] = 0;
goto LABEL_13;
}
if ( v7 > 7 && (v7 == 13 || v7 == 27) )
break;
}
LABEL_8:
if ( *a2 && !strchr(a2, v7) || (unsigned int)(v8 - 32) > 0x5E || v5 >= a3 )
break;
v15 = (char *)&a1[v6];
if ( v3 )
{
v17 = v5++;
memmove((void *)&a1[v6 + 1], v15, v17 - v6 + 1);
v15 = (char *)&a1[v6];
}
else
{
v5 += v5 <= v6;
}
*v15 = v8;
++v6;
a1[v5] = 0;
}
LABEL_12:
a1[v5] = 0;
if ( ((v8 - 328) & 0xFFFFFFF7) == 0 )
break;
LABEL_13:
v9 = v8 != 27;
if ( v8 == 13 || v8 == 27 )
goto LABEL_15;
}
v9 = v8 != 27;
LABEL_15:
clearinput();
changecursor(0LL);
setcursor(nocursor);
return v9;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1, const char *a2, int a3)
{
unsigned int v3; // er14
int v5; // er12
int v6; // ebp
int v7; // eax
int v8; // ebx
bool v9; // r15
int v11; // edx
int v12; // edx
__int64 v13; // rsi
const char *v14; // rdi
char *v15; // rsi
int v16; // edx
int v17; // edx

v3 = 1;
v5 = strlen(a1);
v6 = v5;
changecursor(1LL);
while ( 1 )
{
while ( 1 )
{
writef(1LL, 25LL, 15LL, 79LL, &unk_55C, a1);
gotoxy((unsigned int)(v6 + 1), 25LL);
v7 = func0();
v8 = v7;
if ( v7 <= 339 )
{
if ( v7 > 326 )
{
switch ( v7 )
{
case 327:
v6 = 0;
goto LABEL_18;
case 328:
case 336:
goto LABEL_12;
case 331:
v6 -= v6 > 0;
goto LABEL_18;
case 333:
if ( v5 > v6 )
++v6;
goto LABEL_18;
case 335:
v6 = v5;
goto LABEL_18;
case 338:
v3 ^= 1u;
changecursor(v3);
goto LABEL_18;
case 339:
if ( v5 > v6 )
{
v16 = v5--;
movmem(&a1[v6 + 1], &a1[v6], (unsigned int)(v16 - v6));
}
goto LABEL_18;
default:
goto LABEL_8;
}
}
if ( v7 == 8 )
{
if ( v6 > 0 )
{
v11 = v5--;
v12 = v11 - v6;
v13 = (__int64)&a1[v6 - 1];
v14 = &a1[v6--];
movmem(v14, v13, (unsigned int)(v12 + 1));
}
LABEL_18:
a1[v5] = 0;
goto LABEL_13;
}
if ( v7 > 7 && (v7 == 13 || v7 == 27) )
break;
}
LABEL_8:
if ( *a2 && !strchr(a2, v7) || (unsigned int)(v8 - 32) > 0x5E || v5 >= a3 )
break;
v15 = (char *)&a1[v6];
if ( v3 )
{
v17 = v5++;
memmove((void *)&a1[v6 + 1], v15, v17 - v6 + 1);
v15 = (char *)&a1[v6];
}
else
{
v5 += v5 <= v6;
}
*v15 = v8;
++v6;
a1[v5] = 0;
}
LABEL_12:
a1[v5] = 0;
if ( ((v8 - 328) & 0xFFFFFFF7) == 0 )
break;
LABEL_13:
v9 = v8 != 27;
if ( v8 == 13 || v8 == 27 )
goto LABEL_15;
}
v9 = v8 != 27;
LABEL_15:
clearinput();
changecursor(0LL);
setcursor(nocursor);
return v9;
}

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_55F, 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_55F, 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 nptr[5]; // [rsp+Bh] [rbp-7Dh] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

nptr[0] = 0;
sprintf(s, "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(s);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int *a1, int a2, int a3)
{
_BOOL8 result; // rax
int v5; // eax
char nptr[5]; // [rsp+Bh] [rbp-7Dh] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

nptr[0] = 0;
sprintf(s, "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(s);
}
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

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; // eax

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

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

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

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

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

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

result = *a2;
a1[1] = a2;
*a1 = result;
*(_QWORD *)(result + 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 func2()
{
__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(_QWORD **a1)
{
_QWORD *v2; // rbp
_QWORD *v3; // rbx
_QWORD *v4; // rdi

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

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

v2 = *a1;
v3 = (_QWORD *)**a1;
if ( *a1 != v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
zfree(v4);
}
while ( v2 != v3 );
v2 = *a1;
}
free(v2);
*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 func4(__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 func5(__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)
{
_QWORD *v2; // rax
__int64 v3; // r9
__int64 v4; // r8

v2 = ring_get_node(a1, a2);
v3 = v2[2];
v2[2] = v4;
return v3;
}

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; // rax
_QWORD *v5; // r8
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, __int64 a3)
{
_QWORD *v4; // rax
_QWORD *v5; // r8
__int64 result; // rax

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

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)
{
__int64 *v4; // rax
_QWORD *v5; // r8
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 a3)
{
__int64 *v4; // rax
_QWORD *v5; // r8
__int64 result; // rax

*(_QWORD *)(zalloc(24LL) + 16) = a3;
v4 = ring_get_node(a1, a2);
func0(v5, v4);
result = a3;
++*(_DWORD *)(a1 + 24);
return result;
}

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 func10(__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)
{
__int64 *v2; // rax
__int64 v3; // r12
__int64 v4; // rax

v2 = ring_get_node(a1, a2);
v3 = v2[2];
node_del_isra_0(*v2, (_QWORD *)v2[1]);
zfree(v4);
--*(_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;
}


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:
__int64 __fastcall set_member(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx

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

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 func6(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 result; // rax
__int64 v4; // r13
_QWORD *i; // rbx

result = *(unsigned int *)(a1 + 24);
if ( (int)result > 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;
}

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

result = *(unsigned int *)(a1 + 24);
if ( (int)result > 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;
}


decompiled_code:
__int64 __fastcall seq_new(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 v3; // rax
__int64 result; // rax

v1 = a1;
a1 = (int)a1;
v2 = zcalloc(1LL, 24LL);
if ( !(_DWORD)a1 )
{
a1 = 16LL;
v1 = 16;
}
v3 = zcalloc(a1, 8LL);
*(_DWORD *)(v2 + 8) = v1;
*(_QWORD *)v2 = v3;
result = v2;
*(_QWORD *)(v2 + 12) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 v3; // rax
__int64 result; // rax

v1 = a1;
a1 = (int)a1;
v2 = zcalloc(1LL, 24LL);
if ( !(_DWORD)a1 )
{
a1 = 16LL;
v1 = 16;
}
v3 = zcalloc(a1, 8LL);
*(_DWORD *)(v2 + 8) = v1;
*(_QWORD *)v2 = v3;
result = v2;
*(_QWORD *)(v2 + 12) = 0LL;
return result;
}

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()
{
int v0; // eax
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // rdx
__int64 v4; // rcx
const char *result; // rax
_DWORD *v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
_DWORD *v9; // rax
__int64 v10; // rdx
_DWORD *v11; // rax
__int64 v12; // rdx
__int64 v13; // rdx
__int64 v14; // rcx
_DWORD *v15; // r8

array_resize(ary_a, 5LL);
v0 = array_size(ary_a);
v2 = 56LL;
if ( v0 != 4 )
goto LABEL_4;
if ( (unsigned int)array_length(ary_a, 5LL, v1, 56LL) != 5 )
{
v2 = 57LL;
LABEL_4:
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error.\n", "tests/array_tests.c", v2);
return "array_resize error.\n";
}
v6 = (_DWORD *)array_get(ary_a, 0LL, v3, v4);
v8 = 61LL;
if ( *v6
|| (v9 = (_DWORD *)array_get(ary_a, 1LL, v7, 61LL), v8 = 63LL, *v9 != 1)
|| (v11 = (_DWORD *)array_get(ary_a, 2LL, v10, 63LL), v8 = 65LL, *v11 != 2) )
{
LABEL_11:
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", v8);
return "array_resize error";
}
if ( *(_DWORD *)array_get(ary_a, 3LL, v12, 65LL) != 3 )
{
v8 = 67LL;
goto LABEL_11;
}
v15 = (_DWORD *)array_get(ary_a, 4LL, v13, v14);
result = 0LL;
if ( *v15 != 4 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 69LL);
result = "array_resize error";
}
return result;
}

canonical_decompiled_code:
const char *func9()
{
int v0; // eax
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // rdx
__int64 v4; // rcx
const char *result; // rax
_DWORD *v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
_DWORD *v9; // rax
__int64 v10; // rdx
_DWORD *v11; // rax
__int64 v12; // rdx
__int64 v13; // rdx
__int64 v14; // rcx
_DWORD *v15; // r8

func19(ary_a, 5LL);
v0 = func18(ary_a);
v2 = 56LL;
if ( v0 != 4 )
goto LABEL_4;
if ( (unsigned int)func17(ary_a, 5LL, v1, 56LL) != 5 )
{
v2 = 57LL;
LABEL_4:
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error.\n", "tests/array_tests.c", v2);
return "array_resize error.\n";
}
v6 = (_DWORD *)func15(ary_a, 0LL, v3, v4);
v8 = 61LL;
if ( *v6
|| (v9 = (_DWORD *)func15(ary_a, 1LL, v7, 61LL), v8 = 63LL, *v9 != 1)
|| (v11 = (_DWORD *)func15(ary_a, 2LL, v10, 63LL), v8 = 65LL, *v11 != 2) )
{
LABEL_11:
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", v8);
return "array_resize error";
}
if ( *(_DWORD *)func15(ary_a, 3LL, v12, 65LL) != 3 )
{
v8 = 67LL;
goto LABEL_11;
}
v15 = (_DWORD *)func15(ary_a, 4LL, v13, v14);
result = 0LL;
if ( *v15 != 4 )
{
fprintf(_bss_start, "[ERROR] (%s:%d:) array_resize error", "tests/array_tests.c", 69LL);
result = "array_resize error";
}
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) + a2 * *(_DWORD *)(a1 + 4);
}

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 func16(__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 func17(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 func18(__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:
void __fastcall array_resize(__int64 a1, signed int a2)
{
unsigned int v3; // eax
int v4; // edi
void *v5; // r12
int v6; // eax
void *v7; // rax

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

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 *