decompiled_code:
__int64 __fastcall find_scrollto(_QWORD *a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // eax

if ( finddrawwin == *a1 )
{
v3 = scrollbar_line(scrollfind, 0LL);
result = editwindow_line(find_info, v3);
}
else
{
v1 = scrollbar_line(scrollrep, 0LL);
result = editwindow_line(rep_info, v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // eax

if ( finddrawwin == *a1 )
{
v3 = scrollbar_line(scrollfind, 0LL);
result = editwindow_line(find_info, v3);
}
else
{
v1 = scrollbar_line(scrollrep, 0LL);
result = editwindow_line(rep_info, v1);
}
return result;
}

original_code:
static void find_scrollto(void *data, int kind __attribute__((unused)))
{
    Window win = *((Window*) data);
    if (win == finddrawwin) {
 int line_nr = scrollbar_line(scrollfind, 0);
 editwindow_line(find_info, line_nr);
    } else {
 int line_nr = scrollbar_line(scrollrep, 0);
 editwindow_line(rep_info, line_nr);
    }
}

canonical_original_code:
static void find_scrollto(void *data, int kind)
{
    unsigned long win = *((Window*) data);
    if (win == finddrawwin) {
 int line_nr = scrollbar_line(scrollfind, 0);
 editwindow_line(find_info, line_nr);
    } else {
 int line_nr = scrollbar_line(scrollrep, 0);
 editwindow_line(rep_info, line_nr);
    }
}

variable_types: kind int


repo: jff/mathspad

decompiled_code:
int find_init()
{
int result; // eax
__int64 v1; // rax
__int64 v2; // rax

win_width = display_width >> 1;
win_height = display_height / 3u;
if ( !XStringListToTextProperty(&findname, 1, &find_name) )
{
v1 = translate("Can't set the name for the find.");
message(999LL, v1);
}
result = XStringListToTextProperty(&iconname, 1, &icon_name);
if ( !result )
{
v2 = translate("Can't set iconname for the find.");
result = message(999LL, v2);
}
return result;
}

canonical_decompiled_code:
int func15()
{
int result; // eax
__int64 v1; // rax
__int64 v2; // rax

win_width = display_width >> 1;
win_height = display_height / 3u;
if ( !XStringListToTextProperty(&findname, 1, &find_name) )
{
v1 = translate("Can't set the name for the find.");
message(999LL, v1);
}
result = XStringListToTextProperty(&iconname, 1, &icon_name);
if ( !result )
{
v2 = translate("Can't set iconname for the find.");
result = message(999LL, v2);
}
return result;
}

original_code:
void find_init(void)
{
    win_width = display_width/2;
    win_height= display_height/3;
    if (!XStringListToTextProperty(&findname, 1, &find_name))
 message(1000 -1,translate("Can't set the name for the find."));
    if (!XStringListToTextProperty(&iconname, 1, &icon_name))
 message(1000 -1, translate("Can't set iconname for the find."));
}

canonical_original_code:
void find_init()
{
    win_width = display_width/2;
    win_height= display_height/3;
    if (!XStringListToTextProperty(&findname, 1, &find_name))
 message(1000 -1,translate("Can't set the name for the find."));
    if (!XStringListToTextProperty(&iconname, 1, &icon_name))
 message(1000 -1, translate("Can't set iconname for the find."));
}

return_type: void


decompiled_code:
__int64 find_close()
{
XDestroyWindow(display, findwin);
return find_bad_end(0LL);
}

canonical_decompiled_code:
__int64 func17()
{
XDestroyWindow(display, findwin);
return func13(0LL);
}

original_code:
void find_close(void)
{
    XDestroyWindow(display, findwin);
    find_bad_end(((void *)0));
}

canonical_original_code:
void find_close()
{
    XDestroyWindow(display, findwin);
    find_bad_end(((void *)0));
}


decompiled_code:
void __fastcall find_handle_button(__int64 a1, int a2)
{
char *v2; // rdi
_QWORD *v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

if ( a2 <= 1 )
{
if ( a2 >= 0 )
{
v2 = menuname[a2];
v3 = (_QWORD *)((char *)&menufind + 96 * a2);
if ( mouse_button == 3 )
{
*v3 = findwin;
v5 = translate(v2);
v3[11] = popup_define(v5);
popup_make((char *)&menufind + 96 * a2);
}
else
{
v4 = translate(v2);
v3[11] = popup_define(v4);
popup_call_default((char *)&menufind + 96 * a2);
}
}
}
else if ( a2 == 2 && find_is_open && !remark_is_open )
{
find_close();
}
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1, int a2)
{
char *v2; // rdi
_QWORD *v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

if ( a2 <= 1 )
{
if ( a2 >= 0 )
{
v2 = menuname[a2];
v3 = (_QWORD *)((char *)&menufind + 96 * a2);
if ( mouse_button == 3 )
{
*v3 = findwin;
v5 = translate(v2);
v3[11] = popup_define(v5);
popup_make((char *)&menufind + 96 * a2);
}
else
{
v4 = translate(v2);
v3[11] = popup_define(v4);
popup_call_default((char *)&menufind + 96 * a2);
}
}
}
else if ( a2 == 2 && find_is_open && !remark_is_open )
{
func17();
}
}

original_code:
static void find_handle_button(void *data __attribute__((unused)), int b_num)
{
    int ph_match = 1;
    switch (b_num) {
    case FINDBUTTON:
    case STACKBUTTON:
 if (mouse_button == 3) {
     menufind[b_num].parentwin=findwin;
     menufind[b_num].menu=popup_define(translate(menuname[b_num]));
     popup_make(&menufind[b_num]);
 } else {
     menufind[b_num].menu=popup_define(translate(menuname[b_num]));
     popup_call_default(menufind+b_num);
 }
 break;
      case DONEBUTTON:
 if ((find_is_open && !remark_is_open)) find_close();
 break;
    }
    if (!ph_match)
 message(1, translate("Place holders don't match."));
}

canonical_original_code:
static void find_handle_button(void *data, int b_num)
{
    int ph_match = 1;
    switch (b_num) {
    case FINDBUTTON:
    case STACKBUTTON:
 if (mouse_button == 3) {
     menufind[b_num].parentwin=findwin;
     menufind[b_num].menu=popup_define(translate(menuname[b_num]));
     popup_make(&menufind[b_num]);
 } else {
     menufind[b_num].menu=popup_define(translate(menuname[b_num]));
     popup_call_default(menufind+b_num);
 }
 break;
      case DONEBUTTON:
 if ((find_is_open && !remark_is_open)) find_close();
 break;
    }
    if (!ph_match)
 message(1, translate("Place holders don't match."));
}

variable_types:
data
void *


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

result = *a1;
if ( *a1 == finddrawwin )
{
dbl_click();
result = get_motion_hints(finddrawwin, 0LL);
}
else if ( result == repdrawwin )
{
dbl_click();
result = get_motion_hints(repdrawwin, 0LL);
}
return result;
}

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

result = *a1;
if ( *a1 == finddrawwin )
{
dbl_click();
result = get_motion_hints(finddrawwin, 0LL);
}
else if ( result == repdrawwin )
{
dbl_click();
result = get_motion_hints(repdrawwin, 0LL);
}
return result;
}

original_code:
static void double_click_func(void *data)
{
    if (*((Window*) data)== finddrawwin) {
 dbl_click();
 get_motion_hints(finddrawwin,0);
    } else if (*((Window*) data) == repdrawwin) {
 dbl_click();
 get_motion_hints(repdrawwin,0);
    }
}

canonical_original_code:
static void double_click_func(void *data)
{
    if (*((unsigned long *) data)== finddrawwin) {
 dbl_click();
 get_motion_hints(finddrawwin,0);
    } else if (*((unsigned long *) data) == repdrawwin) {
 dbl_click();
 get_motion_hints(repdrawwin,0);
    }
}


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

if ( menu_is_open )
{
result = menu_iconized;
if ( !menu_iconized )
return result;
}
if ( notation_is_open )
{
result = notation_iconized;
if ( !notation_iconized )
return result;
if ( !notadef_is_open )
goto LABEL_5;
LABEL_16:
result = notadef_iconized;
if ( !notadef_iconized )
return result;
goto LABEL_5;
}
if ( notadef_is_open )
goto LABEL_16;
LABEL_5:
if ( !buffer_is_open || (result = buffer_iconized, buffer_iconized) )
{
if ( !find_is_open || (result = find_iconized, find_iconized) )
{
if ( !default_is_open || (result = default_iconized, default_iconized) )
{
if ( !symbol_is_open || (result = symbol_iconized, symbol_iconized) )
{
result = 1LL;
if ( edit_is_open )
result = edit_iconized != 0;
}
}
}
}
return result;
}

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

if ( menu_is_open )
{
result = menu_iconized;
if ( !menu_iconized )
return result;
}
if ( notation_is_open )
{
result = notation_iconized;
if ( !notation_iconized )
return result;
if ( !notadef_is_open )
goto LABEL_5;
LABEL_16:
result = notadef_iconized;
if ( !notadef_iconized )
return result;
goto LABEL_5;
}
if ( notadef_is_open )
goto LABEL_16;
LABEL_5:
if ( !buffer_is_open || (result = buffer_iconized, buffer_iconized) )
{
if ( !find_is_open || (result = find_iconized, find_iconized) )
{
if ( !default_is_open || (result = default_iconized, default_iconized) )
{
if ( !symbol_is_open || (result = symbol_iconized, symbol_iconized) )
{
result = 1LL;
if ( edit_is_open )
result = edit_iconized != 0;
}
}
}
}
return result;
}

original_code:
static int all_iconized(void)
{
    return ((!menu_is_open || menu_iconized) &&
     (!notation_is_open || notation_iconized) &&
     (!notadef_is_open || notadef_iconized) &&
     (!buffer_is_open || buffer_iconized) &&
     (!find_is_open || find_iconized) &&
     (!default_is_open || default_iconized) &&
     (!symbol_is_open || symbol_iconized) &&
     (!edit_is_open || edit_iconized)) ;
}

canonical_original_code:
static int all_iconized()
{
    return ((!menu_is_open || menu_iconized) &&
     (!notation_is_open || notation_iconized) &&
     (!notadef_is_open || notadef_iconized) &&
     (!buffer_is_open || buffer_iconized) &&
     (!find_is_open || find_iconized) &&
     (!default_is_open || default_iconized) &&
     (!symbol_is_open || symbol_iconized) &&
     (!edit_is_open || edit_iconized)) ;
}

return_type: int


decompiled_code:
__int64 __fastcall do_motion_notify(unsigned int a1, unsigned int a2)
{
int v2; // er8
__int64 result; // rax
__int64 v4; // rax
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a1;
v5 = a2;
if ( when_motion_window && when_motion_window != motion_window )
{
motion_window = when_motion_window;
when_motion_window = 0LL;
goto LABEL_4;
}
LODWORD(result) = v6[0];
when_motion_window = 0LL;
if ( (v6[0] & v5) == -1 )
{
LABEL_4:
v2 = motion_get_pos(v6, &v5);
result = v6[0];
if ( !v2 )
return result;
}
if ( mouse_old_x != (_DWORD)result || (result = v5, mouse_old_y != v5) )
{
set_info(motion_window);
is_click = 0;
v4 = *((_QWORD *)&eventfunc + (unsigned int)wt);
mouse_old_x = v6[0];
mouse_old_y = v5;
result = *(_QWORD *)(v4 + 40);
if ( result && (!remark_is_open || wt == 14 || pwt == 14) )
result = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD))result)(data, v6[0], v5, (unsigned int)wt);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
int v2; // er8
__int64 result; // rax
__int64 v4; // rax
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a1;
v5 = a2;
if ( when_motion_window && when_motion_window != motion_window )
{
motion_window = when_motion_window;
when_motion_window = 0LL;
goto LABEL_4;
}
LODWORD(result) = v6[0];
when_motion_window = 0LL;
if ( (v6[0] & v5) == -1 )
{
LABEL_4:
v2 = motion_get_pos(v6, &v5);
result = v6[0];
if ( !v2 )
return result;
}
if ( mouse_old_x != (_DWORD)result || (result = v5, mouse_old_y != v5) )
{
func1(motion_window);
is_click = 0;
v4 = *((_QWORD *)&eventfunc + (unsigned int)wt);
mouse_old_x = v6[0];
mouse_old_y = v5;
result = *(_QWORD *)(v4 + 40);
if ( result && (!remark_is_open || wt == 14 || pwt == 14) )
result = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD))result)(data, v6[0], v5, (unsigned int)wt);
}
return result;
}

original_code:
static void do_motion_notify(int x, int y)
{
    int get_pos = (x==-1 && y==-1);
    if (when_motion_window && when_motion_window != motion_window) {
 motion_window=when_motion_window;
 get_pos = 1;
    }
    when_motion_window = 0;
    if (get_pos)
 if (!motion_get_pos(&x,&y)) return;
    if ((mouse_old_x == x && mouse_old_y == y)) return;
    set_info(motion_window);
    mouse_old_x=x;
    mouse_old_y=y;
    is_click = 0;
    if (eventfunc[wt]->motion)
 if (!remark_is_open || wt==REMARKWINDOW || pwt==REMARKWINDOW)
     (*(eventfunc[wt]->motion))(data, x, y);
}

variable_types: x int

variable_types: y int


decompiled_code:
void get_events()
{
Time v0; // rbx
void (__fastcall *v1)(__int64); // rax
__int64 v2; // rax
void (__fastcall *v3)(__int64, XEvent *); // rax
void *v4; // rdi
void (__fastcall *v5)(__int64, XEvent *); // rax
void (__fastcall *v6)(__int64); // rax
void (__fastcall *v7)(__int64); // rax
__int64 v8; // rax
__int64 v9; // rax
_BOOL4 v10; // edx
void (__fastcall *v11)(__int64); // rdx
char *v12; // rax
char *v13; // rdi
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rbp
__int64 v17; // rax
unsigned int v18; // [rsp+8h] [rbp-70h] BYREF
unsigned int v19; // [rsp+Ch] [rbp-6Ch] BYREF
char v20[4]; // [rsp+10h] [rbp-68h] BYREF
char v21[4]; // [rsp+14h] [rbp-64h] BYREF
int v22; // [rsp+18h] [rbp-60h] BYREF
int v23; // [rsp+1Ch] [rbp-5Ch] BYREF
unsigned __int64 v24; // [rsp+20h] [rbp-58h] BYREF
unsigned __int64 v25; // [rsp+28h] [rbp-50h] BYREF
Atom v26; // [rsp+30h] [rbp-48h] BYREF
unsigned __int8 *v27[8]; // [rsp+38h] [rbp-40h] BYREF

v0 = 0LL;
while ( 1 )
{
XEventsQueued(display, 2);
XNextEvent(display, &report);
set_info(report.pad[4]);
convert_event(&report, v20, v21);
can_auto_save = 0;
switch ( report.type )
{
case 2:
v0 = report.xkey.time;
last_time = report.xkey.time;
do_key_press_constprop_0();
goto LABEL_8;
case 4:
if ( !(unsigned int)mouse_press(report.xkey.state, report.xkey.keycode) )
goto LABEL_66;
v10 = 0;
press_time = report.xkey.time;
if ( report.xany.window == first_click )
v10 = report.xkey.time - release_time < wait_time;
double_click = v10;
mouse_old_y = report.xkey.y;
mouse_old_x = report.xkey.x;
push_keymap(0LL);
if ( double_click
&& (v11 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 144LL)) != 0LL )
{
if ( !remark_is_open )
{
v11(data);
goto LABEL_8;
}
if ( (unsigned int)remark_removable() )
goto LABEL_91;
if ( wt != 14 )
{
if ( pwt != 14 )
goto LABEL_8;
LABEL_91:
(*(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 144LL))(data);
goto LABEL_8;
}
(*(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + 14) + 144LL))(data);
}
else
{
v14 = *((_QWORD *)&eventfunc + (unsigned int)wt);
double_click = 0;
v5 = *(void (__fastcall **)(__int64, XEvent *))(v14 + 24);
first_click = report.pad[4];
if ( !v5 )
goto LABEL_8;
if ( !remark_is_open )
{
LABEL_33:
v5(data, &report);
goto LABEL_8;
}
if ( (unsigned int)remark_removable() )
{
LABEL_74:
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 24LL))(
data,
&report);
goto LABEL_8;
}
if ( wt == 14 )
{
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + 14) + 24LL))(data, &report);
}
else
{
if ( pwt == 14 )
goto LABEL_74;
v17 = translate("Please handle the popup first. (It should be visible by now)");
message(0LL, v17);
}
}
LABEL_8:
can_auto_save = 1;
call_auto_save(v0);
break;
case 5:
if ( (unsigned int)mouse_release(report.xkey.state, report.xkey.keycode) )
{
v0 = report.xkey.time;
last_time = report.xkey.time;
release_time = report.xkey.time;
if ( motion_window )
set_info(motion_window);
pop_keymap();
v3 = *(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 32LL);
if ( !v3 )
goto LABEL_20;
if ( remark_is_open )
{
if ( (unsigned int)remark_removable() )
goto LABEL_79;
if ( wt == 14 )
{
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + 14) + 32LL))(data, &report);
goto LABEL_20;
}
if ( pwt == 14 )
LABEL_79:
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 32LL))(
data,
&report);
else
remark_raise();
}
else
{
v3(data, &report);
}
LABEL_20:
when_motion_window = 0LL;
goto LABEL_8;
}
LABEL_66:
do_motion_notify(0xFFFFFFFF, 0xFFFFFFFF);
goto LABEL_8;
case 6:
while ( XCheckMaskEvent(display, 0x2000LL, &report) )
;
if ( when_motion_window && when_motion_window != motion_window )
motion_window = when_motion_window;
when_motion_window = 0LL;
if ( (unsigned int)motion_get_pos(&v18, &v19) && (unsigned int)is_drag(report.xkey.time) )
do_motion_notify(v18, v19);
goto LABEL_8;
case 7:
v0 = report.xkey.time;
v9 = *((_QWORD *)&eventfunc + (unsigned int)wt);
last_time = report.xkey.time;
v1 = *(void (__fastcall **)(__int64))(v9 + 72);
if ( !v1 )
goto LABEL_8;
goto LABEL_11;
case 8:
v0 = report.xkey.time;
v8 = *((_QWORD *)&eventfunc + (unsigned int)wt);
last_time = report.xkey.time;
v1 = *(void (__fastcall **)(__int64))(v8 + 64);
if ( !v1 )
goto LABEL_8;
goto LABEL_11;
case 9:
if ( window_keyboard(report.xany.window) )
{
v2 = window_keyboard(report.xany.window);
set_keyboard_stack(v2);
}
goto LABEL_8;
case 0xC:
case 0xD:
if ( !report.xexpose.count )
{
v1 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 8LL);
if ( v1 )
goto LABEL_11;
}
goto LABEL_8;
case 0xF:
change_visibility(report.xany.window, report.xcookie.cookie);
goto LABEL_8;
case 0x11:
destroy_window(report.xany.window);
goto LABEL_8;
case 0x12:
change_mapped(report.xany.window, 0LL);
v7 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 48LL);
if ( v7 )
v7(data);
if ( remark_is_open && (unsigned int)all_iconized() )
remark_unmap();
goto LABEL_8;
case 0x13:
change_mapped(report.xany.window, 1LL);
v6 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 56LL);
if ( v6 )
{
v6(data);
if ( remark_is_open )
remark_raise();
}
goto LABEL_8;
case 0x16:
v5 = *(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 16LL);
if ( !v5 )
goto LABEL_8;
goto LABEL_33;
case 0x1C:
v5 = *(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 152LL);
if ( v5 )
goto LABEL_33;
goto LABEL_8;
case 0x1E:
send_selection(&report);
goto LABEL_8;
case 0x1F:
if ( report.xkey.time )
{
v25 = 0LL;
XGetWindowProperty(
display,
report.xany.window,
report.xkey.time,
0LL,
3000LL,
0,
0LL,
&v26,
&v22,
&v24,
&v25,
v27);
v0 = report.xselectionrequest.property;
last_time = report.xselectionrequest.property;
if ( v27[0] && v24 )
{
v16 = 0LL;
while ( v25 )
{
v16 += 3000LL;
wmselection = v27[0];
handle_key(80LL, 5832793LL);
XGetWindowProperty(
display,
report.xany.window,
report.xkey.time,
v16,
3000LL,
0,
0LL,
&v26,
&v22,
&v24,
&v25,
v27);
}
wmselection = v27[0];
if ( v24 && v27[0] )
handle_key(80LL, 5832793LL);
}
else
{
wmselection = XFetchBytes(display, &v23);
v4 = wmselection;
v24 = v23;
if ( v23 )
{
if ( wmselection )
handle_key(80LL, 5832793LL);
v4 = wmselection;
}
if ( v4 )
XFree(v4);
}
wmselection = 0LL;
XDeleteProperty(display, report.xany.window, report.xkey.time);
}
else
{
v12 = XFetchBytes(display, (int *)v27);
wmselection = v12;
v13 = v12;
if ( LODWORD(v27[0]) && v12 )
{
handle_key(80LL, 5832793LL);
v13 = (char *)wmselection;
}
XFree(v13);
wmselection = 0LL;
}
goto LABEL_8;
case 0x21:
if ( WM_SAVE_YOURSELF == report.xkey.time )
{
v15 = translate(".mpproject");
save_project(v15);
menu_set_command();
}
else if ( WM_DELETE_WINDOW == report.xkey.time )
{
XDestroyWindow(display, report.xany.window);
v1 = (void (__fastcall *)(__int64))**((_QWORD **)&eventfunc + (unsigned int)wt);
if ( v1 )
LABEL_11:
v1(data);
}
goto LABEL_8;
case 0x22:
if ( report.xfocus.mode == 1 )
XRefreshKeyboardMapping((XMappingEvent *)&report);
goto LABEL_8;
default:
goto LABEL_8;
}
}
}

canonical_decompiled_code:
void func5()
{
Time v0; // rbx
void (__fastcall *v1)(__int64); // rax
__int64 v2; // rax
void (__fastcall *v3)(__int64, XEvent *); // rax
void *v4; // rdi
void (__fastcall *v5)(__int64, XEvent *); // rax
void (__fastcall *v6)(__int64); // rax
void (__fastcall *v7)(__int64); // rax
__int64 v8; // rax
__int64 v9; // rax
_BOOL4 v10; // edx
void (__fastcall *v11)(__int64); // rdx
char *v12; // rax
char *v13; // rdi
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rbp
__int64 v17; // rax
unsigned int v18; // [rsp+8h] [rbp-70h] BYREF
unsigned int v19; // [rsp+Ch] [rbp-6Ch] BYREF
char v20[4]; // [rsp+10h] [rbp-68h] BYREF
char v21[4]; // [rsp+14h] [rbp-64h] BYREF
int v22; // [rsp+18h] [rbp-60h] BYREF
int v23; // [rsp+1Ch] [rbp-5Ch] BYREF
unsigned __int64 v24; // [rsp+20h] [rbp-58h] BYREF
unsigned __int64 v25; // [rsp+28h] [rbp-50h] BYREF
Atom v26; // [rsp+30h] [rbp-48h] BYREF
unsigned __int8 *v27[8]; // [rsp+38h] [rbp-40h] BYREF

v0 = 0LL;
while ( 1 )
{
XEventsQueued(display, 2);
XNextEvent(display, &report);
func1(report.pad[4]);
convert_event(&report, v20, v21);
can_auto_save = 0;
switch ( report.type )
{
case 2:
v0 = report.xkey.time;
last_time = report.xkey.time;
func3();
goto LABEL_8;
case 4:
if ( !(unsigned int)mouse_press(report.xkey.state, report.xkey.keycode) )
goto LABEL_66;
v10 = 0;
press_time = report.xkey.time;
if ( report.xany.window == first_click )
v10 = report.xkey.time - release_time < wait_time;
double_click = v10;
mouse_old_y = report.xkey.y;
mouse_old_x = report.xkey.x;
push_keymap(0LL);
if ( double_click
&& (v11 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 144LL)) != 0LL )
{
if ( !remark_is_open )
{
v11(data);
goto LABEL_8;
}
if ( (unsigned int)remark_removable() )
goto LABEL_91;
if ( wt != 14 )
{
if ( pwt != 14 )
goto LABEL_8;
LABEL_91:
(*(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 144LL))(data);
goto LABEL_8;
}
(*(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + 14) + 144LL))(data);
}
else
{
v14 = *((_QWORD *)&eventfunc + (unsigned int)wt);
double_click = 0;
v5 = *(void (__fastcall **)(__int64, XEvent *))(v14 + 24);
first_click = report.pad[4];
if ( !v5 )
goto LABEL_8;
if ( !remark_is_open )
{
LABEL_33:
v5(data, &report);
goto LABEL_8;
}
if ( (unsigned int)remark_removable() )
{
LABEL_74:
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 24LL))(
data,
&report);
goto LABEL_8;
}
if ( wt == 14 )
{
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + 14) + 24LL))(data, &report);
}
else
{
if ( pwt == 14 )
goto LABEL_74;
v17 = translate("Please handle the popup first. (It should be visible by now)");
message(0LL, v17);
}
}
LABEL_8:
can_auto_save = 1;
call_auto_save(v0);
break;
case 5:
if ( (unsigned int)mouse_release(report.xkey.state, report.xkey.keycode) )
{
v0 = report.xkey.time;
last_time = report.xkey.time;
release_time = report.xkey.time;
if ( motion_window )
func1(motion_window);
pop_keymap();
v3 = *(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 32LL);
if ( !v3 )
goto LABEL_20;
if ( remark_is_open )
{
if ( (unsigned int)remark_removable() )
goto LABEL_79;
if ( wt == 14 )
{
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + 14) + 32LL))(data, &report);
goto LABEL_20;
}
if ( pwt == 14 )
LABEL_79:
(*(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 32LL))(
data,
&report);
else
remark_raise();
}
else
{
v3(data, &report);
}
LABEL_20:
when_motion_window = 0LL;
goto LABEL_8;
}
LABEL_66:
func2(0xFFFFFFFF, 0xFFFFFFFF);
goto LABEL_8;
case 6:
while ( XCheckMaskEvent(display, 0x2000LL, &report) )
;
if ( when_motion_window && when_motion_window != motion_window )
motion_window = when_motion_window;
when_motion_window = 0LL;
if ( (unsigned int)motion_get_pos(&v18, &v19) && (unsigned int)is_drag(report.xkey.time) )
func2(v18, v19);
goto LABEL_8;
case 7:
v0 = report.xkey.time;
v9 = *((_QWORD *)&eventfunc + (unsigned int)wt);
last_time = report.xkey.time;
v1 = *(void (__fastcall **)(__int64))(v9 + 72);
if ( !v1 )
goto LABEL_8;
goto LABEL_11;
case 8:
v0 = report.xkey.time;
v8 = *((_QWORD *)&eventfunc + (unsigned int)wt);
last_time = report.xkey.time;
v1 = *(void (__fastcall **)(__int64))(v8 + 64);
if ( !v1 )
goto LABEL_8;
goto LABEL_11;
case 9:
if ( window_keyboard(report.xany.window) )
{
v2 = window_keyboard(report.xany.window);
set_keyboard_stack(v2);
}
goto LABEL_8;
case 0xC:
case 0xD:
if ( !report.xexpose.count )
{
v1 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 8LL);
if ( v1 )
goto LABEL_11;
}
goto LABEL_8;
case 0xF:
change_visibility(report.xany.window, report.xcookie.cookie);
goto LABEL_8;
case 0x11:
destroy_window(report.xany.window);
goto LABEL_8;
case 0x12:
change_mapped(report.xany.window, 0LL);
v7 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 48LL);
if ( v7 )
v7(data);
if ( remark_is_open && (unsigned int)func0() )
remark_unmap();
goto LABEL_8;
case 0x13:
change_mapped(report.xany.window, 1LL);
v6 = *(void (__fastcall **)(__int64))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 56LL);
if ( v6 )
{
v6(data);
if ( remark_is_open )
remark_raise();
}
goto LABEL_8;
case 0x16:
v5 = *(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 16LL);
if ( !v5 )
goto LABEL_8;
goto LABEL_33;
case 0x1C:
v5 = *(void (__fastcall **)(__int64, XEvent *))(*((_QWORD *)&eventfunc + (unsigned int)wt) + 152LL);
if ( v5 )
goto LABEL_33;
goto LABEL_8;
case 0x1E:
send_selection(&report);
goto LABEL_8;
case 0x1F:
if ( report.xkey.time )
{
v25 = 0LL;
XGetWindowProperty(
display,
report.xany.window,
report.xkey.time,
0LL,
3000LL,
0,
0LL,
&v26,
&v22,
&v24,
&v25,
v27);
v0 = report.xselectionrequest.property;
last_time = report.xselectionrequest.property;
if ( v27[0] && v24 )
{
v16 = 0LL;
while ( v25 )
{
v16 += 3000LL;
wmselection = v27[0];
handle_key(80LL, 5832793LL);
XGetWindowProperty(
display,
report.xany.window,
report.xkey.time,
v16,
3000LL,
0,
0LL,
&v26,
&v22,
&v24,
&v25,
v27);
}
wmselection = v27[0];
if ( v24 && v27[0] )
handle_key(80LL, 5832793LL);
}
else
{
wmselection = XFetchBytes(display, &v23);
v4 = wmselection;
v24 = v23;
if ( v23 )
{
if ( wmselection )
handle_key(80LL, 5832793LL);
v4 = wmselection;
}
if ( v4 )
XFree(v4);
}
wmselection = 0LL;
XDeleteProperty(display, report.xany.window, report.xkey.time);
}
else
{
v12 = XFetchBytes(display, (int *)v27);
wmselection = v12;
v13 = v12;
if ( LODWORD(v27[0]) && v12 )
{
handle_key(80LL, 5832793LL);
v13 = (char *)wmselection;
}
XFree(v13);
wmselection = 0LL;
}
goto LABEL_8;
case 0x21:
if ( WM_SAVE_YOURSELF == report.xkey.time )
{
v15 = translate(".mpproject");
save_project(v15);
menu_set_command();
}
else if ( WM_DELETE_WINDOW == report.xkey.time )
{
XDestroyWindow(display, report.xany.window);
v1 = (void (__fastcall *)(__int64))**((_QWORD **)&eventfunc + (unsigned int)wt);
if ( v1 )
LABEL_11:
v1(data);
}
goto LABEL_8;
case 0x22:
if ( report.xfocus.mode == 1 )
XRefreshKeyboardMapping((XMappingEvent *)&report);
goto LABEL_8;
default:
goto LABEL_8;
}
}
}

original_code:
void get_events(void)
{
    Atom matom;
    int x,y;
    unsigned long auto_save = 0;
    KeyNum keynum;
    KeyMode keymode;
    char buffer[5000];
    while (1) {
 (void) XEventsQueued(display, 2);
 XNextEvent(display, &report);
 set_info(report.xany.window);
 if (convert_event((void*)(&report), &keynum, &keymode)) {
 }
 can_auto_save = 0;
 switch (report.type) {
 case 13:
 case 12:
     if (!report.xexpose.count && eventfunc[wt]->draw)
         (*(eventfunc[wt]->draw))(data);
     break;
 case 6:
     while (XCheckMaskEvent(display, (1L<<13), &report));
     if (when_motion_window && when_motion_window != motion_window) {
  motion_window=when_motion_window;
     }
     when_motion_window = 0;
     if (motion_get_pos(&x,&y) && is_drag(report.xmotion.time))
  do_motion_notify(x,y);
     break;
 case 22:
     if (eventfunc[wt]->configure)
  (*(eventfunc[wt]->configure))(data, &report.xconfigure);
     break;
 case 7:
     auto_save = last_time = report.xcrossing.time;
     if (eventfunc[wt]->enter) (*(eventfunc[wt]->enter))(data);
     break;
 case 8:
     auto_save = last_time = report.xcrossing.time;
     if (eventfunc[wt]->leave) (*(eventfunc[wt]->leave))(data);
     break;
 case 4:
     if (mouse_press(report.xbutton.state, report.xbutton.button)) {
  press_time = report.xbutton.time;
  double_click = (first_click==report.xany.window) &&
                 (press_time-release_time)<(unsigned int)wait_time;
  mouse_old_x = report.xbutton.x;
  mouse_old_y = report.xbutton.y;
  push_keymap(0);
  if (double_click && eventfunc[wt]->dbl_click) {
    if (!remark_is_open || remark_removable() ||
        wt==REMARKWINDOW || pwt==REMARKWINDOW)
      (*(eventfunc[wt]->dbl_click))(data);
      } else {
    double_click = 0;
    first_click = report.xany.window;
    if (eventfunc[wt]->press) {
      if (!remark_is_open || remark_removable() ||
   wt==REMARKWINDOW || pwt==REMARKWINDOW)
        (*(eventfunc[wt]->press))(data, &report.xbutton);
      else message(0, translate("Please handle the popup first. "
     "(It should be visible by now)"));
    }
  }
     } else
  do_motion_notify(-1,-1);
     break;
 case 5:
     if (mouse_release(report.xbutton.state, report.xbutton.button)) {
  auto_save = release_time = last_time = report.xbutton.time;
  if (motion_window) set_info(motion_window);
  pop_keymap();
  if (eventfunc[wt]->release) {
      if (!remark_is_open || remark_removable() ||
   wt==REMARKWINDOW || pwt==REMARKWINDOW)
   (*(eventfunc[wt]->release))(data, &report.xbutton);
      else
   remark_raise();
  }
  when_motion_window=0;
     } else
  do_motion_notify(-1,-1);
     break;
 case 28:
     if (eventfunc[wt]->property_change)
  (*eventfunc[wt]->property_change)(data, &report.xproperty);
     break;
 case 17:
     destroy_window(report.xany.window);
     break;
 case 2:
     auto_save = last_time = report.xkey.time;
     do_key_press(&report.xkey);
     break;
 case 9:
   if (window_keyboard(report.xany.window)) {
     set_keyboard_stack(window_keyboard(report.xany.window));
   }
   break;
 case 10:
   break;
 case 34:
     if (report.xmapping.request == 1)
  XRefreshKeyboardMapping(&report.xmapping);
     break;
 case 30:
     send_selection(&report.xselectionrequest);
     break;
 case 31:
     if (report.xselection.property!= 0L) {
  long start=0;
  unsigned long nit, byte_af=0;
  Atom act_type;
  int act_form;
  int l;
  int freeit=0;
  unsigned char *wmdata;
  XGetWindowProperty(display, report.xselection.requestor,
       report.xselection.property, 0, 3000, 0,
       0L, &act_type, &act_form,
       &nit, &byte_af, &wmdata);
  auto_save = last_time = report.xselection.time;
  if (!wmdata || !nit) {
      freeit = 1;
      wmselection = XFetchBytes(display, &l);
      nit = l;
  } else {
      while (byte_af) {
   wmselection = (char*) wmdata;
   handle_key('P',((((((((0)|(((0x01)<<16)|(0x01))))|(((0x08)<<16)|(0x08))))|(((0x10)<<16)|(0x10))))|(((0x40)<<16)|(0x40))));
   start+=3000;
   XGetWindowProperty(display,report.xselection.requestor,
        report.xselection.property, start,
        3000, 0, 0L,
        &act_type, &act_form, &nit,
        &byte_af, &wmdata);
      }
      wmselection = (char*) wmdata;
  }
  if (nit && wmselection)
      handle_key('P',((((((((0)|(((0x01)<<16)|(0x01))))|(((0x08)<<16)|(0x08))))|(((0x10)<<16)|(0x10))))|(((0x40)<<16)|(0x40))));
  if (freeit && wmselection) XFree(wmselection);
  wmselection = ((void *)0);
  XDeleteProperty(display, report.xselection.requestor,
    report.xselection.property);
     } else {
  int l;
  wmselection = XFetchBytes(display, &l);
  if (l && wmselection)
      handle_key('P', ((((((((0)|(((0x01)<<16)|(0x01))))|(((0x08)<<16)|(0x08))))|(((0x10)<<16)|(0x10))))|(((0x40)<<16)|(0x40))));
  XFree(wmselection);
  wmselection = ((void *)0);
     }
     break;
 case 33:
     matom = (Atom) report.xclient.data.l[0];
     if (matom == WM_SAVE_YOURSELF) {
  save_project(translate(".mpproject"));
  menu_set_command();
     } else if (matom == WM_DELETE_WINDOW) {
  XDestroyWindow(display, report.xany.window);
  if (eventfunc[wt]->bad_end) (*(eventfunc[wt]->bad_end))(data);
     }
     break;
 case 15:
     change_visibility(report.xvisibility.window, report.xvisibility.state);
     break;
 case 18:
     change_mapped(report.xany.window, 0);
     if (eventfunc[wt]->iconize) (*(eventfunc[wt]->iconize))(data);
     if (remark_is_open && all_iconized()) remark_unmap();
     break;
 case 19:
     change_mapped(report.xany.window, 1);
     if (eventfunc[wt]->deiconize) {
  (*(eventfunc[wt]->deiconize))(data);
  if (remark_is_open) remark_raise();
     }
     break;
 default:
     break;
 }
 can_auto_save = 1;
        call_auto_save(auto_save);
    }
}

canonical_original_code:
void get_events()
{
    unsigned long matom;
    int x; int y;
    unsigned long auto_save = 0;
    unsigned int keynum;
    unsigned int keymode;
    char buffer[5000];
    while (1) {
 (void) XEventsQueued(display, 2);
 XNextEvent(display, &report);
 set_info(report.xany.window);
 if (convert_event((void *)(&report), &keynum, &keymode)) {
 }
 can_auto_save = 0;
 switch (report.type) {
 case 13:
 case 12:
     if (!report.xexpose.count && eventfunc[wt]->draw)
         (*(eventfunc[wt]->draw))(data);
     break;
 case 6:
     while (XCheckMaskEvent(display, (1L<<13), &report));
     if (when_motion_window && when_motion_window != motion_window) {
  motion_window=when_motion_window;
     }
     when_motion_window = 0;
     if (motion_get_pos(&x,&y) && is_drag(report.xmotion.time))
  do_motion_notify(x,y);
     break;
 case 22:
     if (eventfunc[wt]->configure)
  (*(eventfunc[wt]->configure))(data, &report.xconfigure);
     break;
 case 7:
     auto_save = last_time = report.xcrossing.time;
     if (eventfunc[wt]->enter) (*(eventfunc[wt]->enter))(data);
     break;
 case 8:
     auto_save = last_time = report.xcrossing.time;
     if (eventfunc[wt]->leave) (*(eventfunc[wt]->leave))(data);
     break;
 case 4:
     if (mouse_press(report.xbutton.state, report.xbutton.button)) {
  press_time = report.xbutton.time;
  double_click = (first_click==report.xany.window) &&
                 (press_time-release_time)<(unsigned int)wait_time;
  mouse_old_x = report.xbutton.x;
  mouse_old_y = report.xbutton.y;
  push_keymap(0);
  if (double_click && eventfunc[wt]->dbl_click) {
    if (!remark_is_open || remark_removable() ||
        wt==REMARKWINDOW || pwt==REMARKWINDOW)
      (*(eventfunc[wt]->dbl_click))(data);
      } else {
    double_click = 0;
    first_click = report.xany.window;
    if (eventfunc[wt]->press) {
      if (!remark_is_open || remark_removable() ||
   wt==REMARKWINDOW || pwt==REMARKWINDOW)
        (*(eventfunc[wt]->press))(data, &report.xbutton);
      else message(0, translate("Please handle the popup first. "
     "(It should be visible by now)"));
    }
  }
     } else
  do_motion_notify(-1,-1);
     break;
 case 5:
     if (mouse_release(report.xbutton.state, report.xbutton.button)) {
  auto_save = release_time = last_time = report.xbutton.time;
  if (motion_window) set_info(motion_window);
  pop_keymap();
  if (eventfunc[wt]->release) {
      if (!remark_is_open || remark_removable() ||
   wt==REMARKWINDOW || pwt==REMARKWINDOW)
   (*(eventfunc[wt]->release))(data, &report.xbutton);
      else
   remark_raise();
  }
  when_motion_window=0;
     } else
  do_motion_notify(-1,-1);
     break;
 case 28:
     if (eventfunc[wt]->property_change)
  (*eventfunc[wt]->property_change)(data, &report.xproperty);
     break;
 case 17:
     destroy_window(report.xany.window);
     break;
 case 2:
     auto_save = last_time = report.xkey.time;
     do_key_press(&report.xkey);
     break;
 case 9:
   if (window_keyboard(report.xany.window)) {
     set_keyboard_stack(window_keyboard(report.xany.window));
   }
   break;
 case 10:
   break;
 case 34:
     if (report.xmapping.request == 1)
  XRefreshKeyboardMapping(&report.xmapping);
     break;
 case 30:
     send_selection(&report.xselectionrequest);
     break;
 case 31:
     if (report.xselection.property!= 0L) {
  long start = 0;
  unsigned long nit; unsigned long byte_af = 0;
  unsigned long act_type;
  int act_form;
  int l;
  int freeit = 0;
  unsigned char *wmdata;
  XGetWindowProperty(display, report.xselection.requestor,
       report.xselection.property, 0, 3000, 0,
       0L, &act_type, &act_form,
       &nit, &byte_af, &wmdata);
  auto_save = last_time = report.xselection.time;
  if (!wmdata || !nit) {
      freeit = 1;
      wmselection = XFetchBytes(display, &l);
      nit = l;
  } else {
      while (byte_af) {
   wmselection = (char *) wmdata;
   handle_key('P',((((((((0)|(((0x01)<<16)|(0x01))))|(((0x08)<<16)|(0x08))))|(((0x10)<<16)|(0x10))))|(((0x40)<<16)|(0x40))));
   start+=3000;
   XGetWindowProperty(display,report.xselection.requestor,
        report.xselection.property, start,
        3000, 0, 0L,
        &act_type, &act_form, &nit,
        &byte_af, &wmdata);
      }
      wmselection = (char *) wmdata;
  }
  if (nit && wmselection)
      handle_key('P',((((((((0)|(((0x01)<<16)|(0x01))))|(((0x08)<<16)|(0x08))))|(((0x10)<<16)|(0x10))))|(((0x40)<<16)|(0x40))));
  if (freeit && wmselection) XFree(wmselection);
  wmselection = ((void *)0);
  XDeleteProperty(display, report.xselection.requestor,
    report.xselection.property);
     } else {
  int l;
  wmselection = XFetchBytes(display, &l);
  if (l && wmselection)
      handle_key('P', ((((((((0)|(((0x01)<<16)|(0x01))))|(((0x08)<<16)|(0x08))))|(((0x10)<<16)|(0x10))))|(((0x40)<<16)|(0x40))));
  XFree(wmselection);
  wmselection = ((void *)0);
     }
     break;
 case 33:
     matom = (unsigned long) report.xclient.data.l[0];
     if (matom == WM_SAVE_YOURSELF) {
  save_project(translate(".mpproject"));
  menu_set_command();
     } else if (matom == WM_DELETE_WINDOW) {
  XDestroyWindow(display, report.xany.window);
  if (eventfunc[wt]->bad_end) (*(eventfunc[wt]->bad_end))(data);
     }
     break;
 case 15:
     change_visibility(report.xvisibility.window, report.xvisibility.state);
     break;
 case 18:
     change_mapped(report.xany.window, 0);
     if (eventfunc[wt]->iconize) (*(eventfunc[wt]->iconize))(data);
     if (remark_is_open && all_iconized()) remark_unmap();
     break;
 case 19:
     change_mapped(report.xany.window, 1);
     if (eventfunc[wt]->deiconize) {
  (*(eventfunc[wt]->deiconize))(data);
  if (remark_is_open) remark_raise();
     }
     break;
 default:
     break;
 }
 can_auto_save = 1;
        call_auto_save(auto_save);
    }
}

variable_types:
matom
unsigned long

variable_types:
keynum
unsigned int

variable_types:
keymode
unsigned int

variable_types:
buffer
char [5000]

variable_types: start long

variable_types:
nit
unsigned long

variable_types: l int

variable_types: freeit int

variable_types:
wmdata
unsigned char *


decompiled_code:
__int64 typepool_init()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-48h] BYREF
const char *v2; // [rsp+8h] [rbp-40h]
__int64 v3; // [rsp+10h] [rbp-38h]
__int64 v4; // [rsp+18h] [rbp-30h]
__int64 v5; // [rsp+20h] [rbp-28h]
int v6; // [rsp+28h] [rbp-20h]

if ( dword_428 <= 4 )
{
v6 = 0;
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v1 = 0LL;
v2 = "NoValidType";
fx_add(&typepool, &v1);
v1 = 0x400000001LL;
v2 = "Int";
fx_add(&typepool, &v1);
v1 = 0x800000002LL;
v2 = "String";
fx_add(&typepool, &v1);
v1 = 0x800000003LL;
v2 = "Real";
fx_add(&typepool, &v1);
v1 = 0x800000004LL;
v2 = "Lazy";
result = fx_add(&typepool, &v1);
}
return result;
}

original_code:
static void typepool_init(void)
{
  TypeConstruct tc;
  if (((&typepool)->nr)>=5) return;
  tc.conskind=0;
  tc.construct=0;
  tc.destruct=0;
  tc.copy=0;
  tc.pos=0;
  tc.conssize=0;
  tc.name="NoValidType";
  fx_add(&typepool, &(tc));
  tc.pos=1;
  tc.conssize=sizeof(int);
  tc.name="Int";
  fx_add(&typepool, &(tc));
  tc.pos=2;
  tc.conssize=sizeof(Uchar*);
  tc.name="String";
  fx_add(&typepool, &(tc));
  tc.pos=3;
  tc.conssize=sizeof(double);
  tc.name="Real";
  fx_add(&typepool, &(tc));
  tc.pos=4;
  tc.conssize=sizeof(void*);
  tc.name="Lazy";
  fx_add(&typepool, &(tc));
}

canonical_original_code:
static void typepool_init()
{
  struct TypeConstruct tc;
  if (((&typepool)->nr)>=5) return;
  tc.conskind=0;
  tc.construct=0;
  tc.destruct=0;
  tc.copy=0;
  tc.pos=0;
  tc.conssize=0;
  tc.name="NoValidType";
  fx_add(&typepool, &(tc));
  tc.pos=1;
  tc.conssize=sizeof(int);
  tc.name="Int";
  fx_add(&typepool, &(tc));
  tc.pos=2;
  tc.conssize=sizeof(unsigned short *);
  tc.name="String";
  fx_add(&typepool, &(tc));
  tc.pos=3;
  tc.conssize=sizeof(double);
  tc.name="Real";
  fx_add(&typepool, &(tc));
  tc.pos=4;
  tc.conssize=sizeof(void *);
  tc.name="Lazy";
  fx_add(&typepool, &(tc));
}

variable_types: struct TypeConstruct { unsigned int pos; int conssize; char *name; void (*construct)(void **); void (*destruct)(void *); void (*copy)(void **, void *); int conskind; union { void *record; } cons; }


decompiled_code:
int __fastcall type_cmp(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 8), *(const char **)(a2 + 8));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 8), *(const char **)(a2 + 8));
}

original_code:
static int type_cmp(const void *type1, const void *type2)
{
  return strcmp(((TypeConstruct*)type1)->name,
  ((TypeConstruct*)type2)->name);
}

canonical_original_code:
static int type_cmp(void *type1, void *type2)
{
  return strcmp(((struct TypeConstruct *)type1)->name,
  ((struct TypeConstruct *)type2)->name);
}

user_defined_types: struct TypeConstruct { unsigned int pos; int conssize; char *name; void (*construct)(void **); void (*destruct)(void *); void (*copy)(void **, void *); int conskind; union { void *record; } cons; }


decompiled_code:
__int64 __fastcall define_type(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
int v8; // eax
int v9; // eax
__int64 result; // rax
_QWORD *v11; // rdx
bool v12; // zf
int v13[2]; // [rsp+0h] [rbp-68h] BYREF
__int64 v14; // [rsp+8h] [rbp-60h]
__int64 v15; // [rsp+10h] [rbp-58h]
__int64 v16; // [rsp+18h] [rbp-50h]
__int64 v17; // [rsp+20h] [rbp-48h]
int v18; // [rsp+28h] [rbp-40h]

v8 = dword_428;
if ( !dword_428 )
{
typepool_init();
v8 = dword_428;
}
v13[0] = v8;
v13[1] = a2;
v14 = a1;
v9 = fx_contains(&typepool, v13);
if ( !v9 )
{
v15 = a3;
v16 = a4;
v17 = a5;
v18 = 0;
fx_add(&typepool, v13);
return (unsigned int)v13[0];
}
result = (unsigned int)(v9 - 1);
v11 = (_QWORD *)(typepool + (unsigned int)(dword_430 * result));
if ( v11[2] )
{
if ( v11[3] )
goto LABEL_6;
}
else
{
v12 = v11[3] == 0LL;
v11[2] = a3;
if ( !v12 )
{
LABEL_6:
if ( v11[4] )
return result;
LABEL_9:
v11[4] = a5;
return result;
}
}
v12 = v11[4] == 0LL;
v11[3] = a4;
if ( v12 )
goto LABEL_9;
return result;
}

original_code:
Type define_type(char *name, int size,
   void (*construct)(void**),
   void (*destruct)(void*),
   void (*copy)(void**, void*))
{
  TypeConstruct tc;
  int type_exists;
  if (!((&typepool)->nr)) typepool_init();
  tc.pos=((&typepool)->nr);
  tc.conssize=size;
  tc.name=name;
  type_exists = fx_contains(&typepool, &(tc));
  if (type_exists) {
    Type t=type_exists-1;
    if (!((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((t))*((&typepool)->size)))).construct)) {
      (*((TypeConstruct*) (((char*)(&typepool)->arr) + ((t))*((&typepool)->size)))).construct=construct;
    }
    if (!((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((t))*((&typepool)->size)))).destruct)) {
      (*((TypeConstruct*) (((char*)(&typepool)->arr) + ((t))*((&typepool)->size)))).destruct=destruct;
    }
    if (!((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((t))*((&typepool)->size)))).copy)) {
      (*((TypeConstruct*) (((char*)(&typepool)->arr) + ((t))*((&typepool)->size)))).copy=copy;
    }
    return t;
  }
  tc.construct=construct;
  tc.destruct=destruct;
  tc.copy=copy;
  tc.conskind=0;
  fx_add(&typepool, &(tc));
  return tc.pos;
}

canonical_original_code:
unsigned int define_type(char *name, int size, void (*construct)(void **), void (*destruct)(void *), void (*copy)(void **, void *))
{
  struct TypeConstruct tc;
  int type_exists;
  if (!((&typepool)->nr)) typepool_init();
  tc.pos=((&typepool)->nr);
  tc.conssize=size;
  tc.name=name;
  type_exists = fx_contains(&typepool, &(tc));
  if (type_exists) {
    unsigned int t = type_exists-1;
    if (!((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((t))*((&typepool)->size)))).construct)) {
      (*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((t))*((&typepool)->size)))).construct=construct;
    }
    if (!((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((t))*((&typepool)->size)))).destruct)) {
      (*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((t))*((&typepool)->size)))).destruct=destruct;
    }
    if (!((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((t))*((&typepool)->size)))).copy)) {
      (*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((t))*((&typepool)->size)))).copy=copy;
    }
    return t;
  }
  tc.construct=construct;
  tc.destruct=destruct;
  tc.copy=copy;
  tc.conskind=0;
  fx_add(&typepool, &(tc));
  return tc.pos;
}

variable_types:
name
char *

variable_types: size int

variable_types:
construct
void (*)(void **)

variable_types:
destruct
void (*)(void *)

variable_types:
copy
void (*)(void **, void *)

variable_types:
t
unsigned int

return_type: unsigned int


decompiled_code:
__int16 __fastcall lookup_type(char *src)
{
size_t v1; // rax
int v2; // edx
__int16 result; // ax
int v4; // eax
__int64 v5; // [rsp+0h] [rbp-458h] BYREF
char *v6; // [rsp+8h] [rbp-450h]
char dest[1048]; // [rsp+40h] [rbp-418h] BYREF

if ( !dword_428 )
typepool_init();
strcpy(dest, src);
v1 = strlen(dest);
if ( !strcmp(&dest[v1 - 3], "Ref") )
{
v6 = dest;
dest[(int)v1 - 3] = 0;
v4 = fx_contains(&typepool, &v5);
if ( v4 )
{
result = v4 - 1;
HIBYTE(result) |= 0x80u;
return result;
}
return 0;
}
v6 = dest;
v2 = fx_contains(&typepool, &v5);
result = v2 - 1;
if ( !v2 )
return 0;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(char *src)
{
size_t v1; // rax
int v2; // edx
__int16 result; // ax
int v4; // eax
__int64 v5; // [rsp+0h] [rbp-458h] BYREF
char *v6; // [rsp+8h] [rbp-450h]
char dest[1048]; // [rsp+40h] [rbp-418h] BYREF

if ( !dword_428 )
func0();
strcpy(dest, src);
v1 = strlen(dest);
if ( !strcmp(&dest[v1 - 3], "Ref") )
{
v6 = dest;
dest[(int)v1 - 3] = 0;
v4 = fx_contains(&typepool, &v5);
if ( v4 )
{
result = v4 - 1;
HIBYTE(result) |= 0x80u;
return result;
}
return 0;
}
v6 = dest;
v2 = fx_contains(&typepool, &v5);
result = v2 - 1;
if ( !v2 )
return 0;
return result;
}

original_code:
Type lookup_type(char *name)
{
  TypeConstruct tc;
  char unrefname[1024];
  int isref, len,i;
  if (!((&typepool)->nr)) typepool_init();
  isref=0;
  strcpy(unrefname, name);
  len=strlen(unrefname);
  if (!strcmp(unrefname+len-refextlen, refext)) {
    unrefname[len-refextlen]=0;
    isref=1;
  }
  tc.name=unrefname;
  i = fx_contains(&typepool, &(tc));
  if (i) {
    if (isref) return ((i-1)|0x8000);
    else return i-1;
  } else
    return 0;
}

canonical_original_code:
unsigned int lookup_type(char *name)
{
  struct TypeConstruct tc;
  char unrefname[1024];
  int isref; int len; int i;
  if (!((&typepool)->nr)) typepool_init();
  isref=0;
  strcpy(unrefname, name);
  len=strlen(unrefname);
  if (!strcmp(unrefname+len-refextlen, refext)) {
    unrefname[len-refextlen]=0;
    isref=1;
  }
  tc.name=unrefname;
  i = fx_contains(&typepool, &(tc));
  if (i) {
    if (isref) return ((i-1)|0x8000);
    else return i-1;
  } else
    return 0;
}

variable_types:
unrefname
char [1024]

variable_types: isref int

variable_types: len int

variable_types: i int


decompiled_code:
const char *__fastcall lookup_typename(unsigned int a1)
{
const char *result; // rax

if ( (a1 & 0x8000) != 0 )
a1 &= 0x7FFFu;
result = "???";
if ( a1 )
{
if ( dword_428 > a1 )
result = *(const char **)(typepool + dword_430 * a1 + 8);
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned int a1)
{
const char *result; // rax

if ( (a1 & 0x8000) != 0 )
a1 &= 0x7FFFu;
result = "???";
if ( a1 )
{
if ( dword_428 > a1 )
result = *(const char **)(typepool + dword_430 * a1 + 8);
}
return result;
}

original_code:
char *lookup_typename(Type t)
{
  if ((((t)&0x8000)>0)) t=((t)&0x7fff);
  if (t<1 || t>=((&typepool)->nr)) return "???";
  return (*((TypeConstruct*) (((char*)(&typepool)->arr) + ((t))*((&typepool)->size)))).name;
}

canonical_original_code:
char *lookup_typename(unsigned int t)
{
  if ((((t)&0x8000)>0)) t=((t)&0x7fff);
  if (t<1 || t>=((&typepool)->nr)) return "???";
  return (*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((t))*((&typepool)->size)))).name;
}

return_type: char *


ConstructValue

decompiled_code:
void __fastcall ConstructValue(__int64 a1)
{
void (__fastcall *v1)(__int64); // rax

if ( a1 )
{
if ( (BYTE1(*(_DWORD *)a1) & 0x80u) == 0
&& (v1 = *(void (__fastcall **)(__int64))(typepool + dword_430 * (*(_DWORD *)a1 & 0x1FFFu) + 16)) != 0LL )
{
v1(a1 + 8);
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
}
}

original_code:
void ConstructValue(Value* v)
{
  Type t;
  if (!v) return;
  t=v->type;
  if ((((t)&0x8000)>0)) {
    v->val.stval=0;
  } else {
    if ((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).construct) {
      (*((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).construct))(&v->val.stval);
    } else {
      v->val.stval=0;
    }
  }
}

canonical_original_code:
void ConstructValue(struct Value *v)
{
  unsigned int t;
  if (!v) return;
  t=v->type;
  if ((((t)&0x8000)>0)) {
    v->val.stval=0;
  } else {
    if ((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).construct) {
      (*((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).construct))(&v->val.stval);
    } else {
      v->val.stval=0;
    }
  }
}

variable_types: struct Value { unsigned int type; union TVal { int ival; double rval; void *stval; int *iref; double *rref; void **stref; } val; } *

user_defined_types: struct Value { unsigned int type; union TVal val; }


CopyValue

decompiled_code:
__int64 __fastcall CopyValue(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx
_QWORD *v4; // rsi

result = *a1;
v3 = *(_DWORD *)a2 & 0x8000;
if ( (result & 0x8000) == 0 )
{
v4 = *(_QWORD **)(a2 + 8);
result = *(_QWORD *)(typepool + dword_430 * (*a1 & 0x1FFF) + 32);
if ( v3 )
{
v4 = (_QWORD *)*v4;
if ( result )
return ((__int64 (__fastcall *)(unsigned int *, _QWORD *))result)(a1 + 2, v4);
}
else if ( result )
{
return ((__int64 (__fastcall *)(unsigned int *, _QWORD *))result)(a1 + 2, v4);
}
*((_QWORD *)a1 + 1) = v4;
return result;
}
if ( v3 )
{
result = *(_QWORD *)(a2 + 8);
*((_QWORD *)a1 + 1) = result;
}
else
{
*((_QWORD *)a1 + 1) = a2 + 8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx
_QWORD *v4; // rsi

result = *a1;
v3 = *(_DWORD *)a2 & 0x8000;
if ( (result & 0x8000) == 0 )
{
v4 = *(_QWORD **)(a2 + 8);
result = *(_QWORD *)(typepool + dword_430 * (*a1 & 0x1FFF) + 32);
if ( v3 )
{
v4 = (_QWORD *)*v4;
if ( result )
return ((__int64 (__fastcall *)(unsigned int *, _QWORD *))result)(a1 + 2, v4);
}
else if ( result )
{
return ((__int64 (__fastcall *)(unsigned int *, _QWORD *))result)(a1 + 2, v4);
}
*((_QWORD *)a1 + 1) = v4;
return result;
}
if ( v3 )
{
result = *(_QWORD *)(a2 + 8);
*((_QWORD *)a1 + 1) = result;
}
else
{
*((_QWORD *)a1 + 1) = a2 + 8;
}
return result;
}

original_code:
void CopyValue(Value* dest, Value* orig)
{
  if ((((dest->type)&0x8000)>0)) {
    if ((((orig->type)&0x8000)>0)) {
      dest->val.stref=orig->val.stref;
    } else {
      dest->val.stref=(void*) (&(orig->val));
    }
  } else {
    if ((((orig->type)&0x8000)>0)) {
      if ((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy) {
 (*((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy))(&dest->val.stval,
            *(orig->val.stref));
      } else {
 memcpy(&dest->val, orig->val.stref, sizeof(TVal));
      }
    } else {
      if ((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy) {
 (*((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy))(&dest->val.stval,
            orig->val.stval);
      } else {
 dest->val=orig->val;
      }
    }
  }
}

canonical_original_code:
void CopyValue(struct Value *dest, struct Value *orig)
{
  if ((((dest->type)&0x8000)>0)) {
    if ((((orig->type)&0x8000)>0)) {
      dest->val.stref=orig->val.stref;
    } else {
      dest->val.stref=(void *) (&(orig->val));
    }
  } else {
    if ((((orig->type)&0x8000)>0)) {
      if ((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy) {
 (*((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy))(&dest->val.stval,
            *(orig->val.stref));
      } else {
 memcpy(&dest->val, orig->val.stref, sizeof(TVal));
      }
    } else {
      if ((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy) {
 (*((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((dest->type)&0x1fff)))*((&typepool)->size)))).copy))(&dest->val.stval,
            orig->val.stval);
      } else {
 dest->val=orig->val;
      }
    }
  }
}

variable_types:
orig
struct Value *

user_defined_types: union TVal { int ival; double rval; void *stval; int *iref; double *rref; void **stref; }


DestructValue

decompiled_code:
void __fastcall DestructValue(__int64 a1)
{
void (__fastcall *v1)(_QWORD); // rax

if ( a1 && (BYTE1(*(_DWORD *)a1) & 0x80u) == 0 )
{
v1 = *(void (__fastcall **)(_QWORD))(typepool + dword_430 * (*(_DWORD *)a1 & 0x1FFFu) + 24);
if ( v1 )
v1(*(_QWORD *)(a1 + 8));
}
}

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

if ( a1 && (BYTE1(*(_DWORD *)a1) & 0x80u) == 0 )
{
v1 = *(void (__fastcall **)(_QWORD))(typepool + dword_430 * (*(_DWORD *)a1 & 0x1FFFu) + 24);
if ( v1 )
v1(*(_QWORD *)(a1 + 8));
}
}

original_code:
void DestructValue(Value* v)
{
  Type t;
  if (!v) return;
  t=v->type;
  if (!(((t)&0x8000)>0)) {
    if ((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).destruct) {
      (*((*((TypeConstruct*) (((char*)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).destruct))(v->val.stval);
    }
  }
}

canonical_original_code:
void DestructValue(struct Value *v)
{
  unsigned int t;
  if (!v) return;
  t=v->type;
  if (!(((t)&0x8000)>0)) {
    if ((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).destruct) {
      (*((*((struct TypeConstruct *) (((char *)(&typepool)->arr) + ((((t)&0x1fff)))*((&typepool)->size)))).destruct))(v->val.stval);
    }
  }
}


decompiled_code:
__int64 __fastcall expand_flex(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // ebp
bool v5; // sf
int v6; // esi
void *v7; // rdi
int v8; // ebp
void *v9; // rax

result = 1LL;
if ( *(_DWORD *)(a1 + 12) <= a2 )
{
v3 = a2 + 32;
v5 = a2 + 1 < 0;
v6 = a2 + 1;
v7 = *(void **)a1;
if ( v5 )
v6 = v3;
v8 = (v6 >> 5) + 1;
if ( v7 )
v9 = realloc(v7, 32 * v8 * *(_DWORD *)(a1 + 16));
else
v9 = malloc(32 * v8 * *(_DWORD *)(a1 + 16));
if ( v9 )
{
*(_QWORD *)a1 = v9;
result = 1LL;
*(_DWORD *)(a1 + 12) = 32 * v8;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int expand_flex(FlexArray *fl, int sz)
{
    if (fl->max < sz+1) {
        void *temp;
 if (fl->arr)
     temp = (void *) realloc(fl->arr, fl->size * (32 * ((sz+1)/32 +1)));
 else
     temp = (void*) malloc(fl->size * (32 * ((sz+1)/32 +1)));
 if (!temp) return 0;
 fl->arr = temp;
 fl->max = (32 * ((sz+1)/32 +1));
    }
    return 1;
}

canonical_original_code:
static int expand_flex(struct FlexArray *fl, int sz)
{
    if (fl->max < sz+1) {
        void *temp;
 if (fl->arr)
     temp = (void *) realloc(fl->arr, fl->size * (32 * ((sz+1)/32 +1)));
 else
     temp = (void *) malloc(fl->size * (32 * ((sz+1)/32 +1)));
 if (!temp) return 0;
 fl->arr = temp;
 fl->max = (32 * ((sz+1)/32 +1));
    }
    return 1;
}

variable_types: struct FlexArray { void *arr; int nr; int max; int size; int (*comp)(void *, void *); } *

variable_types: sz int

variable_types:
temp
void *


decompiled_code:
__int64 __fastcall int_cmp(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 != *a2;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 != *a2;
return result;
}

original_code:
int int_cmp(const void *x, const void *y)
{
    return (*((int*)x) < *((int*)y) ? -1 : (*((int*)x) == *((int*)y) ? 0 : 1));
}

variable_types:
x
void *

variable_types:
y
void *


decompiled_code:
__int64 __fastcall fx_contains(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
int v4; // edi

v2 = 0;
if ( *(int *)(a1 + 8) <= 0 )
return 0LL;
while ( 1 )
{
v4 = v2 * *(_DWORD *)(a1 + 16);
++v2;
if ( !(*(unsigned int (__fastcall **)(_QWORD, __int64))(a1 + 24))(*(_QWORD *)a1 + v4, a2) )
break;
if ( *(_DWORD *)(a1 + 8) <= (signed int)v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
int v4; // edi

v2 = 0;
if ( *(int *)(a1 + 8) <= 0 )
return 0LL;
while ( 1 )
{
v4 = v2 * *(_DWORD *)(a1 + 16);
++v2;
if ( !(*(unsigned int (__fastcall **)(_QWORD, __int64))(a1 + 24))(*(_QWORD *)a1 + v4, a2) )
break;
if ( *(_DWORD *)(a1 + 8) <= (signed int)v2 )
return 0LL;
}
return v2;
}

original_code:
int fx_contains(FlexArray *fl, void *item)
{
    int i=0;
    if (!fl->nr) return 0;
    while (i<fl->nr) {
 if (!(fl->comp((char*)fl->arr+i*fl->size, item)))
     return i+1;
 i++;
    }
    return 0;
}

canonical_original_code:
int fx_contains(struct FlexArray *fl, void *item)
{
    int i = 0;
    if (!fl->nr) return 0;
    while (i<fl->nr) {
 if (!(fl->comp((char *)fl->arr+i*fl->size, item)))
     return i+1;
 i++;
    }
    return 0;
}

variable_types:
item
void *

user_defined_types: struct FlexArray { void *arr; int nr; int max; int size; int (*comp)(void *, void *); }


original_code:
void fx_remove(FlexArray *fl, void *item)
{
    int i,delta,cmpres;
    if (!fl->nr) return;
    delta=0;
    for (i=0; i<fl->nr; i++) {
 cmpres = !(fl->comp((char*)fl->arr+i*fl->size, item));
 if (delta && !cmpres)
     membwd((char*)fl->arr+(i-delta)*fl->size,
     (char*)fl->arr+i*fl->size,
     (char*)fl->arr+(i+1)*fl->size);
 if (cmpres) delta++;
    }
    fl->nr = fl->nr-delta;
}

canonical_original_code:
void fx_remove(struct FlexArray *fl, void *item)
{
    int i; int delta; int cmpres;
    if (!fl->nr) return;
    delta=0;
    for (i=0; i<fl->nr; i++) {
 cmpres = !(fl->comp((char *)fl->arr+i*fl->size, item));
 if (delta && !cmpres)
     membwd((char *)fl->arr+(i-delta)*fl->size,
     (char *)fl->arr+i*fl->size,
     (char *)fl->arr+(i+1)*fl->size);
 if (cmpres) delta++;
    }
    fl->nr = fl->nr-delta;
}

variable_types: delta int

variable_types: cmpres int


original_code:
void fx_add(FlexArray *fl, void *item)
{
    if (!expand_flex(fl, fl->nr)) return;
    membwd((char*)fl->arr+fl->nr*fl->size,(char*)item,(char*)item+fl->size);
    fl->nr++;
}

canonical_original_code:
void fx_add(struct FlexArray *fl, void *item)
{
    if (!expand_flex(fl, fl->nr)) return;
    membwd((char *)fl->arr+fl->nr*fl->size,(char *)item,(char *)item+fl->size);
    fl->nr++;
}


original_code:
int fx_switch(FlexArray *fl, void *olditem, void *newitem)
{
    int i,changed=0;
    i=0;
    while (i<fl->nr) {
 if (!fl->comp((char*)fl->arr+i*fl->size, olditem)) {
     membwd((char*)fl->arr+i*fl->size,(char*)newitem,(char*)newitem+fl->size);
     changed=i+1;
 }
 i++;
    }
    return changed;
}

canonical_original_code:
int fx_switch(struct FlexArray *fl, void *olditem, void *newitem)
{
    int i; int changed = 0;
    i=0;
    while (i<fl->nr) {
 if (!fl->comp((char *)fl->arr+i*fl->size, olditem)) {
     membwd((char *)fl->arr+i*fl->size,(char *)newitem,(char *)newitem+fl->size);
     changed=i+1;
 }
 i++;
    }
    return changed;
}

variable_types:
olditem
void *

variable_types:
newitem
void *

variable_types: changed int


original_code:
void fx_init(FlexArray *fl, int sz, int (*cmp)(const void*,const void*))
{
    fl->size=sz;
    fl->comp=cmp;
    fl->max=0;
    fl->nr=0;
    fl->arr=((void *)0);
}

canonical_original_code:
void fx_init(struct FlexArray *fl, int sz, int (*cmp)(void *, void *))
{
    fl->size=sz;
    fl->comp=cmp;
    fl->max=0;
    fl->nr=0;
    fl->arr=((void *)0);
}

variable_types:
cmp
int (*)(void *, void *)


decompiled_code:
void __fastcall fx_clear(__int64 a1)
{
void *v2; // rdi

*(_QWORD *)(a1 + 8) = 0LL;
v2 = *(void **)a1;
if ( v2 )
free(v2);
*(_QWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
void *v2; // rdi

*(_QWORD *)(a1 + 8) = 0LL;
v2 = *(void **)a1;
if ( v2 )
free(v2);
*(_QWORD *)a1 = 0LL;
}

original_code:
void fx_clear(FlexArray *fl)
{
    fl->max=0;
    fl->nr=0;
    if (fl->arr) free(fl->arr);
    fl->arr = 0;
}

canonical_original_code:
void fx_clear(struct FlexArray *fl)
{
    fl->max=0;
    fl->nr=0;
    if (fl->arr) free(fl->arr);
    fl->arr = 0;
}


decompiled_code:
__int64 __fastcall fx_set(__int64 a1, int a2, __int64 a3)
{
int v4; // ebx
int v5; // esi
__int64 result; // rax

if ( a2 < 0 )
return 0LL;
v4 = a2;
v5 = *(_DWORD *)(a1 + 8);
if ( v5 <= v4 )
{
if ( !(unsigned int)expand_flex(a1, v5) )
return 0LL;
v5 = *(_DWORD *)(a1 + 8);
}
if ( v4 > v5 )
v4 = v5;
membwd(*(_QWORD *)a1 + v4 * *(_DWORD *)(a1 + 16), a3, a3 + *(int *)(a1 + 16));
result = (unsigned int)(v4 + 1);
if ( v4 == *(_DWORD *)(a1 + 8) )
*(_DWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, __int64 a3)
{
int v4; // ebx
int v5; // esi
__int64 result; // rax

if ( a2 < 0 )
return 0LL;
v4 = a2;
v5 = *(_DWORD *)(a1 + 8);
if ( v5 <= v4 )
{
if ( !(unsigned int)func1(a1, v5) )
return 0LL;
v5 = *(_DWORD *)(a1 + 8);
}
if ( v4 > v5 )
v4 = v5;
func0(*(_QWORD *)a1 + v4 * *(_DWORD *)(a1 + 16), a3, a3 + *(int *)(a1 + 16));
result = (unsigned int)(v4 + 1);
if ( v4 == *(_DWORD *)(a1 + 8) )
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
int fx_set(FlexArray *fl, int pos, void *item)
{
    if (pos<0) return 0;
    if (pos>=fl->nr && !expand_flex(fl,fl->nr)) return 0;
    if (pos>=fl->nr) pos = fl->nr;
    membwd((char*)fl->arr+pos*fl->size,(char*)item,(char*)item+fl->size);
    if (pos==fl->nr) fl->nr++;
    return pos+1;
}

canonical_original_code:
int fx_set(struct FlexArray *fl, int pos, void *item)
{
    if (pos<0) return 0;
    if (pos>=fl->nr && !expand_flex(fl,fl->nr)) return 0;
    if (pos>=fl->nr) pos = fl->nr;
    membwd((char *)fl->arr+pos*fl->size,(char *)item,(char *)item+fl->size);
    if (pos==fl->nr) fl->nr++;
    return pos+1;
}

variable_types: pos int


decompiled_code:
void *__fastcall fx_copy(__int64 a1)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 16);
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, *(const void **)a1, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 16);
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, *(const void **)a1, v1);
return v3;
}

original_code:
void *fx_copy(FlexArray *fl)
{
    void *res;
    res = malloc(fl->size*fl->nr);
    if (res) memcpy(res, fl->arr, fl->size*fl->nr);
    return res;
}

canonical_original_code:
void *fx_copy(struct FlexArray *fl)
{
    void *res;
    res = malloc(fl->size*fl->nr);
    if (res) memcpy(res, fl->arr, fl->size*fl->nr);
    return res;
}

variable_types:
res
void *

return_type: void *


decompiled_code:
void func_free()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void func_free(void *var __attribute__((unused)))
{
}

canonical_original_code:
static void func_free(void *var)
{
}

variable_types:
var
void *


decompiled_code:
int __fastcall func_cmp(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
static int func_cmp(const void *func1, const void *func2)
{
    return strcmp(((FunctionDef*)func1)->name, ((FunctionDef*)func2)->name);
}

canonical_original_code:
static int func_cmp(void *func1, void *func2)
{
    return strcmp(((struct FunctionDef *)func1)->name, ((struct FunctionDef *)func2)->name);
}

user_defined_types: struct FunctionDef { char *name; char *description; char nr_args; char functype; unsigned int restype; struct Prototype *prototype; void (*funcptr)(); }

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


original_code:
FuncRef define_function(char *name, char *description,
   Prototype *prototype, void (*funcptr)())
{
    FunctionDef fdef;
    fdef.name=name;
    fdef.description=description;
    fdef.nr_args=((prototype)->n);
    fdef.restype=((prototype)->restype);
    fdef.prototype=prototype;
    fdef.funcptr=funcptr;
    LT_insert(&funcpool, &fdef);
    return (FuncRef) LT_found_leaf();
}

canonical_original_code:
struct FuncDef *define_function(char *name, char *description, struct Prototype *prototype, void (*funcptr)())
{
    struct FunctionDef fdef;
    fdef.name=name;
    fdef.description=description;
    fdef.nr_args=((prototype)->n);
    fdef.restype=((prototype)->restype);
    fdef.prototype=prototype;
    fdef.funcptr=funcptr;
    LT_insert(&funcpool, &fdef);
    return (struct FuncDef *) LT_found_leaf();
}

variable_types:
name
char *

variable_types:
description
char *

variable_types:
funcptr
void (*)()

variable_types: struct FunctionDef { char *name; char *description; char nr_args; char functype; unsigned int restype; struct Prototype { unsigned int *type; int n; unsigned int restype; int max; int (*caller)(); } *prototype; void (*funcptr)(); }

return_type: struct FuncDef { char *name; char *description; char nr_args; char functype; unsigned int rettype; void *prototype; } *


decompiled_code:
__int64 __fastcall lookup_function(__int64 a1)
{
__int64 result; // rax
__int64 v2[7]; // [rsp+0h] [rbp-38h] BYREF

v2[0] = a1;
result = LT_member(&funcpool, v2);
if ( result )
result = LT_found_leaf();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2[7]; // [rsp+0h] [rbp-38h] BYREF

v2[0] = a1;
result = LT_member(&funcpool, v2);
if ( result )
result = LT_found_leaf();
return result;
}

original_code:
FuncRef lookup_function(char *name)
{
    FunctionDef fdef;
    fdef.name=name;
    if (LT_member(&funcpool,&fdef)) {
 return LT_found_leaf();
    } else {
 return 0;
    }
}

canonical_original_code:
struct FuncDef *lookup_function(char *name)
{
    struct FunctionDef fdef;
    fdef.name=name;
    if (LT_member(&funcpool,&fdef)) {
 return LT_found_leaf();
    } else {
 return 0;
    }
}

user_defined_types: struct FuncDef { char *name; char *description; char nr_args; char functype; unsigned int rettype; void *prototype; }


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

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

original_code:
Prototype *proto_function(FuncRef function)
{
    return (Prototype*) (function?function->prototype:0);
}

canonical_original_code:
struct Prototype *proto_function(struct FuncDef *function)
{
    return (struct Prototype *) (function?function->prototype:0);
}

variable_types: struct FuncDef { char *name; char *description; char nr_args; char functype; unsigned int rettype; void *prototype; } *

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


decompiled_code:
__int64 __fastcall restype_function(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
Type restype_function(FuncRef function)
{
    return ((FunctionDef*)function)->restype;
}

canonical_original_code:
unsigned int restype_function(struct FuncDef *function)
{
    return ((struct FunctionDef *)function)->restype;
}


original_code:
int call_function(FuncRef function, Value **list)
{
    Type t;
    FunctionDef *fdef = (FunctionDef*) function;
    void *refval[50];
    void *argval[50];
    Value *v;
    int i,n;
    if (error_status) return error_status;
    if (!((fdef->prototype)->caller)) {
 error_status = 2;
 return 2;
    }
    n=((fdef->prototype)->n);
    for (i=0; i<n; i++) {
 v=list[i];
 t = (((i)<0||(i)>=(fdef->prototype)->n) ? 0 : (fdef->prototype)->type[i]);
        if (!((!(((t)^(v->type))&0x1FFF)) && (((t)^(v->type))!=0xC000))) {
     error_status = 1;
     return 1;
 }
 if ((((t)&0x8000)>0)) {
     if ((((v->type)&0x8000)>0)) {
  argval[i]=&v->val;
     } else {
  refval[i]=&v->val;
  argval[i]=&refval[i];
     }
 } else {
     if ((((v->type)&0x8000)>0)) {
  argval[i]= *((void**)(&v->val));
     } else {
  argval[i]=&v->val;
     }
 }
    }
    t=fdef->restype;
    if (t) {
      v=list[i];
      t=((t)|0x8000);
      if ((((v->type)&0x8000)>0)) {
 argval[i]=&v->val;
      } else {
 refval[i]=&v->val;
 argval[i]=&refval[i];
      }
    }
    (((fdef->prototype)->caller))(fdef->funcptr, &argval);
    return error_status;
}

canonical_original_code:
int call_function(struct FuncDef *function, struct Value **list)
{
    unsigned int t;
    struct FunctionDef *fdef = (FunctionDef*) function;
    void *refval[50];
    void *argval[50];
    struct Value *v;
    int i; int n;
    if (error_status) return error_status;
    if (!((fdef->prototype)->caller)) {
 error_status = 2;
 return 2;
    }
    n=((fdef->prototype)->n);
    for (i=0; i<n; i++) {
 v=list[i];
 t = (((i)<0||(i)>=(fdef->prototype)->n) ? 0 : (fdef->prototype)->type[i]);
        if (!((!(((t)^(v->type))&0x1FFF)) && (((t)^(v->type))!=0xC000))) {
     error_status = 1;
     return 1;
 }
 if ((((t)&0x8000)>0)) {
     if ((((v->type)&0x8000)>0)) {
  argval[i]=&v->val;
     } else {
  refval[i]=&v->val;
  argval[i]=&refval[i];
     }
 } else {
     if ((((v->type)&0x8000)>0)) {
  argval[i]= *((void **)(&v->val));
     } else {
  argval[i]=&v->val;
     }
 }
    }
    t=fdef->restype;
    if (t) {
      v=list[i];
      t=((t)|0x8000);
      if ((((v->type)&0x8000)>0)) {
 argval[i]=&v->val;
      } else {
 refval[i]=&v->val;
 argval[i]=&refval[i];
      }
    }
    (((fdef->prototype)->caller))(fdef->funcptr, &argval);
    return error_status;
}

variable_types: struct Value { unsigned int type; union TVal { int ival; double rval; void *stval; int *iref; double *rref; void **stref; } val; } **

variable_types:
t
unsigned int

variable_types: struct FunctionDef { char *name; char *description; char nr_args; char functype; unsigned int restype; struct Prototype { unsigned int *type; int n; unsigned int restype; int max; int (*caller)(); } *prototype; void (*funcptr)(); } *

variable_types:
refval
void *[50]

variable_types:
argval
void *[50]

variable_types: i int

variable_types: n int


decompiled_code:
__int64 __fastcall font_handle(int a1, _DWORD *a2)
{
*a2 = font_change_attribute((unsigned int)*a2, (a1 >> 5) & 0x1F, a1 & 0x1F);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, _DWORD *a2)
{
*a2 = font_change_attribute((unsigned int)*a2, (a1 >> 5) & 0x1F, a1 & 0x1F);
return 0LL;
}

original_code:
static Uchar *font_handle(int lowvalue, Attribute *attr, RedirectFunc *func)
{
    int attribute,value;
    int curattr;
    curattr=attr->font;
    attribute=(lowvalue&0x3e0)>>5;
    value=(lowvalue&0x1f);
    attr->font=font_change_attribute(curattr, attribute, value);
    return 0;
}

canonical_original_code:
static unsigned short *font_handle(int lowvalue, struct _attribs *attr, int (**func)(unsigned short))
{
    int attribute; int value;
    int curattr;
    curattr=attr->font;
    attribute=(lowvalue&0x3e0)>>5;
    value=(lowvalue&0x1f);
    attr->font=font_change_attribute(curattr, attribute, value);
    return 0;
}

variable_types: lowvalue int

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)

variable_types: attribute int

variable_types: value int

variable_types: curattr int

return_type: unsigned short *


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

result = add_markup_handler(56193LL, font_print, font_handle);
if ( !result )
{
v1 = translate("Unable to add font handler.\n");
v2 = (const char *)UstrtoLocale(v1);
result = fprintf(stderr, v2);
}
return result;
}

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

result = add_markup_handler(56193LL, font_print, font_handle);
if ( !result )
{
v1 = translate("Unable to add font handler.\n");
v2 = (const char *)UstrtoLocale(v1);
result = fprintf(stderr, v2);
}
return result;
}

original_code:
void font_markup_init(void)
{
    if (!add_markup_handler(FontAttrib, font_print, font_handle)) {
 fprintf(stderr,
  UstrtoLocale(translate("Unable to add font handler.\n")));
    }
}

canonical_original_code:
void font_markup_init()
{
    if (!add_markup_handler(FontAttrib, font_print, font_handle)) {
 fprintf(stderr,
  UstrtoLocale(translate("Unable to add font handler.\n")));
    }
}


decompiled_code:
int check_property()
{
int v0; // eax
int v2; // [rsp+Ch] [rbp-2Ch] BYREF
Atom v3; // [rsp+10h] [rbp-28h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-20h] BYREF
unsigned __int64 v5; // [rsp+20h] [rbp-18h] BYREF
unsigned __int8 *v6; // [rsp+28h] [rbp-10h] BYREF

XGetWindowProperty(display, testwin, testend, 0LL, 512LL, 0, textprop, &v3, &v2, &v4, &v5, &v6);
if ( v4 != 3 || (v0 = 1, strcmp((const char *)v6, "Yes")) )
v0 = 0;
other_prog_ex |= v0;
return XFree(v6);
}

canonical_decompiled_code:
int func2()
{
int v0; // eax
int v2; // [rsp+Ch] [rbp-2Ch] BYREF
Atom v3; // [rsp+10h] [rbp-28h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-20h] BYREF
unsigned __int64 v5; // [rsp+20h] [rbp-18h] BYREF
unsigned __int8 *v6; // [rsp+28h] [rbp-10h] BYREF

XGetWindowProperty(display, testwin, testend, 0LL, 512LL, 0, textprop, &v3, &v2, &v4, &v5, &v6);
if ( v4 != 3 || (v0 = 1, strcmp((const char *)v6, "Yes")) )
v0 = 0;
other_prog_ex |= v0;
return XFree(v6);
}

original_code:
static void check_property(void)
{
    Atom actt;
    int actf;
    unsigned long nit, baf;
    unsigned char *prp;
    XGetWindowProperty(display, testwin, testend, 0, 512, 0, textprop,
         &actt, &actf, &nit, &baf, &prp);
    other_prog_ex |= (nit==3 && !strcmp((char*)prp, "Yes"));
    XFree(prp);
}

canonical_original_code:
static void check_property()
{
    unsigned long actt;
    int actf;
    unsigned long nit; unsigned long baf;
    unsigned char *prp;
    XGetWindowProperty(display, testwin, testend, 0, 512, 0, textprop,
         &actt, &actf, &nit, &baf, &prp);
    other_prog_ex |= (nit==3 && !strcmp((char *)prp, "Yes"));
    XFree(prp);
}

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 check_event()
{
int result; // eax
Window v1; // rdx

result = event.type;
if ( event.type == 28 )
{
v1 = event.xkey.root;
if ( v1 == dummy && event.xexpose.count == 1 )
{
propempty = 1;
}
else if ( v1 == testend )
{
result = event.xexpose.count;
if ( result )
{
if ( result == 1 )
{
XDeleteProperty(display, testwin, v1);
XCloseDisplay(display);
exit(0);
}
}
else
{
result = check_property();
}
}
}
else if ( event.type == 17 )
{
result = testwin;
if ( event.xkey.root == testwin )
exit(0);
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax
Window v1; // rdx

result = event.type;
if ( event.type == 28 )
{
v1 = event.xkey.root;
if ( v1 == dummy && event.xexpose.count == 1 )
{
propempty = 1;
}
else if ( v1 == testend )
{
result = event.xexpose.count;
if ( result )
{
if ( result == 1 )
{
XDeleteProperty(display, testwin, v1);
XCloseDisplay(display);
exit(0);
}
}
else
{
result = func2();
}
}
}
else if ( event.type == 17 )
{
result = testwin;
if ( event.xkey.root == testwin )
exit(0);
}
return result;
}

original_code:
static void check_event(void)
{
    if (event.type==28 &&
 event.xproperty.atom==dummy &&
 event.xproperty.state==1)
 propempty=1;
    else if (event.type==28 &&
      event.xproperty.atom==testend &&
      event.xproperty.state==0)
 check_property();
    else if (event.type==28 &&
      event.xproperty.atom==testend &&
      event.xproperty.state==1) {
 XDeleteProperty(display, testwin, testend);
 XCloseDisplay(display);
 exit(0);
    } else if (event.type==17 &&
        event.xdestroywindow.window==testwin)
 exit(0);
}

canonical_original_code:
static void check_event()
{
    if (event.type==28 &&
 event.xproperty.atom==dummy &&
 event.xproperty.state==1)
 propempty=1;
    else if (event.type==28 &&
      event.xproperty.atom==testend &&
      event.xproperty.state==0)
 check_property();
    else if (event.type==28 &&
      event.xproperty.atom==testend &&
      event.xproperty.state==1) {
 XDeleteProperty(display, testwin, testend);
 XCloseDisplay(display);
 exit(0);
    } else if (event.type==17 &&
        event.xdestroywindow.window==testwin)
 exit(0);
}


decompiled_code:
int read_input()
{
__int64 v0; // rdx
int *v1; // rbp
_QWORD *v2; // rbx
int v3; // er13
int v4; // er12
char *v5; // rax
size_t v6; // r15
int v7; // ebx
_QWORD *v8; // rax
_QWORD *v9; // r14
int result; // eax

v0 = (unsigned int)oldfileflag;
BYTE1(v0) = BYTE1(oldfileflag) | 8;
fcntl(filenof, 4, v0);
v1 = _errno_location();
do
{
v2 = (_QWORD *)endstack;
v3 = allocsize;
if ( endstack )
{
v4 = allocsize - *(_DWORD *)(endstack + 8);
if ( v4 <= 99 )
{
v6 = allocsize;
v4 = allocsize;
v8 = malloc(0x18uLL);
v2[2] = v8;
v9 = v8;
endstack = (__int64)v8;
v2 = v8;
v5 = (char *)malloc(v3);
*((_DWORD *)v9 + 2) = 0;
*v9 = v5;
v9[2] = 0LL;
}
else
{
v5 = *(char **)endstack;
v6 = v4;
}
}
else
{
v6 = allocsize;
v4 = allocsize;
v2 = malloc(0x18uLL);
endstack = (__int64)v2;
beginstack = v2;
v5 = (char *)malloc(v3);
*((_DWORD *)v2 + 2) = 0;
*v2 = v5;
v2[2] = 0LL;
}
*v1 = 0;
v7 = fread(&v5[*((int *)v2 + 2)], 1uLL, v6, f);
if ( *v1 )
clearerr(f);
if ( v7 > 0 )
{
totlen += v7;
*(_DWORD *)(endstack + 8) += v7;
}
}
while ( v7 == v4 );
result = fcntl(filenof, 4, (unsigned int)oldfileflag);
*v1 = 0;
return result;
}

canonical_decompiled_code:
int func5()
{
__int64 v0; // rdx
int *v1; // rbp
_QWORD *v2; // rbx
int v3; // er13
int v4; // er12
char *v5; // rax
size_t v6; // r15
int v7; // ebx
_QWORD *v8; // rax
_QWORD *v9; // r14
int result; // eax

v0 = (unsigned int)oldfileflag;
BYTE1(v0) = BYTE1(oldfileflag) | 8;
fcntl(filenof, 4, v0);
v1 = _errno_location();
do
{
v2 = (_QWORD *)endstack;
v3 = allocsize;
if ( endstack )
{
v4 = allocsize - *(_DWORD *)(endstack + 8);
if ( v4 <= 99 )
{
v6 = allocsize;
v4 = allocsize;
v8 = malloc(0x18uLL);
v2[2] = v8;
v9 = v8;
endstack = (__int64)v8;
v2 = v8;
v5 = (char *)malloc(v3);
*((_DWORD *)v9 + 2) = 0;
*v9 = v5;
v9[2] = 0LL;
}
else
{
v5 = *(char **)endstack;
v6 = v4;
}
}
else
{
v6 = allocsize;
v4 = allocsize;
v2 = malloc(0x18uLL);
endstack = (__int64)v2;
beginstack = v2;
v5 = (char *)malloc(v3);
*((_DWORD *)v2 + 2) = 0;
*v2 = v5;
v2[2] = 0LL;
}
*v1 = 0;
v7 = fread(&v5[*((int *)v2 + 2)], 1uLL, v6, f);
if ( *v1 )
clearerr(f);
if ( v7 > 0 )
{
totlen += v7;
*(_DWORD *)(endstack + 8) += v7;
}
}
while ( v7 == v4 );
result = fcntl(filenof, 4, (unsigned int)oldfileflag);
*v1 = 0;
return result;
}

original_code:
static void read_input(void)
{
    int i,c;
    i=c=0;
    fcntl(filenof,4,oldfileflag|04000|0|04000);
    while (i==c) {
 if (!endstack) {
     beginstack=endstack=(STRSTACK*) malloc(sizeof(STRSTACK));
     endstack->str=(char*) malloc(sizeof(char)*allocsize);
     endstack->len=0;
     endstack->next=((void *)0);
 } else if (allocsize-endstack->len < 100) {
     endstack->next = (STRSTACK*) malloc(sizeof(STRSTACK));
     endstack=endstack->next;
     endstack->str=(char*) malloc(sizeof(char)*allocsize);
     endstack->len=0;
     endstack->next=0;
 }
 c=allocsize-endstack->len;
 (*__errno_location ())=0;
 i= fread(endstack->str+endstack->len, 1, c, f);
 if ((*__errno_location ())) clearerr(f);
 if (i>0) {
     endstack->len+=i;
     totlen+=i;
 }
    }
    fcntl(filenof,4,oldfileflag);
    (*__errno_location ())=0;
}

canonical_original_code:
static void read_input()
{
    int i; int c;
    i=c=0;
    fcntl(filenof,4,oldfileflag|04000|0|04000);
    while (i==c) {
 if (!endstack) {
     beginstack=endstack=(struct STRSTACK *) malloc(sizeof(STRSTACK));
     endstack->str=(char *) malloc(sizeof(char)*allocsize);
     endstack->len=0;
     endstack->next=((void *)0);
 } else if (allocsize-endstack->len < 100) {
     endstack->next = (struct STRSTACK *) malloc(sizeof(STRSTACK));
     endstack=endstack->next;
     endstack->str=(char *) malloc(sizeof(char)*allocsize);
     endstack->len=0;
     endstack->next=0;
 }
 c=allocsize-endstack->len;
 (*__errno_location ())=0;
 i= fread(endstack->str+endstack->len, 1, c, f);
 if ((*__errno_location ())) clearerr(f);
 if (i>0) {
     endstack->len+=i;
     totlen+=i;
 }
    }
    fcntl(filenof,4,oldfileflag);
    (*__errno_location ())=0;
}

variable_types: c int

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


decompiled_code:
int check_events()
{
int result; // eax
int v1; // ebx

while ( 1 )
{
result = XEventsQueued(display, 2);
if ( !result )
break;
v1 = result;
do
{
--v1;
XNextEvent(display, &event);
check_event();
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
int v1; // ebx

while ( 1 )
{
result = XEventsQueued(display, 2);
if ( !result )
break;
v1 = result;
do
{
--v1;
XNextEvent(display, &event);
func4();
}
while ( v1 );
}
return result;
}

original_code:
static void check_events(void)
{
    int n=1,i;
    while (n) {
 i=n=XEventsQueued(display, 2);
 while (i) {
     i--;
     XNextEvent(display, &event);
     check_event();
 }
    }
}

canonical_original_code:
static void check_events()
{
    int n = 1; int i;
    while (n) {
 i=n=XEventsQueued(display, 2);
 while (i) {
     i--;
     XNextEvent(display, &event);
     check_event();
 }
    }
}


decompiled_code:
void __fastcall set_property(int a1)
{
unsigned __int8 *v2; // rax
_DWORD *v3; // r14
unsigned __int8 *v4; // r12
int v5; // ebp
unsigned __int8 *v6; // rbx
unsigned __int8 *v7; // rsi
unsigned int v8; // eax
unsigned __int8 *v9; // rdi
__int64 v10; // rbx
__int64 i; // rax

v2 = (unsigned __int8 *)malloc(a1);
v3 = beginstack;
v4 = v2;
if ( beginstack && a1 > 0 )
{
v5 = 0;
v6 = v2;
v7 = *(unsigned __int8 **)beginstack;
v8 = *((_DWORD *)beginstack + 2);
LABEL_4:
if ( v8 )
{
do
{
++v5;
*v6++ = *v7++;
--v8;
}
while ( v8 && a1 > v5 );
v9 = *(unsigned __int8 **)v3;
if ( v8 )
goto LABEL_12;
}
else
{
while ( 1 )
{
v9 = v7;
if ( !v8 )
break;
LABEL_12:
v3[2] = v8;
v10 = v8;
for ( i = 0LL; i != v10; ++i )
v9[i] = v7[i];
v6 = &v9[v10];
LABEL_9:
if ( a1 <= v5 )
goto LABEL_16;
v7 = *(unsigned __int8 **)v3;
v8 = v3[2];
if ( a1 > v5 )
goto LABEL_4;
}
}
free(v9);
beginstack = (void *)*((_QWORD *)v3 + 2);
free(v3);
v3 = beginstack;
if ( beginstack )
goto LABEL_9;
endstack = 0LL;
}
else
{
v5 = 0;
}
LABEL_16:
totlen -= v5;
XChangeProperty(display, testwin, dummy, textprop, 8, 2, v4, v5);
XFlush(display);
propempty = 0;
free(v4);
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
unsigned __int8 *v2; // rax
_DWORD *v3; // r14
unsigned __int8 *v4; // r12
int v5; // ebp
unsigned __int8 *v6; // rbx
unsigned __int8 *v7; // rsi
unsigned int v8; // eax
unsigned __int8 *v9; // rdi
__int64 v10; // rbx
__int64 i; // rax

v2 = (unsigned __int8 *)malloc(a1);
v3 = beginstack;
v4 = v2;
if ( beginstack && a1 > 0 )
{
v5 = 0;
v6 = v2;
v7 = *(unsigned __int8 **)beginstack;
v8 = *((_DWORD *)beginstack + 2);
LABEL_4:
if ( v8 )
{
do
{
++v5;
*v6++ = *v7++;
--v8;
}
while ( v8 && a1 > v5 );
v9 = *(unsigned __int8 **)v3;
if ( v8 )
goto LABEL_12;
}
else
{
while ( 1 )
{
v9 = v7;
if ( !v8 )
break;
LABEL_12:
v3[2] = v8;
v10 = v8;
for ( i = 0LL; i != v10; ++i )
v9[i] = v7[i];
v6 = &v9[v10];
LABEL_9:
if ( a1 <= v5 )
goto LABEL_16;
v7 = *(unsigned __int8 **)v3;
v8 = v3[2];
if ( a1 > v5 )
goto LABEL_4;
}
}
free(v9);
beginstack = (void *)*((_QWORD *)v3 + 2);
free(v3);
v3 = beginstack;
if ( beginstack )
goto LABEL_9;
endstack = 0LL;
}
else
{
v5 = 0;
}
LABEL_16:
totlen -= v5;
XChangeProperty(display, testwin, dummy, textprop, 8, 2, v4, v5);
XFlush(display);
propempty = 0;
free(v4);
}

original_code:
static void set_property(int size)
{
    STRSTACK *h;
    char *info=((void *)0);
    char *c,*d;
    int i=0,j=0;
    c = info = (char*) malloc(size*sizeof(char));
    h = beginstack;
    while (h && j<size) {
 d = h->str;
 i = h->len;
 while (i && j<size) {
     i--;j++;
     *c++=*d++;
 }
 if (!i) {
     free(h->str);
     beginstack = h->next;
     free(h);
     h = beginstack;
     if (!h) endstack=((void *)0);
 } else {
     c=h->str;
     h->len=i;
     while (i) {
  i--;
  *c++=*d++;
     }
 }
    }
    totlen=totlen-j;
    XChangeProperty(display,testwin,dummy,textprop,8,
      2,(unsigned char*)info,j);
    XFlush(display);
    propempty=0;
    free(info);
}

canonical_original_code:
static void set_property(int size)
{
    struct STRSTACK *h;
    char *info = ((void *)0);
    char *c; char *d;
    int i = 0; int j = 0;
    c = info = (char *) malloc(size*sizeof(char));
    h = beginstack;
    while (h && j<size) {
 d = h->str;
 i = h->len;
 while (i && j<size) {
     i--;j++;
     *c++=*d++;
 }
 if (!i) {
     free(h->str);
     beginstack = h->next;
     free(h);
     h = beginstack;
     if (!h) endstack=((void *)0);
 } else {
     c=h->str;
     h->len=i;
     while (i) {
  i--;
  *c++=*d++;
     }
 }
    }
    totlen=totlen-j;
    XChangeProperty(display,testwin,dummy,textprop,8,
      2,(unsigned char *)info,j);
    XFlush(display);
    propempty=0;
    free(info);
}

variable_types: size int

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

variable_types:
info
char *

variable_types:
c
char *

variable_types:
d
char *

variable_types: j int


decompiled_code:
void get_and_set()
{
int v0; // edi

iosig_on = 0;
read_input();
check_events();
if ( propempty && other_prog_ex )
{
v0 = totlen;
if ( totlen < minsize )
{
if ( !alarm_needed )
{
LABEL_6:
iosig_on = 1;
return;
}
LABEL_5:
alarm_needed = 10;
alarm(0xAu);
goto LABEL_6;
}
if ( maxsize <= totlen )
v0 = maxsize;
set_property(v0);
}
if ( !alarm_needed )
goto LABEL_6;
if ( totlen < minsize )
goto LABEL_5;
alarm_needed = 1;
alarm(1u);
iosig_on = 1;
}

canonical_decompiled_code:
void func9()
{
int v0; // edi

iosig_on = 0;
func5();
func6();
if ( propempty && other_prog_ex )
{
v0 = totlen;
if ( totlen < minsize )
{
if ( !alarm_needed )
{
LABEL_6:
iosig_on = 1;
return;
}
LABEL_5:
alarm_needed = 10;
alarm(0xAu);
goto LABEL_6;
}
if ( maxsize <= totlen )
v0 = maxsize;
func7(v0);
}
if ( !alarm_needed )
goto LABEL_6;
if ( totlen < minsize )
goto LABEL_5;
alarm_needed = 1;
alarm(1u);
iosig_on = 1;
}

original_code:
static void get_and_set(void)
{
    iosig_on=0;
    read_input();
    check_events();
    if (propempty && other_prog_ex && totlen>=minsize)
 set_property(totlen<maxsize?totlen:maxsize);
    if (alarm_needed) {
 if (totlen>=minsize) {
     alarm_needed=1;
 } else alarm_needed=10;
 alarm(alarm_needed);
    }
    iosig_on=1;
}

canonical_original_code:
static void get_and_set()
{
    iosig_on=0;
    read_input();
    check_events();
    if (propempty && other_prog_ex && totlen>=minsize)
 set_property(totlen<maxsize?totlen:maxsize);
    if (alarm_needed) {
 if (totlen>=minsize) {
     alarm_needed=1;
 } else alarm_needed=10;
 alarm(alarm_needed);
    }
    iosig_on=1;
}


decompiled_code:
void __fastcall input_handle(int a1)
{
signal(a1, input_handle);
if ( iosig_on )
get_and_set();
*_errno_location() = 0;
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
signal(a1, input_handle);
if ( iosig_on )
func9();
*_errno_location() = 0;
}

original_code:
static void input_handle(int sig __attribute__((unused)))
{
    signal(sig, input_handle);
    if (iosig_on) get_and_set();
    (*__errno_location ())=0;
}

canonical_original_code:
static void input_handle(int sig)
{
    signal(sig, input_handle);
    if (iosig_on) get_and_set();
    (*__errno_location ())=0;
}

variable_types: sig int


decompiled_code:
void __fastcall alarm_handle(int a1)
{
signal(a1, alarm_handle);
if ( alarm_needed && iosig_on )
{
get_and_set();
*_errno_location() = 0;
}
else
{
*_errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func11(int a1)
{
signal(a1, alarm_handle);
if ( alarm_needed && iosig_on )
{
func9();
*_errno_location() = 0;
}
else
{
*_errno_location() = 0;
}
}

original_code:
static void alarm_handle(int sig __attribute__((unused)))
{
    signal(sig, alarm_handle);
    if (alarm_needed && iosig_on) get_and_set();
    (*__errno_location ())=0;
}

canonical_original_code:
static void alarm_handle(int sig)
{
    signal(sig, alarm_handle);
    if (alarm_needed && iosig_on) get_and_set();
    (*__errno_location ())=0;
}


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

v0 = XOpenDisplay(displayname);
display = v0;
if ( !v0 )
{
v3 = XDisplayName(displayname);
fprintf(stderr, "xpipein: 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);
XDeleteProperty(display, testwin, dummy);
result = check_property();
propempty = 1;
return result;
}

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

v0 = XOpenDisplay(displayname);
display = v0;
if ( !v0 )
{
v3 = XDisplayName(displayname);
fprintf(stderr, "xpipein: 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);
XDeleteProperty(display, testwin, dummy);
result = func2();
propempty = 1;
return result;
}

original_code:
static void server_init(void)
{
    int i;
    XSetWindowAttributes winattr;
    if ((display=XOpenDisplay(displayname))==((void *)0)) {
 fprintf(stderr, "xpipein: 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);
    XDeleteProperty(display,testwin,dummy);
    check_property();
    propempty=1;
}

canonical_original_code:
static void server_init()
{
    int i;
    struct XSetWindowAttributes winattr;
    if ((display=XOpenDisplay(displayname))==((void *)0)) {
 fprintf(stderr, "xpipein: 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);
    XDeleteProperty(display,testwin,dummy);
    check_property();
    propempty=1;
}

variable_types: i int

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 __noreturn handle()
{
set_property(0);
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
func7(0);
XDeleteProperty(display, testwin, testend);
XCloseDisplay(display);
exit(0);
}

original_code:
static void handle(int sig __attribute__((unused)))
{
    set_property(0);
    XDeleteProperty(display, testwin, testend);
    XCloseDisplay(display);
    exit(0);
}

canonical_original_code:
static void handle(int sig)
{
    set_property(0);
    XDeleteProperty(display, testwin, testend);
    XCloseDisplay(display);
    exit(0);
}