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


repo: smaclennan/zedit

decompiled_code:
__int64 file_mode()
{
int v0; // edx
__mode_t v2; // eax
__int16 v3; // bx

v0 = Cmask_0;
if ( !Cmask_0 )
{
v2 = umask(0);
v3 = v2;
umask(v2);
Cmask_0 = ~v3 & 0x1B6;
v0 = ~v3 & 0x1B6;
}
return v0 | *(_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

return_type: int


zwritefile

decompiled_code:
bool __fastcall zwritefile(char *name)
{
unsigned int v1; // eax
int v2; // ebx
const char *v3; // rdx
bool result; // al
const char *v5; // rax
int v6; // edx
const char *v7; // rax
int v8; // er8
_BYTE v9[32]; // [rsp+0h] [rbp-C8h] BYREF
struct stat v10; // [rsp+20h] [rbp-A8h] BYREF

if ( *(_QWORD *)(Curbuff + 48LL) && !stat(name, &v10) )
{
if ( v10.st_mtim.tv_sec > *(_QWORD *)(Curbuff + 48LL) )
{
v7 = lastpart(name);
strconcat(&PawStr, 266LL, "WARNING: ", v7, " has been modified. Overwrite? ", 0LL);
v8 = ask(&PawStr);
result = 0;
if ( v8 != 1 )
return result;
}
if ( SLODWORD(v10.st_nlink) > 1 )
{
v5 = lastpart(name);
strconcat(&PawStr, 266LL, "WARNING: ", v5, " is linked. Preserve? ", 0LL);
v6 = ask(&PawStr);
result = 0;
if ( v6 == -1 )
return result;
if ( !v6 )
unlink(name);
}
}
bmrktopnt(Bbuff, (__int64)v9);
v1 = file_mode();
v2 = bwritefile(Bbuff, name, v1);
bpnttomrk(Bbuff, v9);
if ( v2 )
{
if ( stat(name, &v10) )
*(_QWORD *)(Curbuff + 48LL) = -1LL;
else
*(_QWORD *)(Curbuff + 48LL) = v10.st_mtim.tv_sec;
putpaw(&unk_C04);
}
else if ( *_errno_location() == 13 )
{
error((int)"File is read only.", (int)v9, v3);
}
else
{
error((int)"Unable to write file.", (int)v9, v3);
}
return v2 != 0;
}

canonical_decompiled_code:
bool __fastcall func7(char *name)
{
unsigned int v1; // eax
int v2; // ebx
const char *v3; // rdx
bool result; // al
const char *v5; // rax
int v6; // edx
const char *v7; // rax
int v8; // er8
_BYTE v9[32]; // [rsp+0h] [rbp-C8h] BYREF
struct stat v10; // [rsp+20h] [rbp-A8h] BYREF

if ( *(_QWORD *)(Curbuff + 48LL) && !stat(name, &v10) )
{
if ( v10.st_mtim.tv_sec > *(_QWORD *)(Curbuff + 48LL) )
{
v7 = func5(name);
strconcat(&PawStr, 266LL, "WARNING: ", v7, " has been modified. Overwrite? ", 0LL);
v8 = ask(&PawStr);
result = 0;
if ( v8 != 1 )
return result;
}
if ( SLODWORD(v10.st_nlink) > 1 )
{
v5 = func5(name);
strconcat(&PawStr, 266LL, "WARNING: ", v5, " is linked. Preserve? ", 0LL);
v6 = ask(&PawStr);
result = 0;
if ( v6 == -1 )
return result;
if ( !v6 )
unlink(name);
}
}
func0(Bbuff, (__int64)v9);
v1 = func6();
v2 = bwritefile(Bbuff, name, v1);
bpnttomrk(Bbuff, v9);
if ( v2 )
{
if ( stat(name, &v10) )
*(_QWORD *)(Curbuff + 48LL) = -1LL;
else
*(_QWORD *)(Curbuff + 48LL) = v10.st_mtim.tv_sec;
putpaw(&unk_C04);
}
else if ( *_errno_location() == 13 )
{
error((int)"File is read only.", (int)v9, v3);
}
else
{
error((int)"Unable to write file.", (int)v9, v3);
}
return v2 != 0;
}

original_code:
static _Bool zwritefile(char *fname)
{
 struct mark smark;
 struct stat sbuf;
 int nlink = 1, rc;
 if (Curbuff->mtime && stat(fname, &sbuf) == 0) {
  if (sbuf.st_mtim.tv_sec > Curbuff->mtime) {
   strconcat(PawStr, (256 + 10),
      "WARNING: ", lastpart(fname),
      " has been modified. Overwrite? ", ((void *)0));
   if (ask(PawStr) != 1)
    return 0;
  }
  nlink = sbuf.st_nlink;
 }
 if (nlink > 1) {
  strconcat(PawStr, (256 + 10), "WARNING: ", lastpart(fname),
      " is linked. Preserve? ", ((void *)0));
  switch (ask(PawStr)) {
  case 1:
   break;
  case 0:
   unlink(fname);
   break;
  case -1:
   return 0;
  }
 }
 bmrktopnt(Bbuff, &smark);
 rc = bwritefile(Bbuff, fname, file_mode());
 bpnttomrk(Bbuff, &smark);
 if (rc) {
  if (stat(fname, &sbuf) == 0)
   Curbuff->mtime = sbuf.st_mtim.tv_sec;
  else
   Curbuff->mtime = -1;
  putpaw("");
 } else {
  if ((*__errno_location ()) == 13)
   error("File is read only.");
  else
   error("Unable to write file.");
 }
 return rc;
}

canonical_original_code:
static _Bool zwritefile(char *fname)
{
 struct mark smark;
 struct stat sbuf;
 int nlink = 1; int rc;
 if (Curbuff->mtime && stat(fname, &sbuf) == 0) {
  if (sbuf.st_mtim.tv_sec > Curbuff->mtime) {
   strconcat(PawStr, (256 + 10),
      "WARNING: ", lastpart(fname),
      " has been modified. Overwrite? ", ((void *)0));
   if (ask(PawStr) != 1)
    return 0;
  }
  nlink = sbuf.st_nlink;
 }
 if (nlink > 1) {
  strconcat(PawStr, (256 + 10), "WARNING: ", lastpart(fname),
      " is linked. Preserve? ", ((void *)0));
  switch (ask(PawStr)) {
  case 1:
   break;
  case 0:
   unlink(fname);
   break;
  case -1:
   return 0;
  }
 }
 bmrktopnt(Bbuff, &smark);
 rc = bwritefile(Bbuff, fname, file_mode());
 bpnttomrk(Bbuff, &smark);
 if (rc) {
  if (stat(fname, &sbuf) == 0)
   Curbuff->mtime = sbuf.st_mtim.tv_sec;
  else
   Curbuff->mtime = -1;
  putpaw("");
 } else {
  if ((*__errno_location ()) == 13)
   error("File is read only.");
  else
   error("Unable to write file.");
 }
 return rc;
}

variable_types:
fname
char *

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

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

variable_types: nlink int

variable_types: rc int

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

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

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


zreadfile

decompiled_code:
__int64 __fastcall zreadfile(const char *errnum)
{
int v2; // eax
__time_t v3; // rdx
int *v4; // rax
unsigned int v5; // er8
__int64 result; // rax
__int64 v7; // rdi
int v8; // eax
const char *v9; // rdx
__int64 v10; // rax
char *v11; // rax
int v12; // [rsp+Ch] [rbp-ACh] BYREF
struct stat v13; // [rsp+10h] [rbp-A8h] BYREF

v2 = stat(errnum, &v13);
v3 = v13.st_mtim.tv_sec;
if ( v2 )
{
v4 = _errno_location();
v5 = -1;
if ( *v4 != 2 )
return v5;
v3 = 0LL;
memset(&v13, 0, sizeof(v13));
}
v7 = Bbuff;
*(_QWORD *)(Curbuff + 48LL) = v3;
bempty(v7);
v8 = breadfile(Bbuff, errnum, &v12);
if ( v8 < 0 )
{
v5 = 1;
if ( v8 == -2 )
return v5;
v11 = strerror(-v8);
error((int)"%s: %s", (int)errnum, v11);
result = 0xFFFFFFFFLL;
}
else
{
if ( v8 == 1 )
{
error((int)"gzdopen %s", (int)errnum, v9);
return (unsigned int)-1;
}
v10 = Bbuff;
if ( v12 )
{
*(_DWORD *)(Curbuff + 76LL) |= 0x10000u;
}
else if ( *(_DWORD *)(*(_QWORD *)(Bbuff + 16LL) + 4096LL) )
{
crfixup();
v10 = Bbuff;
}
*(_DWORD *)(v10 + 36) = 0;
putpaw(&unk_C04);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *errnum)
{
int v2; // eax
__time_t v3; // rdx
int *v4; // rax
unsigned int v5; // er8
__int64 result; // rax
__int64 v7; // rdi
int v8; // eax
const char *v9; // rdx
__int64 v10; // rax
char *v11; // rax
int v12; // [rsp+Ch] [rbp-ACh] BYREF
struct stat v13; // [rsp+10h] [rbp-A8h] BYREF

v2 = stat(errnum, &v13);
v3 = v13.st_mtim.tv_sec;
if ( v2 )
{
v4 = _errno_location();
v5 = -1;
if ( *v4 != 2 )
return v5;
v3 = 0LL;
memset(&v13, 0, sizeof(v13));
}
v7 = Bbuff;
*(_QWORD *)(Curbuff + 48LL) = v3;
bempty(v7);
v8 = breadfile(Bbuff, errnum, &v12);
if ( v8 < 0 )
{
v5 = 1;
if ( v8 == -2 )
return v5;
v11 = strerror(-v8);
error((int)"%s: %s", (int)errnum, v11);
result = 0xFFFFFFFFLL;
}
else
{
if ( v8 == 1 )
{
error((int)"gzdopen %s", (int)errnum, v9);
return (unsigned int)-1;
}
v10 = Bbuff;
if ( v12 )
{
*(_DWORD *)(Curbuff + 76LL) |= 0x10000u;
}
else if ( *(_DWORD *)(*(_QWORD *)(Bbuff + 16LL) + 4096LL) )
{
func4();
v10 = Bbuff;
}
*(_DWORD *)(v10 + 36) = 0;
putpaw(&unk_C04);
result = 0LL;
}
return result;
}

original_code:
int zreadfile(char *fname)
{
 struct stat sbuf;
 int compressed, rc;
 if (stat(fname, &sbuf)) {
  if ((*__errno_location ()) == 2)
   memset(&sbuf, 0, sizeof(sbuf));
  else
   return -1;
 }
 Curbuff->mtime = sbuf.st_mtim.tv_sec;
 bempty(Bbuff);
  rc = breadfile(Bbuff, fname, &compressed);
 if (rc < 0) {
  if (rc == -2)
   return 1;
  error("%s: %s", fname, strerror(-rc));
  return -1;
 }
 if (rc == 1) {
  error("gzdopen %s", fname);
  return -1;
 }
 if (compressed)
  Curbuff->bmode |= 0x10000;
 else if (((Bbuff)->curpage->plen))
  crfixup();
 Bbuff->bmodf = 0;
 putpaw("");
 return 0;
}

canonical_original_code:
int zreadfile(char *fname)
{
 struct stat sbuf;
 int compressed; int rc;
 if (stat(fname, &sbuf)) {
  if ((*__errno_location ()) == 2)
   memset(&sbuf, 0, sizeof(sbuf));
  else
   return -1;
 }
 Curbuff->mtime = sbuf.st_mtim.tv_sec;
 bempty(Bbuff);
  rc = breadfile(Bbuff, fname, &compressed);
 if (rc < 0) {
  if (rc == -2)
   return 1;
  error("%s: %s", fname, strerror(-rc));
  return -1;
 }
 if (rc == 1) {
  error("gzdopen %s", fname);
  return -1;
 }
 if (compressed)
  Curbuff->bmode |= 0x10000;
 else if (((Bbuff)->curpage->plen))
  crfixup();
 Bbuff->bmodf = 0;
 putpaw("");
 return 0;
}

variable_types: compressed int

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


readone

decompiled_code:
__int64 __fastcall readone(__int64 a1, const char *a2)
{
unsigned int v3; // er12
__int64 v4; // r14
const char *v6; // rsi
int v7; // ebp
const char *v8; // rax

v3 = 1;
v4 = Curbuff;
if ( cfindbuff() )
return v3;
v3 = 0;
if ( !cmakebuff(a1, a2) )
return v3;
v6 = lastpart(a2);
putpaw("Reading %s", v6);
v7 = zreadfile(a2);
if ( v7 < 0 )
{
cdelbuff(Curbuff);
zswitchto(v4);
v8 = lastpart(a2);
putpaw("Read Error %s", v8);
return v3;
}
toggle_mode(0LL);
if ( v7 )
{
putpaw("New File");
}
else if ( access(a2, 6) == -1 )
{
*(_DWORD *)(Curbuff + 76LL) |= 4u;
}
set_last_bufname(v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2)
{
unsigned int v3; // er12
__int64 v4; // r14
const char *v6; // rsi
int v7; // ebp
const char *v8; // rax

v3 = 1;
v4 = Curbuff;
if ( cfindbuff() )
return v3;
v3 = 0;
if ( !cmakebuff(a1, a2) )
return v3;
v6 = func5(a2);
putpaw("Reading %s", v6);
v7 = func8(a2);
if ( v7 < 0 )
{
cdelbuff(Curbuff);
zswitchto(v4);
v8 = func5(a2);
putpaw("Read Error %s", v8);
return v3;
}
toggle_mode(0LL);
if ( v7 )
{
putpaw("New File");
}
else if ( access(a2, 6) == -1 )
{
*(_DWORD *)(Curbuff + 76LL) |= 4u;
}
set_last_bufname(v4);
return 1LL;
}

original_code:
static _Bool readone(char *bname, char *path)
{
 int rc;
 struct zbuff *was = Curbuff;
 if (cfindbuff(bname))
  return 1;
 if (!cmakebuff(bname, path))
  return 0;
 putpaw("Reading %s", lastpart(path));
 rc = zreadfile(path);
 if (rc < 0) {
  cdelbuff(Curbuff);
  zswitchto(was);
  putpaw("Read Error %s", lastpart(path));
  return 0;
 }
 toggle_mode(0);
 if (rc > 0)
  putpaw("New File");
 else if (access(path, 4 | 2) == -1)
  Curbuff->bmode |= 0x0004;
 set_last_bufname(was);
 return 1;
}

variable_types:
bname
char *

variable_types:
path
char *

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


findfile

decompiled_code:
__int64 __fastcall findfile(char *src)
{
__int64 v1; // r13
const char *v2; // rsi
__int64 v3; // rbp
const char *v4; // rsi
int v5; // er13
int v6; // eax
unsigned int v7; // ebp
char *v8; // r13
unsigned int v11; // er13
char v12[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = Curbuff;
Arg = 0;
v2 = lastpart(src);
strncpy(v12, v2, 0x1FuLL);
v3 = Bufflist;
v12[31] = 0;
if ( Bufflist )
{
while ( 1 )
{
v4 = *(const char **)(v3 + 24);
if ( v4 )
{
if ( !strcmp(src, v4) )
break;
}
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
goto LABEL_5;
}
zswitchto(v3);
if ( Initializing )
return 1;
set_last_bufname(v1);
}
else
{
LABEL_5:
if ( cfindbuff(v12) )
{
v5 = 28;
v6 = strlen(v12);
if ( v6 <= 28 )
v5 = v6;
v7 = 0;
v8 = &v12[v5];
do
{
strfmt(v8, 4LL, ".%d", v7);
if ( !cfindbuff(v12) )
break;
++v7;
}
while ( v7 != 99 );
if ( cfindbuff(v12) )
return 0;
}
if ( !(unsigned __int8)readone((__int64)v12, src) )
return 0;
}
v11 = Initializing;
if ( !Initializing )
{
cswitchto(Curbuff);
reframe();
return 1;
}
if ( Fname )
return 1;
strcpy(&Fname, src);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *src)
{
__int64 v1; // r13
const char *v2; // rsi
__int64 v3; // rbp
const char *v4; // rsi
int v5; // er13
int v6; // eax
unsigned int v7; // ebp
char *v8; // r13
unsigned int v11; // er13
char v12[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = Curbuff;
Arg = 0;
v2 = func5(src);
strncpy(v12, v2, 0x1FuLL);
v3 = Bufflist;
v12[31] = 0;
if ( Bufflist )
{
while ( 1 )
{
v4 = *(const char **)(v3 + 24);
if ( v4 )
{
if ( !strcmp(src, v4) )
break;
}
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
goto LABEL_5;
}
zswitchto(v3);
if ( Initializing )
return 1;
set_last_bufname(v1);
}
else
{
LABEL_5:
if ( cfindbuff(v12) )
{
v5 = 28;
v6 = strlen(v12);
if ( v6 <= 28 )
v5 = v6;
v7 = 0;
v8 = &v12[v5];
do
{
strfmt(v8, 4LL, ".%d", v7);
if ( !cfindbuff(v12) )
break;
++v7;
}
while ( v7 != 99 );
if ( cfindbuff(v12) )
return 0;
}
if ( !(unsigned __int8)func9((__int64)v12, src) )
return 0;
}
v11 = Initializing;
if ( !Initializing )
{
cswitchto(Curbuff);
reframe();
return 1;
}
if ( Fname )
return 1;
strcpy(&Fname, src);
return v11;
}

original_code:
_Bool findfile(char *path)
{
 char tbname[31 + 1];
 struct zbuff *tbuff;
 struct zbuff *was = Curbuff;
 Arg = 0;
 strncpy(tbname, lastpart(path), 31);
 tbname[31] = '\0';
 for ((tbuff) = Bufflist; (tbuff); (tbuff) = (tbuff)->next)
  if (tbuff->fname && strcmp(path, tbuff->fname) == 0) {
   zswitchto(tbuff);
   if (Initializing)
    return 1;
   set_last_bufname(was);
   break;
  }
 if (!tbuff) {
  if (cfindbuff(tbname)) {
   char *p;
   int i;
   i = strlen(tbname);
   p = &tbname[i < 31 - 3 ? i : 31 - 3];
   for (i = 0; i < 99; ++i) {
    strfmt(p, 4, ".%d", i);
    if (!cfindbuff(tbname))
     break;
   }
   if (cfindbuff(tbname))
    return 0;
  }
  if (!readone(tbname, path))
   return 0;
 }
 if (!Initializing) {
  cswitchto(Curbuff);
  reframe();
 } else if (!*Fname)
  strcpy(Fname, path);
 return 1;
}

canonical_original_code:
_Bool findfile(char *path)
{
 char tbname[-1];
 struct zbuff *tbuff;
 struct zbuff *was = Curbuff;
 Arg = 0;
 strncpy(tbname, lastpart(path), 31);
 tbname[31] = '\0';
 for ((tbuff) = Bufflist; (tbuff); (tbuff) = (tbuff)->next)
  if (tbuff->fname && strcmp(path, tbuff->fname) == 0) {
   zswitchto(tbuff);
   if (Initializing)
    return 1;
   set_last_bufname(was);
   break;
  }
 if (!tbuff) {
  if (cfindbuff(tbname)) {
   char *p;
   int i;
   i = strlen(tbname);
   p = &tbname[i < 31 - 3 ? i : 31 - 3];
   for (i = 0; i < 99; ++i) {
    strfmt(p, 4, ".%d", i);
    if (!cfindbuff(tbname))
     break;
   }
   if (cfindbuff(tbname))
    return 0;
  }
  if (!readone(tbname, path))
   return 0;
 }
 if (!Initializing) {
  cswitchto(Curbuff);
  reframe();
 } else if (!*Fname)
  strcpy(Fname, path);
 return 1;
}

variable_types:
tbname
char [-1]

variable_types:
p
char *

variable_types: i int

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


filesave

decompiled_code:
bool filesave()
{
const char *v0; // rdi
const char *v1; // rax
bool result; // al
int v3; // er8
__int64 v4; // rbx
char *v5; // rax
char v6[264]; // [rsp+0h] [rbp-108h] BYREF

Arg = 0;
v0 = *(const char **)(Curbuff + 24LL);
if ( v0 )
goto LABEL_2;
v6[0] = 0;
v3 = getfname("File Name: ", v6);
result = 0;
if ( !v3 )
{
v4 = Curbuff;
v5 = strdup(v6);
*(_QWORD *)(v4 + 24) = v5;
v0 = v5;
*(_DWORD *)(Curwdo + 56LL) = -1;
LABEL_2:
v1 = lastpart(v0);
putpaw("Writing %s", v1);
result = zwritefile(*(char **)(Curbuff + 24LL));
}
return result;
}

canonical_decompiled_code:
bool func14()
{
const char *v0; // rdi
const char *v1; // rax
bool result; // al
int v3; // er8
__int64 v4; // rbx
char *v5; // rax
char v6[264]; // [rsp+0h] [rbp-108h] BYREF

Arg = 0;
v0 = *(const char **)(Curbuff + 24LL);
if ( v0 )
goto LABEL_2;
v6[0] = 0;
v3 = getfname("File Name: ", v6);
result = 0;
if ( !v3 )
{
v4 = Curbuff;
v5 = strdup(v6);
*(_QWORD *)(v4 + 24) = v5;
v0 = v5;
*(_DWORD *)(Curwdo + 56LL) = -1;
LABEL_2:
v1 = func5(v0);
putpaw("Writing %s", v1);
result = func7(*(char **)(Curbuff + 24LL));
}
return result;
}

original_code:
_Bool filesave(void)
{
 char path[255 + 1];
 Arg = 0;
 if (Curbuff->fname == ((void *)0)) {
  *path = '\0';
  if (getfname("File Name: ", path) == 0)
   Curbuff->fname = strdup(path);
  else
   return 0;
  Curwdo->modeflags = -1;
 }
 putpaw("Writing %s", lastpart(Curbuff->fname));
 return zwritefile(Curbuff->fname);
}

canonical_original_code:
_Bool filesave()
{
 char path[-1];
 Arg = 0;
 if (Curbuff->fname == ((void *)0)) {
  *path = '\0';
  if (getfname("File Name: ", path) == 0)
   Curbuff->fname = strdup(path);
  else
   return 0;
  Curwdo->modeflags = -1;
 }
 putpaw("Writing %s", lastpart(Curbuff->fname));
 return zwritefile(Curbuff->fname);
}

variable_types:
path
char [-1]


bisaftermrk

original_code:
int bisaftermrk(struct buff *buff, struct mark *mark)
{
 struct page *tp;
 if (!mark->mpage || mark->mbuff != buff)
  return 0;
 if (mark->mpage == buff->curpage)
  return buff->curchar > mark->moffset;
 if (mark->mpage == buff->curpage->nextp)
  return 0;
 for (tp = buff->curpage->prevp;
   tp && tp != mark->mpage;
   tp = tp->prevp)
  ;
 return tp != ((void *)0);
}

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:
mark
struct mark *

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


tstyle

decompiled_code:
void __fastcall tstyle(int a1)
{
_BYTE *v1; // rax
__int16 v2; // [rsp+0h] [rbp-38h] BYREF
char v3[54]; // [rsp+2h] [rbp-36h] BYREF

if ( cur_style_0 != a1 )
{
v2 = 23323;
v1 = (_BYTE *)uint2str(a1, v3);
*v1 = 109;
twrite(&v2, v1 + 1 - (_BYTE *)&v2);
cur_style_0 = a1;
tflush();
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
_BYTE *v1; // rax
__int16 v2; // [rsp+0h] [rbp-38h] BYREF
char v3[54]; // [rsp+2h] [rbp-36h] BYREF

if ( cur_style_0 != a1 )
{
v2 = 23323;
v1 = (_BYTE *)uint2str(a1, v3);
*v1 = 109;
twrite(&v2, v1 + 1 - (_BYTE *)&v2);
cur_style_0 = a1;
tflush();
}
}

original_code:
void tstyle(int style)
{
 static int cur_style = -1;
 if (style == cur_style)
  return;
 char str[32], *p = str;
 *p++ = '\033'; *p++ = '[';
 p = uint2str(style, p);
 *p++ = 'm';
 twrite(str, p - str);
 cur_style = style;
 tflush();
}

canonical_original_code:
void tstyle(int style)
{
 static int cur_style = -1;
 if (style == cur_style)
  return;
 char str[32]; char *p = str;
 *p++ = '\033'; *p++ = '[';
 p = uint2str(style, p);
 *p++ = 'm';
 twrite(str, p - str);
 cur_style = style;
 tflush();
}

variable_types: style int

variable_types:
str
char [32]

return_type: void


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


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


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 *

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


btostart

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

canonical_decompiled_code:
void __fastcall func4(__int64 *a1)
{
func2((__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);
}


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

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

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

v2 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = v2;
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; } *


delinit

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

result = bcreate();
Killbuff = result;
return result;
}

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

result = bcreate();
Killbuff = result;
return result;
}

original_code:
void delinit(void)
{
 Killbuff = bcreate();
}

canonical_original_code:
void delinit()
{
 Killbuff = bcreate();
}


delfini

decompiled_code:
__int64 delfini()
{
return bdelbuff(Killbuff);
}

canonical_decompiled_code:
__int64 func9()
{
return bdelbuff(Killbuff);
}

original_code:
void delfini(void)
{
 bdelbuff(Killbuff);
}

canonical_original_code:
void delfini()
{
 bdelbuff(Killbuff);
}


delpages

decompiled_code:
__int64 delpages()
{
unsigned int v0; // er8
__int64 i; // rax

v0 = 0;
for ( i = *(_QWORD *)Killbuff; i; ++v0 )
i = *(_QWORD *)(i + 4112);
return v0;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // er8
__int64 i; // rax

v0 = 0;
for ( i = *(_QWORD *)Killbuff; i; ++v0 )
i = *(_QWORD *)(i + 4112);
return v0;
}

original_code:
unsigned int delpages(void)
{
 unsigned int npage = 0;
 for (struct page *page = Killbuff->firstp; page; page = page->nextp)
  ++npage;
 return npage;
}

canonical_original_code:
unsigned int delpages()
{
 unsigned int npage = 0;
 for (struct page *page = Killbuff->firstp; page; page = page->nextp)
  ++npage;
 return npage;
}

variable_types:
npage
unsigned int

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

return_type: unsigned int


delcmd

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

switch ( Lfunc )
{
case 0xD:
case 0x10:
case 0x11:
case 0x12:
case 0x14:
case 0x20:
case 0x27:
case 0x38:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( Lfunc )
{
case 0xD:
case 0x10:
case 0x11:
case 0x12:
case 0x14:
case 0x20:
case 0x27:
case 0x38:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}


copytomrk

decompiled_code:
__int64 __fastcall copytomrk(__int64 a1)
{
__int64 v1; // r8
__int64 result; // rax

if ( (unsigned __int8)delcmd() )
{
btoend(Killbuff);
result = bcopyrgn(a1, v1);
}
else
{
bempty(Killbuff);
result = bcopyrgn(a1, Killbuff);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // r8
__int64 result; // rax

if ( (unsigned __int8)func11() )
{
func5(Killbuff);
result = bcopyrgn(a1, v1);
}
else
{
bempty(Killbuff);
result = bcopyrgn(a1, Killbuff);
}
return result;
}

original_code:
static void copytomrk(struct mark *tmark)
{
 if (delcmd())
  btoend(Killbuff);
 else
  bempty(Killbuff);
 bcopyrgn(tmark, Killbuff);
}

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


killtomrk

decompiled_code:
__int64 __fastcall killtomrk(__int64 a1)
{
copytomrk(a1);
return bdeltomrk(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
func12(a1);
return bdeltomrk(a1);
}

original_code:
void killtomrk(struct mark *tmark)
{
 copytomrk(tmark);
 bdeltomrk(tmark);
}


decompiled_code:
__int64 Zdelete_blanks()
{
__int64 v0; // r12
__int64 v1; // rax
__int64 v2; // rbp
const char *v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdi
_BYTE v8[104]; // [rsp+0h] [rbp-68h] BYREF

v0 = bcremark(Bbuff);
v1 = bcremark(Bbuff);
v2 = v1;
if ( v0 && v1 )
{
if ( Argp )
{
Arg = 0;
if ( (unsigned int)re_compile(v8, "^[ \t]*\r?$", 1LL) )
{
error((int)"Internal re error.", (int)"^[ \t]*\r?$", v4);
}
else
{
btostart(Bbuff);
while ( (unsigned int)re_step(Bbuff, v8, v2) )
{
bmove1(Bbuff);
bdeltomrk(v2);
}
re_free(v8);
}
}
else
{
if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
{
bmove1(Bbuff);
bmrktopnt(Bbuff, v2);
bmovepast(Bbuff, &isspace, v6);
v7 = Bbuff;
if ( !bisstart(Bbuff) )
{
bcsearch(v7, 10LL);
v7 = Bbuff;
}
if ( (unsigned int)bisbeforemrk(v7, v2) )
bdeltomrk(v2);
}
if ( (unsigned int)bcsearch(Bbuff, 10LL) )
{
bmrktopnt(Bbuff, v2);
bmovepast(Bbuff, &isspace, v5);
if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
bmove1(Bbuff);
if ( (unsigned int)bisaftermrk(Bbuff, v2) )
bdeltomrk(v2);
}
}
}
else
{
tbell();
if ( !v0 )
goto LABEL_7;
}
bpnttomrk(Bbuff, v0);
LABEL_7:
bdelmark(v0);
return bdelmark(v2);
}

canonical_decompiled_code:
__int64 func25()
{
__int64 v0; // r12
__int64 v1; // rax
__int64 v2; // rbp
const char *v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdi
_BYTE v8[104]; // [rsp+0h] [rbp-68h] BYREF

v0 = bcremark(Bbuff);
v1 = bcremark(Bbuff);
v2 = v1;
if ( v0 && v1 )
{
if ( Argp )
{
Arg = 0;
if ( (unsigned int)re_compile(v8, "^[ \t]*\r?$", 1LL) )
{
error((int)"Internal re error.", (int)"^[ \t]*\r?$", v4);
}
else
{
func4(Bbuff);
while ( (unsigned int)re_step(Bbuff, v8, v2) )
{
func6(Bbuff);
bdeltomrk(v2);
}
re_free(v8);
}
}
else
{
if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
{
func6(Bbuff);
func7(Bbuff, v2);
bmovepast(Bbuff, &isspace, v6);
v7 = Bbuff;
if ( !func0(Bbuff) )
{
bcsearch(v7, 10LL);
v7 = Bbuff;
}
if ( (unsigned int)bisbeforemrk(v7, v2) )
bdeltomrk(v2);
}
if ( (unsigned int)bcsearch(Bbuff, 10LL) )
{
func7(Bbuff, v2);
bmovepast(Bbuff, &isspace, v5);
if ( (unsigned int)bcrsearch(Bbuff, 10LL) )
func6(Bbuff);
if ( (unsigned int)bisaftermrk(Bbuff, v2) )
bdeltomrk(v2);
}
}
}
else
{
tbell();
if ( !v0 )
goto LABEL_7;
}
bpnttomrk(Bbuff, v0);
LABEL_7:
bdelmark(v0);
return bdelmark(v2);
}

original_code: static void Zdelete_blanks(void) {}

canonical_original_code: static void Zdelete_blanks() {}


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 func0(__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;
}


bmrktopnt

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

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

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


original_code:
static int add_clumped(struct buff *buff, struct undo *undo, int size)
{
 int left;
 struct mark *mrk = &undo->mrk;
 left = mrk->mpage->plen - mrk->moffset;
 if (left >= size)
  mrk->moffset += size;
 else {
  size -= left;
  while (size > 0) {
   mrk->mpage = mrk->mpage->nextp;
   mrk->moffset = 0;
   if (!mrk->mpage)
    return 0;
   if (mrk->mpage->plen >= (unsigned int)size) {
    mrk->moffset = size;
    size = 0;
   } else
    size -= mrk->mpage->plen;
  }
 }
 return bisatmrk(buff, mrk);
}

variable_types: struct undo { struct undo *prev; unsigned char *data; unsigned long offset; struct mark { struct buff *mbuff; struct page *mpage; unsigned int moffset; } mrk; int size; } *

variable_types: size int

variable_types: left int

user_defined_types: struct undo { struct undo *prev; unsigned char *data; unsigned long offset; struct mark mrk; int size; }


original_code:
static int del_clumped(struct buff *buff, struct undo *undo, int size)
{
 struct mark *mrk = &undo->mrk;
 if (bisatmrk(buff, mrk))
  return 1;
 if (mrk->moffset >= (unsigned int)size) {
  mrk->moffset -= size;
 } else if (mrk->mpage->prevp) {
  mrk->mpage = mrk->mpage->prevp;
  mrk->moffset = mrk->mpage->plen - size;
 }
 if (bisatmrk(buff, mrk))
  return -1;
 return 0;
}


decompiled_code:
void __fastcall free_undo(void **a1)
{
void **v1; // rbp

v1 = (void **)*a1;
if ( *a1 )
{
*a1 = *v1;
free(v1[1]);
free(v1);
}
}

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

v1 = (void **)*a1;
if ( *a1 )
{
*a1 = *v1;
free(v1[1]);
free(v1);
}
}

original_code:
static void free_undo(void **tail)
{
 struct undo *undo = (struct undo *)*tail;
 if (undo) {
  *tail = undo->prev;
  free(undo->data);
  free(undo);
 }
}

variable_types:
tail
void **

variable_types: struct undo { struct undo *prev; unsigned char *data; unsigned long offset; 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; } mrk; int size; } *


decompiled_code:
char *__fastcall undo_prepend(__int64 a1, unsigned __int8 *a2)
{
char *result; // rax
_BYTE *v3; // rbp

result = (char *)realloc(*(void **)(a1 + 8), *(_DWORD *)(a1 + 48) + 1);
if ( result )
{
v3 = result;
memmove(result + 1, result, *(int *)(a1 + 48));
result = (char *)*a2;
*v3 = (_BYTE)result;
++*(_DWORD *)(a1 + 48);
*(_QWORD *)(a1 + 8) = v3;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1, unsigned __int8 *a2)
{
char *result; // rax
_BYTE *v3; // rbp

result = (char *)realloc(*(void **)(a1 + 8), *(_DWORD *)(a1 + 48) + 1);
if ( result )
{
v3 = result;
memmove(result + 1, result, *(int *)(a1 + 48));
result = (char *)*a2;
*v3 = (_BYTE)result;
++*(_DWORD *)(a1 + 48);
*(_QWORD *)(a1 + 8) = v3;
}
return result;
}

original_code:
static void undo_prepend(struct undo *undo, unsigned char *data)
{
 unsigned char *buf = (unsigned char *)realloc(undo->data, undo->size + 1);
 if (!buf)
  return;
 memmove(buf + 1, buf, undo->size);
 *buf = *data;
 undo->data = buf;
 undo->size++;
}

variable_types:
data
unsigned char *

variable_types:
buf
unsigned char *


original_code:
void undo_add(struct buff *buff, int size)
{
 struct undo *undo = (struct undo *)buff->undo_tail;
 if (buff->in_undo)
  return;
 if (undo && ((undo)->data == ((void *)0)) && add_clumped(buff, undo, size)) {
  undo->size += size;
  undo->offset += size;
 } else
  undo = new_undo(buff, &buff->undo_tail, 1, size);
 bmrktopnt(buff, &undo->mrk);
}


decompiled_code:
void **__fastcall undo_del(__int64 a1, int a2)
{
void **result; // rax
__int64 v3; // r12
int v4; // eax

result = (void **)*(unsigned int *)(a1 + 40);
if ( !(_DWORD)result && a2 )
{
v3 = *(_QWORD *)(a1 + 48);
if ( v3 && *(_QWORD *)(v3 + 8) )
{
v4 = del_clumped(a1, *(_QWORD *)(a1 + 48));
if ( v4 == -1 )
{
result = (void **)undo_prepend(v3, *(unsigned __int8 **)(a1 + 24));
--*(_QWORD *)(v3 + 16);
return result;
}
if ( v4 == 1 )
return (void **)undo_append(v3, *(_BYTE **)(a1 + 24));
}
result = (void **)new_undo(a1, (__int64 *)(a1 + 48), 0, a2);
if ( result )
result = (void **)memcpy(result[1], *(const void **)(a1 + 24), a2);
}
return result;
}

canonical_decompiled_code:
void **__fastcall func7(__int64 a1, int a2)
{
void **result; // rax
__int64 v3; // r12
int v4; // eax

result = (void **)*(unsigned int *)(a1 + 40);
if ( !(_DWORD)result && a2 )
{
v3 = *(_QWORD *)(a1 + 48);
if ( v3 && *(_QWORD *)(v3 + 8) )
{
v4 = func3(a1, *(_QWORD *)(a1 + 48));
if ( v4 == -1 )
{
result = (void **)func5(v3, *(unsigned __int8 **)(a1 + 24));
--*(_QWORD *)(v3 + 16);
return result;
}
if ( v4 == 1 )
return (void **)undo_append(v3, *(_BYTE **)(a1 + 24));
}
result = (void **)new_undo(a1, (__int64 *)(a1 + 48), 0, a2);
if ( result )
result = (void **)memcpy(result[1], *(const void **)(a1 + 24), a2);
}
return result;
}

original_code:
void undo_del(struct buff *buff, int size)
{
 struct undo *undo = (struct undo *)buff->undo_tail;
 if (buff->in_undo)
  return;
 if (size == 0)
  return;
 if (undo && !((undo)->data == ((void *)0)))
  switch (del_clumped(buff, undo, size)) {
  case 1:
   undo_append(undo, buff->curcptr);
   return;
  case -1:
   undo_prepend(undo, buff->curcptr);
   undo->offset--;
   return;
  }
 undo = new_undo(buff, &buff->undo_tail, 0, size);
 if (undo == ((void *)0))
  return;
 memcpy(undo->data, buff->curcptr, size);
}


decompiled_code:
void __fastcall undo_clear(__int64 a1)
{
while ( *(_QWORD *)(a1 + 48) )
free_undo((void **)(a1 + 48));
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
while ( *(_QWORD *)(a1 + 48) )
func4((void **)(a1 + 48));
}

original_code:
void undo_clear(struct buff *buff)
{
 while (buff->undo_tail)
  free_undo(&buff->undo_tail);
}


original_code:
int do_undo(struct buff *buff)
{
 struct undo *undo;
 int i;
 if (!buff->undo_tail)
  return 1;
 undo = (struct undo *)buff->undo_tail;
 buff->in_undo = 1;
 boffset(buff, undo->offset);
 if (((undo)->data == ((void *)0))) {
  bmove(buff, -undo->size);
  bdelete(buff, undo->size);
  free_undo(&buff->undo_tail);
 } else {
  unsigned long offset = undo->offset;
  struct mark *tmark = bcremark(buff);
  if (!tmark)
   return 1;
  do {
   for (i = 0; i < undo->size; ++i)
    binsert(buff, undo->data[i]);
   free_undo(&buff->undo_tail);
   undo = (struct undo *)buff->undo_tail;
  } while (undo && !((undo)->data == ((void *)0)) && undo->offset == offset);
  bpnttomrk(buff, tmark);
  bdelmark(tmark);
 }
 buff->in_undo = 0;
 return 0;
}

variable_types: i int

variable_types:
offset
unsigned long


bwritev

original_code:
int bwritev(struct buff *buff, int fd, unsigned int size)
{
 struct iovec iovs[16];
 struct page *pg;
 int i, n, amount, did = 0;
 do {
  unsigned int have = ((buff)->curpage->plen) - buff->curchar;
  iovs[0].iov_base = buff->curcptr;
  iovs[0].iov_len = (have < size ? have : size);
  size -= iovs[0].iov_len;
  amount = iovs[0].iov_len;
  for (pg = buff->curpage->nextp, i = 1;
    i < 16 && size > 0 && pg;
    ++i, pg = pg->nextp) {
   iovs[i].iov_base = pg->pdata;
   iovs[i].iov_len = (pg->plen < size ? pg->plen : size);
   size -= iovs[i].iov_len;
   amount += iovs[i].iov_len;
  }
  do
   n = writev(fd, iovs, i);
  while (n < 0 && (*__errno_location ()) == 4);
  if (n > 0) {
   bmove(buff, n);
   did += n;
  }
 } while (n == amount && size > 0);
 return did;
}

canonical_original_code:
int bwritev(struct buff *buff, int fd, unsigned int size)
{
 struct iovec iovs[16];
 struct page *pg;
 int i; int n; int amount; int did = 0;
 do {
  unsigned int have = ((buff)->curpage->plen) - buff->curchar;
  iovs[0].iov_base = buff->curcptr;
  iovs[0].iov_len = (have < size ? have : size);
  size -= iovs[0].iov_len;
  amount = iovs[0].iov_len;
  for (pg = buff->curpage->nextp, i = 1;
    i < 16 && size > 0 && pg;
    ++i, pg = pg->nextp) {
   iovs[i].iov_base = pg->pdata;
   iovs[i].iov_len = (pg->plen < size ? pg->plen : size);
   size -= iovs[i].iov_len;
   amount += iovs[i].iov_len;
  }
  do
   n = writev(fd, iovs, i);
  while (n < 0 && (*__errno_location ()) == 4);
  if (n > 0) {
   bmove(buff, n);
   did += n;
  }
 } while (n == amount && size > 0);
 return did;
}

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: fd int

variable_types:
size
unsigned int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [16]

variable_types: n int

variable_types: amount int

variable_types: did int

variable_types:
have
unsigned int


decompiled_code:
char *__fastcall special_label(int a1)
{
unsigned int v1; // edi
char *result; // rax

v1 = a1 - 225;
result = (char *)&unk_85B;
if ( v1 <= 0x17 )
result = key_label[v1];
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
unsigned int v1; // edi
char *result; // rax

v1 = a1 - 225;
result = (char *)&unk_85B;
if ( v1 <= 0x17 )
result = key_label[v1];
return result;
}

original_code:
static const char *special_label(int key)
{
 if (key >= (('a') + 128) && key <= (('x') + 128))
  return key_label[key - (('a') + 128)];
 else
  return "???";
}

canonical_original_code:
static char *special_label(int key)
{
 if (key >= (('a') + 128) && key <= (('x') + 128))
  return key_label[key - (('a') + 128)];
 else
  return "???";
}

variable_types: key int

return_type: char *


decompiled_code:
_BOOL8 __fastcall is_special(int a1)
{
return (unsigned int)(a1 - 225) <= 0x17;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
return (unsigned int)(a1 - 225) <= 0x17;
}

original_code:
static int is_special(int cmd)
{
 return cmd >= (('a') + 128) && cmd <= (('x') + 128);
}

variable_types: cmd int


decompiled_code:
__int64 __fastcall dump_bindings(int a1)
{
signed int v2; // ebx
int v3; // edx
__int64 result; // rax
unsigned int v5; // edi
char *v6; // rax

v2 = 0;
binstr(Bbuff, "\nBinding(s): ");
v3 = 0;
while ( 1 )
{
while ( 1 )
{
result = *((unsigned __int8 *)&Keys + v2);
if ( (_DWORD)result == a1 )
break;
if ( ++v2 == 384 )
goto LABEL_8;
}
if ( v3 )
{
LABEL_10:
binsert(Bbuff, 44LL);
Cmd = 32;
Zfill_check();
}
v5 = v2++;
v6 = dispkey(v5, (char *)&PawStr);
result = binstr(Bbuff, v6);
if ( v2 == 384 )
return result;
result = *((unsigned __int8 *)&Keys + v2);
if ( a1 == (_DWORD)result )
goto LABEL_10;
++v2;
v3 = 1;
if ( v2 == 384 )
{
LABEL_8:
if ( !v3 )
result = binstr(Bbuff, "Unbound");
return result;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
signed int v2; // ebx
int v3; // edx
__int64 result; // rax
unsigned int v5; // edi
char *v6; // rax

v2 = 0;
binstr(Bbuff, "\nBinding(s): ");
v3 = 0;
while ( 1 )
{
while ( 1 )
{
result = *((unsigned __int8 *)&Keys + v2);
if ( (_DWORD)result == a1 )
break;
if ( ++v2 == 384 )
goto LABEL_8;
}
if ( v3 )
{
LABEL_10:
binsert(Bbuff, 44LL);
Cmd = 32;
Zfill_check();
}
v5 = v2++;
v6 = func2(v5, (char *)&PawStr);
result = binstr(Bbuff, v6);
if ( v2 == 384 )
return result;
result = *((unsigned __int8 *)&Keys + v2);
if ( a1 == (_DWORD)result )
goto LABEL_10;
++v2;
v3 = 1;
if ( v2 == 384 )
{
LABEL_8:
if ( !v3 )
result = binstr(Bbuff, "Unbound");
return result;
}
}
}

original_code:
static void dump_bindings(int fnum)
{
 int k, found = 0;
 binstr(Bbuff, "\nBinding(s): ");
 for (k = 0; k < (128 + 128 + 128); ++k)
  if (Keys[k] == fnum) {
   if (found) {
    binsert(Bbuff, ',');
    Cmd = ' ';
    Zfill_check();
   } else
    found = 1;
   binstr(Bbuff, dispkey(k, PawStr));
  }
 if (!found)
  binstr(Bbuff, "Unbound");
}

canonical_original_code:
static void dump_bindings(int fnum)
{
 int k; int found = 0;
 binstr(Bbuff, "\nBinding(s): ");
 for (k = 0; k < (128 + 128 + 128); ++k)
  if (Keys[k] == fnum) {
   if (found) {
    binsert(Bbuff, ',');
    Cmd = ' ';
    Zfill_check();
   } else
    found = 1;
   binstr(Bbuff, dispkey(k, PawStr));
  }
 if (!found)
  binstr(Bbuff, "Unbound");
}

variable_types: fnum int

variable_types: k int

variable_types: found int


btostart

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

canonical_decompiled_code:
void __fastcall func5(__int64 *a1)
{
func4((__int64)a1, *a1);
}

original_code:
static inline void btostart(struct buff *buff)
{
 makecur(buff, buff->firstp, 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; } *


decompiled_code:
__int64 __fastcall dump_doc(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 i; // rsi

if ( a1 )
{
v1 = a1;
binstr(Bbuff, "\n\n");
for ( i = *a1; (_BYTE)i; ++v1 )
{
if ( (_BYTE)i == 32 )
{
Cmd = 32;
Zfill_check();
}
else
{
binsert(Bbuff, i);
}
i = v1[1];
}
}
return binsert(Bbuff, 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 i; // rsi

if ( a1 )
{
v1 = a1;
binstr(Bbuff, "\n\n");
for ( i = *a1; (_BYTE)i; ++v1 )
{
if ( (_BYTE)i == 32 )
{
Cmd = 32;
Zfill_check();
}
else
{
binsert(Bbuff, i);
}
i = v1[1];
}
}
return binsert(Bbuff, 10LL);
}

original_code:
void dump_doc(const char *doc)
{
 if (doc) {
  binstr(Bbuff, "\n\n");
  for (; *doc; ++doc)
   if (*doc == ' ') {
    Cmd = *doc;
    Zfill_check();
   } else
    binsert(Bbuff, *doc);
 }
 binsert(Bbuff, '\n');
}

canonical_original_code:
void dump_doc(char *doc)
{
 if (doc) {
  binstr(Bbuff, "\n\n");
  for (; *doc; ++doc)
   if (*doc == ' ') {
    Cmd = *doc;
    Zfill_check();
   } else
    binsert(Bbuff, *doc);
 }
 binsert(Bbuff, '\n');
}

variable_types:
doc
char *


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


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


bmrktopnt

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

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

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

v2 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = v2;
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; } *


mrkatmrk

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

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

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

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

original_code:
static inline int mrkatmrk(struct mark *m1, struct mark *m2)
{
 return m1->moffset == m2->moffset &&
  m1->mpage == m2->mpage &&
  m1->mbuff == m2->mbuff;
}

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


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


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 *


breadv

original_code:
int breadv(struct buff *buff, int fd)
{
 int n, n_read, left;
 struct page *npage;
 struct iovec iovs[2];
 if (buff->curchar != ((buff)->curpage->plen)) {
  if (!pagesplit(buff, buff->curchar)) {
   (*__errno_location ()) = 12;
   return -1;
  }
 }
 left = 4096 - ((buff)->curpage->plen);
 if (left) {
  iovs[0].iov_base = buff->curcptr;
  iovs[0].iov_len = left;
 } else
  iovs[0].iov_len = 0;
 npage = newpage(buff);
 if (!npage) {
  (*__errno_location ()) = 12;
  return -1;
 }
 iovs[1].iov_base = npage->pdata;
 iovs[1].iov_len = 4096;
 n = n_read = readv(fd, iovs, 2);
 if (n <= 0) {
  freepage(buff, npage);
  return n;
 }
 if (left) {
  int wrote = (left < n ? left : n);
  buff->curcptr += wrote;
  buff->curchar += wrote;
  ((buff)->curpage->plen) += wrote;
  n -= wrote;
 }
 if (n > 0) {
  makecur(buff, npage, n);
  ((buff)->curpage->plen) = n;
 } else
  freepage(buff, npage);
 return n_read;
}

canonical_original_code:
int breadv(struct buff *buff, int fd)
{
 int n; int n_read; int left;
 struct page *npage;
 struct iovec iovs[2];
 if (buff->curchar != ((buff)->curpage->plen)) {
  if (!pagesplit(buff, buff->curchar)) {
   (*__errno_location ()) = 12;
   return -1;
  }
 }
 left = 4096 - ((buff)->curpage->plen);
 if (left) {
  iovs[0].iov_base = buff->curcptr;
  iovs[0].iov_len = left;
 } else
  iovs[0].iov_len = 0;
 npage = newpage(buff);
 if (!npage) {
  (*__errno_location ()) = 12;
  return -1;
 }
 iovs[1].iov_base = npage->pdata;
 iovs[1].iov_len = 4096;
 n = n_read = readv(fd, iovs, 2);
 if (n <= 0) {
  freepage(buff, npage);
  return n;
 }
 if (left) {
  int wrote = (left < n ? left : n);
  buff->curcptr += wrote;
  buff->curchar += wrote;
  ((buff)->curpage->plen) += wrote;
  n -= wrote;
 }
 if (n > 0) {
  makecur(buff, npage, n);
  ((buff)->curpage->plen) = n;
 } else
  freepage(buff, npage);
 return n_read;
}

variable_types: fd int

variable_types: left int

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

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

variable_types: wrote int


bmrktopnt

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

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


btostart

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

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


bline

decompiled_code:
__int64 __fastcall bline(__int64 *a1)
{
__int64 v1; // r12
_BYTE v3[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = 1LL;
bmrktopnt((__int64)a1, (__int64)v3);
btostart(a1);
while ( (unsigned int)bcsearch(a1, 10LL) && !(unsigned int)bisaftermrk(a1, v3) )
++v1;
bpnttomrk(a1, v3);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // r12
_BYTE v3[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = 1LL;
func0((__int64)a1, (__int64)v3);
func2(a1);
while ( (unsigned int)bcsearch(a1, 10LL) && !(unsigned int)bisaftermrk(a1, v3) )
++v1;
bpnttomrk(a1, v3);
return v1;
}

original_code:
unsigned long bline(struct buff *buff)
{
 struct mark tmark;
 unsigned long line = 1;
 bmrktopnt(buff, &tmark);
 btostart(buff);
 while (bcsearch(buff, '\n') && !bisaftermrk(buff, &tmark))
  ++line;
 bpnttomrk(buff, &tmark);
 return line;
}

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

variable_types:
line
unsigned long

return_type: unsigned long


decompiled_code:
void dummy_bsetmod()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: static void dummy_bsetmod(struct buff *buff) {}


mrkaftermrk

original_code:
int mrkaftermrk(struct mark *mark1, struct mark *mark2)
{
 struct page *tpage;
 if (!mark1->mpage || !mark2->mpage || mark1->mbuff != mark2->mbuff)
  return 0;
 if (mark1->mpage == mark2->mpage)
  return mark1->moffset > mark2->moffset;
 if (mark1->mpage->nextp == mark2->mpage)
  return 0;
 for (tpage = mark1->mpage->prevp;
   tpage && tpage != mark2->mpage;
   tpage = tpage->prevp)
  ;
 return tpage != ((void *)0);
}

variable_types: struct mark { 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 *marks; } *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; } *

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


bisend

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


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


bstrline

decompiled_code:
__int64 __fastcall bstrline(__int64 a1, _BYTE *a2, int a3)
{
int v3; // er12
char v6; // al
int v7; // ecx
_BOOL4 v8; // er8
char v9; // al

v3 = a3;
if ( a3 )
{
tobegline();
if ( v3 <= 1 )
{
v3 = 0;
}
else
{
v3 = 0;
do
{
if ( bisend(a1) )
break;
v6 = **(_BYTE **)(a1 + 24);
if ( v6 == 10 )
break;
*a2 = v6;
++v3;
++a2;
bmove1(a1);
}
while ( v3 != v7 );
}
*a2 = 0;
while ( 1 )
{
v8 = bisend(a1);
v9 = **(_BYTE **)(a1 + 24);
if ( v8 )
break;
if ( v9 == 10 )
goto LABEL_13;
++v3;
bmove1(a1);
}
if ( v9 != 10 )
return (unsigned int)v3;
LABEL_13:
bmove1(a1);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2, int a3)
{
int v3; // er12
char v6; // al
int v7; // ecx
_BOOL4 v8; // er8
char v9; // al

v3 = a3;
if ( a3 )
{
tobegline();
if ( v3 <= 1 )
{
v3 = 0;
}
else
{
v3 = 0;
do
{
if ( func0(a1) )
break;
v6 = **(_BYTE **)(a1 + 24);
if ( v6 == 10 )
break;
*a2 = v6;
++v3;
++a2;
func3(a1);
}
while ( v3 != v7 );
}
*a2 = 0;
while ( 1 )
{
v8 = func0(a1);
v9 = **(_BYTE **)(a1 + 24);
if ( v8 )
break;
if ( v9 == 10 )
goto LABEL_13;
++v3;
func3(a1);
}
if ( v9 != 10 )
return (unsigned int)v3;
LABEL_13:
func3(a1);
}
return (unsigned int)v3;
}

original_code:
int bstrline(struct buff *buff, char *str, int len)
{
 int count = 0;
 if (len == 0)
  return 0;
 tobegline(buff);
 while (len > 1 && !bisend(buff) && *buff->curcptr != '\n') {
  *str++ = *buff->curcptr;
  --len;
  ++count;
  bmove1(buff);
 }
 *str = 0;
 while (!bisend(buff) && *buff->curcptr != '\n') {
  ++count;
  bmove1(buff);
 }
 if (*buff->curcptr == '\n')
  bmove1(buff);
 return count;
}

variable_types:
str
char *

variable_types: len int

variable_types: count int


bwritefd

decompiled_code:
__int64 __fastcall bwritefd(__int64 *a1, int a2)
{
__int64 v2; // rbx
char v3; // al
unsigned int v4; // er12
bool v5; // zf

v2 = *a1;
if ( *a1 )
{
while ( 1 )
{
v3 = 1;
v4 = 1;
if ( *(_DWORD *)(v2 + 4096) )
{
makecur_constprop_0((__int64)a1, v2);
v5 = *(_DWORD *)(v2 + 4096) == (unsigned int)write(a2, (const void *)v2, *(unsigned int *)(v2 + 4096));
v2 = *(_QWORD *)(v2 + 4112);
v3 = v5;
v4 = v5;
if ( !v2 )
goto LABEL_7;
}
else
{
v2 = *(_QWORD *)(v2 + 4112);
if ( !v2 )
goto LABEL_7;
}
if ( !v3 )
goto LABEL_7;
}
}
v4 = 1;
LABEL_7:
close(a2);
return v4;
}

original_code:
static int bwritefd(struct buff *buff, int fd)
{
 struct page *tpage;
 int n, status = 1;
 for (tpage = buff->firstp; tpage && status; tpage = tpage->nextp)
  if (tpage->plen) {
   makecur(buff, tpage, 0);
   n = write(fd, tpage->pdata, tpage->plen);
   status = n == tpage->plen;
  }
 close(fd);
 return status;
}

canonical_original_code:
static int bwritefd(struct buff *buff, int fd)
{
 struct page *tpage;
 int n; int status = 1;
 for (tpage = buff->firstp; tpage && status; tpage = tpage->nextp)
  if (tpage->plen) {
   makecur(buff, tpage, 0);
   n = write(fd, tpage->pdata, tpage->plen);
   status = n == tpage->plen;
  }
 close(fd);
 return status;
}

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: n int

variable_types: status int


btostart

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

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


bwritefile

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

if ( a2 )
{
v4 = creat(a2, a3 & 0x1FF);
if ( v4 >= 0 )
{
if ( (a3 & 0x20000) != 0 )
v5 = bwritedos((__int64 *)a1, v4);
else
v5 = bwritefd((__int64 *)a1, v4);
if ( v5 )
*(_DWORD *)(a1 + 36) = 0;
}
}
btostart((__int64 *)a1);
}

original_code:
int bwritefile(struct buff *buff, char *fname, int mode)
{
 int fd;
 int status = 0;
 if (!fname)
  goto done;
 fd = creat(fname, mode & 0777);
 if (fd < 0)
  goto done;
  if (mode & 0x20000)
   status = bwritedos(buff, fd);
  else
   status = bwritefd(buff, fd);
 if (status)
  buff->bmodf = 0;
done:
 btostart(buff);
 return status;
}

variable_types:
fname
char *

variable_types: mode int

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


makeoffset

variable_types: dist int


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 func2(__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

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

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


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 func4(__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; } *


newcomment

decompiled_code:
void __fastcall newcomment(__int64 a1)
{
__int64 *v2; // rax
__int64 *v3; // rbp
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rax
__int64 v7; // rdi
__int64 v8; // rax

v2 = (__int64 *)calloc(0x18uLL, 1uLL);
if ( v2 )
{
v3 = v2;
v4 = bcremark(Bbuff);
v5 = Bbuff;
*v3 = v4;
v6 = bcremark(v5);
v7 = *v3;
v3[1] = v6;
if ( v7 && v6 )
{
mrktomrk(v7, a1);
v8 = Curbuff;
if ( *(_QWORD *)(Curbuff + 56LL) )
*(_QWORD *)(*(_QWORD *)(Curbuff + 64LL) + 16LL) = v3;
else
*(_QWORD *)(Curbuff + 56LL) = v3;
*(_QWORD *)(v8 + 64) = v3;
}
else
{
((void (*)(void))bdelmark)();
bdelmark(v3[1]);
free(v3);
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
__int64 *v2; // rax
__int64 *v3; // rbp
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rax
__int64 v7; // rdi
__int64 v8; // rax

v2 = (__int64 *)calloc(0x18uLL, 1uLL);
if ( v2 )
{
v3 = v2;
v4 = bcremark(Bbuff);
v5 = Bbuff;
*v3 = v4;
v6 = bcremark(v5);
v7 = *v3;
v3[1] = v6;
if ( v7 && v6 )
{
func4(v7, a1);
v8 = Curbuff;
if ( *(_QWORD *)(Curbuff + 56LL) )
*(_QWORD *)(*(_QWORD *)(Curbuff + 64LL) + 16LL) = v3;
else
*(_QWORD *)(Curbuff + 56LL) = v3;
*(_QWORD *)(v8 + 64) = v3;
}
else
{
((void (*)(void))bdelmark)();
bdelmark(v3[1]);
free(v3);
}
}
}

original_code:
static void newcomment(struct mark *start)
{
 struct comment *com = calloc(sizeof(struct comment), 1);
 if (!com)
  return;
 com->start = bcremark(Bbuff);
 com->end = bcremark(Bbuff);
 if (!com->start || !com->end) {
  bdelmark(com->start);
  bdelmark(com->end);
  free(com);
  return;
 }
 mrktomrk(com->start, start);
 if (!Curbuff->chead)
  Curbuff->chead = com;
 else
  ((struct comment *)Curbuff->ctail)->next = com;
 Curbuff->ctail = com;
}

variable_types: struct comment { 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; } *start; struct comment *next; } *

user_defined_types: struct comment { struct mark *start; struct comment *next; }


btostart

canonical_decompiled_code:
void __fastcall func8(__int64 *a1)
{
func6((__int64)a1, *a1);
}

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


resetcomments

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

start = *(_QWORD *)(Curbuff + 56LL);
result = (unsigned __int8)(Lfunc - 13);
switch ( Lfunc )
{
case 0xD:
case 0xF:
case 0x10:
case 0x11:
case 0x12:
case 0x14:
case 0x20:
case 0x22:
case 0x27:
case 0x37:
case 0x38:
case 0x49:
case 0x4B:
case 0x69:
Comstate = 0;
break;
default:
return result;
}
return result;
}

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

start = *(_QWORD *)(Curbuff + 56LL);
result = (unsigned __int8)(Lfunc - 13);
switch ( Lfunc )
{
case 0xD:
case 0xF:
case 0x10:
case 0x11:
case 0x12:
case 0x14:
case 0x20:
case 0x22:
case 0x27:
case 0x37:
case 0x38:
case 0x49:
case 0x4B:
case 0x69:
Comstate = 0;
break;
default:
return result;
}
return result;
}


uncomment

original_code:
void uncomment(struct zbuff *buff)
{
 if (buff)
  while (buff->chead) {
   struct comment *com = buff->chead;
   buff->chead = com->next;
   bdelmark(com->start);
   bdelmark(com->end);
   free(com);
  }
 Comstate = 0;
}

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


scanbuffer

decompiled_code:
__int64 __fastcall scanbuffer(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rdi
int v3; // eax
char v4; // al
int v5; // eax
__int64 result; // rax
_BYTE v7[32]; // [rsp+0h] [rbp-58h] BYREF
char v8[56]; // [rsp+20h] [rbp-38h] BYREF

v1 = *(unsigned __int8 *)(Curbuff + 72LL);
uncomment(a1);
invalidate_scrnmarks(0LL, (unsigned int)(Rowmax - 2));
zswitchto(a1);
bmrktopnt(Bbuff, (__int64)v7);
btostart(Bbuff);
if ( !(_BYTE)v1 )
{
while ( 1 )
{
LABEL_2:
v2 = Bbuff;
while ( 1 )
{
v3 = bcsearch(v2, 47LL);
v2 = Bbuff;
if ( !v3 || bisend(Bbuff) )
goto LABEL_16;
v4 = **(_BYTE **)(v2 + 24);
if ( v4 == 42 )
break;
if ( v4 == 47 )
{
bmove(v2, 0xFFFFFFFFLL);
bmrktopnt(Bbuff, (__int64)v8);
toendline(Bbuff);
LABEL_8:
newcomment((__int64)v8);
goto LABEL_2;
}
}
bmove(v2, 0xFFFFFFFFLL);
bmrktopnt(Bbuff, (__int64)v8);
if ( (unsigned int)bm_search(Bbuff, &unk_840) )
goto LABEL_8;
}
}
while ( 1 )
{
v5 = bcsearch(Bbuff, v1);
v2 = Bbuff;
if ( !v5 || bisend(Bbuff) )
break;
if ( !(unsigned int)bmove(v2, 4294967294LL) )
goto LABEL_15;
if ( ((*_ctype_b_loc())[**(unsigned __int8 **)(Bbuff + 24LL)] & 0x2000) != 0 )
{
bmove1(Bbuff);
LABEL_15:
bmrktopnt(Bbuff, (__int64)v8);
bcsearch(Bbuff, 10LL);
bmove(Bbuff, 0xFFFFFFFFLL);
newcomment((__int64)v8);
}
else
{
bmove(Bbuff, 2LL);
}
}
LABEL_16:
result = bpnttomrk(v2, v7);
Comstate = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rdi
int v3; // eax
char v4; // al
int v5; // eax
__int64 result; // rax
_BYTE v7[32]; // [rsp+0h] [rbp-58h] BYREF
char v8[56]; // [rsp+20h] [rbp-38h] BYREF

v1 = *(unsigned __int8 *)(Curbuff + 72LL);
func10(a1);
invalidate_scrnmarks(0LL, (unsigned int)(Rowmax - 2));
zswitchto(a1);
func3(Bbuff, (__int64)v7);
func8(Bbuff);
if ( !(_BYTE)v1 )
{
while ( 1 )
{
LABEL_2:
v2 = Bbuff;
while ( 1 )
{
v3 = bcsearch(v2, 47LL);
v2 = Bbuff;
if ( !v3 || func0(Bbuff) )
goto LABEL_16;
v4 = **(_BYTE **)(v2 + 24);
if ( v4 == 42 )
break;
if ( v4 == 47 )
{
bmove(v2, 0xFFFFFFFFLL);
func3(Bbuff, (__int64)v8);
toendline(Bbuff);
LABEL_8:
func5((__int64)v8);
goto LABEL_2;
}
}
bmove(v2, 0xFFFFFFFFLL);
func3(Bbuff, (__int64)v8);
if ( (unsigned int)bm_search(Bbuff, &unk_840) )
goto LABEL_8;
}
}
while ( 1 )
{
v5 = bcsearch(Bbuff, v1);
v2 = Bbuff;
if ( !v5 || func0(Bbuff) )
break;
if ( !(unsigned int)bmove(v2, 4294967294LL) )
goto LABEL_15;
if ( ((*_ctype_b_loc())[**(unsigned __int8 **)(Bbuff + 24LL)] & 0x2000) != 0 )
{
func7(Bbuff);
LABEL_15:
func3(Bbuff, (__int64)v8);
bcsearch(Bbuff, 10LL);
bmove(Bbuff, 0xFFFFFFFFLL);
func5((__int64)v8);
}
else
{
bmove(Bbuff, 2LL);
}
}
LABEL_16:
result = bpnttomrk(v2, v7);
Comstate = 1;
return result;
}

original_code:
static void scanbuffer(struct zbuff *buff)
{
 struct mark tmark, start;
 unsigned char comchar = Curbuff->comchar;
 uncomment(buff);
 invalidate_scrnmarks(0, Rowmax - 2);
 zswitchto(buff);
 bmrktopnt(Bbuff, &tmark);
 btostart(Bbuff);
 if (comchar) {
  while (bcsearch(Bbuff, comchar) && !bisend(Bbuff)) {
   if (bmove(Bbuff, -2) == 0) {
   } else if (((*__ctype_b_loc ())[(int) (((*Bbuff->curcptr)))] & (unsigned short int) _ISspace))
    bmove1(Bbuff);
   else {
    bmove(Bbuff, 2);
    continue;
   }
   bmrktopnt(Bbuff, &start);
   bcsearch(Bbuff, '\n');
   bmove(Bbuff, -1);
   newcomment(&start);
  }
 } else {
  while (bcsearch(Bbuff, '/') && !bisend(Bbuff)) {
   if ((*Bbuff->curcptr) == '*') {
    bmove(Bbuff, -1);
    bmrktopnt(Bbuff, &start);
    if (bm_search(Bbuff, "*/", 0))
     newcomment(&start);
   } else if ((*Bbuff->curcptr) == '/') {
    bmove(Bbuff, -1);
    bmrktopnt(Bbuff, &start);
    toendline(Bbuff);
    newcomment(&start);
   }
  }
 }
 bpnttomrk(Bbuff, &tmark);
 Comstate = 1;
}

canonical_original_code:
static void scanbuffer(struct zbuff *buff)
{
 struct mark tmark; struct mark start;
 unsigned char comchar = Curbuff->comchar;
 uncomment(buff);
 invalidate_scrnmarks(0, Rowmax - 2);
 zswitchto(buff);
 bmrktopnt(Bbuff, &tmark);
 btostart(Bbuff);
 if (comchar) {
  while (bcsearch(Bbuff, comchar) && !bisend(Bbuff)) {
   if (bmove(Bbuff, -2) == 0) {
   } else if (((*__ctype_b_loc ())[(int) (((*Bbuff->curcptr)))] & (unsigned short) _ISspace))
    bmove1(Bbuff);
   else {
    bmove(Bbuff, 2);
    continue;
   }
   bmrktopnt(Bbuff, &start);
   bcsearch(Bbuff, '\n');
   bmove(Bbuff, -1);
   newcomment(&start);
  }
 } else {
  while (bcsearch(Bbuff, '/') && !bisend(Bbuff)) {
   if ((*Bbuff->curcptr) == '*') {
    bmove(Bbuff, -1);
    bmrktopnt(Bbuff, &start);
    if (bm_search(Bbuff, "*/", 0))
     newcomment(&start);
   } else if ((*Bbuff->curcptr) == '/') {
    bmove(Bbuff, -1);
    bmrktopnt(Bbuff, &start);
    toendline(Bbuff);
    newcomment(&start);
   }
  }
 }
 bpnttomrk(Bbuff, &tmark);
 Comstate = 1;
}

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

variable_types:
comchar
unsigned char


cprntchar

decompiled_code:
__int64 __fastcall cprntchar(unsigned __int8 a1)
{
_QWORD *v1; // rax
__int64 v3; // rdi
__int64 v4; // rcx
__int64 v5; // rdi
__int64 v7; // r12
_QWORD *v8; // rbp
__int64 v9; // rdi

v1 = (_QWORD *)start;
if ( !Comstate )
{
v7 = Curbuff;
scanbuffer(Curbuff);
v8 = (_QWORD *)Whead;
if ( Whead )
{
do
{
v9 = v8[1];
if ( v9 != Curbuff )
scanbuffer(v9);
v8 = (_QWORD *)*v8;
}
while ( v8 );
}
zswitchto(v7);
if ( !Curbuff )
{
start = 0LL;
goto LABEL_8;
}
v1 = *(_QWORD **)(Curbuff + 56LL);
start = (__int64)v1;
}
if ( v1 )
{
v3 = Bbuff;
while ( !(unsigned int)bisbeforemrk(v3, *v1) )
{
if ( (unsigned int)bisbeforemrk(Bbuff, *(_QWORD *)(start + 8))
|| (v3 = Bbuff, bisatmrk(Bbuff, *(_QWORD *)(start + 8))) )
{
v5 = 31LL;
goto LABEL_9;
}
v1 = *(_QWORD **)(v4 + 16);
start = (__int64)v1;
if ( !v1 )
break;
}
}
LABEL_8:
v5 = 0LL;
LABEL_9:
tstyle(v5);
return tprntchar(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 a1)
{
_QWORD *v1; // rax
__int64 v3; // rdi
__int64 v4; // rcx
__int64 v5; // rdi
__int64 v7; // r12
_QWORD *v8; // rbp
__int64 v9; // rdi

v1 = (_QWORD *)start;
if ( !Comstate )
{
v7 = Curbuff;
func11(Curbuff);
v8 = (_QWORD *)Whead;
if ( Whead )
{
do
{
v9 = v8[1];
if ( v9 != Curbuff )
func11(v9);
v8 = (_QWORD *)*v8;
}
while ( v8 );
}
zswitchto(v7);
if ( !Curbuff )
{
start = 0LL;
goto LABEL_8;
}
v1 = *(_QWORD **)(Curbuff + 56LL);
start = (__int64)v1;
}
if ( v1 )
{
v3 = Bbuff;
while ( !(unsigned int)bisbeforemrk(v3, *v1) )
{
if ( (unsigned int)bisbeforemrk(Bbuff, *(_QWORD *)(start + 8))
|| (v3 = Bbuff, func2(Bbuff, *(_QWORD *)(start + 8))) )
{
v5 = 31LL;
goto LABEL_9;
}
v1 = *(_QWORD **)(v4 + 16);
start = (__int64)v1;
if ( !v1 )
break;
}
}
LABEL_8:
v5 = 0LL;
LABEL_9:
tstyle(v5);
return tprntchar(a1);
}

original_code:
void cprntchar(unsigned char ch)
{
 int style = 0;
 if (!Comstate) {
  struct wdo *wdo;
  struct zbuff *was = Curbuff;
  scanbuffer(Curbuff);
  for (wdo = Whead; wdo; wdo = wdo->next)
   if (wdo->wbuff != Curbuff)
    scanbuffer(wdo->wbuff);
  zswitchto(was);
  start = Curbuff ? Curbuff->chead : ((void *)0);
 }
 for (; start; start = start->next)
  if (bisbeforemrk(Bbuff, start->start))
   break;
  else if (bisbeforemrk(Bbuff, start->end) ||
    bisatmrk(Bbuff, start->end)) {
   style = (30 | 1);
   break;
  }
 tstyle(style);
 tprntchar(ch);
}

variable_types:
ch
unsigned char

variable_types: style int

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


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 *


boffset

original_code:
void boffset(struct buff *buff, unsigned long offset)
{
 struct page *tpage;
 for (tpage = buff->firstp; tpage->nextp; tpage = tpage->nextp) {
  if (tpage->plen >= offset)
   break;
  offset -= tpage->plen;
 }
 makecur(buff, tpage, offset);
}

variable_types:
offset
unsigned long

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


bisbeforemrk

original_code:
int bisbeforemrk(struct buff *buff, struct mark *mark)
{
 struct page *tp;
 if (!mark->mpage || mark->mbuff != buff)
  return 0;
 if (mark->mpage == buff->curpage)
  return buff->curchar < mark->moffset;
 if (mark->mpage == buff->curpage->prevp)
  return 0;
 for (tp = buff->curpage->nextp;
   tp && tp != mark->mpage;
   tp = tp->nextp)
  ;
 return tp != ((void *)0);
}

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:
mark
struct mark *


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

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

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


makeoffset

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


bmrktopnt

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

v2 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a2 = a1;
*(_QWORD *)(a2 + 8) = v2;
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;
}


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


btostart

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


original_code:
static void fill_matrix1(char *p1)
{
 _Bool eol;
 int row = 0, col = 0;
 btostart(Bbuff);
 for (row = 0; row < (Rowmax - 2); ++row) {
  for (eol = 0, col = 0; col < (Colmax - 1); ++col, ++p1)
   if (eol || bisend(Bbuff) || (*Bbuff->curcptr) == ('\n')) {
    binsert(Bbuff, ' ');
    eol = 1;
   } else {
    if (((*__ctype_b_loc ())[(int) (((*Bbuff->curcptr)))] & (unsigned short int) _ISspace))
     (*Bbuff->curcptr) = ' ';
    else {
     *p1 += 100;
     (*Bbuff->curcptr) = '*';
    }
    bmove1(Bbuff);
   }
  if (!bisend(Bbuff) && (*Bbuff->curcptr) == ('\n'))
   bmove1(Bbuff);
  else
   binsert(Bbuff, ('\n'));
 }
}

canonical_original_code:
static void fill_matrix1(char *p1)
{
 _Bool eol;
 int row = 0; int col = 0;
 btostart(Bbuff);
 for (row = 0; row < (Rowmax - 2); ++row) {
  for (eol = 0, col = 0; col < (Colmax - 1); ++col, ++p1)
   if (eol || bisend(Bbuff) || (*Bbuff->curcptr) == ('\n')) {
    binsert(Bbuff, ' ');
    eol = 1;
   } else {
    if (((*__ctype_b_loc ())[(int) (((*Bbuff->curcptr)))] & (unsigned short) _ISspace))
     (*Bbuff->curcptr) = ' ';
    else {
     *p1 += 100;
     (*Bbuff->curcptr) = '*';
    }
    bmove1(Bbuff);
   }
  if (!bisend(Bbuff) && (*Bbuff->curcptr) == ('\n'))
   bmove1(Bbuff);
  else
   binsert(Bbuff, ('\n'));
 }
}

variable_types: row int

variable_types: col int


generation

decompiled_code:
void __fastcall generation(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // rbp
_BYTE *v3; // rbx
size_t v4; // r12
char *v5; // rax
char *v6; // rdx
char *v7; // rsi
_BYTE *v8; // rax
__int64 v9; // rcx
_BYTE *v10; // r12
unsigned int v11; // er13
char v12; // al
__int64 v13; // rcx
size_t v14; // rcx
size_t v15; // rcx

v2 = a1;
v3 = a2;
v4 = (Colmax - 1) * (Rowmax - 2);
v5 = (char *)memset(a2, 0, v4);
if ( a1 >= &a1[v4] )
{
btostart(Bbuff);
}
else
{
v6 = a1;
v7 = &v5[-v4 + 1];
v8 = v3;
do
{
if ( *v6 > 100 )
{
*v8 += 100;
switch ( *v6 )
{
case 'e':
++v8[-Colmax];
++v8[1 - Colmax];
v15 = 2 - Colmax;
goto LABEL_28;
case 'f':
++v8[v4 - Colmax];
++v8[v4 + 1 - Colmax];
v15 = v4 + 2 - Colmax;
LABEL_28:
++v8[v15];
++v8[1];
++v8[Colmax];
goto LABEL_7;
case 'g':
++v8[-Colmax];
++v8[1 - Colmax];
++v8[2 - Colmax];
++v8[1];
++v8[Colmax - v4];
goto LABEL_20;
case 'h':
++v8[(__int64)Colmax - 1 - Colmax];
++v8[1 - Colmax];
v14 = 2 - Colmax;
goto LABEL_23;
case 'i':
++v8[-Colmax];
++v8[1 - Colmax];
++v8[2 - Colmax - (__int64)Colmax + 1];
goto LABEL_6;
case 'j':
++v8[v4 - 1 + Colmax - Colmax];
++v8[v4 + 1 - Colmax];
v14 = v4 + 2 - Colmax;
LABEL_23:
++v8[v14];
++v8[1];
++v8[Colmax];
++v8[Colmax - 1];
++v8[Colmax - 3 + (__int64)Colmax];
++v8[Colmax - 2];
break;
case 'k':
++v8[v4 - Colmax];
++v8[v4 + 1 - Colmax];
v9 = v4 + 2 - Colmax - (__int64)Colmax + 1;
++v8[v9];
LABEL_6:
++v8[2LL - Colmax];
++v8[1];
LABEL_7:
++v8[Colmax - 1];
++v8[Colmax - 2];
++*(v8 - 1);
break;
case 'l':
v13 = -Colmax + (__int64)Colmax - 1;
++v8[v13];
++v8[1 - Colmax];
++v8[2 - Colmax];
++v8[1];
++v8[Colmax - v4];
++v8[Colmax - 1LL - v4];
++v8[Colmax - 2 + (__int64)Colmax - 1 - v4];
++v8[Colmax - 2];
break;
case 'm':
++v8[-Colmax];
++v8[1 - Colmax];
++v8[2 - Colmax - (__int64)Colmax + 1];
++v8[2LL - Colmax];
++*v7;
LABEL_20:
++v8[Colmax - 1LL - v4];
++v8[Colmax - 2 - v4];
++*(v8 - 1);
break;
default:
break;
}
}
++v6;
++v8;
++v7;
}
while ( &a1[v4] != v6 );
v10 = &v3[v4];
v11 = 0;
btostart(Bbuff);
do
{
while ( 1 )
{
v12 = *v3;
if ( *v3 == 3 )
{
*v2 += 100;
**(_BYTE **)(Bbuff + 24LL) = 42;
invalidate_scrnmarks(v11, v11 + 1);
}
else if ( (unsigned __int8)(v12 - 102) > 1u && v12 > 99 )
{
*v2 -= 100;
**(_BYTE **)(Bbuff + 24LL) = 32;
invalidate_scrnmarks(v11, v11 + 1);
}
bmove1(Bbuff);
if ( **(_BYTE **)(Bbuff + 24LL) == 10 )
break;
++v3;
++v2;
if ( v3 == v10 )
return;
}
++v3;
++v11;
++v2;
bmove1(Bbuff);
}
while ( v3 != v10 );
}
}

variable_types:
end
char *

variable_types: msize int


bmrktopnt

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

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

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


decompiled_code:
__int64 get_tagfile()
{
__int64 v0; // rsi
char *v1; // rax
__int64 v2; // rax
__int64 result; // rax

if ( Argp )
{
Arg = 0;
result = getfname("Tagfile: ", &Tagfile);
}
else if ( access(&Tagfile, 0)
&& ((v0 = *(_QWORD *)(Curbuff + 24LL)) == 0
|| (strlcpy(&Tagfile, v0, 251LL), (v1 = strrchr(&Tagfile, 47)) == 0LL)
|| (strcpy(v1 + 1, "TAGS"), access(&Tagfile, 0)))
&& (v2 = zgetcwd(&Tagfile, 255LL), strconcat(&Tagfile, 255LL, v2, "TAGS", 0LL), access(&Tagfile, 0)) )
{
Tagfile = 0;
result = getfname("Tagfile: ", &Tagfile);
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rsi
char *v1; // rax
__int64 v2; // rax
__int64 result; // rax

if ( Argp )
{
Arg = 0;
result = getfname("Tagfile: ", &Tagfile);
}
else if ( access(&Tagfile, 0)
&& ((v0 = *(_QWORD *)(Curbuff + 24LL)) == 0
|| (strlcpy(&Tagfile, v0, 251LL), (v1 = strrchr(&Tagfile, 47)) == 0LL)
|| (strcpy(v1 + 1, "TAGS"), access(&Tagfile, 0)))
&& (v2 = zgetcwd(&Tagfile, 255LL), strconcat(&Tagfile, 255LL, v2, "TAGS", 0LL), access(&Tagfile, 0)) )
{
Tagfile = 0;
result = getfname("Tagfile: ", &Tagfile);
}
else
{
result = 0LL;
}
return result;
}

original_code:
static int get_tagfile(void)
{
 if (Argp) {
  Arg = 0;
  return getfname("Tagfile: ", Tagfile);
 }
 if (access(Tagfile, 0) == 0)
  return 0;
 if (Curbuff->fname) {
  char *p;
  strlcpy(Tagfile, Curbuff->fname, sizeof(Tagfile) - 4);
  p = strrchr(Tagfile, '/');
  if (p) {
   ++p;
   strcpy(p, "TAGS");
   if (access(Tagfile, 0) == 0)
    return 0;
  }
 }
 strconcat(Tagfile, sizeof(Tagfile), zgetcwd(Tagfile, sizeof(Tagfile)),
    "TAGS", ((void *)0));
 if (access(Tagfile, 0) == 0)
  return 0;
 *Tagfile = '\0';
 return getfname("Tagfile: ", Tagfile);
}

canonical_original_code:
static int get_tagfile()
{
 if (Argp) {
  Arg = 0;
  return getfname("Tagfile: ", Tagfile);
 }
 if (access(Tagfile, 0) == 0)
  return 0;
 if (Curbuff->fname) {
  char *p;
  strlcpy(Tagfile, Curbuff->fname, sizeof(Tagfile) - 4);
  p = strrchr(Tagfile, '/');
  if (p) {
   ++p;
   strcpy(p, "TAGS");
   if (access(Tagfile, 0) == 0)
    return 0;
  }
 }
 strconcat(Tagfile, sizeof(Tagfile), zgetcwd(Tagfile, sizeof(Tagfile)),
    "TAGS", ((void *)0));
 if (access(Tagfile, 0) == 0)
  return 0;
 *Tagfile = '\0';
 return getfname("Tagfile: ", Tagfile);
}

variable_types:
p
char *


decompiled_code:
int __fastcall tagfile_modified(__int64 a1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( strcmp(*(const char **)(a1 + 24), &Tagfile)
|| (result = stat(&Tagfile, &v2)) != 0
|| v2.st_mtim.tv_sec > *(_QWORD *)(a1 + 48) )
{
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( strcmp(*(const char **)(a1 + 24), &Tagfile)
|| (result = stat(&Tagfile, &v2)) != 0
|| v2.st_mtim.tv_sec > *(_QWORD *)(a1 + 48) )
{
result = 1;
}
return result;
}

original_code:
static _Bool tagfile_modified(struct zbuff *buff)
{
 struct stat sbuf;
 if (strcmp(buff->fname, Tagfile))
  return 1;
 if (stat(Tagfile, &sbuf) || sbuf.st_mtim.tv_sec > buff->mtime)
  return 1;
 return 0;
}

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

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


decompiled_code:
__int64 read_tagfile()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 result; // rax

if ( (unsigned int)get_tagfile()
|| ((v0 = cfindbuff("*tags*"), (v1 = v0) == 0) || (unsigned __int8)tagfile_modified(v0))
&& ((v1 = cmakebuff("*tags*", &Tagfile)) == 0 || (unsigned int)zreadfile(&Tagfile)) )
{
result = 0LL;
}
else
{
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 result; // rax

if ( (unsigned int)func1()
|| ((v0 = cfindbuff("*tags*"), (v1 = v0) == 0) || (unsigned __int8)func2(v0))
&& ((v1 = cmakebuff("*tags*", &Tagfile)) == 0 || (unsigned int)zreadfile(&Tagfile)) )
{
result = 0LL;
}
else
{
result = v1;
}
return result;
}

original_code:
static struct zbuff *read_tagfile(void)
{
 struct zbuff *buff;
 if (get_tagfile())
  return ((void *)0);
 buff = cfindbuff("*tags*");
 if (buff && tagfile_modified(buff) == 0)
  return buff;
 buff = cmakebuff("*tags*", Tagfile);
 if (!buff)
  return ((void *)0);
 if (zreadfile(Tagfile))
  return ((void *)0);
 return buff;
}

canonical_original_code:
static struct zbuff *read_tagfile()
{
 struct zbuff *buff;
 if (get_tagfile())
  return ((void *)0);
 buff = cfindbuff("*tags*");
 if (buff && tagfile_modified(buff) == 0)
  return buff;
 buff = cmakebuff("*tags*", Tagfile);
 if (!buff)
  return ((void *)0);
 if (zreadfile(Tagfile))
  return ((void *)0);
 return buff;
}

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


btostart

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

canonical_decompiled_code:
void __fastcall func5(__int64 *a1)
{
func4((__int64)a1, *a1);
}


bdeltomrk

decompiled_code:
__int64 __fastcall bdeltomrk(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // r12
int v3; // esi
__int64 v4; // rax
__int64 v5; // rsi

v1 = *a1;
if ( (unsigned int)bisaftermrk(*a1, a1) )
bswappnt(v1, a1);
v2 = 0LL;
while ( (unsigned int)bisbeforemrk(v1, a1) )
{
v4 = *(_QWORD *)(v1 + 16);
if ( v4 == a1[1] )
v3 = *((_DWORD *)a1 + 4);
else
v3 = *(_DWORD *)(v4 + 4096);
v5 = (unsigned int)(v3 - *(_DWORD *)(v1 + 32));
v2 += (unsigned int)v5;
bdelete(v1, v5);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // r12
int v3; // esi
__int64 v4; // rax
__int64 v5; // rsi

v1 = *a1;
if ( (unsigned int)bisaftermrk(*a1, a1) )
bswappnt(v1, a1);
v2 = 0LL;
while ( (unsigned int)bisbeforemrk(v1, a1) )
{
v4 = *(_QWORD *)(v1 + 16);
if ( v4 == a1[1] )
v3 = *((_DWORD *)a1 + 4);
else
v3 = *(_DWORD *)(v4 + 4096);
v5 = (unsigned int)(v3 - *(_DWORD *)(v1 + 32));
v2 += (unsigned int)v5;
bdelete(v1, v5);
}
return v2;
}

original_code:
long bdeltomrk(struct mark *mark)
{
 long amount, deleted = 0;
 struct buff *buff = mark->mbuff;
 if (bisaftermrk(buff, mark))
  bswappnt(buff, mark);
 while (bisbeforemrk(buff, mark)) {
  if (buff->curpage == mark->mpage)
   amount = mark->moffset - buff->curchar;
  else
   amount = ((buff)->curpage->plen) - buff->curchar;
  bdelete(buff, amount);
  deleted += amount;
 }
 return deleted;
}

canonical_original_code:
long bdeltomrk(struct mark *mark)
{
 long amount; long deleted = 0;
 struct buff *buff = mark->mbuff;
 if (bisaftermrk(buff, mark))
  bswappnt(buff, mark);
 while (bisbeforemrk(buff, mark)) {
  if (buff->curpage == mark->mpage)
   amount = mark->moffset - buff->curchar;
  else
   amount = ((buff)->curpage->plen) - buff->curchar;
  bdelete(buff, amount);
  deleted += amount;
 }
 return deleted;
}

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

variable_types: amount long

variable_types: deleted long

return_type: long


bmrktopnt

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

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

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


mrktomrk

canonical_decompiled_code:
__int64 __fastcall func1(__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;
}


bswappnt

decompiled_code:
__int64 __fastcall bswappnt(__int64 a1, _QWORD *a2)
{
_BYTE v3[56]; // [rsp-38h] [rbp-38h] BYREF

if ( *a2 != a1 )
return 0LL;
bmrktopnt(a1, (__int64)v3);
bpnttomrk(a1, a2);
mrktomrk((__int64)a2, (__int64)v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
_BYTE v3[56]; // [rsp-38h] [rbp-38h] BYREF

if ( *a2 != a1 )
return 0LL;
func0(a1, (__int64)v3);
bpnttomrk(a1, a2);
func1((__int64)a2, (__int64)v3);
return 1LL;
}

original_code:
int bswappnt(struct buff *buff, struct mark *mark)
{
 struct mark tmp;
 if (mark->mbuff != buff)
  return 0;
 bmrktopnt(buff, &tmp);
 bpnttomrk(buff, mark);
 mrktomrk(mark, &tmp);
 return 1;
}

variable_types: struct mark { 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 *marks; } *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; }


mrkbeforemrk

original_code:
int mrkbeforemrk(struct mark *mark1, struct mark *mark2)
{
 struct page *tpage;
 if (!mark1->mpage || !mark2->mpage || mark1->mbuff != mark2->mbuff)
  return 0;
 if (mark1->mpage == mark2->mpage)
  return mark1->moffset < mark2->moffset;
 if (mark1->mpage->prevp == mark2->mpage)
  return 0;
 for (tpage = mark1->mpage->nextp;
   tpage && tpage != mark2->mpage;
   tpage = tpage->nextp)
  ;
 return tpage != ((void *)0);
}

variable_types: struct mark { 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 *marks; } *mbuff; struct page *mpage; unsigned int moffset; struct mark *prev; struct mark *next; } *


freepage

decompiled_code:
void __fastcall freepage(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rcx
__int64 v3; // rdx

if ( a2 )
{
v2 = a2[514];
v3 = a2[513];
if ( v2 )
{
*(_QWORD *)(v2 + 4104) = v3;
if ( v3 )
{
LABEL_4:
*(_QWORD *)(v3 + 4112) = v2;
LABEL_5:
free(a2);
return;
}
if ( !a1 )
goto LABEL_5;
}
else
{
a1[1] = v3;
if ( v3 )
goto LABEL_4;
}
*a1 = v2;
goto LABEL_5;
}
}

original_code:
void freepage(struct buff *buff, struct page *page)
{
 if (!page)
  return;
 if (page->nextp)
  page->nextp->prevp = page->prevp;
 else
  buff->lastp = page->prevp;
 if (page->prevp)
  page->prevp->nextp = page->nextp;
 else if (buff)
  buff->firstp = page->nextp;
 free(page);
}

variable_types:
page
struct page *


twrite

decompiled_code:
ssize_t __fastcall twrite(int a1, const void *a2, int a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1, const void *a2, int a3)
{
return write(a1, a2, a3);
}

original_code:
int twrite(const void *buf, int len)
{
again:
 if (tcur + len < 2048) {
  memcpy(tbuffer + tcur, buf, len);
  tcur += len;
  return len;
 }
 tflush();
 if (len >= 2048)
  return write(1, buf, len);
 goto again;
}

canonical_original_code:
int twrite(void *buf, int len)
{
again:
 if (tcur + len < 2048) {
  memcpy(tbuffer + tcur, buf, len);
  tcur += len;
  return len;
 }
 tflush();
 if (len >= 2048)
  return write(1, buf, len);
 goto again;
}

variable_types:
buf
void *

variable_types: len int


terror

decompiled_code:
ssize_t __fastcall terror(const char *a1)
{
int v1; // eax

v1 = strlen(a1);
return twrite(2, a1, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func1(const char *a1)
{
int v1; // eax

v1 = strlen(a1);
return func0(2, a1, v1);
}

original_code:
static inline int terror(const char *str)
{
 return _twrite(2, str, strlen(str));
}

canonical_original_code:
static inline int terror(char *str)
{
 return _twrite(2, str, strlen(str));
}

variable_types:
str
char *


Dbgfname

decompiled_code:
void *__fastcall Dbgfname(void *src)
{
void *v1; // r8
size_t v2; // r12
char *v3; // rax

free(dbgfname);
v1 = 0LL;
dbgfname = 0LL;
if ( src )
{
v2 = strlen((const char *)src) + 1;
v3 = (char *)malloc(v2);
dbgfname = v3;
v1 = v3;
if ( v3 )
v1 = memcpy(v3, src, v2);
}
return v1;
}

canonical_decompiled_code:
void *__fastcall func2(void *src)
{
void *v1; // r8
size_t v2; // r12
char *v3; // rax

free(dbgfname);
v1 = 0LL;
dbgfname = 0LL;
if ( src )
{
v2 = strlen((const char *)src) + 1;
v3 = (char *)malloc(v2);
dbgfname = v3;
v1 = v3;
if ( v3 )
v1 = memcpy(v3, src, v2);
}
return v1;
}

original_code:
const char *Dbgfname(const char *fname)
{
 free(dbgfname);
 dbgfname = ((void *)0);
 if (fname) {
  dbgfname = malloc(strlen(fname) + 1);
  if (dbgfname)
   strcpy(dbgfname, fname);
 }
 return dbgfname;
}

canonical_original_code:
char *Dbgfname(char *fname)
{
 free(dbgfname);
 dbgfname = ((void *)0);
 if (fname) {
  dbgfname = malloc(strlen(fname) + 1);
  if (dbgfname)
   strcpy(dbgfname, fname);
 }
 return dbgfname;
}

variable_types:
fname
char *


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


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


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


bmoveto

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

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
{
while ( 1 )
{
bmove(a1, 0xFFFFFFFFLL);
if ( func0(a1) )
break;
if ( a2(**(unsigned __int8 **)(a1 + 24)) )
{
if ( !func0(a1) )
func4(a1);
return;
}
}
}
}

original_code:
void bmoveto(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 (!bisstart(buff))
   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


bmrktopnt

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


mrkfini

decompiled_code:
void mrkfini()
{
free(freemark);
freemark = 0LL;
}

canonical_decompiled_code:
void func3()
{
free(freemark);
freemark = 0LL;
}

original_code:
void mrkfini(void)
{
 free(freemark);
 freemark = ((void *)0);
}

canonical_original_code:
void mrkfini()
{
 free(freemark);
 freemark = ((void *)0);
}