original_code:
int test_next(KVSet * (*create_kvset_fun)()){
    KVSet* skiplist = create_kvset_fun();
    void * el;
    skiplist->funs.put(skiplist, (void *)(3));
    skiplist->funs.put(skiplist, (void *)(6));
    skiplist->funs.put(skiplist, (void *)(4));
    el = skiplist->funs.first(skiplist);
    ((void) sizeof ((el == (void *)(3)) ? 1 : 0), __extension__ ({ if (el == (void *)(3)) ; else __assert_fail ("el == TO_VP(3)", "test_kvset.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.next(skiplist, el);
    ((void) sizeof ((el == (void *)(4)) ? 1 : 0), __extension__ ({ if (el == (void *)(4)) ; else __assert_fail ("el == TO_VP(4)", "test_kvset.c", 239, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.next(skiplist, el);
    ((void) sizeof ((el == (void *)(6)) ? 1 : 0), __extension__ ({ if (el == (void *)(6)) ; else __assert_fail ("el == TO_VP(6)", "test_kvset.c", 243, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.next(skiplist, el);
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return el == ((void *)0);
}

canonical_original_code:
int test_next(struct kv_set *(*create_kvset_fun)()){
    struct kv_set *skiplist = create_kvset_fun();
    void *el;
    skiplist->funs.put(skiplist, (void *)(3));
    skiplist->funs.put(skiplist, (void *)(6));
    skiplist->funs.put(skiplist, (void *)(4));
    el = skiplist->funs.first(skiplist);
    ((void) sizeof ((el == (void *)(3)) ? 1 : 0), __extension__ ({ if (el == (void *)(3)) ; else __assert_fail ("el == TO_VP(3)", "test_kvset.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.next(skiplist, el);
    ((void) sizeof ((el == (void *)(4)) ? 1 : 0), __extension__ ({ if (el == (void *)(4)) ; else __assert_fail ("el == TO_VP(4)", "test_kvset.c", 239, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.next(skiplist, el);
    ((void) sizeof ((el == (void *)(6)) ? 1 : 0), __extension__ ({ if (el == (void *)(6)) ; else __assert_fail ("el == TO_VP(6)", "test_kvset.c", 243, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.next(skiplist, el);
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return el == ((void *)0);
}


original_code:
int test_previous(KVSet * (*create_kvset_fun)()){
    KVSet* skiplist = create_kvset_fun();
    void * el;
    skiplist->funs.put(skiplist, (void *)(3));
    skiplist->funs.put(skiplist, (void *)(6));
    skiplist->funs.put(skiplist, (void *)(4));
    el = skiplist->funs.last(skiplist);
    ((void) sizeof ((el == (void *)(6)) ? 1 : 0), __extension__ ({ if (el == (void *)(6)) ; else __assert_fail ("el == TO_VP(6)", "test_kvset.c", 267, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.previous(skiplist, el);
    ((void) sizeof ((el == (void *)(4)) ? 1 : 0), __extension__ ({ if (el == (void *)(4)) ; else __assert_fail ("el == TO_VP(4)", "test_kvset.c", 271, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.previous(skiplist, el);
    ((void) sizeof ((el == (void *)(3)) ? 1 : 0), __extension__ ({ if (el == (void *)(3)) ; else __assert_fail ("el == TO_VP(3)", "test_kvset.c", 275, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.previous(skiplist, el);
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return el == ((void *)0);
}

canonical_original_code:
int test_previous(struct kv_set *(*create_kvset_fun)()){
    struct kv_set *skiplist = create_kvset_fun();
    void *el;
    skiplist->funs.put(skiplist, (void *)(3));
    skiplist->funs.put(skiplist, (void *)(6));
    skiplist->funs.put(skiplist, (void *)(4));
    el = skiplist->funs.last(skiplist);
    ((void) sizeof ((el == (void *)(6)) ? 1 : 0), __extension__ ({ if (el == (void *)(6)) ; else __assert_fail ("el == TO_VP(6)", "test_kvset.c", 267, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.previous(skiplist, el);
    ((void) sizeof ((el == (void *)(4)) ? 1 : 0), __extension__ ({ if (el == (void *)(4)) ; else __assert_fail ("el == TO_VP(4)", "test_kvset.c", 271, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.previous(skiplist, el);
    ((void) sizeof ((el == (void *)(3)) ? 1 : 0), __extension__ ({ if (el == (void *)(3)) ; else __assert_fail ("el == TO_VP(3)", "test_kvset.c", 275, __extension__ __PRETTY_FUNCTION__); }));
    el = skiplist->funs.previous(skiplist, el);
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return el == ((void *)0);
}

variable_types: struct kv_set { struct kv_set_functions { void (*delete_table)(struct kv_set *kv_set, void (*element_free_function)(void *context, void *element), void *context); void *(*put)(struct kv_set *set, void *key_value); int (*put_new)(struct kv_set *set, void *key_value); void *(*remove)(struct kv_set *set, void *key); void *(*lookup)(struct kv_set *set, void *key); int (*member)(struct kv_set *set, void *key); void *(*first)(struct kv_set *set); void *(*last)(struct kv_set *set); void *(*next)(struct kv_set *set, void *key); void *(*previous)(struct kv_set *set, void *key); } funs; unsigned int key_offset; void *type_specific_data; } *(*)()

variable_types:
el
void *

return_type: int

user_defined_types: struct kv_set { struct kv_set_functions funs; unsigned int key_offset; void *type_specific_data; }


decompiled_code:
int __fastcall test_general_kvset_properties(__int64 (*a1)(void))
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax

puts("\x1B[32m -- STARTING GENERAL PROPERTIES TESTS! -- \x1B[m");
printf("STARTING TEST: ");
v1 = test_create_and_delete(a1);
test(v1, "test_create_and_delete()");
printf("STARTING TEST: ");
v2 = test_insert(a1);
test(v2, "test_insert()");
printf("STARTING TEST: ");
v3 = test_insert_write_over(a1);
test(v3, "test_insert_write_over()");
printf("STARTING TEST: ");
v4 = test_lookup(a1);
test(v4, "test_lookup()");
printf("STARTING TEST: ");
v5 = test_lookup_not_exsisting(a1);
test(v5, "test_lookup_not_exsisting()");
printf("STARTING TEST: ");
v6 = test_remove(a1);
test(v6, "test_remove()");
printf("STARTING TEST: ");
v7 = test_insert_lookup_delete_lookup_many(a1);
test(v7, "test_insert_lookup_delete_lookup_many()");
printf("STARTING TEST: ");
v8 = test_insert_new(a1);
test(v8, "test_insert_new()");
return puts("\x1B[32m -- GENERAL PROPERTIES TESTS COMPLETED! -- \x1B[m");
}

canonical_decompiled_code:
int __fastcall func13(__int64 (*a1)(void))
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax

puts("\x1B[32m -- STARTING GENERAL PROPERTIES TESTS! -- \x1B[m");
printf("STARTING TEST: ");
v1 = func1(a1);
func0(v1, "test_create_and_delete()");
printf("STARTING TEST: ");
v2 = func2(a1);
func0(v2, "test_insert()");
printf("STARTING TEST: ");
v3 = func4(a1);
func0(v3, "test_insert_write_over()");
printf("STARTING TEST: ");
v4 = func5(a1);
func0(v4, "test_lookup()");
printf("STARTING TEST: ");
v5 = func6(a1);
func0(v5, "test_lookup_not_exsisting()");
printf("STARTING TEST: ");
v6 = func7(a1);
func0(v6, "test_remove()");
printf("STARTING TEST: ");
v7 = func8(a1);
func0(v7, "test_insert_lookup_delete_lookup_many()");
printf("STARTING TEST: ");
v8 = func3(a1);
func0(v8, "test_insert_new()");
return puts("\x1B[32m -- GENERAL PROPERTIES TESTS COMPLETED! -- \x1B[m");
}

original_code:
void test_general_kvset_properties(KVSet * (*create_kvset_fun)()){
    printf("\033[32m -- STARTING GENERAL PROPERTIES TESTS! -- \033[m\n");
    printf("STARTING TEST: "); test(test_create_and_delete(create_kvset_fun), "test_create_and_delete()");;
    printf("STARTING TEST: "); test(test_insert(create_kvset_fun), "test_insert()");;
    printf("STARTING TEST: "); test(test_insert_write_over(create_kvset_fun), "test_insert_write_over()");;
    printf("STARTING TEST: "); test(test_lookup(create_kvset_fun), "test_lookup()");;
    printf("STARTING TEST: "); test(test_lookup_not_exsisting(create_kvset_fun), "test_lookup_not_exsisting()");;
    printf("STARTING TEST: "); test(test_remove(create_kvset_fun), "test_remove()");;
    printf("STARTING TEST: "); test(test_insert_lookup_delete_lookup_many(create_kvset_fun), "test_insert_lookup_delete_lookup_many()");;
    printf("STARTING TEST: "); test(test_insert_new(create_kvset_fun), "test_insert_new()");;
    printf("\033[32m -- GENERAL PROPERTIES TESTS COMPLETED! -- \033[m\n");
}

canonical_original_code:
void test_general_kvset_properties(struct kv_set *(*create_kvset_fun)()){
    printf("\033[32m -- STARTING GENERAL PROPERTIES TESTS! -- \033[m\n");
    printf("STARTING TEST: "); test(test_create_and_delete(create_kvset_fun), "test_create_and_delete()");;
    printf("STARTING TEST: "); test(test_insert(create_kvset_fun), "test_insert()");;
    printf("STARTING TEST: "); test(test_insert_write_over(create_kvset_fun), "test_insert_write_over()");;
    printf("STARTING TEST: "); test(test_lookup(create_kvset_fun), "test_lookup()");;
    printf("STARTING TEST: "); test(test_lookup_not_exsisting(create_kvset_fun), "test_lookup_not_exsisting()");;
    printf("STARTING TEST: "); test(test_remove(create_kvset_fun), "test_remove()");;
    printf("STARTING TEST: "); test(test_insert_lookup_delete_lookup_many(create_kvset_fun), "test_insert_lookup_delete_lookup_many()");;
    printf("STARTING TEST: "); test(test_insert_new(create_kvset_fun), "test_insert_new()");;
    printf("\033[32m -- GENERAL PROPERTIES TESTS COMPLETED! -- \033[m\n");
}

return_type: void

user_defined_types: struct kv_set_functions { void (*delete_table)(struct kv_set *kv_set, void (*element_free_function)(void *context, void *element), void *context); void *(*put)(struct kv_set *set, void *key_value); int (*put_new)(struct kv_set *set, void *key_value); void *(*remove)(struct kv_set *set, void *key); void *(*lookup)(struct kv_set *set, void *key); int (*member)(struct kv_set *set, void *key); void *(*first)(struct kv_set *set); void *(*last)(struct kv_set *set); void *(*next)(struct kv_set *set, void *key); void *(*previous)(struct kv_set *set, void *key); }


decompiled_code:
int __fastcall test_ordered_kvset_properties(__int64 (*a1)(void))
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax

puts("\x1B[32m -- STARTING ORDERED PROPERTIES TESTS! -- \x1B[m");
printf("STARTING TEST: ");
v1 = test_first(a1);
test(v1, "test_first()");
printf("STARTING TEST: ");
v2 = test_first(a1);
test(v2, "test_last()");
printf("STARTING TEST: ");
v3 = test_next(a1);
test(v3, "test_next()");
printf("STARTING TEST: ");
v4 = test_previous(a1);
test(v4, "test_previous()");
return puts("\x1B[32m -- ORDERED PROPERTIES TESTS COMPLETED! -- \x1B[m");
}

canonical_decompiled_code:
int __fastcall func14(__int64 (*a1)(void))
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax

puts("\x1B[32m -- STARTING ORDERED PROPERTIES TESTS! -- \x1B[m");
printf("STARTING TEST: ");
v1 = func9(a1);
func0(v1, "test_first()");
printf("STARTING TEST: ");
v2 = func9(a1);
func0(v2, "test_last()");
printf("STARTING TEST: ");
v3 = func11(a1);
func0(v3, "test_next()");
printf("STARTING TEST: ");
v4 = func12(a1);
func0(v4, "test_previous()");
return puts("\x1B[32m -- ORDERED PROPERTIES TESTS COMPLETED! -- \x1B[m");
}

original_code:
void test_ordered_kvset_properties(KVSet * (*create_kvset_fun)()){
    printf("\033[32m -- STARTING ORDERED PROPERTIES TESTS! -- \033[m\n");
    printf("STARTING TEST: "); test(test_first(create_kvset_fun), "test_first()");;
    printf("STARTING TEST: "); test(test_first(create_kvset_fun), "test_last()");;
    printf("STARTING TEST: "); test(test_next(create_kvset_fun), "test_next()");;
    printf("STARTING TEST: "); test(test_previous(create_kvset_fun), "test_previous()");;
    printf("\033[32m -- ORDERED PROPERTIES TESTS COMPLETED! -- \033[m\n");
}

canonical_original_code:
void test_ordered_kvset_properties(struct kv_set *(*create_kvset_fun)()){
    printf("\033[32m -- STARTING ORDERED PROPERTIES TESTS! -- \033[m\n");
    printf("STARTING TEST: "); test(test_first(create_kvset_fun), "test_first()");;
    printf("STARTING TEST: "); test(test_first(create_kvset_fun), "test_last()");;
    printf("STARTING TEST: "); test(test_next(create_kvset_fun), "test_next()");;
    printf("STARTING TEST: "); test(test_previous(create_kvset_fun), "test_previous()");;
    printf("\033[32m -- ORDERED PROPERTIES TESTS COMPLETED! -- \033[m\n");
}


decompiled_code:
void test_unordered_kvset_properties()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void test_unordered_kvset_properties(KVSet * (*create_kvset_fun)()){
}

canonical_original_code:
void test_unordered_kvset_properties(struct kv_set *(*create_kvset_fun)()){
}


decompiled_code:
double __fastcall benchmark_put(__int64 (*a1)(void), int a2)
{
__int64 v2; // r13
void *v3; // rsp
unsigned int v4; // eax
_QWORD *v5; // rbx
_QWORD *v6; // r12
_QWORD *v7; // r14
int v8; // er15
int v9; // ebx
_QWORD v11[6]; // [rsp+0h] [rbp-30h] BYREF

v2 = a1();
v3 = alloca(8LL * a2);
v4 = time(0LL);
srand(v4);
if ( a2 <= 0 )
{
v8 = clock();
}
else
{
v5 = v11;
v6 = v11;
v7 = &v11[a2];
do
*v5++ = rand() + 1;
while ( v5 != v7 );
v8 = clock();
do
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 8))(v2, *v6++);
while ( v6 != v7 );
}
v9 = clock();
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))v2)(v2, 0LL, 0LL);
return (double)(v9 - v8);
}

canonical_decompiled_code:
double __fastcall func0(__int64 (*a1)(void), int a2)
{
__int64 v2; // r13
void *v3; // rsp
unsigned int v4; // eax
_QWORD *v5; // rbx
_QWORD *v6; // r12
_QWORD *v7; // r14
int v8; // er15
int v9; // ebx
_QWORD v11[6]; // [rsp+0h] [rbp-30h] BYREF

v2 = a1();
v3 = alloca(8LL * a2);
v4 = time(0LL);
srand(v4);
if ( a2 <= 0 )
{
v8 = clock();
}
else
{
v5 = v11;
v6 = v11;
v7 = &v11[a2];
do
*v5++ = rand() + 1;
while ( v5 != v7 );
v8 = clock();
do
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 8))(v2, *v6++);
while ( v6 != v7 );
}
v9 = clock();
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))v2)(v2, 0LL, 0LL);
return (double)(v9 - v8);
}

original_code:
double benchmark_put(KVSet * (*create_kvset_fun)(), int num_of_operations){
    int i;
    clock_t begin, end;
    double time_spent;
    KVSet * skiplist = create_kvset_fun();
    void * elements[num_of_operations];
    srand((unsigned)time(0));
    for(i = 0; i < num_of_operations; i++){
        elements[i] = (void *)(0xFFFFFFFFFFFFFFFF & (rand()+1));
    }
    begin = clock();
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.put(skiplist, elements[i]);
    }
    end = clock();
    time_spent = ((double)(end - begin));
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return time_spent;
}

canonical_original_code:
double benchmark_put(struct kv_set *(*create_kvset_fun)(), int num_of_operations){
    int i;
    long begin; long end;
    double time_spent;
    struct kv_set *skiplist = create_kvset_fun();
    void *elements[-1];
    srand((unsigned int)time(0));
    for(i = 0; i < num_of_operations; i++){
        elements[i] = (void *)(0xFFFFFFFFFFFFFFFF & (rand()+1));
    }
    begin = clock();
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.put(skiplist, elements[i]);
    }
    end = clock();
    time_spent = ((double)(end - begin));
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return time_spent;
}

variable_types: i int

variable_types: begin long

variable_types: end long

variable_types: struct kv_set { struct kv_set_functions { void (*delete_table)(struct kv_set *kv_set, void (*element_free_function)(void *context, void *element), void *context); void *(*put)(struct kv_set *set, void *key_value); int (*put_new)(struct kv_set *set, void *key_value); void *(*remove)(struct kv_set *set, void *key); void *(*lookup)(struct kv_set *set, void *key); int (*member)(struct kv_set *set, void *key); void *(*first)(struct kv_set *set); void *(*last)(struct kv_set *set); void *(*next)(struct kv_set *set, void *key); void *(*previous)(struct kv_set *set, void *key); } funs; unsigned int key_offset; void *type_specific_data; } *

variable_types:
elements
void *[-1]

return_type: double


decompiled_code:
double __fastcall benchmark_lookup(__int64 (*a1)(void), int a2)
{
__int64 v2; // r12
void *v3; // rsp
unsigned int v4; // eax
_QWORD *v5; // r13
_QWORD *v6; // rbx
_QWORD *v7; // r14
_QWORD *v8; // r15
int v9; // er15
__int64 v10; // r13
int v11; // ebx
_QWORD v13[6]; // [rsp+0h] [rbp-30h] BYREF

v2 = a1();
v3 = alloca(8LL * a2);
v4 = time(0LL);
srand(v4);
if ( a2 <= 0 )
{
v9 = clock();
}
else
{
v5 = v13;
v6 = v13;
v7 = &v13[a2];
v8 = v13;
do
*v8++ = rand() + 1;
while ( v8 != v7 );
do
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 8))(v2, *v5++);
while ( v5 != v7 );
v9 = clock();
do
{
v10 = *v6;
if ( v10 != (*(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 32))(v2, *v6) )
_assert_fail(
"elements[i] == skiplist->funs.lookup(skiplist, elements[i])",
"benchmark_kvset.c",
0x56u,
"benchmark_lookup");
++v6;
}
while ( v6 != v7 );
}
v11 = clock();
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))v2)(v2, 0LL, 0LL);
return (double)(v11 - v9);
}

canonical_decompiled_code:
double __fastcall func1(__int64 (*a1)(void), int a2)
{
__int64 v2; // r12
void *v3; // rsp
unsigned int v4; // eax
_QWORD *v5; // r13
_QWORD *v6; // rbx
_QWORD *v7; // r14
_QWORD *v8; // r15
int v9; // er15
__int64 v10; // r13
int v11; // ebx
_QWORD v13[6]; // [rsp+0h] [rbp-30h] BYREF

v2 = a1();
v3 = alloca(8LL * a2);
v4 = time(0LL);
srand(v4);
if ( a2 <= 0 )
{
v9 = clock();
}
else
{
v5 = v13;
v6 = v13;
v7 = &v13[a2];
v8 = v13;
do
*v8++ = rand() + 1;
while ( v8 != v7 );
do
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 8))(v2, *v5++);
while ( v5 != v7 );
v9 = clock();
do
{
v10 = *v6;
if ( v10 != (*(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 32))(v2, *v6) )
_assert_fail(
"elements[i] == skiplist->funs.lookup(skiplist, elements[i])",
"benchmark_kvset.c",
0x56u,
"benchmark_lookup");
++v6;
}
while ( v6 != v7 );
}
v11 = clock();
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))v2)(v2, 0LL, 0LL);
return (double)(v11 - v9);
}

original_code:
double benchmark_lookup(KVSet * (*create_kvset_fun)(), int num_of_operations){
    int i;
    clock_t begin, end;
    double time_spent;
    KVSet * skiplist = create_kvset_fun();
    void * elements[num_of_operations];
    srand((unsigned)time(0));
    for(i = 0; i < num_of_operations; i++){
        elements[i] = (void *)(0xFFFFFFFFFFFFFFFF & (rand()+1));
    }
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.put(skiplist, elements[i]);
    }
    begin = clock();
    for(i = 0; i < num_of_operations; i++){
        ((void) sizeof ((elements[i] == skiplist->funs.lookup(skiplist, elements[i])) ? 1 : 0), __extension__ ({ if (elements[i] == skiplist->funs.lookup(skiplist, elements[i])) ; else __assert_fail ("elements[i] == skiplist->funs.lookup(skiplist, elements[i])", "benchmark_kvset.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    }
    end = clock();
    time_spent = ((double)(end - begin));
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return time_spent;
}

canonical_original_code:
double benchmark_lookup(struct kv_set *(*create_kvset_fun)(), int num_of_operations){
    int i;
    long begin; long end;
    double time_spent;
    struct kv_set *skiplist = create_kvset_fun();
    void *elements[-1];
    srand((unsigned int)time(0));
    for(i = 0; i < num_of_operations; i++){
        elements[i] = (void *)(0xFFFFFFFFFFFFFFFF & (rand()+1));
    }
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.put(skiplist, elements[i]);
    }
    begin = clock();
    for(i = 0; i < num_of_operations; i++){
        ((void) sizeof ((elements[i] == skiplist->funs.lookup(skiplist, elements[i])) ? 1 : 0), __extension__ ({ if (elements[i] == skiplist->funs.lookup(skiplist, elements[i])) ; else __assert_fail ("elements[i] == skiplist->funs.lookup(skiplist, elements[i])", "benchmark_kvset.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    }
    end = clock();
    time_spent = ((double)(end - begin));
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return time_spent;
}


decompiled_code:
double __fastcall benchmark_remove(__int64 (*a1)(void), int a2)
{
__int64 v2; // r12
void *v3; // rsp
unsigned int v4; // eax
_QWORD *v5; // rbx
_QWORD *v6; // r13
_QWORD *v7; // r15
_QWORD *v8; // r14
int v9; // er14
int v10; // ebx
_QWORD v12[6]; // [rsp+0h] [rbp-30h] BYREF

v2 = a1();
v3 = alloca(8LL * a2);
v4 = time(0LL);
srand(v4);
if ( a2 <= 0 )
{
v9 = clock();
}
else
{
v5 = v12;
v6 = v12;
v7 = &v12[a2];
v8 = v12;
do
*v8++ = rand() + 1;
while ( v8 != v7 );
do
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 8))(v2, *v5++);
while ( v5 != v7 );
v9 = clock();
do
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 24))(v2, *v6++);
while ( v6 != v7 );
}
v10 = clock();
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))v2)(v2, 0LL, 0LL);
return (double)(v10 - v9);
}

original_code:
double benchmark_remove(KVSet * (*create_kvset_fun)(), int num_of_operations){
    int i;
    clock_t begin, end;
    double time_spent;
    KVSet * skiplist = create_kvset_fun();
    void * elements[num_of_operations];
    srand((unsigned)time(0));
    for(i = 0; i < num_of_operations; i++){
        elements[i] = (void *)(0xFFFFFFFFFFFFFFFF & (rand()+1));
    }
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.put(skiplist, elements[i]);
    }
    begin = clock();
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.remove(skiplist, elements[i]);
    }
    end = clock();
    time_spent = ((double)(end - begin));
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return time_spent;
}

canonical_original_code:
double benchmark_remove(struct kv_set *(*create_kvset_fun)(), int num_of_operations){
    int i;
    long begin; long end;
    double time_spent;
    struct kv_set *skiplist = create_kvset_fun();
    void *elements[-1];
    srand((unsigned int)time(0));
    for(i = 0; i < num_of_operations; i++){
        elements[i] = (void *)(0xFFFFFFFFFFFFFFFF & (rand()+1));
    }
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.put(skiplist, elements[i]);
    }
    begin = clock();
    for(i = 0; i < num_of_operations; i++){
        skiplist->funs.remove(skiplist, elements[i]);
    }
    end = clock();
    time_spent = ((double)(end - begin));
    skiplist->funs.delete_table(skiplist, ((void *)0), ((void *)0));
    return time_spent;
}


decompiled_code:
__int64 __fastcall get_command(int a1, int a2)
{
__int64 result; // rax

if ( a2 )
result = (unsigned __int8)bto_commands_ex[a1];
else
result = (unsigned __int8)bto_commands[a1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
__int64 result; // rax

if ( a2 )
result = (unsigned __int8)bto_commands_ex[a1];
else
result = (unsigned __int8)bto_commands[a1];
return result;
}

original_code:
char get_command(int no, int extend) {
  char cmd;
  if (extend)
    cmd = bto_commands_ex[no];
  else
    cmd = bto_commands[no];
  return cmd;
}

variable_types: no int

variable_types: extend int

variable_types: cmd char

return_type: char


decompiled_code:
__int64 __fastcall get_data_length(int a1)
{
return a1 == 0 ? 7 : 35;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return a1 == 0 ? 7 : 35;
}

original_code:
int get_data_length(int extend) {
  if (extend)
    return 35;
  else
    return 7;
}


usage

decompiled_code:
size_t usage()
{
fwrite("usage: bto_ir_cmd <option>\n", 1uLL, 0x1BuLL, stderr);
fwrite(" -r \tReceive Infrared code.\n", 1uLL, 0x23uLL, stderr);
fwrite(" -t <code>\tTransfer Infrared code.\n", 1uLL, 0x24uLL, stderr);
fwrite(" -e \tExtend Infrared code.\n", 1uLL, 0x22uLL, stderr);
fwrite(" \t Normal: 7 octets\n", 1uLL, 0x20uLL, stderr);
return fwrite(" \t Extend: 35 octets\n", 1uLL, 0x20uLL, stderr);
}

canonical_decompiled_code:
size_t func16()
{
fwrite("usage: bto_ir_cmd <option>\n", 1uLL, 0x1BuLL, stderr);
fwrite(" -r \tReceive Infrared code.\n", 1uLL, 0x23uLL, stderr);
fwrite(" -t <code>\tTransfer Infrared code.\n", 1uLL, 0x24uLL, stderr);
fwrite(" -e \tExtend Infrared code.\n", 1uLL, 0x22uLL, stderr);
fwrite(" \t Normal: 7 octets\n", 1uLL, 0x20uLL, stderr);
return fwrite(" \t Extend: 35 octets\n", 1uLL, 0x20uLL, stderr);
}

original_code:
void usage() {
  fprintf(stderr, "usage: bto_ir_cmd <option>\n");
  fprintf(stderr, "  -r       \tReceive Infrared code.\n");
  fprintf(stderr, "  -t <code>\tTransfer Infrared code.\n");
  fprintf(stderr, "  -e       \tExtend Infrared code.\n");
  fprintf(stderr, "           \t  Normal:  7 octets\n");
  fprintf(stderr, "           \t  Extend: 35 octets\n");
}


decompiled_code:
double __fastcall parse_lat(__int64 a1)
{
double result; // xmm0_8
float v2; // [rsp+8h] [rbp-10h] BYREF
int v3; // [rsp+Ch] [rbp-Ch] BYREF

result = 0.0;
if ( (unsigned int)_isoc99_sscanf(a1, "%2i%f", &v3, &v2) == 2 )
result = v2 / 60.0 + (double)v3;
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
double result; // xmm0_8
float v2; // [rsp+8h] [rbp-10h] BYREF
int v3; // [rsp+Ch] [rbp-Ch] BYREF

result = 0.0;
if ( (unsigned int)_isoc99_sscanf(a1, "%2i%f", &v3, &v2) == 2 )
result = v2 / 60.0 + (double)v3;
return result;
}

original_code:
double parse_lat(char *str)
{
        int deg;
        float min;
        int ret;
        ret = sscanf(str, "%2i%f", &deg, &min);
        if (ret != 2)
                return 0;
        return deg + (min / 60.0);
}

variable_types:
str
char *

variable_types: deg int

variable_types: min float

variable_types: ret int


decompiled_code:
double __fastcall parse_lon(__int64 a1)
{
double result; // xmm0_8
float v2; // [rsp+8h] [rbp-10h] BYREF
int v3; // [rsp+Ch] [rbp-Ch] BYREF

result = 0.0;
if ( (unsigned int)_isoc99_sscanf(a1, "%3i%f", &v3, &v2) == 2 )
result = v2 / 60.0 + (double)v3;
return result;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
double result; // xmm0_8
float v2; // [rsp+8h] [rbp-10h] BYREF
int v3; // [rsp+Ch] [rbp-Ch] BYREF

result = 0.0;
if ( (unsigned int)_isoc99_sscanf(a1, "%3i%f", &v3, &v2) == 2 )
result = v2 / 60.0 + (double)v3;
return result;
}

original_code:
double parse_lon(char *str)
{
        int deg;
        float min;
        int ret;
        ret = sscanf(str, "%3i%f", &deg, &min);
        if (ret != 2)
                return 0;
        return deg + (min / 60.0);
}


original_code:
int valid_checksum(char *str)
{
        char *ptr = str;
        unsigned char c_cksum = 0;
        unsigned char r_cksum;
        if (str[0] != '$')
                return 0;
        str++;
        for (ptr = str; *ptr && (*ptr != '*'); ptr++)
                c_cksum ^= *ptr;
        sscanf(ptr, "*%02hhx", &r_cksum);
        return c_cksum == r_cksum;
}

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall parse_gga(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // r12
int v4; // ebp
char *v5; // rax
char *v6; // rbx

v2 = strchr(a2, 44);
if ( v2 )
{
v3 = v2;
*v2 = 0;
v4 = 0;
while ( 1 )
{
++v4;
v5 = strchr(v3 + 1, 44);
v6 = v5;
if ( !v5 )
break;
*v5 = 0;
switch ( v4 )
{
case 1:
*(_QWORD *)(a1 + 48) = atoi(v3 + 1);
break;
case 2:
*(double *)a1 = parse_lat((__int64)(v3 + 1));
break;
case 3:
if ( v3[1] == 83 )
*(_QWORD *)a1 ^= LC5;
break;
case 4:
*(double *)(a1 + 8) = parse_lon((__int64)(v3 + 1));
break;
case 5:
if ( v3[1] == 87 )
*(_QWORD *)(a1 + 8) ^= LC5;
break;
case 6:
*(_DWORD *)(a1 + 40) = atoi(v3 + 1);
break;
case 7:
*(_DWORD *)(a1 + 44) = atoi(v3 + 1);
break;
case 9:
*(double *)(a1 + 16) = atof(v3 + 1);
break;
default:
break;
}
v3 = v6;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // r12
int v4; // ebp
char *v5; // rax
char *v6; // rbx

v2 = strchr(a2, 44);
if ( v2 )
{
v3 = v2;
*v2 = 0;
v4 = 0;
while ( 1 )
{
++v4;
v5 = strchr(v3 + 1, 44);
v6 = v5;
if ( !v5 )
break;
*v5 = 0;
switch ( v4 )
{
case 1:
*(_QWORD *)(a1 + 48) = atoi(v3 + 1);
break;
case 2:
*(double *)a1 = func0((__int64)(v3 + 1));
break;
case 3:
if ( v3[1] == 83 )
*(_QWORD *)a1 ^= LC5;
break;
case 4:
*(double *)(a1 + 8) = func1((__int64)(v3 + 1));
break;
case 5:
if ( v3[1] == 87 )
*(_QWORD *)(a1 + 8) ^= LC5;
break;
case 6:
*(_DWORD *)(a1 + 40) = atoi(v3 + 1);
break;
case 7:
*(_DWORD *)(a1 + 44) = atoi(v3 + 1);
break;
case 9:
*(double *)(a1 + 16) = atof(v3 + 1);
break;
default:
break;
}
v3 = v6;
}
}
return 1LL;
}

original_code:
int parse_gga(struct posit *mypos, char *str)
{
        int num = 0;
        char *field = strchr(str, ',');
        while (str && field) {
                *field = 0;
                switch (num) {
                case 1:
                        mypos->tstamp = atoi(str);
                        break;
                case 2:
                        mypos->lat = parse_lat(str);
                        break;
                case 3:
                        if (*str == 'S')
                                mypos->lat *= -1;
                        break;
                case 4:
                        mypos->lon = parse_lon(str);
                        break;
                case 5:
                        if (*str == 'W')
                                mypos->lon *= -1;
                        break;
                case 6:
                        mypos->qual = atoi(str);
                        break;
                case 7:
                        mypos->sats = atoi(str);
                        break;
                case 9:
                        mypos->alt = atof(str);
                        break;
                }
                num++;
                str = field + 1;
                field = strchr(str, ',');
        }
        return 1;
}

variable_types: struct posit { double lat; double lon; double alt; double course; double speed; int qual; int sats; long tstamp; int dstamp; } *

variable_types: num int

variable_types:
field
char *


original_code:
int parse_rmc(struct posit *mypos, char *str)
{
        int num = 0;
        char *field = strchr(str, ',');
        while (str && field) {
                *field = 0;
                switch (num) {
                case 2:
                        if (*str != 'A')
                                return 1;
                        break;
                case 7:
                        mypos->speed = atof(str);
                        break;
                case 8:
                        mypos->course = atof(str);
                        break;
                case 9:
                        mypos->dstamp = atoi(str);
                        break;
                };
                num++;
                str = field + 1;
                field = strchr(str, ',');
        }
        return 1;
}

user_defined_types: struct posit { double lat; double lon; double alt; double course; double speed; int qual; int sats; long tstamp; int dstamp; }


decompiled_code:
__int64 __fastcall aprsis_login(int fd, const char *a2, double a3, double a4, double a5)
{
int v5; // eax
int v6; // ebx
int v7; // ebp
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v5 = asprintf(&ptr, "user %s pass -1 vers Unknown 0.00 filter r/%.0f/%.0f/%.0f\r\n", a2, a3, a4, a5);
if ( v5 < 0 )
return 4294967284LL;
v6 = v5;
v7 = write(fd, ptr, v5);
free(ptr);
return 5 * (unsigned int)(v6 == v7) - 5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, const char *a2, double a3, double a4, double a5)
{
int v5; // eax
int v6; // ebx
int v7; // ebp
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v5 = asprintf(&ptr, "user %s pass -1 vers Unknown 0.00 filter r/%.0f/%.0f/%.0f\r\n", a2, a3, a4, a5);
if ( v5 < 0 )
return 4294967284LL;
v6 = v5;
v7 = write(fd, ptr, v5);
free(ptr);
return 5 * (unsigned int)(v6 == v7) - 5;
}

original_code:
static int aprsis_login(int fd, const char *call,
                        double lat, double lon, double range)
{
        char *buf;
        int ret, len;
        len = asprintf(&buf, "user %s pass -1 vers Unknown 0.00 filter r/%.0f/%.0f/%.0f\r\n",
                       call, lat, lon, range);
        if (len < 0)
                return -12;
        ret = write(fd, buf, len);
        free(buf);
        if (ret != len)
                return -5;
        else
                return 0;
}

canonical_original_code:
static int aprsis_login(int fd, char *call, double lat, double lon, double range)
{
        char *buf;
        int ret; int len;
        len = asprintf(&buf, "user %s pass -1 vers Unknown 0.00 filter r/%.0f/%.0f/%.0f\r\n",
                       call, lat, lon, range);
        if (len < 0)
                return -12;
        ret = write(fd, buf, len);
        free(buf);
        if (ret != len)
                return -5;
        else
                return 0;
}

variable_types: fd int

variable_types:
call
char *

variable_types: lat double

variable_types: lon double

variable_types: range double

variable_types:
buf
char *

variable_types: len int


decompiled_code:
__int64 __fastcall aprsis_connect(const char *a1, __int16 a2, const char *a3, double a4, double a5, double a6)
{
struct hostent *v7; // rax
int v8; // eax
unsigned int v9; // ebx
int v10; // er15
struct sockaddr v12; // [rsp+0h] [rbp-48h] BYREF

v7 = gethostbyname(a1);
if ( !v7 )
return (unsigned int)-101;
if ( v7->h_length <= 0 )
return (unsigned int)-101;
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = **(_DWORD **)v7->h_addr_list;
*(_WORD *)v12.sa_data = _bswap_16(a2);
v8 = socket(2, 1, 0);
v9 = v8;
if ( v8 >= 0 )
{
v10 = connect(v8, &v12, 0x10u);
if ( v10 < 0 || (v10 = aprsis_login(v9, a3, a4, a5, a6), v10 < 0) || (puts("Connected"), v10) )
{
close(v9);
v9 = v10;
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int16 a2, const char *a3, double a4, double a5, double a6)
{
struct hostent *v7; // rax
int v8; // eax
unsigned int v9; // ebx
int v10; // er15
struct sockaddr v12; // [rsp+0h] [rbp-48h] BYREF

v7 = gethostbyname(a1);
if ( !v7 )
return (unsigned int)-101;
if ( v7->h_length <= 0 )
return (unsigned int)-101;
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = **(_DWORD **)v7->h_addr_list;
*(_WORD *)v12.sa_data = func0(a2);
v8 = socket(2, 1, 0);
v9 = v8;
if ( v8 >= 0 )
{
v10 = connect(v8, &v12, 0x10u);
if ( v10 < 0 || (v10 = func1(v9, a3, a4, a5, a6), v10 < 0) || (puts("Connected"), v10) )
{
close(v9);
v9 = v10;
}
}
return v9;
}

original_code:
int aprsis_connect(const char *hostname, int port, const char *mycall,
                   double lat, double lon, double range)
{
        int sock;
        struct sockaddr_in sa;
        struct hostent *he;
        int ret;
        he = gethostbyname(hostname);
        if (!he || (he->h_length < 1))
                return -101;
        sa.sin_family = 2;
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(sa.sin_addr));
        sa.sin_port = htons(port);
        sock = socket(2, SOCK_STREAM, 0);
        if (sock < 0)
                return sock;
        ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
        if (ret < 0)
                goto out;
        ret = aprsis_login(sock, mycall, lat, lon, range);
        if (ret < 0)
                goto out;
        printf("Connected\n");
 out:
        if (ret) {
                close(sock);
                return ret;
        }
        return sock;
}

canonical_original_code:
int aprsis_connect(char *hostname, int port, char *mycall, double lat, double lon, double range)
{
        int sock;
        struct sockaddr_in sa;
        struct hostent *he;
        int ret;
        he = gethostbyname(hostname);
        if (!he || (he->h_length < 1))
                return -101;
        sa.sin_family = 2;
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(sa.sin_addr));
        sa.sin_port = htons(port);
        sock = socket(2, SOCK_STREAM, 0);
        if (sock < 0)
                return sock;
        ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
        if (ret < 0)
                goto out;
        ret = aprsis_login(sock, mycall, lat, lon, range);
        if (ret < 0)
                goto out;
        printf("Connected\n");
 out:
        if (ret) {
                close(sock);
                return ret;
        }
        return sock;
}

variable_types:
hostname
char *

variable_types: port int

variable_types:
mycall
char *

variable_types: sock int

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]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall get_packet_text(int fd, _BYTE *a2, unsigned int *a3)
{
unsigned int v4; // er14
unsigned int v5; // ebp
int v6; // eax
char v7; // dl

*a2 = 0;
v4 = *a3;
if ( *a3 )
{
v5 = 0;
v4 = 0;
do
{
v6 = read(fd, &a2[v5], 1uLL);
v7 = a2[v5];
if ( v6 == 1 )
{
++v5;
}
else if ( !v6 )
{
break;
}
v4 = v5;
}
while ( *a3 > v5 && v7 != 10 );
}
else
{
v5 = 0;
v7 = 0;
}
*a3 = v4;
return ((int)v5 > 0) & (unsigned __int8)(v7 == 10);
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, _BYTE *a2, unsigned int *a3)
{
unsigned int v4; // er14
unsigned int v5; // ebp
int v6; // eax
char v7; // dl

*a2 = 0;
v4 = *a3;
if ( *a3 )
{
v5 = 0;
v4 = 0;
do
{
v6 = read(fd, &a2[v5], 1uLL);
v7 = a2[v5];
if ( v6 == 1 )
{
++v5;
}
else if ( !v6 )
{
break;
}
v4 = v5;
}
while ( *a3 > v5 && v7 != 10 );
}
else
{
v5 = 0;
v7 = 0;
}
*a3 = v4;
return ((int)v5 > 0) & (unsigned __int8)(v7 == 10);
}

original_code:
int get_packet_text(int fd, char *buffer, unsigned int *len)
{
        int i = 0;
        char last = '\0';
        buffer[i] = '\0';
        while ((i < *len) && (last != '\n')) {
                int ret;
                ret = read(fd, &buffer[i], 1);
                last = buffer[i];
                if (ret == 1)
                        i++;
                else if (ret == 0)
                        break;
        }
        *len = i;
        return (i > 0) && (last == '\n');
}

variable_types:
buffer
char *

variable_types:
len
unsigned int *

variable_types: i int

variable_types: last char

variable_types: ret int


decompiled_code:
__int64 __fastcall ui_connect(struct sockaddr *addr, socklen_t len)
{
int v2; // eax
unsigned int v3; // ebx

v2 = socket(addr->sa_family, 1, 0);
if ( v2 < 0 )
{
perror("socket");
v3 = -*__errno_location();
}
else
{
v3 = v2;
if ( connect(v2, addr, len) )
{
perror("connect");
close(v3);
v3 = -*__errno_location();
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(struct sockaddr *addr, socklen_t len)
{
int v2; // eax
unsigned int v3; // ebx

v2 = socket(addr->sa_family, 1, 0);
if ( v2 < 0 )
{
perror("socket");
v3 = -*__errno_location();
}
else
{
v3 = v2;
if ( connect(v2, addr, len) )
{
perror("connect");
close(v3);
v3 = -*__errno_location();
}
}
return v3;
}

original_code:
int ui_connect(struct sockaddr *dest, unsigned int dest_len)
{
        int sock;
        sock = socket(dest->sa_family, SOCK_STREAM, 0);
        if (sock < 0) {
                perror("socket");
                return -(*__errno_location ());
        }
        if (connect(sock, dest, dest_len)) {
                perror("connect");
                close(sock);
                return -(*__errno_location ());
        }
        return sock;
}

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


decompiled_code:
__int64 __fastcall ui_send(int a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // ebp
size_t v6; // r15
_WORD *v7; // rax
_WORD *v8; // rbx
unsigned __int16 v9; // bp
unsigned __int16 v10; // r12
unsigned int v11; // ebp

v4 = strlen(a2);
v5 = v4 + strlen(a3) + 10;
v6 = v5;
v7 = malloc(v5);
if ( !v7 )
return (unsigned int)-12;
v8 = v7;
*v7 = 0;
v7[1] = v5;
v9 = strlen(a2) + 1;
v8[2] = v9;
v10 = strlen(a3) + 1;
v8[3] = v10;
memcpy(v8 + 4, a2, v9);
memcpy((char *)v8 + v9 + 8, a3, v10);
v11 = send(a1, v8, v6, 0x4000);
free(v8);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // ebp
size_t v6; // r15
_WORD *v7; // rax
_WORD *v8; // rbx
unsigned __int16 v9; // bp
unsigned __int16 v10; // r12
unsigned int v11; // ebp

v4 = strlen(a2);
v5 = v4 + strlen(a3) + 10;
v6 = v5;
v7 = malloc(v5);
if ( !v7 )
return (unsigned int)-12;
v8 = v7;
*v7 = 0;
v7[1] = v5;
v9 = strlen(a2) + 1;
v8[2] = v9;
v10 = strlen(a3) + 1;
v8[3] = v10;
memcpy(v8 + 4, a2, v9);
memcpy((char *)v8 + v9 + 8, a3, v10);
v11 = send(a1, v8, v6, 0x4000);
free(v8);
return v11;
}

original_code:
int ui_send(int sock, const char *name, const char *value)
{
        int ret;
        int len;
        int offset;
        struct ui_msg *msg;
        len = sizeof(*msg) + strlen(name) + strlen(value) + 2;
        msg = malloc(len);
        if (!msg)
                return -12;
        msg->type = MSG_SETVALUE;
        msg->length = len;
        msg->name_value.name_len = strlen(name) + 1;
        msg->name_value.valu_len = strlen(value) + 1;
        offset = sizeof(*msg);
        memcpy((char*)msg + offset, name, msg->name_value.name_len);
        offset += msg->name_value.name_len;
        memcpy((char*)msg + offset, value, msg->name_value.valu_len);
        ret = send(sock, msg, len, MSG_NOSIGNAL);
        free(msg);
        return ret;
}

canonical_original_code:
int ui_send(int sock, char *name, char *value)
{
        int ret;
        int len;
        int offset;
        struct ui_msg *msg;
        len = sizeof(*msg) + strlen(name) + strlen(value) + 2;
        msg = malloc(len);
        if (!msg)
                return -12;
        msg->type = MSG_SETVALUE;
        msg->length = len;
        msg->name_value.name_len = strlen(name) + 1;
        msg->name_value.valu_len = strlen(value) + 1;
        offset = sizeof(*msg);
        memcpy((char *)msg + offset, name, msg->name_value.name_len);
        offset += msg->name_value.name_len;
        memcpy((char *)msg + offset, value, msg->name_value.valu_len);
        ret = send(sock, msg, len, MSG_NOSIGNAL);
        free(msg);
        return ret;
}

variable_types:
name
char *

variable_types:
value
char *

variable_types: offset int

variable_types: struct ui_msg { unsigned short type; unsigned short length; union { struct { unsigned short name_len; unsigned short valu_len; } name_value; }; } *


decompiled_code:
__int64 __fastcall ui_send_to(struct sockaddr *a1, socklen_t a2, const char *a3, const char *a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // ebp

if ( !*a3 )
return (unsigned int)-22;
v6 = ui_connect(a1, a2);
v7 = v6;
if ( v6 >= 0 )
{
v8 = ui_send(v6, a3, a4);
close(v7);
v7 = v8;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func10(struct sockaddr *a1, socklen_t a2, const char *a3, const char *a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // ebp

if ( !*a3 )
return (unsigned int)-22;
v6 = func8(a1, a2);
v7 = v6;
if ( v6 >= 0 )
{
v8 = func9(v6, a3, a4);
close(v7);
v7 = v8;
}
return v7;
}

original_code:
int ui_send_to(struct sockaddr *dest, unsigned int dest_len,
               const char *name, const char *value)
{
        int sock;
        int ret;
        if (strlen(name) == 0)
                return -22;
        sock = ui_connect(dest, dest_len);
        if (sock < 0)
                return sock;
        ret = ui_send(sock, name, value);
        close(sock);
        return ret;
}

canonical_original_code:
int ui_send_to(struct sockaddr *dest, unsigned int dest_len, char *name, char *value)
{
        int sock;
        int ret;
        if (strlen(name) == 0)
                return -22;
        sock = ui_connect(dest, dest_len);
        if (sock < 0)
                return sock;
        ret = ui_send(sock, name, value);
        close(sock);
        return ret;
}


decompiled_code:
__int64 __fastcall ui_get_msg(int fd, _QWORD *a2)
{
int v2; // edx
__int64 v3; // r12
_QWORD *v4; // rax
__int64 buf; // [rsp+8h] [rbp-20h] BYREF

v2 = read(fd, &buf, 8uLL);
if ( v2 > 0 )
{
v3 = WORD1(buf);
v4 = malloc(WORD1(buf));
*a2 = v4;
if ( v4 )
{
*v4 = buf;
read(fd, v4 + 1, v3 - 8);
v2 = 1;
}
else
{
v2 = -12;
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, _QWORD *a2)
{
int v2; // edx
__int64 v3; // r12
_QWORD *v4; // rax
__int64 buf; // [rsp+8h] [rbp-20h] BYREF

v2 = read(fd, &buf, 8uLL);
if ( v2 > 0 )
{
v3 = WORD1(buf);
v4 = malloc(WORD1(buf));
*a2 = v4;
if ( v4 )
{
*v4 = buf;
read(fd, v4 + 1, v3 - 8);
v2 = 1;
}
else
{
v2 = -12;
}
}
return (unsigned int)v2;
}

original_code:
int ui_get_msg(int sock, struct ui_msg **msg)
{
        struct ui_msg hdr;
        int ret;
        ret = read(sock, &hdr, sizeof(hdr));
        if (ret <= 0)
                return ret;
        *msg = malloc(hdr.length);
        if (!*msg)
                return -12;
        memcpy(*msg, &hdr, sizeof(hdr));
        ret = read(sock, ((char *)*msg)+sizeof(hdr), hdr.length - sizeof(hdr));
        return 1;
}

variable_types: struct ui_msg { unsigned short type; unsigned short length; union { struct { unsigned short name_len; unsigned short valu_len; } name_value; }; } **


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

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
if ( (unsigned __int8)(result - 32) > 0x5Eu && (_BYTE)result != 13 && (_BYTE)result != 10 )
*a1 = 32;
++a1;
}
return result;
}

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

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
if ( (unsigned __int8)(result - 32) > 0x5Eu && (_BYTE)result != 13 && (_BYTE)result != 10 )
*a1 = 32;
++a1;
}
return result;
}

original_code:
void filter_to_ascii(char *string)
{
        int i;
        for (i = 0; string[i]; i++) {
                if ((string[i] < 0x20 || string[i] > 0x7E) &&
                    (string[i] != '\r' && string[i] != '\n'))
                        string[i] = ' ';
        }
}

variable_types:
string
char *


decompiled_code:
__int64 __fastcall ui_get_msg_valu(_WORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( !*a1 )
{
filter_to_ascii((_BYTE *)a1 + (unsigned __int16)a1[2] + 8);
result = (__int64)a1 + (unsigned __int16)a1[2] + 8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_WORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( !*a1 )
{
func12((_BYTE *)a1 + (unsigned __int16)a1[2] + 8);
result = (__int64)a1 + (unsigned __int16)a1[2] + 8;
}
return result;
}

original_code:
char *ui_get_msg_valu(struct ui_msg *msg)
{
        if (msg->type != MSG_SETVALUE)
                return ((void *)0);
        filter_to_ascii((char *)msg + sizeof(*msg) + msg->name_value.name_len);
        return (char*)msg + sizeof(*msg) + msg->name_value.name_len;
}

canonical_original_code:
char *ui_get_msg_valu(struct ui_msg *msg)
{
        if (msg->type != MSG_SETVALUE)
                return ((void *)0);
        filter_to_ascii((char *)msg + sizeof(*msg) + msg->name_value.name_len);
        return (char *)msg + sizeof(*msg) + msg->name_value.name_len;
}

return_type: char *

user_defined_types: struct ui_msg { unsigned short type; unsigned short length; union { struct { unsigned short name_len; unsigned short valu_len; } name_value; }; }


decompiled_code:
__int64 __fastcall ui_send_default(const char *a1, const char *a2)
{
__int64 result; // rax
struct sockaddr v3[8]; // [rsp+0h] [rbp-88h] BYREF

if ( getenv("INET") )
{
v3[0].sa_family = 2;
*(_WORD *)v3[0].sa_data = _bswap_16(9123);
*(_DWORD *)&v3[0].sa_data[2] = 2130706433;
result = ui_send_to(v3, 0x10u, a1, a2);
}
else
{
v3[0].sa_family = 1;
strcpy(v3[0].sa_data, "/tmp/KK7DS_UI");
result = ui_send_to(v3, 0x6Eu, a1, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, const char *a2)
{
__int64 result; // rax
struct sockaddr v3[8]; // [rsp+0h] [rbp-88h] BYREF

if ( getenv("INET") )
{
v3[0].sa_family = 2;
*(_WORD *)v3[0].sa_data = func7(9123);
*(_DWORD *)&v3[0].sa_data[2] = 2130706433;
result = func10(v3, 0x10u, a1, a2);
}
else
{
v3[0].sa_family = 1;
strcpy(v3[0].sa_data, "/tmp/KK7DS_UI");
result = func10(v3, 0x6Eu, a1, a2);
}
return result;
}

original_code:
int ui_send_default(const char *name, const char *value)
{
        if (getenv("INET")) {
                struct sockaddr_in sin;
                sin.sin_family = 2;
                sin.sin_port = htons(9123);
                sin.sin_addr.s_addr = 0x7F000001;
                return ui_send_to((struct sockaddr *)&sin, sizeof(sin),
                                  name, value);
        } else {
                struct sockaddr_un sun;
                sun.sun_family = 1;
                strcpy(sun.sun_path, "/tmp/KK7DS_UI");
                return ui_send_to((struct sockaddr *)&sun, sizeof(sun),
                                  name, value);
        }
}

canonical_original_code:
int ui_send_default(char *name, char *value)
{
        if (getenv("INET")) {
                struct sockaddr_in sin;
                sin.sin_family = 2;
                sin.sin_port = htons(9123);
                sin.sin_addr.s_addr = 0x7F000001;
                return ui_send_to((struct sockaddr *)&sin, sizeof(sin),
                                  name, value);
        } else {
                struct sockaddr_un sun;
                sun.sun_family = 1;
                strcpy(sun.sun_path, "/tmp/KK7DS_UI");
                return ui_send_to((struct sockaddr *)&sun, sizeof(sun),
                                  name, value);
        }
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 3 )
return ui_send_default(argv[1], argv[2]);
printf("Usage: %s [NAME] [VALUE]\n", *argv);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 3 )
return func14(argv[1], argv[2]);
printf("Usage: %s [NAME] [VALUE]\n", *argv);
return 1;
}

original_code:
int main(int argc, char **argv)
{
        if (argc != 3) {
                printf("Usage: %s [NAME] [VALUE]\n", argv[0]);
                return 1;
        }
        return ui_send_default(argv[1], argv[2]);
}

variable_types: argc int

variable_types:
argv
char **


checksum

decompiled_code:
char *__fastcall checksum(__int64 a1)
{
char v1; // al
_BYTE *v2; // rdx
unsigned __int8 v3; // cl

v1 = *(_BYTE *)(a1 + 1);
if ( v1 )
{
v2 = (_BYTE *)(a1 + 1);
v3 = 0;
do
{
v3 ^= v1;
v1 = *++v2;
}
while ( *v2 );
}
else
{
v3 = 0;
}
sprintf(csstr_0, "*%02hhX", v3);
return csstr_0;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
char v1; // al
_BYTE *v2; // rdx
unsigned __int8 v3; // cl

v1 = *(_BYTE *)(a1 + 1);
if ( v1 )
{
v2 = (_BYTE *)(a1 + 1);
v3 = 0;
do
{
v3 ^= v1;
v1 = *++v2;
}
while ( *v2 );
}
else
{
v3 = 0;
}
sprintf(csstr_0, "*%02hhX", v3);
return csstr_0;
}

original_code:
char *checksum(const char *str)
{
        unsigned char cs = 0;
        const char *ptr;
        static char csstr[4];
        for (ptr = str+1; *ptr; ptr++)
                cs ^= *ptr;
        sprintf(csstr, "*%02hhX", cs % 256);
        return csstr;
}

canonical_original_code:
char *checksum(char *str)
{
        unsigned char cs = 0;
        char *ptr;
        static char csstr[4];
        for (ptr = str+1; *ptr; ptr++)
                cs ^= *ptr;
        sprintf(csstr, "*%02hhX", cs % 256);
        return csstr;
}

variable_types:
str
char *

variable_types:
cs
unsigned char

variable_types:
ptr
char *

variable_types:
csstr
char [4]


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
__int64 v4[3]; // [rsp+0h] [rbp-28h] BYREF
double v5; // [rsp+18h] [rbp-10h]

v4[0] = 0x4046C33333333333LL;
v4[1] = 0x405EBAA64C2F837BLL;
v4[2] = 0x404B800000000000LL;
v5 = 123.0;
make_gga(_bss_start, (double *)v4);
make_rmc(_bss_start, (double *)v4);
fflush(0LL);
sleep(1u);
for ( i = -15; ; ++i )
{
make_gga(_bss_start, (double *)v4);
make_rmc(_bss_start, (double *)v4);
fflush(0LL);
sleep(1u);
if ( i <= 2 )
v5 = v5 + 10.0;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
__int64 v4[3]; // [rsp+0h] [rbp-28h] BYREF
double v5; // [rsp+18h] [rbp-10h]

v4[0] = 0x4046C33333333333LL;
v4[1] = 0x405EBAA64C2F837BLL;
v4[2] = 0x404B800000000000LL;
v5 = 123.0;
func8(_bss_start, (double *)v4);
func9(_bss_start, (double *)v4);
fflush(0LL);
sleep(1u);
for ( i = -15; ; ++i )
{
func8(_bss_start, (double *)v4);
func9(_bss_start, (double *)v4);
fflush(0LL);
sleep(1u);
if ( i <= 2 )
v5 = v5 + 10.0;
}
}

variable_types: struct pos { double lat; double lon; double speed; double course; }

variable_types: i int


repo: kkopiec/kamikaze

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
int v5; // ebp
void *v6; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

printf("executing");
v3 = open("Kamikaze_Client", 2);
v4 = open("Kamikaze_Server", 2);
v5 = v4;
if ( v3 < 0 && v4 < 0 )
{
perror("aider of pipes open\n");
exit(1);
}
v6 = malloc(0xAuLL);
read(v3, v6, 0xAuLL);
buf[0] = 32;
close(v3);
write(v5, buf, 1uLL);
close(v5);
return 1;
}

original_code:
int main(int argc, char **argv)
{
  printf("executing");
 int i = 0;
 int pv = atoi(argv[1]);
 int file_server, file_client;
 char str[256];
 char *buf;
 file_client = open("Kamikaze_Client",02 );
 file_server = open("Kamikaze_Server",02);
 if((file_client <0)&&(file_server<0))
   {
     perror("aider of pipes open\n");
     exit(1);
}
 buf = malloc(10*sizeof(char));
    read(file_client,buf,10*sizeof(char));
 char blank = ' ';
 close(file_client);
 write(file_server,&blank, 1);
 close(file_server);
 return 1;
 }

canonical_original_code:
int main(int argc, char **argv)
{
  printf("executing");
 int i = 0;
 int pv = atoi(argv[1]);
 int file_server; int file_client;
 char str[256];
 char *buf;
 file_client = open("Kamikaze_Client",02 );
 file_server = open("Kamikaze_Server",02);
 if((file_client <0)&&(file_server<0))
   {
     perror("aider of pipes open\n");
     exit(1);
}
 buf = malloc(10*sizeof(char));
    read(file_client,buf,10*sizeof(char));
 char blank = ' ';
 close(file_client);
 write(file_server,&blank, 1);
 close(file_server);
 return 1;
 }

variable_types: pv int

variable_types:
str
char [256]

variable_types:
buf
char *

variable_types: blank char


closeSerialLine

decompiled_code:
__int64 closeSerialLine()
{
close(fds);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
close(fds);
return 0LL;
}

original_code:
int closeSerialLine()
{
  close(fds);
  return 0;
}


decompiled_code:
ssize_t __fastcall serialport_write(int fd, void *buf)
{
int v2; // ebx
ssize_t result; // rax

v2 = strlen((const char *)buf);
result = write(fd, buf, v2);
if ( v2 != (_DWORD)result )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, void *buf)
{
int v2; // ebx
ssize_t result; // rax

v2 = strlen((const char *)buf);
result = write(fd, buf, v2);
if ( v2 != (_DWORD)result )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int serialport_write(int fd, unsigned char* buf)
{
    int len = strlen(buf);
    int n = write(fd, buf, len);
    if( n!=len )
        return -1;
    return n;
}

canonical_original_code:
int serialport_write(int fd, unsigned char *buf)
{
    int len = strlen(buf);
    int n = write(fd, buf, len);
    if( n!=len )
        return -1;
    return n;
}

variable_types: fd int

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: n int


sendToArduino

decompiled_code:
__int64 __fastcall sendToArduino(void *buf)
{
return (unsigned int)-((unsigned int)serialport_write(fds, buf) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf)
{
return (unsigned int)-((unsigned int)func1(fds, buf) == -1);
}

original_code:
int sendToArduino(unsigned char* buffer)
{
  int rc;
  rc = serialport_write(fds, buffer);
  if(rc==-1) return -1;
  return 0;
}

canonical_original_code:
int sendToArduino(unsigned char *buffer)
{
  int rc;
  rc = serialport_write(fds, buffer);
  if(rc==-1) return -1;
  return 0;
}

variable_types:
buffer
unsigned char *

variable_types: rc int


decompiled_code:
__int64 __fastcall serialport_init(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
speed_t v4; // ebp
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 258);
v3 = v2;
if ( v2 == -1 )
{
perror("Port could not be opened");
return v3;
}
if ( tcgetattr(v2, &v6) < 0 )
{
perror("Couldn't get term attributes");
return (unsigned int)-1;
}
if ( a2 == 38400 )
{
v4 = 15;
}
else if ( a2 > 38400 )
{
v4 = 4097;
if ( a2 != 57600 )
{
if ( a2 != 115200 )
{
LABEL_8:
v4 = a2;
goto LABEL_14;
}
v4 = 4098;
}
}
else
{
v4 = 13;
if ( a2 != 9600 )
{
v4 = 14;
if ( a2 != 19200 )
{
v4 = 12;
if ( a2 != 4800 )
goto LABEL_8;
}
}
}
LABEL_14:
cfsetispeed(&v6, v4);
cfsetospeed(&v6, v4);
*(_QWORD *)&v6.c_cflag = __PAIR64__(v6.c_lflag, v6.c_cflag & 0x7FFFFE8F | 0x8B0) & 0xFFFFFFE4FFFFFFFFLL;
v6.c_iflag &= 0xFFFFE3FF;
v6.c_oflag &= 0xFFFFFFFE;
v6.c_cc[6] = 0;
v6.c_cc[5] = 20;
if ( tcsetattr(v3, 0, &v6) < 0 )
{
perror("Couldn't set term attributes");
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
speed_t v4; // ebp
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 258);
v3 = v2;
if ( v2 == -1 )
{
perror("Port could not be opened");
return v3;
}
if ( tcgetattr(v2, &v6) < 0 )
{
perror("Couldn't get term attributes");
return (unsigned int)-1;
}
if ( a2 == 38400 )
{
v4 = 15;
}
else if ( a2 > 38400 )
{
v4 = 4097;
if ( a2 != 57600 )
{
if ( a2 != 115200 )
{
LABEL_8:
v4 = a2;
goto LABEL_14;
}
v4 = 4098;
}
}
else
{
v4 = 13;
if ( a2 != 9600 )
{
v4 = 14;
if ( a2 != 19200 )
{
v4 = 12;
if ( a2 != 4800 )
goto LABEL_8;
}
}
}
LABEL_14:
cfsetispeed(&v6, v4);
cfsetospeed(&v6, v4);
*(_QWORD *)&v6.c_cflag = __PAIR64__(v6.c_lflag, v6.c_cflag & 0x7FFFFE8F | 0x8B0) & 0xFFFFFFE4FFFFFFFFLL;
v6.c_iflag &= 0xFFFFE3FF;
v6.c_oflag &= 0xFFFFFFFE;
v6.c_cc[6] = 0;
v6.c_cc[5] = 20;
if ( tcsetattr(v3, 0, &v6) < 0 )
{
perror("Couldn't set term attributes");
v3 = -1;
}
return v3;
}

original_code:
int serialport_init(const char* serialport, int baud)
{
    struct termios toptions;
     int fd;
 fd = open(serialport, 02 | 0400);
    if (fd == -1) {
        perror("Port could not be opened");
        return -1;
    }
    if (tcgetattr(fd, &toptions) < 0) {
        perror("Couldn't get term attributes");
        return -1;
    }
    speed_t brate = baud;
    switch(baud) {
  case 4800: brate=0000014; break;
  case 9600: brate=0000015; break;
  case 19200: brate=0000016; break;
  case 38400: brate=0000017; break;
  case 57600: brate=0010001; break;
  case 115200: brate=0010002; break;
    }
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);
    toptions.c_cflag &= ~0000400;
    toptions.c_cflag &= ~0000100;
    toptions.c_cflag &= ~0000060;
    toptions.c_cflag |= 0000060;
    toptions.c_cflag &= ~020000000000;
    toptions.c_cflag |= 0000200 | 0004000;
    toptions.c_iflag &= ~(0002000 | 0010000 | 0004000);
    toptions.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    toptions.c_oflag &= ~0000001;
    toptions.c_cc[6] = 0;
    toptions.c_cc[5] = 20;
    if( tcsetattr(fd, 0, &toptions) < 0) {
        perror("Couldn't set term attributes");
        return -1;
    }
    return fd;
}

canonical_original_code:
int serialport_init(char *serialport, int baud)
{
    struct termios toptions;
     int fd;
 fd = open(serialport, 02 | 0400);
    if (fd == -1) {
        perror("Port could not be opened");
        return -1;
    }
    if (tcgetattr(fd, &toptions) < 0) {
        perror("Couldn't get term attributes");
        return -1;
    }
    unsigned int brate = baud;
    switch(baud) {
  case 4800: brate=0000014; break;
  case 9600: brate=0000015; break;
  case 19200: brate=0000016; break;
  case 38400: brate=0000017; break;
  case 57600: brate=0010001; break;
  case 115200: brate=0010002; break;
    }
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);
    toptions.c_cflag &= ~0000400;
    toptions.c_cflag &= ~0000100;
    toptions.c_cflag &= ~0000060;
    toptions.c_cflag |= 0000060;
    toptions.c_cflag &= ~020000000000;
    toptions.c_cflag |= 0000200 | 0004000;
    toptions.c_iflag &= ~(0002000 | 0010000 | 0004000);
    toptions.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    toptions.c_oflag &= ~0000001;
    toptions.c_cc[6] = 0;
    toptions.c_cc[5] = 20;
    if( tcsetattr(fd, 0, &toptions) < 0) {
        perror("Couldn't set term attributes");
        return -1;
    }
    return fd;
}

variable_types:
serialport
char *

variable_types: baud int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types:
brate
unsigned int


initiateSerialLine

decompiled_code:
__int64 initiateSerialLine()
{
fds = 0;
fds = serialport_init("/dev/ttyACM0", 4098);
return (unsigned int)-(fds == -1);
}

canonical_decompiled_code:
__int64 func4()
{
fds = 0;
fds = func3("/dev/ttyACM0", 4098);
return (unsigned int)-(fds == -1);
}

original_code:
int initiateSerialLine()
{
  fds = 0;
  char serialport[256];
  int baudrate = 0010002;
  fds = serialport_init("/dev/ttyACM0", baudrate);
  if(fds==-1) return -1;
  return 0;
}

variable_types:
serialport
char [256]

variable_types: baudrate int


process

decompiled_code:
__int64 __fastcall process(unsigned int a1)
{
__int64 v1; // r12
void *v2; // rbp
__int64 v3; // rax

v1 = jack_port_get_buffer(input_port, a1);
v2 = malloc(0x10uLL);
*((_QWORD *)v2 + 1) = malloc(8LL * a1);
*(_DWORD *)v2 = a1;
*((_DWORD *)v2 + 1) = jack_get_sample_rate(client);
if ( a1 )
{
v3 = 0LL;
do
{
*(_QWORD *)(*((_QWORD *)v2 + 1) + v3) = *(_QWORD *)(v1 + v3);
v3 += 8LL;
}
while ( v3 != 8LL * a1 );
}
dataproc(v2);
free(*((void **)v2 + 1));
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 v1; // r12
void *v2; // rbp
__int64 v3; // rax

v1 = jack_port_get_buffer(input_port, a1);
v2 = malloc(0x10uLL);
*((_QWORD *)v2 + 1) = malloc(8LL * a1);
*(_DWORD *)v2 = a1;
*((_DWORD *)v2 + 1) = jack_get_sample_rate(client);
if ( a1 )
{
v3 = 0LL;
do
{
*(_QWORD *)(*((_QWORD *)v2 + 1) + v3) = *(_QWORD *)(v1 + v3);
v3 += 8LL;
}
while ( v3 != 8LL * a1 );
}
dataproc(v2);
free(*((void **)v2 + 1));
free(v2);
return 0LL;
}

original_code:
int
process (jack_nframes_t nframes, void *arg)
{
  double *in = (double *) jack_port_get_buffer (input_port, nframes);
  struct audio_stream *adata = malloc(sizeof(struct audio_stream));
  adata->audio_data = malloc(sizeof(double) * nframes);
  adata->buffer_length = nframes;
  adata->sample_rate = jack_get_sample_rate(client);
  int i;
  for ( i = 0 ; i < nframes ; i++){
    adata->audio_data[i] = (double) in[i];
  }
  (*dataproc) (adata);
  free(adata->audio_data);
  free(adata);
  return 0;
}

canonical_original_code:
int process(unsigned int nframes, void *arg)
{
  double *in = (double *) jack_port_get_buffer (input_port, nframes);
  struct audio_stream *adata = malloc(sizeof(struct audio_stream));
  adata->audio_data = malloc(sizeof(double) * nframes);
  adata->buffer_length = nframes;
  adata->sample_rate = jack_get_sample_rate(client);
  int i;
  for ( i = 0 ; i < nframes ; i++){
    adata->audio_data[i] = (double) in[i];
  }
  (*dataproc) (adata);
  free(adata->audio_data);
  free(adata);
  return 0;
}

variable_types:
nframes
unsigned int

variable_types:
arg
void *

variable_types:
in
double *

variable_types: struct audio_stream { unsigned int buffer_length; unsigned int sample_rate; double *audio_data; } *

variable_types: i int


decompiled_code:
void __noreturn jack_shutdown()
{
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
exit(1);
}

original_code:
void
jack_shutdown(void *arg)
{
  exit(1);
}


decompiled_code:
__int64 mic_grab()
{
__int64 v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rax
__int64 result; // rax

v0 = jack_get_ports(client, 0LL, 0LL, 6LL);
if ( !v0 )
{
fwrite("Cannot find phisical capture ports!\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v1 = (_QWORD *)v0;
v2 = jack_port_name(input_port);
result = jack_connect(client, *v1, v2);
if ( (_DWORD)result )
{
fwrite("Cannot connect input ports!\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rax
__int64 result; // rax

v0 = jack_get_ports(client, 0LL, 0LL, 6LL);
if ( !v0 )
{
fwrite("Cannot find phisical capture ports!\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v1 = (_QWORD *)v0;
v2 = jack_port_name(input_port);
result = jack_connect(client, *v1, v2);
if ( (_DWORD)result )
{
fwrite("Cannot connect input ports!\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
return result;
}

original_code:
void mic_grab()
{
  const char **ports;
  if ((ports = jack_get_ports(client, ((void *)0), ((void *)0), JackPortIsPhysical|JackPortIsOutput)) == ((void *)0)){
    fprintf(stderr, "Cannot find phisical capture ports!\n");
    exit(1);
  }
  if (jack_connect(client, ports[0], jack_port_name(input_port))){
    fprintf(stderr,"Cannot connect input ports!\n");
    exit(1);
  }
}

canonical_original_code:
void mic_grab()
{
  char **ports;
  if ((ports = jack_get_ports(client, ((void *)0), ((void *)0), JackPortIsPhysical|JackPortIsOutput)) == ((void *)0)){
    fprintf(stderr, "Cannot find phisical capture ports!\n");
    exit(1);
  }
  if (jack_connect(client, ports[0], jack_port_name(input_port))){
    fprintf(stderr,"Cannot connect input ports!\n");
    exit(1);
  }
}

variable_types:
ports
char **


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

dataproc = a1;
v1 = jack_client_open("kamikaze", 0LL, 0LL);
client = v1;
if ( v1 )
{
jack_set_process_callback(v1, process, 0LL);
jack_on_shutdown(client, jack_shutdown, 0LL);
input_port = jack_port_register(client, "mic", "32 bit float mono audio", 1LL, 0LL);
if ( (unsigned int)jack_activate(client) )
{
fwrite("cannot activate client!\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
result = mic_grab();
}
else
{
fwrite("jack server not running?/nOr maybe should try this as root?/n", 1uLL, 0x3DuLL, stderr);
result = 1LL;
}
return result;
}

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

dataproc = a1;
v1 = jack_client_open("kamikaze", 0LL, 0LL);
client = v1;
if ( v1 )
{
jack_set_process_callback(v1, process, 0LL);
jack_on_shutdown(client, jack_shutdown, 0LL);
input_port = jack_port_register(client, "mic", "32 bit float mono audio", 1LL, 0LL);
if ( (unsigned int)jack_activate(client) )
{
fwrite("cannot activate client!\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
result = func2();
}
else
{
fwrite("jack server not running?/nOr maybe should try this as root?/n", 1uLL, 0x3DuLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
mic_setup( void (*dpf)(struct audio_stream*) )
{
  dataproc = dpf;
  if ((client = jack_client_open("kamikaze", JackNullOption,((void *)0))) == ((void *)0)){
    fprintf(stderr, "jack server not running?/nOr maybe should try this as root?/n");
    return 1;
  }
  jack_set_process_callback(client, process, 0);
  jack_on_shutdown(client, jack_shutdown,0);
  input_port = jack_port_register(client, "mic", "32 bit float mono audio", JackPortIsInput,0);
  if (jack_activate(client)){
    fprintf(stderr, "cannot activate client!\n");
    exit(1);
  }
  mic_grab();
}

canonical_original_code:
int mic_setup(void (*dpf)(struct audio_stream *))
{
  dataproc = dpf;
  if ((client = jack_client_open("kamikaze", JackNullOption,((void *)0))) == ((void *)0)){
    fprintf(stderr, "jack server not running?/nOr maybe should try this as root?/n");
    return 1;
  }
  jack_set_process_callback(client, process, 0);
  jack_on_shutdown(client, jack_shutdown,0);
  input_port = jack_port_register(client, "mic", "32 bit float mono audio", JackPortIsInput,0);
  if (jack_activate(client)){
    fprintf(stderr, "cannot activate client!\n");
    exit(1);
  }
  mic_grab();
}

variable_types: void (*)(struct audio_stream { unsigned int buffer_length; unsigned int sample_rate; double *audio_data; } *)


readCommand

decompiled_code:
int __fastcall readCommand(const char *a1, const char *a2)
{
int v2; // ebx
int v3; // ebp
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = open(a1, 2);
v3 = open(a2, 2);
if ( v2 <= 0 )
fwrite("Error: cannot open server pipe\n", 1uLL, 0x1FuLL, stderr);
if ( (unsigned int)read(v2, buf, 4uLL) == 4 )
{
cmdnr = buf[0];
write(v3, "OK", 5uLL);
}
close(v2);
return close(v3);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
int v2; // ebx
int v3; // ebp
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = open(a1, 2);
v3 = open(a2, 2);
if ( v2 <= 0 )
fwrite("Error: cannot open server pipe\n", 1uLL, 0x1FuLL, stderr);
if ( (unsigned int)read(v2, buf, 4uLL) == 4 )
{
cmdnr = buf[0];
write(v3, "OK", 5uLL);
}
close(v2);
return close(v3);
}

original_code:
void
readCommand(const char* pipeServer, const char *pipeClient)
{
  int fifo_s, fifo_c;
  char* buf;
  int command;
  fifo_s = open(pipeServer, 02);
  fifo_c = open(pipeClient, 02);
  if (fifo_s < 1){
    fprintf(stderr, "Error: cannot open server pipe\n");
    exit -1;
  }
  if (read(fifo_s, &command, sizeof(int)) == sizeof(int)){
    cmdnr = command;
    buf="OK";
    write(fifo_c,buf,5*sizeof(char));
  }
  close(fifo_s);
  close(fifo_c);
}

canonical_original_code:
void readCommand(char *pipeServer, char *pipeClient)
{
  int fifo_s; int fifo_c;
  char *buf;
  int command;
  fifo_s = open(pipeServer, 02);
  fifo_c = open(pipeClient, 02);
  if (fifo_s < 1){
    fprintf(stderr, "Error: cannot open server pipe\n");
    exit -1;
  }
  if (read(fifo_s, &command, sizeof(int)) == sizeof(int)){
    cmdnr = command;
    buf="OK";
    write(fifo_c,buf,5*sizeof(char));
  }
  close(fifo_s);
  close(fifo_c);
}

variable_types:
pipeServer
char *

variable_types:
pipeClient
char *

variable_types:
buf
char *

variable_types: command int


decompiled_code:
void __fastcall apply_window(__int64 a1, int a2)
{
__int64 i; // rax

if ( window_len_2 != a2 )
{
window_len_2 = a2;
if ( a2 > 40960 )
{
printf("%s : datalen > MAX_HEIGHT\n", "apply_window");
exit(1);
}
calc_kaiser_window(window_0, 20.0);
}
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
*(double *)(a1 + 8 * i) = *(double *)(a1 + 8 * i) * window_0[i];
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
__int64 i; // rax

if ( window_len_2 != a2 )
{
window_len_2 = a2;
if ( a2 > 40960 )
{
printf("%s : datalen > MAX_HEIGHT\n", "apply_window");
exit(1);
}
calc_kaiser_window(window_0, 20.0);
}
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
*(double *)(a1 + 8 * i) = *(double *)(a1 + 8 * i) * window_0[i];
}
}

original_code:
void
apply_window (double * data, int datalen)
{
  static double window [10 * 4096] ;
  static int window_len = 0 ;
  int k ;
  if (window_len != datalen)
    {
      window_len = datalen ;
      if (datalen > ((int) (sizeof (window) / sizeof (window [0]))))
 {
   printf ("%s : datalen >  MAX_HEIGHT\n", __func__) ;
   exit (1) ;
 } ;
      calc_kaiser_window (window, datalen, 20.0) ;
    } ;
  for (k = 0 ; k < datalen ; k++)
    data [k] *= window [k] ;
  return ;
}

canonical_original_code:
void apply_window(double *data, int datalen)
{
  static double window[-1];
  static int window_len = 0;
  int k;
  if (window_len != datalen)
    {
      window_len = datalen ;
      if (datalen > ((int) (sizeof (window) / sizeof (window [0]))))
 {
   printf ("%s : datalen >  MAX_HEIGHT\n", __func__) ;
   exit (1) ;
 } ;
      calc_kaiser_window (window, datalen, 20.0) ;
    } ;
  for (k = 0 ; k < datalen ; k++)
    data [k] *= window [k] ;
  return ;
}

variable_types:
data
double *

variable_types: datalen int

variable_types:
window
double [-1]

variable_types: k int


decompiled_code:
void *__fastcall fftw_setup(int a1)
{
void *result; // rax

in = malloc(8LL * a1);
result = malloc(8LL * a1);
out = result;
fft_set = 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(int a1)
{
void *result; // rax

in = malloc(8LL * a1);
result = malloc(8LL * a1);
out = result;
fft_set = 1;
return result;
}

original_code:
void
fftw_setup(int length)
{
  int N = length;
  in = malloc(sizeof(double) * N);
  out = malloc(sizeof(double) * N);
  fft_set = 1;
}

variable_types: length int

variable_types: N int


getfreq

decompiled_code:
__int64 __fastcall getfreq(void *src, void *a2, int a3)
{
if ( !fft_set )
fftw_setup(a3);
plan = fftw_plan_r2r_1d((unsigned int)a3, src, a2, 0LL, 0LL);
memcpy(in, src, a3);
fftw_execute(plan);
memcpy(out, a2, a3);
fftw_destroy_plan(plan);
return (unsigned int)(2 * a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, void *a2, int a3)
{
if ( !fft_set )
func2(a3);
plan = fftw_plan_r2r_1d((unsigned int)a3, src, a2, 0LL, 0LL);
memcpy(in, src, a3);
fftw_execute(plan);
memcpy(out, a2, a3);
fftw_destroy_plan(plan);
return (unsigned int)(2 * a3);
}

original_code:
int
getfreq(double *sin, double* sout, int length)
{
  if (!fft_set)
    fftw_setup(length);
  plan = fftw_plan_r2r_1d (length , sin, sout, FFTW_R2HC, (0U)) ;
  memcpy(in, sin, length);
  fftw_execute(plan);
  memcpy(out, sout, length);
  fftw_destroy_plan (plan);
  return length * 2;
}

canonical_original_code:
int getfreq(double *sin, double *sout, int length)
{
  if (!fft_set)
    fftw_setup(length);
  plan = fftw_plan_r2r_1d (length , sin, sout, FFTW_R2HC, (0U)) ;
  memcpy(in, sin, length);
  fftw_execute(plan);
  memcpy(out, sout, length);
  fftw_destroy_plan (plan);
  return length * 2;
}

variable_types:
sin
double *

variable_types:
sout
double *


decompiled_code:
void fft_clean()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void
fft_clean()
{
  if (fft_set)
    ;
}

canonical_original_code:
void fft_clean()
{
  if (fft_set)
    ;
}


factorial

decompiled_code:
double __fastcall factorial(int a1)
{
__int64 v1; // rax

if ( a1 < 0 )
{
puts("Oops : val < 0.");
exit(1);
}
if ( a1 > 64 )
{
puts("Oops : val > ARRAY_LEN (memory).");
exit(1);
}
v1 = 1LL;
if ( a1 > 0 )
{
do
{
memory_2[v1] = (double)(int)v1 * *(double *)(8 * v1 + 0x558);
++v1;
}
while ( v1 != a1 + 1 );
}
return memory_2[a1];
}

canonical_decompiled_code:
double __fastcall func0(int a1)
{
__int64 v1; // rax

if ( a1 < 0 )
{
puts("Oops : val < 0.");
exit(1);
}
if ( a1 > 64 )
{
puts("Oops : val > ARRAY_LEN (memory).");
exit(1);
}
v1 = 1LL;
if ( a1 > 0 )
{
do
{
memory_2[v1] = (double)(int)v1 * *(double *)(8 * v1 + 0x558);
++v1;
}
while ( v1 != a1 + 1 );
}
return memory_2[a1];
}

original_code:
static double
factorial (int val)
{ static double memory [64] = { 1.0 } ;
 static int have_entry = 0 ;
 int k ;
 if (val < 0)
 { printf ("Oops : val < 0.\n") ;
  exit (1) ;
  } ;
 if (val > ((int) (sizeof (memory) / sizeof (memory [0]))))
 { printf ("Oops : val > ARRAY_LEN (memory).\n") ;
  exit (1) ;
  } ;
 if (val < have_entry)
  return memory [val] ;
 for (k = have_entry + 1 ; k <= val ; k++)
  memory [k] = k * memory [k - 1] ;
 return memory [val] ;
}

canonical_original_code:
static double factorial(int val)
{ static double memory[64] = { 1.0 };
 static int have_entry = 0;
 int k;
 if (val < 0)
 { printf ("Oops : val < 0.\n") ;
  exit (1) ;
  } ;
 if (val > ((int) (sizeof (memory) / sizeof (memory [0]))))
 { printf ("Oops : val > ARRAY_LEN (memory).\n") ;
  exit (1) ;
  } ;
 if (val < have_entry)
  return memory [val] ;
 for (k = have_entry + 1 ; k <= val ; k++)
  memory [k] = k * memory [k - 1] ;
 return memory [val] ;
}

variable_types: val int

variable_types:
memory
double [64]


decompiled_code:
double __fastcall besseli0(double a1)
{
double v1; // r14
int i; // ebp
double v3; // rbx
double v4; // xmm1_8
double v5; // xmm0_8
double v7; // [rsp+8h] [rbp-20h]

v1 = a1 * 0.5;
v7 = 0.0;
for ( i = 1; i != 25; ++i )
{
v3 = pow(v1, (double)i);
v4 = factorial(i);
v5 = v3 / v4 * (v3 / v4) + v7;
v7 = v5;
}
return v5 + 1.0;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
double v1; // r14
int i; // ebp
double v3; // rbx
double v4; // xmm1_8
double v5; // xmm0_8
double v7; // [rsp+8h] [rbp-20h]

v1 = a1 * 0.5;
v7 = 0.0;
for ( i = 1; i != 25; ++i )
{
v3 = pow(v1, (double)i);
v4 = func0(i);
v5 = v3 / v4 * (v3 / v4) + v7;
v7 = v5;
}
return v5 + 1.0;
}

original_code:
static double
besseli0 (double x)
{
 int k ;
 double result = 0.0 ;
 for (k = 1 ; k < 25 ; k++)
 { double temp ;
  temp = pow (0.5 * x, k) / factorial (k) ;
  result += temp * temp ;
  } ;
 return 1.0 + result ;
}

canonical_original_code:
static double besseli0(double x)
{
 int k;
 double result = 0.0;
 for (k = 1 ; k < 25 ; k++)
 { double temp;
  temp = pow (0.5 * x, k) / factorial (k) ;
  result += temp * temp ;
  } ;
 return 1.0 + result ;
}

variable_types: x double

variable_types: result double

variable_types: temp double


decompiled_code:
void __fastcall calc_kaiser_window(__int64 a1, int a2, double a3)
{
double v3; // xmm0_8
__int64 i; // rbx
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // [rsp+0h] [rbp-38h]

v3 = besseli0(a3);
v8 = v3;
if ( COERCE_DOUBLE(*(_QWORD *)&v3 & LC5) > 1.797693134862316e308 )
{
printf("besseli0 (%f) : %f\nExiting\n", a3, v3);
exit(1);
}
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(double *)(a1 + 8 * i++) = besseli0(v7 * a3) / v8 )
{
v5 = ((double)(int)i + 0.5 - (double)a2 * 0.5 + (double)(int)i + 0.5 - (double)a2 * 0.5) / (double)a2;
v6 = 1.0 - v5 * v5;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2, double a3)
{
double v3; // xmm0_8
__int64 i; // rbx
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // [rsp+0h] [rbp-38h]

v3 = func1(a3);
v8 = v3;
if ( COERCE_DOUBLE(*(_QWORD *)&v3 & LC5) > 1.797693134862316e308 )
{
printf("besseli0 (%f) : %f\nExiting\n", a3, v3);
exit(1);
}
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(double *)(a1 + 8 * i++) = func1(v7 * a3) / v8 )
{
v5 = ((double)(int)i + 0.5 - (double)a2 * 0.5 + (double)(int)i + 0.5 - (double)a2 * 0.5) / (double)a2;
v6 = 1.0 - v5 * v5;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
}
}
}

original_code:
void
calc_kaiser_window (double * data, int datalen, double beta)
{
 double two_n_on_N, denom ;
 int k ;
 denom = besseli0 (beta) ;
 if (! __builtin_isfinite (denom))
 { printf ("besseli0 (%f) : %f\nExiting\n", beta, denom) ;
  exit (1) ;
  } ;
 for (k = 0 ; k < datalen ; k++)
 { double n = k + 0.5 - 0.5 * datalen ;
  two_n_on_N = (2.0 * n) / datalen ;
  data [k] = besseli0 (beta * sqrt (1.0 - two_n_on_N * two_n_on_N)) / denom ;
  } ;
 return ;
}

canonical_original_code:
void calc_kaiser_window(double *data, int datalen, double beta)
{
 double two_n_on_N; double denom;
 int k;
 denom = besseli0 (beta) ;
 if (! __builtin_isfinite (denom))
 { printf ("besseli0 (%f) : %f\nExiting\n", beta, denom) ;
  exit (1) ;
  } ;
 for (k = 0 ; k < datalen ; k++)
 { double n = k + 0.5 - 0.5 * datalen;
  two_n_on_N = (2.0 * n) / datalen ;
  data [k] = besseli0 (beta * sqrt (1.0 - two_n_on_N * two_n_on_N)) / denom ;
  } ;
 return ;
}

variable_types: beta double

variable_types: denom double

variable_types: n double


variable_types:
a
double [4]

variable_types: scale double


decompiled_code:
__int64 __fastcall get_bit(int *a1, unsigned int a2, int a3, int a4)
{
__int64 v6; // r12
int v7; // ebp
int v8; // ebx
int v9; // ecx

v6 = *((_QWORD *)a1 + 2);
v7 = *a1;
v8 = a1[1];
v9 = a1[2];
if ( v9 < (int)a2 )
fprintf(
stderr,
"Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n",
a2,
(unsigned int)(v9 - 1));
return (unsigned int)*(char *)(v6 + (int)(a4 * v7 + a3 + v7 * a2 * v8));
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, unsigned int a2, int a3, int a4)
{
__int64 v6; // r12
int v7; // ebp
int v8; // ebx
int v9; // ecx

v6 = *((_QWORD *)a1 + 2);
v7 = *a1;
v8 = a1[1];
v9 = a1[2];
if ( v9 < (int)a2 )
fprintf(
stderr,
"Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n",
a2,
(unsigned int)(v9 - 1));
return (unsigned int)*(char *)(v6 + (int)(a4 * v7 + a3 + v7 * a2 * v8));
}

original_code:
int
get_bit(struct image *img, int frame, int w, int h)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  if (frame > imf){
    fprintf(stderr, "Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n", frame, imf -1);
    exit -1;
  }
  int pn;
  pn = (frame * ih * iw) + ((h*iw) +w);
  return (int)data[pn];
}

variable_types: struct image { int width; int height; int frames; char *imgdata; } *

variable_types: frame int

variable_types: w int

variable_types: h int

variable_types:
data
char *

variable_types: iw int

variable_types: ih int

variable_types: imf int

variable_types: pn int


rshift

original_code:
void
rshift(struct image *img)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  int fr_length = ih * iw;
  memmove(data + fr_length, data, (imf-1)* fr_length*sizeof(char));
  memset(data, 0, fr_length * sizeof(char));
  return;
}

user_defined_types: struct image { int width; int height; int frames; char *imgdata; }


decompiled_code:
int __fastcall clear_column(int *a1, unsigned int a2, int a3)
{
int v4; // ebx
signed int v5; // ecx
int result; // eax

v4 = a1[1];
v5 = a1[2];
if ( v5 < (int)a2 )
result = fprintf(
stderr,
"Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n",
a2,
(unsigned int)(v5 - 1));
if ( v4 >= 0 )
{
do
result = set_bit(a1, a2, a3, v4--, 0);
while ( v4 != -1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int *a1, unsigned int a2, int a3)
{
int v4; // ebx
signed int v5; // ecx
int result; // eax

v4 = a1[1];
v5 = a1[2];
if ( v5 < (int)a2 )
result = fprintf(
stderr,
"Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n",
a2,
(unsigned int)(v5 - 1));
if ( v4 >= 0 )
{
do
result = func0(a1, a2, a3, v4--, 0);
while ( v4 != -1 );
}
return result;
}

original_code:
void
clear_column (struct image *img, int frame, int w)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  if (frame > imf){
    fprintf(stderr, "Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n", frame, imf -1);
    exit -1;
  }
  int h = ih;
  while (h >= 0){
    set_bit(img,frame,w,h,0);
    h-=1;
  }
  return;
}

canonical_original_code:
void clear_column(struct image *img, int frame, int w)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  if (frame > imf){
    fprintf(stderr, "Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n", frame, imf -1);
    exit -1;
  }
  int h = ih;
  while (h >= 0){
    set_bit(img,frame,w,h,0);
    h-=1;
  }
  return;
}


decompiled_code:
int __fastcall set_column(int *a1, unsigned int a2, int a3, int a4)
{
signed int v6; // ecx
int result; // eax

v6 = a1[2];
if ( v6 < (int)a2 )
result = fprintf(
stderr,
"Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n",
a2,
(unsigned int)(v6 - 1));
if ( a4 >= 0 )
{
do
result = set_bit(a1, a2, a3, a4--, 1);
while ( a4 != -1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int *a1, unsigned int a2, int a3, int a4)
{
signed int v6; // ecx
int result; // eax

v6 = a1[2];
if ( v6 < (int)a2 )
result = fprintf(
stderr,
"Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n",
a2,
(unsigned int)(v6 - 1));
if ( a4 >= 0 )
{
do
result = func0(a1, a2, a3, a4--, 1);
while ( a4 != -1 );
}
return result;
}

original_code:
void
set_column (struct image *img, int frame, int w, int h)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  if (frame > imf){
    fprintf(stderr, "Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n", frame, imf -1);
    exit -1;
  }
  while (h >= 0){
    set_bit(img,frame,w,h,1);
    h-=1;
  }
  return;
}

canonical_original_code:
void set_column(struct image *img, int frame, int w, int h)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  if (frame > imf){
    fprintf(stderr, "Error: out of bounds. Trying to write to the frame no: %d but the last frame is %d\n", frame, imf -1);
    exit -1;
  }
  while (h >= 0){
    set_bit(img,frame,w,h,1);
    h-=1;
  }
  return;
}


testimgdisplay

decompiled_code:
int __fastcall testimgdisplay(int *a1)
{
int v1; // er12
int result; // eax
int v3; // er15
int v4; // er13
int v5; // ebx
unsigned int v6; // ebp
int v7; // [rsp+Ch] [rbp-3Ch]

v1 = *a1;
result = a1[1];
v7 = result;
v3 = a1[2];
v4 = 0;
if ( result > 0 )
{
do
{
v6 = 0;
if ( v3 > 0 )
{
do
{
v5 = 0;
if ( v1 > 0 )
{
do
{
if ( (unsigned int)get_bit(a1, v6, v5, v4) )
putchar(88);
else
putchar(32);
++v5;
}
while ( v1 != v5 );
}
printf(" | ");
++v6;
}
while ( v3 != v6 );
}
result = putchar(10);
++v4;
}
while ( v7 != v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int *a1)
{
int v1; // er12
int result; // eax
int v3; // er15
int v4; // er13
int v5; // ebx
unsigned int v6; // ebp
int v7; // [rsp+Ch] [rbp-3Ch]

v1 = *a1;
result = a1[1];
v7 = result;
v3 = a1[2];
v4 = 0;
if ( result > 0 )
{
do
{
v6 = 0;
if ( v3 > 0 )
{
do
{
v5 = 0;
if ( v1 > 0 )
{
do
{
if ( (unsigned int)func1(a1, v6, v5, v4) )
putchar(88);
else
putchar(32);
++v5;
}
while ( v1 != v5 );
}
printf(" | ");
++v6;
}
while ( v3 != v6 );
}
result = putchar(10);
++v4;
}
while ( v7 != v4 );
}
return result;
}

original_code:
void
testimgdisplay(struct image *img)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  int row, col, slate;
  for(row = 0; row < ih; row++){
    for(slate = 0; slate < imf; slate++){
      for(col = 0; col < iw; col++){
 int c = get_bit(img,slate,col,row);
 if(c != 0){
   printf("X");
 } else
   {
     printf(" ");
   }
      }
      printf(" | ");
    }
    printf("\n");
  }
  return;
}

canonical_original_code:
void testimgdisplay(struct image *img)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  int row; int col; int slate;
  for(row = 0; row < ih; row++){
    for(slate = 0; slate < imf; slate++){
      for(col = 0; col < iw; col++){
 int c = get_bit(img,slate,col,row);
 if(c != 0){
   printf("X");
 } else
   {
     printf(" ");
   }
      }
      printf(" | ");
    }
    printf("\n");
  }
  return;
}

variable_types: row int

variable_types: col int

variable_types: slate int

variable_types: c int


dshifttop

decompiled_code:
void __fastcall dshifttop(int *a1)
{
int v1; // er14
int v2; // er15
unsigned int v3; // er12
int v4; // ebp
int v5; // ebx

v1 = *a1;
v2 = a1[2];
v3 = 0;
if ( v2 > 0 )
{
do
{
v4 = 0;
if ( v1 > 0 )
{
do
{
v5 = 7;
while ( !(unsigned int)get_bit(a1, v3, v4, v5) )
{
if ( !--v5 )
goto LABEL_4;
}
set_bit(a1, v3, v4, v5, 0);
LABEL_4:
++v4;
}
while ( v1 != v4 );
}
++v3;
}
while ( v2 != v3 );
}
}

canonical_decompiled_code:
void __fastcall func6(int *a1)
{
int v1; // er14
int v2; // er15
unsigned int v3; // er12
int v4; // ebp
int v5; // ebx

v1 = *a1;
v2 = a1[2];
v3 = 0;
if ( v2 > 0 )
{
do
{
v4 = 0;
if ( v1 > 0 )
{
do
{
v5 = 7;
while ( !(unsigned int)func1(a1, v3, v4, v5) )
{
if ( !--v5 )
goto LABEL_4;
}
func0(a1, v3, v4, v5, 0);
LABEL_4:
++v4;
}
while ( v1 != v4 );
}
++v3;
}
while ( v2 != v3 );
}
}

original_code:
void
dshifttop (struct image* img)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  int bufsize = iw*ih*imf;
  int w,h;
  int frame,col,row;
  for (frame = 0; frame < imf; frame++){
    for(col = 0; col < iw; col++){
      for(row = 7; row > 0 ; row--){
 int c;
 if((c= get_bit(img, frame,col,row)) != 0){
     set_bit(img, frame, col,row,0);
     break;
   }
      }
    }
  }
  return;
}

canonical_original_code:
void dshifttop(struct image *img)
{
  char *data = img->imgdata;
  int iw = img->width;
  int ih = img->height;
  int imf = img->frames;
  int bufsize = iw*ih*imf;
  int w; int h;
  int frame; int col; int row;
  for (frame = 0; frame < imf; frame++){
    for(col = 0; col < iw; col++){
      for(row = 7; row > 0 ; row--){
 int c;
 if((c= get_bit(img, frame,col,row)) != 0){
     set_bit(img, frame, col,row,0);
     break;
   }
      }
    }
  }
  return;
}

variable_types: bufsize int


fallingEdge

decompiled_code:
__int64 __fastcall fallingEdge(__int64 a1, int *a2)
{
unsigned int i; // ebx
__int64 result; // rax

dshifttop();
rshift(a1);
for ( i = 0; i != 8; ++i )
{
if ( *a2 < 0 )
{
*a2 = 0;
}
else if ( *a2 > 7 )
{
*a2 = 7;
}
clear_column(a1, 0LL, i);
result = set_column(a1, 0LL, i, (unsigned int)*a2++);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2)
{
unsigned int i; // ebx
__int64 result; // rax

dshifttop();
rshift(a1);
for ( i = 0; i != 8; ++i )
{
if ( *a2 < 0 )
{
*a2 = 0;
}
else if ( *a2 > 7 )
{
*a2 = 7;
}
clear_column(a1, 0LL, i);
result = set_column(a1, 0LL, i, (unsigned int)*a2++);
}
return result;
}

original_code:
void
fallingEdge(struct image *img, int *mag, int size)
{
  dshifttop(img);
  rshift(img);
  int i;
  for(i = 0 ; i < 8 ; i++){
    if(mag[i] <0)
      mag[i] = 0;
    if(mag[i] >7)
      mag[i] = 7;
    clear_column(img,0,i);
    set_column(img,0,i,mag[i]);
  }
  return;
}

variable_types:
mag
int *

variable_types: size int

variable_types: i int


plainDb

decompiled_code:
__int64 __fastcall plainDb(__int64 a1, int *a2)
{
unsigned int i; // ebx
__int64 result; // rax

rshift(a1);
for ( i = 0; i != 8; ++i )
{
if ( *a2 < 0 )
{
*a2 = 0;
}
else if ( *a2 > 7 )
{
*a2 = 7;
}
clear_column(a1, 0LL, i);
result = set_column(a1, 0LL, i, (unsigned int)*a2++);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2)
{
unsigned int i; // ebx
__int64 result; // rax

rshift(a1);
for ( i = 0; i != 8; ++i )
{
if ( *a2 < 0 )
{
*a2 = 0;
}
else if ( *a2 > 7 )
{
*a2 = 7;
}
clear_column(a1, 0LL, i);
result = set_column(a1, 0LL, i, (unsigned int)*a2++);
}
return result;
}

original_code:
void
plainDb(struct image *img, int *mag, int size)
{
  rshift(img);
  int i;
  for(i = 0 ; i < 8 ; i++){
    if(mag[i] <0)
      mag[i] = 0;
    if(mag[i] >7)
      mag[i] = 7;
    clear_column(img,0,i);
    set_column(img,0,i,mag[i]);
  }
  return;
}

variable_types: struct image { int width; int height; int frames; char *imgdata; } *


openSerial

decompiled_code:
__int64 __fastcall openSerial(const char *a1)
{
int v1; // eax

v1 = open(a1, 2306);
fdsl = v1;
if ( v1 == -1 )
{
fprintf(stderr, "cannoct open serial line %s\n", a1);
exit(-1);
}
fcntl(v1, 4, 0LL);
if ( tcgetattr(fdsl, &tty) < 0 )
{
fwrite("Cannot read port attributes!\n", 1uLL, 0x1DuLL, stderr);
close(fdsl);
exit(-1);
}
*(__m128i *)&orig_tty.c_iflag = _mm_load_si128((const __m128i *)&tty);
*(__m128i *)&orig_tty.c_line = _mm_load_si128((const __m128i *)&tty.c_line);
*(__m128i *)&orig_tty.c_cc[15] = _mm_load_si128((const __m128i *)&tty.c_cc[15]);
*(_QWORD *)&orig_tty.c_cc[31] = *(_QWORD *)&tty.c_cc[31];
orig_tty.c_ospeed = tty.c_ospeed;
cfmakeraw(&tty);
if ( cfsetospeed(&tty, 0x1002u) == -1 )
{
fwrite("cannot set desired speed of the line\n", 1uLL, 0x25uLL, stderr);
close(fdsl);
exit(-1);
}
if ( tcsetattr(fdsl, 2, &tty) < 0 )
{
fprintf(stderr, "Cannot set raw terminal on %s\n", a1);
close(fdsl);
exit(-1);
}
sleep(1u);
return (unsigned int)fdsl;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // eax

v1 = open(a1, 2306);
fdsl = v1;
if ( v1 == -1 )
{
fprintf(stderr, "cannoct open serial line %s\n", a1);
exit(-1);
}
fcntl(v1, 4, 0LL);
if ( tcgetattr(fdsl, &tty) < 0 )
{
fwrite("Cannot read port attributes!\n", 1uLL, 0x1DuLL, stderr);
close(fdsl);
exit(-1);
}
*(__m128i *)&orig_tty.c_iflag = _mm_load_si128((const __m128i *)&tty);
*(__m128i *)&orig_tty.c_line = _mm_load_si128((const __m128i *)&tty.c_line);
*(__m128i *)&orig_tty.c_cc[15] = _mm_load_si128((const __m128i *)&tty.c_cc[15]);
*(_QWORD *)&orig_tty.c_cc[31] = *(_QWORD *)&tty.c_cc[31];
orig_tty.c_ospeed = tty.c_ospeed;
cfmakeraw(&tty);
if ( cfsetospeed(&tty, 0x1002u) == -1 )
{
fwrite("cannot set desired speed of the line\n", 1uLL, 0x25uLL, stderr);
close(fdsl);
exit(-1);
}
if ( tcsetattr(fdsl, 2, &tty) < 0 )
{
fprintf(stderr, "Cannot set raw terminal on %s\n", a1);
close(fdsl);
exit(-1);
}
sleep(1u);
return (unsigned int)fdsl;
}

original_code:
int openSerial(char* dev_path)
{
  if((fdsl = open(dev_path, 02|0400|04000)) == -1){
    fprintf(stderr, "cannoct open serial line %s\n",dev_path);
    exit(-1);
  }
  fcntl(fdsl, 4, 0);
  if ((tcgetattr(fdsl, &tty) < 0)){
    fprintf(stderr,"Cannot read port attributes!\n");
    close(fdsl);
    exit(-1);
  }
  orig_tty = tty;
  cfmakeraw(&tty);
  if((cfsetospeed (&tty, 0010002)) ==-1){
    fprintf(stderr, "cannot set desired speed of the line\n");
    close(fdsl);
    exit(-1);
  }
  if (tcsetattr(fdsl, 2, &tty) < 0){
    fprintf(stderr, "Cannot set raw terminal on %s\n",dev_path);
    close(fdsl);
    exit (-1);
  }
  sleep(1);
  return fdsl;
}

canonical_original_code:
int openSerial(char *dev_path)
{
  if((fdsl = open(dev_path, 02|0400|04000)) == -1){
    fprintf(stderr, "cannoct open serial line %s\n",dev_path);
    exit(-1);
  }
  fcntl(fdsl, 4, 0);
  if ((tcgetattr(fdsl, &tty) < 0)){
    fprintf(stderr,"Cannot read port attributes!\n");
    close(fdsl);
    exit(-1);
  }
  orig_tty = tty;
  cfmakeraw(&tty);
  if((cfsetospeed (&tty, 0010002)) ==-1){
    fprintf(stderr, "cannot set desired speed of the line\n");
    close(fdsl);
    exit(-1);
  }
  if (tcsetattr(fdsl, 2, &tty) < 0){
    fprintf(stderr, "Cannot set raw terminal on %s\n",dev_path);
    close(fdsl);
    exit (-1);
  }
  sleep(1);
  return fdsl;
}


closeSerial

decompiled_code:
int __fastcall closeSerial(int fd)
{
if ( tcsetattr(fd, 2, &orig_tty) < 0 )
{
fwrite("Cannot set back terminal on /dev/ttyACM0\n", 1uLL, 0x29uLL, stderr);
close(fdsl);
exit(-1);
}
return close(fd);
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
if ( tcsetattr(fd, 2, &orig_tty) < 0 )
{
fwrite("Cannot set back terminal on /dev/ttyACM0\n", 1uLL, 0x29uLL, stderr);
close(fdsl);
exit(-1);
}
return close(fd);
}

original_code:
void closeSerial(int dev)
{
  if (tcsetattr(dev, 2, &orig_tty) < 0){
    fprintf(stderr, "Cannot set back terminal on /dev/ttyACM0\n");
    close(fdsl);
    exit(-1);
  }
  close(dev);
}

variable_types: dev int


sendData

decompiled_code:
void __fastcall sendData(void *buf, int a2, int a3)
{
char *v3; // rbx

if ( a2 > 0 )
{
v3 = (char *)buf;
do
{
if ( (unsigned int)write(a3, v3, 8uLL) != 8 )
{
fwrite("something wrong went with writting!\n", 1uLL, 0x24uLL, stderr);
close(a3);
exit(-1);
}
v3 += 8;
}
while ( v3 != (char *)buf + 8 * ((unsigned int)(a2 - 1) >> 3) + 8 );
}
}

canonical_decompiled_code:
void __fastcall func2(void *buf, int a2, int a3)
{
char *v3; // rbx

if ( a2 > 0 )
{
v3 = (char *)buf;
do
{
if ( (unsigned int)write(a3, v3, 8uLL) != 8 )
{
fwrite("something wrong went with writting!\n", 1uLL, 0x24uLL, stderr);
close(a3);
exit(-1);
}
v3 += 8;
}
while ( v3 != (char *)buf + 8 * ((unsigned int)(a2 - 1) >> 3) + 8 );
}
}

original_code:
int sendData(unsigned char *data, int size, int dev)
{
  int g = 0;
  int w = 0;
  unsigned char *test = data;
  while(g < size){
    g+=8;
    if ((w = write(dev, test, 8)) != 8){
      fprintf(stderr, "something wrong went with writting!\n");
      close(dev);
      exit (-1);
    }
    test+=8;
  }
}

variable_types:
data
unsigned char *

variable_types: g int

variable_types: w int

variable_types:
test
unsigned char *


repo: kkpattern/CTCI

original_code:
int set_of_stacks_push(SetOfStacks *stacks, int value) {
  if (stacks->heads[stacks->current_stack] < stacks->max_stack_size) {
    int *current_stack = stacks->stacks[stacks->current_stack];
    size_t current_stack_head = stacks->heads[stacks->current_stack];
    current_stack[current_stack_head] = value;
    stacks->heads[stacks->current_stack] += 1;
  } else {
    if (stacks->current_stack >= stacks->stack_number-1) {
      size_t new_stack_number = stacks->stack_number*2;
      int **new_stacks = (int **) malloc(sizeof(int *) * new_stack_number);
      if (((void *)0) == new_stacks) return 1;
      size_t *new_heads = (size_t *) malloc(sizeof(size_t) * new_stack_number);
      if (((void *)0) == new_heads) {
        free(new_stacks);
        return 1;
      }
      memcpy(new_heads, stacks->heads, sizeof(size_t) * stacks->stack_number);
      memcpy(new_stacks, stacks->stacks, sizeof(int*) * stacks->stack_number);
      free(stacks->heads);
      free(stacks->stacks);
      stacks->stack_number = new_stack_number;
      stacks->heads = new_heads;
      stacks->stacks = new_stacks;
    }
    int *new_stack = (int *) malloc(sizeof(int) * stacks->max_stack_size);
    if (((void *)0) == new_stack) return 1;
    new_stack[0] = value;
    stacks->current_stack += 1;
    stacks->heads[stacks->current_stack] = 1;
    stacks->stacks[stacks->current_stack] = new_stack;
  }
  return 0;
}

canonical_original_code:
int set_of_stacks_push(struct _SetOfStacks *stacks, int value) {
  if (stacks->heads[stacks->current_stack] < stacks->max_stack_size) {
    int *current_stack = stacks->stacks[stacks->current_stack];
    unsigned long current_stack_head = stacks->heads[stacks->current_stack];
    current_stack[current_stack_head] = value;
    stacks->heads[stacks->current_stack] += 1;
  } else {
    if (stacks->current_stack >= stacks->stack_number-1) {
      unsigned long new_stack_number = stacks->stack_number*2;
      int **new_stacks = (int **) malloc(sizeof(int *) * new_stack_number);
      if (((void *)0) == new_stacks) return 1;
      unsigned long *new_heads = (size_t *) malloc(sizeof(size_t) * new_stack_number);
      if (((void *)0) == new_heads) {
        free(new_stacks);
        return 1;
      }
      memcpy(new_heads, stacks->heads, sizeof(unsigned long) * stacks->stack_number);
      memcpy(new_stacks, stacks->stacks, sizeof(int *) * stacks->stack_number);
      free(stacks->heads);
      free(stacks->stacks);
      stacks->stack_number = new_stack_number;
      stacks->heads = new_heads;
      stacks->stacks = new_stacks;
    }
    int *new_stack = (int *) malloc(sizeof(int) * stacks->max_stack_size);
    if (((void *)0) == new_stack) return 1;
    new_stack[0] = value;
    stacks->current_stack += 1;
    stacks->heads[stacks->current_stack] = 1;
    stacks->stacks[stacks->current_stack] = new_stack;
  }
  return 0;
}

variable_types: struct _SetOfStacks { int **stacks; unsigned long stack_number; unsigned long current_stack; unsigned long max_stack_size; unsigned long *heads; } *

variable_types: value int