usage

decompiled_code:
int usage()
{
return puts(
"\n"
"DisPel v1 by James Churchill/pelrun (C)2001-2011\n"
"65816/SNES Disassembler\n"
"Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
" [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
" [-d <width>] [-o <outfile>] <infile>\n"
"\n"
"Options: (numbers are hex-only, no prefixes)\n"
" -n Skip $200 byte SMC header\n"
" -t Don't output addresses/hex dump.\n"
" -h/-l Force HiROM/LoROM memory mapping.\n"
" -s/-i Force enable/disable shadow ROM addresses (see readme.)\n"
" -a Start in 8-bit accumulator mode. Default is 16-bit.\n"
" -x Start in 8-bit X/Y mode. Default is 16-bit.\n"
" -e Turn off bank-boundary enforcement. (see readme.)\n"
" -p Split subroutines by placing blank lines after RTS,RTL,RTI\n"
" -b <bank> Disassemble bank <bank> only. Overrides -r.\n"
" -r <start>-<end> Disassemble block from <start> to <end>.\n"
" Omit -<end> to disassemble to end of file.\n"
" -g <origin> Set origin of disassembled code (see readme.)\n"
" -d <width> No disassembly - produce a hexdump with <width> bytes/line.\n"
" -o <outfile> Set file to redirect output to. Default is stdout.\n"
" <infile> File to disassemble.");
}

canonical_decompiled_code:
int func0()
{
return puts(
"\n"
"DisPel v1 by James Churchill/pelrun (C)2001-2011\n"
"65816/SNES Disassembler\n"
"Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
" [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
" [-d <width>] [-o <outfile>] <infile>\n"
"\n"
"Options: (numbers are hex-only, no prefixes)\n"
" -n Skip $200 byte SMC header\n"
" -t Don't output addresses/hex dump.\n"
" -h/-l Force HiROM/LoROM memory mapping.\n"
" -s/-i Force enable/disable shadow ROM addresses (see readme.)\n"
" -a Start in 8-bit accumulator mode. Default is 16-bit.\n"
" -x Start in 8-bit X/Y mode. Default is 16-bit.\n"
" -e Turn off bank-boundary enforcement. (see readme.)\n"
" -p Split subroutines by placing blank lines after RTS,RTL,RTI\n"
" -b <bank> Disassemble bank <bank> only. Overrides -r.\n"
" -r <start>-<end> Disassemble block from <start> to <end>.\n"
" Omit -<end> to disassemble to end of file.\n"
" -g <origin> Set origin of disassembled code (see readme.)\n"
" -d <width> No disassembly - produce a hexdump with <width> bytes/line.\n"
" -o <outfile> Set file to redirect output to. Default is stdout.\n"
" <infile> File to disassemble.");
}

original_code:
void usage(void)
{
 printf("\nDisPel v1 by James Churchill/pelrun (C)2001-2011\n"
  "65816/SNES Disassembler\n"
  "Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
  "              [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
  "              [-d <width>] [-o <outfile>] <infile>\n\n"
  "Options: (numbers are hex-only, no prefixes)\n"
  " -n                Skip $200 byte SMC header\n"
  " -t                Don't output addresses/hex dump.\n"
  " -h/-l             Force HiROM/LoROM memory mapping.\n"
  " -s/-i             Force enable/disable shadow ROM addresses (see readme.)\n"
  " -a                Start in 8-bit accumulator mode. Default is 16-bit.\n"
  " -x                Start in 8-bit X/Y mode. Default is 16-bit.\n"
  " -e                Turn off bank-boundary enforcement. (see readme.)\n"
  " -p                Split subroutines by placing blank lines after RTS,RTL,RTI\n"
  " -b <bank>         Disassemble bank <bank> only. Overrides -r.\n"
  " -r <start>-<end>  Disassemble block from <start> to <end>.\n"
  "                     Omit -<end> to disassemble to end of file.\n"
  " -g <origin>       Set origin of disassembled code (see readme.)\n"
  " -d <width>        No disassembly - produce a hexdump with <width> bytes/line.\n"
  " -o <outfile>      Set file to redirect output to. Default is stdout.\n"
  " <infile>          File to disassemble.\n");
}

canonical_original_code:
void usage()
{
 printf("\nDisPel v1 by James Churchill/pelrun (C)2001-2011\n"
  "65816/SNES Disassembler\n"
  "Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
  "              [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
  "              [-d <width>] [-o <outfile>] <infile>\n\n"
  "Options: (numbers are hex-only, no prefixes)\n"
  " -n                Skip $200 byte SMC header\n"
  " -t                Don't output addresses/hex dump.\n"
  " -h/-l             Force HiROM/LoROM memory mapping.\n"
  " -s/-i             Force enable/disable shadow ROM addresses (see readme.)\n"
  " -a                Start in 8-bit accumulator mode. Default is 16-bit.\n"
  " -x                Start in 8-bit X/Y mode. Default is 16-bit.\n"
  " -e                Turn off bank-boundary enforcement. (see readme.)\n"
  " -p                Split subroutines by placing blank lines after RTS,RTL,RTI\n"
  " -b <bank>         Disassemble bank <bank> only. Overrides -r.\n"
  " -r <start>-<end>  Disassemble block from <start> to <end>.\n"
  "                     Omit -<end> to disassemble to end of file.\n"
  " -g <origin>       Set origin of disassembled code (see readme.)\n"
  " -d <width>        No disassembly - produce a hexdump with <width> bytes/line.\n"
  " -o <outfile>      Set file to redirect output to. Default is stdout.\n"
  " <infile>          File to disassemble.\n");
}

return_type: void


AllASCII

repo: pelrun/Dispel

decompiled_code:
__int64 __fastcall AllASCII(_BYTE *a1, int a2)
{
_BYTE *v2; // rdx

if ( a2 <= 0 )
return 1LL;
v2 = a1;
while ( (unsigned __int8)(*v2 - 32) <= 0x5Eu )
{
if ( ++v2 == &a1[a2 - 1 + 1] )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, int a2)
{
_BYTE *v2; // rdx

if ( a2 <= 0 )
return 1LL;
v2 = a1;
while ( (unsigned __int8)(*v2 - 32) <= 0x5Eu )
{
if ( ++v2 == &a1[a2 - 1 + 1] )
return 1LL;
}
return 0LL;
}

original_code:
int AllASCII(unsigned char *b, int size)
{
 int i;
 for (i = 0; i < size; i++)
 {
  if (b[i] < 32 || b[i] > 126)
  {
   return 0;
  }
 }
 return 1;
}

variable_types:
b
unsigned char *

variable_types: size int

variable_types: i int

return_type: int


ScoreHiROM

original_code:
int ScoreHiROM(unsigned char *data)
{
 int score = 0;
 if ((data[0xFFDC] + data[0xFFDD]*256 + data[0xFFDE] + data[0xFFDF]*256) == 0xFFFF)
 {
  score += 2;
 }
 if (data[0xFFDA] == 0x33)
 {
  score += 2;
 }
 if ((data[0xFFD5] & 0xf) < 4)
 {
  score += 2;
 }
 if (!(data[0xFFFD] & 0x80))
 {
  score -= 4;
 }
 if ((1 << (data[0xFFD7] - 7)) > 48)
 {
  score -= 1;
 }
 if (!AllASCII(&data[0xFFB0], 6))
 {
  score -= 1;
 }
 if (!AllASCII(&data[0xFFC0], 20))
 {
  score -= 1;
 }
 return (score);
}

variable_types:
data
unsigned char *

variable_types: score int


ScoreLoROM

original_code:
int ScoreLoROM(unsigned char *data)
{
 int score = 0;
 if ((data[0x7FDC] + data[0x7FDD]*256 + data[0x7FDE] + data[0x7FDF]*256) == 0xFFFF)
 {
  score += 2;
 }
 if (data[0x7FDA] == 0x33)
 {
  score += 2;
 }
 if ((data[0x7FD5] & 0xf) < 4)
 {
  score += 2;
 }
 if (!(data[0x7FFD] & 0x80))
 {
  score -= 4;
 }
 if ((1 << (data[0x7FD7] - 7)) > 48)
 {
  score -= 1;
 }
 if (!AllASCII(&data[0x7FB0], 6))
 {
  score -= 1;
 }
 if (!AllASCII(&data[0x7FC0], 20))
 {
  score -= 1;
 }
 return (score);
}


hexdump

decompiled_code:
__int64 __fastcall hexdump(__int64 a1, int a2, unsigned __int64 a3, unsigned __int64 a4, char *a5, unsigned __int8 a6)
{
unsigned int v10; // er14
unsigned __int8 *v11; // rbx
char *v12; // rbp
unsigned __int8 *v13; // r13
unsigned __int8 *v14; // r12

sprintf(a5, "%02lX/%04lX:\t", BYTE2(a2), (unsigned __int16)a2);
v10 = a6;
if ( a6 && a3 < a4 )
{
v11 = (unsigned __int8 *)(a1 + a3);
v12 = a5 + 9;
v13 = &v11[a6 - 1];
v14 = (unsigned __int8 *)(a1 + a4);
do
{
sprintf(v12, "%02X", *v11);
if ( v11 == v13 )
break;
++v11;
v12 += 2;
}
while ( v11 != v14 );
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, unsigned __int64 a3, unsigned __int64 a4, char *a5, unsigned __int8 a6)
{
unsigned int v10; // er14
unsigned __int8 *v11; // rbx
char *v12; // rbp
unsigned __int8 *v13; // r13
unsigned __int8 *v14; // r12

sprintf(a5, "%02lX/%04lX:\t", BYTE2(a2), (unsigned __int16)a2);
v10 = a6;
if ( a6 && a3 < a4 )
{
v11 = (unsigned __int8 *)(a1 + a3);
v12 = a5 + 9;
v13 = &v11[a6 - 1];
v14 = (unsigned __int8 *)(a1 + a4);
do
{
sprintf(v12, "%02X", *v11);
if ( v11 == v13 )
break;
++v11;
v12 += 2;
}
while ( v11 != v14 );
}
return v10;
}

original_code:
int hexdump(unsigned char *data,unsigned long pos,unsigned long rpos,
   unsigned long len,char *inst, unsigned char dwidth)
{
 int i;
 sprintf(inst, "%02lX/%04lX:\t", (pos >> 16) & 0xFF, pos & 0xFFFF);
 for(i=0; i<dwidth && i+rpos<len; i++)
 {
  sprintf(inst + i*2 + 9, "%02X", data[rpos+i]);
 }
 return dwidth;
}

canonical_original_code:
int hexdump(unsigned char *data, unsigned long pos, unsigned long rpos, unsigned long len, char *inst, unsigned char dwidth)
{
 int i;
 sprintf(inst, "%02lX/%04lX:\t", (pos >> 16) & 0xFF, pos & 0xFFFF);
 for(i=0; i<dwidth && i+rpos<len; i++)
 {
  sprintf(inst + i*2 + 9, "%02X", data[rpos+i]);
 }
 return dwidth;
}

variable_types:
pos
unsigned long

variable_types:
rpos
unsigned long

variable_types:
len
unsigned long

variable_types:
inst
char *

variable_types:
dwidth
unsigned char


repo: pengjianzhang/simple-interpreter

decompiled_code:
int __fastcall interpreter_err(const char *a1)
{
return printf("line %d:%s\n", (unsigned int)interpreter_line_num, a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("line %d:%s\n", (unsigned int)interpreter_line_num, a1);
}

original_code:
void interpreter_err(char * msg)
{
 printf("line %d:%s\n", interpreter_line_num,msg);
}

canonical_original_code:
void interpreter_err(char *msg)
{
 printf("line %d:%s\n", interpreter_line_num,msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall new_expression_node(unsigned int a1, int *a2, _DWORD *a3)
{
void *v4; // rbx

if ( a2 && (a3 || operation_is_unitary(a1)) && expression_vtype_eq(a2, a3) && (unsigned int)operation_match(a1, *a2) )
{
v4 = malloc(0x18uLL);
if ( v4 )
{
interpreter_err("expression type not match");
free(v4);
}
}
else
{
interpreter_err("expression type not match");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int *a2, _DWORD *a3)
{
void *v4; // rbx

if ( a2 && (a3 || func5(a1)) && func1(a2, a3) && (unsigned int)func6(a1, *a2) )
{
v4 = malloc(0x18uLL);
if ( v4 )
{
func7("expression type not match");
free(v4);
}
}
else
{
func7("expression type not match");
}
return 0LL;
}

original_code:
struct expression_node * new_expression_node(enum operation_type opt, struct expression_node * en1, struct expression_node * en2)
{
 struct expression * e = ((void *)0);
 if(en1 == ((void *)0))
  goto err;
 else if((en2 == ((void *)0)) && (!_operation_is_unitary(opt)))
   goto err;
 else if(!expression_vtype_eq(en1,en2))
  goto err;
 if(!_operation_match(opt,en1->vtype)) goto err;
 e = (struct expression *)malloc(sizeof(struct expression));
 if(e == ((void *)0)) return ((void *)0);
 if(_operation_is_arithmetic(opt,2)){
 }
 else if( _operation_is_relation(opt,2)){
 }
 else if( _operation_is_logic(opt,2)){
 }
 else if( _operation_is_logic(opt,1)){
 }
 else
 {
  goto err;
 }
err:
 interpreter_err("expression type not match");
 if(e) free(e);
 return ((void *)0);
}

canonical_original_code:
struct expression_node *new_expression_node(enum operation_type opt, struct expression_node *en1, struct expression_node *en2)
{
 struct expression *e = ((void *)0);
 if(en1 == ((void *)0))
  goto err;
 else if((en2 == ((void *)0)) && (!_operation_is_unitary(opt)))
   goto err;
 else if(!expression_vtype_eq(en1,en2))
  goto err;
 if(!_operation_match(opt,en1->vtype)) goto err;
 e = (struct expression *)malloc(sizeof(struct expression));
 if(e == ((void *)0)) return ((void *)0);
 if(_operation_is_arithmetic(opt,2)){
 }
 else if( _operation_is_relation(opt,2)){
 }
 else if( _operation_is_logic(opt,2)){
 }
 else if( _operation_is_logic(opt,1)){
 }
 else
 {
  goto err;
 }
err:
 interpreter_err("expression type not match");
 if(e) free(e);
 return ((void *)0);
}

variable_types: struct expression { struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } enode; struct expression_node *op[2]; } *

return_type: struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } *

user_defined_types: struct expression { struct expression_node enode; struct expression_node *op[2]; }

user_defined_types: struct expression_node { enum value_type vtype; enum operation_type optype; }


decompiled_code:
void interpreter_read_file()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
struct script * interpreter_read_file(char * filename)
{
}

canonical_original_code:
struct script *interpreter_read_file(char *filename)
{
}

variable_types:
filename
char *

return_type: struct script { char name[64]; struct list_head { struct list_head *next; } stmt; struct variable { struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } enode; union { struct bg_string { char *str; int len; unsigned char cflag; } str; long integer; unsigned int boolean; } v; } varspace[]; } *

user_defined_types: struct script { char name[64]; struct list_head stmt; struct variable varspace[]; }

user_defined_types: struct variable { struct expression_node enode; union { struct bg_string str; long integer; unsigned int boolean; } v; }


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

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

original_code:
int interpreter_run(struct script * s)
{
 return 1;
}

canonical_original_code:
int interpreter_run(struct script *s)
{
 return 1;
}

variable_types: struct script { char name[64]; struct list_head { struct list_head *next; } stmt; struct variable { struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } enode; union { struct bg_string { char *str; int len; unsigned char cflag; } str; long integer; unsigned int boolean; } v; } varspace[]; } *


decompiled_code:
void sound_use()
{
++sound_use_count;
}

canonical_decompiled_code:
void func0()
{
++sound_use_count;
}

original_code:
static void sound_use(void)
{
 sound_use_count++;
}

canonical_original_code:
static void sound_use()
{
 sound_use_count++;
}


decompiled_code:
__int64 sound_unuse()
{
bool v0; // zf
__int64 result; // rax

v0 = sound_use_count == 1;
result = (unsigned int)--sound_use_count;
if ( v0 )
result = snd_config_update_free_global();
return result;
}

canonical_decompiled_code:
__int64 func2()
{
bool v0; // zf
__int64 result; // rax

v0 = sound_use_count == 1;
result = (unsigned int)--sound_use_count;
if ( v0 )
result = snd_config_update_free_global();
return result;
}

original_code:
static void sound_unuse(void)
{
 if (--sound_use_count == 0)
  snd_config_update_free_global();
}

canonical_original_code:
static void sound_unuse()
{
 if (--sound_use_count == 0)
  snd_config_update_free_global();
}


COORD

decompiled_code:
__int64 __fastcall COORD(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
static inline struct coord COORD(int x, int y) {
 return (struct coord){ .x = x, .y = y };
}

variable_types: x int

variable_types: y int

return_type: struct coord { union { int x; }; union { int y; }; }


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

if ( a1 == 1 )
{
result = *(unsigned int *)(view + 24);
scroll_offset_start = *(_DWORD *)(view + 24);
}
else if ( a1 == 2 )
{
zooming = 1;
result = **(_QWORD **)(view + 16);
thumb_dim_start = result;
}
return result;
}

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

if ( a1 == 1 )
{
result = *(unsigned int *)(view + 24);
scroll_offset_start = *(_DWORD *)(view + 24);
}
else if ( a1 == 2 )
{
zooming = 1;
result = **(_QWORD **)(view + 16);
thumb_dim_start = result;
}
return result;
}

original_code:
static void eh_drag_start(int button, struct coord start) {
 if (button == 1) {
  scroll_offset_start = view->scroll_offset;
 } else if (button == 2) {
  zooming = 1;
  thumb_dim_start = view->frame->thumb_dim;
 }
}

variable_types: button int

variable_types: struct coord { union { int x; }; union { int y; }; }


decompiled_code:
void __fastcall eh_drag_stop(int a1)
{
if ( a1 == 2 )
zooming = 0;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
if ( a1 == 2 )
zooming = 0;
}

original_code:
static void eh_drag_stop(int button) {
 if (button == 2) {
  zooming = 0;
 }
}


decompiled_code:
__int64 __fastcall eh_drag_update(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rsi
__int64 *v6; // rbx
__int64 v7; // rbx

v3 = a2 >> 32;
result = a3 >> 32;
if ( a1 == 1 )
{
v5 = view;
result = (unsigned int)(HIDWORD(a3) - v3);
*(_DWORD *)(view + 24) = scroll_offset_start - result;
*(_DWORD *)(v5 + 28) = 1;
}
else if ( a1 == 2 )
{
v6 = *(__int64 **)(view + 16);
*v6 = COORD(
(int)thumb_dim_start + (int)a3 - (int)a2,
(unsigned int)(HIDWORD(thumb_dim_start) + HIDWORD(a3) - HIDWORD(a2)));
v7 = *(_QWORD *)(view + 8);
*(_QWORD *)(v7 + 16) = (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(view + 16) + 24LL))(*(_QWORD *)(view + 16));
layout_recompute(*(_QWORD *)(view + 8));
result = view;
*(_DWORD *)(view + 28) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rsi
__int64 *v6; // rbx
__int64 v7; // rbx

v3 = a2 >> 32;
result = a3 >> 32;
if ( a1 == 1 )
{
v5 = view;
result = (unsigned int)(HIDWORD(a3) - v3);
*(_DWORD *)(view + 24) = scroll_offset_start - result;
*(_DWORD *)(v5 + 28) = 1;
}
else if ( a1 == 2 )
{
v6 = *(__int64 **)(view + 16);
*v6 = func0(
(int)thumb_dim_start + (int)a3 - (int)a2,
(unsigned int)(HIDWORD(thumb_dim_start) + HIDWORD(a3) - HIDWORD(a2)));
v7 = *(_QWORD *)(view + 8);
*(_QWORD *)(v7 + 16) = (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(view + 16) + 24LL))(*(_QWORD *)(view + 16));
layout_recompute(*(_QWORD *)(view + 8));
result = view;
*(_DWORD *)(view + 28) = 1;
}
return result;
}

original_code:
static void eh_drag_update(int button, struct coord start, struct coord pointer) {
 if (button == 1) {
  view->scroll_offset = scroll_offset_start - (pointer.y - start.y);
  view->dirty = 1;
 } else if (button == 2) {
  view->frame->thumb_dim = COORD(
   thumb_dim_start.width + (pointer.x - start.x),
   thumb_dim_start.height + (pointer.y - start.y)
  );
  view->layout->frame = view->frame->frame_size(view->frame);
  layout_recompute(view->layout);
  view->dirty = 1;
 }
}

variable_types:
pointer
struct coord

user_defined_types: struct coord { union { int x; }; union { int y; }; }


decompiled_code:
__pid_t __fastcall eh_click(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__pid_t result; // eax
__pid_t v5; // ebx
char **v6; // rbp
const char ***v7; // r13
int v8; // er12
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v2 = view;
v3 = COORD(a2, (unsigned int)(*(_DWORD *)(view + 24) + HIDWORD(a2)));
result = layout_frame_number_by_coord(*(_QWORD *)(v2 + 8), v3);
if ( result != -1 )
{
v5 = result;
result = fork();
if ( !result )
{
if ( fork() )
exit(0);
v6 = (char **)malloc(8LL * (*(_DWORD *)(*(_QWORD *)(view + 8) + 24LL) + 4));
v7 = (const char ***)thumbnails;
v8 = 3;
while ( *v7 )
{
stat(**v7, &v9);
if ( (v9.st_mode & 0xF000) == 0x8000 )
v6[v8++] = (char *)**v7;
++v7;
}
*v6 = "feh";
v6[1] = "--start-at";
v6[2] = **(char ***)(thumbnails + 8LL * v5);
v6[v8] = 0LL;
execvp("feh", v6);
perror("exec");
exit(1);
}
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__pid_t result; // eax
__pid_t v5; // ebx
char **v6; // rbp
const char ***v7; // r13
int v8; // er12
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v2 = view;
v3 = func0(a2, (unsigned int)(*(_DWORD *)(view + 24) + HIDWORD(a2)));
result = layout_frame_number_by_coord(*(_QWORD *)(v2 + 8), v3);
if ( result != -1 )
{
v5 = result;
result = fork();
if ( !result )
{
if ( fork() )
exit(0);
v6 = (char **)malloc(8LL * (*(_DWORD *)(*(_QWORD *)(view + 8) + 24LL) + 4));
v7 = (const char ***)thumbnails;
v8 = 3;
while ( *v7 )
{
stat(**v7, &v9);
if ( (v9.st_mode & 0xF000) == 0x8000 )
v6[v8++] = (char *)**v7;
++v7;
}
*v6 = "feh";
v6[1] = "--start-at";
v6[2] = **(char ***)(thumbnails + 8LL * v5);
v6[v8] = 0LL;
execvp("feh", v6);
perror("exec");
exit(1);
}
}
return result;
}

original_code:
static void eh_click(int button, struct coord pos) {
 int n = layout_frame_number_by_coord(view->layout, COORD(pos.x, pos.y + view->scroll_offset));
 if (n == -1) {
 } else {
  if (!fork()) {
   if (!fork()) {
    char **varg = malloc(sizeof(char*) * (view->layout->frame_count + 4));
    int va = 3;
    struct thumbnail **p = thumbnails;
    while (*p != ((void *)0)) {
     struct stat s;
     stat((*p)->filename, &s);
     if (((((s.st_mode)) & 0170000) == (0100000))) {
      varg[va] = (*p)->filename;
      va++;
     }
     p++;
    }
    varg[0] = "feh";
    varg[1] = "--start-at";
    varg[2] = thumbnails[n]->filename;
    varg[va] = ((void *)0);
    execvp("feh", varg);
    perror("exec");
    exit(1);
   }
   exit(0);
  }
 }
}

variable_types: n int

variable_types:
varg
char **

variable_types: va int

variable_types: struct thumbnail { char *filename; void *imlib; struct coord { union { int x; }; union { int y; }; } thumb_dim; int size; int failed; } **

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

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

user_defined_types: struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // er15
__int64 i; // rbx
void **v6; // rbp
__int64 v7; // rbp
__int64 v8; // rbx
__int64 *v9; // rbx
__int64 v10; // rbx
__int64 *v11; // rbx
__int64 v12; // rbx
__int64 v13; // rbp
__int64 v14; // rax
__int64 v15; // rbx
__int64 v16; // rax
struct dirent **namelist; // [rsp+8h] [rbp-40h] BYREF

if ( argc != 2 )
{
fwrite("thumbnail must be invoked with a single argument specifying the directory to load\n", 1uLL, 0x52uLL, stderr);
exit(1);
}
x11 = x11_connect(2, argv, envp);
x11_setup_imlib(x11);
input_set_click_handler(eh_click);
input_set_drag_handlers(eh_drag_start, eh_drag_stop, eh_drag_update);
view = view_new();
*(_QWORD *)view = surface_new();
**(_QWORD **)view = x11;
v3 = *(_QWORD *)view;
*(_QWORD *)(v3 + 8) = x11_make_window();
XStoreName(*(Display **)x11, *(_QWORD *)(*(_QWORD *)view + 8LL), argv[1]);
XFlush(*(Display **)x11);
v4 = scandir(argv[1], &namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
thumbnails = malloc(8LL * (v4 + 1));
if ( v4 > 0 )
{
for ( i = 0LL; i != v4; ++i )
{
v6 = (void **)(thumbnails + i * 8);
*v6 = malloc(0x20uLL);
v7 = *(_QWORD *)(thumbnails + i * 8);
asprintf((char **)v7, "%s/%s", argv[1], namelist[i]->d_name);
*(_DWORD *)(v7 + 28) = 0;
*(_QWORD *)(v7 + 8) = 0LL;
free(namelist[i]);
}
}
free(namelist);
*(_QWORD *)(thumbnails + 8LL * (v4 + 1) - 8) = 0LL;
v8 = view;
*(_QWORD *)(v8 + 16) = frame_new_symbols();
v9 = *(__int64 **)(view + 16);
*v9 = COORD(0xC8u, 150LL);
v10 = view;
*(_QWORD *)(v10 + 8) = layout_new();
v11 = *(__int64 **)(view + 8);
*v11 = COORD(0, 0LL);
v12 = view;
v13 = *(_QWORD *)(view + 8);
*(_QWORD *)(v13 + 8) = COORD(0x14u, 20LL);
v14 = *(_QWORD *)(v12 + 16);
v15 = *(_QWORD *)(v12 + 8);
*(_QWORD *)(v15 + 16) = (*(__int64 (__fastcall **)(__int64))(v14 + 24))(v14);
v16 = view;
*(_DWORD *)(*(_QWORD *)(view + 8) + 24LL) = v4;
layout_recompute(*(_QWORD *)(v16 + 8));
must_update = 1;
event_loop(*(Display **)x11);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // er15
__int64 i; // rbx
void **v6; // rbp
__int64 v7; // rbp
__int64 v8; // rbx
__int64 *v9; // rbx
__int64 v10; // rbx
__int64 *v11; // rbx
__int64 v12; // rbx
__int64 v13; // rbp
__int64 v14; // rax
__int64 v15; // rbx
__int64 v16; // rax
struct dirent **namelist; // [rsp+8h] [rbp-40h] BYREF

if ( argc != 2 )
{
fwrite("thumbnail must be invoked with a single argument specifying the directory to load\n", 1uLL, 0x52uLL, stderr);
exit(1);
}
x11 = x11_connect(2, argv, envp);
x11_setup_imlib(x11);
input_set_click_handler(eh_click);
input_set_drag_handlers(eh_drag_start, eh_drag_stop, eh_drag_update);
view = view_new();
*(_QWORD *)view = surface_new();
**(_QWORD **)view = x11;
v3 = *(_QWORD *)view;
*(_QWORD *)(v3 + 8) = x11_make_window();
XStoreName(*(Display **)x11, *(_QWORD *)(*(_QWORD *)view + 8LL), argv[1]);
XFlush(*(Display **)x11);
v4 = scandir(argv[1], &namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
thumbnails = malloc(8LL * (v4 + 1));
if ( v4 > 0 )
{
for ( i = 0LL; i != v4; ++i )
{
v6 = (void **)(thumbnails + i * 8);
*v6 = malloc(0x20uLL);
v7 = *(_QWORD *)(thumbnails + i * 8);
asprintf((char **)v7, "%s/%s", argv[1], namelist[i]->d_name);
*(_DWORD *)(v7 + 28) = 0;
*(_QWORD *)(v7 + 8) = 0LL;
free(namelist[i]);
}
}
free(namelist);
*(_QWORD *)(thumbnails + 8LL * (v4 + 1) - 8) = 0LL;
v8 = view;
*(_QWORD *)(v8 + 16) = frame_new_symbols();
v9 = *(__int64 **)(view + 16);
*v9 = func0(0xC8u, 150LL);
v10 = view;
*(_QWORD *)(v10 + 8) = layout_new();
v11 = *(__int64 **)(view + 8);
*v11 = func0(0, 0LL);
v12 = view;
v13 = *(_QWORD *)(view + 8);
*(_QWORD *)(v13 + 8) = func0(0x14u, 20LL);
v14 = *(_QWORD *)(v12 + 16);
v15 = *(_QWORD *)(v12 + 8);
*(_QWORD *)(v15 + 16) = (*(__int64 (__fastcall **)(__int64))(v14 + 24))(v14);
v16 = view;
*(_DWORD *)(*(_QWORD *)(view + 8) + 24LL) = v4;
layout_recompute(*(_QWORD *)(v16 + 8));
must_update = 1;
func6(*(Display **)x11);
}

original_code:
int main(int argc, char *argv[]) {
 if (argc != 2) {
  fputs("thumbnail must be invoked with a single argument specifying the directory to load\n", stderr);
  exit(1);
 }
 x11 = x11_connect();
 x11_setup_imlib(x11);
 input_set_click_handler(eh_click);
 input_set_drag_handlers(eh_drag_start, eh_drag_stop, eh_drag_update);
 view = view_new();
 view->surface = surface_new();
 view->surface->x11 = x11;
 view->surface->window = x11_make_window(x11);
 XStoreName(x11->display, view->surface->window, argv[1]);
 XFlush(x11->display);
 struct dirent **dir_entries;
 int dir_count = scandir(argv[1], &dir_entries, ((void *)0), alphasort);
 thumbnails = malloc(sizeof(struct thumbnail *) * (dir_count + 1));
 for (int i = 0; i < dir_count; i++) {
  thumbnails[i] = malloc(sizeof(struct thumbnail));
  struct thumbnail *t = thumbnails[i];
  char *fn = dir_entries[i]->d_name;
  asprintf(&t->filename, "%s/%s", argv[1], fn);
  t->failed = 0;
  t->imlib = ((void *)0);
  free(dir_entries[i]);
 }
 free(dir_entries);
 thumbnails[dir_count] = ((void *)0);
 view->frame = frame_new_symbols();
 view->frame->thumb_dim = COORD(200, 150);
 view->layout = layout_new();
 view->layout->window = COORD(0, 0);
 view->layout->spacing = COORD(20, 20);
 view->layout->frame = view->frame->frame_size(view->frame);
 view->layout->frame_count = dir_count;
 layout_recompute(view->layout);
 must_update = 1;
 event_loop(x11->display, 0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types: i int

variable_types: struct thumbnail { char *filename; void *imlib; struct coord { union { int x; }; union { int y; }; } thumb_dim; int size; int failed; } *

variable_types:
fn
char *


COORD

canonical_original_code:
static inline struct coord COORD(int x, int y) {
 return (struct coord){ .x = x, .y = y };
}


decompiled_code:
__int64 __fastcall symbols_frame_size(unsigned int *a1)
{
return COORD(*a1, a1[1] + 12);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return func0(*a1, a1[1] + 12);
}

original_code:
static struct coord symbols_frame_size(struct frame *frame) {
 return COORD(frame->thumb_dim.width, frame->thumb_dim.height + 12);
}

variable_types: struct frame { struct coord thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; } *, struct rect { struct coord tl; struct coord dim; }); struct coord (*frame_size)(struct frame *); } *

user_defined_types: struct frame { struct coord thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail *, struct rect); struct coord (*frame_size)(struct frame *); }


decompiled_code:
void __fastcall symbols_render(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // er13
__int64 v7; // r14
__int64 v8; // rax
const char *v9; // r15
char *v10; // rax
size_t v11; // rax
char *v12; // r12
__int64 v13; // rax
__int64 v14; // rdi
int v15; // [rsp+8h] [rbp-40h] BYREF
char v16[60]; // [rsp+Ch] [rbp-3Ch] BYREF

v5 = a3;
v7 = a3 >> 32;
v8 = symbols_frame_size(a1);
if ( v8 != a4 )
fprintf(
stderr,
"[-] target frame size %dx%d does not match configured one %dx%d\n",
(unsigned int)a4,
a4 >> 32,
(unsigned int)v8,
v8 >> 32);
if ( *(_QWORD *)(a2 + 8) && !*(_DWORD *)(a2 + 28) )
{
v13 = coord_scale_to_fit(*(_QWORD *)(a2 + 16), *(_QWORD *)a1);
imlib_blend_image_onto_image(
*(_QWORD *)(a2 + 8),
1LL,
0LL,
0LL,
*(unsigned int *)(a2 + 16),
*(unsigned int *)(a2 + 20),
(unsigned int)(v5 + (int)(*a1 - v13) / 2),
(unsigned int)(v7 + (int)(a1[1] - HIDWORD(v13)) / 2),
v13,
v13 >> 32);
}
if ( *((_QWORD *)a1 + 1)
|| (imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu"),
v14 = imlib_load_font("DejaVuSans/10"),
(*((_QWORD *)a1 + 1) = v14) != 0LL) )
{
imlib_context_set_font();
imlib_context_set_color(255LL, 255LL, 255LL, 255LL);
v9 = *(const char **)a2;
v10 = strrchr(*(const char **)a2, 47);
if ( v10 )
v9 = v10 + 1;
v11 = strlen(v9);
v12 = (char *)malloc(v11 + 1);
strcpy(v12, v9);
imlib_get_text_size(v12, &v15, v16);
imlib_text_draw((unsigned int)(((int)a4 - v15) / 2 + v5), a1[1] + (unsigned int)v7, v12);
free(v12);
}
}

canonical_decompiled_code:
void __fastcall func2(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // er13
__int64 v7; // r14
__int64 v8; // rax
const char *v9; // r15
char *v10; // rax
size_t v11; // rax
char *v12; // r12
__int64 v13; // rax
__int64 v14; // rdi
int v15; // [rsp+8h] [rbp-40h] BYREF
char v16[60]; // [rsp+Ch] [rbp-3Ch] BYREF

v5 = a3;
v7 = a3 >> 32;
v8 = func1(a1);
if ( v8 != a4 )
fprintf(
stderr,
"[-] target frame size %dx%d does not match configured one %dx%d\n",
(unsigned int)a4,
a4 >> 32,
(unsigned int)v8,
v8 >> 32);
if ( *(_QWORD *)(a2 + 8) && !*(_DWORD *)(a2 + 28) )
{
v13 = coord_scale_to_fit(*(_QWORD *)(a2 + 16), *(_QWORD *)a1);
imlib_blend_image_onto_image(
*(_QWORD *)(a2 + 8),
1LL,
0LL,
0LL,
*(unsigned int *)(a2 + 16),
*(unsigned int *)(a2 + 20),
(unsigned int)(v5 + (int)(*a1 - v13) / 2),
(unsigned int)(v7 + (int)(a1[1] - HIDWORD(v13)) / 2),
v13,
v13 >> 32);
}
if ( *((_QWORD *)a1 + 1)
|| (imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu"),
v14 = imlib_load_font("DejaVuSans/10"),
(*((_QWORD *)a1 + 1) = v14) != 0LL) )
{
imlib_context_set_font();
imlib_context_set_color(255LL, 255LL, 255LL, 255LL);
v9 = *(const char **)a2;
v10 = strrchr(*(const char **)a2, 47);
if ( v10 )
v9 = v10 + 1;
v11 = strlen(v9);
v12 = (char *)malloc(v11 + 1);
strcpy(v12, v9);
imlib_get_text_size(v12, &v15, v16);
imlib_text_draw((unsigned int)(((int)a4 - v15) / 2 + v5), a1[1] + (unsigned int)v7, v12);
free(v12);
}
}

original_code:
static void symbols_render(struct frame *frame, struct thumbnail *t, struct rect target) {
 struct coord _rc1 = symbols_frame_size(frame);
 struct coord _rc2 = target.dim;
 if (_rc1.x != _rc2.x || _rc1.y != _rc2.y) {
  fprintf(stderr, "[-] target frame size %dx%d does not match configured one %dx%d\n",
   _rc2.x, _rc2.y, _rc1.x, _rc1.y
  );
 }
 if (t->imlib != ((void *)0) && !t->failed) {
  struct coord render_dim = coord_scale_to_fit(
   t->thumb_dim,
   frame->thumb_dim
  );
  imlib_blend_image_onto_image(t->imlib, 1,
               0, 0, t->thumb_dim.width, t->thumb_dim.height,
    target.tl.x + (frame->thumb_dim.width - render_dim.width ) / 2,
    target.tl.y + (frame->thumb_dim.height - render_dim.height) / 2,
    render_dim.width, render_dim.height
  );
 }
 if (frame->font == ((void *)0)) {
  imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu");
  frame->font = imlib_load_font("DejaVuSans/10");
 }
 if (frame->font != ((void *)0)) {
  imlib_context_set_font(frame->font);
  imlib_context_set_color(255, 255, 255, 255);
  char *basename = strrchr(t->filename, '/');
  if (basename == ((void *)0)) {
   basename = t->filename;
  } else {
   basename++;
  }
  char *text = malloc(sizeof(char) * (strlen(basename) + 1));
  strcpy(text, basename);
  int textwidth, textheight;
  imlib_get_text_size(text, &textwidth, &textheight);
  int tx, ty;
  tx = target.tl.x + (target.dim.width - textwidth) / 2;
  ty = target.tl.y + frame->thumb_dim.height;
  imlib_text_draw(tx, ty, text);
  free(text);
 }
}

canonical_original_code:
static void symbols_render(struct frame *frame, struct thumbnail *t, struct rect target) {
 struct coord _rc1 = symbols_frame_size(frame);
 struct coord _rc2 = target.dim;
 if (_rc1.x != _rc2.x || _rc1.y != _rc2.y) {
  fprintf(stderr, "[-] target frame size %dx%d does not match configured one %dx%d\n",
   _rc2.x, _rc2.y, _rc1.x, _rc1.y
  );
 }
 if (t->imlib != ((void *)0) && !t->failed) {
  struct coord render_dim = coord_scale_to_fit(
   t->thumb_dim,
   frame->thumb_dim
  );
  imlib_blend_image_onto_image(t->imlib, 1,
               0, 0, t->thumb_dim.width, t->thumb_dim.height,
    target.tl.x + (frame->thumb_dim.width - render_dim.width ) / 2,
    target.tl.y + (frame->thumb_dim.height - render_dim.height) / 2,
    render_dim.width, render_dim.height
  );
 }
 if (frame->font == ((void *)0)) {
  imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu");
  frame->font = imlib_load_font("DejaVuSans/10");
 }
 if (frame->font != ((void *)0)) {
  imlib_context_set_font(frame->font);
  imlib_context_set_color(255, 255, 255, 255);
  char *basename = strrchr(t->filename, '/');
  if (basename == ((void *)0)) {
   basename = t->filename;
  } else {
   basename++;
  }
  char *text = malloc(sizeof(char) * (strlen(basename) + 1));
  strcpy(text, basename);
  int textwidth; int textheight;
  imlib_get_text_size(text, &textwidth, &textheight);
  int tx; int ty;
  tx = target.tl.x + (target.dim.width - textwidth) / 2;
  ty = target.tl.y + frame->thumb_dim.height;
  imlib_text_draw(tx, ty, text);
  free(text);
 }
}

variable_types: struct frame { struct coord { union { int x; }; union { int y; }; } thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; } *, struct rect { struct coord tl; struct coord dim; }); struct coord (*frame_size)(struct frame *); } *

variable_types:
t
struct thumbnail *

variable_types:
target
struct rect

variable_types:
basename
char *

variable_types:
text
char *

variable_types: textwidth int

variable_types: textheight int

variable_types: tx int

variable_types: ty int


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

result = malloc(0x20uLL);
result[3] = symbols_frame_size;
result[2] = symbols_render;
result[1] = 0LL;
return result;
}

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

result = malloc(0x20uLL);
result[3] = symbols_frame_size;
result[2] = symbols_render;
result[1] = 0LL;
return result;
}

original_code:
struct frame *frame_new_symbols() {
 struct frame *f = malloc(sizeof(struct frame));
 f->frame_size = symbols_frame_size;
 f->render = symbols_render;
 f->font = ((void *)0);
 return f;
}

return_type: struct frame { struct coord { union { int x; }; union { int y; }; } thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; } *, struct rect { struct coord tl; struct coord dim; }); struct coord (*frame_size)(struct frame *); } *


reaper

repo: beghbali/StackOverflowExploit

decompiled_code:
void reaper()
{
signal(17, reaper);
if ( verbose )
write(2, "reaper: ", 8uLL);
if ( wait(0LL) > 0 )
{
++servers_allowed;
if ( !verbose )
return;
write(2, ".", 1uLL);
}
if ( verbose )
write(2, " reaped\n", 8uLL);
}

canonical_decompiled_code:
void func0()
{
signal(17, reaper);
if ( verbose )
write(2, "reaper: ", 8uLL);
if ( wait(0LL) > 0 )
{
++servers_allowed;
if ( !verbose )
return;
write(2, ".", 1uLL);
}
if ( verbose )
write(2, " reaped\n", 8uLL);
}

original_code:
void reaper(void)
{
 (void) signal(17,(void (*)(int)) reaper);
 if (verbose) write(2,"reaper: ",8);
 if (wait((int *) 0) > 0) {
  ++servers_allowed;
  if (verbose) write(2,".",1);
 }
 if (verbose) write(2," reaped\n",8);
}

canonical_original_code:
void reaper()
{
 (void) signal(17,(void (*)(int)) reaper);
 if (verbose) write(2,"reaper: ",8);
 if (wait((int *) 0) > 0) {
  ++servers_allowed;
  if (verbose) write(2,".",1);
 }
 if (verbose) write(2," reaped\n",8);
}


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"Usage: %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",
(const char *)me);
}

canonical_decompiled_code:
int func2()
{
return fprintf(
stderr,
"Usage: %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",
(const char *)me);
}

original_code:
void usage(void)
{
 fprintf(stderr,"Usage:  %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",me);
}

canonical_original_code:
void usage()
{
 fprintf(stderr,"Usage:  %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",me);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int v4; // er13
unsigned __int16 v5; // r12
int v6; // er15
int v7; // eax
int v8; // eax
int v9; // ebx
unsigned int v10; // ebp
__pid_t v11; // eax
int v12; // eax
int v13; // ebx
char *v14; // rax
char *v15; // rax
int v16; // eax
int v18; // [rsp+Ch] [rbp-15Ch]
char s[264]; // [rsp+10h] [rbp-158h] BYREF
socklen_t addr_len; // [rsp+118h] [rbp-50h] BYREF
int optval; // [rsp+11Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+120h] [rbp-48h] BYREF

me = (__int64)strrchr(*argv, 47);
v3 = (const char *)(me + 1);
if ( !me )
v3 = *argv;
me = (__int64)v3;
v18 = -1;
v4 = 0;
v5 = 5103;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "c:lLp:s:Dv");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'D':
v6 = 1;
break;
case 'L':
v4 = 0;
break;
case 'c':
v18 = atoi(optarg);
break;
case 'l':
v4 = 1;
break;
case 'p':
v5 = atoi(optarg);
break;
case 's':
servers_allowed = atoi(optarg);
break;
case 'v':
++verbose;
break;
default:
usage();
exit(1);
}
}
if ( verbose )
printf("Address of sockaddr is %p\n", &addr);
if ( v6 )
{
v12 = open("/dev/tty", 0, 0LL);
v13 = v12;
if ( v12 != -1 )
{
ioctl(v12, 0x5422uLL, 0LL);
close(v13);
}
}
v8 = socket(2, 1, 0);
v9 = v8;
if ( v8 != -1 )
{
optval = 1;
if ( setsockopt(v8, 1, 2, &optval, 4u) != -1 )
{
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(v5);
if ( bind(v9, &addr, 0x10u) != -1 )
{
if ( listen(v9, 4) != -1 )
{
signal(17, (__sighandler_t)reaper);
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v10 = accept(v9, &addr, &addr_len);
if ( v10 == -1 )
break;
if ( verbose )
{
v14 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
fprintf(stderr, "[%s]\n", v14);
}
if ( v4 )
{
v15 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "rpc_server: Connect on port %d from %s", v5, v15);
syslog(30, s);
}
v11 = fork();
if ( v11 == -1 )
{
perror("fork");
exit(1);
}
if ( !v11 )
{
close(v9);
rpc_service(v10);
exit(0);
}
close(v10);
--servers_allowed;
v16 = v18;
if ( v18 > 0 )
{
--v18;
if ( v16 == 1 )
exit(0);
}
while ( !servers_allowed )
{
if ( verbose )
fwrite("Pausing\n", 1uLL, 8uLL, stderr);
pause();
if ( verbose )
fprintf(stderr, "paused, servers_allowed %ld\n", servers_allowed);
}
}
if ( *_errno_location() != 4 )
{
perror("accept");
exit(1);
}
}
}
perror("listen");
exit(1);
}
perror("bind");
exit(1);
}
perror("setsockoopt");
exit(1);
}
perror("socket");
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int v4; // er13
unsigned __int16 v5; // r12
int v6; // er15
int v7; // eax
int v8; // eax
int v9; // ebx
unsigned int v10; // ebp
__pid_t v11; // eax
int v12; // eax
int v13; // ebx
char *v14; // rax
char *v15; // rax
int v16; // eax
int v18; // [rsp+Ch] [rbp-15Ch]
char s[264]; // [rsp+10h] [rbp-158h] BYREF
socklen_t addr_len; // [rsp+118h] [rbp-50h] BYREF
int optval; // [rsp+11Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+120h] [rbp-48h] BYREF

me = (__int64)strrchr(*argv, 47);
v3 = (const char *)(me + 1);
if ( !me )
v3 = *argv;
me = (__int64)v3;
v18 = -1;
v4 = 0;
v5 = 5103;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "c:lLp:s:Dv");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'D':
v6 = 1;
break;
case 'L':
v4 = 0;
break;
case 'c':
v18 = atoi(optarg);
break;
case 'l':
v4 = 1;
break;
case 'p':
v5 = atoi(optarg);
break;
case 's':
servers_allowed = atoi(optarg);
break;
case 'v':
++verbose;
break;
default:
func2();
exit(1);
}
}
if ( verbose )
printf("Address of sockaddr is %p\n", &addr);
if ( v6 )
{
v12 = open("/dev/tty", 0, 0LL);
v13 = v12;
if ( v12 != -1 )
{
ioctl(v12, 0x5422uLL, 0LL);
close(v13);
}
}
v8 = socket(2, 1, 0);
v9 = v8;
if ( v8 != -1 )
{
optval = 1;
if ( setsockopt(v8, 1, 2, &optval, 4u) != -1 )
{
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func1(v5);
if ( bind(v9, &addr, 0x10u) != -1 )
{
if ( listen(v9, 4) != -1 )
{
signal(17, (__sighandler_t)reaper);
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v10 = accept(v9, &addr, &addr_len);
if ( v10 == -1 )
break;
if ( verbose )
{
v14 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
fprintf(stderr, "[%s]\n", v14);
}
if ( v4 )
{
v15 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "rpc_server: Connect on port %d from %s", v5, v15);
syslog(30, s);
}
v11 = fork();
if ( v11 == -1 )
{
perror("fork");
exit(1);
}
if ( !v11 )
{
close(v9);
rpc_service(v10);
exit(0);
}
close(v10);
--servers_allowed;
v16 = v18;
if ( v18 > 0 )
{
--v18;
if ( v16 == 1 )
exit(0);
}
while ( !servers_allowed )
{
if ( verbose )
fwrite("Pausing\n", 1uLL, 8uLL, stderr);
pause();
if ( verbose )
fprintf(stderr, "paused, servers_allowed %ld\n", servers_allowed);
}
}
if ( *_errno_location() != 4 )
{
perror("accept");
exit(1);
}
}
}
perror("listen");
exit(1);
}
perror("bind");
exit(1);
}
perror("setsockoopt");
exit(1);
}
perror("socket");
exit(1);
}

original_code:
int main(int ac,
  char **av)
{
 int s, ss;
 struct sockaddr_in name;
 int set,ch,namelen;
 int detach;
 u_short port = 5103;
 int log = 0, count = -1;
 extern int getopt(), optind;
 extern char *optarg;
 (void) copyright;
 me = strrchr(av[0],'/');
 if (!me) me = av[0]; else ++me;
 detach = 0;
 while ((ch = getopt(ac,av,"c:lLp:s:Dv")) != (-1)) switch (ch) {
 case 'c': count = atoi(optarg); break;
 case 'l': log = 1; break;
 case 'L': log = 0; break;
 case 'p': port = atoi(optarg); break;
 case 's': servers_allowed = atoi(optarg); break;
 case 'D': detach = 1; break;
 case 'v': verbose++; break;
 default: usage(); exit(1);
 }
 if (verbose) {
  printf("Address of sockaddr is %p\n",&name);
 }
 if (detach) {
  int i;
  i = open("/dev/tty",00,0);
  if (i != -1) {
   (void) ioctl(i,0x5422,(char *) 0);
   (void) close(i);
  }
 }
 if ((s = socket(2,SOCK_STREAM,0)) == -1) {
  perror("socket");
  exit(1);
 }
 set = 1;
 if (setsockopt(s,1,2,(const char *) &set, sizeof(set)) == -1) {
  perror("setsockoopt");
  exit(1);
 }
 memset((char *)&name,0,sizeof(name));
 name.sin_family = 2;
 name.sin_port = htons(port);
 if (bind(s,(struct sockaddr *) &name,sizeof(name)) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(s,4) == -1) {
  perror("listen");
  exit(1);
 }
 (void) signal(17,(void (*)(int)) reaper);
again:
 while ((namelen = sizeof name), ((ss = accept(s,(struct sockaddr *)&name,&namelen)) != -1)) {
  if (verbose) {
   fprintf(stderr,"[%s]\n",inet_ntoa(name.sin_addr));
  }
  if (log) {
   char buf[256];
   sprintf(buf,"rpc_server: Connect on port %d from %s",port,inet_ntoa(name.sin_addr));
   syslog(6 | (3<<3),buf);
  }
  switch (fork()) {
  case 0:
   (void) close(s);
   rpc_service(ss);
   exit(0);
  case -1:
   perror("fork");
   exit(1);
  default:
   (void) close(ss);
   --servers_allowed;
   break;
  }
  if (count > 0 && --count == 0) exit(0);
  while (!servers_allowed) {
   if (verbose) fprintf(stderr,"Pausing\n");
   pause();
   if (verbose) fprintf(stderr,"paused, servers_allowed %ld\n",servers_allowed);
  }
 }
 if ((*__errno_location ()) == 4) goto again;
 perror("accept");
 exit(1);
}

canonical_original_code:
int main(int ac, char **av)
{
 int s; int ss;
 struct sockaddr_in name;
 int set; int ch; int namelen;
 int detach;
 unsigned short port = 5103;
 int log = 0; int count = -1;
 extern int getopt(); extern int optind;
 extern char *optarg;
 (void) copyright;
 me = strrchr(av[0],'/');
 if (!me) me = av[0]; else ++me;
 detach = 0;
 while ((ch = getopt(ac,av,"c:lLp:s:Dv")) != (-1)) switch (ch) {
 case 'c': count = atoi(optarg); break;
 case 'l': log = 1; break;
 case 'L': log = 0; break;
 case 'p': port = atoi(optarg); break;
 case 's': servers_allowed = atoi(optarg); break;
 case 'D': detach = 1; break;
 case 'v': verbose++; break;
 default: usage(); exit(1);
 }
 if (verbose) {
  printf("Address of sockaddr is %p\n",&name);
 }
 if (detach) {
  int i;
  i = open("/dev/tty",00,0);
  if (i != -1) {
   (void) ioctl(i,0x5422,(char *) 0);
   (void) close(i);
  }
 }
 if ((s = socket(2,SOCK_STREAM,0)) == -1) {
  perror("socket");
  exit(1);
 }
 set = 1;
 if (setsockopt(s,1,2,(char *) &set, sizeof(set)) == -1) {
  perror("setsockoopt");
  exit(1);
 }
 memset((char *)&name,0,sizeof(name));
 name.sin_family = 2;
 name.sin_port = htons(port);
 if (bind(s,(struct sockaddr *) &name,sizeof(name)) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(s,4) == -1) {
  perror("listen");
  exit(1);
 }
 (void) signal(17,(void (*)(int)) reaper);
again:
 while ((namelen = sizeof name), ((ss = accept(s,(struct sockaddr *)&name,&namelen)) != -1)) {
  if (verbose) {
   fprintf(stderr,"[%s]\n",inet_ntoa(name.sin_addr));
  }
  if (log) {
   char buf[256];
   sprintf(buf,"rpc_server: Connect on port %d from %s",port,inet_ntoa(name.sin_addr));
   syslog(6 | (3<<3),buf);
  }
  switch (fork()) {
  case 0:
   (void) close(s);
   rpc_service(ss);
   exit(0);
  case -1:
   perror("fork");
   exit(1);
  default:
   (void) close(ss);
   --servers_allowed;
   break;
  }
  if (count > 0 && --count == 0) exit(0);
  while (!servers_allowed) {
   if (verbose) fprintf(stderr,"Pausing\n");
   pause();
   if (verbose) fprintf(stderr,"paused, servers_allowed %ld\n",servers_allowed);
  }
 }
 if ((*__errno_location ()) == 4) goto again;
 perror("accept");
 exit(1);
}

variable_types: ac int

variable_types:
av
char **

variable_types: s int

variable_types: ss int

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

variable_types: set int

variable_types: ch int

variable_types: namelen int

variable_types: detach int

variable_types:
port
unsigned short

variable_types: log int

variable_types: count int

variable_types:
getopt
int ()

variable_types: optind int

variable_types:
optarg
char *

variable_types:
buf
char [256]

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

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


decompiled_code:
size_t __fastcall rpc_hndlr0(__int64 a1)
{
double v1; // xmm0_8
double v3; // [rsp+8h] [rbp-28h] BYREF
double v4; // [rsp+10h] [rbp-20h] BYREF
unsigned int v5; // [rsp+1Ch] [rbp-14h] BYREF
unsigned int v6; // [rsp+20h] [rbp-10h] BYREF
unsigned int v7[3]; // [rsp+24h] [rbp-Ch] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlfd", v7, &v4, &v6, &v3, &v5) != 5 )
return fwrite("rpc_hndlr0: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr0: unmarshalled");
printf("i0 = %d\n", v7[0]);
printf("i1 = %d\n", v6);
printf("i2 = %d\n", v5);
printf("d0 = %f\n", v4);
printf("d1 = %f\n", v3);
}
v1 = (double)(int)v7[0] + v3 + (double)(int)v6 + (double)(int)v5 + v4;
v4 = v1;
if ( verbose )
printf("rpc_hndlr0: returning d0 = %f\n", v1);
return srss_marshall(a1, "lf", v4);
}

canonical_decompiled_code:
size_t __fastcall func0(__int64 a1)
{
double v1; // xmm0_8
double v3; // [rsp+8h] [rbp-28h] BYREF
double v4; // [rsp+10h] [rbp-20h] BYREF
unsigned int v5; // [rsp+1Ch] [rbp-14h] BYREF
unsigned int v6; // [rsp+20h] [rbp-10h] BYREF
unsigned int v7[3]; // [rsp+24h] [rbp-Ch] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlfd", v7, &v4, &v6, &v3, &v5) != 5 )
return fwrite("rpc_hndlr0: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr0: unmarshalled");
printf("i0 = %d\n", v7[0]);
printf("i1 = %d\n", v6);
printf("i2 = %d\n", v5);
printf("d0 = %f\n", v4);
printf("d1 = %f\n", v3);
}
v1 = (double)(int)v7[0] + v3 + (double)(int)v6 + (double)(int)v5 + v4;
v4 = v1;
if ( verbose )
printf("rpc_hndlr0: returning d0 = %f\n", v1);
return srss_marshall(a1, "lf", v4);
}

original_code:
void rpc_hndlr0(struct srss_state *sp) {
 int i0, i1, i2;
 double d0, d1;
 if (srss_unmarshall(sp,"dlfdlfd",&i0,&d0,&i1,&d1,&i2) != 5) {
  fprintf(stderr,"rpc_hndlr0: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr0: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("i2 = %d\n",i2);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 + i0 + i1 + i2;
 if (verbose) {
  printf("rpc_hndlr0: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

canonical_original_code:
void rpc_hndlr0(struct srss_state *sp) {
 int i0; int i1; int i2;
 double d0; double d1;
 if (srss_unmarshall(sp,"dlfdlfd",&i0,&d0,&i1,&d1,&i2) != 5) {
  fprintf(stderr,"rpc_hndlr0: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr0: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("i2 = %d\n",i2);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 + i0 + i1 + i2;
 if (verbose) {
  printf("rpc_hndlr0: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

variable_types: struct srss_state { int sock; int num_entries; struct srss_entry { char *rpc_name; void (*rpc_handler)(struct srss_state *); } *entry_pts; int in_ix; char in_buf[-1]; void (*fn)(struct srss_entry *); } *

user_defined_types: struct srss_state { int sock; int num_entries; struct srss_entry *entry_pts; int in_ix; char in_buf[-1]; void (*fn)(struct srss_entry *); }


decompiled_code:
size_t __fastcall rpc_hndlr1(__int64 a1)
{
double v1; // xmm0_8
double v3; // [rsp+8h] [rbp-20h] BYREF
double v4; // [rsp+10h] [rbp-18h] BYREF
unsigned int v5; // [rsp+18h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+1Ch] [rbp-Ch] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlf", v6, &v4, &v5, &v3) != 4 )
return fwrite("rpc_hndlr1: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr1: unmarshalled");
printf("i0 = %d\n", v6[0]);
printf("i1 = %d\n", v5);
printf("d0 = %f\n", v4);
printf("d1 = %f\n", v3);
}
v1 = v3 - (double)(int)v6[0] - (double)(int)v5 + v4;
v4 = v1;
if ( verbose )
printf("rpc_hndlr1: returning d0 = %f\n", v1);
return srss_marshall(a1, "lf", v4);
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1)
{
double v1; // xmm0_8
double v3; // [rsp+8h] [rbp-20h] BYREF
double v4; // [rsp+10h] [rbp-18h] BYREF
unsigned int v5; // [rsp+18h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+1Ch] [rbp-Ch] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlf", v6, &v4, &v5, &v3) != 4 )
return fwrite("rpc_hndlr1: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr1: unmarshalled");
printf("i0 = %d\n", v6[0]);
printf("i1 = %d\n", v5);
printf("d0 = %f\n", v4);
printf("d1 = %f\n", v3);
}
v1 = v3 - (double)(int)v6[0] - (double)(int)v5 + v4;
v4 = v1;
if ( verbose )
printf("rpc_hndlr1: returning d0 = %f\n", v1);
return srss_marshall(a1, "lf", v4);
}

original_code:
void rpc_hndlr1(struct srss_state *sp) {
 int i0, i1;
 double d0, d1;
 if (srss_unmarshall(sp,"dlfdlf",&i0,&d0,&i1,&d1) != 4) {
  fprintf(stderr,"rpc_hndlr1: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr1: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 - i0 - i1;
 if (verbose) {
  printf("rpc_hndlr1: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

canonical_original_code:
void rpc_hndlr1(struct srss_state *sp) {
 int i0; int i1;
 double d0; double d1;
 if (srss_unmarshall(sp,"dlfdlf",&i0,&d0,&i1,&d1) != 4) {
  fprintf(stderr,"rpc_hndlr1: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr1: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 - i0 - i1;
 if (verbose) {
  printf("rpc_hndlr1: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

user_defined_types: struct srss_entry { char *rpc_name; void (*rpc_handler)(struct srss_state *); }


decompiled_code:
__int64 __fastcall start_service(unsigned int a1)
{
srss_server_init(&ifc, 2LL, &entries, a1);
return srss_service(&ifc, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
srss_server_init(&ifc, 2LL, &entries, a1);
return srss_service(&ifc, 1LL);
}

original_code:
int start_service(int sock)
{
 srss_server_init(&ifc,sizeof entries/sizeof entries[0],entries,sock);
 return srss_service(&ifc,1);
}

variable_types: sock int


decompiled_code:
unsigned int __fastcall rpc_service(unsigned int a1)
{
unsigned int result; // eax
__pid_t v2; // eax

if ( verbose )
{
v2 = getpid();
fprintf(stderr, "child starting service, pid %lu\n", v2);
}
result = start_service(a1);
if ( verbose )
result = fprintf(stderr, "child service routine returned %d\n", result);
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func3(unsigned int a1)
{
unsigned int result; // eax
__pid_t v2; // eax

if ( verbose )
{
v2 = getpid();
fprintf(stderr, "child starting service, pid %lu\n", v2);
}
result = func2(a1);
if ( verbose )
result = fprintf(stderr, "child service routine returned %d\n", result);
return result;
}

original_code:
void rpc_service(int sock)
{
 int rv;
 if (verbose)
  fprintf(stderr,"child starting service, pid %lu\n",(unsigned long) getpid());
 rv = start_service(sock);
 if (verbose)
  fprintf(stderr,"child service routine returned %d\n",rv);
}

variable_types: rv int


parseDate

repo: behrat/fah-stats

decompiled_code:
char *__fastcall parseDate(const char *a1, struct tm *a2)
{
return strptime(a1, "%A%t%B %d %T PST %Y\n", a2);
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1, struct tm *a2)
{
return strptime(a1, "%A%t%B %d %T PST %Y\n", a2);
}

original_code:
char * parseDate(char* buffer, struct tm * time) {
 return strptime(buffer, "%A%t%B %d %T PST %Y\n", time);
}

canonical_original_code:
char *parseDate(char *buffer, struct tm *time) {
 return strptime(buffer, "%A%t%B %d %T PST %Y\n", time);
}

variable_types:
buffer
char *

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

return_type: char *


signalHandler

repo: bejayoharen/guitartuner

decompiled_code:
void signalHandler()
{
running = 0;
}

canonical_decompiled_code:
void func0()
{
running = 0;
}

original_code: void signalHandler( int signum ) { running = 0; }

canonical_original_code: void signalHandler(int signum) { running = 0; }

variable_types: signum int


buildHammingWindow

original_code:
void buildHammingWindow( float *window, int size )
{
   for( int i=0; i<size; ++i )
      window[i] = .54 - .46 * cos( 2 * 3.14159265358979323846 * i / (float) size );
}

canonical_original_code:
void buildHammingWindow(float *window, int size)
{
   for( int i = 0; i<size; ++i )
      window[i] = .54 - .46 * cos( 2 * 3.14159265358979323846 * i / (float) size );
}

variable_types:
window
float *

variable_types: size int

variable_types: i int


buildHanWindow

original_code:
void buildHanWindow( float *window, int size )
{
   for( int i=0; i<size; ++i )
      window[i] = .5 * ( 1 - cos( 2 * 3.14159265358979323846 * i / (size-1.0) ) );
}

canonical_original_code:
void buildHanWindow(float *window, int size)
{
   for( int i = 0; i<size; ++i )
      window[i] = .5 * ( 1 - cos( 2 * 3.14159265358979323846 * i / (size-1.0) ) );
}


applyWindow

original_code:
void applyWindow( float *window, float *data, int size )
{
   for( int i=0; i<size; ++i )
      data[i] *= window[i] ;
}

canonical_original_code:
void applyWindow(float *window, float *data, int size)
{
   for( int i = 0; i<size; ++i )
      data[i] *= window[i] ;
}

variable_types:
data
float *


computeSecondOrderLowPassParameters

original_code:
void computeSecondOrderLowPassParameters( float srate, float f, float *a, float *b )
{
   float a0;
   float w0 = 2 * 3.14159265358979323846 * f/srate;
   float cosw0 = cos(w0);
   float sinw0 = sin(w0);
   float alpha = sinw0/2 * sqrt(2);
   a0 = 1 + alpha;
   a[0] = (-2*cosw0) / a0;
   a[1] = (1 - alpha) / a0;
   b[0] = ((1-cosw0)/2) / a0;
   b[1] = ( 1-cosw0) / a0;
   b[2] = b[0];
}

canonical_original_code:
void computeSecondOrderLowPassParameters(float srate, float f, float *a, float *b)
{
   float a0;
   float w0 = 2 * 3.14159265358979323846 * f/srate;
   float cosw0 = cos(w0);
   float sinw0 = sin(w0);
   float alpha = sinw0/2 * sqrt(2);
   a0 = 1 + alpha;
   a[0] = (-2*cosw0) / a0;
   a[1] = (1 - alpha) / a0;
   b[0] = ((1-cosw0)/2) / a0;
   b[1] = ( 1-cosw0) / a0;
   b[2] = b[0];
}

variable_types: srate float

variable_types: f float

variable_types:
a
float *

variable_types:
b
float *

variable_types: alpha float


processSecondOrderFilter

decompiled_code:
void __fastcall processSecondOrderFilter(float *a1, float *a2, float *a3, float a4)
{
float v5; // xmm3_4
float v6; // xmm0_4

v5 = a1[2];
v6 = (float)((float)((float)(a3[2] * a1[1]) + (float)((float)(a4 * *a3) + (float)(*a1 * a3[1]))) - (float)(v5 * *a2))
- (float)(a2[1] * a1[3]);
a1[1] = *a1;
*a1 = a4;
a1[3] = v5;
a1[2] = v6;
}

original_code:
float processSecondOrderFilter( float x, float *mem, float *a, float *b )
{
    float ret = b[0] * x + b[1] * mem[0] + b[2] * mem[1]
                         - a[0] * mem[2] - a[1] * mem[3] ;
  mem[1] = mem[0];
  mem[0] = x;
  mem[3] = mem[2];
  mem[2] = ret;
  return ret;
}

canonical_original_code:
float processSecondOrderFilter(float x, float *mem, float *a, float *b)
{
    float ret = b[0] * x + b[1] * mem[0] + b[2] * mem[1]
                         - a[0] * mem[2] - a[1] * mem[3];
  mem[1] = mem[0];
  mem[0] = x;
  mem[3] = mem[2];
  mem[2] = ret;
  return ret;
}

variable_types: x float

variable_types:
mem
float *

variable_types: ret float

return_type: float


main

original_code:
int main( int argc, char **argv ) {
   PaStreamParameters inputParameters;
   float a[2], b[3], mem1[4], mem2[4];
   float data[(8192)];
   float datai[(8192)];
   float window[(8192)];
   float freqTable[(8192)];
   char * noteNameTable[(8192)];
   float notePitchTable[(8192)];
   void * fft = ((void *)0);
   PaStream *stream = ((void *)0);
   PaError err = 0;
   struct sigaction action;
   action.__sigaction_handler.sa_handler = signalHandler;
   sigemptyset (&action.sa_mask);
   action.sa_flags = 0;
   sigaction (2, &action, ((void *)0));
   sigaction (1, &action, ((void *)0));
   sigaction (15, &action, ((void *)0));
   buildHanWindow( window, (8192) );
   fft = initfft( (13) );
   computeSecondOrderLowPassParameters( (8000), 330, a, b );
   mem1[0] = 0; mem1[1] = 0; mem1[2] = 0; mem1[3] = 0;
   mem2[0] = 0; mem2[1] = 0; mem2[2] = 0; mem2[3] = 0;
   for( int i=0; i<(8192); ++i ) {
      freqTable[i] = ( (8000) * i ) / (float) ( (8192) );
   }
   for( int i=0; i<(8192); ++i ) {
      noteNameTable[i] = ((void *)0);
      notePitchTable[i] = -1;
   }
   for( int i=0; i<127; ++i ) {
      float pitch = ( 440.0 / 32.0 ) * pow( 2, (i-9.0)/12.0 ) ;
      if( pitch > (8000) / 2.0 )
         break;
      float min = 1000000000.0;
      int index = -1;
      for( int j=0; j<(8192); ++j ) {
         if( fabsf( freqTable[j]-pitch ) < min ) {
             min = fabsf( freqTable[j]-pitch );
             index = j;
         }
      }
      noteNameTable[index] = NOTES[i%12];
      notePitchTable[index] = pitch;
   }
   err = Pa_Initialize();
   if( err != paNoError ) goto error;
   inputParameters.device = Pa_GetDefaultInputDevice();
   inputParameters.channelCount = 1;
   inputParameters.sampleFormat = ((PaSampleFormat) 0x00000001);
   inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency ;
   inputParameters.hostApiSpecificStreamInfo = ((void *)0);
   printf( "Opening %s\n",
           Pa_GetDeviceInfo( inputParameters.device )->name );
   err = Pa_OpenStream( &stream,
                        &inputParameters,
                        ((void *)0),
                        (8000),
                        (8192),
                        ((PaStreamFlags) 0x00000001),
                        ((void *)0),
                        ((void *)0) );
   if( err != paNoError ) goto error;
   err = Pa_StartStream( stream );
   if( err != paNoError ) goto error;
   while( running )
   {
      err = Pa_ReadStream( stream, data, (8192) );
      if( err ) goto error;
      for( int j=0; j<(8192); ++j ) {
         data[j] = processSecondOrderFilter( data[j], mem1, a, b );
         data[j] = processSecondOrderFilter( data[j], mem2, a, b );
      }
      applyWindow( window, data, (8192) );
      for( int j=0; j<(8192); ++j )
         datai[j] = 0;
      applyfft( fft, data, datai, 0 );
      float maxVal = -1;
      int maxIndex = -1;
      for( int j=0; j<(8192)/2; ++j ) {
         float v = data[j] * data[j] + datai[j] * datai[j] ;
         if( v > maxVal ) {
            maxVal = v;
            maxIndex = j;
         }
      }
      float freq = freqTable[maxIndex];
      int nearestNoteDelta=0;
      while( 1 ) {
         if( nearestNoteDelta < maxIndex && noteNameTable[maxIndex-nearestNoteDelta] != ((void *)0) ) {
            nearestNoteDelta = -nearestNoteDelta;
            break;
         } else if( nearestNoteDelta + maxIndex < (8192) && noteNameTable[maxIndex+nearestNoteDelta] != ((void *)0) ) {
            break;
         }
         ++nearestNoteDelta;
      }
      char * nearestNoteName = noteNameTable[maxIndex+nearestNoteDelta];
      float nearestNotePitch = notePitchTable[maxIndex+nearestNoteDelta];
      float centsSharp = 1200 * log( freq / nearestNotePitch ) / log( 2.0 );
      printf("\033[2J\033[1;1H");
      fflush(stdout);
      printf( "Tuner listening. Control-C to exit.\n" );
      printf( "%f Hz, %d : %f\n", freq, maxIndex, maxVal*1000 );
      printf( "Nearest Note: %s\n", nearestNoteName );
      if( nearestNoteDelta != 0 ) {
         if( centsSharp > 0 )
            printf( "%f cents sharp.\n", centsSharp );
         if( centsSharp < 0 )
            printf( "%f cents flat.\n", -centsSharp );
      } else {
         printf( "in tune!\n" );
      }
      printf( "\n" );
      int chars = 30;
      if( nearestNoteDelta == 0 || centsSharp >= 0 ) {
         for( int i=0; i<chars; ++i )
            printf( " " );
      } else {
         for( int i=0; i<chars+centsSharp; ++i )
            printf( " " );
         for( int i=chars+centsSharp<0?0:chars+centsSharp; i<chars; ++i )
            printf( "=" );
      }
      printf( " %2s ", nearestNoteName );
      if( nearestNoteDelta != 0 )
         for( int i=0; i<chars && i<centsSharp; ++i )
           printf( "=" );
      printf("\n");
   }
   err = Pa_StopStream( stream );
   if( err != paNoError ) goto error;
   destroyfft( fft );
   Pa_Terminate();
   return 0;
 error:
   if( stream ) {
      Pa_AbortStream( stream );
      Pa_CloseStream( stream );
   }
   destroyfft( fft );
   Pa_Terminate();
   fprintf( stderr, "An error occured while using the portaudio stream\n" );
   fprintf( stderr, "Error number: %d\n", err );
   fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
   return 1;
}

canonical_original_code:
int main(int argc, char **argv) {
   struct PaStreamParameters inputParameters;
   float a[2]; float b[3]; float mem1[4]; float mem2[4];
   float data[-1];
   float datai[-1];
   float window[-1];
   float freqTable[-1];
   char *noteNameTable[-1];
   float notePitchTable[-1];
   void *fft = ((void *)0);
   void *stream = ((void *)0);
   int err = 0;
   struct sigaction action;
   action.__sigaction_handler.sa_handler = signalHandler;
   sigemptyset (&action.sa_mask);
   action.sa_flags = 0;
   sigaction (2, &action, ((void *)0));
   sigaction (1, &action, ((void *)0));
   sigaction (15, &action, ((void *)0));
   buildHanWindow( window, (8192) );
   fft = initfft( (13) );
   computeSecondOrderLowPassParameters( (8000), 330, a, b );
   mem1[0] = 0; mem1[1] = 0; mem1[2] = 0; mem1[3] = 0;
   mem2[0] = 0; mem2[1] = 0; mem2[2] = 0; mem2[3] = 0;
   for( int i = 0; i<(8192); ++i ) {
      freqTable[i] = ( (8000) * i ) / (float) ( (8192) );
   }
   for( int i = 0; i<(8192); ++i ) {
      noteNameTable[i] = ((void *)0);
      notePitchTable[i] = -1;
   }
   for( int i = 0; i<127; ++i ) {
      float pitch = ( 440.0 / 32.0 ) * pow( 2, (i-9.0)/12.0 );
      if( pitch > (8000) / 2.0 )
         break;
      float min = 1000000000.0;
      int index = -1;
      for( int j = 0; j<(8192); ++j ) {
         if( fabsf( freqTable[j]-pitch ) < min ) {
             min = fabsf( freqTable[j]-pitch );
             index = j;
         }
      }
      noteNameTable[index] = NOTES[i%12];
      notePitchTable[index] = pitch;
   }
   err = Pa_Initialize();
   if( err != paNoError ) goto error;
   inputParameters.device = Pa_GetDefaultInputDevice();
   inputParameters.channelCount = 1;
   inputParameters.sampleFormat = ((unsigned long) 0x00000001);
   inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency ;
   inputParameters.hostApiSpecificStreamInfo = ((void *)0);
   printf( "Opening %s\n",
           Pa_GetDeviceInfo( inputParameters.device )->name );
   err = Pa_OpenStream( &stream,
                        &inputParameters,
                        ((void *)0),
                        (8000),
                        (8192),
                        ((unsigned long) 0x00000001),
                        ((void *)0),
                        ((void *)0) );
   if( err != paNoError ) goto error;
   err = Pa_StartStream( stream );
   if( err != paNoError ) goto error;
   while( running )
   {
      err = Pa_ReadStream( stream, data, (8192) );
      if( err ) goto error;
      for( int j = 0; j<(8192); ++j ) {
         data[j] = processSecondOrderFilter( data[j], mem1, a, b );
         data[j] = processSecondOrderFilter( data[j], mem2, a, b );
      }
      applyWindow( window, data, (8192) );
      for( int j = 0; j<(8192); ++j )
         datai[j] = 0;
      applyfft( fft, data, datai, 0 );
      float maxVal = -1;
      int maxIndex = -1;
      for( int j = 0; j<(8192)/2; ++j ) {
         float v = data[j] * data[j] + datai[j] * datai[j];
         if( v > maxVal ) {
            maxVal = v;
            maxIndex = j;
         }
      }
      float freq = freqTable[maxIndex];
      int nearestNoteDelta = 0;
      while( 1 ) {
         if( nearestNoteDelta < maxIndex && noteNameTable[maxIndex-nearestNoteDelta] != ((void *)0) ) {
            nearestNoteDelta = -nearestNoteDelta;
            break;
         } else if( nearestNoteDelta + maxIndex < (8192) && noteNameTable[maxIndex+nearestNoteDelta] != ((void *)0) ) {
            break;
         }
         ++nearestNoteDelta;
      }
      char *nearestNoteName = noteNameTable[maxIndex+nearestNoteDelta];
      float nearestNotePitch = notePitchTable[maxIndex+nearestNoteDelta];
      float centsSharp = 1200 * log( freq / nearestNotePitch ) / log( 2.0 );
      printf("\033[2J\033[1;1H");
      fflush(stdout);
      printf( "Tuner listening. Control-C to exit.\n" );
      printf( "%f Hz, %d : %f\n", freq, maxIndex, maxVal*1000 );
      printf( "Nearest Note: %s\n", nearestNoteName );
      if( nearestNoteDelta != 0 ) {
         if( centsSharp > 0 )
            printf( "%f cents sharp.\n", centsSharp );
         if( centsSharp < 0 )
            printf( "%f cents flat.\n", -centsSharp );
      } else {
         printf( "in tune!\n" );
      }
      printf( "\n" );
      int chars = 30;
      if( nearestNoteDelta == 0 || centsSharp >= 0 ) {
         for( int i = 0; i<chars; ++i )
            printf( " " );
      } else {
         for( int i = 0; i<chars+centsSharp; ++i )
            printf( " " );
         for( int i = chars+centsSharp<0?0:chars+centsSharp; i<chars; ++i )
            printf( "=" );
      }
      printf( " %2s ", nearestNoteName );
      if( nearestNoteDelta != 0 )
         for( int i = 0; i<chars && i<centsSharp; ++i )
           printf( "=" );
      printf("\n");
   }
   err = Pa_StopStream( stream );
   if( err != paNoError ) goto error;
   destroyfft( fft );
   Pa_Terminate();
   return 0;
 error:
   if( stream ) {
      Pa_AbortStream( stream );
      Pa_CloseStream( stream );
   }
   destroyfft( fft );
   Pa_Terminate();
   fprintf( stderr, "An error occured while using the portaudio stream\n" );
   fprintf( stderr, "Error number: %d\n", err );
   fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
   return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct PaStreamParameters { int device; int channelCount; unsigned long sampleFormat; double suggestedLatency; void *hostApiSpecificStreamInfo; }

variable_types:
a
float [2]

variable_types:
b
float [3]

variable_types:
data
float [-1]

variable_types:
datai
float [-1]

variable_types:
window
float [-1]

variable_types:
freqTable
float [-1]

variable_types:
noteNameTable
char *[-1]

variable_types:
notePitchTable
float [-1]

variable_types:
fft
void *

variable_types:
stream
void *

variable_types: err int

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

variable_types: pitch float

variable_types: min float

variable_types: index int

variable_types: j int

variable_types: maxVal float

variable_types: maxIndex int

variable_types: v float

variable_types: freq float

variable_types: nearestNoteDelta int

variable_types:
nearestNoteName
char *

variable_types: nearestNotePitch float

variable_types: centsSharp float

variable_types: chars int

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

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


destroyfft

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

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

original_code:
void destroyfft( void *fft ) {
    free( fft );
}

canonical_original_code:
void destroyfft(void *fft) {
    free( fft );
}

variable_types:
fft
void *


applyfft

original_code:
void applyfft( void * fft, float *xr, float *xi, _Bool inv ) {
    int n, n2, i, k, kn2, l, p;
    float ang, s, c, tr, ti;
    struct fft_s *mfft = (struct fft_s *) fft ;
    n = 1 << mfft->bits;
    n2 = n / 2;
    for ( l = 0; l < mfft->bits; ++l ) {
        for ( k = 0; k < n; k += n2 ) {
            for( i = 0; i < n2; ++i, ++k ) {
                p = mfft->bitreverse[k / n2];
                ang = 6.283185 * p / n;
                c = cos( ang );
                s = sin( ang );
                kn2 = k + n2;
                if ( inv )
                    s = -s;
                tr = xr[kn2] * c + xi[kn2] * s;
                ti = xi[kn2] * c - xr[kn2] * s;
                xr[kn2] = xr[k] - tr;
                xi[kn2] = xi[k] - ti;
                xr[k] += tr;
                xi[k] += ti;
            }
        }
        n2 /= 2;
    }
    for ( k = 0; k < n; ++k ) {
        i = mfft->bitreverse[k];
        if ( i <= k )
            continue;
        tr = xr[k];
        ti = xi[k];
        xr[k] = xr[i];
        xi[k] = xi[i];
        xr[i] = tr;
        xi[i] = ti;
    }
    if ( ! inv ) {
        float f;
        f = 1.0 / n;
        for( i = 0; i < n ; ++i ) {
            xr[i] *= f;
            xi[i] *= f;
        }
    }
}

canonical_original_code:
void applyfft(void *fft, float *xr, float *xi, _Bool inv) {
    int n; int n2; int i; int k; int kn2; int l; int p;
    float ang; float s; float c; float tr; float ti;
    struct fft_s *mfft = (struct fft_s *) fft;
    n = 1 << mfft->bits;
    n2 = n / 2;
    for ( l = 0; l < mfft->bits; ++l ) {
        for ( k = 0; k < n; k += n2 ) {
            for( i = 0; i < n2; ++i, ++k ) {
                p = mfft->bitreverse[k / n2];
                ang = 6.283185 * p / n;
                c = cos( ang );
                s = sin( ang );
                kn2 = k + n2;
                if ( inv )
                    s = -s;
                tr = xr[kn2] * c + xi[kn2] * s;
                ti = xi[kn2] * c - xr[kn2] * s;
                xr[kn2] = xr[k] - tr;
                xi[kn2] = xi[k] - ti;
                xr[k] += tr;
                xi[k] += ti;
            }
        }
        n2 /= 2;
    }
    for ( k = 0; k < n; ++k ) {
        i = mfft->bitreverse[k];
        if ( i <= k )
            continue;
        tr = xr[k];
        ti = xi[k];
        xr[k] = xr[i];
        xi[k] = xi[i];
        xr[i] = tr;
        xi[i] = ti;
    }
    if ( ! inv ) {
        float f;
        f = 1.0 / n;
        for( i = 0; i < n ; ++i ) {
            xr[i] *= f;
            xi[i] *= f;
        }
    }
}

variable_types:
xr
float *

variable_types:
xi
float *

variable_types: n int

variable_types: i int

variable_types: k int

variable_types: l int

variable_types: p int

variable_types: ang float

variable_types: s float

variable_types: c float

variable_types: tr float

variable_types: ti float

variable_types: struct fft_s { int bitreverse[32768]; int bits; } *

variable_types: f float


repo: bekars/NginB

decompiled_code:
int __fastcall cache_header_dump(__int64 a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax

v1 = ctime((const time_t *)a1);
printf("valid: %s", v1);
v2 = ctime((const time_t *)(a1 + 8));
printf("last_modify: %s", v2);
v3 = ctime((const time_t *)(a1 + 16));
printf("date: %s", v3);
printf("crc32: %x\n", *(unsigned int *)(a1 + 24));
printf("msec: %d\n", *(unsigned __int16 *)(a1 + 28));
printf("header: %d\n", *(unsigned __int16 *)(a1 + 30));
return printf("body: %d\n", *(unsigned __int16 *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax

v1 = ctime((const time_t *)a1);
printf("valid: %s", v1);
v2 = ctime((const time_t *)(a1 + 8));
printf("last_modify: %s", v2);
v3 = ctime((const time_t *)(a1 + 16));
printf("date: %s", v3);
printf("crc32: %x\n", *(unsigned int *)(a1 + 24));
printf("msec: %d\n", *(unsigned __int16 *)(a1 + 28));
printf("header: %d\n", *(unsigned __int16 *)(a1 + 30));
return printf("body: %d\n", *(unsigned __int16 *)(a1 + 32));
}

original_code:
void
cache_header_dump(ngx_http_file_cache_header_t *cache_header)
{
    printf("valid: %s", ctime(&cache_header->valid_sec));
    printf("last_modify: %s", ctime(&cache_header->last_modified));
    printf("date: %s", ctime(&cache_header->date));
    printf("crc32: %x\n", cache_header->crc32);
    printf("msec: %d\n", cache_header->valid_msec);
    printf("header: %d\n", cache_header->header_start);
    printf("body: %d\n", cache_header->body_start);
}

canonical_original_code:
void cache_header_dump(struct ngx_http_file_cache_header_t *cache_header)
{
    printf("valid: %s", ctime(&cache_header->valid_sec));
    printf("last_modify: %s", ctime(&cache_header->last_modified));
    printf("date: %s", ctime(&cache_header->date));
    printf("crc32: %x\n", cache_header->crc32);
    printf("msec: %d\n", cache_header->valid_msec);
    printf("header: %d\n", cache_header->header_start);
    printf("body: %d\n", cache_header->body_start);
}

variable_types: struct ngx_http_file_cache_header_t { long valid_sec; long last_modified; long date; unsigned int crc32; unsigned short valid_msec; unsigned short header_start; unsigned short body_start; } *


decompiled_code:
__int64 __fastcall cache_header_bodyoffset_modify(const char *a1, __int64 a2)
{
*(_WORD *)(a2 + 32) = atoi(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
*(_WORD *)(a2 + 32) = atoi(a1);
return 0LL;
}

original_code:
int
cache_header_bodyoffset_modify(char *bodyoffset, ngx_http_file_cache_header_t *cache_header)
{
    cache_header->body_start = atoi(bodyoffset);
    return 0;
}

canonical_original_code:
int cache_header_bodyoffset_modify(char *bodyoffset, struct ngx_http_file_cache_header_t *cache_header)
{
    cache_header->body_start = atoi(bodyoffset);
    return 0;
}

variable_types:
bodyoffset
char *

user_defined_types: struct ngx_http_file_cache_header_t { long valid_sec; long last_modified; long date; unsigned int crc32; unsigned short valid_msec; unsigned short header_start; unsigned short body_start; }


decompiled_code:
__int64 __fastcall cache_header_expired_modify(const char *a1, _QWORD *a2)
{
__int64 result; // rax
char v3; // [rsp+Bh] [rbp-1Dh] BYREF
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

if ( sscanf(a1, "%c%d", &v3, &v4) == 2 )
{
printf("add %c%d secs to expired...\n", (unsigned int)v3, v4);
if ( v3 == 43 )
*a2 += (int)v4;
else
*a2 -= (int)v4;
result = 0LL;
}
else
{
printf("arg %s error!\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, _QWORD *a2)
{
__int64 result; // rax
char v3; // [rsp+Bh] [rbp-1Dh] BYREF
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

if ( sscanf(a1, "%c%d", &v3, &v4) == 2 )
{
printf("add %c%d secs to expired...\n", (unsigned int)v3, v4);
if ( v3 == 43 )
*a2 += (int)v4;
else
*a2 -= (int)v4;
result = 0LL;
}
else
{
printf("arg %s error!\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
cache_header_expired_modify(char *expired, ngx_http_file_cache_header_t *cache_header)
{
    int secs;
    char ope;
    if (sscanf(expired, "%c%d", &ope, &secs) != 2) {
        printf("arg %s error!\n", expired);
        return -1;
    }
    printf("add %c%d secs to expired...\n", ope, secs);
    if (ope == '+') {
        cache_header->valid_sec += secs;
    } else {
        cache_header->valid_sec -= secs;
    }
    return 0;
}

canonical_original_code:
int cache_header_expired_modify(char *expired, struct ngx_http_file_cache_header_t *cache_header)
{
    int secs;
    char ope;
    if (sscanf(expired, "%c%d", &ope, &secs) != 2) {
        printf("arg %s error!\n", expired);
        return -1;
    }
    printf("add %c%d secs to expired...\n", ope, secs);
    if (ope == '+') {
        cache_header->valid_sec += secs;
    } else {
        cache_header->valid_sec -= secs;
    }
    return 0;
}

variable_types:
expired
char *

variable_types: secs int

variable_types: ope char


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)(argc - 2) <= 2 )
{
if ( argc == 3 )
{
cache_header_show(argv[1], 0);
cache_header_expired_modify(argv[2], &cache_header);
update_cache_file(argv[1], &cache_header);
}
else if ( argc == 4 )
{
cache_header_show(argv[1], 0);
cache_header_expired_modify(argv[2], &cache_header);
cache_header_bodyoffset_modify(argv[3], (__int64)&cache_header);
update_cache_file(argv[1], &cache_header);
}
cache_header_show(argv[1], 1);
exit(0);
}
printf("Usage: %s <cache_file_name> +<expired_seconds(optinal)> <body_offset>\n", *argv);
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)(argc - 2) <= 2 )
{
if ( argc == 3 )
{
func8(argv[1], 0);
func10(argv[2], &cache_header);
func11(argv[1], &cache_header);
}
else if ( argc == 4 )
{
func8(argv[1], 0);
func10(argv[2], &cache_header);
func9(argv[3], (__int64)&cache_header);
func11(argv[1], &cache_header);
}
func8(argv[1], 1);
exit(0);
}
printf("Usage: %s <cache_file_name> +<expired_seconds(optinal)> <body_offset>\n", *argv);
exit(-1);
}

original_code:
int
main(int argc, char **argv)
{
    if ((argc < 2) || (argc > 4)) {
        printf("Usage: %s <cache_file_name> +<expired_seconds(optinal)> <body_offset>\n", argv[0]);
        exit(-1);
    }
    if (argc == 3) {
        cache_header_show(argv[1], 0);
        cache_header_expired_modify(argv[2], &cache_header);
        update_cache_file(argv[1], &cache_header);
    }
    if (argc == 4) {
        cache_header_show(argv[1], 0);
        cache_header_expired_modify(argv[2], &cache_header);
        cache_header_bodyoffset_modify(argv[3], &cache_header);
        update_cache_file(argv[1], &cache_header);
    }
    cache_header_show(argv[1], 1);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **


isPrime

decompiled_code:
__int64 __fastcall isPrime(__int64 a1)
{
__int64 v1; // rcx

if ( a1 <= 2 )
return 1LL;
if ( (a1 & 1) == 0 )
return 0LL;
v1 = 2LL;
while ( a1 != ++v1 )
{
if ( !(a1 % v1) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rcx

if ( a1 <= 2 )
return 1LL;
if ( (a1 & 1) == 0 )
return 0LL;
v1 = 2LL;
while ( a1 != ++v1 )
{
if ( !(a1 % v1) )
return 0LL;
}
return 1LL;
}

original_code:
int isPrime(long x) {
    long i = 0;
    for(i = 2; i < x; i++) {
        if((x % i) == 0)return 0;
    }
    return 1;
}

variable_types: x long

variable_types: i long


totient

original_code:
long totient( long n) {
    long *primeList = ( long *)malloc(n * sizeof( long));
    primeList[0] = 2;
    long j = 0;
    long p;
    long q;
    long index = 1;
    long i = 2;
    for(i = 3; i < n; i +=2) {
        if(isPrime(i) == 1) {
            primeList[index] = i;
            index++;
        }
    }
    for(i = 0; i < index; i++) {
        for (j = 0 ; j <index; j++) {
            if(primeList[i] * primeList[j] == n) {
                p = primeList[i];
                q = primeList[j];
                free(primeList);
                return (p - 1) * (q - 1);
            }
        }
    }
    free(primeList);
    return -1;
}

canonical_original_code:
long totient(long n) {
    long *primeList = ( long *)malloc(n * sizeof( long));
    primeList[0] = 2;
    long j = 0;
    long p;
    long q;
    long index = 1;
    long i = 2;
    for(i = 3; i < n; i +=2) {
        if(isPrime(i) == 1) {
            primeList[index] = i;
            index++;
        }
    }
    for(i = 0; i < index; i++) {
        for (j = 0 ; j <index; j++) {
            if(primeList[i] * primeList[j] == n) {
                p = primeList[i];
                q = primeList[j];
                free(primeList);
                return (p - 1) * (q - 1);
            }
        }
    }
    free(primeList);
    return -1;
}

variable_types: n long

variable_types:
primeList
long *

variable_types: j long

variable_types: p long

variable_types: q long

variable_types: index long

return_type: long


getM

original_code:
long getM(long a, long b) {
  return (a - 1) * (b - 1);
}

variable_types: a long

variable_types: b long


gcd

original_code:
long gcd(long a, long b) {
  long remainder = 0;
  if((a != 0) && (b != 0)) {
    if(a < b) {
      long temp = a;
      a = b;
      b = temp;
    }
    while(a % b > 0) {
      remainder = a % b;
      a = b;
      b = remainder;
    }
  } else {
    return 0;
  }
  return b;
}

variable_types: remainder long

variable_types: temp long


modulo

original_code:
long modulo(long a, long b, long c) {
  long solution = 1;
  long length = 0;
  while(b > 0) {
    long index = b % 2;
    if(index == 1) {
      b = (b - 1) / 2;
    } else {
      b = b / 2;
    }
    if(index == 1) {
      long term = (long)a;
      long counter = 1;
      while(counter <= length) {
 if(length != 0) {
   term = (term * term) % c;
 }
 counter += 1;
      }
      solution = (solution * term) % c;
    }
    length++;
  }
  if(solution < 0) {
    solution = solution + c;
  }
  return solution;
}

variable_types: c long

variable_types: solution long

variable_types: length long

variable_types: term long

variable_types: counter long


coprime

decompiled_code:
__int64 __fastcall coprime(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rax

for ( i = rand() % a1; ; ++i )
{
v2 = gcd(i, a1);
if ( i >= 0 && v2 == 1 )
break;
}
return i;
}

original_code:
long coprime(long x) {
  long value = rand() % x;
  while((gcd(value, x) != 1) || (value < 0)) {
    value++;
  }
  return value;
}

variable_types: x long

variable_types: value long


encrypt

decompiled_code:
// attributes: thunk
__int64 __fastcall encrypt(__int64 a1, __int64 a2, __int64 a3)
{
return modulo(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
return func12(a1, a2, a3);
}

original_code:
long encrypt(long msg, long key, long c) {
  return modulo(msg, key, c);
}

variable_types: msg long

variable_types: key long


decrypt

decompiled_code:
__int64 __fastcall decrypt(__int64 a1, __int64 a2, int a3)
{
return modulo(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, int a3)
{
return func12(a1, a2, a3);
}

original_code:
char decrypt(long msg, long key, int c) {
    return modulo(msg, key, c);
}

variable_types: c int

return_type: char


original_code:
long mod_inverse(long base, long m) {
  long mod = m;
  if(gcd(base, m) != 1) {
    return 0;
  }
  long preA = 1, preB = 0;
  long quotient[1000];
  long remainder = 0, counter = 0, A = 0, B = 0;
  while(base % m != 0) {
    remainder = base % m;
    base = m;
    m = remainder;
    quotient[counter] = base / m;
    counter++;
  }
  if(counter > 2) {
    while(counter >= 0) {
      B = preA;
      A = preB - quotient[counter] * preA;
      preB = B;
      preA = A;
      counter--;
    }
  } else {
    return 0;
  }
  if(A % mod < 0) {
    return A % mod + mod;
  }
  return A % mod;
}

canonical_original_code:
long mod_inverse(long base, long m) {
  long mod = m;
  if(gcd(base, m) != 1) {
    return 0;
  }
  long preA = 1; long preB = 0;
  long quotient[1000];
  long remainder = 0; long counter = 0; long A = 0; long B = 0;
  while(base % m != 0) {
    remainder = base % m;
    base = m;
    m = remainder;
    quotient[counter] = base / m;
    counter++;
  }
  if(counter > 2) {
    while(counter >= 0) {
      B = preA;
      A = preB - quotient[counter] * preA;
      preB = B;
      preA = A;
      counter--;
    }
  } else {
    return 0;
  }
  if(A % mod < 0) {
    return A % mod + mod;
  }
  return A % mod;
}

variable_types: base long

variable_types: m long

variable_types: mod long

variable_types: preA long

variable_types: preB long

variable_types:
quotient
long [1000]

variable_types: A long

variable_types: B long


generateKeys

decompiled_code:
unsigned __int64 __fastcall generateKeys(__int64 a1, __int64 a2, __int64 *a3, __int64 *a4, _QWORD *a5)
{
__int64 i; // rbx
__int64 v9; // rax
unsigned __int64 result; // rax

for ( i = (a2 - 1) * (a1 - 1); ; *a4 = mod_inverse(v9, i) )
{
if ( (unsigned __int64)(*a5 - 2LL) <= 0x270E && (unsigned __int64)(*a3 - 2) <= 0x270E )
{
result = *a4 - 2;
if ( result <= 0x270E )
break;
}
*a5 = a2 * a1;
v9 = coprime(i);
*a3 = v9;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(__int64 a1, __int64 a2, __int64 *a3, __int64 *a4, _QWORD *a5)
{
__int64 i; // rbx
__int64 v9; // rax
unsigned __int64 result; // rax

for ( i = (a2 - 1) * (a1 - 1); ; *a4 = func16(v9, i) )
{
if ( (unsigned __int64)(*a5 - 2LL) <= 0x270E && (unsigned __int64)(*a3 - 2) <= 0x270E )
{
result = *a4 - 2;
if ( result <= 0x270E )
break;
}
*a5 = a2 * a1;
v9 = func13(i);
*a3 = v9;
}
return result;
}

variable_types: a long

variable_types: b long

variable_types:
e
long *

variable_types:
d
long *

variable_types:
c
long *


repo: bemk/AVL

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

if ( !a1 )
return 0LL;
result = tree_find_leftmost(*(_QWORD *)(a1 + 8));
if ( !result )
result = a1;
return result;
}

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

if ( !a1 )
return 0LL;
result = func4(*(_QWORD *)(a1 + 8));
if ( !result )
result = a1;
return result;
}

original_code:
static struct tree* tree_find_leftmost(struct tree* tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree* tmp = tree_find_leftmost(tree->left);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

canonical_original_code:
static struct tree *tree_find_leftmost(struct tree *tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree *tmp = tree_find_leftmost(tree->left);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

variable_types:
tree
struct tree *

variable_types: struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root { struct tree *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; } *

user_defined_types: struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; }

user_defined_types: struct tree_root { struct tree *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t mutex; }

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

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


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

if ( !a1 )
return 0LL;
result = tree_find_rightmost(*(_QWORD *)(a1 + 16));
if ( !result )
result = a1;
return result;
}

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

if ( !a1 )
return 0LL;
result = func5(*(_QWORD *)(a1 + 16));
if ( !result )
result = a1;
return result;
}

original_code:
static struct tree* tree_find_rightmost(struct tree* tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree* tmp = tree_find_rightmost(tree->right);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

canonical_original_code:
static struct tree *tree_find_rightmost(struct tree *tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree *tmp = tree_find_rightmost(tree->right);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

return_type: struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root { struct tree *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; } *