decompiled_code:
__int64 __fastcall layout_set_main_v(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // esi
unsigned int v3; // ecx
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er13
unsigned int v7; // ebx
int v8; // eax
__int64 v9; // rdx
unsigned int v10; // ebx
int v11; // er12
unsigned int v12; // er15
unsigned int v13; // ebx
unsigned int v14; // ebx
__int64 v15; // rax
__int64 v16; // r14
__int64 v17; // r12
__int64 *v18; // rax
__int64 v19; // rax
__int64 i; // r15
__int64 v21; // r12
__int64 *v22; // rax
__int64 v23; // r13
int j; // er12
__int64 v25; // r14
__int64 *v26; // rax
unsigned int v27; // er11
unsigned int v28; // edx
unsigned int v29; // er11
unsigned int v30; // edx
unsigned int v31; // [rsp+10h] [rbp-58h]
int v32; // [rsp+14h] [rbp-54h]
int v33; // [rsp+14h] [rbp-54h]
unsigned int v34; // [rsp+18h] [rbp-50h]
int v35; // [rsp+1Ch] [rbp-4Ch]
__int64 v36; // [rsp+20h] [rbp-48h]
unsigned int v37; // [rsp+28h] [rbp-40h]
int v38; // [rsp+2Ch] [rbp-3Ch]

layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_main_v", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v2 = *(_DWORD *)(a1 + 180);
v3 = 1;
if ( v2 > 2 )
v3 = v2 / 3;
v4 = result - 2;
v5 = ((int)result - 2) / v3;
v6 = v5 + 1;
v37 = v5;
v7 = v4 / (v5 + 1) + 1;
v31 = v4 / (v5 + 1);
v34 = v7;
v35 = v2 / v7;
v8 = options_get_number(a1 + 192, "main-pane-width", v2 % v7);
v9 = 3 * v6;
v10 = *(_DWORD *)(a1 + 176);
v11 = v8 + 1;
if ( (unsigned int)(v8 + 1) < 3 )
v11 = 3;
if ( v11 + (int)v9 - 1 > v10 )
{
if ( v10 >= (int)v9 + 2 )
{
v11 = v10 - (v9 - 1);
v12 = v10 - v9;
v13 = 3;
}
else
{
v12 = 3;
v13 = 3;
v11 = 4;
}
}
else
{
v12 = v11 - 1;
v9 = (v10 - v11) / v6 * v6;
v13 = (v10 - v11) / v6;
}
v32 = v9;
v14 = v13 - 1;
layout_free(a1, "main-pane-width", v9);
v15 = layout_create_cell(0LL);
*(_QWORD *)(a1 + 168) = v15;
v16 = v15;
v36 = v15;
v38 = v11 + v32;
layout_set_size(v15, (unsigned int)(v11 + v32), *(unsigned int *)(a1 + 180), 0LL, 0LL);
layout_make_node(v16, 0LL);
v17 = layout_create_cell(v16);
layout_set_size(v17, v12, *(unsigned int *)(a1 + 180), 0LL, 0LL);
layout_make_leaf(v17, *(_QWORD *)(a1 + 144));
v18 = *(__int64 **)(v16 + 48);
*(_QWORD *)(v17 + 56) = 0LL;
v33 = 0;
*(_QWORD *)(v17 + 64) = v18;
*v18 = v17;
v19 = *(_QWORD *)(a1 + 144);
*(_QWORD *)(v16 + 48) = v17 + 56;
for ( i = *(_QWORD *)(v19 + 456); i; ++v33 )
{
v21 = layout_create_cell(v36);
layout_set_size(v21, v14, *(unsigned int *)(a1 + 180), 0LL, 0LL);
v22 = *(__int64 **)(v36 + 48);
*(_QWORD *)(v21 + 56) = 0LL;
*(_QWORD *)(v21 + 64) = v22;
*v22 = v21;
*(_QWORD *)(v36 + 48) = v21 + 56;
if ( v34 == 1 )
{
layout_make_leaf(v21, i);
i = *(_QWORD *)(i + 456);
}
else
{
layout_make_node(v21, 1LL);
v23 = v21;
for ( j = 0; ; ++j )
{
v25 = layout_create_cell(v23);
layout_set_size(v25, v14, (unsigned int)(v35 - 1), 0LL, 0LL);
layout_make_leaf(v25, i);
v26 = *(__int64 **)(v23 + 48);
i = *(_QWORD *)(i + 456);
*(_QWORD *)(v25 + 56) = 0LL;
*(_QWORD *)(v25 + 64) = v26;
*v26 = v25;
*(_QWORD *)(v23 + 48) = v25 + 56;
if ( !i )
break;
if ( v31 == j )
goto LABEL_14;
}
if ( v34 == j )
{
LABEL_14:
v27 = v34;
goto LABEL_15;
}
v27 = j + 1;
LABEL_15:
v28 = *(_DWORD *)(a1 + 180);
v29 = v35 * v27 - 1;
if ( v28 > v29 )
layout_resize_adjust(**(_QWORD **)(v25 + 64), 1LL, v28 - v29);
}
if ( v37 == v33 )
break;
}
v30 = *(_DWORD *)(a1 + 176);
if ( v30 > v38 - 1 )
layout_resize_adjust(**(_QWORD **)(*(_QWORD *)(v36 + 48) + 8LL), 0LL, v30 - (v38 - 1));
layout_fix_offsets(v36);
layout_fix_panes(a1, *(unsigned int *)(a1 + 176), *(unsigned int *)(a1 + 180));
layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_main_v", 1LL);
result = server_redraw_window(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // esi
unsigned int v3; // ecx
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er13
unsigned int v7; // ebx
int v8; // eax
__int64 v9; // rdx
unsigned int v10; // ebx
int v11; // er12
unsigned int v12; // er15
unsigned int v13; // ebx
unsigned int v14; // ebx
__int64 v15; // rax
__int64 v16; // r14
__int64 v17; // r12
__int64 *v18; // rax
__int64 v19; // rax
__int64 i; // r15
__int64 v21; // r12
__int64 *v22; // rax
__int64 v23; // r13
int j; // er12
__int64 v25; // r14
__int64 *v26; // rax
unsigned int v27; // er11
unsigned int v28; // edx
unsigned int v29; // er11
unsigned int v30; // edx
unsigned int v31; // [rsp+10h] [rbp-58h]
int v32; // [rsp+14h] [rbp-54h]
int v33; // [rsp+14h] [rbp-54h]
unsigned int v34; // [rsp+18h] [rbp-50h]
int v35; // [rsp+1Ch] [rbp-4Ch]
__int64 v36; // [rsp+20h] [rbp-48h]
unsigned int v37; // [rsp+28h] [rbp-40h]
int v38; // [rsp+2Ch] [rbp-3Ch]

layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_main_v", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v2 = *(_DWORD *)(a1 + 180);
v3 = 1;
if ( v2 > 2 )
v3 = v2 / 3;
v4 = result - 2;
v5 = ((int)result - 2) / v3;
v6 = v5 + 1;
v37 = v5;
v7 = v4 / (v5 + 1) + 1;
v31 = v4 / (v5 + 1);
v34 = v7;
v35 = v2 / v7;
v8 = options_get_number(a1 + 192, "main-pane-width", v2 % v7);
v9 = 3 * v6;
v10 = *(_DWORD *)(a1 + 176);
v11 = v8 + 1;
if ( (unsigned int)(v8 + 1) < 3 )
v11 = 3;
if ( v11 + (int)v9 - 1 > v10 )
{
if ( v10 >= (int)v9 + 2 )
{
v11 = v10 - (v9 - 1);
v12 = v10 - v9;
v13 = 3;
}
else
{
v12 = 3;
v13 = 3;
v11 = 4;
}
}
else
{
v12 = v11 - 1;
v9 = (v10 - v11) / v6 * v6;
v13 = (v10 - v11) / v6;
}
v32 = v9;
v14 = v13 - 1;
layout_free(a1, "main-pane-width", v9);
v15 = layout_create_cell(0LL);
*(_QWORD *)(a1 + 168) = v15;
v16 = v15;
v36 = v15;
v38 = v11 + v32;
layout_set_size(v15, (unsigned int)(v11 + v32), *(unsigned int *)(a1 + 180), 0LL, 0LL);
layout_make_node(v16, 0LL);
v17 = layout_create_cell(v16);
layout_set_size(v17, v12, *(unsigned int *)(a1 + 180), 0LL, 0LL);
layout_make_leaf(v17, *(_QWORD *)(a1 + 144));
v18 = *(__int64 **)(v16 + 48);
*(_QWORD *)(v17 + 56) = 0LL;
v33 = 0;
*(_QWORD *)(v17 + 64) = v18;
*v18 = v17;
v19 = *(_QWORD *)(a1 + 144);
*(_QWORD *)(v16 + 48) = v17 + 56;
for ( i = *(_QWORD *)(v19 + 456); i; ++v33 )
{
v21 = layout_create_cell(v36);
layout_set_size(v21, v14, *(unsigned int *)(a1 + 180), 0LL, 0LL);
v22 = *(__int64 **)(v36 + 48);
*(_QWORD *)(v21 + 56) = 0LL;
*(_QWORD *)(v21 + 64) = v22;
*v22 = v21;
*(_QWORD *)(v36 + 48) = v21 + 56;
if ( v34 == 1 )
{
layout_make_leaf(v21, i);
i = *(_QWORD *)(i + 456);
}
else
{
layout_make_node(v21, 1LL);
v23 = v21;
for ( j = 0; ; ++j )
{
v25 = layout_create_cell(v23);
layout_set_size(v25, v14, (unsigned int)(v35 - 1), 0LL, 0LL);
layout_make_leaf(v25, i);
v26 = *(__int64 **)(v23 + 48);
i = *(_QWORD *)(i + 456);
*(_QWORD *)(v25 + 56) = 0LL;
*(_QWORD *)(v25 + 64) = v26;
*v26 = v25;
*(_QWORD *)(v23 + 48) = v25 + 56;
if ( !i )
break;
if ( v31 == j )
goto LABEL_14;
}
if ( v34 == j )
{
LABEL_14:
v27 = v34;
goto LABEL_15;
}
v27 = j + 1;
LABEL_15:
v28 = *(_DWORD *)(a1 + 180);
v29 = v35 * v27 - 1;
if ( v28 > v29 )
layout_resize_adjust(**(_QWORD **)(v25 + 64), 1LL, v28 - v29);
}
if ( v37 == v33 )
break;
}
v30 = *(_DWORD *)(a1 + 176);
if ( v30 > v38 - 1 )
layout_resize_adjust(**(_QWORD **)(*(_QWORD *)(v36 + 48) + 8LL), 0LL, v30 - (v38 - 1));
layout_fix_offsets(v36);
layout_fix_panes(a1, *(unsigned int *)(a1 + 176), *(unsigned int *)(a1 + 180));
layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_main_v", 1LL);
result = server_redraw_window(a1);
}
return result;
}

original_code:
void
layout_set_main_v(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc, *lcmain, *lccolumn, *lcchild;
 u_int n, mainwidth, width, height, used;
 u_int i, j, columns, rows, totalcolumns;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 n--;
 rows = w->sy / (2 + 1);
 columns = 1 + (n - 1) / rows;
 rows = 1 + (n - 1) / columns;
 height = w->sy / rows;
 mainwidth = options_get_number(&w->options, "main-pane-width") + 1;
 if (mainwidth < 2 + 1)
  mainwidth = 2 + 1;
 totalcolumns = columns * (2 + 1) - 1;
 if (mainwidth + totalcolumns > w->sx) {
  if (totalcolumns + 2 + 1 > w->sx)
   mainwidth = 2 + 2;
  else
   mainwidth = w->sx - totalcolumns;
  width = 2 + 1;
 } else
  width = (w->sx - mainwidth) / columns;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, mainwidth + columns * width, w->sy, 0, 0);
 layout_make_node(lc, LAYOUT_LEFTRIGHT);
 lcmain = layout_create_cell(lc);
 layout_set_size(lcmain, mainwidth - 1, w->sy, 0, 0);
 layout_make_leaf(lcmain, ((&w->panes)->tqh_first));
 do { (lcmain)->entry.tqe_next = ((void *)0); (lcmain)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcmain); (&lc->cells)->tqh_last = &(lcmain)->entry.tqe_next; } while (0);
 wp = ((((&w->panes)->tqh_first))->entry.tqe_next);
 for (j = 0; j < columns; j++) {
  if (wp == ((void *)0))
   break;
  lccolumn = layout_create_cell(lc);
  layout_set_size(lccolumn, width - 1, w->sy, 0, 0);
  do { (lccolumn)->entry.tqe_next = ((void *)0); (lccolumn)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lccolumn); (&lc->cells)->tqh_last = &(lccolumn)->entry.tqe_next; } while (0);
  if (rows == 1) {
   layout_make_leaf(lccolumn, wp);
   wp = ((wp)->entry.tqe_next);
   continue;
  }
  layout_make_node(lccolumn, LAYOUT_TOPBOTTOM);
  for (i = 0; i < rows; i++) {
   lcchild = layout_create_cell(lccolumn);
   layout_set_size(lcchild, width - 1, height - 1, 0, 0);
   layout_make_leaf(lcchild, wp);
   do { (lcchild)->entry.tqe_next = ((void *)0); (lcchild)->entry.tqe_prev = (&lccolumn->cells)->tqh_last; *(&lccolumn->cells)->tqh_last = (lcchild); (&lccolumn->cells)->tqh_last = &(lcchild)->entry.tqe_next; } while (0);
   if ((wp = ((wp)->entry.tqe_next)) == ((void *)0))
    break;
  }
  if (i == rows)
   i--;
  used = ((i + 1) * height) - 1;
   if (w->sy <= used)
    continue;
   lcchild = (*(((struct layout_cells *)((&lccolumn->cells)->tqh_last))->tqh_last));
   layout_resize_adjust(lcchild, LAYOUT_TOPBOTTOM, w->sy - used);
 }
 used = mainwidth + (columns * width) - 1;
 if (w->sx > used) {
  lccolumn = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lccolumn, LAYOUT_LEFTRIGHT, w->sx - used);
 }
 layout_fix_offsets(lc);
 layout_fix_panes(w, w->sx, w->sy);
 layout_print_cell(w->layout_root, __func__, 1);
 server_redraw_window(w);
}

canonical_original_code:
void layout_set_main_v(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc; struct layout_cell *lcmain; struct layout_cell *lccolumn; struct layout_cell *lcchild;
 unsigned int n; unsigned int mainwidth; unsigned int width; unsigned int height; unsigned int used;
 unsigned int i; unsigned int j; unsigned int columns; unsigned int rows; unsigned int totalcolumns;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 n--;
 rows = w->sy / (2 + 1);
 columns = 1 + (n - 1) / rows;
 rows = 1 + (n - 1) / columns;
 height = w->sy / rows;
 mainwidth = options_get_number(&w->options, "main-pane-width") + 1;
 if (mainwidth < 2 + 1)
  mainwidth = 2 + 1;
 totalcolumns = columns * (2 + 1) - 1;
 if (mainwidth + totalcolumns > w->sx) {
  if (totalcolumns + 2 + 1 > w->sx)
   mainwidth = 2 + 2;
  else
   mainwidth = w->sx - totalcolumns;
  width = 2 + 1;
 } else
  width = (w->sx - mainwidth) / columns;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, mainwidth + columns * width, w->sy, 0, 0);
 layout_make_node(lc, LAYOUT_LEFTRIGHT);
 lcmain = layout_create_cell(lc);
 layout_set_size(lcmain, mainwidth - 1, w->sy, 0, 0);
 layout_make_leaf(lcmain, ((&w->panes)->tqh_first));
 do { (lcmain)->entry.tqe_next = ((void *)0); (lcmain)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcmain); (&lc->cells)->tqh_last = &(lcmain)->entry.tqe_next; } while (0);
 wp = ((((&w->panes)->tqh_first))->entry.tqe_next);
 for (j = 0; j < columns; j++) {
  if (wp == ((void *)0))
   break;
  lccolumn = layout_create_cell(lc);
  layout_set_size(lccolumn, width - 1, w->sy, 0, 0);
  do { (lccolumn)->entry.tqe_next = ((void *)0); (lccolumn)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lccolumn); (&lc->cells)->tqh_last = &(lccolumn)->entry.tqe_next; } while (0);
  if (rows == 1) {
   layout_make_leaf(lccolumn, wp);
   wp = ((wp)->entry.tqe_next);
   continue;
  }
  layout_make_node(lccolumn, LAYOUT_TOPBOTTOM);
  for (i = 0; i < rows; i++) {
   lcchild = layout_create_cell(lccolumn);
   layout_set_size(lcchild, width - 1, height - 1, 0, 0);
   layout_make_leaf(lcchild, wp);
   do { (lcchild)->entry.tqe_next = ((void *)0); (lcchild)->entry.tqe_prev = (&lccolumn->cells)->tqh_last; *(&lccolumn->cells)->tqh_last = (lcchild); (&lccolumn->cells)->tqh_last = &(lcchild)->entry.tqe_next; } while (0);
   if ((wp = ((wp)->entry.tqe_next)) == ((void *)0))
    break;
  }
  if (i == rows)
   i--;
  used = ((i + 1) * height) - 1;
   if (w->sy <= used)
    continue;
   lcchild = (*(((struct layout_cells *)((&lccolumn->cells)->tqh_last))->tqh_last));
   layout_resize_adjust(lcchild, LAYOUT_TOPBOTTOM, w->sy - used);
 }
 used = mainwidth + (columns * width) - 1;
 if (w->sx > used) {
  lccolumn = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lccolumn, LAYOUT_LEFTRIGHT, w->sx - used);
 }
 layout_fix_offsets(lc);
 layout_fix_panes(w, w->sx, w->sy);
 layout_print_cell(w->layout_root, __func__, 1);
 server_redraw_window(w);
}

variable_types:
mainwidth
unsigned int

variable_types:
totalcolumns
unsigned int

user_defined_types: struct window { char *name; struct timeval name_timer; struct window_pane *active; struct window_panes panes; int lastlayout; struct layout_cell *layout_root; unsigned int sx; unsigned int sy; int flags; struct options options; unsigned int references; }

user_defined_types: struct window_pane { struct window *window; struct layout_cell *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx ictx; int pipe_fd; struct buffer *pipe_buf; unsigned long pipe_off; struct screen *screen; struct screen base; unsigned int saved_cx; unsigned int saved_cy; struct grid *saved_grid; struct grid_cell saved_cell; struct window_mode *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; }

user_defined_types: struct layout_cell { enum layout_type type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; }

user_defined_types: struct layout_cells { struct layout_cell *tqh_first; struct layout_cell **tqh_last; }

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

user_defined_types: struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; }

user_defined_types: struct input_ctx { struct window_pane *wp; struct screen_write_ctx ctx; unsigned char *buf; unsigned long len; unsigned long off; unsigned long was; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; struct utf8_data utf8data; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }

user_defined_types: enum layout_type { LAYOUT_LEFTRIGHT=0, LAYOUT_TOPBOTTOM=1, LAYOUT_WINDOWPANE=2 }

user_defined_types: struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; }

user_defined_types: struct screen_write_ctx { struct window_pane *wp; struct screen *s; }

user_defined_types: struct utf8_data { unsigned char data[9]; unsigned long have; unsigned long size; unsigned int width; }

user_defined_types: struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, struct client *, struct mouse_event *); void (*timer)(struct window_pane *); }

user_defined_types: struct options { struct options_tree tree; struct options *parent; }

user_defined_types: struct options_tree { struct options_entry *sph_root; }

user_defined_types: struct screen { char *title; struct grid *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel sel; }

user_defined_types: struct input_arg { unsigned char data[64]; unsigned long used; }

user_defined_types: struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; }

user_defined_types: struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_DATA=2 } type; char *str; long long num; void *data; void (*freefn)(void *); struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; }

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

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct environ_entry { char *name; char *value; struct { struct environ_entry *rbe_left; struct environ_entry *rbe_right; struct environ_entry *rbe_parent; int rbe_color; } entry; }

user_defined_types: struct job { char *cmd; int pid; int status; struct client *client; int fd; struct buffer *out; void (*callbackfn)(struct job *); void (*freefn)(void *); void *data; int flags; struct { struct job *rbe_left; struct job *rbe_right; struct job *rbe_parent; int rbe_color; } entry; struct { struct job *sle_next; } lentry; }

user_defined_types: struct winlink_stack { struct winlink *tqh_first; struct winlink **tqh_last; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

user_defined_types: struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; }

user_defined_types: struct grid_utf8 { unsigned char width; unsigned char data[9]; }

user_defined_types: struct imsg_fd { struct { struct imsg_fd *tqe_next; struct imsg_fd **tqe_prev; } entry; int fd; }

user_defined_types: struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; }

user_defined_types: struct winlink { int idx; struct window *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *tqe_next; struct winlink **tqe_prev; } sentry; }

user_defined_types: struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; }

user_defined_types: struct session_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; }

user_defined_types: enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 }

user_defined_types: enum mode_key_cmd { MODEKEY_NONE=0, MODEKEY_OTHER=1, MODEKEYEDIT_BACKSPACE=2, MODEKEYEDIT_CANCEL=3, MODEKEYEDIT_COMPLETE=4, MODEKEYEDIT_CURSORLEFT=5, MODEKEYEDIT_CURSORRIGHT=6, MODEKEYEDIT_DELETE=7, MODEKEYEDIT_DELETELINE=8, MODEKEYEDIT_DELETETOENDOFLINE=9, MODEKEYEDIT_ENDOFLINE=10, MODEKEYEDIT_ENTER=11, MODEKEYEDIT_HISTORYDOWN=12, MODEKEYEDIT_HISTORYUP=13, MODEKEYEDIT_PASTE=14, MODEKEYEDIT_STARTOFLINE=15, MODEKEYEDIT_SWITCHMODE=16, MODEKEYEDIT_SWITCHMODEAPPEND=17, MODEKEYEDIT_TRANSPOSECHARS=18, MODEKEYCHOICE_CANCEL=19, MODEKEYCHOICE_CHOOSE=20, MODEKEYCHOICE_DOWN=21, MODEKEYCHOICE_PAGEDOWN=22, MODEKEYCHOICE_PAGEUP=23, MODEKEYCHOICE_UP=24, MODEKEYCOPY_BACKTOINDENTATION=25, MODEKEYCOPY_BOTTOMLINE=26, MODEKEYCOPY_CANCEL=27, MODEKEYCOPY_CLEARSELECTION=28, MODEKEYCOPY_COPYSELECTION=29, MODEKEYCOPY_DOWN=30, MODEKEYCOPY_ENDOFLINE=31, MODEKEYCOPY_GOTOLINE=32, MODEKEYCOPY_HALFPAGEDOWN=33, MODEKEYCOPY_HALFPAGEUP=34, MODEKEYCOPY_LEFT=35, MODEKEYCOPY_MIDDLELINE=36, MODEKEYCOPY_NEXTPAGE=37, MODEKEYCOPY_NEXTWORD=38, MODEKEYCOPY_PREVIOUSPAGE=39, MODEKEYCOPY_PREVIOUSWORD=40, MODEKEYCOPY_RIGHT=41, MODEKEYCOPY_SCROLLDOWN=42, MODEKEYCOPY_SCROLLUP=43, MODEKEYCOPY_SEARCHAGAIN=44, MODEKEYCOPY_SEARCHDOWN=45, MODEKEYCOPY_SEARCHUP=46, MODEKEYCOPY_STARTOFLINE=47, MODEKEYCOPY_STARTSELECTION=48, MODEKEYCOPY_TOPLINE=49, MODEKEYCOPY_UP=50 }

user_defined_types: struct paste_buffer { char *data; unsigned long size; }


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
char *__fastcall layout_set_name(unsigned int a1)
{
return (&layout_sets)[2 * a1];
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
return (&layout_sets)[2 * a1];
}

original_code:
const char *
layout_set_name(u_int layout)
{
 return (layout_sets[layout].name);
}

canonical_original_code:
char *layout_set_name(unsigned int layout)
{
 return (layout_sets[layout].name);
}

variable_types:
layout
unsigned int

return_type: char *


decompiled_code:
__int64 __fastcall layout_set_lookup(char *s2)
{
unsigned int v1; // er13
__int64 v2; // rbx
size_t v3; // r12

v1 = -1;
v2 = 0LL;
v3 = strlen(s2);
if ( strncmp("even-horizontal", s2, v3) )
goto LABEL_4;
while ( v1 == -1 )
{
v1 = v2;
LABEL_4:
if ( ++v2 == 4 )
return v1;
while ( strncmp((&layout_sets)[2 * v2], s2, v3) )
{
if ( ++v2 == 4 )
return v1;
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
unsigned int v1; // er13
__int64 v2; // rbx
size_t v3; // r12

v1 = -1;
v2 = 0LL;
v3 = strlen(s2);
if ( strncmp("even-horizontal", s2, v3) )
goto LABEL_4;
while ( v1 == -1 )
{
v1 = v2;
LABEL_4:
if ( ++v2 == 4 )
return v1;
while ( strncmp((&layout_sets)[2 * v2], s2, v3) )
{
if ( ++v2 == 4 )
return v1;
}
}
return (unsigned int)-1;
}

original_code:
int
layout_set_lookup(const char *name)
{
 u_int i;
 int matched = -1;
 for (i = 0; i < (sizeof((layout_sets)) / sizeof((layout_sets)[0])); i++) {
  if (strncmp(layout_sets[i].name, name, strlen(name)) == 0) {
   if (matched != -1)
    return (-1);
   matched = i;
  }
 }
 return (matched);
}

canonical_original_code:
int layout_set_lookup(char *name)
{
 unsigned int i;
 int matched = -1;
 for (i = 0; i < (sizeof((layout_sets)) / sizeof((layout_sets)[0])); i++) {
  if (strncmp(layout_sets[i].name, name, strlen(name)) == 0) {
   if (matched != -1)
    return (-1);
   matched = i;
  }
 }
 return (matched);
}

variable_types:
name
char *

variable_types:
i
unsigned int

variable_types: matched int

return_type: int


decompiled_code:
__int64 __fastcall layout_set_select(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
void (*v3)(void); // rax

v2 = 3;
if ( a2 <= 3 )
v2 = a2;
v3 = (void (*)(void))(&layout_sets)[2 * v2 + 1];
if ( v3 )
v3();
*(_DWORD *)(a1 + 160) = v2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
void (*v3)(void); // rax

v2 = 3;
if ( a2 <= 3 )
v2 = a2;
v3 = (void (*)(void))(&layout_sets)[2 * v2 + 1];
if ( v3 )
v3();
*(_DWORD *)(a1 + 160) = v2;
return v2;
}

original_code:
u_int
layout_set_select(struct window *w, u_int layout)
{
 if (layout > (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1)
  layout = (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1;
 if (layout_sets[layout].arrange != ((void *)0))
  layout_sets[layout].arrange(w);
 w->lastlayout = layout;
 return (layout);
}

canonical_original_code:
unsigned int layout_set_select(struct window *w, unsigned int layout)
{
 if (layout > (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1)
  layout = (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1;
 if (layout_sets[layout].arrange != ((void *)0))
  layout_sets[layout].arrange(w);
 w->lastlayout = layout;
 return (layout);
}

variable_types: struct window { char *name; struct timeval { long tv_sec; long tv_usec; } name_timer; struct window_pane { struct window *window; struct layout_cell { enum layout_type { LAYOUT_LEFTRIGHT=0, LAYOUT_TOPBOTTOM=1, LAYOUT_WINDOWPANE=2 } type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells { struct layout_cell *tqh_first; struct layout_cell **tqh_last; } cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; } *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; } *in; struct buffer *out; struct input_ctx { struct window_pane *wp; struct screen_write_ctx { struct window_pane *wp; struct screen { char *title; struct grid { int flags; unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; struct grid_line { unsigned int cellsize; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } *celldata; unsigned int utf8size; struct grid_utf8 { unsigned char width; unsigned char data[9]; } *utf8data; int flags; } *linedata; } *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; } sel; } *s; } ctx; unsigned char *buf; unsigned long len; unsigned long off; unsigned long was; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; struct utf8_data { unsigned char data[9]; unsigned long have; unsigned long size; unsigned int width; } utf8data; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg { unsigned char data[64]; unsigned long used; } *list; unsigned int num; unsigned long space; } args; } ictx; int pipe_fd; struct buffer *pipe_buf; unsigned long pipe_off; struct screen *screen; struct screen base; unsigned int saved_cx; unsigned int saved_cy; struct grid *saved_grid; struct grid_cell saved_cell; struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client { struct imsgbuf { struct { struct imsg_fd { struct { struct imsg_fd *tqe_next; struct imsg_fd **tqe_prev; } entry; int fd; } *tqh_first; struct imsg_fd **tqh_last; } fds; struct buf_read { unsigned char buf[65535]; unsigned char *rptr; unsigned long wpos; } r; struct msgbuf { struct { struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; } w; int fd; int pid; } ibuf; struct timeval creation_time; struct timeval activity_time; struct environ { struct environ_entry { char *name; char *value; struct { struct environ_entry *rbe_left; struct environ_entry *rbe_right; struct environ_entry *rbe_parent; int rbe_color; } entry; } *rbh_root; } environ; char *title; char *cwd; struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term { char *name; unsigned int references; struct tty_code { enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 } type; union { char *string; int number; int flag; } value; } codes[-1]; int flags; struct { struct tty_term *sle_next; } entry; } *term; int fd; struct buffer *in; struct buffer *out; int log_fd; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } tio; struct grid_cell cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval key_timer; unsigned long ksize; struct tty_keys { struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; } *rbh_root; } ktree; } tty; struct timeval repeat_timer; struct timeval status_timer; struct jobs { struct job { char *cmd; int pid; int status; struct client *client; int fd; struct buffer *out; void (*callbackfn)(struct job *); void (*freefn)(void *); void *data; int flags; struct { struct job *rbe_left; struct job *rbe_right; struct job *rbe_parent; int rbe_color; } entry; struct { struct job *sle_next; } lentry; } *rbh_root; } status_jobs; struct screen status; int flags; struct timeval identify_timer; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callbackfn)(void *, char *); void (*prompt_freefn)(void *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data { struct mode_key_tree { struct mode_key_binding { int key; int mode; enum mode_key_cmd { MODEKEY_NONE=0, MODEKEY_OTHER=1, MODEKEYEDIT_BACKSPACE=2, MODEKEYEDIT_CANCEL=3, MODEKEYEDIT_COMPLETE=4, MODEKEYEDIT_CURSORLEFT=5, MODEKEYEDIT_CURSORRIGHT=6, MODEKEYEDIT_DELETE=7, MODEKEYEDIT_DELETELINE=8, MODEKEYEDIT_DELETETOENDOFLINE=9, MODEKEYEDIT_ENDOFLINE=10, MODEKEYEDIT_ENTER=11, MODEKEYEDIT_HISTORYDOWN=12, MODEKEYEDIT_HISTORYUP=13, MODEKEYEDIT_PASTE=14, MODEKEYEDIT_STARTOFLINE=15, MODEKEYEDIT_SWITCHMODE=16, MODEKEYEDIT_SWITCHMODEAPPEND=17, MODEKEYEDIT_TRANSPOSECHARS=18, MODEKEYCHOICE_CANCEL=19, MODEKEYCHOICE_CHOOSE=20, MODEKEYCHOICE_DOWN=21, MODEKEYCHOICE_PAGEDOWN=22, MODEKEYCHOICE_PAGEUP=23, MODEKEYCHOICE_UP=24, MODEKEYCOPY_BACKTOINDENTATION=25, MODEKEYCOPY_BOTTOMLINE=26, MODEKEYCOPY_CANCEL=27, MODEKEYCOPY_CLEARSELECTION=28, MODEKEYCOPY_COPYSELECTION=29, MODEKEYCOPY_DOWN=30, MODEKEYCOPY_ENDOFLINE=31, MODEKEYCOPY_GOTOLINE=32, MODEKEYCOPY_HALFPAGEDOWN=33, MODEKEYCOPY_HALFPAGEUP=34, MODEKEYCOPY_LEFT=35, MODEKEYCOPY_MIDDLELINE=36, MODEKEYCOPY_NEXTPAGE=37, MODEKEYCOPY_NEXTWORD=38, MODEKEYCOPY_PREVIOUSPAGE=39, MODEKEYCOPY_PREVIOUSWORD=40, MODEKEYCOPY_RIGHT=41, MODEKEYCOPY_SCROLLDOWN=42, MODEKEYCOPY_SCROLLUP=43, MODEKEYCOPY_SEARCHAGAIN=44, MODEKEYCOPY_SEARCHDOWN=45, MODEKEYCOPY_SEARCHUP=46, MODEKEYCOPY_STARTOFLINE=47, MODEKEYCOPY_STARTSELECTION=48, MODEKEYCOPY_TOPLINE=49, MODEKEYCOPY_UP=50 } cmd; struct { struct mode_key_binding *spe_left; struct mode_key_binding *spe_right; } entry; } *sph_root; } *tree; int mode; } prompt_mdata; struct session { char *name; struct timeval creation_time; struct timeval activity_time; unsigned int sx; unsigned int sy; struct winlink { int idx; struct window *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *tqe_next; struct winlink **tqe_prev; } sentry; } *curw; struct winlink_stack { struct winlink *tqh_first; struct winlink **tqh_last; } lastw; struct winlinks { struct winlink *rbh_root; } windows; struct options { struct options_tree { struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_DATA=2 } type; char *str; long long num; void *data; void (*freefn)(void *); struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; } *sph_root; } tree; struct options *parent; } options; struct paste_stack { struct paste_buffer { char *data; unsigned long size; } **list; unsigned int num; unsigned long space; } buffers; struct { struct session_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; } *slh_first; } alerts; int flags; struct termios *tio; struct environ environ; int references; struct { struct session *tqe_next; struct session **tqe_prev; } gentry; } *session; int references; } *, int); void (*mouse)(struct window_pane *, struct client *, struct mouse_event { unsigned char b; unsigned char x; unsigned char y; } *); void (*timer)(struct window_pane *); } *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; } *active; struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; } panes; int lastlayout; struct layout_cell *layout_root; unsigned int sx; unsigned int sy; int flags; struct options options; unsigned int references; } *

return_type: unsigned int

user_defined_types: struct window { char *name; struct timeval name_timer; struct window_pane *active; struct window_panes panes; int lastlayout; struct layout_cell *layout_root; unsigned int sx; unsigned int sy; int flags; struct options options; unsigned int references; }

user_defined_types: struct window_pane { struct window *window; struct layout_cell *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx ictx; int pipe_fd; struct buffer *pipe_buf; unsigned long pipe_off; struct screen *screen; struct screen base; unsigned int saved_cx; unsigned int saved_cy; struct grid *saved_grid; struct grid_cell saved_cell; struct window_mode *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; }

user_defined_types: struct input_ctx { struct window_pane *wp; struct screen_write_ctx ctx; unsigned char *buf; unsigned long len; unsigned long off; unsigned long was; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; struct utf8_data utf8data; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }

user_defined_types: struct layout_cell { enum layout_type type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; }

user_defined_types: struct screen_write_ctx { struct window_pane *wp; struct screen *s; }

user_defined_types: struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, struct client *, struct mouse_event *); void (*timer)(struct window_pane *); }

user_defined_types: struct screen { char *title; struct grid *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel sel; }

user_defined_types: struct grid { int flags; unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; struct grid_line *linedata; }

user_defined_types: struct client { struct imsgbuf ibuf; struct timeval creation_time; struct timeval activity_time; struct environ environ; char *title; char *cwd; struct tty tty; struct timeval repeat_timer; struct timeval status_timer; struct jobs status_jobs; struct screen status; int flags; struct timeval identify_timer; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callbackfn)(void *, char *); void (*prompt_freefn)(void *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; int references; }

user_defined_types: struct imsgbuf { struct { struct imsg_fd *tqh_first; struct imsg_fd **tqh_last; } fds; struct buf_read r; struct msgbuf w; int fd; int pid; }

user_defined_types: struct environ { struct environ_entry *rbh_root; }

user_defined_types: struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term *term; int fd; struct buffer *in; struct buffer *out; int log_fd; struct termios tio; struct grid_cell cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval key_timer; unsigned long ksize; struct tty_keys ktree; }

user_defined_types: struct mode_key_data { struct mode_key_tree *tree; int mode; }

user_defined_types: struct grid_line { unsigned int cellsize; struct grid_cell *celldata; unsigned int utf8size; struct grid_utf8 *utf8data; int flags; }

user_defined_types: struct msgbuf { struct { struct buf *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; }

user_defined_types: struct session { char *name; struct timeval creation_time; struct timeval activity_time; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; struct termios *tio; struct environ environ; int references; struct { struct session *tqe_next; struct session **tqe_prev; } gentry; }

user_defined_types: struct tty_term { char *name; unsigned int references; struct tty_code codes[-1]; int flags; struct { struct tty_term *sle_next; } entry; }

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

user_defined_types: struct options { struct options_tree tree; struct options *parent; }

user_defined_types: struct paste_stack { struct paste_buffer **list; unsigned int num; unsigned long space; }

user_defined_types: struct options_tree { struct options_entry *sph_root; }

user_defined_types: struct tty_code { enum tty_code_type type; union { char *string; int number; int flag; } value; }

user_defined_types: struct mode_key_binding { int key; int mode; enum mode_key_cmd cmd; struct { struct mode_key_binding *spe_left; struct mode_key_binding *spe_right; } entry; }


decompiled_code:
__int64 __fastcall layout_set_next(__int64 a1)
{
int v1; // ebx
unsigned int v2; // ebx
unsigned int v3; // er12
void (__fastcall *v4)(__int64); // rax

v1 = *(_DWORD *)(a1 + 160);
if ( v1 == -1 || (v2 = v1 + 1, v3 = v2, v2 > 3) )
{
v2 = 0;
v4 = (void (__fastcall *)(__int64))layout_set_even_h;
v3 = 0;
LABEL_4:
v4(a1);
*(_DWORD *)(a1 + 160) = v2;
return v3;
}
v4 = (void (__fastcall *)(__int64))(&layout_sets)[2 * v2 + 1];
if ( v4 )
goto LABEL_4;
*(_DWORD *)(a1 + 160) = v2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebx
unsigned int v2; // ebx
unsigned int v3; // er12
void (__fastcall *v4)(__int64); // rax

v1 = *(_DWORD *)(a1 + 160);
if ( v1 == -1 || (v2 = v1 + 1, v3 = v2, v2 > 3) )
{
v2 = 0;
v4 = (void (__fastcall *)(__int64))layout_set_even_h;
v3 = 0;
LABEL_4:
v4(a1);
*(_DWORD *)(a1 + 160) = v2;
return v3;
}
v4 = (void (__fastcall *)(__int64))(&layout_sets)[2 * v2 + 1];
if ( v4 )
goto LABEL_4;
*(_DWORD *)(a1 + 160) = v2;
return v2;
}

original_code:
u_int
layout_set_next(struct window *w)
{
 u_int layout;
 if (w->lastlayout == -1)
  layout = 0;
 else {
  layout = w->lastlayout + 1;
  if (layout > (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1)
   layout = 0;
 }
 if (layout_sets[layout].arrange != ((void *)0))
  layout_sets[layout].arrange(w);
 w->lastlayout = layout;
 return (layout);
}

canonical_original_code:
unsigned int layout_set_next(struct window *w)
{
 unsigned int layout;
 if (w->lastlayout == -1)
  layout = 0;
 else {
  layout = w->lastlayout + 1;
  if (layout > (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1)
   layout = 0;
 }
 if (layout_sets[layout].arrange != ((void *)0))
  layout_sets[layout].arrange(w);
 w->lastlayout = layout;
 return (layout);
}

user_defined_types: struct window { char *name; struct timeval name_timer; struct window_pane *active; struct window_panes panes; int lastlayout; struct layout_cell *layout_root; unsigned int sx; unsigned int sy; int flags; struct options options; unsigned int references; }

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

user_defined_types: struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; }

user_defined_types: struct window_pane { struct window *window; struct layout_cell *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx ictx; int pipe_fd; struct buffer *pipe_buf; unsigned long pipe_off; struct screen *screen; struct screen base; unsigned int saved_cx; unsigned int saved_cy; struct grid *saved_grid; struct grid_cell saved_cell; struct window_mode *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; }

user_defined_types: struct input_ctx { struct window_pane *wp; struct screen_write_ctx ctx; unsigned char *buf; unsigned long len; unsigned long off; unsigned long was; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; struct utf8_data utf8data; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }

user_defined_types: struct layout_cell { enum layout_type type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; }

user_defined_types: struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; }

user_defined_types: struct screen_write_ctx { struct window_pane *wp; struct screen *s; }

user_defined_types: struct utf8_data { unsigned char data[9]; unsigned long have; unsigned long size; unsigned int width; }

user_defined_types: struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, struct client *, struct mouse_event *); void (*timer)(struct window_pane *); }

user_defined_types: enum layout_type { LAYOUT_LEFTRIGHT=0, LAYOUT_TOPBOTTOM=1, LAYOUT_WINDOWPANE=2 }

user_defined_types: struct layout_cells { struct layout_cell *tqh_first; struct layout_cell **tqh_last; }

user_defined_types: struct screen { char *title; struct grid *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel sel; }

user_defined_types: struct input_arg { unsigned char data[64]; unsigned long used; }

user_defined_types: struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; }

user_defined_types: struct mouse_event { unsigned char b; unsigned char x; unsigned char y; }

user_defined_types: struct buf_read { unsigned char buf[65535]; unsigned char *rptr; unsigned long wpos; }

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

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct environ_entry { char *name; char *value; struct { struct environ_entry *rbe_left; struct environ_entry *rbe_right; struct environ_entry *rbe_parent; int rbe_color; } entry; }

user_defined_types: struct job { char *cmd; int pid; int status; struct client *client; int fd; struct buffer *out; void (*callbackfn)(struct job *); void (*freefn)(void *); void *data; int flags; struct { struct job *rbe_left; struct job *rbe_right; struct job *rbe_parent; int rbe_color; } entry; struct { struct job *sle_next; } lentry; }

user_defined_types: struct winlink_stack { struct winlink *tqh_first; struct winlink **tqh_last; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

user_defined_types: struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; }

user_defined_types: struct grid_utf8 { unsigned char width; unsigned char data[9]; }

user_defined_types: struct imsg_fd { struct { struct imsg_fd *tqe_next; struct imsg_fd **tqe_prev; } entry; int fd; }

user_defined_types: struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; }

user_defined_types: struct winlink { int idx; struct window *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *tqe_next; struct winlink **tqe_prev; } sentry; }

user_defined_types: struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; }

user_defined_types: struct session_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; }

user_defined_types: enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 }

user_defined_types: enum mode_key_cmd { MODEKEY_NONE=0, MODEKEY_OTHER=1, MODEKEYEDIT_BACKSPACE=2, MODEKEYEDIT_CANCEL=3, MODEKEYEDIT_COMPLETE=4, MODEKEYEDIT_CURSORLEFT=5, MODEKEYEDIT_CURSORRIGHT=6, MODEKEYEDIT_DELETE=7, MODEKEYEDIT_DELETELINE=8, MODEKEYEDIT_DELETETOENDOFLINE=9, MODEKEYEDIT_ENDOFLINE=10, MODEKEYEDIT_ENTER=11, MODEKEYEDIT_HISTORYDOWN=12, MODEKEYEDIT_HISTORYUP=13, MODEKEYEDIT_PASTE=14, MODEKEYEDIT_STARTOFLINE=15, MODEKEYEDIT_SWITCHMODE=16, MODEKEYEDIT_SWITCHMODEAPPEND=17, MODEKEYEDIT_TRANSPOSECHARS=18, MODEKEYCHOICE_CANCEL=19, MODEKEYCHOICE_CHOOSE=20, MODEKEYCHOICE_DOWN=21, MODEKEYCHOICE_PAGEDOWN=22, MODEKEYCHOICE_PAGEUP=23, MODEKEYCHOICE_UP=24, MODEKEYCOPY_BACKTOINDENTATION=25, MODEKEYCOPY_BOTTOMLINE=26, MODEKEYCOPY_CANCEL=27, MODEKEYCOPY_CLEARSELECTION=28, MODEKEYCOPY_COPYSELECTION=29, MODEKEYCOPY_DOWN=30, MODEKEYCOPY_ENDOFLINE=31, MODEKEYCOPY_GOTOLINE=32, MODEKEYCOPY_HALFPAGEDOWN=33, MODEKEYCOPY_HALFPAGEUP=34, MODEKEYCOPY_LEFT=35, MODEKEYCOPY_MIDDLELINE=36, MODEKEYCOPY_NEXTPAGE=37, MODEKEYCOPY_NEXTWORD=38, MODEKEYCOPY_PREVIOUSPAGE=39, MODEKEYCOPY_PREVIOUSWORD=40, MODEKEYCOPY_RIGHT=41, MODEKEYCOPY_SCROLLDOWN=42, MODEKEYCOPY_SCROLLUP=43, MODEKEYCOPY_SEARCHAGAIN=44, MODEKEYCOPY_SEARCHDOWN=45, MODEKEYCOPY_SEARCHUP=46, MODEKEYCOPY_STARTOFLINE=47, MODEKEYCOPY_STARTSELECTION=48, MODEKEYCOPY_TOPLINE=49, MODEKEYCOPY_UP=50 }

user_defined_types: struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_DATA=2 } type; char *str; long long num; void *data; void (*freefn)(void *); struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; }

user_defined_types: struct paste_buffer { char *data; unsigned long size; }


decompiled_code:
__int64 __fastcall layout_set_previous(__int64 a1)
{
int v1; // eax
__int64 v2; // r12
__int64 (__fastcall *v3)(__int64); // rax
int v4; // ebp

v1 = *(_DWORD *)(a1 + 160);
if ( v1 == -1 || !v1 )
{
v3 = layout_set_main_v;
v4 = 3;
LODWORD(v2) = 3;
}
else
{
v2 = (unsigned int)(v1 - 1);
v3 = (__int64 (__fastcall *)(__int64))(&layout_sets)[2 * v2 + 1];
v4 = v2;
if ( !v3 )
{
*(_DWORD *)(a1 + 160) = v2;
return (unsigned int)v2;
}
}
v3(a1);
*(_DWORD *)(a1 + 160) = v4;
return (unsigned int)v2;
}

original_code:
u_int
layout_set_previous(struct window *w)
{
 u_int layout;
 if (w->lastlayout == -1)
  layout = (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1;
 else {
  layout = w->lastlayout;
  if (layout == 0)
   layout = (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1;
  else
   layout--;
 }
 if (layout_sets[layout].arrange != ((void *)0))
  layout_sets[layout].arrange(w);
 w->lastlayout = layout;
 return (layout);
}

canonical_original_code:
unsigned int layout_set_previous(struct window *w)
{
 unsigned int layout;
 if (w->lastlayout == -1)
  layout = (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1;
 else {
  layout = w->lastlayout;
  if (layout == 0)
   layout = (sizeof((layout_sets)) / sizeof((layout_sets)[0])) - 1;
  else
   layout--;
 }
 if (layout_sets[layout].arrange != ((void *)0))
  layout_sets[layout].arrange(w);
 w->lastlayout = layout;
 return (layout);
}

user_defined_types: struct window { char *name; struct timeval name_timer; struct window_pane *active; struct window_panes panes; int lastlayout; struct layout_cell *layout_root; unsigned int sx; unsigned int sy; int flags; struct options options; unsigned int references; }

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

user_defined_types: struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; }

user_defined_types: struct window_pane { struct window *window; struct layout_cell *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx ictx; int pipe_fd; struct buffer *pipe_buf; unsigned long pipe_off; struct screen *screen; struct screen base; unsigned int saved_cx; unsigned int saved_cy; struct grid *saved_grid; struct grid_cell saved_cell; struct window_mode *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; }

user_defined_types: struct input_ctx { struct window_pane *wp; struct screen_write_ctx ctx; unsigned char *buf; unsigned long len; unsigned long off; unsigned long was; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; struct utf8_data utf8data; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }

user_defined_types: struct layout_cell { enum layout_type type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; }

user_defined_types: struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; }

user_defined_types: struct screen_write_ctx { struct window_pane *wp; struct screen *s; }

user_defined_types: struct utf8_data { unsigned char data[9]; unsigned long have; unsigned long size; unsigned int width; }

user_defined_types: struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, struct client *, struct mouse_event *); void (*timer)(struct window_pane *); }

user_defined_types: enum layout_type { LAYOUT_LEFTRIGHT=0, LAYOUT_TOPBOTTOM=1, LAYOUT_WINDOWPANE=2 }

user_defined_types: struct layout_cells { struct layout_cell *tqh_first; struct layout_cell **tqh_last; }

user_defined_types: struct screen { char *title; struct grid *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel sel; }

user_defined_types: struct input_arg { unsigned char data[64]; unsigned long used; }

user_defined_types: struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; }

user_defined_types: struct grid { int flags; unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; struct grid_line *linedata; }

user_defined_types: struct client { struct imsgbuf ibuf; struct timeval creation_time; struct timeval activity_time; struct environ environ; char *title; char *cwd; struct tty tty; struct timeval repeat_timer; struct timeval status_timer; struct jobs status_jobs; struct screen status; int flags; struct timeval identify_timer; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callbackfn)(void *, char *); void (*prompt_freefn)(void *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; int references; }

user_defined_types: struct mouse_event { unsigned char b; unsigned char x; unsigned char y; }

user_defined_types: struct imsgbuf { struct { struct imsg_fd *tqh_first; struct imsg_fd **tqh_last; } fds; struct buf_read r; struct msgbuf w; int fd; int pid; }

user_defined_types: struct environ { struct environ_entry *rbh_root; }

user_defined_types: struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term *term; int fd; struct buffer *in; struct buffer *out; int log_fd; struct termios tio; struct grid_cell cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval key_timer; unsigned long ksize; struct tty_keys ktree; }

user_defined_types: struct mode_key_data { struct mode_key_tree *tree; int mode; }

user_defined_types: struct grid_line { unsigned int cellsize; struct grid_cell *celldata; unsigned int utf8size; struct grid_utf8 *utf8data; int flags; }

user_defined_types: struct buf_read { unsigned char buf[65535]; unsigned char *rptr; unsigned long wpos; }

user_defined_types: struct msgbuf { struct { struct buf *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; }

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

user_defined_types: struct session { char *name; struct timeval creation_time; struct timeval activity_time; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; struct termios *tio; struct environ environ; int references; struct { struct session *tqe_next; struct session **tqe_prev; } gentry; }

user_defined_types: struct tty_term { char *name; unsigned int references; struct tty_code codes[-1]; int flags; struct { struct tty_term *sle_next; } entry; }

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

user_defined_types: struct options { struct options_tree tree; struct options *parent; }

user_defined_types: struct paste_stack { struct paste_buffer **list; unsigned int num; unsigned long space; }

user_defined_types: struct options_tree { struct options_entry *sph_root; }

user_defined_types: struct tty_code { enum tty_code_type type; union { char *string; int number; int flag; } value; }

user_defined_types: struct mode_key_binding { int key; int mode; enum mode_key_cmd cmd; struct { struct mode_key_binding *spe_left; struct mode_key_binding *spe_right; } entry; }


decompiled_code:
__int64 __fastcall utf8_overlap(unsigned int *a1, unsigned int *a2)
{
unsigned int v2; // edx
unsigned int v3; // ecx
unsigned int v4; // esi
__int64 result; // rax
unsigned int v6; // edi

v2 = *a1;
v3 = *a2;
if ( *a1 < *a2 )
{
v6 = a1[1];
result = 1LL;
if ( v3 > v6 )
{
v4 = a2[1];
return (v2 <= v4) & (unsigned __int8)(v4 <= v6);
}
}
else
{
v4 = a2[1];
result = 1LL;
if ( v2 > v4 )
{
v6 = a1[1];
if ( v3 <= v6 && (v2 == v3 || v4 >= v6) )
return 1LL;
return (v2 <= v4) & (unsigned __int8)(v4 <= v6);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, unsigned int *a2)
{
unsigned int v2; // edx
unsigned int v3; // ecx
unsigned int v4; // esi
__int64 result; // rax
unsigned int v6; // edi

v2 = *a1;
v3 = *a2;
if ( *a1 < *a2 )
{
v6 = a1[1];
result = 1LL;
if ( v3 > v6 )
{
v4 = a2[1];
return (v2 <= v4) & (unsigned __int8)(v4 <= v6);
}
}
else
{
v4 = a2[1];
result = 1LL;
if ( v2 > v4 )
{
v6 = a1[1];
if ( v3 <= v6 && (v2 == v3 || v4 >= v6) )
return 1LL;
return (v2 <= v4) & (unsigned __int8)(v4 <= v6);
}
}
return result;
}

original_code:
int
utf8_overlap(
    struct utf8_width_entry *item1, struct utf8_width_entry *item2)
{
 if (item1->first >= item2->first && item1->first <= item2->last)
  return (1);
 if (item1->last >= item2->first && item1->last <= item2->last)
  return (1);
 if (item2->first >= item1->first && item2->first <= item1->last)
  return (1);
 if (item2->last >= item1->first && item2->last <= item1->last)
  return (1);
 return (0);
}

canonical_original_code:
int utf8_overlap(struct utf8_width_entry *item1, struct utf8_width_entry *item2)
{
 if (item1->first >= item2->first && item1->first <= item2->last)
  return (1);
 if (item1->last >= item2->first && item1->last <= item2->last)
  return (1);
 if (item2->first >= item1->first && item2->first <= item1->last)
  return (1);
 if (item2->last >= item1->first && item2->last <= item1->last)
  return (1);
 return (0);
}

variable_types: struct utf8_width_entry { unsigned int first; unsigned int last; int width; struct utf8_width_entry *left; struct utf8_width_entry *right; } *


decompiled_code:
__int64 utf8_build()
{
unsigned int *v0; // r11
unsigned int v1; // er10
unsigned int *v2; // r9
unsigned int v3; // er8
__int64 result; // rax
__int64 *v5; // rdx

v0 = (unsigned int *)&utf8_width_table;
v1 = 0;
LABEL_2:
v2 = (unsigned int *)&utf8_width_table;
v3 = 0;
while ( v1 == v3 || !(unsigned int)utf8_overlap(v0, v2) )
{
++v3;
v2 += 8;
if ( v3 == 157 )
{
result = utf8_width_root;
if ( utf8_width_root )
{
v5 = &utf8_width_root;
while ( 1 )
{
while ( v0[1] < *(_DWORD *)result )
{
v5 = (__int64 *)(result + 16);
LABEL_9:
result = *v5;
if ( !*v5 )
goto LABEL_13;
}
if ( *v0 <= *(_DWORD *)(result + 4) )
goto LABEL_9;
v5 = (__int64 *)(result + 24);
result = *(_QWORD *)(result + 24);
if ( !result )
goto LABEL_13;
}
}
v5 = &utf8_width_root;
LABEL_13:
++v1;
*v5 = (__int64)v0;
v0 += 8;
if ( v1 == 157 )
return result;
goto LABEL_2;
}
}
log_fatalx("utf8 overlap: %u %u", v1, v3);
return utf8_print();
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int *v0; // r11
unsigned int v1; // er10
unsigned int *v2; // r9
unsigned int v3; // er8
__int64 result; // rax
__int64 *v5; // rdx

v0 = (unsigned int *)&utf8_width_table;
v1 = 0;
LABEL_2:
v2 = (unsigned int *)&utf8_width_table;
v3 = 0;
while ( v1 == v3 || !(unsigned int)func0(v0, v2) )
{
++v3;
v2 += 8;
if ( v3 == 157 )
{
result = utf8_width_root;
if ( utf8_width_root )
{
v5 = &utf8_width_root;
while ( 1 )
{
while ( v0[1] < *(_DWORD *)result )
{
v5 = (__int64 *)(result + 16);
LABEL_9:
result = *v5;
if ( !*v5 )
goto LABEL_13;
}
if ( *v0 <= *(_DWORD *)(result + 4) )
goto LABEL_9;
v5 = (__int64 *)(result + 24);
result = *(_QWORD *)(result + 24);
if ( !result )
goto LABEL_13;
}
}
v5 = &utf8_width_root;
LABEL_13:
++v1;
*v5 = (__int64)v0;
v0 += 8;
if ( v1 == 157 )
return result;
goto LABEL_2;
}
}
log_fatalx("utf8 overlap: %u %u", v1, v3);
return func2();
}

original_code:
void
utf8_build(void)
{
 struct utf8_width_entry **ptr, *item, *node;
 u_int i, j;
 for (i = 0; i < (sizeof((utf8_width_table)) / sizeof((utf8_width_table)[0])); i++) {
  item = &utf8_width_table[i];
  for (j = 0; j < (sizeof((utf8_width_table)) / sizeof((utf8_width_table)[0])); j++) {
   if (i != j && utf8_overlap(item, &utf8_width_table[j]))
    log_fatalx("utf8 overlap: %u %u", i, j);
  }
  ptr = &utf8_width_root;
  while (*ptr != ((void *)0)) {
   node = *ptr;
   if (item->last < node->first)
    ptr = &(node->left);
   else if (item->first > node->last)
    ptr = &(node->right);
  }
  *ptr = item;
 }
}

canonical_original_code:
void utf8_build()
{
 struct utf8_width_entry **ptr; struct utf8_width_entry *item; struct utf8_width_entry *node;
 unsigned int i; unsigned int j;
 for (i = 0; i < (sizeof((utf8_width_table)) / sizeof((utf8_width_table)[0])); i++) {
  item = &utf8_width_table[i];
  for (j = 0; j < (sizeof((utf8_width_table)) / sizeof((utf8_width_table)[0])); j++) {
   if (i != j && utf8_overlap(item, &utf8_width_table[j]))
    log_fatalx("utf8 overlap: %u %u", i, j);
  }
  ptr = &utf8_width_root;
  while (*ptr != ((void *)0)) {
   node = *ptr;
   if (item->last < node->first)
    ptr = &(node->left);
   else if (item->first > node->last)
    ptr = &(node->right);
  }
  *ptr = item;
 }
}

variable_types: struct utf8_width_entry { unsigned int first; unsigned int last; int width; struct utf8_width_entry *left; struct utf8_width_entry *right; } **

variable_types:
j
unsigned int

return_type: void


decompiled_code:
__int64 __fastcall utf8_print(unsigned int *a1, unsigned int a2)
{
__int64 result; // rax
__int64 v5; // rdi

while ( 1 )
{
result = log_debug("%*s%04x -> %04x", a2, " ", *a1, a1[1]);
v5 = *((_QWORD *)a1 + 2);
if ( v5 )
result = utf8_print(v5, a2 + 1);
a1 = (unsigned int *)*((_QWORD *)a1 + 3);
if ( !a1 )
break;
++a2;
}
return result;
}

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

while ( 1 )
{
result = log_debug("%*s%04x -> %04x", a2, " ", *a1, a1[1]);
v5 = *((_QWORD *)a1 + 2);
if ( v5 )
result = func2(v5, a2 + 1);
a1 = (unsigned int *)*((_QWORD *)a1 + 3);
if ( !a1 )
break;
++a2;
}
return result;
}

original_code:
void
utf8_print(struct utf8_width_entry *node, int n)
{
 log_debug("%*s%04x -> %04x", n, " ", node->first, node->last);
 if (node->left != ((void *)0))
  utf8_print(node->left, n + 1);
 if (node->right != ((void *)0))
  utf8_print(node->right, n + 1);
}

variable_types: n int

user_defined_types: struct utf8_width_entry { unsigned int first; unsigned int last; int width; struct utf8_width_entry *left; struct utf8_width_entry *right; }


decompiled_code:
__int64 __fastcall cmd_has_session_exec(__int64 a1, __int64 a2)
{
return (unsigned int)-(cmd_find_session(a2, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return (unsigned int)-(cmd_find_session(a2, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) == 0);
}

original_code:
int
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
 struct cmd_target_data *data = self->data;
 if (cmd_find_session(ctx, data->target) == ((void *)0))
  return (-1);
 return (0);
}

variable_types: struct cmd { struct cmd_entry { char *name; char *alias; char *usage; int flags; void (*init)(struct cmd *, int); int (*parse)(struct cmd *, int, char **, char **); int (*exec)(struct cmd *, struct cmd_ctx { struct client { int fd; struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; } *in; struct buffer *out; char *title; char *cwd; struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term { char *name; unsigned int references; struct tty_code { enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 } type; union { char *string; int number; int flag; } value; } codes[-1]; int flags; struct { struct tty_term *sle_next; } entry; } *term; int fd; struct buffer *in; struct buffer *out; int log_fd; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } tio; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval { long tv_sec; long tv_usec; } key_timer; unsigned long ksize; struct tty_keys { struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; } *rbh_root; } ktree; } tty; struct timeval status_timer; struct timeval repeat_timer; struct screen { char *title; struct grid { unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; unsigned int *size; struct grid_cell **data; unsigned int *usize; struct grid_utf8 { unsigned char width; unsigned char data[8]; } **udata; } *grid; unsigned int cx; unsigned int cy; unsigned int old_cx; unsigned int old_cy; unsigned int rupper; unsigned int rlower; unsigned int old_rupper; unsigned int old_rlower; int mode; unsigned char *tabs; struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; } sel; } status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data { int type; int flags; } prompt_mdata; struct session { char *name; struct timeval tv; unsigned int sx; unsigned int sy; struct winlink { int idx; struct window { char *name; struct timeval name_timer; struct window_pane { struct window *window; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx { struct window_pane *wp; struct screen_write_ctx { struct window_pane *wp; struct screen *s; } ctx; unsigned char *buf; unsigned long len; unsigned long off; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; unsigned char utf8_buf[4]; unsigned int utf8_len; unsigned int utf8_off; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg { unsigned char data[64]; unsigned long used; } *list; unsigned int num; unsigned long space; } args; } ictx; struct screen *screen; struct screen base; struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, struct client *, unsigned char, unsigned char, unsigned char); void (*timer)(struct window_pane *); } *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; } *active; struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; } panes; unsigned int layout; unsigned int sx; unsigned int sy; int flags; struct options { struct options_tree { struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_KEY=2 } type; union { char *string; long long number; int key; } value; struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; } *sph_root; } tree; struct options *parent; } options; unsigned int references; } *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *sle_next; } sentry; } *curw; struct winlink_stack { struct winlink *slh_first; } lastw; struct winlinks { struct winlink *rbh_root; } windows; struct options options; struct paste_stack { struct paste_buffer { char *data; struct timeval tv; } **list; unsigned int num; unsigned long space; } buffers; struct { struct session_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; } *slh_first; } alerts; int flags; } *session; } *cmdclient; struct client *curclient; struct session *cursession; struct msg_command_data { int pid; unsigned int idx; unsigned long namelen; } *msgdata; void (*print)(struct cmd_ctx *, char *, ...); void (*info)(struct cmd_ctx *, char *, ...); void (*error)(struct cmd_ctx *, char *, ...); } *); void (*send)(struct cmd *, struct buffer *); void (*recv)(struct cmd *, struct buffer *); void (*free)(struct cmd *); unsigned long (*print)(struct cmd *, char *, unsigned long); } *entry; void *data; struct { struct cmd *tqe_next; struct cmd **tqe_prev; } qentry; } *

variable_types:
ctx
struct cmd_ctx *

variable_types: struct cmd_target_data { int flags; char *target; char *arg; } *

user_defined_types: struct cmd { struct cmd_entry *entry; void *data; struct { struct cmd *tqe_next; struct cmd **tqe_prev; } qentry; }

user_defined_types: struct cmd_entry { char *name; char *alias; char *usage; int flags; void (*init)(struct cmd *, int); int (*parse)(struct cmd *, int, char **, char **); int (*exec)(struct cmd *, struct cmd_ctx *); void (*send)(struct cmd *, struct buffer *); void (*recv)(struct cmd *, struct buffer *); void (*free)(struct cmd *); unsigned long (*print)(struct cmd *, char *, unsigned long); }

user_defined_types: struct cmd_ctx { struct client *cmdclient; struct client *curclient; struct session *cursession; struct msg_command_data *msgdata; void (*print)(struct cmd_ctx *, char *, ...); void (*info)(struct cmd_ctx *, char *, ...); void (*error)(struct cmd_ctx *, char *, ...); }

user_defined_types: struct client { int fd; struct buffer *in; struct buffer *out; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; }

user_defined_types: struct screen { char *title; struct grid *grid; unsigned int cx; unsigned int cy; unsigned int old_cx; unsigned int old_cy; unsigned int rupper; unsigned int rlower; unsigned int old_rupper; unsigned int old_rlower; int mode; unsigned char *tabs; struct screen_sel sel; }

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct session { char *name; struct timeval tv; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; }

user_defined_types: struct grid { unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; unsigned int *size; struct grid_cell **data; unsigned int *usize; struct grid_utf8 **udata; }

user_defined_types: struct winlink { int idx; struct window *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *sle_next; } sentry; }

user_defined_types: struct window { char *name; struct timeval name_timer; struct window_pane *active; struct window_panes panes; unsigned int layout; unsigned int sx; unsigned int sy; int flags; struct options options; unsigned int references; }

user_defined_types: struct window_pane { struct window *window; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx ictx; struct screen *screen; struct screen base; struct window_mode *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; }

user_defined_types: struct input_ctx { struct window_pane *wp; struct screen_write_ctx ctx; unsigned char *buf; unsigned long len; unsigned long off; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; unsigned char utf8_buf[4]; unsigned int utf8_len; unsigned int utf8_off; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }


decompiled_code:
void __fastcall server_job_callback(__int64 a1, __int64 a2, __int64 a3)
{
if ( *(_DWORD *)(a3 + 24) != -1 )
{
if ( (unsigned int)buffer_poll(a1, a2, *(_QWORD *)(a3 + 32), 0LL) )
{
close(*(_DWORD *)(a3 + 24));
*(_DWORD *)(a3 + 24) = -1;
}
}
}

original_code:
void
server_job_callback(int fd, int events, void *data)
{
 struct job *job = data;
 if (job->fd == -1)
  return;
 if (buffer_poll(fd, events, job->out, ((void *)0)) != 0) {
  close(job->fd);
  job->fd = -1;
 }
}

variable_types: fd int

variable_types: events int

variable_types:
data
void *

variable_types: struct job { char *cmd; int pid; int status; struct client { struct imsgbuf { struct { struct imsg_fd { struct { struct imsg_fd *tqe_next; struct imsg_fd **tqe_prev; } entry; int fd; } *tqh_first; struct imsg_fd **tqh_last; } fds; struct buf_read { unsigned char buf[65535]; unsigned char *rptr; unsigned long wpos; } r; struct msgbuf { struct { struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; } w; int fd; int pid; } ibuf; struct timeval { long tv_sec; long tv_usec; } creation_time; struct timeval activity_time; struct environ { struct environ_entry { char *name; char *value; struct { struct environ_entry *rbe_left; struct environ_entry *rbe_right; struct environ_entry *rbe_parent; int rbe_color; } entry; } *rbh_root; } environ; char *title; char *cwd; struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term { char *name; unsigned int references; struct tty_code { enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 } type; union { char *string; int number; int flag; } value; } codes[-1]; int flags; struct { struct tty_term *sle_next; } entry; } *term; int fd; struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; } *in; struct buffer *out; int log_fd; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } tio; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval key_timer; unsigned long ksize; struct tty_keys { struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; } *rbh_root; } ktree; } tty; struct timeval repeat_timer; struct timeval status_timer; struct jobs { struct job *rbh_root; } status_jobs; struct screen { char *title; struct grid { int flags; unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; struct grid_line { unsigned int cellsize; struct grid_cell *celldata; unsigned int utf8size; struct grid_utf8 { unsigned char width; unsigned char data[9]; } *utf8data; int flags; } *linedata; } *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; } sel; } status; int flags; struct timeval identify_timer; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callbackfn)(void *, char *); void (*prompt_freefn)(void *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data { struct mode_key_tree { struct mode_key_binding { int key; int mode; enum mode_key_cmd { MODEKEY_NONE=0, MODEKEY_OTHER=1, MODEKEYEDIT_BACKSPACE=2, MODEKEYEDIT_CANCEL=3, MODEKEYEDIT_COMPLETE=4, MODEKEYEDIT_CURSORLEFT=5, MODEKEYEDIT_CURSORRIGHT=6, MODEKEYEDIT_DELETE=7, MODEKEYEDIT_DELETELINE=8, MODEKEYEDIT_DELETETOENDOFLINE=9, MODEKEYEDIT_ENDOFLINE=10, MODEKEYEDIT_ENTER=11, MODEKEYEDIT_HISTORYDOWN=12, MODEKEYEDIT_HISTORYUP=13, MODEKEYEDIT_PASTE=14, MODEKEYEDIT_STARTOFLINE=15, MODEKEYEDIT_SWITCHMODE=16, MODEKEYEDIT_SWITCHMODEAPPEND=17, MODEKEYEDIT_TRANSPOSECHARS=18, MODEKEYCHOICE_CANCEL=19, MODEKEYCHOICE_CHOOSE=20, MODEKEYCHOICE_DOWN=21, MODEKEYCHOICE_PAGEDOWN=22, MODEKEYCHOICE_PAGEUP=23, MODEKEYCHOICE_UP=24, MODEKEYCOPY_BACKTOINDENTATION=25, MODEKEYCOPY_BOTTOMLINE=26, MODEKEYCOPY_CANCEL=27, MODEKEYCOPY_CLEARSELECTION=28, MODEKEYCOPY_COPYSELECTION=29, MODEKEYCOPY_DOWN=30, MODEKEYCOPY_ENDOFLINE=31, MODEKEYCOPY_GOTOLINE=32, MODEKEYCOPY_HALFPAGEDOWN=33, MODEKEYCOPY_HALFPAGEUP=34, MODEKEYCOPY_LEFT=35, MODEKEYCOPY_MIDDLELINE=36, MODEKEYCOPY_NEXTPAGE=37, MODEKEYCOPY_NEXTWORD=38, MODEKEYCOPY_PREVIOUSPAGE=39, MODEKEYCOPY_PREVIOUSWORD=40, MODEKEYCOPY_RIGHT=41, MODEKEYCOPY_SCROLLDOWN=42, MODEKEYCOPY_SCROLLUP=43, MODEKEYCOPY_SEARCHAGAIN=44, MODEKEYCOPY_SEARCHDOWN=45, MODEKEYCOPY_SEARCHUP=46, MODEKEYCOPY_STARTOFLINE=47, MODEKEYCOPY_STARTSELECTION=48, MODEKEYCOPY_TOPLINE=49, MODEKEYCOPY_UP=50 } cmd; struct { struct mode_key_binding *spe_left; struct mode_key_binding *spe_right; } entry; } *sph_root; } *tree; int mode; } prompt_mdata; struct session { char *name; struct timeval creation_time; struct timeval activity_time; unsigned int sx; unsigned int sy; struct winlink { int idx; struct window { char *name; struct timeval name_timer; struct window_pane { struct window *window; struct layout_cell { enum layout_type { LAYOUT_LEFTRIGHT=0, LAYOUT_TOPBOTTOM=1, LAYOUT_WINDOWPANE=2 } type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells { struct layout_cell *tqh_first; struct layout_cell **tqh_last; } cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; } *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx { struct window_pane *wp; struct screen_write_ctx { struct window_pane *wp; struct screen *s; } ctx; unsigned char *buf; unsigned long len; unsigned long off; unsigned long was; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; struct utf8_data { unsigned char data[9]; unsigned long have; unsigned long size; unsigned int width; } utf8data; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg { unsigned char data[64]; unsigned long used; } *list; unsigned int num; unsigned long space; } args; } ictx; int pipe_fd; struct buffer *pipe_buf; unsigned long pipe_off; struct screen *screen; struct screen base; unsigned int saved_cx; unsigned int saved_cy; struct grid *saved_grid; struct grid_cell saved_cell; struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, struct client *, struct mouse_event { unsigned char b; unsigned char x; unsigned char y; } *); void (*timer)(struct window_pane *); } *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; } *active; struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; } panes; int lastlayout; struct layout_cell *layout_root; unsigned int sx; unsigned int sy; int flags; struct options { struct options_tree { struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_DATA=2 } type; char *str; long long num; void *data; void (*freefn)(void *); struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; } *sph_root; } tree; struct options *parent; } options; unsigned int references; } *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *tqe_next; struct winlink **tqe_prev; } sentry; } *curw; struct winlink_stack { struct winlink *tqh_first; struct winlink **tqh_last; } lastw; struct winlinks { struct winlink *rbh_root; } windows; struct options options; struct paste_stack { struct paste_buffer { char *data; unsigned long size; } **list; unsigned int num; unsigned long space; } buffers; struct { struct session_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; } *slh_first; } alerts; int flags; struct termios *tio; struct environ environ; int references; struct { struct session *tqe_next; struct session **tqe_prev; } gentry; } *session; int references; } *client; int fd; struct buffer *out; void (*callbackfn)(struct job *); void (*freefn)(void *); void *data; int flags; struct { struct job *rbe_left; struct job *rbe_right; struct job *rbe_parent; int rbe_color; } entry; struct { struct job *sle_next; } lentry; } *

user_defined_types: struct job { char *cmd; int pid; int status; struct client *client; int fd; struct buffer *out; void (*callbackfn)(struct job *); void (*freefn)(void *); void *data; int flags; struct { struct job *rbe_left; struct job *rbe_right; struct job *rbe_parent; int rbe_color; } entry; struct { struct job *sle_next; } lentry; }

user_defined_types: struct client { struct imsgbuf ibuf; struct timeval creation_time; struct timeval activity_time; struct environ environ; char *title; char *cwd; struct tty tty; struct timeval repeat_timer; struct timeval status_timer; struct jobs status_jobs; struct screen status; int flags; struct timeval identify_timer; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callbackfn)(void *, char *); void (*prompt_freefn)(void *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; int references; }

user_defined_types: struct imsgbuf { struct { struct imsg_fd *tqh_first; struct imsg_fd **tqh_last; } fds; struct buf_read r; struct msgbuf w; int fd; int pid; }

user_defined_types: struct environ { struct environ_entry *rbh_root; }

user_defined_types: struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term *term; int fd; struct buffer *in; struct buffer *out; int log_fd; struct termios tio; struct grid_cell cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval key_timer; unsigned long ksize; struct tty_keys ktree; }

user_defined_types: struct screen { char *title; struct grid *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel sel; }

user_defined_types: struct mode_key_data { struct mode_key_tree *tree; int mode; }

user_defined_types: struct msgbuf { struct { struct buf *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; }

user_defined_types: struct session { char *name; struct timeval creation_time; struct timeval activity_time; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; struct termios *tio; struct environ environ; int references; struct { struct session *tqe_next; struct session **tqe_prev; } gentry; }

user_defined_types: struct tty_term { char *name; unsigned int references; struct tty_code codes[-1]; int flags; struct { struct tty_term *sle_next; } entry; }

user_defined_types: struct grid { int flags; unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; struct grid_line *linedata; }

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

user_defined_types: struct paste_stack { struct paste_buffer **list; unsigned int num; unsigned long space; }

user_defined_types: struct winlink { int idx; struct window *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *tqe_next; struct winlink **tqe_prev; } sentry; }

user_defined_types: struct grid_line { unsigned int cellsize; struct grid_cell *celldata; unsigned int utf8size; struct grid_utf8 *utf8data; int flags; }

user_defined_types: struct window { char *name; struct timeval name_timer; struct window_pane *active; struct window_panes panes; int lastlayout; struct layout_cell *layout_root; unsigned int sx; unsigned int sy; int flags; struct options options; unsigned int references; }

user_defined_types: struct options { struct options_tree tree; struct options *parent; }

user_defined_types: struct window_pane { struct window *window; struct layout_cell *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx ictx; int pipe_fd; struct buffer *pipe_buf; unsigned long pipe_off; struct screen *screen; struct screen base; unsigned int saved_cx; unsigned int saved_cy; struct grid *saved_grid; struct grid_cell saved_cell; struct window_mode *mode; void *modedata; struct { struct window_pane *tqe_next; struct window_pane **tqe_prev; } entry; }

user_defined_types: struct input_ctx { struct window_pane *wp; struct screen_write_ctx ctx; unsigned char *buf; unsigned long len; unsigned long off; unsigned long was; struct grid_cell cell; struct grid_cell saved_cell; unsigned int saved_cx; unsigned int saved_cy; unsigned char *string_buf; unsigned long string_len; int string_type; struct utf8_data utf8data; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }

user_defined_types: struct layout_cell { enum layout_type type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; }

user_defined_types: struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, unsigned int, unsigned int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, struct client *, struct mouse_event *); void (*timer)(struct window_pane *); }


decompiled_code:
__int64 server_job_prepare()
{
__int64 i; // rbx
__int64 v1; // rdi
__int64 result; // rax

for ( i = all_jobs; i; i = *(_QWORD *)(i + 104) )
{
v1 = *(unsigned int *)(i + 24);
if ( (_DWORD)v1 != -1 )
result = server_poll_add(v1, 1LL, server_job_callback, i);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // rbx
__int64 v1; // rdi
__int64 result; // rax

for ( i = all_jobs; i; i = *(_QWORD *)(i + 104) )
{
v1 = *(unsigned int *)(i + 24);
if ( (_DWORD)v1 != -1 )
result = server_poll_add(v1, 1LL, server_job_callback, i);
}
return result;
}

original_code:
void
server_job_prepare(void)
{
 struct job *job;
 for((job) = ((&all_jobs)->slh_first); (job) != ((void *)0); (job) = ((job)->lentry.sle_next)) {
  if (job->fd == -1)
   continue;
  server_poll_add(job->fd, 0x001, server_job_callback, job);
 }
}

canonical_original_code:
void server_job_prepare()
{
 struct job *job;
 for((job) = ((&all_jobs)->slh_first); (job) != ((void *)0); (job) = ((job)->lentry.sle_next)) {
  if (job->fd == -1)
   continue;
  server_poll_add(job->fd, 0x001, server_job_callback, job);
 }
}

user_defined_types: struct job { char *cmd; int pid; int status; struct client *client; int fd; struct buffer *out; void (*callbackfn)(struct job *); void (*freefn)(void *); void *data; int flags; struct { struct job *rbe_left; struct job *rbe_right; struct job *rbe_parent; int rbe_color; } entry; struct { struct job *sle_next; } lentry; }

user_defined_types: struct client { struct imsgbuf ibuf; struct timeval creation_time; struct timeval activity_time; struct environ environ; char *title; char *cwd; struct tty tty; struct timeval repeat_timer; struct timeval status_timer; struct jobs status_jobs; struct screen status; int flags; struct timeval identify_timer; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callbackfn)(void *, char *); void (*prompt_freefn)(void *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; int references; }

user_defined_types: struct imsgbuf { struct { struct imsg_fd *tqh_first; struct imsg_fd **tqh_last; } fds; struct buf_read r; struct msgbuf w; int fd; int pid; }

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

user_defined_types: struct environ { struct environ_entry *rbh_root; }

user_defined_types: struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term *term; int fd; struct buffer *in; struct buffer *out; int log_fd; struct termios tio; struct grid_cell cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval key_timer; unsigned long ksize; struct tty_keys ktree; }

user_defined_types: struct buf_read { unsigned char buf[65535]; unsigned char *rptr; unsigned long wpos; }

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

user_defined_types: struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; }

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; }

user_defined_types: struct environ_entry { char *name; char *value; struct { struct environ_entry *rbe_left; struct environ_entry *rbe_right; struct environ_entry *rbe_parent; int rbe_color; } entry; }

user_defined_types: struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; }

user_defined_types: struct winlink_stack { struct winlink *tqh_first; struct winlink **tqh_last; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

user_defined_types: struct imsg_fd { struct { struct imsg_fd *tqe_next; struct imsg_fd **tqe_prev; } entry; int fd; }

user_defined_types: struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; }

user_defined_types: struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; }

user_defined_types: struct tty_code { enum tty_code_type type; union { char *string; int number; int flag; } value; }

user_defined_types: struct mode_key_binding { int key; int mode; enum mode_key_cmd cmd; struct { struct mode_key_binding *spe_left; struct mode_key_binding *spe_right; } entry; }

user_defined_types: struct session_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; }

user_defined_types: enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 }

user_defined_types: enum mode_key_cmd { MODEKEY_NONE=0, MODEKEY_OTHER=1, MODEKEYEDIT_BACKSPACE=2, MODEKEYEDIT_CANCEL=3, MODEKEYEDIT_COMPLETE=4, MODEKEYEDIT_CURSORLEFT=5, MODEKEYEDIT_CURSORRIGHT=6, MODEKEYEDIT_DELETE=7, MODEKEYEDIT_DELETELINE=8, MODEKEYEDIT_DELETETOENDOFLINE=9, MODEKEYEDIT_ENDOFLINE=10, MODEKEYEDIT_ENTER=11, MODEKEYEDIT_HISTORYDOWN=12, MODEKEYEDIT_HISTORYUP=13, MODEKEYEDIT_PASTE=14, MODEKEYEDIT_STARTOFLINE=15, MODEKEYEDIT_SWITCHMODE=16, MODEKEYEDIT_SWITCHMODEAPPEND=17, MODEKEYEDIT_TRANSPOSECHARS=18, MODEKEYCHOICE_CANCEL=19, MODEKEYCHOICE_CHOOSE=20, MODEKEYCHOICE_DOWN=21, MODEKEYCHOICE_PAGEDOWN=22, MODEKEYCHOICE_PAGEUP=23, MODEKEYCHOICE_UP=24, MODEKEYCOPY_BACKTOINDENTATION=25, MODEKEYCOPY_BOTTOMLINE=26, MODEKEYCOPY_CANCEL=27, MODEKEYCOPY_CLEARSELECTION=28, MODEKEYCOPY_COPYSELECTION=29, MODEKEYCOPY_DOWN=30, MODEKEYCOPY_ENDOFLINE=31, MODEKEYCOPY_GOTOLINE=32, MODEKEYCOPY_HALFPAGEDOWN=33, MODEKEYCOPY_HALFPAGEUP=34, MODEKEYCOPY_LEFT=35, MODEKEYCOPY_MIDDLELINE=36, MODEKEYCOPY_NEXTPAGE=37, MODEKEYCOPY_NEXTWORD=38, MODEKEYCOPY_PREVIOUSPAGE=39, MODEKEYCOPY_PREVIOUSWORD=40, MODEKEYCOPY_RIGHT=41, MODEKEYCOPY_SCROLLDOWN=42, MODEKEYCOPY_SCROLLUP=43, MODEKEYCOPY_SEARCHAGAIN=44, MODEKEYCOPY_SEARCHDOWN=45, MODEKEYCOPY_SEARCHUP=46, MODEKEYCOPY_STARTOFLINE=47, MODEKEYCOPY_STARTSELECTION=48, MODEKEYCOPY_TOPLINE=49, MODEKEYCOPY_UP=50 }

user_defined_types: struct paste_buffer { char *data; unsigned long size; }

user_defined_types: struct grid_utf8 { unsigned char width; unsigned char data[9]; }

user_defined_types: struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; }

user_defined_types: struct options_tree { struct options_entry *sph_root; }

user_defined_types: struct screen_write_ctx { struct window_pane *wp; struct screen *s; }

user_defined_types: struct utf8_data { unsigned char data[9]; unsigned long have; unsigned long size; unsigned int width; }

user_defined_types: struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_DATA=2 } type; char *str; long long num; void *data; void (*freefn)(void *); struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; }

user_defined_types: enum layout_type { LAYOUT_LEFTRIGHT=0, LAYOUT_TOPBOTTOM=1, LAYOUT_WINDOWPANE=2 }

user_defined_types: struct layout_cells { struct layout_cell *tqh_first; struct layout_cell **tqh_last; }

user_defined_types: struct input_arg { unsigned char data[64]; unsigned long used; }

user_defined_types: struct mouse_event { unsigned char b; unsigned char x; unsigned char y; }