swapmark

decompiled_code:
__int64 __fastcall swapmark(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rdi
int v7; // esi
int v8; // ecx
__int64 result; // rax

v4 = curwp;
v5 = *(_QWORD *)(curwp + 40LL);
if ( v5 )
{
v6 = *(_QWORD *)(curwp + 32LL);
v7 = *(_DWORD *)(curwp + 48LL);
v8 = *(_DWORD *)(curwp + 80LL);
*(_QWORD *)(curwp + 32LL) = v5;
*(_DWORD *)(v4 + 48) = *(_DWORD *)(v4 + 52);
*(_DWORD *)(v4 + 80) = *(_DWORD *)(v4 + 84);
*(_QWORD *)(v4 + 40) = v6;
*(_DWORD *)(v4 + 52) = v7;
*(_DWORD *)(v4 + 84) = v8;
*(_BYTE *)(v4 + 68) |= 2u;
result = 1LL;
}
else
{
dobeep(a1, a2, 0LL, a4);
ewprintf("No mark in this window");
result = 0LL;
}
return result;
}

original_code:
int
swapmark(int f, int n)
{
 struct line *odotp;
 int odoto, odotline;
 if (curwp->w_markp == ((void *)0)) {
  dobeep();
  ewprintf("No mark in this window");
  return (0);
 }
 odotp = curwp->w_dotp;
 odoto = curwp->w_doto;
 odotline = curwp->w_dotline;
 curwp->w_dotp = curwp->w_markp;
 curwp->w_doto = curwp->w_marko;
 curwp->w_dotline = curwp->w_markline;
 curwp->w_markp = odotp;
 curwp->w_marko = odoto;
 curwp->w_markline = odotline;
 curwp->w_rflag |= 0x02;
 return (1);
}

canonical_original_code:
int swapmark(int f, int n)
{
 struct line *odotp;
 int odoto; int odotline;
 if (curwp->w_markp == ((void *)0)) {
  dobeep();
  ewprintf("No mark in this window");
  return (0);
 }
 odotp = curwp->w_dotp;
 odoto = curwp->w_doto;
 odotline = curwp->w_dotline;
 curwp->w_dotp = curwp->w_markp;
 curwp->w_doto = curwp->w_marko;
 curwp->w_dotline = curwp->w_markline;
 curwp->w_markp = odotp;
 curwp->w_marko = odoto;
 curwp->w_markline = odotline;
 curwp->w_rflag |= 0x02;
 return (1);
}

variable_types: odoto int

variable_types: odotline int


setlineno

repo: scott-parker/mg-openbsd

original_code:
int
setlineno(int n)
{
 struct line *clp;
 if (n >= 0) {
  if (n == 0)
   n++;
  curwp->w_dotline = n;
  clp = ((curbp->b_headp)->l_fp);
  while (--n > 0) {
   if (((clp)->l_fp) == curbp->b_headp) {
    curwp->w_dotline = curwp->w_bufp->b_lines;
    break;
   }
   clp = ((clp)->l_fp);
  }
 } else {
  curwp->w_dotline = curwp->w_bufp->b_lines + n;
  clp = ((curbp->b_headp)->l_bp);
  while (n < 0) {
   if (((clp)->l_bp) == curbp->b_headp) {
    curwp->w_dotline = 1;
    break;
   }
   clp = ((clp)->l_bp);
   n++;
  }
 }
 curwp->w_dotp = clp;
 curwp->w_doto = 0;
 curwp->w_rflag |= 0x02;
 return (1);
}

variable_types: n int

variable_types: struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *

return_type: int


gotoline

decompiled_code:
__int64 __fastcall gotoline(char a1, __int64 a2)
{
unsigned int v2; // ebx
_BYTE *v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
const char *v7; // [rsp+8h] [rbp-30h] BYREF
char v8[40]; // [rsp+10h] [rbp-28h] BYREF

v2 = a1 & 7;
if ( (a1 & 7) != 0 )
return (unsigned int)setlineno(a2);
v3 = (_BYTE *)eread("Goto line: ", v8, 32LL, 88LL);
if ( !v3 )
return 2;
if ( !*v3 )
return 2;
a2 = strtonum(v8, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, &v7);
if ( !v7 )
return (unsigned int)setlineno(a2);
dobeep(v8, a2, v4, v5);
ewprintf("Line number %s", v7);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func20(char a1, __int64 a2)
{
unsigned int v2; // ebx
_BYTE *v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
const char *v7; // [rsp+8h] [rbp-30h] BYREF
char v8[40]; // [rsp+10h] [rbp-28h] BYREF

v2 = a1 & 7;
if ( (a1 & 7) != 0 )
return (unsigned int)func19(a2);
v3 = (_BYTE *)eread("Goto line: ", v8, 32LL, 88LL);
if ( !v3 )
return 2;
if ( !*v3 )
return 2;
a2 = strtonum(v8, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, &v7);
if ( !v7 )
return (unsigned int)func19(a2);
dobeep(v8, a2, v4, v5);
ewprintf("Line number %s", v7);
return v2;
}

original_code:
int
gotoline(int f, int n)
{
 char buf[32], *bufp;
 const char *err;
 if (!(f & 7)) {
  if ((bufp = eread("Goto line: ", buf, sizeof(buf),
      0x0040 | 0x0008 | 0x0010)) == ((void *)0))
   return (2);
  if (bufp[0] == '\0')
   return (2);
  n = (int)strtonum(buf, (-0x7fffffff - 1), 0x7fffffff, &err);
  if (err) {
   dobeep();
   ewprintf("Line number %s", err);
   return (0);
  }
 }
 return(setlineno(n));
}

canonical_original_code:
int gotoline(int f, int n)
{
 char buf[32]; char *bufp;
 char *err;
 if (!(f & 7)) {
  if ((bufp = eread("Goto line: ", buf, sizeof(buf),
      0x0040 | 0x0008 | 0x0010)) == ((void *)0))
   return (2);
  if (bufp[0] == '\0')
   return (2);
  n = (int)strtonum(buf, (-0x7fffffff - 1), 0x7fffffff, &err);
  if (err) {
   dobeep();
   ewprintf("Line number %s", err);
   return (0);
  }
 }
 return(setlineno(n));
}

variable_types: f int

variable_types:
buf
char [32]

variable_types:
bufp
char *

variable_types:
err
char *


getattr

decompiled_code:
__int64 __fastcall getattr(const char *a1, const char **a2)
{
char *v2; // rax
char *v3; // r12
char *v4; // rax
char *v5; // rbp
char *v6; // rax
unsigned int v7; // edx

v2 = strchr(a1, 32);
if ( !v2 )
return 0;
v3 = v2 + 1;
*v2 = 0;
*a2 = a1;
v4 = strchr(v2 + 1, 32);
if ( !v4 )
return 0;
v5 = v4 + 1;
*v4 = 0;
a2[1] = v3;
v6 = strchr(v4 + 1, 32);
if ( !v6 )
return 0;
*v6 = 0;
a2[2] = v5;
v7 = 0;
if ( v6[1] )
{
a2[3] = v6 + 1;
v7 = 1;
}
return v7;
}

original_code:
int
getattr(char *line, struct cstokens *t)
{
 char *p;
 if ((p = strchr(line, ' ')) == ((void *)0))
  return (0);
 *p++ = '\0';
 t->fname = line;
 line = p;
 if ((p = strchr(line, ' ')) == ((void *)0))
  return (0);
 *p++ = '\0';
 t->function = line;
 line = p;
 if ((p = strchr(line, ' ')) == ((void *)0))
  return (0);
 *p++ = '\0';
 t->lineno = line;
 if (*p == '\0')
  return (0);
 t->pattern = p;
 return (1);
}

variable_types:
line
char *

variable_types: struct cstokens { char *fname; char *function; char *lineno; char *pattern; } *

variable_types:
p
char *


csflush

decompiled_code:
void csflush()
{
void **i; // rbx
_QWORD *j; // rdi

for ( i = (void **)csrecords; csrecords; i = (void **)csrecords )
{
free(i[2]);
for ( j = i[3]; j; j = i[3] )
{
if ( *j )
*(_QWORD *)(*j + 8LL) = j[1];
else
i[4] = (void *)j[1];
*(_QWORD *)j[1] = *j;
free(j);
}
if ( *i )
*((_QWORD *)*i + 1) = i[1];
else
off_D78 = (__int64 *)i[1];
*(_QWORD *)i[1] = *i;
free(i);
}
addentryr = 0LL;
addentryfn = 0LL;
currecord = 0LL;
curmatch = 0LL;
}

canonical_decompiled_code:
void func1()
{
void **i; // rbx
_QWORD *j; // rdi

for ( i = (void **)csrecords; csrecords; i = (void **)csrecords )
{
free(i[2]);
for ( j = i[3]; j; j = i[3] )
{
if ( *j )
*(_QWORD *)(*j + 8LL) = j[1];
else
i[4] = (void *)j[1];
*(_QWORD *)j[1] = *j;
free(j);
}
if ( *i )
*((_QWORD *)*i + 1) = i[1];
else
off_D78 = (__int64 *)i[1];
*(_QWORD *)i[1] = *i;
free(i);
}
addentryr = 0LL;
addentryfn = 0LL;
currecord = 0LL;
curmatch = 0LL;
}

original_code:
void
csflush(void)
{
 struct csrecord *r;
 struct csmatch *m;
 while ((r = ((&csrecords)->tqh_first)) != ((void *)0)) {
  free(r->filename);
  while ((m = ((&r->matches)->tqh_first)) != ((void *)0)) {
   do { if (((m)->entry.tqe_next) != ((void *)0)) (m)->entry.tqe_next->entry.tqe_prev = (m)->entry.tqe_prev; else (&r->matches)->tqh_last = (m)->entry.tqe_prev; *(m)->entry.tqe_prev = (m)->entry.tqe_next; ; ; } while (0);
   free(m);
  }
  do { if (((r)->entry.tqe_next) != ((void *)0)) (r)->entry.tqe_next->entry.tqe_prev = (r)->entry.tqe_prev; else (&csrecords)->tqh_last = (r)->entry.tqe_prev; *(r)->entry.tqe_prev = (r)->entry.tqe_next; ; ; } while (0);
  free(r);
 }
 addentryr = ((void *)0);
 addentryfn = ((void *)0);
 currecord = ((void *)0);
 curmatch = ((void *)0);
}

canonical_original_code:
void csflush()
{
 struct csrecord *r;
 struct csmatch *m;
 while ((r = ((&csrecords)->tqh_first)) != ((void *)0)) {
  free(r->filename);
  while ((m = ((&r->matches)->tqh_first)) != ((void *)0)) {
   do { if (((m)->entry.tqe_next) != ((void *)0)) (m)->entry.tqe_next->entry.tqe_prev = (m)->entry.tqe_prev; else (&r->matches)->tqh_last = (m)->entry.tqe_prev; *(m)->entry.tqe_prev = (m)->entry.tqe_next; ; ; } while (0);
   free(m);
  }
  do { if (((r)->entry.tqe_next) != ((void *)0)) (r)->entry.tqe_next->entry.tqe_prev = (r)->entry.tqe_prev; else (&csrecords)->tqh_last = (r)->entry.tqe_prev; *(r)->entry.tqe_prev = (r)->entry.tqe_next; ; ; } while (0);
  free(r);
 }
 addentryr = ((void *)0);
 addentryfn = ((void *)0);
 currecord = ((void *)0);
 curmatch = ((void *)0);
}

variable_types: struct csrecord { struct { struct csrecord *tqe_next; struct csrecord **tqe_prev; } entry; char *filename; struct matches { struct csmatch { struct { struct csmatch *tqe_next; struct csmatch **tqe_prev; } entry; int lineno; } *tqh_first; struct csmatch **tqh_last; } matches; } *

return_type: void

user_defined_types: struct csrecord { struct { struct csrecord *tqe_next; struct csrecord **tqe_prev; } entry; char *filename; struct matches matches; }

user_defined_types: struct matches { struct csmatch *tqh_first; struct csmatch **tqh_last; }


csexists

decompiled_code:
_BOOL8 __fastcall csexists(char *s)
{
_BOOL8 result; // rax
char *v3; // rdi
char *v4; // r13
int v5; // er12
int v6; // eax
int v7; // edx
__int64 v8; // rax
char *v9; // rax
const char *v10; // rbx
char *stringp; // [rsp+8h] [rbp-430h] BYREF
char sa[1064]; // [rsp+10h] [rbp-428h] BYREF

if ( strchr(s, 47) )
return access(s, 0) != -1;
v3 = getenv("PATH");
result = 0LL;
if ( v3 )
{
v4 = strndup(v3, 0x400uLL);
stringp = v4;
if ( v4 )
{
v5 = strlen(s);
do
{
v9 = strsep(&stringp, ":");
v10 = v9;
if ( !v9 )
goto LABEL_17;
if ( !*v9 )
*v9 = 46;
v6 = strlen(v9);
v7 = v6;
if ( v10[v6 - 1] == 47 )
{
v8 = v6 - 1;
do
{
v7 = v8;
v10[v8--] = 0;
}
while ( v10[v8] == 47 );
}
if ( (unsigned int)(v5 + v7 + 1) > 0x3FF )
{
dobeep();
ewprintf("path too long");
LABEL_17:
free(v4);
return 0LL;
}
snprintf(sa, 0x400uLL, "%s/%s", v10, s);
}
while ( access(sa, 0) );
free(v4);
result = 1LL;
}
else
{
dobeep();
ewprintf("out of memory");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *s)
{
_BOOL8 result; // rax
char *v3; // rdi
char *v4; // r13
int v5; // er12
int v6; // eax
int v7; // edx
__int64 v8; // rax
char *v9; // rax
const char *v10; // rbx
char *stringp; // [rsp+8h] [rbp-430h] BYREF
char sa[1064]; // [rsp+10h] [rbp-428h] BYREF

if ( strchr(s, 47) )
return access(s, 0) != -1;
v3 = getenv("PATH");
result = 0LL;
if ( v3 )
{
v4 = strndup(v3, 0x400uLL);
stringp = v4;
if ( v4 )
{
v5 = strlen(s);
do
{
v9 = strsep(&stringp, ":");
v10 = v9;
if ( !v9 )
goto LABEL_17;
if ( !*v9 )
*v9 = 46;
v6 = strlen(v9);
v7 = v6;
if ( v10[v6 - 1] == 47 )
{
v8 = v6 - 1;
do
{
v7 = v8;
v10[v8--] = 0;
}
while ( v10[v8] == 47 );
}
if ( (unsigned int)(v5 + v7 + 1) > 0x3FF )
{
dobeep();
ewprintf("path too long");
LABEL_17:
free(v4);
return 0LL;
}
snprintf(sa, 0x400uLL, "%s/%s", v10, s);
}
while ( access(sa, 0) );
free(v4);
result = 1LL;
}
else
{
dobeep();
ewprintf("out of memory");
result = 0LL;
}
}
return result;
}

original_code:
int
csexists(const char *cmd)
{
       char fname[1024], *dir, *path, *pathc, *tmp;
       int cmdlen, dlen;
       if (strchr(cmd, '/')) {
               if (access(cmd, 0) == -1)
                       return (0);
               else
                       return (1);
       }
       if ((tmp = getenv("PATH")) == ((void *)0))
               return (0);
       if ((pathc = path = strndup(tmp, 1024)) == ((void *)0)) {
               dobeep();
               ewprintf("out of memory");
               return (0);
       }
       cmdlen = strlen(cmd);
       while ((dir = strsep(&path, ":")) != ((void *)0)) {
               if (*dir == '\0')
                       *dir = '.';
               dlen = strlen(dir);
               while (dir[dlen-1] == '/')
                       dir[--dlen] = '\0';
               if (dlen + 1 + cmdlen >= sizeof(fname)) {
                       dobeep();
                       ewprintf("path too long");
                       goto cleanup;
               }
               snprintf(fname, sizeof(fname), "%s/%s", dir, cmd);
               if(access(fname, 0) == 0) {
         free(pathc);
         return (1);
        }
       }
cleanup:
 free(pathc);
 return (0);
}

canonical_original_code:
int csexists(char *cmd)
{
       char fname[1024]; char *dir; char *path; char *pathc; char *tmp;
       int cmdlen; int dlen;
       if (strchr(cmd, '/')) {
               if (access(cmd, 0) == -1)
                       return (0);
               else
                       return (1);
       }
       if ((tmp = getenv("PATH")) == ((void *)0))
               return (0);
       if ((pathc = path = strndup(tmp, 1024)) == ((void *)0)) {
               dobeep();
               ewprintf("out of memory");
               return (0);
       }
       cmdlen = strlen(cmd);
       while ((dir = strsep(&path, ":")) != ((void *)0)) {
               if (*dir == '\0')
                       *dir = '.';
               dlen = strlen(dir);
               while (dir[dlen-1] == '/')
                       dir[--dlen] = '\0';
               if (dlen + 1 + cmdlen >= sizeof(fname)) {
                       dobeep();
                       ewprintf("path too long");
                       goto cleanup;
               }
               snprintf(fname, sizeof(fname), "%s/%s", dir, cmd);
               if(access(fname, 0) == 0) {
         free(pathc);
         return (1);
        }
       }
cleanup:
 free(pathc);
 return (0);
}

variable_types:
cmd
char *

variable_types:
fname
char [1024]

variable_types:
dir
char *

variable_types:
path
char *

variable_types:
pathc
char *

variable_types:
tmp
char *

variable_types: cmdlen int

variable_types: dlen int


ltrim

decompiled_code:
unsigned __int8 *__fastcall ltrim(unsigned __int8 *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 1) != 0 )
++a1;
return a1;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func3(unsigned __int8 *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 1) != 0 )
++a1;
return a1;
}

original_code:
const char *
ltrim(const char *s)
{
 while (((*__ctype_b_loc ())[(int) (((unsigned char)*s))] & (unsigned short int) _ISblank))
  s++;
 return s;
}

canonical_original_code:
char *ltrim(char *s)
{
 while (((*__ctype_b_loc ())[(int) (((unsigned char)*s))] & (unsigned short) _ISblank))
  s++;
 return s;
}

variable_types:
s
char *

return_type: char *


cssymbol

decompiled_code:
__int64 cssymbol()
{
return do_cscope(0);
}

canonical_decompiled_code:
__int64 func8()
{
return func6(0);
}

original_code:
int
cssymbol(int f, int n)
{
 return (do_cscope(0));
}

variable_types: f int

variable_types: n int


csdefinition

decompiled_code:
__int64 csdefinition()
{
return do_cscope(1u);
}

canonical_decompiled_code:
__int64 func9()
{
return func6(1u);
}

original_code:
int
csdefinition(int f, int n)
{
 return (do_cscope(1));
}


csfuncalled

decompiled_code:
__int64 csfuncalled()
{
return do_cscope(2u);
}

canonical_decompiled_code:
__int64 func10()
{
return func6(2u);
}

original_code:
int
csfuncalled(int f, int n)
{
 return (do_cscope(2));
}


cscallerfuncs

decompiled_code:
__int64 cscallerfuncs()
{
return do_cscope(3u);
}

canonical_decompiled_code:
__int64 func11()
{
return func6(3u);
}

original_code:
int
cscallerfuncs(int f, int n)
{
 return (do_cscope(3));
}


csfindtext

decompiled_code:
__int64 csfindtext()
{
return do_cscope(4u);
}

canonical_decompiled_code:
__int64 func12()
{
return func6(4u);
}

original_code:
int
csfindtext(int f, int n)
{
 return (do_cscope(4));
}


csegrep

decompiled_code:
__int64 csegrep()
{
return do_cscope(6u);
}

canonical_decompiled_code:
__int64 func13()
{
return func6(6u);
}

original_code:
int
csegrep(int f, int n)
{
 return (do_cscope(6));
}


csfindfile

decompiled_code:
__int64 csfindfile()
{
return do_cscope(7u);
}

canonical_decompiled_code:
__int64 func14()
{
return func6(7u);
}

original_code:
int
csfindfile(int f, int n)
{
 return (do_cscope(7));
}


csfindinc

decompiled_code:
__int64 csfindinc()
{
return do_cscope(8u);
}

canonical_decompiled_code:
__int64 func15()
{
return func6(8u);
}

original_code:
int
csfindinc(int f, int n)
{
 return (do_cscope(8));
}


csnextmatch

decompiled_code:
__int64 csnextmatch()
{
__int64 result; // rax
__int64 v1; // rax

if ( curmatch )
{
if ( *(_QWORD *)curmatch )
{
curmatch = *(_QWORD *)curmatch;
return jumptomatch();
}
v1 = *(_QWORD *)currecord;
if ( *(_QWORD *)currecord )
{
currecord = *(_QWORD *)currecord;
curmatch = *(_QWORD *)(v1 + 24);
return jumptomatch();
}
dobeep();
ewprintf("The end of *cscope* buffer has been reached");
result = 0LL;
}
else
{
if ( csrecords )
{
currecord = csrecords;
curmatch = *(_QWORD *)(csrecords + 24);
return jumptomatch();
}
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 result; // rax
__int64 v1; // rax

if ( curmatch )
{
if ( *(_QWORD *)curmatch )
{
curmatch = *(_QWORD *)curmatch;
return func7();
}
v1 = *(_QWORD *)currecord;
if ( *(_QWORD *)currecord )
{
currecord = *(_QWORD *)currecord;
curmatch = *(_QWORD *)(v1 + 24);
return func7();
}
dobeep();
ewprintf("The end of *cscope* buffer has been reached");
result = 0LL;
}
else
{
if ( csrecords )
{
currecord = csrecords;
curmatch = *(_QWORD *)(csrecords + 24);
return func7();
}
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
result = 0LL;
}
return result;
}

original_code:
int
csnextmatch(int f, int n)
{
 struct csrecord *r;
 struct csmatch *m;
 if (curmatch == ((void *)0)) {
  if ((r = ((&csrecords)->tqh_first)) == ((void *)0)) {
   dobeep();
   ewprintf("The *cscope* buffer does not exist yet");
   return (0);
  }
  currecord = r;
  curmatch = ((&r->matches)->tqh_first);
 } else {
  m = ((curmatch)->entry.tqe_next);
  if (m == ((void *)0)) {
   r = ((currecord)->entry.tqe_next);
   if (r == ((void *)0)) {
    dobeep();
    ewprintf("The end of *cscope* buffer has been"
        " reached");
    return (0);
   } else {
    currecord = r;
    curmatch = ((&currecord->matches)->tqh_first);
   }
  } else
   curmatch = m;
 }
 return (jumptomatch());
}

variable_types: struct csmatch { struct { struct csmatch *tqe_next; struct csmatch **tqe_prev; } entry; int lineno; } *


csprevmatch

decompiled_code:
__int64 csprevmatch()
{
__int64 v1; // rax

if ( !curmatch )
return 0LL;
if ( **(_QWORD **)(*(_QWORD *)(curmatch + 8) + 8LL) )
{
curmatch = **(_QWORD **)(*(_QWORD *)(curmatch + 8) + 8LL);
}
else
{
v1 = **(_QWORD **)(*(_QWORD *)(currecord + 8) + 8LL);
if ( !v1 )
{
dobeep();
ewprintf("The beginning of *cscope* buffer has been reached");
return 0LL;
}
currecord = **(_QWORD **)(*(_QWORD *)(currecord + 8) + 8LL);
curmatch = **(_QWORD **)(*(_QWORD *)(v1 + 32) + 8LL);
}
return jumptomatch();
}

canonical_decompiled_code:
__int64 func18()
{
__int64 v1; // rax

if ( !curmatch )
return 0LL;
if ( **(_QWORD **)(*(_QWORD *)(curmatch + 8) + 8LL) )
{
curmatch = **(_QWORD **)(*(_QWORD *)(curmatch + 8) + 8LL);
}
else
{
v1 = **(_QWORD **)(*(_QWORD *)(currecord + 8) + 8LL);
if ( !v1 )
{
dobeep();
ewprintf("The beginning of *cscope* buffer has been reached");
return 0LL;
}
currecord = **(_QWORD **)(*(_QWORD *)(currecord + 8) + 8LL);
curmatch = **(_QWORD **)(*(_QWORD *)(v1 + 32) + 8LL);
}
return func7();
}

original_code:
int
csprevmatch(int f, int n)
{
 struct csmatch *m;
 struct csrecord *r;
 if (curmatch == ((void *)0))
  return (0);
 else {
  m = (*(((struct matches *)((curmatch)->entry.tqe_prev))->tqh_last));
  if (m)
   curmatch = m;
  else {
   r = (*(((struct csrecords *)((currecord)->entry.tqe_prev))->tqh_last));
   if (r == ((void *)0)) {
    dobeep();
    ewprintf("The beginning of *cscope* buffer has"
        " been reached");
    return (0);
   } else {
    currecord = r;
    curmatch = (*(((struct matches *)((&currecord->matches)->tqh_last))->tqh_last));
   }
  }
 }
 return (jumptomatch());
}

user_defined_types: struct csmatch { struct { struct csmatch *tqe_next; struct csmatch **tqe_prev; } entry; int lineno; }

user_defined_types: struct csrecords { struct csrecord *tqh_first; struct csrecord **tqh_last; }


csnextfile

decompiled_code:
__int64 csnextfile()
{
__int64 v0; // rax
__int64 result; // rax

if ( curmatch )
{
v0 = *(_QWORD *)currecord;
if ( *(_QWORD *)currecord )
{
LABEL_3:
currecord = v0;
curmatch = *(_QWORD *)(v0 + 24);
return jumptomatch();
}
dobeep();
ewprintf("The end of *cscope* buffer has been reached");
result = 0LL;
}
else
{
v0 = csrecords;
if ( csrecords )
goto LABEL_3;
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func19()
{
__int64 v0; // rax
__int64 result; // rax

if ( curmatch )
{
v0 = *(_QWORD *)currecord;
if ( *(_QWORD *)currecord )
{
LABEL_3:
currecord = v0;
curmatch = *(_QWORD *)(v0 + 24);
return func7();
}
dobeep();
ewprintf("The end of *cscope* buffer has been reached");
result = 0LL;
}
else
{
v0 = csrecords;
if ( csrecords )
goto LABEL_3;
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
result = 0LL;
}
return result;
}

original_code:
int
csnextfile(int f, int n)
{
 struct csrecord *r;
 if (curmatch == ((void *)0)) {
  if ((r = ((&csrecords)->tqh_first)) == ((void *)0)) {
   dobeep();
   ewprintf("The *cscope* buffer does not exist yet");
   return (0);
  }
 } else {
  if ((r = ((currecord)->entry.tqe_next)) == ((void *)0)) {
   dobeep();
   ewprintf("The end of *cscope* buffer has been reached");
   return (0);
  }
 }
 currecord = r;
 curmatch = ((&currecord->matches)->tqh_first);
 return (jumptomatch());
}


csprevfile

decompiled_code:
__int64 csprevfile()
{
__int64 v0; // rax
__int64 result; // rax

if ( curmatch )
{
v0 = **(_QWORD **)(*(_QWORD *)(currecord + 8) + 8LL);
if ( v0 )
{
LABEL_3:
currecord = v0;
curmatch = *(_QWORD *)(v0 + 24);
return jumptomatch();
}
dobeep();
ewprintf("The beginning of *cscope* buffer has been reached");
result = 0LL;
}
else
{
v0 = csrecords;
if ( csrecords )
goto LABEL_3;
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
__int64 v0; // rax
__int64 result; // rax

if ( curmatch )
{
v0 = **(_QWORD **)(*(_QWORD *)(currecord + 8) + 8LL);
if ( v0 )
{
LABEL_3:
currecord = v0;
curmatch = *(_QWORD *)(v0 + 24);
return func7();
}
dobeep();
ewprintf("The beginning of *cscope* buffer has been reached");
result = 0LL;
}
else
{
v0 = csrecords;
if ( csrecords )
goto LABEL_3;
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
result = 0LL;
}
return result;
}

original_code:
int
csprevfile(int f, int n)
{
 struct csrecord *r;
 if (curmatch == ((void *)0)) {
  if ((r = ((&csrecords)->tqh_first)) == ((void *)0)) {
   dobeep();
   ewprintf("The *cscope* buffer does not exist yet");
   return (0);
  }
 } else {
  if ((r = (*(((struct csrecords *)((currecord)->entry.tqe_prev))->tqh_last))) == ((void *)0)) {
   dobeep();
   ewprintf("The beginning of *cscope* buffer has been"
       " reached");
   return (0);
  }
 }
 currecord = r;
 curmatch = ((&currecord->matches)->tqh_first);
 return (jumptomatch());
}


gid

original_code:
static int
gid(int f, int n)
{
 char command[1024];
 char cprompt[1024], *bufp;
 int c;
 struct buffer *bp;
 struct mgwin *wp;
 int i, j, len;
 i = curwp->w_doto;
 while (i > 0) {
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalnum) || c == '_')
   break;
  i--;
 }
 for (; i > 0; i--) {
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i - 1)])));
  if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalnum) && c != '_')
   break;
 }
 for (j = 0; j < sizeof(cprompt) - 1 && i < ((curwp->w_dotp)->l_used);
     j++, i++) {
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
  if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalnum) && c != '_')
   break;
  cprompt[j] = c;
 }
 cprompt[j] = '\0';
 if ((bufp = eread("Run gid (with args): ", cprompt, 1024,
     (j ? 0x0020 : 0) | 0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 len = snprintf(command, sizeof(command), "gid %s", cprompt);
 if (len < 0 || len >= sizeof(command))
  return (0);
 if ((bp = compile_mode("*gid*", command)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 compile_win = curwp = wp;
 return (1);
}

canonical_original_code:
static int gid(int f, int n)
{
 char command[1024];
 char cprompt[1024]; char *bufp;
 int c;
 struct buffer *bp;
 struct mgwin *wp;
 int i; int j; int len;
 i = curwp->w_doto;
 while (i > 0) {
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalnum) || c == '_')
   break;
  i--;
 }
 for (; i > 0; i--) {
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i - 1)])));
  if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalnum) && c != '_')
   break;
 }
 for (j = 0; j < sizeof(cprompt) - 1 && i < ((curwp->w_dotp)->l_used);
     j++, i++) {
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
  if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalnum) && c != '_')
   break;
  cprompt[j] = c;
 }
 cprompt[j] = '\0';
 if ((bufp = eread("Run gid (with args): ", cprompt, 1024,
     (j ? 0x0020 : 0) | 0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 len = snprintf(command, sizeof(command), "gid %s", cprompt);
 if (len < 0 || len >= sizeof(command))
  return (0);
 if ((bp = compile_mode("*gid*", command)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 compile_win = curwp = wp;
 return (1);
}

variable_types:
command
char [1024]

variable_types:
cprompt
char [1024]

variable_types:
bufp
char *

variable_types: c int

variable_types: struct buffer { struct list { union { struct mgwin { struct list w_list; struct buffer *w_bufp; struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *w_linep; struct line *w_dotp; struct line *w_markp; int w_doto; int w_marko; int w_toprow; int w_ntrows; int w_frame; char w_rflag; char w_flag; struct line *w_wrapline; int w_dotline; int w_markline; } *l_wp; struct buffer *x_bp; struct list *l_nxt; } l_p; char *l_name; } b_list; struct buffer *b_altb; struct line *b_dotp; struct line *b_markp; struct line *b_headp; struct maps_s { struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *p_map; char *p_name; struct maps_s *p_next; } *b_modes[4]; int b_doto; int b_marko; short b_nmodes; char b_nwnd; char b_flag; char b_fname[1024]; char b_cwd[1024]; struct fileinfo { unsigned int fi_uid; unsigned int fi_gid; unsigned int fi_mode; struct timespec { long tv_sec; long tv_nsec; } fi_mtime; } b_fi; struct undoq { struct undo_rec { struct { struct undo_rec *tqe_next; struct undo_rec **tqe_prev; } next; enum { INSERT=1, DELETE=2, BOUNDARY=3, MODIFIED=4, DELREG=5 } type; struct region { struct line *r_linep; int r_offset; int r_lineno; int r_size; } region; int pos; char *content; } *tqh_first; struct undo_rec **tqh_last; } b_undo; struct undo_rec *b_undoptr; int b_dotline; int b_markline; int b_lines; } *

variable_types: struct mgwin { struct list { union { struct mgwin *l_wp; struct buffer { struct list b_list; struct buffer *b_altb; struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *b_dotp; struct line *b_markp; struct line *b_headp; struct maps_s { struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; } map_element[1]; } *p_map; char *p_name; struct maps_s *p_next; } *b_modes[4]; int b_doto; int b_marko; short b_nmodes; char b_nwnd; char b_flag; char b_fname[1024]; char b_cwd[1024]; struct fileinfo { unsigned int fi_uid; unsigned int fi_gid; unsigned int fi_mode; struct timespec { long tv_sec; long tv_nsec; } fi_mtime; } b_fi; struct undoq { struct undo_rec { struct { struct undo_rec *tqe_next; struct undo_rec **tqe_prev; } next; enum { INSERT=1, DELETE=2, BOUNDARY=3, MODIFIED=4, DELREG=5 } type; struct region { struct line *r_linep; int r_offset; int r_lineno; int r_size; } region; int pos; char *content; } *tqh_first; struct undo_rec **tqh_last; } b_undo; struct undo_rec *b_undoptr; int b_dotline; int b_markline; int b_lines; } *x_bp; struct list *l_nxt; } l_p; char *l_name; } w_list; struct buffer *w_bufp; struct line *w_linep; struct line *w_dotp; struct line *w_markp; int w_doto; int w_marko; int w_toprow; int w_ntrows; int w_frame; char w_rflag; char w_flag; struct line *w_wrapline; int w_dotline; int w_markline; } *

variable_types: i int

variable_types: j int

variable_types: len int

user_defined_types: struct buffer { struct list b_list; struct buffer *b_altb; struct line *b_dotp; struct line *b_markp; struct line *b_headp; struct maps_s *b_modes[4]; int b_doto; int b_marko; short b_nmodes; char b_nwnd; char b_flag; char b_fname[1024]; char b_cwd[1024]; struct fileinfo b_fi; struct undoq b_undo; struct undo_rec *b_undoptr; int b_dotline; int b_markline; int b_lines; }

user_defined_types: struct mgwin { struct list w_list; struct buffer *w_bufp; struct line *w_linep; struct line *w_dotp; struct line *w_markp; int w_doto; int w_marko; int w_toprow; int w_ntrows; int w_frame; char w_rflag; char w_flag; struct line *w_wrapline; int w_dotline; int w_markline; }

user_defined_types: struct list { union { struct mgwin *l_wp; struct buffer *x_bp; struct list *l_nxt; } l_p; char *l_name; }

user_defined_types: struct fileinfo { unsigned int fi_uid; unsigned int fi_gid; unsigned int fi_mode; struct timespec fi_mtime; }

user_defined_types: struct undoq { struct undo_rec *tqh_first; struct undo_rec **tqh_last; }

user_defined_types: struct maps_s { struct keymap_s *p_map; char *p_name; struct maps_s *p_next; }

user_defined_types: struct undo_rec { struct { struct undo_rec *tqe_next; struct undo_rec **tqe_prev; } next; enum { INSERT=1, DELETE=2, BOUNDARY=3, MODIFIED=4, DELREG=5 } type; struct region region; int pos; char *content; }

user_defined_types: struct keymap_s { short map_num; short map_max; int (*map_default)(int, int); struct map_element map_element[1]; }


grep

decompiled_code:
__int64 grep()
{
_BYTE *v0; // rax
unsigned int v1; // edx
unsigned __int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
char v7[1032]; // [rsp+0h] [rbp-408h] BYREF

strlcpy(v7, "grep -n ", 1024LL);
v0 = (_BYTE *)eread("Run grep: ", v7, 1024LL, 56LL);
if ( !v0 )
return 2;
v1 = 0;
if ( *v0 )
{
v3 = strlcat(v7, " /dev/null", 1024LL);
v1 = 0;
if ( v3 <= 0x3FF )
{
v4 = compile_mode((__int64)"*grep*", v7);
v5 = v4;
v1 = 0;
if ( v4 )
{
v6 = popbuf(v4, 0LL, 0LL);
if ( v6 )
{
curbp = v5;
curwp = v6;
compile_win = v6;
v1 = 1;
}
else
{
v1 = 0;
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
_BYTE *v0; // rax
unsigned int v1; // edx
unsigned __int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
char v7[1032]; // [rsp+0h] [rbp-408h] BYREF

strlcpy(v7, "grep -n ", 1024LL);
v0 = (_BYTE *)eread("Run grep: ", v7, 1024LL, 56LL);
if ( !v0 )
return 2;
v1 = 0;
if ( *v0 )
{
v3 = strlcat(v7, " /dev/null", 1024LL);
v1 = 0;
if ( v3 <= 0x3FF )
{
v4 = func0((__int64)"*grep*", v7);
v5 = v4;
v1 = 0;
if ( v4 )
{
v6 = popbuf(v4, 0LL, 0LL);
if ( v6 )
{
curbp = v5;
curwp = v6;
compile_win = v6;
v1 = 1;
}
else
{
v1 = 0;
}
}
}
}
return v1;
}

original_code:
static int
grep(int f, int n)
{
 char cprompt[1024], *bufp;
 struct buffer *bp;
 struct mgwin *wp;
 (void)strlcpy(cprompt, "grep -n ", sizeof(cprompt));
 if ((bufp = eread("Run grep: ", cprompt, 1024,
     0x0020 | 0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if (strlcat(cprompt, " /dev/null", sizeof(cprompt)) >= sizeof(cprompt))
  return (0);
 if ((bp = compile_mode("*grep*", cprompt)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 compile_win = curwp = wp;
 return (1);
}

canonical_original_code:
static int grep(int f, int n)
{
 char cprompt[1024]; char *bufp;
 struct buffer *bp;
 struct mgwin *wp;
 (void)strlcpy(cprompt, "grep -n ", sizeof(cprompt));
 if ((bufp = eread("Run grep: ", cprompt, 1024,
     0x0020 | 0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if (strlcat(cprompt, " /dev/null", sizeof(cprompt)) >= sizeof(cprompt))
  return (0);
 if ((bp = compile_mode("*grep*", cprompt)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 compile_win = curwp = wp;
 return (1);
}

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

user_defined_types: struct region { struct line *r_linep; int r_offset; int r_lineno; int r_size; }

user_defined_types: struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; }

user_defined_types: struct map_element { short k_base; short k_num; int (**k_funcp)(int, int); struct keymap_s *k_prefmap; }


decompiled_code:
__int64 compile_goto_error()
{
__int64 v0; // r12
__int64 result; // rax
char *v2; // rbp
__int64 v3; // rdx
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 *v7; // rdx
__int64 v8; // rdi
char *v9; // rax
char *v10; // rbx
char *v11; // rax
char *v12; // rbp
char *v13; // rax
unsigned int v14; // er13
__int64 v15; // [rsp+8h] [rbp-440h] BYREF
char v16[1032]; // [rsp+10h] [rbp-438h] BYREF
char *stringp[6]; // [rsp+418h] [rbp-30h] BYREF

compile_win = curwp;
compile_buffer = curbp;
v0 = *(_QWORD *)(*(_QWORD *)(curbp + 40LL) + 8LL);
if ( v0 == *(_QWORD *)(curwp + 32LL) )
return 0LL;
while ( 1 )
{
v9 = (char *)linetostr();
v10 = v9;
if ( !v9 )
return 0LL;
stringp[0] = v9;
v11 = strsep(stringp, ":");
v12 = v11;
if ( !v11 )
goto LABEL_9;
if ( !*v11 )
goto LABEL_9;
v13 = strsep(stringp, ":");
if ( !v13 )
goto LABEL_9;
if ( !*v13 )
goto LABEL_9;
v14 = strtonum(v13, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, &v15);
if ( v15 )
goto LABEL_9;
if ( *v12 == 47 )
break;
if ( (unsigned int)getbufcwd(v16, 1024LL) && (unsigned __int64)strlcat(v16, v12, 1024LL) <= 0x3FF )
{
free(v10);
v2 = v16;
goto LABEL_4;
}
LABEL_9:
free(v10);
v6 = curwp;
v7 = *(__int64 **)(curwp + 32LL);
if ( v7 == *(__int64 **)(*(_QWORD *)(curbp + 40LL) + 8LL) )
{
dobeep();
ewprintf("No more hits");
return 0LL;
}
v8 = *v7;
*(_QWORD *)(curwp + 32LL) = *v7;
*(_BYTE *)(v6 + 68) |= 2u;
if ( v8 == v0 )
return 0LL;
}
v2 = (char *)adjustname(v12, 1LL);
free(v10);
result = 0LL;
if ( !v2 )
return result;
LABEL_4:
v4 = findbuffer(v2);
result = 0LL;
if ( v4 )
{
v5 = popbuf(v4, 0LL, v3);
if ( v5 )
{
curbp = v4;
curwp = v5;
if ( !*(_BYTE *)(v4 + 92) )
readin(v2);
gotoline(7LL, v14);
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // r12
__int64 result; // rax
char *v2; // rbp
__int64 v3; // rdx
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 *v7; // rdx
__int64 v8; // rdi
char *v9; // rax
char *v10; // rbx
char *v11; // rax
char *v12; // rbp
char *v13; // rax
unsigned int v14; // er13
__int64 v15; // [rsp+8h] [rbp-440h] BYREF
char v16[1032]; // [rsp+10h] [rbp-438h] BYREF
char *stringp[6]; // [rsp+418h] [rbp-30h] BYREF

compile_win = curwp;
compile_buffer = curbp;
v0 = *(_QWORD *)(*(_QWORD *)(curbp + 40LL) + 8LL);
if ( v0 == *(_QWORD *)(curwp + 32LL) )
return 0LL;
while ( 1 )
{
v9 = (char *)linetostr();
v10 = v9;
if ( !v9 )
return 0LL;
stringp[0] = v9;
v11 = strsep(stringp, ":");
v12 = v11;
if ( !v11 )
goto LABEL_9;
if ( !*v11 )
goto LABEL_9;
v13 = strsep(stringp, ":");
if ( !v13 )
goto LABEL_9;
if ( !*v13 )
goto LABEL_9;
v14 = strtonum(v13, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, &v15);
if ( v15 )
goto LABEL_9;
if ( *v12 == 47 )
break;
if ( (unsigned int)getbufcwd(v16, 1024LL) && (unsigned __int64)strlcat(v16, v12, 1024LL) <= 0x3FF )
{
free(v10);
v2 = v16;
goto LABEL_4;
}
LABEL_9:
free(v10);
v6 = curwp;
v7 = *(__int64 **)(curwp + 32LL);
if ( v7 == *(__int64 **)(*(_QWORD *)(curbp + 40LL) + 8LL) )
{
dobeep();
ewprintf("No more hits");
return 0LL;
}
v8 = *v7;
*(_QWORD *)(curwp + 32LL) = *v7;
*(_BYTE *)(v6 + 68) |= 2u;
if ( v8 == v0 )
return 0LL;
}
v2 = (char *)adjustname(v12, 1LL);
free(v10);
result = 0LL;
if ( !v2 )
return result;
LABEL_4:
v4 = findbuffer(v2);
result = 0LL;
if ( v4 )
{
v5 = popbuf(v4, 0LL, v3);
if ( v5 )
{
curbp = v4;
curwp = v5;
if ( !*(_BYTE *)(v4 + 92) )
readin(v2);
gotoline(7LL, v14);
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int
compile_goto_error(int f, int n)
{
 struct buffer *bp;
 struct mgwin *wp;
 char *fname, *line, *lp, *ln;
 int lineno;
 char *adjf, path[1024];
 const char *errstr;
 struct line *last;
 compile_win = curwp;
 compile_buffer = curbp;
 last = ((((compile_buffer)->b_headp)->l_bp));
 retry:
 if (curwp->w_dotp == last)
  return (0);
 if ((line = linetostr(curwp->w_dotp)) == ((void *)0))
  return (0);
 lp = line;
 if ((fname = strsep(&lp, ":")) == ((void *)0) || *fname == '\0')
  goto fail;
 if ((ln = strsep(&lp, ":")) == ((void *)0) || *ln == '\0')
  goto fail;
 lineno = (int)strtonum(ln, (-0x7fffffff - 1), 0x7fffffff, &errstr);
 if (errstr)
  goto fail;
 if (fname && fname[0] != '/') {
  if (getbufcwd(path, sizeof(path)) == 0)
   goto fail;
  if (strlcat(path, fname, sizeof(path)) >= sizeof(path))
   goto fail;
  adjf = path;
 } else {
  adjf = adjustname(fname, 1);
 }
 free(line);
 if (adjf == ((void *)0))
  return (0);
 if ((bp = findbuffer(adjf)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 curwp = wp;
 if (bp->b_fname[0] == '\0')
  readin(adjf);
 gotoline(7, lineno);
 return (1);
fail:
 free(line);
 if (curwp->w_dotp != ((((curbp)->b_headp)->l_bp))) {
  curwp->w_dotp = ((curwp->w_dotp)->l_fp);
  curwp->w_rflag |= 0x02;
  goto retry;
 }
 dobeep();
 ewprintf("No more hits");
 return (0);
}

canonical_original_code:
static int compile_goto_error(int f, int n)
{
 struct buffer *bp;
 struct mgwin *wp;
 char *fname; char *line; char *lp; char *ln;
 int lineno;
 char *adjf; char path[1024];
 char *errstr;
 struct line *last;
 compile_win = curwp;
 compile_buffer = curbp;
 last = ((((compile_buffer)->b_headp)->l_bp));
 retry:
 if (curwp->w_dotp == last)
  return (0);
 if ((line = linetostr(curwp->w_dotp)) == ((void *)0))
  return (0);
 lp = line;
 if ((fname = strsep(&lp, ":")) == ((void *)0) || *fname == '\0')
  goto fail;
 if ((ln = strsep(&lp, ":")) == ((void *)0) || *ln == '\0')
  goto fail;
 lineno = (int)strtonum(ln, (-0x7fffffff - 1), 0x7fffffff, &errstr);
 if (errstr)
  goto fail;
 if (fname && fname[0] != '/') {
  if (getbufcwd(path, sizeof(path)) == 0)
   goto fail;
  if (strlcat(path, fname, sizeof(path)) >= sizeof(path))
   goto fail;
  adjf = path;
 } else {
  adjf = adjustname(fname, 1);
 }
 free(line);
 if (adjf == ((void *)0))
  return (0);
 if ((bp = findbuffer(adjf)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 curwp = wp;
 if (bp->b_fname[0] == '\0')
  readin(adjf);
 gotoline(7, lineno);
 return (1);
fail:
 free(line);
 if (curwp->w_dotp != ((((curbp)->b_headp)->l_bp))) {
  curwp->w_dotp = ((curwp->w_dotp)->l_fp);
  curwp->w_rflag |= 0x02;
  goto retry;
 }
 dobeep();
 ewprintf("No more hits");
 return (0);
}

variable_types:
fname
char *

variable_types:
line
char *

variable_types:
lp
char *

variable_types:
ln
char *

variable_types: lineno int

variable_types:
adjf
char *

variable_types:
path
char [1024]

variable_types:
errstr
char *

variable_types: struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *


decompiled_code:
__int64 next_error()
{
__int64 v0; // rax
_QWORD *v1; // rcx
__int64 result; // rax

v0 = compile_win;
if ( compile_win && compile_buffer )
{
curwp = compile_win;
curbp = compile_buffer;
v1 = *(_QWORD **)(compile_win + 32);
if ( v1 == *(_QWORD **)(*(_QWORD *)(compile_buffer + 40) + 8LL) )
{
dobeep();
ewprintf("No more hits");
result = 0LL;
}
else
{
*(_QWORD *)(compile_win + 32) = *v1;
*(_BYTE *)(v0 + 68) |= 2u;
result = compile_goto_error();
}
}
else
{
dobeep();
ewprintf("No compilation active");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
_QWORD *v1; // rcx
__int64 result; // rax

v0 = compile_win;
if ( compile_win && compile_buffer )
{
curwp = compile_win;
curbp = compile_buffer;
v1 = *(_QWORD **)(compile_win + 32);
if ( v1 == *(_QWORD **)(*(_QWORD *)(compile_buffer + 40) + 8LL) )
{
dobeep();
ewprintf("No more hits");
result = 0LL;
}
else
{
*(_QWORD *)(compile_win + 32) = *v1;
*(_BYTE *)(v0 + 68) |= 2u;
result = func3();
}
}
else
{
dobeep();
ewprintf("No compilation active");
result = 0LL;
}
return result;
}

original_code:
int
next_error(int f, int n)
{
 if (compile_win == ((void *)0) || compile_buffer == ((void *)0)) {
  dobeep();
  ewprintf("No compilation active");
  return (0);
 }
 curwp = compile_win;
 curbp = compile_buffer;
 if (curwp->w_dotp == ((((curbp)->b_headp)->l_bp))) {
  dobeep();
  ewprintf("No more hits");
  return (0);
 }
 curwp->w_dotp = ((curwp->w_dotp)->l_fp);
 curwp->w_rflag |= 0x02;
 return (compile_goto_error(f, n));
}

variable_types: f int

variable_types: n int


compile

decompiled_code:
__int64 __fastcall compile(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
_BYTE *v3; // rbx
__int64 result; // rax
__int64 v5; // rdx
__int64 v6; // rbx
__int64 v7; // rdx
char v8[1048]; // [rsp+0h] [rbp-418h] BYREF

strlcpy(v8, compile_last_command, 1024LL);
v2 = eread("Compile command: ", v8, 1024LL, 56LL);
if ( !v2 )
return 2LL;
v3 = (_BYTE *)v2;
result = 0LL;
if ( *v3 )
{
result = savebuffers(a1, a2);
if ( (_DWORD)result != 2 )
{
strlcpy(compile_last_command, v3, 1024LL);
v6 = compile_mode((__int64)"*compile*", v8);
result = 0LL;
if ( v6 )
{
v7 = popbuf(v6, 0LL, v5);
result = 0LL;
if ( v7 )
{
curbp = v6;
curwp = v7;
compile_win = v7;
gotoline(7LL, 0LL);
result = 1LL;
}
}
}
}
return result;
}

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

strlcpy(v8, compile_last_command, 1024LL);
v2 = eread("Compile command: ", v8, 1024LL, 56LL);
if ( !v2 )
return 2LL;
v3 = (_BYTE *)v2;
result = 0LL;
if ( *v3 )
{
result = savebuffers(a1, a2);
if ( (_DWORD)result != 2 )
{
strlcpy(compile_last_command, v3, 1024LL);
v6 = func0((__int64)"*compile*", v8);
result = 0LL;
if ( v6 )
{
v7 = popbuf(v6, 0LL, v5);
result = 0LL;
if ( v7 )
{
curbp = v6;
curwp = v7;
compile_win = v7;
gotoline(7LL, 0LL);
result = 1LL;
}
}
}
}
return result;
}

original_code:
int
compile(int f, int n)
{
 char cprompt[1024], *bufp;
 struct buffer *bp;
 struct mgwin *wp;
 (void)strlcpy(cprompt, compile_last_command, sizeof(cprompt));
 if ((bufp = eread("Compile command: ", cprompt, 1024,
     0x0020 | 0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if (savebuffers(f, n) == 2)
  return (2);
 (void)strlcpy(compile_last_command, bufp, sizeof(compile_last_command));
 if ((bp = compile_mode("*compile*", cprompt)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 compile_win = curwp = wp;
 gotoline(7, 0);
 return (1);
}

canonical_original_code:
int compile(int f, int n)
{
 char cprompt[1024]; char *bufp;
 struct buffer *bp;
 struct mgwin *wp;
 (void)strlcpy(cprompt, compile_last_command, sizeof(cprompt));
 if ((bufp = eread("Compile command: ", cprompt, 1024,
     0x0020 | 0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if (savebuffers(f, n) == 2)
  return (2);
 (void)strlcpy(compile_last_command, bufp, sizeof(compile_last_command));
 if ((bp = compile_mode("*compile*", cprompt)) == ((void *)0))
  return (0);
 if ((wp = popbuf(bp, 0x00)) == ((void *)0))
  return (0);
 curbp = bp;
 compile_win = curwp = wp;
 gotoline(7, 0);
 return (1);
}

variable_types:
cprompt
char [1024]

variable_types:
bufp
char *


decompiled_code:
__int64 grep_init()
{
funmap_add(compile_goto_error, "compile-goto-error");
funmap_add(next_error, "next-error");
funmap_add(grep, "grep");
funmap_add(compile, "compile");
funmap_add(gid, "gid");
return maps_add(&compilemap, "compile");
}

canonical_decompiled_code:
__int64 func6()
{
funmap_add(compile_goto_error, "compile-goto-error");
funmap_add(next_error, "next-error");
funmap_add(grep, "grep");
funmap_add(compile, "compile");
funmap_add(gid, "gid");
return maps_add(&compilemap, "compile");
}

original_code:
void
grep_init(void)
{
 funmap_add(compile_goto_error, "compile-goto-error");
 funmap_add(next_error, "next-error");
 funmap_add(grep, "grep");
 funmap_add(compile, "compile");
 funmap_add(gid, "gid");
 maps_add((KEYMAP *)&compilemap, "compile");
}

canonical_original_code:
void grep_init()
{
 funmap_add(compile_goto_error, "compile-goto-error");
 funmap_add(next_error, "next-error");
 funmap_add(grep, "grep");
 funmap_add(compile, "compile");
 funmap_add(gid, "gid");
 maps_add((struct keymap_s *)&compilemap, "compile");
}


globalwdtoggle

decompiled_code:
__int64 __fastcall globalwdtoggle(char a1, int a2)
{
_BOOL4 v2; // eax

if ( (a1 & 7) != 0 )
v2 = a2 > 0;
else
v2 = globalwd == 0;
globalwd = v2;
sgarbf = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, int a2)
{
_BOOL4 v2; // eax

if ( (a1 & 7) != 0 )
v2 = a2 > 0;
else
v2 = globalwd == 0;
globalwd = v2;
sgarbf = 1;
return 1LL;
}

original_code:
int
globalwdtoggle(int f, int n)
{
 if (f & 7)
  globalwd = n > 0;
 else
  globalwd = !globalwd;
 sgarbf = 1;
 return (1);
}


gotoeop

original_code:
int
gotoeop(int f, int n)
{
 int col, nospace;
 if (n < 0)
  return (gotobop(f, -n));
 while (n-- > 0) {
  nospace = 0;
  while (((curwp->w_dotp)->l_fp) != curbp->b_headp) {
   col = 0;
   curwp->w_doto = 0;
   while (col < ((curwp->w_dotp)->l_used) &&
       (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(col)])))))] & (unsigned short int) _ISspace)))
    col++;
   if (col >= ((curwp->w_dotp)->l_used)) {
    if (nospace)
     break;
   } else
    nospace = 1;
   curwp->w_dotp = ((curwp->w_dotp)->l_fp);
   curwp->w_dotline++;
   if (((curwp->w_dotp)->l_fp) == curbp->b_headp) {
    gotoeol(8, 1);
    curwp->w_rflag |= 0x02;
    return (0);
   }
  }
 }
 curwp->w_rflag |= 0x02;
 return (1);
}

canonical_original_code:
int gotoeop(int f, int n)
{
 int col; int nospace;
 if (n < 0)
  return (gotobop(f, -n));
 while (n-- > 0) {
  nospace = 0;
  while (((curwp->w_dotp)->l_fp) != curbp->b_headp) {
   col = 0;
   curwp->w_doto = 0;
   while (col < ((curwp->w_dotp)->l_used) &&
       (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(col)])))))] & (unsigned short) _ISspace)))
    col++;
   if (col >= ((curwp->w_dotp)->l_used)) {
    if (nospace)
     break;
   } else
    nospace = 1;
   curwp->w_dotp = ((curwp->w_dotp)->l_fp);
   curwp->w_dotline++;
   if (((curwp->w_dotp)->l_fp) == curbp->b_headp) {
    gotoeol(8, 1);
    curwp->w_rflag |= 0x02;
    return (0);
   }
  }
 }
 curwp->w_rflag |= 0x02;
 return (1);
}

variable_types: col int

variable_types: nospace int


gotobop

original_code:
int
gotobop(int f, int n)
{
 int col, nospace;
 if (n < 0)
  return (gotoeop(f, -n));
 while (n-- > 0) {
  nospace = 0;
  while (((curwp->w_dotp)->l_bp) != curbp->b_headp) {
   curwp->w_doto = 0;
   col = 0;
   while (col < ((curwp->w_dotp)->l_used) &&
       (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(col)])))))] & (unsigned short int) _ISspace)))
    col++;
   if (col >= ((curwp->w_dotp)->l_used)) {
    if (nospace)
     break;
   } else
    nospace = 1;
   curwp->w_dotline--;
   curwp->w_dotp = ((curwp->w_dotp)->l_bp);
  }
 }
 curwp->w_rflag |= 0x02;
 return (1);
}

canonical_original_code:
int gotobop(int f, int n)
{
 int col; int nospace;
 if (n < 0)
  return (gotoeop(f, -n));
 while (n-- > 0) {
  nospace = 0;
  while (((curwp->w_dotp)->l_bp) != curbp->b_headp) {
   curwp->w_doto = 0;
   col = 0;
   while (col < ((curwp->w_dotp)->l_used) &&
       (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(col)])))))] & (unsigned short) _ISspace)))
    col++;
   if (col >= ((curwp->w_dotp)->l_used)) {
    if (nospace)
     break;
   } else
    nospace = 1;
   curwp->w_dotline--;
   curwp->w_dotp = ((curwp->w_dotp)->l_bp);
  }
 }
 curwp->w_rflag |= 0x02;
 return (1);
}


fillpara

original_code:
int
fillpara(int f, int n)
{
 int c;
 int wordlen;
 int clength;
 int i;
 int eopflag;
 int firstflag;
 int newlength;
 int eolflag;
 int retval;
 struct line *eopline;
 char wbuf[256];
 undo_boundary_enable(8, 0);
 (void)gotoeop(8, 1);
 if (curwp->w_doto != 0) {
  (void)lnewline();
  eopline = ((curwp->w_dotp)->l_fp);
 } else
  eopline = curwp->w_dotp;
 (void)gotobop(8, 1);
 while (inword() == 0 && forwchar(8, 1));
 clength = curwp->w_doto;
 wordlen = 0;
 firstflag = 1;
 eopflag = 0;
 while (!eopflag) {
  if ((eolflag = (curwp->w_doto == ((curwp->w_dotp)->l_used)))) {
   c = ' ';
   if (((curwp->w_dotp)->l_fp) == eopline)
    eopflag = 1;
  } else
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
  if (ldelete((RSIZE) 1, 0x00) == 0 && !eopflag) {
   retval = 0;
   goto cleanup;
  }
  if (c != ' ' && c != '\t') {
   if (wordlen < 256 - 1)
    wbuf[wordlen++] = c;
   else {
    ewprintf("Word too long!");
   }
  } else if (wordlen) {
   newlength = clength + 1 + wordlen;
   if ((eolflag ||
       curwp->w_doto == ((curwp->w_dotp)->l_used) ||
       (c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) == ' '
       || c == '\t') && (((cinfo[((unsigned char) (wbuf[wordlen - 1]))]&0x10)!=0) ||
       (wbuf[wordlen - 1] == ')' && wordlen >= 2 &&
       ((cinfo[((unsigned char) (wbuf[wordlen - 2]))]&0x10)!=0))) &&
       wordlen < 256 - 1)
    wbuf[wordlen++] = ' ';
   if (newlength <= fillcol) {
    if (!firstflag) {
     (void)linsert(1, ' ');
     ++clength;
    }
    firstflag = 0;
   } else {
    if (curwp->w_doto > 0 &&
        (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto - 1)]))) == ' ') {
     curwp->w_doto -= 1;
     (void)ldelete((RSIZE) 1, 0x00);
    }
    (void)lnewline();
    clength = 0;
   }
   for (i = 0; i < wordlen; i++) {
    (void)linsert(1, wbuf[i]);
    ++clength;
   }
   wordlen = 0;
  }
 }
 (void)lnewline();
 (void)backchar(8, 1);
 retval = 1;
cleanup:
 undo_boundary_enable(8, 1);
 return (retval);
}

canonical_original_code:
int fillpara(int f, int n)
{
 int c;
 int wordlen;
 int clength;
 int i;
 int eopflag;
 int firstflag;
 int newlength;
 int eolflag;
 int retval;
 struct line *eopline;
 char wbuf[256];
 undo_boundary_enable(8, 0);
 (void)gotoeop(8, 1);
 if (curwp->w_doto != 0) {
  (void)lnewline();
  eopline = ((curwp->w_dotp)->l_fp);
 } else
  eopline = curwp->w_dotp;
 (void)gotobop(8, 1);
 while (inword() == 0 && forwchar(8, 1));
 clength = curwp->w_doto;
 wordlen = 0;
 firstflag = 1;
 eopflag = 0;
 while (!eopflag) {
  if ((eolflag = (curwp->w_doto == ((curwp->w_dotp)->l_used)))) {
   c = ' ';
   if (((curwp->w_dotp)->l_fp) == eopline)
    eopflag = 1;
  } else
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
  if (ldelete((int) 1, 0x00) == 0 && !eopflag) {
   retval = 0;
   goto cleanup;
  }
  if (c != ' ' && c != '\t') {
   if (wordlen < 256 - 1)
    wbuf[wordlen++] = c;
   else {
    ewprintf("Word too long!");
   }
  } else if (wordlen) {
   newlength = clength + 1 + wordlen;
   if ((eolflag ||
       curwp->w_doto == ((curwp->w_dotp)->l_used) ||
       (c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) == ' '
       || c == '\t') && (((cinfo[((unsigned char) (wbuf[wordlen - 1]))]&0x10)!=0) ||
       (wbuf[wordlen - 1] == ')' && wordlen >= 2 &&
       ((cinfo[((unsigned char) (wbuf[wordlen - 2]))]&0x10)!=0))) &&
       wordlen < 256 - 1)
    wbuf[wordlen++] = ' ';
   if (newlength <= fillcol) {
    if (!firstflag) {
     (void)linsert(1, ' ');
     ++clength;
    }
    firstflag = 0;
   } else {
    if (curwp->w_doto > 0 &&
        (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto - 1)]))) == ' ') {
     curwp->w_doto -= 1;
     (void)ldelete((int) 1, 0x00);
    }
    (void)lnewline();
    clength = 0;
   }
   for (i = 0; i < wordlen; i++) {
    (void)linsert(1, wbuf[i]);
    ++clength;
   }
   wordlen = 0;
  }
 }
 (void)lnewline();
 (void)backchar(8, 1);
 retval = 1;
cleanup:
 undo_boundary_enable(8, 1);
 return (retval);
}

variable_types: c int

variable_types: wordlen int

variable_types: clength int

variable_types: i int

variable_types: eopflag int

variable_types: firstflag int

variable_types: newlength int

variable_types: eolflag int

variable_types: retval int

variable_types:
wbuf
char [256]


killpara

decompiled_code:
__int64 __fastcall killpara(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 result; // rax
int v7; // ebp
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8

while ( a2 )
{
v7 = gotoeop(8LL, 1, a3, a4, a5);
v8 = curwp;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
v9 = *(unsigned int *)(v8 + 48);
*(_DWORD *)(v8 + 52) = v9;
gotobop(8LL, 1, v9, v10, v11);
*(_DWORD *)(curwp + 48LL) = 0;
result = killregion(8LL, 1LL);
if ( (_DWORD)result == 1 )
{
--a2;
if ( v7 )
continue;
}
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 result; // rax
int v7; // ebp
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8

while ( a2 )
{
v7 = func0(8LL, 1, a3, a4, a5);
v8 = curwp;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
v9 = *(unsigned int *)(v8 + 48);
*(_DWORD *)(v8 + 52) = v9;
func1(8LL, 1, v9, v10, v11);
*(_DWORD *)(curwp + 48LL) = 0;
result = killregion(8LL, 1LL);
if ( (_DWORD)result == 1 )
{
--a2;
if ( v7 )
continue;
}
return result;
}
return 1LL;
}

original_code:
int
killpara(int f, int n)
{
 int status, end = 0;
 while (n--) {
  if (!gotoeop(8, 1))
   end = 1;
  curwp->w_markp = curwp->w_dotp;
  curwp->w_marko = curwp->w_doto;
  (void)gotobop(8, 1);
  curwp->w_doto = 0;
  if ((status = killregion(8, 1)) != 1)
   return (status);
  if (end)
   return (1);
 }
 return (1);
}

canonical_original_code:
int killpara(int f, int n)
{
 int status; int end = 0;
 while (n--) {
  if (!gotoeop(8, 1))
   end = 1;
  curwp->w_markp = curwp->w_dotp;
  curwp->w_marko = curwp->w_doto;
  (void)gotobop(8, 1);
  curwp->w_doto = 0;
  if ((status = killregion(8, 1)) != 1)
   return (status);
  if (end)
   return (1);
 }
 return (1);
}

variable_types: status int

variable_types: end int


fillword

original_code:
int
fillword(int f, int n)
{
 char c;
 int col, i, nce;
 for (i = col = 0; col <= fillcol; ++i, ++col) {
  if (i == curwp->w_doto)
   return selfinsert(f, n);
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
  if (c == '\t'
   )
   col |= 0x07;
  else if (((cinfo[((unsigned char) (c))]&0x08)!=0) != 0)
   ++col;
 }
 if (curwp->w_doto != ((curwp->w_dotp)->l_used)) {
  (void)selfinsert(f, n);
  nce = ((curwp->w_dotp)->l_used) - curwp->w_doto;
 } else
  nce = 0;
 curwp->w_doto = i;
 if ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) != ' ' && c != '\t')
  do {
   (void)backchar(8, 1);
  } while ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) != ' ' &&
      c != '\t' && curwp->w_doto > 0);
 if (curwp->w_doto == 0)
  do {
   (void)forwchar(8, 1);
  } while ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) != ' ' &&
      c != '\t' && curwp->w_doto < ((curwp->w_dotp)->l_used));
 (void)delwhite(8, 1);
 (void)lnewline();
 i = ((curwp->w_dotp)->l_used) - nce;
 curwp->w_doto = i > 0 ? i : 0;
 curwp->w_rflag |= 0x02;
 if (nce == 0 && curwp->w_doto != 0)
  return (fillword(f, n));
 return (1);
}

canonical_original_code:
int fillword(int f, int n)
{
 char c;
 int col; int i; int nce;
 for (i = col = 0; col <= fillcol; ++i, ++col) {
  if (i == curwp->w_doto)
   return selfinsert(f, n);
  c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
  if (c == '\t'
   )
   col |= 0x07;
  else if (((cinfo[((unsigned char) (c))]&0x08)!=0) != 0)
   ++col;
 }
 if (curwp->w_doto != ((curwp->w_dotp)->l_used)) {
  (void)selfinsert(f, n);
  nce = ((curwp->w_dotp)->l_used) - curwp->w_doto;
 } else
  nce = 0;
 curwp->w_doto = i;
 if ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) != ' ' && c != '\t')
  do {
   (void)backchar(8, 1);
  } while ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) != ' ' &&
      c != '\t' && curwp->w_doto > 0);
 if (curwp->w_doto == 0)
  do {
   (void)forwchar(8, 1);
  } while ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))) != ' ' &&
      c != '\t' && curwp->w_doto < ((curwp->w_dotp)->l_used));
 (void)delwhite(8, 1);
 (void)lnewline();
 i = ((curwp->w_dotp)->l_used) - nce;
 curwp->w_doto = i > 0 ? i : 0;
 curwp->w_rflag |= 0x02;
 if (nce == 0 && curwp->w_doto != 0)
  return (fillword(f, n));
 return (1);
}

variable_types: f int

variable_types: n int

variable_types: c char

variable_types: nce int


setfillcol

decompiled_code:
__int64 __fastcall setfillcol(char a1, int a2)
{
unsigned int v2; // ebx
const char *v4; // rax
const char *v5; // rbp
unsigned int v6; // eax
__int64 v7; // [rsp+8h] [rbp-40h] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v2 = a1 & 7;
if ( (a1 & 7) != 0 )
{
fillcol = a2;
v2 = 1;
}
else
{
v4 = (const char *)eread("Set fill-column: ", v8, 32LL, 24LL);
v5 = v4;
if ( v4 )
{
if ( *v4 )
{
v6 = strtonum(v4, 0LL, 0x7FFFFFFFLL, &v7);
if ( v7 )
{
dobeep();
ewprintf("Invalid fill column: %s", v5);
}
else
{
fillcol = v6;
ewprintf("Fill column set to %d", v6);
v2 = 1;
}
}
}
else
{
v2 = 2;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, int a2)
{
unsigned int v2; // ebx
const char *v4; // rax
const char *v5; // rbp
unsigned int v6; // eax
__int64 v7; // [rsp+8h] [rbp-40h] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v2 = a1 & 7;
if ( (a1 & 7) != 0 )
{
fillcol = a2;
v2 = 1;
}
else
{
v4 = (const char *)eread("Set fill-column: ", v8, 32LL, 24LL);
v5 = v4;
if ( v4 )
{
if ( *v4 )
{
v6 = strtonum(v4, 0LL, 0x7FFFFFFFLL, &v7);
if ( v7 )
{
dobeep();
ewprintf("Invalid fill column: %s", v5);
}
else
{
fillcol = v6;
ewprintf("Fill column set to %d", v6);
v2 = 1;
}
}
}
else
{
v2 = 2;
}
}
return v2;
}

original_code:
int
setfillcol(int f, int n)
{
 char buf[32], *rep;
 const char *es;
 int nfill;
 if ((f & 7) != 0) {
  fillcol = n;
 } else {
  if ((rep = eread("Set fill-column: ", buf, sizeof(buf),
      0x0008 | 0x0010)) == ((void *)0))
   return (2);
  else if (rep[0] == '\0')
   return (0);
  nfill = strtonum(rep, 0, 0x7fffffff, &es);
  if (es != ((void *)0)) {
   dobeep();
   ewprintf("Invalid fill column: %s", rep);
   return (0);
  }
  fillcol = nfill;
  ewprintf("Fill column set to %d", fillcol);
 }
 return (1);
}

canonical_original_code:
int setfillcol(int f, int n)
{
 char buf[32]; char *rep;
 char *es;
 int nfill;
 if ((f & 7) != 0) {
  fillcol = n;
 } else {
  if ((rep = eread("Set fill-column: ", buf, sizeof(buf),
      0x0008 | 0x0010)) == ((void *)0))
   return (2);
  else if (rep[0] == '\0')
   return (0);
  nfill = strtonum(rep, 0, 0x7fffffff, &es);
  if (es != ((void *)0)) {
   dobeep();
   ewprintf("Invalid fill column: %s", rep);
   return (0);
  }
  fillcol = nfill;
  ewprintf("Fill column set to %d", fillcol);
 }
 return (1);
}

variable_types:
buf
char [32]

variable_types:
rep
char *

variable_types:
es
char *

variable_types: nfill int


kgrow

decompiled_code:
__int64 __fastcall kgrow(int a1)
{
unsigned int v1; // er12
char *v2; // rbp
int v3; // er13
int v4; // ebx
void *v5; // r14
__int64 result; // rax

v1 = ksize + 0x2000;
if ( ksize + 0x2000 <= (unsigned int)ksize )
{
dobeep();
ewprintf("Kill buffer size at maximum");
result = 0LL;
}
else
{
v2 = (char *)malloc(v1);
if ( v2 )
{
v3 = 2048;
if ( a1 == 2 )
v3 = kstart + 0x2000;
v4 = kused - kstart;
v5 = kbufp;
memmove(&v2[v3], (char *)kbufp + kstart, kused - kstart);
if ( v5 )
free(v5);
kbufp = v2;
ksize = v1;
kused = v3 + v4;
kstart = v3;
result = 1LL;
}
else
{
dobeep();
ewprintf("Can't get %ld bytes", ksize + 0x2000);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // er12
char *v2; // rbp
int v3; // er13
int v4; // ebx
void *v5; // r14
__int64 result; // rax

v1 = ksize + 0x2000;
if ( ksize + 0x2000 <= (unsigned int)ksize )
{
dobeep();
ewprintf("Kill buffer size at maximum");
result = 0LL;
}
else
{
v2 = (char *)malloc(v1);
if ( v2 )
{
v3 = 2048;
if ( a1 == 2 )
v3 = kstart + 0x2000;
v4 = kused - kstart;
v5 = kbufp;
memmove(&v2[v3], (char *)kbufp + kstart, kused - kstart);
if ( v5 )
free(v5);
kbufp = v2;
ksize = v1;
kused = v3 + v4;
kstart = v3;
result = 1LL;
}
else
{
dobeep();
ewprintf("Can't get %ld bytes", ksize + 0x2000);
result = 0LL;
}
}
return result;
}

original_code:
static int
kgrow(int dir)
{
 int nstart;
 char *nbufp;
 if ((unsigned)(ksize + 8192) <= (unsigned)ksize) {
  dobeep();
  ewprintf("Kill buffer size at maximum");
  return (0);
 }
 if ((nbufp = malloc((unsigned)(ksize + 8192))) == ((void *)0)) {
  dobeep();
  ewprintf("Can't get %ld bytes", (long)(ksize + 8192));
  return (0);
 }
 nstart = (dir == 0x02) ? (kstart + 8192) : (8192 / 4);
 bcopy(&(kbufp[kstart]), &(nbufp[nstart]), (int)(kused - kstart));
 if (kbufp != ((void *)0))
  free(kbufp);
 kbufp = nbufp;
 ksize += 8192;
 kused = kused - kstart + nstart;
 kstart = nstart;
 return (1);
}

canonical_original_code:
static int kgrow(int dir)
{
 int nstart;
 char *nbufp;
 if ((unsigned int)(ksize + 8192) <= (unsigned int)ksize) {
  dobeep();
  ewprintf("Kill buffer size at maximum");
  return (0);
 }
 if ((nbufp = malloc((unsigned int)(ksize + 8192))) == ((void *)0)) {
  dobeep();
  ewprintf("Can't get %ld bytes", (long)(ksize + 8192));
  return (0);
 }
 nstart = (dir == 0x02) ? (kstart + 8192) : (8192 / 4);
 bcopy(&(kbufp[kstart]), &(nbufp[nstart]), (int)(kused - kstart));
 if (kbufp != ((void *)0))
  free(kbufp);
 kbufp = nbufp;
 ksize += 8192;
 kused = kused - kstart + nstart;
 kstart = nstart;
 return (1);
}

variable_types: dir int

variable_types: nstart int

variable_types:
nbufp
char *


kdelete

decompiled_code:
void kdelete()
{
if ( kbufp )
{
free(kbufp);
kbufp = 0LL;
ksize = 0;
kused = 0;
kstart = 0;
}
}

canonical_decompiled_code:
void func1()
{
if ( kbufp )
{
free(kbufp);
kbufp = 0LL;
ksize = 0;
kused = 0;
kstart = 0;
}
}

original_code:
void
kdelete(void)
{
 if (kbufp != ((void *)0)) {
  free(kbufp);
  kbufp = ((void *)0);
  kstart = kused = ksize = 0;
 }
}

canonical_original_code:
void kdelete()
{
 if (kbufp != ((void *)0)) {
  free(kbufp);
  kbufp = ((void *)0);
  kstart = kused = ksize = 0;
 }
}


kinsert

decompiled_code:
__int64 __fastcall kinsert(char a1, int a2)
{
__int64 result; // rax
int v3; // eax

result = 1LL;
if ( a2 )
{
if ( kused == ksize && a2 == 1 )
{
result = kgrow(1);
if ( !(_DWORD)result )
return result;
goto LABEL_10;
}
if ( kstart || a2 != 2 )
{
if ( a2 != 1 )
{
if ( a2 != 2 )
{
panic("broken kinsert call");
return 1LL;
}
goto LABEL_13;
}
LABEL_10:
v3 = kused++;
*((_BYTE *)kbufp + v3) = a1;
return 1LL;
}
result = kgrow(2);
if ( (_DWORD)result )
{
LABEL_13:
*((_BYTE *)kbufp + --kstart) = a1;
return 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, int a2)
{
__int64 result; // rax
int v3; // eax

result = 1LL;
if ( a2 )
{
if ( kused == ksize && a2 == 1 )
{
result = func0(1);
if ( !(_DWORD)result )
return result;
goto LABEL_10;
}
if ( kstart || a2 != 2 )
{
if ( a2 != 1 )
{
if ( a2 != 2 )
{
panic("broken kinsert call");
return 1LL;
}
goto LABEL_13;
}
LABEL_10:
v3 = kused++;
*((_BYTE *)kbufp + v3) = a1;
return 1LL;
}
result = func0(2);
if ( (_DWORD)result )
{
LABEL_13:
*((_BYTE *)kbufp + --kstart) = a1;
return 1LL;
}
}
return result;
}

original_code:
int
kinsert(int c, int dir)
{
 if (dir == 0x00)
  return (1);
 if (kused == ksize && dir == 0x01 && kgrow(dir) == 0)
  return (0);
 if (kstart == 0 && dir == 0x02 && kgrow(dir) == 0)
  return (0);
 if (dir == 0x01)
  kbufp[kused++] = c;
 else if (dir == 0x02)
  kbufp[--kstart] = c;
 else
  panic("broken kinsert call");
 return (1);
}

variable_types: c int


kremove

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

if ( a1 < 0 )
return 0xFFFFFFFFLL;
v1 = kstart + a1;
if ( v1 >= kused )
result = 0xFFFFFFFFLL;
else
result = *((unsigned __int8 *)kbufp + v1);
return result;
}

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

if ( a1 < 0 )
return 0xFFFFFFFFLL;
v1 = kstart + a1;
if ( v1 >= kused )
result = 0xFFFFFFFFLL;
else
result = *((unsigned __int8 *)kbufp + v1);
return result;
}

original_code:
int
kremove(int n)
{
 if (n < 0 || n + kstart >= kused)
  return (-1);
 return (((unsigned char) (kbufp[n + kstart])));
}


kchunk

decompiled_code:
__int64 __fastcall kchunk(void *src, int a2, int a3)
{
int v3; // ebx
__int64 result; // rax
int v5; // er13
int v6; // ebx

if ( kused == kstart )
{
v3 = 1;
LABEL_8:
while ( 1 )
{
v5 = kused;
if ( ksize - kused >= a2 )
break;
result = kgrow(v3);
if ( !(_DWORD)result )
return result;
}
memmove((char *)kbufp + kused, src, a2);
kused = v5 + a2;
result = 1LL;
}
else
{
v3 = a3;
if ( (a3 & 1) != 0 )
goto LABEL_8;
result = 1LL;
if ( (a3 & 2) != 0 )
{
while ( kstart < a2 )
{
result = kgrow(v3);
if ( !(_DWORD)result )
return result;
}
v6 = kstart - a2;
memmove((char *)kbufp + kstart - a2, src, a2);
kstart = v6;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *src, int a2, int a3)
{
int v3; // ebx
__int64 result; // rax
int v5; // er13
int v6; // ebx

if ( kused == kstart )
{
v3 = 1;
LABEL_8:
while ( 1 )
{
v5 = kused;
if ( ksize - kused >= a2 )
break;
result = func0(v3);
if ( !(_DWORD)result )
return result;
}
memmove((char *)kbufp + kused, src, a2);
kused = v5 + a2;
result = 1LL;
}
else
{
v3 = a3;
if ( (a3 & 1) != 0 )
goto LABEL_8;
result = 1LL;
if ( (a3 & 2) != 0 )
{
while ( kstart < a2 )
{
result = func0(v3);
if ( !(_DWORD)result )
return result;
}
v6 = kstart - a2;
memmove((char *)kbufp + kstart - a2, src, a2);
kstart = v6;
result = 1LL;
}
}
return result;
}

original_code:
int
kchunk(char *cp1, RSIZE chunk, int kflag)
{
 if (kused == kstart)
  kflag = 0x01;
 if (kflag & 0x01) {
  while (ksize - kused < chunk)
   if (kgrow(kflag) == 0)
    return (0);
  bcopy(cp1, &(kbufp[kused]), (int)chunk);
  kused += chunk;
 } else if (kflag & 0x02) {
  while (kstart < chunk)
   if (kgrow(kflag) == 0)
    return (0);
  bcopy(cp1, &(kbufp[kstart - chunk]), (int)chunk);
  kstart -= chunk;
 }
 return (1);
}

canonical_original_code:
int kchunk(char *cp1, int chunk, int kflag)
{
 if (kused == kstart)
  kflag = 0x01;
 if (kflag & 0x01) {
  while (ksize - kused < chunk)
   if (kgrow(kflag) == 0)
    return (0);
  bcopy(cp1, &(kbufp[kused]), (int)chunk);
  kused += chunk;
 } else if (kflag & 0x02) {
  while (kstart < chunk)
   if (kgrow(kflag) == 0)
    return (0);
  bcopy(cp1, &(kbufp[kstart - chunk]), (int)chunk);
  kstart -= chunk;
 }
 return (1);
}

variable_types: chunk int

variable_types: kflag int


killline

original_code:
int
killline(int f, int n)
{
 struct line *nextp;
 RSIZE chunk;
 int i, c;
 if ((lastflag & 0x0002) == 0)
  kdelete();
 thisflag |= 0x0002;
 if (!(f & 7)) {
  for (i = curwp->w_doto; i < ((curwp->w_dotp)->l_used); ++i)
   if ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])))) != ' ' && c != '\t')
    break;
  if (i == ((curwp->w_dotp)->l_used))
   chunk = ((curwp->w_dotp)->l_used) - curwp->w_doto + 1;
  else {
   chunk = ((curwp->w_dotp)->l_used) - curwp->w_doto;
   if (chunk == 0)
    chunk = 1;
  }
 } else if (n > 0) {
  chunk = ((curwp->w_dotp)->l_used) - curwp->w_doto;
  nextp = ((curwp->w_dotp)->l_fp);
  if (nextp != curbp->b_headp)
   chunk++;
  if (nextp == curbp->b_headp)
   goto done;
  i = n;
  while (--i) {
   chunk += ((nextp)->l_used);
   nextp = ((nextp)->l_fp);
   if (nextp != curbp->b_headp)
    chunk++;
   if (nextp == curbp->b_headp)
    break;
  }
 } else {
  chunk = curwp->w_doto;
  curwp->w_doto = 0;
  i = n;
  while (i++) {
   if (((curwp->w_dotp)->l_fp))
    chunk++;
   curwp->w_dotp = ((curwp->w_dotp)->l_bp);
   curwp->w_rflag |= 0x02;
   chunk += ((curwp->w_dotp)->l_used);
  }
 }
done:
 if (chunk)
  return (ldelete(chunk, 0x01));
 return (1);
}

canonical_original_code:
int killline(int f, int n)
{
 struct line *nextp;
 int chunk;
 int i; int c;
 if ((lastflag & 0x0002) == 0)
  kdelete();
 thisflag |= 0x0002;
 if (!(f & 7)) {
  for (i = curwp->w_doto; i < ((curwp->w_dotp)->l_used); ++i)
   if ((c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])))) != ' ' && c != '\t')
    break;
  if (i == ((curwp->w_dotp)->l_used))
   chunk = ((curwp->w_dotp)->l_used) - curwp->w_doto + 1;
  else {
   chunk = ((curwp->w_dotp)->l_used) - curwp->w_doto;
   if (chunk == 0)
    chunk = 1;
  }
 } else if (n > 0) {
  chunk = ((curwp->w_dotp)->l_used) - curwp->w_doto;
  nextp = ((curwp->w_dotp)->l_fp);
  if (nextp != curbp->b_headp)
   chunk++;
  if (nextp == curbp->b_headp)
   goto done;
  i = n;
  while (--i) {
   chunk += ((nextp)->l_used);
   nextp = ((nextp)->l_fp);
   if (nextp != curbp->b_headp)
    chunk++;
   if (nextp == curbp->b_headp)
    break;
  }
 } else {
  chunk = curwp->w_doto;
  curwp->w_doto = 0;
  i = n;
  while (i++) {
   if (((curwp->w_dotp)->l_fp))
    chunk++;
   curwp->w_dotp = ((curwp->w_dotp)->l_bp);
   curwp->w_rflag |= 0x02;
   chunk += ((curwp->w_dotp)->l_used);
  }
 }
done:
 if (chunk)
  return (ldelete(chunk, 0x01));
 return (1);
}

variable_types: struct line { struct line *l_fp; struct line *l_bp; int l_size; int l_used; char *l_text; } *

variable_types: i int


yank

decompiled_code:
__int64 __fastcall yank(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // er12
int v4; // ebp
int i; // ebx
int v6; // eax
__int64 v7; // rcx
__int64 v8; // rdx

result = 0LL;
if ( a2 >= 0 )
{
v3 = a2;
undo_boundary_enable(8LL, 0LL);
if ( a2 )
{
v4 = 0;
do
{
isetmark();
for ( i = 0; ; ++i )
{
v6 = kremove(i);
if ( v6 < 0 )
break;
if ( v6 == 10 )
{
result = newline(8LL, 1LL);
if ( !(_DWORD)result )
return result;
++v4;
}
else
{
result = linsert(1LL, (unsigned int)v6);
if ( !(_DWORD)result )
return result;
}
}
--v3;
}
while ( v3 );
v7 = curwp;
v8 = *(_QWORD *)(curwp + 24LL);
if ( *(_QWORD *)(curwp + 32LL) != v8 )
goto LABEL_20;
while ( v4 )
{
--v4;
if ( *(_QWORD *)(v8 + 8) == *(_QWORD *)(curbp + 40LL) )
break;
v8 = *(_QWORD *)(v8 + 8);
}
}
else
{
v7 = curwp;
v8 = *(_QWORD *)(curwp + 32LL);
if ( *(_QWORD *)(curwp + 24LL) != v8 )
goto LABEL_20;
}
*(_QWORD *)(v7 + 24) = v8;
*(_BYTE *)(v7 + 68) |= 8u;
LABEL_20:
undo_boundary_enable(8LL, 1LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // er12
int v4; // ebp
int i; // ebx
int v6; // eax
__int64 v7; // rcx
__int64 v8; // rdx

result = 0LL;
if ( a2 >= 0 )
{
v3 = a2;
undo_boundary_enable(8LL, 0LL);
if ( a2 )
{
v4 = 0;
do
{
isetmark();
for ( i = 0; ; ++i )
{
v6 = func3(i);
if ( v6 < 0 )
break;
if ( v6 == 10 )
{
result = newline(8LL, 1LL);
if ( !(_DWORD)result )
return result;
++v4;
}
else
{
result = linsert(1LL, (unsigned int)v6);
if ( !(_DWORD)result )
return result;
}
}
--v3;
}
while ( v3 );
v7 = curwp;
v8 = *(_QWORD *)(curwp + 24LL);
if ( *(_QWORD *)(curwp + 32LL) != v8 )
goto LABEL_20;
while ( v4 )
{
--v4;
if ( *(_QWORD *)(v8 + 8) == *(_QWORD *)(curbp + 40LL) )
break;
v8 = *(_QWORD *)(v8 + 8);
}
}
else
{
v7 = curwp;
v8 = *(_QWORD *)(curwp + 32LL);
if ( *(_QWORD *)(curwp + 24LL) != v8 )
goto LABEL_20;
}
*(_QWORD *)(v7 + 24) = v8;
*(_BYTE *)(v7 + 68) |= 8u;
LABEL_20:
undo_boundary_enable(8LL, 1LL);
result = 1LL;
}
return result;
}

original_code:
int
yank(int f, int n)
{
 struct line *lp;
 int c, i, nline;
 if (n < 0)
  return (0);
 nline = 0;
 undo_boundary_enable(8, 0);
 while (n--) {
  isetmark();
  i = 0;
  while ((c = kremove(i)) >= 0) {
   if (c == '\n') {
    if (newline(8, 1) == 0)
     return (0);
    ++nline;
   } else {
    if (linsert(1, c) == 0)
     return (0);
   }
   ++i;
  }
 }
 lp = curwp->w_linep;
 if (curwp->w_dotp == lp) {
  while (nline-- && ((lp)->l_bp) != curbp->b_headp)
   lp = ((lp)->l_bp);
  curwp->w_linep = lp;
  curwp->w_rflag |= 0x08;
 }
 undo_boundary_enable(8, 1);
 return (1);
}

canonical_original_code:
int yank(int f, int n)
{
 struct line *lp;
 int c; int i; int nline;
 if (n < 0)
  return (0);
 nline = 0;
 undo_boundary_enable(8, 0);
 while (n--) {
  isetmark();
  i = 0;
  while ((c = kremove(i)) >= 0) {
   if (c == '\n') {
    if (newline(8, 1) == 0)
     return (0);
    ++nline;
   } else {
    if (linsert(1, c) == 0)
     return (0);
   }
   ++i;
  }
 }
 lp = curwp->w_linep;
 if (curwp->w_dotp == lp) {
  while (nline-- && ((lp)->l_bp) != curbp->b_headp)
   lp = ((lp)->l_bp);
  curwp->w_linep = lp;
  curwp->w_rflag |= 0x08;
 }
 undo_boundary_enable(8, 1);
 return (1);
}

variable_types: nline int


inword

decompiled_code:
__int64 inword()
{
int v0; // edx
__int64 v1; // rcx
__int64 result; // rax

v0 = *(_DWORD *)(curwp + 48LL);
v1 = *(_QWORD *)(curwp + 32LL);
result = 0LL;
if ( v0 != *(_DWORD *)(v1 + 20) )
result = *((_BYTE *)&cinfo + *(unsigned __int8 *)(*(_QWORD *)(v1 + 24) + v0)) & 1;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx
__int64 v1; // rcx
__int64 result; // rax

v0 = *(_DWORD *)(curwp + 48LL);
v1 = *(_QWORD *)(curwp + 32LL);
result = 0LL;
if ( v0 != *(_DWORD *)(v1 + 20) )
result = *((_BYTE *)&cinfo + *(unsigned __int8 *)(*(_QWORD *)(v1 + 24) + v0)) & 1;
return result;
}

original_code:
int
inword(void)
{
 return (curwp->w_doto != ((curwp->w_dotp)->l_used) &&
     ((cinfo[((unsigned char) (curwp->w_dotp->l_text[curwp->w_doto]))]&0x01)!=0));
}

canonical_original_code:
int inword()
{
 return (curwp->w_doto != ((curwp->w_dotp)->l_used) &&
     ((cinfo[((unsigned char) (curwp->w_dotp->l_text[curwp->w_doto]))]&0x01)!=0));
}


forwword

decompiled_code:
__int64 __fastcall forwword(int a1, int a2)
{
int v2; // ebx

if ( a2 < 0 )
return backword(a1 | 8u, (unsigned int)-a2);
if ( !a2 )
return 1LL;
v2 = a2;
while ( 2 )
{
while ( !(unsigned int)inword() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 1LL;
}
do
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 1LL;
}
while ( (unsigned int)inword() );
if ( --v2 )
continue;
break;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // ebx

if ( a2 < 0 )
return func2(a1 | 8u, (unsigned int)-a2);
if ( !a2 )
return 1LL;
v2 = a2;
while ( 2 )
{
while ( !(unsigned int)func0() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 1LL;
}
do
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 1LL;
}
while ( (unsigned int)func0() );
if ( --v2 )
continue;
break;
}
return 1LL;
}

original_code:
int
forwword(int f, int n)
{
 if (n < 0)
  return (backword(f | 8, -n));
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
  while (inword() != 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
 }
 return (1);
}

variable_types: f int


backword

decompiled_code:
__int64 __fastcall backword(int a1, int a2)
{
int v2; // ebx
__int64 result; // rax

v2 = a2;
if ( a2 < 0 )
return forwword(a1 | 8u, -a2);
result = backchar(8LL, 1LL);
if ( (_DWORD)result )
{
if ( a2 )
{
while ( 2 )
{
while ( !(unsigned int)inword() )
{
if ( !(unsigned int)backchar(8LL, 1LL) )
return 1LL;
}
do
{
if ( !(unsigned int)backchar(8LL, 1LL) )
return 1LL;
}
while ( (unsigned int)inword() );
if ( --v2 )
continue;
break;
}
}
result = forwchar(8LL, 1LL);
}
return result;
}

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

v2 = a2;
if ( a2 < 0 )
return func1(a1 | 8u, -a2);
result = backchar(8LL, 1LL);
if ( (_DWORD)result )
{
if ( a2 )
{
while ( 2 )
{
while ( !(unsigned int)func0() )
{
if ( !(unsigned int)backchar(8LL, 1LL) )
return 1LL;
}
do
{
if ( !(unsigned int)backchar(8LL, 1LL) )
return 1LL;
}
while ( (unsigned int)func0() );
if ( --v2 )
continue;
break;
}
}
result = forwchar(8LL, 1LL);
}
return result;
}

original_code:
int
backword(int f, int n)
{
 if (n < 0)
  return (forwword(f | 8, -n));
 if (backchar(8, 1) == 0)
  return (0);
 while (n--) {
  while (inword() == 0) {
   if (backchar(8, 1) == 0)
    return (1);
  }
  while (inword() != 0) {
   if (backchar(8, 1) == 0)
    return (1);
  }
 }
 return (forwchar(8, 1));
}

variable_types: n int


countfword

decompiled_code:
__int64 countfword()
{
__int64 v0; // rbp
int v1; // er12
unsigned int v2; // ebx
__int64 v3; // rax

v0 = *(_QWORD *)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = 0;
while ( (unsigned int)inword() && (unsigned int)forwchar(8LL, 1LL) )
++v2;
v3 = curwp;
*(_QWORD *)(curwp + 32LL) = v0;
*(_DWORD *)(v3 + 48) = v1;
return v2;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
int v1; // er12
unsigned int v2; // ebx
__int64 v3; // rax

v0 = *(_QWORD *)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = 0;
while ( (unsigned int)func0() && (unsigned int)forwchar(8LL, 1LL) )
++v2;
v3 = curwp;
*(_QWORD *)(curwp + 32LL) = v0;
*(_DWORD *)(v3 + 48) = v1;
return v2;
}

original_code:
RSIZE
countfword()
{
 RSIZE size;
 struct line *dotp;
 int doto;
 dotp = curwp->w_dotp;
 doto = curwp->w_doto;
 size = 0;
 while (inword() != 0) {
  if (forwchar(8, 1) == 0)
   goto out;
  ++size;
 }
out:
 curwp->w_dotp = dotp;
 curwp->w_doto = doto;
 return (size);
}

canonical_original_code:
int countfword()
{
 int size;
 struct line *dotp;
 int doto;
 dotp = curwp->w_dotp;
 doto = curwp->w_doto;
 size = 0;
 while (inword() != 0) {
  if (forwchar(8, 1) == 0)
   goto out;
  ++size;
 }
out:
 curwp->w_dotp = dotp;
 curwp->w_doto = doto;
 return (size);
}

variable_types: size int

variable_types: doto int


upperword

decompiled_code:
__int64 __fastcall upperword(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx
unsigned int v5; // eax
_BYTE *v6; // rax

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else if ( a2 )
{
do
{
while ( !(unsigned int)inword() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
v5 = countfword();
undo_add_change(*(_QWORD *)(curwp + 32LL), *(unsigned int *)(curwp + 48LL), v5);
while ( (unsigned int)inword() )
{
v6 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v6) & 4) != 0 )
{
*v6 -= 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
--v2;
}
while ( v2 );
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx
unsigned int v5; // eax
_BYTE *v6; // rax

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else if ( a2 )
{
do
{
while ( !(unsigned int)func0() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
v5 = func3();
undo_add_change(*(_QWORD *)(curwp + 32LL), *(unsigned int *)(curwp + 48LL), v5);
while ( (unsigned int)func0() )
{
v6 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v6) & 4) != 0 )
{
*v6 -= 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
--v2;
}
while ( v2 );
}
}
return v3;
}

original_code:
int
upperword(int f, int n)
{
 int c, s;
 RSIZE size;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
  size = countfword();
  undo_add_change(curwp->w_dotp, curwp->w_doto, size);
  while (inword() != 0) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
   if (((cinfo[((unsigned char) (c))]&0x04)!=0) != 0) {
    c = ((c)-0x20);
    ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
    lchange(0x08);
   }
   if (forwchar(8, 1) == 0)
    return (1);
  }
 }
 return (1);
}

canonical_original_code:
int upperword(int f, int n)
{
 int c; int s;
 int size;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
  size = countfword();
  undo_add_change(curwp->w_dotp, curwp->w_doto, size);
  while (inword() != 0) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
   if (((cinfo[((unsigned char) (c))]&0x04)!=0) != 0) {
    c = ((c)-0x20);
    ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
    lchange(0x08);
   }
   if (forwchar(8, 1) == 0)
    return (1);
  }
 }
 return (1);
}

variable_types: s int


lowerword

decompiled_code:
__int64 __fastcall lowerword(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx
unsigned int v5; // eax
_BYTE *v6; // rax

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else if ( a2 )
{
do
{
while ( !(unsigned int)inword() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
v5 = countfword();
undo_add_change(*(_QWORD *)(curwp + 32LL), *(unsigned int *)(curwp + 48LL), v5);
while ( (unsigned int)inword() )
{
v6 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v6) & 2) != 0 )
{
*v6 += 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
--v2;
}
while ( v2 );
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx
unsigned int v5; // eax
_BYTE *v6; // rax

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else if ( a2 )
{
do
{
while ( !(unsigned int)func0() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
v5 = func3();
undo_add_change(*(_QWORD *)(curwp + 32LL), *(unsigned int *)(curwp + 48LL), v5);
while ( (unsigned int)func0() )
{
v6 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v6) & 2) != 0 )
{
*v6 += 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
--v2;
}
while ( v2 );
}
}
return v3;
}

original_code:
int
lowerword(int f, int n)
{
 int c, s;
 RSIZE size;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
  size = countfword();
  undo_add_change(curwp->w_dotp, curwp->w_doto, size);
  while (inword() != 0) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
   if (((cinfo[((unsigned char) (c))]&0x02)!=0) != 0) {
    c = ((c)+0x20);
    ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
    lchange(0x08);
   }
   if (forwchar(8, 1) == 0)
    return (1);
  }
 }
 return (1);
}

canonical_original_code:
int lowerword(int f, int n)
{
 int c; int s;
 int size;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
  size = countfword();
  undo_add_change(curwp->w_dotp, curwp->w_doto, size);
  while (inword() != 0) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
   if (((cinfo[((unsigned char) (c))]&0x02)!=0) != 0) {
    c = ((c)+0x20);
    ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
    lchange(0x08);
   }
   if (forwchar(8, 1) == 0)
    return (1);
  }
 }
 return (1);
}


capword

decompiled_code:
__int64 __fastcall capword(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx
unsigned int v5; // eax
_BYTE *v6; // rax
_BYTE *v7; // rax

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else if ( a2 )
{
do
{
while ( !(unsigned int)inword() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
v5 = countfword();
undo_add_change(*(_QWORD *)(curwp + 32LL), *(unsigned int *)(curwp + 48LL), v5);
if ( (unsigned int)inword() )
{
v6 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v6) & 4) != 0 )
{
*v6 -= 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
while ( (unsigned int)inword() )
{
v7 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v7) & 2) != 0 )
{
*v7 += 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
}
--v2;
}
while ( v2 );
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx
unsigned int v5; // eax
_BYTE *v6; // rax
_BYTE *v7; // rax

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else if ( a2 )
{
do
{
while ( !(unsigned int)func0() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
v5 = func3();
undo_add_change(*(_QWORD *)(curwp + 32LL), *(unsigned int *)(curwp + 48LL), v5);
if ( (unsigned int)func0() )
{
v6 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v6) & 4) != 0 )
{
*v6 -= 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
while ( (unsigned int)func0() )
{
v7 = (_BYTE *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + *(int *)(curwp + 48LL));
if ( (*((_BYTE *)&cinfo + (unsigned __int8)*v7) & 2) != 0 )
{
*v7 += 32;
lchange(8LL);
}
if ( !(unsigned int)forwchar(8LL, 1LL) )
return v3;
}
}
--v2;
}
while ( v2 );
}
}
return v3;
}

original_code:
int
capword(int f, int n)
{
 int c, s;
 RSIZE size;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
  size = countfword();
  undo_add_change(curwp->w_dotp, curwp->w_doto, size);
  if (inword() != 0) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
   if (((cinfo[((unsigned char) (c))]&0x04)!=0) != 0) {
    c = ((c)-0x20);
    ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
    lchange(0x08);
   }
   if (forwchar(8, 1) == 0)
    return (1);
   while (inword() != 0) {
    c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
    if (((cinfo[((unsigned char) (c))]&0x02)!=0) != 0) {
     c = ((c)+0x20);
     ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
     lchange(0x08);
    }
    if (forwchar(8, 1) == 0)
     return (1);
   }
  }
 }
 return (1);
}

canonical_original_code:
int capword(int f, int n)
{
 int c; int s;
 int size;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    return (1);
  }
  size = countfword();
  undo_add_change(curwp->w_dotp, curwp->w_doto, size);
  if (inword() != 0) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
   if (((cinfo[((unsigned char) (c))]&0x04)!=0) != 0) {
    c = ((c)-0x20);
    ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
    lchange(0x08);
   }
   if (forwchar(8, 1) == 0)
    return (1);
   while (inword() != 0) {
    c = (((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])));
    if (((cinfo[((unsigned char) (c))]&0x02)!=0) != 0) {
     c = ((c)+0x20);
     ((curwp->w_dotp)->l_text[(curwp->w_doto)]=(c));
     lchange(0x08);
    }
    if (forwchar(8, 1) == 0)
     return (1);
   }
  }
 }
 return (1);
}


delfword

decompiled_code:
__int64 __fastcall delfword(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 result; // rax
__int64 v4; // r12
int v5; // ebp
int v6; // er13
__int64 v7; // rax

v2 = a2;
result = checkdirty(curbp);
if ( (_DWORD)result == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
result = 0LL;
}
else
{
result = 0LL;
if ( a2 >= 0 )
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
v4 = *(_QWORD *)(curwp + 32LL);
v5 = *(_DWORD *)(curwp + 48LL);
if ( a2 )
{
v6 = a2;
v2 = 0;
LABEL_8:
while ( !(unsigned int)inword() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
goto LABEL_15;
++v2;
}
while ( (unsigned int)forwchar(8LL, 1LL) )
{
++v2;
if ( !(unsigned int)inword() )
{
if ( --v6 )
goto LABEL_8;
break;
}
}
}
LABEL_15:
v7 = curwp;
*(_QWORD *)(curwp + 32LL) = v4;
*(_DWORD *)(v7 + 48) = v5;
result = ldelete(v2, 1LL);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 result; // rax
__int64 v4; // r12
int v5; // ebp
int v6; // er13
__int64 v7; // rax

v2 = a2;
result = checkdirty(curbp);
if ( (_DWORD)result == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
result = 0LL;
}
else
{
result = 0LL;
if ( a2 >= 0 )
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
v4 = *(_QWORD *)(curwp + 32LL);
v5 = *(_DWORD *)(curwp + 48LL);
if ( a2 )
{
v6 = a2;
v2 = 0;
LABEL_8:
while ( !(unsigned int)func0() )
{
if ( !(unsigned int)forwchar(8LL, 1LL) )
goto LABEL_15;
++v2;
}
while ( (unsigned int)forwchar(8LL, 1LL) )
{
++v2;
if ( !(unsigned int)func0() )
{
if ( --v6 )
goto LABEL_8;
break;
}
}
}
LABEL_15:
v7 = curwp;
*(_QWORD *)(curwp + 32LL) = v4;
*(_DWORD *)(v7 + 48) = v5;
result = ldelete(v2, 1LL);
}
}
}
return result;
}

original_code:
int
delfword(int f, int n)
{
 RSIZE size;
 struct line *dotp;
 int doto;
 int s;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 if ((lastflag & 0x0002) == 0)
  kdelete();
 thisflag |= 0x0002;
 dotp = curwp->w_dotp;
 doto = curwp->w_doto;
 size = 0;
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    goto out;
   ++size;
  }
  while (inword() != 0) {
   if (forwchar(8, 1) == 0)
    goto out;
   ++size;
  }
 }
out:
 curwp->w_dotp = dotp;
 curwp->w_doto = doto;
 return (ldelete(size, 0x01));
}

canonical_original_code:
int delfword(int f, int n)
{
 int size;
 struct line *dotp;
 int doto;
 int s;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 if ((lastflag & 0x0002) == 0)
  kdelete();
 thisflag |= 0x0002;
 dotp = curwp->w_dotp;
 doto = curwp->w_doto;
 size = 0;
 while (n--) {
  while (inword() == 0) {
   if (forwchar(8, 1) == 0)
    goto out;
   ++size;
  }
  while (inword() != 0) {
   if (forwchar(8, 1) == 0)
    goto out;
   ++size;
  }
 }
out:
 curwp->w_dotp = dotp;
 curwp->w_doto = doto;
 return (ldelete(size, 0x01));
}


delbword

decompiled_code:
__int64 __fastcall delbword(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
if ( (unsigned int)backchar(8LL, 1LL) )
{
if ( a2 )
{
LABEL_8:
while ( !(unsigned int)inword() )
{
if ( !(unsigned int)backchar(8LL, 1LL) )
goto LABEL_17;
++v3;
}
while ( (unsigned int)backchar(8LL, 1LL) )
{
++v3;
if ( !(unsigned int)inword() )
{
if ( --v2 )
goto LABEL_8;
goto LABEL_15;
}
}
}
else
{
LABEL_15:
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 0;
--v3;
}
LABEL_17:
v3 = ldelete(v3, 2LL);
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
int v2; // ebp
unsigned int v3; // ebx

v2 = a2;
v3 = checkdirty(curbp);
if ( v3 == 1 )
{
if ( (*(_BYTE *)(curbp + 91LL) & 0x10) != 0 )
{
dobeep();
ewprintf("Buffer is read-only");
v3 = 0;
}
else if ( a2 < 0 )
{
v3 = 0;
}
else
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
if ( (unsigned int)backchar(8LL, 1LL) )
{
if ( a2 )
{
LABEL_8:
while ( !(unsigned int)func0() )
{
if ( !(unsigned int)backchar(8LL, 1LL) )
goto LABEL_17;
++v3;
}
while ( (unsigned int)backchar(8LL, 1LL) )
{
++v3;
if ( !(unsigned int)func0() )
{
if ( --v2 )
goto LABEL_8;
goto LABEL_15;
}
}
}
else
{
LABEL_15:
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 0;
--v3;
}
LABEL_17:
v3 = ldelete(v3, 2LL);
}
}
}
return v3;
}

original_code:
int
delbword(int f, int n)
{
 RSIZE size;
 int s;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 if ((lastflag & 0x0002) == 0)
  kdelete();
 thisflag |= 0x0002;
 if (backchar(8, 1) == 0)
  return (1);
 size = 1;
 while (n--) {
  while (inword() == 0) {
   if (backchar(8, 1) == 0)
    goto out;
   ++size;
  }
  while (inword() != 0) {
   if (backchar(8, 1) == 0)
    goto out;
   ++size;
  }
 }
 if (forwchar(8, 1) == 0)
  return (0);
 --size;
out:
 return (ldelete(size, 0x02));
}

canonical_original_code:
int delbword(int f, int n)
{
 int size;
 int s;
 if ((s = checkdirty(curbp)) != 1)
  return (s);
 if (curbp->b_flag & 0x10) {
  dobeep();
  ewprintf("Buffer is read-only");
  return (0);
 }
 if (n < 0)
  return (0);
 if ((lastflag & 0x0002) == 0)
  kdelete();
 thisflag |= 0x0002;
 if (backchar(8, 1) == 0)
  return (1);
 size = 1;
 while (n--) {
  while (inword() == 0) {
   if (backchar(8, 1) == 0)
    goto out;
   ++size;
  }
  while (inword() != 0) {
   if (backchar(8, 1) == 0)
    goto out;
   ++size;
  }
 }
 if (forwchar(8, 1) == 0)
  return (0);
 --size;
out:
 return (ldelete(size, 0x02));
}


decompiled_code:
__int64 re_readpattern()
{
_BYTE *v0; // rax
__int64 result; // rax
int v2; // ebx
int v3; // eax
char v4[256]; // [rsp+0h] [rbp-158h] BYREF
char v5[88]; // [rsp+100h] [rbp-58h] BYREF

if ( re_pat )
v0 = (_BYTE *)eread("%s: (default %s) ", v5, &loc_50);
else
v0 = (_BYTE *)eread("%s: ", v5);
if ( !v0 )
return 2LL;
if ( !*v0 )
return re_pat != 0;
strlcpy(&re_pat, v5, 80LL);
v2 = casefoldsearch == 0 ? 1 : 3;
if ( dofree_0 )
regfree(&regex_buff);
v3 = regcomp(&regex_buff, &re_pat, v2);
if ( v3 )
{
regerror(v3, &regex_buff, v4, 0x100uLL);
dobeep();
ewprintf("Regex Error: %s", v4);
re_pat = 0;
result = 0LL;
}
else
{
dofree_0 = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
_BYTE *v0; // rax
__int64 result; // rax
int v2; // ebx
int v3; // eax
char v4[256]; // [rsp+0h] [rbp-158h] BYREF
char v5[88]; // [rsp+100h] [rbp-58h] BYREF

if ( re_pat )
v0 = (_BYTE *)eread("%s: (default %s) ", v5, &loc_50);
else
v0 = (_BYTE *)eread("%s: ", v5);
if ( !v0 )
return 2LL;
if ( !*v0 )
return re_pat != 0;
strlcpy(&re_pat, v5, 80LL);
v2 = casefoldsearch == 0 ? 1 : 3;
if ( dofree_0 )
regfree(&regex_buff);
v3 = regcomp(&regex_buff, &re_pat, v2);
if ( v3 )
{
regerror(v3, &regex_buff, v4, 0x100uLL);
dobeep();
ewprintf("Regex Error: %s", v4);
re_pat = 0;
result = 0LL;
}
else
{
dofree_0 = 1;
result = 1LL;
}
return result;
}

original_code:
static int
re_readpattern(char *prompt)
{
 static int dofree = 0;
 int flags, error, s;
 char tpat[80], *rep;
 if (re_pat[0] == '\0')
  rep = eread("%s: ", tpat, 80, 0x0008 | 0x0010, prompt);
 else
  rep = eread("%s: (default %s) ", tpat, 80,
      0x0040 | 0x0008 | 0x0010, prompt, re_pat);
 if (rep == ((void *)0))
  return (2);
 if (rep[0] != '\0') {
  (void)strlcpy(re_pat, tpat, sizeof(re_pat));
  if (casefoldsearch)
   flags = 1 | (1 << 1);
  else
   flags = 1;
  if (dofree)
   regfree(&regex_buff);
  error = regcomp(&regex_buff, re_pat, flags);
  if (error != 0) {
   char message[256];
   regerror(error, &regex_buff, message, sizeof(message));
   dobeep();
   ewprintf("Regex Error: %s", message);
   re_pat[0] = '\0';
   return (0);
  }
  dofree = 1;
  s = 1;
 } else if (rep[0] == '\0' && re_pat[0] != '\0')
  s = 1;
 else
  s = 0;
 return (s);
}

canonical_original_code:
static int re_readpattern(char *prompt)
{
 static int dofree = 0;
 int flags; int error; int s;
 char tpat[80]; char *rep;
 if (re_pat[0] == '\0')
  rep = eread("%s: ", tpat, 80, 0x0008 | 0x0010, prompt);
 else
  rep = eread("%s: (default %s) ", tpat, 80,
      0x0040 | 0x0008 | 0x0010, prompt, re_pat);
 if (rep == ((void *)0))
  return (2);
 if (rep[0] != '\0') {
  (void)strlcpy(re_pat, tpat, sizeof(re_pat));
  if (casefoldsearch)
   flags = 1 | (1 << 1);
  else
   flags = 1;
  if (dofree)
   regfree(&regex_buff);
  error = regcomp(&regex_buff, re_pat, flags);
  if (error != 0) {
   char message[256];
   regerror(error, &regex_buff, message, sizeof(message));
   dobeep();
   ewprintf("Regex Error: %s", message);
   re_pat[0] = '\0';
   return (0);
  }
  dofree = 1;
  s = 1;
 } else if (rep[0] == '\0' && re_pat[0] != '\0')
  s = 1;
 else
  s = 0;
 return (s);
}

variable_types:
prompt
char *

variable_types: dofree int

variable_types: flags int

variable_types: error int

variable_types:
tpat
char [80]

variable_types:
rep
char *

variable_types:
message
char [256]