original_code:
void
layout_left_vertical(struct window *w, int active_changed)
{
 struct window_pane *wp;
 u_int i, n, height, yoff;
 if (active_changed)
  return;
 n = window_count_panes(w);
 if (n == 0)
  return;
 if (n == 1 || w->sx < 82 + 4) {
  layout_active_only(w, active_changed);
  return;
 }
 n--;
 if (w->sy / n < 4) {
  height = 4;
  n = w->sy / 4;
 } else
  height = w->sy / n;
 i = yoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  if (wp == ((&w->panes)->tqh_first)) {
   wp->xoff = 0;
   wp->yoff = 0;
   window_pane_resize(wp, 81, w->sy);
   wp->flags &= ~0x1;
   continue;
  }
  if (i > n) {
   wp->flags |= 0x1;
   continue;
  }
  wp->flags &= ~0x1;
  wp->xoff = 82;
  wp->yoff = yoff;
  if (i != n - 1)
    window_pane_resize(wp, w->sx - 82, height - 1);
  else
    window_pane_resize(wp, w->sx - 82, height);
  i++;
  yoff += height;
 }
 while (yoff++ < w->sy) {
  wp = (*(((struct window_panes *)((&w->panes)->tqh_last))->tqh_last));
  while (wp != ((void *)0) && wp == ((&w->panes)->tqh_first))
   wp = (*(((struct window_panes *)((wp)->entry.tqe_prev))->tqh_last));
  if (wp == ((void *)0))
   break;
  window_pane_resize(wp, wp->sx, wp->sy + 1);
 }
}

canonical_original_code:
void layout_left_vertical(struct window *w, int active_changed)
{
 struct window_pane *wp;
 unsigned int i; unsigned int n; unsigned int height; unsigned int yoff;
 if (active_changed)
  return;
 n = window_count_panes(w);
 if (n == 0)
  return;
 if (n == 1 || w->sx < 82 + 4) {
  layout_active_only(w, active_changed);
  return;
 }
 n--;
 if (w->sy / n < 4) {
  height = 4;
  n = w->sy / 4;
 } else
  height = w->sy / n;
 i = yoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  if (wp == ((&w->panes)->tqh_first)) {
   wp->xoff = 0;
   wp->yoff = 0;
   window_pane_resize(wp, 81, w->sy);
   wp->flags &= ~0x1;
   continue;
  }
  if (i > n) {
   wp->flags |= 0x1;
   continue;
  }
  wp->flags &= ~0x1;
  wp->xoff = 82;
  wp->yoff = yoff;
  if (i != n - 1)
    window_pane_resize(wp, w->sx - 82, height - 1);
  else
    window_pane_resize(wp, w->sx - 82, height);
  i++;
  yoff += height;
 }
 while (yoff++ < w->sy) {
  wp = (*(((struct window_panes *)((&w->panes)->tqh_last))->tqh_last));
  while (wp != ((void *)0) && wp == ((&w->panes)->tqh_first))
   wp = (*(((struct window_panes *)((wp)->entry.tqe_prev))->tqh_last));
  if (wp == ((void *)0))
   break;
  window_pane_resize(wp, wp->sx, wp->sy + 1);
 }
}

variable_types:
i
unsigned int

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 timeval { long tv_sec; long tv_usec; }

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

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_KEY=2 } type; union { char *string; long long number; int key; } value; struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; }

user_defined_types: struct mode_key_data { int type; int flags; }

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 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[8]; }

user_defined_types: struct winlink_stack { struct winlink *slh_first; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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 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: struct paste_buffer { char *data; struct timeval tv; }


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
__int64 __fastcall layout_refresh(__int64 a1)
{
((void (*)(void))(&layouts)[2 * *(unsigned int *)(a1 + 48) + 1])();
return server_redraw_window(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
((void (*)(void))(&layouts)[2 * *(unsigned int *)(a1 + 48) + 1])();
return server_redraw_window(a1);
}

original_code:
void
layout_refresh(struct window *w, __attribute__ ((unused)) int active_changed)
{
 layouts[w->layout].fn(w, active_changed);
 server_redraw_window(w);
}

canonical_original_code:
void layout_refresh(struct window *w, int active_changed)
{
 layouts[w->layout].fn(w, active_changed);
 server_redraw_window(w);
}

variable_types: struct window { char *name; struct timeval { long tv_sec; long tv_usec; } 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 { 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 { unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; unsigned int *size; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } **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; 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; 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 fd; struct buffer *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 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 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_hidden; 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 *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 { 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; 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; } *, 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 options; unsigned int references; } *

return_type: void

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; }

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 *, unsigned char, unsigned char, unsigned char); void (*timer)(struct window_pane *); }

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; struct screen_sel sel; }

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 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_hidden; 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 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 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 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 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; }


decompiled_code:
__int64 __fastcall layout_next(__int64 a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)(a1 + 48) + 1;
if ( v1 > 4 )
{
*(_DWORD *)(a1 + 48) = 0;
window_fit_panes();
window_update_panes(a1);
}
else
{
*(_DWORD *)(a1 + 48) = v1;
}
return layout_refresh(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)(a1 + 48) + 1;
if ( v1 > 4 )
{
*(_DWORD *)(a1 + 48) = 0;
window_fit_panes();
window_update_panes(a1);
}
else
{
*(_DWORD *)(a1 + 48) = v1;
}
return func5(a1);
}

original_code:
void
layout_next(struct window *w)
{
 w->layout++;
 if (w->layout > (sizeof((layouts)) / sizeof((layouts)[0])) - 1) {
  w->layout = 0;
  window_fit_panes(w);
  window_update_panes(w);
 }
 layout_refresh(w, 0);
}

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 buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; }

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 mode_key_data { int type; int flags; }

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 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[8]; }

user_defined_types: struct winlink_stack { struct winlink *slh_first; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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 *sle_next; } sentry; }

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: 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; }


decompiled_code:
__int64 __fastcall layout_set_even_h(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // eax
__int64 v3; // rdx
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // r14
__int64 v8; // rbp
unsigned int v9; // er15
unsigned int v10; // er13
__int64 v11; // rbx
__int64 *v12; // rax
unsigned int v13; // eax
int v14; // [rsp+Ch] [rbp-3Ch]

layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_h", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v3 = *(_DWORD *)(a1 + 176) % (unsigned int)result;
v2 = *(_DWORD *)(a1 + 176) / (unsigned int)result;
v4 = 3;
if ( v2 >= 3 )
v4 = v2;
v14 = v4;
layout_free(a1, "layout_set_even_h", v3);
v5 = layout_create_cell(0LL);
v6 = *(unsigned int *)(a1 + 180);
*(_QWORD *)(a1 + 168) = v5;
v7 = v5;
layout_set_size(v5, *(unsigned int *)(a1 + 176), v6, 0LL, 0LL);
layout_make_node(v7, 0LL);
v8 = *(_QWORD *)(a1 + 144);
if ( v8 )
{
v9 = v4 - 1;
v10 = 0;
do
{
v11 = layout_create_cell(v7);
layout_set_size(v11, v9, *(unsigned int *)(a1 + 180), v10, 0LL);
layout_make_leaf(v11, v8);
v12 = *(__int64 **)(v7 + 48);
v10 += v14;
*(_QWORD *)(v11 + 56) = 0LL;
v8 = *(_QWORD *)(v8 + 456);
*(_QWORD *)(v11 + 64) = v12;
*v12 = v11;
*(_QWORD *)(v7 + 48) = v11 + 56;
}
while ( v8 );
v13 = *(_DWORD *)(a1 + 176);
if ( v13 > v10 - 1 )
{
v7 = **(_QWORD **)(v11 + 64);
layout_resize_adjust(v7, 0LL, v13 + 1 - v10);
}
}
layout_fix_offsets(v7);
layout_fix_panes(a1, *(unsigned int *)(a1 + 176), *(unsigned int *)(a1 + 180));
layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_h", 1LL);
result = server_redraw_window(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // eax
__int64 v3; // rdx
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // r14
__int64 v8; // rbp
unsigned int v9; // er15
unsigned int v10; // er13
__int64 v11; // rbx
__int64 *v12; // rax
unsigned int v13; // eax
int v14; // [rsp+Ch] [rbp-3Ch]

layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_h", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v3 = *(_DWORD *)(a1 + 176) % (unsigned int)result;
v2 = *(_DWORD *)(a1 + 176) / (unsigned int)result;
v4 = 3;
if ( v2 >= 3 )
v4 = v2;
v14 = v4;
layout_free(a1, "layout_set_even_h", v3);
v5 = layout_create_cell(0LL);
v6 = *(unsigned int *)(a1 + 180);
*(_QWORD *)(a1 + 168) = v5;
v7 = v5;
layout_set_size(v5, *(unsigned int *)(a1 + 176), v6, 0LL, 0LL);
layout_make_node(v7, 0LL);
v8 = *(_QWORD *)(a1 + 144);
if ( v8 )
{
v9 = v4 - 1;
v10 = 0;
do
{
v11 = layout_create_cell(v7);
layout_set_size(v11, v9, *(unsigned int *)(a1 + 180), v10, 0LL);
layout_make_leaf(v11, v8);
v12 = *(__int64 **)(v7 + 48);
v10 += v14;
*(_QWORD *)(v11 + 56) = 0LL;
v8 = *(_QWORD *)(v8 + 456);
*(_QWORD *)(v11 + 64) = v12;
*v12 = v11;
*(_QWORD *)(v7 + 48) = v11 + 56;
}
while ( v8 );
v13 = *(_DWORD *)(a1 + 176);
if ( v13 > v10 - 1 )
{
v7 = **(_QWORD **)(v11 + 64);
layout_resize_adjust(v7, 0LL, v13 + 1 - v10);
}
}
layout_fix_offsets(v7);
layout_fix_panes(a1, *(unsigned int *)(a1 + 176), *(unsigned int *)(a1 + 180));
layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_h", 1LL);
result = server_redraw_window(a1);
}
return result;
}

original_code:
void
layout_set_even_h(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc, *lcnew;
 u_int i, n, width, xoff;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 if (w->sx / n < 2 + 1)
  width = 2 + 1;
 else
  width = w->sx / n;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, w->sx, w->sy, 0, 0);
 layout_make_node(lc, LAYOUT_LEFTRIGHT);
 i = xoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  lcnew = layout_create_cell(lc);
  layout_set_size(lcnew, width - 1, w->sy, xoff, 0);
  layout_make_leaf(lcnew, wp);
  do { (lcnew)->entry.tqe_next = ((void *)0); (lcnew)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcnew); (&lc->cells)->tqh_last = &(lcnew)->entry.tqe_next; } while (0);
  i++;
  xoff += width;
 }
 if (w->sx > xoff - 1) {
  lc = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lc, LAYOUT_LEFTRIGHT, w->sx - (xoff - 1));
 }
 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_even_h(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc; struct layout_cell *lcnew;
 unsigned int i; unsigned int n; unsigned int width; unsigned int xoff;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 if (w->sx / n < 2 + 1)
  width = 2 + 1;
 else
  width = w->sx / n;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, w->sx, w->sy, 0, 0);
 layout_make_node(lc, LAYOUT_LEFTRIGHT);
 i = xoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  lcnew = layout_create_cell(lc);
  layout_set_size(lcnew, width - 1, w->sy, xoff, 0);
  layout_make_leaf(lcnew, wp);
  do { (lcnew)->entry.tqe_next = ((void *)0); (lcnew)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcnew); (&lc->cells)->tqh_last = &(lcnew)->entry.tqe_next; } while (0);
  i++;
  xoff += width;
 }
 if (w->sx > xoff - 1) {
  lc = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lc, LAYOUT_LEFTRIGHT, w->sx - (xoff - 1));
 }
 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: 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; } *

variable_types: struct window_pane { struct window { char *name; struct timeval { long tv_sec; long tv_usec; } name_timer; struct window_pane *active; struct window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; } panes; int lastlayout; 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_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 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 { 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 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; } *

variable_types: 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 { struct window { char *name; struct timeval { long tv_sec; long tv_usec; } name_timer; struct window_pane *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 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 { 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 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; } *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; } *

variable_types:
n
unsigned int

variable_types:
width
unsigned int

variable_types:
xoff
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 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 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 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 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 paste_stack { struct paste_buffer **list; unsigned int num; unsigned long space; }

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_even_v(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // eax
__int64 v3; // rdx
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // r14
__int64 v8; // rbp
unsigned int v9; // er15
unsigned int v10; // er13
__int64 v11; // rbx
__int64 *v12; // rax
unsigned int v13; // eax
int v14; // [rsp+Ch] [rbp-3Ch]

layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_v", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v3 = *(_DWORD *)(a1 + 180) % (unsigned int)result;
v2 = *(_DWORD *)(a1 + 180) / (unsigned int)result;
v4 = 3;
if ( v2 >= 3 )
v4 = v2;
v14 = v4;
layout_free(a1, "layout_set_even_v", v3);
v5 = layout_create_cell(0LL);
v6 = *(unsigned int *)(a1 + 180);
*(_QWORD *)(a1 + 168) = v5;
v7 = v5;
layout_set_size(v5, *(unsigned int *)(a1 + 176), v6, 0LL, 0LL);
layout_make_node(v7, 1LL);
v8 = *(_QWORD *)(a1 + 144);
if ( v8 )
{
v9 = v4 - 1;
v10 = 0;
do
{
v11 = layout_create_cell(v7);
layout_set_size(v11, *(unsigned int *)(a1 + 176), v9, 0LL, v10);
layout_make_leaf(v11, v8);
v12 = *(__int64 **)(v7 + 48);
v10 += v14;
*(_QWORD *)(v11 + 56) = 0LL;
v8 = *(_QWORD *)(v8 + 456);
*(_QWORD *)(v11 + 64) = v12;
*v12 = v11;
*(_QWORD *)(v7 + 48) = v11 + 56;
}
while ( v8 );
v13 = *(_DWORD *)(a1 + 180);
if ( v13 > v10 - 1 )
{
v7 = **(_QWORD **)(v11 + 64);
layout_resize_adjust(v7, 1LL, v13 + 1 - v10);
}
}
layout_fix_offsets(v7);
layout_fix_panes(a1, *(unsigned int *)(a1 + 176), *(unsigned int *)(a1 + 180));
layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_v", 1LL);
result = server_redraw_window(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // eax
__int64 v3; // rdx
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // r14
__int64 v8; // rbp
unsigned int v9; // er15
unsigned int v10; // er13
__int64 v11; // rbx
__int64 *v12; // rax
unsigned int v13; // eax
int v14; // [rsp+Ch] [rbp-3Ch]

layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_v", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v3 = *(_DWORD *)(a1 + 180) % (unsigned int)result;
v2 = *(_DWORD *)(a1 + 180) / (unsigned int)result;
v4 = 3;
if ( v2 >= 3 )
v4 = v2;
v14 = v4;
layout_free(a1, "layout_set_even_v", v3);
v5 = layout_create_cell(0LL);
v6 = *(unsigned int *)(a1 + 180);
*(_QWORD *)(a1 + 168) = v5;
v7 = v5;
layout_set_size(v5, *(unsigned int *)(a1 + 176), v6, 0LL, 0LL);
layout_make_node(v7, 1LL);
v8 = *(_QWORD *)(a1 + 144);
if ( v8 )
{
v9 = v4 - 1;
v10 = 0;
do
{
v11 = layout_create_cell(v7);
layout_set_size(v11, *(unsigned int *)(a1 + 176), v9, 0LL, v10);
layout_make_leaf(v11, v8);
v12 = *(__int64 **)(v7 + 48);
v10 += v14;
*(_QWORD *)(v11 + 56) = 0LL;
v8 = *(_QWORD *)(v8 + 456);
*(_QWORD *)(v11 + 64) = v12;
*v12 = v11;
*(_QWORD *)(v7 + 48) = v11 + 56;
}
while ( v8 );
v13 = *(_DWORD *)(a1 + 180);
if ( v13 > v10 - 1 )
{
v7 = **(_QWORD **)(v11 + 64);
layout_resize_adjust(v7, 1LL, v13 + 1 - v10);
}
}
layout_fix_offsets(v7);
layout_fix_panes(a1, *(unsigned int *)(a1 + 176), *(unsigned int *)(a1 + 180));
layout_print_cell(*(_QWORD *)(a1 + 168), "layout_set_even_v", 1LL);
result = server_redraw_window(a1);
}
return result;
}

original_code:
void
layout_set_even_v(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc, *lcnew;
 u_int i, n, height, yoff;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 if (w->sy / n < 2 + 1)
  height = 2 + 1;
 else
  height = w->sy / n;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, w->sx, w->sy, 0, 0);
 layout_make_node(lc, LAYOUT_TOPBOTTOM);
 i = yoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  lcnew = layout_create_cell(lc);
  layout_set_size(lcnew, w->sx, height - 1, 0, yoff);
  layout_make_leaf(lcnew, wp);
  do { (lcnew)->entry.tqe_next = ((void *)0); (lcnew)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcnew); (&lc->cells)->tqh_last = &(lcnew)->entry.tqe_next; } while (0);
  i++;
  yoff += height;
 }
 if (w->sy > yoff - 1) {
  lc = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lc, LAYOUT_TOPBOTTOM, w->sy - (yoff - 1));
 }
 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_even_v(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc; struct layout_cell *lcnew;
 unsigned int i; unsigned int n; unsigned int height; unsigned int yoff;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 if (w->sy / n < 2 + 1)
  height = 2 + 1;
 else
  height = w->sy / n;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, w->sx, w->sy, 0, 0);
 layout_make_node(lc, LAYOUT_TOPBOTTOM);
 i = yoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  lcnew = layout_create_cell(lc);
  layout_set_size(lcnew, w->sx, height - 1, 0, yoff);
  layout_make_leaf(lcnew, wp);
  do { (lcnew)->entry.tqe_next = ((void *)0); (lcnew)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcnew); (&lc->cells)->tqh_last = &(lcnew)->entry.tqe_next; } while (0);
  i++;
  yoff += height;
 }
 if (w->sy > yoff - 1) {
  lc = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lc, LAYOUT_TOPBOTTOM, w->sy - (yoff - 1));
 }
 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:
height
unsigned int

variable_types:
yoff
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 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 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 paste_buffer { char *data; unsigned long size; }


decompiled_code:
__int64 __fastcall layout_set_main_h(__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_h", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v2 = *(_DWORD *)(a1 + 176);
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-height", v2 % v7);
v9 = 3 * v6;
v10 = *(_DWORD *)(a1 + 180);
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-height", v9);
v15 = layout_create_cell(0LL);
*(_QWORD *)(a1 + 168) = v15;
v16 = v15;
v36 = v15;
v38 = v11 + v32;
layout_set_size(v15, *(unsigned int *)(a1 + 176), (unsigned int)(v11 + v32), 0LL, 0LL);
layout_make_node(v16, 1LL);
v17 = layout_create_cell(v16);
layout_set_size(v17, *(unsigned int *)(a1 + 176), v12, 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, *(unsigned int *)(a1 + 176), v14, 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, 0LL);
v23 = v21;
for ( j = 0; ; ++j )
{
v25 = layout_create_cell(v23);
layout_set_size(v25, (unsigned int)(v35 - 1), v14, 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 + 176);
v29 = v35 * v27 - 1;
if ( v28 > v29 )
layout_resize_adjust(**(_QWORD **)(v25 + 64), 0LL, v28 - v29);
}
if ( v37 == v33 )
break;
}
v30 = *(_DWORD *)(a1 + 180);
if ( v30 > v38 - 1 )
layout_resize_adjust(**(_QWORD **)(*(_QWORD *)(v36 + 48) + 8LL), 1LL, 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_h", 1LL);
result = server_redraw_window(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__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_h", 1LL);
result = window_count_panes(a1);
if ( (unsigned int)result > 1 )
{
v2 = *(_DWORD *)(a1 + 176);
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-height", v2 % v7);
v9 = 3 * v6;
v10 = *(_DWORD *)(a1 + 180);
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-height", v9);
v15 = layout_create_cell(0LL);
*(_QWORD *)(a1 + 168) = v15;
v16 = v15;
v36 = v15;
v38 = v11 + v32;
layout_set_size(v15, *(unsigned int *)(a1 + 176), (unsigned int)(v11 + v32), 0LL, 0LL);
layout_make_node(v16, 1LL);
v17 = layout_create_cell(v16);
layout_set_size(v17, *(unsigned int *)(a1 + 176), v12, 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, *(unsigned int *)(a1 + 176), v14, 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, 0LL);
v23 = v21;
for ( j = 0; ; ++j )
{
v25 = layout_create_cell(v23);
layout_set_size(v25, (unsigned int)(v35 - 1), v14, 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 + 176);
v29 = v35 * v27 - 1;
if ( v28 > v29 )
layout_resize_adjust(**(_QWORD **)(v25 + 64), 0LL, v28 - v29);
}
if ( v37 == v33 )
break;
}
v30 = *(_DWORD *)(a1 + 180);
if ( v30 > v38 - 1 )
layout_resize_adjust(**(_QWORD **)(*(_QWORD *)(v36 + 48) + 8LL), 1LL, 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_h", 1LL);
result = server_redraw_window(a1);
}
return result;
}

original_code:
void
layout_set_main_h(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc, *lcmain, *lcrow, *lcchild;
 u_int n, mainheight, width, height, used;
 u_int i, j, columns, rows, totalrows;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 n--;
 columns = w->sx / (2 + 1);
 rows = 1 + (n - 1) / columns;
 columns = 1 + (n - 1) / rows;
 width = w->sx / columns;
 mainheight = options_get_number(&w->options, "main-pane-height") + 1;
 if (mainheight < 2 + 1)
  mainheight = 2 + 1;
 totalrows = rows * (2 + 1) - 1;
 if (mainheight + totalrows > w->sy) {
  if (totalrows + 2 + 1 > w->sy)
   mainheight = 2 + 2;
  else
   mainheight = w->sy - totalrows;
  height = 2 + 1;
 } else
  height = (w->sy - mainheight) / rows;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, w->sx, mainheight + rows * height, 0, 0);
 layout_make_node(lc, LAYOUT_TOPBOTTOM);
 lcmain = layout_create_cell(lc);
 layout_set_size(lcmain, w->sx, mainheight - 1, 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 < rows; j++) {
  if (wp == ((void *)0))
   break;
  lcrow = layout_create_cell(lc);
  layout_set_size(lcrow, w->sx, height - 1, 0, 0);
  do { (lcrow)->entry.tqe_next = ((void *)0); (lcrow)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcrow); (&lc->cells)->tqh_last = &(lcrow)->entry.tqe_next; } while (0);
  if (columns == 1) {
   layout_make_leaf(lcrow, wp);
   wp = ((wp)->entry.tqe_next);
   continue;
  }
  layout_make_node(lcrow, LAYOUT_LEFTRIGHT);
  for (i = 0; i < columns; i++) {
   lcchild = layout_create_cell(lcrow);
   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 = (&lcrow->cells)->tqh_last; *(&lcrow->cells)->tqh_last = (lcchild); (&lcrow->cells)->tqh_last = &(lcchild)->entry.tqe_next; } while (0);
   if ((wp = ((wp)->entry.tqe_next)) == ((void *)0))
    break;
  }
  if (i == columns)
   i--;
   used = ((i + 1) * width) - 1;
   if (w->sx <= used)
    continue;
   lcchild = (*(((struct layout_cells *)((&lcrow->cells)->tqh_last))->tqh_last));
   layout_resize_adjust(lcchild, LAYOUT_LEFTRIGHT, w->sx - used);
 }
 used = mainheight + (rows * height) - 1;
 if (w->sy > used) {
  lcrow = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lcrow, LAYOUT_TOPBOTTOM, w->sy - 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_h(struct window *w)
{
 struct window_pane *wp;
 struct layout_cell *lc; struct layout_cell *lcmain; struct layout_cell *lcrow; struct layout_cell *lcchild;
 unsigned int n; unsigned int mainheight; unsigned int width; unsigned int height; unsigned int used;
 unsigned int i; unsigned int j; unsigned int columns; unsigned int rows; unsigned int totalrows;
 layout_print_cell(w->layout_root, __func__, 1);
 n = window_count_panes(w);
 if (n <= 1)
  return;
 n--;
 columns = w->sx / (2 + 1);
 rows = 1 + (n - 1) / columns;
 columns = 1 + (n - 1) / rows;
 width = w->sx / columns;
 mainheight = options_get_number(&w->options, "main-pane-height") + 1;
 if (mainheight < 2 + 1)
  mainheight = 2 + 1;
 totalrows = rows * (2 + 1) - 1;
 if (mainheight + totalrows > w->sy) {
  if (totalrows + 2 + 1 > w->sy)
   mainheight = 2 + 2;
  else
   mainheight = w->sy - totalrows;
  height = 2 + 1;
 } else
  height = (w->sy - mainheight) / rows;
 layout_free(w);
 lc = w->layout_root = layout_create_cell(((void *)0));
 layout_set_size(lc, w->sx, mainheight + rows * height, 0, 0);
 layout_make_node(lc, LAYOUT_TOPBOTTOM);
 lcmain = layout_create_cell(lc);
 layout_set_size(lcmain, w->sx, mainheight - 1, 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 < rows; j++) {
  if (wp == ((void *)0))
   break;
  lcrow = layout_create_cell(lc);
  layout_set_size(lcrow, w->sx, height - 1, 0, 0);
  do { (lcrow)->entry.tqe_next = ((void *)0); (lcrow)->entry.tqe_prev = (&lc->cells)->tqh_last; *(&lc->cells)->tqh_last = (lcrow); (&lc->cells)->tqh_last = &(lcrow)->entry.tqe_next; } while (0);
  if (columns == 1) {
   layout_make_leaf(lcrow, wp);
   wp = ((wp)->entry.tqe_next);
   continue;
  }
  layout_make_node(lcrow, LAYOUT_LEFTRIGHT);
  for (i = 0; i < columns; i++) {
   lcchild = layout_create_cell(lcrow);
   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 = (&lcrow->cells)->tqh_last; *(&lcrow->cells)->tqh_last = (lcchild); (&lcrow->cells)->tqh_last = &(lcchild)->entry.tqe_next; } while (0);
   if ((wp = ((wp)->entry.tqe_next)) == ((void *)0))
    break;
  }
  if (i == columns)
   i--;
   used = ((i + 1) * width) - 1;
   if (w->sx <= used)
    continue;
   lcchild = (*(((struct layout_cells *)((&lcrow->cells)->tqh_last))->tqh_last));
   layout_resize_adjust(lcchild, LAYOUT_LEFTRIGHT, w->sx - used);
 }
 used = mainheight + (rows * height) - 1;
 if (w->sy > used) {
  lcrow = (*(((struct layout_cells *)((&lc->cells)->tqh_last))->tqh_last));
  layout_resize_adjust(lcrow, LAYOUT_TOPBOTTOM, w->sy - 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:
mainheight
unsigned int

variable_types:
used
unsigned int

variable_types:
j
unsigned int

variable_types:
columns
unsigned int

variable_types:
rows
unsigned int

variable_types:
totalrows
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 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 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 paste_stack { struct paste_buffer **list; unsigned int num; unsigned long space; }

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; }