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);
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);
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;
}


repo: Jery-Mong/snake

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;
}

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; } *

return_type: int


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;
}

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; }


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; } *

return_type: void

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);
}

variable_types: i int

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)
{
__int64 result; // rax

move_steps(a1, 1LL, 4LL);
result = check_position_h(a1, 5LL);
if ( (_DWORD)result != 1 )
{
move_steps(a1, 2LL, 5LL);
result = check_position_h(a1, 4LL);
if ( (_DWORD)result != 1 )
{
move_steps(a1, 1LL, 4LL);
move_steps(a1, 1LL, 0LL);
result = check_position_v(a1);
if ( (_DWORD)result != 1 )
{
move_steps(a1, 1LL, 1LL);
result = 0LL;
}
}
}
return result;
}

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

move_steps(a1, 1LL, 4LL);
result = check_position_h(a1, 5LL);
if ( (_DWORD)result != 1 )
{
move_steps(a1, 2LL, 5LL);
result = check_position_h(a1, 4LL);
if ( (_DWORD)result != 1 )
{
move_steps(a1, 1LL, 4LL);
move_steps(a1, 1LL, 0LL);
result = check_position_v(a1);
if ( (_DWORD)result != 1 )
{
move_steps(a1, 1LL, 1LL);
result = 0LL;
}
}
}
return result;
}

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);
 }
}


decompiled_code:
void __fastcall com_transfer(__int64 a1)
{
__m128i *v1; // rbx

v1 = duplex_obj(a1);
(*(void (__fastcall **)(__m128i *))(a1 + 32))(v1);
transfer(a1, (__int64)v1);
free(v1);
}

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

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
return (unsigned int)(sigaction(sig, &v4, &v3) >> 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

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
return (unsigned int)(sigaction(sig, &v4, &v3) >> 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

canonical_name: main

repo: Jille/oid

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
ssize_t v3; // rax
ssize_t v4; // rax
int result; // eax
ssize_t v6; // rax
signed __int64 v7; // rax
ssize_t v8; // rax
ssize_t v9; // 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);
if ( v3 == -1 )
err(1, "read(STDIN, ..., %d)", 4096LL);
if ( v3 )
{
wantedread = v3;
actualread = 0LL;
while ( 1 )
{
v4 = read(fdout, (void *)(actualread + 4210912), wantedread - actualread);
if ( v4 == -1 )
err(1, "read(fdout, ..., %ld)", wantedread - actualread);
if ( !v4 )
break;
actualread += v4;
if ( actualread >= (__int64)wantedread )
{
if ( !memcmp(&wantedbuf, &actualbuf, 0x1000uLL) )
{
++unchanged;
}
else
{
++changed;
written = 0LL;
do
{
v9 = pwrite64(fdout, (const void *)(written + 4215008), wantedread - written, pos + written);
if ( v9 == -1 )
err(1, "pwrite(%s, ..., %ld, %ld)", argv[1], wantedread - written, pos + written);
if ( !v9 )
__assert_fail("ret != 0", "oid.c", 0x51u, "main");
written += v9;
}
while ( written < (__int64)wantedread );
}
pos += wantedread;
goto LABEL_3;
}
}
if ( lseek64(fdout, pos, 0) == -1 )
err(1, "lseek(%s, %ld, SEEK_SET)", argv[1], pos);
do
{
++appended;
written = 0LL;
do
{
v6 = write(fdout, (char *)&wantedbuf + written, wantedread);
if ( v6 == -1 )
err(1, "write(%s, ..., %ld)", argv[1], wantedread);
v7 = written + v6;
written = v7;
}
while ( v7 < (__int64)wantedread );
pos += v7;
v8 = read(fdin, &wantedbuf, 0x1000uLL);
if ( v8 == -1 )
err(1, "read(STDIN, ..., %d)", 4096LL);
wantedread = v8;
}
while ( v8 );
}
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:
const char *__fastcall token_to_string(char a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = (const char *)&unk_76D;
break;
case 2:
result = "BOOL";
break;
case 3:
result = "VOID";
break;
case 4:
result = "WORD";
break;
case 5:
result = "NUMBER";
break;
case 6:
result = "IF";
break;
case 7:
result = "WHILE";
break;
case 8:
result = "ELSE";
break;
case 9:
result = "RETURN";
break;
case 10:
result = "TRUE";
break;
case 11:
result = "FALSE";
break;
case 12:
result = "AND";
break;
case 13:
result = "OR";
break;
case 14:
result = "EQ";
break;
case 15:
result = "NE";
break;
case 16:
result = "GTE";
break;
case 17:
result = "LTE";
break;
case 33:
result = "!";
break;
case 37:
result = "%";
break;
case 38:
result = "&";
break;
case 40:
result = "(";
break;
case 41:
result = ")";
break;
case 42:
result = "*";
break;
case 43:
result = "+";
break;
case 44:
result = ",";
break;
case 45:
result = "-";
break;
case 47:
result = "/";
break;
case 58:
result = ":";
break;
case 59:
result = ";";
break;
case 60:
result = "<";
break;
case 61:
result = "=";
break;
case 62:
result = ">";
break;
case 91:
result = "[";
break;
case 93:
result = "]";
break;
case 123:
result = "{";
break;
case 124:
result = "|";
break;
case 125:
result = "}";
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
result = (const char *)&unk_76D;
break;
case 2:
result = "BOOL";
break;
case 3:
result = "VOID";
break;
case 4:
result = "WORD";
break;
case 5:
result = "NUMBER";
break;
case 6:
result = "IF";
break;
case 7:
result = "WHILE";
break;
case 8:
result = "ELSE";
break;
case 9:
result = "RETURN";
break;
case 10:
result = "TRUE";
break;
case 11:
result = "FALSE";
break;
case 12:
result = "AND";
break;
case 13:
result = "OR";
break;
case 14:
result = "EQ";
break;
case 15:
result = "NE";
break;
case 16:
result = "GTE";
break;
case 17:
result = "LTE";
break;
case 33:
result = "!";
break;
case 37:
result = "%";
break;
case 38:
result = "&";
break;
case 40:
result = "(";
break;
case 41:
result = ")";
break;
case 42:
result = "*";
break;
case 43:
result = "+";
break;
case 44:
result = ",";
break;
case 45:
result = "-";
break;
case 47:
result = "/";
break;
case 58:
result = ":";
break;
case 59:
result = ";";
break;
case 60:
result = "<";
break;
case 61:
result = "=";
break;
case 62:
result = ">";
break;
case 91:
result = "[";
break;
case 93:
result = "]";
break;
case 123:
result = "{";
break;
case 124:
result = "|";
break;
case 125:
result = "}";
break;
default:
result = 0LL;
break;
}
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; // edx

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; // edx

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 *

return_type: char


decompiled_code:
__int64 __fastcall get_id_for_rule(signed int *a1, const char *a2)
{
int v3; // er12
const char **v4; // rbp
int v5; // ebx
signed int v6; // er12
int *v7; // rax
void *v8; // rdi
int *v9; // r14

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

canonical_decompiled_code:
__int64 __fastcall func2(signed int *a1, const char *a2)
{
int v3; // er12
const char **v4; // rbp
int v5; // ebx
signed int v6; // er12
int *v7; // rax
void *v8; // rdi
int *v9; // r14

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

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: 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; // eax
unsigned int v4; // ecx

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

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

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

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(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

**(_BYTE **)(a1 + 8) = a2;
switch ( a2 )
{
case '!':
case '&':
case '<':
case '=':
case '>':
case '|':
v2 = generator_eof(*(_QWORD *)a1);
result = 0xFFFFFFFFLL;
if ( !v2 )
{
result = generator_shift(*(_QWORD *)a1);
if ( (_DWORD)result == 61 )
{
if ( a2 == 61 )
{
**(_BYTE **)(a1 + 8) = 14;
result = 4294967293LL;
}
else if ( a2 > 61 )
{
if ( a2 == 62 )
{
**(_BYTE **)(a1 + 8) = 16;
result = 4294967293LL;
}
}
else if ( a2 == 33 )
{
**(_BYTE **)(a1 + 8) = 15;
result = 4294967293LL;
}
else if ( a2 == 60 )
{
**(_BYTE **)(a1 + 8) = 17;
result = 4294967293LL;
}
}
else if ( (_DWORD)result == 124 || (_DWORD)result == 38 )
{
if ( a2 != (_DWORD)result )
goto LABEL_7;
**(_BYTE **)(a1 + 8) = (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_7:
asprintf((char **)(a1 + 24), "Operator '%c' is unknown.", (unsigned int)a2);
result = 4294967294LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

**(_BYTE **)(a1 + 8) = a2;
switch ( a2 )
{
case '!':
case '&':
case '<':
case '=':
case '>':
case '|':
v2 = generator_eof(*(_QWORD *)a1);
result = 0xFFFFFFFFLL;
if ( !v2 )
{
result = generator_shift(*(_QWORD *)a1);
if ( (_DWORD)result == 61 )
{
if ( a2 == 61 )
{
**(_BYTE **)(a1 + 8) = 14;
result = 4294967293LL;
}
else if ( a2 > 61 )
{
if ( a2 == 62 )
{
**(_BYTE **)(a1 + 8) = 16;
result = 4294967293LL;
}
}
else if ( a2 == 33 )
{
**(_BYTE **)(a1 + 8) = 15;
result = 4294967293LL;
}
else if ( a2 == 60 )
{
**(_BYTE **)(a1 + 8) = 17;
result = 4294967293LL;
}
}
else if ( (_DWORD)result == 124 || (_DWORD)result == 38 )
{
if ( a2 != (_DWORD)result )
goto LABEL_7;
**(_BYTE **)(a1 + 8) = (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_7:
asprintf((char **)(a1 + 24), "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(__int64 a1, char a2)
{
char *i; // rbp
int v3; // eax
unsigned int v4; // edx
char v6; // [rsp+0h] [rbp-28h] BYREF
char v7; // [rsp+1h] [rbp-27h] BYREF
char v8; // [rsp+10h] [rbp-18h] BYREF

v6 = a2;
for ( i = &v7; ; *(i - 1) = v3 )
{
if ( (unsigned int)generator_eof(*(_QWORD *)a1) )
{
v4 = -1;
goto LABEL_13;
}
if ( i == &v8 )
{
asprintf((char **)(a1 + 24), "Word '%.*s...' too long.", 16, &v6);
return (unsigned int)-2;
}
v3 = generator_shift(*(_QWORD *)a1);
v4 = v3;
if ( v3 <= 90 )
break;
if ( (unsigned int)(v3 - 97) > 0x19 )
goto LABEL_13;
LABEL_11:
++i;
}
if ( v3 > 64 )
goto LABEL_11;
if ( (unsigned int)(v3 - 48) <= 9 )
{
asprintf((char **)(a1 + 24), "Keyword '%.*s...' contains digit.", i - &v6, &v6);
return (unsigned int)-2;
}
LABEL_13:
*i = 0;
if ( !strcmp(&v6, "True") )
{
**(_BYTE **)(a1 + 8) = 10;
}
else if ( !strcmp(&v6, "False") )
{
**(_BYTE **)(a1 + 8) = 11;
}
else if ( !strcmp(&v6, "Int") )
{
**(_BYTE **)(a1 + 8) = 1;
}
else if ( !strcmp(&v6, "Bool") )
{
**(_BYTE **)(a1 + 8) = 2;
}
else if ( !strcmp(&v6, "Void") )
{
**(_BYTE **)(a1 + 8) = 3;
}
else
{
asprintf((char **)(a1 + 24), "Keyword '%s...' is unknown.", &v6);
v4 = -2;
}
return v4;
}

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

v6 = a2;
for ( i = &v7; ; *(i - 1) = v3 )
{
if ( (unsigned int)generator_eof(*(_QWORD *)a1) )
{
v4 = -1;
goto LABEL_13;
}
if ( i == &v8 )
{
asprintf((char **)(a1 + 24), "Word '%.*s...' too long.", 16, &v6);
return (unsigned int)-2;
}
v3 = generator_shift(*(_QWORD *)a1);
v4 = v3;
if ( v3 <= 90 )
break;
if ( (unsigned int)(v3 - 97) > 0x19 )
goto LABEL_13;
LABEL_11:
++i;
}
if ( v3 > 64 )
goto LABEL_11;
if ( (unsigned int)(v3 - 48) <= 9 )
{
asprintf((char **)(a1 + 24), "Keyword '%.*s...' contains digit.", i - &v6, &v6);
return (unsigned int)-2;
}
LABEL_13:
*i = 0;
if ( !strcmp(&v6, "True") )
{
**(_BYTE **)(a1 + 8) = 10;
}
else if ( !strcmp(&v6, "False") )
{
**(_BYTE **)(a1 + 8) = 11;
}
else if ( !strcmp(&v6, "Int") )
{
**(_BYTE **)(a1 + 8) = 1;
}
else if ( !strcmp(&v6, "Bool") )
{
**(_BYTE **)(a1 + 8) = 2;
}
else if ( !strcmp(&v6, "Void") )
{
**(_BYTE **)(a1 + 8) = 3;
}
else
{
asprintf((char **)(a1 + 24), "Keyword '%s...' is unknown.", &v6);
v4 = -2;
}
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; // er12
char *v6; // rbx
char v7; // [rsp+0h] [rbp-98h] BYREF
char v8; // [rsp+1h] [rbp-97h] BYREF
char v9; // [rsp+80h] [rbp-18h] BYREF

v7 = a2;
v2 = &v8;
while ( !(unsigned int)generator_eof(*a1) )
{
if ( v2 == &v9 )
{
asprintf(a1 + 3, "Word '%.*s...' too long.", 128, &v7);
return (unsigned int)-2;
}
v3 = generator_shift(*a1);
v4 = v3;
if ( v3 > 90 )
{
if ( (unsigned int)(v3 - 97) > 0x19 )
goto LABEL_10;
}
else
{
if ( v3 > 64 )
{
asprintf(a1 + 3, "Word '%.*s...' contains invalid uppercase character.", v2 - &v7, &v7);
return (unsigned int)-2;
}
if ( (unsigned int)(v3 - 48) > 9 )
goto LABEL_10;
}
*v2++ = v3;
}
v4 = -1;
LABEL_10:
*v2 = 0;
if ( !strcmp(&v7, "if") )
{
*a1[1] = 6;
}
else if ( !strcmp(&v7, "while") )
{
*a1[1] = 7;
}
else if ( !strcmp(&v7, "else") )
{
*a1[1] = 8;
}
else if ( !strcmp(&v7, "return") )
{
*a1[1] = 9;
}
else
{
*a1[1] = 4;
v6 = a1[1];
*((_QWORD *)v6 + 1) = strdup(&v7);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char **a1, char a2)
{
char *v2; // rbp
int v3; // eax
unsigned int v4; // er12
char *v6; // rbx
char v7; // [rsp+0h] [rbp-98h] BYREF
char v8; // [rsp+1h] [rbp-97h] BYREF
char v9; // [rsp+80h] [rbp-18h] BYREF

v7 = a2;
v2 = &v8;
while ( !(unsigned int)generator_eof(*a1) )
{
if ( v2 == &v9 )
{
asprintf(a1 + 3, "Word '%.*s...' too long.", 128, &v7);
return (unsigned int)-2;
}
v3 = generator_shift(*a1);
v4 = v3;
if ( v3 > 90 )
{
if ( (unsigned int)(v3 - 97) > 0x19 )
goto LABEL_10;
}
else
{
if ( v3 > 64 )
{
asprintf(a1 + 3, "Word '%.*s...' contains invalid uppercase character.", v2 - &v7, &v7);
return (unsigned int)-2;
}
if ( (unsigned int)(v3 - 48) > 9 )
goto LABEL_10;
}
*v2++ = v3;
}
v4 = -1;
LABEL_10:
*v2 = 0;
if ( !strcmp(&v7, "if") )
{
*a1[1] = 6;
}
else if ( !strcmp(&v7, "while") )
{
*a1[1] = 7;
}
else if ( !strcmp(&v7, "else") )
{
*a1[1] = 8;
}
else if ( !strcmp(&v7, "return") )
{
*a1[1] = 9;
}
else
{
*a1[1] = 4;
v6 = a1[1];
*((_QWORD *)v6 + 1) = strdup(&v7);
}
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)
{
_DWORD *v2; // rax
unsigned int v3; // ebx
_DWORD *v4; // rax
__int64 result; // rax
char *v6; // [rsp+0h] [rbp-48h] BYREF
_DWORD *v7; // [rsp+8h] [rbp-40h]
unsigned int v8; // [rsp+10h] [rbp-38h]
char *ptr; // [rsp+18h] [rbp-30h] BYREF

v2 = malloc(0x18uLL);
v7 = v2;
*(_BYTE *)v2 = 0;
v8 = 1;
v2[4] = 1;
v6 = (char *)generator_create(&gen_input, a2, 1LL);
v3 = -3;
while ( v3 != -3 )
{
if ( v3 > 0xFF )
_assert_fail("in >= 0 && in < 256", "scanner.c", 0x2Bu, "gen_tokens");
switch ( v3 )
{
case 9u:
case 0xDu:
case 0x20u:
goto LABEL_14;
case 0xAu:
LABEL_13:
++v8;
goto LABEL_14;
case 0x21u:
case 0x25u:
case 0x26u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Bu:
case 0x2Cu:
case 0x2Du:
case 0x2Fu:
case 0x3Au:
case 0x3Bu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x5Bu:
case 0x5Du:
case 0x7Bu:
case 0x7Cu:
case 0x7Du:
LABEL_12:
v3 = scan_initial_sign((__int64)&v6, v3);
goto LABEL_7;
case 0x30u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
LABEL_6:
v3 = scan_initial_int(&v6, v3);
goto LABEL_7;
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:
case 0x52u:
case 0x53u:
case 0x54u:
case 0x55u:
case 0x56u:
case 0x57u:
case 0x58u:
case 0x59u:
case 0x5Au:
LABEL_11:
v3 = scan_initial_upper((__int64)&v6, v3);
goto LABEL_7;
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:
case 0x72u:
case 0x73u:
case 0x74u:
case 0x75u:
case 0x76u:
case 0x77u:
case 0x78u:
case 0x79u:
case 0x7Au:
LABEL_10:
v3 = scan_initial_lower(&v6, v3);
LABEL_7:
if ( v3 == -2 )
goto LABEL_17;
LABEL_8:
if ( v3 == -4 )
goto LABEL_14;
generator_yield(a1, v7);
v4 = malloc(0x18uLL);
v7 = v4;
*(_BYTE *)v4 = 0;
v4[4] = v8;
break;
default:
LABEL_16:
asprintf(&ptr, "Unknown character %c (%d) found", v3, v3);
LABEL_17:
fprintf(stderr, "%s: Error from scanner: %s at line %d\n", a2, ptr, v8);
free(ptr);
exit(1);
}
}
LABEL_14:
result = generator_eof(v6);
if ( !(_DWORD)result )
{
v3 = generator_shift(v6);
switch ( v3 )
{
case 9u:
case 0xDu:
case 0x20u:
v3 = -4;
goto LABEL_8;
case 0xAu:
goto LABEL_13;
case 0x21u:
case 0x25u:
case 0x26u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Bu:
case 0x2Cu:
case 0x2Du:
case 0x2Fu:
case 0x3Au:
case 0x3Bu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x5Bu:
case 0x5Du:
case 0x7Bu:
case 0x7Cu:
case 0x7Du:
goto LABEL_12;
case 0x30u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
goto LABEL_6;
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:
case 0x52u:
case 0x53u:
case 0x54u:
case 0x55u:
case 0x56u:
case 0x57u:
case 0x58u:
case 0x59u:
case 0x5Au:
goto LABEL_11;
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:
case 0x72u:
case 0x73u:
case 0x74u:
case 0x75u:
case 0x76u:
case 0x77u:
case 0x78u:
case 0x79u:
case 0x7Au:
goto LABEL_10;
default:
goto LABEL_16;
}
}
return result;
}

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

v2 = malloc(0x18uLL);
v7 = v2;
*(_BYTE *)v2 = 0;
v8 = 1;
v2[4] = 1;
v6 = (char *)generator_create(&gen_input, a2, 1LL);
v3 = -3;
while ( v3 != -3 )
{
if ( v3 > 0xFF )
_assert_fail("in >= 0 && in < 256", "scanner.c", 0x2Bu, "gen_tokens");
switch ( v3 )
{
case 9u:
case 0xDu:
case 0x20u:
goto LABEL_14;
case 0xAu:
LABEL_13:
++v8;
goto LABEL_14;
case 0x21u:
case 0x25u:
case 0x26u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Bu:
case 0x2Cu:
case 0x2Du:
case 0x2Fu:
case 0x3Au:
case 0x3Bu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x5Bu:
case 0x5Du:
case 0x7Bu:
case 0x7Cu:
case 0x7Du:
LABEL_12:
v3 = func1((__int64)&v6, v3);
goto LABEL_7;
case 0x30u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
LABEL_6:
v3 = func0(&v6, v3);
goto LABEL_7;
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:
case 0x52u:
case 0x53u:
case 0x54u:
case 0x55u:
case 0x56u:
case 0x57u:
case 0x58u:
case 0x59u:
case 0x5Au:
LABEL_11:
v3 = func2((__int64)&v6, v3);
goto LABEL_7;
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:
case 0x72u:
case 0x73u:
case 0x74u:
case 0x75u:
case 0x76u:
case 0x77u:
case 0x78u:
case 0x79u:
case 0x7Au:
LABEL_10:
v3 = func3(&v6, v3);
LABEL_7:
if ( v3 == -2 )
goto LABEL_17;
LABEL_8:
if ( v3 == -4 )
goto LABEL_14;
generator_yield(a1, v7);
v4 = malloc(0x18uLL);
v7 = v4;
*(_BYTE *)v4 = 0;
v4[4] = v8;
break;
default:
LABEL_16:
asprintf(&ptr, "Unknown character %c (%d) found", v3, v3);
LABEL_17:
fprintf(stderr, "%s: Error from scanner: %s at line %d\n", a2, ptr, v8);
free(ptr);
exit(1);
}
}
LABEL_14:
result = generator_eof(v6);
if ( !(_DWORD)result )
{
v3 = generator_shift(v6);
switch ( v3 )
{
case 9u:
case 0xDu:
case 0x20u:
v3 = -4;
goto LABEL_8;
case 0xAu:
goto LABEL_13;
case 0x21u:
case 0x25u:
case 0x26u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Bu:
case 0x2Cu:
case 0x2Du:
case 0x2Fu:
case 0x3Au:
case 0x3Bu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x5Bu:
case 0x5Du:
case 0x7Bu:
case 0x7Cu:
case 0x7Du:
goto LABEL_12;
case 0x30u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
goto LABEL_6;
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:
case 0x52u:
case 0x53u:
case 0x54u:
case 0x55u:
case 0x56u:
case 0x57u:
case 0x58u:
case 0x59u:
case 0x5Au:
goto LABEL_11;
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:
case 0x72u:
case 0x73u:
case 0x74u:
case 0x75u:
case 0x76u:
case 0x77u:
case 0x78u:
case 0x79u:
case 0x7Au:
goto LABEL_10;
default:
goto LABEL_16;
}
}
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; }; }; } *

return_type: void *


decompiled_code:
int __fastcall generator_yield(__int64 a1, __int64 a2)
{
void **v2; // r13
int result; // eax

pthread_testcancel();
if ( *(_DWORD *)(a1 + 112) == -1 )
{
*(_QWORD *)(a1 + 128) = a2;
*(_DWORD *)(a1 + 136) = 1;
for ( result = pthread_cond_signal((pthread_cond_t *)(a1 + 64));
*(_DWORD *)(a1 + 136);
result = pthread_cond_wait((pthread_cond_t *)(a1 + 64), (pthread_mutex_t *)(a1 + 24)) )
{
;
}
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
pthread_testcancel();
v2 = *(void ***)(a1 + 136);
*v2 = calloc(1uLL, 0x10uLL);
*(_QWORD *)(**(_QWORD **)(a1 + 136) + 8LL) = a2;
*(_QWORD *)(a1 + 136) = **(_QWORD **)(a1 + 136);
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
void **v2; // r13
int result; // eax

pthread_testcancel();
if ( *(_DWORD *)(a1 + 112) == -1 )
{
*(_QWORD *)(a1 + 128) = a2;
*(_DWORD *)(a1 + 136) = 1;
for ( result = pthread_cond_signal((pthread_cond_t *)(a1 + 64));
*(_DWORD *)(a1 + 136);
result = pthread_cond_wait((pthread_cond_t *)(a1 + 64), (pthread_mutex_t *)(a1 + 24)) )
{
;
}
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
pthread_testcancel();
v2 = *(void ***)(a1 + 136);
*v2 = calloc(1uLL, 0x10uLL);
*(_QWORD *)(**(_QWORD **)(a1 + 136) + 8LL) = a2;
*(_QWORD *)(a1 + 136) = **(_QWORD **)(a1 + 136);
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

original_code:
void
generator_yield(generator *g, void *item) {
 pthread_testcancel();
 if(g->async == -1) {
  g->item = item;
  g->has_item = 1;
  pthread_cond_signal(&g->cond);
  while(g->has_item) {
   pthread_cond_wait(&g->cond, &g->lock);
  }
 } else {
  pthread_mutex_lock(&g->lock);
  pthread_testcancel();
  *g->output_last = calloc(1, sizeof(struct generator_item));
  (*g->output_last)->item = item;
  g->output_last = &((*g->output_last)->next);
  pthread_cond_signal(&g->cond);
  pthread_mutex_unlock(&g->lock);
 }
}

canonical_original_code:
void generator_yield(struct _generator *g, void *item) {
 pthread_testcancel();
 if(g->async == -1) {
  g->item = item;
  g->has_item = 1;
  pthread_cond_signal(&g->cond);
  while(g->has_item) {
   pthread_cond_wait(&g->cond, &g->lock);
  }
 } else {
  pthread_mutex_lock(&g->lock);
  pthread_testcancel();
  *g->output_last = calloc(1, sizeof(struct generator_item));
  (*g->output_last)->item = item;
  g->output_last = &((*g->output_last)->next);
  pthread_cond_signal(&g->cond);
  pthread_mutex_unlock(&g->lock);
 }
}

variable_types:
item
void *


decompiled_code:
_BOOL8 __fastcall generator_eof(__int64 a1)
{
__int64 v1; // rax
pthread_mutex_t *i; // rbp
__int64 j; // rax
_BOOL8 result; // rax
int v5; // eax
pthread_cond_t *v6; // rbp

if ( *(_DWORD *)(a1 + 112) == -1 )
{
result = 0LL;
if ( !*(_QWORD *)(a1 + 120) )
{
v5 = *(_DWORD *)(a1 + 136);
if ( !v5 )
{
v6 = (pthread_cond_t *)(a1 + 64);
do
{
pthread_cond_signal(v6);
pthread_cond_wait(v6, (pthread_mutex_t *)(a1 + 24));
v5 = *(_DWORD *)(a1 + 136);
}
while ( !v5 );
}
result = v5 == -1;
}
}
else
{
v1 = *(_QWORD *)(a1 + 120);
for ( i = (pthread_mutex_t *)(a1 + 24); !v1; v1 = *(_QWORD *)(a1 + 120) )
{
pthread_mutex_lock(i);
for ( j = *(_QWORD *)(a1 + 128); !j; j = *(_QWORD *)(a1 + 128) )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), i);
*(_QWORD *)(a1 + 120) = j;
*(_QWORD *)(a1 + 128) = 0LL;
*(_QWORD *)(a1 + 136) = a1 + 128;
pthread_mutex_unlock(i);
}
result = v1 == -1;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
pthread_mutex_t *i; // rbp
__int64 j; // rax
_BOOL8 result; // rax
int v5; // eax
pthread_cond_t *v6; // rbp

if ( *(_DWORD *)(a1 + 112) == -1 )
{
result = 0LL;
if ( !*(_QWORD *)(a1 + 120) )
{
v5 = *(_DWORD *)(a1 + 136);
if ( !v5 )
{
v6 = (pthread_cond_t *)(a1 + 64);
do
{
pthread_cond_signal(v6);
pthread_cond_wait(v6, (pthread_mutex_t *)(a1 + 24));
v5 = *(_DWORD *)(a1 + 136);
}
while ( !v5 );
}
result = v5 == -1;
}
}
else
{
v1 = *(_QWORD *)(a1 + 120);
for ( i = (pthread_mutex_t *)(a1 + 24); !v1; v1 = *(_QWORD *)(a1 + 120) )
{
pthread_mutex_lock(i);
for ( j = *(_QWORD *)(a1 + 128); !j; j = *(_QWORD *)(a1 + 128) )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), i);
*(_QWORD *)(a1 + 120) = j;
*(_QWORD *)(a1 + 128) = 0LL;
*(_QWORD *)(a1 + 136) = a1 + 128;
pthread_mutex_unlock(i);
}
result = v1 == -1;
}
return result;
}

original_code:
int
generator_eof(generator *g) {
 if(g->async == -1) {
  if(g->ready != ((void *)0)) {
   return 0;
  }
  while(g->has_item == 0) {
   pthread_cond_signal(&g->cond);
   pthread_cond_wait(&g->cond, &g->lock);
  }
  return (g->has_item == -1);
 } else {
  while(g->ready == ((void *)0)) {
   pthread_mutex_lock(&g->lock);
   while(g->output == ((void *)0)) {
    pthread_cond_wait(&g->cond, &g->lock);
   }
   g->ready = g->output;
   g->output = ((void *)0);
   g->output_last = &g->output;
   pthread_mutex_unlock(&g->lock);
  }
  return (g->ready == (void *)-1);
 }
}

canonical_original_code:
int generator_eof(struct _generator *g) {
 if(g->async == -1) {
  if(g->ready != ((void *)0)) {
   return 0;
  }
  while(g->has_item == 0) {
   pthread_cond_signal(&g->cond);
   pthread_cond_wait(&g->cond, &g->lock);
  }
  return (g->has_item == -1);
 } else {
  while(g->ready == ((void *)0)) {
   pthread_mutex_lock(&g->lock);
   while(g->output == ((void *)0)) {
    pthread_cond_wait(&g->cond, &g->lock);
   }
   g->ready = g->output;
   g->output = ((void *)0);
   g->output_last = &g->output;
   pthread_mutex_unlock(&g->lock);
  }
  return (g->ready == (void *)-1);
 }
}


original_code:
void *
generator_shift(generator *g) {
 void *ret;
 if(generator_eof(g)) {
  return ((void *)0);
 }
 if(g->async == -1 && g->ready == ((void *)0)) {
  ret = g->item;
  g->item = ((void *)0);
  if(g->has_item == -2) {
   g->has_item = -1;
  } else {
   g->has_item = 0;
  }
 } else {
  void *container = g->ready;
  ret = g->ready->item;
  g->ready = g->ready->next;
  free(container);
 }
 return ret;
}

canonical_original_code:
void *generator_shift(struct _generator *g) {
 void *ret;
 if(generator_eof(g)) {
  return ((void *)0);
 }
 if(g->async == -1 && g->ready == ((void *)0)) {
  ret = g->item;
  g->item = ((void *)0);
  if(g->has_item == -2) {
   g->has_item = -1;
  } else {
   g->has_item = 0;
  }
 } else {
  void *container = g->ready;
  ret = g->ready->item;
  g->ready = g->ready->next;
  free(container);
 }
 return ret;
}

variable_types:
ret
void *

variable_types:
container
void *


decompiled_code:
void __fastcall generator_destroy(void *ptr)
{
_DWORD *v2; // rdi
_QWORD *v3; // rdx
_QWORD *i; // rdi

if ( *((_DWORD *)ptr + 28) == -1 )
{
v2 = *(_DWORD **)ptr;
if ( !*v2 )
goto LABEL_9;
goto LABEL_3;
}
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 24));
v2 = *(_DWORD **)ptr;
if ( **(_DWORD **)ptr )
LABEL_3:
pthread_cancel((pthread_t)v2);
if ( *((_DWORD *)ptr + 28) != -1 )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 17);
if ( (unsigned __int64)(*v3 - 1LL) <= 0xFFFFFFFFFFFFFFFDLL )
_assert_fail(
"*g->output_last == NULL || *g->output_last == (void *)-1",
"generator.c",
0x98u,
"generator_destroy");
*v3 = *((_QWORD *)ptr + 15);
for ( i = (_QWORD *)*((_QWORD *)ptr + 16);
(unsigned __int64)i - 1 <= 0xFFFFFFFFFFFFFFFDLL;
i = (_QWORD *)*((_QWORD *)ptr + 16) )
{
*((_QWORD *)ptr + 16) = *i;
free(i);
}
}
LABEL_9:
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 24));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 64));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
_DWORD *v2; // rdi
_QWORD *v3; // rdx
_QWORD *i; // rdi

if ( *((_DWORD *)ptr + 28) == -1 )
{
v2 = *(_DWORD **)ptr;
if ( !*v2 )
goto LABEL_9;
goto LABEL_3;
}
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 24));
v2 = *(_DWORD **)ptr;
if ( **(_DWORD **)ptr )
LABEL_3:
pthread_cancel((pthread_t)v2);
if ( *((_DWORD *)ptr + 28) != -1 )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 17);
if ( (unsigned __int64)(*v3 - 1LL) <= 0xFFFFFFFFFFFFFFFDLL )
_assert_fail(
"*g->output_last == NULL || *g->output_last == (void *)-1",
"generator.c",
0x98u,
"generator_destroy");
*v3 = *((_QWORD *)ptr + 15);
for ( i = (_QWORD *)*((_QWORD *)ptr + 16);
(unsigned __int64)i - 1 <= 0xFFFFFFFFFFFFFFFDLL;
i = (_QWORD *)*((_QWORD *)ptr + 16) )
{
*((_QWORD *)ptr + 16) = *i;
free(i);
}
}
LABEL_9:
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 24));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 64));
free(ptr);
}

original_code:
void
generator_destroy(generator *g) {
 if(g->async != -1) {
  pthread_mutex_lock(&g->lock);
 }
 if(*(int *)g->thr != 0) {
  pthread_cancel(g->thr);
 }
 if(g->async != -1) {
  ((void) sizeof ((*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ? 1 : 0), __extension__ ({ if (*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ; else __assert_fail ("*g->output_last == NULL || *g->output_last == (void *)-1", "generator.c", 152, __extension__ __PRETTY_FUNCTION__); }));
  *g->output_last = g->ready;
  while(g->output != ((void *)0) && g->output != (void *)-1) {
   struct generator_item *c = g->output;
   g->output = c->next;
   free(c);
  }
 }
 pthread_mutex_unlock(&g->lock);
 pthread_mutex_destroy(&g->lock);
 pthread_cond_destroy(&g->cond);
 free(g);
}

canonical_original_code:
void generator_destroy(struct _generator *g) {
 if(g->async != -1) {
  pthread_mutex_lock(&g->lock);
 }
 if(*(int *)g->thr != 0) {
  pthread_cancel(g->thr);
 }
 if(g->async != -1) {
  ((void) sizeof ((*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ? 1 : 0), __extension__ ({ if (*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ; else __assert_fail ("*g->output_last == NULL || *g->output_last == (void *)-1", "generator.c", 152, __extension__ __PRETTY_FUNCTION__); }));
  *g->output_last = g->ready;
  while(g->output != ((void *)0) && g->output != (void *)-1) {
   struct generator_item *c = g->output;
   g->output = c->next;
   free(c);
  }
 }
 pthread_mutex_unlock(&g->lock);
 pthread_mutex_destroy(&g->lock);
 pthread_cond_destroy(&g->cond);
 free(g);
}

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


decompiled_code:
__int64 __fastcall lazyarray_exists(__int64 *a1, int a2)
{
__int64 v4; // rdi
int v5; // eax
_QWORD *v6; // rbp
int v7; // eax
int v8; // eax

if ( a2 < *((_DWORD *)a1 + 4) )
return 1LL;
while ( !(unsigned int)generator_eof(*a1) )
{
v7 = *((_DWORD *)a1 + 5);
if ( *((_DWORD *)a1 + 4) == v7 )
{
v8 = 2 * v7;
*((_DWORD *)a1 + 5) = v8;
a1[1] = (__int64)realloc((void *)a1[1], 8LL * v8);
}
v4 = *a1;
v5 = *((_DWORD *)a1 + 4);
*((_DWORD *)a1 + 4) = v5 + 1;
v6 = (_QWORD *)(a1[1] + 8LL * v5);
*v6 = generator_shift(v4);
if ( *((_DWORD *)a1 + 4) > a2 )
return 1LL;
}
return 0LL;
}

original_code:
int
lazyarray_exists(lazyarray *la, int num) {
 while(num >= la->last) {
  if(generator_eof(la->g)) {
   return 0;
  }
  if(la->last == la->size) {
   la->size *= 2;
   la->array = realloc(la->array, la->size * sizeof(void *));
  }
  la->array[la->last++] = generator_shift(la->g);
 }
 return 1;
}

canonical_original_code:
int lazyarray_exists(struct _lazyarray *la, int num) {
 while(num >= la->last) {
  if(generator_eof(la->g)) {
   return 0;
  }
  if(la->last == la->size) {
   la->size *= 2;
   la->array = realloc(la->array, la->size * sizeof(void *));
  }
  la->array[la->last++] = generator_shift(la->g);
 }
 return 1;
}

variable_types: struct _lazyarray { 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; }; }; } *g; void **array; int last; int size; } *

user_defined_types: struct _lazyarray { struct _generator *g; void **array; int last; int size; }


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

if ( (unsigned int)lazyarray_exists(a1, a2) )
result = *(_QWORD *)(a1[1] + 8LL * a2);
else
result = 0LL;
return result;
}

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

if ( (unsigned int)func0(a1, a2) )
result = *(_QWORD *)(a1[1] + 8LL * a2);
else
result = 0LL;
return result;
}

original_code:
void *
lazyarray_get(lazyarray *la, int num) {
 if(!lazyarray_exists(la, num)) {
  return ((void *)0);
 }
 return la->array[num];
}

canonical_original_code:
void *lazyarray_get(struct _lazyarray *la, int num) {
 if(!lazyarray_exists(la, num)) {
  return ((void *)0);
 }
 return la->array[num];
}


decompiled_code:
void __fastcall lazyarray_destroy(__int64 a1)
{
generator_destroy(*(_QWORD *)a1);
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
generator_destroy(*(_QWORD *)a1);
free(*(void **)(a1 + 8));
}

original_code:
void
lazyarray_destroy(lazyarray *la) {
 generator_destroy(la->g);
 free(la->array);
}

canonical_original_code:
void lazyarray_destroy(struct _lazyarray *la) {
 generator_destroy(la->g);
 free(la->array);
}


repo: JinTu/sandbox

decompiled_code:
const char *__fastcall bus_str(int a1)
{
const char *result; // rax

if ( a1 == 5 )
return "Bluetooth";
if ( a1 > 5 )
{
result = "Other";
if ( a1 == 6 )
result = "Virtual";
}
else
{
result = "USB";
if ( a1 != 3 )
{
result = "Other";
if ( a1 == 4 )
result = "HIL";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(int a1)
{
const char *result; // rax

if ( a1 == 5 )
return "Bluetooth";
if ( a1 > 5 )
{
result = "Other";
if ( a1 == 6 )
result = "Virtual";
}
else
{
result = "USB";
if ( a1 != 3 )
{
result = "Other";
if ( a1 == 4 )
result = "HIL";
}
}
return result;
}

original_code:
const char *
bus_str(int bus)
{
 switch (bus) {
 case 0x03:
  return "USB";
  break;
 case 0x04:
  return "HIL";
  break;
 case 0x05:
  return "Bluetooth";
  break;
 case 0x06:
  return "Virtual";
  break;
 default:
  return "Other";
  break;
 }
}

canonical_original_code:
char *bus_str(int bus)
{
 switch (bus) {
 case 0x03:
  return "USB";
  break;
 case 0x04:
  return "HIL";
  break;
 case 0x05:
  return "Bluetooth";
  break;
 case 0x06:
  return "Virtual";
  break;
 default:
  return "Other";
  break;
 }
}

variable_types: bus int


repo: JnuSimba/APUE

decompiled_code:
int my_exit1()
{
return puts("my exit1 ... ");
}

canonical_decompiled_code:
int func7()
{
return puts("my exit1 ... ");
}

original_code:
void my_exit1(void)
{
 printf("my exit1 ... \n");
}

canonical_original_code:
void my_exit1()
{
 printf("my exit1 ... \n");
}


decompiled_code:
int my_exit2()
{
return puts("my exit2 ... ");
}

canonical_decompiled_code:
int func8()
{
return puts("my exit2 ... ");
}

original_code:
void my_exit2(void)
{
 printf("my exit2 ... \n");
}

canonical_original_code:
void my_exit2()
{
 printf("my exit2 ... \n");
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
printf("hello world");
putchar(10);
atexit(my_exit1, argv);
atexit(my_exit2, argv);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
printf("hello world");
putchar(10);
func11(my_exit1, argv);
func11(my_exit2, argv);
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
 printf("hello world");
 printf("\n");
 atexit(my_exit1);
 atexit(my_exit2);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall my_system(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebp
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( !a1 )
return 1LL;
v1 = fork();
v2 = v1;
if ( v1 < 0 )
{
stat_loc[0] = -1;
}
else
{
if ( !v1 )
{
execl("/bin/sh", "sh", &unk_402004, a1, 0LL);
exit(127);
}
while ( waitpid(v2, stat_loc, 0) < 0 )
{
if ( *__errno_location() != 4 )
{
stat_loc[0] = -1;
return (unsigned int)stat_loc[0];
}
}
}
return (unsigned int)stat_loc[0];
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebp
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( !a1 )
return 1LL;
v1 = fork();
v2 = v1;
if ( v1 < 0 )
{
stat_loc[0] = -1;
}
else
{
if ( !v1 )
{
execl("/bin/sh", "sh", &unk_402004, a1, 0LL);
exit(127);
}
while ( waitpid(v2, stat_loc, 0) < 0 )
{
if ( *__errno_location() != 4 )
{
stat_loc[0] = -1;
return (unsigned int)stat_loc[0];
}
}
}
return (unsigned int)stat_loc[0];
}

original_code:
int my_system(const char* command)
{
 pid_t pid;
 int status;
 if (command == ((void *)0))
  return 1;
 if ((pid = fork()) < 0)
   status = -1;
 else if (pid == 0) {
  execl("/bin/sh", "sh", "-c", command, ((void *)0));
  exit(127);
 }
 else {
  while (waitpid(pid, &status, 0) < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   status = -1;
   break;
  }
 }
 return status;
}

canonical_original_code:
int my_system(char *command)
{
 int pid;
 int status;
 if (command == ((void *)0))
  return 1;
 if ((pid = fork()) < 0)
   status = -1;
 else if (pid == 0) {
  execl("/bin/sh", "sh", "-c", command, ((void *)0));
  exit(127);
 }
 else {
  while (waitpid(pid, &status, 0) < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   status = -1;
   break;
  }
 }
 return status;
}

variable_types:
command
char *

variable_types: pid int

variable_types: status int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
my_system((__int64)"ls -l | wc -w");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7((__int64)"ls -l | wc -w");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 my_system("ls -l | wc -w");
 return 0;
}


decompiled_code:
__int64 __fastcall my_signal(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0;
v2 = sigaction(sig, &v5, &v4) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v4.sa_handler;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0;
v2 = sigaction(sig, &v5, &v4) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v4.sa_handler;
return result;
}

original_code:
__sighandler_t my_signal(int sig, __sighandler_t handler)
{
 struct sigaction act;
 struct sigaction oldact;
 act.__sigaction_handler.sa_handler = handler;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (sigaction(sig, &act, &oldact) < 0)
  return ((__sighandler_t) -1);
 return oldact.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*my_signal(int sig, void (*handler)(int)))(int)
{
 struct sigaction act;
 struct sigaction oldact;
 act.__sigaction_handler.sa_handler = handler;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (sigaction(sig, &act, &oldact) < 0)
  return ((__sighandler_t) -1);
 return oldact.__sigaction_handler.sa_handler;
}

variable_types: sig int

variable_types:
handler
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)(); }

return_type: void (*)(int)


handler

decompiled_code:
int __fastcall handler(unsigned int a1)
{
return printf("rev sig=%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("rev sig=%d\n", a1);
}

original_code:
void handler(int sig)
{
 printf("rev sig=%d\n", sig);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
my_signal(2, (void (*)(int))handler);
while ( 1 )
pause();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func8(2, (void (*)(int))handler);
while ( 1 )
pause();
}

original_code:
int main(int argc, char *argv[])
{
 my_signal(2, handler);
 for (; ;)
  pause();
 return 0;
}


decompiled_code:
__int64 read_command()
{
return (unsigned int)-(fgets(cmdline, 1024, stdin) == 0LL);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)-(fgets(cmdline, 1024, stdin) == 0LL);
}

original_code:
int read_command(void)
{
 if (fgets(cmdline, 1024, stdin) == ((void *)0))
  return -1;
 return 0;
}

canonical_original_code:
int read_command()
{
 if (fgets(cmdline, 1024, stdin) == ((void *)0))
  return -1;
 return 0;
}


decompiled_code:
__int64 execute_command()
{
execute_disk_command();
return 0LL;
}

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

original_code:
int execute_command(void)
{
 execute_disk_command();
 return 0;
}

canonical_original_code:
int execute_command()
{
 execute_disk_command();
 return 0;
}


decompiled_code:
__int64 __fastcall get_command(int a1)
{
__int64 result; // rax
__int64 i; // rsi
char *v3; // rax
char v4; // cl
_BYTE *v5; // r14
char v6; // cl
char v7; // r15
char v8; // r15
int v9; // er14
_BYTE *v10; // rax
char v11; // cl
char v12; // al
_BYTE *v13; // rax
char v14; // cl

result = lineptr;
if ( *(_BYTE *)lineptr )
{
for ( i = 0LL; ; ++i )
{
if ( *(_BYTE *)lineptr == 32 || *(_BYTE *)lineptr == 9 )
{
v3 = (char *)(lineptr + 1);
do
{
do
{
lineptr = (__int64)v3;
v4 = *v3++;
}
while ( v4 == 32 );
}
while ( v4 == 9 );
}
cmd[22 * a1 + i] = avptr;
v5 = (_BYTE *)lineptr;
v6 = *(_BYTE *)lineptr;
v7 = 1;
if ( *(_BYTE *)lineptr <= 0x3Eu )
v7 = ((0x5000004100000600uLL >> v6) ^ 1) & 1;
v8 = (v6 != 124) & v7;
if ( v8 )
{
do
{
lineptr = (__int64)(v5 + 1);
v10 = (_BYTE *)avptr++;
*v10 = *v5;
v5 = (_BYTE *)lineptr;
v11 = *(_BYTE *)lineptr;
v12 = v8;
if ( *(_BYTE *)lineptr <= 0x3Eu )
v12 = ((0x5000004100000600uLL >> v11) ^ 1) & 1;
}
while ( v11 != 124 && v12 );
v9 = 1;
}
else
{
v9 = 0;
}
v13 = (_BYTE *)avptr++;
*v13 = 0;
result = lineptr;
v14 = *(_BYTE *)lineptr;
if ( *(char *)lineptr > 60 )
break;
if ( v14 <= 8 )
return result;
result = 1LL << v14;
if ( ((1LL << v14) & 0x1000004000000400LL) != 0 )
goto LABEL_25;
if ( (result & 0x100000200LL) == 0 )
return result;
}
if ( v14 == 62 || v14 == 124 )
{
LABEL_25:
if ( !v9 )
{
result = (int)i + 22LL * a1;
cmd[result] = 0LL;
}
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 result; // rax
__int64 i; // rsi
char *v3; // rax
char v4; // cl
_BYTE *v5; // r14
char v6; // cl
char v7; // r15
char v8; // r15
int v9; // er14
_BYTE *v10; // rax
char v11; // cl
char v12; // al
_BYTE *v13; // rax
char v14; // cl

result = lineptr;
if ( *(_BYTE *)lineptr )
{
for ( i = 0LL; ; ++i )
{
if ( *(_BYTE *)lineptr == 32 || *(_BYTE *)lineptr == 9 )
{
v3 = (char *)(lineptr + 1);
do
{
do
{
lineptr = (__int64)v3;
v4 = *v3++;
}
while ( v4 == 32 );
}
while ( v4 == 9 );
}
cmd[22 * a1 + i] = avptr;
v5 = (_BYTE *)lineptr;
v6 = *(_BYTE *)lineptr;
v7 = 1;
if ( *(_BYTE *)lineptr <= 0x3Eu )
v7 = ((0x5000004100000600uLL >> v6) ^ 1) & 1;
v8 = (v6 != 124) & v7;
if ( v8 )
{
do
{
lineptr = (__int64)(v5 + 1);
v10 = (_BYTE *)avptr++;
*v10 = *v5;
v5 = (_BYTE *)lineptr;
v11 = *(_BYTE *)lineptr;
v12 = v8;
if ( *(_BYTE *)lineptr <= 0x3Eu )
v12 = ((0x5000004100000600uLL >> v11) ^ 1) & 1;
}
while ( v11 != 124 && v12 );
v9 = 1;
}
else
{
v9 = 0;
}
v13 = (_BYTE *)avptr++;
*v13 = 0;
result = lineptr;
v14 = *(_BYTE *)lineptr;
if ( *(char *)lineptr > 60 )
break;
if ( v14 <= 8 )
return result;
result = 1LL << v14;
if ( ((1LL << v14) & 0x1000004000000400LL) != 0 )
goto LABEL_25;
if ( (result & 0x100000200LL) == 0 )
return result;
}
if ( v14 == 62 || v14 == 124 )
{
LABEL_25:
if ( !v9 )
{
result = (int)i + 22LL * a1;
cmd[result] = 0LL;
}
return result;
}
}
return result;
}

original_code:
void get_command(int num)
{
 int j = 0;
 int inword = 0;
 while(*lineptr != '\0')
 {
  while(*lineptr == ' ' || *lineptr == '\t')
   lineptr++;
  cmd[num].args[j] = avptr;
  while(*lineptr != ' '
   && *lineptr != '\t'
   && *lineptr != '|'
   && *lineptr != '<'
   && *lineptr != '>'
   && *lineptr != '&'
   && *lineptr != '\n')
  {
    *avptr++ = *lineptr++;
    inword = 1;
  }
  *avptr++ = '\0';
  switch(*lineptr)
  {
   case ' ':
   case '\t':
    inword = 0;
    j++;
    break;
   case '<':
   case '>':
   case '|':
   case '&':
   case '\n':
    if (inword == 0)
     cmd[num].args[j] = ((void *)0);
    return;
   default:
    return;
  }
 }
}

variable_types: num int

variable_types: j int

variable_types: inword int


check

decompiled_code:
__int64 __fastcall check(char *a1)
{
char *v1; // rdx
char *v2; // rax
char v3; // cl
char v4; // al

v1 = (char *)lineptr;
if ( *(_BYTE *)lineptr == 32 || *(_BYTE *)lineptr == 9 )
{
v2 = (char *)(lineptr + 1);
do
{
do
{
v1 = v2;
lineptr = (__int64)v2;
v3 = *v2++;
}
while ( v3 == 32 );
}
while ( v3 == 9 );
}
v4 = *a1;
if ( *a1 )
{
while ( *v1 == v4 )
{
++a1;
++v1;
v4 = *a1;
if ( !*a1 )
goto LABEL_9;
}
if ( v4 )
return 0LL;
}
LABEL_9:
lineptr = (__int64)v1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
char *v1; // rdx
char *v2; // rax
char v3; // cl
char v4; // al

v1 = (char *)lineptr;
if ( *(_BYTE *)lineptr == 32 || *(_BYTE *)lineptr == 9 )
{
v2 = (char *)(lineptr + 1);
do
{
do
{
v1 = v2;
lineptr = (__int64)v2;
v3 = *v2++;
}
while ( v3 == 32 );
}
while ( v3 == 9 );
}
v4 = *a1;
if ( *a1 )
{
while ( *v1 == v4 )
{
++a1;
++v1;
v4 = *a1;
if ( !*a1 )
goto LABEL_9;
}
if ( v4 )
return 0LL;
}
LABEL_9:
lineptr = (__int64)v1;
return 1LL;
}

original_code:
int check(const char* str)
{
 while(*lineptr == ' ' || *lineptr == '\t')
   lineptr++;
 char* p = lineptr;
 while(*str != '\0' && *p == *str)
 {
  str++;
  p++;
 }
 if(*str == '\0')
 {
  lineptr = p;
  return 1;
 }
 return 0;
}

canonical_original_code:
int check(char *str)
{
 while(*lineptr == ' ' || *lineptr == '\t')
   lineptr++;
 char *p = lineptr;
 while(*str != '\0' && *p == *str)
 {
  str++;
  p++;
 }
 if(*str == '\0')
 {
  lineptr = p;
  return 1;
 }
 return 0;
}

variable_types:
str
char *

variable_types:
p
char *


decompiled_code:
__int64 __fastcall parse_command(__int64 a1, unsigned __int64 a2)
{
unsigned int i; // ebx

if ( (unsigned int)check("\n") )
return (unsigned int)-1;
if ( (unsigned int)builtins() )
return (unsigned int)-1;
get_command(0);
if ( (unsigned int)check((char *)asc_402004) )
get_name(infile, a2);
for ( i = 1; i != 5; ++i )
{
if ( !(unsigned int)check((char *)&asc_402004[1]) )
break;
get_command(i);
}
if ( (unsigned int)check((char *)&asc_402004[2]) )
{
if ( (unsigned int)check((char *)&asc_402004[2]) )
append = 1;
get_name(outfile, a2);
}
if ( (unsigned int)check((char *)&asc_402004[3]) )
backgnd = 1;
if ( (unsigned int)check("\n") )
{
cmd_count = i;
}
else
{
fwrite("command line syntax error.\n", 1uLL, 0x1BuLL, stderr);
i = -1;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned __int64 a2)
{
unsigned int i; // ebx

if ( (unsigned int)func11("\n") )
return (unsigned int)-1;
if ( (unsigned int)func21() )
return (unsigned int)-1;
func9(0);
if ( (unsigned int)func11((char *)asc_402004) )
func10(infile, a2);
for ( i = 1; i != 5; ++i )
{
if ( !(unsigned int)func11((char *)&asc_402004[1]) )
break;
func9(i);
}
if ( (unsigned int)func11((char *)&asc_402004[2]) )
{
if ( (unsigned int)func11((char *)&asc_402004[2]) )
append = 1;
func10(outfile, a2);
}
if ( (unsigned int)func11((char *)&asc_402004[3]) )
backgnd = 1;
if ( (unsigned int)func11("\n") )
{
cmd_count = i;
}
else
{
fwrite("command line syntax error.\n", 1uLL, 0x1BuLL, stderr);
i = -1;
}
return i;
}

original_code:
int parse_command(void)
{
 if (check("\n"))
  return -1;
 if(builtins())
  return -1;
 get_command(0);
 if (check("<"))
  get_name(infile);
 int i;
 for (i = 1; i < 5; i++)
 {
  if (check("|"))
   get_command(i);
  else
   break;
 }
 if(check(">"))
 {
  if(check(">"))
   append = 1;
  get_name(outfile);
 }
 if(check("&"))
  backgnd = 1;
 if(check("\n"))
 {
  cmd_count = i;
  return cmd_count;
 }
 else
 {
  fprintf(stderr, "command line syntax error.\n");
  return -1;
 }
}

canonical_original_code:
int parse_command()
{
 if (check("\n"))
  return -1;
 if(builtins())
  return -1;
 get_command(0);
 if (check("<"))
  get_name(infile);
 int i;
 for (i = 1; i < 5; i++)
 {
  if (check("|"))
   get_command(i);
  else
   break;
 }
 if(check(">"))
 {
  if(check(">"))
   append = 1;
  get_name(outfile);
 }
 if(check("&"))
  backgnd = 1;
 if(check("\n"))
 {
  cmd_count = i;
  return cmd_count;
 }
 else
 {
  fprintf(stderr, "command line syntax error.\n");
  return -1;
 }
}

variable_types: i int