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

if ( *(_DWORD *)(a1 + 56) > a2 )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(*(_QWORD *)(a1 + 48) + 32LL * a2 + 24))(a1, a3);
return result;
}

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

if ( *(_DWORD *)(a1 + 56) > a2 )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(*(_QWORD *)(a1 + 48) + 32LL * a2 + 24))(a1, a3);
return result;
}

original_code:
void nocta_set(nocta_unit* unit, int param_id, int val) {
 if (param_id >= unit->num_params)
  return;
 nocta_param* param = &unit->params[param_id];
 param->set(unit, val);
}

canonical_original_code:
void nocta_set(struct nocta_unit *unit, int param_id, int val) {
 if (param_id >= unit->num_params)
  return;
 struct nocta_param *param = &unit->params[param_id];
 param->set(unit, val);
}

variable_types: val int


repo: geckojsc/nocta

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

result = 0LL;
if ( *(_DWORD *)(a1 + 56) > a2 )
result = *(_QWORD *)(a1 + 48) + 32LL * a2;
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 56) > a2 )
result = *(_QWORD *)(a1 + 48) + 32LL * a2;
return result;
}

original_code:
nocta_param* nocta_get_param(nocta_unit* unit, int param_id) {
 return param_id < unit->num_params ? &unit->params[param_id] : ((void *)0);
}

canonical_original_code:
struct nocta_param *nocta_get_param(struct nocta_unit *unit, int param_id) {
 return param_id < unit->num_params ? &unit->params[param_id] : ((void *)0);
}

variable_types:
unit
struct nocta_unit *

return_type: struct nocta_param { char *name; int min; int (*get)(struct nocta_unit { struct nocta_context { int sample_rate; } *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param *params; int num_params; } *unit); void (*set)(struct nocta_unit *unit, int val); } *

user_defined_types: struct nocta_param { char *name; int min; int (*get)(struct nocta_unit *unit); void (*set)(struct nocta_unit *unit, int val); }

user_defined_types: struct nocta_unit { struct nocta_context *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param *params; int num_params; }


decompiled_code:
__int64 __fastcall gainer_process_l(__int64 a1, int a2)
{
unsigned __int8 *v2; // rdi
char v3; // dl
int v4; // ecx

v2 = *(unsigned __int8 **)(a1 + 16);
v3 = v2[1];
v4 = 255;
if ( v3 > 0 )
v4 = 255 - 2 * v3;
return (unsigned int)((a2 * ((v4 * *v2) >> 8)) >> 7);
}

original_code:
static int gainer_process_l(nocta_unit* self, int in) {
 gainer_data* data = self->data;
 int amp = 255;
 if (data->pan > 0) amp -= 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

canonical_original_code:
static int gainer_process_l(struct nocta_unit *self, int in) {
 struct gainer_data *data = self->data;
 int amp = 255;
 if (data->pan > 0) amp -= 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

variable_types: struct nocta_unit { struct nocta_context { int sample_rate; } *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param { char *name; int min; int (*get)(struct nocta_unit *unit); void (*set)(struct nocta_unit *unit, int val); } *params; int num_params; } *

variable_types: in int

variable_types: struct gainer_data { unsigned char vol; char pan; } *

variable_types: amp int

return_type: int


decompiled_code:
__int64 __fastcall gainer_process_r(__int64 a1, int a2)
{
unsigned __int8 *v2; // rcx
char v3; // dl
int v4; // edi

v2 = *(unsigned __int8 **)(a1 + 16);
v3 = v2[1];
v4 = 255;
if ( v3 < 0 )
v4 = 2 * v3 + 255;
return (unsigned int)((a2 * ((v4 * *v2) >> 8)) >> 7);
}

original_code:
static int gainer_process_r(nocta_unit* self, int in) {
 gainer_data* data = self->data;
 int amp = 255;
 if (data->pan < 0) amp += 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

canonical_original_code:
static int gainer_process_r(struct nocta_unit *self, int in) {
 struct gainer_data *data = self->data;
 int amp = 255;
 if (data->pan < 0) amp += 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

user_defined_types: struct gainer_data { unsigned char vol; char pan; }

user_defined_types: struct nocta_context { int sample_rate; }


decompiled_code:
__int64 __fastcall get_pan(__int64 a1)
{
return (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + 1LL);
}

original_code:
static int get_pan(nocta_unit* self) {
 gainer_data* data = self->data;
 return data->pan;
}

canonical_original_code:
static int get_pan(struct nocta_unit *self) {
 struct gainer_data *data = self->data;
 return data->pan;
}


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

result = *(_QWORD *)(a1 + 16);
*(_BYTE *)(result + 1) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 16);
*(_BYTE *)(result + 1) = a2;
return result;
}

original_code:
static void set_pan(nocta_unit* self, int pan) {
 gainer_data* data = self->data;
 data->pan = pan;
}

canonical_original_code:
static void set_pan(struct nocta_unit *self, int pan) {
 struct gainer_data *data = self->data;
 data->pan = pan;
}

variable_types: pan int

return_type: void


decompiled_code:
__int64 __fastcall nocta_gainer(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
__int64 v4; // r9
char v6[10]; // [rsp+4Eh] [rbp-Ah] BYREF

v6[0] = 0x80;
v6[1] = 0;
ialloc_impl(2, v6);
return nocta_create_impl(2LL, v6, v1, v2, v3, v4, a1, "gainer");
}

original_code:
nocta_unit* nocta_gainer(nocta_context* context) {
 return nocta_create_impl((nocta_unit) { .context = context, .name = "gainer", .data = ialloc_impl(sizeof(gainer_data), &(gainer_data){ .vol = 128, .pan = 0 }), .process_l = gainer_process_l, .process_r = gainer_process_r, .params = gainer_params, .num_params = NOCTA_GAINER_NUM_PARAMS });
}

canonical_original_code:
struct nocta_unit *nocta_gainer(struct nocta_context *context) {
 return nocta_create_impl((struct nocta_unit) { .context = context, .name = "gainer", .data = ialloc_impl(sizeof(gainer_data), &(struct gainer_data){ .vol = 128, .pan = 0 }), .process_l = gainer_process_l, .process_r = gainer_process_r, .params = gainer_params, .num_params = NOCTA_GAINER_NUM_PARAMS });
}

variable_types:
context
struct nocta_context *

return_type: struct nocta_unit { struct nocta_context { int sample_rate; } *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param { char *name; int min; int (*get)(struct nocta_unit *unit); void (*set)(struct nocta_unit *unit, int val); } *params; int num_params; } *


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

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

original_code:
inline static int32_t u8_to_fix(int32_t x) {
 return x << (13 - 8);
}

canonical_original_code:
inline static int u8_to_fix(int x) {
 return x << (13 - 8);
}

variable_types: x int


decompiled_code:
__int64 __fastcall fix_mul(int a1, int a2)
{
return (unsigned int)((a2 * a1) >> 13);
}

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

original_code:
inline static int32_t fix_mul(int32_t a, int32_t b) {
 return (a * b) >> 13;
}

canonical_original_code:
inline static int fix_mul(int a, int b) {
 return (a * b) >> 13;
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall fix_div(int a1, int a2)
{
return (unsigned int)((a1 << 13) / a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return (unsigned int)((a1 << 13) / a2);
}

original_code:
inline static int32_t fix_div(int32_t a, int32_t b) {
 return (a << 13) / b;
}

canonical_original_code:
inline static int fix_div(int a, int b) {
 return (a << 13) / b;
}


decompiled_code:
__int64 __fastcall bqfilter_run(int *a1, int *a2, int a3)
{
int v4; // ebx
int v5; // er14
int v6; // ebx
int v7; // ebx
int v8; // er15
int v9; // ebx
__int64 result; // rax

v4 = fix_mul(a1[8], a3);
v5 = *a2;
v6 = fix_mul(a1[9], *a2) + v4;
v7 = fix_mul(a1[10], a2[1]) + v6;
v8 = a2[2];
v9 = v7 - fix_mul(a1[6], v8);
result = v9 - (unsigned int)fix_mul(a1[7], a2[3]);
a2[1] = v5;
*a2 = a3;
a2[3] = v8;
a2[2] = result;
return result;
}

original_code:
static int bqfilter_run(filter_data* data, filter_state* state, int input) {
 int output = fix_mul(data->b0, input);
 output += fix_mul(data->b1, state->in1);
 output += fix_mul(data->b2, state->in2);
 output -= fix_mul(data->a1, state->out1);
 output -= fix_mul(data->a2, state->out2);
 state->in2 = state->in1;
 state->in1 = input;
 state->out2 = state->out1;
 state->out1 = output;
 return output;
}

canonical_original_code:
static int bqfilter_run(struct filter_data *data, struct filter_state *state, int input) {
 int output = fix_mul(data->b0, input);
 output += fix_mul(data->b1, state->in1);
 output += fix_mul(data->b2, state->in2);
 output -= fix_mul(data->a1, state->out1);
 output -= fix_mul(data->a2, state->out2);
 state->in2 = state->in1;
 state->in1 = input;
 state->out2 = state->out1;
 state->out1 = output;
 return output;
}

variable_types: struct filter_data { unsigned char vol; int mode; int freq; int amp; unsigned char res; int a0; int b0; struct filter_state { int in1; int out1; } l[2]; } *

variable_types:
state
struct filter_state *

variable_types: input int

variable_types: output int

user_defined_types: struct filter_data { unsigned char vol; int mode; int freq; int amp; unsigned char res; int a0; int b0; struct filter_state l[2]; }


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

v2 = *(int **)(a1 + 16);
v3 = bqfilter_run(v2, v2 + 19, (v2[3] * a2) >> 8);
return (unsigned int)((int)(bqfilter_run(v2, v2 + 23, v3) * *(unsigned __int8 *)v2) >> 8);
}

original_code:
static int bqfilter_r(nocta_unit* self, int x) {
 filter_data* data = self->data;
 x = x*data->amp >> 8;
 for (int i=0; i<2; i++) {
  x = bqfilter_run(data, &data->r[i], x);
 }
 return x*data->vol >> 8;
}

canonical_original_code:
static int bqfilter_r(struct nocta_unit *self, int x) {
 struct filter_data *data = self->data;
 x = x*data->amp >> 8;
 for (int i = 0; i<2; i++) {
  x = bqfilter_run(data, &data->r[i], x);
 }
 return x*data->vol >> 8;
}

variable_types: i int

user_defined_types: struct filter_state { int in1; int out1; }


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

v2 = *(int **)(a1 + 16);
v3 = bqfilter_run(v2, v2 + 11, (v2[3] * a2) >> 8);
return (unsigned int)((int)(bqfilter_run(v2, v2 + 15, v3) * *(unsigned __int8 *)v2) >> 8);
}

original_code:
static int bqfilter_l(nocta_unit* self, int x) {
 filter_data* data = self->data;
 x = x*data->amp >> 8;
 for (int i=0; i<2; i++) {
  x = bqfilter_run(data, &data->l[i], x);
 }
 return x*data->vol >> 8;
}

canonical_original_code:
static int bqfilter_l(struct nocta_unit *self, int x) {
 struct filter_data *data = self->data;
 x = x*data->amp >> 8;
 for (int i = 0; i<2; i++) {
  x = bqfilter_run(data, &data->l[i], x);
 }
 return x*data->vol >> 8;
}


decompiled_code:
__int64 __fastcall fix_cos(int a1)
{
return (unsigned int)(int)(cos((double)a1 * 0.0001220703125) * 8192.0);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return (unsigned int)(int)(cos((double)a1 * 0.0001220703125) * 8192.0);
}

original_code:
inline static int32_t fix_cos(int32_t x) {
 double y = (double)x / (1<<13);
 return cos(y) * (1<<13);
}

canonical_original_code:
inline static int fix_cos(int x) {
 double y = (double)x / (1<<13);
 return cos(y) * (1<<13);
}

variable_types: y double


decompiled_code:
__int64 __fastcall fix_sin(int a1)
{
return (unsigned int)(int)(sin((double)a1 * 0.0001220703125) * 8192.0);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return (unsigned int)(int)(sin((double)a1 * 0.0001220703125) * 8192.0);
}

original_code:
inline static int32_t fix_sin(int32_t x) {
 double y = (double)x / (1<<13);
 return sin(y) * (1<<13);
}

canonical_original_code:
inline static int fix_sin(int x) {
 double y = (double)x / (1<<13);
 return sin(y) * (1<<13);
}


original_code:
nocta_unit* nocta_bqfilter(nocta_context* context) {
 nocta_unit* self = nocta_create_impl((nocta_unit) { .context = context, .name = "bqfilter", .data = ialloc_impl(sizeof(filter_data), &(filter_data){ .vol = 255, .freq = 22050, .res = 0 }), .process_l = bqfilter_l, .process_r = bqfilter_r, .params = bqfilter_params, .num_params = NOCTA_FILTER_NUM_PARAMS });
 set_mode(self, NOCTA_FILTER_MODE_LOWPASS);
 return self;
}

canonical_original_code:
struct nocta_unit *nocta_bqfilter(struct nocta_context *context) {
 struct nocta_unit *self = nocta_create_impl((nocta_unit) { .context = context, .name = "bqfilter", .data = ialloc_impl(sizeof(filter_data), &(filter_data){ .vol = 255, .freq = 22050, .res = 0 }), .process_l = bqfilter_l, .process_r = bqfilter_r, .params = bqfilter_params, .num_params = NOCTA_FILTER_NUM_PARAMS });
 set_mode(self, NOCTA_FILTER_MODE_LOWPASS);
 return self;
}


repo: geekofhearts/lang

original_code:
void context_destroy(void* the_context) {
  context_t* typed_context = (context_t*)the_context;
  variable_t* var = (variable_t*)typed_context->local_variables[0];
  int i;
  for (i = 0; var != ((void *)0); var = (variable_t*)(typed_context->local_variables[++i])) {
    var->destructor((void*)var);
  }
  free(typed_context->local_variables);
}

canonical_original_code:
void context_destroy(void *the_context) {
  struct context_t *typed_context = (context_t*)the_context;
  struct variable_t *var = (variable_t*)typed_context->local_variables[0];
  int i;
  for (i = 0; var != ((void *)0); var = (struct variable_t *)(typed_context->local_variables[++i])) {
    var->destructor((void *)var);
  }
  free(typed_context->local_variables);
}

variable_types: struct context_t { void **local_variables; int thread_id; void **global_variables; } *

variable_types: struct variable_t { char *name; void *value; void (*destructor)(void *); } *


decompiled_code:
void __fastcall __noreturn raise_error(const char *a1)
{
printf("ERROR: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
printf("ERROR: %s\n", a1);
exit(1);
}

original_code:
void raise_error(char* message) {
  printf("ERROR: %s\n", message);
  exit(1);
}

canonical_original_code:
void raise_error(char *message) {
  printf("ERROR: %s\n", message);
  exit(1);
}

variable_types:
message
char *


decompiled_code:
void __noreturn segfault_handler()
{
puts("ERROR: caught a segmentation fault: most likely the system refused to allocate the RAM you or lang requested.");
puts("exiting now.");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
puts("ERROR: caught a segmentation fault: most likely the system refused to allocate the RAM you or lang requested.");
puts("exiting now.");
exit(1);
}

original_code:
void segfault_handler(int signal) {
  printf("ERROR: caught a segmentation fault: most likely the system refused to allocate the RAM you or lang requested.\n");
  printf("exiting now.\n");
  exit(1);
}

variable_types: signal int


decompiled_code:
int __fastcall print_version_info(const char *a1)
{
return printf("%s v%i.%i\n", a1, 0LL, 1LL);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
return printf("%s v%i.%i\n", a1, 0LL, 1LL);
}

original_code:
void print_version_info(char* name) {
  printf("%s v%i.%i\n", name, 0, 1);
}

canonical_original_code:
void print_version_info(char *name) {
  printf("%s v%i.%i\n", name, 0, 1);
}

variable_types:
name
char *


decompiled_code:
int setup_error_handling()
{
struct sigaction *v0; // rbx

v0 = (struct sigaction *)malloc(0x98uLL);
v0->sa_handler = (__sighandler_t)segfault_handler;
sigemptyset(&v0->sa_mask);
v0->sa_flags = 0;
return sigaction(11, v0, 0LL);
}

canonical_decompiled_code:
int func13()
{
struct sigaction *v0; // rbx

v0 = (struct sigaction *)malloc(0x98uLL);
v0->sa_handler = (__sighandler_t)segfault_handler;
sigemptyset(&v0->sa_mask);
v0->sa_flags = 0;
return sigaction(11, v0, 0LL);
}

original_code:
void setup_error_handling(void) {
  struct sigaction* action = (struct sigaction*)malloc(sizeof(struct sigaction));
  action->__sigaction_handler.sa_handler = &segfault_handler;
  sigemptyset(&(action->sa_mask));
  action->sa_flags = 0;
  sigaction(11, action, ((void *)0));
}

canonical_original_code:
void setup_error_handling() {
  struct sigaction *action = (struct sigaction*)malloc(sizeof(struct sigaction));
  action->__sigaction_handler.sa_handler = &segfault_handler;
  sigemptyset(&(action->sa_mask));
  action->sa_flags = 0;
  sigaction(11, action, ((void *)0));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); } *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // r12
const char **v4; // rsi
int result; // eax

setup_error_handling();
if ( argc <= 1 )
{
print_version_info(*argv);
result = prompt();
}
else
{
v3 = (int *)malloc(4uLL);
v4 = parseopts(argc, argv, v3);
result = *v3;
if ( *v3 )
result = script((unsigned int)result, v4);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // r12
const char **v4; // rsi
int result; // eax

func13();
if ( argc <= 1 )
{
func10(*argv);
result = func14();
}
else
{
v3 = (int *)malloc(4uLL);
v4 = func12(argc, argv, v3);
result = *v3;
if ( *v3 )
result = func15((unsigned int)result, v4);
}
return result;
}

original_code:
int main(int argc, char** argv) {
  setup_error_handling();
  if (argc > 1) {
    int* script_argc = (int*)malloc(sizeof(int));
    char** script_and_args = parseopts(argc, argv, script_argc);
    if (*(script_argc)) {
      return script(*(script_argc), script_and_args);
    }
    return 0;
  } else {
    print_version_info(argv[0]);
    return prompt();
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  setup_error_handling();
  if (argc > 1) {
    int *script_argc = (int*)malloc(sizeof(int));
    char **script_and_args = parseopts(argc, argv, script_argc);
    if (*(script_argc)) {
      return script(*(script_argc), script_and_args);
    }
    return 0;
  } else {
    print_version_info(argv[0]);
    return prompt();
  }
}

variable_types: argc int

variable_types:
argv
char **


prompt

decompiled_code:
__int64 prompt()
{
puts("imma run the interpreter.");
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
puts("imma run the interpreter.");
return 0LL;
}

original_code:
int prompt(void) {
  printf("imma run the interpreter.\n");
  return 0;
}

canonical_original_code:
int prompt() {
  printf("imma run the interpreter.\n");
  return 0;
}


script

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

printf("imma run script called %s now with args ", *a2);
if ( a1 > 1 )
{
v2 = a2 + 1;
do
printf("%s, ", *v2++);
while ( v2 != &a2[(unsigned int)(a1 - 2) + 2] );
}
puts(" aaaand that's all.");
return 0LL;
}

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

printf("imma run script called %s now with args ", *a2);
if ( a1 > 1 )
{
v2 = a2 + 1;
do
printf("%s, ", *v2++);
while ( v2 != &a2[(unsigned int)(a1 - 2) + 2] );
}
puts(" aaaand that's all.");
return 0LL;
}

original_code:
int script(int argc, char** argv) {
  printf("imma run script called %s now with args ", argv[0]);
  int i;
  for (i = 1; i < argc; i++) {
    printf("%s, ", argv[i]);
  }
  printf(" aaaand that's all.\n");
  return 0;
}

canonical_original_code:
int script(int argc, char **argv) {
  printf("imma run script called %s now with args ", argv[0]);
  int i;
  for (i = 1; i < argc; i++) {
    printf("%s, ", argv[i]);
  }
  printf(" aaaand that's all.\n");
  return 0;
}


decompiled_code:
void __fastcall ctype_variable_destructor(void **a1)
{
free(*a1);
free(a1[1]);
}

canonical_decompiled_code:
void __fastcall func16(void **a1)
{
free(*a1);
free(a1[1]);
}

original_code:
void ctype_variable_destructor(void* var) {
  variable_t* typed_var = (variable_t*)var;
  free(typed_var->name);
  free(typed_var->value);
}

canonical_original_code:
void ctype_variable_destructor(void *var) {
  struct variable_t *typed_var = (variable_t*)var;
  free(typed_var->name);
  free(typed_var->value);
}

variable_types:
var
void *

user_defined_types: struct variable_t { char *name; void *value; void (*destructor)(void *); }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
struct hostent *v4; // rax
char *v5; // r13
int v7; // ebp
size_t v8; // rax
char *v9; // rbx
size_t v10; // rax
char *v11; // rbx
bool v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
char *v17; // rsi
char v18[2000]; // [rsp+0h] [rbp-818h] BYREF
struct sockaddr addr; // [rsp+7D0h] [rbp-48h] BYREF

puts("OpenWRT smart home v1.00a");
puts("http://smarthome.russemotto.com\n");
if ( argc <= 1 )
{
puts("\nI need a hostname");
}
else
{
v3 = argv[1];
v4 = gethostbyname(v3);
if ( v4 )
{
v5 = inet_ntoa((struct in_addr)(*(struct in_addr **)v4->h_addr_list)->s_addr);
pinMode(29LL, 0LL);
while ( 1 )
{
v7 = socket(2, 1, 0);
if ( v7 == -1 )
printf("Could not create socket");
*(_DWORD *)&addr.sa_data[2] = inet_addr(v5);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(80);
if ( connect(v7, &addr, 0x10u) < 0 )
perror(" Error: connection failed.");
puts("Connected");
v8 = strlen(v3);
v9 = (char *)malloc(v8 + 54);
strcpy(v9, "GET /LP HTTP/1.0\r\nHost: ");
strcat(v9, v3);
strcpy(&v9[strlen(v9)], "\r\nUser-Agent: smarthome\r\n\r\n");
v10 = strlen(v9);
if ( send(v7, v9, v10, 0) < 0 )
printf("Error: Send failed");
if ( recv(v7, v18, 0x7D0uLL, 0) >= 0 )
{
puts("Server reply :");
puts(v18);
v11 = strstr(v18, "\r\n\r\n");
if ( v11 )
v11 += 4;
v12 = memcmp(v11, "on", 2uLL) != 0;
v13 = 0;
v14 = !v12;
if ( !v12 )
{
printf("Turning on");
turnOn(2LL);
}
v15 = "off";
v16 = 3LL;
v17 = v11;
do
{
if ( !v16 )
break;
v13 = (unsigned __int8)*v17 < (unsigned int)*v15;
v14 = *v17++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
printf("Turning off");
turnOff(2LL, v17);
}
}
close(v7);
}
}
herror("gethostbyname");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
struct hostent *v4; // rax
char *v5; // r13
int v7; // ebp
size_t v8; // rax
char *v9; // rbx
size_t v10; // rax
char *v11; // rbx
bool v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
char *v17; // rsi
char v18[2000]; // [rsp+0h] [rbp-818h] BYREF
struct sockaddr addr; // [rsp+7D0h] [rbp-48h] BYREF

puts("OpenWRT smart home v1.00a");
puts("http://smarthome.russemotto.com\n");
if ( argc <= 1 )
{
puts("\nI need a hostname");
}
else
{
v3 = argv[1];
v4 = gethostbyname(v3);
if ( v4 )
{
v5 = inet_ntoa((struct in_addr)(*(struct in_addr **)v4->h_addr_list)->s_addr);
func10(29LL, 0LL);
while ( 1 )
{
v7 = socket(2, 1, 0);
if ( v7 == -1 )
printf("Could not create socket");
*(_DWORD *)&addr.sa_data[2] = inet_addr(v5);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func7(80);
if ( connect(v7, &addr, 0x10u) < 0 )
perror(" Error: connection failed.");
puts("Connected");
v8 = strlen(v3);
v9 = (char *)malloc(v8 + 54);
strcpy(v9, "GET /LP HTTP/1.0\r\nHost: ");
strcat(v9, v3);
strcpy(&v9[strlen(v9)], "\r\nUser-Agent: smarthome\r\n\r\n");
v10 = strlen(v9);
if ( send(v7, v9, v10, 0) < 0 )
printf("Error: Send failed");
if ( recv(v7, v18, 0x7D0uLL, 0) >= 0 )
{
puts("Server reply :");
puts(v18);
v11 = strstr(v18, "\r\n\r\n");
if ( v11 )
v11 += 4;
v12 = memcmp(v11, "on", 2uLL) != 0;
v13 = 0;
v14 = !v12;
if ( !v12 )
{
printf("Turning on");
func17(2LL);
}
v15 = "off";
v16 = 3LL;
v17 = v11;
do
{
if ( !v16 )
break;
v13 = (unsigned __int8)*v17 < (unsigned int)*v15;
v14 = *v17++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
printf("Turning off");
func16(2LL, v17);
}
}
close(v7);
}
}
herror("gethostbyname");
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 char *ip;
 char *host;
 int sock;
 struct sockaddr_in server;
 char server_reply[2000];
 printf("OpenWRT smart home v1.00a\n");
 printf("http://smarthome.russemotto.com\n\n");
 if(argc <2)
 {
  printf("\nI need a hostname\n");
  return 0;
 }
 host = argv[1];
 struct hostent *h;
 if ((h=gethostbyname(host)) == ((void *)0)) {
  herror("gethostbyname");
  return 0;
 }
 ip = inet_ntoa(*((struct in_addr *)h->h_addr_list[0]));
 pinMode(29, 0);
 while(1) {
  sock = socket(2 , SOCK_STREAM , 0);
  if (sock == -1)
  {
   printf("Could not create socket");
  }
  server.sin_addr.s_addr = inet_addr(ip);
  server.sin_family = 2;
  server.sin_port = htons(80);
  if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0)
  {
   perror(" Error: connection failed.");
  }
  printf("Connected\n");
  char *message = malloc(26+strlen(host)+28);
  strcpy(message, "GET /LP HTTP/1.0\r\nHost: ");
  strcat(message, host);
  strcat(message, "\r\nUser-Agent: smarthome\r\n\r\n");
  if( send(sock , message , strlen(message) , 0) < 0)
  {
   printf("Error: Send failed");
  }
  if( recv(sock , server_reply , 2000 , 0) >= 0)
  {
   puts("Server reply :");
   puts(server_reply);
   int htmlstart = 0;
     char * htmlcontent;
   if(htmlstart == 0)
   {
          htmlcontent = strstr(server_reply, "\r\n\r\n");
    if(htmlcontent != ((void *)0)){
    htmlstart = 1;
    htmlcontent += 4;
   }
      }
  if (strncmp(htmlcontent, "on", 2) == 0) {
   printf("Turning on");
   turnOn(2);
  }
  if (strncmp(htmlcontent, "off", 3) == 0) {
   printf("Turning off");
   turnOff(2);
  }
  }
 close(sock);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char *ip;
 char *host;
 int sock;
 struct sockaddr_in server;
 char server_reply[2000];
 printf("OpenWRT smart home v1.00a\n");
 printf("http://smarthome.russemotto.com\n\n");
 if(argc <2)
 {
  printf("\nI need a hostname\n");
  return 0;
 }
 host = argv[1];
 struct hostent *h;
 if ((h=gethostbyname(host)) == ((void *)0)) {
  herror("gethostbyname");
  return 0;
 }
 ip = inet_ntoa(*((struct in_addr *)h->h_addr_list[0]));
 pinMode(29, 0);
 while(1) {
  sock = socket(2 , SOCK_STREAM , 0);
  if (sock == -1)
  {
   printf("Could not create socket");
  }
  server.sin_addr.s_addr = inet_addr(ip);
  server.sin_family = 2;
  server.sin_port = htons(80);
  if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0)
  {
   perror(" Error: connection failed.");
  }
  printf("Connected\n");
  char *message = malloc(26+strlen(host)+28);
  strcpy(message, "GET /LP HTTP/1.0\r\nHost: ");
  strcat(message, host);
  strcat(message, "\r\nUser-Agent: smarthome\r\n\r\n");
  if( send(sock , message , strlen(message) , 0) < 0)
  {
   printf("Error: Send failed");
  }
  if( recv(sock , server_reply , 2000 , 0) >= 0)
  {
   puts("Server reply :");
   puts(server_reply);
   int htmlstart = 0;
     char *htmlcontent;
   if(htmlstart == 0)
   {
          htmlcontent = strstr(server_reply, "\r\n\r\n");
    if(htmlcontent != ((void *)0)){
    htmlstart = 1;
    htmlcontent += 4;
   }
      }
  if (strncmp(htmlcontent, "on", 2) == 0) {
   printf("Turning on");
   turnOn(2);
  }
  if (strncmp(htmlcontent, "off", 3) == 0) {
   printf("Turning off");
   turnOff(2);
  }
  }
 close(sock);
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types:
ip
char *

variable_types:
host
char *

variable_types: sock int

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: htmlstart int

variable_types:
htmlcontent
char *

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

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


usDelay

decompiled_code:
void __fastcall usDelay(unsigned int a1)
{
unsigned int i; // eax

if ( a1 )
{
for ( i = 1; i <= a1; ++i )
;
}
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1)
{
unsigned int i; // eax

if ( a1 )
{
for ( i = 1; i <= a1; ++i )
;
}
}

original_code:
void usDelay(int d) {
 unsigned int i;
 for ( i = 1 ; i <= d ; i++ )
 {
  asm("");
 }
}

variable_types: d int

variable_types:
i
unsigned int


A

decompiled_code:
void A()
{
digitalWrite(29LL, 1u);
usDelay(0x1B58u);
digitalWrite(29LL, 0);
usDelay(0x1B58u);
digitalWrite(29LL, 1u);
usDelay(0x1B58u);
digitalWrite(29LL, 0);
usDelay(0x1B58u);
digitalWrite(29LL, 1u);
usDelay(0x1B58u);
digitalWrite(29LL, 0);
usDelay(0xC738u);
}

original_code:
void A(void) {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}

canonical_original_code:
void A() {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}


B

decompiled_code:
void B()
{
digitalWrite(29LL, 1u);
usDelay(0x1B58u);
digitalWrite(29LL, 0);
usDelay(0x1B58u);
digitalWrite(29LL, 1u);
usDelay(0x1B58u);
digitalWrite(29LL, 0);
usDelay(0xC738u);
}

original_code:
void B(void) {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}

canonical_original_code:
void B() {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}


C

decompiled_code:
void C()
{
digitalWrite(29LL, 1u);
usDelay(0x1B58u);
digitalWrite(29LL, 0);
usDelay(0xC738u);
}

original_code:
void C(void) {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}

canonical_original_code:
void C() {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}


turnOff

decompiled_code:
void __fastcall turnOff(int a1)
{
int v1; // ebx

v1 = 5;
do
{
sendInit();
B();
B();
setChannel(a1);
usDelay(0x7C830u);
--v1;
}
while ( v1 );
}

canonical_decompiled_code:
void __fastcall func16(int a1)
{
int v1; // ebx

v1 = 5;
do
{
func14();
func12();
func12();
func15(a1);
func8(0x7C830u);
--v1;
}
while ( v1 );
}

original_code:
void turnOff(int k) {
 unsigned int i;
 for ( i = 1 ; i <= 5 ; i++ ) {
  sendInit();
  B();B();
  setChannel(k);
  usDelay(510000);
 }
}

variable_types: k int


turnOn

decompiled_code:
void __fastcall turnOn(int a1)
{
int v1; // ebx

v1 = 5;
do
{
sendInit();
C();
A();
setChannel(a1);
usDelay(0x7C830u);
--v1;
}
while ( v1 );
}

canonical_decompiled_code:
void __fastcall func17(int a1)
{
int v1; // ebx

v1 = 5;
do
{
func14();
func13();
func11();
func15(a1);
func8(0x7C830u);
--v1;
}
while ( v1 );
}

original_code:
void turnOn(int k) {
 unsigned int i;
 for ( i = 1 ; i <= 5 ; i++ ) {
  sendInit();
  C();A();
  setChannel(k);
  usDelay(510000);
 }
}


passivesocket

repo: gekalogiros/proxy-server

decompiled_code:
__int64 __fastcall passivesocket(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_WORD *)v4.sa_data = _bswap_16(a1);
if ( bind(v2, &v4, 0x10u) < 0 )
return (unsigned int)-1;
if ( listen(v2, 5) < 0 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_WORD *)v4.sa_data = func0(a1);
if ( bind(v2, &v4, 0x10u) < 0 )
return (unsigned int)-1;
if ( listen(v2, 5) < 0 )
v2 = -1;
return v2;
}

original_code:
int passivesocket(int portnumber)
{
  struct sockaddr_in addr;
  int x;
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  addr.sin_port = htons(portnumber);
  if(bind(x, (struct sockaddr*) &addr, sizeof(addr)) < 0)
    return -1;
  if(listen(x, 5) < 0)
    return -1;
  return x;
}

canonical_original_code:
int passivesocket(int portnumber)
{
  struct sockaddr_in addr;
  int x;
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
  addr.sin_port = htons(portnumber);
  if(bind(x, (struct sockaddr *) &addr, sizeof(addr)) < 0)
    return -1;
  if(listen(x, 5) < 0)
    return -1;
  return x;
}

variable_types: portnumber int

variable_types: x int


activesocket

decompiled_code:
__int64 __fastcall activesocket(const char *a1, __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbp
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = gethostbyname(a1);
if ( v2 )
{
v3 = v2;
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v4 = -1;
}
else
{
*(_QWORD *)&v6.sa_family = 2LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_QWORD *)&v6.sa_data[2] = **(unsigned int **)v3->h_addr_list;
*(_WORD *)v6.sa_data = _bswap_16(a2);
if ( connect(v4, &v6, 0x10u) < 0 )
v4 = -1;
}
}
else
{
fprintf(stderr, "%s: doesn't exist!\n", a1);
v4 = -1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbp
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = gethostbyname(a1);
if ( v2 )
{
v3 = v2;
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v4 = -1;
}
else
{
*(_QWORD *)&v6.sa_family = 2LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_QWORD *)&v6.sa_data[2] = **(unsigned int **)v3->h_addr_list;
*(_WORD *)v6.sa_data = func0(a2);
if ( connect(v4, &v6, 0x10u) < 0 )
v4 = -1;
}
}
else
{
fprintf(stderr, "%s: doesn't exist!\n", a1);
v4 = -1;
}
return (unsigned int)v4;
}

original_code:
int activesocket(char *hostname, int portnumber)
{
  struct sockaddr_in addr;
  struct hostent *h;
  int x;
  h = gethostbyname(hostname);
  if(h == ((void *)0)) {
    fprintf(stderr, "%s: doesn't exist!\n", hostname);
    return -1;
  }
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  memcpy(&addr.sin_addr.s_addr, h -> h_addr_list[0], sizeof(int));
  addr.sin_port = htons(portnumber);
  if(connect(x, (struct sockaddr*) &addr, sizeof(addr)) < 0)
    return -1;
  return x;
}

canonical_original_code:
int activesocket(char *hostname, int portnumber)
{
  struct sockaddr_in addr;
  struct hostent *h;
  int x;
  h = gethostbyname(hostname);
  if(h == ((void *)0)) {
    fprintf(stderr, "%s: doesn't exist!\n", hostname);
    return -1;
  }
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  memcpy(&addr.sin_addr.s_addr, h -> h_addr_list[0], sizeof(int));
  addr.sin_port = htons(portnumber);
  if(connect(x, (struct sockaddr *) &addr, sizeof(addr)) < 0)
    return -1;
  return x;
}

variable_types:
hostname
char *

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


acceptfrom

decompiled_code:
__int64 __fastcall acceptfrom(int a1, char *a2, int a3)
{
int v4; // eax
unsigned int v5; // ebp
char *v6; // rax
socklen_t addr_len; // [rsp+4h] [rbp-34h] BYREF
int optval[2]; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v4 = accept(a1, &addr, &addr_len);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
optval[1] = 5;
optval[0] = 1;
setsockopt(v4, 1, 13, optval, 8u);
v6 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strncpy(a2, v6, a3);
a2[a3 - 1] = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, char *a2, int a3)
{
int v4; // eax
unsigned int v5; // ebp
char *v6; // rax
socklen_t addr_len; // [rsp+4h] [rbp-34h] BYREF
int optval[2]; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v4 = accept(a1, &addr, &addr_len);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
optval[1] = 5;
optval[0] = 1;
setsockopt(v4, 1, 13, optval, 8u);
v6 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strncpy(a2, v6, a3);
a2[a3 - 1] = 0;
return v5;
}

original_code:
int acceptfrom(int socket, char *client, int size)
{
  struct sockaddr_in addr;
  struct linger l;
  int s, i;
  i = sizeof(addr);
  s = accept(socket, (struct sockaddr *)&addr, &i);
  if(s < 0)
    return -1;
  l.l_linger = 5;
  l.l_onoff = 1;
  setsockopt(s, 1, 13, (char *)&l, sizeof(l));
  strncpy(client, inet_ntoa(addr.sin_addr), size);
  client[size-1] = '\0';
  return s;
}

canonical_original_code:
int acceptfrom(int socket, char *client, int size)
{
  struct sockaddr_in addr;
  struct linger l;
  int s; int i;
  i = sizeof(addr);
  s = accept(socket, (struct sockaddr *)&addr, &i);
  if(s < 0)
    return -1;
  l.l_linger = 5;
  l.l_onoff = 1;
  setsockopt(s, 1, 13, (char *)&l, sizeof(l));
  strncpy(client, inet_ntoa(addr.sin_addr), size);
  client[size-1] = '\0';
  return s;
}

variable_types: socket int

variable_types:
client
char *

variable_types: size int

variable_types: struct linger { int l_onoff; int l_linger; }

variable_types: s int

variable_types: i int


acceptconnection

decompiled_code:
__int64 __fastcall acceptconnection(int a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

return acceptfrom(a1, v2, 40);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

return func3(a1, v2, 40);
}

original_code:
int acceptconnection(int socket)
{
  char client[40];
  return acceptfrom(socket, client, 40);
}

variable_types:
client
char [40]


TCPreadline

decompiled_code:
__int64 __fastcall TCPreadline(int fd, void *buf, int a3)
{
char *v3; // r13
char *v4; // rbx
unsigned int v5; // ebp
int v6; // eax

v3 = (char *)buf + (unsigned int)(a3 - 2);
v4 = (char *)buf;
v5 = 0;
while ( 1 )
{
v6 = read(fd, v4, 1uLL);
if ( v6 <= 0 )
break;
++v5;
if ( *v4 == 10 || v4 == v3 )
goto LABEL_6;
++v4;
}
if ( v6 >= 0 )
{
LABEL_6:
*((_BYTE *)buf + (int)v5) = 0;
return v5;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, int a3)
{
char *v3; // r13
char *v4; // rbx
unsigned int v5; // ebp
int v6; // eax

v3 = (char *)buf + (unsigned int)(a3 - 2);
v4 = (char *)buf;
v5 = 0;
while ( 1 )
{
v6 = read(fd, v4, 1uLL);
if ( v6 <= 0 )
break;
++v5;
if ( *v4 == 10 || v4 == v3 )
goto LABEL_6;
++v4;
}
if ( v6 >= 0 )
{
LABEL_6:
*((_BYTE *)buf + (int)v5) = 0;
return v5;
}
return (unsigned int)v6;
}

original_code:
int TCPreadline(int s, char *buffer, int size)
{
  char *b;
  int n, count;
  b = buffer;
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if (*b == '\n' || count == size-1)
      break;
    b ++;
  }
  if (n < 0) return n;
  buffer[count] = '\0';
  return count;
}

canonical_original_code:
int TCPreadline(int s, char *buffer, int size)
{
  char *b;
  int n; int count;
  b = buffer;
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if (*b == '\n' || count == size-1)
      break;
    b ++;
  }
  if (n < 0) return n;
  buffer[count] = '\0';
  return count;
}

variable_types:
buffer
char *

variable_types:
b
char *

variable_types: n int

variable_types: count int


HTTPreadheader

decompiled_code:
__int64 __fastcall HTTPreadheader(int fd, void *buf, int a3)
{
char *v3; // r14
char *v4; // rbx
unsigned int v5; // er12
char v6; // bp
int v7; // eax
char v8; // al

v3 = (char *)buf + (unsigned int)(a3 - 2);
v4 = (char *)buf;
v5 = 0;
v6 = 10;
while ( 1 )
{
v7 = read(fd, v4, 1uLL);
if ( v7 <= 0 )
break;
++v5;
v8 = *v4;
if ( v6 == 10 && v8 == 10 || v4 == v3 )
goto LABEL_9;
if ( v8 != 13 )
v6 = *v4;
++v4;
}
if ( v7 >= 0 )
{
LABEL_9:
*((_BYTE *)buf + (int)v5) = 0;
return v5;
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, void *buf, int a3)
{
char *v3; // r14
char *v4; // rbx
unsigned int v5; // er12
char v6; // bp
int v7; // eax
char v8; // al

v3 = (char *)buf + (unsigned int)(a3 - 2);
v4 = (char *)buf;
v5 = 0;
v6 = 10;
while ( 1 )
{
v7 = read(fd, v4, 1uLL);
if ( v7 <= 0 )
break;
++v5;
v8 = *v4;
if ( v6 == 10 && v8 == 10 || v4 == v3 )
goto LABEL_9;
if ( v8 != 13 )
v6 = *v4;
++v4;
}
if ( v7 >= 0 )
{
LABEL_9:
*((_BYTE *)buf + (int)v5) = 0;
return v5;
}
return (unsigned int)v7;
}

original_code:
int HTTPreadheader(int s, char *buffer, int size)
{
  char *b;
  char last;
  int n, count;
  b = buffer;
  last = '\n';
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if ((*b == '\n' && last == '\n') || count == size-1)
      break;
    if (*b != '\r') last = *b;
    b ++;
  }
  if (n < 0)
    return n;
  buffer[count] = '\0';
  return count;
}

canonical_original_code:
int HTTPreadheader(int s, char *buffer, int size)
{
  char *b;
  char last;
  int n; int count;
  b = buffer;
  last = '\n';
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if ((*b == '\n' && last == '\n') || count == size-1)
      break;
    if (*b != '\r') last = *b;
    b ++;
  }
  if (n < 0)
    return n;
  buffer[count] = '\0';
  return count;
}

variable_types: last char


HTTPheadervalue

decompiled_code:
__int64 __fastcall HTTPheadervalue(const char *a1, const char *a2, char *a3)
{
char *v3; // r12
char *v5; // rax
char *v6; // rbx
char v7; // al
const char *i; // rbx
size_t v9; // rbp

v3 = (char *)a1;
while ( 1 )
{
v5 = strstr(a1, a2);
v6 = v5;
if ( !v5 )
return 0LL;
if ( v3 == v5 )
break;
v7 = *(v5 - 1);
if ( v7 == 10 || v7 == 13 )
break;
a1 = v6 + 1;
}
for ( i = &v6[strlen(a2) + 1]; *i == 32; ++i )
;
v9 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v9);
a3[v9] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2, char *a3)
{
char *v3; // r12
char *v5; // rax
char *v6; // rbx
char v7; // al
const char *i; // rbx
size_t v9; // rbp

v3 = (char *)a1;
while ( 1 )
{
v5 = strstr(a1, a2);
v6 = v5;
if ( !v5 )
return 0LL;
if ( v3 == v5 )
break;
v7 = *(v5 - 1);
if ( v7 == 10 || v7 == 13 )
break;
a1 = v6 + 1;
}
for ( i = &v6[strlen(a2) + 1]; *i == 32; ++i )
;
v9 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v9);
a3[v9] = 0;
return 1LL;
}

original_code:
int HTTPheadervalue(char *header, char *key, char *value)
{
  char *b = header;
  int i;
  while (1) {
    b = strstr(b, key);
    if (b == ((void *)0)) return 0;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  b += strlen(key)+1;
  while (*b == ' ')
    b++;
  i = strcspn(b, "\n\r");
  strncpy(value, b, i);
  value[i] = '\0';
  return 1;
}

variable_types:
header
char *

variable_types:
key
char *

variable_types:
value
char *


HTTPheaderremove

decompiled_code:
char *__fastcall HTTPheaderremove(const char *a1, const char *a2)
{
char *v2; // rbx
char *result; // rax
char v4; // dl
char *i; // rdx
char *v6; // rcx
char v7; // dl

v2 = (char *)a1;
while ( 1 )
{
result = strstr(a1, a2);
if ( !result )
break;
if ( v2 == result || (v4 = *(result - 1), v4 == 10) || v4 == 13 )
{
for ( i = result; *i != 10; ++i )
;
v6 = i + 1;
v7 = i[1];
if ( v7 )
{
do
{
++v6;
*result++ = v7;
v7 = *v6;
}
while ( *v6 );
}
*result = 0;
return result;
}
a1 = result + 1;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1, const char *a2)
{
char *v2; // rbx
char *result; // rax
char v4; // dl
char *i; // rdx
char *v6; // rcx
char v7; // dl

v2 = (char *)a1;
while ( 1 )
{
result = strstr(a1, a2);
if ( !result )
break;
if ( v2 == result || (v4 = *(result - 1), v4 == 10) || v4 == 13 )
{
for ( i = result; *i != 10; ++i )
;
v6 = i + 1;
v7 = i[1];
if ( v7 )
{
do
{
++v6;
*result++ = v7;
v7 = *v6;
}
while ( *v6 );
}
*result = 0;
return result;
}
a1 = result + 1;
}
return result;
}

original_code:
void HTTPheaderremove(char *header, char *key)
{
  char *b = header;
  char *nextline;
  while (1) {
    b = strstr(b, key);
    if (b == ((void *)0)) return;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  nextline = b;
  while (*nextline != '\n')
    nextline++;
  nextline++;
  while (*nextline != '\0')
    *b++ = *nextline++;
  *b = '\0';
}

variable_types:
nextline
char *


decompiled_code:
char *__fastcall strstr_case(char *s1, char *s2)
{
char *v2; // rbx
int v3; // eax
size_t v4; // rbp

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncasecmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func9(char *s1, char *s2)
{
char *v2; // rbx
int v3; // eax
size_t v4; // rbp

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncasecmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

original_code:
char *strstr_case(char *p, char *key)
{
  int len = strlen(key);
  while (*p != '\0')
    if (strncasecmp(p, key, len) == 0)
      return p;
    else
      p++;
  return ((void *)0);
}

variable_types:
p
char *

variable_types: len int

return_type: char *


decompiled_code:
__int64 __fastcall HTTPheadervalue_case(char *a1, char *a2, char *a3)
{
char *v3; // r12
char *v5; // rax
char *v6; // rbx
char v7; // al
const char *i; // rbx
size_t v9; // rbp

v3 = a1;
while ( 1 )
{
v5 = strstr_case(a1, a2);
v6 = v5;
if ( !v5 )
return 0LL;
if ( v3 == v5 )
break;
v7 = *(v5 - 1);
if ( v7 == 10 || v7 == 13 )
break;
a1 = v6 + 1;
}
for ( i = &v6[strlen(a2) + 1]; *i == 32; ++i )
;
v9 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v9);
a3[v9] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, char *a2, char *a3)
{
char *v3; // r12
char *v5; // rax
char *v6; // rbx
char v7; // al
const char *i; // rbx
size_t v9; // rbp

v3 = a1;
while ( 1 )
{
v5 = func9(a1, a2);
v6 = v5;
if ( !v5 )
return 0LL;
if ( v3 == v5 )
break;
v7 = *(v5 - 1);
if ( v7 == 10 || v7 == 13 )
break;
a1 = v6 + 1;
}
for ( i = &v6[strlen(a2) + 1]; *i == 32; ++i )
;
v9 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v9);
a3[v9] = 0;
return 1LL;
}

original_code:
int HTTPheadervalue_case(char *header, char *key, char *value)
{
  char *b = header;
  int i;
  while (1) {
    b = strstr_case(b, key);
    if (b == ((void *)0)) return 0;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  b += strlen(key)+1;
  while (*b == ' ')
    b++;
  i = strcspn(b, "\n\r");
  strncpy(value, b, i);
  value[i] = '\0';
  return 1;
}


decompiled_code:
char *__fastcall HTTPheaderremove_case(char *a1, char *a2)
{
char *v2; // rbx
char *result; // rax
char v4; // dl
char *i; // rdx
char *v6; // rcx
char v7; // dl

v2 = a1;
while ( 1 )
{
result = strstr_case(a1, a2);
if ( !result )
break;
if ( v2 == result || (v4 = *(result - 1), v4 == 10) || v4 == 13 )
{
for ( i = result; *i != 10; ++i )
;
v6 = i + 1;
v7 = i[1];
if ( v7 )
{
do
{
++v6;
*result++ = v7;
v7 = *v6;
}
while ( *v6 );
}
*result = 0;
return result;
}
a1 = result + 1;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(char *a1, char *a2)
{
char *v2; // rbx
char *result; // rax
char v4; // dl
char *i; // rdx
char *v6; // rcx
char v7; // dl

v2 = a1;
while ( 1 )
{
result = func9(a1, a2);
if ( !result )
break;
if ( v2 == result || (v4 = *(result - 1), v4 == 10) || v4 == 13 )
{
for ( i = result; *i != 10; ++i )
;
v6 = i + 1;
v7 = i[1];
if ( v7 )
{
do
{
++v6;
*result++ = v7;
v7 = *v6;
}
while ( *v6 );
}
*result = 0;
return result;
}
a1 = result + 1;
}
return result;
}

original_code:
void HTTPheaderremove_case(char *header, char *key)
{
  char *b = header;
  char *nextline;
  while (1) {
    b = strstr_case(b, key);
    if (b == ((void *)0)) return;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  nextline = b;
  while (*nextline != '\n')
    nextline++;
  nextline++;
  while (*nextline != '\0')
    *b++ = *nextline++;
  *b = '\0';
}


contentlength

decompiled_code:
__int64 __fastcall contentlength(__int64 a1)
{
_BYTE v2[2572]; // [rsp+0h] [rbp-A18h] BYREF
unsigned int v3; // [rsp+A0Ch] [rbp-Ch] BYREF

v3 = 0x7FFFFFFF;
if ( (unsigned int)HTTPheadervalue_case(a1, "Content-Length", v2) )
_isoc99_sscanf(v2, "%d", &v3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_BYTE v2[2572]; // [rsp+0h] [rbp-A18h] BYREF
unsigned int v3; // [rsp+A0Ch] [rbp-Ch] BYREF

v3 = 0x7FFFFFFF;
if ( (unsigned int)HTTPheadervalue_case(a1, "Content-Length", v2) )
_isoc99_sscanf(v2, "%d", &v3);
return v3;
}

original_code:
int contentlength(char *header)
{
  int len=0x7fffffff;
  char line[2560];
  if (HTTPheadervalue_case(header, "Content-Length", line))
    sscanf(line, "%d", &len);
  return len;
}

canonical_original_code:
int contentlength(char *header)
{
  int len = 0x7fffffff;
  char line[2560];
  if (HTTPheadervalue_case(header, "Content-Length", line))
    sscanf(line, "%d", &len);
  return len;
}

variable_types:
line
char [2560]


parserequest

original_code:
void parserequest(char *request, int *method, char *host, int *pn, char *path)
{
 char url[2560] = "";
 char m[2560] = "";
 char hostport[2560] = "";
 char port[2560] = "";
 int i;
 sscanf(request, "%[^ ] %[^ ] HTTP/1.1", m, url);
 for (i=0; i<2; i++)
 {
  if (strcmp(m, methods[i]) == 0)
  *method = i;
 }
 sscanf(url, "http://%[^\n\r/]%[^\n\r]", hostport, path);
 sscanf(hostport, "%[^:]:%[^\n\r]", host, port);
 if (*port == '\0')
 {
  *pn = 80;
 }
 else
 {
  *pn = atoi(port);
 }
}

variable_types:
request
char *

variable_types:
method
int *

variable_types:
host
char *

variable_types:
pn
int *

variable_types:
path
char *

variable_types:
url
char [2560]

variable_types:
hostport
char [2560]

variable_types:
port
char [2560]


serviceconn

decompiled_code:
void *__fastcall serviceconn(void *a1)
{
unsigned int v1; // er12
char *v2; // r13
signed int v3; // ebp
char *v4; // rbx
struct pollfd fds; // [rsp+Ch] [rbp-6E3Ch] BYREF
int v7; // [rsp+14h] [rbp-6E34h] BYREF
int v8; // [rsp+18h] [rbp-6E30h] BYREF
int v9; // [rsp+1Ch] [rbp-6E2Ch] BYREF
char v10[2560]; // [rsp+20h] [rbp-6E28h] BYREF
char v11[2560]; // [rsp+A20h] [rbp-6428h] BYREF
char src[20480]; // [rsp+1420h] [rbp-5A28h] BYREF
char v13[2600]; // [rsp+6420h] [rbp-A28h] BYREF

v1 = *(_DWORD *)a1;
v9 = 0;
v2 = (char *)malloc(0x16EC87C00uLL);
fds.fd = v1;
fds.events = 192;
v3 = 0;
while ( 1 )
{
if ( poll(&fds, 1uLL, 10000) <= 0 )
{
puts("Connection Timeout");
goto LABEL_8;
}
if ( !(unsigned int)TCPreadline(v1, v13, 2560LL) )
break;
parserequest((__int64)v13, &v8, (__int64)v11, &v7, (__int64)v10);
if ( !(unsigned int)HTTPreadheader(v1, src, 20480LL) )
break;
printf("%s%s", v13, src);
HTTPheaderremove_case(src, "Connection");
v4 = &v2[61536 * (v3 % 100000)];
*((_DWORD *)v4 + 14) = v3;
*((_DWORD *)v4 + 15) = v3 % 100000;
*((_DWORD *)v4 + 16) = v1;
*((_DWORD *)v4 + 17) = v8;
*((_DWORD *)v4 + 19) = 0;
*((_DWORD *)v4 + 18) = v7;
*((_QWORD *)v4 + 10) = &v9;
*((_QWORD *)v4 + 7691) = v2;
pthread_cond_init((pthread_cond_t *)(v4 + 8), 0LL);
strcpy(v4 + 88, src);
strcpy(v4 + 20568, v11);
strcpy(v4 + 41048, v10);
pthread_create((pthread_t *)v4, 0LL, processRequest, v4);
printf("I created the %d request in order to serve the client %d \n", (unsigned int)v3++, v1);
if ( v9 )
goto LABEL_8;
}
puts("Asynchronous closed by the client");
LABEL_8:
close(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
unsigned int v1; // er12
char *v2; // r13
signed int v3; // ebp
char *v4; // rbx
struct pollfd fds; // [rsp+Ch] [rbp-6E3Ch] BYREF
int v7; // [rsp+14h] [rbp-6E34h] BYREF
int v8; // [rsp+18h] [rbp-6E30h] BYREF
int v9; // [rsp+1Ch] [rbp-6E2Ch] BYREF
char v10[2560]; // [rsp+20h] [rbp-6E28h] BYREF
char v11[2560]; // [rsp+A20h] [rbp-6428h] BYREF
char src[20480]; // [rsp+1420h] [rbp-5A28h] BYREF
char v13[2600]; // [rsp+6420h] [rbp-A28h] BYREF

v1 = *(_DWORD *)a1;
v9 = 0;
v2 = (char *)malloc(0x16EC87C00uLL);
fds.fd = v1;
fds.events = 192;
v3 = 0;
while ( 1 )
{
if ( poll(&fds, 1uLL, 10000) <= 0 )
{
puts("Connection Timeout");
goto LABEL_8;
}
if ( !(unsigned int)TCPreadline(v1, v13, 2560LL) )
break;
func1((__int64)v13, &v8, (__int64)v11, &v7, (__int64)v10);
if ( !(unsigned int)HTTPreadheader(v1, src, 20480LL) )
break;
printf("%s%s", v13, src);
HTTPheaderremove_case(src, "Connection");
v4 = &v2[61536 * (v3 % 100000)];
*((_DWORD *)v4 + 14) = v3;
*((_DWORD *)v4 + 15) = v3 % 100000;
*((_DWORD *)v4 + 16) = v1;
*((_DWORD *)v4 + 17) = v8;
*((_DWORD *)v4 + 19) = 0;
*((_DWORD *)v4 + 18) = v7;
*((_QWORD *)v4 + 10) = &v9;
*((_QWORD *)v4 + 7691) = v2;
pthread_cond_init((pthread_cond_t *)(v4 + 8), 0LL);
strcpy(v4 + 88, src);
strcpy(v4 + 20568, v11);
strcpy(v4 + 41048, v10);
pthread_create((pthread_t *)v4, 0LL, processRequest, v4);
printf("I created the %d request in order to serve the client %d \n", (unsigned int)v3++, v1);
if ( v9 )
goto LABEL_8;
}
puts("Asynchronous closed by the client");
LABEL_8:
close(v1);
return 0LL;
}

original_code:
void *serviceconn(void *socketDescriptor)
{
 int cli = *(int*)socketDescriptor;
 char reqline[2560];
 char reqhead[20480];
 char host[2560], path[2560];
 int closeCliConn = 0, requestIndex=0;
 int method, portno, adaptedIndex;
        REQUEST *reqThreadArray;
 reqThreadArray=(REQUEST*)malloc(sizeof(REQUEST)*100000);
 int timeOutSecs=10000;
 struct pollfd fds[1];
 fds[0].fd = cli;
 fds[0].events = 0x040 | 0x080;
 while(closeCliConn == 0)
 {
  if ( poll(fds, 1, timeOutSecs) <= 0 )
  {
   printf("Connection Timeout\n");
   break;
  }
  if ( TCPreadline(cli, reqline, 2560) == 0 )
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  parserequest(reqline, &method, host, &portno, path);
  if (HTTPreadheader(cli, reqhead, 20480) == 0)
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  printf("%s%s", reqline, reqhead);
  HTTPheaderremove_case(reqhead, "Connection");
  adaptedIndex=requestIndex%100000;
  reqThreadArray[adaptedIndex].requestID=requestIndex;
  reqThreadArray[adaptedIndex].adaptedID=adaptedIndex;
  reqThreadArray[adaptedIndex].socketDescriptor=cli;
  reqThreadArray[adaptedIndex].method=method;
  reqThreadArray[adaptedIndex].served=0;
  reqThreadArray[adaptedIndex].portNumber=portno;
  reqThreadArray[adaptedIndex].breakCliConn=&closeCliConn;
  reqThreadArray[adaptedIndex].arrayAddress=reqThreadArray;
  pthread_cond_init( &(reqThreadArray[adaptedIndex].cond), ((void *)0));
  strcpy(reqThreadArray[adaptedIndex].reqhead, reqhead);
  strcpy(reqThreadArray[adaptedIndex].hostName, host);
  strcpy(reqThreadArray[adaptedIndex].pathName, path);
  pthread_create(&(reqThreadArray[adaptedIndex].reqThread), ((void *)0), processRequest, &reqThreadArray[adaptedIndex]);
  printf("I created the %d request in order to serve the client %d \n", requestIndex, cli);
  requestIndex++;
 }
 close(cli);
 return 0;
}

canonical_original_code:
void *serviceconn(void *socketDescriptor)
{
 int cli = *(int*)socketDescriptor;
 char reqline[2560];
 char reqhead[20480];
 char host[2560]; char path[2560];
 int closeCliConn = 0; int requestIndex = 0;
 int method; int portno; int adaptedIndex;
        struct req *reqThreadArray;
 reqThreadArray=(struct req *)malloc(sizeof(REQUEST)*100000);
 int timeOutSecs = 10000;
 struct pollfd fds[1];
 fds[0].fd = cli;
 fds[0].events = 0x040 | 0x080;
 while(closeCliConn == 0)
 {
  if ( poll(fds, 1, timeOutSecs) <= 0 )
  {
   printf("Connection Timeout\n");
   break;
  }
  if ( TCPreadline(cli, reqline, 2560) == 0 )
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  parserequest(reqline, &method, host, &portno, path);
  if (HTTPreadheader(cli, reqhead, 20480) == 0)
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  printf("%s%s", reqline, reqhead);
  HTTPheaderremove_case(reqhead, "Connection");
  adaptedIndex=requestIndex%100000;
  reqThreadArray[adaptedIndex].requestID=requestIndex;
  reqThreadArray[adaptedIndex].adaptedID=adaptedIndex;
  reqThreadArray[adaptedIndex].socketDescriptor=cli;
  reqThreadArray[adaptedIndex].method=method;
  reqThreadArray[adaptedIndex].served=0;
  reqThreadArray[adaptedIndex].portNumber=portno;
  reqThreadArray[adaptedIndex].breakCliConn=&closeCliConn;
  reqThreadArray[adaptedIndex].arrayAddress=reqThreadArray;
  pthread_cond_init( &(reqThreadArray[adaptedIndex].cond), ((void *)0));
  strcpy(reqThreadArray[adaptedIndex].reqhead, reqhead);
  strcpy(reqThreadArray[adaptedIndex].hostName, host);
  strcpy(reqThreadArray[adaptedIndex].pathName, path);
  pthread_create(&(reqThreadArray[adaptedIndex].reqThread), ((void *)0), processRequest, &reqThreadArray[adaptedIndex]);
  printf("I created the %d request in order to serve the client %d \n", requestIndex, cli);
  requestIndex++;
 }
 close(cli);
 return 0;
}

variable_types:
socketDescriptor
void *

variable_types: cli int

variable_types:
reqline
char [2560]

variable_types:
reqhead
char [20480]

variable_types:
host
char [2560]

variable_types:
path
char [2560]

variable_types: closeCliConn int

variable_types: requestIndex int

variable_types: method int

variable_types: portno int

variable_types: adaptedIndex int

variable_types: struct req { unsigned long reqThread; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int requestID; int adaptedID; int socketDescriptor; int method; int portNumber; int served; int *breakCliConn; char reqhead[20480]; char hostName[20480]; char pathName[20480]; struct req *arrayAddress; } *

variable_types: timeOutSecs int

variable_types: struct pollfd { int fd; short events; short revents; } [1]

return_type: void *

user_defined_types: struct req { unsigned long reqThread; union pthread_cond_t cond; int requestID; int adaptedID; int socketDescriptor; int method; int portNumber; int served; int *breakCliConn; char reqhead[20480]; char hostName[20480]; char pathName[20480]; struct req *arrayAddress; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


copydata

decompiled_code:
__int64 __fastcall copydata(int fd, int a2, int a3)
{
int v3; // ebp
int v4; // eax
int v5; // ebx
_BYTE v7[8232]; // [rsp+0h] [rbp-2028h] BYREF

v3 = a3;
if ( a3 <= 0 )
return 0LL;
while ( 1 )
{
v4 = read(fd, v7, 0x2000uLL);
v5 = v4;
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
if ( write(a2, v7, v4) < v4 )
break;
v3 -= v5;
if ( v3 <= 0 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2, int a3)
{
int v3; // ebp
int v4; // eax
int v5; // ebx
_BYTE v7[8232]; // [rsp+0h] [rbp-2028h] BYREF

v3 = a3;
if ( a3 <= 0 )
return 0LL;
while ( 1 )
{
v4 = read(fd, v7, 0x2000uLL);
v5 = v4;
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
if ( write(a2, v7, v4) < v4 )
break;
v3 -= v5;
if ( v3 <= 0 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int copydata(int from, int to, int len)
{
 char tbuff[8192];
 int n;
 while (len > 0)
 {
  if ((n = read(from, tbuff, 8192)) <= 0)
  {
   return -1;
  }
  if (write(to, tbuff, n) < n)
  {
   return -1;
  }
  len -= n;
 }
 return 0;
}

variable_types: from int

variable_types: to int

variable_types: len int

variable_types:
tbuff
char [8192]

variable_types: n int


closeClientConn

decompiled_code:
__int64 __fastcall closeClientConn(__int64 a1, __int64 a2)
{
bool v2; // bp
int v3; // edx
bool v4; // al
char v6[20504]; // [rsp+0h] [rbp-5018h] BYREF

v2 = (unsigned int)HTTPheadervalue_case(a2, "Content-Length", v6) == 0;
v3 = HTTPheadervalue_case(a1, "Connection: ", v6);
v4 = 0;
if ( v3 == 1 )
{
v4 = 1;
if ( strcmp(v6, "close") )
v4 = strcmp(v6, "close\r") == 0;
}
return v2 | (unsigned __int8)v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
bool v2; // bp
int v3; // edx
bool v4; // al
char v6[20504]; // [rsp+0h] [rbp-5018h] BYREF

v2 = (unsigned int)HTTPheadervalue_case(a2, "Content-Length", v6) == 0;
v3 = HTTPheadervalue_case(a1, "Connection: ", v6);
v4 = 0;
if ( v3 == 1 )
{
v4 = 1;
if ( strcmp(v6, "close") )
v4 = strcmp(v6, "close\r") == 0;
}
return v2 | (unsigned __int8)v4;
}

original_code:
int closeClientConn(char *reqHeader, char *resHeader){
 char value[20480];
 _Bool closeConn1 = 0;
 _Bool closeConn2 = 0;
        _Bool closeConn;
 if ( HTTPheadervalue_case(resHeader, "Content-Length", value) == 0 )
 {
  closeConn1 = 1;
 }
 if ( HTTPheadervalue_case(reqHeader, "Connection: ", value) == 1)
 {
  if ( strcmp(value, "close") == 0 || strcmp(value, "close\r") == 0 )
  {
   closeConn2 = 1;
  }
 }
 closeConn = (closeConn1 || closeConn2);
 return (int)closeConn;
}

variable_types:
reqHeader
char *

variable_types:
resHeader
char *

variable_types:
value
char [20480]


processRequest

decompiled_code:
void *__fastcall processRequest(void *a1)
{
__int64 v1; // r13
int v2; // er15
int v3; // ebp
int v4; // er12
int v5; // er14
unsigned int v6; // ebx
int v7; // eax
unsigned int v8; // ebx
size_t v9; // rax
size_t v10; // rax
size_t v11; // rax
size_t v12; // rax
int v13; // eax
__int64 v14; // rbx
size_t v15; // rax
int v17; // eax
__int64 v18; // rax
__int64 v19[7693]; // [rsp+0h] [rbp-1FEA8h] BYREF
int v20; // [rsp+F068h] [rbp-10E40h] BYREF
char v21; // [rsp+F06Ch] [rbp-10E3Ch] BYREF
char v22[2560]; // [rsp+F070h] [rbp-10E38h] BYREF
char v23[2560]; // [rsp+FA70h] [rbp-10438h] BYREF
char v24[20480]; // [rsp+10470h] [rbp-FA38h] BYREF
char s[20480]; // [rsp+15470h] [rbp-AA38h] BYREF
char dest[20480]; // [rsp+1A470h] [rbp-5A38h] BYREF
char buf[2616]; // [rsp+1F470h] [rbp-A38h] BYREF

memcpy(v19, a1, 0xF060uLL);
v1 = v19[7691];
v2 = v19[7];
v3 = HIDWORD(v19[7]);
v4 = v19[8];
v5 = HIDWORD(v19[8]);
v6 = v19[9];
strcpy(dest, (const char *)&v19[11]);
strcpy(v23, (const char *)&v19[2571]);
strcpy(v22, (const char *)&v19[5131]);
printf("%s", dest);
v7 = activesocket(v23, v6);
if ( v7 < 0 )
{
strcpy(v24, "HTTP/1.1 503\r\nContent-Length: 12\r\nConnection: close\r\n\r\nNon-existent");
v15 = strlen(v24);
if ( write(v4, v24, v15) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v1 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v1 + 61536 * (v3 + 1LL) + 8));
**(_DWORD **)(v1 + 61536LL * v3 + 80) = 1;
}
}
else
{
v8 = v7;
sprintf(s, "%s %s HTTP/1.1\r\n", (&methods)[v5], v22);
strcat(s, "Connection: close\r\n");
strcat(s, dest);
v9 = strlen(s);
write(v8, s, v9);
printf("%s", s);
if ( v5 == 1 )
{
v17 = contentlength((__int64)dest);
if ( (int)copydata(v4, v8, v17) < 0 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
}
TCPreadline(v8, buf, 2560LL);
_isoc99_sscanf(buf, "HTTP/1.%d %d ", &v21, &v20);
HTTPreadheader(v8, v24, 20480LL);
HTTPheaderremove_case(v24, "Connection");
pthread_mutex_lock(&checkOrder);
if ( v2 )
{
v18 = 61536LL * v3;
if ( !*(_DWORD *)(v1 + v18 - 61460) )
pthread_cond_wait((pthread_cond_t *)(v1 + v18 + 8), &checkOrder);
}
pthread_mutex_unlock(&checkOrder);
v10 = strlen(buf);
if ( write(v4, buf, v10) == -1 )
{
puts("Asynchronous closed by the client.");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
printf("%s", buf);
if ( (unsigned int)closeClientConn((__int64)dest, (__int64)v24) == 1 )
{
strcpy(buf, "Connection: close\r\n");
**(_DWORD **)(v1 + 61536LL * v3 + 80) = 1;
}
else
{
strcpy(buf, "Connection: keep-alive\r\n");
}
v11 = strlen(buf);
if ( write(v4, buf, v11) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
v12 = strlen(v24);
if ( write(v4, v24, v12) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
{
LABEL_32:
pthread_cond_signal((pthread_cond_t *)(v1 + 8));
LABEL_35:
close(v8);
**(_DWORD **)(v1 + 61536LL * v3 + 80) = 1;
return 0LL;
}
LABEL_34:
pthread_cond_signal((pthread_cond_t *)(v1 + 61536 * (v3 + 1LL) + 8));
goto LABEL_35;
}
printf("%s%s", buf, v24);
if ( v20 != 204 && v20 != 304 )
{
v13 = contentlength((__int64)v24);
if ( (int)copydata(v8, v4, v13) < 0 )
{
puts("Asynchronous closed by the client.");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
}
close(v8);
v14 = 61536LL * v3;
*(_DWORD *)(v1 + v14 + 76) = 1;
pthread_mutex_lock(&checkOrder);
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v1 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v1 + v14 + 61544));
pthread_mutex_unlock(&checkOrder);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func5(void *a1)
{
__int64 v1; // r13
int v2; // er15
int v3; // ebp
int v4; // er12
int v5; // er14
unsigned int v6; // ebx
int v7; // eax
unsigned int v8; // ebx
size_t v9; // rax
size_t v10; // rax
size_t v11; // rax
size_t v12; // rax
int v13; // eax
__int64 v14; // rbx
size_t v15; // rax
int v17; // eax
__int64 v18; // rax
__int64 v19[7693]; // [rsp+0h] [rbp-1FEA8h] BYREF
int v20; // [rsp+F068h] [rbp-10E40h] BYREF
char v21; // [rsp+F06Ch] [rbp-10E3Ch] BYREF
char v22[2560]; // [rsp+F070h] [rbp-10E38h] BYREF
char v23[2560]; // [rsp+FA70h] [rbp-10438h] BYREF
char v24[20480]; // [rsp+10470h] [rbp-FA38h] BYREF
char s[20480]; // [rsp+15470h] [rbp-AA38h] BYREF
char dest[20480]; // [rsp+1A470h] [rbp-5A38h] BYREF
char buf[2616]; // [rsp+1F470h] [rbp-A38h] BYREF

memcpy(v19, a1, 0xF060uLL);
v1 = v19[7691];
v2 = v19[7];
v3 = HIDWORD(v19[7]);
v4 = v19[8];
v5 = HIDWORD(v19[8]);
v6 = v19[9];
strcpy(dest, (const char *)&v19[11]);
strcpy(v23, (const char *)&v19[2571]);
strcpy(v22, (const char *)&v19[5131]);
printf("%s", dest);
v7 = activesocket(v23, v6);
if ( v7 < 0 )
{
strcpy(v24, "HTTP/1.1 503\r\nContent-Length: 12\r\nConnection: close\r\n\r\nNon-existent");
v15 = strlen(v24);
if ( write(v4, v24, v15) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v1 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v1 + 61536 * (v3 + 1LL) + 8));
**(_DWORD **)(v1 + 61536LL * v3 + 80) = 1;
}
}
else
{
v8 = v7;
sprintf(s, "%s %s HTTP/1.1\r\n", (&methods)[v5], v22);
strcat(s, "Connection: close\r\n");
strcat(s, dest);
v9 = strlen(s);
write(v8, s, v9);
printf("%s", s);
if ( v5 == 1 )
{
v17 = func0((__int64)dest);
if ( (int)func3(v4, v8, v17) < 0 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
}
TCPreadline(v8, buf, 2560LL);
_isoc99_sscanf(buf, "HTTP/1.%d %d ", &v21, &v20);
HTTPreadheader(v8, v24, 20480LL);
HTTPheaderremove_case(v24, "Connection");
pthread_mutex_lock(&checkOrder);
if ( v2 )
{
v18 = 61536LL * v3;
if ( !*(_DWORD *)(v1 + v18 - 61460) )
pthread_cond_wait((pthread_cond_t *)(v1 + v18 + 8), &checkOrder);
}
pthread_mutex_unlock(&checkOrder);
v10 = strlen(buf);
if ( write(v4, buf, v10) == -1 )
{
puts("Asynchronous closed by the client.");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
printf("%s", buf);
if ( (unsigned int)func4((__int64)dest, (__int64)v24) == 1 )
{
strcpy(buf, "Connection: close\r\n");
**(_DWORD **)(v1 + 61536LL * v3 + 80) = 1;
}
else
{
strcpy(buf, "Connection: keep-alive\r\n");
}
v11 = strlen(buf);
if ( write(v4, buf, v11) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
v12 = strlen(v24);
if ( write(v4, v24, v12) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
{
LABEL_32:
pthread_cond_signal((pthread_cond_t *)(v1 + 8));
LABEL_35:
close(v8);
**(_DWORD **)(v1 + 61536LL * v3 + 80) = 1;
return 0LL;
}
LABEL_34:
pthread_cond_signal((pthread_cond_t *)(v1 + 61536 * (v3 + 1LL) + 8));
goto LABEL_35;
}
printf("%s%s", buf, v24);
if ( v20 != 204 && v20 != 304 )
{
v13 = func0((__int64)v24);
if ( (int)func3(v8, v4, v13) < 0 )
{
puts("Asynchronous closed by the client.");
if ( v3 == 99999 )
goto LABEL_32;
goto LABEL_34;
}
}
close(v8);
v14 = 61536LL * v3;
*(_DWORD *)(v1 + v14 + 76) = 1;
pthread_mutex_lock(&checkOrder);
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v1 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v1 + v14 + 61544));
pthread_mutex_unlock(&checkOrder);
}
return 0LL;
}

original_code:
void *processRequest(void *args){
 char resline[2560];
 char reqhead[20480], reqhead1[20480], reshead[20480];
 char host[2560], path[2560];
 int srv, v, status;
 REQUEST currentReq=*(REQUEST*)args;
 REQUEST *arrayHead = currentReq.arrayAddress;
 int reqID = currentReq.requestID;
 int adaptID = currentReq.adaptedID;
 int cli = currentReq.socketDescriptor;
 int method = currentReq.method;
 int portno = currentReq.portNumber;
 strcpy(reqhead, currentReq.reqhead);
 strcpy(host, currentReq.hostName);
 strcpy(path, currentReq.pathName);
 printf("%s", reqhead);
 if ((srv = activesocket(host, portno)) < 0)
 {
  sprintf(reshead, "HTTP/1.1 503\r\nContent-Length: 12\r\nConnection: close\r\n\r\nNon-existent");
  if ( write(cli, reshead, strlen(reshead)) == -1 )
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
 }
 else
 {
  sprintf(reqhead1, "%s %s HTTP/1.1\r\n", methods[method], path);
  strcat(reqhead1, "Connection: close\r\n");
  strcat(reqhead1, reqhead);
  write(srv, reqhead1, strlen(reqhead1));
  printf("%s", reqhead1);
  if (method == 1)
  {
   if ( copydata(cli, srv, contentlength(reqhead)) < 0 )
   {
    printf("Asynchronous closed by the client\n");
    if (adaptID==100000 -1){
     pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  TCPreadline(srv, resline, 2560);
  sscanf(resline, "HTTP/1.%d %d ", &v, &status);
  HTTPreadheader(srv, reshead, 20480);
  HTTPheaderremove_case(reshead, "Connection");
  pthread_mutex_lock(&checkOrder);
  if( reqID==0 && (arrayHead[100000 -1].served) == 0 && reqID>100000)
  {
   pthread_cond_wait( &(arrayHead[adaptID].cond), &checkOrder);
  }
  else if( reqID!=0 && (arrayHead[adaptID-1].served)==0)
  {
   pthread_cond_wait(&(arrayHead[adaptID].cond), &checkOrder);
  }
  pthread_mutex_unlock(&checkOrder);
  if ( write(cli, resline, strlen(resline)) == -1 )
  {
   printf("Asynchronous closed by the client.\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s", resline);
  if ( closeClientConn(reqhead, reshead) == 1)
  {
   strcpy(resline, "Connection: close\r\n");
   *(arrayHead[adaptID].breakCliConn) = 1;
  }
  else
  {
   strcpy(resline, "Connection: keep-alive\r\n");
  }
  if ( write(cli, resline, strlen(resline)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  if( write(cli, reshead, strlen(reshead)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s%s", resline, reshead);
  if (status != 204 && status != 304)
  {
   if ( copydata(srv, cli, contentlength(reshead)) < 0 ){
    printf("Asynchronous closed by the client.\n");
    if (adaptID==100000 -1){
    pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  close(srv);
  arrayHead[adaptID].served = 1;
  pthread_mutex_lock(&checkOrder);
  if (adaptID==100000 -1)
  {
   pthread_cond_signal(&(arrayHead[0].cond));
  }
  else
  {
   pthread_cond_signal(&(arrayHead[adaptID+1].cond));
  }
  pthread_mutex_unlock(&checkOrder);
 }
 return ((void *)0);
}

canonical_original_code:
void *processRequest(void *args){
 char resline[2560];
 char reqhead[20480]; char reqhead1[20480]; char reshead[20480];
 char host[2560]; char path[2560];
 int srv; int v; int status;
 struct req currentReq = *(REQUEST*)args;
 struct req *arrayHead = currentReq.arrayAddress;
 int reqID = currentReq.requestID;
 int adaptID = currentReq.adaptedID;
 int cli = currentReq.socketDescriptor;
 int method = currentReq.method;
 int portno = currentReq.portNumber;
 strcpy(reqhead, currentReq.reqhead);
 strcpy(host, currentReq.hostName);
 strcpy(path, currentReq.pathName);
 printf("%s", reqhead);
 if ((srv = activesocket(host, portno)) < 0)
 {
  sprintf(reshead, "HTTP/1.1 503\r\nContent-Length: 12\r\nConnection: close\r\n\r\nNon-existent");
  if ( write(cli, reshead, strlen(reshead)) == -1 )
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
 }
 else
 {
  sprintf(reqhead1, "%s %s HTTP/1.1\r\n", methods[method], path);
  strcat(reqhead1, "Connection: close\r\n");
  strcat(reqhead1, reqhead);
  write(srv, reqhead1, strlen(reqhead1));
  printf("%s", reqhead1);
  if (method == 1)
  {
   if ( copydata(cli, srv, contentlength(reqhead)) < 0 )
   {
    printf("Asynchronous closed by the client\n");
    if (adaptID==100000 -1){
     pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  TCPreadline(srv, resline, 2560);
  sscanf(resline, "HTTP/1.%d %d ", &v, &status);
  HTTPreadheader(srv, reshead, 20480);
  HTTPheaderremove_case(reshead, "Connection");
  pthread_mutex_lock(&checkOrder);
  if( reqID==0 && (arrayHead[100000 -1].served) == 0 && reqID>100000)
  {
   pthread_cond_wait( &(arrayHead[adaptID].cond), &checkOrder);
  }
  else if( reqID!=0 && (arrayHead[adaptID-1].served)==0)
  {
   pthread_cond_wait(&(arrayHead[adaptID].cond), &checkOrder);
  }
  pthread_mutex_unlock(&checkOrder);
  if ( write(cli, resline, strlen(resline)) == -1 )
  {
   printf("Asynchronous closed by the client.\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s", resline);
  if ( closeClientConn(reqhead, reshead) == 1)
  {
   strcpy(resline, "Connection: close\r\n");
   *(arrayHead[adaptID].breakCliConn) = 1;
  }
  else
  {
   strcpy(resline, "Connection: keep-alive\r\n");
  }
  if ( write(cli, resline, strlen(resline)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  if( write(cli, reshead, strlen(reshead)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s%s", resline, reshead);
  if (status != 204 && status != 304)
  {
   if ( copydata(srv, cli, contentlength(reshead)) < 0 ){
    printf("Asynchronous closed by the client.\n");
    if (adaptID==100000 -1){
    pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  close(srv);
  arrayHead[adaptID].served = 1;
  pthread_mutex_lock(&checkOrder);
  if (adaptID==100000 -1)
  {
   pthread_cond_signal(&(arrayHead[0].cond));
  }
  else
  {
   pthread_cond_signal(&(arrayHead[adaptID+1].cond));
  }
  pthread_mutex_unlock(&checkOrder);
 }
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
resline
char [2560]

variable_types:
reqhead
char [20480]

variable_types:
reshead
char [20480]

variable_types:
host
char [2560]

variable_types:
path
char [2560]

variable_types: srv int

variable_types: v int

variable_types: status int

variable_types: struct req { unsigned long reqThread; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int requestID; int adaptedID; int socketDescriptor; int method; int portNumber; int served; int *breakCliConn; char reqhead[20480]; char hostName[20480]; char pathName[20480]; struct req *arrayAddress; }

variable_types: reqID int

variable_types: adaptID int

variable_types: cli int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // ebp
pthread_t *v5; // rbx
int arg[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = atoi(argv[1]);
v4 = passivesocket(v3);
signal(13, (__sighandler_t)((char *)contentlength + 1));
while ( 1 )
{
do
arg[0] = acceptconnection(v4);
while ( arg[0] == -1 );
v5 = (pthread_t *)malloc(8uLL);
pthread_mutex_lock(&accessCLI);
pthread_create(v5, 0LL, serviceconn, arg);
pthread_mutex_unlock(&accessCLI);
}
}

original_code:
int main(int argc, char *argv[])
{
 int socketDescriptor;
 int s = passivesocket(atoi(argv[1]));
 signal(13, ((__sighandler_t) 1));
 while(1){
  socketDescriptor= acceptconnection(s);
  if (socketDescriptor != -1)
  {
   pthread_t *client;
   client=(pthread_t*)malloc(sizeof(pthread_t));
   pthread_mutex_lock(&accessCLI);
   pthread_create(client, ((void *)0), serviceconn, &socketDescriptor);
   pthread_mutex_unlock(&accessCLI);
  }
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int socketDescriptor;
 int s = passivesocket(atoi(argv[1]));
 signal(13, ((void (*)(int)) 1));
 while(1){
  socketDescriptor= acceptconnection(s);
  if (socketDescriptor != -1)
  {
   unsigned long *client;
   client=(unsigned long *)malloc(sizeof(pthread_t));
   pthread_mutex_lock(&accessCLI);
   pthread_create(client, ((void *)0), serviceconn, &socketDescriptor);
   pthread_mutex_unlock(&accessCLI);
  }
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: socketDescriptor int

variable_types: s int

variable_types:
client
unsigned long *


decompiled_code:
char *__fastcall parse_args(int argc, char **argv)
{
char *v3; // r12
char v4; // al
int v5; // edi
char *v6; // rax
int v7; // edi
char *v8; // rax
char v9; // al
const char **v10; // r13
int v11; // ebp
size_t v12; // r12
const char **v13; // rbx
char *v14; // rax
char *result; // rax
const char **v16; // rbx
__int64 v17; // r12
char *v18; // rbp

v3 = *argv;
while ( 1 )
{
v4 = getopt(argc, argv, "hl:s:o:");
if ( v4 == -1 )
break;
if ( v4 == 111 )
{
v9 = *optarg;
if ( *optarg == 110 )
{
format = 2;
}
else if ( v9 == 114 )
{
format = 0;
}
else
{
if ( v9 != 104 )
{
fprintf(stderr, "Unknown format: %c\n", (unsigned int)v9);
usage(stderr, v3);
exit(64);
}
format = 1;
}
}
else if ( v4 > 111 )
{
if ( v4 != 115 )
goto LABEL_22;
dlt = strtol(optarg, 0LL, 0);
if ( !dlt )
{
v7 = *__errno_location();
if ( v7 )
{
v8 = strerror(v7);
fprintf(stderr, "Failed to parse %s: %s\n", optarg, v8);
exit(64);
}
}
}
else
{
if ( v4 == 104 )
{
usage(stdout, v3);
exit(0);
}
if ( v4 != 108 )
{
LABEL_22:
usage(stderr, v3);
exit(64);
}
dlt = strtol(optarg, 0LL, 0);
if ( !dlt )
{
v5 = *__errno_location();
if ( v5 )
{
v6 = strerror(v5);
fprintf(stderr, "Failed to parse %s: %s\n", optarg, v6);
exit(64);
}
}
}
}
v10 = (const char **)&argv[optind];
v11 = argc - optind;
if ( !v11 )
{
fwrite("Expression expected\n", 1uLL, 0x14uLL, stderr);
usage(stderr, v3);
exit(64);
}
v12 = v11;
if ( v11 > 0 )
{
v13 = (const char **)&argv[optind];
do
v12 += strlen(*v13++);
while ( v13 != &v10[(unsigned int)(v11 - 1) + 1] );
}
v14 = (char *)malloc(v12);
expr = v14;
if ( !v14 )
exit(70);
*v14 = 0;
result = strcat(v14, *v10);
if ( v11 > 1 )
{
v16 = v10 + 1;
v17 = (__int64)&v10[(unsigned int)(v11 - 2) + 2];
do
{
v18 = expr;
*(_WORD *)&v18[strlen(expr)] = 32;
result = strcat(expr, *v16++);
}
while ( v16 != (const char **)v17 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(int argc, char **argv)
{
char *v3; // r12
char v4; // al
int v5; // edi
char *v6; // rax
int v7; // edi
char *v8; // rax
char v9; // al
const char **v10; // r13
int v11; // ebp
size_t v12; // r12
const char **v13; // rbx
char *v14; // rax
char *result; // rax
const char **v16; // rbx
__int64 v17; // r12
char *v18; // rbp

v3 = *argv;
while ( 1 )
{
v4 = getopt(argc, argv, "hl:s:o:");
if ( v4 == -1 )
break;
if ( v4 == 111 )
{
v9 = *optarg;
if ( *optarg == 110 )
{
format = 2;
}
else if ( v9 == 114 )
{
format = 0;
}
else
{
if ( v9 != 104 )
{
fprintf(stderr, "Unknown format: %c\n", (unsigned int)v9);
func7(stderr, v3);
exit(64);
}
format = 1;
}
}
else if ( v4 > 111 )
{
if ( v4 != 115 )
goto LABEL_22;
dlt = strtol(optarg, 0LL, 0);
if ( !dlt )
{
v7 = *__errno_location();
if ( v7 )
{
v8 = strerror(v7);
fprintf(stderr, "Failed to parse %s: %s\n", optarg, v8);
exit(64);
}
}
}
else
{
if ( v4 == 104 )
{
func7(stdout, v3);
exit(0);
}
if ( v4 != 108 )
{
LABEL_22:
func7(stderr, v3);
exit(64);
}
dlt = strtol(optarg, 0LL, 0);
if ( !dlt )
{
v5 = *__errno_location();
if ( v5 )
{
v6 = strerror(v5);
fprintf(stderr, "Failed to parse %s: %s\n", optarg, v6);
exit(64);
}
}
}
}
v10 = (const char **)&argv[optind];
v11 = argc - optind;
if ( !v11 )
{
fwrite("Expression expected\n", 1uLL, 0x14uLL, stderr);
func7(stderr, v3);
exit(64);
}
v12 = v11;
if ( v11 > 0 )
{
v13 = (const char **)&argv[optind];
do
v12 += strlen(*v13++);
while ( v13 != &v10[(unsigned int)(v11 - 1) + 1] );
}
v14 = (char *)malloc(v12);
expr = v14;
if ( !v14 )
exit(70);
*v14 = 0;
result = strcat(v14, *v10);
if ( v11 > 1 )
{
v16 = v10 + 1;
v17 = (__int64)&v10[(unsigned int)(v11 - 2) + 2];
do
{
v18 = expr;
*(_WORD *)&v18[strlen(expr)] = 32;
result = strcat(expr, *v16++);
}
while ( v16 != (const char **)v17 );
}
return result;
}

original_code:
void
parse_args(int argc, char *argv[])
{
 char c;
 char *progname = argv[0];
 int i;
 size_t len;
 while((c = getopt(argc, argv, "hl:s:o:")) != -1)
 {
  switch(c)
  {
  case 'h':
   usage(stdout, progname);
   exit(0);
   break;
  case 'l':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 's':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 'o':
   switch(optarg[0])
   {
   case 'r':
    format = RAW;
    break;
   case 'h':
    format = HEXSTRING;
    break;
   case 'n':
    format = NG_BPF;
    break;
   default:
    fprintf(stderr, "Unknown format: %c\n", optarg[0]);
    usage(stderr, progname);
    exit(64);
    break;
   }
   break;
  default:
   usage(stderr, progname);
   exit(64);
   break;
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0)
 {
  fprintf(stderr, "Expression expected\n");
  usage(stderr, progname);
  exit(64);
 }
 len = argc;
 for(i = 0; i < argc; i++)
  len += strlen(argv[i]);
 expr = malloc(len);
 if (expr == ((void *)0))
  exit(70);
 expr[0] = '\0';
 strcat(expr, argv[0]);
 for(i = 1; i < argc; i++)
 {
  strcat(expr, " ");
  strcat(expr, argv[i]);
 }
}

canonical_original_code:
void parse_args(int argc, char *argv[])
{
 char c;
 char *progname = argv[0];
 int i;
 unsigned long len;
 while((c = getopt(argc, argv, "hl:s:o:")) != -1)
 {
  switch(c)
  {
  case 'h':
   usage(stdout, progname);
   exit(0);
   break;
  case 'l':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 's':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 'o':
   switch(optarg[0])
   {
   case 'r':
    format = RAW;
    break;
   case 'h':
    format = HEXSTRING;
    break;
   case 'n':
    format = NG_BPF;
    break;
   default:
    fprintf(stderr, "Unknown format: %c\n", optarg[0]);
    usage(stderr, progname);
    exit(64);
    break;
   }
   break;
  default:
   usage(stderr, progname);
   exit(64);
   break;
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0)
 {
  fprintf(stderr, "Expression expected\n");
  usage(stderr, progname);
  exit(64);
 }
 len = argc;
 for(i = 0; i < argc; i++)
  len += strlen(argv[i]);
 expr = malloc(len);
 if (expr == ((void *)0))
  exit(70);
 expr[0] = '\0';
 strcat(expr, argv[0]);
 for(i = 1; i < argc; i++)
 {
  strcat(expr, " ");
  strcat(expr, argv[i]);
 }
}

variable_types: c char

variable_types:
progname
char *

variable_types: i int

variable_types:
len
unsigned long


decompiled_code:
unsigned __int64 __fastcall print_raw(unsigned int *a1)
{
unsigned __int64 v1; // r12
unsigned __int64 result; // rax

if ( *a1 )
{
v1 = 0LL;
do
{
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 1));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 2));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 3));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 7));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 6));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 5));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1++ + 4));
result = *a1;
}
while ( result > v1 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(unsigned int *a1)
{
unsigned __int64 v1; // r12
unsigned __int64 result; // rax

if ( *a1 )
{
v1 = 0LL;
do
{
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 1));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 2));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 3));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 7));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 6));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 5));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1++ + 4));
result = *a1;
}
while ( result > v1 );
}
return result;
}

original_code:
void
print_raw(const struct bpf_program *prog)
{
 size_t i;
 for(i = 0; i < prog->bf_len; i++)
 {
  putchar(prog->bf_insns[i].code >> 8);
  putchar(prog->bf_insns[i].code & 0xff);
  putchar(prog->bf_insns[i].jt);
  putchar(prog->bf_insns[i].jf);
  putchar(prog->bf_insns[i].k >> 24);
  putchar((prog->bf_insns[i].k >> 16) & 0xff);
  putchar((prog->bf_insns[i].k >> 8) & 0xff);
  putchar(prog->bf_insns[i].k & 0xff);
 }
}

canonical_original_code:
void print_raw(struct bpf_program *prog)
{
 unsigned long i;
 for(i = 0; i < prog->bf_len; i++)
 {
  putchar(prog->bf_insns[i].code >> 8);
  putchar(prog->bf_insns[i].code & 0xff);
  putchar(prog->bf_insns[i].jt);
  putchar(prog->bf_insns[i].jf);
  putchar(prog->bf_insns[i].k >> 24);
  putchar((prog->bf_insns[i].k >> 16) & 0xff);
  putchar((prog->bf_insns[i].k >> 8) & 0xff);
  putchar(prog->bf_insns[i].k & 0xff);
 }
}

variable_types: struct bpf_program { unsigned int bf_len; struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *bf_insns; } *

variable_types:
i
unsigned long

user_defined_types: struct bpf_program { unsigned int bf_len; struct bpf_insn *bf_insns; }


original_code:
void
print_hexstring(const struct bpf_program *prog)
{
 size_t i;
 for(i = 0; i < prog->bf_len; i++)
 {
  printf("%02X", prog->bf_insns[i].code >> 8);
  printf("%02X", prog->bf_insns[i].code & 0xff);
  printf("%02X", prog->bf_insns[i].jt);
  printf("%02X", prog->bf_insns[i].jf);
  printf("%02X", prog->bf_insns[i].k >> 24);
  printf("%02X", (prog->bf_insns[i].k >> 16) & 0xff);
  printf("%02X", (prog->bf_insns[i].k >> 8) & 0xff);
  printf("%02X", prog->bf_insns[i].k & 0xff);
 }
 printf("\n");
}

canonical_original_code:
void print_hexstring(struct bpf_program *prog)
{
 unsigned long i;
 for(i = 0; i < prog->bf_len; i++)
 {
  printf("%02X", prog->bf_insns[i].code >> 8);
  printf("%02X", prog->bf_insns[i].code & 0xff);
  printf("%02X", prog->bf_insns[i].jt);
  printf("%02X", prog->bf_insns[i].jf);
  printf("%02X", prog->bf_insns[i].k >> 24);
  printf("%02X", (prog->bf_insns[i].k >> 16) & 0xff);
  printf("%02X", (prog->bf_insns[i].k >> 8) & 0xff);
  printf("%02X", prog->bf_insns[i].k & 0xff);
 }
 printf("\n");
}

user_defined_types: struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; }


decompiled_code:
int __fastcall print_ng_bpf(unsigned int *a1)
{
unsigned __int64 v1; // rbx

printf("bpf_prog_len=%d bpf_prog=[ ", *a1);
if ( *a1 )
{
v1 = 0LL;
do
{
printf(
"{ code=%d jt=%d jf=%d k=%d } ",
*(unsigned __int16 *)(*((_QWORD *)a1 + 1) + 8 * v1),
*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 2),
*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 3),
*(unsigned int *)(*((_QWORD *)a1 + 1) + 8 * v1 + 4));
++v1;
}
while ( *a1 > v1 );
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
unsigned __int64 v1; // rbx

printf("bpf_prog_len=%d bpf_prog=[ ", *a1);
if ( *a1 )
{
v1 = 0LL;
do
{
printf(
"{ code=%d jt=%d jf=%d k=%d } ",
*(unsigned __int16 *)(*((_QWORD *)a1 + 1) + 8 * v1),
*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 2),
*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v1 + 3),
*(unsigned int *)(*((_QWORD *)a1 + 1) + 8 * v1 + 4));
++v1;
}
while ( *a1 > v1 );
}
return puts("]");
}

original_code:
void
print_ng_bpf(const struct bpf_program *prog)
{
 size_t i;
 printf("bpf_prog_len=%d bpf_prog=[ ", prog->bf_len);
 for (i = 0; i < prog->bf_len; i++)
 {
  printf("{ code=%d jt=%d jf=%d k=%d } ", prog->bf_insns[i].code, prog->bf_insns[i].jt, prog->bf_insns[i].jf, prog->bf_insns[i].k);
 }
 printf("]\n");
}

canonical_original_code:
void print_ng_bpf(struct bpf_program *prog)
{
 unsigned long i;
 printf("bpf_prog_len=%d bpf_prog=[ ", prog->bf_len);
 for (i = 0; i < prog->bf_len; i++)
 {
  printf("{ code=%d jt=%d jf=%d k=%d } ", prog->bf_insns[i].code, prog->bf_insns[i].jt, prog->bf_insns[i].jf, prog->bf_insns[i].k);
 }
 printf("]\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[6]; // [rsp+0h] [rbp-18h] BYREF

parse_args(argc, (char **)argv);
if ( (unsigned int)pcap_compile_nopcap() )
{
fwrite("Syntax error in expression\n", 1uLL, 0x1BuLL, stderr);
exit(64);
}
switch ( format )
{
case 1:
print_hexstring(v4);
break;
case 2:
print_ng_bpf(v4);
break;
case 0:
print_raw(v4);
break;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[6]; // [rsp+0h] [rbp-18h] BYREF

func8(argc, (char **)argv);
if ( (unsigned int)pcap_compile_nopcap() )
{
fwrite("Syntax error in expression\n", 1uLL, 0x1BuLL, stderr);
exit(64);
}
switch ( format )
{
case 1:
func10(v4);
break;
case 2:
func11(v4);
break;
case 0:
func9(v4);
break;
}
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 struct bpf_program prog;
 parse_args(argc, argv);
 if (pcap_compile_nopcap(snaplen, dlt, &prog, expr, 1, 0))
 {
  fprintf(stderr, "Syntax error in expression\n");
  exit(64);
 }
 switch(format)
 {
 case RAW:
  print_raw(&prog);
  break;
 case HEXSTRING:
  print_hexstring(&prog);
  break;
 case NG_BPF:
  print_ng_bpf(&prog);
  break;
 }
 return 0;
}

variable_types: struct bpf_program { unsigned int bf_len; struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *bf_insns; }


RangeDestroy

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

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

original_code:
void RangeDestroy(Range *r) {
    if (r) {
        free(r);
        r = ((void *)0);
    }
}

canonical_original_code:
void RangeDestroy(struct Range *r) {
    if (r) {
        free(r);
        r = ((void *)0);
    }
}

variable_types: struct Range { unsigned long max; unsigned long min; } *


WriteSetCreate

decompiled_code:
_QWORD *WriteSetCreate()
{
_QWORD *v0; // rbx

v0 = malloc(8uLL);
*v0 = al_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rbx

v0 = malloc(8uLL);
*v0 = al_new();
return v0;
}

original_code:
WriteSet *WriteSetCreate() {
    WriteSet *new = malloc(sizeof(WriteSet));
    new->ranges = al_new();
    return (new);
}

canonical_original_code:
struct WriteSet *WriteSetCreate() {
    struct WriteSet *new = malloc(sizeof(WriteSet));
    new->ranges = al_new();
    return (new);
}

variable_types: struct WriteSet { struct ArrayList { void **al_elements; int al_size; int al_capacity; enum ATYPE { AL_LIST_UNSORTED=0, AL_LIST_SORTED=1, AL_LIST_SET=2 } al_type; int al_lock; unsigned int flags; int (*al_compare)(void *, void *); void (*al_print)(void *); void (*al_free)(void *); } *ranges; } *

user_defined_types: struct WriteSet { struct ArrayList *ranges; }

user_defined_types: struct ArrayList { void **al_elements; int al_size; int al_capacity; enum ATYPE al_type; int al_lock; unsigned int flags; int (*al_compare)(void *, void *); void (*al_print)(void *); void (*al_free)(void *); }


WriteSetDestroy

decompiled_code:
void __fastcall WriteSetDestroy(void *ptr)
{
if ( ptr )
{
al_freeWithElements(*(_QWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
al_freeWithElements(*(_QWORD *)ptr);
free(ptr);
}
}

original_code:
void WriteSetDestroy(WriteSet *ws) {
    if(ws != ((void *)0)) {
        al_freeWithElements(ws->ranges);
        free(ws);
    }
    ws = ((void *)0);
}

canonical_original_code:
void WriteSetDestroy(struct WriteSet *ws) {
    if(ws != ((void *)0)) {
        al_freeWithElements(ws->ranges);
        free(ws);
    }
    ws = ((void *)0);
}

user_defined_types: enum ATYPE { AL_LIST_UNSORTED=0, AL_LIST_SORTED=1, AL_LIST_SET=2 }