dirinit

decompiled_code:
int dirinit()
{
char *v0; // rax

mgcwd = 0;
v0 = getcwd(&mgcwd, 0x400uLL);
if ( !v0 )
{
ewprintf("Can't get current directory!");
LODWORD(v0) = chdir("/");
}
if ( mgcwd != 47 || byte_481 )
LODWORD(v0) = strlcat(&mgcwd, "/", 1024LL);
return (int)v0;
}

canonical_decompiled_code:
int func0()
{
char *v0; // rax

mgcwd = 0;
v0 = getcwd(&mgcwd, 0x400uLL);
if ( !v0 )
{
ewprintf("Can't get current directory!");
LODWORD(v0) = chdir("/");
}
if ( mgcwd != 47 || byte_481 )
LODWORD(v0) = strlcat(&mgcwd, "/", 1024LL);
return (int)v0;
}

original_code:
void
dirinit(void)
{
 mgcwd[0] = '\0';
 if (getcwd(mgcwd, sizeof(mgcwd)) == ((void *)0)) {
  ewprintf("Can't get current directory!");
  chdir("/");
 }
 if (!(mgcwd[0] == '/' && mgcwd [1] == '\0'))
  (void)strlcat(mgcwd, "/", sizeof(mgcwd));
}

canonical_original_code:
void dirinit()
{
 mgcwd[0] = '\0';
 if (getcwd(mgcwd, sizeof(mgcwd)) == ((void *)0)) {
  ewprintf("Can't get current directory!");
  chdir("/");
 }
 if (!(mgcwd[0] == '/' && mgcwd [1] == '\0'))
  (void)strlcat(mgcwd, "/", sizeof(mgcwd));
}


changedir

repo: scott-parker/mg-openbsd

decompiled_code:
__int64 changedir()
{
_BYTE *v0; // rax
char *v2; // r12
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

strlcpy(v3, &mgcwd, 1024LL);
v0 = (_BYTE *)eread("Change default directory: ", v3, 1024LL, 60LL);
if ( !v0 )
return 2LL;
if ( !*v0 )
return 0LL;
if ( chdir(v3) == -1 )
{
dobeep();
ewprintf("Can't change dir to %s", v3);
return 0LL;
}
v2 = getcwd(&mgcwd, 0x400uLL);
if ( !v2 )
panic("Can't get current directory!");
if ( byte_47F[strlen(&mgcwd)] != 47 )
strlcat(&mgcwd, "/", 1024LL);
ewprintf("Current directory is now %s", v2);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
_BYTE *v0; // rax
char *v2; // r12
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

strlcpy(v3, &mgcwd, 1024LL);
v0 = (_BYTE *)eread("Change default directory: ", v3, 1024LL, 60LL);
if ( !v0 )
return 2LL;
if ( !*v0 )
return 0LL;
if ( chdir(v3) == -1 )
{
dobeep();
ewprintf("Can't change dir to %s", v3);
return 0LL;
}
v2 = getcwd(&mgcwd, 0x400uLL);
if ( !v2 )
panic("Can't get current directory!");
if ( byte_47F[strlen(&mgcwd)] != 47 )
strlcat(&mgcwd, "/", 1024LL);
ewprintf("Current directory is now %s", v2);
return 1LL;
}

original_code:
int
changedir(int f, int n)
{
 char bufc[1024], *bufp;
 (void)strlcpy(bufc, mgcwd, sizeof(bufc));
 if ((bufp = eread("Change default directory: ", bufc, 1024,
     0x0020 | 0x0008 | 0x0010 | 0x0004)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if (chdir(bufc) == -1) {
  dobeep();
  ewprintf("Can't change dir to %s", bufc);
  return (0);
 }
 if ((bufp = getcwd(mgcwd, sizeof(mgcwd))) == ((void *)0))
  panic("Can't get current directory!");
 if (mgcwd[strlen(mgcwd) - 1] != '/')
  (void)strlcat(mgcwd, "/", sizeof(mgcwd));
 ewprintf("Current directory is now %s", bufp);
 return (1);
}

canonical_original_code:
int changedir(int f, int n)
{
 char bufc[1024]; char *bufp;
 (void)strlcpy(bufc, mgcwd, sizeof(bufc));
 if ((bufp = eread("Change default directory: ", bufc, 1024,
     0x0020 | 0x0008 | 0x0010 | 0x0004)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if (chdir(bufc) == -1) {
  dobeep();
  ewprintf("Can't change dir to %s", bufc);
  return (0);
 }
 if ((bufp = getcwd(mgcwd, sizeof(mgcwd))) == ((void *)0))
  panic("Can't get current directory!");
 if (mgcwd[strlen(mgcwd) - 1] != '/')
  (void)strlcat(mgcwd, "/", sizeof(mgcwd));
 ewprintf("Current directory is now %s", bufp);
 return (1);
}

variable_types: f int

variable_types: n int

variable_types:
bufc
char [1024]

variable_types:
bufp
char *

return_type: int


showcwdir

decompiled_code:
__int64 showcwdir()
{
ewprintf("Current directory: %s", &mgcwd);
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
ewprintf("Current directory: %s", &mgcwd);
return 1LL;
}

original_code:
int
showcwdir(int f, int n)
{
 ewprintf("Current directory: %s", mgcwd);
 return (1);
}


getcwdir

decompiled_code:
_BOOL8 __fastcall getcwdir(__int64 a1, unsigned __int64 a2)
{
return strlcpy(a1, &mgcwd, a2) < a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
return strlcpy(a1, &mgcwd, a2) < a2;
}

original_code:
int
getcwdir(char *buf, size_t len)
{
 if (strlcpy(buf, mgcwd, len) >= len)
  return (0);
 return (1);
}

canonical_original_code:
int getcwdir(char *buf, unsigned long len)
{
 if (strlcpy(buf, mgcwd, len) >= len)
  return (0);
 return (1);
}

variable_types:
buf
char *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall do_makedir(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbp
const char *v3; // rax
char *v4; // rbx
int v5; // er13
const char *v6; // rbx
char v7; // r14
int v8; // er15
__int64 result; // rax
__mode_t mask; // [rsp+Ch] [rbp-CCh]
struct stat v11; // [rsp+10h] [rbp-C8h] BYREF

v1 = (const char *)adjustname(a1, 1LL);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = &v1[strlen(v1) - 1];
if ( v2 < v3 )
{
do
{
if ( *v3 != 47 )
break;
*v3-- = 0;
}
while ( v2 != v3 );
}
v4 = (char *)v2;
mask = umask(0);
v5 = ~(_WORD)mask & 0x1FF;
LOBYTE(v5) = ~(_BYTE)mask | 0xC0;
while ( 1 )
{
v6 = &v4[strspn(v4, "/")];
v4 = (char *)&v6[strcspn(v6, "/")];
v7 = *v4;
*v4 = 0;
v8 = stat(v2, &v11);
if ( !v7 )
break;
if ( v8 )
{
if ( mkdir(v2, v5) )
goto LABEL_23;
}
else if ( (v11.st_mode & 0xF000) != 0x4000 && mkdir(v2, v5) && (v11.st_mode & 0xF000) != 0x4000 )
{
eerase();
LABEL_17:
umask(mask);
return 0LL;
}
*v4 = 47;
}
if ( v8 )
{
if ( mkdir(v2, ~(_WORD)mask & 0x1FF) )
{
LABEL_23:
dobeep();
ewprintf("Creating directory: permission denied, %s", v2);
goto LABEL_17;
}
eerase();
umask(mask);
result = 1LL;
}
else
{
dobeep();
ewprintf("Cannot create directory %s: file exists", v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbp
const char *v3; // rax
char *v4; // rbx
int v5; // er13
const char *v6; // rbx
char v7; // r14
int v8; // er15
__int64 result; // rax
__mode_t mask; // [rsp+Ch] [rbp-CCh]
struct stat v11; // [rsp+10h] [rbp-C8h] BYREF

v1 = (const char *)adjustname(a1, 1LL);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = &v1[strlen(v1) - 1];
if ( v2 < v3 )
{
do
{
if ( *v3 != 47 )
break;
*v3-- = 0;
}
while ( v2 != v3 );
}
v4 = (char *)v2;
mask = umask(0);
v5 = ~(_WORD)mask & 0x1FF;
LOBYTE(v5) = ~(_BYTE)mask | 0xC0;
while ( 1 )
{
v6 = &v4[strspn(v4, "/")];
v4 = (char *)&v6[strcspn(v6, "/")];
v7 = *v4;
*v4 = 0;
v8 = stat(v2, &v11);
if ( !v7 )
break;
if ( v8 )
{
if ( mkdir(v2, v5) )
goto LABEL_23;
}
else if ( (v11.st_mode & 0xF000) != 0x4000 && mkdir(v2, v5) && (v11.st_mode & 0xF000) != 0x4000 )
{
eerase();
LABEL_17:
umask(mask);
return 0LL;
}
*v4 = 47;
}
if ( v8 )
{
if ( mkdir(v2, ~(_WORD)mask & 0x1FF) )
{
LABEL_23:
dobeep();
ewprintf("Creating directory: permission denied, %s", v2);
goto LABEL_17;
}
eerase();
umask(mask);
result = 1LL;
}
else
{
dobeep();
ewprintf("Cannot create directory %s: file exists", v2);
result = 0LL;
}
return result;
}

original_code:
int
do_makedir(char *path)
{
 struct stat sb;
 int finished, ishere;
 mode_t dir_mode, mode, oumask;
 char *slash;
 if ((path = adjustname(path, 1)) == ((void *)0))
  return (0);
 slash = strrchr(path, '\0');
 while (--slash > path && *slash == '/')
  *slash = '\0';
 slash = path;
 oumask = umask(0);
 mode = 0777 & ~oumask;
 dir_mode = mode | 0200 | 0100;
 for (;;) {
  slash += strspn(slash, "/");
  slash += strcspn(slash, "/");
  finished = (*slash == '\0');
  *slash = '\0';
  ishere = !stat(path, &sb);
  if (finished && ishere) {
   dobeep();
   ewprintf("Cannot create directory %s: file exists",
        path);
   return(0);
  } else if (!finished && ishere && ((((sb.st_mode)) & 0170000) == (0040000))) {
   *slash = '/';
   continue;
  }
  if (mkdir(path, finished ? mode : dir_mode) == 0) {
   if (mode > 0777 && chmod(path, mode) < 0) {
    umask(oumask);
    return (2);
   }
  } else {
   if (!ishere || !((((sb.st_mode)) & 0170000) == (0040000))) {
    if (!ishere) {
     dobeep();
     ewprintf("Creating directory: "
         "permission denied, %s", path);
    } else
     eerase();
    umask(oumask);
    return (0);
   }
  }
  if (finished)
   break;
  *slash = '/';
 }
 eerase();
 umask(oumask);
 return (1);
}

canonical_original_code:
int do_makedir(char *path)
{
 struct stat sb;
 int finished; int ishere;
 unsigned int dir_mode; unsigned int mode; unsigned int oumask;
 char *slash;
 if ((path = adjustname(path, 1)) == ((void *)0))
  return (0);
 slash = strrchr(path, '\0');
 while (--slash > path && *slash == '/')
  *slash = '\0';
 slash = path;
 oumask = umask(0);
 mode = 0777 & ~oumask;
 dir_mode = mode | 0200 | 0100;
 for (;;) {
  slash += strspn(slash, "/");
  slash += strcspn(slash, "/");
  finished = (*slash == '\0');
  *slash = '\0';
  ishere = !stat(path, &sb);
  if (finished && ishere) {
   dobeep();
   ewprintf("Cannot create directory %s: file exists",
        path);
   return(0);
  } else if (!finished && ishere && ((((sb.st_mode)) & 0170000) == (0040000))) {
   *slash = '/';
   continue;
  }
  if (mkdir(path, finished ? mode : dir_mode) == 0) {
   if (mode > 0777 && chmod(path, mode) < 0) {
    umask(oumask);
    return (2);
   }
  } else {
   if (!ishere || !((((sb.st_mode)) & 0170000) == (0040000))) {
    if (!ishere) {
     dobeep();
     ewprintf("Creating directory: "
         "permission denied, %s", path);
    } else
     eerase();
    umask(oumask);
    return (0);
   }
  }
  if (finished)
   break;
  *slash = '/';
 }
 eerase();
 umask(oumask);
 return (1);
}

variable_types:
path
char *

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

variable_types: finished int

variable_types: ishere int

variable_types:
mode
unsigned int

variable_types:
oumask
unsigned int

variable_types:
slash
char *

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


decompiled_code:
__int64 ask_makedir()
{
__int64 result; // rax
_BYTE *v1; // rdi
_BYTE v2[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( (unsigned int)getbufcwd(v2, 1024LL) != 1 )
return 2LL;
v1 = (_BYTE *)eread("Make directory: ", v2, 1024LL, 60LL);
if ( !v1 )
return 2LL;
result = 0LL;
if ( *v1 )
result = do_makedir((__int64)v1);
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
_BYTE *v1; // rdi
_BYTE v2[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( (unsigned int)getbufcwd(v2, 1024LL) != 1 )
return 2LL;
v1 = (_BYTE *)eread("Make directory: ", v2, 1024LL, 60LL);
if ( !v1 )
return 2LL;
result = 0LL;
if ( *v1 )
result = func4((__int64)v1);
return result;
}

original_code:
int
ask_makedir(void)
{
 char bufc[1024];
 char *path;
 if (getbufcwd(bufc, sizeof(bufc)) != 1)
  return (2);
 if ((path = eread("Make directory: ", bufc, 1024,
     0x0020 | 0x0008 | 0x0010 | 0x0004)) == ((void *)0))
  return (2);
 else if (path[0] == '\0')
  return (0);
 return (do_makedir(path));
}

canonical_original_code:
int ask_makedir()
{
 char bufc[1024];
 char *path;
 if (getbufcwd(bufc, sizeof(bufc)) != 1)
  return (2);
 if ((path = eread("Make directory: ", bufc, 1024,
     0x0020 | 0x0008 | 0x0010 | 0x0004)) == ((void *)0))
  return (2);
 else if (path[0] == '\0')
  return (0);
 return (do_makedir(path));
}


makedir

decompiled_code:
// attributes: thunk
__int64 makedir()
{
return ask_makedir();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

original_code:
int
makedir(int f, int n)
{
 return (ask_makedir());
}


changemode

decompiled_code:
__int64 __fastcall changemode(char a1, int a2, const char *a3)
{
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // rdx
int v7; // ecx
__int16 v8; // r12
__int64 v9; // rax
__int64 result; // rax
__int64 v11; // rax
__int16 v12; // r12

v4 = name_mode(a3);
if ( !v4 )
{
dobeep();
ewprintf("Can't find mode %s", a3);
return 0LL;
}
v5 = curbp;
v6 = v4;
v7 = *(__int16 *)(curbp + 88LL);
v8 = *(_WORD *)(curbp + 88LL);
if ( (a1 & 7) != 0 )
{
if ( a2 <= 0 )
goto LABEL_7;
if ( v7 >= 0 )
{
LABEL_16:
v11 = 0LL;
while ( *(_QWORD *)(curbp + 8 * v11 + 48) != v6 )
{
if ( v7 < (int)++v11 )
{
if ( v8 <= 2 )
goto LABEL_21;
dobeep();
ewprintf("Too many modes");
return 0LL;
}
}
return 1LL;
}
LABEL_21:
v12 = v8 + 1;
*(_WORD *)(curbp + 88LL) = v12;
*(_QWORD *)(v5 + 8LL * v12 + 48) = v6;
LABEL_22:
upmodes(v5);
return 1LL;
}
if ( v7 < 0 )
{
if ( a2 <= 0 )
return 1LL;
goto LABEL_21;
}
v9 = 0LL;
while ( *(_QWORD *)(curbp + 8 * v9 + 48) != v6 )
{
if ( v7 < (int)++v9 )
{
if ( a2 > 0 )
goto LABEL_16;
break;
}
}
LABEL_7:
result = 1LL;
if ( v7 > 0 )
{
while ( *(_QWORD *)(curbp + 8 * result + 48) != v6 )
{
if ( v7 < (int)++result )
return 1LL;
}
if ( (int)result < v7 )
memmove(
(void *)(curbp + 8LL * ((int)result + 6)),
(const void *)(curbp + 8LL * ((int)result + 6) + 8),
8LL * (unsigned int)(v7 - 1 - result) + 8);
*(_WORD *)(v5 + 88) = v8 - 1;
goto LABEL_22;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2, const char *a3)
{
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // rdx
int v7; // ecx
__int16 v8; // r12
__int64 v9; // rax
__int64 result; // rax
__int64 v11; // rax
__int16 v12; // r12

v4 = name_mode(a3);
if ( !v4 )
{
dobeep();
ewprintf("Can't find mode %s", a3);
return 0LL;
}
v5 = curbp;
v6 = v4;
v7 = *(__int16 *)(curbp + 88LL);
v8 = *(_WORD *)(curbp + 88LL);
if ( (a1 & 7) != 0 )
{
if ( a2 <= 0 )
goto LABEL_7;
if ( v7 >= 0 )
{
LABEL_16:
v11 = 0LL;
while ( *(_QWORD *)(curbp + 8 * v11 + 48) != v6 )
{
if ( v7 < (int)++v11 )
{
if ( v8 <= 2 )
goto LABEL_21;
dobeep();
ewprintf("Too many modes");
return 0LL;
}
}
return 1LL;
}
LABEL_21:
v12 = v8 + 1;
*(_WORD *)(curbp + 88LL) = v12;
*(_QWORD *)(v5 + 8LL * v12 + 48) = v6;
LABEL_22:
upmodes(v5);
return 1LL;
}
if ( v7 < 0 )
{
if ( a2 <= 0 )
return 1LL;
goto LABEL_21;
}
v9 = 0LL;
while ( *(_QWORD *)(curbp + 8 * v9 + 48) != v6 )
{
if ( v7 < (int)++v9 )
{
if ( a2 > 0 )
goto LABEL_16;
break;
}
}
LABEL_7:
result = 1LL;
if ( v7 > 0 )
{
while ( *(_QWORD *)(curbp + 8 * result + 48) != v6 )
{
if ( v7 < (int)++result )
return 1LL;
}
if ( (int)result < v7 )
memmove(
(void *)(curbp + 8LL * ((int)result + 6)),
(const void *)(curbp + 8LL * ((int)result + 6) + 8),
8LL * (unsigned int)(v7 - 1 - result) + 8);
*(_WORD *)(v5 + 88) = v8 - 1;
goto LABEL_22;
}
return result;
}

original_code:
int
changemode(int f, int n, char *mode)
{
 int i;
 struct maps_s *m;
 if ((m = name_mode(mode)) == ((void *)0)) {
  dobeep();
  ewprintf("Can't find mode %s", mode);
  return (0);
 }
 if (!(f & 7)) {
  for (i = 0; i <= curbp->b_nmodes; i++)
   if (curbp->b_modes[i] == m) {
    n = 0;
    break;
   }
 }
 if (n > 0) {
  for (i = 0; i <= curbp->b_nmodes; i++)
   if (curbp->b_modes[i] == m)
    return (1);
  if (curbp->b_nmodes >= 4 - 1) {
   dobeep();
   ewprintf("Too many modes");
   return (0);
  }
  curbp->b_modes[++(curbp->b_nmodes)] = m;
 } else {
  for (i = 1; i <= curbp->b_nmodes && m != curbp->b_modes[i];
      i++);
  if (i > curbp->b_nmodes)
   return (1);
  for (; i < curbp->b_nmodes; i++)
   curbp->b_modes[i] = curbp->b_modes[i + 1];
  curbp->b_nmodes--;
 }
 upmodes(curbp);
 return (1);
}

variable_types:
mode
char *

variable_types: i int

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

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

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


indentmode

decompiled_code:
__int64 __fastcall indentmode(char a1, int a2)
{
return changemode(a1, a2, "indent");
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, int a2)
{
return func0(a1, a2, "indent");
}

original_code:
int
indentmode(int f, int n)
{
 return (changemode(f, n, "indent"));
}


fillmode

decompiled_code:
__int64 __fastcall fillmode(char a1, int a2)
{
return changemode(a1, a2, "fill");
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, int a2)
{
return func0(a1, a2, "fill");
}

original_code:
int
fillmode(int f, int n)
{
 return (changemode(f, n, "fill"));
}


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

result = changemode(a1, a2, "overwrite");
if ( (_DWORD)result )
{
v3 = *(_BYTE *)(curbp + 91LL);
if ( (a1 & 7) != 0 )
{
if ( a2 <= 0 )
{
*(_BYTE *)(curbp + 91LL) = v3 & 0xF7;
result = 1LL;
}
else
{
*(_BYTE *)(curbp + 91LL) = v3 | 8;
result = 1LL;
}
}
else
{
*(_BYTE *)(curbp + 91LL) = v3 ^ 8;
result = 1LL;
}
}
return result;
}

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

result = func0(a1, a2, "overwrite");
if ( (_DWORD)result )
{
v3 = *(_BYTE *)(curbp + 91LL);
if ( (a1 & 7) != 0 )
{
if ( a2 <= 0 )
{
*(_BYTE *)(curbp + 91LL) = v3 & 0xF7;
result = 1LL;
}
else
{
*(_BYTE *)(curbp + 91LL) = v3 | 8;
result = 1LL;
}
}
else
{
*(_BYTE *)(curbp + 91LL) = v3 ^ 8;
result = 1LL;
}
}
return result;
}

original_code:
int
overwrite_mode(int f, int n)
{
 if (changemode(f, n, "overwrite") == 0)
  return (0);
 if (f & 7) {
  if (n <= 0)
   curbp->b_flag &= ~0x08;
  else
   curbp->b_flag |= 0x08;
 } else
  curbp->b_flag ^= 0x08;
 return (1);
}


decompiled_code:
__int64 __fastcall set_default_mode(char a1, int a2)
{
_BYTE *v2; // rax
unsigned int v3; // er12
void *v5; // rdx
int v6; // ecx
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
int v10; // ebx
__int64 v11; // [rsp+0h] [rbp-38h] BYREF
__int16 v12; // [rsp+8h] [rbp-30h]

v2 = (_BYTE *)eread("Set Default Mode: ", &v11, 32LL, 8LL);
if ( v2 )
{
v3 = 0;
if ( !*v2 )
return v3;
v5 = (void *)name_mode(&v11);
if ( !v5 )
{
dobeep();
ewprintf("can't find mode %s", (const char *)&v11);
return v3;
}
v6 = defb_nmodes;
if ( (a1 & 7) != 0 )
{
if ( a2 > 0 )
{
if ( defb_nmodes >= 0 )
{
v7 = 0LL;
goto LABEL_10;
}
LABEL_26:
++defb_nmodes;
*(&defb_modes + v6 + 1) = v5;
if ( v11 == 0x746972777265766FLL && v12 == 101 )
{
defb_flag |= 8u;
return 1;
}
return 1LL;
}
}
else
{
if ( defb_nmodes < 0 )
{
if ( a2 > 0 )
goto LABEL_26;
return 1LL;
}
v8 = 0LL;
while ( *(&defb_modes + v8) != v5 )
{
if ( defb_nmodes < (int)++v8 )
{
v7 = 0LL;
if ( a2 <= 0 )
break;
LABEL_10:
while ( *(&defb_modes + v7) != v5 )
{
if ( defb_nmodes < (int)++v7 )
{
if ( defb_nmodes != 3 )
goto LABEL_26;
dobeep();
v3 = 0;
ewprintf("Too many modes");
return v3;
}
}
return 1LL;
}
}
}
v9 = 1LL;
if ( defb_nmodes > 0 )
{
while ( *(&defb_modes + v9) != v5 )
{
if ( defb_nmodes < (int)++v9 )
return 1LL;
}
v10 = defb_nmodes - 1;
if ( defb_nmodes > (int)v9 )
memmove(&defb_modes + (int)v9, &defb_modes + (int)v9 + 1, 8LL * (unsigned int)(defb_nmodes - 1 - v9) + 8);
defb_nmodes = v10;
if ( v11 == 0x746972777265766FLL && v12 == 101 )
defb_flag &= 0xFFFFFFF7;
}
return 1LL;
}
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, int a2)
{
_BYTE *v2; // rax
unsigned int v3; // er12
void *v5; // rdx
int v6; // ecx
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
int v10; // ebx
__int64 v11; // [rsp+0h] [rbp-38h] BYREF
__int16 v12; // [rsp+8h] [rbp-30h]

v2 = (_BYTE *)eread("Set Default Mode: ", &v11, 32LL, 8LL);
if ( v2 )
{
v3 = 0;
if ( !*v2 )
return v3;
v5 = (void *)name_mode(&v11);
if ( !v5 )
{
dobeep();
ewprintf("can't find mode %s", (const char *)&v11);
return v3;
}
v6 = defb_nmodes;
if ( (a1 & 7) != 0 )
{
if ( a2 > 0 )
{
if ( defb_nmodes >= 0 )
{
v7 = 0LL;
goto LABEL_10;
}
LABEL_26:
++defb_nmodes;
*(&defb_modes + v6 + 1) = v5;
if ( v11 == 0x746972777265766FLL && v12 == 101 )
{
defb_flag |= 8u;
return 1;
}
return 1LL;
}
}
else
{
if ( defb_nmodes < 0 )
{
if ( a2 > 0 )
goto LABEL_26;
return 1LL;
}
v8 = 0LL;
while ( *(&defb_modes + v8) != v5 )
{
if ( defb_nmodes < (int)++v8 )
{
v7 = 0LL;
if ( a2 <= 0 )
break;
LABEL_10:
while ( *(&defb_modes + v7) != v5 )
{
if ( defb_nmodes < (int)++v7 )
{
if ( defb_nmodes != 3 )
goto LABEL_26;
dobeep();
v3 = 0;
ewprintf("Too many modes");
return v3;
}
}
return 1LL;
}
}
}
v9 = 1LL;
if ( defb_nmodes > 0 )
{
while ( *(&defb_modes + v9) != v5 )
{
if ( defb_nmodes < (int)++v9 )
return 1LL;
}
v10 = defb_nmodes - 1;
if ( defb_nmodes > (int)v9 )
memmove(&defb_modes + (int)v9, &defb_modes + (int)v9 + 1, 8LL * (unsigned int)(defb_nmodes - 1 - v9) + 8);
defb_nmodes = v10;
if ( v11 == 0x746972777265766FLL && v12 == 101 )
defb_flag &= 0xFFFFFFF7;
}
return 1LL;
}
return 2LL;
}

original_code:
int
set_default_mode(int f, int n)
{
 int i;
 struct maps_s *m;
 char modebuf[32], *bufp;
 if ((bufp = eread("Set Default Mode: ", modebuf, sizeof(modebuf),
     0x0008)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if ((m = name_mode(modebuf)) == ((void *)0)) {
  dobeep();
  ewprintf("can't find mode %s", modebuf);
  return (0);
 }
 if (!(f & 7)) {
  for (i = 0; i <= defb_nmodes; i++)
   if (defb_modes[i] == m) {
    n = 0;
    break;
   }
 }
 if (n > 0) {
  for (i = 0; i <= defb_nmodes; i++)
   if (defb_modes[i] == m)
    return (1);
  if (defb_nmodes >= 4 - 1) {
   dobeep();
   ewprintf("Too many modes");
   return (0);
  }
  defb_modes[++defb_nmodes] = m;
 } else {
  for (i = 1; i <= defb_nmodes && m != defb_modes[i]; i++);
  if (i > defb_nmodes)
   return (1);
  for (; i < defb_nmodes; i++)
   defb_modes[i] = defb_modes[i + 1];
  defb_nmodes--;
 }
 if (strcmp(modebuf, "overwrite") == 0) {
  if (n <= 0)
   defb_flag &= ~0x08;
  else
   defb_flag |= 0x08;
 }
 return (1);
}

canonical_original_code:
int set_default_mode(int f, int n)
{
 int i;
 struct maps_s *m;
 char modebuf[32]; char *bufp;
 if ((bufp = eread("Set Default Mode: ", modebuf, sizeof(modebuf),
     0x0008)) == ((void *)0))
  return (2);
 else if (bufp[0] == '\0')
  return (0);
 if ((m = name_mode(modebuf)) == ((void *)0)) {
  dobeep();
  ewprintf("can't find mode %s", modebuf);
  return (0);
 }
 if (!(f & 7)) {
  for (i = 0; i <= defb_nmodes; i++)
   if (defb_modes[i] == m) {
    n = 0;
    break;
   }
 }
 if (n > 0) {
  for (i = 0; i <= defb_nmodes; i++)
   if (defb_modes[i] == m)
    return (1);
  if (defb_nmodes >= 4 - 1) {
   dobeep();
   ewprintf("Too many modes");
   return (0);
  }
  defb_modes[++defb_nmodes] = m;
 } else {
  for (i = 1; i <= defb_nmodes && m != defb_modes[i]; i++);
  if (i > defb_nmodes)
   return (1);
  for (; i < defb_nmodes; i++)
   defb_modes[i] = defb_modes[i + 1];
  defb_nmodes--;
 }
 if (strcmp(modebuf, "overwrite") == 0) {
  if (n <= 0)
   defb_flag &= ~0x08;
  else
   defb_flag |= 0x08;
 }
 return (1);
}

variable_types:
modebuf
char [32]

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


showcpos

original_code:
int
showcpos(int f, int n)
{
 struct line *clp;
 long nchar, cchar;
 int nline, row;
 int cline, cbyte;
 int ratio;
 clp = ((((curbp)->b_headp)->l_fp));
 cchar = 0;
 cline = 0;
 cbyte = 0;
 nchar = 0;
 nline = 0;
 for (;;) {
  ++nline;
  if (clp == curwp->w_dotp) {
   cline = nline;
   cchar = nchar + curwp->w_doto;
   if (curwp->w_doto == ((clp)->l_used))
    cbyte = '\n';
   else
    cbyte = (((unsigned char) ((clp)->l_text[(curwp->w_doto)])));
  }
  nchar += ((clp)->l_used);
  clp = ((clp)->l_fp);
  if (clp == curbp->b_headp)
   break;
  nchar++;
 }
 row = curwp->w_toprow + 1;
 clp = curwp->w_linep;
 while (clp != curbp->b_headp && clp != curwp->w_dotp) {
  ++row;
  clp = ((clp)->l_fp);
 }
 ratio = nchar ? (100L * cchar) / nchar : 100;
 ewprintf("Char: %c (0%o)  point=%ld(%d%%)  line=%d  row=%d  col=%d",
     cbyte, cbyte, cchar, ratio, cline, row, getcolpos(curwp));
 return (1);
}

canonical_original_code:
int showcpos(int f, int n)
{
 struct line *clp;
 long nchar; long cchar;
 int nline; int row;
 int cline; int cbyte;
 int ratio;
 clp = ((((curbp)->b_headp)->l_fp));
 cchar = 0;
 cline = 0;
 cbyte = 0;
 nchar = 0;
 nline = 0;
 for (;;) {
  ++nline;
  if (clp == curwp->w_dotp) {
   cline = nline;
   cchar = nchar + curwp->w_doto;
   if (curwp->w_doto == ((clp)->l_used))
    cbyte = '\n';
   else
    cbyte = (((unsigned char) ((clp)->l_text[(curwp->w_doto)])));
  }
  nchar += ((clp)->l_used);
  clp = ((clp)->l_fp);
  if (clp == curbp->b_headp)
   break;
  nchar++;
 }
 row = curwp->w_toprow + 1;
 clp = curwp->w_linep;
 while (clp != curbp->b_headp && clp != curwp->w_dotp) {
  ++row;
  clp = ((clp)->l_fp);
 }
 ratio = nchar ? (100L * cchar) / nchar : 100;
 ewprintf("Char: %c (0%o)  point=%ld(%d%%)  line=%d  row=%d  col=%d",
     cbyte, cbyte, cchar, ratio, cline, row, getcolpos(curwp));
 return (1);
}

variable_types: f int

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

variable_types: nchar long

variable_types: cchar long

variable_types: nline int

variable_types: row int

variable_types: cline int

variable_types: cbyte int

variable_types: ratio int


openline

decompiled_code:
__int64 __fastcall openline(int a1, int a2)
{
unsigned int v2; // er12
int v4; // ebx
unsigned int v5; // er12

v2 = 0;
if ( a2 < 0 )
return v2;
v2 = 1;
if ( !a2 )
return v2;
undo_boundary_enable(8LL, 0LL);
v4 = a2;
while ( 1 )
{
v5 = lnewline();
if ( v5 != 1 )
break;
if ( !--v4 )
{
v5 = backchar(a1 | 8u, (unsigned int)a2);
break;
}
}
undo_boundary_enable(8LL, 1LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
unsigned int v2; // er12
int v4; // ebx
unsigned int v5; // er12

v2 = 0;
if ( a2 < 0 )
return v2;
v2 = 1;
if ( !a2 )
return v2;
undo_boundary_enable(8LL, 0LL);
v4 = a2;
while ( 1 )
{
v5 = lnewline();
if ( v5 != 1 )
break;
if ( !--v4 )
{
v5 = backchar(a1 | 8u, (unsigned int)a2);
break;
}
}
undo_boundary_enable(8LL, 1LL);
return v5;
}

original_code:
int
openline(int f, int n)
{
 int i, s;
 if (n < 0)
  return (0);
 if (n == 0)
  return (1);
 undo_boundary_enable(8, 0);
 i = n;
 do {
  s = lnewline();
 } while (s == 1 && --i);
 if (s == 1)
  s = backchar(f | 8, n);
 undo_boundary_enable(8, 1);
 return (s);
}

canonical_original_code:
int openline(int f, int n)
{
 int i; int s;
 if (n < 0)
  return (0);
 if (n == 0)
  return (1);
 undo_boundary_enable(8, 0);
 i = n;
 do {
  s = lnewline();
 } while (s == 1 && --i);
 if (s == 1)
  s = backchar(f | 8, n);
 undo_boundary_enable(8, 1);
 return (s);
}

variable_types: n int

variable_types: s int


newline

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

if ( a2 < 0 )
return 0LL;
v2 = a2;
while ( v2-- != 0 )
{
result = lnewline();
if ( (_DWORD)result != 1 )
return result;
}
return 1LL;
}

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

if ( a2 < 0 )
return 0LL;
v2 = a2;
while ( v2-- != 0 )
{
result = lnewline();
if ( (_DWORD)result != 1 )
return result;
}
return 1LL;
}

original_code:
int
newline(int f, int n)
{
 int s;
 if (n < 0)
  return (0);
 while (n--) {
  if ((s = lnewline()) != 1)
   return (s);
 }
 return (1);
}


deblank

original_code:
int
deblank(int f, int n)
{
 struct line *lp1, *lp2;
 RSIZE nld;
 lp1 = curwp->w_dotp;
 while (((lp1)->l_used) == 0 && (lp2 = ((lp1)->l_bp)) != curbp->b_headp)
  lp1 = lp2;
 lp2 = lp1;
 nld = (RSIZE)0;
 while ((lp2 = ((lp2)->l_fp)) != curbp->b_headp && ((lp2)->l_used) == 0)
  ++nld;
 if (nld == 0)
  return (1);
 curwp->w_dotp = ((lp1)->l_fp);
 curwp->w_doto = 0;
 return (ldelete((RSIZE)nld, 0x00));
}

canonical_original_code:
int deblank(int f, int n)
{
 struct line *lp1; struct line *lp2;
 int nld;
 lp1 = curwp->w_dotp;
 while (((lp1)->l_used) == 0 && (lp2 = ((lp1)->l_bp)) != curbp->b_headp)
  lp1 = lp2;
 lp2 = lp1;
 nld = (int)0;
 while ((lp2 = ((lp2)->l_fp)) != curbp->b_headp && ((lp2)->l_used) == 0)
  ++nld;
 if (nld == 0)
  return (1);
 curwp->w_dotp = ((lp1)->l_fp);
 curwp->w_doto = 0;
 return (ldelete((int)nld, 0x00));
}

variable_types: nld int

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


delwhite

decompiled_code:
__int64 delwhite()
{
__int64 v0; // rbp
int v1; // ebx
int v2; // er12
const unsigned __int16 *v3; // rcx
unsigned __int8 *v4; // rax
int v5; // ebp
const unsigned __int16 **v6; // r8

v0 = *(_QWORD *)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = *(_DWORD *)(v0 + 20);
if ( v1 >= v2 )
{
v5 = *(_DWORD *)(curwp + 48LL);
goto LABEL_8;
}
v3 = *_ctype_b_loc();
v4 = (unsigned __int8 *)(*(_QWORD *)(v0 + 24) + v1);
v5 = v1;
while ( (v3[*v4] & 0x2000) != 0 )
{
++v5;
++v4;
if ( v5 == v2 )
goto LABEL_8;
}
if ( v1 )
{
while ( (unsigned int)backchar(8LL, 1LL) == 1 )
{
v6 = _ctype_b_loc();
v1 = *(_DWORD *)(curwp + 48LL);
if ( ((*v6)[*(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + v1)] & 0x2000) == 0 )
{
forwchar(8LL, 1LL);
break;
}
LABEL_8:
if ( !v1 )
goto LABEL_9;
}
v1 = *(_DWORD *)(curwp + 48LL);
}
LABEL_9:
ldelete((unsigned int)(v5 - v1), 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbp
int v1; // ebx
int v2; // er12
const unsigned __int16 *v3; // rcx
unsigned __int8 *v4; // rax
int v5; // ebp
const unsigned __int16 **v6; // r8

v0 = *(_QWORD *)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = *(_DWORD *)(v0 + 20);
if ( v1 >= v2 )
{
v5 = *(_DWORD *)(curwp + 48LL);
goto LABEL_8;
}
v3 = *_ctype_b_loc();
v4 = (unsigned __int8 *)(*(_QWORD *)(v0 + 24) + v1);
v5 = v1;
while ( (v3[*v4] & 0x2000) != 0 )
{
++v5;
++v4;
if ( v5 == v2 )
goto LABEL_8;
}
if ( v1 )
{
while ( (unsigned int)backchar(8LL, 1LL) == 1 )
{
v6 = _ctype_b_loc();
v1 = *(_DWORD *)(curwp + 48LL);
if ( ((*v6)[*(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 24LL) + v1)] & 0x2000) == 0 )
{
forwchar(8LL, 1LL);
break;
}
LABEL_8:
if ( !v1 )
goto LABEL_9;
}
v1 = *(_DWORD *)(curwp + 48LL);
}
LABEL_9:
ldelete((unsigned int)(v5 - v1), 0LL);
return 1LL;
}

original_code:
int
delwhite(int f, int n)
{
 int col, s;
 col = curwp->w_doto;
 while (col < ((curwp->w_dotp)->l_used) &&
     (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(col)])))))] & (unsigned short int) _ISspace)))
  ++col;
 do {
  if (curwp->w_doto == 0) {
   s = 0;
   break;
  }
  if ((s = backchar(8, 1)) != 1)
   break;
 } while (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))))] & (unsigned short int) _ISspace));
 if (s == 1)
  (void)forwchar(8, 1);
 (void)ldelete((RSIZE)(col - curwp->w_doto), 0x00);
 return (1);
}

canonical_original_code:
int delwhite(int f, int n)
{
 int col; int s;
 col = curwp->w_doto;
 while (col < ((curwp->w_dotp)->l_used) &&
     (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(col)])))))] & (unsigned short) _ISspace)))
  ++col;
 do {
  if (curwp->w_doto == 0) {
   s = 0;
   break;
  }
  if ((s = backchar(8, 1)) != 1)
   break;
 } while (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))))] & (unsigned short) _ISspace));
 if (s == 1)
  (void)forwchar(8, 1);
 (void)ldelete((RSIZE)(col - curwp->w_doto), 0x00);
 return (1);
}

variable_types: col int


justone

decompiled_code:
__int64 __fastcall justone(unsigned int a1, unsigned int a2)
{
undo_boundary_enable(8LL, 0LL);
delwhite(a1, a2);
linsert(1LL, 32LL);
undo_boundary_enable(8LL, 1LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
undo_boundary_enable(8LL, 0LL);
func5(a1, a2);
linsert(1LL, 32LL);
undo_boundary_enable(8LL, 1LL);
return 1LL;
}

original_code:
int
justone(int f, int n)
{
 undo_boundary_enable(8, 0);
 (void)delwhite(f, n);
 linsert(1, ' ');
 undo_boundary_enable(8, 1);
 return (1);
}


deltrailwhite

decompiled_code:
__int64 deltrailwhite()
{
int v0; // ebx

v0 = *(_DWORD *)(curwp + 48LL);
gotoeol(8LL, 1LL);
delwhite(8LL, 1LL);
if ( *(_DWORD *)(curwp + 48LL) > v0 )
*(_DWORD *)(curwp + 48LL) = v0;
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ebx

v0 = *(_DWORD *)(curwp + 48LL);
gotoeol(8LL, 1LL);
func5(8LL, 1LL);
if ( *(_DWORD *)(curwp + 48LL) > v0 )
*(_DWORD *)(curwp + 48LL) = v0;
return 1LL;
}

original_code:
int
deltrailwhite(int f, int n)
{
 int soff;
 soff = curwp->w_doto;
 gotoeol(8, 1);
 delwhite(8, 1);
 if (soff < curwp->w_doto)
  curwp->w_doto = soff;
 return (1);
}

variable_types: soff int


lfindent

decompiled_code:
__int64 __fastcall lfindent(__int64 a1, int a2)
{
unsigned int v2; // er12
int v3; // ebx
__int64 v4; // rax
int v5; // edx
unsigned __int8 *v6; // rax
int v7; // ebp
__int64 v8; // rsi
int v9; // edx
int v11; // eax

v2 = 0;
if ( a2 < 0 )
return v2;
v3 = a2;
undo_boundary_enable(8LL, 0LL);
if ( !a2 )
{
LABEL_14:
v2 = 1;
goto LABEL_15;
}
while ( 1 )
{
v4 = *(_QWORD *)(curwp + 32LL);
v5 = *(_DWORD *)(v4 + 20);
if ( v5 <= 0 )
{
if ( !(unsigned int)lnewline() )
break;
goto LABEL_13;
}
v6 = *(unsigned __int8 **)(v4 + 24);
v7 = 0;
v8 = (__int64)&v6[v5 - 1 + 1];
do
{
v9 = *v6;
if ( v9 != 32 && v9 != 9 )
break;
if ( v9 == 9 )
v7 |= 7u;
++v6;
++v7;
}
while ( v6 != (unsigned __int8 *)v8 );
if ( !(unsigned int)lnewline() )
break;
if ( v7 >> 3 )
{
if ( !(unsigned int)linsert((unsigned int)(v7 >> 3), 9LL) )
break;
v11 = v7 & 7;
v7 = v11;
if ( !v11 )
goto LABEL_13;
}
else if ( !v7 )
{
goto LABEL_13;
}
if ( !(unsigned int)linsert((unsigned int)v7, 32LL) )
break;
LABEL_13:
if ( !--v3 )
goto LABEL_14;
}
v2 = 0;
LABEL_15:
undo_boundary_enable(8LL, 1LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
unsigned int v2; // er12
int v3; // ebx
__int64 v4; // rax
int v5; // edx
unsigned __int8 *v6; // rax
int v7; // ebp
__int64 v8; // rsi
int v9; // edx
int v11; // eax

v2 = 0;
if ( a2 < 0 )
return v2;
v3 = a2;
undo_boundary_enable(8LL, 0LL);
if ( !a2 )
{
LABEL_14:
v2 = 1;
goto LABEL_15;
}
while ( 1 )
{
v4 = *(_QWORD *)(curwp + 32LL);
v5 = *(_DWORD *)(v4 + 20);
if ( v5 <= 0 )
{
if ( !(unsigned int)lnewline() )
break;
goto LABEL_13;
}
v6 = *(unsigned __int8 **)(v4 + 24);
v7 = 0;
v8 = (__int64)&v6[v5 - 1 + 1];
do
{
v9 = *v6;
if ( v9 != 32 && v9 != 9 )
break;
if ( v9 == 9 )
v7 |= 7u;
++v6;
++v7;
}
while ( v6 != (unsigned __int8 *)v8 );
if ( !(unsigned int)lnewline() )
break;
if ( v7 >> 3 )
{
if ( !(unsigned int)linsert((unsigned int)(v7 >> 3), 9LL) )
break;
v11 = v7 & 7;
v7 = v11;
if ( !v11 )
goto LABEL_13;
}
else if ( !v7 )
{
goto LABEL_13;
}
if ( !(unsigned int)linsert((unsigned int)v7, 32LL) )
break;
LABEL_13:
if ( !--v3 )
goto LABEL_14;
}
v2 = 0;
LABEL_15:
undo_boundary_enable(8LL, 1LL);
return v2;
}

original_code:
int
lfindent(int f, int n)
{
 int c, i, nicol;
 int s = 1;
 if (n < 0)
  return (0);
 undo_boundary_enable(8, 0);
 while (n--) {
  nicol = 0;
  for (i = 0; i < ((curwp->w_dotp)->l_used); ++i) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
   if (c != ' ' && c != '\t')
    break;
   if (c == '\t')
    nicol |= 0x07;
   ++nicol;
  }
  if (lnewline() == 0 || ((
      ((i = nicol / 8) != 0 && linsert(i, '\t') == 0) ||
      ((i = nicol % 8) != 0 && linsert(i, ' ') == 0)))) {
   s = 0;
   break;
  }
 }
 undo_boundary_enable(8, 1);
 return (s);
}

canonical_original_code:
int lfindent(int f, int n)
{
 int c; int i; int nicol;
 int s = 1;
 if (n < 0)
  return (0);
 undo_boundary_enable(8, 0);
 while (n--) {
  nicol = 0;
  for (i = 0; i < ((curwp->w_dotp)->l_used); ++i) {
   c = (((unsigned char) ((curwp->w_dotp)->l_text[(i)])));
   if (c != ' ' && c != '\t')
    break;
   if (c == '\t')
    nicol |= 0x07;
   ++nicol;
  }
  if (lnewline() == 0 || ((
      ((i = nicol / 8) != 0 && linsert(i, '\t') == 0) ||
      ((i = nicol % 8) != 0 && linsert(i, ' ') == 0)))) {
   s = 0;
   break;
  }
 }
 undo_boundary_enable(8, 1);
 return (s);
}

variable_types: c int

variable_types: i int

variable_types: nicol int


backdel

decompiled_code:
__int64 __fastcall backdel(int a1, int a2)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = a1 | 8;
if ( a2 < 0 )
return forwdel(v2, (unsigned int)-a2);
if ( (a1 & 7) != 0 )
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
}
result = backchar(v2, (unsigned int)a2);
if ( (_DWORD)result == 1 )
result = ldelete((unsigned int)a2, (a1 & 7) != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = a1 | 8;
if ( a2 < 0 )
return func11(v2, (unsigned int)-a2);
if ( (a1 & 7) != 0 )
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
}
result = backchar(v2, (unsigned int)a2);
if ( (_DWORD)result == 1 )
result = ldelete((unsigned int)a2, (a1 & 7) != 0);
return result;
}

original_code:
int
backdel(int f, int n)
{
 int s;
 if (n < 0)
  return (forwdel(f | 8, -n));
 if (f & 7) {
  if ((lastflag & 0x0002) == 0)
   kdelete();
  thisflag |= 0x0002;
 }
 if ((s = backchar(f | 8, n)) == 1)
  s = ldelete((RSIZE)n, (f & 7) ? 0x01 : 0x00);
 return (s);
}

canonical_original_code:
int backdel(int f, int n)
{
 int s;
 if (n < 0)
  return (forwdel(f | 8, -n));
 if (f & 7) {
  if ((lastflag & 0x0002) == 0)
   kdelete();
  thisflag |= 0x0002;
 }
 if ((s = backchar(f | 8, n)) == 1)
  s = ldelete((int)n, (f & 7) ? 0x01 : 0x00);
 return (s);
}

variable_types: f int


twiddle

decompiled_code:
__int64 twiddle()
{
__int64 v0; // r12
__int64 v1; // rbx
__int64 v2; // rax
unsigned int v3; // er12
unsigned int v5; // er12

v0 = *(int *)(curwp + 48LL);
v1 = *(_QWORD *)(curwp + 32LL);
if ( !(_DWORD)v0 )
{
v2 = *(_QWORD *)(curbp + 40LL);
if ( *(_QWORD *)(v1 + 8) == v2 )
{
dobeep();
ewprintf("Beginning of buffer");
return (unsigned int)v0;
}
if ( *(_DWORD *)(v1 + 20) || v2 != *(_QWORD *)v1 )
{
undo_boundary_enable(8LL, 0LL);
if ( *(_DWORD *)(v1 + 20) )
{
v3 = **(unsigned __int8 **)(v1 + 24);
backdel(8, 1);
forwchar(8LL, 1LL);
lnewline();
linsert(1LL, v3);
backdel(8, 1);
}
else
{
forwline(8LL, 1LL);
*(_DWORD *)(curwp + 48LL) = 0;
}
goto LABEL_7;
}
LABEL_14:
dobeep();
LODWORD(v0) = 0;
return (unsigned int)v0;
}
if ( (_DWORD)v0 == *(_DWORD *)(v1 + 20) && *(_QWORD *)(curbp + 40LL) == *(_QWORD *)v1 )
goto LABEL_14;
undo_boundary_enable(8LL, 0LL);
v5 = *(unsigned __int8 *)(*(_QWORD *)(v1 + 24) + v0 - 1);
backdel(8, 1);
forwchar(8LL, 1LL);
linsert(1LL, v5);
LABEL_7:
LODWORD(v0) = 1;
undo_boundary_enable(8LL, 1LL);
lchange(4LL);
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // r12
__int64 v1; // rbx
__int64 v2; // rax
unsigned int v3; // er12
unsigned int v5; // er12

v0 = *(int *)(curwp + 48LL);
v1 = *(_QWORD *)(curwp + 32LL);
if ( !(_DWORD)v0 )
{
v2 = *(_QWORD *)(curbp + 40LL);
if ( *(_QWORD *)(v1 + 8) == v2 )
{
dobeep();
ewprintf("Beginning of buffer");
return (unsigned int)v0;
}
if ( *(_DWORD *)(v1 + 20) || v2 != *(_QWORD *)v1 )
{
undo_boundary_enable(8LL, 0LL);
if ( *(_DWORD *)(v1 + 20) )
{
v3 = **(unsigned __int8 **)(v1 + 24);
func9(8, 1);
forwchar(8LL, 1LL);
lnewline();
linsert(1LL, v3);
func9(8, 1);
}
else
{
forwline(8LL, 1LL);
*(_DWORD *)(curwp + 48LL) = 0;
}
goto LABEL_7;
}
LABEL_14:
dobeep();
LODWORD(v0) = 0;
return (unsigned int)v0;
}
if ( (_DWORD)v0 == *(_DWORD *)(v1 + 20) && *(_QWORD *)(curbp + 40LL) == *(_QWORD *)v1 )
goto LABEL_14;
undo_boundary_enable(8LL, 0LL);
v5 = *(unsigned __int8 *)(*(_QWORD *)(v1 + 24) + v0 - 1);
func9(8, 1);
forwchar(8LL, 1LL);
linsert(1LL, v5);
LABEL_7:
LODWORD(v0) = 1;
undo_boundary_enable(8LL, 1LL);
lchange(4LL);
return (unsigned int)v0;
}

original_code:
int
twiddle(int f, int n)
{
 struct line *dotp;
 int doto, cr;
 dotp = curwp->w_dotp;
 doto = curwp->w_doto;
 if (doto == 0 && ((dotp)->l_bp) == curbp->b_headp) {
  dobeep();
  ewprintf("Beginning of buffer");
  return(0);
 }
 if (doto == ((dotp)->l_used) && ((dotp)->l_fp) == curbp->b_headp) {
  dobeep();
  return(0);
 }
 undo_boundary_enable(8, 0);
 if (doto == 0 && doto == ((dotp)->l_used)) {
  (void)forwline(8, 1);
  curwp->w_doto = 0;
 } else {
  if (doto == 0) {
   cr = (((unsigned char) ((dotp)->l_text[(doto)])));
   (void)backdel(8, 1);
   (void)forwchar(8, 1);
   lnewline();
   linsert(1, cr);
   (void)backdel(8, 1);
  } else {
   cr = (((unsigned char) ((dotp)->l_text[(doto - 1)])));
   (void)backdel(8, 1);
   (void)forwchar(8, 1);
   linsert(1, cr);
  }
 }
 undo_boundary_enable(8, 1);
 lchange(0x04);
 return (1);
}

canonical_original_code:
int twiddle(int f, int n)
{
 struct line *dotp;
 int doto; int cr;
 dotp = curwp->w_dotp;
 doto = curwp->w_doto;
 if (doto == 0 && ((dotp)->l_bp) == curbp->b_headp) {
  dobeep();
  ewprintf("Beginning of buffer");
  return(0);
 }
 if (doto == ((dotp)->l_used) && ((dotp)->l_fp) == curbp->b_headp) {
  dobeep();
  return(0);
 }
 undo_boundary_enable(8, 0);
 if (doto == 0 && doto == ((dotp)->l_used)) {
  (void)forwline(8, 1);
  curwp->w_doto = 0;
 } else {
  if (doto == 0) {
   cr = (((unsigned char) ((dotp)->l_text[(doto)])));
   (void)backdel(8, 1);
   (void)forwchar(8, 1);
   lnewline();
   linsert(1, cr);
   (void)backdel(8, 1);
  } else {
   cr = (((unsigned char) ((dotp)->l_text[(doto - 1)])));
   (void)backdel(8, 1);
   (void)forwchar(8, 1);
   linsert(1, cr);
  }
 }
 undo_boundary_enable(8, 1);
 lchange(0x04);
 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: doto int

variable_types: cr int


forwdel

decompiled_code:
__int64 __fastcall forwdel(int a1, int a2)
{
int v2; // edi

if ( a2 < 0 )
return backdel(a1 | 8u, -a2);
v2 = a1 & 7;
if ( v2 )
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
}
return ldelete((unsigned int)a2, v2 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
int v2; // edi

if ( a2 < 0 )
return func9(a1 | 8u, -a2);
v2 = a1 & 7;
if ( v2 )
{
if ( (lastflag & 2) == 0 )
kdelete();
thisflag |= 2u;
}
return ldelete((unsigned int)a2, v2 != 0);
}

original_code:
int
forwdel(int f, int n)
{
 if (n < 0)
  return (backdel(f | 8, -n));
 if (f & 7) {
  if ((lastflag & 0x0002) == 0)
   kdelete();
  thisflag |= 0x0002;
 }
 return (ldelete((RSIZE) n, (f & 7) ? 0x01 : 0x00));
}

canonical_original_code:
int forwdel(int f, int n)
{
 if (n < 0)
  return (backdel(f | 8, -n));
 if (f & 7) {
  if ((lastflag & 0x0002) == 0)
   kdelete();
  thisflag |= 0x0002;
 }
 return (ldelete((int) n, (f & 7) ? 0x01 : 0x00));
}


delleadwhite

decompiled_code:
__int64 delleadwhite()
{
__int64 v0; // rbp
int v1; // er12
int v2; // ebx
const unsigned __int16 *v3; // rcx
unsigned __int8 *v4; // rax
int i; // ebp
__int64 v6; // rsi

v0 = *(_QWORD *)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = *(_DWORD *)(v0 + 20);
if ( v2 <= 0 )
{
i = 0;
}
else
{
v3 = *_ctype_b_loc();
v4 = *(unsigned __int8 **)(v0 + 24);
for ( i = 0; i != v2; ++i )
{
if ( (v3[*v4] & 0x2000) == 0 )
break;
++v4;
}
v1 -= i;
}
gotobol(8LL, 1LL);
forwdel(8, i);
v6 = 0LL;
if ( v1 >= 0 )
v6 = (unsigned int)v1;
forwchar(8LL, v6);
return 1LL;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbp
int v1; // er12
int v2; // ebx
const unsigned __int16 *v3; // rcx
unsigned __int8 *v4; // rax
int i; // ebp
__int64 v6; // rsi

v0 = *(_QWORD *)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = *(_DWORD *)(v0 + 20);
if ( v2 <= 0 )
{
i = 0;
}
else
{
v3 = *_ctype_b_loc();
v4 = *(unsigned __int8 **)(v0 + 24);
for ( i = 0; i != v2; ++i )
{
if ( (v3[*v4] & 0x2000) == 0 )
break;
++v4;
}
v1 -= i;
}
gotobol(8LL, 1LL);
func11(8, i);
v6 = 0LL;
if ( v1 >= 0 )
v6 = (unsigned int)v1;
forwchar(8LL, v6);
return 1LL;
}

original_code:
int
delleadwhite(int f, int n)
{
 int soff, ls;
 struct line *slp;
 slp = curwp->w_dotp;
 soff = curwp->w_doto;
 for (ls = 0; ls < ((slp)->l_used); ls++)
                 if (!((*__ctype_b_loc ())[(int) (((((unsigned char) ((slp)->l_text[(ls)])))))] & (unsigned short int) _ISspace))
                        break;
 gotobol(8, 1);
 forwdel(8, ls);
 soff -= ls;
 if (soff < 0)
  soff = 0;
 forwchar(8, soff);
 return (1);
}

canonical_original_code:
int delleadwhite(int f, int n)
{
 int soff; int ls;
 struct line *slp;
 slp = curwp->w_dotp;
 soff = curwp->w_doto;
 for (ls = 0; ls < ((slp)->l_used); ls++)
                 if (!((*__ctype_b_loc ())[(int) (((((unsigned char) ((slp)->l_text[(ls)])))))] & (unsigned short) _ISspace))
                        break;
 gotobol(8, 1);
 forwdel(8, ls);
 soff -= ls;
 if (soff < 0)
  soff = 0;
 forwchar(8, soff);
 return (1);
}

variable_types: ls int


indent

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

if ( a2 < 0 )
return 0LL;
delleadwhite(8LL, 1LL);
result = 1LL;
if ( (a1 & 7) != 0 )
{
v3 = *(_DWORD *)(curwp + 48LL);
gotobol(8LL, 1LL);
if ( a2 >> 3 && !(unsigned int)linsert((unsigned int)(a2 >> 3), 9LL)
|| (a2 & 7) != 0 && !(unsigned int)linsert(a2 & 7, 32LL) )
{
result = 0LL;
}
else
{
forwchar(8LL, v3);
result = 1LL;
}
}
return result;
}

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

if ( a2 < 0 )
return 0LL;
func12(8LL, 1LL);
result = 1LL;
if ( (a1 & 7) != 0 )
{
v3 = *(_DWORD *)(curwp + 48LL);
gotobol(8LL, 1LL);
if ( a2 >> 3 && !(unsigned int)linsert((unsigned int)(a2 >> 3), 9LL)
|| (a2 & 7) != 0 && !(unsigned int)linsert(a2 & 7, 32LL) )
{
result = 0LL;
}
else
{
forwchar(8LL, v3);
result = 1LL;
}
}
return result;
}

original_code:
int
indent(int f, int n)
{
 int soff, i;
 if (n < 0)
  return (0);
 delleadwhite(8, 1);
 if (!(f & 7))
  return (1);
 soff = curwp->w_doto;
 (void)gotobol(8, 1);
 if (
     (((i = n / 8) != 0 && linsert(i, '\t') == 0) ||
     ((i = n % 8) != 0 && linsert(i, ' ') == 0)))
  return (0);
 forwchar(8, soff);
 return (1);
}

canonical_original_code:
int indent(int f, int n)
{
 int soff; int i;
 if (n < 0)
  return (0);
 delleadwhite(8, 1);
 if (!(f & 7))
  return (1);
 soff = curwp->w_doto;
 (void)gotobol(8, 1);
 if (
     (((i = n / 8) != 0 && linsert(i, '\t') == 0) ||
     ((i = n % 8) != 0 && linsert(i, ' ') == 0)))
  return (0);
 forwchar(8, soff);
 return (1);
}


backtoindent

original_code:
int
backtoindent(int f, int n)
{
 gotobol(8, 1);
 while (curwp->w_doto < ((curwp->w_dotp)->l_used) &&
     (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))))] & (unsigned short int) _ISspace)))
  ++curwp->w_doto;
 return (1);
}

canonical_original_code:
int backtoindent(int f, int n)
{
 gotobol(8, 1);
 while (curwp->w_doto < ((curwp->w_dotp)->l_used) &&
     (((*__ctype_b_loc ())[(int) (((((unsigned char) ((curwp->w_dotp)->l_text[(curwp->w_doto)])))))] & (unsigned short) _ISspace)))
  ++curwp->w_doto;
 return (1);
}


joinline

decompiled_code:
__int64 __fastcall joinline(char a1)
{
int v1; // ebx

undo_boundary_enable(8LL, 0LL);
if ( (a1 & 7) != 0 )
{
gotoeol(8LL, 1LL);
forwdel(8, 1);
}
else
{
gotobol(8LL, 1LL);
backdel(8, 1);
}
delwhite(8LL, 1LL);
v1 = *(_DWORD *)(curwp + 48LL);
if ( v1 > 0 )
{
linsert(1LL, 32LL);
*(_DWORD *)(curwp + 48LL) = v1;
}
undo_boundary_enable(8LL, 1LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char a1)
{
int v1; // ebx

undo_boundary_enable(8LL, 0LL);
if ( (a1 & 7) != 0 )
{
gotoeol(8LL, 1LL);
func11(8, 1);
}
else
{
gotobol(8LL, 1LL);
func9(8, 1);
}
func5(8LL, 1LL);
v1 = *(_DWORD *)(curwp + 48LL);
if ( v1 > 0 )
{
linsert(1LL, 32LL);
*(_DWORD *)(curwp + 48LL) = v1;
}
undo_boundary_enable(8LL, 1LL);
return 1LL;
}

original_code:
int
joinline(int f, int n)
{
 int doto;
 undo_boundary_enable(8, 0);
 if (f & 7) {
  gotoeol(8, 1);
  forwdel(8, 1);
 } else {
  gotobol(8, 1);
  backdel(8, 1);
 }
 delwhite(8, 1);
 if ((doto = curwp->w_doto) > 0) {
  linsert(1, ' ');
  curwp->w_doto = doto;
 }
 undo_boundary_enable(8, 1);
 return (1);
}


gotobol

decompiled_code:
__int64 gotobol()
{
*(_DWORD *)(curwp + 48LL) = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
*(_DWORD *)(curwp + 48LL) = 0;
return 1LL;
}

original_code:
int
gotobol(int f, int n)
{
 curwp->w_doto = 0;
 return (1);
}


gotoeol

decompiled_code:
__int64 gotoeol()
{
*(_DWORD *)(curwp + 48LL) = *(_DWORD *)(*(_QWORD *)(curwp + 32LL) + 20LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
*(_DWORD *)(curwp + 48LL) = *(_DWORD *)(*(_QWORD *)(curwp + 32LL) + 20LL);
return 1LL;
}

original_code:
int
gotoeol(int f, int n)
{
 curwp->w_doto = ((curwp->w_dotp)->l_used);
 return (1);
}


forwchar

original_code:
int
forwchar(int f, int n)
{
 if (n < 0)
  return (backchar(f, -n));
 while (n--) {
  if (curwp->w_doto == ((curwp->w_dotp)->l_used)) {
   curwp->w_dotp = ((curwp->w_dotp)->l_fp);
   if (curwp->w_dotp == curbp->b_headp) {
    curwp->w_dotp = ((curwp->w_dotp)->l_bp);
    if (!(f & 8)) {
     dobeep();
     ewprintf("End of buffer");
    }
    return (0);
   }
   curwp->w_doto = 0;
   curwp->w_dotline++;
   curwp->w_rflag |= 0x02;
  } else
   curwp->w_doto++;
 }
 return (1);
}


backchar

original_code:
int
backchar(int f, int n)
{
 struct line *lp;
 if (n < 0)
  return (forwchar(f, -n));
 while (n--) {
  if (curwp->w_doto == 0) {
   if ((lp = ((curwp->w_dotp)->l_bp)) == curbp->b_headp) {
    if (!(f & 8)) {
     dobeep();
     ewprintf("Beginning of buffer");
    }
    return (0);
   }
   curwp->w_dotp = lp;
   curwp->w_doto = ((lp)->l_used);
   curwp->w_rflag |= 0x02;
   curwp->w_dotline--;
  } else
   curwp->w_doto--;
 }
 return (1);
}


setgoal

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

result = getcolpos(curwp);
curgoal = result;
return result;
}

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

result = getcolpos(curwp);
curgoal = result;
return result;
}

original_code:
void
setgoal(void)
{
 curgoal = getcolpos(curwp);
}

canonical_original_code:
void setgoal()
{
 curgoal = getcolpos(curwp);
}

return_type: void


getgoal

original_code:
int
getgoal(struct line *dlp)
{
 int c, i, col = 0;
 char tmp[5];
 for (i = 0; i < ((dlp)->l_used); i++) {
  c = (((unsigned char) ((dlp)->l_text[(i)])));
  if (c == '\t'
   ) {
   col |= 0x07;
   col++;
  } else if (((cinfo[((unsigned char) (c))]&0x08)!=0) != 0) {
   col += 2;
  } else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint))
   col++;
  else {
   col += snprintf(tmp, sizeof(tmp), "\\%o", c);
  }
  if (col > curgoal)
   break;
 }
 return (i);
}

canonical_original_code:
int getgoal(struct line *dlp)
{
 int c; int i; int col = 0;
 char tmp[5];
 for (i = 0; i < ((dlp)->l_used); i++) {
  c = (((unsigned char) ((dlp)->l_text[(i)])));
  if (c == '\t'
   ) {
   col |= 0x07;
   col++;
  } else if (((cinfo[((unsigned char) (c))]&0x08)!=0) != 0) {
   col += 2;
  } else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint))
   col++;
  else {
   col += snprintf(tmp, sizeof(tmp), "\\%o", c);
  }
  if (col > curgoal)
   break;
 }
 return (i);
}

variable_types:
tmp
char [5]


backline

decompiled_code:
__int64 __fastcall backline(int a1, int a2)
{
char v2; // r13
__int64 v3; // r12
__int64 v4; // rdi
__int64 v5; // rbp
int v6; // eax
__int64 v7; // rsi
int v8; // er8
__int64 v9; // rdx

v2 = a1;
if ( a2 < 0 )
return forwline(a1 | 8u, (unsigned int)-a2);
if ( (lastflag & 1) == 0 )
setgoal();
v3 = curwp;
thisflag |= 1u;
v4 = *(_QWORD *)(curbp + 40LL);
v5 = *(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 8LL);
if ( v5 == v4 )
{
if ( (v2 & 8) == 0 )
{
((void (*)(void))dobeep)();
ewprintf("Beginning of buffer");
}
}
else
{
if ( a2 )
{
v6 = a2 - 2;
v7 = (unsigned int)(*(_DWORD *)(curwp + 80LL) + 1 - a2);
while ( 1 )
{
v8 = v7 + v6;
if ( v6 == -1 )
{
*(_DWORD *)(curwp + 80LL) = v8;
goto LABEL_13;
}
v9 = *(_QWORD *)(v5 + 8);
if ( v4 == v9 )
break;
--v6;
v5 = *(_QWORD *)(v5 + 8);
}
*(_DWORD *)(curwp + 80LL) = v8;
if ( v6 )
{
if ( (v2 & 8) == 0 )
{
dobeep(v4, v7, v9, (unsigned int)(v6 - 1));
ewprintf("Beginning of buffer");
v3 = curwp;
}
}
}
else
{
v5 = *(_QWORD *)(curwp + 32LL);
}
LABEL_13:
*(_QWORD *)(v3 + 32) = v5;
*(_DWORD *)(v3 + 48) = getgoal(v5);
*(_BYTE *)(curwp + 68LL) |= 2u;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
char v2; // r13
__int64 v3; // r12
__int64 v4; // rdi
__int64 v5; // rbp
int v6; // eax
__int64 v7; // rsi
int v8; // er8
__int64 v9; // rdx

v2 = a1;
if ( a2 < 0 )
return func7(a1 | 8u, (unsigned int)-a2);
if ( (lastflag & 1) == 0 )
func4();
v3 = curwp;
thisflag |= 1u;
v4 = *(_QWORD *)(curbp + 40LL);
v5 = *(_QWORD *)(*(_QWORD *)(curwp + 32LL) + 8LL);
if ( v5 == v4 )
{
if ( (v2 & 8) == 0 )
{
((void (*)(void))dobeep)();
ewprintf("Beginning of buffer");
}
}
else
{
if ( a2 )
{
v6 = a2 - 2;
v7 = (unsigned int)(*(_DWORD *)(curwp + 80LL) + 1 - a2);
while ( 1 )
{
v8 = v7 + v6;
if ( v6 == -1 )
{
*(_DWORD *)(curwp + 80LL) = v8;
goto LABEL_13;
}
v9 = *(_QWORD *)(v5 + 8);
if ( v4 == v9 )
break;
--v6;
v5 = *(_QWORD *)(v5 + 8);
}
*(_DWORD *)(curwp + 80LL) = v8;
if ( v6 )
{
if ( (v2 & 8) == 0 )
{
dobeep(v4, v7, v9, (unsigned int)(v6 - 1));
ewprintf("Beginning of buffer");
v3 = curwp;
}
}
}
else
{
v5 = *(_QWORD *)(curwp + 32LL);
}
LABEL_13:
*(_QWORD *)(v3 + 32) = v5;
*(_DWORD *)(v3 + 48) = func5(v5);
*(_BYTE *)(curwp + 68LL) |= 2u;
}
return 1LL;
}

original_code:
int
backline(int f, int n)
{
 struct line *dlp;
 if (n < 0)
  return (forwline(f | 8, -n));
 if ((lastflag & 0x0001) == 0)
  setgoal();
 thisflag |= 0x0001;
 dlp = curwp->w_dotp;
 if (((dlp)->l_bp) == curbp->b_headp) {
  if (!(f & 8)) {
   dobeep();
   ewprintf("Beginning of buffer");
  }
  return(1);
 }
 while (n-- && ((dlp)->l_bp) != curbp->b_headp) {
  dlp = ((dlp)->l_bp);
  curwp->w_dotline--;
 }
 if (n > 0 && !(f & 8)) {
  dobeep();
  ewprintf("Beginning of buffer");
 }
 curwp->w_dotp = dlp;
 curwp->w_doto = getgoal(dlp);
 curwp->w_rflag |= 0x02;
 return (1);
}


forwline

decompiled_code:
__int64 __fastcall forwline(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rbp
__int64 v5; // r12
_QWORD *v6; // rax
__int64 v7; // rax

if ( (int)a2 < 0 )
return backline((unsigned int)a1 | 8, -(int)a2);
v4 = *(_QWORD **)(curwp + 32LL);
if ( *(_QWORD **)(curbp + 40LL) != v4 )
{
if ( (lastflag & 1) != 0 )
{
thisflag |= 1u;
if ( (_DWORD)a2 )
goto LABEL_5;
}
else
{
setgoal();
a2 = (unsigned int)a2;
thisflag |= 1u;
if ( (_DWORD)a2 )
{
LABEL_5:
v5 = curwp;
v6 = *(_QWORD **)(curbp + 40LL);
while ( 1 )
{
v4 = (_QWORD *)*v4;
if ( v6 == v4 )
break;
++*(_DWORD *)(v5 + 80);
a2 = (unsigned int)(a2 - 1);
if ( !(_DWORD)a2 )
{
*(_BYTE *)(v5 + 68) |= 2u;
*(_QWORD *)(v5 + 32) = v4;
*(_DWORD *)(v5 + 48) = getgoal((__int64)v4);
return 1LL;
}
}
v7 = v6[1];
*(_QWORD *)(v5 + 32) = v7;
LODWORD(v7) = *(_DWORD *)(v7 + 20);
*(_BYTE *)(v5 + 68) |= 2u;
*(_DWORD *)(v5 + 48) = v7;
if ( (a1 & 8) == 0 )
goto LABEL_14;
return 1LL;
}
}
return 1LL;
}
if ( (a1 & 8) != 0 )
return 1LL;
LABEL_14:
dobeep(a1, a2, a3, a4);
ewprintf("End of buffer");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rbp
__int64 v5; // r12
_QWORD *v6; // rax
__int64 v7; // rax

if ( (int)a2 < 0 )
return func6((unsigned int)a1 | 8, -(int)a2);
v4 = *(_QWORD **)(curwp + 32LL);
if ( *(_QWORD **)(curbp + 40LL) != v4 )
{
if ( (lastflag & 1) != 0 )
{
thisflag |= 1u;
if ( (_DWORD)a2 )
goto LABEL_5;
}
else
{
func4();
a2 = (unsigned int)a2;
thisflag |= 1u;
if ( (_DWORD)a2 )
{
LABEL_5:
v5 = curwp;
v6 = *(_QWORD **)(curbp + 40LL);
while ( 1 )
{
v4 = (_QWORD *)*v4;
if ( v6 == v4 )
break;
++*(_DWORD *)(v5 + 80);
a2 = (unsigned int)(a2 - 1);
if ( !(_DWORD)a2 )
{
*(_BYTE *)(v5 + 68) |= 2u;
*(_QWORD *)(v5 + 32) = v4;
*(_DWORD *)(v5 + 48) = func5((__int64)v4);
return 1LL;
}
}
v7 = v6[1];
*(_QWORD *)(v5 + 32) = v7;
LODWORD(v7) = *(_DWORD *)(v7 + 20);
*(_BYTE *)(v5 + 68) |= 2u;
*(_DWORD *)(v5 + 48) = v7;
if ( (a1 & 8) == 0 )
goto LABEL_14;
return 1LL;
}
}
return 1LL;
}
if ( (a1 & 8) != 0 )
return 1LL;
LABEL_14:
dobeep(a1, a2, a3, a4);
ewprintf("End of buffer");
return 1LL;
}

original_code:
int
forwline(int f, int n)
{
 struct line *dlp;
 if (n < 0)
  return (backline(f | 8, -n));
 if ((dlp = curwp->w_dotp) == curbp->b_headp) {
  if (!(f & 8)) {
   dobeep();
   ewprintf("End of buffer");
  }
  return(1);
 }
 if ((lastflag & 0x0001) == 0)
  setgoal();
 thisflag |= 0x0001;
 if (n == 0)
  return (1);
 while (n--) {
  dlp = ((dlp)->l_fp);
  if (dlp == curbp->b_headp) {
   curwp->w_dotp = ((dlp)->l_bp);
   curwp->w_doto = ((curwp->w_dotp)->l_used);
   curwp->w_rflag |= 0x02;
   if (!(f & 8)) {
    dobeep();
    ewprintf("End of buffer");
   }
   return (1);
  }
  curwp->w_dotline++;
 }
 curwp->w_rflag |= 0x02;
 curwp->w_dotp = dlp;
 curwp->w_doto = getgoal(dlp);
 return (1);
}


backpage

decompiled_code:
__int64 __fastcall backpage(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
_QWORD *v3; // rbp
_QWORD *i; // rbx
bool v5; // cf
int v6; // edi
_QWORD *v7; // rax
int v8; // edx
_QWORD *v9; // rsi
int v10; // edx
__int64 result; // rax

if ( (a1 & 7) != 0 )
{
if ( (int)a2 < 0 )
return forwpage((unsigned int)a1 | 8, (unsigned int)-(int)a2);
v2 = curwp;
}
else
{
v2 = curwp;
LODWORD(a2) = *(_DWORD *)(curwp + 60LL) - 2;
if ( (int)a2 <= 0 )
return backline(a1, 1);
}
v3 = *(_QWORD **)(v2 + 24);
for ( i = v3; ; i = (_QWORD *)i[1] )
{
v5 = (_DWORD)a2 == 0;
a2 = (unsigned int)(a2 - 1);
if ( v5 || i[1] == *(_QWORD *)(curbp + 40LL) )
break;
}
if ( i == v3 )
{
dobeep(a1, a2, curbp, v2);
ewprintf("Beginning of buffer");
v2 = curwp;
}
v6 = *(_DWORD *)(v2 + 60);
*(_BYTE *)(v2 + 68) |= 8u;
*(_QWORD *)(v2 + 24) = i;
v7 = *(_QWORD **)(v2 + 32);
if ( v6 )
{
v8 = v6;
do
{
if ( *(_QWORD **)(curbp + 40LL) == i )
break;
if ( i == v7 )
goto LABEL_18;
i = (_QWORD *)*i;
--v8;
}
while ( v8 );
}
v9 = (_QWORD *)*v3;
if ( (_QWORD *)*v3 == v7 )
{
LABEL_21:
*(_DWORD *)(v2 + 48) = 0;
result = 1LL;
}
else
{
v10 = *(_DWORD *)(v2 + 80);
while ( v6 < v10 )
{
v7 = (_QWORD *)v7[1];
*(_DWORD *)(v2 + 80) = --v10;
*(_QWORD *)(v2 + 32) = v7;
if ( v7 == v9 )
goto LABEL_21;
}
LABEL_18:
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
_QWORD *v3; // rbp
_QWORD *i; // rbx
bool v5; // cf
int v6; // edi
_QWORD *v7; // rax
int v8; // edx
_QWORD *v9; // rsi
int v10; // edx
__int64 result; // rax

if ( (a1 & 7) != 0 )
{
if ( (int)a2 < 0 )
return func9((unsigned int)a1 | 8, (unsigned int)-(int)a2);
v2 = curwp;
}
else
{
v2 = curwp;
LODWORD(a2) = *(_DWORD *)(curwp + 60LL) - 2;
if ( (int)a2 <= 0 )
return func6(a1, 1);
}
v3 = *(_QWORD **)(v2 + 24);
for ( i = v3; ; i = (_QWORD *)i[1] )
{
v5 = (_DWORD)a2 == 0;
a2 = (unsigned int)(a2 - 1);
if ( v5 || i[1] == *(_QWORD *)(curbp + 40LL) )
break;
}
if ( i == v3 )
{
dobeep(a1, a2, curbp, v2);
ewprintf("Beginning of buffer");
v2 = curwp;
}
v6 = *(_DWORD *)(v2 + 60);
*(_BYTE *)(v2 + 68) |= 8u;
*(_QWORD *)(v2 + 24) = i;
v7 = *(_QWORD **)(v2 + 32);
if ( v6 )
{
v8 = v6;
do
{
if ( *(_QWORD **)(curbp + 40LL) == i )
break;
if ( i == v7 )
goto LABEL_18;
i = (_QWORD *)*i;
--v8;
}
while ( v8 );
}
v9 = (_QWORD *)*v3;
if ( (_QWORD *)*v3 == v7 )
{
LABEL_21:
*(_DWORD *)(v2 + 48) = 0;
result = 1LL;
}
else
{
v10 = *(_DWORD *)(v2 + 80);
while ( v6 < v10 )
{
v7 = (_QWORD *)v7[1];
*(_DWORD *)(v2 + 80) = --v10;
*(_QWORD *)(v2 + 32) = v7;
if ( v7 == v9 )
goto LABEL_21;
}
LABEL_18:
result = 1LL;
}
return result;
}

original_code:
int
backpage(int f, int n)
{
 struct line *lp, *lp2;
 if (!(f & 7)) {
  n = curwp->w_ntrows - 2;
  if (n <= 0)
   return (backline(f, 1));
 } else if (n < 0)
  return (forwpage(f | 8, -n));
 lp = lp2 = curwp->w_linep;
 while (n-- && ((lp)->l_bp) != curbp->b_headp) {
  lp = ((lp)->l_bp);
 }
 if (lp == curwp->w_linep) {
  dobeep();
  ewprintf("Beginning of buffer");
 }
 curwp->w_linep = lp;
 curwp->w_rflag |= 0x08;
 for (n = curwp->w_ntrows; n-- && lp != curbp->b_headp; lp = ((lp)->l_fp))
  if (lp == curwp->w_dotp)
   return (1);
        lp2 = ((lp2)->l_fp);
 while (curwp->w_dotp != lp2) {
                if (curwp->w_dotline <= curwp->w_ntrows)
                        return (1);
  curwp->w_dotp = ((curwp->w_dotp)->l_bp);
  curwp->w_dotline--;
 }
 curwp->w_doto = 0;
 return (1);
}

canonical_original_code:
int backpage(int f, int n)
{
 struct line *lp; struct line *lp2;
 if (!(f & 7)) {
  n = curwp->w_ntrows - 2;
  if (n <= 0)
   return (backline(f, 1));
 } else if (n < 0)
  return (forwpage(f | 8, -n));
 lp = lp2 = curwp->w_linep;
 while (n-- && ((lp)->l_bp) != curbp->b_headp) {
  lp = ((lp)->l_bp);
 }
 if (lp == curwp->w_linep) {
  dobeep();
  ewprintf("Beginning of buffer");
 }
 curwp->w_linep = lp;
 curwp->w_rflag |= 0x08;
 for (n = curwp->w_ntrows; n-- && lp != curbp->b_headp; lp = ((lp)->l_fp))
  if (lp == curwp->w_dotp)
   return (1);
        lp2 = ((lp2)->l_fp);
 while (curwp->w_dotp != lp2) {
                if (curwp->w_dotline <= curwp->w_ntrows)
                        return (1);
  curwp->w_dotp = ((curwp->w_dotp)->l_bp);
  curwp->w_dotline--;
 }
 curwp->w_doto = 0;
 return (1);
}


forwpage

original_code:
int
forwpage(int f, int n)
{
 struct line *lp;
 if (!(f & 7)) {
  n = curwp->w_ntrows - 2;
  if (n <= 0)
   n = 1;
 } else if (n < 0)
  return (backpage(f | 8, -n));
 lp = curwp->w_linep;
 while (n--)
  if ((lp = ((lp)->l_fp)) == curbp->b_headp) {
   dobeep();
   ewprintf("End of buffer");
   return(1);
  }
 curwp->w_linep = lp;
 curwp->w_rflag |= 0x08;
 for (n = curwp->w_ntrows; n-- && lp != curbp->b_headp; lp = ((lp)->l_fp))
  if (lp == curwp->w_dotp)
   return (1);
 while (curwp->w_dotp != curwp->w_linep) {
  curwp->w_dotp = ((curwp->w_dotp)->l_fp);
  curwp->w_dotline++;
 }
 curwp->w_doto = 0;
 return (1);
}


decompiled_code:
__int64 __fastcall forw1page(int a1, __int64 a2, __int64 a3, __int64 a4)
{
if ( (a1 & 7) != 0 )
forwpage(a1 | 8, a2, a3, a4);
else
forwpage(9, 1LL, a3, a4);
return 1LL;
}

original_code:
int
forw1page(int f, int n)
{
 if (!(f & 7)) {
  n = 1;
  f = 1;
 }
 forwpage(f | 8, n);
 return (1);
}


decompiled_code:
__int64 __fastcall back1page(int a1, __int64 a2)
{
if ( (a1 & 7) != 0 )
backpage(a1 | 8u, a2);
else
backpage(9LL, 1LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int64 a2)
{
if ( (a1 & 7) != 0 )
func8(a1 | 8u, a2);
else
func8(9LL, 1LL);
return 1LL;
}

original_code:
int
back1page(int f, int n)
{
 if (!(f & 7)) {
  n = 1;
  f = 1;
 }
 backpage(f | 8, n);
 return (1);
}


isetmark

decompiled_code:
_DWORD *isetmark()
{
_DWORD *result; // rax

result = (_DWORD *)curwp;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
result[13] = result[12];
result[21] = result[20];
return result;
}

canonical_decompiled_code:
_DWORD *func13()
{
_DWORD *result; // rax

result = (_DWORD *)curwp;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
result[13] = result[12];
result[21] = result[20];
return result;
}

original_code:
void
isetmark(void)
{
 curwp->w_markp = curwp->w_dotp;
 curwp->w_marko = curwp->w_doto;
 curwp->w_markline = curwp->w_dotline;
}

canonical_original_code:
void isetmark()
{
 curwp->w_markp = curwp->w_dotp;
 curwp->w_marko = curwp->w_doto;
 curwp->w_markline = curwp->w_dotline;
}


setmark

decompiled_code:
__int64 setmark()
{
isetmark();
ewprintf("Mark set");
return 1LL;
}

canonical_decompiled_code:
__int64 func14()
{
func13();
ewprintf("Mark set");
return 1LL;
}

original_code:
int
setmark(int f, int n)
{
 isetmark();
 ewprintf("Mark set");
 return (1);
}


gotobob

original_code:
int
gotobob(int f, int n)
{
 (void) setmark(f, n);
 curwp->w_dotp = ((((curbp)->b_headp)->l_fp));
 curwp->w_doto = 0;
 curwp->w_rflag |= 0x08;
 curwp->w_dotline = 1;
 return (1);
}


gotoeob

original_code:
int
gotoeob(int f, int n)
{
 struct line *lp;
 (void) setmark(f, n);
 curwp->w_dotp = ((((curbp)->b_headp)->l_bp));
 curwp->w_doto = ((curwp->w_dotp)->l_used);
 curwp->w_dotline = curwp->w_bufp->b_lines;
 lp = curwp->w_dotp;
 n = curwp->w_ntrows - 3;
 if (n < curwp->w_bufp->b_lines && n >= 3) {
  while (n--)
   curwp->w_dotp = ((curwp->w_dotp)->l_bp);
  curwp->w_linep = curwp->w_dotp;
  curwp->w_dotp = lp;
 }
 curwp->w_rflag |= 0x08;
 return (1);
}


clearmark

decompiled_code:
__int64 clearmark()
{
__int64 v0; // rax

v0 = curwp;
if ( !*(_QWORD *)(curwp + 40LL) )
return 0LL;
*(_QWORD *)(curwp + 40LL) = 0LL;
*(_DWORD *)(v0 + 52) = 0;
*(_DWORD *)(v0 + 84) = 0;
return 1LL;
}

original_code:
int
clearmark(int f, int n)
{
 if (!curwp->w_markp)
  return (0);
 curwp->w_markp = ((void *)0);
 curwp->w_marko = 0;
 curwp->w_markline = 0;
 return (1);
}


swapmark

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

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


gotoline

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

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

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

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

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

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

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char **a2)
{
char *v2; // rax
char *v3; // r12
char *v4; // rax
char *v5; // rbp
char *v6; // rax

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

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; // rbp
__int64 *j; // rdi
__int64 v2; // rax
_QWORD *v3; // rdx
_QWORD *v4; // rax
_QWORD *v5; // rdx

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

canonical_decompiled_code:
void func1()
{
void **i; // rbp
__int64 *j; // rdi
__int64 v2; // rax
_QWORD *v3; // rdx
_QWORD *v4; // rax
_QWORD *v5; // rdx

for ( i = (void **)csrecords; csrecords; i = (void **)csrecords )
{
free(i[2]);
for ( j = (__int64 *)i[3]; j; j = (__int64 *)i[3] )
{
v2 = *j;
v3 = (_QWORD *)j[1];
if ( *j )
*(_QWORD *)(v2 + 8) = v3;
else
i[4] = v3;
*v3 = v2;
free(j);
}
v4 = *i;
v5 = i[1];
if ( *i )
v4[1] = v5;
else
off_D88 = (__int64 *)i[1];
*v5 = v4;
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; } *

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)
{
_BOOL4 v2; // er12
char *v4; // rdi
char *v5; // r13
int v6; // ebx
char *v7; // rax
const char *v8; // r12
int v9; // edx
__int64 v10; // rax
int v11; // edx
char *stringp; // [rsp+8h] [rbp-430h] BYREF
char sa[1064]; // [rsp+10h] [rbp-428h] BYREF

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

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

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

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()
{
_QWORD *v1; // rax

if ( curmatch )
{
if ( *(_QWORD *)curmatch )
{
curmatch = *(_QWORD *)curmatch;
return jumptomatch();
}
v1 = *(_QWORD **)currecord;
if ( *(_QWORD *)currecord )
goto LABEL_5;
dobeep();
ewprintf("The end of *cscope* buffer has been reached");
}
else
{
v1 = csrecords;
if ( csrecords )
{
LABEL_5:
currecord = (__int64)v1;
curmatch = v1[3];
return jumptomatch();
}
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
}
return 0LL;
}

canonical_decompiled_code:
__int64 func17()
{
_QWORD *v1; // rax

if ( curmatch )
{
if ( *(_QWORD *)curmatch )
{
curmatch = *(_QWORD *)curmatch;
return func7();
}
v1 = *(_QWORD **)currecord;
if ( *(_QWORD *)currecord )
goto LABEL_5;
dobeep();
ewprintf("The end of *cscope* buffer has been reached");
}
else
{
v1 = csrecords;
if ( csrecords )
{
LABEL_5:
currecord = (__int64)v1;
curmatch = v1[3];
return func7();
}
dobeep();
ewprintf("The *cscope* buffer does not exist yet");
}
return 0LL;
}

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

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

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

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

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()
{
_QWORD *v0; // rax

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

canonical_decompiled_code:
__int64 func19()
{
_QWORD *v0; // rax

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

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()
{
_QWORD *v0; // rax

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

canonical_decompiled_code:
__int64 func20()
{
_QWORD *v0; // rax

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

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


grep

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

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

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

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

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