reverseComplementBlock

decompiled_code:
int *__fastcall reverseComplementBlock(int *a1)
{
char *v1; // rdx
int *result; // rax
__int64 v3; // rcx
__int64 v4; // rsi

v1 = (char *)(a1 + 1);
result = (int *)((char *)a1 + *a1 + 3);
if ( a1 + 1 <= result )
{
do
{
v3 = *v1;
v4 = *(char *)result;
++v1;
result = (int *)((char *)result - 1);
LOBYTE(v3) = complement[v3];
*(v1 - 1) = complement[v4];
*((_BYTE *)result + 1) = v3;
}
while ( v1 <= (char *)result );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func10(int *a1)
{
char *v1; // rdx
int *result; // rax
__int64 v3; // rcx
__int64 v4; // rsi

v1 = (char *)(a1 + 1);
result = (int *)((char *)a1 + *a1 + 3);
if ( a1 + 1 <= result )
{
do
{
v3 = *v1;
v4 = *(char *)result;
++v1;
result = (int *)((char *)result - 1);
LOBYTE(v3) = complement[v3];
*(v1 - 1) = complement[v4];
*((_BYTE *)result + 1) = v3;
}
while ( v1 <= (char *)result );
}
return result;
}

original_code:
void
reverseComplementBlock(Block * block)
{
 char *ptr1;
 char *ptr2;
 char c;
 ptr1 = &(block->text[0]);
 ptr2 = &(block->text[block->len - 1]);
 while (ptr1 <= ptr2) {
  c = complement[*ptr1];
  *ptr1 = complement[*ptr2];
  *ptr2 = c;
  ptr1++;
  ptr2--;
 }
}

canonical_original_code:
void reverseComplementBlock(struct block_struct *block)
{
 char *ptr1;
 char *ptr2;
 char c;
 ptr1 = &(block->text[0]);
 ptr2 = &(block->text[block->len - 1]);
 while (ptr1 <= ptr2) {
  c = complement[*ptr1];
  *ptr1 = complement[*ptr2];
  *ptr2 = c;
  ptr1++;
  ptr2--;
 }
}

variable_types: struct block_struct { int len; char text[1024]; struct block_struct *next; } *

variable_types: c char


readBlocks

repo: matthiasr/revcomp

decompiled_code:
_QWORD *readBlocks()
{
char v0; // r13
_QWORD *v1; // rbp
int v2; // ebx
_QWORD *v3; // r12
char v4; // al
__int64 v5; // rdx
_QWORD *result; // rax

v0 = 32;
v1 = 0LL;
LABEL_2:
v2 = feof(stdin);
if ( v2 )
return v1;
v3 = malloc(0x410uLL);
while ( !feof(stdin) )
{
v4 = my_getc(stdin);
v0 = v4;
if ( v4 == 62 )
{
ungetc(62, stdin);
*(_DWORD *)v3 = v2;
result = v3;
v3[129] = v1;
return result;
}
if ( v4 > 31 )
{
v5 = v2++;
*((_BYTE *)v3 + v5 + 4) = v4;
}
if ( v2 == 1024 )
{
*(_DWORD *)v3 = 1024;
v3[129] = v1;
LABEL_10:
v1 = v3;
goto LABEL_2;
}
}
*(_DWORD *)v3 = v2;
v3[129] = v1;
if ( v0 != 62 )
goto LABEL_10;
return v3;
}

canonical_decompiled_code:
_QWORD *func11()
{
char v0; // r13
_QWORD *v1; // rbp
int v2; // ebx
_QWORD *v3; // r12
char v4; // al
__int64 v5; // rdx
_QWORD *result; // rax

v0 = 32;
v1 = 0LL;
LABEL_2:
v2 = feof(stdin);
if ( v2 )
return v1;
v3 = malloc(0x410uLL);
while ( !feof(stdin) )
{
v4 = func7(stdin);
v0 = v4;
if ( v4 == 62 )
{
ungetc(62, stdin);
*(_DWORD *)v3 = v2;
result = v3;
v3[129] = v1;
return result;
}
if ( v4 > 31 )
{
v5 = v2++;
*((_BYTE *)v3 + v5 + 4) = v4;
}
if ( v2 == 1024 )
{
*(_DWORD *)v3 = 1024;
v3[129] = v1;
LABEL_10:
v1 = v3;
goto LABEL_2;
}
}
*(_DWORD *)v3 = v2;
v3[129] = v1;
if ( v0 != 62 )
goto LABEL_10;
return v3;
}

original_code:
Block *
readBlocks()
{
 char c;
 int i;
 Block *result;
 Block *old;
 old = ((void *)0);
 result = ((void *)0);
 c = ' ';
 while (c != '>' && !feof(stdin)) {
  result = malloc(sizeof(Block));
  i = 0;
  while (i < 1024 && !feof(stdin)) {
   c = (char)my_getc(stdin);
   if (c == '>') {
    ungetc(c, stdin);
    break;
   }
   if (c >= ' ') {
     result->text[i++] = c;
   }
  }
  result->len = i;
  result->next = old;
  old = result;
 }
 return result;
}

canonical_original_code:
struct block_struct *readBlocks()
{
 char c;
 int i;
 struct block_struct *result;
 struct block_struct *old;
 old = ((void *)0);
 result = ((void *)0);
 c = ' ';
 while (c != '>' && !feof(stdin)) {
  result = malloc(sizeof(Block));
  i = 0;
  while (i < 1024 && !feof(stdin)) {
   c = (char)my_getc(stdin);
   if (c == '>') {
    ungetc(c, stdin);
    break;
   }
   if (c >= ' ') {
     result->text[i++] = c;
   }
  }
  result->len = i;
  result->next = old;
  old = result;
 }
 return result;
}

variable_types: i int

return_type: struct block_struct { int len; char text[1024]; struct block_struct *next; } *


decompiled_code:
__int64 process_sequence()
{
int v0; // ebp
__int64 result; // rax
int *v2; // r12
__int64 v3; // rbx
int v4; // edi
int *v5; // rbx
char v6[168]; // [rsp+0h] [rbp-A8h] BYREF

v0 = feof(stdin);
result = 0LL;
if ( !v0 )
{
fgets(v6, 132, stdin);
if ( !index(v6, 10) )
{
while ( my_getc(stdin) != 10 )
;
}
v2 = (int *)readBlocks();
printf("%s", v6);
if ( v2 )
{
while ( 1 )
{
reverseComplementBlock(v2);
if ( *v2 > 0 )
{
v3 = 0LL;
do
{
if ( v0 == 60 )
{
v0 = 1;
my_putc(10, stdout);
}
else
{
++v0;
}
v4 = *((char *)v2 + v3++ + 4);
my_putc(v4, stdout);
}
while ( *v2 > (int)v3 );
}
v5 = (int *)*((_QWORD *)v2 + 129);
free(v2);
if ( !v5 )
break;
v2 = v5;
}
}
my_putc(10, stdout);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebp
__int64 result; // rax
int *v2; // r12
__int64 v3; // rbx
int v4; // edi
int *v5; // rbx
char v6[168]; // [rsp+0h] [rbp-A8h] BYREF

v0 = feof(stdin);
result = 0LL;
if ( !v0 )
{
fgets(v6, 132, stdin);
if ( !index(v6, 10) )
{
while ( func7(stdin) != 10 )
;
}
v2 = (int *)func11();
printf("%s", v6);
if ( v2 )
{
while ( 1 )
{
func10(v2);
if ( *v2 > 0 )
{
v3 = 0LL;
do
{
if ( v0 == 60 )
{
v0 = 1;
func8(10, stdout);
}
else
{
++v0;
}
v4 = *((char *)v2 + v3++ + 4);
func8(v4, stdout);
}
while ( *v2 > (int)v3 );
}
v5 = (int *)*((_QWORD *)v2 + 129);
free(v2);
if ( !v5 )
break;
v2 = v5;
}
}
func8(10, stdout);
result = 1LL;
}
return result;
}

original_code:
int
process_sequence()
{
 char title [132];
 Block *ptr;
 Block *old_ptr;
 int i;
 int cpos;
 if (!feof(stdin)) {
  fgets(title, 132, stdin);
 } else {
  return 0;
 }
 if (index(title, '\n') == ((void *)0)) {
  while (my_getc(stdin) != '\n') {
  }
 }
 ptr = readBlocks();
 printf("%s", title);
 cpos = 0;
 while (ptr != ((void *)0)) {
  reverseComplementBlock(ptr);
  for (i = 0; i < ptr->len; i++) {
   if (cpos++ == 60) {
    my_putc('\n', stdout);
    cpos = 1;
   }
   my_putc(ptr->text[i], stdout);
  }
  old_ptr = ptr;
  ptr = ptr->next;
  free(old_ptr);
 }
 my_putc('\n', stdout);
 return 1;
}

canonical_original_code:
int process_sequence()
{
 char title[132];
 struct block_struct *ptr;
 struct block_struct *old_ptr;
 int i;
 int cpos;
 if (!feof(stdin)) {
  fgets(title, 132, stdin);
 } else {
  return 0;
 }
 if (index(title, '\n') == ((void *)0)) {
  while (my_getc(stdin) != '\n') {
  }
 }
 ptr = readBlocks();
 printf("%s", title);
 cpos = 0;
 while (ptr != ((void *)0)) {
  reverseComplementBlock(ptr);
  for (i = 0; i < ptr->len; i++) {
   if (cpos++ == 60) {
    my_putc('\n', stdout);
    cpos = 1;
   }
   my_putc(ptr->text[i], stdout);
  }
  old_ptr = ptr;
  ptr = ptr->next;
  free(old_ptr);
 }
 my_putc('\n', stdout);
 return 1;
}

variable_types:
title
char [132]

variable_types: cpos int

return_type: int

user_defined_types: struct block_struct { int len; char text[1024]; struct block_struct *next; }


main

canonical_name: main

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

memset(&complement, 0, 0x100uLL);
setComplement(65LL, 84LL);
setComplement(67LL, 71LL);
setComplement(77LL, 75LL);
setComplement(82LL, 89LL);
setComplement(87LL, 87LL);
setComplement(83LL, 83LL);
setComplement(86LL, 66LL);
setComplement(72LL, 68LL);
setComplement(78LL, 78LL);
do
result = process_sequence();
while ( result );
return result;
}

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

memset(&complement, 0, 0x100uLL);
func9(65LL, 84LL);
func9(67LL, 71LL);
func9(77LL, 75LL);
func9(82LL, 89LL);
func9(87LL, 87LL);
func9(83LL, 83LL);
func9(86LL, 66LL);
func9(72LL, 68LL);
func9(78LL, 78LL);
do
result = func12();
while ( result );
return result;
}

original_code:
int
main(int argc, char** argv)
{
 int i;
 char title [132];
 for (i = 0; i < 256; i++) {
  complement[i] = 0;
 }
 setComplement('A', 'T');
 setComplement('C', 'G');
 setComplement('M', 'K');
 setComplement('R', 'Y');
 setComplement('W', 'W');
 setComplement('S', 'S');
 setComplement('V', 'B');
 setComplement('H', 'D');
 setComplement('N', 'N');
 while (process_sequence()) {
 }
        return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 char title[132];
 for (i = 0; i < 256; i++) {
  complement[i] = 0;
 }
 setComplement('A', 'T');
 setComplement('C', 'G');
 setComplement('M', 'K');
 setComplement('R', 'Y');
 setComplement('W', 'W');
 setComplement('S', 'S');
 setComplement('V', 'B');
 setComplement('H', 'D');
 setComplement('N', 'N');
 while (process_sequence()) {
 }
        return 0;
}

variable_types: argc int

variable_types:
argv
char **


original_code:
void setup_complement(void) {
    unsigned char c;
    for(c=0; c < 255; c++) complement[c] = c;
        { complement['G'] = 'C'; complement['C'] = 'G'; complement['G'+32]='C'; complement['C'+32]='G'; };
        { complement['A'] = 'T'; complement['T'] = 'A'; complement['A'+32]='T'; complement['T'+32]='A'; };
        { complement['M'] = 'K'; complement['K'] = 'M'; complement['M'+32]='K'; complement['K'+32]='M'; };
        { complement['R'] = 'Y'; complement['Y'] = 'R'; complement['R'+32]='Y'; complement['Y'+32]='R'; };
        { complement['V'] = 'B'; complement['B'] = 'V'; complement['V'+32]='B'; complement['B'+32]='V'; };
        { complement['H'] = 'D'; complement['D'] = 'H'; complement['H'+32]='D'; complement['D'+32]='H'; };
}

canonical_original_code:
void setup_complement() {
    unsigned char c;
    for(c=0; c < 255; c++) complement[c] = c;
        { complement['G'] = 'C'; complement['C'] = 'G'; complement['G'+32]='C'; complement['C'+32]='G'; };
        { complement['A'] = 'T'; complement['T'] = 'A'; complement['A'+32]='T'; complement['T'+32]='A'; };
        { complement['M'] = 'K'; complement['K'] = 'M'; complement['M'+32]='K'; complement['K'+32]='M'; };
        { complement['R'] = 'Y'; complement['Y'] = 'R'; complement['R'+32]='Y'; complement['Y'+32]='R'; };
        { complement['V'] = 'B'; complement['B'] = 'V'; complement['V'+32]='B'; complement['B'+32]='V'; };
        { complement['H'] = 'D'; complement['D'] = 'H'; complement['H'+32]='D'; complement['D'+32]='H'; };
}

variable_types:
c
unsigned char

return_type: void


complementAll

decompiled_code:
__int64 __fastcall complementAll(char *a1, __int64 a2)
{
char *v2; // rsi
__int64 v3; // rax
__int64 result; // rax

if ( a2 )
{
v2 = &a1[a2];
do
{
v3 = *a1++;
result = (unsigned __int8)complement[v3];
*(a1 - 1) = result;
}
while ( v2 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, __int64 a2)
{
char *v2; // rsi
__int64 v3; // rax
__int64 result; // rax

if ( a2 )
{
v2 = &a1[a2];
do
{
v3 = *a1++;
result = (unsigned __int8)complement[v3];
*(a1 - 1) = result;
}
while ( v2 != a1 );
}
return result;
}

original_code:
void complementAll(char* array, size_t len) {
    int i;
    for(i=0; i<len; i++)
        array[i] = complement[array[i]];
}

canonical_original_code:
void complementAll(char *array, unsigned long len) {
    int i;
    for(i=0; i<len; i++)
        array[i] = complement[array[i]];
}

variable_types:
array
char *

variable_types:
len
unsigned long


reverse

decompiled_code:
unsigned __int64 __fastcall reverse(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // r8
char i; // dl
_BYTE *v5; // r9
char j; // cl

for ( result = 0LL; result < a2; *v5 = i )
{
v3 = (_BYTE *)(a1 + result);
for ( i = *(_BYTE *)(a1 + result); i == 10; v3 = (_BYTE *)(a1 + result) )
{
++result;
i = *(_BYTE *)(a1 + result);
}
v5 = (_BYTE *)(a1 + a2);
for ( j = *(_BYTE *)(a1 + a2); j == 10; v5 = (_BYTE *)(a1 + a2) )
{
--a2;
j = *(_BYTE *)(a1 + a2);
}
++result;
--a2;
*v3 = j;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // r8
char i; // dl
_BYTE *v5; // r9
char j; // cl

for ( result = 0LL; result < a2; *v5 = i )
{
v3 = (_BYTE *)(a1 + result);
for ( i = *(_BYTE *)(a1 + result); i == 10; v3 = (_BYTE *)(a1 + result) )
{
++result;
i = *(_BYTE *)(a1 + result);
}
v5 = (_BYTE *)(a1 + a2);
for ( j = *(_BYTE *)(a1 + a2); j == 10; v5 = (_BYTE *)(a1 + a2) )
{
--a2;
j = *(_BYTE *)(a1 + a2);
}
++result;
--a2;
*v3 = j;
}
return result;
}

original_code:
void reverse(char* array, size_t len) {
    char temp;
    size_t a = 0, b = len;
    while(a<b) {
        while(array[a] == '\n') a++;
        while(array[b] == '\n') b--;
        temp = array[a];
        array[a] = array[b];
        array[b] = temp;
        a++; b--;
    }
}

canonical_original_code:
void reverse(char *array, unsigned long len) {
    char temp;
    unsigned long a = 0; unsigned long b = len;
    while(a<b) {
        while(array[a] == '\n') a++;
        while(array[b] == '\n') b--;
        temp = array[a];
        array[a] = array[b];
        array[b] = temp;
        a++; b--;
    }
}

variable_types: temp char

variable_types:
a
unsigned long

variable_types:
b
unsigned long


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // r12
size_t v4; // rbx
char *v5; // rbp
size_t v6; // r10
char *i; // r8
size_t v8; // r9
__int64 v9; // r8
__int64 v10; // r9
__int64 v11; // r8
__int64 v12; // r10

v3 = 0LL;
v4 = 1024LL;
setup_complement(1024LL, argv, envp);
v5 = (char *)malloc(0x400uLL);
while ( !feof(stdin) )
{
while ( 1 )
{
v3 += fread(&v5[v3], 1uLL, v4 - v3, stdin);
if ( v4 != v3 )
break;
v4 *= 2LL;
v5 = (char *)realloc(v5, v4);
if ( feof(stdin) )
goto LABEL_5;
}
}
LABEL_5:
v6 = 0LL;
if ( v3 )
{
while ( 1 )
{
for ( i = &v5[v6]; v5[v6] != 10; i = &v5[v6] )
++v6;
v8 = v6;
if ( v3 <= v6 )
break;
while ( v5[v6] != 62 )
{
if ( v3 == ++v6 )
goto LABEL_14;
}
complementAll(i, v6 + ~v8);
reverse(v9, v10);
if ( v3 <= v6 )
goto LABEL_13;
}
LABEL_14:
complementAll(i, ~v8 + v6);
reverse(v11, v12);
}
LABEL_13:
fwrite(v5, 1uLL, v3, stdout);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // r12
size_t v4; // rbx
char *v5; // rbp
size_t v6; // r10
char *i; // r8
size_t v8; // r9
__int64 v9; // r8
__int64 v10; // r9
__int64 v11; // r8
__int64 v12; // r10

v3 = 0LL;
v4 = 1024LL;
func7(1024LL, argv, envp);
v5 = (char *)malloc(0x400uLL);
while ( !feof(stdin) )
{
while ( 1 )
{
v3 += fread(&v5[v3], 1uLL, v4 - v3, stdin);
if ( v4 != v3 )
break;
v4 *= 2LL;
v5 = (char *)realloc(v5, v4);
if ( feof(stdin) )
goto LABEL_5;
}
}
LABEL_5:
v6 = 0LL;
if ( v3 )
{
while ( 1 )
{
for ( i = &v5[v6]; v5[v6] != 10; i = &v5[v6] )
++v6;
v8 = v6;
if ( v3 <= v6 )
break;
while ( v5[v6] != 62 )
{
if ( v3 == ++v6 )
goto LABEL_14;
}
func8(i, v6 + ~v8);
func9(v9, v10);
if ( v3 <= v6 )
goto LABEL_13;
}
LABEL_14:
func8(i, ~v8 + v6);
func9(v11, v12);
}
LABEL_13:
fwrite(v5, 1uLL, v3, stdout);
exit(0);
}

original_code:
int main(int argc, char** argv) {
    setup_complement();
    size_t bufsize = 1024;
    size_t nread = 0;
    size_t blockstart=0, blockend=0;
    char* buf;
    buf = malloc(sizeof(char)*bufsize);
    while(!feof(stdin)) {
        nread += fread(buf+nread, sizeof(char), bufsize-nread, stdin);
        if(nread == bufsize) {
            bufsize *= 2;
            buf = realloc(buf, bufsize);
        }
    }
    while(blockstart < nread) {
        while(buf[blockstart] != '\n')
            blockstart++;
        blockend = blockstart;
        while(blockend < nread && buf[blockend] != '>')
            blockend++;
        blockend--;
        complementAll(buf+blockstart, blockend-blockstart);
        reverse(buf+blockstart, blockend-blockstart);
        blockstart = blockend+1;
    }
    fwrite(buf, sizeof(char), nread, stdout);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv) {
    setup_complement();
    unsigned long bufsize = 1024;
    unsigned long nread = 0;
    unsigned long blockstart = 0; unsigned long blockend = 0;
    char *buf;
    buf = malloc(sizeof(char)*bufsize);
    while(!feof(stdin)) {
        nread += fread(buf+nread, sizeof(char), bufsize-nread, stdin);
        if(nread == bufsize) {
            bufsize *= 2;
            buf = realloc(buf, bufsize);
        }
    }
    while(blockstart < nread) {
        while(buf[blockstart] != '\n')
            blockstart++;
        blockend = blockstart;
        while(blockend < nread && buf[blockend] != '>')
            blockend++;
        blockend--;
        complementAll(buf+blockstart, blockend-blockstart);
        reverse(buf+blockstart, blockend-blockstart);
        blockstart = blockend+1;
    }
    fwrite(buf, sizeof(char), nread, stdout);
    exit(0);
}

variable_types:
bufsize
unsigned long

variable_types:
nread
unsigned long

variable_types:
blockstart
unsigned long

variable_types:
blockend
unsigned long

variable_types:
buf
char *


repo: matthiasr/teco

decompiled_code:
__int64 find_lasteol()
{
unsigned int v0; // er12
char v1; // al
__int64 result; // rax

v0 = 0;
t_qp[1] = mstack[1];
t_qp[2] = mstack[2];
while ( 1 )
{
if ( !(unsigned int)backc(t_qp) )
{
char_count = 0;
return v0;
}
v1 = *(_BYTE *)(t_qp[1] + t_qp[2] + 16LL);
if ( v1 == 13 || v1 == 10 )
break;
++v0;
}
fwdc(t_qp);
result = v0;
char_count = 0;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12
char v1; // al
__int64 result; // rax

v0 = 0;
t_qp[1] = mstack[1];
t_qp[2] = mstack[2];
while ( 1 )
{
if ( !(unsigned int)backc(t_qp) )
{
char_count = 0;
return v0;
}
v1 = *(_BYTE *)(t_qp[1] + t_qp[2] + 16LL);
if ( v1 == 13 || v1 == 10 )
break;
++v0;
}
fwdc(t_qp);
result = v0;
char_count = 0;
return result;
}

original_code:
int find_lasteol()
    {
    int i;
    for (i = 0, t_qp.p = mstack[0].p, t_qp.c = mstack[0].c; (backc(&t_qp)) ; i++)
 {
 if ((t_qp.p->ch[t_qp.c] == 015) || (t_qp.p->ch[t_qp.c] == 012))
     {
     fwdc(&t_qp);
     break;
     }
 }
    char_count = 0;
    return(i);
    }


decompiled_code:
__int64 read_cmdstr()
{
FILE *v0; // rdi
char v1; // bl
FILE *v2; // rdi
__int64 v3; // rdx
__int64 v4; // rax
unsigned int v5; // er12
bool v6; // zf
__int64 result; // rax
__int64 v8; // rdx
__int64 v9; // rax
char v10; // al
char v11; // r12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rdx
__int64 v16; // rax
char v17; // al
__int64 v18; // rdx
__int64 v19; // rax
__int64 v20; // rsi
__int64 v21; // rcx
__int64 v22; // rax
unsigned __int64 i; // rcx
char v24; // al
char v25; // bl
unsigned __int16 v26; // ax
_DWORD *v27; // rdx
int v28; // eax
int v29; // ebx
__int64 v30; // rax
__int64 v31; // rdx
_DWORD *v32; // rdx
char v33; // al
unsigned int v34; // er12
__int64 v35; // rbx
__int64 v36; // rax
__int64 v37; // rax

v0 = eisw;
LABEL_2:
if ( v0 )
goto LABEL_5;
while ( 1 )
{
v0 = 0LL;
if ( !inp_noterm )
{
type_char(42LL);
v0 = eisw;
}
LABEL_5:
ccount = 0;
lastc = 32;
LABEL_9:
while ( 2 )
{
if ( v0 )
{
if ( !ccount )
{
if ( qreg[0] )
{
mstack[1] = qreg[0];
mstack[2] = 0LL;
qreg[2] = 0LL;
}
else
{
LABEL_52:
v13 = get_bcell();
v0 = eisw;
qreg[0] = v13;
*(_QWORD *)(v13 + 8) = qreg;
mstack[1] = v13;
mstack[2] = 0LL;
qreg[2] = 0LL;
if ( !v0 )
goto LABEL_27;
}
}
v1 = getc(v0);
goto LABEL_14;
}
while ( inp_noterm )
{
if ( !ccount )
{
if ( !qreg[0] )
goto LABEL_52;
mstack[1] = qreg[0];
mstack[2] = 0LL;
qreg[2] = 0LL;
}
LABEL_27:
v1 = gettty();
LABEL_14:
v2 = eisw;
if ( v1 != -1 || !eisw )
{
if ( v1 != 10 )
goto LABEL_17;
if ( lastc != 13 && (ez_val & 1) == 0 )
{
v14 = mstack[2];
v15 = mstack[1];
++ccount;
*(_BYTE *)(v15 + v14 + 16) = 13;
fwdcx(mstack);
v2 = eisw;
}
v8 = mstack[1];
v9 = mstack[2];
++ccount;
*(_BYTE *)(v8 + v9 + 16) = 10;
if ( !v2 && !inp_noterm )
type_char(10LL);
fwdcx(mstack);
LABEL_8:
lastc = v1;
v0 = eisw;
goto LABEL_9;
}
fclose(eisw);
eisw = 0LL;
lastc = 32;
}
v10 = gettty();
v11 = v10;
v1 = v10;
if ( v10 == 127 )
{
if ( ccount )
{
--ccount;
backc(mstack);
v17 = *(_BYTE *)(mstack[1] + mstack[2] + 16LL);
if ( v17 == 27 || v17 > 31 )
{
vt(5LL);
--char_count;
}
else if ( v17 == 10 )
{
vt(7LL);
}
else if ( (v17 & 0xFB) == 9 )
{
v29 = find_lasteol();
type_char(13LL);
vt(1LL);
if ( ccount == v29 )
type_char(42LL);
while ( 1 )
{
v30 = t_qp[1];
v31 = t_qp[2];
if ( v30 == mstack[1] && mstack[2] == v31 )
break;
type_char((unsigned int)*(char *)(v30 + v31 + 16));
fwdc(t_qp);
}
}
else
{
vt(6LL);
char_count -= 2;
}
goto LABEL_67;
}
goto LABEL_55;
}
if ( v10 == 21 )
{
type_char(13LL);
vt(1LL);
ccount -= find_lasteol();
if ( ccount > 0 )
{
v16 = t_qp[1];
lastc = 32;
v0 = eisw;
mstack[1] = v16;
mstack[2] = t_qp[2];
continue;
}
LABEL_58:
v0 = eisw;
goto LABEL_2;
}
break;
}
if ( ccount )
goto LABEL_45;
if ( v10 == 42 )
{
type_char(42LL);
v34 = (char)gettty();
type_char(v34);
v35 = (int)getqspec(0LL, v34);
free_blist(qreg[4 * v35]);
v36 = qreg[0];
qreg[4 * v35] = qreg[0];
if ( v36 )
*(_QWORD *)(v36 + 8) = &qreg[4 * v35];
v37 = qreg[2];
LODWORD(err) = 0;
qreg[4 * v35 + 2] = v37;
qreg[2] = 0LL;
qreg[0] = 0LL;
goto LABEL_55;
}
if ( v10 == 63 )
break;
if ( (v10 & 0xFD) == 8 )
{
*(_QWORD *)(pbuff + 24LL) += (int)lines(2 * (unsigned int)(v10 == 10) - 1);
window(5LL);
}
else if ( v10 == 23 )
{
if ( !win_data[7] )
goto LABEL_44;
window(6LL);
window(4LL);
}
else
{
if ( v10 != 27 || (ed_val & 0x20) == 0 )
goto LABEL_44;
qword_BA8 = &estack;
v24 = gettty();
v25 = v24;
if ( v24 <= 31 )
{
v27 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 0;
*v27 = v24;
goto LABEL_88;
}
if ( v24 == 91 || v24 == 79 )
v25 = gettty();
v26 = (*_ctype_b_loc())[v25];
if ( (v26 & 0x100) != 0 )
{
v27 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 1;
*v27 = v25 - 64;
goto LABEL_88;
}
if ( (v26 & 0x200) != 0 )
{
v27 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 2;
*v27 = v25 - 96;
LABEL_88:
v27[1] = 1;
v27[3] = 1;
v28 = getqspec(0LL, 97LL);
exec_qreg(&qreg[4 * v28]);
window(4LL);
v0 = eisw;
goto LABEL_9;
}
if ( (v26 & 0x800) != 0 )
{
v32 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 3;
*v32 = v25 - 48;
while ( 1 )
{
v33 = gettty();
v27 = (_DWORD *)qword_BA8;
if ( v33 == 126 )
break;
*qword_BA8 = v33 + 10 * *qword_BA8 - 48;
}
goto LABEL_88;
}
}
LABEL_55:
v0 = eisw;
if ( eisw )
goto LABEL_5;
if ( !inp_noterm )
{
crlf();
goto LABEL_58;
}
}
if ( (_DWORD)err )
{
type_char(63LL);
v18 = msp;
v19 = *(_QWORD *)(msp + 8LL);
v20 = *(_QWORD *)(v19 + 8);
aa[1] = v19;
v21 = *(_QWORD *)(v20 + 8);
if ( v21 )
{
while ( 1 )
{
v22 = v21;
v21 = *(_QWORD *)(v21 + 8);
if ( !v21 )
break;
v20 = v22;
}
aa[1] = v20;
v19 = v20;
}
aa[2] = 0LL;
for ( i = 0LL; *(_QWORD *)(v18 + 8) != v19 || *(_QWORD *)(v18 + 16) > i; i = aa[2] )
{
type_char((unsigned int)*(char *)(v19 + i + 16));
fwdc(aa);
v19 = aa[1];
v18 = msp;
}
type_char(63LL);
LODWORD(err) = 0;
goto LABEL_55;
}
LABEL_44:
make_buffer(qreg);
v12 = qreg[0];
mstack[2] = 0LL;
qreg[2] = 0LL;
mstack[1] = v12;
LODWORD(err) = 0;
LABEL_45:
v2 = eisw;
if ( lastc != 7 )
goto LABEL_17;
if ( v11 == 7 )
{
qreg[2] = ccount;
goto LABEL_55;
}
if ( v11 == 42 || v11 == 32 )
{
backc(mstack);
--ccount;
crlf();
retype_cmdstr(v11);
LABEL_67:
lastc = 32;
v0 = eisw;
goto LABEL_9;
}
LABEL_17:
v3 = mstack[1];
v4 = mstack[2];
++ccount;
*(_BYTE *)(v3 + v4 + 16) = v1;
if ( !v2 && !inp_noterm )
type_char((unsigned int)v1);
fwdcx(mstack);
if ( v1 == 27 )
{
if ( lastc != 27 )
goto LABEL_8;
v5 = 0;
v6 = eisw == 0LL;
qreg[2] = ccount;
if ( v6 )
{
v5 = inp_noterm;
if ( !inp_noterm )
{
crlf();
goto LABEL_21;
}
result = 0LL;
}
else
{
LABEL_21:
result = v5;
}
}
else
{
if ( v1 != 3 || lastc != 3 )
goto LABEL_8;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
FILE *v0; // rdi
char v1; // bl
FILE *v2; // rdi
__int64 v3; // rdx
__int64 v4; // rax
unsigned int v5; // er12
bool v6; // zf
__int64 result; // rax
__int64 v8; // rdx
__int64 v9; // rax
char v10; // al
char v11; // r12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rdx
__int64 v16; // rax
char v17; // al
__int64 v18; // rdx
__int64 v19; // rax
__int64 v20; // rsi
__int64 v21; // rcx
__int64 v22; // rax
unsigned __int64 i; // rcx
char v24; // al
char v25; // bl
unsigned __int16 v26; // ax
_DWORD *v27; // rdx
int v28; // eax
int v29; // ebx
__int64 v30; // rax
__int64 v31; // rdx
_DWORD *v32; // rdx
char v33; // al
unsigned int v34; // er12
__int64 v35; // rbx
__int64 v36; // rax
__int64 v37; // rax

v0 = eisw;
LABEL_2:
if ( v0 )
goto LABEL_5;
while ( 1 )
{
v0 = 0LL;
if ( !inp_noterm )
{
type_char(42LL);
v0 = eisw;
}
LABEL_5:
ccount = 0;
lastc = 32;
LABEL_9:
while ( 2 )
{
if ( v0 )
{
if ( !ccount )
{
if ( qreg[0] )
{
mstack[1] = qreg[0];
mstack[2] = 0LL;
qreg[2] = 0LL;
}
else
{
LABEL_52:
v13 = get_bcell();
v0 = eisw;
qreg[0] = v13;
*(_QWORD *)(v13 + 8) = qreg;
mstack[1] = v13;
mstack[2] = 0LL;
qreg[2] = 0LL;
if ( !v0 )
goto LABEL_27;
}
}
v1 = getc(v0);
goto LABEL_14;
}
while ( inp_noterm )
{
if ( !ccount )
{
if ( !qreg[0] )
goto LABEL_52;
mstack[1] = qreg[0];
mstack[2] = 0LL;
qreg[2] = 0LL;
}
LABEL_27:
v1 = gettty();
LABEL_14:
v2 = eisw;
if ( v1 != -1 || !eisw )
{
if ( v1 != 10 )
goto LABEL_17;
if ( lastc != 13 && (ez_val & 1) == 0 )
{
v14 = mstack[2];
v15 = mstack[1];
++ccount;
*(_BYTE *)(v15 + v14 + 16) = 13;
fwdcx(mstack);
v2 = eisw;
}
v8 = mstack[1];
v9 = mstack[2];
++ccount;
*(_BYTE *)(v8 + v9 + 16) = 10;
if ( !v2 && !inp_noterm )
type_char(10LL);
fwdcx(mstack);
LABEL_8:
lastc = v1;
v0 = eisw;
goto LABEL_9;
}
fclose(eisw);
eisw = 0LL;
lastc = 32;
}
v10 = gettty();
v11 = v10;
v1 = v10;
if ( v10 == 127 )
{
if ( ccount )
{
--ccount;
backc(mstack);
v17 = *(_BYTE *)(mstack[1] + mstack[2] + 16LL);
if ( v17 == 27 || v17 > 31 )
{
vt(5LL);
--char_count;
}
else if ( v17 == 10 )
{
vt(7LL);
}
else if ( (v17 & 0xFB) == 9 )
{
v29 = func0();
type_char(13LL);
vt(1LL);
if ( ccount == v29 )
type_char(42LL);
while ( 1 )
{
v30 = t_qp[1];
v31 = t_qp[2];
if ( v30 == mstack[1] && mstack[2] == v31 )
break;
type_char((unsigned int)*(char *)(v30 + v31 + 16));
fwdc(t_qp);
}
}
else
{
vt(6LL);
char_count -= 2;
}
goto LABEL_67;
}
goto LABEL_55;
}
if ( v10 == 21 )
{
type_char(13LL);
vt(1LL);
ccount -= func0();
if ( ccount > 0 )
{
v16 = t_qp[1];
lastc = 32;
v0 = eisw;
mstack[1] = v16;
mstack[2] = t_qp[2];
continue;
}
LABEL_58:
v0 = eisw;
goto LABEL_2;
}
break;
}
if ( ccount )
goto LABEL_45;
if ( v10 == 42 )
{
type_char(42LL);
v34 = (char)gettty();
type_char(v34);
v35 = (int)getqspec(0LL, v34);
free_blist(qreg[4 * v35]);
v36 = qreg[0];
qreg[4 * v35] = qreg[0];
if ( v36 )
*(_QWORD *)(v36 + 8) = &qreg[4 * v35];
v37 = qreg[2];
LODWORD(err) = 0;
qreg[4 * v35 + 2] = v37;
qreg[2] = 0LL;
qreg[0] = 0LL;
goto LABEL_55;
}
if ( v10 == 63 )
break;
if ( (v10 & 0xFD) == 8 )
{
*(_QWORD *)(pbuff + 24LL) += (int)lines(2 * (unsigned int)(v10 == 10) - 1);
window(5LL);
}
else if ( v10 == 23 )
{
if ( !win_data[7] )
goto LABEL_44;
window(6LL);
window(4LL);
}
else
{
if ( v10 != 27 || (ed_val & 0x20) == 0 )
goto LABEL_44;
qword_BA8 = &estack;
v24 = gettty();
v25 = v24;
if ( v24 <= 31 )
{
v27 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 0;
*v27 = v24;
goto LABEL_88;
}
if ( v24 == 91 || v24 == 79 )
v25 = gettty();
v26 = (*_ctype_b_loc())[v25];
if ( (v26 & 0x100) != 0 )
{
v27 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 1;
*v27 = v25 - 64;
goto LABEL_88;
}
if ( (v26 & 0x200) != 0 )
{
v27 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 2;
*v27 = v25 - 96;
LABEL_88:
v27[1] = 1;
v27[3] = 1;
v28 = getqspec(0LL, 97LL);
exec_qreg(&qreg[4 * v28]);
window(4LL);
v0 = eisw;
goto LABEL_9;
}
if ( (v26 & 0x800) != 0 )
{
v32 = (_DWORD *)qword_BA8;
*(_DWORD *)(qword_BA8 + 8LL) = 3;
*v32 = v25 - 48;
while ( 1 )
{
v33 = gettty();
v27 = (_DWORD *)qword_BA8;
if ( v33 == 126 )
break;
*qword_BA8 = v33 + 10 * *qword_BA8 - 48;
}
goto LABEL_88;
}
}
LABEL_55:
v0 = eisw;
if ( eisw )
goto LABEL_5;
if ( !inp_noterm )
{
crlf();
goto LABEL_58;
}
}
if ( (_DWORD)err )
{
type_char(63LL);
v18 = msp;
v19 = *(_QWORD *)(msp + 8LL);
v20 = *(_QWORD *)(v19 + 8);
aa[1] = v19;
v21 = *(_QWORD *)(v20 + 8);
if ( v21 )
{
while ( 1 )
{
v22 = v21;
v21 = *(_QWORD *)(v21 + 8);
if ( !v21 )
break;
v20 = v22;
}
aa[1] = v20;
v19 = v20;
}
aa[2] = 0LL;
for ( i = 0LL; *(_QWORD *)(v18 + 8) != v19 || *(_QWORD *)(v18 + 16) > i; i = aa[2] )
{
type_char((unsigned int)*(char *)(v19 + i + 16));
fwdc(aa);
v19 = aa[1];
v18 = msp;
}
type_char(63LL);
LODWORD(err) = 0;
goto LABEL_55;
}
LABEL_44:
make_buffer(qreg);
v12 = qreg[0];
mstack[2] = 0LL;
qreg[2] = 0LL;
mstack[1] = v12;
LODWORD(err) = 0;
LABEL_45:
v2 = eisw;
if ( lastc != 7 )
goto LABEL_17;
if ( v11 == 7 )
{
qreg[2] = ccount;
goto LABEL_55;
}
if ( v11 == 42 || v11 == 32 )
{
backc(mstack);
--ccount;
crlf();
func1(v11);
LABEL_67:
lastc = 32;
v0 = eisw;
goto LABEL_9;
}
LABEL_17:
v3 = mstack[1];
v4 = mstack[2];
++ccount;
*(_BYTE *)(v3 + v4 + 16) = v1;
if ( !v2 && !inp_noterm )
type_char((unsigned int)v1);
fwdcx(mstack);
if ( v1 == 27 )
{
if ( lastc != 27 )
goto LABEL_8;
v5 = 0;
v6 = eisw == 0LL;
qreg[2] = ccount;
if ( v6 )
{
v5 = inp_noterm;
if ( !inp_noterm )
{
crlf();
goto LABEL_21;
}
result = 0LL;
}
else
{
LABEL_21:
result = v5;
}
}
else
{
if ( v1 != 3 || lastc != 3 )
goto LABEL_8;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int read_cmdstr()
    {
    char c;
    int i;
    goto prompt;
  restart:
    if (!eisw && !inp_noterm) crlf();
  prompt:
    if (!eisw && !inp_noterm)
 {
 type_char('*');
 }
    ccount = 0;
    lastc = ' ';
reline:
    for (;;)
 {
 if (!eisw && !inp_noterm)
     {
     if ((c = gettty()) == 0177)
  {
  if (!ccount) goto restart;
  --ccount;
  backc(&mstack[0]);
  if (((c = mstack[0].p->ch[mstack[0].c]) < ' ') && (c != 033))
      {
      if (c == 012) vt(7);
      else if ((c == 015) || (c == 011))
   {
   i = find_lasteol();
   type_char(015);
   vt(1);
   if (i == ccount) type_char('*');
   for (; (t_qp.p != mstack[0].p) || (t_qp.c != mstack[0].c); fwdc(&t_qp))
       type_char(t_qp.p->ch[t_qp.c]);
   }
      else
   {
   vt(6);
   char_count -= 2;
   }
      }
  else
      {
      vt(5);
      char_count--;
      }
  lastc = ' ';
  continue;
  }
     else if (c == (('U') & 0x1f))
  {
  type_char(015);
  vt(1);
  if ((ccount -= find_lasteol()) <= 0) goto prompt;
  mstack[0].p = t_qp.p;
  mstack[0].c = t_qp.c;
  lastc = ' ';
  continue;
  }
     else
  {
  if (!ccount)
      {
      if (c == '*')
   {
   type_char('*');
   type_char(c = gettty());
   i = getqspec(0, c);
   free_blist(qreg[i].f);
   qreg[i].f = qreg[0].f;
   if (qreg[i].f) qreg[i].f->b = (struct buffcell *) &qreg[i];
   qreg[i].z = qreg[0].z;
   qreg[0].f = (struct buffcell *) (qreg[0].z = 0);
   err = 0;
   goto restart;
   }
      else if ((c == '?') && (err))
   {
   type_char('?');
   for (aa.p = (*msp).p; aa.p->b->b != ((void *)0); aa.p = aa.p->b);
   for (aa.c = 0; (aa.p != (*msp).p) || (aa.c < (*msp).c); fwdc(&aa)) type_char(aa.p->ch[aa.c]);
   type_char('?');
   err = 0;
   goto restart;
   }
      else if ((c == 012) || (c == (('H') & 0x1f)))
   {
   pbuff->dot += lines( (c == 012) ? 1 : -1);
   window(5);
   goto restart;
   }
      else if ((c == (('W') & 0x1f)) && (win_data[7] != 0))
   {
   window(6);
   window(4);
   goto restart;
   }
      else if ((c == 033) && (ed_val & 32))
          {
          esp = &estack[0];
          c = gettty();
          if (c < ' ')
              {
              esp->val2 = 0;
              esp->val1 = c;
              }
          else
              {
              if (c == '[' || c == 'O') c = gettty();
              if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISupper))
                  {
                  esp->val2 = 1;
                  esp->val1 = c - 'A' + 1;
                  }
              else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISlower))
                  {
                  esp->val2 = 2;
                  esp->val1 = c - 'a' + 1;
                  }
              else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
                  {
                  esp->val2 = 3;
                  esp->val1 = c - '0';
                  while ((c = gettty()) != '~') esp->val1 *= 10, esp->val1 += c - '0';
                  }
              else goto restart;
              }
          esp->flag2 = esp->flag1 = 1;
          exec_qreg(&qreg[getqspec(0, 'a')]);
          window(4);
          goto reline;
          }
      else
   {
   make_buffer(&qreg[0]);
   mstack[0].p = qreg[0].f;
   mstack[0].c = 0;
   qreg[0].z = 0;
   err = 0;
   }
      }
  if (lastc == (('G') & 0x1f))
      {
      if (c == (('G') & 0x1f))
   {
   qreg[0].z = ccount;
   goto restart;
   }
      if ((c == '*') || (c == ' '))
   {
   backc(&mstack[0]);
   --ccount;
   crlf();
   retype_cmdstr(c);
   lastc = ' ';
   continue;
   }
      }
  }
     }
 else
     {
     if (!ccount)
  {
  if (!qreg[0].f)
      {
      qreg[0].f = get_bcell();
      qreg[0].f->b = (struct buffcell *) &qreg[0];
      }
  mstack[0].p = qreg[0].f;
  qreg[0].z = mstack[0].c = 0;
  }
     c = (eisw) ? getc(eisw) : gettty() ;
     if (eisw && (c == (-1)))
  {
  fclose(eisw);
  eisw = 0;
  lastc = ' ';
  continue;
  }
     else
  {
  if ((c == 012) && (lastc != 015) && !(ez_val & 1))
      {
      mstack[0].p->ch[mstack[0].c] = 015;
      ++ccount;
      fwdcx(&mstack[0]);
      }
  }
     }
     mstack[0].p->ch[mstack[0].c] = c;
     ++ccount;
     if (!eisw && !inp_noterm) type_char(c);
     fwdcx(&mstack[0]);
     if ((c == 033) && (lastc == 033)) break;
     if ((c == (('C') & 0x1f)) && (lastc == (('C') & 0x1f))) return(-1);
     lastc = c;
     }
    qreg[0].z = ccount;
    if (!eisw && !inp_noterm) crlf();
    return(0);
    }

canonical_original_code:
int read_cmdstr()
    {
    char c;
    int i;
    goto prompt;
  restart:
    if (!eisw && !inp_noterm) crlf();
  prompt:
    if (!eisw && !inp_noterm)
 {
 type_char('*');
 }
    ccount = 0;
    lastc = ' ';
reline:
    for (;;)
 {
 if (!eisw && !inp_noterm)
     {
     if ((c = gettty()) == 0177)
  {
  if (!ccount) goto restart;
  --ccount;
  backc(&mstack[0]);
  if (((c = mstack[0].p->ch[mstack[0].c]) < ' ') && (c != 033))
      {
      if (c == 012) vt(7);
      else if ((c == 015) || (c == 011))
   {
   i = find_lasteol();
   type_char(015);
   vt(1);
   if (i == ccount) type_char('*');
   for (; (t_qp.p != mstack[0].p) || (t_qp.c != mstack[0].c); fwdc(&t_qp))
       type_char(t_qp.p->ch[t_qp.c]);
   }
      else
   {
   vt(6);
   char_count -= 2;
   }
      }
  else
      {
      vt(5);
      char_count--;
      }
  lastc = ' ';
  continue;
  }
     else if (c == (('U') & 0x1f))
  {
  type_char(015);
  vt(1);
  if ((ccount -= find_lasteol()) <= 0) goto prompt;
  mstack[0].p = t_qp.p;
  mstack[0].c = t_qp.c;
  lastc = ' ';
  continue;
  }
     else
  {
  if (!ccount)
      {
      if (c == '*')
   {
   type_char('*');
   type_char(c = gettty());
   i = getqspec(0, c);
   free_blist(qreg[i].f);
   qreg[i].f = qreg[0].f;
   if (qreg[i].f) qreg[i].f->b = (struct buffcell *) &qreg[i];
   qreg[i].z = qreg[0].z;
   qreg[0].f = (struct buffcell *) (qreg[0].z = 0);
   err = 0;
   goto restart;
   }
      else if ((c == '?') && (err))
   {
   type_char('?');
   for (aa.p = (*msp).p; aa.p->b->b != ((void *)0); aa.p = aa.p->b);
   for (aa.c = 0; (aa.p != (*msp).p) || (aa.c < (*msp).c); fwdc(&aa)) type_char(aa.p->ch[aa.c]);
   type_char('?');
   err = 0;
   goto restart;
   }
      else if ((c == 012) || (c == (('H') & 0x1f)))
   {
   pbuff->dot += lines( (c == 012) ? 1 : -1);
   window(5);
   goto restart;
   }
      else if ((c == (('W') & 0x1f)) && (win_data[7] != 0))
   {
   window(6);
   window(4);
   goto restart;
   }
      else if ((c == 033) && (ed_val & 32))
          {
          esp = &estack[0];
          c = gettty();
          if (c < ' ')
              {
              esp->val2 = 0;
              esp->val1 = c;
              }
          else
              {
              if (c == '[' || c == 'O') c = gettty();
              if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISupper))
                  {
                  esp->val2 = 1;
                  esp->val1 = c - 'A' + 1;
                  }
              else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISlower))
                  {
                  esp->val2 = 2;
                  esp->val1 = c - 'a' + 1;
                  }
              else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
                  {
                  esp->val2 = 3;
                  esp->val1 = c - '0';
                  while ((c = gettty()) != '~') esp->val1 *= 10, esp->val1 += c - '0';
                  }
              else goto restart;
              }
          esp->flag2 = esp->flag1 = 1;
          exec_qreg(&qreg[getqspec(0, 'a')]);
          window(4);
          goto reline;
          }
      else
   {
   make_buffer(&qreg[0]);
   mstack[0].p = qreg[0].f;
   mstack[0].c = 0;
   qreg[0].z = 0;
   err = 0;
   }
      }
  if (lastc == (('G') & 0x1f))
      {
      if (c == (('G') & 0x1f))
   {
   qreg[0].z = ccount;
   goto restart;
   }
      if ((c == '*') || (c == ' '))
   {
   backc(&mstack[0]);
   --ccount;
   crlf();
   retype_cmdstr(c);
   lastc = ' ';
   continue;
   }
      }
  }
     }
 else
     {
     if (!ccount)
  {
  if (!qreg[0].f)
      {
      qreg[0].f = get_bcell();
      qreg[0].f->b = (struct buffcell *) &qreg[0];
      }
  mstack[0].p = qreg[0].f;
  qreg[0].z = mstack[0].c = 0;
  }
     c = (eisw) ? getc(eisw) : gettty() ;
     if (eisw && (c == (-1)))
  {
  fclose(eisw);
  eisw = 0;
  lastc = ' ';
  continue;
  }
     else
  {
  if ((c == 012) && (lastc != 015) && !(ez_val & 1))
      {
      mstack[0].p->ch[mstack[0].c] = 015;
      ++ccount;
      fwdcx(&mstack[0]);
      }
  }
     }
     mstack[0].p->ch[mstack[0].c] = c;
     ++ccount;
     if (!eisw && !inp_noterm) type_char(c);
     fwdcx(&mstack[0]);
     if ((c == 033) && (lastc == 033)) break;
     if ((c == (('C') & 0x1f)) && (lastc == (('C') & 0x1f))) return(-1);
     lastc = c;
     }
    qreg[0].z = ccount;
    if (!eisw && !inp_noterm) crlf();
    return(0);
    }

variable_types: c char

user_defined_types: struct buffcell { struct buffcell *f; struct buffcell *b; char ch[256]; }


decompiled_code:
void int_handler()
{
int v0; // eax

if ( exitflag <= 0 )
{
v0 = et_val;
if ( *(&et_val + 1) >= 0 )
{
exitflag = -2;
}
else
{
BYTE1(v0) = *(&et_val + 1) & 0x7F;
et_val = v0;
}
}
}

canonical_decompiled_code:
void func0()
{
int v0; // eax

if ( exitflag <= 0 )
{
v0 = et_val;
if ( *(&et_val + 1) >= 0 )
{
exitflag = -2;
}
else
{
BYTE1(v0) = *(&et_val + 1) & 0x7F;
et_val = v0;
}
}
}

original_code:
void int_handler()
    {
    if (exitflag <= 0)
 {
 if (et_val & 32768) et_val &= ~32768;
 else exitflag = -2;
 }
    }


decompiled_code:
void __fastcall hup_handler(__int64 a1)
{
if ( exitflag )
{
panic(a1);
exit(1);
}
exitflag = -3;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
if ( exitflag )
{
panic(a1);
exit(1);
}
exitflag = -3;
}

original_code:
void hup_handler()
    {
    if (!exitflag) exitflag = -3;
    else
 {
 panic();
 exit(1);
 }
    }


decompiled_code:
__int64 gettty_nowait()
{
unsigned int v0; // er12
__int64 result; // rax
unsigned int v2; // er13
int v3; // eax
int v4; // er12
int v5; // eax

if ( lf_sw )
{
lf_sw = 0;
result = 10LL;
}
else
{
if ( !inp_noterm )
{
v4 = ttyflags;
v5 = fileno(stdin);
fcntl(v5, 4, v4 | 0x800u);
}
do
v0 = getchar();
while ( !v0 );
if ( !inp_noterm )
{
v2 = ttyflags;
v3 = fileno(stdin);
fcntl(v3, 4, v2);
}
if ( v0 == 13 )
++lf_sw;
result = v0;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // er12
__int64 result; // rax
unsigned int v2; // er13
int v3; // eax
int v4; // er12
int v5; // eax

if ( lf_sw )
{
lf_sw = 0;
result = 10LL;
}
else
{
if ( !inp_noterm )
{
v4 = ttyflags;
v5 = fileno(stdin);
fcntl(v5, 4, v4 | 0x800u);
}
do
v0 = getchar();
while ( !v0 );
if ( !inp_noterm )
{
v2 = ttyflags;
v3 = fileno(stdin);
fcntl(v3, 4, v2);
}
if ( v0 == 13 )
++lf_sw;
result = v0;
}
return result;
}

original_code:
int gettty_nowait()
    {
    int c;
    if (lf_sw)
 {
 lf_sw = 0;
 return(012);
 }
    if (!inp_noterm) fcntl(fileno(stdin), 4, ttyflags | 04000);
    while (!(c = getchar()));
    if (!inp_noterm) fcntl(fileno(stdin), 4, ttyflags);
    if (c == 015) ++lf_sw;
    return(c);
    }

variable_types: c int


gettty

decompiled_code:
__int64 gettty()
{
int v0; // eax
__int64 result; // rax

if ( lf_sw )
{
lf_sw = 0;
result = 10LL;
}
else
{
++in_read;
do
v0 = getchar();
while ( !v0 );
in_read = 0;
if ( v0 == 13 )
{
++lf_sw;
result = 13LL;
}
else
{
if ( v0 == -1 )
longjmp(xxx, 42);
result = v0 & 0x7F;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
__int64 result; // rax

if ( lf_sw )
{
lf_sw = 0;
result = 10LL;
}
else
{
++in_read;
do
v0 = getchar();
while ( !v0 );
in_read = 0;
if ( v0 == 13 )
{
++lf_sw;
result = 13LL;
}
else
{
if ( v0 == -1 )
longjmp(xxx, 42);
result = v0 & 0x7F;
}
}
return result;
}

original_code:
char gettty()
    {
    int c;
    if (lf_sw)
 {
 lf_sw = 0;
 return(012);
 }
    ++in_read;
    while(!(c = getchar()));
    in_read = 0;
    if (c == 015) ++lf_sw;
    if (c == (-1)) longjmp(xxx, (42));
    return( (char) c & 0177);
    }

return_type: char


decompiled_code:
void stp_handler()
{
sigset_t v0; // [rsp+0h] [rbp-88h] BYREF

crlf();
window(1LL);
setup_tty(1);
_sysv_signal(20, 0LL);
sigemptyset(&v0);
sigprocmask(2, &v0, 0LL);
kill(0, 20);
_sysv_signal(20, stp_handler);
setup_tty(3);
*(_DWORD *)(pbuff + 32LL) = 0;
if ( !win_data[7] )
{
if ( !exitflag )
return;
LABEL_5:
retype_cmdstr(42LL);
return;
}
window(3LL);
window(6LL);
window(4LL);
if ( exitflag )
goto LABEL_5;
}

canonical_decompiled_code:
void func8()
{
sigset_t v0; // [rsp+0h] [rbp-88h] BYREF

func7();
window(1LL);
func2(1);
_sysv_signal(20, 0LL);
sigemptyset(&v0);
sigprocmask(2, &v0, 0LL);
kill(0, 20);
_sysv_signal(20, stp_handler);
func2(3);
*(_DWORD *)(pbuff + 32LL) = 0;
if ( !win_data[7] )
{
if ( !exitflag )
return;
LABEL_5:
retype_cmdstr(42LL);
return;
}
window(3LL);
window(6LL);
window(4LL);
if ( exitflag )
goto LABEL_5;
}

original_code:
void stp_handler()
    {
    crlf();
    window(1);
    setup_tty(1);
    signal(20, ((__sighandler_t) 0));
    {
    sigset_t nomask;
    sigemptyset(&nomask);
    sigprocmask(2, &nomask, ((void *)0));
    }
    kill(0, 20);
    signal(20, stp_handler);
    setup_tty(3);
    pbuff->buff_mod = 0;
    if (win_data[7])
 {
 window(3);
 window(6);
 window(4);
 }
    if (exitflag) retype_cmdstr('*');
    }

canonical_original_code:
void stp_handler()
    {
    crlf();
    window(1);
    setup_tty(1);
    signal(20, ((void (*)(int)) 0));
    {
    struct __sigset_t nomask;
    sigemptyset(&nomask);
    sigprocmask(2, &nomask, ((void *)0));
    }
    kill(0, 20);
    signal(20, stp_handler);
    setup_tty(3);
    pbuff->buff_mod = 0;
    if (win_data[7])
 {
 window(3);
 window(6);
 window(4);
 }
    if (exitflag) retype_cmdstr('*');
    }

variable_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
_QWORD *get_bcell()
{
_QWORD *v0; // r8
__int64 v1; // rax
_QWORD *result; // rax
_QWORD *v3; // rax
_QWORD *v4; // rax

v0 = (_QWORD *)freebuff;
if ( !freebuff )
{
v3 = malloc(0xFFF8uLL);
v0 = v3;
if ( !v3 )
longjmp(xxx, 17);
v4 = v3 + 34;
do
{
*(v4 - 34) = v4;
v4 += 34;
}
while ( v4 != v0 + 8160 );
v0[8126] = 0LL;
}
v1 = *v0;
v0[1] = 0LL;
freebuff = v1;
result = v0;
*v0 = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r8
__int64 v1; // rax
_QWORD *result; // rax
_QWORD *v3; // rax
_QWORD *v4; // rax

v0 = (_QWORD *)freebuff;
if ( !freebuff )
{
v3 = malloc(0xFFF8uLL);
v0 = v3;
if ( !v3 )
longjmp(xxx, 17);
v4 = v3 + 34;
do
{
*(v4 - 34) = v4;
v4 += 34;
}
while ( v4 != v0 + 8160 );
v0[8126] = 0LL;
}
v1 = *v0;
v0[1] = 0LL;
freebuff = v1;
result = v0;
*v0 = 0LL;
return result;
}

original_code:
struct buffcell *get_bcell()
    {
    void *malloc(size_t);
    struct buffcell *p;
    int i;
    if (freebuff == ((void *)0))
 {
 p = (struct buffcell *) malloc((0x10000 - 8));
 if (!p) longjmp(xxx, (17));
 else
     {
     freebuff = p;
     for (i = 0; i < ((0x10000 - 8)/sizeof(struct buffcell)) - 1; i++)
  (p+i)->f = p+i+1;
     (p+i)->f = ((void *)0);
     }
 }
    p = freebuff;
    freebuff = freebuff->f;
    p->f = p->b = ((void *)0);
    return(p);
    }

canonical_original_code:
struct buffcell *get_bcell()
    {
    void *malloc(unsigned long);
    struct buffcell *p;
    int i;
    if (freebuff == ((void *)0))
 {
 p = (struct buffcell *) malloc((0x10000 - 8));
 if (!p) longjmp(xxx, (17));
 else
     {
     freebuff = p;
     for (i = 0; i < ((0x10000 - 8)/sizeof(struct buffcell)) - 1; i++)
  (p+i)->f = p+i+1;
     (p+i)->f = ((void *)0);
     }
 }
    p = freebuff;
    freebuff = freebuff->f;
    p->f = p->b = ((void *)0);
    return(p);
    }

variable_types:
malloc
void *(unsigned long)

variable_types: struct buffcell { struct buffcell *f; struct buffcell *b; char ch[256]; } *

variable_types: i int


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

result = (_QWORD *)freedcell;
if ( freedcell )
{
freedcell = *freedcell;
}
else
{
result = get_bcell();
freedcell = 0LL;
result[8] = 0LL;
result[16] = 0LL;
}
*result = 0LL;
return result;
}

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

result = (_QWORD *)freedcell;
if ( freedcell )
{
freedcell = *freedcell;
}
else
{
result = func0();
freedcell = 0LL;
result[8] = 0LL;
result[16] = 0LL;
}
*result = 0LL;
return result;
}

original_code:
struct qp *get_dcell()
    {
    struct qp *t;
    int i;
    if (freedcell == ((void *)0))
 {
 t = freedcell = (struct qp *) get_bcell();
 for (i = 0; i < (sizeof(struct buffcell)/sizeof(struct qp)) - 1; i++)
     {
     (t+i)->f = t+i+1;
     (t+i)->f = ((void *)0);
     }
 }
    t = freedcell;
    freedcell = (struct qp *) freedcell->f;
    t->f = ((void *)0);
    return(t);
    }

variable_types: struct qp { struct qp *f; struct buffcell { struct buffcell *f; struct buffcell *b; char ch[256]; } *p; unsigned long c; unsigned long z; unsigned long dot; int flag; struct is { struct is *f; struct is *b; struct buffcell *p; unsigned long c; unsigned long dot; int count; int dflag; } *il; int *condsp; } *

user_defined_types: struct qp { struct qp *f; struct buffcell *p; unsigned long c; unsigned long z; unsigned long dot; int flag; struct is *il; int *condsp; }


main

repo: matthieutdo/PiBoat

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int v6; // er12
int v7; // [rsp+Ch] [rbp-1Ch]

v3 = init_socket_client(4000LL, argv, envp);
v4 = v3;
if ( v3 >= 0 )
{
while ( 1 )
{
while ( 1 )
{
puts("Piboat menu");
putchar(10);
puts("1 - Set motors speed");
puts("2 - Set pods position");
puts("3 - Set cam position");
putchar(10);
puts("0 - exit");
putchar(10);
printf("Your choice: ");
__isoc99_scanf();
v6 = v7;
if ( v7 != 2 )
break;
set_pods_pos(v4);
v6 = 2;
LABEL_5:
if ( !v6 )
{
close_sock(v4);
return v6;
}
}
if ( v7 != 3 )
{
if ( v7 == 1 )
{
set_motors_speed(v4);
v6 = 1;
}
goto LABEL_5;
}
set_cam_pos(v4);
}
}
switch ( v3 )
{
case -2:
v6 = -1;
puts("Cannot connect to PiBoat (socket not created)");
break;
case -1:
v6 = -1;
puts("Cannot connect to PiBoat (no host)");
break;
case -4:
v6 = -1;
puts("Cannot connect to PiBoat (bind)");
break;
default:
v6 = -1;
if ( v3 == -3 )
puts("Cannot connect to PiBoat (connection)");
else
puts("Cannot connect to PiBoat (unknown)");
break;
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int v6; // er12
int v7; // [rsp+Ch] [rbp-1Ch]

v3 = func12(4000LL, argv, envp);
v4 = v3;
if ( v3 >= 0 )
{
while ( 1 )
{
while ( 1 )
{
puts("Piboat menu");
putchar(10);
puts("1 - Set motors speed");
puts("2 - Set pods position");
puts("3 - Set cam position");
putchar(10);
puts("0 - exit");
putchar(10);
printf("Your choice: ");
__isoc99_scanf();
v6 = v7;
if ( v7 != 2 )
break;
func8(v4);
v6 = 2;
LABEL_5:
if ( !v6 )
{
func13(v4);
return v6;
}
}
if ( v7 != 3 )
{
if ( v7 == 1 )
{
func7(v4);
v6 = 1;
}
goto LABEL_5;
}
func9(v4);
}
}
switch ( v3 )
{
case -2:
v6 = -1;
puts("Cannot connect to PiBoat (socket not created)");
break;
case -1:
v6 = -1;
puts("Cannot connect to PiBoat (no host)");
break;
case -4:
v6 = -1;
puts("Cannot connect to PiBoat (bind)");
break;
default:
v6 = -1;
if ( v3 == -3 )
puts("Cannot connect to PiBoat (connection)");
else
puts("Cannot connect to PiBoat (unknown)");
break;
}
return v6;
}

original_code:
int main(int argc, char *argv[])
{
 socket_t sock;
 int choice;
 sock = init_socket_client(4000);
 if (sock < 0) {
  switch (sock) {
  case -1:
   printf("Cannot connect to PiBoat (no host)\n");
   return -1;
  case -2:
   printf("Cannot connect to PiBoat (socket not created)\n");
   return -1;
  case -3:
   printf("Cannot connect to PiBoat (connection)\n");
   return -1;
  case -4:
   printf("Cannot connect to PiBoat (bind)\n");
   return -1;
  default:
   printf("Cannot connect to PiBoat (unknown)\n");
   return -1;
  }
 }
 do {
  printf("Piboat menu\n");
  printf("\n");
  printf("1 - Set motors speed\n");
  printf("2 - Set pods position\n");
  printf("3 - Set cam position\n");
  printf("\n");
  printf("0 - exit\n");
  printf("\n");
  printf("Your choice: ");
  scanf("%i", &choice);
  switch (choice) {
  case 1:
   set_motors_speed(sock);
   break;
  case 2:
   set_pods_pos(sock);
   break;
  case 3:
   set_cam_pos(sock);
   break;
  case 0:
   break;
  }
 } while (choice != 0);
 close_sock(sock);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int sock;
 int choice;
 sock = init_socket_client(4000);
 if (sock < 0) {
  switch (sock) {
  case -1:
   printf("Cannot connect to PiBoat (no host)\n");
   return -1;
  case -2:
   printf("Cannot connect to PiBoat (socket not created)\n");
   return -1;
  case -3:
   printf("Cannot connect to PiBoat (connection)\n");
   return -1;
  case -4:
   printf("Cannot connect to PiBoat (bind)\n");
   return -1;
  default:
   printf("Cannot connect to PiBoat (unknown)\n");
   return -1;
  }
 }
 do {
  printf("Piboat menu\n");
  printf("\n");
  printf("1 - Set motors speed\n");
  printf("2 - Set pods position\n");
  printf("3 - Set cam position\n");
  printf("\n");
  printf("0 - exit\n");
  printf("\n");
  printf("Your choice: ");
  scanf("%i", &choice);
  switch (choice) {
  case 1:
   set_motors_speed(sock);
   break;
  case 2:
   set_pods_pos(sock);
   break;
  case 3:
   set_cam_pos(sock);
   break;
  case 0:
   break;
  }
 } while (choice != 0);
 close_sock(sock);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sock int

variable_types: choice int


decompiled_code:
int __fastcall set_motors_speed(int fd)
{
int v1; // ebx
int *v2; // rax
int *v3; // r12
ssize_t v4; // rax
char *v5; // rax
unsigned int v7; // [rsp+8h] [rbp-2020h]
unsigned int v8; // [rsp+Ch] [rbp-201Ch]
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

while ( 1 )
{
puts("Enter 2 integers between -100 and 100 (0 for stop motors)");
__isoc99_scanf();
if ( v7 + 100 <= 0xC8 && v8 + 100 <= 0xC8 )
break;
puts("Invalid entry");
}
v1 = snprintf(s, 0x2000uLL, "ms %i %i", v7, v8);
printf("send command: %s\n", s);
v2 = __errno_location();
++v1;
*v2 = 0;
v3 = v2;
v4 = send(fd, s, v1, 0);
if ( v4 < v1 )
{
v5 = strerror(*v3);
LODWORD(v4) = printf("send error: %s\n", v5);
}
return v4;
}

canonical_decompiled_code:
int __fastcall func7(int fd)
{
int v1; // ebx
int *v2; // rax
int *v3; // r12
ssize_t v4; // rax
char *v5; // rax
unsigned int v7; // [rsp+8h] [rbp-2020h]
unsigned int v8; // [rsp+Ch] [rbp-201Ch]
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

while ( 1 )
{
puts("Enter 2 integers between -100 and 100 (0 for stop motors)");
__isoc99_scanf();
if ( v7 + 100 <= 0xC8 && v8 + 100 <= 0xC8 )
break;
puts("Invalid entry");
}
v1 = snprintf(s, 0x2000uLL, "ms %i %i", v7, v8);
printf("send command: %s\n", s);
v2 = __errno_location();
++v1;
*v2 = 0;
v3 = v2;
v4 = send(fd, s, v1, 0);
if ( v4 < v1 )
{
v5 = strerror(*v3);
LODWORD(v4) = printf("send error: %s\n", v5);
}
return v4;
}

original_code:
static void set_motors_speed(socket_t sock)
{
 int speed1, speed2;
 char cmd[8192];
 int redo;
 int len;
 do {
  redo = 0;
  printf("Enter 2 integers between -100 and 100 (0 for stop motors)\n");
  scanf("%i %i", &speed1, &speed2);
  if (speed1 < -100 || speed1 > 100
      || speed2 < -100 || speed2 > 100) {
   printf("Invalid entry\n");
   redo = 1;
  }
 } while (redo);
 len = snprintf(cmd, 8192, "ms %i %i", speed1, speed2);
 printf("send command: %s\n", cmd);
 (*__errno_location ()) = 0;
 if (send(sock, cmd, len + 1, 0) < len + 1) {
  printf("send error: %s\n", strerror((*__errno_location ())));
 }
}

canonical_original_code:
static void set_motors_speed(int sock)
{
 int speed1; int speed2;
 char cmd[8192];
 int redo;
 int len;
 do {
  redo = 0;
  printf("Enter 2 integers between -100 and 100 (0 for stop motors)\n");
  scanf("%i %i", &speed1, &speed2);
  if (speed1 < -100 || speed1 > 100
      || speed2 < -100 || speed2 > 100) {
   printf("Invalid entry\n");
   redo = 1;
  }
 } while (redo);
 len = snprintf(cmd, 8192, "ms %i %i", speed1, speed2);
 printf("send command: %s\n", cmd);
 (*__errno_location ()) = 0;
 if (send(sock, cmd, len + 1, 0) < len + 1) {
  printf("send error: %s\n", strerror((*__errno_location ())));
 }
}

variable_types:
cmd
char [8192]

variable_types: redo int

variable_types: len int


decompiled_code:
int __fastcall set_pods_pos(int fd)
{
int v1; // ebx
int *v2; // rax
int *v3; // r12
ssize_t v4; // rax
char *v5; // rax
unsigned int v7; // [rsp+8h] [rbp-2020h]
unsigned int v8; // [rsp+Ch] [rbp-201Ch]
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

while ( 1 )
{
while ( 1 )
{
puts("Enter right and left pods new position (two integers between 0 and 100)");
__isoc99_scanf();
if ( v7 <= 0x64 )
break;
puts("Invalid right pod position entry");
if ( v8 > 0x64 )
goto LABEL_3;
}
if ( v8 <= 0x64 )
break;
LABEL_3:
puts("Invalid left pod position entry");
}
v1 = snprintf(s, 0x2000uLL, "ds %i %i", v7 + 40, v8 + 40);
printf("send command: %s\n", s);
v2 = __errno_location();
++v1;
*v2 = 0;
v3 = v2;
v4 = send(fd, s, v1, 0);
if ( v4 < v1 )
{
v5 = strerror(*v3);
LODWORD(v4) = printf("send error: %s\n", v5);
}
return v4;
}

canonical_decompiled_code:
int __fastcall func8(int fd)
{
int v1; // ebx
int *v2; // rax
int *v3; // r12
ssize_t v4; // rax
char *v5; // rax
unsigned int v7; // [rsp+8h] [rbp-2020h]
unsigned int v8; // [rsp+Ch] [rbp-201Ch]
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

while ( 1 )
{
while ( 1 )
{
puts("Enter right and left pods new position (two integers between 0 and 100)");
__isoc99_scanf();
if ( v7 <= 0x64 )
break;
puts("Invalid right pod position entry");
if ( v8 > 0x64 )
goto LABEL_3;
}
if ( v8 <= 0x64 )
break;
LABEL_3:
puts("Invalid left pod position entry");
}
v1 = snprintf(s, 0x2000uLL, "ds %i %i", v7 + 40, v8 + 40);
printf("send command: %s\n", s);
v2 = __errno_location();
++v1;
*v2 = 0;
v3 = v2;
v4 = send(fd, s, v1, 0);
if ( v4 < v1 )
{
v5 = strerror(*v3);
LODWORD(v4) = printf("send error: %s\n", v5);
}
return v4;
}

original_code:
static void set_pods_pos(socket_t sock)
{
 int pod_pos_right, pod_pos_left;
 char cmd[8192];
 int redo;
 int len;
 do {
  redo = 0;
  printf("Enter right and left pods new position (two integers between 0 and 100)\n");
  scanf("%i %i", &pod_pos_right, &pod_pos_left);
  if (pod_pos_right < 0 || pod_pos_right > 100) {
   printf("Invalid right pod position entry\n");
   redo = 1;
  }
  if (pod_pos_left < 0 || pod_pos_left > 100) {
   printf("Invalid left pod position entry\n");
   redo = 1;
  }
 } while (redo);
 len = snprintf(cmd, 8192, "ds %i %i", pod_pos_right + 40,
         pod_pos_left + 40);
 printf("send command: %s\n", cmd);
 (*__errno_location ()) = 0;
 if (send(sock, cmd, len + 1, 0) < len + 1) {
  printf("send error: %s\n", strerror((*__errno_location ())));
 }
}

canonical_original_code:
static void set_pods_pos(int sock)
{
 int pod_pos_right; int pod_pos_left;
 char cmd[8192];
 int redo;
 int len;
 do {
  redo = 0;
  printf("Enter right and left pods new position (two integers between 0 and 100)\n");
  scanf("%i %i", &pod_pos_right, &pod_pos_left);
  if (pod_pos_right < 0 || pod_pos_right > 100) {
   printf("Invalid right pod position entry\n");
   redo = 1;
  }
  if (pod_pos_left < 0 || pod_pos_left > 100) {
   printf("Invalid left pod position entry\n");
   redo = 1;
  }
 } while (redo);
 len = snprintf(cmd, 8192, "ds %i %i", pod_pos_right + 40,
         pod_pos_left + 40);
 printf("send command: %s\n", cmd);
 (*__errno_location ()) = 0;
 if (send(sock, cmd, len + 1, 0) < len + 1) {
  printf("send error: %s\n", strerror((*__errno_location ())));
 }
}


decompiled_code:
int __fastcall set_cam_pos(int fd)
{
int v1; // ebx
int *v2; // rax
int *v3; // r12
ssize_t v4; // rax
char *v5; // rax
unsigned int v7; // [rsp+8h] [rbp-2020h]
unsigned int v8; // [rsp+Ch] [rbp-201Ch]
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

while ( 1 )
{
while ( 1 )
{
puts("Enter two integers (X axis and Y axis)");
__isoc99_scanf();
if ( v7 <= 0xAA )
break;
puts("Invalid X entry");
if ( v8 - 60 > 0x6E )
goto LABEL_3;
}
if ( v8 - 60 <= 0x6E )
break;
LABEL_3:
puts("Invalid Y entry");
}
v1 = snprintf(s, 0x2000uLL, "c %i %i", v7, v8);
printf("send command: %s\n", s);
v2 = __errno_location();
++v1;
*v2 = 0;
v3 = v2;
v4 = send(fd, s, v1, 0);
if ( v4 < v1 )
{
v5 = strerror(*v3);
LODWORD(v4) = printf("send error: %s\n", v5);
}
return v4;
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
int v1; // ebx
int *v2; // rax
int *v3; // r12
ssize_t v4; // rax
char *v5; // rax
unsigned int v7; // [rsp+8h] [rbp-2020h]
unsigned int v8; // [rsp+Ch] [rbp-201Ch]
char s[8216]; // [rsp+10h] [rbp-2018h] BYREF

while ( 1 )
{
while ( 1 )
{
puts("Enter two integers (X axis and Y axis)");
__isoc99_scanf();
if ( v7 <= 0xAA )
break;
puts("Invalid X entry");
if ( v8 - 60 > 0x6E )
goto LABEL_3;
}
if ( v8 - 60 <= 0x6E )
break;
LABEL_3:
puts("Invalid Y entry");
}
v1 = snprintf(s, 0x2000uLL, "c %i %i", v7, v8);
printf("send command: %s\n", s);
v2 = __errno_location();
++v1;
*v2 = 0;
v3 = v2;
v4 = send(fd, s, v1, 0);
if ( v4 < v1 )
{
v5 = strerror(*v3);
LODWORD(v4) = printf("send error: %s\n", v5);
}
return v4;
}

original_code:
static void set_cam_pos(socket_t sock)
{
 char cmd[8192];
 int cam_pos_x;
 int cam_pos_y;
 int redo;
 int len;
 do {
  redo = 0;
  printf("Enter two integers (X axis and Y axis)\n");
  scanf("%i %i", &cam_pos_x, &cam_pos_y);
  if (cam_pos_x < 0 || cam_pos_x > 170) {
   printf("Invalid X entry\n");
   redo = 1;
  }
  if (cam_pos_y < 60 || cam_pos_y > 170) {
   printf("Invalid Y entry\n");
   redo = 1;
  }
 } while (redo);
 len = snprintf(cmd, 8192, "c %i %i", cam_pos_x, cam_pos_y);
 printf("send command: %s\n", cmd);
 (*__errno_location ()) = 0;
 if (send(sock, cmd, len + 1, 0) < len + 1) {
  printf("send error: %s\n", strerror((*__errno_location ())));
 }
}

canonical_original_code:
static void set_cam_pos(int sock)
{
 char cmd[8192];
 int cam_pos_x;
 int cam_pos_y;
 int redo;
 int len;
 do {
  redo = 0;
  printf("Enter two integers (X axis and Y axis)\n");
  scanf("%i %i", &cam_pos_x, &cam_pos_y);
  if (cam_pos_x < 0 || cam_pos_x > 170) {
   printf("Invalid X entry\n");
   redo = 1;
  }
  if (cam_pos_y < 60 || cam_pos_y > 170) {
   printf("Invalid Y entry\n");
   redo = 1;
  }
 } while (redo);
 len = snprintf(cmd, 8192, "c %i %i", cam_pos_x, cam_pos_y);
 printf("send command: %s\n", cmd);
 (*__errno_location ()) = 0;
 if (send(sock, cmd, len + 1, 0) < len + 1) {
  printf("send error: %s\n", strerror((*__errno_location ())));
 }
}


decompiled_code:
__int64 __fastcall init_socket_serv(__int16 a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
return (unsigned int)-2;
v3 = v2;
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = 0;
*(_WORD *)v6.sa_data = _bswap_16(a1);
if ( bind(v3, &v6, v4) < 0 )
return (unsigned int)-4;
listen(v3, a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int16 a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
return (unsigned int)-2;
v3 = v2;
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = 0;
*(_WORD *)v6.sa_data = func10(a1);
if ( bind(v3, &v6, v4) < 0 )
return (unsigned int)-4;
listen(v3, a2);
return v3;
}

original_code:
socket_t init_socket_serv(int port, int max_wait)
{
 socket_t sock;
 struct sockaddr_in serv_addr;
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
  return -2;
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 serv_addr.sin_port = htons(port);
 if (bind(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
  return -4;
 listen(sock, max_wait);
 return sock;
}

canonical_original_code:
int init_socket_serv(int port, int max_wait)
{
 int sock;
 struct sockaddr_in serv_addr;
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
  return -2;
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 serv_addr.sin_port = htons(port);
 if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
  return -4;
 listen(sock, max_wait);
 return sock;
}

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall init_socket_client(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
struct hostent *v3; // rax
socklen_t v4; // edx
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
return (unsigned int)-2;
v2 = v1;
v3 = gethostbyname("piboat");
if ( !v3 )
return (unsigned int)-1;
v6[0].sa_family = 2;
memcpy(&v6[0].sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)v6[0].sa_data = _bswap_16(a1);
if ( connect(v2, v6, v4) < 0 )
v2 = -3;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
struct hostent *v3; // rax
socklen_t v4; // edx
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
return (unsigned int)-2;
v2 = v1;
v3 = gethostbyname("piboat");
if ( !v3 )
return (unsigned int)-1;
v6[0].sa_family = 2;
memcpy(&v6[0].sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)v6[0].sa_data = func10(a1);
if ( connect(v2, v6, v4) < 0 )
v2 = -3;
return v2;
}

original_code:
socket_t init_socket_client(int port)
{
 struct hostent *server;
 int res;
 socket_t sock;
 struct sockaddr_in serv_addr;
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
  return (socket_t)-2;
 if ((server = gethostbyname("piboat")) == ((void *)0))
  return (socket_t)-1;
 serv_addr.sin_family = 2;
 memcpy(&serv_addr.sin_addr, server->h_addr_list[0], server->h_length);
 serv_addr.sin_port = htons(port);
 if ((res=connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr))) < 0){
  return (socket_t)-3;
 }
 return sock;
}

canonical_original_code:
int init_socket_client(int port)
{
 struct hostent *server;
 int res;
 int sock;
 struct sockaddr_in serv_addr;
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
  return (socket_t)-2;
 if ((server = gethostbyname("piboat")) == ((void *)0))
  return (socket_t)-1;
 serv_addr.sin_family = 2;
 memcpy(&serv_addr.sin_addr, server->h_addr_list[0], server->h_length);
 serv_addr.sin_port = htons(port);
 if ((res=connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0){
  return (socket_t)-3;
 }
 return sock;
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: res int


decompiled_code:
// attributes: thunk
int close_sock(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func13(int fd)
{
return close(fd);
}

original_code:
void close_sock(socket_t sock)
{
 close((int)sock);
}

canonical_original_code:
void close_sock(int sock)
{
 close((int)sock);
}


commentExists

repo: mattsfrey/mipsassembler

decompiled_code:
_BOOL8 __fastcall commentExists(const char *a1)
{
return strchr(a1, 35) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
return strchr(a1, 35) != 0LL;
}

original_code:
int commentExists(const char *line)
{
    int ret = 0;
    if (strchr(line, '#'))
    {
        ret = 1;
    }
    return ret;
}

canonical_original_code:
int commentExists(char *line)
{
    int ret = 0;
    if (strchr(line, '#'))
    {
        ret = 1;
    }
    return ret;
}

variable_types:
line
char *

variable_types: ret int


isBlank

decompiled_code:
__int64 __fastcall isBlank(const char *a1)
{
const char *v1; // rcx
char v2; // al

v1 = &a1[strlen(a1)];
while ( a1 != v1 )
{
v2 = *a1++;
if ( (unsigned __int8)(v2 - 9) > 1u && v2 != 32 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
const char *v1; // rcx
char v2; // al

v1 = &a1[strlen(a1)];
while ( a1 != v1 )
{
v2 = *a1++;
if ( (unsigned __int8)(v2 - 9) > 1u && v2 != 32 )
return 0LL;
}
return 1LL;
}

original_code:
int isBlank(const char *line)
{
    int i = 0;
    while (i < strlen(line))
    {
        if (line[i] != ' ' && line[i] != '\n' && line[i] != '\t')
        {
            return 0;
        }
        i++;
    }
    return 1;
}

canonical_original_code:
int isBlank(char *line)
{
    int i = 0;
    while (i < strlen(line))
    {
        if (line[i] != ' ' && line[i] != '\n' && line[i] != '\t')
        {
            return 0;
        }
        i++;
    }
    return 1;
}


isComment

decompiled_code:
__int64 __fastcall isComment(const char *a1)
{
const char *v1; // rdx
char v2; // al

v1 = &a1[strlen(a1)];
while ( 1 )
{
if ( a1 == v1 )
return 0LL;
v2 = *a1;
if ( *a1 == 35 )
break;
++a1;
if ( v2 != 9 && v2 != 32 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
const char *v1; // rdx
char v2; // al

v1 = &a1[strlen(a1)];
while ( 1 )
{
if ( a1 == v1 )
return 0LL;
v2 = *a1;
if ( *a1 == 35 )
break;
++a1;
if ( v2 != 9 && v2 != 32 )
return 0LL;
}
return 1LL;
}

original_code:
int isComment(const char *line)
{
    int i = 0;
    while(i < strlen(line))
    {
        if (line[i] != '#')
        {
            if (line[i] != '\t' && line[i] != ' ')
            {
                return 0;
            }
        }
        else
        {
            return 1;
        }
        i++;
    }
    return 0;
}

canonical_original_code:
int isComment(char *line)
{
    int i = 0;
    while(i < strlen(line))
    {
        if (line[i] != '#')
        {
            if (line[i] != '\t' && line[i] != ' ')
            {
                return 0;
            }
        }
        else
        {
            return 1;
        }
        i++;
    }
    return 0;
}


stripComment

decompiled_code:
__int64 __fastcall stripComment(const char *a1)
{
__int64 result; // rax

result = (unsigned int)strlen(a1) - 1;
if ( (int)result >= 0 )
{
result = (int)result;
do
{
if ( a1[result] == 35 )
a1[result] = 0;
--result;
}
while ( (int)result >= 0 );
}
return result;
}

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

result = (unsigned int)strlen(a1) - 1;
if ( (int)result >= 0 )
{
result = (int)result;
do
{
if ( a1[result] == 35 )
a1[result] = 0;
--result;
}
while ( (int)result >= 0 );
}
return result;
}

original_code:
void stripComment(char *line)
{
    int i;
    i = strlen(line)-1;
    while (i >= 0)
    {
        if (line[i] == '#')
        {
            line[i] = '\0';
        }
        i--;
    }
}


trimWhiteSpace

decompiled_code:
char *__fastcall trimWhiteSpace(char *s)
{
char v2; // bl
char *v3; // rbx

while ( 1 )
{
v2 = *s;
if ( !isspace(*s) )
break;
++s;
}
if ( v2 )
{
v3 = &s[strlen(s) - 1];
if ( s < v3 )
{
do
{
if ( !isspace(*v3) )
break;
--v3;
}
while ( s != v3 );
}
v3[1] = 0;
}
return s;
}

canonical_decompiled_code:
char *__fastcall func4(char *s)
{
char v2; // bl
char *v3; // rbx

while ( 1 )
{
v2 = *s;
if ( !isspace(*s) )
break;
++s;
}
if ( v2 )
{
v3 = &s[strlen(s) - 1];
if ( s < v3 )
{
do
{
if ( !isspace(*v3) )
break;
--v3;
}
while ( s != v3 );
}
v3[1] = 0;
}
return s;
}

original_code:
char *trimWhiteSpace(char *str)
{
    char *end;
    while(isspace(*str))
    {
        str++;
    }
    if(*str == 0)
    {
        return str;
    }
    end = str + strlen(str) - 1;
    while(end > str && isspace(*end))
    {
        end--;
    }
    *(end+1) = 0;
    return str;
}

variable_types:
str
char *

variable_types:
end
char *

return_type: char *


regToBin

decompiled_code:
char *__fastcall regToBin(char *dest)
{
int v1; // ebp
size_t v2; // rbx
char v3; // al
__int64 v4; // rdx
int v5; // eax
char *v6; // rcx
char src[6]; // [rsp+2h] [rbp-26h] BYREF
char nptr[32]; // [rsp+8h] [rbp-20h] BYREF

v1 = 0;
v2 = 0LL;
strcpy(src, "00000");
do
{
v3 = dest[v2];
if ( v3 != 36 )
{
v4 = v1++;
nptr[v4] = v3;
}
++v2;
}
while ( strlen(dest) >= v2 );
v5 = atoi(nptr);
if ( v5 > 0 )
{
v6 = &src[4];
do
{
*v6-- = (v5 & 1) + 48;
v5 >>= 1;
}
while ( v5 );
}
return strcpy(dest, src);
}

canonical_decompiled_code:
char *__fastcall func5(char *dest)
{
int v1; // ebp
size_t v2; // rbx
char v3; // al
__int64 v4; // rdx
int v5; // eax
char *v6; // rcx
char src[6]; // [rsp+2h] [rbp-26h] BYREF
char nptr[32]; // [rsp+8h] [rbp-20h] BYREF

v1 = 0;
v2 = 0LL;
strcpy(src, "00000");
do
{
v3 = dest[v2];
if ( v3 != 36 )
{
v4 = v1++;
nptr[v4] = v3;
}
++v2;
}
while ( strlen(dest) >= v2 );
v5 = atoi(nptr);
if ( v5 > 0 )
{
v6 = &src[4];
do
{
*v6-- = (v5 & 1) + 48;
v5 >>= 1;
}
while ( v5 );
}
return strcpy(dest, src);
}

original_code:
char* regToBin(char *reg)
{
    int dec = 0;
    char bin[6] = "00000";
    char integer[8];
    int i, j=0;
    for(i=0; i<=strlen(reg); i++)
    {
        if (reg[i] != '$')
        {
            integer[j] = reg[i];
            j++;
        }
    }
    dec = atoi(integer);
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    strcpy(reg, bin);
    return reg;
}

canonical_original_code:
char *regToBin(char *reg)
{
    int dec = 0;
    char bin[6] = "00000";
    char integer[8];
    int i; int j = 0;
    for(i=0; i<=strlen(reg); i++)
    {
        if (reg[i] != '$')
        {
            integer[j] = reg[i];
            j++;
        }
    }
    dec = atoi(integer);
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    strcpy(reg, bin);
    return reg;
}

variable_types:
reg
char *

variable_types: dec int

variable_types:
bin
char [6]

variable_types:
integer
char [8]

variable_types: i int

variable_types: j int


immToBin

original_code:
char* immToBin(char *imm)
{
    int dec = 0;
    int negflag = 0;
    char bin[17] = "0000000000000000";
    int i;
    int carry = 0;
    dec = atoi(imm);
    if (dec < 0)
    {
        dec = -dec;
        negflag = 1;
    }
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    if (negflag)
    {
        for (i = 0; i<strlen(bin); i++)
        {
            if (bin[i] == '1')
            {
                bin[i] = '0';
            }
            else if (bin[i] == '0')
            {
                bin[i] = '1';
            }
        }
        i = strlen(bin)-1;
        carry = 1;
        while (i > 0)
        {
            if (carry == 1)
            {
                if (bin[i] == '0')
                {
                    bin[i] = '1';
                    carry = 0;
                }
                else
                {
                    bin[i] = '0';
                    carry = 1;
                }
            }
            i--;
        }
    }
    strcpy(imm, bin);
    return imm;
}

canonical_original_code:
char *immToBin(char *imm)
{
    int dec = 0;
    int negflag = 0;
    char bin[17] = "0000000000000000";
    int i;
    int carry = 0;
    dec = atoi(imm);
    if (dec < 0)
    {
        dec = -dec;
        negflag = 1;
    }
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    if (negflag)
    {
        for (i = 0; i<strlen(bin); i++)
        {
            if (bin[i] == '1')
            {
                bin[i] = '0';
            }
            else if (bin[i] == '0')
            {
                bin[i] = '1';
            }
        }
        i = strlen(bin)-1;
        carry = 1;
        while (i > 0)
        {
            if (carry == 1)
            {
                if (bin[i] == '0')
                {
                    bin[i] = '1';
                    carry = 0;
                }
                else
                {
                    bin[i] = '0';
                    carry = 1;
                }
            }
            i--;
        }
    }
    strcpy(imm, bin);
    return imm;
}

variable_types:
imm
char *

variable_types: negflag int

variable_types:
bin
char [17]

variable_types: carry int


original_code:
char* numTo32Bin(char *num)
{
    int dec = 0;
    int negflag = 0;
    char bin[33] = "00000000000000000000000000000000";
    int i;
    int carry = 0;
    dec = atoi(num);
    if (dec < 0)
    {
        dec = -dec;
        negflag = 1;
    }
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    if (negflag)
    {
        for (i = 0; i<strlen(bin); i++)
        {
            if (bin[i] == '1')
            {
                bin[i] = '0';
            }
            else if (bin[i] == '0')
            {
                bin[i] = '1';
            }
        }
        i = strlen(bin)-1;
        carry = 1;
        while (i > 0)
        {
            if (carry == 1)
            {
                if (bin[i] == '0')
                {
                    bin[i] = '1';
                    carry = 0;
                }
                else
                {
                    bin[i] = '0';
                    carry = 1;
                }
            }
            i--;
        }
    }
    strcpy(num, bin);
    return num;
}

canonical_original_code:
char *numTo32Bin(char *num)
{
    int dec = 0;
    int negflag = 0;
    char bin[33] = "00000000000000000000000000000000";
    int i;
    int carry = 0;
    dec = atoi(num);
    if (dec < 0)
    {
        dec = -dec;
        negflag = 1;
    }
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    if (negflag)
    {
        for (i = 0; i<strlen(bin); i++)
        {
            if (bin[i] == '1')
            {
                bin[i] = '0';
            }
            else if (bin[i] == '0')
            {
                bin[i] = '1';
            }
        }
        i = strlen(bin)-1;
        carry = 1;
        while (i > 0)
        {
            if (carry == 1)
            {
                if (bin[i] == '0')
                {
                    bin[i] = '1';
                    carry = 0;
                }
                else
                {
                    bin[i] = '0';
                    carry = 1;
                }
            }
            i--;
        }
    }
    strcpy(num, bin);
    return num;
}

variable_types:
num
char *

variable_types:
bin
char [33]


strnlen

decompiled_code:
size_t __fastcall strnlen(const char *a1, size_t a2)
{
size_t result; // rax

result = strlen(a1);
if ( result > a2 )
result = a2;
return result;
}

canonical_decompiled_code:
size_t __fastcall func8(const char *a1, size_t a2)
{
size_t result; // rax

result = strlen(a1);
if ( result > a2 )
result = a2;
return result;
}

original_code:
size_t strnlen(const char *s, size_t n)
{
    if (strlen(s) <= n)
    {
        return strlen(s);
    }
    else
    {
        return n;
    }
}

canonical_original_code:
unsigned long strnlen(char *s, unsigned long n)
{
    if (strlen(s) <= n)
    {
        return strlen(s);
    }
    else
    {
        return n;
    }
}

variable_types:
s
char *

variable_types:
n
unsigned long

return_type: unsigned long


original_code:
char* binToHex32(char *bin)
{
    int i=0;
    char hex[33];
    char *sub;
    strcpy(hex, "");
    while (i < 32)
    {
        sub = substring(bin, i, 4);
        if (strcmp(sub, "0000")==0)
        {
            strcat(hex, "0");
        }
        else if (strcmp(sub, "0001")==0)
        {
            strcat(hex, "1");
        }
        else if (strcmp(sub, "0010")==0)
        {
            strcat(hex, "2");
        }
        else if (strcmp(sub, "0011")==0)
        {
            strcat(hex, "3");
        }
        else if (strcmp(sub, "0100")==0)
        {
            strcat(hex, "4");
        }
        else if (strcmp(sub, "0101")==0)
        {
            strcat(hex, "5");
        }
        else if (strcmp(sub, "0110")==0)
        {
            strcat(hex, "6");
        }
        else if (strcmp(sub, "0111")==0)
        {
            strcat(hex, "7");
        }
        else if (strcmp(sub, "1000")==0)
        {
            strcat(hex, "8");
        }
        else if (strcmp(sub, "1001")==0)
        {
            strcat(hex, "9");
        }
        else if (strcmp(sub, "1010")==0)
        {
            strcat(hex, "A");
        }
        else if (strcmp(sub, "1011")==0)
        {
            strcat(hex, "B");
        }
        else if (strcmp(sub, "1100")==0)
        {
            strcat(hex, "C");
        }
        else if (strcmp(sub, "1101")==0)
        {
            strcat(hex, "D");
        }
        else if (strcmp(sub, "1110")==0)
        {
            strcat(hex, "E");
        }
        else if (strcmp(sub, "1111")==0)
        {
            strcat(hex, "F");
        }
        free(sub);
        i += 4;
    }
    strcpy(bin, hex);
    return bin;
}

canonical_original_code:
char *binToHex32(char *bin)
{
    int i = 0;
    char hex[33];
    char *sub;
    strcpy(hex, "");
    while (i < 32)
    {
        sub = substring(bin, i, 4);
        if (strcmp(sub, "0000")==0)
        {
            strcat(hex, "0");
        }
        else if (strcmp(sub, "0001")==0)
        {
            strcat(hex, "1");
        }
        else if (strcmp(sub, "0010")==0)
        {
            strcat(hex, "2");
        }
        else if (strcmp(sub, "0011")==0)
        {
            strcat(hex, "3");
        }
        else if (strcmp(sub, "0100")==0)
        {
            strcat(hex, "4");
        }
        else if (strcmp(sub, "0101")==0)
        {
            strcat(hex, "5");
        }
        else if (strcmp(sub, "0110")==0)
        {
            strcat(hex, "6");
        }
        else if (strcmp(sub, "0111")==0)
        {
            strcat(hex, "7");
        }
        else if (strcmp(sub, "1000")==0)
        {
            strcat(hex, "8");
        }
        else if (strcmp(sub, "1001")==0)
        {
            strcat(hex, "9");
        }
        else if (strcmp(sub, "1010")==0)
        {
            strcat(hex, "A");
        }
        else if (strcmp(sub, "1011")==0)
        {
            strcat(hex, "B");
        }
        else if (strcmp(sub, "1100")==0)
        {
            strcat(hex, "C");
        }
        else if (strcmp(sub, "1101")==0)
        {
            strcat(hex, "D");
        }
        else if (strcmp(sub, "1110")==0)
        {
            strcat(hex, "E");
        }
        else if (strcmp(sub, "1111")==0)
        {
            strcat(hex, "F");
        }
        free(sub);
        i += 4;
    }
    strcpy(bin, hex);
    return bin;
}

variable_types:
bin
char *

variable_types:
hex
char [33]

variable_types:
sub
char *


addrToHex

original_code:
char* addrToHex(int address, char *ret)
{
    char bin[17] = "0000000000000000";
    int i;
    char hex[17];
    char *sub;
    int dec = address;
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    strcpy(hex, "");
    i = 0;
    while (i < 17 -1)
    {
        sub = substring(bin, i, 4);
        if (strcmp(sub, "0000")==0)
        {
            strcat(hex, "0");
        }
        else if (strcmp(sub, "0001")==0)
        {
            strcat(hex, "1");
        }
        else if (strcmp(sub, "0010")==0)
        {
            strcat(hex, "2");
        }
        else if (strcmp(sub, "0011")==0)
        {
            strcat(hex, "3");
        }
        else if (strcmp(sub, "0100")==0)
        {
            strcat(hex, "4");
        }
        else if (strcmp(sub, "0101")==0)
        {
            strcat(hex, "5");
        }
        else if (strcmp(sub, "0110")==0)
        {
            strcat(hex, "6");
        }
        else if (strcmp(sub, "0111")==0)
        {
            strcat(hex, "7");
        }
        else if (strcmp(sub, "1000")==0)
        {
            strcat(hex, "8");
        }
        else if (strcmp(sub, "1001")==0)
        {
            strcat(hex, "9");
        }
        else if (strcmp(sub, "1010")==0)
        {
            strcat(hex, "A");
        }
        else if (strcmp(sub, "1011")==0)
        {
            strcat(hex, "B");
        }
        else if (strcmp(sub, "1100")==0)
        {
            strcat(hex, "C");
        }
        else if (strcmp(sub, "1101")==0)
        {
            strcat(hex, "D");
        }
        else if (strcmp(sub, "1110")==0)
        {
            strcat(hex, "E");
        }
        else if (strcmp(sub, "1111")==0)
        {
            strcat(hex, "F");
        }
        free(sub);
        i += 4;
    }
    strcpy(ret, hex);
    return ret;
}

canonical_original_code:
char *addrToHex(int address, char *ret)
{
    char bin[17] = "0000000000000000";
    int i;
    char hex[17];
    char *sub;
    int dec = address;
    i = strlen(bin)-1;
    while (dec > 0)
    {
        bin[i] = (char)(((int)'0')+(dec % 2));
        dec /= 2;
        i--;
    }
    strcpy(hex, "");
    i = 0;
    while (i < 17 -1)
    {
        sub = substring(bin, i, 4);
        if (strcmp(sub, "0000")==0)
        {
            strcat(hex, "0");
        }
        else if (strcmp(sub, "0001")==0)
        {
            strcat(hex, "1");
        }
        else if (strcmp(sub, "0010")==0)
        {
            strcat(hex, "2");
        }
        else if (strcmp(sub, "0011")==0)
        {
            strcat(hex, "3");
        }
        else if (strcmp(sub, "0100")==0)
        {
            strcat(hex, "4");
        }
        else if (strcmp(sub, "0101")==0)
        {
            strcat(hex, "5");
        }
        else if (strcmp(sub, "0110")==0)
        {
            strcat(hex, "6");
        }
        else if (strcmp(sub, "0111")==0)
        {
            strcat(hex, "7");
        }
        else if (strcmp(sub, "1000")==0)
        {
            strcat(hex, "8");
        }
        else if (strcmp(sub, "1001")==0)
        {
            strcat(hex, "9");
        }
        else if (strcmp(sub, "1010")==0)
        {
            strcat(hex, "A");
        }
        else if (strcmp(sub, "1011")==0)
        {
            strcat(hex, "B");
        }
        else if (strcmp(sub, "1100")==0)
        {
            strcat(hex, "C");
        }
        else if (strcmp(sub, "1101")==0)
        {
            strcat(hex, "D");
        }
        else if (strcmp(sub, "1110")==0)
        {
            strcat(hex, "E");
        }
        else if (strcmp(sub, "1111")==0)
        {
            strcat(hex, "F");
        }
        free(sub);
        i += 4;
    }
    strcpy(ret, hex);
    return ret;
}

variable_types: address int

variable_types:
ret
char *

variable_types:
hex
char [17]


decompiled_code:
__int64 __fastcall add_datanode(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
int v4; // ecx

result = *((unsigned int *)a1 + 4);
v3 = *a1;
v4 = result + 1;
if ( *a1 )
{
result = *(_QWORD *)(v3 + 112);
a1[1] = v3;
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 112);
}
while ( result );
a1[1] = v3;
}
*(_QWORD *)(v3 + 112) = a2;
*((_DWORD *)a1 + 4) = v4;
}
else
{
*a1 = a2;
*((_DWORD *)a1 + 4) = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
int v4; // ecx

result = *((unsigned int *)a1 + 4);
v3 = *a1;
v4 = result + 1;
if ( *a1 )
{
result = *(_QWORD *)(v3 + 112);
a1[1] = v3;
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 112);
}
while ( result );
a1[1] = v3;
}
*(_QWORD *)(v3 + 112) = a2;
*((_DWORD *)a1 + 4) = v4;
}
else
{
*a1 = a2;
*((_DWORD *)a1 + 4) = v4;
}
return result;
}

original_code:
void add_datanode(datalist *list, datanode *node)
{
    if (list->head == ((void *)0))
    {
        list->head = node;
        list->count++;
    }
    else
    {
        list->cur = list->head;
        while (list->cur->next != ((void *)0))
        {
            list->cur = list->cur->next;
        }
        list->cur->next = node;
        list->count++;
    }
}

canonical_original_code:
void add_datanode(struct datalist_s *list, struct datanode_s *node)
{
    if (list->head == ((void *)0))
    {
        list->head = node;
        list->count++;
    }
    else
    {
        list->cur = list->head;
        while (list->cur->next != ((void *)0))
        {
            list->cur = list->cur->next;
        }
        list->cur->next = node;
        list->count++;
    }
}

variable_types: struct datalist_s { struct datanode_s { int address; int lineno; char label[32]; char binval[33]; char hex_val[33]; struct datanode_s *next; } *head; struct datanode_s *cur; int count; } *

variable_types:
node
struct datanode_s *

user_defined_types: struct datalist_s { struct datanode_s *head; struct datanode_s *cur; int count; }


decompiled_code:
void __fastcall delete_datalist(void *ptr)
{
_QWORD *i; // rdi

for ( i = *(_QWORD **)ptr; i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = i[14];
free(i);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *i; // rdi

for ( i = *(_QWORD **)ptr; i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = i[14];
free(i);
}
free(ptr);
}

original_code:
void delete_datalist(datalist* list)
{
    datanode *temp = ((void *)0);
    if (list->head != ((void *)0))
    {
        list->cur = list->head;
        while (list->cur != ((void *)0))
        {
            temp = list->cur;
            list->cur = list->cur->next;
            free(temp);
        }
    }
    free(list);
}

canonical_original_code:
void delete_datalist(struct datalist_s *list)
{
    struct datanode_s *temp = ((void *)0);
    if (list->head != ((void *)0))
    {
        list->cur = list->head;
        while (list->cur != ((void *)0))
        {
            temp = list->cur;
            list->cur = list->cur->next;
            free(temp);
        }
    }
    free(list);
}

variable_types: struct datanode_s { int address; int lineno; char label[32]; char binval[33]; char hex_val[33]; struct datanode_s *next; } *


decompiled_code:
__int64 __fastcall add_err(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
int v4; // er8
int v5; // ecx

result = *((unsigned int *)a1 + 4);
v3 = *a1;
*(_QWORD *)(a2 + 48) = 0LL;
v4 = result + 1;
if ( !v3 )
goto LABEL_9;
v5 = *(_DWORD *)(a2 + 4);
if ( v5 < *(_DWORD *)(v3 + 4) )
{
*(_QWORD *)(a2 + 48) = v3;
LABEL_9:
*a1 = a2;
*((_DWORD *)a1 + 4) = v4;
return result;
}
a1[1] = v3;
while ( 1 )
{
result = *(_QWORD *)(v3 + 48);
if ( !result )
{
*(_QWORD *)(v3 + 48) = a2;
*((_DWORD *)a1 + 4) = v4;
return result;
}
if ( v5 < *(_DWORD *)(result + 4) )
break;
a1[1] = result;
v3 = result;
}
*(_QWORD *)(a2 + 48) = result;
*(_QWORD *)(v3 + 48) = a2;
*((_DWORD *)a1 + 4) = v4;
return result;
}

original_code:
void add_err(errlist *list, errnode *node)
{
    node->next = ((void *)0);
    if (list->head == ((void *)0))
    {
        list->head = node;
        list->count++;
    }
    else
    {
        if (node->lineno < list->head->lineno)
        {
            node->next = list->head;
            list->head = node;
            list->count++;
        }
        else
        {
            list->cur = list->head;
            while (list->cur != ((void *)0))
            {
                if (list->cur->next != ((void *)0))
                {
                    if (node->lineno < list->cur->next->lineno)
                    {
                        node->next = list->cur->next;
                        list->cur->next = node;
                        list->count++;
                        return;
                    }
                }
                else
                {
                    list->cur->next = node;
                    list->count++;
                    return;
                }
                list->cur = list->cur->next;
            }
        }
    }
}

canonical_original_code:
void add_err(struct errlist_s *list, struct errnode_s *node)
{
    node->next = ((void *)0);
    if (list->head == ((void *)0))
    {
        list->head = node;
        list->count++;
    }
    else
    {
        if (node->lineno < list->head->lineno)
        {
            node->next = list->head;
            list->head = node;
            list->count++;
        }
        else
        {
            list->cur = list->head;
            while (list->cur != ((void *)0))
            {
                if (list->cur->next != ((void *)0))
                {
                    if (node->lineno < list->cur->next->lineno)
                    {
                        node->next = list->cur->next;
                        list->cur->next = node;
                        list->count++;
                        return;
                    }
                }
                else
                {
                    list->cur->next = node;
                    list->count++;
                    return;
                }
                list->cur = list->cur->next;
            }
        }
    }
}

variable_types: struct errlist_s { struct errnode_s { int errtype; int lineno; char symbol[32]; char opcode[8]; struct errnode_s *next; } *head; struct errnode_s *cur; int count; } *

variable_types:
node
struct errnode_s *

user_defined_types: struct errlist_s { struct errnode_s *head; struct errnode_s *cur; int count; }


decompiled_code:
void __fastcall delete_errlist(void *ptr)
{
_QWORD *i; // rdi

for ( i = *(_QWORD **)ptr; i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = i[6];
free(i);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *i; // rdi

for ( i = *(_QWORD **)ptr; i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = i[6];
free(i);
}
free(ptr);
}

original_code:
void delete_errlist(errlist* list)
{
    errnode *temp = ((void *)0);
    if (list->head != ((void *)0))
    {
        list->cur = list->head;
        while (list->cur != ((void *)0))
        {
            temp = list->cur;
            list->cur = list->cur->next;
            free(temp);
        }
    }
    free(list);
}

canonical_original_code:
void delete_errlist(struct errlist_s *list)
{
    struct errnode_s *temp = ((void *)0);
    if (list->head != ((void *)0))
    {
        list->cur = list->head;
        while (list->cur != ((void *)0))
        {
            temp = list->cur;
            list->cur = list->cur->next;
            free(temp);
        }
    }
    free(list);
}

variable_types: struct errnode_s { int errtype; int lineno; char symbol[32]; char opcode[8]; struct errnode_s *next; } *


hashgen

decompiled_code:
__int64 __fastcall hashgen(_BYTE *a1, int a2)
{
int v2; // ecx
unsigned int i; // edx
int v4; // eax

v2 = (char)*a1;
for ( i = 0; *a1; i = (int)abs32(v4) % a2 )
{
++a1;
v4 = v2 + 127 * i;
v2 = (char)*a1;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, int a2)
{
int v2; // ecx
unsigned int i; // edx
int v4; // eax

v2 = (char)*a1;
for ( i = 0; *a1; i = (int)abs32(v4) % a2 )
{
++a1;
v4 = v2 + 127 * i;
v2 = (char)*a1;
}
return i;
}

original_code:
int hashgen(char *s, int T) {
   int h = 0;
   int temp;
   for (; *s != 0; s++) {
       temp = (127 * h + *s);
       if (temp < 0) temp = -temp;
       h = temp % T;
   }
   return h;
}

variable_types: T int

variable_types: h int

variable_types: temp int


checkHash

decompiled_code:
__int64 __fastcall checkHash(__int64 *a1, int a2, const char *a3, _DWORD *a4)
{
__int64 *v6; // rbp
const char *v7; // rbx

if ( !a1 )
return 0LL;
v6 = a1;
while ( 1 )
{
if ( *((_DWORD *)v6 + 4) == a2 )
{
v7 = (const char *)v6[1];
if ( v7 )
break;
}
LABEL_3:
v6 = (__int64 *)*v6;
if ( !v6 )
return 0LL;
}
while ( strcmp(v7 + 8, a3) )
{
v7 = *(const char **)v7;
if ( !v7 )
goto LABEL_3;
}
*a4 = *((_DWORD *)v7 + 23);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, int a2, const char *a3, _DWORD *a4)
{
__int64 *v6; // rbp
const char *v7; // rbx

if ( !a1 )
return 0LL;
v6 = a1;
while ( 1 )
{
if ( *((_DWORD *)v6 + 4) == a2 )
{
v7 = (const char *)v6[1];
if ( v7 )
break;
}
LABEL_3:
v6 = (__int64 *)*v6;
if ( !v6 )
return 0LL;
}
while ( strcmp(v7 + 8, a3) )
{
v7 = *(const char **)v7;
if ( !v7 )
goto LABEL_3;
}
*a4 = *((_DWORD *)v7 + 23);
return 1LL;
}

original_code:
int checkHash(tnode* head, int key,const char* val, int *address)
{
    tnode* tcur = ((void *)0);
    lnode* lcur = ((void *)0);
    tcur = head;
    while (tcur != ((void *)0))
    {
        if (tcur->key == key)
        {
            lcur = tcur->head;
            while (lcur != ((void *)0))
            {
                if (strcmp(lcur->value, val)==0)
                {
                    *address = lcur->address;
                    return 1;
                }
                lcur = lcur->next;
            }
        }
        tcur = tcur->next;
    }
    return 0;
}

canonical_original_code:
int checkHash(struct TableNode *head, int key, char *val, int *address)
{
    struct TableNode *tcur = ((void *)0);
    struct ListNode *lcur = ((void *)0);
    tcur = head;
    while (tcur != ((void *)0))
    {
        if (tcur->key == key)
        {
            lcur = tcur->head;
            while (lcur != ((void *)0))
            {
                if (strcmp(lcur->value, val)==0)
                {
                    *address = lcur->address;
                    return 1;
                }
                lcur = lcur->next;
            }
        }
        tcur = tcur->next;
    }
    return 0;
}

variable_types: struct TableNode { struct TableNode *next; struct ListNode { struct ListNode *next; char value[81]; int address; } *head; int key; int entries; } *

variable_types: key int

variable_types:
val
char *

variable_types:
address
int *

user_defined_types: struct TableNode { struct TableNode *next; struct ListNode *head; int key; int entries; }


deletetable

decompiled_code:
void __fastcall deletetable(void *ptr)
{
_QWORD *i; // rbp
_QWORD *v2; // rbx
void *v3; // rdi
_QWORD *v4; // rbx

if ( ptr )
{
for ( i = ptr; ; i = v4 )
{
v2 = (_QWORD *)i[1];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
v4 = (_QWORD *)*i;
free(i);
if ( !v4 )
break;
}
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *i; // rbp
_QWORD *v2; // rbx
void *v3; // rdi
_QWORD *v4; // rbx

if ( ptr )
{
for ( i = ptr; ; i = v4 )
{
v2 = (_QWORD *)i[1];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
v4 = (_QWORD *)*i;
free(i);
if ( !v4 )
break;
}
}
}

original_code:
void deletetable(tnode* head)
{
 tnode* tcur = ((void *)0);
 tnode* tcur2 = ((void *)0);
 lnode* lcur = ((void *)0);
 lnode* lcur2 = ((void *)0);
 if (head == ((void *)0))
  return;
 tcur = head;
 while (tcur != ((void *)0))
 {
  lcur = tcur->head;
  while (lcur != ((void *)0))
  {
   lcur2 = lcur;
   lcur = lcur->next;
   free(lcur2);
  }
  tcur2 = tcur;
  tcur = tcur->next;
  free(tcur2);
 }
}

canonical_original_code:
void deletetable(struct TableNode *head)
{
 struct TableNode *tcur = ((void *)0);
 struct TableNode *tcur2 = ((void *)0);
 struct ListNode *lcur = ((void *)0);
 struct ListNode *lcur2 = ((void *)0);
 if (head == ((void *)0))
  return;
 tcur = head;
 while (tcur != ((void *)0))
 {
  lcur = tcur->head;
  while (lcur != ((void *)0))
  {
   lcur2 = lcur;
   lcur = lcur->next;
   free(lcur2);
  }
  tcur2 = tcur;
  tcur = tcur->next;
  free(tcur2);
 }
}

variable_types: struct ListNode { struct ListNode *next; char value[81]; int address; } *


decompiled_code:
__int64 __fastcall add_node(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
int v4; // ecx

result = *((unsigned int *)a1 + 4);
v3 = *a1;
v4 = result + 1;
if ( *a1 )
{
result = *(_QWORD *)(v3 + 200);
a1[1] = v3;
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 200);
}
while ( result );
a1[1] = v3;
}
*(_QWORD *)(v3 + 200) = a2;
*((_DWORD *)a1 + 4) = v4;
}
else
{
*a1 = a2;
*((_DWORD *)a1 + 4) = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
int v4; // ecx

result = *((unsigned int *)a1 + 4);
v3 = *a1;
v4 = result + 1;
if ( *a1 )
{
result = *(_QWORD *)(v3 + 200);
a1[1] = v3;
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 200);
}
while ( result );
a1[1] = v3;
}
*(_QWORD *)(v3 + 200) = a2;
*((_DWORD *)a1 + 4) = v4;
}
else
{
*a1 = a2;
*((_DWORD *)a1 + 4) = v4;
}
return result;
}

original_code:
void add_node(instlist *list, instnode *node)
{
    if (list->head == ((void *)0))
    {
        list->head = node;
        list->count++;
    }
    else
    {
        list->cur = list->head;
        while (list->cur->next != ((void *)0))
        {
            list->cur = list->cur->next;
        }
        list->cur->next = node;
        list->count++;
    }
}

canonical_original_code:
void add_node(struct instlist_s *list, struct instnode_s *node)
{
    if (list->head == ((void *)0))
    {
        list->head = node;
        list->count++;
    }
    else
    {
        list->cur = list->head;
        while (list->cur->next != ((void *)0))
        {
            list->cur = list->cur->next;
        }
        list->cur->next = node;
        list->count++;
    }
}

variable_types: struct instlist_s { struct instnode_s { int address; int lineno; char label[32]; int inst_type; char opcode_name[8]; char opcode_bin[8]; char bin_inst[33]; char hex_inst[33]; char rs1[6]; char rs2[6]; char rt[6]; char sa[6]; char imm[17]; char symbol[32]; struct instnode_s *next; } *head; struct instnode_s *cur; int count; } *

variable_types:
node
struct instnode_s *

user_defined_types: struct instlist_s { struct instnode_s *head; struct instnode_s *cur; int count; }