decompiled_code:
unsigned __int64 __fastcall cmd_bind_key_print(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned int *v4; // rbp
int v5; // eax
unsigned __int64 v6; // rbx
const char *v8; // rax

v4 = *(unsigned int **)(a1 + 8);
v5 = xsnprintf(a2, a3, "%s", **(const char ***)a1);
v6 = v5;
if ( v4 )
{
if ( v5 < a3 )
{
v8 = (const char *)key_string_lookup_key(*v4);
v6 += (int)xsnprintf(a2 + v6, a3 - v6, " %s ", v8);
if ( a3 > v6 )
v6 += cmd_list_print(*((_QWORD *)v4 + 1), a2 + v6, a3 - v6);
}
}
return v6;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned int *v4; // rbp
int v5; // eax
unsigned __int64 v6; // rbx
const char *v8; // rax

v4 = *(unsigned int **)(a1 + 8);
v5 = xsnprintf(a2, a3, "%s", **(const char ***)a1);
v6 = v5;
if ( v4 )
{
if ( v5 < a3 )
{
v8 = (const char *)key_string_lookup_key(*v4);
v6 += (int)xsnprintf(a2 + v6, a3 - v6, " %s ", v8);
if ( a3 > v6 )
v6 += cmd_list_print(*((_QWORD *)v4 + 1), a2 + v6, a3 - v6);
}
}
return v6;
}

original_code:
size_t
cmd_bind_key_print(struct cmd *self, char *buf, size_t len)
{
 struct cmd_bind_key_data *data = self->data;
 size_t off = 0;
 const char *skey;
 off += xsnprintf(buf, len, "%s", self->entry->name);
 if (data == ((void *)0))
  return (off);
 if (off < len) {
  skey = key_string_lookup_key(data->key);
  off += xsnprintf(buf + off, len - off, " %s ", skey);
 }
 if (off < len)
  off += cmd_list_print(data->cmdlist, buf + off, len - off);
 return (off);
}

canonical_original_code:
unsigned long cmd_bind_key_print(struct cmd *self, char *buf, unsigned long len)
{
 struct cmd_bind_key_data *data = self->data;
 unsigned long off = 0;
 char *skey;
 off += xsnprintf(buf, len, "%s", self->entry->name);
 if (data == ((void *)0))
  return (off);
 if (off < len) {
  skey = key_string_lookup_key(data->key);
  off += xsnprintf(buf + off, len - off, " %s ", skey);
 }
 if (off < len)
  off += cmd_list_print(data->cmdlist, buf + off, len - off);
 return (off);
}

variable_types:
buf
char *

variable_types:
len
unsigned long

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

variable_types:
skey
char *

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_bind_key_data { int key; int can_repeat; struct cmd_list *cmdlist; }

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

user_defined_types: struct cmd_list { struct cmd *tqh_first; struct cmd **tqh_last; }

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

user_defined_types: struct client { int fd; struct buffer *in; struct buffer *out; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_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 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 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 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 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 *sle_next; } sentry; }

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

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

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


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
__int64 __fastcall cmd_bind_key_table(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
unsigned int v5; // er12
__int64 v6; // rax
__int64 result; // rax
unsigned int *v8; // rax
unsigned int v9; // [rsp+0h] [rbp-48h] BYREF
_BOOL4 v10; // [rsp+4h] [rbp-44h]

v2 = *(_QWORD *)(a1 + 8);
v3 = mode_key_findtable(*(_QWORD *)(v2 + 24));
if ( v3 )
{
v4 = v3;
v5 = mode_key_fromstring(*(_QWORD *)(v3 + 8), *(_QWORD *)(v2 + 32));
if ( v5 )
{
v9 = *(_DWORD *)v2 & 0xFFFEFFFF;
v10 = *(_DWORD *)(v2 + 16) != 0;
v6 = mode_key_tree_SPLAY_FIND(*(_QWORD **)(v4 + 16), (__int64)&v9);
if ( v6 )
{
*(_DWORD *)(v6 + 8) = v5;
}
else
{
v8 = (unsigned int *)xmalloc(32LL);
*v8 = v9;
v8[1] = v10;
v8[2] = v5;
mode_key_tree_SPLAY_INSERT(*(_QWORD *)(v4 + 16));
}
result = 0LL;
}
else
{
(*(void (**)(__int64, const char *, ...))(a2 + 40))(a2, "unknown command: %s", *(const char **)(v2 + 32));
result = 0xFFFFFFFFLL;
}
}
else
{
(*(void (**)(__int64, const char *, ...))(a2 + 40))(a2, "unknown key table: %s", *(const char **)(v2 + 24));
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
unsigned int v5; // er12
__int64 v6; // rax
__int64 result; // rax
unsigned int *v8; // rax
unsigned int v9; // [rsp+0h] [rbp-48h] BYREF
_BOOL4 v10; // [rsp+4h] [rbp-44h]

v2 = *(_QWORD *)(a1 + 8);
v3 = mode_key_findtable(*(_QWORD *)(v2 + 24));
if ( v3 )
{
v4 = v3;
v5 = mode_key_fromstring(*(_QWORD *)(v3 + 8), *(_QWORD *)(v2 + 32));
if ( v5 )
{
v9 = *(_DWORD *)v2 & 0xFFFEFFFF;
v10 = *(_DWORD *)(v2 + 16) != 0;
v6 = func1(*(_QWORD **)(v4 + 16), (__int64)&v9);
if ( v6 )
{
*(_DWORD *)(v6 + 8) = v5;
}
else
{
v8 = (unsigned int *)xmalloc(32LL);
*v8 = v9;
v8[1] = v10;
v8[2] = v5;
mode_key_tree_SPLAY_INSERT(*(_QWORD *)(v4 + 16));
}
result = 0LL;
}
else
{
(*(void (**)(__int64, const char *, ...))(a2 + 40))(a2, "unknown command: %s", *(const char **)(v2 + 32));
result = 0xFFFFFFFFLL;
}
}
else
{
(*(void (**)(__int64, const char *, ...))(a2 + 40))(a2, "unknown key table: %s", *(const char **)(v2 + 24));
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
{
 struct cmd_bind_key_data *data = self->data;
 const struct mode_key_table *mtab;
 struct mode_key_binding *mbind, mtmp;
 enum mode_key_cmd cmd;
 if ((mtab = mode_key_findtable(data->tablename)) == ((void *)0)) {
  ctx->error(ctx, "unknown key table: %s", data->tablename);
  return (-1);
 }
 cmd = mode_key_fromstring(mtab->cmdstr, data->modecmd);
 if (cmd == MODEKEY_NONE) {
  ctx->error(ctx, "unknown command: %s", data->modecmd);
  return (-1);
 }
 mtmp.key = data->key & ~0x10000;
 mtmp.mode = data->command_key ? 1 : 0;
 if ((mbind = mode_key_tree_SPLAY_FIND(mtab->tree, &mtmp)) != ((void *)0)) {
  mbind->cmd = cmd;
  return (0);
 }
 mbind = xmalloc(sizeof *mbind);
 mbind->key = mtmp.key;
 mbind->mode = mtmp.mode;
 mbind->cmd = cmd;
 mode_key_tree_SPLAY_INSERT(mtab->tree, mbind);
 return (0);
}

canonical_original_code:
int cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
{
 struct cmd_bind_key_data *data = self->data;
 struct mode_key_table *mtab;
 struct mode_key_binding *mbind; struct mode_key_binding mtmp;
 enum mode_key_cmd cmd;
 if ((mtab = mode_key_findtable(data->tablename)) == ((void *)0)) {
  ctx->error(ctx, "unknown key table: %s", data->tablename);
  return (-1);
 }
 cmd = mode_key_fromstring(mtab->cmdstr, data->modecmd);
 if (cmd == MODEKEY_NONE) {
  ctx->error(ctx, "unknown command: %s", data->modecmd);
  return (-1);
 }
 mtmp.key = data->key & ~0x10000;
 mtmp.mode = data->command_key ? 1 : 0;
 if ((mbind = mode_key_tree_SPLAY_FIND(mtab->tree, &mtmp)) != ((void *)0)) {
  mbind->cmd = cmd;
  return (0);
 }
 mbind = xmalloc(sizeof *mbind);
 mbind->key = mtmp.key;
 mbind->mode = mtmp.mode;
 mbind->cmd = cmd;
 mode_key_tree_SPLAY_INSERT(mtab->tree, mbind);
 return (0);
}

variable_types:
ctx
struct cmd_ctx *

variable_types: struct cmd_bind_key_data { int key; int can_repeat; struct cmd_list { 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; } *tqh_first; struct cmd **tqh_last; } *cmdlist; int command_key; char *tablename; char *modecmd; } *

variable_types: struct mode_key_table { char *name; struct mode_key_cmdstr { 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; char *name; } *cmdstr; 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; struct mode_key_entry { 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; } *table; } *

return_type: int

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 cmd { struct cmd_entry *entry; void *data; struct { struct cmd *tqe_next; struct cmd **tqe_prev; } qentry; }

user_defined_types: struct cmd_bind_key_data { int key; int can_repeat; struct cmd_list *cmdlist; int command_key; char *tablename; char *modecmd; }

user_defined_types: struct mode_key_table { char *name; struct mode_key_cmdstr *cmdstr; struct mode_key_tree *tree; struct mode_key_entry *table; }

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_list { struct cmd *tqh_first; struct cmd **tqh_last; }

user_defined_types: struct mode_key_cmdstr { enum mode_key_cmd cmd; char *name; }

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

user_defined_types: struct mode_key_entry { int key; int mode; enum mode_key_cmd cmd; }

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 screen { char *title; struct grid *grid; unsigned int cx; unsigned int cy; unsigned int rupper; unsigned int rlower; int mode; unsigned char *tabs; struct screen_sel sel; }

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

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

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

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

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

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

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

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

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

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

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


decompiled_code:
void __fastcall paste_init_stack(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void
paste_init_stack(struct paste_stack *ps)
{
 do { (ps)->num = 0; (ps)->list = ((void *)0); (ps)->space = 0; } while (0);
}

variable_types: struct paste_stack { struct paste_buffer { char *data; unsigned long size; } **list; unsigned int num; unsigned long space; } *

return_type: void

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


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

if ( *((_DWORD *)a1 + 2) )
result = **a1;
else
result = 0LL;
return result;
}

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

if ( *((_DWORD *)a1 + 2) )
result = **a1;
else
result = 0LL;
return result;
}

original_code:
struct paste_buffer *
paste_get_top(struct paste_stack *ps)
{
 if (((ps)->num) == 0)
  return (((void *)0));
 return (((ps)->list[0]));
}

canonical_original_code:
struct paste_buffer *paste_get_top(struct paste_stack *ps)
{
 if (((ps)->num) == 0)
  return (((void *)0));
 return (((ps)->list[0]));
}

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

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


decompiled_code:
__int64 __fastcall paste_get_index(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 8) <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 8) <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
struct paste_buffer *
paste_get_index(struct paste_stack *ps, u_int idx)
{
 if (idx >= ((ps)->num))
  return (((void *)0));
 return (((ps)->list[idx]));
}

canonical_original_code:
struct paste_buffer *paste_get_index(struct paste_stack *ps, unsigned int idx)
{
 if (idx >= ((ps)->num))
  return (((void *)0));
 return (((ps)->list[idx]));
}

variable_types:
idx
unsigned int

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


decompiled_code:
__int64 __fastcall paste_walk_stack(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebp
__int64 result; // rax

v2 = *a2;
result = paste_get_index(a1, *a2);
*a2 = v2 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebp
__int64 result; // rax

v2 = *a2;
result = func2(a1, *a2);
*a2 = v2 + 1;
return result;
}

original_code:
struct paste_buffer *
paste_walk_stack(struct paste_stack *ps, uint *idx)
{
 struct paste_buffer *pb;
 pb = paste_get_index(ps, *idx);
 (*idx)++;
 return (pb);
}

canonical_original_code:
struct paste_buffer *paste_walk_stack(struct paste_stack *ps, unsigned int *idx)
{
 struct paste_buffer *pb;
 pb = paste_get_index(ps, *idx);
 (*idx)++;
 return (pb);
}

variable_types:
idx
unsigned int *

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


decompiled_code:
__int64 __fastcall paste_free_top(__int64 a1)
{
int v1; // eax
_QWORD *v3; // rdi
_QWORD *v4; // rbp
_QWORD *v5; // rdi
int v6; // eax

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
{
v3 = *(_QWORD **)a1;
v4 = (_QWORD *)*v3;
if ( v1 == 1 )
{
*(_DWORD *)(a1 + 8) = 0;
v5 = *(_QWORD **)a1;
}
else
{
memmove(v3, v3 + 1, 8LL * (unsigned int)(v1 - 1));
v6 = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = v6;
if ( v6 )
goto LABEL_7;
v5 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
{
LABEL_5:
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
LABEL_7:
xfree(*v4);
xfree(v4);
return 0LL;
}
}
xfree(v5);
goto LABEL_5;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
_QWORD *v3; // rdi
_QWORD *v4; // rbp
_QWORD *v5; // rdi
int v6; // eax

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
{
v3 = *(_QWORD **)a1;
v4 = (_QWORD *)*v3;
if ( v1 == 1 )
{
*(_DWORD *)(a1 + 8) = 0;
v5 = *(_QWORD **)a1;
}
else
{
memmove(v3, v3 + 1, 8LL * (unsigned int)(v1 - 1));
v6 = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = v6;
if ( v6 )
goto LABEL_7;
v5 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
{
LABEL_5:
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
LABEL_7:
xfree(*v4);
xfree(v4);
return 0LL;
}
}
xfree(v5);
goto LABEL_5;
}
return 0xFFFFFFFFLL;
}

original_code:
int
paste_free_top(struct paste_stack *ps)
{
 struct paste_buffer *pb;
 if (((ps)->num) == 0)
  return (-1);
 pb = ((ps)->list[0]);
 do { if ((0) < (ps)->num - 1) { memmove((ps)->list + (0), (ps)->list + (0) + 1, (sizeof *(ps)->list) * ((ps)->num - (0) - 1)); } (ps)->num--; if ((ps)->num == 0) do { if ((ps)->list != ((void *)0)) xfree((ps)->list); do { (ps)->num = 0; (ps)->list = ((void *)0); (ps)->space = 0; } while (0); } while (0); } while (0);
 xfree(pb->data);
 xfree(pb);
 return (0);
}


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

do
result = paste_free_top(a1);
while ( !(_DWORD)result );
return result;
}

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

do
result = func4(a1);
while ( !(_DWORD)result );
return result;
}

original_code:
void
paste_free_stack(struct paste_stack *ps)
{
 while (paste_free_top(ps) == 0)
  ;
}


decompiled_code:
__int64 __fastcall paste_free_index(__int64 *a1, unsigned int a2)
{
unsigned int v2; // edx
__int64 v4; // rcx
__int64 v5; // rax
_QWORD *v6; // rdi
_QWORD *v7; // rbp
int v8; // eax

v2 = *((_DWORD *)a1 + 2);
if ( v2 <= a2 )
return 0xFFFFFFFFLL;
v4 = *a1;
v5 = 8LL * a2;
v6 = (_QWORD *)(*a1 + v5);
v7 = (_QWORD *)*v6;
if ( v2 - 1 > a2 )
memmove(v6, (const void *)(v4 + v5 + 8), 8LL * (~a2 + v2));
v8 = *((_DWORD *)a1 + 2) - 1;
*((_DWORD *)a1 + 2) = v8;
if ( !v8 )
{
if ( *a1 )
xfree(*a1);
*((_DWORD *)a1 + 2) = 0;
*a1 = 0LL;
a1[2] = 0LL;
}
xfree(*v7);
xfree(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, unsigned int a2)
{
unsigned int v2; // edx
__int64 v4; // rcx
__int64 v5; // rax
_QWORD *v6; // rdi
_QWORD *v7; // rbp
int v8; // eax

v2 = *((_DWORD *)a1 + 2);
if ( v2 <= a2 )
return 0xFFFFFFFFLL;
v4 = *a1;
v5 = 8LL * a2;
v6 = (_QWORD *)(*a1 + v5);
v7 = (_QWORD *)*v6;
if ( v2 - 1 > a2 )
memmove(v6, (const void *)(v4 + v5 + 8), 8LL * (~a2 + v2));
v8 = *((_DWORD *)a1 + 2) - 1;
*((_DWORD *)a1 + 2) = v8;
if ( !v8 )
{
if ( *a1 )
xfree(*a1);
*((_DWORD *)a1 + 2) = 0;
*a1 = 0LL;
a1[2] = 0LL;
}
xfree(*v7);
xfree(v7);
return 0LL;
}

original_code:
int
paste_free_index(struct paste_stack *ps, u_int idx)
{
 struct paste_buffer *pb;
 if (idx >= ((ps)->num))
  return (-1);
 pb = ((ps)->list[idx]);
 do { if ((idx) < (ps)->num - 1) { memmove((ps)->list + (idx), (ps)->list + (idx) + 1, (sizeof *(ps)->list) * ((ps)->num - (idx) - 1)); } (ps)->num--; if ((ps)->num == 0) do { if ((ps)->list != ((void *)0)) xfree((ps)->list); do { (ps)->num = 0; (ps)->list = ((void *)0); (ps)->space = 0; } while (0); } while (0); } while (0);
 xfree(pb->data);
 xfree(pb);
 return (0);
}

canonical_original_code:
int paste_free_index(struct paste_stack *ps, unsigned int idx)
{
 struct paste_buffer *pb;
 if (idx >= ((ps)->num))
  return (-1);
 pb = ((ps)->list[idx]);
 do { if ((idx) < (ps)->num - 1) { memmove((ps)->list + (idx), (ps)->list + (idx) + 1, (sizeof *(ps)->list) * ((ps)->num - (idx) - 1)); } (ps)->num--; if ((ps)->num == 0) do { if ((ps)->list != ((void *)0)) xfree((ps)->list); do { (ps)->num = 0; (ps)->list = ((void *)0); (ps)->space = 0; } while (0); } while (0); } while (0);
 xfree(pb->data);
 xfree(pb);
 return (0);
}


decompiled_code:
__int64 __fastcall paste_print(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // r12
unsigned __int64 v5; // rdx
unsigned __int64 v6; // rax

v2 = 3LL;
if ( a2 >= 3 )
v2 = a2;
v3 = xmalloc(4 * v2 + 1);
v4 = v3;
v5 = a1[1];
if ( v5 > v2 )
v5 = v2;
v6 = (int)strvisx(v3, *a1, v5, 25LL);
if ( a1[1] >= (unsigned __int64)(int)v6 )
v6 = a1[1];
if ( v2 < v6 )
{
*(_BYTE *)(v4 + v2 - 3) = 0;
strlcat(v4, "...", v2);
}
return v4;
}

original_code:
char *
paste_print(struct paste_buffer *pb, size_t width)
{
 char *buf;
 size_t len, used;
 if (width < 3)
  width = 3;
 buf = xmalloc(width * 4 + 1);
 len = pb->size;
 if (len > width)
  len = width;
 used = strvisx(buf, pb->data, len, 0x01|0x08|0x10);
 if (pb->size > width || used > width) {
  buf[width - 3] = '\0';
  strlcat(buf, "...", width);
 }
 return (buf);
}

canonical_original_code:
char *paste_print(struct paste_buffer *pb, unsigned long width)
{
 char *buf;
 unsigned long len; unsigned long used;
 if (width < 3)
  width = 3;
 buf = xmalloc(width * 4 + 1);
 len = pb->size;
 if (len > width)
  len = width;
 used = strvisx(buf, pb->data, len, 0x01|0x08|0x10);
 if (pb->size > width || used > width) {
  buf[width - 3] = '\0';
  strlcat(buf, "...", width);
 }
 return (buf);
}

variable_types:
width
unsigned long

variable_types:
used
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall cmd_if_shell_parse(const char ***a1, unsigned int a2, __int64 a3, __int64 a4)
{
const char **v6; // r14
_QWORD *v7; // rbp
__int64 result; // rax

((void (__fastcall *)(const char ***, _QWORD))(*a1)[5])(a1, 0LL);
v6 = a1[1];
if ( (unsigned int)BSDgetopt(a2, a3, &unk_24B) == -1 && (v7 = (_QWORD *)(a3 + 8LL * BSDoptind), a2 - BSDoptind == 2) )
{
v6[1] = (const char *)xstrdup(*v7);
*v6 = (const char *)xstrdup(v7[1]);
result = 0LL;
}
else
{
xasprintf(a4, "usage: %s %s", **a1, (*a1)[2]);
((void (__fastcall *)(const char ***))(*a1)[8])(a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char ***a1, unsigned int a2, __int64 a3, __int64 a4)
{
const char **v6; // r14
_QWORD *v7; // rbp
__int64 result; // rax

((void (__fastcall *)(const char ***, _QWORD))(*a1)[5])(a1, 0LL);
v6 = a1[1];
if ( (unsigned int)BSDgetopt(a2, a3, &unk_24B) == -1 && (v7 = (_QWORD *)(a3 + 8LL * BSDoptind), a2 - BSDoptind == 2) )
{
v6[1] = (const char *)xstrdup(*v7);
*v6 = (const char *)xstrdup(v7[1]);
result = 0LL;
}
else
{
xasprintf(a4, "usage: %s %s", **a1, (*a1)[2]);
((void (__fastcall *)(const char ***))(*a1)[8])(a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
cmd_if_shell_parse(struct cmd *self, int argc, char **argv, char **cause)
{
 struct cmd_if_shell_data *data;
 int opt;
 self->entry->init(self, 0);
 data = self->data;
 while ((opt = BSDgetopt(argc, argv, "")) != -1) {
  switch (opt) {
  default:
   goto usage;
  }
 }
 argc -= BSDoptind;
 argv += BSDoptind;
 if (argc != 2)
  goto usage;
 data->sh_cmd = xstrdup(argv[0]);
 data->cmd = xstrdup(argv[1]);
 return (0);
usage:
 xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
 self->entry->free(self);
 return (-1);
}

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 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 { long tv_sec; long tv_usec; } key_timer; unsigned long ksize; struct tty_keys { struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; } *rbh_root; } ktree; } tty; struct timeval status_timer; struct timeval repeat_timer; struct screen { char *title; struct grid { 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[8]; } *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_CANCEL=26, MODEKEYCOPY_CLEARSELECTION=27, MODEKEYCOPY_COPYSELECTION=28, MODEKEYCOPY_DOWN=29, MODEKEYCOPY_ENDOFLINE=30, MODEKEYCOPY_GOTOLINE=31, MODEKEYCOPY_HALFPAGEDOWN=32, MODEKEYCOPY_HALFPAGEUP=33, MODEKEYCOPY_LEFT=34, MODEKEYCOPY_NEXTPAGE=35, MODEKEYCOPY_NEXTWORD=36, MODEKEYCOPY_PREVIOUSPAGE=37, MODEKEYCOPY_PREVIOUSWORD=38, MODEKEYCOPY_RIGHT=39, MODEKEYCOPY_SEARCHAGAIN=40, MODEKEYCOPY_SEARCHDOWN=41, MODEKEYCOPY_SEARCHUP=42, MODEKEYCOPY_STARTOFLINE=43, MODEKEYCOPY_STARTSELECTION=44, MODEKEYCOPY_UP=45 } 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 tv; unsigned int sx; unsigned int sy; struct winlink { int idx; struct window { char *name; struct timeval name_timer; struct window_pane { struct window *window; 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; 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; 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 *, 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; 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_KEY=2 } type; union { char *string; long long number; int key; } value; struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; } *sph_root; } tree; struct options *parent; } options; unsigned int references; } *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *sle_next; } sentry; } *curw; struct winlink_stack { struct winlink *slh_first; } lastw; struct winlinks { struct winlink *rbh_root; } windows; struct options options; struct paste_stack { struct paste_buffer { char *data; unsigned long size; 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; struct termios *tio; struct environ environ; int references; } *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; } *

variable_types: argc int

variable_types:
argv
char **

variable_types:
cause
char **

variable_types: struct cmd_if_shell_data { char *cmd; char *sh_cmd; } *

variable_types: opt int

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 environ environ; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; 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 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; struct termios *tio; struct environ environ; int references; }

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

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

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

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

user_defined_types: struct 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; 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; unsigned char utf8_buf[4]; unsigned int utf8_len; unsigned int utf8_off; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }


decompiled_code:
unsigned __int64 __fastcall cmd_if_shell_print(__int64 a1, __int64 a2, unsigned __int64 a3)
{
_QWORD *v4; // r13
int v5; // eax
unsigned __int64 v6; // rbx

v4 = *(_QWORD **)(a1 + 8);
v5 = xsnprintf(a2, a3, "%s", **(const char ***)a1);
v6 = v5;
if ( v4 )
{
if ( v5 < a3 )
{
if ( !v4[1] || (v6 = cmd_prarg(a2 + v5, a3 - v5, " ") + v5, a3 > v6) )
{
if ( *v4 )
v6 += cmd_prarg(a2 + v6, a3 - v6, " ");
}
}
}
return v6;
}

original_code:
size_t
cmd_if_shell_print(struct cmd *self, char *buf, size_t len)
{
 struct cmd_if_shell_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->sh_cmd != ((void *)0))
  off += cmd_prarg(buf + off, len - off, " ", data->sh_cmd);
 if (off < len && data->cmd != ((void *)0))
  off += cmd_prarg(buf + off, len - off, " ", data->cmd);
 return (off);
}

canonical_original_code:
unsigned long cmd_if_shell_print(struct cmd *self, char *buf, unsigned long len)
{
 struct cmd_if_shell_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->sh_cmd != ((void *)0))
  off += cmd_prarg(buf + off, len - off, " ", data->sh_cmd);
 if (off < len && data->cmd != ((void *)0))
  off += cmd_prarg(buf + off, len - off, " ", data->cmd);
 return (off);
}

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types:
off
unsigned long

return_type: unsigned long

user_defined_types: struct cmd_if_shell_data { char *cmd; char *sh_cmd; }

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 environ { struct environ_entry *rbh_root; }

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

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

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 grid { int flags; unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; struct grid_line *linedata; }

user_defined_types: struct winlink_stack { struct winlink *slh_first; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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

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

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_CANCEL=26, MODEKEYCOPY_CLEARSELECTION=27, MODEKEYCOPY_COPYSELECTION=28, MODEKEYCOPY_DOWN=29, MODEKEYCOPY_ENDOFLINE=30, MODEKEYCOPY_GOTOLINE=31, MODEKEYCOPY_HALFPAGEDOWN=32, MODEKEYCOPY_HALFPAGEUP=33, MODEKEYCOPY_LEFT=34, MODEKEYCOPY_NEXTPAGE=35, MODEKEYCOPY_NEXTWORD=36, MODEKEYCOPY_PREVIOUSPAGE=37, MODEKEYCOPY_PREVIOUSWORD=38, MODEKEYCOPY_RIGHT=39, MODEKEYCOPY_SEARCHAGAIN=40, MODEKEYCOPY_SEARCHDOWN=41, MODEKEYCOPY_SEARCHUP=42, MODEKEYCOPY_STARTOFLINE=43, MODEKEYCOPY_STARTSELECTION=44, MODEKEYCOPY_UP=45 }

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall cmd_if_shell_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 func1(__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_if_shell_free(struct cmd *self)
{
 struct cmd_if_shell_data *data = self->data;
 if (data->cmd != ((void *)0))
  xfree(data->cmd);
 if (data->sh_cmd != ((void *)0))
  xfree(data->sh_cmd);
 xfree(data);
}

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_if_shell_data { char *cmd; char *sh_cmd; }

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 environ environ; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; 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 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 timeval { long tv_sec; long tv_usec; }

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 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; struct termios *tio; struct environ environ; int references; }

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

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 winlink_stack { struct winlink *slh_first; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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

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

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

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

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

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

user_defined_types: struct 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; 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; unsigned char utf8_buf[4]; unsigned int utf8_len; unsigned int utf8_off; unsigned char intermediate; void *(*state)(unsigned char, struct input_ctx *); unsigned char private; struct { struct input_arg *list; unsigned int num; unsigned long space; } args; }


decompiled_code:
__int64 __fastcall cmd_if_shell_exec(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // eax
unsigned int v4; // ebx
void (*v6)(__int64, const char *, ...); // rbx
int *v7; // rax
char *v8; // rax
const char *v9; // [rsp+0h] [rbp-28h] BYREF
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = *(_QWORD *)(a1 + 8);
v3 = system(*(const char **)(v2 + 8));
if ( v3 < 0 )
{
v6 = *(void (**)(__int64, const char *, ...))(a2 + 40);
v7 = _errno_location();
v8 = strerror(*v7);
v6(a2, "system error: %s", v8);
v4 = -1;
}
else
{
v4 = 0;
if ( !v3 )
{
v4 = cmd_string_parse(*(_QWORD *)v2, v10, &v9);
if ( v4 )
{
v4 = -1;
if ( v9 )
{
(*(void (**)(__int64, const char *, ...))(a2 + 40))(a2, "%s", v9);
xfree(v9);
}
}
else if ( (int)cmd_list_exec(v10[0], a2) < 0 )
{
cmd_list_free(v10[0]);
v4 = -1;
}
else
{
cmd_list_free(v10[0]);
}
}
}
return v4;
}

original_code:
int
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{
 struct cmd_if_shell_data *data = self->data;
 struct cmd_list *cmdlist;
 char *cause;
 int ret;
 if ((ret = system(data->sh_cmd)) < 0) {
  ctx->error(ctx, "system error: %s", strerror((*__errno_location ())));
  return (-1);
 } else if (ret != 0)
  return (0);
 if (cmd_string_parse(data->cmd, &cmdlist, &cause) != 0) {
  if (cause != ((void *)0)) {
   ctx->error(ctx, "%s", cause);
   xfree(cause);
  }
  return (-1);
 }
 if (cmd_list_exec(cmdlist, ctx) < 0) {
  cmd_list_free(cmdlist);
  return (-1);
 }
 cmd_list_free(cmdlist);
 return (0);
}

variable_types:
ctx
struct cmd_ctx *

variable_types: struct cmd_list { 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 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 { long tv_sec; long tv_usec; } key_timer; unsigned long ksize; struct tty_keys { struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; } *rbh_root; } ktree; } tty; struct timeval status_timer; struct timeval repeat_timer; struct screen { char *title; struct grid { 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[8]; } *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_CANCEL=26, MODEKEYCOPY_CLEARSELECTION=27, MODEKEYCOPY_COPYSELECTION=28, MODEKEYCOPY_DOWN=29, MODEKEYCOPY_ENDOFLINE=30, MODEKEYCOPY_GOTOLINE=31, MODEKEYCOPY_HALFPAGEDOWN=32, MODEKEYCOPY_HALFPAGEUP=33, MODEKEYCOPY_LEFT=34, MODEKEYCOPY_NEXTPAGE=35, MODEKEYCOPY_NEXTWORD=36, MODEKEYCOPY_PREVIOUSPAGE=37, MODEKEYCOPY_PREVIOUSWORD=38, MODEKEYCOPY_RIGHT=39, MODEKEYCOPY_SEARCHAGAIN=40, MODEKEYCOPY_SEARCHDOWN=41, MODEKEYCOPY_SEARCHUP=42, MODEKEYCOPY_STARTOFLINE=43, MODEKEYCOPY_STARTSELECTION=44, MODEKEYCOPY_UP=45 } 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 tv; unsigned int sx; unsigned int sy; struct winlink { int idx; struct window { char *name; struct timeval name_timer; struct window_pane { struct window *window; 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; 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; 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 *, 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; 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_KEY=2 } type; union { char *string; long long number; int key; } value; struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; } *sph_root; } tree; struct options *parent; } options; unsigned int references; } *window; struct { struct winlink *rbe_left; struct winlink *rbe_right; struct winlink *rbe_parent; int rbe_color; } entry; struct { struct winlink *sle_next; } sentry; } *curw; struct winlink_stack { struct winlink *slh_first; } lastw; struct winlinks { struct winlink *rbh_root; } windows; struct options options; struct paste_stack { struct paste_buffer { char *data; unsigned long size; 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; struct termios *tio; struct environ environ; int references; } *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; } *tqh_first; struct cmd **tqh_last; } *

variable_types:
cause
char *

variable_types: ret int

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_if_shell_data { char *cmd; char *sh_cmd; }

user_defined_types: struct cmd_list { struct cmd *tqh_first; struct cmd **tqh_last; }

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 environ environ; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; 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 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; struct termios *tio; struct environ environ; int references; }

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

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

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


decompiled_code:
__int64 __fastcall client_handle_winch(__int64 a1)
{
__int64 result; // rax
__int16 v2[4]; // [rsp+0h] [rbp-18h] BYREF
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

if ( ioctl(0, 0x5413uLL, v2) == -1 )
{
log_fatal("%s: %s", "client_handle_winch", "ioctl failed");
result = client_msg_dispatch();
}
else
{
v3[0] = (unsigned __int16)v2[1];
v3[1] = (unsigned __int16)v2[0];
result = client_write_server(a1, 9LL, v3, 8LL);
sigwinch = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
__int16 v2[4]; // [rsp+0h] [rbp-18h] BYREF
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

if ( ioctl(0, 0x5413uLL, v2) == -1 )
{
log_fatal("%s: %s", "client_handle_winch", "ioctl failed");
result = func3();
}
else
{
v3[0] = (unsigned __int16)v2[1];
v3[1] = (unsigned __int16)v2[0];
result = client_write_server(a1, 9LL, v3, 8LL);
sigwinch = 0;
}
return result;
}

original_code:
void
client_handle_winch(struct client_ctx *cctx)
{
 struct msg_resize_data data;
 struct winsize ws;
 if (ioctl(0, 0x5413, &ws) == -1)
  log_fatal("%s: %s", __func__, "ioctl failed");;
 data.sx = ws.ws_col;
 data.sy = ws.ws_row;
 client_write_server(cctx, MSG_RESIZE, &data, sizeof data);
 sigwinch = 0;
}

variable_types: struct client_ctx { int srv_fd; struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; } *srv_in; struct buffer *srv_out; int flags; } *

variable_types: struct msg_resize_data { unsigned int sx; unsigned int sy; }

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

user_defined_types: struct client_ctx { int srv_fd; struct buffer *srv_in; struct buffer *srv_out; int flags; }


decompiled_code:
void __fastcall client_send_environ(__int64 a1)
{
char **v1; // rbx
char *i; // rsi
_BYTE v3[1048]; // [rsp+0h] [rbp-418h] BYREF

v1 = environ;
for ( i = *environ; *v1; i = *v1 )
{
if ( (unsigned __int64)strlcpy(v3, i, 1024LL) <= 0x3FF )
client_write_server(a1, 15LL, v3, 1024LL);
++v1;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
char **v1; // rbx
char *i; // rsi
_BYTE v3[1048]; // [rsp+0h] [rbp-418h] BYREF

v1 = environ;
for ( i = *environ; *v1; i = *v1 )
{
if ( (unsigned __int64)strlcpy(v3, i, 1024LL) <= 0x3FF )
client_write_server(a1, 15LL, v3, 1024LL);
++v1;
}
}

original_code:
void
client_send_environ(struct client_ctx *cctx)
{
 char **var;
 struct msg_environ_data data;
  for (var = environ; *var != ((void *)0); var++) {
  if (strlcpy(data.var, *var, sizeof data.var) >= sizeof data.var)
   continue;
  client_write_server(cctx, MSG_ENVIRON, &data, sizeof data);
 }
}

variable_types: struct client_ctx { 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; enum { CCTX_DETACH=0, CCTX_EXIT=1, CCTX_DIED=2, CCTX_SHUTDOWN=3 } exittype; char *errstr; } *

variable_types:
var
char **

variable_types: struct msg_environ_data { char var[1024]; }

user_defined_types: struct client_ctx { struct imsgbuf ibuf; enum { CCTX_DETACH=0, CCTX_EXIT=1, CCTX_DIED=2, CCTX_SHUTDOWN=3 } exittype; char *errstr; }