decompiled_code:
int __fastcall get_rate_limit(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

if ( !a1 )
return 5;
v2 = a1;
while ( 1 )
{
if ( !strcmp("rates", *(const char **)v2) )
{
v3 = *(_QWORD *)(v2 + 8);
if ( v3 )
break;
}
LABEL_3:
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 5;
}
while ( !strstr(a2, *(const char **)v3) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
goto LABEL_3;
}
return atoi(*(const char **)(v3 + 8));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

if ( !a1 )
return 5;
v2 = a1;
while ( 1 )
{
if ( !strcmp("rates", *(const char **)v2) )
{
v3 = *(_QWORD *)(v2 + 8);
if ( v3 )
break;
}
LABEL_3:
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 5;
}
while ( !strstr(a2, *(const char **)v3) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
goto LABEL_3;
}
return atoi(*(const char **)(v3 + 8));
}

original_code:
int get_rate_limit(struct config_sect * config_options, char * host_address){
  char *section = "rates";
  while (config_options) {
    if (strcmp (section, config_options->name) == 0) {
      struct config_token *tokens = config_options->tokens;
      while (tokens) {
 if(strstr( host_address, tokens->token) != ((void *)0)){
   return atoi(tokens->value);
 }
 tokens = tokens->next;
      }
    }
    config_options = config_options->next;
  }
  return 5;
}

canonical_original_code:
int get_rate_limit(struct config_sect *config_options, char *host_address){
  char *section = "rates";
  while (config_options) {
    if (strcmp (section, config_options->name) == 0) {
      struct config_token *tokens = config_options->tokens;
      while (tokens) {
 if(strstr( host_address, tokens->token) != ((void *)0)){
   return atoi(tokens->value);
 }
 tokens = tokens->next;
      }
    }
    config_options = config_options->next;
  }
  return 5;
}

variable_types: struct config_sect { char *name; struct config_token { char *token; char *value; struct config_token *next; } *tokens; struct config_sect *next; } *

variable_types:
section
char *

user_defined_types: struct config_sect { char *name; struct config_token *tokens; struct config_sect *next; }


convertToBpInterval

decompiled_code:
__int64 __fastcall convertToBpInterval(int a1)
{
return (unsigned int)(int)(float)((float)a1 * 1024.0);
}

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

original_code:
int convertToBpInterval(int rate_limit){
  float k = 1024;
  return (int) rate_limit*k;
}

variable_types: k float

return_type: int


decompiled_code:
void __fastcall update_bin(int a1, __int64 a2)
{
if ( a1 < 0 )
_assert_fail("amount_sent >= 0", "rate_lib.c", 0x68u, "update_bin");
if ( !a2 )
_assert_fail("rate_limit != NULL", "rate_lib.c", 0x69u, "update_bin");
*(_DWORD *)(a2 + 32) -= a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1, __int64 a2)
{
if ( a1 < 0 )
_assert_fail("amount_sent >= 0", "rate_lib.c", 0x68u, "update_bin");
if ( !a2 )
_assert_fail("rate_limit != NULL", "rate_lib.c", 0x69u, "update_bin");
*(_DWORD *)(a2 + 32) -= a1;
}

original_code:
void update_bin(int amount_sent, struct rate *rate_limit){
  ((void) sizeof ((amount_sent >= 0) ? 1 : 0), __extension__ ({ if (amount_sent >= 0) ; else __assert_fail ("amount_sent >= 0", "rate_lib.c", 104, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((rate_limit != ((void *)0)) ? 1 : 0), __extension__ ({ if (rate_limit != ((void *)0)) ; else __assert_fail ("rate_limit != NULL", "rate_lib.c", 105, __extension__ __PRETTY_FUNCTION__); }));
  rate_limit -> bin_amount = rate_limit -> bin_amount - amount_sent;
}

variable_types: struct rate { struct timeval { long tv_sec; long tv_usec; } timestamp; int bin_amount; } *

return_type: void

user_defined_types: struct rate { struct timeval timestamp; int bin_amount; }


decompiled_code:
__int64 __fastcall time_compare(__int64 *a1, __int64 *a2)
{
__int64 v2; // rdx
__int64 v3; // rdi
__int64 v4; // rcx
__int64 v5; // rsi
__int64 result; // rax

v2 = *a1;
if ( *a1 < 0 )
_assert_fail("(time1 -> tv_sec) >= 0", "rate_lib.c", 0x78u, "time_compare");
v3 = a1[1];
if ( v3 < 0 )
_assert_fail("(time1 -> tv_usec) >= 0", "rate_lib.c", 0x79u, "time_compare");
v4 = *a2;
if ( *a2 < 0 )
_assert_fail("(time2 -> tv_sec) >= 0", "rate_lib.c", 0x7Au, "time_compare");
v5 = a2[1];
if ( v5 < 0 )
_assert_fail("(time2 -> tv_usec) >= 0", "rate_lib.c", 0x7Bu, "time_compare");
result = 1LL;
if ( v2 <= v4 )
{
result = 0xFFFFFFFFLL;
if ( v2 >= v4 )
result = v3 > v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 *a2)
{
__int64 v2; // rdx
__int64 v3; // rdi
__int64 v4; // rcx
__int64 v5; // rsi
__int64 result; // rax

v2 = *a1;
if ( *a1 < 0 )
_assert_fail("(time1 -> tv_sec) >= 0", "rate_lib.c", 0x78u, "time_compare");
v3 = a1[1];
if ( v3 < 0 )
_assert_fail("(time1 -> tv_usec) >= 0", "rate_lib.c", 0x79u, "time_compare");
v4 = *a2;
if ( *a2 < 0 )
_assert_fail("(time2 -> tv_sec) >= 0", "rate_lib.c", 0x7Au, "time_compare");
v5 = a2[1];
if ( v5 < 0 )
_assert_fail("(time2 -> tv_usec) >= 0", "rate_lib.c", 0x7Bu, "time_compare");
result = 1LL;
if ( v2 <= v4 )
{
result = 0xFFFFFFFFLL;
if ( v2 >= v4 )
result = v3 > v5;
}
return result;
}

original_code:
int time_compare(struct timeval *time1, struct timeval *time2){
  ((void) sizeof (((time1 -> tv_sec) >= 0) ? 1 : 0), __extension__ ({ if ((time1 -> tv_sec) >= 0) ; else __assert_fail ("(time1 -> tv_sec) >= 0", "rate_lib.c", 120, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof (((time1 -> tv_usec) >= 0) ? 1 : 0), __extension__ ({ if ((time1 -> tv_usec) >= 0) ; else __assert_fail ("(time1 -> tv_usec) >= 0", "rate_lib.c", 121, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof (((time2 -> tv_sec) >= 0) ? 1 : 0), __extension__ ({ if ((time2 -> tv_sec) >= 0) ; else __assert_fail ("(time2 -> tv_sec) >= 0", "rate_lib.c", 122, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof (((time2 -> tv_usec) >= 0) ? 1 : 0), __extension__ ({ if ((time2 -> tv_usec) >= 0) ; else __assert_fail ("(time2 -> tv_usec) >= 0", "rate_lib.c", 123, __extension__ __PRETTY_FUNCTION__); }));
  if( (time1 -> tv_sec) > (time2 -> tv_sec) ) return 1;
  else if ((time1 -> tv_sec) < (time2 -> tv_sec) ) return -1;
  else{
    if( (time1 -> tv_usec) > (time2 -> tv_usec) ) return 1;
    else if ((time1 -> tv_sec) < (time2 -> tv_sec) ) return -1;
    else return 0;
  }
}

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


suspend

original_code:
int suspend(struct rate *rate_limit){
  ((void) sizeof ((rate_limit != ((void *)0)) ? 1 : 0), __extension__ ({ if (rate_limit != ((void *)0)) ; else __assert_fail ("rate_limit != NULL", "rate_lib.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  struct timeval current_time, deadline, sleeptime;
  do { (&deadline)->tv_sec = (&(rate_limit -> timestamp))->tv_sec + (&(rate_limit -> period))->tv_sec; (&deadline)->tv_usec = (&(rate_limit -> timestamp))->tv_usec + (&(rate_limit -> period))->tv_usec; if ((&deadline)->tv_usec >= 1000000) { ++(&deadline)->tv_sec; (&deadline)->tv_usec -= 1000000; } } while (0);
  if(gettimeofday(&current_time, ((void *)0)) < 0){
    printf("getting clock information failed: %s", strerror((*__errno_location ())));
    return -1;
  }
  if(time_compare(&current_time, &deadline) <= 0 && rate_limit -> bin_amount <= 0){
    do { (&sleeptime)->tv_sec = (&deadline)->tv_sec - (&current_time)->tv_sec; (&sleeptime)->tv_usec = (&deadline)->tv_usec - (&current_time)->tv_usec; if ((&sleeptime)->tv_usec < 0) { --(&sleeptime)->tv_sec; (&sleeptime)->tv_usec += 1000000; } } while (0);
    printf("Going to sleep");
    select(0,0,0,0,&sleeptime);
    rate_limit -> timestamp = deadline;
    rate_limit -> bin_amount = rate_limit ->bin_max_amount;
  }
  else if(time_compare(&current_time, &deadline) > 0){
    rate_limit -> timestamp = current_time;
    rate_limit -> bin_amount = rate_limit -> bin_max_amount;
  }
  return 1;
}

canonical_original_code:
int suspend(struct rate *rate_limit){
  ((void) sizeof ((rate_limit != ((void *)0)) ? 1 : 0), __extension__ ({ if (rate_limit != ((void *)0)) ; else __assert_fail ("rate_limit != NULL", "rate_lib.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  struct timeval current_time; struct timeval deadline; struct timeval sleeptime;
  do { (&deadline)->tv_sec = (&(rate_limit -> timestamp))->tv_sec + (&(rate_limit -> period))->tv_sec; (&deadline)->tv_usec = (&(rate_limit -> timestamp))->tv_usec + (&(rate_limit -> period))->tv_usec; if ((&deadline)->tv_usec >= 1000000) { ++(&deadline)->tv_sec; (&deadline)->tv_usec -= 1000000; } } while (0);
  if(gettimeofday(&current_time, ((void *)0)) < 0){
    printf("getting clock information failed: %s", strerror((*__errno_location ())));
    return -1;
  }
  if(time_compare(&current_time, &deadline) <= 0 && rate_limit -> bin_amount <= 0){
    do { (&sleeptime)->tv_sec = (&deadline)->tv_sec - (&current_time)->tv_sec; (&sleeptime)->tv_usec = (&deadline)->tv_usec - (&current_time)->tv_usec; if ((&sleeptime)->tv_usec < 0) { --(&sleeptime)->tv_sec; (&sleeptime)->tv_usec += 1000000; } } while (0);
    printf("Going to sleep");
    select(0,0,0,0,&sleeptime);
    rate_limit -> timestamp = deadline;
    rate_limit -> bin_amount = rate_limit ->bin_max_amount;
  }
  else if(time_compare(&current_time, &deadline) > 0){
    rate_limit -> timestamp = current_time;
    rate_limit -> bin_amount = rate_limit -> bin_max_amount;
  }
  return 1;
}

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


decompiled_code:
int __fastcall print_timeval(_QWORD *a1)
{
return printf("%ld sec %ld usec", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func5(_QWORD *a1)
{
return printf("%ld sec %ld usec", *a1, a1[1]);
}

original_code:
void print_timeval(struct timeval *value){
  printf("%ld sec %ld usec", value -> tv_sec, value -> tv_usec);
}

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


decompiled_code:
int test_suspend()
{
__m128i v0; // xmm1
__m128i v2; // [rsp+0h] [rbp-58h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF
__int128 v5; // [rsp+30h] [rbp-28h]
int v6; // [rsp+40h] [rbp-18h]
int v7; // [rsp+44h] [rbp-14h]

v6 = 0;
v5 = 3uLL;
v7 = 3;
tv = 0LL;
gettimeofday(&tv, 0LL);
v2.m128i_i64[0] = tv.tv_sec + 3;
v2.m128i_i64[1] = tv.tv_usec;
if ( tv.tv_usec > 999999 )
{
v2.m128i_i64[0] = tv.tv_sec + 4;
v2.m128i_i64[1] = tv.tv_usec - 1000000;
}
suspend((__int64)&tv);
printf("\nExpect:");
print_timeval(&v2);
printf("\nGot: ");
print_timeval(&tv);
printf("\nAmount(3):%d\n", 0LL);
gettimeofday(&tv, 0LL);
v0 = _mm_loadu_si128((const __m128i *)&tv);
v6 = 2;
v2 = v0;
suspend((__int64)&tv);
printf("\n\nExpect:");
print_timeval(&v2);
printf("\nGot: ");
print_timeval(&tv);
printf("\nAmount(2):%d\n", 0LL);
gettimeofday(&tv, 0LL);
timeout.tv_sec = 4LL;
timeout.tv_usec = 0LL;
select(0, 0LL, 0LL, 0LL, &timeout);
gettimeofday((struct timeval *)&v2, 0LL);
suspend((__int64)&tv);
printf("\n\nExpect:");
print_timeval(&v2);
printf("\nGot: ");
print_timeval(&tv);
return printf("\nAmount(3):%d\n", 2LL);
}

canonical_decompiled_code:
int func6()
{
__m128i v0; // xmm1
__m128i v2; // [rsp+0h] [rbp-58h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF
__int128 v5; // [rsp+30h] [rbp-28h]
int v6; // [rsp+40h] [rbp-18h]
int v7; // [rsp+44h] [rbp-14h]

v6 = 0;
v5 = 3uLL;
v7 = 3;
tv = 0LL;
gettimeofday(&tv, 0LL);
v2.m128i_i64[0] = tv.tv_sec + 3;
v2.m128i_i64[1] = tv.tv_usec;
if ( tv.tv_usec > 999999 )
{
v2.m128i_i64[0] = tv.tv_sec + 4;
v2.m128i_i64[1] = tv.tv_usec - 1000000;
}
func4((__int64)&tv);
printf("\nExpect:");
func5(&v2);
printf("\nGot: ");
func5(&tv);
printf("\nAmount(3):%d\n", 0LL);
gettimeofday(&tv, 0LL);
v0 = _mm_loadu_si128((const __m128i *)&tv);
v6 = 2;
v2 = v0;
func4((__int64)&tv);
printf("\n\nExpect:");
func5(&v2);
printf("\nGot: ");
func5(&tv);
printf("\nAmount(2):%d\n", 0LL);
gettimeofday(&tv, 0LL);
timeout.tv_sec = 4LL;
timeout.tv_usec = 0LL;
select(0, 0LL, 0LL, 0LL, &timeout);
gettimeofday((struct timeval *)&v2, 0LL);
func4((__int64)&tv);
printf("\n\nExpect:");
func5(&v2);
printf("\nGot: ");
func5(&tv);
return printf("\nAmount(3):%d\n", 2LL);
}

original_code:
void test_suspend(void){
  int amount, max_amount;
  max_amount = 3;
  amount = 0;
  const struct timeval reader_timeout = {.tv_sec = 3, .tv_usec = 0};
  struct timeval exp_time;
  struct rate rate_limit = {.period = reader_timeout, .bin_amount = amount,
      .bin_max_amount = max_amount };
  gettimeofday(&(rate_limit.timestamp), ((void *)0));
  do { (&exp_time)->tv_sec = (&(rate_limit.timestamp))->tv_sec + (&reader_timeout)->tv_sec; (&exp_time)->tv_usec = (&(rate_limit.timestamp))->tv_usec + (&reader_timeout)->tv_usec; if ((&exp_time)->tv_usec >= 1000000) { ++(&exp_time)->tv_sec; (&exp_time)->tv_usec -= 1000000; } } while (0);
  suspend(&rate_limit);
  printf("\nExpect:"); print_timeval(&exp_time);
  printf("\nGot: "); print_timeval(&(rate_limit.timestamp));
  printf("\nAmount(3):%d\n", amount);
  gettimeofday(&(rate_limit.timestamp), ((void *)0));
  exp_time = rate_limit.timestamp;
  rate_limit.bin_amount = 2;
  suspend(&rate_limit);
  printf("\n\nExpect:"); print_timeval(&exp_time);
  printf("\nGot: "); print_timeval(&(rate_limit.timestamp));
  printf("\nAmount(2):%d\n", amount);
  gettimeofday(&rate_limit.timestamp, ((void *)0));
  amount = 2;
  select(0,0,0,0,&((struct timeval) {.tv_sec = 4, .tv_usec = 0}));
  gettimeofday(&exp_time, ((void *)0));
  suspend(&rate_limit);
  printf("\n\nExpect:"); print_timeval(&exp_time);
  printf("\nGot: "); print_timeval(&(rate_limit.timestamp));
  printf("\nAmount(3):%d\n", amount);
}

canonical_original_code:
void test_suspend(){
  int amount; int max_amount;
  max_amount = 3;
  amount = 0;
  struct timeval reader_timeout = {.tv_sec = 3, .tv_usec = 0};
  struct timeval exp_time;
  struct rate rate_limit = {.period = reader_timeout, .bin_amount = amount,
      .bin_max_amount = max_amount };
  gettimeofday(&(rate_limit.timestamp), ((void *)0));
  do { (&exp_time)->tv_sec = (&(rate_limit.timestamp))->tv_sec + (&reader_timeout)->tv_sec; (&exp_time)->tv_usec = (&(rate_limit.timestamp))->tv_usec + (&reader_timeout)->tv_usec; if ((&exp_time)->tv_usec >= 1000000) { ++(&exp_time)->tv_sec; (&exp_time)->tv_usec -= 1000000; } } while (0);
  suspend(&rate_limit);
  printf("\nExpect:"); print_timeval(&exp_time);
  printf("\nGot: "); print_timeval(&(rate_limit.timestamp));
  printf("\nAmount(3):%d\n", amount);
  gettimeofday(&(rate_limit.timestamp), ((void *)0));
  exp_time = rate_limit.timestamp;
  rate_limit.bin_amount = 2;
  suspend(&rate_limit);
  printf("\n\nExpect:"); print_timeval(&exp_time);
  printf("\nGot: "); print_timeval(&(rate_limit.timestamp));
  printf("\nAmount(2):%d\n", amount);
  gettimeofday(&rate_limit.timestamp, ((void *)0));
  amount = 2;
  select(0,0,0,0,&((struct timeval) {.tv_sec = 4, .tv_usec = 0}));
  gettimeofday(&exp_time, ((void *)0));
  suspend(&rate_limit);
  printf("\n\nExpect:"); print_timeval(&exp_time);
  printf("\nGot: "); print_timeval(&(rate_limit.timestamp));
  printf("\nAmount(3):%d\n", amount);
}

variable_types: amount int

variable_types: struct rate { struct timeval { long tv_sec; long tv_usec; } timestamp; int bin_amount; }


decompiled_code:
// attributes: thunk
int rate_lib_tests()
{
return test_suspend();
}

canonical_decompiled_code:
int func7()
{
return func6();
}

original_code:
void rate_lib_tests(void){
  test_suspend();
}

canonical_original_code:
void rate_lib_tests(){
  test_suspend();
}


decompiled_code:
int __fastcall no_fork_proc(int a1, __int64 a2, unsigned int a3)
{
int v4; // eax
int v5; // ebp
int result; // eax
int *v7; // rax
char *v8; // rax

v4 = accept(a1, 0LL, 0LL);
if ( v4 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
result = printf("ERROR in creating socket: %s", v8);
}
else
{
v5 = v4;
relay((unsigned int)v4, a2, a3);
result = close(v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, __int64 a2, unsigned int a3)
{
int v4; // eax
int v5; // ebp
int result; // eax
int *v7; // rax
char *v8; // rax

v4 = accept(a1, 0LL, 0LL);
if ( v4 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
result = printf("ERROR in creating socket: %s", v8);
}
else
{
v5 = v4;
relay((unsigned int)v4, a2, a3);
result = close(v5);
}
return result;
}

original_code:
void no_fork_proc(int sock_lis,
  struct config_sect *config_options,
  int rate_limiting){
  int client_sock;
  if ( (client_sock = accept(sock_lis, ((void *)0), ((void *)0))) < 0){
      printf("ERROR in creating socket: %s", strerror((*__errno_location ())));
      return ;
  }
  relay(client_sock, config_options,rate_limiting );
  close(client_sock);
}

user_defined_types: struct config_token { char *token; char *value; struct config_token *next; }


decompiled_code:
void __fastcall __noreturn fork_proc(int fd, __int64 a2, unsigned int a3)
{
int *v4; // r12
int v5; // ebp
char *v6; // rax
__pid_t v7; // eax

v4 = _errno_location();
while ( 1 )
{
while ( 1 )
{
fwrite("\nWaiting For connection\n", 1uLL, 0x18uLL, stdout);
v5 = accept(fd, 0LL, 0LL);
if ( v5 >= 0 )
break;
v6 = strerror(*v4);
printf("ERROR in creating socket: %s", v6);
}
v7 = fork();
if ( v7 )
{
if ( v7 < 0 )
printf("ERROR in creating fork");
}
else
{
relay((unsigned int)v5, a2, a3);
}
close(v5);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int fd, __int64 a2, unsigned int a3)
{
int *v4; // r12
int v5; // ebp
char *v6; // rax
__pid_t v7; // eax

v4 = _errno_location();
while ( 1 )
{
while ( 1 )
{
fwrite("\nWaiting For connection\n", 1uLL, 0x18uLL, stdout);
v5 = accept(fd, 0LL, 0LL);
if ( v5 >= 0 )
break;
v6 = strerror(*v4);
printf("ERROR in creating socket: %s", v6);
}
v7 = fork();
if ( v7 )
{
if ( v7 < 0 )
printf("ERROR in creating fork");
}
else
{
relay((unsigned int)v5, a2, a3);
}
close(v5);
}
}

original_code:
void fork_proc(int sock_lis,
  struct config_sect *config_options,
  int rate_limiting){
  int client_sock;
  pid_t fork_pid;
  while(1){
      fprintf(stdout, "\nWaiting For connection\n");
      if ( (client_sock = accept(sock_lis, ((void *)0), ((void *)0))) < 0){
          printf("ERROR in creating socket: %s", strerror((*__errno_location ())));
          continue;
      }
      fork_pid = fork();
      if(fork_pid == 0){
          relay(client_sock, config_options, rate_limiting);
      }
      else if(fork_pid < 0){
         printf("ERROR in creating fork");
      }
      close(client_sock);
  }
}

canonical_original_code:
void fork_proc(int sock_lis, struct config_sect *config_options, int rate_limiting){
  int client_sock;
  int fork_pid;
  while(1){
      fprintf(stdout, "\nWaiting For connection\n");
      if ( (client_sock = accept(sock_lis, ((void *)0), ((void *)0))) < 0){
          printf("ERROR in creating socket: %s", strerror((*__errno_location ())));
          continue;
      }
      fork_pid = fork();
      if(fork_pid == 0){
          relay(client_sock, config_options, rate_limiting);
      }
      else if(fork_pid < 0){
         printf("ERROR in creating fork");
      }
      close(client_sock);
  }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
char *v4; // rax
char *v5; // r12
int v6; // er13
unsigned int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = 0;
v3 = parseArgs(argc, argv, v8);
v4 = (char *)malloc(0xAuLL);
if ( v3 )
{
v3 = config_load(v3);
v5 = (char *)extractListPort(v3);
extractDebugLevel(v3);
}
else
{
strcpy(v4, "8080");
v5 = v4;
}
v6 = setup_socket(v5, 0LL);
free(v5);
if ( v6 >= 0 )
fork_proc(v6, v3, v8[0]);
printf("ERROR Could not set up listening socket");
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
char *v4; // rax
char *v5; // r12
int v6; // er13
unsigned int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = 0;
v3 = parseArgs(argc, argv, v8);
v4 = (char *)malloc(0xAuLL);
if ( v3 )
{
v3 = config_load(v3);
v5 = (char *)extractListPort(v3);
extractDebugLevel(v3);
}
else
{
strcpy(v4, "8080");
v5 = v4;
}
v6 = setup_socket(v5, 0LL);
free(v5);
if ( v6 >= 0 )
func1(v6, v3, v8[0]);
printf("ERROR Could not set up listening socket");
return -1;
}

original_code:
int main(int argc, char *argv[] )
{
  int sock_lis, debug_mode = 0, rate_limiting = 0;
  struct config_sect * config_options;
  char *configFile = parseArgs(argc, argv, &rate_limiting);
  char * lis_port = malloc(10*sizeof(char));
  if(lis_port == ((void *)0)){
  }
  if(configFile != ((void *)0)){
    config_options = config_load(configFile);
    lis_port = extractListPort(config_options);
    debug_mode = extractDebugLevel(config_options);
  } else {
    strcpy(lis_port, "8080");
    config_options = ((void *)0);
  }
  sock_lis = setup_socket(lis_port, ((void *)0));
  free(lis_port);
  if(sock_lis < 0){
    printf("ERROR Could not set up listening socket");
    return -1;
  }
 fork_proc(sock_lis, config_options, rate_limiting);
  close(sock_lis);
  return 1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int sock_lis; int debug_mode = 0; int rate_limiting = 0;
  struct config_sect *config_options;
  char *configFile = parseArgs(argc, argv, &rate_limiting);
  char *lis_port = malloc(10*sizeof(char));
  if(lis_port == ((void *)0)){
  }
  if(configFile != ((void *)0)){
    config_options = config_load(configFile);
    lis_port = extractListPort(config_options);
    debug_mode = extractDebugLevel(config_options);
  } else {
    strcpy(lis_port, "8080");
    config_options = ((void *)0);
  }
  sock_lis = setup_socket(lis_port, ((void *)0));
  free(lis_port);
  if(sock_lis < 0){
    printf("ERROR Could not set up listening socket");
    return -1;
  }
 fork_proc(sock_lis, config_options, rate_limiting);
  close(sock_lis);
  return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
configFile
char *


parseArgs

original_code:
char * parseArgs(int argc, char * argv[], int *rate_limiting){
    int i;
    char * fileName = ((void *)0);
    for(i = 0; i < argc; i++){
        if(strcmp(argv[i], "-f")==0 && argv[i+1] != ((void *)0)){
            fileName = argv[i+1];
        }
        if(strcmp(argv[i], "-rl")==0){
            *rate_limiting = 1;
        }
    }
    return fileName;
}

canonical_original_code:
char *parseArgs(int argc, char *argv[], int *rate_limiting){
    int i;
    char *fileName = ((void *)0);
    for(i = 0; i < argc; i++){
        if(strcmp(argv[i], "-f")==0 && argv[i+1] != ((void *)0)){
            fileName = argv[i+1];
        }
        if(strcmp(argv[i], "-rl")==0){
            *rate_limiting = 1;
        }
    }
    return fileName;
}

variable_types: i int

variable_types:
fileName
char *

return_type: char *


extractListPort

decompiled_code:
__int64 __fastcall extractListPort(__int64 a1)
{
__int64 v1; // r8
__int64 v2; // rax

v1 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
if ( !strcmp("default", *(const char **)v1) )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
break;
}
LABEL_3:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
while ( strcmp("proxy_port", *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_3;
}
return *(_QWORD *)(v2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r8
__int64 v2; // rax

v1 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
if ( !strcmp("default", *(const char **)v1) )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
break;
}
LABEL_3:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
while ( strcmp("proxy_port", *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_3;
}
return *(_QWORD *)(v2 + 8);
}

original_code:
char * extractListPort(struct config_sect *config_options){
    char * section = "default";
    char * tokenToFind = "proxy_port";
    while (config_options) {
        if (strcmp (section, config_options->name) == 0) {
            struct config_token *tokens = config_options->tokens;
            while (tokens) {
                if(strcmp(tokenToFind, tokens->token) == 0){
                    return tokens->value;
                }
                tokens = tokens->next;
            }
        }
        config_options = config_options->next;
    }
    return ((void *)0);
}

canonical_original_code:
char *extractListPort(struct config_sect *config_options){
    char *section = "default";
    char *tokenToFind = "proxy_port";
    while (config_options) {
        if (strcmp (section, config_options->name) == 0) {
            struct config_token *tokens = config_options->tokens;
            while (tokens) {
                if(strcmp(tokenToFind, tokens->token) == 0){
                    return tokens->value;
                }
                tokens = tokens->next;
            }
        }
        config_options = config_options->next;
    }
    return ((void *)0);
}

variable_types:
tokenToFind
char *

variable_types: struct config_token { char *token; char *value; struct config_token *next; } *


extractDebugLevel

decompiled_code:
int __fastcall extractDebugLevel(__int64 a1)
{
__int64 v1; // r8
__int64 v2; // rax

v1 = a1;
if ( !a1 )
return -1;
while ( 1 )
{
if ( !strcmp("default", *(const char **)v1) )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
break;
}
LABEL_3:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return -1;
}
while ( strcmp("debug", *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_3;
}
return atoi(*(const char **)(v2 + 8));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // r8
__int64 v2; // rax

v1 = a1;
if ( !a1 )
return -1;
while ( 1 )
{
if ( !strcmp("default", *(const char **)v1) )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
break;
}
LABEL_3:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return -1;
}
while ( strcmp("debug", *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_3;
}
return atoi(*(const char **)(v2 + 8));
}

original_code:
int extractDebugLevel(struct config_sect *config_options){
    char * section = "default";
    char * tokenToFind = "debug";
    while (config_options) {
        if (strcmp (section, config_options->name) == 0) {
            struct config_token *tokens = config_options->tokens;
            while (tokens) {
                if(strcmp(tokenToFind, tokens->token) == 0){
                    return atoi(tokens->value);
                }
                tokens = tokens->next;
            }
        }
        config_options = config_options->next;
    }
    return -1;
}

canonical_original_code:
int extractDebugLevel(struct config_sect *config_options){
    char *section = "default";
    char *tokenToFind = "debug";
    while (config_options) {
        if (strcmp (section, config_options->name) == 0) {
            struct config_token *tokens = config_options->tokens;
            while (tokens) {
                if(strcmp(tokenToFind, tokens->token) == 0){
                    return atoi(tokens->value);
                }
                tokens = tokens->next;
            }
        }
        config_options = config_options->next;
    }
    return -1;
}


decompiled_code:
__int64 __fastcall config_get_value(__int64 a1, const char *a2, const char *a3, int a4)
{
__int64 v7; // rbp
const char *v9; // rsi
__int64 v10; // rbx
const char *v12; // rsi

if ( !a1 )
return 0LL;
v7 = a1;
while ( 1 )
{
v9 = *(const char **)v7;
if ( a4 ? strcasecmp(a2, v9) == 0 : strcmp(a2, v9) == 0 )
{
v10 = *(_QWORD *)(v7 + 8);
if ( v10 )
break;
}
LABEL_5:
v7 = *(_QWORD *)(v7 + 16);
if ( !v7 )
return 0LL;
}
while ( 1 )
{
v12 = *(const char **)v10;
if ( a4 ? strcasecmp(a3, v12) == 0 : strcmp(a3, v12) == 0 )
return *(_QWORD *)(v10 + 8);
v10 = *(_QWORD *)(v10 + 16);
if ( !v10 )
goto LABEL_5;
}
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3, int a4)
{
__int64 v7; // rbp
const char *v9; // rsi
__int64 v10; // rbx
const char *v12; // rsi

if ( !a1 )
return 0LL;
v7 = a1;
while ( 1 )
{
v9 = *(const char **)v7;
if ( a4 ? strcasecmp(a2, v9) == 0 : strcmp(a2, v9) == 0 )
{
v10 = *(_QWORD *)(v7 + 8);
if ( v10 )
break;
}
LABEL_5:
v7 = *(_QWORD *)(v7 + 16);
if ( !v7 )
return 0LL;
}
while ( 1 )
{
v12 = *(const char **)v10;
if ( a4 ? strcasecmp(a3, v12) == 0 : strcmp(a3, v12) == 0 )
return *(_QWORD *)(v10 + 8);
v10 = *(_QWORD *)(v10 + 16);
if ( !v10 )
goto LABEL_5;
}
}

original_code:
char *config_get_value (struct config_sect *sects, char *section, char *token, int icase)
{
 while (sects) {
  if ((icase ? strcasecmp (section, sects->name) : strcmp (section, sects->name)) == 0) {
   struct config_token *tokens = sects->tokens;
   while (tokens) {
    if ((icase ? strcasecmp (token, tokens->token) : strcmp (token, tokens->token)) == 0) {
     return (tokens->value);
    }
    tokens = tokens->next;
   }
  }
  sects = sects->next;
 }
 return (((void *)0));
}

canonical_original_code:
char *config_get_value(struct config_sect *sects, char *section, char *token, int icase)
{
 while (sects) {
  if ((icase ? strcasecmp (section, sects->name) : strcmp (section, sects->name)) == 0) {
   struct config_token *tokens = sects->tokens;
   while (tokens) {
    if ((icase ? strcasecmp (token, tokens->token) : strcmp (token, tokens->token)) == 0) {
     return (tokens->value);
    }
    tokens = tokens->next;
   }
  }
  sects = sects->next;
 }
 return (((void *)0));
}

variable_types:
token
char *

variable_types: icase int


decompiled_code:
int __fastcall config_dump(__int64 a1)
{
__int64 v1; // rbp
int result; // eax
__int64 i; // rbx

if ( a1 )
{
v1 = a1;
do
{
result = printf("[%s]\n", *(const char **)v1);
for ( i = *(_QWORD *)(v1 + 8); i; i = *(_QWORD *)(i + 16) )
result = printf("%s\t%s\n", *(const char **)i, *(const char **)(i + 8));
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // rbp
int result; // eax
__int64 i; // rbx

if ( a1 )
{
v1 = a1;
do
{
result = printf("[%s]\n", *(const char **)v1);
for ( i = *(_QWORD *)(v1 + 8); i; i = *(_QWORD *)(i + 16) )
result = printf("%s\t%s\n", *(const char **)i, *(const char **)(i + 8));
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return result;
}

original_code:
void config_dump (struct config_sect *sects)
{
 while (sects) {
  printf ("[%s]\n", sects->name);
  struct config_token *tokens = sects->tokens;
  while (tokens) {
   printf ("%s\t%s\n", tokens->token, tokens->value);
   tokens = tokens->next;
  }
  sects = sects->next;
 }
}

canonical_original_code:
void config_dump(struct config_sect *sects)
{
 while (sects) {
  printf ("[%s]\n", sects->name);
  struct config_token *tokens = sects->tokens;
  while (tokens) {
   printf ("%s\t%s\n", tokens->token, tokens->value);
   tokens = tokens->next;
  }
  sects = sects->next;
 }
}

variable_types: struct config_sect { char *name; struct config_token { char *token; char *value; struct config_token *next; } *tokens; struct config_sect *next; } *


decompiled_code:
void __fastcall config_destroy(void *ptr)
{
char **v1; // r13
char **v2; // r12
char *v3; // rbx
char *v4; // rbp
char *v5; // r14
size_t v6; // rax
char *v7; // r14
size_t v8; // rax
char *v9; // rbp
size_t v10; // rax

if ( ptr )
{
v1 = (char **)ptr;
do
{
v2 = v1;
v1 = (char **)v1[2];
v3 = v2[1];
while ( v3 )
{
v4 = v3;
v3 = (char *)*((_QWORD *)v3 + 2);
v5 = *(char **)v4;
v6 = strlen(*(const char **)v4);
memset(v5, 0, v6);
free(v5);
v7 = (char *)*((_QWORD *)v4 + 1);
v8 = strlen(v7);
memset(v7, 0, v8);
free(v7);
*((_QWORD *)v4 + 2) = 0LL;
*(_OWORD *)v4 = 0LL;
free(v4);
}
v9 = *v2;
v10 = strlen(*v2);
memset(v9, 0, v10);
free(v9);
v2[2] = 0LL;
*(_OWORD *)v2 = 0LL;
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
char **v1; // r13
char **v2; // r12
char *v3; // rbx
char *v4; // rbp
char *v5; // r14
size_t v6; // rax
char *v7; // r14
size_t v8; // rax
char *v9; // rbp
size_t v10; // rax

if ( ptr )
{
v1 = (char **)ptr;
do
{
v2 = v1;
v1 = (char **)v1[2];
v3 = v2[1];
while ( v3 )
{
v4 = v3;
v3 = (char *)*((_QWORD *)v3 + 2);
v5 = *(char **)v4;
v6 = strlen(*(const char **)v4);
memset(v5, 0, v6);
free(v5);
v7 = (char *)*((_QWORD *)v4 + 1);
v8 = strlen(v7);
memset(v7, 0, v8);
free(v7);
*((_QWORD *)v4 + 2) = 0LL;
*(_OWORD *)v4 = 0LL;
free(v4);
}
v9 = *v2;
v10 = strlen(*v2);
memset(v9, 0, v10);
free(v9);
v2[2] = 0LL;
*(_OWORD *)v2 = 0LL;
free(v2);
}
while ( v1 );
}
}

original_code:
void config_destroy (struct config_sect *sects)
{
 while (sects) {
  struct config_sect *next = sects->next;
  struct config_token *token = sects->tokens;
  while (token) {
   struct config_token *next_token = token->next;
   free (memset (token->token, 0, strlen (token->token)));
   free (memset (token->value, 0, strlen (token->value)));
   free (memset (token, 0, sizeof (struct config_token)));
   token = next_token;
  }
  free (memset (sects->name, 0, strlen (sects->name)));
  free (memset (sects, 0, sizeof (struct config_sect)));
  sects = next;
 }
}

canonical_original_code:
void config_destroy(struct config_sect *sects)
{
 while (sects) {
  struct config_sect *next = sects->next;
  struct config_token *token = sects->tokens;
  while (token) {
   struct config_token *next_token = token->next;
   free (memset (token->token, 0, strlen (token->token)));
   free (memset (token->value, 0, strlen (token->value)));
   free (memset (token, 0, sizeof (struct config_token)));
   token = next_token;
  }
  free (memset (sects->name, 0, strlen (sects->name)));
  free (memset (sects, 0, sizeof (struct config_sect)));
  sects = next;
 }
}


repo: ggreg/libsimplenet

decompiled_code:
int socket_unix()
{
return socket(1, 1, 0);
}

canonical_decompiled_code:
int func1()
{
return socket(1, 1, 0);
}

original_code:
inline
int
socket_unix(void)
{
        return socket(1, SOCK_STREAM, 0);
}

canonical_original_code:
inline int socket_unix()
{
        return socket(1, SOCK_STREAM, 0);
}


decompiled_code:
int socket_tcp()
{
return socket(2, 1, 0);
}

canonical_decompiled_code:
int func2()
{
return socket(2, 1, 0);
}

original_code:
inline
int
socket_tcp(void)
{
        return socket(2, SOCK_STREAM, 0);
}

canonical_original_code:
inline int socket_tcp()
{
        return socket(2, SOCK_STREAM, 0);
}


decompiled_code:
__int64 __fastcall socket_init(int a1)
{
int v1; // er8
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v1 = setsockopt(a1, 1, 2, optval, 4u);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // er8
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v1 = setsockopt(a1, 1, 2, optval, 4u);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

original_code:
int
socket_init(int fd)
{
 int optval = 1;
 int err = setsockopt(fd, 1, 2,
   &optval, sizeof(optval));
 if (err == -1) return (*__errno_location ());
 return 0;
}

variable_types: fd int

variable_types: optval int

variable_types: err int


decompiled_code:
__int64 __fastcall socket_close(int a1)
{
int v1; // er8
__int64 result; // rax

v1 = close(a1);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

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

v1 = close(a1);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

original_code:
int
socket_close(int fd)
{
 int err = close(fd);
 if (err == -1) return (*__errno_location ());
 return 0;
}


decompiled_code:
__int64 __fastcall socket_set_nonblocking(int a1)
{
int v1; // er8
__int64 result; // rax

v1 = fcntl(a1, 4, 2048LL);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // er8
__int64 result; // rax

v1 = fcntl(a1, 4, 2048LL);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

original_code:
int
socket_set_nonblocking(int fd)
{
 int err = fcntl(fd, 4, 04000);
 if (err == -1) return (*__errno_location ());
 return 0;
}


decompiled_code:
__int64 __fastcall socket_set_tcpnodelay(int a1)
{
int v1; // er8
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v1 = setsockopt(a1, 1, 1, optval, 4u);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // er8
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v1 = setsockopt(a1, 1, 1, optval, 4u);
result = 0LL;
if ( v1 == -1 )
result = (unsigned int)*_errno_location();
return result;
}

original_code:
int
socket_set_tcpnodelay(int fd)
{
 int optval = 1;
 socklen_t optlen = sizeof(optval);
 int err = setsockopt(fd, 1, 1, &optval, optlen);
 if (err == -1) return (*__errno_location ());
 return 0;
}

canonical_original_code:
int socket_set_tcpnodelay(int fd)
{
 int optval = 1;
 unsigned int optlen = sizeof(optval);
 int err = setsockopt(fd, 1, 1, &optval, optlen);
 if (err == -1) return (*__errno_location ());
 return 0;
}

variable_types:
optlen
unsigned int


decompiled_code:
__int64 __fastcall socket_listen_unix(int fd, struct sockaddr *addr, char *src, int n)
{
size_t v6; // rax
int v7; // er8
__int64 result; // rax

addr->sa_family = 1;
v6 = strlen(src);
strncpy(addr->sa_data, src, v6);
if ( bind(fd, addr, 0x6Eu) == -1 || (v7 = listen(fd, n), result = 0LL, v7 == -1) )
result = (unsigned int)*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, struct sockaddr *addr, char *src, int n)
{
size_t v6; // rax
int v7; // er8
__int64 result; // rax

addr->sa_family = 1;
v6 = strlen(src);
strncpy(addr->sa_data, src, v6);
if ( bind(fd, addr, 0x6Eu) == -1 || (v7 = listen(fd, n), result = 0LL, v7 == -1) )
result = (unsigned int)*_errno_location();
return result;
}

original_code:
int
socket_listen_unix(int fd, struct sockaddr_un *addr,
  const char *path, int backlog)
{
 const int addr_family = 1;
 addr->sun_family = addr_family;
 strncpy(addr->sun_path, path, strlen(path));
 const size_t addrsize = sizeof(struct sockaddr_un);
 int err = bind(fd, (const struct sockaddr *) addr, addrsize);
 if (err == -1) return (*__errno_location ());
 err = listen(fd, backlog);
 if (err == -1) return (*__errno_location ());
 return 0;
}

canonical_original_code:
int socket_listen_unix(int fd, struct sockaddr_un *addr, char *path, int backlog)
{
 int addr_family = 1;
 addr->sun_family = addr_family;
 strncpy(addr->sun_path, path, strlen(path));
 unsigned long addrsize = sizeof(struct sockaddr_un);
 int err = bind(fd, (const struct sockaddr *) addr, addrsize);
 if (err == -1) return (*__errno_location ());
 err = listen(fd, backlog);
 if (err == -1) return (*__errno_location ());
 return 0;
}

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

variable_types:
path
char *

variable_types: backlog int

variable_types:
addrsize
unsigned long


decompiled_code:
__int64 __fastcall socket_listen_tcp(int fd, __int64 a2, const char *a3, __int16 a4, int a5)
{
int v7; // eax
unsigned int v8; // er8
socklen_t v9; // edx
int v10; // eax

*(_WORD *)a2 = 2;
v7 = inet_pton(2, a3, (void *)(a2 + 4));
v8 = 22;
if ( v7 )
{
if ( v7 == -1
|| (*(_WORD *)(a2 + 2) = _bswap_16(a4), bind(fd, (const struct sockaddr *)a2, v9) == -1)
|| (v10 = listen(fd, a5), v8 = 0, v10 == -1) )
{
v8 = *_errno_location();
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, __int64 a2, const char *a3, __int16 a4, int a5)
{
int v7; // eax
unsigned int v8; // er8
socklen_t v9; // edx
int v10; // eax

*(_WORD *)a2 = 2;
v7 = inet_pton(2, a3, (void *)(a2 + 4));
v8 = 22;
if ( v7 )
{
if ( v7 == -1
|| (*(_WORD *)(a2 + 2) = func0(a4), bind(fd, (const struct sockaddr *)a2, v9) == -1)
|| (v10 = listen(fd, a5), v8 = 0, v10 == -1) )
{
v8 = *_errno_location();
}
}
return v8;
}

original_code:
int
socket_listen_tcp(int fd, struct sockaddr_in *addr,
  const char *host, int port, int backlog)
{
 const int addr_family = 2;
 addr->sin_family = addr_family;
 int ok = inet_pton(addr_family, host, &addr->sin_addr.s_addr);
 if (ok == 0) return 22;
 if (ok == -1) return (*__errno_location ());
 addr->sin_port = htons(port);
 const size_t addrsize = sizeof(struct sockaddr_in);
 int err = bind(fd, (const struct sockaddr *) addr, addrsize);
 if (err == -1) return (*__errno_location ());
 err = listen(fd, backlog);
 if (err == -1) return (*__errno_location ());
 return 0;
}

canonical_original_code:
int socket_listen_tcp(int fd, struct sockaddr_in *addr, char *host, int port, int backlog)
{
 int addr_family = 2;
 addr->sin_family = addr_family;
 int ok = inet_pton(addr_family, host, &addr->sin_addr.s_addr);
 if (ok == 0) return 22;
 if (ok == -1) return (*__errno_location ());
 addr->sin_port = htons(port);
 unsigned long addrsize = sizeof(struct sockaddr_in);
 int err = bind(fd, (const struct sockaddr *) addr, addrsize);
 if (err == -1) return (*__errno_location ());
 err = listen(fd, backlog);
 if (err == -1) return (*__errno_location ());
 return 0;
}

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:
host
char *

variable_types: port int

variable_types: ok int

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


decompiled_code:
int __fastcall socket_connect_unix(int fd, const char *a2)
{
_BYTE v3[104]; // [rsp+0h] [rbp-88h] BYREF
int v4; // [rsp+68h] [rbp-20h]
__int16 v5; // [rsp+6Ch] [rbp-1Ch]

if ( fd == -1 || !a2 )
_assert_fail("fd != -1 && path_unix != NULL", "network_socket.c", 0x8Au, "socket_connect_unix");
memset(v3, 0, sizeof(v3));
*(_WORD *)v3 = 1;
v4 = 0;
v5 = 0;
strcpy(&v3[2], a2);
return connect(fd, (const struct sockaddr *)v3, 0x6Eu);
}

canonical_decompiled_code:
int __fastcall func9(int fd, const char *a2)
{
_BYTE v3[104]; // [rsp+0h] [rbp-88h] BYREF
int v4; // [rsp+68h] [rbp-20h]
__int16 v5; // [rsp+6Ch] [rbp-1Ch]

if ( fd == -1 || !a2 )
_assert_fail("fd != -1 && path_unix != NULL", "network_socket.c", 0x8Au, "socket_connect_unix");
memset(v3, 0, sizeof(v3));
*(_WORD *)v3 = 1;
v4 = 0;
v5 = 0;
strcpy(&v3[2], a2);
return connect(fd, (const struct sockaddr *)v3, 0x6Eu);
}

original_code:
inline
int
socket_connect_unix(const int fd, const char *path_unix)
{
        ((void) sizeof ((fd != -1 && path_unix != ((void *)0)) ? 1 : 0), __extension__ ({ if (fd != -1 && path_unix != ((void *)0)) ; else __assert_fail ("fd != -1 && path_unix != NULL", "network_socket.c", 138, __extension__ __PRETTY_FUNCTION__); }));
        struct sockaddr_un server_addr;
        const socklen_t addr_len = sizeof(server_addr);
        memset(&server_addr, 0, addr_len);
        server_addr.sun_family = 1;
        strcpy(server_addr.sun_path, path_unix);
        return connect(fd, (const struct sockaddr *) &server_addr, addr_len);
}

canonical_original_code:
inline int socket_connect_unix(int fd, char *path_unix)
{
        ((void) sizeof ((fd != -1 && path_unix != ((void *)0)) ? 1 : 0), __extension__ ({ if (fd != -1 && path_unix != ((void *)0)) ; else __assert_fail ("fd != -1 && path_unix != NULL", "network_socket.c", 138, __extension__ __PRETTY_FUNCTION__); }));
        struct sockaddr_un server_addr;
        unsigned int addr_len = sizeof(server_addr);
        memset(&server_addr, 0, addr_len);
        server_addr.sun_family = 1;
        strcpy(server_addr.sun_path, path_unix);
        return connect(fd, (struct sockaddr *) &server_addr, addr_len);
}

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

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


decompiled_code:
int __fastcall socket_connect_tcp(int fd, const char *a2, int a3)
{
void *v3; // rdx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

if ( a3 <= 0 || a2 == 0LL || fd == -1 )
_assert_fail("fd != -1 && ip != NULL && port > 0", "network_socket.c", 0x9Bu, "socket_connect_tcp");
*(_DWORD *)&v5.sa_data[2] = 0;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(a3);
inet_pton(2, a2, v3);
*(_QWORD *)&v5.sa_data[6] = 0LL;
return connect(fd, &v5, 0x10u);
}

canonical_decompiled_code:
int __fastcall func10(int fd, const char *a2, int a3)
{
void *v3; // rdx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

if ( a3 <= 0 || a2 == 0LL || fd == -1 )
_assert_fail("fd != -1 && ip != NULL && port > 0", "network_socket.c", 0x9Bu, "socket_connect_tcp");
*(_DWORD *)&v5.sa_data[2] = 0;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func0(a3);
inet_pton(2, a2, v3);
*(_QWORD *)&v5.sa_data[6] = 0LL;
return connect(fd, &v5, 0x10u);
}

original_code:
inline
int
socket_connect_tcp(const int fd, const char *ip, const int port)
{
        ((void) sizeof ((fd != -1 && ip != ((void *)0) && port > 0) ? 1 : 0), __extension__ ({ if (fd != -1 && ip != ((void *)0) && port > 0) ; else __assert_fail ("fd != -1 && ip != NULL && port > 0", "network_socket.c", 155, __extension__ __PRETTY_FUNCTION__); }));
        struct sockaddr_in server_addr;
        const socklen_t addr_len = sizeof(server_addr);
        memset(&server_addr, 0, addr_len);
        server_addr.sin_family = 2;
        server_addr.sin_port = htons(port);
        inet_pton(2, ip, &server_addr.sin_addr.s_addr);
        memset(server_addr.sin_zero, 0, sizeof(server_addr.sin_zero));
        return connect(fd, (const struct sockaddr *) &server_addr, addr_len);
}

canonical_original_code:
inline int socket_connect_tcp(int fd, char *ip, int port)
{
        ((void) sizeof ((fd != -1 && ip != ((void *)0) && port > 0) ? 1 : 0), __extension__ ({ if (fd != -1 && ip != ((void *)0) && port > 0) ; else __assert_fail ("fd != -1 && ip != NULL && port > 0", "network_socket.c", 155, __extension__ __PRETTY_FUNCTION__); }));
        struct sockaddr_in server_addr;
        unsigned int addr_len = sizeof(server_addr);
        memset(&server_addr, 0, addr_len);
        server_addr.sin_family = 2;
        server_addr.sin_port = htons(port);
        inet_pton(2, ip, &server_addr.sin_addr.s_addr);
        memset(server_addr.sin_zero, 0, sizeof(server_addr.sin_zero));
        return connect(fd, (struct sockaddr *) &server_addr, addr_len);
}

variable_types:
ip
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]; }


decompiled_code:
__int64 __fastcall network_client_connect_tcp(unsigned int *a1, __int64 a2)
{
return socket_connect_tcp(*a1, *(_QWORD *)a2, *(unsigned int *)(a2 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, __int64 a2)
{
return socket_connect_tcp(*a1, *(_QWORD *)a2, *(unsigned int *)(a2 + 8));
}

original_code:
static
int
network_client_connect_tcp(struct network_client *client, const void *conf_)
{
    const struct socket_config_tcp *conf = conf_;
    return socket_connect_tcp(client->fd, conf->ip, conf->port);
}

canonical_original_code:
static int network_client_connect_tcp(struct network_client *client, void *conf_)
{
    struct socket_config_tcp *conf = conf_;
    return socket_connect_tcp(client->fd, conf->ip, conf->port);
}

variable_types: struct network_client { int fd; enum socket_type_t { SOCKET_UNIX=0, SOCKET_TCP=1, SOCKET_INVALID=2 } type; } *

variable_types: struct socket_config_tcp { char *ip; int port; int backlog; } *

user_defined_types: struct network_client { int fd; enum socket_type_t type; }


decompiled_code:
__int64 __fastcall network_client_connect_unix(unsigned int *a1, _QWORD *a2)
{
return socket_connect_unix(*a1, *a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, _QWORD *a2)
{
return socket_connect_unix(*a1, *a2);
}

original_code:
static
int
network_client_connect_unix(struct network_client *client, const void *conf_)
{
    const struct socket_config_unix *conf = conf_;
    return socket_connect_unix(client->fd, conf->path);
}

canonical_original_code:
static int network_client_connect_unix(struct network_client *client, void *conf_)
{
    struct socket_config_unix *conf = conf_;
    return socket_connect_unix(client->fd, conf->path);
}

variable_types: struct socket_config_unix { char *path; int backlog; } *

user_defined_types: enum socket_type_t { SOCKET_UNIX=0, SOCKET_TCP=1, SOCKET_INVALID=2 }


decompiled_code:
void __fastcall network_client_free(void *a1)
{
if ( !a1 )
_assert_fail("client != NULL", "network_client.c", 0x41u, "network_client_free");
free(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
if ( !a1 )
_assert_fail("client != NULL", "network_client.c", 0x41u, "network_client_free");
free(a1);
}

original_code:
void
network_client_free(struct network_client *client)
{
    ((void) sizeof ((client != ((void *)0)) ? 1 : 0), __extension__ ({ if (client != ((void *)0)) ; else __assert_fail ("client != NULL", "network_client.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    free(client);
}


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

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

original_code:
int
network_client_close(struct network_client *client)
{
    return socket_close(client->fd);
}


decompiled_code:
__int64 __fastcall network_client_connect(__int64 a1)
{
return ((__int64 (*)(void))*(&socket_type_ops + 2 * *(unsigned int *)(a1 + 4) + 1))();
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return ((__int64 (*)(void))*(&socket_type_ops + 2 * *(unsigned int *)(a1 + 4) + 1))();
}

original_code:
int
network_client_connect(struct network_client *client, void *conf)
{
    if (client->type < SOCKET_UNIX && client->type >= SOCKET_INVALID)
 return 22;
    networkclient_connect_t socket_connect;
    socket_connect = socket_type_ops[client->type].connect;
    return socket_connect(client, conf);
}

canonical_original_code:
int network_client_connect(struct network_client *client, void *conf)
{
    if (client->type < SOCKET_UNIX && client->type >= SOCKET_INVALID)
 return 22;
    int (*socket_connect)(struct network_client *, void *);
    socket_connect = socket_type_ops[client->type].connect;
    return socket_connect(client, conf);
}

variable_types:
conf
void *

variable_types: int (*)(struct network_client { int fd; enum socket_type_t { SOCKET_UNIX=0, SOCKET_TCP=1, SOCKET_INVALID=2 } type; } *, void *)


decompiled_code:
__int64 __fastcall network_client_send(int *a1, __int64 a2, int a3)
{
int v3; // ebx
int v4; // ecx
const void *v5; // rax
size_t v6; // rdx
ssize_t v7; // rax

if ( !a3 )
return 0LL;
v3 = a3;
while ( 1 )
{
v5 = (const void *)simple_buffer_get_head_isra_0(*(_QWORD *)(a2 + 8));
v7 = write(*a1, v5, v6);
if ( !v7 )
return 11LL;
if ( v7 == -1 )
break;
simple_buffer_pull_isra_0(a2, v7);
v3 -= v4;
if ( !v3 )
return 0LL;
}
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, __int64 a2, int a3)
{
int v3; // ebx
int v4; // ecx
const void *v5; // rax
size_t v6; // rdx
ssize_t v7; // rax

if ( !a3 )
return 0LL;
v3 = a3;
while ( 1 )
{
v5 = (const void *)func7(*(_QWORD *)(a2 + 8));
v7 = write(*a1, v5, v6);
if ( !v7 )
return 11LL;
if ( v7 == -1 )
break;
func3(a2, v7);
v3 -= v4;
if ( !v3 )
return 0LL;
}
return (unsigned int)*_errno_location();
}

original_code:
int
network_client_send(struct network_client *client,
 struct simple_buffer *data, unsigned int len)
{
    while (len) {
 ssize_t n = write(client->fd, simple_buffer_get_head(data), len);
 if (n == 0) return 11;
 if (n == -1) return (*__errno_location ());
 simple_buffer_pull(data, n);
 len -= n;
    }
    return 0;
}

canonical_original_code:
int network_client_send(struct network_client *client, struct simple_buffer *data, unsigned int len)
{
    while (len) {
 long n = write(client->fd, simple_buffer_get_head(data), len);
 if (n == 0) return 11;
 if (n == -1) return (*__errno_location ());
 simple_buffer_pull(data, n);
 len -= n;
    }
    return 0;
}

variable_types: struct simple_buffer { char *data; char *head; char *tail; char *userptr; unsigned int size; unsigned int max_size; unsigned int chunk_size; } *

variable_types:
len
unsigned int

variable_types: n long


decompiled_code:
__int64 __fastcall network_client_recv(int *a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // ebx
int v5; // edx
void *v6; // rax
size_t v7; // rdx
ssize_t v8; // rax

simple_buffer_resize_tail_isra_0(a2, a3);
if ( !a3 )
return 0LL;
v4 = a3;
while ( 1 )
{
v6 = (void *)simple_buffer_get_tail_isra_0(*(_QWORD *)(a2 + 16));
v8 = read(*a1, v6, v7);
if ( !v8 )
return 11LL;
if ( v8 == -1 )
break;
simple_buffer_move_tail_isra_0((_DWORD *)a2, v8);
v4 -= v5;
if ( !v4 )
return 0LL;
}
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // ebx
int v5; // edx
void *v6; // rax
size_t v7; // rdx
ssize_t v8; // rax

func5(a2, a3);
if ( !a3 )
return 0LL;
v4 = a3;
while ( 1 )
{
v6 = (void *)func6(*(_QWORD *)(a2 + 16));
v8 = read(*a1, v6, v7);
if ( !v8 )
return 11LL;
if ( v8 == -1 )
break;
func2((_DWORD *)a2, v8);
v4 -= v5;
if ( !v4 )
return 0LL;
}
return (unsigned int)*_errno_location();
}

original_code:
int
network_client_recv(struct network_client *client,
 struct simple_buffer *data, unsigned int len)
{
    simple_buffer_resize_tail(data, len);
    while (len) {
 ssize_t n = read(client->fd, simple_buffer_get_tail(data), len);
 if (n == 0)return 11;
 if (n == -1) return (*__errno_location ());
 simple_buffer_move_tail(data, n);
 len -= n;
    }
    return 0;
}

canonical_original_code:
int network_client_recv(struct network_client *client, struct simple_buffer *data, unsigned int len)
{
    simple_buffer_resize_tail(data, len);
    while (len) {
 long n = read(client->fd, simple_buffer_get_tail(data), len);
 if (n == 0)return 11;
 if (n == -1) return (*__errno_location ());
 simple_buffer_move_tail(data, n);
 len -= n;
    }
    return 0;
}

user_defined_types: struct simple_buffer { char *data; char *head; char *tail; char *userptr; unsigned int size; unsigned int max_size; unsigned int chunk_size; }


original_code:
static inline
int
simple_buffer_resize(struct simple_buffer * const buf, size_t newsize)
{
 if (newsize != buf->max_size) {
  size_t head_offset = buf->head - buf->data;
  size_t tail_offset = buf->tail - buf->data;
  size_t userptr_offset = buf->userptr - buf->data;
  buf->max_size = (newsize/buf->chunk_size+1) * buf->chunk_size;
  char *newbufdata = realloc(buf->data, buf->max_size);
  if (newbufdata == ((void *)0))
   return (*__errno_location ());
  buf->data = newbufdata;
  buf->head = buf->data + head_offset;
  buf->tail = buf->data + tail_offset;
  buf->userptr = buf->data + userptr_offset;
 }
 return 0;
}

canonical_original_code:
static inline int simple_buffer_resize(struct simple_buffer *buf, unsigned long newsize)
{
 if (newsize != buf->max_size) {
  unsigned long head_offset = buf->head - buf->data;
  unsigned long tail_offset = buf->tail - buf->data;
  unsigned long userptr_offset = buf->userptr - buf->data;
  buf->max_size = (newsize/buf->chunk_size+1) * buf->chunk_size;
  char *newbufdata = realloc(buf->data, buf->max_size);
  if (newbufdata == ((void *)0))
   return (*__errno_location ());
  buf->data = newbufdata;
  buf->head = buf->data + head_offset;
  buf->tail = buf->data + tail_offset;
  buf->userptr = buf->data + userptr_offset;
 }
 return 0;
}

variable_types:
newsize
unsigned long

variable_types:
newbufdata
char *


decompiled_code:
__int64 __fastcall client_callback_do_request(const char *a1, __int64 a2, __int64 a3, _DWORD *a4)
{
size_t v6; // rax
const void *v7; // rax
size_t v8; // rdx

v6 = strlen(a1);
simple_buffer_append_isra_0(a2, a1, v6);
simple_buffer_size_isra_0(*(_DWORD *)(a3 + 32));
v7 = (const void *)simple_buffer_get_head_isra_0(*(_QWORD *)(a3 + 8));
simple_buffer_append_isra_0(a2, v7, v8);
simple_buffer_clear_isra_0(a3);
*a4 = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2, __int64 a3, _DWORD *a4)
{
size_t v6; // rax
const void *v7; // rax
size_t v8; // rdx

v6 = strlen(a1);
func3(a2, a1, v6);
func5(*(_DWORD *)(a3 + 32));
v7 = (const void *)func4(*(_QWORD *)(a3 + 8));
func3(a2, v7, v8);
func2(a3);
*a4 = 1;
return 0LL;
}

original_code:
int
client_callback_do_request(void *data,
  struct simple_buffer *bufwrite,
  struct simple_buffer *bufread,
  int *done)
{
 simple_buffer_append(bufwrite, (char *) data, strlen(data));
 simple_buffer_append(bufwrite,
   simple_buffer_get_head(bufread),
   simple_buffer_size(bufread));
 simple_buffer_clear(bufread);
 *done = 1;
 return 0;
}

variable_types:
data
void *

variable_types:
bufread
struct simple_buffer *

variable_types:
done
int *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v4; // cf
bool v5; // zf
const char *v6; // r9
const char *v8; // rcx
const char *v9; // rsi
const char *v10; // rdi
const char **v11; // r13
__int64 v12; // rdi
__int64 v13; // rbp
char *v14; // rdi
__int64 i; // rcx
unsigned int v16; // er12
int *v17; // rax
const char *v18; // [rsp+0h] [rbp-68h] BYREF
int v19; // [rsp+8h] [rbp-60h]
__int64 v20[2]; // [rsp+10h] [rbp-58h] BYREF
void (**v21)(int, const char *, ...); // [rsp+20h] [rbp-48h] BYREF
char v22; // [rsp+28h] [rbp-40h] BYREF
__int64 (__fastcall *v23)(const char *, __int64, __int64, _DWORD *); // [rsp+30h] [rbp-38h]

v4 = (unsigned int)argc < 2;
v5 = argc == 2;
if ( argc > 2 )
{
v6 = argv[1];
v8 = (_BYTE *)(&loc_2 + 2);
v9 = "unix";
v10 = v6;
do
{
if ( !v8 )
break;
v4 = *v9 < (unsigned int)*v10;
v5 = *v9++ == *v10++;
--v8;
}
while ( v5 );
LOBYTE(envp) = (!v4 && !v5) - v4;
if ( !(_BYTE)envp )
{
v8 = "/tmp/simpleserver.socket";
v19 = 2;
v18 = "/tmp/simpleserver.socket";
}
if ( *v6 != 116 || v6[1] != 99 || v6[2] != 112 )
{
v11 = &v18;
v12 = 0LL;
goto LABEL_9;
}
if ( argc != 3 )
{
v11 = (const char **)v20;
v12 = 1LL;
v20[0] = (__int64)"127.0.0.1";
v20[1] = 0x200003039LL;
LABEL_9:
v13 = server_new(v12, 2LL, envp, v8, argv);
if ( v13 )
{
v14 = &v22;
for ( i = 8LL; i; --i )
{
*(_DWORD *)v14 = 0;
v14 += 4;
}
v21 = &syslog;
v23 = client_callback_do_request;
v16 = server_init(v13, &v21, "hello, ", 2048LL);
if ( !v16 )
server_listen(v13, v11);
server_stop(v13, v16);
exit(v16);
}
v17 = _errno_location();
exit(*v17);
}
}
usage(argv);
exit(22);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v4; // cf
bool v5; // zf
const char *v6; // r9
const char *v8; // rcx
const char *v9; // rsi
const char *v10; // rdi
const char **v11; // r13
__int64 v12; // rdi
__int64 v13; // rbp
char *v14; // rdi
__int64 i; // rcx
unsigned int v16; // er12
int *v17; // rax
const char *v18; // [rsp+0h] [rbp-68h] BYREF
int v19; // [rsp+8h] [rbp-60h]
__int64 v20[2]; // [rsp+10h] [rbp-58h] BYREF
void (**v21)(int, const char *, ...); // [rsp+20h] [rbp-48h] BYREF
char v22; // [rsp+28h] [rbp-40h] BYREF
__int64 (__fastcall *v23)(const char *, __int64, __int64, _DWORD *); // [rsp+30h] [rbp-38h]

v4 = (unsigned int)argc < 2;
v5 = argc == 2;
if ( argc > 2 )
{
v6 = argv[1];
v8 = (_BYTE *)(&loc_2 + 2);
v9 = "unix";
v10 = v6;
do
{
if ( !v8 )
break;
v4 = *v9 < (unsigned int)*v10;
v5 = *v9++ == *v10++;
--v8;
}
while ( v5 );
LOBYTE(envp) = (!v4 && !v5) - v4;
if ( !(_BYTE)envp )
{
v8 = "/tmp/simpleserver.socket";
v19 = 2;
v18 = "/tmp/simpleserver.socket";
}
if ( *v6 != 116 || v6[1] != 99 || v6[2] != 112 )
{
v11 = &v18;
v12 = 0LL;
goto LABEL_9;
}
if ( argc != 3 )
{
v11 = (const char **)v20;
v12 = 1LL;
v20[0] = (__int64)"127.0.0.1";
v20[1] = 0x200003039LL;
LABEL_9:
v13 = server_new(v12, 2LL, envp, v8, argv);
if ( v13 )
{
v14 = &v22;
for ( i = 8LL; i; --i )
{
*(_DWORD *)v14 = 0;
v14 += 4;
}
v21 = &syslog;
v23 = client_callback_do_request;
v16 = server_init(v13, &v21, "hello, ", 2048LL);
if ( !v16 )
server_listen(v13, v11);
server_stop(v13, v16);
exit(v16);
}
v17 = _errno_location();
exit(*v17);
}
}
func7(argv);
exit(22);
}

original_code:
int
main(int argc, char **argv)
{
    if (argc < 3) {
 usage(argv);
 exit(22);
    }
    int socket_type;
    void *conf;
    struct socket_config_unix unixcf;
    if (strncmp("unix", argv[1], 4) == 0) {
     unixcf.path = argv[2];
     conf = &unixcf;
     socket_type = SOCKET_UNIX;
    }
    struct socket_config_tcp tcpcf;
    if (strncmp("tcp", argv[1], 3) == 0) {
 if (argc < 4) {
  usage(argv);
  exit(22);
 }
 tcpcf.ip = argv[2];
 tcpcf.port = atoi(argv[3]);
 conf = &tcpcf;
 socket_type = SOCKET_TCP;
    };
    struct network_client *client = network_client_new(socket_type);
    if (client == ((void *)0)) {
     fprintf(stderr,
      "error in network_client_new(): %s\n",
      strerror((*__errno_location ())));
     exit(1);
    }
    struct simple_buffer *bufwrite = simple_buffer_new(getpagesize());
    simple_buffer_append(bufwrite, "client", 6);
    struct simple_buffer *bufread = simple_buffer_new(getpagesize());
    int err = network_client_connect(client, conf);
    if (err) {
     fprintf(stderr,
      "error in network_client_connect(): %s\n",
      strerror(err));
     exit(err);
    }
    err = network_client_send(client, bufwrite, 6);
    if (err) {
     fprintf(stderr,
      "error cannot write to socket: %s\n",
      strerror(err));
     goto end;
    }
    err = network_client_recv(client, bufread, 13);
    if (err) {
     fprintf(stderr,
      "error cannot read from socket: %s\n",
      strerror(err));
     goto end;
    }
    write(1, simple_buffer_get_head(bufread), 13);
    write(1, "\n", 1);
end:
    network_client_free(client);
    simple_buffer_free(bufread);
    simple_buffer_free(bufwrite);
    exit(err);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct socket_config_unix { char *path; int backlog; }

variable_types: struct socket_config_tcp { char *ip; int port; int backlog; }

variable_types: err int


decompiled_code:
void __fastcall simple_buffer_free(void *ptr)
{
void *v2; // rdi

if ( !ptr )
_assert_fail("buf != NULL", "network_buffer.h", 0x47u, "simple_buffer_free");
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

if ( !ptr )
_assert_fail("buf != NULL", "network_buffer.h", 0x47u, "simple_buffer_free");
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
static inline
void
simple_buffer_free(struct simple_buffer *buf)
{
 ((void) sizeof ((buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (buf != ((void *)0)) ; else __assert_fail ("buf != NULL", "network_buffer.h", 71, __extension__ __PRETTY_FUNCTION__); }));
 if (buf->data)
  free(buf->data);
 free(buf);
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v4; // cf
bool v5; // zf
const char *v6; // r9
__int64 v8; // rcx
const char *v9; // rsi
const char *v10; // rdi
const char **v11; // r15
__int64 v12; // rdi
__int64 v13; // rbp
unsigned int v14; // er12
_QWORD *v15; // r13
__int64 *v16; // r14
int v17; // eax
int v18; // er12
char *v19; // rax
const char *v20; // rdi
int v21; // eax
int v22; // eax
int v23; // er12
int v24; // eax
const void *v25; // rax
size_t v26; // rdx
char *v27; // rax
int *v28; // rax
char *v29; // rax
char *v30; // rax
const char **v31; // [rsp+0h] [rbp-48h] BYREF
const char *v32; // [rsp+10h] [rbp-38h] BYREF
int v33; // [rsp+18h] [rbp-30h]

v4 = (unsigned int)argc < 2;
v5 = argc == 2;
if ( argc > 2 )
{
v6 = argv[1];
v8 = 4LL;
v9 = "unix";
v10 = v6;
do
{
if ( !v8 )
break;
v4 = *v9 < (unsigned int)*v10;
v5 = *v9++ == *v10++;
--v8;
}
while ( v5 );
LOBYTE(envp) = (!v4 && !v5) - v4;
if ( !(_BYTE)envp )
{
envp = (const char **)argv[2];
v31 = envp;
}
if ( *v6 != 116 || v6[1] != 99 || v6[2] != 112 )
{
v11 = (const char **)&v31;
v12 = 0LL;
goto LABEL_9;
}
if ( argc != 3 )
{
v20 = argv[3];
v11 = &v32;
v32 = argv[2];
v21 = atoi(v20);
v12 = 1LL;
v33 = v21;
LABEL_9:
v13 = network_client_new(v12, v9, envp, v8, argv);
if ( v13 )
{
v14 = getpagesize();
v15 = simple_buffer_new(v14);
simple_buffer_append_constprop_0_isra_0((__int64)v15);
v16 = simple_buffer_new(v14);
v17 = network_client_connect(v13, v11);
v18 = v17;
if ( v17 )
{
v19 = strerror(v17);
fprintf(stderr, "error in network_client_connect(): %s\n", v19);
exit(v18);
}
v22 = network_client_send(v13, v15, 6LL);
v23 = v22;
if ( v22 )
{
v27 = strerror(v22);
fprintf(stderr, "error cannot write to socket: %s\n", v27);
}
else
{
v24 = network_client_recv(v13, v16, 13LL);
v23 = v24;
if ( v24 )
{
v30 = strerror(v24);
fprintf(stderr, "error cannot read from socket: %s\n", v30);
}
else
{
v25 = (const void *)simple_buffer_get_head_isra_0(v16[1]);
write(1, v25, v26);
write(1, "\n", 1uLL);
}
}
network_client_free(v13);
simple_buffer_free(v16);
simple_buffer_free(v15);
exit(v23);
}
v28 = _errno_location();
v29 = strerror(*v28);
fprintf(stderr, "error in network_client_new(): %s\n", v29);
exit(1);
}
}
usage(argv);
exit(22);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v4; // cf
bool v5; // zf
const char *v6; // r9
__int64 v8; // rcx
const char *v9; // rsi
const char *v10; // rdi
const char **v11; // r15
__int64 v12; // rdi
__int64 v13; // rbp
unsigned int v14; // er12
_QWORD *v15; // r13
__int64 *v16; // r14
int v17; // eax
int v18; // er12
char *v19; // rax
const char *v20; // rdi
int v21; // eax
int v22; // eax
int v23; // er12
int v24; // eax
const void *v25; // rax
size_t v26; // rdx
char *v27; // rax
int *v28; // rax
char *v29; // rax
char *v30; // rax
const char **v31; // [rsp+0h] [rbp-48h] BYREF
const char *v32; // [rsp+10h] [rbp-38h] BYREF
int v33; // [rsp+18h] [rbp-30h]

v4 = (unsigned int)argc < 2;
v5 = argc == 2;
if ( argc > 2 )
{
v6 = argv[1];
v8 = 4LL;
v9 = "unix";
v10 = v6;
do
{
if ( !v8 )
break;
v4 = *v9 < (unsigned int)*v10;
v5 = *v9++ == *v10++;
--v8;
}
while ( v5 );
LOBYTE(envp) = (!v4 && !v5) - v4;
if ( !(_BYTE)envp )
{
envp = (const char **)argv[2];
v31 = envp;
}
if ( *v6 != 116 || v6[1] != 99 || v6[2] != 112 )
{
v11 = (const char **)&v31;
v12 = 0LL;
goto LABEL_9;
}
if ( argc != 3 )
{
v20 = argv[3];
v11 = &v32;
v32 = argv[2];
v21 = atoi(v20);
v12 = 1LL;
v33 = v21;
LABEL_9:
v13 = network_client_new(v12, v9, envp, v8, argv);
if ( v13 )
{
v14 = getpagesize();
v15 = simple_buffer_new(v14);
func2((__int64)v15);
v16 = simple_buffer_new(v14);
v17 = network_client_connect(v13, v11);
v18 = v17;
if ( v17 )
{
v19 = strerror(v17);
fprintf(stderr, "error in network_client_connect(): %s\n", v19);
exit(v18);
}
v22 = network_client_send(v13, v15, 6LL);
v23 = v22;
if ( v22 )
{
v27 = strerror(v22);
fprintf(stderr, "error cannot write to socket: %s\n", v27);
}
else
{
v24 = network_client_recv(v13, v16, 13LL);
v23 = v24;
if ( v24 )
{
v30 = strerror(v24);
fprintf(stderr, "error cannot read from socket: %s\n", v30);
}
else
{
v25 = (const void *)func3(v16[1]);
write(1, v25, v26);
write(1, "\n", 1uLL);
}
}
network_client_free(v13);
func1(v16);
func1(v15);
exit(v23);
}
v28 = _errno_location();
v29 = strerror(*v28);
fprintf(stderr, "error in network_client_new(): %s\n", v29);
exit(1);
}
}
func4(argv);
exit(22);
}

canonical_original_code:
int main(int argc, char **argv)
{
    if (argc < 3) {
 usage(argv);
 exit(22);
    }
    int socket_type;
    void *conf;
    struct socket_config_unix unixcf;
    if (strncmp("unix", argv[1], 4) == 0) {
     unixcf.path = argv[2];
     conf = &unixcf;
     socket_type = SOCKET_UNIX;
    }
    struct socket_config_tcp tcpcf;
    if (strncmp("tcp", argv[1], 3) == 0) {
 if (argc < 4) {
  usage(argv);
  exit(22);
 }
 tcpcf.ip = argv[2];
 tcpcf.port = atoi(argv[3]);
 conf = &tcpcf;
 socket_type = SOCKET_TCP;
    };
    struct network_client *client = network_client_new(socket_type);
    if (client == ((void *)0)) {
     fprintf(stderr,
      "error in network_client_new(): %s\n",
      strerror((*__errno_location ())));
     exit(1);
    }
    struct simple_buffer *bufwrite = simple_buffer_new(getpagesize());
    simple_buffer_append(bufwrite, "client", 6);
    struct simple_buffer *bufread = simple_buffer_new(getpagesize());
    int err = network_client_connect(client, conf);
    if (err) {
     fprintf(stderr,
      "error in network_client_connect(): %s\n",
      strerror(err));
     exit(err);
    }
    err = network_client_send(client, bufwrite, 6);
    if (err) {
     fprintf(stderr,
      "error cannot write to socket: %s\n",
      strerror(err));
     goto end;
    }
    err = network_client_recv(client, bufread, 13);
    if (err) {
     fprintf(stderr,
      "error cannot read from socket: %s\n",
      strerror(err));
     goto end;
    }
    write(1, simple_buffer_get_head(bufread), 13);
    write(1, "\n", 1);
end:
    network_client_free(client);
    simple_buffer_free(bufread);
    simple_buffer_free(bufwrite);
    exit(err);
}

variable_types: struct network_client { int fd; enum socket_type_t { SOCKET_UNIX=0, SOCKET_TCP=1, SOCKET_INVALID=2 } type; } *

user_defined_types: struct socket_config_unix { char *path; int backlog; }

user_defined_types: struct socket_config_tcp { char *ip; int port; int backlog; }


decompiled_code:
__int64 __fastcall detect_stack_direction(unsigned __int64 a1)
{
__int64 result; // rax
char v2[4]; // [rsp+0h] [rbp-4h] BYREF

result = (unsigned int)stack_direction_cached;
if ( !stack_direction_cached )
{
if ( a1 <= (unsigned __int64)v2 )
{
if ( a1 < (unsigned __int64)v2 )
{
stack_direction_cached = 3;
result = 3LL;
}
else
{
stack_direction_cached = 1;
result = 1LL;
}
}
else
{
stack_direction_cached = 2;
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
__int64 result; // rax
char v2[4]; // [rsp+0h] [rbp-4h] BYREF

result = (unsigned int)stack_direction_cached;
if ( !stack_direction_cached )
{
if ( a1 <= (unsigned __int64)v2 )
{
if ( a1 < (unsigned __int64)v2 )
{
stack_direction_cached = 3;
result = 3LL;
}
else
{
stack_direction_cached = 1;
result = 1LL;
}
}
else
{
stack_direction_cached = 2;
result = 2LL;
}
}
return result;
}

original_code:
static enum stack_direction detect_stack_direction (void *before)
{
 if (stack_direction_cached == STACK_DIRECTION_UNSET)
 {
  int tmp;
  void *after = &tmp;
  if (after < before)
   stack_direction_cached = STACK_DIRECTION_DOWN;
  else if (after > before)
   stack_direction_cached = STACK_DIRECTION_UP;
  else
   stack_direction_cached = STACK_DIRECTION_UNKNOWN;
 }
 return stack_direction_cached;
}

canonical_original_code:
static enum stack_direction detect_stack_direction(void *before)
{
 if (stack_direction_cached == STACK_DIRECTION_UNSET)
 {
  int tmp;
  void *after = &tmp;
  if (after < before)
   stack_direction_cached = STACK_DIRECTION_DOWN;
  else if (after > before)
   stack_direction_cached = STACK_DIRECTION_UP;
  else
   stack_direction_cached = STACK_DIRECTION_UNKNOWN;
 }
 return stack_direction_cached;
}

variable_types:
before
void *

variable_types: tmp int

variable_types:
after
void *

return_type: enum stack_direction { STACK_DIRECTION_UNSET=0, STACK_DIRECTION_UNKNOWN=1, STACK_DIRECTION_DOWN=2, STACK_DIRECTION_UP=3 }


decompiled_code:
__int64 detect_stack_direction_wrong()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
static enum stack_direction detect_stack_direction_wrong (void *before)
{
 return STACK_DIRECTION_UNKNOWN;
}

canonical_original_code:
static enum stack_direction detect_stack_direction_wrong(void *before)
{
 return STACK_DIRECTION_UNKNOWN;
}

user_defined_types: enum stack_direction { STACK_DIRECTION_UNSET=0, STACK_DIRECTION_UNKNOWN=1, STACK_DIRECTION_DOWN=2, STACK_DIRECTION_UP=3 }


decompiled_code:
void stack_wrapper_wrong()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void stack_wrapper_wrong (stack_magic_callback callback,
 void *data, size_t dummysize,
 jmp_buf parent, jmp_buf child)
{
}

canonical_original_code:
static void stack_wrapper_wrong(void (*callback)(void *, struct __jmp_buf_tag [1], struct __jmp_buf_tag [1]), void *data, unsigned long dummysize, struct __jmp_buf_tag parent[1], struct __jmp_buf_tag child[1])
{
}

variable_types: void (*)(void *, struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1], struct __jmp_buf_tag [1])

variable_types:
dummysize
unsigned long

variable_types:
parent
struct __jmp_buf_tag [1]

variable_types:
child
struct __jmp_buf_tag [1]

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


decompiled_code:
int __fastcall stack_magic_setup(__int64 a1, __int64 a2, struct __jmp_buf_tag *a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 (__fastcall *v6)(unsigned __int64); // rax
void (*v7)(); // rdx
int v8; // eax
int result; // eax
void (*v11)(); // [rsp+10h] [rbp-48h]
__int64 v15; // [rsp+30h] [rbp-28h] BYREF
char *v16; // [rsp+38h] [rbp-20h] BYREF
char v17[24]; // [rsp+40h] [rbp-18h] BYREF

keep_variable((__int64)detect_stack_direction);
keep_variable((__int64)detect_stack_direction_wrong);
keep_variable((__int64)stack_wrapper);
keep_variable((__int64)stack_wrapper_wrong);
v15 = a1;
v6 = (__int64 (__fastcall *)(unsigned __int64))detect_stack_direction_wrong;
if ( one )
v6 = detect_stack_direction;
v7 = (void (*)())stack_wrapper;
if ( !one )
v7 = stack_wrapper_wrong;
v11 = v7;
v8 = ((__int64 (__fastcall *)(char **, __int64, void (*)(), void (*)()))v6)(&v16, a2, v7, stack_wrapper_wrong);
if ( v8 == 2 )
{
v16 = &v17[-v15 - a2];
}
else
{
if ( v8 != 3 )
stack_magic_setup_cold();
v16 = (char *)(v15 + 16 - (_QWORD)&v15);
}
result = setjmp(a3);
if ( !result )
result = ((__int64 (__fastcall *)(__int64, __int64, char *, struct __jmp_buf_tag *, __int64))v11)(
a5,
a6,
v16,
a3,
a4);
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, struct __jmp_buf_tag *a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 (__fastcall *v6)(unsigned __int64); // rax
void (*v7)(); // rdx
int v8; // eax
int result; // eax
void (*v11)(); // [rsp+10h] [rbp-48h]
__int64 v15; // [rsp+30h] [rbp-28h] BYREF
char *v16; // [rsp+38h] [rbp-20h] BYREF
char v17[24]; // [rsp+40h] [rbp-18h] BYREF

func3((__int64)detect_stack_direction);
func3((__int64)detect_stack_direction_wrong);
func3((__int64)stack_wrapper);
func3((__int64)stack_wrapper_wrong);
v15 = a1;
v6 = (__int64 (__fastcall *)(unsigned __int64))detect_stack_direction_wrong;
if ( one )
v6 = detect_stack_direction;
v7 = (void (*)())stack_wrapper;
if ( !one )
v7 = stack_wrapper_wrong;
v11 = v7;
v8 = ((__int64 (__fastcall *)(char **, __int64, void (*)(), void (*)()))v6)(&v16, a2, v7, stack_wrapper_wrong);
if ( v8 == 2 )
{
v16 = &v17[-v15 - a2];
}
else
{
if ( v8 != 3 )
func8();
v16 = (char *)(v15 + 16 - (_QWORD)&v15);
}
result = setjmp(a3);
if ( !result )
result = ((__int64 (__fastcall *)(__int64, __int64, char *, struct __jmp_buf_tag *, __int64))v11)(
a5,
a6,
v16,
a3,
a4);
return result;
}

original_code:
void stack_magic_setup (void *stackbase, size_t stacksize,
 jmp_buf parent, jmp_buf child,
 stack_magic_callback callback, void *data)
{
 keep_variable (detect_stack_direction);
 keep_variable (detect_stack_direction_wrong);
 keep_variable (stack_wrapper);
 keep_variable (stack_wrapper_wrong);
 enum stack_direction (*dsdfunc)(void *) = one ?
  detect_stack_direction : detect_stack_direction_wrong;
 void (*swfunc)(stack_magic_callback, void *, size_t, jmp_buf, jmp_buf) = one ?
  stack_wrapper : stack_wrapper_wrong;
 uintptr_t target = (uintptr_t) stackbase;
 uintptr_t source = (uintptr_t) ⌖
 size_t dummysize;
 switch (dsdfunc (&dummysize))
 {
  case STACK_DIRECTION_DOWN:
   dummysize = source - (target + stacksize) + (16);
   break;
  case STACK_DIRECTION_UP:
   dummysize = target - source + (16);
   break;
  default:
   do { abort (); } while (0);;
   break;
 }
 if (_setjmp (parent) == STACK_SJLJ_INITIAL)
  swfunc (callback, data, dummysize, parent, child);
}

canonical_original_code:
void stack_magic_setup(void *stackbase, unsigned long stacksize, struct __jmp_buf_tag parent[1], struct __jmp_buf_tag child[1], void (*callback)(void *, struct __jmp_buf_tag [1], struct __jmp_buf_tag [1]), void *data)
{
 keep_variable (detect_stack_direction);
 keep_variable (detect_stack_direction_wrong);
 keep_variable (stack_wrapper);
 keep_variable (stack_wrapper_wrong);
 enum stack_direction (*dsdfunc)(void *) = one ?
  detect_stack_direction : detect_stack_direction_wrong;
 void (*swfunc)(void (*)(void *, struct __jmp_buf_tag [1], struct __jmp_buf_tag [1]), void *, unsigned long, struct __jmp_buf_tag [1], struct __jmp_buf_tag [1]) = one ?
  stack_wrapper : stack_wrapper_wrong;
 unsigned long target = (uintptr_t) stackbase;
 unsigned long source = (uintptr_t) ⌖
 unsigned long dummysize;
 switch (dsdfunc (&dummysize))
 {
  case STACK_DIRECTION_DOWN:
   dummysize = source - (target + stacksize) + (16);
   break;
  case STACK_DIRECTION_UP:
   dummysize = target - source + (16);
   break;
  default:
   do { abort (); } while (0);;
   break;
 }
 if (_setjmp (parent) == STACK_SJLJ_INITIAL)
  swfunc (callback, data, dummysize, parent, child);
}

variable_types:
stackbase
void *

variable_types:
stacksize
unsigned long

variable_types: enum stack_direction { STACK_DIRECTION_UNSET=0, STACK_DIRECTION_UNKNOWN=1, STACK_DIRECTION_DOWN=2, STACK_DIRECTION_UP=3 } (*)(void *)

variable_types: void (*)(void (*)(void *, struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1], struct __jmp_buf_tag [1]), void *, unsigned long, struct __jmp_buf_tag [1], struct __jmp_buf_tag [1])

variable_types:
target
unsigned long

variable_types:
source
unsigned long


decompiled_code:
int __fastcall stack_magic_switch(struct __jmp_buf_tag *a1, struct __jmp_buf_tag *a2, int a3)
{
int result; // eax

result = setjmp(a1);
if ( !result )
longjmp(a2, a3);
return result;
}

canonical_decompiled_code:
int __fastcall func6(struct __jmp_buf_tag *a1, struct __jmp_buf_tag *a2, int a3)
{
int result; // eax

result = setjmp(a1);
if ( !result )
longjmp(a2, a3);
return result;
}

original_code:
int stack_magic_switch (jmp_buf source, jmp_buf target, int num)
{
 int res = _setjmp (source);
 if (res == STACK_SJLJ_INITIAL)
  longjmp (target, num);
 return res;
}

canonical_original_code:
int stack_magic_switch(struct __jmp_buf_tag source[1], struct __jmp_buf_tag target[1], int num)
{
 int res = _setjmp (source);
 if (res == STACK_SJLJ_INITIAL)
  longjmp (target, num);
 return res;
}

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]

variable_types:
target
struct __jmp_buf_tag [1]

variable_types: num int

variable_types: res int


decompiled_code:
void __fastcall __noreturn stack_wrapper(void (__fastcall *a1)(__int64, struct __jmp_buf_tag *, struct __jmp_buf_tag *), __int64 a2, signed __int64 a3, struct __jmp_buf_tag *a4, struct __jmp_buf_tag *a5)
{
void *v7; // rsp
__int64 v8; // [rsp+0h] [rbp-20h] BYREF

v7 = alloca(a3);
keep_variable((__int64)&v8);
stack_magic_switch(a5, a4, 3);
a1(a2, a4, a5);
while ( 1 )
stack_magic_switch(a5, a4, 4);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void (__fastcall *a1)(__int64, struct __jmp_buf_tag *, struct __jmp_buf_tag *), __int64 a2, signed __int64 a3, struct __jmp_buf_tag *a4, struct __jmp_buf_tag *a5)
{
void *v7; // rsp
__int64 v8; // [rsp+0h] [rbp-20h] BYREF

v7 = alloca(a3);
func3((__int64)&v8);
func6(a5, a4, 3);
a1(a2, a4, a5);
while ( 1 )
func6(a5, a4, 4);
}

original_code:
static void stack_wrapper (stack_magic_callback callback,
 void *data, size_t dummysize,
 jmp_buf parent, jmp_buf child)
{
 char dummy[dummysize];
 keep_variable (dummy);
 stack_magic_switch (child, parent, STACK_SJLJ_STARTING);
 callback (data, parent, child);
 while (1)
  stack_magic_switch (child, parent, STACK_SJLJ_STOPPING);
}

canonical_original_code:
static void stack_wrapper(void (*callback)(void *, struct __jmp_buf_tag [1], struct __jmp_buf_tag [1]), void *data, unsigned long dummysize, struct __jmp_buf_tag parent[1], struct __jmp_buf_tag child[1])
{
 char dummy[-1];
 keep_variable (dummy);
 stack_magic_switch (child, parent, STACK_SJLJ_STARTING);
 callback (data, parent, child);
 while (1)
  stack_magic_switch (child, parent, STACK_SJLJ_STOPPING);
}

variable_types:
data
void *

variable_types:
dummy
char [-1]

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


repo: ghills/StructTranslate

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+2h] [rbp-26h]
__int64 v6; // [rsp+Ah] [rbp-1Eh]
int v7; // [rsp+12h] [rbp-16h]
__int16 v8; // [rsp+16h] [rbp-12h]

v5 = 0xCA205CC93423039LL;
v6 = 0x723F670EE40177LL;
v4[0] = 117;
v7 = 354910773;
v8 = 128;
puts("BEFORE:");
strans_print_by_map(v4, &foo_map, 6LL);
putchar(10);
strans_reverse_bytes_by_map(v4, &foo_map, 6LL);
puts("AFTER:");
strans_print_by_map(v4, &foo_map, 6LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+2h] [rbp-26h]
__int64 v6; // [rsp+Ah] [rbp-1Eh]
int v7; // [rsp+12h] [rbp-16h]
__int16 v8; // [rsp+16h] [rbp-12h]

v5 = 0xCA205CC93423039LL;
v6 = 0x723F670EE40177LL;
v4[0] = 117;
v7 = 354910773;
v8 = 128;
puts("BEFORE:");
func13(v4, &foo_map, 6LL);
putchar(10);
func9(v4, &foo_map, 6LL);
puts("AFTER:");
func13(v4, &foo_map, 6LL);
return 0;
}

original_code:
int main( int argc, char * argv[] )
{
    foo_t foo;
    foo = foo_init_data;
    printf("BEFORE:\n");
    strans_print_by_map( &foo, foo_map, ( sizeof(foo_map) / sizeof(foo_map[0]) ) );
    putchar( '\n' );
    strans_reverse_bytes_by_map( &foo, foo_map, ( sizeof(foo_map) / sizeof(foo_map[0]) ) );
    printf("AFTER:\n");
    strans_print_by_map( &foo, foo_map, ( sizeof(foo_map) / sizeof(foo_map[0]) ) );
    return( 0 );
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct foo_t foo;
    foo = foo_init_data;
    printf("BEFORE:\n");
    strans_print_by_map( &foo, foo_map, ( sizeof(foo_map) / sizeof(foo_map[0]) ) );
    putchar( '\n' );
    strans_reverse_bytes_by_map( &foo, foo_map, ( sizeof(foo_map) / sizeof(foo_map[0]) ) );
    printf("AFTER:\n");
    strans_print_by_map( &foo, foo_map, ( sizeof(foo_map) / sizeof(foo_map[0]) ) );
    return( 0 );
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct foo_t { unsigned char uint8; unsigned short uint16; unsigned int uint32; struct subtype_t { unsigned int uint32; } subtype; unsigned short arr[4]; unsigned int uint32_2; }

user_defined_types: struct foo_t { unsigned char uint8; unsigned short uint16; unsigned int uint32; struct subtype_t subtype; unsigned short arr[4]; unsigned int uint32_2; }


decompiled_code:
char *__fastcall strans_reverse_bytes(char *a1, unsigned __int8 a2)
{
char *result; // rax
__int64 v3; // rax
__int64 v4; // rsi
char v5; // cl
char v6; // dl

if ( !a2 )
__assert_fail("cnt > 0", "stranslate.c", 0x65u, "strans_reverse_bytes");
if ( a2 >> 1 )
{
v3 = a2 - 1;
v4 = (__int64)&a1[(unsigned __int8)((a2 >> 1) - 1) + 1];
result = &a1[v3];
do
{
v5 = *result;
v6 = *a1++;
--result;
*(a1 - 1) = v5;
result[1] = v6;
}
while ( a1 != (char *)v4 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *a1, unsigned __int8 a2)
{
char *result; // rax
__int64 v3; // rax
__int64 v4; // rsi
char v5; // cl
char v6; // dl

if ( !a2 )
__assert_fail("cnt > 0", "stranslate.c", 0x65u, "strans_reverse_bytes");
if ( a2 >> 1 )
{
v3 = a2 - 1;
v4 = (__int64)&a1[(unsigned __int8)((a2 >> 1) - 1) + 1];
result = &a1[v3];
do
{
v5 = *result;
v6 = *a1++;
--result;
*(a1 - 1) = v5;
result[1] = v6;
}
while ( a1 != (char *)v4 );
}
return result;
}

original_code:
void strans_reverse_bytes
    (
    uint8_t * const data,
    uint8_t cnt
    )
{
uint8_t i;
((cnt > 0) ? (void) (0) : __assert_fail ("cnt > 0", "stranslate.c", 101, __extension__ __PRETTY_FUNCTION__));
for( i = 0; i < ( cnt / 2 ); i++ )
    {
    {uint8_t _t; _t = data[i]; data[i] = data[cnt-1-i]; data[cnt-1-i] = _t; };
    }
}

canonical_original_code:
void strans_reverse_bytes(unsigned char *data, unsigned char cnt)
{
unsigned char i;
((cnt > 0) ? (void) (0) : __assert_fail ("cnt > 0", "stranslate.c", 101, __extension__ __PRETTY_FUNCTION__));
for( i = 0; i < ( cnt / 2 ); i++ )
    {
    {unsigned char _t; _t = data[i]; data[i] = data[cnt-1-i]; data[cnt-1-i] = _t; };
    }
}

variable_types:
data
unsigned char *

variable_types:
cnt
unsigned char

variable_types:
i
unsigned char


decompiled_code:
__int64 __fastcall reverse_bytes_by_map(__int64 a1, unsigned __int16 *a2, __int16 a3, char a4)
{
unsigned __int16 v4; // dx
unsigned __int16 *v6; // r14
unsigned __int8 v7; // r12
__int64 result; // rax
__int64 v9; // r13
unsigned __int16 v10; // r15
__int64 v11; // rsi

if ( !a3 )
__assert_fail("map_count > 0", "stranslate.c", 0x33u, "reverse_bytes_by_map");
v4 = a3 - 1;
v6 = a2;
v7 = a4 - 1;
result = 3LL * v4;
v9 = (__int64)&a2[12 * v4 + 12];
do
{
if ( !v6[1] )
__assert_fail("map[i].elem_count > 0", "stranslate.c", 0x37u, "reverse_bytes_by_map");
if ( *v6 != 1 )
{
v10 = 0;
do
{
v11 = *((_QWORD *)v6 + 1);
if ( v11 )
{
if ( !a4 )
{
perror("Recursion Depth");
exit(-1);
}
result = reverse_bytes_by_map(a1 + v6[2] + (__int64)(v10 * *v6), v11, v6[8], v7);
}
else
{
result = (__int64)strans_reverse_bytes((char *)(a1 + v6[2] + (__int64)(*v6 * v10)), *v6);
}
++v10;
}
while ( v6[1] > v10 );
}
v6 += 12;
}
while ( v6 != (unsigned __int16 *)v9 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int16 *a2, __int16 a3, char a4)
{
unsigned __int16 v4; // dx
unsigned __int16 *v6; // r14
unsigned __int8 v7; // r12
__int64 result; // rax
__int64 v9; // r13
unsigned __int16 v10; // r15
__int64 v11; // rsi

if ( !a3 )
__assert_fail("map_count > 0", "stranslate.c", 0x33u, "reverse_bytes_by_map");
v4 = a3 - 1;
v6 = a2;
v7 = a4 - 1;
result = 3LL * v4;
v9 = (__int64)&a2[12 * v4 + 12];
do
{
if ( !v6[1] )
__assert_fail("map[i].elem_count > 0", "stranslate.c", 0x37u, "reverse_bytes_by_map");
if ( *v6 != 1 )
{
v10 = 0;
do
{
v11 = *((_QWORD *)v6 + 1);
if ( v11 )
{
if ( !a4 )
{
perror("Recursion Depth");
exit(-1);
}
result = func8(a1 + v6[2] + (__int64)(v10 * *v6), v11, v6[8], v7);
}
else
{
result = (__int64)func7((char *)(a1 + v6[2] + (__int64)(*v6 * v10)), *v6);
}
++v10;
}
while ( v6[1] > v10 );
}
v6 += 12;
}
while ( v6 != (unsigned __int16 *)v9 );
return result;
}

original_code:
static void reverse_bytes_by_map
    (
    void * const data,
    type_map_t const * const
                 map,
    uint16_t map_count,
    uint8_t iters_remain
    )
{
uint16_t i;
uint16_t j;
((map_count > 0) ? (void) (0) : __assert_fail ("map_count > 0", "stranslate.c", 51, __extension__ __PRETTY_FUNCTION__));
for( i = 0; i < map_count; i++ )
    {
    ((map[i].elem_count > 0) ? (void) (0) : __assert_fail ("map[i].elem_count > 0", "stranslate.c", 55, __extension__ __PRETTY_FUNCTION__));
    if( map[i].elem_size == 1 )
        {
        continue;
        }
    for( j = 0; j < map[i].elem_count; j++ )
        {
        if( map[i].type_map )
            {
            if( iters_remain > 0 )
                {
                reverse_bytes_by_map( (void *)( (uint8_t *)data + map[i].offset + (j * map[i].elem_size)), map[i].type_map, map[i].type_count, iters_remain - 1 );
                }
            else
                {
                perror("Recursion Depth");
                exit(-1);
                }
            }
        else
            {
            strans_reverse_bytes( (void *)( (uint8_t *)data + map[i].offset + (j * map[i].elem_size)), map[i].elem_size );
            }
        }
    }
}

canonical_original_code:
static void reverse_bytes_by_map(void *data, struct type_map_t *map, unsigned short map_count, unsigned char iters_remain)
{
unsigned short i;
unsigned short j;
((map_count > 0) ? (void) (0) : __assert_fail ("map_count > 0", "stranslate.c", 51, __extension__ __PRETTY_FUNCTION__));
for( i = 0; i < map_count; i++ )
    {
    ((map[i].elem_count > 0) ? (void) (0) : __assert_fail ("map[i].elem_count > 0", "stranslate.c", 55, __extension__ __PRETTY_FUNCTION__));
    if( map[i].elem_size == 1 )
        {
        continue;
        }
    for( j = 0; j < map[i].elem_count; j++ )
        {
        if( map[i].type_map )
            {
            if( iters_remain > 0 )
                {
                reverse_bytes_by_map( (void *)( (unsigned char *)data + map[i].offset + (j * map[i].elem_size)), map[i].type_map, map[i].type_count, iters_remain - 1 );
                }
            else
                {
                perror("Recursion Depth");
                exit(-1);
                }
            }
        else
            {
            strans_reverse_bytes( (void *)( (unsigned char *)data + map[i].offset + (j * map[i].elem_size)), map[i].elem_size );
            }
        }
    }
}

variable_types: struct type_map_t { unsigned short elem_size; unsigned short elem_count; unsigned short offset; void *type_map; unsigned short type_count; } *

variable_types:
i
unsigned short

variable_types:
j
unsigned short


decompiled_code:
__int64 __fastcall strans_reverse_bytes_by_map(__int64 a1, unsigned __int16 *a2, __int16 a3)
{
return reverse_bytes_by_map(a1, a2, a3, 255);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int16 *a2, __int16 a3)
{
return func8(a1, a2, a3, 255);
}

original_code:
void strans_reverse_bytes_by_map
    (
    void * const data,
    type_map_t const * const
                 map,
    uint16_t map_count
    )
{
reverse_bytes_by_map( data, map, map_count, ( 255 ) );
}

canonical_original_code:
void strans_reverse_bytes_by_map(void *data, struct type_map_t *map, unsigned short map_count)
{
reverse_bytes_by_map( data, map, map_count, ( 255 ) );
}

user_defined_types: struct type_map_t { unsigned short elem_size; unsigned short elem_count; unsigned short offset; void *type_map; unsigned short type_count; }


decompiled_code:
int __fastcall print_n_bytes(unsigned __int8 *a1, __int16 a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi
int result; // eax

if ( a2 )
{
v2 = a1;
v3 = (__int64)&a1[(unsigned __int16)(a2 - 1) + 1];
do
{
v4 = *v2++;
result = printf("%02X ", v4);
}
while ( v2 != (unsigned __int8 *)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int8 *a1, __int16 a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi
int result; // eax

if ( a2 )
{
v2 = a1;
v3 = (__int64)&a1[(unsigned __int16)(a2 - 1) + 1];
do
{
v4 = *v2++;
result = printf("%02X ", v4);
}
while ( v2 != (unsigned __int8 *)v3 );
}
return result;
}

original_code:
static void print_n_bytes
    (
    uint8_t const * const
                data,
    uint16_t cnt
    )
{
uint16_t i;
for( i = 0; i < cnt; i++ )
    {
    printf( "%02X ", data[i] );
    }
}

canonical_original_code:
static void print_n_bytes(unsigned char *data, unsigned short cnt)
{
unsigned short i;
for( i = 0; i < cnt; i++ )
    {
    printf( "%02X ", data[i] );
    }
}

variable_types:
cnt
unsigned short


decompiled_code:
int __fastcall print_n_elements(unsigned __int8 *a1, __int16 a2, unsigned __int16 a3)
{
__int64 v4; // r12
int v5; // ebp
unsigned __int8 *v7; // rdi
int result; // eax

if ( a2 )
{
v4 = a3;
v5 = 0;
do
{
++v5;
putchar(91);
putchar(32);
v7 = a1;
a1 += v4;
print_n_bytes(v7, a3);
result = putchar(93);
}
while ( a2 != (_WORD)v5 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(unsigned __int8 *a1, __int16 a2, unsigned __int16 a3)
{
__int64 v4; // r12
int v5; // ebp
unsigned __int8 *v7; // rdi
int result; // eax

if ( a2 )
{
v4 = a3;
v5 = 0;
do
{
++v5;
putchar(91);
putchar(32);
v7 = a1;
a1 += v4;
func10(v7, a3);
result = putchar(93);
}
while ( a2 != (_WORD)v5 );
}
return result;
}

original_code:
static void print_n_elements
    (
    uint8_t const * const
                data,
    uint16_t cnt,
    uint16_t elem_sz
    )
{
uint16_t i;
for( i = 0; i < cnt; i++ )
    {
    putchar('[');
    putchar(' ');
    print_n_bytes( data + ( elem_sz * i ), elem_sz );
    putchar(']');
    }
}

canonical_original_code:
static void print_n_elements(unsigned char *data, unsigned short cnt, unsigned short elem_sz)
{
unsigned short i;
for( i = 0; i < cnt; i++ )
    {
    putchar('[');
    putchar(' ');
    print_n_bytes( data + ( elem_sz * i ), elem_sz );
    putchar(']');
    }
}


decompiled_code:
int __fastcall print_by_map(__int64 a1, unsigned __int16 *a2, __int16 a3, unsigned __int8 a4)
{
__int64 v5; // r14
unsigned __int8 v6; // r15
unsigned __int16 *v7; // rbp
int v8; // ebx
__int16 v9; // si
int result; // eax
unsigned __int16 v11; // bx

if ( a3 )
{
v5 = (__int64)&a2[12 * (unsigned __int16)(a3 - 1) + 12];
v6 = a4 + 1;
v7 = a2;
do
{
v8 = 0;
if ( a4 )
{
do
{
++v8;
putchar(32);
putchar(32);
}
while ( a4 != (_BYTE)v8 );
}
v9 = v7[1];
if ( *((_QWORD *)v7 + 1) )
{
v11 = 0;
if ( v9 )
{
do
{
putchar(123);
putchar(10);
if ( a4 > 9u )
puts("MAX DEPTH REACHED");
else
print_by_map(a1 + v7[2] + (__int64)(v11 * *v7), *((_QWORD *)v7 + 1), v7[8], v6);
++v11;
putchar(125);
}
while ( v7[1] > v11 );
}
}
else
{
print_n_elements((unsigned __int8 *)(a1 + v7[2]), v9, *v7);
}
v7 += 12;
result = putchar(10);
}
while ( (unsigned __int16 *)v5 != v7 );
}
return result;
}

original_code:
static void print_by_map
    (
    void const * const
                 data,
    type_map_t const * const
                 map,
    uint16_t map_count,
    uint8_t iter_depth
    )
{
uint16_t i;
uint16_t j;
uint8_t * ptr;
uint8_t tab_i;
ptr = (uint8_t *)data;
for( i = 0; i < map_count; i++ )
    {
    for( tab_i = 0; tab_i < iter_depth; tab_i++ )
        {
        putchar(' ');
        putchar(' ');
        }
    if( map[i].type_map )
        {
        for( j = 0; j < map[i].elem_count; j++ )
            {
            putchar('{');
            putchar('\n');
            if( iter_depth < ( 10 ) )
                {
                print_by_map( &ptr[map[i].offset] + (j*map[i].elem_size), map[i].type_map, map[i].type_count, iter_depth + 1 );
                }
            else
                {
                printf("MAX DEPTH REACHED\n");
                }
            putchar('}');
            }
        }
    else
        {
        print_n_elements( &ptr[ map[i].offset ], map[i].elem_count, map[i].elem_size );
        }
    putchar('\n');
    }
}

canonical_original_code:
static void print_by_map(void *data, struct type_map_t *map, unsigned short map_count, unsigned char iter_depth)
{
unsigned short i;
unsigned short j;
unsigned char *ptr;
unsigned char tab_i;
ptr = (unsigned char *)data;
for( i = 0; i < map_count; i++ )
    {
    for( tab_i = 0; tab_i < iter_depth; tab_i++ )
        {
        putchar(' ');
        putchar(' ');
        }
    if( map[i].type_map )
        {
        for( j = 0; j < map[i].elem_count; j++ )
            {
            putchar('{');
            putchar('\n');
            if( iter_depth < ( 10 ) )
                {
                print_by_map( &ptr[map[i].offset] + (j*map[i].elem_size), map[i].type_map, map[i].type_count, iter_depth + 1 );
                }
            else
                {
                printf("MAX DEPTH REACHED\n");
                }
            putchar('}');
            }
        }
    else
        {
        print_n_elements( &ptr[ map[i].offset ], map[i].elem_count, map[i].elem_size );
        }
    putchar('\n');
    }
}

variable_types:
ptr
unsigned char *


decompiled_code:
int __fastcall strans_print_by_map(__int64 a1, unsigned __int16 *a2, __int16 a3)
{
return print_by_map(a1, a2, a3, 0);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, unsigned __int16 *a2, __int16 a3)
{
return func12(a1, a2, a3, 0);
}

original_code:
void strans_print_by_map
    (
    void const * const
                 data,
    type_map_t const * const
                 map,
    uint16_t map_count
    )
{
print_by_map( data, map, map_count, 0 );
}

canonical_original_code:
void strans_print_by_map(void *data, struct type_map_t *map, unsigned short map_count)
{
print_by_map( data, map, map_count, 0 );
}


Usage

decompiled_code:
void __fastcall __noreturn Usage(int a1, const char *a2)
{
bool v2; // zf
FILE *v3; // rdi

v2 = a1 == 0;
v3 = (FILE *)stdout;
if ( v2 )
v3 = stderr;
fprintf(
v3,
"Usage: %s [OPTIONS]...\n"
"\t -p pid - process ID to send signal to\n"
"\t -d delay - post trigger delay (ms)\n"
"\t -t threshold - Sound power threshold at which to send signal\n"
"\t -o out_file - Output filename (default stdout)\n"
"\t -i in_file - file to get input (default stdin)\n"
"\n"
"\n"
"Example:\n"
" $ arecord -D hw:1,0 -f S16_LE | %s -p `pidof raspivid` -d 1000\n",
a2,
a2);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int a1, const char *a2)
{
bool v2; // zf
FILE *v3; // rdi

v2 = a1 == 0;
v3 = (FILE *)stdout;
if ( v2 )
v3 = stderr;
fprintf(
v3,
"Usage: %s [OPTIONS]...\n"
"\t -p pid - process ID to send signal to\n"
"\t -d delay - post trigger delay (ms)\n"
"\t -t threshold - Sound power threshold at which to send signal\n"
"\t -o out_file - Output filename (default stdout)\n"
"\t -i in_file - file to get input (default stdin)\n"
"\n"
"\n"
"Example:\n"
" $ arecord -D hw:1,0 -f S16_LE | %s -p `pidof raspivid` -d 1000\n",
a2,
a2);
exit(-1);
}

original_code:
void Usage(int asked, char *argv0)
{
   fprintf(asked ? stdout : stderr,
      "Usage: %s [OPTIONS]...\n"
           "\t -p pid - process ID to send signal to\n"
           "\t -d delay - post trigger delay (ms)\n"
           "\t -t threshold - Sound power threshold at which to send signal\n"
           "\t -o out_file - Output filename (default stdout)\n"
           "\t -i in_file - file to get input (default stdin)\n\n\n"
           "Example:\n"
           "   $ arecord -D hw:1,0 -f S16_LE | %s -p `pidof raspivid` -d 1000\n"
      ,argv0, argv0);
   exit(-1);
}

variable_types: asked int


repo: ghorn/mathlib

decompiled_code:
__int64 __fastcall xyz_memcpy(__m128i *a1, const __m128i *a2)
{
__int64 result; // rax

*a1 = _mm_loadu_si128(a2);
result = a2[1].m128i_i64[0];
a1[1].m128i_i64[0] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__m128i *a1, const __m128i *a2)
{
__int64 result; // rax

*a1 = _mm_loadu_si128(a2);
result = a2[1].m128i_i64[0];
a1[1].m128i_i64[0] = result;
return result;
}

original_code:
void
xyz_memcpy( xyz_t * x1, const xyz_t * const x0)
{
  memcpy( x1, x0, sizeof(xyz_t) );
}

canonical_original_code:
void xyz_memcpy(struct xyz_t *x1, struct xyz_t *x0)
{
  memcpy( x1, x0, sizeof(xyz_t) );
}

variable_types: struct xyz_t { double x; double y; double z; } *


decompiled_code:
void __fastcall xyz_set_all(double *a1, double a2)
{
*a1 = a2;
a1[1] = a2;
a1[2] = a2;
}

canonical_decompiled_code:
void __fastcall func1(double *a1, double a2)
{
*a1 = a2;
a1[1] = a2;
a1[2] = a2;
}

original_code:
void
xyz_set_all( xyz_t * xyz, double val)
{
  xyz->x = val;
  xyz->y = val;
  xyz->z = val;
}

canonical_original_code:
void xyz_set_all(struct xyz_t *xyz, double val)
{
  xyz->x = val;
  xyz->y = val;
  xyz->z = val;
}

variable_types: val double

user_defined_types: struct xyz_t { double x; double y; double z; }