main

repo: rafkhan/etchy

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
WINDOW *v3; // rdi
int v4; // er14
int v5; // er13
unsigned int v6; // ebx
int v7; // er12
int v8; // ebp
int v9; // er13
unsigned int v10; // eax
__int64 v11; // rsi

init(argc, argv, envp);
v3 = stdscr__NCURSES6_TINFO_5_0_19991023;
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v4 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v5 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1;
}
else
{
v4 = -1;
v5 = -1;
}
v6 = 1;
v7 = 0;
v8 = 0;
v9 = v5 - 1;
while ( 2 )
{
v10 = wgetch(v3);
v11 = v10;
switch ( v10 )
{
case 0x102u:
if ( v4 - 1 > v7 )
{
++v7;
draw_color_with_character(v6, 0LL);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
}
goto LABEL_8;
case 0x103u:
if ( v7 )
{
--v7;
draw_color_with_character(v6, 0LL);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
}
goto LABEL_8;
case 0x104u:
if ( v8 )
{
--v8;
draw_color_with_character(v6, 0LL);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
}
goto LABEL_8;
case 0x105u:
v11 = 0LL;
if ( v9 > v8 )
goto LABEL_16;
goto LABEL_8;
case 0x109u:
v6 = 1;
goto LABEL_8;
case 0x10Au:
v6 = 2;
goto LABEL_8;
case 0x10Bu:
v6 = 3;
goto LABEL_8;
case 0x10Cu:
v6 = 4;
goto LABEL_8;
case 0x10Du:
v6 = 5;
goto LABEL_8;
case 0x10Eu:
v6 = 6;
goto LABEL_8;
case 0x10Fu:
v6 = 7;
goto LABEL_8;
case 0x110u:
v6 = 8;
goto LABEL_8;
default:
if ( v10 - 32 <= 0x5E )
{
if ( v9 > v8 )
{
LABEL_16:
++v8;
draw_color_with_character(v6, v11);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
goto LABEL_8;
}
if ( v4 - 1 <= v7 )
goto LABEL_8;
draw_color_with_character(v6, v10);
LABEL_28:
++v7;
v8 = 0;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, 0);
goto LABEL_8;
}
if ( v10 == 127 )
{
draw_color_with_character(v6, 32LL);
LABEL_8:
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
v3 = stdscr__NCURSES6_TINFO_5_0_19991023;
continue;
}
if ( v10 != 27 )
{
if ( v10 != 10 )
goto LABEL_8;
goto LABEL_28;
}
endwin();
return 0;
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
WINDOW *v3; // rdi
int v4; // er14
int v5; // er13
unsigned int v6; // ebx
int v7; // er12
int v8; // ebp
int v9; // er13
unsigned int v10; // eax
__int64 v11; // rsi

func9(argc, argv, envp);
v3 = stdscr__NCURSES6_TINFO_5_0_19991023;
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v4 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v5 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1;
}
else
{
v4 = -1;
v5 = -1;
}
v6 = 1;
v7 = 0;
v8 = 0;
v9 = v5 - 1;
while ( 2 )
{
v10 = wgetch(v3);
v11 = v10;
switch ( v10 )
{
case 0x102u:
if ( v4 - 1 > v7 )
{
++v7;
func8(v6, 0LL);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
}
goto LABEL_8;
case 0x103u:
if ( v7 )
{
--v7;
func8(v6, 0LL);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
}
goto LABEL_8;
case 0x104u:
if ( v8 )
{
--v8;
func8(v6, 0LL);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
}
goto LABEL_8;
case 0x105u:
v11 = 0LL;
if ( v9 > v8 )
goto LABEL_16;
goto LABEL_8;
case 0x109u:
v6 = 1;
goto LABEL_8;
case 0x10Au:
v6 = 2;
goto LABEL_8;
case 0x10Bu:
v6 = 3;
goto LABEL_8;
case 0x10Cu:
v6 = 4;
goto LABEL_8;
case 0x10Du:
v6 = 5;
goto LABEL_8;
case 0x10Eu:
v6 = 6;
goto LABEL_8;
case 0x10Fu:
v6 = 7;
goto LABEL_8;
case 0x110u:
v6 = 8;
goto LABEL_8;
default:
if ( v10 - 32 <= 0x5E )
{
if ( v9 > v8 )
{
LABEL_16:
++v8;
func8(v6, v11);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v8);
goto LABEL_8;
}
if ( v4 - 1 <= v7 )
goto LABEL_8;
func8(v6, v10);
LABEL_28:
++v7;
v8 = 0;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, 0);
goto LABEL_8;
}
if ( v10 == 127 )
{
func8(v6, 32LL);
LABEL_8:
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
v3 = stdscr__NCURSES6_TINFO_5_0_19991023;
continue;
}
if ( v10 != 27 )
{
if ( v10 != 10 )
goto LABEL_8;
goto LABEL_28;
}
endwin();
return 0;
}
}
}

original_code:
int main(void) {
 int ch, xc, yc, max_y, max_x, color;
 color = 1;
 init();
 (max_y = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), max_x = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 xc = yc = 0;
 while(1) {
  ch = wgetch(stdscr);
  switch(ch) {
   case 0403:
    if(yc > 0) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(--yc),(xc));
    }
    break;
   case 0402:
    if(yc < max_y - 1) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(++yc),(xc));
    }
    break;
   case 0404:
    if(xc > 0) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(yc),(--xc));
    }
    break;
   case 0405:
    if(xc < max_x - 1) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(yc),(++xc));
    }
    break;
   case (0410 +(1)):color = 1;break;;
   case (0410 +(2)):color = 2;break;;
   case (0410 +(3)):color = 3;break;;
   case (0410 +(4)):color = 4;break;;
   case (0410 +(5)):color = 5;break;;
   case (0410 +(6)):color = 6;break;;
   case (0410 +(7)):color = 7;break;;
   case (0410 +(8)):color = 8;break;;
   default:
    if(ch >= ' ' && ch <= '~') {
     if(xc < max_x - 1) {
      draw_color_with_character(color, ch);
      wmove(stdscr,(yc),(++xc));
     } else if(yc < max_y - 1) {
      draw_color_with_character(color, ch);
      xc = 0;
      wmove(stdscr,(++yc),(xc));
     }
    } else if (ch == 127) {
     draw_color_with_character(color, ' ');
    } else if (ch == 27) {
     endwin();
     return 0;
    } else if (ch == 10) {
     xc = 0;
     wmove(stdscr,(++yc),(xc));
    }
  }
  wrefresh(stdscr);
 }
}

canonical_original_code:
int main() {
 int ch; int xc; int yc; int max_y; int max_x; int color;
 color = 1;
 init();
 (max_y = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), max_x = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 xc = yc = 0;
 while(1) {
  ch = wgetch(stdscr);
  switch(ch) {
   case 0403:
    if(yc > 0) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(--yc),(xc));
    }
    break;
   case 0402:
    if(yc < max_y - 1) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(++yc),(xc));
    }
    break;
   case 0404:
    if(xc > 0) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(yc),(--xc));
    }
    break;
   case 0405:
    if(xc < max_x - 1) {
     draw_color_with_character(color, 0);
     wmove(stdscr,(yc),(++xc));
    }
    break;
   case (0410 +(1)):color = 1;break;;
   case (0410 +(2)):color = 2;break;;
   case (0410 +(3)):color = 3;break;;
   case (0410 +(4)):color = 4;break;;
   case (0410 +(5)):color = 5;break;;
   case (0410 +(6)):color = 6;break;;
   case (0410 +(7)):color = 7;break;;
   case (0410 +(8)):color = 8;break;;
   default:
    if(ch >= ' ' && ch <= '~') {
     if(xc < max_x - 1) {
      draw_color_with_character(color, ch);
      wmove(stdscr,(yc),(++xc));
     } else if(yc < max_y - 1) {
      draw_color_with_character(color, ch);
      xc = 0;
      wmove(stdscr,(++yc),(xc));
     }
    } else if (ch == 127) {
     draw_color_with_character(color, ' ');
    } else if (ch == 27) {
     endwin();
     return 0;
    } else if (ch == 10) {
     xc = 0;
     wmove(stdscr,(++yc),(xc));
    }
  }
  wrefresh(stdscr);
 }
}

variable_types: ch int

variable_types: xc int

variable_types: yc int

variable_types: color int


decompiled_code:
chtype inch_without_color()
{
chtype result; // rax

result = winch(stdscr__NCURSES6_TINFO_5_0_19991023) & 0x7F;
if ( (_DWORD)result == 127 )
result = 32LL;
return result;
}

canonical_decompiled_code:
chtype func7()
{
chtype result; // rax

result = winch(stdscr__NCURSES6_TINFO_5_0_19991023) & 0x7F;
if ( (_DWORD)result == 127 )
result = 32LL;
return result;
}

original_code:
int inch_without_color(void) {
 int ch;
 ch = winch(stdscr) & 127;
 if (ch == 127)
  ch = 32;
 return ch;
}

canonical_original_code:
int inch_without_color() {
 int ch;
 ch = winch(stdscr) & 127;
 if (ch == 127)
  ch = 32;
 return ch;
}

return_type: int


decompiled_code:
int __fastcall draw_color_with_character(__int16 a1, int a2)
{
int v2; // eax

v2 = a2;
if ( !a2 )
v2 = inch_without_color();
return waddch(stdscr__NCURSES6_TINFO_5_0_19991023, v2 | (unsigned int)(unsigned __int16)(a1 << 8));
}

canonical_decompiled_code:
int __fastcall func8(__int16 a1, int a2)
{
int v2; // eax

v2 = a2;
if ( !a2 )
v2 = func7();
return waddch(stdscr__NCURSES6_TINFO_5_0_19991023, v2 | (unsigned int)(unsigned __int16)(a1 << 8));
}

original_code:
void draw_color_with_character(int cpair, int ch) {
 if (ch == 0)
  ch = inch_without_color();
 waddch(stdscr,(ch | (((chtype)(((cpair))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
}

variable_types: cpair int

return_type: void


init

decompiled_code:
int init()
{
initscr();
keypad(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
cbreak();
noecho();
start_color();
init_pair(1, 7, 0);
init_pair(2, 7, 1);
init_pair(3, 7, 4);
init_pair(4, 7, 2);
init_pair(5, 0, 3);
init_pair(6, 0, 5);
init_pair(7, 0, 6);
return init_pair(8, 0, 7);
}

canonical_decompiled_code:
int func9()
{
initscr();
keypad(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
cbreak();
noecho();
start_color();
init_pair(1, 7, 0);
init_pair(2, 7, 1);
init_pair(3, 7, 4);
init_pair(4, 7, 2);
init_pair(5, 0, 3);
init_pair(6, 0, 5);
init_pair(7, 0, 6);
return init_pair(8, 0, 7);
}

original_code:
void init(void) {
 initscr();
 keypad(stdscr, 1);
 cbreak();
 noecho();
 start_color();
 init_pair(1, 7, 0);
 init_pair(2, 7, 1);
 init_pair(3, 7, 4);
 init_pair(4, 7, 2);
 init_pair(5, 0, 3);
 init_pair(6, 0, 5);
 init_pair(7, 0, 6);
 init_pair(8, 0, 7);
}

canonical_original_code:
void init() {
 initscr();
 keypad(stdscr, 1);
 cbreak();
 noecho();
 start_color();
 init_pair(1, 7, 0);
 init_pair(2, 7, 1);
 init_pair(3, 7, 4);
 init_pair(4, 7, 2);
 init_pair(5, 0, 3);
 init_pair(6, 0, 5);
 init_pair(7, 0, 6);
 init_pair(8, 0, 7);
}


repo: rahpaere/channel

decompiled_code:
void unload_modules()
{
void **v0; // rbx

v0 = (void **)modules;
if ( modules )
{
do
{
dlclose(v0[2]);
v0 = *(void ***)modules;
free(modules);
modules = v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func7()
{
void **v0; // rbx

v0 = (void **)modules;
if ( modules )
{
do
{
dlclose(v0[2]);
v0 = *(void ***)modules;
free(modules);
modules = v0;
}
while ( v0 );
}
}

original_code:
static void unload_modules(void)
{
 struct module *next;
 while (modules) {
  dlclose(modules->handle);
  next = modules->next;
  free(modules);
  modules = next;
 }
}

canonical_original_code:
static void unload_modules()
{
 struct module *next;
 while (modules) {
  dlclose(modules->handle);
  next = modules->next;
  free(modules);
  modules = next;
 }
}

variable_types: struct module { struct module *next; char *name; void *handle; struct channel { void (*send)(struct channel *channel, void *message); } *channel; } *

user_defined_types: struct module { struct module *next; char *name; void *handle; struct channel *channel; }


decompiled_code:
void *__fastcall channel_lookup(char *s)
{
const char *v1; // rbx
void *v2; // r12
__int64 (*v4)(char *, const char *, ...); // rax
char *v5; // rdx
const char *v6; // rsi
__int64 (*v7)(char *, const char *, ...); // r13
_QWORD *v8; // rbx
char *v9; // rax
const char *v10; // rdx
__int64 v11; // rax
int *v12; // rax
void *v13; // rdi
char v14[296]; // [rsp+0h] [rbp-128h] BYREF

v1 = (const char *)modules;
if ( !modules )
{
LABEL_7:
snprintf(v14, 0x100uLL, "%s.so", s);
v2 = dlopen(v14, 1);
if ( !v2 )
{
syslog(4, "unable to load module %s", s);
return v2;
}
snprintf(v14, 0x100uLL, "%s_setup", s);
v4 = (__int64 (*)(char *, const char *, ...))dlsym(v2, v14);
v5 = s;
v6 = "module %s has no setup function";
v7 = v4;
if ( v4 )
{
v8 = malloc(0x20uLL);
if ( v8 )
{
*v8 = modules;
v9 = strdup(s);
v8[2] = v2;
v8[1] = v9;
v11 = v7(s, "module %s has no setup function", v10);
modules = v8;
v8[3] = v11;
return (void *)v11;
}
v12 = __errno_location();
v6 = "%s";
v5 = strerror(*v12);
}
syslog(4, v6, v5);
v13 = v2;
v2 = 0LL;
dlclose(v13);
return v2;
}
while ( strcmp(*((const char **)v1 + 1), s) )
{
v1 = *(const char **)v1;
if ( !v1 )
goto LABEL_7;
}
return (void *)*((_QWORD *)v1 + 3);
}

canonical_decompiled_code:
void *__fastcall func8(char *s)
{
const char *v1; // rbx
void *v2; // r12
__int64 (*v4)(char *, const char *, ...); // rax
char *v5; // rdx
const char *v6; // rsi
__int64 (*v7)(char *, const char *, ...); // r13
_QWORD *v8; // rbx
char *v9; // rax
const char *v10; // rdx
__int64 v11; // rax
int *v12; // rax
void *v13; // rdi
char v14[296]; // [rsp+0h] [rbp-128h] BYREF

v1 = (const char *)modules;
if ( !modules )
{
LABEL_7:
snprintf(v14, 0x100uLL, "%s.so", s);
v2 = dlopen(v14, 1);
if ( !v2 )
{
syslog(4, "unable to load module %s", s);
return v2;
}
snprintf(v14, 0x100uLL, "%s_setup", s);
v4 = (__int64 (*)(char *, const char *, ...))dlsym(v2, v14);
v5 = s;
v6 = "module %s has no setup function";
v7 = v4;
if ( v4 )
{
v8 = malloc(0x20uLL);
if ( v8 )
{
*v8 = modules;
v9 = strdup(s);
v8[2] = v2;
v8[1] = v9;
v11 = v7(s, "module %s has no setup function", v10);
modules = v8;
v8[3] = v11;
return (void *)v11;
}
v12 = __errno_location();
v6 = "%s";
v5 = strerror(*v12);
}
syslog(4, v6, v5);
v13 = v2;
v2 = 0LL;
dlclose(v13);
return v2;
}
while ( strcmp(*((const char **)v1 + 1), s) )
{
v1 = *(const char **)v1;
if ( !v1 )
goto LABEL_7;
}
return (void *)*((_QWORD *)v1 + 3);
}

original_code:
struct channel *channel_lookup(const char *name)
{
 struct module *module;
 struct channel *(*setup)(void);
 void *handle;
 char str[256];
 for (module = modules; module; module = module->next)
  if (!strcmp(module->name, name))
   return module->channel;
 snprintf(str, sizeof(str), "%s.so", name);
 handle = dlopen(str, 0x00001);
 if (!handle) {
  syslog(4, "unable to load module %s", name);
  return ((void *)0);
 }
 snprintf(str, sizeof(str), "%s_setup", name);
 setup = dlsym(handle, str);
 if (!setup) {
  syslog(4, "module %s has no setup function", name);
  dlclose(handle);
  return ((void *)0);
 }
 module = malloc(sizeof(*module));
 if (!module) {
  syslog(4, "%s", strerror((*__errno_location ())));
  dlclose(handle);
  return ((void *)0);
 }
 module->next = modules;
 module->name = strdup(name);
 module->handle = handle;
 module->channel = setup();
 modules = module;
 return module->channel;
}

canonical_original_code:
struct channel *channel_lookup(char *name)
{
 struct module *module;
 struct channel *(*setup)();
 void *handle;
 char str[256];
 for (module = modules; module; module = module->next)
  if (!strcmp(module->name, name))
   return module->channel;
 snprintf(str, sizeof(str), "%s.so", name);
 handle = dlopen(str, 0x00001);
 if (!handle) {
  syslog(4, "unable to load module %s", name);
  return ((void *)0);
 }
 snprintf(str, sizeof(str), "%s_setup", name);
 setup = dlsym(handle, str);
 if (!setup) {
  syslog(4, "module %s has no setup function", name);
  dlclose(handle);
  return ((void *)0);
 }
 module = malloc(sizeof(*module));
 if (!module) {
  syslog(4, "%s", strerror((*__errno_location ())));
  dlclose(handle);
  return ((void *)0);
 }
 module->next = modules;
 module->name = strdup(name);
 module->handle = handle;
 module->channel = setup();
 modules = module;
 return module->channel;
}

variable_types:
name
char *

variable_types: struct channel { void (*send)(struct channel *channel, void *message); } *(*)()

variable_types:
handle
void *

variable_types:
str
char [256]


decompiled_code:
void null_send()
{
syslog(7, "ignored message on null channel");
}

canonical_decompiled_code:
void func6()
{
syslog(7, "ignored message on null channel");
}

original_code:
static void null_send(struct channel *channel, void *message)
{
 (void)channel;
 (void)message;
 syslog(7, "ignored message on null channel");
}

variable_types: struct channel { void (*send)(struct channel *channel, void *message); } *

variable_types:
message
void *


decompiled_code:
__int64 null_test_setup()
{
void (__fastcall **v0)(_QWORD, _QWORD); // rax

v0 = (void (__fastcall **)(_QWORD, _QWORD))channel_lookup();
(*v0)(v0, 0LL);
syslog(6, "loaded null_test module");
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
void (__fastcall **v0)(_QWORD, _QWORD); // rax

v0 = (void (__fastcall **)(_QWORD, _QWORD))channel_lookup();
(*v0)(v0, 0LL);
syslog(6, "loaded null_test module");
return 0LL;
}

original_code:
struct channel *null_test_setup(void)
{
 struct channel *channel;
 channel = channel_lookup("null");
 channel->send(channel, ((void *)0));
 syslog(6, "loaded null_test module");
 return ((void *)0);
}

canonical_original_code:
struct channel *null_test_setup()
{
 struct channel *channel;
 channel = channel_lookup("null");
 channel->send(channel, ((void *)0));
 syslog(6, "loaded null_test module");
 return ((void *)0);
}

return_type: struct channel { void (*send)(struct channel *channel, void *message); } *


repo: rahpaere/dc

decompiled_code:
__int64 __fastcall log_next(const char **a1)
{
int v2; // edi
const char *v3; // r14
const char *v4; // rax
unsigned __int64 v5; // rcx
unsigned int v6; // er12
int v7; // er13
char *v8; // rax
char *v9; // rbp
int v10; // eax
int v11; // eax
char *v12; // rdi
__int64 result; // rax
char *v14; // rax

v2 = *((_DWORD *)a1 + 10);
if ( v2 > 0 )
{
close(v2);
*((_DWORD *)a1 + 10) = -1;
}
v3 = *a1;
if ( a1[1] )
{
v4 = a1[4];
v5 = (unsigned __int64)a1[2];
v6 = (unsigned int)v4;
if ( v5 )
v6 = (int)v4 % v5;
v7 = strlen(*a1) + 10;
v8 = (char *)malloc(v7);
v9 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
v10 = snprintf(v8, v7, "%s%d", v3, v6);
if ( v7 <= v10 )
{
v14 = (char *)realloc(v9, v10 + 1);
if ( !v14 )
{
v12 = v9;
LABEL_15:
free(v12);
return 0xFFFFFFFFLL;
}
v9 = v14;
sprintf(v14, "%s%d", *a1, v6);
}
LABEL_8:
unlink(v9);
v11 = creat(v9, 0x180u);
v12 = v9;
*((_DWORD *)a1 + 10) = v11;
if ( v11 >= 0 )
{
free(v9);
++a1[4];
result = 0LL;
a1[3] = 0LL;
return result;
}
goto LABEL_15;
}
v9 = strdup(*a1);
if ( v9 )
goto LABEL_8;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
int v2; // edi
const char *v3; // r14
const char *v4; // rax
unsigned __int64 v5; // rcx
unsigned int v6; // er12
int v7; // er13
char *v8; // rax
char *v9; // rbp
int v10; // eax
int v11; // eax
char *v12; // rdi
__int64 result; // rax
char *v14; // rax

v2 = *((_DWORD *)a1 + 10);
if ( v2 > 0 )
{
close(v2);
*((_DWORD *)a1 + 10) = -1;
}
v3 = *a1;
if ( a1[1] )
{
v4 = a1[4];
v5 = (unsigned __int64)a1[2];
v6 = (unsigned int)v4;
if ( v5 )
v6 = (int)v4 % v5;
v7 = strlen(*a1) + 10;
v8 = (char *)malloc(v7);
v9 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
v10 = snprintf(v8, v7, "%s%d", v3, v6);
if ( v7 <= v10 )
{
v14 = (char *)realloc(v9, v10 + 1);
if ( !v14 )
{
v12 = v9;
LABEL_15:
free(v12);
return 0xFFFFFFFFLL;
}
v9 = v14;
sprintf(v14, "%s%d", *a1, v6);
}
LABEL_8:
unlink(v9);
v11 = creat(v9, 0x180u);
v12 = v9;
*((_DWORD *)a1 + 10) = v11;
if ( v11 >= 0 )
{
free(v9);
++a1[4];
result = 0LL;
a1[3] = 0LL;
return result;
}
goto LABEL_15;
}
v9 = strdup(*a1);
if ( v9 )
goto LABEL_8;
return 0xFFFFFFFFLL;
}

original_code:
static int log_next(struct log *log)
{
 char *filename;
 int olderr;
 if (log->fd > 0) {
  close(log->fd);
  log->fd = -1;
 }
 if (log->maxbytes > 0) {
  char *s;
  int guess;
  int length;
  int index;
  index = log->count;
  if (log->maxcount > 0)
   index %= log->maxcount;
  guess = strlen(log->prefix) + 10;
  s = malloc(guess);
  if (!s)
   return -1;
  length = snprintf(s, guess, "%s%d", log->prefix, index);
  if (length >= guess) {
   filename = realloc(s, length + 1);
   if (!filename) {
    free(s);
    return -1;
   }
   sprintf(filename, "%s%d", log->prefix, index);
  } else {
   filename = s;
  }
 } else {
  filename = strdup(log->prefix);
  if (!filename)
   return -1;
 }
 unlink(filename);
 log->fd = creat(filename, 0600);
 if (log->fd < 0) {
  olderr = (*__errno_location ());
  free(filename);
  (*__errno_location ()) = olderr;
  return -1;
 }
 free(filename);
 log->count++;
 log->bytes = 0;
 return 0;
}

variable_types: struct log { char *prefix; unsigned long maxbytes; unsigned long maxcount; unsigned long bytes; unsigned long count; int fd; } *

variable_types:
filename
char *

variable_types: olderr int

variable_types:
s
char *

variable_types: guess int

variable_types: length int

variable_types: index int


decompiled_code:
unsigned __int64 __fastcall log_write(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r13
size_t v5; // rax
size_t v6; // rdx
ssize_t v7; // rax
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
do
{
v5 = *(_QWORD *)(a1 + 8);
v6 = a3 - v4;
if ( v5 && v5 < v6 + *(_QWORD *)(a1 + 24) )
v6 = v5 - *(_QWORD *)(a1 + 24);
v7 = write(*(_DWORD *)(a1 + 40), (const void *)(a2 + v4), v6);
if ( v7 <= 0 )
break;
v8 = *(_QWORD *)(a1 + 8);
v4 += v7;
v9 = *(_QWORD *)(a1 + 24) + v7;
*(_QWORD *)(a1 + 24) = v9;
if ( v9 >= v8 && v8 && (int)log_next((const char **)a1) < 0 )
break;
}
while ( a3 > v4 );
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r13
size_t v5; // rax
size_t v6; // rdx
ssize_t v7; // rax
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
do
{
v5 = *(_QWORD *)(a1 + 8);
v6 = a3 - v4;
if ( v5 && v5 < v6 + *(_QWORD *)(a1 + 24) )
v6 = v5 - *(_QWORD *)(a1 + 24);
v7 = write(*(_DWORD *)(a1 + 40), (const void *)(a2 + v4), v6);
if ( v7 <= 0 )
break;
v8 = *(_QWORD *)(a1 + 8);
v4 += v7;
v9 = *(_QWORD *)(a1 + 24) + v7;
*(_QWORD *)(a1 + 24) = v9;
if ( v9 >= v8 && v8 && (int)func0((const char **)a1) < 0 )
break;
}
while ( a3 > v4 );
return v4;
}

original_code:
size_t log_write(struct log *log, char *data, size_t size)
{
 size_t n;
 size_t total = 0;
 ssize_t bytes;
 while (total < size) {
  n = size - total;
  if (log->maxbytes > 0 && log->bytes + n > log->maxbytes)
   n = log->maxbytes - log->bytes;
  bytes = write(log->fd, &data[total], n);
  if (bytes <= 0)
   break;
  total += bytes;
  log->bytes += bytes;
  if (log->maxbytes > 0 && log->bytes >= log->maxbytes) {
   if (log_next(log) < 0)
    break;
  }
 }
 return total;
}

canonical_original_code:
unsigned long log_write(struct log *log, char *data, unsigned long size)
{
 unsigned long n;
 unsigned long total = 0;
 long bytes;
 while (total < size) {
  n = size - total;
  if (log->maxbytes > 0 && log->bytes + n > log->maxbytes)
   n = log->maxbytes - log->bytes;
  bytes = write(log->fd, &data[total], n);
  if (bytes <= 0)
   break;
  total += bytes;
  log->bytes += bytes;
  if (log->maxbytes > 0 && log->bytes >= log->maxbytes) {
   if (log_next(log) < 0)
    break;
  }
 }
 return total;
}

variable_types:
data
char *

variable_types:
size
unsigned long

variable_types:
n
unsigned long

variable_types:
total
unsigned long

variable_types: bytes long

return_type: unsigned long

user_defined_types: struct log { char *prefix; unsigned long maxbytes; unsigned long maxcount; unsigned long bytes; unsigned long count; int fd; }


decompiled_code:
void __fastcall log_stop(void *ptr)
{
int v2; // edi

v2 = *((_DWORD *)ptr + 10);
if ( v2 > 0 )
close(v2);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int v2; // edi

v2 = *((_DWORD *)ptr + 10);
if ( v2 > 0 )
close(v2);
free(*(void **)ptr);
free(ptr);
}

original_code:
void log_stop(struct log *log)
{
 if (log->fd > 0)
  close(log->fd);
 free(log->prefix);
 free(log);
}


decompiled_code:
void __fastcall do_copy(int fd, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
_BYTE v5[1064]; // [rsp+0h] [rbp-428h] BYREF

while ( 1 )
{
v2 = read(fd, v5, 0x400uLL);
v3 = v2;
if ( v2 <= 0 )
break;
do
{
v4 = write(a2, v5, v3);
if ( v4 <= 0 )
perror("do_copy: write");
v3 -= v4;
}
while ( v3 > 0 );
}
if ( v2 )
perror("do_copy: read");
}

canonical_decompiled_code:
void __fastcall func8(int fd, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
_BYTE v5[1064]; // [rsp+0h] [rbp-428h] BYREF

while ( 1 )
{
v2 = read(fd, v5, 0x400uLL);
v3 = v2;
if ( v2 <= 0 )
break;
do
{
v4 = write(a2, v5, v3);
if ( v4 <= 0 )
perror("do_copy: write");
v3 -= v4;
}
while ( v3 > 0 );
}
if ( v2 )
perror("do_copy: read");
}

original_code:
void do_copy(int input, int output){
 char buf[1024];
 int n;
 while ((n = read(input, buf, sizeof(buf))) > 0) {
  char *p = buf;
  while (n > 0) {
   int m = write(output, buf, n);
   if (m <= 0) {
    perror("do_copy: write");
   }
   p += m;
   n -= m;
  }
 }
 if (n < 0) {
  perror("do_copy: read");
 }
}

variable_types: input int

variable_types: output int

variable_types:
buf
char [1024]

variable_types: n int

variable_types:
p
char *

variable_types: m int


decompiled_code:
__int64 __fastcall do_connect(char *s, __int16 a2)
{
struct hostent *v2; // rax
int v3; // edx
char *v4; // rax
int v5; // edx
int v6; // eax
unsigned int v7; // er12
struct sockaddr v9; // [rsp+0h] [rbp-28h] BYREF

v2 = gethostbyname(s);
if ( !v2 )
{
fprintf(stderr, "can't lookup %s\n", s);
exit(1);
}
v3 = v2->h_addrtype;
v4 = *v2->h_addr_list;
v9.sa_family = v3;
*(_DWORD *)&v9.sa_data[2] = *(_DWORD *)v4;
*(_WORD *)v9.sa_data = _bswap_16(a2);
v6 = socket(2, 1, v5);
v7 = v6;
if ( v6 < 0 )
{
perror("socket");
exit(1);
}
if ( connect(v6, &v9, 0x10u) < 0 )
{
perror(s);
exit(1);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s, __int16 a2)
{
struct hostent *v2; // rax
int v3; // edx
char *v4; // rax
int v5; // edx
int v6; // eax
unsigned int v7; // er12
struct sockaddr v9; // [rsp+0h] [rbp-28h] BYREF

v2 = gethostbyname(s);
if ( !v2 )
{
fprintf(stderr, "can't lookup %s\n", s);
exit(1);
}
v3 = v2->h_addrtype;
v4 = *v2->h_addr_list;
v9.sa_family = v3;
*(_DWORD *)&v9.sa_data[2] = *(_DWORD *)v4;
*(_WORD *)v9.sa_data = func7(a2);
v6 = socket(2, 1, v5);
v7 = v6;
if ( v6 < 0 )
{
perror("socket");
exit(1);
}
if ( connect(v6, &v9, 0x10u) < 0 )
{
perror(s);
exit(1);
}
return v7;
}

original_code:
int do_connect(char *peer, int port){
 struct hostent *h;
 if ((h = gethostbyname(peer)) == 0) {
  fprintf(stderr, "can't lookup %s\n", peer);
  exit(1);
 }
 struct sockaddr_in addr;
 addr.sin_family = 2;
 addr.sin_family = h->h_addrtype;
 addr.sin_addr = * (struct in_addr *) *h->h_addr_list;
 addr.sin_port = htons(port);
 int s;
 if ((s = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  exit(1);
 }
 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  perror(peer);
  exit(1);
 }
 return s;
}

variable_types:
peer
char *

variable_types: port int

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

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: s int

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


main

canonical_name: main

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

atoi(argv[1]);
atoi(argv[2]);
v3 = do_connect("localhost");
v4 = do_connect("localhost");
do_copy(v3, v4);
return 0;
}

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

atoi(argv[1]);
atoi(argv[2]);
v3 = func9("localhost");
v4 = func9("localhost");
func8(v3, v4);
return 0;
}

original_code:
int main(int argc, char *argv[]){
 int inport = atoi(argv[1]);
 int outport = atoi(argv[2]);
 int input = do_connect("localhost", inport);
 int output = do_connect("localhost", outport);
 (void)argc;
 do_copy(input, output);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: inport int

variable_types: outport int


decompiled_code:
__int64 __fastcall resolve_address(void *dest, char *name, char *service)
{
unsigned int v3; // er12
struct addrinfo *v4; // r13
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

req.ai_flags = 0;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_family = 2;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(name, service, &req, &pai);
if ( !v3 )
{
v4 = pai;
memcpy(dest, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(v4);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *dest, char *name, char *service)
{
unsigned int v3; // er12
struct addrinfo *v4; // r13
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

req.ai_flags = 0;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_family = 2;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(name, service, &req, &pai);
if ( !v3 )
{
v4 = pai;
memcpy(dest, pai->ai_addr, pai->ai_addrlen);
freeaddrinfo(v4);
}
return v3;
}

original_code:
static int resolve_address(struct sockaddr_in *addr, const char *host,
      const char *port)
{
 struct addrinfo hints;
 struct addrinfo *ai;
 int err;
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 2;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 err = getaddrinfo(host, port, &hints, &ai);
 if (err)
  return err;
 memcpy(addr, ai->ai_addr, ai->ai_addrlen);
 freeaddrinfo(ai);
 return 0;
}

canonical_original_code:
static int resolve_address(struct sockaddr_in *addr, char *host, char *port)
{
 struct addrinfo hints;
 struct addrinfo *ai;
 int err;
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 2;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 err = getaddrinfo(host, port, &hints, &ai);
 if (err)
  return err;
 memcpy(addr, ai->ai_addr, ai->ai_addrlen);
 freeaddrinfo(ai);
 return 0;
}

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:
host
char *

variable_types:
port
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: err int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall connect_to_peer(struct sockaddr *addr, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
int v5; // edx
const void *v6; // rcx
socklen_t v7; // er8
int v8; // edi
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addra; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v2 = socket(2, 1, 6);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
if ( a2
&& (addra.sa_family = 2,
*(_DWORD *)&addra.sa_data[2] = _bswap_32_constprop_0(a2, 1LL, 2LL),
*(_WORD *)addra.sa_data = _bswap_16(a2),
setsockopt(v3, 1, v5, v6, v7),
bind(v3, &addra, 0x10u) < 0)
|| connect(v3, addr, 0x10u) < 0 )
{
v8 = v3;
v3 = -1;
close(v8);
}
else
{
setsockopt(v3, 6, 1, &optval, 4u);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(struct sockaddr *addr, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
int v5; // edx
const void *v6; // rcx
socklen_t v7; // er8
int v8; // edi
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addra; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v2 = socket(2, 1, 6);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
if ( a2
&& (addra.sa_family = 2,
*(_DWORD *)&addra.sa_data[2] = func3(a2, 1LL, 2LL),
*(_WORD *)addra.sa_data = func1(a2),
setsockopt(v3, 1, v5, v6, v7),
bind(v3, &addra, 0x10u) < 0)
|| connect(v3, addr, 0x10u) < 0 )
{
v8 = v3;
v3 = -1;
close(v8);
}
else
{
setsockopt(v3, 6, 1, &optval, 4u);
}
return v3;
}

original_code:
static int connect_to_peer(struct sockaddr_in *peeraddr, uint16_t bindport)
{
 int s;
 int yes = 1;
 struct sockaddr_in self;
 s = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (s < 0)
  return -1;
 if (bindport) {
  self.sin_family = 2;
  self.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  self.sin_port = htons(bindport);
  setsockopt(s, 1, 2, &yes, sizeof(yes));
  if (bind(s, (struct sockaddr *)&self, sizeof(self)) < 0) {
   close(s);
   return -1;
  }
 }
 if (connect(s, (struct sockaddr *)peeraddr, sizeof(*peeraddr)) < 0) {
  close(s);
  return -1;
 }
 setsockopt(s, IPPROTO_TCP, 1, &yes, sizeof(yes));
 return s;
}

canonical_original_code:
static int connect_to_peer(struct sockaddr_in *peeraddr, unsigned short bindport)
{
 int s;
 int yes = 1;
 struct sockaddr_in self;
 s = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (s < 0)
  return -1;
 if (bindport) {
  self.sin_family = 2;
  self.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  self.sin_port = htons(bindport);
  setsockopt(s, 1, 2, &yes, sizeof(yes));
  if (bind(s, (struct sockaddr *)&self, sizeof(self)) < 0) {
   close(s);
   return -1;
  }
 }
 if (connect(s, (struct sockaddr *)peeraddr, sizeof(*peeraddr)) < 0) {
  close(s);
  return -1;
 }
 setsockopt(s, IPPROTO_TCP, 1, &yes, sizeof(yes));
 return s;
}

variable_types:
bindport
unsigned short

variable_types: yes int


decompiled_code:
char *__fastcall parse_arguments(__int64 a1, int a2, char *const *a3)
{
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
__int64 v8; // rdx
char *v9; // rcx
char *result; // rax

*(char **)a1 = *a3;
while ( 1 )
{
v4 = getopt(a2, a3, "l:n:s:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'n':
v6 = atoi(optarg);
*(_DWORD *)(a1 + 20) = v6;
if ( v6 <= 0 )
goto LABEL_8;
break;
case 's':
v5 = atoi(optarg);
*(_DWORD *)(a1 + 16) = v5;
if ( v5 <= 0 )
goto LABEL_8;
break;
case 'l':
*(_QWORD *)(a1 + 8) = optarg;
break;
default:
goto LABEL_8;
}
}
v7 = optind;
if ( a2 - optind != 5 )
LABEL_8:
usage_isra_0(*(const char **)a1);
v8 = optind;
*(char **)(a1 + 24) = a3[v8];
*(char **)(a1 + 32) = a3[v8 + 1];
*(char **)(a1 + 56) = a3[v8 + 2];
v9 = a3[v8 + 3];
optind = v7 + 5;
*(_QWORD *)(a1 + 40) = v9;
result = a3[v8 + 4];
*(_QWORD *)(a1 + 48) = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, int a2, char *const *a3)
{
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
__int64 v8; // rdx
char *v9; // rcx
char *result; // rax

*(char **)a1 = *a3;
while ( 1 )
{
v4 = getopt(a2, a3, "l:n:s:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'n':
v6 = atoi(optarg);
*(_DWORD *)(a1 + 20) = v6;
if ( v6 <= 0 )
goto LABEL_8;
break;
case 's':
v5 = atoi(optarg);
*(_DWORD *)(a1 + 16) = v5;
if ( v5 <= 0 )
goto LABEL_8;
break;
case 'l':
*(_QWORD *)(a1 + 8) = optarg;
break;
default:
goto LABEL_8;
}
}
v7 = optind;
if ( a2 - optind != 5 )
LABEL_8:
func5(*(const char **)a1);
v8 = optind;
*(char **)(a1 + 24) = a3[v8];
*(char **)(a1 + 32) = a3[v8 + 1];
*(char **)(a1 + 56) = a3[v8 + 2];
v9 = a3[v8 + 3];
optind = v7 + 5;
*(_QWORD *)(a1 + 40) = v9;
result = a3[v8 + 4];
*(_QWORD *)(a1 + 48) = result;
return result;
}

original_code:
static void parse_arguments(struct arguments *args, int argc, char **argv)
{
 int c;
 args->name = argv[0];
 while ((c = getopt(argc, argv, "l:n:s:")) != -1)
  switch (c) {
  case 'l':
   args->logprefix = optarg;
   break;
  case 's':
   args->logbytes = atoi(optarg);
   if (args->logbytes <= 0)
    usage(args);
   break;
  case 'n':
   args->logcount = atoi(optarg);
   if (args->logcount <= 0)
    usage(args);
   break;
  default:
   usage(args);
  }
 if (argc - optind != 5)
  usage(args);
 args->pullhost = argv[optind++];
 args->pullport = argv[optind++];
 args->id = argv[optind++];
 args->pushhost = argv[optind++];
 args->pushport = argv[optind++];
}

variable_types: struct arguments { char *name; char *logprefix; int logbytes; int logcount; char *pullhost; char *pullport; char *pushhost; char *pushport; char *id; } *

variable_types:
argv
char **

variable_types: c int


decompiled_code:
int __fastcall get_args(int argc, char **argv)
{
char *v2; // rax
int result; // eax

prog_args = (__int64)*argv;
while ( 1 )
{
result = getopt(argc, argv, "p:");
if ( result == -1 )
break;
if ( result != 112 )
goto LABEL_7;
if ( *(&prog_args + 1) )
{
fprintf(stderr, "%s: can specify only one port\n", (const char *)prog_args);
exit(1);
}
v2 = optarg;
*(&prog_args + 1) = (__int64)optarg;
if ( !v2 )
{
fprintf(stderr, "%s: -p takes a port argument\n", 0LL);
exit(1);
}
}
if ( optind != argc )
LABEL_7:
usage();
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv)
{
char *v2; // rax
int result; // eax

prog_args = (__int64)*argv;
while ( 1 )
{
result = getopt(argc, argv, "p:");
if ( result == -1 )
break;
if ( result != 112 )
goto LABEL_7;
if ( *(&prog_args + 1) )
{
fprintf(stderr, "%s: can specify only one port\n", (const char *)prog_args);
exit(1);
}
v2 = optarg;
*(&prog_args + 1) = (__int64)optarg;
if ( !v2 )
{
fprintf(stderr, "%s: -p takes a port argument\n", 0LL);
exit(1);
}
}
if ( optind != argc )
LABEL_7:
func0();
return result;
}

original_code:
static void get_args(int argc, char *argv[]){
 prog_args.name = argv[0];
 int c;
 while ((c = getopt(argc, argv, "p:")) != -1) {
  switch (c) {
   case 'p':
    if (prog_args.port != 0) {
     fprintf(stderr, "%s: can specify only one port\n", prog_args.name);
     exit(1);
    }
    if ((prog_args.port = optarg) == 0) {
     fprintf(stderr, "%s: -p takes a port argument\n", prog_args.port);
     exit(1);
    }
    break;
   case '?':
   default:
    usage();
  }
 }
 if (argc - optind != 0) {
  usage();
 }
}


decompiled_code:
__int64 __fastcall do_copy(int fd)
{
int v1; // ebx
FILE *v2; // rbp
FILE *v3; // r12
int v4; // eax
__int64 v5; // rax
_DWORD *v6; // r13
double v7; // xmm0_8
double v8; // xmm0_8
signed int v9; // er14
unsigned int v10; // edx
double v12; // [rsp+8h] [rbp-80h]
double v13; // [rsp+10h] [rbp-78h]
double v14; // [rsp+18h] [rbp-70h]
struct timeval tv; // [rsp+20h] [rbp-68h] BYREF
char ptr[88]; // [rsp+30h] [rbp-58h] BYREF

v1 = 1;
v2 = fopen("out.0230.dat", "r");
v3 = fdopen(fd, "w");
gettimeofday(&tv, 0LL);
v14 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
while ( !feof(v2) )
{
v4 = fread(ptr, 0x2AuLL, 1uLL, v2);
if ( !v4 )
break;
if ( v4 < 0 )
{
perror("do_copy: fread");
exit(1);
}
v5 = get_c37_packet(ptr);
v6 = (_DWORD *)v5;
if ( !v5 )
{
fprintf(stderr, "%s: do_copy: bad packet\n", prog_args);
LABEL_15:
exit(1);
}
if ( *(_WORD *)(v5 + 2) != 42 )
{
fprintf(stderr, "%s: do_copy: bad frame size\n", prog_args);
goto LABEL_15;
}
v7 = (double)(*(_DWORD *)(v5 + 12) & 0xFFFFFF) * 0.00000005960464477539062 + (double)*(int *)(v5 + 8);
if ( v1 )
v13 = (double)(*(_DWORD *)(v5 + 12) & 0xFFFFFF) * 0.00000005960464477539062 + (double)*(int *)(v5 + 8);
v12 = (double)(*(_DWORD *)(v5 + 12) & 0xFFFFFF) * 0.00000005960464477539062 + (double)*(int *)(v5 + 8);
gettimeofday(&tv, 0LL);
v8 = v7 - v13 + v14;
v9 = (int)((v8 - ((double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec))) * 1000000.0);
if ( v9 > 0 )
{
fflush(v3);
usleep(v9);
v8 = v12 - v13 + v14;
}
v1 = 0;
v10 = v6[3] & 0xFF000000;
v6[2] = (int)v8;
v6[3] = v10 | (int)((v8 - (double)(int)v8) * 1000000.0);
write_c37_packet(v3, v6);
free(v6);
}
fclose(v2);
fclose(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd)
{
int v1; // ebx
FILE *v2; // rbp
FILE *v3; // r12
int v4; // eax
__int64 v5; // rax
_DWORD *v6; // r13
double v7; // xmm0_8
double v8; // xmm0_8
signed int v9; // er14
unsigned int v10; // edx
double v12; // [rsp+8h] [rbp-80h]
double v13; // [rsp+10h] [rbp-78h]
double v14; // [rsp+18h] [rbp-70h]
struct timeval tv; // [rsp+20h] [rbp-68h] BYREF
char ptr[88]; // [rsp+30h] [rbp-58h] BYREF

v1 = 1;
v2 = fopen("out.0230.dat", "r");
v3 = fdopen(fd, "w");
gettimeofday(&tv, 0LL);
v14 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
while ( !feof(v2) )
{
v4 = fread(ptr, 0x2AuLL, 1uLL, v2);
if ( !v4 )
break;
if ( v4 < 0 )
{
perror("do_copy: fread");
exit(1);
}
v5 = get_c37_packet(ptr);
v6 = (_DWORD *)v5;
if ( !v5 )
{
fprintf(stderr, "%s: do_copy: bad packet\n", prog_args);
LABEL_15:
exit(1);
}
if ( *(_WORD *)(v5 + 2) != 42 )
{
fprintf(stderr, "%s: do_copy: bad frame size\n", prog_args);
goto LABEL_15;
}
v7 = (double)(*(_DWORD *)(v5 + 12) & 0xFFFFFF) * 0.00000005960464477539062 + (double)*(int *)(v5 + 8);
if ( v1 )
v13 = (double)(*(_DWORD *)(v5 + 12) & 0xFFFFFF) * 0.00000005960464477539062 + (double)*(int *)(v5 + 8);
v12 = (double)(*(_DWORD *)(v5 + 12) & 0xFFFFFF) * 0.00000005960464477539062 + (double)*(int *)(v5 + 8);
gettimeofday(&tv, 0LL);
v8 = v7 - v13 + v14;
v9 = (int)((v8 - ((double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec))) * 1000000.0);
if ( v9 > 0 )
{
fflush(v3);
usleep(v9);
v8 = v12 - v13 + v14;
}
v1 = 0;
v10 = v6[3] & 0xFF000000;
v6[2] = (int)v8;
v6[3] = v10 | (int)((v8 - (double)(int)v8) * 1000000.0);
write_c37_packet(v3, v6);
free(v6);
}
fclose(v2);
fclose(v3);
return 1LL;
}

canonical_original_code:
void do_copy(int input, int output){
 char buf[1024];
 int n;
 while ((n = read(input, buf, sizeof(buf))) > 0) {
  char *p = buf;
  while (n > 0) {
   int m = write(output, buf, n);
   if (m <= 0) {
    perror("do_copy: write");
   }
   p += m;
   n -= m;
  }
 }
 if (n < 0) {
  perror("do_copy: read");
 }
}

variable_types: input int

variable_types: output int

variable_types:
buf
char [1024]

variable_types: n int

variable_types:
p
char *

variable_types: m int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
__int64 i; // rbx
__int64 v5; // rbx
_DWORD *v6; // rax
__int64 v7; // rsi
int v11; // [rsp+0h] [rbp-28h] BYREF
int v12; // [rsp+4h] [rbp-24h] BYREF
_DWORD *v13; // [rsp+8h] [rbp-20h] BYREF
_DWORD *v14; // [rsp+10h] [rbp-18h] BYREF
__int64 v15[2]; // [rsp+18h] [rbp-10h] BYREF

v13 = malloc(0x10uLL);
mdi_init(&v13, argv);
v14 = malloc(0x10uLL);
mdi_init(&v14, argv);
v15[0] = (__int64)malloc(0x10uLL);
mdi_init(v15, argv);
puts(
"1. Compute Sum of n mdi data\n"
"2. Compute n!\n"
"3. Compute 2^n\n"
"Enter the serial number. Enter '4' to switch to another computation. Enter '-1' to exit:");
while ( (unsigned int)_isoc99_scanf("%d", &v11) )
{
if ( v11 != 5 )
{
switch ( v11 )
{
case 1:
puts("Enter the number of mdi data to be added:");
_isoc99_scanf("%d", &v12);
mdi_set_int(v15, 0LL);
puts("Enter the mdi numbers:");
while ( v12-- )
{
while ( 1 )
{
v13 = (_DWORD *)read_mdi(v13);
mdi_set(&v14, v15[0]);
if ( v13[3] < v14[3] )
break;
mdi_add(v15, v13, v14);
if ( !v12-- )
goto LABEL_14;
}
mdi_add(v15, v14, v13);
}
break;
case 2:
puts("Enter the number for which factorial is to be calculated:");
_isoc99_scanf("%d", &v12);
mdi_init(v15, &v12);
mdi_set_int(v15, 1LL);
if ( v12 > 0 )
{
v5 = 1LL;
do
{
v6 = v13;
v7 = v15[0];
**(_DWORD **)v13 = v5++;
v6[3] = 1;
mdi_set(&v14, v7);
mdi_mul(v15, v14, v13);
}
while ( v12 >= v5 );
}
break;
case 3:
puts("Enter the power of 2:");
_isoc99_scanf("%d", &v12);
mdi_init(v15, &v12);
mdi_set_int(v15, 1LL);
v3 = v13;
**(_DWORD **)v13 = 2;
v3[3] = 1;
if ( v12 > 0 )
{
for ( i = 1LL; i <= v12; ++i )
{
mdi_set(&v14, v15[0]);
mdi_mul(v15, v14, v13);
}
}
break;
default:
return 0;
}
LABEL_14:
print_mdi(v15[0]);
}
}
return 0;
}

original_code:
int main()
{
 int j, k, flag, n;
 long int num, i;
 mdi_ptr input1, input2, res;
 input1 = (mdi_ptr)malloc(sizeof(mdi));
 mdi_init(&input1);
 input2 = (mdi_ptr)malloc(sizeof(mdi));
 mdi_init(&input2);
 res = (mdi_ptr)malloc(sizeof(mdi));
 mdi_init(&res);
 printf("1. Compute Sum of n mdi data\n2. Compute n!\n3. Compute 2^n\nEnter the serial number. Enter '4' to switch to another computation. Enter '-1' to exit:\n");
 while(scanf("%d", &flag))
 {
  if(flag == 5)
   continue;
  else if(flag == 1)
  {
   printf("Enter the number of mdi data to be added:\n");
   scanf("%d", &n);
   mdi_set_int(&res, 0);
   printf("Enter the mdi numbers:\n");
   while(n--)
   {
    input1 = read_mdi(input1);
    mdi_set(&input2, res);
    if(input1->digits >= input2->digits)
     mdi_add(&res, input1, input2);
    else
     mdi_add(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 2)
  {
   printf("Enter the number for which factorial is to be calculated:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   for(i=1; i<=n; i++)
   {
    input1->dp[0] = i;
    input1->digits = 1;
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 3)
  {
   printf("Enter the power of 2:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   input1->dp[0] = 2;
   input1->digits = 1;
   for(i=1; i<=n; i++)
   {
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else
   break;
 }
 return 0;
}

canonical_original_code:
int main()
{
 int j; int k; int flag; int n;
 long num; long i;
 struct mdi *input1; struct mdi *input2; struct mdi *res;
 input1 = (struct mdi *)malloc(sizeof(mdi));
 mdi_init(&input1);
 input2 = (struct mdi *)malloc(sizeof(mdi));
 mdi_init(&input2);
 res = (struct mdi *)malloc(sizeof(mdi));
 mdi_init(&res);
 printf("1. Compute Sum of n mdi data\n2. Compute n!\n3. Compute 2^n\nEnter the serial number. Enter '4' to switch to another computation. Enter '-1' to exit:\n");
 while(scanf("%d", &flag))
 {
  if(flag == 5)
   continue;
  else if(flag == 1)
  {
   printf("Enter the number of mdi data to be added:\n");
   scanf("%d", &n);
   mdi_set_int(&res, 0);
   printf("Enter the mdi numbers:\n");
   while(n--)
   {
    input1 = read_mdi(input1);
    mdi_set(&input2, res);
    if(input1->digits >= input2->digits)
     mdi_add(&res, input1, input2);
    else
     mdi_add(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 2)
  {
   printf("Enter the number for which factorial is to be calculated:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   for(i=1; i<=n; i++)
   {
    input1->dp[0] = i;
    input1->digits = 1;
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 3)
  {
   printf("Enter the power of 2:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   input1->dp[0] = 2;
   input1->digits = 1;
   for(i=1; i<=n; i++)
   {
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else
   break;
 }
 return 0;
}

variable_types: j int

variable_types: k int

variable_types: flag int

variable_types: num long

variable_types: i long

variable_types: struct mdi { unsigned int *dp; int ss; unsigned int digits; } *


repo: raidenawkward/nn

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 64) )
bp_layer_destory_nodes();
result = bp_node_destory(a1);
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 64) )
func0();
result = bp_node_destory(a1);
}
return result;
}

original_code:
static void bp_layer_destory_nodes(struct BPNode* node) {
 if (!node)
  return;
 if (node->next)
  bp_layer_destory_nodes(node->next);
 bp_node_destory(node);
}

canonical_original_code:
static void bp_layer_destory_nodes(struct BPNode *node) {
 if (!node)
  return;
 if (node->next)
  bp_layer_destory_nodes(node->next);
 bp_node_destory(node);
}

variable_types: struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *


decompiled_code:
float *__fastcall bp_layer_make_random_array(int a1, int a2)
{
float *v2; // r13
unsigned int v3; // eax
float *v4; // rbx

v2 = (float *)malloc(4LL * a1);
if ( v2 )
{
v3 = time(0LL);
srand(v3);
if ( a1 > 0 )
{
v4 = v2;
do
*v4++ = (float)(rand() % a2) / (float)a2;
while ( v4 != &v2[a1] );
}
}
return v2;
}

canonical_decompiled_code:
float *__fastcall func1(int a1, int a2)
{
float *v2; // r13
unsigned int v3; // eax
float *v4; // rbx

v2 = (float *)malloc(4LL * a1);
if ( v2 )
{
v3 = time(0LL);
srand(v3);
if ( a1 > 0 )
{
v4 = v2;
do
*v4++ = (float)(rand() % a2) / (float)a2;
while ( v4 != &v2[a1] );
}
}
return v2;
}

original_code:
static float* bp_layer_make_random_array(int length, int accuracy) {
 float *array = (float*)malloc(sizeof(float) * length);
 if (!array)
  return array;
 int i;
 srand(time(((void *)0)));
 for (i = 0; i < length; ++i) {
  array[i] = ((float)(rand() % accuracy)) / accuracy;
 }
 return array;
}

canonical_original_code:
static float *bp_layer_make_random_array(int length, int accuracy) {
 float *array = (float*)malloc(sizeof(float) * length);
 if (!array)
  return array;
 int i;
 srand(time(((void *)0)));
 for (i = 0; i < length; ++i) {
  array[i] = ((float)(rand() % accuracy)) / accuracy;
 }
 return array;
}

variable_types: length int

variable_types: accuracy int

variable_types:
array
float *

variable_types: i int

return_type: float *


decompiled_code:
_DWORD *bp_layer_create()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
struct BPLayer* bp_layer_create() {
 struct BPLayer* layer = (struct BPLayer*)malloc(sizeof(struct BPLayer));
 if (!layer)
  return layer;
 layer->first = ((void *)0);
 layer->node_count = 0;
 return layer;
}

canonical_original_code:
struct BPLayer *bp_layer_create() {
 struct BPLayer *layer = (struct BPLayer*)malloc(sizeof(struct BPLayer));
 if (!layer)
  return layer;
 layer->first = ((void *)0);
 layer->node_count = 0;
 return layer;
}

variable_types: struct BPLayer { struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *first; int node_count; } *

user_defined_types: struct BPLayer { struct BPNode *first; int node_count; }


decompiled_code:
__int64 __fastcall bp_layer_indexed_node(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

if ( !a1 || *((_DWORD *)a1 + 2) <= a2 )
return 0LL;
result = *a1;
if ( *a1 && a2 )
{
v3 = 0;
do
{
result = *(_QWORD *)(result + 64);
++v3;
}
while ( result && a2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

if ( !a1 || *((_DWORD *)a1 + 2) <= a2 )
return 0LL;
result = *a1;
if ( *a1 && a2 )
{
v3 = 0;
do
{
result = *(_QWORD *)(result + 64);
++v3;
}
while ( result && a2 != v3 );
}
return result;
}

original_code:
struct BPNode* bp_layer_indexed_node(struct BPLayer* layer, int index) {
 if (!layer)
  return ((void *)0);
 if (index >= layer->node_count)
  return ((void *)0);
 struct BPNode* node = layer->first;
 int current = 0;
 while(node) {
  if (current == index)
   return node;
  node = node->next;
  ++ current;
 }
 return ((void *)0);
}

canonical_original_code:
struct BPNode *bp_layer_indexed_node(struct BPLayer *layer, int index) {
 if (!layer)
  return ((void *)0);
 if (index >= layer->node_count)
  return ((void *)0);
 struct BPNode *node = layer->first;
 int current = 0;
 while(node) {
  if (current == index)
   return node;
  node = node->next;
  ++ current;
 }
 return ((void *)0);
}

variable_types: struct BPLayer { struct BPNode *first; int node_count; } *

variable_types: index int

variable_types: current int

return_type: struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *


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

if ( a1 )
result = bp_layer_destory_nodes(*a1);
return result;
}

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

if ( a1 )
result = func0(*a1);
return result;
}

original_code:
void bp_layer_destory(struct BPLayer* layer) {
 if (!layer)
  return;
 bp_layer_destory_nodes(layer->first);
}

canonical_original_code:
void bp_layer_destory(struct BPLayer *layer) {
 if (!layer)
  return;
 bp_layer_destory_nodes(layer->first);
}

user_defined_types: struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; }


original_code:
int bp_layer_append(struct BPLayer* layer, struct BPNode* node) {
 if (!layer || !node)
  return 0;
 if (layer->node_count < 0)
  return 0;
 if (layer->node_count == 0) {
  layer->first = node;
  node->next = ((void *)0);
 } else {
  struct BPNode* last = layer->first;
  while (last->next) {
   last = last->next;
  }
  last->next = node;
  node->next = ((void *)0);
 }
 ++ layer->node_count;
 return 1;
}

canonical_original_code:
int bp_layer_append(struct BPLayer *layer, struct BPNode *node) {
 if (!layer || !node)
  return 0;
 if (layer->node_count < 0)
  return 0;
 if (layer->node_count == 0) {
  layer->first = node;
  node->next = ((void *)0);
 } else {
  struct BPNode *last = layer->first;
  while (last->next) {
   last = last->next;
  }
  last->next = node;
  node->next = ((void *)0);
 }
 ++ layer->node_count;
 return 1;
}

variable_types:
node
struct BPNode *


original_code:
int bp_layer_connect(struct BPLayer* level0, struct BPLayer* level1) {
 if (!level1)
  return 0;
 if (!level0) {
  struct BPNode *node = level1->first;
  while (node) {
   memset(node->input_weights,0x00,10);
   node->input_weights[0] = (1.0);
   node->input_count = 1;
   node = node->next;
  }
  return 1;
 }
 struct BPNode* node = level1->first;
 while (node) {
  if (node->input_count >= 10)
   goto err;
  memset(node->input_weights,0x00,10);
  int i;
  for (i = 0; i < level0->node_count; ++i)
   node->input_weights[i] = (0.5);
  node->input_count = level0->node_count;
  node = node->next;
 }
 return 1;
err:
 return 0;
}

canonical_original_code:
int bp_layer_connect(struct BPLayer *level0, struct BPLayer *level1) {
 if (!level1)
  return 0;
 if (!level0) {
  struct BPNode *node = level1->first;
  while (node) {
   memset(node->input_weights,0x00,10);
   node->input_weights[0] = (1.0);
   node->input_count = 1;
   node = node->next;
  }
  return 1;
 }
 struct BPNode *node = level1->first;
 while (node) {
  if (node->input_count >= 10)
   goto err;
  memset(node->input_weights,0x00,10);
  int i;
  for (i = 0; i < level0->node_count; ++i)
   node->input_weights[i] = (0.5);
  node->input_count = level0->node_count;
  node = node->next;
 }
 return 1;
err:
 return 0;
}


decompiled_code:
void __fastcall bp_layer_weights_randomize(__int64 *a1, int a2)
{
__int64 i; // rbx
int v3; // edi
float *v4; // rdi
__int64 v5; // rdx
__int64 j; // rax

if ( a1 )
{
for ( i = *a1; i; i = *(_QWORD *)(i + 64) )
{
while ( 1 )
{
v3 = *(_DWORD *)(i + 40);
if ( v3 )
break;
i = *(_QWORD *)(i + 64);
if ( !i )
return;
}
v4 = bp_layer_make_random_array(v3, a2);
if ( !v4 )
break;
v5 = *(int *)(i + 40);
if ( (int)v5 > 0 )
{
for ( j = 0LL; j != v5; ++j )
*(float *)(i + 4 * j) = v4[j];
}
free(v4);
}
}
}

original_code:
void bp_layer_weights_randomize(struct BPLayer* layer, int accuracy) {
 if (!layer)
  return;
 struct BPNode *node = layer->first;
 while (node) {
  if (node->input_count) {
   float *rand_array = bp_layer_make_random_array(node->input_count,accuracy);
   if (!rand_array)
    return;
   int i;
   for (i = 0; i < node->input_count; ++i)
    node->input_weights[i] = rand_array[i];
   free(rand_array);
  }
  node = node->next;
 }
}

canonical_original_code:
void bp_layer_weights_randomize(struct BPLayer *layer, int accuracy) {
 if (!layer)
  return;
 struct BPNode *node = layer->first;
 while (node) {
  if (node->input_count) {
   float *rand_array = bp_layer_make_random_array(node->input_count,accuracy);
   if (!rand_array)
    return;
   int i;
   for (i = 0; i < node->input_count; ++i)
    node->input_weights[i] = rand_array[i];
   free(rand_array);
  }
  node = node->next;
 }
}


decompiled_code:
_WORD *bp_node_create()
{
_WORD *result; // rax

result = malloc(0x48uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[4] = 0;
*((_QWORD *)result + 5) = 0LL;
*((_DWORD *)result + 12) = 0;
*((_QWORD *)result + 7) = 0LL;
*((_QWORD *)result + 8) = 0LL;
}
return result;
}

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

result = malloc(0x48uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[4] = 0;
*((_QWORD *)result + 5) = 0LL;
*((_DWORD *)result + 12) = 0;
*((_QWORD *)result + 7) = 0LL;
*((_QWORD *)result + 8) = 0LL;
}
return result;
}

original_code:
struct BPNode* bp_node_create() {
 struct BPNode *node = (struct BPNode*)malloc(sizeof(struct BPNode));
 if (!node)
  return node;
 memset(node->input_weights,0x00,10);
 node->input_count = 0;
 node->threshold = 0;
 node->output = 0;
 node->get_output = ((void *)0);
 node->next = ((void *)0);
 return node;
}

canonical_original_code:
struct BPNode *bp_node_create() {
 struct BPNode *node = (struct BPNode*)malloc(sizeof(struct BPNode));
 if (!node)
  return node;
 memset(node->input_weights,0x00,10);
 node->input_count = 0;
 node->threshold = 0;
 node->output = 0;
 node->get_output = ((void *)0);
 node->next = ((void *)0);
 return node;
}


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

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

original_code:
void bp_node_destory(struct BPNode* node) {
 if (!node)
  return;
 free(node);
}

canonical_original_code:
void bp_node_destory(struct BPNode *node) {
 if (!node)
  return;
 free(node);
}


original_code:
static void print_net_info(struct BPNet* net) {
 if (!net) {
  printf("empty ptr!\n");
  return;
 }
 int i;
 for (i = 0; i < net->layer_count; ++i) {
  printf("level %d\t",i);
  struct BPNode *node = net->layers[i].first;
  int j = 0;
  while(node) {
   printf("node %d (",j);
   int k;
   for (k = 0; k < node->input_count; ++k) {
    printf("%0.3f",node->input_weights[k]);
    if (k != node->input_count - 1)
     printf(",");
   }
   printf(")\t");
   node = node->next;
   ++j;
  }
  printf("\n");
 }
}

canonical_original_code:
static void print_net_info(struct BPNet *net) {
 if (!net) {
  printf("empty ptr!\n");
  return;
 }
 int i;
 for (i = 0; i < net->layer_count; ++i) {
  printf("level %d\t",i);
  struct BPNode *node = net->layers[i].first;
  int j = 0;
  while(node) {
   printf("node %d (",j);
   int k;
   for (k = 0; k < node->input_count; ++k) {
    printf("%0.3f",node->input_weights[k]);
    if (k != node->input_count - 1)
     printf(",");
   }
   printf(")\t");
   node = node->next;
   ++j;
  }
  printf("\n");
 }
}

variable_types: struct BPNet { struct BPLayer { struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *first; int node_count; } *layers; int layer_count; } *

user_defined_types: struct BPNet { struct BPLayer *layers; int layer_count; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rsi
__int64 v6[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = bp_net_init(5LL, 3LL, envp);
v4 = *(unsigned int *)(v3 + 8);
v6[0] = v3;
printf("net inited , count of layer : %d\n", v4);
print_net_info(v6[0]);
bp_record_save(v6[0], "./record");
sync();
bp_net_destory(v6);
if ( (int)bp_record_load("./record", v6) < 0 )
{
puts("failded when loading");
}
else
{
printf("\nnet reinited , count of layer : %d\n", *(unsigned int *)(v6[0] + 8));
print_net_info(v6[0]);
bp_net_destory(v6);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rsi
__int64 v6[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = bp_net_init(5LL, 3LL, envp);
v4 = *(unsigned int *)(v3 + 8);
v6[0] = v3;
printf("net inited , count of layer : %d\n", v4);
func0(v6[0]);
bp_record_save(v6[0], "./record");
sync();
bp_net_destory(v6);
if ( (int)bp_record_load("./record", v6) < 0 )
{
puts("failded when loading");
}
else
{
printf("\nnet reinited , count of layer : %d\n", *(unsigned int *)(v6[0] + 8));
func0(v6[0]);
bp_net_destory(v6);
}
return 0;
}

original_code:
int main() {
 struct BPNet* net = bp_net_init(5,3);
 printf("net inited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_record_save(net,"./record");
 sync();
 bp_net_destory(&net);
 if (bp_record_load("./record",&net) < 0) {
  printf("failded when loading\n");
  return 0;
 }
 printf("\nnet reinited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_net_destory(&net);
 return 0;
}

canonical_original_code:
int main() {
 struct BPNet *net = bp_net_init(5,3);
 printf("net inited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_record_save(net,"./record");
 sync();
 bp_net_destory(&net);
 if (bp_record_load("./record",&net) < 0) {
  printf("failded when loading\n");
  return 0;
 }
 printf("\nnet reinited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_net_destory(&net);
 return 0;
}


decompiled_code:
__int64 __fastcall bp_record_generate_files_path(char *s, char **a2, char **a3, char **a4)
{
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char *v9; // rax

if ( !s )
return 0LL;
v6 = strlen(s);
*a2 = (char *)malloc(v6 + 12);
v7 = strlen(s);
*a3 = (char *)malloc(v7 + 14);
v8 = strlen(s);
v9 = (char *)malloc(v8 + 13);
*a4 = v9;
if ( !*a2 || !*a3 || !v9 )
return 0LL;
sprintf(*a2, "%s/%s", s, "record.net");
sprintf(*a3, "%s/%s", s, "record.layer");
sprintf(*a4, "%s/%s", s, "record.node");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, char **a2, char **a3, char **a4)
{
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char *v9; // rax

if ( !s )
return 0LL;
v6 = strlen(s);
*a2 = (char *)malloc(v6 + 12);
v7 = strlen(s);
*a3 = (char *)malloc(v7 + 14);
v8 = strlen(s);
v9 = (char *)malloc(v8 + 13);
*a4 = v9;
if ( !*a2 || !*a3 || !v9 )
return 0LL;
sprintf(*a2, "%s/%s", s, "record.net");
sprintf(*a3, "%s/%s", s, "record.layer");
sprintf(*a4, "%s/%s", s, "record.node");
return 1LL;
}

original_code:
static int bp_record_generate_files_path(const char* dir, char** net, char** layer, char** node) {
 if (!dir)
  return 0;
 *net = (char*)malloc(sizeof(char) * (strlen(dir) + strlen("record.net") + 2));
 *layer = (char*)malloc(sizeof(char) * (strlen(dir) + strlen("record.layer") + 2));
 *node = (char*)malloc(sizeof(char) * (strlen(dir) + strlen("record.node") + 2));
 if (!*net || !*layer || !*node)
  return 0;
 sprintf(*net,"%s/%s\0",dir,"record.net");
 sprintf(*layer,"%s/%s\0",dir,"record.layer");
 sprintf(*node,"%s/%s\0",dir,"record.node");
 return 1;
}

canonical_original_code:
static int bp_record_generate_files_path(char *dir, char **net, char **layer, char **node) {
 if (!dir)
  return 0;
 *net = (char *)malloc(sizeof(char) * (strlen(dir) + strlen("record.net") + 2));
 *layer = (char *)malloc(sizeof(char) * (strlen(dir) + strlen("record.layer") + 2));
 *node = (char *)malloc(sizeof(char) * (strlen(dir) + strlen("record.node") + 2));
 if (!*net || !*layer || !*node)
  return 0;
 sprintf(*net,"%s/%s\0",dir,"record.net");
 sprintf(*layer,"%s/%s\0",dir,"record.layer");
 sprintf(*node,"%s/%s\0",dir,"record.node");
 return 1;
}

variable_types:
dir
char *

variable_types:
net
char **

variable_types:
layer
char **

variable_types:
node
char **


decompiled_code:
_DWORD *bp_net_create()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

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

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
struct BPNet* bp_net_create() {
 struct BPNet *net = (struct BPNet*)malloc(sizeof(struct BPNet));
 if (!net)
  return net;
 net->layers = ((void *)0);
 net->layer_count = 0;
 return net;
}

canonical_original_code:
struct BPNet *bp_net_create() {
 struct BPNet *net = (struct BPNet*)malloc(sizeof(struct BPNet));
 if (!net)
  return net;
 net->layers = ((void *)0);
 net->layer_count = 0;
 return net;
}

return_type: struct BPNet { struct BPLayer { struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *first; int node_count; } *layers; int layer_count; } *


decompiled_code:
_BOOL8 __fastcall bp_net_append_layer(__int64 a1, const __m128i *a2)
{
char *v2; // rax
int v3; // edx
__m128i v4; // xmm0
__int64 v5; // rcx
__int64 v6; // rdi

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
*(_DWORD *)(a1 + 8) = 0;
v2 = (char *)realloc(*(void **)a1, 0x10uLL);
if ( !v2 )
return 0LL;
v3 = *(_DWORD *)(a1 + 8);
v4 = _mm_loadu_si128(a2);
*(_QWORD *)a1 = v2;
*(_DWORD *)(a1 + 8) = ++v3;
v5 = 16LL * v3;
v6 = (__int64)&v2[v5 - 32];
if ( !v3 )
v6 = 0LL;
*(__m128i *)&v2[v5 - 16] = v4;
return (unsigned int)bp_layer_connect(v6) != 0;
}

original_code:
int bp_net_append_layer(struct BPNet* net, struct BPLayer* layer) {
 if (!net || !layer)
  return 0;
 if (net->layer_count < 0)
  net->layer_count = 0;
 if (net->layer_count = 0) {
  net->layers = (struct BPLayer*)malloc(sizeof(struct BPLayer));
  if (!net->layers)
   return 0;
 } else {
  struct BPLayer* newLayers = (struct BPLayer*)realloc(net->layers,sizeof(struct BPLayer) * (net->layer_count + 1));
  if (!newLayers)
   return 0;
  net->layers = newLayers;
 }
 net->layers[++ net->layer_count - 1] = *layer;
 if (!bp_layer_connect(net->layer_count? &(net->layers[net->layer_count - 2]) : ((void *)0),
  &(net->layers[net->layer_count - 1])))
  return 0;
 return 1;
}

canonical_original_code:
int bp_net_append_layer(struct BPNet *net, struct BPLayer *layer) {
 if (!net || !layer)
  return 0;
 if (net->layer_count < 0)
  net->layer_count = 0;
 if (net->layer_count = 0) {
  net->layers = (struct BPLayer *)malloc(sizeof(struct BPLayer));
  if (!net->layers)
   return 0;
 } else {
  struct BPLayer *newLayers = (struct BPLayer*)realloc(net->layers,sizeof(struct BPLayer) * (net->layer_count + 1));
  if (!newLayers)
   return 0;
  net->layers = newLayers;
 }
 net->layers[++ net->layer_count - 1] = *layer;
 if (!bp_layer_connect(net->layer_count? &(net->layers[net->layer_count - 2]) : ((void *)0),
  &(net->layers[net->layer_count - 1])))
  return 0;
 return 1;
}

variable_types:
layer
struct BPLayer *


decompiled_code:
int __fastcall verify_line(const char *a1, const char *a2)
{
char *v2; // r12
char *v3; // rax
const char *v4; // r13
int result; // eax

v2 = strstr(a1, "[OUTPUT]");
v3 = strstr(a2, "[OUTPUT]");
if ( !v2 )
return 1;
v4 = v3;
if ( !v3 )
return 1;
result = strcmp(v2, v3);
if ( result )
{
printf("\x1B[32m%s %s\x1B[0m", "MASTER >>>>>", v2);
printf("\x1B[31m%s %s\n\x1B[0m", "STUDENT >>>>>", v4);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
char *v2; // r12
char *v3; // rax
const char *v4; // r13
int result; // eax

v2 = strstr(a1, "[OUTPUT]");
v3 = strstr(a2, "[OUTPUT]");
if ( !v2 )
return 1;
v4 = v3;
if ( !v3 )
return 1;
result = strcmp(v2, v3);
if ( result )
{
printf("\x1B[32m%s %s\x1B[0m", "MASTER >>>>>", v2);
printf("\x1B[31m%s %s\n\x1B[0m", "STUDENT >>>>>", v4);
result = 1;
}
return result;
}

original_code:
int verify_line( char *master, char *student ) {
  char *master_out, *student_out;
  int cmp;
  master_out = strstr(master, "[OUTPUT]");
  student_out = strstr(student, "[OUTPUT]");
  if ( !master_out || !student_out ) {
    return ( 1 );
  }
  cmp = strcmp( master_out, student_out );
  if ( cmp ) {
    printf( "\x1b[32m" "%s %s" "\x1b[0m",
        "MASTER  >>>>>", master_out );
    printf( "\x1b[31m" "%s %s\n" "\x1b[0m",
        "STUDENT >>>>>", student_out );
    return ( 1 );
  }
  return ( 0 );
}

canonical_original_code:
int verify_line(char *master, char *student) {
  char *master_out; char *student_out;
  int cmp;
  master_out = strstr(master, "[OUTPUT]");
  student_out = strstr(student, "[OUTPUT]");
  if ( !master_out || !student_out ) {
    return ( 1 );
  }
  cmp = strcmp( master_out, student_out );
  if ( cmp ) {
    printf( "\x1b[32m" "%s %s" "\x1b[0m",
        "MASTER  >>>>>", master_out );
    printf( "\x1b[31m" "%s %s\n" "\x1b[0m",
        "STUDENT >>>>>", student_out );
    return ( 1 );
  }
  return ( 0 );
}

variable_types:
master
char *

variable_types:
student
char *

variable_types: cmp int


repo: rajamony/denali

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
double v5; // xmm0_8
double v6; // xmm2_8
struct timeval v8; // [rsp+0h] [rbp-28h] BYREF

v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
gettimeofday(&v8, 0LL);
v5 = (double)SLODWORD(v8.tv_usec) / 1000000.0 * (double)(v4 - v3) + (double)v3;
v6 = 0.0;
if ( v5 >= 0.0 )
v6 = fmin(60.0, v5);
printf("Sleeping for %u micro-seconds\n", (unsigned int)(int)(v6 * 1000000.0));
usleep((int)(v6 * 1000000.0));
return 0;
}

original_code:
int main (int argc, char *argv[]) {
    struct timeval tp;
    int min = atoi (argv[1]);
    int max = atoi (argv[2]);
    gettimeofday (&tp, ((void *)0));
    double fraction = ((double) tp.tv_usec)/1e6;
    double howlong = min + fraction * (double) (max - min);
    if (howlong < 0)
        howlong = 0;
    if (howlong > 60)
 howlong = 60;
    useconds_t us = (useconds_t) (howlong * 1e6);
    printf ("Sleeping for %u micro-seconds\n", us);
    usleep (us);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct timeval tp;
    int min = atoi (argv[1]);
    int max = atoi (argv[2]);
    gettimeofday (&tp, ((void *)0));
    double fraction = ((double) tp.tv_usec)/1e6;
    double howlong = min + fraction * (double) (max - min);
    if (howlong < 0)
        howlong = 0;
    if (howlong > 60)
 howlong = 60;
    unsigned int us = (useconds_t) (howlong * 1e6);
    printf ("Sleeping for %u micro-seconds\n", us);
    usleep (us);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: min int

variable_types: max int

variable_types: fraction double

variable_types: howlong double

variable_types:
us
unsigned int


zeta

repo: rajatthomas/Mass-Function

original_code:
double zeta(double mass, double flux){
  double answer = 1+70*pow((1+redshift)/21, -5.) * pow(mass/1e6, -0.33333) * (flux/3e7);
  return pow(answer,-1.0/3.0);
}

variable_types: mass double

variable_types: flux double

variable_types: answer double

return_type: double


momentfunc

decompiled_code:
double __fastcall momentfunc(double a1)
{
double v2; // [rsp+0h] [rbp-18h]
double x; // [rsp+8h] [rbp-10h]

x = exp(a1);
zeta(x, 30000000.0);
v2 = x * pow(x, 0.6666);
return v2 * (x * MassFunc(x, redshift));
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
double v2; // [rsp+0h] [rbp-18h]
double x; // [rsp+8h] [rbp-10h]

x = exp(a1);
func0(x, 30000000.0);
v2 = x * pow(x, 0.6666);
return v2 * (x * MassFunc(x, redshift));
}

original_code:
double momentfunc(double mass, void * params){
  mass = exp(mass);
double integrand;
 integrand = zeta(mass,3e7) * pow(mass, .6666);
integrand *= MassFunc(mass,redshift) * mass;
return integrand;
}

canonical_original_code:
double momentfunc(double mass, void *params){
  mass = exp(mass);
double integrand;
 integrand = zeta(mass,3e7) * pow(mass, .6666);
integrand *= MassFunc(mass,redshift) * mass;
return integrand;
}

variable_types:
params
void *

variable_types: integrand double


crash

decompiled_code:
void __fastcall __noreturn crash(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void crash(char *s)
{
    fprintf(stderr,"%s\n", s); exit(1); return;
}

variable_types:
s
char *


warn

decompiled_code:
int __fastcall warn(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void warn(char *s)
{
    fprintf(stderr,"%s\n", s); return;
}


checking

decompiled_code:
__int64 checking()
{
double v0; // xmm0_8
double v1; // xmm2_8
double v2; // xmm0_8
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm0_8
double v7; // xmm2_8
double v8; // xmm3_8
double v9; // xmm0_8

qtensors = 0;
quiet = 0;
scale = LC1;
qredshift = 0;
if ( Omega_Matter <= 0.0 )
crash("Omega must be positive.");
if ( h_z0 <= 0.0 )
crash("Hubble constant must be positive.");
if ( h_z0 > 10.0 )
{
warn("Did you get the Hubble units right?");
if ( degen_Neutrino >= 0 )
goto LABEL_5;
}
else if ( degen_Neutrino >= 0 )
{
goto LABEL_5;
}
warn("Negative number of degenerate species reset to 1.");
degen_Neutrino = 1;
LABEL_5:
if ( redshift <= -1.0 )
crash("Redshift must exceed -1.");
v0 = Omega_Baryon;
if ( Omega_Baryon < 0.0 )
{
v0 = COERCE_DOUBLE(Omega_Baryon ^ LC9) * Omega_Matter;
Omega_Baryon = v0;
}
v1 = Omega_Neutrino;
if ( Omega_Neutrino < 0.0 )
{
v1 = COERCE_DOUBLE(Omega_Neutrino ^ LC9) * Omega_Matter;
Omega_Neutrino = v1;
}
if ( -2538.0 == Omega_Lambda )
Omega_Lambda = 1.0 - Omega_Matter;
v2 = v0 + v1;
if ( v2 > Omega_Matter )
crash("Baryons + Neutrinos exceeds Omega_0.");
if ( v2 > Omega_Matter * 0.6 )
warn("CDM fraction is below range of TF fitting formula.");
v3 = tilt;
if ( tilt > 1.3 || tilt < 0.7 )
{
warn("Tilt out of range of Bunn and White fitting formula.");
v3 = tilt;
}
v4 = *(double *)&LC11;
if ( v3 == 1.0 )
{
v5 = *(double *)&LC18;
}
else if ( Omega_Matter >= 0.2 && Omega_Matter <= 1.0
|| (warn("Omega out of range of Bunn and White fitting formula."),
v5 = *(double *)&LC18,
v4 = *(double *)&LC11,
1.0 != tilt) )
{
if ( !qtensors )
goto LABEL_24;
goto LABEL_30;
}
v6 = Omega_Matter;
if ( v5 <= Omega_Matter && Omega_Matter <= 1.6 )
{
v7 = Omega_Lambda;
if ( Omega_Lambda >= 0.0 && Omega_Lambda <= 0.8 )
{
if ( !qtensors )
goto LABEL_34;
goto LABEL_32;
}
}
warn("Omega or Lambda out of range of Bunn and White fitting formula.");
v4 = *(double *)&LC11;
if ( !qtensors )
{
LABEL_24:
v6 = Omega_Matter;
goto LABEL_34;
}
LABEL_30:
if ( tilt > v4 )
goto LABEL_55;
v7 = Omega_Lambda;
v6 = Omega_Matter;
LABEL_32:
if ( COERCE_DOUBLE(*(_QWORD *)&v7 & LC24) > 0.00001
&& COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v4 - v6 - v7) & LC24) > 0.00001 )
{
LABEL_55:
crash("Tensor formulae only hold for tilts < 1 and simple cosmologies.");
}
LABEL_34:
v8 = *(double *)&LC26;
if ( Omega_Baryon / v6 > 0.4 )
{
warn("Baryon oscillations will be large. TF fitting form will be inaccurate.");
v6 = Omega_Matter;
v8 = *(double *)&LC26;
}
if ( Omega_Neutrino / v6 > v8 )
{
warn("Neutrino fraction outside of range of TF fitting form.");
v6 = Omega_Matter;
v8 = *(double *)&LC26;
}
v9 = v6 * h_z0 * h_z0;
if ( v9 > v8 )
{
warn("Omega_0 h^2 outside of range of TF fitting form.");
v9 = Omega_Matter * h_z0 * h_z0;
}
if ( v9 < 0.06 )
warn("Omega_0 h^2 outside of range of TF fitting form.");
if ( redshift > 29.0 )
warn("Redshift is higher than range of TF fitting form.");
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
double v0; // xmm0_8
double v1; // xmm2_8
double v2; // xmm0_8
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm0_8
double v7; // xmm2_8
double v8; // xmm3_8
double v9; // xmm0_8

qtensors = 0;
quiet = 0;
scale = LC1;
qredshift = 0;
if ( Omega_Matter <= 0.0 )
func0("Omega must be positive.");
if ( h_z0 <= 0.0 )
func0("Hubble constant must be positive.");
if ( h_z0 > 10.0 )
{
func1("Did you get the Hubble units right?");
if ( degen_Neutrino >= 0 )
goto LABEL_5;
}
else if ( degen_Neutrino >= 0 )
{
goto LABEL_5;
}
func1("Negative number of degenerate species reset to 1.");
degen_Neutrino = 1;
LABEL_5:
if ( redshift <= -1.0 )
func0("Redshift must exceed -1.");
v0 = Omega_Baryon;
if ( Omega_Baryon < 0.0 )
{
v0 = COERCE_DOUBLE(Omega_Baryon ^ LC9) * Omega_Matter;
Omega_Baryon = v0;
}
v1 = Omega_Neutrino;
if ( Omega_Neutrino < 0.0 )
{
v1 = COERCE_DOUBLE(Omega_Neutrino ^ LC9) * Omega_Matter;
Omega_Neutrino = v1;
}
if ( -2538.0 == Omega_Lambda )
Omega_Lambda = 1.0 - Omega_Matter;
v2 = v0 + v1;
if ( v2 > Omega_Matter )
func0("Baryons + Neutrinos exceeds Omega_0.");
if ( v2 > Omega_Matter * 0.6 )
func1("CDM fraction is below range of TF fitting formula.");
v3 = tilt;
if ( tilt > 1.3 || tilt < 0.7 )
{
func1("Tilt out of range of Bunn and White fitting formula.");
v3 = tilt;
}
v4 = *(double *)&LC11;
if ( v3 == 1.0 )
{
v5 = *(double *)&LC18;
}
else if ( Omega_Matter >= 0.2 && Omega_Matter <= 1.0
|| (func1("Omega out of range of Bunn and White fitting formula."),
v5 = *(double *)&LC18,
v4 = *(double *)&LC11,
1.0 != tilt) )
{
if ( !qtensors )
goto LABEL_24;
goto LABEL_30;
}
v6 = Omega_Matter;
if ( v5 <= Omega_Matter && Omega_Matter <= 1.6 )
{
v7 = Omega_Lambda;
if ( Omega_Lambda >= 0.0 && Omega_Lambda <= 0.8 )
{
if ( !qtensors )
goto LABEL_34;
goto LABEL_32;
}
}
func1("Omega or Lambda out of range of Bunn and White fitting formula.");
v4 = *(double *)&LC11;
if ( !qtensors )
{
LABEL_24:
v6 = Omega_Matter;
goto LABEL_34;
}
LABEL_30:
if ( tilt > v4 )
goto LABEL_55;
v7 = Omega_Lambda;
v6 = Omega_Matter;
LABEL_32:
if ( COERCE_DOUBLE(*(_QWORD *)&v7 & LC24) > 0.00001
&& COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v4 - v6 - v7) & LC24) > 0.00001 )
{
LABEL_55:
func0("Tensor formulae only hold for tilts < 1 and simple cosmologies.");
}
LABEL_34:
v8 = *(double *)&LC26;
if ( Omega_Baryon / v6 > 0.4 )
{
func1("Baryon oscillations will be large. TF fitting form will be inaccurate.");
v6 = Omega_Matter;
v8 = *(double *)&LC26;
}
if ( Omega_Neutrino / v6 > v8 )
{
func1("Neutrino fraction outside of range of TF fitting form.");
v6 = Omega_Matter;
v8 = *(double *)&LC26;
}
v9 = v6 * h_z0 * h_z0;
if ( v9 > v8 )
{
func1("Omega_0 h^2 outside of range of TF fitting form.");
v9 = Omega_Matter * h_z0 * h_z0;
}
if ( v9 < 0.06 )
func1("Omega_0 h^2 outside of range of TF fitting form.");
if ( redshift > 29.0 )
func1("Redshift is higher than range of TF fitting form.");
return 1LL;
}

original_code:
int checking()
{
    scale = -1.0;
    qtensors = 0;
    quiet = 0;
    qredshift = 0;
    if (Omega_Matter<=0.0) crash("Omega must be positive.");
    if (h_z0<=0.0) crash("Hubble constant must be positive.");
 else if (h_z0>10.0) warn("Did you get the Hubble units right?");
    if (degen_Neutrino<0) {
 warn("Negative number of degenerate species reset to 1.");
 degen_Neutrino = 1.0;
    }
    if (redshift<=-1.0) crash("Redshift must exceed -1.");
    if (Omega_Baryon<0.0) Omega_Baryon = Omega_Matter*(-Omega_Baryon);
    if (Omega_Neutrino<0.0) Omega_Neutrino = Omega_Matter*(-Omega_Neutrino);
    if (Omega_Lambda== -2538) Omega_Lambda = 1-Omega_Matter;
    if (Omega_Baryon+Omega_Neutrino>Omega_Matter) crash("Baryons + Neutrinos exceeds Omega_0.");
 else if (Omega_Baryon+Omega_Neutrino>0.6*Omega_Matter)
     warn("CDM fraction is below range of TF fitting formula.");
    if (tilt>1.3 || tilt < 0.7)
 warn("Tilt out of range of Bunn and White fitting formula.");
    if (tilt!=1 && (Omega_Matter<0.2 || Omega_Matter>1.0))
 warn("Omega out of range of Bunn and White fitting formula.");
    if (tilt==1 && (Omega_Matter<0.2 || Omega_Matter>1.6 || Omega_Lambda<0.0 || Omega_Lambda>0.8))
 warn("Omega or Lambda out of range of Bunn and White fitting formula.");
    if (qtensors!=0&&(tilt>1.0||
 (fabs(Omega_Lambda)>1e-5&&fabs(1.0-Omega_Matter-Omega_Lambda)>1e-5)))
 crash("Tensor formulae only hold for tilts < 1 and simple cosmologies.");
    if (Omega_Baryon/Omega_Matter>0.4) warn("Baryon oscillations will be large.  TF fitting form will be inaccurate.");
    if (Omega_Neutrino/Omega_Matter>0.4) warn("Neutrino fraction outside of range of TF fitting form.");
    if (Omega_Matter*h_z0*h_z0>0.4) warn("Omega_0 h^2 outside of range of TF fitting form.");
    if (Omega_Matter*h_z0*h_z0<0.06) warn("Omega_0 h^2 outside of range of TF fitting form.");
    if (redshift>29) warn("Redshift is higher than range of TF fitting form.");
    return 1;
}


original_code:
double W2tophat(double x)
{
    double j1onx;
    if (x<0.03)
 j1onx = (1.0/3.0-x*x*1.0/30.0);
    else j1onx = (cos(x)-sin(x)/x)/x/x;
    return 9.0*j1onx*j1onx;
}

variable_types: x double


powerspcb

decompiled_code:
double __fastcall powerspcb(double a1)
{
double v2; // [rsp+8h] [rbp-20h]
double v4; // [rsp+10h] [rbp-18h]
double v5; // [rsp+18h] [rbp-10h]

v2 = pow(a1 * 2997.0, tilt + 3.0);
if ( *(double *)&deltaH * TransferFuncCDM_EH(a1) * growth_to_z0 == 0.0 )
return 0.0 * v2;
v5 = a1;
v4 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0;
return TransferFuncCDM_EH(v5) * *(double *)&deltaH * growth_to_z0 * v4 * v2;
}

canonical_decompiled_code:
double __fastcall func4(double a1)
{
double v2; // [rsp+8h] [rbp-20h]
double v4; // [rsp+10h] [rbp-18h]
double v5; // [rsp+18h] [rbp-10h]

v2 = pow(a1 * 2997.0, tilt + 3.0);
if ( *(double *)&deltaH * TransferFuncCDM_EH(a1) * growth_to_z0 == 0.0 )
return 0.0 * v2;
v5 = a1;
v4 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0;
return TransferFuncCDM_EH(v5) * *(double *)&deltaH * growth_to_z0 * v4 * v2;
}

original_code:
double powerspcb(double k)
{
    return pow(2997.0*k, tilt+3.0)*(((deltaH*TransferFuncCDM_EH(k)*growth_to_z0)) == 0.0 ? 0.0 : (deltaH*TransferFuncCDM_EH(k)*growth_to_z0)*(deltaH*TransferFuncCDM_EH(k)*growth_to_z0));
}

variable_types: k double


decompiled_code:
double __fastcall sig2tophat(double a1)
{
double v3; // [rsp+8h] [rbp-20h]
double v4; // [rsp+8h] [rbp-20h]
double v5; // [rsp+10h] [rbp-18h]

v3 = powerspcb(a1 / *(double *)&sig2_scale);
v4 = v3 * W2tophat(a1);
v5 = powerspcb(1.0 / a1 / *(double *)&sig2_scale);
return (W2tophat(1.0 / a1) * v5 + v4) / a1;
}

canonical_decompiled_code:
double __fastcall func5(double a1)
{
double v3; // [rsp+8h] [rbp-20h]
double v4; // [rsp+8h] [rbp-20h]
double v5; // [rsp+10h] [rbp-18h]

v3 = func4(a1 / *(double *)&sig2_scale);
v4 = v3 * func3(a1);
v5 = func4(1.0 / a1 / *(double *)&sig2_scale);
return (func3(1.0 / a1) * v5 + v4) / a1;
}

original_code:
double sig2tophat(double x, void * params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*W2tophat(x)+
      powerspcb(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

canonical_original_code:
double sig2tophat(double x, void *params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*W2tophat(x)+
      powerspcb(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

variable_types:
powerspcb
double (double k)


decompiled_code:
// attributes: thunk
double __fastcall sig2tophatnu(double a1)
{
return sig2tophat(a1);
}

canonical_decompiled_code:
double __fastcall func6(double a1)
{
return func5(a1);
}

original_code:
double sig2tophatnu(double x, void * params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*W2tophat(x)+
      powerspcbnu(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

canonical_original_code:
double sig2tophatnu(double x, void *params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*W2tophat(x)+
      powerspcbnu(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

variable_types:
powerspcbnu
double (double k)


decompiled_code:
double __fastcall sig2gauss(double a1)
{
double v3; // [rsp+10h] [rbp-18h]
double v4; // [rsp+10h] [rbp-18h]
double v5; // [rsp+18h] [rbp-10h]

v3 = powerspcb(a1 / *(double *)&sig2_scale);
v4 = v3 * exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC9) * a1);
v5 = powerspcb(1.0 / a1 / *(double *)&sig2_scale);
return (exp(-1.0 / a1 / a1) * v5 + v4) / a1;
}

canonical_decompiled_code:
double __fastcall func7(double a1)
{
double v3; // [rsp+10h] [rbp-18h]
double v4; // [rsp+10h] [rbp-18h]
double v5; // [rsp+18h] [rbp-10h]

v3 = func4(a1 / *(double *)&sig2_scale);
v4 = v3 * exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC9) * a1);
v5 = func4(1.0 / a1 / *(double *)&sig2_scale);
return (exp(-1.0 / a1 / a1) * v5 + v4) / a1;
}

original_code:
double sig2gauss(double x, void * params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*exp(-x*x)+
      powerspcb(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}

canonical_original_code:
double sig2gauss(double x, void *params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*exp(-x*x)+
      powerspcb(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}


decompiled_code:
// attributes: thunk
double __fastcall sig2gaussnu(double a1)
{
return sig2gauss(a1);
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
return func7(a1);
}

original_code:
double sig2gaussnu(double x, void * params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*exp(-x*x)+
      powerspcbnu(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}

canonical_original_code:
double sig2gaussnu(double x, void *params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*exp(-x*x)+
      powerspcbnu(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}


decompiled_code:
double __fastcall sig2sharpk(double a1)
{
return powerspcb(a1 / *(double *)&sig2_scale) / a1;
}

canonical_decompiled_code:
double __fastcall func9(double a1)
{
return func4(a1 / *(double *)&sig2_scale) / a1;
}

original_code:
double sig2sharpk(double x, void * params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale))/x;
}

canonical_original_code:
double sig2sharpk(double x, void *params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale))/x;
}


decompiled_code:
// attributes: thunk
double __fastcall sig2sharpknu(double a1)
{
return sig2sharpk(a1);
}

canonical_decompiled_code:
double __fastcall func10(double a1)
{
return func9(a1);
}

original_code:
double sig2sharpknu(double x, void * params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale))/x;
}

canonical_original_code:
double sig2sharpknu(double x, void *params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale))/x;
}


powerspcbnu

decompiled_code:
// attributes: thunk
double __fastcall powerspcbnu(double a1)
{
return powerspcb(a1);
}

canonical_decompiled_code:
double __fastcall func11(double a1)
{
return func4(a1);
}

original_code:
double powerspcbnu(double k)
{
    return pow(2997.0*k, tilt+3.0)*(((deltaH*TransferFuncCDM_EH(k)*growth_to_z0)) == 0.0 ? 0.0 : (deltaH*TransferFuncCDM_EH(k)*growth_to_z0)*(deltaH*TransferFuncCDM_EH(k)*growth_to_z0));
}


cobenorm

decompiled_code:
double cobenorm()
{
double v0; // xmm0_8
double v1; // xmm0_8
double result; // xmm0_8
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm2_8
double v8; // xmm0_8
double v9; // [rsp+8h] [rbp-20h]
double v10; // [rsp+8h] [rbp-20h]
double v11; // [rsp+8h] [rbp-20h]
double v12; // [rsp+8h] [rbp-20h]
double v13; // [rsp+8h] [rbp-20h]
double v14; // [rsp+10h] [rbp-18h]
double v15; // [rsp+10h] [rbp-18h]
double v16; // [rsp+10h] [rbp-18h]
double v17; // [rsp+10h] [rbp-18h]
double v18; // [rsp+10h] [rbp-18h]
double v19; // [rsp+18h] [rbp-10h]
double v20; // [rsp+18h] [rbp-10h]

if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(Omega_Matter + Omega_Lambda - 1.0) & LC24) >= 0.00001 )
{
if ( COERCE_DOUBLE(*(_QWORD *)&Omega_Lambda & LC24) >= 0.00001 )
{
v19 = exp(Omega_Matter);
v17 = exp(Omega_Lambda);
v12 = Omega_Matter;
v13 = 2.422 - v19 * 1.166 + v17 * 0.8 + 3.78 * v12 - v12 * 2.267 * exp(Omega_Lambda);
if ( Omega_Matter == 0.0 )
v20 = 0.0;
else
v20 = Omega_Matter * Omega_Matter * 0.487;
v18 = Omega_Lambda;
v7 = 0.0;
v8 = exp(Omega_Matter) * (v18 * 3.329)
+ v13
+ v20
+ 0.5610000000000001 * v18
- 8.568 * Omega_Matter * Omega_Lambda;
if ( Omega_Lambda != 0.0 )
v7 = Omega_Lambda * Omega_Lambda * 1.08;
result = (v8 + v7) * 0.00001;
}
else
{
v10 = tilt - 1.0;
if ( qtensors )
{
v6 = log(Omega_Matter);
v16 = v10;
v11 = pow(Omega_Matter, -0.35 - v6 * 0.19 - v10 * 0.15);
v4 = 1.7 * v16 * v16 + v16 * 1.02;
}
else
{
v3 = log(Omega_Matter);
v15 = v10;
v11 = pow(Omega_Matter, -0.35 - v3 * 0.19 - v10 * 0.17);
v4 = COERCE_DOUBLE(*(_QWORD *)&v15 ^ LC9) - v15 * (0.14 * v15);
}
result = v11 * 0.0000195 * exp(v4);
}
}
else
{
v14 = tilt - 1.0;
if ( qtensors )
{
v5 = log(Omega_Matter);
v9 = pow(Omega_Matter, -0.785 - v5 * 0.05);
v1 = 1.97 * v14 * v14 + v14;
}
else
{
v0 = log(Omega_Matter);
v9 = pow(Omega_Matter, -0.785 - v0 * 0.05);
v1 = -0.95 * v14 - v14 * (0.169 * v14);
}
result = v9 * 0.0000194 * exp(v1);
}
return result;
}

canonical_decompiled_code:
double func12()
{
double v0; // xmm0_8
double v1; // xmm0_8
double result; // xmm0_8
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm2_8
double v8; // xmm0_8
double v9; // [rsp+8h] [rbp-20h]
double v10; // [rsp+8h] [rbp-20h]
double v11; // [rsp+8h] [rbp-20h]
double v12; // [rsp+8h] [rbp-20h]
double v13; // [rsp+8h] [rbp-20h]
double v14; // [rsp+10h] [rbp-18h]
double v15; // [rsp+10h] [rbp-18h]
double v16; // [rsp+10h] [rbp-18h]
double v17; // [rsp+10h] [rbp-18h]
double v18; // [rsp+10h] [rbp-18h]
double v19; // [rsp+18h] [rbp-10h]
double v20; // [rsp+18h] [rbp-10h]

if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(Omega_Matter + Omega_Lambda - 1.0) & LC24) >= 0.00001 )
{
if ( COERCE_DOUBLE(*(_QWORD *)&Omega_Lambda & LC24) >= 0.00001 )
{
v19 = exp(Omega_Matter);
v17 = exp(Omega_Lambda);
v12 = Omega_Matter;
v13 = 2.422 - v19 * 1.166 + v17 * 0.8 + 3.78 * v12 - v12 * 2.267 * exp(Omega_Lambda);
if ( Omega_Matter == 0.0 )
v20 = 0.0;
else
v20 = Omega_Matter * Omega_Matter * 0.487;
v18 = Omega_Lambda;
v7 = 0.0;
v8 = exp(Omega_Matter) * (v18 * 3.329)
+ v13
+ v20
+ 0.5610000000000001 * v18
- 8.568 * Omega_Matter * Omega_Lambda;
if ( Omega_Lambda != 0.0 )
v7 = Omega_Lambda * Omega_Lambda * 1.08;
result = (v8 + v7) * 0.00001;
}
else
{
v10 = tilt - 1.0;
if ( qtensors )
{
v6 = log(Omega_Matter);
v16 = v10;
v11 = pow(Omega_Matter, -0.35 - v6 * 0.19 - v10 * 0.15);
v4 = 1.7 * v16 * v16 + v16 * 1.02;
}
else
{
v3 = log(Omega_Matter);
v15 = v10;
v11 = pow(Omega_Matter, -0.35 - v3 * 0.19 - v10 * 0.17);
v4 = COERCE_DOUBLE(*(_QWORD *)&v15 ^ LC9) - v15 * (0.14 * v15);
}
result = v11 * 0.0000195 * exp(v4);
}
}
else
{
v14 = tilt - 1.0;
if ( qtensors )
{
v5 = log(Omega_Matter);
v9 = pow(Omega_Matter, -0.785 - v5 * 0.05);
v1 = 1.97 * v14 * v14 + v14;
}
else
{
v0 = log(Omega_Matter);
v9 = pow(Omega_Matter, -0.785 - v0 * 0.05);
v1 = -0.95 * v14 - v14 * (0.169 * v14);
}
result = v9 * 0.0000194 * exp(v1);
}
return result;
}

original_code:
double cobenorm()
{
    double n;
    n = tilt-1;
    if (fabs(Omega_Matter+Omega_Lambda-1.0)<1e-5) {
 if (qtensors)
     return 1.94e-5*pow(Omega_Matter, -0.785-0.05*log(Omega_Matter))*
  exp(n+1.97*n*n);
 else return 1.94e-5*pow(Omega_Matter, -0.785-0.05*log(Omega_Matter))*
  exp(-0.95*n-0.169*n*n);
    } else if (fabs(Omega_Lambda)<1e-5) {
 if (qtensors)
     return 1.95e-5*pow(Omega_Matter,-0.35-0.19*log(Omega_Matter)-0.15*n)*
  exp(+1.02*n+1.7*n*n);
 else return 1.95e-5*pow(Omega_Matter, -0.35-0.19*log(Omega_Matter)-0.17*n)*
  exp(-n-0.14*n*n);
    } else return 1e-5*(2.422-1.166*exp(Omega_Matter)+0.800*exp(Omega_Lambda)
 +3.780*Omega_Matter-2.267*Omega_Matter*exp(Omega_Lambda)+0.487*(((Omega_Matter)) == 0.0 ? 0.0 : (Omega_Matter)*(Omega_Matter))+
 0.561*Omega_Lambda+3.329*Omega_Lambda*exp(Omega_Matter)-8.568*Omega_Matter*Omega_Lambda+
 1.080*(((Omega_Lambda)) == 0.0 ? 0.0 : (Omega_Lambda)*(Omega_Lambda)));
}

variable_types: n double


Sigma

decompiled_code:
double __fastcall Sigma(double a1)
{
__int64 v1; // rbp
double v2; // xmm0_8
__int64 v3; // xmm0_8
double result; // xmm0_8
char v6[8]; // [rsp+10h] [rbp-28h] BYREF
double x; // [rsp+18h] [rbp-20h] BYREF
double (__fastcall *v8[3])(double); // [rsp+20h] [rbp-18h] BYREF

v1 = gsl_integration_workspace_alloc(2000LL);
checking();
if ( (unsigned int)TransferFunc_Init(redshift) )
puts("Some warnings in Init");
v2 = cobenorm();
quiet = 1;
deltaH = *(_QWORD *)&v2;
v3 = scale;
if ( *(double *)&scale > 0.0 || a1 > 0.0 )
{
if ( a1 >= 0.0 && *(double *)&scale < 0.0 )
{
*(double *)&v3 = pow(8.587496929418813e-13 / Omega_Matter * a1, 0.3333333333333333);
scale = v3;
}
sig2_scale = v3;
if ( SigmaFilter == 0x7461682D706F74LL )
v8[0] = sig2tophat;
if ( SigmaFilter == 0x6E61697373756167LL && !*((_BYTE *)&SigmaFilter + 8) )
v8[0] = sig2gauss;
if ( SigmaFilter == 0x6B2D7072616873LL )
v8[0] = sig2sharpk;
gsl_integration_qags(v8, 2000LL, v1, &x, v6, 0.0, 1.0, 0.0, 0.00000001489999);
if ( x < 0.0 )
result = sqrt(x);
else
result = sqrt(x);
}
else
{
result = 0.0;
}
gsl_integration_workspace_free(v1);
return result;
}

canonical_decompiled_code:
double __fastcall func13(double a1)
{
__int64 v1; // rbp
double v2; // xmm0_8
__int64 v3; // xmm0_8
double result; // xmm0_8
char v6[8]; // [rsp+10h] [rbp-28h] BYREF
double x; // [rsp+18h] [rbp-20h] BYREF
double (__fastcall *v8[3])(double); // [rsp+20h] [rbp-18h] BYREF

v1 = gsl_integration_workspace_alloc(2000LL);
func2();
if ( (unsigned int)TransferFunc_Init(redshift) )
puts("Some warnings in Init");
v2 = func12();
quiet = 1;
deltaH = *(_QWORD *)&v2;
v3 = scale;
if ( *(double *)&scale > 0.0 || a1 > 0.0 )
{
if ( a1 >= 0.0 && *(double *)&scale < 0.0 )
{
*(double *)&v3 = pow(8.587496929418813e-13 / Omega_Matter * a1, 0.3333333333333333);
scale = v3;
}
sig2_scale = v3;
if ( SigmaFilter == 0x7461682D706F74LL )
v8[0] = sig2tophat;
if ( SigmaFilter == 0x6E61697373756167LL && !*((_BYTE *)&SigmaFilter + 8) )
v8[0] = sig2gauss;
if ( SigmaFilter == 0x6B2D7072616873LL )
v8[0] = sig2sharpk;
gsl_integration_qags(v8, 2000LL, v1, &x, v6, 0.0, 1.0, 0.0, 0.00000001489999);
if ( x < 0.0 )
result = sqrt(x);
else
result = sqrt(x);
}
else
{
result = 0.0;
}
gsl_integration_workspace_free(v1);
return result;
}

original_code:
double Sigma(double mass)
{
    double sigma = 0.0;
    double cobenorm();
    double epsabs=0.0, abserr, epsrel=1.489999e-08,sig2;
    int nbins = 2000;
 gsl_integration_workspace *w = gsl_integration_workspace_alloc (nbins);
    gsl_function F;
    checking();
  if(TransferFunc_Init(redshift)) printf("Some warnings in Init\n");
  deltaH = cobenorm();
quiet=1;
    if (!quiet) {
 printf("Omega_0  = %5.3f, Omega_baryon = %5.3f, Omega_neutrino = %5.3f\n",
  Omega_Matter, Omega_Baryon, Omega_Neutrino);
 printf("Hubble   = %5.3f, Lambda       = %5.3f, N_neutrinos    = %d\n",
  h_z0, Omega_Lambda, (int) degen_Neutrino);
 printf("Redshift = %5.3f, Growth = %6.4f relative to z=0\n",
  redshift, growth_to_z0);
 printf("Tilt     = %5.3f, COBE normalization: deltaH = %8.3e",
  tilt, deltaH);
 if (tilt!=1.0)
     if (qtensors) printf(" with tensors.\n");
     else printf(" without tensors.\n");
 else printf("\n");
    }
   if (scale>0 || mass>0) {
 if (mass<0)
     mass = 4.0*3.14159265358979323846/3.0*Omega_Matter*2.78e11*scale*scale*scale;
 else if (scale<0)
     scale = pow(3.0/4.0/3.14159265358979323846/2.78e11/Omega_Matter*mass, 1.0/3.0);
 sig2_scale = scale;
        if(strcmp(SigmaFilter,"top-hat")==0)
         F.function = &sig2tophat;
 if(strcmp(SigmaFilter,"gaussian")==0)
  F.function = &sig2gauss;
        if(strcmp(SigmaFilter,"sharp-k")==0)
         F.function = &sig2sharpk;
  gsl_integration_qags(&F,0.0,1.0,epsabs,epsrel,nbins,w,&sig2,&abserr);
 sigma = sqrt(sig2);
    }
 gsl_integration_workspace_free (w);
  return sigma;
}

canonical_original_code:
double Sigma(double mass)
{
    double sigma = 0.0;
    double cobenorm();
    double epsabs = 0.0; double abserr; double epsrel = 1.489999e-08; double sig2;
    int nbins = 2000;
 struct gsl_integration_workspace *w = gsl_integration_workspace_alloc (nbins);
    struct gsl_function_struct F;
    checking();
  if(TransferFunc_Init(redshift)) printf("Some warnings in Init\n");
  deltaH = cobenorm();
quiet=1;
    if (!quiet) {
 printf("Omega_0  = %5.3f, Omega_baryon = %5.3f, Omega_neutrino = %5.3f\n",
  Omega_Matter, Omega_Baryon, Omega_Neutrino);
 printf("Hubble   = %5.3f, Lambda       = %5.3f, N_neutrinos    = %d\n",
  h_z0, Omega_Lambda, (int) degen_Neutrino);
 printf("Redshift = %5.3f, Growth = %6.4f relative to z=0\n",
  redshift, growth_to_z0);
 printf("Tilt     = %5.3f, COBE normalization: deltaH = %8.3e",
  tilt, deltaH);
 if (tilt!=1.0)
     if (qtensors) printf(" with tensors.\n");
     else printf(" without tensors.\n");
 else printf("\n");
    }
   if (scale>0 || mass>0) {
 if (mass<0)
     mass = 4.0*3.14159265358979323846/3.0*Omega_Matter*2.78e11*scale*scale*scale;
 else if (scale<0)
     scale = pow(3.0/4.0/3.14159265358979323846/2.78e11/Omega_Matter*mass, 1.0/3.0);
 sig2_scale = scale;
        if(strcmp(SigmaFilter,"top-hat")==0)
         F.function = &sig2tophat;
 if(strcmp(SigmaFilter,"gaussian")==0)
  F.function = &sig2gauss;
        if(strcmp(SigmaFilter,"sharp-k")==0)
         F.function = &sig2sharpk;
  gsl_integration_qags(&F,0.0,1.0,epsabs,epsrel,nbins,w,&sig2,&abserr);
 sigma = sqrt(sig2);
    }
 gsl_integration_workspace_free (w);
  return sigma;
}

variable_types: sigma double

variable_types:
cobenorm
double ()

variable_types: epsabs double

variable_types: abserr double

variable_types: epsrel double

variable_types: nbins int

variable_types: struct gsl_integration_workspace { unsigned long limit; unsigned long size; unsigned long nrmax; unsigned long i; unsigned long maximum_level; double *alist; double *blist; double *rlist; double *elist; unsigned long *order; unsigned long *level; } *

variable_types: struct gsl_function_struct { double (*function)(double x, void *params); void *params; }


repo: ralferoo/cpctools

decompiled_code:
__int64 __fastcall TZX_InsertBlockAfter(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 result; // rax

result = *(_QWORD *)(a3 + 8);
*a2 = a3;
a2[1] = result;
*(_QWORD *)(a3 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 result; // rax

result = *(_QWORD *)(a3 + 8);
*a2 = a3;
a2[1] = result;
*(_QWORD *)(a3 + 8) = a2;
return result;
}

original_code:
void TZX_InsertBlockAfter(TZX_FILE *pFile,TZX_BLOCK *pBlock, TZX_BLOCK *pPrev)
{
 pBlock->pPrev = pPrev;
 pBlock->pNext = pPrev->pNext;
 pPrev->pNext = pBlock;
}

canonical_original_code:
void TZX_InsertBlockAfter(struct TZX_FILE *pFile, struct TZX_BLOCK *pBlock, struct TZX_BLOCK *pPrev)
{
 pBlock->pPrev = pPrev;
 pBlock->pNext = pPrev->pNext;
 pPrev->pNext = pBlock;
}

variable_types: struct TZX_FILE { unsigned char VersionMajor; unsigned char VersionMinor; struct TZX_BLOCK { struct TZX_BLOCK *pPrev; struct TZX_BLOCK *pNext; unsigned char *pBlockHeader; unsigned long DataBlockSize; unsigned char *pBlockData; } *pFirstBlock; } *

variable_types:
pBlock
struct TZX_BLOCK *

variable_types:
pPrev
struct TZX_BLOCK *

user_defined_types: struct TZX_FILE { unsigned char VersionMajor; unsigned char VersionMinor; struct TZX_BLOCK *pFirstBlock; }