VarDescr

decompiled_code:
__int64 __fastcall VarDescr(__int64 a1, unsigned int *a2)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
int v6; // edx
int v7; // eax
char *v8; // rdi
unsigned int v9; // eax
__int64 result; // rax

v3 = scan(lex, a1, a2);
if ( v3 - 97 > 1 )
{
printf("Expected `int` or `__int64` , got: %x, uk: %d, lex: %s", v3, *a2, lex);
exit(1);
}
do
{
while ( 1 )
{
v4 = scan(lex, a1, a2);
if ( v4 != 1 )
{
printf("Expected `<id>`, got: %x, uk: %d, lex: %s", v4, *a2, lex);
exit(1);
}
current = addToTree(lex, 1LL, current);
result = scan(lex, a1, a2);
if ( (_DWORD)result != 48 )
break;
v5 = scan(lex, a1, a2);
if ( v5 - 32 > 1 )
{
printf("Expected `DecConst` or `HexConst`, got: %x, uk: %d, lex: %s", v5, *a2, lex);
exit(1);
}
v6 = 16;
if ( v5 == 32 )
v6 = 10;
v7 = strtol(lex, 0LL, v6);
v8 = lex;
*(_DWORD *)(current + 48) = v7;
v9 = scan(v8, a1, a2);
if ( v9 != 49 )
{
printf("Expected `]`, got: %x, uk: %d, lex: %s", v9, *a2, lex);
exit(1);
}
PossibleArrInit(a1, a2);
result = scan(lex, a1, a2);
if ( (_DWORD)result != 81 )
goto LABEL_13;
}
if ( (_DWORD)result == 78 )
{
Expression(a1, a2);
result = scan(lex, a1, a2);
}
}
while ( (_DWORD)result == 81 );
LABEL_13:
if ( (_DWORD)result != 80 )
{
printf("Expected `;`, got: %x, uk: %d, lex: %s", (unsigned int)result, *a2, lex);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int *a2)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
int v6; // edx
int v7; // eax
char *v8; // rdi
unsigned int v9; // eax
__int64 result; // rax

v3 = scan(lex, a1, a2);
if ( v3 - 97 > 1 )
{
printf("Expected `int` or `__int64` , got: %x, uk: %d, lex: %s", v3, *a2, lex);
exit(1);
}
do
{
while ( 1 )
{
v4 = scan(lex, a1, a2);
if ( v4 != 1 )
{
printf("Expected `<id>`, got: %x, uk: %d, lex: %s", v4, *a2, lex);
exit(1);
}
current = addToTree(lex, 1LL, current);
result = scan(lex, a1, a2);
if ( (_DWORD)result != 48 )
break;
v5 = scan(lex, a1, a2);
if ( v5 - 32 > 1 )
{
printf("Expected `DecConst` or `HexConst`, got: %x, uk: %d, lex: %s", v5, *a2, lex);
exit(1);
}
v6 = 16;
if ( v5 == 32 )
v6 = 10;
v7 = strtol(lex, 0LL, v6);
v8 = lex;
*(_DWORD *)(current + 48) = v7;
v9 = scan(v8, a1, a2);
if ( v9 != 49 )
{
printf("Expected `]`, got: %x, uk: %d, lex: %s", v9, *a2, lex);
exit(1);
}
func0(a1, a2);
result = scan(lex, a1, a2);
if ( (_DWORD)result != 81 )
goto LABEL_13;
}
if ( (_DWORD)result == 78 )
{
func6(a1, a2);
result = scan(lex, a1, a2);
}
}
while ( (_DWORD)result == 81 );
LABEL_13:
if ( (_DWORD)result != 80 )
{
printf("Expected `;`, got: %x, uk: %d, lex: %s", (unsigned int)result, *a2, lex);
exit(1);
}
return result;
}

original_code:
void VarDescr(char *t, int *uk){
 int oldUk, type,
  T = scan(lex, t, uk);
    if (!(T == 0x61 || T == 0x62)) {
        printf ("Expected `int` or `__int64` , got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    type = T;
    do {
        T = scan(lex, t, uk);
        if (T != 0x1) {
            printf ("Expected `<id>`, got: %x, uk: %d, lex: %s", T, *uk, lex);
            exit(1);
        }
        current = addToTree(lex, T, current);
        T = scan(lex, t, uk);
        if (T == 0x30) {
            T = scan(lex, t, uk);
            if (!(T == 0x20 || T == 0x21)) {
                printf ("Expected `DecConst` or `HexConst`, got: %x, uk: %d, lex: %s", T, *uk, lex);
                exit(1);
            }
            int base = (T == 0x20) ? 10 : 16;
            current->elementsCount = strtol(lex,0,base);
            T = scan(lex, t, uk);
            if (T != 0x31) {
                printf ("Expected `]`, got: %x, uk: %d, lex: %s", T, *uk, lex);
                exit(1);
            }
            PossibleArrInit(t,uk);
            T = scan(lex, t, uk);
        } else if (T == 0x4E) {
            Expression(t,uk);
            T = scan(lex, t, uk);
        }
    } while(T == 0x51);
    if (T != 0x50) {
        printf ("Expected `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
}

canonical_original_code:
void VarDescr(char *t, int *uk){
 int oldUk; int type; int T = scan(lex, t, uk);
    if (!(T == 0x61 || T == 0x62)) {
        printf ("Expected `int` or `__int64` , got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    type = T;
    do {
        T = scan(lex, t, uk);
        if (T != 0x1) {
            printf ("Expected `<id>`, got: %x, uk: %d, lex: %s", T, *uk, lex);
            exit(1);
        }
        current = addToTree(lex, T, current);
        T = scan(lex, t, uk);
        if (T == 0x30) {
            T = scan(lex, t, uk);
            if (!(T == 0x20 || T == 0x21)) {
                printf ("Expected `DecConst` or `HexConst`, got: %x, uk: %d, lex: %s", T, *uk, lex);
                exit(1);
            }
            int base = (T == 0x20) ? 10 : 16;
            current->elementsCount = strtol(lex,0,base);
            T = scan(lex, t, uk);
            if (T != 0x31) {
                printf ("Expected `]`, got: %x, uk: %d, lex: %s", T, *uk, lex);
                exit(1);
            }
            PossibleArrInit(t,uk);
            T = scan(lex, t, uk);
        } else if (T == 0x4E) {
            Expression(t,uk);
            T = scan(lex, t, uk);
        }
    } while(T == 0x51);
    if (T != 0x50) {
        printf ("Expected `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
}

variable_types: type int

variable_types: base int


For

repo: zarkone/MATFL

decompiled_code:
__int64 __fastcall For(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

v2 = scan(lex, a1, a2);
if ( v2 != 100 )
{
printf("Expected `<for>`, got: %x, uk: %d, lex: %s", v2, *a2, lex);
exit(1);
}
v3 = scan(lex, a1, a2);
if ( v3 != 50 )
{
printf("Expected `(`, got: %x, uk: %d, lex: %s", v3, *a2, lex);
exit(1);
}
Expression(a1, a2);
v4 = scan(lex, a1, a2);
if ( v4 != 80 || (Expression(a1, a2), v4 = scan(lex, a1, a2), v4 != 80) )
{
printf("Expected `;`, got: %x, uk: %d, lex: %s", v4, *a2, lex);
exit(1);
}
Expression(a1, a2);
v5 = scan(lex, a1, a2);
if ( v5 != 51 )
{
printf("Expected `)`, got: %x, uk: %d, lex: %s", v5, *a2, lex);
exit(1);
}
return Operator(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

v2 = scan(lex, a1, a2);
if ( v2 != 100 )
{
printf("Expected `<for>`, got: %x, uk: %d, lex: %s", v2, *a2, lex);
exit(1);
}
v3 = scan(lex, a1, a2);
if ( v3 != 50 )
{
printf("Expected `(`, got: %x, uk: %d, lex: %s", v3, *a2, lex);
exit(1);
}
func6(a1, a2);
v4 = scan(lex, a1, a2);
if ( v4 != 80 || (func6(a1, a2), v4 = scan(lex, a1, a2), v4 != 80) )
{
printf("Expected `;`, got: %x, uk: %d, lex: %s", v4, *a2, lex);
exit(1);
}
func6(a1, a2);
v5 = scan(lex, a1, a2);
if ( v5 != 51 )
{
printf("Expected `)`, got: %x, uk: %d, lex: %s", v5, *a2, lex);
exit(1);
}
return func9(a1, a2);
}

original_code:
void For(char *t,int *uk){
    int oldUk = *uk, T = scan(lex,t,uk);
    if (T != 0x64) {
        printf ("Expected  `<for>`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    T = scan(lex,t,uk);
    if (T != 0x32) {
        printf ("Expected  `(`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Expression(t,uk);
    T = scan(lex,t,uk);
    if (T != 0x50) {
        printf ("Expected  `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Expression(t,uk);
    T = scan(lex,t,uk);
    if (T != 0x50) {
        printf ("Expected  `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Expression(t,uk);
    T = scan(lex,t,uk);
    if (T != 0x33) {
        printf ("Expected  `)`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Operator(t,uk);
}

canonical_original_code:
void For(char *t, int *uk){
    int oldUk = *uk; int T = scan(lex,t,uk);
    if (T != 0x64) {
        printf ("Expected  `<for>`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    T = scan(lex,t,uk);
    if (T != 0x32) {
        printf ("Expected  `(`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Expression(t,uk);
    T = scan(lex,t,uk);
    if (T != 0x50) {
        printf ("Expected  `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Expression(t,uk);
    T = scan(lex,t,uk);
    if (T != 0x50) {
        printf ("Expected  `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Expression(t,uk);
    T = scan(lex,t,uk);
    if (T != 0x33) {
        printf ("Expected  `)`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
    Operator(t,uk);
}

variable_types:
t
char *

variable_types:
uk
int *

variable_types: oldUk int

variable_types: T int

return_type: void


Operator

decompiled_code:
__int64 __fastcall Operator(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax

v2 = *a2;
result = scan(lex, a1, a2);
switch ( (_DWORD)result )
{
case 0x64:
*a2 = v2;
return For(a1, a2);
case 0x34:
*a2 = v2;
return Block(a1, a2);
case 1:
if ( (unsigned int)scan(lex, a1, a2) == 50 )
{
v4 = scan(lex, a1, a2);
if ( v4 != 51 )
{
printf("Expected `<id>()`, got: %x, uk: %d, lex: %s", v4, *a2, lex);
exit(1);
}
goto LABEL_9;
}
break;
default:
if ( (unsigned int)(result - 32) > 1 && (_DWORD)result != 50 )
goto LABEL_6;
break;
}
*a2 = v2;
Expression(a1, a2);
LABEL_9:
result = scan(lex, a1, a2);
LABEL_6:
if ( (_DWORD)result != 80 )
{
printf("Expected `;`, got: %x, uk: %d, lex: %s", (unsigned int)result, *a2, lex);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax

v2 = *a2;
result = scan(lex, a1, a2);
switch ( (_DWORD)result )
{
case 0x64:
*a2 = v2;
return func8(a1, a2);
case 0x34:
*a2 = v2;
return func10(a1, a2);
case 1:
if ( (unsigned int)scan(lex, a1, a2) == 50 )
{
v4 = scan(lex, a1, a2);
if ( v4 != 51 )
{
printf("Expected `<id>()`, got: %x, uk: %d, lex: %s", v4, *a2, lex);
exit(1);
}
goto LABEL_9;
}
break;
default:
if ( (unsigned int)(result - 32) > 1 && (_DWORD)result != 50 )
goto LABEL_6;
break;
}
*a2 = v2;
func6(a1, a2);
LABEL_9:
result = scan(lex, a1, a2);
LABEL_6:
if ( (_DWORD)result != 80 )
{
printf("Expected `;`, got: %x, uk: %d, lex: %s", (unsigned int)result, *a2, lex);
exit(1);
}
return result;
}

original_code:
void Operator(char *t,int *uk){
    int oldUk = *uk, T = scan(lex,t,uk);
    if (T == 0x64) {
        *uk = oldUk;
        For(t,uk);
        return;
    } else if (T == 0x34) {
        *uk = oldUk;
        Block(t,uk);
        return;
    }
    if (T == 0x1) {
        T = scan(lex,t,uk);
        if (T == 0x32) {
            T = scan(lex,t,uk);
            if (T != 0x33) {
                printf ("Expected `<id>()`, got: %x, uk: %d, lex: %s", T, *uk, lex);
                exit(1);
            } else {
                T = scan(lex,t,uk);
            }
        } else {
            *uk = oldUk;
            Expression(t,uk);
            T = scan(lex,t,uk);
        }
    } else if (T == 0x32 ||
               T == 0x20 ||
               T == 0x21 ) {
        *uk = oldUk;
        Expression(t,uk);
        T = scan(lex,t,uk);
    }
    if (T != 0x50) {
        printf ("Expected  `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
}

canonical_original_code:
void Operator(char *t, int *uk){
    int oldUk = *uk; int T = scan(lex,t,uk);
    if (T == 0x64) {
        *uk = oldUk;
        For(t,uk);
        return;
    } else if (T == 0x34) {
        *uk = oldUk;
        Block(t,uk);
        return;
    }
    if (T == 0x1) {
        T = scan(lex,t,uk);
        if (T == 0x32) {
            T = scan(lex,t,uk);
            if (T != 0x33) {
                printf ("Expected `<id>()`, got: %x, uk: %d, lex: %s", T, *uk, lex);
                exit(1);
            } else {
                T = scan(lex,t,uk);
            }
        } else {
            *uk = oldUk;
            Expression(t,uk);
            T = scan(lex,t,uk);
        }
    } else if (T == 0x32 ||
               T == 0x20 ||
               T == 0x21 ) {
        *uk = oldUk;
        Expression(t,uk);
        T = scan(lex,t,uk);
    }
    if (T != 0x50) {
        printf ("Expected  `;`, got: %x, uk: %d, lex: %s", T, *uk, lex);
        exit(1);
    }
}


Block

decompiled_code:
__int64 __fastcall Block(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax
__int64 v3; // r13
unsigned int v4; // er12
unsigned __int64 v5; // rax
__int64 result; // rax
__int64 v7[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = scan(lex, a1, a2);
if ( v2 != 52 )
{
printf("Expected `{ `, got: %x (uk: %d, lex: %s)", v2, *a2, lex);
exit(1);
}
v3 = 0x14000300000002LL;
current = createBlock(current, v7);
while ( 1 )
{
while ( 1 )
{
v4 = *a2;
v5 = scan(lex, a1, a2);
if ( (unsigned int)(v5 - 97) > 1 )
break;
*a2 = v4;
VarDescr(a1, a2);
}
if ( ((unsigned int)v5 > 0x34 || !_bittest64(&v3, v5)) && (_DWORD)v5 != 80 && (_DWORD)v5 != 100 )
break;
*a2 = v4;
Operator(a1, a2);
}
if ( (_DWORD)v5 != 53 )
{
printf("Expected `<var descr>` or `<operator>`, got: %x (uk: %d, lex: %s)", (unsigned int)v5, *a2, lex);
exit(1);
}
result = v7[0];
current = v7[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax
__int64 v3; // r13
unsigned int v4; // er12
unsigned __int64 v5; // rax
__int64 result; // rax
__int64 v7[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = scan(lex, a1, a2);
if ( v2 != 52 )
{
printf("Expected `{ `, got: %x (uk: %d, lex: %s)", v2, *a2, lex);
exit(1);
}
v3 = 0x14000300000002LL;
current = createBlock(current, v7);
while ( 1 )
{
while ( 1 )
{
v4 = *a2;
v5 = scan(lex, a1, a2);
if ( (unsigned int)(v5 - 97) > 1 )
break;
*a2 = v4;
func7(a1, a2);
}
if ( ((unsigned int)v5 > 0x34 || !_bittest64(&v3, v5)) && (_DWORD)v5 != 80 && (_DWORD)v5 != 100 )
break;
*a2 = v4;
func9(a1, a2);
}
if ( (_DWORD)v5 != 53 )
{
printf("Expected `<var descr>` or `<operator>`, got: %x (uk: %d, lex: %s)", (unsigned int)v5, *a2, lex);
exit(1);
}
result = v7[0];
current = v7[0];
return result;
}

original_code:
void Block(char *t, int *uk){
    int oldUk = *uk, T = scan(lex,t,uk);
    if (!(T == 0x34)) {
        printf ("Expected `{ `, got: %x (uk: %d, lex: %s)", T, *uk, lex);
        exit(1);
    }
    Node *rollback;
    current = createBlock(current, &rollback);
    while(T != 0x35) {
        oldUk = *uk;
        T = scan(lex,t,uk);
        if (T == 0x61 || T == 0x62) {
            *uk = oldUk;
            VarDescr(t,uk);
        } else if (T == 0x32 ||
                   T == 0x1 ||
                   T == 0x50 ||
                   T == 0x20 ||
                   T == 0x21 ||
                   T == 0x64 ||
                   T == 0x34) {
            *uk = oldUk;
            Operator(t,uk);
        } else if (T != 0x35) {
            printf ("Expected `<var descr>` or `<operator>`, got: %x (uk: %d, lex: %s)", T, *uk, lex);
            exit(1);
        }
    }
    current = rollback;
}

canonical_original_code:
void Block(char *t, int *uk){
    int oldUk = *uk; int T = scan(lex,t,uk);
    if (!(T == 0x34)) {
        printf ("Expected `{ `, got: %x (uk: %d, lex: %s)", T, *uk, lex);
        exit(1);
    }
    struct Node *rollback;
    current = createBlock(current, &rollback);
    while(T != 0x35) {
        oldUk = *uk;
        T = scan(lex,t,uk);
        if (T == 0x61 || T == 0x62) {
            *uk = oldUk;
            VarDescr(t,uk);
        } else if (T == 0x32 ||
                   T == 0x1 ||
                   T == 0x50 ||
                   T == 0x20 ||
                   T == 0x21 ||
                   T == 0x64 ||
                   T == 0x34) {
            *uk = oldUk;
            Operator(t,uk);
        } else if (T != 0x35) {
            printf ("Expected `<var descr>` or `<operator>`, got: %x (uk: %d, lex: %s)", T, *uk, lex);
            exit(1);
        }
    }
    current = rollback;
}

variable_types: struct Node { enum DATA_TYPE { dBlock=0, dTInt=1, dTInt64=2, dTVoidFunc=3, dTIntMain=4, dTFor=5 } type; enum BOOL { FALSE=0, TRUE=1 } isAssignable; char *data; struct Node *child; int elementsCount; } *

user_defined_types: struct Node { enum DATA_TYPE type; enum BOOL isAssignable; char *data; struct Node *child; int elementsCount; }


FuncDescr

decompiled_code:
__int64 __fastcall FuncDescr(__int64 a1, unsigned int *a2)
{
unsigned int v3; // er13
int v4; // eax
__int64 v5; // rsi
unsigned int v6; // er13
int v7; // eax
unsigned int v8; // er13
unsigned int v9; // eax

v3 = scan(lex, a1, a2);
v4 = scan(lex, a1, a2);
if ( v3 != 96 || (v5 = 3LL, v4 != 1) )
{
if ( v3 != 97 || v4 != 99 )
{
printf("Expected `void <id>` or `int main`, got: %x (uk: %d, lex: %s)", v3, *a2, lex);
exit(1);
}
v5 = 4LL;
}
current = addToTree(lex, v5, current);
v6 = scan(lex, a1, a2);
v7 = scan(lex, a1, a2);
if ( v6 != 50 || v7 != 51 )
{
printf("Expected `()`, got: %x (uk: %d, lex: %s)", v6, *a2, lex);
exit(1);
}
v8 = *a2;
v9 = scan(lex, a1, a2);
*a2 = v8;
if ( v9 != 52 )
{
printf("Expected `{ `, got: %x (uk: %d, lex: %s)", v9, v8, lex);
exit(1);
}
return Block(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int *a2)
{
unsigned int v3; // er13
int v4; // eax
__int64 v5; // rsi
unsigned int v6; // er13
int v7; // eax
unsigned int v8; // er13
unsigned int v9; // eax

v3 = scan(lex, a1, a2);
v4 = scan(lex, a1, a2);
if ( v3 != 96 || (v5 = 3LL, v4 != 1) )
{
if ( v3 != 97 || v4 != 99 )
{
printf("Expected `void <id>` or `int main`, got: %x (uk: %d, lex: %s)", v3, *a2, lex);
exit(1);
}
v5 = 4LL;
}
current = addToTree(lex, v5, current);
v6 = scan(lex, a1, a2);
v7 = scan(lex, a1, a2);
if ( v6 != 50 || v7 != 51 )
{
printf("Expected `()`, got: %x (uk: %d, lex: %s)", v6, *a2, lex);
exit(1);
}
v8 = *a2;
v9 = scan(lex, a1, a2);
*a2 = v8;
if ( v9 != 52 )
{
printf("Expected `{ `, got: %x (uk: %d, lex: %s)", v9, v8, lex);
exit(1);
}
return func10(a1, a2);
}

original_code:
void FuncDescr(char *t, int *uk){
 int oldUk, type,
  T = scan(lex, t, uk),
  T1 = scan(lex, t, uk);
 if (!((T == 0x60 && T1 == 0x1) || (T == 0x61 && T1 == 0x63))) {
       printf("Expected `void <id>` or `int main`, got: %x (uk: %d, lex: %s)", T, *uk, lex);
       exit(1);
    }
    type = (T1 == 0x63) ? dTIntMain : dTVoidFunc;
    current = addToTree(lex, type, current);
    T = scan(lex, t, uk);
    T1 = scan(lex, t, uk);
    if (!(T == 0x32 && T1 == 0x33)) {
        printf ("Expected `()`, got: %x (uk: %d, lex: %s)", T, *uk, lex);
        exit(1);
    }
    oldUk = *uk;
    T = scan(lex, t, uk);
    *uk = oldUk;
    if (!(T == 0x34)) {
        printf ("Expected `{ `, got: %x (uk: %d, lex: %s)", T, *uk, lex);
        exit(1);
    }
    Block(t, uk);
}

canonical_original_code:
void FuncDescr(char *t, int *uk){
 int oldUk; int type; int T = scan(lex, t, uk); int T1 = scan(lex, t, uk);
 if (!((T == 0x60 && T1 == 0x1) || (T == 0x61 && T1 == 0x63))) {
       printf("Expected `void <id>` or `int main`, got: %x (uk: %d, lex: %s)", T, *uk, lex);
       exit(1);
    }
    type = (T1 == 0x63) ? dTIntMain : dTVoidFunc;
    current = addToTree(lex, type, current);
    T = scan(lex, t, uk);
    T1 = scan(lex, t, uk);
    if (!(T == 0x32 && T1 == 0x33)) {
        printf ("Expected `()`, got: %x (uk: %d, lex: %s)", T, *uk, lex);
        exit(1);
    }
    oldUk = *uk;
    T = scan(lex, t, uk);
    *uk = oldUk;
    if (!(T == 0x34)) {
        printf ("Expected `{ `, got: %x (uk: %d, lex: %s)", T, *uk, lex);
        exit(1);
    }
    Block(t, uk);
}


scan

variable_types:
lex
char *

variable_types: i int

return_type: int


decompiled_code:
void __fastcall __noreturn my_err(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void my_err(char *string)
{
 perror(string);
 exit (1);
}

variable_types:
string
char *


original_code:
void sort_route_info(struct f_route *route, int num)
{
 int i, j, k;
 for(i = 0; i < num-1; i++)
 {
  k = i;
  for(j = i+1; j < num; j++)
   if(route[k].route_value > route[j].route_value)
    k = j;
  if(k != i)
  {
   struct f_route temp;
   temp = route[k];
   route[k] = route[i];
   route[i] = temp;
  }
 }
}

canonical_original_code:
void sort_route_info(struct f_route *route, int num)
{
 int i; int j; int k;
 for(i = 0; i < num-1; i++)
 {
  k = i;
  for(j = i+1; j < num; j++)
   if(route[k].route_value > route[j].route_value)
    k = j;
  if(k != i)
  {
   struct f_route temp;
   temp = route[k];
   route[k] = route[i];
   route[i] = temp;
  }
 }
}

variable_types: struct f_route { int route; int route_index; int matrix_index; int route_value; } *

variable_types: num int

variable_types: j int

variable_types: k int


listte

decompiled_code:
__int64 __fastcall listte(__int64 a1, __int64 a2)
{
const __int32_t **v2; // r13
__int32_t v3; // ebx
char v4; // bl

puts(&s);
readfile(a1, a2);
getchar();
system("clear");
puts(asc_1B8);
puts(asc_1E8);
puts(asc_218);
puts(asc_248);
puts(asc_280);
printf(format);
v2 = _ctype_toupper_loc();
while ( 1 )
{
v3 = (*v2)[(char)getchar()];
while ( getchar() != 10 )
;
if ( (_BYTE)v3 == 82 )
{
averpaixu(a1, a2);
getchar();
}
else if ( (char)v3 > 82 )
{
if ( (_BYTE)v3 == 88 )
readfile(a1, a2);
}
else if ( (_BYTE)v3 == 70 )
{
find(a1, a2);
getchar();
}
else if ( (_BYTE)v3 == 80 )
{
paixu(a1, a2);
getchar();
}
printf(&byte_2E8);
v4 = getchar();
getchar();
if ( v4 == 110 )
break;
system("clear");
puts(asc_1B8);
puts(asc_1E8);
puts(asc_218);
puts(asc_248);
puts(asc_280);
printf(format);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
const __int32_t **v2; // r13
__int32_t v3; // ebx
char v4; // bl

puts(&s);
readfile(a1, a2);
getchar();
system("clear");
puts(asc_1B8);
puts(asc_1E8);
puts(asc_218);
puts(asc_248);
puts(asc_280);
printf(format);
v2 = _ctype_toupper_loc();
while ( 1 )
{
v3 = (*v2)[(char)getchar()];
while ( getchar() != 10 )
;
if ( (_BYTE)v3 == 82 )
{
averpaixu(a1, a2);
getchar();
}
else if ( (char)v3 > 82 )
{
if ( (_BYTE)v3 == 88 )
readfile(a1, a2);
}
else if ( (_BYTE)v3 == 70 )
{
find(a1, a2);
getchar();
}
else if ( (_BYTE)v3 == 80 )
{
paixu(a1, a2);
getchar();
}
printf(&byte_2E8);
v4 = getchar();
getchar();
if ( v4 == 110 )
break;
system("clear");
puts(asc_1B8);
puts(asc_1E8);
puts(asc_218);
puts(asc_248);
puts(asc_280);
printf(format);
}
return 1LL;
}

original_code:
int listte(DOD *head,char filename[])
{
 char ch;
 printf("当前文件中所保存的数据如下\n");
 readfile(head,filename);
 getchar();
 system("clear");
 printf("\n\t\t此学生管理系统具有以下功能:\n");
 printf("\t\t&& 数据读取，请输入-------(X/x)\n");
 printf("\t\t&& 信息查询，请输入------(F/f)\n");
 printf("\t\t&& 学生单课成绩排序，请输入------(P/p)\n");
 printf("\t\t&& 学生平均分排序,请输入-----(R/r)\n");
 printf("\t\t&& 如果你想退出，请输入----------(Q/q)\n$$:");
 while(1)
 {
  ch=getchar();
  ch=toupper(ch);
  while(getchar() != '\n');
       switch(ch)
  {
   case 'X': readfile(head,filename);break;
   case 'F': find(head,filename);getchar();break;
   case 'P': paixu(head,filename);getchar();break;
   case 'R': averpaixu(head,filename);getchar();break;
   case 'Q': break;
  }
   printf("请问您是否还要继续其他操作？(y/n)\n$$:");
   ch=getchar();
   getchar();
         if(ch=='n')
    break;
   else
   {
    system("clear");
    printf("\n\t\t此学生管理系统具有以下功能:\n");
    printf("\t\t&& 数据读取，请输入-------(X/x)\n");
    printf("\t\t&& 信息查询，请输入------(F/f)\n");
    printf("\t\t&& 学生单课成绩排序，请输入------(P/p)\n");
    printf("\t\t&& 学生平均分排序,请输入-----(R/r)\n");
    printf("\t\t&& 如果你想退出，请输入----------(Q/q)\n$$:");
    continue;
   }
 }
 return 1;
}

canonical_original_code:
int listte(struct stu *head, char filename[])
{
 char ch;
 printf("当前文件中所保存的数据如下\n");
 readfile(head,filename);
 getchar();
 system("clear");
 printf("\n\t\t此学生管理系统具有以下功能:\n");
 printf("\t\t&& 数据读取，请输入-------(X/x)\n");
 printf("\t\t&& 信息查询，请输入------(F/f)\n");
 printf("\t\t&& 学生单课成绩排序，请输入------(P/p)\n");
 printf("\t\t&& 学生平均分排序,请输入-----(R/r)\n");
 printf("\t\t&& 如果你想退出，请输入----------(Q/q)\n$$:");
 while(1)
 {
  ch=getchar();
  ch=toupper(ch);
  while(getchar() != '\n');
       switch(ch)
  {
   case 'X': readfile(head,filename);break;
   case 'F': find(head,filename);getchar();break;
   case 'P': paixu(head,filename);getchar();break;
   case 'R': averpaixu(head,filename);getchar();break;
   case 'Q': break;
  }
   printf("请问您是否还要继续其他操作？(y/n)\n$$:");
   ch=getchar();
   getchar();
         if(ch=='n')
    break;
   else
   {
    system("clear");
    printf("\n\t\t此学生管理系统具有以下功能:\n");
    printf("\t\t&& 数据读取，请输入-------(X/x)\n");
    printf("\t\t&& 信息查询，请输入------(F/f)\n");
    printf("\t\t&& 学生单课成绩排序，请输入------(P/p)\n");
    printf("\t\t&& 学生平均分排序,请输入-----(R/r)\n");
    printf("\t\t&& 如果你想退出，请输入----------(Q/q)\n$$:");
    continue;
   }
 }
 return 1;
}

variable_types: struct stu { int num; char name[20]; struct stue { int year; int month; int day; } birth; char sex[6]; char class[15]; char address[20]; float eng; float math; float chinese; float average; float ever_sum; int e; struct stu *next; } *

variable_types:
filename
char []

variable_types: ch char

user_defined_types: struct stu { int num; char name[20]; struct stue birth; char sex[6]; char class[15]; char address[20]; float eng; float math; float chinese; float average; float ever_sum; int e; struct stu *next; }


creat

original_code:
int creat(DOD *head)
{
 DOD *p1,*p2,*p3,*p4,*q;
 char ch;
 int i=1;
 p1=head;
 printf("请选择排序方式\n");
  printf("学号排序(U/u)/姓名排序(N/n)\n$$:");
  scanf("%c",&ch);
  ch=toupper(ch);
 printf("学生信息的输入\n");
 system("clear");
 while(1)
 {
  printf("请输入第%d名同学的学号(整数,为零停止)\n",i++);
  p2=(DOD *)malloc(sizeof(struct stu));
  scanf("%d",&p2->num);
  if(p2->num==0)
   break;
  p4=head;
  while(p4->next!=((void *)0))
  {
   if(p4->next->num==p2->num)
   {
    printf("注意！此学号你一用过，请换一个学号！\n");
    scanf("%d",&p2->num);
   }
   p4=p4->next;
  }
  printf("请输入姓名(不加空格)\n");
  scanf("%s",p2->name);
  printf("请输入生日：年  月  日\n");
  scanf("%d%d%d",&p2->birth.year,
    &p2->birth.month,&p2->birth.day);
  printf("请输入性别\n");
  scanf("%s",p2->sex);
  printf("请输入班级\n");
  scanf("%s",p2->class);
  printf("请输入地址\n");
  scanf("%s",p2->address);
  printf("请输入：英语   高数   C语言\n");
  scanf("%f%f%f",&p2->eng,&p2->math,&p2->chinese);
  getchar();
  system("clear");
  p3=head;
  p1->next=p2;
   p2->next=((void *)0);
   if(ch=='U')
   {
   while(p3->next!=((void *)0)&&p3->next->num<p2->num)
    p3=p3->next;
   if(p3->next->num==p2->num)
    p1=p2;
   }
  if(ch=='N')
  {
   while(p3->next!=((void *)0)&&strcmp(p3->next->name,p2->name)<0)
    p3=p3->next;
   if(strcmp(p3->next->name,p2->name)==0)
    p1=p2;
  }
   if(p3->next->num!=p2->num||strcmp(p3->next->name,p2->name)!=0)
   {
    p1->next=((void *)0);
    q=p1;
    p1=p3->next;
    p2->next=p1;
    p3->next=p2;
    p1=q;
   }
 }
 p1->next=((void *)0);
 free(p2);
 return 1;
}

canonical_original_code:
int creat(struct stu *head)
{
 struct stu *p1; struct stu *p2; struct stu *p3; struct stu *p4; struct stu *q;
 char ch;
 int i = 1;
 p1=head;
 printf("请选择排序方式\n");
  printf("学号排序(U/u)/姓名排序(N/n)\n$$:");
  scanf("%c",&ch);
  ch=toupper(ch);
 printf("学生信息的输入\n");
 system("clear");
 while(1)
 {
  printf("请输入第%d名同学的学号(整数,为零停止)\n",i++);
  p2=(struct stu *)malloc(sizeof(struct stu));
  scanf("%d",&p2->num);
  if(p2->num==0)
   break;
  p4=head;
  while(p4->next!=((void *)0))
  {
   if(p4->next->num==p2->num)
   {
    printf("注意！此学号你一用过，请换一个学号！\n");
    scanf("%d",&p2->num);
   }
   p4=p4->next;
  }
  printf("请输入姓名(不加空格)\n");
  scanf("%s",p2->name);
  printf("请输入生日：年  月  日\n");
  scanf("%d%d%d",&p2->birth.year,
    &p2->birth.month,&p2->birth.day);
  printf("请输入性别\n");
  scanf("%s",p2->sex);
  printf("请输入班级\n");
  scanf("%s",p2->class);
  printf("请输入地址\n");
  scanf("%s",p2->address);
  printf("请输入：英语   高数   C语言\n");
  scanf("%f%f%f",&p2->eng,&p2->math,&p2->chinese);
  getchar();
  system("clear");
  p3=head;
  p1->next=p2;
   p2->next=((void *)0);
   if(ch=='U')
   {
   while(p3->next!=((void *)0)&&p3->next->num<p2->num)
    p3=p3->next;
   if(p3->next->num==p2->num)
    p1=p2;
   }
  if(ch=='N')
  {
   while(p3->next!=((void *)0)&&strcmp(p3->next->name,p2->name)<0)
    p3=p3->next;
   if(strcmp(p3->next->name,p2->name)==0)
    p1=p2;
  }
   if(p3->next->num!=p2->num||strcmp(p3->next->name,p2->name)!=0)
   {
    p1->next=((void *)0);
    q=p1;
    p1=p3->next;
    p2->next=p1;
    p3->next=p2;
    p1=q;
   }
 }
 p1->next=((void *)0);
 free(p2);
 return 1;
}

user_defined_types: struct stue { int year; int month; int day; }


repo: zcutlip/basic-data-structures

decompiled_code:
void __fastcall adt_test_data_destroy(void **a1)
{
int *v2; // rax
_QWORD *v3; // rdi
__int64 v4; // rbx
_DWORD *v5; // rax
void *v6; // [rsp+0h] [rbp-20h] BYREF

if ( a1 )
{
v2 = (int *)*a1;
if ( *a1 )
{
v3 = (_QWORD *)*((_QWORD *)v2 + 1);
if ( *v2 > 0 )
{
v4 = 0LL;
do
{
v6 = (void *)v3[v4];
_test_item_destroy(&v6);
v5 = *a1;
v3 = (_QWORD *)*((_QWORD *)*a1 + 1);
v3[v4++] = 0LL;
}
while ( *v5 > (int)v4 );
}
free(v3);
free(*a1);
*a1 = 0LL;
}
}
}

original_code:
void adt_test_data_destroy(adt_test_data **t_data_p)
{
    int i;
    adt_test_item *t_item;
    if(((void *)0)==t_data_p || ((void *)0)==*t_data_p)
    {
        return;
    }
    for(i=0;i<(*t_data_p)->item_count;i++)
    {
        t_item=(*t_data_p)->test_items[i];
        __test_item_destroy(&t_item);
        (*t_data_p)->test_items[i]=((void *)0);
    }
    free((*t_data_p)->test_items);
    free(*t_data_p);
    *t_data_p=((void *)0);
    return;
}

canonical_original_code:
void adt_test_data_destroy(struct adt_test_data_struct **t_data_p)
{
    int i;
    struct adt_test_item_struct *t_item;
    if(((void *)0)==t_data_p || ((void *)0)==*t_data_p)
    {
        return;
    }
    for(i=0;i<(*t_data_p)->item_count;i++)
    {
        t_item=(*t_data_p)->test_items[i];
        __test_item_destroy(&t_item);
        (*t_data_p)->test_items[i]=((void *)0);
    }
    free((*t_data_p)->test_items);
    free(*t_data_p);
    *t_data_p=((void *)0);
    return;
}

variable_types: struct adt_test_data_struct { int item_count; int current_item; struct adt_test_item_struct { unsigned int number; char key[1024]; char data[1024]; int removed; } **test_items; } **

user_defined_types: struct adt_test_data_struct { int item_count; int current_item; struct adt_test_item_struct **test_items; }


decompiled_code:
__int64 seed_random()
{
int v0; // eax
int v1; // ebp
unsigned int buf[4]; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/random", 0);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = v0;
if ( (unsigned __int64)read(v0, buf, 8uLL) <= 7 )
return 0xFFFFFFFFLL;
close(v1);
srandom(buf[0]);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v1; // ebp
unsigned int buf[4]; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/random", 0);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = v0;
if ( (unsigned __int64)read(v0, buf, 8uLL) <= 7 )
return 0xFFFFFFFFLL;
close(v1);
srandom(buf[0]);
return 0LL;
}

original_code:
adt_status seed_random(void)
{
    int fd;
    long random;
    fd=open("/dev/random",00);
    if(fd<0)
    {
        return -1;
    }
    if(read(fd,(void *)&random,sizeof(random)) < sizeof(random))
    {
        return -1;
    }
    close(fd);
    srandom(random);
    return 0;
}

canonical_original_code:
int seed_random()
{
    int fd;
    long random;
    fd=open("/dev/random",00);
    if(fd<0)
    {
        return -1;
    }
    if(read(fd,(void *)&random,sizeof(random)) < sizeof(random))
    {
        return -1;
    }
    close(fd);
    srandom(random);
    return 0;
}

variable_types: fd int

variable_types: random long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)test_remove_last(argc, argv, envp) )
_assert_fail("ADT_OK==status", "test_list.c", 0x1EDu, "main");
if ( (unsigned int)test_remove_first() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F0u, "main");
if ( (unsigned int)test_insert_before() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F3u, "main");
if ( (unsigned int)test_insert_after() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F6u, "main");
if ( (unsigned int)test_remove_node() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F9u, "main");
puts("All tests succesful.");
printf("%s\n\n", "*******************************************");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func6(argc, argv, envp) )
_assert_fail("ADT_OK==status", "test_list.c", 0x1EDu, "main");
if ( (unsigned int)func7() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F0u, "main");
if ( (unsigned int)func3() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F3u, "main");
if ( (unsigned int)func4() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F6u, "main");
if ( (unsigned int)func5() )
_assert_fail("ADT_OK==status", "test_list.c", 0x1F9u, "main");
puts("All tests succesful.");
printf("%s\n\n", "*******************************************");
return 0;
}

original_code:
int main(void)
{
    adt_status status;
    status=test_remove_last();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 493, __extension__ __PRETTY_FUNCTION__); }));
    status=test_remove_first();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 496, __extension__ __PRETTY_FUNCTION__); }));
    status=test_insert_before();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 499, __extension__ __PRETTY_FUNCTION__); }));
    status=test_insert_after();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 502, __extension__ __PRETTY_FUNCTION__); }));
    status=test_remove_node();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 505, __extension__ __PRETTY_FUNCTION__); }));
    printf("All tests succesful.\n");
    printf("%s\n\n","*******************************************");
    return 0;
}

canonical_original_code:
int main()
{
    int status;
    status=test_remove_last();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 493, __extension__ __PRETTY_FUNCTION__); }));
    status=test_remove_first();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 496, __extension__ __PRETTY_FUNCTION__); }));
    status=test_insert_before();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 499, __extension__ __PRETTY_FUNCTION__); }));
    status=test_insert_after();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 502, __extension__ __PRETTY_FUNCTION__); }));
    status=test_remove_node();
    ((void) sizeof ((0==status) ? 1 : 0), __extension__ ({ if (0==status) ; else __assert_fail ("ADT_OK==status", "test_list.c", 505, __extension__ __PRETTY_FUNCTION__); }));
    printf("All tests succesful.\n");
    printf("%s\n\n","*******************************************");
    return 0;
}

variable_types: status int


repo: zcz/cps

decompiled_code:
double __fastcall Z_period(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12
double v4; // xmm0_8
double result; // xmm0_8
double v6; // [rsp+8h] [rbp-20h]
double v7; // [rsp+8h] [rbp-20h]

v2 = *(&PV_disstart + 1) + 60 * PV_disstart;
v3 = *(&PV_disend + 1) + 60 * PV_disend;
if ( v2 > a1 && v2 < a2 )
{
v6 = Z_period(a1, *(&PV_disstart + 1) + 60 * PV_disstart);
result = Z_period(v2, a2) + v6;
}
else if ( v3 < a2 && v3 > a1 )
{
v7 = Z_period(a1, *(&PV_disend + 1) + 60 * PV_disend);
result = Z_period(v3, a2) + v7;
}
else
{
v4 = (double)((int)a2 - (int)a1);
if ( v2 > a1 || v3 < a2 )
result = v4 * *(double *)&PV_norprice;
else
result = v4 * *(double *)&PV_disprice;
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12
double v4; // xmm0_8
double result; // xmm0_8
double v6; // [rsp+8h] [rbp-20h]
double v7; // [rsp+8h] [rbp-20h]

v2 = *(&PV_disstart + 1) + 60 * PV_disstart;
v3 = *(&PV_disend + 1) + 60 * PV_disend;
if ( v2 > a1 && v2 < a2 )
{
v6 = func0(a1, *(&PV_disstart + 1) + 60 * PV_disstart);
result = func0(v2, a2) + v6;
}
else if ( v3 < a2 && v3 > a1 )
{
v7 = func0(a1, *(&PV_disend + 1) + 60 * PV_disend);
result = func0(v3, a2) + v7;
}
else
{
v4 = (double)((int)a2 - (int)a1);
if ( v2 > a1 || v3 < a2 )
result = v4 * *(double *)&PV_norprice;
else
result = v4 * *(double *)&PV_disprice;
}
return result;
}

original_code:
double Z_period( long Z_q, long Z_h )
{
  long Z_qq, Z_hh;
  Z_qq=60*PV_disstart[0]+PV_disstart[1];
  Z_hh=60*PV_disend[0]+PV_disend[1];
  if ((Z_qq>Z_q) && (Z_qq<Z_h)) return( Z_period( Z_q, Z_qq )+ Z_period( Z_qq, Z_h ) );
  if ((Z_hh<Z_h) && (Z_hh>Z_q)) return( Z_period( Z_q, Z_hh )+ Z_period( Z_hh, Z_h ) );
  if ((Z_qq<=Z_q) && (Z_hh>=Z_h)) return( (Z_h-Z_q) * PV_disprice );
  return( (Z_h-Z_q) * PV_norprice );
}

canonical_original_code:
double Z_period(long Z_q, long Z_h)
{
  long Z_qq; long Z_hh;
  Z_qq=60*PV_disstart[0]+PV_disstart[1];
  Z_hh=60*PV_disend[0]+PV_disend[1];
  if ((Z_qq>Z_q) && (Z_qq<Z_h)) return( Z_period( Z_q, Z_qq )+ Z_period( Z_qq, Z_h ) );
  if ((Z_hh<Z_h) && (Z_hh>Z_q)) return( Z_period( Z_q, Z_hh )+ Z_period( Z_hh, Z_h ) );
  if ((Z_qq<=Z_q) && (Z_hh>=Z_h)) return( (Z_h-Z_q) * PV_disprice );
  return( (Z_h-Z_q) * PV_norprice );
}

return_type: double


decompiled_code:
double __fastcall Z_double_double(double a1)
{
signed __int64 v1; // rdx
signed __int64 v2; // rax
int v3; // eax
char *endptr; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

sprintf(s, "%lf", a1);
v1 = strlen(s);
v2 = 0LL;
do
{
if ( s[v2] == 46 )
s[v2] = 0;
++v2;
}
while ( v1 >= v2 );
strtod(s, &endptr);
return (double)v3;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
signed __int64 v1; // rdx
signed __int64 v2; // rax
int v3; // eax
char *endptr; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

sprintf(s, "%lf", a1);
v1 = strlen(s);
v2 = 0LL;
do
{
if ( s[v2] == 46 )
s[v2] = 0;
++v2;
}
while ( v1 >= v2 );
strtod(s, &endptr);
return (double)v3;
}

original_code:
double Z_double_double( double Z_d )
{
  char Z_s[100], *Z_temp;
  long i, o, p;
  double dd;
  sprintf( Z_s, "%lf", Z_d);
  p = strlen(Z_s);
  for (i=0;i<=p;i++)
    if (Z_s[i]=='.') Z_s[i] = '\0';
  dd = strtod( Z_s, &Z_temp );
  return(dd);
}

canonical_original_code:
double Z_double_double(double Z_d)
{
  char Z_s[100]; char *Z_temp;
  long i; long o; long p;
  double dd;
  sprintf( Z_s, "%lf", Z_d);
  p = strlen(Z_s);
  for (i=0;i<=p;i++)
    if (Z_s[i]=='.') Z_s[i] = '\0';
  dd = strtod( Z_s, &Z_temp );
  return(dd);
}

variable_types: i long

variable_types: o long

variable_types: p long

variable_types: dd double


decompiled_code:
void __fastcall L_gift(double *a1, double a2)
{
bool v3; // zf
double v4; // xmm0_8
double v5; // xmm3_8
double v6; // xmm2_8
double v7; // xmm0_8

v3 = a2 == 0.0;
v4 = *a1;
if ( v3 || *(double *)&PV_threshold > v4 )
{
*a1 = v4 + a2;
}
else
{
v5 = Z_double_double(a2 / *(double *)&PV_gift);
v6 = Z_double_double(*a1 / *(double *)&PV_threshold);
if ( a2 >= *(double *)&PV_gift * v6 )
{
*a1 = *a1 - v6 * *(double *)&PV_threshold + a2 - *(double *)&PV_gift * v6;
}
else
{
v7 = *a1 - *(double *)&PV_threshold * v5;
*a1 = v7;
if ( a2 - v5 * *(double *)&PV_gift > 0.00001 )
*a1 = v7 - *(double *)&PV_threshold;
}
}
}

canonical_decompiled_code:
void __fastcall func3(double *a1, double a2)
{
bool v3; // zf
double v4; // xmm0_8
double v5; // xmm3_8
double v6; // xmm2_8
double v7; // xmm0_8

v3 = a2 == 0.0;
v4 = *a1;
if ( v3 || *(double *)&PV_threshold > v4 )
{
*a1 = v4 + a2;
}
else
{
v5 = func1(a2 / *(double *)&PV_gift);
v6 = func1(*a1 / *(double *)&PV_threshold);
if ( a2 >= *(double *)&PV_gift * v6 )
{
*a1 = *a1 - v6 * *(double *)&PV_threshold + a2 - *(double *)&PV_gift * v6;
}
else
{
v7 = *a1 - *(double *)&PV_threshold * v5;
*a1 = v7;
if ( a2 - v5 * *(double *)&PV_gift > 0.00001 )
*a1 = v7 - *(double *)&PV_threshold;
}
}
}

original_code:
double L_gift(double *P,double discount)
{
  double a, b, Z_c;
  double gift;
  if ((discount==0)||((*P)<PV_threshold))
  {
    (*P) = (*P) + discount;
    return 0;
  }
  else
  {
    a=Z_double_double(discount/PV_gift);
    b=Z_double_double((*P)/PV_threshold);
    if (b*PV_gift<=discount)
    {
      gift=b*PV_gift;
      (*P)=(*P)-b*PV_threshold+discount-gift;
    } else
    {
      gift=discount;
      (*P)=(*P)-(a)*PV_threshold;
      if ((discount - a * PV_gift)>0.00001) (*P)=(*P)-PV_threshold;
    }
  }
  return gift;
}

canonical_original_code:
double L_gift(double *P, double discount)
{
  double a; double b; double Z_c;
  double gift;
  if ((discount==0)||((*P)<PV_threshold))
  {
    (*P) = (*P) + discount;
    return 0;
  }
  else
  {
    a=Z_double_double(discount/PV_gift);
    b=Z_double_double((*P)/PV_threshold);
    if (b*PV_gift<=discount)
    {
      gift=b*PV_gift;
      (*P)=(*P)-b*PV_threshold+discount-gift;
    } else
    {
      gift=discount;
      (*P)=(*P)-(a)*PV_threshold;
      if ((discount - a * PV_gift)>0.00001) (*P)=(*P)-PV_threshold;
    }
  }
  return gift;
}

variable_types:
P
double *

variable_types: discount double

variable_types: a double

variable_types: b double

variable_types: gift double


decompiled_code:
_BOOL8 __fastcall L_year(int a1)
{
_BOOL8 result; // rax
int v2; // edi

result = 0LL;
if ( (a1 & 3) == 0 )
{
result = 1LL;
v2 = -1030792151 * a1 + 85899344;
if ( __ROR4__(v2, 4) > 0xA3D70Au )
result = __ROR4__(v2, 2) > 0x28F5C28u;
}
return result;
}

original_code:
int L_year(int year)
{
  if( (year%4) !=0) return 0;
  else if( (year%400) !=0 && (year%100)==0) return 0;
  else return 1;
}

variable_types: year int


variable_types:
y
int [2]

variable_types:
m
int [2]

variable_types:
d
int [2]

variable_types:
h
int [2]

variable_types:
min
int [2]

variable_types: i int

variable_types: j int

variable_types: c int

variable_types: gap long

variable_types: days int

variable_types: daysum int

variable_types:
day
int [2]

variable_types:
n
int [13]

return_type: long


variable_types: daycost double

variable_types: sum double

variable_types: a int

variable_types: b int

variable_types: n int


decompiled_code:
int __fastcall P_time(char *s1)
{
double v1; // xmm0_8
int v2; // eax
int result; // eax
char *endptr; // [rsp+8h] [rbp-80h] BYREF
char dest[120]; // [rsp+10h] [rbp-78h] BYREF

strcpy(dest, s1);
dest[4] = 0;
v1 = strtod(dest, &endptr);
if ( v2 >= PV_lastyear )
{
P_status(PV_mess[11], v1);
result = -11;
}
else
{
result = strcmp(s1, PV_shijian);
if ( result )
{
if ( result <= 0 )
{
P_status(PV_mess[10], v1);
result = -10;
}
else
{
strcpy(PV_shijian, s1);
result = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s1)
{
double v1; // xmm0_8
int v2; // eax
int result; // eax
char *endptr; // [rsp+8h] [rbp-80h] BYREF
char dest[120]; // [rsp+10h] [rbp-78h] BYREF

strcpy(dest, s1);
dest[4] = 0;
v1 = strtod(dest, &endptr);
if ( v2 >= PV_lastyear )
{
P_status(PV_mess[11], v1);
result = -11;
}
else
{
result = strcmp(s1, PV_shijian);
if ( result )
{
if ( result <= 0 )
{
P_status(PV_mess[10], v1);
result = -10;
}
else
{
strcpy(PV_shijian, s1);
result = 0;
}
}
}
return result;
}

original_code:
int P_time(char Y_newtime[])
{
  int a;
char Z_s[100], *Z_char;
double Z_d;
strcpy( Z_s, Y_newtime );
Z_s[4] = '\0';
Z_d = strtod( Z_s, &Z_char );
if (Z_d>=PV_lastyear) {P_status(PV_mess[11]);return -11;};
  a=strcmp(Y_newtime,PV_shijian);
  if(a==0) return 0;
  if(a>0)
  {
    strcpy(PV_shijian,Y_newtime);
    return 0;
  }
  if(a<0) {P_status(PV_mess[10]);return -10;};
}

canonical_original_code:
int P_time(char Y_newtime[])
{
  int a;
char Z_s[100]; char *Z_char;
double Z_d;
strcpy( Z_s, Y_newtime );
Z_s[4] = '\0';
Z_d = strtod( Z_s, &Z_char );
if (Z_d>=PV_lastyear) {P_status(PV_mess[11]);return -11;};
  a=strcmp(Y_newtime,PV_shijian);
  if(a==0) return 0;
  if(a>0)
  {
    strcpy(PV_shijian,Y_newtime);
    return 0;
  }
  if(a<0) {P_status(PV_mess[10]);return -10;};
}


decompiled_code:
__int64 __fastcall P_indebug(_BYTE *a1, char *a2, _BYTE *a3, double a4)
{
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-E8h] BYREF
char v6[120]; // [rsp+70h] [rbp-78h] BYREF

if ( *a1 )
{
if ( *a2 )
{
if ( *a3 )
{
if ( P_carspos(a1, &v5, v6) > 0 )
{
P_status(PV_mess[12], a4);
result = 4294967284LL;
}
else
{
result = (unsigned int)(P_time(a2) >> 31);
}
}
else
{
P_status(PV_mess[9], a4);
result = 4294967287LL;
}
}
else
{
P_status(PV_mess[8], a4);
result = 4294967288LL;
}
}
else
{
P_status(PV_mess[7], a4);
result = 4294967289LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, char *a2, _BYTE *a3, double a4)
{
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-E8h] BYREF
char v6[120]; // [rsp+70h] [rbp-78h] BYREF

if ( *a1 )
{
if ( *a2 )
{
if ( *a3 )
{
if ( P_carspos(a1, &v5, v6) > 0 )
{
P_status(PV_mess[12], a4);
result = 4294967284LL;
}
else
{
result = (unsigned int)(func0(a2) >> 31);
}
}
else
{
P_status(PV_mess[9], a4);
result = 4294967287LL;
}
}
else
{
P_status(PV_mess[8], a4);
result = 4294967288LL;
}
}
else
{
P_status(PV_mess[7], a4);
result = 4294967289LL;
}
return result;
}

original_code:
int P_indebug(char Y_car[], char Y_timein[], char Y_name[])
{
  if (strlen( Y_car )==0) {P_status(PV_mess[7]);return -7;};
  if (strlen( Y_timein )==0) {P_status(PV_mess[8]);return -8;};
  if (strlen( Y_name ) == 0) {P_status(PV_mess[9]);return -9;};
  char Y_temp1[100], Y_temp2[100];
  if(P_carspos(Y_car,Y_temp1,Y_temp2)>0) {P_status(PV_mess[12]);return -12;}
  else if (P_time(Y_timein)<0) return -1;
       else return 0;
}

canonical_original_code:
int P_indebug(char Y_car[], char Y_timein[], char Y_name[])
{
  if (strlen( Y_car )==0) {P_status(PV_mess[7]);return -7;};
  if (strlen( Y_timein )==0) {P_status(PV_mess[8]);return -8;};
  if (strlen( Y_name ) == 0) {P_status(PV_mess[9]);return -9;};
  char Y_temp1[100]; char Y_temp2[100];
  if(P_carspos(Y_car,Y_temp1,Y_temp2)>0) {P_status(PV_mess[12]);return -12;}
  else if (P_time(Y_timein)<0) return -1;
       else return 0;
}


decompiled_code:
__int64 __fastcall P_outdebug(_BYTE *a1, char *a2, _BYTE *a3, double a4)
{
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-E8h] BYREF
char v6[120]; // [rsp+70h] [rbp-78h] BYREF

if ( *a1 )
{
if ( *a2 )
{
if ( *a3 )
{
if ( P_carspos(a1, &v5, v6) < 0 )
result = 4294967282LL;
else
result = (unsigned int)(P_time(a2) >> 31);
}
else
{
P_status(PV_mess[9], a4);
result = 4294967287LL;
}
}
else
{
P_status(PV_mess[8], a4);
result = 4294967288LL;
}
}
else
{
P_status(PV_mess[7], a4);
result = 4294967289LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, char *a2, _BYTE *a3, double a4)
{
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-E8h] BYREF
char v6[120]; // [rsp+70h] [rbp-78h] BYREF

if ( *a1 )
{
if ( *a2 )
{
if ( *a3 )
{
if ( P_carspos(a1, &v5, v6) < 0 )
result = 4294967282LL;
else
result = (unsigned int)(func0(a2) >> 31);
}
else
{
P_status(PV_mess[9], a4);
result = 4294967287LL;
}
}
else
{
P_status(PV_mess[8], a4);
result = 4294967288LL;
}
}
else
{
P_status(PV_mess[7], a4);
result = 4294967289LL;
}
return result;
}

original_code:
int P_outdebug(char Y_car[], char Y_timeout[], char Y_nameout[])
{
  if (strlen( Y_car )==0) {P_status(PV_mess[7]);return -7;};
  if (strlen( Y_timeout )==0) {P_status(PV_mess[8]);return -8;};
  if (strlen( Y_nameout )==0) {P_status(PV_mess[9]);return -9;};
  char Y_temp1[100], Y_temp2[100];
  if(P_carspos(Y_car,Y_temp1,Y_temp2)<0) return(-14);
  else if (P_time(Y_timeout)<0) return -1;
       else return 0;
}

canonical_original_code:
int P_outdebug(char Y_car[], char Y_timeout[], char Y_nameout[])
{
  if (strlen( Y_car )==0) {P_status(PV_mess[7]);return -7;};
  if (strlen( Y_timeout )==0) {P_status(PV_mess[8]);return -8;};
  if (strlen( Y_nameout )==0) {P_status(PV_mess[9]);return -9;};
  char Y_temp1[100]; char Y_temp2[100];
  if(P_carspos(Y_car,Y_temp1,Y_temp2)<0) return(-14);
  else if (P_time(Y_timeout)<0) return -1;
       else return 0;
}


decompiled_code:
__int64 __fastcall P_iinput(_BYTE *a1, char *a2, _BYTE *a3, __int64 a4, double a5)
{
int v7; // eax
unsigned int v8; // er12
int v10; // eax

v7 = P_indebug(a1, a2, a3, a5);
v8 = v7;
if ( v7 >= 0 && !v7 )
{
v10 = P_insert(a1, a2, a3, a4);
v8 = v10;
if ( v10 )
{
if ( v10 < 0 )
{
v8 = -13;
P_status(PV_mess[13], a5);
}
}
else
{
P_earn(a2, 1LL, 1.0);
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, char *a2, _BYTE *a3, __int64 a4, double a5)
{
int v7; // eax
unsigned int v8; // er12
int v10; // eax

v7 = func1(a1, a2, a3, a5);
v8 = v7;
if ( v7 >= 0 && !v7 )
{
v10 = P_insert(a1, a2, a3, a4);
v8 = v10;
if ( v10 )
{
if ( v10 < 0 )
{
v8 = -13;
P_status(PV_mess[13], a5);
}
}
else
{
P_earn(a2, 1LL, 1.0);
}
}
return v8;
}

original_code:
int P_iinput(char Y_car[], char Y_timein[], char Y_name[], long *Z_pos)
{
  int a,b,c;
  c = P_indebug(Y_car,Y_timein,Y_name);
  if(c<0) return c;
  if(c==0)
  {
    b=P_insert(Y_car,Y_timein,Y_name,Z_pos);
    if(b==0)
    {
      a=P_earn(Y_timein,1.0,1);
      return 0;
    }
    if(b<0) {P_status(PV_mess[13]);return -13;};
  }
}

canonical_original_code:
int P_iinput(char Y_car[], char Y_timein[], char Y_name[], long *Z_pos)
{
  int a; int b; int c;
  c = P_indebug(Y_car,Y_timein,Y_name);
  if(c<0) return c;
  if(c==0)
  {
    b=P_insert(Y_car,Y_timein,Y_name,Z_pos);
    if(b==0)
    {
      a=P_earn(Y_timein,1.0,1);
      return 0;
    }
    if(b<0) {P_status(PV_mess[13]);return -13;};
  }
}


original_code:
int P_oinput(char Y_car[], char Y_timeout[], char Y_nameout[], double *Y_moneymoney)
{
  char Y_timein[13],Y_namein[30];
  int a;
  double Y_money;
  long Y_times,Y_wholetime;
  double Y_wholemoney;
  double Z_p;
  int s,m,e;
  s=P_outdebug(Y_car,Y_timeout,Y_nameout);
  if(s<0) return s;
  if(s==0)
  {
    e=P_get(Y_car,Y_timein,Y_namein);
    if(e==0)
    {
      P_readout(Y_car,&Y_times,&Y_wholetime,&Y_wholemoney,&Z_p);
      Y_money=P_money(Y_timein,Y_timeout,&Z_p);
      P_readin(Y_car,&Y_money,&Z_p,Y_namein,Y_nameout,Y_timein,Y_timeout);
      P_earn(Y_timeout,Y_money,0);
      P_earn(Y_timeout,1.0,2);
      *Y_moneymoney = Y_money;
      return 0;
    }
  }
}

canonical_original_code:
int P_oinput(char Y_car[], char Y_timeout[], char Y_nameout[], double *Y_moneymoney)
{
  char Y_timein[13]; char Y_namein[30];
  int a;
  double Y_money;
  long Y_times; long Y_wholetime;
  double Y_wholemoney;
  double Z_p;
  int s; int m; int e;
  s=P_outdebug(Y_car,Y_timeout,Y_nameout);
  if(s<0) return s;
  if(s==0)
  {
    e=P_get(Y_car,Y_timein,Y_namein);
    if(e==0)
    {
      P_readout(Y_car,&Y_times,&Y_wholetime,&Y_wholemoney,&Z_p);
      Y_money=P_money(Y_timein,Y_timeout,&Z_p);
      P_readin(Y_car,&Y_money,&Z_p,Y_namein,Y_nameout,Y_timein,Y_timeout);
      P_earn(Y_timeout,Y_money,0);
      P_earn(Y_timeout,1.0,2);
      *Y_moneymoney = Y_money;
      return 0;
    }
  }
}

variable_types: s int

variable_types: m int

variable_types: e int


decompiled_code:
__int64 __fastcall P_pdiset(int a1, int a2, int a3, int a4, double a5, double a6)
{
__int64 result; // rax

if ( a2 + 60 * a1 > a4 + 60 * a3 )
{
P_status(PV_mess[5], a5);
result = 4294967291LL;
}
else
{
PV_disstart = a1;
result = 0LL;
*(&PV_disstart + 1) = a2;
PV_disend = a3;
*(&PV_disend + 1) = a4;
PV_norprice = *(_QWORD *)&a5;
PV_disprice = *(_QWORD *)&a6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, int a3, int a4, double a5, double a6)
{
__int64 result; // rax

if ( a2 + 60 * a1 > a4 + 60 * a3 )
{
P_status(PV_mess[5], a5);
result = 4294967291LL;
}
else
{
PV_disstart = a1;
result = 0LL;
*(&PV_disstart + 1) = a2;
PV_disend = a3;
*(&PV_disend + 1) = a4;
PV_norprice = *(_QWORD *)&a5;
PV_disprice = *(_QWORD *)&a6;
}
return result;
}

original_code:
int P_pdiset(int Y_a0, int Y_a1, int Y_b0, int Y_b1, double Y_c, double Y_d)
{
long Z_a, Z_b;
Z_a = Y_a0*60+Y_a1;
Z_b = Y_b0*60+Y_b1;
if (Z_a>Z_b) {P_status(PV_mess[5]);return -5;};
  PV_disstart[0]=Y_a0;
  PV_disstart[1]=Y_a1;
  PV_disend[0]=Y_b0;
  PV_disend[1]=Y_b1;
  PV_norprice=Y_c;
  PV_disprice=Y_d;
  return 0;
}

canonical_original_code:
int P_pdiset(int Y_a0, int Y_a1, int Y_b0, int Y_b1, double Y_c, double Y_d)
{
long Z_a; long Z_b;
Z_a = Y_a0*60+Y_a1;
Z_b = Y_b0*60+Y_b1;
if (Z_a>Z_b) {P_status(PV_mess[5]);return -5;};
  PV_disstart[0]=Y_a0;
  PV_disstart[1]=Y_a1;
  PV_disend[0]=Y_b0;
  PV_disend[1]=Y_b1;
  PV_norprice=Y_c;
  PV_disprice=Y_d;
  return 0;
}


decompiled_code:
__int64 __fastcall P_adiset(double a1, double a2)
{
__int64 result; // rax

if ( a2 >= a1 )
{
P_status(PV_mess[6], a1);
result = 4294967290LL;
}
else
{
PV_threshold = *(_QWORD *)&a1;
result = 0LL;
PV_gift = *(_QWORD *)&a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(double a1, double a2)
{
__int64 result; // rax

if ( a2 >= a1 )
{
P_status(PV_mess[6], a1);
result = 4294967290LL;
}
else
{
PV_threshold = *(_QWORD *)&a1;
result = 0LL;
PV_gift = *(_QWORD *)&a2;
}
return result;
}

original_code:
int P_adiset(double Y_a, double Y_b)
{
if (Y_a<=Y_b) {P_status(PV_mess[6]);return -6;};
  PV_threshold=Y_a;
  PV_gift=Y_b;
  return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12

v3 = -1;
G_menu(argc, argv, envp);
if ( argc == 2 )
v3 = -(strcmp(argv[1], "-f") == 0) - 1;
Z_cc = (__int64)calloc(0xF4241uLL, 0xD0uLL);
if ( !Z_cc )
{
fwrite("Cannot allocate memory\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
if ( (v3 & (unsigned int)G_uinit()) != 0 )
G_quit();
else
G_larg();
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 G_menu();
 unsigned int flag = ~0;
 if(argc == 2 && strcmp(*(argv+1), "-f") == 0)
  flag ^= 1;
 Z_cc = (struct Z_car *) calloc(1000000 + 1, sizeof(struct Z_car));
 if(!Z_cc) {
  fprintf(stderr, "Cannot allocate memory\n");
  exit(1);
 }
 if(!(G_uinit() & flag)) {
  G_larg();
  return(0);
 }
 G_quit();
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
flag
unsigned int

user_defined_types: struct Z_car { char car[21]; char user[31]; char date[13]; long father[4]; long number; }


repo: zdavkeos/Stack-Depth

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *retaddr; // [rsp+8h] [rbp+0h]

_cyg_profile_func_enter(main, retaddr, envp);
puts("calling foo 4 times");
foo(4LL);
foo(4LL);
foo(4LL);
foo(4LL);
_cyg_profile_func_exit(main, retaddr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *retaddr; // [rsp+8h] [rbp+0h]

func9(main, retaddr, envp);
puts("calling foo 4 times");
func8(4LL);
func8(4LL);
func8(4LL);
func8(4LL);
func10(main, retaddr);
return 0;
}

original_code:
int main(int argc, char** argv)
{
    int i;
    printf("calling foo 4 times\n");
    for (i = 0; i < 4; i++) {
        foo(4);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i;
    printf("calling foo 4 times\n");
    for (i = 0; i < 4; i++) {
        foo(4);
    }
    return 0;
}

variable_types: i int


bar

decompiled_code:
__int64 __fastcall bar(__int64 a1, __int64 a2, __int64 a3)
{
void *retaddr; // [rsp+8h] [rbp+0h]

_cyg_profile_func_enter(bar, retaddr, a3);
return _cyg_profile_func_exit(bar, retaddr);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
void *retaddr; // [rsp+8h] [rbp+0h]

func9(bar, retaddr, a3);
return func10(bar, retaddr);
}

original_code:
void bar()
{
}

canonical_original_code:
void bar()
{
}


foo

decompiled_code:
__int64 __fastcall foo(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx
__int64 retaddr; // [rsp+8h] [rbp+0h]

_cyg_profile_func_enter(foo, retaddr, a3);
bar((__int64)foo, retaddr, v3);
return _cyg_profile_func_exit(foo, retaddr);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx
__int64 retaddr; // [rsp+8h] [rbp+0h]

func9(foo, retaddr, a3);
func7((__int64)foo, retaddr, v3);
return func10(foo, retaddr);
}

original_code:
void foo()
{
    bar();
}

canonical_original_code:
void foo()
{
    bar();
}


main

repo: zendesk/ultragrep

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
const char *v4; // r8
__int64 *v5; // rdi
char *v6; // r12
size_t v7; // rax
__off_t v8; // r12
__ssize_t v9; // rax
char *v10; // [rsp+0h] [rbp-18h] BYREF
size_t n[2]; // [rsp+8h] [rbp-10h] BYREF

v10 = 0LL;
if ( argc <= 2 )
{
fwrite("Usage: ug_build_index process.lua file\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
v3 = 10LL;
v4 = argv[1];
v5 = &ctx;
v6 = (char *)argv[2];
while ( v3 )
{
*(_DWORD *)v5 = 0;
v5 = (__int64 *)((char *)v5 + 4);
--v3;
}
qword_1E0 = ug_lua_init(v4);
stream = fopen(v6, "r");
if ( stream )
{
open_indexes(v6);
v7 = strlen(v6);
if ( !strcmp(&v6[v7 - 3], ".gz") )
{
build_gz_index(&ctx);
}
else
{
while ( 1 )
{
v8 = ftello(stream);
v9 = getline(&v10, n, stream);
if ( v9 < 0 )
break;
ug_process_line(qword_1E0, v10, (unsigned int)v9, v8);
}
}
ug_lua_on_eof(qword_1E0);
exit(0);
}
perror("Couldn't open log file");
exit(1);
}

original_code:
int main(int argc, char **argv)
{
    char *line = ((void *)0), *lua_fname, *log_fname;
    ssize_t line_size;
    size_t allocated;
    if (argc < 3) {
        fprintf(stderr, "Usage: ug_build_index process.lua file\n");
        exit(1);
    }
    lua_fname = argv[1];
    log_fname = argv[2];
    bzero(&ctx, sizeof(build_idx_context_t));
    ctx.lua = ug_lua_init(lua_fname);
    ctx.flog = fopen(log_fname, "r");
    if (!ctx.flog) {
        perror("Couldn't open log file");
        exit(1);
    }
    open_indexes(log_fname);
    if (strcmp(log_fname + (strlen(log_fname) - 3), ".gz") == 0) {
        build_gz_index(&ctx);
    } else {
        while (1) {
            off_t offset;
            offset = ftello(ctx.flog);
            line_size = getline(&line, &allocated, ctx.flog);
            if ( line_size < 0 )
                break;
            ug_process_line(ctx.lua, line, line_size, offset);
        }
    }
    ug_lua_on_eof(ctx.lua);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *line = ((void *)0); char *lua_fname; char *log_fname;
    long line_size;
    unsigned long allocated;
    if (argc < 3) {
        fprintf(stderr, "Usage: ug_build_index process.lua file\n");
        exit(1);
    }
    lua_fname = argv[1];
    log_fname = argv[2];
    bzero(&ctx, sizeof(build_idx_context_t));
    ctx.lua = ug_lua_init(lua_fname);
    ctx.flog = fopen(log_fname, "r");
    if (!ctx.flog) {
        perror("Couldn't open log file");
        exit(1);
    }
    open_indexes(log_fname);
    if (strcmp(log_fname + (strlen(log_fname) - 3), ".gz") == 0) {
        build_gz_index(&ctx);
    } else {
        while (1) {
            long offset;
            offset = ftello(ctx.flog);
            line_size = getline(&line, &allocated, ctx.flog);
            if ( line_size < 0 )
                break;
            ug_process_line(ctx.lua, line, line_size, offset);
        }
    }
    ug_lua_on_eof(ctx.lua);
    exit(0);
}

variable_types:
line
char *

variable_types:
allocated
unsigned long

variable_types: offset long


original_code:
void handle_request(request_t *req)
{
    time_t floored_time;
    floored_time = req->time - (req->time % 10);
    if (!ctx.last_index_time || floored_time > ctx.last_index_time) {
        ug_write_index(ctx.findex, floored_time, req->offset);
        ctx.last_index_time = floored_time;
    }
}

canonical_original_code:
void handle_request(struct request_t *req)
{
    long floored_time;
    floored_time = req->time - (req->time % 10);
    if (!ctx.last_index_time || floored_time > ctx.last_index_time) {
        ug_write_index(ctx.findex, floored_time, req->offset);
        ctx.last_index_time = floored_time;
    }
}

variable_types: struct request_t { char *buf; long offset; long time; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
FILE *v4; // rbp
const char *v5; // rax
FILE *v6; // r13
__off_t v7; // rax
int v8; // eax
const char *v10; // rax
_BYTE v11[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( argc <= 2 )
{
fwrite("Usage: ug_cat file timestamp\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
v3 = (char *)argv[1];
v4 = fopen(v3, "r");
if ( !v4 )
{
perror("Couldn't open log file");
exit(1);
}
v5 = (const char *)ug_get_index_fname(v3, (char *)"idx");
v6 = fopen(v5, "r");
if ( !strcmp(&v3[strlen(v3) - 3], ".gz") )
{
if ( v6 )
{
v10 = (const char *)ug_get_index_fname(v3, "gzidx");
if ( !fopen(v10, "r") )
{
perror("error opening gzidx component");
exit(1);
}
}
atol(argv[2]);
ug_gzip_cat(v4);
}
else
{
if ( v6 )
{
atol(argv[2]);
v7 = ug_get_offset_for_timestamp(v6);
fseeko(v4, v7, 0);
}
while ( 1 )
{
v8 = fread(v11, 1uLL, 0x1000uLL, v4);
if ( !v8 )
break;
fwrite(v11, 1uLL, v8, stdout);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
FILE *v4; // rbp
const char *v5; // rax
FILE *v6; // r13
__off_t v7; // rax
int v8; // eax
const char *v10; // rax
_BYTE v11[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( argc <= 2 )
{
fwrite("Usage: ug_cat file timestamp\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
v3 = (char *)argv[1];
v4 = fopen(v3, "r");
if ( !v4 )
{
perror("Couldn't open log file");
exit(1);
}
v5 = (const char *)func13(v3, (char *)"idx");
v6 = fopen(v5, "r");
if ( !strcmp(&v3[strlen(v3) - 3], ".gz") )
{
if ( v6 )
{
v10 = (const char *)func13(v3, "gzidx");
if ( !fopen(v10, "r") )
{
perror("error opening gzidx component");
exit(1);
}
}
atol(argv[2]);
func8(v4);
}
else
{
if ( v6 )
{
atol(argv[2]);
v7 = func12(v6);
fseeko(v4, v7, 0);
}
while ( 1 )
{
v8 = fread(v11, 1uLL, 0x1000uLL, v4);
if ( !v8 )
break;
fwrite(v11, 1uLL, v8, stdout);
}
}
return 0;
}


decompiled_code:
char *__fastcall ug_get_index_fname(char *path, char *s)
{
char *v2; // r13
char *v3; // r14
size_t v4; // r15
char *v5; // rax
size_t v6; // r12
size_t v7; // rax
char *v8; // r12
char *v9; // rax

v2 = strdup(path);
v3 = dirname(v2);
v4 = strlen(v3);
v5 = __xpg_basename(path);
v6 = strlen(v5);
v7 = strlen(s);
v8 = (char *)malloc(v7 + v4 + v6 + 4);
v9 = __xpg_basename(path);
sprintf(v8, "%s/.%s.%s", v3, v9, s);
free(v2);
return v8;
}

canonical_decompiled_code:
char *__fastcall func13(char *path, char *s)
{
char *v2; // r13
char *v3; // r14
size_t v4; // r15
char *v5; // rax
size_t v6; // r12
size_t v7; // rax
char *v8; // r12
char *v9; // rax

v2 = strdup(path);
v3 = dirname(v2);
v4 = strlen(v3);
v5 = __xpg_basename(path);
v6 = strlen(v5);
v7 = strlen(s);
v8 = (char *)malloc(v7 + v4 + v6 + 4);
v9 = __xpg_basename(path);
sprintf(v8, "%s/.%s.%s", v3, v9, s);
free(v2);
return v8;
}

original_code:
char *ug_get_index_fname(char *log_fname, char *ext)
{
    char *tmp, *dir, *index_fname;
    tmp = strdup(log_fname);
    dir = dirname(tmp);
    index_fname = malloc(strlen(dir) + strlen(__xpg_basename(log_fname)) + strlen("/..") + strlen(ext) + 1);
    sprintf(index_fname, "%s/.%s.%s", dir, __xpg_basename(log_fname), ext);
    free(tmp);
    return index_fname;
}

canonical_original_code:
char *ug_get_index_fname(char *log_fname, char *ext)
{
    char *tmp; char *dir; char *index_fname;
    tmp = strdup(log_fname);
    dir = dirname(tmp);
    index_fname = malloc(strlen(dir) + strlen(__xpg_basename(log_fname)) + strlen("/..") + strlen(ext) + 1);
    sprintf(index_fname, "%s/.%s.%s", dir, __xpg_basename(log_fname), ext);
    free(tmp);
    return index_fname;
}

variable_types:
ext
char *

variable_types:
tmp
char *

variable_types:
dir
char *

return_type: char *


decompiled_code:
int __fastcall print_request(char *s)
{
char *v1; // rax
char *v2; // rdx
int v3; // ebp
int v4; // ebx

printf("%s", s);
v1 = &s[strlen(s) - 1];
if ( s < v1 )
{
while ( *v1 == 10 )
{
if ( s == --v1 )
goto LABEL_13;
}
if ( s < v1 )
{
v2 = v1;
do
v3 = (_DWORD)v1 - (_DWORD)v2--;
while ( s != v2 && *v2 != 10 );
if ( v3 )
{
v4 = 0;
do
{
++v4;
putchar(45);
}
while ( v4 != 80 && v3 > v4 );
}
}
}
LABEL_13:
putchar(10);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func2(char *s)
{
char *v1; // rax
char *v2; // rdx
int v3; // ebp
int v4; // ebx

printf("%s", s);
v1 = &s[strlen(s) - 1];
if ( s < v1 )
{
while ( *v1 == 10 )
{
if ( s == --v1 )
goto LABEL_13;
}
if ( s < v1 )
{
v2 = v1;
do
v3 = (_DWORD)v1 - (_DWORD)v2--;
while ( s != v2 && *v2 != 10 );
if ( v3 )
{
v4 = 0;
do
{
++v4;
putchar(45);
}
while ( v4 != 80 && v3 > v4 );
}
}
}
LABEL_13:
putchar(10);
return fflush(stdout);
}

original_code:
void print_request(char *request)
{
    int i, last_line_len = 0;
    char *p;
    printf("%s", request);
    p = request + (strlen(request) - 1);
    while ( p > request && (*p == '\n') )
      p--;
    while ( p > request && (*p != '\n') ) {
      p--;
      last_line_len++;
    }
    for (i = 0; i < (last_line_len - 1) && i < 80; i++)
        putchar('-');
    putchar('\n');
    fflush(stdout);
}

canonical_original_code:
void print_request(char *request)
{
    int i; int last_line_len = 0;
    char *p;
    printf("%s", request);
    p = request + (strlen(request) - 1);
    while ( p > request && (*p == '\n') )
      p--;
    while ( p > request && (*p != '\n') ) {
      p--;
      last_line_len++;
    }
    for (i = 0; i < (last_line_len - 1) && i < 80; i++)
        putchar('-');
    putchar('\n');
    fflush(stdout);
}

variable_types:
request
char *

variable_types:
p
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
FILE *v4; // r13
__int64 v5; // rbp
__int64 v6; // rcx
__ssize_t v7; // rax
char *v9; // [rsp+0h] [rbp-38h] BYREF
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v9 = 0LL;
n[0] = 0LL;
if ( argc <= 4 || (ctx = 0LL, xmmword_430 = 0LL, xmmword_440 = 0LL, parse_args(argc, (char **)argv) == -1) )
{
fwrite(
"Usage: ug_guts [-f input] -l file.lua -s start_time -e end_time regexps [... regexps]\n\n",
1uLL,
0x57uLL,
stderr);
exit(1);
}
v3 = ug_lua_init(xmmword_440);
if ( !v3 )
LABEL_12:
exit(1);
if ( !*((_QWORD *)&xmmword_440 + 1) )
{
v4 = stdin;
goto LABEL_6;
}
v4 = fopen(*((const char **)&xmmword_440 + 1), "r");
if ( !v4 )
{
perror(*((const char **)&xmmword_440 + 1));
goto LABEL_12;
}
LABEL_6:
v5 = 0LL;
do
{
v7 = getline(&v9, n, v4);
if ( v7 < 0 )
break;
v6 = v5;
v5 += v7;
ug_process_line(v3, v9, (unsigned int)v7, v6);
}
while ( *((__int64 *)&ctx + 1) >= max_request_time );
ug_lua_on_eof(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
FILE *v4; // r13
__int64 v5; // rbp
__int64 v6; // rcx
__ssize_t v7; // rax
char *v9; // [rsp+0h] [rbp-38h] BYREF
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v9 = 0LL;
n[0] = 0LL;
if ( argc <= 4 || (ctx = 0LL, xmmword_430 = 0LL, xmmword_440 = 0LL, func0(argc, (char **)argv) == -1) )
{
fwrite(
"Usage: ug_guts [-f input] -l file.lua -s start_time -e end_time regexps [... regexps]\n\n",
1uLL,
0x57uLL,
stderr);
exit(1);
}
v3 = ug_lua_init(xmmword_440);
if ( !v3 )
LABEL_12:
exit(1);
if ( !*((_QWORD *)&xmmword_440 + 1) )
{
v4 = stdin;
goto LABEL_6;
}
v4 = fopen(*((const char **)&xmmword_440 + 1), "r");
if ( !v4 )
{
perror(*((const char **)&xmmword_440 + 1));
goto LABEL_12;
}
LABEL_6:
v5 = 0LL;
do
{
v7 = getline(&v9, n, v4);
if ( v7 < 0 )
break;
v6 = v5;
v5 += v7;
ug_process_line(v3, v9, (unsigned int)v7, v6);
}
while ( *((__int64 *)&ctx + 1) >= max_request_time );
ug_lua_on_eof(v3);
return 0;
}


variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: y int

variable_types: nleapdays int

variable_types: t long

variable_types:
moff
unsigned short [12]


repo: zenhack/battstat

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char i; // al
FILE *v4; // rax
const char *v5; // r10
unsigned __int64 v6; // r9
unsigned __int64 v7; // rtt
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rax
const char *v10; // rdx
__int64 v11; // rax

for ( i = oldstatus; ; oldstatus = i )
{
while ( 1 )
{
if ( i != 85 )
sleep(1u);
memset(status_line, 0, sizeof(status_line));
status_f = (__int64)fopen("/sys/class/power_supply/BAT0/status", "r");
capacity_f = (__int64)fopen("/sys/class/power_supply/BAT0/capacity", "r");
power_now_f = (__int64)fopen("/sys/class/power_supply/BAT0/power_now", "r");
v4 = fopen("/sys/class/power_supply/BAT0/energy_now", "r");
energy_now_f = (__int64)v4;
if ( status_f )
{
if ( capacity_f
&& power_now_f
&& v4
&& (unsigned int)__isoc99_fscanf()
&& (unsigned int)__isoc99_fscanf()
&& (unsigned int)__isoc99_fscanf()
&& (unsigned int)__isoc99_fscanf()
&& power )
{
break;
}
}
close_files();
i = oldstatus;
}
v5 = "Discharging";
v6 = energy / (unsigned __int64)power;
hour = energy / (unsigned __int64)power;
v7 = 60 * (energy % (unsigned __int64)power);
v8 = v7 / power;
min = v7 / power;
energy = v7 % power;
v9 = 60 * (v7 % power) / power;
if ( status == 67 )
v5 = "Charging";
v10 = "%s (%d%%), %lu:%02lu:%02lu";
if ( status == 67 )
v10 = "%s (%d%%)";
sec = v9;
snprintf(status_line, 0x100uLL, v10, v5, (unsigned int)capacity, v6, v8, v9);
close_files();
puts(status_line);
fflush(stdout);
v11 = min;
if ( status != 67 && !hour )
{
if ( (unsigned __int64)min > 4 )
{
if ( (unsigned __int64)min > 0x13 )
goto LABEL_23;
}
else if ( (unsigned __int64)oldmin > 4 )
{
send_notification("critical", "Very Low Battery", status_line);
v11 = min;
goto LABEL_23;
}
if ( (unsigned __int64)oldmin > 0x13 )
{
send_notification("normal", 4202599LL, status_line);
v11 = min;
}
}
LABEL_23:
oldmin = v11;
oldhour = hour;
oldsec = sec;
i = status;
if ( oldstatus != 85 && oldstatus != status )
{
if ( status == 67 )
{
send_notification("normal", "AC adapter plugged in", status_line);
i = status;
}
else if ( status == 68 )
{
send_notification("normal", "AC adapter unplugged", status_line);
i = status;
}
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char i; // al
FILE *v4; // rax
const char *v5; // r10
unsigned __int64 v6; // r9
unsigned __int64 v7; // rtt
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rax
const char *v10; // rdx
__int64 v11; // rax

for ( i = oldstatus; ; oldstatus = i )
{
while ( 1 )
{
if ( i != 85 )
sleep(1u);
memset(status_line, 0, sizeof(status_line));
status_f = (__int64)fopen("/sys/class/power_supply/BAT0/status", "r");
capacity_f = (__int64)fopen("/sys/class/power_supply/BAT0/capacity", "r");
power_now_f = (__int64)fopen("/sys/class/power_supply/BAT0/power_now", "r");
v4 = fopen("/sys/class/power_supply/BAT0/energy_now", "r");
energy_now_f = (__int64)v4;
if ( status_f )
{
if ( capacity_f
&& power_now_f
&& v4
&& (unsigned int)__isoc99_fscanf()
&& (unsigned int)__isoc99_fscanf()
&& (unsigned int)__isoc99_fscanf()
&& (unsigned int)__isoc99_fscanf()
&& power )
{
break;
}
}
func8();
i = oldstatus;
}
v5 = "Discharging";
v6 = energy / (unsigned __int64)power;
hour = energy / (unsigned __int64)power;
v7 = 60 * (energy % (unsigned __int64)power);
v8 = v7 / power;
min = v7 / power;
energy = v7 % power;
v9 = 60 * (v7 % power) / power;
if ( status == 67 )
v5 = "Charging";
v10 = "%s (%d%%), %lu:%02lu:%02lu";
if ( status == 67 )
v10 = "%s (%d%%)";
sec = v9;
snprintf(status_line, 0x100uLL, v10, v5, (unsigned int)capacity, v6, v8, v9);
func8();
puts(status_line);
fflush(stdout);
v11 = min;
if ( status != 67 && !hour )
{
if ( (unsigned __int64)min > 4 )
{
if ( (unsigned __int64)min > 0x13 )
goto LABEL_23;
}
else if ( (unsigned __int64)oldmin > 4 )
{
func9("critical", "Very Low Battery", status_line);
v11 = min;
goto LABEL_23;
}
if ( (unsigned __int64)oldmin > 0x13 )
{
func9("normal", 4202599LL, status_line);
v11 = min;
}
}
LABEL_23:
oldmin = v11;
oldhour = hour;
oldsec = sec;
i = status;
if ( oldstatus != 85 && oldstatus != status )
{
if ( status == 67 )
{
func9("normal", "AC adapter plugged in", status_line);
i = status;
}
else if ( status == 68 )
{
func9("normal", "AC adapter unplugged", status_line);
i = status;
}
}
}
}

original_code:
int main(int argc, char **argv) {
    for(;;) {
        if(oldstatus != 'U') {
            sleep(1);
        }
        bzero(status_line, sizeof status_line);
        status_f = fopen("/sys/class/power_supply/BAT0/""status", "r");
        capacity_f = fopen("/sys/class/power_supply/BAT0/""capacity", "r");
        power_now_f = fopen("/sys/class/power_supply/BAT0/""power_now", "r");
        energy_now_f = fopen("/sys/class/power_supply/BAT0/""energy_now", "r");
        if(!status_f || !capacity_f || !power_now_f || !energy_now_f) {
            close_files();
            continue;
        }
        if(!fscanf(status_f, "%c", &status) ||
           !fscanf(capacity_f, "%d", &capacity) ||
           !fscanf(power_now_f, "%ld", &power) ||
           !fscanf(energy_now_f, "%ld", &energy)) {
            close_files();
            continue;
        }
        if(power == 0) {
            close_files();
            continue;
        }
        hour = energy/power;
        energy %= power;
        min = (60*energy)/power;
        energy = (60*energy)%power;
        sec = (60*energy)/power;
        snprintf(status_line, sizeof status_line,
            (status == 'C')? "%s (%d%%)" : "%s (%d%%), %lu:%02lu:%02lu",
            (status == 'C')? "Charging" : "Discharging",
            capacity, hour, min, sec);
        close_files();
        puts(status_line);
        fflush(stdout);
        if(status != 'C' && hour == 0) {
            if(min < 5 && oldmin >= 5) {
                send_notification("critical", "Very Low Battery", status_line);
            } else if(min < 20 && oldmin >= 20) {
                send_notification("normal", "Low Battery", status_line);
            }
        }
        oldhour = hour;
        oldmin = min;
        oldsec = sec;
        if(oldstatus != 'U' && oldstatus != status) {
            if(status == 'C') {
                send_notification("normal", "AC adapter plugged in", status_line);
            } else if(status == 'D') {
                send_notification("normal", "AC adapter unplugged", status_line);
            }
        }
        oldstatus = status;
    }
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int close_files()
{
close_if_open((FILE *)status_f);
close_if_open((FILE *)capacity_f);
close_if_open((FILE *)power_now_f);
return close_if_open((FILE *)energy_now_f);
}

canonical_decompiled_code:
int func8()
{
func7((FILE *)status_f);
func7((FILE *)capacity_f);
func7((FILE *)power_now_f);
return func7((FILE *)energy_now_f);
}

original_code:
void close_files(void) {
    close_if_open(status_f);
    close_if_open(capacity_f);
    close_if_open(power_now_f);
    close_if_open(energy_now_f);
}

canonical_original_code:
void close_files() {
    close_if_open(status_f);
    close_if_open(capacity_f);
    close_if_open(power_now_f);
    close_if_open(energy_now_f);
}


decompiled_code:
__pid_t __fastcall send_notification(char *a1, char *a2, char *a3)
{
__pid_t result; // eax
__pid_t stat_loc; // [rsp+Ch] [rbp-3Ch] BYREF
char *stat_loc_4[7]; // [rsp+10h] [rbp-38h] BYREF

stat_loc_4[0] = "/usr/bin/notify-send";
stat_loc_4[1] = "-u";
stat_loc_4[2] = a1;
stat_loc_4[3] = a2;
stat_loc_4[4] = a3;
stat_loc_4[5] = 0LL;
result = fork();
if ( result != -1 )
{
if ( result )
{
wait((__WAIT_STATUS)&stat_loc);
result = stat_loc;
}
else
{
result = execv("/usr/bin/notify-send", stat_loc_4);
}
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func9(char *a1, char *a2, char *a3)
{
__pid_t result; // eax
__pid_t stat_loc; // [rsp+Ch] [rbp-3Ch] BYREF
char *stat_loc_4[7]; // [rsp+10h] [rbp-38h] BYREF

stat_loc_4[0] = "/usr/bin/notify-send";
stat_loc_4[1] = "-u";
stat_loc_4[2] = a1;
stat_loc_4[3] = a2;
stat_loc_4[4] = a3;
stat_loc_4[5] = 0LL;
result = fork();
if ( result != -1 )
{
if ( result )
{
wait((__WAIT_STATUS)&stat_loc);
result = stat_loc;
}
else
{
result = execv("/usr/bin/notify-send", stat_loc_4);
}
}
return result;
}

original_code:
int send_notification(char *urgency, char *summary, char *body) {
    int status;
    char *argv[6];
    argv[0] = "/usr/bin/notify-send";
    argv[1] = "-u";
    argv[2] = urgency;
    argv[3] = summary;
    argv[4] = body;
    argv[5] = ((void *)0);
    switch(fork()) {
    case -1:
        return -1;
    case 0:
        return execv("/usr/bin/notify-send", argv);
    default:
        wait(&status);
        return status;
    }
}

variable_types:
urgency
char *

variable_types:
summary
char *

variable_types:
body
char *

variable_types: status int

variable_types:
argv
char *[6]


repo: zenhack/skilisp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rsi
int v5; // eax
int result; // eax
const char *v7; // rdx
char *ptr; // [rsp+8h] [rbp-10h]

v3 = skil_token(_bss_start);
if ( v3 < 0 )
return 0;
v4 = (unsigned int)v3;
while ( 1 )
{
if ( (_DWORD)v4 == 256 )
{
printf("ATOM: %s\n", ptr);
free(ptr);
goto LABEL_7;
}
if ( (int)v4 > 256 )
break;
if ( (unsigned int)(v4 - 40) > 1 )
goto LABEL_10;
printf("%c\n", v4);
LABEL_7:
v5 = skil_token(_bss_start);
v4 = (unsigned int)v5;
if ( v5 < 0 )
return 0;
}
result = 0;
if ( (_DWORD)v4 == 257 )
return result;
LABEL_10:
v7 = ptr;
if ( !ptr )
v7 = "NULL";
printf("Unknown token type %d with value %s!\n", v4, v7);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rsi
int v5; // eax
int result; // eax
const char *v7; // rdx
char *ptr; // [rsp+8h] [rbp-10h]

v3 = func11(_bss_start);
if ( v3 < 0 )
return 0;
v4 = (unsigned int)v3;
while ( 1 )
{
if ( (_DWORD)v4 == 256 )
{
printf("ATOM: %s\n", ptr);
free(ptr);
goto LABEL_7;
}
if ( (int)v4 > 256 )
break;
if ( (unsigned int)(v4 - 40) > 1 )
goto LABEL_10;
printf("%c\n", v4);
LABEL_7:
v5 = func11(_bss_start);
v4 = (unsigned int)v5;
if ( v5 < 0 )
return 0;
}
result = 0;
if ( (_DWORD)v4 == 257 )
return result;
LABEL_10:
v7 = ptr;
if ( !ptr )
v7 = "NULL";
printf("Unknown token type %d with value %s!\n", v4, v7);
return 1;
}

original_code:
int main(void) {
 char *img;
 int token_type;
 token_type = skil_token(stdin, &img);
 while(token_type >= 0) {
  switch(token_type) {
  case '(':
  case ')':
   printf("%c\n", token_type);
   break;
  case 256:
   printf("ATOM: %s\n", img);
   free(img);
   break;
  case 257:
   return 0;
   break;
  default:
   printf("Unknown token type %d with value %s!\n",
    token_type, (img)? img :"NULL");
   return 1;
   break;
  }
  token_type = skil_token(stdin, &img);
 }
 return 0;
}

canonical_original_code:
int main() {
 char *img;
 int token_type;
 token_type = skil_token(stdin, &img);
 while(token_type >= 0) {
  switch(token_type) {
  case '(':
  case ')':
   printf("%c\n", token_type);
   break;
  case 256:
   printf("ATOM: %s\n", img);
   free(img);
   break;
  case 257:
   return 0;
   break;
  default:
   printf("Unknown token type %d with value %s!\n",
    token_type, (img)? img :"NULL");
   return 1;
   break;
  }
  token_type = skil_token(stdin, &img);
 }
 return 0;
}

variable_types:
img
char *


isatomchar

original_code:
int isatomchar(int c) {
 return
  ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint) &&
  !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace) &&
  c != ';' &&
  c != '(' &&
  c != ')' &&
  c != (-1);
}

canonical_original_code:
int isatomchar(int c) {
 return
  ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint) &&
  !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace) &&
  c != ';' &&
  c != '(' &&
  c != ')' &&
  c != (-1);
}

variable_types: c int


decompiled_code:
__int64 __fastcall skil_string_buffer_init(_QWORD *a1)
{
_BYTE *v1; // rax
__int64 result; // rax

a1[1] = 16LL;
v1 = malloc(0x10uLL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
result = 0LL;
a1[2] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
_BYTE *v1; // rax
__int64 result; // rax

a1[1] = 16LL;
v1 = malloc(0x10uLL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
result = 0LL;
a1[2] = 0LL;
return result;
}

original_code:
int skil_string_buffer_init(skil_string_buffer_t *buf) {
 buf->cap = 16;
 buf->buf = malloc(sizeof(char) * buf->cap);
 if(!buf->buf) {
  return -1;
 }
 buf->buf[0] = '\0';
 buf->len = 0;
 return 0;
}

canonical_original_code:
int skil_string_buffer_init(struct skil_string_buffer_t *buf) {
 buf->cap = 16;
 buf->buf = malloc(sizeof(char) * buf->cap);
 if(!buf->buf) {
  return -1;
 }
 buf->buf[0] = '\0';
 buf->len = 0;
 return 0;
}

variable_types: struct skil_string_buffer_t { char *buf; unsigned long cap; } *


decompiled_code:
__int64 __fastcall skil_string_buffer_putc(__int64 a1, char a2)
{
__int64 v4; // rax
unsigned __int64 v5; // rsi
void *v6; // rdi
__int64 result; // rax
void *v8; // rax

v4 = *(_QWORD *)(a1 + 16);
v5 = *(_QWORD *)(a1 + 8);
v6 = *(void **)a1;
if ( v4 + 1 < v5 )
goto LABEL_2;
v8 = realloc(v6, 2 * v5);
v6 = v8;
if ( v8 )
{
*(_QWORD *)a1 = v8;
v4 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) *= 2LL;
LABEL_2:
*((_BYTE *)v6 + v4) = a2;
*(_BYTE *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 16) + 1LL) = 0;
result = 0LL;
++*(_QWORD *)(a1 + 16);
return result;
}
return 0xFFFFFFFFLL;
}

original_code:
int skil_string_buffer_putc(skil_string_buffer_t *buf, char c) {
 if(buf->len + 1 >= buf->cap) {
  char *newbuf = realloc(buf->buf, buf->cap * 2);
  if(!newbuf) {
   return -1;
  }
  buf->buf = newbuf;
  buf->cap *= 2;
 }
 buf->buf[buf->len] = c;
 buf->buf[buf->len+1] = '\0';
 buf->len++;
 return 0;
}

canonical_original_code:
int skil_string_buffer_putc(struct skil_string_buffer_t *buf, char c) {
 if(buf->len + 1 >= buf->cap) {
  char *newbuf = realloc(buf->buf, buf->cap * 2);
  if(!newbuf) {
   return -1;
  }
  buf->buf = newbuf;
  buf->cap *= 2;
 }
 buf->buf[buf->len] = c;
 buf->buf[buf->len+1] = '\0';
 buf->len++;
 return 0;
}

variable_types: c char

variable_types:
newbuf
char *

user_defined_types: struct skil_string_buffer_t { char *buf; unsigned long cap; }


search

repo: zenkj/lp

original_code:
static int search(lp_strpool *sp, const char* str) {
    int i = 0;
    int j = sp->idxcount - 1;
    char *pool = sp->pool;
    int *indexes = sp->indexes;
    while (i <= j) {
        int m = (i + j) / 2;
        char *b = &pool[indexes[m]];
        int r = strcmp(b, str);
        if (r == 0) {
            return indexes[m];
        } else if (r < 0) {
            i = m + 1;
        } else {
            j = m - 1;
        }
    }
    return -((i+j+1)/2) - 1;
}

canonical_original_code:
static int search(struct lp_strpool *sp, char *str) {
    int i = 0;
    int j = sp->idxcount - 1;
    char *pool = sp->pool;
    int *indexes = sp->indexes;
    while (i <= j) {
        int m = (i + j) / 2;
        char *b = &pool[indexes[m]];
        int r = strcmp(b, str);
        if (r == 0) {
            return indexes[m];
        } else if (r < 0) {
            i = m + 1;
        } else {
            j = m - 1;
        }
    }
    return -((i+j+1)/2) - 1;
}

variable_types: struct lp_strpool { int charcount; int charsize; char *pool; int idxcount; int idxsize; int *indexes; } *

variable_types:
str
char *

variable_types: i int

variable_types: j int

variable_types:
pool
char *

variable_types:
indexes
int *

variable_types: m int

variable_types:
b
char *

variable_types: r int


decompiled_code:
_QWORD *strpool_init()
{
void *v0; // rax
void *v1; // rbp
void *v2; // r13
_QWORD *v3; // rax
_QWORD *v4; // r12

v0 = malloc(0x1000uLL);
if ( !v0 )
goto LABEL_7;
v1 = v0;
v2 = malloc(0x400uLL);
if ( !v2 )
{
free(v1);
LABEL_7:
v4 = 0LL;
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
return v4;
}
v3 = malloc(0x20uLL);
v4 = v3;
if ( v3 )
{
v3[1] = v1;
*v3 = 0x100000000000LL;
v3[2] = 0x10000000000LL;
v3[3] = v2;
}
else
{
free(v1);
free(v2);
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
}
return v4;
}

canonical_decompiled_code:
_QWORD *func1()
{
void *v0; // rax
void *v1; // rbp
void *v2; // r13
_QWORD *v3; // rax
_QWORD *v4; // r12

v0 = malloc(0x1000uLL);
if ( !v0 )
goto LABEL_7;
v1 = v0;
v2 = malloc(0x400uLL);
if ( !v2 )
{
free(v1);
LABEL_7:
v4 = 0LL;
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
return v4;
}
v3 = malloc(0x20uLL);
v4 = v3;
if ( v3 )
{
v3[1] = v1;
*v3 = 0x100000000000LL;
v3[2] = 0x10000000000LL;
v3[3] = v2;
}
else
{
free(v1);
free(v2);
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
}
return v4;
}

original_code:
lp_strpool *strpool_init() {
    char *pool;
    int *indexes;
    lp_strpool *sp;
    pool = (char*)malloc(4096);
    if (pool == ((void *)0)) {
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    indexes = (int*)malloc(256 * sizeof(int));
    if (indexes == ((void *)0)) {
        free(pool);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp = (lp_strpool*)malloc(sizeof(lp_strpool));
    if (sp == ((void *)0)) {
        free(pool);
        free(indexes);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp->charcount = 0;
    sp->charsize = 4096;
    sp->pool = pool;
    sp->idxcount = 0;
    sp->idxsize = 256;
    sp->indexes = indexes;
    return sp;
}

canonical_original_code:
struct lp_strpool *strpool_init() {
    char *pool;
    int *indexes;
    struct lp_strpool *sp;
    pool = (char *)malloc(4096);
    if (pool == ((void *)0)) {
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    indexes = (int *)malloc(256 * sizeof(int));
    if (indexes == ((void *)0)) {
        free(pool);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp = (struct lp_strpool *)malloc(sizeof(lp_strpool));
    if (sp == ((void *)0)) {
        free(pool);
        free(indexes);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp->charcount = 0;
    sp->charsize = 4096;
    sp->pool = pool;
    sp->idxcount = 0;
    sp->idxsize = 256;
    sp->indexes = indexes;
    return sp;
}

return_type: struct lp_strpool { int charcount; int charsize; char *pool; int idxcount; int idxsize; int *indexes; } *


decompiled_code:
void __fastcall strpool_destroy(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void strpool_destroy(lp_strpool* sp) {
    if (sp == ((void *)0))
        return;
    free(sp->indexes);
    free(sp->pool);
    free(sp);
}

canonical_original_code:
void strpool_destroy(struct lp_strpool *sp) {
    if (sp == ((void *)0))
        return;
    free(sp->indexes);
    free(sp->pool);
    free(sp);
}

user_defined_types: struct lp_strpool { int charcount; int charsize; char *pool; int idxcount; int idxsize; int *indexes; }


original_code:
int strpool_add(lp_strpool *sp, const char* str) {
    int len;
    int pos;
    int idxpos;
    int newcharcount;
    int newidxcount;
    ((void) sizeof ((sp != ((void *)0)) ? 1 : 0), __extension__ ({ if (sp != ((void *)0)) ; else __assert_fail ("sp != NULL", "strpool.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "strpool.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    pos = search(sp, str);
    if (pos >= 0) {
        return pos;
    }
    idxpos = -(pos + 1);
    len = strlen(str);
    pos = sp->charcount;
    newcharcount = pos + len + 1;
    if (newcharcount >= sp->charsize) {
        int newsize = newcharcount * 2;
        char *pool = (char*)realloc(sp->pool, newsize);
        if (pool == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->pool = pool;
        sp->charsize = newsize;
    }
    newidxcount = sp->idxcount + 1;
    if (newidxcount >= sp->idxsize) {
        int newsize = newidxcount * 2;
        int *indexes = (int*)realloc(sp->indexes, newsize*sizeof(int));
        if (indexes == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->indexes = indexes;
        sp->idxsize = newsize;
    }
    strcpy(sp->pool + sp->charcount, str);
    sp->charcount = newcharcount;
    if (idxpos < sp->idxcount) {
        memmove((void*)(sp->indexes+idxpos+1), (void*)(sp->indexes+idxpos), sizeof(int));
    }
    sp->indexes[idxpos] = pos;
    sp->idxcount = newidxcount;
    return pos;
}

canonical_original_code:
int strpool_add(struct lp_strpool *sp, char *str) {
    int len;
    int pos;
    int idxpos;
    int newcharcount;
    int newidxcount;
    ((void) sizeof ((sp != ((void *)0)) ? 1 : 0), __extension__ ({ if (sp != ((void *)0)) ; else __assert_fail ("sp != NULL", "strpool.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "strpool.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    pos = search(sp, str);
    if (pos >= 0) {
        return pos;
    }
    idxpos = -(pos + 1);
    len = strlen(str);
    pos = sp->charcount;
    newcharcount = pos + len + 1;
    if (newcharcount >= sp->charsize) {
        int newsize = newcharcount * 2;
        char *pool = (char*)realloc(sp->pool, newsize);
        if (pool == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->pool = pool;
        sp->charsize = newsize;
    }
    newidxcount = sp->idxcount + 1;
    if (newidxcount >= sp->idxsize) {
        int newsize = newidxcount * 2;
        int *indexes = (int*)realloc(sp->indexes, newsize*sizeof(int));
        if (indexes == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->indexes = indexes;
        sp->idxsize = newsize;
    }
    strcpy(sp->pool + sp->charcount, str);
    sp->charcount = newcharcount;
    if (idxpos < sp->idxcount) {
        memmove((void *)(sp->indexes+idxpos+1), (void *)(sp->indexes+idxpos), sizeof(int));
    }
    sp->indexes[idxpos] = pos;
    sp->idxcount = newidxcount;
    return pos;
}

variable_types: len int

variable_types: pos int

variable_types: idxpos int

variable_types: newcharcount int

variable_types: newidxcount int

variable_types: newsize int


decompiled_code:
int __fastcall strpool_print(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
const char *v4; // rdi

result = *(_DWORD *)(a1 + 16);
if ( result > 0 )
{
v3 = 0LL;
do
{
v4 = (const char *)(*(_QWORD *)(a1 + 8) + *(int *)(*(_QWORD *)(a1 + 24) + 4 * v3++));
result = puts(v4);
}
while ( *(_DWORD *)(a1 + 16) > (int)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
const char *v4; // rdi

result = *(_DWORD *)(a1 + 16);
if ( result > 0 )
{
v3 = 0LL;
do
{
v4 = (const char *)(*(_QWORD *)(a1 + 8) + *(int *)(*(_QWORD *)(a1 + 24) + 4 * v3++));
result = puts(v4);
}
while ( *(_DWORD *)(a1 + 16) > (int)v3 );
}
return result;
}

original_code:
void strpool_print(lp_strpool *sp) {
    int i;
    for (i=0; i<sp->idxcount; i++) {
        printf("%s\n", sp->pool + sp->indexes[i]);
    }
}

canonical_original_code:
void strpool_print(struct lp_strpool *sp) {
    int i;
    for (i=0; i<sp->idxcount; i++) {
        printf("%s\n", sp->pool + sp->indexes[i]);
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbp
unsigned int v4; // eax

v3 = (int *)strpool_init();
strpool_add(v3, "cadsfeasfd");
strpool_add(v3, "afsadf");
strpool_add(v3, "f1111");
strpool_add(v3, "dr222");
strpool_add(v3, "iddd");
strpool_add(v3, "eaa");
v4 = search((__int64)v3, argv[1]);
printf("%d\n", v4);
strpool_print((__int64)v3);
strpool_destroy(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbp
unsigned int v4; // eax

v3 = (int *)func1();
func3(v3, "cadsfeasfd");
func3(v3, "afsadf");
func3(v3, "f1111");
func3(v3, "dr222");
func3(v3, "iddd");
func3(v3, "eaa");
v4 = func0((__int64)v3, argv[1]);
printf("%d\n", v4);
func4((__int64)v3);
func2(v3);
return 0;
}

original_code:
int main(int argc, char*argv[]) {
    lp_strpool *sp = strpool_init();
    strpool_add(sp, "cadsfeasfd");
    strpool_add(sp, "afsadf");
    strpool_add(sp, "f1111");
    strpool_add(sp, "dr222");
    strpool_add(sp, "iddd");
    strpool_add(sp, "eaa");
    printf("%d\n", search(sp, argv[1]));
    strpool_print(sp);
    strpool_destroy(sp);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct lp_strpool *sp = strpool_init();
    strpool_add(sp, "cadsfeasfd");
    strpool_add(sp, "afsadf");
    strpool_add(sp, "f1111");
    strpool_add(sp, "dr222");
    strpool_add(sp, "iddd");
    strpool_add(sp, "eaa");
    printf("%d\n", search(sp, argv[1]));
    strpool_print(sp);
    strpool_destroy(sp);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
char *init_item()
{
char *v0; // rax
char *v1; // r12
void *v2; // rax
char *result; // rax

v0 = (char *)calloc(1uLL, 0x58uLL);
if ( !v0 || (v1 = v0, v2 = calloc(0x14uLL, 1uLL), (*((_QWORD *)v1 + 5) = v2) == 0LL) )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
*((_QWORD *)v1 + 5) = 0LL;
*((_QWORD *)v1 + 6) = 0LL;
sem_init((sem_t *)(v1 + 56), 0, 0);
result = v1;
*((_DWORD *)v1 + 4) = -1;
return result;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rax
char *v1; // r12
void *v2; // rax
char *result; // rax

v0 = (char *)calloc(1uLL, 0x58uLL);
if ( !v0 || (v1 = v0, v2 = calloc(0x14uLL, 1uLL), (*((_QWORD *)v1 + 5) = v2) == 0LL) )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
*((_QWORD *)v1 + 5) = 0LL;
*((_QWORD *)v1 + 6) = 0LL;
sem_init((sem_t *)(v1 + 56), 0, 0);
result = v1;
*((_DWORD *)v1 + 4) = -1;
return result;
}

original_code:
item* init_item()
{
    item* i = ((void *)0);
    i = calloc(1, sizeof(item));
    if(i==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = calloc(20, sizeof(char));
    if(i->value==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = ((void *)0);
    i->pair = ((void *)0);
    sem_init(&(i->waiting), 0, 0);
    i->file_position = -1;
    return i;
}

canonical_original_code:
struct _item *init_item()
{
    struct _item *i = ((void *)0);
    i = calloc(1, sizeof(item));
    if(i==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = calloc(20, sizeof(char));
    if(i->value==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = ((void *)0);
    i->pair = ((void *)0);
    sem_init(&(i->waiting), 0, 0);
    i->file_position = -1;
    return i;
}

variable_types: struct _item { int clientID; int shardID; int dimension; int op; int file_position; char key[20]; char *value; struct KV_t { char key[20]; char value[20]; } *pair; union sem_t { char __size[32]; long __align; } waiting; } *

user_defined_types: struct _item { int clientID; int shardID; int dimension; int op; int file_position; char key[20]; char *value; struct KV_t *pair; union sem_t waiting; }


decompiled_code:
void __fastcall destroy_item(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
sem_destroy((sem_t *)((char *)ptr + 56));
v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
sem_destroy((sem_t *)((char *)ptr + 56));
v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void destroy_item(item *i)
{
    if(i != ((void *)0)){
        sem_destroy(&(i->waiting));
        if(i->pair != ((void *)0)){
            free(i->pair);
        }
        if(i->value != ((void *)0)){
            free(i->value);
        }
        free(i);
    }
}

canonical_original_code:
void destroy_item(struct _item *i)
{
    if(i != ((void *)0)){
        sem_destroy(&(i->waiting));
        if(i->pair != ((void *)0)){
            free(i->pair);
        }
        if(i->value != ((void *)0)){
            free(i->value);
        }
        free(i);
    }
}

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct KV_t { char key[20]; char value[20]; }


decompiled_code:
void __fastcall destroy_buffer(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
free(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
free(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(ptr);
}

original_code:
void destroy_buffer(buffer *b)
{
    int ix;
    for(ix = 0; ix < b->size; ix += 1) {
        free(b->items[ix]);
    }
    free(b);
}

canonical_original_code:
void destroy_buffer(struct _buffer *b)
{
    int ix;
    for(ix = 0; ix < b->size; ix += 1) {
        free(b->items[ix]);
    }
    free(b);
}

variable_types: struct _buffer { int size; struct _item { int clientID; int shardID; int dimension; int op; int file_position; char key[20]; char *value; struct KV_t { char key[20]; char value[20]; } *pair; union sem_t { char __size[32]; long __align; } waiting; } **items; } *

variable_types: ix int

user_defined_types: struct _buffer { int size; struct _item **items; }