decompiled_code:
__int64 __fastcall parse_up(char *dest, const char *a2, const char *a3, const char *a4, const char *a5)
{
__int64 v8; // rbx
char *v9; // rax
char *v11; // rax
char v12[17]; // [rsp+Ch] [rbp-ECh] BYREF
char v13[19]; // [rsp+1Dh] [rbp-DBh] BYREF
__int128 v14[2]; // [rsp+30h] [rbp-C8h] BYREF
__int16 v15; // [rsp+50h] [rbp-A8h]
char s[16]; // [rsp+60h] [rbp-98h] BYREF
__int128 v17; // [rsp+70h] [rbp-88h]
__int128 v18; // [rsp+80h] [rbp-78h]
__int128 v19; // [rsp+90h] [rbp-68h]
__int128 v20; // [rsp+A0h] [rbp-58h]
__int16 v21; // [rsp+B0h] [rbp-48h]
char v22; // [rsp+B2h] [rbp-46h]

Dlog("parse_up");
v15 = 10;
v14[0] = (__int128)_mm_load_si128((const __m128i *)&LC12);
strcpy(v12, "up2date\n");
v14[1] = (__int128)_mm_load_si128((const __m128i *)&LC13);
*(__m128i *)&v13[3] = _mm_load_si128((const __m128i *)&LC14);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up");
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, 3LL);
fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, 1LL);
v8 = (unsigned int)waz(a2);
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, v8);
strcpy(&v12[9], "5143169147");
if ( (_DWORD)v8 == 1 )
{
if ( (unsigned int)isfield(a2, &v12[9], a4, a5) )
{
Dlog("after isfield");
*(_OWORD *)s = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0;
v22 = 0;
v11 = mk_btreel(dest, delim, 1, &v12[9], a4, a5);
send_recv_2pbk_skt(v11, s);
if ( s[0] == 48 )
printf("%s", (const char *)v14);
else
puts(s);
return 0LL;
}
return 0xFFFFFFFFLL;
}
if ( !(unsigned int)isfield(a2, a3, a4, a5) )
return 0xFFFFFFFFLL;
Dlog("after isfield");
v21 = 0;
v22 = 0;
*(_OWORD *)s = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v9 = mk_btreel(dest, delim, v8, a3, a4, a5);
send_recv_2pbk_skt(v9, s);
if ( (_DWORD)v8 == 3 )
{
if ( s[0] != 48 )
{
printf("%s %s %s %s", a4, a5, a3, v12);
return 0LL;
}
printf("%s %s %s", a4, a5, &v13[3]);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *dest, const char *a2, const char *a3, const char *a4, const char *a5)
{
__int64 v8; // rbx
char *v9; // rax
char *v11; // rax
char v12[17]; // [rsp+Ch] [rbp-ECh] BYREF
char v13[19]; // [rsp+1Dh] [rbp-DBh] BYREF
__int128 v14[2]; // [rsp+30h] [rbp-C8h] BYREF
__int16 v15; // [rsp+50h] [rbp-A8h]
char s[16]; // [rsp+60h] [rbp-98h] BYREF
__int128 v17; // [rsp+70h] [rbp-88h]
__int128 v18; // [rsp+80h] [rbp-78h]
__int128 v19; // [rsp+90h] [rbp-68h]
__int128 v20; // [rsp+A0h] [rbp-58h]
__int16 v21; // [rsp+B0h] [rbp-48h]
char v22; // [rsp+B2h] [rbp-46h]

Dlog("parse_up");
v15 = 10;
v14[0] = (__int128)_mm_load_si128((const __m128i *)&LC12);
strcpy(v12, "up2date\n");
v14[1] = (__int128)_mm_load_si128((const __m128i *)&LC13);
*(__m128i *)&v13[3] = _mm_load_si128((const __m128i *)&LC14);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up");
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, 3LL);
fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, 1LL);
v8 = (unsigned int)func0(a2);
fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, v8);
strcpy(&v12[9], "5143169147");
if ( (_DWORD)v8 == 1 )
{
if ( (unsigned int)isfield(a2, &v12[9], a4, a5) )
{
Dlog("after isfield");
*(_OWORD *)s = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0;
v22 = 0;
v11 = func1(dest, delim, 1, &v12[9], a4, a5);
send_recv_2pbk_skt(v11, s);
if ( s[0] == 48 )
printf("%s", (const char *)v14);
else
puts(s);
return 0LL;
}
return 0xFFFFFFFFLL;
}
if ( !(unsigned int)isfield(a2, a3, a4, a5) )
return 0xFFFFFFFFLL;
Dlog("after isfield");
v21 = 0;
v22 = 0;
*(_OWORD *)s = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v9 = func1(dest, delim, v8, a3, a4, a5);
send_recv_2pbk_skt(v9, s);
if ( (_DWORD)v8 == 3 )
{
if ( s[0] != 48 )
{
printf("%s %s %s %s", a4, a5, a3, v12);
return 0LL;
}
printf("%s %s %s", a4, a5, &v13[3]);
}
return 0LL;
}

original_code:
int
parse_up(char *qstrp, char *up, char *phon, char *name, char *last) {
 Dlog("parse_up");
 char noalice[] = "Alice doesn't live here anymore!\n";
 char havealice[] = "now lives here\n";
 char upalice[] = "up2date\n";
 int upbit = UPDATE;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, LOOKUP));
 upbit = waz(up);
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 char myphon[] = "5143169147";
 char *myphonp = myphon;
 if(upbit == LOOKUP)
  phon = myphonp;
 if (!(isfield(up, phon, name, last)))
  return -1;
 Dlog("after isfield");
 char buf[((4*20) + 2 + 1)] = {0};
 char *bufp = buf;
 qstrp = mk_btreel(qstrp, delim, upbit, phon, name, last);
 send_recv_2pbk_skt(qstrp, bufp);
 switch (upbit) {
  case LOOKUP:
   if ((buf[0] - '0') == 0)
    printf("%s", noalice);
   else
    printf("%s\n", bufp);
   break;
  case UPDATE:
   if ((buf[0] - '0') == 0)
    printf("%s %s %s", name, last, havealice);
   else
    printf("%s %s %s %s", name, last, phon, upalice);
   break;
  default:
   break;
 }
 return 0;
}

canonical_original_code:
int parse_up(char *qstrp, char *up, char *phon, char *name, char *last) {
 Dlog("parse_up");
 char noalice[] = "Alice doesn't live here anymore!\n";
 char havealice[] = "now lives here\n";
 char upalice[] = "up2date\n";
 int upbit = UPDATE;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_up"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "LOOKUP", 10, LOOKUP));
 upbit = waz(up);
 (fprintf(stderr, "%-*s = %-*d\n", 10, "upbit", 10, upbit));
 char myphon[] = "5143169147";
 char *myphonp = myphon;
 if(upbit == LOOKUP)
  phon = myphonp;
 if (!(isfield(up, phon, name, last)))
  return -1;
 Dlog("after isfield");
 char buf[-1] = {0};
 char *bufp = buf;
 qstrp = mk_btreel(qstrp, delim, upbit, phon, name, last);
 send_recv_2pbk_skt(qstrp, bufp);
 switch (upbit) {
  case LOOKUP:
   if ((buf[0] - '0') == 0)
    printf("%s", noalice);
   else
    printf("%s\n", bufp);
   break;
  case UPDATE:
   if ((buf[0] - '0') == 0)
    printf("%s %s %s", name, last, havealice);
   else
    printf("%s %s %s %s", name, last, phon, upalice);
   break;
  default:
   break;
 }
 return 0;
}

variable_types:
qstrp
char *

variable_types:
noalice
char []

variable_types:
havealice
char []

variable_types:
upalice
char []

variable_types:
myphon
char []

variable_types:
myphonp
char *

variable_types:
buf
char [-1]

variable_types:
bufp
char *


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

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

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

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

original_code:
int
mk_socket() {
 int s;
 if ((s = socket(1, SOCK_STREAM, 0)) == -1) {
  perror("socket");
  exit(1);
 }
 return s;
}

variable_types: s int

return_type: int


decompiled_code:
void *__fastcall send_recv_2pbk_skt(void *buf, void *a2)
{
int v2; // ebp
size_t v3; // rax
int v4; // eax
int v5; // ebx
struct sockaddr v7[9]; // [rsp+0h] [rbp-98h] BYREF

v2 = mk_socket();
v7[0].sa_family = 1;
strcpy(v7[0].sa_data, "/tmp/22294");
if ( connect(v2, v7, 0xCu) == -1 )
{
perror("connect");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, (const char *)buf);
v3 = strlen((const char *)buf);
if ( send(v2, buf, v3, 0) == -1 )
{
perror("send");
exit(1);
}
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
v4 = recv(v2, a2, 0x53uLL, 0);
if ( v4 <= 0 )
{
if ( v4 )
perror("recv");
else
printf("\x1B[31mpbkc:\tServer closed connection\n\x1B[0m");
exit(1);
}
v5 = v4;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()");
*((_BYTE *)a2 + v5) = 0;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
return a2;
}

canonical_decompiled_code:
void *__fastcall func1(void *buf, void *a2)
{
int v2; // ebp
size_t v3; // rax
int v4; // eax
int v5; // ebx
struct sockaddr v7[9]; // [rsp+0h] [rbp-98h] BYREF

v2 = func0();
v7[0].sa_family = 1;
strcpy(v7[0].sa_data, "/tmp/22294");
if ( connect(v2, v7, 0xCu) == -1 )
{
perror("connect");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, (const char *)buf);
v3 = strlen((const char *)buf);
if ( send(v2, buf, v3, 0) == -1 )
{
perror("send");
exit(1);
}
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
v4 = recv(v2, a2, 0x53uLL, 0);
if ( v4 <= 0 )
{
if ( v4 )
perror("recv");
else
printf("\x1B[31mpbkc:\tServer closed connection\n\x1B[0m");
exit(1);
}
v5 = v4;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()");
*((_BYTE *)a2 + v5) = 0;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)a2);
return a2;
}

original_code:
char *
send_recv_2pbk_skt(char *qstrp, char *bufp) {
 int s, len;
 int t;
 struct sockaddr_un remote;
 s = mk_socket();
 remote.sun_family = 1;
 strcpy(remote.sun_path, "/tmp/22294");
 len = strlen(remote.sun_path) + sizeof(remote.sun_family);
 if (connect(s, (struct sockaddr *)&remote, len) == -1) {
  perror("connect");
  exit(1);
 }
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
 (fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, qstrp));
 if (send(s, qstrp, strlen(qstrp), 0) == -1) {
  perror("send");
  exit(1);
 }
 (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
 if ((t = recv(s, bufp, ((4*20) + 2 + 1), 0)) > 0) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()"));
  bufp[t] = '\0';
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  return bufp;
 } else {
  if (t < 0) perror("recv");
  else printf("\033[31m" "pbkc:\tServer closed connection\n" "\033[0m");
  exit(1);
 }
 close(s);
}

canonical_original_code:
char *send_recv_2pbk_skt(char *qstrp, char *bufp) {
 int s; int len;
 int t;
 struct sockaddr_un remote;
 s = mk_socket();
 remote.sun_family = 1;
 strcpy(remote.sun_path, "/tmp/22294");
 len = strlen(remote.sun_path) + sizeof(remote.sun_family);
 if (connect(s, (struct sockaddr *)&remote, len) == -1) {
  perror("connect");
  exit(1);
 }
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
 (fprintf(stderr, "%-*s = %-*s\n", 10, "qstrp", 10, qstrp));
 if (send(s, qstrp, strlen(qstrp), 0) == -1) {
  perror("send");
  exit(1);
 }
 (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
 if ((t = recv(s, bufp, ((4*20) + 2 + 1), 0)) > 0) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv()"));
  bufp[t] = '\0';
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  return bufp;
 } else {
  if (t < 0) perror("recv");
  else printf("\033[31m" "pbkc:\tServer closed connection\n" "\033[0m");
  exit(1);
 }
 close(s);
}

variable_types: len int

variable_types: t int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

return_type: char *

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


cgigetval

decompiled_code:
void *__fastcall cgigetval(char *s1)
{
int v1; // eax
const char *v2; // r14
int v3; // ebp
size_t v4; // r13
int v5; // er15
char v6; // al
char *v7; // rbx
char *v8; // rax
unsigned int v9; // er15
void *v10; // rax
void *v11; // r12
int v13; // [rsp+8h] [rbp-40h]

if ( !querystring_0 )
{
querystring_0 = getenv("QUERY_STRING");
if ( !querystring_0 )
return 0LL;
}
if ( !s1 )
return 0LL;
v1 = strlen(s1);
v2 = querystring_0;
v13 = v1;
v3 = v1;
if ( !*querystring_0 )
return 0LL;
v4 = v1;
while ( 1 )
{
v7 = strchr(v2, 61);
v8 = strchr(v2, 38);
if ( !v8 )
break;
if ( v7 > v8 )
{
if ( !*v2 )
return 0LL;
}
else
{
v5 = (_DWORD)v8 - (_DWORD)v2;
if ( v3 == (_DWORD)v7 - (_DWORD)v2 )
goto LABEL_12;
LABEL_7:
v2 += v5;
v6 = *v2;
if ( *v2 == 38 )
v6 = *++v2;
if ( !v6 )
return 0LL;
}
}
v5 = strlen(v2);
if ( v3 != (_DWORD)v7 - (_DWORD)v2 )
goto LABEL_7;
LABEL_12:
if ( strncmp(s1, v2, v4) )
goto LABEL_7;
v9 = v5 - v13;
v10 = malloc((int)v9);
v11 = v10;
if ( v10 )
unescstring(v7 + 1, v9 - 1, v10, v9);
return v11;
}

canonical_decompiled_code:
void *__fastcall func0(char *s1)
{
int v1; // eax
const char *v2; // r14
int v3; // ebp
size_t v4; // r13
int v5; // er15
char v6; // al
char *v7; // rbx
char *v8; // rax
unsigned int v9; // er15
void *v10; // rax
void *v11; // r12
int v13; // [rsp+8h] [rbp-40h]

if ( !querystring_0 )
{
querystring_0 = getenv("QUERY_STRING");
if ( !querystring_0 )
return 0LL;
}
if ( !s1 )
return 0LL;
v1 = strlen(s1);
v2 = querystring_0;
v13 = v1;
v3 = v1;
if ( !*querystring_0 )
return 0LL;
v4 = v1;
while ( 1 )
{
v7 = strchr(v2, 61);
v8 = strchr(v2, 38);
if ( !v8 )
break;
if ( v7 > v8 )
{
if ( !*v2 )
return 0LL;
}
else
{
v5 = (_DWORD)v8 - (_DWORD)v2;
if ( v3 == (_DWORD)v7 - (_DWORD)v2 )
goto LABEL_12;
LABEL_7:
v2 += v5;
v6 = *v2;
if ( *v2 == 38 )
v6 = *++v2;
if ( !v6 )
return 0LL;
}
}
v5 = strlen(v2);
if ( v3 != (_DWORD)v7 - (_DWORD)v2 )
goto LABEL_7;
LABEL_12:
if ( strncmp(s1, v2, v4) )
goto LABEL_7;
v9 = v5 - v13;
v10 = malloc((int)v9);
v11 = v10;
if ( v10 )
unescstring(v7 + 1, v9 - 1, v10, v9);
return v11;
}

original_code:
char *cgigetval(char *fieldname)
{
 int fnamelen;
 char *p, *p2, *p3;
 int len1, len2;
 static char *querystring = ((void *)0);
 if(querystring == ((void *)0))
 {
  querystring = getenv("QUERY_STRING");
  if(querystring == ((void *)0))
   return ((void *)0);
 }
 if(fieldname == ((void *)0))
  return ((void *)0);
 fnamelen = strlen(fieldname);
 for(p = querystring; *p != '\0';)
 {
  p2 = strchr(p, '=');
  p3 = strchr(p, '&');
  if(p3 != ((void *)0))
   len2 = p3 - p;
  else
   len2 = strlen(p);
  if((p2 == ((void *)0) || p3 != ((void *)0)) && (p2 > p3))
  {
   p3 += len2;
   continue;
  }
  len1 = p2 - p;
  if(len1 == fnamelen && strncmp(fieldname, p, len1) == 0)
  {
   int retlen = len2 - len1 - 1;
   char *retbuf = malloc(retlen + 1);
   if(retbuf == ((void *)0))
    return ((void *)0);
   unescstring(p2 + 1, retlen, retbuf, retlen+1);
   return retbuf;
  }
  p += len2;
  if(*p == '&')
   p++;
 }
 return ((void *)0);
}

canonical_original_code:
char *cgigetval(char *fieldname)
{
 int fnamelen;
 char *p; char *p2; char *p3;
 int len1; int len2;
 static char *querystring = ((void *)0);
 if(querystring == ((void *)0))
 {
  querystring = getenv("QUERY_STRING");
  if(querystring == ((void *)0))
   return ((void *)0);
 }
 if(fieldname == ((void *)0))
  return ((void *)0);
 fnamelen = strlen(fieldname);
 for(p = querystring; *p != '\0';)
 {
  p2 = strchr(p, '=');
  p3 = strchr(p, '&');
  if(p3 != ((void *)0))
   len2 = p3 - p;
  else
   len2 = strlen(p);
  if((p2 == ((void *)0) || p3 != ((void *)0)) && (p2 > p3))
  {
   p3 += len2;
   continue;
  }
  len1 = p2 - p;
  if(len1 == fnamelen && strncmp(fieldname, p, len1) == 0)
  {
   int retlen = len2 - len1 - 1;
   char *retbuf = malloc(retlen + 1);
   if(retbuf == ((void *)0))
    return ((void *)0);
   unescstring(p2 + 1, retlen, retbuf, retlen+1);
   return retbuf;
  }
  p += len2;
  if(*p == '&')
   p++;
 }
 return ((void *)0);
}

variable_types:
fieldname
char *

variable_types: fnamelen int

variable_types:
p
char *

variable_types:
querystring
char *

variable_types: retlen int

variable_types:
retbuf
char *


isop

decompiled_code:
_BOOL8 __fastcall isop(unsigned __int64 a1)
{
return a1 <= 5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int64 a1)
{
return a1 <= 5;
}

original_code:
unsigned short int
isop(long long op) {
 if ((NONE <= op) && (op <= BOP))
  return 1;
 else
  return 0;
}

canonical_original_code:
unsigned short isop(long long op) {
 if ((NONE <= op) && (op <= BOP))
  return 1;
 else
  return 0;
}

variable_types:
op
long long

return_type: unsigned short


decompiled_code:
__int64 no_up()
{
puts("Naughty Naughty srv!");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
puts("Naughty Naughty srv!");
return 0LL;
}

original_code:
int
no_up() {
 printf("Naughty Naughty srv!\n");
 return FALSE;
}


isup

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

if ( a1 )
result = 1LL;
else
result = no_up();
return result;
}

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

if ( a1 )
result = 1LL;
else
result = func1();
return result;
}

original_code:
int
isup(char *up) {
 if(up == ((void *)0))
  return no_up();
 return TRUE;
}

variable_types:
up
char *


decompiled_code:
__int64 long_phon()
{
printf("Bad phone!\nneed exactly %d digits!\n", 10LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
printf("Bad phone!\nneed exactly %d digits!\n", 10LL);
return 0LL;
}

original_code:
int
long_phon() {
 printf("Bad phone!\nneed exactly %d digits!\n", 10);
 return FALSE;
}


decompiled_code:
__int64 bad_phon_dig()
{
puts("Only digits for phon, please!");
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
puts("Only digits for phon, please!");
return 0LL;
}

original_code:
int
bad_phon_dig() {
 printf("Only digits for phon, please!\n");
 return FALSE;
}


decompiled_code:
__int64 phon_with_zero_start()
{
puts("No phon starts with 0");
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
puts("No phon starts with 0");
return 0LL;
}

original_code:
int
phon_with_zero_start() {
 printf("No phon starts with 0\n");
 return FALSE;
}


isphdigit

decompiled_code:
__int64 __fastcall isphdigit(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rdx
_BYTE *v3; // rcx
__int64 result; // rax

v2 = a1;
v3 = a1 + 10;
do
{
if ( (unsigned __int8)(*v2 - 48) > 9u )
return bad_phon_dig(a1, a2, v2, v3);
++v2;
}
while ( v2 != v3 );
if ( *a1 == 48 )
result = phon_with_zero_start();
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rdx
_BYTE *v3; // rcx
__int64 result; // rax

v2 = a1;
v3 = a1 + 10;
do
{
if ( (unsigned __int8)(*v2 - 48) > 9u )
return func4(a1, a2, v2, v3);
++v2;
}
while ( v2 != v3 );
if ( *a1 == 48 )
result = func5();
else
result = 1LL;
return result;
}

original_code:
int
isphdigit(char *phon, int len) {
 for(len = 0; len < 10; len++)
  if (!(phon[len] >= '0' && phon[len] <= '9'))
   return bad_phon_dig();
 if(phon[0] == '0')
  return phon_with_zero_start();
 return TRUE;
}

variable_types:
phon
char *


decompiled_code:
__int64 no_input_phon()
{
printf("No %s !\n", (const char *)&unk_2E0);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
printf("No %s !\n", (const char *)&unk_2E0);
return 0LL;
}

original_code:
int
no_input_phon() {
 printf("No %s !\n", "");
 return FALSE;
}


isph

decompiled_code:
__int64 __fastcall isph(char *a1)
{
if ( !a1 )
return no_input_phon();
if ( (unsigned int)strlen(a1) == 10 )
return isphdigit(a1, 10LL);
return long_phon();
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
if ( !a1 )
return func7();
if ( (unsigned int)strlen(a1) == 10 )
return func6(a1, 10LL);
return func3();
}

original_code:
int
isph(char *phon) {
 if(phon == ((void *)0))
  return no_input_phon();
 int len = strlen(phon);
 if(len != 10) {
  return long_phon();
 }
 else
  return isphdigit(phon, len);
}


decompiled_code:
__int64 name_is_long()
{
printf("long long %s !\n", "name");
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
printf("long long %s !\n", "name");
return 0LL;
}

original_code:
int
name_is_long(char *name) {
 printf("long long %s !\n" , "name");
 return FALSE;
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall is_name_alpha(char *a1, int a2)
{
const unsigned __int16 *v2; // rdx
__int64 v3; // rcx

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = (__int64)&a1[a2 - 1 + 1];
do
{
if ( (v2[*a1] & 0x400) == 0 )
{
puts("only alpha chars!");
return 0LL;
}
++a1;
}
while ( (char *)v3 != a1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, int a2)
{
const unsigned __int16 *v2; // rdx
__int64 v3; // rcx

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = (__int64)&a1[a2 - 1 + 1];
do
{
if ( (v2[*a1] & 0x400) == 0 )
{
puts("only alpha chars!");
return 0LL;
}
++a1;
}
while ( (char *)v3 != a1 );
return 1LL;
}

original_code:
int
is_name_alpha(char *name, int len) {
 int i;
 for(i = 0; i < len; i++)
  if(!(((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short int) _ISalpha))) {
   printf("only alpha chars!\n");
   return FALSE;
  }
 return TRUE;
}

canonical_original_code:
int is_name_alpha(char *name, int len) {
 int i;
 for(i = 0; i < len; i++)
  if(!(((*__ctype_b_loc ())[(int) ((name[i]))] & (unsigned short) _ISalpha))) {
   printf("only alpha chars!\n");
   return FALSE;
  }
 return TRUE;
}

variable_types: i int


decompiled_code:
__int64 no_name()
{
printf("No %s!, No man! Naland\n", "name");
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
printf("No %s!, No man! Naland\n", "name");
return 0LL;
}

original_code:
int
no_name() {
 printf("No %s!, No man! Naland\n", "name");
 return FALSE;
}


isn

decompiled_code:
__int64 __fastcall isn(char *a1)
{
int v1; // eax
__int64 result; // rax

if ( !a1 )
return no_name();
v1 = strlen(a1);
if ( v1 <= 20 )
result = is_name_alpha(a1, v1);
else
result = name_is_long("name");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
int v1; // eax
__int64 result; // rax

if ( !a1 )
return func11();
v1 = strlen(a1);
if ( v1 <= 20 )
result = func10(a1, v1);
else
result = func9("name");
return result;
}

original_code:
int
isn(char *name) {
 if(name == ((void *)0))
  return no_name();
 else {
  int len = strlen(name);
  if(20 < len)
   return name_is_long("name");
  else
   return is_name_alpha(name, len);
 }
 return TRUE;
}


isfield

decompiled_code:
_BOOL8 __fastcall isfield(__int64 a1, char *a2, char *a3, char *a4)
{
_BOOL8 result; // rax

if ( (unsigned int)isup(a1) && (unsigned int)isph(a2) && (unsigned int)isn(a3) )
result = (unsigned int)isn(a4) != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int64 a1, char *a2, char *a3, char *a4)
{
_BOOL8 result; // rax

if ( (unsigned int)func2(a1) && (unsigned int)func8(a2) && (unsigned int)func12(a3) )
result = (unsigned int)func12(a4) != 0;
else
result = 0LL;
return result;
}

original_code:
int
isfield(char *up, char *ph, char *n, char *l) {
 if (isup(up) && isph(ph) && isn(n) && isn(l))
  return TRUE;
 return FALSE;
}

variable_types:
ph
char *

variable_types:
n
char *

variable_types:
l
char *


isl

decompiled_code:
// attributes: thunk
__int64 __fastcall isl(char *a1)
{
return isn(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1)
{
return func12(a1);
}

original_code:
int
isl(char *last) {
 return isn(last);
}

variable_types:
last
char *


decompiled_code:
__int64 __fastcall addnode_2root(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // eax
__int64 result; // rax
int v5; // eax

v2 = a2;
if ( !a1 )
return v2;
v3 = strcmp(*(const char **)(a2 + 8), *(const char **)(a1 + 8));
if ( v3 )
{
if ( v3 >= 0 )
{
v2 = a1;
*(_QWORD *)(a1 + 56) = addnode_2root(*(_QWORD *)(a1 + 56), a2);
return v2;
}
*(_QWORD *)(a1 + 40) = addnode_2root(*(_QWORD *)(a1 + 40), a2);
result = a1;
}
else
{
++*(_DWORD *)(a1 + 32);
v2 = a1;
v5 = strcmp(*(const char **)(a2 + 16), *(const char **)(a1 + 16));
if ( !v5 )
return v2;
if ( v5 < 0 )
{
*(_QWORD *)(a1 + 40) = addnode_2root(*(_QWORD *)(a1 + 40), a2);
return v2;
}
*(_QWORD *)(a1 + 56) = addnode_2root(*(_QWORD *)(a1 + 56), a2);
result = a1;
}
return result;
}

original_code:
tnode *
addnode_2root(tnode *root, tnode *node) {
 int cond;
 if (root == ((void *)0)) {
  root = node;
 } else if ((cond = strcmp(node->name, root->name)) == 0) {
  root->count++;
  if ((cond = strcmp(node->last, root->last)) == 0) {
   return root;
  } else if (cond < 0)
   root->left = addnode_2root(root->left, node);
  else
   root->right = addnode_2root(root->right, node);
  return root;
 } else if (cond < 0)
  root->left = addnode_2root(root->left, node);
 else
  root->right = addnode_2root(root->right, node);
 return root;
}

canonical_original_code:
struct tnode *addnode_2root(struct tnode *root, struct tnode *node) {
 int cond;
 if (root == ((void *)0)) {
  root = node;
 } else if ((cond = strcmp(node->name, root->name)) == 0) {
  root->count++;
  if ((cond = strcmp(node->last, root->last)) == 0) {
   return root;
  } else if (cond < 0)
   root->left = addnode_2root(root->left, node);
  else
   root->right = addnode_2root(root->right, node);
  return root;
 } else if (cond < 0)
  root->left = addnode_2root(root->left, node);
 else
  root->right = addnode_2root(root->right, node);
 return root;
}

variable_types:
root
struct tnode *

variable_types:
node
struct tnode *

variable_types: cond int

return_type: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; } *


decompiled_code:
int __fastcall hit_print(__int64 a1)
{
return printf("%d\n", *(unsigned int *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
return printf("%d\n", *(unsigned int *)(a1 + 32));
}

original_code:
void
hit_print(tnode *node) {
 printf("%d\n", node->count);
}

canonical_original_code:
void hit_print(struct tnode *node) {
 printf("%d\n", node->count);
}

variable_types: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; } *

return_type: void


decompiled_code:
int __fastcall node_printf(_QWORD *a1)
{
_QWORD *v1; // r9
_QWORD *v2; // r9
const char *v3; // rax
const char *v4; // r10
const char *v5; // r11
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

nodef_print(a1, 0LL, 4);
nodef_print(v1, 0LL, 2);
v3 = (const char *)nodef_print(v2, v7, 1);
return printf("%s:%s:%s\n", v3, v4, v5);
}

canonical_decompiled_code:
int __fastcall func6(_QWORD *a1)
{
_QWORD *v1; // r9
_QWORD *v2; // r9
const char *v3; // rax
const char *v4; // r10
const char *v5; // r11
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

func5(a1, 0LL, 4);
func5(v1, 0LL, 2);
v3 = (const char *)func5(v2, v7, 1);
return printf("%s:%s:%s\n", v3, v4, v5);
}

original_code:
void
node_printf(tnode *node) {
 char phon[20];
 char *phonp = phon;
 printf("%s:%s:%s\n",
 nodef_print(node, phonp, PHON),
 nodef_print(node, ((void *)0), NAME),
 nodef_print(node, ((void *)0), LAST));
}

canonical_original_code:
void node_printf(struct tnode *node) {
 char phon[20];
 char *phonp = phon;
 printf("%s:%s:%s\n",
 nodef_print(node, phonp, PHON),
 nodef_print(node, ((void *)0), NAME),
 nodef_print(node, ((void *)0), LAST));
}

variable_types:
phon
char [20]

variable_types:
phonp
char *

user_defined_types: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; }


treeprint

decompiled_code:
int __fastcall treeprint(_QWORD *a1, int a2)
{
_QWORD *v2; // rbp
int result; // eax

if ( a1 )
{
v2 = a1;
do
{
if ( a2 == 1 )
{
treeprint(v2[5], 1LL);
result = node_printf(v2);
v2 = (_QWORD *)v2[7];
}
else
{
if ( a2 == 2 )
{
treeprint(v2[5], 2LL);
treeprint(v2[7], 2LL);
return node_printf(v2);
}
if ( a2 )
return result;
node_printf(v2);
result = treeprint(v2[5], 0LL);
v2 = (_QWORD *)v2[7];
}
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(_QWORD *a1, int a2)
{
_QWORD *v2; // rbp
int result; // eax

if ( a1 )
{
v2 = a1;
do
{
if ( a2 == 1 )
{
func7(v2[5], 1LL);
result = func6(v2);
v2 = (_QWORD *)v2[7];
}
else
{
if ( a2 == 2 )
{
func7(v2[5], 2LL);
func7(v2[7], 2LL);
return func6(v2);
}
if ( a2 )
return result;
func6(v2);
result = func7(v2[5], 0LL);
v2 = (_QWORD *)v2[7];
}
}
while ( v2 );
}
return result;
}

original_code:
void
treeprint(tnode *root, int order) {
 if (root != ((void *)0)) {
  switch (order) {
   case PRE:
    node_printf(root);
    treeprint(root->left, order);
    treeprint(root->right, order);
    break;
   case IN:
    treeprint(root->left, order);
    node_printf(root);
    treeprint(root->right, order);
    break;
   case POST:
    treeprint(root->left, order);
    treeprint(root->right, order);
    node_printf(root);
    break;
   default:
    break;
  }
 }
}

canonical_original_code:
void treeprint(struct tnode *root, int order) {
 if (root != ((void *)0)) {
  switch (order) {
   case PRE:
    node_printf(root);
    treeprint(root->left, order);
    treeprint(root->right, order);
    break;
   case IN:
    treeprint(root->left, order);
    node_printf(root);
    treeprint(root->right, order);
    break;
   case POST:
    treeprint(root->left, order);
    treeprint(root->right, order);
    node_printf(root);
    break;
   default:
    break;
  }
 }
}

variable_types: order int


decompiled_code:
char *__fastcall node2line(unsigned int *a1, const char *a2, char *a3)
{
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

if ( !a1 )
return 0LL;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line");
fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, *a1);
v4 = (const char *)nodef_print(a1, a3, 0);
strcpy(a3, v4);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v5 = (const char *)nodef_print(a1, a3, 1);
strcat(a3, v5);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v6 = (const char *)nodef_print(a1, a3, 2);
strcat(a3, v6);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v7 = (const char *)nodef_print(a1, a3, 4);
return strcat(a3, v7);
}

canonical_decompiled_code:
char *__fastcall func8(unsigned int *a1, const char *a2, char *a3)
{
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

if ( !a1 )
return 0LL;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line");
fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, *a1);
v4 = (const char *)func5(a1, a3, 0);
strcpy(a3, v4);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v5 = (const char *)func5(a1, a3, 1);
strcat(a3, v5);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v6 = (const char *)func5(a1, a3, 2);
strcat(a3, v6);
strcat(a3, a2);
fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, a3);
v7 = (const char *)func5(a1, a3, 4);
return strcat(a3, v7);
}

original_code:
char *
node2line(tnode *node, char *delim, char *lbuf) {
 if (node == ((void *)0))
  return ((void *)0);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, node->op));
 lbuf = strcpy(lbuf, nodef_print(node, lbuf, OP));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, PHON));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, NAME));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, LAST));
 return lbuf;
}

canonical_original_code:
char *node2line(struct tnode *node, char *delim, char *lbuf) {
 if (node == ((void *)0))
  return ((void *)0);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "node2line"));
 (fprintf(stderr, "%-*s = %-*d\n", 10, "node->op", 10, node->op));
 lbuf = strcpy(lbuf, nodef_print(node, lbuf, OP));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, PHON));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, NAME));
 lbuf = strcat(lbuf, delim);
 (fprintf(stderr, "%-*s = %-*s\n", 10, "lbuf", 10, lbuf));
 lbuf = strcat(lbuf, nodef_print(node, lbuf, LAST));
 return lbuf;
}

variable_types:
delim
char *

variable_types:
lbuf
char *


decompiled_code:
void *__fastcall kr_strdup(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func12(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
char *kr_strdup(char *s)
{
     char *p;
      p = (char *) malloc(strlen(s)+1);
      if (p != ((void *)0))
          strcpy(p, s);
      return p;
}

variable_types:
s
char *

variable_types:
p
char *


talloc

decompiled_code:
void *talloc()
{
return malloc(0x40uLL);
}

canonical_decompiled_code:
void *func13()
{
return malloc(0x40uLL);
}

original_code:
tnode *
talloc(void) {
 return (tnode *) malloc(sizeof(tnode));
}

canonical_original_code:
struct tnode *talloc() {
 return (struct tnode *) malloc(sizeof(tnode));
}


decompiled_code:
__int64 __fastcall ins_node(__int64 a1, const char **a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
__int64 result; // rax
_DWORD *v5; // rax
_QWORD *v6; // rax

v2 = (_QWORD *)lookup(a1, (__int64)a2);
if ( *v2 )
{
v3 = v2;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("found a match updating\n", 1uLL, 0x17uLL, stderr);
*(_QWORD *)(*v3 + 24LL) = a2[3];
result = 3LL;
}
else
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("NO match inserting here\n", 1uLL, 0x18uLL, stderr);
v5 = mk_node(0LL, 0, 0, a2[3], a2[1], a2[2]);
v6 = (_QWORD *)addnode_2root(a1, (__int64)v5);
treeprint(v6, 1);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char **a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
__int64 result; // rax
_DWORD *v5; // rax
_QWORD *v6; // rax

v2 = (_QWORD *)func1(a1, (__int64)a2);
if ( *v2 )
{
v3 = v2;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("found a match updating\n", 1uLL, 0x17uLL, stderr);
*(_QWORD *)(*v3 + 24LL) = a2[3];
result = 3LL;
}
else
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("NO match inserting here\n", 1uLL, 0x18uLL, stderr);
v5 = mk_node(0LL, 0, 0, a2[3], a2[1], a2[2]);
v6 = (_QWORD *)func0(a1, (__int64)v5);
func7(v6, 1);
result = 2LL;
}
return result;
}

original_code:
int
ins_node(tnode *root, tnode *node) {
 int insbit;
 tnode **place_in_tree = lookup(root, node);
 if ((*place_in_tree) == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "NO match inserting here\n"));
  tnode *nnode = ((void *)0);
  nnode = mk_node(nnode, NONE, NONE, node->phon, node->name, node->last);
  root = addnode_2root(root, nnode);
  treeprint(root, IN);
  insbit = INS;
 } else {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "found a match updating\n"));
  (*place_in_tree)->phon = node->phon;
  strcpy((*place_in_tree)->phon, node->phon);
  insbit = UPDATE;
 }
 return insbit;
}

canonical_original_code:
int ins_node(struct tnode *root, struct tnode *node) {
 int insbit;
 struct tnode **place_in_tree = lookup(root, node);
 if ((*place_in_tree) == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "NO match inserting here\n"));
  struct tnode *nnode = ((void *)0);
  nnode = mk_node(nnode, NONE, NONE, node->phon, node->name, node->last);
  root = addnode_2root(root, nnode);
  treeprint(root, IN);
  insbit = INS;
 } else {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "found a match updating\n"));
  (*place_in_tree)->phon = node->phon;
  strcpy((*place_in_tree)->phon, node->phon);
  insbit = UPDATE;
 }
 return insbit;
}

variable_types: insbit int

variable_types: struct tnode { unsigned int op; char *name; char *last; char *phon; int count; struct tnode *left; struct tnode *parent; struct tnode *right; } **


decompiled_code:
__int64 __fastcall init_pbook(__int64 a1)
{
FILE *v1; // rax
__int64 v2; // r12

datafile = fs_house_keeping();
v1 = fopen((const char *)datafile, "r");
dbfp = v1;
if ( !v1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("dbfp is null\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
v2 = grow_btree(v1, a1);
fclose(dbfp);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
FILE *v1; // rax
__int64 v2; // r12

datafile = fs_house_keeping();
v1 = fopen((const char *)datafile, "r");
dbfp = v1;
if ( !v1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("dbfp is null\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
v2 = grow_btree(v1, a1);
fclose(dbfp);
return v2;
}

original_code:
tnode *
init_pbook(tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "r");
 if(dbfp == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "dbfp is null\n"));
  exit(1);
 }
 root = grow_btree(dbfp, root);
 fclose(dbfp);
 return root;
}

canonical_original_code:
struct tnode *init_pbook(struct tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "r");
 if(dbfp == ((void *)0)) {
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "dbfp is null\n"));
  exit(1);
 }
 root = grow_btree(dbfp, root);
 fclose(dbfp);
 return root;
}


decompiled_code:
__int64 __fastcall uinit_pbook(__int64 a1)
{
datafile = fs_house_keeping();
dbfp = fopen((const char *)datafile, "wb");
ugrow_btree(a1, dbfp);
fclose(dbfp);
return datafile;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
datafile = fs_house_keeping();
dbfp = fopen((const char *)datafile, "wb");
ugrow_btree(a1, dbfp);
fclose(dbfp);
return datafile;
}

original_code:
char *
uinit_pbook(tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "wb");
 ugrow_btree(root, dbfp);
 fclose(dbfp);
 return datafile;
}

canonical_original_code:
char *uinit_pbook(struct tnode *root) {
 datafile = fs_house_keeping();
 dbfp = fopen(datafile, "wb");
 ugrow_btree(root, dbfp);
 fclose(dbfp);
 return datafile;
}


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

if ( a2 == 1 )
{
dbfp = fopen(a1, "r+b");
if ( dbfp )
return 0LL;
puts("File cannot be opened.\n");
result = 1LL;
}
else
{
if ( a2 != 2 )
return 0LL;
dbfp = fopen(a1, "wb");
if ( dbfp )
return 0LL;
puts("File cannot be opened.\n");
result = 2LL;
}
return result;
}

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

if ( a2 == 1 )
{
dbfp = fopen(a1, "r+b");
if ( dbfp )
return 0LL;
puts("File cannot be opened.\n");
result = 1LL;
}
else
{
if ( a2 != 2 )
return 0LL;
dbfp = fopen(a1, "wb");
if ( dbfp )
return 0LL;
puts("File cannot be opened.\n");
result = 2LL;
}
return result;
}

original_code:
int
load_pbook(char *datafile, int prm) {
 int ret = 0;
 switch (prm) {
  case RB:
   if ((dbfp = fopen(datafile, "r+b")) == ((void *)0)) {
    puts("File cannot be opened.\n");
    ret = RB;
   }
   break;
  case WB:
   if ((dbfp = fopen(datafile, "wb")) == ((void *)0)) {
    puts("File cannot be opened.\n");
    ret = WB;
   }
   break;
  default:
   break;
 }
 return ret;
}

variable_types:
datafile
char *

variable_types: prm int

variable_types: ret int


decompiled_code:
int __fastcall html_header(const char *a1)
{
puts("Content-Type: text/html; charset=utf-8\n");
puts("<html>");
puts("<head>");
printf("<title>%s</title>\n", a1);
puts("</head>");
puts("<body>");
return puts("<pre>");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts("Content-Type: text/html; charset=utf-8\n");
puts("<html>");
puts("<head>");
printf("<title>%s</title>\n", a1);
puts("</head>");
puts("<body>");
return puts("<pre>");
}

original_code:
void
html_header(char *title){
 printf("Content-Type: text/html; charset=utf-8\n\n");
 printf("<html>\n");
 printf("<head>\n");
 printf("<title>%s</title>\n", title);
 printf("</head>\n");
 printf("<body>\n");
 printf("<pre>\n");
}

variable_types:
title
char *


decompiled_code:
int html_footer()
{
puts("
");
puts("");
return puts("");
}

canonical_decompiled_code:
int func1()
{
puts("
");
puts("");
return puts("");
}

original_code:
void
html_footer(void) {
 printf("
\n");
 printf("\n");
 printf("\n");
}

canonical_original_code:
void html_footer() {
 printf("
\n");
 printf("\n");
 printf("\n");
}


decompiled_code:
int create_pbook_directory()
{
dir = &datafile_path;
strcpy(&datafile_path, "./.config");
mkdir(&datafile_path, 0x1C0u);
strcat(dir, "/pbook");
return mkdir(dir, 0x1C0u);
}

canonical_decompiled_code:
int func0()
{
dir = &datafile_path;
strcpy(&datafile_path, "./.config");
mkdir(&datafile_path, 0x1C0u);
strcat(dir, "/pbook");
return mkdir(dir, 0x1C0u);
}

original_code:
void
create_pbook_directory()
{
 dir = ((void *)0);
 dir = datafile_path;
 strcpy(dir, ".");
 strcat(dir, "/.config");
 mkdir(dir, 0700);
 strcat(dir, "/pbook");
 mkdir(dir, 0700);
}


decompiled_code:
char *set_filename()
{
char *v0; // rbx
char *result; // rax

v0 = dir;
datafile = (__int64)&datafile_path_name;
result = &v0[strlen(dir)];
strcpy(result, "/phonebook");
datafile = (__int64)v0;
return result;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbx
char *result; // rax

v0 = dir;
datafile = (__int64)&datafile_path_name;
result = &v0[strlen(dir)];
strcpy(result, "/phonebook");
datafile = (__int64)v0;
return result;
}

original_code:
void
set_filename() {
 datafile = ((void *)0);
 datafile = datafile_path_name;
 datafile = strcat(dir, "/phonebook");
}


decompiled_code:
__int64 fs_house_keeping()
{
create_pbook_directory();
set_filename();
return datafile;
}

canonical_decompiled_code:
__int64 func2()
{
func0();
func1();
return datafile;
}

original_code:
char *
fs_house_keeping() {
 create_pbook_directory();
 set_filename();
 return datafile;
}

canonical_original_code:
char *fs_house_keeping() {
 create_pbook_directory();
 set_filename();
 return datafile;
}


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

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

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

result = socket(1, 1, 0);
if ( result == -1 )
{
perror("socket");
exit(1);
}
return result;
}

original_code:
int
mk_socket() {
 int s;
 if ((s = socket(1, SOCK_STREAM, 0)) == -1) {
  perror("socket");
  exit(1);
 }
 return s;
}

variable_types: s int


decompiled_code:
__int64 __fastcall parse_op(char *dest)
{
unsigned int v1; // er13
_DWORD *v2; // rbp
__int64 v4; // rax

v2 = (_DWORD *)l2node(dest, delim);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op");
if ( *v2 == 1 )
{
v1 = 0;
v4 = *(_QWORD *)lookup(root, v2);
if ( v4 )
strcpy(dest, *(const char **)(v4 + 24));
}
else if ( *v2 == 3 )
{
v1 = ins_node(root, v2);
uinit_pbook(root);
if ( v1 == 2 )
v1 = 0;
}
free(v2);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *dest)
{
unsigned int v1; // er13
_DWORD *v2; // rbp
__int64 v4; // rax

v2 = (_DWORD *)l2node(dest, delim);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op");
if ( *v2 == 1 )
{
v1 = 0;
v4 = *(_QWORD *)lookup(root, v2);
if ( v4 )
strcpy(dest, *(const char **)(v4 + 24));
}
else if ( *v2 == 3 )
{
v1 = ins_node(root, v2);
uinit_pbook(root);
if ( v1 == 2 )
v1 = 0;
}
free(v2);
return v1;
}

original_code:
int
parse_op(char *bufp) {
 int insbit;
 tnode *qn = ((void *)0);
 tnode **qnp = ((void *)0);
 qn = l2node(bufp, delim);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op"));
 switch (qn->op) {
  case LOOKUP:
   if ((*(qnp = lookup(root, qn))) != ((void *)0))
    strcpy(bufp, (*qnp)->phon);
   else
    insbit = NONE;
   break;
  case UPDATE:
   insbit = ins_node(root, qn);
   uinit_pbook(root);
   switch (insbit) {
    case INS:
     insbit = NONE;
     break;
    case UPDATE:
     insbit = UPDATE;
     break;
    default:
     break;
   }
  default:
   break;
 }
 free(qn);
 return insbit;
}

canonical_original_code:
int parse_op(char *bufp) {
 int insbit;
 struct tnode *qn = ((void *)0);
 struct tnode **qnp = ((void *)0);
 qn = l2node(bufp, delim);
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "parse_op"));
 switch (qn->op) {
  case LOOKUP:
   if ((*(qnp = lookup(root, qn))) != ((void *)0))
    strcpy(bufp, (*qnp)->phon);
   else
    insbit = NONE;
   break;
  case UPDATE:
   insbit = ins_node(root, qn);
   uinit_pbook(root);
   switch (insbit) {
    case INS:
     insbit = NONE;
     break;
    case UPDATE:
     insbit = UPDATE;
     break;
    default:
     break;
   }
  default:
   break;
 }
 free(qn);
 return insbit;
}

variable_types:
bufp
char *


decompiled_code:
__int64 __fastcall read_from_client(int fd)
{
int v1; // eax
size_t v2; // rax
ssize_t v3; // r8
__int64 result; // rax
__int128 buf[5]; // [rsp+14h] [rbp-68h] BYREF
__int16 v6; // [rsp+64h] [rbp-18h]
char v7; // [rsp+66h] [rbp-16h]

v6 = 0;
buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
v7 = 0;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "read()");
v1 = read(fd, buf, 0x53uLL);
*((_BYTE *)buf + v1) = 0;
if ( v1 < 0 )
{
perror("read");
exit(1);
}
if ( !v1 )
return 0xFFFFFFFFLL;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
if ( !(unsigned int)parse_op((char *)buf) )
LOWORD(buf[0]) = 48;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
v2 = strlen((const char *)buf);
v3 = send(fd, buf, v2 + 1, 0);
result = 0LL;
if ( v3 < 0 )
{
perror("send");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
int v1; // eax
size_t v2; // rax
ssize_t v3; // r8
__int64 result; // rax
__int128 buf[5]; // [rsp+14h] [rbp-68h] BYREF
__int16 v6; // [rsp+64h] [rbp-18h]
char v7; // [rsp+66h] [rbp-16h]

v6 = 0;
buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
v7 = 0;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "read()");
v1 = read(fd, buf, 0x53uLL);
*((_BYTE *)buf + v1) = 0;
if ( v1 < 0 )
{
perror("read");
exit(1);
}
if ( !v1 )
return 0xFFFFFFFFLL;
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
if ( !(unsigned int)func1((char *)buf) )
LOWORD(buf[0]) = 48;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "send()");
fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, (const char *)buf);
v2 = strlen((const char *)buf);
v3 = send(fd, buf, v2 + 1, 0);
result = 0LL;
if ( v3 < 0 )
{
perror("send");
result = 0LL;
}
return result;
}

original_code:
int
read_from_client(int filedes) {
 char buf[((4*20) + 2 + 1)] = {0};
 char *bufp = buf;
 int nbytes;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "read()"));
 nbytes = read (filedes, buf, ((4*20) + 2 + 1));
 bufp[nbytes] = '\0';
 if (nbytes < 0) {
    perror ("read");
    exit (1);
 }
 else if (nbytes == 0)
  return -1;
 else {
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (parse_op(bufp) == NONE) {
   char none[] = "0";
   char *nonep = none;
   strcpy(bufp, nonep);
  }
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (send(filedes, bufp, (strlen(bufp)+1), 0) < 0) {
   perror("send");
  }
  return 0;
 }
}

canonical_original_code:
int read_from_client(int filedes) {
 char buf[-1] = {0};
 char *bufp = buf;
 int nbytes;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "read()"));
 nbytes = read (filedes, buf, ((4*20) + 2 + 1));
 bufp[nbytes] = '\0';
 if (nbytes < 0) {
    perror ("read");
    exit (1);
 }
 else if (nbytes == 0)
  return -1;
 else {
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (parse_op(bufp) == NONE) {
   char none[] = "0";
   char *nonep = none;
   strcpy(bufp, nonep);
  }
  (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "send()"));
  (fprintf(stderr, "%-*s = %-*s\n", 10, "bufp", 10, bufp));
  if (send(filedes, bufp, (strlen(bufp)+1), 0) < 0) {
   perror("send");
  }
  return 0;
 }
}

variable_types: filedes int

variable_types:
buf
char [-1]

variable_types: nbytes int

variable_types:
nonep
char *


decompiled_code:
int recv_send_2pbk_skt()
{
int v0; // er14
int v1; // eax
int v2; // ebp
__int64 v3; // rdx
__int64 v4; // rsi
FILE *v5; // rcx
__m128i v6; // xmm1
__m128i v7; // xmm2
__m128i v8; // xmm3
__m128i v9; // xmm4
__m128i v10; // xmm5
__m128i v11; // xmm6
__m128i v12; // xmm7
int v13; // er13
int i; // ebx
__fd_mask v15; // rax
int v16; // er12
int v18; // [rsp+Ch] [rbp-2ACh]
socklen_t addr_len[2]; // [rsp+18h] [rbp-2A0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-298h] BYREF
struct sockaddr v21; // [rsp+90h] [rbp-228h] BYREF
__m128i v22[8]; // [rsp+100h] [rbp-1B8h] BYREF
fd_set readfds; // [rsp+180h] [rbp-138h] BYREF
__int64 v24[23]; // [rsp+200h] [rbp-B8h] BYREF

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt");
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("creating the socket\n", 1uLL, 0x14uLL, stderr);
v0 = mk_socket();
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
addr.sa_family = 1;
strcpy(addr.sa_data, "/tmp/22294");
unlink(addr.sa_data);
v1 = strlen(addr.sa_data);
if ( bind(v0, &addr, v1 + 2) == -1 )
{
perror("bind");
exit(1);
}
if ( listen(v0, 5) == -1 )
{
perror("listen");
exit(1);
}
memset(v22, 0, sizeof(v22));
v2 = fileno(stdin);
v22[0].m128i_i64[v2 / 64] |= 1LL << (v2 % 64);
v3 = v0 / 64;
v4 = 1LL << (v0 % 64);
v22[0].m128i_i64[v3] |= v4;
memset(v24, 0, 0x80uLL);
v5 = stderr;
v24[v3] |= v4;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, v5);
fwrite("send \"EOF\" with Ctrl-D to stop the daemon or\n", 1uLL, 0x2DuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Waiting for a connection...\n", 1uLL, 0x1CuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("selecting the set\n", 1uLL, 0x12uLL, stderr);
do
{
v6 = _mm_loadu_si128(&v22[1]);
v7 = _mm_loadu_si128(&v22[2]);
v8 = _mm_loadu_si128(&v22[3]);
v9 = _mm_loadu_si128(&v22[4]);
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v22);
v10 = _mm_loadu_si128(&v22[5]);
*(__m128i *)&readfds.fds_bits[2] = v6;
v11 = _mm_loadu_si128(&v22[6]);
v12 = _mm_loadu_si128(&v22[7]);
*(__m128i *)&readfds.fds_bits[4] = v7;
*(__m128i *)&readfds.fds_bits[6] = v8;
*(__m128i *)&readfds.fds_bits[8] = v9;
*(__m128i *)&readfds.fds_bits[10] = v10;
*(__m128i *)&readfds.fds_bits[12] = v11;
*(__m128i *)&readfds.fds_bits[14] = v12;
if ( select(1024, &readfds, 0LL, 0LL, 0LL) < 0 )
{
perror("select");
exit(1);
}
v18 = 0;
v13 = 1;
for ( i = 0; ; ++i )
{
v15 = readfds.fds_bits[i >> 6] & (1LL << i);
if ( !v15 )
goto LABEL_7;
if ( v0 == i )
break;
if ( v2 == i )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("not sock\n", 1uLL, 9uLL, stderr);
LODWORD(v15) = getchar();
if ( (_DWORD)v15 == -1 )
{
LODWORD(v15) = close(v0);
if ( v13 == 1024 )
return v15;
v18 = 1;
goto LABEL_8;
}
}
LABEL_7:
if ( v13 == 1024 )
goto LABEL_13;
LABEL_8:
++v13;
}
*(_QWORD *)addr_len = 110LL;
v16 = accept(v0, &v21, addr_len);
if ( v16 < 0 )
{
perror("accept");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Connected.\n", 1uLL, 0xBuLL, stderr);
read_from_client(v16);
v15 = v16 >> 6;
v22[0].m128i_i64[v15] |= 1LL << v16;
if ( v13 != 1024 )
goto LABEL_8;
LABEL_13:
;
}
while ( v18 != 1 );
return v15;
}

canonical_decompiled_code:
int func3()
{
int v0; // er14
int v1; // eax
int v2; // ebp
__int64 v3; // rdx
__int64 v4; // rsi
FILE *v5; // rcx
__m128i v6; // xmm1
__m128i v7; // xmm2
__m128i v8; // xmm3
__m128i v9; // xmm4
__m128i v10; // xmm5
__m128i v11; // xmm6
__m128i v12; // xmm7
int v13; // er13
int i; // ebx
__fd_mask v15; // rax
int v16; // er12
int v18; // [rsp+Ch] [rbp-2ACh]
socklen_t addr_len[2]; // [rsp+18h] [rbp-2A0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-298h] BYREF
struct sockaddr v21; // [rsp+90h] [rbp-228h] BYREF
__m128i v22[8]; // [rsp+100h] [rbp-1B8h] BYREF
fd_set readfds; // [rsp+180h] [rbp-138h] BYREF
__int64 v24[23]; // [rsp+200h] [rbp-B8h] BYREF

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt");
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("creating the socket\n", 1uLL, 0x14uLL, stderr);
v0 = func0();
fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
addr.sa_family = 1;
strcpy(addr.sa_data, "/tmp/22294");
unlink(addr.sa_data);
v1 = strlen(addr.sa_data);
if ( bind(v0, &addr, v1 + 2) == -1 )
{
perror("bind");
exit(1);
}
if ( listen(v0, 5) == -1 )
{
perror("listen");
exit(1);
}
memset(v22, 0, sizeof(v22));
v2 = fileno(stdin);
v22[0].m128i_i64[v2 / 64] |= 1LL << (v2 % 64);
v3 = v0 / 64;
v4 = 1LL << (v0 % 64);
v22[0].m128i_i64[v3] |= v4;
memset(v24, 0, 0x80uLL);
v5 = stderr;
v24[v3] |= v4;
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, v5);
fwrite("send \"EOF\" with Ctrl-D to stop the daemon or\n", 1uLL, 0x2DuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Waiting for a connection...\n", 1uLL, 0x1CuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("selecting the set\n", 1uLL, 0x12uLL, stderr);
do
{
v6 = _mm_loadu_si128(&v22[1]);
v7 = _mm_loadu_si128(&v22[2]);
v8 = _mm_loadu_si128(&v22[3]);
v9 = _mm_loadu_si128(&v22[4]);
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v22);
v10 = _mm_loadu_si128(&v22[5]);
*(__m128i *)&readfds.fds_bits[2] = v6;
v11 = _mm_loadu_si128(&v22[6]);
v12 = _mm_loadu_si128(&v22[7]);
*(__m128i *)&readfds.fds_bits[4] = v7;
*(__m128i *)&readfds.fds_bits[6] = v8;
*(__m128i *)&readfds.fds_bits[8] = v9;
*(__m128i *)&readfds.fds_bits[10] = v10;
*(__m128i *)&readfds.fds_bits[12] = v11;
*(__m128i *)&readfds.fds_bits[14] = v12;
if ( select(1024, &readfds, 0LL, 0LL, 0LL) < 0 )
{
perror("select");
exit(1);
}
v18 = 0;
v13 = 1;
for ( i = 0; ; ++i )
{
v15 = readfds.fds_bits[i >> 6] & (1LL << i);
if ( !v15 )
goto LABEL_7;
if ( v0 == i )
break;
if ( v2 == i )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("not sock\n", 1uLL, 9uLL, stderr);
LODWORD(v15) = getchar();
if ( (_DWORD)v15 == -1 )
{
LODWORD(v15) = close(v0);
if ( v13 == 1024 )
return v15;
v18 = 1;
goto LABEL_8;
}
}
LABEL_7:
if ( v13 == 1024 )
goto LABEL_13;
LABEL_8:
++v13;
}
*(_QWORD *)addr_len = 110LL;
v16 = accept(v0, &v21, addr_len);
if ( v16 < 0 )
{
perror("accept");
exit(1);
}
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("Connected.\n", 1uLL, 0xBuLL, stderr);
func2(v16);
v15 = v16 >> 6;
v22[0].m128i_i64[v15] |= 1LL << v16;
if ( v13 != 1024 )
goto LABEL_8;
LABEL_13:
;
}
while ( v18 != 1 );
return v15;
}

original_code:
void
recv_send_2pbk_skt() {
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt"));
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 int len;
 size_t size;
 struct sockaddr_un local, pbkc;
 int sock;
 fd_set active_fd_set, read_fd_set, write_fd_set;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "creating the socket\n"));
 sock = mk_socket();
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 local.sun_family = 1;
 strcpy(local.sun_path, "/tmp/22294");
 unlink(local.sun_path);
 len = strlen(local.sun_path) + sizeof(local.sun_family);
 if (bind(sock, (struct sockaddr *)&local, len) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(sock, 5) == -1) {
  perror("listen");
  exit(1);
 }
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&active_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 int stdinfd = fileno(stdin);
 ((void) (((&active_fd_set)->__fds_bits)[((stdinfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((stdinfd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&active_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&write_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "send \"EOF\" with Ctrl-D to stop the daemon or\n"));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Waiting for a connection...\n"));
 int i;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "selecting the set\n"));
 int sig = START;
 while(sig != KILL) {
 read_fd_set = active_fd_set;
 if (select (1024, &read_fd_set, ((void *)0), ((void *)0), ((void *)0)) < 0) {
  perror ("select");
  exit (1);
 }
 for (i = 0; i < 1024; ++i) {
  if (((((&read_fd_set)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (i == sock) {
    int new;
    size = sizeof(pbkc);
    new = accept (sock,
      (struct sockaddr *) &pbkc,
      &size);
    if (new < 0) {
     perror ("accept");
     exit (1);
    }
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Connected.\n"));
    read_from_client (new);
    ((void) (((&active_fd_set)->__fds_bits)[((new) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new) % (8 * (int) sizeof (__fd_mask)))))));
   }
   else if (i == stdinfd) {
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "not sock\n"));
    int c;
    if((c=getchar()) == (-1)) {
     close(sock);
     sig = KILL;
    }
   }
  }
 }
 }
}

canonical_original_code:
void recv_send_2pbk_skt() {
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "recv_send_2pbk_skt"));
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 int len;
 unsigned long size;
 struct sockaddr_un local; struct sockaddr_un pbkc;
 int sock;
 struct fd_set active_fd_set; struct fd_set read_fd_set; struct fd_set write_fd_set;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "creating the socket\n"));
 sock = mk_socket();
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 local.sun_family = 1;
 strcpy(local.sun_path, "/tmp/22294");
 unlink(local.sun_path);
 len = strlen(local.sun_path) + sizeof(local.sun_family);
 if (bind(sock, (struct sockaddr *)&local, len) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(sock, 5) == -1) {
  perror("listen");
  exit(1);
 }
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&active_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 int stdinfd = fileno(stdin);
 ((void) (((&active_fd_set)->__fds_bits)[((stdinfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((stdinfd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&active_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_fd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&write_fd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "send \"EOF\" with Ctrl-D to stop the daemon or\n"));
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Waiting for a connection...\n"));
 int i;
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "selecting the set\n"));
 int sig = START;
 while(sig != KILL) {
 read_fd_set = active_fd_set;
 if (select (1024, &read_fd_set, ((void *)0), ((void *)0), ((void *)0)) < 0) {
  perror ("select");
  exit (1);
 }
 for (i = 0; i < 1024; ++i) {
  if (((((&read_fd_set)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (i == sock) {
    int new;
    size = sizeof(pbkc);
    new = accept (sock,
      (struct sockaddr *) &pbkc,
      &size);
    if (new < 0) {
     perror ("accept");
     exit (1);
    }
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "Connected.\n"));
    read_from_client (new);
    ((void) (((&active_fd_set)->__fds_bits)[((new) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new) % (8 * (int) sizeof (__fd_mask)))))));
   }
   else if (i == stdinfd) {
    (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "not sock\n"));
    int c;
    if((c=getchar()) == (-1)) {
     close(sock);
     sig = KILL;
    }
   }
  }
 }
 }
}

variable_types: len int

variable_types:
size
unsigned long

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: sock int

variable_types: stdinfd int

variable_types: i int

variable_types: sig int

variable_types: new int

variable_types: c int


pbkd

decompiled_code:
size_t __fastcall pbkd(int a1)
{
size_t result; // rax

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "pbkd");
result = fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
if ( !a1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("started pbd in foreground mode\n", 1uLL, 0x1FuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("calling recv_send_2pbk_skt\n", 1uLL, 0x1BuLL, stderr);
result = recv_send_2pbk_skt();
}
return result;
}

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

fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fprintf(stderr, "ENTERED: %-*s: ", 12, "pbkd");
result = fwrite("\x1B[1m\x1B[37m [DONE] \n\x1B[0m", 1uLL, 0x18uLL, stderr);
if ( !a1 )
{
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("started pbd in foreground mode\n", 1uLL, 0x1FuLL, stderr);
fwrite("\x1B[1m\x1B[37m [DEBUG] \x1B[0m", 1uLL, 0x18uLL, stderr);
fwrite("calling recv_send_2pbk_skt\n", 1uLL, 0x1BuLL, stderr);
result = recv_send_2pbk_skt();
}
return result;
}

original_code:
void
pbkd(int mode) {
 (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "ENTERED: %-*s: ", 12, "pbkd"));
 fprintf(stderr, "\033[1m\033[37m" "  [DONE]  \n" "\033[0m");
 switch (mode) {
  case START:
   (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "started pbd in foreground mode\n"));
   (fprintf(stderr, "\033[1m\033[37m" "  [DEBUG]  " "\033[0m"), fprintf(stderr, "calling recv_send_2pbk_skt\n"));
   recv_send_2pbk_skt();
   break;
  case KILL:
   break;
  default:
   break;
 }
}

variable_types: mode int


decompiled_code:
__int64 __fastcall pb_getline(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // eax

v2 = 0LL;
while ( 1 )
{
v3 = getchar();
if ( v3 == -1 )
break;
if ( v3 == 10 )
goto LABEL_8;
if ( a2 - 1 > (int)v2 )
*(_BYTE *)(a1 + v2++) = v3;
}
if ( (_DWORD)v2 )
{
LABEL_8:
*(_BYTE *)(a1 + (int)v2) = 0;
exit(1);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // eax

v2 = 0LL;
while ( 1 )
{
v3 = getchar();
if ( v3 == -1 )
break;
if ( v3 == 10 )
goto LABEL_8;
if ( a2 - 1 > (int)v2 )
*(_BYTE *)(a1 + v2++) = v3;
}
if ( (_DWORD)v2 )
{
LABEL_8:
*(_BYTE *)(a1 + (int)v2) = 0;
exit(1);
}
return 0xFFFFFFFFLL;
}

original_code:
int pb_getline(char line[], int max)
{
 int nch = 0;
 int c;
 max = max - 1;
  while((c = getchar()) != (-1)) {
   if(c == '\n')
    break;
   if(nch < max) {
    line[nch] = c;
    nch = nch + 1;
   }
  }
 if(c == (-1) && nch == 0)
  return (-1);
 line[nch] = '\0';
 exit(1);
}

variable_types:
line
char []

variable_types: max int

variable_types: nch int


xctod

decompiled_code:
__int64 __fastcall xctod(int a1)
{
unsigned __int16 v1; // ax
bool v2; // zf
__int64 result; // rax

v1 = (*_ctype_b_loc())[a1];
if ( (v1 & 0x800) != 0 )
return (unsigned int)(a1 - 48);
if ( (v1 & 0x100) != 0 )
return (unsigned int)(a1 - 55);
v2 = (v1 & 0x200) == 0;
result = 0LL;
if ( !v2 )
result = (unsigned int)(a1 - 87);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int16 v1; // ax
bool v2; // zf
__int64 result; // rax

v1 = (*_ctype_b_loc())[a1];
if ( (v1 & 0x800) != 0 )
return (unsigned int)(a1 - 48);
if ( (v1 & 0x100) != 0 )
return (unsigned int)(a1 - 55);
v2 = (v1 & 0x200) == 0;
result = 0LL;
if ( !v2 )
result = (unsigned int)(a1 - 87);
return result;
}

original_code:
static int xctod(int c)
{
 if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
  return c - '0';
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISupper))
  return c - 'A' + 10;
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISlower))
  return c - 'a' + 10;
 else
  return 0;
}

canonical_original_code:
static int xctod(int c)
{
 if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
  return c - '0';
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISupper))
  return c - 'A' + 10;
 else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISlower))
  return c - 'a' + 10;
 else
  return 0;
}


canonical_original_code:
void hexdump_addr(unsigned char *buf, int len, unsigned int addr_start)
{
  int i;
  unsigned char str[17];
  str[16] = 0;
  for(i = 0; i < len; i++) {
    if(!(i % 16)) printf("%08x  ", i + addr_start);
    str[i % 16] = ((buf[i] >= 32 && buf[i] <= 126) ? buf[i] : '.');
    printf("%02x ", buf[i]);
    if(!((i+1) % 8)) {
      if(!((i+1) % 16))
        printf(" %s\n", str);
      else
        printf(" ");
    }
  }
  i = 16 - (i % 16);
  str[16 - i] = 0;
  if(i > 0 && i < 16) {
    if(i > 8) printf(" ");
    while(i--)
      printf("   ");
    printf(" %s\n", str);
  }
}

variable_types:
buf
unsigned char *

variable_types:
str
unsigned char [17]


decompiled_code:
unsigned __int64 __fastcall read_data(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 i; // r12
ssize_t v5; // rax

if ( !a3 )
return 0LL;
for ( i = 0LL; i < a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( !v5 )
break;
}
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 i; // r12
ssize_t v5; // rax

if ( !a3 )
return 0LL;
for ( i = 0LL; i < a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( !v5 )
break;
}
return i;
}

original_code:
size_t read_data( int fd , void * buf , size_t size )
{
 size_t sr = 0;
 while( sr < size )
 {
  size_t ret = read( fd , ((char*)buf)+sr , size - sr );
  if( ret == 0 ) break;
  sr += ret;
 }
 return sr;
}

canonical_original_code:
unsigned long read_data(int fd, void *buf, unsigned long size)
{
 unsigned long sr = 0;
 while( sr < size )
 {
  unsigned long ret = read( fd , ((char*)buf)+sr , size - sr );
  if( ret == 0 ) break;
  sr += ret;
 }
 return sr;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
sr
unsigned long

variable_types:
ret
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall read_termios(int fd, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a2 + 17;
v3 = a2 + 36;
read_data(fd, a2, 0x20uLL);
do
{
v4 = v2++;
read_data(fd, v4, 1uLL);
}
while ( v2 != v3 );
return 51LL;
}

original_code:
size_t read_termios( int fd , struct termios* buf )
{
 read_data( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  read_data( fd , buf->c_cc + i , sizeof(cc_t) );
 return 32 + 19;
}

canonical_original_code:
unsigned long read_termios(int fd, struct termios *buf)
{
 read_data( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  read_data( fd , buf->c_cc + i , sizeof(cc_t) );
 return 32 + 19;
}

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


decompiled_code:
__int64 __fastcall write_termios(int fd, char *a2)
{
char *v2; // rbx
char *v3; // rbp
char *v4; // rsi

v2 = a2 + 17;
v3 = a2 + 36;
write(fd, a2, 0x20uLL);
do
{
v4 = v2++;
write(fd, v4, 1uLL);
}
while ( v2 != v3 );
return 51LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, char *a2)
{
char *v2; // rbx
char *v3; // rbp
char *v4; // rsi

v2 = a2 + 17;
v3 = a2 + 36;
write(fd, a2, 0x20uLL);
do
{
v4 = v2++;
write(fd, v4, 1uLL);
}
while ( v2 != v3 );
return 51LL;
}

original_code:
size_t write_termios( int fd , const struct termios *buf )
{
 write( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  write( fd , buf->c_cc + i , 1 );
 return 32 + 19;
}

canonical_original_code:
unsigned long write_termios(int fd, struct termios *buf)
{
 write( fd , buf , 32 );
 int i;
 for( i = 0 ; i < 19 ; i ++ )
  write( fd , buf->c_cc + i , 1 );
 return 32 + 19;
}

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


decompiled_code:
unsigned __int64 __fastcall read_vdata(int fd, _QWORD *a2)
{
unsigned __int64 v2; // r12
void *v3; // rax
size_t size[3]; // [rsp+Ch] [rbp-1Ch] BYREF

read_data(fd, (__int64)size, 4uLL);
v2 = LODWORD(size[0]);
v3 = malloc(LODWORD(size[0]));
*a2 = v3;
return read_data(fd, (__int64)v3, v2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(int fd, _QWORD *a2)
{
unsigned __int64 v2; // r12
void *v3; // rax
size_t size[3]; // [rsp+Ch] [rbp-1Ch] BYREF

func0(fd, (__int64)size, 4uLL);
v2 = LODWORD(size[0]);
v3 = malloc(LODWORD(size[0]));
*a2 = v3;
return func0(fd, (__int64)v3, v2);
}

original_code:
size_t read_vdata( int fd , char **buf)
{
 unsigned int sz;
 size_t ret = 0;
 read_data( fd , &sz , sizeof(sz) );
 *buf = (char*)malloc(sz);
 ret += read_data( fd , *buf , sz );
 return ret;
}

canonical_original_code:
unsigned long read_vdata(int fd, char **buf)
{
 unsigned int sz;
 unsigned long ret = 0;
 read_data( fd , &sz , sizeof(sz) );
 *buf = (char *)malloc(sz);
 ret += read_data( fd , *buf , sz );
 return ret;
}

variable_types:
buf
char **

variable_types:
sz
unsigned int


decompiled_code:
ssize_t __fastcall write_vdata(int fd, void *buf, unsigned int a3)
{
ssize_t v3; // rbx
unsigned int bufa[7]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
v3 = write(fd, bufa, 4uLL);
return v3 + write(fd, buf, bufa[0]);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, void *buf, unsigned int a3)
{
ssize_t v3; // rbx
unsigned int bufa[7]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
v3 = write(fd, bufa, 4uLL);
return v3 + write(fd, buf, bufa[0]);
}

original_code:
size_t write_vdata( int fd , char *buf , unsigned int size)
{
 size_t ret = write( fd , &size , sizeof(unsigned int) );
 ret += write( fd , buf , size );
 return ret;
}

canonical_original_code:
unsigned long write_vdata(int fd, char *buf, unsigned int size)
{
 unsigned long ret = write( fd , &size , sizeof(unsigned int) );
 ret += write( fd , buf , size );
 return ret;
}

variable_types:
buf
char *

variable_types:
size
unsigned int


decompiled_code:
unsigned __int64 __fastcall read_concmd(int a1, __int64 a2)
{
return read_data(a1, a2, 0x1CuLL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(int a1, __int64 a2)
{
return func0(a1, a2, 0x1CuLL);
}

original_code:
size_t read_concmd( int fd , struct concmd *buf )
{
 size_t ret = 0;
 ret += read_data( fd , buf , sizeof(struct concmd) );
 return ret;
}

canonical_original_code:
unsigned long read_concmd(int fd, struct concmd *buf)
{
 unsigned long ret = 0;
 ret += read_data( fd , buf , sizeof(struct concmd) );
 return ret;
}

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


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 v3; // r12
unsigned __int64 v4; // r12
_QWORD *v5; // rbp
int v6; // ebx
_QWORD *v7; // rsi

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

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

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

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: struct shellparm { char *sp_exec; int sp_argc; char *sp_argv[255]; } *

variable_types: i int


decompiled_code:
ssize_t __fastcall write_shellparm(int fd, const char **a2)
{
char *v2; // rbp
int v3; // eax
ssize_t v4; // r12
ssize_t v5; // r12
__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);
}
while ( *((_DWORD *)a2 + 2) > (int)v6 );
}
return v5;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, const char **a2)
{
char *v2; // rbp
int v3; // eax
ssize_t v4; // r12
ssize_t v5; // r12
__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);
}
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:
__int64 __fastcall write_pushpram(int fd, char **a2)
{
char *v2; // r12
int v3; // eax
ssize_t v4; // rax
char *v5; // r13
ssize_t v6; // r12
int v7; // eax
ssize_t v8; // r12
ssize_t v9; // r12

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

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

v2 = *a2;
v3 = strlen(*a2);
v4 = func4(fd, v2, v3 + 1);
v5 = a2[1];
v6 = v4;
v7 = strlen(v5);
v8 = func4(fd, v5, v7 + 1) + v6;
v9 = write(fd, a2 + 2, 4uLL) + v8;
return v9 + 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)
{
__m128i v1; // xmm0
__m128i v2; // xmm1
__m128i v3; // xmm2
int *v5; // rax
int v6; // er12
int *v7; // rbx
struct termios v8; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
__m128i v1; // xmm0
__m128i v2; // xmm1
__m128i v3; // xmm2
int *v5; // rax
int v6; // er12
int *v7; // rbx
struct termios v8; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

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

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


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


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

decompiled_code:
int __fastcall solve(int a1, __int64 a2, int a3, _DWORD *a4)
{
__int64 v5; // rcx
__int64 v6; // rdx
int v7; // eax
__int64 v8; // rax
int v9; // er8

if ( a3 <= 0 )
{
LABEL_5:
LODWORD(v8) = puts("COULDN'T FIND SOLUTION");
}
else
{
v5 = a3;
v6 = 0LL;
while ( 1 )
{
v7 = *(_DWORD *)(a2 + 4 * v6);
if ( v7 < a1 )
break;
LABEL_4:
if ( v5 == ++v6 )
goto LABEL_5;
}
v9 = a1 - v7;
v8 = 0LL;
while ( (_DWORD)v6 == (_DWORD)v8 || *(_DWORD *)(a2 + 4 * v8) != v9 )
{
if ( v5 == ++v8 )
goto LABEL_4;
}
*a4 = v6 + 1;
a4[1] = v8 + 1;
}
return v8;
}

canonical_decompiled_code:
int __fastcall func9(int a1, __int64 a2, int a3, _DWORD *a4)
{
__int64 v5; // rcx
__int64 v6; // rdx
int v7; // eax
__int64 v8; // rax
int v9; // er8

if ( a3 <= 0 )
{
LABEL_5:
LODWORD(v8) = puts("COULDN'T FIND SOLUTION");
}
else
{
v5 = a3;
v6 = 0LL;
while ( 1 )
{
v7 = *(_DWORD *)(a2 + 4 * v6);
if ( v7 < a1 )
break;
LABEL_4:
if ( v5 == ++v6 )
goto LABEL_5;
}
v9 = a1 - v7;
v8 = 0LL;
while ( (_DWORD)v6 == (_DWORD)v8 || *(_DWORD *)(a2 + 4 * v8) != v9 )
{
if ( v5 == ++v8 )
goto LABEL_4;
}
*a4 = v6 + 1;
a4[1] = v8 + 1;
}
return v8;
}

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);
val[dword_404440] = a1;
dword_404440 = result + 1;
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);
val[dword_404440] = a1;
dword_404440 = result + 1;
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()
{
int result; // eax
int v1; // ecx

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

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

if ( dword_404440 <= 1 )
return puts("error: less than 2 elements");
result = dword_404440 - 2;
v1 = (int)val[dword_404440 - 1];
val[dword_404440 - 1] = 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


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(0x80000000LL, v4);
printf("origin: %s\n", v4);
itoa(0x80000000LL, 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(0x80000000LL, v4);
printf("origin: %s\n", v4);
func9(0x80000000LL, 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;
}


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, char *a2)
{
itoa_helper(a1, a2);
reverse(a2);
}

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

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


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);
val[dword_404460] = a1;
dword_404460 = result + 1;
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);
val[dword_404460] = a1;
dword_404460 = result + 1;
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()
{
int result; // eax
int v1; // ecx

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

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

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


func

decompiled_code:
int __fastcall func(const char *a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double y; // [rsp+8h] [rbp-10h]

if ( !strcmp(a1, "sin") )
{
v5 = pop();
v2 = sin(v5);
return push(v2);
}
if ( !strcmp(a1, "cos") )
{
v4 = pop();
v2 = cos(v4);
return push(v2);
}
if ( !strcmp(a1, "exp") )
{
v6 = pop();
v2 = exp(v6);
return push(v2);
}
if ( !strcmp(a1, "pow") )
{
y = pop();
v1 = pop();
v2 = pow(v1, y);
return push(v2);
}
return printf("%s is not a supported function.\n", a1);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double y; // [rsp+8h] [rbp-10h]

if ( !strcmp(a1, "sin") )
{
v5 = func8();
v2 = sin(v5);
return func7(v2);
}
if ( !strcmp(a1, "cos") )
{
v4 = func8();
v2 = cos(v4);
return func7(v2);
}
if ( !strcmp(a1, "exp") )
{
v6 = func8();
v2 = exp(v6);
return func7(v2);
}
if ( !strcmp(a1, "pow") )
{
y = func8();
v1 = func8();
v2 = pow(v1, y);
return func7(v2);
}
return printf("%s is not a supported function.\n", a1);
}

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(__int64 a1, __int64 a2, char a3, unsigned int a4)
{
int v4; // eax
int v5; // er8
int v6; // er10
char v7; // r9

v4 = getbits(a4, a3 - 1, a3);
return (v6 & (unsigned int)~v5) + (v4 << v7);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, char a3, unsigned int a4)
{
int v4; // eax
int v5; // er8
int v6; // er10
char v7; // r9

v4 = func7(a4, a3 - 1, a3);
return (v6 & (unsigned int)~v5) + (v4 << v7);
}

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