main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
const char *v6; // rdi
__int64 v7; // r14
char v8; // dl
int *v9; // rax
FILE *v10; // rdi
int *v11; // rbx
int v12; // eax
int v13; // ebx
int v14; // edi
char v16; // al
int v17; // edx
int v18; // eax
int v19; // eax
int v20; // eax

f = stdin;
filenof = fileno(stdin);
oldfileflag = fcntl(filenof, 3);
v4 = 1;
if ( argc > 1 )
{
do
{
v5 = v4 + 1;
v6 = argv[v4];
v7 = v4;
if ( *v6 == 45 )
{
v8 = v6[1];
if ( v8 == 69 )
{
v5 = v4 + 2;
endname = (char *)argv[v7 + 1];
}
else
{
switch ( v8 )
{
case 'T':
v5 = v4 + 2;
propname = (char *)argv[v7 + 1];
break;
case 'a':
v19 = strtol(argv[v7 + 1], 0LL, 0);
if ( v19 < 32 )
v19 = 32;
++v5;
allocsize = v19;
break;
case 'd':
if ( !strcmp(v6 + 2, "isplay") )
{
++v5;
displayname = (char *)argv[v7 + 1];
}
break;
case 'm':
v16 = v6[2];
if ( v16 == 105 )
{
v20 = strtol(argv[v7 + 1], 0LL, 0);
if ( v20 <= 0 )
v20 = 1;
++v5;
minsize = v20;
}
else if ( v16 == 97 )
{
v17 = strtol(argv[v7 + 1], 0LL, 0);
v18 = minsize;
if ( minsize <= v17 )
v18 = v17;
++v5;
maxsize = v18;
}
break;
case 'w':
if ( !strcmp(v6 + 2, "indow") )
{
++v5;
testwin = strtol(argv[v7 + 1], 0LL, 0);
}
break;
default:
break;
}
}
}
v4 = v5;
}
while ( argc > v5 );
}
server_init();
signal(1, (__sighandler_t)handle);
signal(2, (__sighandler_t)handle);
signal(3, (__sighandler_t)handle);
signal(4, (__sighandler_t)handle);
signal(6, (__sighandler_t)handle);
signal(8, (__sighandler_t)handle);
signal(7, (__sighandler_t)handle);
signal(11, (__sighandler_t)handle);
signal(31, (__sighandler_t)handle);
signal(13, (__sighandler_t)handle);
signal(14, alarm_handle);
signal(15, (__sighandler_t)handle);
signal(23, input_handle);
signal(29, input_handle);
signal(24, (__sighandler_t)handle);
signal(25, (__sighandler_t)handle);
signal(10, (__sighandler_t)handle);
signal(12, (__sighandler_t)handle);
signal(29, input_handle);
get_and_set();
alarm(alarm_needed);
while ( !feof(f) )
{
while ( 1 )
{
v9 = _errno_location();
v10 = f;
*v9 = 0;
v11 = v9;
v12 = fgetc(v10);
if ( v12 == -1 || *v11 )
break;
ungetc(v12, f);
get_and_set();
if ( feof(f) )
goto LABEL_12;
}
}
LABEL_12:
alarm_needed = 0;
do
{
do
{
do
{
XNextEvent(display, &event);
check_event();
}
while ( !propempty );
}
while ( !other_prog_ex );
v13 = totlen;
v14 = totlen;
if ( maxsize <= totlen )
v14 = maxsize;
set_property(v14);
}
while ( v13 );
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
const char *v6; // rdi
__int64 v7; // r14
char v8; // dl
int *v9; // rax
FILE *v10; // rdi
int *v11; // rbx
int v12; // eax
int v13; // ebx
int v14; // edi
char v16; // al
int v17; // edx
int v18; // eax
int v19; // eax
int v20; // eax

f = stdin;
filenof = fileno(stdin);
oldfileflag = fcntl(filenof, 3);
v4 = 1;
if ( argc > 1 )
{
do
{
v5 = v4 + 1;
v6 = argv[v4];
v7 = v4;
if ( *v6 == 45 )
{
v8 = v6[1];
if ( v8 == 69 )
{
v5 = v4 + 2;
endname = (char *)argv[v7 + 1];
}
else
{
switch ( v8 )
{
case 'T':
v5 = v4 + 2;
propname = (char *)argv[v7 + 1];
break;
case 'a':
v19 = strtol(argv[v7 + 1], 0LL, 0);
if ( v19 < 32 )
v19 = 32;
++v5;
allocsize = v19;
break;
case 'd':
if ( !strcmp(v6 + 2, "isplay") )
{
++v5;
displayname = (char *)argv[v7 + 1];
}
break;
case 'm':
v16 = v6[2];
if ( v16 == 105 )
{
v20 = strtol(argv[v7 + 1], 0LL, 0);
if ( v20 <= 0 )
v20 = 1;
++v5;
minsize = v20;
}
else if ( v16 == 97 )
{
v17 = strtol(argv[v7 + 1], 0LL, 0);
v18 = minsize;
if ( minsize <= v17 )
v18 = v17;
++v5;
maxsize = v18;
}
break;
case 'w':
if ( !strcmp(v6 + 2, "indow") )
{
++v5;
testwin = strtol(argv[v7 + 1], 0LL, 0);
}
break;
default:
break;
}
}
}
v4 = v5;
}
while ( argc > v5 );
}
func3();
signal(1, (__sighandler_t)handle);
signal(2, (__sighandler_t)handle);
signal(3, (__sighandler_t)handle);
signal(4, (__sighandler_t)handle);
signal(6, (__sighandler_t)handle);
signal(8, (__sighandler_t)handle);
signal(7, (__sighandler_t)handle);
signal(11, (__sighandler_t)handle);
signal(31, (__sighandler_t)handle);
signal(13, (__sighandler_t)handle);
signal(14, alarm_handle);
signal(15, (__sighandler_t)handle);
signal(23, input_handle);
signal(29, input_handle);
signal(24, (__sighandler_t)handle);
signal(25, (__sighandler_t)handle);
signal(10, (__sighandler_t)handle);
signal(12, (__sighandler_t)handle);
signal(29, input_handle);
func9();
alarm(alarm_needed);
while ( !feof(f) )
{
while ( 1 )
{
v9 = _errno_location();
v10 = f;
*v9 = 0;
v11 = v9;
v12 = fgetc(v10);
if ( v12 == -1 || *v11 )
break;
ungetc(v12, f);
func9();
if ( feof(f) )
goto LABEL_12;
}
}
LABEL_12:
alarm_needed = 0;
do
{
do
{
do
{
XNextEvent(display, &event);
func4();
}
while ( !propempty );
}
while ( !other_prog_ex );
v13 = totlen;
v14 = totlen;
if ( maxsize <= totlen )
v14 = maxsize;
func7(v14);
}
while ( v13 );
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int i=1;
    int endprop=0;
    f = stdin;
    filenof=fileno(f);
    oldfileflag=fcntl(filenof,3);
    for (i=1; i<argc; i++) {
 if (argv[i][0]=='-') {
     switch (argv[i][1]) {
     case 'T': propname = argv[i+1]; i++; break;
     case 'E': endname = argv[i+1]; i++; break;
     case 'm':
  if (argv[i][2]=='i') {
      minsize = strtol(argv[i+1],((void *)0), 0);
      if (minsize<1) minsize=1;
      i++;
  } else if (argv[i][2]=='a') {
      maxsize = strtol(argv[i+1],((void *)0),0);
      if (maxsize<minsize) maxsize=minsize;
      i++;
  }
  break;
     case 'a':
         allocsize=strtol(argv[i+1],((void *)0),0);
  if (allocsize<32) allocsize=32;
  i++;
  break;
     case 'd':
  if (!strcmp(argv[i]+2, "isplay")) {
      displayname = argv[i+1];
      i++;
  }
  break;
     case 'w':
  if (!strcmp(argv[i]+2,"indow")) {
      testwin = strtol(argv[i+1],((void *)0),0);
      i++;
  }
  break;
     default: break;
     }
 }
    }
    server_init();
    signal(1, handle);
    signal(2, handle);
    signal(3, handle);
    signal(4, handle);
    signal(6, handle);
    signal(8, handle);
    signal(7, handle);
    signal(11, handle);
    signal(31, handle);
    signal(13, handle);
    signal(14, alarm_handle);
    signal(15, handle);
    signal(23, input_handle);
    signal(29, input_handle);
    signal(24, handle);
    signal(25, handle);
    signal(10, handle);
    signal(12, handle);
    signal(29, input_handle);
    get_and_set();
    alarm(alarm_needed);
    while (!feof(f)) {
 (*__errno_location ())=0;
 i=fgetc(f);
 if (i!=(-1) && !(*__errno_location ())) {
     ungetc(i,f);
     get_and_set();
 }
    }
    alarm_needed=0;
    while (!endprop) {
 XNextEvent(display, &event);
 check_event();
 if (propempty && other_prog_ex) {
     endprop = (totlen==0);
     set_property(totlen<maxsize?totlen:maxsize);
 }
    }
    XDeleteProperty(display, testwin, testend);
    XCloseDisplay(display);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i = 1;
    int endprop = 0;
    f = stdin;
    filenof=fileno(f);
    oldfileflag=fcntl(filenof,3);
    for (i=1; i<argc; i++) {
 if (argv[i][0]=='-') {
     switch (argv[i][1]) {
     case 'T': propname = argv[i+1]; i++; break;
     case 'E': endname = argv[i+1]; i++; break;
     case 'm':
  if (argv[i][2]=='i') {
      minsize = strtol(argv[i+1],((void *)0), 0);
      if (minsize<1) minsize=1;
      i++;
  } else if (argv[i][2]=='a') {
      maxsize = strtol(argv[i+1],((void *)0),0);
      if (maxsize<minsize) maxsize=minsize;
      i++;
  }
  break;
     case 'a':
         allocsize=strtol(argv[i+1],((void *)0),0);
  if (allocsize<32) allocsize=32;
  i++;
  break;
     case 'd':
  if (!strcmp(argv[i]+2, "isplay")) {
      displayname = argv[i+1];
      i++;
  }
  break;
     case 'w':
  if (!strcmp(argv[i]+2,"indow")) {
      testwin = strtol(argv[i+1],((void *)0),0);
      i++;
  }
  break;
     default: break;
     }
 }
    }
    server_init();
    signal(1, handle);
    signal(2, handle);
    signal(3, handle);
    signal(4, handle);
    signal(6, handle);
    signal(8, handle);
    signal(7, handle);
    signal(11, handle);
    signal(31, handle);
    signal(13, handle);
    signal(14, alarm_handle);
    signal(15, handle);
    signal(23, input_handle);
    signal(29, input_handle);
    signal(24, handle);
    signal(25, handle);
    signal(10, handle);
    signal(12, handle);
    signal(29, input_handle);
    get_and_set();
    alarm(alarm_needed);
    while (!feof(f)) {
 (*__errno_location ())=0;
 i=fgetc(f);
 if (i!=(-1) && !(*__errno_location ())) {
     ungetc(i,f);
     get_and_set();
 }
    }
    alarm_needed=0;
    while (!endprop) {
 XNextEvent(display, &event);
 check_event();
 if (propempty && other_prog_ex) {
     endprop = (totlen==0);
     set_property(totlen<maxsize?totlen:maxsize);
 }
    }
    XDeleteProperty(display, testwin, testend);
    XCloseDisplay(display);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: endprop int


repo: jff/mathspad

decompiled_code:
// attributes: thunk
__int64 lookup_int_constant()
{
return define_int_constant();
}

canonical_decompiled_code:
__int64 func0()
{
return define_int_constant();
}

original_code:
Argument lookup_int_constant(int n)
{
    return define_int_constant(n);
}

canonical_original_code:
int lookup_int_constant(int n)
{
    return define_int_constant(n);
}

variable_types: n int

return_type: int


decompiled_code:
// attributes: thunk
__int64 lookup_string_constant()
{
return define_string_constant();
}

canonical_decompiled_code:
__int64 func1()
{
return define_string_constant();
}

original_code:
Argument lookup_string_constant(Uchar *s)
{
    return define_string_constant(s);
}

canonical_original_code:
int lookup_string_constant(unsigned short *s)
{
    return define_string_constant(s);
}

variable_types:
s
unsigned short *


decompiled_code:
// attributes: thunk
__int64 lookup_real_constant()
{
return define_real_constant();
}

canonical_decompiled_code:
__int64 func2()
{
return define_real_constant();
}

original_code:
Argument lookup_real_constant(double r)
{
    return define_real_constant(r);
}

canonical_original_code:
int lookup_real_constant(double r)
{
    return define_real_constant(r);
}

variable_types: r double


statetomode

decompiled_code:
__int64 __fastcall statetomode(int a1)
{
return a1 & 0x7D | (a1 << 16) & 0x7D0000u;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return a1 & 0x7D | (a1 << 16) & 0x7D0000u;
}

canonical_original_code:
static unsigned int statetomode(unsigned int state)
{
    return ((state&(0x01|0x04|0x08|0x10|0x20|0x40))|((state&(0x01|0x04|0x08|0x10|0x20|0x40))<<16));
}

variable_types:
state
unsigned int

return_type: unsigned int


keynumtounicode

decompiled_code:
__int64 __fastcall keynumtounicode(__int16 a1)
{
if ( !keynummap )
keynummap = umap_load_file("X11keysym", 2LL, 3LL, 0LL);
return *(unsigned __int16 *)(*(_QWORD *)(keynummap + 8LL * HIBYTE(a1)) + 2LL * (unsigned __int8)a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
if ( !keynummap )
keynummap = umap_load_file("X11keysym", 2LL, 3LL, 0LL);
return *(unsigned __int16 *)(*(_QWORD *)(keynummap + 8LL * HIBYTE(a1)) + 2LL * (unsigned __int8)a1);
}

original_code:
static int keynumtounicode(KeyNum keynum)
{
  if (!keynummap) {
    (keynummap)=(MapUchar) umap_load_file((mapkeysymname), sizeof(Uchar), 3, 0);
  }
  return ((keynummap)[((Uchar)(keynum&0xffff))/256][((Uchar)(keynum&0xffff))%256]);
}

canonical_original_code:
static int keynumtounicode(unsigned int keynum)
{
  if (!keynummap) {
    (keynummap)=(unsigned short **) umap_load_file((mapkeysymname), sizeof(Uchar), 3, 0);
  }
  return ((keynummap)[((Uchar)(keynum&0xffff))/256][((Uchar)(keynum&0xffff))%256]);
}

variable_types:
keynum
unsigned int


keyandmodetochar

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

v2 = a1;
result = keynumtounicode(a1);
if ( (unsigned int)(result - 32) <= 0x5F )
{
if ( (a2 & 8) != 0 )
v2 = a1 + 128;
if ( (a2 & 4) != 0 && (v2 & 0x40) != 0 )
{
if ( (v2 & 0x20) != 0 )
v2 -= 32;
v2 -= 64;
}
result = v2;
}
return result;
}

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

v2 = a1;
result = func1(a1);
if ( (unsigned int)(result - 32) <= 0x5F )
{
if ( (a2 & 8) != 0 )
v2 = a1 + 128;
if ( (a2 & 4) != 0 && (v2 & 0x40) != 0 )
{
if ( (v2 & 0x20) != 0 )
v2 -= 32;
v2 -= 64;
}
result = v2;
}
return result;
}

original_code:
static int keyandmodetochar(KeyNum keynum, KeyMode keymode)
{
  int i;
  i = keynumtounicode(keynum);
  if (i > 127 || i<32) return i;
  if (keymode & 0x08) keynum=keynum+0x80;
  if (keymode & 0x04 && (keynum&0x40)) {
    if (keynum & 0x20) keynum=keynum-32;
    keynum=keynum-64;
  }
  return keynum;
}

canonical_original_code:
static int keyandmodetochar(unsigned int keynum, unsigned int keymode)
{
  int i;
  i = keynumtounicode(keynum);
  if (i > 127 || i<32) return i;
  if (keymode & 0x08) keynum=keynum+0x80;
  if (keymode & 0x04 && (keynum&0x40)) {
    if (keynum & 0x20) keynum=keynum-32;
    keynum=keynum-64;
  }
  return keynum;
}

variable_types:
keymode
unsigned int

variable_types: i int


StringToKey

decompiled_code:
KeySym __fastcall StringToKey(char *a1)
{
KeySym result; // rax
char *v2; // rbp
int v3; // edx
int v4; // eax
char v5; // dl
char *v6; // rbp

if ( !a1 )
return 0LL;
result = (unsigned int)*a1;
v2 = a1;
if ( !*a1 || a1[1] )
{
result = XStringToKeysym(a1);
if ( !result )
{
if ( !memcmp(a1, "double_", 7uLL) )
{
v2 += 7;
v3 = 32592;
}
else
{
v3 = 32576;
if ( !memcmp(v2, "triple_", 7uLL) )
{
v2 += 7;
v3 = 32608;
}
}
if ( !memcmp(v2, "down_", 5uLL) || !memcmp(v2, "drag_", 5uLL) )
{
v6 = v2 + 5;
v3 -= 64;
if ( !memcmp(v6, "mouse_", 6uLL) )
{
v4 = v6[6];
if ( (unsigned __int8)(v6[6] - 49) <= 4u && !v6[7] )
return (unsigned int)(v3 + v4 - 48);
}
}
else
{
if ( !memcmp(v2, "mouse_", 6uLL) )
{
v4 = v2[6];
if ( (unsigned __int8)(v2[6] - 49) <= 4u && !v2[7] )
return (unsigned int)(v3 + v4 - 48);
}
if ( v3 == 32576 && !memcmp(v2, "mouse_movement", 0xEuLL) )
{
v5 = v2[14];
result = 32704LL;
if ( !v5 )
return result;
if ( v5 == 95 && (unsigned __int8)(v2[15] - 49) <= 4u )
{
result = (unsigned int)(v2[15] + 32656);
if ( v2[16] )
result = 0LL;
return result;
}
}
}
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
KeySym __fastcall func3(char *a1)
{
KeySym result; // rax
char *v2; // rbp
int v3; // edx
int v4; // eax
char v5; // dl
char *v6; // rbp

if ( !a1 )
return 0LL;
result = (unsigned int)*a1;
v2 = a1;
if ( !*a1 || a1[1] )
{
result = XStringToKeysym(a1);
if ( !result )
{
if ( !memcmp(a1, "double_", 7uLL) )
{
v2 += 7;
v3 = 32592;
}
else
{
v3 = 32576;
if ( !memcmp(v2, "triple_", 7uLL) )
{
v2 += 7;
v3 = 32608;
}
}
if ( !memcmp(v2, "down_", 5uLL) || !memcmp(v2, "drag_", 5uLL) )
{
v6 = v2 + 5;
v3 -= 64;
if ( !memcmp(v6, "mouse_", 6uLL) )
{
v4 = v6[6];
if ( (unsigned __int8)(v6[6] - 49) <= 4u && !v6[7] )
return (unsigned int)(v3 + v4 - 48);
}
}
else
{
if ( !memcmp(v2, "mouse_", 6uLL) )
{
v4 = v2[6];
if ( (unsigned __int8)(v2[6] - 49) <= 4u && !v2[7] )
return (unsigned int)(v3 + v4 - 48);
}
if ( v3 == 32576 && !memcmp(v2, "mouse_movement", 0xEuLL) )
{
v5 = v2[14];
result = 32704LL;
if ( !v5 )
return result;
if ( v5 == 95 && (unsigned __int8)(v2[15] - 49) <= 4u )
{
result = (unsigned int)(v2[15] + 32656);
if ( v2[16] )
result = 0LL;
return result;
}
}
}
return 0LL;
}
}
return result;
}

variable_types:
s
char *

variable_types:
ks
unsigned long

variable_types:
k
unsigned int


KeyToString

decompiled_code:
char *__fastcall KeyToString(unsigned int a1)
{
char *result; // rax
int v2; // edx
char *v3; // rax
char *v4; // rdx
int v5; // ecx

result = XKeysymToString(a1);
if ( !result && (a1 & 0xFF00) == 32512 )
{
v2 = a1 & 0xFF30;
if ( v2 == 32528 )
{
keystringbuf = 0x5F656C62756F64LL;
v3 = (char *)&keystringbuf + 7;
}
else
{
v3 = (char *)&keystringbuf;
if ( v2 == 32544 )
{
keystringbuf = 0x5F656C70697274LL;
v3 = (char *)&keystringbuf + 7;
}
}
v4 = v3 + 5;
v5 = a1 & 0xFFC0;
if ( v5 == 32512 )
{
strcpy(v3, "down_");
strcpy(v3 + 5, "mouse");
v4 = v3 + 10;
}
else if ( v5 == 32640 )
{
strcpy(v3, "drag_");
strcpy(v3 + 5, "mouse");
v4 = v3 + 10;
}
else
{
strcpy(v3, "mouse");
if ( v5 == 32704 )
{
strcpy(v3 + 5, "_movement");
v4 = v3 + 14;
}
}
result = (char *)&keystringbuf;
if ( (a1 & 0xF) != 0 )
{
*v4 = 95;
*(_WORD *)(v4 + 1) = (unsigned __int8)((a1 & 0xF) + 48);
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
char *result; // rax
int v2; // edx
char *v3; // rax
char *v4; // rdx
int v5; // ecx

result = XKeysymToString(a1);
if ( !result && (a1 & 0xFF00) == 32512 )
{
v2 = a1 & 0xFF30;
if ( v2 == 32528 )
{
keystringbuf = 0x5F656C62756F64LL;
v3 = (char *)&keystringbuf + 7;
}
else
{
v3 = (char *)&keystringbuf;
if ( v2 == 32544 )
{
keystringbuf = 0x5F656C70697274LL;
v3 = (char *)&keystringbuf + 7;
}
}
v4 = v3 + 5;
v5 = a1 & 0xFFC0;
if ( v5 == 32512 )
{
strcpy(v3, "down_");
strcpy(v3 + 5, "mouse");
v4 = v3 + 10;
}
else if ( v5 == 32640 )
{
strcpy(v3, "drag_");
strcpy(v3 + 5, "mouse");
v4 = v3 + 10;
}
else
{
strcpy(v3, "mouse");
if ( v5 == 32704 )
{
strcpy(v3 + 5, "_movement");
v4 = v3 + 14;
}
}
result = (char *)&keystringbuf;
if ( (a1 & 0xF) != 0 )
{
*v4 = 95;
*(_WORD *)(v4 + 1) = (unsigned __int8)((a1 & 0xF) + 48);
}
}
return result;
}

original_code:
char *KeyToString(KeyNum key)
{
    char *s;
    s = XKeysymToString(key);
    if (s) return s;
    s=keystringbuf;
    if ((((key)&0xFF00)==0x7F00)) {
      if ((((key)&0xFF30)==0x7F10)) { strcpy(s,"double_"); s=s+7; }
      if ((((key)&0xFF30)==0x7F20)) { strcpy(s,"triple_"); s=s+7; }
      if ((((key)&0xFFC0)==0x7F00)) { strcpy(s,"down_"); s=s+5; }
      if ((((key)&0xFFC0)==0x7F80)) { strcpy(s,"drag_"); s=s+5; }
      strcpy(s,"mouse"); s=s+5;
      if ((((key)&0xFFC0)==0x7FC0)) { strcpy(s,"_movement"); s=s+9; }
      if (((key)&0xf)) { *s++='_'; *s++='0'+((key)&0xf); *s='\0'; }
      return keystringbuf;
    }
    return 0;
}

canonical_original_code:
char *KeyToString(unsigned int key)
{
    char *s;
    s = XKeysymToString(key);
    if (s) return s;
    s=keystringbuf;
    if ((((key)&0xFF00)==0x7F00)) {
      if ((((key)&0xFF30)==0x7F10)) { strcpy(s,"double_"); s=s+7; }
      if ((((key)&0xFF30)==0x7F20)) { strcpy(s,"triple_"); s=s+7; }
      if ((((key)&0xFFC0)==0x7F00)) { strcpy(s,"down_"); s=s+5; }
      if ((((key)&0xFFC0)==0x7F80)) { strcpy(s,"drag_"); s=s+5; }
      strcpy(s,"mouse"); s=s+5;
      if ((((key)&0xFFC0)==0x7FC0)) { strcpy(s,"_movement"); s=s+9; }
      if (((key)&0xf)) { *s++='_'; *s++='0'+((key)&0xf); *s='\0'; }
      return keystringbuf;
    }
    return 0;
}

variable_types:
key
unsigned int

return_type: char *


IsModifier

decompiled_code:
_BOOL8 __fastcall IsModifier(int a1)
{
_BOOL8 result; // rax

if ( (unsigned int)(a1 - 65505) <= 0xD || (unsigned int)(a1 - 65025) <= 0x12 )
result = 1LL;
else
result = (unsigned int)(a1 - 65406) <= 1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(int a1)
{
_BOOL8 result; // rax

if ( (unsigned int)(a1 - 65505) <= 0xD || (unsigned int)(a1 - 65025) <= 0x12 )
result = 1LL;
else
result = (unsigned int)(a1 - 65406) <= 1;
return result;
}

original_code:
int IsModifier(KeyNum key)
{
  return ((((KeySym)(key) >= 0xffe1) && ((KeySym)(key) <= 0xffee)) || (((KeySym)(key) >= 0xfe01) && ((KeySym)(key) <= 0xfe13)) || ((KeySym)(key) == 0xff7e) || ((KeySym)(key) == 0xff7f));
}

canonical_original_code:
int IsModifier(unsigned int key)
{
  return ((((KeySym)(key) >= 0xffe1) && ((KeySym)(key) <= 0xffee)) || (((KeySym)(key) >= 0xfe01) && ((KeySym)(key) <= 0xfe13)) || ((KeySym)(key) == 0xff7e) || ((KeySym)(key) == 0xff7f));
}


decompiled_code:
_BOOL8 __fastcall valid_start_position(_WORD *a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( (*(_BYTE *)(*(_QWORD *)(uctype + 8LL * (unsigned __int8)HIBYTE(*a1)) + 4LL * (unsigned __int8)*a1 + 1) & 0x20) == 0 )
v1 = (unsigned __int16)(*a1 + 9216) > 0x3FFu;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_WORD *a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( (*(_BYTE *)(*(_QWORD *)(uctype + 8LL * (unsigned __int8)HIBYTE(*a1)) + 4LL * (unsigned __int8)*a1 + 1) & 0x20) == 0 )
v1 = (unsigned __int16)(*a1 + 9216) > 0x3FFu;
return v1;
}

original_code:
int valid_start_position(Uchar *string)
{
    return (!(((uctype)[((Uchar)(*string))/256][((Uchar)(*string))%256])&((1<<13))) && (!((*string)>=0xDC00 && (*string)<0xE000)));
}

canonical_original_code:
int valid_start_position(unsigned short *string)
{
    return (!(((uctype)[((Uchar)(*string))/256][((Uchar)(*string))%256])&((1<<13))) && (!((*string)>=0xDC00 && (*string)<0xE000)));
}

variable_types:
string
unsigned short *


decompiled_code:
__int64 __fastcall add_surrogate_handler(__int16 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // rdx

v4 = mm_malloc(32LL);
if ( !v4 )
return 0LL;
v5 = surrolist;
*(_QWORD *)(v4 + 8) = a2;
*(_QWORD *)(v4 + 16) = a3;
*(_QWORD *)(v4 + 24) = v5;
*(_WORD *)v4 = a1;
surrolist = v4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // rdx

v4 = mm_malloc(32LL);
if ( !v4 )
return 0LL;
v5 = surrolist;
*(_QWORD *)(v4 + 8) = a2;
*(_QWORD *)(v4 + 16) = a3;
*(_QWORD *)(v4 + 24) = v5;
*(_WORD *)v4 = a1;
surrolist = v4;
return 1LL;
}

original_code:
int add_surrogate_handler(Uchar highvalue, HandleFunc print,
     HandleFunc handle)
{
    SurroHandler *sh;
    sh=mm_malloc(sizeof(SurroHandler));
    if (!sh) return 0;
    sh->next=surrolist;
    surrolist=sh;
    sh->print=print;
    sh->handle=handle;
    sh->highval=highvalue;
    return 1;
}

canonical_original_code:
int add_surrogate_handler(unsigned short highvalue, unsigned short *(*print)(int, struct _attribs *, int (**)(unsigned short)), unsigned short *(*handle)(int, struct _attribs *, int (**)(unsigned short)))
{
    struct SurroHandler *sh;
    sh=mm_malloc(sizeof(SurroHandler));
    if (!sh) return 0;
    sh->next=surrolist;
    surrolist=sh;
    sh->print=print;
    sh->handle=handle;
    sh->highval=highvalue;
    return 1;
}

variable_types:
highvalue
unsigned short

variable_types: unsigned short *(*)(int, struct _attribs { int font; int fgcolor; int bgcolor; int language; int country; int direction; int text; int plane; void *object; int pos; int posdelta; } *, int (**)(unsigned short))

variable_types: unsigned short *(*)(int, struct _attribs *, int (**)(unsigned short))

variable_types: struct SurroHandler { unsigned short highval; unsigned short *(*print)(int, struct _attribs { int font; int fgcolor; int bgcolor; int language; int country; int direction; int text; int plane; void *object; int pos; int posdelta; } *, int (**)(unsigned short)); unsigned short *(*handle)(int, struct _attribs *, int (**)(unsigned short)); struct SurroHandler *next; } *

user_defined_types: struct SurroHandler { unsigned short highval; unsigned short *(*print)(int, struct _attribs *, int (**)(unsigned short)); unsigned short *(*handle)(int, struct _attribs *, int (**)(unsigned short)); struct SurroHandler *next; }


decompiled_code:
__int64 __fastcall add_markup_handler(__int16 a1, __int64 a2, __int64 a3)
{
return add_surrogate_handler(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, __int64 a2, __int64 a3)
{
return func1(a1, a2, a3);
}

original_code:
int add_markup_handler(MarkupGroup mg, HandleFunc print, HandleFunc handle)
{
    return add_surrogate_handler((Uchar) mg, print, handle);
}

canonical_original_code:
int add_markup_handler(enum MarkupGroup mg, unsigned short *(*print)(int, struct _attribs *, int (**)(unsigned short)), unsigned short *(*handle)(int, struct _attribs *, int (**)(unsigned short)))
{
    return add_surrogate_handler((unsigned short) mg, print, handle);
}

variable_types: enum MarkupGroup { FontAttrib=56193, BoxAttrib=56194, ColorAttrib=56195, LangAttrib=56196, ArgAttrib=56197, LocaleAttrib=56198, ProgAttrib=56199, StackAttrib=56200 }

user_defined_types: struct _attribs { int font; int fgcolor; int bgcolor; int language; int country; int direction; int text; int plane; void *object; int pos; int posdelta; }


decompiled_code:
__int64 high_surro()
{
return (unsigned __int16)surrohighvalue;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned __int16)surrohighvalue;
}

original_code:
int high_surro(void)
{
    return surrohighvalue;
}

canonical_original_code:
int high_surro()
{
    return surrohighvalue;
}


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

if ( current_handler )
result = (*(__int64 (__fastcall **)(_QWORD))(current_handler + 16))(a1);
else
result = 0LL;
return result;
}

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

if ( current_handler )
result = (*(__int64 (__fastcall **)(_QWORD))(current_handler + 16))(a1);
else
result = 0LL;
return result;
}

original_code:
Uchar *handle_surro(Uchar lowvalue, Attribute *attr, RedirectFunc *func)
{
    if (current_handler) {
 return (*current_handler->handle)(lowvalue, attr, func);
    } else {
 return ((void *)0);
    }
}

canonical_original_code:
unsigned short *handle_surro(unsigned short lowvalue, struct _attribs *attr, int (**func)(unsigned short))
{
    if (current_handler) {
 return (*current_handler->handle)(lowvalue, attr, func);
    } else {
 return ((void *)0);
    }
}

variable_types:
lowvalue
unsigned short

variable_types: struct _attribs { int font; int fgcolor; int bgcolor; int language; int country; int direction; int text; int plane; void *object; int pos; int posdelta; } *

variable_types:
func
int (**)(unsigned short)

return_type: unsigned short *


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

if ( current_handler )
result = (*(__int64 (__fastcall **)(_QWORD))(current_handler + 8))(a1);
else
result = 0LL;
return result;
}

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

if ( current_handler )
result = (*(__int64 (__fastcall **)(_QWORD))(current_handler + 8))(a1);
else
result = 0LL;
return result;
}

original_code:
Uchar *print_surro(Uchar lowvalue, Attribute *attr, RedirectFunc *func)
{
    if (current_handler) {
 return (*current_handler->print)(lowvalue, attr, func);
    } else {
 return ((void *)0);
    }
}

canonical_original_code:
unsigned short *print_surro(unsigned short lowvalue, struct _attribs *attr, int (**func)(unsigned short))
{
    if (current_handler) {
 return (*current_handler->print)(lowvalue, attr, func);
    } else {
 return ((void *)0);
    }
}


decompiled_code:
// attributes: thunk
__int64 markup_init()
{
return font_markup_init();
}

canonical_decompiled_code:
__int64 func7()
{
return font_markup_init();
}

original_code:
void markup_init(void)
{
    font_markup_init();
}

canonical_original_code:
void markup_init()
{
    font_markup_init();
}

return_type: void


gcd

decompiled_code:
int __fastcall gcd(signed int *a1, signed int a2, signed int a3)
{
int result; // eax

while ( 1 )
{
if ( a2 > a3 )
{
a2 -= a3 * (a3 / a2 - 1);
goto LABEL_3;
}
if ( a2 >= a3 )
break;
a3 -= a2 * (a2 / a3 - 1);
LABEL_3:
result = printf("a\t%i\tb\t%i\n", (unsigned int)a2, (unsigned int)a3);
}
*a1 = a2;
return result;
}

canonical_decompiled_code:
int __fastcall func0(signed int *a1, signed int a2, signed int a3)
{
int result; // eax

while ( 1 )
{
if ( a2 > a3 )
{
a2 -= a3 * (a3 / a2 - 1);
goto LABEL_3;
}
if ( a2 >= a3 )
break;
a3 -= a2 * (a2 / a3 - 1);
LABEL_3:
result = printf("a\t%i\tb\t%i\n", (unsigned int)a2, (unsigned int)a3);
}
*a1 = a2;
return result;
}

original_code:
void gcd(int *r, int a, int b)
{
    while (1) {
 if (a>b) a=a-(b/a-1)*b;
 else if (b>a) b=b-(a/b-1)*a;
 else break;
 printf("a\t%i\tb\t%i\n", a,b);
    }
    *r=a;
}

variable_types:
r
int *

variable_types: a int

variable_types: b int


fac

decompiled_code:
int __fastcall fac(_DWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
int result; // eax
__int64 v4; // rdx

v2 = a2;
*a1 = 1;
result = printf("a\t%i\tr\t%i\n", a2, 1LL);
if ( (int)a2 > 0 )
{
do
{
v4 = v2 * *a1;
--v2;
*a1 = v4;
result = printf("a\t%i\tr\t%i\n", v2, v4);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(_DWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
int result; // eax
__int64 v4; // rdx

v2 = a2;
*a1 = 1;
result = printf("a\t%i\tr\t%i\n", a2, 1LL);
if ( (int)a2 > 0 )
{
do
{
v4 = v2 * *a1;
--v2;
*a1 = v4;
result = printf("a\t%i\tr\t%i\n", v2, v4);
}
while ( v2 );
}
return result;
}

original_code:
void fac(int *r, int a)
{
    *r=1;
    printf("a\t%i\tr\t%i\n", a, *r);
    while (a>0) {
 *r=*r*a;
 a=a-1;
 printf("a\t%i\tr\t%i\n", a, *r);
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 6;
fac(v4, 6LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 6;
func1(v4, 6LL);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int y=6;
    fac(&y,y);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int y = 6;
    fac(&y,y);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: y int


decompiled_code:
__int64 box_handle()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
static Uchar *box_handle(int lowvalue, Attribute *attr, RedirectFunc *func)
{
    return ((void *)0);
}

canonical_original_code:
static unsigned short *box_handle(int lowvalue, struct _attribs *attr, int (**func)(unsigned short))
{
    return ((void *)0);
}

variable_types: lowvalue int


decompiled_code:
// attributes: thunk
__int64 box_print()
{
return box_handle_constprop_0();
}

canonical_decompiled_code:
__int64 func2()
{
return func1();
}

original_code:
static Uchar *box_print(int lowvalue, Attribute *attr, RedirectFunc *func)
{
    return ((void *)0);
}

canonical_original_code:
static unsigned short *box_print(int lowvalue, struct _attribs *attr, int (**func)(unsigned short))
{
    return ((void *)0);
}


decompiled_code:
int box_markup_init()
{
int result; // eax
__int64 v1; // rax
const char *v2; // rax

result = add_markup_handler(56194LL, box_print, box_handle);
if ( !result )
{
v1 = translate("Unable to add box handler.\n");
v2 = (const char *)UstrtoLocale(v1);
result = fprintf(stderr, v2);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
__int64 v1; // rax
const char *v2; // rax

result = add_markup_handler(56194LL, box_print, box_handle);
if ( !result )
{
v1 = translate("Unable to add box handler.\n");
v2 = (const char *)UstrtoLocale(v1);
result = fprintf(stderr, v2);
}
return result;
}

original_code:
void box_markup_init(void)
{
    if (!add_markup_handler(BoxAttrib, box_print, box_handle)) {
 fprintf(stderr, UstrtoLocale(translate("Unable to add box handler.\n")));
    }
}

canonical_original_code:
void box_markup_init()
{
    if (!add_markup_handler(BoxAttrib, box_print, box_handle)) {
 fprintf(stderr, UstrtoLocale(translate("Unable to add box handler.\n")));
    }
}


message

decompiled_code:
int __fastcall message(int a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // rax
int result; // eax
const char *v5; // r12
const char *v6; // rax

if ( menu_is_open )
{
message_time = last_time;
switch ( a1 )
{
case 0:
return out_message(a2);
case 1:
out_message(a2);
return XBell(display, 0);
case 2:
kind_of_remark = -1;
goto LABEL_6;
case 3:
kind_of_remark = -2;
LABEL_6:
result = remark_make(0LL, 0LL, 0LL, 1LL, a2, 0LL, 0LL, 0LL, 0LL);
if ( !result )
{
v5 = (const char *)UstrtoLocale(a2);
v6 = (const char *)UstrtoLocale(progname);
result = fprintf(stderr, "%s: %s\n", v6, v5);
}
break;
case 4:
result = out_message_curs(a2);
break;
default:
goto LABEL_3;
}
}
else
{
LABEL_3:
v2 = (const char *)UstrtoLocale(a2);
v3 = (const char *)UstrtoLocale(progname);
result = fprintf(stderr, "%s: %s\n", v3, v2);
if ( a1 > 3 )
exit(a1 - 1000);
}
return result;
}

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

if ( menu_is_open )
{
message_time = last_time;
switch ( a1 )
{
case 0:
return out_message(a2);
case 1:
out_message(a2);
return XBell(display, 0);
case 2:
kind_of_remark = -1;
goto LABEL_6;
case 3:
kind_of_remark = -2;
LABEL_6:
result = remark_make(0LL, 0LL, 0LL, 1LL, a2, 0LL, 0LL, 0LL, 0LL);
if ( !result )
{
v5 = (const char *)UstrtoLocale(a2);
v6 = (const char *)UstrtoLocale(progname);
result = fprintf(stderr, "%s: %s\n", v6, v5);
}
break;
case 4:
result = out_message_curs(a2);
break;
default:
goto LABEL_3;
}
}
else
{
LABEL_3:
v2 = (const char *)UstrtoLocale(a2);
v3 = (const char *)UstrtoLocale(progname);
result = fprintf(stderr, "%s: %s\n", v3, v2);
if ( a1 > 3 )
exit(a1 - 1000);
}
return result;
}

original_code:
void message(int lvl, Uchar *text)
{
    int to_standard = 0;
    if (menu_is_open) {
 message_time = last_time;
 switch (lvl) {
 case 0:
     out_message(text);
     break;
 case 4:
     out_message_curs(text);
     break;
 case 1:
     out_message(text);
     XBell(display, 0);
     break;
 case 2:
     kind_of_remark = -1;
     to_standard = (!remark_make(0, ((void *)0), ((void *)0), 1,
     text, ((void *)0), ((void *)0), 0, ((void *)0)));
     break;
 case 3:
     kind_of_remark = -2;
     to_standard = (!remark_make(0, ((void *)0), ((void *)0), 1,
     text, ((void *)0), ((void *)0), 0, ((void *)0)));
     break;
 default:
     to_standard = 1;
     break;
 }
    } else
 to_standard = 1;
    if (to_standard) {
 fprintf(stderr, "%s: %s\n", UstrtoLocale(progname), UstrtoLocale(text));
 if (lvl>3) {
     exit(lvl-1000);
 }
    }
}

canonical_original_code:
void message(int lvl, unsigned short *text)
{
    int to_standard = 0;
    if (menu_is_open) {
 message_time = last_time;
 switch (lvl) {
 case 0:
     out_message(text);
     break;
 case 4:
     out_message_curs(text);
     break;
 case 1:
     out_message(text);
     XBell(display, 0);
     break;
 case 2:
     kind_of_remark = -1;
     to_standard = (!remark_make(0, ((void *)0), ((void *)0), 1,
     text, ((void *)0), ((void *)0), 0, ((void *)0)));
     break;
 case 3:
     kind_of_remark = -2;
     to_standard = (!remark_make(0, ((void *)0), ((void *)0), 1,
     text, ((void *)0), ((void *)0), 0, ((void *)0)));
     break;
 default:
     to_standard = 1;
     break;
 }
    } else
 to_standard = 1;
    if (to_standard) {
 fprintf(stderr, "%s: %s\n", UstrtoLocale(progname), UstrtoLocale(text));
 if (lvl>3) {
     exit(lvl-1000);
 }
    }
}

variable_types: lvl int

variable_types:
text
unsigned short *


decompiled_code:
__int64 __fastcall message2(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp

v3 = concat(a2, a3);
message(a1, v3);
return mm_free(v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp

v3 = concat(a2, a3);
func0(a1, v3);
return mm_free(v3);
}

original_code:
void message2(int lvl, Uchar *text1, Uchar *text2)
{
    Uchar *temp;
    temp = concat(text1, text2);
    message(lvl, temp);
    mm_free(temp);
}

canonical_original_code:
void message2(int lvl, unsigned short *text1, unsigned short *text2)
{
    unsigned short *temp;
    temp = concat(text1, text2);
    message(lvl, temp);
    mm_free(temp);
}

variable_types:
temp
unsigned short *


original_code:
void system_init(int argc, char *argv[])
{
    char *temp;
    Uchar *c;
    char *g;
    int i,n=0,dhda=0;
    temp = getenv("HOME");
    if (temp) {
      homedir = concat(FilenametoUstr(temp), translate("/"));
    } else {
      homedir = concat(translate("."), translate("/"));
    }
    i=Ustrlen(homedir);
    if (homedir[i-2]=='/') homedir[i-1]='\0';
    userdir = concat(homedir, translate("mathspad" "/"));
    latexdir = concat(userdir, translate("latex" "/"));
    notationdir = concat(userdir, translate("stencils" "/"));
    latex_line_unit = concat(translate("2mm"),((void *)0));
    latex_tab_unit = concat(translate("8.5mm"),((void *)0));
    latex_space_unit = concat(translate("0.3em"),((void *)0));
    if (((void*)(0!=((temp = getenv("MATHPADHOME"))))))
      if (temp[strlen(temp)-1]=='/')
 program_dir = concat(translate(temp),((void *)0));
      else
 program_dir = concat(translate(temp), translate("/"));
    else
      program_dir = concat(translate("/home/jff/code/mathpad-0.80-jff/build/share/MathSpad" "/"),((void *)0));
    if (!getenv("MATHPADFONTPATH")) {
      char *d;
      int bl;
      bl=strlen("MATHPADFONTPATH=" "/home/jff/code/mathpad-0.80-jff/build/share/MathSpad/fonts");
      d=mm_malloc(sizeof(char)*(bl+1));
      if (d) {
 strcpy(d,"MATHPADFONTPATH=" "/home/jff/code/mathpad-0.80-jff/build/share/MathSpad/fonts");
 putenv(d);
      }
    }
    if (!getenv("mathpad")) {
      char buffer[3000];
      int bl;
      char *d;
      sprintf(buffer,"mathpad=%s", UstrtoFilename(program_dir));
      bl=strlen(buffer);
      d = mm_malloc(sizeof(d)*(bl+1));
      if (d) {
 strcpy(d,buffer);
 putenv(d);
      }
    }
    if (!getenv("mathspad")) {
      char buffer[3000];
      int bl;
      char *d;
      sprintf(buffer,"mathspad=%s", UstrtoFilename(program_dir));
      bl=strlen(buffer);
      d = mm_malloc(sizeof(d)*(bl+1));
      if (d) {
 strcpy(d,buffer);
 putenv(d);
      }
    }
    if (((void*)(0!=((temp = getenv("PATH")))))) {
      char *p;
      i=strlen(temp)+strlen(UstrtoFilename(program_dir))+15;
      p= (char*) mm_malloc(i*sizeof(char));
      strcpy(p,"PATH=");
      strcat(p,temp);
      i=strlen(p);
      p[i++]=':';
      strcpy(p+i,UstrtoFilename(program_dir));
      strcat(p+i,"bin");
      putenv(p);
    }
    if (((void*)(0!=((temp = getenv("MATHPADLATEX"))))))
      if (temp[strlen(temp)-1]=='/')
 program_latexdir = concat(FilenametoUstr(temp),((void *)0));
      else
 program_latexdir = concat(FilenametoUstr(temp), translate("/"));
    else
      program_latexdir = concat(program_dir, translate("latex" "/"));
    if (((void*)(0!=((temp = getenv("MATHPADSTENCIL"))))))
      if (temp[strlen(temp)-1]=='/')
 program_notationdir = concat(FilenametoUstr(temp), ((void *)0));
      else
 program_notationdir = concat(FilenametoUstr(temp), translate("/"));
    else
      program_notationdir = concat(program_dir, translate("stencils" "/"));
    if (((void*)(0!=((temp = getenv("MATHPADFONTS")))))) {
      program_fontfilename = concat(translate(temp), ((void *)0));
      fontfile[0] = concat(translate(temp), ((void *)0));
    } else {
      fontfile[0] = concat(translate("MPFonts"), ((void *)0));
      program_fontfilename = concat(translate("MPFonts"), ((void *)0));
    }
    temp = getenv("MATHPADHELPPATH");
    if (!temp) temp=":";
    g=temp;
    i=0;
    while (*g) { n+=(*g==':'); g++; i++; }
    help_dirs = (Uchar **) mm_malloc(sizeof(char*) * (n*2+7));
    c = (Uchar*) mm_malloc(sizeof(Uchar)*(n*10+i*2+2));
    g = temp;
    while (i>0 || (!i && !*g)) {
      int cp=0;
      help_dirs[nr_help_dirs]=c;
      while (((void*)(0!=((*c=*g++)))) && *c != ':') {
 cp+=(*c == '%');
 c++;i--;
      }
      i--;
      if (*c==':') *c='\0';
      if (help_dirs[nr_help_dirs]!=c) {
 if (*(c-1)!='/' && !cp) {
   *c++='/';
   *c='\0';
 }
 if (!cp) {
   nr_help_dirs++;
   c++;
   help_dirs[nr_help_dirs]=c;
   concat_in(c,help_dirs[nr_help_dirs-1], translate("%.mpd"));
   while (*c) c++;
 }
      } else if (!dhda) {
 dhda=1;
 help_dirs[nr_help_dirs++] =
   concat(homedir, translate("mathspad" "/" "help" "/" "%.mpd"));
 help_dirs[nr_help_dirs++] =
   concat(homedir, translate("mathspad" "/" "help" "/"));
 help_dirs[nr_help_dirs++] =
   concat(program_dir, translate("help" "/" "%.mpd"));
 help_dirs[nr_help_dirs++] =
   concat(program_dir, translate("help" "/"));
 help_dirs[nr_help_dirs++] = concat(translate("%.mpd"),((void *)0));
 help_dirs[nr_help_dirs] = concat(((void *)0),((void *)0));
      }
      nr_help_dirs++;
      c++;
    }
    for (i=1; i<4; i++)
      fontfile[i]= concat(((void *)0),((void *)0));
    if (((void*)(0!=((temp = getenv("MATHPADKEYS"))))))
      program_keypath = concat(translate(temp), ((void *)0));
    else
      program_keypath = concat(translate("emacs:unicode"),((void *)0));
    keypath = concat(((void *)0),((void *)0));
    make_defaults(argc, argv);
}

canonical_original_code:
void system_init(int argc, char *argv[])
{
    char *temp;
    unsigned short *c;
    char *g;
    int i; int n = 0; int dhda = 0;
    temp = getenv("HOME");
    if (temp) {
      homedir = concat(FilenametoUstr(temp), translate("/"));
    } else {
      homedir = concat(translate("."), translate("/"));
    }
    i=Ustrlen(homedir);
    if (homedir[i-2]=='/') homedir[i-1]='\0';
    userdir = concat(homedir, translate("mathspad" "/"));
    latexdir = concat(userdir, translate("latex" "/"));
    notationdir = concat(userdir, translate("stencils" "/"));
    latex_line_unit = concat(translate("2mm"),((void *)0));
    latex_tab_unit = concat(translate("8.5mm"),((void *)0));
    latex_space_unit = concat(translate("0.3em"),((void *)0));
    if (((void *)(0!=((temp = getenv("MATHPADHOME"))))))
      if (temp[strlen(temp)-1]=='/')
 program_dir = concat(translate(temp),((void *)0));
      else
 program_dir = concat(translate(temp), translate("/"));
    else
      program_dir = concat(translate("/home/jff/code/mathpad-0.80-jff/build/share/MathSpad" "/"),((void *)0));
    if (!getenv("MATHPADFONTPATH")) {
      char *d;
      int bl;
      bl=strlen("MATHPADFONTPATH=" "/home/jff/code/mathpad-0.80-jff/build/share/MathSpad/fonts");
      d=mm_malloc(sizeof(char)*(bl+1));
      if (d) {
 strcpy(d,"MATHPADFONTPATH=" "/home/jff/code/mathpad-0.80-jff/build/share/MathSpad/fonts");
 putenv(d);
      }
    }
    if (!getenv("mathpad")) {
      char buffer[3000];
      int bl;
      char *d;
      sprintf(buffer,"mathpad=%s", UstrtoFilename(program_dir));
      bl=strlen(buffer);
      d = mm_malloc(sizeof(d)*(bl+1));
      if (d) {
 strcpy(d,buffer);
 putenv(d);
      }
    }
    if (!getenv("mathspad")) {
      char buffer[3000];
      int bl;
      char *d;
      sprintf(buffer,"mathspad=%s", UstrtoFilename(program_dir));
      bl=strlen(buffer);
      d = mm_malloc(sizeof(d)*(bl+1));
      if (d) {
 strcpy(d,buffer);
 putenv(d);
      }
    }
    if (((void *)(0!=((temp = getenv("PATH")))))) {
      char *p;
      i=strlen(temp)+strlen(UstrtoFilename(program_dir))+15;
      p= (char *) mm_malloc(i*sizeof(char));
      strcpy(p,"PATH=");
      strcat(p,temp);
      i=strlen(p);
      p[i++]=':';
      strcpy(p+i,UstrtoFilename(program_dir));
      strcat(p+i,"bin");
      putenv(p);
    }
    if (((void *)(0!=((temp = getenv("MATHPADLATEX"))))))
      if (temp[strlen(temp)-1]=='/')
 program_latexdir = concat(FilenametoUstr(temp),((void *)0));
      else
 program_latexdir = concat(FilenametoUstr(temp), translate("/"));
    else
      program_latexdir = concat(program_dir, translate("latex" "/"));
    if (((void *)(0!=((temp = getenv("MATHPADSTENCIL"))))))
      if (temp[strlen(temp)-1]=='/')
 program_notationdir = concat(FilenametoUstr(temp), ((void *)0));
      else
 program_notationdir = concat(FilenametoUstr(temp), translate("/"));
    else
      program_notationdir = concat(program_dir, translate("stencils" "/"));
    if (((void *)(0!=((temp = getenv("MATHPADFONTS")))))) {
      program_fontfilename = concat(translate(temp), ((void *)0));
      fontfile[0] = concat(translate(temp), ((void *)0));
    } else {
      fontfile[0] = concat(translate("MPFonts"), ((void *)0));
      program_fontfilename = concat(translate("MPFonts"), ((void *)0));
    }
    temp = getenv("MATHPADHELPPATH");
    if (!temp) temp=":";
    g=temp;
    i=0;
    while (*g) { n+=(*g==':'); g++; i++; }
    help_dirs = (unsigned short **) mm_malloc(sizeof(char *) * (n*2+7));
    c = (unsigned short *) mm_malloc(sizeof(Uchar)*(n*10+i*2+2));
    g = temp;
    while (i>0 || (!i && !*g)) {
      int cp = 0;
      help_dirs[nr_help_dirs]=c;
      while (((void *)(0!=((*c=*g++)))) && *c != ':') {
 cp+=(*c == '%');
 c++;i--;
      }
      i--;
      if (*c==':') *c='\0';
      if (help_dirs[nr_help_dirs]!=c) {
 if (*(c-1)!='/' && !cp) {
   *c++='/';
   *c='\0';
 }
 if (!cp) {
   nr_help_dirs++;
   c++;
   help_dirs[nr_help_dirs]=c;
   concat_in(c,help_dirs[nr_help_dirs-1], translate("%.mpd"));
   while (*c) c++;
 }
      } else if (!dhda) {
 dhda=1;
 help_dirs[nr_help_dirs++] =
   concat(homedir, translate("mathspad" "/" "help" "/" "%.mpd"));
 help_dirs[nr_help_dirs++] =
   concat(homedir, translate("mathspad" "/" "help" "/"));
 help_dirs[nr_help_dirs++] =
   concat(program_dir, translate("help" "/" "%.mpd"));
 help_dirs[nr_help_dirs++] =
   concat(program_dir, translate("help" "/"));
 help_dirs[nr_help_dirs++] = concat(translate("%.mpd"),((void *)0));
 help_dirs[nr_help_dirs] = concat(((void *)0),((void *)0));
      }
      nr_help_dirs++;
      c++;
    }
    for (i=1; i<4; i++)
      fontfile[i]= concat(((void *)0),((void *)0));
    if (((void *)(0!=((temp = getenv("MATHPADKEYS"))))))
      program_keypath = concat(translate(temp), ((void *)0));
    else
      program_keypath = concat(translate("emacs:unicode"),((void *)0));
    keypath = concat(((void *)0),((void *)0));
    make_defaults(argc, argv);
}

variable_types:
argv
char *[]

variable_types:
temp
char *

variable_types:
c
unsigned short *

variable_types:
g
char *

variable_types: i int

variable_types: n int

variable_types: dhda int

variable_types:
d
char *

variable_types: bl int

variable_types:
buffer
char [3000]

variable_types:
p
char *

variable_types: cp int


decompiled_code:
__int64 __fastcall set_string_size(__int64 *a1, _DWORD *a2, int a3)
{
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rax

result = 1LL;
if ( *a2 <= a3 )
{
if ( *a1 )
{
v5 = mm_realloc(a1, 2LL * a3);
if ( v5 )
{
*a1 = v5;
LABEL_5:
*a2 = a3;
return 1LL;
}
}
else
{
v6 = mm_malloc(2LL * a3);
*a1 = v6;
if ( v6 )
goto LABEL_5;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, _DWORD *a2, int a3)
{
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rax

result = 1LL;
if ( *a2 <= a3 )
{
if ( *a1 )
{
v5 = mm_realloc(a1, 2LL * a3);
if ( v5 )
{
*a1 = v5;
LABEL_5:
*a2 = a3;
return 1LL;
}
}
else
{
v6 = mm_malloc(2LL * a3);
*a1 = v6;
if ( v6 )
goto LABEL_5;
}
result = 0LL;
}
return result;
}

original_code:
int set_string_size(Uchar **str, int *length, int newlength)
{
    if (newlength< *length) return 1;
    if (!*str) {
 *str=(Uchar*) mm_malloc(sizeof(Uchar)*newlength);
 if (!*str) return 0;
    } else {
 Uchar *nbuf;
 nbuf=(Uchar*) mm_realloc(str,newlength*sizeof(Uchar));
 if (!nbuf) return 0;
 *str=nbuf;
    }
    *length=newlength;
    return 1;
}

canonical_original_code:
int set_string_size(unsigned short **str, int *length, int newlength)
{
    if (newlength< *length) return 1;
    if (!*str) {
 *str=(unsigned short *) mm_malloc(sizeof(Uchar)*newlength);
 if (!*str) return 0;
    } else {
 unsigned short *nbuf;
 nbuf=(unsigned short *) mm_realloc(str,newlength*sizeof(Uchar));
 if (!nbuf) return 0;
 *str=nbuf;
    }
    *length=newlength;
    return 1;
}

variable_types:
str
unsigned short **

variable_types:
length
int *

variable_types: newlength int

variable_types:
nbuf
unsigned short *


decompiled_code:
void unitype_init()
{
if ( !uctype )
{
uctype = umap_load_file("GenClass", 4LL, 6LL, 0LL);
uclow = umap_load_file("ToLower", 2LL, 3LL, 0LL);
ucup = umap_load_file("ToUpper", 2LL, 3LL, 0LL);
uctitle = umap_load_file("ToTitle", 2LL, 3LL, 0LL);
ucinitial = umap_load_file("ToInitial", 2LL, 3LL, 0LL);
ucmedial = umap_load_file("ToMedial", 2LL, 3LL, 0LL);
ucfinal = umap_load_file("ToFinal", 2LL, 3LL, 0LL);
ucisolated = umap_load_file("ToIsolated", 2LL, 3LL, 0LL);
ucvalue = umap_load_file("ToNum", 2LL, 3LL, 0LL);
ucdenum = umap_load_file("ToDenum", 2LL, 3LL, 0LL);
ucspacevar = umap_load_file("ToSpacing", 2LL, 3LL, 0LL);
ucmirror = umap_load_file("ToMirror", 2LL, 3LL, 0LL);
ucnoaccent = umap_load_file("ToNoAccent", 2LL, 3LL, 0LL);
ucdecomp = umap_load_file("Decomposition", 8LL, 5LL, &MapUstrLoadInt);
ucdetag = umap_load_file("DeCompTag", 1LL, 2LL, 0LL);
uccancom = umap_load_file("CanComClass", 1LL, 2LL, 0LL);
uchexval = umap_load_file("ToHexValue", 1LL, 2LL, 0LL);
}
}

canonical_decompiled_code:
void func0()
{
if ( !uctype )
{
uctype = umap_load_file("GenClass", 4LL, 6LL, 0LL);
uclow = umap_load_file("ToLower", 2LL, 3LL, 0LL);
ucup = umap_load_file("ToUpper", 2LL, 3LL, 0LL);
uctitle = umap_load_file("ToTitle", 2LL, 3LL, 0LL);
ucinitial = umap_load_file("ToInitial", 2LL, 3LL, 0LL);
ucmedial = umap_load_file("ToMedial", 2LL, 3LL, 0LL);
ucfinal = umap_load_file("ToFinal", 2LL, 3LL, 0LL);
ucisolated = umap_load_file("ToIsolated", 2LL, 3LL, 0LL);
ucvalue = umap_load_file("ToNum", 2LL, 3LL, 0LL);
ucdenum = umap_load_file("ToDenum", 2LL, 3LL, 0LL);
ucspacevar = umap_load_file("ToSpacing", 2LL, 3LL, 0LL);
ucmirror = umap_load_file("ToMirror", 2LL, 3LL, 0LL);
ucnoaccent = umap_load_file("ToNoAccent", 2LL, 3LL, 0LL);
ucdecomp = umap_load_file("Decomposition", 8LL, 5LL, &MapUstrLoadInt);
ucdetag = umap_load_file("DeCompTag", 1LL, 2LL, 0LL);
uccancom = umap_load_file("CanComClass", 1LL, 2LL, 0LL);
uchexval = umap_load_file("ToHexValue", 1LL, 2LL, 0LL);
}
}

original_code:
void unitype_init(void)
{
  if (!uctype) {
    (uctype)=(MapInt) umap_load_file(("GenClass"), sizeof(int), 6, 0);
    (uclow)=(MapUchar) umap_load_file(("ToLower"), sizeof(Uchar), 3, 0);
    (ucup)=(MapUchar) umap_load_file(("ToUpper"), sizeof(Uchar), 3, 0);
    (uctitle)=(MapUchar) umap_load_file(("ToTitle"), sizeof(Uchar), 3, 0);
    (ucinitial)=(MapUchar) umap_load_file(("ToInitial"), sizeof(Uchar), 3, 0);
    (ucmedial)=(MapUchar) umap_load_file(("ToMedial"), sizeof(Uchar), 3, 0);
    (ucfinal)=(MapUchar) umap_load_file(("ToFinal"), sizeof(Uchar), 3, 0);
    (ucisolated)=(MapUchar) umap_load_file(("ToIsolated"), sizeof(Uchar), 3, 0);
    (ucvalue)=(MapUchar) umap_load_file(("ToNum"), sizeof(Uchar), 3, 0);
    (ucdenum)=(MapUchar) umap_load_file(("ToDenum"), sizeof(Uchar), 3, 0);
    (ucspacevar)=(MapUchar) umap_load_file(("ToSpacing"), sizeof(Uchar), 3, 0);
    (ucmirror)=(MapUchar) umap_load_file(("ToMirror"), sizeof(Uchar), 3, 0);
    (ucnoaccent)=(MapUchar) umap_load_file(("ToNoAccent"), sizeof(Uchar), 3, 0);
    (ucdecomp)=(MapUstr) umap_load_file(("Decomposition"), sizeof(Uchar*), 5, MapUstrLoadInt);
    (ucdetag)=(MapChar) umap_load_file(("DeCompTag"), sizeof(char), 2, 0);
    (uccancom)=(MapChar) umap_load_file(("CanComClass"), sizeof(char), 2, 0);
    (uchexval)=(MapChar) umap_load_file(("ToHexValue"), sizeof(char), 2, 0);
  }
}

canonical_original_code:
void unitype_init()
{
  if (!uctype) {
    (uctype)=(int **) umap_load_file(("GenClass"), sizeof(int), 6, 0);
    (uclow)=(unsigned short **) umap_load_file(("ToLower"), sizeof(Uchar), 3, 0);
    (ucup)=(unsigned short **) umap_load_file(("ToUpper"), sizeof(Uchar), 3, 0);
    (uctitle)=(unsigned short **) umap_load_file(("ToTitle"), sizeof(Uchar), 3, 0);
    (ucinitial)=(unsigned short **) umap_load_file(("ToInitial"), sizeof(Uchar), 3, 0);
    (ucmedial)=(unsigned short **) umap_load_file(("ToMedial"), sizeof(Uchar), 3, 0);
    (ucfinal)=(unsigned short **) umap_load_file(("ToFinal"), sizeof(Uchar), 3, 0);
    (ucisolated)=(unsigned short **) umap_load_file(("ToIsolated"), sizeof(Uchar), 3, 0);
    (ucvalue)=(unsigned short **) umap_load_file(("ToNum"), sizeof(Uchar), 3, 0);
    (ucdenum)=(unsigned short **) umap_load_file(("ToDenum"), sizeof(Uchar), 3, 0);
    (ucspacevar)=(unsigned short **) umap_load_file(("ToSpacing"), sizeof(Uchar), 3, 0);
    (ucmirror)=(unsigned short **) umap_load_file(("ToMirror"), sizeof(Uchar), 3, 0);
    (ucnoaccent)=(unsigned short **) umap_load_file(("ToNoAccent"), sizeof(Uchar), 3, 0);
    (ucdecomp)=(unsigned short ***) umap_load_file(("Decomposition"), sizeof(unsigned short *), 5, MapUstrLoadInt);
    (ucdetag)=(char **) umap_load_file(("DeCompTag"), sizeof(char), 2, 0);
    (uccancom)=(char **) umap_load_file(("CanComClass"), sizeof(char), 2, 0);
    (uchexval)=(char **) umap_load_file(("ToHexValue"), sizeof(char), 2, 0);
  }
}


decompiled_code:
__int64 __fastcall load_library(char *a1)
{
__int64 v2; // rdi
__int64 v3; // rbx
char *v4; // rbp
__int64 result; // rax
_QWORD *v6; // rbx
void *v7; // rax
void (*v8)(void); // rdx
size_t v9; // rax
char *v10; // rax
__int64 v11; // rax
char *v12; // rax
char v13[28]; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = libpath;
v3 = liblist;
if ( !libpath )
{
libpath = make_pathinfo("LIBPATH", ".:/home/jff/code/mathpad-0.80-jff/build/lib/MathSpad", &unk_190);
v2 = libpath;
}
v4 = (char *)search_file(v2, a1, v13);
if ( !v4 )
{
*a1 = 0;
v4 = a1;
}
if ( v3 )
{
while ( strcmp(v4, *(const char **)(v3 + 8)) )
{
v3 = *(_QWORD *)v3;
if ( !v3 )
goto LABEL_10;
}
free(v4);
result = 0LL;
}
else
{
LABEL_10:
v6 = malloc(0x18uLL);
v7 = dlopen(v4, 1);
v6[2] = v7;
if ( v7 )
{
v8 = (void (*)(void))dlsym(v7, "init_library");
if ( v8 )
v8();
else
fprintf(stderr, "Library %s does not contain an init function\n", v4);
v9 = strlen(v4);
v10 = (char *)malloc(v9 + 1);
v6[1] = v10;
strcpy(v10, v4);
v11 = liblist;
liblist = (__int64)v6;
*v6 = v11;
result = 1LL;
}
else
{
v12 = dlerror();
fprintf(stderr, "%s\n", v12);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
__int64 v2; // rdi
__int64 v3; // rbx
char *v4; // rbp
__int64 result; // rax
_QWORD *v6; // rbx
void *v7; // rax
void (*v8)(void); // rdx
size_t v9; // rax
char *v10; // rax
__int64 v11; // rax
char *v12; // rax
char v13[28]; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = libpath;
v3 = liblist;
if ( !libpath )
{
libpath = make_pathinfo("LIBPATH", ".:/home/jff/code/mathpad-0.80-jff/build/lib/MathSpad", &unk_190);
v2 = libpath;
}
v4 = (char *)search_file(v2, a1, v13);
if ( !v4 )
{
*a1 = 0;
v4 = a1;
}
if ( v3 )
{
while ( strcmp(v4, *(const char **)(v3 + 8)) )
{
v3 = *(_QWORD *)v3;
if ( !v3 )
goto LABEL_10;
}
free(v4);
result = 0LL;
}
else
{
LABEL_10:
v6 = malloc(0x18uLL);
v7 = dlopen(v4, 1);
v6[2] = v7;
if ( v7 )
{
v8 = (void (*)(void))dlsym(v7, "init_library");
if ( v8 )
v8();
else
fprintf(stderr, "Library %s does not contain an init function\n", v4);
v9 = strlen(v4);
v10 = (char *)malloc(v9 + 1);
v6[1] = v10;
strcpy(v10, v4);
v11 = liblist;
liblist = (__int64)v6;
*v6 = v11;
result = 1LL;
}
else
{
v12 = dlerror();
fprintf(stderr, "%s\n", v12);
result = 0LL;
}
}
return result;
}

original_code:
int load_library(char *libname)
{
    Library *lp=liblist;
    void (*initfunc)();
    char *foundname;
    int ftype;
    if (!libpath) libpath = make_pathinfo("LIBPATH", ".:/home/jff/code/mathpad-0.80-jff/build/lib/MathSpad", ".so");
    foundname = search_file(libpath, libname, &ftype);
    if (!foundname) foundname=strcpy(libname,"");
    while (lp && strcmp(foundname, lp->name)) lp=lp->next;
    if (lp) { free(foundname); return 0; }
    lp=(Library*)malloc(sizeof(Library));
    lp->handle=dlopen(foundname, 0x00001);
    if (!lp->handle) {
 fprintf(stderr, "%s\n", dlerror());
 return 0;
    }
    initfunc = (void (*)()) dlsym(lp->handle, "init_library");
    if (initfunc) {
 (*initfunc)();
    } else {
 fprintf(stderr, "Library %s does not contain an init function\n",
  foundname);
    }
    lp->name=(char*) malloc(sizeof(char)*(strlen(foundname)+1));
    strcpy(lp->name, foundname);
    lp->next=liblist;
    liblist=lp;
    return 1;
}

canonical_original_code:
int load_library(char *libname)
{
    struct Library *lp = liblist;
    void (*initfunc)();
    char *foundname;
    int ftype;
    if (!libpath) libpath = make_pathinfo("LIBPATH", ".:/home/jff/code/mathpad-0.80-jff/build/lib/MathSpad", ".so");
    foundname = search_file(libpath, libname, &ftype);
    if (!foundname) foundname=strcpy(libname,"");
    while (lp && strcmp(foundname, lp->name)) lp=lp->next;
    if (lp) { free(foundname); return 0; }
    lp=(struct Library *)malloc(sizeof(Library));
    lp->handle=dlopen(foundname, 0x00001);
    if (!lp->handle) {
 fprintf(stderr, "%s\n", dlerror());
 return 0;
    }
    initfunc = (void (*)()) dlsym(lp->handle, "init_library");
    if (initfunc) {
 (*initfunc)();
    } else {
 fprintf(stderr, "Library %s does not contain an init function\n",
  foundname);
    }
    lp->name=(char *) malloc(sizeof(char)*(strlen(foundname)+1));
    strcpy(lp->name, foundname);
    lp->next=liblist;
    liblist=lp;
    return 1;
}

variable_types:
libname
char *

variable_types: struct Library { struct Library *next; char *name; void *handle; } *

variable_types:
initfunc
void (*)()

variable_types:
foundname
char *

variable_types: ftype int


reshuffle

original_code:
int reshuffle(int len, int *direct, void **item)
{
    int i,lb,ub,max;
    max=0;
    for (i=0; i<len; i++) {
 if (direct[i]>max) max=direct[i];
    }
    while (max) {
 i=0;
 while (i<len) {
     while (i<len && direct[i]!=max) i++;
     if (i!=len) {
  void *c;
  lb=i;
  while (i<len && direct[i]==max) { direct[i]=max-1; i++; }
  ub=i-1;
  while (lb<ub) {
      c=item[lb];
      item[lb]=item[ub];
      item[ub]=c;
      lb++;
      ub--;
  }
     }
 }
 max--;
    }
    return 0;
}

canonical_original_code:
int reshuffle(int len, int *direct, void **item)
{
    int i; int lb; int ub; int max;
    max=0;
    for (i=0; i<len; i++) {
 if (direct[i]>max) max=direct[i];
    }
    while (max) {
 i=0;
 while (i<len) {
     while (i<len && direct[i]!=max) i++;
     if (i!=len) {
  void *c;
  lb=i;
  while (i<len && direct[i]==max) { direct[i]=max-1; i++; }
  ub=i-1;
  while (lb<ub) {
      c=item[lb];
      item[lb]=item[ub];
      item[ub]=c;
      lb++;
      ub--;
  }
     }
 }
 max--;
    }
    return 0;
}

variable_types: len int

variable_types:
direct
int *

variable_types:
item
void **

variable_types: i int

variable_types: lb int

variable_types: ub int

variable_types: max int

variable_types:
c
void *


decompiled_code:
__int64 __fastcall MAG_parse(__int64 a1, _DWORD *a2)
{
lex_open_string();
parse_input();
*a2 = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2)
{
lex_open_string();
parse_input();
*a2 = 0;
return 1LL;
}

original_code:
int MAG_parse(unsigned char *buffer, unsigned int *len)
{
  lex_open_string(buffer);
  parse_input();
  *len=0;
  return 1;
}

variable_types:
buffer
unsigned char *

variable_types:
len
unsigned int *


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

v2 = translate("MAGscript %i&", a2);
return open_program(v2, a1, MAG_parse);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = translate("MAGscript %i&", a2);
return open_program(v2, a1, MAG_parse);
}

original_code:
void MAG_start(Uchar *title)
{
  open_program(translate("MAGscript %i&"), title, MAG_parse);
}

canonical_original_code:
void MAG_start(unsigned short *title)
{
  open_program(translate("MAGscript %i&"), title, MAG_parse);
}

variable_types:
title
unsigned short *


decompiled_code:
__int64 __fastcall call_str(__int64 (__fastcall *a1)(_QWORD), _QWORD **a2)
{
return a1(**a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 (__fastcall *a1)(_QWORD), _QWORD **a2)
{
return a1(**a2);
}

original_code:
static int call_str(int (*fcal)(), void **args)
{
  return (*fcal)(*((Uchar**)args[0]));
}

canonical_original_code:
static int call_str(int (*fcal)(), void **args)
{
  return (*fcal)(*((unsigned short **)args[0]));
}

variable_types:
fcal
int (*)()

variable_types:
args
void **


decompiled_code:
__int64 init_library()
{
__int64 v0; // rax

v0 = define_prototype(&tlist, 1LL, 0LL, call_str);
define_function("MAG_start", "Start the MAG system.", v0, MAG_start);
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax

v0 = define_prototype(&tlist, 1LL, 0LL, call_str);
define_function("MAG_start", "Start the MAG system.", v0, MAG_start);
return 1LL;
}

original_code:
int init_library(void)
{
  Prototype *pt;
  pt = define_prototype(tlist[0],1, 0, call_str);
  define_function("MAG_start", "Start the MAG system.",
    pt, MAG_start);
  return 1;
}

canonical_original_code:
int init_library()
{
  struct Prototype *pt;
  pt = define_prototype(tlist[0],1, 0, call_str);
  define_function("MAG_start", "Start the MAG system.",
    pt, MAG_start);
  return 1;
}

variable_types: struct Prototype { unsigned int *type; int n; unsigned int restype; int max; int (*caller)(); } *


decompiled_code:
__int64 __fastcall increase_refcount(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rdx

result = ((unsigned __int16)a1 ^ (unsigned __int16)((int)a1 >> 12)) & 0xFFF;
if ( a1 )
{
v3 = ((unsigned __int16)a1 ^ (unsigned __int16)((int)a1 >> 12)) & 0xFFF;
result = hash_table[v3];
if ( result )
{
while ( *(_QWORD *)result != a1 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
goto LABEL_8;
}
++*(_DWORD *)(result + 16);
}
else
{
LABEL_8:
result = FreeList_malloc(&refelems);
v4 = hash_table[v3];
*(_QWORD *)result = a1;
*(_QWORD *)(result + 24) = v4;
*(_DWORD *)(result + 16) = 1;
*(_QWORD *)(result + 8) = a2;
hash_table[v3] = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rdx

result = ((unsigned __int16)a1 ^ (unsigned __int16)((int)a1 >> 12)) & 0xFFF;
if ( a1 )
{
v3 = ((unsigned __int16)a1 ^ (unsigned __int16)((int)a1 >> 12)) & 0xFFF;
result = hash_table[v3];
if ( result )
{
while ( *(_QWORD *)result != a1 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
goto LABEL_8;
}
++*(_DWORD *)(result + 16);
}
else
{
LABEL_8:
result = FreeList_malloc(&refelems);
v4 = hash_table[v3];
*(_QWORD *)result = a1;
*(_QWORD *)(result + 24) = v4;
*(_DWORD *)(result + 16) = 1;
*(_QWORD *)(result + 8) = a2;
hash_table[v3] = result;
}
}
return result;
}

original_code:
void increase_refcount(void *pointer, void (*freefunc)(void*))
{
  int i=(((((int)(pointer))>>12)^((int)(pointer)))&((1<<12)-1));
  RefElem *re= hash_table[i];
  if (!pointer) return;
  while (re && re->pointer!=pointer) re=re->next;
  if (re) {
    re->count++;
    ;
  } else {
    ;
    re=FreeList_malloc(&refelems);
    re->next=hash_table[i];
    re->pointer=pointer;
    re->count=1;
    re->freefunc=freefunc;
    hash_table[i]=re;
  }
}

canonical_original_code:
void increase_refcount(void *pointer, void (*freefunc)(void *))
{
  int i = (((((int)(pointer))>>12)^((int)(pointer)))&((1<<12)-1));
  struct RefElem *re = hash_table[i];
  if (!pointer) return;
  while (re && re->pointer!=pointer) re=re->next;
  if (re) {
    re->count++;
    ;
  } else {
    ;
    re=FreeList_malloc(&refelems);
    re->next=hash_table[i];
    re->pointer=pointer;
    re->count=1;
    re->freefunc=freefunc;
    hash_table[i]=re;
  }
}

variable_types:
pointer
void *

variable_types:
freefunc
void (*)(void *)

variable_types: struct RefElem { void *pointer; void (*freefunc)(void *); int count; struct RefElem *next; } *


decompiled_code:
__int64 __fastcall decrease_refcount(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rbx
__int64 v3; // rbp
void (*v5)(void); // rax

result = ((unsigned __int16)a1 ^ (unsigned __int16)((int)a1 >> 12)) & 0xFFF;
v2 = &hash_table[result];
if ( a1 )
{
v3 = hash_table[result];
if ( v3 )
{
while ( *(_QWORD *)v3 != a1 )
{
v2 = (_QWORD *)(v3 + 24);
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return result;
}
if ( (*(_DWORD *)(v3 + 16))-- == 1 )
{
v5 = *(void (**)(void))(v3 + 8);
if ( v5 )
v5();
*v2 = *(_QWORD *)(v3 + 24);
result = FreeList_free(&refelems, v3);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rbx
__int64 v3; // rbp
void (*v5)(void); // rax

result = ((unsigned __int16)a1 ^ (unsigned __int16)((int)a1 >> 12)) & 0xFFF;
v2 = &hash_table[result];
if ( a1 )
{
v3 = hash_table[result];
if ( v3 )
{
while ( *(_QWORD *)v3 != a1 )
{
v2 = (_QWORD *)(v3 + 24);
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return result;
}
if ( (*(_DWORD *)(v3 + 16))-- == 1 )
{
v5 = *(void (**)(void))(v3 + 8);
if ( v5 )
v5();
*v2 = *(_QWORD *)(v3 + 24);
result = FreeList_free(&refelems, v3);
}
}
}
return result;
}

original_code:
void decrease_refcount(void *pointer)
{
  int i=(((((int)(pointer))>>12)^((int)(pointer)))&((1<<12)-1));
  RefElem **re=&(hash_table[i]);
  if (!pointer) return;
  while (*re && (*re)->pointer!=pointer)
     re=&(*re)->next;
  if (*re) {
    (*re)->count--;
    ;
    if (!(*re)->count) {
      RefElem *h;
      ;
      h=*re;
      if (h->freefunc) {
 (*h->freefunc)(pointer);
      }
      *re = h->next;
      FreeList_free(&refelems, h);
    }
  } else {
    ;
    refcount_break(16);
  }
}

canonical_original_code:
void decrease_refcount(void *pointer)
{
  int i = (((((int)(pointer))>>12)^((int)(pointer)))&((1<<12)-1));
  struct RefElem **re = &(hash_table[i]);
  if (!pointer) return;
  while (*re && (*re)->pointer!=pointer)
     re=&(*re)->next;
  if (*re) {
    (*re)->count--;
    ;
    if (!(*re)->count) {
      struct RefElem *h;
      ;
      h=*re;
      if (h->freefunc) {
 (*h->freefunc)(pointer);
      }
      *re = h->next;
      FreeList_free(&refelems, h);
    }
  } else {
    ;
    refcount_break(16);
  }
}

variable_types: struct RefElem { void *pointer; void (*freefunc)(void *); int count; struct RefElem *next; } **


decompiled_code:
unsigned int __fastcall nonblock_write(void *buf, int a2)
{
char *v2; // rbp
int v4; // eax
unsigned int result; // eax
_DWORD *v6; // rax
int v7; // edx
const void *v8; // rsi
int v9; // eax
_DWORD *v10; // r12
int v11; // edx
_DWORD *v12; // rax
size_t v13; // rdi
_QWORD *v14; // r12
__int64 v15; // rbx
_BYTE *v16; // rax
__int64 v17; // rax

critical = 1;
v2 = (char *)buf;
if ( !buffersize )
goto LABEL_2;
v6 = beginstack;
LABEL_8:
v7 = v6[4];
v8 = (const void *)*((_QWORD *)v6 + 1);
while ( 1 )
{
v9 = write(outfnr, v8, v7);
if ( v9 == -1 )
break;
v10 = beginstack;
buffersize -= v9;
v11 = *((_DWORD *)beginstack + 4);
v8 = (const void *)(*((_QWORD *)beginstack + 1) + v9);
*((_QWORD *)beginstack + 1) = v8;
v7 = v11 - v9;
v10[4] = v7;
if ( !v7 )
{
free(*(void **)v10);
beginstack = (void *)*((_QWORD *)v10 + 3);
free(v10);
v6 = beginstack;
if ( beginstack )
goto LABEL_8;
break;
}
}
if ( buffersize )
{
if ( a2 )
{
LABEL_14:
v12 = malloc(0x20uLL);
v13 = a2;
buffersize += a2;
v12[4] = a2;
v14 = v12;
*((_QWORD *)v12 + 3) = 0LL;
v15 = a2 - 1;
v16 = malloc(v13);
*v14 = v16;
v14[1] = v16;
while ( 1 )
{
v16[v15] = v2[v15];
if ( !(_DWORD)v15 )
break;
v16 = (_BYTE *)v14[1];
--v15;
}
if ( beginstack )
{
v17 = endstack;
endstack = (__int64)v14;
*(_QWORD *)(v17 + 24) = v14;
}
else
{
endstack = (__int64)v14;
beginstack = v14;
}
goto LABEL_5;
}
}
else
{
LABEL_2:
v4 = write(outfnr, buf, a2);
if ( v4 > 0 )
{
a2 -= v4;
v2 = (char *)buf + v4;
}
if ( a2 )
goto LABEL_14;
}
LABEL_5:
critical = 0;
result = alarm_needed;
if ( alarm_needed )
{
alarm_needed = buffersize == 0 ? 10 : 1;
result = alarm(alarm_needed);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func10(void *buf, int a2)
{
char *v2; // rbp
int v4; // eax
unsigned int result; // eax
_DWORD *v6; // rax
int v7; // edx
const void *v8; // rsi
int v9; // eax
_DWORD *v10; // r12
int v11; // edx
_DWORD *v12; // rax
size_t v13; // rdi
_QWORD *v14; // r12
__int64 v15; // rbx
_BYTE *v16; // rax
__int64 v17; // rax

critical = 1;
v2 = (char *)buf;
if ( !buffersize )
goto LABEL_2;
v6 = beginstack;
LABEL_8:
v7 = v6[4];
v8 = (const void *)*((_QWORD *)v6 + 1);
while ( 1 )
{
v9 = write(outfnr, v8, v7);
if ( v9 == -1 )
break;
v10 = beginstack;
buffersize -= v9;
v11 = *((_DWORD *)beginstack + 4);
v8 = (const void *)(*((_QWORD *)beginstack + 1) + v9);
*((_QWORD *)beginstack + 1) = v8;
v7 = v11 - v9;
v10[4] = v7;
if ( !v7 )
{
free(*(void **)v10);
beginstack = (void *)*((_QWORD *)v10 + 3);
free(v10);
v6 = beginstack;
if ( beginstack )
goto LABEL_8;
break;
}
}
if ( buffersize )
{
if ( a2 )
{
LABEL_14:
v12 = malloc(0x20uLL);
v13 = a2;
buffersize += a2;
v12[4] = a2;
v14 = v12;
*((_QWORD *)v12 + 3) = 0LL;
v15 = a2 - 1;
v16 = malloc(v13);
*v14 = v16;
v14[1] = v16;
while ( 1 )
{
v16[v15] = v2[v15];
if ( !(_DWORD)v15 )
break;
v16 = (_BYTE *)v14[1];
--v15;
}
if ( beginstack )
{
v17 = endstack;
endstack = (__int64)v14;
*(_QWORD *)(v17 + 24) = v14;
}
else
{
endstack = (__int64)v14;
beginstack = v14;
}
goto LABEL_5;
}
}
else
{
LABEL_2:
v4 = write(outfnr, buf, a2);
if ( v4 > 0 )
{
a2 -= v4;
v2 = (char *)buf + v4;
}
if ( a2 )
goto LABEL_14;
}
LABEL_5:
critical = 0;
result = alarm_needed;
if ( alarm_needed )
{
alarm_needed = buffersize == 0 ? 10 : 1;
result = alarm(alarm_needed);
}
return result;
}

original_code:
static void nonblock_write(char *c, int b)
{
    int wrres=1;
    critical=1;
    if (buffersize) {
 do {
     wrres=write(outfnr, beginstack->str, beginstack->len);
     if (wrres!=-1) {
  beginstack->len -= wrres;
  beginstack->str += wrres;
  buffersize=buffersize-wrres;
  if (!beginstack->len) {
      STRSTACK *h=beginstack;
      free(beginstack->ptr);
      beginstack=h->next;
      free(h);
  }
     }
 } while (wrres!=-1 && beginstack);
    }
    if (!buffersize)
 wrres=write(outfnr, c, b);
    else
 wrres= -1;
    if (wrres>0) {
 c=c+wrres;
 b=b-wrres;
    }
    if (b) {
 STRSTACK *h;
 h=(STRSTACK *)malloc(sizeof(STRSTACK));
 h->next=((void *)0);
 h->len=b;
 buffersize+=b;
 h->str=h->ptr=(char*) malloc(b*sizeof(char));
 while (b--) h->str[b]=c[b];
 if (!beginstack)
     beginstack=endstack=h;
 else {
     endstack->next=h;
     endstack=h;
 }
    }
    critical=0;
    if (alarm_needed) {
 if (buffersize)
     alarm_needed=1;
 else
     alarm_needed=10;
 alarm(alarm_needed);
    }
}

canonical_original_code:
static void nonblock_write(char *c, int b)
{
    int wrres = 1;
    critical=1;
    if (buffersize) {
 do {
     wrres=write(outfnr, beginstack->str, beginstack->len);
     if (wrres!=-1) {
  beginstack->len -= wrres;
  beginstack->str += wrres;
  buffersize=buffersize-wrres;
  if (!beginstack->len) {
      struct STRSTACK *h = beginstack;
      free(beginstack->ptr);
      beginstack=h->next;
      free(h);
  }
     }
 } while (wrres!=-1 && beginstack);
    }
    if (!buffersize)
 wrres=write(outfnr, c, b);
    else
 wrres= -1;
    if (wrres>0) {
 c=c+wrres;
 b=b-wrres;
    }
    if (b) {
 struct STRSTACK *h;
 h=(struct STRSTACK *)malloc(sizeof(STRSTACK));
 h->next=((void *)0);
 h->len=b;
 buffersize+=b;
 h->str=h->ptr=(char *) malloc(b*sizeof(char));
 while (b--) h->str[b]=c[b];
 if (!beginstack)
     beginstack=endstack=h;
 else {
     endstack->next=h;
     endstack=h;
 }
    }
    critical=0;
    if (alarm_needed) {
 if (buffersize)
     alarm_needed=1;
 else
     alarm_needed=10;
 alarm(alarm_needed);
    }
}

variable_types:
c
char *

variable_types: b int

variable_types: wrres int

variable_types: struct STRSTACK { char *ptr; char *str; int len; struct STRSTACK *next; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
int v5; // ebp
const char *v6; // rdi
__int64 v7; // r14
char v8; // al
unsigned int v9; // eax
__int64 v10; // rdx
unsigned int v11; // er12
int v12; // ebx
const void **v13; // rax
void *v14; // rdi
void *v15; // rax
__int64 v17; // rbp
int v18; // [rsp+Ch] [rbp-5Ch] BYREF
Atom v19; // [rsp+10h] [rbp-58h] BYREF
unsigned __int64 v20; // [rsp+18h] [rbp-50h] BYREF
unsigned __int64 v21; // [rsp+20h] [rbp-48h] BYREF
unsigned __int8 *v22; // [rsp+28h] [rbp-40h] BYREF

v4 = 1;
outf = (__int64)_bss_start;
outfnr = fileno(_bss_start);
if ( argc > 1 )
{
do
{
v5 = v4 + 1;
v6 = argv[v4];
v7 = v4;
if ( *v6 == 45 )
{
v8 = v6[1];
if ( v8 == 100 )
{
if ( !strcmp(v6 + 2, "isplay") )
{
v5 = v4 + 2;
displayname = (char *)argv[v7 + 1];
}
}
else if ( v8 > 100 )
{
if ( v8 == 119 && !strcmp(v6 + 2, "indow") )
{
v5 = v4 + 2;
testwin = strtol(argv[v7 + 1], 0LL, 0);
}
}
else if ( v8 == 69 )
{
v5 = v4 + 2;
endname = (char *)argv[v7 + 1];
}
else if ( v8 == 84 )
{
v5 = v4 + 2;
propname = (char *)argv[v7 + 1];
}
}
v4 = v5;
}
while ( argc > v5 );
}
signal(1, handle);
signal(2, handle);
signal(3, handle);
signal(4, handle);
signal(6, handle);
signal(8, handle);
signal(7, handle);
signal(11, handle);
signal(31, handle);
signal(13, handle);
signal(14, handle);
signal(15, handle);
signal(23, handle);
signal(29, handle);
signal(24, handle);
signal(25, handle);
signal(10, handle);
signal(12, handle);
v9 = fcntl(outfnr, 3);
v10 = v9;
v11 = v9;
BYTE1(v10) = BYTE1(v9) | 8;
fcntl(outfnr, 4, v10);
server_init();
alarm(alarm_needed);
if ( propempty )
goto LABEL_29;
do
{
v12 = 0;
XNextEvent(display, &event);
if ( event.type == 28 )
{
if ( event.xkey.root == dummy )
{
v12 = event.xexpose.count;
if ( event.xexpose.count )
{
v12 = 0;
}
else
{
v21 = 1LL;
v17 = 0LL;
do
{
XGetWindowProperty(display, testwin, dummy, v17 / 4, 512LL, 1, textprop, &v19, &v18, &v20, &v21, &v22);
nonblock_write(v22);
XFree(v22);
v17 += v20;
}
while ( v21 );
propempty = 0;
}
}
}
else if ( event.type == 17 )
{
v12 = event.xkey.root == testwin;
}
nonblock_write("");
}
while ( !(propempty | v12) );
if ( !v12 )
LABEL_29:
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
fcntl(outfnr, 4, v11);
v13 = (const void **)beginstack;
for ( alarm_needed = 0; beginstack; v13 = (const void **)beginstack )
{
write(outfnr, v13[1], *((int *)v13 + 4));
free(*((void **)beginstack + 1));
v14 = beginstack;
v15 = (void *)*((_QWORD *)beginstack + 3);
endstack = (__int64)beginstack;
beginstack = v15;
free(v14);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
int v5; // ebp
const char *v6; // rdi
__int64 v7; // r14
char v8; // al
unsigned int v9; // eax
__int64 v10; // rdx
unsigned int v11; // er12
int v12; // ebx
const void **v13; // rax
void *v14; // rdi
void *v15; // rax
__int64 v17; // rbp
int v18; // [rsp+Ch] [rbp-5Ch] BYREF
Atom v19; // [rsp+10h] [rbp-58h] BYREF
unsigned __int64 v20; // [rsp+18h] [rbp-50h] BYREF
unsigned __int64 v21; // [rsp+20h] [rbp-48h] BYREF
unsigned __int8 *v22; // [rsp+28h] [rbp-40h] BYREF

v4 = 1;
outf = (__int64)_bss_start;
outfnr = fileno(_bss_start);
if ( argc > 1 )
{
do
{
v5 = v4 + 1;
v6 = argv[v4];
v7 = v4;
if ( *v6 == 45 )
{
v8 = v6[1];
if ( v8 == 100 )
{
if ( !strcmp(v6 + 2, "isplay") )
{
v5 = v4 + 2;
displayname = (char *)argv[v7 + 1];
}
}
else if ( v8 > 100 )
{
if ( v8 == 119 && !strcmp(v6 + 2, "indow") )
{
v5 = v4 + 2;
testwin = strtol(argv[v7 + 1], 0LL, 0);
}
}
else if ( v8 == 69 )
{
v5 = v4 + 2;
endname = (char *)argv[v7 + 1];
}
else if ( v8 == 84 )
{
v5 = v4 + 2;
propname = (char *)argv[v7 + 1];
}
}
v4 = v5;
}
while ( argc > v5 );
}
signal(1, handle);
signal(2, handle);
signal(3, handle);
signal(4, handle);
signal(6, handle);
signal(8, handle);
signal(7, handle);
signal(11, handle);
signal(31, handle);
signal(13, handle);
signal(14, handle);
signal(15, handle);
signal(23, handle);
signal(29, handle);
signal(24, handle);
signal(25, handle);
signal(10, handle);
signal(12, handle);
v9 = fcntl(outfnr, 3);
v10 = v9;
v11 = v9;
BYTE1(v10) = BYTE1(v9) | 8;
fcntl(outfnr, 4, v10);
func9();
alarm(alarm_needed);
if ( propempty )
goto LABEL_29;
do
{
v12 = 0;
XNextEvent(display, &event);
if ( event.type == 28 )
{
if ( event.xkey.root == dummy )
{
v12 = event.xexpose.count;
if ( event.xexpose.count )
{
v12 = 0;
}
else
{
v21 = 1LL;
v17 = 0LL;
do
{
XGetWindowProperty(display, testwin, dummy, v17 / 4, 512LL, 1, textprop, &v19, &v18, &v20, &v21, &v22);
func10(v22);
XFree(v22);
v17 += v20;
}
while ( v21 );
propempty = 0;
}
}
}
else if ( event.type == 17 )
{
v12 = event.xkey.root == testwin;
}
func10("");
}
while ( !(propempty | v12) );
if ( !v12 )
LABEL_29:
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
fcntl(outfnr, 4, v11);
v13 = (const void **)beginstack;
for ( alarm_needed = 0; beginstack; v13 = (const void **)beginstack )
{
write(outfnr, v13[1], *((int *)v13 + 4));
free(*((void **)beginstack + 1));
v14 = beginstack;
v15 = (void *)*((_QWORD *)beginstack + 3);
endstack = (__int64)beginstack;
beginstack = v15;
free(v14);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int i;
    int close_con=0;
    outf = stdout;
    outfnr=fileno(outf);
    for (i=1; i<argc; i++) {
 if (argv[i][0]=='-') {
     switch (argv[i][1]) {
     case 'T': propname = argv[i+1]; i++; break;
     case 'E': endname = argv[i+1]; i++; break;
     case 'd':
  if (!strcmp(argv[i]+2, "isplay")) {
      displayname = argv[i+1];
      i++;
  }
  break;
     case 'w':
  if (!strcmp(argv[i]+2,"indow")) {
      testwin = strtol(argv[i+1], ((void *)0), 0);
      i++;
  }
  break;
     default: break;
     }
 }
    }
    i=1;
    signal(1, handle);
    signal(2, handle);
    signal(3, handle);
    signal(4, handle);
    signal(6, handle);
    signal(8, handle);
    signal(7, handle);
    signal(11, handle);
    signal(31, handle);
    signal(13, handle);
    signal(14, handle);
    signal(15, handle);
    signal(23, handle);
    signal(29, handle);
    signal(24, handle);
    signal(25, handle);
    signal(10, handle);
    signal(12, handle);
    i=fcntl(outfnr, 3);
    fcntl(outfnr, 4, i|04000|0|04000);
    server_init();
    alarm(alarm_needed);
    while (!propempty && !close_con) {
 XNextEvent(display, &event);
 if (event.type==28 &&
     event.xproperty.atom==dummy &&
     event.xproperty.state==0) {
     long n=0;
     long len=512;
     Atom actt;
     int actf;
     unsigned long nit,baf=1;
     unsigned char *prp;
     while (baf) {
  XGetWindowProperty(display, testwin, dummy, n/4, len, 1,
       textprop, &actt, &actf, &nit, &baf, &prp);
  nonblock_write((char*)prp, nit);
  XFree(prp);
  n=n+nit;
     }
     propempty= 0;
 } else if (event.type==17 &&
     event.xdestroywindow.window == testwin)
     close_con=1;
 nonblock_write("",0);
    }
    if (!close_con) XDeleteProperty(display, testwin, testend);
    XCloseDisplay(display);
    fcntl(outfnr, 4, i);
    alarm_needed=0;
    while (beginstack) {
 write(outfnr,beginstack->str, beginstack->len);
 free(beginstack->str);
 endstack=beginstack;
 beginstack=endstack->next;
 free(endstack);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i;
    int close_con = 0;
    outf = stdout;
    outfnr=fileno(outf);
    for (i=1; i<argc; i++) {
 if (argv[i][0]=='-') {
     switch (argv[i][1]) {
     case 'T': propname = argv[i+1]; i++; break;
     case 'E': endname = argv[i+1]; i++; break;
     case 'd':
  if (!strcmp(argv[i]+2, "isplay")) {
      displayname = argv[i+1];
      i++;
  }
  break;
     case 'w':
  if (!strcmp(argv[i]+2,"indow")) {
      testwin = strtol(argv[i+1], ((void *)0), 0);
      i++;
  }
  break;
     default: break;
     }
 }
    }
    i=1;
    signal(1, handle);
    signal(2, handle);
    signal(3, handle);
    signal(4, handle);
    signal(6, handle);
    signal(8, handle);
    signal(7, handle);
    signal(11, handle);
    signal(31, handle);
    signal(13, handle);
    signal(14, handle);
    signal(15, handle);
    signal(23, handle);
    signal(29, handle);
    signal(24, handle);
    signal(25, handle);
    signal(10, handle);
    signal(12, handle);
    i=fcntl(outfnr, 3);
    fcntl(outfnr, 4, i|04000|0|04000);
    server_init();
    alarm(alarm_needed);
    while (!propempty && !close_con) {
 XNextEvent(display, &event);
 if (event.type==28 &&
     event.xproperty.atom==dummy &&
     event.xproperty.state==0) {
     long n = 0;
     long len = 512;
     unsigned long actt;
     int actf;
     unsigned long nit; unsigned long baf = 1;
     unsigned char *prp;
     while (baf) {
  XGetWindowProperty(display, testwin, dummy, n/4, len, 1,
       textprop, &actt, &actf, &nit, &baf, &prp);
  nonblock_write((char *)prp, nit);
  XFree(prp);
  n=n+nit;
     }
     propempty= 0;
 } else if (event.type==17 &&
     event.xdestroywindow.window == testwin)
     close_con=1;
 nonblock_write("",0);
    }
    if (!close_con) XDeleteProperty(display, testwin, testend);
    XCloseDisplay(display);
    fcntl(outfnr, 4, i);
    alarm_needed=0;
    while (beginstack) {
 write(outfnr,beginstack->str, beginstack->len);
 free(beginstack->str);
 endstack=beginstack;
 beginstack=endstack->next;
 free(endstack);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: n long

variable_types: len long

variable_types:
actt
unsigned long

variable_types: actf int

variable_types:
nit
unsigned long

variable_types:
baf
unsigned long

variable_types:
prp
unsigned char *


decompiled_code:
int server_init()
{
Display *v0; // rax
__int64 v1; // rbx
char *v3; // rax
XSetWindowAttributes v4; // [rsp+0h] [rbp-78h] BYREF

v0 = XOpenDisplay(displayname);
display = v0;
if ( !v0 )
{
v3 = XDisplayName(displayname);
fprintf(stderr, "xpipeout: Cannot connect to server %s\n", v3);
exit(-1);
}
v1 = v0->default_screen;
textprop = XInternAtom(v0, "TEXT", 1);
dummy = XInternAtom(display, propname, 0);
testend = XInternAtom(display, endname, 0);
if ( !testwin )
testwin = display->screens[v1].root;
v4.event_mask = 4325376LL;
XSetErrorHandler((XErrorHandler)error_handler);
XSetIOErrorHandler((XIOErrorHandler)ioerror_handler);
XChangeWindowAttributes(display, testwin, 0x800uLL, &v4);
return XChangeProperty(display, testwin, testend, textprop, 8, 0, "Yes", 3);
}

canonical_decompiled_code:
int func9()
{
Display *v0; // rax
__int64 v1; // rbx
char *v3; // rax
XSetWindowAttributes v4; // [rsp+0h] [rbp-78h] BYREF

v0 = XOpenDisplay(displayname);
display = v0;
if ( !v0 )
{
v3 = XDisplayName(displayname);
fprintf(stderr, "xpipeout: Cannot connect to server %s\n", v3);
exit(-1);
}
v1 = v0->default_screen;
textprop = XInternAtom(v0, "TEXT", 1);
dummy = XInternAtom(display, propname, 0);
testend = XInternAtom(display, endname, 0);
if ( !testwin )
testwin = display->screens[v1].root;
v4.event_mask = 4325376LL;
XSetErrorHandler((XErrorHandler)error_handler);
XSetIOErrorHandler((XIOErrorHandler)ioerror_handler);
XChangeWindowAttributes(display, testwin, 0x800uLL, &v4);
return XChangeProperty(display, testwin, testend, textprop, 8, 0, "Yes", 3);
}

original_code:
static void server_init(void)
{
    int i;
    XSetWindowAttributes winattr;
    if ((display=XOpenDisplay(displayname))==((void *)0)) {
 fprintf(stderr, "xpipeout: Cannot connect to server %s\n",
  XDisplayName(displayname));
 exit(-1);
    }
    i = (((_XPrivDisplay)(display))->default_screen);
    textprop = XInternAtom(display, "TEXT", 1);
    dummy = XInternAtom(display, propname, 0);
    testend = XInternAtom(display, endname, 0);
    if (!testwin) testwin = ((&((_XPrivDisplay)(display))->screens[i])->root);
    winattr.event_mask = (1L<<22) | (1L<<17);
    XSetErrorHandler(error_handler);
    XSetIOErrorHandler(ioerror_handler);
    XChangeWindowAttributes(display, testwin, (1L<<11), &winattr);
    XChangeProperty(display, testwin, testend, textprop,8, 0,
      (unsigned char*)"Yes", 3);
}

canonical_original_code:
static void server_init()
{
    int i;
    struct XSetWindowAttributes winattr;
    if ((display=XOpenDisplay(displayname))==((void *)0)) {
 fprintf(stderr, "xpipeout: Cannot connect to server %s\n",
  XDisplayName(displayname));
 exit(-1);
    }
    i = (((_XPrivDisplay)(display))->default_screen);
    textprop = XInternAtom(display, "TEXT", 1);
    dummy = XInternAtom(display, propname, 0);
    testend = XInternAtom(display, endname, 0);
    if (!testwin) testwin = ((&((_XPrivDisplay)(display))->screens[i])->root);
    winattr.event_mask = (1L<<22) | (1L<<17);
    XSetErrorHandler(error_handler);
    XSetIOErrorHandler(ioerror_handler);
    XChangeWindowAttributes(display, testwin, (1L<<11), &winattr);
    XChangeProperty(display, testwin, testend, textprop,8, 0,
      (unsigned char *)"Yes", 3);
}

variable_types: struct XSetWindowAttributes { unsigned long background_pixmap; unsigned long background_pixel; unsigned long border_pixmap; unsigned long border_pixel; int bit_gravity; int win_gravity; int backing_store; unsigned long backing_planes; unsigned long backing_pixel; int save_under; long event_mask; long do_not_propagate_mask; int override_redirect; unsigned long colormap; unsigned long cursor; }


handle

decompiled_code:
void __fastcall handle(unsigned __int64 a1)
{
__int64 v1; // rax

if ( (unsigned int)a1 > 0x1D || (v1 = 545275904LL, !_bittest64(&v1, a1)) )
{
signal(a1, 0LL);
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
exit(0);
}
signal(a1, handle);
if ( !critical )
nonblock_write("", 0);
}

canonical_decompiled_code:
void __fastcall func11(unsigned __int64 a1)
{
__int64 v1; // rax

if ( (unsigned int)a1 > 0x1D || (v1 = 545275904LL, !_bittest64(&v1, a1)) )
{
signal(a1, 0LL);
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
exit(0);
}
signal(a1, handle);
if ( !critical )
func10("", 0);
}

original_code:
static void handle(int sig)
{
    if (sig==29 || sig==23 || sig==14) {
 signal(sig, handle);
 if (!critical) nonblock_write("",0);
    } else {
 signal(sig, ((__sighandler_t) 0));
 XDeleteProperty(display, testwin, testend);
 XCloseDisplay(display);
 exit(0);
    }
}

canonical_original_code:
static void handle(int sig)
{
    if (sig==29 || sig==23 || sig==14) {
 signal(sig, handle);
 if (!critical) nonblock_write("",0);
    } else {
 signal(sig, ((void (*)(int)) 0));
 XDeleteProperty(display, testwin, testend);
 XCloseDisplay(display);
 exit(0);
    }
}

variable_types: sig int


rrot

original_code:
static BreanchNode* rrot(BreanchNode* t)
{
    BreanchNode* b;
    int i;
    b=t->left;
    t->left=b->right;
    b->right=t;
    i= -t->bal*5-b->bal+2;
    b->bal = -newbaltop[i];
    t->bal = -newbalright[i];
    return b;
}

canonical_original_code:
static struct bnode *rrot(struct bnode *t)
{
    struct bnode *b;
    int i;
    b=t->left;
    t->left=b->right;
    b->right=t;
    i= -t->bal*5-b->bal+2;
    b->bal = -newbaltop[i];
    t->bal = -newbalright[i];
    return b;
}

variable_types:
t
struct bnode *

variable_types: struct bnode { char kind; char bal; void *val; struct bnode *left; struct bnode *right; } *


lrot

decompiled_code:
__int64 __fastcall lrot(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // ecx

result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(result + 16);
*(_QWORD *)(result + 16) = a1;
v2 = 5 * *(char *)(a1 + 1) + *(char *)(result + 1) + 2;
v3 = newbaltop[v2];
LODWORD(v2) = newbalright[v2];
*(_BYTE *)(result + 1) = v3;
*(_BYTE *)(a1 + 1) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // ecx

result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(result + 16);
*(_QWORD *)(result + 16) = a1;
v2 = 5 * *(char *)(a1 + 1) + *(char *)(result + 1) + 2;
v3 = newbaltop[v2];
LODWORD(v2) = newbalright[v2];
*(_BYTE *)(result + 1) = v3;
*(_BYTE *)(a1 + 1) = v2;
return result;
}

original_code:
static BreanchNode* lrot(BreanchNode* t)
{
    BreanchNode* b;
    int i;
    b=t->right;
    t->right=b->left;
    b->left=t;
    i=t->bal*5+b->bal+2;
    b->bal = newbaltop[i];
    t->bal = newbalright[i];
    return b;
}

canonical_original_code:
static struct bnode *lrot(struct bnode *t)
{
    struct bnode *b;
    int i;
    b=t->right;
    t->right=b->left;
    b->left=t;
    i=t->bal*5+b->bal+2;
    b->bal = newbaltop[i];
    t->bal = newbalright[i];
    return b;
}

return_type: struct bnode { char kind; char bal; void *val; struct bnode *left; struct bnode *right; } *


rotate

original_code:
static BreanchNode* rotate(BreanchNode* t)
{
    if (t->bal < -1) {
 if (t->left->bal>0) t->left=lrot(t->left);
 t=rrot(t);
    } else if (t->bal > 1) {
 if (t->right->bal<0) t->right=rrot(t->right);
 t=lrot(t);
    }
    return t;
}

canonical_original_code:
static struct bnode *rotate(struct bnode *t)
{
    if (t->bal < -1) {
 if (t->left->bal>0) t->left=lrot(t->left);
 t=rrot(t);
    } else if (t->bal > 1) {
 if (t->right->bal<0) t->right=rrot(t->right);
 t=lrot(t);
    }
    return t;
}

user_defined_types: struct bnode { char kind; char bal; void *val; struct bnode *left; struct bnode *right; }


decompiled_code:
void __fastcall free_breanchnode(void *ptr)
{
if ( ptr )
{
if ( *(_BYTE *)ptr )
{
free_breanchnode(*((void **)ptr + 2));
free_breanchnode(*((void **)ptr + 3));
free(ptr);
}
else
{
if ( free_leaf )
free_leaf();
free(ptr);
}
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
if ( *(_BYTE *)ptr )
{
func3(*((void **)ptr + 2));
func3(*((void **)ptr + 3));
free(ptr);
}
else
{
if ( free_leaf )
free_leaf();
free(ptr);
}
}
}

original_code:
static void free_breanchnode(BreanchNode* t)
{
    if (!t) return;
    if (t->kind==0) {
 if (free_leaf) (*free_leaf)((void*) t);
 free(t);
    } else {
 free_breanchnode(t->left);
 free_breanchnode(t->right);
 free(t);
    }
}

canonical_original_code:
static void free_breanchnode(struct bnode *t)
{
    if (!t) return;
    if (t->kind==0) {
 if (free_leaf) (*free_leaf)((void *) t);
 free(t);
    } else {
 free_breanchnode(t->left);
 free_breanchnode(t->right);
 free(t);
    }
}


decompiled_code:
void *__fastcall delete_node(void *ptr, __int64 a2)
{
void *result; // rax
int v3; // ebx
__int64 v4; // rax
char v5; // al
__int64 v6; // rax
int v7; // ecx
__int64 v8; // rax
void *v9; // [rsp+0h] [rbp-30h]
__int64 v10; // [rsp+0h] [rbp-30h]

if ( !ptr )
return 0LL;
if ( *(_BYTE *)ptr )
{
v3 = cmp_leaf(a2, *((_QWORD *)ptr + 1));
if ( v3 < 0 )
{
v6 = delete_node(*((void **)ptr + 2));
v7 = dchange;
*((_QWORD *)ptr + 2) = v6;
if ( !v7 )
return ptr;
if ( !v6 )
{
v10 = *((_QWORD *)ptr + 3);
rmin = v10 + 8;
free(ptr);
return (void *)v10;
}
v5 = *((_BYTE *)ptr + 1) + 1;
*((_BYTE *)ptr + 1) = v5;
if ( v5 <= 1 )
{
LABEL_12:
dchange = v5 == 0;
return ptr;
}
v8 = *((_QWORD *)ptr + 3);
}
else
{
v4 = delete_node(*((void **)ptr + 3));
*((_QWORD *)ptr + 3) = v4;
if ( !v3 )
*((_QWORD *)ptr + 1) = rmin;
if ( !dchange )
return ptr;
if ( !v4 )
{
v9 = (void *)*((_QWORD *)ptr + 2);
free(ptr);
result = v9;
rmin = (__int64)v9 + 8;
return result;
}
v5 = *((_BYTE *)ptr + 1) - 1;
*((_BYTE *)ptr + 1) = v5;
if ( v5 >= -1 )
goto LABEL_12;
v8 = *((_QWORD *)ptr + 2);
}
dchange = *(_BYTE *)(v8 + 1) != 0;
return (void *)rotate((__int64)ptr);
}
if ( (unsigned int)cmp_leaf(a2, (char *)ptr + 8) )
{
dchange = 0;
result = ptr;
}
else
{
if ( free_leaf )
free_leaf((char *)ptr + 8);
free(ptr);
result = 0LL;
dchange = 1;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(void *ptr, __int64 a2)
{
void *result; // rax
int v3; // ebx
__int64 v4; // rax
char v5; // al
__int64 v6; // rax
int v7; // ecx
__int64 v8; // rax
void *v9; // [rsp+0h] [rbp-30h]
__int64 v10; // [rsp+0h] [rbp-30h]

if ( !ptr )
return 0LL;
if ( *(_BYTE *)ptr )
{
v3 = cmp_leaf(a2, *((_QWORD *)ptr + 1));
if ( v3 < 0 )
{
v6 = func4(*((void **)ptr + 2));
v7 = dchange;
*((_QWORD *)ptr + 2) = v6;
if ( !v7 )
return ptr;
if ( !v6 )
{
v10 = *((_QWORD *)ptr + 3);
rmin = v10 + 8;
free(ptr);
return (void *)v10;
}
v5 = *((_BYTE *)ptr + 1) + 1;
*((_BYTE *)ptr + 1) = v5;
if ( v5 <= 1 )
{
LABEL_12:
dchange = v5 == 0;
return ptr;
}
v8 = *((_QWORD *)ptr + 3);
}
else
{
v4 = func4(*((void **)ptr + 3));
*((_QWORD *)ptr + 3) = v4;
if ( !v3 )
*((_QWORD *)ptr + 1) = rmin;
if ( !dchange )
return ptr;
if ( !v4 )
{
v9 = (void *)*((_QWORD *)ptr + 2);
free(ptr);
result = v9;
rmin = (__int64)v9 + 8;
return result;
}
v5 = *((_BYTE *)ptr + 1) - 1;
*((_BYTE *)ptr + 1) = v5;
if ( v5 >= -1 )
goto LABEL_12;
v8 = *((_QWORD *)ptr + 2);
}
dchange = *(_BYTE *)(v8 + 1) != 0;
return (void *)func2((__int64)ptr);
}
if ( (unsigned int)cmp_leaf(a2, (char *)ptr + 8) )
{
dchange = 0;
result = ptr;
}
else
{
if ( free_leaf )
free_leaf((char *)ptr + 8);
free(ptr);
result = 0LL;
dchange = 1;
}
return result;
}

original_code:
static BreanchNode* delete_node(BreanchNode* t, void* val)
{
    if (!t) return ((void *)0);
    if (t->kind==0) {
 if (!(*cmp_leaf)(val, (&(((LeafNode*)t)->val)))) {
     if (free_leaf) (*free_leaf)((&(((LeafNode*)t)->val)));
     free(t);
     t=((void *)0);
     dchange=1;
 } else
     dchange=0;
    } else {
 int cmpres= (*cmp_leaf)(val,t->val);
 if (cmpres<0) {
     t->left = delete_node(t->left, val);
     if (dchange) {
  if (!t->left) {
      BreanchNode* b;
      b=t;
      t=t->right;
      rmin=(&(((LeafNode*)t)->val));
      free(b);
  } else {
      t->bal = t->bal+1;
      if (t->bal>1) {
   dchange = (t->right->bal!=0);
   t=rotate(t);
      } else
   dchange = !t->bal;
  }
     }
 } else {
     t->right = delete_node(t->right, val);
     if (!cmpres) t->val=rmin;
     if (dchange) {
  if (!t->right) {
      BreanchNode* b;
      b=t;
      t=t->left;
      free(b);
      rmin=(&(((LeafNode*)t)->val));
  } else {
      t->bal = t->bal-1;
      if (t->bal<-1) {
   dchange = (t->left->bal!=0);
   t=rotate(t);
      } else
   dchange = !t->bal;
  }
     }
 }
    }
    return t;
}

canonical_original_code:
static struct bnode *delete_node(struct bnode *t, void *val)
{
    if (!t) return ((void *)0);
    if (t->kind==0) {
 if (!(*cmp_leaf)(val, (&(((struct lnode *)t)->val)))) {
     if (free_leaf) (*free_leaf)((&(((struct lnode *)t)->val)));
     free(t);
     t=((void *)0);
     dchange=1;
 } else
     dchange=0;
    } else {
 int cmpres = (*cmp_leaf)(val,t->val);
 if (cmpres<0) {
     t->left = delete_node(t->left, val);
     if (dchange) {
  if (!t->left) {
      struct bnode *b;
      b=t;
      t=t->right;
      rmin=(&(((struct lnode *)t)->val));
      free(b);
  } else {
      t->bal = t->bal+1;
      if (t->bal>1) {
   dchange = (t->right->bal!=0);
   t=rotate(t);
      } else
   dchange = !t->bal;
  }
     }
 } else {
     t->right = delete_node(t->right, val);
     if (!cmpres) t->val=rmin;
     if (dchange) {
  if (!t->right) {
      struct bnode *b;
      b=t;
      t=t->left;
      free(b);
      rmin=(&(((struct lnode *)t)->val));
  } else {
      t->bal = t->bal-1;
      if (t->bal<-1) {
   dchange = (t->left->bal!=0);
   t=rotate(t);
      } else
   dchange = !t->bal;
  }
     }
 }
    }
    return t;
}

variable_types:
val
void *

variable_types: cmpres int

user_defined_types: struct lnode { char kind; union DummyAlign val; }

user_defined_types: union DummyAlign { double al1; long al2; void *al3; int al4; }


original_code:
static BreanchNode* insert_node(BreanchNode* t, void* val)
{
    if (!t) {
 t=((BreanchNode*) calloc(1,leafsize));
 t->kind=0;
 memcpy((&(((LeafNode*)t)->val)),val, leafsize-(sizeof(LeafNode)-sizeof(DummyAlign)));
 lastleaf=t;
 dchange=1;
    } else if (t->kind==1) {
 if ((*cmp_leaf)(val, t->val) < 0) {
     t->left = insert_node(t->left, val);
     if (dchange) {
  t->bal=t->bal-1;
  dchange= (t->bal == -1);
  if (t->bal < -1) t=rotate(t);
     }
 } else {
     t->right = insert_node(t->right, val);
     if (dchange) {
  t->bal=t->bal+1;
  dchange = (t->bal == 1);
  if (t->bal > 1) t=rotate(t);
     }
 }
    } else {
 int cmpres=(*cmp_leaf)((&(((LeafNode*)t)->val)),val);
 if (!cmpres) {
     lastleaf=t;
     dchange=0;
 } else {
     BreanchNode* l = ((BreanchNode*) calloc(1,leafsize));
     BreanchNode* b = ((BreanchNode*) malloc(sizeof(BreanchNode)));
     l->kind=0;
     b->kind=1;
     b->bal=0;
     lastleaf=l;
     dchange=1;
     memcpy((&(((LeafNode*)l)->val)),val, leafsize-(sizeof(LeafNode)-sizeof(DummyAlign)));
     if (cmpres<0) {
  b->left=t;
  b->right=l;
  b->val=(&(((LeafNode*)l)->val));
     } else {
  b->left=l;
  b->right=t;
  b->val=(&(((LeafNode*)t)->val));
     }
     t=b;
 }
    }
    return t;
}

canonical_original_code:
static struct bnode *insert_node(struct bnode *t, void *val)
{
    if (!t) {
 t=((struct bnode *) calloc(1,leafsize));
 t->kind=0;
 memcpy((&(((struct lnode *)t)->val)),val, leafsize-(sizeof(LeafNode)-sizeof(DummyAlign)));
 lastleaf=t;
 dchange=1;
    } else if (t->kind==1) {
 if ((*cmp_leaf)(val, t->val) < 0) {
     t->left = insert_node(t->left, val);
     if (dchange) {
  t->bal=t->bal-1;
  dchange= (t->bal == -1);
  if (t->bal < -1) t=rotate(t);
     }
 } else {
     t->right = insert_node(t->right, val);
     if (dchange) {
  t->bal=t->bal+1;
  dchange = (t->bal == 1);
  if (t->bal > 1) t=rotate(t);
     }
 }
    } else {
 int cmpres = (*cmp_leaf)((&(((LeafNode*)t)->val)),val);
 if (!cmpres) {
     lastleaf=t;
     dchange=0;
 } else {
     struct bnode *l = ((BreanchNode*) calloc(1,leafsize));
     struct bnode *b = ((BreanchNode*) malloc(sizeof(BreanchNode)));
     l->kind=0;
     b->kind=1;
     b->bal=0;
     lastleaf=l;
     dchange=1;
     memcpy((&(((struct lnode *)l)->val)),val, leafsize-(sizeof(LeafNode)-sizeof(DummyAlign)));
     if (cmpres<0) {
  b->left=t;
  b->right=l;
  b->val=(&(((struct lnode *)l)->val));
     } else {
  b->left=l;
  b->right=t;
  b->val=(&(((struct lnode *)t)->val));
     }
     t=b;
 }
    }
    return t;
}


decompiled_code:
__int64 __fastcall add_breanchnode(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( !a2 )
return a1;
v2 = a2;
while ( *(_BYTE *)v2 == 1 )
{
result = add_breanchnode(a1, *(_QWORD *)(v2 + 16));
v2 = *(_QWORD *)(v2 + 24);
a1 = result;
if ( !v2 )
return result;
}
return insert_node(a1, *(const void **)(v2 + 8));
}

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

if ( !a2 )
return a1;
v2 = a2;
while ( *(_BYTE *)v2 == 1 )
{
result = func6(a1, *(_QWORD *)(v2 + 16));
v2 = *(_QWORD *)(v2 + 24);
a1 = result;
if ( !v2 )
return result;
}
return func5(a1, *(const void **)(v2 + 8));
}

original_code:
static BreanchNode *add_breanchnode(BreanchNode *lt, BreanchNode *ltadd)
{
    if (!ltadd) return lt;
    if (ltadd->kind==1) {
 lt = add_breanchnode(lt, ltadd->left);
 return add_breanchnode(lt, ltadd->right);
    } else
 return insert_node(lt, ltadd->val);
}

canonical_original_code:
static struct bnode *add_breanchnode(struct bnode *lt, struct bnode *ltadd)
{
    if (!ltadd) return lt;
    if (ltadd->kind==1) {
 lt = add_breanchnode(lt, ltadd->left);
 return add_breanchnode(lt, ltadd->right);
    } else
 return insert_node(lt, ltadd->val);
}

variable_types:
lt
struct bnode *

variable_types:
ltadd
struct bnode *


decompiled_code:
__int64 LT_found_leaf()
{
return lastleaf + 8;
}

canonical_decompiled_code:
__int64 func9()
{
return lastleaf + 8;
}

original_code:
void* LT_found_leaf(void)
{
    return (void*) (&(((LeafNode*)lastleaf)->val));
}

canonical_original_code:
void *LT_found_leaf()
{
    return (void *) (&(((struct lnode *)lastleaf)->val));
}

return_type: void *