decompiled_code:
__int64 __fastcall bitvolver_run(__int64 a1, int a2, int a3)
{
int v3; // er14
int v4; // er12
size_t v5; // rbx
char *v6; // r13
size_t v7; // rbp
char *v8; // rax
char *v9; // rsi
__int64 v10; // rdx
__int64 v11; // rax
char *v12; // r14
pthread_t *v13; // r13
pthread_t *v14; // r12
char *v15; // rbx
int v16; // ebp
void **v17; // rbp
pthread_t *v18; // rbx
int v20; // [rsp+0h] [rbp-78h]
unsigned int v21; // [rsp+4h] [rbp-74h]
pthread_t *newthread; // [rsp+8h] [rbp-70h]
void **thread_return; // [rsp+18h] [rbp-60h]
char *arg; // [rsp+20h] [rbp-58h]
char *v27; // [rsp+28h] [rbp-50h]
void *ptr; // [rsp+30h] [rbp-48h]
void *v29; // [rsp+38h] [rbp-40h]

v3 = a2;
v4 = a3;
v5 = 8LL * a2;
v6 = (char *)malloc(v5);
ptr = v6;
v27 = (char *)malloc(v5);
v7 = 16LL * a2;
v8 = (char *)malloc(v7);
v29 = v8;
if ( v4 > 0 )
{
v9 = v8;
arg = &v8[v7 - 16];
v10 = 8LL * (v3 - 1);
newthread = (pthread_t *)&v6[v10];
v11 = (unsigned int)(v3 - 1);
v12 = &v9[v7 - 32 - 16 * v11];
thread_return = (void **)&v27[v10];
v13 = (pthread_t *)&v6[v5 - 16 - 8 * v11];
v21 = 0;
do
{
v20 = *(_DWORD *)(a1 + 16) / a2 - 1;
printf("Generation %d\n", v21);
if ( a2 )
{
v14 = newthread;
v15 = arg;
v16 = 0;
do
{
*(_QWORD *)v15 = a1;
*((_DWORD *)v15 + 2) = v16;
v16 += v20;
*((_DWORD *)v15 + 3) = v16;
pthread_create(v14, 0LL, _evolve, v15);
v15 -= 16;
--v14;
}
while ( v15 != v12 );
v17 = thread_return;
v18 = newthread;
do
pthread_join(*v18--, v17--);
while ( v18 != v13 );
}
++v21;
}
while ( a3 != v21 );
}
free(ptr);
free(v27);
free(v29);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3)
{
int v3; // er14
int v4; // er12
size_t v5; // rbx
char *v6; // r13
size_t v7; // rbp
char *v8; // rax
char *v9; // rsi
__int64 v10; // rdx
__int64 v11; // rax
char *v12; // r14
pthread_t *v13; // r13
pthread_t *v14; // r12
char *v15; // rbx
int v16; // ebp
void **v17; // rbp
pthread_t *v18; // rbx
int v20; // [rsp+0h] [rbp-78h]
unsigned int v21; // [rsp+4h] [rbp-74h]
pthread_t *newthread; // [rsp+8h] [rbp-70h]
void **thread_return; // [rsp+18h] [rbp-60h]
char *arg; // [rsp+20h] [rbp-58h]
char *v27; // [rsp+28h] [rbp-50h]
void *ptr; // [rsp+30h] [rbp-48h]
void *v29; // [rsp+38h] [rbp-40h]

v3 = a2;
v4 = a3;
v5 = 8LL * a2;
v6 = (char *)malloc(v5);
ptr = v6;
v27 = (char *)malloc(v5);
v7 = 16LL * a2;
v8 = (char *)malloc(v7);
v29 = v8;
if ( v4 > 0 )
{
v9 = v8;
arg = &v8[v7 - 16];
v10 = 8LL * (v3 - 1);
newthread = (pthread_t *)&v6[v10];
v11 = (unsigned int)(v3 - 1);
v12 = &v9[v7 - 32 - 16 * v11];
thread_return = (void **)&v27[v10];
v13 = (pthread_t *)&v6[v5 - 16 - 8 * v11];
v21 = 0;
do
{
v20 = *(_DWORD *)(a1 + 16) / a2 - 1;
printf("Generation %d\n", v21);
if ( a2 )
{
v14 = newthread;
v15 = arg;
v16 = 0;
do
{
*(_QWORD *)v15 = a1;
*((_DWORD *)v15 + 2) = v16;
v16 += v20;
*((_DWORD *)v15 + 3) = v16;
pthread_create(v14, 0LL, _evolve, v15);
v15 -= 16;
--v14;
}
while ( v15 != v12 );
v17 = thread_return;
v18 = newthread;
do
pthread_join(*v18--, v17--);
while ( v18 != v13 );
}
++v21;
}
while ( a3 != v21 );
}
free(ptr);
free(v27);
free(v29);
return 0LL;
}

original_code:
int bitvolver_run(Bitvolver* bv, int threads, int generations){
 int i = 0, j = 0;
 pthread_t* trds = (pthread_t*)malloc(sizeof(pthread_t) * threads);
 void** returns = (void**)malloc(sizeof(void*) * threads);
 EvoArgs* args = (EvoArgs*)malloc(sizeof(EvoArgs) * threads);
 for(j = 0; j < generations; j++){
  int ti = 0;
  int memPerThread = (bv->MemberCount / threads) - 1;
  printf("Generation %d\n", j);
  for(i = threads; i--;){
   args[i].bv = bv;
   args[i].start = ti; ti += memPerThread;
   args[i].end = ti;
   pthread_create(&trds[i], ((void *)0), __evolve, &args[i]);
  }
  for(i = threads; i--;){
   pthread_join(trds[i], &returns[i]);
  }
 }
 free(trds);
 free(returns);
 free(args);
 return 0;
}

canonical_original_code:
int bitvolver_run(struct __bitvolver *bv, int threads, int generations){
 int i = 0; int j = 0;
 unsigned long *trds = (pthread_t*)malloc(sizeof(pthread_t) * threads);
 void **returns = (void**)malloc(sizeof(void*) * threads);
 struct EvoArgs *args = (EvoArgs*)malloc(sizeof(EvoArgs) * threads);
 for(j = 0; j < generations; j++){
  int ti = 0;
  int memPerThread = (bv->MemberCount / threads) - 1;
  printf("Generation %d\n", j);
  for(i = threads; i--;){
   args[i].bv = bv;
   args[i].start = ti; ti += memPerThread;
   args[i].end = ti;
   pthread_create(&trds[i], ((void *)0), __evolve, &args[i]);
  }
  for(i = threads; i--;){
   pthread_join(trds[i], &returns[i]);
  }
 }
 free(trds);
 free(returns);
 free(args);
 return 0;
}

variable_types: threads int

variable_types: generations int

variable_types: j int

variable_types:
trds
unsigned long *

variable_types:
returns
void **

variable_types: struct EvoArgs { struct __bitvolver { void *Generation; float *Fitnesses; int MemberCount; int MemberSize; float MutationRate; void (*Mutate)(struct __bitvolver *, void *src, void *dst); float (*Fitness)(void *member); } *bv; int start; int end; } *

variable_types: ti int

variable_types: memPerThread int

user_defined_types: struct EvoArgs { struct __bitvolver *bv; int start; int end; }


repo: mrshu/serialib

original_code:
int serial_open(serial **s, char* port, const unsigned int baud)
{
 *s = (serial *) malloc(sizeof(serial));
 (*s)->port = (char *) malloc((strlen(port) + 1) * sizeof(char));
 strcpy((*s)->port, port);
 struct termios options;
 (*s)->fd = open(port, 02 | 0400 | 04000);
 if ((*s)->fd == -1)
  return -1;
 fcntl((*s)->fd, 4, 04000);
 tcgetattr((*s)->fd, &options);
 bzero(&options, sizeof(options));
 speed_t speed;
 switch (baud){
  case 110 : speed=0000003; break;
  case 300 : speed=0000007; break;
  case 600 : speed=0000010; break;
  case 1200 : speed=0000011; break;
  case 2400 : speed=0000013; break;
  case 4800 : speed=0000014; break;
  case 9600 : speed=0000015; break;
  case 19200 : speed=0000016; break;
  case 38400 : speed=0000017; break;
  case 57600 : speed=0010001; break;
  case 115200 : speed=0010002; break;
 }
 cfsetispeed(&options, speed);
        cfsetospeed(&options, speed);
 options.c_cflag |= ( 0004000 | 0000200 | 0000060);
 options.c_cc[5]=0;
 options.c_cc[6]=0;
 tcsetattr((*s)->fd, 0, &options);
 return 0;
}

canonical_original_code:
int serial_open(struct serial_s **s, char *port, unsigned int baud)
{
 *s = (struct serial_s *) malloc(sizeof(serial));
 (*s)->port = (char *) malloc((strlen(port) + 1) * sizeof(char));
 strcpy((*s)->port, port);
 struct termios options;
 (*s)->fd = open(port, 02 | 0400 | 04000);
 if ((*s)->fd == -1)
  return -1;
 fcntl((*s)->fd, 4, 04000);
 tcgetattr((*s)->fd, &options);
 bzero(&options, sizeof(options));
 unsigned int speed;
 switch (baud){
  case 110 : speed=0000003; break;
  case 300 : speed=0000007; break;
  case 600 : speed=0000010; break;
  case 1200 : speed=0000011; break;
  case 2400 : speed=0000013; break;
  case 4800 : speed=0000014; break;
  case 9600 : speed=0000015; break;
  case 19200 : speed=0000016; break;
  case 38400 : speed=0000017; break;
  case 57600 : speed=0010001; break;
  case 115200 : speed=0010002; break;
 }
 cfsetispeed(&options, speed);
        cfsetospeed(&options, speed);
 options.c_cflag |= ( 0004000 | 0000200 | 0000060);
 options.c_cc[5]=0;
 options.c_cc[6]=0;
 tcsetattr((*s)->fd, 0, &options);
 return 0;
}

variable_types: struct serial_s { unsigned int baud; char *port; int fd; } **

variable_types:
port
char *

variable_types:
baud
unsigned int

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

variable_types:
speed
unsigned int

return_type: int


decompiled_code:
__int64 __fastcall serial_read_char(__int64 a1, void *a2)
{
return (unsigned int)-((unsigned int)read(*(_DWORD *)(a1 + 16), a2, 1uLL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, void *a2)
{
return (unsigned int)-((unsigned int)read(*(_DWORD *)(a1 + 16), a2, 1uLL) != 1);
}

original_code:
int serial_read_char(serial *s, char *p)
{
 return (read(s->fd, p, 1) == 1) ? 0 : -1;
}

canonical_original_code:
int serial_read_char(struct serial_s *s, char *p)
{
 return (read(s->fd, p, 1) == 1) ? 0 : -1;
}

variable_types: struct serial_s { unsigned int baud; char *port; int fd; } *

variable_types:
p
char *


decompiled_code:
__int64 __fastcall serial_read(__int64 a1, _BYTE *a2, char a3, int a4)
{
_BYTE *v5; // rbx
int v6; // er12
int v7; // ebp

v5 = a2;
v6 = a4 - 1;
v7 = 0;
while ( v7 != v6 )
{
++v7;
if ( (unsigned int)serial_read_char(a1, v5) )
{
*v5 = 0;
return 0xFFFFFFFFLL;
}
if ( *v5++ == a3 )
{
a2[v7] = 0;
return 1LL;
}
}
a2[v6] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2, char a3, int a4)
{
_BYTE *v5; // rbx
int v6; // er12
int v7; // ebp

v5 = a2;
v6 = a4 - 1;
v7 = 0;
while ( v7 != v6 )
{
++v7;
if ( (unsigned int)func1(a1, v5) )
{
*v5 = 0;
return 0xFFFFFFFFLL;
}
if ( *v5++ == a3 )
{
a2[v7] = 0;
return 1LL;
}
}
a2[v6] = 0;
return 1LL;
}

original_code:
int serial_read(serial *s, char *buf, char eol, unsigned int len)
{
 int i = 0;
 while (i < len-1) {
  int j = serial_read_char(s, &buf[i++]);
  if (j != 0){
   buf[i-1] = '\0';
   return -1;
  }
  if (buf[i-1] == eol){
   buf[i] = '\0';
   return 1;
  }
 }
 buf[i] = '\0';
 return 1;
}

canonical_original_code:
int serial_read(struct serial_s *s, char *buf, char eol, unsigned int len)
{
 int i = 0;
 while (i < len-1) {
  int j = serial_read_char(s, &buf[i++]);
  if (j != 0){
   buf[i-1] = '\0';
   return -1;
  }
  if (buf[i-1] == eol){
   buf[i] = '\0';
   return 1;
  }
 }
 buf[i] = '\0';
 return 1;
}

variable_types:
buf
char *

variable_types: eol char

variable_types:
len
unsigned int

variable_types: i int

user_defined_types: struct serial_s { unsigned int baud; char *port; int fd; }


decompiled_code:
__int64 __fastcall serial_write_char(__int64 a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-((unsigned int)write(*(_DWORD *)(a1 + 16), buf, 1uLL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-((unsigned int)write(*(_DWORD *)(a1 + 16), buf, 1uLL) != 1);
}

original_code:
int serial_write_char(serial *s, char p)
{
 return (write(s->fd, &p, 1) == 1) ? 0: -1;
}

canonical_original_code:
int serial_write_char(struct serial_s *s, char p)
{
 return (write(s->fd, &p, 1) == 1) ? 0: -1;
}

variable_types: p char


decompiled_code:
__int64 __fastcall serial_write(__int64 a1, const char *a2)
{
unsigned int v2; // ebx

v2 = strlen(a2);
return (unsigned int)-((unsigned int)write(*(_DWORD *)(a1 + 16), a2, v2) != v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
unsigned int v2; // ebx

v2 = strlen(a2);
return (unsigned int)-((unsigned int)write(*(_DWORD *)(a1 + 16), a2, v2) != v2);
}

original_code:
int serial_write(serial *s, char* str)
{
 int len = strlen(str);
 if (write(s->fd, str, len) != len)
  return -1;
 return 0;
}

canonical_original_code:
int serial_write(struct serial_s *s, char *str)
{
 int len = strlen(str);
 if (write(s->fd, str, len) != len)
  return -1;
 return 0;
}

variable_types:
str
char *

variable_types: len int


decompiled_code:
int __fastcall timer_init(struct timeval **a1)
{
struct timeval *v1; // rax

v1 = (struct timeval *)malloc(0x10uLL);
*a1 = v1;
return gettimeofday(v1, 0LL);
}

canonical_decompiled_code:
int __fastcall func5(struct timeval **a1)
{
struct timeval *v1; // rax

v1 = (struct timeval *)malloc(0x10uLL);
*a1 = v1;
return gettimeofday(v1, 0LL);
}

original_code:
void timer_init(timer **t)
{
 *t = (timer *) malloc(sizeof(timer));
 gettimeofday(*t, ((void *)0));
}

canonical_original_code:
void timer_init(struct timeval **t)
{
 *t = (struct timeval *) malloc(sizeof(timer));
 gettimeofday(*t, ((void *)0));
}

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

return_type: void


decompiled_code:
__int64 __fastcall timer_elapsed(_DWORD *a1)
{
int v1; // eax
int v2; // edx
int v3; // ecx
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v5, 0LL);
v1 = LODWORD(v5.tv_sec) - *a1;
v2 = LODWORD(v5.tv_usec) - a1[2];
v3 = v2;
if ( v2 < 0 )
{
v3 = v2 + 1000000;
--v1;
}
return 1000 * v1 + v3 / 1000;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1)
{
int v1; // eax
int v2; // edx
int v3; // ecx
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v5, 0LL);
v1 = LODWORD(v5.tv_sec) - *a1;
v2 = LODWORD(v5.tv_usec) - a1[2];
v3 = v2;
if ( v2 < 0 )
{
v3 = v2 + 1000000;
--v1;
}
return 1000 * v1 + v3 / 1000;
}

original_code:
unsigned long int timer_elapsed(timer *t)
{
    timer CurrentTime;
    int sec,usec;
    gettimeofday(&CurrentTime, ((void *)0));
    sec=CurrentTime.tv_sec - t->tv_sec;
    usec=CurrentTime.tv_usec - t->tv_usec;
    if (usec<0) {
        usec=1000000-t->tv_usec + CurrentTime.tv_usec;
        sec--;
    }
    return sec*1000+usec/1000;
}

canonical_original_code:
unsigned long timer_elapsed(struct timeval *t)
{
    struct timeval CurrentTime;
    int sec; int usec;
    gettimeofday(&CurrentTime, ((void *)0));
    sec=CurrentTime.tv_sec - t->tv_sec;
    usec=CurrentTime.tv_usec - t->tv_usec;
    if (usec<0) {
        usec=1000000-t->tv_usec + CurrentTime.tv_usec;
        sec--;
    }
    return sec*1000+usec/1000;
}

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

variable_types: sec int

variable_types: usec int

return_type: unsigned long


main

canonical_name: main

repo: mrstegeman/fireworks

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
float *v4; // rbx
void *v5; // rbp
void *v6; // r12
void *v7; // r13
double v8; // xmm0_8
struct timespec v10; // [rsp+0h] [rbp-38h] BYREF

v10.tv_sec = 0LL;
v10.tv_nsec = 25000000LL;
ncurses_init();
v3 = time(0LL);
srand(v3);
v4 = (float *)calloc(0x20uLL, 0xC8uLL);
v5 = calloc(0x20uLL, 0xC8uLL);
v6 = calloc(0x20uLL, 0xC8uLL);
v7 = calloc(0x20uLL, 0xC8uLL);
particle_init(v4, 200LL);
particle_init(v5, 200LL);
particle_init(v6, 200LL);
particle_init(v7, 200LL);
while ( wgetch(stdscr) != 113 )
{
v8 = v4[6];
if ( v8 < 1.21 && v8 > 1.19 )
{
particle_init(v5, 200LL);
}
else if ( v8 < 0.8100000000000001 && v8 > 0.79 )
{
particle_init(v6, 200LL);
}
else if ( v8 >= 0.41 || v8 <= 0.39 )
{
if ( v8 < 0.01 )
particle_init(v4, 200LL);
}
else
{
particle_init(v7, 200LL);
}
werase(stdscr);
particle_update(v4, 200LL, 0.0099999998);
particle_update(v5, 200LL, 0.0099999998);
particle_update(v6, 200LL, 0.0099999998);
particle_update(v7, 200LL, 0.0099999998);
particle_draw(v4, 200LL);
particle_draw(v5, 200LL);
particle_draw(v6, 200LL);
particle_draw(v7, 200LL);
wrefresh(stdscr);
nanosleep(&v10, 0LL);
}
free(v4);
free(v5);
free(v6);
free(v7);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
float *v4; // rbx
void *v5; // rbp
void *v6; // r12
void *v7; // r13
double v8; // xmm0_8
struct timespec v10; // [rsp+0h] [rbp-38h] BYREF

v10.tv_sec = 0LL;
v10.tv_nsec = 25000000LL;
func0();
v3 = time(0LL);
srand(v3);
v4 = (float *)calloc(0x20uLL, 0xC8uLL);
v5 = calloc(0x20uLL, 0xC8uLL);
v6 = calloc(0x20uLL, 0xC8uLL);
v7 = calloc(0x20uLL, 0xC8uLL);
particle_init(v4, 200LL);
particle_init(v5, 200LL);
particle_init(v6, 200LL);
particle_init(v7, 200LL);
while ( wgetch(stdscr) != 113 )
{
v8 = v4[6];
if ( v8 < 1.21 && v8 > 1.19 )
{
particle_init(v5, 200LL);
}
else if ( v8 < 0.8100000000000001 && v8 > 0.79 )
{
particle_init(v6, 200LL);
}
else if ( v8 >= 0.41 || v8 <= 0.39 )
{
if ( v8 < 0.01 )
particle_init(v4, 200LL);
}
else
{
particle_init(v7, 200LL);
}
werase(stdscr);
particle_update(v4, 200LL, 0.0099999998);
particle_update(v5, 200LL, 0.0099999998);
particle_update(v6, 200LL, 0.0099999998);
particle_update(v7, 200LL, 0.0099999998);
particle_draw(v4, 200LL);
particle_draw(v5, 200LL);
particle_draw(v6, 200LL);
particle_draw(v7, 200LL);
wrefresh(stdscr);
nanosleep(&v10, 0LL);
}
free(v4);
free(v5);
free(v6);
free(v7);
endwin();
return 0;
}

original_code:
int main() {
    struct timespec interval = { .tv_sec = 0, .tv_nsec = 25000000 };
    size_t size = 200;
    ncurses_init();
    srand((unsigned) time(((void *)0)));
    particle *p = (particle *) calloc(sizeof(particle), size);
    particle *q = (particle *) calloc(sizeof(particle), size);
    particle *r = (particle *) calloc(sizeof(particle), size);
    particle *s = (particle *) calloc(sizeof(particle), size);
    particle_init(p, size);
    particle_init(q, size);
    particle_init(r, size);
    particle_init(s, size);
    while (wgetch(stdscr) != 'q') {
        if (p[0].life < 1.21 && p[0].life > 1.19) {
            particle_init(q, size);
        } else if (p[0].life < 0.81 && p[0].life > 0.79) {
            particle_init(r, size);
        } else if (p[0].life < 0.41 && p[0].life > 0.39) {
            particle_init(s, size);
        } else if (p[0].life < 0.01) {
            particle_init(p, size);
        }
        werase(stdscr);
        particle_update(p, 0.01, size);
        particle_update(q, 0.01, size);
        particle_update(r, 0.01, size);
        particle_update(s, 0.01, size);
        particle_draw(p, size);
        particle_draw(q, size);
        particle_draw(r, size);
        particle_draw(s, size);
        wrefresh(stdscr);
        nanosleep(&interval, ((void *)0));
    }
    free(p);
    p = ((void *)0);
    free(q);
    q = ((void *)0);
    free(r);
    r = ((void *)0);
    free(s);
    s = ((void *)0);
    endwin();
    return 0;
}

canonical_original_code:
int main() {
    struct timespec interval = { .tv_sec = 0, .tv_nsec = 25000000 };
    unsigned long size = 200;
    ncurses_init();
    srand((unsigned int) time(((void *)0)));
    struct particle_t *p = (particle *) calloc(sizeof(particle), size);
    struct particle_t *q = (particle *) calloc(sizeof(particle), size);
    struct particle_t *r = (particle *) calloc(sizeof(particle), size);
    struct particle_t *s = (particle *) calloc(sizeof(particle), size);
    particle_init(p, size);
    particle_init(q, size);
    particle_init(r, size);
    particle_init(s, size);
    while (wgetch(stdscr) != 'q') {
        if (p[0].life < 1.21 && p[0].life > 1.19) {
            particle_init(q, size);
        } else if (p[0].life < 0.81 && p[0].life > 0.79) {
            particle_init(r, size);
        } else if (p[0].life < 0.41 && p[0].life > 0.39) {
            particle_init(s, size);
        } else if (p[0].life < 0.01) {
            particle_init(p, size);
        }
        werase(stdscr);
        particle_update(p, 0.01, size);
        particle_update(q, 0.01, size);
        particle_update(r, 0.01, size);
        particle_update(s, 0.01, size);
        particle_draw(p, size);
        particle_draw(q, size);
        particle_draw(r, size);
        particle_draw(s, size);
        wrefresh(stdscr);
        nanosleep(&interval, ((void *)0));
    }
    free(p);
    p = ((void *)0);
    free(q);
    q = ((void *)0);
    free(r);
    r = ((void *)0);
    free(s);
    s = ((void *)0);
    endwin();
    return 0;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types:
size
unsigned long

variable_types: struct particle_t { float pos[2]; float center[2]; float vel[2]; float life; unsigned char color; _Bool exploded; } *


decompiled_code:
__int64 __fastcall particle_init(__int64 a1, __int64 a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm3
int v4; // ebx
int v5; // ebp
int v6; // eax
__int64 result; // rax
int v8; // edx

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)((float)rand() * 4.6566129e-10) * (float)-LINES;
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)(COERCE_FLOAT(_mm_cvtsi128_si32(v2)) - (float)(LINES / (rand() % 4 + 1))) * 0.8;
v4 = _mm_cvtsi128_si32(v3);
v5 = rand() % 8;
v6 = rand();
v8 = v6 % COLS;
result = (unsigned int)(v6 / COLS);
if ( a2 )
{
result = a1;
do
{
*(float *)result = (float)(LINES - 1);
*(float *)(result + 4) = (float)v8;
*(_DWORD *)(result + 16) = v4;
*(_DWORD *)(result + 20) = 0;
*(_DWORD *)(result + 24) = LC3;
*(_BYTE *)(result + 28) = v5;
*(_BYTE *)(result + 29) = 0;
result += 32LL;
}
while ( result != 32 * a2 + a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm3
int v4; // ebx
int v5; // ebp
int v6; // eax
__int64 result; // rax
int v8; // edx

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)((float)rand() * 4.6566129e-10) * (float)-LINES;
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)(COERCE_FLOAT(_mm_cvtsi128_si32(v2)) - (float)(LINES / (rand() % 4 + 1))) * 0.8;
v4 = _mm_cvtsi128_si32(v3);
v5 = rand() % 8;
v6 = rand();
v8 = v6 % COLS;
result = (unsigned int)(v6 / COLS);
if ( a2 )
{
result = a1;
do
{
*(float *)result = (float)(LINES - 1);
*(float *)(result + 4) = (float)v8;
*(_DWORD *)(result + 16) = v4;
*(_DWORD *)(result + 20) = 0;
*(_DWORD *)(result + 24) = LC3;
*(_BYTE *)(result + 28) = v5;
*(_BYTE *)(result + 29) = 0;
result += 32LL;
}
while ( result != 32 * a2 + a1 );
}
return result;
}

original_code:
void particle_init(particle *p, size_t size) {
    float init_vel, col;
    size_t i;
    uint8_t init_color;
    init_vel = (((float) rand()) / ((float) 2147483647) * (-LINES) - (LINES / (rand() % 4 + 1))) * 0.8;
    init_color = (uint8_t) (rand() % 8);
    col = rand() % COLS;
    for (i = 0; i < size; ++i) {
        p[i].pos[0] = (float) (LINES - 1);
        p[i].pos[1] = col;
        p[i].vel[0] = init_vel;
        p[i].vel[1] = 0.0;
        p[i].life = 1.6;
        p[i].color = init_color;
        p[i].exploded = 0;
    }
}

canonical_original_code:
void particle_init(struct particle_t *p, unsigned long size) {
    float init_vel; float col;
    unsigned long i;
    unsigned char init_color;
    init_vel = (((float) rand()) / ((float) 2147483647) * (-LINES) - (LINES / (rand() % 4 + 1))) * 0.8;
    init_color = (unsigned char) (rand() % 8);
    col = rand() % COLS;
    for (i = 0; i < size; ++i) {
        p[i].pos[0] = (float) (LINES - 1);
        p[i].pos[1] = col;
        p[i].vel[0] = init_vel;
        p[i].vel[1] = 0.0;
        p[i].life = 1.6;
        p[i].color = init_color;
        p[i].exploded = 0;
    }
}

variable_types: col float

variable_types:
i
unsigned long

user_defined_types: struct particle_t { float pos[2]; float center[2]; float vel[2]; float life; unsigned char color; _Bool exploded; }


original_code:
void particle_update(particle *p, float dt, size_t size) {
    size_t i;
    for (i = 0; i < size; ++i) {
        p[i].life -= dt;
        p[i].pos[0] += p[i].vel[0] * dt;
        p[i].pos[1] += p[i].vel[1] * dt;
        if (p[i].life < 0.76 && !p[i].exploded) {
            p[i].exploded = 1;
            p[i].center[0] = p[i].pos[0];
            p[i].center[1] = p[i].pos[1];
            p[i].vel[0] = ((float) rand() / (float) 2147483647) * 50 - 25;
            p[i].vel[1] = ((float) rand() / (float) 2147483647) * 100 - 50;
        }
    }
}

canonical_original_code:
void particle_update(struct particle_t *p, float dt, unsigned long size) {
    unsigned long i;
    for (i = 0; i < size; ++i) {
        p[i].life -= dt;
        p[i].pos[0] += p[i].vel[0] * dt;
        p[i].pos[1] += p[i].vel[1] * dt;
        if (p[i].life < 0.76 && !p[i].exploded) {
            p[i].exploded = 1;
            p[i].center[0] = p[i].pos[0];
            p[i].center[1] = p[i].pos[1];
            p[i].vel[0] = ((float) rand() / (float) 2147483647) * 50 - 25;
            p[i].vel[1] = ((float) rand() / (float) 2147483647) * 100 - 50;
        }
    }
}

variable_types: dt float


variable_types: distance float


decompiled_code:
__int64 __fastcall do_register(int fd)
{
__int64 result; // rax
int v2[266]; // [rsp+0h] [rbp-428h] BYREF

v2[0] = 100;
printf("Input username : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
printf("Input password : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
send(fd, v2, 0x408uLL, 0);
usleep(0xC8u);
memset(v2, 0, 0x408uLL);
recv(fd, v2, 0x408uLL, 0);
if ( v2[1] == 10 )
{
puts((const char *)&v2[2]);
result = 0LL;
}
else if ( v2[1] == 20 )
{
puts((const char *)&v2[2]);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd)
{
__int64 result; // rax
int v2[266]; // [rsp+0h] [rbp-428h] BYREF

v2[0] = 100;
printf("Input username : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
printf("Input password : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
send(fd, v2, 0x408uLL, 0);
usleep(0xC8u);
memset(v2, 0, 0x408uLL);
recv(fd, v2, 0x408uLL, 0);
if ( v2[1] == 10 )
{
puts((const char *)&v2[2]);
result = 0LL;
}
else if ( v2[1] == 20 )
{
puts((const char *)&v2[2]);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int do_register(int sockfd)
{
 MSG msg;
 msg.type = 100;
 printf("Input username : ");
 scanf("%s",msg.content.u_info.name);
 while(getchar() != '\n');
 printf("Input password : ");
 scanf("%s",msg.content.u_info.password);
 while(getchar() != '\n');
 send(sockfd,&msg,sizeof(msg),0);
 usleep(200);
 bzero(&msg,sizeof(msg));
 recv(sockfd,&msg,sizeof(msg),0);
 switch(msg._errno)
 {
 case 10:
  printf("%s\n",msg.content.buf);
  break;
 case 20:
  printf("%s\n",msg.content.buf);
  return -1;
 }
 return 0;
}

canonical_original_code:
int do_register(int sockfd)
{
 struct MSG msg;
 msg.type = 100;
 printf("Input username : ");
 scanf("%s",msg.content.u_info.name);
 while(getchar() != '\n');
 printf("Input password : ");
 scanf("%s",msg.content.u_info.password);
 while(getchar() != '\n');
 send(sockfd,&msg,sizeof(msg),0);
 usleep(200);
 bzero(&msg,sizeof(msg));
 recv(sockfd,&msg,sizeof(msg),0);
 switch(msg._errno)
 {
 case 10:
  printf("%s\n",msg.content.buf);
  break;
 case 20:
  printf("%s\n",msg.content.buf);
  return -1;
 }
 return 0;
}

variable_types: sockfd int

variable_types: struct MSG { int type; int _errno; union { struct user_info { char name[15]; char password[20]; } u_info; char buf[1024]; } content; }

user_defined_types: struct MSG { int type; int _errno; union { struct user_info u_info; char buf[1024]; } content; }


decompiled_code:
__int64 __fastcall do_login(int fd)
{
__int64 result; // rax
int v2[266]; // [rsp+0h] [rbp-428h] BYREF

v2[0] = 200;
printf("Input username : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
printf("Input password : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
send(fd, v2, 0x408uLL, 0);
usleep(0xC8u);
memset(v2, 0, 0x408uLL);
recv(fd, v2, 0x408uLL, 0);
if ( v2[1] == 10 )
{
puts((const char *)&v2[2]);
result = 0LL;
}
else if ( v2[1] == 30 )
{
puts((const char *)&v2[2]);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd)
{
__int64 result; // rax
int v2[266]; // [rsp+0h] [rbp-428h] BYREF

v2[0] = 200;
printf("Input username : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
printf("Input password : ");
__isoc99_scanf();
while ( getchar() != 10 )
;
send(fd, v2, 0x408uLL, 0);
usleep(0xC8u);
memset(v2, 0, 0x408uLL);
recv(fd, v2, 0x408uLL, 0);
if ( v2[1] == 10 )
{
puts((const char *)&v2[2]);
result = 0LL;
}
else if ( v2[1] == 30 )
{
puts((const char *)&v2[2]);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int do_login(int sockfd)
{
 MSG msg;
 msg.type = 200;
 printf("Input username : ");
 scanf("%s",msg.content.u_info.name);
 while(getchar() != '\n');
 printf("Input password : ");
 scanf("%s",msg.content.u_info.password);
 while(getchar() != '\n');
 send(sockfd,&msg,sizeof(msg),0);
 usleep(200);
 bzero(&msg,sizeof(msg));
 recv(sockfd,&msg,sizeof(msg),0);
 switch(msg._errno)
 {
 case 10:
  printf("%s\n",msg.content.buf);
  break;
 case 30:
  printf("%s\n",msg.content.buf);
  return -1;
 }
 return 0;
}

canonical_original_code:
int do_login(int sockfd)
{
 struct MSG msg;
 msg.type = 200;
 printf("Input username : ");
 scanf("%s",msg.content.u_info.name);
 while(getchar() != '\n');
 printf("Input password : ");
 scanf("%s",msg.content.u_info.password);
 while(getchar() != '\n');
 send(sockfd,&msg,sizeof(msg),0);
 usleep(200);
 bzero(&msg,sizeof(msg));
 recv(sockfd,&msg,sizeof(msg),0);
 switch(msg._errno)
 {
 case 10:
  printf("%s\n",msg.content.buf);
  break;
 case 30:
  printf("%s\n",msg.content.buf);
  return -1;
 }
 return 0;
}

user_defined_types: struct user_info { char name[15]; char password[20]; }


decompiled_code:
void __fastcall __noreturn do_word(int fd)
{
int v1[266]; // [rsp+0h] [rbp-428h] BYREF

while ( 1 )
{
printf("word>");
v1[0] = 300;
fgets((char *)&v1[2], 1024, stdin);
*((_BYTE *)&v1[1] + strlen((const char *)&v1[2]) + 3) = 0;
send(fd, v1, 0x408uLL, 0);
usleep(0xC8u);
memset(v1, 0, 0x408uLL);
recv(fd, v1, 0x408uLL, 0);
puts((const char *)&v1[2]);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func12(int fd)
{
int v1[266]; // [rsp+0h] [rbp-428h] BYREF

while ( 1 )
{
printf("word>");
v1[0] = 300;
fgets((char *)&v1[2], 1024, stdin);
*((_BYTE *)&v1[1] + strlen((const char *)&v1[2]) + 3) = 0;
send(fd, v1, 0x408uLL, 0);
usleep(0xC8u);
memset(v1, 0, 0x408uLL);
recv(fd, v1, 0x408uLL, 0);
puts((const char *)&v1[2]);
}
}

original_code:
int do_word(int sockfd)
{
 MSG msg;
 while(1)
 {
  printf("word>");
  msg.type = 300;
  fgets(msg.content.buf,sizeof(msg.content.buf),stdin);
  msg.content.buf[strlen(msg.content.buf) - 1] = '\0';
  send(sockfd,&msg,sizeof(msg),0);
  usleep(200);
  bzero(&msg,sizeof(msg));
  recv(sockfd,&msg,sizeof(msg),0);
  printf("%s\n",msg.content.buf);
 }
 return 0;
}

canonical_original_code:
int do_word(int sockfd)
{
 struct MSG msg;
 while(1)
 {
  printf("word>");
  msg.type = 300;
  fgets(msg.content.buf,sizeof(msg.content.buf),stdin);
  msg.content.buf[strlen(msg.content.buf) - 1] = '\0';
  send(sockfd,&msg,sizeof(msg),0);
  usleep(200);
  bzero(&msg,sizeof(msg));
  recv(sockfd,&msg,sizeof(msg),0);
  printf("%s\n",msg.content.buf);
 }
 return 0;
}


decompiled_code:
void __fastcall __noreturn do_task(int fd)
{
int v1; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
while ( 1 )
{
help_info();
printf("cmd>");
__isoc99_scanf();
if ( v1 == 2 )
break;
if ( v1 == 3 )
exit(0);
if ( v1 == 1 )
do_register(fd);
else
puts("Unknow cmd.");
}
if ( (int)do_login(fd) >= 0 )
do_word(fd);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func13(int fd)
{
int v1; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
while ( 1 )
{
func8();
printf("cmd>");
__isoc99_scanf();
if ( v1 == 2 )
break;
if ( v1 == 3 )
exit(0);
if ( v1 == 1 )
func10(fd);
else
puts("Unknow cmd.");
}
if ( (int)func11(fd) >= 0 )
func12(fd);
}
}

original_code:
int do_task(int sockfd)
{
 int cmd;
 while(1)
 {
  help_info();
  printf("cmd>");
  scanf("%d",&cmd);
  switch(cmd)
  {
   case 1:
    if(do_register(sockfd) < 0) continue;
    break;
   case 2:
    if(do_login(sockfd) < 0) continue;
    goto next;
    break;
   case 3:
    exit(0);
   default:
    printf("Unknow cmd.\n");
    continue;
  }
 }
next:
 do_word(sockfd);
 return 0;
}

variable_types: cmd int


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

if ( argc <= 2 )
{
fprintf(stderr, "Usage : %s argv[1].\n", *argv);
exit(1);
}
v3 = init_tcp((char *)argv[1], (char *)argv[2]);
do_task(v3);
}

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

if ( argc <= 2 )
{
fprintf(stderr, "Usage : %s argv[1].\n", *argv);
exit(1);
}
v3 = func9((char *)argv[1], (char *)argv[2]);
func13(v3);
}

original_code:
int main(int argc,char *argv[])
{
 int sockfd;
 int addr_len = sizeof(struct sockaddr);
 struct sockaddr_in peer_addr;
 if(argc < 3)
 {
  fprintf(stderr,"Usage : %s argv[1].\n",argv[0]);
  exit(1);
 }
 sockfd = init_tcp(argv[1],argv[2]);
 do_task(sockfd);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int sockfd;
 int addr_len = sizeof(struct sockaddr);
 struct sockaddr_in peer_addr;
 if(argc < 3)
 {
  fprintf(stderr,"Usage : %s argv[1].\n",argv[0]);
  exit(1);
 }
 sockfd = init_tcp(argv[1],argv[2]);
 do_task(sockfd);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

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

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


decompiled_code:
__int64 __fastcall init_tcp(char *cp, char *nptr)
{
int v2; // eax
unsigned int v3; // ebx
__int16 v4; // ax
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("Fail to socket");
exit(1);
}
v3 = v2;
v6.sa_family = 2;
*(_QWORD *)&v6.sa_data[6] = 0LL;
v4 = atoi(nptr);
*(_WORD *)v6.sa_data = _bswap_16(v4);
*(_DWORD *)&v6.sa_data[2] = inet_addr(cp);
if ( connect(v3, &v6, 0x10u) < 0 )
{
perror("Fail to bind");
exit(1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *cp, char *nptr)
{
int v2; // eax
unsigned int v3; // ebx
__int16 v4; // ax
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("Fail to socket");
exit(1);
}
v3 = v2;
v6.sa_family = 2;
*(_QWORD *)&v6.sa_data[6] = 0LL;
v4 = atoi(nptr);
*(_WORD *)v6.sa_data = func7(v4);
*(_DWORD *)&v6.sa_data[2] = inet_addr(cp);
if ( connect(v3, &v6, 0x10u) < 0 )
{
perror("Fail to bind");
exit(1);
}
return v3;
}

original_code:
int init_tcp(char *ip,char *port)
{
 int sockfd;
 struct sockaddr_in server_addr;
 if((sockfd = socket(2,SOCK_STREAM,0)) < 0)
 {
  perror("Fail to socket");
  exit(1);
 }
 bzero(&server_addr,sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_port = htons(atoi(port));
 server_addr.sin_addr.s_addr = inet_addr(ip);
 if(connect(sockfd,(struct sockaddr *)&server_addr,sizeof(server_addr)) < 0)
 {
  perror("Fail to bind");
  exit(1);
 }
 return sockfd;
}

canonical_original_code:
int init_tcp(char *ip, char *port)
{
 int sockfd;
 struct sockaddr_in server_addr;
 if((sockfd = socket(2,SOCK_STREAM,0)) < 0)
 {
  perror("Fail to socket");
  exit(1);
 }
 bzero(&server_addr,sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_port = htons(atoi(port));
 server_addr.sin_addr.s_addr = inet_addr(ip);
 if(connect(sockfd,(struct sockaddr *)&server_addr,sizeof(server_addr)) < 0)
 {
  perror("Fail to bind");
  exit(1);
 }
 return sockfd;
}

variable_types:
ip
char *

variable_types:
port
char *

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


decompiled_code:
void signal_handler()
{
waitpid(-1, 0LL, 1);
}

canonical_decompiled_code:
void func0()
{
waitpid(-1, 0LL, 1);
}

original_code:
void signal_handler(int signum)
{
 waitpid(-1,((void *)0),1);
 return ;
}

variable_types: signum int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
int v4; // ebp
int v5; // ebx
__pid_t v6; // eax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len; // [rsp+14h] [rbp-24h] BYREF
__int64 v9[4]; // [rsp+18h] [rbp-20h] BYREF

addr_len = 16;
if ( argc <= 2 )
{
fprintf(stderr, "Usage : %s argv[1].\n", *argv);
exit(1);
}
if ( signal(17, (__sighandler_t)signal_handler) != (__sighandler_t)-1LL )
{
if ( (unsigned int)sqlite3_open(argv[3], v9) )
{
v3 = (const char *)sqlite3_errmsg(v9[0]);
fprintf(stderr, "sqlite3 open %s : %s.\n", argv[3], v3);
exit(1);
}
v4 = init_tcp((char *)argv[1], (char *)argv[2]);
while ( 1 )
{
v5 = accept(v4, &v7, &addr_len);
if ( v5 < 0 )
break;
v6 = fork();
if ( v6 < 0 )
{
perror("Fail to fork");
exit(1);
}
if ( !v6 )
do_client((unsigned int)v5, v9[0]);
close(v5);
}
perror("Fail to accept");
exit(1);
}
perror("Fail to signal");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
int v4; // ebp
int v5; // ebx
__pid_t v6; // eax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len; // [rsp+14h] [rbp-24h] BYREF
__int64 v9[4]; // [rsp+18h] [rbp-20h] BYREF

addr_len = 16;
if ( argc <= 2 )
{
fprintf(stderr, "Usage : %s argv[1].\n", *argv);
exit(1);
}
if ( signal(17, (__sighandler_t)signal_handler) != (__sighandler_t)-1LL )
{
if ( (unsigned int)sqlite3_open(argv[3], v9) )
{
v3 = (const char *)sqlite3_errmsg(v9[0]);
fprintf(stderr, "sqlite3 open %s : %s.\n", argv[3], v3);
exit(1);
}
v4 = func2((char *)argv[1], (char *)argv[2]);
while ( 1 )
{
v5 = accept(v4, &v7, &addr_len);
if ( v5 < 0 )
break;
v6 = fork();
if ( v6 < 0 )
{
perror("Fail to fork");
exit(1);
}
if ( !v6 )
do_client((unsigned int)v5, v9[0]);
close(v5);
}
perror("Fail to accept");
exit(1);
}
perror("Fail to signal");
exit(1);
}


decompiled_code:
__int64 __fastcall do_register(int fd, __int64 a2, const char *a3, const char *a4)
{
__int64 v7[129]; // [rsp+0h] [rbp-858h] BYREF
char v8[4]; // [rsp+408h] [rbp-450h] BYREF
int v9; // [rsp+40Ch] [rbp-44Ch] BYREF
__int64 v10; // [rsp+410h] [rbp-448h] BYREF
const char *v11; // [rsp+418h] [rbp-440h] BYREF
int buf; // [rsp+420h] [rbp-438h] BYREF
int v13; // [rsp+424h] [rbp-434h]
char v14[40]; // [rsp+428h] [rbp-430h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
memset(&v7[2], 0, 0x3F0uLL);
sprintf((char *)v7, "select * from user_table where NAME='%s';", a3);
if ( (unsigned int)((__int64 (__fastcall *)(__int64, __int64 *, __int64 *, int *, char *, const char **))sqlite3_get_table)(
a2,
v7,
&v10,
&v9,
v8,
&v11) )
{
fprintf(stderr, "sqlite3 get table error : %s.\n", v11);
exit(1);
}
if ( v9 )
{
buf = 100;
v13 = 20;
strcpy(v14, "Register fail,The username is EEXIST.");
send(fd, &buf, 0x408uLL, 0);
}
else
{
memset(v7, 0, 0x400uLL);
sprintf((char *)v7, "insert into user_table values('%s','%s');", a3, a4);
if ( (int)sqlite3_exec(a2, v7, 0LL, 0LL, &v11) < 0 )
{
fprintf(stderr, "sqlite3 execl [%s] error : %s.\n", (const char *)v7, v11);
exit(1);
}
buf = 100;
v13 = 10;
strcpy(v14, "Register success !");
send(fd, &buf, 0x408uLL, 0);
}
sqlite3_free_table(v10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, const char *a3, const char *a4)
{
__int64 v7[129]; // [rsp+0h] [rbp-858h] BYREF
char v8[4]; // [rsp+408h] [rbp-450h] BYREF
int v9; // [rsp+40Ch] [rbp-44Ch] BYREF
__int64 v10; // [rsp+410h] [rbp-448h] BYREF
const char *v11; // [rsp+418h] [rbp-440h] BYREF
int buf; // [rsp+420h] [rbp-438h] BYREF
int v13; // [rsp+424h] [rbp-434h]
char v14[40]; // [rsp+428h] [rbp-430h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
memset(&v7[2], 0, 0x3F0uLL);
sprintf((char *)v7, "select * from user_table where NAME='%s';", a3);
if ( (unsigned int)((__int64 (__fastcall *)(__int64, __int64 *, __int64 *, int *, char *, const char **))sqlite3_get_table)(
a2,
v7,
&v10,
&v9,
v8,
&v11) )
{
fprintf(stderr, "sqlite3 get table error : %s.\n", v11);
exit(1);
}
if ( v9 )
{
buf = 100;
v13 = 20;
strcpy(v14, "Register fail,The username is EEXIST.");
send(fd, &buf, 0x408uLL, 0);
}
else
{
memset(v7, 0, 0x400uLL);
sprintf((char *)v7, "insert into user_table values('%s','%s');", a3, a4);
if ( (int)sqlite3_exec(a2, v7, 0LL, 0LL, &v11) < 0 )
{
fprintf(stderr, "sqlite3 execl [%s] error : %s.\n", (const char *)v7, v11);
exit(1);
}
buf = 100;
v13 = 10;
strcpy(v14, "Register success !");
send(fd, &buf, 0x408uLL, 0);
}
sqlite3_free_table(v10);
return 0LL;
}


decompiled_code:
__int64 __fastcall do_login(int fd, __int64 a2, const char *a3, const char *a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-848h] BYREF
char v6[1008]; // [rsp+10h] [rbp-838h] BYREF
char v7[4]; // [rsp+408h] [rbp-440h] BYREF
int v8; // [rsp+40Ch] [rbp-43Ch] BYREF
__int64 v9; // [rsp+410h] [rbp-438h] BYREF
const char *v10; // [rsp+418h] [rbp-430h] BYREF
int buf; // [rsp+420h] [rbp-428h] BYREF
int v12; // [rsp+424h] [rbp-424h]
char v13[32]; // [rsp+428h] [rbp-420h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
sprintf((char *)v5, "select * from user_table where NAME='%s' and PASSWORD='%s';", a3, a4);
if ( (unsigned int)((__int64 (__fastcall *)(__int64, __int64 *, __int64 *, int *, char *, const char **))sqlite3_get_table)(
a2,
v5,
&v9,
&v8,
v7,
&v10) )
{
fprintf(stderr, "sqlite3 get table error : %s.\n", v10);
exit(1);
}
buf = 200;
if ( v8 )
{
v12 = 10;
strcpy(v13, "Login success.");
}
else
{
v12 = 30;
strcpy(v13, "The username or password error!");
}
send(fd, &buf, 0x408uLL, 0);
sqlite3_free_table(v9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2, const char *a3, const char *a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-848h] BYREF
char v6[1008]; // [rsp+10h] [rbp-838h] BYREF
char v7[4]; // [rsp+408h] [rbp-440h] BYREF
int v8; // [rsp+40Ch] [rbp-43Ch] BYREF
__int64 v9; // [rsp+410h] [rbp-438h] BYREF
const char *v10; // [rsp+418h] [rbp-430h] BYREF
int buf; // [rsp+420h] [rbp-428h] BYREF
int v12; // [rsp+424h] [rbp-424h]
char v13[32]; // [rsp+428h] [rbp-420h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
sprintf((char *)v5, "select * from user_table where NAME='%s' and PASSWORD='%s';", a3, a4);
if ( (unsigned int)((__int64 (__fastcall *)(__int64, __int64 *, __int64 *, int *, char *, const char **))sqlite3_get_table)(
a2,
v5,
&v9,
&v8,
v7,
&v10) )
{
fprintf(stderr, "sqlite3 get table error : %s.\n", v10);
exit(1);
}
buf = 200;
if ( v8 )
{
v12 = 10;
strcpy(v13, "Login success.");
}
else
{
v12 = 30;
strcpy(v13, "The username or password error!");
}
send(fd, &buf, 0x408uLL, 0);
sqlite3_free_table(v9);
return 0LL;
}


decompiled_code:
__int64 __fastcall do_word(int fd, __int64 a2, const char *a3)
{
__int64 v4[2]; // [rsp+0h] [rbp-848h] BYREF
char v5[1008]; // [rsp+10h] [rbp-838h] BYREF
int v6; // [rsp+408h] [rbp-440h] BYREF
int v7; // [rsp+40Ch] [rbp-43Ch] BYREF
__int64 v8; // [rsp+410h] [rbp-438h] BYREF
const char *v9; // [rsp+418h] [rbp-430h] BYREF
int buf; // [rsp+420h] [rbp-428h] BYREF
int v11; // [rsp+424h] [rbp-424h]
char dest[14]; // [rsp+428h] [rbp-420h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
memset(v5, 0, sizeof(v5));
sprintf((char *)v4, "select * from word_table where WORD='%s';", a3);
if ( (unsigned int)((__int64 (__fastcall *)(__int64, __int64 *, __int64 *, int *, int *, const char **))sqlite3_get_table)(
a2,
v4,
&v8,
&v7,
&v6,
&v9) )
{
fprintf(stderr, "sqlite3 get table error : %s.\n", v9);
exit(1);
}
buf = 300;
if ( v7 )
{
v11 = 10;
strcpy(dest, *(const char **)(v8 + 8LL * v6 + 8));
}
else
{
v11 = 30;
strcpy(dest, "No such word ");
}
send(fd, &buf, 0x408uLL, 0);
sqlite3_free_table(v8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2, const char *a3)
{
__int64 v4[2]; // [rsp+0h] [rbp-848h] BYREF
char v5[1008]; // [rsp+10h] [rbp-838h] BYREF
int v6; // [rsp+408h] [rbp-440h] BYREF
int v7; // [rsp+40Ch] [rbp-43Ch] BYREF
__int64 v8; // [rsp+410h] [rbp-438h] BYREF
const char *v9; // [rsp+418h] [rbp-430h] BYREF
int buf; // [rsp+420h] [rbp-428h] BYREF
int v11; // [rsp+424h] [rbp-424h]
char dest[14]; // [rsp+428h] [rbp-420h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
memset(v5, 0, sizeof(v5));
sprintf((char *)v4, "select * from word_table where WORD='%s';", a3);
if ( (unsigned int)((__int64 (__fastcall *)(__int64, __int64 *, __int64 *, int *, int *, const char **))sqlite3_get_table)(
a2,
v4,
&v8,
&v7,
&v6,
&v9) )
{
fprintf(stderr, "sqlite3 get table error : %s.\n", v9);
exit(1);
}
buf = 300;
if ( v7 )
{
v11 = 10;
strcpy(dest, *(const char **)(v8 + 8LL * v6 + 8));
}
else
{
v11 = 30;
strcpy(dest, "No such word ");
}
send(fd, &buf, 0x408uLL, 0);
sqlite3_free_table(v8);
return 0LL;
}


checkFilename

repo: msantl/MREPRO

decompiled_code:
__int64 __fastcall checkFilename(_BYTE *a1, int a2)
{
_BYTE *v2; // rax

if ( a2 <= 0 )
return 1LL;
v2 = a1;
while ( *v2 != 47 )
{
if ( ++v2 == &a1[a2 - 1 + 1] )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1, int a2)
{
_BYTE *v2; // rax

if ( a2 <= 0 )
return 1LL;
v2 = a1;
while ( *v2 != 47 )
{
if ( ++v2 == &a1[a2 - 1 + 1] )
return 1LL;
}
return 0LL;
}

original_code:
int checkFilename(char *ptr, int len) {
  int i;
  for (i = 0; i < len; ++i) {
    if (ptr[i] == '/') {
    return 0;
    }
  }
  return 1;
}

variable_types:
ptr
char *

variable_types: len int

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // eax
int v5; // eax
int v6; // er12
const char *v7; // rax
__int64 v8; // rbp
int v9; // eax
int v10; // ebx
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-78h] BYREF
int v14; // [rsp+5Ch] [rbp-2Ch]

v3 = (char *)malloc(8uLL);
strcpy(v3, "1234");
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "p:");
if ( v4 == -1 )
break;
if ( v4 != 112 )
errx(1, "Usage: ./tcpserver [-p port]");
strcpy(v3, optarg);
}
if ( optind != argc )
errx(1, "Usage: ./tcpserver [-p port]");
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v5 = getaddrinfo(0LL, v3, &req, &pai);
if ( v5 )
{
v7 = gai_strerror(v5);
errx(1, v7);
}
if ( !pai )
errx(1, "getaddrinfo error");
v6 = Socket((unsigned int)pai->ai_family, (unsigned int)pai->ai_socktype, (unsigned int)pai->ai_protocol);
Bind(v6);
Listen(v6);
while ( 1 )
{
memset(&file, 0, 0x10000uLL);
memset(filename, 0, sizeof(filename));
v14 = 16;
v8 = (unsigned int)Accept(v6);
Recv(v8, filename, 0x10000LL, 0LL);
if ( !strcmp(filename, "Kraj") )
break;
v9 = strlen(filename);
if ( !(unsigned int)checkFilename(filename, v9) )
{
Close(v8);
errx(1, "Nedozvoljena putanja datoteke");
}
v10 = open(filename, 0);
if ( v10 < 0 )
errx(1, "open: datoteka ne postoji");
while ( (int)read(v10, &file, 0x10000uLL) > 0 )
{
WriteAll(v8, &file);
memset(&file, 0, 0x10000uLL);
}
close(v10);
Close(v8);
}
Close(v8);
Close(v6);
freeaddrinfo(pai);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // eax
int v5; // eax
int v6; // er12
const char *v7; // rax
__int64 v8; // rbp
int v9; // eax
int v10; // ebx
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-78h] BYREF
int v14; // [rsp+5Ch] [rbp-2Ch]

v3 = (char *)malloc(8uLL);
strcpy(v3, "1234");
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "p:");
if ( v4 == -1 )
break;
if ( v4 != 112 )
errx(1, "Usage: ./tcpserver [-p port]");
strcpy(v3, optarg);
}
if ( optind != argc )
errx(1, "Usage: ./tcpserver [-p port]");
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v5 = getaddrinfo(0LL, v3, &req, &pai);
if ( v5 )
{
v7 = gai_strerror(v5);
errx(1, v7);
}
if ( !pai )
errx(1, "getaddrinfo error");
v6 = func8((unsigned int)pai->ai_family, (unsigned int)pai->ai_socktype, (unsigned int)pai->ai_protocol);
func10(v6);
func13(v6);
while ( 1 )
{
memset(&file, 0, 0x10000uLL);
memset(filename, 0, sizeof(filename));
v14 = 16;
v8 = (unsigned int)func12(v6);
func17(v8, filename, 0x10000LL, 0LL);
if ( !strcmp(filename, "Kraj") )
break;
v9 = strlen(filename);
if ( !(unsigned int)func7(filename, v9) )
{
func9(v8);
errx(1, "Nedozvoljena putanja datoteke");
}
v10 = open(filename, 0);
if ( v10 < 0 )
errx(1, "open: datoteka ne postoji");
while ( (int)read(v10, &file, 0x10000uLL) > 0 )
{
func14(v8, &file);
memset(&file, 0, 0x10000uLL);
}
close(v10);
func9(v8);
}
func9(v8);
func9(v6);
freeaddrinfo(pai);
free(v3);
return 0;
}

original_code:
int main(int argc, char** argv) {
  int datoteka;
  int ch;
  int status;
  int sockfd, newfd;
  socklen_t server_l;
  struct sockaddr server;
  socklen_t client_l;
  struct sockaddr client;
  struct addrinfo hints, *res;
  char* port = (char *)malloc(sizeof(char) * 8);
  strcpy(port, "1234");
  while ((ch = getopt(argc, argv, "p:")) != -1) {
    switch(ch) {
      case 'p':
        strcpy(port, optarg);
        break;
      default:
        errx(1, "Usage: ./tcpserver [-p port]");
        break;
    }
  }
  if (argc - optind != 0) {
    errx(1, "Usage: ./tcpserver [-p port]");
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(((void *)0), port, &hints, &res)) != 0) {
    errx(1, gai_strerror(status));
  } else if (res == ((void *)0)) {
    errx(1, "getaddrinfo error");
  }
  sockfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  server = *(res->ai_addr);
  server_l = sizeof(server);
  Bind(sockfd, res->ai_addr, res->ai_addrlen);
  Listen(sockfd, 10);
  while (1) {
    memset(file, 0, sizeof file);
    memset(filename, 0, sizeof filename);
    client_l = sizeof(client);
    newfd = Accept(sockfd, &client, &client_l);
    Recv(newfd, filename, sizeof(filename), 0);
    if (strcmp(filename, "Kraj") == 0) {
      Close(newfd);
      break;
    } else if (checkFilename(filename, strlen(filename)) == 0) {
      Close(newfd);
      errx(1, "Nedozvoljena putanja datoteke");
    } else {
      datoteka = open(filename, 00);
      if (datoteka < 0) {
        errx(1, "open: datoteka ne postoji");
      }
      while ((status = read(datoteka, file, sizeof(file))) > 0) {
        WriteAll(newfd, file, status);
        memset(file, 0, sizeof(file));
      }
      close(datoteka);
      Close(newfd);
    }
  }
  Close(sockfd);
  freeaddrinfo(res);
  free(port);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int datoteka;
  int ch;
  int status;
  int sockfd; int newfd;
  unsigned int server_l;
  struct sockaddr server;
  unsigned int client_l;
  struct sockaddr client;
  struct addrinfo hints; struct addrinfo *res;
  char *port = (char *)malloc(sizeof(char) * 8);
  strcpy(port, "1234");
  while ((ch = getopt(argc, argv, "p:")) != -1) {
    switch(ch) {
      case 'p':
        strcpy(port, optarg);
        break;
      default:
        errx(1, "Usage: ./tcpserver [-p port]");
        break;
    }
  }
  if (argc - optind != 0) {
    errx(1, "Usage: ./tcpserver [-p port]");
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(((void *)0), port, &hints, &res)) != 0) {
    errx(1, gai_strerror(status));
  } else if (res == ((void *)0)) {
    errx(1, "getaddrinfo error");
  }
  sockfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  server = *(res->ai_addr);
  server_l = sizeof(server);
  Bind(sockfd, res->ai_addr, res->ai_addrlen);
  Listen(sockfd, 10);
  while (1) {
    memset(file, 0, sizeof file);
    memset(filename, 0, sizeof filename);
    client_l = sizeof(client);
    newfd = Accept(sockfd, &client, &client_l);
    Recv(newfd, filename, sizeof(filename), 0);
    if (strcmp(filename, "Kraj") == 0) {
      Close(newfd);
      break;
    } else if (checkFilename(filename, strlen(filename)) == 0) {
      Close(newfd);
      errx(1, "Nedozvoljena putanja datoteke");
    } else {
      datoteka = open(filename, 00);
      if (datoteka < 0) {
        errx(1, "open: datoteka ne postoji");
      }
      while ((status = read(datoteka, file, sizeof(file))) > 0) {
        WriteAll(newfd, file, status);
        memset(file, 0, sizeof(file));
      }
      close(datoteka);
      Close(newfd);
    }
  }
  Close(sockfd);
  freeaddrinfo(res);
  free(port);
  return 0;
}

variable_types:
argv
char **

variable_types: datoteka int

variable_types: ch int

variable_types: status int

variable_types: newfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall file_last_change(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return LODWORD(v2.st_mtim.tv_sec);
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return LODWORD(v2.st_mtim.tv_sec);
}

original_code:
int file_last_change(char *filename) {
  struct stat fileState;
  int ftime;
  stat(filename, &fileState);
  ftime = (int)fileState.st_mtim.tv_sec;
  return ftime;
}

variable_types:
filename
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: ftime int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall file_size(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return LODWORD(v2.st_size);
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return LODWORD(v2.st_size);
}

original_code:
int file_size(char *filename) {
  struct stat fileState;
  int fsize;
  stat(filename, &fileState);
  fsize = (int)fileState.st_size;
  return fsize;
}

variable_types: fsize int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
_BOOL8 __fastcall file_exists(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

original_code:
int file_exists(char *filename) {
  struct stat fileState;
  return (stat(filename, &fileState) == 0);
}


Socket

decompiled_code:
__int64 __fastcall Socket(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
{
if ( !daemon_proc )
err(1, "socket error");
syslog(1, "Greska: socket error");
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
{
if ( !daemon_proc )
err(1, "socket error");
syslog(1, "Greska: socket error");
}
return (unsigned int)v3;
}

original_code:
int Socket(int domain, int type, int protocol) {
  int fd = socket(domain, type, protocol);
  if (fd < 0) {
    if (daemon_proc) {
      syslog(1, "Greska: socket error");
    } else {
      err(1, "socket error");
    }
  }
  return fd;
}

variable_types: domain int

variable_types: type int

variable_types: protocol int

variable_types: fd int


Close

decompiled_code:
int __fastcall Close(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
return close(a1);
}

original_code:
void Close(int sockfd) {
  close(sockfd);
}

variable_types: sockfd int


Bind

decompiled_code:
void __fastcall Bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( bind(a1, a2, a3) < 0 )
{
Close(a1);
if ( !daemon_proc )
err(1, "bind error");
syslog(1, "Greska: bind error");
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( bind(a1, a2, a3) < 0 )
{
func1(a1);
if ( !daemon_proc )
err(1, "bind error");
syslog(1, "Greska: bind error");
}
}

original_code:
void Bind(int sockfd, struct sockaddr* addr, socklen_t addr_len) {
  if (bind(sockfd, addr, addr_len) < 0) {
    Close(sockfd);
    if (daemon_proc) {
      syslog(1, "Greska: bind error");
    } else {
      err(1, "bind error");
    }
  }
}

canonical_original_code:
void Bind(int sockfd, struct sockaddr *addr, unsigned int addr_len) {
  if (bind(sockfd, addr, addr_len) < 0) {
    Close(sockfd);
    if (daemon_proc) {
      syslog(1, "Greska: bind error");
    } else {
      err(1, "bind error");
    }
  }
}

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


Connect

decompiled_code:
void __fastcall Connect(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( connect(a1, a2, a3) < 0 )
{
Close(a1);
if ( !daemon_proc )
err(1, "connect error");
syslog(1, "Greska: connect error");
}
}

canonical_decompiled_code:
void __fastcall func3(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( connect(a1, a2, a3) < 0 )
{
func1(a1);
if ( !daemon_proc )
err(1, "connect error");
syslog(1, "Greska: connect error");
}
}

original_code:
void Connect(int sockfd, struct sockaddr* addr, socklen_t addr_len) {
  if (connect(sockfd, addr, addr_len) < 0) {
    Close(sockfd);
    if (daemon_proc) {
      syslog(1, "Greska: connect error");
    } else {
      err(1, "connect error");
    }
  }
}

canonical_original_code:
void Connect(int sockfd, struct sockaddr *addr, unsigned int addr_len) {
  if (connect(sockfd, addr, addr_len) < 0) {
    Close(sockfd);
    if (daemon_proc) {
      syslog(1, "Greska: connect error");
    } else {
      err(1, "connect error");
    }
  }
}


Accept

decompiled_code:
__int64 __fastcall Accept(int a1, struct sockaddr *a2, socklen_t *a3)
{
int v3; // ebx

v3 = accept(a1, a2, a3);
if ( v3 < 0 )
{
Close(a1);
if ( !daemon_proc )
err(1, "accept error");
syslog(1, "Greska: accept error");
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, struct sockaddr *a2, socklen_t *a3)
{
int v3; // ebx

v3 = accept(a1, a2, a3);
if ( v3 < 0 )
{
func1(a1);
if ( !daemon_proc )
err(1, "accept error");
syslog(1, "Greska: accept error");
}
return (unsigned int)v3;
}

original_code:
int Accept(int sockfd, struct sockaddr* addr, socklen_t *addr_len) {
  int fd = accept(sockfd, addr, addr_len);
  if (fd < 0) {
    Close(sockfd);
    if (daemon_proc) {
      syslog(1, "Greska: accept error");
    } else {
      err(1, "accept error");
    }
  }
  return fd;
}

canonical_original_code:
int Accept(int sockfd, struct sockaddr *addr, unsigned int *addr_len) {
  int fd = accept(sockfd, addr, addr_len);
  if (fd < 0) {
    Close(sockfd);
    if (daemon_proc) {
      syslog(1, "Greska: accept error");
    } else {
      err(1, "accept error");
    }
  }
  return fd;
}


Listen

decompiled_code:
void __fastcall Listen(int a1, int a2)
{
if ( listen(a1, a2) < 0 )
{
Close(a1);
if ( !daemon_proc )
err(1, "listen error");
syslog(1, "Greska: listen error");
}
}

canonical_decompiled_code:
void __fastcall func5(int a1, int a2)
{
if ( listen(a1, a2) < 0 )
{
func1(a1);
if ( !daemon_proc )
err(1, "listen error");
syslog(1, "Greska: listen error");
}
}

original_code:
void Listen(int sockfd, int backlog) {
  if (listen(sockfd, backlog) < 0) {
    Close(sockfd);
    if (daemon_proc) {
      syslog(1, "Greska: listen error");
    } else {
      err(1, "listen error");
    }
  }
}

variable_types: backlog int


WriteAll

decompiled_code:
__int64 __fastcall WriteAll(int fd, void *buf, int a3)
{
unsigned int v3; // er14
int v5; // ebp
int v6; // eax
int v7; // ebx

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
do
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
{
if ( v6 < 0 && *_errno_location() == 4 )
{
v7 = 0;
}
else
{
if ( !daemon_proc )
errx(1, "write error");
syslog(1, "Greska: write error");
}
}
v5 -= v7;
buf = (char *)buf + v7;
}
while ( v5 > 0 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, void *buf, int a3)
{
unsigned int v3; // er14
int v5; // ebp
int v6; // eax
int v7; // ebx

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
do
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
{
if ( v6 < 0 && *_errno_location() == 4 )
{
v7 = 0;
}
else
{
if ( !daemon_proc )
errx(1, "write error");
syslog(1, "Greska: write error");
}
}
v5 -= v7;
buf = (char *)buf + v7;
}
while ( v5 > 0 );
}
return v3;
}

original_code:
int WriteAll(int sockfd, char *buff, int len) {
  int nleft, nwritten;
  nleft = len;
  while (nleft > 0) {
    if ( (nwritten = write(sockfd, buff, nleft)) <= 0) {
      if (nwritten < 0 && (*__errno_location ()) == 4) {
        nwritten = 0;
      } else {
        if (daemon_proc) {
          syslog(1, "Greska: write error");
        } else {
          errx(1, "write error");
        }
      }
    }
    nleft -= nwritten;
    buff += nwritten;
  }
  return len;
}

canonical_original_code:
int WriteAll(int sockfd, char *buff, int len) {
  int nleft; int nwritten;
  nleft = len;
  while (nleft > 0) {
    if ( (nwritten = write(sockfd, buff, nleft)) <= 0) {
      if (nwritten < 0 && (*__errno_location ()) == 4) {
        nwritten = 0;
      } else {
        if (daemon_proc) {
          syslog(1, "Greska: write error");
        } else {
          errx(1, "write error");
        }
      }
    }
    nleft -= nwritten;
    buff += nwritten;
  }
  return len;
}

variable_types:
buff
char *

variable_types: len int

variable_types: nleft int

variable_types: nwritten int


ReadAll

decompiled_code:
__int64 __fastcall ReadAll(int fd, void *buf, int a3)
{
int v3; // er14
int v5; // ebp
int v6; // eax
int v7; // ebx

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
while ( 1 )
{
v6 = read(fd, buf, v5);
v7 = v6;
if ( v6 < 0 )
{
if ( *_errno_location() == 4 )
{
v7 = 0;
}
else
{
if ( !daemon_proc )
errx(1, "read error");
syslog(1, "Greska: read error");
}
}
else if ( !v6 )
{
return (unsigned int)(v3 - v5);
}
v5 -= v7;
buf = (char *)buf + v7;
if ( v5 <= 0 )
return (unsigned int)(v3 - v5);
}
}
v5 = a3;
return (unsigned int)(v3 - v5);
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf, int a3)
{
int v3; // er14
int v5; // ebp
int v6; // eax
int v7; // ebx

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
while ( 1 )
{
v6 = read(fd, buf, v5);
v7 = v6;
if ( v6 < 0 )
{
if ( *_errno_location() == 4 )
{
v7 = 0;
}
else
{
if ( !daemon_proc )
errx(1, "read error");
syslog(1, "Greska: read error");
}
}
else if ( !v6 )
{
return (unsigned int)(v3 - v5);
}
v5 -= v7;
buf = (char *)buf + v7;
if ( v5 <= 0 )
return (unsigned int)(v3 - v5);
}
}
v5 = a3;
return (unsigned int)(v3 - v5);
}

original_code:
int ReadAll(int sockfd, char *buff, int len) {
  int nleft, nread;
  nleft = len;
  while (nleft > 0) {
    if ( (nread = read(sockfd, buff, nleft)) < 0) {
      if ((*__errno_location ()) == 4) {
        nread = 0;
      } else {
        if (daemon_proc) {
          syslog(1, "Greska: read error");
        } else {
          errx(1, "read error");
        }
      }
    } else if (nread == 0) {
      break;
    }
    nleft -= nread;
    buff += nread;
  }
  return (len - nleft);
}

canonical_original_code:
int ReadAll(int sockfd, char *buff, int len) {
  int nleft; int nread;
  nleft = len;
  while (nleft > 0) {
    if ( (nread = read(sockfd, buff, nleft)) < 0) {
      if ((*__errno_location ()) == 4) {
        nread = 0;
      } else {
        if (daemon_proc) {
          syslog(1, "Greska: read error");
        } else {
          errx(1, "read error");
        }
      }
    } else if (nread == 0) {
      break;
    }
    nleft -= nread;
    buff += nread;
  }
  return (len - nleft);
}

variable_types: nread int


Send

decompiled_code:
__int64 __fastcall Send(int a1, const void *a2, int a3, int a4)
{
int v4; // ebx

v4 = send(a1, a2, a3, a4);
if ( v4 < 0 )
{
if ( !daemon_proc )
errx(1, "send error");
syslog(1, "Greska: send error");
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, const void *a2, int a3, int a4)
{
int v4; // ebx

v4 = send(a1, a2, a3, a4);
if ( v4 < 0 )
{
if ( !daemon_proc )
errx(1, "send error");
syslog(1, "Greska: send error");
}
return (unsigned int)v4;
}

original_code:
int Send(int sockfd, char *buff, int len, int flags) {
  int status = send(sockfd, buff, len, flags);
  if (status < 0) {
    if (daemon_proc) {
      syslog(1, "Greska: send error");
    } else {
      errx(1, "send error");
    }
  }
  return status;
}

variable_types: flags int

variable_types: status int


Recv

decompiled_code:
__int64 __fastcall Recv(int a1, void *a2, int a3, int a4)
{
int v4; // ebx

v4 = recv(a1, a2, a3, a4);
if ( v4 < 0 )
{
if ( !daemon_proc )
errx(1, "recv error");
syslog(1, "Greska: recv error");
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, void *a2, int a3, int a4)
{
int v4; // ebx

v4 = recv(a1, a2, a3, a4);
if ( v4 < 0 )
{
if ( !daemon_proc )
errx(1, "recv error");
syslog(1, "Greska: recv error");
}
return (unsigned int)v4;
}

original_code:
int Recv(int sockfd, char *buff, int len, int flags) {
  int status = recv(sockfd, buff, len, flags);
  if (status < 0) {
    if (daemon_proc) {
      syslog(1, "Greska: recv  error");
    } else {
      errx(1, "recv error");
    }
  }
  return status;
}


decompiled_code:
__int64 __fastcall p_to_i(unsigned __int8 *a1, _DWORD *a2)
{
__int64 result; // rax

*a2 = 0;
for ( result = *a1; (_BYTE)result; result = *a1 )
{
*a2 = (char)result + 10 * *a2 - 48;
++a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1, _DWORD *a2)
{
__int64 result; // rax

*a2 = 0;
for ( result = *a1; (_BYTE)result; result = *a1 )
{
*a2 = (char)result + 10 * *a2 - 48;
++a1;
}
return result;
}

variable_types:
c
char *

variable_types:
i
int *


decompiled_code:
__suseconds_t my_getcurrtime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func11()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
uint64_t my_getcurrtime() {
  struct timeval tv;
  uint64_t curtime;
  gettimeofday(&tv, ((void *)0));
  curtime = tv.tv_sec * 1000000 + tv.tv_usec;
  return curtime;
}

canonical_original_code:
unsigned long my_getcurrtime() {
  struct timeval tv;
  unsigned long curtime;
  gettimeofday(&tv, ((void *)0));
  curtime = tv.tv_sec * 1000000 + tv.tv_usec;
  return curtime;
}

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

variable_types:
curtime
unsigned long


Socket

decompiled_code:
int __fastcall Socket(int a1, int a2, int a3)
{
int result; // eax

result = socket(a1, a2, a3);
if ( result < 0 )
errx(1, "Could not initialize socket");
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2, int a3)
{
int result; // eax

result = socket(a1, a2, a3);
if ( result < 0 )
errx(1, "Could not initialize socket");
return result;
}

original_code:
int Socket(int ai_family, int ai_socktype, int ai_protocol) {
  int fd = socket(ai_family, ai_socktype, ai_protocol);
  if (fd < 0) {
    errx(1, "Could not initialize socket");
  }
  return fd;
}


Bind

decompiled_code:
int __fastcall Bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
errx(1, "Could not bind to socket");
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
errx(1, "Could not bind to socket");
return result;
}

original_code:
void Bind(int sockfd, const struct sockaddr* myaddr, int addrlen) {
  int status = bind(sockfd, myaddr, addrlen);
  if (status < 0) {
    errx(1, "Could not bind to socket");
  }
  return;
}

canonical_original_code:
void Bind(int sockfd, struct sockaddr *myaddr, int addrlen) {
  int status = bind(sockfd, myaddr, addrlen);
  if (status < 0) {
    errx(1, "Could not bind to socket");
  }
  return;
}

variable_types: addrlen int


Close

decompiled_code:
int __fastcall Close(int fd)
{
shutdown(fd, 2);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
shutdown(fd, 2);
return close(fd);
}

original_code:
void Close(int sockfd) {
  shutdown(sockfd, SHUT_RDWR);
  close(sockfd);
}


Errx

decompiled_code:
void Errx(int a1, const char *a2, ...)
{
gcc_va_list ap; // [rsp+8h] [rbp-D0h] BYREF

va_start(ap, a2);
if ( !daemon_proc )
verrx(a1, a2, ap);
vsyslog(a1, a2, ap);
}

canonical_decompiled_code:
void func1(int a1, const char *a2, ...)
{
gcc_va_list ap; // [rsp+8h] [rbp-D0h] BYREF

va_start(ap, a2);
if ( !daemon_proc )
verrx(a1, a2, ap);
vsyslog(a1, a2, ap);
}

original_code:
void Errx(int status, char *format, ...) {
  va_list args;
  __builtin_va_start(args,format);
  if (daemon_proc) {
    vsyslog(status, format, args);
  } else {
    verrx(status, format, args);
  }
  __builtin_va_end(args);
}

canonical_original_code:
void Errx(int status, char *format, ...) {
  __builtin_va_list args;
  __builtin_va_start(args,format);
  if (daemon_proc) {
    vsyslog(status, format, args);
  } else {
    verrx(status, format, args);
  }
  __builtin_va_end(args);
}

variable_types:
format
char *


Warnx

decompiled_code:
void Warnx(char *fmt, ...)
{
gcc_va_list ap; // [rsp+8h] [rbp-D0h] BYREF

va_start(ap, fmt);
if ( daemon_proc )
vsyslog((int)&loc_4 + 2, fmt, ap);
else
vwarnx(fmt, ap);
}

canonical_decompiled_code:
void func11(char *fmt, ...)
{
gcc_va_list ap; // [rsp+8h] [rbp-D0h] BYREF

va_start(ap, fmt);
if ( daemon_proc )
vsyslog((int)&loc_4 + 2, fmt, ap);
else
vwarnx(fmt, ap);
}

original_code:
void Warnx(char *format, ...) {
  va_list args;
  __builtin_va_start(args,format);
  if (daemon_proc) {
    vsyslog(6, format, args);
  } else {
    vwarnx(format, args);
  }
  __builtin_va_end(args);
}

canonical_original_code:
void Warnx(char *format, ...) {
  __builtin_va_list args;
  __builtin_va_start(args,format);
  if (daemon_proc) {
    vsyslog(6, format, args);
  } else {
    vwarnx(format, args);
  }
  __builtin_va_end(args);
}


getHostname

original_code:
void getHostname(char *host, int n, char *hostname) {
  int i = 0;
  int j;
  for (i = 3; i < n; ++i) {
    if (host[i-3] == ':' && host[i-2] == '/' && host[i-1] == '/') {
      break;
    }
  }
  for (j = i; j < n && host[j] != '/'; ++j) {
    hostname[j - i] = host[j];
  }
}

variable_types:
host
char *

variable_types: n int

variable_types:
hostname
char *

variable_types: i int

variable_types: j int


getFilename

original_code:
void getFilename(char *host, int n, char *filename) {
  int i;
  for (i = 0; i < n; ++i) {
    if (host[i] == '/') filename[i] = '_';
    else if (host[i] == ':') filename[i] = '_';
    else if (host[i] == '%') filename[i] = '_';
    else if (host[i] == '.') filename[i] = '_';
    else filename[i] = host[i];
  }
}

variable_types:
filename
char *


noviSocket

decompiled_code:
__int64 __fastcall noviSocket(const char *a1, const char *a2, __m128i *a3, _DWORD *a4, int a5)
{
int v8; // eax
unsigned int v9; // er12
const char *v11; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v8 = getaddrinfo(a1, a2, &req, &pai);
if ( v8 )
{
v11 = gai_strerror(v8);
errx(1, "%s", v11);
}
if ( !pai )
errx(1, "getaddrinfo returned no results");
v9 = Socket((unsigned int)pai->ai_family, (unsigned int)pai->ai_socktype, (unsigned int)pai->ai_protocol);
if ( a3 )
*a3 = _mm_loadu_si128((const __m128i *)pai->ai_addr);
if ( a4 )
*a4 = 16;
if ( a5 )
Bind(v9, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(pai);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2, __m128i *a3, _DWORD *a4, int a5)
{
int v8; // eax
unsigned int v9; // er12
const char *v11; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v8 = getaddrinfo(a1, a2, &req, &pai);
if ( v8 )
{
v11 = gai_strerror(v8);
errx(1, "%s", v11);
}
if ( !pai )
errx(1, "getaddrinfo returned no results");
v9 = Socket((unsigned int)pai->ai_family, (unsigned int)pai->ai_socktype, (unsigned int)pai->ai_protocol);
if ( a3 )
*a3 = _mm_loadu_si128((const __m128i *)pai->ai_addr);
if ( a4 )
*a4 = 16;
if ( a5 )
Bind(v9, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(pai);
return v9;
}

original_code:
int noviSocket(char *node, char *port, struct sockaddr *server, socklen_t *server_l, int povezi) {
  struct addrinfo hints, *res;
  int status;
  int sockfd;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(node, port, &hints, &res)) != 0) {
    errx(1, "%s", gai_strerror(status));
  } else if (res == ((void *)0)) {
    errx(1, "getaddrinfo returned no results");
  }
  sockfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (server != ((void *)0)) {
    *server = *(res->ai_addr);
  }
  if (server_l != ((void *)0)) {
    *server_l = sizeof(*server);
  }
  if (povezi) {
    Bind(sockfd, res->ai_addr, res->ai_addrlen);
  }
  freeaddrinfo(res);
  return sockfd;
}

canonical_original_code:
int noviSocket(char *node, char *port, struct sockaddr *server, unsigned int *server_l, int povezi) {
  struct addrinfo hints; struct addrinfo *res;
  int status;
  int sockfd;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(node, port, &hints, &res)) != 0) {
    errx(1, "%s", gai_strerror(status));
  } else if (res == ((void *)0)) {
    errx(1, "getaddrinfo returned no results");
  }
  sockfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (server != ((void *)0)) {
    *server = *(res->ai_addr);
  }
  if (server_l != ((void *)0)) {
    *server_l = sizeof(*server);
  }
  if (povezi) {
    Bind(sockfd, res->ai_addr, res->ai_addrlen);
  }
  freeaddrinfo(res);
  return sockfd;
}

variable_types:
node
char *

variable_types:
port
char *

variable_types: povezi int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: sockfd int


decompiled_code:
__int64 __fastcall check_filename(char *a1)
{
char v1; // al

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( v1 != 47 )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

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

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( v1 != 47 )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

original_code:
int check_filename(char *filename) {
  char *p;
  for (p = filename; *p; ++p) {
    if (*p == '/') {
      return 0;
    }
  }
  return 1;
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall daemon_init(char *ident, int facility)
{
__pid_t v2; // eax
__pid_t v3; // eax
unsigned int i; // ebx

v2 = fork();
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( v2 > 0 )
exit(0);
if ( setsid() < 0 )
return 0xFFFFFFFFLL;
signal(1, (__sighandler_t)((char *)_bswap_32 + 1));
v3 = fork();
if ( v3 < 0 )
return 0xFFFFFFFFLL;
if ( v3 > 0 )
exit(0);
daemon_proc = 1;
for ( i = 0; i != 64; ++i )
Close(i);
open("/dev/null", 0);
open("/dev/null", 2);
open("/dev/null", 2);
openlog(ident, 1, facility);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *ident, int facility)
{
__pid_t v2; // eax
__pid_t v3; // eax
unsigned int i; // ebx

v2 = fork();
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( v2 > 0 )
exit(0);
if ( setsid() < 0 )
return 0xFFFFFFFFLL;
signal(1, (__sighandler_t)((char *)_bswap_32 + 1));
v3 = fork();
if ( v3 < 0 )
return 0xFFFFFFFFLL;
if ( v3 > 0 )
exit(0);
daemon_proc = 1;
for ( i = 0; i != 64; ++i )
Close(i);
open("/dev/null", 0);
open("/dev/null", 2);
open("/dev/null", 2);
openlog(ident, 1, facility);
return 0LL;
}

original_code:
int daemon_init(const char *pname, int facility) {
  int i;
  pid_t pid;
  if ((pid = fork()) < 0) {
    return -1;
  } else if (pid > 0) {
    _exit(0);
  }
  if (setsid() < 0) {
    return -1;
  }
  signal(1, ((__sighandler_t) 1));
  if ((pid = fork()) < 0) {
    return -1;
  } else if (pid > 0) {
    _exit(0);
  }
  daemon_proc = 1;
  for (i = 0; i < 64; ++i) {
    Close(i);
  }
  open("/dev/null", 00);
  open("/dev/null", 02);
  open("/dev/null", 02);
  openlog(pname, 0x01, facility);
  return 0;
}

canonical_original_code:
int daemon_init(char *pname, int facility) {
  int i;
  int pid;
  if ((pid = fork()) < 0) {
    return -1;
  } else if (pid > 0) {
    _exit(0);
  }
  if (setsid() < 0) {
    return -1;
  }
  signal(1, ((void (*)(int)) 1));
  if ((pid = fork()) < 0) {
    return -1;
  } else if (pid > 0) {
    _exit(0);
  }
  daemon_proc = 1;
  for (i = 0; i < 64; ++i) {
    Close(i);
  }
  open("/dev/null", 00);
  open("/dev/null", 02);
  open("/dev/null", 02);
  openlog(pname, 0x01, facility);
  return 0;
}

variable_types:
pname
char *

variable_types: facility int

variable_types: pid int


decompiled_code:
__int64 __fastcall generate_server_response(char *src, char *dest)
{
int v2; // eax
int v3; // eax
const char *v4; // rax
__int64 result; // rax
int v6; // eax
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-120h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-118h] BYREF
struct sockaddr buf; // [rsp+40h] [rbp-E8h] BYREF
char serv[64]; // [rsp+50h] [rbp-D8h] BYREF
char host[64]; // [rsp+90h] [rbp-98h] BYREF
char srca[88]; // [rsp+D0h] [rbp-58h] BYREF

*(_QWORD *)&buf.sa_family = 0LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
v2 = inet_pton(2, src, &buf.sa_data[2]);
if ( v2 < 0 )
{
strcpy(dest, "inet_pton returned error for this query");
result = 0x79726575712073LL;
}
else if ( v2 )
{
if ( v2 != 1 )
errx(1, "Undefined behaviour for inet_pton");
buf.sa_family = 2;
*(_WORD *)buf.sa_data = _bswap_16(80);
v3 = getnameinfo(&buf, 0x10u, host, 0x40u, serv, 0x40u, 0);
if ( v3 )
{
v4 = gai_strerror(v3);
result = (__int64)strcpy(dest, v4);
}
else
{
strcpy(dest, src);
*(_WORD *)&dest[strlen(dest)] = 32;
result = (__int64)strcat(dest, host);
}
}
else
{
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 2;
v6 = getaddrinfo(src, "80", &req, &pai);
if ( v6 )
{
v7 = gai_strerror(v6);
result = (__int64)strcpy(dest, v7);
}
else if ( pai )
{
inet_ntop(pai->ai_family, &pai->ai_addr->sa_data[2], srca, 0x40u);
strcpy(dest, src);
*(_WORD *)&dest[strlen(dest)] = 32;
result = (__int64)strcat(dest, srca);
}
else
{
strcpy(dest, "getaddrinfo didnt find any records");
result = 0x6120646E69662074LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *src, char *dest)
{
int v2; // eax
int v3; // eax
const char *v4; // rax
__int64 result; // rax
int v6; // eax
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-120h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-118h] BYREF
struct sockaddr buf; // [rsp+40h] [rbp-E8h] BYREF
char serv[64]; // [rsp+50h] [rbp-D8h] BYREF
char host[64]; // [rsp+90h] [rbp-98h] BYREF
char srca[88]; // [rsp+D0h] [rbp-58h] BYREF

*(_QWORD *)&buf.sa_family = 0LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
v2 = inet_pton(2, src, &buf.sa_data[2]);
if ( v2 < 0 )
{
strcpy(dest, "inet_pton returned error for this query");
result = 0x79726575712073LL;
}
else if ( v2 )
{
if ( v2 != 1 )
errx(1, "Undefined behaviour for inet_pton");
buf.sa_family = 2;
*(_WORD *)buf.sa_data = func7(80);
v3 = getnameinfo(&buf, 0x10u, host, 0x40u, serv, 0x40u, 0);
if ( v3 )
{
v4 = gai_strerror(v3);
result = (__int64)strcpy(dest, v4);
}
else
{
strcpy(dest, src);
*(_WORD *)&dest[strlen(dest)] = 32;
result = (__int64)strcat(dest, host);
}
}
else
{
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 2;
v6 = getaddrinfo(src, "80", &req, &pai);
if ( v6 )
{
v7 = gai_strerror(v6);
result = (__int64)strcpy(dest, v7);
}
else if ( pai )
{
inet_ntop(pai->ai_family, &pai->ai_addr->sa_data[2], srca, 0x40u);
strcpy(dest, src);
*(_WORD *)&dest[strlen(dest)] = 32;
result = (__int64)strcat(dest, srca);
}
else
{
strcpy(dest, "getaddrinfo didnt find any records");
result = 0x6120646E69662074LL;
}
}
return result;
}

original_code:
void generate_server_response(char *q, char *a) {
  int status;
  char adresa[64], host[64], serv[64];
  struct sockaddr_in sa;
  struct addrinfo hints, *res;
  memset(&sa, 0, sizeof sa);
  status = inet_pton(2, q, &(sa.sin_addr));
  if (status < 0) {
    strcpy(a, "inet_pton returned error for this query");
  } else if (status == 0) {
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 2;
    hints.ai_flags |= 0x0002;
    status = getaddrinfo(q, "80", &hints, &res);
    if (status != 0) {
      strcpy(a, gai_strerror(status));
    } else if (res == ((void *)0)) {
      strcpy(a, "getaddrinfo didnt find any records");
    } else {
      inet_ntop(
        res->ai_family,
        &((struct sockaddr_in *)res->ai_addr)->sin_addr,
        adresa,
        sizeof(adresa)
      );
      strcpy(a, q);
      strcat(a, " ");
      strcat(a, adresa);
    }
  } else if (status == 1) {
    sa.sin_family = 2;
    sa.sin_port = htons(80);
    status = getnameinfo((struct sockaddr *)&sa, sizeof(sa), host, sizeof host, serv, sizeof serv, 0);
    if (status != 0) {
      strcpy(a, gai_strerror(status));
    } else {
      strcpy(a, q);
      strcat(a, " ");
      strcat(a, host);
    }
  } else {
    errx(1, "Undefined behaviour for inet_pton");
  }
  return;
}

canonical_original_code:
void generate_server_response(char *q, char *a) {
  int status;
  char adresa[64]; char host[64]; char serv[64];
  struct sockaddr_in sa;
  struct addrinfo hints; struct addrinfo *res;
  memset(&sa, 0, sizeof sa);
  status = inet_pton(2, q, &(sa.sin_addr));
  if (status < 0) {
    strcpy(a, "inet_pton returned error for this query");
  } else if (status == 0) {
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 2;
    hints.ai_flags |= 0x0002;
    status = getaddrinfo(q, "80", &hints, &res);
    if (status != 0) {
      strcpy(a, gai_strerror(status));
    } else if (res == ((void *)0)) {
      strcpy(a, "getaddrinfo didnt find any records");
    } else {
      inet_ntop(
        res->ai_family,
        &((struct sockaddr_in *)res->ai_addr)->sin_addr,
        adresa,
        sizeof(adresa)
      );
      strcpy(a, q);
      strcat(a, " ");
      strcat(a, adresa);
    }
  } else if (status == 1) {
    sa.sin_family = 2;
    sa.sin_port = htons(80);
    status = getnameinfo((struct sockaddr *)&sa, sizeof(sa), host, sizeof host, serv, sizeof serv, 0);
    if (status != 0) {
      strcpy(a, gai_strerror(status));
    } else {
      strcpy(a, q);
      strcat(a, " ");
      strcat(a, host);
    }
  } else {
    errx(1, "Undefined behaviour for inet_pton");
  }
  return;
}

variable_types:
q
char *

variable_types:
a
char *

variable_types: status int

variable_types:
adresa
char [64]

variable_types:
host
char [64]

variable_types:
serv
char [64]

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 addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // eax
int v5; // eax
__int64 v6; // r12
const char *v7; // rax
size_t v8; // rax
int v9; // eax
int v10; // eax
char v12[1024]; // [rsp+0h] [rbp-878h] BYREF
char buf[1032]; // [rsp+400h] [rbp-478h] BYREF
struct addrinfo *pai; // [rsp+808h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+810h] [rbp-68h] BYREF
struct sockaddr addr; // [rsp+840h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+85Ch] [rbp-1Ch] BYREF

v3 = (char *)malloc(8uLL);
strcpy(v3, "3737");
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "p:");
if ( v4 == -1 )
break;
if ( v4 != 112 )
errx(1, "Usage: ./udpserver [-p port]");
strcpy(v3, _bss_start);
}
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v5 = getaddrinfo(0LL, v3, &req, &pai);
if ( v5 )
{
v7 = gai_strerror(v5);
errx(1, v7);
}
v6 = (unsigned int)Socket(
(unsigned int)pai->ai_family,
(unsigned int)pai->ai_socktype,
(unsigned int)pai->ai_protocol);
Bind(v6, pai->ai_addr, pai->ai_addrlen);
while ( 1 )
{
memset(buf, 0, 0x400uLL);
memset(v12, 0, sizeof(v12));
addr_len[0] = 16;
v9 = recvfrom(v6, buf, 0x400uLL, 0, &addr, addr_len);
if ( !v9 )
break;
v10 = v9 - 1;
if ( buf[v10] == 10 )
buf[v10] = 0;
printf("Q: %s\n", buf);
generate_server_response(buf, v12);
v8 = strlen(v12);
sendto(v6, v12, v8, 0, &addr, addr_len[0]);
}
Close(v6);
freeaddrinfo(pai);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // eax
int v5; // eax
__int64 v6; // r12
const char *v7; // rax
size_t v8; // rax
int v9; // eax
int v10; // eax
char v12[1024]; // [rsp+0h] [rbp-878h] BYREF
char buf[1032]; // [rsp+400h] [rbp-478h] BYREF
struct addrinfo *pai; // [rsp+808h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+810h] [rbp-68h] BYREF
struct sockaddr addr; // [rsp+840h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+85Ch] [rbp-1Ch] BYREF

v3 = (char *)malloc(8uLL);
strcpy(v3, "3737");
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "p:");
if ( v4 == -1 )
break;
if ( v4 != 112 )
errx(1, "Usage: ./udpserver [-p port]");
strcpy(v3, _bss_start);
}
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v5 = getaddrinfo(0LL, v3, &req, &pai);
if ( v5 )
{
v7 = gai_strerror(v5);
errx(1, v7);
}
v6 = (unsigned int)func9(
(unsigned int)pai->ai_family,
(unsigned int)pai->ai_socktype,
(unsigned int)pai->ai_protocol);
func10(v6, pai->ai_addr, pai->ai_addrlen);
while ( 1 )
{
memset(buf, 0, 0x400uLL);
memset(v12, 0, sizeof(v12));
addr_len[0] = 16;
v9 = recvfrom(v6, buf, 0x400uLL, 0, &addr, addr_len);
if ( !v9 )
break;
v10 = v9 - 1;
if ( buf[v10] == 10 )
buf[v10] = 0;
printf("Q: %s\n", buf);
func8(buf, v12);
v8 = strlen(v12);
sendto(v6, v12, v8, 0, &addr, addr_len[0]);
}
func11(v6);
freeaddrinfo(pai);
free(v3);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int ch;
  int status;
  int socket_fd;
  int msglen;
  socklen_t client_l;
  struct sockaddr client;
  struct addrinfo hints, *res;
  char question[1024], answer[1024];
  char *port = (char *)malloc(sizeof(char) * 8);
  char *IP = (char *)malloc(sizeof(char) * 64);
  strcpy(port, "3737");
  while ((ch = getopt(argc, argv, "p:")) != -1) {
    switch(ch) {
      case 'p':
        strcpy(port, optarg);
        break;
      default:
        errx(1, "Usage: ./udpserver [-p port]");
        break;
    }
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  status = getaddrinfo(((void *)0), port, &hints, &res);
  if (status != 0) { errx(1, gai_strerror(status)); }
  socket_fd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  Bind(socket_fd, res->ai_addr, res->ai_addrlen);
  while (1) {
    memset(question, 0, sizeof question);
    memset(answer, 0, sizeof answer);
    client_l = sizeof(client);
    msglen = recvfrom(socket_fd, question, sizeof(question), 0, &client, &client_l);
    if (msglen == 0) {
      break;
    } else {
      if (question[msglen - 1] == '\n') {
        question[msglen - 1] = '\0';
      }
      printf("Q: %s\n", question);
      generate_server_response(question, answer);
      sendto(socket_fd, answer, strlen(answer), 0, &client, client_l);
    }
  }
  Close(socket_fd);
  freeaddrinfo(res);
  free(port);
  free(IP);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int ch;
  int status;
  int socket_fd;
  int msglen;
  unsigned int client_l;
  struct sockaddr client;
  struct addrinfo hints; struct addrinfo *res;
  char question[1024]; char answer[1024];
  char *port = (char *)malloc(sizeof(char) * 8);
  char *IP = (char *)malloc(sizeof(char) * 64);
  strcpy(port, "3737");
  while ((ch = getopt(argc, argv, "p:")) != -1) {
    switch(ch) {
      case 'p':
        strcpy(port, optarg);
        break;
      default:
        errx(1, "Usage: ./udpserver [-p port]");
        break;
    }
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  status = getaddrinfo(((void *)0), port, &hints, &res);
  if (status != 0) { errx(1, gai_strerror(status)); }
  socket_fd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  Bind(socket_fd, res->ai_addr, res->ai_addrlen);
  while (1) {
    memset(question, 0, sizeof question);
    memset(answer, 0, sizeof answer);
    client_l = sizeof(client);
    msglen = recvfrom(socket_fd, question, sizeof(question), 0, &client, &client_l);
    if (msglen == 0) {
      break;
    } else {
      if (question[msglen - 1] == '\n') {
        question[msglen - 1] = '\0';
      }
      printf("Q: %s\n", question);
      generate_server_response(question, answer);
      sendto(socket_fd, answer, strlen(answer), 0, &client, client_l);
    }
  }
  Close(socket_fd);
  freeaddrinfo(res);
  free(port);
  free(IP);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ch int

variable_types: msglen int

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

variable_types:
question
char [1024]

variable_types:
answer
char [1024]

variable_types:
IP
char *


decompiled_code:
__int64 __fastcall daemon_init(char *ident, int facility)
{
__pid_t v2; // eax
__pid_t v3; // eax
unsigned int i; // ebx

v2 = fork();
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( v2 > 0 )
exit(0);
if ( setsid() < 0 )
return 0xFFFFFFFFLL;
signal(1, (__sighandler_t)((char *)_bswap_16 + 1));
v3 = fork();
if ( v3 < 0 )
return 0xFFFFFFFFLL;
if ( v3 > 0 )
exit(0);
daemon_proc = 1;
for ( i = 0; i != 64; ++i )
Close(i);
open("/dev/null", 0);
open("/dev/null", 2);
open("/dev/null", 2);
openlog(ident, 1, facility);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *ident, int facility)
{
__pid_t v2; // eax
__pid_t v3; // eax
unsigned int i; // ebx

v2 = fork();
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( v2 > 0 )
exit(0);
if ( setsid() < 0 )
return 0xFFFFFFFFLL;
signal(1, (__sighandler_t)((char *)_bswap_16 + 1));
v3 = fork();
if ( v3 < 0 )
return 0xFFFFFFFFLL;
if ( v3 > 0 )
exit(0);
daemon_proc = 1;
for ( i = 0; i != 64; ++i )
Close(i);
open("/dev/null", 0);
open("/dev/null", 2);
open("/dev/null", 2);
openlog(ident, 1, facility);
return 0LL;
}

variable_types:
pname
char *

variable_types: facility int

variable_types: i int

variable_types: pid int


noviSocket

decompiled_code:
__int64 __fastcall noviSocket(const char *a1, const char *a2, __m128i *a3, _DWORD *a4)
{
int v6; // eax
unsigned int v7; // ebx
const char *v9; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v6 = getaddrinfo(a1, a2, &req, &pai);
if ( v6 )
{
v9 = gai_strerror(v6);
Errx(1LL, "TFTP ERROR 0 ms45889: %s", v9);
}
else if ( !pai )
{
Errx(1LL, "TFTP ERROR 0 ms45889: getaddrinfo error");
}
v7 = Socket((unsigned int)pai->ai_family, (unsigned int)pai->ai_socktype, (unsigned int)pai->ai_protocol);
if ( a3 )
*a3 = _mm_loadu_si128((const __m128i *)pai->ai_addr);
if ( a4 )
*a4 = 16;
Bind(v7, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(pai);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2, __m128i *a3, _DWORD *a4)
{
int v6; // eax
unsigned int v7; // ebx
const char *v9; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
v6 = getaddrinfo(a1, a2, &req, &pai);
if ( v6 )
{
v9 = gai_strerror(v6);
Errx(1LL, "TFTP ERROR 0 ms45889: %s", v9);
}
else if ( !pai )
{
Errx(1LL, "TFTP ERROR 0 ms45889: getaddrinfo error");
}
v7 = Socket((unsigned int)pai->ai_family, (unsigned int)pai->ai_socktype, (unsigned int)pai->ai_protocol);
if ( a3 )
*a3 = _mm_loadu_si128((const __m128i *)pai->ai_addr);
if ( a4 )
*a4 = 16;
Bind(v7, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(pai);
return v7;
}

original_code:
int noviSocket(char *node, char *port, struct sockaddr *server, socklen_t *server_l) {
  struct addrinfo hints, *res;
  int status;
  int sockfd;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(node, port, &hints, &res)) != 0) {
    Errx(daemon_proc ? 1 : 1, "TFTP ERROR 0 ms45889: %s", gai_strerror(status));
  } else if (res == ((void *)0)) {
    Errx(daemon_proc ? 1 : 1, "TFTP ERROR 0 ms45889: getaddrinfo error");
  }
  sockfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (server != ((void *)0)) {
    *server = *(res->ai_addr);
  }
  if (server_l != ((void *)0)) {
    *server_l = sizeof(*server);
  }
  Bind(sockfd, res->ai_addr, res->ai_addrlen);
  freeaddrinfo(res);
  return sockfd;
}

canonical_original_code:
int noviSocket(char *node, char *port, struct sockaddr *server, unsigned int *server_l) {
  struct addrinfo hints; struct addrinfo *res;
  int status;
  int sockfd;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(node, port, &hints, &res)) != 0) {
    Errx(daemon_proc ? 1 : 1, "TFTP ERROR 0 ms45889: %s", gai_strerror(status));
  } else if (res == ((void *)0)) {
    Errx(daemon_proc ? 1 : 1, "TFTP ERROR 0 ms45889: getaddrinfo error");
  }
  sockfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (server != ((void *)0)) {
    *server = *(res->ai_addr);
  }
  if (server_l != ((void *)0)) {
    *server_l = sizeof(*server);
  }
  Bind(sockfd, res->ai_addr, res->ai_addrlen);
  freeaddrinfo(res);
  return sockfd;
}

variable_types:
node
char *

variable_types:
port
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: status int

variable_types: sockfd int


timediff

repo: mschneider/parprogassignments

decompiled_code:
double __fastcall timediff(int a1, int a2, int a3, int a4)
{
return (double)(a4 - a2) * 0.000001 + (double)(a3 - a1);
}

canonical_decompiled_code:
double __fastcall func7(int a1, int a2, int a3, int a4)
{
return (double)(a4 - a2) * 0.000001 + (double)(a3 - a1);
}

original_code:
double timediff(timeval a, timeval b)
{
  return 1.0 * (b.tv_sec - a.tv_sec)
       + 0.000001 * (b.tv_usec - a.tv_usec);
}

canonical_original_code:
double timediff(struct timeval a, struct timeval b)
{
  return 1.0 * (b.tv_sec - a.tv_sec)
       + 0.000001 * (b.tv_usec - a.tv_usec);
}

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

variable_types:
b
struct timeval

return_type: double