outstr

decompiled_code:
void *__fastcall outstr(__int64 a1, char *a2, int a3)
{
int v4; // er12
int v5; // er14

v4 = strlen(a2);
v5 = (a3 & 0xFFFFF) - v4;
if ( (a3 & 0x100000) == 0 )
{
outmemset(a1, 0x20u, v5);
v5 = 0;
}
outmemcpy(a1, (unsigned __int8 *)a2, v4);
return outmemset(a1, 0x20u, v5);
}

original_code:
static void outstr(struct outbuff *out, const char *s, unsigned int flags)
{
 int slen = strlen(s);
 int len = flags & 0x0fffff;
 int pad = len - slen;
 if ((flags & 0x100000) == 0) {
  outmemset(out, ' ', pad);
  pad = 0;
 }
 outmemcpy(out, s, slen);
 outmemset(out, ' ', pad);
}

canonical_original_code:
static void outstr(struct outbuff *out, char *s, unsigned int flags)
{
 int slen = strlen(s);
 int len = flags & 0x0fffff;
 int pad = len - slen;
 if ((flags & 0x100000) == 0) {
  outmemset(out, ' ', pad);
  pad = 0;
 }
 outmemcpy(out, s, slen);
 outmemset(out, ' ', pad);
}

variable_types:
s
char *

variable_types:
flags
unsigned int

variable_types: slen int

variable_types: len int

variable_types: pad int


outnum

repo: smaclennan/zedit

decompiled_code:
void *__fastcall outnum(__int64 a1, char *a2, int a3)
{
int v4; // eax
int v5; // er13

v4 = strlen(a2);
v5 = v4;
if ( (a3 & 0xFFFFF) != 0 )
outmemset(a1, (a3 & 0x200000) == 0 ? 32 : 48, (a3 & 0xFFFFF) - v4);
return outmemcpy(a1, (unsigned __int8 *)a2, v5);
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, char *a2, int a3)
{
int v4; // eax
int v5; // er13

v4 = strlen(a2);
v5 = v4;
if ( (a3 & 0xFFFFF) != 0 )
func3(a1, (a3 & 0x200000) == 0 ? 32 : 48, (a3 & 0xFFFFF) - v4);
return func2(a1, (unsigned __int8 *)a2, v5);
}

original_code:
static void outnum(struct outbuff *out, const char *s, unsigned int flags)
{
 int slen = strlen(s);
 int len = flags & 0x0fffff;
 if (len)
  outmemset(out, (flags & 0x200000) ? '0' : ' ', len - slen);
 outmemcpy(out, s, slen);
}

canonical_original_code:
static void outnum(struct outbuff *out, char *s, unsigned int flags)
{
 int slen = strlen(s);
 int len = flags & 0x0fffff;
 if (len)
  outmemset(out, (flags & 0x200000) ? '0' : ' ', len - slen);
 outmemcpy(out, s, slen);
}

variable_types: struct outbuff { struct buff { struct page { char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; char *curcptr; unsigned int curchar; int bmodf; struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; } *marks; } *buff; char *str; int len; int n; } *

return_type: void

user_defined_types: struct outbuff { struct buff *buff; char *str; int len; int n; }

user_defined_types: struct buff { struct page *firstp; struct page *lastp; struct page *curpage; char *curcptr; unsigned int curchar; int bmodf; struct mark *marks; }


decompiled_code:
__int64 __fastcall strfmt_ap(__int64 a1, int a2, unsigned __int8 *a3, int *a4)
{
__int64 result; // rax
__int64 v5[5]; // [rsp+0h] [rbp-28h] BYREF

v5[0] = 0LL;
v5[1] = a1;
v5[2] = (unsigned int)(a2 - 1);
result = 0LL;
if ( a2 > 0 )
result = _strfmt((__int64)v5, a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, unsigned __int8 *a3, int *a4)
{
__int64 result; // rax
__int64 v5[5]; // [rsp+0h] [rbp-28h] BYREF

v5[0] = 0LL;
v5[1] = a1;
v5[2] = (unsigned int)(a2 - 1);
result = 0LL;
if ( a2 > 0 )
result = func6((__int64)v5, a3, a4);
return result;
}

original_code:
int strfmt_ap(char *str, int len, const char *fmt, va_list ap)
{
 struct outbuff out = { .str = str, .len = len - 1, .n = 0 };
 if (len < 1)
  return 0;
 return __strfmt(&out, fmt, ap);
}

canonical_original_code:
int strfmt_ap(char *str, int len, char *fmt, __builtin_va_list ap)
{
 struct outbuff out = { .str = str, .len = len - 1, .n = 0 };
 if (len < 1)
  return 0;
 return __strfmt(&out, fmt, ap);
}

variable_types:
str
char *

variable_types:
fmt
char *

variable_types: struct outbuff { struct buff { struct page { char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; char *curcptr; unsigned int curchar; int bmodf; struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; } *marks; } *buff; char *str; int len; int n; }

return_type: int


strfmt

decompiled_code:
__int64 strfmt(__int64 a1, int a2, unsigned __int8 *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return strfmt_ap(a1, a2, a3, (int *)va);
}

canonical_decompiled_code:
__int64 func8(__int64 a1, int a2, unsigned __int8 *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return func7(a1, a2, a3, (int *)va);
}

original_code:
int strfmt(char *str, int len, const char *fmt, ...)
{
 va_list ap;
 int n;
 __builtin_va_start(ap,fmt);
 n = strfmt_ap(str, len, fmt, ap);
 __builtin_va_end(ap);
 return n;
}

canonical_original_code:
int strfmt(char *str, int len, char *fmt, ...)
{
 __builtin_va_list ap;
 int n;
 __builtin_va_start(ap,fmt);
 n = strfmt_ap(str, len, fmt, ap);
 __builtin_va_end(ap);
 return n;
}

variable_types: n int


binstr

decompiled_code:
__int64 binstr(__int64 a1, unsigned __int8 *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF
__int64 v4[4]; // [rsp+20h] [rbp-D8h] BYREF

va_start(va, a2);
v4[1] = 0LL;
v4[2] = 0LL;
v4[0] = a1;
return _strfmt((__int64)v4, a2, (int *)va);
}

canonical_decompiled_code:
__int64 func9(__int64 a1, unsigned __int8 *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF
__int64 v4[4]; // [rsp+20h] [rbp-D8h] BYREF

va_start(va, a2);
v4[1] = 0LL;
v4[2] = 0LL;
v4[0] = a1;
return func6((__int64)v4, a2, (int *)va);
}

original_code:
int binstr(struct buff *buff, const char *fmt, ...)
{
 struct outbuff out = { .buff = buff, .str = ((void *)0), .n = 0 };
 va_list ap;
 int rc;
 __builtin_va_start(ap,fmt);
 rc = __strfmt(&out, fmt, ap);
 __builtin_va_end(ap);
 return rc;
}

canonical_original_code:
int binstr(struct buff *buff, char *fmt, ...)
{
 struct outbuff out = { .buff = buff, .str = ((void *)0), .n = 0 };
 __builtin_va_list ap;
 int rc;
 __builtin_va_start(ap,fmt);
 rc = __strfmt(&out, fmt, ap);
 __builtin_va_end(ap);
 return rc;
}

variable_types: struct buff { struct page { char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; char *curcptr; unsigned int curchar; int bmodf; struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; } *marks; } *

variable_types: rc int


bisstart

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

original_code:
static inline int bisstart(struct buff *buff)
{
 return buff->curpage == buff->firstp && buff->curchar == 0;
}

variable_types: struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *

user_defined_types: struct buff { struct page *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; }


bisend

decompiled_code:
_BOOL8 __fastcall bisend(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

original_code:
static inline int bisend(struct buff *buff)
{
 return buff->curpage->nextp == ((void *)0) &&
  buff->curchar >= buff->curpage->plen;
}

user_defined_types: struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; }


makeoffset

original_code:
static inline void makeoffset(struct buff *buff, int dist)
{
 buff->curchar = dist;
 buff->curcptr = buff->curpage->pdata + dist;
}

variable_types: dist int


original_code:
static inline void bmove1(struct buff *buff)
{
 if (++buff->curchar < ((buff)->curpage->plen))
  ++buff->curcptr;
 else if (buff->curpage->nextp)
  makecur(buff, buff->curpage->nextp, 0);
 else
  makeoffset(buff, ((buff)->curpage->plen));
}


original_code:
int bm_search(struct buff *buff, const char *str, int sensitive)
{
 int delta[256], len, i, shift;
 len = strlen(str) - 1;
 for (i = 0; i < 256; ++i)
  delta[i] = len ? len : 1;
 if (sensitive)
  for (i = 0; i <= len; ++i)
   delta[(uint8_t)str[i]] = len - i;
 else
  for (i = 0; i <= len; ++i) {
   delta[toupper(str[i])] = len - i;
   delta[tolower(str[i])] = len - i;
  }
 while (!bisend(buff)) {
  while (!bisend(buff) && delta[((uint8_t)(*buff->curcptr))])
   bmove(buff, delta[((uint8_t)(*buff->curcptr))]);
  for (i = len;
    bequal(buff, str[i], sensitive);
    bmove(buff, -1), --i)
   if (i == 0) {
    bmove(buff, len + 1);
    return 1;
   }
  if (i + delta[((uint8_t)(*buff->curcptr))] > len)
   shift = delta[((uint8_t)(*buff->curcptr))];
  else
   shift = len - i + 1;
  bmove(buff, shift);
 }
 return 0;
}

canonical_original_code:
int bm_search(struct buff *buff, char *str, int sensitive)
{
 int delta[256]; int len; int i; int shift;
 len = strlen(str) - 1;
 for (i = 0; i < 256; ++i)
  delta[i] = len ? len : 1;
 if (sensitive)
  for (i = 0; i <= len; ++i)
   delta[(unsigned char)str[i]] = len - i;
 else
  for (i = 0; i <= len; ++i) {
   delta[toupper(str[i])] = len - i;
   delta[tolower(str[i])] = len - i;
  }
 while (!bisend(buff)) {
  while (!bisend(buff) && delta[((unsigned char)(*buff->curcptr))])
   bmove(buff, delta[((unsigned char)(*buff->curcptr))]);
  for (i = len;
    bequal(buff, str[i], sensitive);
    bmove(buff, -1), --i)
   if (i == 0) {
    bmove(buff, len + 1);
    return 1;
   }
  if (i + delta[((unsigned char)(*buff->curcptr))] > len)
   shift = delta[((unsigned char)(*buff->curcptr))];
  else
   shift = len - i + 1;
  bmove(buff, shift);
 }
 return 0;
}

variable_types: sensitive int

variable_types:
delta
int [256]

variable_types: i int

variable_types: shift int

user_defined_types: struct page { char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; }

user_defined_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; }


original_code:
int bm_rsearch(struct buff *buff, const char *str, int sensitive)
{
 int delta[256], len, i, shift;
 len = strlen(str) - 1;
 for (i = 0; i < 256; ++i)
  delta[i] = len ? -len : -1;
 if (sensitive)
  for (i = len; i >= 0; --i)
   delta[(uint8_t)str[i]] = -i;
 else
  for (i = len; i >= 0; --i) {
   delta[toupper(str[i])] = -i;
   delta[tolower(str[i])] = -i;
  }
 bmove(buff, -len);
 while (!bisstart(buff)) {
  while (delta[((uint8_t)(*buff->curcptr))] && !bisstart(buff))
   bmove(buff, delta[((uint8_t)(*buff->curcptr))]);
  for (i = 0;
    i <= len && bequal(buff, str[i], sensitive);
    ++i, bmove1(buff))
   ;
  if (i > len) {
   bmove(buff, -len - 1);
   return 1;
  }
  shift = delta[((uint8_t)(*buff->curcptr))] + i < 0 ? delta[((uint8_t)(*buff->curcptr))] : -i - 1;
  bmove(buff, shift);
 }
 return 0;
}

canonical_original_code:
int bm_rsearch(struct buff *buff, char *str, int sensitive)
{
 int delta[256]; int len; int i; int shift;
 len = strlen(str) - 1;
 for (i = 0; i < 256; ++i)
  delta[i] = len ? -len : -1;
 if (sensitive)
  for (i = len; i >= 0; --i)
   delta[(unsigned char)str[i]] = -i;
 else
  for (i = len; i >= 0; --i) {
   delta[toupper(str[i])] = -i;
   delta[tolower(str[i])] = -i;
  }
 bmove(buff, -len);
 while (!bisstart(buff)) {
  while (delta[((unsigned char)(*buff->curcptr))] && !bisstart(buff))
   bmove(buff, delta[((unsigned char)(*buff->curcptr))]);
  for (i = 0;
    i <= len && bequal(buff, str[i], sensitive);
    ++i, bmove1(buff))
   ;
  if (i > len) {
   bmove(buff, -len - 1);
   return 1;
  }
  shift = delta[((unsigned char)(*buff->curcptr))] + i < 0 ? delta[((unsigned char)(*buff->curcptr))] : -i - 1;
  bmove(buff, shift);
 }
 return 0;
}


bisend

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

canonical_original_code:
static inline int bisend(struct buff *buff)
{
 return buff->curpage->nextp == ((void *)0) &&
  buff->curchar >= buff->curpage->plen;
}


makeoffset

canonical_original_code:
static inline void makeoffset(struct buff *buff, int dist)
{
 buff->curchar = dist;
 buff->curcptr = buff->curpage->pdata + dist;
}


btostart

decompiled_code:
void __fastcall btostart(__int64 *a1)
{
makecur((__int64)a1, *a1, 0);
}

canonical_decompiled_code:
void __fastcall func3(__int64 *a1)
{
func1((__int64)a1, *a1, 0);
}

original_code:
static inline void btostart(struct buff *buff)
{
 makecur(buff, buff->firstp, 0);
}


canonical_original_code:
static inline void bmove1(struct buff *buff)
{
 if (++buff->curchar < ((buff)->curpage->plen))
  ++buff->curcptr;
 else if (buff->curpage->nextp)
  makecur(buff, buff->curpage->nextp, 0);
 else
  makeoffset(buff, ((buff)->curpage->plen));
}


bmrktopnt

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

*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

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

*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

original_code:
static inline void bmrktopnt(struct buff *buff, struct mark *mark)
{
 mark->mbuff = buff;
 mark->mpage = buff->curpage;
 mark->moffset = buff->curchar;
}

variable_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; } *


mrktomrk

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

*(_QWORD *)a1 = *(_QWORD *)a2;
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a2 + 8);
result = *(unsigned int *)(a2 + 16);
*(_DWORD *)(a1 + 16) = result;
return result;
}

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

*(_QWORD *)a1 = *(_QWORD *)a2;
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a2 + 8);
result = *(unsigned int *)(a2 + 16);
*(_DWORD *)(a1 + 16) = result;
return result;
}

original_code:
static inline void mrktomrk(struct mark *m1, struct mark *m2)
{
 m1->mbuff = m2->mbuff;
 m1->mpage = m2->mpage;
 m1->moffset = m2->moffset;
}

variable_types: struct mark { struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *mbuff; struct page *mpage; unsigned int moffset; } *

user_defined_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; }


addbname

decompiled_code:
void *__fastcall addbname(char *s)
{
int v1; // er14
const char **v2; // rbx
int v3; // ebp
const char *v4; // r12
char *v5; // rbp
char *v6; // rax
char *v7; // rbx
void *result; // rax
int v9; // ebx

v1 = Numbnames;
if ( Numbnames == Maxbnames )
{
v9 = Maxbnames + 10;
result = realloc(Bnames, 8 * (Maxbnames + 10));
if ( !result )
return result;
Bnames = result;
Maxbnames = v9;
}
if ( v1 <= 0 )
{
v3 = v1;
}
else
{
v2 = (const char **)((char *)Bnames + 8 * v1);
v3 = v1;
do
{
v4 = *(v2 - 1);
if ( strcasecmp(s, v4) >= 0 )
break;
*v2-- = v4;
--v3;
}
while ( v3 );
}
v5 = (char *)Bnames + 8 * v3;
v6 = strdup(s);
v7 = v6;
*(_QWORD *)v5 = v6;
if ( v6 )
{
if ( strlen(v6) > 0x1F )
v7[31] = 0;
Numbnames = v1 + 1;
}
return *(void **)v5;
}

canonical_decompiled_code:
void *__fastcall func8(char *s)
{
int v1; // er14
const char **v2; // rbx
int v3; // ebp
const char *v4; // r12
char *v5; // rbp
char *v6; // rax
char *v7; // rbx
void *result; // rax
int v9; // ebx

v1 = Numbnames;
if ( Numbnames == Maxbnames )
{
v9 = Maxbnames + 10;
result = realloc(Bnames, 8 * (Maxbnames + 10));
if ( !result )
return result;
Bnames = result;
Maxbnames = v9;
}
if ( v1 <= 0 )
{
v3 = v1;
}
else
{
v2 = (const char **)((char *)Bnames + 8 * v1);
v3 = v1;
do
{
v4 = *(v2 - 1);
if ( strcasecmp(s, v4) >= 0 )
break;
*v2-- = v4;
--v3;
}
while ( v3 );
}
v5 = (char *)Bnames + 8 * v3;
v6 = strdup(s);
v7 = v6;
*(_QWORD *)v5 = v6;
if ( v6 )
{
if ( strlen(v6) > 0x1F )
v7[31] = 0;
Numbnames = v1 + 1;
}
return *(void **)v5;
}

original_code:
static char *addbname(const char *bname)
{
 int i;
 if (Numbnames == Maxbnames) {
  int new = (Maxbnames + 10) * sizeof(char *);
  char **ptr = (char **)realloc(Bnames, new);
  if (!ptr)
   return ((void *)0);
  Bnames = ptr;
  Maxbnames += 10;
 }
 for (i = Numbnames; i > 0 && strcasecmp(bname, Bnames[i - 1]) < 0; --i)
  Bnames[i] = Bnames[i - 1];
 Bnames[i] = strdup(bname);
 if (Bnames[i]) {
  if (strlen(Bnames[i]) > 31)
   Bnames[i][31] = '\0';
  ++Numbnames;
 }
 return Bnames[i];
}

canonical_original_code:
static char *addbname(char *bname)
{
 int i;
 if (Numbnames == Maxbnames) {
  int new = (Maxbnames + 10) * sizeof(char *);
  char **ptr = (char **)realloc(Bnames, new);
  if (!ptr)
   return ((void *)0);
  Bnames = ptr;
  Maxbnames += 10;
 }
 for (i = Numbnames; i > 0 && strcasecmp(bname, Bnames[i - 1]) < 0; --i)
  Bnames[i] = Bnames[i - 1];
 Bnames[i] = strdup(bname);
 if (Bnames[i]) {
  if (strlen(Bnames[i]) > 31)
   Bnames[i][31] = '\0';
  ++Numbnames;
 }
 return Bnames[i];
}

variable_types:
bname
char *

variable_types: new int

variable_types:
ptr
char **

return_type: char *


decompiled_code:
__int64 __fastcall set_last_bufname(__int64 a1)
{
return strlcpy(&Lbufname, *(_QWORD *)(a1 + 16), 32LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return strlcpy(&Lbufname, *(_QWORD *)(a1 + 16), 32LL);
}

original_code:
void set_last_bufname(struct zbuff *buff)
{
 strlcpy(Lbufname, buff->bname, sizeof(Lbufname));
}

variable_types: struct zbuff { struct zbuff *prev; struct zbuff *next; char *bname; char *fname; struct mark { struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *mbuff; struct page *mpage; unsigned int moffset; } *umark; struct buff *buff; long mtime; void *chead; void *ctail; unsigned char comchar; unsigned int bmode; } *

user_defined_types: struct zbuff { struct zbuff *prev; struct zbuff *next; char *bname; char *fname; struct mark *umark; struct buff *buff; long mtime; void *chead; void *ctail; unsigned char comchar; unsigned int bmode; }


getbword

decompiled_code:
__int64 __fastcall getbword(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
__int64 i; // rbx
__int64 v5; // r15
int v6; // eax
_BYTE v8[88]; // [rsp+0h] [rbp-58h] BYREF

bmrktopnt(Bbuff, (__int64)v8);
if ( !(unsigned int)bistoken(**(unsigned __int8 **)(Bbuff + 24)) )
bmoveto(Bbuff, &bistoken, 0LL);
bmovepast(Bbuff, &bistoken, 0LL);
for ( i = 0LL; ; ++i )
{
v5 = Bbuff;
if ( bisend(Bbuff) )
break;
v6 = a3(**(unsigned __int8 **)(v5 + 24));
if ( a2 <= (int)i || !v6 )
break;
*(_BYTE *)(a1 + i) = **(_BYTE **)(Bbuff + 24);
bmove1(Bbuff);
}
*(_BYTE *)(a1 + (int)i) = 0;
bpnttomrk(Bbuff, v8);
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
__int64 i; // rbx
__int64 v5; // r15
int v6; // eax
_BYTE v8[88]; // [rsp+0h] [rbp-58h] BYREF

func5(Bbuff, (__int64)v8);
if ( !(unsigned int)bistoken(**(unsigned __int8 **)(Bbuff + 24)) )
bmoveto(Bbuff, &bistoken, 0LL);
bmovepast(Bbuff, &bistoken, 0LL);
for ( i = 0LL; ; ++i )
{
v5 = Bbuff;
if ( func0(Bbuff) )
break;
v6 = a3(**(unsigned __int8 **)(v5 + 24));
if ( a2 <= (int)i || !v6 )
break;
*(_BYTE *)(a1 + i) = **(_BYTE **)(Bbuff + 24);
func4(Bbuff);
}
*(_BYTE *)(a1 + (int)i) = 0;
bpnttomrk(Bbuff, v8);
return (unsigned int)i;
}

original_code:
int getbword(char word[], int max, int (*valid)(int))
{
 struct mark tmark;
 int i;
 bmrktopnt(Bbuff, &tmark);
 if (!bistoken((*Bbuff->curcptr)))
  bmoveto(Bbuff, bistoken, 0);
 bmovepast(Bbuff, bistoken, 0);
 for (i = 0; !bisend(Bbuff) && valid((*Bbuff->curcptr)) && i < max; ++i) {
  word[i] = (*Bbuff->curcptr);
  bmove1(Bbuff);
 }
 word[i] = '\0';
 bpnttomrk(Bbuff, &tmark);
 return i;
}

variable_types:
word
char []

variable_types: max int

variable_types:
valid
int (*)(int)

variable_types: struct mark { struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *mbuff; struct page *mpage; unsigned int moffset; }


getbtxt

decompiled_code:
__int64 __fastcall getbtxt(__int64 a1, int a2)
{
__int64 i; // rbx
__int64 v3; // rbp
_BOOL4 v4; // eax
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

bmrktopnt(Bbuff, (__int64)v6);
btostart((__int64 *)Bbuff);
for ( i = 0LL; ; ++i )
{
v3 = Bbuff;
v4 = bisend(Bbuff);
if ( a2 <= (int)i || v4 )
break;
*(_BYTE *)(a1 + i) = **(_BYTE **)(v3 + 24);
bmove1(Bbuff);
}
*(_BYTE *)(a1 + (int)i) = 0;
bpnttomrk(Bbuff, v6);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
__int64 i; // rbx
__int64 v3; // rbp
_BOOL4 v4; // eax
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

func5(Bbuff, (__int64)v6);
func3((__int64 *)Bbuff);
for ( i = 0LL; ; ++i )
{
v3 = Bbuff;
v4 = func0(Bbuff);
if ( a2 <= (int)i || v4 )
break;
*(_BYTE *)(a1 + i) = **(_BYTE **)(v3 + 24);
func4(Bbuff);
}
*(_BYTE *)(a1 + (int)i) = 0;
bpnttomrk(Bbuff, v6);
return a1;
}

original_code:
char *getbtxt(char txt[], int max)
{
 struct mark tmark;
 int i;
 bmrktopnt(Bbuff, &tmark);
 btostart(Bbuff);
 for (i = 0; !bisend(Bbuff) && i < max; bmove1(Bbuff), ++i)
  txt[i] = (*Bbuff->curcptr);
 txt[i] = '\0';
 bpnttomrk(Bbuff, &tmark);
 return txt;
}

variable_types:
txt
char []


limit

decompiled_code:
const char *__fastcall limit(const char *a1, int a2)
{
int v2; // edx
const char *result; // rax

v2 = a2 - Colmax + strlen(a1);
result = &a1[v2];
if ( v2 <= 0 )
result = a1;
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(const char *a1, int a2)
{
int v2; // edx
const char *result; // rax

v2 = a2 - Colmax + strlen(a1);
result = &a1[v2];
if ( v2 <= 0 )
result = a1;
return result;
}

original_code:
char *limit(char *fname, int num)
{
 int off = strlen(fname) - (Colmax - num);
 return off > 0 ? fname + off : fname;
}

variable_types:
fname
char *

variable_types: num int

variable_types: off int


lstbuff

original_code:
static void lstbuff(struct zbuff *tbuff)
{
 binstr(Bbuff, "%-16s %s%s %8u %s\n", tbuff->bname,
     (tbuff->bmode & 0x2000) ? "S" : " ",
     tbuff->buff->bmodf ? "*" : " ",
     blength(tbuff->buff),
     tbuff->fname ? limit(tbuff->fname, (31 + 14)) : "NoFile");
}


binit

decompiled_code:
int binit()
{
bsetmod = &vsetmod_callback;
delinit();
return atexit(bfini);
}

canonical_decompiled_code:
int func16()
{
bsetmod = &vsetmod_callback;
delinit();
return atexit(bfini);
}

original_code:
void binit(void)
{
 bsetmod = vsetmod_callback;
 delinit();
 atexit(bfini);
}

canonical_original_code:
void binit()
{
 bsetmod = vsetmod_callback;
 delinit();
 atexit(bfini);
}


zswitchto

decompiled_code:
__int64 __fastcall zswitchto(_QWORD *a1)
{
__int64 result; // rax
_BYTE v2[40]; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
if ( Curbuff != a1 )
{
Curbuff = a1;
Bbuff = a1[5];
bmrktopnt(Bbuff, (__int64)v2);
result = bpnttomrk(Bbuff, v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1)
{
__int64 result; // rax
_BYTE v2[40]; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
if ( Curbuff != a1 )
{
Curbuff = a1;
Bbuff = a1[5];
func5(Bbuff, (__int64)v2);
result = bpnttomrk(Bbuff, v2);
}
}
return result;
}

original_code:
void zswitchto(struct zbuff *buf)
{
 if (buf && buf != Curbuff) {
  Curbuff = buf;
  Bbuff = buf->buff;
  struct mark tmp;
  bmrktopnt(Bbuff, &tmp);
  bpnttomrk(Bbuff, &tmp);
 }
}


cdelbuff

decompiled_code:
__int64 __fastcall cdelbuff(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rax
__int64 result; // rax
_QWORD *v5; // rdi

if ( !ptr )
return 0LL;
if ( Curbuff == ptr )
{
clear_umark();
v5 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v5 )
{
v5 = *(_QWORD **)ptr;
result = 0LL;
if ( !*(_QWORD *)ptr )
return result;
}
zswitchto(v5);
}
undo_clear(*((_QWORD *)ptr + 5));
uncomment(ptr);
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
{
delbname(v2);
*((_QWORD *)ptr + 2) = 0LL;
}
if ( (unsigned __int8)unvoke(ptr) )
checkpipes(1LL);
if ( Bufflist == ptr )
Bufflist = (void *)*((_QWORD *)ptr + 1);
if ( (void *)Bufflist_tail == ptr )
Bufflist_tail = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v3 )
*v3 = *(_QWORD *)ptr;
free(*((void **)ptr + 3));
bdelbuff(*((_QWORD *)ptr + 5));
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rax
__int64 result; // rax
_QWORD *v5; // rdi

if ( !ptr )
return 0LL;
if ( Curbuff == ptr )
{
clear_umark();
v5 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v5 )
{
v5 = *(_QWORD **)ptr;
result = 0LL;
if ( !*(_QWORD *)ptr )
return result;
}
func17(v5);
}
undo_clear(*((_QWORD *)ptr + 5));
uncomment(ptr);
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
{
func7(v2);
*((_QWORD *)ptr + 2) = 0LL;
}
if ( (unsigned __int8)unvoke(ptr) )
checkpipes(1LL);
if ( Bufflist == ptr )
Bufflist = (void *)*((_QWORD *)ptr + 1);
if ( (void *)Bufflist_tail == ptr )
Bufflist_tail = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v3 )
*v3 = *(_QWORD *)ptr;
free(*((void **)ptr + 3));
bdelbuff(*((_QWORD *)ptr + 5));
free(ptr);
return 1LL;
}

original_code:
_Bool cdelbuff(struct zbuff *tbuff)
{
 if (!tbuff)
  return 0;
 if (tbuff == Curbuff) {
  clear_umark();
  if (tbuff->next)
   zswitchto(tbuff->next);
  else if (tbuff->prev)
   zswitchto(tbuff->prev);
  else
   return 0;
 }
 undo_clear(tbuff->buff);
 uncomment(tbuff);
 if (tbuff->bname) {
  delbname(tbuff->bname);
  tbuff->bname = ((void *)0);
 }
 if (unvoke(tbuff))
  checkpipes(1);
 if (tbuff == Bufflist)
  Bufflist = tbuff->next;
 if (tbuff == Bufflist_tail)
  Bufflist_tail = tbuff->prev;
 if (tbuff->prev)
  tbuff->prev->next = tbuff->next;
 if (tbuff->next)
  tbuff->next->prev = tbuff->prev;
 free(tbuff->fname);
 bdelbuff(tbuff->buff);
 free(tbuff);
 return 1;
}


delbuff

decompiled_code:
void __fastcall delbuff(void *ptr)
{
const char *v1; // rsi
const char *v2; // rdx
__int64 *v3; // rbx
__int64 v4; // rsi

v1 = (const char *)*((_QWORD *)ptr + 2);
if ( !strcmp(&Lbufname, v1) )
Lbufname = 0;
if ( (unsigned __int8)cdelbuff(ptr) )
{
cswitchto(Curbuff);
v3 = (__int64 *)Whead;
if ( Whead )
{
do
{
if ( (void *)v3[1] == ptr )
{
v3[1] = (__int64)Curbuff;
bmrktopnt(Bbuff, v3[2]);
v4 = *((_QWORD *)Curbuff + 4);
if ( v4 )
{
mrktomrk(v3[3], v4);
*((_DWORD *)v3 + 10) = 1;
}
else
{
*((_DWORD *)v3 + 10) = 0;
}
bmrktopnt(Bbuff, v3[4]);
*((_DWORD *)v3 + 14) = -1;
}
v3 = (__int64 *)*v3;
}
while ( v3 );
}
}
else
{
error((int)"Last Buffer.", (int)v1, v2);
}
}

canonical_decompiled_code:
void __fastcall func19(void *ptr)
{
const char *v1; // rsi
const char *v2; // rdx
__int64 *v3; // rbx
__int64 v4; // rsi

v1 = (const char *)*((_QWORD *)ptr + 2);
if ( !strcmp(&Lbufname, v1) )
Lbufname = 0;
if ( (unsigned __int8)func18(ptr) )
{
cswitchto(Curbuff);
v3 = (__int64 *)Whead;
if ( Whead )
{
do
{
if ( (void *)v3[1] == ptr )
{
v3[1] = (__int64)Curbuff;
func5(Bbuff, v3[2]);
v4 = *((_QWORD *)Curbuff + 4);
if ( v4 )
{
func6(v3[3], v4);
*((_DWORD *)v3 + 10) = 1;
}
else
{
*((_DWORD *)v3 + 10) = 0;
}
func5(Bbuff, v3[4]);
*((_DWORD *)v3 + 14) = -1;
}
v3 = (__int64 *)*v3;
}
while ( v3 );
}
}
else
{
error((int)"Last Buffer.", (int)v1, v2);
}
}

original_code:
static void delbuff(struct zbuff *buff)
{
 struct wdo *wdo;
 if (strcmp(Lbufname, buff->bname) == 0)
  *Lbufname = '\0';
 if (cdelbuff(buff)) {
  cswitchto(Curbuff);
  for (wdo = Whead; wdo; wdo = wdo->next)
   if (wdo->wbuff == buff) {
    wdo->wbuff = Curbuff;
    bmrktopnt(Bbuff, wdo->wpnt);
    if ((Curbuff->umark)) {
     mrktomrk(wdo->wmrk, (Curbuff->umark));
     wdo->umark_set = 1;
    } else
     wdo->umark_set = 0;
    bmrktopnt(Bbuff, wdo->wstart);
    wdo->modeflags = -1;
   }
 } else
  error("Last Buffer.");
}

variable_types: struct wdo { struct wdo *next; struct zbuff { struct zbuff *prev; struct zbuff *next; char *bname; char *fname; struct mark { struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *mbuff; struct page *mpage; unsigned int moffset; } *umark; struct buff *buff; long mtime; void *chead; void *ctail; unsigned char comchar; unsigned int bmode; } *wbuff; struct mark *wpnt; struct mark *wmrk; struct mark *wstart; int umark_set; int first; int modecol; int modeflags; } *

user_defined_types: struct wdo { struct wdo *next; struct zbuff *wbuff; struct mark *wpnt; struct mark *wmrk; struct mark *wstart; int umark_set; int first; int modecol; int modeflags; }


bfini

decompiled_code:
void bfini(void)
{
void *i; // rdi

Curbuff = 0LL;
for ( i = Bufflist; Bufflist; i = Bufflist )
cdelbuff(i);
cdelbuff(Paw);
delfini();
mrkfini();
Dbgfname(0LL);
}

canonical_decompiled_code:
void func20(void)
{
void *i; // rdi

Curbuff = 0LL;
for ( i = Bufflist; Bufflist; i = Bufflist )
func18(i);
func18(Paw);
delfini();
mrkfini();
Dbgfname(0LL);
}

original_code:
static void bfini(void)
{
 Curbuff = ((void *)0);
 while (Bufflist)
  cdelbuff(Bufflist);
 cdelbuff(Paw);
 delfini();
 mrkfini();
 Dbgfname(((void *)0));
}

canonical_original_code:
static void bfini()
{
 Curbuff = ((void *)0);
 while (Bufflist)
  cdelbuff(Bufflist);
 cdelbuff(Paw);
 delfini();
 mrkfini();
 Dbgfname(((void *)0));
}


cfindbuff

decompiled_code:
void *__fastcall cfindbuff(char *s2)
{
void *i; // rbx

for ( i = Bufflist; i; i = (void *)*((_QWORD *)i + 1) )
{
if ( !strncasecmp(*((const char **)i + 2), s2, 0x1FuLL) )
break;
}
return i;
}

canonical_decompiled_code:
void *__fastcall func21(char *s2)
{
void *i; // rbx

for ( i = Bufflist; i; i = (void *)*((_QWORD *)i + 1) )
{
if ( !strncasecmp(*((const char **)i + 2), s2, 0x1FuLL) )
break;
}
return i;
}

original_code:
struct zbuff *cfindbuff(const char *bname)
{
 struct zbuff *tbuff;
 for ((tbuff) = Bufflist; (tbuff); (tbuff) = (tbuff)->next)
  if (strncasecmp(tbuff->bname, bname, 31) == 0)
   return tbuff;
 return ((void *)0);
}

canonical_original_code:
struct zbuff *cfindbuff(char *bname)
{
 struct zbuff *tbuff;
 for ((tbuff) = Bufflist; (tbuff); (tbuff) = (tbuff)->next)
  if (strncasecmp(tbuff->bname, bname, 31) == 0)
   return tbuff;
 return ((void *)0);
}

return_type: struct zbuff { struct zbuff *prev; struct zbuff *next; char *bname; char *fname; struct mark { struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *mbuff; struct page *mpage; unsigned int moffset; } *umark; struct buff *buff; long mtime; void *chead; void *ctail; unsigned char comchar; unsigned int bmode; } *


decompiled_code:
__int64 switchto_part()
{
_QWORD *v0; // rax
_QWORD *v1; // rax
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

getbtxt((__int64)v3, 79);
v0 = cfindbuff(v3);
if ( !v0 )
v0 = Curbuff;
v1 = (_QWORD *)v0[1];
if ( !v1 )
v1 = Bufflist;
return makepaw(v1[2], 1LL);
}

canonical_decompiled_code:
__int64 func23()
{
_QWORD *v0; // rax
_QWORD *v1; // rax
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

func11((__int64)v3, 79);
v0 = func21(v3);
if ( !v0 )
v0 = Curbuff;
v1 = (_QWORD *)v0[1];
if ( !v1 )
v1 = Bufflist;
return makepaw(v1[2], 1LL);
}

original_code:
static void switchto_part(void)
{
 char word[79 + 1];
 struct zbuff *tbuff;
 getbtxt(word, 79);
 tbuff = cfindbuff(word);
 if (!tbuff)
  tbuff = Curbuff;
 if (tbuff->next)
  tbuff = tbuff->next;
 else
  tbuff = Bufflist;
 makepaw(tbuff->bname, 1);
}

canonical_original_code:
static void switchto_part()
{
 char word[-1];
 struct zbuff *tbuff;
 getbtxt(word, 79);
 tbuff = cfindbuff(word);
 if (!tbuff)
  tbuff = Curbuff;
 if (tbuff->next)
  tbuff = tbuff->next;
 else
  tbuff = Bufflist;
 makepaw(tbuff->bname, 1);
}

variable_types:
word
char [-1]


zcreatebuff

decompiled_code:
void *__fastcall zcreatebuff(char *s, char *a2)
{
void *v2; // rbx
const char *v4; // rdx
_QWORD *v5; // r12
__int64 v6; // rax
char *v7; // rax
const char *v8; // rdx
__int64 v9; // rax
int v10; // edx
int v11; // eax

v2 = cfindbuff(s);
if ( v2 )
return v2;
v5 = calloc(1uLL, 0x50uLL);
if ( !v5 )
{
LABEL_19:
error((int)"Unable to create buffer", 80, v4);
return v2;
}
v6 = bcreate();
v5[5] = v6;
if ( !v6 || a2 && (v7 = strdup(a2), (v5[3] = v7) == 0LL) )
{
free((void *)v5[3]);
bdelbuff(v5[5]);
free(v5);
goto LABEL_19;
}
if ( s && (v2 = addbname(s), (v5[2] = v2) == 0LL) )
{
error((int)"Out of buffer name space", 80, v8);
cdelbuff(v5);
}
else
{
if ( Bufflist )
{
v9 = Bufflist_tail;
*(_QWORD *)(Bufflist_tail + 8) = v5;
*v5 = v9;
}
else
{
Bufflist = v5;
}
Bufflist_tail = (__int64)v5;
v10 = Vars[28];
if ( v10 )
v10 = 2;
v11 = v10 | (text_mode == 0 ? 256 : 1024);
*((_DWORD *)v5 + 19) = v11;
v2 = v5;
if ( s && *s == 42 )
{
BYTE1(v11) |= 0x20u;
*((_DWORD *)v5 + 19) = v11;
*(_DWORD *)(v5[5] + 40LL) = 1;
}
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func26(char *s, char *a2)
{
void *v2; // rbx
const char *v4; // rdx
_QWORD *v5; // r12
__int64 v6; // rax
char *v7; // rax
const char *v8; // rdx
__int64 v9; // rax
int v10; // edx
int v11; // eax

v2 = func21(s);
if ( v2 )
return v2;
v5 = calloc(1uLL, 0x50uLL);
if ( !v5 )
{
LABEL_19:
error((int)"Unable to create buffer", 80, v4);
return v2;
}
v6 = bcreate();
v5[5] = v6;
if ( !v6 || a2 && (v7 = strdup(a2), (v5[3] = v7) == 0LL) )
{
free((void *)v5[3]);
bdelbuff(v5[5]);
free(v5);
goto LABEL_19;
}
if ( s && (v2 = func8(s), (v5[2] = v2) == 0LL) )
{
error((int)"Out of buffer name space", 80, v8);
func18(v5);
}
else
{
if ( Bufflist )
{
v9 = Bufflist_tail;
*(_QWORD *)(Bufflist_tail + 8) = v5;
*v5 = v9;
}
else
{
Bufflist = v5;
}
Bufflist_tail = (__int64)v5;
v10 = Vars[28];
if ( v10 )
v10 = 2;
v11 = v10 | (text_mode == 0 ? 256 : 1024);
*((_DWORD *)v5 + 19) = v11;
v2 = v5;
if ( s && *s == 42 )
{
BYTE1(v11) |= 0x20u;
*((_DWORD *)v5 + 19) = v11;
*(_DWORD *)(v5[5] + 40LL) = 1;
}
}
return v2;
}

original_code:
struct zbuff *zcreatebuff(const char *bname, char *fname)
{
 struct zbuff *bptr = cfindbuff(bname);
 if (bptr)
  return bptr;
 bptr = calloc(1, sizeof(struct zbuff));
 if (!bptr)
  goto failed;
 bptr->buff = bcreate();
 if (!bptr->buff)
  goto failed;
 if (fname) {
  bptr->fname = strdup(fname);
  if (!bptr->fname)
   goto failed;
 }
 if (bname) {
  bptr->bname = addbname(bname);
  if (!bptr->bname) {
   error("Out of buffer name space");
   cdelbuff(bptr);
   return ((void *)0);
  }
 }
 if (Bufflist) {
  Bufflist_tail->next = bptr;
  bptr->prev = Bufflist_tail;
 } else
  Bufflist = bptr;
 Bufflist_tail = bptr;
 bptr->bmode = (text_mode ? 0x0400 : 0x0100) |
  (Vars[(((0 + 1) + 1) + 1)].u.val ? 0x0002 : 0);
 if (bname && *bname == '*') {
  bptr->bmode |= 0x2000;
  bptr->buff->in_undo = 1;
 }
 return bptr;
failed:
 if (bptr) {
  free(bptr->fname);
  bdelbuff(bptr->buff);
  free(bptr);
 }
error("Unable to create buffer");
 return ((void *)0);
}

canonical_original_code:
struct zbuff *zcreatebuff(char *bname, char *fname)
{
 struct zbuff *bptr = cfindbuff(bname);
 if (bptr)
  return bptr;
 bptr = calloc(1, sizeof(struct zbuff));
 if (!bptr)
  goto failed;
 bptr->buff = bcreate();
 if (!bptr->buff)
  goto failed;
 if (fname) {
  bptr->fname = strdup(fname);
  if (!bptr->fname)
   goto failed;
 }
 if (bname) {
  bptr->bname = addbname(bname);
  if (!bptr->bname) {
   error("Out of buffer name space");
   cdelbuff(bptr);
   return ((void *)0);
  }
 }
 if (Bufflist) {
  Bufflist_tail->next = bptr;
  bptr->prev = Bufflist_tail;
 } else
  Bufflist = bptr;
 Bufflist_tail = bptr;
 bptr->bmode = (text_mode ? 0x0400 : 0x0100) |
  (Vars[(((0 + 1) + 1) + 1)].u.val ? 0x0002 : 0);
 if (bname && *bname == '*') {
  bptr->bmode |= 0x2000;
  bptr->buff->in_undo = 1;
 }
 return bptr;
failed:
 if (bptr) {
  free(bptr->fname);
  bdelbuff(bptr->buff);
  free(bptr);
 }
error("Unable to create buffer");
 return ((void *)0);
}


makeoffset

original_code:
static inline void makeoffset(struct buff *buff, int dist)
{
 buff->curchar = dist;
 buff->curcptr = buff->curpage->pdata + dist;
}

variable_types: struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *

variable_types: dist int


original_code:
static inline void bmove1(struct buff *buff)
{
 if (++buff->curchar < ((buff)->curpage->plen))
  ++buff->curcptr;
 else if (buff->curpage->nextp)
  makecur(buff, buff->curpage->nextp, 0);
 else
  makeoffset(buff, ((buff)->curpage->plen));
}


toendline

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

result = bcsearch(a1, 10LL);
if ( (_DWORD)result )
result = bmove(a1, 0xFFFFFFFFLL);
return result;
}

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

result = bcsearch(a1, 10LL);
if ( (_DWORD)result )
result = bmove(a1, 0xFFFFFFFFLL);
return result;
}

original_code:
void toendline(struct buff *buff)
{
 if (bcsearch(buff, '\n'))
  bmove(buff, -1);
}


tobegline

decompiled_code:
void __fastcall tobegline(__int64 a1)
{
if ( !*(_DWORD *)(a1 + 32) || *(_BYTE *)(*(_QWORD *)(a1 + 24) - 1LL) != 10 )
{
if ( (unsigned int)bcrsearch(a1, 10LL) )
bmove1(a1);
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
if ( !*(_DWORD *)(a1 + 32) || *(_BYTE *)(*(_QWORD *)(a1 + 24) - 1LL) != 10 )
{
if ( (unsigned int)bcrsearch(a1, 10LL) )
func2(a1);
}
}

original_code:
void tobegline(struct buff *buff)
{
 if (buff->curchar > 0 && *(buff->curcptr - 1) == '\n')
  return;
 if (bcrsearch(buff, '\n'))
  bmove1(buff);
}


tsize

decompiled_code:
void __fastcall tsize(int *a1, int *a2)
{
int v3; // ebp
int v4; // ebp
char *v5; // rax
const char *v6; // rdi
int v7; // eax
char *endptr; // [rsp+0h] [rbp-30h] BYREF
char buf[2]; // [rsp+Ch] [rbp-24h] BYREF
char nptr[34]; // [rsp+Eh] [rbp-22h] BYREF

*a2 = 80;
*a1 = 30;
if ( !no_tsize )
{
twrite(&unk_EF, 3LL);
twrite("\x1B[999;999H", 10LL);
twrite("\x1B[6n", 4LL);
tflush();
v3 = read(0, buf, 0xBuLL);
twrite("\x1B[u", 3LL);
tflush();
if ( v3 > 0 )
{
buf[v3] = 0;
if ( buf[0] == 27 && buf[1] == 91 )
{
v4 = strtol(nptr, &endptr, 10);
v5 = endptr;
v6 = ++endptr;
if ( *v5 == 59 )
{
v7 = strtol(v6, 0LL, 10);
if ( v4 > 0 && v7 > 0 )
{
*a1 = v4;
*a2 = v7;
}
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(int *a1, int *a2)
{
int v3; // ebp
int v4; // ebp
char *v5; // rax
const char *v6; // rdi
int v7; // eax
char *endptr; // [rsp+0h] [rbp-30h] BYREF
char buf[2]; // [rsp+Ch] [rbp-24h] BYREF
char nptr[34]; // [rsp+Eh] [rbp-22h] BYREF

*a2 = 80;
*a1 = 30;
if ( !no_tsize )
{
twrite(&unk_EF, 3LL);
twrite("\x1B[999;999H", 10LL);
twrite("\x1B[6n", 4LL);
tflush();
v3 = read(0, buf, 0xBuLL);
twrite("\x1B[u", 3LL);
tflush();
if ( v3 > 0 )
{
buf[v3] = 0;
if ( buf[0] == 27 && buf[1] == 91 )
{
v4 = strtol(nptr, &endptr, 10);
v5 = endptr;
v6 = ++endptr;
if ( *v5 == 59 )
{
v7 = strtol(v6, 0LL, 10);
if ( v4 > 0 && v7 > 0 )
{
*a1 = v4;
*a2 = v7;
}
}
}
}
}
}

variable_types:
rows
int *

variable_types:
cols
int *

variable_types:
buf
char [12]

variable_types:
p
char *

variable_types: n int

variable_types: r int

variable_types: c int


bisend

decompiled_code:
_BOOL8 __fastcall bisend(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

original_code:
static inline int bisend(struct buff *buff)
{
 return buff->curpage->nextp == ((void *)0) &&
  buff->curchar >= buff->curpage->plen;
}


makecur

original_code:
static inline void makecur(struct buff *buff, struct page *page, int dist)
{
 buff->curpage = page;
 buff->curchar = dist;
 buff->curcptr = page->pdata + dist;
}

variable_types:
page
struct page *


btostart

decompiled_code:
void __fastcall btostart(__int64 *a1)
{
makecur((__int64)a1, *a1, 0);
}

canonical_decompiled_code:
void __fastcall func3(__int64 *a1)
{
func1((__int64)a1, *a1, 0);
}

original_code:
static inline void btostart(struct buff *buff)
{
 makecur(buff, buff->firstp, 0);
}


btoend

decompiled_code:
void __fastcall btoend(__int64 a1)
{
makecur(a1, *(_QWORD *)(a1 + 8), *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4096LL));
}

original_code:
static inline void btoend(struct buff *buff)
{
 makecur(buff, buff->lastp, buff->lastp->plen);
}


bisatmrk

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)(a2 + 8) )
result = *(_DWORD *)(a1 + 32) == *(_DWORD *)(a2 + 16);
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)(a2 + 8) )
result = *(_DWORD *)(a1 + 32) == *(_DWORD *)(a2 + 16);
return result;
}

original_code:
static inline int bisatmrk(struct buff *buff, struct mark *mark)
{
 return buff->curpage == mark->mpage && buff->curchar == mark->moffset;
}

variable_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; } *


bmrktopnt

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

*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

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

*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

original_code:
static inline void bmrktopnt(struct buff *buff, struct mark *mark)
{
 mark->mbuff = buff;
 mark->mpage = buff->curpage;
 mark->moffset = buff->curchar;
}


mrktomrk

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

*(_QWORD *)a1 = *(_QWORD *)a2;
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a2 + 8);
result = *(unsigned int *)(a2 + 16);
*(_DWORD *)(a1 + 16) = result;
return result;
}

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

*(_QWORD *)a1 = *(_QWORD *)a2;
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a2 + 8);
result = *(unsigned int *)(a2 + 16);
*(_DWORD *)(a1 + 16) = result;
return result;
}

original_code:
static inline void mrktomrk(struct mark *m1, struct mark *m2)
{
 m1->mbuff = m2->mbuff;
 m1->mpage = m2->mpage;
 m1->moffset = m2->moffset;
}

variable_types: struct mark { struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *mbuff; struct page *mpage; unsigned int moffset; } *


getnum

decompiled_code:
__int64 __fastcall getnum(__int64 a1)
{
__int64 result; // rax
char nptr[18]; // [rsp+6h] [rbp-12h] BYREF

nptr[0] = 0;
if ( Argp )
{
result = Arg;
Arg = 0;
}
else if ( (unsigned __int8)getarg(a1, nptr, 9LL) )
{
result = -1LL;
}
else
{
result = strtol(nptr, 0LL, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
char nptr[18]; // [rsp+6h] [rbp-12h] BYREF

nptr[0] = 0;
if ( Argp )
{
result = Arg;
Arg = 0;
}
else if ( (unsigned __int8)getarg(a1, nptr, 9LL) )
{
result = -1LL;
}
else
{
result = strtol(nptr, 0LL, 0);
}
return result;
}

original_code:
static long getnum(const char *prompt)
{
 char str[10];
 long num = -1;
 *str = '\0';
 if (Argp) {
  num = Arg;
  Arg = 0;
 } else if (getarg(prompt, str, 9) == 0)
  num = strtol(str, ((void *)0), 0);
 return num;
}

canonical_original_code:
static long getnum(char *prompt)
{
 char str[10];
 long num = -1;
 *str = '\0';
 if (Argp) {
  num = Arg;
  Arg = 0;
 } else if (getarg(prompt, str, 9) == 0)
  num = strtol(str, ((void *)0), 0);
 return num;
}

variable_types:
prompt
char *

variable_types:
str
char [10]

variable_types: num long

return_type: long


bgetcol

decompiled_code:
__int64 __fastcall bgetcol(unsigned __int8 a1, unsigned int a2)
{
__int64 v3; // rbx
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

bmrktopnt(Bbuff, (__int64)v5);
if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
bmove1(Bbuff);
while ( 1 )
{
v3 = Bbuff;
if ( bisatmrk(Bbuff, (__int64)v5) || bisend(v3) )
break;
a2 += chwidth(**(unsigned __int8 **)(v3 + 24), a2, a1);
bmove1(Bbuff);
}
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 a1, unsigned int a2)
{
__int64 v3; // rbx
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

func7(Bbuff, (__int64)v5);
if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
func5(Bbuff);
while ( 1 )
{
v3 = Bbuff;
if ( func6(Bbuff, (__int64)v5) || func0(v3) )
break;
a2 += chwidth(**(unsigned __int8 **)(v3 + 24), a2, a1);
func5(Bbuff);
}
return a2;
}

original_code:
int bgetcol(_Bool flag, int col)
{
 struct mark pmark;
 bmrktopnt(Bbuff, &pmark);
 if (bcrsearch(Bbuff, '\n'))
  bmove1(Bbuff);
 while (!bisatmrk(Bbuff, &pmark) && !bisend(Bbuff)) {
  col += chwidth((*Bbuff->curcptr), col, flag);
  bmove1(Bbuff);
 }
 return col;
}

variable_types: col int

variable_types: struct mark { struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *mbuff; struct page *mpage; unsigned int moffset; }


forcecol

decompiled_code:
__int64 forcecol()
{
if ( Lfunc <= 0x33u && ((1LL << Lfunc) & 0xA0C0000000000LL) != 0 )
return (unsigned int)fcol_0;
if ( **(_BYTE **)(Bbuff + 24LL) == 10 )
{
fcol_0 = 257;
return (unsigned int)fcol_0;
}
fcol_0 = bgetcol(1u, 0);
return (unsigned int)fcol_0;
}

canonical_decompiled_code:
__int64 func15()
{
if ( Lfunc <= 0x33u && ((1LL << Lfunc) & 0xA0C0000000000LL) != 0 )
return (unsigned int)fcol_0;
if ( **(_BYTE **)(Bbuff + 24LL) == 10 )
{
fcol_0 = 257;
return (unsigned int)fcol_0;
}
fcol_0 = func14(1u, 0);
return (unsigned int)fcol_0;
}

variable_types: fcol int


bmakecol

decompiled_code:
__int64 __fastcall bmakecol(int a1)
{
unsigned int v1; // ebp
unsigned __int8 v2; // bl

if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
bmove1(Bbuff);
v1 = 0;
while ( a1 > (int)v1 )
{
v2 = **(_BYTE **)(Bbuff + 24LL);
if ( v2 == 10 )
break;
if ( bisend(Bbuff) )
break;
v1 += chwidth(v2, v1, 1LL);
bmove1(Bbuff);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
unsigned int v1; // ebp
unsigned __int8 v2; // bl

if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
func5(Bbuff);
v1 = 0;
while ( a1 > (int)v1 )
{
v2 = **(_BYTE **)(Bbuff + 24LL);
if ( v2 == 10 )
break;
if ( func0(Bbuff) )
break;
v1 += chwidth(v2, v1, 1LL);
func5(Bbuff);
}
return v1;
}

original_code:
int bmakecol(int col)
{
 int tcol = 0;
 if (bcrsearch(Bbuff, '\n'))
  bmove1(Bbuff);
 while (tcol < col && (*Bbuff->curcptr) != '\n' && !bisend(Bbuff)) {
  tcol += chwidth((*Bbuff->curcptr), tcol, 1);
  bmove1(Bbuff);
 }
 return tcol;
}

variable_types: tcol int


decompiled_code:
__int64 __fastcall top_op(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx

v1 = *(_DWORD *)(a1 + 12);
v2 = 61;
if ( v1 )
v2 = *(unsigned __int8 *)(a1 + v1 - 1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx

v1 = *(_DWORD *)(a1 + 12);
v2 = 61;
if ( v1 )
v2 = *(unsigned __int8 *)(a1 + v1 - 1);
return v2;
}

original_code:
static char top_op(struct calc *c)
{
 if (c->cur_op == 0)
  return '=';
 return c->ops[c->cur_op - 1];
}

variable_types: struct calc { char ops[10]; int cur_op; union number { long i; double f; } nums[10]; int cur_num; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } failed[1]; int is_float; } *

return_type: char

user_defined_types: struct calc { char ops[10]; int cur_op; union number nums[10]; int cur_num; struct __jmp_buf_tag failed[1]; int is_float; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


decompiled_code:
_BOOL8 __fastcall is_op(char a1)
{
return strchr("*/%+-<>&^|", a1) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
return strchr("*/%+-<>&^|", a1) != 0LL;
}

original_code:
static int is_op(char op)
{
 return strchr("*/%+-<>&^|", op) != ((void *)0);
}

variable_types: op char


lookup

decompiled_code:
__int64 __fastcall lookup(__int64 a1, char *a2, char a3)
{
char i; // al

for ( i = *a2; *a2 != a3; i = *a2 )
{
if ( !i )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 2);
a2 += 8;
}
return *((unsigned int *)a2 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, char a3)
{
char i; // al

for ( i = *a2; *a2 != a3; i = *a2 )
{
if ( !i )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 2);
a2 += 8;
}
return *((unsigned int *)a2 + 1);
}

original_code:
static int lookup(struct calc *c, struct values *vals, char op)
{
 struct values *v;
 for (v = vals; v->op != op; ++v)
  if (!v->op)
   longjmp(c->failed, 2);
 return v->val;
}

variable_types:
vals
struct values { char op; int val; } *

variable_types:
v
struct values { char op; int val; } *

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
__int64 __fastcall calc_f(__int64 a1, char a2)
{
return lookup(a1, fvals, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
return func2(a1, fvals, a2);
}

original_code:
static int calc_f(struct calc *c, char op)
{
 return lookup(c, fvals, op);
}


decompiled_code:
__int64 __fastcall calc_g(__int64 a1, char a2)
{
return lookup(a1, gvals, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
return func2(a1, gvals, a2);
}

original_code:
static int calc_g(struct calc *c, char op)
{
 return lookup(c, gvals, op);
}


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

LODWORD(result) = *(_DWORD *)(a1 + 12);
if ( (int)result > 9 )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 1);
*(_DWORD *)(a1 + 12) = result + 1;
result = (int)result;
*(_BYTE *)(a1 + (int)result) = a2;
return result;
}

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

LODWORD(result) = *(_DWORD *)(a1 + 12);
if ( (int)result > 9 )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 1);
*(_DWORD *)(a1 + 12) = result + 1;
result = (int)result;
*(_BYTE *)(a1 + (int)result) = a2;
return result;
}

original_code:
static void push_op(struct calc *c, char op)
{
 if (c->cur_op >= 10)
  longjmp(c->failed, 1);
 c->ops[c->cur_op++] = op;
}


decompiled_code:
__int64 __fastcall pop_op(__int64 a1)
{
int v1; // eax
int v2; // eax

v1 = *(_DWORD *)(a1 + 12);
if ( v1 < 0 )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 2);
v2 = v1 - 1;
*(_DWORD *)(a1 + 12) = v2;
return *(unsigned __int8 *)(a1 + v2);
}

original_code:
static char pop_op(struct calc *c)
{
 if (c->cur_op < 0)
  longjmp(c->failed, 2);
 return c->ops[--c->cur_op];
}


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

LODWORD(result) = *(_DWORD *)(a1 + 96);
if ( (int)result > 9 )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 1);
*(_DWORD *)(a1 + 96) = result + 1;
result = (int)result;
*(double *)(a1 + 8LL * (int)result + 16) = a2;
return result;
}

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

LODWORD(result) = *(_DWORD *)(a1 + 96);
if ( (int)result > 9 )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 1);
*(_DWORD *)(a1 + 96) = result + 1;
result = (int)result;
*(double *)(a1 + 8LL * (int)result + 16) = a2;
return result;
}

original_code:
static void push_float(struct calc *c, double num)
{
 if (c->cur_num >= 10)
  longjmp(c->failed, 1);
 c->nums[c->cur_num++].f = num;
}

variable_types: num double


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

LODWORD(result) = *(_DWORD *)(a1 + 96);
if ( (int)result > 9 )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 1);
*(_DWORD *)(a1 + 96) = result + 1;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result + 16) = a2;
return result;
}

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

LODWORD(result) = *(_DWORD *)(a1 + 96);
if ( (int)result > 9 )
longjmp((struct __jmp_buf_tag *)(a1 + 104), 1);
*(_DWORD *)(a1 + 96) = result + 1;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result + 16) = a2;
return result;
}

original_code:
static void push_num(struct calc *c, long num)
{
 if (c->cur_num >= 10)
  longjmp(c->failed, 1);
 c->nums[c->cur_num++].i = num;
}


original_code:
static union number pop_num(struct calc *c)
{
 if (c->cur_num == 0)
  longjmp(c->failed, 2);
 return c->nums[--c->cur_num];
}

variable_types: struct calc { char ops[10]; int cur_op; union number nums[10]; int cur_num; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } failed[1]; int is_float; } *

return_type: union number { long i; double f; }


decompiled_code:
__int64 __fastcall calc_g_num(__int64 a1, char **a2)
{
const unsigned __int16 **v4; // rdx
const char *v5; // rdi
char v6; // al
double v7; // xmm0_8
char *v8; // rdx
__int64 v10; // rsi
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = _ctype_b_loc();
v5 = *a2;
v6 = **a2;
if ( ((*v4)[v6] & 0x800) != 0 || v6 == 46 )
{
if ( *(_DWORD *)(a1 + 304) )
{
v7 = strtod(v5, endptr);
push_float(a1, v7);
}
else
{
v10 = strtol(v5, endptr, 0);
switch ( *endptr[0] )
{
case 'G':
case 'g':
goto LABEL_9;
case 'K':
case 'k':
goto LABEL_11;
case 'M':
case 'm':
goto LABEL_10;
case 'P':
case 'p':
v10 <<= 12;
++endptr[0];
break;
case 'T':
case 't':
v10 <<= 10;
LABEL_9:
v10 <<= 10;
LABEL_10:
v10 <<= 10;
LABEL_11:
v10 <<= 10;
++endptr[0];
break;
default:
break;
}
push_num(a1, v10);
}
v8 = endptr[0] - 1;
*a2 = endptr[0] - 1;
*v8 = 78;
}
return lookup(a1, gvals, **a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char **a2)
{
const unsigned __int16 **v4; // rdx
const char *v5; // rdi
char v6; // al
double v7; // xmm0_8
char *v8; // rdx
__int64 v10; // rsi
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = _ctype_b_loc();
v5 = *a2;
v6 = **a2;
if ( ((*v4)[v6] & 0x800) != 0 || v6 == 46 )
{
if ( *(_DWORD *)(a1 + 304) )
{
v7 = strtod(v5, endptr);
func7(a1, v7);
}
else
{
v10 = strtol(v5, endptr, 0);
switch ( *endptr[0] )
{
case 'G':
case 'g':
goto LABEL_9;
case 'K':
case 'k':
goto LABEL_11;
case 'M':
case 'm':
goto LABEL_10;
case 'P':
case 'p':
v10 <<= 12;
++endptr[0];
break;
case 'T':
case 't':
v10 <<= 10;
LABEL_9:
v10 <<= 10;
LABEL_10:
v10 <<= 10;
LABEL_11:
v10 <<= 10;
++endptr[0];
break;
default:
break;
}
func8(a1, v10);
}
v8 = endptr[0] - 1;
*a2 = endptr[0] - 1;
*v8 = 78;
}
return func2(a1, gvals, **a2);
}

original_code:
static int calc_g_num(struct calc *c, char **p)
{
 if (((*__ctype_b_loc ())[(int) ((**p))] & (unsigned short int) _ISdigit) || **p == '.') {
  char *e;
  if (c->is_float)
   push_float(c, strtod(*p, &e));
  else {
   long num = strtol(*p, &e, 0);
   switch (*e) {
   case 't':
   case 'T':
    num *= 1024;
   case 'g':
   case 'G':
    num *= 1024;
   case 'm':
   case 'M':
    num *= 1024;
   case 'k':
   case 'K':
    num *= 1024;
    ++e;
    break;
   case 'p':
   case 'P':
    num *= 4096;
    ++e;
   }
   push_num(c, num);
  }
  *p = e - 1;
  **p = 'N';
 }
 return lookup(c, gvals, **p);
}

canonical_original_code:
static int calc_g_num(struct calc *c, char **p)
{
 if (((*__ctype_b_loc ())[(int) ((**p))] & (unsigned short) _ISdigit) || **p == '.') {
  char *e;
  if (c->is_float)
   push_float(c, strtod(*p, &e));
  else {
   long num = strtol(*p, &e, 0);
   switch (*e) {
   case 't':
   case 'T':
    num *= 1024;
   case 'g':
   case 'G':
    num *= 1024;
   case 'm':
   case 'M':
    num *= 1024;
   case 'k':
   case 'K':
    num *= 1024;
    ++e;
    break;
   case 'p':
   case 'P':
    num *= 4096;
    ++e;
   }
   push_num(c, num);
  }
  *p = e - 1;
  **p = 'N';
 }
 return lookup(c, gvals, **p);
}

variable_types:
p
char **

variable_types:
e
char *


calc

original_code:
int calc(char *p, struct calc_result *result)
{
 struct calc calc, *c = &calc;
 int f_val, g_val, rc;
 rc = _setjmp (c->failed);
 if (rc)
  return rc;
 c->is_float = strchr(p, '.') != ((void *)0);
 c->cur_op = c->cur_num = 0;
 while (*p != '=' || top_op(c) != '=') {
  while (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace))
   ++p;
  if (*p == '<' && *(p + 1) == '<')
   ++p;
  else if (*p == '>' && *(p + 1) == '>')
   ++p;
  f_val = calc_f(c, top_op(c));
  g_val = calc_g_num(c, &p);
  if (g_val < 0)
   return -1;
  if (f_val <= g_val) {
   push_op(c, *p);
   if (*p != '=')
    ++p;
  } else {
   do {
    int op = pop_op(c);
    if (is_op(op)) {
     union number two = pop_num(c);
     union number one = pop_num(c);
     switch (op) {
     case '*':
      do { if (c->is_float) push_float(c, one.f * two.f); else push_num(c, one.i * two.i); } while (0);
      break;
     case '/':
      do { if (c->is_float) push_float(c, one.f / two.f); else push_num(c, one.i / two.i); } while (0);
      break;
     case '%':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i % two.i); } while (0);
      break;
     case '+':
      do { if (c->is_float) push_float(c, one.f + two.f); else push_num(c, one.i + two.i); } while (0);
      break;
     case '-':
      do { if (c->is_float) push_float(c, one.f - two.f); else push_num(c, one.i - two.i); } while (0);
      break;
     case '>':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i >> two.i); } while (0);
      break;
     case '<':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i << two.i); } while (0);
      break;
     case '&':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i & two.i); } while (0);
      break;
     case '^':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i ^ two.i); } while (0);
      break;
     case '|':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i | two.i); } while (0);
      break;
     }
    }
    f_val = calc_f(c, top_op(c));
    g_val = calc_g(c, op);
   } while (f_val >= g_val);
  }
 }
 if (result) {
  result->is_float = c->is_float;
  result->result = pop_num(c);
 }
 return 0;
}

canonical_original_code:
int calc(char *p, struct calc_result *result)
{
 struct calc calc; struct calc *c = &calc;
 int f_val; int g_val; int rc;
 rc = _setjmp (c->failed);
 if (rc)
  return rc;
 c->is_float = strchr(p, '.') != ((void *)0);
 c->cur_op = c->cur_num = 0;
 while (*p != '=' || top_op(c) != '=') {
  while (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace))
   ++p;
  if (*p == '<' && *(p + 1) == '<')
   ++p;
  else if (*p == '>' && *(p + 1) == '>')
   ++p;
  f_val = calc_f(c, top_op(c));
  g_val = calc_g_num(c, &p);
  if (g_val < 0)
   return -1;
  if (f_val <= g_val) {
   push_op(c, *p);
   if (*p != '=')
    ++p;
  } else {
   do {
    int op = pop_op(c);
    if (is_op(op)) {
     union number two = pop_num(c);
     union number one = pop_num(c);
     switch (op) {
     case '*':
      do { if (c->is_float) push_float(c, one.f * two.f); else push_num(c, one.i * two.i); } while (0);
      break;
     case '/':
      do { if (c->is_float) push_float(c, one.f / two.f); else push_num(c, one.i / two.i); } while (0);
      break;
     case '%':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i % two.i); } while (0);
      break;
     case '+':
      do { if (c->is_float) push_float(c, one.f + two.f); else push_num(c, one.i + two.i); } while (0);
      break;
     case '-':
      do { if (c->is_float) push_float(c, one.f - two.f); else push_num(c, one.i - two.i); } while (0);
      break;
     case '>':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i >> two.i); } while (0);
      break;
     case '<':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i << two.i); } while (0);
      break;
     case '&':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i & two.i); } while (0);
      break;
     case '^':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i ^ two.i); } while (0);
      break;
     case '|':
      do { if (c->is_float) longjmp(c->failed, 2); else push_num(c, one.i | two.i); } while (0);
      break;
     }
    }
    f_val = calc_f(c, top_op(c));
    g_val = calc_g(c, op);
   } while (f_val >= g_val);
  }
 }
 if (result) {
  result->is_float = c->is_float;
  result->result = pop_num(c);
 }
 return 0;
}

variable_types:
p
char *

variable_types: struct calc_result { int is_float; union number { long i; double f; } result; } *

variable_types: struct calc { char ops[10]; int cur_op; union number { long i; double f; } nums[10]; int cur_num; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } failed[1]; int is_float; }

variable_types: rc int

variable_types: op int

variable_types:
two
union number { long i; double f; }

variable_types:
one
union number { long i; double f; }

user_defined_types: struct calc_result { int is_float; union number result; }


makecur

original_code:
static inline void makecur(struct buff *buff, struct page *page, int dist)
{
 buff->curpage = page;
 buff->curchar = dist;
 buff->curcptr = page->pdata + dist;
}

variable_types: struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *

variable_types:
page
struct page *

variable_types: dist int


btoend

decompiled_code:
void __fastcall btoend(__int64 a1)
{
makecur(a1, *(_QWORD *)(a1 + 8), *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4096LL));
}

original_code:
static inline void btoend(struct buff *buff)
{
 makecur(buff, buff->lastp, buff->lastp->plen);
}


isdir

decompiled_code:
__int64 __fastcall isdir(const char *a1)
{
int v1; // edx
__mode_t v2; // eax
struct stat v4; // [rsp-18h] [rbp-98h] BYREF

if ( !a1 )
return 0LL;
v1 = stat(a1, &v4);
LOBYTE(v2) = 0;
if ( !v1 )
v2 = (v4.st_mode >> 14) & 1;
return v2 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
int v1; // edx
__mode_t v2; // eax
struct stat v4; // [rsp-18h] [rbp-98h] BYREF

if ( !a1 )
return 0LL;
v1 = stat(a1, &v4);
LOBYTE(v2) = 0;
if ( !v1 )
v2 = (v4.st_mode >> 14) & 1;
return v2 & 1;
}

original_code:
static _Bool isdir(char *path)
{
 struct stat sbuf;
 return path && stat(path, &sbuf) == 0 && (sbuf.st_mode & 0040000);
}

variable_types:
path
char *

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


zgetpwdir

decompiled_code:
__int64 __fastcall zgetpwdir(char *s2, char *dest)
{
int v2; // er12
unsigned int v3; // er13
struct passwd *v4; // rax
struct passwd *v5; // rbx
const char *v6; // r15

v2 = strlen(s2);
setpwent();
v3 = 0;
while ( 1 )
{
v4 = getpwent();
v5 = v4;
if ( !v4 )
break;
v6 = v4->pw_name;
if ( !strncmp(v4->pw_name, s2, v2) )
{
if ( !strcmp(v6, s2) )
{
endpwent();
strcpy(dest, v5->pw_dir);
return 1;
}
if ( !(_BYTE)v3 )
{
strcpy(dest, v5->pw_dir);
v3 = 1;
}
}
}
endpwent();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2, char *dest)
{
int v2; // er12
unsigned int v3; // er13
struct passwd *v4; // rax
struct passwd *v5; // rbx
const char *v6; // r15

v2 = strlen(s2);
setpwent();
v3 = 0;
while ( 1 )
{
v4 = getpwent();
v5 = v4;
if ( !v4 )
break;
v6 = v4->pw_name;
if ( !strncmp(v4->pw_name, s2, v2) )
{
if ( !strcmp(v6, s2) )
{
endpwent();
strcpy(dest, v5->pw_dir);
return 1;
}
if ( !(_BYTE)v3 )
{
strcpy(dest, v5->pw_dir);
v3 = 1;
}
}
}
endpwent();
return v3;
}

original_code:
static _Bool zgetpwdir(char *name, char *to)
{
 struct passwd *pwd;
 _Bool match = 0;
 int len = strlen(name);
 setpwent();
 while ((pwd = getpwent()))
  if (strncmp(pwd->pw_name, name, len) == 0) {
   if (strcmp(pwd->pw_name, name) == 0) {
    endpwent();
    strcpy(to, pwd->pw_dir);
    return 1;
   } else if (!match) {
    strcpy(to, pwd->pw_dir);
    match = 1;
   }
  }
 endpwent();
 return match;
}

variable_types:
name
char *

variable_types:
to
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: len int


nmatch

decompiled_code:
__int64 __fastcall nmatch(__int64 a1, __int64 a2)
{
const __int32_t *v4; // rdx
__int64 v5; // rax
unsigned int v6; // edi
__int64 v7; // rsi
__int64 v8; // rcx

v4 = *_ctype_tolower_loc();
v5 = 0LL;
do
{
v6 = v5;
v7 = *(char *)(a1 + v5);
v8 = *(char *)(a2 + v5++);
}
while ( v4[v7] == v4[v8] );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
const __int32_t *v4; // rdx
__int64 v5; // rax
unsigned int v6; // edi
__int64 v7; // rsi
__int64 v8; // rcx

v4 = *_ctype_tolower_loc();
v5 = 0LL;
do
{
v6 = v5;
v7 = *(char *)(a1 + v5);
v8 = *(char *)(a2 + v5++);
}
while ( v4[v7] == v4[v8] );
return v6;
}

original_code:
int nmatch(char *s1, char *s2)
{
 int i;
 for (i = 0; tolower(*s1) == tolower(*s2); ++i, ++s1, ++s2)
  ;
 return i;
}

variable_types: i int


zgetcwd

decompiled_code:
char *__fastcall zgetcwd(char *s, int a2)
{
int v2; // eax

if ( !getcwd(s, a2 - 1) )
strlcpy(s, Home, a2 - 1);
v2 = strlen(s);
s[v2] = 47;
s[v2 + 1] = 0;
return s;
}

canonical_decompiled_code:
char *__fastcall func9(char *s, int a2)
{
int v2; // eax

if ( !getcwd(s, a2 - 1) )
strlcpy(s, Home, a2 - 1);
v2 = strlen(s);
s[v2] = 47;
s[v2 + 1] = 0;
return s;
}

original_code:
char *zgetcwd(char *cwd, int len)
{
 if (!getcwd(cwd, len - 1))
  strlcpy(cwd, Home, len - 1);
 len = strlen(cwd);
 *(cwd + len) = '/';
 *(cwd + len + 1) = 0;
 return cwd;
}

variable_types:
cwd
char *


pathfixup

original_code:
int pathfixup(char *to, char *from)
{
 char *start, save, dir[255], *p;
 int rc;
 struct stat sbuf;
 do {
  p = strstr(from, "//");
  if (p)
   from = p + 1;
 } while (p);
 start = to;
 *to = '\0';
 if (*from == '~') {
  for (p = dir, ++from; *from && !((*from) == '/'); ++from, ++p)
   *p = *from;
  *p = '\0';
  if (*dir) {
   if (!zgetpwdir(dir, to))
    return 2;
  } else
   strcpy(to, Home);
  to += strlen(to);
  if (*from && !((*from) == '/') && !((*(to - 1)) == '/'))
   *to++ = '/';
 } else if (*from == '$') {
  for (p = dir, ++from; *from && !((*from) == '/'); ++from, ++p)
   *p = *from;
  *p = '\0';
  p = getenv(dir);
  if (p == ((void *)0))
   return 2;
  strcpy(to, p);
  to += strlen(to);
  if (*from && !((*from) == '/') && !((*(to - 1)) == '/'))
   *to++ = '/';
 } else {
  if (!((*from) == '/')) {
   zgetcwd(to, 255);
   to += strlen(to);
  }
 }
 for (; *from; ++from)
  if (*from == '.') {
   if (((*(from + 1)) == '/'))
    ++from;
   else if (*(from + 1) == '.' &&
     (((*(from + 2)) == '/') ||
      *(from + 2) == '\0')) {
    to -= 2;
    while (to > start && !((*to) == '/'))
     --to;
    ++to;
    if (*(++from + 1))
     ++from;
   } else
    *to++ = *from;
  } else if (((*from) == '/')) {
   if (to == start || !((*(to - 1)) == '/'))
    *to++ = '/';
  } else
   *to++ = *from;
 *to = '\0';
 if (stat(start, &sbuf) == -1) {
  to = strrchr(start, '/');
  if (to) {
   save = *to;
   *to = '\0';
   rc = !isdir(start);
   *to = save;
  } else
   rc = 0;
 } else if (sbuf.st_mode & 0040000)
  rc = -1;
 else
  rc = 0;
 if (strlen(start) >= 255)
  Dbg("TOO LONG %d '%s'\n", strlen(start), start);
 return rc;
}

canonical_original_code:
int pathfixup(char *to, char *from)
{
 char *start; char save; char dir[255]; char *p;
 int rc;
 struct stat sbuf;
 do {
  p = strstr(from, "//");
  if (p)
   from = p + 1;
 } while (p);
 start = to;
 *to = '\0';
 if (*from == '~') {
  for (p = dir, ++from; *from && !((*from) == '/'); ++from, ++p)
   *p = *from;
  *p = '\0';
  if (*dir) {
   if (!zgetpwdir(dir, to))
    return 2;
  } else
   strcpy(to, Home);
  to += strlen(to);
  if (*from && !((*from) == '/') && !((*(to - 1)) == '/'))
   *to++ = '/';
 } else if (*from == '$') {
  for (p = dir, ++from; *from && !((*from) == '/'); ++from, ++p)
   *p = *from;
  *p = '\0';
  p = getenv(dir);
  if (p == ((void *)0))
   return 2;
  strcpy(to, p);
  to += strlen(to);
  if (*from && !((*from) == '/') && !((*(to - 1)) == '/'))
   *to++ = '/';
 } else {
  if (!((*from) == '/')) {
   zgetcwd(to, 255);
   to += strlen(to);
  }
 }
 for (; *from; ++from)
  if (*from == '.') {
   if (((*(from + 1)) == '/'))
    ++from;
   else if (*(from + 1) == '.' &&
     (((*(from + 2)) == '/') ||
      *(from + 2) == '\0')) {
    to -= 2;
    while (to > start && !((*to) == '/'))
     --to;
    ++to;
    if (*(++from + 1))
     ++from;
   } else
    *to++ = *from;
  } else if (((*from) == '/')) {
   if (to == start || !((*(to - 1)) == '/'))
    *to++ = '/';
  } else
   *to++ = *from;
 *to = '\0';
 if (stat(start, &sbuf) == -1) {
  to = strrchr(start, '/');
  if (to) {
   save = *to;
   *to = '\0';
   rc = !isdir(start);
   *to = save;
  } else
   rc = 0;
 } else if (sbuf.st_mode & 0040000)
  rc = -1;
 else
  rc = 0;
 if (strlen(start) >= 255)
  Dbg("TOO LONG %d '%s'\n", strlen(start), start);
 return rc;
}

variable_types:
from
char *

variable_types:
start
char *

variable_types: save char

variable_types:
dir
char [255]

variable_types:
p
char *

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


getfname

decompiled_code:
__int64 __fastcall getfname(__int64 a1, char *a2)
{
char v2; // r15
char v3; // r14
char v4; // r13
char *v5; // rax
unsigned int v6; // er12
unsigned int v8; // eax
const char *v9; // rdx
char dest[328]; // [rsp+10h] [rbp-148h] BYREF

v2 = Keys[9];
Keys[9] = 119;
v3 = Keys[47];
Keys[47] = 119;
v4 = Keys[126];
Keys[126] = 119;
v5 = strcpy(dest, a2);
v6 = 1;
if ( !(unsigned __int8)getarg(a1, v5, 255LL, 0LL) )
{
v8 = pathfixup(a2, dest);
v6 = v8;
if ( v8 == -1 )
{
v6 = 1;
}
else if ( !v8 )
{
goto LABEL_2;
}
error((int)"Invalid path.", (int)dest, v9);
}
LABEL_2:
Keys[9] = v2;
Keys[47] = v3;
Keys[126] = v4;
freelist(&Flist);
if ( Didmatch )
{
redisplay();
Didmatch = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char *a2)
{
char v2; // r15
char v3; // r14
char v4; // r13
char *v5; // rax
unsigned int v6; // er12
unsigned int v8; // eax
const char *v9; // rdx
char dest[328]; // [rsp+10h] [rbp-148h] BYREF

v2 = Keys[9];
Keys[9] = 119;
v3 = Keys[47];
Keys[47] = 119;
v4 = Keys[126];
Keys[126] = 119;
v5 = strcpy(dest, a2);
v6 = 1;
if ( !(unsigned __int8)getarg(a1, v5, 255LL, 0LL) )
{
v8 = func10(a2, dest);
v6 = v8;
if ( v8 == -1 )
{
v6 = 1;
}
else if ( !v8 )
{
goto LABEL_2;
}
error((int)"Invalid path.", (int)dest, v9);
}
LABEL_2:
Keys[9] = v2;
Keys[47] = v3;
Keys[126] = v4;
func2(&Flist);
if ( Didmatch )
{
redisplay();
Didmatch = 0;
}
return v6;
}

variable_types:
prompt
char *

variable_types:
mod
char [3]

variable_types:
tmp
char [-1]

variable_types:
was
int [3]

variable_types: rc int


getfill

decompiled_code:
__int64 __fastcall getfill(char *s, const char **a2, _DWORD *a3, bool *a4)
{
int v6; // edx
__int64 result; // rax
int v8; // eax
const char *v9; // rax
const char *v10; // r12
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

if ( First )
{
bempty(Bbuff);
First = 0;
}
getbtxt(v11, 255LL);
v6 = pathfixup(s, v11);
result = 0LL;
if ( v6 <= 0 )
{
v8 = strcmp(s, v11);
*a4 = v8 != 0;
if ( v8 )
makepaw(s, 0LL);
v9 = (const char *)lastpart(s);
*a2 = v9;
*a3 = strlen(v9);
v10 = *a2;
if ( *a2 == s )
{
result = fill_list("./");
}
else
{
if ( v10 - s == 1 )
{
strcpy(v11, *a2);
*a2 = v10 + 1;
strcpy((char *)v10 + 1, v11);
}
*((_BYTE *)*a2 - 1) = 0;
result = fill_list(s);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s, const char **a2, _DWORD *a3, bool *a4)
{
int v6; // edx
__int64 result; // rax
int v8; // eax
const char *v9; // rax
const char *v10; // r12
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

if ( First )
{
bempty(Bbuff);
First = 0;
}
getbtxt(v11, 255LL);
v6 = func10(s, v11);
result = 0LL;
if ( v6 <= 0 )
{
v8 = strcmp(s, v11);
*a4 = v8 != 0;
if ( v8 )
makepaw(s, 0LL);
v9 = (const char *)lastpart(s);
*a2 = v9;
*a3 = strlen(v9);
v10 = *a2;
if ( *a2 == s )
{
result = func5("./");
}
else
{
if ( v10 - s == 1 )
{
strcpy(v11, *a2);
*a2 = v10 + 1;
strcpy((char *)v10 + 1, v11);
}
*((_BYTE *)*a2 - 1) = 0;
result = func5(s);
}
}
return result;
}

original_code:
static struct llist *getfill(char *dir, char **fname, int *len, _Bool *update)
{
 char txt[255 + 1];
 if (First) {
  bempty(Bbuff);
  First = 0;
 }
 getbtxt(txt, 255);
 if (pathfixup(dir, txt) > 0)
  return ((void *)0);
 *update = strcmp(dir, txt);
 if (*update)
  makepaw(dir, 0);
 *fname = lastpart(dir);
 *len = strlen(*fname);
 if (*fname == dir)
  return fill_list("./");
 if (*fname - dir == 1) {
  strcpy(txt, *fname);
  strcpy(++*fname, txt);
 }
 *(*fname - 1) = '\0';
 return fill_list(dir);
}

canonical_original_code:
static struct llist *getfill(char *dir, char **fname, int *len, _Bool *update)
{
 char txt[-1];
 if (First) {
  bempty(Bbuff);
  First = 0;
 }
 getbtxt(txt, 255);
 if (pathfixup(dir, txt) > 0)
  return ((void *)0);
 *update = strcmp(dir, txt);
 if (*update)
  makepaw(dir, 0);
 *fname = lastpart(dir);
 *len = strlen(*fname);
 if (*fname == dir)
  return fill_list("./");
 if (*fname - dir == 1) {
  strcpy(txt, *fname);
  strcpy(++*fname, txt);
 }
 *(*fname - 1) = '\0';
 return fill_list(dir);
}

variable_types:
dir
char *

variable_types:
fname
char **

variable_types:
len
int *

variable_types:
update
_Bool *

variable_types:
txt
char [-1]

return_type: struct llist { char fname[255]; struct llist *prev; } *


setit

decompiled_code:
int __fastcall setit(int a1, const char *a2)
{
char *v2; // rax

LODWORD(v2) = *((_DWORD *)&Vars + 8 * a1 + 2);
switch ( (_DWORD)v2 )
{
case 1:
goto LABEL_11;
case 2:
LODWORD(v2) = strncasecmp(a2, "true", 4uLL);
if ( !(_DWORD)v2 )
{
*((_DWORD *)&Vars + 8 * a1 + 4) = 1;
return (int)v2;
}
LODWORD(v2) = strncasecmp(a2, "false", 5uLL);
if ( !(_DWORD)v2 )
{
*((_DWORD *)&Vars + 8 * a1 + 4) = 0;
return (int)v2;
}
LABEL_11:
LODWORD(v2) = strtol(a2, 0LL, 0);
*((_DWORD *)&Vars + 8 * a1 + 4) = (_DWORD)v2;
return (int)v2;
case 0:
LODWORD(v2) = strcmp(*((const char **)&Vars + 4 * a1 + 2), a2);
if ( (_DWORD)v2 )
{
v2 = strdup(a2);
*((_QWORD *)&Vars + 4 * a1 + 2) = v2;
}
break;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2)
{
char *v2; // rax

LODWORD(v2) = *((_DWORD *)&Vars + 8 * a1 + 2);
switch ( (_DWORD)v2 )
{
case 1:
goto LABEL_11;
case 2:
LODWORD(v2) = strncasecmp(a2, "true", 4uLL);
if ( !(_DWORD)v2 )
{
*((_DWORD *)&Vars + 8 * a1 + 4) = 1;
return (int)v2;
}
LODWORD(v2) = strncasecmp(a2, "false", 5uLL);
if ( !(_DWORD)v2 )
{
*((_DWORD *)&Vars + 8 * a1 + 4) = 0;
return (int)v2;
}
LABEL_11:
LODWORD(v2) = strtol(a2, 0LL, 0);
*((_DWORD *)&Vars + 8 * a1 + 4) = (_DWORD)v2;
return (int)v2;
case 0:
LODWORD(v2) = strcmp(*((const char **)&Vars + 4 * a1 + 2), a2);
if ( (_DWORD)v2 )
{
v2 = strdup(a2);
*((_QWORD *)&Vars + 4 * a1 + 2) = v2;
}
break;
}
return (int)v2;
}

original_code:
static void setit(int i, const char *ptr)
{
 switch (Vars[i].vtype) {
 case V_STRING:
  if (strcmp(Vars[i].u.str, ptr))
   Vars[i].u.str = strdup(ptr);
  break;
 case V_FLAG:
  if (strncasecmp(ptr, "true", 4) == 0)
   Vars[i].u.val = 1;
  else if (strncasecmp(ptr, "false", 5) == 0)
   Vars[i].u.val = 0;
  else
   Vars[i].u.val = strtol(ptr, ((void *)0), 0);
  break;
 case V_DECIMAL:
  Vars[i].u.val = strtol(ptr, ((void *)0), 0);
 }
}

canonical_original_code:
static void setit(int i, char *ptr)
{
 switch (Vars[i].vtype) {
 case V_STRING:
  if (strcmp(Vars[i].u.str, ptr))
   Vars[i].u.str = strdup(ptr);
  break;
 case V_FLAG:
  if (strncasecmp(ptr, "true", 4) == 0)
   Vars[i].u.val = 1;
  else if (strncasecmp(ptr, "false", 5) == 0)
   Vars[i].u.val = 0;
  else
   Vars[i].u.val = strtol(ptr, ((void *)0), 0);
  break;
 case V_DECIMAL:
  Vars[i].u.val = strtol(ptr, ((void *)0), 0);
 }
}

variable_types: i int

variable_types:
ptr
char *


decompiled_code:
int __fastcall do_var_match(unsigned int a1, const char *a2)
{
const char *v2; // rbx
char v3; // bp
const unsigned __int16 *v4; // rax
const unsigned __int16 *v5; // rcx
__int64 v6; // rax

v2 = a2;
if ( Argp && Vars[8 * a1 + 2] )
{
v6 = 32LL * (int)a1;
*(_DWORD *)((char *)&Vars[4] + v6) = Arg;
}
else
{
v3 = *a2;
if ( *a2 )
{
v4 = *_ctype_b_loc();
do
{
if ( (v4[v3] & 0x2000) != 0 )
break;
v3 = *++v2;
}
while ( *v2 );
}
v5 = *_ctype_b_loc();
while ( 1 )
{
LODWORD(v6) = *(unsigned __int8 *)v2;
if ( (v5[(char)v6] & 0x2000) == 0 )
break;
++v2;
}
if ( (_BYTE)v6 )
LODWORD(v6) = setit(a1, v2);
}
if ( !Vars[36] )
Vars[36] = 1;
if ( a1 <= 0xA )
{
v6 = 1154LL;
if ( _bittest64(&v6, a1) )
{
LODWORD(v6) = Vars[8 * a1 + 4];
if ( (int)v6 <= 1 )
{
Vars[8 * a1 + 4] = 2;
}
else if ( (int)v6 > 8 )
{
Vars[8 * a1 + 4] = 8;
}
}
}
return v6;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, const char *a2)
{
const char *v2; // rbx
char v3; // bp
const unsigned __int16 *v4; // rax
const unsigned __int16 *v5; // rcx
__int64 v6; // rax

v2 = a2;
if ( Argp && Vars[8 * a1 + 2] )
{
v6 = 32LL * (int)a1;
*(_DWORD *)((char *)&Vars[4] + v6) = Arg;
}
else
{
v3 = *a2;
if ( *a2 )
{
v4 = *_ctype_b_loc();
do
{
if ( (v4[v3] & 0x2000) != 0 )
break;
v3 = *++v2;
}
while ( *v2 );
}
v5 = *_ctype_b_loc();
while ( 1 )
{
LODWORD(v6) = *(unsigned __int8 *)v2;
if ( (v5[(char)v6] & 0x2000) == 0 )
break;
++v2;
}
if ( (_BYTE)v6 )
LODWORD(v6) = func0(a1, v2);
}
if ( !Vars[36] )
Vars[36] = 1;
if ( a1 <= 0xA )
{
v6 = 1154LL;
if ( _bittest64(&v6, a1) )
{
LODWORD(v6) = Vars[8 * a1 + 4];
if ( (int)v6 <= 1 )
{
Vars[8 * a1 + 4] = 2;
}
else if ( (int)v6 > 8 )
{
Vars[8 * a1 + 4] = 8;
}
}
}
return v6;
}

variable_types:
vin
char *


settabsize

decompiled_code:
__int64 __fastcall settabsize(__int16 a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x1F00;
if ( v1 == 512 )
{
result = (unsigned int)Vars[12];
if ( (_DWORD)result == Tabsize )
result = 0LL;
else
Tabsize = Vars[12];
}
else if ( v1 == 2048 )
{
result = (unsigned int)Vars[60];
if ( (_DWORD)result == Tabsize )
result = 0LL;
else
Tabsize = Vars[60];
}
else
{
result = (unsigned int)Vars[84];
if ( (_DWORD)result == Tabsize )
result = 0LL;
else
Tabsize = Vars[84];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x1F00;
if ( v1 == 512 )
{
result = (unsigned int)Vars[12];
if ( (_DWORD)result == Tabsize )
result = 0LL;
else
Tabsize = Vars[12];
}
else if ( v1 == 2048 )
{
result = (unsigned int)Vars[60];
if ( (_DWORD)result == Tabsize )
result = 0LL;
else
Tabsize = Vars[60];
}
else
{
result = (unsigned int)Vars[84];
if ( (_DWORD)result == Tabsize )
result = 0LL;
else
Tabsize = Vars[84];
}
return result;
}

variable_types:
mode
unsigned int


setavar

decompiled_code:
int __fastcall setavar(const char *a1, char a2)
{
const char **v2; // rbp
unsigned __int64 v3; // rbx
int result; // eax
__int64 v5; // rax
const char *v6; // rdx
char v7[120]; // [rsp+0h] [rbp-78h] BYREF

strlcpy(v7, a1, 80LL);
strtok(v7, " \t");
v2 = (const char **)Vars;
v3 = 0LL;
while ( 1 )
{
result = strcasecmp(v7, *v2);
if ( !result )
break;
v3 = (unsigned int)(v3 + 1);
v2 += 4;
if ( (_DWORD)v3 == 11 )
goto LABEL_4;
}
result = do_var_match(v3, a1);
if ( !a2 )
goto LABEL_7;
if ( (unsigned int)v3 <= 0xA )
{
v5 = 1154LL;
if ( _bittest64(&v5, v3) )
{
settabsize(*(_DWORD *)(Curbuff + 76LL));
redisplay();
}
}
if ( Vars[8 * (int)v3 + 2] )
{
result = putpaw("%s = %d", *(const char **)&Vars[8 * (int)v3], (unsigned int)Vars[8 * (int)v3 + 4]);
}
else
{
v6 = *(const char **)&Vars[8 * (int)v3 + 4];
if ( v6 )
result = putpaw("%s = %s", *(const char **)&Vars[8 * (int)v3], v6);
else
result = putpaw("%s = NONE", *(const char **)&Vars[8 * (int)v3]);
}
if ( (_DWORD)v3 == 2 )
{
result = redisplay();
goto LABEL_7;
}
LABEL_4:
if ( (_DWORD)v3 == 11 && a2 )
result = putpaw("Variable '%s' Not Found", a1);
LABEL_7:
Arg = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, char a2)
{
const char **v2; // rbp
unsigned __int64 v3; // rbx
int result; // eax
__int64 v5; // rax
const char *v6; // rdx
char v7[120]; // [rsp+0h] [rbp-78h] BYREF

strlcpy(v7, a1, 80LL);
strtok(v7, " \t");
v2 = (const char **)Vars;
v3 = 0LL;
while ( 1 )
{
result = strcasecmp(v7, *v2);
if ( !result )
break;
v3 = (unsigned int)(v3 + 1);
v2 += 4;
if ( (_DWORD)v3 == 11 )
goto LABEL_4;
}
result = func1(v3, a1);
if ( !a2 )
goto LABEL_7;
if ( (unsigned int)v3 <= 0xA )
{
v5 = 1154LL;
if ( _bittest64(&v5, v3) )
{
func4(*(_DWORD *)(Curbuff + 76LL));
redisplay();
}
}
if ( Vars[8 * (int)v3 + 2] )
{
result = putpaw("%s = %d", *(const char **)&Vars[8 * (int)v3], (unsigned int)Vars[8 * (int)v3 + 4]);
}
else
{
v6 = *(const char **)&Vars[8 * (int)v3 + 4];
if ( v6 )
result = putpaw("%s = %s", *(const char **)&Vars[8 * (int)v3], v6);
else
result = putpaw("%s = NONE", *(const char **)&Vars[8 * (int)v3]);
}
if ( (_DWORD)v3 == 2 )
{
result = redisplay();
goto LABEL_7;
}
LABEL_4:
if ( (_DWORD)v3 == 11 && a2 )
result = putpaw("Variable '%s' Not Found", a1);
LABEL_7:
Arg = 0;
return result;
}

variable_types:
msg
char [-1]


readvfile

decompiled_code:
__int64 __fastcall readvfile(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = bcreate();
if ( !v1 || (v2 = v1, (unsigned int)breadfile(v1, a1, 0LL)) )
{
terror("Unable to read config file\n");
exit(1);
}
while ( (unsigned int)bstrline(v2, &PawStr, 266LL) )
setavar((const char *)&PawStr, 0);
return bdelbuff(v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = bcreate();
if ( !v1 || (v2 = v1, (unsigned int)breadfile(v1, a1, 0LL)) )
{
func3("Unable to read config file\n");
exit(1);
}
while ( (unsigned int)bstrline(v2, &PawStr, 266LL) )
func5((const char *)&PawStr, 0);
return bdelbuff(v2);
}

original_code:
void readvfile(const char *fname)
{
 struct buff *buff = bcreate();
 if (!buff || breadfile(buff, fname, ((void *)0))) {
  terror("Unable to read config file\n");
  exit(1);
 }
 while (bstrline(buff, PawStr, (256 + 10)))
  setavar(PawStr, 0);
 bdelbuff(buff);
}

canonical_original_code:
void readvfile(char *fname)
{
 struct buff *buff = bcreate();
 if (!buff || breadfile(buff, fname, ((void *)0))) {
  terror("Unable to read config file\n");
  exit(1);
 }
 while (bstrline(buff, PawStr, (256 + 10)))
  setavar(PawStr, 0);
 bdelbuff(buff);
}

variable_types:
fname
char *

variable_types: struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *


makecur

canonical_original_code:
static inline void makecur(struct buff *buff, struct page *page, int dist)
{
 buff->curpage = page;
 buff->curchar = dist;
 buff->curcptr = page->pdata + dist;
}

variable_types:
page
struct page *

variable_types: dist int


makeoffset

original_code:
static inline void makeoffset(struct buff *buff, int dist)
{
 buff->curchar = dist;
 buff->curcptr = buff->curpage->pdata + dist;
}


bmove

decompiled_code:
__int64 __fastcall bmove(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
__int64 v4; // r12
bool v5; // sf
unsigned int v6; // ebx
unsigned int v7; // er14

v2 = a2;
if ( !a2 )
return 1LL;
while ( 1 )
{
while ( 1 )
{
v4 = *(_QWORD *)(a1 + 16);
v5 = (int)(*(_DWORD *)(a1 + 32) + v2) < 0;
v6 = *(_DWORD *)(a1 + 32) + v2;
v2 = v6;
if ( !v5 )
break;
if ( *(_QWORD *)a1 == v4 )
{
makeoffset(a1, 0);
return 0LL;
}
makecur(a1, *(_QWORD *)(v4 + 4104), *(_DWORD *)(*(_QWORD *)(v4 + 4104) + 4096LL));
}
v7 = *(_DWORD *)(v4 + 4096);
if ( v6 < v7 )
{
makeoffset(a1, v6);
return 1LL;
}
if ( lastp(*(_QWORD *)(a1 + 16)) )
break;
v2 = v6 - v7;
makecur(a1, *(_QWORD *)(v4 + 4112), 0);
if ( v6 == v7 )
return 1LL;
}
makeoffset(a1, v7);
return 0LL;
}

original_code:
int bmove(struct buff *buff, int dist)
{
 while (dist) {
  struct page *curpage = buff->curpage;
  dist += buff->curchar;
  if (dist >= 0 && (unsigned int)dist < ((buff)->curpage->plen)) {
   makeoffset(buff, dist);
   return 1;
  }
  if (dist < 0) {
   if (curpage == buff->firstp) {
    makeoffset(buff, 0);
    return 0;
   }
   makecur(buff, curpage->prevp, curpage->prevp->plen);
  } else {
   if (lastp(curpage)) {
    makeoffset(buff, ((buff)->curpage->plen));
    return 0;
   }
   dist -= ((buff)->curpage->plen);
   makecur(buff, curpage->nextp, 0);
  }
 }
 return 1;
}

variable_types: struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *


bisstart

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) == *(_QWORD *)a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

original_code:
static inline int bisstart(struct buff *buff)
{
 return buff->curpage == buff->firstp && buff->curchar == 0;
}


bisend

decompiled_code:
_BOOL8 __fastcall bisend(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( !*(_QWORD *)(v1 + 4112) )
result = *(_DWORD *)(a1 + 32) >= *(_DWORD *)(v1 + 4096);
return result;
}

original_code:
static inline int bisend(struct buff *buff)
{
 return buff->curpage->nextp == ((void *)0) &&
  buff->curchar >= buff->curpage->plen;
}


original_code:
static inline void bmove1(struct buff *buff)
{
 if (++buff->curchar < ((buff)->curpage->plen))
  ++buff->curcptr;
 else if (buff->curpage->nextp)
  makecur(buff, buff->curpage->nextp, 0);
 else
  makeoffset(buff, ((buff)->curpage->plen));
}


bmovepast

decompiled_code:
void __fastcall bmovepast(__int64 a1, unsigned int (__fastcall *a2)(_QWORD), int a3)
{
if ( a3 )
{
while ( !bisend(a1) && a2(**(unsigned __int8 **)(a1 + 24)) )
bmove1(a1);
}
else
{
do
bmove(a1, 0xFFFFFFFFLL);
while ( !bisstart(a1) && a2(**(unsigned __int8 **)(a1 + 24)) );
if ( !a2(**(unsigned __int8 **)(a1 + 24)) )
bmove1(a1);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int (__fastcall *a2)(_QWORD), int a3)
{
if ( a3 )
{
while ( !func1(a1) && a2(**(unsigned __int8 **)(a1 + 24)) )
func4(a1);
}
else
{
do
bmove(a1, 0xFFFFFFFFLL);
while ( !func0(a1) && a2(**(unsigned __int8 **)(a1 + 24)) );
if ( !a2(**(unsigned __int8 **)(a1 + 24)) )
func4(a1);
}
}

original_code:
void bmovepast(struct buff *buff, int (*pred)(int), int forward)
{
 if (forward)
  while (!bisend(buff) && pred(*buff->curcptr))
   bmove1(buff);
 else {
  bmove(buff, -1);
  while (!bisstart(buff) && pred(*buff->curcptr))
   bmove(buff, -1);
  if (!pred(*buff->curcptr))
   bmove1(buff);
 }
}

variable_types: struct buff { struct page { char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; char *curcptr; unsigned int curchar; int bmodf; struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; } *marks; } *

variable_types:
pred
int (*)(int)

variable_types: forward int


bcreate

decompiled_code:
_QWORD *bcreate()
{
_QWORD *v0; // rbx
void *v1; // rax

v0 = calloc(1uLL, 0x30uLL);
if ( v0 )
{
v1 = calloc(1uLL, 0x1018uLL);
*v0 = v1;
if ( v1 )
{
v0[1] = v1;
makecur((__int64)v0, (__int64)v1, 0);
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rbx
void *v1; // rax

v0 = calloc(1uLL, 0x30uLL);
if ( v0 )
{
v1 = calloc(1uLL, 0x1018uLL);
*v0 = v1;
if ( v1 )
{
v0[1] = v1;
func0((__int64)v0, (__int64)v1, 0);
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

original_code:
struct buff *bcreate(void)
{
 struct buff *buf = (struct buff *)calloc(1, sizeof(struct buff));
 if (buf) {
  buf->firstp = calloc(1, sizeof(struct page));
  if (!buf->firstp) {
   free(buf);
   return ((void *)0);
  }
  buf->lastp = buf->firstp;
  makecur(buf, buf->firstp, 0);
 }
 return buf;
}

canonical_original_code:
struct buff *bcreate()
{
 struct buff *buf = (struct buff *)calloc(1, sizeof(struct buff));
 if (buf) {
  buf->firstp = calloc(1, sizeof(struct page));
  if (!buf->firstp) {
   free(buf);
   return ((void *)0);
  }
  buf->lastp = buf->firstp;
  makecur(buf, buf->firstp, 0);
 }
 return buf;
}

return_type: struct buff { struct page { unsigned char pdata[4096]; unsigned int plen; struct page *prevp; struct page *nextp; } *firstp; struct page *lastp; struct page *curpage; unsigned char *curcptr; unsigned int curchar; int bmodf; int in_undo; void *undo_tail; } *


btostart

decompiled_code:
void __fastcall btostart(__int64 *a1)
{
makecur((__int64)a1, *a1, 0);
}

canonical_decompiled_code:
void __fastcall func1(__int64 *a1)
{
func0((__int64)a1, *a1, 0);
}

original_code:
static inline void btostart(struct buff *buff)
{
 makecur(buff, buff->firstp, 0);
}


bmrktopnt

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

*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

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

*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 32);
*(_DWORD *)(a2 + 16) = result;
return result;
}

original_code:
static inline void bmrktopnt(struct buff *buff, struct mark *mark)
{
 mark->mbuff = buff;
 mark->mpage = buff->curpage;
 mark->moffset = buff->curchar;
}

variable_types: struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; } *


crfixup

decompiled_code:
void crfixup()
{
char *v0; // rax

v0 = (char *)memchr(
(const void *)(*(_QWORD *)(Bbuff + 16LL) + 1LL),
10,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Bbuff + 16LL) + 4096LL) - 1));
if ( v0 && *(v0 - 1) == 13 && !raw_mode )
{
*(_DWORD *)(Curbuff + 76LL) |= 0x20000u;
while ( (unsigned int)bcsearch(Bbuff, 13LL) )
{
if ( **(_BYTE **)(Bbuff + 24LL) == 10 )
{
bmove(Bbuff, 0xFFFFFFFFLL);
bdelete(Bbuff, 1LL);
}
}
btostart(Bbuff);
}
}

canonical_decompiled_code:
void func3()
{
char *v0; // rax

v0 = (char *)memchr(
(const void *)(*(_QWORD *)(Bbuff + 16LL) + 1LL),
10,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Bbuff + 16LL) + 4096LL) - 1));
if ( v0 && *(v0 - 1) == 13 && !raw_mode )
{
*(_DWORD *)(Curbuff + 76LL) |= 0x20000u;
while ( (unsigned int)bcsearch(Bbuff, 13LL) )
{
if ( **(_BYTE **)(Bbuff + 24LL) == 10 )
{
bmove(Bbuff, 0xFFFFFFFFLL);
bdelete(Bbuff, 1LL);
}
}
func1(Bbuff);
}
}

original_code:
static void crfixup(void)
{
 char *p = memchr(Bbuff->curpage->pdata + 1, '\n', ((Bbuff)->curpage->plen) - 1);
 if (!p)
  return;
 if (*(p - 1) != '\r')
  return;
 if (raw_mode)
  return;
 Curbuff->bmode |= 0x20000;
 while (bcsearch(Bbuff, '\r'))
  if ((*Bbuff->curcptr) == '\n') {
   bmove(Bbuff, -1);
   bdelete(Bbuff, 1);
  }
 btostart(Bbuff);
}

canonical_original_code:
static void crfixup()
{
 char *p = memchr(Bbuff->curpage->pdata + 1, '\n', ((Bbuff)->curpage->plen) - 1);
 if (!p)
  return;
 if (*(p - 1) != '\r')
  return;
 if (raw_mode)
  return;
 Curbuff->bmode |= 0x20000;
 while (bcsearch(Bbuff, '\r'))
  if ((*Bbuff->curcptr) == '\n') {
   bmove(Bbuff, -1);
   bdelete(Bbuff, 1);
  }
 btostart(Bbuff);
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall get_findfile(__int64 a1)
{
char *v2; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( Fname )
{
if ( !stat(&Fname, &v3) && (v3.st_mode & 0x8000) != 0 )
{
v2 = strrchr(&Fname, 47);
if ( v2 )
v2[1] = 0;
}
}
else
{
zgetcwd(&Fname, 255LL);
}
return getfname(a1, &Fname);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
char *v2; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( Fname )
{
if ( !stat(&Fname, &v3) && (v3.st_mode & 0x8000) != 0 )
{
v2 = strrchr(&Fname, 47);
if ( v2 )
v2[1] = 0;
}
}
else
{
zgetcwd(&Fname, 255LL);
}
return getfname(a1, &Fname);
}

original_code:
static int get_findfile(const char *prompt)
{
 struct stat sbuf;
 if (!*Fname)
  zgetcwd(Fname, 255);
 else if (stat(Fname, &sbuf) == 0)
  if (sbuf.st_mode & 0100000) {
   char *p = strrchr(Fname, '/');
   if (p)
    *(p + 1) = '\0';
  }
 return getfname(prompt, Fname);
}

canonical_original_code:
static int get_findfile(char *prompt)
{
 struct stat sbuf;
 if (!*Fname)
  zgetcwd(Fname, 255);
 else if (stat(Fname, &sbuf) == 0)
  if (sbuf.st_mode & 0100000) {
   char *p = strrchr(Fname, '/');
   if (p)
    *(p + 1) = '\0';
  }
 return getfname(prompt, Fname);
}

variable_types:
prompt
char *

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


lastpart

decompiled_code:
const char *__fastcall lastpart(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

original_code:
char *lastpart(char *fname)
{
 char *p = strrchr(fname, '/');
 if (p)
  return p + 1;
 else
  return fname;
}


decompiled_code:
__int64 file_mode()
{
__mode_t v1; // eax
__int16 v2; // bx

if ( !Cmask_0 )
{
v1 = umask(0);
v2 = v1;
umask(v1);
Cmask_0 = ~v2 & 0x1B6;
}
return Cmask_0 | *(_DWORD *)(Curbuff + 76LL) & 0x30000u;
}

canonical_decompiled_code:
__int64 func6()
{
__mode_t v1; // eax
__int16 v2; // bx

if ( !Cmask_0 )
{
v1 = umask(0);
v2 = v1;
umask(v1);
Cmask_0 = ~v2 & 0x1B6;
}
return Cmask_0 | *(_DWORD *)(Curbuff + 76LL) & 0x30000u;
}

original_code:
int file_mode(void)
{
 static int Cmask;
 if (Cmask == 0) {
  Cmask = umask(0);
  umask(Cmask);
  Cmask = ~Cmask & 0666;
 }
 return Cmask | (Curbuff->bmode & (0x10000 | 0x20000));
}

canonical_original_code:
int file_mode()
{
 static int Cmask;
 if (Cmask == 0) {
  Cmask = umask(0);
  umask(Cmask);
  Cmask = ~Cmask & 0666;
 }
 return Cmask | (Curbuff->bmode & (0x10000 | 0x20000));
}

variable_types: Cmask int