decompiled_code:
__int64 __fastcall io_open(char *filename, char *a2)
{
char *v3; // rax
char *v4; // rax

if ( !strcmp("-", filename) )
{
in = stdin;
}
else
{
in = fopen(filename, "rb");
if ( !in )
{
v3 = dcgettext(0LL, "IO : can't open input file", 5);
err_include(4LL, v3, 0LL, 0LL, 0LL);
return 0xFFFFFFFFLL;
}
}
out = fopen(a2, "wb");
if ( out )
return 0LL;
v4 = dcgettext(0LL, "IO : can't open output file", 5);
err_include(4LL, v4, 0LL, 0LL, 0LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *filename, char *a2)
{
char *v3; // rax
char *v4; // rax

if ( !strcmp("-", filename) )
{
in = stdin;
}
else
{
in = fopen(filename, "rb");
if ( !in )
{
v3 = dcgettext(0LL, "IO : can't open input file", 5);
err_include(4LL, v3, 0LL, 0LL, 0LL);
return 0xFFFFFFFFLL;
}
}
out = fopen(a2, "wb");
if ( out )
return 0LL;
v4 = dcgettext(0LL, "IO : can't open output file", 5);
err_include(4LL, v4, 0LL, 0LL, 0LL);
return 0xFFFFFFFFLL;
}

original_code:
int io_open(const char *fname_in, const char *fname_out)
{
 if(!strncmp("-", fname_in, 4))
  in = stdin;
 else
 {
  in = fopen(fname_in, "rb");
  if(!in)
  {
   err_include(EFATAL, gettext("IO : can't open input file"), 0, 0, 0);
   return -1;
  }
 }
 out = fopen(fname_out, "wb");
 if(!out)
 {
  err_include(EFATAL, gettext("IO : can't open output file"), 0, 0, 0);
  return -1;
 }
 return 0;
}

canonical_original_code:
int io_open(char *fname_in, char *fname_out)
{
 if(!strncmp("-", fname_in, 4))
  in = stdin;
 else
 {
  in = fopen(fname_in, "rb");
  if(!in)
  {
   err_include(EFATAL, gettext("IO : can't open input file"), 0, 0, 0);
   return -1;
  }
 }
 out = fopen(fname_out, "wb");
 if(!out)
 {
  err_include(EFATAL, gettext("IO : can't open output file"), 0, 0, 0);
  return -1;
 }
 return 0;
}


decompiled_code:
int io_close()
{
err_rest();
fclose(in);
return fclose(out);
}

canonical_decompiled_code:
int func1()
{
err_rest();
fclose(in);
return fclose(out);
}

original_code:
void io_close(void)
{
    err_rest();
 fclose(in);
 fclose(out);
}

canonical_original_code:
void io_close()
{
    err_rest();
 fclose(in);
 fclose(out);
}

return_type: void


decompiled_code:
__int64 io_next_c()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx

v0 = io_ungetc_pos;
if ( io_ungetc_pos >= 0 )
{
if ( io_c == 1 )
--io_line;
else
--io_c;
--io_ungetc_pos;
v2 = (unsigned __int8)io_ungetc_buf[v0];
}
else
{
if ( io_bufpos > 1023 )
{
io_buflen = fread(io_buff, 1uLL, 0x400uLL, in);
io_bufpos = 0;
}
v1 = io_bufpos;
if ( io_bufpos >= io_buflen )
{
err_line((unsigned int)io_line);
v2 = -1;
}
else
{
++io_bufpos;
v2 = (unsigned __int8)io_buff[v1];
if ( io_c == 1 )
{
err_line((unsigned int)(io_line - 1));
fwrite(" ", 1uLL, 6uLL, stderr);
}
fputc((char)v2, stderr);
if ( (_BYTE)v2 == 10 )
{
++io_line;
io_c = 1;
}
else
{
++io_c;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx

v0 = io_ungetc_pos;
if ( io_ungetc_pos >= 0 )
{
if ( io_c == 1 )
--io_line;
else
--io_c;
--io_ungetc_pos;
v2 = (unsigned __int8)io_ungetc_buf[v0];
}
else
{
if ( io_bufpos > 1023 )
{
io_buflen = fread(io_buff, 1uLL, 0x400uLL, in);
io_bufpos = 0;
}
v1 = io_bufpos;
if ( io_bufpos >= io_buflen )
{
err_line((unsigned int)io_line);
v2 = -1;
}
else
{
++io_bufpos;
v2 = (unsigned __int8)io_buff[v1];
if ( io_c == 1 )
{
err_line((unsigned int)(io_line - 1));
fwrite(" ", 1uLL, 6uLL, stderr);
}
fputc((char)v2, stderr);
if ( (_BYTE)v2 == 10 )
{
++io_line;
io_c = 1;
}
else
{
++io_c;
}
}
}
return v2;
}

original_code:
char io_next_c(void)
{
 char r = -1;
 if (io_ungetc_pos >= 0)
 {
        io_c--;
        if (io_c == 0)
        {
            io_c = 1;
            io_line--;
        }
        return io_ungetc_buf[io_ungetc_pos--];
 }
 if(io_bufpos >= 1024)
 {
  io_buflen = fread(io_buff, 1, 1024, in);
  io_bufpos = 0;
 }
 if(io_bufpos >= io_buflen)
 {
  r = (-1);
  err_line(io_line);
 } else {
  r = io_buff[io_bufpos++];
        if (io_c == 1)
        {
   err_line(io_line-1);
            fprintf(stderr, "      ");
        }
  fputc(r, stderr);
  if(r == '\n')
  {
   io_line++;
   io_c = 1;
  } else {
   io_c++;
  }
 }
 return r;
}

canonical_original_code:
char io_next_c()
{
 char r = -1;
 if (io_ungetc_pos >= 0)
 {
        io_c--;
        if (io_c == 0)
        {
            io_c = 1;
            io_line--;
        }
        return io_ungetc_buf[io_ungetc_pos--];
 }
 if(io_bufpos >= 1024)
 {
  io_buflen = fread(io_buff, 1, 1024, in);
  io_bufpos = 0;
 }
 if(io_bufpos >= io_buflen)
 {
  r = (-1);
  err_line(io_line);
 } else {
  r = io_buff[io_bufpos++];
        if (io_c == 1)
        {
   err_line(io_line-1);
            fprintf(stderr, "      ");
        }
  fputc(r, stderr);
  if(r == '\n')
  {
   io_line++;
   io_c = 1;
  } else {
   io_c++;
  }
 }
 return r;
}

variable_types: r char

return_type: char


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

result = (unsigned int)io_ungetc_pos;
if ( io_ungetc_pos <= 1023 )
{
++io_ungetc_pos;
result = (int)result + 1;
io_ungetc_buf[result] = a1;
}
return result;
}

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

result = (unsigned int)io_ungetc_pos;
if ( io_ungetc_pos <= 1023 )
{
++io_ungetc_pos;
result = (int)result + 1;
io_ungetc_buf[result] = a1;
}
return result;
}

original_code:
void io_ungetc(char c)
{
    if(io_ungetc_pos < 1024)
    {
        io_ungetc_buf[++io_ungetc_pos] = c;
    }
}

variable_types: c char


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

va_start(arg, format);
return vfprintf(out, format, arg);
}

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

va_start(arg, format);
return vfprintf(out, format, arg);
}

original_code:
void io_printf(const char *fmt, ...)
{
  va_list args;
  __builtin_va_start(args,fmt);
  vfprintf(out, fmt, args);
  __builtin_va_end(args);
}

canonical_original_code:
void io_printf(char *fmt, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  vfprintf(out, fmt, args);
  __builtin_va_end(args);
}

variable_types:
fmt
char *


decompiled_code:
__int64 sem_init()
{
type_init();
return id_init();
}

canonical_decompiled_code:
__int64 func0()
{
type_init();
return id_init();
}

original_code:
void sem_init(void)
{
    type_init();
    id_init();
}

canonical_original_code:
void sem_init()
{
    type_init();
    id_init();
}


decompiled_code:
int __fastcall err_one(__int64 a1)
{
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // eax
char *v5; // rax
char *v6; // rax
char *v7; // rax
__int64 v8; // rdx
const char *v9; // rdx
char *v11; // rax
char *v12; // rax

v1 = 6;
do
{
fputc(42, stderr);
--v1;
}
while ( v1 );
if ( *(int *)(a1 + 28) > 1 )
{
v2 = 1;
do
{
fputc(32, stderr);
++v2;
}
while ( *(_DWORD *)(a1 + 28) > v2 );
}
fputc(94, stderr);
fputc(10, stderr);
v3 = 6;
do
{
fputc(42, stderr);
--v3;
}
while ( v3 );
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 3 )
{
v11 = dcgettext(0LL, "[Error] : ", 5);
fprintf(stderr, v11);
}
else
{
if ( v4 > 3 )
{
if ( v4 == 4 )
{
v6 = dcgettext(0LL, "[Fatal] : ", 5);
fprintf(stderr, v6);
goto LABEL_16;
}
}
else
{
if ( v4 == 1 )
{
v7 = dcgettext(0LL, "[Note ] : ", 5);
fprintf(stderr, v7);
goto LABEL_16;
}
if ( v4 == 2 )
{
v5 = dcgettext(0LL, "[Warn ] : ", 5);
fprintf(stderr, v5);
goto LABEL_16;
}
}
v12 = dcgettext(0LL, "[Unkn ] : ", 5);
fprintf(stderr, v12);
}
LABEL_16:
v8 = *(unsigned int *)(a1 + 24);
if ( (_DWORD)v8 )
fprintf(stderr, "%d,%d : ", v8, *(unsigned int *)(a1 + 28));
fputs(*(const char **)(a1 + 8), stderr);
v9 = *(const char **)(a1 + 16);
if ( v9 )
fprintf(stderr, " %s ", v9);
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // eax
char *v5; // rax
char *v6; // rax
char *v7; // rax
__int64 v8; // rdx
const char *v9; // rdx
char *v11; // rax
char *v12; // rax

v1 = 6;
do
{
fputc(42, stderr);
--v1;
}
while ( v1 );
if ( *(int *)(a1 + 28) > 1 )
{
v2 = 1;
do
{
fputc(32, stderr);
++v2;
}
while ( *(_DWORD *)(a1 + 28) > v2 );
}
fputc(94, stderr);
fputc(10, stderr);
v3 = 6;
do
{
fputc(42, stderr);
--v3;
}
while ( v3 );
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 3 )
{
v11 = dcgettext(0LL, "[Error] : ", 5);
fprintf(stderr, v11);
}
else
{
if ( v4 > 3 )
{
if ( v4 == 4 )
{
v6 = dcgettext(0LL, "[Fatal] : ", 5);
fprintf(stderr, v6);
goto LABEL_16;
}
}
else
{
if ( v4 == 1 )
{
v7 = dcgettext(0LL, "[Note ] : ", 5);
fprintf(stderr, v7);
goto LABEL_16;
}
if ( v4 == 2 )
{
v5 = dcgettext(0LL, "[Warn ] : ", 5);
fprintf(stderr, v5);
goto LABEL_16;
}
}
v12 = dcgettext(0LL, "[Unkn ] : ", 5);
fprintf(stderr, v12);
}
LABEL_16:
v8 = *(unsigned int *)(a1 + 24);
if ( (_DWORD)v8 )
fprintf(stderr, "%d,%d : ", v8, *(unsigned int *)(a1 + 28));
fputs(*(const char **)(a1 + 8), stderr);
v9 = *(const char **)(a1 + 16);
if ( v9 )
fprintf(stderr, " %s ", v9);
return fputc(10, stderr);
}

original_code:
void err_one(error *list)
{
        int i = 0;
        for(i = 0; i < 6; i++)
            fputc('*', stderr);
  for(i = 1; i < list->c; i++)
   fputc(' ', stderr);
  fputc('^', stderr);
  fputc('\n', stderr);
  for(i = 0; i < 6; i++)
            fputc('*', stderr);
  switch (list->level)
  {
   case ENOTE:
    fprintf(stderr, gettext("[Note ] : "));
    break;
   case EWARN:
    fprintf(stderr, gettext("[Warn ] : "));
    break;
   case ERROR:
    fprintf(stderr, gettext("[Error] : "));
    break;
   case EFATAL:
    fprintf(stderr, gettext("[Fatal] : "));
    break;
   default:
    fprintf(stderr, gettext("[Unkn ] : "));
    break;
  }
  if(list -> line != 0)
  {
   fprintf(stderr, "%d,%d : ", list->line, list->c);
  }
  fprintf(stderr, "%s", list->message);
  if(list -> exmsg != 0)
  {
   fprintf(stderr, " %s ", list->exmsg);
  }
  fprintf(stderr, "\n");
}

canonical_original_code:
void err_one(struct _error *list)
{
        int i = 0;
        for(i = 0; i < 6; i++)
            fputc('*', stderr);
  for(i = 1; i < list->c; i++)
   fputc(' ', stderr);
  fputc('^', stderr);
  fputc('\n', stderr);
  for(i = 0; i < 6; i++)
            fputc('*', stderr);
  switch (list->level)
  {
   case ENOTE:
    fprintf(stderr, gettext("[Note ] : "));
    break;
   case EWARN:
    fprintf(stderr, gettext("[Warn ] : "));
    break;
   case ERROR:
    fprintf(stderr, gettext("[Error] : "));
    break;
   case EFATAL:
    fprintf(stderr, gettext("[Fatal] : "));
    break;
   default:
    fprintf(stderr, gettext("[Unkn ] : "));
    break;
  }
  if(list -> line != 0)
  {
   fprintf(stderr, "%d,%d : ", list->line, list->c);
  }
  fprintf(stderr, "%s", list->message);
  if(list -> exmsg != 0)
  {
   fprintf(stderr, " %s ", list->exmsg);
  }
  fprintf(stderr, "\n");
}

variable_types: struct _error { int level; char *message; char *exmsg; int line; int c; struct _error *next; } *

variable_types: i int


decompiled_code:
void err_print()
{
void *v0; // rbx
void *v1; // rdi

v0 = first;
while ( v0 )
{
err_one((__int64)v0);
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 4);
free(v1);
}
}

canonical_decompiled_code:
void func1()
{
void *v0; // rbx
void *v1; // rdi

v0 = first;
while ( v0 )
{
func0((__int64)v0);
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 4);
free(v1);
}
}

original_code:
void err_print(void)
{
 error *list = first;
 error *flis = first;
 while(list != 0)
 {
  err_one(list);
  list = list->next;
  free(flis);
  flis = list;
 }
}

canonical_original_code:
void err_print()
{
 struct _error *list = first;
 struct _error *flis = first;
 while(list != 0)
 {
  err_one(list);
  list = list->next;
  free(flis);
  flis = list;
 }
}

user_defined_types: struct _error { int level; char *message; char *exmsg; int line; int c; struct _error *next; }


decompiled_code:
int __fastcall err_line(int a1)
{
_QWORD *v1; // rbx
int result; // eax

v1 = first;
if ( first )
{
while ( *((_DWORD *)v1 + 6) < a1 )
{
v1 = (_QWORD *)v1[4];
if ( !v1 )
return result;
}
last_err_line = a1;
do
{
if ( *((_DWORD *)v1 + 6) != a1 )
break;
result = err_one((__int64)v1);
v1 = (_QWORD *)v1[4];
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
_QWORD *v1; // rbx
int result; // eax

v1 = first;
if ( first )
{
while ( *((_DWORD *)v1 + 6) < a1 )
{
v1 = (_QWORD *)v1[4];
if ( !v1 )
return result;
}
last_err_line = a1;
do
{
if ( *((_DWORD *)v1 + 6) != a1 )
break;
result = func0((__int64)v1);
v1 = (_QWORD *)v1[4];
}
while ( v1 );
}
return result;
}

original_code:
void err_line(int line)
{
 error *list = first;
 while((list != 0)&&(list->line < line))
        list = list->next;
    if (list != 0)
     last_err_line = line;
 while((list != 0)&&(list->line == line))
 {
        err_one(list);
  list = list->next;
 }
}

canonical_original_code:
void err_line(int line)
{
 struct _error *list = first;
 while((list != 0)&&(list->line < line))
        list = list->next;
    if (list != 0)
     last_err_line = line;
 while((list != 0)&&(list->line == line))
 {
        err_one(list);
  list = list->next;
 }
}

variable_types: line int


decompiled_code:
void err_rest()
{
_DWORD *v0; // rbx
_DWORD *v1; // rbp

v0 = first;
if ( first )
{
while ( 1 )
{
if ( v0[6] > last_err_line )
err_one((__int64)v0);
v1 = (_DWORD *)*((_QWORD *)v0 + 4);
free(v0);
if ( !v1 )
break;
v0 = v1;
}
}
}

canonical_decompiled_code:
void func3()
{
_DWORD *v0; // rbx
_DWORD *v1; // rbp

v0 = first;
if ( first )
{
while ( 1 )
{
if ( v0[6] > last_err_line )
func0((__int64)v0);
v1 = (_DWORD *)*((_QWORD *)v0 + 4);
free(v0);
if ( !v1 )
break;
v0 = v1;
}
}
}

original_code:
void err_rest()
{
 error *list = first;
 error *flis = first;
 while(list != 0)
 {
        if (list->line > last_err_line)
            err_one(list);
  list = list->next;
  free(flis);
  flis = list;
 }
}

canonical_original_code:
void err_rest()
{
 struct _error *list = first;
 struct _error *flis = first;
 while(list != 0)
 {
        if (list->line > last_err_line)
            err_one(list);
  list = list->next;
  free(flis);
  flis = list;
 }
}


decompiled_code:
__int64 add_var()
{
__int64 result; // rax
const char *v1; // rax
char *v2; // rax

result = lex_get_s();
if ( (_DWORD)result == 1000 )
{
v1 = (const char *)lex_get_v();
v2 = strdup(v1);
result = add_to_id_table(0LL, v2, 4003LL);
if ( result )
result = add_to_list(&int_var_list, result);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
const char *v1; // rax
char *v2; // rax

result = lex_get_s();
if ( (_DWORD)result == 1000 )
{
v1 = (const char *)lex_get_v();
v2 = strdup(v1);
result = add_to_id_table(0LL, v2, 4003LL);
if ( result )
result = add_to_list(&int_var_list, result);
}
return result;
}

original_code:
void add_var()
{
    if (lex_get_s() == L_IDENT)
    {
        lex_val tmp = lex_get_v();
        char *name = strdup(tmp.string);
        id_table_elem *tmp3 = add_to_id_table(0, name, UC_VAR);
        if (tmp3 != 0)
            add_to_list(&int_var_list, tmp3);
    }
}

canonical_original_code:
void add_var()
{
    if (lex_get_s() == L_IDENT)
    {
        union lex_val tmp = lex_get_v();
        char *name = strdup(tmp.string);
        struct _id_table_elem *tmp3 = add_to_id_table(0, name, UC_VAR);
        if (tmp3 != 0)
            add_to_list(&int_var_list, tmp3);
    }
}

variable_types: union lex_val { long inumber; double fnumber; char *string; char character; }

variable_types:
name
char *

variable_types: struct _id_table_elem { unsigned long hash; char *name; enum USE_CLASS { UC_PROG=4000, UC_TYPE=4001, UC_CONST=4002, UC_VAR=4003, UC_PROC=4004, UC_FUNC=4005, UC_UNK=4006 } uclass; struct _type_table_elem { enum USE_TYPE { UT_SCALAR=5000, UT_LIMITED=5001, UT_ENUM=5002, UT_ARRAY=5003, UT_RECORD=5004, UT_REFERENCE=5005, UT_SET=5006, UT_FILE=5007 } utype; struct _type_table_elem *base; union { struct _list { void *value; struct _list *next; } *constants; struct _list *indexes; struct { unsigned long min; }; }; } *type; int value; } *

user_defined_types: struct _id_table_elem { unsigned long hash; char *name; enum USE_CLASS uclass; struct _type_table_elem *type; int value; }

user_defined_types: struct _type_table_elem { enum USE_TYPE utype; struct _type_table_elem *base; union { struct _list *constants; struct _list *indexes; struct { unsigned long min; }; }; }


decompiled_code:
__int64 __fastcall int_parse_varlist(__int64 a1, struct sockaddr *a2)
{
socklen_t *v2; // rdx
socklen_t *v3; // rdx
__int64 result; // rax
socklen_t *v5; // rdx

add_var();
accept(1000, a2, v2);
while ( 1 )
{
result = lex_get_s();
if ( (_DWORD)result != 44 )
break;
accept(44, a2, v5);
add_var();
accept(1000, a2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, struct sockaddr *a2)
{
socklen_t *v2; // rdx
socklen_t *v3; // rdx
__int64 result; // rax
socklen_t *v5; // rdx

func0();
accept(1000, a2, v2);
while ( 1 )
{
result = lex_get_s();
if ( (_DWORD)result != 44 )
break;
accept(44, a2, v5);
func0();
accept(1000, a2, v3);
}
return result;
}

original_code:
void *int_parse_varlist (unsigned long *folls, unsigned long *ex)
{
    add_var();
    accept(L_IDENT);
    while(lex_get_s() == L_COMMA)
    {
        accept(L_COMMA);
        add_var();
        accept(L_IDENT);
    }
}

canonical_original_code:
void *int_parse_varlist(unsigned long *folls, unsigned long *ex)
{
    add_var();
    accept(L_IDENT);
    while(lex_get_s() == L_COMMA)
    {
        accept(L_COMMA);
        add_var();
        accept(L_IDENT);
    }
}

variable_types:
folls
unsigned long *

variable_types:
ex
unsigned long *

return_type: void *


decompiled_code:
__int64 __fastcall parse_varlist(__int64 a1, __int64 a2)
{
return parser_exec(parser_start_varlist, a1, a2, int_parse_varlist, parser_name_varlist);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return parser_exec(parser_start_varlist, a1, a2, int_parse_varlist, parser_name_varlist);
}

original_code: void *parse_varlist (unsigned long *folls, unsigned long *ex) { return parser_exec(parser_start_varlist, folls, ex, int_parse_varlist, parser_name_varlist); }

canonical_original_code: void *parse_varlist(unsigned long *folls, unsigned long *ex) { return parser_exec(parser_start_varlist, folls, ex, int_parse_varlist, parser_name_varlist); }


decompiled_code:
void __fastcall int_parse_varpack(__int64 a1)
{
void *v1; // rbx
struct sockaddr *v2; // rsi
socklen_t *v3; // rdx
__int64 v4; // rax
_QWORD *v5; // rdi
__int64 v6; // rbp
__int64 v7; // rdx
_QWORD *v8; // rbx

v1 = (void *)balloc();
bits_disjunct(a1, parser_varpack_aux2, v1);
int_var_list = 0LL;
v2 = (struct sockaddr *)parser_varpack_aux;
parse_varlist((__int64)v1, (__int64)parser_varpack_aux);
free(v1);
accept(58, v2, v3);
v4 = parse_typedefn(a1, 0LL);
v5 = (_QWORD *)int_var_list;
if ( int_var_list )
{
v6 = v4;
while ( 1 )
{
v7 = 0LL;
if ( *(_QWORD *)(*v5 + 24LL) == -1LL )
v7 = v6;
*(_QWORD *)(*v5 + 24LL) = v7;
v8 = (_QWORD *)v5[1];
free(v5);
if ( !v8 )
break;
v5 = v8;
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
void *v1; // rbx
struct sockaddr *v2; // rsi
socklen_t *v3; // rdx
__int64 v4; // rax
_QWORD *v5; // rdi
__int64 v6; // rbp
__int64 v7; // rdx
_QWORD *v8; // rbx

v1 = (void *)balloc();
bits_disjunct(a1, parser_varpack_aux2, v1);
int_var_list = 0LL;
v2 = (struct sockaddr *)parser_varpack_aux;
func2((__int64)v1, (__int64)parser_varpack_aux);
free(v1);
accept(58, v2, v3);
v4 = parse_typedefn(a1, 0LL);
v5 = (_QWORD *)int_var_list;
if ( int_var_list )
{
v6 = v4;
while ( 1 )
{
v7 = 0LL;
if ( *(_QWORD *)(*v5 + 24LL) == -1LL )
v7 = v6;
*(_QWORD *)(*v5 + 24LL) = v7;
v8 = (_QWORD *)v5[1];
free(v5);
if ( !v8 )
break;
v5 = v8;
}
}
}

original_code:
void *int_parse_varpack (unsigned long *folls, unsigned long *ex)
{
    unsigned long *tmp = balloc();
    bits_disjunct(folls, parser_varpack_aux2, tmp);
    int_var_list = 0;
    parse_varlist(tmp, parser_varpack_aux);
    free(tmp);
    accept(L_COLON);
    type_table_elem *tp = (type_table_elem *)parse_typedefn(folls, 0);
    list *t_int_var_list = int_var_list; while(t_int_var_list != 0)
    {
        id_table_elem *q = t_int_var_list->value;
        if (q->type == -1)
            q->type = tp;
        else
            q->type = 0;
        list *t2_int_var_list = t_int_var_list->next; free(t_int_var_list); t_int_var_list = t2_int_var_list;
    }
}

canonical_original_code:
void *int_parse_varpack(unsigned long *folls, unsigned long *ex)
{
    unsigned long *tmp = balloc();
    bits_disjunct(folls, parser_varpack_aux2, tmp);
    int_var_list = 0;
    parse_varlist(tmp, parser_varpack_aux);
    free(tmp);
    accept(L_COLON);
    struct _type_table_elem *tp = (type_table_elem *)parse_typedefn(folls, 0);
    struct _list *t_int_var_list = int_var_list; while(t_int_var_list != 0)
    {
        struct _id_table_elem *q = t_int_var_list->value;
        if (q->type == -1)
            q->type = tp;
        else
            q->type = 0;
        struct _list *t2_int_var_list = t_int_var_list->next; free(t_int_var_list); t_int_var_list = t2_int_var_list;
    }
}

variable_types:
tmp
unsigned long *

variable_types: struct _type_table_elem { enum USE_TYPE { UT_SCALAR=5000, UT_LIMITED=5001, UT_ENUM=5002, UT_ARRAY=5003, UT_RECORD=5004, UT_REFERENCE=5005, UT_SET=5006, UT_FILE=5007 } utype; struct _type_table_elem *base; union { struct _list { void *value; struct _list *next; } *constants; struct _list *indexes; struct { unsigned long min; }; }; } *

user_defined_types: enum USE_CLASS { UC_PROG=4000, UC_TYPE=4001, UC_CONST=4002, UC_VAR=4003, UC_PROC=4004, UC_FUNC=4005, UC_UNK=4006 }


decompiled_code:
__int64 __fastcall parse_varpack(__int64 a1, __int64 a2)
{
return parser_exec(parser_start_varpack, a1, a2, int_parse_varpack, "varpack");
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return parser_exec(parser_start_varpack, a1, a2, int_parse_varpack, "varpack");
}

original_code: void *parse_varpack (unsigned long *folls, unsigned long *ex) { return parser_exec(parser_start_varpack, folls, ex, int_parse_varpack, parser_name_varpack); }

canonical_original_code: void *parse_varpack(unsigned long *folls, unsigned long *ex) { return parser_exec(parser_start_varpack, folls, ex, int_parse_varpack, parser_name_varpack); }


decompiled_code:
__int64 init_parser_varpack()
{
parser_name_varlist = "identifier";
if ( !parser_start_varpack )
parser_start_varpack = (void *)bits_from_array(&int_start_varpack);
if ( !parser_folls_varpack )
parser_folls_varpack = (void *)bits_from_array(&int_folls_varpack);
if ( !parser_start_varlist )
parser_start_varlist = (void *)bits_from_array(&int_start_varlist);
if ( !parser_folls_varlist )
parser_folls_varlist = (void *)bits_from_array(&int_folls_varlist);
if ( !parser_varpack_aux )
parser_varpack_aux = (void *)bits_from_array(&int_varpack_aux);
if ( !parser_varpack_aux2 )
parser_varpack_aux2 = (void *)bits_from_array(&int_varpack_aux2);
return bits_disjunct(parser_varpack_aux, parser_start_typedefn, parser_varpack_aux2);
}

canonical_decompiled_code:
__int64 func5()
{
parser_name_varlist = "identifier";
if ( !parser_start_varpack )
parser_start_varpack = (void *)bits_from_array(&int_start_varpack);
if ( !parser_folls_varpack )
parser_folls_varpack = (void *)bits_from_array(&int_folls_varpack);
if ( !parser_start_varlist )
parser_start_varlist = (void *)bits_from_array(&int_start_varlist);
if ( !parser_folls_varlist )
parser_folls_varlist = (void *)bits_from_array(&int_folls_varlist);
if ( !parser_varpack_aux )
parser_varpack_aux = (void *)bits_from_array(&int_varpack_aux);
if ( !parser_varpack_aux2 )
parser_varpack_aux2 = (void *)bits_from_array(&int_varpack_aux2);
return bits_disjunct(parser_varpack_aux, parser_start_typedefn, parser_varpack_aux2);
}

original_code:
void init_parser_varpack(void)
{
    parser_name_varlist = "identifier";
    { { if (parser_start_varpack == 0) parser_start_varpack = bits_from_array(int_start_varpack); }; { if (parser_folls_varpack == 0) parser_folls_varpack = bits_from_array(int_folls_varpack); }; };
    { { if (parser_start_varlist == 0) parser_start_varlist = bits_from_array(int_start_varlist); }; { if (parser_folls_varlist == 0) parser_folls_varlist = bits_from_array(int_folls_varlist); }; };
    { if (parser_varpack_aux == 0) parser_varpack_aux = bits_from_array(int_varpack_aux); };
    { if (parser_varpack_aux2 == 0) parser_varpack_aux2 = bits_from_array(int_varpack_aux2); }
    bits_disjunct(parser_varpack_aux, parser_start_typedefn, parser_varpack_aux2);
}

canonical_original_code:
void init_parser_varpack()
{
    parser_name_varlist = "identifier";
    { { if (parser_start_varpack == 0) parser_start_varpack = bits_from_array(int_start_varpack); }; { if (parser_folls_varpack == 0) parser_folls_varpack = bits_from_array(int_folls_varpack); }; };
    { { if (parser_start_varlist == 0) parser_start_varlist = bits_from_array(int_start_varlist); }; { if (parser_folls_varlist == 0) parser_folls_varlist = bits_from_array(int_folls_varlist); }; };
    { if (parser_varpack_aux == 0) parser_varpack_aux = bits_from_array(int_varpack_aux); };
    { if (parser_varpack_aux2 == 0) parser_varpack_aux2 = bits_from_array(int_varpack_aux2); }
    bits_disjunct(parser_varpack_aux, parser_start_typedefn, parser_varpack_aux2);
}


decompiled_code:
void fini_parser_varpack()
{
if ( parser_start_varpack )
free(parser_start_varpack);
if ( parser_folls_varpack )
free(parser_folls_varpack);
if ( parser_start_varlist )
free(parser_start_varlist);
if ( parser_folls_varlist )
free(parser_folls_varlist);
if ( parser_varpack_aux )
free(parser_varpack_aux);
if ( parser_varpack_aux2 )
free(parser_varpack_aux2);
}

canonical_decompiled_code:
void func6()
{
if ( parser_start_varpack )
free(parser_start_varpack);
if ( parser_folls_varpack )
free(parser_folls_varpack);
if ( parser_start_varlist )
free(parser_start_varlist);
if ( parser_folls_varlist )
free(parser_folls_varlist);
if ( parser_varpack_aux )
free(parser_varpack_aux);
if ( parser_varpack_aux2 )
free(parser_varpack_aux2);
}

original_code:
void fini_parser_varpack(void)
{
    { { if (parser_start_varpack != 0) free(parser_start_varpack); }; { if (parser_folls_varpack != 0) free(parser_folls_varpack); }; };
    { { if (parser_start_varlist != 0) free(parser_start_varlist); }; { if (parser_folls_varlist != 0) free(parser_folls_varlist); }; };
    { if (parser_varpack_aux != 0) free(parser_varpack_aux); };
    { if (parser_varpack_aux2 != 0) free(parser_varpack_aux2); };
}

canonical_original_code:
void fini_parser_varpack()
{
    { { if (parser_start_varpack != 0) free(parser_start_varpack); }; { if (parser_folls_varpack != 0) free(parser_folls_varpack); }; };
    { { if (parser_start_varlist != 0) free(parser_start_varlist); }; { if (parser_folls_varlist != 0) free(parser_folls_varlist); }; };
    { if (parser_varpack_aux != 0) free(parser_varpack_aux); };
    { if (parser_varpack_aux2 != 0) free(parser_varpack_aux2); };
}


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

setlocale(6, &locale);
bindtextdomain("simple-pascal-compiler", "./i18n/locale");
textdomain("simple-pascal-compiler");
result = *(unsigned __int8 *)localeconv()->decimal_point;
dec_point = result;
return result;
}

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

setlocale(6, &locale);
bindtextdomain("simple-pascal-compiler", "./i18n/locale");
textdomain("simple-pascal-compiler");
result = *(unsigned __int8 *)localeconv()->decimal_point;
dec_point = result;
return result;
}

original_code:
void init_gettext()
{
    setlocale(6, "");
    bindtextdomain("simple-pascal-compiler", "./i18n/locale");
    textdomain("simple-pascal-compiler");
    dec_point = *(localeconv()->decimal_point);
}


decompiled_code:
__int64 get_dec_point()
{
return (unsigned __int8)dec_point;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned __int8)dec_point;
}

original_code:
char get_dec_point()
{
    return dec_point;
}


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

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

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

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

original_code:
int list_len(list *l)
{
    int i = 0;
    while (l != 0)
    {
        l = l->next;
        i++;
    }
    return i;
}

canonical_original_code:
int list_len(struct _list *l)
{
    int i = 0;
    while (l != 0)
    {
        l = l->next;
        i++;
    }
    return i;
}

variable_types: struct _list { void *value; struct _list *next; } *

return_type: int


decompiled_code:
int __fastcall parse_program(__int64 a1, struct sockaddr *a2, socklen_t *a3)
{
socklen_t *v3; // rdx
socklen_t *v4; // rdx
socklen_t *v5; // rdx

accept(901, a2, a3);
accept(1000, a2, v3);
accept(59, a2, v4);
parse_block(parser_program_aux, 0LL);
return accept(46, 0LL, v5);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, struct sockaddr *a2, socklen_t *a3)
{
socklen_t *v3; // rdx
socklen_t *v4; // rdx
socklen_t *v5; // rdx

accept(901, a2, a3);
accept(1000, a2, v3);
accept(59, a2, v4);
parse_block(parser_program_aux, 0LL);
return accept(46, 0LL, v5);
}

original_code:
void *parse_program (unsigned long *folls, unsigned long *ex)
{
    accept(L_PROGRAM);
    accept(L_IDENT);
    accept(L_SEMICOLON);
    parse_block(parser_program_aux, 0);
    accept(L_POINT);
}

canonical_original_code:
void *parse_program(unsigned long *folls, unsigned long *ex)
{
    accept(L_PROGRAM);
    accept(L_IDENT);
    accept(L_SEMICOLON);
    parse_block(parser_program_aux, 0);
    accept(L_POINT);
}


decompiled_code:
void init_parser_program()
{
if ( !parser_start_program )
parser_start_program = (void *)bits_from_array(&int_start_program);
if ( !parser_folls_program )
parser_folls_program = (void *)bits_from_array(&int_folls_program);
if ( !parser_program_aux )
parser_program_aux = (void *)bits_from_array(&int_program_aux);
}

canonical_decompiled_code:
void func1()
{
if ( !parser_start_program )
parser_start_program = (void *)bits_from_array(&int_start_program);
if ( !parser_folls_program )
parser_folls_program = (void *)bits_from_array(&int_folls_program);
if ( !parser_program_aux )
parser_program_aux = (void *)bits_from_array(&int_program_aux);
}

original_code:
void init_parser_program(void)
{
    { { if (parser_start_program == 0) parser_start_program = bits_from_array(int_start_program); }; { if (parser_folls_program == 0) parser_folls_program = bits_from_array(int_folls_program); }; };
    { if (parser_program_aux == 0) parser_program_aux = bits_from_array(int_program_aux); };
}

canonical_original_code:
void init_parser_program()
{
    { { if (parser_start_program == 0) parser_start_program = bits_from_array(int_start_program); }; { if (parser_folls_program == 0) parser_folls_program = bits_from_array(int_folls_program); }; };
    { if (parser_program_aux == 0) parser_program_aux = bits_from_array(int_program_aux); };
}


decompiled_code:
void fini_parser_program()
{
if ( parser_start_program )
free(parser_start_program);
if ( parser_folls_program )
free(parser_folls_program);
if ( parser_program_aux )
free(parser_program_aux);
}

canonical_decompiled_code:
void func2()
{
if ( parser_start_program )
free(parser_start_program);
if ( parser_folls_program )
free(parser_folls_program);
if ( parser_program_aux )
free(parser_program_aux);
}

original_code:
void fini_parser_program(void)
{
    { { if (parser_start_program != 0) free(parser_start_program); }; { if (parser_folls_program != 0) free(parser_folls_program); }; };
    { if (parser_program_aux != 0) free(parser_program_aux); };
}

canonical_original_code:
void fini_parser_program()
{
    { { if (parser_start_program != 0) free(parser_start_program); }; { if (parser_folls_program != 0) free(parser_folls_program); }; };
    { if (parser_program_aux != 0) free(parser_program_aux); };
}


repo: BatchDrake/libsim

original_code:
struct draw *
draw_new (int width, int height)
{
  struct draw *draw;
  draw = xmalloc (((((sizeof (struct draw)) + (4) - 1) / (4)) * (4)));
  draw->width = width;
  draw->height = height;
  draw->total_size = ((height) * (((((((((((width) * (24)))) + (8) - 1) / (8)) * (8)) >> 3) + (4) - 1) / (4)) * (4)));
  draw->pixels = xmalloc (draw->total_size);
  printf ("Total size: %d\n", draw->total_size);
  memset (draw->pixels, 0, draw->total_size);
  return draw;
}

canonical_original_code:
struct draw *draw_new(int width, int height)
{
  struct draw *draw;
  draw = xmalloc (((((sizeof (struct draw)) + (4) - 1) / (4)) * (4)));
  draw->width = width;
  draw->height = height;
  draw->total_size = ((height) * (((((((((((width) * (24)))) + (8) - 1) / (8)) * (8)) >> 3) + (4) - 1) / (4)) * (4)));
  draw->pixels = xmalloc (draw->total_size);
  printf ("Total size: %d\n", draw->total_size);
  memset (draw->pixels, 0, draw->total_size);
  return draw;
}

variable_types: width int

variable_types: height int

variable_types: struct draw { int width; int height; int total_size; unsigned char *pixels; } *


decompiled_code:
void __fastcall draw_free(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

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

original_code:
void
draw_free (struct draw *draw)
{
  free (draw->pixels);
  free (draw);
}

canonical_original_code:
void draw_free(struct draw *draw)
{
  free (draw->pixels);
  free (draw);
}

user_defined_types: struct draw { int width; int height; int total_size; unsigned char *pixels; }


decompiled_code:
__int64 __fastcall draw_pget(__int64 a1, int a2, int a3)
{
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // eax
int v10; // edx
int v11; // eax
__int64 result; // rax

if ( a2 < 0 || (v4 = *(_DWORD *)a1, a3 < 0) || v4 <= a2 || (v5 = *(_DWORD *)(a1 + 4), v5 <= a3) )
{
errno_save();
fprintf(
stderr,
" * LibSIM warning: draw.c:78: Coords (%d, %d) out of bounds!\n",
(unsigned int)a2,
(unsigned int)a3);
errno_restore();
result = 0LL;
}
else
{
v6 = 24 * v4;
v7 = v6 + 14;
v8 = v6 + 7;
if ( v8 < 0 )
v8 = v7;
v9 = v8 >> 3;
v10 = v9 + 6;
v11 = v9 + 3;
if ( v11 < 0 )
v11 = v10;
result = *(_DWORD *)(*(_QWORD *)(a1 + 16) + ((24 * a2) >> 3) + 4 * (v11 >> 2) * (v5 - a3 - 1)) & 0xFFFFFF;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // eax
int v10; // edx
int v11; // eax
__int64 result; // rax

if ( a2 < 0 || (v4 = *(_DWORD *)a1, a3 < 0) || v4 <= a2 || (v5 = *(_DWORD *)(a1 + 4), v5 <= a3) )
{
errno_save();
fprintf(
stderr,
" * LibSIM warning: draw.c:78: Coords (%d, %d) out of bounds!\n",
(unsigned int)a2,
(unsigned int)a3);
errno_restore();
result = 0LL;
}
else
{
v6 = 24 * v4;
v7 = v6 + 14;
v8 = v6 + 7;
if ( v8 < 0 )
v8 = v7;
v9 = v8 >> 3;
v10 = v9 + 6;
v11 = v9 + 3;
if ( v11 < 0 )
v11 = v10;
result = *(_DWORD *)(*(_QWORD *)(a1 + 16) + ((24 * a2) >> 3) + 4 * (v11 >> 2) * (v5 - a3 - 1)) & 0xFFFFFF;
}
return result;
}

original_code:
DWORD
draw_pget (struct draw *draw, int x, int y)
{
  DWORD *p;
  if (x < 0 || x >= draw->width || y < 0 || y >= draw->height)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM warning: " "draw.c" ":" "78" ": " "Coords (%d, %d) out of bounds!\n", x, y); errno_restore (); } while (0);;
    return 0;
  }
  p = (DWORD *) (draw->pixels + ( (((x) * (24)) >> 3) + ((draw->height) - (y) - 1) * (((((((((((draw->width) * (24)))) + (8) - 1) / (8)) * (8)) >> 3) + (4) - 1) / (4)) * (4)) ));
  return *p & 0xffffff;
}

canonical_original_code:
unsigned int draw_pget(struct draw *draw, int x, int y)
{
  unsigned int *p;
  if (x < 0 || x >= draw->width || y < 0 || y >= draw->height)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM warning: " "draw.c" ":" "78" ": " "Coords (%d, %d) out of bounds!\n", x, y); errno_restore (); } while (0);;
    return 0;
  }
  p = (unsigned int *) (draw->pixels + ( (((x) * (24)) >> 3) + ((draw->height) - (y) - 1) * (((((((((((draw->width) * (24)))) + (8) - 1) / (8)) * (8)) >> 3) + (4) - 1) / (4)) * (4)) ));
  return *p & 0xffffff;
}

variable_types: x int

variable_types: y int

variable_types:
p
unsigned int *

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall list_is_empty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
static inline int
list_is_empty (void **list)
{
  ;
  return *list == ((void *)0);
}

canonical_original_code:
static inline int list_is_empty(void **list)
{
  ;
  return *list == ((void *)0);
}

variable_types:
list
void **


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall sorted_list_is_empty(_QWORD *a1)
{
return list_is_empty(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
return func0(a1);
}

original_code:
static inline int
sorted_list_is_empty (void **list)
{
  return list_is_empty (list);
}

canonical_original_code:
static inline int sorted_list_is_empty(void **list)
{
  return list_is_empty (list);
}


decompiled_code:
__int64 __fastcall list_get_head(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
void *
list_get_head (void **list)
{
  ;
  return *list;
}

canonical_original_code:
void *list_get_head(void **list)
{
  ;
  return *list;
}


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

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

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

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

original_code:
void
list_insert_after (void **list, void *element, void *new)
{
  ;
  ;
  ;
  ;
  ((struct list_head *) (new))->next = ((struct list_head *) (element))->next;
  ((struct list_head *) (new))->prev = ((struct list_head *) (element));
  if (((struct list_head *) (element))->next != ((void *)0))
    ((struct list_head *) (element))->next->prev = ((struct list_head *) (new));
  ((struct list_head *) (element))->next = ((struct list_head *) (new));
}

canonical_original_code:
void list_insert_after(void **list, void *element, void *new)
{
  ;
  ;
  ;
  ;
  ((struct list_head *) (new))->next = ((struct list_head *) (element))->next;
  ((struct list_head *) (new))->prev = ((struct list_head *) (element));
  if (((struct list_head *) (element))->next != ((void *)0))
    ((struct list_head *) (element))->next->prev = ((struct list_head *) (new));
  ((struct list_head *) (element))->next = ((struct list_head *) (new));
}

variable_types:
element
void *

variable_types:
new
void *

user_defined_types: struct list_head { struct list_head *next; struct list_head *prev; }


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

v2 = list_get_tail((_QWORD **)a1);
if ( v2 )
result = list_insert_after((__int64)a1, v2, a2);
else
result = list_insert_head(a1, a2);
return result;
}

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

v2 = list_get_tail((_QWORD **)a1);
if ( v2 )
result = func5((__int64)a1, v2, a2);
else
result = func4(a1, a2);
return result;
}

original_code:
void
list_insert_tail (void **list, void *element)
{
  void *tail;
  if ((tail = list_get_tail (list)) == ((void *)0))
    list_insert_head (list, element);
  else
    list_insert_after (list, tail, element);
}

canonical_original_code:
void list_insert_tail(void **list, void *element)
{
  void *tail;
  if ((tail = list_get_tail (list)) == ((void *)0))
    list_insert_head (list, element);
  else
    list_insert_after (list, tail, element);
}

variable_types:
tail
void *


decompiled_code:
// attributes: thunk
__int64 __fastcall sorted_list_get_head(__int64 a1)
{
return list_get_head(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return func2(a1);
}

original_code:
void *
sorted_list_get_head (void **list)
{
  return list_get_head (list);
}

canonical_original_code:
void *sorted_list_get_head(void **list)
{
  return list_get_head (list);
}


decompiled_code:
double *__fastcall sorted_list_search(double **a1, double a2)
{
double *result; // rax
double v4; // xmm0_8

for ( result = *a1; result; result = *(double **)result )
{
v4 = result[2];
if ( v4 == a2 )
break;
if ( v4 > a2 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
double *__fastcall func9(double **a1, double a2)
{
double *result; // rax
double v4; // xmm0_8

for ( result = *a1; result; result = *(double **)result )
{
v4 = result[2];
if ( v4 == a2 )
break;
if ( v4 > a2 )
return 0LL;
}
return result;
}

original_code:
void *
sorted_list_search (void **list, double index)
{
  struct sorted_list_head *this;
  ;
  this = ((struct sorted_list_head *) (*list));
  while (this)
  {
    if (this->index == index)
      return this;
    else if (this->index > index)
      return ((void *)0);
    this = ((struct sorted_list_head *) (this->head.next));
  }
  return ((void *)0);
}

canonical_original_code:
void *sorted_list_search(void **list, double index)
{
  struct sorted_list_head *this;
  ;
  this = ((struct sorted_list_head *) (*list));
  while (this)
  {
    if (this->index == index)
      return this;
    else if (this->index > index)
      return ((void *)0);
    this = ((struct sorted_list_head *) (this->head.next));
  }
  return ((void *)0);
}

variable_types: index double

variable_types: struct sorted_list_head { struct list_head { struct list_head *next; struct list_head *prev; } head; double index; } *

user_defined_types: struct sorted_list_head { struct list_head head; double index; }


decompiled_code:
double *__fastcall sorted_list_get_next(double **a1, double a2)
{
double *result; // rax

for ( result = *a1; result; result = *(double **)result )
{
if ( result[2] >= a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = *(double **)result )
{
if ( result[2] >= a2 )
break;
}
return result;
}

original_code:
void *
sorted_list_get_next (void **list, double index)
{
  struct sorted_list_head *this;
  ;
  this = ((struct sorted_list_head *) (*list));
  while (this)
  {
    if (this->index >= index)
      return this;
    this = ((struct sorted_list_head *) (this->head.next));
  }
  return ((void *)0);
}

canonical_original_code:
void *sorted_list_get_next(void **list, double index)
{
  struct sorted_list_head *this;
  ;
  this = ((struct sorted_list_head *) (*list));
  while (this)
  {
    if (this->index >= index)
      return this;
    this = ((struct sorted_list_head *) (this->head.next));
  }
  return ((void *)0);
}


decompiled_code:
double *__fastcall sorted_list_get_previous(double **a1, double a2)
{
double *result; // rax

for ( result = *a1; result; result = *(double **)result )
{
if ( result[2] > a2 )
return (double *)*((_QWORD *)result + 1);
if ( !*(_QWORD *)result )
return result;
}
return result;
}

canonical_decompiled_code:
double *__fastcall func11(double **a1, double a2)
{
double *result; // rax

for ( result = *a1; result; result = *(double **)result )
{
if ( result[2] > a2 )
return (double *)*((_QWORD *)result + 1);
if ( !*(_QWORD *)result )
return result;
}
return result;
}

original_code:
void *
sorted_list_get_previous (void **list, double index)
{
  struct sorted_list_head *this;
  ;
  this = ((struct sorted_list_head *) (*list));
  while (this)
  {
    if (this->index > index)
      return this->head.prev;
    if (this->head.next == ((void *)0))
      return this;
    this = ((struct sorted_list_head *) (this->head.next));
  }
  return ((void *)0);
}

canonical_original_code:
void *sorted_list_get_previous(void **list, double index)
{
  struct sorted_list_head *this;
  ;
  this = ((struct sorted_list_head *) (*list));
  while (this)
  {
    if (this->index > index)
      return this->head.prev;
    if (this->head.next == ((void *)0))
      return this;
    this = ((struct sorted_list_head *) (this->head.next));
  }
  return ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall circular_list_is_head(_QWORD *a1, __int64 a2)
{
return *a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_QWORD *a1, __int64 a2)
{
return *a1 == a2;
}

original_code:
int
circular_list_is_head (void **list, void *element)
{
  ;
  ;
  return ((struct list_head *) (*list)) == ((struct list_head *) (element));
}

canonical_original_code:
int circular_list_is_head(void **list, void *element)
{
  ;
  ;
  return ((struct list_head *) (*list)) == ((struct list_head *) (element));
}


decompiled_code:
_BOOL8 __fastcall circular_list_is_tail(__int64 a1, __int64 a2)
{
return *(_QWORD *)(*(_QWORD *)a1 + 8LL) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1, __int64 a2)
{
return *(_QWORD *)(*(_QWORD *)a1 + 8LL) == a2;
}

original_code:
int
circular_list_is_tail (void **list, void *element)
{
  ;
  return ((struct list_head *) (*list))->prev == ((struct list_head *) (element));
}

canonical_original_code:
int circular_list_is_tail(void **list, void *element)
{
  ;
  return ((struct list_head *) (*list))->prev == ((struct list_head *) (element));
}


decompiled_code:
__int64 __fastcall circular_list_get_head(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
void *
circular_list_get_head (void **list)
{
  ;
  return *list;
}

canonical_original_code:
void *circular_list_get_head(void **list)
{
  ;
  return *list;
}


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

result = *a1;
if ( *a1 )
result = *(_QWORD *)(result + 8);
return result;
}

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

result = *a1;
if ( *a1 )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
void *
circular_list_get_tail (void **list)
{
  ;
  if (*list == ((void *)0))
    return ((void *)0);
  return (void *) ((void *) ((struct list_head *) (*list))->prev);
}

canonical_original_code:
void *circular_list_get_tail(void **list)
{
  ;
  if (*list == ((void *)0))
    return ((void *)0);
  return (void *) ((void *) ((struct list_head *) (*list))->prev);
}


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

result = circular_list_is_empty(a1);
if ( !result )
*a1 = a2;
return result;
}

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

result = func12(a1);
if ( !result )
*a1 = a2;
return result;
}

original_code:
void
circular_list_scroll_to (void **list, void *element)
{
  ;
  ;
  if (!circular_list_is_empty (list))
    *list = element;
}

canonical_original_code:
void circular_list_scroll_to(void **list, void *element)
{
  ;
  ;
  if (!circular_list_is_empty (list))
    *list = element;
}


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

result = circular_list_is_empty(a1);
if ( !(_DWORD)result )
{
result = *(_QWORD *)(*a1 + 8LL);
*a1 = result;
}
return result;
}

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

result = func12(a1);
if ( !(_DWORD)result )
{
result = *(_QWORD *)(*a1 + 8LL);
*a1 = result;
}
return result;
}

original_code:
void
circular_list_scroll_prev (void **list)
{
  ;
  if (!circular_list_is_empty (list))
    *list = (void *) ((struct circular_list_head *) (*list))->head.prev;
}

canonical_original_code:
void circular_list_scroll_prev(void **list)
{
  ;
  if (!circular_list_is_empty (list))
    *list = (void *) ((struct circular_list_head *) (*list))->head.prev;
}

user_defined_types: struct circular_list_head { struct list_head head; }


decompiled_code:
_BOOL8 __fastcall in_bounds(__int64 a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 >= 0 )
result = *(_DWORD *)(a1 + 12) > a2;
return result;
}

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

result = 0LL;
if ( a2 >= 0 )
result = *(_DWORD *)(a1 + 12) > a2;
return result;
}

original_code:
static inline int
in_bounds (cpi_handle_t *handle, int sz)
{
  if (sz < 0 || sz >= handle->cpi_file_size)
    return 0;
  return 1;
}

canonical_original_code:
static inline int in_bounds(struct cpi_handle *handle, int sz)
{
  if (sz < 0 || sz >= handle->cpi_file_size)
    return 0;
  return 1;
}

variable_types: struct cpi_handle { void *cpi_file; int cpi_fd; int cpi_file_size; int font_is_nt; struct cpi_header { char tag[8]; char reserved[8]; short pointer_no; char pointer_type; int info_off; short entry_no; } *cpi_file_header; } *

variable_types: sz int

user_defined_types: struct cpi_handle { void *cpi_file; int cpi_fd; int cpi_file_size; int font_is_nt; struct cpi_header *cpi_file_header; }


decompiled_code:
__int64 __fastcall cpi_map_codepage(__int64 a1, const char *a2)
{
int v2; // eax
unsigned int v3; // ebp
signed int v4; // eax
void *v5; // rax
const void *v6; // rbp

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( a2 )
{
v2 = open(a2, 0);
v3 = v2;
*(_DWORD *)(a1 + 8) = v2;
if ( v2 == -1 )
{
perror("cpi_map_codepage: open");
return v3;
}
v4 = lseek(v2, 0LL, 2);
v3 = v4;
*(_DWORD *)(a1 + 12) = v4;
if ( v4 == -1 )
{
perror("cpi_map_codepage: lseek");
close(*(_DWORD *)(a1 + 8));
return v3;
}
v5 = mmap(0LL, v4, 1, 2, *(_DWORD *)(a1 + 8), 0LL);
*(_QWORD *)a1 = v5;
if ( v5 == (void *)-1LL )
{
perror("cpi_map_codepage: mmap");
close(*(_DWORD *)(a1 + 8));
return (unsigned int)-1;
}
}
else
{
*(_DWORD *)(a1 + 8) = -1;
*(_DWORD *)(a1 + 12) = 2114;
*(_QWORD *)a1 = &bin2c_pearl_m68k_cpi_data;
}
v6 = *(const void **)a1;
*(_QWORD *)(a1 + 24) = *(_QWORD *)a1;
if ( !memcmp(v6, &unk_FA9, 8uLL) || !memcmp(v6, &unk_FB2, 8uLL) )
{
*(_DWORD *)(a1 + 16) = memcmp(v6, &unk_FB2, 8uLL) == 0;
v3 = 0;
}
else
{
errno_save();
fwrite(" * LibSIM error: cpi.c:83: cpi_map_codepage: invalid file (not a CPI file)\n", 1uLL, 0x4BuLL, stderr);
errno_restore();
munmap(*(void **)a1, *(int *)(a1 + 12));
*(_QWORD *)a1 = 0LL;
close(*(_DWORD *)(a1 + 8));
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
int v2; // eax
unsigned int v3; // ebp
signed int v4; // eax
void *v5; // rax
const void *v6; // rbp

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( a2 )
{
v2 = open(a2, 0);
v3 = v2;
*(_DWORD *)(a1 + 8) = v2;
if ( v2 == -1 )
{
perror("cpi_map_codepage: open");
return v3;
}
v4 = lseek(v2, 0LL, 2);
v3 = v4;
*(_DWORD *)(a1 + 12) = v4;
if ( v4 == -1 )
{
perror("cpi_map_codepage: lseek");
close(*(_DWORD *)(a1 + 8));
return v3;
}
v5 = mmap(0LL, v4, 1, 2, *(_DWORD *)(a1 + 8), 0LL);
*(_QWORD *)a1 = v5;
if ( v5 == (void *)-1LL )
{
perror("cpi_map_codepage: mmap");
close(*(_DWORD *)(a1 + 8));
return (unsigned int)-1;
}
}
else
{
*(_DWORD *)(a1 + 8) = -1;
*(_DWORD *)(a1 + 12) = 2114;
*(_QWORD *)a1 = &bin2c_pearl_m68k_cpi_data;
}
v6 = *(const void **)a1;
*(_QWORD *)(a1 + 24) = *(_QWORD *)a1;
if ( !memcmp(v6, &unk_FA9, 8uLL) || !memcmp(v6, &unk_FB2, 8uLL) )
{
*(_DWORD *)(a1 + 16) = memcmp(v6, &unk_FB2, 8uLL) == 0;
v3 = 0;
}
else
{
errno_save();
fwrite(" * LibSIM error: cpi.c:83: cpi_map_codepage: invalid file (not a CPI file)\n", 1uLL, 0x4BuLL, stderr);
errno_restore();
munmap(*(void **)a1, *(int *)(a1 + 12));
*(_QWORD *)a1 = 0LL;
close(*(_DWORD *)(a1 + 8));
v3 = -1;
}
return v3;
}

original_code:
int
cpi_map_codepage (cpi_handle_t *handle, const char *path)
{
  memset (handle, 0, sizeof (cpi_handle_t));
  if (path == ((void *)0))
  {
    handle->cpi_fd = -1;
    handle->cpi_file_size = sizeof (bin2c_pearl_m68k_cpi_data);
    handle->cpi_file = bin2c_pearl_m68k_cpi_data;
  }
  else
  {
    if ((handle->cpi_fd = open (path, 00)) == -1)
    {
      perror ("cpi_map_codepage: open");
      return -1;
    }
    if ((handle->cpi_file_size = lseek (handle->cpi_fd, 0, 2)) == -1)
    {
      perror ("cpi_map_codepage: lseek");
      close (handle->cpi_fd);
      return -1;
    }
    if ((handle->cpi_file =
      mmap (((void *)0), handle->cpi_file_size, 0x1, 0x02,
      handle->cpi_fd, 0)) ==
      (caddr_t) -1)
    {
      perror ("cpi_map_codepage: mmap");
      close (handle->cpi_fd);
      return -1;
    }
  }
  handle->cpi_file_header = (struct cpi_header *) handle->cpi_file;
  if (memcmp (handle->cpi_file_header->tag, "\xff" "FONT   ", 8) != 0 &&
      memcmp (handle->cpi_file_header->tag, "\xff" "FONT.NT", 8) != 0)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "83" ": " "cpi_map_codepage: invalid file (not a CPI file)\n"); errno_restore (); } while (0);;
    munmap (handle->cpi_file, handle->cpi_file_size);
    handle->cpi_file = ((void *)0);
    close (handle->cpi_fd);
    return -1;
  }
  handle->font_is_nt =
    memcmp (handle->cpi_file_header->tag, "\xff" "FONT.NT", 8) == 0;
  return 0;
}

canonical_original_code:
int cpi_map_codepage(struct cpi_handle *handle, char *path)
{
  memset (handle, 0, sizeof (cpi_handle_t));
  if (path == ((void *)0))
  {
    handle->cpi_fd = -1;
    handle->cpi_file_size = sizeof (bin2c_pearl_m68k_cpi_data);
    handle->cpi_file = bin2c_pearl_m68k_cpi_data;
  }
  else
  {
    if ((handle->cpi_fd = open (path, 00)) == -1)
    {
      perror ("cpi_map_codepage: open");
      return -1;
    }
    if ((handle->cpi_file_size = lseek (handle->cpi_fd, 0, 2)) == -1)
    {
      perror ("cpi_map_codepage: lseek");
      close (handle->cpi_fd);
      return -1;
    }
    if ((handle->cpi_file =
      mmap (((void *)0), handle->cpi_file_size, 0x1, 0x02,
      handle->cpi_fd, 0)) ==
      (caddr_t) -1)
    {
      perror ("cpi_map_codepage: mmap");
      close (handle->cpi_fd);
      return -1;
    }
  }
  handle->cpi_file_header = (struct cpi_header *) handle->cpi_file;
  if (memcmp (handle->cpi_file_header->tag, "\xff" "FONT   ", 8) != 0 &&
      memcmp (handle->cpi_file_header->tag, "\xff" "FONT.NT", 8) != 0)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "83" ": " "cpi_map_codepage: invalid file (not a CPI file)\n"); errno_restore (); } while (0);;
    munmap (handle->cpi_file, handle->cpi_file_size);
    handle->cpi_file = ((void *)0);
    close (handle->cpi_fd);
    return -1;
  }
  handle->font_is_nt =
    memcmp (handle->cpi_file_header->tag, "\xff" "FONT.NT", 8) == 0;
  return 0;
}

variable_types:
path
char *

user_defined_types: struct cpi_header { char tag[8]; char reserved[8]; short pointer_no; char pointer_type; int info_off; short entry_no; }


decompiled_code:
char *__fastcall cpi_get_page(__int64 a1, __int16 a2)
{
char *v2; // rbp
__int64 v3; // rax
unsigned int v4; // er15
char *v5; // rbx
int v6; // er13
int v7; // er14
unsigned int v8; // ebp
int v9; // eax
int v10; // edx
int v11; // eax

v2 = *(char **)a1;
if ( !*(_QWORD *)a1 )
{
errno_save();
fwrite(" * LibSIM error: cpi.c:109: cpi_get_page: no previously CPI file selected\n", 1uLL, 0x4AuLL, stderr);
errno_restore();
return v2;
}
v3 = 25LL;
if ( !*(_DWORD *)(a1 + 16) )
v3 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + 19LL) + 2;
v2 += v3;
if ( *(__int16 *)(*(_QWORD *)(a1 + 24) + 23LL) <= 0 )
return 0LL;
v4 = 0;
while ( 1 )
{
if ( !in_bounds(a1, (int)v2 - *(_DWORD *)a1) )
{
errno_save();
fprintf(
stderr,
" * LibSIM error: cpi.c:122: cpi_get_page: entry 0x%lx (%d) out of bounds!\n",
&v2[-*(_QWORD *)a1],
v4);
errno_restore();
return 0LL;
}
if ( *((_WORD *)v2 + 3) == 1 && *((_WORD *)v2 + 8) == a2 )
return v2;
printf("%d omissible\n", (unsigned int)*((__int16 *)v2 + 8));
++v4;
if ( *(_DWORD *)(a1 + 16) )
break;
printf("Next entry is at 0x%08x\n", *(unsigned int *)(v2 + 2));
v2 = (char *)(*(_QWORD *)a1 + *(int *)(v2 + 2));
LABEL_10:
if ( *(__int16 *)(*(_QWORD *)(a1 + 24) + 23LL) <= (int)v4 )
return 0LL;
}
v5 = v2 + 34;
v6 = *((__int16 *)v2 + 15);
if ( v6 <= 0 )
{
LABEL_21:
v2 = v5;
goto LABEL_10;
}
v7 = *(_DWORD *)a1;
v8 = 0;
while ( in_bounds(a1, (int)v5 - v7) )
{
v9 = v5[1] * *v5 * *((__int16 *)v5 + 2);
v10 = v9 + 14;
v11 = v9 + 7;
if ( v11 < 0 )
v11 = v10;
v5 += (v11 >> 3) + 6;
if ( ++v8 == v6 )
goto LABEL_21;
}
errno_save();
fprintf(stderr, " * LibSIM error: cpi.c:145: cpi_get_page: font 0x%lx (%d) out of bounds!\n", v5, v8);
errno_restore();
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int16 a2)
{
char *v2; // rbp
__int64 v3; // rax
unsigned int v4; // er15
char *v5; // rbx
int v6; // er13
int v7; // er14
unsigned int v8; // ebp
int v9; // eax
int v10; // edx
int v11; // eax

v2 = *(char **)a1;
if ( !*(_QWORD *)a1 )
{
errno_save();
fwrite(" * LibSIM error: cpi.c:109: cpi_get_page: no previously CPI file selected\n", 1uLL, 0x4AuLL, stderr);
errno_restore();
return v2;
}
v3 = 25LL;
if ( !*(_DWORD *)(a1 + 16) )
v3 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + 19LL) + 2;
v2 += v3;
if ( *(__int16 *)(*(_QWORD *)(a1 + 24) + 23LL) <= 0 )
return 0LL;
v4 = 0;
while ( 1 )
{
if ( !func0(a1, (int)v2 - *(_DWORD *)a1) )
{
errno_save();
fprintf(
stderr,
" * LibSIM error: cpi.c:122: cpi_get_page: entry 0x%lx (%d) out of bounds!\n",
&v2[-*(_QWORD *)a1],
v4);
errno_restore();
return 0LL;
}
if ( *((_WORD *)v2 + 3) == 1 && *((_WORD *)v2 + 8) == a2 )
return v2;
printf("%d omissible\n", (unsigned int)*((__int16 *)v2 + 8));
++v4;
if ( *(_DWORD *)(a1 + 16) )
break;
printf("Next entry is at 0x%08x\n", *(unsigned int *)(v2 + 2));
v2 = (char *)(*(_QWORD *)a1 + *(int *)(v2 + 2));
LABEL_10:
if ( *(__int16 *)(*(_QWORD *)(a1 + 24) + 23LL) <= (int)v4 )
return 0LL;
}
v5 = v2 + 34;
v6 = *((__int16 *)v2 + 15);
if ( v6 <= 0 )
{
LABEL_21:
v2 = v5;
goto LABEL_10;
}
v7 = *(_DWORD *)a1;
v8 = 0;
while ( func0(a1, (int)v5 - v7) )
{
v9 = v5[1] * *v5 * *((__int16 *)v5 + 2);
v10 = v9 + 14;
v11 = v9 + 7;
if ( v11 < 0 )
v11 = v10;
v5 += (v11 >> 3) + 6;
if ( ++v8 == v6 )
goto LABEL_21;
}
errno_save();
fprintf(stderr, " * LibSIM error: cpi.c:145: cpi_get_page: font 0x%lx (%d) out of bounds!\n", v5, v8);
errno_restore();
return 0LL;
}

original_code:
struct cpi_entry *
cpi_get_page (cpi_handle_t *handle, short cp)
{
  struct cpi_entry *entry;
  int entry_count;
  int i;
  long p;
  struct cpi_font_info *info;
  struct cpi_disp_font *font;
  if (handle->cpi_file == ((void *)0))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "109" ": " "cpi_get_page: no previously CPI file selected\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  entry_count = 0;
  for (entry = (struct cpi_entry *) (handle->cpi_file +
    (handle->font_is_nt ? 0x19 : handle->cpi_file_header->info_off + 2));
       entry_count < handle->cpi_file_header->entry_no;
       )
  {
    if (!in_bounds (handle, (long) entry - (long) handle->cpi_file))
    {
      do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "122" ": " "cpi_get_page: entry 0x%lx (%d) out of bounds!\n", (long) entry - (long) handle->cpi_file, entry_count); errno_restore (); } while (0);;
      return ((void *)0);
    }
    if (entry->device_type == 1 && entry->codepage == cp)
      return entry;
    printf ("%d omissible\n", entry->codepage);
    entry_count++;
    if (handle->font_is_nt)
    {
      info = (struct cpi_font_info *)
        ((void *) entry + sizeof (struct cpi_entry));
      p = (long) info + sizeof (struct cpi_font_info);
      for (i = 0; i < info->font_no; i++)
      {
        if (!in_bounds (handle, p - (long) handle->cpi_file))
        {
          do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "145" ": " "cpi_get_page: font 0x%lx (%d) out of bounds!\n", p, i); errno_restore (); } while (0);;
          return ((void *)0);
        }
        font = (struct cpi_disp_font *) p;
        p += sizeof (struct cpi_disp_font) +
          (((font->chars * font->rows * font->cols) + 7) / (8));
      }
      entry = (struct cpi_entry *) p;
    }
    else
    {
      printf ("Next entry is at 0x%08x\n", entry->next_entry);
      entry = (struct cpi_entry *) (handle->cpi_file + entry->next_entry);
    }
  }
  return ((void *)0);
}

canonical_original_code:
struct cpi_entry *cpi_get_page(struct cpi_handle *handle, short cp)
{
  struct cpi_entry *entry;
  int entry_count;
  int i;
  long p;
  struct cpi_font_info *info;
  struct cpi_disp_font *font;
  if (handle->cpi_file == ((void *)0))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "109" ": " "cpi_get_page: no previously CPI file selected\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  entry_count = 0;
  for (entry = (struct cpi_entry *) (handle->cpi_file +
    (handle->font_is_nt ? 0x19 : handle->cpi_file_header->info_off + 2));
       entry_count < handle->cpi_file_header->entry_no;
       )
  {
    if (!in_bounds (handle, (long) entry - (long) handle->cpi_file))
    {
      do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "122" ": " "cpi_get_page: entry 0x%lx (%d) out of bounds!\n", (long) entry - (long) handle->cpi_file, entry_count); errno_restore (); } while (0);;
      return ((void *)0);
    }
    if (entry->device_type == 1 && entry->codepage == cp)
      return entry;
    printf ("%d omissible\n", entry->codepage);
    entry_count++;
    if (handle->font_is_nt)
    {
      info = (struct cpi_font_info *)
        ((void *) entry + sizeof (struct cpi_entry));
      p = (long) info + sizeof (struct cpi_font_info);
      for (i = 0; i < info->font_no; i++)
      {
        if (!in_bounds (handle, p - (long) handle->cpi_file))
        {
          do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "145" ": " "cpi_get_page: font 0x%lx (%d) out of bounds!\n", p, i); errno_restore (); } while (0);;
          return ((void *)0);
        }
        font = (struct cpi_disp_font *) p;
        p += sizeof (struct cpi_disp_font) +
          (((font->chars * font->rows * font->cols) + 7) / (8));
      }
      entry = (struct cpi_entry *) p;
    }
    else
    {
      printf ("Next entry is at 0x%08x\n", entry->next_entry);
      entry = (struct cpi_entry *) (handle->cpi_file + entry->next_entry);
    }
  }
  return ((void *)0);
}

variable_types: cp short

variable_types: struct cpi_entry { short code_size; int next_entry; short device_type; char device_name[8]; short codepage; char reserved[6]; int font_info_ptr; } *

variable_types: i int

variable_types: p long

variable_types: struct cpi_font_info { short reserved; short font_no; short font_data_size; } *

variable_types: struct cpi_disp_font { char rows; char cols; short aspect; short chars; } *


decompiled_code:
char *__fastcall cpi_get_disp_font(__int64 a1, __int64 a2, int a3, int a4)
{
int v6; // ebx
__int64 v7; // rax
char *v8; // rbx
int v9; // er14
unsigned int i; // ebp
char *v11; // rcx
int v13; // eax
int v14; // edx
int v15; // eax
int v16; // esi
int v17; // [rsp+Ch] [rbp-3Ch]

v6 = *(_DWORD *)(a2 + 24);
if ( in_bounds(a1, v6) )
{
v7 = a2 + 28;
if ( !*(_DWORD *)(a1 + 16) )
v7 = *(_QWORD *)a1 + v6;
v8 = (char *)(v7 + 6);
v9 = *(__int16 *)(v7 + 2);
if ( v9 <= 0 )
{
v11 = 0LL;
}
else
{
v17 = *(_DWORD *)a1;
for ( i = 0; i != v9; ++i )
{
if ( !in_bounds(a1, (int)v8 - v17) )
{
errno_save();
fprintf(stderr, " * LibSIM error: cpi.c:192: cpi_get_disp_font: font 0x%lx (%d) out of bounds!\n", v8, i);
errno_restore();
return 0LL;
}
v11 = v8;
v16 = v8[1];
if ( v16 == a4 && *v8 == a3 )
return v11;
v13 = v16 * *((__int16 *)v8 + 2) * *v8;
v14 = v13 + 14;
v15 = v13 + 7;
if ( v15 < 0 )
v15 = v14;
v8 += (v15 >> 3) + 6;
}
v11 = 0LL;
}
}
else
{
errno_save();
fwrite(" * LibSIM error: cpi.c:179: cpi_get_disp_font: font info out of bounds!\n", 1uLL, 0x48uLL, stderr);
errno_restore();
v11 = 0LL;
}
return v11;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2, int a3, int a4)
{
int v6; // ebx
__int64 v7; // rax
char *v8; // rbx
int v9; // er14
unsigned int i; // ebp
char *v11; // rcx
int v13; // eax
int v14; // edx
int v15; // eax
int v16; // esi
int v17; // [rsp+Ch] [rbp-3Ch]

v6 = *(_DWORD *)(a2 + 24);
if ( func0(a1, v6) )
{
v7 = a2 + 28;
if ( !*(_DWORD *)(a1 + 16) )
v7 = *(_QWORD *)a1 + v6;
v8 = (char *)(v7 + 6);
v9 = *(__int16 *)(v7 + 2);
if ( v9 <= 0 )
{
v11 = 0LL;
}
else
{
v17 = *(_DWORD *)a1;
for ( i = 0; i != v9; ++i )
{
if ( !func0(a1, (int)v8 - v17) )
{
errno_save();
fprintf(stderr, " * LibSIM error: cpi.c:192: cpi_get_disp_font: font 0x%lx (%d) out of bounds!\n", v8, i);
errno_restore();
return 0LL;
}
v11 = v8;
v16 = v8[1];
if ( v16 == a4 && *v8 == a3 )
return v11;
v13 = v16 * *((__int16 *)v8 + 2) * *v8;
v14 = v13 + 14;
v15 = v13 + 7;
if ( v15 < 0 )
v15 = v14;
v8 += (v15 >> 3) + 6;
}
v11 = 0LL;
}
}
else
{
errno_save();
fwrite(" * LibSIM error: cpi.c:179: cpi_get_disp_font: font info out of bounds!\n", 1uLL, 0x48uLL, stderr);
errno_restore();
v11 = 0LL;
}
return v11;
}

original_code:
struct cpi_disp_font *
cpi_get_disp_font (cpi_handle_t *handle,
  struct cpi_entry *entry, int rows, int cols)
{
  int i;
  long p;
  struct cpi_font_info *info;
  struct cpi_disp_font *font;
  if (!in_bounds (handle, entry->font_info_ptr))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "179" ": " "cpi_get_disp_font: font info out of bounds!\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  info = (struct cpi_font_info *) ((handle->font_is_nt ?
    (void *) entry + sizeof (struct cpi_entry) :
      handle->cpi_file + entry->font_info_ptr));
  p = (long) info + sizeof (struct cpi_font_info);
  for (i = 0; i < info->font_no; i++)
  {
    if (!in_bounds (handle, p - (long) handle->cpi_file))
    {
      do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "192" ": " "cpi_get_disp_font: font 0x%lx (%d) out of bounds!\n", p, i); errno_restore (); } while (0);;
      return ((void *)0);
    }
    font = (struct cpi_disp_font *) p;
    if (font->cols == cols && font->rows == rows)
      return font;
    p += sizeof (struct cpi_disp_font) +
      (((font->chars * font->rows * font->cols) + 7) / (8));
  }
  return ((void *)0);
}

canonical_original_code:
struct cpi_disp_font *cpi_get_disp_font(struct cpi_handle *handle, struct cpi_entry *entry, int rows, int cols)
{
  int i;
  long p;
  struct cpi_font_info *info;
  struct cpi_disp_font *font;
  if (!in_bounds (handle, entry->font_info_ptr))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "179" ": " "cpi_get_disp_font: font info out of bounds!\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  info = (struct cpi_font_info *) ((handle->font_is_nt ?
    (void *) entry + sizeof (struct cpi_entry) :
      handle->cpi_file + entry->font_info_ptr));
  p = (long) info + sizeof (struct cpi_font_info);
  for (i = 0; i < info->font_no; i++)
  {
    if (!in_bounds (handle, p - (long) handle->cpi_file))
    {
      do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "192" ": " "cpi_get_disp_font: font 0x%lx (%d) out of bounds!\n", p, i); errno_restore (); } while (0);;
      return ((void *)0);
    }
    font = (struct cpi_disp_font *) p;
    if (font->cols == cols && font->rows == rows)
      return font;
    p += sizeof (struct cpi_disp_font) +
      (((font->chars * font->rows * font->cols) + 7) / (8));
  }
  return ((void *)0);
}

variable_types: rows int

variable_types: cols int

return_type: struct cpi_disp_font { char rows; char cols; short aspect; short chars; } *

user_defined_types: struct cpi_entry { short code_size; int next_entry; short device_type; char device_name[8]; short codepage; char reserved[6]; int font_info_ptr; }

user_defined_types: struct cpi_font_info { short reserved; short font_no; short font_data_size; }


original_code:
struct glyph *
cpi_get_glyph (struct cpi_disp_font *font, short glyph)
{
  long relative;
  if (glyph < 0 || glyph >= font->chars)
    return ((void *)0);
  relative = (((glyph * font->rows * font->cols) + 7) / (8));
  relative += (long) font + sizeof (struct cpi_disp_font);
  return (struct glyph *) relative;
}

canonical_original_code:
struct glyph *cpi_get_glyph(struct cpi_disp_font *font, short glyph)
{
  long relative;
  if (glyph < 0 || glyph >= font->chars)
    return ((void *)0);
  relative = (((glyph * font->rows * font->cols) + 7) / (8));
  relative += (long) font + sizeof (struct cpi_disp_font);
  return (struct glyph *) relative;
}

variable_types: glyph short

variable_types: relative long

return_type: struct glyph { char bits[16]; } *

user_defined_types: struct cpi_disp_font { char rows; char cols; short aspect; short chars; }


original_code:
void cpi_puts (struct cpi_disp_font *font,
                int width, int height,
                int x, int y,
                void *buf,
                int wordsize,
                int transpbg,
                unsigned int fc,
                unsigned int bc,
                const char *text)
{
  int i, j;
  int n;
  int len;
  int charlength;
  int p;
  char *bytebuf;
  struct glyph *glyph;
  if (font->cols != 8)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "245" ": " "cpi_puts: weird font type (cols != 8)\n"); errno_restore (); } while (0);;
    return;
  }
  bytebuf = buf;
  len = strlen (text);
  if (font->cols * len + x > width)
    len = (width - x) / font->cols;
  charlength = font->rows;
  if (charlength + y > height)
    charlength = height - y;
  for (n = 0; n < len; n++)
  {
    if ((glyph = cpi_get_glyph (font, (unsigned char) text[n])) == ((void *)0))
      continue;
    for (j = 0; j < charlength; j++)
      for (i = 0; i < 8; i++)
        for (p = 0; p < wordsize; p++)
          if (glyph->bits[j] & (1 << (7 - i)))
            bytebuf[p + wordsize * (( (j + y) ) * width + i + x + n * 8)] =
              fc >> (p * 8);
          else if (!transpbg)
            bytebuf[p + wordsize * (( (j + y) ) * width + i + x + n * 8)] =
              bc >> (p * 8);
  }
}

canonical_original_code:
void cpi_puts(struct cpi_disp_font *font, int width, int height, int x, int y, void *buf, int wordsize, int transpbg, unsigned int fc, unsigned int bc, char *text)
{
  int i; int j;
  int n;
  int len;
  int charlength;
  int p;
  char *bytebuf;
  struct glyph *glyph;
  if (font->cols != 8)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "cpi.c" ":" "245" ": " "cpi_puts: weird font type (cols != 8)\n"); errno_restore (); } while (0);;
    return;
  }
  bytebuf = buf;
  len = strlen (text);
  if (font->cols * len + x > width)
    len = (width - x) / font->cols;
  charlength = font->rows;
  if (charlength + y > height)
    charlength = height - y;
  for (n = 0; n < len; n++)
  {
    if ((glyph = cpi_get_glyph (font, (unsigned char) text[n])) == ((void *)0))
      continue;
    for (j = 0; j < charlength; j++)
      for (i = 0; i < 8; i++)
        for (p = 0; p < wordsize; p++)
          if (glyph->bits[j] & (1 << (7 - i)))
            bytebuf[p + wordsize * (( (j + y) ) * width + i + x + n * 8)] =
              fc >> (p * 8);
          else if (!transpbg)
            bytebuf[p + wordsize * (( (j + y) ) * width + i + x + n * 8)] =
              bc >> (p * 8);
  }
}

variable_types: width int

variable_types: height int

variable_types: x int

variable_types: y int

variable_types:
buf
void *

variable_types: wordsize int

variable_types: transpbg int

variable_types:
fc
unsigned int

variable_types:
bc
unsigned int

variable_types:
text
char *

variable_types: j int

variable_types: n int

variable_types: len int

variable_types: charlength int

variable_types: p int

variable_types:
bytebuf
char *

variable_types:
glyph
struct glyph { char bits[16]; } *


decompiled_code:
void cpi_unmap()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void
cpi_unmap (cpi_handle_t *handle)
{
}

canonical_original_code:
void cpi_unmap(struct cpi_handle *handle)
{
}

variable_types: struct cpi_handle { void *cpi_file; int cpi_fd; int cpi_file_size; int font_is_nt; struct cpi_header { char tag[8]; char reserved[8]; short pointer_no; char pointer_type; int info_off; short entry_no; } *cpi_file_header; } *


decompiled_code:
__int64 __fastcall pso_accel_simple(double *a1, __int64 a2)
{
int v3; // eax
int v4; // eax

vector_mul_by_const(a2 + 64, a1[11]);
vector_sub_to(a1 + 24, a1 + 16, a2);
vector_sub_to(a1 + 32, a2 + 192, a2);
v3 = rand();
vector_mul_by_const(a1 + 24, (double)v3 / 2147483647.0 * a1[12]);
v4 = rand();
vector_mul_by_const(a1 + 32, (double)v4 / 2147483647.0 * a1[13]);
vector_add(a2 + 64, a1 + 24);
return vector_add(a2 + 64, a1 + 32);
}

original_code:
static inline void
pso_accel_simple (pso_problem_t *problem, pso_particle_t *this)
{
  vector_mul_by_const (&this->velocity,
      problem->inertia);
  vector_sub_to (&problem->temp_1,
    &problem->best_global_position,
    &this->position);
  vector_sub_to (&problem->temp_2,
    &this->best_local_position,
    &this->position);
  vector_mul_by_const (&problem->temp_1,
    (rand () / (double) 2147483647) * problem->global_delta);
  vector_mul_by_const (&problem->temp_2,
    (rand () / (double) 2147483647) * problem->local_delta);
  vector_add (&this->velocity, &problem->temp_1);
  vector_add (&this->velocity, &problem->temp_2);
}

canonical_original_code:
static inline void pso_accel_simple(struct pso_problem *problem, struct pso_particle *this)
{
  vector_mul_by_const (&this->velocity,
      problem->inertia);
  vector_sub_to (&problem->temp_1,
    &problem->best_global_position,
    &this->position);
  vector_sub_to (&problem->temp_2,
    &this->best_local_position,
    &this->position);
  vector_mul_by_const (&problem->temp_1,
    (rand () / (double) 2147483647) * problem->global_delta);
  vector_mul_by_const (&problem->temp_2,
    (rand () / (double) 2147483647) * problem->local_delta);
  vector_add (&this->velocity, &problem->temp_1);
  vector_add (&this->velocity, &problem->temp_2);
}

variable_types: struct pso_problem { struct pso_particle { struct vector { int dimension; void *base; double *coef; } position; struct vector velocity; double value; double best_local_value; struct vector best_local_position; } **particle_list; int particle_count; int t; int dimension; struct timeval { long tv_sec; long tv_usec; } start; int quiet; double (*fitness_function)(struct pso_problem *, struct vector *); double pos_min; double vel_min; double inertia; double global_delta; double local_delta; double best_global_value; double when; struct vector best_global_position; struct vector temp_1; } *

variable_types:
this
struct pso_particle *

user_defined_types: struct pso_problem { struct pso_particle **particle_list; int particle_count; int t; int dimension; struct timeval start; int quiet; double (*fitness_function)(struct pso_problem *, struct vector *); double pos_min; double vel_min; double inertia; double global_delta; double local_delta; double best_global_value; double when; struct vector best_global_position; struct vector temp_1; }

user_defined_types: struct pso_particle { struct vector position; struct vector velocity; double value; double best_local_value; struct vector best_local_position; }


decompiled_code:
int __fastcall got_better(__int64 a1)
{
__time_t v1; // rax
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
v1 = v4.tv_sec - *(_QWORD *)(a1 + 24);
v2 = (double)(LODWORD(v4.tv_usec) - *(_DWORD *)(a1 + 32)) / 1000000.0 + (double)(int)v1;
*(double *)(a1 + 120) = v2;
if ( !*(_DWORD *)(a1 + 40) )
{
printf("%-10lg: ", v2);
vector_print(stdout, a1 + 128);
LODWORD(v1) = printf(", b: %lg\n", *(double *)(a1 + 112));
}
return v1;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__time_t v1; // rax
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
v1 = v4.tv_sec - *(_QWORD *)(a1 + 24);
v2 = (double)(LODWORD(v4.tv_usec) - *(_DWORD *)(a1 + 32)) / 1000000.0 + (double)(int)v1;
*(double *)(a1 + 120) = v2;
if ( !*(_DWORD *)(a1 + 40) )
{
printf("%-10lg: ", v2);
vector_print(stdout, a1 + 128);
LODWORD(v1) = printf(", b: %lg\n", *(double *)(a1 + 112));
}
return v1;
}

original_code:
static inline void
got_better (pso_problem_t *problem)
{
  struct timeval end;
  gettimeofday (&end, ((void *)0));
  problem->when = (end.tv_sec - problem->start.tv_sec) +
      (end.tv_usec - problem->start.tv_usec) / 1000000.0;
  if (!problem->quiet)
  {
    printf ("%-10lg: ", problem->when);
    vector_print (stdout, &problem->best_global_position);
    printf (", b: %lg\n", problem->best_global_value);
  }
}

canonical_original_code:
static inline void got_better(struct pso_problem *problem)
{
  struct timeval end;
  gettimeofday (&end, ((void *)0));
  problem->when = (end.tv_sec - problem->start.tv_sec) +
      (end.tv_usec - problem->start.tv_usec) / 1000000.0;
  if (!problem->quiet)
  {
    printf ("%-10lg: ", problem->when);
    vector_print (stdout, &problem->best_global_position);
    printf (", b: %lg\n", problem->best_global_value);
  }
}

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

user_defined_types: struct vector { int dimension; void *base; double *coef; }


original_code:
static inline void
pso_move (pso_problem_t *problem, pso_particle_t *this)
{
  if (this->value > this->best_local_value)
  {
    this->best_local_value = this->value;
    vector_copy (&this->best_local_position, &this->position);
    if (this->value > problem->best_global_value)
    {
      problem->best_global_value = this->value;
      vector_copy (&problem->best_global_position, &this->position);
      got_better (problem);
    }
  }
  vector_add (&this->position,
              &this->velocity);
  this->value = (problem->fitness_function) (problem, &this->position);
}

canonical_original_code:
static inline void pso_move(struct pso_problem *problem, struct pso_particle *this)
{
  if (this->value > this->best_local_value)
  {
    this->best_local_value = this->value;
    vector_copy (&this->best_local_position, &this->position);
    if (this->value > problem->best_global_value)
    {
      problem->best_global_value = this->value;
      vector_copy (&problem->best_global_position, &this->position);
      got_better (problem);
    }
  }
  vector_add (&this->position,
              &this->velocity);
  this->value = (problem->fitness_function) (problem, &this->position);
}

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


original_code:
static inline void
pso_move_discrete (pso_problem_t *problem, pso_particle_t *this)
{
  int i;
  if (this->value > this->best_local_value)
  {
    this->best_local_value = this->value;
    vector_copy (&this->best_local_position, &this->position);
    if (this->value > problem->best_global_value)
    {
      problem->best_global_value = this->value;
      vector_copy (&problem->best_global_position, &this->position);
      got_better (problem);
    }
  }
  for (i = 0; i < problem->dimension; i++)
    if ((double) rand () / (double) 2147483647 <
      (1.0 / (1.0 + exp (-this->velocity.coef[i]))))
      this->position.coef[i] = 1.0;
    else
      this->position.coef[i] = 0.0;
  this->value = (problem->fitness_function) (problem, &this->position);
}

canonical_original_code:
static inline void pso_move_discrete(struct pso_problem *problem, struct pso_particle *this)
{
  int i;
  if (this->value > this->best_local_value)
  {
    this->best_local_value = this->value;
    vector_copy (&this->best_local_position, &this->position);
    if (this->value > problem->best_global_value)
    {
      problem->best_global_value = this->value;
      vector_copy (&problem->best_global_position, &this->position);
      got_better (problem);
    }
  }
  for (i = 0; i < problem->dimension; i++)
    if ((double) rand () / (double) 2147483647 <
      (1.0 / (1.0 + exp (-this->velocity.coef[i]))))
      this->position.coef[i] = 1.0;
    else
      this->position.coef[i] = 0.0;
  this->value = (problem->fitness_function) (problem, &this->position);
}

variable_types: i int


original_code:
void
pso_evolve (pso_problem_t *problem)
{
  int i;
  pso_particle_t *this;
  for (i = 0; i < problem->particle_count; i++)
  {
    this = problem->particle_list[i];
    pso_accel_simple (problem, this);
    pso_move (problem, this);
  }
  if (problem->inertia > 0.4)
    problem->inertia -= ((1.0 - 0.4) / 1000);
  problem->t++;
}

canonical_original_code:
void pso_evolve(struct pso_problem *problem)
{
  int i;
  struct pso_particle *this;
  for (i = 0; i < problem->particle_count; i++)
  {
    this = problem->particle_list[i];
    pso_accel_simple (problem, this);
    pso_move (problem, this);
  }
  if (problem->inertia > 0.4)
    problem->inertia -= ((1.0 - 0.4) / 1000);
  problem->t++;
}

variable_types: struct pso_particle { struct vector { int dimension; void *base; double *coef; } position; struct vector velocity; double value; double best_local_value; struct vector best_local_position; } *


original_code:
void
binary_pso_evolve (pso_problem_t *problem)
{
  int i;
  pso_particle_t *this;
  for (i = 0; i < problem->particle_count; i++)
  {
    this = problem->particle_list[i];
    pso_accel_simple (problem, this);
    pso_move_discrete (problem, this);
  }
  if (problem->inertia > 0.4)
    problem->inertia -= ((1.0 - 0.4) / 1000);
  problem->t++;
}

canonical_original_code:
void binary_pso_evolve(struct pso_problem *problem)
{
  int i;
  struct pso_particle *this;
  for (i = 0; i < problem->particle_count; i++)
  {
    this = problem->particle_list[i];
    pso_accel_simple (problem, this);
    pso_move_discrete (problem, this);
  }
  if (problem->inertia > 0.4)
    problem->inertia -= ((1.0 - 0.4) / 1000);
  problem->t++;
}


decompiled_code:
__int64 __fastcall pso_get_best(__int64 a1, __int64 a2)
{
return vector_copy(a2, a1 + 128);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
return vector_copy(a2, a1 + 128);
}

original_code:
void
pso_get_best (pso_problem_t *problem, vector_t *dest)
{
  vector_copy (dest, &problem->best_global_position);
}

canonical_original_code:
void pso_get_best(struct pso_problem *problem, struct vector *dest)
{
  vector_copy (dest, &problem->best_global_position);
}

variable_types:
dest
struct vector *


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

v2 = xmalloc(8LL * a2 + 63);
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = v2;
result = (v2 + 63) & 0xFFFFFFFFFFFFFFC0LL;
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

v2 = xmalloc(8LL * a2 + 63);
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = v2;
result = (v2 + 63) & 0xFFFFFFFFFFFFFFC0LL;
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void
vector_init (vector_t *vec, int dimension)
{
  void *base;
  vectcoef_t *coefs;
  base = xmalloc (sizeof (vectcoef_t) * (dimension) + 64 - 1);
  coefs = (vectcoef_t *)
    (((unsigned long) base + 64 - 1) & ~(64 - 1));
  vec->dimension = dimension;
  vec->base = base;
  vec->coef = coefs;
}

canonical_original_code:
void vector_init(struct vector *vec, int dimension)
{
  void *base;
  double *coefs;
  base = xmalloc (sizeof (vectcoef_t) * (dimension) + 64 - 1);
  coefs = (double *)
    (((unsigned long) base + 64 - 1) & ~(64 - 1));
  vec->dimension = dimension;
  vec->base = base;
  vec->coef = coefs;
}

variable_types: struct vector { int dimension; void *base; double *coef; } *

variable_types: dimension int

variable_types:
base
void *

variable_types:
coefs
double *


decompiled_code:
void __fastcall vector_free(__int64 a1)
{
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)(a1 + 8));
}

original_code:
void
vector_free (vector_t *vec)
{
  free (vec->base);
}

canonical_original_code:
void vector_free(struct vector *vec)
{
  free (vec->base);
}


original_code:
void
vector_add (vector_t *dest, const vector_t *orig)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] += orig->coef[i];
}

canonical_original_code:
void vector_add(struct vector *dest, struct vector *orig)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] += orig->coef[i];
}

variable_types:
orig
struct vector *

variable_types: siz int


original_code:
void
vector_sub (vector_t *dest, const vector_t *orig)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] -= orig->coef[i];
}

canonical_original_code:
void vector_sub(struct vector *dest, struct vector *orig)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] -= orig->coef[i];
}


original_code:
void
vector_sub_to (vector_t *dest, const vector_t *v1, const vector_t *v2)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = v1->coef[i] - v2->coef[i];
}

canonical_original_code:
void vector_sub_to(struct vector *dest, struct vector *v1, struct vector *v2)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = v1->coef[i] - v2->coef[i];
}


decompiled_code:
void __fastcall vector_add_ponderated(__int64 a1, __int64 a2, double a3)
{
int v5; // esi
__int64 v6; // rsi
__int64 v7; // rax

v5 = *(_DWORD *)a2;
if ( v5 > 0 )
{
v6 = 8LL * (unsigned int)v5;
v7 = 0LL;
do
{
*(double *)(*(_QWORD *)(a1 + 16) + v7) = a3 * *(double *)(*(_QWORD *)(a2 + 16) + v7)
+ *(double *)(*(_QWORD *)(a1 + 16) + v7);
v7 += 8LL;
}
while ( v7 != v6 );
}
}

original_code:
void
vector_add_ponderated (vector_t *dest, const vector_t *orig, vectcoef_t f)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] += f * orig->coef[i];
}

canonical_original_code:
void vector_add_ponderated(struct vector *dest, struct vector *orig, double f)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] += f * orig->coef[i];
}

variable_types: f double


decompiled_code:
void __fastcall vector_mul_by_const(unsigned int *a1, double a2)
{
__int64 v2; // rcx
__int64 v3; // rax

if ( (int)*a1 > 0 )
{
v2 = 8LL * *a1;
v3 = 0LL;
do
{
*(double *)(*((_QWORD *)a1 + 2) + v3) = a2 * *(double *)(*((_QWORD *)a1 + 2) + v3);
v3 += 8LL;
}
while ( v3 != v2 );
}
}

original_code:
void
vector_mul_by_const (vector_t *dest, vectcoef_t f)
{
  int i, siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] *= f;
}

canonical_original_code:
void vector_mul_by_const(struct vector *dest, double f)
{
  int i; int siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] *= f;
}


decompiled_code:
void __fastcall vector_mul_by_const_to(unsigned int *a1, __int64 a2, double a3)
{
__int64 v4; // rsi
__int64 v5; // rax

if ( (int)*a1 > 0 )
{
v4 = 8LL * *a1;
v5 = 0LL;
do
{
*(double *)(*((_QWORD *)a1 + 2) + v5) = a3 * *(double *)(*(_QWORD *)(a2 + 16) + v5);
v5 += 8LL;
}
while ( v5 != v4 );
}
}

original_code:
void
vector_mul_by_const_to (vector_t *dest, const vector_t *orig, vectcoef_t f)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = f * orig->coef[i];
}

canonical_original_code:
void vector_mul_by_const_to(struct vector *dest, struct vector *orig, double f)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = f * orig->coef[i];
}


decompiled_code:
void __fastcall vector_zero(unsigned int *a1)
{
__int64 v1; // rcx
__int64 v2; // rax

if ( (int)*a1 > 0 )
{
v1 = 8LL * *a1;
v2 = 0LL;
do
{
*(_QWORD *)(*((_QWORD *)a1 + 2) + v2) = 0LL;
v2 += 8LL;
}
while ( v2 != v1 );
}
}

original_code:
void
vector_zero (vector_t *dest)
{
  int i;
  int siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = 0.0;
}

canonical_original_code:
void vector_zero(struct vector *dest)
{
  int i;
  int siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = 0.0;
}


original_code:
void
vector_copy (vector_t *dest, const vector_t *orig)
{
  int i;
  int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = orig->coef[i];
}

canonical_original_code:
void vector_copy(struct vector *dest, struct vector *orig)
{
  int i;
  int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = orig->coef[i];
}


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

if ( *(_DWORD *)a2 != 3 )
{
fprintf(stderr, "%s: vector is not tri-dimensional\n", "vector_cross_product");
abort();
}
**(double **)(a1 + 16) = *(double *)(*(_QWORD *)(a2 + 16) + 8LL) * *(double *)(*(_QWORD *)(a3 + 16) + 16LL)
- *(double *)(*(_QWORD *)(a2 + 16) + 16LL) * *(double *)(*(_QWORD *)(a3 + 16) + 8LL);
*(double *)(*(_QWORD *)(a1 + 16) + 8LL) = *(double *)(*(_QWORD *)(a2 + 16) + 16LL) * **(double **)(a3 + 16)
- **(double **)(a2 + 16) * *(double *)(*(_QWORD *)(a3 + 16) + 16LL);
result = *(double **)(a3 + 16);
*(double *)(*(_QWORD *)(a1 + 16) + 16LL) = **(double **)(a2 + 16) * result[1]
- *(double *)(*(_QWORD *)(a2 + 16) + 8LL) * *result;
return result;
}

original_code:
void
vector_cross_product (vector_t *dest, const vector_t *v1, const vector_t *v2)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1];
  dest->coef[1] = v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2];
  dest->coef[2] = v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0];
}

canonical_original_code:
void vector_cross_product(struct vector *dest, struct vector *v1, struct vector *v2)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1];
  dest->coef[1] = v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2];
  dest->coef[2] = v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0];
}


decompiled_code:
double *__fastcall vector_cross_product_ponderated(__int64 a1, __int64 a2, __int64 a3, double a4)
{
double *result; // rax

if ( *(_DWORD *)a2 != 3 )
{
fprintf(stderr, "%s: vector is not tri-dimensional\n", "vector_cross_product_ponderated");
abort();
}
**(double **)(a1 + 16) = (*(double *)(*(_QWORD *)(a2 + 16) + 8LL) * *(double *)(*(_QWORD *)(a3 + 16) + 16LL)
- *(double *)(*(_QWORD *)(a2 + 16) + 16LL) * *(double *)(*(_QWORD *)(a3 + 16) + 8LL))
* a4;
*(double *)(*(_QWORD *)(a1 + 16) + 8LL) = (*(double *)(*(_QWORD *)(a2 + 16) + 16LL) * **(double **)(a3 + 16)
- **(double **)(a2 + 16) * *(double *)(*(_QWORD *)(a3 + 16) + 16LL))
* a4;
result = *(double **)(a3 + 16);
*(double *)(*(_QWORD *)(a1 + 16) + 16LL) = (**(double **)(a2 + 16) * result[1]
- *(double *)(*(_QWORD *)(a2 + 16) + 8LL) * *result)
* a4;
return result;
}

original_code:
void
vector_cross_product_ponderated (vector_t *dest,
                                 const vector_t *v1,
                                 const vector_t *v2,
                                 vectcoef_t f)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = f * (v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1]);
  dest->coef[1] = f * (v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2]);
  dest->coef[2] = f * (v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0]);
}

canonical_original_code:
void vector_cross_product_ponderated(struct vector *dest, struct vector *v1, struct vector *v2, double f)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = f * (v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1]);
  dest->coef[1] = f * (v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2]);
  dest->coef[2] = f * (v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0]);
}


decompiled_code:
double __fastcall vector_norm(__int64 a1)
{
double *v1; // rax
__int64 v2; // rdx
double v3; // xmm1_8

if ( *(int *)a1 <= 0 )
{
v3 = 0.0;
return sqrt(v3);
}
v1 = *(double **)(a1 + 16);
v2 = (__int64)&v1[(unsigned int)(*(_DWORD *)a1 - 1) + 1];
v3 = 0.0;
do
{
v3 = v3 + *v1 * *v1;
++v1;
}
while ( v1 != (double *)v2 );
if ( v3 >= 0.0 )
return sqrt(v3);
return sqrt(v3);
}

original_code:
vectcoef_t
vector_norm (const vector_t *v1)
{
  int i, siz;
  vectcoef_t result = 0.0;
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += v1->coef[i] * v1->coef[i];
  return sqrt (result);
}

canonical_original_code:
double vector_norm(struct vector *v1)
{
  int i; int siz;
  double result = 0.0;
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += v1->coef[i] * v1->coef[i];
  return sqrt (result);
}

variable_types: result double

return_type: double


original_code:
vectcoef_t
vector_eucdist (const vector_t *v1, const vector_t *v2)
{
  int i, siz;
  vectcoef_t result = 0.0;
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += (v1->coef[i] - v2->coef[i]) * (v1->coef[i] - v2->coef[i]);
  return sqrt (result);
}

canonical_original_code:
double vector_eucdist(struct vector *v1, struct vector *v2)
{
  int i; int siz;
  double result = 0.0;
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += (v1->coef[i] - v2->coef[i]) * (v1->coef[i] - v2->coef[i]);
  return sqrt (result);
}


decompiled_code:
int *__fastcall hook_bucket_new(int a1)
{
int *v1; // rax
int *v2; // rcx
int *v3; // rax

if ( a1 <= 0 )
{
errno_save();
fwrite(" * LibSIM error: hook.c:33: hooks < 1? wtf\n", 1uLL, 0x2BuLL, stderr);
errno_restore();
v2 = 0LL;
}
else
{
v1 = (int *)xmalloc(32LL * (a1 - 1) + 16);
v2 = v1;
if ( v1 )
{
*v1 = a1;
v3 = v1 + 2;
do
{
*(_QWORD *)v3 = 0LL;
v3 += 2;
}
while ( v3 != &v2[2 * (a1 - 1) + 4] );
}
}
return v2;
}

canonical_decompiled_code:
int *__fastcall func0(int a1)
{
int *v1; // rax
int *v2; // rcx
int *v3; // rax

if ( a1 <= 0 )
{
errno_save();
fwrite(" * LibSIM error: hook.c:33: hooks < 1? wtf\n", 1uLL, 0x2BuLL, stderr);
errno_restore();
v2 = 0LL;
}
else
{
v1 = (int *)xmalloc(32LL * (a1 - 1) + 16);
v2 = v1;
if ( v1 )
{
*v1 = a1;
v3 = v1 + 2;
do
{
*(_QWORD *)v3 = 0LL;
v3 += 2;
}
while ( v3 != &v2[2 * (a1 - 1) + 4] );
}
}
return v2;
}

original_code:
struct hook_bucket *
hook_bucket_new (int hooks)
{
  struct hook_bucket *new;
  int i;
  if (hooks < 1)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "33" ": " "hooks < 1? wtf\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  if ((new = xmalloc (sizeof (struct hook_bucket) +
                 sizeof (struct hook_func) * (hooks - 1))) == ((void *)0))
    return ((void *)0);
  new->hb_hook_count = hooks;
  for (i = 0; i < hooks; i++)
    new->hb_hooks[i] = ((void *)0);
  return new;
}

canonical_original_code:
struct hook_bucket *hook_bucket_new(int hooks)
{
  struct hook_bucket *new;
  int i;
  if (hooks < 1)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "33" ": " "hooks < 1? wtf\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  if ((new = xmalloc (sizeof (struct hook_bucket) +
                 sizeof (struct hook_func) * (hooks - 1))) == ((void *)0))
    return ((void *)0);
  new->hb_hook_count = hooks;
  for (i = 0; i < hooks; i++)
    new->hb_hooks[i] = ((void *)0);
  return new;
}

variable_types: hooks int

variable_types: struct hook_bucket { int hb_hook_count; struct hook_func { int (*hf_func)(int, void *, void *); void *hf_data; struct hook_func *hf_next; struct hook_func *hf_prev; } *hb_hooks[1]; } *

user_defined_types: struct hook_bucket { int hb_hook_count; struct hook_func *hb_hooks[1]; }