repo: bobrippling/tim

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

result = a1[11];
if ( !result )
{
result = a1[12];
if ( !result )
{
result = a1[10];
if ( !result )
result = a1[9];
}
}
return result;
}

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

result = a1[11];
if ( !result )
{
result = a1[12];
if ( !result )
{
result = a1[10];
if ( !result )
result = a1[9];
}
}
return result;
}

original_code:
window *window_next(window *cur)
{
 if(cur->neighbours.below) return cur->neighbours.below;
 if(cur->neighbours.above) return cur->neighbours.above;
 if(cur->neighbours.right) return cur->neighbours.right;
 if(cur->neighbours.left) return cur->neighbours.left;
 return ((void *)0);
}

canonical_original_code:
struct window *window_next(struct window *cur)
{
 if(cur->neighbours.below) return cur->neighbours.below;
 if(cur->neighbours.above) return cur->neighbours.above;
 if(cur->neighbours.right) return cur->neighbours.right;
 if(cur->neighbours.left) return cur->neighbours.left;
 return ((void *)0);
}

variable_types:
cur
struct window *

return_type: struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *

user_defined_types: struct window { struct buffer *buf; struct point ui_start; struct rect screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode ui_mode; struct { struct window *left; } neighbours; }

user_defined_types: struct buffer { struct retain retains; struct list_ *head; struct { struct point npos; enum buf_mode mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; }


decompiled_code:
__int64 __fastcall window_topleftmost(__int64 a1)
{
__int64 result; // rax
int i; // ecx
__int64 v3; // rdx
__int64 j; // rdx

result = a1;
do
{
for ( i = 0; ; i = 1 )
{
v3 = result;
result = *(_QWORD *)(result + 72);
if ( !result )
break;
}
result = v3;
for ( j = *(_QWORD *)(v3 + 96); j; i = 1 )
{
result = j;
j = *(_QWORD *)(j + 96);
}
}
while ( i );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
int i; // ecx
__int64 v3; // rdx
__int64 j; // rdx

result = a1;
do
{
for ( i = 0; ; i = 1 )
{
v3 = result;
result = *(_QWORD *)(result + 72);
if ( !result )
break;
}
result = v3;
for ( j = *(_QWORD *)(v3 + 96); j; i = 1 )
{
result = j;
j = *(_QWORD *)(j + 96);
}
}
while ( i );
return result;
}

original_code:
window *window_topleftmost(window *win)
{
 for(;;){ int changed = 0; for(; win->neighbours.left; changed = 1, win = win->neighbours.left); for(; win->neighbours.above; changed = 1, win = win->neighbours.above); if(!changed) break; } return win;
}

canonical_original_code:
struct window *window_topleftmost(struct window *win)
{
 for(;;){ int changed = 0; for(; win->neighbours.left; changed = 1, win = win->neighbours.left); for(; win->neighbours.above; changed = 1, win = win->neighbours.above); if(!changed) break; } return win;
}

variable_types:
win
struct window *

variable_types: changed int

user_defined_types: enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr }

user_defined_types: struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; }


decompiled_code:
__int64 __fastcall window_bottomrightmost(__int64 a1)
{
__int64 result; // rax
int i; // ecx
__int64 v3; // rdx
__int64 j; // rdx

result = a1;
do
{
for ( i = 0; ; i = 1 )
{
v3 = result;
result = *(_QWORD *)(result + 80);
if ( !result )
break;
}
result = v3;
for ( j = *(_QWORD *)(v3 + 88); j; i = 1 )
{
result = j;
j = *(_QWORD *)(j + 88);
}
}
while ( i );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
int i; // ecx
__int64 v3; // rdx
__int64 j; // rdx

result = a1;
do
{
for ( i = 0; ; i = 1 )
{
v3 = result;
result = *(_QWORD *)(result + 80);
if ( !result )
break;
}
result = v3;
for ( j = *(_QWORD *)(v3 + 88); j; i = 1 )
{
result = j;
j = *(_QWORD *)(j + 88);
}
}
while ( i );
return result;
}

original_code:
window *window_bottomrightmost(window *win)
{
 for(;;){ int changed = 0; for(; win->neighbours.right; changed = 1, win = win->neighbours.right); for(; win->neighbours.below; changed = 1, win = win->neighbours.below); if(!changed) break; } return win;
}

canonical_original_code:
struct window *window_bottomrightmost(struct window *win)
{
 for(;;){ int changed = 0; for(; win->neighbours.right; changed = 1, win = win->neighbours.right); for(; win->neighbours.below; changed = 1, win = win->neighbours.below); if(!changed) break; } return win;
}


decompiled_code:
bool __fastcall neighbour_is_vertical(unsigned int a1)
{
return a1 <= 1;
}

canonical_decompiled_code:
bool __fastcall func5(unsigned int a1)
{
return a1 <= 1;
}

original_code:
_Bool neighbour_is_vertical(enum neighbour n)
{
 switch(n){
  case neighbour_up:
  case neighbour_down:
   return 1;
  case neighbour_left:
  case neighbour_right:
   break;
 }
 return 0;
}

variable_types: enum neighbour { neighbour_up=0, neighbour_down=1, neighbour_left=2, neighbour_right=3 }


decompiled_code:
void __fastcall window_free(void *ptr)
{
release_nochk(*(_QWORD *)ptr, &buffer_free);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
release_nochk(*(_QWORD *)ptr, &buffer_free);
free(ptr);
}

original_code:
void window_free(window *w)
{
 release_nochk((struct retain *)(w->buf), (void (*)(void *))buffer_free);
 free(w);
}

canonical_original_code:
void window_free(struct window *w)
{
 release_nochk((struct retain *)(w->buf), (void (*)(void *))buffer_free);
 free(w);
}

variable_types: struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *

return_type: void


decompiled_code:
__int64 __fastcall window_current_line(_QWORD *a1, unsigned __int8 a2)
{
return list_seek(*(_QWORD *)(*a1 + 8LL), *(unsigned int *)(a1[6] + 4LL), a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, unsigned __int8 a2)
{
return list_seek(*(_QWORD *)(*a1 + 8LL), *(unsigned int *)(a1[6] + 4LL), a2);
}

original_code:
list_t *window_current_line(const window *w, _Bool create)
{
 return list_seek(w->buf->head, w->ui_pos->y, create);
}

canonical_original_code:
struct list_ *window_current_line(struct window *w, _Bool create)
{
 return list_seek(w->buf->head, w->ui_pos->y, create);
}

variable_types: struct window { struct buffer { struct retain { int rcount; } retains; struct list_ *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *

return_type: struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *


decompiled_code:
__int64 __fastcall window_current_word(_QWORD *a1)
{
return list_word_at(*(_QWORD *)(*a1 + 8LL), a1[6]);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
return list_word_at(*(_QWORD *)(*a1 + 8LL), a1[6]);
}

original_code:
char *window_current_word(const window *w)
{
 return list_word_at(w->buf->head, w->ui_pos);
}

canonical_original_code:
char *window_current_word(struct window *w)
{
 return list_word_at(w->buf->head, w->ui_pos);
}

return_type: char *


decompiled_code:
__int64 __fastcall window_current_fname(_QWORD *a1)
{
return list_fname_at(*(_QWORD *)(*a1 + 8LL), a1[6]);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
return list_fname_at(*(_QWORD *)(*a1 + 8LL), a1[6]);
}

original_code:
char *window_current_fname(const window *w)
{
 return list_fname_at(w->buf->head, w->ui_pos);
}

canonical_original_code:
char *window_current_fname(struct window *w)
{
 return list_fname_at(w->buf->head, w->ui_pos);
}


original_code:
point_t window_toscreen(const window *win, point_t const *pt)
{
 list_t *l = list_seek(win->buf->head, win->ui_pos->y, 0);
 int xoff = 0;
 if(l && l->len_line > 0)
  for(int x = (((unsigned)win->ui_pos->x) < (l->len_line - 1) ? ((unsigned)win->ui_pos->x) : (l->len_line - 1));
    x >= 0;
    x--)
   xoff += nc_charlen(l->line[x]) - 1;
 return (point_t){
  win->screen_coord.x + pt->x - win->ui_start.x + xoff,
  win->screen_coord.y + pt->y - win->ui_start.y
 };
}

canonical_original_code:
struct point window_toscreen(struct window *win, struct point *pt)
{
 struct list_ *l = list_seek(win->buf->head, win->ui_pos->y, 0);
 int xoff = 0;
 if(l && l->len_line > 0)
  for(int x = (((unsigned)win->ui_pos->x) < (l->len_line - 1) ? ((unsigned)win->ui_pos->x) : (l->len_line - 1));
    x >= 0;
    x--)
   xoff += nc_charlen(l->line[x]) - 1;
 return (struct point){
  win->screen_coord.x + pt->x - win->ui_start.x + xoff,
  win->screen_coord.y + pt->y - win->ui_start.y
 };
}

variable_types: struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *

variable_types:
pt
struct point *

variable_types: xoff int

variable_types: x int

return_type: struct point { int x; }


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

result = a1 + 40;
if ( *(_QWORD *)(a1 + 48) == a1 + 40 )
result = a1 + 32;
return result;
}

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

result = a1 + 40;
if ( *(_QWORD *)(a1 + 48) == a1 + 40 )
result = a1 + 32;
return result;
}

original_code:
point_t *window_uipos_alt(window *win)
{
 if(win->ui_pos == &win->ui_vpos)
  return &win->ui_npos;
 return &win->ui_vpos;
}

canonical_original_code:
struct point *window_uipos_alt(struct window *win)
{
 if(win->ui_pos == &win->ui_vpos)
  return &win->ui_npos;
 return &win->ui_vpos;
}

return_type: struct point { int x; } *


original_code:
int window_setmode(window *win, enum buf_mode m)
{
 if(!m || (m & (m - 1))){
  return -1;
 }else{
  if(win->ui_mode & (UI_INSERT | UI_INSERT_COL))
   win->buf->prev_insert = *win->ui_pos;
  if(m & ( UI_VISUAL_CHAR | UI_VISUAL_COL | UI_VISUAL_LN)){
   if((win->ui_mode & ( UI_VISUAL_CHAR | UI_VISUAL_COL | UI_VISUAL_LN)) == 0){
    *window_uipos_alt(win) = *win->ui_pos;
   }
  }else{
   win->buf->prev_visual.mode = win->ui_mode;
   win->buf->prev_visual.npos = *win->ui_pos;
   win->buf->prev_visual.vpos = *window_uipos_alt(win);
  }
  win->ui_mode = m;
  return 0;
 }
}

canonical_original_code:
int window_setmode(struct window *win, enum buf_mode m)
{
 if(!m || (m & (m - 1))){
  return -1;
 }else{
  if(win->ui_mode & (UI_INSERT | UI_INSERT_COL))
   win->buf->prev_insert = *win->ui_pos;
  if(m & ( UI_VISUAL_CHAR | UI_VISUAL_COL | UI_VISUAL_LN)){
   if((win->ui_mode & ( UI_VISUAL_CHAR | UI_VISUAL_COL | UI_VISUAL_LN)) == 0){
    *window_uipos_alt(win) = *win->ui_pos;
   }
  }else{
   win->buf->prev_visual.mode = win->ui_mode;
   win->buf->prev_visual.npos = *win->ui_pos;
   win->buf->prev_visual.vpos = *window_uipos_alt(win);
  }
  win->ui_mode = m;
  return 0;
 }
}

variable_types: enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr }

return_type: int


decompiled_code:
__int64 __fastcall window_inschar(_QWORD *a1, char a2)
{
unsigned int v2; // er8

v2 = a2;
if ( *((_DWORD *)a1 + 16) != 4 )
return buffer_inscolchar(*a1, v2, 1LL, a1[6]);
if ( a2 == 10 || a2 == 13 )
{
window_setmode((__int64)a1, 2);
return buffer_inscolchar(*a1, v2, 1LL, a1[6]);
}
return buffer_inscolchar(*a1, (unsigned int)a2, *(unsigned int *)(*a1 + 72LL), a1[6]);
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1, char a2)
{
unsigned int v2; // er8

v2 = a2;
if ( *((_DWORD *)a1 + 16) != 4 )
return buffer_inscolchar(*a1, v2, 1LL, a1[6]);
if ( a2 == 10 || a2 == 13 )
{
func14((__int64)a1, 2);
return buffer_inscolchar(*a1, v2, 1LL, a1[6]);
}
return buffer_inscolchar(*a1, (unsigned int)a2, *(unsigned int *)(*a1 + 72LL), a1[6]);
}

original_code:
void window_inschar(window *win, char ch)
{
 if(win->ui_mode != UI_INSERT_COL || ((ch) == '\n' || (ch) == '\r')){
  if(win->ui_mode == UI_INSERT_COL)
   window_setmode(win, UI_INSERT);
  buffer_inscolchar(win->buf, ch, 1, win->ui_pos);
 }else{
  buffer_inscolchar(win->buf, ch, win->buf->col_insert_height, win->ui_pos);
 }
}

canonical_original_code:
void window_inschar(struct window *win, char ch)
{
 if(win->ui_mode != UI_INSERT_COL || ((ch) == '\n' || (ch) == '\r')){
  if(win->ui_mode == UI_INSERT_COL)
   window_setmode(win, UI_INSERT);
  buffer_inscolchar(win->buf, ch, 1, win->ui_pos);
 }else{
  buffer_inscolchar(win->buf, ch, win->buf->col_insert_height, win->ui_pos);
 }
}

variable_types: ch char


decompiled_code:
bool __fastcall window_replace_fname(__int64 *a1, __int64 a2, _QWORD *a3)
{
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = 0LL;
buffer_new_fname(v5);
if ( !*a3 )
{
window_replace_buffer(a1, v5[0]);
release_nochk(v5[0], &buffer_free);
}
return *a3 == 0LL;
}

canonical_decompiled_code:
bool __fastcall func17(__int64 *a1, __int64 a2, _QWORD *a3)
{
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = 0LL;
buffer_new_fname(v5);
if ( !*a3 )
{
func16(a1, v5[0]);
release_nochk(v5[0], &buffer_free);
}
return *a3 == 0LL;
}

original_code:
_Bool window_replace_fname(window *win, const char *fname, const char **const err)
{
 buffer_t *buf = ((void *)0);
 buffer_new_fname(&buf, fname, err);
 if(!*err){
  window_replace_buffer(win, buf);
  release_nochk((struct retain *)(buf), (void (*)(void *))buffer_free);
 }
 return !*err;
}

canonical_original_code:
_Bool window_replace_fname(struct window *win, char *fname, char **err)
{
 struct buffer *buf = ((void *)0);
 buffer_new_fname(&buf, fname, err);
 if(!*err){
  window_replace_buffer(win, buf);
  release_nochk((struct retain *)(buf), (void (*)(void *))buffer_free);
 }
 return !*err;
}

variable_types:
fname
char *

variable_types:
err
char **

variable_types: struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *


decompiled_code:
bool __fastcall window_reload_buffer(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rsi
bool result; // al

v3 = buffer_fname(*a1);
result = 0;
if ( v3 )
{
buffer_replace_fname(*a1, v3, a2);
result = *a2 == 0LL;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func18(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rsi
bool result; // al

v3 = buffer_fname(*a1);
result = 0;
if ( v3 )
{
buffer_replace_fname(*a1, v3, a2);
result = *a2 == 0LL;
}
return result;
}

original_code:
_Bool window_reload_buffer(window *win, const char **const err)
{
 const char *fname = buffer_fname(win->buf);
 if(!fname)
  return 0;
 buffer_replace_fname(win->buf, fname, err);
 return !*err;
}

canonical_original_code:
_Bool window_reload_buffer(struct window *win, char **err)
{
 char *fname = buffer_fname(win->buf);
 if(!fname)
  return 0;
 buffer_replace_fname(win->buf, fname, err);
 return !*err;
}


decompiled_code:
__int64 __fastcall window_smartindent(_QWORD *a1)
{
return buffer_smartindent(*a1, a1[6], *(unsigned int *)(a1[6] + 4LL));
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1)
{
return buffer_smartindent(*a1, a1[6], *(unsigned int *)(a1[6] + 4LL));
}

original_code:
void window_smartindent(window *win)
{
 buffer_smartindent(win->buf, &win->ui_pos->x, win->ui_pos->y);
}

canonical_original_code:
void window_smartindent(struct window *win)
{
 buffer_smartindent(win->buf, &win->ui_pos->x, win->ui_pos->y);
}


decompiled_code:
char nc_init()
{
char result; // al

if ( init_0 )
return wrefresh(stdscr);
init_0 = 1;
initscr();
noecho();
cbreak();
raw();
scrollok(stdscr, 1);
nonl();
intrflush(stdscr, 0);
set_escdelay(0);
result = has_colors();
if ( result )
{
start_color();
use_default_colors();
init_pair(1, 0, -1);
init_pair(3, 2, -1);
init_pair(8, 7, -1);
init_pair(2, 1, -1);
init_pair(7, 6, -1);
init_pair(6, 5, -1);
init_pair(5, 4, -1);
init_pair(4, 3, -1);
init_pair(9, -1, 0);
init_pair(11, -1, 2);
init_pair(16, -1, 7);
init_pair(10, -1, 1);
init_pair(15, -1, 6);
init_pair(14, -1, 5);
init_pair(13, -1, 4);
result = init_pair(12, -1, 3);
}
return result;
}

canonical_decompiled_code:
char func0()
{
char result; // al

if ( init_0 )
return wrefresh(stdscr);
init_0 = 1;
initscr();
noecho();
cbreak();
raw();
scrollok(stdscr, 1);
nonl();
intrflush(stdscr, 0);
set_escdelay(0);
result = has_colors();
if ( result )
{
start_color();
use_default_colors();
init_pair(1, 0, -1);
init_pair(3, 2, -1);
init_pair(8, 7, -1);
init_pair(2, 1, -1);
init_pair(7, 6, -1);
init_pair(6, 5, -1);
init_pair(5, 4, -1);
init_pair(4, 3, -1);
init_pair(9, -1, 0);
init_pair(11, -1, 2);
init_pair(16, -1, 7);
init_pair(10, -1, 1);
init_pair(15, -1, 6);
init_pair(14, -1, 5);
init_pair(13, -1, 4);
result = init_pair(12, -1, 3);
}
return result;
}

original_code:
void nc_init()
{
 static int init = 0;
 if(!init){
  init = 1;
  initscr();
  noecho();
  cbreak();
  raw();
  scrollok(stdscr, 1);
  nonl();
  intrflush(stdscr, 0);
  set_escdelay(0);
  if(has_colors()){
   start_color();
   use_default_colors();
   init_pair(1 + 0, 0, -1);
   init_pair(1 + 2, 2, -1);
   init_pair(1 + 7, 7, -1);
   init_pair(1 + 1, 1, -1);
   init_pair(1 + 6, 6, -1);
   init_pair(1 + 5, 5, -1);
   init_pair(1 + 4, 4, -1);
   init_pair(1 + 3, 3, -1);
   init_pair(9 + 0, -1, 0);
   init_pair(9 + 2, -1, 2);
   init_pair(9 + 7, -1, 7);
   init_pair(9 + 1, -1, 1);
   init_pair(9 + 6, -1, 6);
   init_pair(9 + 5, -1, 5);
   init_pair(9 + 4, -1, 4);
   init_pair(9 + 3, -1, 3);
  }
 }else{
  wrefresh(stdscr);
 }
}

variable_types: init int


decompiled_code:
// attributes: thunk
int nc_term(void)
{
return endwin();
}

canonical_decompiled_code:
int func1(void)
{
return endwin();
}

original_code:
void nc_term()
{
 endwin();
}

canonical_original_code:
void nc_term()
{
 endwin();
}


decompiled_code:
int nc_clearall()
{
return wclear(stdscr);
}

canonical_decompiled_code:
int func2()
{
return wclear(stdscr);
}

original_code:
void nc_clearall()
{
 wclear(stdscr);
}

canonical_original_code:
void nc_clearall()
{
 wclear(stdscr);
}


decompiled_code:
__int64 __fastcall nc_highlight(int a1)
{
int (**v1)(int); // rax

v1 = &attron;
if ( !a1 )
v1 = &attroff;
return ((__int64 (__fastcall *)(__int64))v1)(0x40000LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int (**v1)(int); // rax

v1 = &attron;
if ( !a1 )
v1 = &attroff;
return ((__int64 (__fastcall *)(__int64))v1)(0x40000LL);
}

original_code:
void nc_highlight(int on)
{
 (on ? attron : attroff)(((chtype)((1U)) << ((10) + 8)));
}

variable_types: on int


decompiled_code:
int __fastcall nc_status(char *a1, int a2)
{
int v2; // er12

v2 = a2;
scrollok(stdscr, 0);
if ( a2 )
v2 = COLS / 2;
wmove(stdscr, LINES - 1, v2);
wclrtoeol(stdscr);
waddnstr(stdscr, a1, -1);
return scrollok(stdscr, 1);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, int a2)
{
int v2; // er12

v2 = a2;
scrollok(stdscr, 0);
if ( a2 )
v2 = COLS / 2;
wmove(stdscr, LINES - 1, v2);
wclrtoeol(stdscr);
waddnstr(stdscr, a1, -1);
return scrollok(stdscr, 1);
}

original_code:
void nc_status(const char *fmt, int right)
{
 scrollok(stdscr, 0);
 int x = 0;
 if(right)
  x = COLS / 2;
 wmove(stdscr,(LINES - 1),(x));
 wclrtoeol(stdscr);
 waddnstr(stdscr,(fmt),-1);
 scrollok(stdscr, 1);
}

canonical_original_code:
void nc_status(char *fmt, int right)
{
 scrollok(stdscr, 0);
 int x = 0;
 if(right)
  x = COLS / 2;
 wmove(stdscr,(LINES - 1),(x));
 wclrtoeol(stdscr);
 waddnstr(stdscr,(fmt),-1);
 scrollok(stdscr, 1);
}

variable_types:
fmt
char *

variable_types: right int


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

if ( stdscr )
{
result = (unsigned int)stdscr->_curx;
*a1 = stdscr->_cury;
*a2 = result;
}
else
{
result = 0xFFFFFFFFLL;
*a1 = -1;
*a2 = -1;
}
return result;
}

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

if ( stdscr )
{
result = (unsigned int)stdscr->_curx;
*a1 = stdscr->_cury;
*a2 = result;
}
else
{
result = 0xFFFFFFFFLL;
*a1 = -1;
*a2 = -1;
}
return result;
}

original_code:
void nc_get_yx(int *y, int *x)
{
 (*y = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), *x = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
}

variable_types:
y
int *

variable_types:
x
int *


decompiled_code:
int __fastcall nc_set_yx(int a1, int a2)
{
return wmove(stdscr, a1, a2);
}

canonical_decompiled_code:
int __fastcall func6(int a1, int a2)
{
return wmove(stdscr, a1, a2);
}

original_code:
void nc_set_yx(int y, int x)
{
 wmove(stdscr,(y),(x));
}

variable_types: y int


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

result = 1LL;
if ( a1 != 9 )
{
result = 2LL;
if ( a1 != 13 )
result = (unsigned int)(((*_ctype_b_loc())[a1] & 0x4000) == 0) + 1;
}
return result;
}

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

result = 1LL;
if ( a1 != 9 )
{
result = 2LL;
if ( a1 != 13 )
result = (unsigned int)(((*_ctype_b_loc())[a1] & 0x4000) == 0) + 1;
}
return result;
}

original_code:
int nc_charlen(int ch)
{
 int l = 1;
 switch(ch){
  case '\r':
   l++;
   break;
  case '\t':
   break;
  default:
   if(!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint))
    l++;
 }
 return l;
}

canonical_original_code:
int nc_charlen(int ch)
{
 int l = 1;
 switch(ch){
  case '\r':
   l++;
   break;
  case '\t':
   break;
  default:
   if(!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint))
    l++;
 }
 return l;
}

variable_types: ch int

variable_types: l int


decompiled_code:
int __fastcall nc_getch(char a1, _BYTE *a2)
{
char v2; // r13
int *v3; // rbx
int result; // eax

v2 = 0;
v3 = _errno_location();
do
{
while ( 1 )
{
*v3 = 0;
result = wgetch(stdscr);
if ( result < 0 )
break;
if ( v2 )
return result;
if ( result == 26 )
{
raise(20);
}
else
{
if ( !a1 )
return result;
if ( result == 13 )
{
result = 10;
goto LABEL_17;
}
if ( result != 22 )
goto LABEL_17;
if ( a2 )
*a2 = 1;
*v3 = 0;
result = wgetch(stdscr);
if ( result >= 0 || *v3 != 4 )
return result;
v2 = 1;
}
}
}
while ( *v3 == 4 );
if ( v2 || !a1 )
return result;
LABEL_17:
if ( a2 )
*a2 = 0;
return result;
}

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

v2 = 0;
v3 = _errno_location();
do
{
while ( 1 )
{
*v3 = 0;
result = wgetch(stdscr);
if ( result < 0 )
break;
if ( v2 )
return result;
if ( result == 26 )
{
raise(20);
}
else
{
if ( !a1 )
return result;
if ( result == 13 )
{
result = 10;
goto LABEL_17;
}
if ( result != 22 )
goto LABEL_17;
if ( a2 )
*a2 = 1;
*v3 = 0;
result = wgetch(stdscr);
if ( result >= 0 || *v3 != 4 )
return result;
v2 = 1;
}
}
}
while ( *v3 == 4 );
if ( v2 || !a1 )
return result;
LABEL_17:
if ( a2 )
*a2 = 0;
return result;
}

original_code:
int nc_getch(_Bool mapraw, _Bool *wasraw)
{
 _Bool ctrl_v = 0;
 int ch;
restart:
 (*__errno_location ()) = 0;
 ch = wgetch(stdscr);
 if(ch < 0 && (*__errno_location ()) == 4)
  goto restart;
 if(ctrl_v)
  return ch;
 if(ch == (('z') & 037)){
  raise(20);
  goto restart;
 }
 if(mapraw){
  if(ch == '\r'){
   ch = '\n';
  }else if(ch == (('v') & 037)){
   if(wasraw)
    *wasraw = 1;
   ctrl_v = 1;
   goto restart;
  }
  if(wasraw)
   *wasraw = 0;
 }
 return ch;
}

variable_types:
wasraw
_Bool *


decompiled_code:
int __fastcall nc_addch(unsigned __int8 a1)
{
if ( a1 == 9 )
return waddch(stdscr, 0x20uLL);
if ( a1 != 13 )
return waddch(stdscr, a1);
waddch(stdscr, 0x5EuLL);
return waddch(stdscr, 0x4DuLL);
}

canonical_decompiled_code:
int __fastcall func9(unsigned __int8 a1)
{
if ( a1 == 9 )
return waddch(stdscr, 0x20uLL);
if ( a1 != 13 )
return waddch(stdscr, a1);
waddch(stdscr, 0x5EuLL);
return waddch(stdscr, 0x4DuLL);
}

original_code:
void nc_addch(char c)
{
 if(c == '\t'){
  c = ' ';
 }else if(c == '\r'){
  waddch(stdscr,('^'));
  waddch(stdscr,('M'));
  return;
 }
 waddch(stdscr,(c & 0xff));
}

variable_types: c char


variable_types: enum nc_style { ATTR_BOLD=expr, COL_BLUE=expr, COL_BROWN=expr, COL_BG_RED=expr }

variable_types: col int


decompiled_code:
int __fastcall nc_addstr(char *a1)
{
return waddnstr(stdscr, a1, -1);
}

canonical_decompiled_code:
int __fastcall func11(char *a1)
{
return waddnstr(stdscr, a1, -1);
}

original_code:
void nc_addstr(const char *s)
{
 waddnstr(stdscr,(s),-1);
}

canonical_original_code:
void nc_addstr(char *s)
{
 waddnstr(stdscr,(s),-1);
}

variable_types:
s
char *


decompiled_code:
int __fastcall nc_vprintf(char *a1, va_list a2)
{
return vwprintw(stdscr, a1, a2);
}

canonical_decompiled_code:
int __fastcall func12(char *a1, va_list a2)
{
return vwprintw(stdscr, a1, a2);
}

original_code:
void nc_vprintf(const char *fmt, va_list l)
{
 vwprintw(stdscr, fmt, l);
}

canonical_original_code:
void nc_vprintf(char *fmt, __builtin_va_list l)
{
 vwprintw(stdscr, fmt, l);
}


decompiled_code:
__int64 nc_LINES()
{
return (unsigned int)LINES;
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned int)LINES;
}

original_code:
int nc_LINES(void)
{
 return LINES;
}

canonical_original_code:
int nc_LINES()
{
 return LINES;
}


decompiled_code:
__int64 nc_COLS()
{
return (unsigned int)COLS;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)COLS;
}

original_code:
int nc_COLS(void)
{
 return COLS;
}

canonical_original_code:
int nc_COLS()
{
 return COLS;
}


decompiled_code:
int nc_clrtoeol()
{
return wclrtoeol(stdscr);
}

canonical_decompiled_code:
int func15()
{
return wclrtoeol(stdscr);
}

original_code:
void nc_clrtoeol()
{
 wclrtoeol(stdscr);
}


decompiled_code:
__int64 __fastcall io_fifo_pop(_BYTE *a1)
{
char *v2; // rdi
unsigned int v3; // er12
__int64 v4; // rdx

v2 = (char *)io_fifo;
v3 = *(unsigned __int8 *)io_fifo;
*a1 = *((_BYTE *)io_fifo + 1) & 1;
v4 = io_fifoused - 1;
io_fifoused = v4;
if ( v4 )
memmove(v2, v2 + 4, 4 * v4);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
char *v2; // rdi
unsigned int v3; // er12
__int64 v4; // rdx

v2 = (char *)io_fifo;
v3 = *(unsigned __int8 *)io_fifo;
*a1 = *((_BYTE *)io_fifo + 1) & 1;
v4 = io_fifoused - 1;
io_fifoused = v4;
if ( v4 )
memmove(v2, v2 + 4, 4 * v4);
return v3;
}

original_code:
static int io_fifo_pop(_Bool *need_map)
{
 int ret = io_fifo->ch;
 *need_map = io_fifo->needs_map;
 io_fifoused--;
 if(io_fifoused)
  memmove(io_fifo, io_fifo + 1, sizeof(*io_fifo) * io_fifoused);
 return ret;
}

variable_types: ret int


decompiled_code:
void *__fastcall io_fifo_ins(char a1, char a2)
{
char v2; // bp
_BYTE *v3; // rbx
void *result; // rax
char v5; // si

v2 = a2 & 1;
io_fifo_realloc_constprop_0();
v3 = io_fifo;
result = memmove((char *)io_fifo + 4, io_fifo, 4 * io_fifoused - 4);
v5 = v3[1];
*v3 = a1;
v3[1] = v2 | v5 & 0xFE;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(char a1, char a2)
{
char v2; // bp
_BYTE *v3; // rbx
void *result; // rax
char v5; // si

v2 = a2 & 1;
func1();
v3 = io_fifo;
result = memmove((char *)io_fifo + 4, io_fifo, 4 * io_fifoused - 4);
v5 = v3[1];
*v3 = a1;
v3[1] = v2 | v5 & 0xFE;
return result;
}

original_code:
static void io_fifo_ins(char c, _Bool need_map)
{
 io_fifo_realloc(1);
 memmove(io_fifo + 1, io_fifo, (io_fifoused - 1) * sizeof(*io_fifo));
 io_fifo->ch = c;
 io_fifo->needs_map = need_map;
}


decompiled_code:
__int64 io_bufsz()
{
return io_fifoused;
}

canonical_decompiled_code:
__int64 func3()
{
return io_fifoused;
}

original_code:
size_t io_bufsz(void)
{
 return io_fifoused;
}

canonical_original_code:
unsigned long io_bufsz()
{
 return io_fifoused;
}

return_type: unsigned long


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

result = 8LL;
if ( (a1 & 6) == 0 )
result = (a1 & 0x38) == 0 ? 2 : 4;
return result;
}

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

result = 8LL;
if ( (a1 & 6) == 0 )
result = (a1 & 0x38) == 0 ? 2 : 4;
return result;
}

original_code:
enum io bufmode_to_iomap(enum buf_mode bufmode)
{
 if(bufmode & (UI_INSERT | UI_INSERT_COL))
  return IO_MAPI;
 if(bufmode & ( UI_VISUAL_CHAR | UI_VISUAL_COL | UI_VISUAL_LN))
  return IO_MAPV;
 return IO_MAP;
}

variable_types: enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr }

return_type: enum io { IO_NOMAP=expr, IO_MAP=expr, IO_MAPV=expr, IO_MAPI=expr, IO_MAPRAW=expr }


decompiled_code:
void *__fastcall io_ungetch(char a1, char a2)
{
return io_fifo_ins(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func5(char a1, char a2)
{
return func2(a1, a2);
}

original_code:
void io_ungetch(int ch, _Bool needmap)
{
 io_fifo_ins(ch, needmap);
}


decompiled_code:
__int64 __fastcall io_getch(unsigned int a1, _BYTE *a2, char a3)
{
bool v4; // zf
unsigned int v5; // er9
_QWORD *v6; // rax
_QWORD *v7; // r12
const char *v8; // rbp
size_t v9; // rbx
char v11[25]; // [rsp+Fh] [rbp-19h] BYREF

v4 = io_fifoused == 0;
*a2 = 0;
v11[0] = 0;
if ( v4 )
v5 = nc_getch((a1 >> 4) & 1);
else
v5 = io_fifo_pop(v11);
if ( a3 && (!*a2 || v11[0]) )
{
v6 = io_findmap(v5, a1 & 0xFFFFFFEF);
v7 = v6;
if ( v6 )
{
v8 = (const char *)v6[1];
v9 = strlen(v8);
if ( v9 )
{
while ( 1 )
{
io_ungetch(v8[--v9], 0);
if ( !v9 )
break;
v8 = (const char *)v7[1];
}
}
v5 = io_fifo_pop(v11);
if ( v11[0] )
_assert_fail("!need_map", "io.c", 0x6Au, "io_getch");
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, _BYTE *a2, char a3)
{
bool v4; // zf
unsigned int v5; // er9
_QWORD *v6; // rax
_QWORD *v7; // r12
const char *v8; // rbp
size_t v9; // rbx
char v11[25]; // [rsp+Fh] [rbp-19h] BYREF

v4 = io_fifoused == 0;
*a2 = 0;
v11[0] = 0;
if ( v4 )
v5 = nc_getch((a1 >> 4) & 1);
else
v5 = func0(v11);
if ( a3 && (!*a2 || v11[0]) )
{
v6 = io_findmap(v5, a1 & 0xFFFFFFEF);
v7 = v6;
if ( v6 )
{
v8 = (const char *)v6[1];
v9 = strlen(v8);
if ( v9 )
{
while ( 1 )
{
func5(v8[--v9], 0);
if ( !v9 )
break;
v8 = (const char *)v7[1];
}
}
v5 = func0(v11);
if ( v11[0] )
_assert_fail("!need_map", "io.c", 0x6Au, "io_getch");
}
}
return v5;
}

original_code:
int io_getch(enum io ty, _Bool *wasraw, _Bool domaps)
{
 if(wasraw)
  *wasraw = 0;
 int ch;
 _Bool need_map = 0;
 if(io_fifoused)
  ch = io_fifo_pop(&need_map);
 else
  ch = nc_getch(ty & IO_MAPRAW, wasraw);
 if(domaps && (!wasraw || !*wasraw || need_map)){
  const keymap_t *map = io_findmap(ch, ty & ~IO_MAPRAW);
  if(map){
   for(size_t i = strlen(map->to); i > 0; i--)
    io_ungetch(map->to[i-1], 0);
   ch = io_fifo_pop(&need_map);
   ((!need_map) ? (void) (0) : __assert_fail ("!need_map", "io.c", 106, __extension__ __PRETTY_FUNCTION__));
   return ch;
  }
 }
 return ch;
}

canonical_original_code:
int io_getch(enum io ty, _Bool *wasraw, _Bool domaps)
{
 if(wasraw)
  *wasraw = 0;
 int ch;
 _Bool need_map = 0;
 if(io_fifoused)
  ch = io_fifo_pop(&need_map);
 else
  ch = nc_getch(ty & IO_MAPRAW, wasraw);
 if(domaps && (!wasraw || !*wasraw || need_map)){
  struct keymap *map = io_findmap(ch, ty & ~IO_MAPRAW);
  if(map){
   for(unsigned long i = strlen(map->to); i > 0; i--)
    io_ungetch(map->to[i-1], 0);
   ch = io_fifo_pop(&need_map);
   ((!need_map) ? (void) (0) : __assert_fail ("!need_map", "io.c", 106, __extension__ __PRETTY_FUNCTION__));
   return ch;
  }
 }
 return ch;
}

variable_types: struct keymap { enum io { IO_NOMAP=expr, IO_MAP=expr, IO_MAPV=expr, IO_MAPI=expr, IO_MAPRAW=expr } mode; char from; char *to; } *

variable_types:
i
unsigned long

user_defined_types: struct keymap { enum io mode; char from; char *to; }


decompiled_code:
__int64 __fastcall io_read_repeat(unsigned int a1)
{
unsigned int i; // er12
int v2; // ebp
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

i = 0;
v2 = io_getch(a1, v4, 1);
if ( ((*_ctype_b_loc())[v2] & 0x800) != 0 && v2 != 48 )
{
for ( i = v2 - 48; ; i = v2 + 10 * i - 48 )
{
v2 = io_getch(a1, v4, 1);
if ( (unsigned int)(v2 - 48) > 9 )
break;
}
}
io_ungetch(v2, 0);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
unsigned int i; // er12
int v2; // ebp
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

i = 0;
v2 = func6(a1, v4, 1);
if ( ((*_ctype_b_loc())[v2] & 0x800) != 0 && v2 != 48 )
{
for ( i = v2 - 48; ; i = v2 + 10 * i - 48 )
{
v2 = func6(a1, v4, 1);
if ( (unsigned int)(v2 - 48) > 9 )
break;
}
}
func5(v2, 0);
return i;
}

original_code:
unsigned io_read_repeat(enum io io_mode)
{
 unsigned repeat = 0;
 _Bool raw;
 int ch = io_getch(io_mode, &raw, 1);
 (void)raw;
 if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) && ch != '0'){
  repeat = ch - '0';
  for(;;){
   ch = io_getch(io_mode, &raw, 1);
   if('0' <= ch && ch <= '9')
    repeat = repeat * 10 + ch - '0';
   else
    break;
  }
 }
 io_ungetch(ch, 0);
 return repeat;
}

canonical_original_code:
unsigned int io_read_repeat(enum io io_mode)
{
 unsigned int repeat = 0;
 _Bool raw;
 int ch = io_getch(io_mode, &raw, 1);
 (void)raw;
 if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) && ch != '0'){
  repeat = ch - '0';
  for(;;){
   ch = io_getch(io_mode, &raw, 1);
   if('0' <= ch && ch <= '9')
    repeat = repeat * 10 + ch - '0';
   else
    break;
  }
 }
 io_ungetch(ch, 0);
 return repeat;
}

variable_types: enum io { IO_NOMAP=expr, IO_MAP=expr, IO_MAPV=expr, IO_MAPI=expr, IO_MAPRAW=expr }

variable_types:
repeat
unsigned int

return_type: unsigned int


umalloc

decompiled_code:
void *__fastcall umalloc(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
umalloc_cold();
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
func5();
return result;
}

original_code:
void *umalloc(size_t l)
{
 void *p = malloc(l);
 if(!p)
  abort();
 memset(p, 0, l);
 return p;
}

canonical_original_code:
void *umalloc(unsigned long l)
{
 void *p = malloc(l);
 if(!p)
  abort();
 memset(p, 0, l);
 return p;
}

variable_types:
l
unsigned long

variable_types:
p
void *

return_type: void *


urealloc

decompiled_code:
void *__fastcall urealloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
urealloc_cold();
return result;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
func6();
return result;
}

original_code:
void *urealloc(void *p, size_t l)
{
 void *r = realloc(p, l);
 if(!r)
  abort();
 return r;
}

canonical_original_code:
void *urealloc(void *p, unsigned long l)
{
 void *r = realloc(p, l);
 if(!r)
  abort();
 return r;
}

variable_types:
r
void *


ustrdup

decompiled_code:
char *__fastcall ustrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)umalloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *ustrdup(const char *s)
{
 char *r = umalloc(strlen(s) + 1);
 strcpy(r, s);
 return r;
}

canonical_original_code:
char *ustrdup(char *s)
{
 char *r = umalloc(strlen(s) + 1);
 strcpy(r, s);
 return r;
}

variable_types:
r
char *


join

decompiled_code:
char *__fastcall join(const char *a1, const char **a2, int a3)
{
const char **v5; // rbx
int v6; // eax
int v7; // er15
__int64 v8; // rax
const char **v9; // r12
int v10; // ebp
__int64 v11; // r13
const char *v12; // rdi
char *v13; // rax
const char *v14; // rdx
char *v15; // r12
char *v16; // rbp
const char *v17; // rcx

v5 = a2;
v6 = strlen(a1);
if ( a3 <= 0 )
return (char *)umalloc(1uLL);
v7 = v6;
v8 = (unsigned int)(a3 - 1);
v9 = a2;
v10 = 1;
v11 = (__int64)&a2[v8 + 1];
do
{
v12 = *v9++;
v10 += strlen(v12) + v7;
}
while ( v9 != (const char **)v11 );
v13 = (char *)umalloc(v10);
v14 = (const char *)&unk_1CA;
v15 = v13;
v16 = v13;
while ( 1 )
{
v17 = *v5++;
v16 += sprintf(v16, "%s%s", v14, v17);
if ( v5 == (const char **)v11 )
break;
v14 = a1;
}
return v15;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, const char **a2, int a3)
{
const char **v5; // rbx
int v6; // eax
int v7; // er15
__int64 v8; // rax
const char **v9; // r12
int v10; // ebp
__int64 v11; // r13
const char *v12; // rdi
char *v13; // rax
const char *v14; // rdx
char *v15; // r12
char *v16; // rbp
const char *v17; // rcx

v5 = a2;
v6 = strlen(a1);
if ( a3 <= 0 )
return (char *)func0(1uLL);
v7 = v6;
v8 = (unsigned int)(a3 - 1);
v9 = a2;
v10 = 1;
v11 = (__int64)&a2[v8 + 1];
do
{
v12 = *v9++;
v10 += strlen(v12) + v7;
}
while ( v9 != (const char **)v11 );
v13 = (char *)func0(v10);
v14 = (const char *)&unk_1CA;
v15 = v13;
v16 = v13;
while ( 1 )
{
v17 = *v5++;
v16 += sprintf(v16, "%s%s", v14, v17);
if ( v5 == (const char **)v11 )
break;
v14 = a1;
}
return v15;
}

original_code:
char *join(const char *sep, char **vec, int n)
{
 const int len_sep = strlen(sep);
 int len = 1;
 for(int i = 0; i < n; i++)
  len += len_sep + strlen(vec[i]);
 char *p, *r = p = umalloc(len);
 const char *sep_actual = "";
 for(int i = 0; i < n; i++){
  p += sprintf(p, "%s%s", sep_actual, vec[i]);
  sep_actual = sep;
 }
 return r;
}

canonical_original_code:
char *join(char *sep, char **vec, int n)
{
 int len_sep = strlen(sep);
 int len = 1;
 for(int i = 0; i < n; i++)
  len += len_sep + strlen(vec[i]);
 char *p; char *r = p = umalloc(len);
 char *sep_actual = "";
 for(int i = 0; i < n; i++){
  p += sprintf(p, "%s%s", sep_actual, vec[i]);
  sep_actual = sep;
 }
 return r;
}

variable_types:
sep
char *

variable_types:
vec
char **

variable_types: n int

variable_types: len int

variable_types: i int

variable_types:
p
char *


ustrvprintf

decompiled_code:
void *__fastcall ustrvprintf(char *format, const __m128i *a2)
{
void *v2; // rbp
int v3; // ebx
__m128i v4; // xmm0
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

v2 = 0LL;
v3 = 8;
do
{
v3 *= 2;
v2 = urealloc(v2, v3);
v4 = _mm_loadu_si128(a2);
v7 = a2[1].m128i_i64[0];
arg = v4;
}
while ( v3 <= vsnprintf((char *)v2, v3, format, &arg) );
return v2;
}

canonical_decompiled_code:
void *__fastcall func4(char *format, const __m128i *a2)
{
void *v2; // rbp
int v3; // ebx
__m128i v4; // xmm0
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

v2 = 0LL;
v3 = 8;
do
{
v3 *= 2;
v2 = func1(v2, v3);
v4 = _mm_loadu_si128(a2);
v7 = a2[1].m128i_i64[0];
arg = v4;
}
while ( v3 <= vsnprintf((char *)v2, v3, format, &arg) );
return v2;
}

original_code:
char *ustrvprintf(const char *fmt, va_list l)
{
 char *buf = ((void *)0);
 int len = 8, ret;
 do{
  va_list lcp;
  len *= 2;
  buf = urealloc(buf, len);
  __builtin_va_copy(lcp,l);
  ret = vsnprintf(buf, len, fmt, lcp);
  __builtin_va_end(lcp);
 }while(ret >= len);
 return buf;
}

canonical_original_code:
char *ustrvprintf(char *fmt, __builtin_va_list l)
{
 char *buf = ((void *)0);
 int len = 8; int ret;
 do{
  __builtin_va_list lcp;
  len *= 2;
  buf = urealloc(buf, len);
  __builtin_va_copy(lcp,l);
  ret = vsnprintf(buf, len, fmt, lcp);
  __builtin_va_end(lcp);
 }while(ret >= len);
 return buf;
}

variable_types:
fmt
char *

variable_types:
buf
char *


decompiled_code:
void __fastcall tab_free(void *ptr)
{
if ( *(_QWORD *)ptr )
{
window_free();
*(_QWORD *)ptr = 0LL;
}
if ( ptr == (void *)tabs_first() )
tabs_set_first(*((_QWORD *)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( *(_QWORD *)ptr )
{
window_free();
*(_QWORD *)ptr = 0LL;
}
if ( ptr == (void *)tabs_first() )
tabs_set_first(*((_QWORD *)ptr + 1));
free(ptr);
}

original_code:
void tab_free(tab *t)
{
 if(t->win){
  window_free(t->win);
  t->win = ((void *)0);
 }
 if(t == tabs_first())
  tabs_set_first(t->next);
 free(t);
}

canonical_original_code:
void tab_free(struct tab *t)
{
 if(t->win){
  window_free(t->win);
  t->win = ((void *)0);
 }
 if(t == tabs_first())
  tabs_set_first(t->next);
 free(t);
}

variable_types: struct tab { struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *win; struct tab *next; } *

user_defined_types: struct tab { struct window *win; struct tab *next; }


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

for ( result = tabs_first(); ; result = *(_QWORD *)(result + 8) )
{
if ( !result )
{
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}
if ( *(_QWORD *)(result + 8) == a1 )
break;
}
*(_QWORD *)(result + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

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

for ( result = tabs_first(); ; result = *(_QWORD *)(result + 8) )
{
if ( !result )
{
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}
if ( *(_QWORD *)(result + 8) == a1 )
break;
}
*(_QWORD *)(result + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

original_code:
void tab_evict(tab *t)
{
 tab *i;
 for(i = tabs_first(); i; i = i->next){
  if(i->next == t){
   i->next = t->next;
   break;
  }
 }
 t->next = ((void *)0);
}

canonical_original_code:
void tab_evict(struct tab *t)
{
 struct tab *i;
 for(i = tabs_first(); i; i = i->next){
  if(i->next == t){
   i->next = t->next;
   break;
  }
 }
 t->next = ((void *)0);
}


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

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

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

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

original_code:
tab *tab_next(tab *t)
{
 return t->next ? t->next : tabs_first();
}

canonical_original_code:
struct tab *tab_next(struct tab *t)
{
 return t->next ? t->next : tabs_first();
}

variable_types:
t
struct tab *

return_type: struct tab { struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *win; struct tab *next; } *


decompiled_code:
char *__fastcall paren_lookup(unsigned __int8 a1)
{
char *result; // rax

result = (char *)&parens;
if ( a1 <= 0x7Du )
result = (char *)&parens + 2 * a1;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 a1)
{
char *result; // rax

result = (char *)&parens;
if ( a1 <= 0x7Du )
result = (char *)&parens + 2 * a1;
return result;
}

original_code:
static const struct paren *paren_lookup(char c)
{
 unsigned char u = c;
 if(u >= sizeof parens / sizeof *parens)
  return &parens[0];
 return &parens[u];
}

canonical_original_code:
static struct paren *paren_lookup(char c)
{
 unsigned char u = c;
 if(u >= sizeof parens / sizeof *parens)
  return &parens[0];
 return &parens[u];
}

variable_types: c char

variable_types:
u
unsigned char

return_type: struct paren { char opp; _Bool lead; } *


decompiled_code:
char *__fastcall strchr_rev(char *a1, int a2, char *a3)
{
int v3; // eax

if ( a2 == *a1 )
return a1;
if ( a1 != a3 )
{
while ( 1 )
{
v3 = *--a1;
if ( v3 == a2 )
break;
if ( a3 == a1 )
return 0LL;
}
return a1;
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, int a2, char *a3)
{
int v3; // eax

if ( a2 == *a1 )
return a1;
if ( a1 != a3 )
{
while ( 1 )
{
v3 = *--a1;
if ( v3 == a2 )
break;
if ( a3 == a1 )
return 0LL;
}
return a1;
}
return 0LL;
}

original_code:
char *strchr_rev(const char *s, int ch, const char *start)
{
 while(*s != ch){
  if(s == start)
   return ((void *)0);
  s--;
 }
 return (char *)s;
}

canonical_original_code:
char *strchr_rev(char *s, int ch, char *start)
{
 while(*s != ch){
  if(s == start)
   return ((void *)0);
  s--;
 }
 return (char *)s;
}

variable_types:
s
char *

variable_types: ch int

variable_types:
start
char *


decompiled_code:
const char *__fastcall tim_strrevstr(unsigned __int64 a1, unsigned int a2, const char *a3)
{
size_t v4; // rax
const char *v5; // r12
size_t v6; // r13

v4 = strlen(a3);
v5 = (const char *)(a1 + a2);
if ( __CFADD__(a1, a2) )
return 0LL;
v6 = v4;
while ( strncmp(v5, a3, v6) )
{
if ( a1 > (unsigned __int64)--v5 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned __int64 a1, unsigned int a2, const char *a3)
{
size_t v4; // rax
const char *v5; // r12
size_t v6; // r13

v4 = strlen(a3);
v5 = (const char *)(a1 + a2);
if ( __CFADD__(a1, a2) )
return 0LL;
v6 = v4;
while ( strncmp(v5, a3, v6) )
{
if ( a1 > (unsigned __int64)--v5 )
return 0LL;
}
return v5;
}

original_code:
char *tim_strrevstr(char *restrict haystack, unsigned off, const char *restrict needle)
{
 const size_t nlen = strlen(needle);
 for(char *p = haystack + off;
   p >= haystack;
   p--)
 {
  if(!strncmp(p, needle, nlen))
   return p;
 }
 return ((void *)0);
}

canonical_original_code:
char *tim_strrevstr(char *haystack, unsigned int off, char *needle)
{
 unsigned long nlen = strlen(needle);
 for(char *p = haystack + off;
   p >= haystack;
   p--)
 {
  if(!strncmp(p, needle, nlen))
   return p;
 }
 return ((void *)0);
}

variable_types:
haystack
char *

variable_types:
off
unsigned int

variable_types:
needle
char *

variable_types:
nlen
unsigned long


isallspace

decompiled_code:
__int64 __fastcall isallspace(char *a1, __int64 a2)
{
char *v2; // rsi
const unsigned __int16 *v3; // rdx

if ( !a2 )
return 1LL;
v2 = &a1[a2];
v3 = *_ctype_b_loc();
do
{
if ( (v3[*a1] & 0x2000) == 0 )
return 0LL;
++a1;
}
while ( v2 != a1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, __int64 a2)
{
char *v2; // rsi
const unsigned __int16 *v3; // rdx

if ( !a2 )
return 1LL;
v2 = &a1[a2];
v3 = *_ctype_b_loc();
do
{
if ( (v3[*a1] & 0x2000) == 0 )
return 0LL;
++a1;
}
while ( v2 != a1 );
return 1LL;
}

original_code:
_Bool isallspace(const char *s, size_t len)
{
 for(size_t i = 0; i < len; i++)
  if(!((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace))
   return 0;
 return 1;
}

canonical_original_code:
_Bool isallspace(char *s, unsigned long len)
{
 for(unsigned long i = 0; i < len; i++)
  if(!((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace))
   return 0;
 return 1;
}

variable_types:
len
unsigned long

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall isdigit_or_minus(char a1)
{
const unsigned __int16 **v1; // rax
int v2; // edx

v1 = _ctype_b_loc();
v2 = a1;
LOBYTE(v2) = a1 == 45;
return v2 | ((*v1)[a1] >> 11) & 1u;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
const unsigned __int16 **v1; // rax
int v2; // edx

v1 = _ctype_b_loc();
v2 = a1;
LOBYTE(v2) = a1 == 45;
return v2 | ((*v1)[a1] >> 11) & 1u;
}

original_code:
_Bool isdigit_or_minus(char c)
{
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) || c == '-';
}

canonical_original_code:
_Bool isdigit_or_minus(char c)
{
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) || c == '-';
}


skipspace

decompiled_code:
char *__fastcall skipspace(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

canonical_decompiled_code:
char *__fastcall func5(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

original_code:
char *skipspace(const char *in)
{
 for(; ((*__ctype_b_loc ())[(int) ((*in))] & (unsigned short int) _ISspace); in++);
 return (char *)in;
}

canonical_original_code:
char *skipspace(char *in)
{
 for(; ((*__ctype_b_loc ())[(int) ((*in))] & (unsigned short) _ISspace); in++);
 return (char *)in;
}

variable_types:
in
char *


decompiled_code:
bool __fastcall paren_match(unsigned __int8 a1, char *a2)
{
char v2; // al

v2 = *paren_lookup(a1);
*a2 = v2;
return v2 != 0;
}

canonical_decompiled_code:
bool __fastcall func6(unsigned __int8 a1, char *a2)
{
char v2; // al

v2 = *func0(a1);
*a2 = v2;
return v2 != 0;
}

original_code:
_Bool paren_match(char c, char *other)
{
 return (*other = paren_lookup(c)->opp);
}

variable_types:
other
char *


decompiled_code:
__int64 __fastcall paren_left(unsigned __int8 a1)
{
return (unsigned __int8)paren_lookup(a1)[1];
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 a1)
{
return (unsigned __int8)func0(a1)[1];
}

original_code:
_Bool paren_left(char c)
{
 return paren_lookup(c)->lead;
}


decompiled_code:
__int64 __fastcall paren_opposite(unsigned __int8 a1)
{
return (unsigned __int8)*paren_lookup(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1)
{
return (unsigned __int8)*func0(a1);
}

original_code:
char paren_opposite(char c)
{
 return paren_lookup(c)->opp;
}

return_type: char


decompiled_code:
void __fastcall str_ltrim(void *dest, size_t *a2)
{
size_t v2; // rbx
__int64 v4; // rsi
const unsigned __int16 *v5; // rdx
size_t v6; // rbx

v2 = *a2;
if ( *a2 )
{
v4 = 0LL;
v5 = *_ctype_b_loc();
while ( (v5[*((char *)dest + v4)] & 0x2000) != 0 )
{
if ( v2 == ++v4 )
goto LABEL_7;
}
if ( !v4 )
return;
LABEL_7:
v6 = v2 - v4;
*a2 = v6;
memmove(dest, (char *)dest + v4, v6);
}
}

canonical_decompiled_code:
void __fastcall func9(void *dest, size_t *a2)
{
size_t v2; // rbx
__int64 v4; // rsi
const unsigned __int16 *v5; // rdx
size_t v6; // rbx

v2 = *a2;
if ( *a2 )
{
v4 = 0LL;
v5 = *_ctype_b_loc();
while ( (v5[*((char *)dest + v4)] & 0x2000) != 0 )
{
if ( v2 == ++v4 )
goto LABEL_7;
}
if ( !v4 )
return;
LABEL_7:
v6 = v2 - v4;
*a2 = v6;
memmove(dest, (char *)dest + v4, v6);
}
}

original_code:
void str_ltrim(char *s, size_t *pl)
{
 size_t i;
 for(i = 0; i < *pl && ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace); i++);
 if(i)
  memmove(s, s + i, *pl -= i);
}

canonical_original_code:
void str_ltrim(char *s, unsigned long *pl)
{
 unsigned long i;
 for(i = 0; i < *pl && ((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace); i++);
 if(i)
  memmove(s, s + i, *pl -= i);
}

variable_types:
pl
unsigned long *


decompiled_code:
char *__fastcall expand_tilde(_BYTE *a1)
{
const char *v1; // rbp
const unsigned __int16 **v2; // rax
const unsigned __int16 *v3; // rdx
unsigned __int16 v4; // ax
char *v5; // rax
char *v6; // r13
size_t v7; // rbx
size_t v8; // rax
size_t v9; // r15
size_t v10; // r14
char *v11; // r12
__int64 v12; // rax

if ( *a1 != 126 )
return 0LL;
v1 = a1 + 1;
v2 = _ctype_b_loc();
v3 = *v2;
v4 = (*v2)[(char)a1[1]];
if ( (v4 & 0x400) != 0 )
{
if ( (v4 & 8) != 0 )
{
do
v12 = *++v1;
while ( (v3[v12] & 8) != 0 );
}
return 0LL;
}
v5 = getenv("HOME");
v6 = v5;
if ( !v5 )
return 0LL;
v7 = strlen(v5);
v8 = strlen(v1);
v9 = v7 + v8;
v10 = v8;
v11 = (char *)umalloc(v7 + v8 + 1);
memcpy(v11, v6, v7);
memcpy(&v11[v7], v1, v10);
v11[v9] = 0;
return v11;
}

canonical_decompiled_code:
char *__fastcall func11(_BYTE *a1)
{
const char *v1; // rbp
const unsigned __int16 **v2; // rax
const unsigned __int16 *v3; // rdx
unsigned __int16 v4; // ax
char *v5; // rax
char *v6; // r13
size_t v7; // rbx
size_t v8; // rax
size_t v9; // r15
size_t v10; // r14
char *v11; // r12
__int64 v12; // rax

if ( *a1 != 126 )
return 0LL;
v1 = a1 + 1;
v2 = _ctype_b_loc();
v3 = *v2;
v4 = (*v2)[(char)a1[1]];
if ( (v4 & 0x400) != 0 )
{
if ( (v4 & 8) != 0 )
{
do
v12 = *++v1;
while ( (v3[v12] & 8) != 0 );
}
return 0LL;
}
v5 = getenv("HOME");
v6 = v5;
if ( !v5 )
return 0LL;
v7 = strlen(v5);
v8 = strlen(v1);
v9 = v7 + v8;
v10 = v8;
v11 = (char *)umalloc(v7 + v8 + 1);
memcpy(v11, v6, v7);
memcpy(&v11[v7], v1, v10);
v11[v9] = 0;
return v11;
}

original_code:
char *expand_tilde(const char *in)
{
 if(*in != '~')
  return ((void *)0);
 const char *user = in + 1;
 if(((*__ctype_b_loc ())[(int) ((*user))] & (unsigned short int) _ISalpha)){
  const char *user_end;
  for(user_end = user; ((*__ctype_b_loc ())[(int) ((*user_end))] & (unsigned short int) _ISalnum); user_end++);
  return ((void *)0);
 }else{
  const char *home = getenv("HOME");
  if(!home)
   return ((void *)0);
  size_t homelen = strlen(home);
  size_t userlen = strlen(user);
  size_t len = homelen + userlen + 1;
  char *ret = umalloc(len);
  memcpy(ret, home, homelen);
  memcpy(ret + homelen, user, userlen);
  ret[homelen + userlen] = '\0';
  return ret;
 }
}

canonical_original_code:
char *expand_tilde(char *in)
{
 if(*in != '~')
  return ((void *)0);
 char *user = in + 1;
 if(((*__ctype_b_loc ())[(int) ((*user))] & (unsigned short) _ISalpha)){
  char *user_end;
  for(user_end = user; ((*__ctype_b_loc ())[(int) ((*user_end))] & (unsigned short) _ISalnum); user_end++);
  return ((void *)0);
 }else{
  char *home = getenv("HOME");
  if(!home)
   return ((void *)0);
  unsigned long homelen = strlen(home);
  unsigned long userlen = strlen(user);
  unsigned long len = homelen + userlen + 1;
  char *ret = umalloc(len);
  memcpy(ret, home, homelen);
  memcpy(ret + homelen, user, userlen);
  ret[homelen + userlen] = '\0';
  return ret;
 }
}

variable_types:
user
char *

variable_types:
home
char *

variable_types:
homelen
unsigned long

variable_types:
userlen
unsigned long

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall load_argv(void (__fastcall *a1)(__int64, __int64))
{
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
char v7[32]; // [rsp+8h] [rbp-20h] BYREF

v2 = windows_cur();
while ( 1 )
{
result = args_next_fname(1LL);
if ( !result )
break;
buffer_new_fname(&v6, result, v7);
v3 = window_new(v6);
release_nochk(v6, &buffer_free);
v4 = v2;
v2 = v3;
a1(v4, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void (__fastcall *a1)(__int64, __int64))
{
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
char v7[32]; // [rsp+8h] [rbp-20h] BYREF

v2 = windows_cur();
while ( 1 )
{
result = args_next_fname(1LL);
if ( !result )
break;
buffer_new_fname(&v6, result, v7);
v3 = window_new(v6);
release_nochk(v6, &buffer_free);
v4 = v2;
v2 = v3;
a1(v4, v3);
}
return result;
}

original_code:
static void load_argv(void onload(window *cur, window *new))
{
 window *prev_win = windows_cur();
 char *next;
 while((next = args_next_fname(1))){
  buffer_t *buf;
  const char *err;
  buffer_new_fname(&buf, next, &err);
  window *w = window_new(buf);
  release_nochk((struct retain *)(buf), (void (*)(void *))buffer_free);
  onload(prev_win, w);
  prev_win = w;
 }
}

canonical_original_code:
static void load_argv(void onload(struct window *cur, struct window *new))
{
 struct window *prev_win = windows_cur();
 char *next;
 while((next = args_next_fname(1))){
  struct buffer *buf;
  char *err;
  buffer_new_fname(&buf, next, &err);
  struct window *w = window_new(buf);
  release_nochk((struct retain *)(buf), (void (*)(void *))buffer_free);
  onload(prev_win, w);
  prev_win = w;
 }
}

variable_types: void (struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *cur, struct window *new)

variable_types:
next
char *

variable_types:
err
char *


decompiled_code:
__int64 __fastcall win_add_splittop(__int64 a1, __int64 a2)
{
return window_add_neighbour(a1, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return window_add_neighbour(a1, 1LL, a2);
}

original_code:
static void win_add_splittop(window *cur, window *new)
{
 window_add_neighbour(cur, neighbour_down, new);
}

canonical_original_code:
static void win_add_splittop(struct window *cur, struct window *new)
{
 window_add_neighbour(cur, neighbour_down, new);
}

variable_types: struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *

variable_types:
new
struct window *


decompiled_code:
__int64 __fastcall win_add_splitright(__int64 a1, __int64 a2)
{
return window_add_neighbour(a1, 3LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return window_add_neighbour(a1, 3LL, a2);
}

original_code:
static void win_add_splitright(window *cur, window *new)
{
 window_add_neighbour(cur, neighbour_right, new);
}

canonical_original_code:
static void win_add_splitright(struct window *cur, struct window *new)
{
 window_add_neighbour(cur, neighbour_right, new);
}


decompiled_code:
__int64 tabs_cur()
{
return tab_sel;
}

canonical_decompiled_code:
__int64 func3()
{
return tab_sel;
}

original_code:
tab *tabs_cur()
{
 return tab_sel;
}

canonical_original_code:
struct tab *tabs_cur()
{
 return tab_sel;
}


decompiled_code:
void __fastcall tabs_set_cur(__int64 a1)
{
tab_sel = a1;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
tab_sel = a1;
}

original_code:
void tabs_set_cur(tab *new)
{
 tab_sel = new;
}

canonical_original_code:
void tabs_set_cur(struct tab *new)
{
 tab_sel = new;
}

variable_types: struct tab { struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *win; struct tab *next; } *


decompiled_code:
__int64 tabs_first()
{
return tab_first;
}

canonical_decompiled_code:
__int64 func5()
{
return tab_first;
}

original_code:
tab *tabs_first(void)
{
 return tab_first;
}

canonical_original_code:
struct tab *tabs_first()
{
 return tab_first;
}


decompiled_code:
void __fastcall tabs_set_first(__int64 a1)
{
tab_first = a1;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
tab_first = a1;
}

original_code:
void tabs_set_first(tab *t)
{
 tab_first = t;
}

canonical_original_code:
void tabs_set_first(struct tab *t)
{
 tab_first = t;
}


decompiled_code:
__int64 tabs_count()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = tabs_first();
for ( i = 0; v0; ++i )
v0 = *(_QWORD *)(v0 + 8);
return i;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = func5();
for ( i = 0; v0; ++i )
v0 = *(_QWORD *)(v0 + 8);
return i;
}

original_code:
unsigned tabs_count(void)
{
 unsigned n = 0;
 for(tab *t = tabs_first(); t; t = t->next, n++);
 return n;
}

canonical_original_code:
unsigned int tabs_count()
{
 unsigned int n = 0;
 for(struct tab *t = tabs_first(); t; t = t->next, n++);
 return n;
}

variable_types:
n
unsigned int


decompiled_code:
bool tabs_single()
{
return (unsigned int)tabs_count() == 1;
}

canonical_decompiled_code:
bool func8()
{
return (unsigned int)func7() == 1;
}

original_code:
_Bool tabs_single(void)
{
 return tabs_count() == 1;
}

canonical_original_code:
_Bool tabs_single()
{
 return tabs_count() == 1;
}


decompiled_code:
__int64 __fastcall tabs_init(int a1, int a2)
{
_BYTE *v3; // rax
_BYTE *v4; // rbp
__int64 v5; // rax
FILE *v6; // rdi
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rdi
__int64 result; // rax
__int64 v11; // rbp
__int64 v12; // r13
__int64 v13; // rdi
int *v14; // rax
char *v15; // [rsp+0h] [rbp-38h] BYREF
__int64 v16[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = (_BYTE *)args_next_fname(1LL);
if ( v3 )
{
v15 = 0LL;
v4 = v3;
if ( *v3 != 45 || v3[1] )
{
buffer_new_fname(v16, v3, &v15);
}
else
{
v5 = buffer_new_file_nofind(stdin);
v6 = stdin;
*(_BYTE *)(v5 + 57) = 1;
v16[0] = v5;
if ( ferror(v6) )
{
v14 = _errno_location();
v15 = strerror(*v14);
}
freopen("/dev/tty", "r", stdin);
}
if ( v15 )
ui_err("\"%s\": %s", v4);
v7 = window_new(v16[0]);
v8 = tab_new(v7);
release_nochk(v16[0], &buffer_free);
tabs_set_cur(v8);
if ( a1 == 1 )
{
load_argv((void (__fastcall *)(__int64, __int64))win_add_splitright);
}
else if ( a1 == 2 )
{
load_argv((void (__fastcall *)(__int64, __int64))win_add_splittop);
}
}
else
{
v11 = buffer_new();
v12 = window_new(v11);
release_nochk(v11, &buffer_free);
v13 = tab_new(v12);
tabs_set_cur(v13);
}
v9 = tabs_cur();
tabs_set_first(v9);
result = *(_QWORD *)(windows_cur() + 48);
*(_DWORD *)(result + 4) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
_BYTE *v3; // rax
_BYTE *v4; // rbp
__int64 v5; // rax
FILE *v6; // rdi
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rdi
__int64 result; // rax
__int64 v11; // rbp
__int64 v12; // r13
__int64 v13; // rdi
int *v14; // rax
char *v15; // [rsp+0h] [rbp-38h] BYREF
__int64 v16[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = (_BYTE *)args_next_fname(1LL);
if ( v3 )
{
v15 = 0LL;
v4 = v3;
if ( *v3 != 45 || v3[1] )
{
buffer_new_fname(v16, v3, &v15);
}
else
{
v5 = buffer_new_file_nofind(stdin);
v6 = stdin;
*(_BYTE *)(v5 + 57) = 1;
v16[0] = v5;
if ( ferror(v6) )
{
v14 = _errno_location();
v15 = strerror(*v14);
}
freopen("/dev/tty", "r", stdin);
}
if ( v15 )
ui_err("\"%s\": %s", v4);
v7 = window_new(v16[0]);
v8 = tab_new(v7);
release_nochk(v16[0], &buffer_free);
func4(v8);
if ( a1 == 1 )
{
func0((void (__fastcall *)(__int64, __int64))win_add_splitright);
}
else if ( a1 == 2 )
{
func0((void (__fastcall *)(__int64, __int64))win_add_splittop);
}
}
else
{
v11 = buffer_new();
v12 = window_new(v11);
release_nochk(v11, &buffer_free);
v13 = tab_new(v12);
func4(v13);
}
v9 = func3();
func6(v9);
result = *(_QWORD *)(windows_cur() + 48);
*(_DWORD *)(result + 4) = a2;
return result;
}

original_code:
void tabs_init(enum init_args init_args, unsigned off)
{
 char *next = args_next_fname(1);
 if(next){
  const char *err = ((void *)0);
  buffer_t *buf;
  if(!strcmp(next, "-")){
   buf = buffer_new_file_nofind(stdin);
   buf->modified = 1;
   if(ferror(stdin))
    err = strerror((*__errno_location ()));
   freopen("/dev/tty", "r", stdin);
  }else{
   buffer_new_fname(&buf, next, &err);
  }
  if(err)
   ui_err("\"%s\": %s", next, err);
  tab *tab = tab_new(window_new(buf));
  release_nochk((struct retain *)(buf), (void (*)(void *))buffer_free);
  tabs_set_cur(tab);
  switch(init_args){
   case INIT_NONE:
    break;
   case INIT_VALL:
    load_argv(win_add_splitright);
    break;
   case INIT_HALL:
    load_argv(win_add_splittop);
    break;
  }
 }else{
  buffer_t *empty = buffer_new();
  window *win = window_new(empty);
  release_nochk((struct retain *)(empty), (void (*)(void *))buffer_free);
  tab *tab = tab_new(win);
  tabs_set_cur(tab);
 }
 tabs_set_first(tabs_cur());
 windows_cur()->ui_pos->y = off;
}

canonical_original_code:
void tabs_init(enum init_args init_args, unsigned int off)
{
 char *next = args_next_fname(1);
 if(next){
  char *err = ((void *)0);
  struct buffer *buf;
  if(!strcmp(next, "-")){
   buf = buffer_new_file_nofind(stdin);
   buf->modified = 1;
   if(ferror(stdin))
    err = strerror((*__errno_location ()));
   freopen("/dev/tty", "r", stdin);
  }else{
   buffer_new_fname(&buf, next, &err);
  }
  if(err)
   ui_err("\"%s\": %s", next, err);
  struct tab *tab = tab_new(window_new(buf));
  release_nochk((struct retain *)(buf), (void (*)(void *))buffer_free);
  tabs_set_cur(tab);
  switch(init_args){
   case INIT_NONE:
    break;
   case INIT_VALL:
    load_argv(win_add_splitright);
    break;
   case INIT_HALL:
    load_argv(win_add_splittop);
    break;
  }
 }else{
  struct buffer *empty = buffer_new();
  struct window *win = window_new(empty);
  release_nochk((struct retain *)(empty), (void (*)(void *))buffer_free);
  struct tab *tab = tab_new(win);
  tabs_set_cur(tab);
 }
 tabs_set_first(tabs_cur());
 windows_cur()->ui_pos->y = off;
}

variable_types: enum init_args { INIT_NONE=0, INIT_VALL=1, INIT_HALL=2 }

variable_types:
off
unsigned int

variable_types: struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *


decompiled_code:
void tabs_term()
{
__int64 v0; // rax

v0 = tabs_cur();
if ( v0 )
{
tab_free(v0);
tabs_set_cur(0LL);
}
}

canonical_decompiled_code:
void func10()
{
__int64 v0; // rax

v0 = func3();
if ( v0 )
{
tab_free(v0);
func4(0LL);
}
}

original_code:
void tabs_term(void)
{
 if(tabs_cur()){
  tab_free(tabs_cur());
  tabs_set_cur(((void *)0));
 }
}

canonical_original_code:
void tabs_term()
{
 if(tabs_cur()){
  tab_free(tabs_cur());
  tabs_set_cur(((void *)0));
 }
}


decompiled_code:
const char **__fastcall add_argv(__int64 *a1, int *a2, const char **a3, const char *a4, char a5)
{
const char *v6; // r12
__int64 v7; // rax
__int64 v8; // rdx
const char *v9; // rdi
int v10; // er12
const char **result; // rax
int v12; // er15
char **v13; // r13
__int64 v14; // rax
__int64 v15; // rcx
char *v16; // rdi
__int64 v17; // r15
int v18; // eax
glob_t pglob; // [rsp+10h] [rbp-88h] BYREF

pglob.gl_stat = 0LL;
*(_OWORD *)&pglob.gl_pathc = 0LL;
*(_OWORD *)&pglob.gl_offs = 0LL;
*(_OWORD *)&pglob.gl_closedir = 0LL;
*(_OWORD *)&pglob.gl_opendir = 0LL;
if ( !a5 || glob(*a3, 2, 0LL, &pglob) )
{
v6 = *a3;
v7 = urealloc(*a1, 8LL * (*a2 + 2));
v8 = *a2;
v9 = v6;
v10 = 1;
*a1 = v7;
*(_QWORD *)(v7 + 8 * v8) = ustrdup(v9);
}
else
{
v12 = pglob.gl_pathc;
v13 = pglob.gl_pathv;
v10 = pglob.gl_pathc;
v14 = urealloc(*a1, 8LL * (LODWORD(pglob.gl_pathc) + *a2 + 1));
*a1 = v14;
v15 = v14;
if ( v12 > 0 )
{
v16 = *v13;
v17 = 0LL;
while ( 1 )
{
v18 = v17++ + *a2;
*(_QWORD *)(v15 + 8LL * v18) = ustrdup(v16);
if ( v10 <= (int)v17 )
break;
v16 = v13[v17];
v15 = *a1;
}
}
}
*a2 += v10;
globfree(&pglob);
result = a3;
*a3 = a4;
return result;
}

canonical_decompiled_code:
const char **__fastcall func0(__int64 *a1, int *a2, const char **a3, const char *a4, char a5)
{
const char *v6; // r12
__int64 v7; // rax
__int64 v8; // rdx
const char *v9; // rdi
int v10; // er12
const char **result; // rax
int v12; // er15
char **v13; // r13
__int64 v14; // rax
__int64 v15; // rcx
char *v16; // rdi
__int64 v17; // r15
int v18; // eax
glob_t pglob; // [rsp+10h] [rbp-88h] BYREF

pglob.gl_stat = 0LL;
*(_OWORD *)&pglob.gl_pathc = 0LL;
*(_OWORD *)&pglob.gl_offs = 0LL;
*(_OWORD *)&pglob.gl_closedir = 0LL;
*(_OWORD *)&pglob.gl_opendir = 0LL;
if ( !a5 || glob(*a3, 2, 0LL, &pglob) )
{
v6 = *a3;
v7 = urealloc(*a1, 8LL * (*a2 + 2));
v8 = *a2;
v9 = v6;
v10 = 1;
*a1 = v7;
*(_QWORD *)(v7 + 8 * v8) = ustrdup(v9);
}
else
{
v12 = pglob.gl_pathc;
v13 = pglob.gl_pathv;
v10 = pglob.gl_pathc;
v14 = urealloc(*a1, 8LL * (LODWORD(pglob.gl_pathc) + *a2 + 1));
*a1 = v14;
v15 = v14;
if ( v12 > 0 )
{
v16 = *v13;
v17 = 0LL;
while ( 1 )
{
v18 = v17++ + *a2;
*(_QWORD *)(v15 + 8LL * v18) = ustrdup(v16);
if ( v10 <= (int)v17 )
break;
v16 = v13[v17];
v15 = *a1;
}
}
}
*a2 += v10;
globfree(&pglob);
result = a3;
*a3 = a4;
return result;
}

original_code:
static void add_argv(
  char ***pargv, int *pargc,
  char **panchor, char *current,
  _Bool shellglob)
{
 char *failbuf;
 glob_t globbed = { 0 };
 int argc_inc;
 char **argv_add;
 int flags = (1 << 1) | 0 | 0;
 if(shellglob && 0 == glob((*panchor), flags, ((void *)0), &globbed)){
  argc_inc = globbed.gl_pathc;
  argv_add = globbed.gl_pathv;
 }else{
  argc_inc = 1;
  argv_add = &failbuf;
  failbuf = (*panchor);
 }
 (*pargv) = urealloc((*pargv), ((*pargc) + argc_inc + 1) * sizeof *(*pargv));
 for(int i = 0; i < argc_inc; i++)
  (*pargv)[(*pargc) + i] = ustrdup(argv_add[i]);
 (*pargc) += argc_inc;
 globfree(&globbed);
 (*panchor) = current;
}

canonical_original_code:
static void add_argv(char ***pargv, int *pargc, char **panchor, char *current, _Bool shellglob)
{
 char *failbuf;
 struct glob_t globbed = { 0 };
 int argc_inc;
 char **argv_add;
 int flags = (1 << 1) | 0 | 0;
 if(shellglob && 0 == glob((*panchor), flags, ((void *)0), &globbed)){
  argc_inc = globbed.gl_pathc;
  argv_add = globbed.gl_pathv;
 }else{
  argc_inc = 1;
  argv_add = &failbuf;
  failbuf = (*panchor);
 }
 (*pargv) = urealloc((*pargv), ((*pargc) + argc_inc + 1) * sizeof *(*pargv));
 for(int i = 0; i < argc_inc; i++)
  (*pargv)[(*pargc) + i] = ustrdup(argv_add[i]);
 (*pargc) += argc_inc;
 globfree(&globbed);
 (*panchor) = current;
}

variable_types:
pargv
char ***

variable_types:
pargc
int *

variable_types:
panchor
char **

variable_types:
current
char *

variable_types:
failbuf
char *

variable_types: struct glob_t { unsigned long gl_pathc; char **gl_pathv; unsigned long gl_offs; int gl_flags; void (*gl_closedir)(void *); void *(*gl_readdir)(void *); void *(*gl_opendir)(char *); int (*gl_lstat)(char *, void *); int (*gl_stat)(char *, void *); }

variable_types: flags int

variable_types: i int


decompiled_code:
__int64 __fastcall parse_cmd(const char *a1, _DWORD *a2, __int64 *a3, char a4)
{
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // rbx
const char *v8; // r15
char v9; // r14
unsigned int v11; // [rsp+Ch] [rbp-4Ch] BYREF
__int64 v12; // [rsp+10h] [rbp-48h] BYREF
const char *v13[8]; // [rsp+18h] [rbp-40h] BYREF

result = (unsigned int)*a2;
v6 = *a3;
v7 = *a1;
v13[0] = a1;
v11 = result;
v12 = v6;
if ( (_BYTE)v7 )
{
v8 = a1;
v9 = a4;
do
{
++v8;
if ( (_BYTE)v7 != 92 && ((*_ctype_b_loc())[v7] & 0x2000) != 0 )
{
*((_BYTE *)v8 - 1) = 0;
add_argv(&v12, (int *)&v11, v13, v8, a4);
}
v7 = *v8;
}
while ( (_BYTE)v7 );
if ( v13[0] != v8 )
add_argv(&v12, (int *)&v11, v13, v8, v9);
v6 = v12;
result = v11;
}
*a3 = v6;
*a2 = result;
return result;
}

original_code:
void parse_cmd(char *cmd, int *pargc, char ***pargv, _Bool shellglob)
{
 int argc = *pargc;
 char **argv = *pargv;
 char *anchor, *p;
 p = anchor = cmd;
 while(*p){
  if(*p == '\\'){
   p++;
   continue;
  }
  if(!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace)){
   p++;
   continue;
  }
  *p++ = '\0';
  add_argv(&argv, &argc, &anchor, p, shellglob);
 }
 if(anchor != p)
  add_argv(&argv, &argc, &anchor, p, shellglob);
 *pargv = argv;
 *pargc = argc;
}

canonical_original_code:
void parse_cmd(char *cmd, int *pargc, char ***pargv, _Bool shellglob)
{
 int argc = *pargc;
 char **argv = *pargv;
 char *anchor; char *p;
 p = anchor = cmd;
 while(*p){
  if(*p == '\\'){
   p++;
   continue;
  }
  if(!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace)){
   p++;
   continue;
  }
  *p++ = '\0';
  add_argv(&argv, &argc, &anchor, p, shellglob);
 }
 if(anchor != p)
  add_argv(&argv, &argc, &anchor, p, shellglob);
 *pargv = argv;
 *pargc = argc;
}

variable_types:
cmd
char *

variable_types: argc int

variable_types:
argv
char **

variable_types:
anchor
char *

variable_types:
p
char *


original_code:
_Bool parse_ranged_cmd(
  char *cmd,
  const cmd_t **pcmd_f,
  char ***pargv, int *pargc,
  _Bool *pforce,
  struct range **prange)
{
 (*pargv) = ((void *)0);
 (*pargc) = 0;
 char *cmd_i = skipspace(cmd);
 if(!*cmd_i)
  return 0;
 switch(parse_range(cmd_i, &cmd_i, (*prange))){
  case RANGE_PARSE_FAIL:
   return 0;
  case RANGE_PARSE_NONE:
   (*prange) = ((void *)0);
  case RANGE_PARSE_PASS:
   break;
 }
 cmd_i = skipspace(cmd_i);
 (*pargc) = 1;
 (*pargv) = umalloc(((*pargc) + 1) * sizeof *(*pargv));
 if(((*__ctype_b_loc ())[(int) ((*cmd_i))] & (unsigned short int) _ISalpha)){
  char *p;
  for(p = cmd_i + 1; ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha); p++);
  (*pargv)[0] = ustrdup_len(cmd_i, p - cmd_i);
  cmd_i = p - 1;
 }else if(*cmd_i){
  (*pargv)[0] = ustrdup_len(cmd_i, 1);
 }else{
  return 0;
 }
 cmd_i++;
 (*pcmd_f) = ((void *)0);
 for(int i = 0; cmds[i].arg0; i++)
  if(!strcmp(cmds[i].arg0, (*pargv)[0])){
   (*pcmd_f) = &cmds[i];
   break;
  }
 if(!(*pcmd_f))
  return 0;
 (*pforce) = 0;
 if(*cmd_i == '!')
  (*pforce) = 1, cmd_i++;
 cmd_i = skipspace(cmd_i);
 if((*pcmd_f)->single_arg){
  (*pargv) = urealloc((*pargv), (++(*pargc) + 1) * sizeof *(*pargv));
  (*pargv)[1] = ustrdup(cmd_i);
 }else{
  parse_cmd(cmd_i, &(*pargc), &(*pargv), !(*pcmd_f)->skipglob);
 }
 (*pargv)[(*pargc)] = ((void *)0);
 filter_argv(&(*pargc), &(*pargv));
 return 1;
}

canonical_original_code:
_Bool parse_ranged_cmd(char *cmd, struct cmd_t **pcmd_f, char ***pargv, int *pargc, _Bool *pforce, struct range **prange)
{
 (*pargv) = ((void *)0);
 (*pargc) = 0;
 char *cmd_i = skipspace(cmd);
 if(!*cmd_i)
  return 0;
 switch(parse_range(cmd_i, &cmd_i, (*prange))){
  case RANGE_PARSE_FAIL:
   return 0;
  case RANGE_PARSE_NONE:
   (*prange) = ((void *)0);
  case RANGE_PARSE_PASS:
   break;
 }
 cmd_i = skipspace(cmd_i);
 (*pargc) = 1;
 (*pargv) = umalloc(((*pargc) + 1) * sizeof *(*pargv));
 if(((*__ctype_b_loc ())[(int) ((*cmd_i))] & (unsigned short) _ISalpha)){
  char *p;
  for(p = cmd_i + 1; ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha); p++);
  (*pargv)[0] = ustrdup_len(cmd_i, p - cmd_i);
  cmd_i = p - 1;
 }else if(*cmd_i){
  (*pargv)[0] = ustrdup_len(cmd_i, 1);
 }else{
  return 0;
 }
 cmd_i++;
 (*pcmd_f) = ((void *)0);
 for(int i = 0; cmds[i].arg0; i++)
  if(!strcmp(cmds[i].arg0, (*pargv)[0])){
   (*pcmd_f) = &cmds[i];
   break;
  }
 if(!(*pcmd_f))
  return 0;
 (*pforce) = 0;
 if(*cmd_i == '!')
  (*pforce) = 1, cmd_i++;
 cmd_i = skipspace(cmd_i);
 if((*pcmd_f)->single_arg){
  (*pargv) = urealloc((*pargv), (++(*pargc) + 1) * sizeof *(*pargv));
  (*pargv)[1] = ustrdup(cmd_i);
 }else{
  parse_cmd(cmd_i, &(*pargc), &(*pargv), !(*pcmd_f)->skipglob);
 }
 (*pargv)[(*pargc)] = ((void *)0);
 filter_argv(&(*pargc), &(*pargv));
 return 1;
}

variable_types: struct cmd_t { char *arg0; union { _Bool (*f_argv)(int argc, char **argv, _Bool force, struct range { int start; } *); _Bool (*f_arg1)(char *cmd, char *arg, _Bool force, struct range *); }; _Bool single_arg; _Bool inverse; _Bool skipglob; } **

variable_types:
pforce
_Bool *

variable_types:
prange
struct range **

user_defined_types: struct cmd_t { char *arg0; union { _Bool (*f_argv)(int argc, char **argv, _Bool force, struct range *); _Bool (*f_arg1)(char *cmd, char *arg, _Bool force, struct range *); }; _Bool single_arg; _Bool inverse; _Bool skipglob; }


decompiled_code:
void __fastcall free_argv(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
void free_argv(char **argv, int argc)
{
 for(int i = 0; i < argc; i++)
  free(argv[i]);
 free(argv);
}


decompiled_code:
__int64 __fastcall parse_range(char *a1, char **a2, _DWORD *a3)
{
char v4; // r8
__int64 result; // rax
_QWORD *v6; // rax

if ( *a1 == 37 )
{
*a3 = 0;
v6 = (_QWORD *)windows_cur();
a3[1] = buffer_nlines(*v6);
result = 2LL;
*a2 = a1 + 1;
}
else
{
v4 = parse_range_1(a1, a2, a3);
result = 0LL;
if ( v4 )
{
if ( **a2 == 44 )
{
result = 1 - ((unsigned int)((unsigned __int8)parse_range_1(*a2 + 1, a2, a3 + 1) == 0) - 1);
}
else
{
a3[1] = *a3;
result = 2LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, char **a2, _DWORD *a3)
{
char v4; // r8
__int64 result; // rax
_QWORD *v6; // rax

if ( *a1 == 37 )
{
*a3 = 0;
v6 = (_QWORD *)windows_cur();
a3[1] = buffer_nlines(*v6);
result = 2LL;
*a2 = a1 + 1;
}
else
{
v4 = func0(a1, a2, a3);
result = 0LL;
if ( v4 )
{
if ( **a2 == 44 )
{
result = 1 - ((unsigned int)((unsigned __int8)func0(*a2 + 1, a2, a3 + 1) == 0) - 1);
}
else
{
a3[1] = *a3;
result = 2LL;
}
}
}
return result;
}

original_code:
enum range_parse parse_range(
  char *cmd, char **end,
  struct range *r)
{
 if(*cmd == '%'){
  r->start = 0;
  r->end = buffer_nlines(windows_cur()->buf);
  *end = cmd + 1;
  return RANGE_PARSE_PASS;
 }
 if(!parse_range_1(cmd, end, &r->start))
  return RANGE_PARSE_NONE;
 cmd = *end;
 if(*cmd == ','){
  cmd++;
  if(!parse_range_1(cmd, end, &r->end))
   return RANGE_PARSE_FAIL;
 }else{
  r->end = r->start;
 }
 return RANGE_PARSE_PASS;
}

canonical_original_code:
enum range_parse parse_range(char *cmd, char **end, struct range *r)
{
 if(*cmd == '%'){
  r->start = 0;
  r->end = buffer_nlines(windows_cur()->buf);
  *end = cmd + 1;
  return RANGE_PARSE_PASS;
 }
 if(!parse_range_1(cmd, end, &r->start))
  return RANGE_PARSE_NONE;
 cmd = *end;
 if(*cmd == ','){
  cmd++;
  if(!parse_range_1(cmd, end, &r->end))
   return RANGE_PARSE_FAIL;
 }else{
  r->end = r->start;
 }
 return RANGE_PARSE_PASS;
}

variable_types:
end
char **

variable_types:
r
struct range { int start; } *

return_type: enum range_parse { RANGE_PARSE_NONE=0, RANGE_PARSE_FAIL=1, RANGE_PARSE_PASS=2 }


decompiled_code:
__int64 __fastcall range_sort(int *a1)
{
__int64 result; // rax
int v2; // edx

result = (unsigned int)*a1;
v2 = a1[1];
if ( (int)result > v2 )
{
*a1 = v2;
a1[1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1)
{
__int64 result; // rax
int v2; // edx

result = (unsigned int)*a1;
v2 = a1[1];
if ( (int)result > v2 )
{
*a1 = v2;
a1[1] = result;
}
return result;
}

original_code:
void range_sort(struct range *r)
{
 if(r->start > r->end){
  int tmp = r->start;
  r->start = r->end;
  r->end = tmp;
 }
}

variable_types: tmp int


decompiled_code:
__int64 __fastcall buffers_find(char *s2)
{
_QWORD *v2; // r13
__int64 v3; // rbp
_QWORD *v4; // r14
__int64 v5; // r12
const char *v6; // rdi

if ( !windows_cur() )
return 0LL;
v2 = (_QWORD *)tabs_first();
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = window_topleftmost(*v2);
if ( v3 )
break;
LABEL_9:
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
LABEL_4:
v4 = (_QWORD *)v3;
while ( 1 )
{
v5 = *v4;
v6 = (const char *)buffer_fname(*v4);
if ( v6 )
{
if ( !strcmp(v6, s2) )
return v5;
}
v4 = (_QWORD *)v4[11];
if ( !v4 )
{
v3 = *(_QWORD *)(v3 + 80);
if ( v3 )
goto LABEL_4;
goto LABEL_9;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
_QWORD *v2; // r13
__int64 v3; // rbp
_QWORD *v4; // r14
__int64 v5; // r12
const char *v6; // rdi

if ( !windows_cur() )
return 0LL;
v2 = (_QWORD *)tabs_first();
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = window_topleftmost(*v2);
if ( v3 )
break;
LABEL_9:
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
LABEL_4:
v4 = (_QWORD *)v3;
while ( 1 )
{
v5 = *v4;
v6 = (const char *)buffer_fname(*v4);
if ( v6 )
{
if ( !strcmp(v6, s2) )
return v5;
}
v4 = (_QWORD *)v4[11];
if ( !v4 )
{
v3 = *(_QWORD *)(v3 + 80);
if ( v3 )
goto LABEL_4;
goto LABEL_9;
}
}
}

original_code:
buffer_t *buffers_find(const char *fname)
{
 if(!windows_cur())
  return ((void *)0);
 for(tab *tab = tabs_first(); tab; tab = tab->next){
  window *win;
  win = window_topleftmost(tab->win); for(window *h = win; h; h = h->neighbours.right) for(win = h; win; win = win->neighbours.below){
   buffer_t *buf = win->buf;
   const char *thisfname = buffer_fname(buf);
   if(thisfname && !strcmp(thisfname, fname))
    return buf;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct buffer *buffers_find(char *fname)
{
 if(!windows_cur())
  return ((void *)0);
 for(struct tab *tab = tabs_first(); tab; tab = tab->next){
  struct window *win;
  win = window_topleftmost(tab->win); for(struct window *h = win; h; h = h->neighbours.right) for(win = h; win; win = win->neighbours.below){
   struct buffer *buf = win->buf;
   char *thisfname = buffer_fname(buf);
   if(thisfname && !strcmp(thisfname, fname))
    return buf;
  }
 }
 return ((void *)0);
}

variable_types:
fname
char *

variable_types: struct tab { struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *win; struct tab *next; } *

variable_types:
thisfname
char *


decompiled_code:
char __fastcall buffers_modified_single(__int64 a1)
{
char result; // al

result = *(_BYTE *)(a1 + 57);
if ( result )
result = (unsigned int)buffer_opencount() == 1;
return result;
}

canonical_decompiled_code:
char __fastcall func1(__int64 a1)
{
char result; // al

result = *(_BYTE *)(a1 + 57);
if ( result )
result = (unsigned int)buffer_opencount() == 1;
return result;
}

original_code:
_Bool buffers_modified_single(const buffer_t *b)
{
 return b->modified && buffer_opencount(b) == 1;
}

canonical_original_code:
_Bool buffers_modified_single(struct buffer *b)
{
 return b->modified && buffer_opencount(b) == 1;
}

variable_types: struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *


decompiled_code:
__int64 __fastcall args_next_fname(char a1)
{
__int64 v1; // r8

if ( !remaining_fnames )
return 0LL;
v1 = *(_QWORD *)remaining_fnames;
if ( *(_QWORD *)remaining_fnames )
{
if ( a1 )
remaining_fnames += 8LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 v1; // r8

if ( !remaining_fnames )
return 0LL;
v1 = *(_QWORD *)remaining_fnames;
if ( *(_QWORD *)remaining_fnames )
{
if ( a1 )
remaining_fnames += 8LL;
}
return v1;
}

original_code:
char *args_next_fname(_Bool pop)
{
 char *fname = remaining_fnames ? *remaining_fnames : ((void *)0);
 if(pop && fname)
  remaining_fnames++;
 return fname;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
const char **v5; // rbx
unsigned int v6; // er15
int v7; // er12
const char *v8; // rdi
const unsigned __int16 *v9; // rsi
char *i; // rax
__int64 v11; // rcx
int v12; // er12
unsigned int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v3 = argc;
v14[0] = 0;
if ( argc <= 1 )
{
v6 = 0;
v3 = 1LL;
goto LABEL_13;
}
v5 = argv + 1;
v6 = 0;
v7 = 1;
while ( 1 )
{
v8 = *v5;
if ( **v5 != 45 )
break;
if ( v8[1] != 79 || v8[2] )
{
if ( v8[1] != 111 || v8[2] )
break;
v6 = 2;
}
else
{
v6 = 1;
}
LABEL_12:
++v7;
++v5;
if ( (_DWORD)v3 == v7 )
goto LABEL_13;
}
if ( *v8 == 43 )
{
v9 = *_ctype_b_loc();
for ( i = (char *)(v8 + 1); ; ++i )
{
v11 = *i;
if ( (v9[v11] & 0x800) == 0 )
break;
}
if ( !(_BYTE)v11 && (unsigned int)_isoc99_sscanf(v8 + 1, &unk_40, v14) == 1 )
{
if ( v14[0] )
--v14[0];
goto LABEL_12;
}
}
v3 = v7;
LABEL_13:
remaining_fnames = (__int64)&argv[v3];
ui_init();
tabs_init(v6, v14[0]);
v12 = ui_main();
ui_term();
tabs_term();
return v12;
}

original_code:
int main(int argc, char **argv)
{
 int i;
 unsigned offset = 0;
 enum init_args initargs = INIT_NONE;
 for(i = 1; i < argc; i++){
  if(!strcmp(argv[i], "-O")){
   initargs = INIT_VALL;
  }else if(!strcmp(argv[i], "-o")){
   initargs = INIT_HALL;
  }else if(*argv[i] == '+'){
   char *p = argv[i] + 1;
   while(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit))
    p++;
   if(*p == '\0' && sscanf(argv[i]+1, "%u", &offset) == 1){
    if(offset > 0)
     offset--;
   }else{
    break;
   }
  }else{
   break;
  }
 }
 remaining_fnames = argv + i;
 ui_init();
 tabs_init(initargs, offset);
 int r = ui_main();
 ui_term();
 tabs_term();
 return r;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 unsigned int offset = 0;
 enum init_args initargs = INIT_NONE;
 for(i = 1; i < argc; i++){
  if(!strcmp(argv[i], "-O")){
   initargs = INIT_VALL;
  }else if(!strcmp(argv[i], "-o")){
   initargs = INIT_HALL;
  }else if(*argv[i] == '+'){
   char *p = argv[i] + 1;
   while(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit))
    p++;
   if(*p == '\0' && sscanf(argv[i]+1, "%u", &offset) == 1){
    if(offset > 0)
     offset--;
   }else{
    break;
   }
  }else{
   break;
  }
 }
 remaining_fnames = argv + i;
 ui_init();
 tabs_init(initargs, offset);
 int r = ui_main();
 ui_term();
 tabs_term();
 return r;
}

variable_types:
offset
unsigned int

variable_types: enum init_args { INIT_NONE=0, INIT_VALL=1, INIT_HALL=2 }

variable_types: r int


decompiled_code:
__int64 __fastcall word_state(_QWORD *a1, int a2, char a3)
{
__int64 result; // rax
char v5; // bp
unsigned __int16 v6; // dx

if ( !a1 || a2 < 0 )
return 0LL;
result = 0LL;
if ( (unsigned __int64)a2 < a1[1] )
{
v5 = *(_BYTE *)(*a1 + a2);
v6 = (*_ctype_b_loc())[v5];
result = 1LL;
if ( (v6 & 0x2000) == 0 )
{
result = 2LL;
if ( !a3 )
{
if ( (v6 & 8) != 0 || (result = 4LL, v5 == 95) )
result = 2LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2, char a3)
{
__int64 result; // rax
char v5; // bp
unsigned __int16 v6; // dx

if ( !a1 || a2 < 0 )
return 0LL;
result = 0LL;
if ( (unsigned __int64)a2 < a1[1] )
{
v5 = *(_BYTE *)(*a1 + a2);
v6 = (*_ctype_b_loc())[v5];
result = 1LL;
if ( (v6 & 0x2000) == 0 )
{
result = 2LL;
if ( !a3 )
{
if ( (v6 & 8) != 0 || (result = 4LL, v5 == 95) )
result = 2LL;
}
}
}
return result;
}

original_code:
enum word_state word_state(
  const list_t *l, int x, _Bool big_words)
{
 if(l && 0 <= x && (unsigned)x < l->len_line){
  const char ch = l->line[x];
  if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISspace))
   return W_SPACE;
  else if(big_words)
   return W_KEYWORD;
  else if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalnum) || ch == '_')
   return W_KEYWORD;
  return W_NON_KWORD;
 }
 return W_NONE;
}

canonical_original_code:
enum word_state word_state(struct list_ *l, int x, _Bool big_words)
{
 if(l && 0 <= x && (unsigned int)x < l->len_line){
  char ch = l->line[x];
  if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISspace))
   return W_SPACE;
  else if(big_words)
   return W_KEYWORD;
  else if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalnum) || ch == '_')
   return W_KEYWORD;
  return W_NON_KWORD;
 }
 return W_NONE;
}

variable_types: struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *

variable_types: x int

variable_types: ch char

return_type: enum word_state { W_NONE=0, W_SPACE=expr, W_KEYWORD=expr, W_NON_KWORD=expr }


decompiled_code:
__int64 __fastcall word_seek_to_end(_QWORD *a1, int a2, int *a3, char a4)
{
int v6; // er12
__int64 result; // rax
int v8; // ebx
int v9; // [rsp+Ch] [rbp-3Ch]

v6 = a2 + *a3;
result = word_state(a1, *a3, a4);
v9 = result;
if ( (_DWORD)result )
{
while ( 1 )
{
v8 = v6;
result = word_state(a1, v6, a4);
v6 += a2;
if ( (_DWORD)result != v9 )
break;
*a3 = v8;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2, int *a3, char a4)
{
int v6; // er12
__int64 result; // rax
int v8; // ebx
int v9; // [rsp+Ch] [rbp-3Ch]

v6 = a2 + *a3;
result = func0(a1, *a3, a4);
v9 = result;
if ( (_DWORD)result )
{
while ( 1 )
{
v8 = v6;
result = func0(a1, v6, a4);
v6 += a2;
if ( (_DWORD)result != v9 )
break;
*a3 = v8;
}
}
return result;
}

original_code:
void word_seek_to_end(list_t *l, int dir, point_t *to, _Bool big_words)
{
 const enum word_state st = word_state(l, to->x, big_words);
 if(st != W_NONE)
  while(word_state(l, to->x + dir, big_words) == st)
   to->x += dir;
}

canonical_original_code:
void word_seek_to_end(struct list_ *l, int dir, struct point *to, _Bool big_words)
{
 enum word_state st = word_state(l, to->x, big_words);
 if(st != W_NONE)
  while(word_state(l, to->x + dir, big_words) == st)
   to->x += dir;
}

variable_types: dir int

variable_types:
to
struct point { int x; } *

variable_types: enum word_state { W_NONE=0, W_SPACE=expr, W_KEYWORD=expr, W_NON_KWORD=expr }


decompiled_code:
_QWORD *windows_cur()
{
_QWORD *result; // rax

result = (_QWORD *)tabs_cur();
if ( result )
result = (_QWORD *)*result;
return result;
}

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

result = (_QWORD *)tabs_cur();
if ( result )
result = (_QWORD *)*result;
return result;
}

original_code:
window *windows_cur()
{
 tab *t = tabs_cur();
 return t ? t->win : ((void *)0);
}

canonical_original_code:
struct window *windows_cur()
{
 struct tab *t = tabs_cur();
 return t ? t->win : ((void *)0);
}


decompiled_code:
__int64 __fastcall windows_set_cur(__int64 a1)
{
__int64 v1; // rax

v1 = tabs_cur();
return tab_set_focus(v1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax

v1 = tabs_cur();
return tab_set_focus(v1, a1);
}

original_code:
void windows_set_cur(window *new)
{
 tab_set_focus(tabs_cur(), new);
}

canonical_original_code:
void windows_set_cur(struct window *new)
{
 tab_set_focus(tabs_cur(), new);
}

variable_types: struct window { struct buffer { struct retain { int rcount; } retains; struct list_ { char *line; unsigned long len_line; struct list_ *next; int flag; } *head; struct { struct point { int x; } npos; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } mode; } prev_visual; struct point prev_insert; char *fname; _Bool eol; _Bool modified; long mtime; unsigned int col_insert_height; } *buf; struct point ui_start; struct rect { int x; } screen_coord; struct point ui_npos; struct point ui_vpos; struct point *ui_pos; struct point ui_paren; enum buf_mode { UI_NORMAL=expr, UI_INSERT=expr, UI_INSERT_COL=expr, UI_VISUAL_CHAR=expr, UI_VISUAL_COL=expr, UI_VISUAL_LN=expr } ui_mode; struct { struct window *left; } neighbours; } *


decompiled_code:
int shellout_wait_ret()
{
int result; // eax

fwrite("enter to continue...", 1uLL, 0x14uLL, stderr);
do
result = getchar();
while ( result != -1 && result != 10 );
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

fwrite("enter to continue...", 1uLL, 0x14uLL, stderr);
do
result = getchar();
while ( result != -1 && result != 10 );
return result;
}

original_code:
void shellout_wait_ret(void)
{
  fprintf(stderr, "enter to continue...");
  for(;;){
   int c = getchar();
   if(c == (-1) || c == '\n')
    break;
  }
}

canonical_original_code:
void shellout_wait_ret()
{
  fprintf(stderr, "enter to continue...");
  for(;;){
   int c = getchar();
   if(c == (-1) || c == '\n')
    break;
  }
}

variable_types: c int


shellout

decompiled_code:
__int64 __fastcall shellout(char *command)
{
char *v1; // rbp
unsigned int v2; // er12

v1 = command;
if ( !command )
{
v1 = getenv("SHELL");
if ( !v1 )
v1 = "sh";
}
ui_term();
v2 = system(v1);
shellout_wait_ret();
ui_init();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *command)
{
char *v1; // rbp
unsigned int v2; // er12

v1 = command;
if ( !command )
{
v1 = getenv("SHELL");
if ( !v1 )
v1 = "sh";
}
ui_term();
v2 = system(v1);
func0();
ui_init();
return v2;
}

original_code:
int shellout(const char *cmd)
{
 const char *shcmd;
 int r;
 if(cmd){
  shcmd = cmd;
 }else{
  const char *shell = getenv("SHELL");
  if(!shell)
   shell = "sh";
  shcmd = shell;
 }
 ui_term();
 r = system(shcmd);
 shellout_wait_ret();
 ui_init();
 return r;
}

canonical_original_code:
int shellout(char *cmd)
{
 char *shcmd;
 int r;
 if(cmd){
  shcmd = cmd;
 }else{
  char *shell = getenv("SHELL");
  if(!shell)
   shell = "sh";
  shcmd = shell;
 }
 ui_term();
 r = system(shcmd);
 shellout_wait_ret();
 ui_init();
 return r;
}

variable_types:
cmd
char *

variable_types:
shcmd
char *

variable_types:
shell
char *


original_code:
_Bool region_contains(const region_t *re, int x, int y)
{
 region_t sorted = *re;
 point_sort_full(&sorted.begin, &sorted.end);
 const struct
 {
  _Bool x, y;
 } in = {
  sorted.begin.x <= x && x <= sorted.end.x,
  sorted.begin.y <= y && y <= sorted.end.y
 };
 switch(re->type){
  case REGION_LINE:
   return in.y;
  case REGION_COL:
   return in.y && in.x;
  case REGION_CHAR:
   if(!in.y)
    return 0;
   if(re->begin.y == re->end.y)
    return in.x;
   sorted = *re;
   point_sort_y(&sorted.begin, &sorted.end);
   if(y == sorted.begin.y)
    return x >= sorted.begin.x;
   if(y == sorted.end.y)
    return x <= sorted.end.x;
   return 1;
 }
 return 0;
}

canonical_original_code:
_Bool region_contains(struct region *re, int x, int y)
{
 struct region sorted = *re;
 point_sort_full(&sorted.begin, &sorted.end);
 struct { _Bool x; } in = {
  sorted.begin.x <= x && x <= sorted.end.x,
  sorted.begin.y <= y && y <= sorted.end.y
 };
 switch(re->type){
  case REGION_LINE:
   return in.y;
  case REGION_COL:
   return in.y && in.x;
  case REGION_CHAR:
   if(!in.y)
    return 0;
   if(re->begin.y == re->end.y)
    return in.x;
   sorted = *re;
   point_sort_y(&sorted.begin, &sorted.end);
   if(y == sorted.begin.y)
    return x >= sorted.begin.x;
   if(y == sorted.end.y)
    return x <= sorted.end.x;
   return 1;
 }
 return 0;
}

variable_types: struct region { struct point { int x; } begin; enum region_type { REGION_CHAR=0, REGION_COL=1, REGION_LINE=2 } type; } *

variable_types: y int

variable_types:
in
struct { _Bool x; }

user_defined_types: struct region { struct point begin; enum region_type type; }