repo: igorsobreira/iclib

decompiled_code:
__int64 find_should_return_matched_element_or_NULL_if_not_found()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbp
int v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tcase_fn_start("find_should_return_matched_element_or_NULL_if_not_found", "tests/check_ic_list.c", 101LL);
v5 = 20;
v6 = 23;
v7 = 43;
v8[0] = 100;
v0 = ic_list_new();
ic_list_append(v0, &v5);
ic_list_append(v0, &v6);
ic_list_append(v0, &v7);
v1 = ic_list_find(v0, &v5);
if ( !v1 )
{
ck_assert_failed("tests/check_ic_list.c", 112LL, "Assertion 'found != NULL' failed", 0LL);
goto LABEL_8;
}
v2 = v1;
mark_point("tests/check_ic_list.c", 112LL);
if ( **(_DWORD **)(v2 + 16) != v5 )
{
LABEL_8:
ck_assert_failed("tests/check_ic_list.c", 113LL, "Assertion '*(int *)found->data == num1' failed", 0LL);
goto LABEL_9;
}
mark_point("tests/check_ic_list.c", 113LL);
v3 = ic_list_find(v0, &v6);
if ( !v3 )
{
LABEL_9:
ck_assert_failed("tests/check_ic_list.c", 116LL, "Assertion 'found != NULL' failed", 0LL);
goto LABEL_10;
}
mark_point("tests/check_ic_list.c", 116LL);
if ( **(_DWORD **)(v3 + 16) != v6 )
{
LABEL_10:
ck_assert_failed("tests/check_ic_list.c", 117LL, "Assertion '*(int *)found->data == num2' failed", 0LL);
goto LABEL_11;
}
mark_point("tests/check_ic_list.c", 117LL);
if ( !ic_list_find(v0, v8) )
{
mark_point("tests/check_ic_list.c", 120LL);
return ic_list_free(v0);
}
LABEL_11:
ck_assert_failed("tests/check_ic_list.c", 120LL, "Assertion 'found == NULL' failed", 0LL);
return nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds();
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbp
int v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tcase_fn_start("find_should_return_matched_element_or_NULL_if_not_found", "tests/check_ic_list.c", 101LL);
v5 = 20;
v6 = 23;
v7 = 43;
v8[0] = 100;
v0 = ic_list_new();
ic_list_append(v0, &v5);
ic_list_append(v0, &v6);
ic_list_append(v0, &v7);
v1 = ic_list_find(v0, &v5);
if ( !v1 )
{
ck_assert_failed("tests/check_ic_list.c", 112LL, "Assertion 'found != NULL' failed", 0LL);
goto LABEL_8;
}
v2 = v1;
mark_point("tests/check_ic_list.c", 112LL);
if ( **(_DWORD **)(v2 + 16) != v5 )
{
LABEL_8:
ck_assert_failed("tests/check_ic_list.c", 113LL, "Assertion '*(int *)found->data == num1' failed", 0LL);
goto LABEL_9;
}
mark_point("tests/check_ic_list.c", 113LL);
v3 = ic_list_find(v0, &v6);
if ( !v3 )
{
LABEL_9:
ck_assert_failed("tests/check_ic_list.c", 116LL, "Assertion 'found != NULL' failed", 0LL);
goto LABEL_10;
}
mark_point("tests/check_ic_list.c", 116LL);
if ( **(_DWORD **)(v3 + 16) != v6 )
{
LABEL_10:
ck_assert_failed("tests/check_ic_list.c", 117LL, "Assertion '*(int *)found->data == num2' failed", 0LL);
goto LABEL_11;
}
mark_point("tests/check_ic_list.c", 117LL);
if ( !ic_list_find(v0, v8) )
{
mark_point("tests/check_ic_list.c", 120LL);
return ic_list_free(v0);
}
LABEL_11:
ck_assert_failed("tests/check_ic_list.c", 120LL, "Assertion 'found == NULL' failed", 0LL);
return func1();
}

original_code:
static void find_should_return_matched_element_or_NULL_if_not_found (int _i __attribute__ ((unused))){ tcase_fn_start ("""find_should_return_matched_element_or_NULL_if_not_found", "tests/check_ic_list.c", 101);
{
  int num1 = 20, num2 = 23, num3 = 43, num4 = 100;
  ic_node *found;
  ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num1);
  ic_list_append(mylist, &num2);
  ic_list_append(mylist, &num3);
  found = ic_list_find(mylist, &num1);
  (found != ((void *)0)) ? _mark_point("tests/check_ic_list.c", 112) : _ck_assert_failed("tests/check_ic_list.c", 112, "Assertion '""found != NULL""' failed", ((void *)0));
  (*(int *)found->data == num1) ? _mark_point("tests/check_ic_list.c", 113) : _ck_assert_failed("tests/check_ic_list.c", 113, "Assertion '""*(int *)found->data == num1""' failed", ((void *)0));
  found = ic_list_find(mylist, &num2);
  (found != ((void *)0)) ? _mark_point("tests/check_ic_list.c", 116) : _ck_assert_failed("tests/check_ic_list.c", 116, "Assertion '""found != NULL""' failed", ((void *)0));
  (*(int *)found->data == num2) ? _mark_point("tests/check_ic_list.c", 117) : _ck_assert_failed("tests/check_ic_list.c", 117, "Assertion '""*(int *)found->data == num2""' failed", ((void *)0));
  found = ic_list_find(mylist, &num4);
  (found == ((void *)0)) ? _mark_point("tests/check_ic_list.c", 120) : _ck_assert_failed("tests/check_ic_list.c", 120, "Assertion '""found == NULL""' failed", ((void *)0));
  ic_list_free(mylist);
}
}

canonical_original_code:
static void find_should_return_matched_element_or_NULL_if_not_found(int _i){ tcase_fn_start ("""find_should_return_matched_element_or_NULL_if_not_found", "tests/check_ic_list.c", 101);
{
  int num1 = 20; int num2 = 23; int num3 = 43; int num4 = 100;
  struct ic_node *found;
  struct ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num1);
  ic_list_append(mylist, &num2);
  ic_list_append(mylist, &num3);
  found = ic_list_find(mylist, &num1);
  (found != ((void *)0)) ? _mark_point("tests/check_ic_list.c", 112) : _ck_assert_failed("tests/check_ic_list.c", 112, "Assertion '""found != NULL""' failed", ((void *)0));
  (*(int *)found->data == num1) ? _mark_point("tests/check_ic_list.c", 113) : _ck_assert_failed("tests/check_ic_list.c", 113, "Assertion '""*(int *)found->data == num1""' failed", ((void *)0));
  found = ic_list_find(mylist, &num2);
  (found != ((void *)0)) ? _mark_point("tests/check_ic_list.c", 116) : _ck_assert_failed("tests/check_ic_list.c", 116, "Assertion '""found != NULL""' failed", ((void *)0));
  (*(int *)found->data == num2) ? _mark_point("tests/check_ic_list.c", 117) : _ck_assert_failed("tests/check_ic_list.c", 117, "Assertion '""*(int *)found->data == num2""' failed", ((void *)0));
  found = ic_list_find(mylist, &num4);
  (found == ((void *)0)) ? _mark_point("tests/check_ic_list.c", 120) : _ck_assert_failed("tests/check_ic_list.c", 120, "Assertion '""found == NULL""' failed", ((void *)0));
  ic_list_free(mylist);
}
}

variable_types: struct ic_list { struct ic_node { struct ic_node *prev; struct ic_node *next; void *data; } *head; struct ic_node *tail; unsigned long length; } *

user_defined_types: struct ic_list { struct ic_node *head; struct ic_node *tail; unsigned long length; }


decompiled_code:
__int64 nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds()
{
__int64 v0; // rbx
_DWORD *v1; // rax
_DWORD *v2; // rax
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

tcase_fn_start(
"nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds",
"tests/check_ic_list.c",
82LL);
v4 = 1;
v5[0] = 2;
v0 = ic_list_new();
ic_list_append(v0, &v4);
ic_list_append(v0, v5);
v1 = (_DWORD *)ic_list_nth_data(v0, 0LL);
if ( *v1 != v4 )
{
ck_assert_failed(
"tests/check_ic_list.c",
90LL,
"Assertion '*(int *)ic_list_nth_data(mylist, 0) == num1' failed",
0LL);
goto LABEL_7;
}
mark_point("tests/check_ic_list.c", 90LL);
v2 = (_DWORD *)ic_list_nth_data(v0, 1LL);
if ( *v2 != v5[0] )
{
LABEL_7:
ck_assert_failed(
"tests/check_ic_list.c",
91LL,
"Assertion '*(int *)ic_list_nth_data(mylist, 1) == num2' failed",
0LL);
goto LABEL_8;
}
mark_point("tests/check_ic_list.c", 91LL);
if ( ic_list_nth_data(v0, 2LL) )
{
LABEL_8:
ck_assert_failed("tests/check_ic_list.c", 92LL, "Assertion 'ic_list_nth_data(mylist, 2) == NULL' failed", 0LL);
goto LABEL_9;
}
mark_point("tests/check_ic_list.c", 92LL);
if ( !ic_list_nth_data(v0, 10LL) )
{
mark_point("tests/check_ic_list.c", 93LL);
return ic_list_free(v0);
}
LABEL_9:
ck_assert_failed("tests/check_ic_list.c", 93LL, "Assertion 'ic_list_nth_data(mylist, 10) == NULL' failed", 0LL);
return new_ic_list_should_be_empty();
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
_DWORD *v1; // rax
_DWORD *v2; // rax
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

tcase_fn_start(
"nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds",
"tests/check_ic_list.c",
82LL);
v4 = 1;
v5[0] = 2;
v0 = ic_list_new();
ic_list_append(v0, &v4);
ic_list_append(v0, v5);
v1 = (_DWORD *)ic_list_nth_data(v0, 0LL);
if ( *v1 != v4 )
{
ck_assert_failed(
"tests/check_ic_list.c",
90LL,
"Assertion '*(int *)ic_list_nth_data(mylist, 0) == num1' failed",
0LL);
goto LABEL_7;
}
mark_point("tests/check_ic_list.c", 90LL);
v2 = (_DWORD *)ic_list_nth_data(v0, 1LL);
if ( *v2 != v5[0] )
{
LABEL_7:
ck_assert_failed(
"tests/check_ic_list.c",
91LL,
"Assertion '*(int *)ic_list_nth_data(mylist, 1) == num2' failed",
0LL);
goto LABEL_8;
}
mark_point("tests/check_ic_list.c", 91LL);
if ( ic_list_nth_data(v0, 2LL) )
{
LABEL_8:
ck_assert_failed("tests/check_ic_list.c", 92LL, "Assertion 'ic_list_nth_data(mylist, 2) == NULL' failed", 0LL);
goto LABEL_9;
}
mark_point("tests/check_ic_list.c", 92LL);
if ( !ic_list_nth_data(v0, 10LL) )
{
mark_point("tests/check_ic_list.c", 93LL);
return ic_list_free(v0);
}
LABEL_9:
ck_assert_failed("tests/check_ic_list.c", 93LL, "Assertion 'ic_list_nth_data(mylist, 10) == NULL' failed", 0LL);
return func2();
}

original_code:
static void nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds (int _i __attribute__ ((unused))){ tcase_fn_start ("""nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds", "tests/check_ic_list.c", 82);
{
  int num1 = 1, num2 = 2;
  ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num1);
  ic_list_append(mylist, &num2);
  (*(int *)ic_list_nth_data(mylist, 0) == num1) ? _mark_point("tests/check_ic_list.c", 90) : _ck_assert_failed("tests/check_ic_list.c", 90, "Assertion '""*(int *)ic_list_nth_data(mylist, 0) == num1""' failed", ((void *)0));
  (*(int *)ic_list_nth_data(mylist, 1) == num2) ? _mark_point("tests/check_ic_list.c", 91) : _ck_assert_failed("tests/check_ic_list.c", 91, "Assertion '""*(int *)ic_list_nth_data(mylist, 1) == num2""' failed", ((void *)0));
  (ic_list_nth_data(mylist, 2) == ((void *)0)) ? _mark_point("tests/check_ic_list.c", 92) : _ck_assert_failed("tests/check_ic_list.c", 92, "Assertion '""ic_list_nth_data(mylist, 2) == NULL""' failed", ((void *)0));
  (ic_list_nth_data(mylist, 10) == ((void *)0)) ? _mark_point("tests/check_ic_list.c", 93) : _ck_assert_failed("tests/check_ic_list.c", 93, "Assertion '""ic_list_nth_data(mylist, 10) == NULL""' failed", ((void *)0));
  ic_list_free(mylist);
}
}

canonical_original_code:
static void nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds(int _i){ tcase_fn_start ("""nth_should_return_element_data_at_that_position_or_NULL_if_out_of_bounds", "tests/check_ic_list.c", 82);
{
  int num1 = 1; int num2 = 2;
  struct ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num1);
  ic_list_append(mylist, &num2);
  (*(int *)ic_list_nth_data(mylist, 0) == num1) ? _mark_point("tests/check_ic_list.c", 90) : _ck_assert_failed("tests/check_ic_list.c", 90, "Assertion '""*(int *)ic_list_nth_data(mylist, 0) == num1""' failed", ((void *)0));
  (*(int *)ic_list_nth_data(mylist, 1) == num2) ? _mark_point("tests/check_ic_list.c", 91) : _ck_assert_failed("tests/check_ic_list.c", 91, "Assertion '""*(int *)ic_list_nth_data(mylist, 1) == num2""' failed", ((void *)0));
  (ic_list_nth_data(mylist, 2) == ((void *)0)) ? _mark_point("tests/check_ic_list.c", 92) : _ck_assert_failed("tests/check_ic_list.c", 92, "Assertion '""ic_list_nth_data(mylist, 2) == NULL""' failed", ((void *)0));
  (ic_list_nth_data(mylist, 10) == ((void *)0)) ? _mark_point("tests/check_ic_list.c", 93) : _ck_assert_failed("tests/check_ic_list.c", 93, "Assertion '""ic_list_nth_data(mylist, 10) == NULL""' failed", ((void *)0));
  ic_list_free(mylist);
}
}

return_type: void

user_defined_types: struct ic_node { struct ic_node *prev; struct ic_node *next; void *data; }


decompiled_code:
__int64 new_ic_list_should_be_empty()
{
__int64 v0; // rbx
__int64 result; // rax

tcase_fn_start("new_ic_list_should_be_empty", "tests/check_ic_list.c", 8LL);
v0 = ic_list_new();
if ( (unsigned __int8)ic_list_empty(v0) )
{
mark_point("tests/check_ic_list.c", 11LL);
result = ic_list_free(v0);
}
else
{
ck_assert_failed(
"tests/check_ic_list.c",
11LL,
"Assertion 'ic_list_empty(mylist)' failed",
"new list should be empty");
result = assert_list_bounds();
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 result; // rax

tcase_fn_start("new_ic_list_should_be_empty", "tests/check_ic_list.c", 8LL);
v0 = ic_list_new();
if ( (unsigned __int8)ic_list_empty(v0) )
{
mark_point("tests/check_ic_list.c", 11LL);
result = ic_list_free(v0);
}
else
{
ck_assert_failed(
"tests/check_ic_list.c",
11LL,
"Assertion 'ic_list_empty(mylist)' failed",
"new list should be empty");
result = func3();
}
return result;
}

original_code:
static void new_ic_list_should_be_empty (int _i __attribute__ ((unused))){ tcase_fn_start ("""new_ic_list_should_be_empty", "tests/check_ic_list.c", 8);
{
  ic_list *mylist = ic_list_new();
  (ic_list_empty(mylist)) ? _mark_point("tests/check_ic_list.c", 11) : _ck_assert_failed("tests/check_ic_list.c", 11, "Assertion '""ic_list_empty(mylist)""' failed" , "new list should be empty", ((void *)0));
  ic_list_free(mylist);
}
}

canonical_original_code:
static void new_ic_list_should_be_empty(int _i){ tcase_fn_start ("""new_ic_list_should_be_empty", "tests/check_ic_list.c", 8);
{
  struct ic_list *mylist = ic_list_new();
  (ic_list_empty(mylist)) ? _mark_point("tests/check_ic_list.c", 11) : _ck_assert_failed("tests/check_ic_list.c", 11, "Assertion '""ic_list_empty(mylist)""' failed" , "new list should be empty", ((void *)0));
  ic_list_free(mylist);
}
}


decompiled_code:
__int64 __fastcall assert_list_bounds(__int64 a1)
{
if ( **(_QWORD **)a1 )
{
ck_assert_failed(
"tests/asserts.h",
5LL,
"Assertion 'list->head->prev == NULL' failed",
"list head's 'prev' should be NULL");
}
else
{
mark_point("tests/asserts.h", 5LL);
if ( !*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) )
return mark_point("tests/asserts.h", 6LL);
}
ck_assert_failed(
"tests/asserts.h",
6LL,
"Assertion 'list->tail->next == NULL' failed",
"list tail's 'next' should be NULL");
return assert_list_has_only_one_element();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( **(_QWORD **)a1 )
{
ck_assert_failed(
"tests/asserts.h",
5LL,
"Assertion 'list->head->prev == NULL' failed",
"list head's 'prev' should be NULL");
}
else
{
mark_point("tests/asserts.h", 5LL);
if ( !*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) )
return mark_point("tests/asserts.h", 6LL);
}
ck_assert_failed(
"tests/asserts.h",
6LL,
"Assertion 'list->tail->next == NULL' failed",
"list tail's 'next' should be NULL");
return func4();
}

original_code:
void assert_list_bounds(ic_list *list)
{
  (list->head->prev == ((void *)0)) ? _mark_point("tests/asserts.h", 5) : _ck_assert_failed("tests/asserts.h", 5, "Assertion '""list->head->prev == NULL""' failed" , "list head's 'prev' should be NULL", ((void *)0));
  (list->tail->next == ((void *)0)) ? _mark_point("tests/asserts.h", 6) : _ck_assert_failed("tests/asserts.h", 6, "Assertion '""list->tail->next == NULL""' failed" , "list tail's 'next' should be NULL", ((void *)0));
}

canonical_original_code:
void assert_list_bounds(struct ic_list *list)
{
  (list->head->prev == ((void *)0)) ? _mark_point("tests/asserts.h", 5) : _ck_assert_failed("tests/asserts.h", 5, "Assertion '""list->head->prev == NULL""' failed" , "list head's 'prev' should be NULL", ((void *)0));
  (list->tail->next == ((void *)0)) ? _mark_point("tests/asserts.h", 6) : _ck_assert_failed("tests/asserts.h", 6, "Assertion '""list->tail->next == NULL""' failed" , "list tail's 'next' should be NULL", ((void *)0));
}


decompiled_code:
__int64 __fastcall assert_list_has_only_one_element(__int64 a1, const void *a2, size_t a3)
{
const void *v4; // r13
const void *v5; // rbx

if ( ic_list_length() != 1 )
{
ck_assert_failed("tests/asserts.h", 13LL, "Assertion 'ic_list_length(list) == 1' failed", 0LL);
goto LABEL_8;
}
mark_point("tests/asserts.h", 13LL);
v4 = (const void *)ic_list_first(a1);
v5 = (const void *)ic_list_last(a1);
if ( !v4 )
{
LABEL_8:
ck_assert_failed("tests/asserts.h", 18LL, "Assertion 'head != NULL' failed", 0LL);
goto LABEL_9;
}
mark_point("tests/asserts.h", 18LL);
if ( !v5 )
{
LABEL_9:
ck_assert_failed("tests/asserts.h", 19LL, "Assertion 'tail != NULL' failed", 0LL);
goto LABEL_10;
}
mark_point("tests/asserts.h", 19LL);
if ( memcmp(a2, v4, a3) )
{
LABEL_10:
ck_assert_failed(
"tests/asserts.h",
20LL,
"Assertion 'memcmp(element, head, elem_size) == 0' failed",
"element should be head");
goto LABEL_11;
}
mark_point("tests/asserts.h", 20LL);
if ( !memcmp(a2, v5, a3) )
return mark_point("tests/asserts.h", 21LL);
LABEL_11:
ck_assert_failed(
"tests/asserts.h",
21LL,
"Assertion 'memcmp(element, tail, elem_size) == 0' failed",
"element should be tail");
return prepend_one_element_should_make_it_head_and_tail();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const void *a2, size_t a3)
{
const void *v4; // r13
const void *v5; // rbx

if ( ic_list_length() != 1 )
{
ck_assert_failed("tests/asserts.h", 13LL, "Assertion 'ic_list_length(list) == 1' failed", 0LL);
goto LABEL_8;
}
mark_point("tests/asserts.h", 13LL);
v4 = (const void *)ic_list_first(a1);
v5 = (const void *)ic_list_last(a1);
if ( !v4 )
{
LABEL_8:
ck_assert_failed("tests/asserts.h", 18LL, "Assertion 'head != NULL' failed", 0LL);
goto LABEL_9;
}
mark_point("tests/asserts.h", 18LL);
if ( !v5 )
{
LABEL_9:
ck_assert_failed("tests/asserts.h", 19LL, "Assertion 'tail != NULL' failed", 0LL);
goto LABEL_10;
}
mark_point("tests/asserts.h", 19LL);
if ( memcmp(a2, v4, a3) )
{
LABEL_10:
ck_assert_failed(
"tests/asserts.h",
20LL,
"Assertion 'memcmp(element, head, elem_size) == 0' failed",
"element should be head");
goto LABEL_11;
}
mark_point("tests/asserts.h", 20LL);
if ( !memcmp(a2, v5, a3) )
return mark_point("tests/asserts.h", 21LL);
LABEL_11:
ck_assert_failed(
"tests/asserts.h",
21LL,
"Assertion 'memcmp(element, tail, elem_size) == 0' failed",
"element should be tail");
return func5();
}

original_code:
void assert_list_has_only_one_element(ic_list *list, void *element, size_t elem_size)
{
  void *head, *tail;
  (ic_list_length(list) == 1) ? _mark_point("tests/asserts.h", 13) : _ck_assert_failed("tests/asserts.h", 13, "Assertion '""ic_list_length(list) == 1""' failed", ((void *)0));
  head = ic_list_first(list);
  tail = ic_list_last(list);
  (head != ((void *)0)) ? _mark_point("tests/asserts.h", 18) : _ck_assert_failed("tests/asserts.h", 18, "Assertion '""head != NULL""' failed", ((void *)0));
  (tail != ((void *)0)) ? _mark_point("tests/asserts.h", 19) : _ck_assert_failed("tests/asserts.h", 19, "Assertion '""tail != NULL""' failed", ((void *)0));
  (memcmp(element, head, elem_size) == 0) ? _mark_point("tests/asserts.h", 20) : _ck_assert_failed("tests/asserts.h", 20, "Assertion '""memcmp(element, head, elem_size) == 0""' failed" , "element should be head", ((void *)0));
  (memcmp(element, tail, elem_size) == 0) ? _mark_point("tests/asserts.h", 21) : _ck_assert_failed("tests/asserts.h", 21, "Assertion '""memcmp(element, tail, elem_size) == 0""' failed" , "element should be tail", ((void *)0));
}

canonical_original_code:
void assert_list_has_only_one_element(struct ic_list *list, void *element, unsigned long elem_size)
{
  void *head; void *tail;
  (ic_list_length(list) == 1) ? _mark_point("tests/asserts.h", 13) : _ck_assert_failed("tests/asserts.h", 13, "Assertion '""ic_list_length(list) == 1""' failed", ((void *)0));
  head = ic_list_first(list);
  tail = ic_list_last(list);
  (head != ((void *)0)) ? _mark_point("tests/asserts.h", 18) : _ck_assert_failed("tests/asserts.h", 18, "Assertion '""head != NULL""' failed", ((void *)0));
  (tail != ((void *)0)) ? _mark_point("tests/asserts.h", 19) : _ck_assert_failed("tests/asserts.h", 19, "Assertion '""tail != NULL""' failed", ((void *)0));
  (memcmp(element, head, elem_size) == 0) ? _mark_point("tests/asserts.h", 20) : _ck_assert_failed("tests/asserts.h", 20, "Assertion '""memcmp(element, head, elem_size) == 0""' failed" , "element should be head", ((void *)0));
  (memcmp(element, tail, elem_size) == 0) ? _mark_point("tests/asserts.h", 21) : _ck_assert_failed("tests/asserts.h", 21, "Assertion '""memcmp(element, tail, elem_size) == 0""' failed" , "element should be tail", ((void *)0));
}

variable_types:
element
void *

variable_types:
head
void *

variable_types:
tail
void *


decompiled_code:
__int64 prepend_one_element_should_make_it_head_and_tail()
{
__int64 v0; // rbx
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tcase_fn_start("prepend_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 50LL);
v2[0] = 20;
v0 = ic_list_new();
ic_list_prepend(v0, v2);
assert_list_has_only_one_element(v0, v2, 8uLL);
assert_list_bounds(v0);
return ic_list_free(v0);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tcase_fn_start("prepend_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 50LL);
v2[0] = 20;
v0 = ic_list_new();
ic_list_prepend(v0, v2);
func4(v0, v2, 8uLL);
func3(v0);
return ic_list_free(v0);
}

original_code:
static void prepend_one_element_should_make_it_head_and_tail (int _i __attribute__ ((unused))){ tcase_fn_start ("""prepend_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 50);
{
  int num = 20;
  ic_list *mylist = ic_list_new();
  ic_list_prepend(mylist, &num);
  assert_list_has_only_one_element(mylist, &num, sizeof(int *));
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}

canonical_original_code:
static void prepend_one_element_should_make_it_head_and_tail(int _i){ tcase_fn_start ("""prepend_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 50);
{
  int num = 20;
  struct ic_list *mylist = ic_list_new();
  ic_list_prepend(mylist, &num);
  assert_list_has_only_one_element(mylist, &num, sizeof(int *));
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}

variable_types: num int


decompiled_code:
__int64 append_one_element_should_make_it_head_and_tail()
{
__int64 v0; // rbx
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tcase_fn_start("append_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 18LL);
v2[0] = 10;
v0 = ic_list_new();
ic_list_append(v0, v2);
assert_list_has_only_one_element(v0, v2, 8uLL);
assert_list_bounds(v0);
return ic_list_free(v0);
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tcase_fn_start("append_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 18LL);
v2[0] = 10;
v0 = ic_list_new();
ic_list_append(v0, v2);
func4(v0, v2, 8uLL);
func3(v0);
return ic_list_free(v0);
}

original_code:
static void append_one_element_should_make_it_head_and_tail (int _i __attribute__ ((unused))){ tcase_fn_start ("""append_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 18);
{
  int num = 10;
  ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num);
  assert_list_has_only_one_element(mylist, &num, sizeof(int *));
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}

canonical_original_code:
static void append_one_element_should_make_it_head_and_tail(int _i){ tcase_fn_start ("""append_one_element_should_make_it_head_and_tail", "tests/check_ic_list.c", 18);
{
  int num = 10;
  struct ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num);
  assert_list_has_only_one_element(mylist, &num, sizeof(int *));
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}


decompiled_code:
__int64 __fastcall prepend_many_elements(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
__int64 v8; // rbx
double v9; // xmm4_8
double v10; // xmm5_8
__int64 result; // rax
int v12; // [rsp+4h] [rbp-14h] BYREF
int v13; // [rsp+8h] [rbp-10h] BYREF
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

tcase_fn_start("prepend_many_elements", "tests/check_ic_list.c", 63LL);
v12 = 12;
v13 = 30;
v14[0] = 42;
v8 = ic_list_new();
ic_list_prepend(v8, v14);
ic_list_prepend(v8, &v13);
ic_list_prepend(v8, &v12);
if ( ic_list_length(v8) )
{
mark_point("tests/check_ic_list.c", 72LL);
assert_list_elements(v8, a1, a2, a3, a4, v9, v10, a7, a8, &v12, &v13, v14);
assert_list_bounds(v8);
result = ic_list_free(v8);
}
else
{
ck_assert_failed(
"tests/check_ic_list.c",
72LL,
"Assertion 'ic_list_length(mylist)' failed",
(_BYTE *)&loc_2 + 1,
0LL);
result = append_many_elements();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
__int64 v8; // rbx
double v9; // xmm4_8
double v10; // xmm5_8
__int64 result; // rax
int v12; // [rsp+4h] [rbp-14h] BYREF
int v13; // [rsp+8h] [rbp-10h] BYREF
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

tcase_fn_start("prepend_many_elements", "tests/check_ic_list.c", 63LL);
v12 = 12;
v13 = 30;
v14[0] = 42;
v8 = ic_list_new();
ic_list_prepend(v8, v14);
ic_list_prepend(v8, &v13);
ic_list_prepend(v8, &v12);
if ( ic_list_length(v8) )
{
mark_point("tests/check_ic_list.c", 72LL);
func7(v8, a1, a2, a3, a4, v9, v10, a7, a8, &v12, &v13, v14);
func3(v8);
result = ic_list_free(v8);
}
else
{
ck_assert_failed(
"tests/check_ic_list.c",
72LL,
"Assertion 'ic_list_length(mylist)' failed",
(_BYTE *)&loc_2 + 1,
0LL);
result = func9();
}
return result;
}

original_code:
static void prepend_many_elements (int _i __attribute__ ((unused))){ tcase_fn_start ("""prepend_many_elements", "tests/check_ic_list.c", 63);
{
  int num1 = 12, num2 = 30, num3 = 42;
  ic_list *mylist = ic_list_new();
  ic_list_prepend(mylist, &num3);
  ic_list_prepend(mylist, &num2);
  ic_list_prepend(mylist, &num1);
  (ic_list_length(mylist)) ? _mark_point("tests/check_ic_list.c", 72) : _ck_assert_failed("tests/check_ic_list.c", 72, "Assertion '""ic_list_length(mylist)""' failed" , 3, ((void *)0));
  assert_list_elements(mylist, &num1, &num2, &num3);
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}

canonical_original_code:
static void prepend_many_elements(int _i){ tcase_fn_start ("""prepend_many_elements", "tests/check_ic_list.c", 63);
{
  int num1 = 12; int num2 = 30; int num3 = 42;
  struct ic_list *mylist = ic_list_new();
  ic_list_prepend(mylist, &num3);
  ic_list_prepend(mylist, &num2);
  ic_list_prepend(mylist, &num1);
  (ic_list_length(mylist)) ? _mark_point("tests/check_ic_list.c", 72) : _ck_assert_failed("tests/check_ic_list.c", 72, "Assertion '""ic_list_length(mylist)""' failed" , 3, ((void *)0));
  assert_list_elements(mylist, &num1, &num2, &num3);
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}


decompiled_code:
__int64 __fastcall append_many_elements(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
__int64 v8; // rbx
double v9; // xmm4_8
double v10; // xmm5_8
__int64 result; // rax
int v12; // [rsp+4h] [rbp-14h] BYREF
int v13; // [rsp+8h] [rbp-10h] BYREF
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

tcase_fn_start("append_many_elements", "tests/check_ic_list.c", 31LL);
v12 = 12;
v13 = 30;
v14[0] = 42;
v8 = ic_list_new();
ic_list_append(v8, &v12);
ic_list_append(v8, &v13);
ic_list_append(v8, v14);
if ( ic_list_length(v8) )
{
mark_point("tests/check_ic_list.c", 40LL);
assert_list_elements(v8, a1, a2, a3, a4, v9, v10, a7, a8, &v12, &v13, v14);
assert_list_bounds(v8);
result = ic_list_free(v8);
}
else
{
ck_assert_failed(
"tests/check_ic_list.c",
40LL,
"Assertion 'ic_list_length(mylist)' failed",
(_BYTE *)&loc_2 + 1,
0LL);
result = ic_list_suite();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
__int64 v8; // rbx
double v9; // xmm4_8
double v10; // xmm5_8
__int64 result; // rax
int v12; // [rsp+4h] [rbp-14h] BYREF
int v13; // [rsp+8h] [rbp-10h] BYREF
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

tcase_fn_start("append_many_elements", "tests/check_ic_list.c", 31LL);
v12 = 12;
v13 = 30;
v14[0] = 42;
v8 = ic_list_new();
ic_list_append(v8, &v12);
ic_list_append(v8, &v13);
ic_list_append(v8, v14);
if ( ic_list_length(v8) )
{
mark_point("tests/check_ic_list.c", 40LL);
func7(v8, a1, a2, a3, a4, v9, v10, a7, a8, &v12, &v13, v14);
func3(v8);
result = ic_list_free(v8);
}
else
{
ck_assert_failed(
"tests/check_ic_list.c",
40LL,
"Assertion 'ic_list_length(mylist)' failed",
(_BYTE *)&loc_2 + 1,
0LL);
result = func10();
}
return result;
}

original_code:
static void append_many_elements (int _i __attribute__ ((unused))){ tcase_fn_start ("""append_many_elements", "tests/check_ic_list.c", 31);
{
  int num1 = 12, num2 = 30, num3 = 42;
  ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num1);
  ic_list_append(mylist, &num2);
  ic_list_append(mylist, &num3);
  (ic_list_length(mylist)) ? _mark_point("tests/check_ic_list.c", 40) : _ck_assert_failed("tests/check_ic_list.c", 40, "Assertion '""ic_list_length(mylist)""' failed" , 3, ((void *)0));
  assert_list_elements(mylist, &num1, &num2, &num3);
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}

canonical_original_code:
static void append_many_elements(int _i){ tcase_fn_start ("""append_many_elements", "tests/check_ic_list.c", 31);
{
  int num1 = 12; int num2 = 30; int num3 = 42;
  struct ic_list *mylist = ic_list_new();
  ic_list_append(mylist, &num1);
  ic_list_append(mylist, &num2);
  ic_list_append(mylist, &num3);
  (ic_list_length(mylist)) ? _mark_point("tests/check_ic_list.c", 40) : _ck_assert_failed("tests/check_ic_list.c", 40, "Assertion '""ic_list_length(mylist)""' failed" , 3, ((void *)0));
  assert_list_elements(mylist, &num1, &num2, &num3);
  assert_list_bounds(mylist);
  ic_list_free(mylist);
}
}


decompiled_code:
__int64 __fastcall binary_search(_QWORD *a1, __int64 a2, int a3, int a4, __int64 (__fastcall *a5)(__int64, _QWORD))
{
unsigned int v6; // ebx
int v8; // er12
int v9; // eax

if ( a4 < a3 )
{
v8 = -1;
}
else
{
v6 = a4;
v8 = a4;
if ( a4 > a3 )
v8 = a4 - a3 / 2;
v9 = a5(a2, *a1 + a1[1] * v8);
if ( v9 < 0 )
{
v8 = binary_search(a1, a2, (unsigned int)a3, (unsigned int)(v8 - 1), a5);
}
else if ( v9 > 0 )
{
v8 = binary_search(a1, a2, (unsigned int)(v8 + 1), v6, a5);
}
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, int a3, int a4, __int64 (__fastcall *a5)(__int64, _QWORD))
{
unsigned int v6; // ebx
int v8; // er12
int v9; // eax

if ( a4 < a3 )
{
v8 = -1;
}
else
{
v6 = a4;
v8 = a4;
if ( a4 > a3 )
v8 = a4 - a3 / 2;
v9 = a5(a2, *a1 + a1[1] * v8);
if ( v9 < 0 )
{
v8 = func0(a1, a2, (unsigned int)a3, (unsigned int)(v8 - 1), a5);
}
else if ( v9 > 0 )
{
v8 = func0(a1, a2, (unsigned int)(v8 + 1), v6, a5);
}
}
return (unsigned int)v8;
}

original_code:
static int
binary_search(const vector *v, const void *key, int start, int end, vector_cmp_func cmp_func)
{
  if (end < start) return VECT_SEARCH_NOT_FOUND;
  int cmp;
  int middle = (end > start) ? (end - start / 2) : end;
  void *elem = (char *)v->elems + middle * v->elem_size;
  cmp = cmp_func(key, elem);
  if (cmp < 0)
    return binary_search(v, key, start, middle-1, cmp_func);
  if (cmp > 0)
    return binary_search(v, key, middle+1, end, cmp_func);
  return middle;
}

canonical_original_code:
static int binary_search(struct vector *v, void *key, int start, int end, int (*cmp_func)(void *elem_ptr1, void *elem_ptr2))
{
  if (end < start) return VECT_SEARCH_NOT_FOUND;
  int cmp;
  int middle = (end > start) ? (end - start / 2) : end;
  void *elem = (char *)v->elems + middle * v->elem_size;
  cmp = cmp_func(key, elem);
  if (cmp < 0)
    return binary_search(v, key, start, middle-1, cmp_func);
  if (cmp > 0)
    return binary_search(v, key, middle+1, end, cmp_func);
  return middle;
}

variable_types: struct vector { void *elems; unsigned long elem_size; int step; unsigned long length; unsigned long alloc_length; void (*free_func)(void *elem_ptr); } *

variable_types:
key
void *

variable_types: start int

variable_types: end int

variable_types: int (*)(void *elem_ptr1, void *elem_ptr2)

variable_types: cmp int

variable_types: middle int

variable_types:
elem
void *

return_type: int


original_code:
static void
grow_if_needed(vector *v)
{
  if (v->length == v->alloc_length) {
    v->alloc_length *= v->step;
    v->elems = realloc(v->elems, v->alloc_length * v->elem_size);
  }
}

canonical_original_code:
static void grow_if_needed(struct vector *v)
{
  if (v->length == v->alloc_length) {
    v->alloc_length *= v->step;
    v->elems = realloc(v->elems, v->alloc_length * v->elem_size);
  }
}

user_defined_types: struct vector { void *elems; unsigned long elem_size; int step; unsigned long length; unsigned long alloc_length; void (*free_func)(void *elem_ptr); }


decompiled_code:
__int64 __fastcall vector_length(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t
vector_length(const vector *v)
{
  return v->length;
}

canonical_original_code:
unsigned long vector_length(struct vector *v)
{
  return v->length;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall vector_insert(_QWORD *a1, const void *a2, int a3)
{
__int64 v3; // rax
__int64 v6; // rdi
char *v7; // r12
__int64 result; // rax

v3 = a1[3];
if ( a3 < 0 )
return 4294967292LL;
if ( a3 > (int)v3 )
return 4294967292LL;
if ( a3 || v3 )
{
grow_if_needed((__int64)a1);
v6 = a1[1];
v7 = (char *)(*a1 + v6 * a3);
memmove(&v7[v6], v7, v6 * (a1[3] - a3));
memcpy(v7, a2, a1[1]);
++a1[3];
result = 0LL;
}
else
{
vector_append(a1, a2);
result = 0LL;
}
return result;
}

original_code:
int
vector_insert(vector *v, const void *elem_ptr, int position)
{
  if (position > (int)v->length || position < 0) {
    return VECT_INSERT_INVALID_POSITION;
  }
  if (v->length == 0 && position == 0) {
    vector_append(v, elem_ptr);
    return VECT_OK;
  }
  grow_if_needed(v);
  void *src = (char *)v->elems + position * v->elem_size;
  void *dst = (char *)src + v->elem_size;
  memmove(dst, src, v->elem_size * (v->length - position));
  memcpy(src, elem_ptr, v->elem_size);
  v->length++;
  return VECT_OK;
}

canonical_original_code:
int vector_insert(struct vector *v, void *elem_ptr, int position)
{
  if (position > (int)v->length || position < 0) {
    return VECT_INSERT_INVALID_POSITION;
  }
  if (v->length == 0 && position == 0) {
    vector_append(v, elem_ptr);
    return VECT_OK;
  }
  grow_if_needed(v);
  void *src = (char *)v->elems + position * v->elem_size;
  void *dst = (char *)src + v->elem_size;
  memmove(dst, src, v->elem_size * (v->length - position));
  memcpy(src, elem_ptr, v->elem_size);
  v->length++;
  return VECT_OK;
}

variable_types: position int

variable_types:
src
void *

variable_types:
dst
void *


decompiled_code:
__int64 __fastcall vector_search(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, __int64), int a4, char a5)
{
unsigned __int64 v7; // rcx
__int64 v8; // rbx

if ( !a2 )
return 4294967294LL;
if ( a4 < 0 )
return 4294967293LL;
v7 = a1[3];
if ( a4 >= (int)v7 )
return 4294967293LL;
if ( a5 )
return binary_search(a1, a2, a4, (int)v7 - 1, a3);
v8 = a4;
if ( v7 <= a4 )
return 0xFFFFFFFFLL;
while ( (unsigned int)a3(*a1 + a1[1] * v8, a2) )
{
if ( a1[3] <= (unsigned __int64)++v8 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, __int64), int a4, char a5)
{
unsigned __int64 v7; // rcx
__int64 v8; // rbx

if ( !a2 )
return 4294967294LL;
if ( a4 < 0 )
return 4294967293LL;
v7 = a1[3];
if ( a4 >= (int)v7 )
return 4294967293LL;
if ( a5 )
return func0(a1, a2, a4, (int)v7 - 1, a3);
v8 = a4;
if ( v7 <= a4 )
return 0xFFFFFFFFLL;
while ( (unsigned int)a3(*a1 + a1[1] * v8, a2) )
{
if ( a1[3] <= (unsigned __int64)++v8 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v8;
}

original_code:
int
vector_search(const vector *v, const void *key, vector_cmp_func cmp_func,
              int start, _Bool is_sorted)
{
  size_t i;
  if (key == ((void *)0)) {
    return VECT_SEARCH_INVALID_KEY;
  }
  if (start < 0 || start >= (int)v->length) {
    return VECT_SEARCH_INVALID_START;
  }
  if (is_sorted) {
    return binary_search(v, key, start, v->length-1, cmp_func);
  } else {
    for (i = start; i < v->length; i++) {
      if (cmp_func((char *)v->elems + i * v->elem_size, key) == 0) return i;
    }
  }
  return VECT_SEARCH_NOT_FOUND;
}

canonical_original_code:
int vector_search(struct vector *v, void *key, int (*cmp_func)(void *elem_ptr1, void *elem_ptr2), int start, _Bool is_sorted)
{
  unsigned long i;
  if (key == ((void *)0)) {
    return VECT_SEARCH_INVALID_KEY;
  }
  if (start < 0 || start >= (int)v->length) {
    return VECT_SEARCH_INVALID_START;
  }
  if (is_sorted) {
    return binary_search(v, key, start, v->length-1, cmp_func);
  } else {
    for (i = start; i < v->length; i++) {
      if (cmp_func((char *)v->elems + i * v->elem_size, key) == 0) return i;
    }
  }
  return VECT_SEARCH_NOT_FOUND;
}

variable_types:
i
unsigned long


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

if ( a2 >= *(_DWORD *)(a1 + 24) || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)a1 + *(_QWORD *)(a1 + 8) * a2;
return result;
}

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

if ( a2 >= *(_DWORD *)(a1 + 24) || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)a1 + *(_QWORD *)(a1 + 8) * a2;
return result;
}

original_code:
void *
vector_get(const vector *v, int position)
{
  if (position >= (int)v->length || position < 0)
    return ((void *)0);
  return ((char *)v->elems + (position * v->elem_size));
}

canonical_original_code:
void *vector_get(struct vector *v, int position)
{
  if (position >= (int)v->length || position < 0)
    return ((void *)0);
  return ((char *)v->elems + (position * v->elem_size));
}

return_type: void *


decompiled_code:
__int64 __fastcall vector_replace(__int64 a1, int a2, const void *a3)
{
void *v4; // rbx
void (__fastcall *v5)(_QWORD); // rax

if ( a2 < 0 )
return 4294967291LL;
if ( a2 >= *(_DWORD *)(a1 + 24) )
return 4294967291LL;
v4 = (void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 8) * a2);
v5 = *(void (__fastcall **)(_QWORD))(a1 + 40);
if ( v5 )
v5(*(_QWORD *)a1 + *(_QWORD *)(a1 + 8) * a2);
memcpy(v4, a3, *(_QWORD *)(a1 + 8));
return 0LL;
}

original_code:
int
vector_replace(vector *v, int position, const void *elem_ptr)
{
  if (position < 0 || position >= (int)v->length) {
    return VECT_REPLACE_INVALID_POSITION;
  }
  void *pos = (char *)v->elems + position * v->elem_size;
  if (v->free_func) {
    v->free_func(pos);
  }
  memcpy(pos, elem_ptr, v->elem_size);
  return VECT_OK;
}

canonical_original_code:
int vector_replace(struct vector *v, int position, void *elem_ptr)
{
  if (position < 0 || position >= (int)v->length) {
    return VECT_REPLACE_INVALID_POSITION;
  }
  void *pos = (char *)v->elems + position * v->elem_size;
  if (v->free_func) {
    v->free_func(pos);
  }
  memcpy(pos, elem_ptr, v->elem_size);
  return VECT_OK;
}

variable_types:
pos
void *


decompiled_code:
void __fastcall vector_sort(__int64 a1, int (*a2)(const void *, const void *))
{
if ( a2 )
qsort(*(void **)a1, *(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int (*a2)(const void *, const void *))
{
if ( a2 )
qsort(*(void **)a1, *(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 8), a2);
}

original_code:
void
vector_sort(vector *v, vector_cmp_func cmp_func)
{
  if (cmp_func == ((void *)0)) return;
  qsort(v->elems, v->length, v->elem_size, cmp_func);
}

canonical_original_code:
void vector_sort(struct vector *v, int (*cmp_func)(void *elem_ptr1, void *elem_ptr2))
{
  if (cmp_func == ((void *)0)) return;
  qsort(v->elems, v->length, v->elem_size, cmp_func);
}


decompiled_code:
__int64 __fastcall vector_map(_QWORD *a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
unsigned int v5; // ebp
__int64 v6; // rdi
__int64 result; // rax

if ( a2 && a1[3] )
{
v5 = 0;
v6 = 0LL;
do
{
result = a2(*a1 + a1[1] * v6, a3);
v6 = ++v5;
}
while ( (unsigned __int64)v5 < a1[3] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
unsigned int v5; // ebp
__int64 v6; // rdi
__int64 result; // rax

if ( a2 && a1[3] )
{
v5 = 0;
v6 = 0LL;
do
{
result = a2(*a1 + a1[1] * v6, a3);
v6 = ++v5;
}
while ( (unsigned __int64)v5 < a1[3] );
}
return result;
}

original_code:
void
vector_map(vector *v, vector_map_func map_func, void *data)
{
  if (map_func == ((void *)0)) return;
  unsigned int i;
  for (i = 0; i < v->length; i++)
    map_func((char *)v->elems + i * v->elem_size, data);
}

canonical_original_code:
void vector_map(struct vector *v, void (*map_func)(void *elem_ptr, void *aux_data), void *data)
{
  if (map_func == ((void *)0)) return;
  unsigned int i;
  for (i = 0; i < v->length; i++)
    map_func((char *)v->elems + i * v->elem_size, data);
}

variable_types: void (*)(void *elem_ptr, void *aux_data)

variable_types:
data
void *

variable_types:
i
unsigned int


original_code:
int
vector_delete(vector *v, int position)
{
  if (position < 0 || position >= (int)v->length) {
    return VECT_DELETE_INVALID_POSITION;
  }
  void *elem = (char *)v->elems + position * v->elem_size;
  if (v->free_func != ((void *)0)) {
    v->free_func(elem);
  }
  if (position != ((int)v->length - 1) && (int)v->length > 1) {
    void *source = (char *)v->elems + (position+1) * v->elem_size;
    void *destin = (char *)v->elems + position * v->elem_size;
    size_t num = (v->length - (position+1)) * v->elem_size;
    memmove(destin, source, num);
  }
  v->length--;
  return VECT_OK;
}

canonical_original_code:
int vector_delete(struct vector *v, int position)
{
  if (position < 0 || position >= (int)v->length) {
    return VECT_DELETE_INVALID_POSITION;
  }
  void *elem = (char *)v->elems + position * v->elem_size;
  if (v->free_func != ((void *)0)) {
    v->free_func(elem);
  }
  if (position != ((int)v->length - 1) && (int)v->length > 1) {
    void *source = (char *)v->elems + (position+1) * v->elem_size;
    void *destin = (char *)v->elems + position * v->elem_size;
    unsigned long num = (v->length - (position+1)) * v->elem_size;
    memmove(destin, source, num);
  }
  v->length--;
  return VECT_OK;
}

variable_types:
source
void *

variable_types:
destin
void *

variable_types:
num
unsigned long


decompiled_code:
void __fastcall vector_free(void *ptr)
{
__int64 v1; // rbp

if ( ptr )
{
if ( *((_QWORD *)ptr + 5) && *((int *)ptr + 6) > 0 )
{
v1 = 0LL;
do
(*((void (__fastcall **)(__int64))ptr + 5))(*(_QWORD *)ptr + *((_QWORD *)ptr + 1) * v1++);
while ( *((_DWORD *)ptr + 6) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
__int64 v1; // rbp

if ( ptr )
{
if ( *((_QWORD *)ptr + 5) && *((int *)ptr + 6) > 0 )
{
v1 = 0LL;
do
(*((void (__fastcall **)(__int64))ptr + 5))(*(_QWORD *)ptr + *((_QWORD *)ptr + 1) * v1++);
while ( *((_DWORD *)ptr + 6) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void
vector_free(vector *v)
{
  if (v == ((void *)0)) return;
  if (v->free_func != ((void *)0)) {
    int i;
    for (i = 0; i < (int)v->length; i++) {
      v->free_func((char *)v->elems + i * v->elem_size);
    }
  }
  free(v->elems);
  free(v);
}

canonical_original_code:
void vector_free(struct vector *v)
{
  if (v == ((void *)0)) return;
  if (v->free_func != ((void *)0)) {
    int i;
    for (i = 0; i < (int)v->length; i++) {
      v->free_func((char *)v->elems + i * v->elem_size);
    }
  }
  free(v->elems);
  free(v);
}

variable_types: struct vector { void *elems; unsigned long elem_size; int step; unsigned long length; unsigned long alloc_length; void (*free_func)(void *elem_ptr); } *

variable_types: i int


decompiled_code:
_QWORD *ic_list_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
ic_list * ic_list_new(void)
{
  ic_list *l = malloc(sizeof(ic_list));
  l->head = ((void *)0);
  l->tail = ((void *)0);
  l->length = 0;
  return l;
}

canonical_original_code:
struct ic_list *ic_list_new()
{
  struct ic_list *l = malloc(sizeof(ic_list));
  l->head = ((void *)0);
  l->tail = ((void *)0);
  l->length = 0;
  return l;
}

variable_types: struct ic_list { struct ic_node { struct ic_node *prev; struct ic_node *next; void *data; } *head; struct ic_node *tail; unsigned long length; } *


decompiled_code:
bool __fastcall ic_list_empty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
bool __fastcall func1(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
_Bool ic_list_empty(ic_list *l)
{
  return l->head == ((void *)0);
}

canonical_original_code:
_Bool ic_list_empty(struct ic_list *l)
{
  return l->head == ((void *)0);
}


decompiled_code:
__int64 __fastcall ic_list_length(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
size_t ic_list_length(ic_list *l)
{
  return l->length;
}

canonical_original_code:
unsigned long ic_list_length(struct ic_list *l)
{
  return l->length;
}


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

result = *a1;
if ( *a1 )
result = *(_QWORD *)(result + 16);
return result;
}

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

result = *a1;
if ( *a1 )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
void * ic_list_first(ic_list *l)
{
  if (l->head != ((void *)0))
    return l->head->data;
  return ((void *)0);
}

canonical_original_code:
void *ic_list_first(struct ic_list *l)
{
  if (l->head != ((void *)0))
    return l->head->data;
  return ((void *)0);
}


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

result = *(_QWORD *)(a1 + 8);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
void * ic_list_last(ic_list *l)
{
  if (l->tail != ((void *)0))
    return l->tail->data;
  return ((void *)0);
}

canonical_original_code:
void *ic_list_last(struct ic_list *l)
{
  if (l->tail != ((void *)0))
    return l->tail->data;
  return ((void *)0);
}


decompiled_code:
__int64 __fastcall ic_list_nth(__int64 *a1, unsigned __int64 a2)
{
__int64 v2; // rbx
__int64 i; // rax

v2 = *a1;
if ( ic_list_length((__int64)a1) <= a2 )
return 0LL;
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, unsigned __int64 a2)
{
__int64 v2; // rbx
__int64 i; // rax

v2 = *a1;
if ( func2((__int64)a1) <= a2 )
return 0LL;
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
ic_node * ic_list_nth(ic_list *l, size_t n)
{
  ic_node *tmp, *node = l->head;
  size_t jumps = 0;
  if (n >= ic_list_length(l)) return ((void *)0);
  while (jumps < n) {
    tmp = node->next;
    node = tmp;
    jumps++;
  }
  return node;
}

canonical_original_code:
struct ic_node *ic_list_nth(struct ic_list *l, unsigned long n)
{
  struct ic_node *tmp; struct ic_node *node = l->head;
  unsigned long jumps = 0;
  if (n >= ic_list_length(l)) return ((void *)0);
  while (jumps < n) {
    tmp = node->next;
    node = tmp;
    jumps++;
  }
  return node;
}

variable_types: struct ic_list { struct ic_node *head; struct ic_node *tail; unsigned long length; } *

variable_types:
n
unsigned long

variable_types: struct ic_node { struct ic_node *prev; struct ic_node *next; void *data; } *

variable_types:
jumps
unsigned long


decompiled_code:
__int64 __fastcall ic_list_nth_data(__int64 *a1, unsigned __int64 a2)
{
__int64 result; // rax

result = ic_list_nth(a1, a2);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, unsigned __int64 a2)
{
__int64 result; // rax

result = func7(a1, a2);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
void * ic_list_nth_data(ic_list *l, size_t n)
{
  ic_node *node = ic_list_nth(l, n);
  if (node == ((void *)0)) return ((void *)0);
  return node->data;
}

canonical_original_code:
void *ic_list_nth_data(struct ic_list *l, unsigned long n)
{
  struct ic_node *node = ic_list_nth(l, n);
  if (node == ((void *)0)) return ((void *)0);
  return node->data;
}


decompiled_code:
__int64 __fastcall ic_list_find(__int64 *a1, const void *a2)
{
unsigned __int64 i; // rbp
__int64 v3; // rbx

for ( i = 0LL; ic_list_length((__int64)a1) > i; ++i )
{
v3 = ic_list_nth(a1, i);
if ( !memcmp(a2, *(const void **)(v3 + 16), 8uLL) )
return v3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, const void *a2)
{
unsigned __int64 i; // rbp
__int64 v3; // rbx

for ( i = 0LL; func2((__int64)a1) > i; ++i )
{
v3 = func7(a1, i);
if ( !memcmp(a2, *(const void **)(v3 + 16), 8uLL) )
return v3;
}
return 0LL;
}

original_code:
ic_node * ic_list_find(ic_list *l, void *data)
{
  size_t n = 0;
  ic_node *node = ((void *)0);
  while (n < ic_list_length(l)) {
    node = ic_list_nth(l, n);
    if (memcmp(data, node->data, sizeof(void *)) == 0) return node;
    n++;
  }
  return ((void *)0);
}

canonical_original_code:
struct ic_node *ic_list_find(struct ic_list *l, void *data)
{
  unsigned long n = 0;
  struct ic_node *node = ((void *)0);
  while (n < ic_list_length(l)) {
    node = ic_list_nth(l, n);
    if (memcmp(data, node->data, sizeof(void *)) == 0) return node;
    n++;
  }
  return ((void *)0);
}

return_type: struct ic_node { struct ic_node *prev; struct ic_node *next; void *data; } *


decompiled_code:
void __fastcall ic_list_free(void *ptr)
{
_QWORD *v2; // rdi
void *i; // rax

if ( ic_list_empty(ptr) )
{
free(ptr);
}
else
{
v2 = *(_QWORD **)ptr;
for ( i = (void *)*((_QWORD *)ptr + 1); *(void **)ptr != i; i = (void *)*((_QWORD *)ptr + 1) )
{
*(_QWORD *)ptr = v2[1];
free(v2);
v2 = *(_QWORD **)ptr;
}
free(i);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
_QWORD *v2; // rdi
void *i; // rax

if ( func1(ptr) )
{
free(ptr);
}
else
{
v2 = *(_QWORD **)ptr;
for ( i = (void *)*((_QWORD *)ptr + 1); *(void **)ptr != i; i = (void *)*((_QWORD *)ptr + 1) )
{
*(_QWORD *)ptr = v2[1];
free(v2);
v2 = *(_QWORD **)ptr;
}
free(i);
free(ptr);
}
}

original_code:
void ic_list_free(ic_list *l)
{
  if (ic_list_empty(l)) {
    free(l);
  } else {
    ic_node *tmp;
    while (l->head != l->tail) {
      tmp = l->head;
      l->head = l->head->next;
      free(tmp);
    }
    free(l->head);
    free(l);
  }
}

canonical_original_code:
void ic_list_free(struct ic_list *l)
{
  if (ic_list_empty(l)) {
    free(l);
  } else {
    struct ic_node *tmp;
    while (l->head != l->tail) {
      tmp = l->head;
      l->head = l->head->next;
      free(tmp);
    }
    free(l->head);
    free(l);
  }
}


multiply

repo: iiiyu/oh-my-c

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

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

original_code:
int
multiply(int num1, int num2)
{
 return num1 * num2;
}


decompiled_code:
__int64 __fastcall crc8_lsb(int a1, _BYTE *a2, __int64 a3)
{
_BYTE *v3; // r8
_BYTE *v4; // r9
__int64 result; // rax
int v6; // ecx
unsigned int v7; // edx
unsigned int v8; // esi
bool v9; // zf

v3 = a2;
if ( !a3 )
return 0LL;
v4 = &a2[a3];
LODWORD(result) = 0;
do
{
LOBYTE(result) = *v3++ ^ result;
v6 = 8;
do
{
v7 = result;
LOBYTE(v7) = (unsigned __int8)result >> 1;
v8 = result;
LOBYTE(v8) = (unsigned __int8)result >> 1;
v9 = (result & 1) == 0;
result = a1 ^ v7;
if ( v9 )
result = v8;
--v6;
}
while ( v6 );
}
while ( v4 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, _BYTE *a2, __int64 a3)
{
_BYTE *v3; // r8
_BYTE *v4; // r9
__int64 result; // rax
int v6; // ecx
unsigned int v7; // edx
unsigned int v8; // esi
bool v9; // zf

v3 = a2;
if ( !a3 )
return 0LL;
v4 = &a2[a3];
LODWORD(result) = 0;
do
{
LOBYTE(result) = *v3++ ^ result;
v6 = 8;
do
{
v7 = result;
LOBYTE(v7) = (unsigned __int8)result >> 1;
v8 = result;
LOBYTE(v8) = (unsigned __int8)result >> 1;
v9 = (result & 1) == 0;
result = a1 ^ v7;
if ( v9 )
result = v8;
--v6;
}
while ( v6 );
}
while ( v4 != v3 );
return result;
}

original_code:
uint8_t crc8_lsb(uint8_t poly, uint8_t *data, size_t size) {
  uint8_t crc = 0x00;
  while (size--) {
    crc ^= *data++;
    for (int bit = 0; bit < 8; bit++) {
      if (crc & 0x01) {
        crc = (crc >> 1) ^ poly;
      } else {
        crc >>= 1;
      }
    }
  }
  return crc;
}

canonical_original_code:
unsigned char crc8_lsb(unsigned char poly, unsigned char *data, unsigned long size) {
  unsigned char crc = 0x00;
  while (size--) {
    crc ^= *data++;
    for (int bit = 0; bit < 8; bit++) {
      if (crc & 0x01) {
        crc = (crc >> 1) ^ poly;
      } else {
        crc >>= 1;
      }
    }
  }
  return crc;
}

variable_types:
poly
unsigned char

variable_types:
data
unsigned char *

variable_types:
size
unsigned long

variable_types:
crc
unsigned char

variable_types: bit int

return_type: unsigned char


decompiled_code:
__int64 __fastcall crc8_msb(int a1, _BYTE *a2, __int64 a3)
{
_BYTE *v3; // r8
_BYTE *v4; // r9
__int64 result; // rax
int v6; // ecx
unsigned int v7; // esi
bool v8; // sf

v3 = a2;
if ( !a3 )
return 0LL;
v4 = &a2[a3];
LODWORD(result) = 0;
do
{
LOBYTE(result) = *v3++ ^ result;
v6 = 8;
do
{
v7 = 2 * result;
v8 = (result & 0x80u) != 0LL;
result = a1 ^ (unsigned int)(2 * result);
if ( !v8 )
result = v7;
--v6;
}
while ( v6 );
}
while ( v4 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, _BYTE *a2, __int64 a3)
{
_BYTE *v3; // r8
_BYTE *v4; // r9
__int64 result; // rax
int v6; // ecx
unsigned int v7; // esi
bool v8; // sf

v3 = a2;
if ( !a3 )
return 0LL;
v4 = &a2[a3];
LODWORD(result) = 0;
do
{
LOBYTE(result) = *v3++ ^ result;
v6 = 8;
do
{
v7 = 2 * result;
v8 = (result & 0x80u) != 0LL;
result = a1 ^ (unsigned int)(2 * result);
if ( !v8 )
result = v7;
--v6;
}
while ( v6 );
}
while ( v4 != v3 );
return result;
}

original_code:
uint8_t crc8_msb(uint8_t poly, uint8_t *data, size_t size) {
  uint8_t crc = 0x00;
  while (size--) {
    crc ^= *data++;
    for (int bit = 0; bit < 8; bit++) {
      if (crc & 0x80) {
        crc = (crc << 1) ^ poly;
      } else {
        crc <<= 1;
      }
    }
  }
  return crc;
}

canonical_original_code:
unsigned char crc8_msb(unsigned char poly, unsigned char *data, unsigned long size) {
  unsigned char crc = 0x00;
  while (size--) {
    crc ^= *data++;
    for (int bit = 0; bit < 8; bit++) {
      if (crc & 0x80) {
        crc = (crc << 1) ^ poly;
      } else {
        crc <<= 1;
      }
    }
  }
  return crc;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al

v3 = crc8_lsb(29, "Hello World!!!", 14LL);
printf("%02x\n", v3);
v4 = crc8_msb(29, "Hello World!!!", 14LL);
printf("%02x\n", v4);
v5 = crc8_lsb(49, "Hello World!!!", 14LL);
printf("%02x\n", v5);
v6 = crc8_msb(49, "Hello World!!!", 14LL);
printf("%02x\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al

v3 = func7(29, "Hello World!!!", 14LL);
printf("%02x\n", v3);
v4 = func8(29, "Hello World!!!", 14LL);
printf("%02x\n", v4);
v5 = func7(49, "Hello World!!!", 14LL);
printf("%02x\n", v5);
v6 = func8(49, "Hello World!!!", 14LL);
printf("%02x\n", v6);
return 0;
}

original_code:
int main(void) {
  char *data = "Hello World!!!";
  uint8_t poly;
  poly = 0x1D;
  printf("%02x\n", crc8_lsb(poly, (uint8_t *)data, strlen(data)));
  printf("%02x\n", crc8_msb(poly, (uint8_t *)data, strlen(data)));
  poly = 0x31;
  printf("%02x\n", crc8_lsb(poly, (uint8_t *)data, strlen(data)));
  printf("%02x\n", crc8_msb(poly, (uint8_t *)data, strlen(data)));
  return 0;
}

canonical_original_code:
int main() {
  char *data = "Hello World!!!";
  unsigned char poly;
  poly = 0x1D;
  printf("%02x\n", crc8_lsb(poly, (unsigned char *)data, strlen(data)));
  printf("%02x\n", crc8_msb(poly, (unsigned char *)data, strlen(data)));
  poly = 0x31;
  printf("%02x\n", crc8_lsb(poly, (unsigned char *)data, strlen(data)));
  printf("%02x\n", crc8_msb(poly, (unsigned char *)data, strlen(data)));
  return 0;
}

variable_types:
data
char *


repo: ikegam/sparsexml

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

CU_initialize_registry(argc, argv, envp);
v4 = CU_add_suite("SparseXML", 0LL, 0LL);
add_private_test(&v4);
CU_add_test(v4, "Parse simple XML", test_parse_simple_xml);
CU_add_test(v4, "Check status in running explorer", test_check_event_on_content);
CU_add_test(v4, "Check ", test_check_parsing_attribute);
CU_basic_run_tests();
CU_cleanup_registry();
return 0;
}

original_code:
int main(void) {
  CU_pSuite suite;
  CU_initialize_registry();
  suite = CU_add_suite("SparseXML", ((void *)0), ((void *)0));
  add_private_test(&suite);
  CU_add_test(suite, "Parse simple XML", test_parse_simple_xml);
  CU_add_test(suite, "Check status in running explorer", test_check_event_on_content);
  CU_add_test(suite, "Check ", test_check_parsing_attribute );
  CU_basic_run_tests();
  CU_cleanup_registry();
  return 0;
}

canonical_original_code:
int main() {
  struct CU_Suite *suite;
  CU_initialize_registry();
  suite = CU_add_suite("SparseXML", ((void *)0), ((void *)0));
  add_private_test(&suite);
  CU_add_test(suite, "Parse simple XML", test_parse_simple_xml);
  CU_add_test(suite, "Check status in running explorer", test_check_event_on_content);
  CU_add_test(suite, "Check ", test_check_parsing_attribute );
  CU_basic_run_tests();
  CU_cleanup_registry();
  return 0;
}

variable_types: struct CU_Suite { char *pName; int fActive; struct CU_Test { char *pName; int fActive; void (*pTestFunc)(); struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*pJumpBuf)[1]; struct CU_Test *pNext; struct CU_Test *pPrev; } *pTest; int (*pInitializeFunc)(); int (*pCleanupFunc)(); void (*pSetUpFunc)(); void (*pTearDownFunc)(); unsigned int uiNumberOfTests; struct CU_Suite *pNext; struct CU_Suite *pPrev; unsigned int uiNumberOfTestsFailed; unsigned int uiNumberOfTestsSuccess; } *

user_defined_types: struct CU_Suite { char *pName; int fActive; struct CU_Test *pTest; int (*pInitializeFunc)(); int (*pCleanupFunc)(); void (*pSetUpFunc)(); void (*pTearDownFunc)(); unsigned int uiNumberOfTests; struct CU_Suite *pNext; struct CU_Suite *pPrev; unsigned int uiNumberOfTestsFailed; unsigned int uiNumberOfTestsSuccess; }

user_defined_types: struct CU_Test { char *pName; int fActive; void (*pTestFunc)(); struct __jmp_buf_tag (*pJumpBuf)[1]; struct CU_Test *pNext; struct CU_Test *pPrev; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


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

v0 = sxml_make_explorer();
CU_assertImplementation(*(_DWORD *)v0 == 0, 10LL, "explorer->state == INITIAL", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(*(_DWORD *)(v0 + 1028) == 0, 11LL, "explorer->bp == 0", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(
*(_BYTE *)(v0 + 4) == 0,
12LL,
"strlen(explorer->buffer) == 0",
"test-private.c",
&unk_300,
0LL);
return sxml_destroy_explorer(v0);
}

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

v0 = sxml_make_explorer();
CU_assertImplementation(*(_DWORD *)v0 == 0, 10LL, "explorer->state == INITIAL", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(*(_DWORD *)(v0 + 1028) == 0, 11LL, "explorer->bp == 0", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(
*(_BYTE *)(v0 + 4) == 0,
12LL,
"strlen(explorer->buffer) == 0",
"test-private.c",
&unk_300,
0LL);
return sxml_destroy_explorer(v0);
}

original_code:
void test_initialize_explorer(void) {
  SXMLExplorer* explorer;
  explorer = sxml_make_explorer();
  { CU_assertImplementation((explorer->state == INITIAL), 10, "explorer->state == INITIAL", "test-private.c", "", 0); };
  { CU_assertImplementation((explorer->bp == 0), 11, "explorer->bp == 0", "test-private.c", "", 0); };
  { CU_assertImplementation((strlen(explorer->buffer) == 0), 12, "strlen(explorer->buffer) == 0", "test-private.c", "", 0); };
  sxml_destroy_explorer(explorer);
}

canonical_original_code:
void test_initialize_explorer() {
  struct __SXMLExplorer *explorer;
  explorer = sxml_make_explorer();
  { CU_assertImplementation((explorer->state == INITIAL), 10, "explorer->state == INITIAL", "test-private.c", "", 0); };
  { CU_assertImplementation((explorer->bp == 0), 11, "explorer->bp == 0", "test-private.c", "", 0); };
  { CU_assertImplementation((strlen(explorer->buffer) == 0), 12, "strlen(explorer->buffer) == 0", "test-private.c", "", 0); };
  sxml_destroy_explorer(explorer);
}

variable_types: struct __SXMLExplorer { enum __SXMLExplorerState { INITIAL=0, IN_DECLARATION=1, IN_TAG=2, IN_ATTRIBUTE_KEY=3, IN_ATTRIBUTE_VALUE=4, IN_CONTENT=5 } state; char buffer[1024]; unsigned int bp; unsigned char header_parsed; unsigned char (*tag_func)(char *); unsigned char (*content_func)(char *); unsigned char (*attribute_value_func)(char *); unsigned char (*attribute_key_func)(char *); } *

user_defined_types: struct __SXMLExplorer { enum __SXMLExplorerState state; char buffer[1024]; unsigned int bp; unsigned char header_parsed; unsigned char (*tag_func)(char *); unsigned char (*content_func)(char *); unsigned char (*attribute_value_func)(char *); unsigned char (*attribute_key_func)(char *); }


decompiled_code:
__int64 test_parse_separated_xml()
{
__int64 v0; // rbx
char v1; // bp
char v3[24]; // [rsp+Ch] [rbp-3Ch] BYREF
char v4[36]; // [rsp+24h] [rbp-24h] BYREF

strcpy(v4, "<?xml versi");
strcpy(&v3[14], "on=\"1.1\"?");
strcpy(&v3[9], "><ta");
strcpy(v3, "g></tag>");
v0 = sxml_make_explorer();
sxml_register_func(v0, on_tag_0, 0LL, 0LL, 0LL);
sxml_run_explorer(v0, v4);
CU_assertImplementation(
*(_DWORD *)v0 == 1,
40LL,
"explorer->state == IN_DECLARATION",
"test-private.c",
&unk_300,
0LL);
sxml_run_explorer(v0, &v3[14]);
CU_assertImplementation(
*(_DWORD *)v0 == 1,
42LL,
"explorer->state == IN_DECLARATION",
"test-private.c",
&unk_300,
0LL);
sxml_run_explorer(v0, &v3[9]);
CU_assertImplementation(*(_DWORD *)v0 == 2, 44LL, "explorer->state == IN_TAG", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(
strcmp((const char *)(v0 + 4), "ta") == 0,
45LL,
"strcmp(explorer->buffer, \"ta\") == 0",
"test-private.c",
&unk_300,
0LL);
v1 = sxml_run_explorer(v0, v3);
CU_assertImplementation(*(_DWORD *)v0 == 5, 47LL, "explorer->state == IN_CONTENT", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(v1 == 3, 48LL, "ret == SXMLExplorerInterrupted", "test-private.c", &unk_300, 0LL);
return sxml_destroy_explorer(v0);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
char v1; // bp
char v3[24]; // [rsp+Ch] [rbp-3Ch] BYREF
char v4[36]; // [rsp+24h] [rbp-24h] BYREF

strcpy(v4, "<?xml versi");
strcpy(&v3[14], "on=\"1.1\"?");
strcpy(&v3[9], "><ta");
strcpy(v3, "g></tag>");
v0 = sxml_make_explorer();
sxml_register_func(v0, on_tag_0, 0LL, 0LL, 0LL);
sxml_run_explorer(v0, v4);
CU_assertImplementation(
*(_DWORD *)v0 == 1,
40LL,
"explorer->state == IN_DECLARATION",
"test-private.c",
&unk_300,
0LL);
sxml_run_explorer(v0, &v3[14]);
CU_assertImplementation(
*(_DWORD *)v0 == 1,
42LL,
"explorer->state == IN_DECLARATION",
"test-private.c",
&unk_300,
0LL);
sxml_run_explorer(v0, &v3[9]);
CU_assertImplementation(*(_DWORD *)v0 == 2, 44LL, "explorer->state == IN_TAG", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(
strcmp((const char *)(v0 + 4), "ta") == 0,
45LL,
"strcmp(explorer->buffer, \"ta\") == 0",
"test-private.c",
&unk_300,
0LL);
v1 = sxml_run_explorer(v0, v3);
CU_assertImplementation(*(_DWORD *)v0 == 5, 47LL, "explorer->state == IN_CONTENT", "test-private.c", &unk_300, 0LL);
CU_assertImplementation(v1 == 3, 48LL, "ret == SXMLExplorerInterrupted", "test-private.c", &unk_300, 0LL);
return sxml_destroy_explorer(v0);
}

original_code:
void test_parse_separated_xml(void) {
  SXMLExplorer* explorer;
  char xml1[] = "<?xml versi";
  char xml2[] = "on=\"1.1\"?";
  char xml3[] = "><ta";
  char xml4[] = "g></tag>";
  unsigned char ret;
  unsigned char on_tag(char *name) {
    static int c = 0;
    if (strcmp("tag", name) == 0 && c == 0) {
      c++;
    } else if (strcmp("/tag", name) == 0 && c == 1) {
      c++;
    }
    if (c==2) {
      return 0x01;
    }
    return 0x00;
  }
  explorer = sxml_make_explorer();
  sxml_register_func(explorer, &on_tag, ((void *)0), ((void *)0), ((void *)0));
  ret = sxml_run_explorer(explorer, xml1);
  { CU_assertImplementation((explorer->state == IN_DECLARATION), 40, "explorer->state == IN_DECLARATION", "test-private.c", "", 0); };
  ret = sxml_run_explorer(explorer, xml2);
  { CU_assertImplementation((explorer->state == IN_DECLARATION), 42, "explorer->state == IN_DECLARATION", "test-private.c", "", 0); };
  ret = sxml_run_explorer(explorer, xml3);
  { CU_assertImplementation((explorer->state == IN_TAG), 44, "explorer->state == IN_TAG", "test-private.c", "", 0); };
  { CU_assertImplementation((strcmp(explorer->buffer, "ta") == 0), 45, "strcmp(explorer->buffer, \"ta\") == 0", "test-private.c", "", 0); };
  ret = sxml_run_explorer(explorer, xml4);
  { CU_assertImplementation((explorer->state == IN_CONTENT), 47, "explorer->state == IN_CONTENT", "test-private.c", "", 0); };
  { CU_assertImplementation((ret == 0x03), 48, "ret == SXMLExplorerInterrupted", "test-private.c", "", 0); };
  sxml_destroy_explorer(explorer);
}

canonical_original_code:
void test_parse_separated_xml() {
  struct __SXMLExplorer *explorer;
  char xml1[] = "<?xml versi";
  char xml2[] = "on=\"1.1\"?";
  char xml3[] = "><ta";
  char xml4[] = "g></tag>";
  unsigned char ret;
  unsigned char on_tag(char *name) {
    static int c = 0;
    if (strcmp("tag", name) == 0 && c == 0) {
      c++;
    } else if (strcmp("/tag", name) == 0 && c == 1) {
      c++;
    }
    if (c==2) {
      return 0x01;
    }
    return 0x00;
  }
  explorer = sxml_make_explorer();
  sxml_register_func(explorer, &on_tag, ((void *)0), ((void *)0), ((void *)0));
  ret = sxml_run_explorer(explorer, xml1);
  { CU_assertImplementation((explorer->state == IN_DECLARATION), 40, "explorer->state == IN_DECLARATION", "test-private.c", "", 0); };
  ret = sxml_run_explorer(explorer, xml2);
  { CU_assertImplementation((explorer->state == IN_DECLARATION), 42, "explorer->state == IN_DECLARATION", "test-private.c", "", 0); };
  ret = sxml_run_explorer(explorer, xml3);
  { CU_assertImplementation((explorer->state == IN_TAG), 44, "explorer->state == IN_TAG", "test-private.c", "", 0); };
  { CU_assertImplementation((strcmp(explorer->buffer, "ta") == 0), 45, "strcmp(explorer->buffer, \"ta\") == 0", "test-private.c", "", 0); };
  ret = sxml_run_explorer(explorer, xml4);
  { CU_assertImplementation((explorer->state == IN_CONTENT), 47, "explorer->state == IN_CONTENT", "test-private.c", "", 0); };
  { CU_assertImplementation((ret == 0x03), 48, "ret == SXMLExplorerInterrupted", "test-private.c", "", 0); };
  sxml_destroy_explorer(explorer);
}

variable_types:
ret
unsigned char

variable_types: c int

user_defined_types: enum __SXMLExplorerState { INITIAL=0, IN_DECLARATION=1, IN_TAG=2, IN_ATTRIBUTE_KEY=3, IN_ATTRIBUTE_VALUE=4, IN_CONTENT=5 }


decompiled_code:
__int64 __fastcall add_private_test(_QWORD *a1)
{
CU_add_test(*a1, "initialize phase", test_initialize_explorer);
return CU_add_test(*a1, "Parse simple separated XML", test_parse_separated_xml);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
CU_add_test(*a1, "initialize phase", test_initialize_explorer);
return CU_add_test(*a1, "Parse simple separated XML", test_parse_separated_xml);
}

original_code:
void add_private_test(CU_pSuite* suite) {
  CU_add_test(*suite, "initialize phase", test_initialize_explorer);
  CU_add_test(*suite, "Parse simple separated XML", test_parse_separated_xml);
}

canonical_original_code:
void add_private_test(struct CU_Suite **suite) {
  CU_add_test(*suite, "initialize phase", test_initialize_explorer);
  CU_add_test(*suite, "Parse simple separated XML", test_parse_separated_xml);
}

variable_types: struct CU_Suite { char *pName; int fActive; struct CU_Test { char *pName; int fActive; void (*pTestFunc)(); struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*pJumpBuf)[1]; struct CU_Test *pNext; struct CU_Test *pPrev; } *pTest; int (*pInitializeFunc)(); int (*pCleanupFunc)(); void (*pSetUpFunc)(); void (*pTearDownFunc)(); unsigned int uiNumberOfTests; struct CU_Suite *pNext; struct CU_Suite *pPrev; unsigned int uiNumberOfTestsFailed; unsigned int uiNumberOfTestsSuccess; } **


original_code:
unsigned char priv_sxml_change_explorer_state(SXMLExplorer* explorer, SXMLExplorerState state) {
  unsigned char ret = 0x00;
  if (strlen(explorer->buffer) > 0) {
           if (explorer->state == IN_TAG && state == IN_CONTENT && explorer->tag_func != ((void *)0)) {
      ret = explorer->tag_func(explorer->buffer);
    } else if (explorer->state == IN_TAG && state == IN_TAG && explorer->tag_func != ((void *)0)) {
      ret = explorer->tag_func(explorer->buffer);
    } else if (explorer->state == IN_TAG && state == IN_ATTRIBUTE_KEY && explorer->tag_func != ((void *)0)) {
      ret = explorer->tag_func(explorer->buffer);
    } else if (explorer->state == IN_CONTENT && state == IN_TAG && explorer->content_func != ((void *)0)) {
      ret = explorer->content_func(explorer->buffer);
    } else if (explorer->state == IN_ATTRIBUTE_KEY && state == IN_ATTRIBUTE_VALUE && explorer->attribute_key_func != ((void *)0)) {
      ret = explorer->attribute_key_func(explorer->buffer);
    } else if (explorer->state == IN_ATTRIBUTE_VALUE && state == IN_TAG && explorer->attribute_value_func != ((void *)0)) {
      ret = explorer->attribute_value_func(explorer->buffer);
    }
  }
  explorer->bp = 0;
  explorer->buffer[0] = '\0';
  explorer->state = state;
  return ret;
}

canonical_original_code:
unsigned char priv_sxml_change_explorer_state(struct __SXMLExplorer *explorer, enum __SXMLExplorerState state) {
  unsigned char ret = 0x00;
  if (strlen(explorer->buffer) > 0) {
           if (explorer->state == IN_TAG && state == IN_CONTENT && explorer->tag_func != ((void *)0)) {
      ret = explorer->tag_func(explorer->buffer);
    } else if (explorer->state == IN_TAG && state == IN_TAG && explorer->tag_func != ((void *)0)) {
      ret = explorer->tag_func(explorer->buffer);
    } else if (explorer->state == IN_TAG && state == IN_ATTRIBUTE_KEY && explorer->tag_func != ((void *)0)) {
      ret = explorer->tag_func(explorer->buffer);
    } else if (explorer->state == IN_CONTENT && state == IN_TAG && explorer->content_func != ((void *)0)) {
      ret = explorer->content_func(explorer->buffer);
    } else if (explorer->state == IN_ATTRIBUTE_KEY && state == IN_ATTRIBUTE_VALUE && explorer->attribute_key_func != ((void *)0)) {
      ret = explorer->attribute_key_func(explorer->buffer);
    } else if (explorer->state == IN_ATTRIBUTE_VALUE && state == IN_TAG && explorer->attribute_value_func != ((void *)0)) {
      ret = explorer->attribute_value_func(explorer->buffer);
    }
  }
  explorer->bp = 0;
  explorer->buffer[0] = '\0';
  explorer->state = state;
  return ret;
}

variable_types: enum __SXMLExplorerState { INITIAL=0, IN_DECLARATION=1, IN_TAG=2, IN_ATTRIBUTE_KEY=3, IN_ATTRIBUTE_VALUE=4, IN_CONTENT=5 }


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

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

original_code:
SXMLExplorerState sxml_check_explorer_state(SXMLExplorer* ex) {
  return ex->state;
}

canonical_original_code:
enum __SXMLExplorerState sxml_check_explorer_state(struct __SXMLExplorer *ex) {
  return ex->state;
}

return_type: enum __SXMLExplorerState { INITIAL=0, IN_DECLARATION=1, IN_TAG=2, IN_ATTRIBUTE_KEY=3, IN_ATTRIBUTE_VALUE=4, IN_CONTENT=5 }


decompiled_code:
_DWORD *sxml_make_explorer()
{
_DWORD *result; // rax

result = malloc(0x430uLL);
*result = 0;
result[257] = 0;
*((_BYTE *)result + 4) = 0;
*((_BYTE *)result + 1032) = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *result; // rax

result = malloc(0x430uLL);
*result = 0;
result[257] = 0;
*((_BYTE *)result + 4) = 0;
*((_BYTE *)result + 1032) = 0;
return result;
}

original_code:
SXMLExplorer* sxml_make_explorer(void) {
  SXMLExplorer* explorer;
  explorer = malloc(sizeof(SXMLExplorer));
  explorer->state = INITIAL;
  explorer->bp = 0;
  explorer->buffer[0] = '\0';
  explorer->header_parsed = 0;
  return explorer;
}

canonical_original_code:
struct __SXMLExplorer *sxml_make_explorer() {
  struct __SXMLExplorer *explorer;
  explorer = malloc(sizeof(SXMLExplorer));
  explorer->state = INITIAL;
  explorer->bp = 0;
  explorer->buffer[0] = '\0';
  explorer->header_parsed = 0;
  return explorer;
}

return_type: struct __SXMLExplorer { enum __SXMLExplorerState { INITIAL=0, IN_DECLARATION=1, IN_TAG=2, IN_ATTRIBUTE_KEY=3, IN_ATTRIBUTE_VALUE=4, IN_CONTENT=5 } state; char buffer[1024]; unsigned int bp; unsigned char header_parsed; unsigned char (*tag_func)(char *); unsigned char (*content_func)(char *); unsigned char (*attribute_value_func)(char *); unsigned char (*attribute_key_func)(char *); } *


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

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

original_code:
void sxml_destroy_explorer(SXMLExplorer *explorer) {
  free(explorer);
}

canonical_original_code:
void sxml_destroy_explorer(struct __SXMLExplorer *explorer) {
  free(explorer);
}


decompiled_code:
__int64 __fastcall sxml_run_explorer(__int64 a1, char *a2)
{
char v3; // cl
unsigned int v4; // edx
__int64 v5; // rax
size_t v6; // rax
char v7; // al
size_t v8; // rax
unsigned int v9; // eax
unsigned int v10; // eax

do
{
switch ( *(_DWORD *)a1 )
{
case 0:
v3 = priv_sxml_change_explorer_state((int *)a1, 2);
goto LABEL_3;
case 1:
v3 = 0;
if ( *a2 == 62 )
{
v6 = strlen((const char *)(a1 + 4));
v3 = 0;
if ( *(_BYTE *)(a1 + v6 + 3) == 63 )
goto LABEL_19;
}
goto LABEL_3;
case 2:
v7 = *a2;
if ( *a2 == 62 )
goto LABEL_19;
if ( v7 == 63 )
{
v8 = strlen((const char *)(a1 + 4));
v3 = 0;
if ( *(_BYTE *)(a1 + v8 + 3) != 60 )
goto LABEL_3;
LODWORD(v5) = priv_sxml_change_explorer_state((int *)a1, 1);
v3 = v5;
}
else
{
v3 = 0;
if ( v7 != 32 )
goto LABEL_3;
LODWORD(v5) = priv_sxml_change_explorer_state((int *)a1, 3);
v3 = v5;
}
break;
case 3:
if ( *a2 == 34 )
{
v9 = *(_DWORD *)(a1 + 1028);
if ( v9 <= 1 )
_assert_fail("explorer->bp > 1", "sparsexml.c", 0x70u, "sxml_run_explorer");
v10 = v9 - 1;
*(_DWORD *)(a1 + 1028) = v10;
*(_BYTE *)(a1 + v10 + 4) = 0;
LODWORD(v5) = priv_sxml_change_explorer_state((int *)a1, 4);
v3 = v5;
}
else if ( *a2 == 62 )
{
LABEL_19:
LODWORD(v5) = priv_sxml_change_explorer_state((int *)a1, 5);
v3 = v5;
}
else
{
v3 = 0;
LABEL_3:
v4 = *(_DWORD *)(a1 + 1028);
*(_DWORD *)(a1 + 1028) = v4 + 1;
*(_BYTE *)(a1 + v4 + 4) = *a2;
v5 = v4 + 1;
*(_BYTE *)(a1 + v5 + 4) = 0;
}
break;
case 4:
v3 = 0;
if ( *a2 == 34 )
goto LABEL_24;
goto LABEL_3;
case 5:
v3 = 0;
if ( *a2 != 60 )
goto LABEL_3;
LABEL_24:
LODWORD(v5) = priv_sxml_change_explorer_state((int *)a1, 2);
v3 = v5;
break;
default:
v3 = 0;
goto LABEL_3;
}
++a2;
}
while ( *a2 && !v3 );
LOBYTE(v5) = v3 == 1;
return (unsigned int)(v5 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2)
{
char v3; // cl
unsigned int v4; // edx
__int64 v5; // rax
size_t v6; // rax
char v7; // al
size_t v8; // rax
unsigned int v9; // eax
unsigned int v10; // eax

do
{
switch ( *(_DWORD *)a1 )
{
case 0:
v3 = func0((int *)a1, 2);
goto LABEL_3;
case 1:
v3 = 0;
if ( *a2 == 62 )
{
v6 = strlen((const char *)(a1 + 4));
v3 = 0;
if ( *(_BYTE *)(a1 + v6 + 3) == 63 )
goto LABEL_19;
}
goto LABEL_3;
case 2:
v7 = *a2;
if ( *a2 == 62 )
goto LABEL_19;
if ( v7 == 63 )
{
v8 = strlen((const char *)(a1 + 4));
v3 = 0;
if ( *(_BYTE *)(a1 + v8 + 3) != 60 )
goto LABEL_3;
LODWORD(v5) = func0((int *)a1, 1);
v3 = v5;
}
else
{
v3 = 0;
if ( v7 != 32 )
goto LABEL_3;
LODWORD(v5) = func0((int *)a1, 3);
v3 = v5;
}
break;
case 3:
if ( *a2 == 34 )
{
v9 = *(_DWORD *)(a1 + 1028);
if ( v9 <= 1 )
_assert_fail("explorer->bp > 1", "sparsexml.c", 0x70u, "sxml_run_explorer");
v10 = v9 - 1;
*(_DWORD *)(a1 + 1028) = v10;
*(_BYTE *)(a1 + v10 + 4) = 0;
LODWORD(v5) = func0((int *)a1, 4);
v3 = v5;
}
else if ( *a2 == 62 )
{
LABEL_19:
LODWORD(v5) = func0((int *)a1, 5);
v3 = v5;
}
else
{
v3 = 0;
LABEL_3:
v4 = *(_DWORD *)(a1 + 1028);
*(_DWORD *)(a1 + 1028) = v4 + 1;
*(_BYTE *)(a1 + v4 + 4) = *a2;
v5 = v4 + 1;
*(_BYTE *)(a1 + v5 + 4) = 0;
}
break;
case 4:
v3 = 0;
if ( *a2 == 34 )
goto LABEL_24;
goto LABEL_3;
case 5:
v3 = 0;
if ( *a2 != 60 )
goto LABEL_3;
LABEL_24:
LODWORD(v5) = func0((int *)a1, 2);
v3 = v5;
break;
default:
v3 = 0;
goto LABEL_3;
}
++a2;
}
while ( *a2 && !v3 );
LOBYTE(v5) = v3 == 1;
return (unsigned int)(v5 + 2);
}

original_code:
unsigned char sxml_run_explorer(SXMLExplorer* explorer, char *xml) {
  unsigned char result = 0x00;
  do {
    switch (explorer->state) {
      case INITIAL:
        switch (*xml) {
          default:
            result = priv_sxml_change_explorer_state(explorer, IN_TAG);
        }
        break;
      case IN_DECLARATION:
        switch (*xml) {
          case '>':
            if (explorer->buffer[strlen(explorer->buffer)-1] != '?') {
              break;
            }
            result = priv_sxml_change_explorer_state(explorer, IN_CONTENT);
            continue;
        }
        break;
      case IN_TAG:
        switch (*xml) {
          case '>':
            result = priv_sxml_change_explorer_state(explorer, IN_CONTENT);
            continue;
          case ' ':
            result = priv_sxml_change_explorer_state(explorer, IN_ATTRIBUTE_KEY);
            continue;
          case '?':
            if (explorer->buffer[strlen(explorer->buffer)-1] != '<') {
              break;
            }
            result = priv_sxml_change_explorer_state(explorer, IN_DECLARATION);
            continue;
        }
        break;
      case IN_ATTRIBUTE_KEY:
        switch (*xml) {
          case '>':
            result = priv_sxml_change_explorer_state(explorer, IN_CONTENT);
            continue;
          case '"':
            ((void) sizeof ((explorer->bp > 1) ? 1 : 0), __extension__ ({ if (explorer->bp > 1) ; else __assert_fail ("explorer->bp > 1", "sparsexml.c", 112, __extension__ __PRETTY_FUNCTION__); }));
            explorer->bp--;
            explorer->buffer[explorer->bp] = '\0';
            result = priv_sxml_change_explorer_state(explorer, IN_ATTRIBUTE_VALUE);
            continue;
        }
      case IN_ATTRIBUTE_VALUE:
        switch (*xml) {
          case '"':
            result = priv_sxml_change_explorer_state(explorer, IN_TAG);
            continue;
        }
        break;
      case IN_CONTENT:
        switch (*xml) {
          case '<':
            result = priv_sxml_change_explorer_state(explorer, IN_TAG);
            continue;
        }
        break;
    }
    explorer->buffer[explorer->bp++] = *xml;
    explorer->buffer[explorer->bp] = '\0';
  } while ((*++xml != '\0') && (result == 0x00));
  if (result == 0x01) {
    return 0x03;
  }
  return 0x02;
}

canonical_original_code:
unsigned char sxml_run_explorer(struct __SXMLExplorer *explorer, char *xml) {
  unsigned char result = 0x00;
  do {
    switch (explorer->state) {
      case INITIAL:
        switch (*xml) {
          default:
            result = priv_sxml_change_explorer_state(explorer, IN_TAG);
        }
        break;
      case IN_DECLARATION:
        switch (*xml) {
          case '>':
            if (explorer->buffer[strlen(explorer->buffer)-1] != '?') {
              break;
            }
            result = priv_sxml_change_explorer_state(explorer, IN_CONTENT);
            continue;
        }
        break;
      case IN_TAG:
        switch (*xml) {
          case '>':
            result = priv_sxml_change_explorer_state(explorer, IN_CONTENT);
            continue;
          case ' ':
            result = priv_sxml_change_explorer_state(explorer, IN_ATTRIBUTE_KEY);
            continue;
          case '?':
            if (explorer->buffer[strlen(explorer->buffer)-1] != '<') {
              break;
            }
            result = priv_sxml_change_explorer_state(explorer, IN_DECLARATION);
            continue;
        }
        break;
      case IN_ATTRIBUTE_KEY:
        switch (*xml) {
          case '>':
            result = priv_sxml_change_explorer_state(explorer, IN_CONTENT);
            continue;
          case '"':
            ((void) sizeof ((explorer->bp > 1) ? 1 : 0), __extension__ ({ if (explorer->bp > 1) ; else __assert_fail ("explorer->bp > 1", "sparsexml.c", 112, __extension__ __PRETTY_FUNCTION__); }));
            explorer->bp--;
            explorer->buffer[explorer->bp] = '\0';
            result = priv_sxml_change_explorer_state(explorer, IN_ATTRIBUTE_VALUE);
            continue;
        }
      case IN_ATTRIBUTE_VALUE:
        switch (*xml) {
          case '"':
            result = priv_sxml_change_explorer_state(explorer, IN_TAG);
            continue;
        }
        break;
      case IN_CONTENT:
        switch (*xml) {
          case '<':
            result = priv_sxml_change_explorer_state(explorer, IN_TAG);
            continue;
        }
        break;
    }
    explorer->buffer[explorer->bp++] = *xml;
    explorer->buffer[explorer->bp] = '\0';
  } while ((*++xml != '\0') && (result == 0x00));
  if (result == 0x01) {
    return 0x03;
  }
  return 0x02;
}

variable_types:
xml
char *

variable_types:
result
unsigned char


decompiled_code:
int log_close()
{
pthread_mutex_lock(&log_mutex);
if ( log_fp )
{
fclose(log_fp);
log_fp = 0LL;
}
return pthread_mutex_unlock(&log_mutex);
}

canonical_decompiled_code:
int func0()
{
pthread_mutex_lock(&log_mutex);
if ( log_fp )
{
fclose(log_fp);
log_fp = 0LL;
}
return pthread_mutex_unlock(&log_mutex);
}

original_code:
void log_close(void) {
 pthread_mutex_lock(&log_mutex);
 if (log_fp) {
  fclose(log_fp);
  log_fp = ((void *)0);
 }
 pthread_mutex_unlock(&log_mutex);
 return ;
}

canonical_original_code:
void log_close() {
 pthread_mutex_lock(&log_mutex);
 if (log_fp) {
  fclose(log_fp);
  log_fp = ((void *)0);
 }
 pthread_mutex_unlock(&log_mutex);
 return ;
}


lerror

decompiled_code:
int __fastcall lerror(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return lprintf("%s: %s\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return func1("%s: %s\n", a1, v2);
}

original_code:
void lerror(char *str) {
 lprintf("%s: %s\n", str, strerror((*__errno_location ())));
 return ;
}

variable_types:
str
char *


lraw

decompiled_code:
int __fastcall lraw(char *format)
{
return fprintf(log_fp, format);
}

canonical_decompiled_code:
int __fastcall func3(char *format)
{
return fprintf(log_fp, format);
}

original_code:
void lraw(char *str) {
 fprintf(log_fp, str);
}


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

pthread_mutex_lock(&log_mutex);
if ( !logfile )
logfile = (char *)hashtable_lookup(cfg, "daemon-logfile");
if ( log_fp || (log_fp = fopen(logfile, "a+")) != 0LL )
{
pthread_mutex_unlock(&log_mutex);
result = 1LL;
}
else
{
perror(logfile);
pthread_mutex_unlock(&log_mutex);
result = 0LL;
}
return result;
}

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

pthread_mutex_lock(&log_mutex);
if ( !logfile )
logfile = (char *)hashtable_lookup(cfg, "daemon-logfile");
if ( log_fp || (log_fp = fopen(logfile, "a+")) != 0LL )
{
pthread_mutex_unlock(&log_mutex);
result = 1LL;
}
else
{
perror(logfile);
pthread_mutex_unlock(&log_mutex);
result = 0LL;
}
return result;
}

original_code:
int log_open(void) {
 pthread_mutex_lock(&log_mutex);
 if (!logfile) {
  logfile = hashtable_lookup(cfg, "daemon-logfile");
 }
 if (!log_fp) {
  log_fp = fopen(logfile, "a+");
  if (!log_fp) {
   perror(logfile);
   pthread_mutex_unlock(&log_mutex);
   return 0;
  }
 }
 pthread_mutex_unlock(&log_mutex);
 return 1;
}

canonical_original_code:
int log_open() {
 pthread_mutex_lock(&log_mutex);
 if (!logfile) {
  logfile = hashtable_lookup(cfg, "daemon-logfile");
 }
 if (!log_fp) {
  log_fp = fopen(logfile, "a+");
  if (!log_fp) {
   perror(logfile);
   pthread_mutex_unlock(&log_mutex);
   return 0;
  }
 }
 pthread_mutex_unlock(&log_mutex);
 return 1;
}


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

log_close();
result = remove(logfile);
if ( !result )
result = log_open();
return result;
}

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

func0();
result = remove(logfile);
if ( !result )
result = func4();
return result;
}

original_code:
int log_restart(void) {
 int retval;
 log_close();
 retval = remove(logfile);
  if (retval == 0) {
  retval = log_open();
 }
 return retval;
}

canonical_original_code:
int log_restart() {
 int retval;
 log_close();
 retval = remove(logfile);
  if (retval == 0) {
  retval = log_open();
 }
 return retval;
}

variable_types: retval int


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

*(&opipes + a1) = dup(a1 + 1);
result = pipe(&spipes[2 * a1]);
if ( !result )
result = dup2(dword_3C4[2 * a1], a1 + 1);
return result;
}

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

*(&opipes + a1) = dup(a1 + 1);
result = pipe(&spipes[2 * a1]);
if ( !result )
result = dup2(dword_3C4[2 * a1], a1 + 1);
return result;
}

original_code:
void io_bufferpipe(int idx) {
 opipes[idx] = dup(idx+1);
 if (!(pipe(spipes[idx]))) {
  dup2(spipes[idx][1], idx+1);
 }
 return ;
}

variable_types: idx int


decompiled_code:
void __fastcall io_killbuf(int a1)
{
void *v2; // rdi
void *v3; // rdi

v2 = (void *)streamsbufs[3 * a1];
if ( v2 )
free(v2);
v3 = (void *)qword_388[3 * a1];
if ( v3 )
free(v3);
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
void *v2; // rdi
void *v3; // rdi

v2 = (void *)streamsbufs[3 * a1];
if ( v2 )
free(v2);
v3 = (void *)qword_388[3 * a1];
if ( v3 )
free(v3);
}

original_code:
void io_killbuf(int idx) {
 if (streamsbufs[idx].buf) {
  free(streamsbufs[idx].buf);
 }
 if (streamsbufs[idx].fname) {
  free(streamsbufs[idx].fname);
 }
 return ;
}


decompiled_code:
int __fastcall io_bufpipe(int fd, int a2)
{
int result; // eax
int v3; // ebx
size_t v4; // r12
void *v5; // rdi
fd_set v6; // [rsp+0h] [rbp-4A8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-428h] BYREF
char buf[1048]; // [rsp+90h] [rbp-418h] BYREF

memset(&v6, 0, sizeof(v6));
v6.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = 5LL;
result = select(fd + 1, &v6, 0LL, 0LL, &timeout);
if ( result > 0 )
{
memset(buf, 0, 0x400uLL);
result = read(fd, buf, 0x400uLL);
v3 = result;
if ( result >= 0 )
{
v4 = result;
v5 = calloc(result, 1uLL);
result = 3 * a2;
streamsbufs[3 * a2] = (__int64)v5;
if ( v5 )
{
memcpy(v5, buf, v4);
result = 3 * a2;
dword_390[6 * a2] = v3;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int fd, int a2)
{
int result; // eax
int v3; // ebx
size_t v4; // r12
void *v5; // rdi
fd_set v6; // [rsp+0h] [rbp-4A8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-428h] BYREF
char buf[1048]; // [rsp+90h] [rbp-418h] BYREF

memset(&v6, 0, sizeof(v6));
v6.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = 5LL;
result = select(fd + 1, &v6, 0LL, 0LL, &timeout);
if ( result > 0 )
{
memset(buf, 0, 0x400uLL);
result = read(fd, buf, 0x400uLL);
v3 = result;
if ( result >= 0 )
{
v4 = result;
v5 = calloc(result, 1uLL);
result = 3 * a2;
streamsbufs[3 * a2] = (__int64)v5;
if ( v5 )
{
memcpy(v5, buf, v4);
result = 3 * a2;
dword_390[6 * a2] = v3;
}
}
}
return result;
}

original_code:
void io_bufpipe(int fd, int bidx) {
 char tmpbuf[1024];
 struct timeval tv;
 int rval;
 fd_set rfd;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfd)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rfd)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 0;
 tv.tv_usec = 5;
 rval = select(fd+1, &rfd, ((void *)0), ((void *)0), &tv);
 if (rval <= 0) {
  return ;
 }
 memset(tmpbuf, 0x0, sizeof(tmpbuf));
 rval = read(fd, tmpbuf, sizeof(tmpbuf));
 if (rval < 0) {
  return ;
 }
 streamsbufs[bidx].buf = calloc(rval, sizeof(char));
 if (streamsbufs[bidx].buf) {
  memcpy(streamsbufs[bidx].buf, tmpbuf, rval);
  streamsbufs[bidx].buflen = rval;
 }
 return ;
}

canonical_original_code:
void io_bufpipe(int fd, int bidx) {
 char tmpbuf[1024];
 struct timeval tv;
 int rval;
 struct fd_set rfd;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfd)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rfd)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 0;
 tv.tv_usec = 5;
 rval = select(fd+1, &rfd, ((void *)0), ((void *)0), &tv);
 if (rval <= 0) {
  return ;
 }
 memset(tmpbuf, 0x0, sizeof(tmpbuf));
 rval = read(fd, tmpbuf, sizeof(tmpbuf));
 if (rval < 0) {
  return ;
 }
 streamsbufs[bidx].buf = calloc(rval, sizeof(char));
 if (streamsbufs[bidx].buf) {
  memcpy(streamsbufs[bidx].buf, tmpbuf, rval);
  streamsbufs[bidx].buflen = rval;
 }
 return ;
}

variable_types: fd int

variable_types: bidx int

variable_types:
tmpbuf
char [1024]

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

variable_types: rval int

variable_types:
rfd
struct fd_set { long __fds_bits[-1]; }


decompiled_code:
int __fastcall io_releasepipe(int a1)
{
int result; // eax
const char *v3; // rdi
int v4; // ebp

result = a1;
if ( spipes[2 * a1] > 0 )
{
close(dword_3C4[2 * a1]);
if ( qword_388[3 * a1] )
io_bufpipe(spipes[2 * a1], a1);
close(spipes[2 * a1]);
if ( streamsbufs[3 * a1] )
{
v3 = (const char *)qword_388[3 * a1];
if ( v3 )
{
v4 = open(v3, 65);
if ( v4 > 0 )
{
write(v4, (const void *)streamsbufs[3 * a1], dword_390[6 * a1]);
close(v4);
}
}
}
result = dup2(*(&opipes + a1), a1 + 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int result; // eax
const char *v3; // rdi
int v4; // ebp

result = a1;
if ( spipes[2 * a1] > 0 )
{
close(dword_3C4[2 * a1]);
if ( qword_388[3 * a1] )
func4(spipes[2 * a1], a1);
close(spipes[2 * a1]);
if ( streamsbufs[3 * a1] )
{
v3 = (const char *)qword_388[3 * a1];
if ( v3 )
{
v4 = open(v3, 65);
if ( v4 > 0 )
{
write(v4, (const void *)streamsbufs[3 * a1], dword_390[6 * a1]);
close(v4);
}
}
}
result = dup2(*(&opipes + a1), a1 + 1);
}
return result;
}

original_code:
void io_releasepipe(int idx) {
 int fd;
 if (spipes[idx][0] > 0) {
  close(spipes[idx][1]);
  if (streamsbufs[idx].fname) {
   io_bufpipe(spipes[idx][0], idx);
  }
  close(spipes[idx][0]);
  if (streamsbufs[idx].buf && streamsbufs[idx].fname) {
   fd = open(streamsbufs[idx].fname, 0100|01);
   if (fd > 0) {
    write(fd, streamsbufs[idx].buf, streamsbufs[idx].buflen);
    close(fd);
   }
  }
  dup2(opipes[idx], idx+1);
 }
 return ;
}


decompiled_code:
__int64 io_buffer()
{
return _io_foreach((__int64 (__fastcall *)(_QWORD))io_bufferpipe, 2);
}

canonical_decompiled_code:
__int64 func6()
{
return func1((__int64 (__fastcall *)(_QWORD))io_bufferpipe, 2);
}

original_code:
void io_buffer(void) {
 __io_foreach(io_bufferpipe, 2);
 return ;
}

canonical_original_code:
void io_buffer() {
 __io_foreach(io_bufferpipe, 2);
 return ;
}


decompiled_code:
__int64 io_release()
{
fflush(stdout);
fflush(stderr);
return _io_foreach((__int64 (__fastcall *)(_QWORD))io_releasepipe, 2);
}

canonical_decompiled_code:
__int64 func7()
{
fflush(stdout);
fflush(stderr);
return func1((__int64 (__fastcall *)(_QWORD))io_releasepipe, 2);
}

original_code:
void io_release(void) {
 fflush(stdout);
 fflush(stderr);
 __io_foreach(io_releasepipe, 2);
 return ;
}

canonical_original_code:
void io_release() {
 fflush(stdout);
 fflush(stderr);
 __io_foreach(io_releasepipe, 2);
 return ;
}


decompiled_code:
int io_fastrelease()
{
dup2(opipes, 1);
return dup2(fd, 2);
}

canonical_decompiled_code:
int func8()
{
dup2(opipes, 1);
return dup2(fd, 2);
}

original_code:
void io_fastrelease(void) {
 dup2(opipes[0], 1);
 dup2(opipes[1], 2);
 return ;
}

canonical_original_code:
void io_fastrelease() {
 dup2(opipes[0], 1);
 dup2(opipes[1], 2);
 return ;
}


decompiled_code:
__int64 __fastcall io_foutput(int a1, const char *a2)
{
if ( !qword_388[3 * a1] )
qword_388[3 * a1] = (__int64)strdup(a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, const char *a2)
{
if ( !qword_388[3 * a1] )
qword_388[3 * a1] = (__int64)strdup(a2);
return 1LL;
}

original_code:
int io_foutput(int idx, char *file) {
 if (!streamsbufs[idx].fname) {
  streamsbufs[idx].fname = strdup(file);
 }
 return 1;
}

variable_types:
file
char *


decompiled_code:
__int64 io_killbufs()
{
return _io_foreach((__int64 (__fastcall *)(_QWORD))io_killbuf, 2);
}

canonical_decompiled_code:
__int64 func10()
{
return func1((__int64 (__fastcall *)(_QWORD))io_killbuf, 2);
}

original_code:
void io_killbufs(void) {
 __io_foreach(io_killbuf, 2);
 return ;
}

canonical_original_code:
void io_killbufs() {
 __io_foreach(io_killbuf, 2);
 return ;
}


decompiled_code:
__int64 io_get_stdout()
{
return _io_getbuf(0);
}

canonical_decompiled_code:
__int64 func11()
{
return func0(0);
}

original_code:
char *io_get_stdout(void) {
 return __io_getbuf(0);
}

canonical_original_code:
char *io_get_stdout() {
 return __io_getbuf(0);
}

return_type: char *


decompiled_code:
__int64 io_get_stderr()
{
return _io_getbuf(1);
}

canonical_decompiled_code:
__int64 func12()
{
return func0(1);
}

original_code:
char *io_get_stderr(void) {
 return __io_getbuf(1);
}

canonical_original_code:
char *io_get_stderr() {
 return __io_getbuf(1);
}