decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // ebx
__int64 v5; // rax
const char *v6; // rcx
const char *v7; // rdx
int result; // eax
unsigned int v9; // ebp
unsigned int v10; // ebx
__int64 v11; // r13
__int64 v12; // r12

Pm_Initialize();
if ( argc == 3 )
{
v9 = atoi(argv[1]);
v10 = atoi(argv[2]);
Pt_Start();
v11 = Pm_GetDeviceInfo();
v12 = Pm_GetDeviceInfo();
printf("Using device #%2d, '%s' for input\n", v9, *(const char **)(v11 + 16));
printf("Using device #%2d, '%s' for output\n", v10, *(const char **)(v12 + 16));
if ( *(_DWORD *)(v12 + 28) )
{
if ( *(_DWORD *)(v11 + 24) )
{
midi_process(v9, v10);
Pm_Terminate();
result = 0;
}
else
{
puts("Selected device is unsuitable for input, exiting.");
result = -1;
}
}
else
{
puts("Selected device is unsuitable for output, exiting.");
result = -1;
}
}
else
{
v3 = Pm_CountDevices();
printf("\nUsage: %s <input device id> <output device id>\n\n", *argv);
printf("Listing %d devices:\n", (unsigned int)v3);
if ( v3 <= 0 )
{
result = 0;
}
else
{
v4 = 0;
while ( 1 )
{
v5 = Pm_GetDeviceInfo();
if ( !v5 )
break;
v6 = "\n\t" + 2;
if ( *(_DWORD *)(v5 + 28) )
v6 = "output";
v7 = "input ";
if ( !*(_DWORD *)(v5 + 24) )
v7 = "\n\t" + 2;
printf("\tDevice: #%2d (%s%s) '%s'\n", v4++, v7, v6, *(const char **)(v5 + 16));
if ( v3 == v4 )
return 0;
}
printf("\tDevice id (%2d) out of range\n", v4);
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // ebx
__int64 v5; // rax
const char *v6; // rcx
const char *v7; // rdx
int result; // eax
unsigned int v9; // ebp
unsigned int v10; // ebx
__int64 v11; // r13
__int64 v12; // r12

Pm_Initialize();
if ( argc == 3 )
{
v9 = atoi(argv[1]);
v10 = atoi(argv[2]);
Pt_Start();
v11 = Pm_GetDeviceInfo();
v12 = Pm_GetDeviceInfo();
printf("Using device #%2d, '%s' for input\n", v9, *(const char **)(v11 + 16));
printf("Using device #%2d, '%s' for output\n", v10, *(const char **)(v12 + 16));
if ( *(_DWORD *)(v12 + 28) )
{
if ( *(_DWORD *)(v11 + 24) )
{
func21(v9, v10);
Pm_Terminate();
result = 0;
}
else
{
puts("Selected device is unsuitable for input, exiting.");
result = -1;
}
}
else
{
puts("Selected device is unsuitable for output, exiting.");
result = -1;
}
}
else
{
v3 = Pm_CountDevices();
printf("\nUsage: %s <input device id> <output device id>\n\n", *argv);
printf("Listing %d devices:\n", (unsigned int)v3);
if ( v3 <= 0 )
{
result = 0;
}
else
{
v4 = 0;
while ( 1 )
{
v5 = Pm_GetDeviceInfo();
if ( !v5 )
break;
v6 = "\n\t" + 2;
if ( *(_DWORD *)(v5 + 28) )
v6 = "output";
v7 = "input ";
if ( !*(_DWORD *)(v5 + 24) )
v7 = "\n\t" + 2;
printf("\tDevice: #%2d (%s%s) '%s'\n", v4++, v7, v6, *(const char **)(v5 + 16));
if ( v3 == v4 )
return 0;
}
printf("\tDevice id (%2d) out of range\n", v4);
result = 0;
}
}
return result;
}

original_code:
int main(int c, char **v) {
  int dev_count, i;
  PmDeviceID devi, devo;
  const PmDeviceInfo *in, *out;
  Pm_Initialize();
  if(c!=3) {
    dev_count = Pm_CountDevices();
    printf("\nUsage: %s <input device id> <output device id>\n\n", v[0]);
    printf("Listing %d devices:\n", dev_count);
    for(i=0;i<dev_count;i++) {
      devi = i;
      in = Pm_GetDeviceInfo(devi);
      if(in==((void *)0)) {
        printf("\tDevice id (%2d) out of range\n", devi);
        break;
      }
      printf("\tDevice: #%2d (%s%s) '%s'\n",
        devi, (in->input ? "input " : ""), (in->output ? "output" : ""),
        in->name);
    }
    return 0;
  }
  devi=atoi(v[1]);
  devo=atoi(v[2]);
  Pt_Start(1, 0, 0);
  in=Pm_GetDeviceInfo(devi);
  out=Pm_GetDeviceInfo(devo);
  printf("Using device #%2d, '%s' for input\n", devi, in->name);
  printf("Using device #%2d, '%s' for output\n", devo, out->name);
  if(!out->output) {
    printf("Selected device is unsuitable for output, exiting.\n");
    return -1;
  }
  if(!in->input) {
    printf("Selected device is unsuitable for input, exiting.\n");
    return -1;
  }
  midi_process(devi, devo);
  Pm_Terminate();
  return 0;
}

canonical_original_code:
int main(int c, char **v) {
  int dev_count; int i;
  int devi; int devo;
  struct PmDeviceInfo *in; struct PmDeviceInfo *out;
  Pm_Initialize();
  if(c!=3) {
    dev_count = Pm_CountDevices();
    printf("\nUsage: %s <input device id> <output device id>\n\n", v[0]);
    printf("Listing %d devices:\n", dev_count);
    for(i=0;i<dev_count;i++) {
      devi = i;
      in = Pm_GetDeviceInfo(devi);
      if(in==((void *)0)) {
        printf("\tDevice id (%2d) out of range\n", devi);
        break;
      }
      printf("\tDevice: #%2d (%s%s) '%s'\n",
        devi, (in->input ? "input " : ""), (in->output ? "output" : ""),
        in->name);
    }
    return 0;
  }
  devi=atoi(v[1]);
  devo=atoi(v[2]);
  Pt_Start(1, 0, 0);
  in=Pm_GetDeviceInfo(devi);
  out=Pm_GetDeviceInfo(devo);
  printf("Using device #%2d, '%s' for input\n", devi, in->name);
  printf("Using device #%2d, '%s' for output\n", devo, out->name);
  if(!out->output) {
    printf("Selected device is unsuitable for output, exiting.\n");
    return -1;
  }
  if(!in->input) {
    printf("Selected device is unsuitable for input, exiting.\n");
    return -1;
  }
  midi_process(devi, devo);
  Pm_Terminate();
  return 0;
}

variable_types: c int

variable_types:
v
char **

variable_types: i int

variable_types: struct PmDeviceInfo { int structVersion; char *interf; char *name; int input; int output; int opened; } *


main

canonical_name: main

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

if ( argc <= 1 )
{
fprintf(stderr, "usage %s dir", *argv);
result = 1;
}
else
{
scan(argv[1]);
result = 0;
}
return result;
}

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

if ( argc <= 1 )
{
fprintf(stderr, "usage %s dir", *argv);
result = 1;
}
else
{
func7(argv[1]);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc<=1) {
  fprintf(stderr, "usage %s dir", argv[0]);
  return 1;
 }
 scan(argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


eval

repo: termie/corewarjs

original_code:
char *
eval(int prevPrec, long val1, char oper1, char *expr, long *result)
{
  long result2, val2;
  char oper2;
  int prec1, prec2;
  expr = getval(expr, &val2);
  while(((*__ctype_b_loc ())[(int) ((*(expr)))] & (unsigned short int) _ISspace)) ++(expr);
  if ((((*expr)==')' || !(*expr)) ? 1 : 0)) {
    *result = calc(val1, val2, oper1);
    return expr;
  }
  expr = getop(expr, &oper2);
  saveOper = 0;
  if ((prec1 = (oper1=='*' || oper1=='/' || oper1=='%' ? 5 : (oper1=='+' || oper1=='-' ? 4 : (oper1=='>' || oper1=='<' || oper1==EQUAL || oper1==NEQU || oper1==GTE || oper1==LTE ? 3 : (oper1==AND ? 2 : (oper1==OR ? 1 : 0)))))) >= (prec2 = (oper2=='*' || oper2=='/' || oper2=='%' ? 5 : (oper2=='+' || oper2=='-' ? 4 : (oper2=='>' || oper2=='<' || oper2==EQUAL || oper2==NEQU || oper2==GTE || oper2==LTE ? 3 : (oper2==AND ? 2 : (oper2==OR ? 1 : 0))))))) {
    if (prec2 >= prevPrec || prec1 <= prevPrec) {
      expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
    } else {
      *result = calc(val1, val2, oper1);
      saveOper = oper2;
    }
  } else {
    expr = eval(prec1, val2, oper2, expr, &result2);
    *result = calc(val1, result2, oper1);
    if (saveOper && (saveOper=='*' || saveOper=='/' || saveOper=='%' ? 5 : (saveOper=='+' || saveOper=='-' ? 4 : (saveOper=='>' || saveOper=='<' || saveOper==EQUAL || saveOper==NEQU || saveOper==GTE || saveOper==LTE ? 3 : (saveOper==AND ? 2 : (saveOper==OR ? 1 : 0))))) >= prevPrec) {
      expr = eval(prec2, *result, saveOper, expr, result);
      saveOper = 0;
    }
  }
  return expr;
}

canonical_original_code:
char *eval(int prevPrec, long val1, char oper1, char *expr, long *result)
{
  long result2; long val2;
  char oper2;
  int prec1; int prec2;
  expr = getval(expr, &val2);
  while(((*__ctype_b_loc ())[(int) ((*(expr)))] & (unsigned short) _ISspace)) ++(expr);
  if ((((*expr)==')' || !(*expr)) ? 1 : 0)) {
    *result = calc(val1, val2, oper1);
    return expr;
  }
  expr = getop(expr, &oper2);
  saveOper = 0;
  if ((prec1 = (oper1=='*' || oper1=='/' || oper1=='%' ? 5 : (oper1=='+' || oper1=='-' ? 4 : (oper1=='>' || oper1=='<' || oper1==EQUAL || oper1==NEQU || oper1==GTE || oper1==LTE ? 3 : (oper1==AND ? 2 : (oper1==OR ? 1 : 0)))))) >= (prec2 = (oper2=='*' || oper2=='/' || oper2=='%' ? 5 : (oper2=='+' || oper2=='-' ? 4 : (oper2=='>' || oper2=='<' || oper2==EQUAL || oper2==NEQU || oper2==GTE || oper2==LTE ? 3 : (oper2==AND ? 2 : (oper2==OR ? 1 : 0))))))) {
    if (prec2 >= prevPrec || prec1 <= prevPrec) {
      expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
    } else {
      *result = calc(val1, val2, oper1);
      saveOper = oper2;
    }
  } else {
    expr = eval(prec1, val2, oper2, expr, &result2);
    *result = calc(val1, result2, oper1);
    if (saveOper && (saveOper=='*' || saveOper=='/' || saveOper=='%' ? 5 : (saveOper=='+' || saveOper=='-' ? 4 : (saveOper=='>' || saveOper=='<' || saveOper==EQUAL || saveOper==NEQU || saveOper==GTE || saveOper==LTE ? 3 : (saveOper==AND ? 2 : (saveOper==OR ? 1 : 0))))) >= prevPrec) {
      expr = eval(prec2, *result, saveOper, expr, result);
      saveOper = 0;
    }
  }
  return expr;
}

variable_types: prevPrec int

variable_types:
expr
char *

variable_types:
result
long *

return_type: char *


decompiled_code:
void **reset_regs()
{
void **result; // rax

result = (void **)regAr;
do
*result++ = 0LL;
while ( result != jpt_B );
return result;
}

canonical_decompiled_code:
void **func4()
{
void **result; // rax

result = (void **)regAr;
do
*result++ = 0LL;
while ( result != jpt_B );
return result;
}

original_code:
void
reset_regs()
{
  register int idx;
  for (idx = 0; idx < 26; ++idx)
    regAr[idx] = 0L;
}

variable_types: idx int

return_type: void


decompiled_code:
__int64 __fastcall perfect_fit_check(unsigned __int64 a1, int *a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax

v2 = *a2;
result = 0LL;
if ( v2 <= a1 )
{
result = 1LL;
if ( v2 != a1 )
{
printf("NOT POSSIBLE");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, int *a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax

v2 = *a2;
result = 0LL;
if ( v2 <= a1 )
{
result = 1LL;
if ( v2 != a1 )
{
printf("NOT POSSIBLE");
result = 0LL;
}
}
return result;
}

original_code:
int perfect_fit_check(size_t size_block_wanted, uint8_t * ptr_to_block ){
  uint32_t * a_ptr_to_block = (uint32_t * )ptr_to_block ;
  int size_of_memory_block = (int) * a_ptr_to_block;
  if ((size_of_memory_block ) > size_block_wanted ){
    return 0;
  }else if ((size_of_memory_block ) == (size_block_wanted )){
    return 1;
  }else{ printf("NOT POSSIBLE"); return 0;}
}

canonical_original_code:
int perfect_fit_check(unsigned long size_block_wanted, unsigned char *ptr_to_block){
  unsigned int *a_ptr_to_block = (uint32_t * )ptr_to_block;
  int size_of_memory_block = (int) * a_ptr_to_block;
  if ((size_of_memory_block ) > size_block_wanted ){
    return 0;
  }else if ((size_of_memory_block ) == (size_block_wanted )){
    return 1;
  }else{ printf("NOT POSSIBLE"); return 0;}
}


decompiled_code:
void __fastcall fixed_allocate(__int64 a1, __int64 a2)
{
*(_DWORD *)(a2 + 4) = 0;
}

original_code:
void fixed_allocate (size_t size_wanted, uint8_t *ptr ){
  uint32_t * a_ptr = (uint32_t *)ptr;
  a_ptr += 1;
  *a_ptr = 0;
}

canonical_original_code:
void fixed_allocate(unsigned long size_wanted, unsigned char *ptr){
  unsigned int *a_ptr = (uint32_t *)ptr;
  a_ptr += 1;
  *a_ptr = 0;
}

variable_types:
ptr
unsigned char *


decompiled_code:
int *__fastcall the_malloc(int a1)
{
int *v1; // rbx
int i; // ebp
__int64 v3; // rbp
int v4; // er12
int v5; // eax
int *v6; // r12
__int64 v7; // r13
int v8; // ebp

if ( !heap_begin )
heap_begin = (__int64)mmap(0LL, 0x100000uLL, 3, 34, -1, 0LL);
if ( !free_list )
{
free_list = heap_begin;
*(_DWORD *)heap_begin = 0x100000;
*(_DWORD *)(free_list + 4) = 0;
}
v1 = (int *)free_list;
for ( i = 0; (int)pow(2.0, (double)i) < (unsigned __int64)(a1 + 8); ++i )
;
v3 = (unsigned int)(int)pow(2.0, (double)i);
v4 = *v1;
printf("\ncurrent block size : %d size_wanted: %d\n", (unsigned int)*v1, v3);
if ( (int)v3 <= v4 )
goto LABEL_12;
v5 = 0;
do
{
v6 = v1;
v1 = (int *)((char *)v1 + v1[1]);
++v5;
}
while ( (int)v3 > *v1 );
v7 = (int)v3;
if ( v5 )
{
while ( !(unsigned int)perfect_fit_check((int)v3, v1) )
split(v1);
v8 = v1[1];
fixed_allocate(v7, (__int64)v1);
v6[1] += v8;
}
else
{
LABEL_12:
puts("\nTHIS SHOULDN'T PRINT twice ");
while ( !(unsigned int)perfect_fit_check((int)v3, v1) )
split(v1);
free_list = (__int64)v1 + v1[1];
fixed_allocate((int)v3, (__int64)v1);
}
return v1;
}

canonical_decompiled_code:
int *__fastcall func3(int a1)
{
int *v1; // rbx
int i; // ebp
__int64 v3; // rbp
int v4; // er12
int v5; // eax
int *v6; // r12
__int64 v7; // r13
int v8; // ebp

if ( !heap_begin )
heap_begin = (__int64)mmap(0LL, 0x100000uLL, 3, 34, -1, 0LL);
if ( !free_list )
{
free_list = heap_begin;
*(_DWORD *)heap_begin = 0x100000;
*(_DWORD *)(free_list + 4) = 0;
}
v1 = (int *)free_list;
for ( i = 0; (int)pow(2.0, (double)i) < (unsigned __int64)(a1 + 8); ++i )
;
v3 = (unsigned int)(int)pow(2.0, (double)i);
v4 = *v1;
printf("\ncurrent block size : %d size_wanted: %d\n", (unsigned int)*v1, v3);
if ( (int)v3 <= v4 )
goto LABEL_12;
v5 = 0;
do
{
v6 = v1;
v1 = (int *)((char *)v1 + v1[1]);
++v5;
}
while ( (int)v3 > *v1 );
v7 = (int)v3;
if ( v5 )
{
while ( !(unsigned int)func0((int)v3, v1) )
func2(v1);
v8 = v1[1];
func1(v7, (__int64)v1);
v6[1] += v8;
}
else
{
LABEL_12:
puts("\nTHIS SHOULDN'T PRINT twice ");
while ( !(unsigned int)func0((int)v3, v1) )
func2(v1);
free_list = (__int64)v1 + v1[1];
func1((int)v3, (__int64)v1);
}
return v1;
}

original_code:
void *the_malloc(size_t request_size) {
    if (!heap_begin) {
        heap_begin = mmap(((void *)0), HEAPSIZE, 0x1|0x2, 0x20|0x02, -1, 0);
    }
    if (free_list==((void *)0)){
      free_list = heap_begin;
      *((uint32_t*) free_list) = 1024*1024;
      *((uint32_t*)free_list+1) = 0;
    }
    uint32_t * free_ptr = (uint32_t *)free_list;
    int size_wanted;
    request_size += 8;
    request_size = (int ) request_size;
    int power = 0;
    while ( (int) pow(2,power) < (request_size )){
      power +=1 ;
    }
    size_wanted = (int ) pow(2, power);
    int current_block_size = (int) *(free_ptr);
    int current_next = (int) *((free_ptr)+1);
    printf("\ncurrent block size : %d size_wanted: %d\n", current_block_size, size_wanted);
    int old_next ;
    int old_block_size;
    uint32_t * ptr_to_old = free_ptr;
    int trial = 0;
    while ( current_block_size < (int) size_wanted){
      old_block_size = (int) *(free_ptr );
      old_next = (int) *((free_ptr)+1);
      ptr_to_old = free_ptr ;
      free_ptr = (uint32_t *)(( uint8_t *)free_ptr + old_next );
      current_block_size = (int) *(free_ptr );
      current_next = (int) *((free_ptr)+1);
      trial += 1;
    }
    if (trial ==0){
      printf("\nTHIS SHOULDN'T PRINT twice \n");
      while (perfect_fit_check( ((size_t)size_wanted), ((uint8_t *)free_ptr ))==0){
  split((uint8_t *)free_ptr);
       }
      uint8_t * for_alloc = (uint8_t *)free_ptr;
      int next_leap_to_free_block = (int) *((free_ptr)+1);
     free_ptr = (uint32_t *)(( uint8_t *) free_ptr + next_leap_to_free_block);
     free_list = (void *) free_ptr ;
     fixed_allocate( (size_t)size_wanted, for_alloc );
     return (void *) for_alloc;
    }
    else{
      while (perfect_fit_check( ((size_t)size_wanted), ((uint8_t *)free_ptr ))==0){
       split((uint8_t *)free_ptr);
     }
   int next_leap_to_free_block = *(free_ptr +1);
   fixed_allocate( (size_t)size_wanted, (uint8_t *)free_ptr );
   old_next =(uint32_t) *((uint32_t *)ptr_to_old +1 );
   old_next += next_leap_to_free_block;
   *((uint32_t *)ptr_to_old+1) = (uint32_t ) old_next ;
    }
    return (void *) free_ptr ;
}

canonical_original_code:
void *the_malloc(unsigned long request_size) {
    if (!heap_begin) {
        heap_begin = mmap(((void *)0), HEAPSIZE, 0x1|0x2, 0x20|0x02, -1, 0);
    }
    if (free_list==((void *)0)){
      free_list = heap_begin;
      *((unsigned int *) free_list) = 1024*1024;
      *((unsigned int *)free_list+1) = 0;
    }
    unsigned int *free_ptr = (uint32_t *)free_list;
    int size_wanted;
    request_size += 8;
    request_size = (int ) request_size;
    int power = 0;
    while ( (int) pow(2,power) < (request_size )){
      power +=1 ;
    }
    size_wanted = (int ) pow(2, power);
    int current_block_size = (int) *(free_ptr);
    int current_next = (int) *((free_ptr)+1);
    printf("\ncurrent block size : %d size_wanted: %d\n", current_block_size, size_wanted);
    int old_next;
    int old_block_size;
    unsigned int *ptr_to_old = free_ptr;
    int trial = 0;
    while ( current_block_size < (int) size_wanted){
      old_block_size = (int) *(free_ptr );
      old_next = (int) *((free_ptr)+1);
      ptr_to_old = free_ptr ;
      free_ptr = (unsigned int *)(( unsigned char *)free_ptr + old_next );
      current_block_size = (int) *(free_ptr );
      current_next = (int) *((free_ptr)+1);
      trial += 1;
    }
    if (trial ==0){
      printf("\nTHIS SHOULDN'T PRINT twice \n");
      while (perfect_fit_check( ((unsigned long)size_wanted), ((unsigned char *)free_ptr ))==0){
  split((unsigned char *)free_ptr);
       }
      unsigned char *for_alloc = (uint8_t *)free_ptr;
      int next_leap_to_free_block = (int) *((free_ptr)+1);
     free_ptr = (unsigned int *)(( unsigned char *) free_ptr + next_leap_to_free_block);
     free_list = (void *) free_ptr ;
     fixed_allocate( (unsigned long)size_wanted, for_alloc );
     return (void *) for_alloc;
    }
    else{
      while (perfect_fit_check( ((unsigned long)size_wanted), ((unsigned char *)free_ptr ))==0){
       split((unsigned char *)free_ptr);
     }
   int next_leap_to_free_block = *(free_ptr +1);
   fixed_allocate( (unsigned long)size_wanted, (unsigned char *)free_ptr );
   old_next =(unsigned int) *((unsigned int *)ptr_to_old +1 );
   old_next += next_leap_to_free_block;
   *((unsigned int *)ptr_to_old+1) = (unsigned int ) old_next ;
    }
    return (void *) free_ptr ;
}

variable_types: power int

variable_types: trial int

return_type: void *


decompiled_code:
int __fastcall the_free(unsigned __int64 a1)
{
unsigned __int64 v1; // rbp
int result; // eax
unsigned __int64 v3; // rax

result = puts("\nNOOOOOOOOOO");
if ( a1 )
{
v3 = free_list;
if ( (int)a1 <= (int)free_list )
{
puts("\n OHHHHHHHHHHHHHH");
result = free_list - a1;
*(_DWORD *)(a1 + 4) = free_list - a1;
free_list = a1;
}
else
{
if ( free_list < a1 )
{
do
{
v1 = v3;
v3 += *(int *)(v3 + 4);
}
while ( a1 > v3 );
}
*(_DWORD *)(v1 + 4) = a1 - v1;
result = v3 - a1;
*(_DWORD *)(a1 + 4) += result;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int64 a1)
{
unsigned __int64 v1; // rbp
int result; // eax
unsigned __int64 v3; // rax

result = puts("\nNOOOOOOOOOO");
if ( a1 )
{
v3 = free_list;
if ( (int)a1 <= (int)free_list )
{
puts("\n OHHHHHHHHHHHHHH");
result = free_list - a1;
*(_DWORD *)(a1 + 4) = free_list - a1;
free_list = a1;
}
else
{
if ( free_list < a1 )
{
do
{
v1 = v3;
v3 += *(int *)(v3 + 4);
}
while ( a1 > v3 );
}
*(_DWORD *)(v1 + 4) = a1 - v1;
result = v3 - a1;
*(_DWORD *)(a1 + 4) += result;
}
}
return result;
}

original_code:
void the_free(void *freeblock) {
  uint32_t *itr = heap_begin;
  printf("\nNOOOOOOOOOO\n");
  if (freeblock == ((void *)0)){
    return;
  }
  else{
    if ((int)freeblock <= (int)free_list){
      printf("\n OHHHHHHHHHHHHHH\n");
      *(((uint32_t *)freeblock) + 1 ) = (int )((uint8_t *)free_list - (uint8_t *)freeblock);
      free_list = freeblock ;
      return;
    }
    else{
      uint32_t * tmp = free_list;
      uint32_t * before ;
      uint32_t * after ;
      int jump_by ;
      while (tmp < (uint32_t *)freeblock ){
 before = tmp ;
 jump_by = (int)*( tmp +1);
 tmp = (uint32_t *) (((uint8_t *)tmp) + jump_by );
 after = tmp ;
      }
      *(before +1 ) = (int)((uint8_t *)freeblock - (uint8_t *)before);
      *(((uint32_t *)freeblock) + 1 ) += (int)((uint8_t *)after - (uint8_t *)freeblock);
      return;
   }
  }
}

canonical_original_code:
void the_free(void *freeblock) {
  unsigned int *itr = heap_begin;
  printf("\nNOOOOOOOOOO\n");
  if (freeblock == ((void *)0)){
    return;
  }
  else{
    if ((int)freeblock <= (int)free_list){
      printf("\n OHHHHHHHHHHHHHH\n");
      *(((unsigned int *)freeblock) + 1 ) = (int )((unsigned char *)free_list - (unsigned char *)freeblock);
      free_list = freeblock ;
      return;
    }
    else{
      unsigned int *tmp = free_list;
      unsigned int *before;
      unsigned int *after;
      int jump_by;
      while (tmp < (unsigned int *)freeblock ){
 before = tmp ;
 jump_by = (int)*( tmp +1);
 tmp = (unsigned int *) (((unsigned char *)tmp) + jump_by );
 after = tmp ;
      }
      *(before +1 ) = (int)((unsigned char *)freeblock - (unsigned char *)before);
      *(((unsigned int *)freeblock) + 1 ) += (int)((unsigned char *)after - (unsigned char *)freeblock);
      return;
   }
  }
}

variable_types:
freeblock
void *

variable_types:
itr
unsigned int *

variable_types:
tmp
unsigned int *

variable_types:
before
unsigned int *

variable_types:
after
unsigned int *


decompiled_code:
int dump_memory_map()
{
unsigned int *v0; // rbp
int v1; // er12
unsigned int v2; // ebx
__int64 v3; // rdx
const char *v4; // rcx
int result; // eax

v0 = (unsigned int *)heap_begin;
v1 = 0;
do
{
v2 = *v0;
v3 = v0[1];
v4 = "free";
if ( !(_DWORD)v3 )
v4 = "allocated";
result = printf("\nBlock size : %d, offset %d, %s, %d \n", v2, v3, v4, (unsigned int)v0);
v1 += v2;
v0 = (unsigned int *)((char *)v0 + (int)v2);
}
while ( v1 <= 0xFFFFF );
return result;
}

canonical_decompiled_code:
int func5()
{
unsigned int *v0; // rbp
int v1; // er12
unsigned int v2; // ebx
__int64 v3; // rdx
const char *v4; // rcx
int result; // eax

v0 = (unsigned int *)heap_begin;
v1 = 0;
do
{
v2 = *v0;
v3 = v0[1];
v4 = "free";
if ( !(_DWORD)v3 )
v4 = "allocated";
result = printf("\nBlock size : %d, offset %d, %s, %d \n", v2, v3, v4, (unsigned int)v0);
v1 += v2;
v0 = (unsigned int *)((char *)v0 + (int)v2);
}
while ( v1 <= 0xFFFFF );
return result;
}

original_code:
void dump_memory_map(void ) {
  int place = 0;
  uint32_t * tmp = (uint32_t *) heap_begin;
  while(place < (int) pow(2,20) ){
    int size = (int) *tmp;
    int offset = (int) *((uint32_t *)tmp + 1);
    char* state;
    if (offset == 0){state = "allocated";}
    else{state = "free";}
    printf("\nBlock size : %d, offset %d, %s, %d \n", size, offset,state, (int) tmp);
    place += size;
    tmp = (uint32_t *)((uint8_t *) tmp + size );
      }
}

canonical_original_code:
void dump_memory_map() {
  int place = 0;
  unsigned int *tmp = (uint32_t *) heap_begin;
  while(place < (int) pow(2,20) ){
    int size = (int) *tmp;
    int offset = (int) *((uint32_t *)tmp + 1);
    char *state;
    if (offset == 0){state = "allocated";}
    else{state = "free";}
    printf("\nBlock size : %d, offset %d, %s, %d \n", size, offset,state, (int) tmp);
    place += size;
    tmp = (unsigned int *)((unsigned char *) tmp + size );
      }
}

variable_types: place int

variable_types: size int

variable_types: offset int

variable_types:
state
char *


main

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

v3 = the_malloc(50);
v4 = the_malloc(100);
the_malloc(51);
the_free((unsigned __int64)v3);
dump_memory_map();
the_free((unsigned __int64)v4);
dump_memory_map();
return 0;
}

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

v3 = func3(50);
v4 = func3(100);
func3(51);
func4((unsigned __int64)v3);
func5();
func4((unsigned __int64)v4);
func5();
return 0;
}

original_code:
int main(){
  void *m1 = the_malloc(50);
  void *m2 = the_malloc(100);
  void * m3 = the_malloc(51);
    the_free(m1);
  dump_memory_map();
  the_free(m2);
  dump_memory_map();
  return 0;
}

canonical_original_code:
int main(){
  void *m1 = the_malloc(50);
  void *m2 = the_malloc(100);
  void *m3 = the_malloc(51);
    the_free(m1);
  dump_memory_map();
  the_free(m2);
  dump_memory_map();
  return 0;
}


decompiled_code:
void __fastcall free_tri_matrix(void *ptr, int a2, int a3)
{
void **v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx

if ( a2 > 0 )
{
v4 = (void **)ptr;
v5 = 8LL * (unsigned int)(a3 - 1) + 8;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
free(*(void **)((char *)*v4 + v6));
*(_QWORD *)((char *)*v4 + v6) = 0LL;
v6 += 8LL;
}
while ( v6 != v5 );
}
free(*v4);
*v4++ = 0LL;
}
while ( v4 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, int a2, int a3)
{
void **v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx

if ( a2 > 0 )
{
v4 = (void **)ptr;
v5 = 8LL * (unsigned int)(a3 - 1) + 8;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
free(*(void **)((char *)*v4 + v6));
*(_QWORD *)((char *)*v4 + v6) = 0LL;
v6 += 8LL;
}
while ( v6 != v5 );
}
free(*v4);
*v4++ = 0LL;
}
while ( v4 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void free_tri_matrix(char ***M, int x, int y) {
    int i, j;
    for (i = 0; i < x; i++) {
        for (j = 0; j < y; j++) {
            free(M[i][j]);
            M[i][j] = ((void *)0);
        }
        free(M[i]);
        M[i] = ((void *)0);
    }
    free(M);
    M = ((void *)0);
}

canonical_original_code:
void free_tri_matrix(char ***M, int x, int y) {
    int i; int j;
    for (i = 0; i < x; i++) {
        for (j = 0; j < y; j++) {
            free(M[i][j]);
            M[i][j] = ((void *)0);
        }
        free(M[i]);
        M[i] = ((void *)0);
    }
    free(M);
    M = ((void *)0);
}

variable_types:
M
char ***

variable_types: x int

variable_types: y int

variable_types: i int

variable_types: j int


repo: thlorenz/multi-tap-example

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

v3 = add(2, 3);
printf("%d + %d = %d\n", 2LL, 3LL, v3);
v4 = mult(2, 3);
printf("%d * %d = %d\n", 2LL, 3LL, v4);
return 0;
}

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

v3 = func8(2, 3);
printf("%d + %d = %d\n", 2LL, 3LL, v3);
v4 = func7(2, 3);
printf("%d * %d = %d\n", 2LL, 3LL, v4);
return 0;
}

original_code:
int main(void) {
  int a = 2;
  int b = 3;
  printf("%d + %d = %d\n", a, b, add(a, b));
  printf("%d * %d = %d\n", a, b, mult(a, b));
  return 0;
}

canonical_original_code:
int main() {
  int a = 2;
  int b = 3;
  printf("%d + %d = %d\n", a, b, add(a, b));
  printf("%d * %d = %d\n", a, b, mult(a, b));
  return 0;
}

variable_types: a int

variable_types: b int


DirectoryCheck

decompiled_code:
__int64 __fastcall DirectoryCheck(char *a1, char *a2)
{
unsigned int v4; // er12
char v5; // dl
int v6; // esi
int v7; // edi
int v8; // er8
unsigned int v9; // eax
char v10; // cl
unsigned int v11; // ebx
__int64 result; // rax
char v13[64]; // [rsp+0h] [rbp-E8h] BYREF
char src[64]; // [rsp+40h] [rbp-A8h] BYREF
char dest[104]; // [rsp+80h] [rbp-68h] BYREF

if ( SS5SocksOpt[49] )
v4 = pthread_self();
else
v4 = getpid();
dest[0] = 0;
src[0] = 0;
v13[0] = 0;
v5 = *a2;
if ( *a2 )
{
v6 = 0;
v7 = 0;
v8 = 0;
v9 = 0;
while ( 1 )
{
if ( v5 == 92 || v5 == 64 )
{
dest[v9] = 0;
++v6;
++v9;
v7 = 1;
}
else if ( !v7 )
{
v10 = a2[v9];
dest[v9] = v10;
src[v9] = v10;
src[v9 + 1] = 0;
goto LABEL_8;
}
src[v8] = a2[v9];
src[++v8] = 0;
LABEL_8:
v5 = a2[++v9];
if ( v9 > 0x3E || !v5 )
{
if ( v6 )
{
strncpy(v13, src, 0x40uLL);
strncpy(src, dest, 0x40uLL);
strncpy(dest, v13, 0x40uLL);
}
break;
}
}
}
v11 = 0;
while ( NLdapStore > v11 )
{
if ( !SS5SocksOpt[42]
|| !memcmp(&S5Ldap[342 * v11 + 326], "DEF", 3uLL)
|| !strncasecmp(&S5Ldap[342 * v11 + 326], dest, 0x3FuLL) )
{
result = DirectoryQuery(v4, a1, src, v11++);
if ( (_DWORD)result )
return result;
}
else
{
++v11;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, char *a2)
{
unsigned int v4; // er12
char v5; // dl
int v6; // esi
int v7; // edi
int v8; // er8
unsigned int v9; // eax
char v10; // cl
unsigned int v11; // ebx
__int64 result; // rax
char v13[64]; // [rsp+0h] [rbp-E8h] BYREF
char src[64]; // [rsp+40h] [rbp-A8h] BYREF
char dest[104]; // [rsp+80h] [rbp-68h] BYREF

if ( SS5SocksOpt[49] )
v4 = pthread_self();
else
v4 = getpid();
dest[0] = 0;
src[0] = 0;
v13[0] = 0;
v5 = *a2;
if ( *a2 )
{
v6 = 0;
v7 = 0;
v8 = 0;
v9 = 0;
while ( 1 )
{
if ( v5 == 92 || v5 == 64 )
{
dest[v9] = 0;
++v6;
++v9;
v7 = 1;
}
else if ( !v7 )
{
v10 = a2[v9];
dest[v9] = v10;
src[v9] = v10;
src[v9 + 1] = 0;
goto LABEL_8;
}
src[v8] = a2[v9];
src[++v8] = 0;
LABEL_8:
v5 = a2[++v9];
if ( v9 > 0x3E || !v5 )
{
if ( v6 )
{
strncpy(v13, src, 0x40uLL);
strncpy(src, dest, 0x40uLL);
strncpy(dest, v13, 0x40uLL);
}
break;
}
}
}
v11 = 0;
while ( NLdapStore > v11 )
{
if ( !SS5SocksOpt[42]
|| !memcmp(&S5Ldap[342 * v11 + 326], "DEF", 3uLL)
|| !strncasecmp(&S5Ldap[342 * v11 + 326], dest, 0x3FuLL) )
{
result = func0(v4, a1, src, v11++);
if ( (_DWORD)result )
return result;
}
else
{
++v11;
}
}
return 0LL;
}

original_code:
UINT DirectoryCheck( char *group, char *user )
{
  register UINT idx1;
  register UINT idx2;
  char ntbdomain[64];
  char ntbuser[64];
  char swap[64];
  UINT count;
  int err = ERR;
  int pos = 0,
      gss = 0;
  pid_t pid;
  if( ( !SS5SocksOpt.IsThreaded ) )
    pid = getpid();
  else
    pid = (UINT)pthread_self();
  ntbdomain[0]='\0';
  ntbuser[0] ='\0';
  swap[0] ='\0';
  for(idx1 = 0, idx2 = 0; user[idx1] && (idx1 < (sizeof(ntbuser) - 1)); idx1++ ) {
    if( user[idx1] == '\\' || user[idx1] == '@' ) {
      ntbdomain[idx1] = '\0';
      pos = 1;
      gss++;
      idx1++;
    }
    if( pos == 0 ) {
      ntbdomain[idx1] = user[idx1];
      ntbuser[idx1] = user[idx1];
      ntbuser[idx1 + 1] = '\0';
    }
    else if( pos == 1 ) {
      ntbuser[idx2++] = user[idx1];
      ntbuser[idx2] = '\0';
    }
  }
  if( gss ) {
    strncpy(swap,ntbuser,sizeof(swap));
    strncpy(ntbuser,ntbdomain,sizeof(ntbuser));
    strncpy(ntbdomain,swap,sizeof(ntbdomain));
  }
  for( count = 0; (err == ERR) && (count < NLdapStore); count++ ) {
    if( SS5SocksOpt.LdapNetbiosDomain ) {
      if( !strncmp(S5Ldap[count].NtbDomain,"DEF",sizeof("DEF") -1) ) {
        err = DirectoryQuery(pid, group, ntbuser, count);
      }
      else if( !strncasecmp(S5Ldap[count].NtbDomain,ntbdomain,sizeof(ntbdomain) -1) )
        err = DirectoryQuery(pid, group, ntbuser, count);
    }
    else {
      err = DirectoryQuery( pid, group, ntbuser, count);
    }
  }
  return err;
}

canonical_original_code:
unsigned int DirectoryCheck(char *group, char *user)
{
  register unsigned int idx1;
  register unsigned int idx2;
  char ntbdomain[64];
  char ntbuser[64];
  char swap[64];
  unsigned int count;
  int err = ERR;
  int pos = 0; int gss = 0;
  int pid;
  if( ( !SS5SocksOpt.IsThreaded ) )
    pid = getpid();
  else
    pid = (unsigned int)pthread_self();
  ntbdomain[0]='\0';
  ntbuser[0] ='\0';
  swap[0] ='\0';
  for(idx1 = 0, idx2 = 0; user[idx1] && (idx1 < (sizeof(ntbuser) - 1)); idx1++ ) {
    if( user[idx1] == '\\' || user[idx1] == '@' ) {
      ntbdomain[idx1] = '\0';
      pos = 1;
      gss++;
      idx1++;
    }
    if( pos == 0 ) {
      ntbdomain[idx1] = user[idx1];
      ntbuser[idx1] = user[idx1];
      ntbuser[idx1 + 1] = '\0';
    }
    else if( pos == 1 ) {
      ntbuser[idx2++] = user[idx1];
      ntbuser[idx2] = '\0';
    }
  }
  if( gss ) {
    strncpy(swap,ntbuser,sizeof(swap));
    strncpy(ntbuser,ntbdomain,sizeof(ntbuser));
    strncpy(ntbdomain,swap,sizeof(ntbdomain));
  }
  for( count = 0; (err == ERR) && (count < NLdapStore); count++ ) {
    if( SS5SocksOpt.LdapNetbiosDomain ) {
      if( !strncmp(S5Ldap[count].NtbDomain,"DEF",sizeof("DEF") -1) ) {
        err = DirectoryQuery(pid, group, ntbuser, count);
      }
      else if( !strncasecmp(S5Ldap[count].NtbDomain,ntbdomain,sizeof(ntbdomain) -1) )
        err = DirectoryQuery(pid, group, ntbuser, count);
    }
    else {
      err = DirectoryQuery( pid, group, ntbuser, count);
    }
  }
  return err;
}

variable_types:
group
char *

variable_types:
user
char *

variable_types:
ntbdomain
char [64]

variable_types:
ntbuser
char [64]

variable_types:
swap
char [64]

variable_types:
count
unsigned int

variable_types: err int

variable_types: pos int

variable_types: gss int

variable_types: pid int

return_type: unsigned int


inportb

repo: tyranid/saturndebug

decompiled_code:
__int64 __fastcall inportb(unsigned __int16 a1)
{
__int64 result; // rax

LOBYTE(result) = __inbyte(a1);
return (unsigned __int8)result;
}

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

LOBYTE(result) = __inbyte(a1);
return (unsigned __int8)result;
}

original_code:
int inportb(int port)
{
   unsigned char value;
  __asm__ volatile ("inb %1,%0"
                    : "=a" (value)
                    : "d" ((unsigned short) port));
   return value;
}

variable_types: port int

variable_types:
value
unsigned char


outportb

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

result = a2;
__outbyte(a1, a2);
return result;
}

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

result = a2;
__outbyte(a1, a2);
return result;
}

original_code:
void outportb(unsigned short int port, unsigned char val)
{
  __asm__ volatile (
                    "outb %0,%1\n"
                    :
                    : "a" (val), "d" (port)
                    );
}

canonical_original_code:
void outportb(unsigned short port, unsigned char val)
{
  __asm__ volatile (
                    "outb %0,%1\n"
                    :
                    : "a" (val), "d" (port)
                    );
}

variable_types:
port
unsigned short

variable_types:
val
unsigned char


repo: udoprog/cr

decompiled_code:
_DWORD *string_new()
{
return string_new_s(16);
}

canonical_decompiled_code:
_DWORD *func0()
{
return string_new_s(16);
}

original_code:
string* string_new() {
  return string_new_s(16);
}

canonical_original_code:
struct string *string_new() {
  return string_new_s(16);
}

return_type: struct string { unsigned char *base; unsigned int size; int _bss; int _bsi; } *


decompiled_code:
void __fastcall string_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void string_free(string* s) {
  free(s->base);
  free(s);
}

canonical_original_code:
void string_free(struct string *s) {
  free(s->base);
  free(s);
}

variable_types: struct string { unsigned char *base; unsigned int size; int _bss; int _bsi; } *


decompiled_code:
__int64 __fastcall string_inc(__int64 a1)
{
int v1; // ebp
void *v2; // rax

v1 = 2 * *(_DWORD *)(a1 + 12);
v2 = realloc(*(void **)a1, v1);
if ( v2 )
{
*(_QWORD *)a1 = v2;
*(_DWORD *)(a1 + 12) = v1;
++*(_DWORD *)(a1 + 16);
}
else
{
v1 = 0;
}
return (unsigned int)v1;
}

original_code:
int string_inc(string* s)
{
  int tmp_base_size;
  unsigned char* tmp_base;
  tmp_base_size = s->_bss * 2;
  tmp_base = realloc(s->base, tmp_base_size);
  if (tmp_base == ((void *)0)) {
    return 0;
  }
  s->base = tmp_base;
  s->_bss = tmp_base_size;
  s->_bsi += 1;
  return tmp_base_size;
}

canonical_original_code:
int string_inc(struct string *s)
{
  int tmp_base_size;
  unsigned char *tmp_base;
  tmp_base_size = s->_bss * 2;
  tmp_base = realloc(s->base, tmp_base_size);
  if (tmp_base == ((void *)0)) {
    return 0;
  }
  s->base = tmp_base;
  s->_bss = tmp_base_size;
  s->_bsi += 1;
  return tmp_base_size;
}

user_defined_types: struct string { unsigned char *base; unsigned int size; int _bss; int _bsi; }


original_code:
int string_resize(string* s, int size)
{
  int tmp_base_size;
  unsigned char* tmp_base;
  if (size < s->_bss) {
    return 0;
  }
  tmp_base_size = s->_bss * 2;
  s->_bsi += 1;
  while (tmp_base_size < size) {
    tmp_base_size = tmp_base_size * 2;
    s->_bsi += 1;
  }
  tmp_base = realloc(s->base, tmp_base_size);
  if (tmp_base == ((void *)0)) {
    return 0;
  }
  s->base = tmp_base;
  s->_bss = tmp_base_size;
  return tmp_base_size;
}

canonical_original_code:
int string_resize(struct string *s, int size)
{
  int tmp_base_size;
  unsigned char *tmp_base;
  if (size < s->_bss) {
    return 0;
  }
  tmp_base_size = s->_bss * 2;
  s->_bsi += 1;
  while (tmp_base_size < size) {
    tmp_base_size = tmp_base_size * 2;
    s->_bsi += 1;
  }
  tmp_base = realloc(s->base, tmp_base_size);
  if (tmp_base == ((void *)0)) {
    return 0;
  }
  s->base = tmp_base;
  s->_bss = tmp_base_size;
  return tmp_base_size;
}

variable_types: size int


decompiled_code:
int __fastcall string_ncmp(const char **a1, const char *a2, int a3)
{
return strncmp(*a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func4(const char **a1, const char *a2, int a3)
{
return strncmp(*a1, a2, a3);
}

original_code:
int string_ncmp(string* s, const unsigned char* other, int n)
{
  return strncmp((const char*)s->base, (const char *)other, n);
}

canonical_original_code:
int string_ncmp(struct string *s, unsigned char *other, int n)
{
  return strncmp((char *)s->base, (char *)other, n);
}

variable_types:
other
unsigned char *

variable_types: n int


decompiled_code:
__int64 __fastcall string_set_offset(__int64 a1, const void *a2, int a3, int a4)
{
int v6; // ebp
__int64 result; // rax

v6 = a3 + a4;
while ( v6 > *(_DWORD *)(a1 + 12) )
{
result = string_inc(a1);
if ( !(_DWORD)result )
return result;
}
memcpy((void *)(*(_QWORD *)a1 + a3), a2, a4);
*(_DWORD *)(a1 + 8) = v6;
memset((void *)(*(_QWORD *)a1 + a4 + (__int64)a3), 0, *(_DWORD *)(a1 + 12) - a3 - a4);
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const void *a2, int a3, int a4)
{
int v6; // ebp
__int64 result; // rax

v6 = a3 + a4;
while ( v6 > *(_DWORD *)(a1 + 12) )
{
result = func2(a1);
if ( !(_DWORD)result )
return result;
}
memcpy((void *)(*(_QWORD *)a1 + a3), a2, a4);
*(_DWORD *)(a1 + 8) = v6;
memset((void *)(*(_QWORD *)a1 + a4 + (__int64)a3), 0, *(_DWORD *)(a1 + 12) - a3 - a4);
return *(unsigned int *)(a1 + 8);
}

original_code:
int string_set_offset(string* s, const unsigned char* source, int offset, int size)
{
  while (offset + size > s->_bss) {
    if (string_inc(s) == 0) {
      return 0;
    }
  }
  memcpy(s->base + offset, source, size);
  s->size = offset + size;
  memset(s->base + offset + size, 0x00, s->_bss - offset - size);
  return s->size;
}

canonical_original_code:
int string_set_offset(struct string *s, unsigned char *source, int offset, int size)
{
  while (offset + size > s->_bss) {
    if (string_inc(s) == 0) {
      return 0;
    }
  }
  memcpy(s->base + offset, source, size);
  s->size = offset + size;
  memset(s->base + offset + size, 0x00, s->_bss - offset - size);
  return s->size;
}

variable_types:
source
unsigned char *

variable_types: offset int


decompiled_code:
__int64 __fastcall string_set(__int64 a1, const void *a2, int a3)
{
return string_set_offset(a1, a2, 0, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2, int a3)
{
return func5(a1, a2, 0, a3);
}

original_code:
int string_set(string* s, const unsigned char* source, int size)
{
  return string_set_offset(s, source, 0, size);
}

canonical_original_code:
int string_set(struct string *s, unsigned char *source, int size)
{
  return string_set_offset(s, source, 0, size);
}


decompiled_code:
__int64 __fastcall string_append(__int64 a1, const void *a2, int a3)
{
return string_set_offset(a1, a2, *(_DWORD *)(a1 + 8), a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const void *a2, int a3)
{
return func5(a1, a2, *(_DWORD *)(a1 + 8), a3);
}

original_code:
int string_append(string* s, const unsigned char* source, int size)
{
  return string_set_offset(s, source, s->size, size);
}

canonical_original_code:
int string_append(struct string *s, unsigned char *source, int size)
{
  return string_set_offset(s, source, s->size, size);
}


decompiled_code:
int gpio_init()
{
int v0; // eax
int v1; // ebx
void *v2; // rbp
int result; // eax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
perror("Opening /dev/mem");
exit(1);
}
v1 = v0;
v2 = mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
if ( v2 == (void *)-1LL )
{
perror("mmap(/dev/mem)");
exit(1);
}
result = close(v1);
ugpio = (__int64)v2;
return result;
}

canonical_decompiled_code:
int func13()
{
int v0; // eax
int v1; // ebx
void *v2; // rbp
int result; // eax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
perror("Opening /dev/mem");
exit(1);
}
v1 = v0;
v2 = mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
if ( v2 == (void *)-1LL )
{
perror("mmap(/dev/mem)");
exit(1);
}
result = close(v1);
ugpio = (__int64)v2;
return result;
}

original_code:
static void
gpio_init() {
    int fd;
    char *map;
    fd = open("/dev/mem",02|04010000);
    if ( fd < 0 ) {
        perror("Opening /dev/mem");
        exit(1);
    }
    map = (char *) mmap(
        ((void *)0),
        (4*1024),
        0x1|0x2,
        0x01,
        fd,
        (0x20000000 + 0x200000)
    );
    if ( (long)map == -1L ) {
        perror("mmap(/dev/mem)");
        exit(1);
    }
    close(fd);
    ugpio = (volatile unsigned *)map;
}

canonical_original_code:
static void gpio_init() {
    int fd;
    char *map;
    fd = open("/dev/mem",02|04010000);
    if ( fd < 0 ) {
        perror("Opening /dev/mem");
        exit(1);
    }
    map = (char *) mmap(
        ((void *)0),
        (4*1024),
        0x1|0x2,
        0x01,
        fd,
        (0x20000000 + 0x200000)
    );
    if ( (long)map == -1L ) {
        perror("mmap(/dev/mem)");
        exit(1);
    }
    close(fd);
    ugpio = (unsigned int *)map;
}

variable_types: fd int

variable_types:
map
char *


repo: wfr/clblake

decompiled_code:
int __fastcall ocl_strerror(unsigned int a1, char *a2, size_t a3)
{
const char *v3; // r8

switch ( a1 )
{
case 0xFFFFFFC2:
v3 = "Invalid mip-map level";
break;
case 0xFFFFFFC3:
v3 = "Invalid buffer size";
break;
case 0xFFFFFFC4:
v3 = "Invalid OpenGL object";
break;
case 0xFFFFFFC5:
v3 = "Invalid operation";
break;
case 0xFFFFFFC6:
v3 = "Invalid event";
break;
case 0xFFFFFFC7:
v3 = "Invalid event wait list";
break;
case 0xFFFFFFC8:
v3 = "Invalid global offset";
break;
case 0xFFFFFFC9:
v3 = "Invalid work item size";
break;
case 0xFFFFFFCA:
v3 = "Invalid work group size";
break;
case 0xFFFFFFCB:
v3 = "Invalid work dimension";
break;
case 0xFFFFFFCC:
v3 = "Invalid kernel arguments";
break;
case 0xFFFFFFCD:
v3 = "Invalid argument size";
break;
case 0xFFFFFFCE:
v3 = "Invalid argument value";
break;
case 0xFFFFFFCF:
v3 = "Invalid argument index";
break;
case 0xFFFFFFD0:
v3 = "Invalid kernel";
break;
case 0xFFFFFFD1:
v3 = "Invalid kernel definition";
break;
case 0xFFFFFFD2:
v3 = "Invalid kernel name";
break;
case 0xFFFFFFD3:
v3 = "Invalid program executable";
break;
case 0xFFFFFFD4:
v3 = "Invalid program";
break;
case 0xFFFFFFD5:
v3 = "Invalid build options";
break;
case 0xFFFFFFD6:
v3 = "Invalid binary";
break;
case 0xFFFFFFD7:
v3 = "Invalid sampler";
break;
case 0xFFFFFFD8:
v3 = "Invalid image size";
break;
case 0xFFFFFFD9:
v3 = "Invalid image format descriptor";
break;
case 0xFFFFFFDA:
v3 = "Invalid memory object";
break;
case 0xFFFFFFDB:
v3 = "Invalid host pointer";
break;
case 0xFFFFFFDC:
v3 = "Invalid command queue";
break;
case 0xFFFFFFDD:
v3 = "Invalid queue properties";
break;
case 0xFFFFFFDE:
v3 = "Invalid context";
break;
case 0xFFFFFFDF:
v3 = "Invalid device";
break;
case 0xFFFFFFE0:
v3 = "Invalid platform";
break;
case 0xFFFFFFE1:
v3 = "Invalid device type";
break;
case 0xFFFFFFE2:
v3 = "Invalid value";
break;
case 0xFFFFFFF4:
v3 = "Map failure";
break;
case 0xFFFFFFF5:
v3 = "Program build failure";
break;
case 0xFFFFFFF6:
v3 = "Image format not supported";
break;
case 0xFFFFFFF7:
v3 = "Image format mismatch";
break;
case 0xFFFFFFF8:
v3 = "Memory copy overlap";
break;
case 0xFFFFFFF9:
v3 = "Profiling information not available";
break;
case 0xFFFFFFFA:
v3 = "Out of host memory";
break;
case 0xFFFFFFFB:
v3 = "Out of resources";
break;
case 0xFFFFFFFC:
v3 = "Memory object allocation failure";
break;
case 0xFFFFFFFD:
v3 = "Compiler not available";
break;
case 0xFFFFFFFE:
v3 = "Device not available";
break;
case 0xFFFFFFFF:
v3 = "Device not found.";
break;
case 0u:
v3 = "Success!";
break;
default:
v3 = "Unknown";
break;
}
return snprintf(a2, a3, "[%d]: %s", a1, v3);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, char *a2, size_t a3)
{
const char *v3; // r8

switch ( a1 )
{
case 0xFFFFFFC2:
v3 = "Invalid mip-map level";
break;
case 0xFFFFFFC3:
v3 = "Invalid buffer size";
break;
case 0xFFFFFFC4:
v3 = "Invalid OpenGL object";
break;
case 0xFFFFFFC5:
v3 = "Invalid operation";
break;
case 0xFFFFFFC6:
v3 = "Invalid event";
break;
case 0xFFFFFFC7:
v3 = "Invalid event wait list";
break;
case 0xFFFFFFC8:
v3 = "Invalid global offset";
break;
case 0xFFFFFFC9:
v3 = "Invalid work item size";
break;
case 0xFFFFFFCA:
v3 = "Invalid work group size";
break;
case 0xFFFFFFCB:
v3 = "Invalid work dimension";
break;
case 0xFFFFFFCC:
v3 = "Invalid kernel arguments";
break;
case 0xFFFFFFCD:
v3 = "Invalid argument size";
break;
case 0xFFFFFFCE:
v3 = "Invalid argument value";
break;
case 0xFFFFFFCF:
v3 = "Invalid argument index";
break;
case 0xFFFFFFD0:
v3 = "Invalid kernel";
break;
case 0xFFFFFFD1:
v3 = "Invalid kernel definition";
break;
case 0xFFFFFFD2:
v3 = "Invalid kernel name";
break;
case 0xFFFFFFD3:
v3 = "Invalid program executable";
break;
case 0xFFFFFFD4:
v3 = "Invalid program";
break;
case 0xFFFFFFD5:
v3 = "Invalid build options";
break;
case 0xFFFFFFD6:
v3 = "Invalid binary";
break;
case 0xFFFFFFD7:
v3 = "Invalid sampler";
break;
case 0xFFFFFFD8:
v3 = "Invalid image size";
break;
case 0xFFFFFFD9:
v3 = "Invalid image format descriptor";
break;
case 0xFFFFFFDA:
v3 = "Invalid memory object";
break;
case 0xFFFFFFDB:
v3 = "Invalid host pointer";
break;
case 0xFFFFFFDC:
v3 = "Invalid command queue";
break;
case 0xFFFFFFDD:
v3 = "Invalid queue properties";
break;
case 0xFFFFFFDE:
v3 = "Invalid context";
break;
case 0xFFFFFFDF:
v3 = "Invalid device";
break;
case 0xFFFFFFE0:
v3 = "Invalid platform";
break;
case 0xFFFFFFE1:
v3 = "Invalid device type";
break;
case 0xFFFFFFE2:
v3 = "Invalid value";
break;
case 0xFFFFFFF4:
v3 = "Map failure";
break;
case 0xFFFFFFF5:
v3 = "Program build failure";
break;
case 0xFFFFFFF6:
v3 = "Image format not supported";
break;
case 0xFFFFFFF7:
v3 = "Image format mismatch";
break;
case 0xFFFFFFF8:
v3 = "Memory copy overlap";
break;
case 0xFFFFFFF9:
v3 = "Profiling information not available";
break;
case 0xFFFFFFFA:
v3 = "Out of host memory";
break;
case 0xFFFFFFFB:
v3 = "Out of resources";
break;
case 0xFFFFFFFC:
v3 = "Memory object allocation failure";
break;
case 0xFFFFFFFD:
v3 = "Compiler not available";
break;
case 0xFFFFFFFE:
v3 = "Device not available";
break;
case 0xFFFFFFFF:
v3 = "Device not found.";
break;
case 0u:
v3 = "Success!";
break;
default:
v3 = "Unknown";
break;
}
return snprintf(a2, a3, "[%d]: %s", a1, v3);
}

original_code:
void ocl_strerror(cl_int err, char* buf, size_t buflen) {
 const char *msg;
 switch(err) {
  case 0: msg = "Success!"; break;
  case -1: msg = "Device not found."; break;
  case -2: msg = "Device not available"; break;
  case -3: msg = "Compiler not available"; break;
  case -4: msg = "Memory object allocation failure"; break;
  case -5: msg = "Out of resources"; break;
  case -6: msg = "Out of host memory"; break;
  case -7: msg = "Profiling information not available"; break;
  case -8: msg = "Memory copy overlap"; break;
  case -9: msg = "Image format mismatch"; break;
  case -10: msg = "Image format not supported"; break;
  case -11: msg = "Program build failure"; break;
  case -12: msg = "Map failure"; break;
  case -30: msg = "Invalid value"; break;
  case -31: msg = "Invalid device type"; break;
  case -32: msg = "Invalid platform"; break;
  case -33: msg = "Invalid device"; break;
  case -34: msg = "Invalid context"; break;
  case -35: msg = "Invalid queue properties"; break;
  case -36: msg = "Invalid command queue"; break;
  case -37: msg = "Invalid host pointer"; break;
  case -38: msg = "Invalid memory object"; break;
  case -39: msg = "Invalid image format descriptor"; break;
  case -40: msg = "Invalid image size"; break;
  case -41: msg = "Invalid sampler"; break;
  case -42: msg = "Invalid binary"; break;
  case -43: msg = "Invalid build options"; break;
  case -44: msg = "Invalid program"; break;
  case -45: msg = "Invalid program executable"; break;
  case -46: msg = "Invalid kernel name"; break;
  case -47: msg = "Invalid kernel definition"; break;
  case -48: msg = "Invalid kernel"; break;
  case -49: msg = "Invalid argument index"; break;
  case -50: msg = "Invalid argument value"; break;
  case -51: msg = "Invalid argument size"; break;
  case -52: msg = "Invalid kernel arguments"; break;
  case -53: msg = "Invalid work dimension"; break;
  case -54: msg = "Invalid work group size"; break;
  case -55: msg = "Invalid work item size"; break;
  case -56: msg = "Invalid global offset"; break;
  case -57: msg = "Invalid event wait list"; break;
  case -58: msg = "Invalid event"; break;
  case -59: msg = "Invalid operation"; break;
  case -60: msg = "Invalid OpenGL object"; break;
  case -61: msg = "Invalid buffer size"; break;
  case -62: msg = "Invalid mip-map level"; break;
  default: msg = "Unknown"; break;
 }
 snprintf(buf, buflen, "[%d]: %s", err, msg);
}

canonical_original_code:
void ocl_strerror(int err, char *buf, unsigned long buflen) {
 char *msg;
 switch(err) {
  case 0: msg = "Success!"; break;
  case -1: msg = "Device not found."; break;
  case -2: msg = "Device not available"; break;
  case -3: msg = "Compiler not available"; break;
  case -4: msg = "Memory object allocation failure"; break;
  case -5: msg = "Out of resources"; break;
  case -6: msg = "Out of host memory"; break;
  case -7: msg = "Profiling information not available"; break;
  case -8: msg = "Memory copy overlap"; break;
  case -9: msg = "Image format mismatch"; break;
  case -10: msg = "Image format not supported"; break;
  case -11: msg = "Program build failure"; break;
  case -12: msg = "Map failure"; break;
  case -30: msg = "Invalid value"; break;
  case -31: msg = "Invalid device type"; break;
  case -32: msg = "Invalid platform"; break;
  case -33: msg = "Invalid device"; break;
  case -34: msg = "Invalid context"; break;
  case -35: msg = "Invalid queue properties"; break;
  case -36: msg = "Invalid command queue"; break;
  case -37: msg = "Invalid host pointer"; break;
  case -38: msg = "Invalid memory object"; break;
  case -39: msg = "Invalid image format descriptor"; break;
  case -40: msg = "Invalid image size"; break;
  case -41: msg = "Invalid sampler"; break;
  case -42: msg = "Invalid binary"; break;
  case -43: msg = "Invalid build options"; break;
  case -44: msg = "Invalid program"; break;
  case -45: msg = "Invalid program executable"; break;
  case -46: msg = "Invalid kernel name"; break;
  case -47: msg = "Invalid kernel definition"; break;
  case -48: msg = "Invalid kernel"; break;
  case -49: msg = "Invalid argument index"; break;
  case -50: msg = "Invalid argument value"; break;
  case -51: msg = "Invalid argument size"; break;
  case -52: msg = "Invalid kernel arguments"; break;
  case -53: msg = "Invalid work dimension"; break;
  case -54: msg = "Invalid work group size"; break;
  case -55: msg = "Invalid work item size"; break;
  case -56: msg = "Invalid global offset"; break;
  case -57: msg = "Invalid event wait list"; break;
  case -58: msg = "Invalid event"; break;
  case -59: msg = "Invalid operation"; break;
  case -60: msg = "Invalid OpenGL object"; break;
  case -61: msg = "Invalid buffer size"; break;
  case -62: msg = "Invalid mip-map level"; break;
  default: msg = "Unknown"; break;
 }
 snprintf(buf, buflen, "[%d]: %s", err, msg);
}

variable_types:
buf
char *

variable_types:
buflen
unsigned long

variable_types:
msg
char *


goodBye

repo: xenomuta/SIPffer

decompiled_code:
void __noreturn goodBye()
{
fwrite("\x1B[0;37m\n-=[ END OF CAPTURE ]=-\n\n", 1uLL, 0x20uLL, stderr);
pcap_breakloop(sniff);
pcap_freecode(&fp);
pcap_close(sniff);
fprintf(stderr, "%d packets captured\n%d packets shown\n\n", (unsigned int)captured, (unsigned int)shown);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("\x1B[0;37m\n-=[ END OF CAPTURE ]=-\n\n", 1uLL, 0x20uLL, stderr);
pcap_breakloop(sniff);
pcap_freecode(&fp);
pcap_close(sniff);
fprintf(stderr, "%d packets captured\n%d packets shown\n\n", (unsigned int)captured, (unsigned int)shown);
exit(0);
}

original_code:
void goodBye(int sig) {
 fprintf(stderr, "\x1b[0;37m\n-=[ END OF CAPTURE ]=-\n\n");
 pcap_breakloop(sniff);
 pcap_freecode(&fp);
 pcap_close(sniff);
 fprintf(stderr, "%d packets captured\n%d packets shown\n\n", captured, shown);
 _exit(0);
}

variable_types: sig int


getTime

decompiled_code:
char *__fastcall getTime(time_t a1)
{
char *v1; // rbx
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v1 = "n/a";
if ( a1 )
{
timer = a1;
v1 = (char *)malloc(0x1EuLL);
*(_QWORD *)v1 = 0LL;
*((_QWORD *)v1 + 1) = 0LL;
*((_QWORD *)v1 + 2) = 0LL;
*((_DWORD *)v1 + 6) = 0;
*((_WORD *)v1 + 14) = 0;
v3 = localtime(&timer);
strftime(v1, 0x1EuLL, "%Y-%m-%d %T", v3);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(time_t a1)
{
char *v1; // rbx
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v1 = "n/a";
if ( a1 )
{
timer = a1;
v1 = (char *)malloc(0x1EuLL);
*(_QWORD *)v1 = 0LL;
*((_QWORD *)v1 + 1) = 0LL;
*((_QWORD *)v1 + 2) = 0LL;
*((_DWORD *)v1 + 6) = 0;
*((_WORD *)v1 + 14) = 0;
v3 = localtime(&timer);
strftime(v1, 0x1EuLL, "%Y-%m-%d %T", v3);
}
return v1;
}

original_code:
char *getTime(struct timeval cap_tv) {
 char *buff;
 time_t curtime;
 if (!cap_tv.tv_sec) return "n/a";
 curtime=cap_tv.tv_sec;
 buff = (char *)malloc(30); memset(buff, 0, 30);
 strftime(buff, 30, "%Y-%m-%d %T", localtime(&curtime));
 return buff;
}

canonical_original_code:
char *getTime(struct timeval cap_tv) {
 char *buff;
 long curtime;
 if (!cap_tv.tv_sec) return "n/a";
 curtime=cap_tv.tv_sec;
 buff = (char *)malloc(30); memset(buff, 0, 30);
 strftime(buff, 30, "%Y-%m-%d %T", localtime(&curtime));
 return buff;
}

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

variable_types:
buff
char *

variable_types: curtime long


getSIPHeader

decompiled_code:
size_t __fastcall getSIPHeader(const char *a1, const char *a2)
{
char *v2; // rax
const char *v3; // r12
char *v4; // rax
const char *v5; // rbx
char *v6; // rax
size_t v7; // rax

v2 = strdup(a1);
strtok(v2, "\r\n");
v3 = 0LL;
while ( 1 )
{
v4 = strtok(0LL, "\r\n");
v5 = v4;
if ( !v4 )
break;
v6 = strchr(v4, 58);
if ( v6 )
{
*v6 = 0;
v7 = strlen(a2);
if ( !strncasecmp(a2, v5, v7) )
return (size_t)&v5[strlen(v5) + 2];
v3 = v5;
}
}
if ( v3 )
*v3 = 0;
return (size_t)v3;
}

canonical_decompiled_code:
size_t __fastcall func2(const char *a1, const char *a2)
{
char *v2; // rax
const char *v3; // r12
char *v4; // rax
const char *v5; // rbx
char *v6; // rax
size_t v7; // rax

v2 = strdup(a1);
strtok(v2, "\r\n");
v3 = 0LL;
while ( 1 )
{
v4 = strtok(0LL, "\r\n");
v5 = v4;
if ( !v4 )
break;
v6 = strchr(v4, 58);
if ( v6 )
{
*v6 = 0;
v7 = strlen(a2);
if ( !strncasecmp(a2, v5, v7) )
return (size_t)&v5[strlen(v5) + 2];
v3 = v5;
}
}
if ( v3 )
*v3 = 0;
return (size_t)v3;
}

original_code:
char *getSIPHeader(const u_char *packet, char *wantedHeader) {
 char *crudo, *linea, *header = ((void *)0);
 crudo = strdup((char *)packet);
 linea = strtok(crudo, "\r\n");
 for (;;) {
  linea = strtok(((void *)0), "\r\n");
  if (!linea) break;
  if ((strchr(linea, ':'))) {
   memset(strchr(linea, ':'), 0, 1);
   header = linea;
   if (!strncasecmp(wantedHeader, header, strlen(wantedHeader))) return (header+strlen(header) + 2);
  }
 }
 if (!header) return ((void *)0);
 header[0] = 0x00;
 return header;
}

canonical_original_code:
char *getSIPHeader(unsigned char *packet, char *wantedHeader) {
 char *crudo; char *linea; char *header = ((void *)0);
 crudo = strdup((char *)packet);
 linea = strtok(crudo, "\r\n");
 for (;;) {
  linea = strtok(((void *)0), "\r\n");
  if (!linea) break;
  if ((strchr(linea, ':'))) {
   memset(strchr(linea, ':'), 0, 1);
   header = linea;
   if (!strncasecmp(wantedHeader, header, strlen(wantedHeader))) return (header+strlen(header) + 2);
  }
 }
 if (!header) return ((void *)0);
 header[0] = 0x00;
 return header;
}

variable_types:
packet
unsigned char *

variable_types:
wantedHeader
char *

variable_types:
crudo
char *

variable_types:
linea
char *

variable_types:
header
char *


decompiled_code:
_BOOL8 __fastcall rx_match(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
return (unsigned int)pcre_exec(rx, 0LL, a1, v1, 0LL, 0LL, 0LL, 0LL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
return (unsigned int)pcre_exec(rx, 0LL, a1, v1, 0LL, 0LL, 0LL, 0LL) == 0;
}

original_code:
int rx_match (char *packet) {
  const char *error;
  int erroffset;
  int rc = pcre_exec(rx, ((void *)0), packet, strlen(packet), 0, 0, ((void *)0), 0);
  return rc == 0;
}

canonical_original_code:
int rx_match(char *packet) {
  char *error;
  int erroffset;
  int rc = pcre_exec(rx, ((void *)0), packet, strlen(packet), 0, 0, ((void *)0), 0);
  return rc == 0;
}

variable_types:
packet
char *

variable_types:
error
char *

variable_types: erroffset int

variable_types: rc int


getSIPPacket

decompiled_code:
char __fastcall getSIPPacket(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r13
unsigned __int8 *v5; // r12
unsigned int v6; // er15
char *v7; // rbp
unsigned int v8; // er14
char *v9; // rax
size_t v10; // rax
bool v11; // zf
const char *v12; // rax
unsigned __int8 *v13; // rax
unsigned __int8 v14; // dl
char v15; // r13
__int64 v16; // r15
char *v17; // rax
const char *v18; // rdi
unsigned int v20; // [rsp+14h] [rbp-44h]
unsigned int v21; // [rsp+18h] [rbp-40h]
unsigned int v22; // [rsp+1Ch] [rbp-3Ch]

v4 = a3;
++captured;
if ( file || strcmp(dev, "any") )
{
if ( !a3 )
{
LOBYTE(v9) = fwrite("Invalid Packet\n", 1uLL, 0xFuLL, stderr);
return (char)v9;
}
v5 = (unsigned __int8 *)(a3 + 14);
}
else
{
v5 = (unsigned __int8 *)(a3 + 16);
v4 = a3 + 2;
}
v6 = *(_DWORD *)(a2 + 20);
if ( v6 <= 0x22 )
goto LABEL_27;
if ( (*(_BYTE *)(v4 + 14) & 0xF0) == 64 )
goto LABEL_10;
if ( (*(_BYTE *)(v4 + 16) & 0xF0) != 64 )
{
LABEL_27:
LOBYTE(v9) = fwrite("Invalid Packet\n", 1uLL, 0xFuLL, stderr);
return (char)v9;
}
v5 = (unsigned __int8 *)(v4 + 16);
v4 += 2LL;
LABEL_10:
v7 = (char *)malloc(v6);
v8 = *(_DWORD *)(a2 + 16);
memset(v7, 0, v8);
strncpy(v7, (const char *)(v4 + 42), v6 - 42);
LODWORD(v9) = strcmp(dev, "any") == 0 ? 44 : 42;
v7[v6 - (unsigned int)v9] = 0;
if ( !method || (v10 = strlen(&method), LODWORD(v9) = strncmp(v7, &method, v10), !(_DWORD)v9) )
{
if ( !response[0]
|| v8 > 3
&& (v11 = memcmp(v7, "SIP/", 4uLL) == 0, LOBYTE(v9) = !v11, v11)
&& (LODWORD(v9) = strncmp(v7 + 8, response, 3uLL), !(_DWORD)v9) )
{
if ( !regexp
|| (!header || (v12 = (const char *)getSIPHeader(v7, &header), LODWORD(v9) = rx_match(v12), (_DWORD)v9))
&& (LODWORD(v9) = rx_match(v7), (_DWORD)v9) )
{
switch ( follow )
{
case 0:
goto LABEL_23;
case 1:
callID = (char *)getSIPHeader(v7, "Call-ID");
if ( !callID )
{
v9 = (char *)getSIPHeader(v7, "call-id");
callID = v9;
if ( !v9 )
return (char)v9;
}
follow = 2;
break;
case 2:
break;
default:
LABEL_23:
++shown;
v13 = v5 + 12;
v14 = 0;
do
v14 += *v13++;
while ( v5 + 16 != v13 );
v15 = v14 % 6u;
v16 = v5[15];
v20 = v5[14];
v21 = v5[13];
v22 = v5[12];
v17 = getTime(*(_QWORD *)a2);
printf("\x1B[0;37m<==[%d bytes]==[%s] : %d.%d.%d.%d => ", v8, v17, v22, v21, v20, v16);
LOBYTE(v9) = printf(
"%d.%d.%d.%d ====\n\x1B[1;%dm%s\n\x1B[0;37m=================>\n\n\x1B[0m",
v5[16],
v5[17],
v5[18],
v5[19],
(unsigned __int8)(v15 + 31),
v7);
return (char)v9;
}
v18 = (const char *)getSIPHeader(v7, "Call-ID");
if ( v18 || (v9 = (char *)getSIPHeader(v7, "call-id"), (v18 = v9) != 0LL) )
{
LODWORD(v9) = strcmp(v18, callID);
if ( !(_DWORD)v9 )
goto LABEL_23;
}
}
}
}
return (char)v9;
}

canonical_decompiled_code:
char __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r13
unsigned __int8 *v5; // r12
unsigned int v6; // er15
char *v7; // rbp
unsigned int v8; // er14
char *v9; // rax
size_t v10; // rax
bool v11; // zf
const char *v12; // rax
unsigned __int8 *v13; // rax
unsigned __int8 v14; // dl
char v15; // r13
__int64 v16; // r15
char *v17; // rax
const char *v18; // rdi
unsigned int v20; // [rsp+14h] [rbp-44h]
unsigned int v21; // [rsp+18h] [rbp-40h]
unsigned int v22; // [rsp+1Ch] [rbp-3Ch]

v4 = a3;
++captured;
if ( file || strcmp(dev, "any") )
{
if ( !a3 )
{
LOBYTE(v9) = fwrite("Invalid Packet\n", 1uLL, 0xFuLL, stderr);
return (char)v9;
}
v5 = (unsigned __int8 *)(a3 + 14);
}
else
{
v5 = (unsigned __int8 *)(a3 + 16);
v4 = a3 + 2;
}
v6 = *(_DWORD *)(a2 + 20);
if ( v6 <= 0x22 )
goto LABEL_27;
if ( (*(_BYTE *)(v4 + 14) & 0xF0) == 64 )
goto LABEL_10;
if ( (*(_BYTE *)(v4 + 16) & 0xF0) != 64 )
{
LABEL_27:
LOBYTE(v9) = fwrite("Invalid Packet\n", 1uLL, 0xFuLL, stderr);
return (char)v9;
}
v5 = (unsigned __int8 *)(v4 + 16);
v4 += 2LL;
LABEL_10:
v7 = (char *)malloc(v6);
v8 = *(_DWORD *)(a2 + 16);
memset(v7, 0, v8);
strncpy(v7, (const char *)(v4 + 42), v6 - 42);
LODWORD(v9) = strcmp(dev, "any") == 0 ? 44 : 42;
v7[v6 - (unsigned int)v9] = 0;
if ( !method || (v10 = strlen(&method), LODWORD(v9) = strncmp(v7, &method, v10), !(_DWORD)v9) )
{
if ( !response[0]
|| v8 > 3
&& (v11 = memcmp(v7, "SIP/", 4uLL) == 0, LOBYTE(v9) = !v11, v11)
&& (LODWORD(v9) = strncmp(v7 + 8, response, 3uLL), !(_DWORD)v9) )
{
if ( !regexp
|| (!header || (v12 = (const char *)func2(v7, &header), LODWORD(v9) = func3(v12), (_DWORD)v9))
&& (LODWORD(v9) = func3(v7), (_DWORD)v9) )
{
switch ( follow )
{
case 0:
goto LABEL_23;
case 1:
callID = (char *)func2(v7, "Call-ID");
if ( !callID )
{
v9 = (char *)func2(v7, "call-id");
callID = v9;
if ( !v9 )
return (char)v9;
}
follow = 2;
break;
case 2:
break;
default:
LABEL_23:
++shown;
v13 = v5 + 12;
v14 = 0;
do
v14 += *v13++;
while ( v5 + 16 != v13 );
v15 = v14 % 6u;
v16 = v5[15];
v20 = v5[14];
v21 = v5[13];
v22 = v5[12];
v17 = func1(*(_QWORD *)a2);
printf("\x1B[0;37m<==[%d bytes]==[%s] : %d.%d.%d.%d => ", v8, v17, v22, v21, v20, v16);
LOBYTE(v9) = printf(
"%d.%d.%d.%d ====\n\x1B[1;%dm%s\n\x1B[0;37m=================>\n\n\x1B[0m",
v5[16],
v5[17],
v5[18],
v5[19],
(unsigned __int8)(v15 + 31),
v7);
return (char)v9;
}
v18 = (const char *)func2(v7, "Call-ID");
if ( v18 || (v9 = (char *)func2(v7, "call-id"), (v18 = v9) != 0LL) )
{
LODWORD(v9) = strcmp(v18, callID);
if ( !(_DWORD)v9 )
goto LABEL_23;
}
}
}
}
return (char)v9;
}

original_code:
void getSIPPacket(u_char *data, const struct pcap_pkthdr *h, const u_char *p) {
 struct iphdr *cip;
 const u_char *packet;
 unsigned int caplen;
 captured++;
 if (!strlen(file) && !strcmp(dev, "any")) p += 2;
 cip = (struct iphdr *)(p+14);
 if ((!p) || (h->len <= (14 +20)) || ((unsigned char)cip->version != 4)) {
  if (p && p + 1) {
   p += 2;
   cip = (struct iphdr *)(p+14);
  } else {
   if (1) fprintf(stderr, "Invalid Packet\n");
   return;
  }
  if ((!p) || (h->len <= (14 +20)) || ((unsigned char)cip->version != 4)) {
   if (1) fprintf(stderr, "Invalid Packet\n");
   return;
  }
 }
 packet = (u_char *)malloc(h->len);
 memset((char *)packet, 0, h->caplen);
 strncpy((char *)packet, (char *)(p + 14 + 20 + 8), h->len - (14 + 20 + 8));
 memset((char *)packet + (h->len - (14 + 20 + (!strcmp(dev, "any")?10:8))), 0, 1);
 caplen = h->caplen;
 if ((strlen(method) > 0) && strncmp((char *)packet, method, strlen(method))) return;
 if (strlen(response) > 0) {
  if (caplen < 4) return;
  if (strncmp((char *)packet, "SIP/", 4)) return;
  if (strncmp((char *)packet + 8, response, 3)) return;
 }
 if (strlen(regexp) > 0) {
  if ((strlen(header) > 0) && !rx_match(getSIPHeader(packet, header))) return;
  if (!rx_match((char *)packet)) return;
 }
 if (follow) {
  if (follow == 1) {
   if (!(callID = getSIPHeader(packet, "Call-ID"))) {
    callID = getSIPHeader(packet, "call-id");
   }
   if (callID) {
    follow = 2;
   } else return;
  }
  if (follow == 2) {
   char *call_id = getSIPHeader(packet, "Call-ID");
   if (!call_id) call_id = getSIPHeader(packet, "call-id");
   if (!call_id) return;
   if (strcmp(call_id, callID)) return;
  }
 }
 shown++;
 u_char *srcip = (u_char *)&cip->saddr;
 u_char *dstip = (u_char *)&cip->daddr;
 int i = 0;
 u_char color = 0;
 for (i = 0; i < 4; i++) {
  color += srcip[i];
 }
 color = 31 + (color % 6);
 printf("\x1b[0;37m<==[%d bytes]==[%s] : %d.%d.%d.%d => ", caplen, getTime(h->ts), srcip[0], srcip[1], srcip[2], srcip[3]);
 printf("%d.%d.%d.%d ====\n\x1b[1;%dm%s\n\x1b[0;37m=================>\n\n\x1b[0m", dstip[0], dstip[1], dstip[2], dstip[3], color, packet);
}

canonical_original_code:
void getSIPPacket(unsigned char *data, struct pcap_pkthdr *h, unsigned char *p) {
 struct iphdr *cip;
 unsigned char *packet;
 unsigned int caplen;
 captured++;
 if (!strlen(file) && !strcmp(dev, "any")) p += 2;
 cip = (struct iphdr *)(p+14);
 if ((!p) || (h->len <= (14 +20)) || ((unsigned char)cip->version != 4)) {
  if (p && p + 1) {
   p += 2;
   cip = (struct iphdr *)(p+14);
  } else {
   if (1) fprintf(stderr, "Invalid Packet\n");
   return;
  }
  if ((!p) || (h->len <= (14 +20)) || ((unsigned char)cip->version != 4)) {
   if (1) fprintf(stderr, "Invalid Packet\n");
   return;
  }
 }
 packet = (unsigned char *)malloc(h->len);
 memset((char *)packet, 0, h->caplen);
 strncpy((char *)packet, (char *)(p + 14 + 20 + 8), h->len - (14 + 20 + 8));
 memset((char *)packet + (h->len - (14 + 20 + (!strcmp(dev, "any")?10:8))), 0, 1);
 caplen = h->caplen;
 if ((strlen(method) > 0) && strncmp((char *)packet, method, strlen(method))) return;
 if (strlen(response) > 0) {
  if (caplen < 4) return;
  if (strncmp((char *)packet, "SIP/", 4)) return;
  if (strncmp((char *)packet + 8, response, 3)) return;
 }
 if (strlen(regexp) > 0) {
  if ((strlen(header) > 0) && !rx_match(getSIPHeader(packet, header))) return;
  if (!rx_match((char *)packet)) return;
 }
 if (follow) {
  if (follow == 1) {
   if (!(callID = getSIPHeader(packet, "Call-ID"))) {
    callID = getSIPHeader(packet, "call-id");
   }
   if (callID) {
    follow = 2;
   } else return;
  }
  if (follow == 2) {
   char *call_id = getSIPHeader(packet, "Call-ID");
   if (!call_id) call_id = getSIPHeader(packet, "call-id");
   if (!call_id) return;
   if (strcmp(call_id, callID)) return;
  }
 }
 shown++;
 unsigned char *srcip = (u_char *)&cip->saddr;
 unsigned char *dstip = (u_char *)&cip->daddr;
 int i = 0;
 unsigned char color = 0;
 for (i = 0; i < 4; i++) {
  color += srcip[i];
 }
 color = 31 + (color % 6);
 printf("\x1b[0;37m<==[%d bytes]==[%s] : %d.%d.%d.%d => ", caplen, getTime(h->ts), srcip[0], srcip[1], srcip[2], srcip[3]);
 printf("%d.%d.%d.%d ====\n\x1b[1;%dm%s\n\x1b[0;37m=================>\n\n\x1b[0m", dstip[0], dstip[1], dstip[2], dstip[3], color, packet);
}

variable_types:
data
unsigned char *

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

variable_types:
p
unsigned char *

variable_types: struct iphdr { unsigned char ihl; unsigned char tos; short tot_len; unsigned short id; short off; unsigned char ttl; unsigned char protocol; unsigned short check; struct in_addr { unsigned int s_addr; } saddr; struct in_addr daddr; } *

variable_types:
caplen
unsigned int

variable_types:
srcip
unsigned char *

variable_types:
dstip
unsigned char *

variable_types: i int

variable_types:
color
unsigned char

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }

user_defined_types: struct iphdr { unsigned char ihl; unsigned char tos; short tot_len; unsigned short id; short off; unsigned char ttl; unsigned char protocol; unsigned short check; struct in_addr saddr; struct in_addr daddr; }


payola

decompiled_code:
int payola()
{
return fprintf(
stderr,
"SIPffer v%s: A SIP protocol sniffer\nXenoMuta.com - https://github.com/xenomuta/SIPffer\n\n",
"1.0.2");
}

canonical_decompiled_code:
int func5()
{
return fprintf(
stderr,
"SIPffer v%s: A SIP protocol sniffer\nXenoMuta.com - https://github.com/xenomuta/SIPffer\n\n",
"1.0.2");
}

original_code:
void payola() {
 fprintf(stderr, "SIPffer v%s: A SIP protocol sniffer\nXenoMuta.com - https://github.com/xenomuta/SIPffer\n\n", "1.0.2");
}


usage

decompiled_code:
size_t usage()
{
fwrite("Usage: sipffer [OPTIONS] -i interface [regular expression (PCRE)]\n", 1uLL, 0x42uLL, stderr);
fwrite(" or: sipffer [OPTIONS] -a file [regular expression (PCRE)]\n\n", 1uLL, 0x3EuLL, stderr);
fwrite(" -i interface: \tEthernet Interface to sniff\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -a/--file file:\tArchived PCAP file to read\n\n", 1uLL, 0x2DuLL, stderr);
fwrite("OPTIONS:\n", 1uLL, 9uLL, stderr);
fwrite(" -p port: \tSpecify port to filtrar on ( defaults to udp/5060 )\n", 1uLL, 0x45uLL, stderr);
fwrite(" -f BPF filter: \tFiltro BPF adicional ( formato tcpdump )\n", 1uLL, 0x3AuLL, stderr);
fwrite(" -m method: \tFiltra por method SIP (INVITE,REGISTER,\n", 1uLL, 0x39uLL, stderr);
fwrite(" \t\tACK,SUBSCRIBE,CANCEL,BYE or OPTIONS)\n", 1uLL, 0x37uLL, stderr);
fwrite(" -r response: \tFilter by (numerical) response (200, 404, etc...)\n", 1uLL, 0x43uLL, stderr);
fwrite(
" -s/--follow: \tCapture the first matching packet and follow it's session (Call-ID)\n",
1uLL,
0x55uLL,
stderr);
fwrite(" -c header \tOnly match regular expression with header specified\n", 1uLL, 0x45uLL, stderr);
fwrite(" \t\tej. (From, To, Contact, etc...)\n", 1uLL, 0x32uLL, stderr);
return fwrite(" -h \tShow this help screen\n\n\n", 1uLL, 0x29uLL, stderr);
}

canonical_decompiled_code:
size_t func6()
{
fwrite("Usage: sipffer [OPTIONS] -i interface [regular expression (PCRE)]\n", 1uLL, 0x42uLL, stderr);
fwrite(" or: sipffer [OPTIONS] -a file [regular expression (PCRE)]\n\n", 1uLL, 0x3EuLL, stderr);
fwrite(" -i interface: \tEthernet Interface to sniff\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -a/--file file:\tArchived PCAP file to read\n\n", 1uLL, 0x2DuLL, stderr);
fwrite("OPTIONS:\n", 1uLL, 9uLL, stderr);
fwrite(" -p port: \tSpecify port to filtrar on ( defaults to udp/5060 )\n", 1uLL, 0x45uLL, stderr);
fwrite(" -f BPF filter: \tFiltro BPF adicional ( formato tcpdump )\n", 1uLL, 0x3AuLL, stderr);
fwrite(" -m method: \tFiltra por method SIP (INVITE,REGISTER,\n", 1uLL, 0x39uLL, stderr);
fwrite(" \t\tACK,SUBSCRIBE,CANCEL,BYE or OPTIONS)\n", 1uLL, 0x37uLL, stderr);
fwrite(" -r response: \tFilter by (numerical) response (200, 404, etc...)\n", 1uLL, 0x43uLL, stderr);
fwrite(
" -s/--follow: \tCapture the first matching packet and follow it's session (Call-ID)\n",
1uLL,
0x55uLL,
stderr);
fwrite(" -c header \tOnly match regular expression with header specified\n", 1uLL, 0x45uLL, stderr);
fwrite(" \t\tej. (From, To, Contact, etc...)\n", 1uLL, 0x32uLL, stderr);
return fwrite(" -h \tShow this help screen\n\n\n", 1uLL, 0x29uLL, stderr);
}

original_code:
void usage() {
 fprintf(stderr, "Usage: sipffer [OPTIONS] -i interface [regular expression (PCRE)]\n");
 fprintf(stderr, "   or: sipffer [OPTIONS] -a file [regular expression (PCRE)]\n\n");
 fprintf(stderr, " -i interface:  \tEthernet Interface to sniff\n");
 fprintf(stderr, " -a/--file file:\tArchived PCAP file to read\n\n");
 fprintf(stderr, "OPTIONS:\n");
 fprintf(stderr, " -p port:       \tSpecify port to filtrar on ( defaults to udp/5060 )\n");
 fprintf(stderr, " -f BPF filter: \tFiltro BPF adicional ( formato tcpdump )\n");
 fprintf(stderr, " -m method:     \tFiltra por method SIP (INVITE,REGISTER,\n");
 fprintf(stderr, "                \t\tACK,SUBSCRIBE,CANCEL,BYE or OPTIONS)\n");
 fprintf(stderr, " -r response:   \tFilter by (numerical) response (200, 404, etc...)\n");
 fprintf(stderr, " -s/--follow:   \tCapture the first matching packet and follow it's session (Call-ID)\n");
 fprintf(stderr, " -c header      \tOnly match regular expression with header specified\n");
 fprintf(stderr, "                \t\tej. (From, To, Contact, etc...)\n");
 fprintf(stderr, " -h             \tShow this help screen\n\n\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // ebx
__int64 v5; // rbx
const char *v6; // rax
const char *v7; // rax
__int64 v8; // r8
unsigned int v10; // [rsp+4h] [rbp-934h] BYREF
const char *v11; // [rsp+8h] [rbp-930h] BYREF
char s[2056]; // [rsp+10h] [rbp-928h] BYREF
unsigned int v13; // [rsp+818h] [rbp-120h] BYREF
int v14; // [rsp+81Ch] [rbp-11Ch] BYREF
char v15[280]; // [rsp+820h] [rbp-118h] BYREF

payola();
strcpy(port, "5060");
memset(&file, 0, 0x80uLL);
memset(&method, 0, 0x80uLL);
*(_WORD *)response = 0;
byte_180B = 0;
memset(&regexp, 0, 0x800uLL);
memset(&header, 0, 0x80uLL);
memset(&filter, 0, 0x800uLL);
follow = 0;
*(_QWORD *)dev = 7958113LL;
qword_2148 = 0LL;
qword_2150 = 0LL;
qword_2158 = 0LL;
if ( argc > 1 )
{
for ( i = 1; argc > i; ++i )
{
v8 = i;
if ( *argv[v8] == 45 )
{
if ( !strcmp(argv[i], "-s") )
{
if ( !strcmp(argv[i], "-h") )
goto LABEL_68;
LABEL_51:
follow = 1;
continue;
}
if ( !strcmp(argv[i], "--follow") )
{
if ( !strcmp(argv[i], "-h") )
goto LABEL_68;
goto LABEL_51;
}
if ( i + 1 == argc )
{
usage();
return 2;
}
if ( !strcmp(argv[i], "-h") )
{
LABEL_68:
usage();
return 0;
}
if ( !strcmp(argv[i], "-a") || !strcmp(argv[i], "--file") )
{
++i;
strncpy(&file, argv[v8 + 1], 0x80uLL);
}
else if ( !strcmp(argv[i], "-i") )
{
++i;
strncpy(dev, argv[v8 + 1], 0x20uLL);
}
else if ( !strcmp(argv[i], "-p") )
{
++i;
strncpy(port, argv[v8 + 1], 5uLL);
}
else if ( !strcmp(argv[i], "-c") )
{
++i;
strncpy(&header, argv[v8 + 1], 0x80uLL);
}
else if ( !strcmp(argv[i], "-f") )
{
++i;
strncpy(&filter, argv[v8 + 1], 0x800uLL);
}
else if ( !strcmp(argv[i], "-m") )
{
++i;
strncpy(&method, argv[v8 + 1], 0x80uLL);
}
else if ( !strcmp(argv[i], "-r") )
{
++i;
strncpy(response, argv[v8 + 1], 3uLL);
}
}
else
{
strncpy(&regexp, argv[i], 0x800uLL);
}
}
}
if ( header )
{
if ( !regexp )
{
fwrite("ERROR: Must specify regular expression when using '-c' option\n\n", 1uLL, 0x3FuLL, stderr);
return 2;
}
}
else if ( !regexp )
{
goto LABEL_17;
}
rx = pcre_compile(&regexp, 1LL, &v11, &v10, 0LL);
if ( !rx )
{
fprintf(stderr, "ERROR: Invalid PCRE pattern at offset %d: %s\n\n", v10, v11);
return 2;
}
LABEL_17:
memset(s, 0, 0x800uLL);
if ( filter )
snprintf(s, 0x800uLL, "udp and port %s and %s", port, &filter);
else
snprintf(s, 0x800uLL, "udp and port %s", port);
signal(6, (__sighandler_t)goodBye);
signal(15, (__sighandler_t)goodBye);
signal(19, (__sighandler_t)goodBye);
signal(9, (__sighandler_t)goodBye);
signal(2, (__sighandler_t)goodBye);
if ( file )
{
sniff = pcap_open_offline(&file, v15);
if ( !sniff )
{
fprintf(stderr, "ERROR: Can't open file '%s': %s\n\n", dev, v15);
return 2;
}
}
else
{
v5 = pcap_open_live(dev, 0xFFFFLL, 1LL, 1000LL, v15);
sniff = v5;
if ( !v5 )
{
fprintf(stderr, "ERROR: Can't open interface '%s': %s\n\n", dev, v15);
return 2;
}
if ( !strcmp(dev, "any") && (unsigned int)pcap_set_datalink(v5, 113LL) == -1 )
{
fwrite("ERROR: Can't assign link type DTL_LINUX_SLL\n\n", 1uLL, 0x2DuLL, stderr);
return 2;
}
if ( (unsigned int)pcap_lookupnet(dev, &v14, &v13, v15) == -1 )
{
fprintf(stderr, "WARNING: Can't find IP/Netmask for interface '%s'\n\n", dev);
v13 = 0;
v14 = 0;
}
}
if ( (unsigned int)pcap_compile(sniff, &fp, s, 1LL, v13) == -1 )
{
v6 = (const char *)pcap_geterr(sniff);
fprintf(stderr, "ERROR: Can't parse BPF filter \"%s\": %s\n\n", &filter, v6);
v4 = 2;
}
else if ( (unsigned int)pcap_setfilter(sniff, &fp) == -1 )
{
v7 = (const char *)pcap_geterr(sniff);
fprintf(stderr, "ERROR: Can't apply BPF filter \"%s\": %s\n\n", &filter, v7);
v4 = 2;
}
else
{
fprintf(stderr, "OK, sniffing interface '%s' on port '%s'\n", dev, port);
if ( filter )
fprintf(stderr, "BPF filter: \"%s\"\n", s);
if ( method )
fprintf(stderr, "Only packets with SIP method: %s\n", &method);
if ( response[0] )
fprintf(stderr, "Only Packets with SIP response: %s\n", response);
if ( regexp )
{
fprintf(stderr, "Only packets matching regular expression: /%s/", &regexp);
if ( header )
fprintf(stderr, " in header field: %s\n", &header);
else
fputc(10, stderr);
}
if ( follow )
fwrite("Follow first packet with related packets by Call-ID.\n", 1uLL, 0x35uLL, stderr);
v4 = pcap_loop(sniff, 0LL, getSIPPacket, 0LL);
pcap_freecode(&fp);
pcap_close(sniff);
if ( v4 > 0 )
{
fprintf(stderr, "%d packets captured\n%d packets shown\n\n", (unsigned int)v4, (unsigned int)shown);
v4 = 0;
}
else if ( v4 )
{
v4 = 2;
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // ebx
__int64 v5; // rbx
const char *v6; // rax
const char *v7; // rax
__int64 v8; // r8
unsigned int v10; // [rsp+4h] [rbp-934h] BYREF
const char *v11; // [rsp+8h] [rbp-930h] BYREF
char s[2056]; // [rsp+10h] [rbp-928h] BYREF
unsigned int v13; // [rsp+818h] [rbp-120h] BYREF
int v14; // [rsp+81Ch] [rbp-11Ch] BYREF
char v15[280]; // [rsp+820h] [rbp-118h] BYREF

func5();
strcpy(port, "5060");
memset(&file, 0, 0x80uLL);
memset(&method, 0, 0x80uLL);
*(_WORD *)response = 0;
byte_180B = 0;
memset(&regexp, 0, 0x800uLL);
memset(&header, 0, 0x80uLL);
memset(&filter, 0, 0x800uLL);
follow = 0;
*(_QWORD *)dev = 7958113LL;
qword_2148 = 0LL;
qword_2150 = 0LL;
qword_2158 = 0LL;
if ( argc > 1 )
{
for ( i = 1; argc > i; ++i )
{
v8 = i;
if ( *argv[v8] == 45 )
{
if ( !strcmp(argv[i], "-s") )
{
if ( !strcmp(argv[i], "-h") )
goto LABEL_68;
LABEL_51:
follow = 1;
continue;
}
if ( !strcmp(argv[i], "--follow") )
{
if ( !strcmp(argv[i], "-h") )
goto LABEL_68;
goto LABEL_51;
}
if ( i + 1 == argc )
{
func6();
return 2;
}
if ( !strcmp(argv[i], "-h") )
{
LABEL_68:
func6();
return 0;
}
if ( !strcmp(argv[i], "-a") || !strcmp(argv[i], "--file") )
{
++i;
strncpy(&file, argv[v8 + 1], 0x80uLL);
}
else if ( !strcmp(argv[i], "-i") )
{
++i;
strncpy(dev, argv[v8 + 1], 0x20uLL);
}
else if ( !strcmp(argv[i], "-p") )
{
++i;
strncpy(port, argv[v8 + 1], 5uLL);
}
else if ( !strcmp(argv[i], "-c") )
{
++i;
strncpy(&header, argv[v8 + 1], 0x80uLL);
}
else if ( !strcmp(argv[i], "-f") )
{
++i;
strncpy(&filter, argv[v8 + 1], 0x800uLL);
}
else if ( !strcmp(argv[i], "-m") )
{
++i;
strncpy(&method, argv[v8 + 1], 0x80uLL);
}
else if ( !strcmp(argv[i], "-r") )
{
++i;
strncpy(response, argv[v8 + 1], 3uLL);
}
}
else
{
strncpy(&regexp, argv[i], 0x800uLL);
}
}
}
if ( header )
{
if ( !regexp )
{
fwrite("ERROR: Must specify regular expression when using '-c' option\n\n", 1uLL, 0x3FuLL, stderr);
return 2;
}
}
else if ( !regexp )
{
goto LABEL_17;
}
rx = pcre_compile(&regexp, 1LL, &v11, &v10, 0LL);
if ( !rx )
{
fprintf(stderr, "ERROR: Invalid PCRE pattern at offset %d: %s\n\n", v10, v11);
return 2;
}
LABEL_17:
memset(s, 0, 0x800uLL);
if ( filter )
snprintf(s, 0x800uLL, "udp and port %s and %s", port, &filter);
else
snprintf(s, 0x800uLL, "udp and port %s", port);
signal(6, (__sighandler_t)goodBye);
signal(15, (__sighandler_t)goodBye);
signal(19, (__sighandler_t)goodBye);
signal(9, (__sighandler_t)goodBye);
signal(2, (__sighandler_t)goodBye);
if ( file )
{
sniff = pcap_open_offline(&file, v15);
if ( !sniff )
{
fprintf(stderr, "ERROR: Can't open file '%s': %s\n\n", dev, v15);
return 2;
}
}
else
{
v5 = pcap_open_live(dev, 0xFFFFLL, 1LL, 1000LL, v15);
sniff = v5;
if ( !v5 )
{
fprintf(stderr, "ERROR: Can't open interface '%s': %s\n\n", dev, v15);
return 2;
}
if ( !strcmp(dev, "any") && (unsigned int)pcap_set_datalink(v5, 113LL) == -1 )
{
fwrite("ERROR: Can't assign link type DTL_LINUX_SLL\n\n", 1uLL, 0x2DuLL, stderr);
return 2;
}
if ( (unsigned int)pcap_lookupnet(dev, &v14, &v13, v15) == -1 )
{
fprintf(stderr, "WARNING: Can't find IP/Netmask for interface '%s'\n\n", dev);
v13 = 0;
v14 = 0;
}
}
if ( (unsigned int)pcap_compile(sniff, &fp, s, 1LL, v13) == -1 )
{
v6 = (const char *)pcap_geterr(sniff);
fprintf(stderr, "ERROR: Can't parse BPF filter \"%s\": %s\n\n", &filter, v6);
v4 = 2;
}
else if ( (unsigned int)pcap_setfilter(sniff, &fp) == -1 )
{
v7 = (const char *)pcap_geterr(sniff);
fprintf(stderr, "ERROR: Can't apply BPF filter \"%s\": %s\n\n", &filter, v7);
v4 = 2;
}
else
{
fprintf(stderr, "OK, sniffing interface '%s' on port '%s'\n", dev, port);
if ( filter )
fprintf(stderr, "BPF filter: \"%s\"\n", s);
if ( method )
fprintf(stderr, "Only packets with SIP method: %s\n", &method);
if ( response[0] )
fprintf(stderr, "Only Packets with SIP response: %s\n", response);
if ( regexp )
{
fprintf(stderr, "Only packets matching regular expression: /%s/", &regexp);
if ( header )
fprintf(stderr, " in header field: %s\n", &header);
else
fputc(10, stderr);
}
if ( follow )
fwrite("Follow first packet with related packets by Call-ID.\n", 1uLL, 0x35uLL, stderr);
v4 = pcap_loop(sniff, 0LL, getSIPPacket, 0LL);
pcap_freecode(&fp);
pcap_close(sniff);
if ( v4 > 0 )
{
fprintf(stderr, "%d packets captured\n%d packets shown\n\n", (unsigned int)v4, (unsigned int)shown);
v4 = 0;
}
else if ( v4 )
{
v4 = 2;
}
}
return v4;
}

original_code:
int main(int argc, char *argv[]) {
 char errbuf[256];
 bpf_u_int32 ip;
 bpf_u_int32 mask;
 int i;
 payola();
 memset((char *)&port, 0, sizeof(port));
 strncpy((char *)&port, "5060", sizeof(port));
 memset((char *)&dev, 0, sizeof(dev));
 memset((char *)&file, 0, sizeof(file));
 memset((char *)&method, 0, sizeof(method));
 memset((char *)&response, 0, sizeof(response));
 memset((char *)&regexp, 0, sizeof(regexp));
 memset((char *)&header, 0, sizeof(header));
 memset((char *)&filter, 0, sizeof(filter));
 follow = 0;
 strncpy((char *)&dev, "any", sizeof(dev));
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-') {
   strncpy((char *)&regexp, argv[i], sizeof(regexp));
   continue;
  } else if ((argv[i][0] == '-') && strcmp(argv[i], "-s") && strcmp(argv[i], "--follow") && (i + 1 == argc)) {
   usage();
   return 2;
  }
  if (!strcmp(argv[i], "-h")) {
   usage();
   return 0;
  }
  if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--follow")) {
   follow = 1;
   continue;
  }
  if (!strcmp(argv[i], "-a") || !strcmp(argv[i], "--file")) {
   strncpy((char *)&file, argv[++i], sizeof(file));
   continue;
  }
  if (!strcmp(argv[i], "-i")) {
   strncpy((char *)&dev, argv[++i], sizeof(dev));
   continue;
  }
  if (!strcmp(argv[i], "-p")) {
   strncpy((char *)&port, argv[++i], sizeof(port));
   continue;
  }
  if (!strcmp(argv[i], "-c")) {
   strncpy((char *)&header, argv[++i], sizeof(header));
   continue;
  }
  if (!strcmp(argv[i], "-f")) {
   strncpy((char *)&filter, argv[++i], sizeof(filter));
   continue;
  }
  if (!strcmp(argv[i], "-m")) {
   strncpy((char *)&method, argv[++i], sizeof(method));
   continue;
  }
  if (!strcmp(argv[i], "-r")) {
   strncpy((char *)&response, argv[++i], sizeof(response));
   continue;
  }
 }
 if ((strlen(header) > 0) && (strlen(regexp) == 0)) {
  fprintf(stderr, "ERROR: Must specify regular expression when using '-c' option\n\n");
  return 2;
 }
 if (strlen(regexp) > 0) {
   const char *rxerror;
   int rxerroffset;
   rx = pcre_compile((char *)&regexp, 0x00000001, &rxerror, &rxerroffset, ((void *)0));
   if (rx == ((void *)0)) {
     fprintf(stderr, "ERROR: Invalid PCRE pattern at offset %d: %s\n\n", rxerroffset, rxerror);
     return 2;
   }
 }
 char filterfinal[2048];
 memset(filterfinal, 0, 2048);
 if (strlen(filter) > 0) {
  snprintf((char *)&filterfinal, sizeof(filterfinal), "udp and port %s and %s", port, filter);
 } else {
  snprintf((char *)&filterfinal, sizeof(filterfinal), "udp and port %s", port);
 }
 signal(6, &goodBye);
 signal(15, &goodBye);
 signal(19, &goodBye);
 signal(9, &goodBye);
 signal(2, &goodBye);
 if (strlen(file) > 0) {
  if ((sniff = pcap_open_offline(file, errbuf)) == ((void *)0)) {
   fprintf(stderr, "ERROR: Can't open file '%s': %s\n\n", dev, errbuf);
   return 2;
  }
 } else {
  if ((sniff = pcap_open_live(dev, 65535, 1, 1000, errbuf)) == ((void *)0)) {
   fprintf(stderr, "ERROR: Can't open interface '%s': %s\n\n", dev, errbuf);
   return 2;
  }
  if (!strcmp(dev, "any")) {
   if ((pcap_set_datalink(sniff, 113)) == -1) {
    fprintf(stderr, "ERROR: Can't assign link type DTL_LINUX_SLL\n\n");
    return 2;
   }
  }
  if (pcap_lookupnet(dev, &ip, &mask, errbuf) == -1) {
   fprintf(stderr, "WARNING: Can't find IP/Netmask for interface '%s'\n\n", dev);
   mask = 0;
   ip = 0;
  }
 }
 if (pcap_compile(sniff, &fp, filterfinal, 1, mask) == -1) {
  fprintf(stderr, "ERROR: Can't parse BPF filter \"%s\": %s\n\n", filter, pcap_geterr(sniff));
  return 2;
 }
 if (pcap_setfilter(sniff, &fp) == -1) {
  fprintf(stderr, "ERROR: Can't apply BPF filter \"%s\": %s\n\n", filter, pcap_geterr(sniff));
  return 2;
 }
 fprintf(stderr, "OK, sniffing interface '%s' on port '%s'\n", dev, port);
 if (strlen(filter) > 0) fprintf(stderr, "BPF filter: \"%s\"\n", filterfinal);
 if (strlen(method) > 0) fprintf(stderr, "Only packets with SIP method: %s\n", method);
 if (strlen(response) > 0) fprintf(stderr, "Only Packets with SIP response: %s\n", response);
 if (strlen(regexp) > 0) {
  fprintf(stderr, "Only packets matching regular expression: /%s/", regexp);
  if (strlen(header) > 0) fprintf(stderr, " in header field: %s\n", header);
  else fprintf(stderr, "\n");
 }
 if (follow) {
  fprintf(stderr, "Follow first packet with related packets by Call-ID.\n");
 }
 int res = pcap_loop(sniff, 0, getSIPPacket, ((void *)0));
 pcap_freecode(&fp);
 pcap_close(sniff);
 if (res > 0) {
  fprintf(stderr, "%d packets captured\n%d packets shown\n\n", res, shown);
 }
 return (res >= 0)?0:2;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char errbuf[256];
 unsigned int ip;
 unsigned int mask;
 int i;
 payola();
 memset((char *)&port, 0, sizeof(port));
 strncpy((char *)&port, "5060", sizeof(port));
 memset((char *)&dev, 0, sizeof(dev));
 memset((char *)&file, 0, sizeof(file));
 memset((char *)&method, 0, sizeof(method));
 memset((char *)&response, 0, sizeof(response));
 memset((char *)&regexp, 0, sizeof(regexp));
 memset((char *)&header, 0, sizeof(header));
 memset((char *)&filter, 0, sizeof(filter));
 follow = 0;
 strncpy((char *)&dev, "any", sizeof(dev));
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-') {
   strncpy((char *)&regexp, argv[i], sizeof(regexp));
   continue;
  } else if ((argv[i][0] == '-') && strcmp(argv[i], "-s") && strcmp(argv[i], "--follow") && (i + 1 == argc)) {
   usage();
   return 2;
  }
  if (!strcmp(argv[i], "-h")) {
   usage();
   return 0;
  }
  if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--follow")) {
   follow = 1;
   continue;
  }
  if (!strcmp(argv[i], "-a") || !strcmp(argv[i], "--file")) {
   strncpy((char *)&file, argv[++i], sizeof(file));
   continue;
  }
  if (!strcmp(argv[i], "-i")) {
   strncpy((char *)&dev, argv[++i], sizeof(dev));
   continue;
  }
  if (!strcmp(argv[i], "-p")) {
   strncpy((char *)&port, argv[++i], sizeof(port));
   continue;
  }
  if (!strcmp(argv[i], "-c")) {
   strncpy((char *)&header, argv[++i], sizeof(header));
   continue;
  }
  if (!strcmp(argv[i], "-f")) {
   strncpy((char *)&filter, argv[++i], sizeof(filter));
   continue;
  }
  if (!strcmp(argv[i], "-m")) {
   strncpy((char *)&method, argv[++i], sizeof(method));
   continue;
  }
  if (!strcmp(argv[i], "-r")) {
   strncpy((char *)&response, argv[++i], sizeof(response));
   continue;
  }
 }
 if ((strlen(header) > 0) && (strlen(regexp) == 0)) {
  fprintf(stderr, "ERROR: Must specify regular expression when using '-c' option\n\n");
  return 2;
 }
 if (strlen(regexp) > 0) {
   char *rxerror;
   int rxerroffset;
   rx = pcre_compile((char *)&regexp, 0x00000001, &rxerror, &rxerroffset, ((void *)0));
   if (rx == ((void *)0)) {
     fprintf(stderr, "ERROR: Invalid PCRE pattern at offset %d: %s\n\n", rxerroffset, rxerror);
     return 2;
   }
 }
 char filterfinal[2048];
 memset(filterfinal, 0, 2048);
 if (strlen(filter) > 0) {
  snprintf((char *)&filterfinal, sizeof(filterfinal), "udp and port %s and %s", port, filter);
 } else {
  snprintf((char *)&filterfinal, sizeof(filterfinal), "udp and port %s", port);
 }
 signal(6, &goodBye);
 signal(15, &goodBye);
 signal(19, &goodBye);
 signal(9, &goodBye);
 signal(2, &goodBye);
 if (strlen(file) > 0) {
  if ((sniff = pcap_open_offline(file, errbuf)) == ((void *)0)) {
   fprintf(stderr, "ERROR: Can't open file '%s': %s\n\n", dev, errbuf);
   return 2;
  }
 } else {
  if ((sniff = pcap_open_live(dev, 65535, 1, 1000, errbuf)) == ((void *)0)) {
   fprintf(stderr, "ERROR: Can't open interface '%s': %s\n\n", dev, errbuf);
   return 2;
  }
  if (!strcmp(dev, "any")) {
   if ((pcap_set_datalink(sniff, 113)) == -1) {
    fprintf(stderr, "ERROR: Can't assign link type DTL_LINUX_SLL\n\n");
    return 2;
   }
  }
  if (pcap_lookupnet(dev, &ip, &mask, errbuf) == -1) {
   fprintf(stderr, "WARNING: Can't find IP/Netmask for interface '%s'\n\n", dev);
   mask = 0;
   ip = 0;
  }
 }
 if (pcap_compile(sniff, &fp, filterfinal, 1, mask) == -1) {
  fprintf(stderr, "ERROR: Can't parse BPF filter \"%s\": %s\n\n", filter, pcap_geterr(sniff));
  return 2;
 }
 if (pcap_setfilter(sniff, &fp) == -1) {
  fprintf(stderr, "ERROR: Can't apply BPF filter \"%s\": %s\n\n", filter, pcap_geterr(sniff));
  return 2;
 }
 fprintf(stderr, "OK, sniffing interface '%s' on port '%s'\n", dev, port);
 if (strlen(filter) > 0) fprintf(stderr, "BPF filter: \"%s\"\n", filterfinal);
 if (strlen(method) > 0) fprintf(stderr, "Only packets with SIP method: %s\n", method);
 if (strlen(response) > 0) fprintf(stderr, "Only Packets with SIP response: %s\n", response);
 if (strlen(regexp) > 0) {
  fprintf(stderr, "Only packets matching regular expression: /%s/", regexp);
  if (strlen(header) > 0) fprintf(stderr, " in header field: %s\n", header);
  else fprintf(stderr, "\n");
 }
 if (follow) {
  fprintf(stderr, "Follow first packet with related packets by Call-ID.\n");
 }
 int res = pcap_loop(sniff, 0, getSIPPacket, ((void *)0));
 pcap_freecode(&fp);
 pcap_close(sniff);
 if (res > 0) {
  fprintf(stderr, "%d packets captured\n%d packets shown\n\n", res, shown);
 }
 return (res >= 0)?0:2;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
errbuf
char [256]

variable_types:
ip
unsigned int

variable_types:
mask
unsigned int

variable_types:
rxerror
char *

variable_types: rxerroffset int

variable_types:
filterfinal
char [2048]

variable_types: res int


repo: xlcteam/vic

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

result = 0LL;
memset((void *)(unsigned int)((_DWORD)&vic_funcs + 96), 0, 0x600uLL);
vic_funcs_len = 4;
return result;
}

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

result = 0LL;
memset((void *)(unsigned int)((_DWORD)&vic_funcs + 96), 0, 0x600uLL);
vic_funcs_len = 4;
return result;
}

original_code:
void vic_funcs_clear(void)
{
    void *start = vic_funcs + 4;
    memset(start, 0, sizeof(struct vic_func_t) * 64);
    vic_funcs_len = 4;
}

canonical_original_code:
void vic_funcs_clear()
{
    void *start = vic_funcs + 4;
    memset(start, 0, sizeof(struct vic_func_t) * 64);
    vic_funcs_len = 4;
}

variable_types:
start
void *

user_defined_types: struct vic_func_t { char name[-1]; void (*p_func)(); }


decompiled_code:
__int64 __fastcall vic_fn_add(char *src, __int64 a2)
{
unsigned __int8 v2; // bp
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rax
__m128i v6; // [rsp+0h] [rbp-58h] BYREF
__int64 v7; // [rsp+10h] [rbp-48h]
char dest[8]; // [rsp+27h] [rbp-31h] BYREF
char v9; // [rsp+2Fh] [rbp-29h]

*(_QWORD *)dest = 0LL;
v9 = 0;
strncpy(dest, src, 8uLL);
v2 = vic_funcs_len;
if ( vic_funcs_len )
{
v3 = 0LL;
do
{
if ( !strcmp(dest, (const char *)&vic_funcs + 24 * v3) )
{
*((_QWORD *)&vic_funcs + 3 * (int)v3 + 2) = a2;
return 0LL;
}
++v3;
}
while ( v2 > (unsigned __int8)v3 );
result = 1LL;
if ( v2 == 68 )
return result;
}
v7 = a2;
strcpy(v6.m128i_i8, dest);
v5 = 24LL * v2;
*(__int128 *)((char *)&vic_funcs + v5) = (__int128)_mm_loadu_si128(&v6);
*(_QWORD *)((char *)&vic_funcs + v5 + 16) = v7;
vic_funcs_len = v2 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, __int64 a2)
{
unsigned __int8 v2; // bp
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rax
__m128i v6; // [rsp+0h] [rbp-58h] BYREF
__int64 v7; // [rsp+10h] [rbp-48h]
char dest[8]; // [rsp+27h] [rbp-31h] BYREF
char v9; // [rsp+2Fh] [rbp-29h]

*(_QWORD *)dest = 0LL;
v9 = 0;
strncpy(dest, src, 8uLL);
v2 = vic_funcs_len;
if ( vic_funcs_len )
{
v3 = 0LL;
do
{
if ( !strcmp(dest, (const char *)&vic_funcs + 24 * v3) )
{
*((_QWORD *)&vic_funcs + 3 * (int)v3 + 2) = a2;
return 0LL;
}
++v3;
}
while ( v2 > (unsigned __int8)v3 );
result = 1LL;
if ( v2 == 68 )
return result;
}
v7 = a2;
strcpy(v6.m128i_i8, dest);
v5 = 24LL * v2;
*(__int128 *)((char *)&vic_funcs + v5) = (__int128)_mm_loadu_si128(&v6);
*(_QWORD *)((char *)&vic_funcs + v5 + 16) = v7;
vic_funcs_len = v2 + 1;
return 0LL;
}

original_code:
uint8_t vic_fn_add(const char *raw_name, void (*p_func)(void))
{
    char name[8 +1] = {'\0'};
    strncpy(name, raw_name, 8);
    uint8_t i;
    for (i = 0; i < vic_funcs_len; i++) {
        if (strcmp(name, vic_funcs[i].name) == 0) {
            vic_funcs[i].p_func = p_func;
            return 0;
        }
    }
    if (vic_funcs_len == (64 +4)) {
        return 1;
    }
    struct vic_func_t new_func;
    new_func.p_func = p_func;
    strcpy(new_func.name, name);
    vic_funcs[vic_funcs_len] = new_func;
    vic_funcs_len++;
    return 0;
}

canonical_original_code:
unsigned char vic_fn_add(char *raw_name, void (*p_func)())
{
    char name[-1] = {'\0'};
    strncpy(name, raw_name, 8);
    unsigned char i;
    for (i = 0; i < vic_funcs_len; i++) {
        if (strcmp(name, vic_funcs[i].name) == 0) {
            vic_funcs[i].p_func = p_func;
            return 0;
        }
    }
    if (vic_funcs_len == (64 +4)) {
        return 1;
    }
    struct vic_func_t new_func;
    new_func.p_func = p_func;
    strcpy(new_func.name, name);
    vic_funcs[vic_funcs_len] = new_func;
    vic_funcs_len++;
    return 0;
}

variable_types:
name
char [-1]

variable_types:
i
unsigned char

variable_types: struct vic_func_t { char name[-1]; void (*p_func)(); }

return_type: unsigned char


decompiled_code:
__int64 __fastcall vic_fn_call(char *src)
{
unsigned __int8 v1; // r12
__int64 v2; // rbx
char dest[8]; // [rsp+7h] [rbp-21h] BYREF
char v5; // [rsp+Fh] [rbp-19h]

*(_QWORD *)dest = 0LL;
v5 = 0;
strncpy(dest, src, 8uLL);
v1 = vic_funcs_len;
if ( !vic_funcs_len )
return 2LL;
v2 = 0LL;
while ( strcmp(dest, (const char *)&vic_funcs + 24 * v2) )
{
if ( v1 <= (unsigned __int8)++v2 )
return 2LL;
}
(*(&vic_funcs + 3 * (int)v2 + 2))();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src)
{
unsigned __int8 v1; // r12
__int64 v2; // rbx
char dest[8]; // [rsp+7h] [rbp-21h] BYREF
char v5; // [rsp+Fh] [rbp-19h]

*(_QWORD *)dest = 0LL;
v5 = 0;
strncpy(dest, src, 8uLL);
v1 = vic_funcs_len;
if ( !vic_funcs_len )
return 2LL;
v2 = 0LL;
while ( strcmp(dest, (const char *)&vic_funcs + 24 * v2) )
{
if ( v1 <= (unsigned __int8)++v2 )
return 2LL;
}
(*(&vic_funcs + 3 * (int)v2 + 2))();
return 0LL;
}

original_code:
uint8_t vic_fn_call(const char *raw_name)
{
    char name[8 + 1] = {'\0'};
    strncpy(name, raw_name, 8);
    uint8_t i;
    for (i = 0; i < vic_funcs_len; i++) {
        if (strcmp(name, vic_funcs[i].name) == 0) {
            (*(vic_funcs[i].p_func))();
            return 0;
        }
    }
    return 2;
}

canonical_original_code:
unsigned char vic_fn_call(char *raw_name)
{
    char name[-1] = {'\0'};
    strncpy(name, raw_name, 8);
    unsigned char i;
    for (i = 0; i < vic_funcs_len; i++) {
        if (strcmp(name, vic_funcs[i].name) == 0) {
            (*(vic_funcs[i].p_func))();
            return 0;
        }
    }
    return 2;
}


decompiled_code:
__int64 __fastcall vic_fn_rm(char *src)
{
unsigned __int8 v1; // r13
__int64 v2; // rbx
int v3; // er12
int v4; // ebp
__int64 result; // rax
int v6; // ebx
__int64 v7; // rax
char dest[8]; // [rsp+7h] [rbp-31h] BYREF
char v9; // [rsp+Fh] [rbp-29h]

*(_QWORD *)dest = 0LL;
v9 = 0;
strncpy(dest, src, 8uLL);
v1 = vic_funcs_len;
if ( !vic_funcs_len )
return 2LL;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
v4 = v2;
if ( !strcmp(dest, (const char *)&vic_funcs + 24 * v2) )
break;
if ( v1 <= (unsigned __int8)++v2 )
return 2LL;
}
if ( (unsigned __int8)v2 <= 3u )
{
*(&vic_funcs + 3 * (int)v2 + 2) = 0LL;
*(&vic_funcs + 3 * v2) = 0LL;
result = 0LL;
}
else
{
v6 = v1 - 1;
if ( v4 < v6 )
{
do
{
v7 = v4 + 1;
*(&vic_funcs + 3 * v4 + 2) = *(&vic_funcs + 3 * v7 + 2);
strcpy((char *)&vic_funcs + 24 * v7 - 24, (const char *)&vic_funcs + 24 * v7);
v4 = (unsigned __int8)++v3;
}
while ( (unsigned __int8)v3 < v6 );
}
vic_funcs_len = v1 - 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
unsigned __int8 v1; // r13
__int64 v2; // rbx
int v3; // er12
int v4; // ebp
__int64 result; // rax
int v6; // ebx
__int64 v7; // rax
char dest[8]; // [rsp+7h] [rbp-31h] BYREF
char v9; // [rsp+Fh] [rbp-29h]

*(_QWORD *)dest = 0LL;
v9 = 0;
strncpy(dest, src, 8uLL);
v1 = vic_funcs_len;
if ( !vic_funcs_len )
return 2LL;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
v4 = v2;
if ( !strcmp(dest, (const char *)&vic_funcs + 24 * v2) )
break;
if ( v1 <= (unsigned __int8)++v2 )
return 2LL;
}
if ( (unsigned __int8)v2 <= 3u )
{
*(&vic_funcs + 3 * (int)v2 + 2) = 0LL;
*(&vic_funcs + 3 * v2) = 0LL;
result = 0LL;
}
else
{
v6 = v1 - 1;
if ( v4 < v6 )
{
do
{
v7 = v4 + 1;
*(&vic_funcs + 3 * v4 + 2) = *(&vic_funcs + 3 * v7 + 2);
strcpy((char *)&vic_funcs + 24 * v7 - 24, (const char *)&vic_funcs + 24 * v7);
v4 = (unsigned __int8)++v3;
}
while ( (unsigned __int8)v3 < v6 );
}
vic_funcs_len = v1 - 1;
result = 0LL;
}
return result;
}

original_code:
uint8_t vic_fn_rm(const char *raw_name)
{
    char name[8 + 1] = {'\0'};
    strncpy(name, raw_name, 8);
    uint8_t i;
    for (i = 0; i < vic_funcs_len; i++) {
        if (strcmp(name, vic_funcs[i].name) == 0) {
            if (i < 4) {
                vic_funcs[i].p_func = ((void *)0);
                memset(vic_funcs[i].name, 0, 8);
            } else {
                uint8_t j;
                for (j = i; j < vic_funcs_len - 1; j++) {
                    vic_funcs[j].p_func = vic_funcs[j+1].p_func;
                    strcpy(vic_funcs[j].name, vic_funcs[j+1].name);
                }
                vic_funcs_len--;
            }
            return 0;
        }
    }
    return 2;
}

canonical_original_code:
unsigned char vic_fn_rm(char *raw_name)
{
    char name[-1] = {'\0'};
    strncpy(name, raw_name, 8);
    unsigned char i;
    for (i = 0; i < vic_funcs_len; i++) {
        if (strcmp(name, vic_funcs[i].name) == 0) {
            if (i < 4) {
                vic_funcs[i].p_func = ((void *)0);
                memset(vic_funcs[i].name, 0, 8);
            } else {
                unsigned char j;
                for (j = i; j < vic_funcs_len - 1; j++) {
                    vic_funcs[j].p_func = vic_funcs[j+1].p_func;
                    strcpy(vic_funcs[j].name, vic_funcs[j+1].name);
                }
                vic_funcs_len--;
            }
            return 0;
        }
    }
    return 2;
}

variable_types:
j
unsigned char