decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rdx
_QWORD *v11; // rbp
__int64 v12; // rax
__int64 v13; // rcx
__int64 v14; // rdx
int v16[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = linked_list_append(0LL, 1LL, envp);
v5 = linked_list_append(v3, 2LL, v4);
v7 = linked_list_append(v5, 3LL, v6);
v9 = linked_list_append(v7, 4LL, v8);
v11 = (_QWORD *)linked_list_append(v9, 5LL, v10);
v12 = v11[1];
v13 = *(_QWORD *)(v12 + 8);
do
{
v14 = v12;
v12 = *(_QWORD *)(v12 + 8);
}
while ( v12 );
*(_QWORD *)(v14 + 8) = v13;
v16[0] = 0;
begining_of_loop(v11, v16);
if ( v16[0] != 3 )
__assert_fail("3 == value", "2.5.c", 0x49u, "main");
linked_list_print(v11);
linked_list_free(v11);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rdx
_QWORD *v11; // rbp
__int64 v12; // rax
__int64 v13; // rcx
__int64 v14; // rdx
int v16[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = linked_list_append(0LL, 1LL, envp);
v5 = linked_list_append(v3, 2LL, v4);
v7 = linked_list_append(v5, 3LL, v6);
v9 = linked_list_append(v7, 4LL, v8);
v11 = (_QWORD *)linked_list_append(v9, 5LL, v10);
v12 = v11[1];
v13 = *(_QWORD *)(v12 + 8);
do
{
v14 = v12;
v12 = *(_QWORD *)(v12 + 8);
}
while ( v12 );
*(_QWORD *)(v14 + 8) = v13;
v16[0] = 0;
func9(v11, v16);
if ( v16[0] != 3 )
__assert_fail("3 == value", "2.5.c", 0x49u, "main");
func13(v11);
func12(v11);
return 0;
}

original_code:
int main() {
  LinkedList *list = ((void *)0);
  list = linked_list_append(list, 1);
  list = linked_list_append(list, 2);
  list = linked_list_append(list, 3);
  list = linked_list_append(list, 4);
  list = linked_list_append(list, 5);
  LinkedList *third_node = list->next->next;
  LinkedList *tail = list;
  while (((void *)0) != tail->next) tail = tail->next;
  tail->next = third_node;
  int value = 0;
  begining_of_loop(list, &value);
  ((3 == value) ? (void) (0) : __assert_fail ("3 == value", "2.5.c", 73, __extension__ __PRETTY_FUNCTION__));
  linked_list_print(list);
  linked_list_free(list);
}

canonical_original_code:
int main() {
  struct _LinkedList *list = ((void *)0);
  list = linked_list_append(list, 1);
  list = linked_list_append(list, 2);
  list = linked_list_append(list, 3);
  list = linked_list_append(list, 4);
  list = linked_list_append(list, 5);
  struct _LinkedList *third_node = list->next->next;
  struct _LinkedList *tail = list;
  while (((void *)0) != tail->next) tail = tail->next;
  tail->next = third_node;
  int value = 0;
  begining_of_loop(list, &value);
  ((3 == value) ? (void) (0) : __assert_fail ("3 == value", "2.5.c", 73, __extension__ __PRETTY_FUNCTION__));
  linked_list_print(list);
  linked_list_free(list);
}

variable_types: value int


repo: kkpattern/CTCI

original_code:
void matrix_free(IntMatrix *matrix) {
  for (int i = 0; i < matrix->row_size; ++i) free(matrix->data[i]);
  free(matrix->data);
  matrix->data = ((void *)0);
}

canonical_original_code:
void matrix_free(struct _IntMatrix *matrix) {
  for (int i = 0; i < matrix->row_size; ++i) free(matrix->data[i]);
  free(matrix->data);
  matrix->data = ((void *)0);
}

variable_types: struct _IntMatrix { unsigned long row_size; unsigned long column_size; int **data; } *

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall matrix_init(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
size_t v6; // rbx
__int64 v7; // r14
void *v8; // rax

*a1 = a2;
a1[1] = a3;
v4 = calloc(8 * a2, 1uLL);
a1[2] = v4;
if ( v4 )
{
v5 = v4;
v6 = 4 * a3;
v7 = 0LL;
if ( !a2 )
return 0LL;
while ( 1 )
{
v8 = malloc(v6);
v5[v7] = v8;
if ( !v8 )
break;
if ( a2 == ++v7 )
return 0LL;
}
matrix_free((__int64)a1);
}
return 1LL;
}

original_code:
int matrix_init(IntMatrix *matrix, size_t row_size, size_t column_size) {
  int result = 0;
  matrix->row_size = row_size;
  matrix->column_size = column_size;
  matrix->data = (int **) malloc(sizeof(int*) * row_size);
  if (matrix->data == ((void *)0)) return 1;
  for (int i = 0; i < row_size; ++i) matrix->data[i] = ((void *)0);
  for (int i = 0; i < row_size; ++i) {
    matrix->data[i] = (int *) malloc(sizeof(int) * column_size);
    if (matrix->data[i] == ((void *)0)) {
      result = 1;
      break;
    }
  }
  if (result == 1) {
    matrix_free(matrix);
  }
  return result;
}

canonical_original_code:
int matrix_init(struct _IntMatrix *matrix, unsigned long row_size, unsigned long column_size) {
  int result = 0;
  matrix->row_size = row_size;
  matrix->column_size = column_size;
  matrix->data = (int **) malloc(sizeof(int *) * row_size);
  if (matrix->data == ((void *)0)) return 1;
  for (int i = 0; i < row_size; ++i) matrix->data[i] = ((void *)0);
  for (int i = 0; i < row_size; ++i) {
    matrix->data[i] = (int *) malloc(sizeof(int) * column_size);
    if (matrix->data[i] == ((void *)0)) {
      result = 1;
      break;
    }
  }
  if (result == 1) {
    matrix_free(matrix);
  }
  return result;
}

variable_types: result int

return_type: int

user_defined_types: struct _IntMatrix { unsigned long row_size; unsigned long column_size; int **data; }


decompiled_code:
int __fastcall matrix_print(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v9; // r12
__int64 i; // rbx
__int64 v11; // rsi
int result; // eax

v9 = 0LL;
if ( a7 )
{
do
{
if ( a8 )
{
for ( i = 0LL; i != a8; ++i )
{
v11 = *(unsigned int *)(*(_QWORD *)(a9 + 8 * v9) + 4 * i);
printf("%d ", v11);
}
}
++v9;
result = putchar(10);
}
while ( v9 != a7 );
}
return result;
}

original_code:
void matrix_print(IntMatrix matrix) {
  for (size_t i = 0; i < matrix.row_size; ++i) {
    for (size_t j = 0; j < matrix.column_size; ++j) {
      printf("%d ", matrix.data[i][j]);
    }
    printf("\n");
  }
}

canonical_original_code:
void matrix_print(struct _IntMatrix matrix) {
  for (unsigned long i = 0; i < matrix.row_size; ++i) {
    for (unsigned long j = 0; j < matrix.column_size; ++j) {
      printf("%d ", matrix.data[i][j]);
    }
    printf("\n");
  }
}

variable_types: struct _IntMatrix { unsigned long row_size; unsigned long column_size; int **data; }

variable_types:
i
unsigned long

variable_types:
j
unsigned long


original_code:
void matrix_set_zero(IntMatrix *matrix) {
  int *row_mark = (int *) malloc(matrix->row_size*sizeof(int));
  for (size_t i = 0; i < matrix->row_size; ++i) row_mark[i] = 0;
  int *column_mark = (int *) malloc(matrix->column_size*sizeof(int));
  for (size_t i = 0; i < matrix->column_size; ++i) column_mark[i] = 0;
  for (size_t i = 0; i < matrix->row_size; ++i) {
    for (size_t j = 0; j < matrix->column_size; ++j) {
      if (matrix->data[i][j] == 0) {
        row_mark[i] = 1;
        column_mark[j] = 1;
      }
    }
  }
  for (size_t i = 0; i < matrix->row_size; ++i) {
    if (row_mark[i] == 1) {
      for (size_t j = 0; j < matrix->column_size; ++j) {
        matrix->data[i][j] = 0;
      }
    }
  }
  for (size_t j = 0; j < matrix->column_size; ++j) {
    if (column_mark[j] == 1) {
      for (size_t i = 0; i < matrix->row_size; ++i) {
        matrix->data[i][j] = 0;
      }
    }
  }
  free(column_mark);
  free(row_mark);
}

canonical_original_code:
void matrix_set_zero(struct _IntMatrix *matrix) {
  int *row_mark = (int *) malloc(matrix->row_size*sizeof(int));
  for (unsigned long i = 0; i < matrix->row_size; ++i) row_mark[i] = 0;
  int *column_mark = (int *) malloc(matrix->column_size*sizeof(int));
  for (unsigned long i = 0; i < matrix->column_size; ++i) column_mark[i] = 0;
  for (unsigned long i = 0; i < matrix->row_size; ++i) {
    for (unsigned long j = 0; j < matrix->column_size; ++j) {
      if (matrix->data[i][j] == 0) {
        row_mark[i] = 1;
        column_mark[j] = 1;
      }
    }
  }
  for (unsigned long i = 0; i < matrix->row_size; ++i) {
    if (row_mark[i] == 1) {
      for (unsigned long j = 0; j < matrix->column_size; ++j) {
        matrix->data[i][j] = 0;
      }
    }
  }
  for (unsigned long j = 0; j < matrix->column_size; ++j) {
    if (column_mark[j] == 1) {
      for (unsigned long i = 0; i < matrix->row_size; ++i) {
        matrix->data[i][j] = 0;
      }
    }
  }
  free(column_mark);
  free(row_mark);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er8
int v5; // er9
__int64 v6; // rsi
__int64 i; // rax
_DWORD *v8; // rdx
int v9; // ecx
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9
__int64 v15; // [rsp+0h] [rbp-28h] BYREF
__int64 v16; // [rsp+8h] [rbp-20h]
__int64 v17; // [rsp+10h] [rbp-18h]

v3 = 1;
if ( !(unsigned int)matrix_init(&v15, 3LL, 4LL) )
{
v6 = v17;
v3 = 0;
for ( i = 0LL; i != 3; ++i )
{
v8 = *(_DWORD **)(v6 + 8 * i);
v8[1] = i + 1;
*v8 = i;
v8[2] = i + 2;
v9 = i + 3;
v8[3] = v9;
}
matrix_print((unsigned int)&v15, v6, (_DWORD)v8, v9, v4, v5, v15, v16, v17);
matrix_set_zero(&v15);
matrix_print((unsigned int)&v15, v6, v10, v11, v12, v13, v15, v16, v17);
matrix_free(&v15);
}
return v3;
}

original_code:
int main() {
  IntMatrix matrix;
  if (0 != matrix_init(&matrix, 3, 4)) {
    return 1;
  }
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 4; ++j) {
      matrix.data[i][j] = i+j;
    }
  }
  matrix_print(matrix);
  matrix_set_zero(&matrix);
  matrix_print(matrix);
  matrix_free(&matrix);
}

canonical_original_code:
int main() {
  struct _IntMatrix matrix;
  if (0 != matrix_init(&matrix, 3, 4)) {
    return 1;
  }
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 4; ++j) {
      matrix.data[i][j] = i+j;
    }
  }
  matrix_print(matrix);
  matrix_set_zero(&matrix);
  matrix_print(matrix);
  matrix_free(&matrix);
}

variable_types: j int


decompiled_code:
__int64 __fastcall solve_hanoi(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
__int64 v5; // rbp
unsigned __int64 v6; // r13
__int64 result; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a4 <= 1 )
{
v8[0] = 0;
stacks_pop(a1, a2, v8);
result = stacks_push(a1, (unsigned int)a3, (unsigned int)v8[0]);
}
else
{
v5 = 1LL;
if ( a3 == 1 || a2 == 1 )
{
do
{
do
++v5;
while ( a2 == v5 );
}
while ( a3 == v5 );
}
v6 = a4 - 1;
solve_hanoi(a1, a2, v5, a4 - 1);
v8[0] = 0;
stacks_pop(a1, (unsigned int)a2, v8);
stacks_push(a1, (unsigned int)a3, (unsigned int)v8[0]);
result = solve_hanoi(a1, v5, a3, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
__int64 v5; // rbp
unsigned __int64 v6; // r13
__int64 result; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a4 <= 1 )
{
v8[0] = 0;
func9(a1, a2, v8);
result = func8(a1, (unsigned int)a3, (unsigned int)v8[0]);
}
else
{
v5 = 1LL;
if ( a3 == 1 || a2 == 1 )
{
do
{
do
++v5;
while ( a2 == v5 );
}
while ( a3 == v5 );
}
v6 = a4 - 1;
func7(a1, a2, v5, a4 - 1);
v8[0] = 0;
func9(a1, (unsigned int)a2, v8);
func8(a1, (unsigned int)a3, (unsigned int)v8[0]);
result = func7(a1, v5, a3, v6);
}
return result;
}

original_code:
void solve_hanoi(Stacks *stacks, size_t from, size_t to, size_t disk_count) {
  if (1 < disk_count) {
    size_t transit = 1;
    while (transit == from || transit == to) ++transit;
    solve_hanoi(stacks, from, transit, disk_count-1);
    int value = 0;
    stacks_pop(stacks, from, &value);
    stacks_push(stacks, to, value);
    solve_hanoi(stacks, transit, to, disk_count-1);
  } else {
    int value = 0;
    stacks_pop(stacks, from, &value);
    stacks_push(stacks, to, value);
  }
}

canonical_original_code:
void solve_hanoi(struct _Stacks *stacks, unsigned long from, unsigned long to, unsigned long disk_count) {
  if (1 < disk_count) {
    unsigned long transit = 1;
    while (transit == from || transit == to) ++transit;
    solve_hanoi(stacks, from, transit, disk_count-1);
    int value = 0;
    stacks_pop(stacks, from, &value);
    stacks_push(stacks, to, value);
    solve_hanoi(stacks, transit, to, disk_count-1);
  } else {
    int value = 0;
    stacks_pop(stacks, from, &value);
    stacks_push(stacks, to, value);
  }
}

variable_types: struct _Stacks { int *stack; unsigned long stack_number; unsigned long *stack_head; unsigned long stack_size; } *

variable_types:
from
unsigned long

variable_types:
to
unsigned long

variable_types:
transit
unsigned long


original_code:
int stacks_push(Stacks *stacks, int stack_id, int value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  size_t insert_position =
    stacks->stack_head[stack_id-1]*stacks->stack_number+stack_id-1;
  if (insert_position >= stacks->stack_size) {
    size_t new_stack_size = 2*stacks->stack_size;
    int *new_stack = (int *) malloc(sizeof(int) * new_stack_size);
    if (((void *)0) == new_stack) return 2;
    memcpy(new_stack, stacks->stack, sizeof(int)*stacks->stack_size);
    free(stacks->stack);
    stacks->stack = new_stack;
    stacks->stack_size = new_stack_size;
  }
  stacks->stack[insert_position] = value;
  stacks->stack_head[stack_id-1] += 1;
  return 0;
}

canonical_original_code:
int stacks_push(struct _Stacks *stacks, int stack_id, int value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  unsigned long insert_position = stacks->stack_head[stack_id-1]*stacks->stack_number+stack_id-1;
  if (insert_position >= stacks->stack_size) {
    unsigned long new_stack_size = 2*stacks->stack_size;
    int *new_stack = (int *) malloc(sizeof(int) * new_stack_size);
    if (((void *)0) == new_stack) return 2;
    memcpy(new_stack, stacks->stack, sizeof(int)*stacks->stack_size);
    free(stacks->stack);
    stacks->stack = new_stack;
    stacks->stack_size = new_stack_size;
  }
  stacks->stack[insert_position] = value;
  stacks->stack_head[stack_id-1] += 1;
  return 0;
}

user_defined_types: struct _Stacks { int *stack; unsigned long stack_number; unsigned long *stack_head; unsigned long stack_size; }


original_code:
int stacks_pop(Stacks *stacks, int stack_id, int *value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  size_t stack_head = stacks->stack_head[stack_id-1];
  if (0 == stack_head) return 2;
  size_t pop_position = (stack_head-1)*stacks->stack_number+stack_id-1;
  *value = stacks->stack[pop_position];
  stacks->stack_head[stack_id-1] -= 1;
  return 0;
}

canonical_original_code:
int stacks_pop(struct _Stacks *stacks, int stack_id, int *value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  unsigned long stack_head = stacks->stack_head[stack_id-1];
  if (0 == stack_head) return 2;
  unsigned long pop_position = (stack_head-1)*stacks->stack_number+stack_id-1;
  *value = stacks->stack[pop_position];
  stacks->stack_head[stack_id-1] -= 1;
  return 0;
}

variable_types:
value
int *


decompiled_code:
__int64 __fastcall stacks_free(void *ptr)
{
free(*((void **)ptr + 2));
free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *ptr)
{
free(*((void **)ptr + 2));
free(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
Stacks *stacks_free(Stacks *stacks) {
  free(stacks->stack_head);
  free(stacks->stack);
  free(stacks);
  return ((void *)0);
}

canonical_original_code:
struct _Stacks *stacks_free(struct _Stacks *stacks) {
  free(stacks->stack_head);
  free(stacks->stack);
  free(stacks);
  return ((void *)0);
}

variable_types:
stacks
struct _Stacks *

return_type: struct _Stacks { int *stack; unsigned long stack_number; unsigned long *stack_head; unsigned long stack_size; } *


decompiled_code:
__int64 __fastcall stack_push(__int64 a1, int a2)
{
return stacks_push(a1, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
return func8(a1, 1, a2);
}

original_code:
int stack_push(Stack *stack, int value) {
  return stacks_push(stack, 1, value);
}

canonical_original_code:
int stack_push(struct _Stacks *stack, int value) {
  return stacks_push(stack, 1, value);
}


decompiled_code:
__int64 __fastcall stack_pop(_QWORD *a1, _DWORD *a2)
{
return stacks_pop(a1, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, _DWORD *a2)
{
return func9(a1, 1, a2);
}

original_code:
int stack_pop(Stack *stack, int *value) {
  return stacks_pop(stack, 1, value);
}

canonical_original_code:
int stack_pop(struct _Stacks *stack, int *value) {
  return stacks_pop(stack, 1, value);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall stack_free(void *a1)
{
return stacks_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(void *a1)
{
return func10(a1);
}

original_code:
Stack *stack_free(Stack *stack) {
  return stacks_free(stack);
}

canonical_original_code:
struct _Stacks *stack_free(struct _Stacks *stack) {
  return stacks_free(stack);
}

variable_types:
stack
struct _Stacks *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int i; // ebx
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v3 = stacks_init(3LL, 10LL, envp);
stacks_push(v3, 1LL, 3LL);
stacks_push(v3, 1LL, 2LL);
stacks_push(v3, 1LL, 1LL);
solve_hanoi(v3, 1LL, 3LL, 3LL);
if ( (unsigned int)stacks_pop(v3, 1LL, v6) != 2 )
__assert_fail("2 == stacks_pop(stacks, 1, &value)", "3.4.c", 0x2Bu, "main");
for ( i = 1; i != 4; ++i )
{
if ( (unsigned int)stacks_pop(v3, 3LL, v6) )
__assert_fail("0 == stacks_pop(stacks, 3, &value)", "3.4.c", 0x2Eu, "main");
v6[0] = i;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int i; // ebx
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v3 = stacks_init(3LL, 10LL, envp);
func8(v3, 1LL, 3LL);
func8(v3, 1LL, 2LL);
func8(v3, 1LL, 1LL);
func7(v3, 1LL, 3LL, 3LL);
if ( (unsigned int)func9(v3, 1LL, v6) != 2 )
__assert_fail("2 == stacks_pop(stacks, 1, &value)", "3.4.c", 0x2Bu, "main");
for ( i = 1; i != 4; ++i )
{
if ( (unsigned int)func9(v3, 3LL, v6) )
__assert_fail("0 == stacks_pop(stacks, 3, &value)", "3.4.c", 0x2Eu, "main");
v6[0] = i;
}
return 0;
}

original_code:
int main() {
  Stacks *stacks = stacks_init(3, 10);
  size_t disk_count = 3;
  int value = 0;
  for (int i = disk_count; i > 0; --i) {
    stacks_push(stacks, 1, i);
  }
  solve_hanoi(stacks, 1, 3, 3);
  ((2 == stacks_pop(stacks, 1, &value)) ? (void) (0) : __assert_fail ("2 == stacks_pop(stacks, 1, &value)", "3.4.c", 43, __extension__ __PRETTY_FUNCTION__));
  for (int i = 1; i <= disk_count; ++i) {
    ((0 == stacks_pop(stacks, 3, &value)) ? (void) (0) : __assert_fail ("0 == stacks_pop(stacks, 3, &value)", "3.4.c", 46, __extension__ __PRETTY_FUNCTION__));
    ((value = i) ? (void) (0) : __assert_fail ("value = i", "3.4.c", 47, __extension__ __PRETTY_FUNCTION__));
  }
  return 0;
}

canonical_original_code:
int main() {
  struct _Stacks *stacks = stacks_init(3, 10);
  unsigned long disk_count = 3;
  int value = 0;
  for (int i = disk_count; i > 0; --i) {
    stacks_push(stacks, 1, i);
  }
  solve_hanoi(stacks, 1, 3, 3);
  ((2 == stacks_pop(stacks, 1, &value)) ? (void) (0) : __assert_fail ("2 == stacks_pop(stacks, 1, &value)", "3.4.c", 43, __extension__ __PRETTY_FUNCTION__));
  for (int i = 1; i <= disk_count; ++i) {
    ((0 == stacks_pop(stacks, 3, &value)) ? (void) (0) : __assert_fail ("0 == stacks_pop(stacks, 3, &value)", "3.4.c", 46, __extension__ __PRETTY_FUNCTION__));
    ((value = i) ? (void) (0) : __assert_fail ("value = i", "3.4.c", 47, __extension__ __PRETTY_FUNCTION__));
  }
  return 0;
}


decompiled_code:
__int64 test_linked_list_pop_head()
{
void *v0; // rbp
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = (void *)memory_pool_init(0x190uLL);
v1 = memory_pool_alloc_int(v0, 1LL);
v2 = linked_list_append(0LL, v1);
v3 = memory_pool_alloc_int(v0, 2LL);
v4 = linked_list_append(v2, v3);
v8[0] = 0LL;
v5 = linked_list_pop_head(v4, v8);
*(_DWORD *)v8[0] = 1;
v6 = linked_list_pop_head(v5, v8);
*(_DWORD *)v8[0] = 2;
if ( v6 )
__assert_fail("NULL == list", "test_lists.c", 0x10u, "test_linked_list_pop_head");
if ( linked_list_pop_head(0LL, v8) )
__assert_fail(
"NULL == linked_list_pop_head(list, (void**)&value)",
"test_lists.c",
0x11u,
"test_linked_list_pop_head");
linked_list_free(0LL);
return memory_pool_free(v0);
}

canonical_decompiled_code:
__int64 func7()
{
void *v0; // rbp
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = (void *)memory_pool_init(0x190uLL);
v1 = memory_pool_alloc_int(v0, 1LL);
v2 = linked_list_append(0LL, v1);
v3 = memory_pool_alloc_int(v0, 2LL);
v4 = linked_list_append(v2, v3);
v8[0] = 0LL;
v5 = linked_list_pop_head(v4, v8);
*(_DWORD *)v8[0] = 1;
v6 = linked_list_pop_head(v5, v8);
*(_DWORD *)v8[0] = 2;
if ( v6 )
__assert_fail("NULL == list", "test_lists.c", 0x10u, "test_linked_list_pop_head");
if ( linked_list_pop_head(0LL, v8) )
__assert_fail(
"NULL == linked_list_pop_head(list, (void**)&value)",
"test_lists.c",
0x11u,
"test_linked_list_pop_head");
func17(0LL);
return func9(v0);
}

original_code:
void test_linked_list_pop_head() {
  MemoryPool *pool = memory_pool_init(sizeof(int) * 100);
  LinkedList *list = ((void *)0);
  list = linked_list_append(list, memory_pool_alloc_int(pool, 1));
  list = linked_list_append(list, memory_pool_alloc_int(pool, 2));
  int *value = ((void *)0);
  list = linked_list_pop_head(list, (void**)&value);
  ((*value = 1) ? (void) (0) : __assert_fail ("*value = 1", "test_lists.c", 13, __extension__ __PRETTY_FUNCTION__));
  list = linked_list_pop_head(list, (void**)&value);
  ((*value = 2) ? (void) (0) : __assert_fail ("*value = 2", "test_lists.c", 15, __extension__ __PRETTY_FUNCTION__));
  ((((void *)0) == list) ? (void) (0) : __assert_fail ("NULL == list", "test_lists.c", 16, __extension__ __PRETTY_FUNCTION__));
  ((((void *)0) == linked_list_pop_head(list, (void**)&value)) ? (void) (0) : __assert_fail ("NULL == linked_list_pop_head(list, (void**)&value)", "test_lists.c", 17, __extension__ __PRETTY_FUNCTION__));
  list = linked_list_free(list);
  memory_pool_free(pool);
}

canonical_original_code:
void test_linked_list_pop_head() {
  struct _MemoryPool *pool = memory_pool_init(sizeof(int) * 100);
  struct _LinkedList *list = ((void *)0);
  list = linked_list_append(list, memory_pool_alloc_int(pool, 1));
  list = linked_list_append(list, memory_pool_alloc_int(pool, 2));
  int *value = ((void *)0);
  list = linked_list_pop_head(list, (void **)&value);
  ((*value = 1) ? (void) (0) : __assert_fail ("*value = 1", "test_lists.c", 13, __extension__ __PRETTY_FUNCTION__));
  list = linked_list_pop_head(list, (void **)&value);
  ((*value = 2) ? (void) (0) : __assert_fail ("*value = 2", "test_lists.c", 15, __extension__ __PRETTY_FUNCTION__));
  ((((void *)0) == list) ? (void) (0) : __assert_fail ("NULL == list", "test_lists.c", 16, __extension__ __PRETTY_FUNCTION__));
  ((((void *)0) == linked_list_pop_head(list, (void **)&value)) ? (void) (0) : __assert_fail ("NULL == linked_list_pop_head(list, (void**)&value)", "test_lists.c", 17, __extension__ __PRETTY_FUNCTION__));
  list = linked_list_free(list);
  memory_pool_free(pool);
}

variable_types: struct _MemoryPool { void *pool; void *head; unsigned long size; } *

variable_types: struct _LinkedList { struct _LinkedList *prev; struct _LinkedList *next; void *value; } *


decompiled_code:
__int64 __fastcall memory_pool_alloc(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned __int64)(a2 + a1[1] - *a1) > a1[2] )
return 0LL;
result = a1[1];
a1[1] = result + a2;
return result;
}

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

if ( (unsigned __int64)(a2 + a1[1] - *a1) > a1[2] )
return 0LL;
result = a1[1];
a1[1] = result + a2;
return result;
}

original_code:
void *memory_pool_alloc(MemoryPool *pool, size_t size) {
  size_t used_size = (char *)pool->head - (char *)pool->pool;
  if (used_size + size > pool->size) return ((void *)0);
  void *result = pool->head;
  pool->head = (void *)((char *)pool->head + size);
  return result;
}

canonical_original_code:
void *memory_pool_alloc(struct _MemoryPool *pool, unsigned long size) {
  unsigned long used_size = (char *)pool->head - (char *)pool->pool;
  if (used_size + size > pool->size) return ((void *)0);
  void *result = pool->head;
  pool->head = (void *)((char *)pool->head + size);
  return result;
}

variable_types:
size
unsigned long

variable_types:
result
void *

return_type: void *

user_defined_types: struct _MemoryPool { void *pool; void *head; unsigned long size; }


decompiled_code:
__int64 __fastcall memory_pool_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *ptr)
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
MemoryPool *memory_pool_free(MemoryPool *pool) {
  free(pool->pool);
  free(pool);
  return ((void *)0);
}

canonical_original_code:
struct _MemoryPool *memory_pool_free(struct _MemoryPool *pool) {
  free(pool->pool);
  free(pool);
  return ((void *)0);
}

variable_types:
pool
struct _MemoryPool *

return_type: struct _MemoryPool { void *pool; void *head; unsigned long size; } *


decompiled_code:
__int64 __fastcall int_compare_by_pointer(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 != *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 != *a2;
return result;
}

original_code:
int int_compare_by_pointer(void *pa, void *pb) {
  int a = *(int *)pa;
  int b = *(int *)pb;
  if (a < b) return -1;
  else if (a == b) return 0;
  else return 1;
}

variable_types:
pa
void *

variable_types:
pb
void *

variable_types: a int

variable_types: b int


decompiled_code:
void __fastcall binary_search_tree_node_free(void *ptr)
{
if ( ptr )
{
binary_search_tree_node_free(*((void **)ptr + 2));
binary_search_tree_node_free(*((void **)ptr + 3));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
if ( ptr )
{
func11(*((void **)ptr + 2));
func11(*((void **)ptr + 3));
free(ptr);
}
}

original_code:
BinarySearchTreeNode *binary_search_tree_node_free(BinarySearchTreeNode *node) {
  if (((void *)0) != node) {
    binary_search_tree_node_free(node->left);
    binary_search_tree_node_free(node->right);
    free(node);
  }
}

canonical_original_code:
struct _BinarySearchTreeNode *binary_search_tree_node_free(struct _BinarySearchTreeNode *node) {
  if (((void *)0) != node) {
    binary_search_tree_node_free(node->left);
    binary_search_tree_node_free(node->right);
    free(node);
  }
}

variable_types:
node
struct _BinarySearchTreeNode *

return_type: struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } *


decompiled_code:
__int64 __fastcall binary_search_tree_insert(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v3; // rax
_QWORD *v4; // r13
_QWORD *v5; // rbp
void **v6; // rbx
int v7; // eax
_QWORD *v8; // rdx
__int64 v9; // rcx
__int64 result; // rax

v3 = binary_search_tree_node_alloc(a2, a3);
if ( !v3 )
return 1LL;
v4 = *(_QWORD **)a1;
v5 = v3;
v6 = (void **)a1;
if ( *(_QWORD *)a1 )
{
while ( 1 )
{
v7 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(a1 + 8))(*v5, *v4);
if ( !v7 )
break;
v8 = *v6;
v9 = (__int64)*v6 + 16;
v6 = (void **)((char *)*v6 + 24);
if ( v7 < 0 )
v6 = (void **)v9;
v4 = *v6;
if ( !*v6 )
{
v4 = v8;
goto LABEL_9;
}
}
v4 = (_QWORD *)*((_QWORD *)*v6 + 4);
binary_search_tree_node_free(*v6);
*v6 = 0LL;
}
LABEL_9:
*v6 = v5;
result = 0LL;
v5[4] = v4;
return result;
}

original_code:
int binary_search_tree_insert(BinarySearchTree *tree, void *key, void *value) {
  BinarySearchTreeNode *new_node = binary_search_tree_node_alloc(key, value);
  if (((void *)0) == new_node) return 1;
  BinarySearchTreeNode **insert_position = &(tree->root);
  BinarySearchTreeNode *parent = ((void *)0);
  while (((void *)0) != *insert_position) {
    int compare_result = tree->key_compare(new_node->key,
                                           (*insert_position)->key);
    if (0 == compare_result) {
      parent = (*insert_position)->parent;
      binary_search_tree_node_free(*insert_position);
      *insert_position = ((void *)0);
    } else if (0 > compare_result) {
      parent = *insert_position;
      insert_position = &((*insert_position)->left);
    } else {
      parent = *insert_position;
      insert_position = &((*insert_position)->right);
    }
  }
  *insert_position = new_node;
  new_node->parent = parent;
  return 0;
}

canonical_original_code:
int binary_search_tree_insert(struct _BinarySearchTree *tree, void *key, void *value) {
  struct _BinarySearchTreeNode *new_node = binary_search_tree_node_alloc(key, value);
  if (((void *)0) == new_node) return 1;
  struct _BinarySearchTreeNode **insert_position = &(tree->root);
  struct _BinarySearchTreeNode *parent = ((void *)0);
  while (((void *)0) != *insert_position) {
    int compare_result = tree->key_compare(new_node->key,
                                           (*insert_position)->key);
    if (0 == compare_result) {
      parent = (*insert_position)->parent;
      binary_search_tree_node_free(*insert_position);
      *insert_position = ((void *)0);
    } else if (0 > compare_result) {
      parent = *insert_position;
      insert_position = &((*insert_position)->left);
    } else {
      parent = *insert_position;
      insert_position = &((*insert_position)->right);
    }
  }
  *insert_position = new_node;
  new_node->parent = parent;
  return 0;
}

variable_types: struct _BinarySearchTree { struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } *root; int (*key_compare)(void *a, void *b); int (*value_compare)(void *a, void *b); } *

variable_types:
key
void *

variable_types:
value
void *

variable_types: struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } **

user_defined_types: struct _BinarySearchTree { struct _BinarySearchTreeNode *root; int (*key_compare)(void *a, void *b); int (*value_compare)(void *a, void *b); }


decompiled_code:
__int64 __fastcall binary_search_tree_find(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v3; // rbx
_QWORD *v5; // rax
__int64 result; // rax
bool v7; // sf

v3 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 1LL;
while ( 1 )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, *v3);
v7 = (int)result < 0;
if ( !(_DWORD)result )
break;
v5 = (_QWORD *)v3[2];
if ( !v7 )
v5 = (_QWORD *)v3[3];
v3 = v5;
if ( !v5 )
return 1LL;
}
*a3 = v3[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v3; // rbx
_QWORD *v5; // rax
__int64 result; // rax
bool v7; // sf

v3 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 1LL;
while ( 1 )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, *v3);
v7 = (int)result < 0;
if ( !(_DWORD)result )
break;
v5 = (_QWORD *)v3[2];
if ( !v7 )
v5 = (_QWORD *)v3[3];
v3 = v5;
if ( !v5 )
return 1LL;
}
*a3 = v3[1];
return result;
}

original_code:
int binary_search_tree_find(BinarySearchTree *tree, void *key, void **value) {
  int result = 1;
  BinarySearchTreeNode *test_node = tree->root;
  while (((void *)0) != test_node) {
    int compare_result = tree->key_compare(key, test_node->key);
    if (0 == compare_result) {
      *value = test_node->value;
      result = 0;
      break;
    } else if (0 > compare_result) {
      test_node = test_node->left;
    } else {
      test_node = test_node->right;
    }
  }
  return result;
}

canonical_original_code:
int binary_search_tree_find(struct _BinarySearchTree *tree, void *key, void **value) {
  int result = 1;
  struct _BinarySearchTreeNode *test_node = tree->root;
  while (((void *)0) != test_node) {
    int compare_result = tree->key_compare(key, test_node->key);
    if (0 == compare_result) {
      *value = test_node->value;
      result = 0;
      break;
    } else if (0 > compare_result) {
      test_node = test_node->left;
    } else {
      test_node = test_node->right;
    }
  }
  return result;
}

variable_types:
value
void **

variable_types: result int

variable_types: struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } *


decompiled_code:
__int64 __fastcall binary_search_tree_free(void *ptr)
{
binary_search_tree_node_free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(void *ptr)
{
func11(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
BinarySearchTree *binary_search_tree_free(BinarySearchTree *tree) {
  tree->root = binary_search_tree_node_free(tree->root);
  free(tree);
  return ((void *)0);
}

canonical_original_code:
struct _BinarySearchTree *binary_search_tree_free(struct _BinarySearchTree *tree) {
  tree->root = binary_search_tree_node_free(tree->root);
  free(tree);
  return ((void *)0);
}

variable_types:
tree
struct _BinarySearchTree *

return_type: struct _BinarySearchTree { struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } *root; int (*key_compare)(void *a, void *b); int (*value_compare)(void *a, void *b); } *


decompiled_code:
__int64 __fastcall singly_linked_list_free(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
return 0LL;
}

original_code:
SinglyLinkedList *singly_linked_list_free(SinglyLinkedList *list) {
  SinglyLinkedList *node = list;
  while (((void *)0) != node) {
    SinglyLinkedList *tmp = node->next;
    free(node);
    node = tmp;
  }
  return ((void *)0);
}

canonical_original_code:
struct _SinglyLinkedList *singly_linked_list_free(struct _SinglyLinkedList *list) {
  struct _SinglyLinkedList *node = list;
  while (((void *)0) != node) {
    struct _SinglyLinkedList *tmp = node->next;
    free(node);
    node = tmp;
  }
  return ((void *)0);
}

variable_types:
list
struct _SinglyLinkedList *

variable_types: struct _SinglyLinkedList { struct _SinglyLinkedList *next; int value; } *


decompiled_code:
int __fastcall singly_linked_list_print(__int64 **a1)
{
__int64 **v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d->", *((unsigned int *)v1 + 2));
v1 = (__int64 **)*v1;
}
while ( v1 );
}
return puts("NULL");
}

canonical_decompiled_code:
int __fastcall func16(__int64 **a1)
{
__int64 **v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d->", *((unsigned int *)v1 + 2));
v1 = (__int64 **)*v1;
}
while ( v1 );
}
return puts("NULL");
}

original_code:
void singly_linked_list_print(SinglyLinkedList *list) {
  SinglyLinkedList *node = list;
  while (((void *)0) != node) {
    printf("%d->", node->value);
    node = node->next;
  }
  printf("NULL\n");
}

canonical_original_code:
void singly_linked_list_print(struct _SinglyLinkedList *list) {
  struct _SinglyLinkedList *node = list;
  while (((void *)0) != node) {
    printf("%d->", node->value);
    node = node->next;
  }
  printf("NULL\n");
}

user_defined_types: struct _SinglyLinkedList { struct _SinglyLinkedList *next; int value; }


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

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
while ( v1 );
return 0LL;
}

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

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
while ( v1 );
return 0LL;
}

original_code:
LinkedList *linked_list_free(LinkedList *list) {
  LinkedList *node = list;
  while (((void *)0) != node) {
    LinkedList *tmp = node->next;
    free(node);
    node = tmp;
  }
  return ((void *)0);
}

canonical_original_code:
struct _LinkedList *linked_list_free(struct _LinkedList *list) {
  struct _LinkedList *node = list;
  while (((void *)0) != node) {
    struct _LinkedList *tmp = node->next;
    free(node);
    node = tmp;
  }
  return ((void *)0);
}

variable_types:
list
struct _LinkedList *

variable_types: struct _LinkedList { struct _LinkedList *prev; struct _LinkedList *next; void *value; } *


decompiled_code:
int __fastcall linked_list_print(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d->", *(_QWORD *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return puts("NULL");
}

original_code:
void linked_list_print(LinkedList *list) {
  LinkedList *node = list;
  while (((void *)0) != node) {
    printf("%d->", node->value);
    node = node->next;
  }
  printf("NULL\n");
}

canonical_original_code:
void linked_list_print(struct _LinkedList *list) {
  struct _LinkedList *node = list;
  while (((void *)0) != node) {
    printf("%d->", node->value);
    node = node->next;
  }
  printf("NULL\n");
}

user_defined_types: struct _LinkedList { struct _LinkedList *prev; struct _LinkedList *next; void *value; }


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

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

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


decompiled_code:
__int64 test_memory_pool()
{
_QWORD *v0; // rbp

v0 = (_QWORD *)memory_pool_init(0xAuLL);
if ( *v0 != memory_pool_alloc(v0, 2LL) )
__assert_fail("memory_pool_alloc(pool, 2) == pool->pool", "test_utility.c", 7u, "test_memory_pool");
if ( memory_pool_alloc(v0, 8LL) - *v0 != 2 )
__assert_fail("(char*)memory_pool_alloc(pool, 8)-(char*)pool->pool == 2", "test_utility.c", 8u, "test_memory_pool");
if ( memory_pool_alloc(v0, 1LL) )
__assert_fail("NULL == memory_pool_alloc(pool, 1)", "test_utility.c", 9u, "test_memory_pool");
return memory_pool_free(v0);
}

canonical_decompiled_code:
__int64 func7()
{
_QWORD *v0; // rbp

v0 = (_QWORD *)memory_pool_init(0xAuLL);
if ( *v0 != func10(v0, 2LL) )
__assert_fail("memory_pool_alloc(pool, 2) == pool->pool", "test_utility.c", 7u, "test_memory_pool");
if ( func10(v0, 8LL) - *v0 != 2 )
__assert_fail("(char*)memory_pool_alloc(pool, 8)-(char*)pool->pool == 2", "test_utility.c", 8u, "test_memory_pool");
if ( func10(v0, 1LL) )
__assert_fail("NULL == memory_pool_alloc(pool, 1)", "test_utility.c", 9u, "test_memory_pool");
return func11(v0);
}

original_code:
void test_memory_pool() {
  MemoryPool *pool = memory_pool_init(10);
  ((memory_pool_alloc(pool, 2) == pool->pool) ? (void) (0) : __assert_fail ("memory_pool_alloc(pool, 2) == pool->pool", "test_utility.c", 7, __extension__ __PRETTY_FUNCTION__));
  (((char*)memory_pool_alloc(pool, 8)-(char*)pool->pool == 2) ? (void) (0) : __assert_fail ("(char*)memory_pool_alloc(pool, 8)-(char*)pool->pool == 2", "test_utility.c", 8, __extension__ __PRETTY_FUNCTION__));
  ((((void *)0) == memory_pool_alloc(pool, 1)) ? (void) (0) : __assert_fail ("NULL == memory_pool_alloc(pool, 1)", "test_utility.c", 9, __extension__ __PRETTY_FUNCTION__));
  memory_pool_free(pool);
}

canonical_original_code:
void test_memory_pool() {
  struct _MemoryPool *pool = memory_pool_init(10);
  ((memory_pool_alloc(pool, 2) == pool->pool) ? (void) (0) : __assert_fail ("memory_pool_alloc(pool, 2) == pool->pool", "test_utility.c", 7, __extension__ __PRETTY_FUNCTION__));
  (((char *)memory_pool_alloc(pool, 8)-(char *)pool->pool == 2) ? (void) (0) : __assert_fail ("(char*)memory_pool_alloc(pool, 8)-(char*)pool->pool == 2", "test_utility.c", 8, __extension__ __PRETTY_FUNCTION__));
  ((((void *)0) == memory_pool_alloc(pool, 1)) ? (void) (0) : __assert_fail ("NULL == memory_pool_alloc(pool, 1)", "test_utility.c", 9, __extension__ __PRETTY_FUNCTION__));
  memory_pool_free(pool);
}

variable_types: struct _MemoryPool { void *pool; void *head; unsigned long size; } *


decompiled_code:
__int64 test_memory_pool_alloc_int()
{
void *v0; // rbp

v0 = (void *)memory_pool_init(0xAuLL);
if ( *(_DWORD *)memory_pool_alloc_int(v0, 1LL) != 1 )
__assert_fail("*a == 1", "test_utility.c", 0x10u, "test_memory_pool_alloc_int");
return memory_pool_free(v0);
}

canonical_decompiled_code:
__int64 func8()
{
void *v0; // rbp

v0 = (void *)memory_pool_init(0xAuLL);
if ( *(_DWORD *)memory_pool_alloc_int(v0, 1LL) != 1 )
__assert_fail("*a == 1", "test_utility.c", 0x10u, "test_memory_pool_alloc_int");
return func11(v0);
}

original_code:
void test_memory_pool_alloc_int() {
  MemoryPool *pool = memory_pool_init(10);
  int *a = memory_pool_alloc_int(pool, 1);
  ((*a == 1) ? (void) (0) : __assert_fail ("*a == 1", "test_utility.c", 16, __extension__ __PRETTY_FUNCTION__));
  memory_pool_free(pool);
}

canonical_original_code:
void test_memory_pool_alloc_int() {
  struct _MemoryPool *pool = memory_pool_init(10);
  int *a = memory_pool_alloc_int(pool, 1);
  ((*a == 1) ? (void) (0) : __assert_fail ("*a == 1", "test_utility.c", 16, __extension__ __PRETTY_FUNCTION__));
  memory_pool_free(pool);
}

variable_types:
a
int *


decompiled_code:
__int64 test_int_compare_by_pointer()
{
__int64 result; // rax
int v1; // [rsp+8h] [rbp-10h] BYREF
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = 1;
v2[0] = 2;
if ( (unsigned int)int_compare_by_pointer(&v1, v2) != -1 )
__assert_fail("-1 == int_compare_by_pointer(&a, &b)", "test_utility.c", 0x17u, "test_int_compare_by_pointer");
v1 = 2;
if ( (unsigned int)int_compare_by_pointer(&v1, v2) )
__assert_fail("0 == int_compare_by_pointer(&a, &b)", "test_utility.c", 0x19u, "test_int_compare_by_pointer");
v1 = 3;
result = int_compare_by_pointer(&v1, v2);
if ( (_DWORD)result != 1 )
__assert_fail("1 == int_compare_by_pointer(&a, &b)", "test_utility.c", 0x1Bu, "test_int_compare_by_pointer");
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
int v1; // [rsp+8h] [rbp-10h] BYREF
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = 1;
v2[0] = 2;
if ( (unsigned int)func12(&v1, v2) != -1 )
__assert_fail("-1 == int_compare_by_pointer(&a, &b)", "test_utility.c", 0x17u, "test_int_compare_by_pointer");
v1 = 2;
if ( (unsigned int)func12(&v1, v2) )
__assert_fail("0 == int_compare_by_pointer(&a, &b)", "test_utility.c", 0x19u, "test_int_compare_by_pointer");
v1 = 3;
result = func12(&v1, v2);
if ( (_DWORD)result != 1 )
__assert_fail("1 == int_compare_by_pointer(&a, &b)", "test_utility.c", 0x1Bu, "test_int_compare_by_pointer");
return result;
}

original_code:
void test_int_compare_by_pointer() {
  int a = 1;
  int b = 2;
  ((-1 == int_compare_by_pointer(&a, &b)) ? (void) (0) : __assert_fail ("-1 == int_compare_by_pointer(&a, &b)", "test_utility.c", 23, __extension__ __PRETTY_FUNCTION__));
  a = 2;
  ((0 == int_compare_by_pointer(&a, &b)) ? (void) (0) : __assert_fail ("0 == int_compare_by_pointer(&a, &b)", "test_utility.c", 25, __extension__ __PRETTY_FUNCTION__));
  a = 3;
  ((1 == int_compare_by_pointer(&a, &b)) ? (void) (0) : __assert_fail ("1 == int_compare_by_pointer(&a, &b)", "test_utility.c", 27, __extension__ __PRETTY_FUNCTION__));
}

variable_types: a int


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

if ( (unsigned __int64)(a2 + a1[1] - *a1) > a1[2] )
return 0LL;
result = a1[1];
a1[1] = result + a2;
return result;
}

variable_types:
size
unsigned long

variable_types:
result
void *


canonical_decompiled_code:
__int64 __fastcall func11(void *ptr)
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}

variable_types:
pool
struct _MemoryPool *


canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 != *a2;
return result;
}

canonical_original_code:
int int_compare_by_pointer(void *pa, void *pb) {
  int a = *(int *)pa;
  int b = *(int *)pb;
  if (a < b) return -1;
  else if (a == b) return 0;
  else return 1;
}

variable_types:
pa
void *

variable_types:
pb
void *

variable_types: b int


canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
if ( ptr )
{
func13(*((void **)ptr + 2));
func13(*((void **)ptr + 3));
free(ptr);
}
}

variable_types:
node
struct _BinarySearchTreeNode *

user_defined_types: struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; }


variable_types: struct _BinarySearchTree { struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } *root; int (*key_compare)(void *a, void *b); int (*value_compare)(void *a, void *b); } *

variable_types:
key
void *

variable_types:
value
void *

variable_types: struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } **


canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v3; // rbx
_QWORD *v5; // rax
__int64 result; // rax
bool v7; // sf

v3 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 1LL;
while ( 1 )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, *v3);
v7 = (int)result < 0;
if ( !(_DWORD)result )
break;
v5 = (_QWORD *)v3[2];
if ( !v7 )
v5 = (_QWORD *)v3[3];
v3 = v5;
if ( !v5 )
return 1LL;
}
*a3 = v3[1];
return result;
}

variable_types:
value
void **

variable_types: result int

variable_types: struct _BinarySearchTreeNode { void *key; void *value; struct _BinarySearchTreeNode *left; struct _BinarySearchTreeNode *right; struct _BinarySearchTreeNode *parent; } *


canonical_decompiled_code:
__int64 __fastcall func16(void *ptr)
{
func13(*(void **)ptr);
free(ptr);
return 0LL;
}

variable_types:
tree
struct _BinarySearchTree *


canonical_decompiled_code:
__int64 __fastcall func17(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
return 0LL;
}

variable_types:
list
struct _SinglyLinkedList *

variable_types: struct _SinglyLinkedList { struct _SinglyLinkedList *next; int value; } *


canonical_decompiled_code:
int __fastcall func18(__int64 **a1)
{
__int64 **v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d->", *((unsigned int *)v1 + 2));
v1 = (__int64 **)*v1;
}
while ( v1 );
}
return puts("NULL");
}


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

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
while ( v1 );
return 0LL;
}

variable_types:
list
struct _LinkedList *

variable_types: struct _LinkedList { struct _LinkedList *prev; struct _LinkedList *next; void *value; } *


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

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

original_code:
int main() {
  test_memory_pool();
  test_memory_pool_alloc_int();
  test_int_compare_by_pointer();
  return 0;
}


decompiled_code:
void __fastcall image_free(void *ptr, int a2)
{
void *v2; // r13
void **v3; // r14
void **v4; // r12
__int64 v5; // rbx
void *v6; // rdi
void *v7; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = 0LL;
do
{
v6 = *(void **)((char *)*v3 + v5);
v5 += 8LL;
free(v6);
}
while ( 8LL * (unsigned int)a2 != v5 );
v7 = *v3++;
free(v7);
}
while ( v4 != v3 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr, int a2)
{
void *v2; // r13
void **v3; // r14
void **v4; // r12
__int64 v5; // rbx
void *v6; // rdi
void *v7; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = 0LL;
do
{
v6 = *(void **)((char *)*v3 + v5);
v5 += 8LL;
free(v6);
}
while ( 8LL * (unsigned int)a2 != v5 );
v7 = *v3++;
free(v7);
}
while ( v4 != v3 );
}
free(v2);
}

original_code:
void image_free(char ***image, int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      free(image[i][j]);
    }
    free(image[i]);
  }
  free(image);
}

variable_types:
image
char ***

variable_types: n int

variable_types: i int

variable_types: j int


decompiled_code:
char *__fastcall pixel_copy(char *a1, const char *a2, int a3)
{
return strncpy(a1, a2, a3);
}

canonical_decompiled_code:
char *__fastcall func8(char *a1, const char *a2, int a3)
{
return strncpy(a1, a2, a3);
}

original_code:
void pixel_copy(char *dest, const char *source, int l) {
  strncpy(dest, source, l);
}

canonical_original_code:
void pixel_copy(char *dest, char *source, int l) {
  strncpy(dest, source, l);
}

variable_types:
dest
char *

variable_types:
source
char *

variable_types: l int


original_code:
void image_rotate(char ***image, int n, int l) {
  char *source = (char *) malloc(sizeof(char)*l);
  char *buffer = (char *) malloc(sizeof(char)*l);
  for (int i = 0; i < (n+1)/2; ++i) {
    for (int j = 0; j < (n+1)/2; ++j) {
      int next_i = j;
      int next_j = n-i-1;
      pixel_copy(source, image[i][j], l);
      while (next_i != i && next_j != j) {
        pixel_copy(buffer, image[next_i][next_j], l);
        pixel_copy(image[next_i][next_j], source, l);
        pixel_copy(source, buffer, l);
        next_i = next_j;
        next_j = n-next_i-1;
      }
    }
  }
  free(buffer);
  free(source);
}

variable_types:
buffer
char *


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

v3 = (void *)image_alloc(3LL, 4LL, envp);
image_rotate(v3, 3LL, 4LL);
image_free(v3);
return 0;
}

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

v3 = (void *)image_alloc(3LL, 4LL, envp);
func9(v3, 3LL, 4LL);
func7(v3);
return 0;
}

original_code:
int main() {
  int n = 3;
  char ***image = image_alloc(n, 4);
  image_rotate(image, n, 4);
  image_free(image, n);
  return 0;
}


original_code:
int nth_to_last(SinglyLinkedList *list, int n, int *value) {
  int length = 0;
  SinglyLinkedList *counter = list;
  while (((void *)0) != counter) {
    ++length;
    counter = counter->next;
  }
  if (length < n) return 1;
  n = length - n;
  SinglyLinkedList *target = list;
  while (n > 0) {
    target = target->next;
    --n;
  }
  *value = target->value;
  return 0;
}

canonical_original_code:
int nth_to_last(struct _SinglyLinkedList *list, int n, int *value) {
  int length = 0;
  struct _SinglyLinkedList *counter = list;
  while (((void *)0) != counter) {
    ++length;
    counter = counter->next;
  }
  if (length < n) return 1;
  n = length - n;
  struct _SinglyLinkedList *target = list;
  while (n > 0) {
    target = target->next;
    --n;
  }
  *value = target->value;
  return 0;
}

variable_types:
value
int *

variable_types: length int


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

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
return 0LL;
}

return_type: struct _SinglyLinkedList { struct _SinglyLinkedList *next; int value; } *


canonical_decompiled_code:
int __fastcall func9(__int64 **a1)
{
__int64 **v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d->", *((unsigned int *)v1 + 2));
v1 = (__int64 **)*v1;
}
while ( v1 );
}
return puts("NULL");
}


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

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
while ( v1 );
return 0LL;
}

return_type: struct _LinkedList { struct _LinkedList *prev; struct _LinkedList *next; void *value; } *


decompiled_code:
__int64 __fastcall memory_pool_alloc(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned __int64)(a2 + a1[1] - *a1) > a1[2] )
return 0LL;
result = a1[1];
a1[1] = result + a2;
return result;
}

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

if ( (unsigned __int64)(a2 + a1[1] - *a1) > a1[2] )
return 0LL;
result = a1[1];
a1[1] = result + a2;
return result;
}

original_code:
void *memory_pool_alloc(MemoryPool *pool, size_t size) {
  size_t used_size = (char *)pool->head - (char *)pool->pool;
  if (used_size + size > pool->size) return ((void *)0);
  void *result = pool->head;
  pool->head = (void *)((char *)pool->head + size);
  return result;
}

variable_types: struct _MemoryPool { void *pool; void *head; unsigned long size; } *

variable_types:
size
unsigned long

variable_types:
result
void *


decompiled_code:
__int64 __fastcall memory_pool_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(void *ptr)
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
MemoryPool *memory_pool_free(MemoryPool *pool) {
  free(pool->pool);
  free(pool);
  return ((void *)0);
}

variable_types:
pool
struct _MemoryPool *


decompiled_code:
__int64 __fastcall int_compare_by_pointer(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 != *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 != *a2;
return result;
}

original_code:
int int_compare_by_pointer(void *pa, void *pb) {
  int a = *(int *)pa;
  int b = *(int *)pb;
  if (a < b) return -1;
  else if (a == b) return 0;
  else return 1;
}

variable_types:
pa
void *

variable_types:
pb
void *

variable_types: a int

variable_types: b int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // rax
__int64 v14; // rcx
__int64 v15; // r8
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // r9
void *v19; // r9
int v21[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = singly_linked_list_append(0LL, 1LL, envp);
v5 = singly_linked_list_append(v3, 2LL, v4);
v7 = singly_linked_list_append(v5, 3LL, v6);
v9 = singly_linked_list_append(v7, 4LL, v8);
v11 = singly_linked_list_append(v9, 5LL, v10);
v13 = singly_linked_list_append(v11, 6LL, v12);
v21[0] = 0;
if ( (unsigned int)nth_to_last(v13, 1LL, v21, v14, v15, v13) )
__assert_fail("0 == nth_to_last(list, 1, &value)", "2.2.c", 0x29u, "main");
if ( v21[0] != 6 )
__assert_fail("6 == value", "2.2.c", 0x2Au, "main");
if ( (unsigned int)nth_to_last(v18, 7LL, v21, v16, v17, v18) != 1 )
__assert_fail("1 == nth_to_last(list, 7, &value)", "2.2.c", 0x2Bu, "main");
singly_linked_list_free(v19);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // rax
__int64 v14; // rcx
__int64 v15; // r8
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // r9
void *v19; // r9
int v21[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = singly_linked_list_append(0LL, 1LL, envp);
v5 = singly_linked_list_append(v3, 2LL, v4);
v7 = singly_linked_list_append(v5, 3LL, v6);
v9 = singly_linked_list_append(v7, 4LL, v8);
v11 = singly_linked_list_append(v9, 5LL, v10);
v13 = singly_linked_list_append(v11, 6LL, v12);
v21[0] = 0;
if ( (unsigned int)func7(v13, 1LL, v21, v14, v15, v13) )
__assert_fail("0 == nth_to_last(list, 1, &value)", "2.2.c", 0x29u, "main");
if ( v21[0] != 6 )
__assert_fail("6 == value", "2.2.c", 0x2Au, "main");
if ( (unsigned int)func7(v18, 7LL, v21, v16, v17, v18) != 1 )
__assert_fail("1 == nth_to_last(list, 7, &value)", "2.2.c", 0x2Bu, "main");
func8(v19);
return 0;
}

original_code:
int main() {
  SinglyLinkedList *list = ((void *)0);
  list = singly_linked_list_append(list, 1);
  list = singly_linked_list_append(list, 2);
  list = singly_linked_list_append(list, 3);
  list = singly_linked_list_append(list, 4);
  list = singly_linked_list_append(list, 5);
  list = singly_linked_list_append(list, 6);
  int value = 0;
  ((0 == nth_to_last(list, 1, &value)) ? (void) (0) : __assert_fail ("0 == nth_to_last(list, 1, &value)", "2.2.c", 41, __extension__ __PRETTY_FUNCTION__));
  ((6 == value) ? (void) (0) : __assert_fail ("6 == value", "2.2.c", 42, __extension__ __PRETTY_FUNCTION__));
  ((1 == nth_to_last(list, 7, &value)) ? (void) (0) : __assert_fail ("1 == nth_to_last(list, 7, &value)", "2.2.c", 43, __extension__ __PRETTY_FUNCTION__));
  singly_linked_list_free(list);
}

canonical_original_code:
int main() {
  struct _SinglyLinkedList *list = ((void *)0);
  list = singly_linked_list_append(list, 1);
  list = singly_linked_list_append(list, 2);
  list = singly_linked_list_append(list, 3);
  list = singly_linked_list_append(list, 4);
  list = singly_linked_list_append(list, 5);
  list = singly_linked_list_append(list, 6);
  int value = 0;
  ((0 == nth_to_last(list, 1, &value)) ? (void) (0) : __assert_fail ("0 == nth_to_last(list, 1, &value)", "2.2.c", 41, __extension__ __PRETTY_FUNCTION__));
  ((6 == value) ? (void) (0) : __assert_fail ("6 == value", "2.2.c", 42, __extension__ __PRETTY_FUNCTION__));
  ((1 == nth_to_last(list, 7, &value)) ? (void) (0) : __assert_fail ("1 == nth_to_last(list, 7, &value)", "2.2.c", 43, __extension__ __PRETTY_FUNCTION__));
  singly_linked_list_free(list);
}

variable_types: struct _SinglyLinkedList { struct _SinglyLinkedList *next; int value; } *

variable_types: value int


decompiled_code:
__int64 __fastcall sort_stack(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbp
int v4; // eax
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6 = 0;
LABEL_2:
for ( i = stack_init(20LL, a2, a3); ; stack_push(i, v6) )
{
v4 = stack_pop(a1, &v6);
v7[0] = 0;
if ( v4 )
break;
while ( 1 )
{
if ( (unsigned int)stack_pop(i, v7) )
{
stack_push(i, v6);
goto LABEL_2;
}
if ( (int)v6 >= v7[0] )
break;
stack_push(a1, (unsigned int)v7[0]);
}
stack_push(i, (unsigned int)v7[0]);
}
while ( !(unsigned int)stack_pop(i, v7) )
stack_push(a1, (unsigned int)v7[0]);
return stack_free(i);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbp
int v4; // eax
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6 = 0;
LABEL_2:
for ( i = stack_init(20LL, a2, a3); ; func11(i, v6) )
{
v4 = func12(a1, &v6);
v7[0] = 0;
if ( v4 )
break;
while ( 1 )
{
if ( (unsigned int)func12(i, v7) )
{
func11(i, v6);
goto LABEL_2;
}
if ( (int)v6 >= v7[0] )
break;
func11(a1, (unsigned int)v7[0]);
}
func11(i, (unsigned int)v7[0]);
}
while ( !(unsigned int)func12(i, v7) )
func11(a1, (unsigned int)v7[0]);
return func13(i);
}

original_code:
void sort_stack(Stack *stack) {
  Stack *helper_stack = stack_init(20);
  int test_element = 0;
  while (0 == stack_pop(stack, &test_element)) {
    int compare = 0;
    while (0 == stack_pop(helper_stack, &compare)) {
      if (test_element < compare) {
        stack_push(stack, compare);
      } else {
        stack_push(helper_stack, compare);
        break;
      }
    }
    stack_push(helper_stack, test_element);
  }
  int value = 0;
  while (0 == stack_pop(helper_stack, &value)) {
    stack_push(stack, value);
  }
  helper_stack = stack_free(helper_stack);
}

canonical_original_code:
void sort_stack(struct _Stacks *stack) {
  struct _Stacks *helper_stack = stack_init(20);
  int test_element = 0;
  while (0 == stack_pop(stack, &test_element)) {
    int compare = 0;
    while (0 == stack_pop(helper_stack, &compare)) {
      if (test_element < compare) {
        stack_push(stack, compare);
      } else {
        stack_push(helper_stack, compare);
        break;
      }
    }
    stack_push(helper_stack, test_element);
  }
  int value = 0;
  while (0 == stack_pop(helper_stack, &value)) {
    stack_push(stack, value);
  }
  helper_stack = stack_free(helper_stack);
}

variable_types: struct _Stacks { int *stack; unsigned long stack_number; unsigned long *stack_head; unsigned long stack_size; } *

variable_types: compare int


original_code:
int stacks_push(Stacks *stacks, int stack_id, int value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  size_t insert_position =
    stacks->stack_head[stack_id-1]*stacks->stack_number+stack_id-1;
  if (insert_position >= stacks->stack_size) {
    size_t new_stack_size = 2*stacks->stack_size;
    int *new_stack = (int *) malloc(sizeof(int) * new_stack_size);
    if (((void *)0) == new_stack) return 2;
    memcpy(new_stack, stacks->stack, sizeof(int)*stacks->stack_size);
    free(stacks->stack);
    stacks->stack = new_stack;
    stacks->stack_size = new_stack_size;
  }
  stacks->stack[insert_position] = value;
  stacks->stack_head[stack_id-1] += 1;
  return 0;
}

canonical_original_code:
int stacks_push(struct _Stacks *stacks, int stack_id, int value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  unsigned long insert_position = stacks->stack_head[stack_id-1]*stacks->stack_number+stack_id-1;
  if (insert_position >= stacks->stack_size) {
    unsigned long new_stack_size = 2*stacks->stack_size;
    int *new_stack = (int *) malloc(sizeof(int) * new_stack_size);
    if (((void *)0) == new_stack) return 2;
    memcpy(new_stack, stacks->stack, sizeof(int)*stacks->stack_size);
    free(stacks->stack);
    stacks->stack = new_stack;
    stacks->stack_size = new_stack_size;
  }
  stacks->stack[insert_position] = value;
  stacks->stack_head[stack_id-1] += 1;
  return 0;
}


original_code:
int stacks_pop(Stacks *stacks, int stack_id, int *value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  size_t stack_head = stacks->stack_head[stack_id-1];
  if (0 == stack_head) return 2;
  size_t pop_position = (stack_head-1)*stacks->stack_number+stack_id-1;
  *value = stacks->stack[pop_position];
  stacks->stack_head[stack_id-1] -= 1;
  return 0;
}

canonical_original_code:
int stacks_pop(struct _Stacks *stacks, int stack_id, int *value) {
  if (stack_id < 1 || stack_id > stacks->stack_number) {
    return 1;
  }
  unsigned long stack_head = stacks->stack_head[stack_id-1];
  if (0 == stack_head) return 2;
  unsigned long pop_position = (stack_head-1)*stacks->stack_number+stack_id-1;
  *value = stacks->stack[pop_position];
  stacks->stack_head[stack_id-1] -= 1;
  return 0;
}


decompiled_code:
__int64 __fastcall stacks_free(void *ptr)
{
free(*((void **)ptr + 2));
free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *ptr)
{
free(*((void **)ptr + 2));
free(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
Stacks *stacks_free(Stacks *stacks) {
  free(stacks->stack_head);
  free(stacks->stack);
  free(stacks);
  return ((void *)0);
}

canonical_original_code:
struct _Stacks *stacks_free(struct _Stacks *stacks) {
  free(stacks->stack_head);
  free(stacks->stack);
  free(stacks);
  return ((void *)0);
}

variable_types:
stacks
struct _Stacks *


decompiled_code:
__int64 __fastcall stack_push(__int64 a1, int a2)
{
return stacks_push(a1, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
return func8(a1, 1, a2);
}

original_code:
int stack_push(Stack *stack, int value) {
  return stacks_push(stack, 1, value);
}

canonical_original_code:
int stack_push(struct _Stacks *stack, int value) {
  return stacks_push(stack, 1, value);
}


decompiled_code:
__int64 __fastcall stack_pop(_QWORD *a1, _DWORD *a2)
{
return stacks_pop(a1, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, _DWORD *a2)
{
return func9(a1, 1, a2);
}

original_code:
int stack_pop(Stack *stack, int *value) {
  return stacks_pop(stack, 1, value);
}

canonical_original_code:
int stack_pop(struct _Stacks *stack, int *value) {
  return stacks_pop(stack, 1, value);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall stack_free(void *a1)
{
return stacks_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(void *a1)
{
return func10(a1);
}

original_code:
Stack *stack_free(Stack *stack) {
  return stacks_free(stack);
}

canonical_original_code:
struct _Stacks *stack_free(struct _Stacks *stack) {
  return stacks_free(stack);
}

variable_types:
stack
struct _Stacks *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rbp
int v5; // ebx
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 1;
v4 = stack_init(10LL, argv, envp);
do
{
if ( (unsigned int)stack_push(v4, v3) )
__assert_fail("0 == stack_push(stack, i)", "3.6.c", 0x23u, "main");
++v3;
}
while ( v3 != 11 );
v5 = 1;
sort_stack(v4);
v7[0] = 0;
do
{
if ( (unsigned int)stack_pop(v4, v7) )
__assert_fail("0 == stack_pop(stack, &value)", "3.6.c", 0x28u, "main");
if ( v7[0] != v5 )
__assert_fail("i == value", "3.6.c", 0x29u, "main");
++v5;
}
while ( v5 != 11 );
stack_free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rbp
int v5; // ebx
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 1;
v4 = stack_init(10LL, argv, envp);
do
{
if ( (unsigned int)func11(v4, v3) )
__assert_fail("0 == stack_push(stack, i)", "3.6.c", 0x23u, "main");
++v3;
}
while ( v3 != 11 );
v5 = 1;
func7(v4);
v7[0] = 0;
do
{
if ( (unsigned int)func12(v4, v7) )
__assert_fail("0 == stack_pop(stack, &value)", "3.6.c", 0x28u, "main");
if ( v7[0] != v5 )
__assert_fail("i == value", "3.6.c", 0x29u, "main");
++v5;
}
while ( v5 != 11 );
func13(v4);
return 0;
}

original_code:
int main() {
  Stack *stack = stack_init(10);
  for (int i = 1; i <= 10; ++i) {
    ((0 == stack_push(stack, i)) ? (void) (0) : __assert_fail ("0 == stack_push(stack, i)", "3.6.c", 35, __extension__ __PRETTY_FUNCTION__));
  }
  sort_stack(stack);
  int value = 0;
  for (int i = 1; i <= 10; ++i) {
    ((0 == stack_pop(stack, &value)) ? (void) (0) : __assert_fail ("0 == stack_pop(stack, &value)", "3.6.c", 40, __extension__ __PRETTY_FUNCTION__));
    ((i == value) ? (void) (0) : __assert_fail ("i == value", "3.6.c", 41, __extension__ __PRETTY_FUNCTION__));
  }
  stack = stack_free(stack);
  return 0;
}

canonical_original_code:
int main() {
  struct _Stacks *stack = stack_init(10);
  for (int i = 1; i <= 10; ++i) {
    ((0 == stack_push(stack, i)) ? (void) (0) : __assert_fail ("0 == stack_push(stack, i)", "3.6.c", 35, __extension__ __PRETTY_FUNCTION__));
  }
  sort_stack(stack);
  int value = 0;
  for (int i = 1; i <= 10; ++i) {
    ((0 == stack_pop(stack, &value)) ? (void) (0) : __assert_fail ("0 == stack_pop(stack, &value)", "3.6.c", 40, __extension__ __PRETTY_FUNCTION__));
    ((i == value) ? (void) (0) : __assert_fail ("i == value", "3.6.c", 41, __extension__ __PRETTY_FUNCTION__));
  }
  stack = stack_free(stack);
  return 0;
}

variable_types: i int


add

original_code:
LinkedList *add(LinkedList *a, LinkedList *b, MemoryPool *pool) {
  LinkedList *result = ((void *)0);
  int incre = 0;
  while (!(((void *)0) == a && ((void *)0) == b)) {
    int sum = incre;
    if (((void *)0) != a) {
      sum += *((int *)a->value);
      a = a->next;
    }
    if (((void *)0) != b) {
      sum += *((int *)b->value);
      b = b->next;
    }
    int digit = sum % 10;
    incre = sum / 10;
    result = linked_list_append(result, memory_pool_alloc_int(pool, digit));
  }
  return result;
}

canonical_original_code:
struct _LinkedList *add(struct _LinkedList *a, struct _LinkedList *b, struct _MemoryPool *pool) {
  struct _LinkedList *result = ((void *)0);
  int incre = 0;
  while (!(((void *)0) == a && ((void *)0) == b)) {
    int sum = incre;
    if (((void *)0) != a) {
      sum += *((int *)a->value);
      a = a->next;
    }
    if (((void *)0) != b) {
      sum += *((int *)b->value);
      b = b->next;
    }
    int digit = sum % 10;
    incre = sum / 10;
    result = linked_list_append(result, memory_pool_alloc_int(pool, digit));
  }
  return result;
}

variable_types:
a
struct _LinkedList *

variable_types:
b
struct _LinkedList *

variable_types: struct _LinkedList { struct _LinkedList *prev; struct _LinkedList *next; void *value; } *

variable_types: incre int

variable_types: sum int

variable_types: digit int


decompiled_code:
int __fastcall linked_list_print(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf("%d->", *(_QWORD *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return puts("NULL");
}

original_code:
void linked_list_print(LinkedList *list) {
  LinkedList *node = list;
  while (((void *)0) != node) {
    printf("%d->", node->value);
    node = node->next;
  }
  printf("NULL\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rax
void *v9; // r12
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
__int64 v13; // r13
__int64 v14; // rax
__int64 v15; // r13
__int64 v16; // rax
void *v17; // r13
void *v18; // r14

v3 = (void *)memory_pool_init(0x190uLL);
v4 = memory_pool_alloc_int(v3, 3LL);
v5 = linked_list_append(0LL, v4);
v6 = memory_pool_alloc_int(v3, 1LL);
v7 = linked_list_append(v5, v6);
v8 = memory_pool_alloc_int(v3, 5LL);
v9 = (void *)linked_list_append(v7, v8);
linked_list_print(v9);
v10 = memory_pool_alloc_int(v3, 5LL);
v11 = linked_list_append(0LL, v10);
v12 = memory_pool_alloc_int(v3, 9LL);
v13 = linked_list_append(v11, v12);
v14 = memory_pool_alloc_int(v3, 2LL);
v15 = linked_list_append(v13, v14);
v16 = memory_pool_alloc_int(v3, 1LL);
v17 = (void *)linked_list_append(v15, v16);
linked_list_print(v17);
v18 = (void *)add(v9, v17, v3);
linked_list_print(v18);
linked_list_free(v18);
linked_list_free(v17);
linked_list_free(v9);
memory_pool_free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rax
void *v9; // r12
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
__int64 v13; // r13
__int64 v14; // rax
__int64 v15; // r13
__int64 v16; // rax
void *v17; // r13
void *v18; // r14

v3 = (void *)memory_pool_init(0x190uLL);
v4 = memory_pool_alloc_int(v3, 3LL);
v5 = linked_list_append(0LL, v4);
v6 = memory_pool_alloc_int(v3, 1LL);
v7 = linked_list_append(v5, v6);
v8 = memory_pool_alloc_int(v3, 5LL);
v9 = (void *)linked_list_append(v7, v8);
func11(v9);
v10 = memory_pool_alloc_int(v3, 5LL);
v11 = linked_list_append(0LL, v10);
v12 = memory_pool_alloc_int(v3, 9LL);
v13 = linked_list_append(v11, v12);
v14 = memory_pool_alloc_int(v3, 2LL);
v15 = linked_list_append(v13, v14);
v16 = memory_pool_alloc_int(v3, 1LL);
v17 = (void *)linked_list_append(v15, v16);
func11(v17);
v18 = (void *)func7(v9, v17, v3);
func11(v18);
func10(v18);
func10(v17);
func10(v9);
func13(v3);
return 0;
}

original_code:
int main() {
  MemoryPool *pool = memory_pool_init(sizeof(100)*100);
  LinkedList *number_a = ((void *)0);
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 3));
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 1));
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 5));
  linked_list_print(number_a);
  LinkedList *number_b = ((void *)0);
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 5));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 9));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 2));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 1));
  linked_list_print(number_b);
  LinkedList *result = add(number_a, number_b, pool);
  linked_list_print(result);
  linked_list_free(result);
  linked_list_free(number_b);
  linked_list_free(number_a);
  memory_pool_free(pool);
  return 0;
}

canonical_original_code:
int main() {
  struct _MemoryPool *pool = memory_pool_init(sizeof(100)*100);
  struct _LinkedList *number_a = ((void *)0);
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 3));
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 1));
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 5));
  linked_list_print(number_a);
  struct _LinkedList *number_b = ((void *)0);
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 5));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 9));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 2));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 1));
  linked_list_print(number_b);
  struct _LinkedList *result = add(number_a, number_b, pool);
  linked_list_print(result);
  linked_list_free(result);
  linked_list_free(number_b);
  linked_list_free(number_a);
  memory_pool_free(pool);
  return 0;
}

variable_types: struct _MemoryPool { void *pool; void *head; unsigned long size; } *


decompiled_code:
__int64 __fastcall is_rotation(void *src, char *needle)
{
unsigned int v2; // er13
size_t v3; // rbx
char *v5; // r14

v2 = 0;
v3 = strlen((const char *)src);
if ( v3 != strlen(needle) )
return 0LL;
v5 = (char *)malloc(2 * v3 + 1);
memcpy(v5, src, v3);
memcpy(&v5[v3], src, v3 + 1);
LOBYTE(v2) = strstr(v5, needle) != 0LL;
free(v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *src, char *needle)
{
unsigned int v2; // er13
size_t v3; // rbx
char *v5; // r14

v2 = 0;
v3 = strlen((const char *)src);
if ( v3 != strlen(needle) )
return 0LL;
v5 = (char *)malloc(2 * v3 + 1);
memcpy(v5, src, v3);
memcpy(&v5[v3], src, v3 + 1);
LOBYTE(v2) = strstr(v5, needle) != 0LL;
free(v5);
return v2;
}

original_code:
_Bool is_rotation(const char *s1, const char *s2) {
  if (strlen(s1) != strlen(s2)) return 0;
  char *buffer = (char *) malloc(strlen(s1)*2+1);
  strcpy(buffer, s1);
  strcat(buffer, s1);
  _Bool result = 0;
  if (((void *)0) != strstr(buffer, s2)) result = 1;
  free(buffer);
  return result;
}

canonical_original_code:
_Bool is_rotation(char *s1, char *s2) {
  if (strlen(s1) != strlen(s2)) return 0;
  char *buffer = (char *) malloc(strlen(s1)*2+1);
  strcpy(buffer, s1);
  strcat(buffer, s1);
  _Bool result = 0;
  if (((void *)0) != strstr(buffer, s2)) result = 1;
  free(buffer);
  return result;
}

variable_types:
buffer
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned __int8)is_rotation("abcd", "cdba") )
__assert_fail("false == is_rotation(\"abcd\", \"cdba\")", "1.8.c", 0x16u, "main");
if ( (unsigned __int8)is_rotation("abcd", "bc") )
__assert_fail("false == is_rotation(\"abcd\", \"bc\")", "1.8.c", 0x17u, "main");
if ( !(unsigned __int8)is_rotation("abcd", "cdab") )
__assert_fail("true == is_rotation(\"abcd\", \"cdab\")", "1.8.c", 0x18u, "main");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned __int8)func7("abcd", "cdba") )
__assert_fail("false == is_rotation(\"abcd\", \"cdba\")", "1.8.c", 0x16u, "main");
if ( (unsigned __int8)func7("abcd", "bc") )
__assert_fail("false == is_rotation(\"abcd\", \"bc\")", "1.8.c", 0x17u, "main");
if ( !(unsigned __int8)func7("abcd", "cdab") )
__assert_fail("true == is_rotation(\"abcd\", \"cdab\")", "1.8.c", 0x18u, "main");
return 0;
}

original_code:
int main() {
  ((0 == is_rotation("abcd", "cdba")) ? (void) (0) : __assert_fail ("false == is_rotation(\"abcd\", \"cdba\")", "1.8.c", 22, __extension__ __PRETTY_FUNCTION__));
  ((0 == is_rotation("abcd", "bc")) ? (void) (0) : __assert_fail ("false == is_rotation(\"abcd\", \"bc\")", "1.8.c", 23, __extension__ __PRETTY_FUNCTION__));
  ((1 == is_rotation("abcd", "cdab")) ? (void) (0) : __assert_fail ("true == is_rotation(\"abcd\", \"cdab\")", "1.8.c", 24, __extension__ __PRETTY_FUNCTION__));
  return 0;
}


decompiled_code:
void *__fastcall escape_spaces(const char *a1)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // rax
char v4; // bl
char *v5; // r12
char *v6; // rdi
const unsigned __int16 **v7; // rcx
__int64 v8; // rax
size_t v9; // r14
void *v10; // r13

v1 = (char *)a1;
v2 = strlen(a1);
v3 = (char *)malloc(3 * v2 + 1);
v4 = *a1;
v5 = v3;
if ( *a1 )
{
v6 = v3;
v7 = __ctype_b_loc();
do
{
while ( ((*v7)[v4] & 0x2000) == 0 )
{
++v1;
*v6++ = v4;
v4 = *v1;
if ( !*v1 )
goto LABEL_6;
}
v8 = append_space_escape((__int64)v6);
v4 = *++v1;
v6 = (char *)v8;
}
while ( v4 );
}
else
{
v6 = v3;
}
LABEL_6:
*v6 = 0;
v9 = strlen(v5) + 1;
v10 = malloc(v9);
memcpy(v10, v5, v9);
free(v5);
return v10;
}

canonical_decompiled_code:
void *__fastcall func8(const char *a1)
{
char *v1; // rbp
size_t v2; // rax
char *v3; // rax
char v4; // bl
char *v5; // r12
char *v6; // rdi
const unsigned __int16 **v7; // rcx
__int64 v8; // rax
size_t v9; // r14
void *v10; // r13

v1 = (char *)a1;
v2 = strlen(a1);
v3 = (char *)malloc(3 * v2 + 1);
v4 = *a1;
v5 = v3;
if ( *a1 )
{
v6 = v3;
v7 = __ctype_b_loc();
do
{
while ( ((*v7)[v4] & 0x2000) == 0 )
{
++v1;
*v6++ = v4;
v4 = *v1;
if ( !*v1 )
goto LABEL_6;
}
v8 = func7((__int64)v6);
v4 = *++v1;
v6 = (char *)v8;
}
while ( v4 );
}
else
{
v6 = v3;
}
LABEL_6:
*v6 = 0;
v9 = strlen(v5) + 1;
v10 = malloc(v9);
memcpy(v10, v5, v9);
free(v5);
return v10;
}

original_code:
char *escape_spaces(const char *string) {
  char *buffer = (char *) malloc(strlen(string)*3+1);
  char *insert_position = buffer;
  for (const char *c = string; *c != '\0'; ++c) {
    if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace)) {
      *insert_position = *c;
      ++insert_position;
    } else {
      insert_position = append_space_escape(insert_position);
    }
  }
  *insert_position = '\0';
  char *result = (char *) malloc(strlen(buffer)+1);
  strcpy(result, buffer);
  free(buffer);
  return result;
}

canonical_original_code:
char *escape_spaces(char *string) {
  char *buffer = (char *) malloc(strlen(string)*3+1);
  char *insert_position = buffer;
  for (char *c = string; *c != '\0'; ++c) {
    if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace)) {
      *insert_position = *c;
      ++insert_position;
    } else {
      insert_position = append_space_escape(insert_position);
    }
  }
  *insert_position = '\0';
  char *result = (char *) malloc(strlen(buffer)+1);
  strcpy(result, buffer);
  free(buffer);
  return result;
}

variable_types:
string
char *

variable_types:
c
char *

variable_types:
result
char *

return_type: char *


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

v3 = (char *)escape_spaces("abcd efg", argv, envp);
if ( strcmp(v3, "abcd%20efg") )
__assert_fail("strcmp(escaped_string, \"abcd%20efg\") == 0", "1.5.c", 0x28u, "main");
free(v3);
return 0;
}

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

v3 = (char *)func8("abcd efg", argv, envp);
if ( strcmp(v3, "abcd%20efg") )
__assert_fail("strcmp(escaped_string, \"abcd%20efg\") == 0", "1.5.c", 0x28u, "main");
free(v3);
return 0;
}

original_code:
int main() {
  char *escaped_string = escape_spaces("abcd efg");
  ((strcmp(escaped_string, "abcd%20efg") == 0) ? (void) (0) : __assert_fail ("strcmp(escaped_string, \"abcd%20efg\") == 0", "1.5.c", 40, __extension__ __PRETTY_FUNCTION__));
  free(escaped_string);
  return 0;
}


original_code:
static void
xterm_close (void *data)
{
  struct xterm_channel *xt = data;
  if (!xt)
    return;
  if (xt->fds.fdin != -1)
    close (xt->fds.fdin);
  if (xt->pid != -1)
    {
      kill (xt->pid, 9);
      waitpid (xt->pid, ((void *)0), 0);
    }
  if (xt->argv)
    free (xt->argv);
  xt->fds.fdin = -1;
  xt->fds.fdout = -1;
  xt->pid = -1;
  xt->argv = ((void *)0);
}

canonical_original_code:
static void xterm_close(void *data)
{
  struct xterm_channel *xt = data;
  if (!xt)
    return;
  if (xt->fds.fdin != -1)
    close (xt->fds.fdin);
  if (xt->pid != -1)
    {
      kill (xt->pid, 9);
      waitpid (xt->pid, ((void *)0), 0);
    }
  if (xt->argv)
    free (xt->argv);
  xt->fds.fdin = -1;
  xt->fds.fdout = -1;
  xt->pid = -1;
  xt->argv = ((void *)0);
}

variable_types:
data
void *

variable_types: struct xterm_channel { struct fd_channel { int fdin; int fdout; } fds; int pid; char **argv; } *

user_defined_types: struct xterm_channel { struct fd_channel fds; int pid; char **argv; }


decompiled_code:
void __fastcall xterm_exit(int status, void *arg)
{
xterm_close((__int64)arg);
}

canonical_decompiled_code:
void __fastcall func1(int status, void *arg)
{
func0((__int64)arg);
}

original_code:
static void
xterm_exit (int i, void *data)
{
  xterm_close (data);
}

canonical_original_code:
static void xterm_exit(int i, void *data)
{
  xterm_close (data);
}


decompiled_code:
__int64 __fastcall xterm_open(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
signed int v3; // eax
char *v4; // rbp
int v5; // eax
__pid_t v6; // eax
__int64 result; // rax
const char *v8; // r13
char *v9; // rax
__int64 v10; // rsi
struct termios v11; // [rsp+0h] [rbp-A8h] BYREF
char buf[104]; // [rsp+40h] [rbp-68h] BYREF

if ( a1 )
{
v1 = open("/dev/ptmx", 2);
v2 = v1;
if ( v1 < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
grantpt(v1);
unlockpt(v2);
v3 = (unsigned int)ptsname(v2);
v4 = (char *)v3;
if ( v3 )
{
v5 = open((const char *)v3, 2);
*(_DWORD *)a1 = v5;
*(_DWORD *)(a1 + 4) = v5;
if ( v5 >= 0 )
{
if ( tcgetattr(v5, &v11) >= 0 )
{
cfmakeraw(&v11);
if ( tcsetattr(*(_DWORD *)a1, 1, &v11) >= 0 )
{
v6 = fork();
*(_DWORD *)(a1 + 8) = v6;
if ( v6 != -1 )
{
if ( !v6 )
{
signal(2, (__sighandler_t)((char *)xterm_close + 1));
v8 = &v4[strlen(v4) - 2];
if ( strchr(v8, 47) )
{
v9 = _xpg_basename(v4);
sprintf(buf, "-S%s/%d", v9, v2);
}
else
{
sprintf(buf, "-S%c%c%d", (unsigned int)*v8, (unsigned int)v8[1], v2);
}
v10 = *(_QWORD *)(a1 + 16);
*(_QWORD *)v10 = "xterm";
*(_QWORD *)(v10 + 8) = buf;
execvp("xterm", (char *const *)v10);
if ( write(v2, "\n", 1uLL) < 0 )
puts("ERROR: xterm: write failed");
exit(1);
}
while ( (int)read(*(_DWORD *)a1, buf, 1uLL) >= 0 )
{
if ( buf[0] == 10 )
{
cfmakeraw(&v11);
if ( tcsetattr(*(_DWORD *)a1, 1, &v11) < 0 )
break;
return 0LL;
}
}
}
}
}
close(*(_DWORD *)a1);
}
}
else
{
*_errno_location() = 25;
}
close(v2);
*(_QWORD *)a1 = -1LL;
result = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 8) = -1;
}
}
else
{
*_errno_location() = 19;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
signed int v3; // eax
char *v4; // rbp
int v5; // eax
__pid_t v6; // eax
__int64 result; // rax
const char *v8; // r13
char *v9; // rax
__int64 v10; // rsi
struct termios v11; // [rsp+0h] [rbp-A8h] BYREF
char buf[104]; // [rsp+40h] [rbp-68h] BYREF

if ( a1 )
{
v1 = open("/dev/ptmx", 2);
v2 = v1;
if ( v1 < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
grantpt(v1);
unlockpt(v2);
v3 = (unsigned int)ptsname(v2);
v4 = (char *)v3;
if ( v3 )
{
v5 = open((const char *)v3, 2);
*(_DWORD *)a1 = v5;
*(_DWORD *)(a1 + 4) = v5;
if ( v5 >= 0 )
{
if ( tcgetattr(v5, &v11) >= 0 )
{
cfmakeraw(&v11);
if ( tcsetattr(*(_DWORD *)a1, 1, &v11) >= 0 )
{
v6 = fork();
*(_DWORD *)(a1 + 8) = v6;
if ( v6 != -1 )
{
if ( !v6 )
{
signal(2, (__sighandler_t)((char *)xterm_close + 1));
v8 = &v4[strlen(v4) - 2];
if ( strchr(v8, 47) )
{
v9 = _xpg_basename(v4);
sprintf(buf, "-S%s/%d", v9, v2);
}
else
{
sprintf(buf, "-S%c%c%d", (unsigned int)*v8, (unsigned int)v8[1], v2);
}
v10 = *(_QWORD *)(a1 + 16);
*(_QWORD *)v10 = "xterm";
*(_QWORD *)(v10 + 8) = buf;
execvp("xterm", (char *const *)v10);
if ( write(v2, "\n", 1uLL) < 0 )
puts("ERROR: xterm: write failed");
exit(1);
}
while ( (int)read(*(_DWORD *)a1, buf, 1uLL) >= 0 )
{
if ( buf[0] == 10 )
{
cfmakeraw(&v11);
if ( tcsetattr(*(_DWORD *)a1, 1, &v11) < 0 )
break;
return 0LL;
}
}
}
}
}
close(*(_DWORD *)a1);
}
}
else
{
*_errno_location() = 25;
}
close(v2);
*(_QWORD *)a1 = -1LL;
result = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 8) = -1;
}
}
else
{
*_errno_location() = 19;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int
xterm_open (void *data)
{
  struct xterm_channel *xt = data;
  int master, retval;
  char *slavename;
  struct termios termio;
  char arg[64], *fin;
  if (!data)
    {
      (*__errno_location ()) = 19;
      return -1;
    }
  master = open ("/dev/ptmx", 02);
  if (master < 0)
    return -1;
  grantpt (master);
  unlockpt (master);
  slavename = (char *) ptsname (master);
  if (!slavename)
    {
      (*__errno_location ()) = 25;
      goto closemastererror;
    }
  xt->fds.fdout = xt->fds.fdin = open (slavename, 02);
  if (xt->fds.fdout < 0)
    goto closemastererror;
  retval = tcgetattr (xt->fds.fdin, &termio);
  if (retval < 0)
    goto closeslaveerror;
  cfmakeraw (&termio);
  retval = tcsetattr (xt->fds.fdin, 1, &termio);
  if (retval < 0)
    goto closeslaveerror;
  xt->pid = fork ();
  if (xt->pid == -1)
    goto closeslaveerror;
  if (xt->pid == 0)
    {
      signal (2, ((__sighandler_t) 1));
      fin = slavename + strlen (slavename) - 2;
      if (strchr (fin, '/'))
 {
   sprintf (arg, "-S%s/%d", __xpg_basename (slavename), master);
 }
      else
 {
   sprintf (arg, "-S%c%c%d", fin[0], fin[1], master);
 }
      xt->argv[0] = "xterm";
      xt->argv[1] = arg;
      execvp ("xterm", xt->argv);
      if (write (master, "\n", 1) < 0)
 {
   printf ("ERROR: xterm: write failed\n");
 }
      exit (1);
    }
  do {
    retval = read (xt->fds.fdin, &arg, 1);
  } while (retval >= 0 && arg[0] != '\n');
  if (retval < 0)
    goto closeslaveerror;
  cfmakeraw (&termio);
  retval = tcsetattr (xt->fds.fdin, 1, &termio);
  if (retval < 0)
    goto closeslaveerror;
  return 0;
closeslaveerror:
  close (xt->fds.fdin);
closemastererror:
  close (master);
  xt->pid = xt->fds.fdin = xt->fds.fdout = -1;
  return -1;
}

canonical_original_code:
static int xterm_open(void *data)
{
  struct xterm_channel *xt = data;
  int master; int retval;
  char *slavename;
  struct termios termio;
  char arg[64]; char *fin;
  if (!data)
    {
      (*__errno_location ()) = 19;
      return -1;
    }
  master = open ("/dev/ptmx", 02);
  if (master < 0)
    return -1;
  grantpt (master);
  unlockpt (master);
  slavename = (char *) ptsname (master);
  if (!slavename)
    {
      (*__errno_location ()) = 25;
      goto closemastererror;
    }
  xt->fds.fdout = xt->fds.fdin = open (slavename, 02);
  if (xt->fds.fdout < 0)
    goto closemastererror;
  retval = tcgetattr (xt->fds.fdin, &termio);
  if (retval < 0)
    goto closeslaveerror;
  cfmakeraw (&termio);
  retval = tcsetattr (xt->fds.fdin, 1, &termio);
  if (retval < 0)
    goto closeslaveerror;
  xt->pid = fork ();
  if (xt->pid == -1)
    goto closeslaveerror;
  if (xt->pid == 0)
    {
      signal (2, ((void (*)(int)) 1));
      fin = slavename + strlen (slavename) - 2;
      if (strchr (fin, '/'))
 {
   sprintf (arg, "-S%s/%d", __xpg_basename (slavename), master);
 }
      else
 {
   sprintf (arg, "-S%c%c%d", fin[0], fin[1], master);
 }
      xt->argv[0] = "xterm";
      xt->argv[1] = arg;
      execvp ("xterm", xt->argv);
      if (write (master, "\n", 1) < 0)
 {
   printf ("ERROR: xterm: write failed\n");
 }
      exit (1);
    }
  do {
    retval = read (xt->fds.fdin, &arg, 1);
  } while (retval >= 0 && arg[0] != '\n');
  if (retval < 0)
    goto closeslaveerror;
  cfmakeraw (&termio);
  retval = tcsetattr (xt->fds.fdin, 1, &termio);
  if (retval < 0)
    goto closeslaveerror;
  return 0;
closeslaveerror:
  close (xt->fds.fdin);
closemastererror:
  close (master);
  xt->pid = xt->fds.fdin = xt->fds.fdout = -1;
  return -1;
}

variable_types: master int

variable_types: retval int

variable_types:
slavename
char *

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

variable_types:
arg
char [64]

variable_types:
fin
char *

user_defined_types: struct fd_channel { int fdin; int fdout; }


decompiled_code:
ssize_t __fastcall xterm_putc(char a1)
{
__int64 v1; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = xt_fd;
buf[0] = a1;
if ( !xt_fd )
{
xt_fd = (__int64)xterm_init_constprop_0();
if ( (unsigned int)xterm_open(xt_fd) == -1 )
{
puts("Failed to open xterm");
exit(1);
}
v1 = xt_fd;
}
return write(*(_DWORD *)(v1 + 4), buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func4(char a1)
{
__int64 v1; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = xt_fd;
buf[0] = a1;
if ( !xt_fd )
{
xt_fd = (__int64)func3();
if ( (unsigned int)func2(xt_fd) == -1 )
{
puts("Failed to open xterm");
exit(1);
}
v1 = xt_fd;
}
return write(*(_DWORD *)(v1 + 4), buf, 1uLL);
}

original_code:
void xterm_putc (char c)
{
  if (!xt_fd) {
    xt_fd = xterm_init("");
    if (xterm_open(xt_fd) == -1) {
      printf("Failed to open xterm\n");
      exit(1);
    }
  }
  write(xt_fd->fds.fdout, &c, 1);
}

canonical_original_code:
void xterm_putc(char c)
{
  if (!xt_fd) {
    xt_fd = xterm_init("");
    if (xterm_open(xt_fd) == -1) {
      printf("Failed to open xterm\n");
      exit(1);
    }
  }
  write(xt_fd->fds.fdout, &c, 1);
}

variable_types: c char


decompiled_code:
__int64 __fastcall xterm_getc(int a1)
{
int *v1; // rax
int v2; // eax
__int64 result; // rax
ssize_t v4; // rax
char buf; // [rsp+7h] [rbp-11h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

v1 = (int *)xt_fd;
if ( !xt_fd )
{
xt_fd = (__int64)xterm_init_constprop_0();
if ( (unsigned int)xterm_open(xt_fd) == -1 )
{
puts("Failed to open xterm");
exit(1);
}
v1 = (int *)xt_fd;
}
fds.fd = *v1;
fds.events = 1;
v2 = poll(&fds, 1uLL, 0);
if ( v2 < 0 )
{
perror("poll");
exit(1);
}
if ( !v2 )
return 0xFFFFFFFFLL;
if ( (fds.revents & 1) == 0 )
{
if ( (fds.revents & 0x38) != 0 )
{
puts("xterm poll error");
exit(1);
}
return 0xFFFFFFFFLL;
}
result = 0LL;
if ( !a1 )
{
v4 = read(fds.fd, &buf, 1uLL);
if ( v4 )
{
if ( v4 >= 0 )
return (unsigned int)buf;
perror("read");
}
puts("xterm read error");
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int *v1; // rax
int v2; // eax
__int64 result; // rax
ssize_t v4; // rax
char buf; // [rsp+7h] [rbp-11h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

v1 = (int *)xt_fd;
if ( !xt_fd )
{
xt_fd = (__int64)func3();
if ( (unsigned int)func2(xt_fd) == -1 )
{
puts("Failed to open xterm");
exit(1);
}
v1 = (int *)xt_fd;
}
fds.fd = *v1;
fds.events = 1;
v2 = poll(&fds, 1uLL, 0);
if ( v2 < 0 )
{
perror("poll");
exit(1);
}
if ( !v2 )
return 0xFFFFFFFFLL;
if ( (fds.revents & 1) == 0 )
{
if ( (fds.revents & 0x38) != 0 )
{
puts("xterm poll error");
exit(1);
}
return 0xFFFFFFFFLL;
}
result = 0LL;
if ( !a1 )
{
v4 = read(fds.fd, &buf, 1uLL);
if ( v4 )
{
if ( v4 >= 0 )
return (unsigned int)buf;
perror("read");
}
puts("xterm read error");
exit(1);
}
return result;
}

original_code:
int xterm_getc (int peek)
{
  if (!xt_fd) {
    xt_fd = xterm_init("");
    if (xterm_open(xt_fd) == -1) {
      printf("Failed to open xterm\n");
      exit(1);
    }
  }
  struct pollfd pollfds[1];
  pollfds[0].fd = xt_fd->fds.fdin;
  pollfds[0].events = 0x001;
  int active_fds = poll(pollfds, 1, 0);
  if ( active_fds < 0 ) {
    perror( "poll" );
    exit(1);
  }
  if (active_fds == 0) {
    return -1;
  }
  if (pollfds[0].revents & 0x001) {
    if (!peek) {
      char c;
      ssize_t bytes_read = read(pollfds[0].fd, &c, 1);
      if (bytes_read == 0) {
 printf("xterm read error\n");
 exit(1);
      } else if (bytes_read < 0) {
 perror( "read" );
 printf("xterm read error\n");
 exit(1);
      }
      return c;
    } else {
      return 0;
    }
  } else if ((pollfds[0].revents)
      & (0x008 | 0x010 | 0x020) ) {
    printf("xterm poll error\n");
    exit(1);
  }
  return -1;
}

canonical_original_code:
int xterm_getc(int peek)
{
  if (!xt_fd) {
    xt_fd = xterm_init("");
    if (xterm_open(xt_fd) == -1) {
      printf("Failed to open xterm\n");
      exit(1);
    }
  }
  struct pollfd pollfds[1];
  pollfds[0].fd = xt_fd->fds.fdin;
  pollfds[0].events = 0x001;
  int active_fds = poll(pollfds, 1, 0);
  if ( active_fds < 0 ) {
    perror( "poll" );
    exit(1);
  }
  if (active_fds == 0) {
    return -1;
  }
  if (pollfds[0].revents & 0x001) {
    if (!peek) {
      char c;
      long bytes_read = read(pollfds[0].fd, &c, 1);
      if (bytes_read == 0) {
 printf("xterm read error\n");
 exit(1);
      } else if (bytes_read < 0) {
 perror( "read" );
 printf("xterm read error\n");
 exit(1);
      }
      return c;
    } else {
      return 0;
    }
  } else if ((pollfds[0].revents)
      & (0x008 | 0x010 | 0x020) ) {
    printf("xterm poll error\n");
    exit(1);
  }
  return -1;
}

variable_types: peek int

variable_types: struct pollfd { int fd; short events; short revents; } [1]


SigmaComparison

repo: kland/person-time

decompiled_code:
__int64 __fastcall SigmaComparison(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( **(double **)a2 <= *(double *)a1 )
result = *(double *)a1 > *(double *)(*(_QWORD *)a2 + 8LL);
return result;
}

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

result = 0xFFFFFFFFLL;
if ( **(double **)a2 <= *(double *)a1 )
result = *(double *)a1 > *(double *)(*(_QWORD *)a2 + 8LL);
return result;
}

original_code:
static int SigmaComparison(const void *key, const void *elem)
{
 double s;
 struct Rectangle **sigmaInterval;
 int result;
 s = *((double *) key);
 sigmaInterval = (struct Rectangle **) elem;
 if (s < (*sigmaInterval)->sigmaMin) {
  result = -1;
 } else if ((*sigmaInterval)->sigmaMax < s) {
  result = 1;
 } else {
  result = 0;
 }
 return result;
}

canonical_original_code:
static int SigmaComparison(void *key, void *elem)
{
 double s;
 struct Rectangle **sigmaInterval;
 int result;
 s = *((double *) key);
 sigmaInterval = (struct Rectangle **) elem;
 if (s < (*sigmaInterval)->sigmaMin) {
  result = -1;
 } else if ((*sigmaInterval)->sigmaMax < s) {
  result = 1;
 } else {
  result = 0;
 }
 return result;
}

variable_types:
key
void *

variable_types:
elem
void *

variable_types: s double

variable_types: struct Rectangle { double sigmaMin; double tauMin; double personTime; } **

variable_types: result int


TauComparison

decompiled_code:
__int64 __fastcall TauComparison(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *((double *)a2 + 2) <= *(double *)a1 )
result = *(double *)a1 > *((double *)a2 + 3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *((double *)a2 + 2) <= *(double *)a1 )
result = *(double *)a1 > *((double *)a2 + 3);
return result;
}

original_code:
static int TauComparison(const void *key, const void *elem)
{
 double t;
 struct Rectangle *tauInterval;
 int result;
 t = *((double *) key);
 tauInterval = (struct Rectangle *) elem;
 if (t < tauInterval->tauMin) {
  result = -1;
 } else if (tauInterval->tauMax < t) {
  result = 1;
 } else {
  result = 0;
 }
 return result;
}

canonical_original_code:
static int TauComparison(void *key, void *elem)
{
 double t;
 struct Rectangle *tauInterval;
 int result;
 t = *((double *) key);
 tauInterval = (struct Rectangle *) elem;
 if (t < tauInterval->tauMin) {
  result = -1;
 } else if (tauInterval->tauMax < t) {
  result = 1;
 } else {
  result = 0;
 }
 return result;
}

variable_types: t double

variable_types: struct Rectangle { double sigmaMin; double tauMin; double personTime; } *


InsideGrid

decompiled_code:
_BOOL8 __fastcall InsideGrid(__int64 a1, double a2, double a3)
{
double *v3; // rdx
_BOOL8 result; // rax

v3 = **(double ***)a1;
if ( a2 < *v3 || *(double *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8) - 8) + 8LL) <= a2 || a3 < v3[2] )
result = 0LL;
else
result = v3[5 * *(int *)(a1 + 12) - 2] > a3;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, double a2, double a3)
{
double *v3; // rdx
_BOOL8 result; // rax

v3 = **(double ***)a1;
if ( a2 < *v3 || *(double *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8) - 8) + 8LL) <= a2 || a3 < v3[2] )
result = 0LL;
else
result = v3[5 * *(int *)(a1 + 12) - 2] > a3;
return result;
}

original_code:
static int InsideGrid(double s, double t, PersonTime_Grid grid)
{
 return (grid->rect[0][0].sigmaMin <= s)
  && (s < grid->rect[grid->m - 1][0].sigmaMax)
  && (grid->rect[0][0].tauMin <= t)
  && (t < grid->rect[0][grid->n - 1].tauMax);
}

canonical_original_code:
static int InsideGrid(double s, double t, struct PersonTime_GridDesc *grid)
{
 return (grid->rect[0][0].sigmaMin <= s)
  && (s < grid->rect[grid->m - 1][0].sigmaMax)
  && (grid->rect[0][0].tauMin <= t)
  && (t < grid->rect[0][grid->n - 1].tauMax);
}

variable_types: struct PersonTime_GridDesc { struct Rectangle { double sigmaMin; double tauMin; double personTime; } **rect; int m; int n; } *

user_defined_types: struct PersonTime_GridDesc { struct Rectangle **rect; int m; int n; }