repo: lucioseki/MC

decompiled_code:
int __fastcall show_header(__int64 a1)
{
printf("ChunkID: %.4s\n", (const char *)a1);
printf("ChunkSize: %ld\n", *(_QWORD *)(a1 + 8));
printf("Format: %.4s\n", (const char *)(a1 + 16));
printf("Subchunk1ID: %.4s\n", (const char *)(a1 + 24));
printf("Subchunk1Size: %ld\n", *(_QWORD *)(a1 + 32));
printf("AudioFormat: %hu\n", *(unsigned __int16 *)(a1 + 40));
printf("NumChannels: %hu\n", *(unsigned __int16 *)(a1 + 42));
printf("SampleRate: %ld\n", *(_QWORD *)(a1 + 48));
printf("ByteRate: %ld\n", *(_QWORD *)(a1 + 56));
printf("BlockAlign: %hu\n", *(unsigned __int16 *)(a1 + 64));
printf("BitsPerSample: %hu\n", *(unsigned __int16 *)(a1 + 66));
printf("Subchunk2ID: %.4s\n", (const char *)(a1 + 72));
return printf("Subchunk2Size: %ld\n\n", *(_QWORD *)(a1 + 80));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
printf("ChunkID: %.4s\n", (const char *)a1);
printf("ChunkSize: %ld\n", *(_QWORD *)(a1 + 8));
printf("Format: %.4s\n", (const char *)(a1 + 16));
printf("Subchunk1ID: %.4s\n", (const char *)(a1 + 24));
printf("Subchunk1Size: %ld\n", *(_QWORD *)(a1 + 32));
printf("AudioFormat: %hu\n", *(unsigned __int16 *)(a1 + 40));
printf("NumChannels: %hu\n", *(unsigned __int16 *)(a1 + 42));
printf("SampleRate: %ld\n", *(_QWORD *)(a1 + 48));
printf("ByteRate: %ld\n", *(_QWORD *)(a1 + 56));
printf("BlockAlign: %hu\n", *(unsigned __int16 *)(a1 + 64));
printf("BitsPerSample: %hu\n", *(unsigned __int16 *)(a1 + 66));
printf("Subchunk2ID: %.4s\n", (const char *)(a1 + 72));
return printf("Subchunk2Size: %ld\n\n", *(_QWORD *)(a1 + 80));
}

original_code:
void show_header(HeaderType *header){
 printf("ChunkID: %.4s\n", &(header->ChunkID));
 printf("ChunkSize: %ld\n", header->ChunkSize);
 printf("Format: %.4s\n", &(header->Format));
 printf("Subchunk1ID: %.4s\n", &(header->Subchunk1ID));
 printf("Subchunk1Size: %ld\n", header->Subchunk1Size);
 printf("AudioFormat: %hu\n", header->AudioFormat);
 printf("NumChannels: %hu\n", header->NumChannels);
 printf("SampleRate: %ld\n", header->SampleRate);
 printf("ByteRate: %ld\n", header->ByteRate);
 printf("BlockAlign: %hu\n", header->BlockAlign);
 printf("BitsPerSample: %hu\n", header->BitsPerSample);
 printf("Subchunk2ID: %.4s\n", &(header->Subchunk2ID));
 printf("Subchunk2Size: %ld\n\n", header->Subchunk2Size);
}

canonical_original_code:
void show_header(struct HeaderType *header){
 printf("ChunkID: %.4s\n", &(header->ChunkID));
 printf("ChunkSize: %ld\n", header->ChunkSize);
 printf("Format: %.4s\n", &(header->Format));
 printf("Subchunk1ID: %.4s\n", &(header->Subchunk1ID));
 printf("Subchunk1Size: %ld\n", header->Subchunk1Size);
 printf("AudioFormat: %hu\n", header->AudioFormat);
 printf("NumChannels: %hu\n", header->NumChannels);
 printf("SampleRate: %ld\n", header->SampleRate);
 printf("ByteRate: %ld\n", header->ByteRate);
 printf("BlockAlign: %hu\n", header->BlockAlign);
 printf("BitsPerSample: %hu\n", header->BitsPerSample);
 printf("Subchunk2ID: %.4s\n", &(header->Subchunk2ID));
 printf("Subchunk2Size: %ld\n\n", header->Subchunk2Size);
}

variable_types: struct HeaderType { long ChunkID; long ChunkSize; long Format; long Subchunk1ID; long Subchunk1Size; unsigned short AudioFormat; unsigned short NumChannels; long SampleRate; long ByteRate; unsigned short BlockAlign; unsigned short BitsPerSample; long Subchunk2ID; long Subchunk2Size; } *


smoothSerialYX

decompiled_code:
void __fastcall smoothSerialYX(int a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned int i; // ebp
__int64 j; // rbx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
for ( j = 0LL; j != a1; ++j )
*(float *)(a4 + 4 * j) = evaluate((unsigned int)a1, a2, (unsigned int)j, i, a3);
a4 += 4LL * a1;
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned int i; // ebp
__int64 j; // rbx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
for ( j = 0LL; j != a1; ++j )
*(float *)(a4 + 4 * j) = evaluate((unsigned int)a1, a2, (unsigned int)j, i, a3);
a4 += 4LL * a1;
}
}
}

original_code:
void smoothSerialYX ( int dim, int halfwidth, float * m1, float * m2 )
{
  int x,y;
  for (y=0; y<dim; y++)
  {
    for (x=0; x<dim; x++)
    {
      m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
    }
  }
}

canonical_original_code:
void smoothSerialYX(int dim, int halfwidth, float *m1, float *m2)
{
  int x; int y;
  for (y=0; y<dim; y++)
  {
    for (x=0; x<dim; x++)
    {
      m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
    }
  }
}

variable_types: dim int

variable_types: halfwidth int

variable_types: x int

variable_types: y int

return_type: void


smoothSerialXY

decompiled_code:
__int64 __fastcall smoothSerialXY(int a1, unsigned int a2, __int64 a3, __int64 a4)
{
float *v5; // rbp
unsigned int j; // ebx
__int64 result; // rax
__int64 i; // [rsp+8h] [rbp-50h]

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; result = ++i )
{
v5 = (float *)(a4 + 4 * i);
for ( j = 0; j != a1; ++j )
{
*v5 = evaluate((unsigned int)a1, a2, (unsigned int)i, j, a3);
v5 += a1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, unsigned int a2, __int64 a3, __int64 a4)
{
float *v5; // rbp
unsigned int j; // ebx
__int64 result; // rax
__int64 i; // [rsp+8h] [rbp-50h]

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; result = ++i )
{
v5 = (float *)(a4 + 4 * i);
for ( j = 0; j != a1; ++j )
{
*v5 = evaluate((unsigned int)a1, a2, (unsigned int)i, j, a3);
v5 += a1;
}
}
}
return result;
}

original_code:
void smoothSerialXY ( int dim, int halfwidth, float * m1, float * m2 )
{
  int x,y;
  for (x=0; x<dim; x++)
  {
    for (y=0; y<dim; y++)
    {
      m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
    }
  }
}

canonical_original_code:
void smoothSerialXY(int dim, int halfwidth, float *m1, float *m2)
{
  int x; int y;
  for (x=0; x<dim; x++)
  {
    for (y=0; y<dim; y++)
    {
      m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
    }
  }
}


smoothParallelYXFor

decompiled_code:
__int64 __fastcall smoothParallelYXFor(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]
int v7; // [rsp+14h] [rbp-14h]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(smoothParallelYXFor__omp_fn_0, v5, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]
int v7; // [rsp+14h] [rbp-14h]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(smoothParallelYXFor__omp_fn_0, v5, 0LL, 0LL);
}

original_code:
void smoothParallelYXFor ( int dim, int halfwidth, float * m1, float * m2 )
{
 int x,y;

#pragma omp parallel for private (x,y)
 for (y=0; y<dim; y++)
 {
  for (x=0; x<dim; x++)
  {
   m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
  }
 }
}

canonical_original_code:
void smoothParallelYXFor(int dim, int halfwidth, float *m1, float *m2)
{
 int x; int y;

#pragma omp parallel for private (x,y)
 for (y=0; y<dim; y++)
 {
  for (x=0; x<dim; x++)
  {
   m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
  }
 }
}


smoothParallelXYFor

decompiled_code:
__int64 __fastcall smoothParallelXYFor(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]
int v7; // [rsp+14h] [rbp-14h]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(smoothParallelXYFor__omp_fn_0, v5, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]
int v7; // [rsp+14h] [rbp-14h]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(smoothParallelXYFor__omp_fn_0, v5, 0LL, 0LL);
}

original_code:
void smoothParallelXYFor ( int dim, int halfwidth, float * m1, float * m2 )
{
 int x,y;

#pragma omp parallel for private (x,y)
 for (x=0; x<dim; x++)
 {
  for (y=0; y<dim; y++)
  {
   m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
  }
 }
}

canonical_original_code:
void smoothParallelXYFor(int dim, int halfwidth, float *m1, float *m2)
{
 int x; int y;

#pragma omp parallel for private (x,y)
 for (x=0; x<dim; x++)
 {
  for (y=0; y<dim; y++)
  {
   m2[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1 );
  }
 }
}


smoothParallelCoalescedFor

decompiled_code:
__int64 __fastcall smoothParallelCoalescedFor(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]
int v7; // [rsp+14h] [rbp-14h]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(smoothParallelCoalescedFor__omp_fn_0, v5, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]
int v7; // [rsp+14h] [rbp-14h]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(smoothParallelCoalescedFor__omp_fn_0, v5, 0LL, 0LL);
}

original_code:
void smoothParallelCoalescedFor ( int dim, int halfwidth, float * m1, float * m2 )
{
 int i;

#pragma omp parallel for private (i)
 for (i=0; i<dim*dim; i++){
  m2[i] = evaluate (dim, halfwidth, i%dim, i/dim, m1);
 }
}

canonical_original_code:
void smoothParallelCoalescedFor(int dim, int halfwidth, float *m1, float *m2)
{
 int i;

#pragma omp parallel for private (i)
 for (i=0; i<dim*dim; i++){
  m2[i] = evaluate (dim, halfwidth, i%dim, i/dim, m1);
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall smoothParallelYXFor2(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v7[4]; // [rsp+0h] [rbp-38h] BYREF
int v8; // [rsp+20h] [rbp-18h]
int v9; // [rsp+24h] [rbp-14h]

v7[3] = a6;
v7[2] = a5;
v7[1] = a4;
v7[0] = a3;
v9 = a2;
v8 = a1;
return GOMP_parallel(smoothParallelYXFor2__omp_fn_0, v7, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v7[4]; // [rsp+0h] [rbp-38h] BYREF
int v8; // [rsp+20h] [rbp-18h]
int v9; // [rsp+24h] [rbp-14h]

v7[3] = a6;
v7[2] = a5;
v7[1] = a4;
v7[0] = a3;
v9 = a2;
v8 = a1;
return GOMP_parallel(smoothParallelYXFor2__omp_fn_0, v7, 0LL, 0LL);
}

original_code:
void smoothParallelYXFor2 ( int dim, int halfwidth, float * m1in,float * m2in, float * m3out, float *m4out )
{
 int x,y;

#pragma omp parallel for private (x,y)
 for (y=0; y<dim; y++)
 {
  for (x=0; x<dim; x++)
  {
   m3out[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1in );
   m4out[y*dim+x] = evaluate ( dim, halfwidth, x, y, m2in );
  }
 }
}

canonical_original_code:
void smoothParallelYXFor2(int dim, int halfwidth, float *m1in, float *m2in, float *m3out, float *m4out)
{
 int x; int y;

#pragma omp parallel for private (x,y)
 for (y=0; y<dim; y++)
 {
  for (x=0; x<dim; x++)
  {
   m3out[y*dim+x] = evaluate ( dim, halfwidth, x, y, m1in );
   m4out[y*dim+x] = evaluate ( dim, halfwidth, x, y, m2in );
  }
 }
}


decompiled_code:
int create_dialogue_box()
{
dialogue_win = newwin(10, 80, 0, 45);
wborder(dialogue_win, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
dialogue_pan = (__int64)new_panel(dialogue_win);
keypad(stdscr, 0);
keypad(dialogue_win, 1);
update_panels();
return doupdate();
}

canonical_decompiled_code:
int func0()
{
dialogue_win = newwin(10, 80, 0, 45);
wborder(dialogue_win, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
dialogue_pan = (__int64)new_panel(dialogue_win);
keypad(stdscr, 0);
keypad(dialogue_win, 1);
update_panels();
return doupdate();
}

original_code:
void create_dialogue_box() {
    int lines = 10,
        cols = 80,
        y = 0,
        x = 45;
    dialogue_win = newwin(lines, cols, y, x);
    wborder(dialogue_win, 0, 0, 0, 0, 0, 0, 0, 0);
    dialogue_pan = new_panel(dialogue_win);
    keypad(stdscr, 0);
    keypad(dialogue_win, 1);
    update_panels();
    doupdate();
}

canonical_original_code:
void create_dialogue_box() {
    int lines = 10; int cols = 80; int y = 0; int x = 45;
    dialogue_win = newwin(lines, cols, y, x);
    wborder(dialogue_win, 0, 0, 0, 0, 0, 0, 0, 0);
    dialogue_pan = new_panel(dialogue_win);
    keypad(stdscr, 0);
    keypad(dialogue_win, 1);
    update_panels();
    doupdate();
}

variable_types: lines int

variable_types: cols int


decompiled_code:
__int64 __fastcall check_nbd(int a1, int a2, int a3, int a4)
{
int v6; // edx
int v7; // er9
int i; // eax

v6 = -1;
v7 = a2 - 1;
while ( 2 )
{
for ( i = 0; ; ++i )
{
if ( v6 | (i - 1) )
{
if ( a3 == a1 + v6 && a4 == v7 + i )
return 1LL;
if ( i > 1 )
break;
}
}
if ( ++v6 != 2 )
continue;
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3, int a4)
{
int v6; // edx
int v7; // er9
int i; // eax

v6 = -1;
v7 = a2 - 1;
while ( 2 )
{
for ( i = 0; ; ++i )
{
if ( v6 | (i - 1) )
{
if ( a3 == a1 + v6 && a4 == v7 + i )
return 1LL;
if ( i > 1 )
break;
}
}
if ( ++v6 != 2 )
continue;
break;
}
return 0LL;
}

canonical_original_code:
int check_nbd(int x1, int y1, int x2, int y2) {
    int i; int j;
    for(i = -1; i < 2; i++) {
        for(j = -1; j < 2; j++) {
            if((i || j) && (x2 == x1 + i && y2 == y1 + j)) {
                return 1;
            }
        }
    }
    return 0;
}

variable_types: j int

return_type: int


repo: luikore/ccut

decompiled_code:
void __fastcall __noreturn print_trace_handler(unsigned int a1)
{
int v1; // ebx
void *v2[23]; // [rsp+0h] [rbp-B8h] BYREF

v1 = backtrace(v2, 20);
fprintf(stderr, "Error: signal %d:\n", a1);
backtrace_symbols_fd(v2, v1, 2);
Exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
int v1; // ebx
void *v2[23]; // [rsp+0h] [rbp-B8h] BYREF

v1 = backtrace(v2, 20);
fprintf(stderr, "Error: signal %d:\n", a1);
backtrace_symbols_fd(v2, v1, 2);
Exit(1);
}

original_code:
static void print_trace_handler(int sig) {
  void *array[20];
  size_t size;
  size = backtrace(array, 20);
  fprintf(stderr, "Error: signal %d:\n", sig);
  backtrace_symbols_fd(array, size, 2);
  _Exit(1);
}

canonical_original_code:
static void print_trace_handler(int sig) {
  void *array[20];
  unsigned long size;
  size = backtrace(array, 20);
  fprintf(stderr, "Error: signal %d:\n", sig);
  backtrace_symbols_fd(array, size, 2);
  _Exit(1);
}

variable_types: sig int

variable_types:
array
void *[20]

variable_types:
size
unsigned long


decompiled_code:
int __fastcall fail_before(unsigned int a1)
{
int result; // eax

result = printf("\x1B[38;5;1m%d: ", a1);
++dword_5E0;
dword_5D8 = 2;
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
int result; // eax

result = printf("\x1B[38;5;1m%d: ", a1);
++dword_5E0;
dword_5D8 = 2;
return result;
}

original_code:
static void fail_before(int line) {
  printf("\e[38;5;1m%d: ", line);
  ctx.failure_size++;
  ctx.current_state = 2;
}

variable_types: line int


decompiled_code:
int fail_after()
{
return printf("\x1B[38;5;7m ");
}

canonical_decompiled_code:
int func2()
{
return printf("\x1B[38;5;7m ");
}

original_code:
static void fail_after() {
  printf("\e[38;5;7m ");
}


decompiled_code:
int inc_assertion_size()
{
int result; // eax

printf("\x1B[38;5;2m.\x1B[38;5;7m");
result = fflush(stdout);
++dword_5E8;
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

printf("\x1B[38;5;2m.\x1B[38;5;7m");
result = fflush(stdout);
++dword_5E8;
return result;
}

original_code:
static void inc_assertion_size() {
  printf("\e[38;5;2m.\e[38;5;7m");
  fflush(stdout);
  ctx.assertion_size++;
}


decompiled_code:
__int64 __fastcall test_runned(char *s2)
{
const char **v1; // rbx
const char **v2; // r12

if ( dword_5C4 <= 0 )
return 0LL;
v1 = (const char **)ptr;
v2 = (const char **)((char *)ptr + 8 * (unsigned int)(dword_5C4 - 1) + 8);
while ( strcmp(*v1, s2) )
{
if ( ++v1 == v2 )
return 0LL;
}
return 1LL;
}

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

if ( dword_5C4 <= 0 )
return 0LL;
v1 = (const char **)ptr;
v2 = (const char **)((char *)ptr + 8 * (unsigned int)(dword_5C4 - 1) + 8);
while ( strcmp(*v1, s2) )
{
if ( ++v1 == v2 )
return 0LL;
}
return 1LL;
}

original_code:
static int test_runned(const char* c) {
  for (int i = 0; i < ctx.runned_tests_size; i++) {
    if (strcmp(ctx.runned_tests[i], c) == 0) {
      return 1;
    }
  }
  return 0;
}

canonical_original_code:
static int test_runned(char *c) {
  for (int i = 0; i < ctx.runned_tests_size; i++) {
    if (strcmp(ctx.runned_tests[i], c) == 0) {
      return 1;
    }
  }
  return 0;
}

variable_types:
c
char *


decompiled_code:
void *__fastcall add_runned_test(char *a1)
{
int v1; // ebx
int v2; // esi
void *result; // rax

s1 = a1;
printf("\n %s ", a1);
v1 = dword_5C4;
v2 = ctx;
if ( dword_5C4 >= ctx )
{
ctx *= 2;
ptr = realloc(ptr, 16LL * v2);
}
dword_5C4 = v1 + 1;
result = ptr;
*((_QWORD *)ptr + v1) = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(char *a1)
{
int v1; // ebx
int v2; // esi
void *result; // rax

s1 = a1;
printf("\n %s ", a1);
v1 = dword_5C4;
v2 = ctx;
if ( dword_5C4 >= ctx )
{
ctx *= 2;
ptr = realloc(ptr, 16LL * v2);
}
dword_5C4 = v1 + 1;
result = ptr;
*((_QWORD *)ptr + v1) = a1;
return result;
}

original_code:
static void add_runned_test(const char* c) {
  ctx.current_name = c;
  printf("\n  %s ", c);
  if (ctx.runned_tests_size >= ctx.runned_tests_cap) {
    ctx.runned_tests_cap *= 2;
    ctx.runned_tests = realloc(ctx.runned_tests, sizeof(char*) * ctx.runned_tests_cap);
  }
  ctx.runned_tests[ctx.runned_tests_size++] = c;
}

canonical_original_code:
static void add_runned_test(char *c) {
  ctx.current_name = c;
  printf("\n  %s ", c);
  if (ctx.runned_tests_size >= ctx.runned_tests_cap) {
    ctx.runned_tests_cap *= 2;
    ctx.runned_tests = realloc(ctx.runned_tests, sizeof(char *) * ctx.runned_tests_cap);
  }
  ctx.runned_tests[ctx.runned_tests_size++] = c;
}


decompiled_code:
__sighandler_t __fastcall ccut_print_trace_on(int a1)
{
return _sysv_signal(a1, (__sighandler_t)print_trace_handler);
}

canonical_decompiled_code:
__sighandler_t __fastcall func6(int a1)
{
return _sysv_signal(a1, (__sighandler_t)print_trace_handler);
}

original_code:
void ccut_print_trace_on(int sig) {
  signal(sig, print_trace_handler);
}


usage

decompiled_code:
int usage()
{
printf(
"Usage: %s [FILE]...\nPrint CRC (32-bit) checksums.\n\nWith no FILE, or when FILE is -, read standard input.\n",
"crc32sum");
return puts("\n --help\t display this help and exit");
}

canonical_decompiled_code:
int func7()
{
printf(
"Usage: %s [FILE]...\nPrint CRC (32-bit) checksums.\n\nWith no FILE, or when FILE is -, read standard input.\n",
"crc32sum");
return puts("\n --help\t display this help and exit");
}

original_code:
void usage()
{
 printf("Usage: %s [FILE]...\n"
        "Print CRC (32-bit) checksums.\n"
        "\n"
        "With no FILE, or when FILE is -, read standard input.\n",
        "crc32sum");
 printf("\n"
        "      --help\t display this help and exit\n");
}


version

decompiled_code:
int version()
{
return printf(
"Copyright (C) 2013.\n"
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/old-licenses/gpl-2.0.html>.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"
"\n"
"Written by %s.\n",
"Luis Ortega Perez de Villar");
}

canonical_decompiled_code:
int func8()
{
return printf(
"Copyright (C) 2013.\n"
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/old-licenses/gpl-2.0.html>.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"
"\n"
"Written by %s.\n",
"Luis Ortega Perez de Villar");
}

original_code:
void version()
{
 printf("Copyright (C) 2013.\n"
        "License GPLv2+: GNU GPL version 2 or later"
        " <http://gnu.org/licenses/old-licenses/gpl-2.0.html>.\n"
        "This is free software: you are free to change and"
        " redistribute it.\n"
        "There is NO WARRANTY, to the extent permitted by law.\n"
        "\n"
        "Written by %s.\n", "Luis Ortega Perez de Villar");
}


strntrim

decompiled_code:
char *__fastcall strntrim(char *a1, __int64 a2)
{
char *v2; // rbx
const unsigned __int16 **v3; // rsi
char *result; // rax

v2 = &a1[a2];
if ( a1 >= &a1[a2] )
{
v2 = a1;
LABEL_5:
result = v2;
}
else
{
v3 = __ctype_b_loc();
result = a1;
while ( ((*v3)[*result] & 0x2000) != 0 )
{
if ( v2 == ++result )
goto LABEL_5;
}
if ( v2 > result )
{
do
{
if ( ((*v3)[*v2] & 0x2000) == 0 )
break;
*v2-- = 0;
}
while ( v2 != result );
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *a1, __int64 a2)
{
char *v2; // rbx
const unsigned __int16 **v3; // rsi
char *result; // rax

v2 = &a1[a2];
if ( a1 >= &a1[a2] )
{
v2 = a1;
LABEL_5:
result = v2;
}
else
{
v3 = __ctype_b_loc();
result = a1;
while ( ((*v3)[*result] & 0x2000) != 0 )
{
if ( v2 == ++result )
goto LABEL_5;
}
if ( v2 > result )
{
do
{
if ( ((*v3)[*v2] & 0x2000) == 0 )
break;
*v2-- = 0;
}
while ( v2 != result );
}
}
return result;
}

original_code:
char * strntrim(char *str, size_t len)
{
 char *strend = str + len;
 while ((str < strend) && ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace))
  str++;
 while ((strend > str) && (((*__ctype_b_loc ())[(int) ((*strend))] & (unsigned short int) _ISspace))) {
  *strend = '\0';
  strend--;
 }
 return str;
}

canonical_original_code:
char *strntrim(char *str, unsigned long len)
{
 char *strend = str + len;
 while ((str < strend) && ((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace))
  str++;
 while ((strend > str) && (((*__ctype_b_loc ())[(int) ((*strend))] & (unsigned short) _ISspace))) {
  *strend = '\0';
  strend--;
 }
 return str;
}

variable_types:
str
char *

variable_types:
len
unsigned long

variable_types:
strend
char *

return_type: char *


decompiled_code:
__int64 __fastcall digest_bytestream(int fd)
{
size_t v1; // r13
void *v2; // r12
__int64 v3; // rbx
int v4; // eax
ssize_t v5; // rax
struct stat v7; // [rsp+0h] [rbp-B8h] BYREF

if ( fd )
{
v3 = 0LL;
if ( (unsigned int)fstat(fd, &v7) == -1 )
return v3;
v4 = v7.st_mode & 0xF000;
if ( v4 == 0x4000 )
{
*__errno_location() = 21;
return v3;
}
if ( v4 != 0x8000 )
{
*__errno_location() = 22;
return 0LL;
}
}
v1 = getpagesize();
v2 = calloc(v1, 1uLL);
if ( !v2 )
return 0LL;
LABEL_9:
v3 = crc32();
do
{
v5 = read(fd, v2, v1);
if ( !v5 )
break;
if ( v5 != -1 )
goto LABEL_9;
}
while ( *__errno_location() == 4 );
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd)
{
size_t v1; // r13
void *v2; // r12
__int64 v3; // rbx
int v4; // eax
ssize_t v5; // rax
struct stat v7; // [rsp+0h] [rbp-B8h] BYREF

if ( fd )
{
v3 = 0LL;
if ( (unsigned int)func16(fd, &v7) == -1 )
return v3;
v4 = v7.st_mode & 0xF000;
if ( v4 == 0x4000 )
{
*__errno_location() = 21;
return v3;
}
if ( v4 != 0x8000 )
{
*__errno_location() = 22;
return 0LL;
}
}
v1 = getpagesize();
v2 = calloc(v1, 1uLL);
if ( !v2 )
return 0LL;
LABEL_9:
v3 = crc32();
do
{
v5 = read(fd, v2, v1);
if ( !v5 )
break;
if ( v5 != -1 )
goto LABEL_9;
}
while ( *__errno_location() == 4 );
free(v2);
return v3;
}

original_code:
uLong digest_bytestream(int fd)
{
 struct stat sb;
 uLong crc = 0;
 char *buf = ((void *)0);
 ssize_t ret;
 size_t len = getpagesize();
 if (fd == 0)
  goto db_digest;
 if (fstat(fd, &sb) == -1)
  goto db_out;
 if (((((sb.st_mode)) & 0170000) == (0040000))) {
  (*__errno_location ()) = 21;
  goto db_out;
 }
 if (!((((sb.st_mode)) & 0170000) == (0100000))) {
  (*__errno_location ()) = 22;
  goto db_out;
 }
db_digest:
 buf = calloc(len, sizeof(char));
 if (buf == ((void *)0))
  goto db_out;
 crc = crc32(0L, 0, 0);
 while ((ret = read(fd, buf, len)) != 0) {
  if (ret == -1) {
   if ((*__errno_location ()) == 4)
    continue;
   break;
  }
  crc = crc32(crc, (Bytef *) buf, ret);
 }
 free(buf);
db_out:
 return crc;
}

canonical_original_code:
unsigned long digest_bytestream(int fd)
{
 struct stat sb;
 unsigned long crc = 0;
 char *buf = ((void *)0);
 long ret;
 unsigned long len = getpagesize();
 if (fd == 0)
  goto db_digest;
 if (fstat(fd, &sb) == -1)
  goto db_out;
 if (((((sb.st_mode)) & 0170000) == (0040000))) {
  (*__errno_location ()) = 21;
  goto db_out;
 }
 if (!((((sb.st_mode)) & 0170000) == (0100000))) {
  (*__errno_location ()) = 22;
  goto db_out;
 }
db_digest:
 buf = calloc(len, sizeof(char));
 if (buf == ((void *)0))
  goto db_out;
 crc = crc32(0L, 0, 0);
 while ((ret = read(fd, buf, len)) != 0) {
  if (ret == -1) {
   if ((*__errno_location ()) == 4)
    continue;
   break;
  }
  crc = crc32(crc, (unsigned char *) buf, ret);
 }
 free(buf);
db_out:
 return crc;
}

variable_types: fd int

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

variable_types:
crc
unsigned long

variable_types:
buf
char *

variable_types: ret long

return_type: unsigned long

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


decompiled_code:
__int64 __fastcall digest_file(const char *a1)
{
int v1; // eax
__int64 v2; // rbp
int v3; // ebx

v1 = open(a1, 0);
v2 = 1LL;
if ( v1 != -1 )
{
v3 = v1;
v2 = digest_bytestream(v1);
close(v3);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
int v1; // eax
__int64 v2; // rbp
int v3; // ebx

v1 = open(a1, 0);
v2 = 1LL;
if ( v1 != -1 )
{
v3 = v1;
v2 = func10(v1);
close(v3);
}
return v2;
}

original_code:
uLong digest_file(const char *filename)
{
 int fd;
 uLong crc;
 fd = open(filename, 00);
 if (fd == -1)
  return 1;
 crc = digest_bytestream(fd);
 close(fd);
 return crc;
}

canonical_original_code:
unsigned long digest_file(char *filename)
{
 int fd;
 unsigned long crc;
 fd = open(filename, 00);
 if (fd == -1)
  return 1;
 crc = digest_bytestream(fd);
 close(fd);
 return crc;
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall sum_file(const char *a1)
{
int *v2; // rbp
__int64 v3; // rax
int v4; // edi
char *v5; // rax

v2 = __errno_location();
*v2 = 0;
if ( !strcmp(a1, "-") )
v3 = digest_bytestream(0);
else
v3 = digest_file(a1);
v4 = *v2;
if ( *v2 )
{
if ( v4 == 21 )
{
fprintf(stderr, "%s: %s: Is a directory\n", "crc32sum", a1);
}
else
{
v5 = strerror(v4);
fprintf(stderr, "%s: %s\n", a1, v5);
}
}
else
{
fprintf(stdout, "%08lX %s\n", v3, a1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
int *v2; // rbp
__int64 v3; // rax
int v4; // edi
char *v5; // rax

v2 = __errno_location();
*v2 = 0;
if ( !strcmp(a1, "-") )
v3 = func10(0);
else
v3 = func11(a1);
v4 = *v2;
if ( *v2 )
{
if ( v4 == 21 )
{
fprintf(stderr, "%s: %s: Is a directory\n", "crc32sum", a1);
}
else
{
v5 = strerror(v4);
fprintf(stderr, "%s: %s\n", a1, v5);
}
}
else
{
fprintf(stdout, "%08lX %s\n", v3, a1);
}
return 0LL;
}

original_code:
int sum_file(char *filename)
{
 uLong crc;
 (*__errno_location ()) = 0;
 if ((strcmp((filename), ("-")) == 0))
  crc = digest_bytestream(0);
 else
  crc = digest_file(filename);
 if ((*__errno_location ()))
  if ((*__errno_location ()) == 21)
   fprintf(stderr, "%s: %s: Is a directory\n",
    "crc32sum", filename);
  else
   fprintf(stderr, "%s: %s\n", filename, strerror((*__errno_location ())));
 else
  fprintf(stdout, "%08lX  %s\n", crc, filename);
 return 0;
}

canonical_original_code:
int sum_file(char *filename)
{
 unsigned long crc;
 (*__errno_location ()) = 0;
 if ((strcmp((filename), ("-")) == 0))
  crc = digest_bytestream(0);
 else
  crc = digest_file(filename);
 if ((*__errno_location ()))
  if ((*__errno_location ()) == 21)
   fprintf(stderr, "%s: %s: Is a directory\n",
    "crc32sum", filename);
  else
   fprintf(stderr, "%s: %s\n", filename, strerror((*__errno_location ())));
 else
  fprintf(stdout, "%08lX  %s\n", crc, filename);
 return 0;
}


main

canonical_name: main

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

if ( argc == 1 )
return sum_file("-");
do
{
v3 = getopt_long(argc, (char *const *)argv, "c:", &long_options, 0LL);
if ( v3 == -1 )
{
for ( i = optind; argc > (int)i; ++i )
sum_file(argv[i]);
return 0;
}
}
while ( !v3 );
if ( v3 <= 0 )
{
if ( v3 == -3 )
{
version();
result = 0;
}
else
{
if ( v3 != -2 )
goto LABEL_13;
usage();
result = 0;
}
}
else
{
if ( v3 != 63 )
{
if ( v3 == 99 )
return digest_check(optarg);
LABEL_13:
abort();
}
result = 1;
}
return result;
}

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

if ( argc == 1 )
return func12("-");
do
{
v3 = getopt_long(argc, (char *const *)argv, "c:", &long_options, 0LL);
if ( v3 == -1 )
{
for ( i = optind; argc > (int)i; ++i )
func12(argv[i]);
return 0;
}
}
while ( !v3 );
if ( v3 <= 0 )
{
if ( v3 == -3 )
{
func8();
result = 0;
}
else
{
if ( v3 != -2 )
goto LABEL_13;
func7();
result = 0;
}
}
else
{
if ( v3 != 63 )
{
if ( v3 == 99 )
return func13(optarg);
LABEL_13:
abort();
}
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 extern int optind, optopt;
 extern char *optarg;
 int c;
 if (argc == 1)
  return sum_file("-");
 while ((c = getopt_long(argc, argv, "c:", long_options, ((void *)0))) != -1) {
  switch (c) {
  case 0:
   continue;
  case 'c':
   return digest_check(optarg);
  case -2:
   usage();
   return 0;
  case -3:
   version();
   return 0;
  case '?':
   return 1;
  default:
   abort();
  }
 }
 for (int i = optind; i < argc; i++)
  sum_file(argv[i]);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 extern int optind; extern int optopt;
 extern char *optarg;
 int c;
 if (argc == 1)
  return sum_file("-");
 while ((c = getopt_long(argc, argv, "c:", long_options, ((void *)0))) != -1) {
  switch (c) {
  case 0:
   continue;
  case 'c':
   return digest_check(optarg);
  case -2:
   usage();
   return 0;
  case -3:
   version();
   return 0;
  case '?':
   return 1;
  default:
   abort();
  }
 }
 for (int i = optind; i < argc; i++)
  sum_file(argv[i]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: optind int

variable_types: optopt int

variable_types:
optarg
char *

variable_types: c int

variable_types: i int


repo: luisbebop/nano-torrent

original_code:
int handshake_message() {
 char protocol[] = "BitTorrent protocol";
 unsigned char pstrlen = strlen(protocol);
 unsigned char buf[pstrlen+49];
 unsigned char recv[pstrlen+49];
 int recvd;
 buf[0]=pstrlen;
 memcpy(&buf[1],protocol,pstrlen);
 memcpy(&buf[1+pstrlen+8],digest,20);
 memcpy(&buf[1+pstrlen+8+20],peer_id,20);
 uclsend(buf, sizeof(buf));
 hexdump(buf, sizeof(buf), "sent handshake");
 recvd = uclreceive(recv, pstrlen+49);
 hexdump(recv, recvd, "received handshake");
 if (recvd != pstrlen+49) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int handshake_message() {
 char protocol[] = "BitTorrent protocol";
 unsigned char pstrlen = strlen(protocol);
 unsigned char buf[-1];
 unsigned char recv[-1];
 int recvd;
 buf[0]=pstrlen;
 memcpy(&buf[1],protocol,pstrlen);
 memcpy(&buf[1+pstrlen+8],digest,20);
 memcpy(&buf[1+pstrlen+8+20],peer_id,20);
 uclsend(buf, sizeof(buf));
 hexdump(buf, sizeof(buf), "sent handshake");
 recvd = uclreceive(recv, pstrlen+49);
 hexdump(recv, recvd, "received handshake");
 if (recvd != pstrlen+49) {
  return 0;
 }
 return 1;
}

variable_types:
protocol
char []

variable_types:
pstrlen
unsigned char

variable_types:
buf
unsigned char [-1]

variable_types:
recv
unsigned char [-1]

variable_types: recvd int


decompiled_code:
__int64 __fastcall interested_message(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
char v6[13]; // [rsp+Bh] [rbp-Dh] BYREF

v6[0] = 0;
v6[1] = 0;
v6[2] = 0;
v6[3] = 1;
v6[4] = 2;
uclsend(v6, 5LL, a3, a4, a5);
return hexdump(v6, 5LL, "sent interested");
}

original_code:
void interested_message() {
 int msgsize = 1;
 unsigned char buf[5] = {((unsigned char)((((unsigned short)((msgsize) >> 16))) >> 8)), ((unsigned char)((((unsigned short)((msgsize) >> 16))) & 0xff)), ((unsigned char)((((unsigned short)((msgsize) & 0xffff))) >> 8)), ((unsigned char)((((unsigned short)((msgsize) & 0xffff))) & 0xff)), 0x02};
 uclsend(buf, 5);
 hexdump(buf, 5, "sent interested");
}

variable_types: msgsize int

variable_types:
buf
unsigned char [5]


original_code:
void requestblock_message(int index, int begin, int length) {
 int msgsize = 13;
 unsigned char buf[17] = {((unsigned char)((((unsigned short)((msgsize) >> 16))) >> 8)), ((unsigned char)((((unsigned short)((msgsize) >> 16))) & 0xff)), ((unsigned char)((((unsigned short)((msgsize) & 0xffff))) >> 8)), ((unsigned char)((((unsigned short)((msgsize) & 0xffff))) & 0xff)), 0x06,
        ((unsigned char)((((unsigned short)((index) >> 16))) >> 8)), ((unsigned char)((((unsigned short)((index) >> 16))) & 0xff)), ((unsigned char)((((unsigned short)((index) & 0xffff))) >> 8)), ((unsigned char)((((unsigned short)((index) & 0xffff))) & 0xff)),
        ((unsigned char)((((unsigned short)((begin) >> 16))) >> 8)), ((unsigned char)((((unsigned short)((begin) >> 16))) & 0xff)), ((unsigned char)((((unsigned short)((begin) & 0xffff))) >> 8)), ((unsigned char)((((unsigned short)((begin) & 0xffff))) & 0xff)),
        ((unsigned char)((((unsigned short)((length) >> 16))) >> 8)), ((unsigned char)((((unsigned short)((length) >> 16))) & 0xff)), ((unsigned char)((((unsigned short)((length) & 0xffff))) >> 8)), ((unsigned char)((((unsigned short)((length) & 0xffff))) & 0xff))};
 uclsend(buf, 17);
 hexdump(buf, 17, "sent request block");
}

variable_types: index int

variable_types: begin int

variable_types: length int

variable_types:
buf
unsigned char [17]


decompiled_code:
__int64 __fastcall check_sha1_piece(__int64 a1, int a2, int a3)
{
int v3; // edx
__int64 result; // rax
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

sha1_compute(a1, a3, v5);
v3 = memcmp(v5, (char *)&pieces_sha1 + 20 * a2, 0x14uLL);
result = 1LL;
if ( v3 )
{
puts("invalid sha1 piece");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
int v3; // edx
__int64 result; // rax
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

sha1_compute(a1, a3, v5);
v3 = memcmp(v5, (char *)&pieces_sha1 + 20 * a2, 0x14uLL);
result = 1LL;
if ( v3 )
{
puts("invalid sha1 piece");
result = 0LL;
}
return result;
}

original_code:
int check_sha1_piece(unsigned char *piece_buf, int piece, int offset) {
 unsigned char sha1_piece[20];
 sha1_compute(piece_buf, offset, sha1_piece);
 if (memcmp(&sha1_piece[0], &pieces_sha1[piece*20], 20) == 0) {
  return 1;
 } else {
  printf("invalid sha1 piece\n");
  return 0;
 }
}

variable_types: piece int

variable_types: offset int


decompiled_code:
__int64 check_next_piece()
{
__int64 v0; // rax
unsigned __int64 v1; // rbp
int v2; // er12
__int64 v3; // r13
__int64 v4; // rbx
__int64 v5; // rbx
__int64 result; // rax
__int64 v7; // rax

files = ben_dict_get_by_str(info, "files");
if ( files )
{
file_length = 0;
puts("check_next_piece multiple files");
v0 = files;
if ( *(_QWORD *)(files + 8) )
{
v1 = 0LL;
v2 = 0;
do
{
v3 = *(_QWORD *)(*(_QWORD *)(v0 + 24) + 8 * v1);
v4 = ben_dict_get_by_str(v3, "path");
printf(
"check_next_piece filename[i]=%s\n",
*(const char **)(*(_QWORD *)(*(_QWORD *)(v4 + 24) + 8LL * *(_QWORD *)(v4 + 8) - 8) + 16LL));
file_length += *(_QWORD *)(ben_dict_get_by_str(v3, "length") + 8);
v5 = (unsigned int)getfilesize(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 24) + 8LL * *(_QWORD *)(v4 + 8) - 8)
+ 16LL));
printf("check_next_piece file_len_disk=%d\n", v5);
if ( (int)v5 > 0 )
v2 += v5;
v0 = files;
++v1;
}
while ( *(_QWORD *)(files + 8) > v1 );
}
else
{
v2 = 0;
}
}
else
{
puts("check next_piece single file");
file_length = *(_QWORD *)(ben_dict_get_by_str(info, "length") + 8);
v7 = ben_dict_get_by_str(info, "name");
v2 = getfilesize(*(_QWORD *)(v7 + 16));
printf("check_next_piece file_length=%d\n", (unsigned int)file_length);
}
if ( file_length == v2 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( v2 > 0 )
result = (unsigned int)(v2 / piece_length);
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
unsigned __int64 v1; // rbp
int v2; // er12
__int64 v3; // r13
__int64 v4; // rbx
__int64 v5; // rbx
__int64 result; // rax
__int64 v7; // rax

files = ben_dict_get_by_str(info, "files");
if ( files )
{
file_length = 0;
puts("check_next_piece multiple files");
v0 = files;
if ( *(_QWORD *)(files + 8) )
{
v1 = 0LL;
v2 = 0;
do
{
v3 = *(_QWORD *)(*(_QWORD *)(v0 + 24) + 8 * v1);
v4 = ben_dict_get_by_str(v3, "path");
printf(
"check_next_piece filename[i]=%s\n",
*(const char **)(*(_QWORD *)(*(_QWORD *)(v4 + 24) + 8LL * *(_QWORD *)(v4 + 8) - 8) + 16LL));
file_length += *(_QWORD *)(ben_dict_get_by_str(v3, "length") + 8);
v5 = (unsigned int)getfilesize(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 24) + 8LL * *(_QWORD *)(v4 + 8) - 8)
+ 16LL));
printf("check_next_piece file_len_disk=%d\n", v5);
if ( (int)v5 > 0 )
v2 += v5;
v0 = files;
++v1;
}
while ( *(_QWORD *)(files + 8) > v1 );
}
else
{
v2 = 0;
}
}
else
{
puts("check next_piece single file");
file_length = *(_QWORD *)(ben_dict_get_by_str(info, "length") + 8);
v7 = ben_dict_get_by_str(info, "name");
v2 = getfilesize(*(_QWORD *)(v7 + 16));
printf("check_next_piece file_length=%d\n", (unsigned int)file_length);
}
if ( file_length == v2 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( v2 > 0 )
result = (unsigned int)(v2 / piece_length);
return result;
}

original_code:
int check_next_piece() {
 int i = 0;
 int file_len_disk = 0;
 int total_size = 0;
 struct bencode* file;
 struct bencode_list* path;
 files = (struct bencode_list*)ben_dict_get_by_str(info,"files");
 if (files) {
  file_length = 0;
  printf("check_next_piece multiple files\n");
  for (i=0; i < files->n; i++) {
   file = files->values[i];
   path = (struct bencode_list*)ben_dict_get_by_str(file,"path");
   printf("check_next_piece filename[i]=%s\n", ((struct bencode_str*)path->values[(path->n)-1])->s);
   file_length += ((struct bencode_int*)ben_dict_get_by_str(file,"length"))->ll;
   file_len_disk = getfilesize(((struct bencode_str*)path->values[(path->n)-1])->s);
   printf("check_next_piece file_len_disk=%d\n", file_len_disk);
   if (file_len_disk > 0) {
    total_size += file_len_disk;
   }
  }
 } else {
  printf("check next_piece single file\n");
  file_length = ((struct bencode_int*)ben_dict_get_by_str(info,"length"))->ll;
  total_size = getfilesize(((struct bencode_str*)ben_dict_get_by_str(info,"name"))->s);
  printf("check_next_piece file_length=%d\n", file_length);
 }
 if (total_size == file_length) {
  return -1;
 }
 if (total_size <= 0) {
  return 0;
 }
 return total_size/piece_length;
}

canonical_original_code:
int check_next_piece() {
 int i = 0;
 int file_len_disk = 0;
 int total_size = 0;
 struct bencode *file;
 struct bencode_list *path;
 files = (struct bencode_list *)ben_dict_get_by_str(info,"files");
 if (files) {
  file_length = 0;
  printf("check_next_piece multiple files\n");
  for (i=0; i < files->n; i++) {
   file = files->values[i];
   path = (struct bencode_list *)ben_dict_get_by_str(file,"path");
   printf("check_next_piece filename[i]=%s\n", ((struct bencode_str *)path->values[(path->n)-1])->s);
   file_length += ((struct bencode_int *)ben_dict_get_by_str(file,"length"))->ll;
   file_len_disk = getfilesize(((struct bencode_str *)path->values[(path->n)-1])->s);
   printf("check_next_piece file_len_disk=%d\n", file_len_disk);
   if (file_len_disk > 0) {
    total_size += file_len_disk;
   }
  }
 } else {
  printf("check next_piece single file\n");
  file_length = ((struct bencode_int *)ben_dict_get_by_str(info,"length"))->ll;
  total_size = getfilesize(((struct bencode_str *)ben_dict_get_by_str(info,"name"))->s);
  printf("check_next_piece file_length=%d\n", file_length);
 }
 if (total_size == file_length) {
  return -1;
 }
 if (total_size <= 0) {
  return 0;
 }
 return total_size/piece_length;
}

variable_types:
file
struct bencode { char type; } *

variable_types: struct bencode_list { char type; unsigned long n; unsigned long alloc; struct bencode { char type; } **values; } *

user_defined_types: struct bencode_list { char type; unsigned long n; unsigned long alloc; struct bencode **values; }

user_defined_types: struct bencode_str { char type; unsigned long len; char *s; }

user_defined_types: struct bencode_int { char type; long long ll; }


decompiled_code:
__int64 __fastcall parse_torrent(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
__int64 v3; // rdi
__int64 v4; // rsi
void *v5; // rbx
__int64 v6; // rsi
const void *v7; // r12
__int64 v8; // rbp
__int64 v10; // [rsp+8h] [rbp-3020h] BYREF
char s[12312]; // [rsp+10h] [rbp-3018h] BYREF

memset(s, 0, 0x3000uLL);
v1 = readbinaryfile(s, a1);
v2 = 0;
if ( v1 > 0 )
{
v3 = ben_decode(s, v1, 0LL);
torrent = v3;
v2 = 0;
if ( v3 )
{
v4 = ben_dict_get_by_str(v3, "info");
info = v4;
v2 = 0;
if ( v4 )
{
v5 = (void *)ben_encode(&v10, v4, 0LL);
sha1_compute(v5, v10, &digest);
free(v5);
hexdump(&digest, 20LL, "parse_torrent digest");
v6 = *(_QWORD *)(ben_dict_get_by_str(info, "piece length") + 8);
piece_length = v6;
printf("parse_torrent piece_length=%d\n", v6);
v7 = *(const void **)(ben_dict_get_by_str(info, "pieces") + 16);
v8 = *(_QWORD *)(ben_dict_get_by_str(info, "pieces") + 8);
memcpy(&pieces_sha1, v7, (int)v8);
pieces_num = (int)v8 / 20;
printf("parse_torrent pieces=%d\n", (unsigned int)((int)v8 / 20));
hexdump(&pieces_sha1, (unsigned int)v8, "parse_torrent pieces_sha1");
requested_piece = check_next_piece();
printf("parse_torrent requested_piece=%d\n", (unsigned int)requested_piece);
printf("parse_torrent file_length=%d\n", (unsigned int)file_length);
v2 = 1;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
__int64 v3; // rdi
__int64 v4; // rsi
void *v5; // rbx
__int64 v6; // rsi
const void *v7; // r12
__int64 v8; // rbp
__int64 v10; // [rsp+8h] [rbp-3020h] BYREF
char s[12312]; // [rsp+10h] [rbp-3018h] BYREF

memset(s, 0, 0x3000uLL);
v1 = readbinaryfile(s, a1);
v2 = 0;
if ( v1 > 0 )
{
v3 = ben_decode(s, v1, 0LL);
torrent = v3;
v2 = 0;
if ( v3 )
{
v4 = ben_dict_get_by_str(v3, "info");
info = v4;
v2 = 0;
if ( v4 )
{
v5 = (void *)ben_encode(&v10, v4, 0LL);
sha1_compute(v5, v10, &digest);
free(v5);
hexdump(&digest, 20LL, "parse_torrent digest");
v6 = *(_QWORD *)(ben_dict_get_by_str(info, "piece length") + 8);
piece_length = v6;
printf("parse_torrent piece_length=%d\n", v6);
v7 = *(const void **)(ben_dict_get_by_str(info, "pieces") + 16);
v8 = *(_QWORD *)(ben_dict_get_by_str(info, "pieces") + 8);
memcpy(&pieces_sha1, v7, (int)v8);
pieces_num = (int)v8 / 20;
printf("parse_torrent pieces=%d\n", (unsigned int)((int)v8 / 20));
hexdump(&pieces_sha1, (unsigned int)v8, "parse_torrent pieces_sha1");
requested_piece = func5();
printf("parse_torrent requested_piece=%d\n", (unsigned int)requested_piece);
printf("parse_torrent file_length=%d\n", (unsigned int)file_length);
v2 = 1;
}
}
}
return v2;
}

original_code:
int parse_torrent(char *torrent_filename) {
 unsigned char buf[12 * 1024];
 unsigned char *sha1_pieces;
 int sha1_pieces_len;
 int len = 0;
 size_t info_len;
 char *info_encoded;
 memset(buf, 0, sizeof(buf));
 len = readbinaryfile(buf, torrent_filename);
 if (len <= 0) {
  return 0;
 }
 torrent = (struct bencode*)ben_decode(buf,len);
 if(!torrent) {
  return 0;
 }
 info = (struct bencode*)ben_dict_get_by_str((struct bencode*)torrent,"info");
 if(!info) {
  return 0;
 }
 info_encoded = ben_encode(&info_len,(struct bencode*)info);
 sha1_compute(info_encoded, info_len, digest);
 free(info_encoded);
 hexdump(digest, 20, "parse_torrent digest");
 piece_length = ((struct bencode_int*)ben_dict_get_by_str(info,"piece length"))->ll;
 printf("parse_torrent piece_length=%d\n", piece_length);
 sha1_pieces = ((struct bencode_str*)ben_dict_get_by_str(info,"pieces"))->s;
 sha1_pieces_len = ((struct bencode_str*)ben_dict_get_by_str(info,"pieces"))->len;
 memcpy(pieces_sha1, sha1_pieces, sha1_pieces_len);
 pieces_num = (sha1_pieces_len/20);
 printf("parse_torrent pieces=%d\n", pieces_num);
 hexdump(pieces_sha1, sha1_pieces_len, "parse_torrent pieces_sha1");
 requested_piece = check_next_piece();
 printf("parse_torrent requested_piece=%d\n", requested_piece);
 printf("parse_torrent file_length=%d\n", file_length);
 return 1;
}

canonical_original_code:
int parse_torrent(char *torrent_filename) {
 unsigned char buf[-1];
 unsigned char *sha1_pieces;
 int sha1_pieces_len;
 int len = 0;
 unsigned long info_len;
 char *info_encoded;
 memset(buf, 0, sizeof(buf));
 len = readbinaryfile(buf, torrent_filename);
 if (len <= 0) {
  return 0;
 }
 torrent = (struct bencode *)ben_decode(buf,len);
 if(!torrent) {
  return 0;
 }
 info = (struct bencode *)ben_dict_get_by_str((struct bencode *)torrent,"info");
 if(!info) {
  return 0;
 }
 info_encoded = ben_encode(&info_len,(struct bencode *)info);
 sha1_compute(info_encoded, info_len, digest);
 free(info_encoded);
 hexdump(digest, 20, "parse_torrent digest");
 piece_length = ((struct bencode_int *)ben_dict_get_by_str(info,"piece length"))->ll;
 printf("parse_torrent piece_length=%d\n", piece_length);
 sha1_pieces = ((struct bencode_str *)ben_dict_get_by_str(info,"pieces"))->s;
 sha1_pieces_len = ((struct bencode_str *)ben_dict_get_by_str(info,"pieces"))->len;
 memcpy(pieces_sha1, sha1_pieces, sha1_pieces_len);
 pieces_num = (sha1_pieces_len/20);
 printf("parse_torrent pieces=%d\n", pieces_num);
 hexdump(pieces_sha1, sha1_pieces_len, "parse_torrent pieces_sha1");
 requested_piece = check_next_piece();
 printf("parse_torrent requested_piece=%d\n", requested_piece);
 printf("parse_torrent file_length=%d\n", file_length);
 return 1;
}

variable_types: len int


decompiled_code:
__int64 __fastcall piece_message(int a1, unsigned __int8 *a2)
{
unsigned int v2; // er12
int v3; // ebx
int v4; // ebx
__int64 result; // rax
int v6; // ebp
__int64 v7; // rcx
__int64 v8; // r8

v2 = _byteswap_ushort(*((_WORD *)a2 + 1)) | (((*a2 << 8) | a2[1]) << 16);
v3 = _byteswap_ushort(*((_WORD *)a2 + 3)) | (((a2[4] << 8) | a2[5]) << 16);
printf("piece_message len=%d\n", (unsigned int)(a1 - 8));
printf("piece_message piece=%d\n", v2);
printf("piece_message requested_piece=%d\n", (unsigned int)requested_piece);
printf("piece_message offset=%d\n", (unsigned int)v3);
memcpy(&piece_buf[v3], a2 + 8, a1 - 8);
v4 = a1 - 8 + v3;
printf("piece_message download= %d|%d\n", v4 + piece_length * v2, (unsigned int)file_length);
if ( piece_length == v4 || v4 + v2 * piece_length == file_length )
{
if ( (unsigned int)check_sha1_piece((__int64)piece_buf, v2, v4) )
save_piece(piece_buf, v2, v4);
v4 = 0;
}
requested_piece = check_next_piece();
printf("piece_message requested_piece=%d\n", (unsigned int)requested_piece);
result = 1LL;
if ( requested_piece >= 0 )
{
v6 = file_length - (v4 + piece_length * v2);
if ( v6 >= 1024 )
v6 = 1024;
printf("piece_message size_to_receive=%d\n", (unsigned int)v6);
requestblock_message(requested_piece, v4, (unsigned int)v6, v7, v8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned __int8 *a2)
{
unsigned int v2; // er12
int v3; // ebx
int v4; // ebx
__int64 result; // rax
int v6; // ebp
__int64 v7; // rcx
__int64 v8; // r8

v2 = _byteswap_ushort(*((_WORD *)a2 + 1)) | (((*a2 << 8) | a2[1]) << 16);
v3 = _byteswap_ushort(*((_WORD *)a2 + 3)) | (((a2[4] << 8) | a2[5]) << 16);
printf("piece_message len=%d\n", (unsigned int)(a1 - 8));
printf("piece_message piece=%d\n", v2);
printf("piece_message requested_piece=%d\n", (unsigned int)requested_piece);
printf("piece_message offset=%d\n", (unsigned int)v3);
memcpy(&piece_buf[v3], a2 + 8, a1 - 8);
v4 = a1 - 8 + v3;
printf("piece_message download= %d|%d\n", v4 + piece_length * v2, (unsigned int)file_length);
if ( piece_length == v4 || v4 + v2 * piece_length == file_length )
{
if ( (unsigned int)func3((__int64)piece_buf, v2, v4) )
func4(piece_buf, v2, v4);
v4 = 0;
}
requested_piece = func5();
printf("piece_message requested_piece=%d\n", (unsigned int)requested_piece);
result = 1LL;
if ( requested_piece >= 0 )
{
v6 = file_length - (v4 + piece_length * v2);
if ( v6 >= 1024 )
v6 = 1024;
printf("piece_message size_to_receive=%d\n", (unsigned int)v6);
func2(requested_piece, v4, (unsigned int)v6, v7, v8);
result = 0LL;
}
return result;
}

original_code:
int piece_message(int len, unsigned char *buf) {
 int piece = ((int)(((unsigned short)(((unsigned short)(((unsigned char)((buf[3]) & 0xff)) | ((unsigned short)((unsigned char)((buf[2]) & 0xff))) << 8)))) | (((unsigned int)((unsigned short)(((unsigned short)(((unsigned char)((buf[1]) & 0xff)) | ((unsigned short)((unsigned char)((buf[0]) & 0xff))) << 8))))) << 16)));
 int offset = ((int)(((unsigned short)(((unsigned short)(((unsigned char)((buf[7]) & 0xff)) | ((unsigned short)((unsigned char)((buf[6]) & 0xff))) << 8)))) | (((unsigned int)((unsigned short)(((unsigned short)(((unsigned char)((buf[5]) & 0xff)) | ((unsigned short)((unsigned char)((buf[4]) & 0xff))) << 8))))) << 16)));
 int datalen = len-8;
 int maxlen = 0;
 int size_to_receive = 1024;
 printf("piece_message len=%d\n", datalen);
 printf("piece_message piece=%d\n", piece);
 printf("piece_message requested_piece=%d\n", requested_piece);
 printf("piece_message offset=%d\n", offset);
 memcpy(&piece_buf[offset], &buf[8], datalen);
 offset+=datalen;
 printf("piece_message download= %d|%d\n", offset+(piece*piece_length), file_length);
 if (offset == piece_length || (offset+(piece*piece_length) == file_length)) {
  if(check_sha1_piece(piece_buf, piece, offset)) {
   save_piece(piece_buf, piece, offset);
  }
  offset = 0;
 }
 requested_piece = check_next_piece();
 printf("piece_message requested_piece=%d\n", requested_piece);
 if (requested_piece >= 0) {
  maxlen = file_length - (piece*piece_length+offset);
  if (maxlen < 1024) {
   size_to_receive = maxlen;
  }
  printf("piece_message size_to_receive=%d\n", size_to_receive);
  requestblock_message(requested_piece,offset,size_to_receive);
  return 0;
 } else {
  return 1;
 }
}

variable_types:
buf
unsigned char *

variable_types: datalen int

variable_types: maxlen int


decompiled_code:
__int64 process_message_loop()
{
__int64 v1; // rsi
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rcx
__int64 v5; // r8
int i; // ebx
__int64 v7; // r12
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int16 vars0[1036]; // [rsp+0h] [rbp+0h] BYREF

do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
memset(vars0, 0, 0x800uLL);
puts("trying to receive a message ...");
v1 = (unsigned int)uclreceive(vars0, 4LL);
hexdump(vars0, v1, "uclreceive 4");
if ( (_DWORD)v1 != 4 )
{
LABEL_2:
puts("closing connection and exiting process_message_loop()");
uclclose();
return 0LL;
}
v2 = _byteswap_ushort(vars0[1]) | (((LOBYTE(vars0[0]) << 8) | (unsigned int)HIBYTE(vars0[0])) << 16);
printf("size_to_receive=%d\n", v2);
if ( (_DWORD)v2 )
break;
puts("keep alive message received");
}
v3 = (unsigned int)uclreceive(vars0, (unsigned int)v2);
hexdump(vars0, v3, "uclreceive N");
if ( (_DWORD)v2 == (_DWORD)v3 )
break;
if ( (int)v3 <= 0 )
goto LABEL_2;
for ( i = v2 - v3; i > 0; i -= v7 )
{
v7 = (unsigned int)uclreceive(vars0, (unsigned int)i);
hexdump(vars0, v7, "uclreceive DHT hash table");
}
}
if ( LOBYTE(vars0[0]) != 5 )
break;
hexdump(vars0, (unsigned int)v3, "bitfield message received");
interested_message((__int64)vars0, (unsigned int)v3, v8, v9, v10);
}
if ( LOBYTE(vars0[0]) == 7 )
break;
if ( LOBYTE(vars0[0]) == 1 )
{
hexdump(vars0, (unsigned int)v3, "unchoke message received");
requestblock_message(requested_piece, 0, 1024LL, v4, v5);
}
}
hexdump(vars0, (unsigned int)v3, "piece message received");
}
while ( !(unsigned int)piece_message((int)v3 - 1, (unsigned __int8 *)vars0 + 1) );
puts("closing connection and exiting process_message_loop()");
puts("all pieces downloaded()");
uclclose();
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v1; // rsi
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rcx
__int64 v5; // r8
int i; // ebx
__int64 v7; // r12
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int16 vars0[1036]; // [rsp+0h] [rbp+0h] BYREF

do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
memset(vars0, 0, 0x800uLL);
puts("trying to receive a message ...");
v1 = (unsigned int)uclreceive(vars0, 4LL);
hexdump(vars0, v1, "uclreceive 4");
if ( (_DWORD)v1 != 4 )
{
LABEL_2:
puts("closing connection and exiting process_message_loop()");
uclclose();
return 0LL;
}
v2 = _byteswap_ushort(vars0[1]) | (((LOBYTE(vars0[0]) << 8) | (unsigned int)HIBYTE(vars0[0])) << 16);
printf("size_to_receive=%d\n", v2);
if ( (_DWORD)v2 )
break;
puts("keep alive message received");
}
v3 = (unsigned int)uclreceive(vars0, (unsigned int)v2);
hexdump(vars0, v3, "uclreceive N");
if ( (_DWORD)v2 == (_DWORD)v3 )
break;
if ( (int)v3 <= 0 )
goto LABEL_2;
for ( i = v2 - v3; i > 0; i -= v7 )
{
v7 = (unsigned int)uclreceive(vars0, (unsigned int)i);
hexdump(vars0, v7, "uclreceive DHT hash table");
}
}
if ( LOBYTE(vars0[0]) != 5 )
break;
hexdump(vars0, (unsigned int)v3, "bitfield message received");
func1((__int64)vars0, (unsigned int)v3, v8, v9, v10);
}
if ( LOBYTE(vars0[0]) == 7 )
break;
if ( LOBYTE(vars0[0]) == 1 )
{
hexdump(vars0, (unsigned int)v3, "unchoke message received");
func2(requested_piece, 0, 1024LL, v4, v5);
}
}
hexdump(vars0, (unsigned int)v3, "piece message received");
}
while ( !(unsigned int)func7((int)v3 - 1, (unsigned __int8 *)vars0 + 1) );
puts("closing connection and exiting process_message_loop()");
puts("all pieces downloaded()");
uclclose();
return 1LL;
}

original_code:
int process_message_loop() {
 unsigned char recv[2048];
 int recvd = 0;
 int size_to_receive;
 while(42) {
  memset(recv,0,sizeof(recv));
  printf("trying to receive a message ...\n");
  recvd = uclreceive(recv, 4);
  hexdump(recv, recvd, "uclreceive 4");
  if (recvd != 4) {
   printf("closing connection and exiting process_message_loop()\n");
   uclclose();
   return 0;
  }
  size_to_receive = ((int)(((unsigned short)(((unsigned short)(((unsigned char)((recv[3]) & 0xff)) | ((unsigned short)((unsigned char)((recv[2]) & 0xff))) << 8)))) | (((unsigned int)((unsigned short)(((unsigned short)(((unsigned char)((recv[1]) & 0xff)) | ((unsigned short)((unsigned char)((recv[0]) & 0xff))) << 8))))) << 16)));
  printf("size_to_receive=%d\n", size_to_receive);
  if (size_to_receive == 0) {
   printf("keep alive message received\n");
   continue;
  }
  recvd = uclreceive(recv, size_to_receive);
  hexdump(recv, recvd, "uclreceive N");
  if (recvd != size_to_receive) {
   if (recvd > 0) {
    size_to_receive -= recvd;
    while (size_to_receive > 0) {
     recvd = uclreceive(recv, size_to_receive);
     hexdump(recv, recvd, "uclreceive DHT hash table");
     size_to_receive -= recvd;
    }
    continue;
   }
   printf("closing connection and exiting process_message_loop()\n");
   uclclose();
   return 0;
  }
  switch(recv[0]) {
   case 1: {
    hexdump(recv, recvd, "unchoke message received");
    requestblock_message(requested_piece,0,1024);
    break;
   }
   case 5: {
    hexdump(recv, recvd, "bitfield message received");
    interested_message();
    break;
   }
   case 7: {
    hexdump(recv, recvd, "piece message received");
    if(piece_message(recvd-1, &recv[1])) {
     printf("closing connection and exiting process_message_loop()\n");
     printf("all pieces downloaded()\n");
     uclclose();
     return 1;
    }
    break;
   }
  }
 }
}

variable_types:
recv
unsigned char [2048]


decompiled_code:
__int64 start_peer_connection()
{
unsigned int v0; // ebx

uclconnect();
if ( handshake_message() )
return (unsigned int)process_message_loop();
v0 = 0;
uclclose();
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // ebx

uclconnect();
if ( func0() )
return (unsigned int)func8();
v0 = 0;
uclclose();
return v0;
}

original_code:
int start_peer_connection(int argc, char *argv[]) {
 int ret;
 uclconnect(argc,argv);
 if (handshake_message()) {
  return process_message_loop();
 } else {
  uclclose();
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int


decompiled_code:
__int64 clean_memory()
{
__int64 result; // rax

if ( torrent )
result = ben_free();
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax

if ( torrent )
result = ben_free();
return result;
}

original_code:
void clean_memory() {
 if(torrent) {
  ben_free(torrent);
 }
}


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
perror(a1);
exit(0);
}

original_code:
void error(const char *msg)
{
 perror(msg);
 exit(0);
}

canonical_original_code:
void error(char *msg)
{
 perror(msg);
 exit(0);
}

variable_types:
msg
char *


uclconnect

decompiled_code:
int __fastcall uclconnect(int a1, const char **a2)
{
__int16 v2; // r12
int v3; // ebp
struct hostent *v4; // rax
int result; // eax
struct sockaddr dest[2]; // [rsp+0h] [rbp-28h] BYREF

if ( a1 <= 2 )
{
printf("usage %s hostname port\n", *a2);
exit(0);
}
v2 = atoi(a2[2]);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
error("ERROR opening socket");
v4 = gethostbyname(a2[1]);
if ( !v4 )
{
puts("ERROR, no such host");
exit(0);
}
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
memmove(&dest[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)dest[0].sa_data = _bswap_16(v2);
result = connect(v3, dest, 0x10u);
if ( result < 0 )
error("ERROR connecting");
socket_handle = v3;
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, const char **a2)
{
__int16 v2; // r12
int v3; // ebp
struct hostent *v4; // rax
int result; // eax
struct sockaddr dest[2]; // [rsp+0h] [rbp-28h] BYREF

if ( a1 <= 2 )
{
printf("usage %s hostname port\n", *a2);
exit(0);
}
v2 = atoi(a2[2]);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
func1("ERROR opening socket");
v4 = gethostbyname(a2[1]);
if ( !v4 )
{
puts("ERROR, no such host");
exit(0);
}
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
memmove(&dest[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)dest[0].sa_data = func0(v2);
result = connect(v3, dest, 0x10u);
if ( result < 0 )
func1("ERROR connecting");
socket_handle = v3;
return result;
}

original_code:
void uclconnect(int argc, char *argv[])
{
 int sockfd, portno, n;
 struct sockaddr_in serv_addr;
 struct hostent *server;
 if (argc < 3) {
  printf("usage %s hostname port\n", argv[0]);
  exit(0);
 }
 portno = atoi(argv[2]);
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) {
  error("ERROR opening socket");
 }
 server = gethostbyname(argv[1]);
 if (server == ((void *)0)) {
  printf("ERROR, no such host\n");
  exit(0);
 }
 bzero((char *) &serv_addr, sizeof(serv_addr));
 serv_addr.sin_family = 2;
 bcopy((char *)server->h_addr_list[0], (char *)&serv_addr.sin_addr.s_addr, server->h_length);
 serv_addr.sin_port = htons(portno);
 if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) {
  error("ERROR connecting");
 }
 socket_handle = sockfd;
}

canonical_original_code:
void uclconnect(int argc, char *argv[])
{
 int sockfd; int portno; int n;
 struct sockaddr_in serv_addr;
 struct hostent *server;
 if (argc < 3) {
  printf("usage %s hostname port\n", argv[0]);
  exit(0);
 }
 portno = atoi(argv[2]);
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) {
  error("ERROR opening socket");
 }
 server = gethostbyname(argv[1]);
 if (server == ((void *)0)) {
  printf("ERROR, no such host\n");
  exit(0);
 }
 bzero((char *) &serv_addr, sizeof(serv_addr));
 serv_addr.sin_family = 2;
 bcopy((char *)server->h_addr_list[0], (char *)&serv_addr.sin_addr.s_addr, server->h_length);
 serv_addr.sin_port = htons(portno);
 if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) {
  error("ERROR connecting");
 }
 socket_handle = sockfd;
}

variable_types: sockfd int

variable_types: portno int

variable_types: n 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; } *

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


uclsend

decompiled_code:
ssize_t __fastcall uclsend(void *buf, size_t n)
{
ssize_t result; // rax

result = write(socket_handle, buf, (unsigned int)n);
if ( (int)result < 0 )
error("ERROR writing to socket");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *buf, size_t n)
{
ssize_t result; // rax

result = write(socket_handle, buf, (unsigned int)n);
if ( (int)result < 0 )
func1("ERROR writing to socket");
return result;
}

original_code:
int uclsend(unsigned char * buf, int len)
{
 int n;
 n = write(socket_handle,buf,len);
 if (n < 0) {
  error("ERROR writing to socket");
 }
 return n;
}

canonical_original_code:
int uclsend(unsigned char *buf, int len)
{
 int n;
 n = write(socket_handle,buf,len);
 if (n < 0) {
  error("ERROR writing to socket");
 }
 return n;
}


uclreceive

decompiled_code:
ssize_t __fastcall uclreceive(void *buf, size_t nbytes)
{
ssize_t result; // rax

result = read(socket_handle, buf, (unsigned int)nbytes);
if ( (int)result < 0 )
error("ERROR reading from socket");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(void *buf, size_t nbytes)
{
ssize_t result; // rax

result = read(socket_handle, buf, (unsigned int)nbytes);
if ( (int)result < 0 )
func1("ERROR reading from socket");
return result;
}

original_code:
int uclreceive(unsigned char * buf, int maxlen)
{
 int n;
 n = read(socket_handle,buf,maxlen);
 if (n < 0) {
  error("ERROR reading from socket");
 }
 return n;
}

canonical_original_code:
int uclreceive(unsigned char *buf, int maxlen)
{
 int n;
 n = read(socket_handle,buf,maxlen);
 if (n < 0) {
  error("ERROR reading from socket");
 }
 return n;
}


uclclose

decompiled_code:
int uclclose()
{
return close(socket_handle);
}

canonical_decompiled_code:
int func5()
{
return close(socket_handle);
}

original_code:
void uclclose() {
 close(socket_handle);
}


hexdump

decompiled_code:
int __fastcall hexdump(char *a1, int a2, const char *a3)
{
int result; // eax
__int64 v4; // rbp
int v5; // ebx
_DWORD v6[34]; // [rsp+0h] [rbp-C8h] BYREF
char s[4]; // [rsp+88h] [rbp-40h] BYREF
char v8; // [rsp+8Ch] [rbp-3Ch]

memset(v6, 0, 0x80uLL);
printf("---------> %s <--------- (%d bytes from %p)\n", a3, (unsigned int)a2, a1);
puts(" +0 +4 +8 +c 0 4 8 c ");
result = 538976288;
strcpy((char *)v6, "+0000 \n");
if ( a2 > 0 )
{
v4 = 1LL;
v5 = 0;
while ( 1 )
{
sprintf(s, "%02x", (unsigned __int8)a1[v4 - 1]);
*(_WORD *)((char *)&v6[2] + 3 * v5) = *(_WORD *)s;
result = (unsigned __int8)a1[v4 - 1];
if ( (unsigned __int8)(result - 32) > 0x5Eu )
{
result = v5;
*((_BYTE *)&v6[14] + v5 + 2) = 46;
}
else
{
*((_BYTE *)&v6[14] + v5 + 2) = result;
}
++v5;
if ( v4 == a2 )
break;
if ( v5 == 16 )
{
printf("%s", (const char *)v6);
memset(v6, 32, 74);
sprintf(s, "+%04x", (unsigned int)v4);
v6[0] = *(_DWORD *)s;
LOBYTE(v6[1]) = v8;
v5 = 0;
}
++v4;
}
if ( v5 )
result = printf("%s", (const char *)v6);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *a1, int a2, const char *a3)
{
int result; // eax
__int64 v4; // rbp
int v5; // ebx
_DWORD v6[34]; // [rsp+0h] [rbp-C8h] BYREF
char s[4]; // [rsp+88h] [rbp-40h] BYREF
char v8; // [rsp+8Ch] [rbp-3Ch]

memset(v6, 0, 0x80uLL);
printf("---------> %s <--------- (%d bytes from %p)\n", a3, (unsigned int)a2, a1);
puts(" +0 +4 +8 +c 0 4 8 c ");
result = 538976288;
strcpy((char *)v6, "+0000 \n");
if ( a2 > 0 )
{
v4 = 1LL;
v5 = 0;
while ( 1 )
{
sprintf(s, "%02x", (unsigned __int8)a1[v4 - 1]);
*(_WORD *)((char *)&v6[2] + 3 * v5) = *(_WORD *)s;
result = (unsigned __int8)a1[v4 - 1];
if ( (unsigned __int8)(result - 32) > 0x5Eu )
{
result = v5;
*((_BYTE *)&v6[14] + v5 + 2) = 46;
}
else
{
*((_BYTE *)&v6[14] + v5 + 2) = result;
}
++v5;
if ( v4 == a2 )
break;
if ( v5 == 16 )
{
printf("%s", (const char *)v6);
memset(v6, 32, 74);
sprintf(s, "+%04x", (unsigned int)v4);
v6[0] = *(_DWORD *)s;
LOBYTE(v6[1]) = v8;
v5 = 0;
}
++v4;
}
if ( v5 )
result = printf("%s", (const char *)v6);
}
return result;
}

original_code:
void hexdump(unsigned char *data, int size, char *caption) {
 int i;
 int j;
 char temp[8];
 char buffer[128];
 char *ascii;
 memset(buffer, 0, 128);
 printf("---------> %s <--------- (%d bytes from %p)\n", caption, size, data);
 printf("        +0          +4          +8          +c            0   4   8   c   \n");
 ascii = buffer + 58;
 memset(buffer, ' ', 58 + 16);
 buffer[58 + 16] = '\n';
 buffer[58 + 17] = '\0';
 buffer[0] = '+';
 buffer[1] = '0';
 buffer[2] = '0';
 buffer[3] = '0';
 buffer[4] = '0';
 for (i = 0, j = 0; i < size; i++, j++) {
  if (j == 16) {
   printf("%s", buffer);
   memset(buffer, ' ', 58 + 16);
   sprintf(temp, "+%04x", i);
   memcpy(buffer, temp, 5);
   j = 0;
  }
  sprintf(temp, "%02x", 0xff & data[i]);
  memcpy(buffer + 8 + (j * 3), temp, 2);
  if ((data[i] > 31) && (data[i] < 127)) {
   ascii[j] = data[i];
  } else {
   ascii[j] = '.';
  }
 }
 if (j != 0) {
  printf("%s", buffer);
 }
}

variable_types:
data
unsigned char *

variable_types: size int

variable_types:
caption
char *

variable_types: i int

variable_types: j int

variable_types:
temp
char [8]

variable_types:
buffer
char [128]

variable_types:
ascii
char *


main

repo: luislavena/experiments

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("main: calling prefect_awesome...");
perfect_awesome("main: calling prefect_awesome...", argv);
puts("main: done.");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("main: calling prefect_awesome...");
func8("main: calling prefect_awesome...", argv);
puts("main: done.");
return 0;
}

original_code:
int main(void)
{
 puts("main: calling prefect_awesome...");
 perfect_awesome();
 puts("main: done.");
 return 0;
}

canonical_original_code:
int main()
{
 puts("main: calling prefect_awesome...");
 perfect_awesome();
 puts("main: done.");
 return 0;
}


decompiled_code:
int perfect_awesome()
{
puts("b: calling perfect...");
perfect();
puts("b: calling awesome...");
return _wrap_awesome();
}

canonical_decompiled_code:
int func8()
{
puts("b: calling perfect...");
func10();
puts("b: calling awesome...");
return func7();
}

original_code:
void perfect_awesome(void)
{
 puts("b: calling perfect...");
 perfect();
 puts("b: calling awesome...");
 awesome();
}

canonical_original_code:
void perfect_awesome()
{
 puts("b: calling perfect...");
 perfect();
 puts("b: calling awesome...");
 awesome();
}


awesome

decompiled_code:
int awesome()
{
return puts("Awesome from A!");
}

canonical_decompiled_code:
int func9()
{
return puts("Awesome from A!");
}

original_code:
void awesome(void)
{
 puts("Awesome from A!");
}

canonical_original_code:
void awesome()
{
 puts("Awesome from A!");
}


perfect

decompiled_code:
int perfect()
{
return puts("Perfect!");
}

canonical_decompiled_code:
int func10()
{
return puts("Perfect!");
}

original_code:
void perfect(void)
{
 puts("Perfect!");
}

canonical_original_code:
void perfect()
{
 puts("Perfect!");
}


repo: lukasz-skalski/CUPS-GPIO-Notifier

decompiled_code:
void __fastcall unix_signal_handler(int a1)
{
if ( a1 == 2 )
g_main_loop_quit();
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( a1 == 2 )
g_main_loop_quit();
}

original_code:
void unix_signal_handler (int signo)
{
  if (signo == 2)
    g_main_loop_quit (loop);
}

canonical_original_code:
void unix_signal_handler(int signo)
{
  if (signo == 2)
    g_main_loop_quit (loop);
}

variable_types: signo int


decompiled_code:
__int64 printer_off_timeout()
{
set_GPIO((unsigned int)gpio_num, 1u);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
func11((unsigned int)gpio_num, 1u);
return 0LL;
}

original_code:
int printer_off_timeout (gpointer user_data)
{
  set_GPIO (gpio_num,1);
  return (0);
}

canonical_original_code:
int printer_off_timeout(void *user_data)
{
  set_GPIO (gpio_num,1);
  return (0);
}


demonize

decompiled_code:
int demonize()
{
__pid_t v0; // eax

v0 = fork();
if ( v0 < 0 )
exit(1);
if ( v0 > 0 )
exit(0);
umask(0);
if ( setsid() < 0 )
exit(1);
if ( chdir("/") < 0 )
exit(1);
close(0);
close(1);
return close(2);
}

canonical_decompiled_code:
int func14()
{
__pid_t v0; // eax

v0 = fork();
if ( v0 < 0 )
exit(1);
if ( v0 > 0 )
exit(0);
umask(0);
if ( setsid() < 0 )
exit(1);
if ( chdir("/") < 0 )
exit(1);
close(0);
close(1);
return close(2);
}

original_code:
void demonize (void)
{
  pid_t pid;
  pid_t sid;
  pid = fork();
  if (pid < 0)
    exit (1);
  if (pid > 0)
    exit (0);
  umask(0);
  sid = setsid();
  if (sid < 0)
    exit (1);
  if ((chdir("/")) < 0)
    exit (1);
  close (0);
  close (1);
  close (2);
}

canonical_original_code:
void demonize()
{
  int pid;
  int sid;
  pid = fork();
  if (pid < 0)
    exit (1);
  if (pid > 0)
    exit (0);
  umask(0);
  sid = setsid();
  if (sid < 0)
    exit (1);
  if ((chdir("/")) < 0)
    exit (1);
  close (0);
  close (1);
  close (2);
}

variable_types: pid int

variable_types: sid int


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

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 65) > 5u )
_assert_fail("0", "utils/libhexbin.c", 0x31u, "get_nibble");
result = (unsigned int)(a1 - 55);
}
return result;
}

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

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 65) > 5u )
_assert_fail("0", "utils/libhexbin.c", 0x31u, "get_nibble");
result = (unsigned int)(a1 - 55);
}
return result;
}

original_code:
static uint8_t get_nibble (char c)
{
  uint8_t nibble;
  if (('0' <= c) && (c <= '9'))
    nibble = c - '0';
  else if (('A' <= c) && (c <= 'F'))
    nibble = 10 + (c - 'A');
  else
    ((0) ? (void) (0) : __assert_fail ("0", "utils/libhexbin.c", 49, __extension__ __PRETTY_FUNCTION__));
  return nibble;
}

canonical_original_code:
static unsigned char get_nibble(char c)
{
  unsigned char nibble;
  if (('0' <= c) && (c <= '9'))
    nibble = c - '0';
  else if (('A' <= c) && (c <= 'F'))
    nibble = 10 + (c - 'A');
  else
    ((0) ? (void) (0) : __assert_fail ("0", "utils/libhexbin.c", 49, __extension__ __PRETTY_FUNCTION__));
  return nibble;
}

variable_types: c char

variable_types:
nibble
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall get_byte(char *a1)
{
int v1; // ebx

v1 = get_nibble(*a1);
return 16 * v1 + (unsigned int)get_nibble(a1[1]);
}

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

v1 = func0(*a1);
return 16 * v1 + (unsigned int)func0(a1[1]);
}

original_code:
static uint8_t get_byte (char *buf)
{
  return (get_nibble (buf[0]) << 4) + (get_nibble (buf[1]));
}

canonical_original_code:
static unsigned char get_byte(char *buf)
{
  return (get_nibble (buf[0]) << 4) + (get_nibble (buf[1]));
}

variable_types:
buf
char *


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

v1 = a1[269] & 3;
if ( v1 == 2 )
return (unsigned __int8)a1[270];
if ( (a1[269] & 3) == 3 )
return (unsigned __int8)a1[270] + ((unsigned __int8)a1[272] << 8);
if ( v1 )
return (unsigned __int8)a1[270] + ((unsigned __int8)a1[272] << 8);
return (unsigned __int8)a1[270] + 32 * (unsigned int)(unsigned __int8)a1[272];
}

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

v1 = a1[269] & 3;
if ( v1 == 2 )
return (unsigned __int8)a1[270];
if ( (a1[269] & 3) == 3 )
return (unsigned __int8)a1[270] + ((unsigned __int8)a1[272] << 8);
if ( v1 )
return (unsigned __int8)a1[270] + ((unsigned __int8)a1[272] << 8);
return (unsigned __int8)a1[270] + 32 * (unsigned int)(unsigned __int8)a1[272];
}

variable_types: struct vm8051 { unsigned int cycles; unsigned char _data[256]; unsigned char _sfr[128]; unsigned char _xdata[65536]; unsigned char _code[65536]; unsigned char IR[4]; unsigned short PC; unsigned char interrupted; unsigned char interrupts_blocked; void *coprocessors; } *


decompiled_code:
__int64 __fastcall get_timer1(_BYTE *a1)
{
unsigned __int8 v1; // al
__int64 result; // rax

v1 = a1[269] & 0x30;
if ( v1 == 32 )
return (unsigned __int8)a1[271];
if ( v1 > 0x20u )
{
if ( v1 == 48 )
result = (unsigned __int8)a1[271] + ((unsigned __int8)a1[273] << 8);
else
result = 0xFFFFFFFFLL;
}
else if ( v1 )
{
if ( v1 == 16 )
result = (unsigned __int8)a1[271] + ((unsigned __int8)a1[273] << 8);
else
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned __int8)a1[271] + 32 * (unsigned int)(unsigned __int8)a1[273];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
unsigned __int8 v1; // al
__int64 result; // rax

v1 = a1[269] & 0x30;
if ( v1 == 32 )
return (unsigned __int8)a1[271];
if ( v1 > 0x20u )
{
if ( v1 == 48 )
result = (unsigned __int8)a1[271] + ((unsigned __int8)a1[273] << 8);
else
result = 0xFFFFFFFFLL;
}
else if ( v1 )
{
if ( v1 == 16 )
result = (unsigned __int8)a1[271] + ((unsigned __int8)a1[273] << 8);
else
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned __int8)a1[271] + 32 * (unsigned int)(unsigned __int8)a1[273];
}
return result;
}

user_defined_types: struct vm8051 { unsigned int cycles; unsigned char _data[256]; unsigned char _sfr[128]; unsigned char _xdata[65536]; unsigned char _code[65536]; unsigned char IR[4]; unsigned short PC; unsigned char interrupted; unsigned char interrupts_blocked; void *coprocessors; }


original_code:
size_t inst8051 (struct vm8051 *vm, uint8_t *inst, uint16_t addr)
{
  size_t inst_len = 0;
  inst[0] = vm->_code[addr+inst_len++];
  if (inst[0] & 0x08)
    {
      switch (inst[0] & 0xF0)
        {
        case 0x70:
        case 0x80:
        case 0xA0:
        case 0xD0:
          inst[1] = vm->_code[addr+inst_len++];
          break;
        case 0xB0:
          inst[1] = vm->_code[addr+inst_len++];
          inst[2] = vm->_code[addr+inst_len++];
          break;
        }
    }
  else if ((inst[0] & 0x06) == 0x06)
    {
      switch (inst[0] & 0xF0)
        {
        case 0x70:
        case 0x80:
        case 0xA0:
          inst[1] = vm->_code[addr+inst_len++];
          break;
        case 0xB0:
          inst[1] = vm->_code[addr+inst_len++];
          inst[2] = vm->_code[addr+inst_len++];
          break;
        }
    }
  else if ((inst[0] & 0x0F) == 0x01)
    {
      inst[1] = vm->_code[addr+inst_len++];
    }
  else
    {
      switch (inst[0])
        {
        case 0x10:
        case 0x20:
        case 0x30:
        case 0x90:
        case 0x02:
        case 0x12:
        case 0x43:
        case 0x53:
        case 0x63:
        case 0xB4:
        case 0x75:
        case 0x85:
        case 0xB5:
        case 0xD5:
          inst[1] = vm->_code[addr+inst_len++];
          inst[2] = vm->_code[addr+inst_len++];
          break;
        case 0x40:
        case 0x50:
        case 0x60:
        case 0x70:
        case 0x80:
        case 0xA0:
        case 0xB0:
        case 0xC0:
        case 0xD0:
        case 0x42:
        case 0x52:
        case 0x62:
        case 0x72:
        case 0x82:
        case 0x92:
        case 0xA2:
        case 0xB2:
        case 0xC2:
        case 0xD2:
        case 0x24:
        case 0x34:
        case 0x44:
        case 0x54:
        case 0x64:
        case 0x74:
        case 0x94:
        case 0x05:
        case 0x15:
        case 0x25:
        case 0x35:
        case 0x45:
        case 0x55:
        case 0x65:
        case 0x95:
        case 0xC5:
        case 0xE5:
        case 0xF5:
          inst[1] = vm->_code[addr+inst_len++];
          break;
        }
    }
  inst[3] = (uint8_t) inst_len;
  return inst_len;
}

canonical_original_code:
unsigned long inst8051(struct vm8051 *vm, unsigned char *inst, unsigned short addr)
{
  unsigned long inst_len = 0;
  inst[0] = vm->_code[addr+inst_len++];
  if (inst[0] & 0x08)
    {
      switch (inst[0] & 0xF0)
        {
        case 0x70:
        case 0x80:
        case 0xA0:
        case 0xD0:
          inst[1] = vm->_code[addr+inst_len++];
          break;
        case 0xB0:
          inst[1] = vm->_code[addr+inst_len++];
          inst[2] = vm->_code[addr+inst_len++];
          break;
        }
    }
  else if ((inst[0] & 0x06) == 0x06)
    {
      switch (inst[0] & 0xF0)
        {
        case 0x70:
        case 0x80:
        case 0xA0:
          inst[1] = vm->_code[addr+inst_len++];
          break;
        case 0xB0:
          inst[1] = vm->_code[addr+inst_len++];
          inst[2] = vm->_code[addr+inst_len++];
          break;
        }
    }
  else if ((inst[0] & 0x0F) == 0x01)
    {
      inst[1] = vm->_code[addr+inst_len++];
    }
  else
    {
      switch (inst[0])
        {
        case 0x10:
        case 0x20:
        case 0x30:
        case 0x90:
        case 0x02:
        case 0x12:
        case 0x43:
        case 0x53:
        case 0x63:
        case 0xB4:
        case 0x75:
        case 0x85:
        case 0xB5:
        case 0xD5:
          inst[1] = vm->_code[addr+inst_len++];
          inst[2] = vm->_code[addr+inst_len++];
          break;
        case 0x40:
        case 0x50:
        case 0x60:
        case 0x70:
        case 0x80:
        case 0xA0:
        case 0xB0:
        case 0xC0:
        case 0xD0:
        case 0x42:
        case 0x52:
        case 0x62:
        case 0x72:
        case 0x82:
        case 0x92:
        case 0xA2:
        case 0xB2:
        case 0xC2:
        case 0xD2:
        case 0x24:
        case 0x34:
        case 0x44:
        case 0x54:
        case 0x64:
        case 0x74:
        case 0x94:
        case 0x05:
        case 0x15:
        case 0x25:
        case 0x35:
        case 0x45:
        case 0x55:
        case 0x65:
        case 0x95:
        case 0xC5:
        case 0xE5:
        case 0xF5:
          inst[1] = vm->_code[addr+inst_len++];
          break;
        }
    }
  inst[3] = (unsigned char) inst_len;
  return inst_len;
}

variable_types:
inst
unsigned char *

variable_types:
addr
unsigned short


original_code:
void fetch8051 (struct vm8051 *vm)
{
  vm->PC += inst8051 (vm, vm->IR, vm->PC);
}

canonical_original_code:
void fetch8051(struct vm8051 *vm)
{
  vm->PC += inst8051 (vm, vm->IR, vm->PC);
}