decompiled_code:
ssize_t __fastcall write_concmd(int a1, const void *a2)
{
return write(a1, a2, 0x1CuLL);
}

canonical_decompiled_code:
ssize_t __fastcall func6(int a1, const void *a2)
{
return write(a1, a2, 0x1CuLL);
}

original_code:
size_t write_concmd( int fd , struct concmd *buf )
{
 return write( fd , buf , sizeof(struct concmd) );
}

canonical_original_code:
unsigned long write_concmd(int fd, struct concmd *buf)
{
 return write( fd , buf , sizeof(struct concmd) );
}

user_defined_types: struct concmd { int cc_flag; int cc_cdword; char cc_signature[20]; }


decompiled_code:
unsigned __int64 __fastcall read_shellparm(int fd, __int64 a2)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // r12
_QWORD *v4; // rbp
int v5; // ebx

v2 = read_vdata(fd, (_QWORD *)a2);
v3 = read_data(fd, a2 + 8, 4uLL) + v2;
if ( *(int *)(a2 + 8) > 0 )
{
v4 = (_QWORD *)(a2 + 16);
v5 = 0;
do
{
v3 += read_vdata(fd, v4);
++v5;
++v4;
}
while ( *(_DWORD *)(a2 + 8) > v5 );
}
return v3;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(int fd, __int64 a2)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // r12
_QWORD *v4; // rbp
int v5; // ebx

v2 = func3(fd, (_QWORD *)a2);
v3 = func0(fd, a2 + 8, 4uLL) + v2;
if ( *(int *)(a2 + 8) > 0 )
{
v4 = (_QWORD *)(a2 + 16);
v5 = 0;
do
{
v3 += func3(fd, v4);
++v5;
++v4;
}
while ( *(_DWORD *)(a2 + 8) > v5 );
}
return v3;
}

original_code:
size_t read_shellparm( int fd , struct shellparm *buf )
{
 size_t ret = 0;
 ret += read_vdata( fd , &buf->sp_exec );
 ret += read_data( fd , &buf->sp_argc , sizeof(int) );
 int i;
 for( i = 0 ; i < buf->sp_argc ; i ++ )
 {
  ret += read_vdata( fd , &buf->sp_argv[i] );
 }
 return ret;
}

canonical_original_code:
unsigned long read_shellparm(int fd, struct shellparm *buf)
{
 unsigned long ret = 0;
 ret += read_vdata( fd , &buf->sp_exec );
 ret += read_data( fd , &buf->sp_argc , sizeof(int) );
 int i;
 for( i = 0 ; i < buf->sp_argc ; i ++ )
 {
  ret += read_vdata( fd , &buf->sp_argv[i] );
 }
 return ret;
}

variable_types: fd int

variable_types: struct shellparm { char *sp_exec; int sp_argc; char *sp_argv[255]; } *

variable_types:
ret
unsigned long

variable_types: i int

return_type: unsigned long


decompiled_code:
ssize_t __fastcall write_shellparm(int fd, const char **a2)
{
char *v2; // rbx
int v3; // eax
ssize_t v4; // r13
ssize_t v5; // r13
__int64 v6; // rbx
char *v7; // rbp
int v8; // eax

v2 = (char *)*a2;
v3 = strlen(*a2);
v4 = write_vdata(fd, v2, v3 + 1);
v5 = write(fd, a2 + 1, 4uLL) + v4;
if ( *((int *)a2 + 2) > 0 )
{
v6 = 0LL;
do
{
v7 = (char *)a2[v6 + 2];
v8 = strlen(v7);
v5 += write_vdata(fd, v7, v8 + 1);
++v6;
}
while ( *((_DWORD *)a2 + 2) > (int)v6 );
}
return v5;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, const char **a2)
{
char *v2; // rbx
int v3; // eax
ssize_t v4; // r13
ssize_t v5; // r13
__int64 v6; // rbx
char *v7; // rbp
int v8; // eax

v2 = (char *)*a2;
v3 = strlen(*a2);
v4 = func4(fd, v2, v3 + 1);
v5 = write(fd, a2 + 1, 4uLL) + v4;
if ( *((int *)a2 + 2) > 0 )
{
v6 = 0LL;
do
{
v7 = (char *)a2[v6 + 2];
v8 = strlen(v7);
v5 += func4(fd, v7, v8 + 1);
++v6;
}
while ( *((_DWORD *)a2 + 2) > (int)v6 );
}
return v5;
}

original_code:
size_t write_shellparm( int fd , struct shellparm *buf )
{
 size_t ret = 0;
 ret += write_vdata( fd , buf->sp_exec , strlen(buf->sp_exec) + 1 );
 ret += write( fd , &buf->sp_argc , sizeof(int) );
 int i;
 for( i = 0 ; i < buf->sp_argc ; i ++ )
 {
  ret += write_vdata( fd , buf->sp_argv[i] , strlen(buf->sp_argv[i]) + 1);
 }
 return ret;
}

canonical_original_code:
unsigned long write_shellparm(int fd, struct shellparm *buf)
{
 unsigned long ret = 0;
 ret += write_vdata( fd , buf->sp_exec , strlen(buf->sp_exec) + 1 );
 ret += write( fd , &buf->sp_argc , sizeof(int) );
 int i;
 for( i = 0 ; i < buf->sp_argc ; i ++ )
 {
  ret += write_vdata( fd , buf->sp_argv[i] , strlen(buf->sp_argv[i]) + 1);
 }
 return ret;
}

user_defined_types: struct shellparm { char *sp_exec; int sp_argc; char *sp_argv[255]; }


decompiled_code:
unsigned __int64 __fastcall read_pushparm(int fd, _QWORD *a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rbx

v2 = read_vdata(fd, a2);
v3 = read_vdata(fd, a2 + 1) + v2;
v4 = read_data(fd, (__int64)(a2 + 2), 4uLL) + v3;
return v4 + read_data(fd, (__int64)a2 + 20, 4uLL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(int fd, _QWORD *a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rbx

v2 = func3(fd, a2);
v3 = func3(fd, a2 + 1) + v2;
v4 = func0(fd, (__int64)(a2 + 2), 4uLL) + v3;
return v4 + func0(fd, (__int64)a2 + 20, 4uLL);
}

original_code:
size_t read_pushparm(int fd , struct pushparm* buf )
{
 size_t ret = 0;
 ret += read_vdata( fd , &buf->psp_basename );
 ret += read_vdata( fd , &buf->psp_path );
 ret += read_data( fd , &buf->psp_mode , sizeof(int) );
 ret += read_data( fd , &buf->psp_size , sizeof(unsigned int));
 return ret;
}

canonical_original_code:
unsigned long read_pushparm(int fd, struct pushparm *buf)
{
 unsigned long ret = 0;
 ret += read_vdata( fd , &buf->psp_basename );
 ret += read_vdata( fd , &buf->psp_path );
 ret += read_data( fd , &buf->psp_mode , sizeof(int) );
 ret += read_data( fd , &buf->psp_size , sizeof(unsigned int));
 return ret;
}

variable_types: struct pushparm { char *psp_basename; char *psp_path; int psp_mode; unsigned int psp_size; } *


decompiled_code:
ssize_t __fastcall write_pushpram(int fd, char **a2)
{
char *v2; // r12
int v3; // eax
ssize_t v4; // r12
char *v5; // r13
int v6; // eax
ssize_t v7; // r12
ssize_t v8; // r12

v2 = *a2;
v3 = strlen(*a2);
v4 = write_vdata(fd, v2, v3 + 1);
v5 = a2[1];
v6 = strlen(v5);
v7 = write_vdata(fd, v5, v6 + 1) + v4;
v8 = write(fd, a2 + 2, 4uLL) + v7;
return v8 + write(fd, (char *)a2 + 20, 4uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func10(int fd, char **a2)
{
char *v2; // r12
int v3; // eax
ssize_t v4; // r12
char *v5; // r13
int v6; // eax
ssize_t v7; // r12
ssize_t v8; // r12

v2 = *a2;
v3 = strlen(*a2);
v4 = func4(fd, v2, v3 + 1);
v5 = a2[1];
v6 = strlen(v5);
v7 = func4(fd, v5, v6 + 1) + v4;
v8 = write(fd, a2 + 2, 4uLL) + v7;
return v8 + write(fd, (char *)a2 + 20, 4uLL);
}

original_code:
size_t write_pushpram(int fd , struct pushparm* buf)
{
 size_t ret = 0;
 ret += write_vdata( fd , buf->psp_basename , strlen(buf->psp_basename) + 1 );
 ret += write_vdata( fd , buf->psp_path , strlen(buf->psp_path)+1 );
 ret += write( fd , &buf->psp_mode , sizeof(int) );
 ret += write( fd , &buf->psp_size , sizeof(unsigned int) );
 return ret;
}

canonical_original_code:
unsigned long write_pushpram(int fd, struct pushparm *buf)
{
 unsigned long ret = 0;
 ret += write_vdata( fd , buf->psp_basename , strlen(buf->psp_basename) + 1 );
 ret += write_vdata( fd , buf->psp_path , strlen(buf->psp_path)+1 );
 ret += write( fd , &buf->psp_mode , sizeof(int) );
 ret += write( fd , &buf->psp_size , sizeof(unsigned int) );
 return ret;
}

user_defined_types: struct pushparm { char *psp_basename; char *psp_path; int psp_mode; unsigned int psp_size; }


decompiled_code:
unsigned __int64 __fastcall read_iopacket(int fd, __int64 a2)
{
unsigned __int64 v2; // r12
unsigned int v3; // eax

v2 = read_data(fd, a2, 4uLL);
v3 = read_vdata(fd, (_QWORD *)(a2 + 8));
*(_DWORD *)(a2 + 4) = v3;
return v2 + v3;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(int fd, __int64 a2)
{
unsigned __int64 v2; // r12
unsigned int v3; // eax

v2 = func0(fd, a2, 4uLL);
v3 = func3(fd, (_QWORD *)(a2 + 8));
*(_DWORD *)(a2 + 4) = v3;
return v2 + v3;
}

original_code:
size_t read_iopacket(int fd , struct iopacket* buf )
{
 size_t ret = 0;
 ret += read_data( fd , &buf->ip_type , sizeof(unsigned int) );
 buf->ip_len = read_vdata( fd , (char**)&buf->ip_data );
 ret+= buf->ip_len;
 return ret;
}

canonical_original_code:
unsigned long read_iopacket(int fd, struct iopacket *buf)
{
 unsigned long ret = 0;
 ret += read_data( fd , &buf->ip_type , sizeof(unsigned int) );
 buf->ip_len = read_vdata( fd , (char **)&buf->ip_data );
 ret+= buf->ip_len;
 return ret;
}

variable_types: struct iopacket { unsigned int ip_type; unsigned int ip_len; void *ip_data; } *


decompiled_code:
ssize_t __fastcall write_iopacket(int fd, __int64 a2)
{
ssize_t v2; // rbx

v2 = write(fd, (const void *)a2, 4uLL);
return v2 + write_vdata(fd, *(void **)(a2 + 8), *(_DWORD *)(a2 + 4));
}

canonical_decompiled_code:
ssize_t __fastcall func12(int fd, __int64 a2)
{
ssize_t v2; // rbx

v2 = write(fd, (const void *)a2, 4uLL);
return v2 + func4(fd, *(void **)(a2 + 8), *(_DWORD *)(a2 + 4));
}

original_code:
size_t write_iopacket(int fd , struct iopacket* buf )
{
 size_t ret = 0;
 ret += write( fd , &buf->ip_type , sizeof(unsigned int) );
 ret += write_vdata( fd , buf->ip_data , buf->ip_len );
 return ret;
}

canonical_original_code:
unsigned long write_iopacket(int fd, struct iopacket *buf)
{
 unsigned long ret = 0;
 ret += write( fd , &buf->ip_type , sizeof(unsigned int) );
 ret += write_vdata( fd , buf->ip_data , buf->ip_len );
 return ret;
}

user_defined_types: struct iopacket { unsigned int ip_type; unsigned int ip_len; void *ip_data; }


decompiled_code:
__int64 __fastcall tty_raw(int fd)
{
__int64 result; // rax
int *v2; // rbp
int v3; // er12
struct termios v4; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

if ( tcgetattr(fd, &termios_p) < 0 )
return 0xFFFFFFFFLL;
*(__m128i *)&v4.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v4.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v4.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v4.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v4.c_ospeed = termios_p.c_ospeed;
termios_p.c_lflag &= 0xFFFF7FF4;
termios_p.c_iflag &= 0xFFFFFACD;
termios_p.c_cflag = termios_p.c_cflag & 0xFFFFFECF | 0x30;
termios_p.c_oflag &= 0xFFFFFFFE;
termios_p.c_cc[6] = 1;
termios_p.c_cc[5] = 0;
if ( tcsetattr(fd, 2, &termios_p) < 0 )
return 0xFFFFFFFFLL;
if ( tcgetattr(fd, &termios_p) < 0 )
{
v2 = _errno_location();
v3 = *v2;
tcsetattr(fd, 2, &v4);
*v2 = v3;
result = 0xFFFFFFFFLL;
}
else if ( (termios_p.c_cflag & 0x130) == 48
&& !(termios_p.c_iflag & 0x532 | termios_p.c_lflag & 0x800B | termios_p.c_oflag & 1)
&& *(_WORD *)&termios_p.c_cc[5] == 256 )
{
result = 0LL;
}
else
{
tcsetattr(fd, 2, &v4);
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
__int64 result; // rax
int *v2; // rbp
int v3; // er12
struct termios v4; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

if ( tcgetattr(fd, &termios_p) < 0 )
return 0xFFFFFFFFLL;
*(__m128i *)&v4.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v4.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v4.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v4.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v4.c_ospeed = termios_p.c_ospeed;
termios_p.c_lflag &= 0xFFFF7FF4;
termios_p.c_iflag &= 0xFFFFFACD;
termios_p.c_cflag = termios_p.c_cflag & 0xFFFFFECF | 0x30;
termios_p.c_oflag &= 0xFFFFFFFE;
termios_p.c_cc[6] = 1;
termios_p.c_cc[5] = 0;
if ( tcsetattr(fd, 2, &termios_p) < 0 )
return 0xFFFFFFFFLL;
if ( tcgetattr(fd, &termios_p) < 0 )
{
v2 = _errno_location();
v3 = *v2;
tcsetattr(fd, 2, &v4);
*v2 = v3;
result = 0xFFFFFFFFLL;
}
else if ( (termios_p.c_cflag & 0x130) == 48
&& !(termios_p.c_iflag & 0x532 | termios_p.c_lflag & 0x800B | termios_p.c_oflag & 1)
&& *(_WORD *)&termios_p.c_cc[5] == 256 )
{
result = 0LL;
}
else
{
tcsetattr(fd, 2, &v4);
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

variable_types: err int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: int


getCurrentTPar

original_code:
void getCurrentTPar( TParList tplist, trackparameters *tp, int step )
{
 int i = step - seq_first;
 tp->dvxmin = tplist[i].dvxmin;
 tp->dvxmax = tplist[i].dvxmax;
 tp->dvymin = tplist[i].dvymin;
 tp->dvymax = tplist[i].dvymax;
 tp->dvzmin = tplist[i].dvzmin;
 tp->dvzmax = tplist[i].dvzmax;
 tp->dangle = tplist[i].dangle;
 tp->dacc = tplist[i].dacc;
 tp->add = tplist[i].add;
}

canonical_original_code:
void getCurrentTPar(struct trackparameters *tplist, struct trackparameters *tp, int step)
{
 int i = step - seq_first;
 tp->dvxmin = tplist[i].dvxmin;
 tp->dvxmax = tplist[i].dvxmax;
 tp->dvymin = tplist[i].dvymin;
 tp->dvymax = tplist[i].dvymax;
 tp->dvzmin = tplist[i].dvzmin;
 tp->dvzmax = tplist[i].dvzmax;
 tp->dangle = tplist[i].dangle;
 tp->dacc = tplist[i].dacc;
 tp->add = tplist[i].add;
}

variable_types: struct trackparameters { double dacc; double dvymax; int dsumg; } *

variable_types:
tp
struct trackparameters *

variable_types: step int

return_type: void


freeTrackingParameters

decompiled_code:
void __fastcall freeTrackingParameters(void *a1)
{
if ( !staticTracking )
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
if ( !staticTracking )
free(a1);
}

original_code:
void freeTrackingParameters( TParList tp )
{
 if( !staticTracking )
  free( tp );
}

canonical_original_code:
void freeTrackingParameters(struct trackparameters *tp)
{
 if( !staticTracking )
  free( tp );
}

user_defined_types: struct trackparameters { double dacc; double dvymax; int dsumg; }


solve

original_code:
void solve(int credit_amount, int items[2001], int num_items, int solution[2])
{
 int i, j;
 int credit_remaining;
 i = 0;
 while (i < num_items) {
  if (items[i] >= credit_amount) {
   i++;
   continue;
  }
  credit_remaining = credit_amount - items[i];
  j = 0;
  while (j < num_items) {
   if (j == i) {
    j++;
    continue;
   }
   if (items[j] == credit_remaining) {
    solution[0] = i + 1;
    solution[1] = j + 1;
    return;
   }
   j++;
  }
  i++;
 }
 printf("COULDN'T FIND SOLUTION\n");
 return;
}

canonical_original_code:
void solve(int credit_amount, int items[2001], int num_items, int solution[2])
{
 int i; int j;
 int credit_remaining;
 i = 0;
 while (i < num_items) {
  if (items[i] >= credit_amount) {
   i++;
   continue;
  }
  credit_remaining = credit_amount - items[i];
  j = 0;
  while (j < num_items) {
   if (j == i) {
    j++;
    continue;
   }
   if (items[j] == credit_remaining) {
    solution[0] = i + 1;
    solution[1] = j + 1;
    return;
   }
   j++;
  }
  i++;
 }
 printf("COULDN'T FIND SOLUTION\n");
 return;
}

variable_types:
items
int [2001]

variable_types:
solution
int [2]

variable_types: j int


push

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

result = dword_404440;
if ( dword_404440 > 99 )
return printf("error: stack full, can't push %g\n", a1);
++dword_404440;
val[result] = a1;
return result;
}

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

result = dword_404440;
if ( dword_404440 > 99 )
return printf("error: stack full, can't push %g\n", a1);
++dword_404440;
val[result] = a1;
return result;
}

original_code:
void push(double f)
{
 if (sp < 100)
  val[sp++] = f;
 else
  printf("error: stack full, can't push %g\n", f);
}

variable_types: f double


pop

decompiled_code:
double pop()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_404440;
if ( dword_404440 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_404440;
result = val[v0 - 1];
}
return result;
}

canonical_decompiled_code:
double func8()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_404440;
if ( dword_404440 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_404440;
result = val[v0 - 1];
}
return result;
}

original_code:
double pop(void)
{
 if (sp > 0)
  return val[--sp];
 else
 {
  printf("error: stack empty\n");
  return 0.0;
 }
}

canonical_original_code:
double pop()
{
 if (sp > 0)
  return val[--sp];
 else
 {
  printf("error: stack empty\n");
  return 0.0;
 }
}

return_type: double


top

decompiled_code:
double top()
{
if ( dword_404440 > 0 )
return val[dword_404440 - 1];
puts("error: stack empty");
return 0.0;
}

canonical_decompiled_code:
double func9()
{
if ( dword_404440 > 0 )
return val[dword_404440 - 1];
puts("error: stack empty");
return 0.0;
}

original_code:
double top(void)
{
 if (sp > 0)
  return val[sp-1];
 else
 {
  printf("error: stack empty\n");
  return 0.0;
 }
}

canonical_original_code:
double top()
{
 if (sp > 0)
  return val[sp-1];
 else
 {
  printf("error: stack empty\n");
  return 0.0;
 }
}


swap

decompiled_code:
int swap()
{
__int64 v0; // rdx
int v1; // ecx
int result; // eax

if ( dword_404440 <= 1 )
return puts("error: less than 2 elements");
v0 = dword_404440 - 1;
v1 = (int)val[v0];
result = dword_404440 - 2;
val[v0] = val[dword_404440 - 2];
val[result] = (double)v1;
return result;
}

canonical_decompiled_code:
int func10()
{
__int64 v0; // rdx
int v1; // ecx
int result; // eax

if ( dword_404440 <= 1 )
return puts("error: less than 2 elements");
v0 = dword_404440 - 1;
v1 = (int)val[v0];
result = dword_404440 - 2;
val[v0] = val[dword_404440 - 2];
val[result] = (double)v1;
return result;
}

original_code:
void swap(void)
{
 if (sp < 2)
  printf("error: less than 2 elements\n");
 else
 {
  int t = val[sp-1];
  val[sp-1] = val[sp-2];
  val[sp-2] = t;
 }
}

canonical_original_code:
void swap()
{
 if (sp < 2)
  printf("error: less than 2 elements\n");
 else
 {
  int t = val[sp-1];
  val[sp-1] = val[sp-2];
  val[sp-2] = t;
 }
}

variable_types: t int


clear

decompiled_code:
void clear()
{
dword_404440 = 0;
}

original_code:
void clear(void)
{
 sp = 0;
}

canonical_original_code:
void clear()
{
 sp = 0;
}


dup

decompiled_code:
int dup()
{
double v0; // xmm0_8

v0 = top();
return push(v0);
}

canonical_decompiled_code:
int func12()
{
double v0; // xmm0_8

v0 = func9();
return func7(v0);
}

original_code:
void dup(void)
{
 push(top());
}

canonical_original_code:
void dup()
{
 push(top());
}


canonical_original_code:
void itoa_origin(int n, char s[])
{
 int i; int sign;
 if ((sign = n) < 0)
  n = -n;
 i = 0;
 do
 {
  s[i++] = n % 10 + '0';
 } while ((n /= 10) > 0);
 if (sign < 0)
  s[i++] = '-';
 s[i] = '\0';
 reverse(s);
}

variable_types: n int

variable_types:
s
char []

variable_types: sign int


reverse

original_code:
void reverse(char s[])
{
 int len;
 int i;
 char c;
 for (len = 0; s[len] != '\0'; ++len)
  ;
 for (i = 0; i < len / 2; ++i)
 {
  c = s[i];
  s[i] = s[len-1-i];
  s[len-1-i] = c;
 }
}

variable_types: len int

variable_types: c char


itoa

decompiled_code:
void __fastcall itoa(int a1, _BYTE *a2)
{
itoa_helper(a1, a2);
reverse(a2);
}

canonical_decompiled_code:
void __fastcall func9(int a1, _BYTE *a2)
{
func7(a1, a2);
func8(a2);
}

original_code:
void itoa(int n, char s[])
{
 itoa_helper(n, s);
 reverse(s);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[1032]; // [rsp+0h] [rbp-408h] BYREF

printf("%d\n", 0x80000000LL);
itoa_origin(0x80000000, v4);
printf("origin: %s\n", v4);
itoa(0x80000000, v4);
printf("revised: %s\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[1032]; // [rsp+0h] [rbp-408h] BYREF

printf("%d\n", 0x80000000LL);
func10(0x80000000, v4);
printf("origin: %s\n", v4);
func9(0x80000000, v4);
printf("revised: %s\n", v4);
return 0;
}

original_code:
int main(void)
{
 char s[1024];
 printf("%d\n", (-0x7fffffff - 1));
 itoa_origin((-0x7fffffff - 1), s);
 printf("origin: %s\n", s);
 itoa((-0x7fffffff - 1), s);
 printf("revised: %s\n", s);
 return 0;
}

canonical_original_code:
int main()
{
 char s[1024];
 printf("%d\n", (-0x7fffffff - 1));
 itoa_origin((-0x7fffffff - 1), s);
 printf("origin: %s\n", s);
 itoa((-0x7fffffff - 1), s);
 printf("revised: %s\n", s);
 return 0;
}


push

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

result = dword_404460;
if ( dword_404460 > 99 )
return printf("error: stack full, can't push %g\n", a1);
++dword_404460;
val[result] = a1;
return result;
}

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

result = dword_404460;
if ( dword_404460 > 99 )
return printf("error: stack full, can't push %g\n", a1);
++dword_404460;
val[result] = a1;
return result;
}

canonical_original_code:
void push(double f)
{
 if (sp < 100)
  val[sp++] = f;
 else
  printf("error: stack full, can't push %g\n", f);
}


pop

decompiled_code:
double pop()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_404460;
if ( dword_404460 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_404460;
result = val[v0 - 1];
}
return result;
}

canonical_decompiled_code:
double func8()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_404460;
if ( dword_404460 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_404460;
result = val[v0 - 1];
}
return result;
}


top

decompiled_code:
double top()
{
if ( dword_404460 > 0 )
return val[dword_404460 - 1];
puts("error: stack empty");
return 0.0;
}

canonical_decompiled_code:
double func9()
{
if ( dword_404460 > 0 )
return val[dword_404460 - 1];
puts("error: stack empty");
return 0.0;
}


swap

decompiled_code:
int swap()
{
__int64 v0; // rdx
int v1; // ecx
int result; // eax

if ( dword_404460 <= 1 )
return puts("error: less than 2 elements");
v0 = dword_404460 - 1;
v1 = (int)val[v0];
result = dword_404460 - 2;
val[v0] = val[dword_404460 - 2];
val[result] = (double)v1;
return result;
}

canonical_decompiled_code:
int func10()
{
__int64 v0; // rdx
int v1; // ecx
int result; // eax

if ( dword_404460 <= 1 )
return puts("error: less than 2 elements");
v0 = dword_404460 - 1;
v1 = (int)val[v0];
result = dword_404460 - 2;
val[v0] = val[dword_404460 - 2];
val[result] = (double)v1;
return result;
}


func

decompiled_code:
int __fastcall func(const char *a1)
{
double v1; // rbx
double v2; // xmm0_8
double v3; // xmm0_8
int result; // eax
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8

if ( !strcmp(a1, "sin") )
{
v5 = pop();
v6 = sin(v5);
result = push(v6);
}
else if ( !strcmp(a1, "cos") )
{
v7 = pop();
v8 = cos(v7);
result = push(v8);
}
else if ( !strcmp(a1, "exp") )
{
v9 = pop();
v10 = exp(v9);
result = push(v10);
}
else if ( !strcmp(a1, "pow") )
{
v1 = pop();
v2 = pop();
v3 = pow(v2, v1);
result = push(v3);
}
else
{
result = printf("%s is not a supported function.\n", a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
double v1; // rbx
double v2; // xmm0_8
double v3; // xmm0_8
int result; // eax
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8

if ( !strcmp(a1, "sin") )
{
v5 = func8();
v6 = sin(v5);
result = func7(v6);
}
else if ( !strcmp(a1, "cos") )
{
v7 = func8();
v8 = cos(v7);
result = func7(v8);
}
else if ( !strcmp(a1, "exp") )
{
v9 = func8();
v10 = exp(v9);
result = func7(v10);
}
else if ( !strcmp(a1, "pow") )
{
v1 = func8();
v2 = func8();
v3 = pow(v2, v1);
result = func7(v3);
}
else
{
result = printf("%s is not a supported function.\n", a1);
}
return result;
}

original_code:
void func(char s[])
{
 double op2;
 if (0 == strcmp(s, "sin"))
  push(sin(pop()));
 else if (0 == strcmp(s, "cos"))
  push(cos(pop()));
 else if (0 == strcmp(s, "exp"))
  push(exp(pop()));
 else if (!strcmp(s, "pow"))
 {
  op2 = pop();
  push(pow(pop(), op2));
 }
 else
  printf("%s is not a supported function.\n", s);
}


getbits

decompiled_code:
__int64 __fastcall getbits(unsigned int a1, char a2, char a3)
{
return (a1 >> (a2 + 1 - a3)) & ~(-1 << a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, char a2, char a3)
{
return (a1 >> (a2 + 1 - a3)) & ~(-1 << a3);
}

original_code:
unsigned getbits(unsigned x, int p, int n)
{
 return (x >> (p+1-n)) & ~(~0 << n);
}

canonical_original_code:
unsigned int getbits(unsigned int x, int p, int n)
{
 return (x >> (p+1-n)) & ~(~0 << n);
}

variable_types:
x
unsigned int

variable_types: p int

return_type: unsigned int


setbits

decompiled_code:
__int64 __fastcall setbits(int a1, char a2, char a3, unsigned int a4)
{
return (a1 & ~(~(-1 << a3) << (a2 + 1 - a3))) + ((unsigned int)getbits(a4, a3 - 1, a3) << (a2 + 1 - a3));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char a2, char a3, unsigned int a4)
{
return (a1 & ~(~(-1 << a3) << (a2 + 1 - a3))) + ((unsigned int)func7(a4, a3 - 1, a3) << (a2 + 1 - a3));
}

original_code:
unsigned setbits(unsigned x, int p, int n, unsigned y)
{
 x = x & ~(~(~0 << n) << (p+1-n));
 y = getbits(y, n-1, n);
 x = x + (y << (p+1-n));
 return x;
}

canonical_original_code:
unsigned int setbits(unsigned int x, int p, int n, unsigned int y)
{
 x = x & ~(~(~0 << n) << (p+1-n));
 y = getbits(y, n-1, n);
 x = x + (y << (p+1-n));
 return x;
}

variable_types:
y
unsigned int


bitcount

decompiled_code:
__int64 __fastcall bitcount(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

original_code:
int bitcount(unsigned x)
{
 unsigned b;
 for (b = 0; x != 0U; x &= (x-1))
  ++b;
 return b;
}

canonical_original_code:
int bitcount(unsigned int x)
{
 unsigned int b;
 for (b = 0; x != 0U; x &= (x-1))
  ++b;
 return b;
}

variable_types:
b
unsigned int


main

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

v3 = bitcount(2299);
printf("%d\n", v3);
v4 = bitcount(2905);
printf("%d\n", v4);
return 0;
}

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

v3 = func7(2299);
printf("%d\n", v3);
v4 = func7(2905);
printf("%d\n", v4);
return 0;
}

original_code:
int main(void)
{
 unsigned x;
 x = 0x8FB;
 printf("%d\n", bitcount(x));
 x = 0xB59;
 printf("%d\n", bitcount(x));
 return 0;
}

canonical_original_code:
int main()
{
 unsigned int x;
 x = 0x8FB;
 printf("%d\n", bitcount(x));
 x = 0xB59;
 printf("%d\n", bitcount(x));
 return 0;
}


trimline

original_code:
void trimline(char line[], int len)
{
 int i;
 for (i = len - 2; line[i] == ' ' || line[i] == '\t'; --i)
  ;
 line[++i] = (line[len - 1] == '\n') ? '\n' : '\0';
 if (line[i] == '\n')
  line[++i] = '\0';
 if (i != 1)
  printf("%s", line);
}

variable_types:
line
char []

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5[1016]; // [rsp+0h] [rbp-3F8h] BYREF

while ( 1 )
{
v3 = obtenirline((__int64)v5, 1000);
if ( v3 <= 0 )
break;
if ( v3 > 1 )
trimline(v5, v3);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5[1016]; // [rsp+0h] [rbp-3F8h] BYREF

while ( 1 )
{
v3 = func7((__int64)v5, 1000);
if ( v3 <= 0 )
break;
if ( v3 > 1 )
func8(v5, v3);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int len;
 char line[1000];
 while ((len = obtenirline(line, 1000)) > 0)
 {
  if (len > 1)
   trimline(line, len);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
line
char [1000]


getword

original_code:
int getword(char *word, int lim)
{
    int c, getch(void);
    void ungetch(int);
    char *w = word;
    while (((*__ctype_b_loc ())[(int) ((c = getch()))] & (unsigned short int) _ISspace))
        ;
    *w++ = c;
    if (c == '\'')
    {
       if (getch() == '\\')
           getch();
       getch();
    }
    else if (c == '"')
    {
        for(;;)
        {
            if ((c = getch()) == '\\')
                getch();
            else if (c == '"')
                break;
        }
    }
    else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) || c == '_')
    {
        for (; --lim; w++)
            if (!((*__ctype_b_loc ())[(int) ((*w = getch()))] & (unsigned short int) _ISalnum))
            {
                ungetch(*w);
                break;
            }
    }
    else if (c == '/')
    {
        if ((c = getch()) == '*')
        {
            for(;;)
            {
                while ((c = getch()) != '*')
                    ;
                if ((c = getch()) != '/')
                    ungetch(c);
                else
                    break;
            }
        }
        else if (c == '/')
            while (getch() != '\n')
                ;
        else
            ungetch(c);
    }
    *w = '\0';
    return word[0];
}

canonical_original_code:
int getword(char *word, int lim)
{
    int c; int getch();
    void ungetch(int);
    char *w = word;
    while (((*__ctype_b_loc ())[(int) ((c = getch()))] & (unsigned short) _ISspace))
        ;
    *w++ = c;
    if (c == '\'')
    {
       if (getch() == '\\')
           getch();
       getch();
    }
    else if (c == '"')
    {
        for(;;)
        {
            if ((c = getch()) == '\\')
                getch();
            else if (c == '"')
                break;
        }
    }
    else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) || c == '_')
    {
        for (; --lim; w++)
            if (!((*__ctype_b_loc ())[(int) ((*w = getch()))] & (unsigned short) _ISalnum))
            {
                ungetch(*w);
                break;
            }
    }
    else if (c == '/')
    {
        if ((c = getch()) == '*')
        {
            for(;;)
            {
                while ((c = getch()) != '*')
                    ;
                if ((c = getch()) != '/')
                    ungetch(c);
                else
                    break;
            }
        }
        else if (c == '/')
            while (getch() != '\n')
                ;
        else
            ungetch(c);
    }
    *w = '\0';
    return word[0];
}

variable_types:
word
char *

variable_types: lim int

variable_types: c int

variable_types:
getch
int ()

variable_types:
ungetch
void (int)

variable_types:
w
char *


binsearch

decompiled_code:
__int64 __fastcall binsearch(char *s1, __int64 a2, int a3)
{
int v3; // edx
int v4; // ebp
int v5; // er12
int v6; // ebx
unsigned int v7; // er15
int v8; // eax

v3 = a3 - 1;
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
v5 = 0;
do
{
v6 = (v5 + v4) / 2;
v7 = v6;
v8 = strcmp(s1, *(const char **)(a2 + 16LL * v6));
if ( v8 < 0 )
{
v4 = v6 - 1;
}
else
{
if ( v8 <= 0 )
return v7;
v5 = v6 + 1;
}
}
while ( v5 <= v4 );
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s1, __int64 a2, int a3)
{
int v3; // edx
int v4; // ebp
int v5; // er12
int v6; // ebx
unsigned int v7; // er15
int v8; // eax

v3 = a3 - 1;
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
v5 = 0;
do
{
v6 = (v5 + v4) / 2;
v7 = v6;
v8 = strcmp(s1, *(const char **)(a2 + 16LL * v6));
if ( v8 < 0 )
{
v4 = v6 - 1;
}
else
{
if ( v8 <= 0 )
return v7;
v5 = v6 + 1;
}
}
while ( v5 <= v4 );
return (unsigned int)-1;
}

original_code:
int binsearch(char *word, struct key tab[], int n)
{
    int cond;
    int low, high, mid;
    low = 0;
    high = n - 1;
    while (low <= high)
    {
        mid = (low + high) / 2;
        if ((cond = strcmp(word, tab[mid].word)) < 0)
            high = mid - 1;
        else if (cond > 0)
            low = mid + 1;
        else
            return mid;
    }
    return -1;
}

canonical_original_code:
int binsearch(char *word, struct key tab[], int n)
{
    int cond;
    int low; int high; int mid;
    low = 0;
    high = n - 1;
    while (low <= high)
    {
        mid = (low + high) / 2;
        if ((cond = strcmp(word, tab[mid].word)) < 0)
            high = mid - 1;
        else if (cond > 0)
            low = mid + 1;
        else
            return mid;
    }
    return -1;
}

variable_types: struct key { char *word; int count; } []

variable_types: n int

variable_types: cond int

variable_types: low int

variable_types: high int

variable_types: mid int


getch

decompiled_code:
int getch()
{
char *v0; // rax

v0 = (char *)bufp;
if ( bufp <= &buf )
return getchar();
bufp = (char *)bufp - 1;
return *(v0 - 1);
}

canonical_decompiled_code:
int func8()
{
char *v0; // rax

v0 = (char *)bufp;
if ( bufp <= &buf )
return getchar();
bufp = (char *)bufp - 1;
return *(v0 - 1);
}

original_code:
int getch(void)
{
    return bufp > buf ? *--bufp : getchar();
}

canonical_original_code:
int getch()
{
    return bufp > buf ? *--bufp : getchar();
}


ungetch

decompiled_code:
int __fastcall ungetch(char a1)
{
_BYTE *v1; // rax

v1 = bufp;
if ( bufp > &unk_404304 )
{
LODWORD(v1) = puts("ungetch: too many characters");
}
else
{
bufp = (char *)bufp + 1;
*v1 = a1;
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func9(char a1)
{
_BYTE *v1; // rax

v1 = bufp;
if ( bufp > &unk_404304 )
{
LODWORD(v1) = puts("ungetch: too many characters");
}
else
{
bufp = (char *)bufp + 1;
*v1 = a1;
}
return (int)v1;
}

original_code:
void ungetch(int c)
{
    if (bufp > buf + 100)
        printf("ungetch: too many characters\n");
    else
        *bufp++ = c;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rbx
__int64 v5; // rsi
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

while ( (unsigned int)getword(v7, 100) != -1 )
{
if ( ((*__ctype_b_loc())[v7[0]] & 0x400) != 0 )
{
v3 = binsearch(v7, (__int64)&keytab, 32);
if ( v3 >= 0 )
++dword_404088[4 * v3];
}
}
v4 = (char *)&keytab;
do
{
v5 = *((unsigned int *)v4 + 2);
if ( (int)v5 > 0 )
printf("%4d %s\n", v5, *(const char **)v4);
v4 += 16;
}
while ( v4 != &_bss_start );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rbx
__int64 v5; // rsi
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

while ( (unsigned int)func10(v7, 100) != -1 )
{
if ( ((*__ctype_b_loc())[v7[0]] & 0x400) != 0 )
{
v3 = func7(v7, (__int64)&keytab, 32);
if ( v3 >= 0 )
++dword_404088[4 * v3];
}
}
v4 = (char *)&keytab;
do
{
v5 = *((unsigned int *)v4 + 2);
if ( (int)v5 > 0 )
printf("%4d %s\n", v5, *(const char **)v4);
v4 += 16;
}
while ( v4 != &_bss_start );
return 0;
}

original_code:
int main(void)
{
    int n;
    char word[100];
    while (getword(word, 100) != (-1))
    {
        if (((*__ctype_b_loc ())[(int) ((word[0]))] & (unsigned short int) _ISalpha))
            if ((n = binsearch(word, keytab, (sizeof keytab / sizeof(keytab[0])))) >= 0)
                keytab[n].count++;
    }
    for (n = 0; n < (sizeof keytab / sizeof(keytab[0])); n++)
        if (keytab[n].count > 0)
            printf("%4d %s\n", keytab[n].count, keytab[n].word);
    return 0;
}

canonical_original_code:
int main()
{
    int n;
    char word[100];
    while (getword(word, 100) != (-1))
    {
        if (((*__ctype_b_loc ())[(int) ((word[0]))] & (unsigned short) _ISalpha))
            if ((n = binsearch(word, keytab, (sizeof keytab / sizeof(keytab[0])))) >= 0)
                keytab[n].count++;
    }
    for (n = 0; n < (sizeof keytab / sizeof(keytab[0])); n++)
        if (keytab[n].count > 0)
            printf("%4d %s\n", keytab[n].count, keytab[n].word);
    return 0;
}

variable_types:
word
char [100]


atof

original_code:
double atof(char s[])
{
 double val;
 int power;
 int power_sig;
 int power_exp;
 int sign_sig;
 int sign_exp;
 int i;
 for (i = 0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace); ++i)
  ;
 sign_sig = s[i] == '-' ? -1 : 1;
 if (s[i] == '-' || s[i] == '+')
  ++i;
 for (val = 0.0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISdigit); ++i)
  val = 10.0 * val + (s[i] - '0');
 if (s[i] == '.')
  ++i;
 for (power_sig = 0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISdigit); ++i)
 {
  val = 10.0 * val + (s[i] - '0');
  ++power_sig;
 }
 if (s[i] == 'e' || s[i] == 'E')
  ++i;
 sign_exp = s[i] == '-' ? -1 : 1;
 if (s[i] == '-' || s[i] == '+')
  ++i;
 for (power_exp = 0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISdigit); ++i)
  power_exp = 10 * power_exp + (s[i] - '0');
 power = sign_exp * power_exp - power_sig;
 if (power < 0)
 {
  while (power++ < 0)
   val /= 10.0;
 }
 else
 {
  while (power-- > 0)
   val *= 10.0;
 }
 return sign_sig * val;
}

canonical_original_code:
double atof(char s[])
{
 double val;
 int power;
 int power_sig;
 int power_exp;
 int sign_sig;
 int sign_exp;
 int i;
 for (i = 0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace); ++i)
  ;
 sign_sig = s[i] == '-' ? -1 : 1;
 if (s[i] == '-' || s[i] == '+')
  ++i;
 for (val = 0.0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISdigit); ++i)
  val = 10.0 * val + (s[i] - '0');
 if (s[i] == '.')
  ++i;
 for (power_sig = 0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISdigit); ++i)
 {
  val = 10.0 * val + (s[i] - '0');
  ++power_sig;
 }
 if (s[i] == 'e' || s[i] == 'E')
  ++i;
 sign_exp = s[i] == '-' ? -1 : 1;
 if (s[i] == '-' || s[i] == '+')
  ++i;
 for (power_exp = 0; ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISdigit); ++i)
  power_exp = 10 * power_exp + (s[i] - '0');
 power = sign_exp * power_exp - power_sig;
 if (power < 0)
 {
  while (power++ < 0)
   val /= 10.0;
 }
 else
 {
  while (power-- > 0)
   val *= 10.0;
 }
 return sign_sig * val;
}

variable_types:
s
char []

variable_types: val double

variable_types: power int

variable_types: i int


advance

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

result = (unsigned int)(a1 + 1);
if ( a1 >= 1000 )
result = 0LL;
return result;
}

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

result = (unsigned int)(a1 + 1);
if ( a1 >= 1000 )
result = 0LL;
return result;
}

original_code:
int advance(int pointer)
{
 if (pointer < 1001 - 1)
  return pointer + 1;
 else
  return 0;
}

variable_types: pointer int


main

original_code:
int main(void)
{
 char blank[1001];
 int head, tail;
 int nonspace;
 int retval;
 int c;
 retval = nonspace = head = tail = 0;
 while ((c = getchar()) != (-1))
 {
  if (c == '\n')
  {
   head = tail = 0;
   if (nonspace)
      putchar('\n');
   nonspace = 0;
  }
  else if (c == ' ' || c == '\t')
  {
   if (advance(head) == tail)
   {
      putchar(blank[tail]);
      tail = advance(tail);
      nonspace = 1;
      retval = 1;
   }
   blank[head] = c;
   head = advance(head);
  }
  else
  {
   while (head != tail)
   {
    putchar(blank[tail]);
    tail = advance(tail);
   }
   putchar(c);
   nonspace = 1;
  }
 }
 return retval;
}

canonical_original_code:
int main()
{
 char blank[1001];
 int head; int tail;
 int nonspace;
 int retval;
 int c;
 retval = nonspace = head = tail = 0;
 while ((c = getchar()) != (-1))
 {
  if (c == '\n')
  {
   head = tail = 0;
   if (nonspace)
      putchar('\n');
   nonspace = 0;
  }
  else if (c == ' ' || c == '\t')
  {
   if (advance(head) == tail)
   {
      putchar(blank[tail]);
      tail = advance(tail);
      nonspace = 1;
      retval = 1;
   }
   blank[head] = c;
   head = advance(head);
  }
  else
  {
   while (head != tail)
   {
    putchar(blank[tail]);
    tail = advance(tail);
   }
   putchar(c);
   nonspace = 1;
  }
 }
 return retval;
}

variable_types:
blank
char [1001]

variable_types: head int

variable_types: tail int

variable_types: nonspace int

variable_types: retval int


htoi

original_code:
unsigned int htoi(const char s[])
{
 unsigned int answer = 0;
 int i = 0;
 int valid = 1;
 if (s[i] == '0')
 {
  ++i;
  if (s[i] == 'x' || s[i] == 'X')
  {
   ++i;
  }
 }
 while (valid && s[i] != '\0')
 {
  answer *= 16;
  if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISxdigit))
  {
   if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISdigit))
    answer += s[i] - '0';
   else
    answer += toupper(s[i]) - 'A' + 10;
  }
  else
   valid = 0;
  ++i;
 }
 if (!valid)
  answer = 0;
 return answer;
}

canonical_original_code:
unsigned int htoi(char s[])
{
 unsigned int answer = 0;
 int i = 0;
 int valid = 1;
 if (s[i] == '0')
 {
  ++i;
  if (s[i] == 'x' || s[i] == 'X')
  {
   ++i;
  }
 }
 while (valid && s[i] != '\0')
 {
  answer *= 16;
  if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISxdigit))
  {
   if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISdigit))
    answer += s[i] - '0';
   else
    answer += toupper(s[i]) - 'A' + 10;
  }
  else
   valid = 0;
  ++i;
 }
 if (!valid)
  answer = 0;
 return answer;
}

variable_types:
answer
unsigned int

variable_types: valid int


main

original_code:
int main(void)
{
 char *test[] =
 {
  "F00",
  "bar",
  "0100",
  "0x1",
  "0XA",
  "0X0C0E",
  "abcdef",
  "123456",
  "0x123456",
  "deadbeaf",
  "zog_c"
 };
 size_t numtests = sizeof(test) / sizeof(test[0]);
 size_t thistest;
 for (thistest = 0; thistest < numtests; thistest++)
 {
  printf("%s: %u\n", test[thistest], htoi(test[thistest]));
 }
 return 0;
}

canonical_original_code:
int main()
{
 char *test[] = {
  "F00",
  "bar",
  "0100",
  "0x1",
  "0XA",
  "0X0C0E",
  "abcdef",
  "123456",
  "0x123456",
  "deadbeaf",
  "zog_c"
 };
 unsigned long numtests = sizeof(test) / sizeof(test[0]);
 unsigned long thistest;
 for (thistest = 0; thistest < numtests; thistest++)
 {
  printf("%s: %u\n", test[thistest], htoi(test[thistest]));
 }
 return 0;
}

variable_types:
test
char *[]

variable_types:
numtests
unsigned long

variable_types:
thistest
unsigned long


itob

canonical_original_code:
void itob(int n, char s[], int b)
{
 ((void) sizeof ((2 <= b && b <= 16) ? 1 : 0), __extension__ ({ if (2 <= b && b <= 16) ; else __assert_fail ("2 <= b && b <= 16", "5.c", 49, __extension__ __PRETTY_FUNCTION__); }));
 int i; int sign;
 i = 0;
 sign = n;
 do
 {
  unsigned int t = abs(n % b);
  s[i++] = t < 10 ? t + '0' : t - 10 + 'a';
 } while (n /= b);
 if (sign < 0)
  s[i++] = '-';
 s[i] = '\0';
 reverse(s);
}

variable_types: n int

variable_types: b int

variable_types: sign int

variable_types:
t
unsigned int


reverse

original_code:
void reverse(char s[])
{
 int len;
 int i;
 char c;
 for (len = 0; s[len] != '\0'; ++len)
  ;
 for (i = 0; i < len / 2; ++i)
 {
  c = s[i];
  s[i] = s[len-1-i];
  s[len-1-i] = c;
 }
}

variable_types:
s
char []

variable_types: len int

variable_types: c char


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

result = a2;
if ( *(_BYTE *)(a1 + (int)a2 - 1) == 10 )
{
result = a2 - 1;
*(_BYTE *)(a1 + (int)result) = 0;
}
return result;
}

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

result = a2;
if ( *(_BYTE *)(a1 + (int)a2 - 1) == 10 )
{
result = a2 - 1;
*(_BYTE *)(a1 + (int)result) = 0;
}
return result;
}

original_code:
int discard_newline(char s[], int len)
{
 if (s[len - 1] == '\n')
  s[--len] = '\0';
 return len;
}


obtenirline

canonical_original_code:
int obtenirline(char s[], int lim)
{
 int i; int c;
 for (i = 0; i < lim - 1 && (c = getchar()) != '\n' && c != (-1); ++i)
  s[i] = c;
 if (c == '\n')
  s[i++] = '\n';
 s[i] = '\0';
 return i;
}

variable_types: lim int

variable_types: i int

variable_types: c int


main

original_code:
int main(void)
{
 int len;
 char line[1000];
 int i, j, p, col;
 col = p = 0;
 while ((len = obtenirline(line, 1000)) > 0)
 {
  p = 0;
  if (len == 1)
  {
   printf("\n\n");
   col = 0;
   continue;
  }
  len = discard_newline(line, len);
  while (len - p >= 60 - col)
  {
   for (i = 60 - col - 1; i >= 0 && line[p+i] != ' '; --i)
    ;
   for (j = 60 - col - 1; j < len - p && line[p+j] != ' '; ++j)
    ;
   i = ((i + j) / 2 > 60 - col - 1) ? i : j;
   while (i-- >= 0)
    putchar(line[p++]);
   col = 0;
   putchar('\n');
  }
  for (; p < len; ++p, ++col)
  {
   putchar(line[p]);
  }
 }
 return 0;
}

canonical_original_code:
int main()
{
 int len;
 char line[1000];
 int i; int j; int p; int col;
 col = p = 0;
 while ((len = obtenirline(line, 1000)) > 0)
 {
  p = 0;
  if (len == 1)
  {
   printf("\n\n");
   col = 0;
   continue;
  }
  len = discard_newline(line, len);
  while (len - p >= 60 - col)
  {
   for (i = 60 - col - 1; i >= 0 && line[p+i] != ' '; --i)
    ;
   for (j = 60 - col - 1; j < len - p && line[p+j] != ' '; ++j)
    ;
   i = ((i + j) / 2 > 60 - col - 1) ? i : j;
   while (i-- >= 0)
    putchar(line[p++]);
   col = 0;
   putchar('\n');
  }
  for (; p < len; ++p, ++col)
  {
   putchar(line[p]);
  }
 }
 return 0;
}

variable_types:
line
char [1000]

variable_types: j int

variable_types: p int

variable_types: col int


strrindex

decompiled_code:
__int64 __fastcall strrindex(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // r9
unsigned int v3; // er11
unsigned int v4; // er10
__int64 v5; // rax
int v6; // edi
char v7; // cl
char v8; // dl

if ( !*a1 )
return 0xFFFFFFFFLL;
v2 = a1;
v3 = -1;
v4 = 0;
do
{
v5 = 1LL;
if ( *v2 == *a2 )
{
do
{
v6 = v5;
v7 = v2[v5++];
v8 = a2[v5 - 1];
}
while ( v7 == v8 );
if ( !v8 && v6 > 0 )
v3 = v4;
}
++v4;
++v2;
}
while ( *v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // r9
unsigned int v3; // er11
unsigned int v4; // er10
__int64 v5; // rax
int v6; // edi
char v7; // cl
char v8; // dl

if ( !*a1 )
return 0xFFFFFFFFLL;
v2 = a1;
v3 = -1;
v4 = 0;
do
{
v5 = 1LL;
if ( *v2 == *a2 )
{
do
{
v6 = v5;
v7 = v2[v5++];
v8 = a2[v5 - 1];
}
while ( v7 == v8 );
if ( !v8 && v6 > 0 )
v3 = v4;
}
++v4;
++v2;
}
while ( *v2 );
return v3;
}

canonical_original_code:
int strrindex(char s[], char t[])
{
 int i; int j; int k; int kr;
 k = kr = -1;
 for (i = 0; s[i] != '\0'; ++i)
 {
  for (k = i, j = 0; s[k] == t[j]; ++k, ++j)
   ;
  if (j > 0 && t[j] == '\0')
   kr = i;
 }
 return kr;
}

variable_types:
t
char []

variable_types: k int

variable_types: kr int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char v5[77]; // [rsp+Bh] [rbp-4Dh] BYREF

strcpy(&v5[5], "I would forgive you if you could forgive me, could you?\n");
strcpy(v5, "ould");
v3 = strrindex(&v5[5], v5);
printf("%d\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char v5[77]; // [rsp+Bh] [rbp-4Dh] BYREF

strcpy(&v5[5], "I would forgive you if you could forgive me, could you?\n");
strcpy(v5, "ould");
v3 = func7(&v5[5], v5);
printf("%d\n", v3);
return 0;
}

original_code:
int main(void)
{
 char s[] = "I would forgive you if you could forgive me, could you?\n";
 char t[] = "ould";
 printf("%d\n", strrindex(s, t));
 return 0;
}

canonical_original_code:
int main()
{
 char s[] = "I would forgive you if you could forgive me, could you?\n";
 char t[] = "ould";
 printf("%d\n", strrindex(s, t));
 return 0;
}


getbits

original_code:
unsigned getbits(unsigned x, int p, int n)
{
 return (x >> (p+1-n)) & ~(~0 << n);
}

canonical_original_code:
unsigned int getbits(unsigned int x, int p, int n)
{
 return (x >> (p+1-n)) & ~(~0 << n);
}

variable_types:
x
unsigned int

variable_types: n int


invert

decompiled_code:
__int64 __fastcall invert(int a1, char a2, char a3)
{
return (a1 & ~(~(-1 << a3) << (a2 + 1 - a3))) + ((unsigned int)getbits(~a1, a2, a3) << (a2 + 1 - a3));
}

original_code:
unsigned invert(unsigned x, int p, int n)
{
 unsigned y = getbits(~x, p, n) << (p+1-n);
 x = x & ~(~(~0 << n) << (p+1-n));
 return x + y;
}

canonical_original_code:
unsigned int invert(unsigned int x, int p, int n)
{
 unsigned int y = getbits(~x, p, n) << (p+1-n);
 x = x & ~(~(~0 << n) << (p+1-n));
 return x + y;
}

variable_types:
y
unsigned int


copy

decompiled_code:
__int64 __fastcall copy(_BYTE *a1, unsigned __int8 *a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl

result = *a2;
*a1 = result;
if ( (_BYTE)result )
{
result = 1LL;
do
{
v3 = a2[result];
a1[result++] = v3;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, unsigned __int8 *a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl

result = *a2;
*a1 = result;
if ( (_BYTE)result )
{
result = 1LL;
do
{
v3 = a2[result];
a1[result++] = v3;
}
while ( v3 );
}
return result;
}

original_code:
void copy(char to[], char from[])
{
    int i;
    for (i = 0; (to[i] = from[i]) != '\0'; i++)
      ;
}

variable_types:
to
char []

variable_types:
from
char []


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v4[1026]; // [rsp+0h] [rbp-418h] BYREF
char s[22]; // [rsp+402h] [rbp-16h] BYREF

strcpy(s, "Hello\tWorld!\n");
escape((__int64)v4, (unsigned __int8 *)s);
puts((const char *)v4);
unescape(s, v4);
puts(s);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v4[1026]; // [rsp+0h] [rbp-418h] BYREF
char s[22]; // [rsp+402h] [rbp-16h] BYREF

strcpy(s, "Hello\tWorld!\n");
func7((__int64)v4, (unsigned __int8 *)s);
puts((const char *)v4);
func8(s, v4);
puts(s);
return 0;
}

original_code:
int main(void)
{
 char t[] = "Hello\tWorld!\n";
 char s[1024];
 escape(s, t);
 printf("%s\n", s);
 unescape(t, s);
 printf("%s\n", t);
 return 0;
}

canonical_original_code:
int main()
{
 char t[] = "Hello\tWorld!\n";
 char s[1024];
 escape(s, t);
 printf("%s\n", s);
 unescape(t, s);
 printf("%s\n", t);
 return 0;
}


outputError

decompiled_code:
int __fastcall outputError(int a1, int a2, int a3, const char *a4, void *a5)
{
char *v6; // r8
const char *v7; // rcx
__int16 v9[256]; // [rsp+0h] [rbp-618h] BYREF
char s[512]; // [rsp+200h] [rbp-418h] BYREF
char v11[536]; // [rsp+400h] [rbp-218h] BYREF

vsnprintf(s, 0x1F4uLL, a4, a5);
if ( a1 )
{
v6 = strerror(a2);
v7 = "?UNKNOWN?";
if ( (unsigned int)(a2 - 1) <= 0x84 )
v7 = (const char *)*(&ename + a2);
snprintf((char *)v9, 0x1F4uLL, " [%s %s]", v7, v6);
}
else
{
v9[0] = 58;
}
snprintf(v11, 0x1F4uLL, "ERROR%s %s\n", (const char *)v9, s);
if ( a3 )
fflush(stdout);
fputs(v11, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3, const char *a4, void *a5)
{
char *v6; // r8
const char *v7; // rcx
__int16 v9[256]; // [rsp+0h] [rbp-618h] BYREF
char s[512]; // [rsp+200h] [rbp-418h] BYREF
char v11[536]; // [rsp+400h] [rbp-218h] BYREF

vsnprintf(s, 0x1F4uLL, a4, a5);
if ( a1 )
{
v6 = strerror(a2);
v7 = "?UNKNOWN?";
if ( (unsigned int)(a2 - 1) <= 0x84 )
v7 = (const char *)*(&ename + a2);
snprintf((char *)v9, 0x1F4uLL, " [%s %s]", v7, v6);
}
else
{
v9[0] = 58;
}
snprintf(v11, 0x1F4uLL, "ERROR%s %s\n", (const char *)v9, s);
if ( a3 )
fflush(stdout);
fputs(v11, stderr);
return fflush(stderr);
}

original_code:
static void
outputError(Boolean useErr, int err, Boolean flushStdout,
        const char *format, va_list ap)
{
    char buf[500], userMsg[500], errText[500];
    vsnprintf(userMsg, 500, format, ap);
    if (useErr)
        snprintf(errText, 500, " [%s %s]",
                (err > 0 && err <= 133) ?
                ename[err] : "?UNKNOWN?", strerror(err));
    else
        snprintf(errText, 500, ":");
    snprintf(buf, 500, "ERROR%s %s\n", errText, userMsg);
    if (flushStdout)
        fflush(stdout);
    fputs(buf, stderr);
    fflush(stderr);
}

canonical_original_code:
static void outputError(enum Boolean useErr, int err, enum Boolean flushStdout, char *format, __builtin_va_list ap)
{
    char buf[500]; char userMsg[500]; char errText[500];
    vsnprintf(userMsg, 500, format, ap);
    if (useErr)
        snprintf(errText, 500, " [%s %s]",
                (err > 0 && err <= 133) ?
                ename[err] : "?UNKNOWN?", strerror(err));
    else
        snprintf(errText, 500, ":");
    snprintf(buf, 500, "ERROR%s %s\n", errText, userMsg);
    if (flushStdout)
        fflush(stdout);
    fputs(buf, stderr);
    fflush(stderr);
}

variable_types:
useErr
enum Boolean { FALSE=0, TRUE=1 }

variable_types: err int

variable_types:
flushStdout
enum Boolean { FALSE=0, TRUE=1 }

variable_types:
format
char *

variable_types:
buf
char [500]

variable_types:
userMsg
char [500]

variable_types:
errText
char [500]


terminate

decompiled_code:
void __fastcall __noreturn terminate(int a1)
{
char *v1; // rax

v1 = getenv("EF_DUMPCORE");
if ( !v1 || !*v1 )
{
if ( a1 )
exit(1);
exit(1);
}
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int a1)
{
char *v1; // rax

v1 = getenv("EF_DUMPCORE");
if ( !v1 || !*v1 )
{
if ( a1 )
exit(1);
exit(1);
}
abort();
}

original_code:
__attribute__ ((__noreturn__))
static void
terminate(Boolean useExit3)
{
    char *s;
    s = getenv("EF_DUMPCORE");
    if (s != ((void *)0) && *s != '\0')
        abort();
    else if (useExit3)
        exit(1);
    else
        _exit(1);
}

canonical_original_code:
static void terminate(enum Boolean useExit3)
{
    char *s;
    s = getenv("EF_DUMPCORE");
    if (s != ((void *)0) && *s != '\0')
        abort();
    else if (useExit3)
        exit(1);
    else
        _exit(1);
}

variable_types:
s
char *


errMsg

decompiled_code:
int errMsg(const char *a1, ...)
{
int *v1; // rbx
int v2; // er12
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = _errno_location();
v2 = *v1;
result = outputError(1, *v1, 1, a1, va);
*v1 = v2;
return result;
}

canonical_decompiled_code:
int func2(const char *a1, ...)
{
int *v1; // rbx
int v2; // er12
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = _errno_location();
v2 = *v1;
result = func0(1, *v1, 1, a1, va);
*v1 = v2;
return result;
}

original_code:
void
errMsg(const char *format, ...)
{
    va_list argList;
    int savedErrno;
    savedErrno = (*__errno_location ());
    __builtin_va_start(argList,format);
    outputError(TRUE, (*__errno_location ()), TRUE, format, argList);
    __builtin_va_end(argList);
    (*__errno_location ()) = savedErrno;
}

canonical_original_code:
void errMsg(char *format, ...)
{
    __builtin_va_list argList;
    int savedErrno;
    savedErrno = (*__errno_location ());
    __builtin_va_start(argList,format);
    outputError(TRUE, (*__errno_location ()), TRUE, format, argList);
    __builtin_va_end(argList);
    (*__errno_location ()) = savedErrno;
}

variable_types: savedErrno int


errExit

decompiled_code:
void __noreturn errExit(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
outputError(1, *v1, 1, a1, va);
terminate(1);
}

canonical_decompiled_code:
void __noreturn func3(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, 1, a1, va);
func1(1);
}

original_code:
void
errExit(const char *format, ...)
{
    va_list argList;
    __builtin_va_start(argList,format);
    outputError(TRUE, (*__errno_location ()), TRUE, format, argList);
    __builtin_va_end(argList);
    terminate(TRUE);
}

canonical_original_code:
void errExit(char *format, ...)
{
    __builtin_va_list argList;
    __builtin_va_start(argList,format);
    outputError(TRUE, (*__errno_location ()), TRUE, format, argList);
    __builtin_va_end(argList);
    terminate(TRUE);
}


decompiled_code:
void __noreturn err_exit(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
outputError(1, *v1, 0, a1, va);
terminate(0);
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, 0, a1, va);
func1(0);
}

original_code:
void
err_exit(const char *format, ...)
{
    va_list argList;
    __builtin_va_start(argList,format);
    outputError(TRUE, (*__errno_location ()), FALSE, format, argList);
    __builtin_va_end(argList);
    terminate(FALSE);
}

canonical_original_code:
void err_exit(char *format, ...)
{
    __builtin_va_list argList;
    __builtin_va_start(argList,format);
    outputError(TRUE, (*__errno_location ()), FALSE, format, argList);
    __builtin_va_end(argList);
    terminate(FALSE);
}


fatal

decompiled_code:
void __noreturn fatal(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
outputError(0, 0, 1, a1, va);
terminate(1);
}

canonical_decompiled_code:
void __noreturn func5(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, 0, 1, a1, va);
func1(1);
}

original_code:
void
fatal(const char *format, ...)
{
    va_list argList;
    __builtin_va_start(argList,format);
    outputError(FALSE, 0, TRUE, format, argList);
    __builtin_va_end(argList);
    terminate(TRUE);
}

canonical_original_code:
void fatal(char *format, ...)
{
    __builtin_va_list argList;
    __builtin_va_start(argList,format);
    outputError(FALSE, 0, TRUE, format, argList);
    __builtin_va_end(argList);
    terminate(TRUE);
}


usageErr

decompiled_code:
void __noreturn usageErr(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fflush(stdout);
fwrite("Usage: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func6(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fflush(stdout);
fwrite("Usage: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

original_code:
void
usageErr(const char *format, ...)
{
    va_list argList;
    fflush(stdout);
    fprintf(stderr, "Usage: ");
    __builtin_va_start(argList,format);
    vfprintf(stderr, format, argList);
    __builtin_va_end(argList);
    fflush(stderr);
    exit(1);
}

canonical_original_code:
void usageErr(char *format, ...)
{
    __builtin_va_list argList;
    fflush(stdout);
    fprintf(stderr, "Usage: ");
    __builtin_va_start(argList,format);
    vfprintf(stderr, format, argList);
    __builtin_va_end(argList);
    fflush(stderr);
    exit(1);
}


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

if ( signal(2, (__sighandler_t)((char *)init_shell + 1)) == (__sighandler_t)-1LL )
{
errExit("signal");
result = teardown_job();
}
else
{
puts("Tiny Shell v1.0 Created by Yanzhe Chen, 2013.03");
puts("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>");
puts("This is free software: you are free to change and redistribute it.");
puts("There is NO WARRANTY, to the extent permitted by law.");
result = puts("For bug reporting, please email: <0x2fdev0x2fnull@gmail.com>");
}
return result;
}

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

if ( signal(2, (__sighandler_t)((char *)init_shell + 1)) == (__sighandler_t)-1LL )
{
errExit("signal");
result = func1();
}
else
{
puts("Tiny Shell v1.0 Created by Yanzhe Chen, 2013.03");
puts("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>");
puts("This is free software: you are free to change and redistribute it.");
puts("There is NO WARRANTY, to the extent permitted by law.");
result = puts("For bug reporting, please email: <0x2fdev0x2fnull@gmail.com>");
}
return result;
}

original_code:
void init_shell(void)
{
    if (signal(2, ((__sighandler_t) 1)) == ((__sighandler_t) -1))
        errExit("signal");
    printf("Tiny Shell v1.0 Created by Yanzhe Chen, 2013.03\n");
    printf("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
    printf("This is free software: you are free to change and redistribute it.\n");
    printf("There is NO WARRANTY, to the extent permitted by law.\n");
    printf("For bug reporting, please email: <0x2fdev0x2fnull@gmail.com>\n");
}

canonical_original_code:
void init_shell()
{
    if (signal(2, ((void (*)(int)) 1)) == ((__sighandler_t) -1))
        errExit("signal");
    printf("Tiny Shell v1.0 Created by Yanzhe Chen, 2013.03\n");
    printf("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
    printf("This is free software: you are free to change and redistribute it.\n");
    printf("There is NO WARRANTY, to the extent permitted by law.\n");
    printf("For bug reporting, please email: <0x2fdev0x2fnull@gmail.com>\n");
}


original_code:
void teardown_job(void)
{
    if (j != ((void *)0))
    {
        if (j->cmd != ((void *)0))
            free(j->cmd);
        process *p;
        while (!(((&j->head)->sqh_first) == ((void *)0)))
        {
            p = ((&j->head)->sqh_first);
            do { if (((&j->head)->sqh_first = (&j->head)->sqh_first->next.sqe_next) == ((void *)0)) (&j->head)->sqh_last = &(&j->head)->sqh_first; } while (0);
            free(p->argv);
            free(p);
        }
        free(j);
    }
}

canonical_original_code:
void teardown_job()
{
    if (j != ((void *)0))
    {
        if (j->cmd != ((void *)0))
            free(j->cmd);
        struct process *p;
        while (!(((&j->head)->sqh_first) == ((void *)0)))
        {
            p = ((&j->head)->sqh_first);
            do { if (((&j->head)->sqh_first = (&j->head)->sqh_first->next.sqe_next) == ((void *)0)) (&j->head)->sqh_last = &(&j->head)->sqh_first; } while (0);
            free(p->argv);
            free(p);
        }
        free(j);
    }
}

variable_types: struct process { char **argv; struct { struct process *sqe_next; } next; } *


decompiled_code:
__int64 __fastcall launch_process(const char ***a1, int a2, int a3)
{
if ( a2 )
goto LABEL_5;
while ( a3 != 1 )
{
a2 = 1;
if ( dup2(a3, 1) == 1 )
{
close(a3);
break;
}
errExit("dup2");
LABEL_5:
if ( dup2(a2, 0) )
errExit("dup2");
close(a2);
}
execvp(**a1, (char *const *)*a1);
errExit("execvp");
return launch_job();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char ***a1, int a2, int a3)
{
if ( a2 )
goto LABEL_5;
while ( a3 != 1 )
{
a2 = 1;
if ( dup2(a3, 1) == 1 )
{
close(a3);
break;
}
errExit("dup2");
LABEL_5:
if ( dup2(a2, 0) )
errExit("dup2");
close(a2);
}
execvp(**a1, (char *const *)*a1);
errExit("execvp");
return func3();
}

original_code:
void launch_process(process *p, int infile, int outfile, int bg)
{
    if (infile != 0)
    {
        if (dup2(infile, 0) != 0)
            errExit("dup2");
        close(infile);
    }
    if (outfile != 1)
    {
        if (dup2(outfile, 1) != 1)
            errExit("dup2");
        close(outfile);
    }
    execvp(p->argv[0], p->argv);
    errExit("execvp");
}

canonical_original_code:
void launch_process(struct process *p, int infile, int outfile, int bg)
{
    if (infile != 0)
    {
        if (dup2(infile, 0) != 0)
            errExit("dup2");
        close(infile);
    }
    if (outfile != 1)
    {
        if (dup2(outfile, 1) != 1)
            errExit("dup2");
        close(outfile);
    }
    execvp(p->argv[0], p->argv);
    errExit("execvp");
}

variable_types: infile int

variable_types: outfile int

variable_types: bg int

user_defined_types: struct process { char **argv; struct { struct process *sqe_next; } next; }


decompiled_code:
__pid_t __fastcall launch_job(int a1)
{
__pid_t result; // eax
int v2; // er12
__int64 v3; // rbx
int v4; // ebp
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

result = (int)j;
v2 = *((_DWORD *)j + 6);
v3 = *((_QWORD *)j + 1);
if ( v3 )
{
while ( 1 )
{
if ( !*(_QWORD *)(v3 + 8) )
goto LABEL_4;
if ( pipe(pipedes) == -1 )
break;
v4 = pipedes[1];
LABEL_14:
result = fork();
if ( result == -1 )
{
errExit("fork");
LABEL_6:
result = launch_process((const char ***)v3, v2, v4);
goto LABEL_7;
}
if ( !result )
goto LABEL_6;
if ( a1 )
{
LABEL_17:
if ( !v2 )
goto LABEL_18;
goto LABEL_9;
}
LABEL_7:
result = waitpid(result, 0LL, 0);
if ( result != -1 )
goto LABEL_17;
errExit("waitpid");
LABEL_9:
result = close(v2);
LABEL_18:
if ( v4 != 1 )
result = close(v4);
v2 = pipedes[0];
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
return result;
}
errExit("pipe");
LABEL_4:
v4 = *((_DWORD *)j + 7);
goto LABEL_14;
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func3(int a1)
{
__pid_t result; // eax
int v2; // er12
__int64 v3; // rbx
int v4; // ebp
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

result = (int)j;
v2 = *((_DWORD *)j + 6);
v3 = *((_QWORD *)j + 1);
if ( v3 )
{
while ( 1 )
{
if ( !*(_QWORD *)(v3 + 8) )
goto LABEL_4;
if ( pipe(pipedes) == -1 )
break;
v4 = pipedes[1];
LABEL_14:
result = fork();
if ( result == -1 )
{
errExit("fork");
LABEL_6:
result = func2((const char ***)v3, v2, v4);
goto LABEL_7;
}
if ( !result )
goto LABEL_6;
if ( a1 )
{
LABEL_17:
if ( !v2 )
goto LABEL_18;
goto LABEL_9;
}
LABEL_7:
result = waitpid(result, 0LL, 0);
if ( result != -1 )
goto LABEL_17;
errExit("waitpid");
LABEL_9:
result = close(v2);
LABEL_18:
if ( v4 != 1 )
result = close(v4);
v2 = pipedes[0];
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
return result;
}
errExit("pipe");
LABEL_4:
v4 = *((_DWORD *)j + 7);
goto LABEL_14;
}
return result;
}

original_code:
void launch_job(int bg)
{
    process *p;
    pid_t pid;
    int mypipe[2], infile, outfile;
    infile = j->in;
    for((p) = ((&j->head)->sqh_first); (p) != ((void *)0); (p) = ((p)->next.sqe_next))
    {
        if (((p)->next.sqe_next))
        {
            if (pipe(mypipe) == -1)
                errExit("pipe");
            outfile = mypipe[1];
        }
        else
            outfile = j->out;
        switch(pid = fork())
        {
        case -1:
            errExit("fork");
        case 0:
            launch_process(p, infile, outfile, bg);
            break;
        default:
            if (!bg)
                if (waitpid(pid, ((void *)0), 0) == -1)
                    errExit("waitpid");
            break;
        }
        if (infile != 0)
            close(infile);
        if (outfile != 1)
            close(outfile);
        infile = mypipe[0];
    }
}

canonical_original_code:
void launch_job(int bg)
{
    struct process *p;
    int pid;
    int mypipe[2]; int infile; int outfile;
    infile = j->in;
    for((p) = ((&j->head)->sqh_first); (p) != ((void *)0); (p) = ((p)->next.sqe_next))
    {
        if (((p)->next.sqe_next))
        {
            if (pipe(mypipe) == -1)
                errExit("pipe");
            outfile = mypipe[1];
        }
        else
            outfile = j->out;
        switch(pid = fork())
        {
        case -1:
            errExit("fork");
        case 0:
            launch_process(p, infile, outfile, bg);
            break;
        default:
            if (!bg)
                if (waitpid(pid, ((void *)0), 0) == -1)
                    errExit("waitpid");
            break;
        }
        if (infile != 0)
            close(infile);
        if (outfile != 1)
            close(outfile);
        infile = mypipe[0];
    }
}

variable_types: pid int

variable_types:
mypipe
int [2]


decompiled_code:
__int64 __fastcall create_process(char *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r13
void **v3; // r14
unsigned __int64 v4; // r15
char *v5; // rbx
void **v6; // rax
_QWORD *v7; // rax
_BYTE *v9; // rbp
const unsigned __int16 *v10; // rdx
const unsigned __int16 *v11; // rdx
_QWORD *v12; // rax

v5 = a1;
v6 = (void **)malloc(0x10uLL);
if ( !v6 )
{
errExit("malloc");
goto LABEL_7;
}
v3 = v6;
v7 = malloc(0x48uLL);
*v3 = v7;
if ( !v7 )
{
LABEL_7:
errExit("malloc");
goto LABEL_8;
}
v7[8] = 0LL;
v4 = 8LL;
v2 = 0LL;
if ( (unsigned __int64)a1 >= a2 )
{
*v7 = 0LL;
LABEL_5:
free(*v3);
free(v3);
return 0xFFFFFFFFLL;
}
do
{
if ( a2 <= (unsigned __int64)v5 )
{
LABEL_17:
v9 = v5 + 1;
if ( a2 <= (unsigned __int64)(v5 + 1) )
goto LABEL_12;
}
else
{
v10 = *_ctype_b_loc();
while ( (v10[*v5] & 0x2000) != 0 )
{
if ( (char *)a2 == ++v5 )
goto LABEL_17;
}
LABEL_8:
v9 = v5 + 1;
if ( a2 <= (unsigned __int64)(v5 + 1) )
goto LABEL_21;
}
v11 = *_ctype_b_loc();
do
{
if ( (v11[(char)*v9] & 0x2000) != 0 )
break;
++v9;
}
while ( a2 > (unsigned __int64)v9 );
LABEL_21:
if ( a2 > (unsigned __int64)v5 )
{
if ( v2 >= v4 )
{
v12 = realloc(*v3, 16 * v4 + 8);
*v3 = v12;
if ( v12 )
{
v12[2 * v4] = 0LL;
v4 *= 2LL;
}
else
{
errExit("malloc");
}
}
*((_QWORD *)*v3 + v2) = v5;
*v9 = 0;
++v2;
}
LABEL_12:
v5 = v9 + 1;
}
while ( a2 > (unsigned __int64)(v9 + 1) );
*((_QWORD *)*v3 + v2) = 0LL;
if ( !v2 )
goto LABEL_5;
v3[1] = 0LL;
**((_QWORD **)j + 2) = v3;
*((_QWORD *)j + 2) = v3 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r13
void **v3; // r14
unsigned __int64 v4; // r15
char *v5; // rbx
void **v6; // rax
_QWORD *v7; // rax
_BYTE *v9; // rbp
const unsigned __int16 *v10; // rdx
const unsigned __int16 *v11; // rdx
_QWORD *v12; // rax

v5 = a1;
v6 = (void **)malloc(0x10uLL);
if ( !v6 )
{
errExit("malloc");
goto LABEL_7;
}
v3 = v6;
v7 = malloc(0x48uLL);
*v3 = v7;
if ( !v7 )
{
LABEL_7:
errExit("malloc");
goto LABEL_8;
}
v7[8] = 0LL;
v4 = 8LL;
v2 = 0LL;
if ( (unsigned __int64)a1 >= a2 )
{
*v7 = 0LL;
LABEL_5:
free(*v3);
free(v3);
return 0xFFFFFFFFLL;
}
do
{
if ( a2 <= (unsigned __int64)v5 )
{
LABEL_17:
v9 = v5 + 1;
if ( a2 <= (unsigned __int64)(v5 + 1) )
goto LABEL_12;
}
else
{
v10 = *_ctype_b_loc();
while ( (v10[*v5] & 0x2000) != 0 )
{
if ( (char *)a2 == ++v5 )
goto LABEL_17;
}
LABEL_8:
v9 = v5 + 1;
if ( a2 <= (unsigned __int64)(v5 + 1) )
goto LABEL_21;
}
v11 = *_ctype_b_loc();
do
{
if ( (v11[(char)*v9] & 0x2000) != 0 )
break;
++v9;
}
while ( a2 > (unsigned __int64)v9 );
LABEL_21:
if ( a2 > (unsigned __int64)v5 )
{
if ( v2 >= v4 )
{
v12 = realloc(*v3, 16 * v4 + 8);
*v3 = v12;
if ( v12 )
{
v12[2 * v4] = 0LL;
v4 *= 2LL;
}
else
{
errExit("malloc");
}
}
*((_QWORD *)*v3 + v2) = v5;
*v9 = 0;
++v2;
}
LABEL_12:
v5 = v9 + 1;
}
while ( a2 > (unsigned __int64)(v9 + 1) );
*((_QWORD *)*v3 + v2) = 0LL;
if ( !v2 )
goto LABEL_5;
v3[1] = 0LL;
**((_QWORD **)j + 2) = v3;
*((_QWORD *)j + 2) = v3 + 1;
return 0LL;
}

original_code:
int create_process(char *sp, char *ep)
{
    char *sa, *ea;
    process *p;
    size_t argc, size;
    sa = sp;
    ea = ((void *)0);
    argc = 0;
    size = 8;
    if ((p = (process *) malloc(sizeof(process))) == ((void *)0))
        errExit("malloc");
    if ((p->argv = (char **) malloc((size + 1) * sizeof(char *))) == ((void *)0))
        errExit("malloc");
    p->argv[size] = ((void *)0);
    while (sa < ep)
    {
        while (sa < ep && ((*__ctype_b_loc ())[(int) ((*sa))] & (unsigned short int) _ISspace))
            sa++;
        for (ea = sa + 1; ea < ep && !((*__ctype_b_loc ())[(int) ((*ea))] & (unsigned short int) _ISspace); ea++)
            ;
        if (sa < ep)
        {
            if (argc >= size)
            {
                size *= 2;
                p->argv = (char **) realloc(p->argv, (size + 1) * sizeof(char *));
                if (p->argv == ((void *)0))
                    errExit("malloc");
                p->argv[size] = ((void *)0);
            }
            p->argv[argc++] = sa;
            *ea = '\0';
        }
        sa = ea + 1;
    }
    p->argv[argc] = ((void *)0);
    if (argc == 0)
    {
        free(p->argv);
        free(p);
        return -1;
    }
    else
        do { (p)->next.sqe_next = ((void *)0); *(&j->head)->sqh_last = (p); (&j->head)->sqh_last = &(p)->next.sqe_next; } while (0);
    return 0;
}

canonical_original_code:
int create_process(char *sp, char *ep)
{
    char *sa; char *ea;
    struct process *p;
    unsigned long argc; unsigned long size;
    sa = sp;
    ea = ((void *)0);
    argc = 0;
    size = 8;
    if ((p = (struct process *) malloc(sizeof(process))) == ((void *)0))
        errExit("malloc");
    if ((p->argv = (char **) malloc((size + 1) * sizeof(char *))) == ((void *)0))
        errExit("malloc");
    p->argv[size] = ((void *)0);
    while (sa < ep)
    {
        while (sa < ep && ((*__ctype_b_loc ())[(int) ((*sa))] & (unsigned short) _ISspace))
            sa++;
        for (ea = sa + 1; ea < ep && !((*__ctype_b_loc ())[(int) ((*ea))] & (unsigned short) _ISspace); ea++)
            ;
        if (sa < ep)
        {
            if (argc >= size)
            {
                size *= 2;
                p->argv = (char **) realloc(p->argv, (size + 1) * sizeof(char *));
                if (p->argv == ((void *)0))
                    errExit("malloc");
                p->argv[size] = ((void *)0);
            }
            p->argv[argc++] = sa;
            *ea = '\0';
        }
        sa = ea + 1;
    }
    p->argv[argc] = ((void *)0);
    if (argc == 0)
    {
        free(p->argv);
        free(p);
        return -1;
    }
    else
        do { (p)->next.sqe_next = ((void *)0); *(&j->head)->sqh_last = (p); (&j->head)->sqh_last = &(p)->next.sqe_next; } while (0);
    return 0;
}

variable_types:
sp
char *

variable_types:
ep
char *

variable_types:
sa
char *

variable_types:
ea
char *

variable_types:
argc
unsigned long

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall create_job()
{
__ssize_t v0; // rbp
_DWORD *v1; // r14
char *v2; // rax
const char *v3; // rbx
char *v4; // r13
char *v5; // r12
char *v6; // rbx
const unsigned __int16 *v7; // rdx
char *v8; // rbx
char v9; // al
char *v10; // r12
char *v11; // rax
char *v12; // rax
char *v13; // rax
char *v14; // r12
char *v15; // r13
const char *v16; // r14
char v17; // r15
const unsigned __int16 *v18; // rdx
char v19; // al
char *v20; // r13
char *v21; // r15
_DWORD *v22; // r14
int v23; // eax
const char *v24; // r14
char v25; // r15
const unsigned __int16 *v26; // rdx
char v27; // al
char *v28; // r15
_DWORD *v29; // r14
int v30; // eax
size_t v32; // rax
size_t v33; // [rsp+8h] [rbp-50h]
size_t v34; // [rsp+8h] [rbp-50h]
size_t n[8]; // [rsp+18h] [rbp-40h] BYREF

n[0] = 0LL;
v2 = (char *)malloc(0x28uLL);
j = v2;
if ( !v2 )
{
errExit("malloc");
goto LABEL_23;
}
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = v2 + 8;
*((_DWORD *)v2 + 6) = 0;
*((_DWORD *)v2 + 7) = 1;
v0 = getline((char **)v2, n, stdin);
if ( v0 == -1 )
{
LABEL_23:
fatal("getline");
LABEL_24:
v1[8] = 0;
goto LABEL_11;
}
v1 = j;
v3 = *(const char **)j;
if ( **(_BYTE **)j == 10 )
{
LODWORD(v15) = -1;
return (unsigned int)v15;
}
v4 = strrchr(*(const char **)j, 38);
if ( !v4 )
goto LABEL_24;
v5 = strchr(v3, 10);
v6 = v4 + 1;
if ( v5 > v4 + 1 )
{
v7 = *_ctype_b_loc();
do
{
if ( (v7[*v6] & 0x2000) == 0 )
break;
++v6;
}
while ( v5 != v6 );
}
v1[8] = v5 == v6;
if ( v5 == v6 )
*v4 = 0;
LABEL_11:
v8 = *(char **)j;
v9 = **(_BYTE **)j;
if ( v9 == 99 )
{
if ( v8[1] != 100 || ((*_ctype_b_loc())[v8[2]] & 0x2000) == 0 )
goto LABEL_13;
v8[v0 - 1] = 0;
if ( chdir((const char *)(*(_QWORD *)j + 3LL)) != -1 )
{
LODWORD(v15) = -1;
return (unsigned int)v15;
}
errExit("chdir");
}
else if ( v9 != 113 )
{
goto LABEL_13;
}
if ( ((*_ctype_b_loc())[v8[1]] & 0x2000) != 0 )
{
LODWORD(v15) = 1;
return (unsigned int)v15;
}
LABEL_13:
v10 = strchr(v8, 60);
if ( v10 )
{
v11 = strchr(v8, 124);
if ( !v11 || v10 < v11 )
{
v16 = v10 + 1;
v17 = v10[1];
if ( !v17 )
{
LABEL_36:
errMsg("missing filename after '<'");
LODWORD(v15) = -1;
return (unsigned int)v15;
}
v18 = *_ctype_b_loc();
while ( (v18[v17] & 0x2000) != 0 )
{
v17 = *++v16;
if ( !*v16 )
goto LABEL_36;
}
v19 = *v16;
if ( *v16 )
{
v20 = (char *)v16;
do
{
if ( (v18[v19] & 0x2000) != 0 )
break;
v19 = *++v20;
}
while ( *v20 );
}
else
{
v20 = (char *)v16;
}
n[0] = v20 - v16;
v21 = (char *)malloc(v20 - v16 + 1);
if ( !v21 )
errMsg("malloc");
v33 = n[0];
strncpy(v21, v16, n[0]);
v21[v33] = 0;
v22 = j;
v23 = open(v21, 0);
v22[6] = v23;
if ( v23 == -1 )
{
errExit("open");
goto LABEL_49;
}
free(v21);
if ( v10 < v20 )
{
do
*v10++ = 32;
while ( v10 != v20 );
}
}
}
v10 = strchr(v8, 62);
if ( !v10 )
goto LABEL_19;
v12 = strrchr(v8, 124);
if ( v12 )
{
if ( v10 <= v12 )
goto LABEL_19;
}
LABEL_49:
v24 = v10 + 1;
v25 = v10[1];
if ( v25 )
{
v26 = *_ctype_b_loc();
while ( (v26[v25] & 0x2000) != 0 )
{
v25 = *++v24;
if ( !*v24 )
goto LABEL_53;
}
v27 = *v24;
if ( *v24 )
{
v15 = (char *)v24;
do
{
if ( (v26[v27] & 0x2000) != 0 )
break;
v27 = *++v15;
}
while ( *v15 );
}
else
{
v15 = (char *)v24;
}
n[0] = v15 - v24;
v28 = (char *)malloc(v15 - v24 + 1);
if ( !v28 )
errMsg("malloc");
v34 = n[0];
strncpy(v28, v24, n[0]);
v28[v34] = 0;
v29 = j;
v30 = open(v28, 577, 432LL);
v29[7] = v30;
if ( v30 == -1 )
{
errExit("open");
LABEL_66:
errMsg("empty pipeline");
}
else
{
free(v28);
if ( v10 < v15 )
{
do
*v10++ = 32;
while ( v10 != v15 );
}
LABEL_19:
while ( 1 )
{
v13 = strchr(v8, 124);
v14 = v13;
if ( !v13 )
break;
LODWORD(v15) = create_process(v8, (unsigned __int64)v13);
if ( (_DWORD)v15 == -1 )
goto LABEL_66;
v0 -= v14 - v8 + 1;
v8 = v14 + 1;
}
LODWORD(v15) = 0;
if ( v0 > 0 )
{
v32 = strlen(v8);
LODWORD(v15) = create_process(v8, (unsigned __int64)&v8[v32]);
if ( (_DWORD)v15 == -1 )
errMsg("empty command");
else
LODWORD(v15) = 0;
}
}
}
else
{
LABEL_53:
errMsg("missing filename after '>'");
LODWORD(v15) = -1;
}
return (unsigned int)v15;
}

canonical_decompiled_code:
__int64 __fastcall func5()
{
__ssize_t v0; // rbp
_DWORD *v1; // r14
char *v2; // rax
const char *v3; // rbx
char *v4; // r13
char *v5; // r12
char *v6; // rbx
const unsigned __int16 *v7; // rdx
char *v8; // rbx
char v9; // al
char *v10; // r12
char *v11; // rax
char *v12; // rax
char *v13; // rax
char *v14; // r12
char *v15; // r13
const char *v16; // r14
char v17; // r15
const unsigned __int16 *v18; // rdx
char v19; // al
char *v20; // r13
char *v21; // r15
_DWORD *v22; // r14
int v23; // eax
const char *v24; // r14
char v25; // r15
const unsigned __int16 *v26; // rdx
char v27; // al
char *v28; // r15
_DWORD *v29; // r14
int v30; // eax
size_t v32; // rax
size_t v33; // [rsp+8h] [rbp-50h]
size_t v34; // [rsp+8h] [rbp-50h]
size_t n[8]; // [rsp+18h] [rbp-40h] BYREF

n[0] = 0LL;
v2 = (char *)malloc(0x28uLL);
j = v2;
if ( !v2 )
{
errExit("malloc");
goto LABEL_23;
}
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = v2 + 8;
*((_DWORD *)v2 + 6) = 0;
*((_DWORD *)v2 + 7) = 1;
v0 = getline((char **)v2, n, stdin);
if ( v0 == -1 )
{
LABEL_23:
fatal("getline");
LABEL_24:
v1[8] = 0;
goto LABEL_11;
}
v1 = j;
v3 = *(const char **)j;
if ( **(_BYTE **)j == 10 )
{
LODWORD(v15) = -1;
return (unsigned int)v15;
}
v4 = strrchr(*(const char **)j, 38);
if ( !v4 )
goto LABEL_24;
v5 = strchr(v3, 10);
v6 = v4 + 1;
if ( v5 > v4 + 1 )
{
v7 = *_ctype_b_loc();
do
{
if ( (v7[*v6] & 0x2000) == 0 )
break;
++v6;
}
while ( v5 != v6 );
}
v1[8] = v5 == v6;
if ( v5 == v6 )
*v4 = 0;
LABEL_11:
v8 = *(char **)j;
v9 = **(_BYTE **)j;
if ( v9 == 99 )
{
if ( v8[1] != 100 || ((*_ctype_b_loc())[v8[2]] & 0x2000) == 0 )
goto LABEL_13;
v8[v0 - 1] = 0;
if ( chdir((const char *)(*(_QWORD *)j + 3LL)) != -1 )
{
LODWORD(v15) = -1;
return (unsigned int)v15;
}
errExit("chdir");
}
else if ( v9 != 113 )
{
goto LABEL_13;
}
if ( ((*_ctype_b_loc())[v8[1]] & 0x2000) != 0 )
{
LODWORD(v15) = 1;
return (unsigned int)v15;
}
LABEL_13:
v10 = strchr(v8, 60);
if ( v10 )
{
v11 = strchr(v8, 124);
if ( !v11 || v10 < v11 )
{
v16 = v10 + 1;
v17 = v10[1];
if ( !v17 )
{
LABEL_36:
errMsg("missing filename after '<'");
LODWORD(v15) = -1;
return (unsigned int)v15;
}
v18 = *_ctype_b_loc();
while ( (v18[v17] & 0x2000) != 0 )
{
v17 = *++v16;
if ( !*v16 )
goto LABEL_36;
}
v19 = *v16;
if ( *v16 )
{
v20 = (char *)v16;
do
{
if ( (v18[v19] & 0x2000) != 0 )
break;
v19 = *++v20;
}
while ( *v20 );
}
else
{
v20 = (char *)v16;
}
n[0] = v20 - v16;
v21 = (char *)malloc(v20 - v16 + 1);
if ( !v21 )
errMsg("malloc");
v33 = n[0];
strncpy(v21, v16, n[0]);
v21[v33] = 0;
v22 = j;
v23 = open(v21, 0);
v22[6] = v23;
if ( v23 == -1 )
{
errExit("open");
goto LABEL_49;
}
free(v21);
if ( v10 < v20 )
{
do
*v10++ = 32;
while ( v10 != v20 );
}
}
}
v10 = strchr(v8, 62);
if ( !v10 )
goto LABEL_19;
v12 = strrchr(v8, 124);
if ( v12 )
{
if ( v10 <= v12 )
goto LABEL_19;
}
LABEL_49:
v24 = v10 + 1;
v25 = v10[1];
if ( v25 )
{
v26 = *_ctype_b_loc();
while ( (v26[v25] & 0x2000) != 0 )
{
v25 = *++v24;
if ( !*v24 )
goto LABEL_53;
}
v27 = *v24;
if ( *v24 )
{
v15 = (char *)v24;
do
{
if ( (v26[v27] & 0x2000) != 0 )
break;
v27 = *++v15;
}
while ( *v15 );
}
else
{
v15 = (char *)v24;
}
n[0] = v15 - v24;
v28 = (char *)malloc(v15 - v24 + 1);
if ( !v28 )
errMsg("malloc");
v34 = n[0];
strncpy(v28, v24, n[0]);
v28[v34] = 0;
v29 = j;
v30 = open(v28, 577, 432LL);
v29[7] = v30;
if ( v30 == -1 )
{
errExit("open");
LABEL_66:
errMsg("empty pipeline");
}
else
{
free(v28);
if ( v10 < v15 )
{
do
*v10++ = 32;
while ( v10 != v15 );
}
LABEL_19:
while ( 1 )
{
v13 = strchr(v8, 124);
v14 = v13;
if ( !v13 )
break;
LODWORD(v15) = func4(v8, (unsigned __int64)v13);
if ( (_DWORD)v15 == -1 )
goto LABEL_66;
v0 -= v14 - v8 + 1;
v8 = v14 + 1;
}
LODWORD(v15) = 0;
if ( v0 > 0 )
{
v32 = strlen(v8);
LODWORD(v15) = func4(v8, (unsigned __int64)&v8[v32]);
if ( (_DWORD)v15 == -1 )
errMsg("empty command");
else
LODWORD(v15) = 0;
}
}
}
else
{
LABEL_53:
errMsg("missing filename after '>'");
LODWORD(v15) = -1;
}
return (unsigned int)v15;
}

original_code:
int create_job(void)
{
    size_t len = 0;
    ssize_t read;
    char *sp, *ep;
    char *r, *f, *sf, *ef;
    j = (job *) malloc(sizeof(job));
    if (j == ((void *)0))
        errExit("malloc");
    do { (&j->head)->sqh_first = ((void *)0); (&j->head)->sqh_last = &(&j->head)->sqh_first; } while (0);
    j->in = 0;
    j->out = 1;
    if ((read = getline(&j->cmd, &len, stdin)) == -1)
        fatal("getline");
    if (j->cmd[0] == '\n')
        return -1;
    sp = strrchr(j->cmd, '&');
    ep = strchr(j->cmd, '\n');
    if (sp)
    {
        for (r = sp + 1; r < ep; r++)
            if (!((*__ctype_b_loc ())[(int) ((*r))] & (unsigned short int) _ISspace))
                break;
        j->bg = (r == ep) ? 1 : 0;
    }
    else
        j->bg = 0;
    if (j->bg)
        *sp = '\0';
    if (j->cmd[0] == 'c' && j->cmd[1] == 'd' && ((*__ctype_b_loc ())[(int) ((j->cmd[2]))] & (unsigned short int) _ISspace))
    {
        j->cmd[read-1] = '\0';
        if (chdir(j->cmd+3) == -1)
            errExit("chdir");
        return -1;
    }
    if (j->cmd[0] == 'q' && ((*__ctype_b_loc ())[(int) ((j->cmd[1]))] & (unsigned short int) _ISspace))
        return 1;
    sp = j->cmd;
    ep = ((void *)0);
    r = sf = ef = ((void *)0);
    r = strchr(sp, '<');
    ep = strchr(sp, '|');
    if (r && (!ep || r < ep))
    {
        for (sf = r + 1; *sf != '\0' && ((*__ctype_b_loc ())[(int) ((*sf))] & (unsigned short int) _ISspace); sf++)
            ;
        for (ef = sf; *ef != '\0' && !((*__ctype_b_loc ())[(int) ((*ef))] & (unsigned short int) _ISspace); ef++)
            ;
        if (*sf == '\0')
        {
            errMsg("missing filename after '<'");
            return -1;
        }
        len = ef - sf;
        f = (char *) malloc((len + 1) * sizeof(char));
        if (f == ((void *)0))
            errMsg("malloc");
        strncpy(f, sf, len);
        f[len] = '\0';
        if ((j->in = open(f, 00)) == -1)
            errExit("open");
        free(f);
        for(; r < ef; r++)
            *r = ' ';
    }
    r = strchr(sp, '>');
    ep = strrchr(sp, '|');
    if (r && (!ep || ep < r))
    {
        for (sf = r + 1; *sf != '\0' && ((*__ctype_b_loc ())[(int) ((*sf))] & (unsigned short int) _ISspace); sf++)
            ;
        for (ef = sf; *ef != '\0' && !((*__ctype_b_loc ())[(int) ((*ef))] & (unsigned short int) _ISspace); ef++)
            ;
        if (*sf == '\0')
        {
            errMsg("missing filename after '>'");
            return -1;
        }
        len = ef - sf;
        f = (char *) malloc((len + 1) * sizeof(char));
        if (f == ((void *)0))
            errMsg("malloc");
        strncpy(f, sf, len);
        f[len] = '\0';
        if ((j->out = open(f, 01 | 01000 | 0100,
                    0400 | (0400 >> 3) | (0200 >> 3) | 0200)) == -1)
            errExit("open");
        free(f);
        for(; r < ef; r++)
            *r = ' ';
    }
    while ((ep = strchr(sp, '|')) != ((void *)0))
    {
        if (create_process(sp, ep) == -1)
        {
            errMsg("empty pipeline");
            return -1;
        }
        else
        {
            read -= ep - sp + 1;
            sp = ep + 1;
        }
    }
    if (read > 0)
    {
        if (create_process(sp, sp + strlen(sp)) == -1)
        {
            errMsg("empty command");
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int create_job()
{
    unsigned long len = 0;
    long read;
    char *sp; char *ep;
    char *r; char *f; char *sf; char *ef;
    j = (struct job *) malloc(sizeof(job));
    if (j == ((void *)0))
        errExit("malloc");
    do { (&j->head)->sqh_first = ((void *)0); (&j->head)->sqh_last = &(&j->head)->sqh_first; } while (0);
    j->in = 0;
    j->out = 1;
    if ((read = getline(&j->cmd, &len, stdin)) == -1)
        fatal("getline");
    if (j->cmd[0] == '\n')
        return -1;
    sp = strrchr(j->cmd, '&');
    ep = strchr(j->cmd, '\n');
    if (sp)
    {
        for (r = sp + 1; r < ep; r++)
            if (!((*__ctype_b_loc ())[(int) ((*r))] & (unsigned short) _ISspace))
                break;
        j->bg = (r == ep) ? 1 : 0;
    }
    else
        j->bg = 0;
    if (j->bg)
        *sp = '\0';
    if (j->cmd[0] == 'c' && j->cmd[1] == 'd' && ((*__ctype_b_loc ())[(int) ((j->cmd[2]))] & (unsigned short) _ISspace))
    {
        j->cmd[read-1] = '\0';
        if (chdir(j->cmd+3) == -1)
            errExit("chdir");
        return -1;
    }
    if (j->cmd[0] == 'q' && ((*__ctype_b_loc ())[(int) ((j->cmd[1]))] & (unsigned short) _ISspace))
        return 1;
    sp = j->cmd;
    ep = ((void *)0);
    r = sf = ef = ((void *)0);
    r = strchr(sp, '<');
    ep = strchr(sp, '|');
    if (r && (!ep || r < ep))
    {
        for (sf = r + 1; *sf != '\0' && ((*__ctype_b_loc ())[(int) ((*sf))] & (unsigned short) _ISspace); sf++)
            ;
        for (ef = sf; *ef != '\0' && !((*__ctype_b_loc ())[(int) ((*ef))] & (unsigned short) _ISspace); ef++)
            ;
        if (*sf == '\0')
        {
            errMsg("missing filename after '<'");
            return -1;
        }
        len = ef - sf;
        f = (char *) malloc((len + 1) * sizeof(char));
        if (f == ((void *)0))
            errMsg("malloc");
        strncpy(f, sf, len);
        f[len] = '\0';
        if ((j->in = open(f, 00)) == -1)
            errExit("open");
        free(f);
        for(; r < ef; r++)
            *r = ' ';
    }
    r = strchr(sp, '>');
    ep = strrchr(sp, '|');
    if (r && (!ep || ep < r))
    {
        for (sf = r + 1; *sf != '\0' && ((*__ctype_b_loc ())[(int) ((*sf))] & (unsigned short) _ISspace); sf++)
            ;
        for (ef = sf; *ef != '\0' && !((*__ctype_b_loc ())[(int) ((*ef))] & (unsigned short) _ISspace); ef++)
            ;
        if (*sf == '\0')
        {
            errMsg("missing filename after '>'");
            return -1;
        }
        len = ef - sf;
        f = (char *) malloc((len + 1) * sizeof(char));
        if (f == ((void *)0))
            errMsg("malloc");
        strncpy(f, sf, len);
        f[len] = '\0';
        if ((j->out = open(f, 01 | 01000 | 0100,
                    0400 | (0400 >> 3) | (0200 >> 3) | 0200)) == -1)
            errExit("open");
        free(f);
        for(; r < ef; r++)
            *r = ' ';
    }
    while ((ep = strchr(sp, '|')) != ((void *)0))
    {
        if (create_process(sp, ep) == -1)
        {
            errMsg("empty pipeline");
            return -1;
        }
        else
        {
            read -= ep - sp + 1;
            sp = ep + 1;
        }
    }
    if (read > 0)
    {
        if (create_process(sp, sp + strlen(sp)) == -1)
        {
            errMsg("empty command");
            return -1;
        }
    }
    return 0;
}

variable_types:
len
unsigned long

variable_types: read long

variable_types:
r
char *

variable_types:
f
char *

variable_types:
sf
char *

variable_types:
ef
char *

user_defined_types: struct job { char *cmd; struct { struct process *sqh_first; struct process **sqh_last; } head; int in; int bg; }


main

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

init_shell();
while ( 1 )
{
while ( 1 )
{
printf("(tsh) ");
v3 = create_job("(tsh) ", argv);
if ( v3 )
break;
launch_job(*((_DWORD *)j + 8));
teardown_job();
}
if ( v3 == 1 )
break;
if ( v3 == -1 )
teardown_job();
}
teardown_job();
return 0;
}

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

func0();
while ( 1 )
{
while ( 1 )
{
printf("(tsh) ");
v3 = func5("(tsh) ", argv);
if ( v3 )
break;
func3(*((_DWORD *)j + 8));
func1();
}
if ( v3 == 1 )
break;
if ( v3 == -1 )
func1();
}
func1();
return 0;
}

original_code:
int main(void)
{
    int rc;
    init_shell();
    while (1)
    {
        printf("(tsh) ");
        rc = create_job();
        if(rc == 0)
        {
            launch_job(j->bg);
            teardown_job();
        }
        else if (rc == 1)
        {
            teardown_job();
            break;
        }
        else if (rc == -1)
        {
            teardown_job();
            continue;
        }
    }
    return 0;
}

canonical_original_code:
int main()
{
    int rc;
    init_shell();
    while (1)
    {
        printf("(tsh) ");
        rc = create_job();
        if(rc == 0)
        {
            launch_job(j->bg);
            teardown_job();
        }
        else if (rc == 1)
        {
            teardown_job();
            break;
        }
        else if (rc == -1)
        {
            teardown_job();
            continue;
        }
    }
    return 0;
}

variable_types: rc int


decompiled_code:
__int64 __fastcall is_existing_blk_or_reg_file(const char *a1)
{
__int64 result; // rax
int v2; // edx
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v3) >= 0 )
return (((v3.st_mode & 0xF000) - 24576) & 0xFFFFDFFF) == 0;
v2 = *_errno_location();
result = (unsigned int)-v2;
if ( v2 == 2 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 result; // rax
int v2; // edx
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v3) >= 0 )
return (((v3.st_mode & 0xF000) - 24576) & 0xFFFFDFFF) == 0;
v2 = *_errno_location();
result = (unsigned int)-v2;
if ( v2 == 2 )
result = 0LL;
return result;
}

original_code:
int is_existing_blk_or_reg_file(const char* filename)
{
 struct stat st_buf;
 if(stat(filename, &st_buf) < 0) {
  if((*__errno_location ()) == 2)
   return 0;
  else
   return -(*__errno_location ());
 }
 return (((((st_buf.st_mode)) & 0170000) == (0060000)) || ((((st_buf.st_mode)) & 0170000) == (0100000)));
}

canonical_original_code:
int is_existing_blk_or_reg_file(char *filename)
{
 struct stat st_buf;
 if(stat(filename, &st_buf) < 0) {
  if((*__errno_location ()) == 2)
   return 0;
  else
   return -(*__errno_location ());
 }
 return (((((st_buf.st_mode)) & 0170000) == (0060000)) || ((((st_buf.st_mode)) & 0170000) == (0100000)));
}

variable_types:
filename
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall is_loop_device(const char *a1)
{
unsigned int v1; // edx
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v3) < 0 )
return (unsigned int)-*_errno_location();
v1 = 0;
if ( (v3.st_mode & 0xF000) == 24576 )
v1 = v3.st_rdev >> 8 == 7;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // edx
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v3) < 0 )
return (unsigned int)-*_errno_location();
v1 = 0;
if ( (v3.st_mode & 0xF000) == 24576 )
v1 = v3.st_rdev >> 8 == 7;
return v1;
}

original_code:
int is_loop_device (const char* device)
{
 struct stat statbuf;
 if(stat(device, &statbuf) < 0)
  return -(*__errno_location ());
 return (((((statbuf.st_mode)) & 0170000) == (0060000)) &&
  ((statbuf.st_rdev)>>8) == 7);
}

canonical_original_code:
int is_loop_device(char *device)
{
 struct stat statbuf;
 if(stat(device, &statbuf) < 0)
  return -(*__errno_location ());
 return (((((statbuf.st_mode)) & 0170000) == (0060000)) &&
  ((statbuf.st_rdev)>>8) == 7);
}

variable_types:
device
char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall is_same_blk_file(char *file, char *name)
{
int v2; // edx
__int64 result; // rax
char v4[4096]; // [rsp+0h] [rbp-2138h] BYREF
char resolved[4096]; // [rsp+1000h] [rbp-1138h] BYREF
struct stat v6; // [rsp+2000h] [rbp-138h] BYREF
struct stat v7; // [rsp+2090h] [rbp-A8h] BYREF

if ( !realpath(file, resolved) || !realpath(name, v4) )
return (unsigned int)-*_errno_location();
v2 = strcmp(resolved, v4);
result = 1LL;
if ( v2 )
{
if ( stat(file, &v7) < 0 || stat(name, &v6) < 0 )
{
result = (unsigned int)-*_errno_location();
}
else if ( (v7.st_mode & 0xF000) != 24576
|| (v6.st_mode & 0xF000) != 24576
|| (result = 1LL, v7.st_rdev != v6.st_rdev) )
{
result = 0LL;
if ( v7.st_dev == v6.st_dev )
result = v7.st_ino == v6.st_ino;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *file, char *name)
{
int v2; // edx
__int64 result; // rax
char v4[4096]; // [rsp+0h] [rbp-2138h] BYREF
char resolved[4096]; // [rsp+1000h] [rbp-1138h] BYREF
struct stat v6; // [rsp+2000h] [rbp-138h] BYREF
struct stat v7; // [rsp+2090h] [rbp-A8h] BYREF

if ( !realpath(file, resolved) || !realpath(name, v4) )
return (unsigned int)-*_errno_location();
v2 = strcmp(resolved, v4);
result = 1LL;
if ( v2 )
{
if ( stat(file, &v7) < 0 || stat(name, &v6) < 0 )
{
result = (unsigned int)-*_errno_location();
}
else if ( (v7.st_mode & 0xF000) != 24576
|| (v6.st_mode & 0xF000) != 24576
|| (result = 1LL, v7.st_rdev != v6.st_rdev) )
{
result = 0LL;
if ( v7.st_dev == v6.st_dev )
result = v7.st_ino == v6.st_ino;
}
}
return result;
}

original_code:
int is_same_blk_file(const char* a, const char* b)
{
 struct stat st_buf_a, st_buf_b;
 char real_a[4096];
 char real_b[4096];
 if(!realpath(a, real_a) ||
    !realpath(b, real_b))
 {
  return -(*__errno_location ());
 }
 if(strcmp(real_a, real_b) == 0)
  return 1;
 if(stat(a, &st_buf_a) < 0 ||
    stat(b, &st_buf_b) < 0)
 {
  return -(*__errno_location ());
 }
 if(((((st_buf_a.st_mode)) & 0170000) == (0060000)) &&
    ((((st_buf_b.st_mode)) & 0170000) == (0060000)) &&
    st_buf_a.st_rdev == st_buf_b.st_rdev)
 {
  return 1;
 }
 if (st_buf_a.st_dev == st_buf_b.st_dev &&
     st_buf_a.st_ino == st_buf_b.st_ino)
 {
  return 1;
 }
 return 0;
}

canonical_original_code:
int is_same_blk_file(char *a, char *b)
{
 struct stat st_buf_a; struct stat st_buf_b;
 char real_a[4096];
 char real_b[4096];
 if(!realpath(a, real_a) ||
    !realpath(b, real_b))
 {
  return -(*__errno_location ());
 }
 if(strcmp(real_a, real_b) == 0)
  return 1;
 if(stat(a, &st_buf_a) < 0 ||
    stat(b, &st_buf_b) < 0)
 {
  return -(*__errno_location ());
 }
 if(((((st_buf_a.st_mode)) & 0170000) == (0060000)) &&
    ((((st_buf_b.st_mode)) & 0170000) == (0060000)) &&
    st_buf_a.st_rdev == st_buf_b.st_rdev)
 {
  return 1;
 }
 if (st_buf_a.st_dev == st_buf_b.st_dev &&
     st_buf_a.st_ino == st_buf_b.st_ino)
 {
  return 1;
 }
 return 0;
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
__int64 __fastcall resolve_loop_device(const char *a1, char *a2, int a3)
{
int v4; // eax
int v5; // ebp
unsigned int v6; // ebx
__int64 v8; // [rsp+0h] [rbp-D8h] BYREF
char src[168]; // [rsp+30h] [rbp-A8h] BYREF

v4 = open(a1, 0);
if ( v4 < 0 )
return (unsigned int)-*_errno_location();
v5 = v4;
v6 = ioctl(v4, 0x4C03uLL, &v8);
close(v5);
if ( v6 )
return (unsigned int)-*_errno_location();
strncpy(a2, src, a3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, char *a2, int a3)
{
int v4; // eax
int v5; // ebp
unsigned int v6; // ebx
__int64 v8; // [rsp+0h] [rbp-D8h] BYREF
char src[168]; // [rsp+30h] [rbp-A8h] BYREF

v4 = open(a1, 0);
if ( v4 < 0 )
return (unsigned int)-*_errno_location();
v5 = v4;
v6 = ioctl(v4, 0x4C03uLL, &v8);
close(v5);
if ( v6 )
return (unsigned int)-*_errno_location();
strncpy(a2, src, a3);
return v6;
}

original_code:
int resolve_loop_device(const char* loop_dev, char* loop_file, int max_len)
{
 int loop_fd;
 int ret_ioctl;
 struct loop_info loopinfo;
 if ((loop_fd = open(loop_dev, 00)) < 0)
  return -(*__errno_location ());
 ret_ioctl = ioctl(loop_fd, 0x4C03, &loopinfo);
 close(loop_fd);
 if (ret_ioctl == 0)
  strncpy(loop_file, loopinfo.lo_name, max_len);
 else
  return -(*__errno_location ());
 return 0;
}

canonical_original_code:
int resolve_loop_device(char *loop_dev, char *loop_file, int max_len)
{
 int loop_fd;
 int ret_ioctl;
 struct loop_info loopinfo;
 if ((loop_fd = open(loop_dev, 00)) < 0)
  return -(*__errno_location ());
 ret_ioctl = ioctl(loop_fd, 0x4C03, &loopinfo);
 close(loop_fd);
 if (ret_ioctl == 0)
  strncpy(loop_file, loopinfo.lo_name, max_len);
 else
  return -(*__errno_location ());
 return 0;
}

variable_types: struct loop_info { int lo_number; unsigned long lo_device; unsigned long lo_inode; unsigned long lo_rdevice; int lo_offset; int lo_encrypt_type; int lo_encrypt_key_size; int lo_flags; char lo_name[64]; unsigned char lo_encrypt_key[32]; unsigned long lo_init[2]; char reserved[4]; }