decompiled_code:
__int64 __fastcall dot_replace(_BYTE *a1)
{
__int64 result; // rax

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 46 )
*a1 = 95;
++a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 result; // rax

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 46 )
*a1 = 95;
++a1;
}
return result;
}

original_code:
static void dot_replace(char *lbl)
{
 for(; *lbl; lbl++)
  if(*lbl == '.')
   *lbl = '_';
}

variable_types:
lbl
char *


repo: bobrippling/ucc-c-compiler

decompiled_code:
void __fastcall dot_emit(__int64 a1, __int64 a2)
{
_BYTE *v2; // r12
_BYTE *v3; // rbp
const char *v4; // rdx
const char *v5; // rcx

v2 = (_BYTE *)((__int64 (*)(void))ustrdup)();
v3 = (_BYTE *)ustrdup(a2);
dot_replace(v2);
dot_replace(v3);
fprintf(stderr, "%s -> %s;\n", v4, v5);
free(v2);
free(v3);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
_BYTE *v2; // r12
_BYTE *v3; // rbp
const char *v4; // rdx
const char *v5; // rcx

v2 = (_BYTE *)((__int64 (*)(void))ustrdup)();
v3 = (_BYTE *)ustrdup(a2);
func0(v2);
func0(v3);
fprintf(stderr, "%s -> %s;\n", v4, v5);
free(v2);
free(v3);
}

original_code:
static void dot_emit(const char *from, const char *to)
{
 char *from_ = ustrdup(from);
 char *to_ = ustrdup(to);
 dot_replace(from_);
 dot_replace(to_);
 fprintf(stderr, "%s -> %s;\n", from_, to_);
 free(from_);
 free(to_);
}

canonical_original_code:
static void dot_emit(char *from, char *to)
{
 char *from_ = ustrdup(from);
 char *to_ = ustrdup(to);
 dot_replace(from_);
 dot_replace(to_);
 fprintf(stderr, "%s -> %s;\n", from_, to_);
 free(from_);
 free(to_);
}

variable_types:
from
char *

variable_types:
to
char *

return_type: void


decompiled_code:
char *__fastcall v_store_to_str(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 6 )
result = CSWTCH_10[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 6 )
result = CSWTCH_10[a1];
return result;
}

original_code:
const char *v_store_to_str(enum out_val_store store)
{
 switch(store){
  case V_CONST_I: return "V_CONST_I";
  case V_REG: return "V_REG";
  case V_REGOFF: return "V_REGOFF";
  case V_SPILT: return "V_SPILT";
  case V_LBL: return "V_LBL";
  case V_CONST_F: return "V_CONST_F";
  case V_FLAG: return "V_FLAG";
 }
 return ((void *)0);
}

variable_types: enum out_val_store { V_CONST_I=0, V_REG=1, V_SPILT=2, V_REGOFF=3, V_LBL=4, V_CONST_F=5, V_FLAG=6 }

return_type: char *


decompiled_code:
_BOOL8 __fastcall vreg_eq(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_WORD *)a1 == *(_WORD *)a2 )
result = *(_BYTE *)(a1 + 2) == *(_BYTE *)(a2 + 2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func24(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_WORD *)a1 == *(_WORD *)a2 )
result = *(_BYTE *)(a1 + 2) == *(_BYTE *)(a2 + 2);
return result;
}

original_code:
int vreg_eq(const struct vreg *a, const struct vreg *b)
{
 return a->idx == b->idx && a->is_float == b->is_float;
}

canonical_original_code:
int vreg_eq(struct vreg *a, struct vreg *b)
{
 return a->idx == b->idx && a->is_float == b->is_float;
}

variable_types: struct vreg { unsigned short idx; unsigned char is_float; } *

variable_types:
b
struct vreg *

return_type: int


decompiled_code:
_BOOL8 __fastcall increment_str(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax

v2 = *a1 + 1;
*a1 = v2;
return v2 < a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax

v2 = *a1 + 1;
*a1 = v2;
return v2 < a2;
}

original_code:
static int increment_str(size_t *i, size_t len)
{
 return ++*i < len;
}

canonical_original_code:
static int increment_str(unsigned long *i, unsigned long len)
{
 return ++*i < len;
}

variable_types:
i
unsigned long *

variable_types:
len
unsigned long


decompiled_code:
_BOOL8 __fastcall parse_digit(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, _DWORD *a4)
{
__int64 v5; // rbx
const unsigned __int16 **v6; // rdx
_BOOL8 result; // rax

v5 = *(char *)(a1 + *a2);
if ( (_BYTE)v5 == 42 )
{
*a4 = 1;
result = increment_str(a2, a3);
}
else
{
v6 = _ctype_b_loc();
while ( ((*v6)[v5] & 0x800) != 0 )
{
result = increment_str(a2, a3);
if ( !result )
return result;
v5 = *(char *)(a1 + *a2);
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, _DWORD *a4)
{
__int64 v5; // rbx
const unsigned __int16 **v6; // rdx
_BOOL8 result; // rax

v5 = *(char *)(a1 + *a2);
if ( (_BYTE)v5 == 42 )
{
*a4 = 1;
result = func0(a2, a3);
}
else
{
v6 = _ctype_b_loc();
while ( ((*v6)[v5] & 0x800) != 0 )
{
result = func0(a2, a3);
if ( !result )
return result;
v5 = *(char *)(a1 + *a2);
}
result = 1LL;
}
return result;
}

original_code:
static int parse_digit(const char *fmt, size_t *const i, size_t const len, int *const got_asterisk)
{
 if(fmt[*i] == '*'){
  *got_asterisk = 1;
  return increment_str(i, len);
 }
 while(((*__ctype_b_loc ())[(int) ((fmt[*i]))] & (unsigned short int) _ISdigit)){
  if(!increment_str(i, len))
   return 0;
 }
 return 1;
}

canonical_original_code:
static int parse_digit(char *fmt, unsigned long *i, unsigned long len, int *got_asterisk)
{
 if(fmt[*i] == '*'){
  *got_asterisk = 1;
  return increment_str(i, len);
 }
 while(((*__ctype_b_loc ())[(int) ((fmt[*i]))] & (unsigned short) _ISdigit)){
  if(!increment_str(i, len))
   return 0;
 }
 return 1;
}

variable_types:
fmt
char *


stylef

decompiled_code:
__int64 stylef(__int64 a1, ...)
{
__int64 v2[3]; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list va; // [rsp+18h] [rbp-D0h] BYREF

va_start(va, a1);
v2[1] = 0xFFFFFFFF00000000LL;
v2[0] = 0LL;
return asm_out_sectionv(v2, a1, va);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, ...)
{
__int64 v2[3]; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list va; // [rsp+18h] [rbp-D0h] BYREF

va_start(va, a1);
v2[1] = 0xFFFFFFFF00000000LL;
v2[0] = 0LL;
return asm_out_sectionv(v2, a1, va);
}

original_code:
void stylef(const char *fmt, ...)
{
 struct section sec = { ((void *)0), SECTION_TEXT, -1 };
 va_list l;
 __builtin_va_start(l,fmt);
 asm_out_sectionv(&sec, fmt, l);
 __builtin_va_end(l);
}

canonical_original_code:
void stylef(char *fmt, ...)
{
 struct section sec = { ((void *)0), SECTION_TEXT, -1 };
 __builtin_va_list l;
 __builtin_va_start(l,fmt);
 asm_out_sectionv(&sec, fmt, l);
 __builtin_va_end(l);
}

variable_types: struct section { char *name; int builtin; enum section_flags { SECTION_FLAG_EXECUTABLE=expr, SECTION_FLAG_RO=expr } flags; }

user_defined_types: struct section { char *name; int builtin; enum section_flags flags; }


decompiled_code:
__int64 __fastcall pack_to_align(__int64 a1, unsigned int a2)
{
if ( !a2 )
_assert_fail("align > 0", "pack.c", 0xAu, "pack_to_align");
return -a2 & (a1 + a2 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
if ( !a2 )
_assert_fail("align > 0", "pack.c", 0xAu, "pack_to_align");
return -a2 & (a1 + a2 - 1);
}

original_code:
pack_t pack_to_align(pack_t sz, unsigned align)
{
 ((align > 0) ? (void) (0) : __assert_fail ("align > 0", "pack.c", 10, __extension__ __PRETTY_FUNCTION__));
 return (sz + align - 1) & -align;
}

canonical_original_code:
unsigned long pack_to_align(unsigned long sz, unsigned int align)
{
 ((align > 0) ? (void) (0) : __assert_fail ("align > 0", "pack.c", 10, __extension__ __PRETTY_FUNCTION__));
 return (sz + align - 1) & -align;
}

variable_types:
sz
unsigned long

variable_types:
align
unsigned int

return_type: unsigned long


decompiled_code:
__int64 __fastcall pack_to_word(__int64 a1)
{
unsigned int v1; // esi

v1 = pws_0;
if ( !pws_0 )
{
pws_0 = platform_word_size();
v1 = pws_0;
}
return pack_to_align(a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // esi

v1 = pws_0;
if ( !pws_0 )
{
pws_0 = platform_word_size();
v1 = pws_0;
}
return func0(a1, v1);
}

original_code:
pack_t pack_to_word(pack_t o)
{
 static unsigned pws;
 if(!pws)
  pws = platform_word_size();
 return pack_to_align(o, pws);
}

canonical_original_code:
unsigned long pack_to_word(unsigned long o)
{
 static unsigned int pws;
 if(!pws)
  pws = platform_word_size();
 return pack_to_align(o, pws);
}

variable_types:
o
unsigned long

variable_types:
pws
unsigned int


rtrim

decompiled_code:
size_t __fastcall rtrim(const char *a1)
{
size_t result; // rax
size_t i; // rbx

result = strlen(a1);
for ( i = result; ; --i )
{
if ( !i )
{
*a1 = 0;
return result;
}
result = (size_t)*_ctype_b_loc();
if ( (*(_BYTE *)(result + 2LL * a1[i - 1] + 1) & 0x20) == 0 )
break;
}
a1[i] = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
size_t result; // rax
size_t i; // rbx

result = strlen(a1);
for ( i = result; ; --i )
{
if ( !i )
{
*a1 = 0;
return result;
}
result = (size_t)*_ctype_b_loc();
if ( (*(_BYTE *)(result + 2LL * a1[i - 1] + 1) & 0x20) == 0 )
break;
}
a1[i] = 0;
return result;
}

original_code:
void rtrim(char *s)
{
 size_t l = strlen(s);
 while(l > 0 && ((*__ctype_b_loc ())[(int) ((s[l-1]))] & (unsigned short int) _ISspace))
  l--;
 s[l] = '\0';
}

canonical_original_code:
void rtrim(char *s)
{
 unsigned long l = strlen(s);
 while(l > 0 && ((*__ctype_b_loc ())[(int) ((s[l-1]))] & (unsigned short) _ISspace))
  l--;
 s[l] = '\0';
}

variable_types:
s
char *

variable_types:
l
unsigned long


decompiled_code:
const char *str_stmt_goto()
{
return "goto";
}

canonical_decompiled_code:
const char *func1()
{
return "goto";
}

original_code:
const char *str_stmt_goto(void)
{
 return "goto";
}


decompiled_code:
const char *str_expr__Generic()
{
return "_Generic";
}

canonical_decompiled_code:
const char *func0()
{
return "_Generic";
}

original_code:
const char *str_expr__Generic(void)
{
 return "_Generic";
}


decompiled_code:
const char *str_expr_sizeof()
{
return "sizeof/typeof/alignof";
}

canonical_decompiled_code:
const char *func1()
{
return "sizeof/typeof/alignof";
}

original_code:
const char *str_expr_sizeof(void)
{
 return "sizeof/typeof/alignof";
}


decompiled_code:
const char *str_stmt_switch()
{
return "switch";
}

canonical_decompiled_code:
const char *func4()
{
return "switch";
}

original_code:
const char *str_stmt_switch(void)
{
 return "switch";
}


decompiled_code:
const char *str_stmt_expr()
{
return "expression";
}

canonical_decompiled_code:
const char *func2()
{
return "expression";
}

original_code:
const char *str_stmt_expr(void)
{
 return "expression";
}


decompiled_code:
const char *str_stmt_default()
{
return "default";
}

canonical_decompiled_code:
const char *func0()
{
return "default";
}

original_code:
const char *str_stmt_default(void)
{
 return "default";
}


decompiled_code:
void *str_stmt_for()
{
return &unk_47B;
}

canonical_decompiled_code:
void *func2()
{
return &unk_47B;
}

original_code:
const char *str_stmt_for(void)
{
 return "for";
}

canonical_original_code:
char *str_stmt_for()
{
 return "for";
}


decompiled_code:
const char *str_expr_block()
{
return "block";
}

canonical_decompiled_code:
const char *func0()
{
return "block";
}

original_code:
const char *str_expr_block(void)
{
 return "block";
}


decompiled_code:
const char *str_expr_compound_lit()
{
return "compound-lit";
}

canonical_decompiled_code:
const char *func0()
{
return "compound-lit";
}

original_code:
const char *str_expr_compound_lit(void)
{
 return "compound-lit";
}


decompiled_code:
const char *str_expr_identifier()
{
return "identifier";
}

canonical_decompiled_code:
const char *func0()
{
return "identifier";
}

original_code:
const char *str_expr_identifier(void)
{
 return "identifier";
}


decompiled_code:
const char *str_stmt_noop()
{
return "noop";
}

canonical_decompiled_code:
const char *func0()
{
return "noop";
}

original_code:
const char *str_stmt_noop(void)
{
 return "noop";
}


test

decompiled_code:
int __fastcall test(int a1, const char *a2)
{
int result; // eax

if ( !a1 )
{
ec = 1;
result = fprintf(stderr, "test failed: %s\n", a2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, const char *a2)
{
int result; // eax

if ( !a1 )
{
ec = 1;
result = fprintf(stderr, "test failed: %s\n", a2);
}
return result;
}

original_code:
static void test(int cond, const char *expr, int line)
{
 if(!cond){
  ec = 1;
  fprintf(stderr, "%s:%d: test failed: %s\n", "test.c", line, expr);
 }
}

canonical_original_code:
static void test(int cond, char *expr, int line)
{
 if(!cond){
  ec = 1;
  fprintf(stderr, "%s:%d: test failed: %s\n", "test.c", line, expr);
 }
}

variable_types: cond int

variable_types:
expr
char *

variable_types: line int


icw

decompiled_code:
int icw(const char *a1, unsigned int a2, const char *a3, const char *a4, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a4);
fprintf(stderr, "%s:%d: %s: ", a1, a2, a3);
vfprintf(stderr, a4, arg);
result = fputc(10, stderr);
ec = 1;
return result;
}

canonical_decompiled_code:
int func8(const char *a1, unsigned int a2, const char *a3, const char *a4, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a4);
fprintf(stderr, "%s:%d: %s: ", a1, a2, a3);
vfprintf(stderr, a4, arg);
result = fputc(10, stderr);
ec = 1;
return result;
}

original_code:
void icw(const char *f, int line, const char *fn, const char *fmt, ...)
{
 va_list l;
 __builtin_va_start(l,fmt);
 ice_msg("ICW", f, line, fn, fmt, l);
 __builtin_va_end(l);
}

canonical_original_code:
void icw(char *f, int line, char *fn, char *fmt, ...)
{
 __builtin_va_list l;
 __builtin_va_start(l,fmt);
 ice_msg("ICW", f, line, fn, fmt, l);
 __builtin_va_end(l);
}

variable_types:
f
char *

variable_types:
fn
char *


ice

decompiled_code:
void __fastcall __noreturn ice(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "%s:%d: ice: %s\n", a1, a2, a3);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "%s:%d: ice: %s\n", a1, a2, a3);
exit(1);
}

original_code:
void ice(const char *f, int line, const char *fn, const char *fmt, ...)
{
 va_list l;
 __builtin_va_start(l,fmt);
 ice_msg("ICE", f, line, fn, fmt, l);
 __builtin_va_end(l);
 abort();
}

canonical_original_code:
void ice(char *f, int line, char *fn, char *fmt, ...)
{
 __builtin_va_list l;
 __builtin_va_start(l,fmt);
 ice_msg("ICE", f, line, fn, fmt, l);
 __builtin_va_end(l);
 abort();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_dynmap(argc, argv, envp);
test_dynarray();
test_canon_all();
test_math();
test_str();
return ec;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func11(argc, argv, envp);
func2();
func4();
func5();
func6();
return ec;
}

original_code:
int main(void)
{
 cc1_type_nav = type_nav_init();
 test_quals();
 test_decl_interposability();
 test_decl_needs_GOTPLT();
 test_warnings();
 test_out_out();
 return ec;
}

canonical_original_code:
int main()
{
 cc1_type_nav = type_nav_init();
 test_quals();
 test_decl_interposability();
 test_decl_needs_GOTPLT();
 test_warnings();
 test_out_out();
 return ec;
}


decompiled_code:
bool __fastcall sanitize_opt_add(const char *a1, const char *a2)
{
bool v2; // zf
bool result; // al

v2 = strcmp(a2, "undefined") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize = -1537;
}
else
{
v2 = strcmp(a2, "shift") == 0;
result = !v2;
if ( v2 || (v2 = strcmp(a2, "shift-exponent") == 0, result = !v2, v2) )
{
cc1_sanitize |= 1u;
}
else
{
v2 = strcmp(a2, "vla-bound") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 2u;
}
else
{
v2 = strcmp(a2, "signed-integer-overflow") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 4u;
}
else
{
v2 = strcmp(a2, "bounds") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 8u;
}
else
{
v2 = strcmp(a2, "nonnull-attribute") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x10u;
}
else
{
v2 = strcmp(a2, "integer-divide-by-zero") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x20u;
}
else
{
v2 = strcmp(a2, "unreachable") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x40u;
}
else
{
v2 = strcmp(a2, "null") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x80u;
}
else
{
v2 = strcmp(a2, "alignment") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x100u;
}
else
{
v2 = strcmp(a2, "float-divide-by-zero") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x200u;
}
else
{
v2 = strcmp(a2, "float-cast-overflow") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x400u;
}
else
{
v2 = strcmp(a2, "returns-nonnull-attribute") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x800u;
}
else
{
v2 = strcmp(a2, "bool") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x1000u;
}
else
{
v2 = strcmp(a2, "pointer-overflow") == 0;
result = !v2;
if ( !v2 )
{
fprintf(stderr, "%s: unknown sanitize option '%s'\n", a1, a2);
exit(1);
}
cc1_sanitize |= 0x2000u;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(const char *a1, const char *a2)
{
bool v2; // zf
bool result; // al

v2 = strcmp(a2, "undefined") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize = -1537;
}
else
{
v2 = strcmp(a2, "shift") == 0;
result = !v2;
if ( v2 || (v2 = strcmp(a2, "shift-exponent") == 0, result = !v2, v2) )
{
cc1_sanitize |= 1u;
}
else
{
v2 = strcmp(a2, "vla-bound") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 2u;
}
else
{
v2 = strcmp(a2, "signed-integer-overflow") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 4u;
}
else
{
v2 = strcmp(a2, "bounds") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 8u;
}
else
{
v2 = strcmp(a2, "nonnull-attribute") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x10u;
}
else
{
v2 = strcmp(a2, "integer-divide-by-zero") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x20u;
}
else
{
v2 = strcmp(a2, "unreachable") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x40u;
}
else
{
v2 = strcmp(a2, "null") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x80u;
}
else
{
v2 = strcmp(a2, "alignment") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x100u;
}
else
{
v2 = strcmp(a2, "float-divide-by-zero") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x200u;
}
else
{
v2 = strcmp(a2, "float-cast-overflow") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x400u;
}
else
{
v2 = strcmp(a2, "returns-nonnull-attribute") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x800u;
}
else
{
v2 = strcmp(a2, "bool") == 0;
result = !v2;
if ( v2 )
{
cc1_sanitize |= 0x1000u;
}
else
{
v2 = strcmp(a2, "pointer-overflow") == 0;
result = !v2;
if ( !v2 )
{
fprintf(stderr, "%s: unknown sanitize option '%s'\n", a1, a2);
exit(1);
}
cc1_sanitize |= 0x2000u;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
void sanitize_opt_add(const char *argv0, const char *san)
{
 if(!strcmp(san, "undefined")){
  cc1_sanitize |= ~0u;
  cc1_sanitize &= ~(SAN_FLOAT_DIVIDE_BY_ZERO | SAN_FLOAT_CAST_OVERFLOW);
  return;
 }else if(!strcmp(san, "shift")){
  cc1_sanitize |= SAN_SHIFT_EXPONENT;
  return;
 }
 if(!strcmp(san, "shift-exponent")){ cc1_sanitize |= SAN_SHIFT_EXPONENT; return; } if(!strcmp(san, "vla-bound")){ cc1_sanitize |= SAN_VLA_BOUND; return; } if(!strcmp(san, "signed-integer-overflow")){ cc1_sanitize |= SAN_SIGNED_INTEGER_OVERFLOW; return; } if(!strcmp(san, "bounds")){ cc1_sanitize |= SAN_BOUNDS; return; } if(!strcmp(san, "nonnull-attribute")){ cc1_sanitize |= SAN_NONNULL_ATTRIBUTE; return; } if(!strcmp(san, "integer-divide-by-zero")){ cc1_sanitize |= SAN_INTEGER_DIVIDE_BY_ZERO; return; } if(!strcmp(san, "unreachable")){ cc1_sanitize |= SAN_UNREACHABLE; return; } if(!strcmp(san, "null")){ cc1_sanitize |= SAN_NULL; return; } if(!strcmp(san, "alignment")){ cc1_sanitize |= SAN_ALIGNMENT; return; } if(!strcmp(san, "float-divide-by-zero")){ cc1_sanitize |= SAN_FLOAT_DIVIDE_BY_ZERO; return; } if(!strcmp(san, "float-cast-overflow")){ cc1_sanitize |= SAN_FLOAT_CAST_OVERFLOW; return; } if(!strcmp(san, "returns-nonnull-attribute")){ cc1_sanitize |= SAN_RETURNS_NONNULL_ATTRIBUTE; return; } if(!strcmp(san, "bool")){ cc1_sanitize |= SAN_BOOL; return; } if(!strcmp(san, "pointer-overflow")){ cc1_sanitize |= SAN_POINTER_OVERFLOW; return; }
 fprintf(stderr, "%s: unknown sanitize option '%s'\n", argv0, san);
 exit(1);
}

canonical_original_code:
void sanitize_opt_add(char *argv0, char *san)
{
 if(!strcmp(san, "undefined")){
  cc1_sanitize |= ~0u;
  cc1_sanitize &= ~(SAN_FLOAT_DIVIDE_BY_ZERO | SAN_FLOAT_CAST_OVERFLOW);
  return;
 }else if(!strcmp(san, "shift")){
  cc1_sanitize |= SAN_SHIFT_EXPONENT;
  return;
 }
 if(!strcmp(san, "shift-exponent")){ cc1_sanitize |= SAN_SHIFT_EXPONENT; return; } if(!strcmp(san, "vla-bound")){ cc1_sanitize |= SAN_VLA_BOUND; return; } if(!strcmp(san, "signed-integer-overflow")){ cc1_sanitize |= SAN_SIGNED_INTEGER_OVERFLOW; return; } if(!strcmp(san, "bounds")){ cc1_sanitize |= SAN_BOUNDS; return; } if(!strcmp(san, "nonnull-attribute")){ cc1_sanitize |= SAN_NONNULL_ATTRIBUTE; return; } if(!strcmp(san, "integer-divide-by-zero")){ cc1_sanitize |= SAN_INTEGER_DIVIDE_BY_ZERO; return; } if(!strcmp(san, "unreachable")){ cc1_sanitize |= SAN_UNREACHABLE; return; } if(!strcmp(san, "null")){ cc1_sanitize |= SAN_NULL; return; } if(!strcmp(san, "alignment")){ cc1_sanitize |= SAN_ALIGNMENT; return; } if(!strcmp(san, "float-divide-by-zero")){ cc1_sanitize |= SAN_FLOAT_DIVIDE_BY_ZERO; return; } if(!strcmp(san, "float-cast-overflow")){ cc1_sanitize |= SAN_FLOAT_CAST_OVERFLOW; return; } if(!strcmp(san, "returns-nonnull-attribute")){ cc1_sanitize |= SAN_RETURNS_NONNULL_ATTRIBUTE; return; } if(!strcmp(san, "bool")){ cc1_sanitize |= SAN_BOOL; return; } if(!strcmp(san, "pointer-overflow")){ cc1_sanitize |= SAN_POINTER_OVERFLOW; return; }
 fprintf(stderr, "%s: unknown sanitize option '%s'\n", argv0, san);
 exit(1);
}

variable_types:
san
char *


decompiled_code:
char __fastcall sanitize_opt_set_error(const char *a1, const char *a2)
{
const char *v3; // rbp
_BYTE *v4; // rax
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx

v3 = a2;
free(cc1_sanitize_handler_fn);
cc1_sanitize_handler_fn = 0LL;
LOBYTE(v4) = strcmp(a2, "trap") != 0;
v5 = 0;
v6 = (_BYTE)v4 == 0;
if ( (_BYTE)v4 )
{
v7 = "call=";
v8 = 5LL;
do
{
if ( !v8 )
break;
v5 = *a2 < (unsigned int)*v7;
v6 = *a2++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) != v5 )
{
fprintf(stderr, "%s: unknown sanitize handler '%s'\n", a1, v3);
exit(1);
}
v4 = (_BYTE *)ustrdup(v3 + 5, a2);
cc1_sanitize_handler_fn = v4;
if ( !*v4 )
{
fprintf(stderr, "%s: empty sanitize function handler\n", a1);
exit(1);
}
}
return (char)v4;
}

canonical_decompiled_code:
char __fastcall func1(const char *a1, const char *a2)
{
const char *v3; // rbp
_BYTE *v4; // rax
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx

v3 = a2;
free(cc1_sanitize_handler_fn);
cc1_sanitize_handler_fn = 0LL;
LOBYTE(v4) = strcmp(a2, "trap") != 0;
v5 = 0;
v6 = (_BYTE)v4 == 0;
if ( (_BYTE)v4 )
{
v7 = "call=";
v8 = 5LL;
do
{
if ( !v8 )
break;
v5 = *a2 < (unsigned int)*v7;
v6 = *a2++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) != v5 )
{
fprintf(stderr, "%s: unknown sanitize handler '%s'\n", a1, v3);
exit(1);
}
v4 = (_BYTE *)ustrdup(v3 + 5, a2);
cc1_sanitize_handler_fn = v4;
if ( !*v4 )
{
fprintf(stderr, "%s: empty sanitize function handler\n", a1);
exit(1);
}
}
return (char)v4;
}

original_code:
void sanitize_opt_set_error(const char *argv0, const char *handler)
{
 free(cc1_sanitize_handler_fn);
 cc1_sanitize_handler_fn = ((void *)0);
 if(!strcmp(handler, "trap")){
 }else if(!strncmp(handler, "call=", 5)){
  cc1_sanitize_handler_fn = ustrdup(handler + 5);
  if(!*cc1_sanitize_handler_fn){
   fprintf(stderr, "%s: empty sanitize function handler\n", argv0);
   exit(1);
  }
 }else{
  fprintf(stderr, "%s: unknown sanitize handler '%s'\n", argv0, handler);
  exit(1);
 }
}

canonical_original_code:
void sanitize_opt_set_error(char *argv0, char *handler)
{
 free(cc1_sanitize_handler_fn);
 cc1_sanitize_handler_fn = ((void *)0);
 if(!strcmp(handler, "trap")){
 }else if(!strncmp(handler, "call=", 5)){
  cc1_sanitize_handler_fn = ustrdup(handler + 5);
  if(!*cc1_sanitize_handler_fn){
   fprintf(stderr, "%s: empty sanitize function handler\n", argv0);
   exit(1);
  }
 }else{
  fprintf(stderr, "%s: unknown sanitize handler '%s'\n", argv0, handler);
  exit(1);
 }
}

variable_types:
handler
char *


decompiled_code:
void sanitize_opt_off()
{
cc1_sanitize = 0;
cc1_fopt[48] = 0;
}

canonical_decompiled_code:
void func2()
{
cc1_sanitize = 0;
cc1_fopt[48] = 0;
}

original_code:
void sanitize_opt_off(void)
{
 cc1_sanitize = 0;
 cc1_fopt.trapv = 0;
}

canonical_original_code:
void sanitize_opt_off()
{
 cc1_sanitize = 0;
 cc1_fopt.trapv = 0;
}


decompiled_code:
__int64 __fastcall sanitize_enabled(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 != 128 )
{
if ( a1 <= 0x80 )
{
if ( a1 <= 0x20 )
{
if ( a1 )
{
switch ( a1 )
{
case 1u:
case 2u:
case 4u:
case 8u:
case 0x10u:
case 0x20u:
goto LABEL_8;
default:
return a1 & cc1_sanitize;
}
}
return a1 & cc1_sanitize;
}
if ( a1 != 64 )
return a1 & cc1_sanitize;
}
else if ( a1 != 2048 )
{
if ( a1 <= 0x800 )
{
if ( a1 != 1024 && ((a1 - 256) & 0xFFFFFEFF) != 0 )
return a1 & cc1_sanitize;
}
else if ( ((a1 - 4096) & 0xFFFFEFFF) != 0 )
{
return a1 & cc1_sanitize;
}
}
}
LABEL_8:
result = 0LL;
if ( (a2 & 1) == 0 )
return a1 & cc1_sanitize;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 != 128 )
{
if ( a1 <= 0x80 )
{
if ( a1 <= 0x20 )
{
if ( a1 )
{
switch ( a1 )
{
case 1u:
case 2u:
case 4u:
case 8u:
case 0x10u:
case 0x20u:
goto LABEL_8;
default:
return a1 & cc1_sanitize;
}
}
return a1 & cc1_sanitize;
}
if ( a1 != 64 )
return a1 & cc1_sanitize;
}
else if ( a1 != 2048 )
{
if ( a1 <= 0x800 )
{
if ( a1 != 1024 && ((a1 - 256) & 0xFFFFFEFF) != 0 )
return a1 & cc1_sanitize;
}
else if ( ((a1 - 4096) & 0xFFFFEFFF) != 0 )
{
return a1 & cc1_sanitize;
}
}
}
LABEL_8:
result = 0LL;
if ( (a2 & 1) == 0 )
return a1 & cc1_sanitize;
return result;
}

original_code:
int sanitize_enabled(enum san_opts opt, enum no_sanitize disabled)
{
 switch(opt){
 case SAN_SHIFT_EXPONENT: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_VLA_BOUND: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_SIGNED_INTEGER_OVERFLOW: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_BOUNDS: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_NONNULL_ATTRIBUTE: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_INTEGER_DIVIDE_BY_ZERO: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_UNREACHABLE: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_NULL: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_ALIGNMENT: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_FLOAT_DIVIDE_BY_ZERO: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_FLOAT_CAST_OVERFLOW: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_RETURNS_NONNULL_ATTRIBUTE: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_BOOL: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break; case SAN_POINTER_OVERFLOW: if(disabled & (NO_SANITIZE_UNDEFINED)) return 0; break;
 }
 return cc1_sanitize & opt;
}

variable_types: enum san_opts { SAN_SHIFT_EXPONENT=expr, SAN_VLA_BOUND=expr, SAN_SIGNED_INTEGER_OVERFLOW=expr, SAN_BOUNDS=expr, SAN_NONNULL_ATTRIBUTE=expr, SAN_INTEGER_DIVIDE_BY_ZERO=expr, SAN_UNREACHABLE=expr, SAN_NULL=expr, SAN_ALIGNMENT=expr, SAN_FLOAT_DIVIDE_BY_ZERO=expr, SAN_FLOAT_CAST_OVERFLOW=expr, SAN_RETURNS_NONNULL_ATTRIBUTE=expr, SAN_BOOL=expr, SAN_POINTER_OVERFLOW=expr }

variable_types: enum no_sanitize { NO_SANITIZE_UNDEFINED=expr }


decompiled_code:
void *str_stmt_do()
{
return &unk_1EB;
}

canonical_decompiled_code:
void *func1()
{
return &unk_1EB;
}

original_code:
const char *str_stmt_do(void)
{
 return "do";
}

canonical_original_code:
char *str_stmt_do()
{
 return "do";
}


decompiled_code:
void __fastcall align_sz(unsigned int *a1, unsigned int a2)
{
if ( *a1 < a2 )
*a1 = pack_to_align();
}

canonical_decompiled_code:
void __fastcall func0(unsigned int *a1, unsigned int a2)
{
if ( *a1 < a2 )
*a1 = pack_to_align();
}

original_code:
static void align_sz(unsigned *psz, unsigned align)
{
 if(align > *psz)
  *psz = pack_to_align(*psz, align);
}

canonical_original_code:
static void align_sz(unsigned int *psz, unsigned int align)
{
 if(align > *psz)
  *psz = pack_to_align(*psz, align);
}

variable_types:
psz
unsigned int *


decompiled_code:
__int64 test_rtrim()
{
__int64 result; // rax
__int128 v1[2]; // [rsp+0h] [rbp-28h] BYREF

*((_QWORD *)&v1[0] + 1) = 32LL;
*(_QWORD *)&v1[0] = 0x2020333231636261LL;
v1[1] = 0LL;
rtrim(v1);
if ( strcmp((const char *)v1, "abc123") )
_assert_fail("!strcmp(buf, \"abc123\")", "test.c", 0x18u, "test_rtrim");
LODWORD(v1[0]) = 2105376;
rtrim(v1);
if ( LOBYTE(v1[0]) )
_assert_fail("!strcmp(buf, \"\")", "test.c", 0x1Cu, "test_rtrim");
result = rtrim(v1);
if ( LOBYTE(v1[0]) )
_assert_fail("!strcmp(buf, \"\")", "test.c", 0x20u, "test_rtrim");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int128 v1[2]; // [rsp+0h] [rbp-28h] BYREF

*((_QWORD *)&v1[0] + 1) = 32LL;
*(_QWORD *)&v1[0] = 0x2020333231636261LL;
v1[1] = 0LL;
rtrim(v1);
if ( strcmp((const char *)v1, "abc123") )
_assert_fail("!strcmp(buf, \"abc123\")", "test.c", 0x18u, "test_rtrim");
LODWORD(v1[0]) = 2105376;
rtrim(v1);
if ( LOBYTE(v1[0]) )
_assert_fail("!strcmp(buf, \"\")", "test.c", 0x1Cu, "test_rtrim");
result = rtrim(v1);
if ( LOBYTE(v1[0]) )
_assert_fail("!strcmp(buf, \"\")", "test.c", 0x20u, "test_rtrim");
return result;
}

original_code:
static void test_rtrim(void)
{
 char buf[32] = { 0 };
 strcpy(buf, "abc123   ");
 rtrim(buf);
 ((!strcmp(buf, "abc123")) ? (void) (0) : __assert_fail ("!strcmp(buf, \"abc123\")", "test.c", 24, __extension__ __PRETTY_FUNCTION__));
 strcpy(buf, "   ");
 rtrim(buf);
 ((!strcmp(buf, "")) ? (void) (0) : __assert_fail ("!strcmp(buf, \"\")", "test.c", 28, __extension__ __PRETTY_FUNCTION__));
 strcpy(buf, "");
 rtrim(buf);
 ((!strcmp(buf, "")) ? (void) (0) : __assert_fail ("!strcmp(buf, \"\")", "test.c", 32, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
static void test_rtrim()
{
 char buf[32] = { 0 };
 strcpy(buf, "abc123   ");
 rtrim(buf);
 ((!strcmp(buf, "abc123")) ? (void) (0) : __assert_fail ("!strcmp(buf, \"abc123\")", "test.c", 24, __extension__ __PRETTY_FUNCTION__));
 strcpy(buf, "   ");
 rtrim(buf);
 ((!strcmp(buf, "")) ? (void) (0) : __assert_fail ("!strcmp(buf, \"\")", "test.c", 28, __extension__ __PRETTY_FUNCTION__));
 strcpy(buf, "");
 rtrim(buf);
 ((!strcmp(buf, "")) ? (void) (0) : __assert_fail ("!strcmp(buf, \"\")", "test.c", 32, __extension__ __PRETTY_FUNCTION__));
}

variable_types:
buf
char [32]


ice

decompiled_code:
void __noreturn ice()
{
abort();
}

canonical_decompiled_code:
void __noreturn func1()
{
abort();
}

original_code:
void ice(const char *f, int line, const char *fn, const char *fmt, ...)
{
 (void)f;
 (void)line;
 (void)fn;
 (void)fmt;
 abort();
}

canonical_original_code:
void ice(char *f, int line, char *fn, char *fmt, ...)
{
 (void)f;
 (void)line;
 (void)fn;
 (void)fmt;
 abort();
}

variable_types:
fmt
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_rtrim(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
return 0;
}

original_code:
int main(void)
{
 test_rtrim();
 return 0;
}

canonical_original_code:
int main()
{
 test_rtrim();
 return 0;
}


decompiled_code:
// attributes: thunk
void __fastcall expr_free_abi(void *a1)
{
expr_free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
func2(a1);
}

original_code:
void expr_free_abi(void *e)
{
 expr_free(e);
}

variable_types:
e
void *


decompiled_code:
const char *str_expr_stmt()
{
return "statement";
}

canonical_decompiled_code:
const char *func0()
{
return "statement";
}

original_code:
const char *str_expr_stmt(void)
{
 return "statement";
}


decompiled_code:
__int64 __fastcall leb128_length(__int64 a1, int a2)
{
__int64 v2; // rax
bool v3; // dl
__int64 v4; // rdi
bool v5; // zf
__int64 result; // rax
__int64 v7; // rdx
bool v8; // cl
unsigned __int64 v9; // rdi

if ( a2 )
{
v2 = a1 & 0x40;
v3 = (a1 & 0x40) != 0;
v4 = a1 >> 7;
v5 = (v4 | v2) == 0;
result = 1LL;
if ( !v5 && (v4 != -1 || !v3) )
{
do
{
result = (unsigned int)(result + 1);
v7 = v4 & 0x40;
v8 = (v4 & 0x40) != 0;
v4 >>= 7;
}
while ( v4 | v7 && (v4 != -1 || !v8) );
}
}
else
{
v9 = (unsigned __int64)a1 >> 7;
for ( result = 1LL; v9; v9 >>= 7 )
result = (unsigned int)(result + 1);
}
return result;
}

original_code:
unsigned leb128_length(unsigned long long value, int is_signed)
{
 unsigned len = 1;
 if(is_signed){
  signed long long sv = value;
  for(;;){
   int sign_bit_set = !!(sv & 0x40);
   sv >>= 7;
   if((sv == 0 && !sign_bit_set)
   || (sv == -1 && sign_bit_set))
   {
    break;
   }
   len++;
  }
 }else{
  for(;;){
   value >>= 7;
   if(!value)
    break;
   len++;
  }
 }
 return len;
}

canonical_original_code:
unsigned int leb128_length(unsigned long long value, int is_signed)
{
 unsigned int len = 1;
 if(is_signed){
  long long sv = value;
  for(;;){
   int sign_bit_set = !!(sv & 0x40);
   sv >>= 7;
   if((sv == 0 && !sign_bit_set)
   || (sv == -1 && sign_bit_set))
   {
    break;
   }
   len++;
  }
 }else{
  for(;;){
   value >>= 7;
   if(!value)
    break;
   len++;
  }
 }
 return len;
}

variable_types:
value
unsigned long long

variable_types:
len
unsigned int

variable_types:
sv
long long

return_type: unsigned int


decompiled_code:
const char *str_stmt_while()
{
return "while";
}

canonical_decompiled_code:
const char *func1()
{
return "while";
}

original_code:
const char *str_stmt_while(void)
{
 return "while";
}


decompiled_code:
const char *str_stmt_label()
{
return "label";
}

canonical_decompiled_code:
const char *func1()
{
return "label";
}

original_code:
const char *str_stmt_label(void)
{
 return "label";
}


decompiled_code:
const char *str_stmt_return()
{
return "return";
}

canonical_decompiled_code:
const char *func0()
{
return "return";
}

original_code:
const char *str_stmt_return(void)
{
 return "return";
}


decompiled_code:
const char *str_expr_assign()
{
return "assignment";
}

canonical_decompiled_code:
const char *func0()
{
return "assignment";
}

original_code:
const char *str_expr_assign(void)
{
 return "assignment";
}


picfilter

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

result = a1;
if ( !cc1_fopt[19] )
result = 0LL;
return result;
}

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

result = a1;
if ( !cc1_fopt[19] )
result = 0LL;
return result;
}

original_code:
static enum out_pic_type picfilter(enum out_pic_type flags)
{
 return ((&cc1_fopt)->pic || (&cc1_fopt)->pie) ? flags : OUT_LBL_NOPIC;
}

variable_types: enum out_pic_type { OUT_LBL_NOPIC=0, OUT_LBL_PIC=expr, OUT_LBL_PICLOCAL=expr }


decompiled_code:
char *__fastcall sym_to_str(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 2 )
result = CSWTCH_22[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func17(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 2 )
result = CSWTCH_22[a1];
return result;
}

original_code:
const char *sym_to_str(enum sym_type t)
{
 switch(t){
  case sym_local: return "local";
  case sym_arg: return "arg";
  case sym_global: return "global";
 }
 return ((void *)0);
}

variable_types: enum sym_type { sym_global=0, sym_local=1, sym_arg=2 }


repo: bobrippling/uvi

decompiled_code:
char *__fastcall file_generic(__int64 a1)
{
char *v1; // rcx

v1 = getenv("HOME");
if ( !v1 )
v1 = (char *)&unk_160;
snprintf(fname_0, 0x100uLL, "%s/.uvi%s", v1, a1);
return fname_0;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
char *v1; // rcx

v1 = getenv("HOME");
if ( !v1 )
v1 = (char *)&unk_160;
snprintf(fname_0, 0x100uLL, "%s/.uvi%s", v1, a1);
return fname_0;
}

original_code:
static const char *file_generic(const char *suffix)
{
 static char fname[256];
 const char *home = getenv("HOME");
 if(!home)
  home = "";
 snprintf(fname, sizeof fname, "%s/.uvi%s", home, suffix);
 return fname;
}

canonical_original_code:
static char *file_generic(char *suffix)
{
 static char fname[256];
 char *home = getenv("HOME");
 if(!home)
  home = "";
 snprintf(fname, sizeof fname, "%s/.uvi%s", home, suffix);
 return fname;
}

variable_types:
suffix
char *

variable_types:
fname
char [256]

variable_types:
home
char *


decompiled_code:
char *file_rc()
{
return file_generic((__int64)"rc");
}

canonical_decompiled_code:
char *func1()
{
return func0((__int64)"rc");
}

original_code:
const char *file_rc(void)
{
 return file_generic("rc");
}

canonical_original_code:
char *file_rc()
{
 return file_generic("rc");
}


decompiled_code:
char *file_info()
{
return file_generic((__int64)"info");
}

canonical_decompiled_code:
char *func2()
{
return func0((__int64)"info");
}

original_code:
const char *file_info(void)
{
 return file_generic("info");
}

canonical_original_code:
char *file_info()
{
 return file_generic("info");
}


decompiled_code:
FILE *input_reopen()
{
FILE *result; // rax
int *v1; // rax
char *v2; // rax

fclose(stdin);
result = fopen("/dev/tty", "r");
stdin = result;
if ( !result )
{
gui_term();
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "uvi: freopen(\"/dev/tty\", \"r\", stdin) = %s\n", v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
FILE *func0()
{
FILE *result; // rax
int *v1; // rax
char *v2; // rax

fclose(stdin);
result = fopen("/dev/tty", "r");
stdin = result;
if ( !result )
{
gui_term();
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "uvi: freopen(\"/dev/tty\", \"r\", stdin) = %s\n", v2);
exit(1);
}
return result;
}

original_code:
void input_reopen()
{
 fclose(stdin);
 stdin = fopen("/dev/tty", "r");
 if(!stdin){
  gui_term();
  fprintf(stderr, "uvi: freopen(\"/dev/tty\", \"r\", stdin) = %s\n", strerror((*__errno_location ())));
  exit(1);
 }
}


decompiled_code:
int chomp_line()
{
int v0; // ebp
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v2);
v2.c_lflag &= 0xFFFFFFF5;
v2.c_cc[6] = 1;
tcsetattr(0, 0, &v2);
v0 = getchar();
v2.c_lflag |= 0xAu;
v2.c_cc[6] = 0;
tcsetattr(0, 0, &v2);
return ungetch(v0);
}

canonical_decompiled_code:
int func1()
{
int v0; // ebp
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v2);
v2.c_lflag &= 0xFFFFFFF5;
v2.c_cc[6] = 1;
tcsetattr(0, 0, &v2);
v0 = getchar();
v2.c_lflag |= 0xAu;
v2.c_cc[6] = 0;
tcsetattr(0, 0, &v2);
return ungetch(v0);
}

original_code:
void chomp_line()
{
 int c;
 struct termios attr;
 tcgetattr(0, &attr);
 attr.c_cc[6] = sizeof(char);
 attr.c_lflag &= ~(0000002 | 0000010);
 tcsetattr(0, 0, &attr);
 c = getchar();
 attr.c_cc[6] = 0;
 attr.c_lflag |= 0000002 | 0000010;
 tcsetattr(0, 0, &attr);
 ungetch(c);
}

variable_types: c int

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


decompiled_code:
__int64 buffer_new_empty()
{
_BYTE *v0; // rax

v0 = (_BYTE *)umalloc(1LL);
*v0 = 0;
return buffer_new(v0);
}

canonical_decompiled_code:
__int64 func2()
{
_BYTE *v0; // rax

v0 = (_BYTE *)umalloc(1LL);
*v0 = 0;
return func1(v0);
}

canonical_original_code:
struct buffer_t *buffer_new_empty()
{
 char *s = umalloc(sizeof(char));
 *s = '\0';
 return buffer_new(s);
}

variable_types:
s
char *

return_type: struct buffer_t { struct list { void *data; struct list *next; } *lines; char *fname; int readonly; int modified; int eol; int crlf; int dirty; int nlines; int touched_fs; long opentime; } *

user_defined_types: struct buffer_t { struct list *lines; char *fname; int readonly; int modified; int eol; int crlf; int dirty; int nlines; int touched_fs; long opentime; }


decompiled_code:
void __fastcall buffer_setfilename(__int64 a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax

free(*(void **)(a1 + 8));
if ( a2 )
{
v2 = strlen(a2);
v3 = (char *)umalloc(v2 + 1);
*(_QWORD *)(a1 + 8) = v3;
strcpy(v3, a2);
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax

free(*(void **)(a1 + 8));
if ( a2 )
{
v2 = strlen(a2);
v3 = (char *)umalloc(v2 + 1);
*(_QWORD *)(a1 + 8) = v3;
strcpy(v3, a2);
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
}

original_code:
void buffer_setfilename(buffer_t *b, const char *s)
{
 free(b->fname);
 if(s){
  b->fname = umalloc(strlen(s) + 1);
  strcpy(b->fname, s);
 }else
  b->fname = ((void *)0);
}

canonical_original_code:
void buffer_setfilename(struct buffer_t *b, char *s)
{
 free(b->fname);
 if(s){
  b->fname = umalloc(strlen(s) + 1);
  strcpy(b->fname, s);
 }else
  b->fname = ((void *)0);
}

variable_types: struct buffer_t { struct list { void *data; struct list *next; } *lines; char *fname; int readonly; int modified; int eol; int crlf; int dirty; int nlines; int touched_fs; long opentime; } *


decompiled_code:
_BOOL8 __fastcall is_crlf(__int64 *a1)
{
__int64 v1; // rbp
size_t v2; // r8
__int64 v3; // rax
const char *v4; // rbx
_BOOL4 v5; // er8

v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
v4 = *(const char **)v1;
if ( !*(_QWORD *)v1 )
break;
if ( !*v4 )
return 0LL;
v2 = strlen(*(const char **)v1);
v3 = *(_QWORD *)(v1 + 8);
if ( v4[v2 - 1] != 13 )
{
v5 = 0;
if ( !v3 )
v5 = *(_QWORD *)(v1 + 16) != 0LL;
return v5;
}
if ( !v3 )
break;
v1 = *(_QWORD *)(v1 + 8);
}
}
return 1;
}

original_code:
int is_crlf(buffer_t *b)
{
 struct list *l;
 for(l = b->lines; l && l->data; l = l->next){
  char *s = l->data;
  if(!*s)
   return 0;
  if(s[strlen(s)-1] != '\r'){
   if(l->next)
    return 0;
   else
    return !!l->prev;
  }
 }
 return 1;
}

canonical_original_code:
int is_crlf(struct buffer_t *b)
{
 struct list *l;
 for(l = b->lines; l && l->data; l = l->next){
  char *s = l->data;
  if(!*s)
   return 0;
  if(s[strlen(s)-1] != '\r'){
   if(l->next)
    return 0;
   else
    return !!l->prev;
  }
 }
 return 1;
}

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


decompiled_code:
__int64 __fastcall buffer_write(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)list_gethead(*a1);
return buffer_write_list((__int64)a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)list_gethead(*a1);
return func5((__int64)a1, v1);
}

original_code:
int buffer_write(buffer_t *b)
{
 return buffer_write_list(b, list_gethead(b->lines));
}

canonical_original_code:
int buffer_write(struct buffer_t *b)
{
 return buffer_write_list(b, list_gethead(b->lines));
}

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


decompiled_code:
void __fastcall buffer_free_nolist(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void buffer_free_nolist(buffer_t *b)
{
 if(b){
  free(b->fname);
  free(b);
 }
}

canonical_original_code:
void buffer_free_nolist(struct buffer_t *b)
{
 if(b){
  free(b->fname);
  free(b);
 }
}


decompiled_code:
void __fastcall buffer_free(void *ptr)
{
if ( ptr )
{
list_free(*(_QWORD *)ptr, &free);
buffer_free_nolist(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
if ( ptr )
{
list_free(*(_QWORD *)ptr, &free);
func7(ptr);
}
}

original_code:
void buffer_free(buffer_t *b)
{
 if(b){
  list_free(b->lines, free);
  buffer_free_nolist(b);
 }
}

canonical_original_code:
void buffer_free(struct buffer_t *b)
{
 if(b){
  list_free(b->lines, free);
  buffer_free_nolist(b);
 }
}


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

result = list_free(*(_QWORD *)a1, &free);
*(_QWORD *)a1 = a2;
*(_DWORD *)(a1 + 32) = 1;
return result;
}

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

result = list_free(*(_QWORD *)a1, &free);
*(_QWORD *)a1 = a2;
*(_DWORD *)(a1 + 32) = 1;
return result;
}

original_code:
void buffer_replace(buffer_t *b, struct list *l)
{
 list_free(b->lines, free);
 b->lines = l;
 b->dirty = 1;
}

canonical_original_code:
void buffer_replace(struct buffer_t *b, struct list *l)
{
 list_free(b->lines, free);
 b->lines = l;
 b->dirty = 1;
}

variable_types:
l
struct list *


decompiled_code:
__int64 __fastcall buffer_nchars(_QWORD *a1)
{
const char **v1; // rax
const char *v2; // rdi
const char **v3; // rbx
unsigned int v4; // er12
int v5; // eax

v1 = (const char **)list_gethead(*a1);
v2 = *v1;
if ( !*v1 )
return 1LL;
v3 = v1;
v4 = 0;
while ( 1 )
{
v5 = strlen(v2);
v3 = (const char **)v3[1];
v4 += v5;
if ( !v3 )
break;
v2 = *v3;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
const char **v1; // rax
const char *v2; // rdi
const char **v3; // rbx
unsigned int v4; // er12
int v5; // eax

v1 = (const char **)list_gethead(*a1);
v2 = *v1;
if ( !*v1 )
return 1LL;
v3 = v1;
v4 = 0;
while ( 1 )
{
v5 = strlen(v2);
v3 = (const char **)v3[1];
v4 += v5;
if ( !v3 )
break;
v2 = *v3;
}
return v4;
}

original_code:
int buffer_nchars(buffer_t *b)
{
 struct list *l = list_gethead(b->lines);
 int chars = 0;
 if(!l->data)
  return 1;
 while(l){
  chars += strlen(l->data);
  l = l->next;
 }
 return chars;
}

canonical_original_code:
int buffer_nchars(struct buffer_t *b)
{
 struct list *l = list_gethead(b->lines);
 int chars = 0;
 if(!l->data)
  return 1;
 while(l){
  chars += strlen(l->data);
  l = l->next;
 }
 return chars;
}

variable_types: chars int


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

if ( !*(_DWORD *)(a1 + 32) )
return *(unsigned int *)(a1 + 36);
result = list_count(*(_QWORD *)a1);
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 36) = result;
return result;
}

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

if ( !*(_DWORD *)(a1 + 32) )
return *(unsigned int *)(a1 + 36);
result = list_count(*(_QWORD *)a1);
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 36) = result;
return result;
}

original_code:
int buffer_nlines(buffer_t *b)
{
 if(b->dirty){
  b->nlines = list_count(b->lines);
  b->dirty = 0;
 }
 return b->nlines;
}

canonical_original_code:
int buffer_nlines(struct buffer_t *b)
{
 if(b->dirty){
  b->nlines = list_count(b->lines);
  b->dirty = 0;
 }
 return b->nlines;
}


original_code:
struct list *buffer_extract_range(buffer_t *buffer, struct range *rng)
{
 struct list *l, *newpos, *extracted;
 l = list_getindex(buffer->lines, rng->start);
 extracted = list_extract_range(&l, rng->end - rng->start + 1);
 newpos = l;
 if(!(l = list_getindex(newpos, rng->start)))
  l = list_gettail(newpos);
 buffer->lines = l = list_gethead(l);
 if(!l->data){
  l->data = umalloc(sizeof(char));
  *(char *)l->data = '\0';
 }
 buffer->dirty = 1;
 return extracted;
}

canonical_original_code:
struct list *buffer_extract_range(struct buffer_t *buffer, struct range *rng)
{
 struct list *l; struct list *newpos; struct list *extracted;
 l = list_getindex(buffer->lines, rng->start);
 extracted = list_extract_range(&l, rng->end - rng->start + 1);
 newpos = l;
 if(!(l = list_getindex(newpos, rng->start)))
  l = list_gettail(newpos);
 buffer->lines = l = list_gethead(l);
 if(!l->data){
  l->data = umalloc(sizeof(char));
  *(char *)l->data = '\0';
 }
 buffer->dirty = 1;
 return extracted;
}

variable_types: struct buffer_t { struct list *lines; char *fname; int readonly; int modified; int eol; int crlf; int dirty; int nlines; int touched_fs; long opentime; } *

variable_types:
rng
struct range { int start; } *

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


decompiled_code:
__int64 __fastcall buffer_remove_range(__int64 a1, unsigned int *a2)
{
__int64 v2; // rax

v2 = buffer_extract_range(a1, a2);
return list_free(v2, &free);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int *a2)
{
__int64 v2; // rax

v2 = func13(a1, a2);
return list_free(v2, &free);
}

original_code:
void buffer_remove_range(buffer_t *buffer, struct range *rng)
{
 list_free(buffer_extract_range(buffer, rng), free);
}

canonical_original_code:
void buffer_remove_range(struct buffer_t *buffer, struct range *rng)
{
 list_free(buffer_extract_range(buffer, rng), free);
}


decompiled_code:
_BOOL8 __fastcall buffer_file_exists(__int64 a1)
{
const char *v1; // rdi
_BOOL8 result; // rax

v1 = *(const char **)(a1 + 8);
if ( v1 )
result = access(v1, 0) == 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1)
{
const char *v1; // rdi
_BOOL8 result; // rax

v1 = *(const char **)(a1 + 8);
if ( v1 )
result = access(v1, 0) == 0;
else
result = 0LL;
return result;
}

original_code:
int buffer_file_exists(buffer_t *b)
{
 return (!!(b)->fname) && access(((b)->fname ? (b)->fname : "(no name)"), 0) == 0;
}

canonical_original_code:
int buffer_file_exists(struct buffer_t *b)
{
 return (!!(b)->fname) && access(((b)->fname ? (b)->fname : "(no name)"), 0) == 0;
}


decompiled_code:
_BOOL8 __fastcall buffer_external_modified(__int64 a1)
{
const char *v2; // rdi
_BOOL8 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = *(const char **)(a1 + 8);
if ( !v2 || stat(v2, &v4) )
result = 0LL;
else
result = v4.st_ctim.tv_sec > *(_QWORD *)(a1 + 48);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(__int64 a1)
{
const char *v2; // rdi
_BOOL8 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = *(const char **)(a1 + 8);
if ( !v2 || stat(v2, &v4) )
result = 0LL;
else
result = v4.st_ctim.tv_sec > *(_QWORD *)(a1 + 48);
return result;
}

original_code:
int buffer_external_modified(buffer_t *b)
{
 struct stat st;
 if(!(!!(b)->fname))
  return 0;
 if(stat(((b)->fname ? (b)->fname : "(no name)"), &st))
  return 0;
 return st.st_ctim.tv_sec > ((b)->opentime);
}

canonical_original_code:
int buffer_external_modified(struct buffer_t *b)
{
 struct stat st;
 if(!(!!(b)->fname))
  return 0;
 if(stat(((b)->fname ? (b)->fname : "(no name)"), &st))
  return 0;
 return st.st_ctim.tv_sec > ((b)->opentime);
}

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

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:
void __fastcall macro_set(char a1, __int64 a2)
{
__int64 v2; // rbx
void *v3; // rdi

v2 = a1 - 97;
v3 = (void *)macros[v2];
if ( v3 )
free(v3);
macros[v2] = a2;
}

canonical_decompiled_code:
void __fastcall func0(char a1, __int64 a2)
{
__int64 v2; // rbx
void *v3; // rdi

v2 = a1 - 97;
v3 = (void *)macros[v2];
if ( v3 )
free(v3);
macros[v2] = a2;
}

original_code:
void macro_set(char c, char *s)
{
 int i = c - 'a';
 if(macros[i])
  free(macros[i]);
 macros[i] = s;
}

variable_types: c char

variable_types: i int


decompiled_code:
void __fastcall macro_play(char a1)
{
__int64 v1; // rdi
__int64 v2; // rbp

v1 = a1 - 97;
v2 = macros[v1];
if ( v2 )
{
if ( *(_BYTE *)(v2 + (int)(strlen((const char *)macros[v1]) - 1)) != 27 )
gui_ungetch(27LL);
gui_queue(v2);
}
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
__int64 v1; // rdi
__int64 v2; // rbp

v1 = a1 - 97;
v2 = macros[v1];
if ( v2 )
{
if ( *(_BYTE *)(v2 + (int)(strlen((const char *)macros[v1]) - 1)) != 27 )
gui_ungetch(27LL);
gui_queue(v2);
}
}

original_code:
void macro_play(char c)
{
 const char *iter = macros[c - 'a'];
 if(iter){
  int last = strlen(iter) - 1;
  if(iter[last] != '\x1b')
   gui_ungetch('\x1b');
  gui_queue(iter);
 }
}

canonical_original_code:
void macro_play(char c)
{
 char *iter = macros[c - 'a'];
 if(iter){
  int last = strlen(iter) - 1;
  if(iter[last] != '\x1b')
   gui_ungetch('\x1b');
  gui_queue(iter);
 }
}

variable_types:
iter
char *

variable_types: last int


decompiled_code:
_BOOL8 __fastcall macro_char_valid(int a1)
{
return (unsigned int)(a1 - 97) <= 0x19;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
return (unsigned int)(a1 - 97) <= 0x19;
}

original_code:
int macro_char_valid(int c)
{
 return 'a' <= c && c <= 'z';
}


decompiled_code:
void __fastcall map_free(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void map_free(void *p)
{
 free(((struct map *)p)->cmd);
 free(p);
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall map_add(char a1, __int64 a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rbp
__int64 v4; // rax

v2 = (_BYTE *)umalloc(16LL);
*v2 = a1;
v3 = v2;
v4 = ustrdup(a2);
*((_QWORD *)v3 + 1) = v4;
str_escape(v4);
return list_append(maps, v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, __int64 a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rbp
__int64 v4; // rax

v2 = (_BYTE *)umalloc(16LL);
*v2 = a1;
v3 = v2;
v4 = ustrdup(a2);
*((_QWORD *)v3 + 1) = v4;
str_escape(v4);
return list_append(maps, v3);
}

original_code:
void map_add(char c, const char *cmd)
{
 struct map *m = umalloc(sizeof *m);
 m->c = c;
 m->cmd = ustrdup(cmd);
 str_escape(m->cmd);
 list_append(maps, m);
}

canonical_original_code:
void map_add(char c, char *cmd)
{
 struct map *m = umalloc(sizeof *m);
 m->c = c;
 m->cmd = ustrdup(cmd);
 str_escape(m->cmd);
 list_append(maps, m);
}

variable_types:
cmd
char *

variable_types:
m
struct map { char c; char *cmd; } *


map

decompiled_code:
char *__fastcall map(__int64 a1, __int64 a2)
{
char *result; // rax
__int64 v3; // rbx
char v4; // cl
unsigned int v5; // er12
__int64 v6; // rcx
__int64 v7; // rdx

result = (char *)gui_getch(0LL);
v3 = maps;
v4 = 1;
v5 = (unsigned int)result;
if ( maps )
{
v6 = 0LL;
while ( 1 )
{
result = *(char **)v3;
if ( !*(_QWORD *)v3 )
break;
v7 = (unsigned int)*result;
if ( (_DWORD)v7 == v5 )
{
result = (char *)gui_queue(*((_QWORD *)result + 1), a2, v7, v6);
v3 = *(_QWORD *)(v3 + 8);
v6 = 1LL;
if ( !v3 )
break;
}
else
{
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
break;
}
}
v4 = v6 ^ 1;
}
if ( v5 != 27 )
{
if ( v4 )
result = (char *)gui_status(1LL, "map %c not defined", v5);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int64 a2)
{
char *result; // rax
__int64 v3; // rbx
char v4; // cl
unsigned int v5; // er12
__int64 v6; // rcx
__int64 v7; // rdx

result = (char *)gui_getch(0LL);
v3 = maps;
v4 = 1;
v5 = (unsigned int)result;
if ( maps )
{
v6 = 0LL;
while ( 1 )
{
result = *(char **)v3;
if ( !*(_QWORD *)v3 )
break;
v7 = (unsigned int)*result;
if ( (_DWORD)v7 == v5 )
{
result = (char *)gui_queue(*((_QWORD *)result + 1), a2, v7, v6);
v3 = *(_QWORD *)(v3 + 8);
v6 = 1LL;
if ( !v3 )
break;
}
else
{
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
break;
}
}
v4 = v6 ^ 1;
}
if ( v5 != 27 )
{
if ( v4 )
result = (char *)gui_status(1LL, "map %c not defined", v5);
}
return result;
}

original_code:
void map()
{
 struct list *l;
 int found = 0;
 int c = gui_getch(GETCH_COOKED);
 for(l = maps; l && l->data; l = l->next){
  struct map *m = l->data;
  if(m->c == c){
   gui_queue(m->cmd);
   found = 1;
  }
 }
 if(!found && c != (('[') & 037))
  gui_status(GUI_ERR, "map %c not defined", c);
}

variable_types: found int

variable_types: c int


decompiled_code:
__int64 map_init()
{
__int64 result; // rax

result = list_new(0LL);
maps = result;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

result = list_new(0LL);
maps = result;
return result;
}

original_code:
void map_init()
{
 maps = list_new(((void *)0));
}


decompiled_code:
__int64 map_term()
{
return list_free(maps, map_free);
}

canonical_decompiled_code:
__int64 func4()
{
return list_free(maps, map_free);
}

original_code:
void map_term()
{
 list_free(maps, map_free);
}


decompiled_code:
__int64 map_getall()
{
return maps;
}

canonical_decompiled_code:
__int64 func5()
{
return maps;
}

original_code:
struct list *map_getall()
{
 return maps;
}


decompiled_code:
__int64 buffers_array()
{
return fnames;
}

canonical_decompiled_code:
__int64 func2()
{
return fnames;
}

original_code:
struct old_buffer **buffers_array()
{
 return fnames;
}

return_type: struct old_buffer { char *fname; int last_y; int read; } **


decompiled_code:
__int64 buffers_idx()
{
return (unsigned int)current;
}

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

original_code:
int buffers_idx()
{
 return current;
}

canonical_original_code:
int buffers_idx()
{
 return current;
}


decompiled_code:
__int64 buffers_count()
{
return (unsigned int)count;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)count;
}

original_code:
int buffers_count()
{
 return count;
}

canonical_original_code:
int buffers_count()
{
 return count;
}


decompiled_code:
__int64 buffers_alternate()
{
__int64 result; // rax

if ( last == -1 )
result = 0LL;
else
result = **(_QWORD **)(fnames + 8LL * last);
return result;
}

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

if ( last == -1 )
result = 0LL;
else
result = **(_QWORD **)(fnames + 8LL * last);
return result;
}

original_code:
const char *buffers_alternate(void)
{
 if(last == -1)
  return ((void *)0);
 return fnames[last]->fname;
}

canonical_original_code:
char *buffers_alternate()
{
 if(last == -1)
  return ((void *)0);
 return fnames[last]->fname;
}


decompiled_code:
__int64 buffers_alternate_idx()
{
return (unsigned int)last;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)last;
}

original_code:
int buffers_alternate_idx()
{
 return last;
}


decompiled_code:
__int64 buffers_save_pos()
{
__int64 result; // rax
__int64 v1; // rbx

result = current;
if ( current >= 0 && current < count )
{
v1 = *(_QWORD *)(fnames + 8LL * current);
result = gui_y();
*(_DWORD *)(v1 + 8) = result;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
__int64 v1; // rbx

result = current;
if ( current >= 0 && current < count )
{
v1 = *(_QWORD *)(fnames + 8LL * current);
result = gui_y();
*(_DWORD *)(v1 + 8) = result;
}
return result;
}

original_code:
void buffers_save_pos()
{
 if(0 <= current && current < count)
  fnames[current]->last_y = gui_y();
}


decompiled_code:
__int64 __fastcall buffers_goto(int a1)
{
unsigned int v1; // er12
int v2; // ebp
int v3; // eax
__int64 v4; // rax
__int64 v5; // rax

v1 = 1;
if ( a1 >= 0 && count > a1 )
{
v2 = current;
v3 = current;
if ( current != a1 )
{
buffers_save_pos();
v3 = current;
}
last = v3;
v4 = a1;
current = a1;
if ( current_buf )
{
buffer_free();
v4 = current;
}
current_buf = buffers_readfname(**(const char ***)(fnames + 8 * v4));
if ( arg_ro )
*(_DWORD *)(buffers_current() + 16) = 1;
v1 = 0;
v5 = *(_QWORD *)(fnames + 8LL * a1);
*(_DWORD *)(v5 + 12) = 1;
gui_move(*(unsigned int *)(v5 + 8), 0LL);
if ( v2 != a1 )
{
gui_scrollclear = 0;
gui_scroll(6LL);
gui_scrollclear = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
unsigned int v1; // er12
int v2; // ebp
int v3; // eax
__int64 v4; // rax
__int64 v5; // rax

v1 = 1;
if ( a1 >= 0 && count > a1 )
{
v2 = current;
v3 = current;
if ( current != a1 )
{
func8();
v3 = current;
}
last = v3;
v4 = a1;
current = a1;
if ( current_buf )
{
buffer_free();
v4 = current;
}
current_buf = func1(**(const char ***)(fnames + 8 * v4));
if ( arg_ro )
*(_DWORD *)(func4() + 16) = 1;
v1 = 0;
v5 = *(_QWORD *)(fnames + 8LL * a1);
*(_DWORD *)(v5 + 12) = 1;
gui_move(*(unsigned int *)(v5 + 8), 0LL);
if ( v2 != a1 )
{
gui_scrollclear = 0;
gui_scroll(6LL);
gui_scrollclear = 1;
}
}
return v1;
}

original_code:
int buffers_goto(int n)
{
 extern int gui_scrollclear;
 int loadpos;
 if(n < 0 || n >= count)
  return 1;
 if((loadpos = current != n))
  buffers_save_pos();
 last = current;
 current = n;
 if(current_buf)
  buffer_free(current_buf);
 current_buf = buffers_readfname(fnames[current]->fname);
 if(arg_ro)
  ((buffers_current())->readonly) = 1;
 fnames[n]->read = 1;
 gui_move(fnames[n]->last_y, 0);
 if(loadpos){
  gui_scrollclear = 0;
  gui_scroll(CURSOR_MIDDLE);
  gui_scrollclear = 1;
 }
 return 0;
}

variable_types: n int

variable_types: loadpos int


decompiled_code:
__int64 __fastcall buffers_init(int a1, const char **a2, int a3)
{
const char **v3; // r12
int v5; // ebx
__int64 v6; // r13
__int64 v7; // rbp
_QWORD *v8; // rax
const char *v9; // r14
const char **v10; // r15
__int64 result; // rax
_OWORD *v12; // rax
bool v13; // cc
__int64 v14; // rax
__int64 v15; // [rsp+10h] [rbp-48h]
int v16; // [rsp+1Ch] [rbp-3Ch]

v3 = a2;
v5 = a1;
if ( a1 <= 0 || **a2 != 45 || (*a2)[1] )
{
v16 = 0;
++a1;
}
else
{
v3 = a2 + 1;
fwrite("uvi: reading from stdin\n", 1uLL, 0x18uLL, stderr);
v16 = 1;
v5 = a1 - 1;
}
arg_ro = a3;
v6 = 0LL;
v7 = 0LL;
count = v5;
v8 = (_QWORD *)umalloc(8LL * a1);
v15 = (__int64)v8;
fnames = (__int64)v8;
if ( count <= 0 )
{
count = 0;
*v8 = 0LL;
}
else
{
do
{
while ( 1 )
{
v9 = v3[v7];
if ( v7 )
break;
LABEL_13:
++v7;
v12 = new_old_buf((__int64)v9);
v13 = count <= (int)v7;
*(_QWORD *)(v15 + 8 * v6) = v12;
v6 = (int)v6 + 1;
v15 = fnames;
if ( v13 )
goto LABEL_10;
}
v10 = v3;
while ( strcmp(v9, *v10) )
{
if ( &v3[(unsigned int)(v7 - 1) + 1] == ++v10 )
goto LABEL_13;
}
++v7;
}
while ( count > (int)v7 );
LABEL_10:
count = v6;
*(_QWORD *)(v15 + 8LL * (int)v6) = 0LL;
if ( (_DWORD)v6 )
{
current = 0;
if ( !v16 )
return buffers_goto(0);
goto LABEL_17;
}
}
current = -1;
if ( v16 )
{
LABEL_17:
v14 = buffers_readfile((__int64)stdin, "-", 1);
*(_DWORD *)(v14 + 20) = 1;
current_buf = v14;
result = input_reopen();
current = -1;
return result;
}
result = buffer_new_empty();
current_buf = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, const char **a2, int a3)
{
const char **v3; // r12
int v5; // ebx
__int64 v6; // r13
__int64 v7; // rbp
_QWORD *v8; // rax
const char *v9; // r14
const char **v10; // r15
__int64 result; // rax
_OWORD *v12; // rax
bool v13; // cc
__int64 v14; // rax
__int64 v15; // [rsp+10h] [rbp-48h]
int v16; // [rsp+1Ch] [rbp-3Ch]

v3 = a2;
v5 = a1;
if ( a1 <= 0 || **a2 != 45 || (*a2)[1] )
{
v16 = 0;
++a1;
}
else
{
v3 = a2 + 1;
fwrite("uvi: reading from stdin\n", 1uLL, 0x18uLL, stderr);
v16 = 1;
v5 = a1 - 1;
}
arg_ro = a3;
v6 = 0LL;
v7 = 0LL;
count = v5;
v8 = (_QWORD *)umalloc(8LL * a1);
v15 = (__int64)v8;
fnames = (__int64)v8;
if ( count <= 0 )
{
count = 0;
*v8 = 0LL;
}
else
{
do
{
while ( 1 )
{
v9 = v3[v7];
if ( v7 )
break;
LABEL_13:
++v7;
v12 = new_old_buf((__int64)v9);
v13 = count <= (int)v7;
*(_QWORD *)(v15 + 8 * v6) = v12;
v6 = (int)v6 + 1;
v15 = fnames;
if ( v13 )
goto LABEL_10;
}
v10 = v3;
while ( strcmp(v9, *v10) )
{
if ( &v3[(unsigned int)(v7 - 1) + 1] == ++v10 )
goto LABEL_13;
}
++v7;
}
while ( count > (int)v7 );
LABEL_10:
count = v6;
*(_QWORD *)(v15 + 8LL * (int)v6) = 0LL;
if ( (_DWORD)v6 )
{
current = 0;
if ( !v16 )
return func9(0);
goto LABEL_17;
}
}
current = -1;
if ( v16 )
{
LABEL_17:
v14 = func0((__int64)stdin, "-", 1);
*(_DWORD *)(v14 + 20) = 1;
current_buf = v14;
result = input_reopen();
current = -1;
return result;
}
result = buffer_new_empty();
current_buf = result;
return result;
}

original_code:
void buffers_init(int argc, const char **argv, int ro)
{
 int i, bufidx;
 int read_stdin = 0;
 if(argc > 0 && !strcmp(argv[0], "-")){
  argc--;
  argv++;
  read_stdin = 1;
  fputs("uvi: reading from stdin\n", stderr);
 }
 count = argc;
 arg_ro = ro;
 fnames = umalloc((count + 1) * sizeof *fnames);
 bufidx = 0;
 for(i = 0; i < count; i++){
  int j, found = 0;
  for(j = 0; j < i; j++)
   if(!strcmp(argv[i], argv[j])){
    found = 1;
    break;
   }
  if(!found)
   fnames[bufidx++] = new_old_buf(argv[i]);
 }
 fnames[count = bufidx] = ((void *)0);
 current = count > 0 ? 0 : -1;
 if(read_stdin){
  current_buf = buffers_readfile(stdin, "-", 1);
  ((current_buf)->modified) = 1;
  input_reopen();
  current = -1;
 }else if(count > 0){
  buffers_goto(0);
 }else{
  current_buf = buffer_new_empty();
 }
}

canonical_original_code:
void buffers_init(int argc, char **argv, int ro)
{
 int i; int bufidx;
 int read_stdin = 0;
 if(argc > 0 && !strcmp(argv[0], "-")){
  argc--;
  argv++;
  read_stdin = 1;
  fputs("uvi: reading from stdin\n", stderr);
 }
 count = argc;
 arg_ro = ro;
 fnames = umalloc((count + 1) * sizeof *fnames);
 bufidx = 0;
 for(i = 0; i < count; i++){
  int j; int found = 0;
  for(j = 0; j < i; j++)
   if(!strcmp(argv[i], argv[j])){
    found = 1;
    break;
   }
  if(!found)
   fnames[bufidx++] = new_old_buf(argv[i]);
 }
 fnames[count = bufidx] = ((void *)0);
 current = count > 0 ? 0 : -1;
 if(read_stdin){
  current_buf = buffers_readfile(stdin, "-", 1);
  ((current_buf)->modified) = 1;
  input_reopen();
  current = -1;
 }else if(count > 0){
  buffers_goto(0);
 }else{
  current_buf = buffer_new_empty();
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ro int

variable_types: bufidx int

variable_types: j int


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

if ( current == -1 )
result = buffers_goto(0);
else
result = buffers_goto(a1 + current);
return result;
}

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

if ( current == -1 )
result = func9(0);
else
result = func9(a1 + current);
return result;
}

original_code:
int buffers_next(int n)
{
 if(current == -1)
  return buffers_goto(0);
 return buffers_goto(current + n);
}


decompiled_code:
__int64 __fastcall buffers_del(int a1)
{
__int64 result; // rax
int v2; // ebp
__int64 v3; // r14
__int64 v4; // r12
void **v5; // r13
int v6; // ebp

result = 1LL;
if ( a1 >= 0 )
{
v2 = count;
if ( count > a1 )
{
v3 = fnames;
v4 = 8LL * a1;
v5 = (void **)(fnames + v4);
free(**(void ***)(fnames + v4));
free(*v5);
if ( last == a1 )
last = -1;
v6 = v2 - 1;
memmove(v5, (const void *)(v3 + v4 + 8), 8LL * (unsigned int)(v6 - a1) + 8);
count = v6;
if ( current == a1 )
{
current = -1;
result = 0LL;
}
else
{
result = 0LL;
if ( current > a1 )
--current;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 result; // rax
int v2; // ebp
__int64 v3; // r14
__int64 v4; // r12
void **v5; // r13
int v6; // ebp

result = 1LL;
if ( a1 >= 0 )
{
v2 = count;
if ( count > a1 )
{
v3 = fnames;
v4 = 8LL * a1;
v5 = (void **)(fnames + v4);
free(**(void ***)(fnames + v4));
free(*v5);
if ( last == a1 )
last = -1;
v6 = v2 - 1;
memmove(v5, (const void *)(v3 + v4 + 8), 8LL * (unsigned int)(v6 - a1) + 8);
count = v6;
if ( current == a1 )
{
current = -1;
result = 0LL;
}
else
{
result = 0LL;
if ( current > a1 )
--current;
}
}
}
return result;
}

original_code:
int buffers_del(int n)
{
 int i;
 if(n < 0 || n >= count)
  return 1;
 free(fnames[n]->fname);
 free(fnames[n]);
 if(last == n)
  last = -1;
 for(i = n; i < count; i++)
  fnames[i] = fnames[i + 1];
 count--;
 if(current == n)
  current = -1;
 else if(current > n)
  current--;
 return 0;
}


decompiled_code:
__int64 buffers_first_unread()
{
__int64 result; // rax

if ( count <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_DWORD *)(*(_QWORD *)(fnames + 8 * result) + 12LL) )
{
if ( ++result == count )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax

if ( count <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_DWORD *)(*(_QWORD *)(fnames + 8 * result) + 12LL) )
{
if ( ++result == count )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int buffers_first_unread()
{
 int i;
 for(i = 0; i < count; i++)
  if(!fnames[i]->read)
   return i;
 return -1;
}


decompiled_code:
_BOOL8 buffers_unread()
{
return (unsigned int)buffers_first_unread() != -1;
}

canonical_decompiled_code:
_BOOL8 func14()
{
return (unsigned int)func13() != -1;
}

original_code:
int buffers_unread()
{
 return buffers_first_unread() != -1;
}


decompiled_code:
__int64 __fastcall buffers_find(char *s2)
{
__int64 v1; // r12
const char **v2; // rax
__int64 v3; // rbx

v1 = fnames;
v2 = *(const char ***)fnames;
if ( !*(_QWORD *)fnames )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(*v2, s2) )
{
++v3;
v2 = *(const char ***)(v1 + 8 * v3);
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *s2)
{
__int64 v1; // r12
const char **v2; // rax
__int64 v3; // rbx

v1 = fnames;
v2 = *(const char ***)fnames;
if ( !*(_QWORD *)fnames )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(*v2, s2) )
{
++v3;
v2 = *(const char ***)(v1 + 8 * v3);
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

original_code:
int buffers_find(const char *fname)
{
 struct old_buffer **iter;
 int i;
 for(i = 0, iter = fnames; *iter; iter++, i++)
  if(!strcmp((*iter)->fname, fname))
   return i;
 return -1;
}

canonical_original_code:
int buffers_find(char *fname)
{
 struct old_buffer **iter;
 int i;
 for(i = 0, iter = fnames; *iter; iter++, i++)
  if(!strcmp((*iter)->fname, fname))
   return i;
 return -1;
}

variable_types:
fname
char *

variable_types: struct old_buffer { char *fname; int last_y; int read; } **


decompiled_code:
__int64 __fastcall buffers_add(char *a1)
{
unsigned int v1; // er12
__int64 v3; // rbx
__int64 v4; // rax
_QWORD *v5; // rbx
_OWORD *v6; // rax
__int64 v7; // rdx

v1 = buffers_find(a1);
if ( v1 == -1 )
{
v1 = count;
v3 = count + 2;
++count;
v3 *= 8LL;
v4 = urealloc(fnames, v3);
v5 = (_QWORD *)(v4 + v3 - 16);
fnames = v4;
v6 = new_old_buf((__int64)a1);
v7 = count;
*v5 = v6;
*(_QWORD *)(fnames + 8 * v7) = 0LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1)
{
unsigned int v1; // er12
__int64 v3; // rbx
__int64 v4; // rax
_QWORD *v5; // rbx
_OWORD *v6; // rax
__int64 v7; // rdx

v1 = func15(a1);
if ( v1 == -1 )
{
v1 = count;
v3 = count + 2;
++count;
v3 *= 8LL;
v4 = urealloc(fnames, v3);
v5 = (_QWORD *)(v4 + v3 - 16);
fnames = v4;
v6 = new_old_buf((__int64)a1);
v7 = count;
*v5 = v6;
*(_QWORD *)(fnames + 8 * v7) = 0LL;
}
return v1;
}

original_code:
int buffers_add(const char *fname)
{
 int i;
 if((i = buffers_find(fname)) != -1)
  return i;
 i = count++;
 fnames = urealloc(fnames, (count + 1) * sizeof *fnames);
 fnames[i] = new_old_buf(fname);
 fnames[count] = ((void *)0);
 return i;
}

canonical_original_code:
int buffers_add(char *fname)
{
 int i;
 if((i = buffers_find(fname)) != -1)
  return i;
 i = count++;
 fnames = urealloc(fnames, (count + 1) * sizeof *fnames);
 fnames[i] = new_old_buf(fname);
 fnames[count] = ((void *)0);
 return i;
}

variable_types: i int


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

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 func17(char *s2)
{
int v1; // eax
_BOOL4 v2; // er8

v1 = func15(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);
}


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

buffers_save_pos();
if ( s2 )
{
v2 = buffers_find(s2);
if ( v2 == -1 )
v2 = buffers_add(s2);
result = buffers_goto(v2);
}
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 func18(char *s2)
{
int v2; // edi
__int64 result; // rax

func8();
if ( s2 )
{
v2 = func15(s2);
if ( v2 == -1 )
v2 = func16(s2);
result = func9(v2);
}
else
{
if ( current_buf )
buffer_free();
current_buf = func1(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);
 }
}


umalloc

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

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

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

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

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 *


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

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

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

v2 = a2 - (_DWORD)src;
v3 = (char *)func0(v2 + 1);
result = strncpy(v3, src, v2);
result[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; // r12

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; // r12

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:
p
void *

variable_types:
n
void *


ustrprintf

decompiled_code:
char *ustrprintf(char *f, ...)
{
char *v2; // [rsp+0h] [rbp-D8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

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

canonical_decompiled_code:
char *func4(char *f, ...)
{
char *v2; // [rsp+0h] [rbp-D8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

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

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

result = (unsigned int)visual_state;
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

result = (unsigned int)visual_state;
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; // r8

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

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

func1(&visual_cursor);
v0 = &visual_anchor;
if ( (int)visual_cursor - (int)visual_anchor <= 0 )
{
v0 = &visual_cursor;
if ( (_DWORD)visual_cursor == (_DWORD)visual_anchor && SHIDWORD(visual_cursor) > SHIDWORD(visual_anchor) )
v0 = &visual_anchor;
}
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;
}


decompiled_code:
__int64 visual_swap()
{
__int64 v0; // rdx
int v1; // eax
__int64 v2; // rdi
__int64 v3; // rsi
int v5; // eax

v0 = visual_anchor;
visual_anchor = visual_cursor;
visual_cursor = v0;
v1 = gui_y();
v2 = (unsigned int)visual_cursor;
if ( v1 == (_DWORD)visual_cursor )
{
v5 = gui_x();
v3 = HIDWORD(visual_cursor);
v2 = (unsigned int)visual_cursor;
if ( v5 == HIDWORD(visual_cursor) )
return gui_move((unsigned int)visual_anchor, HIDWORD(visual_anchor));
}
else
{
v3 = HIDWORD(visual_cursor);
}
return gui_move(v2, v3);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rdx
int v1; // eax
__int64 v2; // rdi
__int64 v3; // rsi
int v5; // eax

v0 = visual_anchor;
visual_anchor = visual_cursor;
visual_cursor = v0;
v1 = gui_y();
v2 = (unsigned int)visual_cursor;
if ( v1 == (_DWORD)visual_cursor )
{
v5 = gui_x();
v3 = HIDWORD(visual_cursor);
v2 = (unsigned int)visual_cursor;
if ( v5 == HIDWORD(visual_cursor) )
return gui_move((unsigned int)visual_anchor, HIDWORD(visual_anchor));
}
else
{
v3 = HIDWORD(visual_cursor);
}
return gui_move(v2, v3);
}

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
int v5; // esi
__int64 *v6; // rdx
const char *v7; // rax
const char *v8; // r8

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 = *((_DWORD *)v3 + 1);
v6 = v3;
v7 = (const char *)&unk_2E4;
v8 = (const char *)&unk_2E5;
if ( v5 == v4 )
v8 = (const char *)&unk_2E4;
if ( (_DWORD)v1 != 1 )
v7 = (const char *)&unk_2E5;
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 *)v6 + 1),
(unsigned int)(v5 + 1),
v1,
v7,
(unsigned int)(v5 - v4 + 1),
v8);
}

canonical_decompiled_code:
__int64 func11()
{
__int64 *v0; // rbp
__int64 v1; // rbx
__int64 *v2; // rbp
__int64 *v3; // rax
int v4; // ecx
int v5; // esi
__int64 *v6; // rdx
const char *v7; // rax
const char *v8; // r8

v0 = func4();
v1 = (unsigned int)(*(_DWORD *)func5() - *(_DWORD *)v0 + 1);
v2 = func6();
v3 = func7();
v4 = *((_DWORD *)v2 + 1);
v5 = *((_DWORD *)v3 + 1);
v6 = v3;
v7 = (const char *)&unk_2E4;
v8 = (const char *)&unk_2E5;
if ( v5 == v4 )
v8 = (const char *)&unk_2E4;
if ( (_DWORD)v1 != 1 )
v7 = (const char *)&unk_2E5;
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 *)v6 + 1),
(unsigned int)(v5 + 1),
v1,
v7,
(unsigned int)(v5 - v4 + 1),
v8);
}

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; // rbp
const char **v2; // r12
const char **v3; // r13
int v4; // ebx
const char *v5; // rdi
int v6; // eax
const char *v7; // rdi
const char **v8; // r12
__int64 v9; // rcx
unsigned int v10; // er8
const char **v11; // rdx
const char *v12; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = a1;
v4 = 0x7FFFFFFF;
v5 = *a1;
do
{
v6 = strlen(v5);
if ( v4 > v6 )
v4 = v6;
v5 = v3[1];
++v3;
}
while ( v5 );
if ( v4 <= 0 )
return (unsigned int)v4;
v7 = v2[1];
v8 = v2 + 1;
v9 = 0LL;
while ( 1 )
{
v10 = v9;
if ( v7 )
break;
LABEL_13:
if ( v4 == ++v9 )
return (unsigned int)v4;
}
v11 = v8;
v12 = v7;
while ( v12[v9] == v1[v9] )
{
v12 = v11[1];
++v11;
if ( !v12 )
goto LABEL_13;
}
return v10;
}

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

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = a1;
v4 = 0x7FFFFFFF;
v5 = *a1;
do
{
v6 = strlen(v5);
if ( v4 > v6 )
v4 = v6;
v5 = v3[1];
++v3;
}
while ( v5 );
if ( v4 <= 0 )
return (unsigned int)v4;
v7 = v2[1];
v8 = v2 + 1;
v9 = 0LL;
while ( 1 )
{
v10 = v9;
if ( v7 )
break;
LABEL_13:
if ( v4 == ++v9 )
return (unsigned int)v4;
}
v11 = v8;
v12 = v7;
while ( v12[v9] == v1[v9] )
{
v12 = v11[1];
++v11;
if ( !v12 )
goto LABEL_13;
}
return v10;
}

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(__int64 *a1, int *a2, int *a3, char a4)
{
unsigned int v4; // er12
const char *v7; // rax
char *v8; // rbp
int v9; // ebx
_QWORD *v10; // rax
__int64 v11; // rax
const char **v12; // r14
unsigned int v13; // eax
__int64 v14; // rdx
__int64 v15; // rcx
int *v16; // rdx
const char **v17; // rbx
char *v18; // rdi
unsigned int v19; // [rsp+8h] [rbp-40h] BYREF
unsigned int v20[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( a4 != 14 )
return 1;
v7 = (const char *)word_at(*a1, (unsigned int)(*a3 - 1));
if ( (v8 = (char *)v7) == 0LL )
return 1;
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 )
{
v4 = 1;
gui_getyx(&v19, v20, v14, v15, v13);
gui_show_array(256LL, v19 + 1, v20[0], v12);
gui_setyx(v19, v20[0]);
}
else
{
v16 = a3;
v4 = 0;
intellisense_complete_to(a1, a2, v16, (__int64)*v12, v13, v9, 0);
}
v17 = v12;
free(v8);
v18 = (char *)*v12;
if ( !*v12 )
goto LABEL_12;
do
{
free(v18);
v18 = (char *)v17[1];
++v17;
}
while ( v18 );
if ( !*v12 )
LABEL_12:
gui_status(1LL, "no completions");
free(v12);
return v4;
}

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

if ( a4 != 14 )
return 1;
v7 = (const char *)word_at(*a1, (unsigned int)(*a3 - 1));
if ( (v8 = (char *)v7) == 0LL )
return 1;
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 )
{
v4 = 1;
gui_getyx(&v19, v20, v14, v15, v13);
gui_show_array(256LL, v19 + 1, v20[0], v12);
gui_setyx(v19, v20[0]);
}
else
{
v16 = a3;
v4 = 0;
func1(a1, a2, v16, (__int64)*v12, v13, v9, 0);
}
v17 = v12;
free(v8);
v18 = (char *)*v12;
if ( !*v12 )
goto LABEL_12;
do
{
free(v18);
v18 = (char *)v17[1];
++v17;
}
while ( v18 );
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 *