decompiled_code:
__int64 __fastcall cmd_copy_buffer_free(__int64 a1)
{
_QWORD *v1; // rbx

v1 = *(_QWORD **)(a1 + 8);
if ( *v1 )
((void (*)(void))xfree)();
if ( v1[1] )
((void (*)(void))xfree)();
return xfree(v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_QWORD *v1; // rbx

v1 = *(_QWORD **)(a1 + 8);
if ( *v1 )
((void (*)(void))xfree)();
if ( v1[1] )
((void (*)(void))xfree)();
return xfree(v1);
}

original_code:
void
cmd_copy_buffer_free(struct cmd *self)
{
 struct cmd_copy_buffer_data *data = self->data;
 if (data->dst_session != ((void *)0))
  xfree(data->dst_session);
 if (data->src_session != ((void *)0))
  xfree(data->src_session);
 xfree(data);
}

variable_types: struct cmd { struct cmd_entry { char *name; char *alias; char *usage; int flags; unsigned long chflags; void (*init)(struct cmd *, int); int (*parse)(struct cmd *, int, char **, char **); int (*exec)(struct cmd *, struct cmd_ctx { 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 { 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 { 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; } *curclient; struct client *cmdclient; struct msg_command_data { int pid; unsigned int idx; int argc; char argv[2048]; } *msgdata; void (*print)(struct cmd_ctx *, char *, ...); void (*info)(struct cmd_ctx *, char *, ...); void (*error)(struct cmd_ctx *, char *, ...); } *); 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; } *

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_copy_buffer_data { char *dst_session; char *src_session; int dst_idx; int src_idx; }

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

user_defined_types: struct cmd_ctx { struct client *curclient; struct client *cmdclient; 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 { 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 tty_keys { struct tty_key *rbh_root; }

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 tty_code { enum tty_code_type type; union { char *string; int number; int flag; } value; }

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 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 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 options_tree { struct options_entry *sph_root; }

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


repo: ThomasAdam/tmux-ARCHIVED

original_code:
size_t
cmd_copy_buffer_print(struct cmd *self, char *buf, size_t len)
{
 struct cmd_copy_buffer_data *data = self->data;
 size_t off = 0;
 off += xsnprintf(buf, len, "%s", self->entry->name);
 if (data == ((void *)0))
  return (off);
 if (off < len && data->src_idx != -1) {
  off += xsnprintf(buf + off, len - off, " -a %d",
     data->src_idx);
 }
 if (off < len && data->dst_idx != -1) {
  off += xsnprintf(buf + off, len - off, " -b %d",
     data->dst_idx);
 }
 if (off < len && data->src_session != ((void *)0)) {
  off += cmd_prarg(buf + off, len - off, " -s ",
     data->src_session);
 }
 if (off < len && data->dst_session != ((void *)0)) {
  off += cmd_prarg(buf + off, len - off, " -t ",
     data->dst_session);
 }
 return (off);
}

canonical_original_code:
unsigned long cmd_copy_buffer_print(struct cmd *self, char *buf, unsigned long len)
{
 struct cmd_copy_buffer_data *data = self->data;
 unsigned long off = 0;
 off += xsnprintf(buf, len, "%s", self->entry->name);
 if (data == ((void *)0))
  return (off);
 if (off < len && data->src_idx != -1) {
  off += xsnprintf(buf + off, len - off, " -a %d",
     data->src_idx);
 }
 if (off < len && data->dst_idx != -1) {
  off += xsnprintf(buf + off, len - off, " -b %d",
     data->dst_idx);
 }
 if (off < len && data->src_session != ((void *)0)) {
  off += cmd_prarg(buf + off, len - off, " -s ",
     data->src_session);
 }
 if (off < len && data->dst_session != ((void *)0)) {
  off += cmd_prarg(buf + off, len - off, " -t ",
     data->dst_session);
 }
 return (off);
}

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types: struct cmd_copy_buffer_data { char *dst_session; char *src_session; int dst_idx; int src_idx; } *

variable_types:
off
unsigned long

return_type: unsigned long

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; unsigned long chflags; void (*init)(struct cmd *, int); int (*parse)(struct cmd *, int, char **, char **); int (*exec)(struct cmd *, struct cmd_ctx *); void (*free)(struct cmd *); unsigned long (*print)(struct cmd *, char *, unsigned long); }

user_defined_types: struct cmd_ctx { struct client *curclient; struct client *cmdclient; 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 { 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 msg_command_data { int pid; unsigned int idx; int argc; char argv[2048]; }

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


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

result = *(_QWORD *)(a1 + 32);
if ( result )
{
v2 = 0;
do
{
if ( (*(_BYTE *)(result + 24) & 1) == 0 )
{
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 20) = v2;
v2 += *(_DWORD *)(result + 12) + 1;
}
result = *(_QWORD *)(result + 376);
}
while ( result );
}
return result;
}

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

result = *(_QWORD *)(a1 + 32);
if ( result )
{
v2 = 0;
do
{
if ( (*(_BYTE *)(result + 24) & 1) == 0 )
{
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 20) = v2;
v2 += *(_DWORD *)(result + 12) + 1;
}
result = *(_QWORD *)(result + 376);
}
while ( result );
}
return result;
}

original_code:
void
layout_manual_v_update_offsets(struct window *w)
{
 struct window_pane *wp;
 u_int yoff;
 yoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  if (wp->flags & 0x1)
   continue;
  wp->xoff = 0;
  wp->yoff = yoff;
  yoff += wp->sy + 1;
 }
}

canonical_original_code:
void layout_manual_v_update_offsets(struct window *w)
{
 struct window_pane *wp;
 unsigned int yoff;
 yoff = 0;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  if (wp->flags & 0x1)
   continue;
  wp->xoff = 0;
  wp->yoff = yoff;
  yoff += wp->sy + 1;
 }
}

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

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; 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; 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; 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; 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_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 *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; } *, 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; } *

variable_types:
yoff
unsigned int

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


original_code:
void
layout_manual_v_refresh(struct window *w, __attribute__ ((unused)) int active_only)
{
 struct window_pane *wp;
 u_int npanes, canfit, total;
 int left;
 if (active_only)
  return;
 if ((((&w->panes)->tqh_first) == ((void *)0)))
  return;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next))
      wp->flags &= ~0x1;
 npanes = window_count_panes(w);
 if (w->sy <= 4 * npanes) {
  canfit = w->sy / 4;
  if (canfit == 0) {
   for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
    if (wp == ((&w->panes)->tqh_first))
     wp->sy = w->sy;
    else
     wp->flags |= 0x1;
   }
  } else {
   for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
    if (canfit-- > 0)
     wp->sy = 4 - 1;
    else
     wp->flags |= 0x1;
   }
   ((&w->panes)->tqh_first)->sy += 1 + w->sy % 4;
  }
 } else {
  total = 0;
  for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next))
   total += wp->sy;
  total += npanes - 1;
  left = w->sy - total;
  if (left > 0) {
   while (left > 0) {
    for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
     wp->sy++;
     if (--left == 0)
      break;
    }
   }
  } else {
   while (left < 0) {
    for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
     if (wp->sy <= 4 - 1)
      continue;
     wp->sy--;
     if (++left == 0)
      break;
    }
   }
  }
 }
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  wp->sy--;
      window_pane_resize(wp, w->sx, wp->sy + 1);
 }
 layout_manual_v_update_offsets(w);
 window_set_active_pane(w, w->active);
}

canonical_original_code:
void layout_manual_v_refresh(struct window *w, int active_only)
{
 struct window_pane *wp;
 unsigned int npanes; unsigned int canfit; unsigned int total;
 int left;
 if (active_only)
  return;
 if ((((&w->panes)->tqh_first) == ((void *)0)))
  return;
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next))
      wp->flags &= ~0x1;
 npanes = window_count_panes(w);
 if (w->sy <= 4 * npanes) {
  canfit = w->sy / 4;
  if (canfit == 0) {
   for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
    if (wp == ((&w->panes)->tqh_first))
     wp->sy = w->sy;
    else
     wp->flags |= 0x1;
   }
  } else {
   for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
    if (canfit-- > 0)
     wp->sy = 4 - 1;
    else
     wp->flags |= 0x1;
   }
   ((&w->panes)->tqh_first)->sy += 1 + w->sy % 4;
  }
 } else {
  total = 0;
  for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next))
   total += wp->sy;
  total += npanes - 1;
  left = w->sy - total;
  if (left > 0) {
   while (left > 0) {
    for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
     wp->sy++;
     if (--left == 0)
      break;
    }
   }
  } else {
   while (left < 0) {
    for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
     if (wp->sy <= 4 - 1)
      continue;
     wp->sy--;
     if (++left == 0)
      break;
    }
   }
  }
 }
 for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next)) {
  wp->sy--;
      window_pane_resize(wp, w->sx, wp->sy + 1);
 }
 layout_manual_v_update_offsets(w);
 window_set_active_pane(w, w->active);
}

variable_types:
npanes
unsigned int

variable_types:
canfit
unsigned int

variable_types:
total
unsigned int

variable_types: left int

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 screen_write_ctx { struct window_pane *wp; struct screen *s; }

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


original_code:
void
layout_manual_v_resize(struct window_pane *wp, int adjust)
{
 struct window *w = wp->window;
 struct window_pane *wq;
 if (adjust > 0) {
  if (((wp)->entry.tqe_next) == ((void *)0)) {
   if (wp == ((&w->panes)->tqh_first)) {
    return;
   }
   wp = (*(((struct window_panes *)((wp)->entry.tqe_prev))->tqh_last));
  }
  while (adjust-- > 0) {
   wq = wp;
   while ((wq = ((wq)->entry.tqe_next)) != ((void *)0)) {
    if (wq->sy <= 4)
     continue;
    window_pane_resize(wq, wq->sx, wq->sy - 1);
    break;
   }
   if (wq == ((void *)0))
    break;
   window_pane_resize(wp, wp->sx, wp->sy + 1);
  }
 } else {
  adjust = -adjust;
  wq = ((wp)->entry.tqe_next);
  if (wq == ((void *)0)) {
   if (wp == ((&w->panes)->tqh_first)) {
    return;
   }
   wq = wp;
   wp = (*(((struct window_panes *)((wq)->entry.tqe_prev))->tqh_last));
  }
  while (adjust-- > 0) {
   if (wp->sy <= 4)
    break;
   window_pane_resize(wq, wq->sx, wq->sy + 1);
   window_pane_resize(wp, wp->sx, wp->sy - 1);
  }
 }
 layout_manual_v_update_offsets(w);
}

variable_types: adjust int

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

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


original_code:
void
window_choose_vadd(struct window_pane *wp, int idx, const char *fmt, va_list ap)
{
 struct window_choose_mode_data *data = wp->modedata;
 struct window_choose_mode_item *item;
 do { do { if ((0x7fffffff * 2U + 1U) - (1) < (&data->list)->num) log_fatalx("%s: %s", __func__, "number too big");; if ((18446744073709551615UL) / ((&data->list)->num + (1)) < (sizeof *(&data->list)->list)) log_fatalx("%s: %s", __func__, "size too big");; if ((&data->list)->space == 0) { (&data->list)->space = (10 * (sizeof *(&data->list)->list)); (&data->list)->list = xrealloc((&data->list)->list, 1, (&data->list)->space); } while ((&data->list)->space <= ((&data->list)->num + (1)) * (sizeof *(&data->list)->list)) { (&data->list)->list = xrealloc((&data->list)->list, 2, (&data->list)->space); (&data->list)->space *= 2; } } while (0); (&data->list)->num += 1; } while (0);
 item = &((&data->list)->list[(&data->list)->num - 1]);
 xvasprintf(&item->name, fmt, ap);
 item->idx = idx;
}

canonical_original_code:
void window_choose_vadd(struct window_pane *wp, int idx, char *fmt, __builtin_va_list ap)
{
 struct window_choose_mode_data *data = wp->modedata;
 struct window_choose_mode_item *item;
 do { do { if ((0x7fffffff * 2U + 1U) - (1) < (&data->list)->num) log_fatalx("%s: %s", __func__, "number too big");; if ((18446744073709551615UL) / ((&data->list)->num + (1)) < (sizeof *(&data->list)->list)) log_fatalx("%s: %s", __func__, "size too big");; if ((&data->list)->space == 0) { (&data->list)->space = (10 * (sizeof *(&data->list)->list)); (&data->list)->list = xrealloc((&data->list)->list, 1, (&data->list)->space); } while ((&data->list)->space <= ((&data->list)->num + (1)) * (sizeof *(&data->list)->list)) { (&data->list)->list = xrealloc((&data->list)->list, 2, (&data->list)->space); (&data->list)->space *= 2; } } while (0); (&data->list)->num += 1; } while (0);
 item = &((&data->list)->list[(&data->list)->num - 1]);
 xvasprintf(&item->name, fmt, ap);
 item->idx = idx;
}

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

variable_types: idx int

variable_types:
fmt
char *

variable_types: struct window_choose_mode_data { 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; } screen; struct mode_key_data { int type; int flags; } mdata; struct { struct window_choose_mode_item { char *name; int idx; } *list; unsigned int num; unsigned long space; } list; unsigned int top; unsigned int selected; void (*callback)(void *, int); void *data; } *

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 window_choose_mode_data { struct screen screen; struct mode_key_data mdata; struct { struct window_choose_mode_item *list; unsigned int num; unsigned long space; } list; unsigned int top; unsigned int selected; void (*callback)(void *, int); void *data; }

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 screen_write_ctx { struct window_pane *wp; struct screen *s; }

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


decompiled_code:
__int64 window_choose_add(__int64 a1, int a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return window_choose_vadd(a1, a2, a3, (__int64)va);
}

canonical_decompiled_code:
__int64 func4(__int64 a1, int a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return func3(a1, a2, a3, (__int64)va);
}

original_code:
void __attribute__ ((format (printf, 3, 4)))
window_choose_add(struct window_pane *wp, int idx, const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 window_choose_vadd(wp, idx, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void window_choose_add(struct window_pane *wp, int idx, char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 window_choose_vadd(wp, idx, fmt, ap);
 __builtin_va_end(ap);
}

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

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


decompiled_code:
__int64 __fastcall window_choose_key_index(__int64 a1, int a2)
{
const char *v3; // rbx
char v4; // si

v3 = "0123456789abcdefghijklmnopqrstuvwxyz";
v4 = 48;
do
{
if ( (unsigned int)mode_key_lookup(a1 + 80, (unsigned int)v4) <= 1 )
{
if ( !a2 )
return (unsigned int)*v3;
--a2;
}
v4 = *++v3;
}
while ( *v3 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
const char *v3; // rbx
char v4; // si

v3 = "0123456789abcdefghijklmnopqrstuvwxyz";
v4 = 48;
do
{
if ( (unsigned int)mode_key_lookup(a1 + 80, (unsigned int)v4) <= 1 )
{
if ( !a2 )
return (unsigned int)*v3;
--a2;
}
v4 = *++v3;
}
while ( *v3 );
return 0xFFFFFFFFLL;
}

original_code:
int
window_choose_key_index(struct window_choose_mode_data *data, u_int idx)
{
 static const char keys[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 const char *ptr;
 int mkey;
 for (ptr = keys; *ptr != '\0'; ptr++) {
  mkey = mode_key_lookup(&data->mdata, *ptr);
  if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER)
   continue;
  if (idx-- == 0)
   return (*ptr);
 }
 return (-1);
}

canonical_original_code:
int window_choose_key_index(struct window_choose_mode_data *data, unsigned int idx)
{
 static char keys[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 char *ptr;
 int mkey;
 for (ptr = keys; *ptr != '\0'; ptr++) {
  mkey = mode_key_lookup(&data->mdata, *ptr);
  if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER)
   continue;
  if (idx-- == 0)
   return (*ptr);
 }
 return (-1);
}

variable_types: struct window_choose_mode_data { 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; int rectflag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; } sel; } screen; 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_SCROLLDOWN=24, MODEKEYCHOICE_SCROLLUP=25, MODEKEYCHOICE_UP=26, MODEKEYCOPY_BACKTOINDENTATION=27, MODEKEYCOPY_BOTTOMLINE=28, MODEKEYCOPY_CANCEL=29, MODEKEYCOPY_CLEARSELECTION=30, MODEKEYCOPY_COPYSELECTION=31, MODEKEYCOPY_DOWN=32, MODEKEYCOPY_ENDOFLINE=33, MODEKEYCOPY_GOTOLINE=34, MODEKEYCOPY_HALFPAGEDOWN=35, MODEKEYCOPY_HALFPAGEUP=36, MODEKEYCOPY_HISTORYBOTTOM=37, MODEKEYCOPY_HISTORYTOP=38, MODEKEYCOPY_JUMP=39, MODEKEYCOPY_JUMPAGAIN=40, MODEKEYCOPY_JUMPREVERSE=41, MODEKEYCOPY_JUMPBACK=42, MODEKEYCOPY_LEFT=43, MODEKEYCOPY_MIDDLELINE=44, MODEKEYCOPY_NEXTPAGE=45, MODEKEYCOPY_NEXTSPACE=46, MODEKEYCOPY_NEXTSPACEEND=47, MODEKEYCOPY_NEXTWORD=48, MODEKEYCOPY_NEXTWORDEND=49, MODEKEYCOPY_PREVIOUSPAGE=50, MODEKEYCOPY_PREVIOUSSPACE=51, MODEKEYCOPY_PREVIOUSWORD=52, MODEKEYCOPY_RECTANGLETOGGLE=53, MODEKEYCOPY_RIGHT=54, MODEKEYCOPY_SCROLLDOWN=55, MODEKEYCOPY_SCROLLUP=56, MODEKEYCOPY_SEARCHAGAIN=57, MODEKEYCOPY_SEARCHDOWN=58, MODEKEYCOPY_SEARCHREVERSE=59, MODEKEYCOPY_SEARCHUP=60, MODEKEYCOPY_STARTNUMBERPREFIX=61, MODEKEYCOPY_STARTOFLINE=62, MODEKEYCOPY_STARTSELECTION=63, MODEKEYCOPY_TOPLINE=64, MODEKEYCOPY_UP=65 } cmd; struct { struct mode_key_binding *spe_left; struct mode_key_binding *spe_right; } entry; } *sph_root; } *tree; int mode; } mdata; struct { struct window_choose_mode_item { char *name; int idx; } *list; unsigned int num; unsigned long space; } list; unsigned int top; unsigned int selected; void (*callbackfn)(void *, int); void (*freefn)(void *); void *data; } *

variable_types:
idx
unsigned int

variable_types:
keys
char []

variable_types:
ptr
char *

variable_types: mkey int

return_type: int

user_defined_types: struct window_choose_mode_data { struct screen screen; struct mode_key_data mdata; struct { struct window_choose_mode_item *list; unsigned int num; unsigned long space; } list; unsigned int top; unsigned int selected; void (*callbackfn)(void *, int); void (*freefn)(void *); void *data; }

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 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 grid_line { unsigned int cellsize; struct grid_cell *celldata; unsigned int utf8size; struct grid_utf8 *utf8data; int flags; }

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 window_choose_index_key(__int64 a1, int a2)
{
unsigned int v3; // ebp
const char *v4; // rbx
char v5; // si

v3 = 0;
v4 = "0123456789abcdefghijklmnopqrstuvwxyz";
v5 = 48;
do
{
if ( (unsigned int)mode_key_lookup(a1 + 80, (unsigned int)v5) <= 1 )
{
if ( *v4 == a2 )
return v3;
++v3;
}
v5 = *++v4;
}
while ( *v4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
unsigned int v3; // ebp
const char *v4; // rbx
char v5; // si

v3 = 0;
v4 = "0123456789abcdefghijklmnopqrstuvwxyz";
v5 = 48;
do
{
if ( (unsigned int)mode_key_lookup(a1 + 80, (unsigned int)v5) <= 1 )
{
if ( *v4 == a2 )
return v3;
++v3;
}
v5 = *++v4;
}
while ( *v4 );
return 0xFFFFFFFFLL;
}

original_code:
int
window_choose_index_key(struct window_choose_mode_data *data, int key)
{
 static const char keys[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 const char *ptr;
 int mkey;
 u_int idx = 0;
 for (ptr = keys; *ptr != '\0'; ptr++) {
  mkey = mode_key_lookup(&data->mdata, *ptr);
  if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER)
   continue;
  if (key == *ptr)
   return (idx);
  idx++;
 }
 return (-1);
}

canonical_original_code:
int window_choose_index_key(struct window_choose_mode_data *data, int key)
{
 static char keys[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 char *ptr;
 int mkey;
 unsigned int idx = 0;
 for (ptr = keys; *ptr != '\0'; ptr++) {
  mkey = mode_key_lookup(&data->mdata, *ptr);
  if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER)
   continue;
  if (key == *ptr)
   return (idx);
  idx++;
 }
 return (-1);
}

variable_types: key int

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

user_defined_types: struct window_choose_mode_item { char *name; int idx; }

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_SCROLLDOWN=24, MODEKEYCHOICE_SCROLLUP=25, MODEKEYCHOICE_UP=26, MODEKEYCOPY_BACKTOINDENTATION=27, MODEKEYCOPY_BOTTOMLINE=28, MODEKEYCOPY_CANCEL=29, MODEKEYCOPY_CLEARSELECTION=30, MODEKEYCOPY_COPYSELECTION=31, MODEKEYCOPY_DOWN=32, MODEKEYCOPY_ENDOFLINE=33, MODEKEYCOPY_GOTOLINE=34, MODEKEYCOPY_HALFPAGEDOWN=35, MODEKEYCOPY_HALFPAGEUP=36, MODEKEYCOPY_HISTORYBOTTOM=37, MODEKEYCOPY_HISTORYTOP=38, MODEKEYCOPY_JUMP=39, MODEKEYCOPY_JUMPAGAIN=40, MODEKEYCOPY_JUMPREVERSE=41, MODEKEYCOPY_JUMPBACK=42, MODEKEYCOPY_LEFT=43, MODEKEYCOPY_MIDDLELINE=44, MODEKEYCOPY_NEXTPAGE=45, MODEKEYCOPY_NEXTSPACE=46, MODEKEYCOPY_NEXTSPACEEND=47, MODEKEYCOPY_NEXTWORD=48, MODEKEYCOPY_NEXTWORDEND=49, MODEKEYCOPY_PREVIOUSPAGE=50, MODEKEYCOPY_PREVIOUSSPACE=51, MODEKEYCOPY_PREVIOUSWORD=52, MODEKEYCOPY_RECTANGLETOGGLE=53, MODEKEYCOPY_RIGHT=54, MODEKEYCOPY_SCROLLDOWN=55, MODEKEYCOPY_SCROLLUP=56, MODEKEYCOPY_SEARCHAGAIN=57, MODEKEYCOPY_SEARCHDOWN=58, MODEKEYCOPY_SEARCHREVERSE=59, MODEKEYCOPY_SEARCHUP=60, MODEKEYCOPY_STARTNUMBERPREFIX=61, MODEKEYCOPY_STARTOFLINE=62, MODEKEYCOPY_STARTSELECTION=63, MODEKEYCOPY_TOPLINE=64, MODEKEYCOPY_UP=65 }

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


decompiled_code:
__int64 __fastcall window_choose_redraw_screen(_QWORD *a1)
{
__int64 v1; // r12
unsigned int v2; // ebx
_BYTE v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = a1[56];
screen_write_start(v4, a1, 0LL);
if ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) )
{
v2 = 0;
do
window_choose_write_line(a1, (__int64)v4, v2++);
while ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > v2 );
}
return screen_write_stop(v4);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
__int64 v1; // r12
unsigned int v2; // ebx
_BYTE v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = a1[56];
screen_write_start(v4, a1, 0LL);
if ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) )
{
v2 = 0;
do
func6(a1, (__int64)v4, v2++);
while ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > v2 );
}
return screen_write_stop(v4);
}

original_code:
void
window_choose_redraw_screen(struct window_pane *wp)
{
 struct window_choose_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 struct screen_write_ctx ctx;
 u_int i;
 screen_write_start(&ctx, wp, ((void *)0));
 for (i = 0; i < ((s)->grid->sy); i++)
  window_choose_write_line(wp, &ctx, i);
 screen_write_stop(&ctx);
}

canonical_original_code:
void window_choose_redraw_screen(struct window_pane *wp)
{
 struct window_choose_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 struct screen_write_ctx ctx;
 unsigned int i;
 screen_write_start(&ctx, wp, ((void *)0));
 for (i = 0; i < ((s)->grid->sy); i++)
  window_choose_write_line(wp, &ctx, i);
 screen_write_stop(&ctx);
}

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

variable_types: struct screen_write_ctx { 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; 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; 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 ctx; unsigned char *buf; unsigned long len; unsigned long off; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } 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 { 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; struct screen_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; } sel; } *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 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; } *wp; struct screen *s; }

variable_types:
i
unsigned int

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

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 window_choose_mode_data { struct screen screen; struct mode_key_data mdata; struct { struct window_choose_mode_item *list; unsigned int num; unsigned long space; } list; unsigned int top; unsigned int selected; void (*callback)(void *, int); void *data; }

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 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 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_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 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 options { struct options_tree tree; struct options *parent; }

user_defined_types: struct options_tree { struct options_entry *sph_root; }

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


decompiled_code:
__int64 __fastcall window_choose_resize(_QWORD *a1, __int64 a2, int a3)
{
__int64 v4; // rdi
int v5; // eax

v4 = a1[56];
v5 = *(_DWORD *)(v4 + 124) - a3 + 1;
if ( *(_DWORD *)(v4 + 124) <= (unsigned int)(a3 - 1) )
v5 = 0;
*(_DWORD *)(v4 + 120) = v5;
screen_resize();
return window_choose_redraw_screen(a1);
}

original_code:
void
window_choose_resize(struct window_pane *wp, u_int sx, u_int sy)
{
 struct window_choose_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 data->top = 0;
 if (data->selected > sy - 1)
  data->top = data->selected - (sy - 1);
 screen_resize(s, sx, sy);
 window_choose_redraw_screen(wp);
}

canonical_original_code:
void window_choose_resize(struct window_pane *wp, unsigned int sx, unsigned int sy)
{
 struct window_choose_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 data->top = 0;
 if (data->selected > sy - 1)
  data->top = data->selected - (sy - 1);
 screen_resize(s, sx, sy);
 window_choose_redraw_screen(wp);
}

variable_types:
sx
unsigned int

variable_types:
sy
unsigned int

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

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 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 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_choose_mode_item { char *name; int idx; }

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

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


decompiled_code:
__int64 __fastcall window_choose_scroll_up(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = a1[56];
result = *(unsigned int *)(v1 + 120);
if ( (_DWORD)result )
{
*(_DWORD *)(v1 + 120) = result - 1;
screen_write_start(v3, a1, 0LL);
screen_write_cursormove(v3, 0LL, 0LL);
screen_write_insertline(v3, 1LL);
window_choose_write_line(a1, (__int64)v3, 0);
if ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > 1u )
window_choose_write_line(a1, (__int64)v3, 1u);
result = screen_write_stop(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = a1[56];
result = *(unsigned int *)(v1 + 120);
if ( (_DWORD)result )
{
*(_DWORD *)(v1 + 120) = result - 1;
screen_write_start(v3, a1, 0LL);
screen_write_cursormove(v3, 0LL, 0LL);
screen_write_insertline(v3, 1LL);
func6(a1, (__int64)v3, 0);
if ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > 1u )
func6(a1, (__int64)v3, 1u);
result = screen_write_stop(v3);
}
return result;
}

original_code:
void
window_choose_scroll_up(struct window_pane *wp)
{
 struct window_choose_mode_data *data = wp->modedata;
 struct screen_write_ctx ctx;
 if (data->top == 0)
  return;
 data->top--;
 screen_write_start(&ctx, wp, ((void *)0));
 screen_write_cursormove(&ctx, 0, 0);
 screen_write_insertline(&ctx, 1);
 window_choose_write_line(wp, &ctx, 0);
 if (((&data->screen)->grid->sy) > 1)
  window_choose_write_line(wp, &ctx, 1);
 screen_write_stop(&ctx);
}

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 window_choose_mode_data { struct screen screen; struct mode_key_data mdata; struct { struct window_choose_mode_item *list; unsigned int num; unsigned long space; } list; unsigned int top; unsigned int selected; void (*callback)(void *, int); void *data; }

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

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

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_sel { int flag; unsigned int sx; unsigned int sy; unsigned int ex; unsigned int ey; struct grid_cell cell; }

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

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 options_tree { struct options_entry *sph_root; }

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