decompiled_code:
__int64 __fastcall server_window_check_activity(__int64 a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // r13
unsigned int *v5; // rax

if ( (*(_BYTE *)(a2 + 72) & 4) == 0 )
return 0LL;
if ( *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL) == a2 )
return 0LL;
if ( !options_get_number(a2 + 80, "monitor-activity") )
return 0LL;
if ( (unsigned int)session_alert_has_window(a1, a2, 4LL) )
return 0LL;
session_alert_add(a1, a2, 4LL);
if ( (*(_BYTE *)(a1 + 128) & 1) != 0 )
return 0LL;
if ( options_get_number(a1 + 80, "visual-activity") && *((_DWORD *)&clients + 2) )
{
v3 = 0;
do
{
v4 = *(_QWORD *)(clients + 8LL * v3);
if ( v4 )
{
if ( *(_QWORD *)(v4 + 66368) == a1 )
{
v5 = (unsigned int *)winlink_find_by_window(a1 + 72, a2);
status_message_set(v4, "Activity in window %u", *v5);
}
}
++v3;
}
while ( *((_DWORD *)&clients + 2) > v3 );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // r13
unsigned int *v5; // rax

if ( (*(_BYTE *)(a2 + 72) & 4) == 0 )
return 0LL;
if ( *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL) == a2 )
return 0LL;
if ( !options_get_number(a2 + 80, "monitor-activity") )
return 0LL;
if ( (unsigned int)session_alert_has_window(a1, a2, 4LL) )
return 0LL;
session_alert_add(a1, a2, 4LL);
if ( (*(_BYTE *)(a1 + 128) & 1) != 0 )
return 0LL;
if ( options_get_number(a1 + 80, "visual-activity") && *((_DWORD *)&clients + 2) )
{
v3 = 0;
do
{
v4 = *(_QWORD *)(clients + 8LL * v3);
if ( v4 )
{
if ( *(_QWORD *)(v4 + 66368) == a1 )
{
v5 = (unsigned int *)winlink_find_by_window(a1 + 72, a2);
status_message_set(v4, "Activity in window %u", *v5);
}
}
++v3;
}
while ( *((_DWORD *)&clients + 2) > v3 );
}
return 1LL;
}

original_code:
int
server_window_check_activity(struct session *s, struct window *w)
{
 struct client *c;
 u_int i;
 if (!(w->flags & 0x4))
  return (0);
 if (s->curw->window == w)
  return (0);
  if (!options_get_number(&w->options, "monitor-activity"))
  return (0);
 if (session_alert_has_window(s, w, 0x4))
  return (0);
 session_alert_add(s, w, 0x4);
 if (s->flags & 0x1)
  return (0);
  if (options_get_number(&s->options, "visual-activity")) {
  for (i = 0; i < ((&clients)->num); i++) {
   c = ((&clients)->list[i]);
   if (c == ((void *)0) || c->session != s)
    continue;
   status_message_set(c, "Activity in window %u",
       winlink_find_by_window(&s->windows, w)->idx);
  }
 }
 return (1);
}

canonical_original_code:
int server_window_check_activity(struct session *s, struct window *w)
{
 struct client *c;
 unsigned int i;
 if (!(w->flags & 0x4))
  return (0);
 if (s->curw->window == w)
  return (0);
  if (!options_get_number(&w->options, "monitor-activity"))
  return (0);
 if (session_alert_has_window(s, w, 0x4))
  return (0);
 session_alert_add(s, w, 0x4);
 if (s->flags & 0x1)
  return (0);
  if (options_get_number(&s->options, "visual-activity")) {
  for (i = 0; i < ((&clients)->num); i++) {
   c = ((&clients)->list[i]);
   if (c == ((void *)0) || c->session != s)
    continue;
   status_message_set(c, "Activity in window %u",
       winlink_find_by_window(&s->windows, w)->idx);
  }
 }
 return (1);
}

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

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

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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

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

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

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

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

user_defined_types: struct 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_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; }

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

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

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

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

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 window_panes { struct window_pane *tqh_first; struct window_pane **tqh_last; }

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

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

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

user_defined_types: struct options_tree { struct options_entry *sph_root; }

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

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

user_defined_types: struct 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 grid_utf8 { unsigned char width; unsigned char data[9]; }

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 utf8_data { unsigned char data[9]; unsigned long have; unsigned long size; unsigned int width; }

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

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

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

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

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


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
__int64 __fastcall server_window_check_content(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE *v5; // rax
_BYTE *v6; // rbp
__int64 v8; // rdi
unsigned int v9; // ebp
__int64 v10; // r13
unsigned int *v11; // rax

if ( (*(_BYTE *)(a2 + 72) & 4) == 0 )
return 0LL;
if ( *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL) == a2 )
return 0LL;
v5 = (_BYTE *)options_get_string(a2 + 80, "monitor-content");
v6 = v5;
if ( !v5 )
return 0LL;
if ( !*v5 )
return 0LL;
if ( (unsigned int)session_alert_has_window(a1, a2, 8LL) )
return 0LL;
v8 = window_pane_search(a3, v6, 0LL);
if ( !v8 )
return 0LL;
xfree(v8);
session_alert_add(a1, a2, 8LL);
if ( (*(_BYTE *)(a1 + 128) & 1) != 0 )
return 0LL;
if ( options_get_number(a1 + 80, "visual-content") && *((_DWORD *)&clients + 2) )
{
v9 = 0;
do
{
v10 = *(_QWORD *)(clients + 8LL * v9);
if ( v10 )
{
if ( *(_QWORD *)(v10 + 66368) == a1 )
{
v11 = (unsigned int *)winlink_find_by_window(a1 + 72, a2);
status_message_set(v10, "Content in window %u", *v11);
}
}
++v9;
}
while ( *((_DWORD *)&clients + 2) > v9 );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE *v5; // rax
_BYTE *v6; // rbp
__int64 v8; // rdi
unsigned int v9; // ebp
__int64 v10; // r13
unsigned int *v11; // rax

if ( (*(_BYTE *)(a2 + 72) & 4) == 0 )
return 0LL;
if ( *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL) == a2 )
return 0LL;
v5 = (_BYTE *)options_get_string(a2 + 80, "monitor-content");
v6 = v5;
if ( !v5 )
return 0LL;
if ( !*v5 )
return 0LL;
if ( (unsigned int)session_alert_has_window(a1, a2, 8LL) )
return 0LL;
v8 = window_pane_search(a3, v6, 0LL);
if ( !v8 )
return 0LL;
xfree(v8);
session_alert_add(a1, a2, 8LL);
if ( (*(_BYTE *)(a1 + 128) & 1) != 0 )
return 0LL;
if ( options_get_number(a1 + 80, "visual-content") && *((_DWORD *)&clients + 2) )
{
v9 = 0;
do
{
v10 = *(_QWORD *)(clients + 8LL * v9);
if ( v10 )
{
if ( *(_QWORD *)(v10 + 66368) == a1 )
{
v11 = (unsigned int *)winlink_find_by_window(a1 + 72, a2);
status_message_set(v10, "Content in window %u", *v11);
}
}
++v9;
}
while ( *((_DWORD *)&clients + 2) > v9 );
}
return 1LL;
}

original_code:
int
server_window_check_content(
    struct session *s, struct window *w, struct window_pane *wp)
{
 struct client *c;
 u_int i;
 char *found, *ptr;
 if (!(w->flags & 0x4))
  return (0);
 if (s->curw->window == w)
  return (0);
 ptr = options_get_string(&w->options, "monitor-content");
 if (ptr == ((void *)0) || *ptr == '\0')
  return (0);
 if (session_alert_has_window(s, w, 0x8))
  return (0);
 if ((found = window_pane_search(wp, ptr, ((void *)0))) == ((void *)0))
  return (0);
     xfree(found);
 session_alert_add(s, w, 0x8);
 if (s->flags & 0x1)
  return (0);
  if (options_get_number(&s->options, "visual-content")) {
  for (i = 0; i < ((&clients)->num); i++) {
   c = ((&clients)->list[i]);
   if (c == ((void *)0) || c->session != s)
    continue;
   status_message_set(c, "Content in window %u",
       winlink_find_by_window(&s->windows, w)->idx);
  }
 }
 return (1);
}

canonical_original_code:
int server_window_check_content(struct session *s, struct window *w, struct window_pane *wp)
{
 struct client *c;
 unsigned int i;
 char *found; char *ptr;
 if (!(w->flags & 0x4))
  return (0);
 if (s->curw->window == w)
  return (0);
 ptr = options_get_string(&w->options, "monitor-content");
 if (ptr == ((void *)0) || *ptr == '\0')
  return (0);
 if (session_alert_has_window(s, w, 0x8))
  return (0);
 if ((found = window_pane_search(wp, ptr, ((void *)0))) == ((void *)0))
  return (0);
     xfree(found);
 session_alert_add(s, w, 0x8);
 if (s->flags & 0x1)
  return (0);
  if (options_get_number(&s->options, "visual-content")) {
  for (i = 0; i < ((&clients)->num); i++) {
   c = ((&clients)->list[i]);
   if (c == ((void *)0) || c->session != s)
    continue;
   status_message_set(c, "Content in window %u",
       winlink_find_by_window(&s->windows, w)->idx);
  }
 }
 return (1);
}

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

variable_types:
w
struct window *

variable_types:
wp
struct window_pane *

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

variable_types:
i
unsigned int

variable_types:
found
char *

variable_types:
ptr
char *

return_type: int

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

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 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 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 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 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_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 server_window_check_alive(__int64 a1)
{
int v1; // er13
__int64 v2; // rbp
__int64 v4; // r12
unsigned int i; // er12
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rax

v1 = 1;
v2 = *(_QWORD *)(a1 + 32);
if ( !v2 )
goto LABEL_8;
do
{
while ( 1 )
{
v4 = v2;
v2 = *(_QWORD *)(v2 + 464);
if ( *(_DWORD *)(v4 + 68) == -1 && !options_get_number(a1 + 80, "remain-on-exit") )
break;
v1 = 0;
if ( !v2 )
goto LABEL_7;
}
layout_close_pane(v4);
window_remove_pane(a1, v4);
server_redraw_window(a1);
}
while ( v2 );
LABEL_7:
if ( v1 )
{
LABEL_8:
for ( i = 0; *((_DWORD *)&sessions + 2) > i; ++i )
{
v6 = *(_QWORD *)(sessions + 8LL * i);
if ( v6 && (unsigned int)session_has(*(_QWORD *)(sessions + 8LL * i), a1) )
{
while ( 1 )
{
v7 = winlinks_RB_MINMAX(v6 + 72, 0xFFFFFFFFLL);
v8 = v7;
if ( !v7 )
break;
if ( *(_QWORD *)(v7 + 8) != a1 )
{
do
{
v9 = winlinks_RB_NEXT(v8);
v8 = v9;
if ( !v9 )
goto LABEL_10;
}
while ( *(_QWORD *)(v9 + 8) != a1 );
}
if ( (unsigned int)session_detach(v6, v8) )
{
server_destroy_session_group(v6);
break;
}
server_redraw_session(v6);
server_status_session_group(v6);
}
}
LABEL_10:
;
}
recalculate_sizes();
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
int v1; // er13
__int64 v2; // rbp
__int64 v4; // r12
unsigned int i; // er12
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rax

v1 = 1;
v2 = *(_QWORD *)(a1 + 32);
if ( !v2 )
goto LABEL_8;
do
{
while ( 1 )
{
v4 = v2;
v2 = *(_QWORD *)(v2 + 464);
if ( *(_DWORD *)(v4 + 68) == -1 && !options_get_number(a1 + 80, "remain-on-exit") )
break;
v1 = 0;
if ( !v2 )
goto LABEL_7;
}
layout_close_pane(v4);
window_remove_pane(a1, v4);
server_redraw_window(a1);
}
while ( v2 );
LABEL_7:
if ( v1 )
{
LABEL_8:
for ( i = 0; *((_DWORD *)&sessions + 2) > i; ++i )
{
v6 = *(_QWORD *)(sessions + 8LL * i);
if ( v6 && (unsigned int)session_has(*(_QWORD *)(sessions + 8LL * i), a1) )
{
while ( 1 )
{
v7 = winlinks_RB_MINMAX(v6 + 72, 0xFFFFFFFFLL);
v8 = v7;
if ( !v7 )
break;
if ( *(_QWORD *)(v7 + 8) != a1 )
{
do
{
v9 = winlinks_RB_NEXT(v8);
v8 = v9;
if ( !v9 )
goto LABEL_10;
}
while ( *(_QWORD *)(v9 + 8) != a1 );
}
if ( (unsigned int)session_detach(v6, v8) )
{
server_destroy_session_group(v6);
break;
}
server_redraw_session(v6);
server_status_session_group(v6);
}
}
LABEL_10:
;
}
recalculate_sizes();
}
}

original_code:
void
server_window_check_alive(struct window *w)
{
 struct window_pane *wp, *wq;
 struct options *oo = &w->options;
 struct session *s;
 struct winlink *wl;
 u_int i;
 int destroyed;
 destroyed = 1;
 wp = ((&w->panes)->tqh_first);
 while (wp != ((void *)0)) {
  wq = ((wp)->entry.tqe_next);
  if (wp->fd == -1 && !options_get_number(oo, "remain-on-exit")) {
   layout_close_pane(wp);
   window_remove_pane(w, wp);
   server_redraw_window(w);
  } else
   destroyed = 0;
  wp = wq;
 }
 if (!destroyed)
  return;
 for (i = 0; i < ((&sessions)->num); i++) {
  s = ((&sessions)->list[i]);
  if (s == ((void *)0))
   continue;
  if (!session_has(s, w))
   continue;
 restart:
  for ((wl) = winlinks_RB_MINMAX(&s->windows, -1); (wl) != ((void *)0); (wl) = winlinks_RB_NEXT(wl)) {
   if (wl->window != w)
    continue;
   if (session_detach(s, wl)) {
    server_destroy_session_group(s);
    break;
   }
   server_redraw_session(s);
   server_status_session_group(s);
   goto restart;
  }
 }
 recalculate_sizes();
}

canonical_original_code:
void server_window_check_alive(struct window *w)
{
 struct window_pane *wp; struct window_pane *wq;
 struct options *oo = &w->options;
 struct session *s;
 struct winlink *wl;
 unsigned int i;
 int destroyed;
 destroyed = 1;
 wp = ((&w->panes)->tqh_first);
 while (wp != ((void *)0)) {
  wq = ((wp)->entry.tqe_next);
  if (wp->fd == -1 && !options_get_number(oo, "remain-on-exit")) {
   layout_close_pane(wp);
   window_remove_pane(w, wp);
   server_redraw_window(w);
  } else
   destroyed = 0;
  wp = wq;
 }
 if (!destroyed)
  return;
 for (i = 0; i < ((&sessions)->num); i++) {
  s = ((&sessions)->list[i]);
  if (s == ((void *)0))
   continue;
  if (!session_has(s, w))
   continue;
 restart:
  for ((wl) = winlinks_RB_MINMAX(&s->windows, -1); (wl) != ((void *)0); (wl) = winlinks_RB_NEXT(wl)) {
   if (wl->window != w)
    continue;
   if (session_detach(s, wl)) {
    server_destroy_session_group(s);
    break;
   }
   server_redraw_session(s);
   server_status_session_group(s);
   goto restart;
  }
 }
 recalculate_sizes();
}

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

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

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

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

variable_types: destroyed int

return_type: void

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

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

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

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

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


decompiled_code:
__int64 server_window_loop()
{
unsigned int v0; // er13
__int64 v1; // r14
unsigned int v2; // er12
__int64 v3; // rbp
__int64 v4; // rbx

if ( *((_DWORD *)&windows + 2) )
{
v0 = 0;
do
{
v1 = *(_QWORD *)(windows + 8LL * v0);
if ( v1 )
{
if ( *((_DWORD *)&sessions + 2) )
{
v2 = 0;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(sessions + 8LL * v2);
if ( v3 && (unsigned int)session_has(*(_QWORD *)(sessions + 8LL * v2), v1) )
{
if ( (unsigned int)server_window_check_bell(v3, v1)
|| (unsigned int)server_window_check_activity(v3, v1) )
{
server_status_session(v3);
}
v4 = *(_QWORD *)(v1 + 32);
if ( v4 )
break;
}
if ( *((_DWORD *)&sessions + 2) <= ++v2 )
goto LABEL_15;
}
do
{
server_window_check_content(v3, v1, v4);
v4 = *(_QWORD *)(v4 + 464);
}
while ( v4 );
++v2;
}
while ( *((_DWORD *)&sessions + 2) > v2 );
}
LABEL_15:
*(_DWORD *)(v1 + 72) &= 0xFFFFFFF2;
server_window_check_alive(v1);
}
++v0;
}
while ( *((_DWORD *)&windows + 2) > v0 );
}
return set_window_names();
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er13
__int64 v1; // r14
unsigned int v2; // er12
__int64 v3; // rbp
__int64 v4; // rbx

if ( *((_DWORD *)&windows + 2) )
{
v0 = 0;
do
{
v1 = *(_QWORD *)(windows + 8LL * v0);
if ( v1 )
{
if ( *((_DWORD *)&sessions + 2) )
{
v2 = 0;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(sessions + 8LL * v2);
if ( v3 && (unsigned int)session_has(*(_QWORD *)(sessions + 8LL * v2), v1) )
{
if ( (unsigned int)func3(v3, v1)
|| (unsigned int)func4(v3, v1) )
{
server_status_session(v3);
}
v4 = *(_QWORD *)(v1 + 32);
if ( v4 )
break;
}
if ( *((_DWORD *)&sessions + 2) <= ++v2 )
goto LABEL_15;
}
do
{
func5(v3, v1, v4);
v4 = *(_QWORD *)(v4 + 464);
}
while ( v4 );
++v2;
}
while ( *((_DWORD *)&sessions + 2) > v2 );
}
LABEL_15:
*(_DWORD *)(v1 + 72) &= 0xFFFFFFF2;
func6(v1);
}
++v0;
}
while ( *((_DWORD *)&windows + 2) > v0 );
}
return set_window_names();
}

original_code:
void
server_window_loop(void)
{
 struct window *w;
 struct window_pane *wp;
 struct session *s;
 u_int i, j;
 for (i = 0; i < ((&windows)->num); i++) {
  w = ((&windows)->list[i]);
  if (w == ((void *)0))
   continue;
  for (j = 0; j < ((&sessions)->num); j++) {
   s = ((&sessions)->list[j]);
   if (s == ((void *)0) || !session_has(s, w))
    continue;
   if (server_window_check_bell(s, w) ||
       server_window_check_activity(s, w))
    server_status_session(s);
   for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next))
    server_window_check_content(s, w, wp);
  }
  w->flags &= ~(0x1|0x4|0x8);
  server_window_check_alive(w);
 }
 set_window_names();
}

canonical_original_code:
void server_window_loop()
{
 struct window *w;
 struct window_pane *wp;
 struct session *s;
 unsigned int i; unsigned int j;
 for (i = 0; i < ((&windows)->num); i++) {
  w = ((&windows)->list[i]);
  if (w == ((void *)0))
   continue;
  for (j = 0; j < ((&sessions)->num); j++) {
   s = ((&sessions)->list[j]);
   if (s == ((void *)0) || !session_has(s, w))
    continue;
   if (server_window_check_bell(s, w) ||
       server_window_check_activity(s, w))
    server_status_session(s);
   for((wp) = ((&w->panes)->tqh_first); (wp) != ((void *)0); (wp) = ((wp)->entry.tqe_next))
    server_window_check_content(s, w, wp);
  }
  w->flags &= ~(0x1|0x4|0x8);
  server_window_check_alive(w);
 }
 set_window_names();
}

variable_types:
j
unsigned int

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

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

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

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

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

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 session_alert { struct winlink *wl; int type; struct { struct session_alert *sle_next; } entry; }

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

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

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

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

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

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

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

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

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

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

user_defined_types: struct environ { struct environ_entry *rbh_root; }

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

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

user_defined_types: struct 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 environ_entry { char *name; char *value; struct { struct environ_entry *rbe_left; struct environ_entry *rbe_right; struct environ_entry *rbe_parent; int rbe_color; } entry; }

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

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

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

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

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

user_defined_types: struct 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: enum tty_code_type { TTYCODE_NONE=0, TTYCODE_STRING=1, TTYCODE_NUMBER=2, TTYCODE_FLAG=3 }

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


decompiled_code:
__pid_t __fastcall imsg_init(__int64 a1, int a2)
{
__pid_t result; // eax

msgbuf_init(a1 + 65568);
bzero((void *)(a1 + 16), 0x10010uLL);
*(_DWORD *)(a1 + 65592) = a2;
*(_DWORD *)(a1 + 65588) = a2;
result = getpid();
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 65596) = result;
*(_QWORD *)(a1 + 8) = a1;
return result;
}

original_code:
void
imsg_init(struct imsgbuf *ibuf, int fd)
{
 msgbuf_init(&ibuf->w);
 bzero(&ibuf->r, sizeof(ibuf->r));
 ibuf->fd = fd;
 ibuf->w.fd = fd;
 ibuf->pid = getpid();
 do { (&ibuf->fds)->tqh_first = ((void *)0); (&ibuf->fds)->tqh_last = &(&ibuf->fds)->tqh_first; } while (0);
}

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

variable_types: fd int


decompiled_code:
void __fastcall imsg_free(__int64 a1)
{
free(*(void **)(a1 + 24));
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
free(*(void **)(a1 + 24));
}

original_code:
void
imsg_free(struct imsg *imsg)
{
 free(imsg->data);
}

variable_types: struct imsg { struct imsg_hdr { unsigned int type; unsigned int len; unsigned int flags; unsigned int peerid; unsigned int pid; } hdr; int fd; void *data; } *

user_defined_types: struct imsg { struct imsg_hdr hdr; int fd; void *data; }


decompiled_code:
__int64 __fastcall imsg_get_fd(__int64 a1)
{
_DWORD *v2; // rdi
__int64 v3; // rdx
unsigned int v4; // er12
_QWORD *v5; // rcx

v2 = *(_DWORD **)a1;
if ( !v2 )
return (unsigned int)-1;
v3 = *(_QWORD *)v2;
v4 = v2[4];
v5 = (_QWORD *)*((_QWORD *)v2 + 1);
if ( *(_QWORD *)v2 )
*(_QWORD *)(v3 + 8) = v5;
else
*(_QWORD *)(a1 + 8) = v5;
*v5 = v3;
free(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
_DWORD *v2; // rdi
__int64 v3; // rdx
unsigned int v4; // er12
_QWORD *v5; // rcx

v2 = *(_DWORD **)a1;
if ( !v2 )
return (unsigned int)-1;
v3 = *(_QWORD *)v2;
v4 = v2[4];
v5 = (_QWORD *)*((_QWORD *)v2 + 1);
if ( *(_QWORD *)v2 )
*(_QWORD *)(v3 + 8) = v5;
else
*(_QWORD *)(a1 + 8) = v5;
*v5 = v3;
free(v2);
return v4;
}

original_code:
int
imsg_get_fd(struct imsgbuf *ibuf)
{
 int fd;
 struct imsg_fd *ifd;
 if ((ifd = ((&ibuf->fds)->tqh_first)) == ((void *)0))
  return (-1);
 fd = ifd->fd;
 do { if (((ifd)->entry.tqe_next) != ((void *)0)) (ifd)->entry.tqe_next->entry.tqe_prev = (ifd)->entry.tqe_prev; else (&ibuf->fds)->tqh_last = (ifd)->entry.tqe_prev; *(ifd)->entry.tqe_prev = (ifd)->entry.tqe_next; ; ; } while (0);
 free(ifd);
 return (fd);
}

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

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


decompiled_code:
__int64 __fastcall imsg_flush(__int64 a1)
{
do
{
if ( !*(_DWORD *)(a1 + 65584) )
return 0LL;
}
while ( (int)msgbuf_write(a1 + 65568) >= 0 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
do
{
if ( !*(_DWORD *)(a1 + 65584) )
return 0LL;
}
while ( (int)msgbuf_write(a1 + 65568) >= 0 );
return 0xFFFFFFFFLL;
}

original_code:
int
imsg_flush(struct imsgbuf *ibuf)
{
 while (ibuf->w.queued)
  if (msgbuf_write(&ibuf->w) < 0)
   return (-1);
 return (0);
}


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

msgbuf_clear(a1 + 65568);
while ( 1 )
{
result = imsg_get_fd(a1);
if ( (_DWORD)result == -1 )
break;
close(result);
}
return result;
}

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

msgbuf_clear(a1 + 65568);
while ( 1 )
{
result = func8(a1);
if ( (_DWORD)result == -1 )
break;
close(result);
}
return result;
}

original_code:
void
imsg_clear(struct imsgbuf *ibuf)
{
 int fd;
 msgbuf_clear(&ibuf->w);
 while ((fd = imsg_get_fd(ibuf)) != -1)
  close(fd);
}


original_code: void options_tree_SPLAY_MINMAX(struct options_tree *head, int __comp) { struct options_entry __node, *__left, *__right, *__tmp; (&__node)->entry.spe_left = (&__node)->entry.spe_right = ((void *)0); __left = __right = &__node; while (1) { if (__comp < 0) { __tmp = ((head)->sph_root)->entry.spe_left; if (__tmp == ((void *)0)) break; if (__comp < 0){ do { ((head)->sph_root)->entry.spe_left = (__tmp)->entry.spe_right; (__tmp)->entry.spe_right = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_left == ((void *)0)) break; } do { (__right)->entry.spe_left = (head)->sph_root; __right = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_left; } while (0); } else if (__comp > 0) { __tmp = ((head)->sph_root)->entry.spe_right; if (__tmp == ((void *)0)) break; if (__comp > 0) { do { ((head)->sph_root)->entry.spe_right = (__tmp)->entry.spe_left; (__tmp)->entry.spe_left = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_right == ((void *)0)) break; } do { (__left)->entry.spe_right = (head)->sph_root; __left = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_right; } while (0); } } do { (__left)->entry.spe_right = ((head)->sph_root)->entry.spe_left; (__right)->entry.spe_left = ((head)->sph_root)->entry.spe_right; ((head)->sph_root)->entry.spe_left = (&__node)->entry.spe_right; ((head)->sph_root)->entry.spe_right = (&__node)->entry.spe_left; } while (0); }

canonical_original_code: void options_tree_SPLAY_MINMAX(struct options_tree *head, int __comp) { struct options_entry __node; struct options_entry *__left; struct options_entry *__right; struct options_entry *__tmp; (&__node)->entry.spe_left = (&__node)->entry.spe_right = ((void *)0); __left = __right = &__node; while (1) { if (__comp < 0) { __tmp = ((head)->sph_root)->entry.spe_left; if (__tmp == ((void *)0)) break; if (__comp < 0){ do { ((head)->sph_root)->entry.spe_left = (__tmp)->entry.spe_right; (__tmp)->entry.spe_right = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_left == ((void *)0)) break; } do { (__right)->entry.spe_left = (head)->sph_root; __right = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_left; } while (0); } else if (__comp > 0) { __tmp = ((head)->sph_root)->entry.spe_right; if (__tmp == ((void *)0)) break; if (__comp > 0) { do { ((head)->sph_root)->entry.spe_right = (__tmp)->entry.spe_left; (__tmp)->entry.spe_left = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_right == ((void *)0)) break; } do { (__left)->entry.spe_right = (head)->sph_root; __left = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_right; } while (0); } } do { (__left)->entry.spe_right = ((head)->sph_root)->entry.spe_left; (__right)->entry.spe_left = ((head)->sph_root)->entry.spe_right; ((head)->sph_root)->entry.spe_left = (&__node)->entry.spe_right; ((head)->sph_root)->entry.spe_right = (&__node)->entry.spe_left; } while (0); }

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

user_defined_types: struct options_tree { struct options_entry *sph_root; }


decompiled_code:
int __fastcall options_cmp(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
int
options_cmp(struct options_entry *o1, struct options_entry *o2)
{
 return (strcmp(o1->name, o2->name));
}

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


original_code: void options_tree_SPLAY(struct options_tree *head, struct options_entry *elm) { struct options_entry __node, *__left, *__right, *__tmp; int __comp; (&__node)->entry.spe_left = (&__node)->entry.spe_right = ((void *)0); __left = __right = &__node; while ((__comp = (options_cmp)(elm, (head)->sph_root))) { if (__comp < 0) { __tmp = ((head)->sph_root)->entry.spe_left; if (__tmp == ((void *)0)) break; if ((options_cmp)(elm, __tmp) < 0){ do { ((head)->sph_root)->entry.spe_left = (__tmp)->entry.spe_right; (__tmp)->entry.spe_right = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_left == ((void *)0)) break; } do { (__right)->entry.spe_left = (head)->sph_root; __right = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_left; } while (0); } else if (__comp > 0) { __tmp = ((head)->sph_root)->entry.spe_right; if (__tmp == ((void *)0)) break; if ((options_cmp)(elm, __tmp) > 0){ do { ((head)->sph_root)->entry.spe_right = (__tmp)->entry.spe_left; (__tmp)->entry.spe_left = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_right == ((void *)0)) break; } do { (__left)->entry.spe_right = (head)->sph_root; __left = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_right; } while (0); } } do { (__left)->entry.spe_right = ((head)->sph_root)->entry.spe_left; (__right)->entry.spe_left = ((head)->sph_root)->entry.spe_right; ((head)->sph_root)->entry.spe_left = (&__node)->entry.spe_right; ((head)->sph_root)->entry.spe_right = (&__node)->entry.spe_left; } while (0); }

canonical_original_code: void options_tree_SPLAY(struct options_tree *head, struct options_entry *elm) { struct options_entry __node; struct options_entry *__left; struct options_entry *__right; struct options_entry *__tmp; int __comp; (&__node)->entry.spe_left = (&__node)->entry.spe_right = ((void *)0); __left = __right = &__node; while ((__comp = (options_cmp)(elm, (head)->sph_root))) { if (__comp < 0) { __tmp = ((head)->sph_root)->entry.spe_left; if (__tmp == ((void *)0)) break; if ((options_cmp)(elm, __tmp) < 0){ do { ((head)->sph_root)->entry.spe_left = (__tmp)->entry.spe_right; (__tmp)->entry.spe_right = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_left == ((void *)0)) break; } do { (__right)->entry.spe_left = (head)->sph_root; __right = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_left; } while (0); } else if (__comp > 0) { __tmp = ((head)->sph_root)->entry.spe_right; if (__tmp == ((void *)0)) break; if ((options_cmp)(elm, __tmp) > 0){ do { ((head)->sph_root)->entry.spe_right = (__tmp)->entry.spe_left; (__tmp)->entry.spe_left = (head)->sph_root; (head)->sph_root = __tmp; } while (0); if (((head)->sph_root)->entry.spe_right == ((void *)0)) break; } do { (__left)->entry.spe_right = (head)->sph_root; __left = (head)->sph_root; (head)->sph_root = ((head)->sph_root)->entry.spe_right; } while (0); } } do { (__left)->entry.spe_right = ((head)->sph_root)->entry.spe_left; (__right)->entry.spe_left = ((head)->sph_root)->entry.spe_right; ((head)->sph_root)->entry.spe_left = (&__node)->entry.spe_right; ((head)->sph_root)->entry.spe_right = (&__node)->entry.spe_left; } while (0); }

variable_types:
elm
struct options_entry *

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


original_code: struct options_entry * options_tree_SPLAY_INSERT(struct options_tree *head, struct options_entry *elm) { if (((head)->sph_root == ((void *)0))) { (elm)->entry.spe_left = (elm)->entry.spe_right = ((void *)0); } else { int __comp; options_tree_SPLAY(head, elm); __comp = (options_cmp)(elm, (head)->sph_root); if(__comp < 0) { (elm)->entry.spe_left = ((head)->sph_root)->entry.spe_left; (elm)->entry.spe_right = (head)->sph_root; ((head)->sph_root)->entry.spe_left = ((void *)0); } else if (__comp > 0) { (elm)->entry.spe_right = ((head)->sph_root)->entry.spe_right; (elm)->entry.spe_left = (head)->sph_root; ((head)->sph_root)->entry.spe_right = ((void *)0); } else return ((head)->sph_root); } (head)->sph_root = (elm); return (((void *)0)); }

canonical_original_code: struct options_entry *options_tree_SPLAY_INSERT(struct options_tree *head, struct options_entry *elm) { if (((head)->sph_root == ((void *)0))) { (elm)->entry.spe_left = (elm)->entry.spe_right = ((void *)0); } else { int __comp; options_tree_SPLAY(head, elm); __comp = (options_cmp)(elm, (head)->sph_root); if(__comp < 0) { (elm)->entry.spe_left = ((head)->sph_root)->entry.spe_left; (elm)->entry.spe_right = (head)->sph_root; ((head)->sph_root)->entry.spe_left = ((void *)0); } else if (__comp > 0) { (elm)->entry.spe_right = ((head)->sph_root)->entry.spe_right; (elm)->entry.spe_left = (head)->sph_root; ((head)->sph_root)->entry.spe_right = ((void *)0); } else return ((head)->sph_root); } (head)->sph_root = (elm); return (((void *)0)); }

variable_types: struct options_tree { struct options_entry *sph_root; } *

return_type: struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_KEY=2 } type; union { char *string; long long number; int key; } value; struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; } *


decompiled_code:
const char **__fastcall options_tree_SPLAY_REMOVE(__int64 *a1, const char **a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r12

if ( !*a1 )
return 0LL;
options_tree_SPLAY(a1, a2);
v2 = *a1;
if ( options_cmp(a2, (const char **)*a1) )
return 0LL;
v3 = *(_QWORD *)(v2 + 48);
v4 = *(_QWORD *)(v2 + 56);
if ( v3 )
{
*a1 = v3;
options_tree_SPLAY(a1, a2);
*(_QWORD *)(*a1 + 56) = v4;
}
else
{
*a1 = v4;
}
return a2;
}

original_code: struct options_entry * options_tree_SPLAY_REMOVE(struct options_tree *head, struct options_entry *elm) { struct options_entry *__tmp; if (((head)->sph_root == ((void *)0))) return (((void *)0)); options_tree_SPLAY(head, elm); if ((options_cmp)(elm, (head)->sph_root) == 0) { if (((head)->sph_root)->entry.spe_left == ((void *)0)) { (head)->sph_root = ((head)->sph_root)->entry.spe_right; } else { __tmp = ((head)->sph_root)->entry.spe_right; (head)->sph_root = ((head)->sph_root)->entry.spe_left; options_tree_SPLAY(head, elm); ((head)->sph_root)->entry.spe_right = __tmp; } return (elm); } return (((void *)0)); }

canonical_original_code: struct options_entry *options_tree_SPLAY_REMOVE(struct options_tree *head, struct options_entry *elm) { struct options_entry *__tmp; if (((head)->sph_root == ((void *)0))) return (((void *)0)); options_tree_SPLAY(head, elm); if ((options_cmp)(elm, (head)->sph_root) == 0) { if (((head)->sph_root)->entry.spe_left == ((void *)0)) { (head)->sph_root = ((head)->sph_root)->entry.spe_right; } else { __tmp = ((head)->sph_root)->entry.spe_right; (head)->sph_root = ((head)->sph_root)->entry.spe_left; options_tree_SPLAY(head, elm); ((head)->sph_root)->entry.spe_right = __tmp; } return (elm); } return (((void *)0)); }

user_defined_types: struct options_entry { char *name; enum { OPTIONS_STRING=0, OPTIONS_NUMBER=1, OPTIONS_KEY=2 } type; union { char *string; long long number; int key; } value; struct { struct options_entry *spe_left; struct options_entry *spe_right; } entry; }


decompiled_code:
__int64 __fastcall options_tree_SPLAY_FIND(__int64 *a1, const char **a2)
{
__int64 v2; // r12
__int64 result; // rax

if ( !*a1 || (options_tree_SPLAY(a1, a2), v2 = *a1, options_cmp(a2, (const char **)*a1)) )
result = 0LL;
else
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, const char **a2)
{
__int64 v2; // r12
__int64 result; // rax

if ( !*a1 || (func2(a1, a2), v2 = *a1, func1(a2, (const char **)*a1)) )
result = 0LL;
else
result = v2;
return result;
}

original_code: static __inline struct options_entry * options_tree_SPLAY_FIND(struct options_tree *head, struct options_entry *elm) { if (((head)->sph_root == ((void *)0))) return(((void *)0)); options_tree_SPLAY(head, elm); if ((options_cmp)(elm, (head)->sph_root) == 0) return (head->sph_root); return (((void *)0)); }

canonical_original_code: static __inline struct options_entry *options_tree_SPLAY_FIND(struct options_tree *head, struct options_entry *elm) { if (((head)->sph_root == ((void *)0))) return(((void *)0)); options_tree_SPLAY(head, elm); if ((options_cmp)(elm, (head)->sph_root) == 0) return (head->sph_root); return (((void *)0)); }

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


decompiled_code:
__int64 options_set_string(__int64 *a1, const char *a2, __int64 a3, ...)
{
__int64 v4; // rax
__int64 v5; // r12
int v6; // eax
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

v4 = options_find1(a1, a2);
v5 = v4;
if ( v4 )
{
v6 = *(_DWORD *)(v4 + 8);
if ( v6 )
{
if ( v6 == 2 )
(*(void (__fastcall **)(_QWORD))(v5 + 40))(*(_QWORD *)(v5 + 32));
}
else
{
xfree(*(_QWORD *)(v5 + 16));
}
}
else
{
v5 = xmalloc(64LL);
*(_QWORD *)v5 = xstrdup(a2);
options_tree_SPLAY_INSERT(a1, v5);
}
va_start(va, a3);
*(_DWORD *)(v5 + 8) = 0;
xvasprintf(v5 + 16, a3, va);
return v5;
}

original_code:
void __attribute__ ((format (printf, 3, 4)))
options_set_string(struct options *oo, const char *name, const char *fmt, ...)
{
 struct options_entry *o;
 va_list ap;
 if ((o = options_find1(oo, name)) == ((void *)0)) {
  o = xmalloc(sizeof *o);
  o->name = xstrdup(name);
  options_tree_SPLAY_INSERT(&oo->tree, o);
 } else if (o->type == OPTIONS_STRING)
  xfree(o->value.string);
 __builtin_va_start(ap,fmt);
 o->type = OPTIONS_STRING;
 xvasprintf(&o->value.string, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void options_set_string(struct options *oo, char *name, char *fmt, ...)
{
 struct options_entry *o;
 __builtin_va_list ap;
 if ((o = options_find1(oo, name)) == ((void *)0)) {
  o = xmalloc(sizeof *o);
  o->name = xstrdup(name);
  options_tree_SPLAY_INSERT(&oo->tree, o);
 } else if (o->type == OPTIONS_STRING)
  xfree(o->value.string);
 __builtin_va_start(ap,fmt);
 o->type = OPTIONS_STRING;
 xvasprintf(&o->value.string, fmt, ap);
 __builtin_va_end(ap);
}

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

variable_types:
name
char *

variable_types:
fmt
char *

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