decompiled_code:
__int64 __fastcall do_read(__int64 a1, __int64 a2, unsigned int a3)
{
return keyboard_read(a2, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3)
{
return keyboard_read(a2, a3, 0LL);
}

original_code:
int do_read(int fd, char *buf, int count)
{
 return keyboard_read(buf, count, 0);
}


repo: gurugio/gurugio

decompiled_code:
__int64 do_turnoff()
{
del_task(1LL);
del_task(2LL);
stop_scheduler();
_disable();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
del_task(1LL);
del_task(2LL);
stop_scheduler();
_disable();
return 0LL;
}

original_code:
int do_turnoff(void)
{
 del_task(1);
 del_task(2);
 stop_scheduler();
 __asm__ __volatile__("cli":::"memory");
 return 0;
}

canonical_original_code:
int do_turnoff()
{
 del_task(1);
 del_task(2);
 stop_scheduler();
 __asm__ __volatile__("cli":::"memory");
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall do_open(__int64 a1)
{
if ( !(unsigned int)caos_strcmp(a1, "keyboard") )
return keyboard_open(a1);
caos_printf("do_open - Unknown name: %x\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !(unsigned int)caos_strcmp(a1, "keyboard") )
return keyboard_open(a1);
caos_printf("do_open - Unknown name: %x\n", a1);
return 0LL;
}

original_code:
int do_open(const char *name, int flag)
{
 if (caos_strcmp(name, "keyboard") == 0) {
  return keyboard_open(name);
 } else {
  caos_printf("do_open - Unknown name: %x\n", name);
 }
 return 0;
}

canonical_original_code:
int do_open(char *name, int flag)
{
 if (caos_strcmp(name, "keyboard") == 0) {
  return keyboard_open(name);
 } else {
  caos_printf("do_open - Unknown name: %x\n", name);
 }
 return 0;
}

variable_types:
name
char *

variable_types: flag int


decompiled_code:
__int64 __fastcall do_close(unsigned int a1)
{
if ( !a1 )
return keyboard_close("keyboard");
caos_printf("do_close - Unknown fd: %d\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
if ( !a1 )
return keyboard_close("keyboard");
caos_printf("do_close - Unknown fd: %d\n", a1);
return 0LL;
}

original_code:
int do_close(int fd)
{
 if ( fd == 0) {
  return keyboard_close("keyboard");
 } else {
  caos_printf("do_close - Unknown fd: %d\n", fd);
 }
 return 0;
}

variable_types: fd int


decompiled_code:
char *say_hello()
{
return hello_0;
}

canonical_decompiled_code:
char *func7()
{
return hello_0;
}

original_code:
char *say_hello(void)
{
    static char hello[] = "hello!";
    return hello;
}

canonical_original_code:
char *say_hello()
{
    static char hello[] = "hello!";
    return hello;
}

variable_types:
hello
char []

return_type: char *


decompiled_code:
void __fastcall __noreturn start_kernel(__int64 a1, __int64 a2)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v2, "C FUNCTION START!");
init_screen(a1, a2, 0x5452415453204E4FLL);
caos_printf(&unk_1AC, v2);
setup_memory();
init_idt();
set_idtr();
init_char_dev();
keyboard_init();
init_timer();
init_scheduler();
setup_task();
init_cpu_tss();
start_scheduler();
if ( (int)create_task(&init, "init") < 0 )
caos_printf("Create Init fail..\n", "init");
if ( (int)create_task(&user1, "user1") < 0 )
caos_printf("Create user1 fail..\n", "user1");
if ( (int)create_task(&user2, "user2") < 0 )
caos_printf("Create user2 fail..\n", "user2");
caos_printf("CaOS KERNEL END!!\n", "user2");
start_init();
while ( 1 )
;
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int64 a1, __int64 a2)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v2, "C FUNCTION START!");
init_screen(a1, a2, 0x5452415453204E4FLL);
caos_printf(&unk_1AC, v2);
setup_memory();
init_idt();
set_idtr();
init_char_dev();
keyboard_init();
init_timer();
init_scheduler();
setup_task();
init_cpu_tss();
start_scheduler();
if ( (int)create_task(&init, "init") < 0 )
caos_printf("Create Init fail..\n", "init");
if ( (int)create_task(&user1, "user1") < 0 )
caos_printf("Create user1 fail..\n", "user1");
if ( (int)create_task(&user2, "user2") < 0 )
caos_printf("Create user2 fail..\n", "user2");
caos_printf("CaOS KERNEL END!!\n", "user2");
start_init();
while ( 1 )
;
}

original_code:
void start_kernel(void)
{
 char str[] = "C FUNCTION START!";
 init_screen();
 caos_printf("%s\n", str);
 setup_memory();
 init_idt();
 set_idtr();
 init_char_dev();
 keyboard_init();
 init_timer();
 init_scheduler();
 setup_task();
 init_cpu_tss();
 start_scheduler();
 if (create_task(init, "init") < 0)
  caos_printf("Create Init fail..\n");
 if (create_task(user1, "user1") < 0)
  caos_printf("Create user1 fail..\n");
 if (create_task(user2, "user2") < 0)
  caos_printf("Create user2 fail..\n");
 caos_printf("CaOS KERNEL END!!\n");
 start_init();
 while (1);
}

canonical_original_code:
void start_kernel()
{
 char str[] = "C FUNCTION START!";
 init_screen();
 caos_printf("%s\n", str);
 setup_memory();
 init_idt();
 set_idtr();
 init_char_dev();
 keyboard_init();
 init_timer();
 init_scheduler();
 setup_task();
 init_cpu_tss();
 start_scheduler();
 if (create_task(init, "init") < 0)
  caos_printf("Create Init fail..\n");
 if (create_task(user1, "user1") < 0)
  caos_printf("Create user1 fail..\n");
 if (create_task(user2, "user2") < 0)
  caos_printf("Create user2 fail..\n");
 caos_printf("CaOS KERNEL END!!\n");
 start_init();
 while (1);
}

variable_types:
str
char []

return_type: void


decompiled_code:
int test_mtrace()
{
return printf("HERE! %s:%d\n", "test_mtrace", 8LL);
}

canonical_decompiled_code:
int func7()
{
return printf("HERE! %s:%d\n", "test_mtrace", 8LL);
}

original_code:
void test_mtrace(void)
{
    printf("HERE! %s:%d\n", __func__, 8);
    malloc(10);
}

canonical_original_code:
void test_mtrace()
{
    printf("HERE! %s:%d\n", __func__, 8);
    malloc(10);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
mtrace();
printf("HERE! %s:%d\n", "main", 18LL);
test_mtrace();
muntrace();
puts("set environment variable \"MALLOC_TRACE\"");
puts("and executes \"mtrace mem_hook $MALLOC_TRACE\"");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
mtrace();
printf("HERE! %s:%d\n", "main", 18LL);
func7();
muntrace();
puts("set environment variable \"MALLOC_TRACE\"");
puts("and executes \"mtrace mem_hook $MALLOC_TRACE\"");
return 0;
}

original_code:
int main(void)
{
    mtrace();
    void *p = malloc(10);
    printf("HERE! %s:%d\n", __func__, 18);
    malloc(20);
    free(p);
    test_mtrace();
    muntrace();
    printf("set environment variable \"MALLOC_TRACE\"\n");
    printf("and executes \"mtrace mem_hook $MALLOC_TRACE\"\n");
    return 0;
}

canonical_original_code:
int main()
{
    mtrace();
    void *p = malloc(10);
    printf("HERE! %s:%d\n", __func__, 18);
    malloc(20);
    free(p);
    test_mtrace();
    muntrace();
    printf("set environment variable \"MALLOC_TRACE\"\n");
    printf("and executes \"mtrace mem_hook $MALLOC_TRACE\"\n");
    return 0;
}

variable_types:
p
void *


variable_types:
bp
char *

variable_types:
flow
char [4]

variable_types:
time
unsigned int


inb

decompiled_code:
unsigned __int8 __fastcall inb(unsigned __int16 a1)
{
return __inbyte(a1);
}

canonical_decompiled_code:
unsigned __int8 __fastcall func0(unsigned __int16 a1)
{
return __inbyte(a1);
}

original_code:
unsigned char inb(unsigned short port)
{
 unsigned char _v;
 __asm__ __volatile__ ("inb %w1, %0":"=a" (_v):"Nd" (port));
 return _v;
}

variable_types:
port
unsigned short

return_type: unsigned char


inw

decompiled_code:
unsigned __int16 __fastcall inw(unsigned __int16 a1)
{
return __inword(a1);
}

canonical_decompiled_code:
unsigned __int16 __fastcall func1(unsigned __int16 a1)
{
return __inword(a1);
}

original_code:
unsigned short inw(unsigned short port)
{
 unsigned short _v;
 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd"(port));
 return _v;
}

return_type: unsigned short


outb

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

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

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

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

original_code:
void outb(unsigned short port, unsigned char value)
{
 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd"(port));
}

variable_types:
value
unsigned char


outw

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

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

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

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

original_code:
void outw(unsigned short port, unsigned short value)
{
 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd"(port));
}

variable_types:
value
unsigned short


decompiled_code:
const char *sys_info_cpu_type()
{
return "x86_64";
}

canonical_decompiled_code:
const char *func7()
{
return "x86_64";
}

original_code:
char *sys_info_cpu_type(void)
{
    return "x86_64";
}


decompiled_code:
const char *sys_info_os_type()
{
return "linux-gnu";
}

canonical_decompiled_code:
const char *func8()
{
return "linux-gnu";
}

original_code:
char *sys_info_os_type(void)
{
    return "linux-gnu";
}


init

decompiled_code:
void __fastcall __noreturn init(__int64 a1, __int64 a2, umode_t a3)
{
int v3; // eax
unsigned int v4; // er13
int v5; // er12
int v6; // ebx
__int64 v7; // rbp
char v8; // si
char v9[32]; // [rsp+0h] [rbp-68h] BYREF
char v10[72]; // [rsp+20h] [rbp-48h]

v3 = sys_open("keyboard", 0, a3);
if ( v3 < 0 )
{
sys_cputstr("open keyboard fail\n");
while ( 1 )
;
}
v4 = v3;
sys_cputstr("SHELL START..\n");
sys_cputstr("Type help for command list\n");
while ( 1 )
{
sys_cputstr("CaOS # ");
v5 = 0;
do
LABEL_11:
v6 = sys_read(v4, v9, 0x1FuLL);
while ( v6 <= 0 );
v7 = 0LL;
while ( 1 )
{
v8 = v9[v7];
v10[v5] = v8;
if ( v8 == 10 )
break;
if ( v8 == 8 )
{
if ( v5 > 0 )
{
v10[v5--] = 0;
v10[v5] = 0;
sys_cputstr("\b");
}
}
else
{
sys_cprintf("%c", v8);
++v5;
}
if ( v6 <= (int)++v7 )
goto LABEL_11;
}
sys_cprintf("%c", 10LL);
v10[v5] = 0;
switch ( v10[0] )
{
case 'h':
sys_cputstr("s : system info\n");
sys_cputstr("i : CaOS info\n");
sys_cputstr("x : exit\n");
break;
case 's':
sys_system_info();
break;
case 'i':
sys_cputstr("CaOS v0.05 IA-32 i386\n");
break;
case 'x':
sys_turnoff();
sys_cputstr("TURN OFF PC..\n");
while ( 1 )
;
default:
sys_cputstr("Unknown command\n");
break;
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int64 a1, __int64 a2, umode_t a3)
{
int v3; // eax
unsigned int v4; // er13
int v5; // er12
int v6; // ebx
__int64 v7; // rbp
char v8; // si
char v9[32]; // [rsp+0h] [rbp-68h] BYREF
char v10[72]; // [rsp+20h] [rbp-48h]

v3 = sys_open("keyboard", 0, a3);
if ( v3 < 0 )
{
sys_cputstr("open keyboard fail\n");
while ( 1 )
;
}
v4 = v3;
sys_cputstr("SHELL START..\n");
sys_cputstr("Type help for command list\n");
while ( 1 )
{
sys_cputstr("CaOS # ");
v5 = 0;
do
LABEL_11:
v6 = sys_read(v4, v9, 0x1FuLL);
while ( v6 <= 0 );
v7 = 0LL;
while ( 1 )
{
v8 = v9[v7];
v10[v5] = v8;
if ( v8 == 10 )
break;
if ( v8 == 8 )
{
if ( v5 > 0 )
{
v10[v5--] = 0;
v10[v5] = 0;
sys_cputstr("\b");
}
}
else
{
sys_cprintf("%c", v8);
++v5;
}
if ( v6 <= (int)++v7 )
goto LABEL_11;
}
sys_cprintf("%c", 10LL);
v10[v5] = 0;
switch ( v10[0] )
{
case 'h':
sys_cputstr("s : system info\n");
sys_cputstr("i : CaOS info\n");
sys_cputstr("x : exit\n");
break;
case 's':
sys_system_info();
break;
case 'i':
sys_cputstr("CaOS v0.05 IA-32 i386\n");
break;
case 'x':
sys_turnoff();
sys_cputstr("TURN OFF PC..\n");
while ( 1 )
;
default:
sys_cputstr("Unknown command\n");
break;
}
}
}

original_code:
void init(void)
{
 int i, l;
 char buf[32];
 char temp[32];
 int ret;
 int keybd_dev;
 if ( (keybd_dev = sys_open("keyboard", 0)) < 0) {
  sys_cputstr("open keyboard fail\n");
  while(1);
 }
 sys_cputstr("SHELL START..\n");
 sys_cputstr("Type help for command list\n");
 while(1) {
  sys_cputstr("CaOS # ");
  while (1) {
   if ( (ret = sys_read(keybd_dev, temp, 31)) > 0) {
    for (l=0; l<ret; l++) {
     buf[i] = temp[l];
     if (buf[i] == '\n') {
      sys_cprintf("%c", buf[i]);
      goto next_line;
     } else if (buf[i] == '\b') {
      if (i >= 1) {
       buf[i] = 0;
       buf[i-1] = 0;
       i--;
       sys_cputstr("\b");
      }
      continue;
     }
     sys_cprintf("%c", buf[i]);
     i++;
    }
   }
  }
next_line:
  buf[i] = 0;
  i=0;
  if (buf[0] == 'h') {
   sys_cputstr("s : system info\n");
   sys_cputstr("i : CaOS info\n");
   sys_cputstr("x : exit\n");
  } else if (buf[0] == 's') {
   sys_system_info();
  } else if (buf[0] == 'i') {
   sys_cputstr("CaOS v0.05 IA-32 i386\n");
  } else if (buf[0] == 'x') {
   sys_turnoff();
   sys_cputstr("TURN OFF PC..\n");
   while (1);
  } else {
   sys_cputstr("Unknown command\n");
  }
 }
 return;
}

canonical_original_code:
void init()
{
 int i; int l;
 char buf[32];
 char temp[32];
 int ret;
 int keybd_dev;
 if ( (keybd_dev = sys_open("keyboard", 0)) < 0) {
  sys_cputstr("open keyboard fail\n");
  while(1);
 }
 sys_cputstr("SHELL START..\n");
 sys_cputstr("Type help for command list\n");
 while(1) {
  sys_cputstr("CaOS # ");
  while (1) {
   if ( (ret = sys_read(keybd_dev, temp, 31)) > 0) {
    for (l=0; l<ret; l++) {
     buf[i] = temp[l];
     if (buf[i] == '\n') {
      sys_cprintf("%c", buf[i]);
      goto next_line;
     } else if (buf[i] == '\b') {
      if (i >= 1) {
       buf[i] = 0;
       buf[i-1] = 0;
       i--;
       sys_cputstr("\b");
      }
      continue;
     }
     sys_cprintf("%c", buf[i]);
     i++;
    }
   }
  }
next_line:
  buf[i] = 0;
  i=0;
  if (buf[0] == 'h') {
   sys_cputstr("s : system info\n");
   sys_cputstr("i : CaOS info\n");
   sys_cputstr("x : exit\n");
  } else if (buf[0] == 's') {
   sys_system_info();
  } else if (buf[0] == 'i') {
   sys_cputstr("CaOS v0.05 IA-32 i386\n");
  } else if (buf[0] == 'x') {
   sys_turnoff();
   sys_cputstr("TURN OFF PC..\n");
   while (1);
  } else {
   sys_cputstr("Unknown command\n");
  }
 }
 return;
}

variable_types: i int

variable_types: l int

variable_types:
buf
char [32]

variable_types:
temp
char [32]

variable_types: ret int


decompiled_code:
void free_myname()
{
printf("FREE <%s>\n", (const char *)myname);
free(myname);
myname = 0LL;
}

canonical_decompiled_code:
void func7()
{
printf("FREE <%s>\n", (const char *)myname);
free(myname);
myname = 0LL;
}

original_code:
static void free_myname(void)
{
    printf("FREE <%s>\n", myname);
    free(myname);
    myname = ((void *)0);
}

canonical_original_code:
static void free_myname()
{
    printf("FREE <%s>\n", myname);
    free(myname);
    myname = ((void *)0);
}


decompiled_code:
void *run_cleanup()
{
printf("__start_cleanup_fns->%p\n", &_start_cleanup_fns);
printf("__stop_cleanup_fns->%p\n", &_start_cleanup_fns);
return &_start_cleanup_fns;
}

canonical_decompiled_code:
void *func8()
{
printf("__start_cleanup_fns->%p\n", &_start_cleanup_fns);
printf("__stop_cleanup_fns->%p\n", &_start_cleanup_fns);
return &_start_cleanup_fns;
}

original_code:
void run_cleanup(void)
{
    void (*const *f)(void) = &__start_cleanup_fns;
    printf("__start_cleanup_fns->%p\n", &__start_cleanup_fns);
    printf("__stop_cleanup_fns->%p\n", &__stop_cleanup_fns);
    while (f < &__stop_cleanup_fns)
    {
        printf("f->%p\n", f);
        (*f++)();
    }
}

canonical_original_code:
void run_cleanup()
{
    void (**f)() = &__start_cleanup_fns;
    printf("__start_cleanup_fns->%p\n", &__start_cleanup_fns);
    printf("__stop_cleanup_fns->%p\n", &__stop_cleanup_fns);
    while (f < &__stop_cleanup_fns)
    {
        printf("f->%p\n", f);
        (*f++)();
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
myname = malloc(0x64uLL);
strcpy((char *)myname, "blabla");
printf("fn_free_myname->%p\n", free_myname);
run_cleanup();
puts("PROGRAM ENDS");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
myname = malloc(0x64uLL);
strcpy((char *)myname, "blabla");
printf("fn_free_myname->%p\n", free_myname);
func8();
puts("PROGRAM ENDS");
return 0;
}

original_code:
int main(void)
{
    myname = malloc(100);
    strncpy(myname, "blabla", 6);
    myname[6] = '\0';
    printf("fn_free_myname->%p\n", fn_free_myname);
    run_cleanup();
    printf("PROGRAM ENDS\n");
    return 0;
}

canonical_original_code:
int main()
{
    myname = malloc(100);
    strncpy(myname, "blabla", 6);
    myname[6] = '\0';
    printf("fn_free_myname->%p\n", fn_free_myname);
    run_cleanup();
    printf("PROGRAM ENDS\n");
    return 0;
}


SipConfNodeNew

repo: gurvindersingh/sipade

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

result = calloc(1uLL, 0x40uLL);
if ( !result )
{
SipLog(3LL, "util-conf.c", 45LL, "Error allocating memory for new configuration node");
exit(1);
}
result[5] = 1;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = result + 8;
return result;
}

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

result = calloc(1uLL, 0x40uLL);
if ( !result )
{
SipLog(3LL, "util-conf.c", 45LL, "Error allocating memory for new configuration node");
exit(1);
}
result[5] = 1;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = result + 8;
return result;
}

original_code:
SipConfNode *SipConfNodeNew(void)
{
    SipConfNode *new;
    new = calloc(1, sizeof(*new));
    if (new == ((void *)0)) {
        SipLog(3, "util-conf.c",45, "Error allocating "
                "memory for new configuration node");
        exit(1);
    }
    new->allow_override = 1;
    do { (&new->head)->tqh_first = ((void *)0); (&new->head)->tqh_last = &(&new->head)->tqh_first; } while (0);
    return new;
}

canonical_original_code:
struct SipConfNode_ *SipConfNodeNew()
{
    struct SipConfNode_ *new;
    new = calloc(1, sizeof(*new));
    if (new == ((void *)0)) {
        SipLog(3, "util-conf.c",45, "Error allocating "
                "memory for new configuration node");
        exit(1);
    }
    new->allow_override = 1;
    do { (&new->head)->tqh_first = ((void *)0); (&new->head)->tqh_last = &(&new->head)->tqh_first; } while (0);
    return new;
}

variable_types: struct SipConfNode_ { char *name; char *val; int is_seq; int allow_override; struct SipConfNode_ *parent; struct { struct SipConfNode_ *tqh_first; struct SipConfNode_ **tqh_last; } head; struct { struct SipConfNode_ *tqe_next; struct SipConfNode_ **tqe_prev; } next; } *


SipConfNodeLookupChild

decompiled_code:
__int64 __fastcall SipConfNodeLookupChild(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 32); i; i = *(_QWORD *)(i + 48) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

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

for ( i = *(_QWORD *)(a1 + 32); i; i = *(_QWORD *)(i + 48) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

original_code:
SipConfNode *SipConfNodeLookupChild(SipConfNode *node, const char *name)
{
    SipConfNode *child;
    for((child) = ((&node->head)->tqh_first); (child) != ((void *)0); (child) = ((child)->next.tqe_next)) {
        if (strcmp(child->name, name) == 0)
            return child;
    }
    return ((void *)0);
}

canonical_original_code:
struct SipConfNode_ *SipConfNodeLookupChild(struct SipConfNode_ *node, char *name)
{
    struct SipConfNode_ *child;
    for((child) = ((&node->head)->tqh_first); (child) != ((void *)0); (child) = ((child)->next.tqe_next)) {
        if (strcmp(child->name, name) == 0)
            return child;
    }
    return ((void *)0);
}

variable_types:
node
struct SipConfNode_ *

variable_types:
name
char *

return_type: struct SipConfNode_ { char *name; char *val; int is_seq; int allow_override; struct SipConfNode_ *parent; struct { struct SipConfNode_ *tqh_first; struct SipConfNode_ **tqh_last; } head; struct { struct SipConfNode_ *tqe_next; struct SipConfNode_ **tqe_prev; } next; } *


SipConfGetRootNode

decompiled_code:
__int64 SipConfGetRootNode()
{
return root;
}

canonical_decompiled_code:
__int64 func3()
{
return root;
}

original_code:
SipConfNode *SipConfGetRootNode(void)
{
    return root;
}

canonical_original_code:
struct SipConfNode_ *SipConfGetRootNode()
{
    return root;
}

user_defined_types: struct SipConfNode_ { char *name; char *val; int is_seq; int allow_override; struct SipConfNode_ *parent; struct { struct SipConfNode_ *tqh_first; struct SipConfNode_ **tqh_last; } head; struct { struct SipConfNode_ *tqe_next; struct SipConfNode_ **tqe_prev; } next; }


SipConfGetNode

decompiled_code:
__int64 __fastcall SipConfGetNode(const char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
char *v3; // rsi
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = root;
save_ptr[0] = 0LL;
v2 = strdup(a1);
v3 = strtok_r(v2, ".", save_ptr);
do
{
v1 = SipConfNodeLookupChild(v1, v3);
if ( !v1 )
break;
v3 = strtok_r(0LL, ".", save_ptr);
}
while ( v3 );
free(v2);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
char *v3; // rsi
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = root;
save_ptr[0] = 0LL;
v2 = strdup(a1);
v3 = strtok_r(v2, ".", save_ptr);
do
{
v1 = func1(v1, v3);
if ( !v1 )
break;
v3 = strtok_r(0LL, ".", save_ptr);
}
while ( v3 );
free(v2);
return v1;
}

original_code:
SipConfNode *SipConfGetNode(char *key)
{
    SipConfNode *node = root;
    char *saveptr = ((void *)0);
    char *token;
    char *tokstr = strdup(key);
    token = strtok_r(tokstr, ".", &saveptr);
    for (;;) {
        node = SipConfNodeLookupChild(node, token);
        if (node == ((void *)0))
            break;
        token = strtok_r(((void *)0), ".", &saveptr);
        if (token == ((void *)0))
            break;
    }
    free(tokstr);
    return node;
}

canonical_original_code:
struct SipConfNode_ *SipConfGetNode(char *key)
{
    struct SipConfNode_ *node = root;
    char *saveptr = ((void *)0);
    char *token;
    char *tokstr = strdup(key);
    token = strtok_r(tokstr, ".", &saveptr);
    for (;;) {
        node = SipConfNodeLookupChild(node, token);
        if (node == ((void *)0))
            break;
        token = strtok_r(((void *)0), ".", &saveptr);
        if (token == ((void *)0))
            break;
    }
    free(tokstr);
    return node;
}

variable_types:
key
char *

variable_types:
saveptr
char *

variable_types:
token
char *

variable_types:
tokstr
char *


SipConfGet

decompiled_code:
__int64 __fastcall SipConfGet(const char *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = SipConfGetNode(a1);
if ( v2 )
{
*a2 = *(_QWORD *)(v2 + 8);
result = 1LL;
}
else
{
SipLog(1LL, "util-conf.c", 163LL, "failed to lookup configuration parameter '%s'", a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = func4(a1);
if ( v2 )
{
*a2 = *(_QWORD *)(v2 + 8);
result = 1LL;
}
else
{
SipLog(1LL, "util-conf.c", 163LL, "failed to lookup configuration parameter '%s'", a1);
result = 0LL;
}
return result;
}

original_code:
int SipConfGet(char *name, char **vptr)
{
    SipConfNode *node = SipConfGetNode(name);
    if (node == ((void *)0)) {
        SipLog(1, "util-conf.c",163, "failed to lookup "
                "configuration parameter '%s'", name);
        return 0;
    }
    else {
        *vptr = node->val;
        return 1;
    }
}

canonical_original_code:
int SipConfGet(char *name, char **vptr)
{
    struct SipConfNode_ *node = SipConfGetNode(name);
    if (node == ((void *)0)) {
        SipLog(1, "util-conf.c",163, "failed to lookup "
                "configuration parameter '%s'", name);
        return 0;
    }
    else {
        *vptr = node->val;
        return 1;
    }
}

variable_types:
vptr
char **


SipConfNodeFree

original_code:
void SipConfNodeFree(SipConfNode *node)
{
    SipConfNode *tmp;
    while ((tmp = ((&node->head)->tqh_first))) {
        do { if (((tmp)->next.tqe_next) != ((void *)0)) (tmp)->next.tqe_next->next.tqe_prev = (tmp)->next.tqe_prev; else (&node->head)->tqh_last = (tmp)->next.tqe_prev; *(tmp)->next.tqe_prev = (tmp)->next.tqe_next; ; ; } while (0);
        SipConfNodeFree(tmp);
    }
    if (node->name != ((void *)0))
        free(node->name);
    if (node->val != ((void *)0))
        free(node->val);
    free(node);
}

canonical_original_code:
void SipConfNodeFree(struct SipConfNode_ *node)
{
    struct SipConfNode_ *tmp;
    while ((tmp = ((&node->head)->tqh_first))) {
        do { if (((tmp)->next.tqe_next) != ((void *)0)) (tmp)->next.tqe_next->next.tqe_prev = (tmp)->next.tqe_prev; else (&node->head)->tqh_last = (tmp)->next.tqe_prev; *(tmp)->next.tqe_prev = (tmp)->next.tqe_next; ; ; } while (0);
        SipConfNodeFree(tmp);
    }
    if (node->name != ((void *)0))
        free(node->name);
    if (node->val != ((void *)0))
        free(node->val);
    free(node);
}


SipConfDeInit

decompiled_code:
__int64 SipConfDeInit()
{
if ( root )
SipConfNodeFree(root);
return SipLog(2LL, "util-conf.c", 202LL, "Configuration module has been de-initialized");
}

canonical_decompiled_code:
__int64 func7()
{
if ( root )
func6(root);
return SipLog(2LL, "util-conf.c", 202LL, "Configuration module has been de-initialized");
}

original_code:
void SipConfDeInit(void)
{
    if (root != ((void *)0))
        SipConfNodeFree(root);
    SipLog(2, "util-conf.c",202, "Configuration module"
            " has been de-initialized");
}

canonical_original_code:
void SipConfDeInit()
{
    if (root != ((void *)0))
        SipConfNodeFree(root);
    SipLog(2, "util-conf.c",202, "Configuration module"
            " has been de-initialized");
}


SipConfInit

decompiled_code:
__int64 __fastcall SipConfInit(char *filename)
{
__int64 result; // rax

if ( root )
{
SipLog(1LL, "util-conf.c", 64LL, "already initialized");
result = 0LL;
}
else
{
root = (__int64)SipConfNodeNew();
if ( !root )
{
SipLog(3LL, "util-conf.c", 69LL, "ERROR: Failed to allocate memory for root configuration node, aborting.");
exit(1);
}
SipLog(1LL, "util-conf.c", 73LL, "configuration module initialized");
result = (unsigned int)-((unsigned int)SipConfYamlLoadFile(filename) != 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *filename)
{
__int64 result; // rax

if ( root )
{
SipLog(1LL, "util-conf.c", 64LL, "already initialized");
result = 0LL;
}
else
{
root = (__int64)func0();
if ( !root )
{
SipLog(3LL, "util-conf.c", 69LL, "ERROR: Failed to allocate memory for root configuration node, aborting.");
exit(1);
}
SipLog(1LL, "util-conf.c", 73LL, "configuration module initialized");
result = (unsigned int)-((unsigned int)func8(filename) != 0);
}
return result;
}

original_code:
int SipConfInit(const char *conf_filename)
{
    if (root != ((void *)0)) {
        SipLog(1, "util-conf.c",64, "already initialized");
        return 0;
    }
    root = SipConfNodeNew();
    if (root == ((void *)0)) {
        SipLog(3, "util-conf.c",69, "ERROR: Failed to allocate"
                " memory for root configuration node, aborting.");
        exit(1);
    }
    SipLog(1, "util-conf.c",73, "configuration module"
            " initialized");
    if (SipConfYamlLoadFile(conf_filename) != 0)
        return -1;
    return 0;
}

canonical_original_code:
int SipConfInit(char *conf_filename)
{
    if (root != ((void *)0)) {
        SipLog(1, "util-conf.c",64, "already initialized");
        return 0;
    }
    root = SipConfNodeNew();
    if (root == ((void *)0)) {
        SipLog(3, "util-conf.c",69, "ERROR: Failed to allocate"
                " memory for root configuration node, aborting.");
        exit(1);
    }
    SipLog(1, "util-conf.c",73, "configuration module"
            " initialized");
    if (SipConfYamlLoadFile(conf_filename) != 0)
        return -1;
    return 0;
}


SipDone

decompiled_code:
void __noreturn SipDone()
{
SipLog(2LL, "sipade.c", 54LL, "Shuting down the engine....");
PQfinish(*(_QWORD *)&conn);
if ( result )
PQclear();
SipConfDeInit();
SipDeinitAnomalyDetection();
SipAlertDeInitCtx();
SipLog(2LL, "sipade.c", 61LL, "Engine down, Bye !!");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
SipLog(2LL, "sipade.c", 54LL, "Shuting down the engine....");
PQfinish(*(_QWORD *)&conn);
if ( result )
PQclear();
SipConfDeInit();
SipDeinitAnomalyDetection();
SipAlertDeInitCtx();
SipLog(2LL, "sipade.c", 61LL, "Engine down, Bye !!");
exit(0);
}

original_code:
void SipDone()
{
    SipLog(2, "sipade.c",54, "Shuting down the "
            "engine....");
    PQfinish(conn);
    if (result != ((void *)0)) PQclear(result);
    SipConfDeInit();
    SipDeinitAnomalyDetection();
    SipAlertDeInitCtx();
    SipLog(2, "sipade.c",61, "Engine down, Bye !!");
    exit(0);
}


SipInitConf

decompiled_code:
char SipInitConf()
{
int v0; // eax
const void *v2; // [rsp+8h] [rbp-20h] BYREF
char *v3; // [rsp+10h] [rbp-18h] BYREF
char *nptr; // [rsp+18h] [rbp-10h] BYREF

nptr = 0LL;
v3 = 0LL;
v2 = 0LL;
if ( (unsigned int)SipConfGet("training-period", &nptr) == 1 )
train_period = strtoul(nptr, 0LL, 10);
else
train_period = 10080LL;
if ( (unsigned int)SipConfGet("ad-algo.interval", &v3) == 1 )
interval = strtoul(v3, 0LL, 10);
else
interval = 10;
v0 = SipConfGet("run-mode", &v2);
if ( v0 == 1 )
{
LOBYTE(v0) = (memcmp(v2, "online", 6uLL) == 0) + 1;
run_mode = v0;
}
else
{
run_mode = 1;
}
return v0;
}

canonical_decompiled_code:
char func1()
{
int v0; // eax
const void *v2; // [rsp+8h] [rbp-20h] BYREF
char *v3; // [rsp+10h] [rbp-18h] BYREF
char *nptr; // [rsp+18h] [rbp-10h] BYREF

nptr = 0LL;
v3 = 0LL;
v2 = 0LL;
if ( (unsigned int)SipConfGet("training-period", &nptr) == 1 )
train_period = strtoul(nptr, 0LL, 10);
else
train_period = 10080LL;
if ( (unsigned int)SipConfGet("ad-algo.interval", &v3) == 1 )
interval = strtoul(v3, 0LL, 10);
else
interval = 10;
v0 = SipConfGet("run-mode", &v2);
if ( v0 == 1 )
{
LOBYTE(v0) = (memcmp(v2, "online", 6uLL) == 0) + 1;
run_mode = v0;
}
else
{
run_mode = 1;
}
return v0;
}

original_code:
void SipInitConf()
{
    char *tr_period = ((void *)0);
    char *interval_s = ((void *)0);
    char *run_mode_s = ((void *)0);
    if (SipConfGet("training-period", &tr_period) == 1) {
        train_period = strtoul(tr_period, ((void *)0), 10);
    } else {
        train_period = 10080;
    }
    if (SipConfGet("ad-algo.interval", &interval_s) == 1) {
        interval = strtoul(interval_s, ((void *)0), 10);
    } else {
        interval = 10;
    }
    if (SipConfGet("run-mode", &run_mode_s) == 1) {
        if (strncmp(run_mode_s, "online", 6) == 0) {
            run_mode = 0x02;
        } else {
            run_mode = 0x01;
        }
    } else {
        run_mode = 0x01;
    }
}


SipAlertInitCtx

decompiled_code:
__int64 SipAlertInitCtx()
{
iface_ctx = calloc(1uLL, 0x18uLL);
if ( iface_ctx )
return 0LL;
SipLog(3LL, "util-alert.c", 47LL, "error in allocating the memroy");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
iface_ctx = calloc(1uLL, 0x18uLL);
if ( iface_ctx )
return 0LL;
SipLog(3LL, "util-alert.c", 47LL, "error in allocating the memroy");
return 0xFFFFFFFFLL;
}

original_code:
int SipAlertInitCtx()
{
    iface_ctx = calloc(1, sizeof (SipAlertCtx));
    if (iface_ctx == ((void *)0)) {
        SipLog(3, "util-alert.c",47, "error in allocating"
                " the memroy");
        return -1;
    }
    return 0;
}


SipAlertInitSyslogIface

decompiled_code:
__int64 SipAlertInitSyslogIface()
{
*((_BYTE *)iface_ctx + 8) |= 1u;
openlog(0LL, 8, 8);
return SipLog(1LL, "util-alert.c", 64LL, "syslog interface is initialized");
}

canonical_decompiled_code:
__int64 func1()
{
*((_BYTE *)iface_ctx + 8) |= 1u;
openlog(0LL, 8, 8);
return SipLog(1LL, "util-alert.c", 64LL, "syslog interface is initialized");
}

original_code:
void SipAlertInitSyslogIface()
{
    iface_ctx->iface |= 0x01;
    openlog(((void *)0), 0x08, (1<<3));
    SipLog(1, "util-alert.c",64, "syslog interface is "
            "initialized");
}


SipAlertInitHobbitIface

decompiled_code:
__int64 SipAlertInitHobbitIface()
{
_QWORD *v0; // rbx
__int64 result; // rax
char **v2; // rbx
char *s; // [rsp+8h] [rbp-10h] BYREF

*((_BYTE *)iface_ctx + 8) |= 2u;
if ( (unsigned int)SipConfGet("alert-file", &s) == 1 )
{
v2 = (char **)iface_ctx;
*v2 = strdup(s);
}
else
{
*(_QWORD *)iface_ctx = "/home/ica/stud/guri/sip_alert.txt";
}
v0 = iface_ctx;
v0[2] = fopen(*(const char **)iface_ctx, "w");
if ( *((_QWORD *)iface_ctx + 2) )
{
if ( (unsigned int)SipConfGet("institution", &institution) == 1 )
{
SipLog(1LL, "util-alert.c", 106LL, "Hobbit interface is initialized");
result = 0LL;
}
else
{
SipLog(
3LL,
"util-alert.c",
99LL,
"Institution code has not been provided in the configuration file. Please provide the code to start the engine :-)");
result = 0xFFFFFFFFLL;
}
}
else
{
SipLog(
3LL,
"util-alert.c",
92LL,
"Failed in opening the \"%s\" file. Check the permission for destination directory!!",
*(const char **)iface_ctx);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
_QWORD *v0; // rbx
__int64 result; // rax
char **v2; // rbx
char *s; // [rsp+8h] [rbp-10h] BYREF

*((_BYTE *)iface_ctx + 8) |= 2u;
if ( (unsigned int)SipConfGet("alert-file", &s) == 1 )
{
v2 = (char **)iface_ctx;
*v2 = strdup(s);
}
else
{
*(_QWORD *)iface_ctx = "/home/ica/stud/guri/sip_alert.txt";
}
v0 = iface_ctx;
v0[2] = fopen(*(const char **)iface_ctx, "w");
if ( *((_QWORD *)iface_ctx + 2) )
{
if ( (unsigned int)SipConfGet("institution", &institution) == 1 )
{
SipLog(1LL, "util-alert.c", 106LL, "Hobbit interface is initialized");
result = 0LL;
}
else
{
SipLog(
3LL,
"util-alert.c",
99LL,
"Institution code has not been provided in the configuration file. Please provide the code to start the engine :-)");
result = 0xFFFFFFFFLL;
}
}
else
{
SipLog(
3LL,
"util-alert.c",
92LL,
"Failed in opening the \"%s\" file. Check the permission for destination directory!!",
*(const char **)iface_ctx);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int SipAlertInitHobbitIface()
{
    char *filename;
    iface_ctx->iface |= 0x02;
    if (SipConfGet("alert-file", &filename) != 1) {
        iface_ctx->filename = calloc(1, sizeof("/home/ica/stud/guri/"
                                               "sip_alert.txt"));
        iface_ctx->filename = "/home/ica/stud/guri/sip_alert.txt";
    } else {
        iface_ctx->filename = strdup(filename);
    }
    iface_ctx->file_descr = fopen(iface_ctx->filename, "w");
    if (iface_ctx->file_descr == ((void *)0)) {
        SipLog(3, "util-alert.c",92, "Failed in opening the"
                " \"%s\" file. Check the permission for destination"
                " directory!!", iface_ctx->filename);
        return -1;
    }
    if (SipConfGet("institution", &institution) != 1) {
        SipLog(3, "util-alert.c",99, "Institution code has"
        " not been provided in the configuration file. Please provide the code"
        " to start the engine :-)");
        return -1;
    }
    SipLog(1, "util-alert.c",106, "Hobbit interface is "
            "initialized");
    return 0;
}

variable_types:
filename
char *


SipAlertInitNotification

decompiled_code:
__int64 SipAlertInitNotification()
{
__int64 *v0; // rsi
int v1; // eax
bool v2; // cf
bool v3; // zf
__int64 v4; // rdx
const char *v5; // rdi
__int64 v6; // rcx
char v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
char v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
__int64 v17; // rdx
__int64 v18; // rcx
__int64 result; // rax
int v20; // edx
char v21[200]; // [rsp+0h] [rbp-D8h] BYREF
__int64 v22[2]; // [rsp+C8h] [rbp-10h] BYREF

SipAlertInitCtx();
v0 = v22;
v1 = SipConfGet("alert-mode", v22);
v2 = v1 == 0;
v3 = v1 == 1;
if ( v1 == 1 )
{
v4 = v22[0];
v5 = "syslog";
v6 = 7LL;
v0 = (__int64 *)v22[0];
do
{
if ( !v6 )
break;
v2 = *(_BYTE *)v0 < *v5;
v3 = *(_BYTE *)v0 == *v5;
v0 = (__int64 *)((char *)v0 + 1);
++v5;
--v6;
}
while ( v3 );
v7 = (!v2 && !v3) - v2;
v8 = 0;
v9 = v7 == 0;
if ( v7 )
{
v10 = "hobbit";
v11 = 7LL;
v0 = (__int64 *)v22[0];
do
{
if ( !v11 )
break;
v8 = *(_BYTE *)v0 < *v10;
v9 = *(_BYTE *)v0 == *v10;
v0 = (__int64 *)((char *)v0 + 1);
++v10;
--v11;
}
while ( v9 );
v12 = (!v8 && !v9) - v8;
v13 = 0;
v14 = v12 == 0;
if ( v12 )
{
v15 = "both";
v16 = 5LL;
v0 = (__int64 *)v22[0];
do
{
if ( !v16 )
break;
v13 = *(_BYTE *)v0 < *v15;
v14 = *(_BYTE *)v0 == *v15;
v0 = (__int64 *)((char *)v0 + 1);
++v15;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
SipAlertInitSyslogIface(v15, v0, v22[0], v16);
if ( (unsigned int)SipAlertInitHobbitIface(v15, v0, v17, v18) )
return 0xFFFFFFFFLL;
}
}
else if ( (unsigned int)SipAlertInitHobbitIface(v10, v0, v22[0], v11) )
{
return 0xFFFFFFFFLL;
}
}
else
{
SipAlertInitSyslogIface(v5, v0, v22[0], v6);
}
}
else
{
((void (*)(void))SipAlertInitSyslogIface)();
}
alert_conn = SipConnectDB("alert-database", v0, v4, v16);
if ( (unsigned int)PQstatus(alert_conn) == 1 )
{
SipLog(3LL, "util-alert.c", 145LL, "Failed in connection to database: %s", v21);
result = 0xFFFFFFFFLL;
}
else
{
v20 = SipConfGet("alert-database.table", &alert_table);
result = 0LL;
if ( v20 != 1 )
alert_table = (__int64)"cdr_alert";
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 *v0; // rsi
int v1; // eax
bool v2; // cf
bool v3; // zf
__int64 v4; // rdx
const char *v5; // rdi
__int64 v6; // rcx
char v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
char v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
__int64 v17; // rdx
__int64 v18; // rcx
__int64 result; // rax
int v20; // edx
char v21[200]; // [rsp+0h] [rbp-D8h] BYREF
__int64 v22[2]; // [rsp+C8h] [rbp-10h] BYREF

func0();
v0 = v22;
v1 = SipConfGet("alert-mode", v22);
v2 = v1 == 0;
v3 = v1 == 1;
if ( v1 == 1 )
{
v4 = v22[0];
v5 = "syslog";
v6 = 7LL;
v0 = (__int64 *)v22[0];
do
{
if ( !v6 )
break;
v2 = *(_BYTE *)v0 < *v5;
v3 = *(_BYTE *)v0 == *v5;
v0 = (__int64 *)((char *)v0 + 1);
++v5;
--v6;
}
while ( v3 );
v7 = (!v2 && !v3) - v2;
v8 = 0;
v9 = v7 == 0;
if ( v7 )
{
v10 = "hobbit";
v11 = 7LL;
v0 = (__int64 *)v22[0];
do
{
if ( !v11 )
break;
v8 = *(_BYTE *)v0 < *v10;
v9 = *(_BYTE *)v0 == *v10;
v0 = (__int64 *)((char *)v0 + 1);
++v10;
--v11;
}
while ( v9 );
v12 = (!v8 && !v9) - v8;
v13 = 0;
v14 = v12 == 0;
if ( v12 )
{
v15 = "both";
v16 = 5LL;
v0 = (__int64 *)v22[0];
do
{
if ( !v16 )
break;
v13 = *(_BYTE *)v0 < *v15;
v14 = *(_BYTE *)v0 == *v15;
v0 = (__int64 *)((char *)v0 + 1);
++v15;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
func1(v15, v0, v22[0], v16);
if ( (unsigned int)func2(v15, v0, v17, v18) )
return 0xFFFFFFFFLL;
}
}
else if ( (unsigned int)func2(v10, v0, v22[0], v11) )
{
return 0xFFFFFFFFLL;
}
}
else
{
func1(v5, v0, v22[0], v6);
}
}
else
{
((void (*)(void))SipAlertInitSyslogIface)();
}
alert_conn = SipConnectDB("alert-database", v0, v4, v16);
if ( (unsigned int)PQstatus(alert_conn) == 1 )
{
SipLog(3LL, "util-alert.c", 145LL, "Failed in connection to database: %s", v21);
result = 0xFFFFFFFFLL;
}
else
{
v20 = SipConfGet("alert-database.table", &alert_table);
result = 0LL;
if ( v20 != 1 )
alert_table = (__int64)"cdr_alert";
}
return result;
}

original_code:
int SipAlertInitNotification()
{
    char *alert_mode;
    char conn_info[200];
    SipAlertInitCtx();
    if (SipConfGet("alert-mode", &alert_mode) == 1) {
        if (strcmp(alert_mode, "syslog") == 0) {
            SipAlertInitSyslogIface();
        } else if (strcmp(alert_mode, "hobbit") == 0) {
            if (SipAlertInitHobbitIface() != 0)
                return -1;
        } else if (strcmp(alert_mode, "both") == 0) {
            SipAlertInitSyslogIface();
            if (SipAlertInitHobbitIface() != 0)
                return -1;
        }
    } else {
        SipAlertInitSyslogIface();
    }
    alert_conn = SipConnectDB("alert-database");
    if(PQstatus(alert_conn) == CONNECTION_BAD) {
        SipLog(3, "util-alert.c",145, "Failed in "
                        "connection to database: %s", conn_info);
        return -1;
    }
    if (SipConfGet("alert-database.table", &alert_table) != 1) {
        alert_table = calloc(1, sizeof("cdr_alert"));
        alert_table = "cdr_alert";
    }
    return 0;
}


SipAlertDeInitCtx

decompiled_code:
__int64 SipAlertDeInitCtx()
{
char v0; // dl
FILE *v1; // rdi
FILE *v3; // rdi

if ( iface_ctx )
{
v0 = *((_BYTE *)iface_ctx + 8);
switch ( v0 )
{
case 2:
v1 = (FILE *)*((_QWORD *)iface_ctx + 2);
if ( v1 )
fclose(v1);
if ( *(_QWORD *)iface_ctx )
free(*(void **)iface_ctx);
goto LABEL_11;
case 3:
v3 = (FILE *)*((_QWORD *)iface_ctx + 2);
if ( v3 )
fclose(v3);
if ( *(_QWORD *)iface_ctx )
free(*(void **)iface_ctx);
break;
case 1:
break;
default:
SipLog(3LL, "util-alert.c", 327LL, "invalid alert mode");
LABEL_11:
free(iface_ctx);
goto LABEL_12;
}
closelog();
goto LABEL_11;
}
LABEL_12:
PQfinish(alert_conn);
return SipLog(2LL, "util-alert.c", 334LL, "Alert module has been de-initialized");
}

canonical_decompiled_code:
__int64 func6()
{
char v0; // dl
FILE *v1; // rdi
FILE *v3; // rdi

if ( iface_ctx )
{
v0 = *((_BYTE *)iface_ctx + 8);
switch ( v0 )
{
case 2:
v1 = (FILE *)*((_QWORD *)iface_ctx + 2);
if ( v1 )
fclose(v1);
if ( *(_QWORD *)iface_ctx )
free(*(void **)iface_ctx);
goto LABEL_11;
case 3:
v3 = (FILE *)*((_QWORD *)iface_ctx + 2);
if ( v3 )
fclose(v3);
if ( *(_QWORD *)iface_ctx )
free(*(void **)iface_ctx);
break;
case 1:
break;
default:
SipLog(3LL, "util-alert.c", 327LL, "invalid alert mode");
LABEL_11:
free(iface_ctx);
goto LABEL_12;
}
closelog();
goto LABEL_11;
}
LABEL_12:
PQfinish(alert_conn);
return SipLog(2LL, "util-alert.c", 334LL, "Alert module has been de-initialized");
}

original_code:
void SipAlertDeInitCtx()
{
    if (iface_ctx != ((void *)0)) {
        switch (iface_ctx->iface) {
            case 0x02:
                if (iface_ctx->file_descr != ((void *)0))
                    fclose(iface_ctx->file_descr);
                if (iface_ctx->filename != ((void *)0))
                    free(iface_ctx->filename);
                break;
            case 0x01:
                closelog();
                break;
            case 0x02 | 0x01:
                if (iface_ctx->file_descr != ((void *)0))
                    fclose(iface_ctx->file_descr);
                if (iface_ctx->filename != ((void *)0))
                    free(iface_ctx->filename);
                closelog();
                break;
            default:
                SipLog(3, "util-alert.c",327, "invalid alert"
                        " mode");
                break;
        }
        free(iface_ctx);
    }
    PQfinish(alert_conn);
    SipLog(2, "util-alert.c",334, "Alert module has been "
            "de-initialized");
}


SipInitLog

decompiled_code:
char SipInitLog()
{
int v0; // eax
bool v1; // zf
const char *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
v0 = SipConfGet("logging-mode", &v3);
if ( v0 == 1 )
{
v1 = strcmp(v3, "error") == 0;
LOBYTE(v0) = !v1;
if ( v1 )
{
log_level = 3;
}
else
{
v1 = strcmp(v3, "info") == 0;
LOBYTE(v0) = v1 + 1;
log_level = v1 + 1;
}
}
return v0;
}

canonical_decompiled_code:
char func0()
{
int v0; // eax
bool v1; // zf
const char *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
v0 = SipConfGet("logging-mode", &v3);
if ( v0 == 1 )
{
v1 = strcmp(v3, "error") == 0;
LOBYTE(v0) = !v1;
if ( v1 )
{
log_level = 3;
}
else
{
v1 = strcmp(v3, "info") == 0;
LOBYTE(v0) = v1 + 1;
log_level = v1 + 1;
}
}
return v0;
}

original_code:
void SipInitLog()
{
    char *mode = ((void *)0);
    if ((SipConfGet("logging-mode", &mode)) == 1) {
        if (strcmp(mode, "error") == 0) {
            log_level = 3;
        } else if (strcmp(mode, "info") == 0) {
            log_level = 2;
        } else {
            log_level = 1;
        }
    }
}

variable_types:
mode
char *


SipLog

decompiled_code:
int SipLog(int a1, const char *a2, unsigned int a3, const char *a4, ...)
{
int result; // eax
struct tm *v7; // rax
char s[32]; // [rsp+0h] [rbp-528h] BYREF
struct timeval tv; // [rsp+20h] [rbp-508h] BYREF
gcc_va_list arg; // [rsp+38h] [rbp-4F0h] BYREF
char v11[1024]; // [rsp+50h] [rbp-4D8h] BYREF

result = log_level;
if ( log_level && log_level <= a1 )
{
gettimeofday(&tv, 0LL);
v7 = localtime(&tv.tv_sec);
snprintf(
s,
0x1EuLL,
"%d/%d/%04d -- %02d:%02d:%02d",
(unsigned int)v7->tm_mday,
(unsigned int)(v7->tm_mon + 1),
(unsigned int)(v7->tm_year + 1900),
(unsigned int)v7->tm_hour,
(unsigned int)v7->tm_min,
(unsigned int)v7->tm_sec);
va_start(arg, a4);
result = vsnprintf(v11, 0x3FFuLL, a4, arg);
if ( result < 0 )
{
result = snprintf(v11, 0x400uLL, "[vnsprintf returned error %d]", (unsigned int)result);
}
else if ( result > 1023 )
{
v11[1022] = 43;
v11[1023] = 0;
}
switch ( a1 )
{
case 2:
result = fprintf(stdout, "[%s] <INFO> %s\n", s, v11);
break;
case 3:
result = fprintf(stderr, "[%s] <ERROR> [%s:%d] %s\n", s, a2, a3, v11);
break;
case 1:
result = fprintf(stdout, "[%s] <DEBUG> [%s:%d] %s\n", s, a2, a3, v11);
break;
}
}
return result;
}

canonical_decompiled_code:
int func1(int a1, const char *a2, unsigned int a3, const char *a4, ...)
{
int result; // eax
struct tm *v7; // rax
char s[32]; // [rsp+0h] [rbp-528h] BYREF
struct timeval tv; // [rsp+20h] [rbp-508h] BYREF
gcc_va_list arg; // [rsp+38h] [rbp-4F0h] BYREF
char v11[1024]; // [rsp+50h] [rbp-4D8h] BYREF

result = log_level;
if ( log_level && log_level <= a1 )
{
gettimeofday(&tv, 0LL);
v7 = localtime(&tv.tv_sec);
snprintf(
s,
0x1EuLL,
"%d/%d/%04d -- %02d:%02d:%02d",
(unsigned int)v7->tm_mday,
(unsigned int)(v7->tm_mon + 1),
(unsigned int)(v7->tm_year + 1900),
(unsigned int)v7->tm_hour,
(unsigned int)v7->tm_min,
(unsigned int)v7->tm_sec);
va_start(arg, a4);
result = vsnprintf(v11, 0x3FFuLL, a4, arg);
if ( result < 0 )
{
result = snprintf(v11, 0x400uLL, "[vnsprintf returned error %d]", (unsigned int)result);
}
else if ( result > 1023 )
{
v11[1022] = 43;
v11[1023] = 0;
}
switch ( a1 )
{
case 2:
result = fprintf(stdout, "[%s] <INFO> %s\n", s, v11);
break;
case 3:
result = fprintf(stderr, "[%s] <ERROR> [%s:%d] %s\n", s, a2, a3, v11);
break;
case 1:
result = fprintf(stdout, "[%s] <DEBUG> [%s:%d] %s\n", s, a2, a3, v11);
break;
}
}
return result;
}

original_code:
void SipLog(int level, char *filename, int line, const char *fmt, ...)
{
    if ((log_level > level) || (log_level == 0))
        return;
    char buf[1024];
    va_list args;
    struct timeval tval;
    struct tm *tms = ((void *)0);
    gettimeofday(&tval, ((void *)0));
    tms = localtime(&tval.tv_sec);
    char temp[30];
    snprintf(temp, 30, "%d/%d/%04d -- %02d:%02d:%02d",tms->tm_mday, tms->tm_mon
            + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min, tms->tm_sec);
    __builtin_va_start(args,fmt);
    int r = vsnprintf(buf, 1023, fmt, args);
    if (r < 0) {
        snprintf(buf, 1024, "[vnsprintf returned error %d]", r);
    }
    if (r > 1023) {
        buf[1022] = '+';
        buf[1023] = '\0';
    }
    switch(level) {
        case 2:
            fprintf(stdout, "[%s] <INFO> %s\n", temp, buf);
            break;
        case 1:
            fprintf(stdout, "[%s] <DEBUG> [%s:%d] %s\n", temp, filename, line,
                    buf);
            break;
        case 3:
            fprintf(stderr, "[%s] <ERROR> [%s:%d] %s\n", temp, filename, line,
                    buf);
            break;
    }
    __builtin_va_end(args);
}

canonical_original_code:
void SipLog(int level, char *filename, int line, char *fmt, ...)
{
    if ((log_level > level) || (log_level == 0))
        return;
    char buf[1024];
    __builtin_va_list args;
    struct timeval tval;
    struct tm *tms = ((void *)0);
    gettimeofday(&tval, ((void *)0));
    tms = localtime(&tval.tv_sec);
    char temp[30];
    snprintf(temp, 30, "%d/%d/%04d -- %02d:%02d:%02d",tms->tm_mday, tms->tm_mon
            + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min, tms->tm_sec);
    __builtin_va_start(args,fmt);
    int r = vsnprintf(buf, 1023, fmt, args);
    if (r < 0) {
        snprintf(buf, 1024, "[vnsprintf returned error %d]", r);
    }
    if (r > 1023) {
        buf[1022] = '+';
        buf[1023] = '\0';
    }
    switch(level) {
        case 2:
            fprintf(stdout, "[%s] <INFO> %s\n", temp, buf);
            break;
        case 1:
            fprintf(stdout, "[%s] <DEBUG> [%s:%d] %s\n", temp, filename, line,
                    buf);
            break;
        case 3:
            fprintf(stderr, "[%s] <ERROR> [%s:%d] %s\n", temp, filename, line,
                    buf);
            break;
    }
    __builtin_va_end(args);
}

variable_types: level int

variable_types: line int

variable_types:
fmt
char *

variable_types:
buf
char [1024]

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

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

variable_types:
temp
char [30]

variable_types: r int


repo: gyaikhom/fcm

decompiled_code:
double __fastcall get_norm(int a1, int a2)
{
__int64 v2; // rax
double v3; // xmm1_8
double v4; // xmm0_8

if ( num_dimensions <= 0 )
{
v3 = 0.0;
return sqrt(v3);
}
v2 = 0LL;
v3 = 0.0;
do
{
v4 = data_point[5 * a1 + v2] - cluster_centre[5 * a2 + v2];
v3 = v3 + v4 * v4;
++v2;
}
while ( num_dimensions > (int)v2 );
if ( v3 >= 0.0 )
return sqrt(v3);
return sqrt(v3);
}

canonical_decompiled_code:
double __fastcall func1(int a1, int a2)
{
__int64 v2; // rax
double v3; // xmm1_8
double v4; // xmm0_8

if ( num_dimensions <= 0 )
{
v3 = 0.0;
return sqrt(v3);
}
v2 = 0LL;
v3 = 0.0;
do
{
v4 = data_point[5 * a1 + v2] - cluster_centre[5 * a2 + v2];
v3 = v3 + v4 * v4;
++v2;
}
while ( num_dimensions > (int)v2 );
if ( v3 >= 0.0 )
return sqrt(v3);
return sqrt(v3);
}

original_code:
double
get_norm(int i, int j) {
    int k;
    double sum = 0.0;
    for (k = 0; k < num_dimensions; k++) {
        sum += pow(data_point[i][k] - cluster_centre[j][k], 2);
    }
    return sqrt(sum);
}

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: sum double

return_type: double


decompiled_code:
double __fastcall get_new_value(int a1, int a2)
{
double v2; // r14
int v3; // ebp
double v4; // rbx
double v5; // xmm0_8
double v7; // [rsp+8h] [rbp-30h]

if ( num_clusters <= 0 )
{
v7 = 0.0;
}
else
{
v2 = 2.0 / (fuzziness - 1.0);
v7 = 0.0;
v3 = 0;
do
{
v4 = get_norm(a1, a2);
v5 = get_norm(a1, v3);
v7 = pow(v4 / v5, v2) + v7;
++v3;
}
while ( num_clusters > v3 );
}
return 1.0 / v7;
}

canonical_decompiled_code:
double __fastcall func2(int a1, int a2)
{
double v2; // r14
int v3; // ebp
double v4; // rbx
double v5; // xmm0_8
double v7; // [rsp+8h] [rbp-30h]

if ( num_clusters <= 0 )
{
v7 = 0.0;
}
else
{
v2 = 2.0 / (fuzziness - 1.0);
v7 = 0.0;
v3 = 0;
do
{
v4 = func1(a1, a2);
v5 = func1(a1, v3);
v7 = pow(v4 / v5, v2) + v7;
++v3;
}
while ( num_clusters > v3 );
}
return 1.0 / v7;
}

original_code:
double
get_new_value(int i, int j) {
    int k;
    double t, p, sum;
    sum = 0.0;
    p = 2 / (fuzziness - 1);
    for (k = 0; k < num_clusters; k++) {
        t = get_norm(i, j) / get_norm(i, k);
        t = pow(t, p);
        sum += t;
    }
    return 1.0 / sum;
}

canonical_original_code:
double get_new_value(int i, int j) {
    int k;
    double t; double p; double sum;
    sum = 0.0;
    p = 2 / (fuzziness - 1);
    for (k = 0; k < num_clusters; k++) {
        t = get_norm(i, j) / get_norm(i, k);
        t = pow(t, p);
        sum += t;
    }
    return 1.0 / sum;
}

variable_types: t double

variable_types: p double


decompiled_code:
double update_degree_of_membership()
{
double *v0; // r13
int v1; // er12
double v2; // xmm0_8
int i; // ebx
double *v4; // rbp
double v6; // [rsp+8h] [rbp-30h]

if ( num_clusters <= 0 )
return 0.0;
v0 = degree_of_memb;
v6 = 0.0;
v1 = 0;
do
{
v4 = v0;
for ( i = 0; num_data_points > i; v4 += 100 )
{
v2 = get_new_value(i, v1);
v6 = fmax(v2 - *v4, v6);
*v4 = v2;
++i;
}
++v1;
++v0;
}
while ( num_clusters > v1 );
return v6;
}

canonical_decompiled_code:
double func3()
{
double *v0; // r13
int v1; // er12
double v2; // xmm0_8
int i; // ebx
double *v4; // rbp
double v6; // [rsp+8h] [rbp-30h]

if ( num_clusters <= 0 )
return 0.0;
v0 = degree_of_memb;
v6 = 0.0;
v1 = 0;
do
{
v4 = v0;
for ( i = 0; num_data_points > i; v4 += 100 )
{
v2 = func2(i, v1);
v6 = fmax(v2 - *v4, v6);
*v4 = v2;
++i;
}
++v1;
++v0;
}
while ( num_clusters > v1 );
return v6;
}

original_code:
double
update_degree_of_membership() {
    int i, j;
    double new_uij;
    double max_diff = 0.0, diff;
    for (j = 0; j < num_clusters; j++) {
        for (i = 0; i < num_data_points; i++) {
            new_uij = get_new_value(i, j);
            diff = new_uij - degree_of_memb[i][j];
            if (diff > max_diff)
                max_diff = diff;
            degree_of_memb[i][j] = new_uij;
        }
    }
    return max_diff;
}

canonical_original_code:
double update_degree_of_membership() {
    int i; int j;
    double new_uij;
    double max_diff = 0.0; double diff;
    for (j = 0; j < num_clusters; j++) {
        for (i = 0; i < num_data_points; i++) {
            new_uij = get_new_value(i, j);
            diff = new_uij - degree_of_memb[i][j];
            if (diff > max_diff)
                max_diff = diff;
            degree_of_memb[i][j] = new_uij;
        }
    }
    return max_diff;
}

variable_types: diff double


fcm

decompiled_code:
__int64 __fastcall fcm(const char *a1)
{
init(a1);
do
calculate_centre_vectors();
while ( update_degree_of_membership() > *(double *)&epsilon );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
func0(a1);
do
calculate_centre_vectors();
while ( func3() > *(double *)&epsilon );
return 0LL;
}

original_code:
int
fcm(char *fname) {
    double max_diff;
    init(fname);
    do {
        calculate_centre_vectors();
        max_diff = update_degree_of_membership();
    } while (max_diff > epsilon);
    return 0;
}

variable_types:
fname
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("------------------------------------------------------------------------");
if ( argc != 2 )
{
puts("USAGE: fcm <input file>");
exit(1);
}
fcm(argv[1]);
printf("Number of data points: %d\n", (unsigned int)num_data_points);
printf("Number of clusters: %d\n", (unsigned int)num_clusters);
printf("Number of data-point dimensions: %d\n", (unsigned int)num_dimensions);
printf("Accuracy margin: %lf\n", *(double *)&epsilon);
print_membership_matrix("membership.matrix");
gnuplot_membership_matrix();
puts("------------------------------------------------------------------------");
puts("The program run was successful...");
puts("Storing membership matrix in file 'membership.matrix'\n");
puts("If the points are on a plane (2 dimensions)");
puts("the gnuplot script was generated in file 'gnuplot.script', and");
puts("the gnuplot data in files cluster.[0]... \n");
puts("Process 'gnuplot.script' to generate graph: 'cluster_plot.png'\n");
puts("NOTE: While generating the gnuplot data, for each of the data points");
puts("the corresponding cluster is the one which has the highest");
puts("degree-of-membership as found in 'membership.matrix'.");
puts("------------------------------------------------------------------------");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("------------------------------------------------------------------------");
if ( argc != 2 )
{
puts("USAGE: fcm <input file>");
exit(1);
}
func4(argv[1]);
printf("Number of data points: %d\n", (unsigned int)num_data_points);
printf("Number of clusters: %d\n", (unsigned int)num_clusters);
printf("Number of data-point dimensions: %d\n", (unsigned int)num_dimensions);
printf("Accuracy margin: %lf\n", *(double *)&epsilon);
func7("membership.matrix");
func5();
puts("------------------------------------------------------------------------");
puts("The program run was successful...");
puts("Storing membership matrix in file 'membership.matrix'\n");
puts("If the points are on a plane (2 dimensions)");
puts("the gnuplot script was generated in file 'gnuplot.script', and");
puts("the gnuplot data in files cluster.[0]... \n");
puts("Process 'gnuplot.script' to generate graph: 'cluster_plot.png'\n");
puts("NOTE: While generating the gnuplot data, for each of the data points");
puts("the corresponding cluster is the one which has the highest");
puts("degree-of-membership as found in 'membership.matrix'.");
puts("------------------------------------------------------------------------");
return 0;
}

original_code:
int
main(int argc, char **argv) {
    printf
            ("------------------------------------------------------------------------\n");
    if (argc != 2) {
        printf("USAGE: fcm <input file>\n");
        exit(1);
    }
    fcm(argv[1]);
    printf("Number of data points: %d\n", num_data_points);
    printf("Number of clusters: %d\n", num_clusters);
    printf("Number of data-point dimensions: %d\n", num_dimensions);
    printf("Accuracy margin: %lf\n", epsilon);
    print_membership_matrix("membership.matrix");
    gnuplot_membership_matrix();
    printf
            ("------------------------------------------------------------------------\n");
    printf("The program run was successful...\n");
    printf("Storing membership matrix in file 'membership.matrix'\n\n");
    printf("If the points are on a plane (2 dimensions)\n");
    printf("the gnuplot script was generated in file 'gnuplot.script', and\n");
    printf("the gnuplot data in files cluster.[0]... \n\n");
    printf
            ("Process 'gnuplot.script' to generate graph: 'cluster_plot.png'\n\n");
    printf
            ("NOTE: While generating the gnuplot data, for each of the data points\n");
    printf("the corresponding cluster is the one which has the highest\n");
    printf("degree-of-membership as found in 'membership.matrix'.\n");
    printf
            ("------------------------------------------------------------------------\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


warn

repo: gyepisam/spread-msg

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

va_start(arg, format);
return output(stderr, format, arg);
}

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

va_start(arg, format);
return func0(stderr, format, arg);
}

original_code:
void warn(const char *fmt, ...) {
  va_list arg;
  __builtin_va_start(arg,fmt);
  output(stderr, fmt, arg);
  __builtin_va_end(arg);
}

canonical_original_code:
void warn(char *fmt, ...) {
  __builtin_va_list arg;
  __builtin_va_start(arg,fmt);
  output(stderr, fmt, arg);
  __builtin_va_end(arg);
}


print

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

va_start(arg, format);
return output(stdout, format, arg);
}

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

va_start(arg, format);
return func0(stdout, format, arg);
}

original_code:
int print(const char *fmt, ...) {
  va_list arg;
  int n;
  __builtin_va_start(arg,fmt);
  n = output(stdout, fmt, arg);
  __builtin_va_end(arg);
  return n;
}

canonical_original_code:
int print(char *fmt, ...) {
  __builtin_va_list arg;
  int n;
  __builtin_va_start(arg,fmt);
  n = output(stdout, fmt, arg);
  __builtin_va_end(arg);
  return n;
}

variable_types: n int


decompiled_code:
size_t __fastcall fmt_date(char *s, int a2, const char *a3)
{
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
return strftime(s, a2, a3, &tp);
}

canonical_decompiled_code:
size_t __fastcall func3(char *s, int a2, const char *a3)
{
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
return strftime(s, a2, a3, &tp);
}

original_code:
int fmt_date(char *buf, int n, char *fmt) {
    struct tm tm;
    time_t now;
    int ret;
    now = time(((void *)0));
    localtime_r(&now, &tm);
    ret = strftime(buf, n, fmt, &tm);
    return ret;
}

canonical_original_code:
int fmt_date(char *buf, int n, char *fmt) {
    struct tm tm;
    long now;
    int ret;
    now = time(((void *)0));
    localtime_r(&now, &tm);
    ret = strftime(buf, n, fmt, &tm);
    return ret;
}

variable_types:
buf
char *

variable_types:
fmt
char *

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

variable_types: now long

variable_types: ret int


decompiled_code:
int warn_log(char *format, ...)
{
__int64 v1; // rax
char v3[40]; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-D0h] BYREF

if ( (unsigned int)fmt_date(v3, 30, "%Y-%m-%d %H:%M:%S") )
warn("%s ", v3);
v1 = sec_time();
warn("[%ld] ", v1);
va_start(arg, format);
return output(stderr, format, arg);
}

canonical_decompiled_code:
int func4(char *format, ...)
{
__int64 v1; // rax
char v3[40]; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-D0h] BYREF

if ( (unsigned int)func3(v3, 30, "%Y-%m-%d %H:%M:%S") )
func1("%s ", v3);
v1 = sec_time();
func1("[%ld] ", v1);
va_start(arg, format);
return func0(stderr, format, arg);
}

original_code:
void warn_log(const char *fmt, ...) {
    va_list arg;
    int n;
    char buf[30];
    n = fmt_date(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S");
    if (n != 0)
        warn("%s ", buf);
    warn("[%ld] ", sec_time());
    __builtin_va_start(arg,fmt);
    output(stderr, fmt, arg);
    __builtin_va_end(arg);
}

canonical_original_code:
void warn_log(char *fmt, ...) {
    __builtin_va_list arg;
    int n;
    char buf[30];
    n = fmt_date(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S");
    if (n != 0)
        warn("%s ", buf);
    warn("[%ld] ", sec_time());
    __builtin_va_start(arg,fmt);
    output(stderr, fmt, arg);
    __builtin_va_end(arg);
}

variable_types:
buf
char [30]


decompiled_code:
int warn_console(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-140h] BYREF
char s[32]; // [rsp+20h] [rbp-128h] BYREF
struct timeval tv; // [rsp+40h] [rbp-108h] BYREF
struct tm tp; // [rsp+50h] [rbp-F8h] BYREF

gettimeofday(&tv, 0LL);
localtime_r(&tv.tv_sec, &tp);
if ( (unsigned int)strftime(s, 0x1EuLL, "%Y-%m-%d %H:%M:%S", &tp) )
fprintf(stderr, "%s ", s);
va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func5(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-140h] BYREF
char s[32]; // [rsp+20h] [rbp-128h] BYREF
struct timeval tv; // [rsp+40h] [rbp-108h] BYREF
struct tm tp; // [rsp+50h] [rbp-F8h] BYREF

gettimeofday(&tv, 0LL);
localtime_r(&tv.tv_sec, &tp);
if ( (unsigned int)strftime(s, 0x1EuLL, "%Y-%m-%d %H:%M:%S", &tp) )
fprintf(stderr, "%s ", s);
va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
void warn_console(const char *fmt, ...) {
    struct tm tm;
    struct timeval tv;
    char buf[30];
    int n;
    va_list arg;
    gettimeofday(&tv, ((void *)0));
    localtime_r(&tv.tv_sec, &tm);
    n = strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
    if (n != 0)
        fprintf(stderr, "%s ", buf);
    __builtin_va_start(arg,fmt);
    vfprintf(stderr, fmt, arg);
    __builtin_va_end(arg);
}

canonical_original_code:
void warn_console(char *fmt, ...) {
    struct tm tm;
    struct timeval tv;
    char buf[30];
    int n;
    __builtin_va_list arg;
    gettimeofday(&tv, ((void *)0));
    localtime_r(&tv.tv_sec, &tm);
    n = strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
    if (n != 0)
        fprintf(stderr, "%s ", buf);
    __builtin_va_start(arg,fmt);
    vfprintf(stderr, fmt, arg);
    __builtin_va_end(arg);
}

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

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


fatal

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

va_start(arg, a1);
output(stderr, a1, arg);
exit(3);
}

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

va_start(arg, a1);
func0(stderr, a1, arg);
exit(3);
}

original_code:
void
fatal(char *msg, ...)
{
  va_list arg;
  __builtin_va_start(arg,msg);
  output(stderr, msg, arg);
  __builtin_va_end(arg);
  exit(3);
}

canonical_original_code:
void fatal(char *msg, ...)
{
  __builtin_va_list arg;
  __builtin_va_start(arg,msg);
  output(stderr, msg, arg);
  __builtin_va_end(arg);
  exit(3);
}

variable_types:
msg
char *


xmalloc

decompiled_code:
void *__fastcall xmalloc(int a1)
{
void *v1; // rax

v1 = malloc(a1);
if ( !v1 )
fatal("out of memory");
return memset(v1, 0, a1);
}

canonical_decompiled_code:
void *__fastcall func7(int a1)
{
void *v1; // rax

v1 = malloc(a1);
if ( !v1 )
func6("out of memory");
return memset(v1, 0, a1);
}

original_code:
void*
xmalloc(int n)
{
 void *p;
 p = malloc(n);
 if(p == ((void*)0))
   fatal("out of memory");
 memset(p, 0, n);
 return p;
}

canonical_original_code:
void *xmalloc(int n)
{
 void *p;
 p = malloc(n);
 if(p == ((void *)0))
   fatal("out of memory");
 memset(p, 0, n);
 return p;
}

variable_types:
p
void *

return_type: void *


xstrdup

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

result = strdup(a1);
if ( !result )
fatal("out of memory");
return result;
}

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

result = strdup(a1);
if ( !result )
func6("out of memory");
return result;
}

original_code:
char*
xstrdup(const char *p)
{
  char *x;
  x = strdup(p);
  if(x == ((void*)0))
    fatal("out of memory");
  return x;
}

canonical_original_code:
char *xstrdup(char *p)
{
  char *x;
  x = strdup(p);
  if(x == ((void *)0))
    fatal("out of memory");
  return x;
}

variable_types:
p
char *

variable_types:
x
char *


xmemdup

decompiled_code:
void *__fastcall xmemdup(void *src, int a2)
{
void *v2; // rax

v2 = xmalloc(a2);
return memcpy(v2, src, a2);
}

canonical_decompiled_code:
void *__fastcall func9(void *src, int a2)
{
void *v2; // rax

v2 = func7(a2);
return memcpy(v2, src, a2);
}

original_code:
void *
xmemdup(const void *p, int n)
{
    void *q;
    q = xmalloc(n);
    memcpy(q, p, n);
    return q;
}

canonical_original_code:
void *xmemdup(void *p, int n)
{
    void *q;
    q = xmalloc(n);
    memcpy(q, p, n);
    return q;
}

variable_types:
q
void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, int a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
fatal("out of memory");
return result;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1, int a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
func6("out of memory");
return result;
}

original_code:
void*
xrealloc(void *p, int n)
{
 p = realloc(p, n);
 if(p == ((void*)0))
  fatal("out of memory");
 return p;
}

canonical_original_code:
void *xrealloc(void *p, int n)
{
 p = realloc(p, n);
 if(p == ((void *)0))
  fatal("out of memory");
 return p;
}


xfree

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

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

original_code:
void
xfree(void *p)
{
  free(p);
}

canonical_original_code:
void xfree(void *p)
{
  free(p);
}


allocate

repo: gyom/schemeInterpreterC

original_code:
void * allocate(struct _MemorySpace * this, int n_chunks) {
 if (this->current_allocation_position + n_chunks > this->end) {
  return ((void *)0);
 } else {
  void * start_of_segment = this->current_allocation_position;
  this->current_allocation_position += n_chunks;
  this->n_chunks_used += n_chunks;
  return start_of_segment;
 }
}

canonical_original_code:
void *allocate(struct _MemorySpace *this, int n_chunks) {
 if (this->current_allocation_position + n_chunks > this->end) {
  return ((void *)0);
 } else {
  void *start_of_segment = this->current_allocation_position;
  this->current_allocation_position += n_chunks;
  this->n_chunks_used += n_chunks;
  return start_of_segment;
 }
}

variable_types: struct _MemorySpace { void *start; void *current_allocation_position; void *end; int n_chunks_total; int n_chunks_used; void *(*allocate)(struct _MemorySpace *, int); void (*destroy)(struct _MemorySpace *); void (*init)(struct _MemorySpace *, int); int (*needs_reallocation)(struct _MemorySpace *); } *


decompiled_code:
_BOOL8 __fastcall needs_reallocation(__int64 a1)
{
return (double)*(int *)(a1 + 28) >= (double)*(int *)(a1 + 24) * 0.9;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return (double)*(int *)(a1 + 28) >= (double)*(int *)(a1 + 24) * 0.9;
}

original_code:
int needs_reallocation(struct _MemorySpace * this) {
 if (0.9 * (this->n_chunks_total) <= (this->n_chunks_used))
  return 1;
 else
  return 0;
}

canonical_original_code:
int needs_reallocation(struct _MemorySpace *this) {
 if (0.9 * (this->n_chunks_total) <= (this->n_chunks_used))
  return 1;
 else
  return 0;
}

user_defined_types: struct _MemorySpace { void *start; void *current_allocation_position; void *end; int n_chunks_total; int n_chunks_used; void *(*allocate)(struct _MemorySpace *, int); void (*destroy)(struct _MemorySpace *); void (*init)(struct _MemorySpace *, int); int (*needs_reallocation)(struct _MemorySpace *); }


init

decompiled_code:
char *__fastcall init(__int64 a1, int a2)
{
char *result; // rax

result = (char *)malloc(a2);
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 16) = &result[a2];
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 24) = a2;
*(_DWORD *)(a1 + 28) = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, int a2)
{
char *result; // rax

result = (char *)malloc(a2);
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 16) = &result[a2];
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 24) = a2;
*(_DWORD *)(a1 + 28) = 0;
return result;
}

original_code:
void init(struct _MemorySpace * this, int n_chunks_total) {
 this->start = malloc(n_chunks_total);
 this->end = this->start + n_chunks_total;
 this->current_allocation_position = this->start;
 this->n_chunks_total = n_chunks_total;
 this->n_chunks_used = 0;
}

canonical_original_code:
void init(struct _MemorySpace *this, int n_chunks_total) {
 this->start = malloc(n_chunks_total);
 this->end = this->start + n_chunks_total;
 this->current_allocation_position = this->start;
 this->n_chunks_total = n_chunks_total;
 this->n_chunks_used = 0;
}


destroy

original_code:
void destroy(struct _MemorySpace * this) {
 free(this->start);
 this->start = ((void *)0);
 this->end = ((void *)0);
 this->current_allocation_position = ((void *)0);
 this->n_chunks_total = 0;
 this->n_chunks_used = 0;
}

canonical_original_code:
void destroy(struct _MemorySpace *this) {
 free(this->start);
 this->start = ((void *)0);
 this->end = ((void *)0);
 this->current_allocation_position = ((void *)0);
 this->n_chunks_total = 0;
 this->n_chunks_used = 0;
}


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
int dlist_count(dlist_t *list)
{
 int i=0;
 while(list) {
  i++;
  list=list->next;
 }
 return i;
}

canonical_original_code:
int dlist_count(struct DLIST *list)
{
 int i = 0;
 while(list) {
  i++;
  list=list->next;
 }
 return i;
}

variable_types: struct DLIST { struct DLIST *prev; struct DLIST *next; unsigned int dt; void (*f)(void *instance, void *data); void *instance; void *data; } *

variable_types: i int


decompiled_code:
int __fastcall dlist_dump(const void **a1)
{
const void **v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("[emux51] staring dlist dump"); v1; v1 = (const void **)v1[1] )
result = printf("list:%p\n\t->prev:\t%p\n\t->next:\t%p\n", v1, *v1, v1[1]);
return result;
}

canonical_decompiled_code:
int __fastcall func1(const void **a1)
{
const void **v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("[emux51] staring dlist dump"); v1; v1 = (const void **)v1[1] )
result = printf("list:%p\n\t->prev:\t%p\n\t->next:\t%p\n", v1, *v1, v1[1]);
return result;
}

original_code:
void dlist_dump(dlist_t *list)
{
 printf("[emux51] staring dlist dump\n");
 while(list) {
  printf("list:%p\n\t->prev:\t%p\n\t->next:\t%p\n", list, list->prev, list->next);
  list=list->next;
 }
}

canonical_original_code:
void dlist_dump(struct DLIST *list)
{
 printf("[emux51] staring dlist dump\n");
 while(list) {
  printf("list:%p\n\t->prev:\t%p\n\t->next:\t%p\n", list, list->prev, list->next);
  list=list->next;
 }
}

user_defined_types: struct DLIST { struct DLIST *prev; struct DLIST *next; unsigned int dt; void (*f)(void *instance, void *data); void *instance; void *data; }


original_code:
void dlist_perform(dlist_t **first, unsigned steps)
{
 dlist_t *list;
 dlist_t *expired;
 int dump=0;
 dlist_t *next;
 list=*first;
 expired=list;
 while (list) {
  if (list->dt > steps) {
   list->dt -= steps;
   if (list->prev)
    list->prev->next=((void *)0);
   else
    expired=((void *)0);
   list->prev=((void *)0);
   break;
  }
  steps -= list->dt;
  list=list->next;
 }
 *first=list;
 if (dump) {
  printf("dumping new list:\n");
  dlist_dump(list);
  printf("dumping expired list:\n");
  dlist_dump(expired);
 }
 int i=0;
 while(expired) {
  if (dump)
   printf("executing %d -> %p\n", ++i, expired);
  next=expired->next;
  expired->f(expired->instance, expired->data);
  expired=next;
 }
}

canonical_original_code:
void dlist_perform(struct DLIST **first, unsigned int steps)
{
 struct DLIST *list;
 struct DLIST *expired;
 int dump = 0;
 struct DLIST *next;
 list=*first;
 expired=list;
 while (list) {
  if (list->dt > steps) {
   list->dt -= steps;
   if (list->prev)
    list->prev->next=((void *)0);
   else
    expired=((void *)0);
   list->prev=((void *)0);
   break;
  }
  steps -= list->dt;
  list=list->next;
 }
 *first=list;
 if (dump) {
  printf("dumping new list:\n");
  dlist_dump(list);
  printf("dumping expired list:\n");
  dlist_dump(expired);
 }
 int i = 0;
 while(expired) {
  if (dump)
   printf("executing %d -> %p\n", ++i, expired);
  next=expired->next;
  expired->f(expired->instance, expired->data);
  expired=next;
 }
}

variable_types: struct DLIST { struct DLIST *prev; struct DLIST *next; unsigned int dt; void (*f)(void *instance, void *data); void *instance; void *data; } **

variable_types:
steps
unsigned int

variable_types: dump int


decompiled_code:
__int64 __fastcall setup_timer(__int64 (*a1)(void), float a2)
{
__time_t v2; // rsi
float v3; // xmm0_4
unsigned __int64 v4; // rcx
struct itimerval v6; // [rsp+0h] [rbp-28h] BYREF

timer_callback = a1;
v2 = (unsigned int)(int)(float)(1.0 / a2);
v3 = 1000000.0 / a2;
if ( v3 >= 9.223372e18 )
v4 = (unsigned int)(int)(float)(v3 - 9.223372e18) ^ 0x8000000000000000LL;
else
v4 = (unsigned int)(int)v3;
v6.it_interval.tv_sec = v2;
v6.it_interval.tv_usec = v4 % 0xF4240;
v6.it_value.tv_sec = v2;
v6.it_value.tv_usec = v4 % 0xF4240;
signal(14, (__sighandler_t)alarm_handler);
setitimer(ITIMER_REAL, &v6, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 (*a1)(void), float a2)
{
__time_t v2; // rsi
float v3; // xmm0_4
unsigned __int64 v4; // rcx
struct itimerval v6; // [rsp+0h] [rbp-28h] BYREF

timer_callback = a1;
v2 = (unsigned int)(int)(float)(1.0 / a2);
v3 = 1000000.0 / a2;
if ( v3 >= 9.223372e18 )
v4 = (unsigned int)(int)(float)(v3 - 9.223372e18) ^ 0x8000000000000000LL;
else
v4 = (unsigned int)(int)v3;
v6.it_interval.tv_sec = v2;
v6.it_interval.tv_usec = v4 % 0xF4240;
v6.it_value.tv_sec = v2;
v6.it_value.tv_usec = v4 % 0xF4240;
signal(14, (__sighandler_t)alarm_handler);
setitimer(ITIMER_REAL, &v6, 0LL);
return 0LL;
}

original_code:
int setup_timer(float freq, void (*callback)(void))
{
 struct itimerval time_setting;
 struct timeval wait_time;
 timer_callback=callback;
 wait_time.tv_sec=1/freq;
 wait_time.tv_usec=(unsigned long int)(1000000/freq)%1000000;
 time_setting.it_interval=wait_time;
 time_setting.it_value=wait_time;
 signal(14, alarm_handler);
 setitimer(ITIMER_REAL, &time_setting, ((void *)0));
 return 0;
}

canonical_original_code:
int setup_timer(float freq, void (*callback)())
{
 struct itimerval time_setting;
 struct timeval wait_time;
 timer_callback=callback;
 wait_time.tv_sec=1/freq;
 wait_time.tv_usec=(unsigned long)(1000000/freq)%1000000;
 time_setting.it_interval=wait_time;
 time_setting.it_value=wait_time;
 signal(14, alarm_handler);
 setitimer(ITIMER_REAL, &time_setting, ((void *)0));
 return 0;
}

variable_types: freq float

variable_types:
callback
void (*)()

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
int __fastcall arch_create_pipe(int *a1)
{
return pipe(a1);
}

canonical_decompiled_code:
int __fastcall func2(int *a1)
{
return pipe(a1);
}

original_code:
int arch_create_pipe(int pipefd[2])
{
 return(pipe(pipefd));
}

variable_types:
pipefd
int [2]


canonical_decompiled_code:
void func0()
{
timer_callback();
}

original_code:
static void alarm_handler()
{
 timer_callback();
}


handler

decompiled_code:
ssize_t handler()
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 120;
return write(*(&pipefd + 1), buf, 1uLL);
}

canonical_decompiled_code:
ssize_t func0()
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 120;
return write(*(&pipefd + 1), buf, 1uLL);
}

original_code:
static void handler(void)
{
 char data='x';
 write(pipefd[1], &data, sizeof(data));
}

canonical_original_code:
static void handler()
{
 char data = 'x';
 write(pipefd[1], &data, sizeof(data));
}

variable_types: data char


decompiled_code:
__int64 __fastcall set_timer(__int64 (*a1)(void), float a2)
{
if ( (unsigned int)arch_create_pipe(&pipefd) )
{
puts("cannot create pipe");
exit(1);
}
read_end = g_io_channel_unix_new((unsigned int)pipefd);
g_io_channel_set_encoding(read_end, 0LL, 0LL);
g_io_channel_set_buffered(read_end, 0LL);
g_io_add_watch(read_end, 1LL, watch, 0LL);
setup_timer(handler, a2);
user_func = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 (*a1)(void), float a2)
{
if ( (unsigned int)arch_create_pipe(&pipefd) )
{
puts("cannot create pipe");
exit(1);
}
read_end = g_io_channel_unix_new((unsigned int)pipefd);
g_io_channel_set_encoding(read_end, 0LL, 0LL);
g_io_channel_set_buffered(read_end, 0LL);
g_io_add_watch(read_end, 1LL, watch, 0LL);
setup_timer(handler, a2);
user_func = a1;
return 0LL;
}

original_code:
int set_timer(float freq, void (*callback)(void))
{
 if (arch_create_pipe(pipefd)){
  printf("cannot create pipe\n");
  exit (1);
 }
 read_end=g_io_channel_unix_new(pipefd[0]);
 g_io_channel_set_encoding(read_end, ((void *)0), ((void *)0));
 g_io_channel_set_buffered(read_end, (0));
 g_io_add_watch(read_end, G_IO_IN, watch, ((void *)0));
 setup_timer(freq, handler);
 user_func=callback;
 return 0;
}

canonical_original_code:
int set_timer(float freq, void (*callback)())
{
 if (arch_create_pipe(pipefd)){
  printf("cannot create pipe\n");
  exit (1);
 }
 read_end=g_io_channel_unix_new(pipefd[0]);
 g_io_channel_set_encoding(read_end, ((void *)0), ((void *)0));
 g_io_channel_set_buffered(read_end, (0));
 g_io_add_watch(read_end, G_IO_IN, watch, ((void *)0));
 setup_timer(freq, handler);
 user_func=callback;
 return 0;
}


configfile

decompiled_code:
__int64 configfile()
{
__int64 v1; // rax

if ( !config_file_0 )
{
v1 = g_getenv("HOME");
config_file_0 = g_build_filename(v1, ".emux51", "emuxrc", 0LL);
printf("[emux51]\tconfig: %s\n", (const char *)config_file_0);
}
return config_file_0;
}

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

if ( !config_file_0 )
{
v1 = g_getenv("HOME");
config_file_0 = g_build_filename(v1, ".emux51", "emuxrc", 0LL);
printf("[emux51]\tconfig: %s\n", (const char *)config_file_0);
}
return config_file_0;
}

original_code:
char *configfile(void)
{
 static char *config_file=((void *)0);
 if (config_file == ((void *)0)) {
  config_file=g_build_filename(g_getenv("HOME"),
      ".emux51", "emuxrc", ((void *)0));
  printf("[emux51]\tconfig: %s\n", config_file);
 }
 return config_file;
}

canonical_original_code:
char *configfile()
{
 static char *config_file = ((void *)0);
 if (config_file == ((void *)0)) {
  config_file=g_build_filename(g_getenv("HOME"),
      ".emux51", "emuxrc", ((void *)0));
  printf("[emux51]\tconfig: %s\n", config_file);
 }
 return config_file;
}


decompiled_code:
__int64 __fastcall crypt_same(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = 0LL;
while ( *(_BYTE *)(a1 + v2) == *(_BYTE *)(a2 + v2) )
{
if ( ++v2 == 13 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool crypt_same(const char *c1, const char *c2)
{
 int i;
 for (i=0; i<13; i++) {
  if (c1[i] != c2[i])
   return 0;
 }
 return 1;
}

canonical_original_code:
_Bool crypt_same(char *c1, char *c2)
{
 int i;
 for (i=0; i<13; i++) {
  if (c1[i] != c2[i])
   return 0;
 }
 return 1;
}


decompiled_code:
int __fastcall crypt_print(const char *a1, const char *a2)
{
char *v2; // rbx
__int64 v3; // rbp
int result; // eax

LODWORD(v2) = (unsigned int)crypt(a1, a2);
if ( (unsigned __int8)crypt_same((int)v2, (__int64)"0xZih4QwAYny2") )
return printf("<- Awesome student ;)");
v2 = (char *)(int)v2;
v3 = (int)v2 + 13LL;
if ( (unsigned __int8)crypt_same((int)v2, (__int64)"0xsSHf1aUzaZI") )
return printf("<< °_O << this is my author!");
do
result = putchar(*v2++);
while ( v2 != (char *)v3 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, const char *a2)
{
char *v2; // rbx
__int64 v3; // rbp
int result; // eax

LODWORD(v2) = (unsigned int)crypt(a1, a2);
if ( (unsigned __int8)func7((int)v2, (__int64)"0xZih4QwAYny2") )
return printf("<- Awesome student ;)");
v2 = (char *)(int)v2;
v3 = (int)v2 + 13LL;
if ( (unsigned __int8)func7((int)v2, (__int64)"0xsSHf1aUzaZI") )
return printf("<< °_O << this is my author!");
do
result = putchar(*v2++);
while ( v2 != (char *)v3 );
return result;
}

original_code:
void crypt_print(const char *data, const char *salt)
{
 char *s;
 s = crypt(data, salt);
 if (crypt_same(s, "0xZih4QwAYny2")) {
  printf("<- Awesome student ;)");
  return;
 }
 if (crypt_same(s, "0xsSHf1aUzaZI")) {
  printf("<< °_O << this is my author!");
  return;
 }
 int i;
 for (i=0; i<13; i++) {
  putchar(s[i]);
 }
}

canonical_original_code:
void crypt_print(char *data, char *salt)
{
 char *s;
 s = crypt(data, salt);
 if (crypt_same(s, "0xZih4QwAYny2")) {
  printf("<- Awesome student ;)");
  return;
 }
 if (crypt_same(s, "0xsSHf1aUzaZI")) {
  printf("<< °_O << this is my author!");
  return;
 }
 int i;
 for (i=0; i<13; i++) {
  putchar(s[i]);
 }
}

variable_types:
data
char *

variable_types:
salt
char *

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
list_dir(".");
else
list_dir(argv[1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
func9(".");
else
func9(argv[1]);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if (argc > 1)
  list_dir(argv[1]);
 else
  list_dir(".");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall my_bsearch_internal(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
int v6; // er14
unsigned int v7; // ebx
unsigned int *v8; // r15
signed int v9; // eax

v6 = a3 - a2;
v7 = a2 + (int)(a3 - a2) / 2;
v8 = (unsigned int *)(a1 + 4LL * (int)v7);
printf("trying %3d == %3d at [%3d] --- [%3d] --- [%3d]\n", a4, *v8, a2, v7, a3);
v9 = *v8;
if ( *v8 == a4 )
{
puts("found");
}
else if ( v6 <= 0 )
{
puts("not found");
v7 = -1;
}
else if ( v9 > (int)a4 )
{
puts("left");
v7 = my_bsearch_internal(a1, a2, v7 - 1, a4);
}
else if ( v9 >= (int)a4 )
{
puts("some bug");
v7 = -1;
}
else
{
puts("right");
v7 = my_bsearch_internal(a1, v7 + 1, a3, a4);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
int v6; // er14
unsigned int v7; // ebx
unsigned int *v8; // r15
signed int v9; // eax

v6 = a3 - a2;
v7 = a2 + (int)(a3 - a2) / 2;
v8 = (unsigned int *)(a1 + 4LL * (int)v7);
printf("trying %3d == %3d at [%3d] --- [%3d] --- [%3d]\n", a4, *v8, a2, v7, a3);
v9 = *v8;
if ( *v8 == a4 )
{
puts("found");
}
else if ( v6 <= 0 )
{
puts("not found");
v7 = -1;
}
else if ( v9 > (int)a4 )
{
puts("left");
v7 = func7(a1, a2, v7 - 1, a4);
}
else if ( v9 >= (int)a4 )
{
puts("some bug");
v7 = -1;
}
else
{
puts("right");
v7 = func7(a1, v7 + 1, a3, a4);
}
return v7;
}

original_code:
int my_bsearch_internal(int *arr, int lbound, int rbound, int value)
{
 int idx;
 idx = lbound + (rbound - lbound)/2;
 printf("trying %3d == %3d at [%3d] --- [%3d] --- [%3d]\n",
   value, arr[idx], lbound, idx, rbound);
 if (arr[idx] == value) {
  printf("found\n");
  return idx;
 }
 if (rbound - lbound < 1) {
  printf("not found\n");
  return -1;
 }
 if (arr[idx] > value) {
  printf("left\n");
  return my_bsearch_internal(arr, lbound, idx-1, value);
 }
 if (arr[idx] < value) {
  printf("right\n");
  return my_bsearch_internal(arr, idx + 1, rbound, value);
 }
 printf("some bug\n");
 return -1;
}

variable_types:
arr
int *

variable_types: lbound int

variable_types: rbound int

variable_types: value int

variable_types: idx int


decompiled_code:
__int64 __fastcall my_bsearch(__int64 a1, int a2, unsigned int a3)
{
return my_bsearch_internal(a1, 0, a2 - 1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, unsigned int a3)
{
return func7(a1, 0, a2 - 1, a3);
}

original_code:
int my_bsearch(int *arr, int size, int value)
{
 return my_bsearch_internal(arr, 0, size-1, value);
}

variable_types: size int


decompiled_code:
int __fastcall arr_print(__int64 a1, int a2)
{
__int64 i; // rbx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
result = printf("[%3d] %d\n", (unsigned int)i, *(unsigned int *)(a1 + 4 * i));
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, int a2)
{
__int64 i; // rbx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
result = printf("[%3d] %d\n", (unsigned int)i, *(unsigned int *)(a1 + 4 * i));
}
return result;
}

original_code:
void arr_print(int *arr, int sz)
{
 int i;
 for (i=0; i<sz; i++) {
  printf("[%3d] %d\n", i, arr[i]);
 }
}

variable_types: sz int

variable_types: i int


decompiled_code:
__int64 __fastcall my_bsearch_norecursive(__int64 a1, int a2, signed int a3)
{
unsigned int v4; // er14
unsigned int v5; // er12
unsigned int v6; // ebx
unsigned int *v7; // rbp

v4 = a2 - 1;
v5 = 0;
while ( 1 )
{
v6 = v5 + (int)(v4 - v5) / 2;
puts("================================");
v7 = (unsigned int *)(a1 + 4LL * (int)v6);
printf(" %d ?= %d\n", *v7, (unsigned int)a3);
printf(" %4d ----- %4d ----- %4d \n", v5, v6, v4);
printf(
"[%4d] ----- [%4d] ----- [%4d]\n",
*(unsigned int *)(a1 + 4LL * (int)v5),
*v7,
*(unsigned int *)(a1 + 4LL * (int)v4));
if ( *v7 == a3 )
{
puts("found");
return v6;
}
if ( (int)(v4 - v5) <= 0 )
break;
if ( (int)*v7 < a3 )
{
puts("too small. going right");
v5 = v6 + 1;
}
if ( (int)*v7 > a3 )
{
puts("too big. going left");
v4 = v6 - 1;
}
}
printf("not found, r: %d, l: %d\n", v4, v5);
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, signed int a3)
{
unsigned int v4; // er14
unsigned int v5; // er12
unsigned int v6; // ebx
unsigned int *v7; // rbp

v4 = a2 - 1;
v5 = 0;
while ( 1 )
{
v6 = v5 + (int)(v4 - v5) / 2;
puts("================================");
v7 = (unsigned int *)(a1 + 4LL * (int)v6);
printf(" %d ?= %d\n", *v7, (unsigned int)a3);
printf(" %4d ----- %4d ----- %4d \n", v5, v6, v4);
printf(
"[%4d] ----- [%4d] ----- [%4d]\n",
*(unsigned int *)(a1 + 4LL * (int)v5),
*v7,
*(unsigned int *)(a1 + 4LL * (int)v4));
if ( *v7 == a3 )
{
puts("found");
return v6;
}
if ( (int)(v4 - v5) <= 0 )
break;
if ( (int)*v7 < a3 )
{
puts("too small. going right");
v5 = v6 + 1;
}
if ( (int)*v7 > a3 )
{
puts("too big. going left");
v4 = v6 - 1;
}
}
printf("not found, r: %d, l: %d\n", v4, v5);
return (unsigned int)-1;
}

original_code:
int my_bsearch_norecursive(int *arr, int size, int value)
{
 int l,r;
 int idx;
 l = 0;
 r = size - 1;
 while (1) {
  idx = l + (r - l)/2;
  printf("================================\n");
  printf(" %d ?= %d\n", arr[idx], value);
  printf(" %4d  -----  %4d  -----  %4d \n", l, idx, r);
  printf("[%4d] ----- [%4d] ----- [%4d]\n",
    arr[l], arr[idx], arr[r]);
  if (arr[idx] == value) {
   printf("found\n");
   return idx;
  }
  if (r - l < 1) {
   printf("not found, r: %d, l: %d\n", r, l);
   return -1;
  }
  if (arr[idx] < value) {
   printf("too small. going right\n");
   l = idx + 1;
  }
  if (arr[idx] > value) {
   printf("too big. going left\n");
   r = idx - 1;
  }
 }
 return -1;
}

canonical_original_code:
int my_bsearch_norecursive(int *arr, int size, int value)
{
 int l; int r;
 int idx;
 l = 0;
 r = size - 1;
 while (1) {
  idx = l + (r - l)/2;
  printf("================================\n");
  printf(" %d ?= %d\n", arr[idx], value);
  printf(" %4d  -----  %4d  -----  %4d \n", l, idx, r);
  printf("[%4d] ----- [%4d] ----- [%4d]\n",
    arr[l], arr[idx], arr[r]);
  if (arr[idx] == value) {
   printf("found\n");
   return idx;
  }
  if (r - l < 1) {
   printf("not found, r: %d, l: %d\n", r, l);
   return -1;
  }
  if (arr[idx] < value) {
   printf("too small. going right\n");
   l = idx + 1;
  }
  if (arr[idx] > value) {
   printf("too big. going left\n");
   r = idx - 1;
  }
 }
 return -1;
}

variable_types: l int

variable_types: r int


decompiled_code:
__int64 __fastcall my_lsearch(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
unsigned int v4; // ecx

if ( a2 <= 0 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( *(_DWORD *)(a1 + 4 * v3) == a3 )
break;
if ( ++v3 == a2 )
return (unsigned int)-1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
unsigned int v4; // ecx

if ( a2 <= 0 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( *(_DWORD *)(a1 + 4 * v3) == a3 )
break;
if ( ++v3 == a2 )
return (unsigned int)-1;
}
return v4;
}

original_code:
int my_lsearch(int *arr, int size, int value)
{
 int i;
 for (i=0; i<size; i++)
  if (arr[i] == value)
   return i;
 return -1;
}


decompiled_code:
__int64 __fastcall test_search(__int64 a1, int a2, unsigned int a3)
{
int v4; // er13
__int64 result; // rax

v4 = my_lsearch(a1, a2, a3);
if ( v4 == (unsigned int)my_bsearch(a1, a2, a3) )
{
puts("ok");
result = 1LL;
}
else
{
puts("missmatch");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, unsigned int a3)
{
int v4; // er13
__int64 result; // rax

v4 = func11(a1, a2, a3);
if ( v4 == (unsigned int)func8(a1, a2, a3) )
{
puts("ok");
result = 1LL;
}
else
{
puts("missmatch");
result = 0LL;
}
return result;
}

original_code:
int test_search(int *arr, int size, int value)
{
 int a, b;
 a = my_lsearch(arr, size, value);
 b = my_bsearch(arr, size, value);
 if (a == b) {
  printf("ok\n");
  return 1;
 } else {
  printf("missmatch\n");
  return 0;
 }
}

canonical_original_code:
int test_search(int *arr, int size, int value)
{
 int a; int b;
 a = my_lsearch(arr, size, value);
 b = my_bsearch(arr, size, value);
 if (a == b) {
  printf("ok\n");
  return 1;
 } else {
  printf("missmatch\n");
  return 0;
 }
}

variable_types: a int

variable_types: b int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 *v4; // rbx
int v5; // er12
int v6; // eax
int v7; // edx
int result; // eax
_BYTE v9[3]; // [rsp+0h] [rbp-1C0h] BYREF
char v10; // [rsp+3h] [rbp-1BDh] BYREF
__int64 v11; // [rsp+190h] [rbp-30h] BYREF

v3 = time(0LL);
srand(v3);
v4 = (__int64 *)v9;
v5 = 0;
do
{
v5 += rand() % 10;
*(_DWORD *)v4 = v5;
v4 = (__int64 *)((char *)v4 + 4);
}
while ( v4 != &v11 );
v6 = rand();
v7 = test_search((__int64)v9, 100, v6 % (*(_DWORD *)(4 * ((unsigned __int64)&v10 >> 2) + 0x18C) + 1));
result = 0;
if ( !v7 )
{
arr_print((__int64)v9, 100);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 *v4; // rbx
int v5; // er12
int v6; // eax
int v7; // edx
int result; // eax
_BYTE v9[3]; // [rsp+0h] [rbp-1C0h] BYREF
char v10; // [rsp+3h] [rbp-1BDh] BYREF
__int64 v11; // [rsp+190h] [rbp-30h] BYREF

v3 = time(0LL);
srand(v3);
v4 = (__int64 *)v9;
v5 = 0;
do
{
v5 += rand() % 10;
*(_DWORD *)v4 = v5;
v4 = (__int64 *)((char *)v4 + 4);
}
while ( v4 != &v11 );
v6 = rand();
v7 = func12((__int64)v9, 100, v6 % (*(_DWORD *)(4 * ((unsigned __int64)&v10 >> 2) + 0x18C) + 1));
result = 0;
if ( !v7 )
{
func9((__int64)v9, 100);
result = 1;
}
return result;
}

original_code:
int main(void)
{
 const int sz = 100;
 int i;
 int arr[sz];
 int last = 0;
 srand(time(((void *)0)));
 for (i=0; i<sz; i++) {
  arr[i] = last + rand()%10;
  last = arr[i];
 }
 i = test_search(arr, sz, rand() % (arr[sz - 1] + 1));
 if (i == 0) {
  arr_print(arr, sz);
  return 1;
 }
 return 0;
}

canonical_original_code:
int main()
{
 int sz = 100;
 int i;
 int arr[-1];
 int last = 0;
 srand(time(((void *)0)));
 for (i=0; i<sz; i++) {
  arr[i] = last + rand()%10;
  last = arr[i];
 }
 i = test_search(arr, sz, rand() % (arr[sz - 1] + 1));
 if (i == 0) {
  arr_print(arr, sz);
  return 1;
 }
 return 0;
}

variable_types:
arr
int [-1]

variable_types: last int


decompiled_code:
void __noreturn signal_handler()
{
puts("\n");
tcsetattr(ser_port, 0, &ser_port_old_cfg);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("\n");
tcsetattr(ser_port, 0, &ser_port_old_cfg);
exit(0);
}

original_code:
void signal_handler(int signal)
{
 printf("\n\n");
 tcsetattr (ser_port, 0, &ser_port_old_cfg);
 exit(0);
}

variable_types: signal int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
char *v5; // rdx
char v6; // al
char v7[256]; // [rsp+0h] [rbp-188h] BYREF
struct termios termios_p; // [rsp+100h] [rbp-88h] BYREF
struct termios s; // [rsp+140h] [rbp-48h] BYREF

system("clear");
v3 = argv[1];
if ( !v3 )
v3 = "/dev/ttyUSB0";
v4 = open(v3, 258);
ser_port = v4;
if ( v4 != -1 )
{
tcgetattr(v4, &termios_p);
__sysv_signal(2, (__sighandler_t)signal_handler);
__sysv_signal(15, (__sighandler_t)signal_handler);
bzero(&s, 0x3CuLL);
s.c_cflag = 2237;
s.c_iflag = 4;
s.c_oflag = 0;
s.c_lflag = 0;
s.c_cc[5] = 0;
s.c_cc[6] = 5;
tcflush(ser_port, 2);
tcsetattr(ser_port, 0, &s);
puts("\n --== Serial Port Thermometer ==-- press CTRL+C to exit\n");
while ( 1 )
{
write(ser_port, "#", 1uLL);
sleep(1u);
v7[(int)read(ser_port, v7, 0xFFuLL)] = 0;
v6 = v7[0];
if ( v7[0] )
{
v5 = v7;
do
{
if ( v6 == -8 )
*v5 = -80;
v6 = *++v5;
}
while ( *v5 );
}
printf("%s", v7);
fflush(_bss_start);
}
}
perror(v3);
exit(-1);
}

original_code:
int main(int argc, char* argv[])
{
 struct termios ser_port_cfg,
   ser_port_old_cfg;
 char *ser_port_name = "/dev/ttyUSB0",
  readbuffer[256],
  *p;
 int readsize;
 system("clear");
 if(argv[1])
  ser_port_name = argv[1];
 ser_port = open(ser_port_name, 02 | 0400);
 if(ser_port == -1)
 {
  perror(ser_port_name);
  exit(-1);
 }
 tcgetattr(ser_port, &ser_port_old_cfg);
 signal(2, signal_handler);
 signal(15, signal_handler);
 bzero(&ser_port_cfg, sizeof(ser_port_cfg));
 ser_port_cfg.c_cflag = 0000015 | 0000060 | 0004000 | 0000200;
 ser_port_cfg.c_iflag = 0000004;
 ser_port_cfg.c_oflag = 0;
 ser_port_cfg.c_lflag = 0;
 ser_port_cfg.c_cc[5] = 0;
 ser_port_cfg.c_cc[6] = 5;
 tcflush(ser_port, 2);
 tcsetattr(ser_port, 0, &ser_port_cfg);
 printf("\n      --== Serial Port Thermometer ==-- press CTRL+C to exit\n\n");
 do
 {
  write(ser_port, "#", 1);
  sleep(1);
  readsize = read(ser_port, readbuffer, 255);
  readbuffer[readsize]=0;
  p = readbuffer;
  while(*p)
  {
   if((unsigned char)*p == 0xF8)
    *p = 0xB0;
   p++;
  }
  printf("%s", readbuffer);
  fflush(stdout);
 } while(1);
 tcsetattr(ser_port, 0, &ser_port_old_cfg);
 close(ser_port);
 return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct termios ser_port_cfg; struct termios ser_port_old_cfg;
 char *ser_port_name = "/dev/ttyUSB0"; char readbuffer[256]; char *p;
 int readsize;
 system("clear");
 if(argv[1])
  ser_port_name = argv[1];
 ser_port = open(ser_port_name, 02 | 0400);
 if(ser_port == -1)
 {
  perror(ser_port_name);
  exit(-1);
 }
 tcgetattr(ser_port, &ser_port_old_cfg);
 signal(2, signal_handler);
 signal(15, signal_handler);
 bzero(&ser_port_cfg, sizeof(ser_port_cfg));
 ser_port_cfg.c_cflag = 0000015 | 0000060 | 0004000 | 0000200;
 ser_port_cfg.c_iflag = 0000004;
 ser_port_cfg.c_oflag = 0;
 ser_port_cfg.c_lflag = 0;
 ser_port_cfg.c_cc[5] = 0;
 ser_port_cfg.c_cc[6] = 5;
 tcflush(ser_port, 2);
 tcsetattr(ser_port, 0, &ser_port_cfg);
 printf("\n      --== Serial Port Thermometer ==-- press CTRL+C to exit\n\n");
 do
 {
  write(ser_port, "#", 1);
  sleep(1);
  readsize = read(ser_port, readbuffer, 255);
  readbuffer[readsize]=0;
  p = readbuffer;
  while(*p)
  {
   if((unsigned char)*p == 0xF8)
    *p = 0xB0;
   p++;
  }
  printf("%s", readbuffer);
  fflush(stdout);
 } while(1);
 tcsetattr(ser_port, 0, &ser_port_old_cfg);
 close(ser_port);
 return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types:
readbuffer
char [256]

variable_types:
p
char *

variable_types: readsize int


decompiled_code:
int __fastcall show_modem_signals(__int16 a1)
{
printf("RTS %c ", (unsigned int)((a1 & 4) != 0) + 48);
printf("CTS %c ", (unsigned int)((a1 & 0x20) != 0) + 48);
printf("DTR %c ", (unsigned int)((a1 & 2) != 0) + 48);
printf("DSR %c ", (unsigned int)((a1 & 0x100) != 0) + 48);
printf("CD %c ", (unsigned int)((a1 & 0x40) != 0) + 48);
printf("RI %c \r", (unsigned int)((unsigned __int8)a1 >> 7) + 48);
return fflush(_bss_start);
}

canonical_decompiled_code:
int __fastcall func7(__int16 a1)
{
printf("RTS %c ", (unsigned int)((a1 & 4) != 0) + 48);
printf("CTS %c ", (unsigned int)((a1 & 0x20) != 0) + 48);
printf("DTR %c ", (unsigned int)((a1 & 2) != 0) + 48);
printf("DSR %c ", (unsigned int)((a1 & 0x100) != 0) + 48);
printf("CD %c ", (unsigned int)((a1 & 0x40) != 0) + 48);
printf("RI %c \r", (unsigned int)((unsigned __int8)a1 >> 7) + 48);
return fflush(_bss_start);
}

original_code:
void show_modem_signals(int flags)
{
 printf("RTS %c ", flags & 0x004 ? '1' : '0');
 printf("CTS %c ", flags & 0x020 ? '1' : '0');
 printf("DTR %c ", flags & 0x002 ? '1' : '0');
 printf("DSR %c ", flags & 0x100 ? '1' : '0');
 printf("CD %c ", flags & 0x040 ? '1' : '0');
 printf("RI %c \r", flags & 0x080 ? '1' : '0');
 fflush(stdout);
}

variable_types: flags int