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

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

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

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

variable_types:
options
char *

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

variable_types:
idx
int *

variable_types: match int


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
__int64 __fastcall getopt_internal(int a1, __int64 a2, char *a3, const char **a4, int *a5, char a6)
{
int v7; // ebp
int v8; // er13
unsigned int v9; // ebx
int v11; // er14
char *v12; // rbp
char *v13; // r13
char *v14; // rax
int v15; // ebx
char **v16; // r15
char *v17; // rbp
int v18; // ebp
int v19; // er15
int v20; // ebp
int v21; // er8
int v22; // eax
int v23; // eax
char v24; // dl
char *s; // [rsp+0h] [rbp-58h]
char v26; // [rsp+Fh] [rbp-49h]

s = a3;
if ( !a3 )
return (unsigned int)-1;
if ( posixly_correct_0 == -1 )
posixly_correct_0 = getenv("POSIXLY_CORRECT") != 0LL;
if ( posixly_correct_0 )
{
a6 &= 0xFEu;
if ( ((*s - 43) & 0xFD) != 0 )
goto LABEL_10;
}
else if ( *s == 43 )
{
a6 &= 0xFEu;
}
else
{
if ( *s != 45 )
goto LABEL_10;
a6 |= 2u;
}
++s;
LABEL_10:
if ( !optind )
{
optreset = 1;
optind = 1;
}
optarg = 0LL;
if ( optreset )
{
nonopt_end = -1;
nonopt_start = -1;
}
while ( 1 )
{
if ( !optreset && *place )
goto LABEL_76;
optreset = 0;
v15 = optind;
if ( optind >= a1 )
{
place = (char *)&unk_904;
v7 = nonopt_end;
if ( nonopt_end == -1 )
{
if ( nonopt_start != -1 )
optind = nonopt_start;
}
else
{
v8 = nonopt_start;
permute_args(nonopt_start, nonopt_end, optind, a2);
optind -= v7 - v8;
}
nonopt_end = -1;
nonopt_start = -1;
return (unsigned int)-1;
}
v16 = (char **)(a2 + 8LL * optind);
v17 = *v16;
place = v17;
if ( *v17 == 45 )
{
v26 = v17[1];
if ( v26 )
{
v11 = nonopt_start;
if ( nonopt_start != -1 && nonopt_end == -1 )
{
LABEL_25:
nonopt_end = v15;
goto LABEL_26;
}
goto LABEL_75;
}
if ( strchr(s, 45) )
break;
}
place = (char *)&unk_904;
if ( (a6 & 2) != 0 )
{
optind = v15 + 1;
optarg = (__int64)*v16;
return 1;
}
if ( (a6 & 1) == 0 )
return (unsigned int)-1;
v18 = nonopt_start;
if ( nonopt_start == -1 )
{
nonopt_start = v15;
}
else
{
v19 = nonopt_end;
if ( nonopt_end != -1 )
{
permute_args(nonopt_start, nonopt_end, v15, a2);
nonopt_start = optind + v18 - v19;
nonopt_end = -1;
}
}
++optind;
}
v11 = nonopt_start;
if ( nonopt_start == -1 )
goto LABEL_27;
if ( nonopt_end == -1 )
goto LABEL_25;
LABEL_26:
if ( !v26 )
goto LABEL_27;
LABEL_75:
place = v17 + 1;
if ( v26 == 45 && !v17[2] )
{
optind = v15 + 1;
place = (char *)&unk_904;
v20 = nonopt_end;
if ( nonopt_end != -1 )
{
permute_args(v11, nonopt_end, v15 + 1, a2);
optind -= v20 - v11;
}
nonopt_end = -1;
nonopt_start = -1;
return (unsigned int)-1;
}
LABEL_76:
if ( a4 && *(char **)(a2 + 8LL * optind) != place )
{
v24 = *place;
if ( *place == 45 )
{
++place;
v21 = 0;
}
else
{
if ( (a6 & 4) == 0 )
goto LABEL_27;
v21 = 0;
if ( v24 != 58 )
v21 = strchr(s, v24) != 0LL;
}
v9 = parse_long_options(a2, s, a4, a5, v21);
if ( v9 != -1 )
{
place = (char *)&unk_904;
return v9;
}
}
LABEL_27:
v12 = place;
v13 = ++place;
v9 = *v12;
if ( v9 == 58 )
goto LABEL_87;
if ( v9 == 45 )
{
if ( !v12[1] )
{
v14 = strchr(s, 45);
if ( !v14 )
return (unsigned int)-1;
goto LABEL_33;
}
LABEL_58:
optopt = v9;
return 63;
}
v14 = strchr(s, v9);
if ( !v14 )
{
LABEL_87:
if ( !v12[1] )
++optind;
goto LABEL_58;
}
if ( a4 && v9 == 87 && v14[1] == 59 )
{
if ( !v12[1] )
{
v22 = optind + 1;
optind = v22;
if ( v22 >= a1 )
{
place = (char *)&unk_904;
optopt = 87;
return 5 * (unsigned int)(*s != 58) + 58;
}
place = *(char **)(a2 + 8LL * v22);
}
v9 = parse_long_options(a2, s, a4, a5, 0);
place = (char *)&unk_904;
return v9;
}
LABEL_33:
if ( v14[1] == 58 )
{
optarg = 0LL;
if ( v12[1] )
{
optarg = (__int64)v13;
}
else if ( v14[2] != 58 )
{
v23 = optind + 1;
optind = v23;
if ( v23 >= a1 )
{
place = (char *)&unk_904;
optopt = v9;
return 5 * (unsigned int)(*s != 58) + 58;
}
optarg = *(_QWORD *)(a2 + 8LL * v23);
}
place = (char *)&unk_904;
++optind;
}
else if ( !v12[1] )
{
++optind;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2, char *a3, const char **a4, int *a5, char a6)
{
int v7; // ebp
int v8; // er13
unsigned int v9; // ebx
int v11; // er14
char *v12; // rbp
char *v13; // r13
char *v14; // rax
int v15; // ebx
char **v16; // r15
char *v17; // rbp
int v18; // ebp
int v19; // er15
int v20; // ebp
int v21; // er8
int v22; // eax
int v23; // eax
char v24; // dl
char *s; // [rsp+0h] [rbp-58h]
char v26; // [rsp+Fh] [rbp-49h]

s = a3;
if ( !a3 )
return (unsigned int)-1;
if ( posixly_correct_0 == -1 )
posixly_correct_0 = getenv("POSIXLY_CORRECT") != 0LL;
if ( posixly_correct_0 )
{
a6 &= 0xFEu;
if ( ((*s - 43) & 0xFD) != 0 )
goto LABEL_10;
}
else if ( *s == 43 )
{
a6 &= 0xFEu;
}
else
{
if ( *s != 45 )
goto LABEL_10;
a6 |= 2u;
}
++s;
LABEL_10:
if ( !optind )
{
optreset = 1;
optind = 1;
}
optarg = 0LL;
if ( optreset )
{
nonopt_end = -1;
nonopt_start = -1;
}
while ( 1 )
{
if ( !optreset && *place )
goto LABEL_76;
optreset = 0;
v15 = optind;
if ( optind >= a1 )
{
place = (char *)&unk_904;
v7 = nonopt_end;
if ( nonopt_end == -1 )
{
if ( nonopt_start != -1 )
optind = nonopt_start;
}
else
{
v8 = nonopt_start;
func1(nonopt_start, nonopt_end, optind, a2);
optind -= v7 - v8;
}
nonopt_end = -1;
nonopt_start = -1;
return (unsigned int)-1;
}
v16 = (char **)(a2 + 8LL * optind);
v17 = *v16;
place = v17;
if ( *v17 == 45 )
{
v26 = v17[1];
if ( v26 )
{
v11 = nonopt_start;
if ( nonopt_start != -1 && nonopt_end == -1 )
{
LABEL_25:
nonopt_end = v15;
goto LABEL_26;
}
goto LABEL_75;
}
if ( strchr(s, 45) )
break;
}
place = (char *)&unk_904;
if ( (a6 & 2) != 0 )
{
optind = v15 + 1;
optarg = (__int64)*v16;
return 1;
}
if ( (a6 & 1) == 0 )
return (unsigned int)-1;
v18 = nonopt_start;
if ( nonopt_start == -1 )
{
nonopt_start = v15;
}
else
{
v19 = nonopt_end;
if ( nonopt_end != -1 )
{
func1(nonopt_start, nonopt_end, v15, a2);
nonopt_start = optind + v18 - v19;
nonopt_end = -1;
}
}
++optind;
}
v11 = nonopt_start;
if ( nonopt_start == -1 )
goto LABEL_27;
if ( nonopt_end == -1 )
goto LABEL_25;
LABEL_26:
if ( !v26 )
goto LABEL_27;
LABEL_75:
place = v17 + 1;
if ( v26 == 45 && !v17[2] )
{
optind = v15 + 1;
place = (char *)&unk_904;
v20 = nonopt_end;
if ( nonopt_end != -1 )
{
func1(v11, nonopt_end, v15 + 1, a2);
optind -= v20 - v11;
}
nonopt_end = -1;
nonopt_start = -1;
return (unsigned int)-1;
}
LABEL_76:
if ( a4 && *(char **)(a2 + 8LL * optind) != place )
{
v24 = *place;
if ( *place == 45 )
{
++place;
v21 = 0;
}
else
{
if ( (a6 & 4) == 0 )
goto LABEL_27;
v21 = 0;
if ( v24 != 58 )
v21 = strchr(s, v24) != 0LL;
}
v9 = func2(a2, s, a4, a5, v21);
if ( v9 != -1 )
{
place = (char *)&unk_904;
return v9;
}
}
LABEL_27:
v12 = place;
v13 = ++place;
v9 = *v12;
if ( v9 == 58 )
goto LABEL_87;
if ( v9 == 45 )
{
if ( !v12[1] )
{
v14 = strchr(s, 45);
if ( !v14 )
return (unsigned int)-1;
goto LABEL_33;
}
LABEL_58:
optopt = v9;
return 63;
}
v14 = strchr(s, v9);
if ( !v14 )
{
LABEL_87:
if ( !v12[1] )
++optind;
goto LABEL_58;
}
if ( a4 && v9 == 87 && v14[1] == 59 )
{
if ( !v12[1] )
{
v22 = optind + 1;
optind = v22;
if ( v22 >= a1 )
{
place = (char *)&unk_904;
optopt = 87;
return 5 * (unsigned int)(*s != 58) + 58;
}
place = *(char **)(a2 + 8LL * v22);
}
v9 = func2(a2, s, a4, a5, 0);
place = (char *)&unk_904;
return v9;
}
LABEL_33:
if ( v14[1] == 58 )
{
optarg = 0LL;
if ( v12[1] )
{
optarg = (__int64)v13;
}
else if ( v14[2] != 58 )
{
v23 = optind + 1;
optind = v23;
if ( v23 >= a1 )
{
place = (char *)&unk_904;
optopt = v9;
return 5 * (unsigned int)(*s != 58) + 58;
}
optarg = *(_QWORD *)(a2 + 8LL * v23);
}
place = (char *)&unk_904;
++optind;
}
else if ( !v12[1] )
{
++optind;
}
return v9;
}

original_code:
static int
getopt_internal(int nargc, char * const *nargv, const char *options,
 const struct option *long_options, int *idx, int flags)
{
 char *oli;
 int optchar, short_too;
 static int posixly_correct = -1;
 if (options == ((void *)0))
  return (-1);
 if (posixly_correct == -1)
  posixly_correct = (getenv("POSIXLY_CORRECT") != ((void *)0));
 if (posixly_correct || *options == '+')
  flags &= ~0x01;
 else if (*options == '-')
  flags |= 0x02;
 if (*options == '+' || *options == '-')
  options++;
 if (optind == 0)
  optind = optreset = 1;
 optarg = ((void *)0);
 if (optreset)
  nonopt_start = nonopt_end = -1;
start:
 if (optreset || !*place) {
  optreset = 0;
  if (optind >= nargc) {
   place = "";
   if (nonopt_end != -1) {
    permute_args(nonopt_start, nonopt_end,
        optind, nargv);
    optind -= nonopt_end - nonopt_start;
   }
   else if (nonopt_start != -1) {
    optind = nonopt_start;
   }
   nonopt_start = nonopt_end = -1;
   return (-1);
  }
  if (*(place = nargv[optind]) != '-' ||
      (place[1] == '\0' && strchr(options, '-') == ((void *)0))) {
   place = "";
   if (flags & 0x02) {
    optarg = nargv[optind++];
    return ((int)1);
   }
   if (!(flags & 0x01)) {
    return (-1);
   }
   if (nonopt_start == -1)
    nonopt_start = optind;
   else if (nonopt_end != -1) {
    permute_args(nonopt_start, nonopt_end,
        optind, nargv);
    nonopt_start = optind -
        (nonopt_end - nonopt_start);
    nonopt_end = -1;
   }
   optind++;
   goto start;
  }
  if (nonopt_start != -1 && nonopt_end == -1)
   nonopt_end = optind;
  if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
   optind++;
   place = "";
   if (nonopt_end != -1) {
    permute_args(nonopt_start, nonopt_end,
        optind, nargv);
    optind -= nonopt_end - nonopt_start;
   }
   nonopt_start = nonopt_end = -1;
   return (-1);
  }
 }
 if (long_options != ((void *)0) && place != nargv[optind] &&
     (*place == '-' || (flags & 0x04))) {
  short_too = 0;
  if (*place == '-')
   place++;
  else if (*place != ':' && strchr(options, *place) != ((void *)0))
   short_too = 1;
  optchar = parse_long_options(nargv, options, long_options,
      idx, short_too);
  if (optchar != -1) {
   place = "";
   return (optchar);
  }
 }
 if ((optchar = (int)*place++) == (int)':' ||
     (optchar == (int)'-' && *place != '\0') ||
     (oli = strchr(options, optchar)) == ((void *)0)) {
  if (optchar == (int)'-' && *place == '\0')
   return (-1);
  if (!*place)
   ++optind;
  if (((opterr) && (*options != ':')))
   warnx(illoptchar, optchar);
  optopt = optchar;
  return ((int)'?');
 }
 if (long_options != ((void *)0) && optchar == 'W' && oli[1] == ';') {
  if (*place)
                ;
  else if (++optind >= nargc) {
   place = "";
   if (((opterr) && (*options != ':')))
    warnx(recargchar, optchar);
   optopt = optchar;
   return (((*options == ':') ? (int)':' : (int)'?'));
  } else
   place = nargv[optind];
  optchar = parse_long_options(nargv, options, long_options,
      idx, 0);
  place = "";
  return (optchar);
 }
 if (*++oli != ':') {
  if (!*place)
   ++optind;
 } else {
  optarg = ((void *)0);
  if (*place)
   optarg = place;
  else if (oli[1] != ':') {
   if (++optind >= nargc) {
    place = "";
    if (((opterr) && (*options != ':')))
     warnx(recargchar, optchar);
    optopt = optchar;
    return (((*options == ':') ? (int)':' : (int)'?'));
   } else
    optarg = nargv[optind];
  }
  place = "";
  ++optind;
 }
 return (optchar);
}

canonical_original_code:
static int getopt_internal(int nargc, char **nargv, char *options, struct option *long_options, int *idx, int flags)
{
 char *oli;
 int optchar; int short_too;
 static int posixly_correct = -1;
 if (options == ((void *)0))
  return (-1);
 if (posixly_correct == -1)
  posixly_correct = (getenv("POSIXLY_CORRECT") != ((void *)0));
 if (posixly_correct || *options == '+')
  flags &= ~0x01;
 else if (*options == '-')
  flags |= 0x02;
 if (*options == '+' || *options == '-')
  options++;
 if (optind == 0)
  optind = optreset = 1;
 optarg = ((void *)0);
 if (optreset)
  nonopt_start = nonopt_end = -1;
start:
 if (optreset || !*place) {
  optreset = 0;
  if (optind >= nargc) {
   place = "";
   if (nonopt_end != -1) {
    permute_args(nonopt_start, nonopt_end,
        optind, nargv);
    optind -= nonopt_end - nonopt_start;
   }
   else if (nonopt_start != -1) {
    optind = nonopt_start;
   }
   nonopt_start = nonopt_end = -1;
   return (-1);
  }
  if (*(place = nargv[optind]) != '-' ||
      (place[1] == '\0' && strchr(options, '-') == ((void *)0))) {
   place = "";
   if (flags & 0x02) {
    optarg = nargv[optind++];
    return ((int)1);
   }
   if (!(flags & 0x01)) {
    return (-1);
   }
   if (nonopt_start == -1)
    nonopt_start = optind;
   else if (nonopt_end != -1) {
    permute_args(nonopt_start, nonopt_end,
        optind, nargv);
    nonopt_start = optind -
        (nonopt_end - nonopt_start);
    nonopt_end = -1;
   }
   optind++;
   goto start;
  }
  if (nonopt_start != -1 && nonopt_end == -1)
   nonopt_end = optind;
  if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
   optind++;
   place = "";
   if (nonopt_end != -1) {
    permute_args(nonopt_start, nonopt_end,
        optind, nargv);
    optind -= nonopt_end - nonopt_start;
   }
   nonopt_start = nonopt_end = -1;
   return (-1);
  }
 }
 if (long_options != ((void *)0) && place != nargv[optind] &&
     (*place == '-' || (flags & 0x04))) {
  short_too = 0;
  if (*place == '-')
   place++;
  else if (*place != ':' && strchr(options, *place) != ((void *)0))
   short_too = 1;
  optchar = parse_long_options(nargv, options, long_options,
      idx, short_too);
  if (optchar != -1) {
   place = "";
   return (optchar);
  }
 }
 if ((optchar = (int)*place++) == (int)':' ||
     (optchar == (int)'-' && *place != '\0') ||
     (oli = strchr(options, optchar)) == ((void *)0)) {
  if (optchar == (int)'-' && *place == '\0')
   return (-1);
  if (!*place)
   ++optind;
  if (((opterr) && (*options != ':')))
   warnx(illoptchar, optchar);
  optopt = optchar;
  return ((int)'?');
 }
 if (long_options != ((void *)0) && optchar == 'W' && oli[1] == ';') {
  if (*place)
                ;
  else if (++optind >= nargc) {
   place = "";
   if (((opterr) && (*options != ':')))
    warnx(recargchar, optchar);
   optopt = optchar;
   return (((*options == ':') ? (int)':' : (int)'?'));
  } else
   place = nargv[optind];
  optchar = parse_long_options(nargv, options, long_options,
      idx, 0);
  place = "";
  return (optchar);
 }
 if (*++oli != ':') {
  if (!*place)
   ++optind;
 } else {
  optarg = ((void *)0);
  if (*place)
   optarg = place;
  else if (oli[1] != ':') {
   if (++optind >= nargc) {
    place = "";
    if (((opterr) && (*options != ':')))
     warnx(recargchar, optchar);
    optopt = optchar;
    return (((*options == ':') ? (int)':' : (int)'?'));
   } else
    optarg = nargv[optind];
  }
  place = "";
  ++optind;
 }
 return (optchar);
}

variable_types: nargc int

variable_types:
nargv
char **

variable_types: flags int

variable_types:
oli
char *

variable_types: optchar int

return_type: int

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


warnx

decompiled_code:
void warnx()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
int
warnx(const char *fmt, ...)
{
}

canonical_original_code:
int warnx(char *fmt, ...)
{
}

variable_types:
fmt
char *


getopt

decompiled_code:
__int64 __fastcall getopt(int a1, __int64 a2, char *a3)
{
return getopt_internal(a1, a2, a3, 0LL, 0LL, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2, char *a3)
{
return func3(a1, a2, a3, 0LL, 0LL, 0);
}

original_code:
int
getopt(int nargc, char * const *nargv, const char *options)
{
 return (getopt_internal(nargc, nargv, options, ((void *)0), ((void *)0), 0));
}

canonical_original_code:
int getopt(int nargc, char **nargv, char *options)
{
 return (getopt_internal(nargc, nargv, options, ((void *)0), ((void *)0), 0));
}


decompiled_code:
__int64 __fastcall getopt_long(int a1, __int64 a2, char *a3, const char **a4, int *a5)
{
return getopt_internal(a1, a2, a3, a4, a5, 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, __int64 a2, char *a3, const char **a4, int *a5)
{
return func3(a1, a2, a3, a4, a5, 1);
}

original_code:
int
getopt_long(int nargc, char * const *nargv, const char *options,
    const struct option *long_options, int *idx)
{
 return (getopt_internal(nargc, nargv, options, long_options, idx,
     0x01));
}

canonical_original_code:
int getopt_long(int nargc, char **nargv, char *options, struct option *long_options, int *idx)
{
 return (getopt_internal(nargc, nargv, options, long_options, idx,
     0x01));
}


decompiled_code:
__int64 __fastcall getopt_long_only(int a1, __int64 a2, char *a3, const char **a4, int *a5)
{
return getopt_internal(a1, a2, a3, a4, a5, 5);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2, char *a3, const char **a4, int *a5)
{
return func3(a1, a2, a3, a4, a5, 5);
}

original_code:
int
getopt_long_only(int nargc, char * const *nargv, const char *options,
    const struct option *long_options, int *idx)
{
 return (getopt_internal(nargc, nargv, options, long_options, idx,
     0x01|0x04));
}

canonical_original_code:
int getopt_long_only(int nargc, char **nargv, char *options, struct option *long_options, int *idx)
{
 return (getopt_internal(nargc, nargv, options, long_options, idx,
     0x01|0x04));
}


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

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

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

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

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

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

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

variable_types:
sx
unsigned int

variable_types:
sy
unsigned int

variable_types: struct window_scroll_mode_data { struct screen { char *title; struct grid { unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; unsigned int *size; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } **data; unsigned int *usize; struct grid_utf8 { unsigned char width; unsigned char data[8]; } **udata; } *grid; unsigned int cx; unsigned int cy; unsigned int old_cx; unsigned int old_cy; unsigned int rupper; unsigned int rlower; unsigned int old_rupper; unsigned int old_rlower; int mode; 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; } screen; struct mode_key_data { int type; int flags; } mdata; unsigned int ox; unsigned int oy; } *

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

variable_types:
i
unsigned int

return_type: void

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

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

user_defined_types: struct window_scroll_mode_data { struct screen screen; struct mode_key_data mdata; unsigned int ox; unsigned int oy; }

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

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

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

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

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

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

user_defined_types: struct options_tree { struct options_entry *sph_root; }

user_defined_types: struct client { int fd; struct buffer *in; struct buffer *out; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; }

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

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct session { char *name; struct timeval tv; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; }

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

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

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


decompiled_code:
__int64 __fastcall window_scroll_write_column(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r13

v4 = *(_QWORD *)(a1 + 400);
screen_write_cursormove(a2, a3, 0LL);
return screen_write_copy(
a2,
a1 + 288,
*(_DWORD *)(v4 + 96) + a3,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 296) + 12LL) - *(_DWORD *)(v4 + 100)),
1LL,
*(unsigned int *)(*(_QWORD *)(v4 + 8) + 8LL));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r13

v4 = *(_QWORD *)(a1 + 400);
screen_write_cursormove(a2, a3, 0LL);
return screen_write_copy(
a2,
a1 + 288,
*(_DWORD *)(v4 + 96) + a3,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 296) + 12LL) - *(_DWORD *)(v4 + 100)),
1LL,
*(unsigned int *)(*(_QWORD *)(v4 + 8) + 8LL));
}

original_code:
void
window_scroll_write_column(
    struct window_pane *wp, struct screen_write_ctx *ctx, u_int px)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 screen_write_cursormove(ctx, px, 0);
 screen_write_copy(ctx, &wp->base, data->ox + px,
     ((&wp->base)->grid->hsize) - data->oy, 1, ((s)->grid->sy));
}

canonical_original_code:
void window_scroll_write_column(struct window_pane *wp, struct screen_write_ctx *ctx, unsigned int px)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 screen_write_cursormove(ctx, px, 0);
 screen_write_copy(ctx, &wp->base, data->ox + px,
     ((&wp->base)->grid->hsize) - data->oy, 1, ((s)->grid->sy));
}

variable_types:
ctx
struct screen_write_ctx *

variable_types:
px
unsigned int

variable_types: struct screen { char *title; struct grid { unsigned int sx; unsigned int sy; unsigned int hsize; unsigned int hlimit; unsigned int *size; struct grid_cell { unsigned char attr; unsigned char flags; unsigned char fg; unsigned char bg; unsigned char data; } **data; unsigned int *usize; struct grid_utf8 { unsigned char width; unsigned char data[8]; } **udata; } *grid; unsigned int cx; unsigned int cy; unsigned int old_cx; unsigned int old_cy; unsigned int rupper; unsigned int rlower; unsigned int old_rupper; unsigned int old_rlower; int mode; 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; } *

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

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

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

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

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

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

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

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

user_defined_types: struct winlink_stack { struct winlink *slh_first; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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

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

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

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

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


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

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

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

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

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

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

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

user_defined_types: struct window_scroll_mode_data { struct screen screen; struct mode_key_data mdata; unsigned int ox; unsigned int oy; }

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

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

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

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

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

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

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

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

user_defined_types: struct options_tree { struct options_entry *sph_root; }

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

user_defined_types: struct client { int fd; struct buffer *in; struct buffer *out; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; }

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

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct session { char *name; struct timeval tv; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; }

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

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


decompiled_code:
__int64 __fastcall window_scroll_scroll_up(_QWORD *a1)
{
__int64 v1; // rdx
__int64 result; // rax
_BYTE v3[24]; // [rsp-18h] [rbp-18h] BYREF

v1 = a1[50];
result = *(unsigned int *)(v1 + 100);
if ( (unsigned int)result < *(_DWORD *)(a1[37] + 12LL) )
{
*(_DWORD *)(v1 + 100) = result + 1;
screen_write_start(v3, a1, 0LL);
screen_write_cursormove(v3, 0LL, 0LL);
screen_write_insertline(v3, 1LL);
window_scroll_write_line(a1, (__int64)v3, 0);
window_scroll_write_line(a1, (__int64)v3, 1u);
result = screen_write_stop(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 v1; // rdx
__int64 result; // rax
_BYTE v3[24]; // [rsp-18h] [rbp-18h] BYREF

v1 = a1[50];
result = *(unsigned int *)(v1 + 100);
if ( (unsigned int)result < *(_DWORD *)(a1[37] + 12LL) )
{
*(_DWORD *)(v1 + 100) = result + 1;
screen_write_start(v3, a1, 0LL);
screen_write_cursormove(v3, 0LL, 0LL);
screen_write_insertline(v3, 1LL);
func1(a1, (__int64)v3, 0);
func1(a1, (__int64)v3, 1u);
result = screen_write_stop(v3);
}
return result;
}

original_code:
void
window_scroll_scroll_up(struct window_pane *wp)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen_write_ctx ctx;
 if (data->oy >= ((&wp->base)->grid->hsize))
  return;
 data->oy++;
 screen_write_start(&ctx, wp, ((void *)0));
 screen_write_cursormove(&ctx, 0, 0);
 screen_write_insertline(&ctx, 1);
 window_scroll_write_line(wp, &ctx, 0);
 window_scroll_write_line(wp, &ctx, 1);
 screen_write_stop(&ctx);
}

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

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

user_defined_types: struct window_scroll_mode_data { struct screen screen; struct mode_key_data mdata; unsigned int ox; unsigned int oy; }

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

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

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

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

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

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

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

user_defined_types: struct winlink_stack { struct winlink *slh_first; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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

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

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

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

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

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


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

v1 = a1[50];
result = *(unsigned int *)(v1 + 100);
if ( (_DWORD)result )
{
*(_DWORD *)(v1 + 100) = result - 1;
screen_write_start(v3, a1, 0LL);
screen_write_cursormove(v3, 0LL, 0LL);
screen_write_deleteline(v3, 1LL);
window_scroll_write_line(a1, (__int64)v3, *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) - 1);
window_scroll_write_line(a1, (__int64)v3, 0);
result = screen_write_stop(v3);
}
return result;
}

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

v1 = a1[50];
result = *(unsigned int *)(v1 + 100);
if ( (_DWORD)result )
{
*(_DWORD *)(v1 + 100) = result - 1;
screen_write_start(v3, a1, 0LL);
screen_write_cursormove(v3, 0LL, 0LL);
screen_write_deleteline(v3, 1LL);
func1(a1, (__int64)v3, *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) - 1);
func1(a1, (__int64)v3, 0);
result = screen_write_stop(v3);
}
return result;
}

original_code:
void
window_scroll_scroll_down(struct window_pane *wp)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 struct screen_write_ctx ctx;
 if (data->oy == 0)
  return;
 data->oy--;
 screen_write_start(&ctx, wp, ((void *)0));
 screen_write_cursormove(&ctx, 0, 0);
 screen_write_deleteline(&ctx, 1);
 window_scroll_write_line(wp, &ctx, ((s)->grid->sy) - 1);
 window_scroll_write_line(wp, &ctx, 0);
 screen_write_stop(&ctx);
}

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

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

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

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

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

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

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

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

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

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

user_defined_types: struct options_tree { struct options_entry *sph_root; }

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

user_defined_types: struct client { int fd; struct buffer *in; struct buffer *out; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; }

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

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct session { char *name; struct timeval tv; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; }

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

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


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

v1 = a1[50];
result = *(unsigned int *)(v1 + 96);
if ( (unsigned int)result <= 0x7FFE )
{
*(_DWORD *)(v1 + 96) = result + 1;
screen_write_start(v5, a1, 0LL);
v3 = *(_QWORD *)(v1 + 8);
if ( *(_DWORD *)(v3 + 8) > 1u )
{
v4 = 1;
do
{
screen_write_cursormove(v5, 0LL, v4);
screen_write_deletecharacter(v5, 1LL);
++v4;
v3 = *(_QWORD *)(v1 + 8);
}
while ( *(_DWORD *)(v3 + 8) > v4 );
}
window_scroll_write_column((__int64)a1, (__int64)v5, *(_DWORD *)(v3 + 4) - 1);
window_scroll_write_line(a1, (__int64)v5, 0);
result = screen_write_stop(v5);
}
return result;
}

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

v1 = a1[50];
result = *(unsigned int *)(v1 + 96);
if ( (unsigned int)result <= 0x7FFE )
{
*(_DWORD *)(v1 + 96) = result + 1;
screen_write_start(v5, a1, 0LL);
v3 = *(_QWORD *)(v1 + 8);
if ( *(_DWORD *)(v3 + 8) > 1u )
{
v4 = 1;
do
{
screen_write_cursormove(v5, 0LL, v4);
screen_write_deletecharacter(v5, 1LL);
++v4;
v3 = *(_QWORD *)(v1 + 8);
}
while ( *(_DWORD *)(v3 + 8) > v4 );
}
func4((__int64)a1, (__int64)v5, *(_DWORD *)(v3 + 4) - 1);
func1(a1, (__int64)v5, 0);
result = screen_write_stop(v5);
}
return result;
}

original_code:
void
window_scroll_scroll_right(struct window_pane *wp)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 struct screen_write_ctx ctx;
 u_int i;
 if (data->ox >= 0x7fff)
  return;
 data->ox++;
 screen_write_start(&ctx, wp, ((void *)0));
 for (i = 1; i < ((s)->grid->sy); i++) {
  screen_write_cursormove(&ctx, 0, i);
  screen_write_deletecharacter(&ctx, 1);
 }
 window_scroll_write_column(wp, &ctx, ((s)->grid->sx) - 1);
 window_scroll_write_line(wp, &ctx, 0);
 screen_write_stop(&ctx);
}

canonical_original_code:
void window_scroll_scroll_right(struct window_pane *wp)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 struct screen_write_ctx ctx;
 unsigned int i;
 if (data->ox >= 0x7fff)
  return;
 data->ox++;
 screen_write_start(&ctx, wp, ((void *)0));
 for (i = 1; i < ((s)->grid->sy); i++) {
  screen_write_cursormove(&ctx, 0, i);
  screen_write_deletecharacter(&ctx, 1);
 }
 window_scroll_write_column(wp, &ctx, ((s)->grid->sx) - 1);
 window_scroll_write_line(wp, &ctx, 0);
 screen_write_stop(&ctx);
}

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

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

user_defined_types: struct window_scroll_mode_data { struct screen screen; struct mode_key_data mdata; unsigned int ox; unsigned int oy; }

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

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

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

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

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

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

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

user_defined_types: struct winlink_stack { struct winlink *slh_first; }

user_defined_types: struct winlinks { struct winlink *rbh_root; }

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

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

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

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

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

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


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

v1 = a1[50];
result = *(unsigned int *)(v1 + 96);
if ( (_DWORD)result )
{
*(_DWORD *)(v1 + 96) = result - 1;
screen_write_start(v4, a1, 0LL);
if ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > 1u )
{
v3 = 1;
do
{
screen_write_cursormove(v4, 0LL, v3);
screen_write_insertcharacter(v4, 1LL);
++v3;
}
while ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > v3 );
}
window_scroll_write_column((__int64)a1, (__int64)v4, 0);
window_scroll_write_line(a1, (__int64)v4, 0);
result = screen_write_stop(v4);
}
return result;
}

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

v1 = a1[50];
result = *(unsigned int *)(v1 + 96);
if ( (_DWORD)result )
{
*(_DWORD *)(v1 + 96) = result - 1;
screen_write_start(v4, a1, 0LL);
if ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > 1u )
{
v3 = 1;
do
{
screen_write_cursormove(v4, 0LL, v3);
screen_write_insertcharacter(v4, 1LL);
++v3;
}
while ( *(_DWORD *)(*(_QWORD *)(v1 + 8) + 8LL) > v3 );
}
func4((__int64)a1, (__int64)v4, 0);
func1(a1, (__int64)v4, 0);
result = screen_write_stop(v4);
}
return result;
}

original_code:
void
window_scroll_scroll_left(struct window_pane *wp)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 struct screen_write_ctx ctx;
 u_int i;
 if (data->ox == 0)
  return;
 data->ox--;
 screen_write_start(&ctx, wp, ((void *)0));
 for (i = 1; i < ((s)->grid->sy); i++) {
  screen_write_cursormove(&ctx, 0, i);
  screen_write_insertcharacter(&ctx, 1);
 }
 window_scroll_write_column(wp, &ctx, 0);
 window_scroll_write_line(wp, &ctx, 0);
 screen_write_stop(&ctx);
}

canonical_original_code:
void window_scroll_scroll_left(struct window_pane *wp)
{
 struct window_scroll_mode_data *data = wp->modedata;
 struct screen *s = &data->screen;
 struct screen_write_ctx ctx;
 unsigned int i;
 if (data->ox == 0)
  return;
 data->ox--;
 screen_write_start(&ctx, wp, ((void *)0));
 for (i = 1; i < ((s)->grid->sy); i++) {
  screen_write_cursormove(&ctx, 0, i);
  screen_write_insertcharacter(&ctx, 1);
 }
 window_scroll_write_column(wp, &ctx, 0);
 window_scroll_write_line(wp, &ctx, 0);
 screen_write_stop(&ctx);
}

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

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

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

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

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

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

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

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

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

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

user_defined_types: struct options_tree { struct options_entry *sph_root; }

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

user_defined_types: struct client { int fd; struct buffer *in; struct buffer *out; char *title; char *cwd; struct tty tty; struct timeval status_timer; struct timeval repeat_timer; struct screen status; int flags; char *message_string; struct timeval message_timer; char *prompt_string; char *prompt_buffer; unsigned long prompt_index; int (*prompt_callback)(void *, char *); void *prompt_data; int prompt_flags; unsigned int prompt_hindex; struct { char **list; unsigned int num; unsigned long space; } prompt_hdata; struct mode_key_data prompt_mdata; struct session *session; }

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

user_defined_types: struct tty_keys { struct tty_key *rbh_root; }

user_defined_types: struct session { char *name; struct timeval tv; unsigned int sx; unsigned int sy; struct winlink *curw; struct winlink_stack lastw; struct winlinks windows; struct options options; struct paste_stack buffers; struct { struct session_alert *slh_first; } alerts; int flags; }

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

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


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

user_defined_types: struct key_binding { int key; struct cmd_list *cmdlist; int can_repeat; struct { struct key_binding *spe_left; struct key_binding *spe_right; } entry; }

user_defined_types: struct key_bindings { struct key_binding *sph_root; }

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

user_defined_types: struct cmd { struct cmd_entry *entry; void *data; struct { struct cmd *tqe_next; struct cmd **tqe_prev; } qentry; }

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

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

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

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

user_defined_types: struct environ { struct environ_entry *rbh_root; }

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

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

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

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

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

user_defined_types: struct mode_key_tree { struct mode_key_binding *sph_root; }

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

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

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

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

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

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

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

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

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