decompiled_code:
__int64 __fastcall cmd_choose_client_exec(__int64 a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // r13
unsigned int v4; // er12
unsigned int v5; // er15
unsigned int v6; // ebx
unsigned int v7; // er14
__int64 v8; // rax
const char **v9; // rcx
const char *v10; // rdx
__int64 *v11; // rbx
const char *v12; // rdi
__int64 v13; // rax
__int64 v15; // [rsp+8h] [rbp-40h]

v15 = *(_QWORD *)(a1 + 8);
if ( *a2 )
{
v2 = cmd_find_window(a2, *(_QWORD *)(v15 + 8), 0LL);
v3 = v2;
if ( v2 )
{
v4 = window_pane_set_mode(*(_QWORD *)(*(_QWORD *)(v2 + 8) + 136LL), &window_choose_mode);
if ( v4 )
{
v4 = 0;
}
else
{
v5 = *((_DWORD *)&clients + 2);
if ( v5 )
{
v5 = 0;
v6 = 0;
v7 = 0;
do
{
v8 = *(_QWORD *)(clients + 8LL * v7);
if ( v8 )
{
v9 = *(const char ***)(v8 + 66968);
if ( v9 )
{
v10 = (const char *)&unk_320;
if ( *a2 == v8 )
v5 = v6;
++v6;
if ( (*(_BYTE *)(v8 + 66184) & 8) != 0 )
v10 = " (utf8)";
window_choose_add(
*(_QWORD *)(*(_QWORD *)(v3 + 8) + 136LL),
v7,
"%s: %s [%ux%u %s]%s",
*(const char **)(v8 + 65784),
*v9,
*(unsigned int *)(v8 + 65792),
*(unsigned int *)(v8 + 65796),
*(const char **)(v8 + 65824),
v10);
}
}
++v7;
}
while ( *((_DWORD *)&clients + 2) > v7 );
}
v11 = (__int64 *)xmalloc(16LL);
v12 = *(const char **)(v15 + 16);
if ( !v12 )
v12 = "detach-client -t '%%'";
v11[1] = xstrdup(v12);
v13 = *a2;
*v11 = *a2;
++*(_DWORD *)(v13 + 66976);
window_choose_ready(
*(_QWORD *)(*(_QWORD *)(v3 + 8) + 136LL),
v5,
cmd_choose_client_callback,
cmd_choose_client_free,
v11);
}
}
else
{
v4 = -1;
}
}
else
{
v4 = -1;
((void (__fastcall *)(__int64 *, const char *))a2[5])(a2, "must be run interactively");
}
return v4;
}

original_code:
int
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
 struct cmd_target_data *data = self->data;
 struct cmd_choose_client_data *cdata;
 struct winlink *wl;
 struct client *c;
 u_int i, idx, cur;
 if (ctx->curclient == ((void *)0)) {
  ctx->error(ctx, "must be run interactively");
  return (-1);
 }
 if ((wl = cmd_find_window(ctx, data->target, ((void *)0))) == ((void *)0))
  return (-1);
 if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
  return (0);
 cur = idx = 0;
 for (i = 0; i < ((&clients)->num); i++) {
  c = ((&clients)->list[i]);
  if (c == ((void *)0) || c->session == ((void *)0))
   continue;
  if (c == ctx->curclient)
   cur = idx;
  idx++;
  window_choose_add(wl->window->active, i,
      "%s: %s [%ux%u %s]%s", c->tty.path,
      c->session->name, c->tty.sx, c->tty.sy,
      c->tty.termname, c->tty.flags & 0x8 ? " (utf8)" : "");
 }
 cdata = xmalloc(sizeof *cdata);
 if (data->arg != ((void *)0))
  cdata->template = xstrdup(data->arg);
 else
  cdata->template = xstrdup("detach-client -t '%%'");
 cdata->client = ctx->curclient;
 cdata->client->references++;
 window_choose_ready(wl->window->active,
     cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
 return (0);
}

canonical_original_code:
int cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
 struct cmd_target_data *data = self->data;
 struct cmd_choose_client_data *cdata;
 struct winlink *wl;
 struct client *c;
 unsigned int i; unsigned int idx; unsigned int cur;
 if (ctx->curclient == ((void *)0)) {
  ctx->error(ctx, "must be run interactively");
  return (-1);
 }
 if ((wl = cmd_find_window(ctx, data->target, ((void *)0))) == ((void *)0))
  return (-1);
 if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
  return (0);
 cur = idx = 0;
 for (i = 0; i < ((&clients)->num); i++) {
  c = ((&clients)->list[i]);
  if (c == ((void *)0) || c->session == ((void *)0))
   continue;
  if (c == ctx->curclient)
   cur = idx;
  idx++;
  window_choose_add(wl->window->active, i,
      "%s: %s [%ux%u %s]%s", c->tty.path,
      c->session->name, c->tty.sx, c->tty.sy,
      c->tty.termname, c->tty.flags & 0x8 ? " (utf8)" : "");
 }
 cdata = xmalloc(sizeof *cdata);
 if (data->arg != ((void *)0))
  cdata->template = xstrdup(data->arg);
 else
  cdata->template = xstrdup("detach-client -t '%%'");
 cdata->client = ctx->curclient;
 cdata->client->references++;
 window_choose_ready(wl->window->active,
     cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
 return (0);
}

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:
ctx
struct cmd_ctx *

variable_types: struct cmd_target_data { unsigned long chflags; char *target; char *arg; char *arg2; } *

variable_types: struct cmd_choose_client_data { 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; } *client; char *template; } *

variable_types: struct winlink { int idx; struct window { char *name; struct timeval { long tv_sec; long tv_usec; } name_timer; struct window_pane { struct window *window; struct layout_cell { enum layout_type { LAYOUT_LEFTRIGHT=0, LAYOUT_TOPBOTTOM=1, LAYOUT_WINDOWPANE=2 } type; struct layout_cell *parent; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; struct window_pane *wp; struct layout_cells { struct layout_cell *tqh_first; struct layout_cell **tqh_last; } cells; struct { struct layout_cell *tqe_next; struct layout_cell **tqe_prev; } entry; } *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; } *in; struct buffer *out; struct input_ctx { struct window_pane *wp; struct screen_write_ctx { struct window_pane *wp; struct screen { char *title; struct grid { int flags; unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; struct grid_line { unsigned int cellsize; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } *celldata; unsigned int utf8size; struct grid_utf8 { unsigned char width; unsigned char data[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; } *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 { 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 *in; struct buffer *out; int log_fd; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } tio; struct grid_cell cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval key_timer; unsigned long ksize; struct tty_keys { struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; } *rbh_root; } ktree; } tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; 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 *curw; struct winlink_stack { struct winlink *slh_first; } lastw; struct winlinks { struct winlink *rbh_root; } windows; struct options { struct options_tree { struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_KEY=2 } type; union { char *string; long long number; int key; } value; struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; } *sph_root; } tree; struct options *parent; } options; struct paste_stack { struct paste_buffer { char *data; 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; } *, 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 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; } *

variable_types:
i
unsigned int

variable_types:
idx
unsigned int

variable_types:
cur
unsigned 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_choose_client_data { struct client *client; char *template; }

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

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

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

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

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

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

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

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

user_defined_types: struct options_tree { struct options_entry *sph_root; }


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
__int64 __fastcall cmd_choose_client_free(__int64 *a1)
{
__int64 v1; // rax
__int64 v3; // rdi

v1 = *a1;
v3 = a1[1];
--*(_DWORD *)(v1 + 66976);
xfree(v3);
return xfree(a1);
}

original_code:
void
cmd_choose_client_free(void *data)
{
 struct cmd_choose_client_data *cdata = data;
 cdata->client->references--;
 xfree(cdata->template);
 xfree(cdata);
}

variable_types:
data
void *

return_type: void

user_defined_types: struct cmd_choose_client_data { struct client *client; char *template; }

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

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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

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

user_defined_types: struct 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 buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; }

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

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

user_defined_types: enum mode_key_cmd { MODEKEY_NONE=0, MODEKEY_OTHER=1, MODEKEYEDIT_BACKSPACE=2, MODEKEYEDIT_CANCEL=3, MODEKEYEDIT_COMPLETE=4, MODEKEYEDIT_CURSORLEFT=5, MODEKEYEDIT_CURSORRIGHT=6, MODEKEYEDIT_DELETE=7, MODEKEYEDIT_DELETELINE=8, MODEKEYEDIT_DELETETOENDOFLINE=9, MODEKEYEDIT_ENDOFLINE=10, MODEKEYEDIT_ENTER=11, MODEKEYEDIT_HISTORYDOWN=12, MODEKEYEDIT_HISTORYUP=13, MODEKEYEDIT_PASTE=14, MODEKEYEDIT_STARTOFLINE=15, MODEKEYEDIT_SWITCHMODE=16, MODEKEYEDIT_SWITCHMODEAPPEND=17, MODEKEYEDIT_TRANSPOSECHARS=18, MODEKEYCHOICE_CANCEL=19, MODEKEYCHOICE_CHOOSE=20, MODEKEYCHOICE_DOWN=21, MODEKEYCHOICE_PAGEDOWN=22, MODEKEYCHOICE_PAGEUP=23, MODEKEYCHOICE_UP=24, MODEKEYCOPY_BACKTOINDENTATION=25, MODEKEYCOPY_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 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 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:
void __fastcall cmd_choose_client_callback(__int64 *a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // r12
char *v4; // rbx
__int64 v5; // rax
__int64 v6; // [rsp+0h] [rbp-58h] BYREF
char *v7; // [rsp+8h] [rbp-50h] BYREF
__int64 v8[9]; // [rsp+10h] [rbp-48h] BYREF

if ( a2 != -1 && (*(_BYTE *)(*a1 + 66577) & 2) == 0 && *((_DWORD *)&clients + 2) - 1 >= a2 )
{
v2 = *(_QWORD *)(clients + 8LL * (int)a2);
if ( v2 )
{
if ( *(_QWORD *)(v2 + 66968) )
{
v3 = cmd_template_replace(a1[1], *(_QWORD *)(v2 + 65784), 1LL);
if ( (unsigned int)cmd_string_parse(v3, &v6, &v7) )
{
v4 = v7;
if ( v7 )
{
*v4 = (*_ctype_toupper_loc())[(unsigned __int8)*v4];
status_message_set(v2, "%s", v7);
xfree(v7);
}
xfree(v3);
}
else
{
xfree(v3);
v5 = *a1;
v8[2] = 0LL;
v8[0] = v5;
v8[5] = (__int64)&key_bindings_error;
v8[3] = (__int64)&key_bindings_print;
v8[4] = (__int64)&key_bindings_info;
v8[1] = 0LL;
cmd_list_exec(v6, v8);
cmd_list_free(v6);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 *a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // r12
char *v4; // rbx
__int64 v5; // rax
__int64 v6; // [rsp+0h] [rbp-58h] BYREF
char *v7; // [rsp+8h] [rbp-50h] BYREF
__int64 v8[9]; // [rsp+10h] [rbp-48h] BYREF

if ( a2 != -1 && (*(_BYTE *)(*a1 + 66577) & 2) == 0 && *((_DWORD *)&clients + 2) - 1 >= a2 )
{
v2 = *(_QWORD *)(clients + 8LL * (int)a2);
if ( v2 )
{
if ( *(_QWORD *)(v2 + 66968) )
{
v3 = cmd_template_replace(a1[1], *(_QWORD *)(v2 + 65784), 1LL);
if ( (unsigned int)cmd_string_parse(v3, &v6, &v7) )
{
v4 = v7;
if ( v7 )
{
*v4 = (*_ctype_toupper_loc())[(unsigned __int8)*v4];
status_message_set(v2, "%s", v7);
xfree(v7);
}
xfree(v3);
}
else
{
xfree(v3);
v5 = *a1;
v8[2] = 0LL;
v8[0] = v5;
v8[5] = (__int64)&key_bindings_error;
v8[3] = (__int64)&key_bindings_print;
v8[4] = (__int64)&key_bindings_info;
v8[1] = 0LL;
cmd_list_exec(v6, v8);
cmd_list_free(v6);
}
}
}
}
}

original_code:
void
cmd_choose_client_callback(void *data, int idx)
{
 struct cmd_choose_client_data *cdata = data;
 struct client *c;
 struct cmd_list *cmdlist;
 struct cmd_ctx ctx;
 char *template, *cause;
 if (idx == -1)
  return;
 if (cdata->client->flags & 0x200)
  return;
 if ((u_int) idx > ((&clients)->num) - 1)
  return;
 c = ((&clients)->list[idx]);
 if (c == ((void *)0) || c->session == ((void *)0))
  return;
 template = cmd_template_replace(cdata->template, c->tty.path, 1);
 if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
  if (cause != ((void *)0)) {
   *cause = toupper((u_char) *cause);
   status_message_set(c, "%s", cause);
   xfree(cause);
  }
  xfree(template);
  return;
 }
 xfree(template);
 ctx.msgdata = ((void *)0);
 ctx.curclient = cdata->client;
 ctx.error = key_bindings_error;
 ctx.print = key_bindings_print;
 ctx.info = key_bindings_info;
 ctx.cmdclient = ((void *)0);
 cmd_list_exec(cmdlist, &ctx);
 cmd_list_free(cmdlist);
}

canonical_original_code:
void cmd_choose_client_callback(void *data, int idx)
{
 struct cmd_choose_client_data *cdata = data;
 struct client *c;
 struct cmd_list *cmdlist;
 struct cmd_ctx ctx;
 char *template; char *cause;
 if (idx == -1)
  return;
 if (cdata->client->flags & 0x200)
  return;
 if ((unsigned int) idx > ((&clients)->num) - 1)
  return;
 c = ((&clients)->list[idx]);
 if (c == ((void *)0) || c->session == ((void *)0))
  return;
 template = cmd_template_replace(cdata->template, c->tty.path, 1);
 if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
  if (cause != ((void *)0)) {
   *cause = toupper((u_char) *cause);
   status_message_set(c, "%s", cause);
   xfree(cause);
  }
  xfree(template);
  return;
 }
 xfree(template);
 ctx.msgdata = ((void *)0);
 ctx.curclient = cdata->client;
 ctx.error = key_bindings_error;
 ctx.print = key_bindings_print;
 ctx.info = key_bindings_info;
 ctx.cmdclient = ((void *)0);
 cmd_list_exec(cmdlist, &ctx);
 cmd_list_free(cmdlist);
}

variable_types: idx int

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:
template
char *

variable_types:
cause
char *

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 cmd_choose_client_data { struct client *client; char *template; }

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

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

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

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

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

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

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

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

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

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

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

user_defined_types: struct window_pane { struct window *window; struct layout_cell *layout_cell; unsigned int sx; unsigned int sy; unsigned int xoff; unsigned int yoff; int flags; char *cmd; char *shell; char *cwd; int pid; int fd; char tty[32]; struct buffer *in; struct buffer *out; struct input_ctx ictx; 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; }

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 cmd_send_keys_send(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a1 + 8);
buffer_write(a2, v2, 24LL);
cmd_send_string(a2, *(_QWORD *)v2);
return buffer_write(a2, *(_QWORD *)(v2 + 16), 4LL * *(unsigned int *)(v2 + 12));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a1 + 8);
buffer_write(a2, v2, 24LL);
cmd_send_string(a2, *(_QWORD *)v2);
return buffer_write(a2, *(_QWORD *)(v2 + 16), 4LL * *(unsigned int *)(v2 + 12));
}

original_code:
void
cmd_send_keys_send(struct cmd *self, struct buffer *b)
{
 struct cmd_send_keys_data *data = self->data;
 buffer_write(b, data, sizeof *data);
 cmd_send_string(b, data->target);
 buffer_write(b, data->keys, data->nkeys * sizeof *data->keys);
}

variable_types: struct cmd { struct cmd_entry { char *name; char *alias; char *usage; int flags; void (*init)(struct cmd *, int); int (*parse)(struct cmd *, int, char **, char **); int (*exec)(struct cmd *, struct cmd_ctx { struct client { int fd; struct buffer { unsigned char *base; unsigned long space; unsigned long size; unsigned long off; } *in; struct buffer *out; char *title; char *cwd; struct tty { char *path; unsigned int sx; unsigned int sy; unsigned int cx; unsigned int cy; int mode; unsigned int rlower; unsigned int rupper; char *termname; struct tty_term { char *name; unsigned int references; struct tty_code { enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 } type; union { char *string; int number; int flag; } value; } codes[-1]; int flags; struct { struct tty_term *sle_next; } entry; } *term; int fd; struct buffer *in; struct buffer *out; int log_fd; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } tio; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } cell; unsigned char acs[-1]; int flags; int term_flags; struct timeval { long tv_sec; long tv_usec; } key_timer; unsigned long ksize; struct tty_keys { struct tty_key { int key; char *string; int flags; struct { struct tty_key *rbe_left; struct tty_key *rbe_right; struct tty_key *rbe_parent; int rbe_color; } entry; } *rbh_root; } ktree; } tty; struct timeval status_timer; struct timeval repeat_timer; struct screen { char *title; struct grid { unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; unsigned int *size; struct grid_cell **data; unsigned int *usize; struct grid_utf8 { unsigned char width; unsigned char data[8]; } **udata; } *grid; unsigned int cx; unsigned int cy; unsigned int old_cx; unsigned int old_cy; unsigned int rupper; unsigned int rlower; unsigned int old_rupper; unsigned int old_rlower; int mode; 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; } *

variable_types:
b
struct buffer *

variable_types: struct cmd_send_keys_data { char *target; int idx; unsigned int nkeys; int *keys; } *

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

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

user_defined_types: struct client { int fd; struct buffer *in; struct buffer *out; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_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 grid { unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; unsigned int *size; struct grid_cell **data; unsigned int *usize; struct grid_utf8 **udata; }

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

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

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

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


decompiled_code:
__int64 __fastcall cmd_send_keys_recv(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rax
__int64 v7; // rdx

v2 = xmalloc(24LL);
*(_QWORD *)(a1 + 8) = v2;
v3 = v2;
buffer_read(a2, v2, 24LL);
v4 = cmd_recv_string(a2);
v5 = *(unsigned int *)(v3 + 12);
*(_QWORD *)v3 = v4;
v6 = xcalloc(v5, 4LL);
v7 = *(unsigned int *)(v3 + 12);
*(_QWORD *)(v3 + 16) = v6;
return buffer_read(a2, v6, 4 * v7);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rax
__int64 v7; // rdx

v2 = xmalloc(24LL);
*(_QWORD *)(a1 + 8) = v2;
v3 = v2;
buffer_read(a2, v2, 24LL);
v4 = cmd_recv_string(a2);
v5 = *(unsigned int *)(v3 + 12);
*(_QWORD *)v3 = v4;
v6 = xcalloc(v5, 4LL);
v7 = *(unsigned int *)(v3 + 12);
*(_QWORD *)(v3 + 16) = v6;
return buffer_read(a2, v6, 4 * v7);
}

original_code:
void
cmd_send_keys_recv(struct cmd *self, struct buffer *b)
{
 struct cmd_send_keys_data *data;
 self->data = data = xmalloc(sizeof *data);
 buffer_read(b, data, sizeof *data);
 data->target = cmd_recv_string(b);
 data->keys = xcalloc(data->nkeys, sizeof *data->keys);
 buffer_read(b, data->keys, data->nkeys * sizeof *data->keys);
}

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_send_keys_data { char *target; int idx; unsigned int nkeys; int *keys; }

user_defined_types: struct msg_command_data { int pid; unsigned int idx; unsigned long namelen; }

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

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

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

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

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

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

user_defined_types: struct paste_buffer { char *data; struct timeval tv; }

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

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

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: struct input_arg { unsigned char data[64]; unsigned long used; }


decompiled_code:
__int64 __fastcall cmd_send_keys_free(__int64 a1)
{
_QWORD *v1; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbp

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

original_code:
void
cmd_send_keys_free(struct cmd *self)
{
 struct cmd_send_keys_data *data = self->data;
 if (data->target != ((void *)0))
  xfree(data->target);
 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_send_keys_data { char *target; int idx; unsigned int nkeys; int *keys; }

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

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

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

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

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

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

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

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

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

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

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


gcd

decompiled_code:
__int64 __fastcall gcd(int a1, int a2)
{
int v2; // edx
int v3; // er8
int v4; // eax
int v5; // edx

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
do
{
v3 = v2;
v4 = a2;
v5 = a2 >> 31;
a2 = v3;
v2 = __SPAIR64__(v5, v4) % v3;
}
while ( v2 );
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v2; // edx
int v3; // er8
int v4; // eax
int v5; // edx

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
do
{
v3 = v2;
v4 = a2;
v5 = a2 >> 31;
a2 = v3;
v2 = __SPAIR64__(v5, v4) % v3;
}
while ( v2 );
return (unsigned int)v3;
}

original_code:
static int
gcd(int a, int b)
{
 int c;
 c = a % b;
 while (c != 0) {
  a = b;
  b = c;
  c = a % b;
 }
 return (b);
}

variable_types: a int

variable_types: b int

variable_types: c int

return_type: int


original_code:
static void
permute_args(int panonopt_start, int panonopt_end, int opt_end,
 char * const *nargv)
{
 int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
 char *swap;
 nnonopts = panonopt_end - panonopt_start;
 nopts = opt_end - panonopt_end;
 ncycle = gcd(nnonopts, nopts);
 cyclelen = (opt_end - panonopt_start) / ncycle;
 for (i = 0; i < ncycle; i++) {
  cstart = panonopt_end+i;
  pos = cstart;
  for (j = 0; j < cyclelen; j++) {
   if (pos >= panonopt_end)
    pos -= nnonopts;
   else
    pos += nopts;
   swap = nargv[pos];
   ((char **) nargv)[pos] = nargv[cstart];
   ((char **)nargv)[cstart] = swap;
  }
 }
}

canonical_original_code:
static void permute_args(int panonopt_start, int panonopt_end, int opt_end, char **nargv)
{
 int cstart; int cyclelen; int i; int j; int ncycle; int nnonopts; int nopts; int pos;
 char *swap;
 nnonopts = panonopt_end - panonopt_start;
 nopts = opt_end - panonopt_end;
 ncycle = gcd(nnonopts, nopts);
 cyclelen = (opt_end - panonopt_start) / ncycle;
 for (i = 0; i < ncycle; i++) {
  cstart = panonopt_end+i;
  pos = cstart;
  for (j = 0; j < cyclelen; j++) {
   if (pos >= panonopt_end)
    pos -= nnonopts;
   else
    pos += nopts;
   swap = nargv[pos];
   ((char **) nargv)[pos] = nargv[cstart];
   ((char **)nargv)[cstart] = swap;
  }
 }
}

variable_types:
nargv
char **

variable_types: cstart int

variable_types: cyclelen int

variable_types: i int

variable_types: j int

variable_types: ncycle int

variable_types: nnonopts int

variable_types: nopts int

variable_types: pos int

variable_types:
swap
char *


decompiled_code:
__int64 __fastcall parse_long_options(__int64 a1, _BYTE *a2, const char **a3, int *a4, int a5)
{
const char *v5; // r13
char *v6; // rax
size_t v7; // r12
const char *v8; // r15
const char **v9; // rbx
int v10; // er14
int v11; // ebp
const char **v12; // rdx
int v13; // eax
char *v14; // rcx
__int64 result; // rax
__int64 v16; // rax
__int64 v19; // [rsp+18h] [rbp-60h]
int v21; // [rsp+30h] [rbp-48h]
int v22; // [rsp+34h] [rbp-44h]

v5 = place;
v21 = optind;
v22 = ++optind;
v6 = strchr(place, 61);
v19 = (__int64)v6;
if ( v6 )
{
v19 = (__int64)(v6 + 1);
v7 = v6 - v5;
}
else
{
v7 = strlen(v5);
}
v8 = *a3;
if ( *a3 )
{
v9 = a3 + 4;
v10 = -1;
v11 = 0;
do
{
if ( !strncmp(v5, v8, v7) )
{
if ( strlen(v8) == v7 )
goto LABEL_14;
if ( v7 != 1 || (a5 & 1) == 0 )
{
if ( v10 != -1 )
goto LABEL_27;
v10 = v11;
}
}
v8 = *v9;
v9 += 4;
++v11;
}
while ( v8 );
if ( v10 == -1 )
goto LABEL_26;
v11 = v10;
LABEL_14:
v12 = &a3[4 * v11];
v13 = *((_DWORD *)v12 + 2);
v14 = (char *)v12[2];
if ( v13 )
{
if ( (unsigned int)(v13 - 1) <= 1 )
{
if ( v19 )
{
optarg = v19;
}
else if ( v13 == 1 )
{
optind = v21 + 2;
v16 = *(_QWORD *)(a1 + 8LL * v22);
optarg = v16;
if ( !v16 )
{
if ( !v14 )
LODWORD(v16) = *((_DWORD *)v12 + 6);
optopt = v16;
optind = v22;
if ( *a2 != 58 )
return 63LL;
return 58LL;
}
}
}
}
else if ( v19 )
{
if ( !v14 )
v13 = *((_DWORD *)v12 + 6);
optopt = v13;
if ( *a2 != 58 )
return 63LL;
return 58LL;
}
if ( a4 )
*a4 = v11;
result = *((unsigned int *)v12 + 6);
if ( v14 )
{
*(_DWORD *)v14 = result;
result = 0LL;
}
}
else
{
LABEL_26:
if ( a5 )
{
optind = v21;
result = 0xFFFFFFFFLL;
}
else
{
LABEL_27:
optopt = 0;
result = 63LL;
}
}
return result;
}

original_code:
static int
parse_long_options(char * const *nargv, const char *options,
 const struct option *long_options, int *idx, int short_too)
{
 char *current_argv, *has_equal;
 size_t current_argv_len;
 int i, match;
 current_argv = place;
 match = -1;
 optind++;
 if ((has_equal = strchr(current_argv, '=')) != ((void *)0)) {
  current_argv_len = has_equal - current_argv;
  has_equal++;
 } else
  current_argv_len = strlen(current_argv);
 for (i = 0; long_options[i].name; i++) {
  if (strncmp(current_argv, long_options[i].name,
      current_argv_len))
   continue;
  if (strlen(long_options[i].name) == current_argv_len) {
   match = i;
   break;
  }
  if (short_too && current_argv_len == 1)
   continue;
  if (match == -1)
   match = i;
  else {
   if (((opterr) && (*options != ':')))
    warnx(ambig, (int)current_argv_len,
         current_argv);
   optopt = 0;
   return ((int)'?');
  }
 }
 if (match != -1) {
  if (long_options[match].has_arg == 0
      && has_equal) {
   if (((opterr) && (*options != ':')))
    warnx(noarg, (int)current_argv_len,
         current_argv);
   if (long_options[match].flag == ((void *)0))
    optopt = long_options[match].val;
   else
    optopt = 0;
   return (((*options == ':') ? (int)':' : (int)'?'));
  }
  if (long_options[match].has_arg == 1 ||
      long_options[match].has_arg == 2) {
   if (has_equal)
    optarg = has_equal;
   else if (long_options[match].has_arg ==
       1) {
    optarg = nargv[optind++];
   }
  }
  if ((long_options[match].has_arg == 1)
      && (optarg == ((void *)0))) {
   if (((opterr) && (*options != ':')))
    warnx(recargstring,
        current_argv);
   if (long_options[match].flag == ((void *)0))
    optopt = long_options[match].val;
   else
    optopt = 0;
   --optind;
   return (((*options == ':') ? (int)':' : (int)'?'));
  }
 } else {
  if (short_too) {
   --optind;
   return (-1);
  }
  if (((opterr) && (*options != ':')))
   warnx(illoptstring, current_argv);
  optopt = 0;
  return ((int)'?');
 }
 if (idx)
  *idx = match;
 if (long_options[match].flag) {
  *long_options[match].flag = long_options[match].val;
  return (0);
 } else
  return (long_options[match].val);
}

canonical_original_code:
static int parse_long_options(char **nargv, char *options, struct option *long_options, int *idx, int short_too)
{
 char *current_argv; char *has_equal;
 unsigned long current_argv_len;
 int i; int match;
 current_argv = place;
 match = -1;
 optind++;
 if ((has_equal = strchr(current_argv, '=')) != ((void *)0)) {
  current_argv_len = has_equal - current_argv;
  has_equal++;
 } else
  current_argv_len = strlen(current_argv);
 for (i = 0; long_options[i].name; i++) {
  if (strncmp(current_argv, long_options[i].name,
      current_argv_len))
   continue;
  if (strlen(long_options[i].name) == current_argv_len) {
   match = i;
   break;
  }
  if (short_too && current_argv_len == 1)
   continue;
  if (match == -1)
   match = i;
  else {
   if (((opterr) && (*options != ':')))
    warnx(ambig, (int)current_argv_len,
         current_argv);
   optopt = 0;
   return ((int)'?');
  }
 }
 if (match != -1) {
  if (long_options[match].has_arg == 0
      && has_equal) {
   if (((opterr) && (*options != ':')))
    warnx(noarg, (int)current_argv_len,
         current_argv);
   if (long_options[match].flag == ((void *)0))
    optopt = long_options[match].val;
   else
    optopt = 0;
   return (((*options == ':') ? (int)':' : (int)'?'));
  }
  if (long_options[match].has_arg == 1 ||
      long_options[match].has_arg == 2) {
   if (has_equal)
    optarg = has_equal;
   else if (long_options[match].has_arg ==
       1) {
    optarg = nargv[optind++];
   }
  }
  if ((long_options[match].has_arg == 1)
      && (optarg == ((void *)0))) {
   if (((opterr) && (*options != ':')))
    warnx(recargstring,
        current_argv);
   if (long_options[match].flag == ((void *)0))
    optopt = long_options[match].val;
   else
    optopt = 0;
   --optind;
   return (((*options == ':') ? (int)':' : (int)'?'));
  }
 } else {
  if (short_too) {
   --optind;
   return (-1);
  }
  if (((opterr) && (*options != ':')))
   warnx(illoptstring, current_argv);
  optopt = 0;
  return ((int)'?');
 }
 if (idx)
  *idx = match;
 if (long_options[match].flag) {
  *long_options[match].flag = long_options[match].val;
  return (0);
 } else
  return (long_options[match].val);
}

variable_types:
options
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *

variable_types:
idx
int *

variable_types: match int