main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
_DWORD *v8; // r15
_DWORD *v9; // r13
_DWORD *v10; // rbp
_DWORD *v11; // rbx
unsigned int v12; // eax
__int64 v13; // rax
int v14; // er14
int result; // eax
double v16; // r12
double v17; // xmm0_8
double v18; // xmm1_8
double v19; // xmm0_8
unsigned __int64 v20; // rax
double v21; // xmm1_8
double v22; // xmm0_8
double v23; // xmm1_8
double v24; // xmm0_8
unsigned __int64 v25; // rax
double v26; // xmm1_8
FILE *v27; // rsi
unsigned int *v28; // r12
__int64 v29; // r14
int fd; // [rsp+8h] [rbp-2FC0h]
int v31; // [rsp+10h] [rbp-2FB8h]
int v32; // [rsp+1Ch] [rbp-2FACh]
unsigned int *ptr; // [rsp+20h] [rbp-2FA8h]
double v34; // [rsp+28h] [rbp-2FA0h]
double v35; // [rsp+30h] [rbp-2F98h]
double v36; // [rsp+38h] [rbp-2F90h]
double v37; // [rsp+40h] [rbp-2F88h]
double v38; // [rsp+48h] [rbp-2F80h]
__int64 v39; // [rsp+50h] [rbp-2F78h] BYREF
unsigned __int64 v40; // [rsp+58h] [rbp-2F70h] BYREF
__int64 v41; // [rsp+60h] [rbp-2F68h] BYREF
unsigned __int64 v42; // [rsp+68h] [rbp-2F60h] BYREF
__int64 buf; // [rsp+70h] [rbp-2F58h] BYREF
unsigned __int64 v44; // [rsp+78h] [rbp-2F50h] BYREF
__int64 v45; // [rsp+80h] [rbp-2F48h] BYREF
unsigned __int64 v46; // [rsp+88h] [rbp-2F40h] BYREF
bool v47[3008]; // [rsp+90h] [rbp-2F38h] BYREF
bool v48[3008]; // [rsp+C50h] [rbp-2378h] BYREF
bool v49[3008]; // [rsp+1810h] [rbp-17B8h] BYREF
bool v50[3064]; // [rsp+23D0h] [rbp-BF8h] BYREF

attr = 0;
qword_404108 = 0LL;
byte_404128 &= 0xFEu;
v3 = getpid();
v4 = perf_event_open((__int64)&attr, v3, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( v4 < 0 )
perror("Opening performance counter");
dword_404170 = 0;
qword_404178 = 5LL;
byte_404198 &= 0xFEu;
v5 = getpid();
fd = perf_event_open((__int64)&dword_404170, v5, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( fd < 0 )
perror("Opening performance counter");
dword_4041E0 = 0;
qword_4041E8 = 4LL;
byte_404208 &= 0xFEu;
v6 = getpid();
v31 = perf_event_open((__int64)&dword_4041E0, v6, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( v31 < 0 )
perror("Opening performance counter");
dword_404250 = 0;
qword_404258 = 1LL;
byte_404278 &= 0xFEu;
v7 = getpid();
v32 = perf_event_open((__int64)&dword_404250, v7, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( v32 < 0 )
perror("Opening performance counter");
if ( argc == 5 )
{
v34 = atof(argv[1]);
v35 = atof(argv[2]);
v36 = atof(argv[3]);
v37 = atof(argv[4]);
v8 = malloc(0x17D78400uLL);
v9 = malloc(0x17D78400uLL);
v10 = malloc(0x17D78400uLL);
v11 = malloc(0x17D78400uLL);
ptr = (unsigned int *)malloc(0x17D78400uLL);
v12 = time(0LL);
srand(v12);
createData(v50, v34);
createData(v49, v35);
createData(v48, v36);
createData(v47, v37);
createOffsets(v8);
createOffsets(v9);
createOffsets(v10);
createOffsets(v11);
puts("Loop start!");
fflush(stdout);
v38 = get_timestamp(0.0);
if ( !(unsigned int)read(v4, &buf, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Au, "main");
if ( !(unsigned int)read(fd, &v44, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Bu, "main");
if ( !(unsigned int)read(v31, &v45, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Cu, "main");
if ( !(unsigned int)read(v32, &v46, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Du, "main");
v13 = 0LL;
v14 = 0;
do
{
if ( v47[v11[v13]] && v48[v10[v13]] && v49[v9[v13]] && v50[v8[v13]] )
ptr[v14++] = v13;
++v13;
}
while ( v13 != 100000000 );
if ( !(unsigned int)read(v4, &v39, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Du, "main");
if ( !(unsigned int)read(fd, &v40, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Eu, "main");
if ( !(unsigned int)read(v31, &v41, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Fu, "main");
if ( !(unsigned int)read(v32, &v42, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0xA0u, "main");
close(v4);
close(fd);
close(v31);
close(v32);
v16 = get_timestamp(v38);
puts("Loop stop!");
printf("Elapsed time: %.9lf seconds\n", v16);
printf("CPU Cycles: %lu \n", v39 - buf);
printf("Instructions: %lu \n", v42 - v46);
if ( (v42 & 0x8000000000000000LL) != 0LL )
v17 = (double)(int)(v42 & 1 | (v42 >> 1)) + (double)(int)(v42 & 1 | (v42 >> 1));
else
v17 = (double)(int)v42;
if ( (v46 & 0x8000000000000000LL) != 0LL )
v18 = (double)(int)(v46 & 1 | (v46 >> 1)) + (double)(int)(v46 & 1 | (v46 >> 1));
else
v18 = (double)(int)v46;
v19 = v17 - v18;
v20 = v39 - buf;
if ( v39 - buf < 0 )
v21 = (double)(int)(v20 & 1 | (v20 >> 1)) + (double)(int)(v20 & 1 | (v20 >> 1));
else
v21 = (double)(int)v20;
printf("IPC: %lf\n", v19 / v21);
printf("Branch misses: %lu \n", v40 - v44);
printf("Branch instructions: %lu \n", v41 - v45);
if ( (v40 & 0x8000000000000000LL) != 0LL )
v22 = (double)(int)(v40 & 1 | (v40 >> 1)) + (double)(int)(v40 & 1 | (v40 >> 1));
else
v22 = (double)(int)v40;
if ( (v44 & 0x8000000000000000LL) != 0LL )
v23 = (double)(int)(v44 & 1 | (v44 >> 1)) + (double)(int)(v44 & 1 | (v44 >> 1));
else
v23 = (double)(int)v44;
v24 = (v22 - v23) * 100.0;
v25 = v41 - v45;
if ( v41 - v45 < 0 )
v26 = (double)(int)(v25 & 1 | (v25 >> 1)) + (double)(int)(v25 & 1 | (v25 >> 1));
else
v26 = (double)(int)v25;
printf("Branch mispred. rate: %lf%%\n", v24 / v26);
putchar(10);
printf("overall selectivity = %10.9f\n", (double)v14 / 100000000.0);
printf("theoretical selectivity = %10.9f\n", v34 * v35 * v36 * v37);
v27 = fopen("/dev/null", "w");
if ( v14 > 0 )
{
v28 = ptr;
v29 = (__int64)&ptr[v14 - 1 + 1];
do
fprintf(v27, "%d ", *v28++);
while ( v28 != (unsigned int *)v29 );
}
fclose(v27);
free(v8);
free(v9);
free(v10);
free(v11);
free(ptr);
result = 0;
}
else
{
puts("argument error!");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
_DWORD *v8; // r15
_DWORD *v9; // r13
_DWORD *v10; // rbp
_DWORD *v11; // rbx
unsigned int v12; // eax
__int64 v13; // rax
int v14; // er14
int result; // eax
double v16; // r12
double v17; // xmm0_8
double v18; // xmm1_8
double v19; // xmm0_8
unsigned __int64 v20; // rax
double v21; // xmm1_8
double v22; // xmm0_8
double v23; // xmm1_8
double v24; // xmm0_8
unsigned __int64 v25; // rax
double v26; // xmm1_8
FILE *v27; // rsi
unsigned int *v28; // r12
__int64 v29; // r14
int fd; // [rsp+8h] [rbp-2FC0h]
int v31; // [rsp+10h] [rbp-2FB8h]
int v32; // [rsp+1Ch] [rbp-2FACh]
unsigned int *ptr; // [rsp+20h] [rbp-2FA8h]
double v34; // [rsp+28h] [rbp-2FA0h]
double v35; // [rsp+30h] [rbp-2F98h]
double v36; // [rsp+38h] [rbp-2F90h]
double v37; // [rsp+40h] [rbp-2F88h]
double v38; // [rsp+48h] [rbp-2F80h]
__int64 v39; // [rsp+50h] [rbp-2F78h] BYREF
unsigned __int64 v40; // [rsp+58h] [rbp-2F70h] BYREF
__int64 v41; // [rsp+60h] [rbp-2F68h] BYREF
unsigned __int64 v42; // [rsp+68h] [rbp-2F60h] BYREF
__int64 buf; // [rsp+70h] [rbp-2F58h] BYREF
unsigned __int64 v44; // [rsp+78h] [rbp-2F50h] BYREF
__int64 v45; // [rsp+80h] [rbp-2F48h] BYREF
unsigned __int64 v46; // [rsp+88h] [rbp-2F40h] BYREF
bool v47[3008]; // [rsp+90h] [rbp-2F38h] BYREF
bool v48[3008]; // [rsp+C50h] [rbp-2378h] BYREF
bool v49[3008]; // [rsp+1810h] [rbp-17B8h] BYREF
bool v50[3064]; // [rsp+23D0h] [rbp-BF8h] BYREF

attr = 0;
qword_404108 = 0LL;
byte_404128 &= 0xFEu;
v3 = getpid();
v4 = func7((__int64)&attr, v3, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( v4 < 0 )
perror("Opening performance counter");
dword_404170 = 0;
qword_404178 = 5LL;
byte_404198 &= 0xFEu;
v5 = getpid();
fd = func7((__int64)&dword_404170, v5, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( fd < 0 )
perror("Opening performance counter");
dword_4041E0 = 0;
qword_4041E8 = 4LL;
byte_404208 &= 0xFEu;
v6 = getpid();
v31 = func7((__int64)&dword_4041E0, v6, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( v31 < 0 )
perror("Opening performance counter");
dword_404250 = 0;
qword_404258 = 1LL;
byte_404278 &= 0xFEu;
v7 = getpid();
v32 = func7((__int64)&dword_404250, v7, 0xFFFFFFFF, 0xFFFFFFFF, 0LL);
if ( v32 < 0 )
perror("Opening performance counter");
if ( argc == 5 )
{
v34 = atof(argv[1]);
v35 = atof(argv[2]);
v36 = atof(argv[3]);
v37 = atof(argv[4]);
v8 = malloc(0x17D78400uLL);
v9 = malloc(0x17D78400uLL);
v10 = malloc(0x17D78400uLL);
v11 = malloc(0x17D78400uLL);
ptr = (unsigned int *)malloc(0x17D78400uLL);
v12 = time(0LL);
srand(v12);
func9(v50, v34);
func9(v49, v35);
func9(v48, v36);
func9(v47, v37);
func10(v8);
func10(v9);
func10(v10);
func10(v11);
puts("Loop start!");
fflush(stdout);
v38 = func8(0.0);
if ( !(unsigned int)read(v4, &buf, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Au, "main");
if ( !(unsigned int)read(fd, &v44, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Bu, "main");
if ( !(unsigned int)read(v31, &v45, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Cu, "main");
if ( !(unsigned int)read(v32, &v46, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Du, "main");
v13 = 0LL;
v14 = 0;
do
{
if ( v47[v11[v13]] && v48[v10[v13]] && v49[v9[v13]] && v50[v8[v13]] )
ptr[v14++] = v13;
++v13;
}
while ( v13 != 100000000 );
if ( !(unsigned int)read(v4, &v39, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Du, "main");
if ( !(unsigned int)read(fd, &v40, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Eu, "main");
if ( !(unsigned int)read(v31, &v41, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Fu, "main");
if ( !(unsigned int)read(v32, &v42, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0xA0u, "main");
close(v4);
close(fd);
close(v31);
close(v32);
v16 = func8(v38);
puts("Loop stop!");
printf("Elapsed time: %.9lf seconds\n", v16);
printf("CPU Cycles: %lu \n", v39 - buf);
printf("Instructions: %lu \n", v42 - v46);
if ( (v42 & 0x8000000000000000LL) != 0LL )
v17 = (double)(int)(v42 & 1 | (v42 >> 1)) + (double)(int)(v42 & 1 | (v42 >> 1));
else
v17 = (double)(int)v42;
if ( (v46 & 0x8000000000000000LL) != 0LL )
v18 = (double)(int)(v46 & 1 | (v46 >> 1)) + (double)(int)(v46 & 1 | (v46 >> 1));
else
v18 = (double)(int)v46;
v19 = v17 - v18;
v20 = v39 - buf;
if ( v39 - buf < 0 )
v21 = (double)(int)(v20 & 1 | (v20 >> 1)) + (double)(int)(v20 & 1 | (v20 >> 1));
else
v21 = (double)(int)v20;
printf("IPC: %lf\n", v19 / v21);
printf("Branch misses: %lu \n", v40 - v44);
printf("Branch instructions: %lu \n", v41 - v45);
if ( (v40 & 0x8000000000000000LL) != 0LL )
v22 = (double)(int)(v40 & 1 | (v40 >> 1)) + (double)(int)(v40 & 1 | (v40 >> 1));
else
v22 = (double)(int)v40;
if ( (v44 & 0x8000000000000000LL) != 0LL )
v23 = (double)(int)(v44 & 1 | (v44 >> 1)) + (double)(int)(v44 & 1 | (v44 >> 1));
else
v23 = (double)(int)v44;
v24 = (v22 - v23) * 100.0;
v25 = v41 - v45;
if ( v41 - v45 < 0 )
v26 = (double)(int)(v25 & 1 | (v25 >> 1)) + (double)(int)(v25 & 1 | (v25 >> 1));
else
v26 = (double)(int)v25;
printf("Branch mispred. rate: %lf%%\n", v24 / v26);
putchar(10);
printf("overall selectivity = %10.9f\n", (double)v14 / 100000000.0);
printf("theoretical selectivity = %10.9f\n", v34 * v35 * v36 * v37);
v27 = fopen("/dev/null", "w");
if ( v14 > 0 )
{
v28 = ptr;
v29 = (__int64)&ptr[v14 - 1 + 1];
do
fprintf(v27, "%d ", *v28++);
while ( v28 != (unsigned int *)v29 );
}
fclose(v27);
free(v8);
free(v9);
free(v10);
free(v11);
free(ptr);
result = 0;
}
else
{
puts("argument error!");
result = -1;
}
return result;
}

original_code:
int main(int argc, char * argv[])
{
  int num_runs = 0;
  int num_filters[1000] = {-99.0};
  float selectivities[1000][15];
  init_array(selectivities);
  struct sel_conf sc;
  if (argc != 3) {
    printf("usage: ./selconds <query_file> <config_file>\n");
    exit(1);
  }
  num_runs = parse_query_file(argv[1], num_filters, selectivities);
  parse_config_file(argv[2], &sc);
  int run_idx;
  printf("==========================================================================================\n");
  for (run_idx = 0; run_idx < num_runs; run_idx++) {
    compute_best_plan(num_filters[run_idx], &sc, selectivities[run_idx]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int num_runs = 0;
  int num_filters[1000] = {-99.0};
  float selectivities[1000][15];
  init_array(selectivities);
  struct sel_conf sc;
  if (argc != 3) {
    printf("usage: ./selconds <query_file> <config_file>\n");
    exit(1);
  }
  num_runs = parse_query_file(argv[1], num_filters, selectivities);
  parse_config_file(argv[2], &sc);
  int run_idx;
  printf("==========================================================================================\n");
  for (run_idx = 0; run_idx < num_runs; run_idx++) {
    compute_best_plan(num_filters[run_idx], &sc, selectivities[run_idx]);
  }
  return 0;
}

variable_types:
argv
char *[]

variable_types:
selectivities
float [1000][15]

variable_types: struct sel_conf { int r; int t; int l; int m; int a; int f; }


sigint

repo: dbittman/basil

decompiled_code:
void __noreturn sigint()
{
fprintf(stderr, "\n\ninterrupted (SIGINT): pc = %d\n", (unsigned int)counter);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
fprintf(stderr, "\n\ninterrupted (SIGINT): pc = %d\n", (unsigned int)counter);
exit(0);
}

original_code:
void sigint(int s)
{
 fprintf(stderr, "\n\ninterrupted (SIGINT): pc = %d\n", counter);
 exit(0);
}

variable_types: s int

return_type: void


decompiled_code:
void __noreturn op_und()
{
fprintf(stderr, "undefined opcode: pc = %d\n", (unsigned int)counter);
exit(2);
}

canonical_decompiled_code:
void __noreturn func8()
{
fprintf(stderr, "undefined opcode: pc = %d\n", (unsigned int)counter);
exit(2);
}

original_code:
void op_und(uint8_t p)
{
 fprintf(stderr, "undefined opcode: pc = %d\n", counter);
 exit(2);
}

canonical_original_code:
void op_und(unsigned char p)
{
 fprintf(stderr, "undefined opcode: pc = %d\n", counter);
 exit(2);
}

variable_types:
p
unsigned char


underflow

decompiled_code:
void __noreturn underflow()
{
fprintf(stderr, "underflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

canonical_decompiled_code:
void __noreturn func9()
{
fprintf(stderr, "underflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

original_code:
void underflow()
{
 fprintf(stderr, "underflow: pc = %d\n", counter);
 exit(2);
}


overflow

decompiled_code:
void __noreturn overflow()
{
fprintf(stderr, "overflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

canonical_decompiled_code:
void __noreturn func10()
{
fprintf(stderr, "overflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

original_code:
void overflow()
{
 fprintf(stderr, "overflow: pc = %d\n", counter);
 exit(2);
}


pop

decompiled_code:
__int64 pop()
{
__int64 v0; // rax

v0 = qword_404258;
if ( qword_404258 == stack )
underflow();
qword_404258 -= 4LL;
return *(unsigned int *)(v0 - 4);
}

original_code:
uint32_t pop()
{
 if(sp == stack) underflow();
 uint32_t x = *(--sp);
 return x;
}

canonical_original_code:
unsigned int pop()
{
 if(sp == stack) underflow();
 unsigned int x = *(--sp);
 return x;
}

variable_types:
x
unsigned int

return_type: unsigned int


decompiled_code:
__int64 op_pop()
{
return pop();
}

canonical_decompiled_code:
__int64 func12()
{
return func11();
}

original_code:
void op_pop(uint8_t p)
{
 pop();
}

canonical_original_code:
void op_pop(unsigned char p)
{
 pop();
}


decompiled_code:
int op_put()
{
int v0; // eax

v0 = pop();
return putc(v0, stdout);
}

canonical_decompiled_code:
int func13()
{
int v0; // eax

v0 = func11();
return putc(v0, stdout);
}

original_code:
void op_put(uint8_t p)
{
 int x = pop();
 putc(x, stdout);
}

canonical_original_code:
void op_put(unsigned char p)
{
 int x = pop();
 putc(x, stdout);
}

variable_types: x int


decompiled_code:
__int64 op_br()
{
int v0; // ebx
__int64 result; // rax

v0 = pop();
result = pop();
if ( v0 )
counter = result;
return result;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebx
__int64 result; // rax

v0 = func11();
result = func11();
if ( v0 )
counter = result;
return result;
}

original_code:
void op_br(uint8_t p)
{
 uint32_t test = pop();
 uint32_t x = pop();
 if(test)
  counter = x;
}

canonical_original_code:
void op_br(unsigned char p)
{
 unsigned int test = pop();
 unsigned int x = pop();
 if(test)
  counter = x;
}

variable_types:
test
unsigned int


decompiled_code:
_DWORD *op_ppc()
{
return push(counter);
}

canonical_decompiled_code:
_DWORD *func22()
{
return push(counter);
}

original_code:
void op_ppc(uint8_t p)
{
 push(counter);
}

canonical_original_code:
void op_ppc(unsigned char p)
{
 push(counter);
}


decompiled_code:
_DWORD *op_get()
{
int v0; // eax

v0 = getc(stdin);
if ( v0 == -1 )
{
fwrite("recieved EOF\n", 1uLL, 0xDuLL, stderr);
while ( 1 )
;
}
return push(v0);
}

canonical_decompiled_code:
_DWORD *func23()
{
int v0; // eax

v0 = getc(stdin);
if ( v0 == -1 )
{
fwrite("recieved EOF\n", 1uLL, 0xDuLL, stderr);
while ( 1 )
;
}
return push(v0);
}

original_code:
void op_get(uint8_t p)
{
 int in = getc(stdin);
 if(in != (-1)) {
  push((uint32_t)in);
 }
 else {
  fprintf(stderr, "recieved EOF\n");
  for(;;);
 }
}

canonical_original_code:
void op_get(unsigned char p)
{
 int in = getc(stdin);
 if(in != (-1)) {
  push((unsigned int)in);
 }
 else {
  fprintf(stderr, "recieved EOF\n");
  for(;;);
 }
}

variable_types: in int


peek

decompiled_code:
__int64 peek()
{
if ( qword_404258 == stack )
underflow();
return *(unsigned int *)(qword_404258 - 4);
}

canonical_decompiled_code:
__int64 func24()
{
if ( qword_404258 == stack )
func9();
return *(unsigned int *)(qword_404258 - 4);
}

original_code:
uint32_t peek()
{
 if(sp == stack) underflow();
 return *(sp-1);
}

canonical_original_code:
unsigned int peek()
{
 if(sp == stack) underflow();
 return *(sp-1);
}


execute

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

if ( waiting_for_push_operand_0 )
{
waiting_for_push_operand_0 = 0;
if ( verbose )
fprintf(stderr, "push %d\n", a1);
result = off_4040C8((unsigned __int8)a1);
}
else if ( a1 )
{
if ( verbose )
fprintf(stderr, "%s\n", (&optable)[2 * (int)a1]);
result = (*(&off_4040C8 + 2 * (int)a1))(0);
}
else
{
waiting_for_push_operand_0 = 1;
}
return result;
}

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

if ( waiting_for_push_operand_0 )
{
waiting_for_push_operand_0 = 0;
if ( verbose )
fprintf(stderr, "push %d\n", a1);
result = off_4040C8((unsigned __int8)a1);
}
else if ( a1 )
{
if ( verbose )
fprintf(stderr, "%s\n", (&optable)[2 * (int)a1]);
result = (*(&off_4040C8 + 2 * (int)a1))(0);
}
else
{
waiting_for_push_operand_0 = 1;
}
return result;
}

original_code:
void execute(int code)
{
 static int waiting_for_push_operand = 0;
 if(waiting_for_push_operand)
 {
  waiting_for_push_operand = 0;
  if(verbose)
   fprintf(stderr, "push %d\n", code);
  optable[0].fn(code);
 } else {
  if(!code)
   waiting_for_push_operand = 1;
  else {
   if(verbose)
    fprintf(stderr, "%s\n", optable[code].name);
   optable[code].fn(0);
  }
 }
}

variable_types: code int


decompiled_code:
__int64 op_swap()
{
int v0; // ebx
__int64 result; // rax
_DWORD *v2; // rsi
char v3; // al

v0 = pop();
result = peek();
if ( v0 )
{
v2 = (_DWORD *)(qword_404258 - 4LL * (unsigned int)(v0 + 1));
if ( (unsigned __int64)v2 < stack )
underflow(-4LL * (unsigned int)(v0 + 1));
*(_DWORD *)(qword_404258 - 4) = *v2;
*(_DWORD *)(qword_404258 - 4LL * (unsigned int)(v0 + 1)) = result;
}
else
{
v3 = pop();
result = execute(v3 & 0xF);
}
return result;
}

canonical_decompiled_code:
__int64 func27()
{
int v0; // ebx
__int64 result; // rax
_DWORD *v2; // rsi
char v3; // al

v0 = func11();
result = func24();
if ( v0 )
{
v2 = (_DWORD *)(qword_404258 - 4LL * (unsigned int)(v0 + 1));
if ( (unsigned __int64)v2 < stack )
func9(-4LL * (unsigned int)(v0 + 1));
*(_DWORD *)(qword_404258 - 4) = *v2;
*(_DWORD *)(qword_404258 - 4LL * (unsigned int)(v0 + 1)) = result;
}
else
{
v3 = func11();
result = func26(v3 & 0xF);
}
return result;
}

original_code:
void op_swap(uint8_t p)
{
 uint32_t param = pop();
 uint32_t elem = peek();
 if(param > 0) {
  if((sp - (param + 1)) < stack)
   underflow();
  *(sp-1) = *(sp - (param + 1));
  *(sp - (param + 1)) = elem;
 } else {
  elem = pop();
  execute(elem & 0xF);
 }
}

canonical_original_code:
void op_swap(unsigned char p)
{
 unsigned int param = pop();
 unsigned int elem = peek();
 if(param > 0) {
  if((sp - (param + 1)) < stack)
   underflow();
  *(sp-1) = *(sp - (param + 1));
  *(sp - (param + 1)) = elem;
 } else {
  elem = pop();
  execute(elem & 0xF);
 }
}

variable_types:
param
unsigned int

variable_types:
elem
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rbp
FILE *v5; // rbx
void *v6; // rax
_BYTE *v7; // rdx
int v8; // eax
unsigned __int8 *v9; // rax
unsigned __int8 v11; // bl
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

opterr = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "vVbh");
if ( v3 == -1 )
break;
if ( v3 == 98 )
{
little_endian = 0;
}
else if ( v3 == 118 )
{
verbose = 1;
}
else
{
if ( v3 != 86 )
usage();
very_verbose = 1;
}
}
v4 = (char *)argv[optind];
if ( !v4 )
usage();
if ( argc <= 1 )
exit(1);
setbuf(stdout, 0LL);
signal(2, (__sighandler_t)sigint);
v5 = fopen(v4, "r");
if ( !v5 )
exit(1);
if ( (unsigned int)stat(v4, &v12) == -1 )
{
perror("stat");
exit(3);
}
v6 = malloc(v12.st_size);
program = (__int64)v6;
if ( !v6 )
{
perror("malloc");
exit(3);
}
pc_8 = (__int64)v6;
stack = (__int64)malloc(0x1000uLL);
qword_404258 = stack;
if ( !stack )
{
perror("malloc");
exit(3);
}
while ( 1 )
{
v8 = fgetc(v5);
if ( v8 == -1 )
break;
v7 = (_BYTE *)pc_8++;
*v7 = v8;
}
max = pc_8;
fclose(v5);
v9 = (unsigned __int8 *)program;
pc_8 = program;
pc_4 = 0;
if ( program < (unsigned __int64)max )
{
do
{
if ( little_endian )
{
if ( pc_4 )
{
LABEL_33:
v11 = *v9 & 0xF;
goto LABEL_28;
}
}
else if ( !pc_4 )
{
goto LABEL_33;
}
v11 = *v9 >> 4;
LABEL_28:
if ( very_verbose )
printf("%d: %d %d: %x: %x\n", (unsigned int)counter, (unsigned int)pc_4, &v9[-program], v11 & 0xF, *v9);
++counter;
execute(v11);
v9 = (unsigned __int8 *)(program + counter / 2);
pc_8 = (__int64)v9;
pc_4 = counter % 2;
}
while ( (unsigned __int64)v9 < max );
}
fprintf(stderr, "executing code outside of program space: pc = %d\n", (unsigned int)counter);
return 2;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rbp
FILE *v5; // rbx
void *v6; // rax
_BYTE *v7; // rdx
int v8; // eax
unsigned __int8 *v9; // rax
unsigned __int8 v11; // bl
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

opterr = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "vVbh");
if ( v3 == -1 )
break;
if ( v3 == 98 )
{
little_endian = 0;
}
else if ( v3 == 118 )
{
verbose = 1;
}
else
{
if ( v3 != 86 )
func28();
very_verbose = 1;
}
}
v4 = (char *)argv[optind];
if ( !v4 )
func28();
if ( argc <= 1 )
exit(1);
setbuf(stdout, 0LL);
signal(2, (__sighandler_t)sigint);
v5 = fopen(v4, "r");
if ( !v5 )
exit(1);
if ( (unsigned int)func31(v4, &v12) == -1 )
{
perror("stat");
exit(3);
}
v6 = malloc(v12.st_size);
program = (__int64)v6;
if ( !v6 )
{
perror("malloc");
exit(3);
}
pc_8 = (__int64)v6;
stack = (__int64)malloc(0x1000uLL);
qword_404258 = stack;
if ( !stack )
{
perror("malloc");
exit(3);
}
while ( 1 )
{
v8 = fgetc(v5);
if ( v8 == -1 )
break;
v7 = (_BYTE *)pc_8++;
*v7 = v8;
}
max = pc_8;
fclose(v5);
v9 = (unsigned __int8 *)program;
pc_8 = program;
pc_4 = 0;
if ( program < (unsigned __int64)max )
{
do
{
if ( little_endian )
{
if ( pc_4 )
{
LABEL_33:
v11 = *v9 & 0xF;
goto LABEL_28;
}
}
else if ( !pc_4 )
{
goto LABEL_33;
}
v11 = *v9 >> 4;
LABEL_28:
if ( very_verbose )
printf("%d: %d %d: %x: %x\n", (unsigned int)counter, (unsigned int)pc_4, &v9[-program], v11 & 0xF, *v9);
++counter;
func26(v11);
v9 = (unsigned __int8 *)(program + counter / 2);
pc_8 = (__int64)v9;
pc_4 = counter % 2;
}
while ( (unsigned __int64)v9 < max );
}
fprintf(stderr, "executing code outside of program space: pc = %d\n", (unsigned int)counter);
return 2;
}

original_code:
int main(int argc, char **argv)
{
 opterr=0;
 int c;
 int keep=0;
 while((c = getopt(argc, argv, "khb")) != (-1)) {
  switch(c) {
   case 'k':
    keep=1;
    break;
   case 'b':
    byte_instructions = 1;
    break;
   case 'h':case '?':
   default:
    usage();
  }
 }
 char *infile = argv[optind];
 char *outfile = argv[optind+1];
 if(!infile || !outfile) usage();
 char out1[strlen(outfile) + 2];
 strcpy(out1, outfile);
 strcat(out1, ".1");
 char out2[strlen(outfile) + 2];
 strcpy(out2,outfile);
 strcat(out2, ".2");
 char out3[strlen(outfile) + 2];
 strcpy(out3, outfile);
 strcat(out3, ".3");
 char outs[strlen(outfile) + 4];
 strcpy(outs, outfile);
 strcat(outs, ".sym");
 if(pass1(infile, out1)) return 1;
 if(pass2(out1, out2, outs)) return 1;
 if(pass3(out2, out3)) return 1;
 if(pass4(out3, outfile, 1)) return 1;
 if(!keep) {
  unlink(out1);
  unlink(out2);
  unlink(out3);
  unlink(outs);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 opterr=0;
 int c;
 int keep = 0;
 while((c = getopt(argc, argv, "khb")) != (-1)) {
  switch(c) {
   case 'k':
    keep=1;
    break;
   case 'b':
    byte_instructions = 1;
    break;
   case 'h':case '?':
   default:
    usage();
  }
 }
 char *infile = argv[optind];
 char *outfile = argv[optind+1];
 if(!infile || !outfile) usage();
 char out1[-1];
 strcpy(out1, outfile);
 strcat(out1, ".1");
 char out2[-1];
 strcpy(out2,outfile);
 strcat(out2, ".2");
 char out3[-1];
 strcpy(out3, outfile);
 strcat(out3, ".3");
 char outs[-1];
 strcpy(outs, outfile);
 strcat(outs, ".sym");
 if(pass1(infile, out1)) return 1;
 if(pass2(out1, out2, outs)) return 1;
 if(pass3(out2, out3)) return 1;
 if(pass4(out3, outfile, 1)) return 1;
 if(!keep) {
  unlink(out1);
  unlink(out2);
  unlink(out3);
  unlink(outs);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: keep int

variable_types:
infile
char *

variable_types:
outfile
char *

variable_types:
outs
char [-1]

return_type: int


decompiled_code:
int __fastcall get_opcode(char *s1)
{
int result; // eax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx
int v9; // edx
int v10; // edx
int v11; // edx
int v12; // edx
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx

result = strcasecmp(s1, "push");
if ( result )
{
result = strcasecmp(s1, "psh");
if ( result )
{
v2 = strcasecmp(s1, "pop");
result = 8;
if ( v2 )
{
v3 = strcasecmp(s1, "dup");
result = 10;
if ( v3 )
{
v4 = strcasecmp(s1, "br");
result = 14;
if ( v4 )
{
v5 = strcasecmp(s1, "branch");
result = 14;
if ( v5 )
{
v6 = strcasecmp(s1, "and");
result = 1;
if ( v6 )
{
v7 = strcasecmp(s1, "add");
result = 6;
if ( v7 )
{
v8 = strcasecmp(s1, "cmp");
result = 7;
if ( v8 )
{
v9 = strcasecmp(s1, "swap");
result = 9;
if ( v9 )
{
v10 = strcasecmp(s1, "swp");
result = 9;
if ( v10 )
{
v11 = strcasecmp(s1, "not");
result = 2;
if ( v11 )
{
v12 = strcasecmp(s1, "or");
result = 3;
if ( v12 )
{
v13 = strcasecmp(s1, "ppc");
result = 11;
if ( v13 )
{
v14 = strcasecmp(s1, "mul");
result = 4;
if ( v14 )
{
v15 = strcasecmp(s1, "div");
result = 5;
if ( v15 )
{
v16 = strcasecmp(s1, "get");
result = 12;
if ( v16 )
result = strcasecmp(s1, "put") == 0 ? 13 : -1;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s1)
{
int result; // eax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx
int v9; // edx
int v10; // edx
int v11; // edx
int v12; // edx
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx

result = strcasecmp(s1, "push");
if ( result )
{
result = strcasecmp(s1, "psh");
if ( result )
{
v2 = strcasecmp(s1, "pop");
result = 8;
if ( v2 )
{
v3 = strcasecmp(s1, "dup");
result = 10;
if ( v3 )
{
v4 = strcasecmp(s1, "br");
result = 14;
if ( v4 )
{
v5 = strcasecmp(s1, "branch");
result = 14;
if ( v5 )
{
v6 = strcasecmp(s1, "and");
result = 1;
if ( v6 )
{
v7 = strcasecmp(s1, "add");
result = 6;
if ( v7 )
{
v8 = strcasecmp(s1, "cmp");
result = 7;
if ( v8 )
{
v9 = strcasecmp(s1, "swap");
result = 9;
if ( v9 )
{
v10 = strcasecmp(s1, "swp");
result = 9;
if ( v10 )
{
v11 = strcasecmp(s1, "not");
result = 2;
if ( v11 )
{
v12 = strcasecmp(s1, "or");
result = 3;
if ( v12 )
{
v13 = strcasecmp(s1, "ppc");
result = 11;
if ( v13 )
{
v14 = strcasecmp(s1, "mul");
result = 4;
if ( v14 )
{
v15 = strcasecmp(s1, "div");
result = 5;
if ( v15 )
{
v16 = strcasecmp(s1, "get");
result = 12;
if ( v16 )
result = strcasecmp(s1, "put") == 0 ? 13 : -1;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
int get_opcode(char *code)
{
 if(!strcasecmp(code, "push") || !strcasecmp(code, "psh")) {
  return 0;
 } else if(!strcasecmp(code, "pop")) {
  return 8;
 } else if(!strcasecmp(code, "dup")) {
  return 10;
 } else if(!strcasecmp(code, "br") || !strcasecmp(code, "branch")) {
  return 14;
 } else if(!strcasecmp(code, "and")) {
  return 1;
 } else if(!strcasecmp(code, "add")) {
  return 6;
 } else if(!strcasecmp(code, "cmp")) {
  return 7;
 } else if(!strcasecmp(code, "swap") || !strcasecmp(code, "swp")) {
  return 9;
 } else if(!strcasecmp(code, "not")) {
  return 2;
 } else if(!strcasecmp(code, "or")) {
  return 3;
 } else if(!strcasecmp(code, "ppc")) {
  return 11;
 } else if(!strcasecmp(code, "mul")) {
  return 4;
 } else if(!strcasecmp(code, "div")) {
  return 5;
 } else if(!strcasecmp(code, "get")) {
  return 12;
 } else if(!strcasecmp(code, "put")) {
  return 13;
 } else
  return -1;
}

variable_types:
code
char *


convert

decompiled_code:
__int64 __fastcall convert(const char *a1, unsigned int a2, char *a3)
{
int v4; // ebp
int v5; // eax
unsigned int v6; // er14
char *endptr; // [rsp+8h] [rbp-30h] BYREF

*_errno_location() = 0;
endptr = 0LL;
v4 = strtol(a3, &endptr, 0);
v5 = strlen(a3);
if ( endptr - a3 == v5 )
{
v6 = v4;
if ( v4 > 15 )
fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", a1, a2, (unsigned int)v4);
}
else
{
v6 = get_opcode(a3);
if ( v6 == -1 )
fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", a1, a2, a3);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2, char *a3)
{
int v4; // ebp
int v5; // eax
unsigned int v6; // er14
char *endptr; // [rsp+8h] [rbp-30h] BYREF

*_errno_location() = 0;
endptr = 0LL;
v4 = strtol(a3, &endptr, 0);
v5 = strlen(a3);
if ( endptr - a3 == v5 )
{
v6 = v4;
if ( v4 > 15 )
fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", a1, a2, (unsigned int)v4);
}
else
{
v6 = func0(a3);
if ( v6 == -1 )
fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", a1, a2, a3);
}
return v6;
}

original_code:
uint8_t convert(char *outname, int line, char *tok)
{
 (*__errno_location ())=0;
 char *end=0;
 int conv = strtol(tok, &end, 0);
 if((end - tok) != (int)strlen(tok)) {
  conv = get_opcode(tok);
  if(conv == -1)
   fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", outname, line, tok);
 } else {
  if(conv > 15)
   fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", outname, line, conv);
 }
 return (uint8_t)conv;
}

canonical_original_code:
unsigned char convert(char *outname, int line, char *tok)
{
 (*__errno_location ())=0;
 char *end = 0;
 int conv = strtol(tok, &end, 0);
 if((end - tok) != (int)strlen(tok)) {
  conv = get_opcode(tok);
  if(conv == -1)
   fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", outname, line, tok);
 } else {
  if(conv > 15)
   fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", outname, line, conv);
 }
 return (unsigned char)conv;
}

variable_types:
outname
char *

variable_types: line int

variable_types:
tok
char *

variable_types:
end
char *

variable_types: conv int

return_type: unsigned char


decompiled_code:
__int64 __fastcall get_label(char *s2)
{
char *v1; // rbx

v1 = syms;
if ( !syms )
return 0xFFFFFFFFLL;
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 17);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
char *v1; // rbx

v1 = syms;
if ( !syms )
return 0xFFFFFFFFLL;
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 17);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v1 + 32);
}

original_code:
int get_label(char *name)
{
 struct symbol *s = syms;
 while(s)
 {
  if(!strcmp(s->name, name))
   return s->pc;
  s=s->next;
 }
 return -1;
}

variable_types:
name
char *

variable_types: struct symbol { char name[128]; int pc; struct symbol *next; } *


decompiled_code:
__int64 __fastcall is_empty(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x2000) != 0 )
{
v1 = *++v2;
if ( !*v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x2000) != 0 )
{
v1 = *++v2;
if ( !*v2 )
return 1LL;
}
return 0LL;
}

original_code:
int is_empty(const char *s) {
  while (*s != '\0') {
    if (!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace))
      return 0;
    s++;
  }
  return 1;
}

canonical_original_code:
int is_empty(char *s) {
  while (*s != '\0') {
    if (!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace))
      return 0;
    s++;
  }
  return 1;
}

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
const char *v5; // r14
const char *v6; // r12
void *v7; // rsp
size_t v8; // rax
void *v9; // rsp
size_t v10; // rax
void *v11; // rsp
size_t v12; // rax
void *v13; // rsp
size_t v14; // rax
int v15; // edx
int result; // eax
char *v17; // r15
int v18; // edx
char *v19; // r14
int v20; // edx
int v21[2]; // [rsp+0h] [rbp-50h] BYREF
char *v22; // [rsp+8h] [rbp-48h]
char *v23; // [rsp+10h] [rbp-40h]
char *name; // [rsp+18h] [rbp-38h]

opterr = 0;
v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "khb");
if ( v4 == -1 )
break;
if ( v4 == 98 )
{
byte_instructions = 1;
}
else
{
v3 = 1;
if ( v4 != 107 )
usage();
}
}
v5 = argv[optind];
v6 = argv[optind + 1];
if ( !v5 || !v6 )
usage();
v7 = alloca(16 * ((strlen(argv[optind + 1]) + 17) / 0x10));
name = (char *)v21;
strcpy((char *)v21, v6);
v8 = strlen((const char *)v21);
*(_WORD *)((char *)v21 + v8) = 12590;
*((_BYTE *)v21 + v8 + 2) = 0;
v9 = alloca(16 * ((strlen(v6) + 17) / 0x10));
v23 = (char *)v21;
strcpy((char *)v21, v6);
v10 = strlen((const char *)v21);
*(_WORD *)((char *)v21 + v10) = 12846;
*((_BYTE *)v21 + v10 + 2) = 0;
v11 = alloca(16 * ((strlen(v6) + 17) / 0x10));
v22 = (char *)v21;
strcpy((char *)v21, v6);
v12 = strlen((const char *)v21);
*(_WORD *)((char *)v21 + v12) = 13102;
*((_BYTE *)v21 + v12 + 2) = 0;
v13 = alloca(16 * ((strlen(v6) + 19) / 0x10));
strcpy((char *)v21, v6);
v14 = strlen((const char *)v21);
*(int *)((char *)v21 + v14) = 1836675886;
*((_BYTE *)&v21[1] + v14) = 0;
v15 = pass1(v5, (const char *)v21);
result = 1;
if ( !v15 )
{
v17 = v23;
v18 = pass2(name, v23, (const char *)v21);
result = 1;
if ( !v18 )
{
v19 = v22;
v20 = pass3(v17, v22);
result = 1;
if ( !v20 )
{
result = pass4(v19, v6, 1);
if ( result )
{
result = 1;
}
else if ( !v3 )
{
unlink(name);
unlink(v23);
unlink(v22);
unlink((const char *)v21);
result = 0;
}
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
const char *v5; // r14
const char *v6; // r12
void *v7; // rsp
size_t v8; // rax
void *v9; // rsp
size_t v10; // rax
void *v11; // rsp
size_t v12; // rax
void *v13; // rsp
size_t v14; // rax
int v15; // edx
int result; // eax
char *v17; // r15
int v18; // edx
char *v19; // r14
int v20; // edx
int v21[2]; // [rsp+0h] [rbp-50h] BYREF
char *v22; // [rsp+8h] [rbp-48h]
char *v23; // [rsp+10h] [rbp-40h]
char *name; // [rsp+18h] [rbp-38h]

opterr = 0;
v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "khb");
if ( v4 == -1 )
break;
if ( v4 == 98 )
{
byte_instructions = 1;
}
else
{
v3 = 1;
if ( v4 != 107 )
func12();
}
}
v5 = argv[optind];
v6 = argv[optind + 1];
if ( !v5 || !v6 )
func12();
v7 = alloca(16 * ((strlen(argv[optind + 1]) + 17) / 0x10));
name = (char *)v21;
strcpy((char *)v21, v6);
v8 = strlen((const char *)v21);
*(_WORD *)((char *)v21 + v8) = 12590;
*((_BYTE *)v21 + v8 + 2) = 0;
v9 = alloca(16 * ((strlen(v6) + 17) / 0x10));
v23 = (char *)v21;
strcpy((char *)v21, v6);
v10 = strlen((const char *)v21);
*(_WORD *)((char *)v21 + v10) = 12846;
*((_BYTE *)v21 + v10 + 2) = 0;
v11 = alloca(16 * ((strlen(v6) + 17) / 0x10));
v22 = (char *)v21;
strcpy((char *)v21, v6);
v12 = strlen((const char *)v21);
*(_WORD *)((char *)v21 + v12) = 13102;
*((_BYTE *)v21 + v12 + 2) = 0;
v13 = alloca(16 * ((strlen(v6) + 19) / 0x10));
strcpy((char *)v21, v6);
v14 = strlen((const char *)v21);
*(int *)((char *)v21 + v14) = 1836675886;
*((_BYTE *)&v21[1] + v14) = 0;
v15 = func11(v5, (const char *)v21);
result = 1;
if ( !v15 )
{
v17 = v23;
v18 = func6(name, v23, (const char *)v21);
result = 1;
if ( !v18 )
{
v19 = v22;
v20 = func5(v17, v22);
result = 1;
if ( !v20 )
{
result = func2(v19, v6, 1);
if ( result )
{
result = 1;
}
else if ( !v3 )
{
unlink(name);
unlink(v23);
unlink(v22);
unlink((const char *)v21);
result = 0;
}
}
}
}
return result;
}


usage

decompiled_code:
void __noreturn usage()
{
fwrite("bas: usage: bas [-k] <source-file> <binary-file>\n", 1uLL, 0x31uLL, stderr);
fwrite("assembles an assembly language program directly into a binary file for BASIL\n", 1uLL, 0x4DuLL, stderr);
fwrite(" -k: keep intermediate files\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -b: make each instruction 8 bites long\n", 1uLL, 0x29uLL, stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
fwrite("bas: usage: bas [-k] <source-file> <binary-file>\n", 1uLL, 0x31uLL, stderr);
fwrite("assembles an assembly language program directly into a binary file for BASIL\n", 1uLL, 0x4DuLL, stderr);
fwrite(" -k: keep intermediate files\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -b: make each instruction 8 bites long\n", 1uLL, 0x29uLL, stderr);
exit(0);
}

original_code:
void usage()
{
 fprintf(stderr, "bas: usage: bas [-k] <source-file> <binary-file>\n");
 fprintf(stderr, "assembles an assembly language program directly into a binary file for BASIL\n");
 fprintf(stderr, "  -k: keep intermediate files\n");
 fprintf(stderr, "  -b: make each instruction 8 bites long\n");
 exit(0);
}


oneline

repo: dbondin/testdnsd

decompiled_code:
int oneline()
{
int v0; // er13
int v1; // er12
int v2; // ebp
int v3; // ebp
int v4; // ebx
int v5; // eax
int i; // ebx
int v7; // eax
int v8; // eax

v0 = rand() % 3 + 2;
v1 = 0;
while ( 1 )
{
v2 = rand() % 5;
if ( v2 >= -1 )
{
v3 = v2 + 2;
v4 = 0;
do
{
v5 = rand();
putchar(v5 % 26 + 97);
++v4;
}
while ( v4 != v3 );
}
if ( v0 < ++v1 )
break;
if ( v1 )
putchar(46);
}
putchar(32);
for ( i = 1; i == 1; ++i )
{
v8 = rand();
printf("%d", (unsigned int)(v8 % 255 + 1));
LABEL_10:
;
}
putchar(46);
v7 = rand();
printf("%d", (unsigned int)(v7 % 255 + 1));
if ( i <= 3 )
goto LABEL_10;
return putchar(10);
}

canonical_decompiled_code:
int func7()
{
int v0; // er13
int v1; // er12
int v2; // ebp
int v3; // ebp
int v4; // ebx
int v5; // eax
int i; // ebx
int v7; // eax
int v8; // eax

v0 = rand() % 3 + 2;
v1 = 0;
while ( 1 )
{
v2 = rand() % 5;
if ( v2 >= -1 )
{
v3 = v2 + 2;
v4 = 0;
do
{
v5 = rand();
putchar(v5 % 26 + 97);
++v4;
}
while ( v4 != v3 );
}
if ( v0 < ++v1 )
break;
if ( v1 )
putchar(46);
}
putchar(32);
for ( i = 1; i == 1; ++i )
{
v8 = rand();
printf("%d", (unsigned int)(v8 % 255 + 1));
LABEL_10:
;
}
putchar(46);
v7 = rand();
printf("%d", (unsigned int)(v7 % 255 + 1));
if ( i <= 3 )
goto LABEL_10;
return putchar(10);
}

original_code:
void oneline() {
    int i;
    int num = 2 + rand() % 3;
    int j;
    int size;
    for(i=0; i <= num; i++) {
 if(i != 0) {
     putchar('.');
 }
 size = 2 + rand() % 5;
 for(j=0; j<size; j++) {
     putchar('a' + rand() % ('z' - 'a' + 1));
 }
    }
    putchar(' ');
    for(i=0; i<4; i++) {
 if(i != 0) {
     putchar('.');
 }
 printf("%d", 1 + rand() % 255);
    }
    putchar('\n');
}

variable_types: i int

variable_types: num int

variable_types: j int

variable_types: size int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
int result; // eax

if ( argc <= 1 )
{
fwrite("Number of lines required\n", 1uLL, 0x19uLL, _bss_start);
result = 1;
}
else
{
v3 = time(0LL);
srand(v3);
v4 = atol(argv[1]);
v5 = 0LL;
if ( v4 <= 0 )
{
fwrite("Bad number of lines specified\n", 1uLL, 0x1EuLL, _bss_start);
result = 1;
}
else
{
do
{
oneline();
++v5;
}
while ( v4 != v5 );
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
int result; // eax

if ( argc <= 1 )
{
fwrite("Number of lines required\n", 1uLL, 0x19uLL, _bss_start);
result = 1;
}
else
{
v3 = time(0LL);
srand(v3);
v4 = atol(argv[1]);
v5 = 0LL;
if ( v4 <= 0 )
{
fwrite("Bad number of lines specified\n", 1uLL, 0x1EuLL, _bss_start);
result = 1;
}
else
{
do
{
func7();
++v5;
}
while ( v4 != v5 );
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char ** argv) {
    long i;
    long num;
    if(argc < 2) {
 fprintf(stderr, "Number of lines required\n");
 return 1;
    }
    srand(time(((void *)0)));
    num = atol(argv[1]);
    if(num <=0) {
 fprintf(stderr, "Bad number of lines specified\n");
 return 1;
    }
    for(i=0; i<num; i++) {
 oneline();
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    long i;
    long num;
    if(argc < 2) {
 fprintf(stderr, "Number of lines required\n");
 return 1;
    }
    srand(time(((void *)0)));
    num = atol(argv[1]);
    if(num <=0) {
 fprintf(stderr, "Bad number of lines specified\n");
 return 1;
    }
    for(i=0; i<num; i++) {
 oneline();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i long

variable_types: num long


original_code:
void prepare_response_found(data_queue_element * dqe, lookupdb_addr * ldb_addr) {
    int ancount = 0;
    int off = dqe->data_len;
    dns_header * ph = (dns_header *) dqe->data;
    struct in_addr * addr;
    ph->flags = htons(0x8100);
    while(ldb_addr != ((void *)0) &&
   off <= 512 - 12 - sizeof(struct in_addr)) {
 dqe->data[off++] = 0xc0;
 dqe->data[off++] = 0x0c;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x04;
 addr = (struct in_addr *) &(dqe->data[off]);
 *addr = ldb_addr->addr;
 off += sizeof(struct in_addr);
 ldb_addr = ldb_addr->next;
 ancount ++;
    }
    ph->ancount = htons(ancount);
    dqe->data_len = off;
}

canonical_original_code:
void prepare_response_found(struct _data_queue_element *dqe, struct _lookupdb_addr *ldb_addr) {
    int ancount = 0;
    int off = dqe->data_len;
    struct _dns_header *ph = (dns_header *) dqe->data;
    struct in_addr *addr;
    ph->flags = htons(0x8100);
    while(ldb_addr != ((void *)0) &&
   off <= 512 - 12 - sizeof(struct in_addr)) {
 dqe->data[off++] = 0xc0;
 dqe->data[off++] = 0x0c;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x04;
 addr = (struct in_addr *) &(dqe->data[off]);
 *addr = ldb_addr->addr;
 off += sizeof(struct in_addr);
 ldb_addr = ldb_addr->next;
 ancount ++;
    }
    ph->ancount = htons(ancount);
    dqe->data_len = off;
}

variable_types: struct _data_queue_element { 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]; } addr; char data[512]; int data_len; } *

variable_types: struct _lookupdb_addr { struct in_addr addr; struct _lookupdb_addr *next; } *

variable_types: ancount int

variable_types: off int

variable_types: struct _dns_header { unsigned short id; unsigned short flags; unsigned short qdcount; unsigned short ancount; unsigned short nscount; unsigned short arcount; } *

variable_types: struct in_addr { unsigned int s_addr; } *

user_defined_types: struct _data_queue_element { struct sockaddr_in addr; char data[512]; int data_len; }

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


decompiled_code:
__int16 __fastcall prepare_response_not_found(__int64 a1)
{
__int16 result; // ax

result = _bswap_16(33027);
*(_WORD *)(a1 + 18) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(__int64 a1)
{
__int16 result; // ax

result = func1(33027);
*(_WORD *)(a1 + 18) = result;
return result;
}

original_code:
static void prepare_response_not_found(data_queue_element * dqe) {
    dns_header * ph = (dns_header *) dqe->data;
    ph->flags = htons(0x8103);
}

canonical_original_code:
static void prepare_response_not_found(struct _data_queue_element *dqe) {
    struct _dns_header *ph = (dns_header *) dqe->data;
    ph->flags = htons(0x8103);
}

user_defined_types: struct _dns_header { unsigned short id; unsigned short flags; unsigned short qdcount; unsigned short ancount; unsigned short nscount; unsigned short arcount; }


decompiled_code:
void __fastcall __noreturn processor_thread_fn(unsigned int *a1)
{
__int16 v1; // bx
unsigned __int16 v2; // r15
unsigned __int16 v3; // bp
unsigned __int16 v4; // r14
unsigned __int16 v5; // r13
__int64 v6; // rbx
unsigned __int16 v7; // [rsp+Eh] [rbp-46Ah]
char v8[512]; // [rsp+10h] [rbp-468h] BYREF
char *v9; // [rsp+210h] [rbp-268h] BYREF
int v10; // [rsp+218h] [rbp-260h]
char v11[16]; // [rsp+220h] [rbp-258h] BYREF
__int16 v12[6]; // [rsp+230h] [rbp-248h] BYREF
char v13[500]; // [rsp+23Ch] [rbp-23Ch] BYREF
unsigned int v14; // [rsp+430h] [rbp-48h]

XXLOG("PRC[%d]: Started", *a1);
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&INQ, v11) )
XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", *a1);
if ( v14 > 0xB )
{
v7 = _bswap_16(v12[0]);
v1 = _bswap_16(v12[1]);
v2 = _bswap_16(v12[2]);
v3 = _bswap_16(v12[3]);
v4 = _bswap_16(v12[4]);
v5 = _bswap_16(v12[5]);
XXLOG_DEBUG(
"PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u",
*a1,
v7,
(unsigned __int16)v1,
v2,
v3,
v4,
v5);
XXLOG_DEBUG("PRC[%d]: %d %d %d", *a1, v1 & 0x8000, v1 & 0x7800, v1 & 0x200);
if ( v1 >= 0
&& !(v1 & 0x7A00 | (unsigned __int16)(v4 | v3 | v5))
&& v2 == 1
&& !(unsigned int)dns_question_load(v13, &v9) )
{
qname2str(v9, (__int64)v8);
XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x", *a1, v8, (unsigned __int16)v10, HIWORD(v10));
if ( v10 == 65537 )
{
v6 = lookupdb_search(&DB, v8);
if ( v6 )
{
XXLOG_DEBUG("PRC[%d]: FOUND", *a1);
prepare_response_found((__int64)v11, v6);
goto LABEL_7;
}
XXLOG_DEBUG("PRC[%d]: NOT FOUND", *a1);
}
}
}
prepare_response_not_found((__int64)v11);
LABEL_7:
XXLOG_DEBUG("PRC[%d]: Put the response in output queue", *a1);
if ( (unsigned int)data_queue_put_data(&OUTQ, v11, v12, v14) )
XXLOG("PRC[%d]: Error putting data to output queue", *a1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func4(unsigned int *a1)
{
__int16 v1; // bx
unsigned __int16 v2; // r15
unsigned __int16 v3; // bp
unsigned __int16 v4; // r14
unsigned __int16 v5; // r13
__int64 v6; // rbx
unsigned __int16 v7; // [rsp+Eh] [rbp-46Ah]
char v8[512]; // [rsp+10h] [rbp-468h] BYREF
char *v9; // [rsp+210h] [rbp-268h] BYREF
int v10; // [rsp+218h] [rbp-260h]
char v11[16]; // [rsp+220h] [rbp-258h] BYREF
__int16 v12[6]; // [rsp+230h] [rbp-248h] BYREF
char v13[500]; // [rsp+23Ch] [rbp-23Ch] BYREF
unsigned int v14; // [rsp+430h] [rbp-48h]

XXLOG("PRC[%d]: Started", *a1);
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&INQ, v11) )
XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", *a1);
if ( v14 > 0xB )
{
v7 = func1(v12[0]);
v1 = func1(v12[1]);
v2 = func1(v12[2]);
v3 = func1(v12[3]);
v4 = func1(v12[4]);
v5 = func1(v12[5]);
XXLOG_DEBUG(
"PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u",
*a1,
v7,
(unsigned __int16)v1,
v2,
v3,
v4,
v5);
XXLOG_DEBUG("PRC[%d]: %d %d %d", *a1, v1 & 0x8000, v1 & 0x7800, v1 & 0x200);
if ( v1 >= 0
&& !(v1 & 0x7A00 | (unsigned __int16)(v4 | v3 | v5))
&& v2 == 1
&& !(unsigned int)dns_question_load(v13, &v9) )
{
func0(v9, (__int64)v8);
XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x", *a1, v8, (unsigned __int16)v10, HIWORD(v10));
if ( v10 == 65537 )
{
v6 = lookupdb_search(&DB, v8);
if ( v6 )
{
XXLOG_DEBUG("PRC[%d]: FOUND", *a1);
func2((__int64)v11, v6);
goto LABEL_7;
}
XXLOG_DEBUG("PRC[%d]: NOT FOUND", *a1);
}
}
}
func3((__int64)v11);
LABEL_7:
XXLOG_DEBUG("PRC[%d]: Put the response in output queue", *a1);
if ( (unsigned int)data_queue_put_data(&OUTQ, v11, v12, v14) )
XXLOG("PRC[%d]: Error putting data to output queue", *a1);
}
}

original_code:
void * processor_thread_fn(void * args) {
    processor_thread_fn_arg_t * prc_arg = (processor_thread_fn_arg_t *) args;
    dns_header h;
    data_queue_element dqe;
    dns_question dnsq;
    char name[512];
    lookupdb_addr * ldb_addr;
    int found;
    XXLOG("PRC[%d]: Started", prc_arg->prc_id);
    while(1) {
 if(data_queue_get_data(&INQ, &dqe)) {
     XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", prc_arg->prc_id);
     continue;
 }
 found = 0;
 if(dqe.data_len >= sizeof(dns_header)) {
     h.id = ntohs(((dns_header *) dqe.data)->id);
     h.flags = ntohs(((dns_header *) dqe.data)->flags);
     h.qdcount = ntohs(((dns_header *) dqe.data)->qdcount);
     h.ancount = ntohs(((dns_header *) dqe.data)->ancount);
     h.nscount = ntohs(((dns_header *) dqe.data)->nscount);
     h.arcount = ntohs(((dns_header *) dqe.data)->arcount);
     XXLOG_DEBUG("PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u",
   prc_arg->prc_id,
   h.id,
   h.flags,
   h.qdcount,
   h.ancount,
   h.nscount,
   h.arcount);
     XXLOG_DEBUG("PRC[%d]: %d %d %d", prc_arg->prc_id, (h.flags & 0x8000), (h.flags & 0x7800), (h.flags & 0x0200));
     if((h.flags & 0x8000) == 0
        && (h.flags & 0x7800) == 0
        && (h.flags & 0x0200) == 0
        && h.qdcount == 1
        && h.ancount == 0
        && h.nscount == 0
        && h.arcount == 0
        )
     {
  if(!dns_question_load((void *)(dqe.data + sizeof(dns_header)), &dnsq)) {
      qname2str(dnsq.qname, name);
      XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x",
    prc_arg->prc_id,
    name,
    dnsq.qtype,
    dnsq.qclass);
      if(dnsq.qtype == 1
         && dnsq.qclass == 1 ) {
   ldb_addr = lookupdb_search(&DB, name);
   if(ldb_addr != ((void *)0)) {
       XXLOG_DEBUG("PRC[%d]: FOUND", prc_arg->prc_id);
       found = 1;
   }
   else {
       XXLOG_DEBUG("PRC[%d]: NOT FOUND", prc_arg->prc_id);
   }
      }
  }
     }
 }
 if(found) {
     prepare_response_found(&dqe, ldb_addr);
 }
 else {
     prepare_response_not_found(&dqe);
 }
 XXLOG_DEBUG("PRC[%d]: Put the response in output queue", prc_arg->prc_id);
 if(data_queue_put_data(&OUTQ, &(dqe.addr), (void *) dqe.data, dqe.data_len)) {
     XXLOG("PRC[%d]: Error putting data to output queue", prc_arg->prc_id);
 }
    }
    return ((void *)0);
}

canonical_original_code:
void *processor_thread_fn(void *args) {
    struct _processor_thread_fn_arg_t *prc_arg = (processor_thread_fn_arg_t *) args;
    struct _dns_header h;
    struct _data_queue_element dqe;
    struct _dns_question dnsq;
    char name[512];
    struct _lookupdb_addr *ldb_addr;
    int found;
    XXLOG("PRC[%d]: Started", prc_arg->prc_id);
    while(1) {
 if(data_queue_get_data(&INQ, &dqe)) {
     XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", prc_arg->prc_id);
     continue;
 }
 found = 0;
 if(dqe.data_len >= sizeof(dns_header)) {
     h.id = ntohs(((struct _dns_header *) dqe.data)->id);
     h.flags = ntohs(((struct _dns_header *) dqe.data)->flags);
     h.qdcount = ntohs(((struct _dns_header *) dqe.data)->qdcount);
     h.ancount = ntohs(((struct _dns_header *) dqe.data)->ancount);
     h.nscount = ntohs(((struct _dns_header *) dqe.data)->nscount);
     h.arcount = ntohs(((struct _dns_header *) dqe.data)->arcount);
     XXLOG_DEBUG("PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u",
   prc_arg->prc_id,
   h.id,
   h.flags,
   h.qdcount,
   h.ancount,
   h.nscount,
   h.arcount);
     XXLOG_DEBUG("PRC[%d]: %d %d %d", prc_arg->prc_id, (h.flags & 0x8000), (h.flags & 0x7800), (h.flags & 0x0200));
     if((h.flags & 0x8000) == 0
        && (h.flags & 0x7800) == 0
        && (h.flags & 0x0200) == 0
        && h.qdcount == 1
        && h.ancount == 0
        && h.nscount == 0
        && h.arcount == 0
        )
     {
  if(!dns_question_load((void *)(dqe.data + sizeof(dns_header)), &dnsq)) {
      qname2str(dnsq.qname, name);
      XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x",
    prc_arg->prc_id,
    name,
    dnsq.qtype,
    dnsq.qclass);
      if(dnsq.qtype == 1
         && dnsq.qclass == 1 ) {
   ldb_addr = lookupdb_search(&DB, name);
   if(ldb_addr != ((void *)0)) {
       XXLOG_DEBUG("PRC[%d]: FOUND", prc_arg->prc_id);
       found = 1;
   }
   else {
       XXLOG_DEBUG("PRC[%d]: NOT FOUND", prc_arg->prc_id);
   }
      }
  }
     }
 }
 if(found) {
     prepare_response_found(&dqe, ldb_addr);
 }
 else {
     prepare_response_not_found(&dqe);
 }
 XXLOG_DEBUG("PRC[%d]: Put the response in output queue", prc_arg->prc_id);
 if(data_queue_put_data(&OUTQ, &(dqe.addr), (void *) dqe.data, dqe.data_len)) {
     XXLOG("PRC[%d]: Error putting data to output queue", prc_arg->prc_id);
 }
    }
    return ((void *)0);
}

variable_types:
args
void *

variable_types: struct _processor_thread_fn_arg_t { int prc_id; } *

variable_types: struct _dns_header { unsigned short id; unsigned short flags; unsigned short qdcount; unsigned short ancount; unsigned short nscount; unsigned short arcount; }

variable_types: struct _data_queue_element { 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]; } addr; char data[512]; int data_len; }

variable_types: struct _dns_question { char *qname; unsigned short qtype; unsigned short qclass; }

variable_types:
name
char [512]

variable_types: struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *

variable_types: found int

return_type: void *

user_defined_types: struct _lookupdb_addr { struct in_addr addr; struct _lookupdb_addr *next; }


receiver

decompiled_code:
__int64 receiver()
{
ssize_t v0; // rax
__int64 v1; // rbx
int v2; // edi
char *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-41Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-418h] BYREF
char buf[1032]; // [rsp+20h] [rbp-408h] BYREF

XXLOG("Starting receiver");
do
{
while ( 1 )
{
XXLOG_DEBUG("Waiting for data");
v0 = recvfrom(SOCKET, buf, 0x400uLL, 0, &addr, &addr_len);
v1 = v0;
if ( v0 == -1 )
break;
XXLOG_DEBUG("Receiver receives %d bytes", v0);
if ( v1 > 0 )
{
XXLOG_DEBUG("Putting data to the queue");
if ( (unsigned int)data_queue_put_data(&INQ, &addr, buf, (unsigned int)v1) )
XXLOG("Receiver error: input queue operation failure");
else
XXLOG_DEBUG("Putting data to the queue success");
}
}
v2 = *_errno_location();
}
while ( v2 == 4 );
v3 = strerror(v2);
return XXLOG("Receiver failed (%s)", v3);
}

canonical_decompiled_code:
__int64 func0()
{
ssize_t v0; // rax
__int64 v1; // rbx
int v2; // edi
char *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-41Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-418h] BYREF
char buf[1032]; // [rsp+20h] [rbp-408h] BYREF

XXLOG("Starting receiver");
do
{
while ( 1 )
{
XXLOG_DEBUG("Waiting for data");
v0 = recvfrom(SOCKET, buf, 0x400uLL, 0, &addr, &addr_len);
v1 = v0;
if ( v0 == -1 )
break;
XXLOG_DEBUG("Receiver receives %d bytes", v0);
if ( v1 > 0 )
{
XXLOG_DEBUG("Putting data to the queue");
if ( (unsigned int)data_queue_put_data(&INQ, &addr, buf, (unsigned int)v1) )
XXLOG("Receiver error: input queue operation failure");
else
XXLOG_DEBUG("Putting data to the queue success");
}
}
v2 = *_errno_location();
}
while ( v2 == 4 );
v3 = strerror(v2);
return XXLOG("Receiver failed (%s)", v3);
}

original_code:
void receiver() {
    ssize_t bytes_read;
    char read_buffer[1024];
    struct sockaddr_in src_addr;
    socklen_t src_len;
    XXLOG("Starting receiver");
    while(1) {
 XXLOG_DEBUG("Waiting for data");
 bytes_read = recvfrom(SOCKET,
         (void *) read_buffer,
         1024,
         0,
         (struct sockaddr *) &src_addr,
         &src_len);
 if(bytes_read == -1) {
     if((*__errno_location ()) == 4) {
  continue;
     }
     else {
  XXLOG("Receiver failed (%s)", strerror((*__errno_location ())));
  return;
     }
 }
 XXLOG_DEBUG("Receiver receives %d bytes", bytes_read);
 if(bytes_read > 0) {
     XXLOG_DEBUG("Putting data to the queue");
     if(data_queue_put_data(&INQ, &src_addr, (void *) read_buffer, bytes_read)) {
  XXLOG("Receiver error: input queue operation failure");
     }
     else {
  XXLOG_DEBUG("Putting data to the queue success");
     }
 }
    }
    XXLOG("Receiver finished");
    return;
}

canonical_original_code:
void receiver() {
    long bytes_read;
    char read_buffer[1024];
    struct sockaddr_in src_addr;
    unsigned int src_len;
    XXLOG("Starting receiver");
    while(1) {
 XXLOG_DEBUG("Waiting for data");
 bytes_read = recvfrom(SOCKET,
         (void *) read_buffer,
         1024,
         0,
         (struct sockaddr *) &src_addr,
         &src_len);
 if(bytes_read == -1) {
     if((*__errno_location ()) == 4) {
  continue;
     }
     else {
  XXLOG("Receiver failed (%s)", strerror((*__errno_location ())));
  return;
     }
 }
 XXLOG_DEBUG("Receiver receives %d bytes", bytes_read);
 if(bytes_read > 0) {
     XXLOG_DEBUG("Putting data to the queue");
     if(data_queue_put_data(&INQ, &src_addr, (void *) read_buffer, bytes_read)) {
  XXLOG("Receiver error: input queue operation failure");
     }
     else {
  XXLOG_DEBUG("Putting data to the queue success");
     }
 }
    }
    XXLOG("Receiver finished");
    return;
}

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

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


decompiled_code:
void __noreturn sender_thread_fn()
{
int *v0; // rax
char *v1; // rax
struct sockaddr v2; // [rsp+0h] [rbp-228h] BYREF
char buf[512]; // [rsp+10h] [rbp-218h] BYREF
int v4; // [rsp+210h] [rbp-18h]

XXLOG("SND: Started");
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&OUTQ, &v2) )
;
if ( (unsigned int)sendto(SOCKET, buf, v4, 0, &v2, 0x10u) == -1 )
{
v0 = _errno_location();
v1 = strerror(*v0);
XXLOG("SND: error sending reply (%s)", v1);
}
else
{
XXLOG_DEBUG("SND: reply sent");
}
}
}

canonical_decompiled_code:
void __noreturn func0()
{
int *v0; // rax
char *v1; // rax
struct sockaddr v2; // [rsp+0h] [rbp-228h] BYREF
char buf[512]; // [rsp+10h] [rbp-218h] BYREF
int v4; // [rsp+210h] [rbp-18h]

XXLOG("SND: Started");
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&OUTQ, &v2) )
;
if ( (unsigned int)sendto(SOCKET, buf, v4, 0, &v2, 0x10u) == -1 )
{
v0 = _errno_location();
v1 = strerror(*v0);
XXLOG("SND: error sending reply (%s)", v1);
}
else
{
XXLOG_DEBUG("SND: reply sent");
}
}
}

original_code:
void * sender_thread_fn(void * args) {
    int status;
    data_queue_element dqe;
    XXLOG("SND: Started");
    while(1) {
 if(data_queue_get_data(&OUTQ, &dqe) == 0) {
     status = sendto(SOCKET,
       (void *) dqe.data,
       dqe.data_len,
       0,
       (struct sockaddr *) &(dqe.addr),
       sizeof(struct sockaddr));
     if(status != -1) {
  XXLOG_DEBUG("SND: reply sent");
     }
     else {
  XXLOG("SND: error sending reply (%s)", strerror((*__errno_location ())));
     }
 }
    }
    return ((void *)0);
}

canonical_original_code:
void *sender_thread_fn(void *args) {
    int status;
    struct _data_queue_element dqe;
    XXLOG("SND: Started");
    while(1) {
 if(data_queue_get_data(&OUTQ, &dqe) == 0) {
     status = sendto(SOCKET,
       (void *) dqe.data,
       dqe.data_len,
       0,
       (struct sockaddr *) &(dqe.addr),
       sizeof(struct sockaddr));
     if(status != -1) {
  XXLOG_DEBUG("SND: reply sent");
     }
     else {
  XXLOG("SND: error sending reply (%s)", strerror((*__errno_location ())));
     }
 }
    }
    return ((void *)0);
}

variable_types: status int


decompiled_code:
int __fastcall data_queue_init(__int64 a1, int a2)
{
int result; // eax
void *v3; // rax

if ( !a1 )
return 1;
result = 1;
if ( a2 > 0 )
{
v3 = malloc(532LL * a2);
*(_QWORD *)(a1 + 8) = v3;
if ( v3 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL) )
{
free(*(void **)(a1 + 8));
result = 3;
}
else
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
if ( result )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
free(*(void **)(a1 + 8));
result = 4;
}
else
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
}
}
}
else
{
result = 2;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
int result; // eax
void *v3; // rax

if ( !a1 )
return 1;
result = 1;
if ( a2 > 0 )
{
v3 = malloc(532LL * a2);
*(_QWORD *)(a1 + 8) = v3;
if ( v3 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL) )
{
free(*(void **)(a1 + 8));
result = 3;
}
else
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
if ( result )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
free(*(void **)(a1 + 8));
result = 4;
}
else
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
}
}
}
else
{
result = 2;
}
}
return result;
}

original_code:
int data_queue_init(data_queue * dq, int size) {
    if(dq == (void *) 0 || size <= 0) {
 return 1;
    }
    dq->data = (data_queue_element *) malloc(sizeof(data_queue_element) * size);
    if(dq->data == (void *) 0) {
 return 2;
    }
    if(pthread_mutex_init(&(dq->mutex), (void *) 0)) {
 free((void *)dq->data);
 return 3;
    }
    if(pthread_cond_init(&(dq->cond), (void *) 0)) {
 pthread_mutex_destroy(&(dq->mutex));
 free((void *)dq->data);
 return 4;
    }
    dq->size = size;
    dq->count = 0;
    return 0;
}

canonical_original_code:
int data_queue_init(struct _data_queue *dq, int size) {
    if(dq == (void *) 0 || size <= 0) {
 return 1;
    }
    dq->data = (struct _data_queue_element *) malloc(sizeof(data_queue_element) * size);
    if(dq->data == (void *) 0) {
 return 2;
    }
    if(pthread_mutex_init(&(dq->mutex), (void *) 0)) {
 free((void *)dq->data);
 return 3;
    }
    if(pthread_cond_init(&(dq->cond), (void *) 0)) {
 pthread_mutex_destroy(&(dq->mutex));
 free((void *)dq->data);
 return 4;
    }
    dq->size = size;
    dq->count = 0;
    return 0;
}

variable_types: struct _data_queue { int size; int count; struct _data_queue_element { 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]; } addr; char data[512]; int data_len; } *data; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; 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; } *

variable_types: size int

user_defined_types: struct _data_queue { int size; int count; struct _data_queue_element *data; union pthread_mutex_t mutex; union pthread_cond_t cond; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

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

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall data_queue_get_size(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
int data_queue_get_size(const data_queue * dq) {
    if(dq == (void *) 0) {
 return 0;
    }
    return dq->size;
}

canonical_original_code:
int data_queue_get_size(struct _data_queue *dq) {
    if(dq == (void *) 0) {
 return 0;
    }
    return dq->size;
}

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

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall data_queue_get_count(__int64 a1)
{
unsigned int v1; // ebx

if ( !a1 )
return (unsigned int)-1;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
return (unsigned int)-1;
v1 = *(_DWORD *)(a1 + 4);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // ebx

if ( !a1 )
return (unsigned int)-1;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
return (unsigned int)-1;
v1 = *(_DWORD *)(a1 + 4);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

original_code:
int data_queue_get_count(data_queue * dq) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     res = dq->count;
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

canonical_original_code:
int data_queue_get_count(struct _data_queue *dq) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     res = dq->count;
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

variable_types: res int


decompiled_code:
__int64 __fastcall data_queue_get_data(__int64 a1, _QWORD *a2)
{
pthread_mutex_t *v3; // r12
unsigned int v4; // ebp
int i; // eax
int v6; // eax
_QWORD *v7; // rsi

if ( !a1 )
return (unsigned int)-1;
v3 = (pthread_mutex_t *)(a1 + 16);
v4 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
if ( v4 )
return (unsigned int)-1;
for ( i = *(_DWORD *)(a1 + 4); !i; i = *(_DWORD *)(a1 + 4) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v3);
v6 = i - 1;
*(_DWORD *)(a1 + 4) = v6;
if ( a2 )
{
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 532LL * v6);
*a2 = *v7;
*(_QWORD *)((char *)a2 + 524) = *(_QWORD *)((char *)v7 + 524);
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v7 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 532) >> 3));
}
pthread_mutex_unlock(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
pthread_mutex_t *v3; // r12
unsigned int v4; // ebp
int i; // eax
int v6; // eax
_QWORD *v7; // rsi

if ( !a1 )
return (unsigned int)-1;
v3 = (pthread_mutex_t *)(a1 + 16);
v4 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
if ( v4 )
return (unsigned int)-1;
for ( i = *(_DWORD *)(a1 + 4); !i; i = *(_DWORD *)(a1 + 4) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v3);
v6 = i - 1;
*(_DWORD *)(a1 + 4) = v6;
if ( a2 )
{
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 532LL * v6);
*a2 = *v7;
*(_QWORD *)((char *)a2 + 524) = *(_QWORD *)((char *)v7 + 524);
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v7 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 532) >> 3));
}
pthread_mutex_unlock(v3);
return v4;
}

original_code:
int data_queue_get_data(data_queue * dq, data_queue_element * data) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     while(1) {
  if(dq->count == 0) {
      pthread_cond_wait(&(dq->cond), &(dq->mutex));
      continue;
  }
  dq->count --;
  if(data != (void *) 0) {
      memcpy((void *) data,
      (void *) &(dq->data[dq->count]),
      sizeof(data_queue_element));
  }
  res = 0;
  break;
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

canonical_original_code:
int data_queue_get_data(struct _data_queue *dq, struct _data_queue_element *data) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     while(1) {
  if(dq->count == 0) {
      pthread_cond_wait(&(dq->cond), &(dq->mutex));
      continue;
  }
  dq->count --;
  if(data != (void *) 0) {
      memcpy((void *) data,
      (void *) &(dq->data[dq->count]),
      sizeof(data_queue_element));
  }
  res = 0;
  break;
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

variable_types:
data
struct _data_queue_element *


original_code:
int data_queue_put_data(data_queue * dq, const struct sockaddr_in * addr, const void * data, int data_len) {
    int res = -1;
    if(dq != (void *) 0 &&
       data != (void *) 0 &&
       addr != (void *) 0 &&
       data_len > 0 &&
       data_len <= 512) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     if(dq->count < dq->size) {
  memcpy((void *) &(dq->data[dq->count].addr),
         (void *) addr,
         sizeof(addr));
  memcpy((void *) &(dq->data[dq->count].data),
         (void *) data,
         data_len);
  dq->data[dq->count].data_len = data_len;
  dq->count ++;
  res = 0;
  pthread_cond_signal(&(dq->cond));
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

canonical_original_code:
int data_queue_put_data(struct _data_queue *dq, struct sockaddr_in *addr, void *data, int data_len) {
    int res = -1;
    if(dq != (void *) 0 &&
       data != (void *) 0 &&
       addr != (void *) 0 &&
       data_len > 0 &&
       data_len <= 512) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     if(dq->count < dq->size) {
  memcpy((void *) &(dq->data[dq->count].addr),
         (void *) addr,
         sizeof(addr));
  memcpy((void *) &(dq->data[dq->count].data),
         (void *) data,
         data_len);
  dq->data[dq->count].data_len = data_len;
  dq->count ++;
  res = 0;
  pthread_cond_signal(&(dq->cond));
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

variable_types:
addr
struct sockaddr_in *

variable_types:
data
void *


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

result = malloc(0x408uLL);
if ( result )
{
result[128] = 0LL;
memset(result, 0, 0x400uLL);
}
return result;
}

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

result = malloc(0x408uLL);
if ( result )
{
result[128] = 0LL;
memset(result, 0, 0x400uLL);
}
return result;
}

original_code:
lookupdb_entry * new_lookupdb_entry() {
    lookupdb_entry * e = (lookupdb_entry *) malloc(sizeof(lookupdb_entry));
    if(e != ((void *)0)) {
 e->addr_list = ((void *)0);
        memset((void *) e->next, 0, sizeof(e->next));
    }
    return e;
}

canonical_original_code:
struct _lookupdb_entry *new_lookupdb_entry() {
    struct _lookupdb_entry *e = (lookupdb_entry *) malloc(sizeof(lookupdb_entry));
    if(e != ((void *)0)) {
 e->addr_list = ((void *)0);
        memset((void *) e->next, 0, sizeof(e->next));
    }
    return e;
}

variable_types: struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *addr_list; } *

user_defined_types: struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr *addr_list; }


decompiled_code:
__int64 __fastcall lookupdb_init(_QWORD *a1)
{
_QWORD *v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
*a1 = 0LL;
v1 = new_lookupdb_entry();
a1[1] = v1;
return (unsigned int)-(v1 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
*a1 = 0LL;
v1 = func0();
a1[1] = v1;
return (unsigned int)-(v1 == 0LL);
}

original_code:
int lookupdb_init(lookupdb * ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    ldb->size = 0;
    ldb->entry = new_lookupdb_entry();
    if(ldb->entry == ((void *)0)) {
 return -1;
    }
    return 0;
}

canonical_original_code:
int lookupdb_init(struct _lookupdb *ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    ldb->size = 0;
    ldb->entry = new_lookupdb_entry();
    if(ldb->entry == ((void *)0)) {
 return -1;
    }
    return 0;
}

variable_types: struct _lookupdb { unsigned long size; struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *addr_list; } *entry; } *

user_defined_types: struct _lookupdb { unsigned long size; struct _lookupdb_entry *entry; }


decompiled_code:
__int64 __fastcall lookupdb_size(__int64 *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = -1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = -1LL;
return result;
}

original_code:
long lookupdb_size(const lookupdb * ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    return ldb->size;
}

canonical_original_code:
long lookupdb_size(struct _lookupdb *ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    return ldb->size;
}

return_type: long


decompiled_code:
__int64 __fastcall lookupdb_search(__int64 a1, _BYTE *a2)
{
_BYTE *v2; // rbp
__int64 v3; // r12
char v4; // bl
const __int32_t *v5; // rdx

if ( !a1 )
return 0LL;
v2 = a2;
if ( !a2 )
return 0LL;
v3 = *(_QWORD *)(a1 + 8);
v4 = *a2;
if ( v3 && v4 )
{
v5 = *_ctype_tolower_loc();
do
{
v3 = *(_QWORD *)(v3 + 8LL * (v5[v4] & 0x7F));
v4 = *++v2;
}
while ( v3 && v4 );
}
if ( v3 )
v3 = *(_QWORD *)(v3 + 1024);
return v3;
}

original_code:
lookupdb_addr * lookupdb_search(const lookupdb * ldb, const char * name) {
    lookupdb_entry * ep;
    int idx;
    if(ldb != ((void *)0) && name != ((void *)0)) {
 ep = ldb->entry;
 for(;*name != 0; name ++) {
     if(ep != ((void *)0)) {
  idx = 0x7f & tolower(*name);
  ep = ep->next[idx];
     }
     else {
  break;
     }
 }
 if(ep != ((void *)0)) {
     return ep->addr_list;
 }
    }
    return ((void *)0);
}

canonical_original_code:
struct _lookupdb_addr *lookupdb_search(struct _lookupdb *ldb, char *name) {
    struct _lookupdb_entry *ep;
    int idx;
    if(ldb != ((void *)0) && name != ((void *)0)) {
 ep = ldb->entry;
 for(;*name != 0; name ++) {
     if(ep != ((void *)0)) {
  idx = 0x7f & tolower(*name);
  ep = ep->next[idx];
     }
     else {
  break;
     }
 }
 if(ep != ((void *)0)) {
     return ep->addr_list;
 }
    }
    return ((void *)0);
}

variable_types: struct _lookupdb { unsigned long size; struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr *addr_list; } *entry; } *

variable_types:
name
char *

variable_types: idx int

return_type: struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *


decompiled_code:
__int64 lookupdb_clear()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 0LL;
}

original_code:
int lookupdb_clear(lookupdb * ldb) {
    return 0;
}

canonical_original_code:
int lookupdb_clear(struct _lookupdb *ldb) {
    return 0;
}


decompiled_code:
__int64 __fastcall dns_question_load(const char *a1, __int64 a2)
{
__int64 v2; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = a1;
v2 = (int)strlen(a1);
*(_WORD *)(a2 + 8) = _bswap_16(*(_WORD *)&a1[v2 + 1]);
*(_WORD *)(a2 + 10) = _bswap_16(*(_WORD *)&a1[v2 + 3]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2)
{
__int64 v2; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = a1;
v2 = (int)strlen(a1);
*(_WORD *)(a2 + 8) = func0(*(_WORD *)&a1[v2 + 1]);
*(_WORD *)(a2 + 10) = func0(*(_WORD *)&a1[v2 + 3]);
return 0LL;
}

original_code:
int dns_question_load(const void * data, dns_question * dnsq) {
    int res = -1;
    if(data != ((void *)0) && dnsq != ((void *)0)) {
 int qname_len;
 dnsq->qname = (char *) data;
 qname_len = strlen(dnsq->qname);
 dnsq->qtype = ntohs(*(uint16_t *)(data + qname_len + 1));
 dnsq->qclass = ntohs(*(uint16_t *)(data + qname_len + 1 + sizeof(dnsq->qtype)));
 res = 0;
    }
    return res;
}

canonical_original_code:
int dns_question_load(void *data, struct _dns_question *dnsq) {
    int res = -1;
    if(data != ((void *)0) && dnsq != ((void *)0)) {
 int qname_len;
 dnsq->qname = (char *) data;
 qname_len = strlen(dnsq->qname);
 dnsq->qtype = ntohs(*(unsigned short *)(data + qname_len + 1));
 dnsq->qclass = ntohs(*(unsigned short *)(data + qname_len + 1 + sizeof(dnsq->qtype)));
 res = 0;
    }
    return res;
}

variable_types: struct _dns_question { char *qname; unsigned short qtype; unsigned short qclass; } *


decompiled_code:
void XXLOG_INIT()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void XXLOG_INIT() {
}

canonical_original_code:
void XXLOG_INIT() {
}


XXLOG

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

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

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

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

original_code:
void XXLOG(const char * format, ...) {
    va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}

canonical_original_code:
void XXLOG(char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}

variable_types:
format
char *


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

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

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

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

original_code:
void XXLOG_DEBUG(const char * format, ...) {
    va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}

canonical_original_code:
void XXLOG_DEBUG(char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}


GetLevelString

repo: dbuchwald/sextium

decompiled_code:
const char *__fastcall GetLevelString(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "OFF";
break;
case 1:
result = "ERROR";
break;
case 2:
result = "WARNING";
break;
case 3:
result = "INFO";
break;
case 4:
result = "DEBUG";
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "OFF";
break;
case 1:
result = "ERROR";
break;
case 2:
result = "WARNING";
break;
case 3:
result = "INFO";
break;
case 4:
result = "DEBUG";
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static const char* GetLevelString(const TRACE_ERRORLEVEL level)
{
  switch (level)
  {
    case TRACE_OFF:
      return __TRACE_LEVEL_OFF;
    case TRACE_ERROR:
      return __TRACE_LEVEL_ERROR;
    case TRACE_WARNING:
      return __TRACE_LEVEL_WARNING;
    case TRACE_INFO:
      return __TRACE_LEVEL_INFO;
    case TRACE_DEBUG:
      return __TRACE_LEVEL_DEBUG;
  }
  return ((void *)0);
}

canonical_original_code:
static char *GetLevelString(enum TRACE_ERRORLEVEL level)
{
  switch (level)
  {
    case TRACE_OFF:
      return __TRACE_LEVEL_OFF;
    case TRACE_ERROR:
      return __TRACE_LEVEL_ERROR;
    case TRACE_WARNING:
      return __TRACE_LEVEL_WARNING;
    case TRACE_INFO:
      return __TRACE_LEVEL_INFO;
    case TRACE_DEBUG:
      return __TRACE_LEVEL_DEBUG;
  }
  return ((void *)0);
}

variable_types: enum TRACE_ERRORLEVEL { TRACE_OFF=0, TRACE_ERROR=1, TRACE_WARNING=2, TRACE_INFO=3, TRACE_DEBUG=4 }

return_type: char *


PrintTraceLine

decompiled_code:
int PrintTraceLine(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
int result; // eax
struct tm *v9; // rax
const char *v10; // rax
time_t v11; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a5);
result = (int)arg[0].reg_save_area;
if ( !trace_initialized )
result = InitializeTrace();
if ( trace_level >= a4 )
{
time(&v11);
v9 = localtime(&v11);
strftime(timestamp_1, 0x200uLL, "%Y.%m.%d %H:%M:%S", v9);
v10 = GetLevelString(a4);
fprintf(trace_file, "[%s] %s ", timestamp_1, v10);
fprintf(trace_file, "<%s> (%s:%d) > ", a1, a2, a3);
vfprintf(trace_file, a5, arg);
fputc(10, trace_file);
result = fflush(trace_file);
}
return result;
}

canonical_decompiled_code:
int func8(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
int result; // eax
struct tm *v9; // rax
const char *v10; // rax
time_t v11; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a5);
result = (int)arg[0].reg_save_area;
if ( !trace_initialized )
result = func9();
if ( trace_level >= a4 )
{
time(&v11);
v9 = localtime(&v11);
strftime(timestamp_1, 0x200uLL, "%Y.%m.%d %H:%M:%S", v9);
v10 = func7(a4);
fprintf(trace_file, "[%s] %s ", timestamp_1, v10);
fprintf(trace_file, "<%s> (%s:%d) > ", a1, a2, a3);
vfprintf(trace_file, a5, arg);
fputc(10, trace_file);
result = fflush(trace_file);
}
return result;
}

original_code:
void PrintTraceLine(const char* function, const char* source_file, const int source_line, const TRACE_ERRORLEVEL level, const char* format, ...)
{
  va_list vl;
  __builtin_va_start(vl,format);
  static char timestamp[512];
  if (!_trace_initialized)
  {
    InitializeTrace();
  }
  if (level <= _trace_level)
  {
    time_t t;
    struct tm *tmp;
    time(&t);
    tmp = localtime(&t);
    strftime(timestamp, sizeof(timestamp), "%Y.%m.%d %H:%M:%S", tmp);
    fprintf(_trace_file, "[%s] %s ", timestamp, GetLevelString(level));
    fprintf(_trace_file, "<%s> (%s:%d) > ", function, source_file, source_line);
    vfprintf(_trace_file, format, vl);
    fprintf(_trace_file, "\n");
    fflush(_trace_file);
  }
}

canonical_original_code:
void PrintTraceLine(char *function, char *source_file, int source_line, enum TRACE_ERRORLEVEL level, char *format, ...)
{
  __builtin_va_list vl;
  __builtin_va_start(vl,format);
  static char timestamp[512];
  if (!_trace_initialized)
  {
    InitializeTrace();
  }
  if (level <= _trace_level)
  {
    long t;
    struct tm *tmp;
    time(&t);
    tmp = localtime(&t);
    strftime(timestamp, sizeof(timestamp), "%Y.%m.%d %H:%M:%S", tmp);
    fprintf(_trace_file, "[%s] %s ", timestamp, GetLevelString(level));
    fprintf(_trace_file, "<%s> (%s:%d) > ", function, source_file, source_line);
    vfprintf(_trace_file, format, vl);
    fprintf(_trace_file, "\n");
    fflush(_trace_file);
  }
}

variable_types:
function
char *

variable_types:
timestamp
char [512]

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

user_defined_types: enum TRACE_ERRORLEVEL { TRACE_OFF=0, TRACE_ERROR=1, TRACE_WARNING=2, TRACE_INFO=3, TRACE_DEBUG=4 }


InitializeTrace

decompiled_code:
int InitializeTrace()
{
char *v0; // rax
int v1; // ebx
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
const char *v7; // rax
int result; // eax
const char *v9; // rax
const char *v10; // rbx
char *v11; // rax

if ( getenv("TRACE_LEVEL") )
{
v0 = getenv("TRACE_LEVEL");
if ( !strcmp(v0, "OFF") )
{
trace_level = 0;
v1 = 2;
}
else
{
v3 = getenv("TRACE_LEVEL");
if ( !strcmp(v3, "ERROR") )
{
trace_level = 1;
v1 = 2;
}
else
{
v4 = getenv("TRACE_LEVEL");
if ( !strcmp(v4, "WARNING") )
{
trace_level = 2;
v1 = 2;
}
else
{
v5 = getenv("TRACE_LEVEL");
if ( !strcmp(v5, "INFO") )
{
trace_level = 3;
v1 = 2;
}
else
{
v6 = getenv("TRACE_LEVEL");
if ( !strcmp(v6, "DEBUG") )
{
trace_level = 4;
v1 = 2;
}
else
{
trace_level = 1;
v1 = 3;
}
}
}
}
}
}
else
{
trace_level = 1;
v1 = 1;
}
if ( getenv("TRACE_FILE") )
{
v2 = getenv("TRACE_FILE");
trace_file = fopen(v2, "a");
if ( !trace_file )
trace_file = stdout;
}
else
{
trace_file = stdout;
}
trace_initialized = 1;
if ( v1 == 2 )
{
v9 = GetLevelString(trace_level);
result = PrintTraceLine("InitializeTrace", "./src/trace.c", 0x71u, 3u, "Trace level: %s", v9);
}
else if ( v1 == 3 )
{
v10 = GetLevelString(1);
v11 = getenv("TRACE_LEVEL");
PrintTraceLine(
"InitializeTrace",
"./src/trace.c",
0x74u,
1u,
"Wrong trace level selected: %s, defaulting to %s",
v11,
v10);
result = PrintTraceLine(
"InitializeTrace",
"./src/trace.c",
0x7Eu,
1u,
"Unable to open trace file, outputting to standard output");
}
else
{
v7 = GetLevelString(1);
PrintTraceLine("InitializeTrace", "./src/trace.c", 0x6Eu, 1u, "No trace level selected, defaulting to %s", v7);
result = PrintTraceLine(
"InitializeTrace",
"./src/trace.c",
0x7Bu,
2u,
"No trace file specified, outputting to standard output");
}
return result;
}

canonical_decompiled_code:
int func9()
{
char *v0; // rax
int v1; // ebx
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
const char *v7; // rax
int result; // eax
const char *v9; // rax
const char *v10; // rbx
char *v11; // rax

if ( getenv("TRACE_LEVEL") )
{
v0 = getenv("TRACE_LEVEL");
if ( !strcmp(v0, "OFF") )
{
trace_level = 0;
v1 = 2;
}
else
{
v3 = getenv("TRACE_LEVEL");
if ( !strcmp(v3, "ERROR") )
{
trace_level = 1;
v1 = 2;
}
else
{
v4 = getenv("TRACE_LEVEL");
if ( !strcmp(v4, "WARNING") )
{
trace_level = 2;
v1 = 2;
}
else
{
v5 = getenv("TRACE_LEVEL");
if ( !strcmp(v5, "INFO") )
{
trace_level = 3;
v1 = 2;
}
else
{
v6 = getenv("TRACE_LEVEL");
if ( !strcmp(v6, "DEBUG") )
{
trace_level = 4;
v1 = 2;
}
else
{
trace_level = 1;
v1 = 3;
}
}
}
}
}
}
else
{
trace_level = 1;
v1 = 1;
}
if ( getenv("TRACE_FILE") )
{
v2 = getenv("TRACE_FILE");
trace_file = fopen(v2, "a");
if ( !trace_file )
trace_file = stdout;
}
else
{
trace_file = stdout;
}
trace_initialized = 1;
if ( v1 == 2 )
{
v9 = func7(trace_level);
result = func8("InitializeTrace", "./src/trace.c", 0x71u, 3u, "Trace level: %s", v9);
}
else if ( v1 == 3 )
{
v10 = func7(1);
v11 = getenv("TRACE_LEVEL");
func8(
"InitializeTrace",
"./src/trace.c",
0x74u,
1u,
"Wrong trace level selected: %s, defaulting to %s",
v11,
v10);
result = func8(
"InitializeTrace",
"./src/trace.c",
0x7Eu,
1u,
"Unable to open trace file, outputting to standard output");
}
else
{
v7 = func7(1);
func8("InitializeTrace", "./src/trace.c", 0x6Eu, 1u, "No trace level selected, defaulting to %s", v7);
result = func8(
"InitializeTrace",
"./src/trace.c",
0x7Bu,
2u,
"No trace file specified, outputting to standard output");
}
return result;
}

original_code:
static void InitializeTrace()
{
  int trace_level_defined;
  int trace_file_defined;
  if (!getenv("TRACE_LEVEL"))
  {
    _trace_level = TRACE_ERROR;
    trace_level_defined=1;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_OFF))
  {
    _trace_level = TRACE_OFF;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_ERROR))
  {
    _trace_level = TRACE_ERROR;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_WARNING))
  {
    _trace_level = TRACE_WARNING;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_INFO))
  {
    _trace_level = TRACE_INFO;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_DEBUG))
  {
    _trace_level = TRACE_DEBUG;
    trace_level_defined=2;
  }
  else
  {
    _trace_level = TRACE_ERROR;
    trace_level_defined=3;
  }
  if (!getenv("TRACE_FILE"))
  {
    _trace_file = stdout;
    trace_file_defined=1;
  }
  else if (!(_trace_file=fopen(getenv("TRACE_FILE"), "a")))
  {
    _trace_file = stdout;
    trace_file_defined=3;
  }
  else
  {
    trace_file_defined=2;
  }
  _trace_initialized=1;
  switch(trace_level_defined)
  {
    case 1:
      PrintTraceLine(__func__, "./src/trace.c", 110, TRACE_ERROR, "No trace level selected, defaulting to %s", GetLevelString(TRACE_ERROR));
      break;
    case 2:
      PrintTraceLine(__func__, "./src/trace.c", 113, TRACE_INFO, "Trace level: %s", GetLevelString(_trace_level));
      break;
    case 3:
      PrintTraceLine(__func__, "./src/trace.c", 116, TRACE_ERROR, "Wrong trace level selected: %s, defaulting to %s", getenv("TRACE_LEVEL"), GetLevelString(TRACE_ERROR));
      break;
  }
  switch(trace_level_defined)
  {
    case 1:
      PrintTraceLine(__func__, "./src/trace.c", 123, TRACE_WARNING, "No trace file specified, outputting to standard output");
      break;
    case 3:
      PrintTraceLine(__func__, "./src/trace.c", 126, TRACE_ERROR, "Unable to open trace file, outputting to standard output");
      break;
  }
}


yywrap

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

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

original_code:
int yywrap()
{
  return 1;
}

canonical_original_code:
int yywrap()
{
  return 1;
}