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

if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 && a3(a2, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = *(_QWORD *)(v4 + 16);
if ( v4 != v5 )
{
while ( !a3(a2, v5) )
{
v5 = *(_QWORD *)(v5 + 16);
if ( *(_QWORD *)(a1 + 8) == v5 )
goto LABEL_9;
}
list_insert_after((_DWORD *)a1, v5, a2);
}
LABEL_9:
result = 0LL;
}
else
{
list_insert_tail(a1, a2);
result = 0LL;
}
return result;
}

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

if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 && a3(a2, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = *(_QWORD *)(v4 + 16);
if ( v4 != v5 )
{
while ( !a3(a2, v5) )
{
v5 = *(_QWORD *)(v5 + 16);
if ( *(_QWORD *)(a1 + 8) == v5 )
goto LABEL_9;
}
func3((_DWORD *)a1, v5, a2);
}
LABEL_9:
result = 0LL;
}
else
{
func5(a1, a2);
result = 0LL;
}
return result;
}

original_code:
int list_sort_insert(list_t *lst, node_t *node, int (*cmp_fn)(node_t *, node_t *))
{
 node_t *iter;
 if (node == ((void *)0))
  return -1;
 if (lst->node_cnt == 0)
  list_insert_tail(lst, node);
 else if (!cmp_fn(node, ((lst)->node_cnt ? (lst)->head->prev : ((void *)0))))
  list_insert_tail(lst, node);
 else {
  for(iter = (lst)->head->next; iter != (lst)->head ; iter = iter->next) {
   if (cmp_fn(node, iter)) {
    list_insert_after(lst, iter, node);
    break;
   }
  }
 }
 return 0;
}

canonical_original_code:
int list_sort_insert(struct list *lst, struct list_node *node, int (*cmp_fn)(struct list_node *, struct list_node *))
{
 struct list_node *iter;
 if (node == ((void *)0))
  return -1;
 if (lst->node_cnt == 0)
  list_insert_tail(lst, node);
 else if (!cmp_fn(node, ((lst)->node_cnt ? (lst)->head->prev : ((void *)0))))
  list_insert_tail(lst, node);
 else {
  for(iter = (lst)->head->next; iter != (lst)->head ; iter = iter->next) {
   if (cmp_fn(node, iter)) {
    list_insert_after(lst, iter, node);
    break;
   }
  }
 }
 return 0;
}

variable_types: int (*)(struct list_node *, struct list_node *)


repo: Jery-Mong/huffman

decompiled_code:
__int64 __fastcall match_item(void *s2)
{
__int64 v1; // rax
int v2; // ebp
unsigned __int8 *v3; // rbx
size_t v4; // rbp
unsigned int v5; // er12

v1 = *(char *)s2;
v2 = v1 + 7;
v3 = (unsigned __int8 *)level_idx_tb[v1];
if ( (int)v1 >= 0 )
v2 = *(char *)s2;
v4 = (v2 >> 3) + 2;
do
{
v5 = *v3;
if ( (_BYTE)v5 == 0xFF )
break;
++v3;
}
while ( memcmp(*(&map_tb + (char)v5), s2, v4) );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *s2)
{
__int64 v1; // rax
int v2; // ebp
unsigned __int8 *v3; // rbx
size_t v4; // rbp
unsigned int v5; // er12

v1 = *(char *)s2;
v2 = v1 + 7;
v3 = (unsigned __int8 *)level_idx_tb[v1];
if ( (int)v1 >= 0 )
v2 = *(char *)s2;
v4 = (v2 >> 3) + 2;
do
{
v5 = *v3;
if ( (_BYTE)v5 == 0xFF )
break;
++v3;
}
while ( memcmp(*(&map_tb + (char)v5), s2, v4) );
return v5;
}

original_code:
char match_item(char *code)
{
 int idx;
 int i = 0;
 int level = code[0];
 while ((idx = level_idx_tb[level][i++]) != -1) {
  if (!memcmp(map_tb[idx], code, level / 8 + 2))
   return idx;
 }
 return -1;
}

variable_types:
code
char *

variable_types: idx int

variable_types: i int

variable_types: level int

return_type: char


decompiled_code:
void *make_level_idx_table()
{
__int64 i; // rbp
__int64 v1; // rax
int v2; // ebx
char *v3; // rdx
__int64 v4; // rdx
void *v6; // rax
void *v7; // rax
void *result; // rax
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

for ( i = 1LL; i != 128; ++i )
{
v1 = 128LL;
v2 = 0;
do
{
v3 = (char *)*(&map_tb + v1);
if ( v3 )
{
if ( *v3 == (_DWORD)i )
{
v4 = v2++;
v9[v4] = v1;
}
}
}
while ( v1-- != 0 );
v6 = malloc(v2 + 1);
level_idx_tb[i] = (__int64)v6;
v7 = memset(v6, -1, v2 + 1);
result = memcpy(v7, v9, v2);
}
return result;
}

canonical_decompiled_code:
void *func8()
{
__int64 i; // rbp
__int64 v1; // rax
int v2; // ebx
char *v3; // rdx
__int64 v4; // rdx
void *v6; // rax
void *v7; // rax
void *result; // rax
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

for ( i = 1LL; i != 128; ++i )
{
v1 = 128LL;
v2 = 0;
do
{
v3 = (char *)*(&map_tb + v1);
if ( v3 )
{
if ( *v3 == (_DWORD)i )
{
v4 = v2++;
v9[v4] = v1;
}
}
}
while ( v1-- != 0 );
v6 = malloc(v2 + 1);
level_idx_tb[i] = (__int64)v6;
v7 = memset(v6, -1, v2 + 1);
result = memcpy(v7, v9, v2);
}
return result;
}

original_code:
void make_level_idx_table()
{
 int i, j;
 int level_cnt;
 char tp[128];
 for (i = 1; i < 128; i++) {
  for (j = 128, level_cnt = 0; j >= 0 ; --j) {
   if (map_tb[j] == (void *)0)
    continue;
   if (map_tb[j][0] == i)
    tp[level_cnt++] = j;
  }
  level_idx_tb[i] = (char *)malloc(level_cnt + 1);
  memset(level_idx_tb[i], -1, level_cnt + 1);
  memcpy(level_idx_tb[i], tp, level_cnt);
 }
}

canonical_original_code:
void make_level_idx_table()
{
 int i; int j;
 int level_cnt;
 char tp[128];
 for (i = 1; i < 128; i++) {
  for (j = 128, level_cnt = 0; j >= 0 ; --j) {
   if (map_tb[j] == (void *)0)
    continue;
   if (map_tb[j][0] == i)
    tp[level_cnt++] = j;
  }
  level_idx_tb[i] = (char *)malloc(level_cnt + 1);
  memset(level_idx_tb[i], -1, level_cnt + 1);
  memcpy(level_idx_tb[i], tp, level_cnt);
 }
}

variable_types: j int

variable_types:
tp
char [128]

return_type: void


decompiled_code:
__int64 find_min_level()
{
unsigned int v0; // er8
__int64 *v1; // rax

v0 = *(char *)map_tb;
v1 = (__int64 *)&unk_4040C8;
do
{
if ( *v1 && (int)v0 > *(char *)*v1 )
v0 = *(char *)*v1;
++v1;
}
while ( v1 != level_idx_tb );
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er8
__int64 *v1; // rax

v0 = *(char *)map_tb;
v1 = (__int64 *)&unk_4040C8;
do
{
if ( *v1 && (int)v0 > *(char *)*v1 )
v0 = *(char *)*v1;
++v1;
}
while ( v1 != level_idx_tb );
return v0;
}

original_code:
int find_min_level()
{
 int i;
 int min;
 min = map_tb[0][0];
 for (i = 1; i < 128; i++) {
  if (map_tb[i] != (void *)0) {
   if (map_tb[i][0] < min)
    min = map_tb[i][0];
  }
 }
 return min;
}

variable_types: min int

return_type: int


repo: Jery-Mong/snake

decompiled_code:
int paint_apple()
{
int *v0; // rbx
int v1; // esi
int v2; // edx
int result; // eax

v0 = &apple;
do
{
v1 = v0[1];
v2 = *v0;
v0 += 2;
wmove(game_erea, v1, v2);
result = waddch(game_erea, 0x40041uLL);
}
while ( v0 != &apple + 6 );
return result;
}

canonical_decompiled_code:
int func0()
{
int *v0; // rbx
int v1; // esi
int v2; // edx
int result; // eax

v0 = &apple;
do
{
v1 = v0[1];
v2 = *v0;
v0 += 2;
wmove(game_erea, v1, v2);
result = waddch(game_erea, 0x40041uLL);
}
while ( v0 != &apple + 6 );
return result;
}

original_code:
void paint_apple()
{
 int i;
 for (i = 0; i < 3; i++) {
  wmove(game_erea, apple[i].y, apple[i].x);
  waddch(game_erea, 'A' | ((chtype)((1U)) << ((10) + 8)));
 }
}


decompiled_code:
void __fastcall paint_seg(__int64 a1)
{
__int64 v1; // rbx
int v2; // er12
int v3; // ebp
int v4; // eax
int v5; // er13
int v6; // er14
int v7; // edx
int v8; // esi
unsigned int v9; // er13
int v10; // edx
unsigned int v11; // er13
int v12; // esi

if ( a1 )
{
v1 = a1;
while ( 1 )
{
if ( !*(_DWORD *)(v1 + 12) )
{
if ( snake_head != v1 )
return;
goto LABEL_4;
}
v2 = *(_DWORD *)v1;
v3 = *(_DWORD *)(v1 + 4);
v4 = *(_DWORD *)(v1 + 8);
v5 = *(_DWORD *)v1;
v6 = v3;
if ( v4 == -1 )
{
do
{
v8 = v3--;
wmove(game_erea, v8, v2);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > (unsigned int)(v6 - v3) );
goto LABEL_4;
}
if ( v4 < 0 )
{
v9 = 0;
if ( v4 == -2 )
{
do
{
v10 = v9 + v2;
++v9;
wmove(game_erea, v3, v10);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > v9 );
}
goto LABEL_4;
}
if ( v4 == 1 )
break;
if ( v4 == 2 )
{
do
{
v7 = v5--;
wmove(game_erea, v3, v7);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > (unsigned int)(v2 - v5) );
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return;
}
else
{
LABEL_4:
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return;
}
}
v11 = 0;
do
{
v12 = v11 + v3;
++v11;
wmove(game_erea, v12, v2);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > v11 );
goto LABEL_4;
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
int v2; // er12
int v3; // ebp
int v4; // eax
int v5; // er13
int v6; // er14
int v7; // edx
int v8; // esi
unsigned int v9; // er13
int v10; // edx
unsigned int v11; // er13
int v12; // esi

if ( a1 )
{
v1 = a1;
while ( 1 )
{
if ( !*(_DWORD *)(v1 + 12) )
{
if ( snake_head != v1 )
return;
goto LABEL_4;
}
v2 = *(_DWORD *)v1;
v3 = *(_DWORD *)(v1 + 4);
v4 = *(_DWORD *)(v1 + 8);
v5 = *(_DWORD *)v1;
v6 = v3;
if ( v4 == -1 )
{
do
{
v8 = v3--;
wmove(game_erea, v8, v2);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > (unsigned int)(v6 - v3) );
goto LABEL_4;
}
if ( v4 < 0 )
{
v9 = 0;
if ( v4 == -2 )
{
do
{
v10 = v9 + v2;
++v9;
wmove(game_erea, v3, v10);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > v9 );
}
goto LABEL_4;
}
if ( v4 == 1 )
break;
if ( v4 == 2 )
{
do
{
v7 = v5--;
wmove(game_erea, v3, v7);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > (unsigned int)(v2 - v5) );
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return;
}
else
{
LABEL_4:
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return;
}
}
v11 = 0;
do
{
v12 = v11 + v3;
++v11;
wmove(game_erea, v12, v2);
waddch(game_erea, 0x40020uLL);
waddch(game_erea, 0x40020uLL);
}
while ( *(_DWORD *)(v1 + 12) > v11 );
goto LABEL_4;
}
}

original_code:
void paint_seg(struct segment *p)
{
 if (p == ((void *)0))
  return;
 if ( p->count == 0 && p != snake_head)
  return;
 int x = p->x;
 int y = p->y;
 switch (p->dir) {
 case -1:
  do {for (int i = 0; i < (p->count); i++) { wmove(game_erea,(y--),(x)); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); } } while (0);
  break;
 case 1:
  do {for (int i = 0; i < (p->count); i++) { wmove(game_erea,(y++),(x)); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); } } while (0);
  break;
 case 2:
  do {for (int i = 0; i < (p->count); i++) { wmove(game_erea,(y),(x--)); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); } } while (0);
  break;
 case -2:
  do {for (int i = 0; i < (p->count); i++) { wmove(game_erea,(y),(x++)); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); waddch(game_erea, ' ' | ((chtype)((1U)) << ((10) + 8))); } } while (0);
  break;
 }
 paint_seg(p->next);
}

variable_types: struct segment { unsigned int x; int dir; unsigned int count; struct segment *pre; struct segment *next; } *

variable_types: x int

variable_types: y int


decompiled_code:
__int64 count_seg()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = snake_head;
if ( !snake_head )
return 0LL;
v1 = 0;
do
{
v0 = *(_QWORD *)(v0 + 24);
++v1;
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = snake_head;
if ( !snake_head )
return 0LL;
v1 = 0;
do
{
v0 = *(_QWORD *)(v0 + 24);
++v1;
}
while ( v0 );
return v1;
}

original_code:
unsigned int count_seg()
{
 struct segment *p = snake_head;
 int i = 0;
 for(p = snake_head; p; p = p->next)
  i++;
 return i;
}

return_type: unsigned int

user_defined_types: struct segment { unsigned int x; int dir; unsigned int count; struct segment *pre; struct segment *next; }


decompiled_code:
__int64 count_node()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = snake_head;
for ( i = 0; v0; v0 = *(_QWORD *)(v0 + 24) )
i += *(_DWORD *)(v0 + 12);
return i;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = snake_head;
for ( i = 0; v0; v0 = *(_QWORD *)(v0 + 24) )
i += *(_DWORD *)(v0 + 12);
return i;
}

original_code:
unsigned int count_node()
{
 struct segment *p;
 unsigned int cnt = 0;
 for(p = snake_head; p; p = p->next)
  cnt += p->count;
 return cnt;
}

variable_types:
cnt
unsigned int


decompiled_code:
int __fastcall paint_node_nr(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // eax
char s[8]; // [rsp+6h] [rbp-12h] BYREF
__int16 v6; // [rsp+Eh] [rbp-Ah]

v6 = 0;
*(_QWORD *)s = 0LL;
v3 = count_node(s, "%d", a3);
sprintf(s, "%d", v3);
wmove(game_erea, 0, 0);
return waddnstr(game_erea, s, -1);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // eax
char s[8]; // [rsp+6h] [rbp-12h] BYREF
__int16 v6; // [rsp+Eh] [rbp-Ah]

v6 = 0;
*(_QWORD *)s = 0LL;
v3 = func3(s, "%d", a3);
sprintf(s, "%d", v3);
wmove(game_erea, 0, 0);
return waddnstr(game_erea, s, -1);
}

original_code:
void paint_node_nr()
{
 char buf[10] = {0};
 sprintf(buf, "%d", count_node());
 wmove(game_erea, 0, 0);
 waddnstr(game_erea,buf,-1);
}

variable_types:
buf
char [10]


display

decompiled_code:
int display()
{
__int64 v0; // rdx

wclear(game_erea);
wborder(game_erea, 0x7CuLL, 0x7CuLL, 0x3DuLL, 0x3DuLL, 0LL, 0LL, 0LL, 0LL);
pthread_mutex_lock(&sync_lock);
paint_seg(snake_head);
pthread_mutex_unlock(&sync_lock);
paint_apple();
paint_node_nr((__int64)&sync_lock, 124LL, v0);
return wrefresh(game_erea);
}

canonical_decompiled_code:
int func5()
{
__int64 v0; // rdx

wclear(game_erea);
wborder(game_erea, 0x7CuLL, 0x7CuLL, 0x3DuLL, 0x3DuLL, 0LL, 0LL, 0LL, 0LL);
pthread_mutex_lock(&sync_lock);
func1(snake_head);
pthread_mutex_unlock(&sync_lock);
func0();
func4((__int64)&sync_lock, 124LL, v0);
return wrefresh(game_erea);
}

original_code:
void display()
{
 wclear(game_erea);
 wborder(game_erea, '|', '|', '=', '=', 0, 0, 0, 0);
 pthread_mutex_lock(&sync_lock);
 paint_seg(snake_head);
 pthread_mutex_unlock(&sync_lock);
 paint_apple();
 paint_node_nr();
 wrefresh(game_erea);
}


decompiled_code:
__int64 __fastcall change_tail(__int64 *a1)
{
__int64 v1; // r8
__int64 v2; // rax
__int64 result; // rax

v1 = *a1;
if ( snake_head != *a1 )
{
v2 = *(_QWORD *)(v1 + 16);
*a1 = v2;
*(_QWORD *)(v2 + 24) = 0LL;
result = item_push(v1, &snake_pool);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 v1; // r8
__int64 v2; // rax
__int64 result; // rax

v1 = *a1;
if ( snake_head != *a1 )
{
v2 = *(_QWORD *)(v1 + 16);
*a1 = v2;
*(_QWORD *)(v2 + 24) = 0LL;
result = item_push(v1, &snake_pool);
}
return result;
}

original_code:
void change_tail(struct segment **tailp)
{
 struct segment *tmp = *tailp;
 if (*tailp != snake_head) {
  *tailp = (*tailp)->pre;
  (*tailp)->next = ((void *)0);
  item_push(tmp, &snake_pool);
 }
}

variable_types: struct segment { unsigned int x; int dir; unsigned int count; struct segment *pre; struct segment *next; } **


decompiled_code:
__int64 __fastcall check_node_at_snake(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // eax

while ( a1 )
{
result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result == 1 )
{
if ( *(_DWORD *)a1 == a2 )
{
v4 = *(_DWORD *)(a1 + 4);
if ( v4 <= a3 && *(_DWORD *)(a1 + 12) + v4 >= a3 )
return result;
}
}
else if ( (int)result > 1 )
{
if ( (_DWORD)result == 2
&& *(_DWORD *)(a1 + 4) == a3
&& *(_DWORD *)a1 >= a2
&& *(_DWORD *)a1 - *(_DWORD *)(a1 + 12) <= a2 )
{
return 1LL;
}
}
else if ( (_DWORD)result == -2 )
{
if ( *(_DWORD *)(a1 + 4) == a3 && *(_DWORD *)a1 <= a2 && *(_DWORD *)(a1 + 12) + *(_DWORD *)a1 >= a2 )
return 1LL;
}
else if ( (_DWORD)result == -1 && *(_DWORD *)a1 == a2 )
{
v5 = *(_DWORD *)(a1 + 4);
if ( v5 >= a3 && v5 - *(_DWORD *)(a1 + 12) <= a3 )
return 1LL;
}
a1 = *(_QWORD *)(a1 + 24);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // eax

while ( a1 )
{
result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result == 1 )
{
if ( *(_DWORD *)a1 == a2 )
{
v4 = *(_DWORD *)(a1 + 4);
if ( v4 <= a3 && *(_DWORD *)(a1 + 12) + v4 >= a3 )
return result;
}
}
else if ( (int)result > 1 )
{
if ( (_DWORD)result == 2
&& *(_DWORD *)(a1 + 4) == a3
&& *(_DWORD *)a1 >= a2
&& *(_DWORD *)a1 - *(_DWORD *)(a1 + 12) <= a2 )
{
return 1LL;
}
}
else if ( (_DWORD)result == -2 )
{
if ( *(_DWORD *)(a1 + 4) == a3 && *(_DWORD *)a1 <= a2 && *(_DWORD *)(a1 + 12) + *(_DWORD *)a1 >= a2 )
return 1LL;
}
else if ( (_DWORD)result == -1 && *(_DWORD *)a1 == a2 )
{
v5 = *(_DWORD *)(a1 + 4);
if ( v5 >= a3 && v5 - *(_DWORD *)(a1 + 12) <= a3 )
return 1LL;
}
a1 = *(_QWORD *)(a1 + 24);
}
return 0LL;
}

original_code:
int check_node_at_snake(struct segment *p, unsigned int hx, unsigned int hy)
{
 while (p) {
  switch (p->dir) {
  case -1:
   if (hx == p->x )
    if (hy <= p->y && hy >= (p->y - p->count))
     return 1;
   break;
  case 1:
   if (hx == p->x)
    if (hy >= p->y && hy <= (p->y + p->count))
     return 1;
   break;
  case 2:
   if (hy == p->y)
    if (hx <= p->x && hx >= (p->x - p->count))
     return 1;
   break;
  case -2:
   if (hy == p->y)
    if (hx >= p->x && hx <= (p->x + p->count))
     return 1;
   break;
  }
  p = p->next;
 }
 return 0;
}

variable_types:
hx
unsigned int

variable_types:
hy
unsigned int


decompiled_code:
__int64 terminated_check()
{
signed int v0; // esi
int v1; // er8
__int64 v2; // rcx
unsigned int v3; // er8
unsigned int v4; // er9
__int64 result; // rax

v0 = *(_DWORD *)snake_head;
v1 = *(_DWORD *)(snake_head + 4);
if ( real_x < *(_DWORD *)snake_head || real_y < v1 || v0 <= 0 || v1 <= 0 )
return 0xFFFFFFFFLL;
v4 = count_seg();
result = 0LL;
if ( v4 > 3 )
result = (unsigned int)-((unsigned int)check_node_at_snake(
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v2 + 24) + 24LL) + 24LL),
v0,
v3) != 0);
return result;
}

canonical_decompiled_code:
__int64 func8()
{
signed int v0; // esi
int v1; // er8
__int64 v2; // rcx
unsigned int v3; // er8
unsigned int v4; // er9
__int64 result; // rax

v0 = *(_DWORD *)snake_head;
v1 = *(_DWORD *)(snake_head + 4);
if ( real_x < *(_DWORD *)snake_head || real_y < v1 || v0 <= 0 || v1 <= 0 )
return 0xFFFFFFFFLL;
v4 = func2();
result = 0LL;
if ( v4 > 3 )
result = (unsigned int)-((unsigned int)func7(
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v2 + 24) + 24LL) + 24LL),
v0,
v3) != 0);
return result;
}

original_code:
int terminated_check()
{
 struct segment *p = snake_head;
 int hx = p->x;
 int hy = p->y;
 if (hx > real_x || hy > real_y || hx < 1 || hy < 1)
  return -1;
 if (count_seg() < 4)
  return 0;
 p = ((p->next)->next)->next;
 if (check_node_at_snake(p, hx, hy))
  return -1;
 return 0;
}

variable_types: hx int

variable_types: hy int


decompiled_code:
__int64 __fastcall update_apple(unsigned int a1)
{
int *v1; // rbx
unsigned int v2; // eax
int v3; // eax
__int64 result; // rax
int v5; // et2
int v6; // eax
int v7; // et2

v1 = apple;
v2 = time(0LL);
srand(v2);
if ( a1 <= 2 )
{
apple[2 * a1] = rand() % real_x + 1;
v6 = rand();
v7 = v6 % real_y;
result = (unsigned int)(v6 / real_y);
apple[2 * a1 + 1] = v7 + 1;
}
else
{
do
{
v1 += 2;
*(v1 - 2) = rand() % real_x + 1;
v3 = rand();
v5 = v3 % real_y;
result = (unsigned int)(v3 / real_y);
*(v1 - 1) = v5 + 1;
}
while ( v1 != &apple[6] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
int *v1; // rbx
unsigned int v2; // eax
int v3; // eax
__int64 result; // rax
int v5; // et2
int v6; // eax
int v7; // et2

v1 = apple;
v2 = time(0LL);
srand(v2);
if ( a1 <= 2 )
{
apple[2 * a1] = rand() % real_x + 1;
v6 = rand();
v7 = v6 % real_y;
result = (unsigned int)(v6 / real_y);
apple[2 * a1 + 1] = v7 + 1;
}
else
{
do
{
v1 += 2;
*(v1 - 2) = rand() % real_x + 1;
v3 = rand();
v5 = v3 % real_y;
result = (unsigned int)(v3 / real_y);
*(v1 - 1) = v5 + 1;
}
while ( v1 != &apple[6] );
}
return result;
}

original_code:
void update_apple(int index)
{
 int i;
 srand((unsigned int)time(((void *)0)));
 if (index >=0 && index < 3 ) {
  apple[index].x = (unsigned int)(rand() % real_x) + 1;
  apple[index].y = (unsigned int)(rand() % real_y) + 1;
 } else
  for (i = 0; i < 3; i++) {
   apple[i].x = (unsigned int)(rand() % real_x) + 1;
   apple[i].y = (unsigned int)(rand() % real_y) + 1;
  }
}

variable_types: index int


decompiled_code:
__int64 eat_apple()
{
__int64 v0; // rdi

v0 = 0LL;
while ( *(_DWORD *)snake_head != apple[2 * v0] || *(_DWORD *)(snake_head + 4) != apple[2 * v0 + 1] )
{
if ( ++v0 == 3 )
return 0LL;
}
++*(_DWORD *)(snake_head + 12);
update_apple(v0);
g_speed = (int)((double)(int)g_speed - 0.01 * (double)(int)g_speed);
return 1LL;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rdi

v0 = 0LL;
while ( *(_DWORD *)snake_head != apple[2 * v0] || *(_DWORD *)(snake_head + 4) != apple[2 * v0 + 1] )
{
if ( ++v0 == 3 )
return 0LL;
}
++*(_DWORD *)(snake_head + 12);
func9(v0);
g_speed = (int)((double)(int)g_speed - 0.01 * (double)(int)g_speed);
return 1LL;
}

original_code:
int eat_apple()
{
 int i;
 for (i = 0; i < 3; i++) {
  if (snake_head->x == apple[i].x && snake_head->y == apple[i].y) {
   snake_head->count++;
   update_apple(i);
   g_speed -= g_speed * 0.01;
   return 1;
  }
 }
 return 0;
}


original_code:
int snake_move()
{
 struct segment *p = snake_head;
 struct segment *tail = ((void *)0);
 tail = snake_head;
 while (tail->next)
  tail = tail->next;
 if (snake_head != tail) {
  if (tail->count == 0)
   change_tail(&tail);
  tail->count--;
  p->count++;
 }
 switch(p->dir) {
 case -1:
  p->y++;
  p->y = p->y + eat_apple();
  break;
 case 1:
  p->y--;
  p->y = p->y - eat_apple();
  break;
 case 2:
  p->x++;
  p->x = p->x + eat_apple();
  break;
 case -2 :
  p->x--;
  p->x = p->x - eat_apple();
  break;
 }
 if (terminated_check())
  return -1;
 return 0;
}


decompiled_code:
void __noreturn quit_game()
{
wmove(game_erea, real_y / 2, real_x / 2);
waddnstr(game_erea, "Game Over\n", -1);
wrefresh(game_erea);
wgetch(stdscr);
endwin();
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
wmove(game_erea, real_y / 2, real_x / 2);
waddnstr(game_erea, "Game Over\n", -1);
wrefresh(game_erea);
wgetch(stdscr);
endwin();
exit(0);
}

original_code:
void quit_game()
{
 wmove(game_erea, real_y / 2, real_x / 2);
 waddnstr(game_erea,"Game Over\n",-1);
 wrefresh(game_erea);
 wgetch(stdscr);
 endwin();
 exit(0);
}


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

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

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

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

original_code:
void insert_head(struct segment *p)
{
 if (p == ((void *)0))
  return;
 struct segment *tmp = snake_head;
 p->next = tmp;
 p->pre = p;
 tmp->pre = p;
 snake_head = p;
}


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

result = wgetch(game_erea);
if ( result == 119 )
return 1;
if ( result > 119 )
{
if ( result != 260 )
{
if ( result > 260 )
return 2 * (result == 261);
if ( result == 258 )
return -1;
return result == 259;
}
return -2;
}
if ( result == 97 )
return -2;
if ( result <= 97 )
{
if ( result != 32 )
result = 0;
}
else if ( result == 100 )
{
result = 2;
}
else
{
result = -(result == 115);
}
return result;
}

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

result = wgetch(game_erea);
if ( result == 119 )
return 1;
if ( result > 119 )
{
if ( result != 260 )
{
if ( result > 260 )
return 2 * (result == 261);
if ( result == 258 )
return -1;
return result == 259;
}
return -2;
}
if ( result == 97 )
return -2;
if ( result <= 97 )
{
if ( result != 32 )
result = 0;
}
else if ( result == 100 )
{
result = 2;
}
else
{
result = -(result == 115);
}
return result;
}

original_code:
int get_arrow_key(void)
{
 int key;
 switch (wgetch(game_erea)) {
 case 'a':
 case 0404:
  key = -2;
  break;
 case 'd':
 case 0405:
  key = 2;
  break;
 case 'w':
 case 0403:
  key = 1;
  break;
 case 's':
 case 0402:
  key = -1;
  break;
 case ' ':
  key = ' ';
  break;
 default:
  key = 0;
  break;
 }
 return key;
}

canonical_original_code:
int get_arrow_key()
{
 int key;
 switch (wgetch(game_erea)) {
 case 'a':
 case 0404:
  key = -2;
  break;
 case 'd':
 case 0405:
  key = 2;
  break;
 case 'w':
 case 0403:
  key = 1;
  break;
 case 's':
 case 0402:
  key = -1;
  break;
 case ' ':
  key = ' ';
  break;
 default:
  key = 0;
  break;
 }
 return key;
}

variable_types: key int


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

result = pthread_mutex_trylock(&run_lock);
if ( result )
result = pthread_mutex_unlock(&run_lock);
return result;
}

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

result = pthread_mutex_trylock(&run_lock);
if ( result )
result = pthread_mutex_unlock(&run_lock);
return result;
}

original_code:
void resume_and_pause_snake()
{
 if (pthread_mutex_trylock(&run_lock))
  pthread_mutex_unlock(&run_lock);
}


decompiled_code:
void __fastcall __noreturn guide_snake(void *a1)
{
int v1; // ebp
_DWORD *v2; // rax

keypad(game_erea, 1);
while ( 1 )
{
do
v1 = get_arrow_key();
while ( !*(_DWORD *)(snake_head + 12) );
if ( v1 > 2 )
{
if ( v1 == 32 )
resume_and_pause_snake();
}
else if ( v1 > 0 || (unsigned int)v1 >= 0xFFFFFFFE )
{
pthread_mutex_lock(&sync_lock);
v2 = new_segment(v1);
insert_head((__int64)v2);
pthread_mutex_unlock(&sync_lock);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func16(void *a1)
{
int v1; // ebp
_DWORD *v2; // rax

keypad(game_erea, 1);
while ( 1 )
{
do
v1 = func14();
while ( !*(_DWORD *)(snake_head + 12) );
if ( v1 > 2 )
{
if ( v1 == 32 )
func15();
}
else if ( v1 > 0 || (unsigned int)v1 >= 0xFFFFFFFE )
{
pthread_mutex_lock(&sync_lock);
v2 = new_segment(v1);
func13((__int64)v2);
pthread_mutex_unlock(&sync_lock);
}
}
}

original_code:
void *guide_snake(void * data)
{
 int key;
 struct segment *new;
 keypad(game_erea, 1);
 while (1) {
  key = get_arrow_key();
  if (snake_head->count == 0)
   continue;
  switch (key){
  case -1:
  case 1:
  case 2:
  case -2:
   pthread_mutex_lock(&sync_lock);
   new = new_segment(key);
   insert_head(new);
   pthread_mutex_unlock(&sync_lock);
   break;
  case ' ':
   resume_and_pause_snake();
   break;
  default:
   break;
  }
 }
}

canonical_original_code:
void *guide_snake(void *data)
{
 int key;
 struct segment *new;
 keypad(game_erea, 1);
 while (1) {
  key = get_arrow_key();
  if (snake_head->count == 0)
   continue;
  switch (key){
  case -1:
  case 1:
  case 2:
  case -2:
   pthread_mutex_lock(&sync_lock);
   new = new_segment(key);
   insert_head(new);
   pthread_mutex_unlock(&sync_lock);
   break;
  case ' ':
   resume_and_pause_snake();
   break;
  default:
   break;
  }
 }
}

variable_types:
data
void *

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
_QWORD *v4; // rdx
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

initscr();
if ( real_x + 1 < COLS && real_y + 1 < LINES )
{
game_erea = derwin(stdscr, real_y + 2, real_x + 2, (LINES - real_y - 2) / 5, (COLS - real_x - 2) / 2);
pthread_mutex_init(&sync_lock, 0LL);
pthread_mutex_init(&run_lock, 0LL);
mem_pool_init(&snake_pool);
noecho();
v4 = (_QWORD *)item_pop(&snake_pool);
snake_head = (__int64)v4;
result = -1;
if ( v4 )
{
v4[2] = v4;
v4[3] = 0LL;
*v4 = 0x140000000FLL;
v4[1] = 0xF00000002LL;
pthread_create(newthread, 0LL, (void *(*)(void *))guide_snake, 0LL);
update_apple(0xFFFFFFFF);
while ( 1 )
{
pthread_mutex_lock(&run_lock);
pthread_mutex_unlock(&run_lock);
pthread_mutex_lock(&sync_lock);
if ( (unsigned int)snake_move() )
break;
pthread_mutex_unlock(&sync_lock);
display();
if ( ((*(_DWORD *)(snake_head + 8) + 2) & 0xFFFFFFFB) != 0 )
usleep((int)((double)(int)g_speed * 2.5));
else
usleep(g_speed);
}
pthread_cancel(newthread[0]);
quit_game();
}
}
else
{
wmove(stdscr, 0, 0);
printw(
"To play this game, the window size request at least x : 94, y : 30,\n but this window size is x : %d, y : %d\n",
(unsigned int)COLS,
(unsigned int)LINES);
wgetch(stdscr);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
_QWORD *v4; // rdx
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

initscr();
if ( real_x + 1 < COLS && real_y + 1 < LINES )
{
game_erea = derwin(stdscr, real_y + 2, real_x + 2, (LINES - real_y - 2) / 5, (COLS - real_x - 2) / 2);
pthread_mutex_init(&sync_lock, 0LL);
pthread_mutex_init(&run_lock, 0LL);
mem_pool_init(&snake_pool);
noecho();
v4 = (_QWORD *)item_pop(&snake_pool);
snake_head = (__int64)v4;
result = -1;
if ( v4 )
{
v4[2] = v4;
v4[3] = 0LL;
*v4 = 0x140000000FLL;
v4[1] = 0xF00000002LL;
pthread_create(newthread, 0LL, (void *(*)(void *))guide_snake, 0LL);
func9(0xFFFFFFFF);
while ( 1 )
{
pthread_mutex_lock(&run_lock);
pthread_mutex_unlock(&run_lock);
pthread_mutex_lock(&sync_lock);
if ( (unsigned int)func11() )
break;
pthread_mutex_unlock(&sync_lock);
func5();
if ( ((*(_DWORD *)(snake_head + 8) + 2) & 0xFFFFFFFB) != 0 )
usleep((int)((double)(int)g_speed * 2.5));
else
usleep(g_speed);
}
pthread_cancel(newthread[0]);
func12();
}
}
else
{
wmove(stdscr, 0, 0);
printw(
"To play this game, the window size request at least x : 94, y : 30,\n but this window size is x : %d, y : %d\n",
(unsigned int)COLS,
(unsigned int)LINES);
wgetch(stdscr);
result = 0;
}
return result;
}

original_code:
int main(void)
{
 pthread_t tid;
  initscr();
 if (COLS < real_x + 2 || LINES < real_y + 2) {
  wmove(stdscr,(0),(0));
  printw("To play this game, the window size request at least x : 94, y : 30,\n but this window size is x : %d, y : %d\n", COLS, LINES);
  wgetch(stdscr);
  return 0;
 }
 game_erea = derwin(stdscr, real_y + 2, real_x + 2, (LINES - real_y - 2) / 5, (COLS - real_x - 2) / 2);
 pthread_mutex_init(&sync_lock, ((void *)0));
 pthread_mutex_init(&run_lock, ((void *)0));
 mem_pool_init(&snake_pool);
 noecho();
 snake_head = (struct segment *)item_pop(&snake_pool);
 if (((void *)0) == snake_head)
  return -1;
 snake_head->x = 15;
 snake_head->y = 20;
 snake_head->dir = 2;
 snake_head->count = 15;
 snake_head->pre = snake_head;
 snake_head->next = ((void *)0);
 pthread_create(&tid, ((void *)0), guide_snake, ((void *)0));
 update_apple(-1);
 while(1) {
  {pthread_mutex_lock(&run_lock);pthread_mutex_unlock(&run_lock);};
  pthread_mutex_lock(&sync_lock);
  if(snake_move()) {
   pthread_cancel(tid);
   quit_game();
  }
  pthread_mutex_unlock(&sync_lock);
  display();
  if (snake_head->dir == 2 ||
   snake_head->dir == -2)
   usleep(g_speed);
  else
   usleep(g_speed * 2.5);
 }
 return 0;
}

canonical_original_code:
int main()
{
 unsigned long tid;
  initscr();
 if (COLS < real_x + 2 || LINES < real_y + 2) {
  wmove(stdscr,(0),(0));
  printw("To play this game, the window size request at least x : 94, y : 30,\n but this window size is x : %d, y : %d\n", COLS, LINES);
  wgetch(stdscr);
  return 0;
 }
 game_erea = derwin(stdscr, real_y + 2, real_x + 2, (LINES - real_y - 2) / 5, (COLS - real_x - 2) / 2);
 pthread_mutex_init(&sync_lock, ((void *)0));
 pthread_mutex_init(&run_lock, ((void *)0));
 mem_pool_init(&snake_pool);
 noecho();
 snake_head = (struct segment *)item_pop(&snake_pool);
 if (((void *)0) == snake_head)
  return -1;
 snake_head->x = 15;
 snake_head->y = 20;
 snake_head->dir = 2;
 snake_head->count = 15;
 snake_head->pre = snake_head;
 snake_head->next = ((void *)0);
 pthread_create(&tid, ((void *)0), guide_snake, ((void *)0));
 update_apple(-1);
 while(1) {
  {pthread_mutex_lock(&run_lock);pthread_mutex_unlock(&run_lock);};
  pthread_mutex_lock(&sync_lock);
  if(snake_move()) {
   pthread_cancel(tid);
   quit_game();
  }
  pthread_mutex_unlock(&sync_lock);
  display();
  if (snake_head->dir == 2 ||
   snake_head->dir == -2)
   usleep(g_speed);
  else
   usleep(g_speed * 2.5);
 }
 return 0;
}

variable_types:
tid
unsigned long


original_code:
int mem_pool_init(mem_pool_t *pool)
{
 int i;
 if (pool->item_max_quantum < 2 || pool->item_size < 1)
  return -1;
 pool->available = (void **)malloc(pool->item_max_quantum * sizeof(void *));
 for (i = 0; i < pool->item_max_quantum / 2; i++) {
  pool->available[i] = malloc(pool->item_size);
  if (pool->available[i] == ((void *)0))
   goto err;
  memset(pool->available[i], 0,pool->item_size);
 }
 pool->avail_cnt = pool->item_max_quantum / 2;
 pool->total_malloc = pool->avail_cnt;
 return 0;
err:
 for (i--; i >= 0; i--) {
  free(pool->available[i]);
 }
 return -1;
}

canonical_original_code:
int mem_pool_init(struct mem_pool_struct *pool)
{
 int i;
 if (pool->item_max_quantum < 2 || pool->item_size < 1)
  return -1;
 pool->available = (void **)malloc(pool->item_max_quantum * sizeof(void *));
 for (i = 0; i < pool->item_max_quantum / 2; i++) {
  pool->available[i] = malloc(pool->item_size);
  if (pool->available[i] == ((void *)0))
   goto err;
  memset(pool->available[i], 0,pool->item_size);
 }
 pool->avail_cnt = pool->item_max_quantum / 2;
 pool->total_malloc = pool->avail_cnt;
 return 0;
err:
 for (i--; i >= 0; i--) {
  free(pool->available[i]);
 }
 return -1;
}

variable_types: struct mem_pool_struct { unsigned int item_max_quantum; int item_size; void **available; unsigned int avail_cnt; void **used; unsigned int total_malloc; } *

variable_types: i int


decompiled_code:
void *__fastcall item_pop(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
void *result; // rax
__int64 v4; // rdx
unsigned int v5; // eax

v1 = *(_DWORD *)(a1 + 16);
if ( v1 )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = v1 - 1;
*(_DWORD *)(a1 + 16) = v5;
result = *(void **)(v4 + 8LL * v5);
}
else
{
v2 = *(_DWORD *)(a1 + 32);
result = 0LL;
if ( v2 < *(_DWORD *)a1 )
{
result = malloc(*(int *)(a1 + 4));
*(_DWORD *)(a1 + 32) = v2 + 1;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
void *result; // rax
__int64 v4; // rdx
unsigned int v5; // eax

v1 = *(_DWORD *)(a1 + 16);
if ( v1 )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = v1 - 1;
*(_DWORD *)(a1 + 16) = v5;
result = *(void **)(v4 + 8LL * v5);
}
else
{
v2 = *(_DWORD *)(a1 + 32);
result = 0LL;
if ( v2 < *(_DWORD *)a1 )
{
result = malloc(*(int *)(a1 + 4));
*(_DWORD *)(a1 + 32) = v2 + 1;
}
}
return result;
}

original_code:
void* item_pop(mem_pool_t * pool)
{
 void *p;
 unsigned int used_cnt = pool->total_malloc - pool->avail_cnt;
 if (pool->avail_cnt < 1)
  if (pool->total_malloc < pool->item_max_quantum) {
   p = (void *)malloc(pool->item_size);
   pool->total_malloc++;
   return p ? p : ((void *)0);
  } else
   return ((void *)0);
 pool->avail_cnt--;
 return pool->available[pool->avail_cnt];
}

canonical_original_code:
void *item_pop(struct mem_pool_struct *pool)
{
 void *p;
 unsigned int used_cnt = pool->total_malloc - pool->avail_cnt;
 if (pool->avail_cnt < 1)
  if (pool->total_malloc < pool->item_max_quantum) {
   p = (void *)malloc(pool->item_size);
   pool->total_malloc++;
   return p ? p : ((void *)0);
  } else
   return ((void *)0);
 pool->avail_cnt--;
 return pool->available[pool->avail_cnt];
}

variable_types:
p
void *

user_defined_types: struct mem_pool_struct { unsigned int item_max_quantum; int item_size; void **available; unsigned int avail_cnt; void **used; unsigned int total_malloc; }


decompiled_code:
__int64 __fastcall item_push(__int64 a1, __int64 a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a2 + 16);
if ( v2 >= *(_DWORD *)a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL * v2) = a1;
*(_DWORD *)(a2 + 16) = v2 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a2 + 16);
if ( v2 >= *(_DWORD *)a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL * v2) = a1;
*(_DWORD *)(a2 + 16) = v2 + 1;
return 0LL;
}

original_code:
int item_push(void *p, mem_pool_t *pool)
{
 unsigned int used_cnt = pool->total_malloc - pool->avail_cnt;
 if (pool->avail_cnt >= pool->item_max_quantum)
  return -1;
 pool->available[pool->avail_cnt] = p;
 pool->avail_cnt++;
 return 0;
}

canonical_original_code:
int item_push(void *p, struct mem_pool_struct *pool)
{
 unsigned int used_cnt = pool->total_malloc - pool->avail_cnt;
 if (pool->avail_cnt >= pool->item_max_quantum)
  return -1;
 pool->available[pool->avail_cnt] = p;
 pool->avail_cnt++;
 return 0;
}


decompiled_code:
__int64 __fastcall count_stack_item(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int count_stack_item(mem_pool_t *pool)
{
 return pool->avail_cnt;
}

canonical_original_code:
int count_stack_item(struct mem_pool_struct *pool)
{
 return pool->avail_cnt;
}


decompiled_code:
__int64 __fastcall count_malloc_item(__int64 a1)
{
return *(unsigned int *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 32);
}

original_code:
int count_malloc_item(mem_pool_t *pool)
{
 return pool->total_malloc;
}

canonical_original_code:
int count_malloc_item(struct mem_pool_struct *pool)
{
 return pool->total_malloc;
}


repo: Jery-Mong/tetris

decompiled_code:
void square_change_to_next()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void square_change_to_next(struct object *square)
{
 return;
}

variable_types: struct object { int base_type; int status; struct segment { int dir; int x; int brick_cnt; } *seg_head; int seg_cnt; void (*init)(struct object *obj); void (*change_to_next)(struct object *obj); union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } *

user_defined_types: struct object { int base_type; int status; struct segment *seg_head; int seg_cnt; void (*init)(struct object *obj); void (*change_to_next)(struct object *obj); union pthread_mutex_t lock; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


original_code:
void stick_init(struct object *stick)
{
 if (stick->base_type != STICK)
  return;
 stick->seg_cnt = 1;
 if (stick->seg_head == ((void *)0)) {
  stick->seg_head = (struct segment *)malloc(sizeof(struct segment) * stick->seg_cnt);
  pthread_mutex_init(&stick->lock, ((void *)0));
 }
 stick->status = 1;
 stick->seg_head->brick_cnt = 4;
 stick->seg_head->dir = VERTICAL;
 stick->seg_head->y = -3;
 stick->seg_head->x = rand() % ((48 / 4) - 4);
 for (int i = rand() % 2; i > 0; i--)
  stick->change_to_next(stick);
}

user_defined_types: struct segment { int dir; int x; int brick_cnt; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
void hook_init(struct object *hook)
{
 if (hook->base_type != HOOK)
  return;
 hook->seg_cnt = 2;
 if (hook->seg_head == ((void *)0)) {
  hook->seg_head = (struct segment *)malloc(sizeof(struct segment) * hook->seg_cnt);
  pthread_mutex_init(&hook->lock, ((void *)0));
 }
 struct segment *seg = hook->seg_head;
 hook->status = 0;
 seg->brick_cnt = 2;
 seg->dir = HORIZONTAL;
 seg->y = -1;
 seg->x = rand() % ((48 / 4) - 2);
 (seg + 1)->dir = VERTICAL;
 (seg + 1)->brick_cnt = 2;
 (seg + 1)->y = seg->y + 1;
 (seg + 1)->x = seg->x + 1;
 int i = rand() % 5;
 for (; i > 0; i--)
  hook->change_to_next(hook);
}

variable_types: struct segment { int dir; int x; int brick_cnt; } *


original_code:
void tu_init(struct object *tu)
{
 if (tu->base_type != TU)
  return;
 tu->seg_cnt = 2;
 if (tu->seg_head == ((void *)0)) {
  tu->seg_head = (struct segment *)malloc(sizeof(struct segment) * tu->seg_cnt);
  pthread_mutex_init(&tu->lock, ((void *)0));
 }
 struct segment *seg = tu->seg_head;
 tu->status = 0;
 seg->brick_cnt = 1;
 seg->dir = HORIZONTAL;
 seg->y = -1;
 seg->x = rand() % ((48 / 4) - 2);
 (seg + 1)->dir = HORIZONTAL;
 (seg + 1)->brick_cnt = 3;
 (seg + 1)->x = seg->x - 1;
 (seg + 1)->y = seg->y + 1;
 int i = rand() % 5;
 for (; i > 0; i--)
  tu->change_to_next(tu);
}


original_code:
void rhook_init(struct object *rhook)
{
 if (rhook->base_type != RHOOK)
  return;
 rhook->seg_cnt = 2;
 if (rhook->seg_head == ((void *)0)) {
  rhook->seg_head = (struct segment *)malloc(sizeof(struct segment) * rhook->seg_cnt);
  pthread_mutex_init(&rhook->lock, ((void *)0));
 }
 struct segment *seg = rhook->seg_head;
 rhook->status = 0;
 seg->brick_cnt = 2;
 seg->dir = HORIZONTAL;
 seg->y = -1;
 seg->x = rand() % ((48 / 4) - 3) + 1;
 (seg + 1)->y = seg->y + 1;
 (seg + 1)->x = seg->x;
 (seg + 1)->dir = VERTICAL;
 (seg + 1)->brick_cnt = 2;
 int i = rand() % 5;
 for (; i > 0; i--)
  rhook->change_to_next(rhook);
}


original_code:
void lightning_init(struct object *lightning)
{
 if (lightning->base_type != LIGHTNING)
  return;
 lightning->seg_cnt = 2;
 if (lightning->seg_head == ((void *)0)) {
  lightning->seg_head = (struct segment *)malloc(sizeof(struct segment) * lightning->seg_cnt);
  pthread_mutex_init(&lightning->lock, ((void *)0));
 }
 struct segment *seg = lightning->seg_head;
 lightning->status = 0;
 seg->brick_cnt = 2;
 seg->dir = VERTICAL;
 seg->y = -1;
 seg->x = rand() % ((48 / 4) - 1);
 (seg + 1)->y = seg->y + 1;
 (seg + 1)->x = seg->x + 1;
 (seg + 1)->dir = VERTICAL;
 (seg + 1)->brick_cnt = 2;
 int i = rand() % 2;
 for (; i > 0; i--)
  lightning->change_to_next(lightning);
}


original_code:
void rlightning_init(struct object *rlightning)
{
 if (rlightning->base_type != RLIGHTNING)
  return;
 rlightning->seg_cnt = 2;
 if (rlightning->seg_head == ((void *)0)) {
  rlightning->seg_head = (struct segment *)malloc(sizeof(struct segment) * rlightning->seg_cnt);
  pthread_mutex_init(&rlightning->lock, ((void *)0));
 }
 struct segment *seg = rlightning->seg_head;
 rlightning->status = 0;
 seg->brick_cnt = 2;
 seg->dir = VERTICAL;
 seg->y = -1;
 seg->x = rand() % ((48 / 4) - 2) + 1;
 (seg + 1)->y = seg->y + 1;
 (seg + 1)->x = seg->x - 1;
 (seg + 1)->dir = VERTICAL;
 (seg + 1)->brick_cnt = 2;
 int i = rand() % 2;
 for (; i > 0; i--)
  rlightning->change_to_next(rlightning);
}


decompiled_code:
__int64 __fastcall check_allow_trans(__int64 a1)
{
move_steps(a1, 1LL, 4LL);
if ( (unsigned int)check_position_h(a1, 5LL) == 1 )
return 1LL;
move_steps(a1, 2LL, 5LL);
if ( (unsigned int)check_position_h(a1, 4LL) == 1 )
return 1LL;
move_steps(a1, 1LL, 4LL);
move_steps(a1, 1LL, 0LL);
if ( (unsigned int)check_position_v(a1) == 1 )
return 1LL;
move_steps(a1, 1LL, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
move_steps(a1, 1LL, 4LL);
if ( (unsigned int)check_position_h(a1, 5LL) == 1 )
return 1LL;
move_steps(a1, 2LL, 5LL);
if ( (unsigned int)check_position_h(a1, 4LL) == 1 )
return 1LL;
move_steps(a1, 1LL, 4LL);
move_steps(a1, 1LL, 0LL);
if ( (unsigned int)check_position_v(a1) == 1 )
return 1LL;
move_steps(a1, 1LL, 1LL);
return 0LL;
}

original_code:
static int check_allow_trans(struct object *obj)
{
 move_steps(obj, 1, CTRL_LEFT);
 if (check_position_h(obj, CTRL_RIGHT) == POSITION_STOP)
  return POSITION_STOP;
 move_steps(obj, 2, CTRL_RIGHT);
 if (check_position_h(obj, CTRL_LEFT) == POSITION_STOP)
  return POSITION_STOP;
 move_steps(obj, 1, CTRL_LEFT);
 move_steps(obj, 1, CTRL_UP);
 if (check_position_v(obj) == POSITION_STOP)
  return POSITION_STOP;
 move_steps(obj, 1, CTRL_DOWN);
 return POSITION_FREE;
}


transfer

original_code:
void transfer(struct object *orig, struct object *dup_obj)
{
 if (check_allow_trans(dup_obj) == POSITION_FREE) {
  memcpy(orig, dup_obj, sizeof(struct object));
  memcpy(orig->seg_head, dup_obj->seg_head, sizeof(struct segment) * orig->seg_cnt);
 }
}


original_code:
void com_transfer(struct object *obj)
{
 struct object *dup_obj = duplex_obj(obj);
 obj->change_to_next(dup_obj);
 transfer(obj, dup_obj);
 free(dup_obj);
}


decompiled_code:
__int64 __fastcall own_signal(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v4; // [rsp+A0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
return (unsigned int)(sigaction(sig, &v3, &v4) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func0(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v4; // [rsp+A0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
return (unsigned int)(sigaction(sig, &v3, &v4) >> 31);
}

original_code:
int own_signal(int signo, void (*func)(int))
{
 struct sigaction act;
 struct sigaction oact;
 act.__sigaction_handler.sa_handler = func;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (sigaction(signo, &act, &oact) < 0)
  return -1;
 return 0;
}

variable_types: signo int

variable_types:
func
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


main

repo: Jille/oid

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
ssize_t v3; // rax
size_t v4; // rdx
signed __int64 v5; // rax
size_t v6; // rbp
ssize_t v7; // rax
__off64_t v8; // rax
size_t v9; // rdx
signed __int64 v10; // rax
ssize_t v11; // rax
ssize_t v12; // rax
int result; // eax
signed __int64 v14; // rax
ssize_t v15; // rax

if ( argc == 2 )
{
fdout = open64(argv[1], 2, envp);
if ( fdout == -1 )
err(1, "open(%s, r+)", argv[1]);
LABEL_3:
v3 = read(fdin, &wantedbuf, 0x1000uLL);
v4 = v3;
if ( v3 == -1 )
LABEL_29:
err(1, "read(STDIN, ..., %d)", 4096LL);
if ( v3 )
{
wantedread = v3;
v5 = 0LL;
actualread = 0LL;
while ( 1 )
{
v7 = read(fdout, (char *)&actualbuf + v5, v4 - v5);
if ( v7 == -1 )
err(1, "read(fdout, ..., %ld)", wantedread - actualread);
if ( !v7 )
break;
v6 = wantedread;
v5 = actualread + v7;
actualread = v5;
v4 = wantedread;
if ( v5 >= (__int64)wantedread )
{
if ( !memcmp(&wantedbuf, &actualbuf, 0x1000uLL) )
{
++unchanged;
}
else
{
++changed;
v14 = 0LL;
written = 0LL;
do
{
v15 = pwrite64(fdout, (char *)&wantedbuf + v14, v6 - v14, v14 + pos);
if ( v15 == -1 )
err(1, "pwrite(%s, ..., %ld, %ld)", argv[1], wantedread - written, pos + written);
if ( !v15 )
__assert_fail("ret != 0", "oid.c", 0x51u, "main");
v6 = wantedread;
v14 = written + v15;
written = v14;
}
while ( v14 < (__int64)wantedread );
}
pos += v6;
goto LABEL_3;
}
}
v8 = lseek64(fdout, pos, 0);
v9 = wantedread;
if ( v8 == -1 )
err(1, "lseek(%s, %ld, SEEK_SET)", argv[1], pos);
do
{
++appended;
v10 = 0LL;
written = 0LL;
do
{
v11 = write(fdout, (char *)&wantedbuf + v10, v9);
if ( v11 == -1 )
err(1, "write(%s, ..., %ld)", argv[1], wantedread);
v9 = wantedread;
v10 = written + v11;
written = v10;
}
while ( v10 < (__int64)wantedread );
pos += v10;
v12 = read(fdin, &wantedbuf, 0x1000uLL);
v9 = v12;
if ( v12 == -1 )
goto LABEL_29;
wantedread = v12;
}
while ( v12 );
}
close(fdout);
printf("Blocks unchanged: %lu; changed: %lu; appended: %lu\n", unchanged, changed, appended);
result = 0;
}
else
{
fprintf(_bss_start, "Usage: %s <file>\n", *argv);
result = 64;
}
return result;
}

original_code:
int
main(int argc, char **argv) {
 ssize_t ret;
 if(argc != 2) {
  fprintf(stderr, "Usage: %s <file>\n", argv[0]);
  return 64;
 }
 fdout = open(argv[1], 02);
 if(fdout == -1) {
  err(1, "open(%s, r+)", argv[1]);
 }
 while(1) {
  ret = read(fdin, wantedbuf, 4096);
  if(ret == -1) {
   err(1, "read(STDIN, ..., %d)", 4096);
  }
  if(ret == 0) {
   goto done;
  }
  wantedread = ret;
  actualread = 0;
  do {
   ret = read(fdout, actualbuf + actualread, wantedread - actualread);
   if(ret == -1) {
    err(1, "read(fdout, ..., %ld)", wantedread - actualread);
   }
   if(ret == 0) {
    if(lseek(fdout, pos, 0) == -1) {
     err(1, "lseek(%s, %ld, SEEK_SET)", argv[1], pos);
    }
    goto extending;
   }
   actualread += ret;
  } while(wantedread > actualread);
  if(memcmp(wantedbuf, actualbuf, 4096) != 0) {
   changed++;
   written = 0;
   do {
    ret = pwrite(fdout, wantedbuf + written, wantedread - written, pos + written);
    if(ret == -1) {
     err(1, "pwrite(%s, ..., %ld, %ld)", argv[1], wantedread - written, pos + written);
    }
    ((void) sizeof ((ret != 0) ? 1 : 0), __extension__ ({ if (ret != 0) ; else __assert_fail ("ret != 0", "oid.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    written += ret;
   } while(wantedread > written);
  } else {
   unchanged++;
  }
  pos += wantedread;
 }
extending:
 do {
  appended++;
  written = 0;
  do {
   ret = write(fdout, wantedbuf + written, wantedread);
   if(ret == -1) {
    err(1, "write(%s, ..., %ld)", argv[1], wantedread);
   }
   written += ret;
  } while(wantedread > written);
  pos += written;
  ret = read(fdin, wantedbuf, 4096);
  if(ret == -1) {
   err(1, "read(STDIN, ..., %d)", 4096);
  }
  wantedread = ret;
 } while(ret != 0);
done:
 close(fdout);
 printf("Blocks unchanged: %lu; changed: %lu; appended: %lu\n", unchanged, changed, appended);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 long ret;
 if(argc != 2) {
  fprintf(stderr, "Usage: %s <file>\n", argv[0]);
  return 64;
 }
 fdout = open(argv[1], 02);
 if(fdout == -1) {
  err(1, "open(%s, r+)", argv[1]);
 }
 while(1) {
  ret = read(fdin, wantedbuf, 4096);
  if(ret == -1) {
   err(1, "read(STDIN, ..., %d)", 4096);
  }
  if(ret == 0) {
   goto done;
  }
  wantedread = ret;
  actualread = 0;
  do {
   ret = read(fdout, actualbuf + actualread, wantedread - actualread);
   if(ret == -1) {
    err(1, "read(fdout, ..., %ld)", wantedread - actualread);
   }
   if(ret == 0) {
    if(lseek(fdout, pos, 0) == -1) {
     err(1, "lseek(%s, %ld, SEEK_SET)", argv[1], pos);
    }
    goto extending;
   }
   actualread += ret;
  } while(wantedread > actualread);
  if(memcmp(wantedbuf, actualbuf, 4096) != 0) {
   changed++;
   written = 0;
   do {
    ret = pwrite(fdout, wantedbuf + written, wantedread - written, pos + written);
    if(ret == -1) {
     err(1, "pwrite(%s, ..., %ld, %ld)", argv[1], wantedread - written, pos + written);
    }
    ((void) sizeof ((ret != 0) ? 1 : 0), __extension__ ({ if (ret != 0) ; else __assert_fail ("ret != 0", "oid.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    written += ret;
   } while(wantedread > written);
  } else {
   unchanged++;
  }
  pos += wantedread;
 }
extending:
 do {
  appended++;
  written = 0;
  do {
   ret = write(fdout, wantedbuf + written, wantedread);
   if(ret == -1) {
    err(1, "write(%s, ..., %ld)", argv[1], wantedread);
   }
   written += ret;
  } while(wantedread > written);
  pos += written;
  ret = read(fdin, wantedbuf, 4096);
  if(ret == -1) {
   err(1, "read(STDIN, ..., %d)", 4096);
  }
  wantedread = ret;
 } while(ret != 0);
done:
 close(fdout);
 printf("Blocks unchanged: %lu; changed: %lu; appended: %lu\n", unchanged, changed, appended);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ret long


repo: Jille/splparser

decompiled_code:
char *__fastcall token_to_string(char a1)
{
unsigned __int8 v1; // di
char *result; // rax

v1 = a1 - 1;
result = 0LL;
if ( v1 <= 0x7Cu )
result = CSWTCH_3[v1];
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char a1)
{
unsigned __int8 v1; // di
char *result; // rax

v1 = a1 - 1;
result = 0LL;
if ( v1 <= 0x7Cu )
result = CSWTCH_3[v1];
return result;
}

original_code:
static const char *
token_to_string(char token) {
 switch(token) {
  case 1:
   return "INT";
  case 2:
   return "BOOL";
  case 3:
   return "VOID";
  case 4:
   return "WORD";
  case 5:
   return "NUMBER";
  case 6:
   return "IF";
  case 7:
   return "WHILE";
  case 8:
   return "ELSE";
  case 9:
   return "RETURN";
  case 10:
   return "TRUE";
  case 11:
   return "FALSE";
  case 12:
   return "AND";
  case 13:
   return "OR";
  case 14:
   return "EQ";
  case 15:
   return "NE";
  case 16:
   return "GTE";
  case 17:
   return "LTE";
  case '=':
   return "=";
  case ';':
   return ";";
  case ',':
   return ",";
  case '+':
   return "+";
  case '-':
   return "-";
  case '*':
   return "*";
  case '/':
   return "/";
  case '%':
   return "%";
  case ':':
   return ":";
  case '(':
   return "(";
  case ')':
   return ")";
  case '{':
   return "{";
  case '}':
   return "}";
  case '[':
   return "[";
  case ']':
   return "]";
  case '<':
   return "<";
  case '>':
   return ">";
  case '!':
   return "!";
  case '&':
   return "&";
  case '|':
   return "|";
 }
 return ((void *)0);
}

canonical_original_code:
static char *token_to_string(char token) {
 switch(token) {
  case 1:
   return "INT";
  case 2:
   return "BOOL";
  case 3:
   return "VOID";
  case 4:
   return "WORD";
  case 5:
   return "NUMBER";
  case 6:
   return "IF";
  case 7:
   return "WHILE";
  case 8:
   return "ELSE";
  case 9:
   return "RETURN";
  case 10:
   return "TRUE";
  case 11:
   return "FALSE";
  case 12:
   return "AND";
  case 13:
   return "OR";
  case 14:
   return "EQ";
  case 15:
   return "NE";
  case 16:
   return "GTE";
  case 17:
   return "LTE";
  case '=':
   return "=";
  case ';':
   return ";";
  case ',':
   return ",";
  case '+':
   return "+";
  case '-':
   return "-";
  case '*':
   return "*";
  case '/':
   return "/";
  case '%':
   return "%";
  case ':':
   return ":";
  case '(':
   return "(";
  case ')':
   return ")";
  case '{':
   return "{";
  case '}':
   return "}";
  case '[':
   return "[";
  case ']':
   return "]";
  case '<':
   return "<";
  case '>':
   return ">";
  case '!':
   return "!";
  case '&':
   return "&";
  case '|':
   return "|";
 }
 return ((void *)0);
}

variable_types: token char

return_type: char *


decompiled_code:
__int64 __fastcall string_to_token(const char *a1)
{
unsigned int v1; // er8

v1 = *((unsigned __int8 *)a1 + 1);
if ( (_BYTE)v1 )
{
v1 = 1;
if ( strcmp("T_INT", a1) )
{
v1 = 2;
if ( strcmp("T_BOOL", a1) )
{
v1 = 3;
if ( strcmp("T_VOID", a1) )
{
v1 = 4;
if ( strcmp("T_WORD", a1) )
{
v1 = 5;
if ( strcmp("T_NUMBER", a1) )
{
v1 = 6;
if ( strcmp("T_IF", a1) )
{
v1 = 7;
if ( strcmp("T_WHILE", a1) )
{
v1 = 8;
if ( strcmp("T_ELSE", a1) )
{
v1 = 9;
if ( strcmp("T_RETURN", a1) )
{
v1 = 10;
if ( strcmp("T_TRUE", a1) )
{
v1 = 11;
if ( strcmp("T_FALSE", a1) )
{
v1 = 12;
if ( strcmp("T_AND", a1) )
{
v1 = 13;
if ( strcmp("T_OR", a1) )
{
v1 = 14;
if ( strcmp("T_EQ", a1) )
{
v1 = 15;
if ( strcmp("T_NE", a1) )
{
v1 = 16;
if ( strcmp("T_GTE", a1) )
v1 = strcmp("T_LTE", a1) == 0 ? 0x11 : 0;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
switch ( *a1 )
{
case '!':
case '%':
case '&':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '/':
case ':':
case ';':
case '<':
case '=':
case '>':
case '[':
case ']':
case '{':
case '|':
case '}':
v1 = *(unsigned __int8 *)a1;
break;
default:
return v1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // er8

v1 = *((unsigned __int8 *)a1 + 1);
if ( (_BYTE)v1 )
{
v1 = 1;
if ( strcmp("T_INT", a1) )
{
v1 = 2;
if ( strcmp("T_BOOL", a1) )
{
v1 = 3;
if ( strcmp("T_VOID", a1) )
{
v1 = 4;
if ( strcmp("T_WORD", a1) )
{
v1 = 5;
if ( strcmp("T_NUMBER", a1) )
{
v1 = 6;
if ( strcmp("T_IF", a1) )
{
v1 = 7;
if ( strcmp("T_WHILE", a1) )
{
v1 = 8;
if ( strcmp("T_ELSE", a1) )
{
v1 = 9;
if ( strcmp("T_RETURN", a1) )
{
v1 = 10;
if ( strcmp("T_TRUE", a1) )
{
v1 = 11;
if ( strcmp("T_FALSE", a1) )
{
v1 = 12;
if ( strcmp("T_AND", a1) )
{
v1 = 13;
if ( strcmp("T_OR", a1) )
{
v1 = 14;
if ( strcmp("T_EQ", a1) )
{
v1 = 15;
if ( strcmp("T_NE", a1) )
{
v1 = 16;
if ( strcmp("T_GTE", a1) )
v1 = strcmp("T_LTE", a1) == 0 ? 0x11 : 0;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
switch ( *a1 )
{
case '!':
case '%':
case '&':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '/':
case ':':
case ';':
case '<':
case '=':
case '>':
case '[':
case ']':
case '{':
case '|':
case '}':
v1 = *(unsigned __int8 *)a1;
break;
default:
return v1;
}
}
return v1;
}

original_code:
static char
string_to_token(char *str) {
 if(str[1] == 0) {
  switch(str[0]) {
   case '=':
   case ';':
   case ',':
   case '+':
   case '-':
   case '*':
   case '/':
   case '%':
   case ':':
   case '(':
   case ')':
   case '{':
   case '}':
   case '[':
   case ']':
   case '<':
   case '>':
   case '!':
   case '&':
   case '|':
    return str[0];
   default:
    return 0;
  }
 }
 if(strcmp("T_INT", str) == 0) {
  return 1;
 } else
 if(strcmp("T_BOOL", str) == 0) {
  return 2;
 } else
 if(strcmp("T_VOID", str) == 0) {
  return 3;
 } else
 if(strcmp("T_WORD", str) == 0) {
  return 4;
 } else
 if(strcmp("T_NUMBER", str) == 0) {
  return 5;
 } else
 if(strcmp("T_IF", str) == 0) {
  return 6;
 } else
 if(strcmp("T_WHILE", str) == 0) {
  return 7;
 } else
 if(strcmp("T_ELSE", str) == 0) {
  return 8;
 } else
 if(strcmp("T_RETURN", str) == 0) {
  return 9;
 } else
 if(strcmp("T_TRUE", str) == 0) {
  return 10;
 } else
 if(strcmp("T_FALSE", str) == 0) {
  return 11;
 } else
 if(strcmp("T_AND", str) == 0) {
  return 12;
 } else
 if(strcmp("T_OR", str) == 0) {
  return 13;
 } else
 if(strcmp("T_EQ", str) == 0) {
  return 14;
 } else
 if(strcmp("T_NE", str) == 0) {
  return 15;
 } else
 if(strcmp("T_GTE", str) == 0) {
  return 16;
 } else
 if(strcmp("T_LTE", str) == 0) {
  return 17;
 } else
  return 0;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall get_id_for_rule(signed int *a1, const char *a2)
{
int v3; // ebp
const char **v4; // rbx
int v5; // er12
__int64 result; // rax
signed int v7; // ebp
int *v8; // rax
void *v9; // rdi
unsigned int v10; // er12
int *v11; // r13

v3 = *a1;
if ( *a1 < 0 )
{
LABEL_6:
v7 = v3 + 1;
*a1 = v7;
if ( (unsigned int)v7 > 0x7CF )
_assert_fail("g->lastrule < sizeof(g->rules) / sizeof(struct rule)", "grammar.c", 0x14u, "get_id_for_rule");
v8 = &a1[44 * v7 + 2];
*(_QWORD *)v8 = 0LL;
*((_QWORD *)v8 + 21) = 0LL;
v9 = (void *)((unsigned __int64)&a1[44 * v7 + 4] & 0xFFFFFFFFFFFFFFF8LL);
memset(v9, 0, 8LL * ((unsigned int)((_DWORD)v8 - (_DWORD)v9 + 176) >> 3));
v10 = *a1;
v11 = &a1[44 * *a1];
v11[2] = v10;
*((_QWORD *)v11 + 2) = strdup(a2);
result = v10;
}
else
{
v4 = (const char **)(a1 + 4);
v5 = 0;
while ( strcmp(a2, *v4) )
{
++v5;
v4 += 22;
if ( v3 < v5 )
goto LABEL_6;
}
result = (unsigned int)v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(signed int *a1, const char *a2)
{
int v3; // ebp
const char **v4; // rbx
int v5; // er12
__int64 result; // rax
signed int v7; // ebp
int *v8; // rax
void *v9; // rdi
unsigned int v10; // er12
int *v11; // r13

v3 = *a1;
if ( *a1 < 0 )
{
LABEL_6:
v7 = v3 + 1;
*a1 = v7;
if ( (unsigned int)v7 > 0x7CF )
_assert_fail("g->lastrule < sizeof(g->rules) / sizeof(struct rule)", "grammar.c", 0x14u, "get_id_for_rule");
v8 = &a1[44 * v7 + 2];
*(_QWORD *)v8 = 0LL;
*((_QWORD *)v8 + 21) = 0LL;
v9 = (void *)((unsigned __int64)&a1[44 * v7 + 4] & 0xFFFFFFFFFFFFFFF8LL);
memset(v9, 0, 8LL * ((unsigned int)((_DWORD)v8 - (_DWORD)v9 + 176) >> 3));
v10 = *a1;
v11 = &a1[44 * *a1];
v11[2] = v10;
*((_QWORD *)v11 + 2) = strdup(a2);
result = v10;
}
else
{
v4 = (const char **)(a1 + 4);
v5 = 0;
while ( strcmp(a2, *v4) )
{
++v5;
v4 += 22;
if ( v3 < v5 )
goto LABEL_6;
}
result = (unsigned int)v5;
}
return result;
}

original_code:
int
get_id_for_rule(grammar *g, char *rule) {
 int i;
 for(i = 0; g->lastrule >= i; i++) {
  if(strcmp(rule, g->rules[i].name) == 0) {
   return i;
  }
 }
 g->lastrule++;
 ((void) sizeof ((g->lastrule < sizeof(g->rules) / sizeof(struct rule)) ? 1 : 0), __extension__ ({ if (g->lastrule < sizeof(g->rules) / sizeof(struct rule)) ; else __assert_fail ("g->lastrule < sizeof(g->rules) / sizeof(struct rule)", "grammar.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 memset(&g->rules[g->lastrule], 0, sizeof(struct rule));
 g->rules[g->lastrule].id = g->lastrule;
 g->rules[g->lastrule].name = strdup(rule);
 return g->lastrule;
}

canonical_original_code:
int get_id_for_rule(struct _grammar *g, char *rule) {
 int i;
 for(i = 0; g->lastrule >= i; i++) {
  if(strcmp(rule, g->rules[i].name) == 0) {
   return i;
  }
 }
 g->lastrule++;
 ((void) sizeof ((g->lastrule < sizeof(g->rules) / sizeof(struct rule)) ? 1 : 0), __extension__ ({ if (g->lastrule < sizeof(g->rules) / sizeof(struct rule)) ; else __assert_fail ("g->lastrule < sizeof(g->rules) / sizeof(struct rule)", "grammar.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 memset(&g->rules[g->lastrule], 0, sizeof(struct rule));
 g->rules[g->lastrule].id = g->lastrule;
 g->rules[g->lastrule].name = strdup(rule);
 return g->lastrule;
}

variable_types: struct _grammar { int lastrule; struct rule { int id; char *name; struct rulepart { int is_literal; union { int rule; char token; }; struct rulepart *next; } *branches[20]; } rules[2000]; } *

variable_types:
rule
char *

user_defined_types: struct rule { int id; char *name; struct rulepart *branches[20]; }

user_defined_types: struct _grammar { int lastrule; struct rule rules[2000]; }


original_code:
struct rulepart *
parse_branch(grammar *g, char *str) {
 char *part, *tokenizer;
 struct rulepart *head;
 struct rulepart **tail = &head;
 ((void) sizeof ((strchr(str, '|') == ((void *)0)) ? 1 : 0), __extension__ ({ if (strchr(str, '|') == ((void *)0)) ; else __assert_fail ("strchr(str, '|') == NULL", "grammar.c", 36, __extension__ __PRETTY_FUNCTION__); }));
 part = strtok_r(str, " ", &tokenizer);
 do {
  *tail = malloc(sizeof(struct rulepart));
  if(part[0] == '\'' && part[2] == '\'' && part[3] == 0) {
   (*tail)->is_literal = 1;
   (*tail)->token = part[1];
  } else if(((*tail)->token = string_to_token(part)) != 0) {
   (*tail)->is_literal = 1;
  } else {
   (*tail)->is_literal = 0;
   (*tail)->rule = get_id_for_rule(g, part);
  }
  tail = &(*tail)->next;
 } while((part = strtok_r(((void *)0), " ", &tokenizer)) != ((void *)0));
 *tail = ((void *)0);
 return head;
}

canonical_original_code:
struct rulepart *parse_branch(struct _grammar *g, char *str) {
 char *part; char *tokenizer;
 struct rulepart *head;
 struct rulepart **tail = &head;
 ((void) sizeof ((strchr(str, '|') == ((void *)0)) ? 1 : 0), __extension__ ({ if (strchr(str, '|') == ((void *)0)) ; else __assert_fail ("strchr(str, '|') == NULL", "grammar.c", 36, __extension__ __PRETTY_FUNCTION__); }));
 part = strtok_r(str, " ", &tokenizer);
 do {
  *tail = malloc(sizeof(struct rulepart));
  if(part[0] == '\'' && part[2] == '\'' && part[3] == 0) {
   (*tail)->is_literal = 1;
   (*tail)->token = part[1];
  } else if(((*tail)->token = string_to_token(part)) != 0) {
   (*tail)->is_literal = 1;
  } else {
   (*tail)->is_literal = 0;
   (*tail)->rule = get_id_for_rule(g, part);
  }
  tail = &(*tail)->next;
 } while((part = strtok_r(((void *)0), " ", &tokenizer)) != ((void *)0));
 *tail = ((void *)0);
 return head;
}

variable_types: struct _grammar { int lastrule; struct rule { int id; char *name; struct rulepart *branches[20]; } rules[2000]; } *

variable_types:
part
char *

variable_types:
tokenizer
char *

variable_types: struct rulepart { int is_literal; union { int rule; char token; }; struct rulepart *next; } **


original_code:
void
show_grammar(grammar *g) {
 int i;
 for(i = 0; g->lastrule >= i; i++) {
  if(g->rules[i].branches[0] == ((void *)0)) {
   continue;
  }
  int b;
  for(b = 0; g->rules[i].branches[b] != ((void *)0); b++) {
   struct rulepart *p = g->rules[i].branches[b];
   printf("\t");
   do {
    if(p->is_literal) {
     printf("%s ", token_to_string(p->token));
    } else {
     printf("%s ", g->rules[p->rule].name);
    }
   } while((p = p->next) != ((void *)0));
   printf("\n");
  }
 }
}

canonical_original_code:
void show_grammar(struct _grammar *g) {
 int i;
 for(i = 0; g->lastrule >= i; i++) {
  if(g->rules[i].branches[0] == ((void *)0)) {
   continue;
  }
  int b;
  for(b = 0; g->rules[i].branches[b] != ((void *)0); b++) {
   struct rulepart *p = g->rules[i].branches[b];
   printf("\t");
   do {
    if(p->is_literal) {
     printf("%s ", token_to_string(p->token));
    } else {
     printf("%s ", g->rules[p->rule].name);
    }
   } while((p = p->next) != ((void *)0));
   printf("\n");
  }
 }
}

variable_types: i int

variable_types: b int

variable_types: struct rulepart { int is_literal; union { int rule; char token; }; struct rulepart *next; } *


decompiled_code:
__int64 __fastcall scan_initial_int(_QWORD *a1, int a2)
{
int v2; // ebx
unsigned int v3; // er8
__int64 v4; // rax

v2 = a2 - 48;
while ( !(unsigned int)generator_eof(*a1) )
{
v3 = generator_shift(*a1);
if ( v3 - 48 > 9 )
goto LABEL_6;
v2 = v3 - 48 + 10 * v2;
}
v3 = -1;
LABEL_6:
v4 = a1[1];
*(_BYTE *)v4 = 5;
*(_DWORD *)(v4 + 8) = v2;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2)
{
int v2; // ebx
unsigned int v3; // er8
__int64 v4; // rax

v2 = a2 - 48;
while ( !(unsigned int)generator_eof(*a1) )
{
v3 = generator_shift(*a1);
if ( v3 - 48 > 9 )
goto LABEL_6;
v2 = v3 - 48 + 10 * v2;
}
v3 = -1;
LABEL_6:
v4 = a1[1];
*(_BYTE *)v4 = 5;
*(_DWORD *)(v4 + 8) = v2;
return v3;
}

original_code:
static int
scan_initial_int(struct scannerstate *st, int in) {
 int num = in - '0';
 while(!generator_eof(st->ig)) {
  in = (intptr_t)generator_shift(st->ig);
  switch(in) {
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
    num *= 10;
    num += in - '0';
    break;
   default:
    goto done;
  }
 }
 in = -1;
done:
 st->active->type = 5;
 st->active->value.ival = num;
 return in;
}

canonical_original_code:
static int scan_initial_int(struct scannerstate *st, int in) {
 int num = in - '0';
 while(!generator_eof(st->ig)) {
  in = (long)generator_shift(st->ig);
  switch(in) {
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
    num *= 10;
    num += in - '0';
    break;
   default:
    goto done;
  }
 }
 in = -1;
done:
 st->active->type = 5;
 st->active->value.ival = num;
 return in;
}

variable_types: struct scannerstate { struct _generator { unsigned long thr; void (*function)(struct _generator *, void *); void *arg; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int async; struct generator_item { struct generator_item *next; void *item; } *ready; union { struct { void *item; int has_item; }; struct { struct generator_item *output; struct generator_item **output_last; }; }; } *ig; struct token { char type; union { int ival; char bval; char *sval; } value; int lineno; } *active; int curline; char *error; } *

variable_types: in int

variable_types: num int

user_defined_types: struct scannerstate { struct _generator *ig; struct token *active; int curline; char *error; }

user_defined_types: struct _generator { unsigned long thr; void (*function)(struct _generator *, void *); void *arg; union pthread_mutex_t lock; union pthread_cond_t cond; int async; struct generator_item *ready; union { struct { void *item; int has_item; }; struct { struct generator_item *output; struct generator_item **output_last; }; }; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


decompiled_code:
__int64 __fastcall scan_initial_sign(char **a1, int a2)
{
__int64 result; // rax
int v3; // er8

*a1[1] = a2;
switch ( a2 )
{
case '!':
case '&':
case '<':
case '=':
case '>':
case '|':
v3 = generator_eof(*a1);
result = 0xFFFFFFFFLL;
if ( !v3 )
{
result = generator_shift(*a1);
if ( (_DWORD)result == 61 )
{
if ( a2 == 61 )
{
*a1[1] = 14;
result = 4294967293LL;
}
else if ( a2 > 61 )
{
if ( a2 == 62 )
{
*a1[1] = 16;
result = 4294967293LL;
}
}
else if ( a2 == 33 )
{
*a1[1] = 15;
result = 4294967293LL;
}
else if ( a2 == 60 )
{
*a1[1] = 17;
result = 4294967293LL;
}
}
else if ( (_DWORD)result == 124 || (_DWORD)result == 38 )
{
if ( a2 != (_DWORD)result )
goto LABEL_2;
*a1[1] = (a2 != 38) + 12;
result = 4294967293LL;
}
}
break;
case '%':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '/':
case ':':
case ';':
case '[':
case ']':
case '{':
case '}':
result = 4294967293LL;
break;
default:
LABEL_2:
asprintf(a1 + 3, "Operator '%c' is unknown.", (unsigned int)a2);
result = 4294967294LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char **a1, int a2)
{
__int64 result; // rax
int v3; // er8

*a1[1] = a2;
switch ( a2 )
{
case '!':
case '&':
case '<':
case '=':
case '>':
case '|':
v3 = generator_eof(*a1);
result = 0xFFFFFFFFLL;
if ( !v3 )
{
result = generator_shift(*a1);
if ( (_DWORD)result == 61 )
{
if ( a2 == 61 )
{
*a1[1] = 14;
result = 4294967293LL;
}
else if ( a2 > 61 )
{
if ( a2 == 62 )
{
*a1[1] = 16;
result = 4294967293LL;
}
}
else if ( a2 == 33 )
{
*a1[1] = 15;
result = 4294967293LL;
}
else if ( a2 == 60 )
{
*a1[1] = 17;
result = 4294967293LL;
}
}
else if ( (_DWORD)result == 124 || (_DWORD)result == 38 )
{
if ( a2 != (_DWORD)result )
goto LABEL_2;
*a1[1] = (a2 != 38) + 12;
result = 4294967293LL;
}
}
break;
case '%':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '/':
case ':':
case ';':
case '[':
case ']':
case '{':
case '}':
result = 4294967293LL;
break;
default:
LABEL_2:
asprintf(a1 + 3, "Operator '%c' is unknown.", (unsigned int)a2);
result = 4294967294LL;
break;
}
return result;
}

original_code:
static int
scan_initial_sign(struct scannerstate *st, int in) {
 int in2;
 st->active->type = in;
 switch(in) {
  case ';':
  case ',':
  case '+':
  case '-':
  case '*':
  case '/':
  case '%':
  case ':':
  case '(':
  case ')':
  case '{':
  case '}':
  case '[':
  case ']':
   return -3;
  case '=':
  case '!':
  case '<':
  case '>':
  case '&':
  case '|':
   if(generator_eof(st->ig)) {
    in2 = -1;
   } else {
    in2 = (intptr_t)generator_shift(st->ig);
   }
   switch(in2) {
    case '=':
     switch(in) {
      case '=':
       st->active->type = 14;
       break;
      case '!':
       st->active->type = 15;
       break;
      case '>':
       st->active->type = 16;
       break;
      case '<':
       st->active->type = 17;
       break;
      default:
       return in2;
     }
     return -3;
    case '&':
    case '|':
     if(in == in2) {
      st->active->type = (in == '&') ? 12 : 13;
      return -3;
     }
     break;
    case -1:
    default:
     if(in2 == '&' || in2 == '|') {
      break;
     }
     return in2;
   }
 }
 asprintf(&st->error, "Operator '%c' is unknown.", in);
 return -2;
}

canonical_original_code:
static int scan_initial_sign(struct scannerstate *st, int in) {
 int in2;
 st->active->type = in;
 switch(in) {
  case ';':
  case ',':
  case '+':
  case '-':
  case '*':
  case '/':
  case '%':
  case ':':
  case '(':
  case ')':
  case '{':
  case '}':
  case '[':
  case ']':
   return -3;
  case '=':
  case '!':
  case '<':
  case '>':
  case '&':
  case '|':
   if(generator_eof(st->ig)) {
    in2 = -1;
   } else {
    in2 = (long)generator_shift(st->ig);
   }
   switch(in2) {
    case '=':
     switch(in) {
      case '=':
       st->active->type = 14;
       break;
      case '!':
       st->active->type = 15;
       break;
      case '>':
       st->active->type = 16;
       break;
      case '<':
       st->active->type = 17;
       break;
      default:
       return in2;
     }
     return -3;
    case '&':
    case '|':
     if(in == in2) {
      st->active->type = (in == '&') ? 12 : 13;
      return -3;
     }
     break;
    case -1:
    default:
     if(in2 == '&' || in2 == '|') {
      break;
     }
     return in2;
   }
 }
 asprintf(&st->error, "Operator '%c' is unknown.", in);
 return -2;
}

user_defined_types: struct token { char type; union { int ival; char bval; char *sval; } value; int lineno; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct generator_item { struct generator_item *next; void *item; }


decompiled_code:
__int64 __fastcall scan_initial_upper(char **a1, char a2)
{
char *i; // rbp
int v3; // eax
unsigned int v4; // er8
int v6; // [rsp+0h] [rbp-28h] BYREF
__int16 v7; // [rsp+4h] [rbp-24h]
char v8; // [rsp+10h] [rbp-18h] BYREF

LOBYTE(v6) = a2;
for ( i = (char *)&v6 + 1; ; *(i - 1) = v3 )
{
if ( (unsigned int)generator_eof(*a1) )
{
v4 = -1;
goto LABEL_12;
}
if ( i == &v8 )
{
asprintf(a1 + 3, "Word '%.*s...' too long.", 16, (const char *)&v6);
return (unsigned int)-2;
}
v3 = generator_shift(*a1);
v4 = v3;
if ( v3 <= 90 )
break;
if ( (unsigned int)(v3 - 97) > 0x19 )
goto LABEL_12;
LABEL_10:
++i;
}
if ( v3 > 64 )
goto LABEL_10;
if ( (unsigned int)(v3 - 48) <= 9 )
{
asprintf(a1 + 3, "Keyword '%.*s...' contains digit.", i - (char *)&v6, (const char *)&v6);
return (unsigned int)-2;
}
LABEL_12:
*i = 0;
if ( v6 != 1702195796 || (_BYTE)v7 )
{
if ( v6 == 1936482630 && v7 == 101 )
{
*a1[1] = 11;
}
else if ( v6 == 7630409 )
{
*a1[1] = 1;
}
else if ( v6 != 1819242306 || (_BYTE)v7 )
{
if ( v6 != 1684631382 || (_BYTE)v7 )
{
asprintf(a1 + 3, "Keyword '%s...' is unknown.", (const char *)&v6);
v4 = -2;
}
else
{
*a1[1] = 3;
}
}
else
{
*a1[1] = 2;
}
}
else
{
*a1[1] = 10;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char **a1, char a2)
{
char *i; // rbp
int v3; // eax
unsigned int v4; // er8
int v6; // [rsp+0h] [rbp-28h] BYREF
__int16 v7; // [rsp+4h] [rbp-24h]
char v8; // [rsp+10h] [rbp-18h] BYREF

LOBYTE(v6) = a2;
for ( i = (char *)&v6 + 1; ; *(i - 1) = v3 )
{
if ( (unsigned int)generator_eof(*a1) )
{
v4 = -1;
goto LABEL_12;
}
if ( i == &v8 )
{
asprintf(a1 + 3, "Word '%.*s...' too long.", 16, (const char *)&v6);
return (unsigned int)-2;
}
v3 = generator_shift(*a1);
v4 = v3;
if ( v3 <= 90 )
break;
if ( (unsigned int)(v3 - 97) > 0x19 )
goto LABEL_12;
LABEL_10:
++i;
}
if ( v3 > 64 )
goto LABEL_10;
if ( (unsigned int)(v3 - 48) <= 9 )
{
asprintf(a1 + 3, "Keyword '%.*s...' contains digit.", i - (char *)&v6, (const char *)&v6);
return (unsigned int)-2;
}
LABEL_12:
*i = 0;
if ( v6 != 1702195796 || (_BYTE)v7 )
{
if ( v6 == 1936482630 && v7 == 101 )
{
*a1[1] = 11;
}
else if ( v6 == 7630409 )
{
*a1[1] = 1;
}
else if ( v6 != 1819242306 || (_BYTE)v7 )
{
if ( v6 != 1684631382 || (_BYTE)v7 )
{
asprintf(a1 + 3, "Keyword '%s...' is unknown.", (const char *)&v6);
v4 = -2;
}
else
{
*a1[1] = 3;
}
}
else
{
*a1[1] = 2;
}
}
else
{
*a1[1] = 10;
}
return v4;
}

original_code:
static int
scan_initial_upper(struct scannerstate *st, int in) {
 char buf[16];
 char *bufp = buf;
 *bufp++ = in;
 while(!generator_eof(st->ig)) {
  if(buf + sizeof(buf) == bufp) {
   asprintf(&st->error, "Word '%.*s...' too long.", (int)sizeof(buf), buf);
   return -2;
  }
  in = (intptr_t)generator_shift(st->ig);
  switch(in) {
   case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
    *bufp++ = in;
    break;
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
    asprintf(&st->error, "Keyword '%.*s...' contains digit.", (int)(bufp - buf), buf);
    return -2;
   default:
    goto done;
  }
 }
 in = -1;
done:
 *bufp = 0;
 if(strcmp(buf, "True") == 0) {
  st->active->type = 10;
 } else if(strcmp(buf, "False") == 0) {
  st->active->type = 11;
 } else if(strcmp(buf, "Int") == 0) {
  st->active->type = 1;
 } else if(strcmp(buf, "Bool") == 0) {
  st->active->type = 2;
 } else if(strcmp(buf, "Void") == 0) {
  st->active->type = 3;
 } else {
  asprintf(&st->error, "Keyword '%s...' is unknown.", buf);
  return -2;
 }
 return in;
}

canonical_original_code:
static int scan_initial_upper(struct scannerstate *st, int in) {
 char buf[16];
 char *bufp = buf;
 *bufp++ = in;
 while(!generator_eof(st->ig)) {
  if(buf + sizeof(buf) == bufp) {
   asprintf(&st->error, "Word '%.*s...' too long.", (int)sizeof(buf), buf);
   return -2;
  }
  in = (long)generator_shift(st->ig);
  switch(in) {
   case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
    *bufp++ = in;
    break;
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
    asprintf(&st->error, "Keyword '%.*s...' contains digit.", (int)(bufp - buf), buf);
    return -2;
   default:
    goto done;
  }
 }
 in = -1;
done:
 *bufp = 0;
 if(strcmp(buf, "True") == 0) {
  st->active->type = 10;
 } else if(strcmp(buf, "False") == 0) {
  st->active->type = 11;
 } else if(strcmp(buf, "Int") == 0) {
  st->active->type = 1;
 } else if(strcmp(buf, "Bool") == 0) {
  st->active->type = 2;
 } else if(strcmp(buf, "Void") == 0) {
  st->active->type = 3;
 } else {
  asprintf(&st->error, "Keyword '%s...' is unknown.", buf);
  return -2;
 }
 return in;
}

variable_types:
buf
char [16]

variable_types:
bufp
char *


decompiled_code:
__int64 __fastcall scan_initial_lower(char **a1, char a2)
{
char *v2; // rbp
int v3; // eax
unsigned int v4; // er13
int v5; // eax
char *v6; // rbx
int v8; // [rsp+0h] [rbp-A8h] BYREF
__int16 v9; // [rsp+4h] [rbp-A4h]
char v10; // [rsp+6h] [rbp-A2h]
char v11; // [rsp+80h] [rbp-28h] BYREF

LOBYTE(v8) = a2;
v2 = (char *)&v8 + 1;
while ( !(unsigned int)generator_eof(*a1) )
{
if ( v2 == &v11 )
{
v4 = -2;
asprintf(a1 + 3, "Word '%.*s...' too long.", 128, (const char *)&v8);
return v4;
}
v3 = generator_shift(*a1);
v4 = v3;
if ( v3 > 90 )
{
if ( (unsigned int)(v3 - 97) > 0x19 )
goto LABEL_9;
}
else
{
if ( v3 > 64 )
{
v4 = -2;
asprintf(a1 + 3, "Word '%.*s...' contains invalid uppercase character.", v2 - (char *)&v8, (const char *)&v8);
return v4;
}
if ( (unsigned int)(v3 - 48) > 9 )
goto LABEL_9;
}
*v2++ = v3;
}
v4 = -1;
LABEL_9:
*v2 = 0;
if ( (_WORD)v8 != 26217 || (v5 = 0, BYTE2(v8)) )
v5 = 1;
v6 = a1[1];
if ( v5 )
{
if ( v8 == 1818847351 && v9 == 101 )
{
*v6 = 7;
}
else if ( v8 != 1702063205 || (_BYTE)v9 )
{
if ( v8 == 1970562418 && v9 == 28274 && !v10 )
{
*v6 = 9;
}
else
{
*v6 = 4;
*((_QWORD *)v6 + 1) = strdup((const char *)&v8);
}
}
else
{
*v6 = 8;
}
}
else
{
*v6 = 6;
}
return v4;
}

original_code:
static int
scan_initial_lower(struct scannerstate *st, int in) {
 char buf[128];
 char *bufp = buf;
 *bufp++ = in;
 while(!generator_eof(st->ig)) {
  if(buf + sizeof(buf) == bufp) {
   asprintf(&st->error, "Word '%.*s...' too long.", (int)sizeof(buf), buf);
   return -2;
  }
  in = (intptr_t)generator_shift(st->ig);
  switch(in) {
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
   case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
    *bufp++ = in;
    break;
   case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
    asprintf(&st->error, "Word '%.*s...' contains invalid uppercase character.", (int)(bufp - buf), buf);
    return -2;
   default:
    goto done;
  }
 }
 in = -1;
done:
 *bufp = 0;
 if(strcmp(buf, "if") == 0) {
  st->active->type = 6;
 } else if(strcmp(buf, "while") == 0) {
  st->active->type = 7;
 } else if(strcmp(buf, "else") == 0) {
  st->active->type = 8;
 } else if(strcmp(buf, "return") == 0) {
  st->active->type = 9;
 } else {
  st->active->type = 4;
  st->active->value.sval = strdup(buf);
 }
 return in;
}

canonical_original_code:
static int scan_initial_lower(struct scannerstate *st, int in) {
 char buf[128];
 char *bufp = buf;
 *bufp++ = in;
 while(!generator_eof(st->ig)) {
  if(buf + sizeof(buf) == bufp) {
   asprintf(&st->error, "Word '%.*s...' too long.", (int)sizeof(buf), buf);
   return -2;
  }
  in = (long)generator_shift(st->ig);
  switch(in) {
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
   case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
    *bufp++ = in;
    break;
   case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
    asprintf(&st->error, "Word '%.*s...' contains invalid uppercase character.", (int)(bufp - buf), buf);
    return -2;
   default:
    goto done;
  }
 }
 in = -1;
done:
 *bufp = 0;
 if(strcmp(buf, "if") == 0) {
  st->active->type = 6;
 } else if(strcmp(buf, "while") == 0) {
  st->active->type = 7;
 } else if(strcmp(buf, "else") == 0) {
  st->active->type = 8;
 } else if(strcmp(buf, "return") == 0) {
  st->active->type = 9;
 } else {
  st->active->type = 4;
  st->active->value.sval = strdup(buf);
 }
 return in;
}

variable_types:
buf
char [128]


decompiled_code:
__int64 __fastcall gen_tokens(__int64 a1, const char *a2)
{
unsigned int v2; // ebp
_DWORD *v3; // rax
unsigned int v4; // eax
__int64 result; // rax
_DWORD *v6; // rax
unsigned int v7; // edx
char *v8; // [rsp+0h] [rbp-38h] BYREF
_DWORD *v9; // [rsp+8h] [rbp-30h]
unsigned int v10; // [rsp+10h] [rbp-28h]
char *ptr; // [rsp+18h] [rbp-20h] BYREF

v2 = -3;
v3 = malloc(0x18uLL);
*(_BYTE *)v3 = 0;
v3[4] = 1;
v9 = v3;
v10 = 1;
v8 = (char *)generator_create(&gen_input, a2, 1LL);
while ( v2 != -3 )
{
if ( v2 > 0xFF )
_assert_fail("in >= 0 && in < 256", "scanner.c", 0x2Bu, "gen_tokens");
v4 = v2 - 9;
LABEL_5:
switch ( v4 )
{
case 0u:
case 4u:
case 0x17u:
goto LABEL_7;
case 1u:
++v10;
goto LABEL_7;
case 0x18u:
case 0x1Cu:
case 0x1Du:
case 0x1Fu:
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x26u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x52u:
case 0x54u:
case 0x72u:
case 0x73u:
case 0x74u:
v2 = scan_initial_sign(&v8, v2);
goto LABEL_12;
case 0x27u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Bu:
case 0x2Cu:
case 0x2Du:
case 0x2Eu:
case 0x2Fu:
case 0x30u:
v2 = scan_initial_int(&v8, v2);
goto LABEL_12;
case 0x38u:
case 0x39u:
case 0x3Au:
case 0x3Bu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x3Fu:
case 0x40u:
case 0x41u:
case 0x42u:
case 0x43u:
case 0x44u:
case 0x45u:
case 0x46u:
case 0x47u:
case 0x48u:
case 0x49u:
case 0x4Au:
case 0x4Bu:
case 0x4Cu:
case 0x4Du:
case 0x4Eu:
case 0x4Fu:
case 0x50u:
case 0x51u:
v2 = scan_initial_upper(&v8, v2);
goto LABEL_12;
case 0x58u:
case 0x59u:
case 0x5Au:
case 0x5Bu:
case 0x5Cu:
case 0x5Du:
case 0x5Eu:
case 0x5Fu:
case 0x60u:
case 0x61u:
case 0x62u:
case 0x63u:
case 0x64u:
case 0x65u:
case 0x66u:
case 0x67u:
case 0x68u:
case 0x69u:
case 0x6Au:
case 0x6Bu:
case 0x6Cu:
case 0x6Du:
case 0x6Eu:
case 0x6Fu:
case 0x70u:
case 0x71u:
v2 = scan_initial_lower(&v8, v2);
LABEL_12:
if ( v2 == -2 )
goto LABEL_10;
if ( v2 == -4 )
goto LABEL_7;
generator_yield(a1, v9);
v6 = malloc(0x18uLL);
v7 = v10;
v9 = v6;
*(_BYTE *)v6 = 0;
v6[4] = v7;
break;
default:
goto LABEL_9;
}
}
LABEL_7:
result = generator_eof(v8);
if ( !(_DWORD)result )
{
v2 = generator_shift(v8);
v4 = v2 - 9;
if ( v2 - 9 > 0x74 )
{
LABEL_9:
asprintf(&ptr, "Unknown character %c (%d) found", v2, v2);
LABEL_10:
fprintf(stderr, "%s: Error from scanner: %s at line %d\n", a2, ptr, v10);
free(ptr);
exit(1);
}
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
unsigned int v2; // ebp
_DWORD *v3; // rax
unsigned int v4; // eax
__int64 result; // rax
_DWORD *v6; // rax
unsigned int v7; // edx
char *v8; // [rsp+0h] [rbp-38h] BYREF
_DWORD *v9; // [rsp+8h] [rbp-30h]
unsigned int v10; // [rsp+10h] [rbp-28h]
char *ptr; // [rsp+18h] [rbp-20h] BYREF

v2 = -3;
v3 = malloc(0x18uLL);
*(_BYTE *)v3 = 0;
v3[4] = 1;
v9 = v3;
v10 = 1;
v8 = (char *)generator_create(&gen_input, a2, 1LL);
while ( v2 != -3 )
{
if ( v2 > 0xFF )
_assert_fail("in >= 0 && in < 256", "scanner.c", 0x2Bu, "gen_tokens");
v4 = v2 - 9;
LABEL_5:
switch ( v4 )
{
case 0u:
case 4u:
case 0x17u:
goto LABEL_7;
case 1u:
++v10;
goto LABEL_7;
case 0x18u:
case 0x1Cu:
case 0x1Du:
case 0x1Fu:
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x26u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x52u:
case 0x54u:
case 0x72u:
case 0x73u:
case 0x74u:
v2 = func1(&v8, v2);
goto LABEL_12;
case 0x27u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Bu:
case 0x2Cu:
case 0x2Du:
case 0x2Eu:
case 0x2Fu:
case 0x30u:
v2 = func0(&v8, v2);
goto LABEL_12;
case 0x38u:
case 0x39u:
case 0x3Au:
case 0x3Bu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x3Fu:
case 0x40u:
case 0x41u:
case 0x42u:
case 0x43u:
case 0x44u:
case 0x45u:
case 0x46u:
case 0x47u:
case 0x48u:
case 0x49u:
case 0x4Au:
case 0x4Bu:
case 0x4Cu:
case 0x4Du:
case 0x4Eu:
case 0x4Fu:
case 0x50u:
case 0x51u:
v2 = func2(&v8, v2);
goto LABEL_12;
case 0x58u:
case 0x59u:
case 0x5Au:
case 0x5Bu:
case 0x5Cu:
case 0x5Du:
case 0x5Eu:
case 0x5Fu:
case 0x60u:
case 0x61u:
case 0x62u:
case 0x63u:
case 0x64u:
case 0x65u:
case 0x66u:
case 0x67u:
case 0x68u:
case 0x69u:
case 0x6Au:
case 0x6Bu:
case 0x6Cu:
case 0x6Du:
case 0x6Eu:
case 0x6Fu:
case 0x70u:
case 0x71u:
v2 = func3(&v8, v2);
LABEL_12:
if ( v2 == -2 )
goto LABEL_10;
if ( v2 == -4 )
goto LABEL_7;
generator_yield(a1, v9);
v6 = malloc(0x18uLL);
v7 = v10;
v9 = v6;
*(_BYTE *)v6 = 0;
v6[4] = v7;
break;
default:
goto LABEL_9;
}
}
LABEL_7:
result = generator_eof(v8);
if ( !(_DWORD)result )
{
v2 = generator_shift(v8);
v4 = v2 - 9;
if ( v2 - 9 > 0x74 )
{
LABEL_9:
asprintf(&ptr, "Unknown character %c (%d) found", v2, v2);
LABEL_10:
fprintf(stderr, "%s: Error from scanner: %s at line %d\n", a2, ptr, v10);
free(ptr);
exit(1);
}
goto LABEL_5;
}
return result;
}

original_code:
void
gen_tokens(generator *g, void *arg) {
 struct scannerstate st;
 st.active = malloc(sizeof(struct token));
 st.active->type = 0;
 st.active->lineno = st.curline = 1;
 int nextchar = -3;
 st.ig = generator_create(gen_input, arg, 1);
 while(nextchar != -3 || !generator_eof(st.ig)) {
  int in;
  if(nextchar == -3) {
   in = (intptr_t)generator_shift(st.ig);
  } else {
   in = nextchar;
   ((void) sizeof ((in >= 0 && in < 256) ? 1 : 0), __extension__ ({ if (in >= 0 && in < 256) ; else __assert_fail ("in >= 0 && in < 256", "scanner.c", 43, __extension__ __PRETTY_FUNCTION__); }));
   nextchar = -3;
  }
  switch(in) {
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
    nextchar = scan_initial_int(&st, in);
    break;
   case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
    nextchar = scan_initial_lower(&st, in);
    break;
   case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
    nextchar = scan_initial_upper(&st, in);
    break;
   case '=':
   case ';':
   case ',':
   case '+':
   case '-':
   case '*':
   case '/':
   case '%':
   case ':':
   case '(':
   case ')':
   case '{':
   case '}':
   case '[':
   case ']':
   case '<':
   case '>':
   case '!':
   case '&':
   case '|':
    nextchar = scan_initial_sign(&st, in);
    break;
   case '\n':
    st.curline++;
   case ' ':
   case '\t':
   case '\r':
    nextchar = -4;
    break;
   default:
    asprintf(&st.error, "Unknown character %c (%d) found", in, in);
    nextchar = -2;
  }
  if(nextchar == -2) {
   break;
  }
  if(nextchar == -4) {
   nextchar = -3;
   continue;
  }
  generator_yield(g, st.active);
  st.active = malloc(sizeof(struct token));
  st.active->type = 0;
  st.active->lineno = st.curline;
 }
 if(nextchar == -2) {
  fprintf(stderr, "%s: Error from scanner: %s at line %d\n", (char *)arg, st.error, st.curline);
  free(st.error);
  exit(1);
 }
}

canonical_original_code:
void gen_tokens(struct _generator *g, void *arg) {
 struct scannerstate st;
 st.active = malloc(sizeof(struct token));
 st.active->type = 0;
 st.active->lineno = st.curline = 1;
 int nextchar = -3;
 st.ig = generator_create(gen_input, arg, 1);
 while(nextchar != -3 || !generator_eof(st.ig)) {
  int in;
  if(nextchar == -3) {
   in = (long)generator_shift(st.ig);
  } else {
   in = nextchar;
   ((void) sizeof ((in >= 0 && in < 256) ? 1 : 0), __extension__ ({ if (in >= 0 && in < 256) ; else __assert_fail ("in >= 0 && in < 256", "scanner.c", 43, __extension__ __PRETTY_FUNCTION__); }));
   nextchar = -3;
  }
  switch(in) {
   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
    nextchar = scan_initial_int(&st, in);
    break;
   case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
    nextchar = scan_initial_lower(&st, in);
    break;
   case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
    nextchar = scan_initial_upper(&st, in);
    break;
   case '=':
   case ';':
   case ',':
   case '+':
   case '-':
   case '*':
   case '/':
   case '%':
   case ':':
   case '(':
   case ')':
   case '{':
   case '}':
   case '[':
   case ']':
   case '<':
   case '>':
   case '!':
   case '&':
   case '|':
    nextchar = scan_initial_sign(&st, in);
    break;
   case '\n':
    st.curline++;
   case ' ':
   case '\t':
   case '\r':
    nextchar = -4;
    break;
   default:
    asprintf(&st.error, "Unknown character %c (%d) found", in, in);
    nextchar = -2;
  }
  if(nextchar == -2) {
   break;
  }
  if(nextchar == -4) {
   nextchar = -3;
   continue;
  }
  generator_yield(g, st.active);
  st.active = malloc(sizeof(struct token));
  st.active->type = 0;
  st.active->lineno = st.curline;
 }
 if(nextchar == -2) {
  fprintf(stderr, "%s: Error from scanner: %s at line %d\n", (char *)arg, st.error, st.curline);
  free(st.error);
  exit(1);
 }
}

variable_types:
arg
void *

variable_types: struct scannerstate { struct _generator { unsigned long thr; void (*function)(struct _generator *, void *); void *arg; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int async; struct generator_item { struct generator_item *next; void *item; } *ready; union { struct { void *item; int has_item; }; struct { struct generator_item *output; struct generator_item **output_last; }; }; } *ig; struct token { char type; union { int ival; char bval; char *sval; } value; int lineno; } *active; int curline; char *error; }

variable_types: nextchar int


decompiled_code:
void *__fastcall generator_run(void *a1)
{
pthread_setcanceltype(1, 0LL);
if ( *((_DWORD *)a1 + 28) == -1 )
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
(*((void (__fastcall **)(void *, _QWORD))a1 + 1))(a1, *((_QWORD *)a1 + 2));
pthread_testcancel();
if ( *((_DWORD *)a1 + 28) == -1 )
{
*((_DWORD *)a1 + 34) = (*((_DWORD *)a1 + 34) == 0) - 2;
}
else
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
**((_QWORD **)a1 + 17) = -1LL;
}
**(_DWORD **)a1 = 0;
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 24));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
pthread_setcanceltype(1, 0LL);
if ( *((_DWORD *)a1 + 28) == -1 )
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
(*((void (__fastcall **)(void *, _QWORD))a1 + 1))(a1, *((_QWORD *)a1 + 2));
pthread_testcancel();
if ( *((_DWORD *)a1 + 28) == -1 )
{
*((_DWORD *)a1 + 34) = (*((_DWORD *)a1 + 34) == 0) - 2;
}
else
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
**((_QWORD **)a1 + 17) = -1LL;
}
**(_DWORD **)a1 = 0;
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 24));
return 0LL;
}

original_code:
static void *
generator_run(void *arg) {
 generator *g = (generator *)arg;
 pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, ((void *)0));
 if(g->async == -1) {
  pthread_mutex_lock(&g->lock);
 }
 g->function(g, g->arg);
 pthread_testcancel();
 if(g->async != -1) {
  pthread_mutex_lock(&g->lock);
  *g->output_last = (void *)-1;
 } else {
  if(g->has_item == 0) {
   g->has_item = -1;
  } else {
   g->has_item = -2;
  }
 }
 *(int *)g->thr = 0;
 pthread_cond_signal(&g->cond);
 pthread_mutex_unlock(&g->lock);
 return 0;
}

canonical_original_code:
static void *generator_run(void *arg) {
 struct _generator *g = (generator *)arg;
 pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, ((void *)0));
 if(g->async == -1) {
  pthread_mutex_lock(&g->lock);
 }
 g->function(g, g->arg);
 pthread_testcancel();
 if(g->async != -1) {
  pthread_mutex_lock(&g->lock);
  *g->output_last = (void *)-1;
 } else {
  if(g->has_item == 0) {
   g->has_item = -1;
  } else {
   g->has_item = -2;
  }
 }
 *(int *)g->thr = 0;
 pthread_cond_signal(&g->cond);
 pthread_mutex_unlock(&g->lock);
 return 0;
}

variable_types: struct _generator { unsigned long thr; void (*function)(struct _generator *, void *); void *arg; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int async; struct generator_item { struct generator_item *next; void *item; } *ready; union { struct { void *item; int has_item; }; struct { struct generator_item *output; struct generator_item **output_last; }; }; } *