decompiled_code:
_BOOL8 __fastcall buffers_at_fname(char *s2)
{
int v1; // eax
_BOOL4 v2; // edx

v1 = buffers_find(s2);
v2 = 0;
if ( v1 != -1 )
v2 = strcmp(**(const char ***)(fnames + 8LL * v1), s2) == 0;
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(char *s2)
{
int v1; // eax
_BOOL4 v2; // edx

v1 = func14(s2);
v2 = 0;
if ( v1 != -1 )
v2 = strcmp(**(const char ***)(fnames + 8LL * v1), s2) == 0;
return v2;
}

original_code:
int buffers_at_fname(const char *fname)
{
 int i = buffers_find(fname);
 if(i == -1)
  return 0;
 return !strcmp(fnames[i]->fname, fname);
}

canonical_original_code:
int buffers_at_fname(char *fname)
{
 int i = buffers_find(fname);
 if(i == -1)
  return 0;
 return !strcmp(fnames[i]->fname, fname);
}


repo: bobrippling/uvi

decompiled_code:
__int64 __fastcall buffers_load(char *s2)
{
int v1; // eax
__int64 result; // rax

buffers_save_pos();
if ( s2 )
{
v1 = buffers_find(s2);
if ( v1 == -1 )
v1 = buffers_add(s2);
result = buffers_goto(v1);
}
else
{
if ( current_buf )
buffer_free();
current_buf = buffers_readfname(0LL);
current = -1;
result = gui_move(0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(char *s2)
{
int v1; // eax
__int64 result; // rax

func7();
if ( s2 )
{
v1 = func14(s2);
if ( v1 == -1 )
v1 = func15(s2);
result = func8(v1);
}
else
{
if ( current_buf )
buffer_free();
current_buf = func0(0LL);
current = -1;
result = gui_move(0LL, 0LL);
}
return result;
}

original_code:
void buffers_load(const char *fname)
{
 int i;
 buffers_save_pos();
 if(fname){
  if((i = buffers_find(fname)) != -1)
   buffers_goto(i);
  else
   buffers_goto(buffers_add(fname));
 }else{
  if(current_buf)
   buffer_free(current_buf);
  current_buf = buffers_readfname(((void *)0));
  current = -1;
  gui_move(0, 0);
 }
}

canonical_original_code:
void buffers_load(char *fname)
{
 int i;
 buffers_save_pos();
 if(fname){
  if((i = buffers_find(fname)) != -1)
   buffers_goto(i);
  else
   buffers_goto(buffers_add(fname));
 }else{
  if(current_buf)
   buffer_free(current_buf);
  current_buf = buffers_readfname(((void *)0));
  current = -1;
  gui_move(0, 0);
 }
}

variable_types:
fname
char *

variable_types: i int

return_type: void


umalloc

decompiled_code:
void *__fastcall umalloc(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
die("umalloc(%ld)", a1);
return v1;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
die("umalloc(%ld)", a1);
return v1;
}

original_code:
void *umalloc(size_t s)
{
 void *p = malloc(s);
 if(!p)
  die("umalloc(%ld)", s);
 return p;
}

canonical_original_code:
void *umalloc(unsigned long s)
{
 void *p = malloc(s);
 if(!p)
  die("umalloc(%ld)", s);
 return p;
}

variable_types:
s
unsigned long

variable_types:
p
void *

return_type: void *


ustrdup

decompiled_code:
char *__fastcall ustrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)umalloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *ustrdup(const char *s)
{
 char *d = umalloc(strlen(s) + 1);
 strcpy(d, s);
 return d;
}

canonical_original_code:
char *ustrdup(char *s)
{
 char *d = umalloc(strlen(s) + 1);
 strcpy(d, s);
 return d;
}

variable_types:
s
char *

variable_types:
d
char *

return_type: char *


decompiled_code:
char *__fastcall ustrdup2(char *src, int a2)
{
int v2; // esi
char *v3; // rbp
char *result; // rax

v2 = a2 - (_DWORD)src;
v3 = (char *)umalloc(v2 + 1);
result = strncpy(v3, src, v2);
v3[v2] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *src, int a2)
{
int v2; // esi
char *v3; // rbp
char *result; // rax

v2 = a2 - (_DWORD)src;
v3 = (char *)func0(v2 + 1);
result = strncpy(v3, src, v2);
v3[v2] = 0;
return result;
}

original_code:
char *ustrdup2(const char *start, const char *fin)
{
 int len = fin - start;
 char *d = umalloc(len + 1);
 strncpy(d, start, len);
 d[len] = '\0';
 return d;
}

canonical_original_code:
char *ustrdup2(char *start, char *fin)
{
 int len = fin - start;
 char *d = umalloc(len + 1);
 strncpy(d, start, len);
 d[len] = '\0';
 return d;
}

variable_types:
start
char *

variable_types:
fin
char *

variable_types: len int


urealloc

decompiled_code:
void *__fastcall urealloc(void *a1, size_t a2)
{
void *v2; // rbx

v2 = realloc(a1, a2);
if ( !v2 )
die("realloc(%p, %ld)", a1, a2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2)
{
void *v2; // rbx

v2 = realloc(a1, a2);
if ( !v2 )
die("realloc(%p, %ld)", a1, a2);
return v2;
}

original_code:
void *urealloc(void *p, size_t s)
{
 void *n = realloc(p, s);
 if(!n)
  die("realloc(%p, %ld)", p, s);
 return n;
}

canonical_original_code:
void *urealloc(void *p, unsigned long s)
{
 void *n = realloc(p, s);
 if(!n)
  die("realloc(%p, %ld)", p, s);
 return n;
}

variable_types:
n
void *


ustrprintf

decompiled_code:
char *ustrprintf(char *f, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
char *ptr; // [rsp+18h] [rbp-C0h] BYREF

va_start(va, f);
ptr = 0LL;
if ( vasprintf(&ptr, f, va) == -1 )
die("vasprintf(\"%s\")", f);
return ptr;
}

canonical_decompiled_code:
char *func4(char *f, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
char *ptr; // [rsp+18h] [rbp-C0h] BYREF

va_start(va, f);
ptr = 0LL;
if ( vasprintf(&ptr, f, va) == -1 )
die("vasprintf(\"%s\")", f);
return ptr;
}

original_code:
char *ustrprintf(const char *fmt, ...)
{
 char *s = ((void *)0);
 va_list l;
 int i;
 __builtin_va_start(l,fmt);
 i = vasprintf(&s, fmt, l);
 __builtin_va_end(l);
 if(i == -1)
  die("vasprintf(\"%s\")", fmt);
 return s;
}

canonical_original_code:
char *ustrprintf(char *fmt, ...)
{
 char *s = ((void *)0);
 __builtin_va_list l;
 int i;
 __builtin_va_start(l,fmt);
 i = vasprintf(&s, fmt, l);
 __builtin_va_end(l);
 if(i == -1)
  die("vasprintf(\"%s\")", fmt);
 return s;
}

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall visual_setpoints(_DWORD *a1, _DWORD *a2)
{
LODWORD(visual_cursor) = *a2;
HIDWORD(visual_cursor) = *a1;
LODWORD(visual_anchor) = a2[1];
HIDWORD(visual_anchor) = a1[1];
return gui_move((unsigned int)visual_cursor, HIDWORD(visual_cursor));
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
LODWORD(visual_cursor) = *a2;
HIDWORD(visual_cursor) = *a1;
LODWORD(visual_anchor) = a2[1];
HIDWORD(visual_anchor) = a1[1];
return gui_move((unsigned int)visual_cursor, HIDWORD(visual_cursor));
}

original_code:
void visual_setpoints(int x[2], int y[2])
{
 visual_cursor.start = y[0];
 visual_cursor.end = x[0];
 visual_anchor.start = y[1];
 visual_anchor.end = x[1];
 gui_move(visual_cursor.start, visual_cursor.end);
}

variable_types:
x
int [2]

variable_types:
y
int [2]


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

*a1 = gui_y();
result = gui_x();
a1[1] = result;
return result;
}

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

*a1 = gui_y();
result = gui_x();
a1[1] = result;
return result;
}

original_code:
void visual_update(struct range *v)
{
 v->start = gui_y();
 v->end = gui_x();
}

variable_types:
v
struct range { int start; } *


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

if ( !visual_state )
{
visual_update(&visual_cursor);
result = visual_update(&visual_anchor);
}
visual_state = a1;
return result;
}

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

if ( !visual_state )
{
func1(&visual_cursor);
result = func1(&visual_anchor);
}
visual_state = a1;
return result;
}

original_code:
void visual_set(enum visual v)
{
 if(visual_state == VISUAL_NONE){
  visual_update(&visual_cursor);
  visual_update(&visual_anchor);
 }
 visual_state = v;
}

variable_types: enum visual { VISUAL_NONE=0, VISUAL_LINE=1, VISUAL_BLOCK=2 }


decompiled_code:
__int64 visual_get()
{
return (unsigned int)visual_state;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)visual_state;
}

original_code:
enum visual visual_get()
{
 return visual_state;
}

return_type: enum visual { VISUAL_NONE=0, VISUAL_LINE=1, VISUAL_BLOCK=2 }


decompiled_code:
__int64 *visual_get_start()
{
__int64 *v0; // rdx

visual_update(&visual_cursor);
v0 = &visual_anchor;
if ( (int)visual_cursor - (int)visual_anchor <= 0 )
{
v0 = &visual_cursor;
if ( (int)visual_cursor - (int)visual_anchor >= 0 )
{
v0 = &visual_anchor;
if ( SHIDWORD(visual_cursor) <= SHIDWORD(visual_anchor) )
v0 = &visual_cursor;
}
}
return v0;
}

canonical_decompiled_code:
__int64 *func4()
{
__int64 *v0; // rdx

func1(&visual_cursor);
v0 = &visual_anchor;
if ( (int)visual_cursor - (int)visual_anchor <= 0 )
{
v0 = &visual_cursor;
if ( (int)visual_cursor - (int)visual_anchor >= 0 )
{
v0 = &visual_anchor;
if ( SHIDWORD(visual_cursor) <= SHIDWORD(visual_anchor) )
v0 = &visual_cursor;
}
}
return v0;
}

original_code:
const struct range *visual_get_start()
{
 int diff;
 visual_update(&visual_cursor);
 diff = visual_cursor.start - visual_anchor.start;
 if(diff > 0)
  return &visual_anchor;
 else if(diff < 0)
  return &visual_cursor;
 return visual_cursor.end > visual_anchor.end ? &visual_anchor : &visual_cursor;
}

variable_types: diff int

return_type: struct range { int start; } *


decompiled_code:
__int64 *visual_get_end()
{
bool v0; // zf
__int64 *result; // rax

v0 = visual_get_start() == &visual_cursor;
result = &visual_cursor;
if ( v0 )
result = &visual_anchor;
return result;
}

canonical_decompiled_code:
__int64 *func5()
{
bool v0; // zf
__int64 *result; // rax

v0 = func4() == &visual_cursor;
result = &visual_cursor;
if ( v0 )
result = &visual_anchor;
return result;
}

original_code:
const struct range *visual_get_end()
{
 if(visual_get_start() == &visual_cursor)
  return &visual_anchor;
 return &visual_cursor;
}


decompiled_code:
__int64 *visual_get_col_start()
{
__int64 *result; // rax

visual_update(&visual_cursor);
result = &visual_anchor;
if ( SHIDWORD(visual_cursor) <= SHIDWORD(visual_anchor) )
result = &visual_cursor;
return result;
}

canonical_decompiled_code:
__int64 *func6()
{
__int64 *result; // rax

func1(&visual_cursor);
result = &visual_anchor;
if ( SHIDWORD(visual_cursor) <= SHIDWORD(visual_anchor) )
result = &visual_cursor;
return result;
}

original_code:
const struct range *visual_get_col_start()
{
 visual_update(&visual_cursor);
 return visual_cursor.end > visual_anchor.end ? &visual_anchor : &visual_cursor;
}


decompiled_code:
__int64 *visual_get_col_end()
{
bool v0; // zf
__int64 *result; // rax

v0 = visual_get_col_start() == &visual_anchor;
result = &visual_cursor;
if ( !v0 )
result = &visual_anchor;
return result;
}

canonical_decompiled_code:
__int64 *func7()
{
bool v0; // zf
__int64 *result; // rax

v0 = func6() == &visual_anchor;
result = &visual_cursor;
if ( !v0 )
result = &visual_anchor;
return result;
}

original_code:
const struct range *visual_get_col_end()
{
 return visual_get_col_start() == &visual_anchor ? &visual_cursor : &visual_anchor;
}


decompiled_code:
_BOOL8 visual_cursor_is_end()
{
return visual_get_end() == &visual_cursor;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return func5() == &visual_cursor;
}

original_code:
int visual_cursor_is_end()
{
 return visual_get_end() == &visual_cursor;
}

return_type: int


decompiled_code:
__int64 visual_swap()
{
int v0; // edx
int v1; // eax
int v2; // edx
__int64 *v3; // rax
bool v5; // zf

v0 = visual_cursor;
v1 = HIDWORD(visual_cursor);
visual_cursor = visual_anchor;
LODWORD(visual_anchor) = v0;
HIDWORD(visual_anchor) = v1;
v2 = gui_y();
v3 = &visual_cursor;
if ( v2 == (_DWORD)visual_cursor )
{
v5 = (unsigned int)gui_x() == HIDWORD(visual_cursor);
v3 = &visual_anchor;
if ( !v5 )
v3 = &visual_cursor;
}
return gui_move(*(unsigned int *)v3, *((unsigned int *)v3 + 1));
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // edx
int v1; // eax
int v2; // edx
__int64 *v3; // rax
bool v5; // zf

v0 = visual_cursor;
v1 = HIDWORD(visual_cursor);
visual_cursor = visual_anchor;
LODWORD(visual_anchor) = v0;
HIDWORD(visual_anchor) = v1;
v2 = gui_y();
v3 = &visual_cursor;
if ( v2 == (_DWORD)visual_cursor )
{
v5 = (unsigned int)gui_x() == HIDWORD(visual_cursor);
v3 = &visual_anchor;
if ( !v5 )
v3 = &visual_cursor;
}
return gui_move(*(unsigned int *)v3, *((unsigned int *)v3 + 1));
}

original_code:
void visual_swap()
{
 struct range *move_to;
 struct range tmp;
 tmp = visual_cursor;
 visual_cursor = visual_anchor;
 visual_anchor = tmp;
 if(gui_y() == visual_cursor.start && gui_x() == visual_cursor.end)
  move_to = &visual_anchor;
 else
  move_to = &visual_cursor;
 gui_move(move_to->start, move_to->end);
}

variable_types:
tmp
struct range { int start; }


decompiled_code:
__int64 visual_join()
{
visual_cursor = visual_anchor;
return gui_move(visual_anchor, visual_anchor >> 32);
}

canonical_decompiled_code:
__int64 func10()
{
visual_cursor = visual_anchor;
return gui_move(visual_anchor, visual_anchor >> 32);
}

original_code:
void visual_join()
{
 memcpy(&visual_cursor, &visual_anchor, sizeof visual_cursor);
 gui_move(visual_cursor.start, visual_cursor.end);
}


decompiled_code:
__int64 visual_status()
{
__int64 *v0; // rbp
__int64 v1; // rbx
__int64 *v2; // rbp
__int64 *v3; // rax
int v4; // ecx
const char *v5; // rdi
const char *v6; // rsi

v0 = visual_get_start();
v1 = (unsigned int)(*(_DWORD *)visual_get_end() - *(_DWORD *)v0 + 1);
v2 = visual_get_col_start();
v3 = visual_get_col_end();
v4 = *((_DWORD *)v2 + 1);
v5 = (const char *)&unk_29C;
if ( *((_DWORD *)v3 + 1) != v4 )
v5 = (const char *)&unk_29D;
v6 = (const char *)&unk_29C;
if ( (_DWORD)v1 != 1 )
v6 = (const char *)&unk_29D;
return gui_status(
0LL,
"(%d,%d)-(%d,%d): %d line%s %d column%s",
(unsigned int)(*(_DWORD *)v2 + 1),
(unsigned int)(v4 + 1),
(unsigned int)(*(_DWORD *)v3 + 1),
(unsigned int)(*((_DWORD *)v3 + 1) + 1),
v1,
v6,
(unsigned int)(*((_DWORD *)v3 + 1) - v4 + 1),
v5);
}

canonical_decompiled_code:
__int64 func11()
{
__int64 *v0; // rbp
__int64 v1; // rbx
__int64 *v2; // rbp
__int64 *v3; // rax
int v4; // ecx
const char *v5; // rdi
const char *v6; // rsi

v0 = func4();
v1 = (unsigned int)(*(_DWORD *)func5() - *(_DWORD *)v0 + 1);
v2 = func6();
v3 = func7();
v4 = *((_DWORD *)v2 + 1);
v5 = (const char *)&unk_29C;
if ( *((_DWORD *)v3 + 1) != v4 )
v5 = (const char *)&unk_29D;
v6 = (const char *)&unk_29C;
if ( (_DWORD)v1 != 1 )
v6 = (const char *)&unk_29D;
return gui_status(
0LL,
"(%d,%d)-(%d,%d): %d line%s %d column%s",
(unsigned int)(*(_DWORD *)v2 + 1),
(unsigned int)(v4 + 1),
(unsigned int)(*(_DWORD *)v3 + 1),
(unsigned int)(*((_DWORD *)v3 + 1) + 1),
v1,
v6,
(unsigned int)(*((_DWORD *)v3 + 1) - v4 + 1),
v5);
}

original_code:
void visual_status()
{
 const struct range *v1, *v2;
 int diff_lines, diff_cols;
 v1 = visual_get_start();
 v2 = visual_get_end();
 diff_lines = v2->start - v1->start + 1;
 v1 = visual_get_col_start();
 v2 = visual_get_col_end();
 diff_cols = v2->end - v1->end + 1;
 gui_status(GUI_NONE, "(%d,%d)-(%d,%d): %d line%s %d column%s",
   v1->start + 1, v1->end + 1,
   v2->start + 1, v2->end + 1,
   diff_lines, diff_lines == 1 ? "" : "s",
   diff_cols, diff_cols == 1 ? "" : "s");
}

canonical_original_code:
void visual_status()
{
 struct range *v1; struct range *v2;
 int diff_lines; int diff_cols;
 v1 = visual_get_start();
 v2 = visual_get_end();
 diff_lines = v2->start - v1->start + 1;
 v1 = visual_get_col_start();
 v2 = visual_get_col_end();
 diff_cols = v2->end - v1->end + 1;
 gui_status(GUI_NONE, "(%d,%d)-(%d,%d): %d line%s %d column%s",
   v1->start + 1, v1->end + 1,
   v2->start + 1, v2->end + 1,
   diff_lines, diff_lines == 1 ? "" : "s",
   diff_cols, diff_cols == 1 ? "" : "s");
}


decompiled_code:
__int64 __fastcall longest_match(const char **a1)
{
const char *v1; // r12
const char **v2; // rbp
const char **v3; // r13
const char *v4; // rdi
int v5; // ebx
int v6; // eax
__int64 i; // rcx
unsigned int v8; // er8
_QWORD *v9; // rdx
const char *v10; // rax

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = a1;
v4 = *a1;
v5 = 0x7FFFFFFF;
do
{
v6 = strlen(v4);
if ( v5 > v6 )
v5 = v6;
v4 = *++v3;
}
while ( *v3 );
if ( v5 <= 0 )
return (unsigned int)v5;
for ( i = 0LL; ; ++i )
{
v8 = i;
v9 = v2 + 1;
if ( v2[1] )
break;
LABEL_12:
if ( v5 - 1 == i )
return (unsigned int)v5;
}
v10 = v2[1];
while ( v10[i] == v1[i] )
{
v10 = (const char *)*++v9;
if ( !*v9 )
goto LABEL_12;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
const char *v1; // r12
const char **v2; // rbp
const char **v3; // r13
const char *v4; // rdi
int v5; // ebx
int v6; // eax
__int64 i; // rcx
unsigned int v8; // er8
_QWORD *v9; // rdx
const char *v10; // rax

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = a1;
v4 = *a1;
v5 = 0x7FFFFFFF;
do
{
v6 = strlen(v4);
if ( v5 > v6 )
v5 = v6;
v4 = *++v3;
}
while ( *v3 );
if ( v5 <= 0 )
return (unsigned int)v5;
for ( i = 0LL; ; ++i )
{
v8 = i;
v9 = v2 + 1;
if ( v2[1] )
break;
LABEL_12:
if ( v5 - 1 == i )
return (unsigned int)v5;
}
v10 = v2[1];
while ( v10[i] == v1[i] )
{
v10 = (const char *)*++v9;
if ( !*v9 )
goto LABEL_12;
}
return v8;
}

original_code:
static int longest_match(char **words)
{
 int minlen = 0x7fffffff;
 int i;
 char **iter;
 if(!*words)
  return 0;
 for(iter = words; *iter; iter++){
  const int len = strlen(*iter);
  if(len < minlen)
   minlen = len;
 }
 for(i = 0; i < minlen; i++){
  char c = (*words)[i];
  char **jter;
  for(jter = words + 1; *jter; jter++)
   if((*jter)[i] != c)
    return i;
 }
 return minlen;
}

canonical_original_code:
static int longest_match(char **words)
{
 int minlen = 0x7fffffff;
 int i;
 char **iter;
 if(!*words)
  return 0;
 for(iter = words; *iter; iter++){
  int len = strlen(*iter);
  if(len < minlen)
   minlen = len;
 }
 for(i = 0; i < minlen; i++){
  char c = (*words)[i];
  char **jter;
  for(jter = words + 1; *jter; jter++)
   if((*jter)[i] != c)
    return i;
 }
 return minlen;
}

variable_types:
words
char **

variable_types: minlen int

variable_types:
iter
char **

variable_types: c char

variable_types:
jter
char **


original_code:
static void intellisense_complete_to(char **pstr, int *psize, int *pos,
  const char *word, int longest_len, int offset_into_word, int escape)
{
 const int space_left = *psize - *pos - longest_len + offset_into_word - 1;
 int nextra = longest_len - offset_into_word;
 if(space_left <= 0){
  *psize -= space_left;
  *pstr = urealloc(*pstr, *psize);
 }
 if(escape){
  char *copy;
  char *str;
  int nescapes;
  copy = __builtin_alloca(nextra + 1);
  strncpy(copy, word + offset_into_word, nextra);
  copy[nextra] = '\0';
  str = str_shell_escape(copy, &nescapes);
  nextra += nescapes;
  strncat(*pstr + *pos, str, nextra);
  free(str);
 }else{
  strncat(*pstr + *pos, word + offset_into_word, nextra);
 }
 *pos += nextra;
}

canonical_original_code:
static void intellisense_complete_to(char **pstr, int *psize, int *pos, char *word, int longest_len, int offset_into_word, int escape)
{
 int space_left = *psize - *pos - longest_len + offset_into_word - 1;
 int nextra = longest_len - offset_into_word;
 if(space_left <= 0){
  *psize -= space_left;
  *pstr = urealloc(*pstr, *psize);
 }
 if(escape){
  char *copy;
  char *str;
  int nescapes;
  copy = __builtin_alloca(nextra + 1);
  strncpy(copy, word + offset_into_word, nextra);
  copy[nextra] = '\0';
  str = str_shell_escape(copy, &nescapes);
  nextra += nescapes;
  strncat(*pstr + *pos, str, nextra);
  free(str);
 }else{
  strncat(*pstr + *pos, word + offset_into_word, nextra);
 }
 *pos += nextra;
}

variable_types:
pstr
char **

variable_types:
psize
int *

variable_types:
pos
int *

variable_types:
word
char *

variable_types: escape int

variable_types: nextra int

variable_types:
copy
char *

variable_types:
str
char *

variable_types: nescapes int


decompiled_code:
__int64 __fastcall intellisense_insert(_QWORD *a1, int *a2, int *a3, char a4)
{
unsigned int v4; // er12
const char *v7; // rax
char *v8; // r15
int v9; // er12
_QWORD *v10; // rax
__int64 v11; // rax
const char **v12; // r13
unsigned int v13; // eax
__int64 v14; // rdx
__int64 v15; // rcx
char *v16; // rdi
char **v17; // rbx
unsigned int v18; // [rsp+8h] [rbp-40h] BYREF
unsigned int v19[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = 1;
if ( a4 == 14 )
{
v7 = (const char *)word_at(*a1, (unsigned int)(*a3 - 1));
v8 = (char *)v7;
if ( v7 )
{
v9 = strlen(v7);
v10 = (_QWORD *)buffers_current();
v11 = list_gethead(*v10);
v12 = (const char **)words_begin(v11, v8);
v13 = longest_match(v12);
if ( (int)(v13 - v9) <= 0 )
{
gui_getyx(&v18, v19, v14, v15, v13);
gui_show_array(256LL, v18 + 1, v19[0], v12);
gui_setyx(v18, v19[0]);
v4 = 1;
}
else
{
intellisense_complete_to(a1, a2, a3, (__int64)*v12, v13, v9, 0);
v4 = 0;
}
free(v8);
v16 = (char *)*v12;
if ( !*v12 )
goto LABEL_12;
v17 = (char **)v12;
do
{
free(v16);
v16 = *++v17;
}
while ( *v17 );
if ( !*v12 )
LABEL_12:
gui_status(1LL, "no completions");
free(v12);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int *a2, int *a3, char a4)
{
unsigned int v4; // er12
const char *v7; // rax
char *v8; // r15
int v9; // er12
_QWORD *v10; // rax
__int64 v11; // rax
const char **v12; // r13
unsigned int v13; // eax
__int64 v14; // rdx
__int64 v15; // rcx
char *v16; // rdi
char **v17; // rbx
unsigned int v18; // [rsp+8h] [rbp-40h] BYREF
unsigned int v19[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = 1;
if ( a4 == 14 )
{
v7 = (const char *)word_at(*a1, (unsigned int)(*a3 - 1));
v8 = (char *)v7;
if ( v7 )
{
v9 = strlen(v7);
v10 = (_QWORD *)buffers_current();
v11 = list_gethead(*v10);
v12 = (const char **)words_begin(v11, v8);
v13 = func0(v12);
if ( (int)(v13 - v9) <= 0 )
{
gui_getyx(&v18, v19, v14, v15, v13);
gui_show_array(256LL, v18 + 1, v19[0], v12);
gui_setyx(v18, v19[0]);
v4 = 1;
}
else
{
func1(a1, a2, a3, (__int64)*v12, v13, v9, 0);
v4 = 0;
}
free(v8);
v16 = (char *)*v12;
if ( !*v12 )
goto LABEL_12;
v17 = (char **)v12;
do
{
free(v16);
v16 = *++v17;
}
while ( *v17 );
if ( !*v12 )
LABEL_12:
gui_status(1LL, "no completions");
free(v12);
}
}
return v4;
}

original_code:
int intellisense_insert(char **pstr, int *psize, int *pos, char ch)
{
 char **words, **iter;
 int len, wlen;
 int ret;
 char *w;
 if(ch != (('n') & 037))
  return 1;
 w = word_at(*pstr, *pos - 1);
 if(!w)
  return 1;
 ret = 1;
 wlen = strlen(w);
 words = words_begin(list_gethead ( ((buffers_current())->lines) ), w);
 len = longest_match(words);
 if(len - wlen > 0){
  intellisense_complete_to(pstr, psize, pos, *words, len, wlen, 0);
  ret = 0;
 }else{
  int y, x;
  gui_getyx(&y, &x);
  gui_show_array(GUI_COL_MAGENTA, y+1, x, (const char **)words);
  gui_setyx(y, x);
 }
 free(w);
 for(iter = words; *iter; iter++)
  free(*iter);
 if(!*words){
  gui_status(GUI_ERR, "no completions");
 }
 free(words);
 return ret;
}

canonical_original_code:
int intellisense_insert(char **pstr, int *psize, int *pos, char ch)
{
 char **words; char **iter;
 int len; int wlen;
 int ret;
 char *w;
 if(ch != (('n') & 037))
  return 1;
 w = word_at(*pstr, *pos - 1);
 if(!w)
  return 1;
 ret = 1;
 wlen = strlen(w);
 words = words_begin(list_gethead ( ((buffers_current())->lines) ), w);
 len = longest_match(words);
 if(len - wlen > 0){
  intellisense_complete_to(pstr, psize, pos, *words, len, wlen, 0);
  ret = 0;
 }else{
  int y; int x;
  gui_getyx(&y, &x);
  gui_show_array(GUI_COL_MAGENTA, y+1, x, (char **)words);
  gui_setyx(y, x);
 }
 free(w);
 for(iter = words; *iter; iter++)
  free(*iter);
 if(!*words){
  gui_status(GUI_ERR, "no completions");
 }
 free(words);
 return ret;
}

variable_types: ch char

variable_types: len int

variable_types: wlen int

variable_types: ret int

variable_types:
w
char *

variable_types: y int

variable_types: x int


decompiled_code:
__int64 __fastcall file_uniq(_QWORD *a1, _QWORD *a2, unsigned int *a3)
{
return str_eqoffset(*a1, *a2, global_settings[5], *a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, _QWORD *a2, unsigned int *a3)
{
return str_eqoffset(*a1, *a2, global_settings[5], *a3);
}

original_code:
int file_uniq(const void *a, const void *b, void *extra)
{
 return str_eqoffset(*(const char **)a, *(const char **)b, global_settings.tabctx, *(int *)extra);
}

canonical_original_code:
int file_uniq(void *a, void *b, void *extra)
{
 return str_eqoffset(*(char **)a, *(char **)b, global_settings.tabctx, *(int *)extra);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
extra
void *


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

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

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

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

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

user_defined_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 st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


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

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( a2 == 1 )
{
*(_QWORD *)(a1 + 16) = intellisense_insert;
*(_DWORD *)(a1 + 24) = 14;
*(_DWORD *)(a1 + 8) = 1;
result = global_settings[4];
*(_DWORD *)(a1 + 4) = result;
*(_DWORD *)(a1 + 12) = 1;
}
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; } *


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 *


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)
{
_QWORD *v1; // rcx
__int64 v2; // rax
unsigned int v3; // edx

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_QWORD *v1; // rcx
__int64 v2; // rax
unsigned int v3; // edx

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

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


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

v2 = list_gethead(a1);
if ( !v2 || v2 == a2 )
{
v3 = 0;
}
else
{
v3 = 0;
do
{
++v3;
v2 = *(_QWORD *)(v2 + 8);
}
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

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

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = func9(a2);
v3 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8) = v3;
if ( v3 )
*(_QWORD *)(v3 + 16) = result;
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a2 + 16) = a1;
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; // rdx
int v4; // eax

for ( i = list_gethead(a1); ; i = *(_QWORD *)(i + 8) )
{
v4 = a2--;
if ( v4 <= 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; // rbx
void *v2; // rdi

v1 = list_gethead(a1);
while ( v1 )
{
v2 = (void *)v1;
v1 = *(_QWORD *)(v1 + 8);
free(v2);
}
}

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

v1 = func6(a1);
while ( v1 )
{
v2 = (void *)v1;
v1 = *(_QWORD *)(v1 + 8);
free(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; // rbx
_QWORD *v3; // rbp

v2 = list_gethead(a1);
while ( v2 )
{
v3 = (_QWORD *)v2;
v2 = *(_QWORD *)(v2 + 8);
if ( *v3 )
a2();
free(v3);
}
}

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

v2 = func6(a1);
while ( v2 )
{
v3 = (_QWORD *)v2;
v2 = *(_QWORD *)(v2 + 8);
if ( *v3 )
a2();
free(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; // rbx
int v1; // edx
_BOOL8 result; // rax

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

canonical_decompiled_code:
_BOOL8 func1()
{
const char *v0; // rbx
int v1; // edx
_BOOL8 result; // rax

v0 = (const char *)file_rc();
v1 = access(v0, 0);
result = 1LL;
if ( !v1 )
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

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

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

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

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
int v2; // eax
__int64 v3; // rbx
int *v4; // rbp
int v5; // er12
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);
v2 = system(command);
exit(v2);
}
exit(-1);
}
close(pipedes[1]);
v3 = list_from_fd((unsigned int)pipedes[0], 0LL);
v4 = _errno_location();
v5 = *v4;
wait(0LL);
*v4 = v5;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *command)
{
__pid_t v1; // eax
int v2; // eax
__int64 v3; // rbx
int *v4; // rbp
int v5; // er12
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);
v2 = system(command);
exit(v2);
}
exit(-1);
}
close(pipedes[1]);
v3 = list_from_fd((unsigned int)pipedes[0], 0LL);
v4 = _errno_location();
v5 = *v4;
wait(0LL);
*v4 = v5;
return v3;
}

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; // rbx
int *v5; // rbp
int v6; // er12
int fd; // [rsp+0h] [rbp-28h] BYREF
int v8; // [rsp+4h] [rbp-24h]
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

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

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

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

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; // rax
__int64 v5; // rbx
_QWORD *v6; // rax
_QWORD *v7; // rbp
unsigned int v8; // er12
_QWORD *v9; // rax
__int64 v10; // r12
int *v11; // rbp
int v12; // er13
unsigned int v13; // er12
_QWORD *v15; // rax
__int64 v16; // rsi
_QWORD *v17; // rax
_QWORD *v18; // rbp
__int64 v19; // rax
_QWORD *v20; // rax

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

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

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

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
__int64 result; // rax

v1 = !yank_char_valid(a1);
result = 0xFFFFFFFFLL;
if ( !v1 )
result = (unsigned int)(a1 - 96);
return result;
}

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

v1 = !func0(a1);
result = 0xFFFFFFFFLL;
if ( !v1 )
result = (unsigned int)(a1 - 96);
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:
void __fastcall yank_set(char a1, __int64 a2, int a3)
{
int v4; // eax
int v5; // ebx
void *v6; // rdi
unsigned __int64 v7; // rbx

v4 = yank_index(a1);
if ( v4 != -1 )
{
v5 = v4;
v6 = (void *)yanks[2 * v4];
if ( v6 )
{
if ( dword_E8[4 * v4] )
list_free(v6, &free);
else
free(v6);
}
v7 = 4LL * v5;
yanks[v7 / 2] = a2;
dword_E8[v7] = a3;
}
}

canonical_decompiled_code:
void __fastcall func2(char a1, __int64 a2, int a3)
{
int v4; // eax
int v5; // ebx
void *v6; // rdi
unsigned __int64 v7; // rbx

v4 = func1(a1);
if ( v4 != -1 )
{
v5 = v4;
v6 = (void *)yanks[2 * v4];
if ( v6 )
{
if ( dword_E8[4 * v4] )
list_free(v6, &free);
else
free(v6);
}
v7 = 4LL * v5;
yanks[v7 / 2] = a2;
dword_E8[v7] = a3;
}
}

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:
void __fastcall yank_set_str(char a1, __int64 a2)
{
yank_set(a1, a2, 0);
}

canonical_decompiled_code:
void __fastcall func3(char a1, __int64 a2)
{
func2(a1, a2, 0);
}

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

variable_types:
s
char *


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

canonical_decompiled_code:
void __fastcall func4(char a1, __int64 a2)
{
func2(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)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func8(int a1, _DWORD *a2, _DWORD *a3)
{
__int64 result; // rax

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

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, _DWORD *a3)
{
int v4; // eax

v4 = mark_idx(a1);
return mark_get_idx(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax

v4 = func0(a1);
return func8(v4, a2, a3);
}

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)
{
int v6; // er13
char *result; // rax
int v8; // edx
char *v9[6]; // [rsp+8h] [rbp-30h] BYREF

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

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

v9[0] = a1;
if ( (unsigned int)func0(v9, a3, a4) )
{
v6 = curv;
result = v9[0];
if ( *v9[0] == 44 )
{
++v9[0];
v8 = func0(v9, a3, a4);
result = 0LL;
if ( v8 )
{
*a2 = v6;
a2[1] = curv;
result = v9[0];
}
}
else
{
*a2 = curv;
a2[1] = v6;
}
}
else
{
result = v9[0];
if ( *v9[0] == 37 )
{
*a2 = 1;
a2[1] = a4;
++result;
}
}
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


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], v7 < v8) || v8 <= 0 )
{
*_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], v7 < v8) || v8 <= 0 )
{
*_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

result = &unk_4F0;
do
{
v1 = (_DWORD *)result[2];
if ( v1 )
*v1 = *(_DWORD *)result;
result += 5;
}
while ( result != (_QWORD *)&unk_860 );
return result;
}

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

result = &unk_4F0;
do
{
v1 = (_DWORD *)result[2];
if ( v1 )
*v1 = *(_DWORD *)result;
result += 5;
}
while ( result != (_QWORD *)&unk_860 );
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_4F4[10 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)dword_4F4[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_500[5 * a1] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned int a1)
{
return qword_500[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_500[5 * a1];
}

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

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

return_type: int *


decompiled_code:
char *__fastcall vars_tostring(unsigned int a1)
{
return vars[5 * a1];
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int a1)
{
return vars[5 * a1];
}

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


decompiled_code:
__int64 __fastcall vars_gettype(char *s2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
const char *v4; // rdi

v2 = 0LL;
while ( 1 )
{
v3 = v2;
v4 = vars[5 * v2];
if ( v4 )
{
if ( !strcmp(v4, s2) )
break;
}
if ( ++v2 == 22 )
return 22;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
const char *v4; // rdi

v2 = 0LL;
while ( 1 )
{
v3 = v2;
v4 = vars[5 * v2];
if ( v4 )
{
if ( !strcmp(v4, s2) )
break;
}
if ( ++v2 == 22 )
return 22;
}
return v3;
}

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)
{
char *v2; // rbp
__int64 v3; // rax
__int64 v4; // r9
void *v5; // rdi
__int64 result; // rax
__int64 v7; // rax
unsigned int v8; // eax
char *v9; // rax
char s[32]; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)vars_isbool(a1) )
{
v2 = vars_tostring(a1);
v3 = buffers_current();
v5 = &unk_27F;
if ( !(unsigned int)vars_get(a1, v3) )
v5 = &unk_280;
result = gui_status_add_col(v5, 64LL, v2, 0LL, 0LL, v4);
}
else
{
v7 = buffers_current();
v8 = vars_get(a1, v7);
snprintf(s, 8uLL, "%d", v8);
v9 = vars_tostring(a1);
result = gui_status_add_col(v9, 4LL, "=", 0LL, s, 16LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
char *v2; // rbp
__int64 v3; // rax
__int64 v4; // r9
void *v5; // rdi
__int64 result; // rax
__int64 v7; // rax
unsigned int v8; // eax
char *v9; // rax
char s[32]; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)func1(a1) )
{
v2 = func6(a1);
v3 = buffers_current();
v5 = &unk_27F;
if ( !(unsigned int)func4(a1, v3) )
v5 = &unk_280;
result = gui_status_add_col(v5, 64LL, v2, 0LL, 0LL, v4);
}
else
{
v7 = buffers_current();
v8 = func4(a1, v7);
snprintf(s, 8uLL, "%d", v8);
v9 = func6(a1);
result = gui_status_add_col(v9, 4LL, "=", 0LL, s, 16LL);
}
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)
{
char *v1; // rbp
const char *v2; // rbx
size_t v3; // rax
const char *v4; // rdx

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

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

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

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; // rbx
__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; // rbx
__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; // edx
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
char v3[4]; // [rsp+8h] [rbp-10h] BYREF
char v4[12]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

v0 = motion_wrap(&v2, v3, (char *)&v2 + 4, v4, &unk_206, 0LL);
result = 1LL;
if ( !v0 )
{
*(_DWORD *)(buffers_current() + 20) = 1;
result = range_through_pipe(v3, "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)
{
unsigned int v1; // er12
unsigned int v2; // ebx
_QWORD *v3; // rax
__int64 v4; // rbx
_BYTE *v5; // rbx
int v6; // ebp
unsigned int v7; // eax
const unsigned __int16 **v8; // r13
_BYTE *v9; // r12
char v10; // al
__int64 v11; // rbp
__int64 result; // rax

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

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

v1 = a1;
v2 = gui_y();
v3 = (_QWORD *)buffers_current();
v4 = *(_QWORD *)list_getindex(*v3, v2);
v5 = (_BYTE *)((int)gui_x() + v4);
if ( !a1 )
v1 = 1;
v6 = gui_x();
v7 = gui_y();
gui_move(v7, v6 + v1);
v8 = _ctype_b_loc();
v9 = &v5[v1];
do
{
v11 = (char)*v5;
if ( ((*v8)[v11] & 0x200) != 0 )
v10 = (*_ctype_toupper_loc())[v11];
else
v10 = (*_ctype_tolower_loc())[v11];
*v5++ = v10;
}
while ( *v5 && 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; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // r12

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; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // r12

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; // ebp
void *v3; // rdi
char *v4; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v2; // ebp
void *v3; // rdi
char *v4; // rax

v2 = regerror(*(_DWORD *)(a1 + 8), *(const regex_t **)a1, 0LL, 0LL);
v3 = *(void **)(a1 + 16);
if ( v3 )
free(v3);
v4 = (char *)umalloc(v2);
*(_QWORD *)(a1 + 16) = v4;
regerror(*(_DWORD *)(a1 + 8), *(const regex_t **)a1, v4, v2);
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
regoff_t v6; // eax
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 = v7.rm_so;
*(_DWORD *)(a1 + 32) = v7.rm_eo - v7.rm_so;
result = a2 + v3 + v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
int v4; // edx
__int64 result; // rax
regoff_t v6; // eax
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 = v7.rm_so;
*(_DWORD *)(a1 + 32) = v7.rm_eo - v7.rm_so;
result = a2 + v3 + 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; // er14
int v7; // ebx
__int64 v8; // r13
__int64 v9; // rax

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

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax
char *v5; // rbp
int v6; // er14
int v7; // ebx
__int64 v8; // r13
__int64 v9; // rax

v4 = strlen(a2);
v5 = (char *)umalloc(v4 + 2);
strcpy(v5, a2);
v5[a3 + 1] = 0;
v6 = strlen(*(const char **)(a1 + 24));
if ( a3 < 0 )
a3 = 0;
v7 = a3 / 2;
v8 = 0LL;
while ( v7 < (int)strlen(v5) )
{
v9 = func2(a1, (__int64)&v5[v7], 0);
if ( v9 )
{
v7 += v6;
v8 = v9;
}
else
{
if ( v8 )
{
free(v5);
return &a2[(int)v8 - (int)v5];
}
if ( v7 <= 0 )
break;
v7 -= v6 + 1;
if ( v7 < 0 )
v7 = 0;
}
}
free(v5);
return 0LL;
}

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(const char *a1, ...)
{
__int64 v1; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

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

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

va_start(arg, a1);
gui_term();
v1 = buffers_current();
preserve(v1);
fwrite("uvi: dying: ", 1uLL, 0xCuLL, stderr);
vfprintf(stderr, a1, 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 *