main

original_code:
int main (int argc, char **argv) {
  json_parser p;
  test_json_content(json1, strlen(json1), 0);
  test_json_content(json2, strlen(json2), 0);
  test_json_content(json3, strlen(json3), 0);
  test_json_content(json4, 99, 1);
  printf ("Size of json_parser: %u\n", sizeof(json_parser));
}

canonical_original_code:
int main(int argc, char **argv) {
  struct json_parser p;
  test_json_content(json1, strlen(json1), 0);
  test_json_content(json2, strlen(json2), 0);
  test_json_content(json3, strlen(json3), 0);
  test_json_content(json4, 99, 1);
  printf ("Size of json_parser: %u\n", sizeof(json_parser));
}

variable_types: argc int

variable_types:
argv
char **

user_defined_types: struct json_parser { unsigned short state; unsigned long stack_size; unsigned long nread; unsigned short stop_on_callback; unsigned short error; void *data; char *data_mark; unsigned long data_size; int (*on_array_begin)(struct json_parser *); int (*on_object_begin)(struct json_parser *); int (*on_string)(struct json_parser *, char *at, unsigned long length); int (*on_end)(struct json_parser *); int (*on_separator)(struct json_parser *); int (*on_minus)(struct json_parser *); int (*on_int)(struct json_parser *, char *at, unsigned long length); int (*on_frac)(struct json_parser *, char *at, unsigned long length); int (*on_exp)(struct json_parser *, char *at, unsigned long length); unsigned char stack[-1]; }


die

decompiled_code:
__int64 die()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 0LL;
}

original_code:
_Bool die ()
{
    return 0;
}

canonical_original_code:
_Bool die()
{
    return 0;
}


live

decompiled_code:
__int64 live()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 1LL;
}

original_code:
_Bool live ()
{
    return 1;
}

canonical_original_code:
_Bool live()
{
    return 1;
}


four

decompiled_code:
__int64 four()
{
return live();
}

canonical_decompiled_code:
__int64 func8()
{
return func7();
}

original_code:
_Bool four ()
{
    domorestuff();
    return live();
}

canonical_original_code:
_Bool four()
{
    domorestuff();
    return live();
}


three

decompiled_code:
__int64 three()
{
return four();
}

canonical_decompiled_code:
__int64 func9()
{
return func8();
}

original_code:
_Bool three ()
{
    domorestuff();
    return four();
}

canonical_original_code:
_Bool three()
{
    domorestuff();
    return four();
}


two

decompiled_code:
__int64 two()
{
int v0; // ebx

v0 = three();
return v0 | (unsigned int)four();
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx

v0 = func9();
return v0 | (unsigned int)func8();
}

original_code:
_Bool two ()
{
    domorestuff();
    return three() | four();
}

canonical_original_code:
_Bool two()
{
    domorestuff();
    return three() | four();
}


one

decompiled_code:
__int64 one()
{
int v0; // ebx
int v1; // ebx

v0 = two();
v1 = three() | v0;
return v1 | (unsigned int)four();
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
int v1; // ebx

v0 = func10();
v1 = func9() | v0;
return v1 | (unsigned int)func8();
}

original_code:
_Bool one ()
{
    domorestuff();
    return two() | three() | four();
}

canonical_original_code:
_Bool one()
{
    domorestuff();
    return two() | three() | four();
}


domorestuff

decompiled_code:
void domorestuff()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void domorestuff() {
    strcmp("", "");
    strcoll("","");
    strncmp("", "", 0);
}

return_type: void


dostuff

decompiled_code:
void dostuff()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void dostuff ()
{
    if(one() | two() | three() | four())
        domorestuff();
}

canonical_original_code:
void dostuff()
{
    if(one() | two() | three() | four())
        domorestuff();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return 0;
}

original_code:
int main ()
{
   dostuff();
   return 0;
}

canonical_original_code:
int main()
{
   dostuff();
   return 0;
}

return_type: int


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

result = (unsigned int)(counter10 + 1);
counter10 = result;
if ( (_DWORD)result == 1 )
result = function1();
if ( counter10 == 2 )
result = function2();
if ( counter10 == 3 )
result = function3();
if ( counter10 == 4 )
result = function4();
if ( counter10 == 5 )
result = function5();
if ( counter10 == 6 )
result = function6();
if ( counter10 == 7 )
result = function7();
if ( counter10 == 8 )
result = function8();
if ( counter10 == 9 )
result = function9();
if ( counter10 == 10 )
result = function10();
return result;
}

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

result = (unsigned int)(counter10 + 1);
counter10 = result;
if ( (_DWORD)result == 1 )
result = func15();
if ( counter10 == 2 )
result = func14();
if ( counter10 == 3 )
result = func13();
if ( counter10 == 4 )
result = func12();
if ( counter10 == 5 )
result = func11();
if ( counter10 == 6 )
result = func10();
if ( counter10 == 7 )
result = func9();
if ( counter10 == 8 )
result = func7();
if ( counter10 == 9 )
result = func8();
if ( counter10 == 10 )
result = func6();
return result;
}

original_code:
void function10()
{
    counter10++;
    if(counter10 == 1)
        function1();
    if(counter10 == 2)
        function2();
    if(counter10 == 3)
        function3();
    if(counter10 == 4)
        function4();
    if(counter10 == 5)
        function5();
    if(counter10 == 6)
        function6();
    if(counter10 == 7)
        function7();
    if(counter10 == 8)
        function8();
    if(counter10 == 9)
        function9();
    if(counter10 == 10)
        function10();
}


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

result = (unsigned int)(counter8 + 1);
counter8 = result;
if ( (_DWORD)result == 1 )
result = function9();
if ( counter8 == 2 )
result = function10();
if ( counter8 == 3 )
result = function1();
if ( counter8 == 4 )
result = function2();
if ( counter8 == 5 )
result = function3();
if ( counter8 == 6 )
result = function4();
if ( counter8 == 7 )
result = function5();
if ( counter8 == 8 )
result = function6();
if ( counter8 == 9 )
result = function7();
if ( counter8 == 10 )
result = function8();
return result;
}

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

result = (unsigned int)(counter8 + 1);
counter8 = result;
if ( (_DWORD)result == 1 )
result = func8();
if ( counter8 == 2 )
result = func6();
if ( counter8 == 3 )
result = func15();
if ( counter8 == 4 )
result = func14();
if ( counter8 == 5 )
result = func13();
if ( counter8 == 6 )
result = func12();
if ( counter8 == 7 )
result = func11();
if ( counter8 == 8 )
result = func10();
if ( counter8 == 9 )
result = func9();
if ( counter8 == 10 )
result = func7();
return result;
}

original_code:
void function8()
{
    counter8++;
    if(counter8 == 1)
        function9();
    if(counter8 == 2)
        function10();
    if(counter8 == 3)
        function1();
    if(counter8 == 4)
        function2();
    if(counter8 == 5)
        function3();
    if(counter8 == 6)
        function4();
    if(counter8 == 7)
        function5();
    if(counter8 == 8)
        function6();
    if(counter8 == 9)
        function7();
    if(counter8 == 10)
        function8();
}


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

result = (unsigned int)(counter9 + 1);
counter9 = result;
if ( (_DWORD)result == 1 )
result = function1();
if ( counter9 == 2 )
result = function2();
if ( counter9 == 3 )
result = function3();
if ( counter9 == 4 )
result = function4();
if ( counter9 == 5 )
result = function5();
if ( counter9 == 6 )
result = function6();
if ( counter9 == 7 )
result = function7();
if ( counter9 == 8 )
result = function8();
if ( counter9 == 9 )
result = function9();
return result;
}

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

result = (unsigned int)(counter9 + 1);
counter9 = result;
if ( (_DWORD)result == 1 )
result = func15();
if ( counter9 == 2 )
result = func14();
if ( counter9 == 3 )
result = func13();
if ( counter9 == 4 )
result = func12();
if ( counter9 == 5 )
result = func11();
if ( counter9 == 6 )
result = func10();
if ( counter9 == 7 )
result = func9();
if ( counter9 == 8 )
result = func7();
if ( counter9 == 9 )
result = func8();
return result;
}

original_code:
void function9()
{
    counter9++;
    if(counter9 == 1)
        function1();
    if(counter9 == 2)
        function2();
    if(counter9 == 3)
        function3();
    if(counter9 == 4)
        function4();
    if(counter9 == 5)
        function5();
    if(counter9 == 6)
        function6();
    if(counter9 == 7)
        function7();
    if(counter9 == 8)
        function8();
    if(counter9 == 9)
        function9();
}


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

result = (unsigned int)(counter7 + 1);
counter7 = result;
if ( (_DWORD)result == 1 )
result = function8();
if ( counter7 == 2 )
result = function9();
if ( counter7 == 3 )
result = function10();
if ( counter7 == 4 )
result = function1();
if ( counter7 == 5 )
result = function2();
if ( counter7 == 6 )
result = function3();
if ( counter7 == 7 )
result = function4();
if ( counter7 == 8 )
result = function5();
if ( counter7 == 9 )
result = function6();
if ( counter7 == 10 )
result = function7();
return result;
}

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

result = (unsigned int)(counter7 + 1);
counter7 = result;
if ( (_DWORD)result == 1 )
result = func7();
if ( counter7 == 2 )
result = func8();
if ( counter7 == 3 )
result = func6();
if ( counter7 == 4 )
result = func15();
if ( counter7 == 5 )
result = func14();
if ( counter7 == 6 )
result = func13();
if ( counter7 == 7 )
result = func12();
if ( counter7 == 8 )
result = func11();
if ( counter7 == 9 )
result = func10();
if ( counter7 == 10 )
result = func9();
return result;
}

original_code:
void function7()
{
    counter7++;
    if(counter7 == 1)
        function8();
    if(counter7 == 2)
        function9();
    if(counter7 == 3)
        function10();
    if(counter7 == 4)
        function1();
    if(counter7 == 5)
        function2();
    if(counter7 == 6)
        function3();
    if(counter7 == 7)
        function4();
    if(counter7 == 8)
        function5();
    if(counter7 == 9)
        function6();
    if(counter7 == 10)
        function7();
}


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

result = (unsigned int)(counter6 + 1);
counter6 = result;
if ( (_DWORD)result == 1 )
result = function7();
if ( counter6 == 2 )
result = function8();
if ( counter6 == 3 )
result = function9();
if ( counter6 == 4 )
result = function10();
if ( counter6 == 5 )
result = function1();
if ( counter6 == 6 )
result = function2();
if ( counter6 == 7 )
result = function3();
if ( counter6 == 8 )
result = function4();
if ( counter6 == 9 )
result = function5();
if ( counter6 == 10 )
result = function6();
return result;
}

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

result = (unsigned int)(counter6 + 1);
counter6 = result;
if ( (_DWORD)result == 1 )
result = func9();
if ( counter6 == 2 )
result = func7();
if ( counter6 == 3 )
result = func8();
if ( counter6 == 4 )
result = func6();
if ( counter6 == 5 )
result = func15();
if ( counter6 == 6 )
result = func14();
if ( counter6 == 7 )
result = func13();
if ( counter6 == 8 )
result = func12();
if ( counter6 == 9 )
result = func11();
if ( counter6 == 10 )
result = func10();
return result;
}

original_code:
void function6()
{
    counter6++;
    if(counter6 == 1)
        function7();
    if(counter6 == 2)
        function8();
    if(counter6 == 3)
        function9();
    if(counter6 == 4)
        function10();
    if(counter6 == 5)
        function1();
    if(counter6 == 6)
        function2();
    if(counter6 == 7)
        function3();
    if(counter6 == 8)
        function4();
    if(counter6 == 9)
        function5();
    if(counter6 == 10)
        function6();
}


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

result = (unsigned int)(counter5 + 1);
counter5 = result;
if ( (_DWORD)result == 1 )
result = function6();
if ( counter5 == 2 )
result = function7();
if ( counter5 == 3 )
result = function8();
if ( counter5 == 4 )
result = function9();
if ( counter5 == 5 )
result = function10();
if ( counter5 == 6 )
result = function1();
if ( counter5 == 7 )
result = function2();
if ( counter5 == 8 )
result = function3();
if ( counter5 == 9 )
result = function4();
if ( counter5 == 10 )
result = function5();
return result;
}

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

result = (unsigned int)(counter5 + 1);
counter5 = result;
if ( (_DWORD)result == 1 )
result = func10();
if ( counter5 == 2 )
result = func9();
if ( counter5 == 3 )
result = func7();
if ( counter5 == 4 )
result = func8();
if ( counter5 == 5 )
result = func6();
if ( counter5 == 6 )
result = func15();
if ( counter5 == 7 )
result = func14();
if ( counter5 == 8 )
result = func13();
if ( counter5 == 9 )
result = func12();
if ( counter5 == 10 )
result = func11();
return result;
}

original_code:
void function5()
{
    counter5++;
    if(counter5 == 1)
        function6();
    if(counter5 == 2)
        function7();
    if(counter5 == 3)
        function8();
    if(counter5 == 4)
        function9();
    if(counter5 == 5)
        function10();
    if(counter5 == 6)
        function1();
    if(counter5 == 7)
        function2();
    if(counter5 == 8)
        function3();
    if(counter5 == 9)
        function4();
    if(counter5 == 10)
        function5();
}


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

result = (unsigned int)(counter4 + 1);
counter4 = result;
if ( (_DWORD)result == 1 )
result = function5();
if ( counter4 == 2 )
result = function6();
if ( counter4 == 3 )
result = function7();
if ( counter4 == 4 )
result = function8();
if ( counter4 == 5 )
result = function9();
if ( counter4 == 6 )
result = function10();
if ( counter4 == 7 )
result = function1();
if ( counter4 == 8 )
result = function2();
if ( counter4 == 9 )
result = function3();
if ( counter4 == 10 )
result = function4();
return result;
}

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

result = (unsigned int)(counter4 + 1);
counter4 = result;
if ( (_DWORD)result == 1 )
result = func11();
if ( counter4 == 2 )
result = func10();
if ( counter4 == 3 )
result = func9();
if ( counter4 == 4 )
result = func7();
if ( counter4 == 5 )
result = func8();
if ( counter4 == 6 )
result = func6();
if ( counter4 == 7 )
result = func15();
if ( counter4 == 8 )
result = func14();
if ( counter4 == 9 )
result = func13();
if ( counter4 == 10 )
result = func12();
return result;
}

original_code:
void function4()
{
    counter4++;
    if(counter4 == 1)
        function5();
    if(counter4 == 2)
        function6();
    if(counter4 == 3)
        function7();
    if(counter4 == 4)
        function8();
    if(counter4 == 5)
        function9();
    if(counter4 == 6)
        function10();
    if(counter4 == 7)
        function1();
    if(counter4 == 8)
        function2();
    if(counter4 == 9)
        function3();
    if(counter4 == 10)
        function4();
}


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

result = (unsigned int)(counter3 + 1);
counter3 = result;
if ( (_DWORD)result == 1 )
result = function4();
if ( counter3 == 2 )
result = function5();
if ( counter3 == 3 )
result = function6();
if ( counter3 == 4 )
result = function7();
if ( counter3 == 5 )
result = function8();
if ( counter3 == 6 )
result = function9();
if ( counter3 == 7 )
result = function10();
if ( counter3 == 8 )
result = function1();
if ( counter3 == 9 )
result = function2();
if ( counter3 == 10 )
result = function3();
return result;
}

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

result = (unsigned int)(counter3 + 1);
counter3 = result;
if ( (_DWORD)result == 1 )
result = func12();
if ( counter3 == 2 )
result = func11();
if ( counter3 == 3 )
result = func10();
if ( counter3 == 4 )
result = func9();
if ( counter3 == 5 )
result = func7();
if ( counter3 == 6 )
result = func8();
if ( counter3 == 7 )
result = func6();
if ( counter3 == 8 )
result = func15();
if ( counter3 == 9 )
result = func14();
if ( counter3 == 10 )
result = func13();
return result;
}

original_code:
void function3()
{
    counter3++;
    if(counter3 == 1)
        function4();
    if(counter3 == 2)
        function5();
    if(counter3 == 3)
        function6();
    if(counter3 == 4)
        function7();
    if(counter3 == 5)
        function8();
    if(counter3 == 6)
        function9();
    if(counter3 == 7)
        function10();
    if(counter3 == 8)
        function1();
    if(counter3 == 9)
        function2();
    if(counter3 == 10)
        function3();
}


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

result = (unsigned int)(counter2 + 1);
counter2 = result;
if ( (_DWORD)result == 1 )
result = function3();
if ( counter2 == 2 )
result = function4();
if ( counter2 == 3 )
result = function5();
if ( counter2 == 4 )
result = function6();
if ( counter2 == 5 )
result = function7();
if ( counter2 == 6 )
result = function8();
if ( counter2 == 7 )
result = function9();
if ( counter2 == 8 )
result = function10();
if ( counter2 == 9 )
result = function1();
if ( counter2 == 10 )
result = function2();
return result;
}

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

result = (unsigned int)(counter2 + 1);
counter2 = result;
if ( (_DWORD)result == 1 )
result = func13();
if ( counter2 == 2 )
result = func12();
if ( counter2 == 3 )
result = func11();
if ( counter2 == 4 )
result = func10();
if ( counter2 == 5 )
result = func9();
if ( counter2 == 6 )
result = func7();
if ( counter2 == 7 )
result = func8();
if ( counter2 == 8 )
result = func6();
if ( counter2 == 9 )
result = func15();
if ( counter2 == 10 )
result = func14();
return result;
}

original_code:
void function2()
{
    counter2++;
    if(counter2 == 1)
        function3();
    if(counter2 == 2)
        function4();
    if(counter2 == 3)
        function5();
    if(counter2 == 4)
        function6();
    if(counter2 == 5)
        function7();
    if(counter2 == 6)
        function8();
    if(counter2 == 7)
        function9();
    if(counter2 == 8)
        function10();
    if(counter2 == 9)
        function1();
    if(counter2 == 10)
        function2();
}


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

result = (unsigned int)(counter1 + 1);
counter1 = result;
if ( (_DWORD)result == 1 )
result = function2();
if ( counter1 == 2 )
result = function3();
if ( counter1 == 3 )
result = function4();
if ( counter1 == 4 )
result = function5();
if ( counter1 == 5 )
result = function6();
if ( counter1 == 6 )
result = function7();
if ( counter1 == 7 )
result = function8();
if ( counter1 == 8 )
result = function9();
if ( counter1 == 9 )
result = function10();
if ( counter1 == 10 )
result = function1();
return result;
}

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

result = (unsigned int)(counter1 + 1);
counter1 = result;
if ( (_DWORD)result == 1 )
result = func14();
if ( counter1 == 2 )
result = func13();
if ( counter1 == 3 )
result = func12();
if ( counter1 == 4 )
result = func11();
if ( counter1 == 5 )
result = func10();
if ( counter1 == 6 )
result = func9();
if ( counter1 == 7 )
result = func7();
if ( counter1 == 8 )
result = func8();
if ( counter1 == 9 )
result = func6();
if ( counter1 == 10 )
result = func15();
return result;
}

original_code:
void function1()
{
    counter1++;
    if(counter1 == 1)
        function2();
    if(counter1 == 2)
        function3();
    if(counter1 == 3)
        function4();
    if(counter1 == 4)
        function5();
    if(counter1 == 5)
        function6();
    if(counter1 == 6)
        function7();
    if(counter1 == 7)
        function8();
    if(counter1 == 8)
        function9();
    if(counter1 == 9)
        function10();
    if(counter1 == 10)
        function1();
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
function1();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func15();
return 0;
}

original_code:
int main ()
{
    function1();
    return 0;
}

canonical_original_code:
int main()
{
    function1();
    return 0;
}


decompiled_code:
_QWORD *make_string_array()
{
_QWORD *v0; // r12
_QWORD *v1; // rbx
_BYTE *v2; // rax
_BYTE *v3; // rcx
_BYTE *v4; // rdx

v0 = malloc(0x50uLL);
v1 = v0;
do
{
v2 = malloc(0xAuLL);
v3 = v2;
v4 = v2 + 10;
do
*v2++ = 88;
while ( v2 != v4 );
*v1++ = v3;
}
while ( v1 != v0 + 10 );
return v0;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // r12
_QWORD *v1; // rbx
_BYTE *v2; // rax
_BYTE *v3; // rcx
_BYTE *v4; // rdx

v0 = malloc(0x50uLL);
v1 = v0;
do
{
v2 = malloc(0xAuLL);
v3 = v2;
v4 = v2 + 10;
do
*v2++ = 88;
while ( v2 != v4 );
*v1++ = v3;
}
while ( v1 != v0 + 10 );
return v0;
}

original_code:
char** make_string_array ()
{
    char ** string_array = malloc(sizeof(char*)*10);
    int i = 0;
    for(;i < 10;i++) {
        char* str = (char*) malloc(10);
        int j = 0;
        for(;j < 10;j++) {
            *(str+j) = 'X';
        }
        *(string_array+i) = str;
    }
    return string_array;
}

canonical_original_code:
char **make_string_array()
{
    char **string_array = malloc(sizeof(char*)*10);
    int i = 0;
    for(;i < 10;i++) {
        char *str = (char*) malloc(10);
        int j = 0;
        for(;j < 10;j++) {
            *(str+j) = 'X';
        }
        *(string_array+i) = str;
    }
    return string_array;
}

variable_types: i int

variable_types:
str
char *

variable_types: j int

return_type: char **


decompiled_code:
int __fastcall print_string_array(const char **a1)
{
const char **v1; // rbx
int result; // eax

puts("Strings:");
v1 = a1;
do
result = printf("\t\"%s\"\n", *v1++);
while ( v1 != a1 + 10 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char **a1)
{
const char **v1; // rbx
int result; // eax

puts("Strings:");
v1 = a1;
do
result = printf("\t\"%s\"\n", *v1++);
while ( v1 != a1 + 10 );
return result;
}

original_code:
void print_string_array (char **arr)
{
    printf("Strings:\n");
    int i = 0;
    for(; i < 10; i++) {
        printf("\t\"%s\"\n", *(arr+i));
    }
}

canonical_original_code:
void print_string_array(char **arr)
{
    printf("Strings:\n");
    int i = 0;
    for(; i < 10; i++) {
        printf("\t\"%s\"\n", *(arr+i));
    }
}

variable_types:
arr
char **


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

v3 = (const char **)make_string_array();
print_string_array(v3);
return 0;
}

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

v3 = (const char **)func7();
func8(v3);
return 0;
}

original_code:
int main (int argc, char **argv)
{
    char **res = make_string_array();
    print_string_array(res);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char **res = make_string_array();
    print_string_array(res);
    return 0;
}

variable_types:
res
char **


decompiled_code:
void __fastcall __noreturn thread_1(void *a1)
{
unsigned int v1; // eax
int v2; // ebx
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v3, 0LL);
time_list[2 * (int)a1] = v3.tv_usec + 1000000 * v3.tv_sec;
v1 = getpid();
printf("Before Context Switch Time %llu, pid %d\n", v3.tv_usec + 1000000 * v3.tv_sec, v1);
v2 = 1000000;
do
{
sched_yield();
--v2;
}
while ( v2 );
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
unsigned int v1; // eax
int v2; // ebx
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v3, 0LL);
time_list[2 * (int)a1] = v3.tv_usec + 1000000 * v3.tv_sec;
v1 = getpid();
printf("Before Context Switch Time %llu, pid %d\n", v3.tv_usec + 1000000 * v3.tv_sec, v1);
v2 = 1000000;
do
{
sched_yield();
--v2;
}
while ( v2 );
pthread_exit(0LL);
}

original_code:
void *thread_1(void *arg)
{
 int i, th_num = (int)arg;
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 time_list[th_num][0] = tv.tv_usec+tv.tv_sec*1000000;
 printf("Before Context Switch Time %llu, pid %d\n", (tv.tv_usec+tv.tv_sec*1000000), getpid());
 for (i = 0; i < 1000000; i++) {
  sched_yield();
 }
 pthread_exit(0);
}

canonical_original_code:
void *thread_1(void *arg)
{
 int i; int th_num = (int)arg;
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 time_list[th_num][0] = tv.tv_usec+tv.tv_sec*1000000;
 printf("Before Context Switch Time %llu, pid %d\n", (tv.tv_usec+tv.tv_sec*1000000), getpid());
 for (i = 0; i < 1000000; i++) {
  sched_yield();
 }
 pthread_exit(0);
}

variable_types:
arg
void *

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: void *


decompiled_code:
void __fastcall __noreturn thread_2(void *a1)
{
int v1; // ebx
unsigned int v2; // eax
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

v1 = 1000000;
do
{
sched_yield();
--v1;
}
while ( v1 );
gettimeofday(&v3, 0LL);
qword_4040A8[2 * (int)a1] = v3.tv_usec + 1000000 * v3.tv_sec;
v2 = getpid();
printf("After Context Switch Time %llu, pid %d\n", v3.tv_usec + 1000000 * v3.tv_sec, v2);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
int v1; // ebx
unsigned int v2; // eax
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

v1 = 1000000;
do
{
sched_yield();
--v1;
}
while ( v1 );
gettimeofday(&v3, 0LL);
qword_4040A8[2 * (int)a1] = v3.tv_usec + 1000000 * v3.tv_sec;
v2 = getpid();
printf("After Context Switch Time %llu, pid %d\n", v3.tv_usec + 1000000 * v3.tv_sec, v2);
pthread_exit(0LL);
}

original_code:
void *thread_2(void *arg)
{
 int i, th_num = (int)arg;
 struct timeval tv;
 for (i = 0; i < 1000000; i++) {
  sched_yield();
 }
 gettimeofday(&tv, ((void *)0));
 time_list[th_num][1] = tv.tv_usec+tv.tv_sec*1000000;
 printf("After Context Switch Time %llu, pid %d\n", (tv.tv_usec+tv.tv_sec*1000000), getpid());
 pthread_exit(0);
}

canonical_original_code:
void *thread_2(void *arg)
{
 int i; int th_num = (int)arg;
 struct timeval tv;
 for (i = 0; i < 1000000; i++) {
  sched_yield();
 }
 gettimeofday(&tv, ((void *)0));
 time_list[th_num][1] = tv.tv_usec+tv.tv_sec*1000000;
 printf("After Context Switch Time %llu, pid %d\n", (tv.tv_usec+tv.tv_sec*1000000), getpid());
 pthread_exit(0);
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


rdtsc

decompiled_code:
__int64 rdtsc()
{
return (unsigned int)__rdtsc();
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)__rdtsc();
}

original_code:
long long rdtsc()
{
    __asm("rdtsc");
}

canonical_original_code:
long long rdtsc()
{
    __asm("rdtsc");
}

return_type: long long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int *v4; // rbx
int *v5; // rbp
pthread_t *v6; // rbx
pthread_t *v7; // r12
char *v8; // rbp
unsigned __int64 v9; // rbx
struct sched_param param; // [rsp+Ch] [rbp-3Ch] BYREF
struct timeval v12; // [rsp+10h] [rbp-38h] BYREF
struct timeval tv; // [rsp+20h] [rbp-28h] BYREF

param.__sched_priority = 0;
v3 = getpid();
sched_setscheduler(v3, 1, &param);
memset(fd_list, 0, 0x640uLL);
memset(p_list, 0, 0x640uLL);
v4 = fd_list;
v5 = p_list;
do
{
pipe(v4);
pipe(v5);
v4 += 2;
v5 += 2;
}
while ( v4 != (int *)&end );
gettimeofday(&tv, 0LL);
v6 = &th_list;
v7 = &th_list;
v8 = 0LL;
do
{
pthread_create(v7, 0LL, (void *(*)(void *))thread_1, v8);
pthread_create(v7 + 1, 0LL, (void *(*)(void *))thread_2, v8++);
v7 += 2;
}
while ( v8 != (char *)200 );
do
{
pthread_join(*v6, 0LL);
pthread_join(v6[1], 0LL);
v6 += 2;
}
while ( v6 != (pthread_t *)p_list );
gettimeofday(&v12, 0LL);
v9 = v12.tv_usec + 1000000 * v12.tv_sec - (tv.tv_usec + 1000000 * tv.tv_sec);
printf("total time %llu\n", v9);
printf("switch count:%llu\n", 400000000LL);
printf("thread switch time %llu\n", v9 / 0x17D78400);
return 0;
}

original_code:
int main()
{
 int i;
 unsigned long time_total;
 struct timeval tv_begin, tv_end;
 struct sched_param param;
 param.sched_priority = 0;
 sched_setscheduler(getpid(), 1, &param);
 memset(fd_list, '\0', 200*sizeof(int)*2);
 memset(p_list, '\0', 200*sizeof(int)*2);
 for (i=0; i<200; i++) {
  pipe(fd_list[i]);
  pipe(p_list[i]);
 }
 gettimeofday(&tv_begin, ((void *)0));
 for (i=0; i<200; i++) {
  pthread_create(&th_list[i][0], ((void *)0), thread_1, (void *)i);
  pthread_create(&th_list[i][1], ((void *)0), thread_2, (void *)i);
 }
 for (i=0; i<200; i++) {
  pthread_join(th_list[i][0], ((void *)0));
  pthread_join(th_list[i][1], ((void *)0));
 }
 gettimeofday(&tv_end, ((void *)0));
 time_total = (tv_end.tv_usec+tv_end.tv_sec*1000000) - (tv_begin.tv_usec+tv_begin.tv_sec*1000000);
 printf("total time %llu\n", time_total);
 printf("switch count:%llu\n", 200*1000000*2);
 printf("thread switch time %llu\n", time_total/(200*1000000*2));
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 unsigned long time_total;
 struct timeval tv_begin; struct timeval tv_end;
 struct sched_param param;
 param.sched_priority = 0;
 sched_setscheduler(getpid(), 1, &param);
 memset(fd_list, '\0', 200*sizeof(int)*2);
 memset(p_list, '\0', 200*sizeof(int)*2);
 for (i=0; i<200; i++) {
  pipe(fd_list[i]);
  pipe(p_list[i]);
 }
 gettimeofday(&tv_begin, ((void *)0));
 for (i=0; i<200; i++) {
  pthread_create(&th_list[i][0], ((void *)0), thread_1, (void *)i);
  pthread_create(&th_list[i][1], ((void *)0), thread_2, (void *)i);
 }
 for (i=0; i<200; i++) {
  pthread_join(th_list[i][0], ((void *)0));
  pthread_join(th_list[i][1], ((void *)0));
 }
 gettimeofday(&tv_end, ((void *)0));
 time_total = (tv_end.tv_usec+tv_end.tv_sec*1000000) - (tv_begin.tv_usec+tv_begin.tv_sec*1000000);
 printf("total time %llu\n", time_total);
 printf("switch count:%llu\n", 200*1000000*2);
 printf("thread switch time %llu\n", time_total/(200*1000000*2));
 return 0;
}

variable_types: struct sched_param { int sched_priority; }


decompiled_code:
int test_mremap()
{
unsigned int v0; // eax
void *v1; // rax
__int64 v2; // rbx
int result; // eax
int *v4; // rbx
char *v5; // rax

v0 = getpagesize();
printf("Page size:%d.\n", v0);
v1 = valloc(0x1000uLL);
if ( v1 )
{
v2 = (__int64)v1;
result = printf("valloc memory address:\t\t%p\n", v1);
valoc_mem = v2;
}
else
{
printf("Can not alloc memory from valloc.");
v4 = __errno_location();
v5 = strerror(*v4);
result = printf(" (%d:%s)\n", (unsigned int)*v4, v5);
}
return result;
}

canonical_decompiled_code:
int func7()
{
unsigned int v0; // eax
void *v1; // rax
__int64 v2; // rbx
int result; // eax
int *v4; // rbx
char *v5; // rax

v0 = getpagesize();
printf("Page size:%d.\n", v0);
v1 = valloc(0x1000uLL);
if ( v1 )
{
v2 = (__int64)v1;
result = printf("valloc memory address:\t\t%p\n", v1);
valoc_mem = v2;
}
else
{
printf("Can not alloc memory from valloc.");
v4 = __errno_location();
v5 = strerror(*v4);
result = printf(" (%d:%s)\n", (unsigned int)*v4, v5);
}
return result;
}

original_code:
void
test_mremap(void)
{
 int page_size;
 void *buf;
 void *buf_new;
 char *p;
 int i;
 page_size = getpagesize();
 printf("Page size:%d.\n", page_size);
 buf = valloc(4096);
 if(!buf) {
  do { printf("Can not alloc memory from valloc."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  goto failed;
 }
 printf("valloc memory address:\t\t%p\n", buf);
 valoc_mem = buf;
failed:
 return;
}

canonical_original_code:
void test_mremap()
{
 int page_size;
 void *buf;
 void *buf_new;
 char *p;
 int i;
 page_size = getpagesize();
 printf("Page size:%d.\n", page_size);
 buf = valloc(4096);
 if(!buf) {
  do { printf("Can not alloc memory from valloc."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  goto failed;
 }
 printf("valloc memory address:\t\t%p\n", buf);
 valoc_mem = buf;
failed:
 return;
}

variable_types:
buf
void *

variable_types:
p
char *


decompiled_code:
int test_brk()
{
char *v0; // rbx
char *v1; // rbx
unsigned int v2; // ebp
void *v3; // rax
int *v5; // rbx
char *v6; // rax

v0 = (char *)sbrk(0LL);
printf("Programe break address:\t\t%p\n", v0);
if ( valoc_mem >= (unsigned __int64)v0 )
printf("prot-break before valloc:%x\n", valoc_mem - (_QWORD)v0);
else
printf("prot-break after valloc:%x\n", &v0[-valoc_mem]);
v1 = v0 + 0x20000000;
v2 = 0x20000000;
while ( !brk(v1) )
{
printf("brked %dM memory.\n", v2 >> 20);
v2 += 0x20000000;
v1 += 0x20000000;
if ( v2 == -536870912 )
{
v3 = sbrk(0LL);
return printf("Programe break address after:\t%p\n", v3);
}
}
printf("Can not use brk to set programe break.");
v5 = __errno_location();
v6 = strerror(*v5);
return printf(" (%d:%s)\n", (unsigned int)*v5, v6);
}

canonical_decompiled_code:
int func8()
{
char *v0; // rbx
char *v1; // rbx
unsigned int v2; // ebp
void *v3; // rax
int *v5; // rbx
char *v6; // rax

v0 = (char *)sbrk(0LL);
printf("Programe break address:\t\t%p\n", v0);
if ( valoc_mem >= (unsigned __int64)v0 )
printf("prot-break before valloc:%x\n", valoc_mem - (_QWORD)v0);
else
printf("prot-break after valloc:%x\n", &v0[-valoc_mem]);
v1 = v0 + 0x20000000;
v2 = 0x20000000;
while ( !brk(v1) )
{
printf("brked %dM memory.\n", v2 >> 20);
v2 += 0x20000000;
v1 += 0x20000000;
if ( v2 == -536870912 )
{
v3 = sbrk(0LL);
return printf("Programe break address after:\t%p\n", v3);
}
}
printf("Can not use brk to set programe break.");
v5 = __errno_location();
v6 = strerror(*v5);
return printf(" (%d:%s)\n", (unsigned int)*v5, v6);
}

original_code:
void
test_brk(void)
{
 void *prog_break;
 unsigned int brk_len;
 int ret;
 int i;
 prog_break = sbrk(0);
 printf("Programe break address:\t\t%p\n", prog_break);
 if (prog_break > valoc_mem)
  printf("prot-break after valloc:%x\n", prog_break-valoc_mem);
 else
  printf("prot-break before valloc:%x\n", valoc_mem-prog_break);
 brk_len = 0x20000000;
 for (i=0; i<6; i++) {
  ret = brk(prog_break+brk_len);
  if(ret) {
   do { printf("Can not use brk to set programe break."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
   goto failed;
  }
  printf("brked %dM memory.\n", brk_len/1024/1024);
  brk_len += 0x20000000;
 }
 prog_break = sbrk(0);
 printf("Programe break address after:\t%p\n", prog_break);
failed:
 return;
}

canonical_original_code:
void test_brk()
{
 void *prog_break;
 unsigned int brk_len;
 int ret;
 int i;
 prog_break = sbrk(0);
 printf("Programe break address:\t\t%p\n", prog_break);
 if (prog_break > valoc_mem)
  printf("prot-break after valloc:%x\n", prog_break-valoc_mem);
 else
  printf("prot-break before valloc:%x\n", valoc_mem-prog_break);
 brk_len = 0x20000000;
 for (i=0; i<6; i++) {
  ret = brk(prog_break+brk_len);
  if(ret) {
   do { printf("Can not use brk to set programe break."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
   goto failed;
  }
  printf("brked %dM memory.\n", brk_len/1024/1024);
  brk_len += 0x20000000;
 }
 prog_break = sbrk(0);
 printf("Programe break address after:\t%p\n", prog_break);
failed:
 return;
}

variable_types: ret int


decompiled_code:
int test_malloc()
{
unsigned __int64 v0; // rbx
void *v1; // rax
int *v2; // rbx
char *v3; // rax

v0 = 0LL;
while ( 1 )
{
v1 = malloc(0x100000uLL);
if ( !v1 )
break;
qmemcpy(v1, "hellohello", 10);
v0 += 0x100000LL;
if ( v0 == 12582912 )
return (int)v1;
}
printf("Allocated %dM memory.", v0 >> 20);
printf("Can not malloc memory.");
v2 = __errno_location();
v3 = strerror(*v2);
LODWORD(v1) = printf(" (%d:%s)\n", (unsigned int)*v2, v3);
return (int)v1;
}

canonical_decompiled_code:
int func9()
{
unsigned __int64 v0; // rbx
void *v1; // rax
int *v2; // rbx
char *v3; // rax

v0 = 0LL;
while ( 1 )
{
v1 = malloc(0x100000uLL);
if ( !v1 )
break;
qmemcpy(v1, "hellohello", 10);
v0 += 0x100000LL;
if ( v0 == 12582912 )
return (int)v1;
}
printf("Allocated %dM memory.", v0 >> 20);
printf("Can not malloc memory.");
v2 = __errno_location();
v3 = strerror(*v2);
LODWORD(v1) = printf(" (%d:%s)\n", (unsigned int)*v2, v3);
return (int)v1;
}

original_code:
void
test_malloc(void)
{
 void *ptr;
 int i;
 size_t aloc_unit_size = 0x100000;
 size_t aloc_size = 0;
 for (i=0; i<12; i++) {
  ptr = malloc(aloc_unit_size);
  if (ptr == ((void *)0)) {
   printf("Allocated %dM memory.", aloc_size/1024/1024);
   do { printf("Can not malloc memory."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
   goto failed;
  }
  memcpy(ptr, "hellohello", 10);
  aloc_size += aloc_unit_size;
 }
failed:
 return;
}

canonical_original_code:
void test_malloc()
{
 void *ptr;
 int i;
 unsigned long aloc_unit_size = 0x100000;
 unsigned long aloc_size = 0;
 for (i=0; i<12; i++) {
  ptr = malloc(aloc_unit_size);
  if (ptr == ((void *)0)) {
   printf("Allocated %dM memory.", aloc_size/1024/1024);
   do { printf("Can not malloc memory."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
   goto failed;
  }
  memcpy(ptr, "hellohello", 10);
  aloc_size += aloc_unit_size;
 }
failed:
 return;
}

variable_types:
ptr
void *


decompiled_code:
int test_rlimit()
{
int *v1; // rbx
char *v2; // rax
struct rlimit v3; // [rsp+0h] [rbp-18h] BYREF

if ( !getrlimit(RLIMIT_DATA, &v3) )
return printf("Data segment size limit cur:%d, max:%d\n", v3.rlim_cur, v3.rlim_max);
printf("Get data segment size error.");
v1 = __errno_location();
v2 = strerror(*v1);
return printf(" (%d:%s)\n", (unsigned int)*v1, v2);
}

canonical_decompiled_code:
int func10()
{
int *v1; // rbx
char *v2; // rax
struct rlimit v3; // [rsp+0h] [rbp-18h] BYREF

if ( !getrlimit(RLIMIT_DATA, &v3) )
return printf("Data segment size limit cur:%d, max:%d\n", v3.rlim_cur, v3.rlim_max);
printf("Get data segment size error.");
v1 = __errno_location();
v2 = strerror(*v1);
return printf(" (%d:%s)\n", (unsigned int)*v1, v2);
}

original_code:
void
test_rlimit(void)
{
 struct rlimit lmt;
 if (getrlimit(RLIMIT_DATA, &lmt)) {
  do { printf("Get data segment size error."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  goto failed;
 }
 printf("Data segment size limit cur:%d, max:%d\n", lmt.rlim_cur, lmt.rlim_max);
failed:
 return;
}

canonical_original_code:
void test_rlimit()
{
 struct rlimit lmt;
 if (getrlimit(RLIMIT_DATA, &lmt)) {
  do { printf("Get data segment size error."); printf(" (%d:%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  goto failed;
 }
 printf("Data segment size limit cur:%d, max:%d\n", lmt.rlim_cur, lmt.rlim_max);
failed:
 return;
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_brk();
test_malloc();
test_rlimit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8();
func9();
func10();
return 0;
}

original_code:
int
main(int argc, char *args[])
{
 char s[10];
 test_brk();
 test_malloc();
 test_rlimit();
 return 0;
}

variable_types:
args
char *[]

variable_types:
s
char [10]


original_code:
static inline void bw_list_del(struct bw_list_head *entry)
{
 __bw_list_del(entry->prev, entry->next);
 entry->next = ((void *) 0x00100100);
 entry->prev = ((void *) 0x00200200);
}

variable_types: struct bw_list_head { struct bw_list_head *next; } *


decompiled_code:
_DWORD *bw_timer_create_queue()
{
char *v0; // rax
_DWORD *v1; // rbx
int *v3; // rbp
char *v4; // rax

v0 = (char *)calloc(1uLL, 0x80uLL);
v1 = v0;
if ( v0 )
{
*(_QWORD *)v0 = v0;
*((_QWORD *)v0 + 1) = v0;
*((_QWORD *)v0 + 2) = v0;
*((_DWORD *)v0 + 6) = 14;
*((_DWORD *)v0 + 7) = 2;
*((_QWORD *)v0 + 4) = _bw_timer_routine;
*((_QWORD *)v0 + 5) = 0LL;
if ( timer_create(0, (struct sigevent *)(v0 + 16), (timer_t *)v0 + 10) )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("BWTIMER: timer_create failed. %d(%s)\n", (unsigned int)*v3, v4);
free(v1);
v1 = 0LL;
}
else
{
v1[30] = 0;
}
}
else
{
puts("BWTIMER: Can not alloc mem for timer queue.");
}
return v1;
}

canonical_decompiled_code:
_DWORD *func12()
{
char *v0; // rax
_DWORD *v1; // rbx
int *v3; // rbp
char *v4; // rax

v0 = (char *)calloc(1uLL, 0x80uLL);
v1 = v0;
if ( v0 )
{
*(_QWORD *)v0 = v0;
*((_QWORD *)v0 + 1) = v0;
*((_QWORD *)v0 + 2) = v0;
*((_DWORD *)v0 + 6) = 14;
*((_DWORD *)v0 + 7) = 2;
*((_QWORD *)v0 + 4) = _bw_timer_routine;
*((_QWORD *)v0 + 5) = 0LL;
if ( timer_create(0, (struct sigevent *)(v0 + 16), (timer_t *)v0 + 10) )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("BWTIMER: timer_create failed. %d(%s)\n", (unsigned int)*v3, v4);
free(v1);
v1 = 0LL;
}
else
{
v1[30] = 0;
}
}
else
{
puts("BWTIMER: Can not alloc mem for timer queue.");
}
return v1;
}

original_code:
bw_timer_queue_t *bw_timer_create_queue(void)
{
 bw_timer_queue_t *queue = ((void *)0);
 int ret;
 queue = calloc(1, sizeof(bw_timer_queue_t));
 if (!queue) {
  printf("BWTIMER: Can not alloc mem for timer queue.\n");
  goto failed;
 }
 do { (&queue->tmq_list)->next = (&queue->tmq_list); (&queue->tmq_list)->prev = (&queue->tmq_list); } while (0);
 queue->tmq_sige.sigev_value.sival_ptr = queue;
 queue->tmq_sige.sigev_signo = 14;
 queue->tmq_sige.sigev_notify = SIGEV_THREAD;
 queue->tmq_sige._sigev_un._sigev_thread._function = __bw_timer_routine;
 queue->tmq_sige._sigev_un._sigev_thread._attribute = ((void *)0);
 ret = timer_create(0, &queue->tmq_sige, &queue->tmq_id);
 if (ret) {
  printf("BWTIMER: timer_create failed. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 queue->tmq_count = 0;
 return queue;
failed:
 if (queue)
  free(queue);
 return ((void *)0);
}

canonical_original_code:
struct _bw_timer_queue *bw_timer_create_queue()
{
 struct _bw_timer_queue *queue = ((void *)0);
 int ret;
 queue = calloc(1, sizeof(bw_timer_queue_t));
 if (!queue) {
  printf("BWTIMER: Can not alloc mem for timer queue.\n");
  goto failed;
 }
 do { (&queue->tmq_list)->next = (&queue->tmq_list); (&queue->tmq_list)->prev = (&queue->tmq_list); } while (0);
 queue->tmq_sige.sigev_value.sival_ptr = queue;
 queue->tmq_sige.sigev_signo = 14;
 queue->tmq_sige.sigev_notify = SIGEV_THREAD;
 queue->tmq_sige._sigev_un._sigev_thread._function = __bw_timer_routine;
 queue->tmq_sige._sigev_un._sigev_thread._attribute = ((void *)0);
 ret = timer_create(0, &queue->tmq_sige, &queue->tmq_id);
 if (ret) {
  printf("BWTIMER: timer_create failed. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 queue->tmq_count = 0;
 return queue;
failed:
 if (queue)
  free(queue);
 return ((void *)0);
}

variable_types: struct _bw_timer_queue { struct bw_list_head { struct bw_list_head *next; } tmq_list; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } tmq_sige; void *tmq_id; struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; } tmq_timeo; int tmq_count; } *

user_defined_types: struct _bw_timer_queue { struct bw_list_head tmq_list; struct sigevent tmq_sige; void *tmq_id; struct itimerspec tmq_timeo; int tmq_count; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }


decompiled_code:
__int64 __fastcall bw_timer_queue_timer(__int64 a1, __m128i *a2)
{
_bw_timer_timer_update_timeo(a2, 1);
_bw_timer_queue_insert(a1, a2);
if ( (unsigned int)_bw_timer_queue_update_timeo(a1) )
puts("BWTIMER: queue timer update timeo failed, ignore");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __m128i *a2)
{
func10(a2, 1);
func7(a1, a2);
if ( (unsigned int)func9(a1) )
puts("BWTIMER: queue timer update timeo failed, ignore");
return 0LL;
}

original_code:
int32_t bw_timer_queue_timer(bw_timer_queue_t *queue, bw_timer_timer_t *timer)
{
 int ret;
 __bw_timer_timer_update_timeo(timer, 1);
 __bw_timer_queue_insert(queue, timer);
 ret = __bw_timer_queue_update_timeo(queue);
 if (ret)
  printf("BWTIMER: queue timer update timeo failed, ignore\n");
 return 0;
}

canonical_original_code:
int bw_timer_queue_timer(struct _bw_timer_queue *queue, struct _bw_timer_timer *timer)
{
 int ret;
 __bw_timer_timer_update_timeo(timer, 1);
 __bw_timer_queue_insert(queue, timer);
 ret = __bw_timer_queue_update_timeo(queue);
 if (ret)
  printf("BWTIMER: queue timer update timeo failed, ignore\n");
 return 0;
}

variable_types: struct _bw_timer_timer { struct bw_list_head tm_node; int (*tm_handler)(void *); void *tm_args; struct timeval { long tv_sec; long tv_usec; } tm_begin; struct timeval tm_tick; struct timeval tm_timeo; } *

user_defined_types: struct _bw_timer_timer { struct bw_list_head tm_node; int (*tm_handler)(void *); void *tm_args; struct timeval tm_begin; struct timeval tm_tick; struct timeval tm_timeo; }

user_defined_types: struct bw_list_head { struct bw_list_head *next; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
__int64 __fastcall bw_timer_unqueue_timer(__int64 a1, __int64 a2)
{
_bw_timer_queue_delete(a1, a2);
if ( (unsigned int)_bw_timer_queue_update_timeo(a1) )
puts("BWTIMER: queue timer update timeo failed, ignore");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
func8(a1, a2);
if ( (unsigned int)func9(a1) )
puts("BWTIMER: queue timer update timeo failed, ignore");
return 0LL;
}

original_code:
int32_t bw_timer_unqueue_timer(bw_timer_queue_t *queue, bw_timer_timer_t *timer)
{
 int ret;
 __bw_timer_queue_delete(queue, timer);
 ret = __bw_timer_queue_update_timeo(queue);
 if (ret)
  printf("BWTIMER: queue timer update timeo failed, ignore\n");
 return 0;
}

canonical_original_code:
int bw_timer_unqueue_timer(struct _bw_timer_queue *queue, struct _bw_timer_timer *timer)
{
 int ret;
 __bw_timer_queue_delete(queue, timer);
 ret = __bw_timer_queue_update_timeo(queue);
 if (ret)
  printf("BWTIMER: queue timer update timeo failed, ignore\n");
 return 0;
}


decompiled_code:
int __fastcall task_start(__int64 a1)
{
return pthread_create((pthread_t *)a1, 0LL, *(void *(**)(void *))(a1 + 8), *(void **)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
return pthread_create((pthread_t *)a1, 0LL, *(void *(**)(void *))(a1 + 8), *(void **)(a1 + 24));
}

original_code:
int
task_start(struct task *t)
{
 return pthread_create(&t->tid, ((void *)0), t->rt, t->arg);
}

variable_types: struct task { unsigned long tid; void *(*rt)(void *t); int status; void *arg; void *ret; } *


decompiled_code:
int __fastcall task_stop(pthread_t *a1)
{
return pthread_kill(*a1, 15);
}

canonical_decompiled_code:
int __fastcall func1(pthread_t *a1)
{
return pthread_kill(*a1, 15);
}

original_code:
int
task_stop(struct task *t)
{
 return pthread_kill(t->tid, 15);
}

user_defined_types: struct task { unsigned long tid; void *(*rt)(void *t); int status; void *arg; void *ret; }


decompiled_code:
int __fastcall task_wait(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func2(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

original_code:
int
task_wait(struct task *t)
{
 return pthread_join(t->tid, ((void *)0));
}


decompiled_code:
__int64 task_timewait()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0xFFFFFFFFLL;
}

original_code:
int
task_timewait(struct task *t)
{
 return -1;
}


decompiled_code:
__int64 __fastcall uskb_header_cpy(__int64 a1, void *a2)
{
size_t v4; // rdx
const void *v5; // rsi

v4 = *(unsigned __int16 *)(a1 + 40);
if ( (*(_BYTE *)(a1 + 16) & 1) != 0 )
v5 = (const void *)(*(_QWORD *)(a1 + 24) + *(unsigned __int16 *)(a1 + 44) - v4);
else
v5 = *(const void **)(a1 + 24);
memcpy(a2, v5, v4);
return *(unsigned __int16 *)(a1 + 40);
}

original_code:
static inline int
uskb_header_cpy(struct usk_buff *uskb, void *buff)
{
 memcpy(buff, ((uskb)->direct ? ((uskb)->header)+(uskb)->header_max-(uskb)->header_len :(uskb)->header), uskb->header_len);
 return uskb->header_len;
}

variable_types: struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node { struct btqueue_node *next; } q_send; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct uprotocol { void (*close)(struct usock { int usk_mode; struct usk_buff_head { struct usk_buff *prev; struct usk_buff *next; unsigned short qlen; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } loc; } *usk_write_queue; struct usk_buff_head *usk_receive_queue; } *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head { struct list_head *next; } node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); } *proto; } *

variable_types:
buff
void *

user_defined_types: struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node q_send; struct sockaddr_in sin; struct uprotocol *proto; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct uprotocol { void (*close)(struct usock *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); }

user_defined_types: struct usock { int usk_mode; struct usk_buff_head *usk_write_queue; struct usk_buff_head *usk_receive_queue; }

user_defined_types: struct usk_buff_head { struct usk_buff *prev; struct usk_buff *next; unsigned short qlen; union pthread_mutex_t loc; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 usender_start()
{
__int64 v0; // rbx

v0 = task_create(usender);
task_start(v0);
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx

v0 = task_create(usender);
task_start(v0);
return v0;
}

original_code:
struct task *
usender_start(void)
{
 struct task *snd_task;
 snd_task = task_create(usender);
 task_start(snd_task);
 return snd_task;
}

canonical_original_code:
struct task *usender_start()
{
 struct task *snd_task;
 snd_task = task_create(usender);
 task_start(snd_task);
 return snd_task;
}

return_type: struct task { unsigned long tid; void *(*rt)(void *t); int status; void *arg; void *ret; } *


decompiled_code:
int usender_init()
{
atomic_init((__int64)&unk_2F8);
return pthread_mutex_init(&mutex, 0LL);
}

canonical_decompiled_code:
int func9()
{
func4((__int64)&unk_2F8);
return pthread_mutex_init(&mutex, 0LL);
}

original_code:
void
usender_init(void)
{
 do { atomic_init(&(&snd_queue)->len); pthread_mutex_init(&(&snd_queue)->loc, ((void *)0)); } while(0);
 snd_queue_max = 4096;
}

canonical_original_code:
void usender_init()
{
 do { atomic_init(&(&snd_queue)->len); pthread_mutex_init(&(&snd_queue)->loc, ((void *)0)); } while(0);
 snd_queue_max = 4096;
}


hello

decompiled_code:
void __fastcall __noreturn hello(void *a1)
{
int v1; // ebx
int i; // eax

printf("Num:%d decrease thread start\n", a1);
v1 = 50000;
while ( 1 )
{
pthread_mutex_lock(&data_loc);
for ( i = data; data <= 50; i = data )
pthread_cond_wait(&data_cond, &data_loc);
data = i - 1;
++op_count;
pthread_mutex_unlock(&data_loc);
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx
int i; // eax

printf("Num:%d decrease thread start\n", a1);
v1 = 50000;
while ( 1 )
{
pthread_mutex_lock(&data_loc);
for ( i = data; data <= 50; i = data )
pthread_cond_wait(&data_cond, &data_loc);
data = i - 1;
++op_count;
pthread_mutex_unlock(&data_loc);
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void *hello(void *threadid)
{
 long tid;
 int tmp;
 int i;
 tid = (long)threadid;
 printf("Num:%d decrease thread start\n", tid);
 for (i = 0; i<50000; i++) {
  pthread_mutex_lock(&data_loc);
  while (data <= 50) {
   pthread_cond_wait(&data_cond, &data_loc);
  }
  tmp = data;
  tmp -= 1;
  data = tmp;
  op_count++;
  pthread_mutex_unlock(&data_loc);
 }
 pthread_exit(((void *)0));
}

variable_types:
threadid
void *

variable_types: tid long

variable_types: tmp int

variable_types: i int


nihao

decompiled_code:
void __fastcall __noreturn nihao(void *a1)
{
int v1; // ebx

printf("Num:%d increase thread start\n", a1);
v1 = 50050;
while ( 1 )
{
pthread_mutex_lock(&data_loc);
++data;
++op_count;
if ( data > 50 )
pthread_cond_broadcast(&data_cond);
pthread_mutex_unlock(&data_loc);
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
int v1; // ebx

printf("Num:%d increase thread start\n", a1);
v1 = 50050;
while ( 1 )
{
pthread_mutex_lock(&data_loc);
++data;
++op_count;
if ( data > 50 )
pthread_cond_broadcast(&data_cond);
pthread_mutex_unlock(&data_loc);
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void *nihao(void *threadid)
{
 long tid;
 int tmp;
 int i;
 tid = (long)threadid;
 printf("Num:%d increase thread start\n", tid);
 for (i = 0; i<50050; i++) {
  pthread_mutex_lock(&data_loc);
  tmp = data;
  tmp += 1;
  data = tmp;
  op_count++;
  if (data > 50) {
   pthread_cond_broadcast(&data_cond);
  }
  pthread_mutex_unlock(&data_loc);
 }
 pthread_exit(((void *)0));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbp
void *v4; // rbx
unsigned int v5; // eax
unsigned int v6; // eax
__int64 i; // rbx
pthread_t th[50]; // [rsp+0h] [rbp-338h] BYREF
pthread_t newthread[53]; // [rsp+190h] [rbp-1A8h] BYREF

pthread_cond_init(&data_cond, 0LL);
pthread_mutex_init(&data_loc, 0LL);
data = 0;
op_count = 0;
v3 = newthread;
v4 = 0LL;
do
{
v5 = pthread_create(v3, 0LL, (void *(*)(void *))hello, v4);
if ( v5 )
{
printf("ERROR; return code from pthread_create() is %d\n", v5);
exit(-1);
}
v6 = pthread_create(&th[(_QWORD)v4], 0LL, (void *(*)(void *))nihao, v4);
if ( v6 )
{
printf("ERROR; return code from pthread_create() is %d\n", v6);
exit(-1);
}
v4 = (char *)v4 + 1;
++v3;
}
while ( v4 != (void *)50 );
for ( i = 0LL; i != 50; ++i )
{
pthread_join(newthread[i], 0LL);
pthread_join(th[i], 0LL);
}
printf("data is %d\n", (unsigned int)data);
return -1;
}

original_code:
int main (int argc, char *argv[])
{
 pthread_t th_inc_id[50];
 pthread_t th_dec_id[50];
 int ret;
 long i;
 pthread_cond_init(&data_cond, ((void *)0));
 pthread_mutex_init(&data_loc, ((void *)0));
 data = 0;
 op_count = 0;
 for(i=0; i<50; i++){
  ret = pthread_create(&th_inc_id[i], ((void *)0), hello, (void *)i);
  if (ret){
   printf("ERROR; return code from pthread_create() is %d\n", ret);
   exit(-1);
  }
  ret = pthread_create(&th_dec_id[i], ((void *)0), nihao, (void *)i);
  if (ret){
   printf("ERROR; return code from pthread_create() is %d\n", ret);
   exit(-1);
  }
 }
 for(i=0; i<50; i++){
  pthread_join(th_inc_id[i], ((void *)0));
  pthread_join(th_dec_id[i], ((void *)0));
 }
 printf("data is %d\n", data);
 return -1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long th_inc_id[50];
 unsigned long th_dec_id[50];
 int ret;
 long i;
 pthread_cond_init(&data_cond, ((void *)0));
 pthread_mutex_init(&data_loc, ((void *)0));
 data = 0;
 op_count = 0;
 for(i=0; i<50; i++){
  ret = pthread_create(&th_inc_id[i], ((void *)0), hello, (void *)i);
  if (ret){
   printf("ERROR; return code from pthread_create() is %d\n", ret);
   exit(-1);
  }
  ret = pthread_create(&th_dec_id[i], ((void *)0), nihao, (void *)i);
  if (ret){
   printf("ERROR; return code from pthread_create() is %d\n", ret);
   exit(-1);
  }
 }
 for(i=0; i<50; i++){
  pthread_join(th_inc_id[i], ((void *)0));
  pthread_join(th_dec_id[i], ((void *)0));
 }
 printf("data is %d\n", data);
 return -1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i long


decompiled_code:
__int64 __fastcall lock_unlock(const char *a1)
{
int v1; // eax
int v2; // er12
unsigned int v3; // ebx
int *v5; // rbx
char *v6; // rax
int *v7; // r13
char *v8; // rax
int *v9; // r13
char *v10; // rax

v1 = open(a1, 66, 436LL);
if ( v1 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("failed to open file %s, %d(%s)\n", a1, (unsigned int)*v5, v6);
v3 = -1;
}
else
{
v2 = v1;
printf("LOCK: begin. %s\n", a1);
v3 = flock(v2, 2);
if ( v3 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("failed to lock file %s, %d(%s)\n", a1, (unsigned int)*v7, v8);
}
else
{
printf("LOCK: end. %s\n", a1);
printf("SEELP: 30 sec. %s\n", a1);
sleep(0x1Eu);
printf("UNLOCK: begin. %s\n", a1);
v3 = flock(v2, 8);
if ( v3 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("failed to unlock file %s, %d(%s)\n", a1, (unsigned int)*v9, v10);
}
else
{
printf("UNLOCK: end. %s\n", a1);
v3 = 0;
}
}
close(v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v1; // eax
int v2; // er12
unsigned int v3; // ebx
int *v5; // rbx
char *v6; // rax
int *v7; // r13
char *v8; // rax
int *v9; // r13
char *v10; // rax

v1 = open(a1, 66, 436LL);
if ( v1 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("failed to open file %s, %d(%s)\n", a1, (unsigned int)*v5, v6);
v3 = -1;
}
else
{
v2 = v1;
printf("LOCK: begin. %s\n", a1);
v3 = flock(v2, 2);
if ( v3 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("failed to lock file %s, %d(%s)\n", a1, (unsigned int)*v7, v8);
}
else
{
printf("LOCK: end. %s\n", a1);
printf("SEELP: 30 sec. %s\n", a1);
sleep(0x1Eu);
printf("UNLOCK: begin. %s\n", a1);
v3 = flock(v2, 8);
if ( v3 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("failed to unlock file %s, %d(%s)\n", a1, (unsigned int)*v9, v10);
}
else
{
printf("UNLOCK: end. %s\n", a1);
v3 = 0;
}
}
close(v2);
}
return v3;
}

original_code:
int lock_unlock(char *filepath)
{
 int fd = -1, ret = -1;
 fd = open(filepath, (02|0100), 0664);
 if (fd < 0) {
  printf("failed to open file %s, %d(%s)\n",
   filepath, (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 printf("LOCK: begin.   %s\n", filepath);
 if (flock(fd, 2) == -1) {
  printf("failed to lock file %s, %d(%s)\n",
   filepath, (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 printf("LOCK: end.     %s\n", filepath);
 printf("SEELP: 30 sec. %s\n", filepath);
 sleep(30);
 printf("UNLOCK: begin. %s\n", filepath);
 if (flock(fd, 8) == -1) {
  printf("failed to unlock file %s, %d(%s)\n",
   filepath, (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 printf("UNLOCK: end.   %s\n", filepath);
 ret = 0;
out:
 if (fd >= 0)
  close(fd);
 return ret;
}

canonical_original_code:
int lock_unlock(char *filepath)
{
 int fd = -1; int ret = -1;
 fd = open(filepath, (02|0100), 0664);
 if (fd < 0) {
  printf("failed to open file %s, %d(%s)\n",
   filepath, (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 printf("LOCK: begin.   %s\n", filepath);
 if (flock(fd, 2) == -1) {
  printf("failed to lock file %s, %d(%s)\n",
   filepath, (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 printf("LOCK: end.     %s\n", filepath);
 printf("SEELP: 30 sec. %s\n", filepath);
 sleep(30);
 printf("UNLOCK: begin. %s\n", filepath);
 if (flock(fd, 8) == -1) {
  printf("failed to unlock file %s, %d(%s)\n",
   filepath, (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 printf("UNLOCK: end.   %s\n", filepath);
 ret = 0;
out:
 if (fd >= 0)
  close(fd);
 return ret;
}

variable_types:
filepath
char *

variable_types: fd int

variable_types: ret int


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
int v1; // ebp
__int64 v2; // rdx

*((_DWORD *)a1 + 4) = 0;
if ( *((int *)a1 + 3) <= 0 )
return 0LL;
v1 = 0;
while ( !(unsigned int)lock_unlock((const char *)a1 + 24) )
{
++*((_DWORD *)a1 + 5);
if ( *((_DWORD *)a1 + 3) <= ++v1 )
return 0LL;
}
v2 = (unsigned int)(*((_DWORD *)a1 + 4) + 1);
*((_DWORD *)a1 + 4) = v2;
printf("worker %d failed %d times\n", *((unsigned int *)a1 + 2), v2);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebp
__int64 v2; // rdx

*((_DWORD *)a1 + 4) = 0;
if ( *((int *)a1 + 3) <= 0 )
return 0LL;
v1 = 0;
while ( !(unsigned int)func7((const char *)a1 + 24) )
{
++*((_DWORD *)a1 + 5);
if ( *((_DWORD *)a1 + 3) <= ++v1 )
return 0LL;
}
v2 = (unsigned int)(*((_DWORD *)a1 + 4) + 1);
*((_DWORD *)a1 + 4) = v2;
printf("worker %d failed %d times\n", *((unsigned int *)a1 + 2), v2);
return 0LL;
}

original_code:
void *worker(void *args)
{
 struct worker_spec *ws = args;
 int i;
 ws->ws_fail = 0;
 for (i=0; i<ws->ws_iter; i++) {
  if (lock_unlock(ws->ws_path)) {
   ws->ws_fail++;
   printf("worker %d failed %d times\n",
    ws->ws_id, ws->ws_fail);
   break;
  } else {
   ws->ws_succ++;
  }
 }
 return ((void *)0);
}

variable_types:
args
void *

variable_types: struct worker_spec { unsigned long ws_thid; int ws_id; int ws_iter; int ws_fail; int ws_succ; char ws_path[4096]; } *


generator

decompiled_code:
__int64 __fastcall generator(const char *a1, int a2, unsigned int a3)
{
char *v4; // rax
char *v5; // rbp
unsigned int v6; // ebx
int v7; // eax
unsigned int v8; // er13
char *v9; // rax
pthread_t *v10; // r13
unsigned int i; // er12
int v12; // eax
unsigned int v13; // ebp
char *v14; // rax
unsigned int *v15; // rbp
__int64 v16; // rbx
char *v18; // [rsp+8h] [rbp-40h]

v4 = (char *)calloc(a2, 0x1018uLL);
v18 = v4;
if ( v4 )
{
v5 = v4;
v6 = 0;
if ( a2 > 0 )
{
while ( 1 )
{
*((_DWORD *)v5 + 2) = v6;
*((_DWORD *)v5 + 3) = a3;
snprintf(v5 + 24, 0x1000uLL, "%s/worker-%d", a1, v6);
v7 = pthread_create((pthread_t *)v5, 0LL, worker, v5);
v8 = v7;
if ( v7 )
{
v9 = strerror(v7);
printf("create %d thread failed, %d(%s)\n", v6, v8, v9);
}
v5 += 4120;
if ( a2 == v6 + 1 )
break;
++v6;
}
v10 = (pthread_t *)v18;
for ( i = 0; ; ++i )
{
v12 = pthread_join(*v10, 0LL);
v13 = v12;
if ( v12 )
{
v14 = strerror(v12);
printf("wait %d thread failed, %d(%s)\n", i, v13, v14);
}
v10 += 515;
if ( v6 == i )
break;
}
printf("Result: dirpath=%s, th_count=%d, iter=%d\n", a1, v6 + 1, a3);
v15 = (unsigned int *)(v18 + 8);
v16 = (__int64)&v18[4120 * v6 + 4128];
do
{
printf("worker(%d), success(%d), fail(%d)\n", *v15, v15[3], v15[2]);
v15 += 1030;
}
while ( v15 != (unsigned int *)v16 );
}
else
{
printf("Result: dirpath=%s, th_count=%d, iter=%d\n", a1, (unsigned int)a2, a3);
}
}
else
{
puts("can not alloc mem!!!");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, int a2, unsigned int a3)
{
char *v4; // rax
char *v5; // rbp
unsigned int v6; // ebx
int v7; // eax
unsigned int v8; // er13
char *v9; // rax
pthread_t *v10; // r13
unsigned int i; // er12
int v12; // eax
unsigned int v13; // ebp
char *v14; // rax
unsigned int *v15; // rbp
__int64 v16; // rbx
char *v18; // [rsp+8h] [rbp-40h]

v4 = (char *)calloc(a2, 0x1018uLL);
v18 = v4;
if ( v4 )
{
v5 = v4;
v6 = 0;
if ( a2 > 0 )
{
while ( 1 )
{
*((_DWORD *)v5 + 2) = v6;
*((_DWORD *)v5 + 3) = a3;
snprintf(v5 + 24, 0x1000uLL, "%s/worker-%d", a1, v6);
v7 = pthread_create((pthread_t *)v5, 0LL, worker, v5);
v8 = v7;
if ( v7 )
{
v9 = strerror(v7);
printf("create %d thread failed, %d(%s)\n", v6, v8, v9);
}
v5 += 4120;
if ( a2 == v6 + 1 )
break;
++v6;
}
v10 = (pthread_t *)v18;
for ( i = 0; ; ++i )
{
v12 = pthread_join(*v10, 0LL);
v13 = v12;
if ( v12 )
{
v14 = strerror(v12);
printf("wait %d thread failed, %d(%s)\n", i, v13, v14);
}
v10 += 515;
if ( v6 == i )
break;
}
printf("Result: dirpath=%s, th_count=%d, iter=%d\n", a1, v6 + 1, a3);
v15 = (unsigned int *)(v18 + 8);
v16 = (__int64)&v18[4120 * v6 + 4128];
do
{
printf("worker(%d), success(%d), fail(%d)\n", *v15, v15[3], v15[2]);
v15 += 1030;
}
while ( v15 != (unsigned int *)v16 );
}
else
{
printf("Result: dirpath=%s, th_count=%d, iter=%d\n", a1, (unsigned int)a2, a3);
}
}
else
{
puts("can not alloc mem!!!");
}
return 0LL;
}

original_code:
int generator(const char *dirpath, int count, int iter)
{
 struct worker_spec *ws = ((void *)0);
 int i, ret;
 ws = calloc(count, sizeof(struct worker_spec));
 if (!ws) {
  printf("can not alloc mem!!!\n");
  goto out;
 }
 for (i=0; i<count; i++) {
  ws[i].ws_id = i;
  ws[i].ws_iter = iter;
  snprintf(ws[i].ws_path, 4096, "%s/worker-%d", dirpath, i);
  ret = pthread_create(&ws[i].ws_thid, ((void *)0), &worker, &ws[i]);
  if (ret) {
   printf("create %d thread failed, %d(%s)\n",
    i, ret, strerror(ret));
  }
 }
 for (i=0; i<count; i++) {
  ret = pthread_join(ws[i].ws_thid, ((void *)0));
  if (ret) {
   printf("wait %d thread failed, %d(%s)\n",
    i, ret, strerror(ret));
  }
 }
 printf("Result: dirpath=%s, th_count=%d, iter=%d\n",
   dirpath, count, iter);
 for (i=0; i<count; i++) {
  printf("worker(%d), success(%d), fail(%d)\n",
   ws[i].ws_id, ws[i].ws_succ, ws[i].ws_fail);
 }
out:
 return 0;
}

canonical_original_code:
int generator(char *dirpath, int count, int iter)
{
 struct worker_spec *ws = ((void *)0);
 int i; int ret;
 ws = calloc(count, sizeof(struct worker_spec));
 if (!ws) {
  printf("can not alloc mem!!!\n");
  goto out;
 }
 for (i=0; i<count; i++) {
  ws[i].ws_id = i;
  ws[i].ws_iter = iter;
  snprintf(ws[i].ws_path, 4096, "%s/worker-%d", dirpath, i);
  ret = pthread_create(&ws[i].ws_thid, ((void *)0), &worker, &ws[i]);
  if (ret) {
   printf("create %d thread failed, %d(%s)\n",
    i, ret, strerror(ret));
  }
 }
 for (i=0; i<count; i++) {
  ret = pthread_join(ws[i].ws_thid, ((void *)0));
  if (ret) {
   printf("wait %d thread failed, %d(%s)\n",
    i, ret, strerror(ret));
  }
 }
 printf("Result: dirpath=%s, th_count=%d, iter=%d\n",
   dirpath, count, iter);
 for (i=0; i<count; i++) {
  printf("worker(%d), success(%d), fail(%d)\n",
   ws[i].ws_id, ws[i].ws_succ, ws[i].ws_fail);
 }
out:
 return 0;
}

variable_types:
dirpath
char *

variable_types: count int

variable_types: iter int

user_defined_types: struct worker_spec { unsigned long ws_thid; int ws_id; int ws_iter; int ws_fail; int ws_succ; char ws_path[4096]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
int v5; // er14
__int64 v6; // r8
__int64 v8[2]; // [rsp+0h] [rbp-1028h] BYREF
char v9[4080]; // [rsp+10h] [rbp-1018h] BYREF

v8[0] = 0x2F746E6D2FLL;
v8[1] = 0LL;
memset(v9, 0, sizeof(v9));
if ( argc - 1 <= 0 )
{
v4 = 100;
v5 = 20;
}
else
{
v3 = 0;
v4 = 100;
v5 = 20;
do
{
v6 = v3;
if ( !strcmp(argv[v6], "-i") )
{
++v3;
v4 = atoi(argv[v6 + 1]);
}
else if ( !strcmp(argv[v3], "-c") )
{
++v3;
v5 = atoi(argv[v6 + 1]);
}
else if ( !strcmp(argv[v3], "-d") )
{
++v3;
snprintf((char *)v8, 0x1000uLL, "%s", argv[v6 + 1]);
}
++v3;
}
while ( v3 < argc - 1 );
}
generator((const char *)v8, v5, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
int v5; // er14
__int64 v6; // r8
__int64 v8[2]; // [rsp+0h] [rbp-1028h] BYREF
char v9[4080]; // [rsp+10h] [rbp-1018h] BYREF

v8[0] = 0x2F746E6D2FLL;
v8[1] = 0LL;
memset(v9, 0, sizeof(v9));
if ( argc - 1 <= 0 )
{
v4 = 100;
v5 = 20;
}
else
{
v3 = 0;
v4 = 100;
v5 = 20;
do
{
v6 = v3;
if ( !strcmp(argv[v6], "-i") )
{
++v3;
v4 = atoi(argv[v6 + 1]);
}
else if ( !strcmp(argv[v3], "-c") )
{
++v3;
v5 = atoi(argv[v6 + 1]);
}
else if ( !strcmp(argv[v3], "-d") )
{
++v3;
snprintf((char *)v8, 0x1000uLL, "%s", argv[v6 + 1]);
}
++v3;
}
while ( v3 < argc - 1 );
}
func9((const char *)v8, v5, v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char dirpath[4096] = "/mnt/";
 int count = 20;
 int iter = 100;
 int i;
 for (i = 0; i < argc - 1; i++) {
  if (strcmp(argv[i], "-i") == 0) {
   i++;
   iter = atoi(argv[i]);
  } else if (strcmp(argv[i], "-c") == 0) {
   i++;
   count = atoi(argv[i]);
  } else if (strcmp(argv[i], "-d") == 0) {
   i++;
   snprintf(dirpath, 4096, "%s", argv[i]);
  }
 }
 generator(dirpath, count, iter);
 return 0;
}

variable_types:
dirpath
char [4096]


decompiled_code:
__int64 __fastcall ip_csum(__int64 a1, int a2)
{
__int64 v2; // rcx
unsigned __int64 v3; // rax

if ( a2 <= 0 )
{
v3 = 0LL;
}
else
{
v2 = a1 + 2LL * (unsigned int)a2;
v3 = 0LL;
do
{
a1 += 2LL;
v3 += *(unsigned __int16 *)(a1 - 2);
}
while ( a1 != v2 );
}
return ~((unsigned __int16)v3 + (unsigned int)(v3 >> 16) + (unsigned int)(((unsigned __int16)v3 + (v3 >> 16)) >> 16));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rcx
unsigned __int64 v3; // rax

if ( a2 <= 0 )
{
v3 = 0LL;
}
else
{
v2 = a1 + 2LL * (unsigned int)a2;
v3 = 0LL;
do
{
a1 += 2LL;
v3 += *(unsigned __int16 *)(a1 - 2);
}
while ( a1 != v2 );
}
return ~((unsigned __int16)v3 + (unsigned int)(v3 >> 16) + (unsigned int)(((unsigned __int16)v3 + (v3 >> 16)) >> 16));
}

original_code:
u16
ip_csum (u16 *buf, int nwords)
{
 unsigned long sum;
 for (sum = 0; nwords > 0; nwords--)
  sum += *buf++;
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 return ~sum;
}

canonical_original_code:
unsigned short ip_csum(unsigned short *buf, int nwords)
{
 unsigned long sum;
 for (sum = 0; nwords > 0; nwords--)
  sum += *buf++;
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 return ~sum;
}

variable_types:
buf
unsigned short *

variable_types: nwords int

variable_types:
sum
unsigned long

return_type: unsigned short


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

v1 = *(_BYTE **)(a1 + 48);
if ( v1 )
result = 4 * (*v1 & 0xFu);
else
result = 0LL;
return result;
}

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

v1 = *(_BYTE **)(a1 + 48);
if ( v1 )
result = 4 * (*v1 & 0xFu);
else
result = 0LL;
return result;
}

original_code:
int
uip_header_len(struct usk_buff *uskb)
{
 struct iphdr *iph;
 iph = ((struct iphdr *)(((uskb))->network_header));
 if (!iph)
  return 0;
 return (iph->ihl * 4);
}

variable_types: struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node { struct btqueue_node *next; } q_send; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct uprotocol { void (*close)(struct usock { int usk_mode; struct usk_buff_head { struct usk_buff *prev; struct usk_buff *next; unsigned short qlen; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } loc; } *usk_write_queue; struct usk_buff_head *usk_receive_queue; } *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head { struct list_head *next; } node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); } *proto; } *

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *


decompiled_code:
__int64 __fastcall uip_find_proto(__int64 a1)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 48);
if ( result )
result = uprotocol_find(*(unsigned __int8 *)(result + 9));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 48);
if ( result )
result = uprotocol_find(*(unsigned __int8 *)(result + 9));
return result;
}

original_code:
struct uprotocol *
uip_find_proto(struct usk_buff *uskb)
{
 struct iphdr *iph;
 struct uprotocol *proto;
 iph = ((struct iphdr *)(((uskb))->network_header));
 if (!iph)
  return 0;
 proto = uprotocol_find(iph->protocol);
 return proto;
}

canonical_original_code:
struct uprotocol *uip_find_proto(struct usk_buff *uskb)
{
 struct iphdr *iph;
 struct uprotocol *proto;
 iph = ((struct iphdr *)(((uskb))->network_header));
 if (!iph)
  return 0;
 proto = uprotocol_find(iph->protocol);
 return proto;
}

variable_types:
uskb
struct usk_buff *

variable_types: struct uprotocol { void (*close)(struct usock { int usk_mode; struct usk_buff_head { struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node { struct btqueue_node *next; } q_send; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct uprotocol *proto; } *prev; struct usk_buff *next; unsigned short qlen; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } loc; } *usk_write_queue; struct usk_buff_head *usk_receive_queue; } *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head { struct list_head *next; } node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); } *

user_defined_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; }


decompiled_code:
__int64 uip_output()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0LL;
}

original_code:
int
uip_output(struct usk_buff *uskb)
{
 return 0;
}

user_defined_types: struct btqueue_node { struct btqueue_node *next; }

user_defined_types: struct list_head { struct list_head *next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall uip_input(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = uprotocol_find(*(unsigned __int8 *)(*(_QWORD *)(a1 + 48) + 9LL));
if ( v1 )
result = (*(__int64 (__fastcall **)(__int64))(v1 + 152))(a1);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = uprotocol_find(*(unsigned __int8 *)(*(_QWORD *)(a1 + 48) + 9LL));
if ( v1 )
result = (*(__int64 (__fastcall **)(__int64))(v1 + 152))(a1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
uip_input(struct usk_buff *uskb)
{
 struct iphdr *iph;
 struct uprotocol *proto;
 int ret;
 iph = ((struct iphdr *)(((uskb))->network_header));
 proto = uprotocol_find(iph->protocol);
 if (!proto) {
  return -1;
 }
 ret = proto->handler(uskb);
 return ret;
}


decompiled_code:
int init_data_channel()
{
int v0; // ebx
int result; // eax
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
client_recv_fd = v0;
v2.sa_family = 2;
*(_WORD *)v2.sa_data = _bswap_16(30667);
*(_DWORD *)&v2.sa_data[2] = 0;
if ( bind(v0, &v2, 0x10u) == -1 )
{
puts("bind error! ");
exit(0);
}
result = listen(client_recv_fd, 5);
if ( result == -1 )
result = puts("listen error! ");
return result;
}

canonical_decompiled_code:
int func1()
{
int v0; // ebx
int result; // eax
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
client_recv_fd = v0;
v2.sa_family = 2;
*(_WORD *)v2.sa_data = func0(30667);
*(_DWORD *)&v2.sa_data[2] = 0;
if ( bind(v0, &v2, 0x10u) == -1 )
{
puts("bind error! ");
exit(0);
}
result = listen(client_recv_fd, 5);
if ( result == -1 )
result = puts("listen error! ");
return result;
}

original_code:
void init_data_channel()
{
 struct sockaddr_in client_addr;
 client_recv_fd = socket(2,SOCK_STREAM,0);
 client_addr.sin_family = 2;
 client_addr.sin_port = htons(30667);
 client_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if(bind(client_recv_fd,(struct sockaddr*) &client_addr,sizeof(client_addr))==-1){
  printf("bind error! \n");
  exit(0);
 }
 if(listen(client_recv_fd,5)==-1)
  printf("listen error! \n");
}

canonical_original_code:
void init_data_channel()
{
 struct sockaddr_in client_addr;
 client_recv_fd = socket(2,SOCK_STREAM,0);
 client_addr.sin_family = 2;
 client_addr.sin_port = htons(30667);
 client_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if(bind(client_recv_fd,(struct sockaddr *) &client_addr,sizeof(client_addr))==-1){
  printf("bind error! \n");
  exit(0);
 }
 if(listen(client_recv_fd,5)==-1)
  printf("listen error! \n");
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


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

if ( close(client_recv_fd) )
result = puts("data chenal close failed ");
else
result = puts("data chenal close success ");
return result;
}

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

if ( close(client_recv_fd) )
result = puts("data chenal close failed ");
else
result = puts("data chenal close success ");
return result;
}

original_code:
void close_data_channel()
{
 if(close(client_recv_fd) == 0)
  printf("data chenal close success \n");
 else
  printf("data chenal close failed \n");
}


decompiled_code:
int get_data_connection()
{
struct sockaddr v1; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
return accept(client_recv_fd, &v1, addr_len);
}

canonical_decompiled_code:
int func3()
{
struct sockaddr v1; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
return accept(client_recv_fd, &v1, addr_len);
}

original_code:
int get_data_connection()
{
 int server_data_channel_fd,server_len;
 server_data_channel_fd = -1;
 struct sockaddr_in server_addr;
 server_len = sizeof(server_addr);
 server_data_channel_fd = accept(client_recv_fd,(struct sockaddr*) &server_addr,&server_len);
 return server_data_channel_fd;
}

canonical_original_code:
int get_data_connection()
{
 int server_data_channel_fd; int server_len;
 server_data_channel_fd = -1;
 struct sockaddr_in server_addr;
 server_len = sizeof(server_addr);
 server_data_channel_fd = accept(client_recv_fd,(struct sockaddr *) &server_addr,&server_len);
 return server_data_channel_fd;
}


decompiled_code:
int __fastcall close_data_connection(int a1)
{
int result; // eax

if ( close(a1) )
result = puts("data channel connection close failed ");
else
result = puts("data channel connection close success ");
return result;
}

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

if ( close(a1) )
result = puts("data channel connection close failed ");
else
result = puts("data channel connection close success ");
return result;
}

original_code:
void close_data_connection(int server_data_channel_fd)
{
 if(close(server_data_channel_fd) != 0)
  printf("data channel connection close failed \n");
 else
  printf("data channel connection close success \n");
}


decompiled_code:
__int64 __fastcall scan_command(__int64 a1, const char *a2, __int64 a3)
{
bool v4; // zf
__int64 result; // rax

printf("command>");
_isoc99_scanf("%s", a2);
if ( !strcmp(a2, "ls") || !strcmp(a2, "cd") || !strcmp(a2, "rm") )
{
_isoc99_scanf("%s", a3);
result = 1LL;
}
else if ( !strcmp(a2, "rename") )
{
_isoc99_scanf("%s", a3);
_isoc99_scanf("%s", a3 + 20);
result = 1LL;
}
else if ( !strcmp(a2, "upload") || !strcmp(a2, "download") )
{
_isoc99_scanf("%s,%s", a3, a3 + 20);
result = 1LL;
}
else
{
v4 = strcmp(a2, "exit") == 0;
result = !v4;
if ( !v4 )
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, __int64 a3)
{
bool v4; // zf
__int64 result; // rax

printf("command>");
_isoc99_scanf("%s", a2);
if ( !strcmp(a2, "ls") || !strcmp(a2, "cd") || !strcmp(a2, "rm") )
{
_isoc99_scanf("%s", a3);
result = 1LL;
}
else if ( !strcmp(a2, "rename") )
{
_isoc99_scanf("%s", a3);
_isoc99_scanf("%s", a3 + 20);
result = 1LL;
}
else if ( !strcmp(a2, "upload") || !strcmp(a2, "download") )
{
_isoc99_scanf("%s,%s", a3, a3 + 20);
result = 1LL;
}
else
{
v4 = strcmp(a2, "exit") == 0;
result = !v4;
if ( !v4 )
result = 2LL;
}
return result;
}

original_code:
int scan_command(char* username,char command[],char arguments[][20])
{
 printf("command>");
 scanf("%s",command);
 if(strcmp(command,"ls") == 0)
 {
  scanf("%s",arguments[0]);
  return 1;
 }
 else if(strcmp(command,"cd") == 0)
 {
  scanf("%s",arguments[0]);
  return 1;
 }
 else if(strcmp(command,"rm") == 0)
 {
  scanf("%s",arguments[0]);
  return 1;
 }
 else if(strcmp(command,"rename") == 0)
 {
  scanf("%s",arguments[0]);
  scanf("%s",arguments[1]);
  return 1;
 }
 else if(strcmp(command,"upload") == 0)
 {
  scanf("%s,%s",arguments[0],arguments[1]);
  return 1;
 }
 else if(strcmp(command,"download") == 0)
 {
  scanf("%s,%s",arguments[0],arguments[1]);
  return 1;
 }
 else if(strcmp(command,"exit") == 0)
 {
  return 0;
 }
 else
 {
  return 2;
 }
}

canonical_original_code:
int scan_command(char *username, char command[], char arguments[][20])
{
 printf("command>");
 scanf("%s",command);
 if(strcmp(command,"ls") == 0)
 {
  scanf("%s",arguments[0]);
  return 1;
 }
 else if(strcmp(command,"cd") == 0)
 {
  scanf("%s",arguments[0]);
  return 1;
 }
 else if(strcmp(command,"rm") == 0)
 {
  scanf("%s",arguments[0]);
  return 1;
 }
 else if(strcmp(command,"rename") == 0)
 {
  scanf("%s",arguments[0]);
  scanf("%s",arguments[1]);
  return 1;
 }
 else if(strcmp(command,"upload") == 0)
 {
  scanf("%s,%s",arguments[0],arguments[1]);
  return 1;
 }
 else if(strcmp(command,"download") == 0)
 {
  scanf("%s,%s",arguments[0],arguments[1]);
  return 1;
 }
 else if(strcmp(command,"exit") == 0)
 {
  return 0;
 }
 else
 {
  return 2;
 }
}

variable_types:
username
char *

variable_types:
command
char []

variable_types:
arguments
char [][20]


QueryDirContent

decompiled_code:
int __fastcall QueryDirContent(int fd, const char *a2)
{
size_t v2; // rax
int v3; // er14
unsigned int v4; // ebp
int v6; // eax
char *v7; // r13
__int64 i; // rbx
const char *v9; // rsi
char v10[32]; // [rsp+0h] [rbp-68h] BYREF
char v11[72]; // [rsp+20h] [rbp-48h] BYREF

memset(buffer, 0, (size_t)&unk_100000);
sprintf(buffer, "request;querydircontent;%s%s|", &current_directory, a2);
v2 = strlen(buffer);
if ( send(fd, buffer, v2, 0) == -1 )
puts("send error");
memset(buffer, 0, (size_t)&unk_100000);
recv(fd, buffer, (size_t)&unk_100000, 0);
response_analysis(buffer, (__int64)v11, (__int64)v10);
if ( !strcmp(v11, "error") )
return printf("%s:%s\n", v11, v10);
v3 = get_data_connection();
puts("type\tname\t\t\t\tsize");
v4 = 0;
while ( 1 )
{
v6 = recv(v3, buffer, (size_t)&unk_100000, 0);
if ( v6 <= 0 )
break;
buffer[v6] = 0;
v7 = get_files_information(buffer);
for ( i = *((_QWORD *)v7 + 14); i; i = *(_QWORD *)(i + 112) )
{
++v4;
v9 = "file";
if ( *(_DWORD *)i )
v9 = "dir";
printf("%s\t%-20s\t\t%-6d\n", v9, (const char *)(i + 4), *(unsigned int *)(i + 104));
}
free_file_list(v7);
}
printf("total %d items\n", v4);
close_data_connection(v3);
return puts("end of query dir ");
}

canonical_decompiled_code:
int __fastcall func9(int fd, const char *a2)
{
size_t v2; // rax
int v3; // er14
unsigned int v4; // ebp
int v6; // eax
char *v7; // r13
__int64 i; // rbx
const char *v9; // rsi
char v10[32]; // [rsp+0h] [rbp-68h] BYREF
char v11[72]; // [rsp+20h] [rbp-48h] BYREF

memset(buffer, 0, (size_t)&unk_100000);
sprintf(buffer, "request;querydircontent;%s%s|", &current_directory, a2);
v2 = strlen(buffer);
if ( send(fd, buffer, v2, 0) == -1 )
puts("send error");
memset(buffer, 0, (size_t)&unk_100000);
recv(fd, buffer, (size_t)&unk_100000, 0);
func6(buffer, (__int64)v11, (__int64)v10);
if ( !strcmp(v11, "error") )
return printf("%s:%s\n", v11, v10);
v3 = func3();
puts("type\tname\t\t\t\tsize");
v4 = 0;
while ( 1 )
{
v6 = recv(v3, buffer, (size_t)&unk_100000, 0);
if ( v6 <= 0 )
break;
buffer[v6] = 0;
v7 = func7(buffer);
for ( i = *((_QWORD *)v7 + 14); i; i = *(_QWORD *)(i + 112) )
{
++v4;
v9 = "file";
if ( *(_DWORD *)i )
v9 = "dir";
printf("%s\t%-20s\t\t%-6d\n", v9, (const char *)(i + 4), *(unsigned int *)(i + 104));
}
func8(v7);
}
printf("total %d items\n", v4);
func4(v3);
return puts("end of query dir ");
}

original_code:
void QueryDirContent(int server_fd,char directory[])
{
 char response_type[20];
 char response_argu[20];
 int server_data_channel_fd;
 int nbytes;
 int item_count = 0;
 struct file_list * files_head = ((void *)0);
 struct file_list * pfile = ((void *)0);
 memset(buffer,'\0',1048576);
 sprintf(buffer,"request;querydircontent;%s%s|",current_directory,directory);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
 }
 memset(buffer,'\0',1048576);
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
      printf("%s:%s\n",response_type,response_argu);
   return;
 }
 server_data_channel_fd = get_data_connection();
 memset(buffer,1048576,'\0');
 printf("type\tname\t\t\t\tsize\n");
  while((nbytes = recv(server_data_channel_fd,buffer,1048576,0)) > 0)
 {
  buffer[nbytes]='\0';
  files_head = get_files_information(buffer);
  pfile = files_head;
  while(pfile->next_file != ((void *)0)){
   item_count++;
   pfile = pfile->next_file;
   printf("%s\t%-20s\t\t%-6d\n",pfile->file_type?"dir":"file",pfile->file_name,pfile->file_size);
  }
  memset(buffer,1048576,'\0');
  free_file_list(files_head);
  }
 printf("total %d items\n",item_count);
 close_data_connection(server_data_channel_fd);
printf("end of query dir \n");
}

canonical_original_code:
void QueryDirContent(int server_fd, char directory[])
{
 char response_type[20];
 char response_argu[20];
 int server_data_channel_fd;
 int nbytes;
 int item_count = 0;
 struct file_list *files_head = ((void *)0);
 struct file_list *pfile = ((void *)0);
 memset(buffer,'\0',1048576);
 sprintf(buffer,"request;querydircontent;%s%s|",current_directory,directory);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
 }
 memset(buffer,'\0',1048576);
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
      printf("%s:%s\n",response_type,response_argu);
   return;
 }
 server_data_channel_fd = get_data_connection();
 memset(buffer,1048576,'\0');
 printf("type\tname\t\t\t\tsize\n");
  while((nbytes = recv(server_data_channel_fd,buffer,1048576,0)) > 0)
 {
  buffer[nbytes]='\0';
  files_head = get_files_information(buffer);
  pfile = files_head;
  while(pfile->next_file != ((void *)0)){
   item_count++;
   pfile = pfile->next_file;
   printf("%s\t%-20s\t\t%-6d\n",pfile->file_type?"dir":"file",pfile->file_name,pfile->file_size);
  }
  memset(buffer,1048576,'\0');
  free_file_list(files_head);
  }
 printf("total %d items\n",item_count);
 close_data_connection(server_data_channel_fd);
printf("end of query dir \n");
}

variable_types:
directory
char []

variable_types: nbytes int

variable_types: struct file_list { int file_type; char file_name[100]; int file_size; struct file_list *next_file; } *


ChangeDirectory

decompiled_code:
__int64 __fastcall ChangeDirectory(int fd, char *src)
{
size_t v2; // rax
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-58h] BYREF
char v5[56]; // [rsp+20h] [rbp-38h] BYREF

sprintf(buffer, "request;changedirectory;%s;%s|", current_directory, src);
v2 = strlen(buffer);
if ( send(fd, buffer, v2, 0) == -1 )
{
puts("send error");
result = 0xFFFFFFFFLL;
}
else
{
recv(fd, buffer, (size_t)&unk_100000, 0);
response_analysis(buffer, (__int64)v5, (__int64)&v4);
if ( !strcmp(v5, "error") )
{
puts("the directory don't exist");
result = 0xFFFFFFFFLL;
}
else
{
strcat(current_directory, src);
current_directory[strlen(current_directory)] = 47;
current_directory[strlen(current_directory) + 1] = 0;
puts("directory changed");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, char *src)
{
size_t v2; // rax
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-58h] BYREF
char v5[56]; // [rsp+20h] [rbp-38h] BYREF

sprintf(buffer, "request;changedirectory;%s;%s|", current_directory, src);
v2 = strlen(buffer);
if ( send(fd, buffer, v2, 0) == -1 )
{
puts("send error");
result = 0xFFFFFFFFLL;
}
else
{
recv(fd, buffer, (size_t)&unk_100000, 0);
func6(buffer, (__int64)v5, (__int64)&v4);
if ( !strcmp(v5, "error") )
{
puts("the directory don't exist");
result = 0xFFFFFFFFLL;
}
else
{
strcat(current_directory, src);
current_directory[strlen(current_directory)] = 47;
current_directory[strlen(current_directory) + 1] = 0;
puts("directory changed");
result = 1LL;
}
}
return result;
}

original_code:
int ChangeDirectory(int server_fd,char new_dir[])
{
 char response_type[20];
 char response_argu[20];
 memset(buffer,1048576,'\0');
 sprintf(buffer,"request;changedirectory;%s;%s|",current_directory,new_dir);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
  return -1;
 }
 memset(buffer,1048576,'\0');
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
  printf("the directory don't exist\n");
  return -1;
 }
 strcat(current_directory,new_dir);
 current_directory[strlen(current_directory)] = '/';
 current_directory[strlen(current_directory)+1] = '\0';
 printf("directory changed\n");
 return 1;
}

canonical_original_code:
int ChangeDirectory(int server_fd, char new_dir[])
{
 char response_type[20];
 char response_argu[20];
 memset(buffer,1048576,'\0');
 sprintf(buffer,"request;changedirectory;%s;%s|",current_directory,new_dir);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
  return -1;
 }
 memset(buffer,1048576,'\0');
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
  printf("the directory don't exist\n");
  return -1;
 }
 strcat(current_directory,new_dir);
 current_directory[strlen(current_directory)] = '/';
 current_directory[strlen(current_directory)+1] = '\0';
 printf("directory changed\n");
 return 1;
}


decompiled_code:
void __fastcall free_file_list(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 14);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 14);
free(v2);
}
}

original_code:
void free_file_list(struct file_list * file_list_head)
{
 struct file_list * tem = ((void *)0);
 while(file_list_head != ((void *)0)){
  tem = file_list_head;
  file_list_head = file_list_head->next_file;
  free(tem);
 }
}

canonical_original_code:
void free_file_list(struct file_list *file_list_head)
{
 struct file_list *tem = ((void *)0);
 while(file_list_head != ((void *)0)){
  tem = file_list_head;
  file_list_head = file_list_head->next_file;
  free(tem);
 }
}

user_defined_types: struct file_list { int file_type; char file_name[100]; int file_size; struct file_list *next_file; }


decompiled_code:
__int64 __fastcall test_fuse_init(int fd, __int64 a2, int *a3)
{
int v4; // eax
__int64 result; // rax
int *v6; // rax
struct iovec v7; // [rsp+0h] [rbp-68h] BYREF
int *v8; // [rsp+10h] [rbp-58h]
__int64 v9; // [rsp+18h] [rbp-50h]
int v10[2]; // [rsp+20h] [rbp-48h] BYREF
__int64 v11; // [rsp+28h] [rbp-40h]
int v12[4]; // [rsp+30h] [rbp-38h] BYREF
__int16 v13; // [rsp+40h] [rbp-28h]
__int16 v14; // [rsp+42h] [rbp-26h]
int v15; // [rsp+44h] [rbp-24h]

printf("%s called\n", "test_fuse_init");
v12[0] = *a3;
v12[1] = a3[1];
v12[2] = 0x20000;
v15 = 0x20000;
v12[3] = 3;
v13 = 64;
v14 = 48;
v7.iov_base = v10;
v7.iov_len = 16LL;
v8 = v12;
v9 = 24LL;
v10[0] = 40;
v11 = *(_QWORD *)(a2 + 8);
v10[1] = 0;
v4 = writev(fd, &v7, 2);
if ( v4 <= 0 )
{
v6 = __errno_location();
printf("write error.errno %d\n", (unsigned int)*v6);
result = 0xFFFFFFFFLL;
}
else
{
printf("write %d bytes\n", (unsigned int)v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, __int64 a2, int *a3)
{
int v4; // eax
__int64 result; // rax
int *v6; // rax
struct iovec v7; // [rsp+0h] [rbp-68h] BYREF
int *v8; // [rsp+10h] [rbp-58h]
__int64 v9; // [rsp+18h] [rbp-50h]
int v10[2]; // [rsp+20h] [rbp-48h] BYREF
__int64 v11; // [rsp+28h] [rbp-40h]
int v12[4]; // [rsp+30h] [rbp-38h] BYREF
__int16 v13; // [rsp+40h] [rbp-28h]
__int16 v14; // [rsp+42h] [rbp-26h]
int v15; // [rsp+44h] [rbp-24h]

printf("%s called\n", "test_fuse_init");
v12[0] = *a3;
v12[1] = a3[1];
v12[2] = 0x20000;
v15 = 0x20000;
v12[3] = 3;
v13 = 64;
v14 = 48;
v7.iov_base = v10;
v7.iov_len = 16LL;
v8 = v12;
v9 = 24LL;
v10[0] = 40;
v11 = *(_QWORD *)(a2 + 8);
v10[1] = 0;
v4 = writev(fd, &v7, 2);
if ( v4 <= 0 )
{
v6 = __errno_location();
printf("write error.errno %d\n", (unsigned int)*v6);
result = 0xFFFFFFFFLL;
}
else
{
printf("write %d bytes\n", (unsigned int)v4);
result = 0LL;
}
return result;
}

original_code:
int test_fuse_init (int fd, struct fuse_in_header *finh, void *msg)
{
 int ret;
 struct fuse_init_in *fini = msg;
 struct fuse_init_out fino;
 struct fuse_out_header fouh;
 struct iovec iov[2];
printf("%s called\n", __func__);
 fino.major = fini->major;
 fino.minor = fini->minor;
 fino.max_readahead = 1 << 17;
 fino.max_write = 1 << 17;
 fino.flags = (1 << 0) | (1 << 1);
 fino.max_background = 64;
 fino.congestion_threshold = 48;
 iov[0].iov_base = &fouh;
 iov[0].iov_len = sizeof(fouh);
 iov[1].iov_base = &fino;
 iov[1].iov_len = sizeof(fino);
 fouh.len = iov[0].iov_len + iov[1].iov_len;
 fouh.unique = finh->unique;
 fouh.error = 0;
 ret = writev(fd, iov, 2);
 if (ret <= 0) {
  printf("write error.errno %d\n", (*__errno_location ()));
  return -1;
 }
 printf("write %d bytes\n", ret);
 return 0;
}

canonical_original_code:
int test_fuse_init(int fd, struct fuse_in_header *finh, void *msg)
{
 int ret;
 struct fuse_init_in *fini = msg;
 struct fuse_init_out fino;
 struct fuse_out_header fouh;
 struct iovec iov[2];
printf("%s called\n", __func__);
 fino.major = fini->major;
 fino.minor = fini->minor;
 fino.max_readahead = 1 << 17;
 fino.max_write = 1 << 17;
 fino.flags = (1 << 0) | (1 << 1);
 fino.max_background = 64;
 fino.congestion_threshold = 48;
 iov[0].iov_base = &fouh;
 iov[0].iov_len = sizeof(fouh);
 iov[1].iov_base = &fino;
 iov[1].iov_len = sizeof(fino);
 fouh.len = iov[0].iov_len + iov[1].iov_len;
 fouh.unique = finh->unique;
 fouh.error = 0;
 ret = writev(fd, iov, 2);
 if (ret <= 0) {
  printf("write error.errno %d\n", (*__errno_location ()));
  return -1;
 }
 printf("write %d bytes\n", ret);
 return 0;
}

variable_types: fd int

variable_types: struct fuse_in_header { unsigned int len; unsigned int opcode; unsigned long unique; unsigned long nodeid; unsigned int uid; unsigned int gid; unsigned int pid; unsigned int padding; } *

variable_types:
msg
void *

variable_types: ret int

variable_types: struct fuse_init_in { unsigned int major; unsigned int minor; unsigned int max_readahead; unsigned int flags; } *

variable_types: struct fuse_init_out { unsigned int major; unsigned int minor; unsigned int max_readahead; unsigned int flags; unsigned short max_background; unsigned short congestion_threshold; unsigned int max_write; }

variable_types: struct fuse_out_header { unsigned int len; int error; unsigned long unique; }

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]