isnumeric

decompiled_code:
__int64 __fastcall isnumeric(char *a1)
{
__int64 v2; // rbx

do
{
v2 = *a1;
if ( !(_BYTE)v2 )
return 1LL;
++a1;
}
while ( ((*_ctype_b_loc())[v2] & 0x800) != 0 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
__int64 v2; // rbx

do
{
v2 = *a1;
if ( !(_BYTE)v2 )
return 1LL;
++a1;
}
while ( ((*_ctype_b_loc())[v2] & 0x800) != 0 );
return 0LL;
}

original_code:
int isnumeric(const char *str) {
 while(*str)
  if(!((*__ctype_b_loc ())[(int) ((*(str++)))] & (unsigned short int) _ISdigit))
   return 0;
 return 1;
}

canonical_original_code:
int isnumeric(char *str) {
 while(*str)
  if(!((*__ctype_b_loc ())[(int) ((*(str++)))] & (unsigned short) _ISdigit))
   return 0;
 return 1;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall remove_infrequent_items(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax
void *v5; // r13
__int64 v6; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
v5 = (void *)list_iterator(a1, 0LL);
while ( list_next(v5) )
{
if ( (float)a2 > (float)((float)((float)*(int *)(list_current(v5) + 8) / (float)a3) * 100.0) )
{
v6 = list_current(v5);
list_remove(a1, v6);
}
}
free(v5);
result = *a1 != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax
void *v5; // r13
__int64 v6; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
v5 = (void *)list_iterator(a1, 0LL);
while ( list_next(v5) )
{
if ( (float)a2 > (float)((float)((float)*(int *)(list_current(v5) + 8) / (float)a3) * 100.0) )
{
v6 = list_current(v5);
list_remove(a1, v6);
}
}
free(v5);
result = *a1 != 0;
}
return result;
}

original_code:
int remove_infrequent_items(list_p items, int min_sup, int tr_cnt) {
 if(!items->length)
  return 0;
 float sup;
 int cur_sup_cnt;
 set_p cur;
 list_iter_p iter = list_iterator(items, 0);
 while(list_next(iter)) {
  cur = (set_p)list_current(iter);
  cur_sup_cnt = cur->sup_cnt;
  sup = ((float)cur_sup_cnt / (float)tr_cnt) * 100;
  if(sup < min_sup) {
   list_remove(items, (void*)list_current(iter));
  }
 }
 free(iter);
 if(!items->length)
  return 0;
 return 1;
}

canonical_original_code:
int remove_infrequent_items(struct list *items, int min_sup, int tr_cnt) {
 if(!items->length)
  return 0;
 float sup;
 int cur_sup_cnt;
 struct set *cur;
 struct list_iter *iter = list_iterator(items, 0);
 while(list_next(iter)) {
  cur = (struct set *)list_current(iter);
  cur_sup_cnt = cur->sup_cnt;
  sup = ((float)cur_sup_cnt / (float)tr_cnt) * 100;
  if(sup < min_sup) {
   list_remove(items, (void *)list_current(iter));
  }
 }
 free(iter);
 if(!items->length)
  return 0;
 return 1;
}

variable_types: struct list { int length; struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *first; struct linked_node *last; void (*destructor)(void *); } *

variable_types: sup float

variable_types: struct set { char *item; int sup_cnt; } *

variable_types: struct list_iter { struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *current; char started; } *

return_type: int

user_defined_types: struct list { int length; struct linked_node *first; struct linked_node *last; void (*destructor)(void *); }

user_defined_types: struct list_iter { struct linked_node *current; char started; }


decompiled_code:
_BOOL8 __fastcall find_frequent_items(int *a1, _DWORD *a2, int a3)
{
__int64 v3; // r15
void *i; // rdi
void *v5; // rax
char *v6; // rax
char *v7; // r14
char *j; // r12
void *v9; // rbp
const char **v10; // rax
const char **v11; // rbx
_DWORD *v12; // rbp

v3 = list_iterator(a1, 0LL);
for ( i = (void *)v3; list_next(v3); i = (void *)v3 )
{
v5 = (void *)list_current(i);
v6 = (char *)my_strdup(v5);
v7 = v6;
if ( !v6 )
{
perror("malloc");
exit(1);
}
for ( j = strtok(v6, " .,:;"); j; j = strtok(0LL, " .,:;") )
{
v9 = (void *)list_iterator(a2, 0LL);
while ( 1 )
{
v10 = (const char **)list_current(v9);
v11 = v10;
if ( v10 )
{
if ( !strcmp(*v10, j) )
break;
}
if ( !list_next(v9) )
{
free(v9);
v12 = malloc(0x10uLL);
*(_QWORD *)v12 = my_strdup(j);
v12[2] = 1;
list_add(a2, v12, 16LL);
free(v12);
goto LABEL_9;
}
}
++*((_DWORD *)v11 + 2);
free(v9);
LABEL_9:
;
}
free(v7);
}
free(i);
return (unsigned int)remove_infrequent_items(a2, a3, *a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int *a1, _DWORD *a2, int a3)
{
__int64 v3; // r15
void *i; // rdi
void *v5; // rax
char *v6; // rax
char *v7; // r14
char *j; // r12
void *v9; // rbp
const char **v10; // rax
const char **v11; // rbx
_DWORD *v12; // rbp

v3 = list_iterator(a1, 0LL);
for ( i = (void *)v3; list_next(v3); i = (void *)v3 )
{
v5 = (void *)list_current(i);
v6 = (char *)func0(v5);
v7 = v6;
if ( !v6 )
{
perror("malloc");
exit(1);
}
for ( j = strtok(v6, " .,:;"); j; j = strtok(0LL, " .,:;") )
{
v9 = (void *)list_iterator(a2, 0LL);
while ( 1 )
{
v10 = (const char **)list_current(v9);
v11 = v10;
if ( v10 )
{
if ( !strcmp(*v10, j) )
break;
}
if ( !list_next(v9) )
{
free(v9);
v12 = malloc(0x10uLL);
*(_QWORD *)v12 = func0(j);
v12[2] = 1;
list_add(a2, v12, 16LL);
free(v12);
goto LABEL_9;
}
}
++*((_DWORD *)v11 + 2);
free(v9);
LABEL_9:
;
}
free(v7);
}
free(i);
return (unsigned int)func4(a2, a3, *a1) != 0;
}

original_code:
int find_frequent_items(list_p tractions, list_p items, int min_sup) {
 int match;
 char *it, *tr_cp;
 const char* const delims = " .,:;";
 set_p new_set, cur_set;
 list_iter_p iter = list_iterator(tractions, 0);
 list_iter_p it_iter;
 while(list_next(iter)) {
  tr_cp = my_strdup((char*)list_current(iter));
  if(!tr_cp) {
   perror("malloc");
   exit(1);
  }
  it = strtok(tr_cp, delims);
  while(it) {
   it_iter = list_iterator(items, 0);
   do {
    match = 0;
    cur_set = (set_p)list_current(it_iter);
    if(cur_set && (!strcmp(cur_set->item, it))) {
     cur_set->sup_cnt++;
     match = 1;
     break;
    }
   } while(list_next(it_iter));
   free(it_iter);
   if(!match) {
    new_set = (set_p) malloc(sizeof(struct set));
    new_set->item = my_strdup(it);
    new_set->sup_cnt = 1;
    list_add(items, (void*)new_set, sizeof(*new_set));
    free(new_set);
   }
   it = strtok(((void *)0), delims);
  }
  free(tr_cp);
 }
 free(iter);
 if(!remove_infrequent_items(items, min_sup, tractions->length))
  return 0;
 return 1;
}

canonical_original_code:
int find_frequent_items(struct list *tractions, struct list *items, int min_sup) {
 int match;
 char *it; char *tr_cp;
 char *delims = " .,:;";
 struct set *new_set; struct set *cur_set;
 struct list_iter *iter = list_iterator(tractions, 0);
 struct list_iter *it_iter;
 while(list_next(iter)) {
  tr_cp = my_strdup((char *)list_current(iter));
  if(!tr_cp) {
   perror("malloc");
   exit(1);
  }
  it = strtok(tr_cp, delims);
  while(it) {
   it_iter = list_iterator(items, 0);
   do {
    match = 0;
    cur_set = (struct set *)list_current(it_iter);
    if(cur_set && (!strcmp(cur_set->item, it))) {
     cur_set->sup_cnt++;
     match = 1;
     break;
    }
   } while(list_next(it_iter));
   free(it_iter);
   if(!match) {
    new_set = (struct set *) malloc(sizeof(struct set));
    new_set->item = my_strdup(it);
    new_set->sup_cnt = 1;
    list_add(items, (void *)new_set, sizeof(*new_set));
    free(new_set);
   }
   it = strtok(((void *)0), delims);
  }
  free(tr_cp);
 }
 free(iter);
 if(!remove_infrequent_items(items, min_sup, tractions->length))
  return 0;
 return 1;
}

variable_types:
items
struct list *

variable_types: match int

variable_types:
it
char *

variable_types:
delims
char *

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


original_code:
void find_subsets(list_p items, int set_size, list_p sets, char *arr[], int q, int r) {
 int i;
 set_p new_set;
 char sub[256] = "";
 list_iter_p iter;
 if(q == set_size) {
  for(i=0; i<set_size; i++) {
   if(strlen(sub))
    strcat(sub, ",");
   strcat(sub, arr[i]);
  }
  new_set = (set_p) malloc(sizeof(struct set));
  if(!new_set) {
   perror("malloc:");
   exit(1);
  }
  list_add(sets, (void*)new_set, sizeof(*new_set));
  free(new_set);
  ((set_p)list_last(sets))->item = my_strdup(sub);
  ((set_p)list_last(sets))->sup_cnt = 0;
  *sub = '\0';
 }
 else {
  i = 0;
  iter = list_iterator(items, 0);
  while(i != r) {
   list_next(iter);
   i++;
  }
  while(list_next(iter)) {
   arr[q]=((set_p)list_current(iter))->item;
   find_subsets(items, set_size, sets, arr, q+1, i+1);
   i++;
  }
  free(iter);
 }
}

canonical_original_code:
void find_subsets(struct list *items, int set_size, struct list *sets, char *arr[], int q, int r) {
 int i;
 struct set *new_set;
 char sub[256] = "";
 struct list_iter *iter;
 if(q == set_size) {
  for(i=0; i<set_size; i++) {
   if(strlen(sub))
    strcat(sub, ",");
   strcat(sub, arr[i]);
  }
  new_set = (struct set *) malloc(sizeof(struct set));
  if(!new_set) {
   perror("malloc:");
   exit(1);
  }
  list_add(sets, (void *)new_set, sizeof(*new_set));
  free(new_set);
  ((struct set *)list_last(sets))->item = my_strdup(sub);
  ((struct set *)list_last(sets))->sup_cnt = 0;
  *sub = '\0';
 }
 else {
  i = 0;
  iter = list_iterator(items, 0);
  while(i != r) {
   list_next(iter);
   i++;
  }
  while(list_next(iter)) {
   arr[q]=((struct set *)list_current(iter))->item;
   find_subsets(items, set_size, sets, arr, q+1, i+1);
   i++;
  }
  free(iter);
 }
}

variable_types:
sets
struct list *

variable_types:
arr
char *[]

variable_types: q int

variable_types: r int

variable_types: i int

variable_types:
sub
char [256]

return_type: void


decompiled_code:
void __fastcall remove_unused(_DWORD *a1, _DWORD *a2)
{
void *v2; // r12
const char *v3; // r14
const char **v4; // rax
__int64 v5; // rax
void *v6; // rbp

v2 = (void *)list_iterator(a1, 0LL);
if ( *a1 && *a2 )
{
while ( list_next(v2) )
{
v6 = (void *)list_iterator(a2, 0LL);
if ( list_current(v6) )
{
while ( list_next(v6) )
{
v3 = *(const char **)list_current(v6);
v4 = (const char **)list_current(v2);
if ( strstr(*v4, v3) )
goto LABEL_7;
}
v5 = list_current(v2);
list_remove(a1, v5);
}
LABEL_7:
free(v6);
}
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func7(_DWORD *a1, _DWORD *a2)
{
void *v2; // r12
const char *v3; // r14
const char **v4; // rax
__int64 v5; // rax
void *v6; // rbp

v2 = (void *)list_iterator(a1, 0LL);
if ( *a1 && *a2 )
{
while ( list_next(v2) )
{
v6 = (void *)list_iterator(a2, 0LL);
if ( list_current(v6) )
{
while ( list_next(v6) )
{
v3 = *(const char **)list_current(v6);
v4 = (const char **)list_current(v2);
if ( strstr(*v4, v3) )
goto LABEL_7;
}
v5 = list_current(v2);
list_remove(a1, v5);
}
LABEL_7:
free(v6);
}
}
free(v2);
}

original_code:
void remove_unused(list_p from, list_p in) {
 list_iter_p from_iter = list_iterator(from, 0);
 list_iter_p in_iter;
 int found;
 if(from->length && in->length) {
  while(list_next(from_iter)) {
   in_iter = list_iterator(in, 0);
   if(list_current(in_iter) != ((void *)0)) {
    found = 0;
    while(list_next(in_iter)) {
     if(strstr(((set_p)list_current(from_iter))->item, ((set_p)list_current(in_iter))->item)) {
      found = 1;
      break;
     }
    }
    if(!found) {
     list_remove(from, (void*)list_current(from_iter));
    }
   }
   free(in_iter);
  }
 }
 free(from_iter);
}

canonical_original_code:
void remove_unused(struct list *from, struct list *in) {
 struct list_iter *from_iter = list_iterator(from, 0);
 struct list_iter *in_iter;
 int found;
 if(from->length && in->length) {
  while(list_next(from_iter)) {
   in_iter = list_iterator(in, 0);
   if(list_current(in_iter) != ((void *)0)) {
    found = 0;
    while(list_next(in_iter)) {
     if(strstr(((struct set *)list_current(from_iter))->item, ((struct set *)list_current(in_iter))->item)) {
      found = 1;
      break;
     }
    }
    if(!found) {
     list_remove(from, (void *)list_current(from_iter));
    }
   }
   free(in_iter);
  }
 }
 free(from_iter);
}

variable_types:
in
struct list *

variable_types: found int


decompiled_code:
__int64 __fastcall remove_infrequent_subsets(_DWORD *a1, _DWORD *a2, __int64 a3, unsigned int a4)
{
_DWORD *v6; // r14
void *v7; // r13
void *v8; // rsp
void *v9; // r12
const char *v10; // r15
const char **v11; // rax
__int64 v13; // rax
const char *v14; // [rsp+0h] [rbp-40h] BYREF
_DWORD *v15; // [rsp+8h] [rbp-38h]

v15 = a2;
v6 = (_DWORD *)create_list();
v7 = (void *)list_iterator(a3, 0LL);
v8 = alloca(8LL * (*a1 + 1));
find_subsets((__int64)a1, a4, (__int64)v6, &v14, 0, 0);
while ( list_next(v7) )
{
v9 = (void *)list_iterator(v6, 0LL);
while ( list_next(v9) )
{
v10 = *(const char **)list_current(v9);
v11 = (const char **)list_current(v7);
if ( !strcmp(*v11, v10) )
{
v13 = list_current(v9);
list_remove(v6, v13);
}
}
free(v9);
}
free(v7);
remove_unused(v15, v6);
return destroy_list(v6);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, _DWORD *a2, __int64 a3, unsigned int a4)
{
_DWORD *v6; // r14
void *v7; // r13
void *v8; // rsp
void *v9; // r12
const char *v10; // r15
const char **v11; // rax
__int64 v13; // rax
const char *v14; // [rsp+0h] [rbp-40h] BYREF
_DWORD *v15; // [rsp+8h] [rbp-38h]

v15 = a2;
v6 = (_DWORD *)create_list();
v7 = (void *)list_iterator(a3, 0LL);
v8 = alloca(8LL * (*a1 + 1));
func6((__int64)a1, a4, (__int64)v6, &v14, 0, 0);
while ( list_next(v7) )
{
v9 = (void *)list_iterator(v6, 0LL);
while ( list_next(v9) )
{
v10 = *(const char **)list_current(v9);
v11 = (const char **)list_current(v7);
if ( !strcmp(*v11, v10) )
{
v13 = list_current(v9);
list_remove(v6, v13);
}
}
free(v9);
}
free(v7);
func7(v15, v6);
return destroy_list(v6);
}

original_code:
void remove_infrequent_subsets(list_p items, list_p sets, list_p prev_freq_sets, int size) {
 list_p subsets = create_list();
 list_iter_p sub_iter;
 list_iter_p pset_iter = list_iterator(prev_freq_sets, 0);
 char *arr[items->length + 1];
 find_subsets(items, size, subsets, arr, 0, 0);
 while(list_next(pset_iter)) {
  sub_iter = list_iterator(subsets, 0);
  while(list_next(sub_iter)) {
   if(!strcmp(((set_p)list_current(pset_iter))->item, ((set_p)list_current(sub_iter))->item)) {
    list_remove(subsets, (void*)list_current(sub_iter));
   }
  }
  free(sub_iter);
 }
 free(pset_iter);
 remove_unused(sets, subsets);
 destroy_list(subsets);
}

canonical_original_code:
void remove_infrequent_subsets(struct list *items, struct list *sets, struct list *prev_freq_sets, int size) {
 struct list *subsets = create_list();
 struct list_iter *sub_iter;
 struct list_iter *pset_iter = list_iterator(prev_freq_sets, 0);
 char *arr[-1];
 find_subsets(items, size, subsets, arr, 0, 0);
 while(list_next(pset_iter)) {
  sub_iter = list_iterator(subsets, 0);
  while(list_next(sub_iter)) {
   if(!strcmp(((struct set *)list_current(pset_iter))->item, ((struct set *)list_current(sub_iter))->item)) {
    list_remove(subsets, (void *)list_current(sub_iter));
   }
  }
  free(sub_iter);
 }
 free(pset_iter);
 remove_unused(sets, subsets);
 destroy_list(subsets);
}

variable_types: size int

variable_types:
arr
char *[-1]


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

result = malloc(0x20uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
result[3] = &free;
return result;
}

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

result = malloc(0x20uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
result[3] = &free;
return result;
}

original_code:
list_p create_list(){
 list_p list = (list_p) malloc(sizeof(struct list));
 list->length = 0;
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->destructor = free;
 return list;
}

canonical_original_code:
struct list *create_list(){
 struct list *list = (list_p) malloc(sizeof(struct list));
 list->length = 0;
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->destructor = free;
 return list;
}

variable_types: struct list { int length; struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *first; struct linked_node *last; void (*destructor)(void *); } *


decompiled_code:
__int64 __fastcall list_first(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

original_code:
void* list_first(list_p list){
 return list->first->data;
}

canonical_original_code:
void *list_first(struct list *list){
 return list->first->data;
}

return_type: void *


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

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

original_code:
void* list_last(list_p list){
 return list->last->data;
}

canonical_original_code:
void *list_last(struct list *list){
 return list->last->data;
}


original_code:
void* list_pop(list_p list){
 lnode_p last = list->last;
 if(last == ((void *)0))
  return ((void *)0);
 void* data = last->data;
 if(last->prev) {
  list->last = last->prev;
  last->prev->next = ((void *)0);
 }
 free(last);
 return data;
}

canonical_original_code:
void *list_pop(struct list *list){
 struct linked_node *last = list->last;
 if(last == ((void *)0))
  return ((void *)0);
 void *data = last->data;
 if(last->prev) {
  list->last = last->prev;
  last->prev->next = ((void *)0);
 }
 free(last);
 return data;
}

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

variable_types:
data
void *


original_code:
void* list_poll(list_p list){
 lnode_p first = list->first;
 if(!first)
  return ((void *)0);
 void* data = first->data;
 if(first->next) {
  list->first = first->next;
  first->next->prev = ((void *)0);
 }
 free(first);
 return data;
}

canonical_original_code:
void *list_poll(struct list *list){
 struct linked_node *first = list->first;
 if(!first)
  return ((void *)0);
 void *data = first->data;
 if(first->next) {
  list->first = first->next;
  first->next->prev = ((void *)0);
 }
 free(first);
 return data;
}


decompiled_code:
void __fastcall destroy_list(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
while ( 1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
if ( !*(_DWORD *)ptr )
break;
(*((void (__fastcall **)(_QWORD))ptr + 3))(*v2);
free(v2);
if ( !v1 )
goto LABEL_5;
}
}
LABEL_5:
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
while ( 1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
if ( !*(_DWORD *)ptr )
break;
(*((void (__fastcall **)(_QWORD))ptr + 3))(*v2);
free(v2);
if ( !v1 )
goto LABEL_5;
}
}
LABEL_5:
free(ptr);
}

original_code:
void destroy_list(list_p list) {
 lnode_p cur = list->first;
 lnode_p next;
 while(cur) {
  next = cur->next;
  if(list->length != 0) {
   list->destructor(cur->data);
   free(cur);
  }
  cur = next;
 }
 free(list);
}

canonical_original_code:
void destroy_list(struct list *list) {
 struct linked_node *cur = list->first;
 struct linked_node *next;
 while(cur) {
  next = cur->next;
  if(list->length != 0) {
   list->destructor(cur->data);
   free(cur);
  }
  cur = next;
 }
 free(list);
}


original_code:
void* list_remove_middle(lnode_p node) {
 void *data = node->data;
 node->prev->next = node->next;
 node->next->prev = node->prev;
 free(node);
 return data;
}

canonical_original_code:
void *list_remove_middle(struct linked_node *node) {
 void *data = node->data;
 node->prev->next = node->next;
 node->next->prev = node->prev;
 free(node);
 return data;
}


decompiled_code:
__int64 __fastcall list_remove(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 *v4; // rdi
__int64 v5; // rdi

result = *(_QWORD *)(a1 + 8);
if ( result )
{
v4 = *(__int64 **)(a1 + 8);
while ( *v4 != a2 )
{
v4 = (__int64 *)v4[1];
if ( !v4 )
return result;
}
if ( (__int64 *)result == v4 )
{
result = list_poll(a1);
v5 = result;
}
else
{
if ( *(__int64 **)(a1 + 16) == v4 )
result = list_pop(a1);
else
result = list_remove_middle(v4);
v5 = result;
}
if ( v5 )
{
result = (*(__int64 (**)(void))(a1 + 24))();
--*(_DWORD *)a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 *v4; // rdi
__int64 v5; // rdi

result = *(_QWORD *)(a1 + 8);
if ( result )
{
v4 = *(__int64 **)(a1 + 8);
while ( *v4 != a2 )
{
v4 = (__int64 *)v4[1];
if ( !v4 )
return result;
}
if ( (__int64 *)result == v4 )
{
result = func4(a1);
v5 = result;
}
else
{
if ( *(__int64 **)(a1 + 16) == v4 )
result = func3(a1);
else
result = func6(v4);
v5 = result;
}
if ( v5 )
{
result = (*(__int64 (**)(void))(a1 + 24))();
--*(_DWORD *)a1;
}
}
return result;
}

original_code:
void list_remove(list_p list, void *data) {
 void *tmp = ((void *)0);
 lnode_p cur = list->first;
 if(!cur) {
  return;
 }
 while(cur) {
  if(cur->data == data) {
   if(cur == list->first) {
    tmp = list_poll(list);
    break;
   }
   else if(cur == list->last) {
    tmp = list_pop(list);
    break;
   }
   else {
    tmp = list_remove_middle(cur);
    break;
   }
  }
  cur = cur->next;
 }
 if(tmp) {
  list->destructor(tmp);
  list->length--;
 }
}

canonical_original_code:
void list_remove(struct list *list, void *data) {
 void *tmp = ((void *)0);
 struct linked_node *cur = list->first;
 if(!cur) {
  return;
 }
 while(cur) {
  if(cur->data == data) {
   if(cur == list->first) {
    tmp = list_poll(list);
    break;
   }
   else if(cur == list->last) {
    tmp = list_pop(list);
    break;
   }
   else {
    tmp = list_remove_middle(cur);
    break;
   }
  }
  cur = cur->next;
 }
 if(tmp) {
  list->destructor(tmp);
  list->length--;
 }
}

variable_types:
tmp
void *


panic

decompiled_code:
void __fastcall __noreturn panic(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void panic(char* str)
{
  perror(str);
  exit(1);
}

canonical_original_code:
void panic(char *str)
{
  perror(str);
  exit(1);
}

variable_types:
str
char *


decompiled_code:
void __fastcall sha256_update_mpz(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4[4]; // [rsp+10h] [rbp-20h] BYREF

v4[0] = 0LL;
v2 = _gmpz_export(0LL, v4, 1LL, 1LL, 0LL, 0LL, a2);
if ( !v2 )
panic("sha256_update_mpz export");
v3 = (void *)v2;
nettle_sha256_update(a1, v4[0], v2);
free(v3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4[4]; // [rsp+10h] [rbp-20h] BYREF

v4[0] = 0LL;
v2 = _gmpz_export(0LL, v4, 1LL, 1LL, 0LL, 0LL, a2);
if ( !v2 )
func0("sha256_update_mpz export");
v3 = (void *)v2;
nettle_sha256_update(a1, v4[0], v2);
free(v3);
}

original_code:
void sha256_update_mpz( struct sha256_ctx* context, const mpz_t luku )
{
  size_t luku_len = 0;
  void* luku_data = __gmpz_export( ((void *)0), &luku_len, 1, 1, 0, 0, luku );
  if( luku_data == ((void *)0) ) panic( "sha256_update_mpz export" );
  nettle_sha256_update( context, luku_len, luku_data );
  free( luku_data );
}

canonical_original_code:
void sha256_update_mpz(struct sha256_ctx *context, struct __mpz_struct luku[1])
{
  unsigned long luku_len = 0;
  void *luku_data = __gmpz_export( ((void *)0), &luku_len, 1, 1, 0, 0, luku );
  if( luku_data == ((void *)0) ) panic( "sha256_update_mpz export" );
  nettle_sha256_update( context, luku_len, luku_data );
  free( luku_data );
}

variable_types: struct sha256_ctx { unsigned int state[8]; unsigned long count; unsigned char block[64]; unsigned int index; } *

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]


decompiled_code:
__int64 __fastcall sha256_s(const char *a1, __int64 a2)
{
size_t v2; // rbp
_BYTE v4[32]; // [rsp+0h] [rbp-A8h] BYREF
char v5[136]; // [rsp+20h] [rbp-88h] BYREF

if ( !a1 )
_assert_fail("s != NULL", "util.c", 0x49u, "sha256_s");
v2 = strlen(a1);
if ( !v2 )
_assert_fail("s_len > 0", "util.c", 0x4Eu, "sha256_s");
nettle_sha256_init(v5);
nettle_sha256_update(v5, v2, a1);
nettle_sha256_digest(v5, 32LL, v4);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2)
{
size_t v2; // rbp
_BYTE v4[32]; // [rsp+0h] [rbp-A8h] BYREF
char v5[136]; // [rsp+20h] [rbp-88h] BYREF

if ( !a1 )
_assert_fail("s != NULL", "util.c", 0x49u, "sha256_s");
v2 = strlen(a1);
if ( !v2 )
_assert_fail("s_len > 0", "util.c", 0x4Eu, "sha256_s");
nettle_sha256_init(v5);
nettle_sha256_update(v5, v2, a1);
nettle_sha256_digest(v5, 32LL, v4);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v4);
}

original_code:
void sha256_s( const unsigned char* const s, mpz_t retval )
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 73, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    size_t s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 78, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_s(unsigned char *s, struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 73, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    unsigned long s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 78, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

variable_types:
s
unsigned char *

variable_types:
digest
unsigned char [32]

variable_types: struct sha256_ctx { unsigned int state[8]; unsigned long count; unsigned char block[64]; unsigned int index; }

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
__int64 __fastcall sha256_zs(__int64 a1, const char *a2, __int64 a3)
{
size_t v4; // r13
_BYTE v6[32]; // [rsp+0h] [rbp-B8h] BYREF
char v7[152]; // [rsp+20h] [rbp-98h] BYREF

if ( !a2 )
_assert_fail("s != NULL", "util.c", 0x65u, "sha256_zs");
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 0x66u, "sha256_zs");
v4 = strlen(a2);
if ( !v4 )
_assert_fail("s_len > 0", "util.c", 0x6Bu, "sha256_zs");
nettle_sha256_init(v7);
sha256_update_mpz((__int64)v7, a1);
nettle_sha256_update(v7, v4, a2);
nettle_sha256_digest(v7, 32LL, v6);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v6);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, __int64 a3)
{
size_t v4; // r13
_BYTE v6[32]; // [rsp+0h] [rbp-B8h] BYREF
char v7[152]; // [rsp+20h] [rbp-98h] BYREF

if ( !a2 )
_assert_fail("s != NULL", "util.c", 0x65u, "sha256_zs");
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 0x66u, "sha256_zs");
v4 = strlen(a2);
if ( !v4 )
_assert_fail("s_len > 0", "util.c", 0x6Bu, "sha256_zs");
nettle_sha256_init(v7);
func2((__int64)v7, a1);
nettle_sha256_update(v7, v4, a2);
nettle_sha256_digest(v7, 32LL, v6);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v6);
}

original_code:
void sha256_zs( mpz_t z, const unsigned char* const s, mpz_t retval )
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 101, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( z, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 102, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    size_t s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 107, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, z );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_zs(struct __mpz_struct z[1], unsigned char *s, struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 101, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( z, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 102, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    unsigned long s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 107, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, z );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

variable_types:
retval
struct __mpz_struct [1]

user_defined_types: struct sha256_ctx { unsigned int state[8]; unsigned long count; unsigned char block[64]; unsigned int index; }


decompiled_code:
__int64 __fastcall sha256_z(__int64 a1, __int64 a2)
{
_BYTE v3[32]; // [rsp+0h] [rbp-A8h] BYREF
char v4[136]; // [rsp+20h] [rbp-88h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x82u, "sha256_z");
nettle_sha256_init(v4);
sha256_update_mpz((__int64)v4, a1);
nettle_sha256_digest(v4, 32LL, v3);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
_BYTE v3[32]; // [rsp+0h] [rbp-A8h] BYREF
char v4[136]; // [rsp+20h] [rbp-88h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x82u, "sha256_z");
nettle_sha256_init(v4);
func2((__int64)v4, a1);
nettle_sha256_digest(v4, 32LL, v3);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v3);
}

original_code:
void sha256_z( mpz_t a, mpz_t retval )
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 130, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_z(struct __mpz_struct a[1], struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 130, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}


decompiled_code:
__int64 __fastcall sha256_zz(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[32]; // [rsp+0h] [rbp-A8h] BYREF
char v6[136]; // [rsp+20h] [rbp-88h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x9Bu, "sha256_zz");
nettle_sha256_init(v6);
sha256_update_mpz((__int64)v6, a1);
sha256_update_mpz((__int64)v6, a2);
nettle_sha256_digest(v6, 32LL, v5);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v5);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[32]; // [rsp+0h] [rbp-A8h] BYREF
char v6[136]; // [rsp+20h] [rbp-88h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x9Bu, "sha256_zz");
nettle_sha256_init(v6);
func2((__int64)v6, a1);
func2((__int64)v6, a2);
nettle_sha256_digest(v6, 32LL, v5);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v5);
}

original_code:
void sha256_zz( mpz_t a, mpz_t b, mpz_t retval )
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 155, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 156, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    sha256_update_mpz( &sha_puskuri, b );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_zz(struct __mpz_struct a[1], struct __mpz_struct b[1], struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 155, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 156, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    sha256_update_mpz( &sha_puskuri, b );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

variable_types:
b
struct __mpz_struct [1]


decompiled_code:
void *__fastcall sha256_binz(__int64 a1)
{
void *v1; // rax
void *v2; // r12
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = malloc(0x21uLL);
if ( !v1 )
panic("malloc failed");
v2 = v1;
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0xB9u, "sha256_binz");
nettle_sha256_init(v4);
sha256_update_mpz((__int64)v4, a1);
nettle_sha256_digest(v4, 32LL, v2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
void *v1; // rax
void *v2; // r12
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = malloc(0x21uLL);
if ( !v1 )
func0("malloc failed");
v2 = v1;
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0xB9u, "sha256_binz");
nettle_sha256_init(v4);
func2((__int64)v4, a1);
nettle_sha256_digest(v4, 32LL, v2);
return v2;
}

original_code:
BYTE* sha256_binz( mpz_t a )
{
  BYTE* retval = malloc( 32 + 1 );
  if( retval == ((void *)0) ) {
    panic("malloc failed");
  }
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 185, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, retval );
  }
  return retval;
}

canonical_original_code:
unsigned char *sha256_binz(struct __mpz_struct a[1])
{
  unsigned char *retval = malloc( 32 + 1 );
  if( retval == ((void *)0) ) {
    panic("malloc failed");
  }
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 185, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, retval );
  }
  return retval;
}

variable_types:
retval
unsigned char *

return_type: unsigned char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
InitKernel(argc, argv, envp);
mymain();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func27(argc, argv, envp);
func20();
}

original_code:
int main(void)
{
  InitKernel();
  ;
  mymain();
  return 0;
}

canonical_original_code:
int main()
{
  InitKernel();
  ;
  mymain();
  return 0;
}


myprint

decompiled_code:
int __fastcall myprint(const char *format)
{
return printf(format);
}

canonical_decompiled_code:
int __fastcall func7(const char *format)
{
return printf(format);
}

original_code:
void myprint(char *text)
{
  printf(text);
}

variable_types:
text
char *


InitTD

decompiled_code:
int __fastcall InitTD(_DWORD *a1, int a2, int a3, int a4)
{
int result; // eax

if ( !a1 )
return myprint("Tried to initialize NULL pointer\n");
a1[4] = a2;
a1[3] = a3;
a1[5] = 3;
a1[6] = a4;
return result;
}

canonical_decompiled_code:
int __fastcall func9(_DWORD *a1, int a2, int a3, int a4)
{
int result; // eax

if ( !a1 )
return func7("Tried to initialize NULL pointer\n");
a1[4] = a2;
a1[3] = a3;
a1[5] = 3;
a1[6] = a4;
return result;
}

original_code:
void InitTD(TD *td, uval32 pc, uval32 sp, uval32 priority)
{
  if(td != ((void *)0)) {
    td->regs.pc = pc;
    td->regs.sp = sp;
    td->regs.sr = 0x0003;
    td->priority = priority;
  } else {
    myprint("Tried to initialize NULL pointer\n");
  }
}

canonical_original_code:
void InitTD(struct type_TD *td, unsigned int pc, unsigned int sp, unsigned int priority)
{
  if(td != ((void *)0)) {
    td->regs.pc = pc;
    td->regs.sp = sp;
    td->regs.sr = 0x0003;
    td->priority = priority;
  } else {
    myprint("Tried to initialize NULL pointer\n");
  }
}

variable_types: struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS { unsigned int sp; unsigned int pc; unsigned int sr; } regs; unsigned int priority; int waittime; enum RC { RC_SUCCESS=0, RC_FAILED=1 } returnCode; struct type_LL { struct type_TD *head; struct type_TD *tail; enum ListType { UNDEF=0, L_PRIORITY=1, L_LIFO=2, L_WAITING=3, L_CIRCULAR=4 } type; } *inlist; } *

variable_types:
pc
unsigned int

variable_types:
sp
unsigned int

variable_types:
priority
unsigned int

user_defined_types: struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS regs; unsigned int priority; int waittime; enum RC returnCode; struct type_LL *inlist; }

user_defined_types: struct type_LL { struct type_TD *head; struct type_TD *tail; enum ListType type; }


FreeQEnqueue

original_code:
int FreeQEnqueue(TD *td, LL *list) {
 if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  list->tail->link = td;
  td->link = list->head;
  list->tail = td;
  return 0;
 } else {
  list->head = td;
  list->tail = td;
  td->link = td;
  return 0;
 }
 return 1;
}

canonical_original_code:
int FreeQEnqueue(struct type_TD *td, struct type_LL *list) {
 if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  list->tail->link = td;
  td->link = list->head;
  list->tail = td;
  return 0;
 } else {
  list->head = td;
  list->tail = td;
  td->link = td;
  return 0;
 }
 return 1;
}

variable_types:
list
struct type_LL *

user_defined_types: struct type_REGS { unsigned int sp; unsigned int pc; unsigned int sr; }

user_defined_types: enum ListType { UNDEF=0, L_PRIORITY=1, L_LIFO=2, L_WAITING=3, L_CIRCULAR=4 }


FreeQDequeue

decompiled_code:
__int64 __fastcall FreeQDequeue(__int64 **a1)
{
__int64 *v1; // rax
__int64 *v2; // rdx
__int64 *v3; // rcx
__int64 result; // rax

v1 = *a1;
v2 = a1[1];
if ( *a1 == v2 )
{
*a1 = 0LL;
result = *((unsigned int *)v1 + 2);
a1[1] = 0LL;
}
else if ( v1 && v2 )
{
v3 = (__int64 *)*v1;
result = *((unsigned int *)v1 + 2);
*a1 = v3;
*v2 = (__int64)v3;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int FreeQDequeue(LL *list) {
 if (list->head == list->tail) {
  TD *head = list->head;
  list->head = ((void *)0);
  list->tail = ((void *)0);
  return head->tid;
 } else if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  TD *head = list->head;
  list->head = list->head->link;
  list->tail->link = list->head;
  return head->tid;
 } else {
  return 0;
 }
}

canonical_original_code:
int FreeQDequeue(struct type_LL *list) {
 if (list->head == list->tail) {
  struct type_TD *head = list->head;
  list->head = ((void *)0);
  list->tail = ((void *)0);
  return head->tid;
 } else if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  struct type_TD *head = list->head;
  list->head = list->head->link;
  list->tail->link = list->head;
  return head->tid;
 } else {
  return 0;
 }
}

variable_types: struct type_LL { struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS { unsigned int sp; unsigned int pc; unsigned int sr; } regs; unsigned int priority; int waittime; enum RC { RC_SUCCESS=0, RC_FAILED=1 } returnCode; struct type_LL *inlist; } *head; struct type_TD *tail; enum ListType { UNDEF=0, L_PRIORITY=1, L_LIFO=2, L_WAITING=3, L_CIRCULAR=4 } type; } *


Dequeue

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

result = *a2;
if ( !*a2 )
return 0LL;
if ( result == a1 )
{
*a2 = *(_QWORD *)result;
result = 1LL;
}
else
{
while ( 1 )
{
v3 = (_QWORD *)result;
result = *(_QWORD *)result;
if ( !result )
break;
if ( result == a1 )
{
*v3 = *(_QWORD *)result;
return 1LL;
}
}
}
return result;
}

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

result = *a2;
if ( !*a2 )
return 0LL;
if ( result == a1 )
{
*a2 = *(_QWORD *)result;
result = 1LL;
}
else
{
while ( 1 )
{
v3 = (_QWORD *)result;
result = *(_QWORD *)result;
if ( !result )
break;
if ( result == a1 )
{
*v3 = *(_QWORD *)result;
return 1LL;
}
}
}
return result;
}

original_code:
int Dequeue( TD *td, LL *list ) {
 TD * ptr;
 if ((ptr = list->head) == ((void *)0)) {
  return 0;
 } else if (ptr == td) {
  list->head = td->link;
  return 1;
 } else {
  while (ptr->link != ((void *)0)) {
   if (ptr->link == td) {
    ptr->link = td->link;
    return 1;
   }
   ptr = ptr->link;
  }
 }
 return 0;
}

canonical_original_code:
int Dequeue(struct type_TD *td, struct type_LL *list) {
 struct type_TD *ptr;
 if ((ptr = list->head) == ((void *)0)) {
  return 0;
 } else if (ptr == td) {
  list->head = td->link;
  return 1;
 } else {
  while (ptr->link != ((void *)0)) {
   if (ptr->link == td) {
    ptr->link = td->link;
    return 1;
   }
   ptr = ptr->link;
  }
 }
 return 0;
}


DestroyList

decompiled_code:
__int64 __fastcall DestroyList(void *ptr)
{
_QWORD *v1; // rax

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

canonical_decompiled_code:
__int64 __fastcall func13(void *ptr)
{
_QWORD *v1; // rax

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

original_code:
RC DestroyList( LL *list )
{
  if(!list){
    return RC_FAILED;
  }
  if(list->head){
    TD* current = list->head;
    while(current){
      TD* old_head = DequeueHead(list);
      free(old_head);
      current = list->head;
    }
  }
  if (!list->head) {
    free(list);
    return RC_SUCCESS;
  }
  free(list);
  return RC_FAILED;
}

canonical_original_code:
enum RC DestroyList(struct type_LL *list)
{
  if(!list){
    return RC_FAILED;
  }
  if(list->head){
    struct type_TD *current = list->head;
    while(current){
      struct type_TD *old_head = DequeueHead(list);
      free(old_head);
      current = list->head;
    }
  }
  if (!list->head) {
    free(list);
    return RC_SUCCESS;
  }
  free(list);
  return RC_FAILED;
}

return_type: enum RC { RC_SUCCESS=0, RC_FAILED=1 }


PriorityEnqueue

original_code:
RC PriorityEnqueue(TD *td, LL *list)
{
  TD *cur, *prev;
    if(!td || !list || list->type != L_PRIORITY){
      return RC_FAILED;
    }
    td->inlist = list;
    if(!list->head){
      list->head = td;
    } else{
      prev = ((void *)0);
      cur = list->head;
      while(cur){
        if(cur->priority >= td->priority){
          if(!prev){
            td->link = list->head;
            list->head = td;
          } else{
            td->link = cur;
            prev->link = td;
          }
          break;
        }
        prev = cur;
        cur = cur->link;
      }
    }
    return RC_SUCCESS;
}

canonical_original_code:
enum RC PriorityEnqueue(struct type_TD *td, struct type_LL *list)
{
  struct type_TD *cur; struct type_TD *prev;
    if(!td || !list || list->type != L_PRIORITY){
      return RC_FAILED;
    }
    td->inlist = list;
    if(!list->head){
      list->head = td;
    } else{
      prev = ((void *)0);
      cur = list->head;
      while(cur){
        if(cur->priority >= td->priority){
          if(!prev){
            td->link = list->head;
            list->head = td;
          } else{
            td->link = cur;
            prev->link = td;
          }
          break;
        }
        prev = cur;
        cur = cur->link;
      }
    }
    return RC_SUCCESS;
}


EnqueueAtHead

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

result = 1LL;
if ( a1 && a2 && *(_DWORD *)(a2 + 16) == 2 )
{
*a1 = *(_QWORD *)a2;
result = 0LL;
*(_QWORD *)a2 = a1;
a1[5] = a2;
}
return result;
}

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

result = 1LL;
if ( a1 && a2 && *(_DWORD *)(a2 + 16) == 2 )
{
*a1 = *(_QWORD *)a2;
result = 0LL;
*(_QWORD *)a2 = a1;
a1[5] = a2;
}
return result;
}

original_code:
RC EnqueueAtHead(TD *td, LL *list)
{
    if(!td || !list || list->type != L_LIFO){
      return RC_FAILED;
    }
    td->link = list->head;
    list->head = td;
    td->inlist = list;
    return RC_SUCCESS;
}

canonical_original_code:
enum RC EnqueueAtHead(struct type_TD *td, struct type_LL *list)
{
    if(!td || !list || list->type != L_LIFO){
      return RC_FAILED;
    }
    td->link = list->head;
    list->head = td;
    td->inlist = list;
    return RC_SUCCESS;
}


WaitlistEnqueue

original_code:
RC WaitlistEnqueue(TD *td, int waittime, LL *list)
{
    TD *cur, *prev;
    if(!td || !list){
      return RC_FAILED;
    }
    if(list->type != L_WAITING){
      return RC_FAILED;
    }
    if (list->head == ((void *)0)) {
    list->head = td;
  } else if (waittime < (list->head)->waittime){
    td->link = list->head;
    list->head = td;
  } else {
    prev = list->head;
    cur = prev->link;
    waittime -= prev->waittime;
    while ((cur != ((void *)0)) && (waittime > cur->waittime))
    {
      prev = cur;
          cur = cur->link;
      waittime -= prev->waittime;
      }
      if (cur != ((void *)0)) {
      td->link = prev->link;
      prev->link = td;
    } else {
          prev->link = td;
    }
  }
  td->inlist = list;
  td->waittime = waittime;
  waitDiff(td->link, waittime);
  return RC_SUCCESS;
}

canonical_original_code:
enum RC WaitlistEnqueue(struct type_TD *td, int waittime, struct type_LL *list)
{
    struct type_TD *cur; struct type_TD *prev;
    if(!td || !list){
      return RC_FAILED;
    }
    if(list->type != L_WAITING){
      return RC_FAILED;
    }
    if (list->head == ((void *)0)) {
    list->head = td;
  } else if (waittime < (list->head)->waittime){
    td->link = list->head;
    list->head = td;
  } else {
    prev = list->head;
    cur = prev->link;
    waittime -= prev->waittime;
    while ((cur != ((void *)0)) && (waittime > cur->waittime))
    {
      prev = cur;
          cur = cur->link;
      waittime -= prev->waittime;
      }
      if (cur != ((void *)0)) {
      td->link = prev->link;
      prev->link = td;
    } else {
          prev->link = td;
    }
  }
  td->inlist = list;
  td->waittime = waittime;
  waitDiff(td->link, waittime);
  return RC_SUCCESS;
}

variable_types: waittime int


DequeueTD

original_code:
void DequeueTD(TD* td){
  if(!td){
    return;
  }
  if (td->inlist) {
    if(td->inlist->head == td){
      td->inlist->head = td->link;
    } else {
      TD *prev, *next;
      prev = FindPrevTD(td->tid, td->inlist);
      next = prev->link->link;
      prev->link = next;
    }
  }
}

canonical_original_code:
void DequeueTD(struct type_TD *td){
  if(!td){
    return;
  }
  if (td->inlist) {
    if(td->inlist->head == td){
      td->inlist->head = td->link;
    } else {
      struct type_TD *prev; struct type_TD *next;
      prev = FindPrevTD(td->tid, td->inlist);
      next = prev->link->link;
      prev->link = next;
    }
  }
}


SysCall

decompiled_code:
__int64 __fastcall SysCall(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
myprint("Here\n");
CreateThread(a2, a3, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
func7("Here\n");
func28(a2, a3, a4);
return 0LL;
}

original_code:
RC SysCall(SysCallType type, uval32 arg0, uval32 arg1, uval32 arg2)
{
  uval32 returnCode;
  myprint("Here\n");
  CreateThread(arg0, arg1, arg2);
  returnCode = RC_SUCCESS;
  return returnCode;
}

canonical_original_code:
enum RC SysCall(enum SysCallType type, unsigned int arg0, unsigned int arg1, unsigned int arg2)
{
  unsigned int returnCode;
  myprint("Here\n");
  CreateThread(arg0, arg1, arg2);
  returnCode = RC_SUCCESS;
  return returnCode;
}

variable_types: enum SysCallType { SYS_CREATE=0, SYS_DIST=1, SYS_YIELD=2, SYS_SUSP=3, SYS_RESUME=4, SYS_CHANGE_PRI=5 }

variable_types:
returnCode
unsigned int


mymain

decompiled_code:
void __noreturn mymain()
{
if ( (unsigned int)SysCall(0LL, 0x1234u, 0, 0) )
__assert_fail("ret == RC_SUCCESS", "user.c", 0x2Fu, "mymain");
myprint("DONE\n");
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func20()
{
if ( (unsigned int)func19(0LL, 0x1234u, 0, 0) )
__assert_fail("ret == RC_SUCCESS", "user.c", 0x2Fu, "mymain");
func7("DONE\n");
while ( 1 )
;
}

original_code:
void mymain()
{
  RC ret;
  ret = SysCall(SYS_CREATE, 0x1234, 0, 0);
  ((void) sizeof ((ret == RC_SUCCESS) ? 1 : 0), __extension__ ({ if (ret == RC_SUCCESS) ; else __assert_fail ("ret == RC_SUCCESS", "user.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  myprint("DONE\n");
  while(1);
}

canonical_original_code:
void mymain()
{
  enum RC ret;
  ret = SysCall(SYS_CREATE, 0x1234, 0, 0);
  ((void) sizeof ((ret == RC_SUCCESS) ? 1 : 0), __extension__ ({ if (ret == RC_SUCCESS) ; else __assert_fail ("ret == RC_SUCCESS", "user.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  myprint("DONE\n");
  while(1);
}

variable_types:
ret
enum RC { RC_SUCCESS=0, RC_FAILED=1 }


getTid

decompiled_code:
__int64 getTid()
{
return FreeQDequeue((__int64 **)FreeQ);
}

canonical_decompiled_code:
__int64 func21()
{
return func11((__int64 **)FreeQ);
}

original_code:
uval32 getTid(){
 return FreeQDequeue(FreeQ);
}

canonical_original_code:
unsigned int getTid(){
 return FreeQDequeue(FreeQ);
}

return_type: unsigned int


tidInUse

decompiled_code:
__int64 __fastcall tidInUse(int a1)
{
__int64 result; // rax
_QWORD *v2; // rdx
_QWORD *v3; // rax

result = 0LL;
if ( (unsigned int)(a1 - 1) <= 0x3FF )
{
v2 = *(_QWORD **)FreeQ;
result = 1LL;
if ( *(_DWORD *)(*(_QWORD *)FreeQ + 24LL) != a1 )
{
v3 = (_QWORD *)*v2;
if ( v2 == (_QWORD *)*v2 )
{
LABEL_4:
result = 0LL;
}
else
{
while ( *((_DWORD *)v3 + 6) != a1 )
{
v3 = (_QWORD *)*v3;
if ( v2 == v3 )
goto LABEL_4;
}
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(int a1)
{
__int64 result; // rax
_QWORD *v2; // rdx
_QWORD *v3; // rax

result = 0LL;
if ( (unsigned int)(a1 - 1) <= 0x3FF )
{
v2 = *(_QWORD **)FreeQ;
result = 1LL;
if ( *(_DWORD *)(*(_QWORD *)FreeQ + 24LL) != a1 )
{
v3 = (_QWORD *)*v2;
if ( v2 == (_QWORD *)*v2 )
{
LABEL_4:
result = 0LL;
}
else
{
while ( *((_DWORD *)v3 + 6) != a1 )
{
v3 = (_QWORD *)*v3;
if ( v2 == v3 )
goto LABEL_4;
}
result = 1LL;
}
}
}
return result;
}

original_code:
int tidInUse(ThreadId tid) {
 if ((tid > 1024) || (tid < 1)) {
  return 0;
 } else {
  TD *ptr = FreeQ->head;
  if (ptr->priority == tid) {
   return 1;
  } else {
   ptr = ptr->link;
  }
  while (ptr != FreeQ->head) {
   if (ptr->priority == tid) {
    return 1;
   } else {
    ptr = ptr->link;
   }
  }
  return 0;
 }
}

canonical_original_code:
int tidInUse(unsigned int tid) {
 if ((tid > 1024) || (tid < 1)) {
  return 0;
 } else {
  struct type_TD *ptr = FreeQ->head;
  if (ptr->priority == tid) {
   return 1;
  } else {
   ptr = ptr->link;
  }
  while (ptr != FreeQ->head) {
   if (ptr->priority == tid) {
    return 1;
   } else {
    ptr = ptr->link;
   }
  }
  return 0;
 }
}

variable_types:
tid
unsigned int


ChangeThreadPriority

decompiled_code:
__int64 __fastcall ChangeThreadPriority(int a1, int a2)
{
unsigned int v2; // er12
__int64 v4; // rax
__int64 v5; // rbp

v2 = 3;
if ( (unsigned int)tidInUse(a1) )
{
v4 = getTD(a1);
v2 = 6;
*(_DWORD *)(v4 + 24) = a2;
v5 = v4;
if ( *(_QWORD *)(v4 + 40) == ReadyQ )
{
if ( (unsigned int)Dequeue(v4, (__int64 *)ReadyQ) )
PriorityEnqueue(v5, (__int64 *)ReadyQ);
else
myprint("Dequeue error\n");
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func24(int a1, int a2)
{
unsigned int v2; // er12
__int64 v4; // rax
__int64 v5; // rbp

v2 = 3;
if ( (unsigned int)func23(a1) )
{
v4 = func22(a1);
v2 = 6;
*(_DWORD *)(v4 + 24) = a2;
v5 = v4;
if ( *(_QWORD *)(v4 + 40) == ReadyQ )
{
if ( (unsigned int)func12(v4, (__int64 *)ReadyQ) )
func14(v5, (__int64 *)ReadyQ);
else
func7("Dequeue error\n");
}
}
return v2;
}

original_code:
T_RC ChangeThreadPriority(ThreadId tid, int newPriority) {
 TD * td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else {
  td = getTD(tid);
 }
 if ((newPriority < 1) & (newPriority > 128)) {
  return PRIORITY_ERROR;
 }
 td->priority = newPriority;
 if (td->inlist == ReadyQ){
  if (Dequeue(td, ReadyQ)) {
   PriorityEnqueue(td, ReadyQ);
  } else {
   myprint("Dequeue error\n");
  }
 }
 return OK;
}

canonical_original_code:
enum T_RC ChangeThreadPriority(unsigned int tid, int newPriority) {
 struct type_TD *td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else {
  td = getTD(tid);
 }
 if ((newPriority < 1) & (newPriority > 128)) {
  return PRIORITY_ERROR;
 }
 td->priority = newPriority;
 if (td->inlist == ReadyQ){
  if (Dequeue(td, ReadyQ)) {
   PriorityEnqueue(td, ReadyQ);
  } else {
   myprint("Dequeue error\n");
  }
 }
 return OK;
}

variable_types: newPriority int

return_type: enum T_RC { RESOURCE_ERROR=0, STACK_ERROR=1, PRIORITY_ERROR=2, TID_ERROR=3, NOT_BLOCKED=4, FAILED=5, OK=6 }


DestroyThread

decompiled_code:
__int64 __fastcall DestroyThread(int a1)
{
__int64 *v2; // rdi
char *v3; // rax

if ( !a1 || *(_DWORD *)(Active + 8) == a1 )
{
Active = 0LL;
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
}
v2 = FindTD(a1, (__int64 **)ReadyQ);
if ( !v2 )
{
v2 = FindTD(a1, (__int64 **)BlockedQ);
if ( !v2 )
return 3LL;
}
DequeueTD((__int64)v2);
v3 = CreateTD(a1);
EnqueueAtHead(v3, FreeQ);
return 6LL;
}

canonical_decompiled_code:
__int64 __fastcall func25(int a1)
{
__int64 *v2; // rdi
char *v3; // rax

if ( !a1 || *(_DWORD *)(Active + 8) == a1 )
{
Active = 0LL;
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
}
v2 = FindTD(a1, (__int64 **)ReadyQ);
if ( !v2 )
{
v2 = FindTD(a1, (__int64 **)BlockedQ);
if ( !v2 )
return 3LL;
}
func18((__int64)v2);
v3 = func8(a1);
func15(v3, FreeQ);
return 6LL;
}

original_code:
T_RC DestroyThread(ThreadId tid) {
 TD* td_tid;
 if (tid == 0 || tid == Active->tid) {
  Active = ((void *)0);
  Active = DequeueHead(ReadyQ);
 }
 if ((td_tid = FindTD(tid, ReadyQ)) == ((void *)0)) {
  if ((td_tid = FindTD(tid, BlockedQ)) == ((void *)0)) {
   return TID_ERROR;
  }
 }
 DequeueTD(td_tid);
 td_tid = CreateTD(tid);
 EnqueueAtHead(td_tid, FreeQ);
 return OK;
}

canonical_original_code:
enum T_RC DestroyThread(unsigned int tid) {
 struct type_TD *td_tid;
 if (tid == 0 || tid == Active->tid) {
  Active = ((void *)0);
  Active = DequeueHead(ReadyQ);
 }
 if ((td_tid = FindTD(tid, ReadyQ)) == ((void *)0)) {
  if ((td_tid = FindTD(tid, BlockedQ)) == ((void *)0)) {
   return TID_ERROR;
  }
 }
 DequeueTD(td_tid);
 td_tid = CreateTD(tid);
 EnqueueAtHead(td_tid, FreeQ);
 return OK;
}

user_defined_types: enum T_RC { RESOURCE_ERROR=0, STACK_ERROR=1, PRIORITY_ERROR=2, TID_ERROR=3, NOT_BLOCKED=4, FAILED=5, OK=6 }


Yield

decompiled_code:
__int64 Yield()
{
PriorityEnqueue(Active, (__int64 *)ReadyQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_decompiled_code:
__int64 func26()
{
func14(Active, (__int64 *)ReadyQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_original_code:
enum T_RC Yield() {
 PriorityEnqueue(Active, ReadyQ);
 Active = DequeueHead(ReadyQ);
 return OK;
}


InitKernel

decompiled_code:
__int64 InitKernel()
{
int v0; // ebx
char *v1; // rbp
char *v2; // rbp

v0 = 0;
ReadyQ = (__int64)CreateList(1);
BlockedQ = (__int64)CreateList(0);
FreeQ = (__int64)CreateList(4);
v1 = CreateTD(1);
InitTD(v1, (int)Idle, (int)&Kernel, 128);
PriorityEnqueue((__int64)v1, (__int64 *)ReadyQ);
do
{
v2 = CreateTD(++v0);
InitTD(v2, 0, 0, 0);
FreeQEnqueue(v2, (__int64 *)FreeQ);
}
while ( v0 != 1024 );
return Yield();
}

canonical_decompiled_code:
__int64 func27()
{
int v0; // ebx
char *v1; // rbp
char *v2; // rbp

v0 = 0;
ReadyQ = (__int64)CreateList(1);
BlockedQ = (__int64)CreateList(0);
FreeQ = (__int64)CreateList(4);
v1 = func8(1);
func9(v1, (int)Idle, (int)&Kernel, 128);
func14((__int64)v1, (__int64 *)ReadyQ);
do
{
v2 = func8(++v0);
func9(v2, 0, 0, 0);
func10(v2, (__int64 *)FreeQ);
}
while ( v0 != 1024 );
return func26();
}

original_code:
void InitKernel(void) {
 int i;
 ReadyQ = CreateList(L_PRIORITY);
 BlockedQ = CreateList(UNDEF);
 FreeQ = CreateList(L_CIRCULAR);
 TD* idle_td = CreateTD(1);
 InitTD(idle_td, (uval32) Idle, (uval32) &(KernelStack.stack[8192]), 128);
 PriorityEnqueue(idle_td, ReadyQ);
 for(i=0;i<1024;i++){
  TD* free_td;
  free_td = CreateTD(i+1);
  InitTD(free_td, 0,0,0);
  FreeQEnqueue(free_td, FreeQ);
 }
 Yield();
}

canonical_original_code:
void InitKernel() {
 int i;
 ReadyQ = CreateList(L_PRIORITY);
 BlockedQ = CreateList(UNDEF);
 FreeQ = CreateList(L_CIRCULAR);
 struct type_TD *idle_td = CreateTD(1);
 InitTD(idle_td, (unsigned int) Idle, (uval32) &(KernelStack.stack[8192]), 128);
 PriorityEnqueue(idle_td, ReadyQ);
 for(i=0;i<1024;i++){
  struct type_TD *free_td;
  free_td = CreateTD(i+1);
  InitTD(free_td, 0,0,0);
  FreeQEnqueue(free_td, FreeQ);
 }
 Yield();
}

variable_types: i int


CreateThread

decompiled_code:
__int64 __fastcall CreateThread(int a1, int a2, unsigned int a3)
{
unsigned int v5; // er12
int v7; // edi
char *v8; // rax
__int64 v9; // rdx

v5 = getTid();
if ( !v5 )
return v5;
if ( !malloc(0x2000uLL) )
return 1;
v7 = v5;
v5 = 6;
v8 = CreateTD(v7);
v9 = ReadyQ;
*((_DWORD *)v8 + 6) = a3;
*((_QWORD *)v8 + 5) = v9;
*((_DWORD *)v8 + 4) = a1;
*((_DWORD *)v8 + 3) = a2;
myprint("CreateThread ");
if ( *(_DWORD *)(Active + 24) >= a3 )
return v5;
Yield();
return 6LL;
}

canonical_decompiled_code:
__int64 __fastcall func28(int a1, int a2, unsigned int a3)
{
unsigned int v5; // er12
int v7; // edi
char *v8; // rax
__int64 v9; // rdx

v5 = func21();
if ( !v5 )
return v5;
if ( !malloc(0x2000uLL) )
return 1;
v7 = v5;
v5 = 6;
v8 = func8(v7);
v9 = ReadyQ;
*((_DWORD *)v8 + 6) = a3;
*((_QWORD *)v8 + 5) = v9;
*((_DWORD *)v8 + 4) = a1;
*((_DWORD *)v8 + 3) = a2;
func7("CreateThread ");
if ( *(_DWORD *)(Active + 24) >= a3 )
return v5;
func26();
return 6LL;
}

original_code:
T_RC CreateThread(uval32 pc, uval32 sp, uval32 priority) {
 int *ptr, tid;
 TD *thread;
 if ((priority < 1) & (priority > 128)) {
  return PRIORITY_ERROR;
 } else if (!(tid = getTid())) {
  return RESOURCE_ERROR;
 } else if ((ptr = malloc(8192)) == 0) {
  return STACK_ERROR;
 }
 thread = CreateTD(tid);
    thread->priority = priority;
    thread->inlist = ReadyQ;
    thread->regs.pc = pc;
    thread->regs.sp = sp;
 myprint("CreateThread ");
 if (priority > Active->priority) {
     Yield();
    }
 return OK;
}

canonical_original_code:
enum T_RC CreateThread(unsigned int pc, unsigned int sp, unsigned int priority) {
 int *ptr; int tid;
 struct type_TD *thread;
 if ((priority < 1) & (priority > 128)) {
  return PRIORITY_ERROR;
 } else if (!(tid = getTid())) {
  return RESOURCE_ERROR;
 } else if ((ptr = malloc(8192)) == 0) {
  return STACK_ERROR;
 }
 thread = CreateTD(tid);
    thread->priority = priority;
    thread->inlist = ReadyQ;
    thread->regs.pc = pc;
    thread->regs.sp = sp;
 myprint("CreateThread ");
 if (priority > Active->priority) {
     Yield();
    }
 return OK;
}

variable_types:
ptr
int *

variable_types: tid int


ResumeThread

decompiled_code:
__int64 __fastcall ResumeThread(int a1)
{
unsigned int v1; // er12
__int64 v3; // rax

v1 = 3;
if ( (unsigned int)tidInUse(a1) )
{
v3 = getTD(a1);
if ( v3 )
{
v1 = 4;
if ( *(_QWORD *)(v3 + 40) == BlockedQ )
{
v1 = 6;
*(_QWORD *)(v3 + 40) = ReadyQ;
if ( *(_DWORD *)(v3 + 24) > *(_DWORD *)(Active + 24) )
Yield();
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func29(int a1)
{
unsigned int v1; // er12
__int64 v3; // rax

v1 = 3;
if ( (unsigned int)func23(a1) )
{
v3 = func22(a1);
if ( v3 )
{
v1 = 4;
if ( *(_QWORD *)(v3 + 40) == BlockedQ )
{
v1 = 6;
*(_QWORD *)(v3 + 40) = ReadyQ;
if ( *(_DWORD *)(v3 + 24) > *(_DWORD *)(Active + 24) )
func26();
}
}
}
return v1;
}

original_code:
T_RC ResumeThread(ThreadId tid) {
 TD * td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else if ((td = getTD(tid)) == ((void *)0)) {
  return TID_ERROR;
 } else {
  if (td->inlist != BlockedQ) {
   return NOT_BLOCKED;
  } else {
   td->inlist = ReadyQ;
  }
  if (td->priority > Active->priority) {
   Yield();
  }
  return OK;
 }
}

canonical_original_code:
enum T_RC ResumeThread(unsigned int tid) {
 struct type_TD *td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else if ((td = getTD(tid)) == ((void *)0)) {
  return TID_ERROR;
 } else {
  if (td->inlist != BlockedQ) {
   return NOT_BLOCKED;
  } else {
   td->inlist = ReadyQ;
  }
  if (td->priority > Active->priority) {
   Yield();
  }
  return OK;
 }
}


Idle

decompiled_code:
void __noreturn Idle()
{
while ( 1 )
{
myprint("CPU is idle\n");
Yield();
}
}

canonical_decompiled_code:
void __noreturn func30()
{
while ( 1 )
{
func7("CPU is idle\n");
func26();
}
}

original_code:
void Idle() {
  int i;
  while( 1 )
  {
   myprint( "CPU is idle\n" );
   for( i = 0; i < 5; i++ )
   {
   }
   Yield();
  }
}


Suspend

decompiled_code:
__int64 Suspend()
{
EnqueueAtHead((_QWORD *)Active, BlockedQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_decompiled_code:
__int64 func31()
{
func15((_QWORD *)Active, BlockedQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_original_code:
enum T_RC Suspend() {
 EnqueueAtHead(Active, BlockedQ);
 Active = DequeueHead(ReadyQ);
 return OK;
}


decompiled_code:
int __fastcall K_SysCall(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
int result; // eax

switch ( a1 )
{
case 0u:
result = CreateThread(a2, a3, a4);
break;
case 1u:
result = DestroyThread(a2);
break;
case 2u:
result = Yield(a1, (unsigned int)a3, a3, a4, a2);
break;
case 3u:
result = Suspend(a1, (unsigned int)a3, a3, a4, a2);
break;
case 4u:
result = ResumeThread(a2);
break;
case 5u:
result = ChangeThreadPriority(a2, a3);
break;
default:
result = myprint("Invalid SysCall type\n");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func32(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
int result; // eax

switch ( a1 )
{
case 0u:
result = func28(a2, a3, a4);
break;
case 1u:
result = func25(a2);
break;
case 2u:
result = func26(a1, (unsigned int)a3, a3, a4, a2);
break;
case 3u:
result = func31(a1, (unsigned int)a3, a3, a4, a2);
break;
case 4u:
result = func29(a2);
break;
case 5u:
result = func24(a2, a3);
break;
default:
result = func7("Invalid SysCall type\n");
break;
}
return result;
}

original_code:
void K_SysCall(SysCallType type, uval32 arg0, uval32 arg1, uval32 arg2) {
 RC returnCode;
 switch (type) {
 case SYS_CREATE:
  returnCode = CreateThread(arg0, arg1, arg2);
  break;
 case SYS_DIST:
  returnCode = DestroyThread(arg0);
  break;
 case SYS_YIELD:
  returnCode = Yield();
  break;
 case SYS_SUSP:
  returnCode = Suspend();
  break;
 case SYS_RESUME:
  returnCode = ResumeThread((ThreadId)arg0);
  break;
 case SYS_CHANGE_PRI:
  returnCode = ChangeThreadPriority(arg0, arg1);
  break;
 default:
  myprint("Invalid SysCall type\n");
  returnCode = FAILED;
  break;
 }
}

canonical_original_code:
void K_SysCall(enum SysCallType type, unsigned int arg0, unsigned int arg1, unsigned int arg2) {
 enum RC returnCode;
 switch (type) {
 case SYS_CREATE:
  returnCode = CreateThread(arg0, arg1, arg2);
  break;
 case SYS_DIST:
  returnCode = DestroyThread(arg0);
  break;
 case SYS_YIELD:
  returnCode = Yield();
  break;
 case SYS_SUSP:
  returnCode = Suspend();
  break;
 case SYS_RESUME:
  returnCode = ResumeThread((unsigned int)arg0);
  break;
 case SYS_CHANGE_PRI:
  returnCode = ChangeThreadPriority(arg0, arg1);
  break;
 default:
  myprint("Invalid SysCall type\n");
  returnCode = FAILED;
  break;
 }
}

variable_types:
returnCode
enum RC { RC_SUCCESS=0, RC_FAILED=1 }

user_defined_types: enum SysCallType { SYS_CREATE=0, SYS_DIST=1, SYS_YIELD=2, SYS_SUSP=3, SYS_RESUME=4, SYS_CHANGE_PRI=5 }


decompiled_code:
void interrupt_handler()
{
;
}

canonical_decompiled_code:
void func33()
{
;
}

original_code:
void interrupt_handler(void)
{
}

canonical_original_code:
void interrupt_handler()
{
}


repo: upwhere/ccbor

decompiled_code:
__int64 __fastcall cbor_store_tag(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rbp
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 192;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rbp
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 192;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
static int cbor_store_tag(struct cbor_t*storage,const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_tag_t t= {
   .base= {
    .major=cbor_major_tag,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  },*fresh=malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  memcpy(fresh,&t,sizeof*fresh);
  storage->next=&(fresh->base);
  return 0;
 }
}

canonical_original_code:
static int cbor_store_tag(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_tag_t t = {
   .base= {
    .major=cbor_major_tag,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  }; struct cbor_tag_t *fresh = malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  memcpy(fresh,&t,sizeof*fresh);
  storage->next=&(fresh->base);
  return 0;
 }
}

variable_types: struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } *

variable_types:
additional
unsigned char

variable_types: stream int

variable_types: struct cbor_tag_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long value; } *

user_defined_types: struct cbor_tag_t { struct cbor_t base; unsigned long value; }

user_defined_types: struct cbor_t { enum cbor_major_t major; struct cbor_t *next; }


decompiled_code:
char __fastcall cbor_major_of(unsigned __int8 a1)
{
return a1 >> 5;
}

canonical_decompiled_code:
char __fastcall func1(unsigned __int8 a1)
{
return a1 >> 5;
}

original_code:
uint8_t cbor_major_of(uint8_t item)
{
 return (item& (cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt))>>5;
}

canonical_original_code:
unsigned char cbor_major_of(unsigned char item)
{
 return (item& (cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt))>>5;
}

variable_types:
item
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall cbor_additional_of(char a1)
{
return a1 & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return a1 & 0x1F;
}

original_code:
uint8_t cbor_additional_of(uint8_t item)
{
 return item& ~(cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt);
}

canonical_original_code:
unsigned char cbor_additional_of(unsigned char item)
{
 return item& ~(cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt);
}


decompiled_code:
void __fastcall recursive_naive_cbor_free(void *ptr)
{
if ( ptr )
{
recursive_naive_cbor_free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
func3(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void recursive_naive_cbor_free(struct cbor_t*listitem)
{
 if(listitem==((void *)0))return;
 recursive_naive_cbor_free(listitem->next);
 free(listitem);
 return;
}

canonical_original_code:
void recursive_naive_cbor_free(struct cbor_t *listitem)
{
 if(listitem==((void *)0))return;
 recursive_naive_cbor_free(listitem->next);
 free(listitem);
 return;
}

user_defined_types: enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr }


decode

decompiled_code:
__int64 __fastcall decode(int fd, __int64 a2)
{
__int64 v3; // rbx
char v4; // di
unsigned __int8 v5; // al
unsigned __int8 v6; // dl
__int64 result; // rax
unsigned __int8 buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = a2;
if ( !a2 )
return 2LL;
while ( 1 )
{
buf[0] = 0;
if ( read(fd, buf, 1uLL) <= 0 )
break;
v4 = buf[0];
cbor_major_of(buf[0]);
v5 = cbor_additional_of(v4);
result = (*(&cbor_store + v6))(v3, v5, (unsigned int)fd);
if ( (_DWORD)result )
return result;
if ( v3 )
v3 = *(_QWORD *)(v3 + 8);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2)
{
__int64 v3; // rbx
char v4; // di
unsigned __int8 v5; // al
unsigned __int8 v6; // dl
__int64 result; // rax
unsigned __int8 buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = a2;
if ( !a2 )
return 2LL;
while ( 1 )
{
buf[0] = 0;
if ( read(fd, buf, 1uLL) <= 0 )
break;
v4 = buf[0];
func1(buf[0]);
v5 = func2(v4);
result = (*(&cbor_store + v6))(v3, v5, (unsigned int)fd);
if ( (_DWORD)result )
return result;
if ( v3 )
v3 = *(_QWORD *)(v3 + 8);
}
return 0LL;
}

original_code:
int decode(const int stream,struct cbor_t*storage)
{
 if(storage==((void *)0))return 2;
 {
  int store_status=0;
  struct cbor_t*store=storage;
  do
  {
   uint8_t item=0;
   if(read(stream,&item,sizeof item) < 1 )
   {
    break;
   }
   store_status=cbor_store[cbor_major_of(item)](store,cbor_additional_of(item),stream);
   if(store_status!=0)
   {
    return store_status;
   }
   if(store!=((void *)0))store=store->next;
  }
  while(1);
  return 0;
 }
}

canonical_original_code:
int decode(int stream, struct cbor_t *storage)
{
 if(storage==((void *)0))return 2;
 {
  int store_status = 0;
  struct cbor_t *store = storage;
  do
  {
   unsigned char item = 0;
   if(read(stream,&item,sizeof item) < 1 )
   {
    break;
   }
   store_status=cbor_store[cbor_major_of(item)](store,cbor_additional_of(item),stream);
   if(store_status!=0)
   {
    return store_status;
   }
   if(store!=((void *)0))store=store->next;
  }
  while(1);
  return 0;
 }
}


decompiled_code:
__int16 __fastcall be16to_h(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static uint16_t be16to_h(const uint16_t bigendian)
{
 return ((bigendian&0x00ff) <<8) |
  ((bigendian&0xff00) >>8);
 return bigendian;
}

canonical_original_code:
static unsigned short be16to_h(unsigned short bigendian)
{
 return ((bigendian&0x00ff) <<8) |
  ((bigendian&0xff00) >>8);
 return bigendian;
}

variable_types:
bigendian
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall be32to_h(unsigned int a1)
{
return _byteswap_ulong(a1);
}

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

original_code:
static uint32_t be32to_h(const uint32_t bigendian)
{
 return ((bigendian&0x000000ff) <<24) |
  ((bigendian&0x0000ff00) <<8) |
  ((bigendian&0x00ff0000) >>8) |
  ((bigendian&0xff000000) >>24);
 return bigendian;
}

canonical_original_code:
static unsigned int be32to_h(unsigned int bigendian)
{
 return ((bigendian&0x000000ff) <<24) |
  ((bigendian&0x0000ff00) <<8) |
  ((bigendian&0x00ff0000) >>8) |
  ((bigendian&0xff000000) >>24);
 return bigendian;
}

variable_types:
bigendian
unsigned int


decompiled_code:
unsigned __int64 __fastcall be64to_h(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

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

variable_types:
bigendian
unsigned long

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall cbor_value_uint(unsigned __int8 a1, int a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 buf[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
switch ( a1 )
{
case 0x18u:
read(a2, &v3, 1uLL);
result = v3;
break;
case 0x19u:
LOWORD(buf[0]) = 0;
read(a2, buf, 2uLL);
result = (unsigned __int16)be16to_h(buf[0]);
break;
case 0x1Au:
LODWORD(buf[0]) = 0;
read(a2, buf, 4uLL);
result = (unsigned int)be32to_h(buf[0]);
break;
case 0x1Bu:
buf[0] = 0LL;
read(a2, buf, 8uLL);
result = be64to_h(buf[0]);
break;
case 0x1Cu:
case 0x1Eu:
case 0x1Fu:
result = 0LL;
break;
default:
result = a1;
break;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int8 a1, int a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 buf[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
switch ( a1 )
{
case 0x18u:
read(a2, &v3, 1uLL);
result = v3;
break;
case 0x19u:
LOWORD(buf[0]) = 0;
read(a2, buf, 2uLL);
result = (unsigned __int16)func0(buf[0]);
break;
case 0x1Au:
LODWORD(buf[0]) = 0;
read(a2, buf, 4uLL);
result = (unsigned int)func1(buf[0]);
break;
case 0x1Bu:
buf[0] = 0LL;
read(a2, buf, 8uLL);
result = func2(buf[0]);
break;
case 0x1Cu:
case 0x1Eu:
case 0x1Fu:
result = 0LL;
break;
default:
result = a1;
break;
}
return result;
}

original_code:
uint64_t cbor_value_uint(const uint8_t additional,const int stream)
{
 uint64_t v=0;
 switch(additional) {
  default:
   return additional;
  case 24:
   (void)read(stream,&v,sizeof(uint8_t));
   break;
  case 25:
  {
   uint16_t v16=0;
   (void)read(stream,&v16,sizeof(uint16_t));
   v=be16to_h(v16);
   break;
  }
  case 26:
  {
   uint32_t v32=0;
   (void)read(stream,&v32,sizeof(uint32_t));
   v=be32to_h(v32);
   break;
  }
  case 27:
  {
   uint64_t v64=0;
   (void)read(stream,&v64,sizeof(uint64_t));
   v=be64to_h(v64);
   break;
  }
  case 28:
  case 30:
  case 31:
   break;
 }
 return v;
}

canonical_original_code:
unsigned long cbor_value_uint(unsigned char additional, int stream)
{
 unsigned long v = 0;
 switch(additional) {
  default:
   return additional;
  case 24:
   (void)read(stream,&v,sizeof(unsigned char));
   break;
  case 25:
  {
   unsigned short v16 = 0;
   (void)read(stream,&v16,sizeof(unsigned short));
   v=be16to_h(v16);
   break;
  }
  case 26:
  {
   unsigned int v32 = 0;
   (void)read(stream,&v32,sizeof(unsigned int));
   v=be32to_h(v32);
   break;
  }
  case 27:
  {
   unsigned long v64 = 0;
   (void)read(stream,&v64,sizeof(unsigned long));
   v=be64to_h(v64);
   break;
  }
  case 28:
  case 30:
  case 31:
   break;
 }
 return v;
}

variable_types:
v
unsigned long


decompiled_code:
__int64 __fastcall cbor_store_uint(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
unsigned __int64 v4; // rbp
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 0;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
unsigned __int64 v4; // rbp
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = func3(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 0;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int cbor_store_uint(struct cbor_t*storage,const uint8_t additional,const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_uint_t c= {
   .base= {
    .major=cbor_major_uint,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  },*fresh=malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  memcpy(fresh,&c,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

canonical_original_code:
int cbor_store_uint(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_uint_t c = {
   .base= {
    .major=cbor_major_uint,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  }; struct cbor_uint_t *fresh = malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  memcpy(fresh,&c,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

variable_types: struct cbor_uint_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long value; } *

user_defined_types: struct cbor_uint_t { struct cbor_t base; unsigned long value; }


decompiled_code:
__int64 __fastcall cbor_store_nint(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
unsigned __int64 v4; // r12
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
if ( v4 == -1LL && a2 != 1 )
{
free(v5);
result = 3LL;
}
else
{
*(_DWORD *)v5 = 32;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
unsigned __int64 v4; // r12
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = func3(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
if ( v4 == -1LL && a2 != 1 )
{
free(v5);
result = 3LL;
}
else
{
*(_DWORD *)v5 = 32;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int cbor_store_nint(struct cbor_t*storage,const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_nint_t n= {
   .base= {
    .major=cbor_major_nint,
    .next=((void *)0),
   },
   .nvalue=cbor_value_uint(additional,stream),
  },*fresh=malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  if(n.nvalue==(uint64_t)-1&&additional!=1)
  {
   free(fresh);
   return 3;
  }
  memcpy(fresh,&n,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

canonical_original_code:
int cbor_store_nint(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_nint_t n = {
   .base= {
    .major=cbor_major_nint,
    .next=((void *)0),
   },
   .nvalue=cbor_value_uint(additional,stream),
  }; struct cbor_nint_t *fresh = malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  if(n.nvalue==(unsigned long)-1&&additional!=1)
  {
   free(fresh);
   return 3;
  }
  memcpy(fresh,&n,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

variable_types: struct cbor_nint_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long nvalue; } *

user_defined_types: struct cbor_nint_t { struct cbor_t base; unsigned long nvalue; }


decompiled_code:
__int64 __fastcall cbor_store_mapentry(_QWORD *a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 (__fastcall *v5)(int *, _QWORD, _QWORD); // r13
unsigned __int8 v6; // al
ssize_t v7; // r8
__int64 v8; // r13
__int64 (__fastcall *v9)(__int64, _QWORD, _QWORD); // rbp
unsigned __int8 v10; // al
__int64 v11; // rcx
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v13; // [rsp+2h] [rbp-38h] BYREF
__int64 v14; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
result = 3LL;
if ( a2 != 0xFF )
{
v13 = 255;
v14 = 0LL;
buf = 0;
v5 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(a2));
v6 = cbor_additional_of(a2);
result = v5(&v13, v6, a3);
if ( !(_DWORD)result )
{
result = 2LL;
if ( v14 )
{
v7 = read(a3, &buf, 1uLL);
result = 3LL;
if ( v7 > 0 && buf != 0xFF )
{
v8 = v14;
v9 = *(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v10 = cbor_additional_of(buf);
result = v9(v8, v10, a3);
if ( !(_DWORD)result )
{
v11 = *(_QWORD *)(v14 + 8);
*a1 = v14;
a1[1] = v11;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 (__fastcall *v5)(int *, _QWORD, _QWORD); // r13
unsigned __int8 v6; // al
ssize_t v7; // r8
__int64 v8; // r13
__int64 (__fastcall *v9)(__int64, _QWORD, _QWORD); // rbp
unsigned __int8 v10; // al
__int64 v11; // rcx
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v13; // [rsp+2h] [rbp-38h] BYREF
__int64 v14; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
result = 3LL;
if ( a2 != 0xFF )
{
v13 = 255;
v14 = 0LL;
buf = 0;
v5 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(a2));
v6 = cbor_additional_of(a2);
result = v5(&v13, v6, a3);
if ( !(_DWORD)result )
{
result = 2LL;
if ( v14 )
{
v7 = read(a3, &buf, 1uLL);
result = 3LL;
if ( v7 > 0 && buf != 0xFF )
{
v8 = v14;
v9 = *(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v10 = cbor_additional_of(buf);
result = v9(v8, v10, a3);
if ( !(_DWORD)result )
{
v11 = *(_QWORD *)(v14 + 8);
*a1 = v14;
a1[1] = v11;
}
}
}
}
}
return result;
}

original_code:
static int cbor_store_mapentry( struct cbor_mapentry_t*storage,const uint8_t key,const int stream)
{
 if(storage==((void *)0))return 2;
 if(key==0xff)return 3;
 {
  struct cbor_t head= {
   .major=0xFF,
   .next=((void *)0),
  };
  struct cbor_t*pair=&head;
  int store_attempt_ret;
  uint8_t item=0;
  if( (store_attempt_ret=cbor_store[cbor_major_of(key) ] (pair,cbor_additional_of(key),stream) ) !=0)return store_attempt_ret;
  if(pair->next==((void *)0))return 2;
  if(read(stream,&item,sizeof item) < (ssize_t) sizeof item)return 3;
  if(item==0xff)
  {
   store_attempt_ret=3;
   goto free;
  }
  pair=pair->next;
  if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (pair,cbor_additional_of(item) ,stream) ) !=0)goto free;
  pair=&head;
  {
   struct cbor_mapentry_t e= {
    .key=pair->next,
    .value=pair->next->next,
   };
   memcpy(storage,&e,sizeof*storage);
  }
  return 0;free:
  {
   return store_attempt_ret;
  }
 }
}

canonical_original_code:
static int cbor_store_mapentry(struct cbor_mapentry_t *storage, unsigned char key, int stream)
{
 if(storage==((void *)0))return 2;
 if(key==0xff)return 3;
 {
  struct cbor_t head = {
   .major=0xFF,
   .next=((void *)0),
  };
  struct cbor_t *pair = &head;
  int store_attempt_ret;
  unsigned char item = 0;
  if( (store_attempt_ret=cbor_store[cbor_major_of(key) ] (pair,cbor_additional_of(key),stream) ) !=0)return store_attempt_ret;
  if(pair->next==((void *)0))return 2;
  if(read(stream,&item,sizeof item) < (long) sizeof item)return 3;
  if(item==0xff)
  {
   store_attempt_ret=3;
   goto free;
  }
  pair=pair->next;
  if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (pair,cbor_additional_of(item) ,stream) ) !=0)goto free;
  pair=&head;
  {
   struct cbor_mapentry_t e = {
    .key=pair->next,
    .value=pair->next->next,
   };
   memcpy(storage,&e,sizeof*storage);
  }
  return 0;free:
  {
   return store_attempt_ret;
  }
 }
}

variable_types: struct cbor_mapentry_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } *key; struct cbor_t *value; } *

variable_types:
key
unsigned char

user_defined_types: struct cbor_mapentry_t { struct cbor_t *key; struct cbor_t *value; }


decompiled_code:
__int64 __fastcall cbor_store_definite_arr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // r12
void *v6; // r13
__int64 v7; // rbx
__int64 (__fastcall *v8)(int *, _QWORD, _QWORD); // r15
unsigned __int8 v9; // al
unsigned int v10; // eax
_QWORD *v11; // rax
unsigned int v12; // [rsp+0h] [rbp-5Ch]
unsigned __int8 buf; // [rsp+13h] [rbp-49h] BYREF
int v14; // [rsp+14h] [rbp-48h] BYREF
__int64 v15; // [rsp+1Ch] [rbp-40h]

if ( !a1 )
return 2LL;
result = 2LL;
if ( *(_QWORD *)(a1 + 8) )
return result;
v5 = cbor_value_uint(a2, a3);
v14 = 255;
v15 = 0LL;
v6 = malloc(8 * v5);
if ( v6 )
{
v7 = 0LL;
if ( v5 )
{
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
break;
v8 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v9 = cbor_additional_of(buf);
v10 = v8(&v14, v9, a3);
if ( v10 )
{
v12 = v10;
free(v6);
return v12;
}
if ( !v15 )
{
free(v6);
return 2LL;
}
*((_QWORD *)v6 + v7++) = v15;
v15 = 0LL;
if ( v5 == v7 )
goto LABEL_12;
}
}
else
{
LABEL_12:
v11 = malloc(0x20uLL);
if ( v11 )
{
*(_DWORD *)v11 = 128;
v11[1] = 0LL;
v11[2] = v5;
v11[3] = v6;
*(_QWORD *)(a1 + 8) = v11;
return 0LL;
}
}
free(v6);
return 1LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // r12
void *v6; // r13
__int64 v7; // rbx
__int64 (__fastcall *v8)(int *, _QWORD, _QWORD); // r15
unsigned __int8 v9; // al
unsigned int v10; // eax
_QWORD *v11; // rax
unsigned int v12; // [rsp+0h] [rbp-5Ch]
unsigned __int8 buf; // [rsp+13h] [rbp-49h] BYREF
int v14; // [rsp+14h] [rbp-48h] BYREF
__int64 v15; // [rsp+1Ch] [rbp-40h]

if ( !a1 )
return 2LL;
result = 2LL;
if ( *(_QWORD *)(a1 + 8) )
return result;
v5 = cbor_value_uint(a2, a3);
v14 = 255;
v15 = 0LL;
v6 = malloc(8 * v5);
if ( v6 )
{
v7 = 0LL;
if ( v5 )
{
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
break;
v8 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v9 = cbor_additional_of(buf);
v10 = v8(&v14, v9, a3);
if ( v10 )
{
v12 = v10;
free(v6);
return v12;
}
if ( !v15 )
{
free(v6);
return 2LL;
}
*((_QWORD *)v6 + v7++) = v15;
v15 = 0LL;
if ( v5 == v7 )
goto LABEL_12;
}
}
else
{
LABEL_12:
v11 = malloc(0x20uLL);
if ( v11 )
{
*(_DWORD *)v11 = 128;
v11[1] = 0LL;
v11[2] = v5;
v11[3] = v6;
*(_QWORD *)(a1 + 8) = v11;
return 0LL;
}
}
free(v6);
return 1LL;
}
return 1LL;
}

original_code:
static int cbor_store_definite_arr(struct cbor_t*storage, const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  const size_t length=cbor_value_uint(additional,stream);
  struct cbor_t **array = malloc(length*sizeof(struct cbor_t const *));
  struct cbor_t head= {
   .major=0xFF,
   .next=((void *)0),
  } , *element= &head;
  int store_status;
  size_t i;
  if(array==((void *)0))
  {
   return 1;
  }
  for(i=0;i<length;i++)
  {
   uint8_t item=0;
   if(read(stream,&item,sizeof item)<(ssize_t)sizeof item)
   {
    free(array);
    return 1;
   }
   if((store_status=cbor_store[cbor_major_of(item)](element,cbor_additional_of(item),stream))!=0)
   {
    free(array);
    return store_status;
   }
   if(element->next==((void *)0))
   {
    free(array);
    return 2;
   }
   array[i]=element->next;
   element->next=((void *)0);
  }
  {
   struct cbor_arr_t a= {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=length,
    .array=array,
   } , *fresh= malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(array);
    return 1;
   }
   memcpy(fresh, &a,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

canonical_original_code:
static int cbor_store_definite_arr(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  unsigned long length = cbor_value_uint(additional,stream);
  struct cbor_t **array = malloc(length*sizeof(struct cbor_t const *));
  struct cbor_t head = {
   .major=0xFF,
   .next=((void *)0),
  }; struct cbor_t *element = &head;
  int store_status;
  unsigned long i;
  if(array==((void *)0))
  {
   return 1;
  }
  for(i=0;i<length;i++)
  {
   unsigned char item = 0;
   if(read(stream,&item,sizeof item)<(long)sizeof item)
   {
    free(array);
    return 1;
   }
   if((store_status=cbor_store[cbor_major_of(item)](element,cbor_additional_of(item),stream))!=0)
   {
    free(array);
    return store_status;
   }
   if(element->next==((void *)0))
   {
    free(array);
    return 2;
   }
   array[i]=element->next;
   element->next=((void *)0);
  }
  {
   struct cbor_arr_t a = {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=length,
    .array=array,
   }; struct cbor_arr_t *fresh = malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(array);
    return 1;
   }
   memcpy(fresh, &a,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

variable_types:
length
unsigned long

variable_types: struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } **

variable_types:
i
unsigned long

variable_types: struct cbor_arr_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long length; struct cbor_t **array; } *

user_defined_types: struct cbor_arr_t { struct cbor_t base; unsigned long length; struct cbor_t **array; }


decompiled_code:
__int64 __fastcall cbor_store_arr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
int *v4; // rbx
__int64 v5; // rbp
__int64 (__fastcall *v6)(int *, _QWORD, _QWORD); // r14
unsigned __int8 v7; // al
__int64 result; // rax
__int64 *v9; // r12
__int64 v10; // rax
__int64 *v11; // rdx
_QWORD *v12; // rax
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v14; // [rsp+2h] [rbp-38h] BYREF
__int64 v15; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
if ( *(_QWORD *)(a1 + 8) )
return 2LL;
if ( a2 != 31 )
return cbor_store_definite_arr(a1, a2, a3);
v14 = 255;
v4 = &v14;
v5 = 0LL;
v15 = 0LL;
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
v6 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v7 = cbor_additional_of(buf);
result = v6(v4, v7, a3);
if ( (_DWORD)result )
return result;
v4 = (int *)*((_QWORD *)v4 + 1);
++v5;
}
v9 = (__int64 *)malloc(8 * v5);
if ( !v9 )
return 1LL;
v10 = v15;
if ( v15 )
{
v11 = v9;
do
{
*v11 = v10;
v10 = *(_QWORD *)(v10 + 8);
++v11;
}
while ( v10 );
}
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 128;
v12[1] = 0LL;
v12[2] = v5;
v12[3] = v9;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(v9);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
int *v4; // rbx
__int64 v5; // rbp
__int64 (__fastcall *v6)(int *, _QWORD, _QWORD); // r14
unsigned __int8 v7; // al
__int64 result; // rax
__int64 *v9; // r12
__int64 v10; // rax
__int64 *v11; // rdx
_QWORD *v12; // rax
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v14; // [rsp+2h] [rbp-38h] BYREF
__int64 v15; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
if ( *(_QWORD *)(a1 + 8) )
return 2LL;
if ( a2 != 31 )
return func0(a1, a2, a3);
v14 = 255;
v4 = &v14;
v5 = 0LL;
v15 = 0LL;
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
v6 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v7 = cbor_additional_of(buf);
result = v6(v4, v7, a3);
if ( (_DWORD)result )
return result;
v4 = (int *)*((_QWORD *)v4 + 1);
++v5;
}
v9 = (__int64 *)malloc(8 * v5);
if ( !v9 )
return 1LL;
v10 = v15;
if ( v15 )
{
v11 = v9;
do
{
*v11 = v10;
v10 = *(_QWORD *)(v10 + 8);
++v11;
}
while ( v10 );
}
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 128;
v12[1] = 0LL;
v12[2] = v5;
v12[3] = v9;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(v9);
result = 1LL;
}
return result;
}

original_code:
int cbor_store_arr(struct cbor_t*storage,const uint8_t additional,const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 if(additional!=cbor_additional_indefinite)
 {
  return cbor_store_definite_arr(storage,additional,stream);
 }
 {
  size_t total_length=0;
  struct cbor_t head= {
   .major=0xFF,
   .next=((void *)0),
  } , *element= &head;
  struct cbor_t**assembled,**assembled_index;
  while(1)
  {
   uint8_t item=0;
   int store_attempt_ret;
   if(read(stream,&item,sizeof item) < (ssize_t) sizeof item)return 3;
   if(item==0xff)break;
   if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (element,cbor_additional_of(item) ,stream) ) !=0)
   {
    return store_attempt_ret;
   }
   element=element->next;
   total_length++;
  }
  if( (assembled=malloc(total_length* (sizeof(struct cbor_t const * ) ) ) ) ==((void *)0))return 1;
  element= &head;
  assembled_index= assembled;
  while( (element=element->next) !=((void *)0))
  {
   *assembled_index= element;
   assembled_index++;
  }
  {
   struct cbor_arr_t a= {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=total_length,
    .array=assembled,
   } , *fresh= malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(assembled);
    return 1;
   }
   memcpy(fresh, &a,sizeof*fresh);
   storage->next=&fresh->base;
  }
 }
 return 0;
}

canonical_original_code:
int cbor_store_arr(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 if(additional!=cbor_additional_indefinite)
 {
  return cbor_store_definite_arr(storage,additional,stream);
 }
 {
  unsigned long total_length = 0;
  struct cbor_t head = {
   .major=0xFF,
   .next=((void *)0),
  }; struct cbor_t *element = &head;
  struct cbor_t **assembled; struct cbor_t **assembled_index;
  while(1)
  {
   unsigned char item = 0;
   int store_attempt_ret;
   if(read(stream,&item,sizeof item) < (long) sizeof item)return 3;
   if(item==0xff)break;
   if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (element,cbor_additional_of(item) ,stream) ) !=0)
   {
    return store_attempt_ret;
   }
   element=element->next;
   total_length++;
  }
  if( (assembled=malloc(total_length* (sizeof(struct cbor_t * ) ) ) ) ==((void *)0))return 1;
  element= &head;
  assembled_index= assembled;
  while( (element=element->next) !=((void *)0))
  {
   *assembled_index= element;
   assembled_index++;
  }
  {
   struct cbor_arr_t a = {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=total_length,
    .array=assembled,
   }; struct cbor_arr_t *fresh = malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(assembled);
    return 1;
   }
   memcpy(fresh, &a,sizeof*fresh);
   storage->next=&fresh->base;
  }
 }
 return 0;
}

variable_types: struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } *

variable_types: struct cbor_arr_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long length; struct cbor_t **array; }