decompiled_code:
int __fastcall handle_arguments(int argc, char **argv)
{
unsigned __int64 v2; // rax
__int64 v3; // rcx
int result; // eax

red = 100;
yellow = 100;
blue = 100;
green = 100;
white = 100;
sound = 100;
opterr = 0;
while ( 1 )
{
result = getopt(argc, argv, "r:y:b:g:w:s:");
if ( result == -1 )
break;
if ( result == 63 )
{
v2 = (unsigned int)(optopt - 98);
if ( (unsigned int)v2 <= 0x17 && (v3 = 10682401LL, _bittest64(&v3, v2)) )
fprintf(stderr, "Option '%c' requires an argument\n", (unsigned int)optopt);
else
fprintf(stderr, "Unhandled option '%c' given\n", (unsigned int)optopt);
usage();
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int argc, char **argv)
{
unsigned __int64 v2; // rax
__int64 v3; // rcx
int result; // eax

red = 100;
yellow = 100;
blue = 100;
green = 100;
white = 100;
sound = 100;
opterr = 0;
while ( 1 )
{
result = getopt(argc, argv, "r:y:b:g:w:s:");
if ( result == -1 )
break;
if ( result == 63 )
{
v2 = (unsigned int)(optopt - 98);
if ( (unsigned int)v2 <= 0x17 && (v3 = 10682401LL, _bittest64(&v3, v2)) )
fprintf(stderr, "Option '%c' requires an argument\n", (unsigned int)optopt);
else
fprintf(stderr, "Unhandled option '%c' given\n", (unsigned int)optopt);
func7();
exit(1);
}
}
return result;
}

original_code:
void handle_arguments(int argc, char *argv[])
{
 int opt;
 red = light_nochange;
 yellow = light_nochange;
 blue = light_nochange;
 green = light_nochange;
 white = light_nochange;
 sound = sound_nochange;
 opterr = 0;
 while((opt = getopt(argc, argv, "r:y:b:g:w:s:")) != -1)
 {
  switch(opt)
  {
   case '?':
    if(optopt == 'r' ||
     optopt == 'y' ||
     optopt == 'b' ||
     optopt == 'g' ||
     optopt == 'w' ||
     optopt == 's')
    {
     fprintf(stderr, "Option '%c' requires an argument\n", optopt);
    }
    else
    {
     fprintf(stderr, "Unhandled option '%c' given\n", optopt);
    }
    usage(argv[0]);
    exit(1);
   case 'r':
    parse_option(&red, optarg, 1);
    break;
   case 'y':
    parse_option(&yellow, optarg, 1);
    break;
   case 'b':
    parse_option(&blue, optarg, 1);
    break;
   case 'g':
    parse_option(&green, optarg, 1);
    break;
   case 'w':
    parse_option(&white, optarg, 1);
    break;
   case 's':
    parse_option(&sound, optarg, 0);
    break;
  }
 }
}

variable_types:
argv
char *[]

variable_types: opt int


quit

decompiled_code:
void __fastcall __noreturn quit(int status)
{
libusb_exit();
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(int status)
{
libusb_exit();
exit(status);
}

original_code:
void quit(int exitCode)
{
 libusb_exit(context);
 exit(exitCode);
}

variable_types: exitCode int

return_type: void


decompiled_code:
__int64 usb_release()
{
if ( (unsigned int)libusb_release_interface() )
{
fwrite("Failed to release interface\n", 1uLL, 0x1CuLL, stderr);
libusb_close();
quit(1);
}
puts("Released interface");
return libusb_close();
}

canonical_decompiled_code:
__int64 func12()
{
if ( (unsigned int)libusb_release_interface() )
{
fwrite("Failed to release interface\n", 1uLL, 0x1CuLL, stderr);
libusb_close();
func10(1);
}
puts("Released interface");
return libusb_close();
}

original_code:
void usb_release(void)
{
 if(libusb_release_interface(qlight_handle, 0) != 0)
 {
  fprintf(stderr, "Failed to release interface\n");
  libusb_close(qlight_handle);
  quit(1);
 }
 printf("Released interface\n");
 libusb_close(qlight_handle);
}

canonical_original_code:
void usb_release()
{
 if(libusb_release_interface(qlight_handle, 0) != 0)
 {
  fprintf(stderr, "Failed to release interface\n");
  libusb_close(qlight_handle);
  quit(1);
 }
 printf("Released interface\n");
 libusb_close(qlight_handle);
}


decompiled_code:
_BOOL8 set_state()
{
int v0; // edx
_BOOL8 result; // rax
int v2; // [rsp+1Ch] [rbp-Ch]

v0 = libusb_bulk_transfer();
result = 0LL;
if ( !v0 )
result = v2 == 16;
return result;
}

canonical_decompiled_code:
_BOOL8 func13()
{
int v0; // edx
_BOOL8 result; // rax
int v2; // [rsp+1Ch] [rbp-Ch]

v0 = libusb_bulk_transfer();
result = 0LL;
if ( !v0 )
result = v2 == 16;
return result;
}

original_code:
int set_state(int red, int yellow, int green, int blue, int white, int sound)
{
 int bytesWritten;
 unsigned char data[16];
 memcpy(data, data_template, 16);
 data[qlight_red] = red;
 data[qlight_yellow] = yellow;
 data[qlight_green] = green;
 data[qlight_blue] = blue;
 data[qlight_white] = white;
 data[qlight_sound] = sound;
 if(libusb_bulk_transfer(qlight_handle, 0x1, data, 16, &bytesWritten, 0) == 0 && bytesWritten == 16)
 {
  return 1;
 }
 return 0;
}

variable_types: red int

variable_types: yellow int

variable_types: green int

variable_types: blue int

variable_types: white int

variable_types: sound int

variable_types: bytesWritten int

variable_types:
data
unsigned char [16]

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rdi

if ( argc > 1 )
{
handle_arguments(argc, (char **)argv);
init();
v3 = (unsigned int)yellow;
v4 = (unsigned int)red;
set_state();
usb_release(v4, v3);
quit(0);
}
usage();
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rdi

if ( argc > 1 )
{
func9(argc, (char **)argv);
func11();
v3 = (unsigned int)yellow;
v4 = (unsigned int)red;
func13();
func12(v4, v3);
func10(0);
}
func7();
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
 if(argc < 2)
 {
  usage(argv[0]);
  exit(1);
 }
 handle_arguments(argc, argv);
 init();
 set_state(red, yellow, green, blue, white, sound);
 usb_release();
 quit(0);
 return 0;
}

variable_types: argc int


repo: Kevin-P-Kerr/lilhttp

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
const char *v4; // r12
__int16 v5; // ax
struct epoll_event *v6; // r12
int v7; // eax
int v8; // er13
int v9; // eax
int *v10; // rbx
__int64 v11; // rbp
int v12; // eax
int v13; // eax
__int64 v14; // rdx
int *v15; // r15
int v16; // eax
struct epoll_event event; // [rsp+4h] [rbp-74h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
__int16 v19[2]; // [rsp+20h] [rbp-58h] BYREF
int v20; // [rsp+24h] [rbp-54h]
socklen_t addr_len; // [rsp+34h] [rbp-44h] BYREF
int v22; // [rsp+38h] [rbp-40h] BYREF
int fd[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

c("in main", argv, envp);
c("running unit tests", argv, v3);
v4 = *argv;
initFt();
parse();
addr_len = 0;
if ( argc <= 1 )
{
fwrite("\nLil'Http: portno config", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !(unsigned int)createSocket(fd) )
{
fprintf(stderr, "%s ERROR, COULD NOT CREATE SERVER SOCKET\n", v4);
exit(1);
}
v19[0] = 2;
v5 = atoi(argv[1]);
v19[1] = _bswap_16(v5);
v20 = 0;
Bind(fd, v19);
listen(fd[0], 5);
v6 = (struct epoll_event *)calloc(0x80uLL, 0xCuLL);
makeSocketNB(fd);
event.events = -2147483647;
event.data.fd = fd[0];
v7 = createpoll();
v8 = v7;
if ( v7 < 0 )
{
fwrite("epoll create error\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
if ( epoll_ctl(v7, 1, fd[0], &event) == -1 )
{
fwrite("error with epoll_ctl on sockfd", 1uLL, 0x1EuLL, stderr);
exit(1);
}
while ( 1 )
{
do
v9 = epoll_wait(v8, v6, 128, -1);
while ( v9 <= 0 );
v10 = (int *)&v6->data;
v11 = (__int64)&v6[(unsigned int)(v9 - 1) + 1].data;
do
{
v12 = *(v10 - 1);
if ( (v12 & 0x18) != 0 || (v12 & 1) == 0 )
{
fwrite("epoll error\n", 1uLL, 0xCuLL, stderr);
close(*v10);
goto LABEL_12;
}
if ( *v10 == fd[0] )
{
while ( 1 )
{
v22 = accept(fd[0], &addr, &addr_len);
if ( v22 <= 0 )
{
v15 = _errno_location();
v16 = *v15;
if ( *v15 == 11 )
{
fwrite("we have accepted all the clients on this event\n", 1uLL, 0x2FuLL, stderr);
goto LABEL_12;
}
switch ( v16 )
{
case 'd':
c("ENETDOWN", &addr, v14);
break;
case 'G':
c("EPROTO", &addr, v14);
break;
case '\\':
c("ENOPROTOOPT", &addr, v14);
break;
case 'p':
c("EHOSTDOWN", &addr, v14);
break;
case '@':
c("ENONET", &addr, v14);
break;
case 'q':
c("EHOSTUNREACH", &addr, v14);
break;
case '_':
c("EOPNOTSUPP", &addr, v14);
break;
case 'e':
c("ENETUNREACH", &addr, v14);
break;
default:
c("what is going on here?", &addr, v14);
perror(sys_errlist[*v15]);
break;
}
for ( ; v22 < 0; v22 = accept(fd[0], &addr, &addr_len) )
;
}
else
{
makeSocketNB(&v22);
fprintf(stderr, "Accepted a new connection on fd %d, made nonblocking\n", (unsigned int)v22);
}
event.data.fd = v22;
event.events = -2147483647;
if ( epoll_ctl(v8, 1, v22, &event) < 0 )
{
fwrite("epoll_ctl error\n", 1uLL, 0x10uLL, stderr);
v13 = *_errno_location();
switch ( v13 )
{
case 17:
fwrite("fd already registered\n", 1uLL, 0x16uLL, stderr);
break;
case 9:
fprintf(stderr, "fd bad\n%d\n", (unsigned int)v22);
goto LABEL_12;
case 12:
fwrite("no memory\n", 1uLL, 0xAuLL, stderr);
break;
case 28:
fwrite("enospc\n", 1uLL, 7uLL, stderr);
break;
}
exit(1);
}
}
}
handleResponse(v10);
fprintf(stderr, "we are about to close file descriptor %d\n", (unsigned int)*v10);
close(*v10);
fwrite("connection closed\n", 1uLL, 0x12uLL, stderr);
LABEL_12:
v10 += 3;
}
while ( v10 != (int *)v11 );
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
const char *v4; // r12
__int16 v5; // ax
struct epoll_event *v6; // r12
int v7; // eax
int v8; // er13
int v9; // eax
int *v10; // rbx
__int64 v11; // rbp
int v12; // eax
int v13; // eax
__int64 v14; // rdx
int *v15; // r15
int v16; // eax
struct epoll_event event; // [rsp+4h] [rbp-74h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
__int16 v19[2]; // [rsp+20h] [rbp-58h] BYREF
int v20; // [rsp+24h] [rbp-54h]
socklen_t addr_len; // [rsp+34h] [rbp-44h] BYREF
int v22; // [rsp+38h] [rbp-40h] BYREF
int fd[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

c("in main", argv, envp);
c("running unit tests", argv, v3);
v4 = *argv;
initFt();
parse();
addr_len = 0;
if ( argc <= 1 )
{
fwrite("\nLil'Http: portno config", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !(unsigned int)createSocket(fd) )
{
fprintf(stderr, "%s ERROR, COULD NOT CREATE SERVER SOCKET\n", v4);
exit(1);
}
v19[0] = 2;
v5 = atoi(argv[1]);
v19[1] = func0(v5);
v20 = 0;
Bind(fd, v19);
listen(fd[0], 5);
v6 = (struct epoll_event *)calloc(0x80uLL, 0xCuLL);
makeSocketNB(fd);
event.events = -2147483647;
event.data.fd = fd[0];
v7 = createpoll();
v8 = v7;
if ( v7 < 0 )
{
fwrite("epoll create error\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
if ( epoll_ctl(v7, 1, fd[0], &event) == -1 )
{
fwrite("error with epoll_ctl on sockfd", 1uLL, 0x1EuLL, stderr);
exit(1);
}
while ( 1 )
{
do
v9 = epoll_wait(v8, v6, 128, -1);
while ( v9 <= 0 );
v10 = (int *)&v6->data;
v11 = (__int64)&v6[(unsigned int)(v9 - 1) + 1].data;
do
{
v12 = *(v10 - 1);
if ( (v12 & 0x18) != 0 || (v12 & 1) == 0 )
{
fwrite("epoll error\n", 1uLL, 0xCuLL, stderr);
close(*v10);
goto LABEL_12;
}
if ( *v10 == fd[0] )
{
while ( 1 )
{
v22 = accept(fd[0], &addr, &addr_len);
if ( v22 <= 0 )
{
v15 = _errno_location();
v16 = *v15;
if ( *v15 == 11 )
{
fwrite("we have accepted all the clients on this event\n", 1uLL, 0x2FuLL, stderr);
goto LABEL_12;
}
switch ( v16 )
{
case 'd':
c("ENETDOWN", &addr, v14);
break;
case 'G':
c("EPROTO", &addr, v14);
break;
case '\\':
c("ENOPROTOOPT", &addr, v14);
break;
case 'p':
c("EHOSTDOWN", &addr, v14);
break;
case '@':
c("ENONET", &addr, v14);
break;
case 'q':
c("EHOSTUNREACH", &addr, v14);
break;
case '_':
c("EOPNOTSUPP", &addr, v14);
break;
case 'e':
c("ENETUNREACH", &addr, v14);
break;
default:
c("what is going on here?", &addr, v14);
perror(sys_errlist[*v15]);
break;
}
for ( ; v22 < 0; v22 = accept(fd[0], &addr, &addr_len) )
;
}
else
{
makeSocketNB(&v22);
fprintf(stderr, "Accepted a new connection on fd %d, made nonblocking\n", (unsigned int)v22);
}
event.data.fd = v22;
event.events = -2147483647;
if ( epoll_ctl(v8, 1, v22, &event) < 0 )
{
fwrite("epoll_ctl error\n", 1uLL, 0x10uLL, stderr);
v13 = *_errno_location();
switch ( v13 )
{
case 17:
fwrite("fd already registered\n", 1uLL, 0x16uLL, stderr);
break;
case 9:
fprintf(stderr, "fd bad\n%d\n", (unsigned int)v22);
goto LABEL_12;
case 12:
fwrite("no memory\n", 1uLL, 0xAuLL, stderr);
break;
case 28:
fwrite("enospc\n", 1uLL, 7uLL, stderr);
break;
}
exit(1);
}
}
}
handleResponse(v10);
fprintf(stderr, "we are about to close file descriptor %d\n", (unsigned int)*v10);
close(*v10);
fwrite("connection closed\n", 1uLL, 0x12uLL, stderr);
LABEL_12:
v10 += 3;
}
while ( v10 != (int *)v11 );
}
}

original_code:
int main(int argc, char *argv[]) {
 c("in main");
 c("running unit tests");
 char *progname=argv[0];
 int sockfd, newsockfd, epollfd;
 socklen_t clilen;
 struct sockaddr_in serv_addr, cli_addr;
 initFt();
 parse();
 clilen = 0;
 if (argc < 2 ) {
  fprintf(stderr, "\nLil'Http: portno config");
  exit(1);
 } if(!createSocket(&sockfd)) {
  fprintf(stderr, "%s ERROR, COULD NOT CREATE SERVER SOCKET\n", progname);
  exit(1);
 } serv_addr.sin_family = 2;
 serv_addr.sin_port = htons(atoi(argv[1]));
 serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 Bind(&sockfd, &serv_addr);
 listen(sockfd, 5);
 struct epoll_event *events = calloc(128, sizeof(struct epoll_event));
 struct epoll_event event;
 makeSocketNB(&sockfd);
 event.events = EPOLLIN | EPOLLET;
 event.data.fd = sockfd;
 if ((epollfd = createpoll())<0) {
  fprintf(stderr, "epoll create error\n");
  exit(1);
 } if (epoll_ctl(epollfd, 1, sockfd, &event) == -1) {
  fprintf(stderr, "error with epoll_ctl on sockfd");
  exit(1);
 }while (1) {
  int n, e;
  e = epoll_wait(epollfd, events, 128, -1);
  for (n=0; n<e; n++) {
   if ((events[n].events & EPOLLERR) || (events[n].events & EPOLLHUP) || !(events[n].events & EPOLLIN)) {
    fprintf (stderr, "epoll error\n");
    close (events[n].data.fd);
    continue;
   } else if (events[n].data.fd == sockfd) {
    while (1) {
     newsockfd=accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
     if (newsockfd>0) {
      makeSocketNB(&newsockfd);
      fprintf(stderr, "Accepted a new connection on fd %d, made nonblocking\n", newsockfd);
     } else if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
      fprintf (stderr, "we have accepted all the clients on this event\n");
      break;
     } else {
      if ((*__errno_location ()) == 100)
       c("ENETDOWN");
      else if ((*__errno_location ()) == 71)
       c("EPROTO");
      else if ((*__errno_location ()) == 92)
       c("ENOPROTOOPT");
      else if ((*__errno_location ()) == 112)
       c("EHOSTDOWN");
      else if ((*__errno_location ()) == 64)
       c("ENONET");
      else if ((*__errno_location ()) == 113)
       c("EHOSTUNREACH");
      else if ((*__errno_location ()) == 95)
       c("EOPNOTSUPP");
      else if ((*__errno_location ()) == 101)
       c("ENETUNREACH");
      else {
       c("what is going on here?");
       perror(sys_errlist[(*__errno_location ())]);
      } while (newsockfd<0) {
       newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
      }
     } event.data.fd = newsockfd;
     event.events = EPOLLIN | EPOLLET;
     if (epoll_ctl(epollfd, 1, newsockfd, &event)<0) {
      fprintf(stderr, "epoll_ctl error\n");
      if ((*__errno_location ()) == 17)
       fprintf(stderr, "fd already registered\n");
      else if ((*__errno_location ()) == 9) {
       fprintf(stderr, "fd bad\n%d\n", newsockfd);
       break;
      }else if ((*__errno_location ()) == 12)
       fprintf(stderr, "no memory\n");
      else if ((*__errno_location ()) == 28)
       fprintf(stderr, "enospc\n");
      exit(1);
     }
     continue;
    }
   } else {
     handleResponse(&events[n].data.fd);
     fprintf(stderr, "we are about to close file descriptor %d\n", events[n].data.fd);
     close (events[n].data.fd);
     fprintf(stderr, "connection closed\n");
   }
  } continue;
 } exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
 c("in main");
 c("running unit tests");
 char *progname = argv[0];
 int sockfd; int newsockfd; int epollfd;
 unsigned int clilen;
 struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
 initFt();
 parse();
 clilen = 0;
 if (argc < 2 ) {
  fprintf(stderr, "\nLil'Http: portno config");
  exit(1);
 } if(!createSocket(&sockfd)) {
  fprintf(stderr, "%s ERROR, COULD NOT CREATE SERVER SOCKET\n", progname);
  exit(1);
 } serv_addr.sin_family = 2;
 serv_addr.sin_port = htons(atoi(argv[1]));
 serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 Bind(&sockfd, &serv_addr);
 listen(sockfd, 5);
 struct epoll_event *events = calloc(128, sizeof(struct epoll_event));
 struct epoll_event event;
 makeSocketNB(&sockfd);
 event.events = EPOLLIN | EPOLLET;
 event.data.fd = sockfd;
 if ((epollfd = createpoll())<0) {
  fprintf(stderr, "epoll create error\n");
  exit(1);
 } if (epoll_ctl(epollfd, 1, sockfd, &event) == -1) {
  fprintf(stderr, "error with epoll_ctl on sockfd");
  exit(1);
 }while (1) {
  int n; int e;
  e = epoll_wait(epollfd, events, 128, -1);
  for (n=0; n<e; n++) {
   if ((events[n].events & EPOLLERR) || (events[n].events & EPOLLHUP) || !(events[n].events & EPOLLIN)) {
    fprintf (stderr, "epoll error\n");
    close (events[n].data.fd);
    continue;
   } else if (events[n].data.fd == sockfd) {
    while (1) {
     newsockfd=accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
     if (newsockfd>0) {
      makeSocketNB(&newsockfd);
      fprintf(stderr, "Accepted a new connection on fd %d, made nonblocking\n", newsockfd);
     } else if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
      fprintf (stderr, "we have accepted all the clients on this event\n");
      break;
     } else {
      if ((*__errno_location ()) == 100)
       c("ENETDOWN");
      else if ((*__errno_location ()) == 71)
       c("EPROTO");
      else if ((*__errno_location ()) == 92)
       c("ENOPROTOOPT");
      else if ((*__errno_location ()) == 112)
       c("EHOSTDOWN");
      else if ((*__errno_location ()) == 64)
       c("ENONET");
      else if ((*__errno_location ()) == 113)
       c("EHOSTUNREACH");
      else if ((*__errno_location ()) == 95)
       c("EOPNOTSUPP");
      else if ((*__errno_location ()) == 101)
       c("ENETUNREACH");
      else {
       c("what is going on here?");
       perror(sys_errlist[(*__errno_location ())]);
      } while (newsockfd<0) {
       newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
      }
     } event.data.fd = newsockfd;
     event.events = EPOLLIN | EPOLLET;
     if (epoll_ctl(epollfd, 1, newsockfd, &event)<0) {
      fprintf(stderr, "epoll_ctl error\n");
      if ((*__errno_location ()) == 17)
       fprintf(stderr, "fd already registered\n");
      else if ((*__errno_location ()) == 9) {
       fprintf(stderr, "fd bad\n%d\n", newsockfd);
       break;
      }else if ((*__errno_location ()) == 12)
       fprintf(stderr, "no memory\n");
      else if ((*__errno_location ()) == 28)
       fprintf(stderr, "enospc\n");
      exit(1);
     }
     continue;
    }
   } else {
     handleResponse(&events[n].data.fd);
     fprintf(stderr, "we are about to close file descriptor %d\n", events[n].data.fd);
     close (events[n].data.fd);
     fprintf(stderr, "connection closed\n");
   }
  } continue;
 } exit(0);
}

variable_types:
progname
char *

variable_types: sockfd int

variable_types: newsockfd int

variable_types: epollfd int

variable_types:
clilen
unsigned int

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

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *

variable_types: n int

variable_types: e 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 epoll_event { unsigned int events; union epoll_data data; }

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


initFt

decompiled_code:
__int64 initFt()
{
_DWORD *v0; // rbx
_BYTE *v1; // rax

c("in initFt");
*((_DWORD *)&ft + 2) = 0;
v0 = malloc(0x10uLL);
ft = v0;
v1 = malloc(1uLL);
*(_QWORD *)v0 = v1;
*v1 = 103;
v0[2] = -1;
*((_DWORD *)&ft + 3) = 0;
return c("out of initFt");
}

canonical_decompiled_code:
__int64 func0()
{
_DWORD *v0; // rbx
_BYTE *v1; // rax

c("in initFt");
*((_DWORD *)&ft + 2) = 0;
v0 = malloc(0x10uLL);
ft = v0;
v1 = malloc(1uLL);
*(_QWORD *)v0 = v1;
*v1 = 103;
v0[2] = -1;
*((_DWORD *)&ft + 3) = 0;
return c("out of initFt");
}

original_code:
void initFt(void) {
 c("in initFt");
 ft.size = 0;
 ft.table = malloc(sizeof(struct table));
 ft.table[0].path = malloc(sizeof(char));
 *ft.table[0].path = 'g';
 ft.table[0].fd = -1;
 ft.flag = 0;
 c("out of initFt");
}

canonical_original_code:
void initFt() {
 c("in initFt");
 ft.size = 0;
 ft.table = malloc(sizeof(struct table));
 ft.table[0].path = malloc(sizeof(char));
 *ft.table[0].path = 'g';
 ft.table[0].fd = -1;
 ft.flag = 0;
 c("out of initFt");
}


inFt

decompiled_code:
__int64 __fastcall inFt(char *s2)
{
int v1; // er13
const char **v2; // r14
__int64 v3; // rbx
__int64 result; // rax

c("in inFT");
v1 = *((_DWORD *)&ft + 2);
if ( v1 < 0 )
{
LABEL_5:
c("out of inFt");
result = 0xFFFFFFFFLL;
}
else
{
v2 = (const char **)ft;
v3 = 0LL;
while ( strcmp(v2[2 * v3], s2) )
{
if ( v1 < (int)++v3 )
goto LABEL_5;
}
c("out of inFt");
result = *((unsigned int *)ft + 4 * v3 + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
int v1; // er13
const char **v2; // r14
__int64 v3; // rbx
__int64 result; // rax

c("in inFT");
v1 = *((_DWORD *)&ft + 2);
if ( v1 < 0 )
{
LABEL_5:
c("out of inFt");
result = 0xFFFFFFFFLL;
}
else
{
v2 = (const char **)ft;
v3 = 0LL;
while ( strcmp(v2[2 * v3], s2) )
{
if ( v1 < (int)++v3 )
goto LABEL_5;
}
c("out of inFt");
result = *((unsigned int *)ft + 4 * v3 + 2);
}
return result;
}

original_code:
int inFt(char *path) {
 c("in inFT");
 int i;
 for (i=0; i<=ft.size; i++) {
  if (strcmp(ft.table[i].path, path) == 0) {
   c("out of inFt");
   return ft.table[i].fd;
  }
 } c("out of inFt");
 return -1;
}

variable_types:
path
char *

variable_types: i int


addFt

decompiled_code:
__int64 __fastcall addFt(char *src, int a2)
{
size_t v3; // rax
void **v4; // r12
int v6; // esi
char *v7; // r12
size_t v8; // rax
void **v9; // r12

c("in addFT");
if ( *((_DWORD *)&ft + 3) )
{
v6 = *((_DWORD *)&ft + 2);
*((_DWORD *)&ft + 2) = v6 + 1;
v7 = (char *)realloc(ft, 16LL * (v6 + 2));
ft = v7;
v8 = strlen(src);
v9 = (void **)&v7[16 * *((int *)&ft + 2)];
*v9 = malloc(v8);
strcpy(*((char **)ft + 2 * *((int *)&ft + 2)), src);
*((_DWORD *)ft + 4 * *((int *)&ft + 2) + 2) = a2;
}
else
{
*((_DWORD *)&ft + 3) = 1;
free(*(void **)ft);
v3 = strlen(src);
v4 = (void **)ft;
*v4 = malloc(v3);
strcpy(*(char **)ft, src);
*((_DWORD *)ft + 2) = a2;
}
c("out of addFt");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int a2)
{
size_t v3; // rax
void **v4; // r12
int v6; // esi
char *v7; // r12
size_t v8; // rax
void **v9; // r12

c("in addFT");
if ( *((_DWORD *)&ft + 3) )
{
v6 = *((_DWORD *)&ft + 2);
*((_DWORD *)&ft + 2) = v6 + 1;
v7 = (char *)realloc(ft, 16LL * (v6 + 2));
ft = v7;
v8 = strlen(src);
v9 = (void **)&v7[16 * *((int *)&ft + 2)];
*v9 = malloc(v8);
strcpy(*((char **)ft + 2 * *((int *)&ft + 2)), src);
*((_DWORD *)ft + 4 * *((int *)&ft + 2) + 2) = a2;
}
else
{
*((_DWORD *)&ft + 3) = 1;
free(*(void **)ft);
v3 = strlen(src);
v4 = (void **)ft;
*v4 = malloc(v3);
strcpy(*(char **)ft, src);
*((_DWORD *)ft + 2) = a2;
}
c("out of addFt");
return 1LL;
}

original_code:
int addFt(char *path, int fd) {
 c("in addFT");
 if (ft.flag == 0) {
  ft.flag = 1;
  free(ft.table[0].path);
  ft.table[0].path = malloc(sizeof(char) * strlen(path));
  strcpy(ft.table[0].path, path);
  ft.table[0].fd = fd;
 } else {
  ft.size++;
  ft.table = realloc(ft.table, sizeof(struct table) * (ft.size + 1));
  ft.table[ft.size].path = malloc(sizeof(char) * strlen(path));
  strcpy(ft.table[ft.size].path, path);
  ft.table[ft.size].fd = fd;
 } c("out of addFt");
 return 1;
}

variable_types: fd int


Read

decompiled_code:
__int64 __fastcall Read(int *a1, void *a2, int a3)
{
c("in Read");
if ( read(*a1, a2, a3) < 0 )
fwrite("Read Error\n", 1uLL, 0xBuLL, stderr);
c("out of Read");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, void *a2, int a3)
{
c("in Read");
if ( read(*a1, a2, a3) < 0 )
fwrite("Read Error\n", 1uLL, 0xBuLL, stderr);
c("out of Read");
return 1LL;
}

original_code:
int Read(int *fd, char *buf, int buf_siz) {
 c("in Read");
 if (read(*fd, buf, buf_siz)<0) {
  fprintf(stderr, "Read Error\n");
  c("out of Read");
  return 1;
 }else {
  c("out of Read");
  return 1;
 }
}

variable_types:
fd
int *

variable_types:
buf
char *


Write

decompiled_code:
__int64 __fastcall Write(int *a1, const char *a2, int a3)
{
c("in Write");
fprintf(stderr, "%s\n", a2);
if ( write(*a1, a2, a3) < 0 )
{
fwrite("Write Error\n", 1uLL, 0xCuLL, stderr);
c("out of Write");
exit(1);
}
c("out of Write");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, const char *a2, int a3)
{
c("in Write");
fprintf(stderr, "%s\n", a2);
if ( write(*a1, a2, a3) < 0 )
{
fwrite("Write Error\n", 1uLL, 0xCuLL, stderr);
c("out of Write");
exit(1);
}
c("out of Write");
return 1LL;
}

original_code:
int Write(int *fd, char *msg, int len) {
 c("in Write");
 fprintf(stderr, "%s\n", msg);
 if (write(*fd, msg, len)<0) {
  fprintf(stderr, "Write Error\n");
  c("out of Write");
  exit(1);
 } else {
  c("out of Write");
  return 1;
 }
}

variable_types:
msg
char *

variable_types: len int


handleFileError

decompiled_code:
__int64 __fastcall handleFileError(__int64 a1, __int64 a2)
{
c("in handleFileError");
addResponse("HTTP/1.0 404 Not Found\n\n", a1, a2);
addResponse(
"<!DOCTYPE HTML><title>404 Not Found</title>
404 Not Found
",
a1,
a2);
c("out of handleFileError");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
c("in handleFileError");
addResponse("HTTP/1.0 404 Not Found\n\n", a1, a2);
addResponse(
"<!DOCTYPE HTML><title>404 Not Found</title>
404 Not Found
",
a1,
a2);
c("out of handleFileError");
return 1LL;
}

original_code:
int handleFileError(char *response, int *i) {
 c("in handleFileError");
 addResponse("HTTP/1.0 404 Not Found\n\n", response, i);
 addResponse("<!DOCTYPE HTML><title>404 Not Found</title>
404 Not Found
", response, i);
 c("out of handleFileError");
 return 1;
}

variable_types:
response
char *

variable_types:
i
int *


getDiff

decompiled_code:
__int64 __fastcall getDiff(_QWORD *a1)
{
unsigned __int8 *v1; // rax
unsigned __int64 v2; // rax
unsigned int v3; // ebx
__int64 v4; // rdx
__int64 v5; // r12
_BYTE *v6; // rdx

c("in getDiff");
v1 = (unsigned __int8 *)a1[1];
*a1 = v1;
v2 = (unsigned int)*v1 + 1;
if ( (unsigned __int8)v2 <= 1u )
{
fwrite("LEX ERROR, LEXER.END IS ON EOF OR 0\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
if ( (unsigned __int8)v2 > 0x21u )
{
v3 = 0;
}
else
{
v3 = 0;
v4 = 0x200000803LL;
if ( _bittest64(&v4, v2) )
goto LABEL_10;
}
v5 = 0x200000803LL;
do
{
do
{
fprintf(stderr, "%d\n", v3++);
v6 = (_BYTE *)(a1[1] + 1LL);
a1[1] = v6;
}
while ( (unsigned __int8)(*v6 + 1) > 0x21u );
}
while ( !_bittest64(&v5, (unsigned int)(unsigned __int8)*v6 + 1) );
LABEL_10:
c("out of getDiff");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
unsigned __int8 *v1; // rax
unsigned __int64 v2; // rax
unsigned int v3; // ebx
__int64 v4; // rdx
__int64 v5; // r12
_BYTE *v6; // rdx

c("in getDiff");
v1 = (unsigned __int8 *)a1[1];
*a1 = v1;
v2 = (unsigned int)*v1 + 1;
if ( (unsigned __int8)v2 <= 1u )
{
fwrite("LEX ERROR, LEXER.END IS ON EOF OR 0\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
if ( (unsigned __int8)v2 > 0x21u )
{
v3 = 0;
}
else
{
v3 = 0;
v4 = 0x200000803LL;
if ( _bittest64(&v4, v2) )
goto LABEL_10;
}
v5 = 0x200000803LL;
do
{
do
{
fprintf(stderr, "%d\n", v3++);
v6 = (_BYTE *)(a1[1] + 1LL);
a1[1] = v6;
}
while ( (unsigned __int8)(*v6 + 1) > 0x21u );
}
while ( !_bittest64(&v5, (unsigned int)(unsigned __int8)*v6 + 1) );
LABEL_10:
c("out of getDiff");
return 1LL;
}

original_code:
int getDiff(struct lexer *lex) {
 c("in getDiff");
 lex->start = lex->end;
 int i=0;
 if (*lex->end==(-1) || *lex->end=='\0') {
  fprintf(stderr, "LEX ERROR, LEXER.END IS ON EOF OR 0\n");
  exit(1);
 } else {
  for (; *lex->end!=' ' && *lex->end!='\n' && *lex->end!=(-1) && *lex->end!='\0'; ++lex->end) {
   fprintf(stderr, "%d\n", i);
   i++;
 }
 } c("out of getDiff");
 return 1;
}

canonical_original_code:
int getDiff(struct lexer *lex) {
 c("in getDiff");
 lex->start = lex->end;
 int i = 0;
 if (*lex->end==(-1) || *lex->end=='\0') {
  fprintf(stderr, "LEX ERROR, LEXER.END IS ON EOF OR 0\n");
  exit(1);
 } else {
  for (; *lex->end!=' ' && *lex->end!='\n' && *lex->end!=(-1) && *lex->end!='\0'; ++lex->end) {
   fprintf(stderr, "%d\n", i);
   i++;
 }
 } c("out of getDiff");
 return 1;
}

variable_types: struct lexer { char *start; char *end; int flag; } *


initLex

decompiled_code:
__int64 __fastcall initLex(__int64 a1, __int64 a2)
{
c("in initLex");
*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 16) = 0;
return c("out of initLex");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
c("in initLex");
*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 16) = 0;
return c("out of initLex");
}

original_code:
void initLex(struct lexer *lex, char *buf) {
 c("in initLex");
 lex->start = buf;
 lex->end = buf;
 lex->flag=0;
 c("out of initLex");
}

user_defined_types: struct lexer { char *start; char *end; int flag; }


restartLex

decompiled_code:
__int64 __fastcall restartLex(__int64 a1)
{
_BYTE *v1; // rax

c("in restartLex");
do
{
v1 = *(_BYTE **)(a1 + 8);
if ( *v1 != 32 && *v1 != 10 )
break;
*(_QWORD *)(a1 + 8) = v1 + 1;
}
while ( (unsigned __int8)(v1[1] + 1) > 1u );
c("out of restartLex");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_BYTE *v1; // rax

c("in restartLex");
do
{
v1 = *(_BYTE **)(a1 + 8);
if ( *v1 != 32 && *v1 != 10 )
break;
*(_QWORD *)(a1 + 8) = v1 + 1;
}
while ( (unsigned __int8)(v1[1] + 1) > 1u );
c("out of restartLex");
return 1LL;
}

original_code:
int restartLex(struct lexer *lex) {
 c("in restartLex");
 while (*lex->end==' ' || *lex->end=='\n') {
  ++lex->end;
  if (*lex->end=='\0' || *lex->end==(-1)) {
   c("out of restartLex");
   return 1;
  }
 } c("out of restartLex");
 return 1;
}


checkSym

decompiled_code:
__int64 __fastcall checkSym(const char *a1)
{
bool v1; // zf
int v2; // ebx

c("in checksym");
v1 = strcmp("GET", a1) == 0;
v2 = !v1;
if ( !v1 )
{
if ( !strcmp(".html", a1) )
{
v2 = 1;
}
else
{
v2 = 2;
if ( strcmp(".js", a1) )
{
c("out of checkSym");
return 0xFFFFFFFFLL;
}
}
}
c("out of checkSym");
return (unsigned int)dword_468[4 * v2];
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
bool v1; // zf
int v2; // ebx

c("in checksym");
v1 = strcmp("GET", a1) == 0;
v2 = !v1;
if ( !v1 )
{
if ( !strcmp(".html", a1) )
{
v2 = 1;
}
else
{
v2 = 2;
if ( strcmp(".js", a1) )
{
c("out of checkSym");
return 0xFFFFFFFFLL;
}
}
}
c("out of checkSym");
return (unsigned int)dword_468[4 * v2];
}

original_code:
int checkSym(char *string) {
 c("in checksym");
 static struct pair {
  char *key;
  int value;
 } table[] = {
  "GET", 129,
  ".html", 131,
  ".js", 132
 };
 int i=0, tablelen=2;
 while(i<=tablelen) {
  if (strcmp(table[i].key, string)==0)
        {
   c("out of checkSym");
            return table[i].value;
        }
  ++i;
 } if (i>tablelen) {
  c("out of checkSym");
  return -1;
 } else {
  fprintf(stderr, "ERROR IN CHECKSYM\n");
  exit(1);
 }
}

canonical_original_code:
int checkSym(char *string) {
 c("in checksym");
 static struct pair table[] = {
  "GET", 129,
  ".html", 131,
  ".js", 132
 };
 int i = 0; int tablelen = 2;
 while(i<=tablelen) {
  if (strcmp(table[i].key, string)==0)
        {
   c("out of checkSym");
            return table[i].value;
        }
  ++i;
 } if (i>tablelen) {
  c("out of checkSym");
  return -1;
 } else {
  fprintf(stderr, "ERROR IN CHECKSYM\n");
  exit(1);
 }
}

variable_types:
string
char *

variable_types: struct pair { char *key; int value; } []

variable_types: tablelen int


createSocket

decompiled_code:
__int64 __fastcall createSocket(int *a1)
{
int v1; // eax

c("in createSocket");
v1 = socket(2, 1, 0);
*a1 = v1;
if ( v1 < 0 )
{
c("out of createSocket");
exit(1);
}
c("out of createSocket");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v1; // eax

c("in createSocket");
v1 = socket(2, 1, 0);
*a1 = v1;
if ( v1 < 0 )
{
c("out of createSocket");
exit(1);
}
c("out of createSocket");
return 1LL;
}

original_code:
int createSocket(int *fd) {
 c("in createSocket");
 if ((*fd = socket(2, SOCK_STREAM, 0))>=0) {
  c("out of createSocket");
  return 1;
 } else {
  c("out of createSocket");
  exit(1);
 }
}


Bind

decompiled_code:
__int64 __fastcall Bind(int *a1, const struct sockaddr *a2)
{
c("in Bind");
if ( bind(*a1, a2, 0x10u) < 0 )
{
fwrite("BIND ERROR\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
c("out of bind");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, const struct sockaddr *a2)
{
c("in Bind");
if ( bind(*a1, a2, 0x10u) < 0 )
{
fwrite("BIND ERROR\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
c("out of bind");
return 1LL;
}

original_code:
int Bind(int *fd, struct sockaddr_in *skaddr) {
 c("in Bind");
 if (bind(*fd, (struct sockaddr *) skaddr, sizeof(*skaddr))<0) {
  fprintf(stderr, "BIND ERROR\n");
  exit(1);
 } else {
  c("out of bind");
  return 1;
 }
}

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


Accept

decompiled_code:
__int64 __fastcall Accept(int *a1, int *a2, struct sockaddr *a3, socklen_t *a4)
{
int v6; // eax

c("in Accept");
v6 = accept(*a2, a3, a4);
*a1 = v6;
if ( v6 < 0 )
{
fwrite("ACCEPT ERROR\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
c("out of accept");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, int *a2, struct sockaddr *a3, socklen_t *a4)
{
int v6; // eax

c("in Accept");
v6 = accept(*a2, a3, a4);
*a1 = v6;
if ( v6 < 0 )
{
fwrite("ACCEPT ERROR\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
c("out of accept");
return 1LL;
}

original_code:
int Accept(int *nsfd, int *sfd, struct sockaddr_in *cli_addr, socklen_t *clilen) {
 c("in Accept");
 if ((*nsfd = accept(*sfd, (struct sockaddr *) cli_addr, clilen))<0) {
  fprintf(stderr, "ACCEPT ERROR\n");
  exit(1);
 } else {
  c("out of accept");
  return 1;
 }
}

canonical_original_code:
int Accept(int *nsfd, int *sfd, struct sockaddr_in *cli_addr, unsigned int *clilen) {
 c("in Accept");
 if ((*nsfd = accept(*sfd, (struct sockaddr *) cli_addr, clilen))<0) {
  fprintf(stderr, "ACCEPT ERROR\n");
  exit(1);
 } else {
  c("out of accept");
  return 1;
 }
}

variable_types:
nsfd
int *

variable_types:
sfd
int *

variable_types:
clilen
unsigned int *


makeSocketNB

decompiled_code:
__int64 __fastcall makeSocketNB(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 v3; // rdx

c("in makeSocketNB");
v1 = fcntl(*a1, 3, 0LL);
v2 = v1;
if ( v1 == -1 )
{
perror("fcntl");
}
else
{
v3 = v1;
BYTE1(v3) = BYTE1(v1) | 8;
v2 = fcntl(*a1, 4, v3);
if ( v2 == -1 )
{
perror("fcntl2");
c("out of makeSocketNB");
}
else
{
c("out of makeSocketNB");
v2 = 0;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 v3; // rdx

c("in makeSocketNB");
v1 = fcntl(*a1, 3, 0LL);
v2 = v1;
if ( v1 == -1 )
{
perror("fcntl");
}
else
{
v3 = v1;
BYTE1(v3) = BYTE1(v1) | 8;
v2 = fcntl(*a1, 4, v3);
if ( v2 == -1 )
{
perror("fcntl2");
c("out of makeSocketNB");
}
else
{
c("out of makeSocketNB");
v2 = 0;
}
}
return v2;
}

original_code:
int makeSocketNB (int *sfd) {
 c("in makeSocketNB");
 int flags, s;
 flags = fcntl (*sfd, 3, 0);
 if (flags == -1) {
  perror ("fcntl");
  return -1;
 } flags |= 04000;
 s = fcntl(*sfd, 4, flags);
 if (s == -1) {
  perror ("fcntl2");
  c("out of makeSocketNB");
  return -1;
 }
 c("out of makeSocketNB");
 return 0;
}

canonical_original_code:
int makeSocketNB(int *sfd) {
 c("in makeSocketNB");
 int flags; int s;
 flags = fcntl (*sfd, 3, 0);
 if (flags == -1) {
  perror ("fcntl");
  return -1;
 } flags |= 04000;
 s = fcntl(*sfd, 4, flags);
 if (s == -1) {
  perror ("fcntl2");
  c("out of makeSocketNB");
  return -1;
 }
 c("out of makeSocketNB");
 return 0;
}

variable_types: flags int

variable_types: s int


createpoll

decompiled_code:
__int64 createpoll()
{
int v0; // eax
unsigned int v1; // ebx

c("in createpoll");
v0 = epoll_create(128);
if ( v0 < 0 )
{
c("out of createpoll");
v1 = -1;
}
else
{
v1 = v0;
c("out of createpoll");
}
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
unsigned int v1; // ebx

c("in createpoll");
v0 = epoll_create(128);
if ( v0 < 0 )
{
c("out of createpoll");
v1 = -1;
}
else
{
v1 = v0;
c("out of createpoll");
}
return v1;
}

original_code:
int createpoll(void) {
 c("in createpoll");
 int fd;
 if ((fd=epoll_create(128))<0) {
  c("out of createpoll");
  return -1;
 } else {
  c("out of createpoll");
  return fd;
 }
}

canonical_original_code:
int createpoll() {
 c("in createpoll");
 int fd;
 if ((fd=epoll_create(128))<0) {
  c("out of createpoll");
  return -1;
 } else {
  c("out of createpoll");
  return fd;
 }
}

variable_types: fd int


parseRequest

decompiled_code:
__int64 __fastcall parseRequest(__int64 a1)
{
__int64 v1; // rbx
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

c("in parseRequest");
initLex(v3, a1);
v1 = getToken(a1, v3);
c("out of parseRequest");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

c("in parseRequest");
initLex(v3, a1);
v1 = getToken(a1, v3);
c("out of parseRequest");
return v1;
}

original_code:
Token *parseRequest(char *request) {
 c("in parseRequest");
 Token *tok;
 struct lexer lex;
 initLex(&lex, request);
 tok = getToken(request, &lex);
 c("out of parseRequest");
 return tok;
}

canonical_original_code:
struct token *parseRequest(char *request) {
 c("in parseRequest");
 struct token *tok;
 struct lexer lex;
 initLex(&lex, request);
 tok = getToken(request, &lex);
 c("out of parseRequest");
 return tok;
}

variable_types:
request
char *

variable_types: struct token { int type; char *value; } *

variable_types: struct lexer { char *start; char *end; int flag; }


countChar

decompiled_code:
__int64 __fastcall countChar(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // ebp

c("in countChar");
if ( *a1 )
{
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
}
else
{
v2 = 0;
}
c("out of countChar");
fprintf(stderr, "%d\n", v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // ebp

c("in countChar");
if ( *a1 )
{
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
}
else
{
v2 = 0;
}
c("out of countChar");
fprintf(stderr, "%d\n", v2);
return v2;
}

original_code:
int countChar(char *buf){
 c("in countChar");
 int nc=0;
 while(buf[nc]!='\0') {
  nc++;
 } c("out of countChar");
 fprintf(stderr, "%d\n", nc);
 return nc;
}

canonical_original_code:
int countChar(char *buf){
 c("in countChar");
 int nc = 0;
 while(buf[nc]!='\0') {
  nc++;
 } c("out of countChar");
 fprintf(stderr, "%d\n", nc);
 return nc;
}

variable_types:
buf
char *

variable_types: nc int


addResponse

decompiled_code:
__int64 __fastcall addResponse(char *src, _BYTE *a2, unsigned int *a3)
{
c("in addResponse");
fprintf(stderr, "i is: %d\n", *a3);
strcpy(&a2[*a3], src);
*a3 = countChar(a2);
c("out of addResponse");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, _BYTE *a2, unsigned int *a3)
{
c("in addResponse");
fprintf(stderr, "i is: %d\n", *a3);
strcpy(&a2[*a3], src);
*a3 = func1(a2);
c("out of addResponse");
return 1LL;
}

original_code:
int addResponse(char *response, char *resbuf, int *i) {
 c("in addResponse");
 fprintf(stderr, "i is: %d\n", *i);
 strcpy(&resbuf[*i], response);
 *i = countChar(resbuf);
 c("out of addResponse");
 return 1;
}

variable_types:
response
char *

variable_types:
resbuf
char *

variable_types:
i
int *


determineDocType

decompiled_code:
__int64 __fastcall determineDocType(char *s, _BYTE *a2, unsigned int *a3)
{
size_t v5; // rax
size_t v6; // rdi
__int64 v7; // rax
const char *v8; // rbp
__int64 v9; // rdx
char *v10; // rbx
int v11; // eax

c("in determineDocType");
v5 = strlen(s);
if ( v5 <= 2 )
{
addResponse("Content-Type: text; charset=utf-8\n\n", a2, a3);
c("out of determineDocType");
}
else
{
v6 = v5;
v7 = 2LL;
if ( s[1] == 46 )
{
v8 = s + 1;
v9 = 1LL;
}
else
{
do
{
v8 = &s[v7];
v9 = v7++;
}
while ( s[v7 - 1] != 46 );
}
v10 = (char *)malloc(v6 - v9);
strcpy(v10, v8);
v11 = checkSym(v10);
if ( v11 < 0 )
{
fwrite("FILE TYPE NOT SUPPORTED\n", 1uLL, 0x18uLL, stderr);
addResponse("Content-Type: text; charset=utf-8\n\n", a2, a3);
}
else if ( v11 == 131 )
{
addResponse("Content-Type: text/html; charset=utf-8\n\n", a2, a3);
}
else if ( v11 == 132 )
{
addResponse("Content-Type: text/javascript; charset=utf-8\n\n", a2, a3);
}
c("out of determineDocType");
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, _BYTE *a2, unsigned int *a3)
{
size_t v5; // rax
size_t v6; // rdi
__int64 v7; // rax
const char *v8; // rbp
__int64 v9; // rdx
char *v10; // rbx
int v11; // eax

c("in determineDocType");
v5 = strlen(s);
if ( v5 <= 2 )
{
func2("Content-Type: text; charset=utf-8\n\n", a2, a3);
c("out of determineDocType");
}
else
{
v6 = v5;
v7 = 2LL;
if ( s[1] == 46 )
{
v8 = s + 1;
v9 = 1LL;
}
else
{
do
{
v8 = &s[v7];
v9 = v7++;
}
while ( s[v7 - 1] != 46 );
}
v10 = (char *)malloc(v6 - v9);
strcpy(v10, v8);
v11 = checkSym(v10);
if ( v11 < 0 )
{
fwrite("FILE TYPE NOT SUPPORTED\n", 1uLL, 0x18uLL, stderr);
func2("Content-Type: text; charset=utf-8\n\n", a2, a3);
}
else if ( v11 == 131 )
{
func2("Content-Type: text/html; charset=utf-8\n\n", a2, a3);
}
else if ( v11 == 132 )
{
func2("Content-Type: text/javascript; charset=utf-8\n\n", a2, a3);
}
c("out of determineDocType");
}
return 1LL;
}

original_code:
int determineDocType(char *path, char *response, int *i) {
 c("in determineDocType");
 int n=1;
 char *tmp;
 if (strlen(path)<=2) {
  addResponse("Content-Type: text; charset=utf-8\n\n", response, i);
  c("out of determineDocType");
  return 1;
 }while (path[n]!='.') {
  n++;
 }
 tmp = malloc((strlen(path)-n) * sizeof(char));
 strcpy(tmp, &path[n]);
 if((n=checkSym(tmp))<0) {
  fprintf(stderr, "FILE TYPE NOT SUPPORTED\n");
  addResponse("Content-Type: text; charset=utf-8\n\n", response, i);
 }else if (n==131) {
  addResponse("Content-Type: text/html; charset=utf-8\n\n", response, i);
 }else if (n==132) {
  addResponse("Content-Type: text/javascript; charset=utf-8\n\n", response, i);
 } c("out of determineDocType");
 return 1;
}

canonical_original_code:
int determineDocType(char *path, char *response, int *i) {
 c("in determineDocType");
 int n = 1;
 char *tmp;
 if (strlen(path)<=2) {
  addResponse("Content-Type: text; charset=utf-8\n\n", response, i);
  c("out of determineDocType");
  return 1;
 }while (path[n]!='.') {
  n++;
 }
 tmp = malloc((strlen(path)-n) * sizeof(char));
 strcpy(tmp, &path[n]);
 if((n=checkSym(tmp))<0) {
  fprintf(stderr, "FILE TYPE NOT SUPPORTED\n");
  addResponse("Content-Type: text; charset=utf-8\n\n", response, i);
 }else if (n==131) {
  addResponse("Content-Type: text/html; charset=utf-8\n\n", response, i);
 }else if (n==132) {
  addResponse("Content-Type: text/javascript; charset=utf-8\n\n", response, i);
 } c("out of determineDocType");
 return 1;
}

variable_types:
path
char *

variable_types: n int

variable_types:
tmp
char *


parseGet

decompiled_code:
__int64 __fastcall parseGet(__int64 a1, _BYTE *a2, unsigned int *a3)
{
_QWORD *v4; // rbx
const char *v5; // r14
size_t v6; // rax
char *v7; // r13
int v8; // eax
char v10[16384]; // [rsp+0h] [rbp-4048h] BYREF
char v11[72]; // [rsp+4000h] [rbp-48h] BYREF

c("in parseGet");
initLex(v11, a1);
v4 = (_QWORD *)getToken(a1, v11);
memset(v10, 0, sizeof(v10));
if ( *(_DWORD *)v4 == 129 )
{
v5 = (const char *)v4[1];
v6 = strlen(v5);
v7 = (char *)malloc(v6);
strcpy(v7, v5);
v8 = inFt(v7);
if ( v8 < 0 )
{
handleFileError(a2, a3);
free(v7);
free(v4);
}
else
{
pread(v8, v10, 0x4000uLL, 0LL);
free(v4);
addResponse("HTTP/1.0 200 OK\n", a2, a3);
addResponse("Server: KevServer/0.3\n", a2, a3);
determineDocType(v7, a2, a3);
free(v7);
addResponse(v10, a2, a3);
}
c("out of parseGet");
}
else
{
addResponse("ERROR!\n", a2, a3);
free(0LL);
free(v4);
c("out of parseGet");
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2, unsigned int *a3)
{
_QWORD *v4; // rbx
const char *v5; // r14
size_t v6; // rax
char *v7; // r13
int v8; // eax
char v10[16384]; // [rsp+0h] [rbp-4048h] BYREF
char v11[72]; // [rsp+4000h] [rbp-48h] BYREF

c("in parseGet");
initLex(v11, a1);
v4 = (_QWORD *)getToken(a1, v11);
memset(v10, 0, sizeof(v10));
if ( *(_DWORD *)v4 == 129 )
{
v5 = (const char *)v4[1];
v6 = strlen(v5);
v7 = (char *)malloc(v6);
strcpy(v7, v5);
v8 = inFt(v7);
if ( v8 < 0 )
{
handleFileError(a2, a3);
free(v7);
free(v4);
}
else
{
pread(v8, v10, 0x4000uLL, 0LL);
free(v4);
func2("HTTP/1.0 200 OK\n", a2, a3);
func2("Server: KevServer/0.3\n", a2, a3);
func3(v7, a2, a3);
free(v7);
func2(v10, a2, a3);
}
c("out of parseGet");
}
else
{
func2("ERROR!\n", a2, a3);
free(0LL);
free(v4);
c("out of parseGet");
}
return 1LL;
}

original_code:
int parseGet(char *request, char *response, int *i) {
 c("in parseGet");
 Token *tok;
 struct lexer lex;
 int rfd;
 char *path;
 char tmp[2*8192];
 initLex(&lex, request);
 tok = getToken(request, &lex);
 memset(tmp, '\0', 2*8192);
 if (tok->type == 129) {
  path = malloc(sizeof(char) * strlen(tok->value));
  strcpy(path, tok->value);
  if((rfd=inFt(path))<0) {
   handleFileError(response, i);
   free(path);
   free(tok);
   c("out of parseGet");
   return 1;
  } else {
   pread(rfd, tmp, 2*8192, 0);
  }
  free(tok);
  addResponse("HTTP/1.0 200 OK\n", response, i);
  addResponse("Server: KevServer/0.3\n", response, i);
  determineDocType(path, response, i);
  free(path);
  addResponse(tmp, response, i);
  c("out of parseGet");
  return 1;
 } else {
  addResponse("ERROR!\n", response, i);
  free(path);
  free(tok);
  c("out of parseGet");
  return 1;
 }
}

canonical_original_code:
int parseGet(char *request, char *response, int *i) {
 c("in parseGet");
 struct token *tok;
 struct lexer lex;
 int rfd;
 char *path;
 char tmp[-1];
 initLex(&lex, request);
 tok = getToken(request, &lex);
 memset(tmp, '\0', 2*8192);
 if (tok->type == 129) {
  path = malloc(sizeof(char) * strlen(tok->value));
  strcpy(path, tok->value);
  if((rfd=inFt(path))<0) {
   handleFileError(response, i);
   free(path);
   free(tok);
   c("out of parseGet");
   return 1;
  } else {
   pread(rfd, tmp, 2*8192, 0);
  }
  free(tok);
  addResponse("HTTP/1.0 200 OK\n", response, i);
  addResponse("Server: KevServer/0.3\n", response, i);
  determineDocType(path, response, i);
  free(path);
  addResponse(tmp, response, i);
  c("out of parseGet");
  return 1;
 } else {
  addResponse("ERROR!\n", response, i);
  free(path);
  free(tok);
  c("out of parseGet");
  return 1;
 }
}

variable_types: rfd int

variable_types:
tmp
char [-1]


handleResponse

decompiled_code:
__int64 __fastcall handleResponse(__int64 a1)
{
_DWORD *v1; // rax
size_t v2; // rax
unsigned int v4; // [rsp+Ch] [rbp-601Ch] BYREF
char s[16384]; // [rsp+10h] [rbp-6018h] BYREF
char v6[8184]; // [rsp+4010h] [rbp-2018h] BYREF
int v7; // [rsp+6008h] [rbp-20h]
__int16 v8; // [rsp+600Ch] [rbp-1Ch]
char v9; // [rsp+600Eh] [rbp-1Ah]

c("in handleResponse");
v4 = 0;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
v9 = 0;
memset(s, 0, 0x3FFFuLL);
Read(a1, v6, 0x2000LL);
fprintf(stderr, "The Request is:\n%s\n", v6);
v1 = (_DWORD *)parseRequest((__int64)v6);
if ( *v1 == 129 )
{
free(v1);
parseGet((__int64)v6, s, &v4);
}
else
{
addResponse("Unknown Request Type\n", s, &v4);
}
v2 = strlen(s);
Write(a1, s, v2);
c("out of handleResponse");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_DWORD *v1; // rax
size_t v2; // rax
unsigned int v4; // [rsp+Ch] [rbp-601Ch] BYREF
char s[16384]; // [rsp+10h] [rbp-6018h] BYREF
char v6[8184]; // [rsp+4010h] [rbp-2018h] BYREF
int v7; // [rsp+6008h] [rbp-20h]
__int16 v8; // [rsp+600Ch] [rbp-1Ch]
char v9; // [rsp+600Eh] [rbp-1Ah]

c("in handleResponse");
v4 = 0;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
v9 = 0;
memset(s, 0, 0x3FFFuLL);
Read(a1, v6, 0x2000LL);
fprintf(stderr, "The Request is:\n%s\n", v6);
v1 = (_DWORD *)func0((__int64)v6);
if ( *v1 == 129 )
{
free(v1);
func4((__int64)v6, s, &v4);
}
else
{
func2("Unknown Request Type\n", s, &v4);
}
v2 = strlen(s);
Write(a1, s, v2);
c("out of handleResponse");
return 1LL;
}

original_code:
int handleResponse(int *fd) {
 c("in handleResponse");
 char buf[8192], retbuf[2*8192];
 int i = 0;
 memset(buf, '\0', 8192 -1);
 memset(retbuf, '\0', (2*8192)-1);
 Token *tok;
 Read(fd, buf, 8192);
 fprintf(stderr, "The Request is:\n%s\n", buf);
 tok = parseRequest(buf);
 if (tok->type == 129) {
  free(tok);
  parseGet(buf, retbuf, &i);
  Write(fd, retbuf, strlen(retbuf));
  c("out of handleResponse");
  return 1;
 } else {
  addResponse("Unknown Request Type\n", retbuf, &i);
  Write(fd, retbuf, strlen(retbuf));
  c("out of handleResponse");
  return 1;
 }
}

canonical_original_code:
int handleResponse(int *fd) {
 c("in handleResponse");
 char buf[8192]; char retbuf[-1];
 int i = 0;
 memset(buf, '\0', 8192 -1);
 memset(retbuf, '\0', (2*8192)-1);
 struct token *tok;
 Read(fd, buf, 8192);
 fprintf(stderr, "The Request is:\n%s\n", buf);
 tok = parseRequest(buf);
 if (tok->type == 129) {
  free(tok);
  parseGet(buf, retbuf, &i);
  Write(fd, retbuf, strlen(retbuf));
  c("out of handleResponse");
  return 1;
 } else {
  addResponse("Unknown Request Type\n", retbuf, &i);
  Write(fd, retbuf, strlen(retbuf));
  c("out of handleResponse");
  return 1;
 }
}

variable_types:
fd
int *

variable_types:
buf
char [8192]

variable_types:
retbuf
char [-1]

variable_types: i int


scan

original_code:
int scan(struct rToken *tok, struct lexer *lex, char *config) {
 int i;
 if (*lex->start == '\0')
  return 0;
 if (*lex->end == '\n') {
  ++lex->end;
  lex->start = lex->end;
 } while (*lex->end != ' ') {
  ++lex->end;
 } int d = (lex->end - lex->start);
 char *tmp = malloc(sizeof(char) * (d+1));
 for (i = 0; i < d; i++) {
  tmp[i] = lex->start[i];
 } tmp[i] = '\0';
 tok->request = malloc(sizeof(char) * (d+1));
 strcpy(tok->request, tmp);
 free(tmp);
 lex->start = (++lex->end);
 while (*lex->end != '\n' && *lex->end != '\0') {
  ++lex->end;
 } d = (lex->end - lex->start);
 tmp = malloc(sizeof(char) * (d+1));
 for (i=0; i < d; i++) {
  tmp[i] = lex->start[i];
 } tmp[i] = '\0';
 tok->path = malloc(sizeof(char) * (d+1));
 strcpy(tok->path, tmp);
 free(tmp);
 lex->start = lex->end;
 return 1;
}

variable_types: struct rToken { char *request; char *path; } *

variable_types: struct lexer { char *start; char *end; int flag; } *

variable_types:
config
char *

variable_types: d int


parse

decompiled_code:
__int64 parse()
{
int v0; // ebx
__int64 v2[4]; // [rsp+0h] [rbp-48h] BYREF
void *ptr; // [rsp+20h] [rbp-28h] BYREF
char *file; // [rsp+28h] [rbp-20h]

v2[0] = (__int64)getConfig();
v2[1] = v2[0];
while ( (unsigned int)scan((char **)&ptr, (__int64)v2) )
{
v0 = open(file, 0);
if ( v0 < 0 )
perror("error in parse");
addFt(ptr, (unsigned int)v0);
free(ptr);
free(file);
}
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebx
__int64 v2[4]; // [rsp+0h] [rbp-48h] BYREF
void *ptr; // [rsp+20h] [rbp-28h] BYREF
char *file; // [rsp+28h] [rbp-20h]

v2[0] = (__int64)func0();
v2[1] = v2[0];
while ( (unsigned int)func1((char **)&ptr, (__int64)v2) )
{
v0 = open(file, 0);
if ( v0 < 0 )
perror("error in parse");
addFt(ptr, (unsigned int)v0);
free(ptr);
free(file);
}
return 1LL;
}

original_code:
int parse() {
 struct rToken tok;
 struct lexer lex;
 char *config = getConfig();
 lex.start = config;
 lex.end = config;
 int fd;
 while (scan(&tok, &lex, config)) {
  fd = open(tok.path, 00);
  if (fd<0)
   perror("error in parse");
  addFt(tok.request, fd);
  free(tok.request);
  free(tok.path);
 } return 1;
}

variable_types: struct rToken { char *request; char *path; }

variable_types: struct lexer { char *start; char *end; int flag; }

variable_types: fd int


c

decompiled_code:
int __fastcall c(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void c(char *string) {
 fprintf(stderr, "%s\n", string);
}

variable_types:
string
char *


detruirePion

repo: KevinBacas/GoProject

decompiled_code:
void __fastcall detruirePion(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

original_code:
void detruirePion(SPion* pion)
{
 free(pion);
}

canonical_original_code:
void detruirePion(struct SPion *pion)
{
 free(pion);
}

variable_types: struct SPion { struct SPosition { int x; int y; } pos; enum Couleur { NOIR=-1, VIDE=0, BLANC=1, BORD=2, UNDEFINED=3 } couleur; } *

user_defined_types: struct SPion { struct SPosition pos; enum Couleur couleur; }


couleurPion

decompiled_code:
__int64 __fastcall couleurPion(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
ECouleur couleurPion(SPion* pion)
{
 return pion->couleur;
}

canonical_original_code:
enum Couleur couleurPion(struct SPion *pion)
{
 return pion->couleur;
}

return_type: enum Couleur { NOIR=-1, VIDE=0, BLANC=1, BORD=2, UNDEFINED=3 }


abscissePion

decompiled_code:
__int64 abscissePion()
{
return abscissePosition();
}

canonical_decompiled_code:
__int64 func2()
{
return abscissePosition();
}

original_code:
int abscissePion(SPion* pion)
{
 return abscissePosition(&pion->pos);
}

canonical_original_code:
int abscissePion(struct SPion *pion)
{
 return abscissePosition(&pion->pos);
}

user_defined_types: enum Couleur { NOIR=-1, VIDE=0, BLANC=1, BORD=2, UNDEFINED=3 }


ordonneePion

decompiled_code:
__int64 ordonneePion()
{
return ordonneePosition();
}

canonical_decompiled_code:
__int64 func3()
{
return ordonneePosition();
}

original_code:
int ordonneePion(SPion* pion)
{
 return ordonneePosition(&pion->pos);
}

canonical_original_code:
int ordonneePion(struct SPion *pion)
{
 return ordonneePosition(&pion->pos);
}


positionPion

decompiled_code:
__int64 __fastcall positionPion(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
SPosition positionPion(SPion* pion)
{
 return pion->pos;
}

canonical_original_code:
struct SPosition positionPion(struct SPion *pion)
{
 return pion->pos;
}

variable_types: struct SPion { struct SPosition pos; enum Couleur { NOIR=-1, VIDE=0, BLANC=1, BORD=2, UNDEFINED=3 } couleur; } *

return_type: struct SPosition { int x; int y; }


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

if ( a1 == 66 )
return 1LL;
result = 0xFFFFFFFFLL;
if ( a1 != 78 )
result = 2 * (unsigned int)(a1 == 45);
return result;
}

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

if ( a1 == 66 )
return 1LL;
result = 0xFFFFFFFFLL;
if ( a1 != 78 )
result = 2 * (unsigned int)(a1 == 45);
return result;
}

original_code:
ECouleur char_to_couleur(char c)
{
 switch(c)
 {
 case'N' : return NOIR;
 case'_' : return VIDE;
 case'B' : return BLANC;
 case'-' : return BORD;
 default : return VIDE;
 }
}

canonical_original_code:
enum Couleur char_to_couleur(char c)
{
 switch(c)
 {
 case'N' : return NOIR;
 case'_' : return VIDE;
 case'B' : return BLANC;
 case'-' : return BORD;
 default : return VIDE;
 }
}

variable_types: c char


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

if ( a1 == 1 )
return 66LL;
if ( a1 > 1 )
{
result = 68LL;
if ( a1 == 2 )
result = 95LL;
}
else
{
result = 78LL;
if ( a1 != -1 )
result = a1 == 0 ? 95 : 68;
}
return result;
}

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

if ( a1 == 1 )
return 66LL;
if ( a1 > 1 )
{
result = 68LL;
if ( a1 == 2 )
result = 95LL;
}
else
{
result = 78LL;
if ( a1 != -1 )
result = a1 == 0 ? 95 : 68;
}
return result;
}

original_code:
char couleur_to_char(ECouleur c)
{
 switch(c)
 {
 case NOIR : return 'N';
 case VIDE : return '_';
 case BLANC : return 'B';
 case BORD : return '_';
 default : return 'D';
 }
}

canonical_original_code:
char couleur_to_char(enum Couleur c)
{
 switch(c)
 {
 case NOIR : return 'N';
 case VIDE : return '_';
 case BLANC : return 'B';
 case BORD : return '_';
 default : return 'D';
 }
}

variable_types: enum Couleur { NOIR=-1, VIDE=0, BLANC=1, BORD=2, UNDEFINED=3 }

return_type: char


afficherMatrice

decompiled_code:
int __fastcall afficherMatrice(__int64 a1)
{
int result; // eax
__int64 i; // r14
__int64 j; // rbx

result = printf("%d %d\n", *(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 12));
if ( *(_QWORD *)a1 )
{
for ( i = 0LL; *(_DWORD *)(a1 + 8) > (int)i; ++i )
{
for ( j = 0LL; *(_DWORD *)(a1 + 12) > (int)j; ++j )
printf("%c ", (unsigned int)*(char *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * i) + j));
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int result; // eax
__int64 i; // r14
__int64 j; // rbx

result = printf("%d %d\n", *(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 12));
if ( *(_QWORD *)a1 )
{
for ( i = 0LL; *(_DWORD *)(a1 + 8) > (int)i; ++i )
{
for ( j = 0LL; *(_DWORD *)(a1 + 12) > (int)j; ++j )
printf("%c ", (unsigned int)*(char *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * i) + j));
result = putchar(10);
}
}
return result;
}

original_code:
void afficherMatrice(Matrice* matrice)
{
  printf("%d %d\n", matrice->nbLigne, matrice->nbColonne);
  if(matrice->donnees)
  {
    int i,j;
    for(i = 0 ; i < matrice->nbLigne ; ++i)
    {
      for(j = 0 ; j < matrice->nbColonne ; ++j)
      {
       printf("%c ", matrice->donnees[i][j]);
      }
      printf("\n");
    }
  }
}

canonical_original_code:
void afficherMatrice(struct matrice *matrice)
{
  printf("%d %d\n", matrice->nbLigne, matrice->nbColonne);
  if(matrice->donnees)
  {
    int i; int j;
    for(i = 0 ; i < matrice->nbLigne ; ++i)
    {
      for(j = 0 ; j < matrice->nbColonne ; ++j)
      {
       printf("%c ", matrice->donnees[i][j]);
      }
      printf("\n");
    }
  }
}

variable_types: struct matrice { char **donnees; int nbLigne; int nbColonne; } *

variable_types: j int


supprimerMatrice

decompiled_code:
int __fastcall supprimerMatrice(const char *a1)
{
return remove(a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
return remove(a1);
}

original_code:
int supprimerMatrice(char* nom_fichier)
{
  return remove(nom_fichier);
}

canonical_original_code:
int supprimerMatrice(char *nom_fichier)
{
  return remove(nom_fichier);
}


desallouerMatrice

decompiled_code:
void __fastcall desallouerMatrice(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void desallouerMatrice(Matrice* matrice)
{
  int i;
  for( i = 0 ; i < matrice->nbLigne ; ++i)
  {
    free(matrice->donnees[i]);
  }
  free(matrice->donnees);
  free(matrice);
}

canonical_original_code:
void desallouerMatrice(struct matrice *matrice)
{
  int i;
  for( i = 0 ; i < matrice->nbLigne ; ++i)
  {
    free(matrice->donnees[i]);
  }
  free(matrice->donnees);
  free(matrice);
}

user_defined_types: struct matrice { char **donnees; int nbLigne; int nbColonne; }


getValeurMatrice

decompiled_code:
__int64 __fastcall getValeurMatrice(_QWORD *a1, int a2, int a3)
{
return *(unsigned __int8 *)(*(_QWORD *)(*a1 + 8LL * a2) + a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, int a2, int a3)
{
return *(unsigned __int8 *)(*(_QWORD *)(*a1 + 8LL * a2) + a3);
}

original_code:
char getValeurMatrice(Matrice* matrice, int x, int y)
{
  return matrice->donnees[x][y];
}

canonical_original_code:
char getValeurMatrice(struct matrice *matrice, int x, int y)
{
  return matrice->donnees[x][y];
}

variable_types: x int

variable_types: y int


setValeurMatrice

decompiled_code:
__int64 __fastcall setValeurMatrice(__int64 a1, int a2, int a3, char a4)
{
__int64 result; // rax

if ( a2 >= 0 && *(_DWORD *)(a1 + 8) > a2 && a3 >= 0 && *(_DWORD *)(a1 + 12) > a3 )
{
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
*(_BYTE *)(result + a3) = a4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, int a3, char a4)
{
__int64 result; // rax

if ( a2 >= 0 && *(_DWORD *)(a1 + 8) > a2 && a3 >= 0 && *(_DWORD *)(a1 + 12) > a3 )
{
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
*(_BYTE *)(result + a3) = a4;
}
return result;
}

original_code:
void setValeurMatrice(Matrice* matrice, int x, int y, char valeur)
{
 if(x > -1 && x < matrice->nbLigne && y > -1 && y < matrice->nbColonne)
  matrice->donnees[x][y] = valeur;
}

canonical_original_code:
void setValeurMatrice(struct matrice *matrice, int x, int y, char valeur)
{
 if(x > -1 && x < matrice->nbLigne && y > -1 && y < matrice->nbColonne)
  matrice->donnees[x][y] = valeur;
}

variable_types: valeur char


getNbLigne

decompiled_code:
__int64 __fastcall getNbLigne(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int getNbLigne(Matrice* matrice)
{
 return matrice->nbLigne;
}

canonical_original_code:
int getNbLigne(struct matrice *matrice)
{
 return matrice->nbLigne;
}


getNbColonne

decompiled_code:
__int64 __fastcall getNbColonne(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int getNbColonne(Matrice* matrice)
{
 return matrice->nbColonne;
}

canonical_original_code:
int getNbColonne(struct matrice *matrice)
{
 return matrice->nbColonne;
}


detruirePosition

decompiled_code:
void __fastcall detruirePosition(void *a1)
{
free(a1);
}

original_code:
void detruirePosition(SPosition* position)
{
 free(position);
}

canonical_original_code:
void detruirePosition(struct SPosition *position)
{
 free(position);
}

variable_types:
position
struct SPosition { int x; int y; } *


abscissePosition

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

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

original_code:
int abscissePosition(SPosition* position)
{
 return position->x;
}

canonical_original_code:
int abscissePosition(struct SPosition *position)
{
 return position->x;
}


ordonneePosition

decompiled_code:
__int64 __fastcall ordonneePosition(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int ordonneePosition(SPosition* position)
{
 return position->y;
}

canonical_original_code:
int ordonneePosition(struct SPosition *position)
{
 return position->y;
}


positionsEgale

decompiled_code:
_BOOL8 __fastcall positionsEgale(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

original_code:
int positionsEgale(void* pos1, void* pos2)
{
 SPosition* p1 = (SPosition*)pos1;
 SPosition* p2 = (SPosition*)pos2;
 return ((p1->x == p2->x) && (p1->y == p2->y));
}

canonical_original_code:
int positionsEgale(void *pos1, void *pos2)
{
 struct SPosition *p1 = (SPosition*)pos1;
 struct SPosition *p2 = (SPosition*)pos2;
 return ((p1->x == p2->x) && (p1->y == p2->y));
}


listInit

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
SList* listInit()
{
 SList* res = malloc(sizeof(SList));
 res->head = ((void *)0);
 res->curr = ((void *)0);
 return res;
}

canonical_original_code:
struct list *listInit()
{
 struct list *res = malloc(sizeof(SList));
 res->head = ((void *)0);
 res->curr = ((void *)0);
 return res;
}

variable_types: struct list { struct node { void *data; struct node *next; } *head; struct node *curr; } *

user_defined_types: struct list { struct node *head; struct node *curr; }


listEmpty

decompiled_code:
_BOOL8 __fastcall listEmpty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int listEmpty(SList* list)
{
 return list->head ? 0 : 1;
}

canonical_original_code:
int listEmpty(struct list *list)
{
 return list->head ? 0 : 1;
}

user_defined_types: struct node { void *data; struct node *next; }


listNext

original_code:
void* listNext(SList* list)
{
 void* res = ((void *)0);
 if(!listEmpty(list))
 {
  if(list->curr->next)
  {
   res = list->curr->next->data;
   list->curr = list->curr->next;
  }
 }
 return res;
}

canonical_original_code:
void *listNext(struct list *list)
{
 void *res = ((void *)0);
 if(!listEmpty(list))
 {
  if(list->curr->next)
  {
   res = list->curr->next->data;
   list->curr = list->curr->next;
  }
 }
 return res;
}

variable_types:
res
void *

return_type: void *


listAdd

decompiled_code:
void __fastcall listAdd(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // r12

if ( a2 )
{
v2 = malloc(0x10uLL);
*v2 = a2;
v2[1] = 0LL;
if ( listEmpty(a1) )
{
*a1 = v2;
a1[1] = v2;
}
else
{
while ( listNext(a1) )
;
*(_QWORD *)(a1[1] + 8LL) = v2;
}
}
}

original_code:
void listAdd(SList* list, void* elem)
{
 if(elem)
 {
  SListNode* node = malloc(sizeof(SListNode));
  node->data = elem;
  node->next = ((void *)0);
  if(listEmpty(list))
  {
   list->head = node;
   list->curr = node;
  }
  else
  {
   while(listNext(list));
   list->curr->next = node;
  }
 }
}

canonical_original_code:
void listAdd(struct list *list, void *elem)
{
 if(elem)
 {
  struct node *node = malloc(sizeof(SListNode));
  node->data = elem;
  node->next = ((void *)0);
  if(listEmpty(list))
  {
   list->head = node;
   list->curr = node;
  }
  else
  {
   while(listNext(list));
   list->curr->next = node;
  }
 }
}

variable_types:
elem
void *

variable_types: struct node { void *data; struct node *next; } *


listRemove

original_code:
void* listRemove(SList* list, int index)
{
 void* res = ((void *)0);
 if(list)
 {
  listHead(list);
  if(!listEmpty(list))
  {
   if(index == 0)
   {
    SListNode* to_delete = list->head;
    list->head = list->head->next;
    res = to_delete->data;
    free(to_delete);
   }
   else
   {
    int i = 1;
    while(listNext(list) && i != index-1) ++i;
    if( i == index-1)
    {
     SListNode* to_delete = list->curr->next;
     list->curr->next = list->curr->next->next;
     res = to_delete->data;
     free(to_delete);
    }
   }
  }
 }
 return res;
}

canonical_original_code:
void *listRemove(struct list *list, int index)
{
 void *res = ((void *)0);
 if(list)
 {
  listHead(list);
  if(!listEmpty(list))
  {
   if(index == 0)
   {
    struct node *to_delete = list->head;
    list->head = list->head->next;
    res = to_delete->data;
    free(to_delete);
   }
   else
   {
    int i = 1;
    while(listNext(list) && i != index-1) ++i;
    if( i == index-1)
    {
     struct node *to_delete = list->curr->next;
     list->curr->next = list->curr->next->next;
     res = to_delete->data;
     free(to_delete);
    }
   }
  }
 }
 return res;
}

variable_types: index int

variable_types: i int


listRemoveElement

original_code:
void* listRemoveElement(SList* list, void* elem)
{
 void* res = ((void *)0);
 if(!listEmpty(list))
 {
  SListNode* prev = ((void *)0);
  SListNode* curr = ((void *)0);
  listHead(list);
  int found = 0;
  do
  {
   prev = curr;
   curr = list->curr;
   if(listCurrent(list) == elem)
   {
    found = 1;
    if(curr == list->head)
    {
     list->head = list->head->next;
     list->curr = list->head;
    }
    else
    {
     prev->next = curr->next;
     list->curr = prev;
    }
    res = curr->data;
    free(curr);
   }
  }while(!found && listNext(list));
 }
 return res;
}

canonical_original_code:
void *listRemoveElement(struct list *list, void *elem)
{
 void *res = ((void *)0);
 if(!listEmpty(list))
 {
  struct node *prev = ((void *)0);
  struct node *curr = ((void *)0);
  listHead(list);
  int found = 0;
  do
  {
   prev = curr;
   curr = list->curr;
   if(listCurrent(list) == elem)
   {
    found = 1;
    if(curr == list->head)
    {
     list->head = list->head->next;
     list->curr = list->head;
    }
    else
    {
     prev->next = curr->next;
     list->curr = prev;
    }
    res = curr->data;
    free(curr);
   }
  }while(!found && listNext(list));
 }
 return res;
}

variable_types: found int


listSize

decompiled_code:
__int64 __fastcall listSize(_QWORD *a1)
{
unsigned int v1; // ebx

v1 = 0;
if ( a1 )
{
listHead((__int64)a1);
v1 = 1;
while ( listNext(a1) )
++v1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
unsigned int v1; // ebx

v1 = 0;
if ( a1 )
{
listHead((__int64)a1);
v1 = 1;
while ( func2(a1) )
++v1;
}
return v1;
}

original_code:
int listSize(SList* list)
{
 int res = 0;
 if(list)
 {
  listHead(list);
  ++res;
  while(listNext(list)) ++res;
 }
 return res;
}

canonical_original_code:
int listSize(struct list *list)
{
 int res = 0;
 if(list)
 {
  listHead(list);
  ++res;
  while(listNext(list)) ++res;
 }
 return res;
}

variable_types: res int


listFind

decompiled_code:
__int64 __fastcall listFind(_QWORD *a1, _QWORD *a2)
{
listHead((__int64)a1);
while ( a2 != listCurrent((__int64)a1) )
{
if ( !listNext(a1) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _QWORD *a2)
{
listHead((__int64)a1);
while ( a2 != listCurrent((__int64)a1) )
{
if ( !func2(a1) )
return 0LL;
}
return 1LL;
}

original_code:
int listFind(SList* list, void* elem)
{
 listHead(list);
 while(listCurrent(list) != elem)
 {
  if(!listNext(list))
  {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int listFind(struct list *list, void *elem)
{
 listHead(list);
 while(listCurrent(list) != elem)
 {
  if(!listNext(list))
  {
   return 0;
  }
 }
 return 1;
}


listSearch

decompiled_code:
__int64 __fastcall listSearch(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD *, __int64))
{
unsigned int v4; // ebx
_QWORD *v5; // rax

if ( a3 == 0LL || a2 == 0 || !a1 )
return 0;
v4 = 0;
if ( !listEmpty(a1) )
{
listHead((__int64)a1);
do
{
v5 = listCurrent((__int64)a1);
v4 = a3(v5, a2);
}
while ( !v4 && listNext(a1) );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD *, __int64))
{
unsigned int v4; // ebx
_QWORD *v5; // rax

if ( a3 == 0LL || a2 == 0 || !a1 )
return 0;
v4 = 0;
if ( !func1(a1) )
{
listHead((__int64)a1);
do
{
v5 = listCurrent((__int64)a1);
v4 = a3(v5, a2);
}
while ( !v4 && func2(a1) );
}
return v4;
}

original_code:
int listSearch(SList* list, void* elem, int(*cmp)(void*, void*))
{
 int found = 0;
 if(list && elem && cmp && !listEmpty(list))
 {
  listHead(list);
  do
  {
   found = cmp(listCurrent(list), elem);
  }while(!found && listNext(list));
 }
 return found;
}

canonical_original_code:
int listSearch(struct list *list, void *elem, int (*cmp)(void *, void *))
{
 int found = 0;
 if(list && elem && cmp && !listEmpty(list))
 {
  listHead(list);
  do
  {
   found = cmp(listCurrent(list), elem);
  }while(!found && listNext(list));
 }
 return found;
}

variable_types:
cmp
int (*)(void *, void *)


listDelete

decompiled_code:
void __fastcall listDelete(void *ptr)
{
if ( ptr )
{
while ( !listEmpty(ptr) )
listRemove((__int64 **)ptr, 0);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
if ( ptr )
{
while ( !func1(ptr) )
func4((__int64 **)ptr, 0);
free(ptr);
}
}

original_code:
void listDelete(SList* list)
{
 if(list)
 {
  while(!listEmpty(list))
  {
   listRemove(list,0);
  }
  free(list);
 }
}

canonical_original_code:
void listDelete(struct list *list)
{
 if(list)
 {
  while(!listEmpty(list))
  {
   listRemove(list,0);
  }
  free(list);
 }
}


compareCouleur

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

if ( a1 - 2 <= 1 )
{
result = 2LL;
if ( a2 != 3 )
result = a2;
}
else
{
result = a1;
if ( a2 - 2 > 1 )
{
result = 0LL;
if ( a1 == a2 )
result = a2;
}
}
return result;
}

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

if ( a1 - 2 <= 1 )
{
result = 2LL;
if ( a2 != 3 )
result = a2;
}
else
{
result = a1;
if ( a2 - 2 > 1 )
{
result = 0LL;
if ( a1 == a2 )
result = a2;
}
}
return result;
}

original_code:
ECouleur compareCouleur(ECouleur couleur1, ECouleur couleur2)
{
 if(couleur1 == BORD || couleur1 == UNDEFINED)
 {
  if(couleur2==UNDEFINED) return BORD;
  else return couleur2;
 }
 if(couleur2 == BORD || couleur2 == UNDEFINED)
 {
  if(couleur1==UNDEFINED) return BORD;
  else return couleur1;
 }
 if(couleur1==couleur2) return couleur1;
 else return VIDE;
}

canonical_original_code:
enum Couleur compareCouleur(enum Couleur couleur1, enum Couleur couleur2)
{
 if(couleur1 == BORD || couleur1 == UNDEFINED)
 {
  if(couleur2==UNDEFINED) return BORD;
  else return couleur2;
 }
 if(couleur2 == BORD || couleur2 == UNDEFINED)
 {
  if(couleur1==UNDEFINED) return BORD;
  else return couleur1;
 }
 if(couleur1==couleur2) return couleur1;
 else return VIDE;
}


loadSound

repo: KillerJaguar/simple-mario

decompiled_code:
__int64 __fastcall loadSound(const char *a1)
{
__int64 v2; // rax
__int64 v3; // rbx
FILE *v4; // rdi
const char *v5; // rdx

v2 = SDL_RWFromFile(a1, &unk_648);
v3 = Mix_LoadWAV_RW(v2, 1LL);
v4 = stdout;
v5 = "Loaded sound";
if ( !v3 )
{
v5 = (const char *)SDL_GetError(stdout, 1LL, "Loaded sound");
v4 = stderr;
}
fprintf(v4, "%s: %s\n", v5, a1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v2; // rax
__int64 v3; // rbx
FILE *v4; // rdi
const char *v5; // rdx

v2 = SDL_RWFromFile(a1, &unk_648);
v3 = Mix_LoadWAV_RW(v2, 1LL);
v4 = stdout;
v5 = "Loaded sound";
if ( !v3 )
{
v5 = (const char *)SDL_GetError(stdout, 1LL, "Loaded sound");
v4 = stderr;
}
fprintf(v4, "%s: %s\n", v5, a1);
return v3;
}

original_code:
Mix_Chunk * loadSound( char * filename )
{
 Mix_Chunk * sfx = Mix_LoadWAV_RW(SDL_RWFromFile(filename, "rb"), 1);
 int loaded = sfx != ((void *)0);
 fprintf( loaded ? stdout : stderr, "%s: %s\n", loaded ? "Loaded sound" : SDL_GetError(), filename );
 return sfx;
}

canonical_original_code:
struct Mix_Chunk *loadSound(char *filename)
{
 struct Mix_Chunk *sfx = Mix_LoadWAV_RW(SDL_RWFromFile(filename, "rb"), 1);
 int loaded = sfx != ((void *)0);
 fprintf( loaded ? stdout : stderr, "%s: %s\n", loaded ? "Loaded sound" : SDL_GetError(), filename );
 return sfx;
}

variable_types:
filename
char *

variable_types: struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; } *

variable_types: loaded int


drawRect

decompiled_code:
__int64 __fastcall drawRect(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 a5)
{
unsigned int v5; // eax
__int64 v7; // [rsp+8h] [rbp-10h] BYREF

v7 = a1;
v5 = SDL_MapRGBA(*(_QWORD *)(g_Screen + 8), a2, a3, a4, a5);
return SDL_FillRect(g_Screen, &v7, v5);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 a5)
{
unsigned int v5; // eax
__int64 v7; // [rsp+8h] [rbp-10h] BYREF

v7 = a1;
v5 = SDL_MapRGBA(*(_QWORD *)(g_Screen + 8), a2, a3, a4, a5);
return SDL_FillRect(g_Screen, &v7, v5);
}

original_code:
void drawRect( SDL_Rect rect, char r, char g, char b, char a )
{
 SDL_FillRect( g_Screen, &rect, SDL_MapRGBA( g_Screen->format, r, g, b, a ) );
}

canonical_original_code:
void drawRect(struct SDL_Rect rect, char r, char g, char b, char a)
{
 SDL_FillRect( g_Screen, &rect, SDL_MapRGBA( g_Screen->format, r, g, b, a ) );
}

variable_types: struct SDL_Rect { short x; unsigned short w; }

variable_types: r char

variable_types: g char

variable_types: b char

variable_types: a char


playSound

decompiled_code:
__int64 __fastcall playSound(__int64 a1)
{
return Mix_PlayChannelTimed(0xFFFFFFFFLL, a1, 0LL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return Mix_PlayChannelTimed(0xFFFFFFFFLL, a1, 0LL, 0xFFFFFFFFLL);
}

original_code:
void playSound( Mix_Chunk * sfx )
{
 Mix_PlayChannelTimed(-1,sfx,0,-1);
}

canonical_original_code:
void playSound(struct Mix_Chunk *sfx)
{
 Mix_PlayChannelTimed(-1,sfx,0,-1);
}

user_defined_types: struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; }


rect

decompiled_code:
unsigned __int64 __fastcall rect(unsigned __int16 a1, unsigned __int16 a2, unsigned __int16 a3, __int64 a4)
{
return (a4 << 48) | ((unsigned __int64)a3 << 32) | ((unsigned __int64)a2 << 16) | a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(unsigned __int16 a1, unsigned __int16 a2, unsigned __int16 a3, __int64 a4)
{
return (a4 << 48) | ((unsigned __int64)a3 << 32) | ((unsigned __int64)a2 << 16) | a1;
}

original_code:
SDL_Rect rect( int x, int y, unsigned w, unsigned h )
{
 SDL_Rect r;
 r.x = x; r.y = y; r.w = w; r.h = h;
 return r;
}

canonical_original_code:
struct SDL_Rect rect(int x, int y, unsigned int w, unsigned int h)
{
 struct SDL_Rect r;
 r.x = x; r.y = y; r.w = w; r.h = h;
 return r;
}

variable_types: x int

variable_types: y int

variable_types:
w
unsigned int

variable_types:
h
unsigned int

return_type: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
_BOOL8 __fastcall rect_contains(unsigned __int64 a1, int a2, int a3)
{
_BOOL4 v3; // ecx

v3 = 0;
if ( (__int16)a1 <= a2 && (__int16)a1 + WORD2(a1) >= a2 && (int)a1 >> 16 <= a3 )
v3 = (int)(((int)a1 >> 16) + HIWORD(a1)) >= a3;
return v3;
}

original_code:
int rect_contains( SDL_Rect a, int x, int y )
{
 return a.x <= x && x <= a.x + a.w && a.y <= y && y <= a.y + a.h;
}

canonical_original_code:
int rect_contains(struct SDL_Rect a, int x, int y)
{
 return a.x <= x && x <= a.x + a.w && a.y <= y && y <= a.y + a.h;
}

user_defined_types: struct SDL_Rect { short x; unsigned short w; }


original_code:
int rect_intersect( SDL_Rect a, SDL_Rect b )
{
     return !( b.x > a.x + a.w ||
               b.x + b.w < a.x ||
               b.y > a.y + a.h ||
               b.y + b.h < a.y );
}

canonical_original_code:
int rect_intersect(struct SDL_Rect a, struct SDL_Rect b)
{
     return !( b.x > a.x + a.w ||
               b.x + b.w < a.x ||
               b.y > a.y + a.h ||
               b.y + b.h < a.y );
}

variable_types:
b
struct SDL_Rect


decompiled_code:
__int64 __fastcall timer_getElapsedTime(_DWORD *a1)
{
return (unsigned int)SDL_GetTicks() - *a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
return (unsigned int)SDL_GetTicks() - *a1;
}

original_code:
int timer_getElapsedTime( Timer * timer )
{
 return SDL_GetTicks() - timer->tick;
}

canonical_original_code:
int timer_getElapsedTime(struct Timer *timer)
{
 return SDL_GetTicks() - timer->tick;
}

variable_types: struct Timer { int tick; int interval; } *


decompiled_code:
__int64 __fastcall timer_update(_DWORD *a1)
{
unsigned int v1; // ebp
unsigned int v2; // edx
__int64 result; // rax

v1 = *a1 + a1[1];
v2 = SDL_GetTicks();
result = 0LL;
if ( v1 < v2 )
{
*a1 = SDL_GetTicks();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1)
{
unsigned int v1; // ebp
unsigned int v2; // edx
__int64 result; // rax

v1 = *a1 + a1[1];
v2 = SDL_GetTicks();
result = 0LL;
if ( v1 < v2 )
{
*a1 = SDL_GetTicks();
result = 1LL;
}
return result;
}

original_code:
int timer_update( Timer * timer )
{
 if ( timer->tick + timer->interval < SDL_GetTicks() )
 {
  timer->tick = SDL_GetTicks();
  return 1;
 }
 return 0;
}

canonical_original_code:
int timer_update(struct Timer *timer)
{
 if ( timer->tick + timer->interval < SDL_GetTicks() )
 {
  timer->tick = SDL_GetTicks();
  return 1;
 }
 return 0;
}

user_defined_types: struct Timer { int tick; int interval; }


init

decompiled_code:
__int64 __fastcall init(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v5; // ebx
__int64 v6; // rdx
const char *v7; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax

if ( (unsigned int)SDL_Init(0xFFFFLL) == -1 )
{
v7 = (const char *)SDL_GetError(0xFFFFLL, a2, v2);
fprintf(stderr, "Failed to initialize SDL: %s\n", v7);
v5 = 1;
}
else if ( (int)Mix_OpenAudio(44100LL, 32784LL, 2LL, 1024LL) < 0 )
{
v9 = (const char *)SDL_GetError(44100LL, 32784LL, v3);
fprintf(stderr, "Error initializing SDL_mixer: %s\n", v9);
v5 = 1;
}
else
{
v5 = TTF_Init();
if ( v5 == -1 )
{
v10 = (const char *)SDL_GetError(44100LL, 32784LL, v4);
fprintf(stderr, "Error initializing TTF_font: %s\n", v10);
}
else
{
g_Screen = SDL_SetVideoMode(640LL, 480LL, 32LL, 0LL);
if ( g_Screen )
{
v5 = 1;
if ( !(unsigned int)game_init() )
{
v5 = game_setState();
if ( v5 )
{
v5 = 1;
}
else
{
sprintf(g_WinCaption, "Mario Tangent -- %d FPS", 60LL);
SDL_WM_SetCaption(g_WinCaption, 0LL);
}
}
}
else
{
v11 = (const char *)SDL_GetError(640LL, 480LL, v6);
fprintf(stderr, "Failed to create a window: %s\n", v11);
v5 = -1;
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v5; // ebx
__int64 v6; // rdx
const char *v7; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax

if ( (unsigned int)SDL_Init(0xFFFFLL) == -1 )
{
v7 = (const char *)SDL_GetError(0xFFFFLL, a2, v2);
fprintf(stderr, "Failed to initialize SDL: %s\n", v7);
v5 = 1;
}
else if ( (int)Mix_OpenAudio(44100LL, 32784LL, 2LL, 1024LL) < 0 )
{
v9 = (const char *)SDL_GetError(44100LL, 32784LL, v3);
fprintf(stderr, "Error initializing SDL_mixer: %s\n", v9);
v5 = 1;
}
else
{
v5 = TTF_Init();
if ( v5 == -1 )
{
v10 = (const char *)SDL_GetError(44100LL, 32784LL, v4);
fprintf(stderr, "Error initializing TTF_font: %s\n", v10);
}
else
{
g_Screen = SDL_SetVideoMode(640LL, 480LL, 32LL, 0LL);
if ( g_Screen )
{
v5 = 1;
if ( !(unsigned int)game_init() )
{
v5 = game_setState();
if ( v5 )
{
v5 = 1;
}
else
{
sprintf(g_WinCaption, "Mario Tangent -- %d FPS", 60LL);
SDL_WM_SetCaption(g_WinCaption, 0LL);
}
}
}
else
{
v11 = (const char *)SDL_GetError(640LL, 480LL, v6);
fprintf(stderr, "Failed to create a window: %s\n", v11);
v5 = -1;
}
}
}
return v5;
}

original_code:
int init( void )
{
 if ( SDL_Init( 0x0000FFFF ) == -1 )
 {
  fprintf( stderr, "Failed to initialize SDL: %s\n", SDL_GetError() );
  return 1;
 }
 if ( Mix_OpenAudio( 44100, 0x8010, 2, 1024 ) < 0 )
 {
  fprintf( stderr, "Error initializing SDL_mixer: %s\n", SDL_GetError());
  return 1;
 }
 if ( TTF_Init() == -1 )
 {
  fprintf( stderr, "Error initializing TTF_font: %s\n", SDL_GetError() );
  return -1;
 }
 g_Screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0x00000000 );
 if ( g_Screen == ((void *)0) )
 {
  fprintf( stderr, "Failed to create a window: %s\n", SDL_GetError() );
  return -1;
 }
 if ( game_init() != 0 || game_setState() != 0 )
  return 1;
 sprintf( g_WinCaption, "Mario Tangent -- %d FPS", FRAMES_PER_SECOND );
 SDL_WM_SetCaption( g_WinCaption, ((void *)0) );
 return 0;
}

canonical_original_code:
int init()
{
 if ( SDL_Init( 0x0000FFFF ) == -1 )
 {
  fprintf( stderr, "Failed to initialize SDL: %s\n", SDL_GetError() );
  return 1;
 }
 if ( Mix_OpenAudio( 44100, 0x8010, 2, 1024 ) < 0 )
 {
  fprintf( stderr, "Error initializing SDL_mixer: %s\n", SDL_GetError());
  return 1;
 }
 if ( TTF_Init() == -1 )
 {
  fprintf( stderr, "Error initializing TTF_font: %s\n", SDL_GetError() );
  return -1;
 }
 g_Screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0x00000000 );
 if ( g_Screen == ((void *)0) )
 {
  fprintf( stderr, "Failed to create a window: %s\n", SDL_GetError() );
  return -1;
 }
 if ( game_init() != 0 || game_setState() != 0 )
  return 1;
 sprintf( g_WinCaption, "Mario Tangent -- %d FPS", FRAMES_PER_SECOND );
 SDL_WM_SetCaption( g_WinCaption, ((void *)0) );
 return 0;
}


decompiled_code:
__int64 clean_up()
{
game_cleanup();
return SDL_Quit();
}

canonical_decompiled_code:
__int64 func15()
{
game_cleanup();
return SDL_Quit();
}

original_code:
void clean_up( void )
{
 game_cleanup();
 SDL_Quit();
}

canonical_original_code:
void clean_up()
{
 game_cleanup();
 SDL_Quit();
}


help

repo: KillingNoisesWorkgroup/rsa

decompiled_code:
void __fastcall __noreturn help(const char **a1)
{
printf("Usage: %s {-g public private num | -e src dst key | -d src dst key}\n", *a1);
printf("%5s: generates public and private files with keys of num bits length\n", "-g");
printf("%5s: encodes src file to dst file with given key file\n", "-e");
printf("%5s: decodes src file to dst file with given key file\n", "-d");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func13(const char **a1)
{
printf("Usage: %s {-g public private num | -e src dst key | -d src dst key}\n", *a1);
printf("%5s: generates public and private files with keys of num bits length\n", "-g");
printf("%5s: encodes src file to dst file with given key file\n", "-e");
printf("%5s: decodes src file to dst file with given key file\n", "-d");
exit(1);
}

original_code:
void help(char** argv){
 printf("Usage: %s {-g public private num | -e src dst key | -d src dst key}\n", argv[0]);
 printf("%5s: generates public and private files with keys of num bits length\n", "-g");
 printf("%5s: encodes src file to dst file with given key file\n", "-e");
 printf("%5s: decodes src file to dst file with given key file\n", "-d");
 exit(1);
}

canonical_original_code:
void help(char **argv){
 printf("Usage: %s {-g public private num | -e src dst key | -d src dst key}\n", argv[0]);
 printf("%5s: generates public and private files with keys of num bits length\n", "-g");
 printf("%5s: encodes src file to dst file with given key file\n", "-e");
 printf("%5s: decodes src file to dst file with given key file\n", "-d");
 exit(1);
}

variable_types:
argv
char **


repo: KimGunSoo/sosohancode

decompiled_code:
int __fastcall connect_server(void *buf)
{
int v1; // eax
int v2; // ebx
int v3; // er12
size_t v4; // rax
ssize_t v5; // rax
struct sockaddr v7[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
puts("socket() error!");
}
else
{
v2 = v1;
puts("socket() success!");
v7[0].sa_family = 1;
strcpy(v7[0].sa_data, "hwcontrol_UDS");
v3 = strlen(v7[0].sa_data);
puts("connect() ...");
if ( connect(v2, v7, v3 + 2) >= 0 )
{
puts("connect() success!");
v4 = strlen((const char *)buf);
v5 = send(v2, buf, v4 + 1, 0);
return printf("client msg[%d] = %s\n", v5, (const char *)buf);
}
puts("connect() error!");
}
return -1;
}

canonical_decompiled_code:
int __fastcall func7(void *buf)
{
int v1; // eax
int v2; // ebx
int v3; // er12
size_t v4; // rax
ssize_t v5; // rax
struct sockaddr v7[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
puts("socket() error!");
}
else
{
v2 = v1;
puts("socket() success!");
v7[0].sa_family = 1;
strcpy(v7[0].sa_data, "hwcontrol_UDS");
v3 = strlen(v7[0].sa_data);
puts("connect() ...");
if ( connect(v2, v7, v3 + 2) >= 0 )
{
puts("connect() success!");
v4 = strlen((const char *)buf);
v5 = send(v2, buf, v4 + 1, 0);
return printf("client msg[%d] = %s\n", v5, (const char *)buf);
}
puts("connect() error!");
}
return -1;
}

original_code:
int connect_server(char* conn_msg)
{
    int server_sock, client_sock;
    int len;
    struct sockaddr_un server_addr;
    if( (server_sock = socket(1, SOCK_STREAM, 0)) < 0 ){
        printf("socket() error!\n");
        return -1;
    }
    printf("socket() success!\n");
    server_addr.sun_family = 1;
    strcpy(server_addr.sun_path, "hwcontrol_UDS");
    len = sizeof(server_addr.sun_family) + strlen(server_addr.sun_path);
    printf("connect() ...\n");
    if( connect(server_sock,(const struct sockaddr*)&server_addr, len) < 0){
        printf("connect() error!\n");
        return -1;
    }
    printf("connect() success!\n");
    int nbyte;
    nbyte = send(server_sock, conn_msg, strlen(conn_msg) + 1, 0);
    printf("client msg[%d] = %s\n",nbyte, conn_msg);
}

canonical_original_code:
int connect_server(char *conn_msg)
{
    int server_sock; int client_sock;
    int len;
    struct sockaddr_un server_addr;
    if( (server_sock = socket(1, SOCK_STREAM, 0)) < 0 ){
        printf("socket() error!\n");
        return -1;
    }
    printf("socket() success!\n");
    server_addr.sun_family = 1;
    strcpy(server_addr.sun_path, "hwcontrol_UDS");
    len = sizeof(server_addr.sun_family) + strlen(server_addr.sun_path);
    printf("connect() ...\n");
    if( connect(server_sock,(struct sockaddr *)&server_addr, len) < 0){
        printf("connect() error!\n");
        return -1;
    }
    printf("connect() success!\n");
    int nbyte;
    nbyte = send(server_sock, conn_msg, strlen(conn_msg) + 1, 0);
    printf("client msg[%d] = %s\n",nbyte, conn_msg);
}

variable_types: len int

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

variable_types: nbyte int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("Start client main");
connect_server("1-client : Hi");
connect_server("2-client : Bye");
puts("End client main");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("Start client main");
func7("1-client : Hi");
func7("2-client : Bye");
puts("End client main");
return 0;
}

original_code:
int main(void)
{
    printf("Start client main\n");
    connect_server("1-client : Hi");
    connect_server("2-client : Bye");
    printf("End client main\n");
}

canonical_original_code:
int main()
{
    printf("Start client main\n");
    connect_server("1-client : Hi");
    connect_server("2-client : Bye");
    printf("End client main\n");
}


decompiled_code:
void *__fastcall hwcontrol_server_thread_fn(void *a1)
{
int v1; // eax
int v2; // ebp
ssize_t v3; // rax
int v4; // ebx
char v6[128]; // [rsp+0h] [rbp-188h] BYREF
struct sockaddr v7; // [rsp+80h] [rbp-108h] BYREF
struct sockaddr addr; // [rsp+F0h] [rbp-98h] BYREF
socklen_t len[7]; // [rsp+16Ch] [rbp-1Ch] BYREF

puts("Start hwcontrol server thread");
v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
puts("socket() error!");
}
else
{
v2 = v1;
puts("socket() success!");
addr.sa_family = 1;
strcpy(addr.sa_data, "hwcontrol_UDS");
len[0] = strlen(addr.sa_data) + 2;
if ( !access("hwcontrol_UDS", 0) )
unlink("hwcontrol_UDS");
if ( bind(v2, &addr, len[0]) < 0 )
{
puts("bind() error!");
perror("bind() error!\n");
}
else
{
puts("bind() success!");
if ( listen(v2, 10) < 0 )
{
puts("listen() error!");
}
else
{
puts("listen() success!");
while ( 1 )
{
puts("accept() ...");
v4 = accept(v2, &v7, len);
if ( v4 < 0 )
break;
puts("accept() success!");
v3 = recv(v4, v6, 0x80uLL, 0);
printf("client msg[%d] = %s\n", v3, v6);
}
puts("accept() error!");
}
}
}
return &hw_th_ret;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // eax
int v2; // ebp
ssize_t v3; // rax
int v4; // ebx
char v6[128]; // [rsp+0h] [rbp-188h] BYREF
struct sockaddr v7; // [rsp+80h] [rbp-108h] BYREF
struct sockaddr addr; // [rsp+F0h] [rbp-98h] BYREF
socklen_t len[7]; // [rsp+16Ch] [rbp-1Ch] BYREF

puts("Start hwcontrol server thread");
v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
puts("socket() error!");
}
else
{
v2 = v1;
puts("socket() success!");
addr.sa_family = 1;
strcpy(addr.sa_data, "hwcontrol_UDS");
len[0] = strlen(addr.sa_data) + 2;
if ( !access("hwcontrol_UDS", 0) )
unlink("hwcontrol_UDS");
if ( bind(v2, &addr, len[0]) < 0 )
{
puts("bind() error!");
perror("bind() error!\n");
}
else
{
puts("bind() success!");
if ( listen(v2, 10) < 0 )
{
puts("listen() error!");
}
else
{
puts("listen() success!");
while ( 1 )
{
puts("accept() ...");
v4 = accept(v2, &v7, len);
if ( v4 < 0 )
break;
puts("accept() success!");
v3 = recv(v4, v6, 0x80uLL, 0);
printf("client msg[%d] = %s\n", v3, v6);
}
puts("accept() error!");
}
}
}
return &hw_th_ret;
}

original_code:
static void* hwcontrol_server_thread_fn(void* arg)
{
    int server_sock, client_sock;
    int len;
    struct sockaddr_un server_addr, client_addr;
    printf("Start hwcontrol server thread\n");
    if( (server_sock = socket(1, SOCK_STREAM, 0)) < 0 ){
        printf("socket() error!\n");
        return (void*) &hw_th_ret;
    }
    printf("socket() success!\n");
    server_addr.sun_family = 1;
    strcpy(server_addr.sun_path, "hwcontrol_UDS");
    len = sizeof(server_addr.sun_family) + strlen(server_addr.sun_path);
    if( access("hwcontrol_UDS", 0) == 0){
        unlink("hwcontrol_UDS");
    }
    if( bind(server_sock,(const struct sockaddr*)&server_addr, len) < 0){
        printf("bind() error!\n");
        perror("bind() error!\n");
        return (void*) &hw_th_ret;
    }
    printf("bind() success!\n");
    if( listen(server_sock, 10) < 0 ){
        printf("listen() error!\n");
        return (void*) &hw_th_ret;
    }
    printf("listen() success!\n");
    while(1){
        printf("accept() ...\n");
        if( (client_sock = accept(server_sock, (struct sockaddr*)&client_addr, &len)) < 0 ){
            printf("accept() error!\n");
            return (void*) &hw_th_ret;
        }
        printf("accept() success!\n");
        char buff[128];
        int nbyte;
        nbyte = recv(client_sock, buff, sizeof(buff), 0);
        printf("client msg[%d] = %s\n",nbyte, buff);
    }
    printf("End hwcontrol server thread\n");
}

canonical_original_code:
static void *hwcontrol_server_thread_fn(void *arg)
{
    int server_sock; int client_sock;
    int len;
    struct sockaddr_un server_addr; struct sockaddr_un client_addr;
    printf("Start hwcontrol server thread\n");
    if( (server_sock = socket(1, SOCK_STREAM, 0)) < 0 ){
        printf("socket() error!\n");
        return (void *) &hw_th_ret;
    }
    printf("socket() success!\n");
    server_addr.sun_family = 1;
    strcpy(server_addr.sun_path, "hwcontrol_UDS");
    len = sizeof(server_addr.sun_family) + strlen(server_addr.sun_path);
    if( access("hwcontrol_UDS", 0) == 0){
        unlink("hwcontrol_UDS");
    }
    if( bind(server_sock,(struct sockaddr *)&server_addr, len) < 0){
        printf("bind() error!\n");
        perror("bind() error!\n");
        return (void *) &hw_th_ret;
    }
    printf("bind() success!\n");
    if( listen(server_sock, 10) < 0 ){
        printf("listen() error!\n");
        return (void *) &hw_th_ret;
    }
    printf("listen() success!\n");
    while(1){
        printf("accept() ...\n");
        if( (client_sock = accept(server_sock, (struct sockaddr *)&client_addr, &len)) < 0 ){
            printf("accept() error!\n");
            return (void *) &hw_th_ret;
        }
        printf("accept() success!\n");
        char buff[128];
        int nbyte;
        nbyte = recv(client_sock, buff, sizeof(buff), 0);
        printf("client msg[%d] = %s\n",nbyte, buff);
    }
    printf("End hwcontrol server thread\n");
}

variable_types:
arg
void *

variable_types:
buff
char [128]

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char thread_return[12]; // [rsp+4h] [rbp-114h] BYREF
__sigset_t oldmask; // [rsp+10h] [rbp-108h] BYREF
sigset_t set; // [rsp+90h] [rbp-88h] BYREF

puts("Start server main");
sigfillset(&set);
pthread_sigmask(2, &set, &oldmask);
pthread_create((pthread_t *)&thread_return[4], 0LL, hwcontrol_server_thread_fn, 0LL);
pthread_sigmask(2, &oldmask, 0LL);
pthread_join(*(pthread_t *)&thread_return[4], (void **)thread_return);
puts("End server main");
return 0;
}

original_code:
int main(void)
{
    sigset_t set, oldset;
    pthread_t thread;
    int ret;
    printf("Start server main\n");
    sigfillset(&set);
    pthread_sigmask(2, &set, &oldset);
    pthread_create(&thread, ((void *)0), hwcontrol_server_thread_fn, ((void *)0));
    pthread_sigmask(2, &oldset, ((void *)0));
    pthread_join(thread, (void **)&ret);
    printf("End server main\n");
}

canonical_original_code:
int main()
{
    struct __sigset_t set; struct __sigset_t oldset;
    unsigned long thread;
    int ret;
    printf("Start server main\n");
    sigfillset(&set);
    pthread_sigmask(2, &set, &oldset);
    pthread_create(&thread, ((void *)0), hwcontrol_server_thread_fn, ((void *)0));
    pthread_sigmask(2, &oldset, ((void *)0));
    pthread_join(thread, (void **)&ret);
    printf("End server main\n");
}

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

variable_types:
thread
unsigned long

variable_types: ret int


repo: KinG-InFeT/Sorgenti

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

v0 = getenv("USER");
return printf("\nCiao %s! FINE!\n", v0);
}

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

v0 = getenv("USER");
return printf("\nCiao %s! FINE!\n", v0);
}

original_code:
void print_footer() {
   printf( "\nCiao %s! FINE!\n", getenv( "USER" ) );
}


decompiled_code:
int print_header()
{
char v1[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(v1, "0.0.1");
return printf("\n0xChat\n\tBy KinG-InFeT v%s\n\n", v1);
}

canonical_decompiled_code:
int func10()
{
char v1[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(v1, "0.0.1");
return printf("\n0xChat\n\tBy KinG-InFeT v%s\n\n", v1);
}

original_code:
void print_header() {
char version[10];
 strcpy(version, "0.0.1");
   printf( "\n0xChat\n\tBy KinG-InFeT v%s\n\n", version);
}

variable_types:
version
char [10]


decompiled_code:
__int16 __fastcall socket_init(__int64 a1, __int16 a2, int a3)
{
__int16 result; // ax

*(_WORD *)a1 = 2;
result = _bswap_16(a2);
*(_WORD *)(a1 + 2) = result;
*(_DWORD *)(a1 + 4) = a3;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func11(__int64 a1, __int16 a2, int a3)
{
__int16 result; // ax

*(_WORD *)a1 = 2;
result = func8(a2);
*(_WORD *)(a1 + 2) = result;
*(_DWORD *)(a1 + 4) = a3;
return result;
}

original_code:
void socket_init( struct sockaddr_in *conn, int port, long int ip ) {
   conn->sin_family = 2;
   conn->sin_port = htons( port );
   conn->sin_addr.s_addr = ip;
}

canonical_original_code:
void socket_init(struct sockaddr_in *conn, int port, long ip) {
   conn->sin_family = 2;
   conn->sin_port = htons( port );
   conn->sin_addr.s_addr = ip;
}

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: port int

variable_types: ip long