decompiled_code:
void *__fastcall http_handler(void *a1)
{
int v1; // er15
const char *v2; // rbp
size_t v3; // r14
char *v4; // rbx
char *v5; // r13
ssize_t v6; // rax
_BYTE *v7; // rax
__int64 v8; // rdx
char *v9; // rax
char *v10; // rbx
const char *v11; // r12
char *v12; // rax
char v13; // al
unsigned int v14; // ebx
int v15; // eax
int v16; // ebp
int v18; // eax
int fd; // [rsp+Ch] [rbp-8DCh]
struct stat stat_buf; // [rsp+10h] [rbp-8D8h] BYREF
off_t offset; // [rsp+A8h] [rbp-840h] BYREF
char s[1024]; // [rsp+B0h] [rbp-838h] BYREF
char buf[1080]; // [rsp+4B0h] [rbp-438h] BYREF

v1 = (int)a1;
fd = (int)a1;
v2 = 0LL;
v3 = 1024LL;
v4 = buf;
v5 = buf;
LABEL_2:
v6 = recv((int)a1, v5, v3, 0);
if ( v6 )
{
if ( v6 < 0 )
{
perror("read");
}
else
{
v5 += v6;
v3 -= v6;
while ( 1 )
{
v7 = memchr(v4, 10, v5 - v4);
if ( !v7 )
goto LABEL_2;
*v7 = 0;
v8 = v7 - v4;
if ( v7 - v4 > 0 && *(v7 - 1) == 13 )
*(v7 - 1) = 0;
if ( v8 == 1 || v8 == 2 && !*(v7 - 1) )
break;
if ( v4 == buf )
v2 = buf;
v4 = v7 + 1;
}
if ( !v2 )
{
fwrite("empty HTTP request\n", 1uLL, 0x13uLL, stderr);
goto LABEL_32;
}
v9 = strchr(v2, 32);
v10 = v9;
if ( !v9 )
goto LABEL_28;
v11 = v9 + 1;
*v9 = 0;
if ( strcmp(v2, "GET") )
{
fprintf(stderr, "unsupported method '%s'\n", v2);
goto LABEL_32;
}
v12 = strrchr(v11, 32);
if ( !v12 )
{
LABEL_28:
fwrite("malformed HTTP request\n", 1uLL, 0x17uLL, stderr);
goto LABEL_32;
}
*v12 = 0;
if ( !memcmp(v12 + 1, "HTTP/1.", 7uLL) && (v13 = v12[8], (unsigned __int8)(v13 - 48) <= 1u) )
{
if ( v10[1] == 47 )
v11 = v10 + 2;
v14 = v13 - 48;
v15 = open(v11, 0);
v16 = v15;
if ( v15 == -1 )
{
snprintf(s, 0x400uLL, "HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s", 1LL, v14, 404LL, "Not Found", "\r\n");
output_buf(v1, s, 0x2DuLL);
}
else
{
if ( (unsigned int)fstat(v15, &stat_buf) )
{
perror("fstat");
}
else
{
snprintf(s, 0x400uLL, "HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s", 1LL, v14, 200LL, "OK", "");
if ( !(unsigned int)output_buf(v1, s, 0x24uLL) )
{
v18 = snprintf(s, 0x400uLL, "Content-Length: %ld\r\n\r\n", stat_buf.st_size);
if ( !(unsigned int)output_buf(v1, s, v18) )
{
offset = 0LL;
while ( stat_buf.st_size != offset )
{
if ( sendfile(fd, v16, &offset, stat_buf.st_size - offset) == -1 )
{
perror("sendfile");
break;
}
}
}
}
}
close(v16);
}
}
else
{
fwrite("malformed HTTP request finalizer\n", 1uLL, 0x21uLL, stderr);
}
}
}
else
{
fwrite("eof!\n", 1uLL, 5uLL, stderr);
}
LABEL_32:
close(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // er15
const char *v2; // rbp
size_t v3; // r14
char *v4; // rbx
char *v5; // r13
ssize_t v6; // rax
_BYTE *v7; // rax
__int64 v8; // rdx
char *v9; // rax
char *v10; // rbx
const char *v11; // r12
char *v12; // rax
char v13; // al
unsigned int v14; // ebx
int v15; // eax
int v16; // ebp
int v18; // eax
int fd; // [rsp+Ch] [rbp-8DCh]
struct stat stat_buf; // [rsp+10h] [rbp-8D8h] BYREF
off_t offset; // [rsp+A8h] [rbp-840h] BYREF
char s[1024]; // [rsp+B0h] [rbp-838h] BYREF
char buf[1080]; // [rsp+4B0h] [rbp-438h] BYREF

v1 = (int)a1;
fd = (int)a1;
v2 = 0LL;
v3 = 1024LL;
v4 = buf;
v5 = buf;
LABEL_2:
v6 = recv((int)a1, v5, v3, 0);
if ( v6 )
{
if ( v6 < 0 )
{
perror("read");
}
else
{
v5 += v6;
v3 -= v6;
while ( 1 )
{
v7 = memchr(v4, 10, v5 - v4);
if ( !v7 )
goto LABEL_2;
*v7 = 0;
v8 = v7 - v4;
if ( v7 - v4 > 0 && *(v7 - 1) == 13 )
*(v7 - 1) = 0;
if ( v8 == 1 || v8 == 2 && !*(v7 - 1) )
break;
if ( v4 == buf )
v2 = buf;
v4 = v7 + 1;
}
if ( !v2 )
{
fwrite("empty HTTP request\n", 1uLL, 0x13uLL, stderr);
goto LABEL_32;
}
v9 = strchr(v2, 32);
v10 = v9;
if ( !v9 )
goto LABEL_28;
v11 = v9 + 1;
*v9 = 0;
if ( strcmp(v2, "GET") )
{
fprintf(stderr, "unsupported method '%s'\n", v2);
goto LABEL_32;
}
v12 = strrchr(v11, 32);
if ( !v12 )
{
LABEL_28:
fwrite("malformed HTTP request\n", 1uLL, 0x17uLL, stderr);
goto LABEL_32;
}
*v12 = 0;
if ( !memcmp(v12 + 1, "HTTP/1.", 7uLL) && (v13 = v12[8], (unsigned __int8)(v13 - 48) <= 1u) )
{
if ( v10[1] == 47 )
v11 = v10 + 2;
v14 = v13 - 48;
v15 = open(v11, 0);
v16 = v15;
if ( v15 == -1 )
{
snprintf(s, 0x400uLL, "HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s", 1LL, v14, 404LL, "Not Found", "\r\n");
func7(v1, s, 0x2DuLL);
}
else
{
if ( (unsigned int)func14(v15, &stat_buf) )
{
perror("fstat");
}
else
{
snprintf(s, 0x400uLL, "HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s", 1LL, v14, 200LL, "OK", "");
if ( !(unsigned int)func7(v1, s, 0x24uLL) )
{
v18 = snprintf(s, 0x400uLL, "Content-Length: %ld\r\n\r\n", stat_buf.st_size);
if ( !(unsigned int)func7(v1, s, v18) )
{
offset = 0LL;
while ( stat_buf.st_size != offset )
{
if ( sendfile(fd, v16, &offset, stat_buf.st_size - offset) == -1 )
{
perror("sendfile");
break;
}
}
}
}
}
close(v16);
}
}
else
{
fwrite("malformed HTTP request finalizer\n", 1uLL, 0x21uLL, stderr);
}
}
}
else
{
fwrite("eof!\n", 1uLL, 5uLL, stderr);
}
LABEL_32:
close(v1);
return 0LL;
}

original_code:
static void* http_handler(void *arg)
{
 int ss = (long)arg;
 char rq[1024], *s = rq, *p = rq, *pp = p;
 size_t size;
 ssize_t ret;
 char *htrq = ((void *)0), *uri;
 int fd = -1;
 int htcode, htmajor, htminor;
 char *htmsg, *htsig;
 char buf[1024];
 off_t offs;
 struct stat st;
 size = sizeof(rq);
 for(;;) {
  ret = recv(ss, s, size, 0);
  if (!ret) {
   fprintf(stderr, "eof!\n");
   goto out;
  }
  if (ret < 0) {
   perror("read");
   goto out;
  }
  s += ret;
  size -= ret;
  for(;;) {
   pp = (char*)memchr(p, '\n', s - p);
   if (!pp)
    break;
   *pp = '\0';
   if (pp - p >= 1 && *(pp - 1) == '\r')
    *(pp - 1) = '\0';
   if (pp - p == 1
     || pp - p == 2 && !*(pp - 1))
    goto done_rq;
   if (p == rq)
    htrq = p;
   p = pp;
   ++p;
  }
 }
done_rq:
 if (!htrq) {
  fprintf(stderr, "empty HTTP request\n");
  goto out;
 }
 uri = strchr(htrq, ' ');
 if (uri == ((void *)0)) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *uri++ = 0;
 if (strcmp(htrq, "GET")) {
  fprintf(stderr, "unsupported method '%s'\n", htrq);
  goto out;
 }
 htsig = strrchr(uri, ' ');
 if (!htsig) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *htsig++ = 0;
 if (strncmp(htsig, "HTTP/1.", 7)
  || !htsig[7] || htsig[7] != '0' && htsig[7] != '1')
 {
  fprintf(stderr, "malformed HTTP request finalizer\n");
  goto out;
 }
 htmajor = 1;
 htminor = htsig[7] - '0';
 if (*uri == '/')
  ++uri;
 fd = open(uri, 00);
 if (fd != -1 && fstat(fd, &st)) {
  perror("fstat");
  goto out;
 }
 if (fd == -1) {
  htcode = 404;
  htmsg = "Not Found";
 } else {
  htcode = 200;
  htmsg = "OK";
 }
 size = snprintf(buf, sizeof(buf),
   "HTTP/%d.%d %d %s\r\n"
   "Connection: Close\r\n%s",
   htmajor, htminor, htcode, htmsg,
   fd == -1 ? "\r\n" : "");
 if (output_buf(ss, buf, size))
  goto out;
 if (fd != -1) {
  size = snprintf(buf, sizeof(buf),
    "Content-Length: %ld\r\n\r\n", st.st_size);
  if (output_buf(ss, buf, size))
   goto out;
  for(offs = 0; offs != st.st_size; ) {
   if (sendfile(ss, fd, &offs, st.st_size - offs) == -1) {
    perror("sendfile");
    goto out;
   }
  }
 }
out:
 if (fd != -1)
  close(fd);
 close(ss);
 return ((void *)0);
}

canonical_original_code:
static void *http_handler(void *arg)
{
 int ss = (long)arg;
 char rq[1024]; char *s = rq; char *p = rq; char *pp = p;
 unsigned long size;
 long ret;
 char *htrq = ((void *)0); char *uri;
 int fd = -1;
 int htcode; int htmajor; int htminor;
 char *htmsg; char *htsig;
 char buf[1024];
 long offs;
 struct stat st;
 size = sizeof(rq);
 for(;;) {
  ret = recv(ss, s, size, 0);
  if (!ret) {
   fprintf(stderr, "eof!\n");
   goto out;
  }
  if (ret < 0) {
   perror("read");
   goto out;
  }
  s += ret;
  size -= ret;
  for(;;) {
   pp = (char *)memchr(p, '\n', s - p);
   if (!pp)
    break;
   *pp = '\0';
   if (pp - p >= 1 && *(pp - 1) == '\r')
    *(pp - 1) = '\0';
   if (pp - p == 1
     || pp - p == 2 && !*(pp - 1))
    goto done_rq;
   if (p == rq)
    htrq = p;
   p = pp;
   ++p;
  }
 }
done_rq:
 if (!htrq) {
  fprintf(stderr, "empty HTTP request\n");
  goto out;
 }
 uri = strchr(htrq, ' ');
 if (uri == ((void *)0)) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *uri++ = 0;
 if (strcmp(htrq, "GET")) {
  fprintf(stderr, "unsupported method '%s'\n", htrq);
  goto out;
 }
 htsig = strrchr(uri, ' ');
 if (!htsig) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *htsig++ = 0;
 if (strncmp(htsig, "HTTP/1.", 7)
  || !htsig[7] || htsig[7] != '0' && htsig[7] != '1')
 {
  fprintf(stderr, "malformed HTTP request finalizer\n");
  goto out;
 }
 htmajor = 1;
 htminor = htsig[7] - '0';
 if (*uri == '/')
  ++uri;
 fd = open(uri, 00);
 if (fd != -1 && fstat(fd, &st)) {
  perror("fstat");
  goto out;
 }
 if (fd == -1) {
  htcode = 404;
  htmsg = "Not Found";
 } else {
  htcode = 200;
  htmsg = "OK";
 }
 size = snprintf(buf, sizeof(buf),
   "HTTP/%d.%d %d %s\r\n"
   "Connection: Close\r\n%s",
   htmajor, htminor, htcode, htmsg,
   fd == -1 ? "\r\n" : "");
 if (output_buf(ss, buf, size))
  goto out;
 if (fd != -1) {
  size = snprintf(buf, sizeof(buf),
    "Content-Length: %ld\r\n\r\n", st.st_size);
  if (output_buf(ss, buf, size))
   goto out;
  for(offs = 0; offs != st.st_size; ) {
   if (sendfile(ss, fd, &offs, st.st_size - offs) == -1) {
    perror("sendfile");
    goto out;
   }
  }
 }
out:
 if (fd != -1)
  close(fd);
 close(ss);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: ss int

variable_types:
rq
char [1024]

variable_types:
s
char *

variable_types:
p
char *

variable_types:
pp
char *

variable_types: ret long

variable_types:
htrq
char *

variable_types:
uri
char *

variable_types: htcode int

variable_types: htmajor int

variable_types: htminor int

variable_types:
htmsg
char *

variable_types:
htsig
char *

variable_types:
buf
char [1024]

variable_types: offs long


repo: arut/htserve

decompiled_code:
int print_version()
{
return puts("htserve - simple multithreaded HTTP server for static content");
}

canonical_decompiled_code:
int func9()
{
return puts("htserve - simple multithreaded HTTP server for static content");
}

original_code:
static void print_version()
{
    printf("htserve - simple multithreaded HTTP "
   "server for static content\n") ;
}

return_type: void


decompiled_code:
void __noreturn print_usage()
{
print_version();
printf(
"Usage: htserve [OPTION*]\n"
" -p, --port port to listen, default is %d\n"
" -t, --timeout network IO timeout (in sec), default is infinity\n"
" -d, --directory chdir to directory before runnung\n"
" -h, --help display this help and exit\n"
"\n",
8888LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func10()
{
func9();
printf(
"Usage: htserve [OPTION*]\n"
" -p, --port port to listen, default is %d\n"
" -t, --timeout network IO timeout (in sec), default is infinity\n"
" -d, --directory chdir to directory before runnung\n"
" -h, --help display this help and exit\n"
"\n",
8888LL);
exit(0);
}

original_code:
static void print_usage()
{
 print_version() ;
 printf("Usage: htserve [OPTION*]\n"
   "  -p, --port       port to listen, default is %d\n"
   "  -t, --timeout    network IO timeout (in sec), default is infinity\n"
   "  -d, --directory  chdir to directory before runnung\n"
   "  -h, --help       display this help and exit\n\n"
   , 8888);
 exit(0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // r12
int v4; // eax
int v6; // ebp
int v7; // eax
int v8; // ebx
__int64 v9[2]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
pthread_t newthread; // [rsp+20h] [rbp-28h] BYREF
int optval[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

optval[0] = 1;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v9[0] = 0LL;
v9[1] = 0LL;
v3 = 8888;
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "p:t:d:h", &lopts, 0LL);
if ( v4 == -1 )
break;
if ( v4 == 112 )
{
v3 = atoi(_bss_start);
}
else if ( v4 > 112 )
{
if ( v4 != 116 )
return 1;
v9[0] = atoi(_bss_start);
}
else
{
if ( v4 != 100 )
{
if ( v4 == 104 )
print_usage();
return 1;
}
if ( chdir(_bss_start) )
{
perror("chdir");
return 1;
}
}
}
signal(13, (__sighandler_t)1);
v6 = socket(2, 1, 0);
if ( v6 == -1 )
{
perror("socket");
}
else
{
*(_WORD *)addr.sa_data = _bswap_16(v3);
*(_DWORD *)&addr.sa_data[2] = 0;
if ( setsockopt(v6, 1, 2, optval, 4u) )
perror("reuseaddr");
if ( bind(v6, &addr, 0x10u) )
{
perror("bind");
}
else
{
if ( !listen(v6, 100) )
{
while ( 1 )
{
while ( 1 )
{
v7 = accept(v6, 0LL, 0LL);
v8 = v7;
if ( v7 >= 0 )
break;
perror("accept");
}
if ( v9[0] && (setsockopt(v7, 1, 20, v9, 0x10u) || setsockopt(v8, 1, 21, v9, 0x10u)) )
{
perror("IO timeout");
close(v8);
}
else if ( pthread_create(&newthread, 0LL, http_handler, (void *)v8) )
{
fwrite("pthread_create failed\n", 1uLL, 0x16uLL, stderr);
close(v8);
}
else if ( pthread_detach(newthread) )
{
fwrite("pthread_detach failed\n", 1uLL, 0x16uLL, stderr);
}
}
}
perror("listen");
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // r12
int v4; // eax
int v6; // ebp
int v7; // eax
int v8; // ebx
__int64 v9[2]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
pthread_t newthread; // [rsp+20h] [rbp-28h] BYREF
int optval[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

optval[0] = 1;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v9[0] = 0LL;
v9[1] = 0LL;
v3 = 8888;
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "p:t:d:h", &lopts, 0LL);
if ( v4 == -1 )
break;
if ( v4 == 112 )
{
v3 = atoi(_bss_start);
}
else if ( v4 > 112 )
{
if ( v4 != 116 )
return 1;
v9[0] = atoi(_bss_start);
}
else
{
if ( v4 != 100 )
{
if ( v4 == 104 )
func10();
return 1;
}
if ( chdir(_bss_start) )
{
perror("chdir");
return 1;
}
}
}
signal(13, (__sighandler_t)1);
v6 = socket(2, 1, 0);
if ( v6 == -1 )
{
perror("socket");
}
else
{
*(_WORD *)addr.sa_data = func11(v3);
*(_DWORD *)&addr.sa_data[2] = 0;
if ( setsockopt(v6, 1, 2, optval, 4u) )
perror("reuseaddr");
if ( bind(v6, &addr, 0x10u) )
{
perror("bind");
}
else
{
if ( !listen(v6, 100) )
{
while ( 1 )
{
while ( 1 )
{
v7 = accept(v6, 0LL, 0LL);
v8 = v7;
if ( v7 >= 0 )
break;
perror("accept");
}
if ( v9[0] && (setsockopt(v7, 1, 20, v9, 0x10u) || setsockopt(v8, 1, 21, v9, 0x10u)) )
{
perror("IO timeout");
close(v8);
}
else if ( pthread_create(&newthread, 0LL, http_handler, (void *)v8) )
{
fwrite("pthread_create failed\n", 1uLL, 0x16uLL, stderr);
close(v8);
}
else if ( pthread_detach(newthread) )
{
fwrite("pthread_detach failed\n", 1uLL, 0x16uLL, stderr);
}
}
}
perror("listen");
}
}
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 int s, ss, opt, one = 1, port = 8888;
 pthread_t pt;
 struct sockaddr_in sin = {
  .sin_family = 2
 };
 struct timeval timeout = {
  .tv_sec = 0,
  .tv_usec = 0
 };
 while((opt = getopt_long(argc, argv, shopts, lopts, ((void *)0))) != -1)
 {
  switch(opt) {
   case 'p':
    port = atoi(optarg);
    break;
   case 't':
    timeout.tv_sec = atoi(optarg);
    break;
   case 'd':
    if (chdir(optarg)) {
     perror("chdir");
     return 1;
    }
    break;
   case 'h':
    print_usage();
    break;
   default:
    return 1;
  }
 }
 signal(13, ((__sighandler_t) 1));
 s = socket(2, SOCK_STREAM, 0);
 if (s == -1) {
  perror("socket");
  return 1;
 }
 sin.sin_port = htons(port);
 sin.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if (setsockopt(s, 1, 2, &one, sizeof(one)))
  perror("reuseaddr");
 if (bind(s, (struct sockaddr*)&sin, sizeof(sin))) {
  perror("bind");
  return 1;
 }
 if (listen(s, 100)) {
  perror("listen");
  return 1;
 }
 for(;;) {
  ss = accept(s, ((void *)0), ((void *)0));
  if (ss < 0) {
   perror("accept");
   continue;
  }
  if (timeout.tv_sec) {
   if (setsockopt(ss, 1, 20,
     &timeout, sizeof(timeout))
    || setsockopt(ss, 1, 21,
     &timeout, sizeof(timeout)))
   {
    perror("IO timeout");
    close(ss);
    continue;
   }
  }
  if (pthread_create(&pt, ((void *)0), http_handler, (void*)(long)ss)) {
   fprintf(stderr, "pthread_create failed\n");
   close(ss);
   continue;
  }
  if (pthread_detach(pt)) {
   fprintf(stderr, "pthread_detach failed\n");
   continue;
  }
 }
 close(s);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int s; int ss; int opt; int one = 1; int port = 8888;
 unsigned long pt;
 struct sockaddr_in sin = {
  .sin_family = 2
 };
 struct timeval timeout = {
  .tv_sec = 0,
  .tv_usec = 0
 };
 while((opt = getopt_long(argc, argv, shopts, lopts, ((void *)0))) != -1)
 {
  switch(opt) {
   case 'p':
    port = atoi(optarg);
    break;
   case 't':
    timeout.tv_sec = atoi(optarg);
    break;
   case 'd':
    if (chdir(optarg)) {
     perror("chdir");
     return 1;
    }
    break;
   case 'h':
    print_usage();
    break;
   default:
    return 1;
  }
 }
 signal(13, ((void (*)(int)) 1));
 s = socket(2, SOCK_STREAM, 0);
 if (s == -1) {
  perror("socket");
  return 1;
 }
 sin.sin_port = htons(port);
 sin.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if (setsockopt(s, 1, 2, &one, sizeof(one)))
  perror("reuseaddr");
 if (bind(s, (struct sockaddr *)&sin, sizeof(sin))) {
  perror("bind");
  return 1;
 }
 if (listen(s, 100)) {
  perror("listen");
  return 1;
 }
 for(;;) {
  ss = accept(s, ((void *)0), ((void *)0));
  if (ss < 0) {
   perror("accept");
   continue;
  }
  if (timeout.tv_sec) {
   if (setsockopt(ss, 1, 20,
     &timeout, sizeof(timeout))
    || setsockopt(ss, 1, 21,
     &timeout, sizeof(timeout)))
   {
    perror("IO timeout");
    close(ss);
    continue;
   }
  }
  if (pthread_create(&pt, ((void *)0), http_handler, (void *)(long)ss)) {
   fprintf(stderr, "pthread_create failed\n");
   close(ss);
   continue;
  }
  if (pthread_detach(pt)) {
   fprintf(stderr, "pthread_detach failed\n");
   continue;
  }
 }
 close(s);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: s int

variable_types: opt int

variable_types: one int

variable_types: port int

variable_types:
pt
unsigned long

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

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: int

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

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


original_code:
void ht_dtor(ht_t* ht){
 int capacity=ht->capacity;
 int i;
    for(i=0;i<capacity;i++){
  bucket_t* pbucket=&(ht->bucket[i]);
  if(pbucket->next!=((void *)0)){
   pbucket=pbucket->next;
   while(pbucket->next!=((void *)0)){
    bucket_t* tmp=pbucket;
    pbucket=pbucket->next;
    free(tmp);
   }
  }
 }
 free(ht->bucket);
 free(ht);
}

canonical_original_code:
void ht_dtor(struct ht *ht){
 int capacity = ht->capacity;
 int i;
    for(i=0;i<capacity;i++){
  struct bucket *pbucket = &(ht->bucket[i]);
  if(pbucket->next!=((void *)0)){
   pbucket=pbucket->next;
   while(pbucket->next!=((void *)0)){
    struct bucket *tmp = pbucket;
    pbucket=pbucket->next;
    free(tmp);
   }
  }
 }
 free(ht->bucket);
 free(ht);
}

variable_types: struct ht { int count; int capacity; struct bucket { int data; int key; struct bucket *next; } *bucket; } *

variable_types: capacity int

variable_types: i int

user_defined_types: struct ht { int count; int capacity; struct bucket *bucket; }


decompiled_code:
__int64 __fastcall ht_hash(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return a1;
}

original_code:
int ht_hash(int in){
 return in;
}

canonical_original_code:
int ht_hash(int in){
 return in;
}

variable_types: in int


decompiled_code:
__int64 __fastcall get_last_32_bit(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return a1;
}

original_code:
int32_t get_last_32_bit(int64_t in){
    int32_t result=0x00000000;
    int32_t last_32_bit=0xFFFFFFFF;
    result = in & last_32_bit;
    return result;
}

canonical_original_code:
int get_last_32_bit(long in){
    int result = 0x00000000;
    int last_32_bit = 0xFFFFFFFF;
    result = in & last_32_bit;
    return result;
}

variable_types: in long

variable_types: result int


decompiled_code:
// attributes: thunk
__int64 __fastcall convert_mac_to_ip(__int64 a1)
{
return get_last_32_bit(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func9(a1);
}

original_code:
int32_t convert_mac_to_ip(int64_t mac){
 int32_t result=get_last_32_bit(mac);
 return result;
}

canonical_original_code:
int convert_mac_to_ip(long mac){
 int result = get_last_32_bit(mac);
 return result;
}

variable_types: mac long


original_code:
int ht_insert(ht_t* ht, int IP, int MAC){
 int index=ht_hash(IP);
    bucket_t* tmp=ht->bucket;
 if(tmp[index].key==-1&&tmp->next==((void *)0)){
     tmp[index].data=MAC;
     tmp[index].key=IP;
 }
 else{
  tmp=&(tmp[index]);
  while(tmp->key!=-1&&tmp->next!=((void *)0)){
   if(tmp->key!=-1&&tmp->next==((void *)0)){
    tmp->next=malloc(sizeof(bucket_t));
    tmp=tmp->next;
    tmp->data=MAC;
          tmp->key=IP;
    tmp->next=((void *)0);
    return 0;
   }
   tmp=tmp->next;
  }
 }
 return 0;
}

canonical_original_code:
int ht_insert(struct ht *ht, int IP, int MAC){
 int index = ht_hash(IP);
    struct bucket *tmp = ht->bucket;
 if(tmp[index].key==-1&&tmp->next==((void *)0)){
     tmp[index].data=MAC;
     tmp[index].key=IP;
 }
 else{
  tmp=&(tmp[index]);
  while(tmp->key!=-1&&tmp->next!=((void *)0)){
   if(tmp->key!=-1&&tmp->next==((void *)0)){
    tmp->next=malloc(sizeof(bucket_t));
    tmp=tmp->next;
    tmp->data=MAC;
          tmp->key=IP;
    tmp->next=((void *)0);
    return 0;
   }
   tmp=tmp->next;
  }
 }
 return 0;
}

variable_types: IP int

variable_types: MAC int

variable_types: index int

variable_types: struct bucket { int data; int key; struct bucket *next; } *


decompiled_code:
__int64 __fastcall ht_search(__int64 a1, unsigned int a2)
{
unsigned int *v2; // rdx
unsigned int *v3; // rax
__int64 result; // rax

v2 = (unsigned int *)(*(_QWORD *)(a1 + 8) + 16LL * (int)ht_hash(a2));
v3 = (unsigned int *)*((_QWORD *)v2 + 1);
if ( v3 )
{
while ( v3[1] != a2 )
{
v3 = (unsigned int *)*((_QWORD *)v3 + 1);
if ( !v3 )
return 2LL;
}
result = *v3;
}
else
{
result = 0xFFFFFFFFLL;
if ( a2 == v2[1] )
result = *v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
unsigned int *v2; // rdx
unsigned int *v3; // rax
__int64 result; // rax

v2 = (unsigned int *)(*(_QWORD *)(a1 + 8) + 16LL * (int)func8(a2));
v3 = (unsigned int *)*((_QWORD *)v2 + 1);
if ( v3 )
{
while ( v3[1] != a2 )
{
v3 = (unsigned int *)*((_QWORD *)v3 + 1);
if ( !v3 )
return 2LL;
}
result = *v3;
}
else
{
result = 0xFFFFFFFFLL;
if ( a2 == v2[1] )
result = *v2;
}
return result;
}

original_code:
int ht_search(ht_t* ht, int IP){
 int index=ht_hash(IP);
    bucket_t* tmp=ht->bucket;
 if(tmp[index].next==((void *)0)){
     bucket_t* tmp=ht->bucket;
     int data=tmp[index].data;
        int key=tmp[index].key;
  if(key==IP){
   return data;
  }
  else{
   return -1;
  }
 }
 else{
  bucket_t* p=&(tmp[index]);
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==IP){
    return p->data;
   }
   p=p->next;
  }
  return 2;
 }
}

canonical_original_code:
int ht_search(struct ht *ht, int IP){
 int index = ht_hash(IP);
    struct bucket *tmp = ht->bucket;
 if(tmp[index].next==((void *)0)){
     struct bucket *tmp = ht->bucket;
     int data = tmp[index].data;
        int key = tmp[index].key;
  if(key==IP){
   return data;
  }
  else{
   return -1;
  }
 }
 else{
  struct bucket *p = &(tmp[index]);
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==IP){
    return p->data;
   }
   p=p->next;
  }
  return 2;
 }
}

variable_types: data int

variable_types: key int

user_defined_types: struct bucket { int data; int key; struct bucket *next; }


decompiled_code:
__int64 __fastcall ht_delete(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
unsigned int v3; // ebp
__int64 v4; // rdi
__int64 v6; // rax

v2 = *(_QWORD *)(a1 + 8) + 16LL * (int)ht_hash(a2);
v3 = *(_DWORD *)(v2 + 4);
if ( v3 == -1 )
{
puts("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) ");
}
else
{
v4 = *(_QWORD *)(v2 + 8);
if ( v4 )
{
while ( *(_DWORD *)(v4 + 4) != a2 )
{
v2 = v4;
if ( !*(_QWORD *)(v4 + 8) )
return 3;
v4 = *(_QWORD *)(v4 + 8);
}
v6 = *(_QWORD *)(v4 + 8);
if ( v6 )
*(_QWORD *)(v2 + 8) = v6;
else
*(_QWORD *)(v2 + 8) = 0LL;
free((void *)v4);
v3 = 0;
}
else if ( v3 == a2 )
{
*(_DWORD *)(v2 + 4) = -1;
v3 = 0;
}
else
{
v3 = 2;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
unsigned int v3; // ebp
__int64 v4; // rdi
__int64 v6; // rax

v2 = *(_QWORD *)(a1 + 8) + 16LL * (int)func8(a2);
v3 = *(_DWORD *)(v2 + 4);
if ( v3 == -1 )
{
puts("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) ");
}
else
{
v4 = *(_QWORD *)(v2 + 8);
if ( v4 )
{
while ( *(_DWORD *)(v4 + 4) != a2 )
{
v2 = v4;
if ( !*(_QWORD *)(v4 + 8) )
return 3;
v4 = *(_QWORD *)(v4 + 8);
}
v6 = *(_QWORD *)(v4 + 8);
if ( v6 )
*(_QWORD *)(v2 + 8) = v6;
else
*(_QWORD *)(v2 + 8) = 0LL;
free((void *)v4);
v3 = 0;
}
else if ( v3 == a2 )
{
*(_DWORD *)(v2 + 4) = -1;
v3 = 0;
}
else
{
v3 = 2;
}
}
return v3;
}

original_code:
int ht_delete(ht_t* ht, int key){
    int index=ht_hash(key);
    bucket_t* tmp=ht->bucket;
 bucket_t* p=&(tmp[index]);
    bucket_t* q=&(tmp[index]);
 if(tmp[index].key==-1){
  printf("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) \n");
  return -1;
 }
 if(p->key!=-1&&p->next==((void *)0)){
  if(p->key==key){
   p->key=-1;
   return 0;
  }
  else{
   return 2;
  }
 }
 else{
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==key){
    if(p->next==((void *)0)){
     q->next=((void *)0);
     free(p);
     return 0;
    }
    else{
     q->next=p->next;
     free(p);
     return 0;
    }
   }
   q=p;
   p=p->next;
  }
  return 3;
 }
 return 4;
}

canonical_original_code:
int ht_delete(struct ht *ht, int key){
    int index = ht_hash(key);
    struct bucket *tmp = ht->bucket;
 struct bucket *p = &(tmp[index]);
    struct bucket *q = &(tmp[index]);
 if(tmp[index].key==-1){
  printf("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) \n");
  return -1;
 }
 if(p->key!=-1&&p->next==((void *)0)){
  if(p->key==key){
   p->key=-1;
   return 0;
  }
  else{
   return 2;
  }
 }
 else{
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==key){
    if(p->next==((void *)0)){
     q->next=((void *)0);
     free(p);
     return 0;
    }
    else{
     q->next=p->next;
     free(p);
     return 0;
    }
   }
   q=p;
   p=p->next;
  }
  return 3;
 }
 return 4;
}


decompiled_code:
int test_ht_ctor()
{
_DWORD *v0; // rbx
_DWORD *v1; // rax

v0 = ht_ctor(20);
v1 = (_DWORD *)*((_QWORD *)v0 + 1);
*v1 = 1;
v1[4] = 2;
if ( **((_DWORD **)v0 + 1) != 1 )
__assert_fail("(ht->bucket)->data==1", "unittest.c", 0xDu, "test_ht_ctor");
printf("ht->bucket->data: %i\n", 1LL);
if ( *(_DWORD *)(*((_QWORD *)v0 + 1) + 16LL) != 2 )
__assert_fail("(ht->bucket[1]).data==2", "unittest.c", 0x11u, "test_ht_ctor");
printf("ht->bucket->data: %i\n", 2LL);
if ( v0[1] != 20 )
__assert_fail("ht->capacity==20", "unittest.c", 0x14u, "test_ht_ctor");
printf("ht->capacity: %i\n", 20LL);
ht_dtor(v0);
return puts("end of test_ht_ctor() -----");
}

canonical_decompiled_code:
int func14()
{
_DWORD *v0; // rbx
_DWORD *v1; // rax

v0 = ht_ctor(20);
v1 = (_DWORD *)*((_QWORD *)v0 + 1);
*v1 = 1;
v1[4] = 2;
if ( **((_DWORD **)v0 + 1) != 1 )
__assert_fail("(ht->bucket)->data==1", "unittest.c", 0xDu, "test_ht_ctor");
printf("ht->bucket->data: %i\n", 1LL);
if ( *(_DWORD *)(*((_QWORD *)v0 + 1) + 16LL) != 2 )
__assert_fail("(ht->bucket[1]).data==2", "unittest.c", 0x11u, "test_ht_ctor");
printf("ht->bucket->data: %i\n", 2LL);
if ( v0[1] != 20 )
__assert_fail("ht->capacity==20", "unittest.c", 0x14u, "test_ht_ctor");
printf("ht->capacity: %i\n", 20LL);
func7(v0);
return puts("end of test_ht_ctor() -----");
}

original_code:
void test_ht_ctor(){
 ht_t* ht=ht_ctor(20);
 bucket_t* tmp=ht->bucket;
 tmp[0].data=1;
    tmp[1].data=2;
 ((void) sizeof (((ht->bucket)->data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket)->data==1) ; else __assert_fail ("(ht->bucket)->data==1", "unittest.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((ht->bucket[0]).data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket[0]).data==1) ; else __assert_fail ("(ht->bucket[0]).data==1", "unittest.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 printf("ht->bucket->data: %i\n", (ht->bucket)->data);
 ((void) sizeof (((ht->bucket[1]).data==2) ? 1 : 0), __extension__ ({ if ((ht->bucket[1]).data==2) ; else __assert_fail ("(ht->bucket[1]).data==2", "unittest.c", 17, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->bucket->data: %i\n", (ht->bucket[1]).data);
 ((void) sizeof ((ht->capacity==20) ? 1 : 0), __extension__ ({ if (ht->capacity==20) ; else __assert_fail ("ht->capacity==20", "unittest.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->capacity: %i\n", ht->capacity);
    ht_dtor(ht);
 printf("end of test_ht_ctor() -----\n");
}

canonical_original_code:
void test_ht_ctor(){
 struct ht *ht = ht_ctor(20);
 struct bucket *tmp = ht->bucket;
 tmp[0].data=1;
    tmp[1].data=2;
 ((void) sizeof (((ht->bucket)->data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket)->data==1) ; else __assert_fail ("(ht->bucket)->data==1", "unittest.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((ht->bucket[0]).data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket[0]).data==1) ; else __assert_fail ("(ht->bucket[0]).data==1", "unittest.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 printf("ht->bucket->data: %i\n", (ht->bucket)->data);
 ((void) sizeof (((ht->bucket[1]).data==2) ? 1 : 0), __extension__ ({ if ((ht->bucket[1]).data==2) ; else __assert_fail ("(ht->bucket[1]).data==2", "unittest.c", 17, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->bucket->data: %i\n", (ht->bucket[1]).data);
 ((void) sizeof ((ht->capacity==20) ? 1 : 0), __extension__ ({ if (ht->capacity==20) ; else __assert_fail ("ht->capacity==20", "unittest.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->capacity: %i\n", ht->capacity);
    ht_dtor(ht);
 printf("end of test_ht_ctor() -----\n");
}


decompiled_code:
int test_ht_dtor()
{
_DWORD **v0; // rax

v0 = (_DWORD **)ht_ctor(20);
*v0[1] = 1;
ht_dtor(v0);
return puts("end of test_ht_dtor() -----");
}

canonical_decompiled_code:
int func15()
{
_DWORD **v0; // rax

v0 = (_DWORD **)ht_ctor(20);
*v0[1] = 1;
func7(v0);
return puts("end of test_ht_dtor() -----");
}

original_code:
void test_ht_dtor(){
    ht_t* ht=ht_ctor(20);
 bucket_t* tmp=ht->bucket;
    tmp[0].data=1;
 ht_dtor(ht);
    printf("end of test_ht_dtor() -----\n");
}

canonical_original_code:
void test_ht_dtor(){
    struct ht *ht = ht_ctor(20);
 struct bucket *tmp = ht->bucket;
    tmp[0].data=1;
 ht_dtor(ht);
    printf("end of test_ht_dtor() -----\n");
}


decompiled_code:
int test_convert_mac_to_ip()
{
if ( (unsigned int)convert_mac_to_ip(1LL) != 1 )
__assert_fail("result==0x00000001", "unittest.c", 0x28u, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(2LL) != 2 )
__assert_fail("result==0x00000002", "unittest.c", 0x2Au, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(3LL) != 3 )
__assert_fail("result==0x00000003", "unittest.c", 0x2Cu, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(4LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x2Eu, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(0xFFFF00000004LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x31u, "test_convert_mac_to_ip");
return puts("end of test_convert_mac_to_ip() -----");
}

canonical_decompiled_code:
int func16()
{
if ( (unsigned int)func10(1LL) != 1 )
__assert_fail("result==0x00000001", "unittest.c", 0x28u, "test_convert_mac_to_ip");
if ( (unsigned int)func10(2LL) != 2 )
__assert_fail("result==0x00000002", "unittest.c", 0x2Au, "test_convert_mac_to_ip");
if ( (unsigned int)func10(3LL) != 3 )
__assert_fail("result==0x00000003", "unittest.c", 0x2Cu, "test_convert_mac_to_ip");
if ( (unsigned int)func10(4LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x2Eu, "test_convert_mac_to_ip");
if ( (unsigned int)func10(0xFFFF00000004LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x31u, "test_convert_mac_to_ip");
return puts("end of test_convert_mac_to_ip() -----");
}

original_code:
void test_convert_mac_to_ip(){
 int32_t result;
 result = convert_mac_to_ip(0x0000000000000001);
 ((void) sizeof ((result==0x00000001) ? 1 : 0), __extension__ ({ if (result==0x00000001) ; else __assert_fail ("result==0x00000001", "unittest.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000002);
    ((void) sizeof ((result==0x00000002) ? 1 : 0), __extension__ ({ if (result==0x00000002) ; else __assert_fail ("result==0x00000002", "unittest.c", 42, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000003);
    ((void) sizeof ((result==0x00000003) ? 1 : 0), __extension__ ({ if (result==0x00000003) ; else __assert_fail ("result==0x00000003", "unittest.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000FFFF00000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of test_convert_mac_to_ip() -----\n");
}

canonical_original_code:
void test_convert_mac_to_ip(){
 int result;
 result = convert_mac_to_ip(0x0000000000000001);
 ((void) sizeof ((result==0x00000001) ? 1 : 0), __extension__ ({ if (result==0x00000001) ; else __assert_fail ("result==0x00000001", "unittest.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000002);
    ((void) sizeof ((result==0x00000002) ? 1 : 0), __extension__ ({ if (result==0x00000002) ; else __assert_fail ("result==0x00000002", "unittest.c", 42, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000003);
    ((void) sizeof ((result==0x00000003) ? 1 : 0), __extension__ ({ if (result==0x00000003) ; else __assert_fail ("result==0x00000003", "unittest.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000FFFF00000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of test_convert_mac_to_ip() -----\n");
}


original_code:
void test_ht_insert(){
    ht_t* ht=ht_ctor(20);
 ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
 int i;
 for(i=0; i<20; i++){
  ((void) sizeof (((ht->bucket[i]).data==i) ? 1 : 0), __extension__ ({ if ((ht->bucket[i]).data==i) ; else __assert_fail ("(ht->bucket[i]).data==i", "unittest.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 }
    ht_dtor(ht);
    printf("end of test_ht_insert() -----\n");
}

canonical_original_code:
void test_ht_insert(){
    struct ht *ht = ht_ctor(20);
 ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
 int i;
 for(i=0; i<20; i++){
  ((void) sizeof (((ht->bucket[i]).data==i) ? 1 : 0), __extension__ ({ if ((ht->bucket[i]).data==i) ; else __assert_fail ("(ht->bucket[i]).data==i", "unittest.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 }
    ht_dtor(ht);
    printf("end of test_ht_insert() -----\n");
}


decompiled_code:
int test_ht_search()
{
_DWORD *v0; // rbp
unsigned int i; // ebx

v0 = ht_ctor(20);
ht_insert((__int64)v0, 0, 0);
ht_insert((__int64)v0, 1u, 1);
ht_insert((__int64)v0, 2u, 2);
ht_insert((__int64)v0, 3u, 3);
ht_insert((__int64)v0, 4u, 4);
ht_insert((__int64)v0, 5u, 5);
ht_insert((__int64)v0, 6u, 6);
ht_insert((__int64)v0, 7u, 7);
ht_insert((__int64)v0, 8u, 8);
ht_insert((__int64)v0, 9u, 9);
ht_insert((__int64)v0, 0xAu, 10);
ht_insert((__int64)v0, 0xBu, 11);
ht_insert((__int64)v0, 0xCu, 12);
ht_insert((__int64)v0, 0xDu, 13);
ht_insert((__int64)v0, 0xEu, 14);
ht_insert((__int64)v0, 0xFu, 15);
ht_insert((__int64)v0, 0x10u, 16);
ht_insert((__int64)v0, 0x11u, 17);
ht_insert((__int64)v0, 0x12u, 18);
ht_insert((__int64)v0, 0x13u, 19);
for ( i = 0; i != 20; ++i )
{
if ( (unsigned int)ht_search((__int64)v0, i) != i )
__assert_fail("a==i", "unittest.c", 0x76u, "test_ht_search");
}
ht_dtor(v0);
return puts("end of test_ht_search() -----");
}

original_code:
void test_ht_search(){
    ht_t* ht=ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
  int a=ht_search(ht, i);
        ((void) sizeof ((a==i) ? 1 : 0), __extension__ ({ if (a==i) ; else __assert_fail ("a==i", "unittest.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_search() -----\n");
}

canonical_original_code:
void test_ht_search(){
    struct ht *ht = ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
  int a = ht_search(ht, i);
        ((void) sizeof ((a==i) ? 1 : 0), __extension__ ({ if (a==i) ; else __assert_fail ("a==i", "unittest.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_search() -----\n");
}

variable_types: a int


decompiled_code:
int test_ht_delete()
{
_DWORD *v0; // rbp
unsigned int i; // ebx
unsigned int j; // ebx

v0 = ht_ctor(20);
ht_insert((__int64)v0, 0, 0);
ht_insert((__int64)v0, 1u, 1);
ht_insert((__int64)v0, 2u, 2);
ht_insert((__int64)v0, 3u, 3);
ht_insert((__int64)v0, 4u, 4);
ht_insert((__int64)v0, 5u, 5);
ht_insert((__int64)v0, 6u, 6);
ht_insert((__int64)v0, 7u, 7);
ht_insert((__int64)v0, 8u, 8);
ht_insert((__int64)v0, 9u, 9);
ht_insert((__int64)v0, 0xAu, 10);
ht_insert((__int64)v0, 0xBu, 11);
ht_insert((__int64)v0, 0xCu, 12);
ht_insert((__int64)v0, 0xDu, 13);
ht_insert((__int64)v0, 0xEu, 14);
ht_insert((__int64)v0, 0xFu, 15);
ht_insert((__int64)v0, 0x10u, 16);
ht_insert((__int64)v0, 0x11u, 17);
ht_insert((__int64)v0, 0x12u, 18);
ht_insert((__int64)v0, 0x13u, 19);
for ( i = 0; i != 20; ++i )
ht_delete((__int64)v0, i);
for ( j = 0; j != 20; ++j )
{
if ( (unsigned int)ht_search((__int64)v0, j) != -1 )
__assert_fail("a==-1", "unittest.c", 0xA3u, "test_ht_delete");
}
ht_dtor(v0);
return puts("end of test_ht_delete() -----");
}

original_code:
void test_ht_delete(){
    ht_t* ht=ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
        ht_delete(ht, i);
    }
    for(i=0; i<20; i++){
  int a=ht_search(ht, i);
  ((void) sizeof ((a==-1) ? 1 : 0), __extension__ ({ if (a==-1) ; else __assert_fail ("a==-1", "unittest.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_delete() -----\n");
}

canonical_original_code:
void test_ht_delete(){
    struct ht *ht = ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
        ht_delete(ht, i);
    }
    for(i=0; i<20; i++){
  int a = ht_search(ht, i);
  ((void) sizeof ((a==-1) ? 1 : 0), __extension__ ({ if (a==-1) ; else __assert_fail ("a==-1", "unittest.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_delete() -----\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_ht_ctor();
test_ht_dtor();
test_convert_mac_to_ip();
test_ht_insert();
test_ht_search();
test_ht_delete();
puts("end of main()! ");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func14();
func15();
func16();
func17();
func18();
func19();
puts("end of main()! ");
return 0;
}

original_code:
int main(){
 test_ht_ctor();
    test_ht_dtor();
 test_convert_mac_to_ip();
 test_ht_insert();
 test_ht_search();
 test_ht_delete();
 printf("end of main()! \n");
 return 0;
}


or

decompiled_code:
__int64 __fastcall or(unsigned int a1, int a2)
{
return a2 | a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2)
{
return a2 | a1;
}

original_code:
int or(int in1, int in2){
 int result=in1 | in2;
 return result;
}

canonical_original_code:
int or(int in1, int in2){
 int result = in1 | in2;
 return result;
}


decompiled_code:
__int64 __fastcall get_last_four_bit(char a1)
{
return a1 & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return a1 & 0xF;
}

original_code:
int8_t get_last_four_bit(int8_t in){
    int8_t result=0x00;
 int8_t last_four_bit=0x0F;
 result = in & last_four_bit;
 return result;
}

canonical_original_code:
char get_last_four_bit(char in){
    char result = 0x00;
 char last_four_bit = 0x0F;
 result = in & last_four_bit;
 return result;
}

variable_types: in char

variable_types: result char

return_type: char


main

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

v3 = (unsigned int)or(1u, 2);
printf("or(1, 2): %i \n", v3);
if ( (_DWORD)v3 != 3 )
__assert_fail("result==3", "main.c", 0x16u, "main");
if ( (unsigned __int8)get_last_four_bit(0) )
__assert_fail("eight_bit_result==0x00", "main.c", 0x1Au, "main");
if ( (unsigned __int8)get_last_four_bit(9) != 9 )
__assert_fail("eight_bit_result==0x09", "main.c", 0x1Du, "main");
if ( (unsigned __int8)get_last_four_bit(10) != 10 )
__assert_fail("eight_bit_result==10", "main.c", 0x1Fu, "main");
if ( (unsigned __int8)get_last_four_bit(11) != 11 )
__assert_fail("eight_bit_result==11", "main.c", 0x21u, "main");
if ( (unsigned __int8)get_last_four_bit(12) != 12 )
__assert_fail("eight_bit_result==12", "main.c", 0x23u, "main");
if ( (unsigned __int8)get_last_four_bit(15) != 15 )
__assert_fail("eight_bit_result==15", "main.c", 0x25u, "main");
if ( (unsigned __int8)get_last_four_bit(16) )
__assert_fail("eight_bit_result==0", "main.c", 0x27u, "main");
if ( (unsigned __int8)get_last_four_bit(32) )
__assert_fail("eight_bit_result==0", "main.c", 0x29u, "main");
puts("end of main() ");
return 0;
}

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

v3 = (unsigned int)func7(1u, 2);
printf("or(1, 2): %i \n", v3);
if ( (_DWORD)v3 != 3 )
__assert_fail("result==3", "main.c", 0x16u, "main");
if ( (unsigned __int8)func8(0) )
__assert_fail("eight_bit_result==0x00", "main.c", 0x1Au, "main");
if ( (unsigned __int8)func8(9) != 9 )
__assert_fail("eight_bit_result==0x09", "main.c", 0x1Du, "main");
if ( (unsigned __int8)func8(10) != 10 )
__assert_fail("eight_bit_result==10", "main.c", 0x1Fu, "main");
if ( (unsigned __int8)func8(11) != 11 )
__assert_fail("eight_bit_result==11", "main.c", 0x21u, "main");
if ( (unsigned __int8)func8(12) != 12 )
__assert_fail("eight_bit_result==12", "main.c", 0x23u, "main");
if ( (unsigned __int8)func8(15) != 15 )
__assert_fail("eight_bit_result==15", "main.c", 0x25u, "main");
if ( (unsigned __int8)func8(16) )
__assert_fail("eight_bit_result==0", "main.c", 0x27u, "main");
if ( (unsigned __int8)func8(32) )
__assert_fail("eight_bit_result==0", "main.c", 0x29u, "main");
puts("end of main() ");
return 0;
}

original_code:
int main(){
    int result=or(1, 2);
 printf("or(1, 2): %i \n", result);
 ((void) sizeof ((result==3) ? 1 : 0), __extension__ ({ if (result==3) ; else __assert_fail ("result==3", "main.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 int8_t eight_bit_result=0x00;
    eight_bit_result=get_last_four_bit(0x00);
    ((void) sizeof ((eight_bit_result==0x00) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x00) ; else __assert_fail ("eight_bit_result==0x00", "main.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(0x09);
 ((void) sizeof ((eight_bit_result==0x09) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x09) ; else __assert_fail ("eight_bit_result==0x09", "main.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(10);
    ((void) sizeof ((eight_bit_result==10) ? 1 : 0), __extension__ ({ if (eight_bit_result==10) ; else __assert_fail ("eight_bit_result==10", "main.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(11);
    ((void) sizeof ((eight_bit_result==11) ? 1 : 0), __extension__ ({ if (eight_bit_result==11) ; else __assert_fail ("eight_bit_result==11", "main.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(12);
    ((void) sizeof ((eight_bit_result==12) ? 1 : 0), __extension__ ({ if (eight_bit_result==12) ; else __assert_fail ("eight_bit_result==12", "main.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(15);
    ((void) sizeof ((eight_bit_result==15) ? 1 : 0), __extension__ ({ if (eight_bit_result==15) ; else __assert_fail ("eight_bit_result==15", "main.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(16);
 ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(32);
    ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of main() \n");
}

canonical_original_code:
int main(){
    int result = or(1, 2);
 printf("or(1, 2): %i \n", result);
 ((void) sizeof ((result==3) ? 1 : 0), __extension__ ({ if (result==3) ; else __assert_fail ("result==3", "main.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 char eight_bit_result = 0x00;
    eight_bit_result=get_last_four_bit(0x00);
    ((void) sizeof ((eight_bit_result==0x00) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x00) ; else __assert_fail ("eight_bit_result==0x00", "main.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(0x09);
 ((void) sizeof ((eight_bit_result==0x09) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x09) ; else __assert_fail ("eight_bit_result==0x09", "main.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(10);
    ((void) sizeof ((eight_bit_result==10) ? 1 : 0), __extension__ ({ if (eight_bit_result==10) ; else __assert_fail ("eight_bit_result==10", "main.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(11);
    ((void) sizeof ((eight_bit_result==11) ? 1 : 0), __extension__ ({ if (eight_bit_result==11) ; else __assert_fail ("eight_bit_result==11", "main.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(12);
    ((void) sizeof ((eight_bit_result==12) ? 1 : 0), __extension__ ({ if (eight_bit_result==12) ; else __assert_fail ("eight_bit_result==12", "main.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(15);
    ((void) sizeof ((eight_bit_result==15) ? 1 : 0), __extension__ ({ if (eight_bit_result==15) ; else __assert_fail ("eight_bit_result==15", "main.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(16);
 ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(32);
    ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of main() \n");
}


repo: ash/qerl

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return yyparse(argc, argv, envp);
}

original_code:
int main() {
    return yyparse();
}

canonical_original_code:
int main() {
    return yyparse();
}


decompiled_code:
int __fastcall yy_stack_print(__int16 *a1, unsigned __int64 a2)
{
__int16 *v2; // rbx

v2 = a1;
fwrite("Stack now", 1uLL, 9uLL, stderr);
if ( (unsigned __int64)a1 <= a2 )
{
do
fprintf(stderr, " %d", (unsigned int)*v2++);
while ( a2 >= (unsigned __int64)v2 );
}
return fputc(10, stderr);
}

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

v2 = a1;
fwrite("Stack now", 1uLL, 9uLL, stderr);
if ( (unsigned __int64)a1 <= a2 )
{
do
fprintf(stderr, " %d", (unsigned int)*v2++);
while ( a2 >= (unsigned __int64)v2 );
}
return fputc(10, stderr);
}

original_code:
static void
yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
{
  fprintf (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      fprintf (stderr, " %d", yybot);
    }
  fprintf (stderr, "\n");
}

canonical_original_code:
static void yy_stack_print(short *yybottom, short *yytop)
{
  fprintf (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      fprintf (stderr, " %d", yybot);
    }
  fprintf (stderr, "\n");
}

variable_types:
yybottom
short *

variable_types:
yytop
short *

variable_types: yybot int


yyerror

decompiled_code:
int yyerror()
{
return printf("Error at line %d\n", yylineno);
}

canonical_decompiled_code:
int func4()
{
return printf("Error at line %d\n", yylineno);
}

original_code:
void yyerror(char *s, ...) {
    printf("Error at line %d\n", yylineno);
}

variable_types:
s
char *


yyparse

decompiled_code:
__int64 yyparse()
{
unsigned __int64 v0; // r14
const char **v1; // r12
char *v2; // rbx
char *v3; // r13
unsigned int v4; // ebp
int v5; // er15
unsigned int v6; // er15
int v7; // er15
int v8; // er15
unsigned __int8 v9; // bp
__int64 v10; // rax
const char **v11; // rbp
int v12; // eax
unsigned int v13; // edx
unsigned __int64 v14; // rax
char *v15; // rax
char *v16; // r15
size_t v17; // r12
__int64 v18; // rax
unsigned int v19; // eax
int v20; // esi
unsigned int v21; // ebp
int v22; // esi
int v23; // eax
unsigned int v24; // eax
int v25; // er15
int v27; // [rsp+8h] [rbp-840h]
signed __int64 v28; // [rsp+8h] [rbp-840h]
char *v29; // [rsp+18h] [rbp-830h]
int v30; // [rsp+24h] [rbp-824h]
unsigned __int64 v31; // [rsp+28h] [rbp-820h]
const char *v32; // [rsp+38h] [rbp-810h]
char v33[1600]; // [rsp+40h] [rbp-808h] BYREF
char src[456]; // [rsp+680h] [rbp-1C8h] BYREF

if ( yydebug )
fwrite("Starting parse\n", 1uLL, 0xFuLL, stderr);
yynerrs = 0;
yychar = -2;
v0 = 200LL;
v1 = (const char **)v33;
v29 = v33;
v2 = src;
v3 = src;
v30 = 0;
v4 = 0;
while ( 1 )
{
*(_WORD *)v2 = v4;
v14 = 2 * v0;
if ( v2 < &v3[2 * v0 - 2] )
goto LABEL_6;
v28 = v2 - v3;
if ( v0 > 0x270F )
goto LABEL_96;
v0 = 10000LL;
if ( v14 <= 0x2710 )
v0 = v14;
v15 = (char *)malloc(10 * v0 + 7);
v16 = v15;
if ( !v15 )
{
LABEL_96:
yyerror();
v21 = 2;
goto LABEL_100;
}
memcpy(v15, v3, v28 + 2);
v17 = 8 * (((v2 - v3) >> 1) + 1);
v31 = 2 * v0;
memcpy(&v16[2 * v0], v29, v17);
if ( v3 != src )
free(v3);
v2 = &v16[v28];
v1 = (const char **)&v16[2 * v0 - 8 + v17];
if ( yydebug )
{
fprintf(stderr, "Stack size increased to %lu\n", v0);
if ( v2 >= &v16[v31 - 2] )
{
v3 = v16;
v21 = 1;
goto LABEL_100;
}
v29 = &v16[2 * v0];
v3 = v16;
LABEL_6:
if ( yydebug )
fprintf(stderr, "Entering state %d\n", v4);
goto LABEL_8;
}
if ( v2 >= &v16[v31 - 2] )
{
v19 = yychar;
v3 = v16;
v21 = 1;
if ( yychar == -2 )
goto LABEL_105;
goto LABEL_101;
}
v29 = &v16[2 * v0];
v3 = v16;
LABEL_8:
if ( v4 == 41 )
break;
v5 = yypact[v4];
if ( v5 == -63 )
goto LABEL_29;
if ( yychar == -2 )
{
if ( yydebug )
fwrite("Reading a token: ", 1uLL, 0x11uLL, stderr);
yychar = yylex();
}
if ( yychar <= 0 )
{
yychar = 0;
v27 = yydebug;
if ( yydebug )
{
fwrite("Now at end of input.\n", 1uLL, 0x15uLL, stderr);
v27 = 0;
}
}
else
{
v27 = 2;
if ( (unsigned int)yychar <= 0x111 )
v27 = (unsigned __int8)yytranslate[yychar];
if ( yydebug )
{
fprintf(stderr, "%s ", "Next token is");
yy_symbol_print(stderr, v27);
fputc(10, stderr);
}
}
v6 = v27 + v5;
if ( v6 > 0xFB || yycheck[v6] != v27 )
{
LABEL_29:
v8 = (unsigned __int8)yydefact[v4];
if ( yydefact[v4] )
goto LABEL_30;
}
else
{
v7 = yytable[v6];
if ( v7 > 0 )
{
v30 = (v30 == 0) + v30 - 1;
if ( yydebug )
{
fprintf(stderr, "%s ", "Shifting");
yy_symbol_print(stderr, v27);
fputc(10, stderr);
}
yychar = -2;
v1[1] = (const char *)yylval;
++v1;
v4 = v7;
goto LABEL_39;
}
if ( v7 != -43 )
{
v8 = -v7;
LABEL_30:
v9 = yyr2[v8];
v32 = v1[1 - v9];
if ( !yydebug )
{
switch ( v8 )
{
case 18:
goto LABEL_33;
case 19:
goto LABEL_50;
case 20:
goto LABEL_51;
case 21:
goto LABEL_52;
case 22:
goto LABEL_53;
case 36:
goto LABEL_54;
case 37:
goto LABEL_55;
case 38:
goto LABEL_56;
case 39:
goto LABEL_57;
case 40:
goto LABEL_58;
case 41:
goto LABEL_59;
case 42:
goto LABEL_60;
case 43:
goto LABEL_61;
case 44:
goto LABEL_62;
case 45:
goto LABEL_63;
case 46:
goto LABEL_64;
case 47:
goto LABEL_65;
case 48:
goto LABEL_66;
case 49:
goto LABEL_67;
case 50:
goto LABEL_68;
case 52:
goto LABEL_69;
case 53:
goto LABEL_70;
case 58:
goto LABEL_71;
default:
goto LABEL_35;
}
}
yy_reduce_print((__int64)v2, (__int64)v1, v8);
switch ( v8 )
{
case 18:
LABEL_33:
printf("line %d: declared '%s'\n", yylineno, *v1);
break;
case 19:
LABEL_50:
printf("line %d: scalar declared '%s' and assigned to '%s'\n", yylineno, *(v1 - 2), *v1);
break;
case 20:
LABEL_51:
printf("line %d: array declared '%s'\n", yylineno, *(v1 - 2));
break;
case 21:
LABEL_52:
printf("line %d: hash declared '%s'\n", yylineno, *(v1 - 2));
break;
case 22:
LABEL_53:
printf("line %d: function '%s' defined\n", yylineno, *(v1 - 4));
break;
case 36:
LABEL_54:
printf("line %d: array %s[], index %i\n", yylineno, *(v1 - 3), *((unsigned int *)v1 - 2));
break;
case 37:
LABEL_55:
printf("line %d: hash %s{}, indexed by expression\n", yylineno, *(v1 - 3));
break;
case 38:
LABEL_56:
printf("line %d: addition\n", yylineno);
break;
case 39:
LABEL_57:
printf("line %d: subtraction\n", yylineno);
break;
case 40:
LABEL_58:
printf("line %d: multiplication\n", yylineno);
break;
case 41:
LABEL_59:
printf("line %d: division\n", yylineno);
break;
case 42:
LABEL_60:
printf("line %d: unary minus\n", yylineno);
break;
case 43:
LABEL_61:
printf("line %d: less than\n", yylineno);
break;
case 44:
LABEL_62:
printf("line %d: more than\n", yylineno);
break;
case 45:
LABEL_63:
printf("line %d: less than or equal\n", yylineno);
break;
case 46:
LABEL_64:
printf("line %d: more than or equal\n", yylineno);
break;
case 47:
LABEL_65:
printf("line %d: equal\n", yylineno);
break;
case 48:
LABEL_66:
printf("line %d: not equal\n", yylineno);
break;
case 49:
LABEL_67:
printf("line %d: approximate equall\n", yylineno);
break;
case 50:
LABEL_68:
printf("line %d: unary negation\n", yylineno);
break;
case 52:
LABEL_69:
printf("line %d: string concatenation\n", yylineno);
break;
case 53:
LABEL_70:
printf("line %d: function %s() call\n", yylineno, *(v1 - 3));
break;
case 58:
LABEL_71:
printf("line %d: if1\n", yylineno);
break;
default:
break;
}
if ( yydebug )
{
fprintf(stderr, "%s ", "-> $$ =");
yy_symbol_print(stderr, (unsigned __int8)yyr1[v8]);
fputc(10, stderr);
v18 = v9;
v11 = &v1[-v9];
v2 -= 2 * v18;
if ( yydebug )
yy_stack_print((__int16 *)v3, (unsigned __int64)v2);
}
else
{
LABEL_35:
v10 = v9;
v11 = &v1[-v9];
v2 -= 2 * v10;
}
v1 = v11 + 1;
v11[1] = v32;
v12 = (unsigned __int8)yyr1[v8] - 36;
v13 = *(__int16 *)v2 + yypgoto[v12];
if ( v13 <= 0xFB && *(_WORD *)v2 == yycheck[v13] )
v4 = yytable[v13];
else
v4 = yydefgoto[v12];
goto LABEL_39;
}
}
v19 = yychar;
v20 = yychar;
if ( yychar != -2 )
{
v20 = 2;
if ( (unsigned int)yychar <= 0x111 )
v20 = (unsigned __int8)yytranslate[yychar];
}
if ( !v30 )
{
++yynerrs;
yyerror();
goto LABEL_89;
}
if ( v30 == 3 )
{
if ( yychar > 0 )
{
yydestruct("Error: discarding", v20);
yychar = -2;
goto LABEL_89;
}
if ( !yychar )
{
v21 = 1;
LABEL_83:
v22 = (unsigned __int8)yytranslate[v19];
goto LABEL_102;
}
}
LABEL_89:
while ( 1 )
{
v23 = yypact[v4];
if ( v23 != -63 )
{
v24 = v23 + 1;
if ( v24 <= 0xFB && yycheck[v24] == 1 )
{
v25 = yytable[v24];
if ( v25 > 0 )
break;
}
}
if ( v2 == v3 )
{
v2 = v3;
v21 = 1;
goto LABEL_100;
}
yydestruct("Error: popping", (unsigned __int8)yystos[v4]);
--v1;
v2 -= 2;
v4 = *(__int16 *)v2;
if ( yydebug )
yy_stack_print((__int16 *)v3, (unsigned __int64)v2);
}
v1[1] = (const char *)yylval;
if ( yydebug )
{
fprintf(stderr, "%s ", "Shifting");
yy_symbol_print(stderr, (unsigned __int8)yystos[v25]);
fputc(10, stderr);
}
++v1;
v4 = v25;
v30 = 3;
LABEL_39:
v2 += 2;
}
v21 = 0;
LABEL_100:
v19 = yychar;
if ( yychar == -2 )
goto LABEL_103;
LABEL_101:
v22 = 2;
if ( v19 <= 0x111 )
goto LABEL_83;
LABEL_102:
yydestruct("Cleanup: discarding lookahead", v22);
LABEL_103:
if ( yydebug )
yy_stack_print((__int16 *)v3, (unsigned __int64)v2);
LABEL_105:
while ( v2 != v3 )
{
yydestruct("Cleanup: popping", (unsigned __int8)yystos[*(__int16 *)v2]);
--v1;
v2 -= 2;
}
if ( v3 != src )
free(v3);
return v21;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int64 v0; // r14
const char **v1; // r12
char *v2; // rbx
char *v3; // r13
unsigned int v4; // ebp
int v5; // er15
unsigned int v6; // er15
int v7; // er15
int v8; // er15
unsigned __int8 v9; // bp
__int64 v10; // rax
const char **v11; // rbp
int v12; // eax
unsigned int v13; // edx
unsigned __int64 v14; // rax
char *v15; // rax
char *v16; // r15
size_t v17; // r12
__int64 v18; // rax
unsigned int v19; // eax
int v20; // esi
unsigned int v21; // ebp
int v22; // esi
int v23; // eax
unsigned int v24; // eax
int v25; // er15
int v27; // [rsp+8h] [rbp-840h]
signed __int64 v28; // [rsp+8h] [rbp-840h]
char *v29; // [rsp+18h] [rbp-830h]
int v30; // [rsp+24h] [rbp-824h]
unsigned __int64 v31; // [rsp+28h] [rbp-820h]
const char *v32; // [rsp+38h] [rbp-810h]
char v33[1600]; // [rsp+40h] [rbp-808h] BYREF
char src[456]; // [rsp+680h] [rbp-1C8h] BYREF

if ( yydebug )
fwrite("Starting parse\n", 1uLL, 0xFuLL, stderr);
yynerrs = 0;
yychar = -2;
v0 = 200LL;
v1 = (const char **)v33;
v29 = v33;
v2 = src;
v3 = src;
v30 = 0;
v4 = 0;
while ( 1 )
{
*(_WORD *)v2 = v4;
v14 = 2 * v0;
if ( v2 < &v3[2 * v0 - 2] )
goto LABEL_6;
v28 = v2 - v3;
if ( v0 > 0x270F )
goto LABEL_96;
v0 = 10000LL;
if ( v14 <= 0x2710 )
v0 = v14;
v15 = (char *)malloc(10 * v0 + 7);
v16 = v15;
if ( !v15 )
{
LABEL_96:
func4();
v21 = 2;
goto LABEL_100;
}
memcpy(v15, v3, v28 + 2);
v17 = 8 * (((v2 - v3) >> 1) + 1);
v31 = 2 * v0;
memcpy(&v16[2 * v0], v29, v17);
if ( v3 != src )
free(v3);
v2 = &v16[v28];
v1 = (const char **)&v16[2 * v0 - 8 + v17];
if ( yydebug )
{
fprintf(stderr, "Stack size increased to %lu\n", v0);
if ( v2 >= &v16[v31 - 2] )
{
v3 = v16;
v21 = 1;
goto LABEL_100;
}
v29 = &v16[2 * v0];
v3 = v16;
LABEL_6:
if ( yydebug )
fprintf(stderr, "Entering state %d\n", v4);
goto LABEL_8;
}
if ( v2 >= &v16[v31 - 2] )
{
v19 = yychar;
v3 = v16;
v21 = 1;
if ( yychar == -2 )
goto LABEL_105;
goto LABEL_101;
}
v29 = &v16[2 * v0];
v3 = v16;
LABEL_8:
if ( v4 == 41 )
break;
v5 = yypact[v4];
if ( v5 == -63 )
goto LABEL_29;
if ( yychar == -2 )
{
if ( yydebug )
fwrite("Reading a token: ", 1uLL, 0x11uLL, stderr);
yychar = yylex();
}
if ( yychar <= 0 )
{
yychar = 0;
v27 = yydebug;
if ( yydebug )
{
fwrite("Now at end of input.\n", 1uLL, 0x15uLL, stderr);
v27 = 0;
}
}
else
{
v27 = 2;
if ( (unsigned int)yychar <= 0x111 )
v27 = (unsigned __int8)yytranslate[yychar];
if ( yydebug )
{
fprintf(stderr, "%s ", "Next token is");
func0(stderr, v27);
fputc(10, stderr);
}
}
v6 = v27 + v5;
if ( v6 > 0xFB || yycheck[v6] != v27 )
{
LABEL_29:
v8 = (unsigned __int8)yydefact[v4];
if ( yydefact[v4] )
goto LABEL_30;
}
else
{
v7 = yytable[v6];
if ( v7 > 0 )
{
v30 = (v30 == 0) + v30 - 1;
if ( yydebug )
{
fprintf(stderr, "%s ", "Shifting");
func0(stderr, v27);
fputc(10, stderr);
}
yychar = -2;
v1[1] = (const char *)yylval;
++v1;
v4 = v7;
goto LABEL_39;
}
if ( v7 != -43 )
{
v8 = -v7;
LABEL_30:
v9 = yyr2[v8];
v32 = v1[1 - v9];
if ( !yydebug )
{
switch ( v8 )
{
case 18:
goto LABEL_33;
case 19:
goto LABEL_50;
case 20:
goto LABEL_51;
case 21:
goto LABEL_52;
case 22:
goto LABEL_53;
case 36:
goto LABEL_54;
case 37:
goto LABEL_55;
case 38:
goto LABEL_56;
case 39:
goto LABEL_57;
case 40:
goto LABEL_58;
case 41:
goto LABEL_59;
case 42:
goto LABEL_60;
case 43:
goto LABEL_61;
case 44:
goto LABEL_62;
case 45:
goto LABEL_63;
case 46:
goto LABEL_64;
case 47:
goto LABEL_65;
case 48:
goto LABEL_66;
case 49:
goto LABEL_67;
case 50:
goto LABEL_68;
case 52:
goto LABEL_69;
case 53:
goto LABEL_70;
case 58:
goto LABEL_71;
default:
goto LABEL_35;
}
}
func1((__int64)v2, (__int64)v1, v8);
switch ( v8 )
{
case 18:
LABEL_33:
printf("line %d: declared '%s'\n", yylineno, *v1);
break;
case 19:
LABEL_50:
printf("line %d: scalar declared '%s' and assigned to '%s'\n", yylineno, *(v1 - 2), *v1);
break;
case 20:
LABEL_51:
printf("line %d: array declared '%s'\n", yylineno, *(v1 - 2));
break;
case 21:
LABEL_52:
printf("line %d: hash declared '%s'\n", yylineno, *(v1 - 2));
break;
case 22:
LABEL_53:
printf("line %d: function '%s' defined\n", yylineno, *(v1 - 4));
break;
case 36:
LABEL_54:
printf("line %d: array %s[], index %i\n", yylineno, *(v1 - 3), *((unsigned int *)v1 - 2));
break;
case 37:
LABEL_55:
printf("line %d: hash %s{}, indexed by expression\n", yylineno, *(v1 - 3));
break;
case 38:
LABEL_56:
printf("line %d: addition\n", yylineno);
break;
case 39:
LABEL_57:
printf("line %d: subtraction\n", yylineno);
break;
case 40:
LABEL_58:
printf("line %d: multiplication\n", yylineno);
break;
case 41:
LABEL_59:
printf("line %d: division\n", yylineno);
break;
case 42:
LABEL_60:
printf("line %d: unary minus\n", yylineno);
break;
case 43:
LABEL_61:
printf("line %d: less than\n", yylineno);
break;
case 44:
LABEL_62:
printf("line %d: more than\n", yylineno);
break;
case 45:
LABEL_63:
printf("line %d: less than or equal\n", yylineno);
break;
case 46:
LABEL_64:
printf("line %d: more than or equal\n", yylineno);
break;
case 47:
LABEL_65:
printf("line %d: equal\n", yylineno);
break;
case 48:
LABEL_66:
printf("line %d: not equal\n", yylineno);
break;
case 49:
LABEL_67:
printf("line %d: approximate equall\n", yylineno);
break;
case 50:
LABEL_68:
printf("line %d: unary negation\n", yylineno);
break;
case 52:
LABEL_69:
printf("line %d: string concatenation\n", yylineno);
break;
case 53:
LABEL_70:
printf("line %d: function %s() call\n", yylineno, *(v1 - 3));
break;
case 58:
LABEL_71:
printf("line %d: if1\n", yylineno);
break;
default:
break;
}
if ( yydebug )
{
fprintf(stderr, "%s ", "-> $$ =");
func0(stderr, (unsigned __int8)yyr1[v8]);
fputc(10, stderr);
v18 = v9;
v11 = &v1[-v9];
v2 -= 2 * v18;
if ( yydebug )
func2((__int16 *)v3, (unsigned __int64)v2);
}
else
{
LABEL_35:
v10 = v9;
v11 = &v1[-v9];
v2 -= 2 * v10;
}
v1 = v11 + 1;
v11[1] = v32;
v12 = (unsigned __int8)yyr1[v8] - 36;
v13 = *(__int16 *)v2 + yypgoto[v12];
if ( v13 <= 0xFB && *(_WORD *)v2 == yycheck[v13] )
v4 = yytable[v13];
else
v4 = yydefgoto[v12];
goto LABEL_39;
}
}
v19 = yychar;
v20 = yychar;
if ( yychar != -2 )
{
v20 = 2;
if ( (unsigned int)yychar <= 0x111 )
v20 = (unsigned __int8)yytranslate[yychar];
}
if ( !v30 )
{
++yynerrs;
func4();
goto LABEL_89;
}
if ( v30 == 3 )
{
if ( yychar > 0 )
{
func3("Error: discarding", v20);
yychar = -2;
goto LABEL_89;
}
if ( !yychar )
{
v21 = 1;
LABEL_83:
v22 = (unsigned __int8)yytranslate[v19];
goto LABEL_102;
}
}
LABEL_89:
while ( 1 )
{
v23 = yypact[v4];
if ( v23 != -63 )
{
v24 = v23 + 1;
if ( v24 <= 0xFB && yycheck[v24] == 1 )
{
v25 = yytable[v24];
if ( v25 > 0 )
break;
}
}
if ( v2 == v3 )
{
v2 = v3;
v21 = 1;
goto LABEL_100;
}
func3("Error: popping", (unsigned __int8)yystos[v4]);
--v1;
v2 -= 2;
v4 = *(__int16 *)v2;
if ( yydebug )
func2((__int16 *)v3, (unsigned __int64)v2);
}
v1[1] = (const char *)yylval;
if ( yydebug )
{
fprintf(stderr, "%s ", "Shifting");
func0(stderr, (unsigned __int8)yystos[v25]);
fputc(10, stderr);
}
++v1;
v4 = v25;
v30 = 3;
LABEL_39:
v2 += 2;
}
v21 = 0;
LABEL_100:
v19 = yychar;
if ( yychar == -2 )
goto LABEL_103;
LABEL_101:
v22 = 2;
if ( v19 <= 0x111 )
goto LABEL_83;
LABEL_102:
func3("Cleanup: discarding lookahead", v22);
LABEL_103:
if ( yydebug )
func2((__int16 *)v3, (unsigned __int64)v2);
LABEL_105:
while ( v2 != v3 )
{
func3("Cleanup: popping", (unsigned __int8)yystos[*(__int16 *)v2]);
--v1;
v2 -= 2;
}
if ( v3 != src )
free(v3);
return v21;
}

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  do { if (yydebug) fprintf (stderr, "Starting parse\n"); } while (0);
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      do { if (yydebug) fprintf (stderr, "Stack size increased to %lu\n", (unsigned long) yystacksize); } while (0);
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  do { if (yydebug) fprintf (stderr, "Entering state %d\n", yystate); } while (0);
  if (yystate == 41)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-63))))
    goto yydefault;
  if (yychar == (-2))
    {
      do { if (yydebug) fprintf (stderr, "Reading a token: "); } while (0);
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      do { if (yydebug) fprintf (stderr, "Now at end of input.\n"); } while (0);
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 273 ? yytranslate[yychar] : 2);
      do { if (yydebug) { fprintf (stderr, "%s ", "Next token is"); yy_symbol_print (stderr, yytoken, &yylval); fprintf (stderr, "\n"); } } while (0);
    }
  yyn += yytoken;
  if (yyn < 0 || 251 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if ((!!((yyn) == (-43))))
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  do { if (yydebug) { fprintf (stderr, "%s ", "Shifting"); yy_symbol_print (stderr, yytoken, &yylval); fprintf (stderr, "\n"); } } while (0);
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  do { if (yydebug) yy_reduce_print (yyssp, yyvsp, yyn); } while (0);
  switch (yyn)
    {
        case 18:
    {printf("line %d: declared '%s'\n", yylineno, (yyvsp[0].s)); }
    break;
  case 19:
    {printf("line %d: scalar declared '%s' and assigned to '%s'\n", yylineno, (yyvsp[-2].s), (yyvsp[0].s));}
    break;
  case 20:
    {printf("line %d: array declared '%s'\n", yylineno, (yyvsp[-2].s));}
    break;
  case 21:
    {printf("line %d: hash declared '%s'\n", yylineno, (yyvsp[-2].s));}
    break;
  case 22:
    {printf("line %d: function '%s' defined\n", yylineno, (yyvsp[-4].s));}
    break;
  case 36:
    {printf("line %d: array %s[], index %i\n", yylineno, (yyvsp[-3].s), (yyvsp[-1].i));}
    break;
  case 37:
    {printf("line %d: hash %s{}, indexed by expression\n", yylineno, (yyvsp[-3].s));}
    break;
  case 38:
    {printf("line %d: addition\n", yylineno);}
    break;
  case 39:
    {printf("line %d: subtraction\n", yylineno);}
    break;
  case 40:
    {printf("line %d: multiplication\n", yylineno);}
    break;
  case 41:
    {printf("line %d: division\n", yylineno);}
    break;
  case 42:
    {printf("line %d: unary minus\n", yylineno);}
    break;
  case 43:
    {printf("line %d: less than\n", yylineno);}
    break;
  case 44:
    {printf("line %d: more than\n", yylineno);}
    break;
  case 45:
    {printf("line %d: less than or equal\n", yylineno);}
    break;
  case 46:
    {printf("line %d: more than or equal\n", yylineno);}
    break;
  case 47:
    {printf("line %d: equal\n", yylineno);}
    break;
  case 48:
    {printf("line %d: not equal\n", yylineno);}
    break;
  case 49:
    {printf("line %d: approximate equall\n", yylineno);}
    break;
  case 50:
    {printf("line %d: unary negation\n", yylineno);}
    break;
  case 52:
    {printf("line %d: string concatenation\n", yylineno);}
    break;
  case 53:
    {printf("line %d: function %s() call\n", yylineno, (yyvsp[-3].s));}
    break;
  case 58:
    {printf("line %d: if1\n", yylineno);}
    break;
      default: break;
    }
  do { if (yydebug) { fprintf (stderr, "%s ", "-> $$ ="); yy_symbol_print (stderr, yyr1[yyn], &yyval); fprintf (stderr, "\n"); } } while (0);
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 36;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 251 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 273 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-63))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 251 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  do { if (yydebug) { fprintf (stderr, "%s ", "Shifting"); yy_symbol_print (stderr, yystos[yyn], yyvsp); fprintf (stderr, "\n"); } } while (0);
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 273 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  do { if (yydebug) fprintf (stderr, "Starting parse\n"); } while (0);
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      do { if (yydebug) fprintf (stderr, "Stack size increased to %lu\n", (unsigned long) yystacksize); } while (0);
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  do { if (yydebug) fprintf (stderr, "Entering state %d\n", yystate); } while (0);
  if (yystate == 41)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-63))))
    goto yydefault;
  if (yychar == (-2))
    {
      do { if (yydebug) fprintf (stderr, "Reading a token: "); } while (0);
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      do { if (yydebug) fprintf (stderr, "Now at end of input.\n"); } while (0);
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 273 ? yytranslate[yychar] : 2);
      do { if (yydebug) { fprintf (stderr, "%s ", "Next token is"); yy_symbol_print (stderr, yytoken, &yylval); fprintf (stderr, "\n"); } } while (0);
    }
  yyn += yytoken;
  if (yyn < 0 || 251 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if ((!!((yyn) == (-43))))
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  do { if (yydebug) { fprintf (stderr, "%s ", "Shifting"); yy_symbol_print (stderr, yytoken, &yylval); fprintf (stderr, "\n"); } } while (0);
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  do { if (yydebug) yy_reduce_print (yyssp, yyvsp, yyn); } while (0);
  switch (yyn)
    {
        case 18:
    {printf("line %d: declared '%s'\n", yylineno, (yyvsp[0].s)); }
    break;
  case 19:
    {printf("line %d: scalar declared '%s' and assigned to '%s'\n", yylineno, (yyvsp[-2].s), (yyvsp[0].s));}
    break;
  case 20:
    {printf("line %d: array declared '%s'\n", yylineno, (yyvsp[-2].s));}
    break;
  case 21:
    {printf("line %d: hash declared '%s'\n", yylineno, (yyvsp[-2].s));}
    break;
  case 22:
    {printf("line %d: function '%s' defined\n", yylineno, (yyvsp[-4].s));}
    break;
  case 36:
    {printf("line %d: array %s[], index %i\n", yylineno, (yyvsp[-3].s), (yyvsp[-1].i));}
    break;
  case 37:
    {printf("line %d: hash %s{}, indexed by expression\n", yylineno, (yyvsp[-3].s));}
    break;
  case 38:
    {printf("line %d: addition\n", yylineno);}
    break;
  case 39:
    {printf("line %d: subtraction\n", yylineno);}
    break;
  case 40:
    {printf("line %d: multiplication\n", yylineno);}
    break;
  case 41:
    {printf("line %d: division\n", yylineno);}
    break;
  case 42:
    {printf("line %d: unary minus\n", yylineno);}
    break;
  case 43:
    {printf("line %d: less than\n", yylineno);}
    break;
  case 44:
    {printf("line %d: more than\n", yylineno);}
    break;
  case 45:
    {printf("line %d: less than or equal\n", yylineno);}
    break;
  case 46:
    {printf("line %d: more than or equal\n", yylineno);}
    break;
  case 47:
    {printf("line %d: equal\n", yylineno);}
    break;
  case 48:
    {printf("line %d: not equal\n", yylineno);}
    break;
  case 49:
    {printf("line %d: approximate equall\n", yylineno);}
    break;
  case 50:
    {printf("line %d: unary negation\n", yylineno);}
    break;
  case 52:
    {printf("line %d: string concatenation\n", yylineno);}
    break;
  case 53:
    {printf("line %d: function %s() call\n", yylineno, (yyvsp[-3].s));}
    break;
  case 58:
    {printf("line %d: if1\n", yylineno);}
    break;
      default: break;
    }
  do { if (yydebug) { fprintf (stderr, "%s ", "-> $$ ="); yy_symbol_print (stderr, yyr1[yyn], &yyval); fprintf (stderr, "\n"); } } while (0);
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 36;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 251 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 273 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-63))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 251 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  do { if (yydebug) { fprintf (stderr, "%s ", "Shifting"); yy_symbol_print (stderr, yystos[yyn], yyvsp); fprintf (stderr, "\n"); } } while (0);
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 273 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  do { if (yydebug) yy_stack_print ((yyss), (yyssp)); } while (0);
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types:
yyvsa
union YYSTYPE { char *s; int i; } [200]

variable_types:
yyvs
union YYSTYPE { char *s; int i; } *

variable_types:
yyvsp
union YYSTYPE { char *s; int i; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types:
yyval
union YYSTYPE { char *s; int i; }

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { char *s; int i; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }


createGradeRecord

decompiled_code:
void *createGradeRecord()
{
_QWORD *v0; // rbx
void *result; // rax

v0 = malloc(0x18uLL);
gradeRecord = (__int64)v0;
*v0 = malloc(0x50uLL);
v0[2] = malloc(1uLL);
result = malloc(0xBuLL);
v0[1] = result;
return result;
}

canonical_decompiled_code:
void *func7()
{
_QWORD *v0; // rbx
void *result; // rax

v0 = malloc(0x18uLL);
gradeRecord = (__int64)v0;
*v0 = malloc(0x50uLL);
v0[2] = malloc(1uLL);
result = malloc(0xBuLL);
v0[1] = result;
return result;
}

original_code:
void createGradeRecord()
{
  gradeRecord = (dbrecord *) malloc(sizeof(dbrecord));
  gradeRecord->Name = (char *) malloc(80);
  gradeRecord->Grade = (char *) malloc(1);
  gradeRecord->SSN = (char *) malloc(11);
}

canonical_original_code:
void createGradeRecord()
{
  gradeRecord = (struct dbrecord *) malloc(sizeof(dbrecord));
  gradeRecord->Name = (char *) malloc(80);
  gradeRecord->Grade = (char *) malloc(1);
  gradeRecord->SSN = (char *) malloc(11);
}

user_defined_types: struct dbrecord { char *Name; char *SSN; char *Grade; }


checkfordone

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

result = a2;
if ( strcmp(a2, "Done") )
{
fprintf(stderr, "Invalid response to %s command (%s)\n", a1, a2);
exit(1);
}
return result;
}

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

result = a2;
if ( strcmp(a2, "Done") )
{
fprintf(stderr, "Invalid response to %s command (%s)\n", a1, a2);
exit(1);
}
return result;
}

original_code:
void checkfordone(char *command, char *replybuffer)
{
 if (strcmp(replybuffer, "Done") != 0)
 {
  fprintf(stderr, "Invalid response to %s command (%s)\n", command, replybuffer);
  exit(1);
 }
}

variable_types:
command
char *

variable_types:
replybuffer
char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(
stderr,
"Usage: %s (-r size [-o offset])|-f filename [-s serialport]\n\tserialport defaults to /dev/ttyUSB0\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(const char *a1)
{
fprintf(
stderr,
"Usage: %s (-r size [-o offset])|-f filename [-s serialport]\n\tserialport defaults to /dev/ttyUSB0\n",
a1);
exit(1);
}

original_code:
void usage(char *argv0)
{
 fprintf(stderr, "Usage: %s (-r size [-o offset])|-f filename [-s serialport]\n" "\tserialport defaults to /dev/ttyUSB0\n", argv0);
 exit(1);
}


ZeroPadding

repo: asrAachen/ASR

decompiled_code:
void __fastcall ZeroPadding(__int64 a1, int a2)
{
_QWORD *v2; // rax

if ( a2 <= 1023 )
{
v2 = (_QWORD *)(a1 + 8LL * a2);
do
*v2++ = 0LL;
while ( v2 != (_QWORD *)(a1 + 8 * (a2 + (unsigned __int64)(unsigned int)(1023 - a2)) + 8) );
}
}

original_code:
static void ZeroPadding(double *Re_Signal, int N_sig)
{
  int i;
  for(i=N_sig; i<1024; i++) Re_Signal[i]=0.0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall modemctl_link_set_active(unsigned int *a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
result = c_ioctl(*a1, 28465LL, v3);
if ( (int)result > 0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
result = c_ioctl(*a1, 28465LL, v3);
if ( (int)result > 0 )
result = 0LL;
return result;
}

original_code:
int modemctl_link_set_active(fwloader_context *ctx, _Bool enabled) {
 unsigned status = enabled;
 int ret;
 unsigned long ioctl_code;
 ioctl_code = (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x31)) << 0) | ((0) << ((0 +8)+8)));
 ret = c_ioctl(ctx->link_fd, ioctl_code, &status);
 if (ret < 0) {
  do {} while (0);
  goto fail;
 }
 return 0;
fail:
 return ret;
}

canonical_original_code:
int modemctl_link_set_active(struct fwloader_context *ctx, _Bool enabled) {
 unsigned int status = enabled;
 int ret;
 unsigned long ioctl_code;
 ioctl_code = (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x31)) << 0) | ((0) << ((0 +8)+8)));
 ret = c_ioctl(ctx->link_fd, ioctl_code, &status);
 if (ret < 0) {
  do {} while (0);
  goto fail;
 }
 return 0;
fail:
 return ret;
}

variable_types: struct fwloader_context { int link_fd; int boot_fd; int radio_fd; char *radio_data; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } radio_stat; } *

variable_types:
status
unsigned int

variable_types: ret int

user_defined_types: struct fwloader_context { int link_fd; int boot_fd; int radio_fd; char *radio_data; struct stat radio_stat; }


decompiled_code:
__int64 __fastcall modemctl_link_set_enabled(unsigned int *a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
result = c_ioctl(*a1, 28464LL, v3);
if ( (int)result > 0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
result = c_ioctl(*a1, 28464LL, v3);
if ( (int)result > 0 )
result = 0LL;
return result;
}

original_code:
int modemctl_link_set_enabled(fwloader_context *ctx, _Bool enabled) {
 unsigned status = enabled;
 int ret;
 unsigned long ioctl_code;
 ioctl_code = (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x30)) << 0) | ((0) << ((0 +8)+8)));
 ret = c_ioctl(ctx->link_fd, ioctl_code, &status);
 if (ret < 0) {
  do {} while (0);
  goto fail;
 }
 return 0;
fail:
 return ret;
}

canonical_original_code:
int modemctl_link_set_enabled(struct fwloader_context *ctx, _Bool enabled) {
 unsigned int status = enabled;
 int ret;
 unsigned long ioctl_code;
 ioctl_code = (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x30)) << 0) | ((0) << ((0 +8)+8)));
 ret = c_ioctl(ctx->link_fd, ioctl_code, &status);
 if (ret < 0) {
  do {} while (0);
  goto fail;
 }
 return 0;
fail:
 return ret;
}

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


decompiled_code:
__int64 __fastcall modemctl_wait_link_ready(unsigned int *a1)
{
__int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
gettimeofday(&tv, 0LL);
while ( 1 )
{
result = c_ioctl(*a1, 28467LL, 0LL);
if ( (int)result < 0 )
break;
if ( (_DWORD)result == 1 )
return 0LL;
usleep(0xC350u);
gettimeofday(&v2, 0LL);
if ( 1000 * (v2.tv_sec - tv.tv_sec) + (v2.tv_usec - tv.tv_usec) / 1000 > 1999 )
return 4294967186LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
__int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
gettimeofday(&tv, 0LL);
while ( 1 )
{
result = c_ioctl(*a1, 28467LL, 0LL);
if ( (int)result < 0 )
break;
if ( (_DWORD)result == 1 )
return 0LL;
usleep(0xC350u);
gettimeofday(&v2, 0LL);
if ( 1000 * (v2.tv_sec - tv.tv_sec) + (v2.tv_usec - tv.tv_usec) / 1000 > 1999 )
return 4294967186LL;
}
return result;
}

original_code:
int modemctl_wait_link_ready(fwloader_context *ctx) {
 int ret;
 struct timeval tv_start = {};
 struct timeval tv_end = {};
 gettimeofday(&tv_start, 0);;
 long diff = 0;
 do {
  ret = c_ioctl(ctx->link_fd, (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x33)) << 0) | ((0) << ((0 +8)+8))), 0);
  if (ret < 0) {
   goto fail;
  }
  if (ret == 1) {
   return 0;
  }
  usleep((50 * 1000));
  gettimeofday(&tv_end, 0);;
  diff = (tv_end.tv_sec - tv_start.tv_sec) * 1000;
  diff += (tv_end.tv_usec - tv_start.tv_usec) / 1000;
 } while (diff < 2000);
 ret = -110;
fail:
 return ret;
}

canonical_original_code:
int modemctl_wait_link_ready(struct fwloader_context *ctx) {
 int ret;
 struct timeval tv_start = {};
 struct timeval tv_end = {};
 gettimeofday(&tv_start, 0);;
 long diff = 0;
 do {
  ret = c_ioctl(ctx->link_fd, (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x33)) << 0) | ((0) << ((0 +8)+8))), 0);
  if (ret < 0) {
   goto fail;
  }
  if (ret == 1) {
   return 0;
  }
  usleep((50 * 1000));
  gettimeofday(&tv_end, 0);;
  diff = (tv_end.tv_sec - tv_start.tv_sec) * 1000;
  diff += (tv_end.tv_usec - tv_start.tv_usec) / 1000;
 } while (diff < 2000);
 ret = -110;
fail:
 return ret;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: diff long


decompiled_code:
__int64 __fastcall modemctl_wait_modem_online(__int64 a1)
{
__int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
gettimeofday(&tv, 0LL);
while ( 1 )
{
result = c_ioctl(*(unsigned int *)(a1 + 4), 28455LL, 0LL);
if ( (int)result < 0 )
break;
if ( (_DWORD)result == 4 )
return 0LL;
usleep(0xC350u);
gettimeofday(&v2, 0LL);
if ( 1000 * (v2.tv_sec - tv.tv_sec) + (v2.tv_usec - tv.tv_usec) / 1000 > 1999 )
return 4294967186LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
gettimeofday(&tv, 0LL);
while ( 1 )
{
result = c_ioctl(*(unsigned int *)(a1 + 4), 28455LL, 0LL);
if ( (int)result < 0 )
break;
if ( (_DWORD)result == 4 )
return 0LL;
usleep(0xC350u);
gettimeofday(&v2, 0LL);
if ( 1000 * (v2.tv_sec - tv.tv_sec) + (v2.tv_usec - tv.tv_usec) / 1000 > 1999 )
return 4294967186LL;
}
return result;
}

original_code:
int modemctl_wait_modem_online(fwloader_context *ctx) {
 int ret;
 struct timeval tv_start = {};
 struct timeval tv_end = {};
 gettimeofday(&tv_start, 0);;
 long diff = 0;
 do {
  ret = c_ioctl(ctx->boot_fd, (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x27)) << 0) | ((0) << ((0 +8)+8))), 0);
  if (ret < 0) {
   goto fail;
  }
  if (ret == STATE_ONLINE) {
   return 0;
  }
  usleep((50 * 1000));
  gettimeofday(&tv_end, 0);;
  diff = (tv_end.tv_sec - tv_start.tv_sec) * 1000;
  diff += (tv_end.tv_usec - tv_start.tv_usec) / 1000;
 } while (diff < 2000);
 ret = -110;
fail:
 return ret;
}

canonical_original_code:
int modemctl_wait_modem_online(struct fwloader_context *ctx) {
 int ret;
 struct timeval tv_start = {};
 struct timeval tv_end = {};
 gettimeofday(&tv_start, 0);;
 long diff = 0;
 do {
  ret = c_ioctl(ctx->boot_fd, (((0U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((0x27)) << 0) | ((0) << ((0 +8)+8))), 0);
  if (ret < 0) {
   goto fail;
  }
  if (ret == STATE_ONLINE) {
   return 0;
  }
  usleep((50 * 1000));
  gettimeofday(&tv_end, 0);;
  diff = (tv_end.tv_sec - tv_start.tv_sec) * 1000;
  diff += (tv_end.tv_usec - tv_start.tv_usec) / 1000;
 } while (diff < 2000);
 ret = -110;
fail:
 return ret;
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall modemctl_modem_power(__int64 a1, char a2)
{
__int64 result; // rax

if ( a2 )
result = c_ioctl(*(unsigned int *)(a1 + 4), 28441LL, 0LL);
else
result = c_ioctl(*(unsigned int *)(a1 + 4), 28448LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
__int64 result; // rax

if ( a2 )
result = c_ioctl(*(unsigned int *)(a1 + 4), 28441LL, 0LL);
else
result = c_ioctl(*(unsigned int *)(a1 + 4), 28448LL, 0LL);
return result;
}


decompiled_code:
__int64 __fastcall modemctl_modem_boot_power(__int64 a1, char a2)
{
__int64 result; // rax

if ( a2 )
result = c_ioctl(*(unsigned int *)(a1 + 4), 28450LL, 0LL);
else
result = c_ioctl(*(unsigned int *)(a1 + 4), 28451LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
__int64 result; // rax

if ( a2 )
result = c_ioctl(*(unsigned int *)(a1 + 4), 28450LL, 0LL);
else
result = c_ioctl(*(unsigned int *)(a1 + 4), 28451LL, 0LL);
return result;
}


calculateCRC

decompiled_code:
char __fastcall calculateCRC(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE *v3; // rsi
_BYTE *v4; // rdx
char result; // al

v3 = (_BYTE *)(a1 + a2);
if ( !a3 )
return 0;
v4 = &v3[a3];
result = 0;
do
result ^= *v3++;
while ( v4 != v3 );
return result;
}

canonical_decompiled_code:
char __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE *v3; // rsi
_BYTE *v4; // rdx
char result; // al

v3 = (_BYTE *)(a1 + a2);
if ( !a3 )
return 0;
v4 = &v3[a3];
result = 0;
do
result ^= *v3++;
while ( v4 != v3 );
return result;
}

original_code:
unsigned char calculateCRC(void* data, size_t offset, size_t length)
{
 unsigned char crc = 0;
 unsigned char *ptr = (unsigned char*)(data + offset);
 while (length--) {
  crc ^= *ptr++;
 }
 return crc;
}

canonical_original_code:
unsigned char calculateCRC(void *data, unsigned long offset, unsigned long length)
{
 unsigned char crc = 0;
 unsigned char *ptr = (unsigned char*)(data + offset);
 while (length--) {
  crc ^= *ptr++;
 }
 return crc;
}

variable_types:
data
void *

variable_types:
offset
unsigned long

variable_types:
length
unsigned long

variable_types:
crc
unsigned char

variable_types:
ptr
unsigned char *

return_type: unsigned char