decompiled_code:
__int64 compile_goto_error()
{
__int64 v0; // rdx
__int64 v1; // rdi
__int64 v2; // rbx
__int64 v3; // rax
__int64 *v4; // rdx
__int64 v5; // rdi
char *v6; // rax
char *v7; // rbp
char *v8; // rax
char *v9; // r12
char *v10; // rax
unsigned int v11; // er13
char *v12; // r12
__int64 v13; // rax
__int64 v14; // rbx
__int64 v15; // rax
bool v16; // zf
char *v18; // [rsp+0h] [rbp-438h] BYREF
__int64 v19; // [rsp+8h] [rbp-430h] BYREF
char v20[1064]; // [rsp+10h] [rbp-428h] BYREF

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

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdx
__int64 v1; // rdi
__int64 v2; // rbx
__int64 v3; // rax
__int64 *v4; // rdx
__int64 v5; // rdi
char *v6; // rax
char *v7; // rbp
char *v8; // rax
char *v9; // r12
char *v10; // rax
unsigned int v11; // er13
char *v12; // r12
__int64 v13; // rax
__int64 v14; // rbx
__int64 v15; // rax
bool v16; // zf
char *v18; // [rsp+0h] [rbp-438h] BYREF
__int64 v19; // [rsp+8h] [rbp-430h] BYREF
char v20[1064]; // [rsp+10h] [rbp-428h] BYREF

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

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

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

variable_types:
fname
char *

variable_types:
line
char *

variable_types:
lp
char *

variable_types:
ln
char *

variable_types: lineno int

variable_types:
adjf
char *

variable_types:
path
char [1024]

variable_types:
errstr
char *

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


repo: scott-parker/mg-openbsd

decompiled_code:
__int64 next_error()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 *v2; // rcx
__int64 v3; // rdx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 *v2; // rcx
__int64 v3; // rdx
__int64 result; // rax

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

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

variable_types: f int

variable_types: n int

return_type: int


compile

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

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

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

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

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

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

variable_types:
cprompt
char [1024]

variable_types:
bufp
char *

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

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

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

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

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

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

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

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

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


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

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

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

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

return_type: void

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


globalwdtoggle

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

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

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

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

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


gotoeop

decompiled_code:
__int64 __fastcall gotoeop(__int64 a1, int a2)
{
__int64 v2; // r14
_QWORD *v3; // r15
_QWORD *v4; // rbx
_QWORD *v5; // r13
int v6; // ebp
int v7; // er12
const unsigned __int16 *v8; // rcx
unsigned __int8 *v9; // rax
__int64 v10; // rsi
_QWORD *v11; // rax
__int64 result; // rax
int v13; // [rsp+Ch] [rbp-3Ch]

if ( a2 < 0 )
return gotobop(a1, (unsigned int)-a2);
v2 = curwp;
v13 = a2 - 1;
if ( a2 )
{
v3 = *(_QWORD **)(curwp + 32LL);
v4 = *(_QWORD **)(curbp + 40LL);
v5 = (_QWORD *)*v3;
while ( 1 )
{
v6 = 0;
if ( v4 != v5 )
break;
LABEL_12:
if ( --v13 == -1 )
goto LABEL_13;
}
while ( 1 )
{
v7 = *((_DWORD *)v3 + 5);
*(_DWORD *)(v2 + 48) = 0;
if ( v7 <= 0 )
{
LABEL_14:
if ( v6 )
goto LABEL_12;
}
else
{
v8 = *_ctype_b_loc();
v9 = (unsigned __int8 *)v3[3];
v10 = (__int64)&v9[v7 - 1 + 1];
while ( (v8[*v9] & 0x2000) != 0 )
{
if ( (unsigned __int8 *)v10 == ++v9 )
goto LABEL_14;
}
v6 = 1;
}
v11 = (_QWORD *)*v5;
++*(_DWORD *)(v2 + 80);
v3 = v5;
*(_QWORD *)(v2 + 32) = v5;
if ( v11 == v4 )
break;
v5 = v11;
if ( v4 == v11 )
goto LABEL_12;
}
gotoeol(8LL, 1LL);
*(_BYTE *)(curwp + 68LL) |= 2u;
result = 0LL;
}
else
{
LABEL_13:
*(_BYTE *)(v2 + 68) |= 2u;
result = 1LL;
}
return result;
}

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

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

variable_types: col int

variable_types: nospace int


gotobop

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

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


fillpara

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

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

variable_types: c int

variable_types: wordlen int

variable_types: clength int

variable_types: i int

variable_types: eopflag int

variable_types: firstflag int

variable_types: newlength int

variable_types: eolflag int

variable_types: retval int

variable_types:
wbuf
char [256]

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


killpara

decompiled_code:
__int64 __fastcall killpara(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v4; // rax
__int64 v5; // rax

while ( 1 )
{
if ( !a2 )
return 1LL;
if ( !(unsigned int)gotoeop(8LL, 1) )
break;
v5 = curwp;
--a2;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
*(_DWORD *)(v5 + 52) = *(_DWORD *)(v5 + 48);
gotobop(8LL, 1);
*(_DWORD *)(curwp + 48LL) = 0;
result = killregion(8LL, 1LL);
if ( (_DWORD)result != 1 )
return result;
}
v4 = curwp;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
*(_DWORD *)(v4 + 52) = *(_DWORD *)(v4 + 48);
gotobop(8LL, 1);
*(_DWORD *)(curwp + 48LL) = 0;
return killregion(8LL, 1LL);
}

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

while ( 1 )
{
if ( !a2 )
return 1LL;
if ( !(unsigned int)func0(8LL, 1) )
break;
v5 = curwp;
--a2;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
*(_DWORD *)(v5 + 52) = *(_DWORD *)(v5 + 48);
func1(8LL, 1);
*(_DWORD *)(curwp + 48LL) = 0;
result = killregion(8LL, 1LL);
if ( (_DWORD)result != 1 )
return result;
}
v4 = curwp;
*(_QWORD *)(curwp + 40LL) = *(_QWORD *)(curwp + 32LL);
*(_DWORD *)(v4 + 52) = *(_DWORD *)(v4 + 48);
func1(8LL, 1);
*(_DWORD *)(curwp + 48LL) = 0;
return killregion(8LL, 1LL);
}

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

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

variable_types: f int

variable_types: n int

variable_types: status int

variable_types: end int


fillword

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

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

variable_types: c char

variable_types: nce int


setfillcol

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

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

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

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

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

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

variable_types:
buf
char [32]

variable_types:
rep
char *

variable_types:
es
char *

variable_types: nfill int


kgrow

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

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

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

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

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

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

variable_types: dir int

variable_types: nstart int

variable_types:
nbufp
char *


kdelete

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

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

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

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


kinsert

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

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

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

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

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

variable_types: c int


kremove

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

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

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

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

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


kchunk

decompiled_code:
__int64 __fastcall kchunk(void *src, int a2, int a3)
{
int v3; // ebx
int v4; // eax
int v5; // ebp
__int64 result; // rax
__int64 v7; // rbx

v3 = kused;
v4 = kstart;
if ( kused == kstart )
{
v5 = 1;
while ( 1 )
{
LABEL_7:
if ( ksize - v3 >= a2 )
{
memmove((char *)kbufp + v3, src, a2);
kused = a2 + v3;
return 1LL;
}
if ( !(unsigned int)kgrow(v5) )
break;
v3 = kused;
}
LABEL_13:
result = 0LL;
}
else
{
v5 = a3;
if ( (a3 & 1) != 0 )
goto LABEL_7;
if ( (a3 & 2) != 0 )
{
while ( a2 > v4 )
{
if ( !(unsigned int)kgrow(v5) )
goto LABEL_13;
v4 = kstart;
}
v7 = v4 - a2;
memmove((char *)kbufp + v7, src, a2);
kstart = v7;
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *src, int a2, int a3)
{
int v3; // ebx
int v4; // eax
int v5; // ebp
__int64 result; // rax
__int64 v7; // rbx

v3 = kused;
v4 = kstart;
if ( kused == kstart )
{
v5 = 1;
while ( 1 )
{
LABEL_7:
if ( ksize - v3 >= a2 )
{
memmove((char *)kbufp + v3, src, a2);
kused = a2 + v3;
return 1LL;
}
if ( !(unsigned int)func0(v5) )
break;
v3 = kused;
}
LABEL_13:
result = 0LL;
}
else
{
v5 = a3;
if ( (a3 & 1) != 0 )
goto LABEL_7;
if ( (a3 & 2) != 0 )
{
while ( a2 > v4 )
{
if ( !(unsigned int)func0(v5) )
goto LABEL_13;
v4 = kstart;
}
v7 = v4 - a2;
memmove((char *)kbufp + v7, src, a2);
kstart = v7;
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

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

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

variable_types: chunk int

variable_types: kflag int


killline

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

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

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

variable_types: i int


yank

decompiled_code:
__int64 __fastcall yank(__int64 a1, int a2)
{
int v2; // er12
int v3; // ebp
int i; // ebx
int v5; // esi
__int64 v6; // rcx
__int64 v7; // rdx
bool v9; // cf

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // er12
int v3; // ebp
int i; // ebx
int v5; // esi
__int64 v6; // rcx
__int64 v7; // rdx
bool v9; // cf

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

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

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

variable_types: f int

variable_types: n int

variable_types: nline int


inword

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

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

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

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

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

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


forwword

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

if ( a2 < 0 )
return backword(a1 | 8u, (unsigned int)-a2);
if ( !a2 )
return 1LL;
v2 = a2;
for ( i = inword(); !i; i = inword() )
{
LABEL_4:
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 1LL;
}
while ( (unsigned int)forwchar(8LL, 1LL) )
{
if ( !(unsigned int)inword() )
{
if ( --v2 )
goto LABEL_4;
return 1LL;
}
}
return 1LL;
}

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

if ( a2 < 0 )
return func2(a1 | 8u, (unsigned int)-a2);
if ( !a2 )
return 1LL;
v2 = a2;
for ( i = func0(); !i; i = func0() )
{
LABEL_4:
if ( !(unsigned int)forwchar(8LL, 1LL) )
return 1LL;
}
while ( (unsigned int)forwchar(8LL, 1LL) )
{
if ( !(unsigned int)func0() )
{
if ( --v2 )
goto LABEL_4;
return 1LL;
}
}
return 1LL;
}

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


backword

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

v2 = a2;
if ( a2 < 0 )
return forwword(a1 | 8u, -a2);
result = backchar(8LL, 1LL);
if ( (_DWORD)result )
{
if ( a2 )
{
while ( !(unsigned int)inword() )
{
LABEL_5:
if ( !(unsigned int)backchar(8LL, 1LL) )
goto LABEL_11;
}
while ( (unsigned int)backchar(8LL, 1LL) )
{
if ( !(unsigned int)inword() )
{
if ( --v2 )
goto LABEL_5;
goto LABEL_10;
}
}
LABEL_11:
result = 1LL;
}
else
{
LABEL_10:
result = forwchar(8LL, 1LL);
}
}
return result;
}

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

v2 = a2;
if ( a2 < 0 )
return func1(a1 | 8u, -a2);
result = backchar(8LL, 1LL);
if ( (_DWORD)result )
{
if ( a2 )
{
while ( !(unsigned int)func0() )
{
LABEL_5:
if ( !(unsigned int)backchar(8LL, 1LL) )
goto LABEL_11;
}
while ( (unsigned int)backchar(8LL, 1LL) )
{
if ( !(unsigned int)func0() )
{
if ( --v2 )
goto LABEL_5;
goto LABEL_10;
}
}
LABEL_11:
result = 1LL;
}
else
{
LABEL_10:
result = forwchar(8LL, 1LL);
}
}
return result;
}

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


countfword

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

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

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

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

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

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

variable_types: size int

variable_types: doto int


upperword

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

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

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

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

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

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

variable_types: s int


lowerword

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

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

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

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

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

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


capword

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

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

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

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

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

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


delfword

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

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

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

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

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

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


delbword

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

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

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

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

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

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


decompiled_code:
__int64 re_readpattern()
{
_BYTE *v0; // rax
__int64 result; // rax
int v2; // er12
int v3; // eax
char _0[80]; // [rsp+0h] [rbp+0h] BYREF
char errbuf[280]; // [rsp+50h] [rbp+50h] BYREF

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

canonical_decompiled_code:
__int64 func0()
{
_BYTE *v0; // rax
__int64 result; // rax
int v2; // er12
int v3; // eax
char _0[80]; // [rsp+0h] [rbp+0h] BYREF
char errbuf[280]; // [rsp+50h] [rbp+50h] BYREF

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

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

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

variable_types:
prompt
char *

variable_types: dofree int

variable_types: flags int

variable_types: error int

variable_types:
tpat
char [80]

variable_types:
rep
char *

variable_types:
message
char [256]


decompiled_code:
__int64 re_forwsrch()
{
__int64 *v0; // rbx
regoff_t v1; // eax
int v2; // ebp
__int64 *v3; // rdx
const char *v4; // rsi
__int64 v5; // rax
regoff_t v6; // edx

v0 = *(__int64 **)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = *(_DWORD *)(curwp + 80LL);
v3 = *(__int64 **)(curbp + 40LL);
if ( *((_DWORD *)v0 + 5) == v1 )
{
if ( v3 == v0 )
return 0LL;
v0 = (__int64 *)*v0;
++v2;
v1 = 0;
}
if ( v3 == v0 )
return 0LL;
while ( 1 )
{
regex_match[0].rm_so = v1;
v4 = (const char *)v0[3];
regex_match[0].rm_eo = *((_DWORD *)v0 + 5);
if ( !regexec(&regex_buff, v4, 0xAuLL, regex_match, 4) )
break;
v0 = (__int64 *)*v0;
++v2;
v1 = 0;
if ( *(__int64 **)(curbp + 40LL) == v0 )
return 0LL;
}
v5 = curwp;
v6 = regex_match[0].rm_eo;
*(_BYTE *)(curwp + 68LL) |= 2u;
*(_DWORD *)(v5 + 48) = v6;
*(_QWORD *)(v5 + 32) = v0;
*(_DWORD *)(v5 + 80) = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 *v0; // rbx
regoff_t v1; // eax
int v2; // ebp
__int64 *v3; // rdx
const char *v4; // rsi
__int64 v5; // rax
regoff_t v6; // edx

v0 = *(__int64 **)(curwp + 32LL);
v1 = *(_DWORD *)(curwp + 48LL);
v2 = *(_DWORD *)(curwp + 80LL);
v3 = *(__int64 **)(curbp + 40LL);
if ( *((_DWORD *)v0 + 5) == v1 )
{
if ( v3 == v0 )
return 0LL;
v0 = (__int64 *)*v0;
++v2;
v1 = 0;
}
if ( v3 == v0 )
return 0LL;
while ( 1 )
{
regex_match[0].rm_so = v1;
v4 = (const char *)v0[3];
regex_match[0].rm_eo = *((_DWORD *)v0 + 5);
if ( !regexec(&regex_buff, v4, 0xAuLL, regex_match, 4) )
break;
v0 = (__int64 *)*v0;
++v2;
v1 = 0;
if ( *(__int64 **)(curbp + 40LL) == v0 )
return 0LL;
}
v5 = curwp;
v6 = regex_match[0].rm_eo;
*(_BYTE *)(curwp + 68LL) |= 2u;
*(_DWORD *)(v5 + 48) = v6;
*(_QWORD *)(v5 + 32) = v0;
*(_DWORD *)(v5 + 80) = v2;
return 1LL;
}

original_code:
static int
re_forwsrch(void)
{
 int tbo, tdotline, error;
 struct line *clp;
 clp = curwp->w_dotp;
 tbo = curwp->w_doto;
 tdotline = curwp->w_dotline;
 if (tbo == clp->l_used)
  if (clp != curbp->b_headp) {
   clp = ((clp)->l_fp);
   tdotline++;
   tbo = 0;
  }
 while (clp != (curbp->b_headp)) {
  regex_match[0].rm_so = tbo;
  regex_match[0].rm_eo = ((clp)->l_used);
  error = regexec(&regex_buff, ((clp)->l_text), 10, regex_match,
      (1 << 2));
  if (error != 0) {
   clp = ((clp)->l_fp);
   tdotline++;
   tbo = 0;
  } else {
   curwp->w_doto = regex_match[0].rm_eo;
   curwp->w_dotp = clp;
   curwp->w_dotline = tdotline;
   curwp->w_rflag |= 0x02;
   return (1);
  }
 }
 return (0);
}

canonical_original_code:
static int re_forwsrch()
{
 int tbo; int tdotline; int error;
 struct line *clp;
 clp = curwp->w_dotp;
 tbo = curwp->w_doto;
 tdotline = curwp->w_dotline;
 if (tbo == clp->l_used)
  if (clp != curbp->b_headp) {
   clp = ((clp)->l_fp);
   tdotline++;
   tbo = 0;
  }
 while (clp != (curbp->b_headp)) {
  regex_match[0].rm_so = tbo;
  regex_match[0].rm_eo = ((clp)->l_used);
  error = regexec(&regex_buff, ((clp)->l_text), 10, regex_match,
      (1 << 2));
  if (error != 0) {
   clp = ((clp)->l_fp);
   tdotline++;
   tbo = 0;
  } else {
   curwp->w_doto = regex_match[0].rm_eo;
   curwp->w_dotp = clp;
   curwp->w_dotline = tdotline;
   curwp->w_rflag |= 0x02;
   return (1);
  }
 }
 return (0);
}

variable_types: tbo int

variable_types: tdotline int


decompiled_code:
__int64 __fastcall re_backsrch()
{
regmatch_t v0; // rbx
__int64 v1; // r14
int v2; // er12
regoff_t v3; // ebp
regoff_t i; // eax
__int64 v6; // rax

v1 = *(_QWORD *)(curwp + 32LL);
v2 = *(_DWORD *)(curwp + 80LL);
v3 = *(_DWORD *)(curwp + 48LL) - 1;
if ( v3 < 0 )
{
v1 = *(_QWORD *)(v1 + 8);
--v2;
v3 = *(_DWORD *)(v1 + 20);
}
if ( v1 == *(_QWORD *)(curbp + 40LL) )
return 0LL;
for ( i = *(_DWORD *)(v1 + 20); ; i = *(_DWORD *)(v1 + 20) )
{
regex_match[0].rm_so = 0;
v0 = (regmatch_t)(*(unsigned __int64 *)&v0 | 0xFFFFFFFF);
regex_match[0].rm_eo = i;
while ( !regexec(&regex_buff, *(const char **)(v1 + 24), 0xAuLL, regex_match, 4) && regex_match[0].rm_so < v3 )
{
v0 = regex_match[0];
++regex_match[0].rm_so;
regex_match[0].rm_eo = *(_DWORD *)(v1 + 20);
}
if ( v0.rm_so != -1 )
break;
v1 = *(_QWORD *)(v1 + 8);
--v2;
v3 = *(_DWORD *)(v1 + 20);
if ( *(_QWORD *)(curbp + 40LL) == v1 )
return 0LL;
}
v6 = curwp;
regex_match[0] = v0;
*(_BYTE *)(curwp + 68LL) |= 2u;
*(_DWORD *)(v6 + 48) = v0.rm_so;
*(_QWORD *)(v6 + 32) = v1;
*(_DWORD *)(v6 + 80) = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2()
{
regmatch_t v0; // rbx
__int64 v1; // r14
int v2; // er12
regoff_t v3; // ebp
regoff_t i; // eax
__int64 v6; // rax

v1 = *(_QWORD *)(curwp + 32LL);
v2 = *(_DWORD *)(curwp + 80LL);
v3 = *(_DWORD *)(curwp + 48LL) - 1;
if ( v3 < 0 )
{
v1 = *(_QWORD *)(v1 + 8);
--v2;
v3 = *(_DWORD *)(v1 + 20);
}
if ( v1 == *(_QWORD *)(curbp + 40LL) )
return 0LL;
for ( i = *(_DWORD *)(v1 + 20); ; i = *(_DWORD *)(v1 + 20) )
{
regex_match[0].rm_so = 0;
v0 = (regmatch_t)(*(unsigned __int64 *)&v0 | 0xFFFFFFFF);
regex_match[0].rm_eo = i;
while ( !regexec(&regex_buff, *(const char **)(v1 + 24), 0xAuLL, regex_match, 4) && regex_match[0].rm_so < v3 )
{
v0 = regex_match[0];
++regex_match[0].rm_so;
regex_match[0].rm_eo = *(_DWORD *)(v1 + 20);
}
if ( v0.rm_so != -1 )
break;
v1 = *(_QWORD *)(v1 + 8);
--v2;
v3 = *(_DWORD *)(v1 + 20);
if ( *(_QWORD *)(curbp + 40LL) == v1 )
return 0LL;
}
v6 = curwp;
regex_match[0] = v0;
*(_BYTE *)(curwp + 68LL) |= 2u;
*(_DWORD *)(v6 + 48) = v0.rm_so;
*(_QWORD *)(v6 + 32) = v1;
*(_DWORD *)(v6 + 80) = v2;
return 1LL;
}

original_code:
static int
re_backsrch(void)
{
 struct line *clp;
 int tbo, tdotline;
 regmatch_t lastmatch;
 clp = curwp->w_dotp;
 tbo = curwp->w_doto;
 tdotline = curwp->w_dotline;
 tbo = tbo - 1;
 if (tbo < 0) {
  clp = ((clp)->l_bp);
  tdotline--;
  tbo = ((clp)->l_used);
 }
 while (clp != (curbp->b_headp)) {
  regex_match[0].rm_so = 0;
  regex_match[0].rm_eo = ((clp)->l_used);
  lastmatch.rm_so = -1;
  while (!regexec(&regex_buff, ((clp)->l_text), 10, regex_match,
      (1 << 2)) && regex_match[0].rm_so < tbo) {
   memcpy(&lastmatch, &regex_match[0], sizeof(regmatch_t));
   regex_match[0].rm_so++;
   regex_match[0].rm_eo = ((clp)->l_used);
  }
  if (lastmatch.rm_so == -1) {
   clp = ((clp)->l_bp);
   tdotline--;
   tbo = ((clp)->l_used);
  } else {
   memcpy(&regex_match[0], &lastmatch, sizeof(regmatch_t));
   curwp->w_doto = regex_match[0].rm_so;
   curwp->w_dotp = clp;
   curwp->w_dotline = tdotline;
   curwp->w_rflag |= 0x02;
   return (1);
  }
 }
 return (0);
}

canonical_original_code:
static int re_backsrch()
{
 struct line *clp;
 int tbo; int tdotline;
 struct regmatch_t lastmatch;
 clp = curwp->w_dotp;
 tbo = curwp->w_doto;
 tdotline = curwp->w_dotline;
 tbo = tbo - 1;
 if (tbo < 0) {
  clp = ((clp)->l_bp);
  tdotline--;
  tbo = ((clp)->l_used);
 }
 while (clp != (curbp->b_headp)) {
  regex_match[0].rm_so = 0;
  regex_match[0].rm_eo = ((clp)->l_used);
  lastmatch.rm_so = -1;
  while (!regexec(&regex_buff, ((clp)->l_text), 10, regex_match,
      (1 << 2)) && regex_match[0].rm_so < tbo) {
   memcpy(&lastmatch, &regex_match[0], sizeof(regmatch_t));
   regex_match[0].rm_so++;
   regex_match[0].rm_eo = ((clp)->l_used);
  }
  if (lastmatch.rm_so == -1) {
   clp = ((clp)->l_bp);
   tdotline--;
   tbo = ((clp)->l_used);
  } else {
   memcpy(&regex_match[0], &lastmatch, sizeof(regmatch_t));
   curwp->w_doto = regex_match[0].rm_so;
   curwp->w_dotp = clp;
   curwp->w_dotline = tdotline;
   curwp->w_rflag |= 0x02;
   return (1);
  }
 }
 return (0);
}

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

variable_types: struct regmatch_t { int rm_so; int rm_eo; }


countmatches

decompiled_code:
__int64 __fastcall countmatches(int a1)
{
__int64 *v1; // rbx
unsigned int v2; // ebp
regoff_t v3; // eax
const char *v4; // rsi

v1 = *(__int64 **)(curwp + 32LL);
if ( *(_DWORD *)(curwp + 48LL) == *((_DWORD *)v1 + 5) )
v1 = (__int64 *)*v1;
if ( *(__int64 **)(curbp + 40LL) != v1 )
{
v2 = 0;
while ( 1 )
{
v3 = *((_DWORD *)v1 + 5);
v4 = (const char *)v1[3];
regex_match[0].rm_so = 0;
regex_match[0].rm_eo = v3;
if ( regexec(&regex_buff, v4, 0xAuLL, regex_match, 4) )
break;
if ( (a1 & 1) != 0 )
{
LABEL_5:
++v2;
LABEL_6:
v1 = (__int64 *)*v1;
if ( *(__int64 **)(curbp + 40LL) == v1 )
goto LABEL_12;
}
else
{
v1 = (__int64 *)*v1;
if ( *(__int64 **)(curbp + 40LL) == v1 )
goto LABEL_12;
}
}
if ( (((unsigned __int8)a1 ^ 1) & 1) == 0 )
goto LABEL_6;
goto LABEL_5;
}
v2 = 0;
LABEL_12:
if ( a1 )
ewprintf("Number of lines matching: %d", v2);
else
ewprintf("Number of lines not matching: %d", v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 *v1; // rbx
unsigned int v2; // ebp
regoff_t v3; // eax
const char *v4; // rsi

v1 = *(__int64 **)(curwp + 32LL);
if ( *(_DWORD *)(curwp + 48LL) == *((_DWORD *)v1 + 5) )
v1 = (__int64 *)*v1;
if ( *(__int64 **)(curbp + 40LL) != v1 )
{
v2 = 0;
while ( 1 )
{
v3 = *((_DWORD *)v1 + 5);
v4 = (const char *)v1[3];
regex_match[0].rm_so = 0;
regex_match[0].rm_eo = v3;
if ( regexec(&regex_buff, v4, 0xAuLL, regex_match, 4) )
break;
if ( (a1 & 1) != 0 )
{
LABEL_5:
++v2;
LABEL_6:
v1 = (__int64 *)*v1;
if ( *(__int64 **)(curbp + 40LL) == v1 )
goto LABEL_12;
}
else
{
v1 = (__int64 *)*v1;
if ( *(__int64 **)(curbp + 40LL) == v1 )
goto LABEL_12;
}
}
if ( (((unsigned __int8)a1 ^ 1) & 1) == 0 )
goto LABEL_6;
goto LABEL_5;
}
v2 = 0;
LABEL_12:
if ( a1 )
ewprintf("Number of lines matching: %d", v2);
else
ewprintf("Number of lines not matching: %d", v2);
return 1LL;
}

original_code:
int
countmatches(int cond)
{
 int error;
 int count = 0;
 struct line *clp;
 clp = curwp->w_dotp;
 if (curwp->w_doto == ((clp)->l_used))
  clp = ((clp)->l_fp);
 while (clp != (curbp->b_headp)) {
  regex_match[0].rm_so = 0;
  regex_match[0].rm_eo = ((clp)->l_used);
  error = regexec(&regex_buff, ((clp)->l_text), 10, regex_match,
      (1 << 2));
  if ((cond == 0 && error) || (cond == 1 && !error))
   count++;
  clp = ((clp)->l_fp);
 }
 if (cond)
  ewprintf("Number of lines matching: %d", count);
 else
  ewprintf("Number of lines not matching: %d", count);
 return (1);
}

variable_types: cond int

variable_types: count int


original_code:
static int
re_doreplace(RSIZE plen, char *st)
{
 int j, k, s, more, num, state;
 struct line *clp;
 char repstr[256];
 clp = curwp->w_dotp;
 more = 1;
 j = 0;
 state = 0;
 num = 0;
 while (more) {
  switch (state) {
  case 0:
   if (*st == '\\') {
    st++;
    state = 1;
   } else if (*st == '\0')
    more = 0;
   else {
    repstr[j] = *st;
    j++;
    if (j >= 256)
     return (0);
    st++;
   }
   break;
  case 1:
   if (*st >= '0' && *st <= '9') {
    num = *st - '0';
    st++;
    state = 2;
   } else if (*st == '\0')
    more = 0;
   else {
    repstr[j] = *st;
    j++;
    if (j >= 256)
     return (0);
    st++;
    state = 0;
   }
   break;
  case 2:
   if (*st >= '0' && *st <= '9') {
    num = 10 * num + *st - '0';
    st++;
   } else {
    if (num >= 10)
     return (0);
    k = regex_match[num].rm_eo - regex_match[num].rm_so;
    if (j + k >= 256)
     return (0);
    bcopy(&(clp->l_text[regex_match[num].rm_so]),
        &repstr[j], k);
    j += k;
    if (*st == '\0')
     more = 0;
    if (*st == '\\') {
     st++;
     state = 1;
    } else {
     repstr[j] = *st;
     j++;
     if (j >= 256)
      return (0);
     st++;
     state = 0;
    }
   }
   break;
  }
 }
 repstr[j] = '\0';
 s = lreplace(plen, repstr);
 return (s);
}

canonical_original_code:
static int re_doreplace(int plen, char *st)
{
 int j; int k; int s; int more; int num; int state;
 struct line *clp;
 char repstr[256];
 clp = curwp->w_dotp;
 more = 1;
 j = 0;
 state = 0;
 num = 0;
 while (more) {
  switch (state) {
  case 0:
   if (*st == '\\') {
    st++;
    state = 1;
   } else if (*st == '\0')
    more = 0;
   else {
    repstr[j] = *st;
    j++;
    if (j >= 256)
     return (0);
    st++;
   }
   break;
  case 1:
   if (*st >= '0' && *st <= '9') {
    num = *st - '0';
    st++;
    state = 2;
   } else if (*st == '\0')
    more = 0;
   else {
    repstr[j] = *st;
    j++;
    if (j >= 256)
     return (0);
    st++;
    state = 0;
   }
   break;
  case 2:
   if (*st >= '0' && *st <= '9') {
    num = 10 * num + *st - '0';
    st++;
   } else {
    if (num >= 10)
     return (0);
    k = regex_match[num].rm_eo - regex_match[num].rm_so;
    if (j + k >= 256)
     return (0);
    bcopy(&(clp->l_text[regex_match[num].rm_so]),
        &repstr[j], k);
    j += k;
    if (*st == '\0')
     more = 0;
    if (*st == '\\') {
     st++;
     state = 1;
    } else {
     repstr[j] = *st;
     j++;
     if (j >= 256)
      return (0);
     st++;
     state = 0;
    }
   }
   break;
  }
 }
 repstr[j] = '\0';
 s = lreplace(plen, repstr);
 return (s);
}

variable_types: plen int

variable_types:
st
char *

variable_types: j int

variable_types: k int

variable_types: more int

variable_types: num int

variable_types: state int

variable_types:
repstr
char [256]


killmatches

decompiled_code:
__int64 __fastcall killmatches(char a1)
{
__int64 *v1; // rbx
unsigned int v2; // ebp
char v3; // r12
char v4; // r13
regoff_t v5; // eax
const char *v6; // rsi
__int64 v7; // rax
int v8; // edi
__int64 result; // rax
__int64 v10; // rdx

v1 = *(__int64 **)(curwp + 32LL);
if ( *(_DWORD *)(curwp + 48LL) == *((_DWORD *)v1 + 5) )
v1 = (__int64 *)*v1;
if ( v1 == *(__int64 **)(curbp + 40LL) )
{
ewprintf("%d line(s) deleted", 0LL);
return 1LL;
}
v2 = 0;
v3 = a1 & 1;
v4 = (a1 ^ 1) & 1;
do
{
v5 = *((_DWORD *)v1 + 5);
v6 = (const char *)v1[3];
regex_match[0].rm_so = 0;
regex_match[0].rm_eo = v5;
if ( regexec(&regex_buff, v6, 0xAuLL, regex_match, 4) )
{
if ( !v4 )
goto LABEL_6;
}
else if ( !v3 )
{
LABEL_6:
v1 = (__int64 *)*v1;
continue;
}
v7 = curwp;
v8 = *((_DWORD *)v1 + 5);
++v2;
*(_QWORD *)(curwp + 32LL) = v1;
*(_DWORD *)(v7 + 48) = 0;
result = ldelete((unsigned int)(v8 + 1), 0LL);
v10 = curwp;
*(_BYTE *)(curwp + 68LL) |= 2u;
v1 = *(__int64 **)(v10 + 32);
if ( !(_DWORD)result )
return result;
}
while ( *(__int64 **)(curbp + 40LL) != v1 );
ewprintf("%d line(s) deleted", v2);
result = 1LL;
if ( v2 )
*(_BYTE *)(curwp + 68LL) |= 2u;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
__int64 *v1; // rbx
unsigned int v2; // ebp
char v3; // r12
char v4; // r13
regoff_t v5; // eax
const char *v6; // rsi
__int64 v7; // rax
int v8; // edi
__int64 result; // rax
__int64 v10; // rdx

v1 = *(__int64 **)(curwp + 32LL);
if ( *(_DWORD *)(curwp + 48LL) == *((_DWORD *)v1 + 5) )
v1 = (__int64 *)*v1;
if ( v1 == *(__int64 **)(curbp + 40LL) )
{
ewprintf("%d line(s) deleted", 0LL);
return 1LL;
}
v2 = 0;
v3 = a1 & 1;
v4 = (a1 ^ 1) & 1;
do
{
v5 = *((_DWORD *)v1 + 5);
v6 = (const char *)v1[3];
regex_match[0].rm_so = 0;
regex_match[0].rm_eo = v5;
if ( regexec(&regex_buff, v6, 0xAuLL, regex_match, 4) )
{
if ( !v4 )
goto LABEL_6;
}
else if ( !v3 )
{
LABEL_6:
v1 = (__int64 *)*v1;
continue;
}
v7 = curwp;
v8 = *((_DWORD *)v1 + 5);
++v2;
*(_QWORD *)(curwp + 32LL) = v1;
*(_DWORD *)(v7 + 48) = 0;
result = ldelete((unsigned int)(v8 + 1), 0LL);
v10 = curwp;
*(_BYTE *)(curwp + 68LL) |= 2u;
v1 = *(__int64 **)(v10 + 32);
if ( !(_DWORD)result )
return result;
}
while ( *(__int64 **)(curbp + 40LL) != v1 );
ewprintf("%d line(s) deleted", v2);
result = 1LL;
if ( v2 )
*(_BYTE *)(curwp + 68LL) |= 2u;
return result;
}

original_code:
static int
killmatches(int cond)
{
 int s, error;
 int count = 0;
 struct line *clp;
 clp = curwp->w_dotp;
 if (curwp->w_doto == ((clp)->l_used))
  clp = ((clp)->l_fp);
 while (clp != (curbp->b_headp)) {
  regex_match[0].rm_so = 0;
  regex_match[0].rm_eo = ((clp)->l_used);
  error = regexec(&regex_buff, ((clp)->l_text), 10, regex_match,
      (1 << 2));
  if ((cond == 0 && error) || (cond == 1 && !error)) {
   curwp->w_doto = 0;
   curwp->w_dotp = clp;
   count++;
   s = ldelete(((clp)->l_used) + 1, 0x00);
   clp = curwp->w_dotp;
   curwp->w_rflag |= 0x02;
   if (s == 0)
    return (0);
  } else
   clp = ((clp)->l_fp);
 }
 ewprintf("%d line(s) deleted", count);
 if (count > 0)
  curwp->w_rflag |= 0x02;
 return (1);
}

canonical_original_code:
static int killmatches(int cond)
{
 int s; int error;
 int count = 0;
 struct line *clp;
 clp = curwp->w_dotp;
 if (curwp->w_doto == ((clp)->l_used))
  clp = ((clp)->l_fp);
 while (clp != (curbp->b_headp)) {
  regex_match[0].rm_so = 0;
  regex_match[0].rm_eo = ((clp)->l_used);
  error = regexec(&regex_buff, ((clp)->l_text), 10, regex_match,
      (1 << 2));
  if ((cond == 0 && error) || (cond == 1 && !error)) {
   curwp->w_doto = 0;
   curwp->w_dotp = clp;
   count++;
   s = ldelete(((clp)->l_used) + 1, 0x00);
   clp = curwp->w_dotp;
   curwp->w_rflag |= 0x02;
   if (s == 0)
    return (0);
  } else
   clp = ((clp)->l_fp);
 }
 ewprintf("%d line(s) deleted", count);
 if (count > 0)
  curwp->w_rflag |= 0x02;
 return (1);
}

variable_types: s int

variable_types: error int


decompiled_code:
__int64 re_forwsearch()
{
unsigned int v0; // er12

v0 = re_readpattern("RE Search");
if ( v0 != 1 )
return v0;
if ( !(unsigned int)re_forwsrch() )
{
dobeep();
v0 = 0;
ewprintf("Search failed: \"%s\"", &re_pat);
return v0;
}
re_srch_lastdir = -1;
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er12

v0 = func0("RE Search");
if ( v0 != 1 )
return v0;
if ( !(unsigned int)func1() )
{
dobeep();
v0 = 0;
ewprintf("Search failed: \"%s\"", &re_pat);
return v0;
}
re_srch_lastdir = -1;
return v0;
}

original_code:
int
re_forwsearch(int f, int n)
{
 int s;
 if ((s = re_readpattern("RE Search")) != 1)
  return (s);
 if (re_forwsrch() == 0) {
  dobeep();
  ewprintf("Search failed: \"%s\"", re_pat);
  return (0);
 }
 re_srch_lastdir = (-1);
 return (1);
}

variable_types: f int

variable_types: n int


decompiled_code:
__int64 re_backsearch()
{
unsigned int v0; // er12

v0 = re_readpattern("RE Search backward");
if ( v0 != 1 )
return v0;
if ( !(unsigned int)re_backsrch() )
{
dobeep();
v0 = 0;
ewprintf("Search failed: \"%s\"", &re_pat);
return v0;
}
re_srch_lastdir = -2;
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er12

v0 = func0("RE Search backward");
if ( v0 != 1 )
return v0;
if ( !(unsigned int)func2() )
{
dobeep();
v0 = 0;
ewprintf("Search failed: \"%s\"", &re_pat);
return v0;
}
re_srch_lastdir = -2;
return v0;
}

original_code:
int
re_backsearch(int f, int n)
{
 int s;
 if ((s = re_readpattern("RE Search backward")) != 1)
  return (s);
 if (re_backsrch() == 0) {
  dobeep();
  ewprintf("Search failed: \"%s\"", re_pat);
  return (0);
 }
 re_srch_lastdir = (-2);
 return (1);
}


decompiled_code:
__int64 re_searchagain()
{
if ( re_srch_lastdir != -3 )
{
if ( re_srch_lastdir == -1 )
{
if ( !(unsigned int)re_forwsrch() )
{
LABEL_6:
dobeep();
ewprintf("Search failed: \"%s\"", &re_pat);
return 0LL;
}
}
else if ( re_srch_lastdir == -2 && !(unsigned int)re_backsrch() )
{
goto LABEL_6;
}
return 1LL;
}
dobeep();
ewprintf("No last search");
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
if ( re_srch_lastdir != -3 )
{
if ( re_srch_lastdir == -1 )
{
if ( !(unsigned int)func1() )
{
LABEL_6:
dobeep();
ewprintf("Search failed: \"%s\"", &re_pat);
return 0LL;
}
}
else if ( re_srch_lastdir == -2 && !(unsigned int)func2() )
{
goto LABEL_6;
}
return 1LL;
}
dobeep();
ewprintf("No last search");
return 0LL;
}

original_code:
int
re_searchagain(int f, int n)
{
 if (re_srch_lastdir == (-3)) {
  dobeep();
  ewprintf("No last search");
  return (0);
 }
 if (re_srch_lastdir == (-1)) {
  if (re_forwsrch() == 0) {
   dobeep();
   ewprintf("Search failed: \"%s\"", re_pat);
   return (0);
  }
  return (1);
 }
 if (re_srch_lastdir == (-2))
  if (re_backsrch() == 0) {
   dobeep();
   ewprintf("Search failed: \"%s\"", re_pat);
   return (0);
  }
 return (1);
}


decompiled_code:
__int64 re_queryrepl()
{
unsigned int v0; // er12
unsigned int v2; // ebp
int v3; // eax
char v4[104]; // [rsp+0h] [rbp-68h] BYREF

v0 = re_readpattern("RE Query replace");
if ( v0 != 1 )
return v0;
if ( !eread("Query replace %s with: ", v4) )
return 2;
ewprintf("Query replacing %s with %s:", &re_pat, v4);
v2 = 0;
LABEL_5:
while ( 2 )
{
if ( (unsigned int)re_forwsrch() != 1 )
{
LABEL_16:
*(_BYTE *)(curwp + 68LL) |= 8u;
update(2LL);
if ( inmacro )
return v0;
if ( !v2 )
{
ewprintf("(No replacements done)");
return v0;
}
goto LABEL_18;
}
while ( 1 )
{
update(2LL);
v3 = getkey(0LL);
if ( v3 <= 46 )
break;
if ( v3 == 96 )
goto LABEL_16;
if ( v3 == 127 )
goto LABEL_5;
LABEL_14:
ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit");
}
if ( v3 <= 6 )
goto LABEL_14;
switch ( v3 )
{
case 7:
ctrlg(8LL, 0LL);
goto LABEL_16;
case 27:
goto LABEL_16;
case 32:
if ( !(unsigned int)re_doreplace(regex_match[0].rm_eo - regex_match[0].rm_so, v4) )
return 0;
++v2;
continue;
case 33:
goto LABEL_10;
case 46:
++v2;
if ( (unsigned int)re_doreplace(regex_match[0].rm_eo - regex_match[0].rm_so, v4) )
goto LABEL_21;
return 0;
default:
goto LABEL_14;
}
}
do
{
LABEL_10:
if ( !(unsigned int)re_doreplace(regex_match[0].rm_eo - regex_match[0].rm_so, v4) )
return 0;
++v2;
}
while ( (unsigned int)re_forwsrch() == 1 );
LABEL_21:
*(_BYTE *)(curwp + 68LL) |= 8u;
update(2LL);
if ( !inmacro )
{
LABEL_18:
if ( v2 == 1 )
{
v0 = 1;
ewprintf("(1 replacement done)");
}
else
{
ewprintf("(%d replacements done)", v2);
}
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er12
unsigned int v2; // ebp
int v3; // eax
char v4[104]; // [rsp+0h] [rbp-68h] BYREF

v0 = func0("RE Query replace");
if ( v0 != 1 )
return v0;
if ( !eread("Query replace %s with: ", v4) )
return 2;
ewprintf("Query replacing %s with %s:", &re_pat, v4);
v2 = 0;
LABEL_5:
while ( 2 )
{
if ( (unsigned int)func1() != 1 )
{
LABEL_16:
*(_BYTE *)(curwp + 68LL) |= 8u;
update(2LL);
if ( inmacro )
return v0;
if ( !v2 )
{
ewprintf("(No replacements done)");
return v0;
}
goto LABEL_18;
}
while ( 1 )
{
update(2LL);
v3 = getkey(0LL);
if ( v3 <= 46 )
break;
if ( v3 == 96 )
goto LABEL_16;
if ( v3 == 127 )
goto LABEL_5;
LABEL_14:
ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit");
}
if ( v3 <= 6 )
goto LABEL_14;
switch ( v3 )
{
case 7:
ctrlg(8LL, 0LL);
goto LABEL_16;
case 27:
goto LABEL_16;
case 32:
if ( !(unsigned int)func4(regex_match[0].rm_eo - regex_match[0].rm_so, v4) )
return 0;
++v2;
continue;
case 33:
goto LABEL_10;
case 46:
++v2;
if ( (unsigned int)func4(regex_match[0].rm_eo - regex_match[0].rm_so, v4) )
goto LABEL_21;
return 0;
default:
goto LABEL_14;
}
}
do
{
LABEL_10:
if ( !(unsigned int)func4(regex_match[0].rm_eo - regex_match[0].rm_so, v4) )
return 0;
++v2;
}
while ( (unsigned int)func1() == 1 );
LABEL_21:
*(_BYTE *)(curwp + 68LL) |= 8u;
update(2LL);
if ( !inmacro )
{
LABEL_18:
if ( v2 == 1 )
{
v0 = 1;
ewprintf("(1 replacement done)");
}
else
{
ewprintf("(%d replacements done)", v2);
}
}
return v0;
}

original_code:
int
re_queryrepl(int f, int n)
{
 int rcnt = 0;
 int plen, s;
 char news[80];
 if ((s = re_readpattern("RE Query replace")) != 1)
  return (s);
 if (eread("Query replace %s with: ", news, 80,
     0x0040 | 0x0008 | 0x0010, re_pat) == ((void *)0))
  return (2);
 ewprintf("Query replacing %s with %s:", re_pat, news);
 while (re_forwsrch() == 1) {
retry:
  update(2);
  switch (getkey(0)) {
  case ' ':
   plen = regex_match[0].rm_eo - regex_match[0].rm_so;
   if (re_doreplace((RSIZE)plen, news) == 0)
    return (0);
   rcnt++;
   break;
  case '.':
   plen = regex_match[0].rm_eo - regex_match[0].rm_so;
   if (re_doreplace((RSIZE)plen, news) == 0)
    return (0);
   rcnt++;
   goto stopsearch;
  case (('G') ^ 0x40):
   (void)ctrlg(8, 0);
   goto stopsearch;
  case (('[') ^ 0x40):
  case '`':
   goto stopsearch;
  case '!':
   do {
    plen = regex_match[0].rm_eo - regex_match[0].rm_so;
    if (re_doreplace((RSIZE)plen, news) == 0)
     return (0);
    rcnt++;
   } while (re_forwsrch() == 1);
   goto stopsearch;
  case (('?') ^ 0x40):
   break;
  default:
   ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit");
   goto retry;
  }
 }
stopsearch:
 curwp->w_rflag |= 0x08;
 update(2);
 if (!inmacro) {
  if (rcnt == 0)
   ewprintf("(No replacements done)");
  else if (rcnt == 1)
   ewprintf("(1 replacement done)");
  else
   ewprintf("(%d replacements done)", rcnt);
 }
 return (1);
}

canonical_original_code:
int re_queryrepl(int f, int n)
{
 int rcnt = 0;
 int plen; int s;
 char news[80];
 if ((s = re_readpattern("RE Query replace")) != 1)
  return (s);
 if (eread("Query replace %s with: ", news, 80,
     0x0040 | 0x0008 | 0x0010, re_pat) == ((void *)0))
  return (2);
 ewprintf("Query replacing %s with %s:", re_pat, news);
 while (re_forwsrch() == 1) {
retry:
  update(2);
  switch (getkey(0)) {
  case ' ':
   plen = regex_match[0].rm_eo - regex_match[0].rm_so;
   if (re_doreplace((int)plen, news) == 0)
    return (0);
   rcnt++;
   break;
  case '.':
   plen = regex_match[0].rm_eo - regex_match[0].rm_so;
   if (re_doreplace((int)plen, news) == 0)
    return (0);
   rcnt++;
   goto stopsearch;
  case (('G') ^ 0x40):
   (void)ctrlg(8, 0);
   goto stopsearch;
  case (('[') ^ 0x40):
  case '`':
   goto stopsearch;
  case '!':
   do {
    plen = regex_match[0].rm_eo - regex_match[0].rm_so;
    if (re_doreplace((int)plen, news) == 0)
     return (0);
    rcnt++;
   } while (re_forwsrch() == 1);
   goto stopsearch;
  case (('?') ^ 0x40):
   break;
  default:
   ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit");
   goto retry;
  }
 }
stopsearch:
 curwp->w_rflag |= 0x08;
 update(2);
 if (!inmacro) {
  if (rcnt == 0)
   ewprintf("(No replacements done)");
  else if (rcnt == 1)
   ewprintf("(1 replacement done)");
  else
   ewprintf("(%d replacements done)", rcnt);
 }
 return (1);
}

variable_types: rcnt int

variable_types:
news
char [80]


setcasefold

decompiled_code:
__int64 __fastcall setcasefold(char a1)
{
if ( (a1 & 7) != 0 )
{
casefoldsearch = 0;
ewprintf("Case-fold-search unset");
}
else
{
casefoldsearch = 1;
ewprintf("Case-fold-search set");
}
re_pat = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
if ( (a1 & 7) != 0 )
{
casefoldsearch = 0;
ewprintf("Case-fold-search unset");
}
else
{
casefoldsearch = 1;
ewprintf("Case-fold-search set");
}
re_pat = 0;
return 1LL;
}

original_code:
int
setcasefold(int f, int n)
{
 if (f & 7) {
  casefoldsearch = 0;
  ewprintf("Case-fold-search unset");
 } else {
  casefoldsearch = 1;
  ewprintf("Case-fold-search set");
 }
 re_pat[0] = '\0';
 return (1);
}


delmatchlines

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

result = re_readpattern("Flush lines (containing match for regexp)");
if ( (_DWORD)result == 1 )
result = killmatches(1);
return result;
}

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

result = func0("Flush lines (containing match for regexp)");
if ( (_DWORD)result == 1 )
result = func5(1);
return result;
}

original_code:
int
delmatchlines(int f, int n)
{
 int s;
 if ((s = re_readpattern("Flush lines (containing match for regexp)"))
     != 1)
  return (s);
 s = killmatches(1);
 return (s);
}


delnonmatchlines

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

result = re_readpattern("Keep lines (containing match for regexp)");
if ( (_DWORD)result == 1 )
result = killmatches(0);
return result;
}

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

result = func0("Keep lines (containing match for regexp)");
if ( (_DWORD)result == 1 )
result = func5(0);
return result;
}

original_code:
int
delnonmatchlines(int f, int n)
{
 int s;
 if ((s = re_readpattern("Keep lines (containing match for regexp)"))
     != 1)
  return (s);
 s = killmatches(0);
 return (s);
}