decompiled_code:
__int64 __fastcall ll_indexof(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r13
unsigned int v4; // er12

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return 0xFFFFFFFFLL;
v4 = 0;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
++v4;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r13
unsigned int v4; // er12

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return 0xFFFFFFFFLL;
v4 = 0;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
++v4;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return v4;
}

original_code:
int ll_indexof(llist_t* const list, void* const elem) {
   __node_t *temp;
   size_t num_bytes;
   int count;
   if(!list) return -1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   count = 0;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return count;
      temp = temp->next;
      count++;
   }
   return -1;
}

canonical_original_code:
int ll_indexof(struct __llist_s *list, void *elem) {
   struct __node_s *temp;
   unsigned long num_bytes;
   int count;
   if(!list) return -1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   count = 0;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return count;
      temp = temp->next;
      count++;
   }
   return -1;
}


repo: bezeredi/libdstructs

decompiled_code:
void __fastcall ll_clear(__int64 a1)
{
void *v1; // rax

if ( a1 )
{
while ( ll_first(a1) )
{
v1 = (void *)ll_remf(a1);
free(v1);
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
void *v1; // rax

if ( a1 )
{
while ( ll_first(a1) )
{
v1 = (void *)func8(a1);
free(v1);
}
}
}

original_code:
void ll_clear(llist_t* const list) {
   if(!list) return;
   while(!(!ll_first(list)))
      free(ll_remf(list));
}

canonical_original_code:
void ll_clear(struct __llist_s *list) {
   if(!list) return;
   while(!(!ll_first(list)))
      free(ll_remf(list));
}

variable_types: struct __llist_s { void *__first; void *__last; unsigned long __elem_size; int __size; } *

return_type: void


decompiled_code:
void __fastcall ll_free(void *ptr)
{
if ( ptr )
{
ll_clear((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( ptr )
{
func9((__int64)ptr);
free(ptr);
}
}

original_code:
void ll_free(llist_t* const list) {
   if(!list) return;
   ll_clear(list);
   free(list);
}

canonical_original_code:
void ll_free(struct __llist_s *list) {
   if(!list) return;
   ll_clear(list);
   free(list);
}

user_defined_types: struct __llist_s { void *__first; void *__last; unsigned long __elem_size; int __size; }


decompiled_code:
// attributes: thunk
void li_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func12(void *ptr)
{
free(ptr);
}

original_code:
void li_free(ll_itr_t* const itr) {
   free(itr);
}

canonical_original_code:
void li_free(struct __ll_iter_s *itr) {
   free(itr);
}

variable_types: struct __ll_iter_s { void *__next; void *__prev; } *


decompiled_code:
_BOOL8 __fastcall li_hasnext(_QWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 != 0LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_QWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 != 0LL;
else
result = 0LL;
return result;
}

original_code:
int li_hasnext(ll_itr_t* const itr) {
   if(!itr) return !1;
   return (itr->__next ? 1 : !1);
}

canonical_original_code:
int li_hasnext(struct __ll_iter_s *itr) {
   if(!itr) return !1;
   return (itr->__next ? 1 : !1);
}

return_type: int

user_defined_types: struct __ll_iter_s { void *__next; void *__prev; }


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

if ( a1 )
result = *(_QWORD *)(a1 + 8) != 0LL;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8) != 0LL;
else
result = 0LL;
return result;
}

original_code:
int li_hasprev(ll_itr_t* const itr) {
   if(!itr) return !1;
   return (itr->__prev ? 1 : !1);
}

canonical_original_code:
int li_hasprev(struct __ll_iter_s *itr) {
   if(!itr) return !1;
   return (itr->__prev ? 1 : !1);
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int v_size(vect_t* const v) {
   return (v ? v->__size : -1);
}

canonical_original_code:
int v_size(struct __vect_s *v) {
   return (v ? v->__size : -1);
}

variable_types: struct __vect_s { int **__elements; unsigned long __elem_size; int __cap; int __size; } *


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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int v_cap(vect_t* const v) {
   return (v ? v->__cap : -1);
}

canonical_original_code:
int v_cap(struct __vect_s *v) {
   return (v ? v->__cap : -1);
}

user_defined_types: struct __vect_s { int **__elements; unsigned long __elem_size; int __cap; int __size; }


decompiled_code:
__int64 __fastcall v_add(__int64 a1, int a2, __int64 a3)
{
int v3; // er14
__int64 result; // rax
int v5; // er12
__int64 v7; // rbp

if ( a2 < 0 || !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 20);
result = 0LL;
if ( v3 >= a2 )
{
v5 = v3 + 1;
*(_DWORD *)(a1 + 20) = v3 + 1;
if ( v3 + 1 == *(_DWORD *)(a1 + 16) )
_v_expand(a1);
v7 = *(_QWORD *)a1;
if ( v5 > a2 )
memmove(
(void *)(v7 + 8LL * v5 - 8LL * (unsigned int)(v3 - a2)),
(const void *)(v7 + 8LL * v5 - 8LL * (unsigned int)(v3 - a2) - 8),
8LL * (unsigned int)(v3 - a2) + 8);
*(_QWORD *)(v7 + 8LL * a2) = a3;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
int v3; // er14
__int64 result; // rax
int v5; // er12
__int64 v7; // rbp

if ( a2 < 0 || !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 20);
result = 0LL;
if ( v3 >= a2 )
{
v5 = v3 + 1;
*(_DWORD *)(a1 + 20) = v3 + 1;
if ( v3 + 1 == *(_DWORD *)(a1 + 16) )
func0(a1);
v7 = *(_QWORD *)a1;
if ( v5 > a2 )
memmove(
(void *)(v7 + 8LL * v5 - 8LL * (unsigned int)(v3 - a2)),
(const void *)(v7 + 8LL * v5 - 8LL * (unsigned int)(v3 - a2) - 8),
8LL * (unsigned int)(v3 - a2) + 8);
*(_QWORD *)(v7 + 8LL * a2) = a3;
result = 1LL;
}
return result;
}

original_code:
int v_add(vect_t* const v, int index, void* const elem) {
   int i, size;
   if(!v) return !1;
   if(index < 0 || index > v->__size)
      return !1;
   size = ++v->__size;
   if(size == v->__cap)
      __v_expand(v);
   for(i = size; i > index; i--)
      v->__elements[i] = v->__elements[i - 1];
   v->__elements[index] = elem;
   return 1;
}

canonical_original_code:
int v_add(struct __vect_s *v, int index, void *elem) {
   int i; int size;
   if(!v) return !1;
   if(index < 0 || index > v->__size)
      return !1;
   size = ++v->__size;
   if(size == v->__cap)
      __v_expand(v);
   for(i = size; i > index; i--)
      v->__elements[i] = v->__elements[i - 1];
   v->__elements[index] = elem;
   return 1;
}

variable_types: index int

variable_types:
elem
void *

variable_types: i int

variable_types: size int


decompiled_code:
__int64 __fastcall v_addf(__int64 a1, __int64 a2)
{
return v_add(a1, 0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return func3(a1, 0, a2);
}

original_code:
void v_addf(vect_t* const v, void* const elem) {
   v_add(v, 0, elem);
}

canonical_original_code:
void v_addf(struct __vect_s *v, void *elem) {
   v_add(v, 0, elem);
}


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

if ( a1 )
result = v_add(a1, *(_DWORD *)(a1 + 20), a2);
return result;
}

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

if ( a1 )
result = func3(a1, *(_DWORD *)(a1 + 20), a2);
return result;
}

original_code:
void v_addl(vect_t* const v, void* const elem) {
   if(!v) return;
   v_add(v, v->__size, elem);
}

canonical_original_code:
void v_addl(struct __vect_s *v, void *elem) {
   if(!v) return;
   v_add(v, v->__size, elem);
}


decompiled_code:
__int64 __fastcall v_contains(__int64 a1, const void *a2)
{
int v2; // eax
size_t v3; // r12
const void **v4; // rbx
__int64 v5; // r13

if ( !a1 )
return 0LL;
v2 = *(_DWORD *)(a1 + 20);
v3 = *(_QWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v4 = *(const void ***)a1;
v5 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( memcmp(a2, *v4, v3) )
{
if ( ++v4 == (const void **)v5 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2)
{
int v2; // eax
size_t v3; // r12
const void **v4; // rbx
__int64 v5; // r13

if ( !a1 )
return 0LL;
v2 = *(_DWORD *)(a1 + 20);
v3 = *(_QWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v4 = *(const void ***)a1;
v5 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( memcmp(a2, *v4, v3) )
{
if ( ++v4 == (const void **)v5 )
return 0LL;
}
return 1LL;
}

original_code:
int v_contains(vect_t* const v, void* const elem) {
   size_t num_bytes;
   int i, size;
   if(!v) return !1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return 1;
   return !1;
}

canonical_original_code:
int v_contains(struct __vect_s *v, void *elem) {
   unsigned long num_bytes;
   int i; int size;
   if(!v) return !1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return 1;
   return !1;
}


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

if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 20) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
else
result = 0LL;
return result;
}

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

if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 20) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
else
result = 0LL;
return result;
}

original_code:
void* v_get(vect_t* const v, int index) {
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   return v->__elements[index];
}

canonical_original_code:
void *v_get(struct __vect_s *v, int index) {
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   return v->__elements[index];
}

return_type: void *


decompiled_code:
__int64 __fastcall v_first(__int64 a1)
{
return v_get(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return func7(a1, 0);
}

original_code:
void* v_first(vect_t* const v) {
   return v_get(v, 0);
}

canonical_original_code:
void *v_first(struct __vect_s *v) {
   return v_get(v, 0);
}


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

if ( a1 )
result = v_get(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func7(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

original_code:
void* v_last(vect_t* const v) {
   if(!v) return ((void *)0);
   return v_get(v, v->__size - 1);
}

canonical_original_code:
void *v_last(struct __vect_s *v) {
   if(!v) return ((void *)0);
   return v_get(v, v->__size - 1);
}


decompiled_code:
__int64 __fastcall v_indexof(__int64 *a1, const void *a2)
{
__int64 v2; // rbp
size_t v3; // r14
__int64 v4; // r15
__int64 v5; // rbx
unsigned int v6; // er13

if ( !a1 )
return (unsigned int)-1;
v2 = *((int *)a1 + 5);
v3 = a1[1];
if ( (int)v2 <= 0 )
return (unsigned int)-1;
v4 = *a1;
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( !memcmp(a2, *(const void **)(v4 + 8 * v5), v3) )
break;
if ( ++v5 == v2 )
return (unsigned int)-1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, const void *a2)
{
__int64 v2; // rbp
size_t v3; // r14
__int64 v4; // r15
__int64 v5; // rbx
unsigned int v6; // er13

if ( !a1 )
return (unsigned int)-1;
v2 = *((int *)a1 + 5);
v3 = a1[1];
if ( (int)v2 <= 0 )
return (unsigned int)-1;
v4 = *a1;
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( !memcmp(a2, *(const void **)(v4 + 8 * v5), v3) )
break;
if ( ++v5 == v2 )
return (unsigned int)-1;
}
return v6;
}

original_code:
int v_indexof(vect_t* const v, void* const elem) {
   size_t num_bytes;
   int i, size;
   if(!v) return -1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return i;
   return -1;
}

canonical_original_code:
int v_indexof(struct __vect_s *v, void *elem) {
   unsigned long num_bytes;
   int i; int size;
   if(!v) return -1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return i;
   return -1;
}


decompiled_code:
__int64 __fastcall v_clear(__int64 a1)
{
return v_apply(a1, &free);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func11(a1, &free);
}

original_code:
void v_clear(vect_t* const v) {
   v_apply(v, free);
}

canonical_original_code:
void v_clear(struct __vect_s *v) {
   v_apply(v, free);
}


decompiled_code:
void __fastcall v_free(void *ptr)
{
if ( ptr )
{
v_clear((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
if ( ptr )
{
func12((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void v_free(vect_t* const v) {
   if(!v) return;
   v_clear(v);
   free(v->__elements);
   free(v);
}

canonical_original_code:
void v_free(struct __vect_s *v) {
   if(!v) return;
   v_clear(v);
   free(v->__elements);
   free(v);
}


original_code:
void* v_rem(vect_t* const v, int index) {
   void *target;
   int i, size;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   if((!v_first(v))) return ((void *)0);
   size = v->__size;
   target = v->__elements[index];
   for(i = index; i < size; i++)
      v->__elements[i] = v->__elements[i + 1];
   v->__size--;
   return target;
}

canonical_original_code:
void *v_rem(struct __vect_s *v, int index) {
   void *target;
   int i; int size;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   if((!v_first(v))) return ((void *)0);
   size = v->__size;
   target = v->__elements[index];
   for(i = index; i < size; i++)
      v->__elements[i] = v->__elements[i + 1];
   v->__size--;
   return target;
}

variable_types:
target
void *


decompiled_code:
__int64 __fastcall v_remf(__int64 a1)
{
return v_rem(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func14(a1, 0);
}

original_code:
void* v_remf(vect_t* const v) {
   return v_rem(v, 0);
}

canonical_original_code:
void *v_remf(struct __vect_s *v) {
   return v_rem(v, 0);
}


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

if ( a1 )
result = v_rem(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func14(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

original_code:
void* v_reml(vect_t* const v) {
   if(!v) return ((void *)0);
   return v_rem(v, v->__size - 1);
}

canonical_original_code:
void *v_reml(struct __vect_s *v) {
   if(!v) return ((void *)0);
   return v_rem(v, v->__size - 1);
}


decompiled_code:
__int64 __fastcall v_set(__int64 a1, int a2, __int64 a3)
{
__int64 *v3; // rcx
__int64 result; // rax

if ( a2 < 0 || !a1 || *(_DWORD *)(a1 + 20) <= a2 )
return 0LL;
v3 = (__int64 *)(*(_QWORD *)a1 + 8LL * a2);
result = *v3;
*v3 = a3;
return result;
}

original_code:
void* v_set(vect_t* const v, int index, void* const elem) {
   void *target;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   target = v->__elements[index];
   v->__elements[index] = elem;
   return target;
}

canonical_original_code:
void *v_set(struct __vect_s *v, int index, void *elem) {
   void *target;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   target = v->__elements[index];
   v->__elements[index] = elem;
   return target;
}


decompiled_code:
void *__fastcall v_toarr(__int64 a1)
{
size_t v2; // r12
void *v3; // rdi
void *result; // rax

if ( !a1 )
return 0LL;
v2 = 8LL * *(int *)(a1 + 20);
v3 = malloc(v2);
if ( v3 )
result = memcpy(v3, *(const void **)a1, v2);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func18(__int64 a1)
{
size_t v2; // r12
void *v3; // rdi
void *result; // rax

if ( !a1 )
return 0LL;
v2 = 8LL * *(int *)(a1 + 20);
v3 = malloc(v2);
if ( v3 )
result = memcpy(v3, *(const void **)a1, v2);
else
result = 0LL;
return result;
}

original_code:
void** v_toarr(vect_t* const v) {
   int **array;
   int size;
   if(!v) return ((void *)0);
   size = v->__size;
   array = malloc(sizeof(void*) * size);
   if(!array) return ((void *)0);
   array = memcpy(array, v->__elements, sizeof(void*) * size);
   return (void**) array;
}

canonical_original_code:
void **v_toarr(struct __vect_s *v) {
   int **array;
   int size;
   if(!v) return ((void *)0);
   size = v->__size;
   array = malloc(sizeof(void *) * size);
   if(!array) return ((void *)0);
   array = memcpy(array, v->__elements, sizeof(void *) * size);
   return (void **) array;
}

variable_types:
array
int **

return_type: void **


original_code:
void v_trim(vect_t* const v) {
   int size;
   if(!v) return;
   size = v->__size;
   v->__elements = realloc(v->__elements, sizeof(void*) * size);
   v->__cap = size;
}

canonical_original_code:
void v_trim(struct __vect_s *v) {
   int size;
   if(!v) return;
   size = v->__size;
   v->__elements = realloc(v->__elements, sizeof(void *) * size);
   v->__cap = size;
}


decompiled_code:
// attributes: thunk
void vi_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func20(void *ptr)
{
free(ptr);
}

original_code:
void vi_free(v_itr_t* const itr) {
   free(itr);
}

canonical_original_code:
void vi_free(struct __v_itr_s *itr) {
   free(itr);
}

variable_types: struct __v_itr_s { struct __vect_s { int **__elements; unsigned long __elem_size; int __cap; int __size; } *vector; int pos; } *

user_defined_types: struct __v_itr_s { struct __vect_s *vector; int pos; }


decompiled_code:
_BOOL8 __fastcall vi_hasnext(_DWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *(_DWORD *)(*(_QWORD *)a1 + 20LL) != a1[2];
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func21(_DWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *(_DWORD *)(*(_QWORD *)a1 + 20LL) != a1[2];
else
result = 0LL;
return result;
}

original_code:
int vi_hasnext(v_itr_t* const itr) {
   if(!itr) return !1;
   if(itr->pos == itr->vector->__size)
      return !1;
   return 1;
}

canonical_original_code:
int vi_hasnext(struct __v_itr_s *itr) {
   if(!itr) return !1;
   if(itr->pos == itr->vector->__size)
      return !1;
   return 1;
}


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

if ( a1 )
result = *(_DWORD *)(a1 + 8) != 0;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_DWORD *)(a1 + 8) != 0;
else
result = 0LL;
return result;
}

original_code:
int vi_hasprev(v_itr_t* const itr) {
   if(!itr) return !1;
   return (itr->pos ? 1 : !1);
}

canonical_original_code:
int vi_hasprev(struct __v_itr_s *itr) {
   if(!itr) return !1;
   return (itr->pos ? 1 : !1);
}


decompiled_code:
__int64 __fastcall vi_next(_DWORD *a1)
{
if ( !a1 )
return 0LL;
if ( !vi_hasnext(a1) )
return 0LL;
return *(_QWORD *)(**(_QWORD **)a1 + 8LL * (int)a1[2]++);
}

canonical_decompiled_code:
__int64 __fastcall func23(_DWORD *a1)
{
if ( !a1 )
return 0LL;
if ( !func21(a1) )
return 0LL;
return *(_QWORD *)(**(_QWORD **)a1 + 8LL * (int)a1[2]++);
}

original_code:
void* vi_next(v_itr_t* const itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasnext(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos++;
   return target;
}

canonical_original_code:
void *vi_next(struct __v_itr_s *itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasnext(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos++;
   return target;
}


decompiled_code:
__int64 __fastcall vi_prev(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( !vi_hasprev(a1) )
return 0LL;
return *(_QWORD *)(**(_QWORD **)a1 + 8LL * (int)(*(_DWORD *)(a1 + 8))--);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( !func22(a1) )
return 0LL;
return *(_QWORD *)(**(_QWORD **)a1 + 8LL * (int)(*(_DWORD *)(a1 + 8))--);
}

original_code:
void* vi_prev(v_itr_t* const itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasprev(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos--;
   return target;
}

canonical_original_code:
void *vi_prev(struct __v_itr_s *itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasprev(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos--;
   return target;
}


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

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

original_code:
void* bst_root(bst_t* const tree) {
   return ((void *)0);
}

canonical_original_code:
void *bst_root(struct __bst_s *tree) {
   return ((void *)0);
}

variable_types: struct __bst_s { void *__elem; unsigned long __elem_size; struct __bst_s *__left; struct __bst_s *__right; } *


decompiled_code:
// attributes: thunk
__int64 __fastcall bst_size(__int64 a1)
{
return bst_height_localalias(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return func2(a1);
}

original_code:
int bst_size(bst_t* const tree) {
   if(!tree) return -1;
   return 0;
}

canonical_original_code:
int bst_size(struct __bst_s *tree) {
   if(!tree) return -1;
   return 0;
}

user_defined_types: struct __bst_s { void *__elem; unsigned long __elem_size; struct __bst_s *__left; struct __bst_s *__right; }


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

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

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

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

original_code:
bst_t* bst_left(bst_t* const tree) {
   if(!tree) return ((void *)0);
   return tree->__left;
}

canonical_original_code:
struct __bst_s *bst_left(struct __bst_s *tree) {
   if(!tree) return ((void *)0);
   return tree->__left;
}

variable_types:
tree
struct __bst_s *

return_type: struct __bst_s { void *__elem; unsigned long __elem_size; struct __bst_s *__left; struct __bst_s *__right; } *


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

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

original_code:
bst_t* bst_right(bst_t* const tree) {
   if(!tree) return ((void *)0);
   return tree->__right;
}

canonical_original_code:
struct __bst_s *bst_right(struct __bst_s *tree) {
   if(!tree) return ((void *)0);
   return tree->__right;
}


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

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

original_code:
int bst_add(bst_t* const tree, void* const elem) {
   if(!tree || !elem) return !1;
   return !1;
}

canonical_original_code:
int bst_add(struct __bst_s *tree, void *elem) {
   if(!tree || !elem) return !1;
   return !1;
}


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

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

original_code:
void* bst_rem(bst_t* const tree, void* const elem) {
   if(!tree || !elem) return ((void *)0);
   return ((void *)0);
}

canonical_original_code:
void *bst_rem(struct __bst_s *tree, void *elem) {
   if(!tree || !elem) return ((void *)0);
   return ((void *)0);
}


decompiled_code:
void *__fastcall bst_toarr(__int64 a1)
{
int v1; // eax

if ( !a1 )
return 0LL;
v1 = bst_size(a1);
return malloc(8LL * v1);
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1)
{
int v1; // eax

if ( !a1 )
return 0LL;
v1 = func3(a1);
return malloc(8LL * v1);
}

original_code:
void** bst_toarr(bst_t* const tree) {
   int **array;
   if(!tree) return ((void *)0);
   array = malloc(sizeof(void*) * bst_size(tree));
   if(!array) return ((void *)0);
   return (void**) array;
}

canonical_original_code:
void **bst_toarr(struct __bst_s *tree) {
   int **array;
   if(!tree) return ((void *)0);
   array = malloc(sizeof(void *) * bst_size(tree));
   if(!array) return ((void *)0);
   return (void **) array;
}


repo: bfabio/packddir

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

result = malloc(8uLL);
if ( !result )
{
fwrite("upackddir: malloc() failed.\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
result[1] = 0LL;
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( !result )
{
fwrite("upackddir: malloc() failed.\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
result[1] = 0LL;
*result = 0LL;
return result;
}

original_code:
list_t list_new()
{
 list_t l;
 l = malloc(sizeof(list_t));
 if (!l) {
  do { fprintf(stderr, "upackddir: " "malloc() failed.\n"); } while (0);
  exit(1);
 }
 l->first = l->last = ((void *)0);
 return l;
}

canonical_original_code:
struct list *list_new()
{
 struct list *l;
 l = malloc(sizeof(list_t));
 if (!l) {
  do { fprintf(stderr, "upackddir: " "malloc() failed.\n"); } while (0);
  exit(1);
 }
 l->first = l->last = ((void *)0);
 return l;
}

variable_types: struct list { struct list_node { struct list_node *prev; struct list_node *next; void *element; } *first; struct list_node *last; } *

user_defined_types: struct list { struct list_node *first; struct list_node *last; }


original_code:
void list_delete(list_t list, list_node_t node)
{
 if (list->first == list->last) {
  list->first = list->last = ((void *)0);
 } else if (node == list->first) {
  list->first = node->next;
 } else if (node == list->last) {
  list->last = node->prev;
 } else {
  node->prev->next = node->next;
  node->next->prev = node->prev;
 }
 free(node);
}

canonical_original_code:
void list_delete(struct list *list, struct list_node *node)
{
 if (list->first == list->last) {
  list->first = list->last = ((void *)0);
 } else if (node == list->first) {
  list->first = node->next;
 } else if (node == list->last) {
  list->last = node->prev;
 } else {
  node->prev->next = node->next;
  node->next->prev = node->prev;
 }
 free(node);
}

variable_types:
node
struct list_node *

user_defined_types: struct list_node { struct list_node *prev; struct list_node *next; void *element; }


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int list_empty(list_t list)
{
 return list->first ? 1 : 0;
}

canonical_original_code:
int list_empty(struct list *list)
{
 return list->first ? 1 : 0;
}


repo: bfeng/MG

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

if ( a1 )
{
puts("#Error relating to buffer create or desotry!!");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
if ( a1 == -6 )
{
result = puts("Out Of Host Memory");
}
else
{
if ( a1 >= -5 )
{
if ( a1 == -5 )
return puts("failure to allocate OpenCL resources on the device");
}
else
{
if ( a1 == -38 )
return puts("Memroy Object Invalid");
if ( a1 == -36 )
return puts("invalid command queue");
}
result = puts("Impossible Error.");
}
}
return result;
}

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

if ( a1 )
{
puts("#Error relating to buffer create or desotry!!");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
if ( a1 == -6 )
{
result = puts("Out Of Host Memory");
}
else
{
if ( a1 >= -5 )
{
if ( a1 == -5 )
return puts("failure to allocate OpenCL resources on the device");
}
else
{
if ( a1 == -38 )
return puts("Memroy Object Invalid");
if ( a1 == -36 )
return puts("invalid command queue");
}
result = puts("Impossible Error.");
}
}
return result;
}

original_code:
static void check_err(cl_int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer create or desotry!!\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      default:
        printf("Impossible Error.\n");
        break;
    }
  }
}

canonical_original_code:
static void check_err(int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer create or desotry!!\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      default:
        printf("Impossible Error.\n");
        break;
    }
  }
}

variable_types: err int


DisposeQueues

decompiled_code:
int DisposeQueues()
{
int v0; // eax
int v1; // eax
int v2; // eax
int v3; // eax

v0 = clReleaseMemObject(d_newJobs);
check_err(v0);
v1 = clReleaseMemObject(d_finishedJobs);
check_err(v1);
v2 = clReleaseMemObject(d_newJobs_array);
check_err(v2);
v3 = clReleaseMemObject(d_finishedJobs_array);
return check_err(v3);
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
int v1; // eax
int v2; // eax
int v3; // eax

v0 = clReleaseMemObject(d_newJobs);
func0(v0);
v1 = clReleaseMemObject(d_finishedJobs);
func0(v1);
v2 = clReleaseMemObject(d_newJobs_array);
func0(v2);
v3 = clReleaseMemObject(d_finishedJobs_array);
return func0(v3);
}

original_code:
void DisposeQueues() {
   cl_int ERR;
   ERR = clReleaseMemObject(d_newJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_newJobs_array);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs_array);
   check_err(ERR);
}

canonical_original_code:
void DisposeQueues() {
   int ERR;
   ERR = clReleaseMemObject(d_newJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_newJobs_array);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs_array);
   check_err(ERR);
}

variable_types: ERR int


decompiled_code:
_BOOL8 __fastcall h_IsEmpty(_DWORD *a1)
{
return (a1[3] + 1) % a1[2] == a1[4];
}

original_code:
int h_IsEmpty(Queue Q) {
  return (Q->Rear+1)%Q->Capacity == Q->Front;
}

canonical_original_code:
int h_IsEmpty(struct QueueRecord *Q) {
  return (Q->Rear+1)%Q->Capacity == Q->Front;
}

variable_types: struct QueueRecord { struct JobDescription { int JobID; int JobType; int numThreads; int params; } *Array; int Capacity; int Rear; int Front; int ReadLock; } *

user_defined_types: struct QueueRecord { struct JobDescription *Array; int Capacity; int Rear; int Front; int ReadLock; }


decompiled_code:
_BOOL8 __fastcall h_IsFull(_DWORD *a1)
{
return (a1[3] + 2) % a1[2] == a1[4];
}

original_code:
int h_IsFull(Queue Q) {
  return (Q->Rear+2)%Q->Capacity == Q->Front;
}

canonical_original_code:
int h_IsFull(struct QueueRecord *Q) {
  return (Q->Rear+2)%Q->Capacity == Q->Front;
}

user_defined_types: struct JobDescription { int JobID; int JobType; int numThreads; int params; }


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

if ( a1 )
{
puts("#Error relating to buffer read or write!!(SafeMemCopy)");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
switch ( a1 )
{
case -59:
result = puts("invalid operation");
break;
case -57:
result = puts("invalid event list");
break;
case -38:
result = puts("Memroy Object Invalid");
break;
case -36:
result = puts("invalid command queue");
break;
case -34:
result = puts("invalid context");
break;
case -30:
result = puts("invalid value");
break;
case -6:
result = puts("Out Of Host Memory");
break;
case -5:
result = puts("failure to allocate OpenCL resources on the device");
break;
case -4:
result = puts("mem allocation failure");
break;
default:
result = puts("Impossible Error.");
break;
}
}
return result;
}

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

if ( a1 )
{
puts("#Error relating to buffer read or write!!(SafeMemCopy)");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
switch ( a1 )
{
case -59:
result = puts("invalid operation");
break;
case -57:
result = puts("invalid event list");
break;
case -38:
result = puts("Memroy Object Invalid");
break;
case -36:
result = puts("invalid command queue");
break;
case -34:
result = puts("invalid context");
break;
case -30:
result = puts("invalid value");
break;
case -6:
result = puts("Out Of Host Memory");
break;
case -5:
result = puts("failure to allocate OpenCL resources on the device");
break;
case -4:
result = puts("mem allocation failure");
break;
default:
result = puts("Impossible Error.");
break;
}
}
return result;
}

original_code:
static void check_err3(cl_int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer read or write!!(SafeMemCopy)\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      case -34:
        printf("invalid context\n");
        break;
      case -30:
        printf("invalid value\n");
        break;
      case -57:
        printf("invalid event list\n");
        break;
      case -4:
        printf("mem allocation failure\n");
        break;
      case -59:
        printf("invalid operation\n");
        break;
      default:
        printf("Impossible Error.\n");
    }
  }
}

canonical_original_code:
static void check_err3(int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer read or write!!(SafeMemCopy)\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      case -34:
        printf("invalid context\n");
        break;
      case -30:
        printf("invalid value\n");
        break;
      case -57:
        printf("invalid event list\n");
        break;
      case -4:
        printf("mem allocation failure\n");
        break;
      case -59:
        printf("invalid operation\n");
        break;
      default:
        printf("Impossible Error.\n");
    }
  }
}


main

canonical_name: main

repo: bfeng/msh

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // [rsp+0h] [rbp-1108h] BYREF
char v4; // [rsp+4h] [rbp-1104h]
char v5[2048]; // [rsp+100h] [rbp-1008h] BYREF
char v6[2056]; // [rsp+900h] [rbp-808h] BYREF

e_variables = (__int64)malloc(0x1000uLL);
read_profile(v6, argv);
init_sh(v6);
while ( 1 )
{
print_prompt_sign(v6);
read_cmdline(&v3);
if ( v3 == 1953069157 && !v4 )
exit(0);
execute(&v3, v5);
}
}

original_code:
int main(void)
{
  char cmdline[256];
  char *argv[256];
  char * profile[256];
 e_variables=(struct env_var *)malloc(sizeof(struct env_var)*256);
  read_profile(profile);
  init_sh(profile);
  while (1)
  {
    print_prompt_sign(profile);
    read_cmdline(cmdline);
    if (strcmp("exit", cmdline) == 0)
      exit(0);
    execute(cmdline, argv);
  }
  puts("Bye");
  return 0;
}

canonical_original_code:
int main()
{
  char cmdline[256];
  char *argv[256];
  char *profile[256];
 e_variables=(struct env_var *)malloc(sizeof(struct env_var)*256);
  read_profile(profile);
  init_sh(profile);
  while (1)
  {
    print_prompt_sign(profile);
    read_cmdline(cmdline);
    if (strcmp("exit", cmdline) == 0)
      exit(0);
    execute(cmdline, argv);
  }
  puts("Bye");
  return 0;
}

variable_types:
cmdline
char [256]

variable_types:
argv
char *[256]

variable_types:
profile
char *[256]

user_defined_types: struct env_var { char *name; int value; }


repo: bgdev/calc

decompiled_code:
__int64 __fastcall copy_x(int *a1)
{
__int64 result; // rax
int v2; // edx

result = (unsigned int)a1[1];
v2 = *a1;
a1[4] = result;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1)
{
__int64 result; // rax
int v2; // edx

result = (unsigned int)a1[1];
v2 = *a1;
a1[4] = result;
a1[1] = v2;
return result;
}

original_code:
int
copy_x (struct calc *c)
{
  c->tmp = c->y;
  c->y = c->x;
  return c->tmp;
}

canonical_original_code:
int copy_x(struct calc *c)
{
  c->tmp = c->y;
  c->y = c->x;
  return c->tmp;
}

variable_types: struct calc { int x; int flags; int op; int tmp; } *


decompiled_code:
__int64 __fastcall is_operation(char a1)
{
return ((a1 & 0xFD) == 45) | (unsigned __int8)((unsigned __int8)(a1 - 42) <= 1u);
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
return ((a1 & 0xFD) == 45) | (unsigned __int8)((unsigned __int8)(a1 - 42) <= 1u);
}

variable_types: c char


decompiled_code:
_BOOL8 __fastcall is_flag_on(__int64 a1, int a2)
{
return (*(_DWORD *)(a1 + 8) & a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, int a2)
{
return (*(_DWORD *)(a1 + 8) & a2) != 0;
}

original_code:
int
is_flag_on (struct calc *c, int flag)
{
  return !!(c->flags & flag);
}

canonical_original_code:
int is_flag_on(struct calc *c, int flag)
{
  return !!(c->flags & flag);
}

variable_types: flag int

user_defined_types: struct calc { int x; int flags; int op; int tmp; }


decompiled_code:
_BOOL8 __fastcall set_flag(__int64 a1, int a2)
{
_BOOL8 result; // rax
int v3; // ecx
int v4; // esi
int v5; // ecx
int v6; // edx

result = is_flag_on(a1, a2);
v4 = v3 | *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)(a1 + 8) & ~v3;
if ( v6 )
v5 = v4;
*(_DWORD *)(a1 + 8) = v5;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(__int64 a1, int a2)
{
_BOOL8 result; // rax
int v3; // ecx
int v4; // esi
int v5; // ecx
int v6; // edx

result = func11(a1, a2);
v4 = v3 | *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)(a1 + 8) & ~v3;
if ( v6 )
v5 = v4;
*(_DWORD *)(a1 + 8) = v5;
return result;
}

original_code:
int
set_flag (struct calc *c, int flag, int on)
{
  int prev = is_flag_on (c, flag);
  if (on)
    c->flags |= flag;
  else
    c->flags &= ~flag;
  return prev;
}

canonical_original_code:
int set_flag(struct calc *c, int flag, int on)
{
  int prev = is_flag_on (c, flag);
  if (on)
    c->flags |= flag;
  else
    c->flags &= ~flag;
  return prev;
}

variable_types: on int

variable_types: prev int


eq

decompiled_code:
__int64 __fastcall eq(int *a1)
{
int v1; // eax
int v3; // ecx

v1 = a1[3];
if ( v1 == 42 )
{
*a1 *= a1[1];
set_flag((__int64)a1, 8);
return (unsigned int)*a1;
}
if ( v1 == 43 )
{
if ( set_flag((__int64)a1, 16) )
*a1 += a1[1];
else
*a1 += copy_x(a1);
LABEL_12:
set_flag((__int64)a1, 8);
return (unsigned int)*a1;
}
if ( v1 != 45 )
{
if ( v1 == 47 )
{
if ( !set_flag((__int64)a1, 16) )
swap_xy((unsigned int *)a1);
v3 = a1[1];
if ( v3 )
*a1 /= v3;
else
set_flag((__int64)a1, 2);
}
goto LABEL_12;
}
if ( !set_flag((__int64)a1, 16) )
swap_xy((unsigned int *)a1);
*a1 -= a1[1];
set_flag((__int64)a1, 8);
return (unsigned int)*a1;
}

original_code:
int
eq (struct calc *c)
{
  if (c->op == '*')
    c->x *= c->y;
  else if (c->op == '+')
    c->x += !set_flag (c, 0x10, 1) ? copy_x (c) : c->y;
  else if (c->op == '-')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      c->x -= c->y;
    }
  else if (c->op == '/')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      if (c->y == 0)
        set_flag (c, 0x2, 1);
      else
        c->x /= c->y;
    }
  set_flag (c, 0x8, 0);
  return c->x;
}

canonical_original_code:
int eq(struct calc *c)
{
  if (c->op == '*')
    c->x *= c->y;
  else if (c->op == '+')
    c->x += !set_flag (c, 0x10, 1) ? copy_x (c) : c->y;
  else if (c->op == '-')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      c->x -= c->y;
    }
  else if (c->op == '/')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      if (c->y == 0)
        set_flag (c, 0x2, 1);
      else
        c->x /= c->y;
    }
  set_flag (c, 0x8, 0);
  return c->x;
}


decompiled_code:
__int64 __fastcall calc_process_cmd(int *a1, char a2)
{
_BOOL4 v2; // er8
__int64 result; // rax
int v4; // er8
int v5; // eax
int v6; // er8

v2 = is_flag_on((__int64)a1, 2);
result = 0LL;
if ( !v2 )
{
if ( ((*__ctype_b_loc())[a2] & 0x800) != 0 )
{
if ( set_flag((__int64)a1, 1) )
{
result = (unsigned int)(v6 + 10 * *a1);
*a1 = result;
}
else
{
*a1 = v6;
set_flag((__int64)a1, 8);
result = (unsigned int)*a1;
}
}
else if ( (unsigned int)is_operation(a2) )
{
if ( is_flag_on((__int64)a1, 8) )
eq(a1);
v5 = *a1;
a1[3] = v4;
a1[1] = v5;
set_flag((__int64)a1, 1);
set_flag((__int64)a1, 16);
result = (unsigned int)*a1;
}
else
{
if ( a2 == 61 )
{
eq(a1);
set_flag((__int64)a1, 1);
}
result = (unsigned int)*a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int *a1, char a2)
{
_BOOL4 v2; // er8
__int64 result; // rax
int v4; // er8
int v5; // eax
int v6; // er8

v2 = func11((__int64)a1, 2);
result = 0LL;
if ( !v2 )
{
if ( ((*__ctype_b_loc())[a2] & 0x800) != 0 )
{
if ( func12((__int64)a1, 1) )
{
result = (unsigned int)(v6 + 10 * *a1);
*a1 = result;
}
else
{
*a1 = v6;
func12((__int64)a1, 8);
result = (unsigned int)*a1;
}
}
else if ( (unsigned int)func9(a2) )
{
if ( func11((__int64)a1, 8) )
func13(a1);
v5 = *a1;
a1[3] = v4;
a1[1] = v5;
func12((__int64)a1, 1);
func12((__int64)a1, 16);
result = (unsigned int)*a1;
}
else
{
if ( a2 == 61 )
{
func13(a1);
func12((__int64)a1, 1);
}
result = (unsigned int)*a1;
}
}
return result;
}

original_code:
int
calc_process_cmd (struct calc *c, char cmd)
{
  if (is_flag_on (c, 0x2))
    return 0;
  if (((*__ctype_b_loc ())[(int) ((cmd))] & (unsigned short int) _ISdigit))
    {
      if (!set_flag (c, 0x1, 1))
        {
          c->x = cmd - '0';
          set_flag (c, 0x8, 1);
        }
      else
        c->x = c->x * 10 + (cmd - '0');
    }
  else if (is_operation (cmd))
    {
      if (is_flag_on (c, 0x8))
        eq (c);
      c->y = c->x;
      c->op = cmd;
      set_flag (c, 0x1, 0);
      set_flag (c, 0x10, 0);
    }
  else if (cmd == '=')
    {
      eq (c);
      set_flag (c, 0x1, 0);
    }
  return c->x;
}

canonical_original_code:
int calc_process_cmd(struct calc *c, char cmd)
{
  if (is_flag_on (c, 0x2))
    return 0;
  if (((*__ctype_b_loc ())[(int) ((cmd))] & (unsigned short) _ISdigit))
    {
      if (!set_flag (c, 0x1, 1))
        {
          c->x = cmd - '0';
          set_flag (c, 0x8, 1);
        }
      else
        c->x = c->x * 10 + (cmd - '0');
    }
  else if (is_operation (cmd))
    {
      if (is_flag_on (c, 0x8))
        eq (c);
      c->y = c->x;
      c->op = cmd;
      set_flag (c, 0x1, 0);
      set_flag (c, 0x10, 0);
    }
  else if (cmd == '=')
    {
      eq (c);
      set_flag (c, 0x1, 0);
    }
  return c->x;
}

variable_types: cmd char


decompiled_code:
__int64 __fastcall calc_process_line(int *a1, char *a2)
{
char *v2; // rbx
char v3; // si
__int64 result; // rax

v2 = a2 + 1;
v3 = *a2;
if ( !v3 )
return 0LL;
do
{
++v2;
result = calc_process_cmd(a1, v3);
v3 = *(v2 - 1);
}
while ( v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int *a1, char *a2)
{
char *v2; // rbx
char v3; // si
__int64 result; // rax

v2 = a2 + 1;
v3 = *a2;
if ( !v3 )
return 0LL;
do
{
++v2;
result = func14(a1, v3);
v3 = *(v2 - 1);
}
while ( v3 );
return result;
}

original_code:
int
calc_process_line (struct calc *calc, char *line)
{
  char c;
  int res;
  while ((c = *line++) != '\0')
    res = calc_process_cmd (calc, c);
  return res;
}

canonical_original_code:
int calc_process_line(struct calc *calc, char *line)
{
  char c;
  int res;
  while ((c = *line++) != '\0')
    res = calc_process_cmd (calc, c);
  return res;
}

variable_types:
line
char *

variable_types: res int


repo: bgnori/solverForPuzzleA

decompiled_code:
const char *test_fact_0()
{
const char *result; // rax

result = "test_fact_0";
if ( fact == 1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func0()
{
const char *result; // rax

result = "test_fact_0";
if ( fact == 1 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_fact_0(void)
{
    if (fact[0] != 1)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_0()
{
    if (fact[0] != 1)
        return __func__;
    return ((void *)0);
}

return_type: char *


decompiled_code:
const char *test_fact_1()
{
const char *result; // rax

result = "test_fact_1";
if ( *((_DWORD *)&fact + 1) == 1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func1()
{
const char *result; // rax

result = "test_fact_1";
if ( *((_DWORD *)&fact + 1) == 1 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_fact_1(void)
{
    if (fact[1] != 1)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_1()
{
    if (fact[1] != 1)
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_fact_6()
{
const char *result; // rax

result = "test_fact_6";
if ( fact[6] == 720 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func2()
{
const char *result; // rax

result = "test_fact_6";
if ( fact[6] == 720 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_fact_6(void)
{
    if (fact[6] != 720)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_6()
{
    if (fact[6] != 720)
        return __func__;
    return ((void *)0);
}


dfact

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

for ( result = 1LL; a1; --a1 )
result = (unsigned int)(a1 * result);
return result;
}

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

for ( result = 1LL; a1; --a1 )
result = (unsigned int)(a1 * result);
return result;
}

original_code:
static
int
dfact(int n)
{
    if(n==0)
        return 1;
    return dfact(n-1) * n;
}

variable_types: n int


decompiled_code:
const char *test_fact_x()
{
__int64 v0; // rdx
int v1; // eax
__int64 v2; // rdx

LODWORD(v0) = 0;
while ( 1 )
{
v1 = dfact(v0);
if ( fact[v2] != v1 )
break;
v0 = v2 + 1;
if ( v0 == 11 )
return 0LL;
}
return "test_fact_x";
}

canonical_decompiled_code:
const char *func4()
{
__int64 v0; // rdx
int v1; // eax
__int64 v2; // rdx

LODWORD(v0) = 0;
while ( 1 )
{
v1 = func3(v0);
if ( fact[v2] != v1 )
break;
v0 = v2 + 1;
if ( v0 == 11 )
return 0LL;
}
return "test_fact_x";
}

original_code:
static
const_char_p
test_fact_x(void)
{
    int i;
    for (i=0; i < 11; i++){
        if (fact[i] != dfact(i))
            return __func__;
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_x()
{
    int i;
    for (i=0; i < 11; i++){
        if (fact[i] != dfact(i))
            return __func__;
    }
    return ((void *)0);
}

variable_types: i int


decompiled_code:
const char *test_with_bugs_all()
{
bool v0; // zf
const char *result; // rax
_QWORD v2[18]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpBugTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned int)failed_at(v2, v3) == -1;
result = "test_with_bugs_all";
if ( v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func7()
{
bool v0; // zf
const char *result; // rax
_QWORD v2[18]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

func5(v2);
func6((__int64)v3);
v0 = (unsigned int)failed_at(v2, v3) == -1;
result = "test_with_bugs_all";
if ( v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_all(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(failed_at(tiles, placement) != -1)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_all()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(failed_at(tiles, placement) != -1)
        return __func__;
    return ((void *)0);
}

variable_types:
tiles
struct TTile { int fPattern[4]; } [9]

variable_types: struct TPlacement { int fPermutation[9]; int fRotation[9]; } [9]


decompiled_code:
const char *test_perfhash_max()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash((unsigned int)(fact[9] - 1), v2);
v0 = 0LL;
while ( v2[v0] == 8 - (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_max";
}

canonical_decompiled_code:
const char *func8()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash((unsigned int)(fact[9] - 1), v2);
v0 = 0LL;
while ( v2[v0] == 8 - (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_max";
}

original_code:
static
const_char_p
test_perfhash_max(void)
{
    int buf[9];
    int i;
    perfhash(fact[9] - 1, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != 8 - i){
            return __func__;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_perfhash_max()
{
    int buf[9];
    int i;
    perfhash(fact[9] - 1, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != 8 - i){
            return __func__;
        }
    }
    return ((void *)0);
}

variable_types:
buf
int [9]


decompiled_code:
const char *test_perfhash_0()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash(0LL, v2);
v0 = 0LL;
while ( v2[v0] == (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_0";
}

canonical_decompiled_code:
const char *func9()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash(0LL, v2);
v0 = 0LL;
while ( v2[v0] == (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_0";
}

original_code:
static
const_char_p
test_perfhash_0(void)
{
    int buf[9];
    int i;
    perfhash(0, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != i){
            return __func__;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_perfhash_0()
{
    int buf[9];
    int i;
    perfhash(0, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != i){
            return __func__;
        }
    }
    return ((void *)0);
}


decompiled_code:
const char *test_with_bugs_1_left_step3()
{
int v0; // ebx
bool v1; // zf
const char *result; // rax
_QWORD v3[18]; // [rsp+0h] [rbp-328h] BYREF
char v4[664]; // [rsp+90h] [rbp-298h] BYREF

setUpBugTiles(v3);
setUpTrivialPlacemnet((__int64)v4);
v0 = get_pattern(0LL, v3, v4, 3LL);
v1 = v0 == (unsigned int)get_pattern(1LL, v3, v4, 1LL);
result = "test_with_bugs_1_left_step3";
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func10()
{
int v0; // ebx
bool v1; // zf
const char *result; // rax
_QWORD v3[18]; // [rsp+0h] [rbp-328h] BYREF
char v4[664]; // [rsp+90h] [rbp-298h] BYREF

func5(v3);
func6((__int64)v4);
v0 = get_pattern(0LL, v3, v4, 3LL);
v1 = v0 == (unsigned int)get_pattern(1LL, v3, v4, 1LL);
result = "test_with_bugs_1_left_step3";
if ( v1 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left_step3(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if ((get_pattern(0, tiles, placement, 3) ^ get_pattern(1, tiles, placement, 1) ^ (8+4+2+1)) != (8+4+2+1))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left_step3()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if ((get_pattern(0, tiles, placement, 3) ^ get_pattern(1, tiles, placement, 1) ^ (8+4+2+1)) != (8+4+2+1))
        return __func__;
    return ((void *)0);
}

user_defined_types: struct TPlacement { int fPermutation[9]; int fRotation[9]; }


decompiled_code:
const char *test_with_bugs_1_left_step0()
{
bool v0; // zf
const char *result; // rax

v0 = (unsigned int)idx2h(1LL) == 0;
result = "test_with_bugs_1_left_step0";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func11()
{
bool v0; // zf
const char *result; // rax

v0 = (unsigned int)idx2h(1LL) == 0;
result = "test_with_bugs_1_left_step0";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left_step0(void)
{
    if(idx2h(1) == 0)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left_step0()
{
    if(idx2h(1) == 0)
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_with_bugs_1_left_step2()
{
int v0; // ebx
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v0 = idx2h(1LL);
v1 = idx2v(1LL);
v2 = (unsigned int)hv2idx((unsigned int)(v0 - 1), v1) == 0;
result = "test_with_bugs_1_left_step2";
if ( v2 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func12()
{
int v0; // ebx
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v0 = idx2h(1LL);
v1 = idx2v(1LL);
v2 = (unsigned int)hv2idx((unsigned int)(v0 - 1), v1) == 0;
result = "test_with_bugs_1_left_step2";
if ( v2 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left_step2(void)
{
    int h, v, n, idx;
    idx = 1;
    h = idx2h(idx);
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    if ( n != 0)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left_step2()
{
    int h; int v; int n; int idx;
    idx = 1;
    h = idx2h(idx);
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    if ( n != 0)
        return __func__;
    return ((void *)0);
}

variable_types: h int

variable_types: v int

variable_types: idx int


decompiled_code:
const char *test_with_bugs_1_left()
{
bool v0; // zf
const char *result; // rax
_QWORD v2[18]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpBugTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned __int8)ok_left(1LL, v2, v3) == 0;
result = "test_with_bugs_1_left";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func13()
{
bool v0; // zf
const char *result; // rax
_QWORD v2[18]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

func5(v2);
func6((__int64)v3);
v0 = (unsigned __int8)ok_left(1LL, v2, v3) == 0;
result = "test_with_bugs_1_left";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_left_mismatch_1()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpBadTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned __int8)ok_left(1LL, v2, v3) == 0;
result = "test_ok_left_mismatch_1";
if ( v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func14()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpBadTiles(v2);
func6((__int64)v3);
v0 = (unsigned __int8)ok_left(1LL, v2, v3) == 0;
result = "test_ok_left_mismatch_1";
if ( v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_left_mismatch_1(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_left_mismatch_1()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_left_match_1()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned __int8)ok_left(1LL, v2, v3) == 0;
result = "test_ok_left_match_1";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func15()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
func6((__int64)v3);
v0 = (unsigned __int8)ok_left(1LL, v2, v3) == 0;
result = "test_ok_left_match_1";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_left_match_1(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_left_match_1()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_left_match_0()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned __int8)ok_left(0LL, v2, v3) == 0;
result = "test_ok_left_match_0";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func16()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
func6((__int64)v3);
v0 = (unsigned __int8)ok_left(0LL, v2, v3) == 0;
result = "test_ok_left_match_0";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_left_match_0(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(0, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_left_match_0()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(0, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_up_mismatch_3()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpBadTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned __int8)ok_up(3LL, v2, v3) == 0;
result = "test_ok_up_mismatch_3";
if ( v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func17()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpBadTiles(v2);
func6((__int64)v3);
v0 = (unsigned __int8)ok_up(3LL, v2, v3) == 0;
result = "test_ok_up_mismatch_3";
if ( v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_up_mismatch_3(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_up(3, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_up_mismatch_3()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_up(3, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_up_match_3()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned __int8)ok_up(0LL, v2, v3) == 0;
result = "test_ok_up_match_3";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func18()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
func6((__int64)v3);
v0 = (unsigned __int8)ok_up(0LL, v2, v3) == 0;
result = "test_ok_up_match_3";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_up_match_3(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_up_match_3()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_up_match_0()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
setUpTrivialPlacemnet((__int64)v3);
v0 = (unsigned __int8)ok_up(0LL, v2, v3) == 0;
result = "test_ok_up_match_0";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func19()
{
bool v0; // zf
const char *result; // rax
_DWORD v2[36]; // [rsp+0h] [rbp-328h] BYREF
char v3[664]; // [rsp+90h] [rbp-298h] BYREF

setUpEasyTiles(v2);
func6((__int64)v3);
v0 = (unsigned __int8)ok_up(0LL, v2, v3) == 0;
result = "test_ok_up_match_0";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_up_match_0(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_up_match_0()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_rotate_fail()
{
char v0; // r8
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int128 v4[2]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v4[0] = 0LL;
v5 = 0;
DWORD1(v4[0]) = 3;
v4[1] = 0LL;
v0 = rotate(1LL, v4);
result = "test_rotate_fail";
if ( !v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( i == 1 )
{
if ( DWORD1(v4[0]) != 3 )
return "test_rotate_fail";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_fail";
if ( v2 == 9 )
return 0LL;
}
++v2;
}
}
return result;
}

canonical_decompiled_code:
const char *func20()
{
char v0; // r8
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int128 v4[2]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v4[0] = 0LL;
v5 = 0;
DWORD1(v4[0]) = 3;
v4[1] = 0LL;
v0 = rotate(1LL, v4);
result = "test_rotate_fail";
if ( !v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( i == 1 )
{
if ( DWORD1(v4[0]) != 3 )
return "test_rotate_fail";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_fail";
if ( v2 == 9 )
return 0LL;
}
++v2;
}
}
return result;
}

original_code:
static
const_char_p
test_rotate_fail(void)
{
    int buf[9] = {0,3,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 3){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_rotate_fail()
{
    int buf[9] = {0,3,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 3){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}


decompiled_code:
const char *test_rotate_ok()
{
char v0; // r8
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int128 v4[2]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v5 = 0;
v4[0] = 0LL;
v4[1] = 0LL;
v0 = rotate(1LL, v4);
result = "test_rotate_ok";
if ( v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( i == 1 )
{
if ( DWORD1(v4[0]) != 1 )
return "test_rotate_ok";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_ok";
if ( v2 == 9 )
return 0LL;
}
++v2;
}
}
return result;
}

canonical_decompiled_code:
const char *func21()
{
char v0; // r8
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int128 v4[2]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v5 = 0;
v4[0] = 0LL;
v4[1] = 0LL;
v0 = rotate(1LL, v4);
result = "test_rotate_ok";
if ( v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( i == 1 )
{
if ( DWORD1(v4[0]) != 1 )
return "test_rotate_ok";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_ok";
if ( v2 == 9 )
return 0LL;
}
++v2;
}
}
return result;
}

original_code:
static
const_char_p
test_rotate_ok(void)
{
    int buf[9] = {0,0,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(!ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 1){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_rotate_ok()
{
    int buf[9] = {0,0,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(!ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 1){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}


decompiled_code:
const char *test_rotate_clear()
{
char v0; // r8
const char *result; // rax
char *v2; // rax
_BYTE v3[36]; // [rsp+0h] [rbp-38h] BYREF
char v4; // [rsp+24h] [rbp-14h] BYREF

v0 = rotate(0xFFFFFFFFLL, v3);
result = "test_rotate_clear";
if ( v0 )
{
v2 = v3;
while ( !*(_DWORD *)v2 )
{
v2 += 4;
if ( v2 == &v4 )
return 0LL;
}
result = "test_rotate_clear";
}
return result;
}

canonical_decompiled_code:
const char *func22()
{
char v0; // r8
const char *result; // rax
char *v2; // rax
_BYTE v3[36]; // [rsp+0h] [rbp-38h] BYREF
char v4; // [rsp+24h] [rbp-14h] BYREF

v0 = rotate(0xFFFFFFFFLL, v3);
result = "test_rotate_clear";
if ( v0 )
{
v2 = v3;
while ( !*(_DWORD *)v2 )
{
v2 += 4;
if ( v2 == &v4 )
return 0LL;
}
result = "test_rotate_clear";
}
return result;
}

original_code:
static
const_char_p
test_rotate_clear(void)
{
    int buf[9];
    int i;
    _Bool ret;
    ret = rotate(-1, buf);
    if(!ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (buf[i] != 0){
            return __func__;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_rotate_clear()
{
    int buf[9];
    int i;
    _Bool ret;
    ret = rotate(-1, buf);
    if(!ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (buf[i] != 0){
            return __func__;
        }
    }
    return ((void *)0);
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 (__fastcall **v3)(); // rbx
const char **v4; // rbp

v3 = &cases;
do
{
while ( 1 )
{
v4 = (const char **)((__int64 (__fastcall *)(_QWORD, const char **, const char **))*v3)(
*(_QWORD *)&argc,
argv,
envp);
if ( !v4 )
break;
++v3;
puts("!");
argv = v4;
*(_QWORD *)&argc = "fail, %s\n";
printf("fail, %s\n", (const char *)v4);
if ( v3 == &cases + 20 )
return 0;
}
*(_QWORD *)&argc = 46LL;
++v3;
putchar(46);
}
while ( v3 != &cases + 20 );
return 0;
}

original_code:
int
main(int argc, const char** argv)
{
    int i, len;
    const_char_p msg;
    unittest u;
    len = sizeof(cases)/sizeof(unittest);
    for(i = 0; i < len; i++){
        u = cases[i];
        msg = u();
        if(msg){
            printf("!\n");
            printf("fail, %s\n", msg);
        }else{
            printf(".");
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i; int len;
    char *msg;
    char *(*u)();
    len = sizeof(cases)/sizeof(unittest);
    for(i = 0; i < len; i++){
        u = cases[i];
        msg = u();
        if(msg){
            printf("!\n");
            printf("fail, %s\n", msg);
        }else{
            printf(".");
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: len int

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall idx2h(int a1)
{
return (unsigned int)(a1 % 3);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return (unsigned int)(a1 % 3);
}

original_code:
int
idx2h(int idx)
{
    return idx % 3;
}

canonical_original_code:
int idx2h(int idx)
{
    return idx % 3;
}


decompiled_code:
__int64 __fastcall idx2v(int a1)
{
return (unsigned int)(a1 / 3);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return (unsigned int)(a1 / 3);
}

original_code:
int
idx2v(int idx)
{
    return idx / 3;
}

canonical_original_code:
int idx2v(int idx)
{
    return idx / 3;
}


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

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

original_code:
int
hv2idx(int h, int v)
{
    return h + v*3;
}


perfhash

original_code:
void
perfhash(int n, int* buf)
{
    int i;
    int nth;
    int availables[10] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    int found;
    for(i = 0; i < 9; i++){
        nth = n / fact[8 - i];
        found = -1;
        while(nth > -1){
            found++;
            if(availables[found]){
                nth--;
            }
        }
        availables[found] = 0;
        buf[i] = found - 1;
        n = n % fact[8-i];
    }
}

canonical_original_code:
void perfhash(int n, int *buf)
{
    int i;
    int nth;
    int availables[10] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    int found;
    for(i = 0; i < 9; i++){
        nth = n / fact[8 - i];
        found = -1;
        while(nth > -1){
            found++;
            if(availables[found]){
                nth--;
            }
        }
        availables[found] = 0;
        buf[i] = found - 1;
        n = n % fact[8-i];
    }
}

variable_types:
buf
int *

variable_types: nth int

variable_types:
availables
int [10]

variable_types: found int


rotate

decompiled_code:
__int64 __fastcall rotate(int a1, __int64 a2)
{
unsigned int v2; // er8
int *v3; // rdx
__int64 result; // rax

if ( a1 == -1 )
{
*(_DWORD *)(a2 + 32) = 0;
*(_OWORD *)a2 = 0LL;
result = 1LL;
*(_OWORD *)(a2 + 16) = 0LL;
}
else
{
v2 = 0;
v3 = (int *)(a2 + 4LL * a1);
if ( *v3 <= 2 )
{
v2 = 1;
++*v3;
}
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
unsigned int v2; // er8
int *v3; // rdx
__int64 result; // rax

if ( a1 == -1 )
{
*(_DWORD *)(a2 + 32) = 0;
*(_OWORD *)a2 = 0LL;
result = 1LL;
*(_OWORD *)(a2 + 16) = 0LL;
}
else
{
v2 = 0;
v3 = (int *)(a2 + 4LL * a1);
if ( *v3 <= 2 )
{
v2 = 1;
++*v3;
}
result = v2;
}
return result;
}

original_code:
_Bool
rotate(int idx, int* buf)
{
    int i;
    if(idx == -1){
        for(i=0;i<9;i++){
            buf[i] = 0;
        }
        return 1;
    }
    if(buf[idx] >= 3){
        return 0;
    }
    buf[idx] ++;
    return 1;
}

canonical_original_code:
_Bool rotate(int idx, int *buf)
{
    int i;
    if(idx == -1){
        for(i=0;i<9;i++){
            buf[i] = 0;
        }
        return 1;
    }
    if(buf[idx] >= 3){
        return 0;
    }
    buf[idx] ++;
    return 1;
}


decompiled_code:
__int64 __fastcall get_pattern(int a1, __int64 a2, __int64 a3, int a4)
{
return *(unsigned int *)(16LL * *(int *)(a3 + 4LL * a1) + a2 + 4LL * a4);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2, __int64 a3, int a4)
{
return *(unsigned int *)(16LL * *(int *)(a3 + 4LL * a1) + a2 + 4LL * a4);
}

original_code:
int
get_pattern(int idx, TTile* tiles, TPlacement* p, int direction)
{
    return (tiles[p->fPermutation[idx]]).fPattern[direction];
}

canonical_original_code:
int get_pattern(int idx, struct TTile *tiles, struct TPlacement *p, int direction)
{
    return (tiles[p->fPermutation[idx]]).fPattern[direction];
}

variable_types:
tiles
struct TTile { int fPattern[4]; } *

variable_types: struct TPlacement { int fPermutation[9]; int fRotation[9]; } *

variable_types: direction int


decompiled_code:
bool __fastcall ok_up(int a1, __int64 a2, __int64 a3)
{
int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // eax

if ( a1 <= 2 )
return 1;
v5 = idx2h();
v6 = idx2v((unsigned int)a1);
v7 = hv2idx((unsigned int)(v5 - 1), v6);
LOBYTE(v5) = get_pattern(v7, a2, a3, 2LL);
return (~((unsigned __int8)get_pattern((unsigned int)a1, a2, a3, 0LL) ^ (unsigned __int8)v5) & 0xF) != 0;
}

canonical_decompiled_code:
bool __fastcall func10(int a1, __int64 a2, __int64 a3)
{
int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // eax

if ( a1 <= 2 )
return 1;
v5 = func4();
v6 = func5((unsigned int)a1);
v7 = func6((unsigned int)(v5 - 1), v6);
LOBYTE(v5) = func9(v7, a2, a3, 2LL);
return (~((unsigned __int8)func9((unsigned int)a1, a2, a3, 0LL) ^ (unsigned __int8)v5) & 0xF) != 0;
}

original_code:
_Bool
ok_up(int idx, TTile* tiles, TPlacement* p)
{
    int h, v;
    int n;
    if(idx < 3)
        return 1;
    h = idx2h(idx);
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    return ((get_pattern(n, tiles, p, 2) ^ get_pattern(idx, tiles, p, 0) ^ (8+4+2+1)) & (8+4+2+1));
}

canonical_original_code:
_Bool ok_up(int idx, struct TTile *tiles, struct TPlacement *p)
{
    int h; int v;
    int n;
    if(idx < 3)
        return 1;
    h = idx2h(idx);
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    return ((get_pattern(n, tiles, p, 2) ^ get_pattern(idx, tiles, p, 0) ^ (8+4+2+1)) & (8+4+2+1));
}

variable_types: n int


decompiled_code:
bool __fastcall ok_left(unsigned int a1, __int64 a2, __int64 a3)
{
int v4; // ebx
bool result; // al
unsigned int v6; // eax
unsigned int v7; // eax
unsigned __int8 v8; // bl

v4 = idx2h();
result = 1;
if ( v4 )
{
v6 = idx2v(a1);
v7 = hv2idx((unsigned int)(v4 - 1), v6);
v8 = get_pattern(v7, a2, a3, 3LL);
result = (~((unsigned __int8)get_pattern(a1, a2, a3, 1LL) ^ v8) & 0xF) != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func11(unsigned int a1, __int64 a2, __int64 a3)
{
int v4; // ebx
bool result; // al
unsigned int v6; // eax
unsigned int v7; // eax
unsigned __int8 v8; // bl

v4 = func4();
result = 1;
if ( v4 )
{
v6 = func5(a1);
v7 = func6((unsigned int)(v4 - 1), v6);
v8 = func9(v7, a2, a3, 3LL);
result = (~((unsigned __int8)func9(a1, a2, a3, 1LL) ^ v8) & 0xF) != 0;
}
return result;
}

original_code:
_Bool
ok_left(int idx, TTile* tiles, TPlacement* p)
{
    int h, v;
    int n;
    h = idx2h(idx);
    if (h == 0)
        return 1;
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    return ((get_pattern(n, tiles, p, 3) ^ get_pattern(idx, tiles, p, 1) ^ (8+4+2+1)) & (8+4+2+1));
}

canonical_original_code:
_Bool ok_left(int idx, struct TTile *tiles, struct TPlacement *p)
{
    int h; int v;
    int n;
    h = idx2h(idx);
    if (h == 0)
        return 1;
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    return ((get_pattern(n, tiles, p, 3) ^ get_pattern(idx, tiles, p, 1) ^ (8+4+2+1)) & (8+4+2+1));
}


decompiled_code:
__int64 __fastcall failed_at(__int64 a1, __int64 a2)
{
unsigned int v2; // er12

v2 = 0;
while ( (unsigned __int8)ok_up(v2, a1, a2) && (unsigned __int8)ok_left(v2, a1, a2) )
{
if ( ++v2 == 9 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
unsigned int v2; // er12

v2 = 0;
while ( (unsigned __int8)func10(v2, a1, a2) && (unsigned __int8)func11(v2, a1, a2) )
{
if ( ++v2 == 9 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int
failed_at(TTile* tiles, TPlacement* p)
{
    int idx;
    for (idx=0; idx < 9; idx++){
        if(!ok_up(idx, tiles, p) ||
           !ok_left(idx, tiles, p)){
            return idx;
        }
    }
    return -1;
}

canonical_original_code:
int failed_at(struct TTile *tiles, struct TPlacement *p)
{
    int idx;
    for (idx=0; idx < 9; idx++){
        if(!ok_up(idx, tiles, p) ||
           !ok_left(idx, tiles, p)){
            return idx;
        }
    }
    return -1;
}


solve

decompiled_code:
__int64 __fastcall solve(__int64 a1, __int64 a2, unsigned int *a3, int a4)
{
unsigned int v5; // er13
__int64 v7; // rdi
int v8; // eax
unsigned int v9; // er15

v5 = *a3;
if ( (int)*a3 < a4 )
{
while ( 2 )
{
perfhash(v5, a2);
v7 = 0xFFFFFFFFLL;
while ( 1 )
{
v9 = rotate(v7, a2 + 36);
if ( !(_BYTE)v9 )
break;
v8 = failed_at(a1, a2);
v7 = (unsigned int)v8;
if ( v8 < 0 )
{
*a3 = v5;
return v9;
}
}
if ( a4 != ++v5 )
continue;
break;
}
}
*a3 = v5;
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, unsigned int *a3, int a4)
{
unsigned int v5; // er13
__int64 v7; // rdi
int v8; // eax
unsigned int v9; // er15

v5 = *a3;
if ( (int)*a3 < a4 )
{
while ( 2 )
{
func7(v5, a2);
v7 = 0xFFFFFFFFLL;
while ( 1 )
{
v9 = func8(v7, a2 + 36);
if ( !(_BYTE)v9 )
break;
v8 = func12(a1, a2);
v7 = (unsigned int)v8;
if ( v8 < 0 )
{
*a3 = v5;
return v9;
}
}
if ( a4 != ++v5 )
continue;
break;
}
}
*a3 = v5;
return 0;
}

original_code:
_Bool
solve(TTile* tiles, TPlacement* p, int* start, int end)
{
    int i;
    int at;
    for(i = *start; i < end; i++){
        perfhash(i, p->fPermutation);
        at = -1;
        while(rotate(at, p->fRotation)){
            at = failed_at(tiles, p);
            if (at < 0){
                *start = i;
                return 1;
            }
        }
    }
    *start = i;
    return 0;
}

canonical_original_code:
_Bool solve(struct TTile *tiles, struct TPlacement *p, int *start, int end)
{
    int i;
    int at;
    for(i = *start; i < end; i++){
        perfhash(i, p->fPermutation);
        at = -1;
        while(rotate(at, p->fRotation)){
            at = failed_at(tiles, p);
            if (at < 0){
                *start = i;
                return 1;
            }
        }
    }
    *start = i;
    return 0;
}

variable_types:
start
int *

variable_types: end int

variable_types: i int

variable_types: at int


repo: bharanis/algorithms

original_code:
int min_delete (int *heap)
{
   int pos = 1;
   int selected;
   int retval = heap[1];
   int temp;
   ((heap)[0]) --;
   heap[1] = heap[((heap)[0])];
   while (((pos)*2) < ((heap)[0])) {
     selected = pos;
     if (heap[((pos)*2)] < heap[selected]) {
        selected = ((pos)*2);
     }
     if (heap[((pos)*2 + 1)] < heap[selected]) {
        selected = ((pos)*2 + 1);
     }
     if (selected != pos) {
        temp = heap[pos];
        heap[pos] = heap[selected];
        heap[selected] = temp;
        pos = selected;
     }
     else
        break;
   }
   return retval;
}

canonical_original_code:
int min_delete(int *heap)
{
   int pos = 1;
   int selected;
   int retval = heap[1];
   int temp;
   ((heap)[0]) --;
   heap[1] = heap[((heap)[0])];
   while (((pos)*2) < ((heap)[0])) {
     selected = pos;
     if (heap[((pos)*2)] < heap[selected]) {
        selected = ((pos)*2);
     }
     if (heap[((pos)*2 + 1)] < heap[selected]) {
        selected = ((pos)*2 + 1);
     }
     if (selected != pos) {
        temp = heap[pos];
        heap[pos] = heap[selected];
        heap[selected] = temp;
        pos = selected;
     }
     else
        break;
   }
   return retval;
}

variable_types:
heap
int *

variable_types: pos int

variable_types: selected int

variable_types: retval int

variable_types: temp int


original_code:
int max_delete (int *heap)
{
   int pos = 1;
   int selected;
   int retval = heap[1];
   int temp;
   ((heap)[0]) --;
   heap[1] = heap[((heap)[0])];
   while (((pos)*2) < ((heap)[0])) {
     selected = pos;
     if (heap[((pos)*2)] > heap[selected]) {
        selected = ((pos)*2);
     }
     if (heap[((pos)*2 + 1)] > heap[selected]) {
        selected = ((pos)*2 + 1);
     }
     if (selected != pos) {
        temp = heap[pos];
        heap[pos] = heap[selected];
        heap[selected] = temp;
        pos = selected;
     }
     else
        break;
   }
   return retval;
}

canonical_original_code:
int max_delete(int *heap)
{
   int pos = 1;
   int selected;
   int retval = heap[1];
   int temp;
   ((heap)[0]) --;
   heap[1] = heap[((heap)[0])];
   while (((pos)*2) < ((heap)[0])) {
     selected = pos;
     if (heap[((pos)*2)] > heap[selected]) {
        selected = ((pos)*2);
     }
     if (heap[((pos)*2 + 1)] > heap[selected]) {
        selected = ((pos)*2 + 1);
     }
     if (selected != pos) {
        temp = heap[pos];
        heap[pos] = heap[selected];
        heap[selected] = temp;
        pos = selected;
     }
     else
        break;
   }
   return retval;
}


decompiled_code:
__int64 __fastcall populate_array(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // er12

v2 = a1;
v3 = random() % (a2 + a2 / -10) + a2 / 10;
if ( v3 > 0 )
{
do
{
v2 += 4LL;
*(_DWORD *)(v2 - 4) = random() % (10 * v3);
}
while ( v2 != a1 + 4LL * (unsigned int)(v3 - 1) + 4 );
}
return (unsigned int)v3;
}

original_code:
int populate_array (int *arr, int size)
{
   int i;
   size = (random() % (size-size/10)) + size/10;
   for (i = 0; i < size; i ++) {
      arr[i] = random() % (size*10);
   }
   return size;
}

canonical_original_code:
int populate_array(int *arr, int size)
{
   int i;
   size = (random() % (size-size/10)) + size/10;
   for (i = 0; i < size; i ++) {
      arr[i] = random() % (size*10);
   }
   return size;
}

variable_types:
arr
int *

variable_types: size int


decompiled_code:
int __fastcall print_array(const char *a1, unsigned int *a2, int a3)
{
unsigned int *v4; // rbx
int result; // eax
__int64 v6; // rbp
__int64 v7; // rsi

v4 = a2;
result = printf("%s", a1);
if ( a3 > 0 )
{
v6 = (__int64)&a2[a3 - 1 + 1];
do
{
v7 = *v4++;
result = printf("%d ", v7);
}
while ( v4 != (unsigned int *)v6 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, unsigned int *a2, int a3)
{
unsigned int *v4; // rbx
int result; // eax
__int64 v6; // rbp
__int64 v7; // rsi

v4 = a2;
result = printf("%s", a1);
if ( a3 > 0 )
{
v6 = (__int64)&a2[a3 - 1 + 1];
do
{
v7 = *v4++;
result = printf("%d ", v7);
}
while ( v4 != (unsigned int *)v6 );
}
return result;
}

original_code:
void print_array(char *header, int *a, int s)
{
  int i;
  printf("%s", header);
  for (i = 0; i < s; i++)
     printf("%d ", a[i]);
}

variable_types:
header
char *

variable_types:
a
int *

variable_types: s int


insert

decompiled_code:
__int64 __fastcall insert(__int64 a1, __int64 a2)
{
int v2; // eax
int *v3; // rcx
int v4; // edx

v2 = 1;
while ( 1 )
{
while ( 1 )
{
v3 = (int *)(a1 + 4LL * v2);
v4 = *v3;
if ( *v3 == -1 )
{
*v3 = a2;
return 0LL;
}
if ( v4 <= (int)a2 )
break;
v2 *= 2;
if ( v2 > 1024 )
return 0xFFFFFFFFLL;
}
if ( v4 >= (int)a2 )
break;
v2 = 2 * v2 + 1;
if ( v2 > 1024 )
return 0xFFFFFFFFLL;
}
printf("insert %d duplicate\n", a2);
return 0LL;
}

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

v2 = 1;
while ( 1 )
{
while ( 1 )
{
v3 = (int *)(a1 + 4LL * v2);
v4 = *v3;
if ( *v3 == -1 )
{
*v3 = a2;
return 0LL;
}
if ( v4 <= (int)a2 )
break;
v2 *= 2;
if ( v2 > 1024 )
return 0xFFFFFFFFLL;
}
if ( v4 >= (int)a2 )
break;
v2 = 2 * v2 + 1;
if ( v2 > 1024 )
return 0xFFFFFFFFLL;
}
printf("insert %d duplicate\n", a2);
return 0LL;
}

original_code:
int insert (int *array, int key)
{
   int root = 1;
   while (array[root] != -1) {
     if (array[root] > key) {
        root = ((root)*2);
     } else if (array[root] < key) {
        root = ((root)*2 + 1);
     } else {
       printf ("insert %d duplicate\n", key);
       return 0;
     }
     if(root > (1<<10)) return -1;;
   }
   array[root] = key;
   return 0;
}

canonical_original_code:
int insert(int *array, int key)
{
   int root = 1;
   while (array[root] != -1) {
     if (array[root] > key) {
        root = ((root)*2);
     } else if (array[root] < key) {
        root = ((root)*2 + 1);
     } else {
       printf ("insert %d duplicate\n", key);
       return 0;
     }
     if(root > (1<<10)) return -1;;
   }
   array[root] = key;
   return 0;
}

variable_types:
array
int *

variable_types: key int

variable_types: root int


bfs

original_code:
void bfs (bnode *root, void (*fn) (bnode *, void *ctx), void *ctx)
{
   int c = count(root);
   bnode **q = malloc (sizeof (bnode *) * c );
   int qidx = 0, pidx = 0, i;
   q[qidx++] = root;
   while (pidx < c) {
     if (((void *)0) != q[pidx]->left) {
       q[qidx++] = q[pidx]->left;
     }
     if (((void *)0) != q[pidx]->right) {
       q[qidx++] = q[pidx]->right;
     }
     pidx ++;
   }
   for (i=0; i<c; i++)
      fn(q[i], ctx);
   free(q);
}

canonical_original_code:
void bfs(struct node *root, void (*fn)(struct node *, void *ctx), void *ctx)
{
   int c = count(root);
   struct node **q = malloc (sizeof (bnode *) * c );
   int qidx = 0; int pidx = 0; int i;
   q[qidx++] = root;
   while (pidx < c) {
     if (((void *)0) != q[pidx]->left) {
       q[qidx++] = q[pidx]->left;
     }
     if (((void *)0) != q[pidx]->right) {
       q[qidx++] = q[pidx]->right;
     }
     pidx ++;
   }
   for (i=0; i<c; i++)
      fn(q[i], ctx);
   free(q);
}

variable_types:
fn
void (*)(struct node *, void *ctx)

variable_types:
ctx
void *

variable_types: c int

variable_types: struct node { struct node *left; struct node *right; int key; int x; int y; int modifier; int height; } **

variable_types: qidx int

variable_types: pidx int


inorder

decompiled_code:
__int64 __fastcall inorder(__int64 a1, int a2, void (__fastcall *a3)(__int64, __int64))
{
int v4; // ebp
__int64 v5; // rsi

if ( a2 > 1024 )
return 0LL;
v4 = a2;
do
{
if ( *(_DWORD *)(a1 + 4LL * v4) == -1 )
break;
inorder(a1, (unsigned int)(2 * v4), a3);
v5 = (unsigned int)v4;
v4 = 2 * v4 + 1;
a3(a1, v5);
}
while ( v4 <= 1024 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int a2, void (__fastcall *a3)(__int64, __int64))
{
int v4; // ebp
__int64 v5; // rsi

if ( a2 > 1024 )
return 0LL;
v4 = a2;
do
{
if ( *(_DWORD *)(a1 + 4LL * v4) == -1 )
break;
func17(a1, (unsigned int)(2 * v4), a3);
v5 = (unsigned int)v4;
v4 = 2 * v4 + 1;
a3(a1, v5);
}
while ( v4 <= 1024 );
return 0LL;
}

original_code:
void inorder(bnode *root, void (*fn) (bnode*, void*), void *ctx)
{
    if (!root) return;
    inorder(root->left, fn, ctx);
    fn(root, ctx);
    inorder(root->right, fn, ctx);
}

canonical_original_code:
void inorder(struct node *root, void (*fn)(struct node *, void *), void *ctx)
{
    if (!root) return;
    inorder(root->left, fn, ctx);
    fn(root, ctx);
    inorder(root->right, fn, ctx);
}

variable_types: struct node { struct node *left; struct node *right; int key; int x; int y; int modifier; int height; } *

variable_types:
fn
void (*)(struct node *, void *)


postorder

decompiled_code:
__int64 __fastcall postorder(__int64 a1, int a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
if ( a2 > 1024 )
return 0LL;
if ( *(_DWORD *)(a1 + 4LL * a2) == -1 )
return 0LL;
postorder(a1, (unsigned int)(2 * a2));
postorder(a1, (unsigned int)(2 * a2 + 1));
return a3(a1, (unsigned int)a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, int a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
if ( a2 > 1024 )
return 0LL;
if ( *(_DWORD *)(a1 + 4LL * a2) == -1 )
return 0LL;
func18(a1, (unsigned int)(2 * a2));
func18(a1, (unsigned int)(2 * a2 + 1));
return a3(a1, (unsigned int)a2);
}

original_code:
void postorder(bnode *root, void (*fn) (bnode*, void*), void *ctx)
{
    if (!root) return;
    postorder(root->left, fn, ctx);
    postorder(root->right, fn, ctx);
    fn(root, ctx);
}

canonical_original_code:
void postorder(struct node *root, void (*fn)(struct node *, void *), void *ctx)
{
    if (!root) return;
    postorder(root->left, fn, ctx);
    postorder(root->right, fn, ctx);
    fn(root, ctx);
}

user_defined_types: struct node { struct node *left; struct node *right; int key; int x; int y; int modifier; int height; }


preorder

decompiled_code:
__int64 __fastcall preorder(__int64 a1, int a2, void (__fastcall *a3)(__int64, __int64))
{
int v4; // ebx
__int64 v5; // rsi
unsigned int v6; // ebx

if ( a2 > 1024 )
return 0LL;
v4 = a2;
do
{
if ( *(_DWORD *)(a1 + 4LL * v4) == -1 )
break;
v5 = (unsigned int)v4;
v6 = 2 * v4;
a3(a1, v5);
preorder(a1, v6, a3);
v4 = v6 + 1;
}
while ( v4 <= 1024 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, int a2, void (__fastcall *a3)(__int64, __int64))
{
int v4; // ebx
__int64 v5; // rsi
unsigned int v6; // ebx

if ( a2 > 1024 )
return 0LL;
v4 = a2;
do
{
if ( *(_DWORD *)(a1 + 4LL * v4) == -1 )
break;
v5 = (unsigned int)v4;
v6 = 2 * v4;
a3(a1, v5);
func19(a1, v6, a3);
v4 = v6 + 1;
}
while ( v4 <= 1024 );
return 0LL;
}

original_code:
void preorder(bnode *root, void (*fn) (bnode*, void*), void *ctx)
{
    if (!root) return;
    fn(root, ctx);
    preorder(root->left, fn, ctx);
    preorder(root->right, fn, ctx);
}

canonical_original_code:
void preorder(struct node *root, void (*fn)(struct node *, void *), void *ctx)
{
    if (!root) return;
    fn(root, ctx);
    preorder(root->left, fn, ctx);
    preorder(root->right, fn, ctx);
}


decompiled_code:
__int64 __fastcall print_tree(__int64 a1)
{
printf("inorder: ");
return inorder(a1, 1, (void (__fastcall *)(__int64, __int64))printnode);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
printf("inorder: ");
return func17(a1, 1, (void (__fastcall *)(__int64, __int64))printnode);
}

original_code:
void print_tree(bnode *root)
{
   print_ws(root);
   printf ("\n");
}

canonical_original_code:
void print_tree(struct node *root)
{
   print_ws(root);
   printf ("\n");
}


largest

decompiled_code:
__int64 __fastcall largest(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax

result = (unsigned int)a2;
if ( 2 * a2 <= 1023 )
{
do
{
v3 = 2 * a2;
if ( *(_DWORD *)(a1 + 8LL * a2 + 4) == -1 )
return (unsigned int)a2;
a2 = v3 + 1;
}
while ( v3 + 1 <= 1024 );
result = (unsigned int)(a2 >> 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax

result = (unsigned int)a2;
if ( 2 * a2 <= 1023 )
{
do
{
v3 = 2 * a2;
if ( *(_DWORD *)(a1 + 8LL * a2 + 4) == -1 )
return (unsigned int)a2;
a2 = v3 + 1;
}
while ( v3 + 1 <= 1024 );
result = (unsigned int)(a2 >> 1);
}
return result;
}

original_code:
int largest(int *array, int root)
{
   if(((root)*2 + 1) > (1<<10)) return root;;
   while (array[((root)*2 + 1)] != -1) {
     root = ((root)*2 + 1);
     if(root > (1<<10)) return ((int)(root)/2);;
   }
   return (root);
}


swap

decompiled_code:
int *__fastcall swap(__int64 a1, int a2, int a3)
{
int *v3; // rcx
int *result; // rax
int v5; // esi

v3 = (int *)(a1 + 4LL * a2);
result = (int *)(a1 + 4LL * a3);
v5 = *v3;
*v3 = *result;
*result = v5;
return result;
}

canonical_decompiled_code:
int *__fastcall func7(__int64 a1, int a2, int a3)
{
int *v3; // rcx
int *result; // rax
int v5; // esi

v3 = (int *)(a1 + 4LL * a2);
result = (int *)(a1 + 4LL * a3);
v5 = *v3;
*v3 = *result;
*result = v5;
return result;
}

original_code:
void swap(int *arr, int i, int j)
{
  int t = arr[i];
  arr[i] = arr[j];
  arr[j] = t;
}

variable_types: i int

variable_types: j int

variable_types: t int


partition

original_code:
int partition (int *arr, int left, int right, int pivotidx)
{
   int pivot = arr[pivotidx];
   int storeidx = left;
   int i;
   swap (arr, pivotidx, right);
   for (i = left; i <= right-1; i++) {
      if (arr[i] < pivot) {
        swap(arr, i, storeidx);
        storeidx ++;
      }
   }
   swap (arr, right, storeidx);
   return storeidx;
}

canonical_original_code:
int partition(int *arr, int left, int right, int pivotidx)
{
   int pivot = arr[pivotidx];
   int storeidx = left;
   int i;
   swap (arr, pivotidx, right);
   for (i = left; i <= right-1; i++) {
      if (arr[i] < pivot) {
        swap(arr, i, storeidx);
        storeidx ++;
      }
   }
   swap (arr, right, storeidx);
   return storeidx;
}

variable_types:
arr
int *

variable_types: left int

variable_types: right int

variable_types: pivotidx int

variable_types: pivot int

variable_types: storeidx int


decompiled_code:
int __fastcall print_array(const char *a1, unsigned int *a2, int a3)
{
unsigned int *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi

v4 = a2;
puts(a1);
if ( a3 > 0 )
{
v5 = (__int64)&a2[a3 - 1 + 1];
do
{
v6 = *v4++;
printf("%d ", v6);
}
while ( v4 != (unsigned int *)v5 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, unsigned int *a2, int a3)
{
unsigned int *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi

v4 = a2;
puts(a1);
if ( a3 > 0 )
{
v5 = (__int64)&a2[a3 - 1 + 1];
do
{
v6 = *v4++;
printf("%d ", v6);
}
while ( v4 != (unsigned int *)v5 );
}
return putchar(10);
}

original_code:
void print_array(char *header, int *a, int s)
{
  int i;
  printf("%s\n", header);
  for (i = 0; i < s; i++)
     printf("%d ", a[i]);
  printf("\n");
}

variable_types:
header
char *

variable_types:
a
int *

variable_types: s int


decompiled_code:
void *__fastcall copy_data_one_direction(void *a1)
{
char *v1; // rbp
int v2; // eax
int v3; // er12
FILE *v4; // rcx

v1 = (char *)a1 + 12;
do
{
v2 = read(*(_DWORD *)a1, v1, 0x2000uLL);
v3 = v2;
if ( v2 <= 0 )
{
shutdown(*((_DWORD *)a1 + 1), 1);
if ( v3 )
{
perror("read");
v4 = stderr;
if ( !*(_DWORD *)a1 )
goto LABEL_6;
}
else
{
v4 = stderr;
if ( !*(_DWORD *)a1 )
{
LABEL_6:
fwrite("[sent EOF]\n", 1uLL, 0xBuLL, v4);
return 0LL;
}
}
fwrite("[received EOF]\n", 1uLL, 0xFuLL, v4);
return 0LL;
}
}
while ( write(*((_DWORD *)a1 + 1), v1, v2) >= 0 );
*((_DWORD *)a1 + 2) = 1;
perror("write");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
char *v1; // rbp
int v2; // eax
int v3; // er12
FILE *v4; // rcx

v1 = (char *)a1 + 12;
do
{
v2 = read(*(_DWORD *)a1, v1, 0x2000uLL);
v3 = v2;
if ( v2 <= 0 )
{
shutdown(*((_DWORD *)a1 + 1), 1);
if ( v3 )
{
perror("read");
v4 = stderr;
if ( !*(_DWORD *)a1 )
goto LABEL_6;
}
else
{
v4 = stderr;
if ( !*(_DWORD *)a1 )
{
LABEL_6:
fwrite("[sent EOF]\n", 1uLL, 0xBuLL, v4);
return 0LL;
}
}
fwrite("[received EOF]\n", 1uLL, 0xFuLL, v4);
return 0LL;
}
}
while ( write(*((_DWORD *)a1 + 1), v1, v2) >= 0 );
*((_DWORD *)a1 + 2) = 1;
perror("write");
return 0LL;
}

original_code:
void *
copy_data_one_direction (void *_st)
{
  struct copy_state *st = _st;
  int n;
  while ((n = read (st->in, st->buf, sizeof (st->buf))) > 0)
    if (write (st->out, st->buf, n) < 0) {
      st->error = 1;
      perror ("write");
      return ((void *)0);
    }
  shutdown (st->out, SHUT_WR);
  if (n < 0)
    perror ("read");
  if (st->in)
    fprintf (stderr, "[received EOF]\n");
  else
    fprintf (stderr, "[sent EOF]\n");
  return ((void *)0);
}

canonical_original_code:
void *copy_data_one_direction(void *_st)
{
  struct copy_state *st = _st;
  int n;
  while ((n = read (st->in, st->buf, sizeof (st->buf))) > 0)
    if (write (st->out, st->buf, n) < 0) {
      st->error = 1;
      perror ("write");
      return ((void *)0);
    }
  shutdown (st->out, SHUT_WR);
  if (n < 0)
    perror ("read");
  if (st->in)
    fprintf (stderr, "[received EOF]\n");
  else
    fprintf (stderr, "[sent EOF]\n");
  return ((void *)0);
}

variable_types: struct copy_state { int in; int out; int error; char buf[8192]; } *

variable_types: n int


sock

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

result = socket(a1, 1, 0);
if ( result < 0 )
{
perror("socket");
exit(1);
}
return result;
}

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

result = socket(a1, 1, 0);
if ( result < 0 )
{
perror("socket");
exit(1);
}
return result;
}

original_code:
static int
sock (int family)
{
  int s = socket (family, SOCK_STREAM, 0);
  if (s < 0) {
    perror ("socket");
    exit (1);
  }
  return s;
}

canonical_original_code:
static int sock(int family)
{
  int s = socket (family, SOCK_STREAM, 0);
  if (s < 0) {
    perror ("socket");
    exit (1);
  }
  return s;
}

variable_types: family int