decompiled_code:
__int64 __fastcall intellisense_file(const char **a1, int *a2, int *a3)
{
const char *v3; // r15
char *v6; // rax
unsigned int v7; // er15
const char *v9; // rdi
char *v10; // rax
const char *v11; // rax
int v12; // eax
__int64 v13; // rax
const char *v14; // rdx
const char *v15; // rax
const char *v16; // rbx
int v17; // eax
char *v18; // rax
char *v19; // rcx
char *v20; // rdx
size_t v21; // r15
void *v22; // rsp
size_t v23; // rax
int v24; // ebx
void *v25; // rsp
char *v26; // rcx
__int64 *v27; // rbx
int v28; // eax
int v29; // er10
size_t v30; // r9
void *v31; // rsp
_BYTE *v32; // rax
char **v33; // r14
unsigned int v34; // er8
__int64 v35; // rdx
__int64 v36; // r11
_QWORD *v37; // rsi
_WORD *v38; // rdi
__int64 v39; // rbx
_WORD *v40; // rcx
_BYTE *v41; // rdx
char v42; // dl
char v43; // [rsp+0h] [rbp-110h] BYREF
_BYTE v44[7]; // [rsp+1h] [rbp-10Fh] BYREF
size_t v45; // [rsp+8h] [rbp-108h]
char *file; // [rsp+10h] [rbp-100h]
char *s; // [rsp+18h] [rbp-F8h]
int v48; // [rsp+2Ch] [rbp-E4h] BYREF
wordexp_t pwordexp; // [rsp+30h] [rbp-E0h] BYREF
struct stat v50; // [rsp+50h] [rbp-C0h] BYREF

v3 = *a1;
if ( !**a1 )
return 1;
if ( !*a3 )
return 1;
v6 = strchr(*a1, 42);
if ( v6 )
{
if ( v3 >= v6 || *(v6 - 1) != 92 )
return 1;
}
v9 = v3;
v10 = strchr(v3, 126);
if ( v10 && (v3 >= v10 || *(v10 - 1) != 92) )
{
v11 = (const char *)str_home_replace(v3);
*a1 = v11;
v9 = v11;
v12 = strlen(v11);
*a3 = v12;
*a2 = v12 + 1;
}
if ( *(_QWORD *)(((__int64 (*)(void))buffers_current)() + 8) )
{
v13 = ((__int64 (*)(void))buffers_current)();
v14 = "(no name)";
if ( *(_QWORD *)(v13 + 8) )
v14 = *(const char **)(buffers_current(v9, 126LL, "(no name)") + 8);
v15 = (const char *)chr_expand(*a1, 37LL, v14);
*a1 = v15;
v16 = v15;
v17 = strlen(v15);
*a3 = v17;
*a2 = v17 + 1;
}
else
{
v16 = *a1;
}
v18 = strrchr(v16, 32);
v19 = (char *)v16;
v20 = v18 - 1;
if ( v18 )
{
while ( 1 )
{
if ( v18 > v16 )
{
if ( *v18 != 32 )
goto LABEL_19;
}
else if ( v18 == v16 )
{
goto LABEL_23;
}
if ( *v20 != 92 )
{
LABEL_23:
v19 = v18 + 1;
if ( *v18 != 32 )
v19 = v18;
break;
}
LABEL_19:
--v18;
--v20;
}
}
s = v19;
file = (char *)strlen(v19);
v21 = (int)file + 2;
v22 = alloca(v21 + 8);
str_shell_unescape(s);
snprintf(&v43, v21, "%s*", s);
v7 = wordexp(&v43, &pwordexp, 4);
if ( v7 )
return 1;
v48 = (int)file;
if ( pwordexp.we_wordc )
{
if ( pwordexp.we_wordc == 1 )
{
s = *pwordexp.we_wordv;
if ( !strcmp(s, &v43) )
{
v7 = 1;
gui_status(0LL, ":%s [no matches]", *a1);
}
else
{
file = s;
v23 = strlen(s);
v24 = v23;
v45 = v23;
v25 = alloca((int)v23 + 2 + 8LL);
s = &v43;
if ( !stat(file, &v50) && (v50.st_mode & 0xF000) == 0x4000 )
{
v24 = v45 + 1;
sprintf(s, "%s/", *(const char **)pwordexp.we_wordv);
v26 = s;
}
else
{
v26 = strcpy(s, *(const char **)pwordexp.we_wordv);
}
intellisense_complete_to((__int64 *)a1, a2, a3, (__int64)v26, v24, v48, 1);
}
}
else
{
v27 = (__int64 *)pwordexp.we_wordv;
s = file;
v28 = longest_match((const char **)pwordexp.we_wordv);
if ( (int)s < v28 )
{
intellisense_complete_to((__int64 *)a1, a2, a3, *v27, v28, (int)s, 1);
}
else
{
uniq(v27, &pwordexp, 8LL, &qsortstrcmp, file_uniq, &v48, &free);
v29 = global_settings[5];
v30 = pwordexp.we_wordc;
v31 = alloca(pwordexp.we_wordc * (v29 + 2) + 11);
v43 = 123;
v32 = v44;
if ( pwordexp.we_wordc )
{
v33 = pwordexp.we_wordv;
v34 = 0;
v35 = 0LL;
v36 = v48;
do
{
if ( v29 <= 0 )
{
v40 = v32;
}
else
{
v37 = &v33[v35];
v38 = &v32[v29];
v39 = v36 - (_QWORD)v32;
while ( 1 )
{
v40 = v32;
v41 = &v32[*v37];
++v32;
v42 = v41[v39];
if ( !v42 )
break;
*(v32 - 1) = v42;
if ( v38 == (_WORD *)v32 )
{
v40 = v38;
break;
}
}
}
v32 = (char *)v40 + 1;
*v40 = 44;
v35 = ++v34;
}
while ( v30 > v34 );
}
*(v32 - 1) = 125;
v7 = 1;
gui_status(0LL, ":%s%s", *a1, &v43);
}
}
}
else
{
v7 = 1;
}
wordfree(&pwordexp);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char **a1, int *a2, int *a3)
{
const char *v3; // r15
char *v6; // rax
unsigned int v7; // er15
const char *v9; // rdi
char *v10; // rax
const char *v11; // rax
int v12; // eax
__int64 v13; // rax
const char *v14; // rdx
const char *v15; // rax
const char *v16; // rbx
int v17; // eax
char *v18; // rax
char *v19; // rcx
char *v20; // rdx
size_t v21; // r15
void *v22; // rsp
size_t v23; // rax
int v24; // ebx
void *v25; // rsp
char *v26; // rcx
__int64 *v27; // rbx
int v28; // eax
int v29; // er10
size_t v30; // r9
void *v31; // rsp
_BYTE *v32; // rax
char **v33; // r14
unsigned int v34; // er8
__int64 v35; // rdx
__int64 v36; // r11
_QWORD *v37; // rsi
_WORD *v38; // rdi
__int64 v39; // rbx
_WORD *v40; // rcx
_BYTE *v41; // rdx
char v42; // dl
char v43; // [rsp+0h] [rbp-110h] BYREF
_BYTE v44[7]; // [rsp+1h] [rbp-10Fh] BYREF
size_t v45; // [rsp+8h] [rbp-108h]
char *file; // [rsp+10h] [rbp-100h]
char *s; // [rsp+18h] [rbp-F8h]
int v48; // [rsp+2Ch] [rbp-E4h] BYREF
wordexp_t pwordexp; // [rsp+30h] [rbp-E0h] BYREF
struct stat v50; // [rsp+50h] [rbp-C0h] BYREF

v3 = *a1;
if ( !**a1 )
return 1;
if ( !*a3 )
return 1;
v6 = strchr(*a1, 42);
if ( v6 )
{
if ( v3 >= v6 || *(v6 - 1) != 92 )
return 1;
}
v9 = v3;
v10 = strchr(v3, 126);
if ( v10 && (v3 >= v10 || *(v10 - 1) != 92) )
{
v11 = (const char *)str_home_replace(v3);
*a1 = v11;
v9 = v11;
v12 = strlen(v11);
*a3 = v12;
*a2 = v12 + 1;
}
if ( *(_QWORD *)(((__int64 (*)(void))buffers_current)() + 8) )
{
v13 = ((__int64 (*)(void))buffers_current)();
v14 = "(no name)";
if ( *(_QWORD *)(v13 + 8) )
v14 = *(const char **)(buffers_current(v9, 126LL, "(no name)") + 8);
v15 = (const char *)chr_expand(*a1, 37LL, v14);
*a1 = v15;
v16 = v15;
v17 = strlen(v15);
*a3 = v17;
*a2 = v17 + 1;
}
else
{
v16 = *a1;
}
v18 = strrchr(v16, 32);
v19 = (char *)v16;
v20 = v18 - 1;
if ( v18 )
{
while ( 1 )
{
if ( v18 > v16 )
{
if ( *v18 != 32 )
goto LABEL_19;
}
else if ( v18 == v16 )
{
goto LABEL_23;
}
if ( *v20 != 92 )
{
LABEL_23:
v19 = v18 + 1;
if ( *v18 != 32 )
v19 = v18;
break;
}
LABEL_19:
--v18;
--v20;
}
}
s = v19;
file = (char *)strlen(v19);
v21 = (int)file + 2;
v22 = alloca(v21 + 8);
str_shell_unescape(s);
snprintf(&v43, v21, "%s*", s);
v7 = wordexp(&v43, &pwordexp, 4);
if ( v7 )
return 1;
v48 = (int)file;
if ( pwordexp.we_wordc )
{
if ( pwordexp.we_wordc == 1 )
{
s = *pwordexp.we_wordv;
if ( !strcmp(s, &v43) )
{
v7 = 1;
gui_status(0LL, ":%s [no matches]", *a1);
}
else
{
file = s;
v23 = strlen(s);
v24 = v23;
v45 = v23;
v25 = alloca((int)v23 + 2 + 8LL);
s = &v43;
if ( !stat(file, &v50) && (v50.st_mode & 0xF000) == 0x4000 )
{
v24 = v45 + 1;
sprintf(s, "%s/", *(const char **)pwordexp.we_wordv);
v26 = s;
}
else
{
v26 = strcpy(s, *(const char **)pwordexp.we_wordv);
}
func1((__int64 *)a1, a2, a3, (__int64)v26, v24, v48, 1);
}
}
else
{
v27 = (__int64 *)pwordexp.we_wordv;
s = file;
v28 = func0((const char **)pwordexp.we_wordv);
if ( (int)s < v28 )
{
func1((__int64 *)a1, a2, a3, *v27, v28, (int)s, 1);
}
else
{
uniq(v27, &pwordexp, 8LL, &qsortstrcmp, file_uniq, &v48, &free);
v29 = global_settings[5];
v30 = pwordexp.we_wordc;
v31 = alloca(pwordexp.we_wordc * (v29 + 2) + 11);
v43 = 123;
v32 = v44;
if ( pwordexp.we_wordc )
{
v33 = pwordexp.we_wordv;
v34 = 0;
v35 = 0LL;
v36 = v48;
do
{
if ( v29 <= 0 )
{
v40 = v32;
}
else
{
v37 = &v33[v35];
v38 = &v32[v29];
v39 = v36 - (_QWORD)v32;
while ( 1 )
{
v40 = v32;
v41 = &v32[*v37];
++v32;
v42 = v41[v39];
if ( !v42 )
break;
*(v32 - 1) = v42;
if ( v38 == (_WORD *)v32 )
{
v40 = v38;
break;
}
}
}
v32 = (char *)v40 + 1;
*v40 = 44;
v35 = ++v34;
}
while ( v30 > v34 );
}
*(v32 - 1) = 125;
v7 = 1;
gui_status(0LL, ":%s%s", *a1, &v43);
}
}
}
else
{
v7 = 1;
}
wordfree(&pwordexp);
return v7;
}

original_code:
int intellisense_file(char **pstr, int *psize, int *pos, char ch)
{
 char *match, *arg;
 wordexp_t exp;
 int arglen, offset;
 int ret = 1;
 if(!**pstr || *pos == 0)
  return 1;
 if((match = strchr(*pstr, '*'))){
  if(match > *pstr ? match[-1] != '\\' : 1)
   return 1;
 }
 if((match = strchr(*pstr, '~')) && (match > *pstr ? match[-1] != '\\' : 1)){
  *pstr = str_home_replace(*pstr);
  *pos += strlen(*pstr) - *pos;
  *psize = *pos + 1;
 }
 if((!!(buffers_current())->fname)){
  *pstr = chr_expand(*pstr, '%', ((buffers_current())->fname ? (buffers_current())->fname : "(no name)"));
  *pos += strlen(*pstr) - *pos;
  *psize = *pos + 1;
 }
 arg = strrchr(*pstr, ' ');
 if(arg){
  for(;;){
   while(arg > *pstr && *arg != ' ')
    arg--;
   if(arg == *pstr)
    break;
   else if(arg[-1] != '\\')
    break;
   arg--;
  }
  if(*arg == ' ')
   arg++;
 }else{
  arg = *pstr;
 }
 arglen = strlen(arg) + 2;
 match = __builtin_alloca(arglen);
 str_shell_unescape(arg);
 snprintf(match, arglen, "%s*", arg);
 if(wordexp(match, &exp, WRDE_NOCMD))
  return 1;
 offset = arglen - 2;
 switch(exp.we_wordc){
  case 0:
   break;
  case 1:
  {
   struct stat st;
   char *s;
   int len;
   if(!strcmp(exp.we_wordv[0], match)){
    gui_status(GUI_NONE, ":%s  [no matches]", *pstr);
    ret = 1;
    break;
   }
   len = strlen(exp.we_wordv[0]);
   s = __builtin_alloca(len + 2);
   if(!stat(exp.we_wordv[0], &st) && ((((st.st_mode)) & 0170000) == (0040000)))
    len++, sprintf(s, "%s/", exp.we_wordv[0]);
   else
    strcpy(s, exp.we_wordv[0]);
   intellisense_complete_to(pstr, psize, pos, s, len, offset, 1);
   ret = 0;
   break;
  }
  default:
  {
   int len;
   len = longest_match(exp.we_wordv);
   if(len > offset){
    intellisense_complete_to(pstr, psize, pos, exp.we_wordv[0], len, offset, 1);
    ret = 0;
   }else{
    char *fnames, *p;
    unsigned int i;
    uniq(exp.we_wordv, &exp.we_wordc, sizeof exp.we_wordv[0],
      qsortstrcmp, file_uniq, &offset, free);
    p = fnames = __builtin_alloca(exp.we_wordc * (2 + global_settings.tabctx) + 3);
    *p++ = '{';
    for(i = 0; i < exp.we_wordc; i++){
     int j;
     for(j = offset; j-offset < global_settings.tabctx && exp.we_wordv[i][j]; j++)
      *p++ = exp.we_wordv[i][j];
     *p++ = ',';
     *p = '\0';
    }
    p[-1] = '}';
    gui_status(GUI_NONE, ":%s%s", *pstr, fnames);
    ret = 1;
   }
   break;
  }
 }
 wordfree(&exp);
 return ret;
}

canonical_original_code:
int intellisense_file(char **pstr, int *psize, int *pos, char ch)
{
 char *match; char *arg;
 struct wordexp_t exp;
 int arglen; int offset;
 int ret = 1;
 if(!**pstr || *pos == 0)
  return 1;
 if((match = strchr(*pstr, '*'))){
  if(match > *pstr ? match[-1] != '\\' : 1)
   return 1;
 }
 if((match = strchr(*pstr, '~')) && (match > *pstr ? match[-1] != '\\' : 1)){
  *pstr = str_home_replace(*pstr);
  *pos += strlen(*pstr) - *pos;
  *psize = *pos + 1;
 }
 if((!!(buffers_current())->fname)){
  *pstr = chr_expand(*pstr, '%', ((buffers_current())->fname ? (buffers_current())->fname : "(no name)"));
  *pos += strlen(*pstr) - *pos;
  *psize = *pos + 1;
 }
 arg = strrchr(*pstr, ' ');
 if(arg){
  for(;;){
   while(arg > *pstr && *arg != ' ')
    arg--;
   if(arg == *pstr)
    break;
   else if(arg[-1] != '\\')
    break;
   arg--;
  }
  if(*arg == ' ')
   arg++;
 }else{
  arg = *pstr;
 }
 arglen = strlen(arg) + 2;
 match = __builtin_alloca(arglen);
 str_shell_unescape(arg);
 snprintf(match, arglen, "%s*", arg);
 if(wordexp(match, &exp, WRDE_NOCMD))
  return 1;
 offset = arglen - 2;
 switch(exp.we_wordc){
  case 0:
   break;
  case 1:
  {
   struct stat st;
   char *s;
   int len;
   if(!strcmp(exp.we_wordv[0], match)){
    gui_status(GUI_NONE, ":%s  [no matches]", *pstr);
    ret = 1;
    break;
   }
   len = strlen(exp.we_wordv[0]);
   s = __builtin_alloca(len + 2);
   if(!stat(exp.we_wordv[0], &st) && ((((st.st_mode)) & 0170000) == (0040000)))
    len++, sprintf(s, "%s/", exp.we_wordv[0]);
   else
    strcpy(s, exp.we_wordv[0]);
   intellisense_complete_to(pstr, psize, pos, s, len, offset, 1);
   ret = 0;
   break;
  }
  default:
  {
   int len;
   len = longest_match(exp.we_wordv);
   if(len > offset){
    intellisense_complete_to(pstr, psize, pos, exp.we_wordv[0], len, offset, 1);
    ret = 0;
   }else{
    char *fnames; char *p;
    unsigned int i;
    uniq(exp.we_wordv, &exp.we_wordc, sizeof exp.we_wordv[0],
      qsortstrcmp, file_uniq, &offset, free);
    p = fnames = __builtin_alloca(exp.we_wordc * (2 + global_settings.tabctx) + 3);
    *p++ = '{';
    for(i = 0; i < exp.we_wordc; i++){
     int j;
     for(j = offset; j-offset < global_settings.tabctx && exp.we_wordv[i][j]; j++)
      *p++ = exp.we_wordv[i][j];
     *p++ = ',';
     *p = '\0';
    }
    p[-1] = '}';
    gui_status(GUI_NONE, ":%s%s", *pstr, fnames);
    ret = 1;
   }
   break;
  }
 }
 wordfree(&exp);
 return ret;
}

variable_types:
pstr
char **

variable_types:
psize
int *

variable_types:
pos
int *

variable_types:
match
char *

variable_types:
arg
char *

variable_types: struct wordexp_t { unsigned long we_wordc; char **we_wordv; unsigned long we_offs; }

variable_types: arglen int

variable_types: offset int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
s
char *

variable_types:
fnames
char *

variable_types:
p
char *

variable_types:
i
unsigned int

variable_types: j int


repo: bobrippling/uvi

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

*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
if ( a2 == 1 )
{
v2 = global_settings[4];
*(_QWORD *)(a1 + 16) = intellisense_insert;
*(_DWORD *)(a1 + 24) = 14;
*(_DWORD *)(a1 + 4) = v2;
result = 0x100000001LL;
*(_QWORD *)(a1 + 8) = 0x100000001LL;
}
else if ( a2 == 2 )
{
*(_QWORD *)(a1 + 16) = intellisense_file;
*(_DWORD *)(a1 + 24) = 9;
}
return result;
}

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

*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
if ( a2 == 1 )
{
v2 = global_settings[4];
*(_QWORD *)(a1 + 16) = intellisense_insert;
*(_DWORD *)(a1 + 24) = 14;
*(_DWORD *)(a1 + 4) = v2;
result = 0x100000001LL;
*(_QWORD *)(a1 + 8) = 0x100000001LL;
}
else if ( a2 == 2 )
{
*(_QWORD *)(a1 + 16) = intellisense_file;
*(_DWORD *)(a1 + 24) = 9;
}
return result;
}

original_code:
void intellisense_init_opt(void *v, enum intellisense_opt o)
{
 struct gui_read_opts *opts = v;
 memset(opts, 0, sizeof *opts);
 switch(o){
  case INTELLI_NONE:
   break;
  case INTELLI_CMD:
   opts->intellisense = intellisense_file;
   opts->intellisense_ch = '\t';
   opts->newline = 0;
   opts->allow_et = 0;
   break;
  case INTELLI_INS:
   opts->intellisense = intellisense_insert;
   opts->intellisense_ch = (('n') & 037);
   opts->newline = 1;
   opts->textw = global_settings.textwidth;
   opts->allow_et = 1;
   break;
 }
}

variable_types:
v
void *

variable_types: enum intellisense_opt { INTELLI_NONE=0, INTELLI_INS=1, INTELLI_CMD=2 }

variable_types: struct gui_read_opts { int bspc_cancel; int textw; int newline; int allow_et; int (*intellisense)(char **, int *, int *, char); int intellisense_ch; } *

return_type: void


decompiled_code:
void __fastcall gui_syntax(char a1, int a2)
{
int v2; // eax

if ( a1 == 35 )
{
if ( a2 )
wattr_on(stdscr, 0x400uLL, 0LL);
}
else if ( a1 == 39 || a1 == 34 )
{
v2 = quoting;
if ( quoting )
{
if ( !a2 )
{
--quoting;
if ( v2 == 1 )
{
wattr_off(stdscr, 0x200uLL, 0LL);
quoting = 0;
}
}
}
else if ( a2 )
{
wattr_on(stdscr, 0x200uLL, 0LL);
quoting = 2;
}
}
}

canonical_decompiled_code:
void __fastcall func0(char a1, int a2)
{
int v2; // eax

if ( a1 == 35 )
{
if ( a2 )
wattr_on(stdscr, 0x400uLL, 0LL);
}
else if ( a1 == 39 || a1 == 34 )
{
v2 = quoting;
if ( quoting )
{
if ( !a2 )
{
--quoting;
if ( v2 == 1 )
{
wattr_off(stdscr, 0x200uLL, 0LL);
quoting = 0;
}
}
}
else if ( a2 )
{
wattr_on(stdscr, 0x200uLL, 0LL);
quoting = 2;
}
}
}

variable_types: c char

variable_types: on int


decompiled_code:
void gui_syntax_reset()
{
quoting = 0;
}

canonical_decompiled_code:
void func1()
{
quoting = 0;
}

original_code:
void gui_syntax_reset(void)
{
 quoting = 0;
}


original_code:
void *list_extract(struct list *l)
{
 void *ret = l->data;
 if(l->next){
  struct list *delthis = l->next;
  l->data = l->next->data;
  l->next = l->next->next;
  if(l->next)
   l->next->prev = l;
  free(delthis);
 }else if(l->prev){
  l->prev->next = ((void *)0);
  free(l);
 }else
  l->data = ((void *)0);
 return ret;
}

variable_types: struct list { void *data; struct list *next; } *

variable_types:
ret
void *

return_type: void *


decompiled_code:
void __fastcall list_remove(__int64 *a1)
{
void *v1; // rax

v1 = (void *)list_extract(a1);
free(v1);
}

canonical_decompiled_code:
void __fastcall func4(__int64 *a1)
{
void *v1; // rax

v1 = (void *)func3(a1);
free(v1);
}

original_code:
void list_remove(struct list *l)
{
 free(list_extract(l));
}

user_defined_types: struct list { void *data; struct list *next; }


original_code:
struct list *list_extract_range(struct list **l, int count)
{
 if(!(*l)->prev){
  struct list *top = *l, *bot = *l;
  if(!bot){
   *l = list_new(((void *)0));
   return top;
  }
  while(bot->next && --count > 0)
   bot = bot->next;
  if(!(*l = bot->next))
   *l = list_new(((void *)0));
  (*l)->prev = ((void *)0);
  bot->next = ((void *)0);
  return top;
 }else{
  struct list *top = (*l)->prev, *bot = *l, *ret;
  while(bot->next && --count > 0)
   bot = bot->next;
  top->next = bot->next;
  if(top->next)
   top->next->prev = top;
  bot->next = ((void *)0);
  (*l)->prev = ((void *)0);
  ret = *l;
  *l = top;
  return ret;
 }
}

canonical_original_code:
struct list *list_extract_range(struct list **l, int count)
{
 if(!(*l)->prev){
  struct list *top = *l; struct list *bot = *l;
  if(!bot){
   *l = list_new(((void *)0));
   return top;
  }
  while(bot->next && --count > 0)
   bot = bot->next;
  if(!(*l = bot->next))
   *l = list_new(((void *)0));
  (*l)->prev = ((void *)0);
  bot->next = ((void *)0);
  return top;
 }else{
  struct list *top = (*l)->prev; struct list *bot = *l; struct list *ret;
  while(bot->next && --count > 0)
   bot = bot->next;
  top->next = bot->next;
  if(top->next)
   top->next->prev = top;
  bot->next = ((void *)0);
  (*l)->prev = ((void *)0);
  ret = *l;
  *l = top;
  return ret;
 }
}

variable_types:
l
struct list **

variable_types: count int

return_type: struct list { void *data; struct list *next; } *


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
struct list *list_gethead(struct list *l)
{
 while(l->prev)
  l = l->prev;
 return l;
}

variable_types:
l
struct list *


decompiled_code:
__int64 __fastcall list_count(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
_QWORD *v3; // rdx
__int64 v4; // rax

v1 = list_gethead(a1);
v2 = 1;
v3 = (_QWORD *)v1;
v4 = *(_QWORD *)(v1 + 8);
if ( !v4 )
return *v3 != 0LL;
do
{
v4 = *(_QWORD *)(v4 + 8);
++v2;
}
while ( v4 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
_QWORD *v3; // rdx
__int64 v4; // rax

v1 = func6(a1);
v2 = 1;
v3 = (_QWORD *)v1;
v4 = *(_QWORD *)(v1 + 8);
if ( !v4 )
return *v3 != 0LL;
do
{
v4 = *(_QWORD *)(v4 + 8);
++v2;
}
while ( v4 );
return v2;
}

original_code:
int list_count(struct list *l)
{
 int i;
 l = list_gethead(l);
 if(!l->next && !l->data)
  return 0;
 i = 1;
 while(l->next)
  l = l->next, ++i;
 return i;
}

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall list_indexof(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = list_gethead(a1);
v3 = 0;
if ( v2 != a2 && v2 )
{
do
{
v2 = *(_QWORD *)(v2 + 8);
++v3;
}
while ( v2 && a2 != v2 );
}
if ( a2 != v2 )
v3 = -1;
return v3;
}

original_code:
int list_indexof(struct list *l, struct list *p)
{
 int i = 0;
 l = list_gethead(l);
 while(l && l != p)
  i++, l = l->next;
 if(l == p)
  return i;
 return -1;
}

variable_types:
p
struct list *


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
struct list *list_gettail(struct list *l)
{
 while(l->next)
  l = l->next;
 return l;
}


decompiled_code:
__int64 __fastcall list_insertlistafter(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx

result = list_gettail(a2);
v4 = *(_QWORD *)(v3 + 8);
*(_QWORD *)(result + 8) = v4;
if ( v4 )
*(_QWORD *)(v4 + 16) = result;
*(_QWORD *)(v3 + 8) = a2;
*(_QWORD *)(a2 + 16) = v3;
return result;
}

original_code:
void list_insertlistafter(struct list *l, struct list *new)
{
 struct list *newend = list_gettail(new);
 newend->next = l->next;
 if(newend->next)
  newend->next->prev = newend;
 l->next = new;
 new->prev = l;
}

variable_types:
new
struct list *


original_code:
void list_insertlistbefore(struct list *l, struct list *new)
{
 new = list_gethead(new);
 if(!l->data){
  l->data = new->data;
  new = new->next;
  free(new->prev);
  l->next = new;
  new->prev = l;
 }else if(!l->prev){
  struct list *block = new;
  char *saved = l->data;
  l->data = new->data;
  block->data = saved;
  new = new->next;
  if(new){
   struct list *newend = list_gettail(new);
   newend->next = block;
   block->prev = newend;
   newend = newend->next;
   if((newend->next = l->next))
    newend->next->prev = newend;
   new->prev = l;
   l->next = new;
  }else{
   if((block->next = l->next))
    block->next->prev = block;
   l->next = block;
   block->prev = l;
  }
 }else
  list_insertlistafter(l->prev, new);
}

variable_types:
saved
char *


decompiled_code:
__int64 __fastcall list_getindex(__int64 a1, int a2)
{
__int64 i; // r8
int v3; // eax

for ( i = list_gethead(a1); ; i = *(_QWORD *)(i + 8) )
{
v3 = a2--;
if ( v3 <= 0 || !*(_QWORD *)(i + 8) )
break;
}
if ( a2 != -1 )
i = 0LL;
return i;
}

original_code:
struct list *list_getindex(struct list *l, int i)
{
 l = list_gethead(l);
 while(i --> 0 && l->next)
  l = l->next;
 if(i != -1)
  return ((void *)0);
 return l;
}


decompiled_code:
void __fastcall list_free_nodata(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

v1 = list_gethead(a1);
if ( v1 )
{
v2 = (_QWORD *)v1;
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

v1 = func6(a1);
if ( v1 )
{
v2 = (_QWORD *)v1;
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
}

original_code:
void list_free_nodata(struct list *l)
{
 struct list *del;
 l = list_gethead(l);
 while(l){
  del = l;
  l = l->next;
  free(del);
 }
}


decompiled_code:
void __fastcall list_free(__int64 a1, void (*a2)(void))
{
__int64 v2; // rax
_QWORD *v3; // rbx
_QWORD *v4; // rbp

v2 = list_gethead(a1);
if ( v2 )
{
v3 = (_QWORD *)v2;
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
if ( *v4 )
a2();
free(v4);
}
while ( v3 );
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, void (*a2)(void))
{
__int64 v2; // rax
_QWORD *v3; // rbx
_QWORD *v4; // rbp

v2 = func6(a1);
if ( v2 )
{
v3 = (_QWORD *)v2;
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
if ( *v4 )
a2();
free(v4);
}
while ( v3 );
}
}

original_code:
void list_free(struct list *l, void (*f)(void *))
{
 struct list *del;
 l = list_gethead(l);
 while(l){
  del = l;
  l = l->next;
  if(del->data)
   f(del->data);
  free(del);
 }
}

variable_types:
f
void (*)(void *)


decompiled_code:
void __fastcall list_remove_range(__int64 *a1, int a2, void (*a3)(void))
{
__int64 v4; // rax

v4 = list_extract_range(a1, a2);
list_free(v4, a3);
}

canonical_decompiled_code:
void __fastcall func16(__int64 *a1, int a2, void (*a3)(void))
{
__int64 v4; // rax

v4 = func5(a1, a2);
func15(v4, a3);
}

original_code:
void list_remove_range(struct list **l, int count, void (*f)(void *))
{
 list_free(list_extract_range(l, count), f);
}

variable_types: struct list { void *data; struct list *next; } **


decompiled_code:
_BOOL8 rc_read()
{
const char *v0; // rbp
_BOOL8 result; // rax

v0 = (const char *)file_rc();
if ( access(v0, 0) )
result = 1LL;
else
result = rc_source(v0);
return result;
}

canonical_decompiled_code:
_BOOL8 func1()
{
const char *v0; // rbp
_BOOL8 result; // rax

v0 = (const char *)file_rc();
if ( access(v0, 0) )
result = 1LL;
else
result = func0(v0);
return result;
}

original_code:
int rc_read()
{
 const char *fn = file_rc();
 if(!access(fn, 0))
  return rc_source(fn);
 return 1;
}

canonical_original_code:
int rc_read()
{
 char *fn = file_rc();
 if(!access(fn, 0))
  return rc_source(fn);
 return 1;
}

variable_types:
fn
char *


decompiled_code:
__int64 __fastcall parent_write(int fd, __int64 a2)
{
__int64 v2; // rbx
const char *v3; // rbp
size_t v4; // rax
unsigned int v5; // er13

if ( a2 )
{
v2 = a2;
while ( 1 )
{
v3 = *(const char **)v2;
v4 = strlen(*(const char **)v2);
if ( write(fd, v3, v4) == -1 || write(fd, &nl_0, 1uLL) == -1 )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
goto LABEL_8;
}
v5 = -1;
}
else
{
LABEL_8:
v5 = 0;
}
close(fd);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2)
{
__int64 v2; // rbx
const char *v3; // rbp
size_t v4; // rax
unsigned int v5; // er13

if ( a2 )
{
v2 = a2;
while ( 1 )
{
v3 = *(const char **)v2;
v4 = strlen(*(const char **)v2);
if ( write(fd, v3, v4) == -1 || write(fd, &nl_0, 1uLL) == -1 )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
goto LABEL_8;
}
v5 = -1;
}
else
{
LABEL_8:
v5 = 0;
}
close(fd);
return v5;
}

original_code:
static int parent_write(int fd, struct list *l)
{
 static const char nl = '\n';
 int ret = 0;
 for(; l; l = l->next)
  if(write(fd, l->data, strlen(l->data)) == -1 ||
    write(fd, &nl, 1) == -1){
   ret = -1;
   break;
  }
 close(fd);
 return ret;
}

canonical_original_code:
static int parent_write(int fd, struct list *l)
{
 static char nl = '\n';
 int ret = 0;
 for(; l; l = l->next)
  if(write(fd, l->data, strlen(l->data)) == -1 ||
    write(fd, &nl, 1) == -1){
   ret = -1;
   break;
  }
 close(fd);
 return ret;
}

variable_types: fd int

variable_types: nl char

variable_types: ret int


decompiled_code:
__int64 __fastcall pipe_read(char *command)
{
__pid_t v1; // eax
__int64 v2; // r12
int *v3; // rax
int v4; // ebx
int *v5; // rbp
__int64 result; // rax
int v7; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) == -1 )
return 0LL;
v1 = fork();
if ( v1 == -1 )
return 0LL;
if ( !v1 )
{
close(pipedes[0]);
if ( dup2(pipedes[1], 1) != -1 )
{
dup2(1, 2);
v7 = system(command);
exit(v7);
}
exit(-1);
}
close(pipedes[1]);
v2 = list_from_fd((unsigned int)pipedes[0], 0LL);
v3 = _errno_location();
v4 = *v3;
v5 = v3;
wait(0LL);
result = v2;
*v5 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *command)
{
__pid_t v1; // eax
__int64 v2; // r12
int *v3; // rax
int v4; // ebx
int *v5; // rbp
__int64 result; // rax
int v7; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) == -1 )
return 0LL;
v1 = fork();
if ( v1 == -1 )
return 0LL;
if ( !v1 )
{
close(pipedes[0]);
if ( dup2(pipedes[1], 1) != -1 )
{
dup2(1, 2);
v7 = system(command);
exit(v7);
}
exit(-1);
}
close(pipedes[1]);
v2 = list_from_fd((unsigned int)pipedes[0], 0LL);
v3 = _errno_location();
v4 = *v3;
v5 = v3;
wait(0LL);
result = v2;
*v5 = v4;
return result;
}

original_code:
struct list *pipe_read(const char *cmd)
{
 int fds[2];
 if(pipe(fds) == -1)
  return ((void *)0);
 switch(fork()){
  case -1:
   return ((void *)0);
  case 0:
   close(fds[0]);
   if(dup2(fds[1], 1) == -1)
    exit(-1);
   dup2(1, 2);
   exit(system(cmd));
  default:
  {
   struct list *l;
   int saveerrno;
   close(fds[1]);
   l = list_from_fd(fds[0], ((void *)0));
   saveerrno = (*__errno_location ());
   wait(((void *)0));
   (*__errno_location ()) = saveerrno;
   return l;
  }
 }
}

canonical_original_code:
struct list *pipe_read(char *cmd)
{
 int fds[2];
 if(pipe(fds) == -1)
  return ((void *)0);
 switch(fork()){
  case -1:
   return ((void *)0);
  case 0:
   close(fds[0]);
   if(dup2(fds[1], 1) == -1)
    exit(-1);
   dup2(1, 2);
   exit(system(cmd));
  default:
  {
   struct list *l;
   int saveerrno;
   close(fds[1]);
   l = list_from_fd(fds[0], ((void *)0));
   saveerrno = (*__errno_location ());
   wait(((void *)0));
   (*__errno_location ()) = saveerrno;
   return l;
  }
 }
}

variable_types:
cmd
char *

variable_types:
fds
int [2]

variable_types: saveerrno int


decompiled_code:
int __fastcall pipe_write(char *command, __int64 a2, int a3)
{
int result; // eax
int v5; // eax
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch]

result = pipe((int *)&stat_loc.__iptr + 1);
if ( result != -1 )
{
result = fork();
if ( result != -1 )
{
if ( !result )
{
if ( a3 )
{
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
close(v7);
if ( dup2(SHIDWORD(stat_loc.__iptr), 0) != -1 )
{
v5 = system(command);
exit(v5);
}
exit(-1);
}
close(SHIDWORD(stat_loc.__iptr));
parent_write(v7, a2);
wait((__WAIT_STATUS)&stat_loc);
result = (int)stat_loc.__uptr;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *command, __int64 a2, int a3)
{
int result; // eax
int v5; // eax
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch]

result = pipe((int *)&stat_loc.__iptr + 1);
if ( result != -1 )
{
result = fork();
if ( result != -1 )
{
if ( !result )
{
if ( a3 )
{
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
close(v7);
if ( dup2(SHIDWORD(stat_loc.__iptr), 0) != -1 )
{
v5 = system(command);
exit(v5);
}
exit(-1);
}
close(SHIDWORD(stat_loc.__iptr));
func0(v7, a2);
wait((__WAIT_STATUS)&stat_loc);
result = (int)stat_loc.__uptr;
}
}
return result;
}

original_code:
int pipe_write(const char *cmd, struct list *l, int close_out)
{
 int fds[2];
 if(pipe(fds) == -1)
  return -1;
 switch(fork()){
  case -1:
   return -1;
  case 0:
  {
   if(close_out){
    freopen("/dev/null", "w", stdout);
    freopen("/dev/null", "w", stderr);
   }
   close(fds[1]);
   if(dup2(fds[0], 0) == -1)
    exit(-1);
   exit(system(cmd));
  }
  default:
  {
   int ret;
   close(fds[0]);
   parent_write(fds[1], l);
   wait(&ret);
   return ret;
  }
 }
}

canonical_original_code:
int pipe_write(char *cmd, struct list *l, int close_out)
{
 int fds[2];
 if(pipe(fds) == -1)
  return -1;
 switch(fork()){
  case -1:
   return -1;
  case 0:
  {
   if(close_out){
    freopen("/dev/null", "w", stdout);
    freopen("/dev/null", "w", stderr);
   }
   close(fds[1]);
   if(dup2(fds[0], 0) == -1)
    exit(-1);
   exit(system(cmd));
  }
  default:
  {
   int ret;
   close(fds[0]);
   parent_write(fds[1], l);
   wait(&ret);
   return ret;
  }
 }
}

variable_types: struct list { void *data; struct list *next; } *


decompiled_code:
__int64 __fastcall pipe_readwrite(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
__int64 v3; // r12
int *v4; // rax
int v5; // ebx
int *v6; // rbp
__int64 result; // rax
int v8; // [rsp+0h] [rbp-28h] BYREF
int fd; // [rsp+4h] [rbp-24h]
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(&v8) == -1 || pipe(pipedes) == -1 )
{
close(v8);
close(fd);
close(pipedes[0]);
close(pipedes[1]);
result = 0LL;
}
else
{
v2 = fork();
if ( v2 == -1 )
{
result = 0LL;
}
else
{
if ( !v2 )
{
close(fd);
close(pipedes[0]);
if ( dup2(v8, 0) != -1 && dup2(pipedes[1], 1) != -1 && dup2(1, 2) != -1 )
{
execlp("sh", "sh", "-c", a1, 0LL);
perror("exec()");
exit(-1);
}
exit(-1);
}
v3 = 0LL;
close(v8);
close(pipedes[1]);
if ( !(unsigned int)parent_write(fd, a2) )
v3 = list_from_fd((unsigned int)pipedes[0], 0LL);
v4 = _errno_location();
v5 = *v4;
v6 = v4;
wait(0LL);
result = v3;
*v6 = v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
__int64 v3; // r12
int *v4; // rax
int v5; // ebx
int *v6; // rbp
__int64 result; // rax
int v8; // [rsp+0h] [rbp-28h] BYREF
int fd; // [rsp+4h] [rbp-24h]
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(&v8) == -1 || pipe(pipedes) == -1 )
{
close(v8);
close(fd);
close(pipedes[0]);
close(pipedes[1]);
result = 0LL;
}
else
{
v2 = fork();
if ( v2 == -1 )
{
result = 0LL;
}
else
{
if ( !v2 )
{
close(fd);
close(pipedes[0]);
if ( dup2(v8, 0) != -1 && dup2(pipedes[1], 1) != -1 && dup2(1, 2) != -1 )
{
execlp("sh", "sh", "-c", a1, 0LL);
perror("exec()");
exit(-1);
}
exit(-1);
}
v3 = 0LL;
close(v8);
close(pipedes[1]);
if ( !(unsigned int)func0(fd, a2) )
v3 = list_from_fd((unsigned int)pipedes[0], 0LL);
v4 = _errno_location();
v5 = *v4;
v6 = v4;
wait(0LL);
result = v3;
*v6 = v5;
}
}
return result;
}

original_code:
struct list *pipe_readwrite(const char *cmd, struct list *l)
{
 int parent_to_child[2], child_to_parent[2];
 if(pipe(parent_to_child) == -1 || pipe(child_to_parent) == -1){
  close(parent_to_child[0]);
  close(parent_to_child[1]);
  close(child_to_parent[0]);
  close(child_to_parent[1]);
  return ((void *)0);
 }
 switch(fork()){
  case -1:
   return ((void *)0);
  case 0:
   close(parent_to_child[1]);
   close(child_to_parent[0]);
   if(
    dup2(parent_to_child[0], 0 ) == -1 ||
    dup2(child_to_parent[1], 1) == -1 ||
    dup2(1, 2) == -1
   ){
    exit(-1);
   }
   execlp("sh", "sh", "-c", cmd, ((void *)0));
   perror("exec()");
   exit(-1);
  default:
  {
   struct list *ret;
   int saveerrno;
   close(parent_to_child[0]);
   close(child_to_parent[1]);
   if(parent_write(parent_to_child[1], l))
    ret = ((void *)0);
   else
    ret = list_from_fd(child_to_parent[0], ((void *)0));
   saveerrno = (*__errno_location ());
   wait(((void *)0));
   (*__errno_location ()) = saveerrno;
   return ret;
  }
 }
}

canonical_original_code:
struct list *pipe_readwrite(char *cmd, struct list *l)
{
 int parent_to_child[2]; int child_to_parent[2];
 if(pipe(parent_to_child) == -1 || pipe(child_to_parent) == -1){
  close(parent_to_child[0]);
  close(parent_to_child[1]);
  close(child_to_parent[0]);
  close(child_to_parent[1]);
  return ((void *)0);
 }
 switch(fork()){
  case -1:
   return ((void *)0);
  case 0:
   close(parent_to_child[1]);
   close(child_to_parent[0]);
   if(
    dup2(parent_to_child[0], 0 ) == -1 ||
    dup2(child_to_parent[1], 1) == -1 ||
    dup2(1, 2) == -1
   ){
    exit(-1);
   }
   execlp("sh", "sh", "-c", cmd, ((void *)0));
   perror("exec()");
   exit(-1);
  default:
  {
   struct list *ret;
   int saveerrno;
   close(parent_to_child[0]);
   close(child_to_parent[1]);
   if(parent_write(parent_to_child[1], l))
    ret = ((void *)0);
   else
    ret = list_from_fd(child_to_parent[0], ((void *)0));
   saveerrno = (*__errno_location ());
   wait(((void *)0));
   (*__errno_location ()) = saveerrno;
   return ret;
  }
 }
}


decompiled_code:
__int64 __fastcall range_through_pipe(unsigned int *a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // rbp
int *v5; // rbx
_QWORD *v6; // rax
_QWORD *v7; // r12
unsigned int v8; // er13
_QWORD *v9; // rax
__int64 v10; // r13
unsigned int v11; // er12
int v12; // er13
_QWORD *v14; // rax
__int64 v15; // rsi
_QWORD *v16; // rax
_QWORD *v17; // rbp
__int64 v18; // rax
_QWORD *v19; // rax

v3 = buffers_current();
v4 = buffer_extract_range(v3, a1);
v5 = _errno_location();
if ( !v4 )
{
v14 = (_QWORD *)buffers_current();
v15 = list_gethead(*v14);
v16 = (_QWORD *)pipe_readwrite(a2, v15);
v17 = v16;
if ( !v16 )
{
v12 = *v5;
v11 = 0;
goto LABEL_8;
}
if ( !*v16 )
{
v11 = 1;
list_free(v16, &free);
v12 = *v5;
goto LABEL_8;
}
v18 = buffers_current();
buffer_replace(v18, v17);
goto LABEL_7;
}
v6 = (_QWORD *)pipe_readwrite(a2, v4);
v7 = v6;
if ( !v6 )
{
v12 = *v5;
v11 = 0;
LABEL_10:
list_free(v4, &free);
goto LABEL_8;
}
if ( !*v6 )
{
v11 = 1;
list_free(v6, &free);
v12 = *v5;
goto LABEL_10;
}
v8 = *a1;
v9 = (_QWORD *)buffers_current();
v10 = list_getindex(*v9, v8);
*(_DWORD *)(buffers_current() + 32) = 1;
if ( v10 )
{
list_insertlistbefore(v10, v7);
}
else
{
v19 = (_QWORD *)buffers_current();
list_appendlist(*v19, v7);
}
list_free_nodata(v4);
LABEL_7:
v11 = 0;
*(_DWORD *)(buffers_current() + 20) = 1;
v12 = *v5;
LABEL_8:
*v5 = v12;
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // rbp
int *v5; // rbx
_QWORD *v6; // rax
_QWORD *v7; // r12
unsigned int v8; // er13
_QWORD *v9; // rax
__int64 v10; // r13
unsigned int v11; // er12
int v12; // er13
_QWORD *v14; // rax
__int64 v15; // rsi
_QWORD *v16; // rax
_QWORD *v17; // rbp
__int64 v18; // rax
_QWORD *v19; // rax

v3 = buffers_current();
v4 = buffer_extract_range(v3, a1);
v5 = _errno_location();
if ( !v4 )
{
v14 = (_QWORD *)buffers_current();
v15 = list_gethead(*v14);
v16 = (_QWORD *)func3(a2, v15);
v17 = v16;
if ( !v16 )
{
v12 = *v5;
v11 = 0;
goto LABEL_8;
}
if ( !*v16 )
{
v11 = 1;
list_free(v16, &free);
v12 = *v5;
goto LABEL_8;
}
v18 = buffers_current();
buffer_replace(v18, v17);
goto LABEL_7;
}
v6 = (_QWORD *)func3(a2, v4);
v7 = v6;
if ( !v6 )
{
v12 = *v5;
v11 = 0;
LABEL_10:
list_free(v4, &free);
goto LABEL_8;
}
if ( !*v6 )
{
v11 = 1;
list_free(v6, &free);
v12 = *v5;
goto LABEL_10;
}
v8 = *a1;
v9 = (_QWORD *)buffers_current();
v10 = list_getindex(*v9, v8);
*(_DWORD *)(buffers_current() + 32) = 1;
if ( v10 )
{
list_insertlistbefore(v10, v7);
}
else
{
v19 = (_QWORD *)buffers_current();
list_appendlist(*v19, v7);
}
list_free_nodata(v4);
LABEL_7:
v11 = 0;
*(_DWORD *)(buffers_current() + 20) = 1;
v12 = *v5;
LABEL_8:
*v5 = v12;
return v11;
}

original_code:
int range_through_pipe(struct range *rng, const char *cmd)
{
 struct list *l, *to_pipe;
 int eno, ret = 0;
 to_pipe = buffer_extract_range(buffers_current(), rng);
 l = pipe_readwrite(cmd, to_pipe ? to_pipe : list_gethead ( ((buffers_current())->lines) ));
 if(l){
  if(l->data){
   if(to_pipe){
    struct list *inshere;
    inshere = list_getindex ( ((buffers_current())->lines), rng->start);
    if(inshere)
     ( (buffers_current())->dirty = 1, list_insertlistbefore ( inshere, l ) );
    else
     ( (buffers_current())->dirty = 1, list_appendlist ( ((buffers_current())->lines), l ) );
    list_free_nodata(to_pipe);
    to_pipe = ((void *)0);
   }else{
    buffer_replace(buffers_current(), l);
   }
   ((buffers_current())->modified) = 1;
  }else{
   list_free(l, free);
   ret = 1;
  }
 }
 eno = (*__errno_location ());
 if(to_pipe)
  list_free(to_pipe, free);
 (*__errno_location ()) = eno;
 return ret;
}

canonical_original_code:
int range_through_pipe(struct range *rng, char *cmd)
{
 struct list *l; struct list *to_pipe;
 int eno; int ret = 0;
 to_pipe = buffer_extract_range(buffers_current(), rng);
 l = pipe_readwrite(cmd, to_pipe ? to_pipe : list_gethead ( ((buffers_current())->lines) ));
 if(l){
  if(l->data){
   if(to_pipe){
    struct list *inshere;
    inshere = list_getindex ( ((buffers_current())->lines), rng->start);
    if(inshere)
     ( (buffers_current())->dirty = 1, list_insertlistbefore ( inshere, l ) );
    else
     ( (buffers_current())->dirty = 1, list_appendlist ( ((buffers_current())->lines), l ) );
    list_free_nodata(to_pipe);
    to_pipe = ((void *)0);
   }else{
    buffer_replace(buffers_current(), l);
   }
   ((buffers_current())->modified) = 1;
  }else{
   list_free(l, free);
   ret = 1;
  }
 }
 eno = (*__errno_location ());
 if(to_pipe)
  list_free(to_pipe, free);
 (*__errno_location ()) = eno;
 return ret;
}

variable_types:
rng
struct range { int start; } *

variable_types: eno int


decompiled_code:
_BOOL8 __fastcall yank_char_valid(int a1)
{
return (unsigned int)(a1 - 96) <= 0x1A;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
return (unsigned int)(a1 - 96) <= 0x1A;
}

original_code:
int yank_char_valid(int reg)
{
 return ('a' - 1) <= reg && reg <= 'z';
}

variable_types: reg int


decompiled_code:
__int64 __fastcall yank_index(char a1)
{
bool v1; // zf
unsigned int v2; // edx
__int64 result; // rax

v1 = !yank_char_valid(a1);
result = 0xFFFFFFFFLL;
if ( !v1 )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
bool v1; // zf
unsigned int v2; // edx
__int64 result; // rax

v1 = !func0(a1);
result = 0xFFFFFFFFLL;
if ( !v1 )
result = v2;
return result;
}

original_code:
static int yank_index(char reg)
{
 if(yank_char_valid(reg))
  return reg - ('a' - 1);
 return -1;
}

variable_types: reg char


decompiled_code:
__int64 __fastcall yank_set(char a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v5; // rbx
unsigned __int64 v6; // rax
void *v7; // rdi

result = yank_index(a1);
if ( (_DWORD)result != -1 )
{
v5 = (int)result;
v6 = 4LL * (int)result;
v7 = (void *)yanks[v6 / 2];
if ( v7 )
{
if ( dword_108[v6] )
list_free(v7, &free);
else
free(v7);
}
result = 16 * v5;
*(__int64 *)((char *)yanks + result) = a2;
*(int *)((char *)dword_108 + result) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v5; // rbx
unsigned __int64 v6; // rax
void *v7; // rdi

result = func1(a1);
if ( (_DWORD)result != -1 )
{
v5 = (int)result;
v6 = 4LL * (int)result;
v7 = (void *)yanks[v6 / 2];
if ( v7 )
{
if ( dword_108[v6] )
list_free(v7, &free);
else
free(v7);
}
result = 16 * v5;
*(__int64 *)((char *)yanks + result) = a2;
*(int *)((char *)dword_108 + result) = a3;
}
return result;
}

original_code:
static void yank_set(char reg, void *d, int is_l)
{
 int i = yank_index(reg);
 if(i == -1)
  return;
 if(yanks[i].v){
  if(yanks[i].is_list)
   list_free((struct list *)yanks[i].v, free);
  else
   free(yanks[i].v);
 }
 yanks[i].v = d;
 yanks[i].is_list = is_l;
}

variable_types:
d
void *

variable_types: i int


decompiled_code:
__int64 __fastcall yank_set_str(char a1, __int64 a2)
{
return yank_set(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, __int64 a2)
{
return func3(a1, a2, 0);
}

original_code:
void yank_set_str(char reg, char *s)
{
 yank_set(reg, s, 0);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall yank_set_list(char a1, __int64 a2)
{
return yank_set(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, __int64 a2)
{
return func3(a1, a2, 1);
}

original_code:
void yank_set_list(char reg, struct list *l)
{
 yank_set(reg, l, 1);
}


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

result = 39LL;
if ( a1 != 36 )
{
result = 46LL;
if ( a1 != 37 )
{
result = (unsigned int)(a1 + 48);
if ( a1 >= 10 )
result = (unsigned int)(a1 + 87);
}
}
return result;
}

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

result = 39LL;
if ( a1 != 36 )
{
result = 46LL;
if ( a1 != 37 )
{
result = (unsigned int)(a1 + 48);
if ( a1 >= 10 )
result = (unsigned int)(a1 + 87);
}
}
return result;
}

original_code:
char mark_from_idx(int c)
{
 switch(c){
  case 36: return '\'';
  case 37: return '.';
 }
 if(c >= 10)
  return c - 10 + 'a';
 return c + '0';
}

variable_types: c int

return_type: char


decompiled_code:
__int64 mark_count()
{
return 38LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 38LL;
}

original_code:
int mark_count()
{
 return 38;
}

canonical_original_code:
int mark_count()
{
 return 38;
}


decompiled_code:
__int64 mark_jump()
{
return mark_cur(39);
}

canonical_decompiled_code:
__int64 func6()
{
return func5(39);
}

original_code: void mark_jump(void) { mark_cur('\''); }

canonical_original_code: void mark_jump() { mark_cur('\''); }


decompiled_code:
__int64 mark_edit()
{
return mark_cur(46);
}

canonical_decompiled_code:
__int64 func7()
{
return func5(46);
}

original_code: void mark_edit(void) { mark_cur('.'); }

canonical_original_code: void mark_edit() { mark_cur('.'); }


decompiled_code:
__int64 __fastcall mark_get_idx(int a1, _DWORD *a2, _DWORD *a3)
{
unsigned int v3; // er8
__int64 v4; // rax

v3 = 1;
v4 = 3LL * a1;
if ( marks[v4 + 2] )
{
v3 = 0;
*a2 = marks[3 * a1];
*a3 = marks[v4 + 1];
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, _DWORD *a2, _DWORD *a3)
{
unsigned int v3; // er8
__int64 v4; // rax

v3 = 1;
v4 = 3LL * a1;
if ( marks[v4 + 2] )
{
v3 = 0;
*a2 = marks[3 * a1];
*a3 = marks[v4 + 1];
}
return v3;
}

original_code:
int mark_get_idx(int i, int *y, int *x)
{
 if(marks[i].set){
  *y = marks[i].y;
  *x = marks[i].x;
  return 0;
 }
 return 1;
}

variable_types:
y
int *

variable_types:
x
int *


decompiled_code:
__int64 __fastcall mark_get(int a1, _DWORD *a2)
{
int v2; // eax
_DWORD *v3; // r8

v2 = mark_idx(a1);
return mark_get_idx(v2, a2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _DWORD *a2)
{
int v2; // eax
_DWORD *v3; // r8

v2 = func0(a1);
return func8(v2, a2, v3);
}

original_code:
int mark_get(int c, int *y, int *x)
{
 return mark_get_idx(mark_idx(c), y, x);
}


decompiled_code:
__int64 __fastcall mark_is_set(int a1)
{
return (unsigned int)marks[3 * (int)mark_idx(a1) + 2];
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return (unsigned int)marks[3 * (int)func0(a1) + 2];
}

original_code:
int mark_is_set(int c)
{
 return marks[mark_idx(c)].set;
}


decompiled_code:
__int64 __fastcall mark_find(int a1, int a2)
{
int *v3; // rax
int i; // edi

v3 = marks;
for ( i = 0; i != 38; ++i )
{
if ( v3[2] && *v3 == a1 && v3[1] == a2 )
return (unsigned int)(char)mark_from_idx(i);
v3 += 3;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
int *v3; // rax
int i; // edi

v3 = marks;
for ( i = 0; i != 38; ++i )
{
if ( v3[2] && *v3 == a1 && v3[1] == a2 )
return (unsigned int)(char)func1(i);
v3 += 3;
}
return 0xFFFFFFFFLL;
}

original_code:
int mark_find(int y, int x)
{
 int i;
 for(i = 0; i < 38; i++)
  if(marks[i].set && marks[i].y == y && marks[i].x == x)
   return mark_from_idx(i);
 return -1;
}

variable_types: y int

variable_types: x int


number

original_code:
static int number(char **sp, int cur, int lim)
{
 char *s = *sp;
 if(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISdigit)){
  curv = *s - '0';
  s++;
  ++*sp;
  while(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISdigit)){
   curv = curv * 10 + *s - '0';
   s++;
   ++*sp;
  }
  return 1;
 }else
  switch(*s){
   case '^':
    ++*sp;
    curv = 1;
    return 1;
   case '$':
    ++*sp;
    curv = lim;
    return 1;
   case '.':
    ++*sp;
    curv = cur+1;
    return 1;
   case '+':
   case '-':
   {
    int chr = *s;
    int i;
    ++*sp;
    if(((*__ctype_b_loc ())[(int) ((**sp))] & (unsigned short int) _ISdigit)){
     number(sp, cur, lim);
     i = curv;
    }else{
     i = cur;
    }
    if(chr == '+')
     i += 2;
    else
     i -= 1;
    curv = i;
    return 1;
   }
  }
 return 0;
}

canonical_original_code:
static int number(char **sp, int cur, int lim)
{
 char *s = *sp;
 if(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISdigit)){
  curv = *s - '0';
  s++;
  ++*sp;
  while(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISdigit)){
   curv = curv * 10 + *s - '0';
   s++;
   ++*sp;
  }
  return 1;
 }else
  switch(*s){
   case '^':
    ++*sp;
    curv = 1;
    return 1;
   case '$':
    ++*sp;
    curv = lim;
    return 1;
   case '.':
    ++*sp;
    curv = cur+1;
    return 1;
   case '+':
   case '-':
   {
    int chr = *s;
    int i;
    ++*sp;
    if(((*__ctype_b_loc ())[(int) ((**sp))] & (unsigned short) _ISdigit)){
     number(sp, cur, lim);
     i = curv;
    }else{
     i = cur;
    }
    if(chr == '+')
     i += 2;
    else
     i -= 1;
    curv = i;
    return 1;
   }
  }
 return 0;
}

variable_types:
sp
char **

variable_types: cur int

variable_types: lim int

variable_types: chr int


getrange

decompiled_code:
char *__fastcall getrange(char *a1, int *a2, unsigned int a3, unsigned int a4)
{
char *result; // rax
int v7; // er13
int v8; // er8
int v9; // eax
char *v10[6]; // [rsp+8h] [rbp-30h] BYREF

v10[0] = a1;
if ( (unsigned int)number(v10, a3, a4) )
{
result = v10[0];
v7 = curv;
if ( *v10[0] == 44 )
{
++v10[0];
v8 = number(v10, a3, a4);
result = 0LL;
if ( v8 )
{
v9 = curv;
*a2 = v7;
a2[1] = v9;
result = v10[0];
}
}
else
{
*a2 = curv;
a2[1] = v7;
}
}
else
{
result = v10[0];
if ( *v10[0] == 37 )
{
a2[1] = a4;
++result;
*a2 = 1;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, int *a2, unsigned int a3, unsigned int a4)
{
char *result; // rax
int v7; // er13
int v8; // er8
int v9; // eax
char *v10[6]; // [rsp+8h] [rbp-30h] BYREF

v10[0] = a1;
if ( (unsigned int)func0(v10, a3, a4) )
{
result = v10[0];
v7 = curv;
if ( *v10[0] == 44 )
{
++v10[0];
v8 = func0(v10, a3, a4);
result = 0LL;
if ( v8 )
{
v9 = curv;
*a2 = v7;
a2[1] = v9;
result = v10[0];
}
}
else
{
*a2 = curv;
a2[1] = v7;
}
}
else
{
result = v10[0];
if ( *v10[0] == 37 )
{
a2[1] = a4;
++result;
*a2 = 1;
}
}
return result;
}

original_code:
static char *getrange(char *s, struct range *r, int cur, int lim)
{
 if(number(&s, cur, lim)){
  int start = curv;
  if(*s == ','){
   ++s;
   if(number(&s, cur, lim)){
    r->start = start;
    r->end = curv;
    return s;
   }else
    return ((void *)0);
  }else{
   r->start = start;
   r->end = start;
   return s;
  }
 }else if(*s == '%'){
  r->start = 1;
  r->end = lim;
  return s + 1;
 }else
  return s;
}

variable_types:
r
struct range { int start; } *

variable_types: start int

return_type: char *


parserange

decompiled_code:
char *__fastcall parserange(char *a1, int *a2, unsigned int *a3)
{
char *result; // rax
int v6; // edx
signed int v7; // esi
int v8; // ecx

result = getrange(a1, a2, *a3, a3[1]);
if ( a1 < result )
{
v6 = *a2;
if ( *a2 <= 0 || (v7 = a3[1], v6 > v7) || (v8 = a2[1], v8 <= 0) || v7 < v8 )
{
*_errno_location() = 22;
result = 0LL;
}
else if ( v6 > v8 )
{
*_errno_location() = 34;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, int *a2, unsigned int *a3)
{
char *result; // rax
int v6; // edx
signed int v7; // esi
int v8; // ecx

result = func1(a1, a2, *a3, a3[1]);
if ( a1 < result )
{
v6 = *a2;
if ( *a2 <= 0 || (v7 = a3[1], v6 > v7) || (v8 = a2[1], v8 <= 0) || v7 < v8 )
{
*_errno_location() = 22;
result = 0LL;
}
else if ( v6 > v8 )
{
*_errno_location() = 34;
result = 0LL;
}
}
return result;
}

original_code:
char *parserange(char *in, struct range *rng, struct range *lim)
{
 char *s = getrange(in, rng, lim->start, lim->end);
 if(s > in){
  if(rng->start < 1 || rng->start > lim->end ||
    rng->end < 1 || rng->end > lim->end){
   (*__errno_location ()) = 22;
   return ((void *)0);
  }else if(rng->start > rng->end){
   (*__errno_location ()) = 34;
   return ((void *)0);
  }
 }
 return s;
}

variable_types:
in
char *

variable_types:
rng
struct range { int start; } *

variable_types:
lim
struct range *


decompiled_code:
_QWORD *vars_default()
{
_QWORD *result; // rax
_DWORD *v1; // rdx
int v2; // ecx

result = &unk_530;
while ( 1 )
{
result += 5;
if ( result == (_QWORD *)&unk_8A0 )
break;
while ( 1 )
{
v1 = (_DWORD *)result[2];
if ( !v1 )
break;
v2 = *(_DWORD *)result;
result += 5;
*v1 = v2;
if ( result == (_QWORD *)&unk_8A0 )
return result;
}
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax
_DWORD *v1; // rdx
int v2; // ecx

result = &unk_530;
while ( 1 )
{
result += 5;
if ( result == (_QWORD *)&unk_8A0 )
break;
while ( 1 )
{
v1 = (_DWORD *)result[2];
if ( !v1 )
break;
v2 = *(_DWORD *)result;
result += 5;
*v1 = v2;
if ( result == (_QWORD *)&unk_8A0 )
return result;
}
}
return result;
}

original_code:
void vars_default()
{
 unsigned int i;
 for(i = 0; i < ((sizeof(vars) / sizeof(vars[0]))); i++)
  if(vars[i].val)
   *vars[i].val = vars[i].default_val;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall vars_isbool(int a1)
{
return (unsigned int)dword_534[10 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)dword_534[10 * a1];
}

original_code:
int vars_isbool(enum vartype t)
{
 return vars[t].isbool;
}

variable_types: enum vartype { VARS_READONLY=0, VARS_MODIFIED=1, VARS_EOL=2, VARS_CRLF=3, VARS_TABSTOP=4, VARS_SHOWTABS=5, VARS_LIST=6, VARS_SCROLLOFF=7, VARS_TEXTWIDTH=8, VARS_TAB_CONTEXT=9, VARS_ICASE=10, VARS_SCASE=11, VARS_HIGHLIGHT=12, VARS_SYNTAX=13, VARS_AUTOINDENT=14, VARS_CINDENT=15, VARS_FUNC_MOTION_VI=16, VARS_EXPANDTAB=17, VARS_INTELLI=18, VARS_FSYNC=19, VARS_ESCTRIM=20, VARS_UVI_INFO=21, VARS_UNKNOWN=22 }


decompiled_code:
_BOOL8 __fastcall vars_isbuffervar(unsigned int a1)
{
return qword_540[5 * a1] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned int a1)
{
return qword_540[5 * a1] == 0;
}

original_code:
int vars_isbuffervar(enum vartype t)
{
 return !vars[t].val;
}

user_defined_types: enum vartype { VARS_READONLY=0, VARS_MODIFIED=1, VARS_EOL=2, VARS_CRLF=3, VARS_TABSTOP=4, VARS_SHOWTABS=5, VARS_LIST=6, VARS_SCROLLOFF=7, VARS_TEXTWIDTH=8, VARS_TAB_CONTEXT=9, VARS_ICASE=10, VARS_SCASE=11, VARS_HIGHLIGHT=12, VARS_SYNTAX=13, VARS_AUTOINDENT=14, VARS_CINDENT=15, VARS_FUNC_MOTION_VI=16, VARS_EXPANDTAB=17, VARS_INTELLI=18, VARS_FSYNC=19, VARS_ESCTRIM=20, VARS_UVI_INFO=21, VARS_UNKNOWN=22 }


decompiled_code:
__int64 __fastcall vars_settingget(unsigned int a1)
{
return qword_540[5 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return qword_540[5 * a1];
}

original_code:
int *vars_settingget(enum vartype t)
{
 return vars[t].val;
}

return_type: int *


decompiled_code:
__int64 __fastcall vars_tostring(unsigned int a1)
{
return (__int64)*(&vars + 5 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
return (__int64)*(&vars + 5 * a1);
}

original_code:
const char *vars_tostring(enum vartype t)
{
 return vars[t].nam;
}


decompiled_code:
__int64 __fastcall vars_gettype(char *s2)
{
unsigned int v1; // er12
const char *v3; // rdi
const char **i; // rbx

v1 = 0;
v3 = (const char *)&unk_2B7;
for ( i = (const char **)off_548; !v3 || strcmp(v3, s2); i += 5 )
{
if ( ++v1 == 22 )
break;
v3 = *i;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
unsigned int v1; // er12
const char *v3; // rdi
const char **i; // rbx

v1 = 0;
v3 = (const char *)&unk_2B7;
for ( i = (const char **)off_548; !v3 || strcmp(v3, s2); i += 5 )
{
if ( ++v1 == 22 )
break;
v3 = *i;
}
return v1;
}

original_code:
enum vartype vars_gettype(const char *s)
{
 unsigned int i;
 for(i = 0; i < ((sizeof(vars) / sizeof(vars[0]))); i++)
  if(vars[i].nam && !strcmp(vars[i].nam, s))
   return i;
 return VARS_UNKNOWN;
}

canonical_original_code:
enum vartype vars_gettype(char *s)
{
 unsigned int i;
 for(i = 0; i < ((sizeof(vars) / sizeof(vars[0]))); i++)
  if(vars[i].nam && !strcmp(vars[i].nam, s))
   return i;
 return VARS_UNKNOWN;
}

variable_types:
s
char *

return_type: enum vartype { VARS_READONLY=0, VARS_MODIFIED=1, VARS_EOL=2, VARS_CRLF=3, VARS_TABSTOP=4, VARS_SHOWTABS=5, VARS_LIST=6, VARS_SCROLLOFF=7, VARS_TEXTWIDTH=8, VARS_TAB_CONTEXT=9, VARS_ICASE=10, VARS_SCASE=11, VARS_HIGHLIGHT=12, VARS_SYNTAX=13, VARS_AUTOINDENT=14, VARS_CINDENT=15, VARS_FUNC_MOTION_VI=16, VARS_EXPANDTAB=17, VARS_INTELLI=18, VARS_FSYNC=19, VARS_ESCTRIM=20, VARS_UVI_INFO=21, VARS_UNKNOWN=22 }


decompiled_code:
__int64 __fastcall vars_show(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v8; // r12
int v9; // edx
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // r9
void *v13; // rdi
__int64 result; // rax
__int64 v15; // rax
unsigned int v16; // eax
const char *v17; // rdx
char s[32]; // [rsp+8h] [rbp-20h] BYREF

vars_isbool(a1);
v8 = vars_tostring(a1);
if ( v9 )
{
v10 = buffers_current();
v13 = &unk_2BA;
if ( !(unsigned int)vars_get(a1, v10) )
v13 = &unk_2BB;
result = gui_status_add_col(v13, 64LL, v11, 0LL, 0LL, v12, a7);
}
else
{
v15 = buffers_current();
v16 = vars_get(a1, v15);
snprintf(s, 8uLL, v17, v16);
result = gui_status_add_col(v8, 4LL, &unk_2C1, 0LL, s, 16LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v8; // r12
int v9; // edx
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // r9
void *v13; // rdi
__int64 result; // rax
__int64 v15; // rax
unsigned int v16; // eax
const char *v17; // rdx
char s[32]; // [rsp+8h] [rbp-20h] BYREF

func1(a1);
v8 = func6(a1);
if ( v9 )
{
v10 = buffers_current();
v13 = &unk_2BA;
if ( !(unsigned int)func4(a1, v10) )
v13 = &unk_2BB;
result = gui_status_add_col(v13, 64LL, v11, 0LL, 0LL, v12, a7);
}
else
{
v15 = buffers_current();
v16 = func4(a1, v15);
snprintf(s, 8uLL, v17, v16);
result = gui_status_add_col(v8, 4LL, &unk_2C1, 0LL, s, 16LL, 0LL);
}
return result;
}

original_code:
void vars_show(enum vartype t)
{
 if(vars_isbool(t)){
  gui_status_add_col(vars_get(t, buffers_current()) ? "" : "no", GUI_COL_RED, vars_tostring(t), GUI_NONE, ((void *)0));
 }else{
  char buf[8];
  snprintf(buf, sizeof buf, "%d", vars_get(t, buffers_current()));
  gui_status_add_col(vars_tostring(t), GUI_COL_BLUE, "=", GUI_NONE, buf, GUI_COL_GREEN, ((void *)0));
 }
}

variable_types:
buf
char [8]


decompiled_code:
__int64 __fastcall vars_help(unsigned int a1)
{
const char *v1; // rbx
const char *v2; // rbp
int v3; // er8
const char *v4; // r8
size_t v5; // rax
const char *v6; // rdx

v1 = "bool";
v2 = (const char *)vars_tostring(a1);
if ( !(unsigned int)vars_isbool(v3) )
v1 = v4;
v5 = strlen(v2);
v6 = ":\t";
if ( v5 <= 6 )
v6 = ":\t\t";
return gui_status_add_col(v2, 64LL, v6, 0LL, v1, 4LL, ":\t");
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
const char *v1; // rbx
const char *v2; // rbp
int v3; // er8
const char *v4; // r8
size_t v5; // rax
const char *v6; // rdx

v1 = "bool";
v2 = (const char *)func6(a1);
if ( !(unsigned int)func1(v3) )
v1 = v4;
v5 = strlen(v2);
v6 = ":\t";
if ( v5 <= 6 )
v6 = ":\t\t";
return gui_status_add_col(v2, 64LL, v6, 0LL, v1, 4LL, ":\t");
}

original_code:
void vars_help(enum vartype t)
{
 const char *s = vars_tostring(t);
 gui_status_add_col(
  s, GUI_COL_RED,
  strlen(s) > 6 ? ":\t" : ":\t\t", GUI_NONE,
  vars_isbool(t) ? "bool" : "int", GUI_COL_BLUE,
  ":\t", GUI_NONE,
  vars[t].help, GUI_NONE,
  ((void *)0));
}

canonical_original_code:
void vars_help(enum vartype t)
{
 char *s = vars_tostring(t);
 gui_status_add_col(
  s, GUI_COL_RED,
  strlen(s) > 6 ? ":\t" : ":\t\t", GUI_NONE,
  vars_isbool(t) ? "bool" : "int", GUI_COL_BLUE,
  ":\t", GUI_NONE,
  vars[t].help, GUI_NONE,
  ((void *)0));
}


decompiled_code:
__int64 go_file()
{
__int64 v0; // rax
void *v1; // rbp
__int64 result; // rax

v0 = gui_current_fname();
if ( v0 )
{
v1 = (void *)v0;
buffers_load(v0);
free(v1);
result = 0LL;
}
else
{
gui_status(1LL, "no file selected");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
void *v1; // rbp
__int64 result; // rax

v0 = gui_current_fname();
if ( v0 )
{
v1 = (void *)v0;
buffers_load(v0);
free(v1);
result = 0LL;
}
else
{
gui_status(1LL, "no file selected");
result = 1LL;
}
return result;
}

original_code:
int go_file()
{
 char *fname = gui_current_fname();
 if(fname){
  buffers_load(fname);
  free(fname);
  return 0;
 }else{
  gui_status(GUI_ERR, "no file selected");
  return 1;
 }
}

variable_types:
fname
char *


decompiled_code:
__int64 fmt_motion()
{
int v0; // er8
__int64 result; // rax
_BYTE v2[4]; // [rsp+0h] [rbp-18h] BYREF
char v3[4]; // [rsp+4h] [rbp-14h] BYREF
char v4[4]; // [rsp+8h] [rbp-10h] BYREF
char v5[12]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = motion_wrap(v4, v2, v5, v3, &unk_22F, 0LL);
result = 1LL;
if ( !v0 )
{
*(_DWORD *)(buffers_current() + 20) = 1;
result = range_through_pipe(v2, "fmt -80");
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er8
__int64 result; // rax
_BYTE v2[4]; // [rsp+0h] [rbp-18h] BYREF
char v3[4]; // [rsp+4h] [rbp-14h] BYREF
char v4[4]; // [rsp+8h] [rbp-10h] BYREF
char v5[12]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = motion_wrap(v4, v2, v5, v3, &unk_22F, 0LL);
result = 1LL;
if ( !v0 )
{
*(_DWORD *)(buffers_current() + 20) = 1;
result = range_through_pipe(v2, "fmt -80");
}
return result;
}

original_code:
int fmt_motion()
{
 struct range rng;
 int x[2];
 if(motion_wrap(&x[0], &rng.start, &x[1], &rng.end, "", 0))
  return 1;
 ((buffers_current())->modified) = 1;
 return range_through_pipe(&rng, "fmt -80");
}

variable_types:
rng
struct range { int start; }

variable_types:
x
int [2]


tilde

decompiled_code:
__int64 __fastcall tilde(unsigned int a1)
{
__int64 v1; // r12
unsigned int v2; // ebp
_QWORD *v3; // rax
__int64 v4; // rbp
char *v5; // rbp
int v6; // ebx
unsigned int v7; // eax
__int64 v8; // rsi
char *v9; // r12
const unsigned __int16 **v10; // r13
char v11; // al
__int64 result; // rax

v1 = a1;
v2 = gui_y();
v3 = (_QWORD *)buffers_current();
v4 = *(_QWORD *)list_getindex(*v3, v2);
v5 = (char *)((int)gui_x() + v4);
if ( !a1 )
v1 = 1LL;
v6 = gui_x();
v7 = gui_y();
v8 = (unsigned int)(v6 + v1);
v9 = &v5[v1];
gui_move(v7, v8);
v10 = _ctype_b_loc();
v11 = *v5;
do
{
if ( ((*v10)[v11] & 0x200) != 0 )
{
*v5++ = (*_ctype_toupper_loc())[v11];
v11 = *v5;
if ( !*v5 )
break;
continue;
}
*v5++ = (*_ctype_tolower_loc())[v11];
v11 = *v5;
if ( !*v5 )
break;
}
while ( v5 != v9 );
result = buffers_current();
*(_DWORD *)(result + 20) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v1; // r12
unsigned int v2; // ebp
_QWORD *v3; // rax
__int64 v4; // rbp
char *v5; // rbp
int v6; // ebx
unsigned int v7; // eax
__int64 v8; // rsi
char *v9; // r12
const unsigned __int16 **v10; // r13
char v11; // al
__int64 result; // rax

v1 = a1;
v2 = gui_y();
v3 = (_QWORD *)buffers_current();
v4 = *(_QWORD *)list_getindex(*v3, v2);
v5 = (char *)((int)gui_x() + v4);
if ( !a1 )
v1 = 1LL;
v6 = gui_x();
v7 = gui_y();
v8 = (unsigned int)(v6 + v1);
v9 = &v5[v1];
gui_move(v7, v8);
v10 = _ctype_b_loc();
v11 = *v5;
do
{
if ( ((*v10)[v11] & 0x200) != 0 )
{
*v5++ = (*_ctype_toupper_loc())[v11];
v11 = *v5;
if ( !*v5 )
break;
continue;
}
*v5++ = (*_ctype_tolower_loc())[v11];
v11 = *v5;
if ( !*v5 )
break;
}
while ( v5 != v9 );
result = buffers_current();
*(_DWORD *)(result + 20) = 1;
return result;
}

original_code:
void tilde(unsigned int rep)
{
 char *data = (char *)list_getindex ( ((buffers_current())->lines), gui_y())->data;
 char *pos = data + gui_x();
 if(!rep)
  rep = 1;
 gui_move(gui_y(), gui_x() + rep);
 while(rep --> 0){
  if(((*__ctype_b_loc ())[(int) ((*pos))] & (unsigned short int) _ISlower))
   *pos = toupper(*pos);
  else
   *pos = tolower(*pos);
  if(!*++pos)
   break;
 }
 ((buffers_current())->modified) = 1;
}

canonical_original_code:
void tilde(unsigned int rep)
{
 char *data = (char *)list_getindex ( ((buffers_current())->lines), gui_y())->data;
 char *pos = data + gui_x();
 if(!rep)
  rep = 1;
 gui_move(gui_y(), gui_x() + rep);
 while(rep --> 0){
  if(((*__ctype_b_loc ())[(int) ((*pos))] & (unsigned short) _ISlower))
   *pos = toupper(*pos);
  else
   *pos = tolower(*pos);
  if(!*++pos)
   break;
 }
 ((buffers_current())->modified) = 1;
}

variable_types:
rep
unsigned int

variable_types:
data
char *

variable_types:
pos
char *


showgirl

decompiled_code:
void __fastcall showgirl(unsigned int a1)
{
const char *v1; // rax
char *v2; // rbp
size_t v3; // r12
char *v4; // rax
char *v5; // r14

v1 = (const char *)gui_current_word();
if ( v1 )
{
v2 = (char *)v1;
v3 = (int)(strlen(v1) + 16);
v4 = (char *)umalloc(v3);
v5 = v4;
if ( a1 )
snprintf(v4, v3, "man %d %s", a1, v2);
else
snprintf(v4, v3, "man %s", v2);
shellout(v5, 0LL);
free(v5);
free(v2);
}
else
{
gui_status(1LL, "invalid word");
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned int a1)
{
const char *v1; // rax
char *v2; // rbp
size_t v3; // r12
char *v4; // rax
char *v5; // r14

v1 = (const char *)gui_current_word();
if ( v1 )
{
v2 = (char *)v1;
v3 = (int)(strlen(v1) + 16);
v4 = (char *)umalloc(v3);
v5 = v4;
if ( a1 )
snprintf(v4, v3, "man %d %s", a1, v2);
else
snprintf(v4, v3, "man %s", v2);
shellout(v5, 0LL);
free(v5);
free(v2);
}
else
{
gui_status(1LL, "invalid word");
}
}

original_code:
void showgirl(unsigned int page)
{
 char *word = gui_current_word();
 char *buf;
 int len;
 if(!word){
  gui_status(GUI_ERR, "invalid word");
  return;
 }
 buf = umalloc(len = strlen(word) + 16);
 if(page)
  snprintf(buf, len, "man %d %s", page, word);
 else
  snprintf(buf, len, "man %s", word);
 shellout(buf, ((void *)0));
 free(buf);
 free(word);
}

variable_types:
page
unsigned int

variable_types:
word
char *

variable_types:
buf
char *

variable_types: len int


decompiled_code:
__int64 __fastcall usearch_err(__int64 a1)
{
int v2; // eax
void *v3; // rdi
int v4; // er12
char *v5; // rax
int v6; // edi
const regex_t *v7; // rsi

v2 = regerror(*(_DWORD *)(a1 + 8), *(const regex_t **)a1, 0LL, 0LL);
v3 = *(void **)(a1 + 16);
v4 = v2;
if ( v3 )
free(v3);
v5 = (char *)umalloc(v4);
v6 = *(_DWORD *)(a1 + 8);
v7 = *(const regex_t **)a1;
*(_QWORD *)(a1 + 16) = v5;
regerror(v6, v7, v5, v4);
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v2; // eax
void *v3; // rdi
int v4; // er12
char *v5; // rax
int v6; // edi
const regex_t *v7; // rsi

v2 = regerror(*(_DWORD *)(a1 + 8), *(const regex_t **)a1, 0LL, 0LL);
v3 = *(void **)(a1 + 16);
v4 = v2;
if ( v3 )
free(v3);
v5 = (char *)umalloc(v4);
v6 = *(_DWORD *)(a1 + 8);
v7 = *(const regex_t **)a1;
*(_QWORD *)(a1 + 16) = v5;
regerror(v6, v7, v5, v4);
return *(_QWORD *)(a1 + 16);
}

original_code:
const char *usearch_err(struct usearch *us)
{
 int len;
 len = regerror(us->lastret, us->reg, ((void *)0), 0);
 if(us->ebuf)
  free(us->ebuf);
 us->ebuf = umalloc(len);
 regerror(us->lastret, us->reg, us->ebuf, len);
 return us->ebuf;
}

variable_types: struct usearch { void *reg; int lastret; char *ebuf; char *term; int first_match_len; } *


usearch

decompiled_code:
__int64 __fastcall usearch(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
int v4; // edx
__int64 result; // rax
__int64 v6; // rax
regmatch_t v7; // [rsp+8h] [rbp-20h] BYREF

v3 = a3;
v4 = regexec(*(const regex_t **)a1, (const char *)(a3 + a2), 1uLL, &v7, 0);
*(_DWORD *)(a1 + 8) = v4;
result = 0LL;
if ( !v4 )
{
v6 = v3 + v7.rm_so;
*(_DWORD *)(a1 + 32) = v7.rm_eo - v7.rm_so;
result = a2 + v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
int v4; // edx
__int64 result; // rax
__int64 v6; // rax
regmatch_t v7; // [rsp+8h] [rbp-20h] BYREF

v3 = a3;
v4 = regexec(*(const regex_t **)a1, (const char *)(a3 + a2), 1uLL, &v7, 0);
*(_DWORD *)(a1 + 8) = v4;
result = 0LL;
if ( !v4 )
{
v6 = v3 + v7.rm_so;
*(_DWORD *)(a1 + 32) = v7.rm_eo - v7.rm_so;
result = a2 + v6;
}
return result;
}

original_code:
const char *usearch(struct usearch *us, const char *parliment, int offset)
{
 regmatch_t match;
 if((us->lastret = regexec(us->reg, parliment + offset, 1 , &match, 0))){
  return ((void *)0);
 }else{
  us->first_match_len = match.rm_eo - match.rm_so;
  return parliment + offset + match.rm_so;
 }
}

canonical_original_code:
char *usearch(struct usearch *us, char *parliment, int offset)
{
 struct regmatch_t match;
 if((us->lastret = regexec(us->reg, parliment + offset, 1 , &match, 0))){
  return ((void *)0);
 }else{
  us->first_match_len = match.rm_eo - match.rm_so;
  return parliment + offset + match.rm_so;
 }
}

variable_types:
parliment
char *

variable_types: offset int

variable_types: struct regmatch_t { int rm_so; int rm_eo; }

user_defined_types: struct usearch { void *reg; int lastret; char *ebuf; char *term; int first_match_len; }


decompiled_code:
const char *__fastcall usearch_rev(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax
char *v5; // rbp
int v6; // eax
int v7; // ecx
int v8; // er13
int v9; // er14
__int64 v10; // r12
int v11; // er15
__int64 v12; // rax

v4 = strlen(a2);
v5 = (char *)umalloc(v4 + 2);
strcpy(v5, a2);
v5[a3 + 1] = 0;
v6 = strlen(*(const char **)(a1 + 24));
v7 = 0;
if ( a3 >= 0 )
v7 = a3;
v8 = v6;
v9 = v6 + 1;
v10 = 0LL;
v11 = v7 >> 1;
while ( 1 )
{
if ( v11 >= (int)strlen(v5) )
{
LABEL_7:
free(v5);
return 0LL;
}
while ( 1 )
{
v12 = usearch(a1, (__int64)&v5[v11], 0);
if ( !v12 )
break;
v11 += v8;
v10 = v12;
if ( v11 >= (int)strlen(v5) )
goto LABEL_7;
}
if ( v10 )
break;
if ( v11 <= 0 )
goto LABEL_7;
v11 -= v9;
if ( v11 < 0 )
v11 = 0;
}
free(v5);
return &a2[(int)v10 - (int)v5];
}

original_code:
const char *usearch_rev(struct usearch *us, const char *parliment, int offset)
{
 const char *ret, *lastmatch;
 char *dup;
 int curoffset, term_len;
 dup = umalloc(strlen(parliment) + 2);
 strcpy(dup, parliment);
 dup[offset + 1] = '\0';
 lastmatch = ((void *)0);
 term_len = strlen(us->term);
 if(offset < 0) offset = 0;
 curoffset = offset / 2;
 for(; curoffset < (signed)strlen(dup);){
  if((ret = usearch(us, dup + curoffset, 0))){
   lastmatch = ret;
   curoffset += term_len;
  }else if(lastmatch){
   int o = lastmatch - dup;
   free(dup);
   return parliment + o;
  }else{
   if(curoffset <= 0)
    break;
   curoffset -= term_len + 1;
   if(curoffset < 0) curoffset = 0;
  }
 }
 free(dup);
 return ((void *)0);
}

canonical_original_code:
char *usearch_rev(struct usearch *us, char *parliment, int offset)
{
 char *ret; char *lastmatch;
 char *dup;
 int curoffset; int term_len;
 dup = umalloc(strlen(parliment) + 2);
 strcpy(dup, parliment);
 dup[offset + 1] = '\0';
 lastmatch = ((void *)0);
 term_len = strlen(us->term);
 if(offset < 0) offset = 0;
 curoffset = offset / 2;
 for(; curoffset < (int)strlen(dup);){
  if((ret = usearch(us, dup + curoffset, 0))){
   lastmatch = ret;
   curoffset += term_len;
  }else if(lastmatch){
   int o = lastmatch - dup;
   free(dup);
   return parliment + o;
  }else{
   if(curoffset <= 0)
    break;
   curoffset -= term_len + 1;
   if(curoffset < 0) curoffset = 0;
  }
 }
 free(dup);
 return ((void *)0);
}

variable_types:
ret
char *

variable_types:
lastmatch
char *

variable_types:
dup
char *

variable_types: curoffset int

variable_types: o int


sigh

decompiled_code:
void __fastcall __noreturn sigh(unsigned int a1)
{
__int64 v1; // rax

gui_term();
v1 = buffers_current();
preserve(v1);
fprintf(stderr, "We get signal %d\n", a1);
exit(a1 + 128);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
__int64 v1; // rax

gui_term();
v1 = buffers_current();
preserve(v1);
fprintf(stderr, "We get signal %d\n", a1);
exit(a1 + 128);
}

original_code:
void sigh(const int sig)
{
 gui_term();
 preserve(buffers_current());
 fprintf(stderr, "We get signal %d\n", sig);
 exit(sig + 128);
}

canonical_original_code:
void sigh(int sig)
{
 gui_term();
 preserve(buffers_current());
 fprintf(stderr, "We get signal %d\n", sig);
 exit(sig + 128);
}

variable_types: sig int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s [-R] [--] [filename]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "Usage: %s [-R] [--] [filename]\n", a1);
exit(1);
}

original_code:
void usage(const char *s)
{
 fprintf(stderr, "Usage: %s [-R] [--] [filename]\n", s);
 exit(1);
}

canonical_original_code:
void usage(char *s)
{
 fprintf(stderr, "Usage: %s [-R] [--] [filename]\n", s);
 exit(1);
}

variable_types:
s
char *


die

decompiled_code:
void __noreturn die(char *format, ...)
{
__int64 v1; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
gui_term();
v1 = buffers_current();
preserve(v1);
fwrite("uvi: dying: ", 1uLL, 0xCuLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
abort();
}

canonical_decompiled_code:
void __noreturn func2(char *format, ...)
{
__int64 v1; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
gui_term();
v1 = buffers_current();
preserve(v1);
fwrite("uvi: dying: ", 1uLL, 0xCuLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
abort();
}

original_code:
void die(const char *fmt, ...)
{
 va_list l;
 gui_term();
 preserve(buffers_current());
 fprintf(stderr, "uvi: dying: ");
 __builtin_va_start(l,fmt);
 vfprintf(stderr, fmt, l);
 __builtin_va_end(l);
 fputc('\n', stderr);
 abort();
}

canonical_original_code:
void die(char *fmt, ...)
{
 __builtin_va_list l;
 gui_term();
 preserve(buffers_current());
 fprintf(stderr, "uvi: dying: ");
 __builtin_va_start(l,fmt);
 vfprintf(stderr, fmt, l);
 __builtin_va_end(l);
 fputc('\n', stderr);
 abort();
}

variable_types:
fmt
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbp
__int64 v5; // r15
__int64 v6; // rax
const char *v7; // rdi
int v8; // er12
bool v9; // zf
const char *v10; // rax
__int64 v11; // r12
char v12; // al
_QWORD *i; // r13
char *s1; // [rsp+0h] [rbp-48h]
unsigned int v16; // [rsp+8h] [rbp-40h]
int v17; // [rsp+Ch] [rbp-3Ch]

v4 = list_new(0LL, argv, envp);
v17 = 0;
if ( !setlocale(6, &locale) )
{
fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
v17 = 1;
}
signal(1, (__sighandler_t)sigh);
signal(2, (__sighandler_t)sigh);
signal(15, (__sighandler_t)sigh);
signal(3, (__sighandler_t)sigh);
if ( argc <= 1 )
{
v16 = 0;
v8 = argc;
goto LABEL_16;
}
v16 = 0;
v5 = 1LL;
while ( 1 )
{
while ( 1 )
{
v7 = argv[v5];
v8 = v5;
if ( *v7 == 45 )
break;
if ( *v7 != 43 )
goto LABEL_16;
v9 = (unsigned int)str_numeric(v7 + 1) == 0;
v10 = argv[v5];
if ( !v9 )
{
v6 = ustrprintf("%sG", v10 + 1);
list_append(v4, v6);
goto LABEL_6;
}
++v5;
v11 = ustrdup(v10 + 1);
str_escape(v11);
list_append(v4, v11);
if ( argc == v5 )
{
LABEL_11:
v8 = argc;
goto LABEL_16;
}
}
s1 = (char *)argv[v5];
if ( strlen(v7) != 2 )
break;
v12 = s1[1];
if ( v12 == 45 )
{
v8 = v5 + 1;
if ( (int)v5 + 1 > argc )
v8 = argc;
goto LABEL_16;
}
if ( v12 != 82 )
{
fprintf(stderr, "unknown option: \"%s\"\n", s1);
LABEL_33:
usage(*argv);
}
v16 = 1;
LABEL_6:
if ( argc == ++v5 )
goto LABEL_11;
}
if ( strcmp(s1, "-") )
{
fprintf(stderr, "invalid option: \"%s\"\n", s1);
goto LABEL_33;
}
LABEL_16:
if ( (int)list_count(v4) > 0 )
{
for ( i = (_QWORD *)list_gettail(v4); i; i = (_QWORD *)i[2] )
gui_queue(*i);
}
list_free(v4, &free);
if ( !isatty(0) )
{
fwrite("uvi: warning: input is not a terminal\n", 1uLL, 0x26uLL, stderr);
if ( isatty(1) )
goto LABEL_25;
LABEL_24:
fwrite("uvi: warning: output is not a terminal\n", 1uLL, 0x27uLL, stderr);
goto LABEL_25;
}
if ( !isatty(1) )
goto LABEL_24;
if ( v17 )
LABEL_25:
sleep(1u);
vars_default();
map_init();
gui_init();
gui_term();
rc_read();
info_read();
buffers_init((unsigned int)(argc - v8), &argv[v8], v16);
gui_reload();
gui_run();
gui_term();
info_write();
map_term();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbp
__int64 v5; // r15
__int64 v6; // rax
const char *v7; // rdi
int v8; // er12
bool v9; // zf
const char *v10; // rax
__int64 v11; // r12
char v12; // al
_QWORD *i; // r13
char *s1; // [rsp+0h] [rbp-48h]
unsigned int v16; // [rsp+8h] [rbp-40h]
int v17; // [rsp+Ch] [rbp-3Ch]

v4 = list_new(0LL, argv, envp);
v17 = 0;
if ( !setlocale(6, &locale) )
{
fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
v17 = 1;
}
signal(1, (__sighandler_t)sigh);
signal(2, (__sighandler_t)sigh);
signal(15, (__sighandler_t)sigh);
signal(3, (__sighandler_t)sigh);
if ( argc <= 1 )
{
v16 = 0;
v8 = argc;
goto LABEL_16;
}
v16 = 0;
v5 = 1LL;
while ( 1 )
{
while ( 1 )
{
v7 = argv[v5];
v8 = v5;
if ( *v7 == 45 )
break;
if ( *v7 != 43 )
goto LABEL_16;
v9 = (unsigned int)str_numeric(v7 + 1) == 0;
v10 = argv[v5];
if ( !v9 )
{
v6 = ustrprintf("%sG", v10 + 1);
list_append(v4, v6);
goto LABEL_6;
}
++v5;
v11 = ustrdup(v10 + 1);
str_escape(v11);
list_append(v4, v11);
if ( argc == v5 )
{
LABEL_11:
v8 = argc;
goto LABEL_16;
}
}
s1 = (char *)argv[v5];
if ( strlen(v7) != 2 )
break;
v12 = s1[1];
if ( v12 == 45 )
{
v8 = v5 + 1;
if ( (int)v5 + 1 > argc )
v8 = argc;
goto LABEL_16;
}
if ( v12 != 82 )
{
fprintf(stderr, "unknown option: \"%s\"\n", s1);
LABEL_33:
func1(*argv);
}
v16 = 1;
LABEL_6:
if ( argc == ++v5 )
goto LABEL_11;
}
if ( strcmp(s1, "-") )
{
fprintf(stderr, "invalid option: \"%s\"\n", s1);
goto LABEL_33;
}
LABEL_16:
if ( (int)list_count(v4) > 0 )
{
for ( i = (_QWORD *)list_gettail(v4); i; i = (_QWORD *)i[2] )
gui_queue(*i);
}
list_free(v4, &free);
if ( !isatty(0) )
{
fwrite("uvi: warning: input is not a terminal\n", 1uLL, 0x26uLL, stderr);
if ( isatty(1) )
goto LABEL_25;
LABEL_24:
fwrite("uvi: warning: output is not a terminal\n", 1uLL, 0x27uLL, stderr);
goto LABEL_25;
}
if ( !isatty(1) )
goto LABEL_24;
if ( v17 )
LABEL_25:
sleep(1u);
vars_default();
map_init();
gui_init();
gui_term();
rc_read();
info_read();
buffers_init((unsigned int)(argc - v8), &argv[v8], v16);
gui_reload();
gui_run();
gui_term();
info_write();
map_term();
return 0;
}

original_code:
int main(int argc, const char **argv)
{
 struct list *cmds = list_new(((void *)0));
 int i, argv_options = 1;
 int argv_fname_start = argc;
 int ro = 0;
 int wait = 0;
 if(setlocale(6, "") == ((void *)0)){
  fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
  wait = 1;
 }
 signal(1, &sigh);
 signal(2, &sigh);
 signal(15, &sigh);
 signal(3, &sigh);
 for(i = 1; i < argc; i++)
  if(argv_options && *argv[i] == '-'){
   if(strlen(argv[i]) == 2){
    switch(argv[i][1]){
     case '-':
      argv_options = 0;
      break;
     case 'R':
      ro = 1;
      break;
     default:
      fprintf(stderr, "unknown option: \"%s\"\n", argv[i]);
      usage(*argv);
    }
   }else if(!strcmp(argv[i], "-")){
    argv_options = 0;
    goto at_fnames;
   }else{
    fprintf(stderr, "invalid option: \"%s\"\n", argv[i]);
    usage(*argv);
   }
  }else if(argv_options && *argv[i] == '+'){
   if(str_numeric(argv[i] + 1)){
    list_append(cmds, ustrprintf("%sG", argv[i] + 1));
   }else{
    char *s = ustrdup(argv[i] + 1);
    str_escape(s);
    list_append(cmds, s);
   }
  }else{
at_fnames:
   argv_fname_start = i;
   break;
  }
 if(list_count(cmds) > 0){
  struct list *l = list_gettail(cmds);
  while(l){
   gui_queue(l->data);
   l = l->prev;
  }
 }
 list_free(cmds, free);
 if(!isatty(0)){
  fputs("uvi: warning: input is not a terminal\n", stderr);
  wait = 1;
 }
 if(!isatty(1)){
  fputs("uvi: warning: output is not a terminal\n", stderr);
  wait = 1;
 }
 if(wait)
  sleep(1);
 vars_default();
 map_init();
 gui_init();
 gui_term();
 rc_read();
 info_read();
 buffers_init(
   argc - argv_fname_start,
   argv + argv_fname_start,
   ro);
 gui_reload();
 gui_run();
 gui_term();
 info_write();
 map_term();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct list *cmds = list_new(((void *)0));
 int i; int argv_options = 1;
 int argv_fname_start = argc;
 int ro = 0;
 int wait = 0;
 if(setlocale(6, "") == ((void *)0)){
  fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
  wait = 1;
 }
 signal(1, &sigh);
 signal(2, &sigh);
 signal(15, &sigh);
 signal(3, &sigh);
 for(i = 1; i < argc; i++)
  if(argv_options && *argv[i] == '-'){
   if(strlen(argv[i]) == 2){
    switch(argv[i][1]){
     case '-':
      argv_options = 0;
      break;
     case 'R':
      ro = 1;
      break;
     default:
      fprintf(stderr, "unknown option: \"%s\"\n", argv[i]);
      usage(*argv);
    }
   }else if(!strcmp(argv[i], "-")){
    argv_options = 0;
    goto at_fnames;
   }else{
    fprintf(stderr, "invalid option: \"%s\"\n", argv[i]);
    usage(*argv);
   }
  }else if(argv_options && *argv[i] == '+'){
   if(str_numeric(argv[i] + 1)){
    list_append(cmds, ustrprintf("%sG", argv[i] + 1));
   }else{
    char *s = ustrdup(argv[i] + 1);
    str_escape(s);
    list_append(cmds, s);
   }
  }else{
at_fnames:
   argv_fname_start = i;
   break;
  }
 if(list_count(cmds) > 0){
  struct list *l = list_gettail(cmds);
  while(l){
   gui_queue(l->data);
   l = l->prev;
  }
 }
 list_free(cmds, free);
 if(!isatty(0)){
  fputs("uvi: warning: input is not a terminal\n", stderr);
  wait = 1;
 }
 if(!isatty(1)){
  fputs("uvi: warning: output is not a terminal\n", stderr);
  wait = 1;
 }
 if(wait)
  sleep(1);
 vars_default();
 map_init();
 gui_init();
 gui_term();
 rc_read();
 info_read();
 buffers_init(
   argc - argv_fname_start,
   argv + argv_fname_start,
   ro);
 gui_reload();
 gui_run();
 gui_term();
 info_write();
 map_term();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct list { void *data; struct list *next; } *

variable_types: i int

variable_types: ro int

variable_types: wait int


decompiled_code:
int __fastcall term_canon(int fd, int a2)
{
int result; // eax
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v3);
if ( result != -1 )
{
if ( a2 )
{
v3.c_lflag |= 0xBu;
*(_WORD *)&v3.c_cc[5] = 0;
}
else
{
v3.c_lflag &= 0xFFFFFFF4;
*(_WORD *)&v3.c_cc[5] = 258;
}
result = tcsetattr(fd, 0, &v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int fd, int a2)
{
int result; // eax
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v3);
if ( result != -1 )
{
if ( a2 )
{
v3.c_lflag |= 0xBu;
*(_WORD *)&v3.c_cc[5] = 0;
}
else
{
v3.c_lflag &= 0xFFFFFFF4;
*(_WORD *)&v3.c_cc[5] = 258;
}
result = tcsetattr(fd, 0, &v3);
}
return result;
}

original_code:
void term_canon(int fd, int on)
{
 struct termios attr;
 if(tcgetattr(fd, &attr) == -1)
  return;
 if(on){
  attr.c_lflag |= (0000001|0000002|0000010);
  attr.c_cc[6] = 0;
  attr.c_cc[5] = 0;
 }else{
  attr.c_lflag &= ~(0000001|0000002|0000010);
  attr.c_cc[6] = 1;
  attr.c_cc[5] = 2;
 }
 tcsetattr(fd, 0, &attr);
}

variable_types: fd int

variable_types: on int

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


decompiled_code:
int __fastcall kill_a_node(void *ptr)
{
kill(*((_DWORD *)ptr + 2), 15);
pthread_cancel(*((_QWORD *)ptr + 26));
pthread_cancel(*((_QWORD *)ptr + 14));
pthread_join(*((_QWORD *)ptr + 26), 0LL);
pthread_join(*((_QWORD *)ptr + 14), 0LL);
close(*((_DWORD *)ptr + 18));
close(*((_DWORD *)ptr + 6));
close(*((_DWORD *)ptr + 30));
close((_DWORD)ptr + 172);
sleep(1u);
unlink((const char *)ptr + 28);
unlink((const char *)ptr + 76);
unlink((const char *)ptr + 124);
unlink((const char *)ptr + 172);
list_remove(&node_list, ptr);
free(ptr);
return printf("Node %d was terminated.\n", *((unsigned int *)ptr + 3));
}

canonical_decompiled_code:
int __fastcall func2(void *ptr)
{
kill(*((_DWORD *)ptr + 2), 15);
pthread_cancel(*((_QWORD *)ptr + 26));
pthread_cancel(*((_QWORD *)ptr + 14));
pthread_join(*((_QWORD *)ptr + 26), 0LL);
pthread_join(*((_QWORD *)ptr + 14), 0LL);
close(*((_DWORD *)ptr + 18));
close(*((_DWORD *)ptr + 6));
close(*((_DWORD *)ptr + 30));
close((_DWORD)ptr + 172);
sleep(1u);
unlink((const char *)ptr + 28);
unlink((const char *)ptr + 76);
unlink((const char *)ptr + 124);
unlink((const char *)ptr + 172);
list_remove(&node_list, ptr);
free(ptr);
return printf("Node %d was terminated.\n", *((unsigned int *)ptr + 3));
}

original_code:
void static kill_a_node(struct sim_node_t *nd)
{
 kill(nd->pid, 15);
 pthread_cancel(nd->cmd_out.thread);
 pthread_cancel(nd->data_out.thread);
 pthread_join(nd->cmd_out.thread, ((void *)0));
 pthread_join(nd->data_out.thread, ((void *)0));
 close(nd->data_out.pipe);
 close(nd->data_in.pipe);
 close(nd->cmd_in.pipe);
 close(nd->cmd_out.name);
 sleep(1);
 unlink(nd->data_in.name);
 unlink(nd->data_out.name);
 unlink(nd->cmd_in.name);
 unlink(nd->cmd_out.name);
 list_remove(&node_list, &nd->list);
 free(nd);
 printf("Node %d was terminated.\n", nd->index);
}

canonical_original_code:
static void kill_a_node(struct sim_node_t *nd)
{
 kill(nd->pid, 15);
 pthread_cancel(nd->cmd_out.thread);
 pthread_cancel(nd->data_out.thread);
 pthread_join(nd->cmd_out.thread, ((void *)0));
 pthread_join(nd->data_out.thread, ((void *)0));
 close(nd->data_out.pipe);
 close(nd->data_in.pipe);
 close(nd->cmd_in.pipe);
 close(nd->cmd_out.name);
 sleep(1);
 unlink(nd->data_in.name);
 unlink(nd->data_out.name);
 unlink(nd->cmd_in.name);
 unlink(nd->cmd_out.name);
 list_remove(&node_list, &nd->list);
 free(nd);
 printf("Node %d was terminated.\n", nd->index);
}

variable_types: struct sim_node_t { struct list_head { struct list_head *next; } list; int pid; int index; unsigned short addr; struct pipe_t { int pipe; char name[30]; unsigned long thread; } data_in; struct pipe_t data_out; struct pipe_t cmd_in; struct pipe_t cmd_out; unsigned char buf[128]; unsigned char cmdbuf[128]; } *

user_defined_types: struct sim_node_t { struct list_head list; int pid; int index; unsigned short addr; struct pipe_t data_in; struct pipe_t data_out; struct pipe_t cmd_in; struct pipe_t cmd_out; unsigned char buf[128]; unsigned char cmdbuf[128]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

INIT_LIST_HEAD_constprop_0();
atexit((void (*)(void))sim_kill_all_nodes);
signal(2, (__sighandler_t)sim_kill_all_nodes);
signal(17, (__sighandler_t)sigchld_handler);
mkdir("./log", 0x1FDu);
strcpy(v4, "./log/sim.txt");
freopen(v4, "w", stderr);
mkdir("./fifo", 0x1FDu);
strcpy(file, "./fifo/PUBLIC");
if ( mknod(file, 0x11B6u, 0LL) == -1 )
perror("mknod");
cli();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

func5();
atexit((void (*)(void))sim_kill_all_nodes);
signal(2, (__sighandler_t)sim_kill_all_nodes);
signal(17, (__sighandler_t)sigchld_handler);
mkdir("./log", 0x1FDu);
strcpy(v4, "./log/sim.txt");
freopen(v4, "w", stderr);
mkdir("./fifo", 0x1FDu);
strcpy(file, "./fifo/PUBLIC");
if ( mknod(file, 0x11B6u, 0LL) == -1 )
perror("mknod");
cli();
return 0;
}

variable_types:
argv
char *[]

variable_types:
msg
char [50]


decompiled_code:
__int64 __fastcall send_data(__int64 a1)
{
return sim_send_data(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return sim_send_data(a1, 0LL);
}

original_code:
void send_data(char *msg)
{
 sim_send_data(msg, 0);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall send_cmd(char *a1)
{
char *v1; // rbp
size_t v2; // r12
unsigned __int8 v3; // al

v1 = strtok(a1, " ");
v2 = (size_t)&a1[strlen(v1) + 1];
v3 = strtol(v1, 0LL, 10);
return sim_send_cmd(v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char *v1; // rbp
size_t v2; // r12
unsigned __int8 v3; // al

v1 = strtok(a1, " ");
v2 = (size_t)&a1[strlen(v1) + 1];
v3 = strtol(v1, 0LL, 10);
return sim_send_cmd(v2, v3);
}

original_code:
void send_cmd(char *str)
{
        U8 index;
        char *num, *msg;
        num = strtok(str, " ");
        msg = str + strlen(num) + 1;
        index = strtol(num, ((void *)0), 10);
        sim_send_cmd(msg, index);
}

canonical_original_code:
void send_cmd(char *str)
{
        unsigned char index;
        char *num; char *msg;
        num = strtok(str, " ");
        msg = str + strlen(num) + 1;
        index = strtol(num, ((void *)0), 10);
        sim_send_cmd(msg, index);
}

variable_types:
str
char *

variable_types:
index
unsigned char

variable_types:
num
char *


decompiled_code:
int __fastcall add_node(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_add_node(v2);
}

canonical_decompiled_code:
int __fastcall func2(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_add_node(v2);
}

original_code:
void add_node(char *str)
{
 U8 index;
 struct sim_node_t *nd;
 char *tmp;
 tmp = strtok(str, " ");
 if (!tmp)
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_add_node(index);
}

canonical_original_code:
void add_node(char *str)
{
 unsigned char index;
 struct sim_node_t *nd;
 char *tmp;
 tmp = strtok(str, " ");
 if (!tmp)
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_add_node(index);
}

variable_types:
tmp
char *

user_defined_types: struct list_head { struct list_head *next; }

user_defined_types: struct pipe_t { int pipe; char name[30]; unsigned long thread; }


decompiled_code:
int __fastcall kill_node(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_kill_nodes(v2);
}

canonical_decompiled_code:
int __fastcall func3(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_kill_nodes(v2);
}

original_code:
void kill_node(char *str)
{
 U8 index;
 char *tmp;
 tmp = strtok(str, " ");
 if (tmp == ((void *)0))
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_kill_nodes(index);
}

canonical_original_code:
void kill_node(char *str)
{
 unsigned char index;
 char *tmp;
 tmp = strtok(str, " ");
 if (tmp == ((void *)0))
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_kill_nodes(index);
}


decompiled_code:
// attributes: thunk
__int64 list_nodes()
{
return sim_list_print();
}

canonical_decompiled_code:
__int64 func4()
{
return sim_list_print();
}

original_code:
void list_nodes(char *str)
{
 sim_list_print();
}


decompiled_code:
void __noreturn quit_sim()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func5()
{
exit(0);
}

original_code:
void quit_sim(char *str)
{
 exit(0);
}

canonical_original_code:
void quit_sim(char *str)
{
 exit(0);
}


original_code:
void write_cli_buf(U8 *msg, U8 len)
{
 if (msg[0] == 0xff)
  memcpy(cli_buf.buf, &msg[1], len);
}

canonical_original_code:
void write_cli_buf(unsigned char *msg, unsigned char len)
{
 if (msg[0] == 0xff)
  memcpy(cli_buf.buf, &msg[1], len);
}

variable_types:
msg
unsigned char *

variable_types:
len
unsigned char


decompiled_code:
int __fastcall parse_string(char *a1)
{
__int64 v1; // rbp
int v2; // ebx
const char *v3; // rsi
char *v4; // r13
size_t v5; // rax

v1 = 0LL;
v2 = 0;
v3 = "send";
v4 = strtok(a1, " ");
do
{
if ( !strcmp(v4, v3) )
{
v5 = strlen(v4);
return ((__int64 (__fastcall *)(char *))*(&off_788 + 2 * v1))(&a1[v5 + 1]);
}
v1 = (unsigned __int8)++v2;
v3 = (&cmd_tbl)[2 * (unsigned __int8)v2];
}
while ( v3 );
return printf("Command '%s' not recognized.\n", v4);
}

canonical_decompiled_code:
int __fastcall func8(char *a1)
{
__int64 v1; // rbp
int v2; // ebx
const char *v3; // rsi
char *v4; // r13
size_t v5; // rax

v1 = 0LL;
v2 = 0;
v3 = "send";
v4 = strtok(a1, " ");
do
{
if ( !strcmp(v4, v3) )
{
v5 = strlen(v4);
return ((__int64 (__fastcall *)(char *))*(&off_788 + 2 * v1))(&a1[v5 + 1]);
}
v1 = (unsigned __int8)++v2;
v3 = (&cmd_tbl)[2 * (unsigned __int8)v2];
}
while ( v3 );
return printf("Command '%s' not recognized.\n", v4);
}

original_code:
void parse_string(char *str)
{
 char *cmd;
 U8 i = 0;
 cmd = strtok(str, " ");
 for (i = 0; cmd_tbl[i].cmd != ((void *)0); i++)
 {
  if (!strcmp(cmd, cmd_tbl[i].cmd))
  {
      cmd_tbl[i].func(str + strlen(cmd) + 1);
      return;
  }
 }
 printf("Command '%s' not recognized.\n", cmd);
}

canonical_original_code:
void parse_string(char *str)
{
 char *cmd;
 unsigned char i = 0;
 cmd = strtok(str, " ");
 for (i = 0; cmd_tbl[i].cmd != ((void *)0); i++)
 {
  if (!strcmp(cmd, cmd_tbl[i].cmd))
  {
      cmd_tbl[i].func(str + strlen(cmd) + 1);
      return;
  }
 }
 printf("Command '%s' not recognized.\n", cmd);
}

variable_types:
cmd
char *

variable_types:
i
unsigned char


decompiled_code:
int __fastcall process_script(char *a1)
{
char *v1; // rbp
FILE *v2; // rdx
char *v3; // rax
size_t v4; // rax
char *v5; // rbp
time_t v6; // rax
int v7; // ebx
struct timespec v9; // [rsp+0h] [rbp-A8h] BYREF
char s[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = strtok(a1, " ");
fp = fopen(v1, "r");
v2 = fp;
if ( !fp )
return printf("PROCESS_SCRIPT: Cannot open file - %s.\n", v1);
while ( fgets(s, 128, v2) )
{
*strchr(s, 10) = 0;
if ( s[0] )
{
v3 = strtok(s, " ");
if ( !strcmp(v3, "send") )
{
v4 = strlen(v3);
parse_string(&s[v4 + 1]);
}
else if ( !strcmp(v3, "wait") )
{
v5 = &s[strlen(v3) + 1];
v6 = time(0LL);
v9.tv_nsec = 0LL;
v9.tv_sec = v6 + 5;
if ( pthread_mutex_lock(&cli_buf) )
perror("process script lock mutex");
while ( check_cli_buf(v5) )
{
v7 = pthread_cond_timedwait(&cond, &cli_buf, &v9);
if ( v7 )
{
perror("cond timed wait");
if ( v7 == 110 )
{
puts("ERROR - WAIT CONDITION TIMED OUT");
exit(1);
}
}
}
if ( pthread_mutex_unlock(&cli_buf) )
perror("process script unlock mutex");
}
}
v2 = fp;
}
fclose(fp);
return puts("SUCCESS: Tests passed and script file closed.");
}

canonical_decompiled_code:
int __fastcall func9(char *a1)
{
char *v1; // rbp
FILE *v2; // rdx
char *v3; // rax
size_t v4; // rax
char *v5; // rbp
time_t v6; // rax
int v7; // ebx
struct timespec v9; // [rsp+0h] [rbp-A8h] BYREF
char s[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = strtok(a1, " ");
fp = fopen(v1, "r");
v2 = fp;
if ( !fp )
return printf("PROCESS_SCRIPT: Cannot open file - %s.\n", v1);
while ( fgets(s, 128, v2) )
{
*strchr(s, 10) = 0;
if ( s[0] )
{
v3 = strtok(s, " ");
if ( !strcmp(v3, "send") )
{
v4 = strlen(v3);
func8(&s[v4 + 1]);
}
else if ( !strcmp(v3, "wait") )
{
v5 = &s[strlen(v3) + 1];
v6 = time(0LL);
v9.tv_nsec = 0LL;
v9.tv_sec = v6 + 5;
if ( pthread_mutex_lock(&cli_buf) )
perror("process script lock mutex");
while ( func7(v5) )
{
v7 = pthread_cond_timedwait(&cond, &cli_buf, &v9);
if ( v7 )
{
perror("cond timed wait");
if ( v7 == 110 )
{
puts("ERROR - WAIT CONDITION TIMED OUT");
exit(1);
}
}
}
if ( pthread_mutex_unlock(&cli_buf) )
perror("process script unlock mutex");
}
}
v2 = fp;
}
fclose(fp);
return puts("SUCCESS: Tests passed and script file closed.");
}

original_code:
void process_script(char *str)
{
 char *name, *tmp, *cmdtype, *msg;
 char fcmd[128];
 struct timespec timeout;
 int status;
 name = strtok(str, " ");
 if ((fp = fopen(name, "r")) == ((void *)0))
 {
  printf("PROCESS_SCRIPT: Cannot open file - %s.\n", name);
  return;
 }
 while (fgets(fcmd, 128, fp) != ((void *)0))
 {
  tmp = strchr(fcmd, '\n');
  *tmp = '\0';
  if (fcmd[0] == '\0')
   continue;
  cmdtype = strtok(fcmd, " ");
  if (strcmp(cmdtype, "send") == 0)
  {
   msg = fcmd + strlen(cmdtype) + 1;
   parse_string(msg);
  } else if (strcmp(cmdtype, "wait") == 0) {
   msg = fcmd + strlen(cmdtype) + 1;
   timeout.tv_sec = time(((void *)0)) + 5;
   timeout.tv_nsec = 0;
   status = pthread_mutex_lock(&cli_buf.mutex);
   if (status)
    perror("process script lock mutex");
   while (check_cli_buf(msg))
   {
    status = pthread_cond_timedwait(&cli_buf.cond, &cli_buf.mutex, &timeout);
    if (status)
     perror("cond timed wait");
    if (status == 110)
    {
     printf("ERROR - WAIT CONDITION TIMED OUT\n");
     exit(1);
    }
   }
   status = pthread_mutex_unlock(&cli_buf.mutex);
   if (status)
    perror("process script unlock mutex");
  }
 }
 fclose(fp);
 printf("SUCCESS: Tests passed and script file closed.\n");
}

canonical_original_code:
void process_script(char *str)
{
 char *name; char *tmp; char *cmdtype; char *msg;
 char fcmd[128];
 struct timespec timeout;
 int status;
 name = strtok(str, " ");
 if ((fp = fopen(name, "r")) == ((void *)0))
 {
  printf("PROCESS_SCRIPT: Cannot open file - %s.\n", name);
  return;
 }
 while (fgets(fcmd, 128, fp) != ((void *)0))
 {
  tmp = strchr(fcmd, '\n');
  *tmp = '\0';
  if (fcmd[0] == '\0')
   continue;
  cmdtype = strtok(fcmd, " ");
  if (strcmp(cmdtype, "send") == 0)
  {
   msg = fcmd + strlen(cmdtype) + 1;
   parse_string(msg);
  } else if (strcmp(cmdtype, "wait") == 0) {
   msg = fcmd + strlen(cmdtype) + 1;
   timeout.tv_sec = time(((void *)0)) + 5;
   timeout.tv_nsec = 0;
   status = pthread_mutex_lock(&cli_buf.mutex);
   if (status)
    perror("process script lock mutex");
   while (check_cli_buf(msg))
   {
    status = pthread_cond_timedwait(&cli_buf.cond, &cli_buf.mutex, &timeout);
    if (status)
     perror("cond timed wait");
    if (status == 110)
    {
     printf("ERROR - WAIT CONDITION TIMED OUT\n");
     exit(1);
    }
   }
   status = pthread_mutex_unlock(&cli_buf.mutex);
   if (status)
    perror("process script unlock mutex");
  }
 }
 fclose(fp);
 printf("SUCCESS: Tests passed and script file closed.\n");
}

variable_types:
name
char *

variable_types:
cmdtype
char *

variable_types:
fcmd
char [128]

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: status int


cli

decompiled_code:
void __noreturn cli()
{
char *v0; // rax
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

while ( 1 )
{
printf("FreakZim>> ");
fflush(stdout);
fgets(v1, 512, stdin);
v0 = strchr(v1, 10);
if ( v0 )
*v0 = 0;
if ( v1[0] )
parse_string(v1);
}
}

canonical_decompiled_code:
void __noreturn func11()
{
char *v0; // rax
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

while ( 1 )
{
printf("FreakZim>> ");
fflush(stdout);
fgets(v1, 512, stdin);
v0 = strchr(v1, 10);
if ( v0 )
*v0 = 0;
if ( v1[0] )
func8(v1);
}
}

original_code:
void cli()
{
 char msg[512];
 char *msg_ptr = ((void *)0);
 struct sim_node_t *nd;
 while (1)
 {
  printf("FreakZim>> ");
  fflush(stdout);
  fgets(msg, sizeof(msg), stdin);
  msg_ptr = strchr(msg, '\n');
  if (msg_ptr)
   *msg_ptr = '\0';
  if (strcmp(msg, "\0"))
   parse_string(msg);
 }
}

variable_types:
msg
char [512]

variable_types: struct sim_node_t { struct list_head { struct list_head *next; } list; int pid; int index; unsigned short addr; struct pipe_t { int pipe; char name[30]; unsigned long thread; } data_in; struct pipe_t data_out; struct pipe_t cmd_in; struct pipe_t cmd_out; unsigned char buf[128]; unsigned char cmdbuf[128]; } *


decompiled_code:
__int64 __fastcall list_head(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
struct list_head *list_head(struct list_head *list)
{
 return list->next;
}

variable_types:
list
struct list_head *

return_type: struct list_head { struct list_head *next; } *


decompiled_code:
__int64 __fastcall list_length(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

original_code:
int list_length(struct list_head *list)
{
 struct list_head *l;
 int n = 0;
 for(l = list->next; l != ((void *)0); l = l->next) {
  ++n;
 }
 return n;
}

variable_types: struct list_head { struct list_head *next; } *

variable_types: n int