cntmatchlines

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

result = re_readpattern("Count lines (matching regexp)");
if ( (_DWORD)result == 1 )
result = countmatches(1);
return result;
}

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

result = func0("Count lines (matching regexp)");
if ( (_DWORD)result == 1 )
result = func3(1);
return result;
}

original_code:
int
cntmatchlines(int f, int n)
{
 int s;
 if ((s = re_readpattern("Count lines (matching regexp)")) != 1)
  return (s);
 s = countmatches(1);
 return (s);
}


cntnonmatchlines

repo: scott-parker/mg-openbsd

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

result = re_readpattern("Count lines (not matching regexp)");
if ( (_DWORD)result == 1 )
result = countmatches(0);
return result;
}

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

result = func0("Count lines (not matching regexp)");
if ( (_DWORD)result == 1 )
result = func3(0);
return result;
}

original_code:
int
cntnonmatchlines(int f, int n)
{
 int s;
 if ((s = re_readpattern("Count lines (not matching regexp)")) != 1)
  return (s);
 s = countmatches(0);
 return (s);
}

variable_types: f int

variable_types: n int

variable_types: s int

return_type: int


ttraw

decompiled_code:
__int64 ttraw()
{
__m128i v0; // xmm0
__m128i v1; // xmm1
tcflag_t v2; // eax
speed_t v3; // edx
__m128i v4; // xmm2
tcflag_t v5; // eax
__int64 result; // rax

if ( tcgetattr(0, &oldtty) < 0 )
{
dobeep();
ewprintf("ttopen can't get terminal attributes");
result = 0LL;
}
else
{
v0 = _mm_load_si128((const __m128i *)&oldtty);
v1 = _mm_load_si128((const __m128i *)&oldtty.c_line);
v2 = oldtty.c_iflag & 0xFFFFFA15;
*(_QWORD *)&newtty.c_cc[31] = *(_QWORD *)&oldtty.c_cc[31];
v3 = oldtty.c_ospeed;
*(__m128i *)&newtty.c_iflag = v0;
v4 = _mm_load_si128((const __m128i *)&oldtty.c_cc[15]);
newtty.c_iflag = v2 | 1;
v5 = newtty.c_cflag;
newtty.c_ospeed = v3;
*(__m128i *)&newtty.c_line = v1;
*(_WORD *)&newtty.c_cc[5] = 256;
newtty.c_oflag &= 0xFFFFFFFE;
newtty.c_lflag &= 0xFFFF7FB4;
newtty.c_cflag = v5 & 0xFFFFFECF | 0x30;
*(__m128i *)&newtty.c_cc[15] = v4;
if ( tcsetattr(0, 1, &newtty) < 0 )
{
dobeep();
ewprintf("ttopen can't tcsetattr");
result = 0LL;
}
else
{
ttstarted = 1;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__m128i v0; // xmm0
__m128i v1; // xmm1
tcflag_t v2; // eax
speed_t v3; // edx
__m128i v4; // xmm2
tcflag_t v5; // eax
__int64 result; // rax

if ( tcgetattr(0, &oldtty) < 0 )
{
dobeep();
ewprintf("ttopen can't get terminal attributes");
result = 0LL;
}
else
{
v0 = _mm_load_si128((const __m128i *)&oldtty);
v1 = _mm_load_si128((const __m128i *)&oldtty.c_line);
v2 = oldtty.c_iflag & 0xFFFFFA15;
*(_QWORD *)&newtty.c_cc[31] = *(_QWORD *)&oldtty.c_cc[31];
v3 = oldtty.c_ospeed;
*(__m128i *)&newtty.c_iflag = v0;
v4 = _mm_load_si128((const __m128i *)&oldtty.c_cc[15]);
newtty.c_iflag = v2 | 1;
v5 = newtty.c_cflag;
newtty.c_ospeed = v3;
*(__m128i *)&newtty.c_line = v1;
*(_WORD *)&newtty.c_cc[5] = 256;
newtty.c_oflag &= 0xFFFFFFFE;
newtty.c_lflag &= 0xFFFF7FB4;
newtty.c_cflag = v5 & 0xFFFFFECF | 0x30;
*(__m128i *)&newtty.c_cc[15] = v4;
if ( tcsetattr(0, 1, &newtty) < 0 )
{
dobeep();
ewprintf("ttopen can't tcsetattr");
result = 0LL;
}
else
{
ttstarted = 1;
result = 1LL;
}
}
return result;
}

original_code:
int
ttraw(void)
{
 if (tcgetattr(0, &oldtty) < 0) {
  dobeep();
  ewprintf("ttopen can't get terminal attributes");
  return (0);
 }
 (void)memcpy(&newtty, &oldtty, sizeof(newtty));
 newtty.c_cc[6] = 1;
 newtty.c_cc[5] = 0;
 newtty.c_iflag |= 0000001;
 newtty.c_iflag &= ~(0000002 | 0000010 | 0000100 | 0000200 | 0000400 | 0002000);
 newtty.c_oflag &= ~0000001;
 newtty.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0000001 | 0100000);
 newtty.c_iflag &= ~0000040;
 newtty.c_cflag &= ~(0000060 | 0000400);
 newtty.c_cflag |= 0000060;
 if (tcsetattr(0, 0 | 1, &newtty) < 0) {
  dobeep();
  ewprintf("ttopen can't tcsetattr");
  return (0);
 }
 ttstarted = 1;
 return (1);
}

canonical_original_code:
int ttraw()
{
 if (tcgetattr(0, &oldtty) < 0) {
  dobeep();
  ewprintf("ttopen can't get terminal attributes");
  return (0);
 }
 (void)memcpy(&newtty, &oldtty, sizeof(newtty));
 newtty.c_cc[6] = 1;
 newtty.c_cc[5] = 0;
 newtty.c_iflag |= 0000001;
 newtty.c_iflag &= ~(0000002 | 0000010 | 0000100 | 0000200 | 0000400 | 0002000);
 newtty.c_oflag &= ~0000001;
 newtty.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0000001 | 0100000);
 newtty.c_iflag &= ~0000040;
 newtty.c_cflag &= ~(0000060 | 0000400);
 newtty.c_cflag |= 0000060;
 if (tcsetattr(0, 0 | 1, &newtty) < 0) {
  dobeep();
  ewprintf("ttopen can't tcsetattr");
  return (0);
 }
 ttstarted = 1;
 return (1);
}


charswaiting

decompiled_code:
__int64 charswaiting()
{
bool v0; // sf
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = ioctl(0, 0x541BuLL, v2) < 0;
result = 0LL;
if ( !v0 )
result = v2[0];
return result;
}

canonical_decompiled_code:
__int64 func1()
{
bool v0; // sf
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = ioctl(0, 0x541BuLL, v2) < 0;
result = 0LL;
if ( !v0 )
result = v2[0];
return result;
}

original_code:
int
charswaiting(void)
{
 int x;
 return ((ioctl(0, 0x541B, &x) < 0) ? 0 : x);
}

canonical_original_code:
int charswaiting()
{
 int x;
 return ((ioctl(0, 0x541B, &x) < 0) ? 0 : x);
}

variable_types: x int


panic

decompiled_code:
__int64 __fastcall panic(char *s)
{
__int64 result; // rax

result = (unsigned int)panicking_0;
if ( !panicking_0 )
{
panicking_0 = 1;
ttclose(s);
fwrite("panic: ", 1uLL, 7uLL, stderr);
fputs(s, stderr);
fputc(10, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s)
{
__int64 result; // rax

result = (unsigned int)panicking_0;
if ( !panicking_0 )
{
panicking_0 = 1;
func7(s);
fwrite("panic: ", 1uLL, 7uLL, stderr);
fputs(s, stderr);
fputc(10, stderr);
exit(1);
}
return result;
}

original_code:
void
panic(char *s)
{
 static int panicking = 0;
 if (panicking)
  return;
 else
  panicking = 1;
 ttclose();
 (void) fputs("panic: ", stderr);
 (void) fputs(s, stderr);
 (void) fputc('\n', stderr);
 exit(1);
}

variable_types:
s
char *

variable_types: panicking int

return_type: void


ttopen

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

if ( isatty(0) && isatty(1) )
{
result = ttraw();
if ( (_DWORD)result )
return result;
return panic("aborting due to terminal initialize failure");
}
panic("standard input and output must be a terminal");
result = ttraw();
if ( !(_DWORD)result )
return panic("aborting due to terminal initialize failure");
return result;
}

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

if ( isatty(0) && isatty(1) )
{
result = func0();
if ( (_DWORD)result )
return result;
return func2("aborting due to terminal initialize failure");
}
func2("standard input and output must be a terminal");
result = func0();
if ( !(_DWORD)result )
return func2("aborting due to terminal initialize failure");
return result;
}

original_code:
void
ttopen(void)
{
 if (!isatty(0) || !isatty(1))
  panic("standard input and output must be a terminal");
 if (ttraw() == 0)
  panic("aborting due to terminal initialize failure");
}

canonical_original_code:
void ttopen()
{
 if (!isatty(0) || !isatty(1))
  panic("standard input and output must be a terminal");
 if (ttraw() == 0)
  panic("aborting due to terminal initialize failure");
}


ttflush

decompiled_code:
void ttflush()
{
size_t v0; // r12
char *v1; // rbp
int v2; // eax
ssize_t v3; // rax
ssize_t v4; // rbx

v0 = nobuf;
v1 = &obuf;
if ( nobuf )
{
while ( 1 )
{
while ( 1 )
{
v2 = fileno(stdout);
v3 = write(v2, v1, v0);
v0 = nobuf;
v4 = v3;
if ( nobuf == v3 )
{
nobuf = 0LL;
return;
}
if ( v3 == -1 )
break;
LABEL_4:
v0 -= v4;
v1 += v4;
nobuf = v0;
}
if ( *_errno_location() != 4 )
{
panic("ttflush write failed");
v0 = nobuf;
goto LABEL_4;
}
}
}
}

canonical_decompiled_code:
void func4()
{
size_t v0; // r12
char *v1; // rbp
int v2; // eax
ssize_t v3; // rax
ssize_t v4; // rbx

v0 = nobuf;
v1 = &obuf;
if ( nobuf )
{
while ( 1 )
{
while ( 1 )
{
v2 = fileno(stdout);
v3 = write(v2, v1, v0);
v0 = nobuf;
v4 = v3;
if ( nobuf == v3 )
{
nobuf = 0LL;
return;
}
if ( v3 == -1 )
break;
LABEL_4:
v0 -= v4;
v1 += v4;
nobuf = v0;
}
if ( *_errno_location() != 4 )
{
func2("ttflush write failed");
v0 = nobuf;
goto LABEL_4;
}
}
}
}

original_code:
void
ttflush(void)
{
 ssize_t written;
 char *buf = obuf;
 if (nobuf == 0)
  return;
 while ((written = write(fileno(stdout), buf, nobuf)) != nobuf) {
  if (written == -1) {
   if ((*__errno_location ()) == 4)
    continue;
   panic("ttflush write failed");
  }
  buf += written;
  nobuf -= written;
 }
 nobuf = 0;
}

canonical_original_code:
void ttflush()
{
 long written;
 char *buf = obuf;
 if (nobuf == 0)
  return;
 while ((written = write(fileno(stdout), buf, nobuf)) != nobuf) {
  if (written == -1) {
   if ((*__errno_location ()) == 4)
    continue;
   panic("ttflush write failed");
  }
  buf += written;
  nobuf -= written;
 }
 nobuf = 0;
}

variable_types: written long

variable_types:
buf
char *


ttcooked

decompiled_code:
__int64 ttcooked()
{
int v0; // er8
__int64 result; // rax

ttflush();
v0 = tcsetattr(0, 1, &oldtty);
result = 1LL;
if ( v0 < 0 )
{
dobeep();
ewprintf("ttclose can't tcsetattr");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // er8
__int64 result; // rax

func4();
v0 = tcsetattr(0, 1, &oldtty);
result = 1LL;
if ( v0 < 0 )
{
dobeep();
ewprintf("ttclose can't tcsetattr");
result = 0LL;
}
return result;
}

original_code:
int
ttcooked(void)
{
 ttflush();
 if (tcsetattr(0, 0 | 1, &oldtty) < 0) {
  dobeep();
  ewprintf("ttclose can't tcsetattr");
  return (0);
 }
 return (1);
}

canonical_original_code:
int ttcooked()
{
 ttflush();
 if (tcsetattr(0, 0 | 1, &oldtty) < 0) {
  dobeep();
  ewprintf("ttclose can't tcsetattr");
  return (0);
 }
 return (1);
}


ttputc

decompiled_code:
__int64 __fastcall ttputc(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rdx
__int64 result; // rax

v1 = nobuf;
if ( nobuf > 0x1FF )
{
ttflush();
v1 = nobuf;
}
v2 = v1 + 1;
obuf[v1] = a1;
result = a1;
nobuf = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rdx
__int64 result; // rax

v1 = nobuf;
if ( nobuf > 0x1FF )
{
func4();
v1 = nobuf;
}
v2 = v1 + 1;
obuf[v1] = a1;
result = a1;
nobuf = v2;
return result;
}

original_code:
int
ttputc(int c)
{
 if (nobuf >= 512)
  ttflush();
 obuf[nobuf++] = c;
 return (c);
}

variable_types: c int


ttclose

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

result = (unsigned int)ttstarted;
if ( ttstarted )
{
result = ttcooked();
if ( !(_DWORD)result )
result = panic((char *)&byte_7F0);
ttstarted = 0;
}
return result;
}

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

result = (unsigned int)ttstarted;
if ( ttstarted )
{
result = func5();
if ( !(_DWORD)result )
result = func2((char *)&byte_7F0);
ttstarted = 0;
}
return result;
}

original_code:
void
ttclose(void)
{
 if (ttstarted) {
  if (ttcooked() == 0)
   panic("");
  ttstarted = 0;
 }
}

canonical_original_code:
void ttclose()
{
 if (ttstarted) {
  if (ttcooked() == 0)
   panic("");
  ttstarted = 0;
 }
}


ttgetc

decompiled_code:
__int64 ttgetc()
{
ssize_t v0; // rax
int v2; // eax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
while ( 1 )
{
v0 = read(0, buf, 1uLL);
if ( v0 != -1 )
break;
v2 = *_errno_location();
if ( v2 == 4 )
{
if ( winch_flag )
{
redraw(0LL, 0LL);
winch_flag = 0;
}
}
else if ( v2 == 5 )
{
panic("lost stdin");
}
}
}
while ( v0 != 1 );
return (unsigned __int8)buf[0];
}

canonical_decompiled_code:
__int64 func8()
{
ssize_t v0; // rax
int v2; // eax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
while ( 1 )
{
v0 = read(0, buf, 1uLL);
if ( v0 != -1 )
break;
v2 = *_errno_location();
if ( v2 == 4 )
{
if ( winch_flag )
{
redraw(0LL, 0LL);
winch_flag = 0;
}
}
else if ( v2 == 5 )
{
func2("lost stdin");
}
}
}
while ( v0 != 1 );
return (unsigned __int8)buf[0];
}

original_code:
int
ttgetc(void)
{
 char c;
 ssize_t ret;
 do {
  ret = read(0, &c, 1);
  if (ret == -1 && (*__errno_location ()) == 4) {
   if (winch_flag) {
    redraw(0, 0);
    winch_flag = 0;
   }
  } else if (ret == -1 && (*__errno_location ()) == 5)
   panic("lost stdin");
  else if (ret == 1)
   break;
 } while (1);
 return ((int) c) & 0xFF;
}

canonical_original_code:
int ttgetc()
{
 char c;
 long ret;
 do {
  ret = read(0, &c, 1);
  if (ret == -1 && (*__errno_location ()) == 4) {
   if (winch_flag) {
    redraw(0, 0);
    winch_flag = 0;
   }
  } else if (ret == -1 && (*__errno_location ()) == 5)
   panic("lost stdin");
  else if (ret == 1)
   break;
 } while (1);
 return ((int) c) & 0xFF;
}

variable_types: c char

variable_types: ret long


ttwait

decompiled_code:
_BOOL8 __fastcall ttwait(int timeout)
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = 0;
fds.events = 1;
return poll(&fds, 1uLL, timeout) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int timeout)
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = 0;
fds.events = 1;
return poll(&fds, 1uLL, timeout) == 0;
}

original_code:
int
ttwait(int msec)
{
 struct pollfd pfd[1];
 pfd[0].fd = 0;
 pfd[0].events = 0x001;
 if ((poll(pfd, 1, msec)) == 0)
  return (1);
 return (0);
}

variable_types: msec int

variable_types: struct pollfd { int fd; short events; short revents; } [1]


finishmacro

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

v0 = macrodef;
if ( macrodef != 1 )
return 0LL;
macrodef = 0;
ewprintf("End Keyboard Macro Definition");
return v0;
}

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

v0 = macrodef;
if ( macrodef != 1 )
return 0LL;
macrodef = 0;
ewprintf("End Keyboard Macro Definition");
return v0;
}

original_code:
int
finishmacro(int f, int n)
{
 if (macrodef == 1) {
  macrodef = 0;
  ewprintf("End Keyboard Macro Definition");
  return (1);
 }
 return (0);
}


definemacro

decompiled_code:
__int64 definemacro()
{
unsigned int v0; // er12
_QWORD *v1; // rbp
void *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

v0 = macrodef;
macrocount = 0;
if ( macrodef )
{
ewprintf("already defining macro");
result = 0LL;
macrodef = 0;
}
else
{
if ( maclhead )
{
v1 = *(_QWORD **)maclhead;
while ( (_QWORD *)maclhead != v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
free(v1);
}
maclhead = lalloc(0LL);
v3 = (_QWORD *)maclhead;
if ( maclhead )
{
v0 = 1;
ewprintf("Defining Keyboard Macro...");
*v3 = v3;
v3[1] = v3;
maclcur = (__int64)v3;
macrodef = 1;
}
result = v0;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
_QWORD *v1; // rbp
void *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

v0 = macrodef;
macrocount = 0;
if ( macrodef )
{
ewprintf("already defining macro");
result = 0LL;
macrodef = 0;
}
else
{
if ( maclhead )
{
v1 = *(_QWORD **)maclhead;
while ( (_QWORD *)maclhead != v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
free(v1);
}
maclhead = lalloc(0LL);
v3 = (_QWORD *)maclhead;
if ( maclhead )
{
v0 = 1;
ewprintf("Defining Keyboard Macro...");
*v3 = v3;
v3[1] = v3;
maclcur = (__int64)v3;
macrodef = 1;
}
result = v0;
}
return result;
}

original_code:
int
definemacro(int f, int n)
{
 struct line *lp1, *lp2;
 macrocount = 0;
 if (macrodef) {
  ewprintf("already defining macro");
  return (macrodef = 0);
 }
 if (maclhead != ((void *)0)) {
  for (lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) {
   lp2 = lp1->l_fp;
   free(lp1);
  }
  free(lp1);
 }
 if ((maclhead = lp1 = lalloc(0)) == ((void *)0))
  return (0);
 ewprintf("Defining Keyboard Macro...");
 maclcur = lp1->l_fp = lp1->l_bp = lp1;
 return (macrodef = 1);
}

canonical_original_code:
int definemacro(int f, int n)
{
 struct line *lp1; struct line *lp2;
 macrocount = 0;
 if (macrodef) {
  ewprintf("already defining macro");
  return (macrodef = 0);
 }
 if (maclhead != ((void *)0)) {
  for (lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) {
   lp2 = lp1->l_fp;
   free(lp1);
  }
  free(lp1);
 }
 if ((maclhead = lp1 = lalloc(0)) == ((void *)0))
  return (0);
 ewprintf("Defining Keyboard Macro...");
 maclcur = lp1->l_fp = lp1->l_bp = lp1;
 return (macrodef = 1);
}

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


executemacro

decompiled_code:
__int64 __fastcall executemacro(__int64 a1, int a2)
{
unsigned int v2; // er13
int v3; // edx
int v4; // er12
int v5; // ebx
int v6; // eax
unsigned int (*v7)(void); // rax
unsigned int v8; // er13

v2 = macrodef;
if ( macrodef )
goto LABEL_14;
v3 = macrocount;
v4 = a2;
if ( macrocount > 255 )
{
if ( !macro[255] )
goto LABEL_4;
LABEL_14:
dobeep();
v8 = 0;
ewprintf("Macro too long. Aborting.");
return v8;
}
if ( !macrocount )
return 1LL;
LABEL_4:
inmacro = 1;
if ( a2 <= 0 )
{
LABEL_12:
inmacro = 0;
return 1;
}
while ( 1 )
{
v5 = 0;
maclcur = *(_QWORD *)maclhead;
if ( v3 > 1 )
break;
LABEL_11:
if ( !--v4 )
goto LABEL_12;
}
while ( 1 )
{
while ( 1 )
{
v7 = (unsigned int (*)(void))macro[v5];
if ( (char *)v7 != (char *)&universal_argument )
break;
v5 += 2;
if ( v3 - 1 <= v5 )
goto LABEL_11;
}
if ( v7() != 1 )
break;
v6 = thisflag;
v3 = macrocount;
++v5;
thisflag = 0;
lastflag = v6;
if ( macrocount - 1 <= v5 )
goto LABEL_11;
}
inmacro = 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // er13
int v3; // edx
int v4; // er12
int v5; // ebx
int v6; // eax
unsigned int (*v7)(void); // rax
unsigned int v8; // er13

v2 = macrodef;
if ( macrodef )
goto LABEL_14;
v3 = macrocount;
v4 = a2;
if ( macrocount > 255 )
{
if ( !macro[255] )
goto LABEL_4;
LABEL_14:
dobeep();
v8 = 0;
ewprintf("Macro too long. Aborting.");
return v8;
}
if ( !macrocount )
return 1LL;
LABEL_4:
inmacro = 1;
if ( a2 <= 0 )
{
LABEL_12:
inmacro = 0;
return 1;
}
while ( 1 )
{
v5 = 0;
maclcur = *(_QWORD *)maclhead;
if ( v3 > 1 )
break;
LABEL_11:
if ( !--v4 )
goto LABEL_12;
}
while ( 1 )
{
while ( 1 )
{
v7 = (unsigned int (*)(void))macro[v5];
if ( (char *)v7 != (char *)&universal_argument )
break;
v5 += 2;
if ( v3 - 1 <= v5 )
goto LABEL_11;
}
if ( v7() != 1 )
break;
v6 = thisflag;
v3 = macrocount;
++v5;
thisflag = 0;
lastflag = v6;
if ( macrocount - 1 <= v5 )
goto LABEL_11;
}
inmacro = 0;
return v2;
}

original_code:
int
executemacro(int f, int n)
{
 int i, j, flag, num;
 PF funct;
 if (macrodef ||
     (macrocount >= 256 && macro[256 - 1].m_funct
     != finishmacro)) {
  dobeep();
  ewprintf("Macro too long. Aborting.");
  return (0);
 }
 if (macrocount == 0)
  return (1);
 inmacro = 1;
 for (i = n; i > 0; i--) {
  maclcur = maclhead->l_fp;
  flag = 0;
  num = 1;
  for (j = 0; j < macrocount - 1; j++) {
   funct = macro[j].m_funct;
   if (funct == universal_argument) {
    flag = 7;
    num = macro[++j].m_count;
    continue;
   }
   if ((*funct)(flag, num) != 1) {
    inmacro = 0;
    return (0);
   }
   lastflag = thisflag;
   thisflag = 0;
   flag = 0;
   num = 1;
  }
 }
 inmacro = 0;
 return (1);
}

canonical_original_code:
int executemacro(int f, int n)
{
 int i; int j; int flag; int num;
 int (*funct)(int, int);
 if (macrodef ||
     (macrocount >= 256 && macro[256 - 1].m_funct
     != finishmacro)) {
  dobeep();
  ewprintf("Macro too long. Aborting.");
  return (0);
 }
 if (macrocount == 0)
  return (1);
 inmacro = 1;
 for (i = n; i > 0; i--) {
  maclcur = maclhead->l_fp;
  flag = 0;
  num = 1;
  for (j = 0; j < macrocount - 1; j++) {
   funct = macro[j].m_funct;
   if (funct == universal_argument) {
    flag = 7;
    num = macro[++j].m_count;
    continue;
   }
   if ((*funct)(flag, num) != 1) {
    inmacro = 0;
    return (0);
   }
   lastflag = thisflag;
   thisflag = 0;
   flag = 0;
   num = 1;
  }
 }
 inmacro = 0;
 return (1);
}

variable_types: i int

variable_types: j int

variable_types: flag int

variable_types: num int

variable_types:
funct
int (*)(int, int)


showall

decompiled_code:
__int64 __fastcall showall(__int64 a1, __int64 a2, const char *a3)
{
unsigned int i; // ebx
void *v5; // rax
void *v6; // rbp
__int64 v8; // [rsp+8h] [rbp-90h] BYREF
char s[16]; // [rsp+10h] [rbp-88h] BYREF
char v10[120]; // [rsp+20h] [rbp-78h] BYREF

if ( !(unsigned int)addlinef(a1, &unk_6B1, &unk_6B0) )
return 0LL;
for ( i = 0; i != 256; ++i )
{
v5 = (void *)doscan(a2, i, &v8);
v6 = v5;
if ( v5 != &selfinsert && v5 != &rescan )
{
getkeyname(v10, 80LL, i);
snprintf(s, 0x10uLL, "%s%s ", a3, v10);
if ( v6 )
{
function_name(v6);
if ( !(unsigned int)addlinef(a1, "%-16s%s", s) )
return 0LL;
}
else if ( !(unsigned int)showall(a1, v8, s) )
{
return 0LL;
}
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, const char *a3)
{
unsigned int i; // ebx
void *v5; // rax
void *v6; // rbp
__int64 v8; // [rsp+8h] [rbp-90h] BYREF
char s[16]; // [rsp+10h] [rbp-88h] BYREF
char v10[120]; // [rsp+20h] [rbp-78h] BYREF

if ( !(unsigned int)addlinef(a1, &unk_6B1, &unk_6B0) )
return 0LL;
for ( i = 0; i != 256; ++i )
{
v5 = (void *)doscan(a2, i, &v8);
v6 = v5;
if ( v5 != &selfinsert && v5 != &rescan )
{
getkeyname(v10, 80LL, i);
snprintf(s, 0x10uLL, "%s%s ", a3, v10);
if ( v6 )
{
function_name(v6);
if ( !(unsigned int)addlinef(a1, "%-16s%s", s) )
return 0LL;
}
else if ( !(unsigned int)func0(a1, v8, s) )
{
return 0LL;
}
}
}
return 1LL;
}

original_code:
static int
showall(struct buffer *bp, KEYMAP *map, char *prefix)
{
 KEYMAP *newmap;
 char buf[80], keybuf[16];
 PF fun;
 int c;
 if (addlinef(bp, "%s", "") == 0)
  return (0);
 for (c = 0; c < 256; c++) {
  fun = doscan(map, c, &newmap);
  if (fun == rescan || fun == selfinsert)
   continue;
  getkeyname(buf, sizeof(buf), c);
  (void)snprintf(keybuf, sizeof(keybuf), "%s%s ", prefix, buf);
  if (fun == ((void *)0)) {
   if (showall(bp, newmap, keybuf) == 0)
    return (0);
  } else {
   if (addlinef(bp, "%-16s%s", keybuf,
        function_name(fun)) == 0)
    return (0);
  }
 }
 return (1);
}

canonical_original_code:
static int showall(struct buffer *bp, struct keymap_s *map, char *prefix)
{
 struct keymap_s *newmap;
 char buf[80]; char keybuf[16];
 int (*fun)(int, int);
 int c;
 if (addlinef(bp, "%s", "") == 0)
  return (0);
 for (c = 0; c < 256; c++) {
  fun = doscan(map, c, &newmap);
  if (fun == rescan || fun == selfinsert)
   continue;
  getkeyname(buf, sizeof(buf), c);
  (void)snprintf(keybuf, sizeof(keybuf), "%s%s ", prefix, buf);
  if (fun == ((void *)0)) {
   if (showall(bp, newmap, keybuf) == 0)
    return (0);
  } else {
   if (addlinef(bp, "%-16s%s", keybuf,
        function_name(fun)) == 0)
    return (0);
  }
 }
 return (1);
}

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:
map
struct keymap_s *

variable_types:
prefix
char *

variable_types:
buf
char [80]

variable_types:
keybuf
char [16]

variable_types:
fun
int (*)(int, int)

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

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

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


findbind

decompiled_code:
__int64 __fastcall findbind(__int64 a1, __int64 a2, char *a3, size_t a4)
{
unsigned int i; // er14
__int64 v7; // rax
unsigned int v8; // er15
__int64 v10; // [rsp+8h] [rbp-60h] BYREF
char v11[16]; // [rsp+10h] [rbp-58h] BYREF
char v12[72]; // [rsp+20h] [rbp-48h] BYREF

for ( i = 0; i != 256; ++i )
{
v7 = doscan(a1, i, &v10);
if ( v7 == a2 )
{
v8 = 1;
getkeyname(a3, a4, i);
return v8;
}
if ( !v7 )
{
v8 = findbind(v10, a2, v11, 16LL);
if ( v8 == 1 )
{
getkeyname(v12, 16LL, i);
snprintf(a3, a4, "%s %s", v12, v11);
return v8;
}
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, char *a3, size_t a4)
{
unsigned int i; // er14
__int64 v7; // rax
unsigned int v8; // er15
__int64 v10; // [rsp+8h] [rbp-60h] BYREF
char v11[16]; // [rsp+10h] [rbp-58h] BYREF
char v12[72]; // [rsp+20h] [rbp-48h] BYREF

for ( i = 0; i != 256; ++i )
{
v7 = doscan(a1, i, &v10);
if ( v7 == a2 )
{
v8 = 1;
getkeyname(a3, a4, i);
return v8;
}
if ( !v7 )
{
v8 = func1(v10, a2, v11, 16LL);
if ( v8 == 1 )
{
getkeyname(v12, 16LL, i);
snprintf(a3, a4, "%s %s", v12, v11);
return v8;
}
}
}
return 0;
}

original_code:
static int
findbind(KEYMAP *map, PF fun, char *buf, size_t len)
{
 KEYMAP *newmap;
 PF nfun;
 char buf2[16], keybuf[16];
 int c;
 for (c = 0; c < 256; c++) {
  nfun = doscan(map, c, &newmap);
  if (nfun == fun) {
   getkeyname(buf, len, c);
   return (1);
  }
  if (nfun == ((void *)0)) {
   if (findbind(newmap, fun, buf2, sizeof(buf2)) == 1) {
    getkeyname(keybuf, sizeof(keybuf), c);
    (void)snprintf(buf, len, "%s %s", keybuf, buf2);
    return (1);
   }
  }
 }
 return (0);
}

canonical_original_code:
static int findbind(struct keymap_s *map, int (*fun)(int, int), char *buf, unsigned long len)
{
 struct keymap_s *newmap;
 int (*nfun)(int, int);
 char buf2[16]; char keybuf[16];
 int c;
 for (c = 0; c < 256; c++) {
  nfun = doscan(map, c, &newmap);
  if (nfun == fun) {
   getkeyname(buf, len, c);
   return (1);
  }
  if (nfun == ((void *)0)) {
   if (findbind(newmap, fun, buf2, sizeof(buf2)) == 1) {
    getkeyname(keybuf, sizeof(keybuf), c);
    (void)snprintf(buf, len, "%s %s", keybuf, buf2);
    return (1);
   }
  }
 }
 return (0);
}

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

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types:
nfun
int (*)(int, int)

variable_types: c int


decompiled_code:
__int64 __fastcall help_help(unsigned int a1, unsigned int a2)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rsi
__int64 (__fastcall *v6)(); // rax

v3 = name_map("help");
if ( !v3 )
return 0LL;
v4 = v3;
ewprintf("a b c: ");
do
{
do
{
v5 = (unsigned int)getkey(0LL);
v6 = (__int64 (__fastcall *)())doscan(v4, v5, 0LL);
}
while ( v6 == help_help );
}
while ( !v6 );
if ( macrodef )
{
if ( macrocount <= 255 )
*((_QWORD *)&macro + macrocount - 1) = v6;
}
return ((__int64 (__fastcall *)(_QWORD, _QWORD))v6)(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rsi
__int64 (__fastcall *v6)(); // rax

v3 = name_map("help");
if ( !v3 )
return 0LL;
v4 = v3;
ewprintf("a b c: ");
do
{
do
{
v5 = (unsigned int)getkey(0LL);
v6 = (__int64 (__fastcall *)())doscan(v4, v5, 0LL);
}
while ( v6 == help_help );
}
while ( !v6 );
if ( macrodef )
{
if ( macrocount <= 255 )
*((_QWORD *)&macro + macrocount - 1) = v6;
}
return ((__int64 (__fastcall *)(_QWORD, _QWORD))v6)(a1, a2);
}

original_code:
int
help_help(int f, int n)
{
 KEYMAP *kp;
 PF funct;
 if ((kp = name_map("help")) == ((void *)0))
  return (0);
 ewprintf("a b c: ");
 do {
  funct = doscan(kp, getkey(0), ((void *)0));
 } while (funct == ((void *)0) || funct == help_help);
 if (macrodef && macrocount < 256)
  macro[macrocount - 1].m_funct = funct;
 return ((*funct)(f, n));
}

canonical_original_code:
int help_help(int f, int n)
{
 struct keymap_s *kp;
 int (*funct)(int, int);
 if ((kp = name_map("help")) == ((void *)0))
  return (0);
 ewprintf("a b c: ");
 do {
  funct = doscan(kp, getkey(0), ((void *)0));
 } while (funct == ((void *)0) || funct == help_help);
 if (macrodef && macrocount < 256)
  macro[macrocount - 1].m_funct = funct;
 return ((*funct)(f, n));
}

variable_types: f int

variable_types: n int

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


desckey

decompiled_code:
__int64 desckey()
{
unsigned int v1; // eax
__int64 v2; // rbx
char *v3; // rbx
int v4; // er13
unsigned int v5; // eax
int v6; // edx
__int64 v7; // rsi
_WORD *v8; // r12
void *v9; // rax
__int16 v10; // ax
__int64 v11; // rdi
__int64 v12; // rbx
__int64 v13; // rsi
__int64 v14; // [rsp+0h] [rbp-90h] BYREF
char v15[136]; // [rsp+8h] [rbp-88h] BYREF

if ( inmacro )
return 1LL;
v1 = strlcpy(v15, "Describe key briefly: ", 80LL);
key = 0;
v2 = (int)v1;
if ( v1 >= 0x50 )
v2 = 79LL;
v3 = &v15[v2];
v4 = *(__int16 *)(curbp + 88LL);
v14 = **(_QWORD **)(curbp + 8LL * *(__int16 *)(curbp + 88LL) + 48);
while ( 1 )
{
ewprintf("%s");
*(v3 - 1) = 32;
v5 = getkey(0LL);
v6 = key + 1;
*((_WORD *)&key + key + 2) = v5;
key = v6;
v7 = v5;
v8 = (_WORD *)getkeyname(v3, 80 - (v3 - v15), (unsigned int)(__int16)v5);
v9 = (void *)doscan(v14, v7, &v14);
if ( v9 )
{
if ( v9 != &rescan )
goto LABEL_19;
v10 = *((_WORD *)&key + key + 1);
if ( (*((_BYTE *)&cinfo + (unsigned __int8)v10) & 2) == 0 )
goto LABEL_11;
v9 = (void *)doscan(v14, (unsigned int)(v10 + 32), &v14);
if ( v9 )
break;
}
LABEL_22:
v3 = (char *)v8 + 1;
*v8 = 45;
}
if ( v9 == &rescan )
{
LABEL_11:
while ( --v4 >= 0 )
{
v11 = **(_QWORD **)(curbp + 8LL * v4 + 48);
v14 = v11;
if ( key <= 0 )
goto LABEL_22;
v12 = 0LL;
while ( 1 )
{
v9 = (void *)doscan(v11, (unsigned int)*((__int16 *)&key + v12 + 2), &v14);
if ( v9 )
break;
if ( key <= (int)++v12 )
goto LABEL_22;
v11 = v14;
}
if ( key - 1 == (_DWORD)v12 && v9 != &rescan )
goto LABEL_19;
}
goto LABEL_23;
}
LABEL_19:
if ( v9 == &selfinsert )
{
LABEL_23:
ewprintf("%k is not bound to any function");
return 1LL;
}
v13 = function_name(v9);
if ( v13 )
ewprintf("%k runs the command %s", v13);
else
ewprintf("%k is bound to an unnamed function");
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v1; // eax
__int64 v2; // rbx
char *v3; // rbx
int v4; // er13
unsigned int v5; // eax
int v6; // edx
__int64 v7; // rsi
_WORD *v8; // r12
void *v9; // rax
__int16 v10; // ax
__int64 v11; // rdi
__int64 v12; // rbx
__int64 v13; // rsi
__int64 v14; // [rsp+0h] [rbp-90h] BYREF
char v15[136]; // [rsp+8h] [rbp-88h] BYREF

if ( inmacro )
return 1LL;
v1 = strlcpy(v15, "Describe key briefly: ", 80LL);
key = 0;
v2 = (int)v1;
if ( v1 >= 0x50 )
v2 = 79LL;
v3 = &v15[v2];
v4 = *(__int16 *)(curbp + 88LL);
v14 = **(_QWORD **)(curbp + 8LL * *(__int16 *)(curbp + 88LL) + 48);
while ( 1 )
{
ewprintf("%s");
*(v3 - 1) = 32;
v5 = getkey(0LL);
v6 = key + 1;
*((_WORD *)&key + key + 2) = v5;
key = v6;
v7 = v5;
v8 = (_WORD *)getkeyname(v3, 80 - (v3 - v15), (unsigned int)(__int16)v5);
v9 = (void *)doscan(v14, v7, &v14);
if ( v9 )
{
if ( v9 != &rescan )
goto LABEL_19;
v10 = *((_WORD *)&key + key + 1);
if ( (*((_BYTE *)&cinfo + (unsigned __int8)v10) & 2) == 0 )
goto LABEL_11;
v9 = (void *)doscan(v14, (unsigned int)(v10 + 32), &v14);
if ( v9 )
break;
}
LABEL_22:
v3 = (char *)v8 + 1;
*v8 = 45;
}
if ( v9 == &rescan )
{
LABEL_11:
while ( --v4 >= 0 )
{
v11 = **(_QWORD **)(curbp + 8LL * v4 + 48);
v14 = v11;
if ( key <= 0 )
goto LABEL_22;
v12 = 0LL;
while ( 1 )
{
v9 = (void *)doscan(v11, (unsigned int)*((__int16 *)&key + v12 + 2), &v14);
if ( v9 )
break;
if ( key <= (int)++v12 )
goto LABEL_22;
v11 = v14;
}
if ( key - 1 == (_DWORD)v12 && v9 != &rescan )
goto LABEL_19;
}
goto LABEL_23;
}
LABEL_19:
if ( v9 == &selfinsert )
{
LABEL_23:
ewprintf("%k is not bound to any function");
return 1LL;
}
v13 = function_name(v9);
if ( v13 )
ewprintf("%k runs the command %s", v13);
else
ewprintf("%k is bound to an unnamed function");
return 1LL;
}

original_code:
int
desckey(int f, int n)
{
 KEYMAP *curmap;
 PF funct;
 int c, m, i, num;
 char *pep;
 char dprompt[80];
 if (inmacro)
  return (1);
 num = strlcpy(dprompt, "Describe key briefly: ", sizeof(dprompt));
 if (num >= sizeof(dprompt))
  num = sizeof(dprompt) - 1;
 pep = dprompt + num;
 key.k_count = 0;
 m = curbp->b_nmodes;
 curmap = curbp->b_modes[m]->p_map;
 for (;;) {
  for (;;) {
   ewprintf("%s", dprompt);
   pep[-1] = ' ';
   pep = getkeyname(pep, sizeof(dprompt) - (pep - dprompt),
       key.k_chars[key.k_count++] = c = getkey(0));
   if ((funct = doscan(curmap, c, &curmap)) != ((void *)0))
    break;
   *pep++ = '-';
   *pep = '\0';
  }
  if (funct != rescan)
   break;
  if (((cinfo[((unsigned char) (key.k_chars[key.k_count - 1]))]&0x02)!=0)) {
   funct = doscan(curmap,
       ((key.k_chars[key.k_count - 1])+0x20), &curmap);
   if (funct == ((void *)0)) {
    *pep++ = '-';
    *pep = '\0';
    continue;
   }
   if (funct != rescan)
    break;
  }
nextmode:
  if (--m < 0)
   break;
  curmap = curbp->b_modes[m]->p_map;
  for (i = 0; i < key.k_count; i++) {
   funct = doscan(curmap, key.k_chars[i], &curmap);
   if (funct != ((void *)0)) {
    if (i == key.k_count - 1 && funct != rescan)
     goto found;
    funct = rescan;
    goto nextmode;
   }
  }
  *pep++ = '-';
  *pep = '\0';
 }
found:
 if (funct == rescan || funct == selfinsert)
  ewprintf("%k is not bound to any function");
 else if ((pep = (char *)function_name(funct)) != ((void *)0))
  ewprintf("%k runs the command %s", pep);
 else
  ewprintf("%k is bound to an unnamed function");
 return (1);
}

canonical_original_code:
int desckey(int f, int n)
{
 struct keymap_s *curmap;
 int (*funct)(int, int);
 int c; int m; int i; int num;
 char *pep;
 char dprompt[80];
 if (inmacro)
  return (1);
 num = strlcpy(dprompt, "Describe key briefly: ", sizeof(dprompt));
 if (num >= sizeof(dprompt))
  num = sizeof(dprompt) - 1;
 pep = dprompt + num;
 key.k_count = 0;
 m = curbp->b_nmodes;
 curmap = curbp->b_modes[m]->p_map;
 for (;;) {
  for (;;) {
   ewprintf("%s", dprompt);
   pep[-1] = ' ';
   pep = getkeyname(pep, sizeof(dprompt) - (pep - dprompt),
       key.k_chars[key.k_count++] = c = getkey(0));
   if ((funct = doscan(curmap, c, &curmap)) != ((void *)0))
    break;
   *pep++ = '-';
   *pep = '\0';
  }
  if (funct != rescan)
   break;
  if (((cinfo[((unsigned char) (key.k_chars[key.k_count - 1]))]&0x02)!=0)) {
   funct = doscan(curmap,
       ((key.k_chars[key.k_count - 1])+0x20), &curmap);
   if (funct == ((void *)0)) {
    *pep++ = '-';
    *pep = '\0';
    continue;
   }
   if (funct != rescan)
    break;
  }
nextmode:
  if (--m < 0)
   break;
  curmap = curbp->b_modes[m]->p_map;
  for (i = 0; i < key.k_count; i++) {
   funct = doscan(curmap, key.k_chars[i], &curmap);
   if (funct != ((void *)0)) {
    if (i == key.k_count - 1 && funct != rescan)
     goto found;
    funct = rescan;
    goto nextmode;
   }
  }
  *pep++ = '-';
  *pep = '\0';
 }
found:
 if (funct == rescan || funct == selfinsert)
  ewprintf("%k is not bound to any function");
 else if ((pep = (char *)function_name(funct)) != ((void *)0))
  ewprintf("%k runs the command %s", pep);
 else
  ewprintf("%k is bound to an unnamed function");
 return (1);
}

variable_types: m int

variable_types: i int

variable_types:
pep
char *

variable_types:
dprompt
char [80]


wallchart

decompiled_code:
__int64 wallchart()
{
__int64 v0; // rbp
__int64 v1; // rax
int v2; // er12
__int64 result; // rax
__int64 v4; // rbx

v0 = bfind("*help*", 1LL);
if ( (unsigned int)bclear(v0) != 1 )
return 0LL;
v1 = curbp;
*(_BYTE *)(v0 + 91) |= 0x10u;
v2 = *(__int16 *)(v1 + 88);
if ( v2 > 0 )
{
while ( 1 )
{
v4 = v2 + 6LL;
if ( !(unsigned int)addlinef(
v0,
"Local keybindings for mode %s:",
*(const char **)(*(_QWORD *)(v1 + 8 * v4) + 8LL)) )
break;
if ( !(unsigned int)showall(v0, **(_QWORD **)(curbp + 8 * v4), (const char *)&unk_6B0)
|| !(unsigned int)addlinef(v0, "%s", (const char *)&unk_6B0) )
{
return 0LL;
}
if ( !--v2 )
goto LABEL_3;
v1 = curbp;
}
result = 0LL;
}
else
{
LABEL_3:
if ( !(unsigned int)addlinef(v0, "%s", "Global bindings:")
|| !(unsigned int)showall(v0, fundamental_mode, (const char *)&unk_6B0) )
{
return 0LL;
}
result = popbuftop(v0, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbp
__int64 v1; // rax
int v2; // er12
__int64 result; // rax
__int64 v4; // rbx

v0 = bfind("*help*", 1LL);
if ( (unsigned int)bclear(v0) != 1 )
return 0LL;
v1 = curbp;
*(_BYTE *)(v0 + 91) |= 0x10u;
v2 = *(__int16 *)(v1 + 88);
if ( v2 > 0 )
{
while ( 1 )
{
v4 = v2 + 6LL;
if ( !(unsigned int)addlinef(
v0,
"Local keybindings for mode %s:",
*(const char **)(*(_QWORD *)(v1 + 8 * v4) + 8LL)) )
break;
if ( !(unsigned int)func0(v0, **(_QWORD **)(curbp + 8 * v4), (const char *)&unk_6B0)
|| !(unsigned int)addlinef(v0, "%s", (const char *)&unk_6B0) )
{
return 0LL;
}
if ( !--v2 )
goto LABEL_3;
v1 = curbp;
}
result = 0LL;
}
else
{
LABEL_3:
if ( !(unsigned int)addlinef(v0, "%s", "Global bindings:")
|| !(unsigned int)func0(v0, fundamental_mode, (const char *)&unk_6B0) )
{
return 0LL;
}
result = popbuftop(v0, 0LL);
}
return result;
}

original_code:
int
wallchart(int f, int n)
{
 int m;
 struct buffer *bp;
 bp = bfind("*help*", 1);
 if (bclear(bp) != 1)
  return (0);
 bp->b_flag |= 0x10;
 for (m = curbp->b_nmodes; m > 0; m--) {
  if ((addlinef(bp, "Local keybindings for mode %s:",
    curbp->b_modes[m]->p_name) == 0) ||
      (showall(bp, curbp->b_modes[m]->p_map, "") == 0) ||
      (addlinef(bp, "%s", "") == 0))
   return (0);
 }
 if ((addlinef(bp, "%s", "Global bindings:") == 0) ||
     (showall(bp, (fundamental_mode.p_map), "") == 0))
  return (0);
 return (popbuftop(bp, 0x00));
}

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


decompiled_code:
__int64 apropos_command()
{
__int64 v0; // rbp
__int64 result; // rax
__int64 v2; // rax
__int64 v3; // r12
_QWORD *v4; // rbx
const char *v5; // r13
__int64 v6; // rax
char needle[32]; // [rsp+10h] [rbp-68h] BYREF
char v8[72]; // [rsp+30h] [rbp-48h] BYREF

if ( !eread("apropos: ", needle, 32LL, 72LL) )
return 2LL;
v0 = bfind("*help*", 1LL);
result = bclear(v0);
if ( (_DWORD)result )
{
v2 = complete_function_list(&unk_6B0);
v3 = v2;
if ( v2 )
{
v4 = (_QWORD *)v2;
while ( 1 )
{
v5 = (const char *)v4[1];
if ( strstr(v5, needle) )
{
v8[0] = 0;
v6 = name_function(v5);
findbind(fundamental_mode, v6, v8, 0x20uLL);
if ( !(unsigned int)addlinef(v0, "%-32s%s", (const char *)v4[1], v8) )
break;
}
v4 = (_QWORD *)*v4;
if ( !v4 )
goto LABEL_8;
}
free_file_list(v3);
result = 0LL;
}
else
{
LABEL_8:
free_file_list(v3);
result = popbuftop(v0, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbp
__int64 result; // rax
__int64 v2; // rax
__int64 v3; // r12
_QWORD *v4; // rbx
const char *v5; // r13
__int64 v6; // rax
char needle[32]; // [rsp+10h] [rbp-68h] BYREF
char v8[72]; // [rsp+30h] [rbp-48h] BYREF

if ( !eread("apropos: ", needle, 32LL, 72LL) )
return 2LL;
v0 = bfind("*help*", 1LL);
result = bclear(v0);
if ( (_DWORD)result )
{
v2 = complete_function_list(&unk_6B0);
v3 = v2;
if ( v2 )
{
v4 = (_QWORD *)v2;
while ( 1 )
{
v5 = (const char *)v4[1];
if ( strstr(v5, needle) )
{
v8[0] = 0;
v6 = name_function(v5);
func1(fundamental_mode, v6, v8, 0x20uLL);
if ( !(unsigned int)addlinef(v0, "%-32s%s", (const char *)v4[1], v8) )
break;
}
v4 = (_QWORD *)*v4;
if ( !v4 )
goto LABEL_8;
}
free_file_list(v3);
result = 0LL;
}
else
{
LABEL_8:
free_file_list(v3);
result = popbuftop(v0, 0LL);
}
}
return result;
}

original_code:
int
apropos_command(int f, int n)
{
 struct buffer *bp;
 struct list *fnames, *el;
 char string[32];
 if (eread("apropos: ", string, sizeof(string), 0x0040 | 0x0008) == ((void *)0))
  return (2);
 bp = bfind("*help*", 1);
 if (bclear(bp) == 0)
  return (0);
 fnames = complete_function_list("");
 for (el = fnames; el != ((void *)0); el = el->l_p.l_nxt) {
  char buf[32];
  if (strstr(el->l_name, string) == ((void *)0))
   continue;
  buf[0] = '\0';
  findbind((fundamental_mode.p_map), name_function(el->l_name),
      buf, sizeof(buf));
  if (addlinef(bp, "%-32s%s", el->l_name, buf) == 0) {
   free_file_list(fnames);
   return (0);
  }
 }
 free_file_list(fnames);
 return (popbuftop(bp, 0x00));
}

canonical_original_code:
int apropos_command(int f, int n)
{
 struct buffer *bp;
 struct list *fnames; struct list *el;
 char string[32];
 if (eread("apropos: ", string, sizeof(string), 0x0040 | 0x0008) == ((void *)0))
  return (2);
 bp = bfind("*help*", 1);
 if (bclear(bp) == 0)
  return (0);
 fnames = complete_function_list("");
 for (el = fnames; el != ((void *)0); el = el->l_p.l_nxt) {
  char buf[32];
  if (strstr(el->l_name, string) == ((void *)0))
   continue;
  buf[0] = '\0';
  findbind((fundamental_mode.p_map), name_function(el->l_name),
      buf, sizeof(buf));
  if (addlinef(bp, "%-32s%s", el->l_name, buf) == 0) {
   free_file_list(fnames);
   return (0);
  }
 }
 free_file_list(fnames);
 return (popbuftop(bp, 0x00));
}

variable_types: struct list { union { struct mgwin { struct list w_list; 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; } *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; } *l_wp; struct buffer *x_bp; struct list *l_nxt; } l_p; char *l_name; } *

variable_types:
string
char [32]

variable_types:
buf
char [32]


getmatch

decompiled_code:
_BOOL8 __fastcall getmatch(int a1, int a2)
{
if ( a1 == 40 )
return a2 == 41;
if ( a1 <= 40 )
{
if ( a1 == 34 )
return a2 == 34;
if ( a1 == 39 )
return a2 == 39;
}
else
{
if ( a1 == 91 )
return a2 == 93;
if ( a1 == 123 )
return a2 == 125;
}
return 0LL;
}

original_code:
static int
getmatch(int c, int mc)
{
 int match = 0;
 switch (c) {
 case '"':
  match = (mc == '"');
  break;
 case '\'':
  match = (mc == '\'');
  break;
 case '(':
  match = (mc == ')');
  break;
 case '[':
  match = (mc == ']');
  break;
 case '{':
  match = (mc == '}');
  break;
 }
 return (match);
}

variable_types: mc int

variable_types: match int


cmode

decompiled_code:
__int64 __fastcall cmode(__int64 a1, __int64 a2)
{
return changemode(a1, a2, &unk_ADC);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return changemode(a1, a2, &unk_ADC);
}

original_code:
int
cmode(int f, int n)
{
 return(changemode(f, n, "c"));
}


decompiled_code:
__int64 __fastcall in_whitespace(__int64 a1, int a2)
{
const unsigned __int16 **v4; // rax
unsigned int v5; // er8
const unsigned __int16 *v6; // rdi
int v7; // esi
__int64 v8; // rax

if ( a2 <= 0 )
return 0LL;
v4 = _ctype_b_loc();
v5 = 0;
v6 = *v4;
v7 = a2 - 1;
v8 = 0LL;
do
{
if ( (v6[*(unsigned __int8 *)(*(_QWORD *)(a1 + 24) + v8)] & 0x2000) == 0 )
break;
if ( v7 == (_DWORD)v8 )
v5 = 1;
++v8;
}
while ( a2 != v8 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
const unsigned __int16 **v4; // rax
unsigned int v5; // er8
const unsigned __int16 *v6; // rdi
int v7; // esi
__int64 v8; // rax

if ( a2 <= 0 )
return 0LL;
v4 = _ctype_b_loc();
v5 = 0;
v6 = *v4;
v7 = a2 - 1;
v8 = 0LL;
do
{
if ( (v6[*(unsigned __int8 *)(*(_QWORD *)(a1 + 24) + v8)] & 0x2000) == 0 )
break;
if ( v7 == (_DWORD)v8 )
v5 = 1;
++v8;
}
while ( a2 != v8 );
return v5;
}

original_code:
static int
in_whitespace(struct line *lp, int len)
{
 int lo;
 int inwhitep = 0;
 for (lo = 0; lo < len; lo++) {
  if (!((*__ctype_b_loc ())[(int) (((((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short int) _ISspace))
   break;
  if (lo == len - 1)
   inwhitep = 1;
 }
 return (inwhitep);
}

canonical_original_code:
static int in_whitespace(struct line *lp, int len)
{
 int lo;
 int inwhitep = 0;
 for (lo = 0; lo < len; lo++) {
  if (!((*__ctype_b_loc ())[(int) (((((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short) _ISspace))
   break;
  if (lo == len - 1)
   inwhitep = 1;
 }
 return (inwhitep);
}

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

variable_types: len int

variable_types: lo int

variable_types: inwhitep int


isnonblank

decompiled_code:
__int64 __fastcall isnonblank(__int64 a1, int a2)
{
const unsigned __int16 **v3; // rax
int v4; // ecx
unsigned int v5; // er9
const unsigned __int16 *v6; // rdi
unsigned __int8 *v7; // rax
__int64 v8; // r8
__int64 v9; // rsi
int v10; // edx

if ( a2 <= 0 )
return 0LL;
v3 = _ctype_b_loc();
v4 = 0;
v5 = 0;
v6 = *v3;
v7 = *(unsigned __int8 **)(a1 + 24);
v8 = (__int64)&v7[a2 - 1 + 1];
while ( 1 )
{
while ( 1 )
{
v9 = *v7;
v10 = *v7;
if ( (v6[v9] & 0x2000) == 0 )
break;
++v7;
v4 = 0;
if ( (unsigned __int8 *)v8 == v7 )
return v5;
}
if ( (_BYTE)v10 == 35 || v4 && (unsigned __int8)v9 == 47 )
break;
++v7;
v5 = 1;
LOBYTE(v10) = (unsigned __int8)v9 == 47;
v4 = v10 & (v4 ^ 1);
if ( (unsigned __int8 *)v8 == v7 )
return v5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
const unsigned __int16 **v3; // rax
int v4; // ecx
unsigned int v5; // er9
const unsigned __int16 *v6; // rdi
unsigned __int8 *v7; // rax
__int64 v8; // r8
__int64 v9; // rsi
int v10; // edx

if ( a2 <= 0 )
return 0LL;
v3 = _ctype_b_loc();
v4 = 0;
v5 = 0;
v6 = *v3;
v7 = *(unsigned __int8 **)(a1 + 24);
v8 = (__int64)&v7[a2 - 1 + 1];
while ( 1 )
{
while ( 1 )
{
v9 = *v7;
v10 = *v7;
if ( (v6[v9] & 0x2000) == 0 )
break;
++v7;
v4 = 0;
if ( (unsigned __int8 *)v8 == v7 )
return v5;
}
if ( (_BYTE)v10 == 35 || v4 && (unsigned __int8)v9 == 47 )
break;
++v7;
v5 = 1;
LOBYTE(v10) = (unsigned __int8)v9 == 47;
v4 = v10 & (v4 ^ 1);
if ( (unsigned __int8 *)v8 == v7 )
return v5;
}
return 0LL;
}

original_code:
static int
isnonblank(const struct line *lp, int omax)
{
 int nonblankp = 0;
 int slashp = 0;
 int lo;
 int c;
 for (lo = 0; lo < omax; lo++) {
  if (!((*__ctype_b_loc ())[(int) ((c = (((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short int) _ISspace)) {
   nonblankp = 1;
   if (c == '#' || (slashp && c == '/')) {
    nonblankp = 0;
    break;
   } else if (!slashp && c == '/') {
    slashp = 1;
    continue;
   }
  }
  slashp = 0;
 }
 return (nonblankp);
}

canonical_original_code:
static int isnonblank(struct line *lp, int omax)
{
 int nonblankp = 0;
 int slashp = 0;
 int lo;
 int c;
 for (lo = 0; lo < omax; lo++) {
  if (!((*__ctype_b_loc ())[(int) ((c = (((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short) _ISspace)) {
   nonblankp = 1;
   if (c == '#' || (slashp && c == '/')) {
    nonblankp = 0;
    break;
   } else if (!slashp && c == '/') {
    slashp = 1;
    continue;
   }
  }
  slashp = 0;
 }
 return (nonblankp);
}

variable_types: omax int

variable_types: nonblankp int

variable_types: slashp int

variable_types: c int

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


findnonblank

original_code:
static struct line *
findnonblank(struct line *lp)
{
 int lo;
 int nonblankp = 0;
 int commentp = 0;
 int slashp;
 int astp;
 int c;
 while (((lp)->l_bp) != curbp->b_headp && (commentp || !nonblankp)) {
  lp = ((lp)->l_bp);
  slashp = 0;
  astp = 0;
  nonblankp = isnonblank(lp, ((lp)->l_used));
  for (lo = ((lp)->l_used) - 1; lo >= 0; lo--) {
   if (!((*__ctype_b_loc ())[(int) ((c = (((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short int) _ISspace)) {
    if (commentp) {
     if (c == '*')
      astp = 1;
     else if (astp && c == '/') {
      commentp = 0;
      nonblankp = isnonblank(lp, lo);
     }
    } else {
     if (c == '/')
      slashp = 1;
     else if (slashp && c == '*')
      commentp = 1;
    }
   }
  }
 }
 if (((lp)->l_bp) == curbp->b_headp && !nonblankp)
  return (curbp->b_headp);
 return (lp);
}

canonical_original_code:
static struct line *findnonblank(struct line *lp)
{
 int lo;
 int nonblankp = 0;
 int commentp = 0;
 int slashp;
 int astp;
 int c;
 while (((lp)->l_bp) != curbp->b_headp && (commentp || !nonblankp)) {
  lp = ((lp)->l_bp);
  slashp = 0;
  astp = 0;
  nonblankp = isnonblank(lp, ((lp)->l_used));
  for (lo = ((lp)->l_used) - 1; lo >= 0; lo--) {
   if (!((*__ctype_b_loc ())[(int) ((c = (((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short) _ISspace)) {
    if (commentp) {
     if (c == '*')
      astp = 1;
     else if (astp && c == '/') {
      commentp = 0;
      nonblankp = isnonblank(lp, lo);
     }
    } else {
     if (c == '/')
      slashp = 1;
     else if (slashp && c == '*')
      commentp = 1;
    }
   }
  }
 }
 if (((lp)->l_bp) == curbp->b_headp && !nonblankp)
  return (curbp->b_headp);
 return (lp);
}

variable_types:
lp
struct line *

variable_types: commentp int

variable_types: astp int

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


getindent

original_code:
static int
getindent(const struct line *lp, int *curi)
{
 int lo, co;
 int nicol = 0;
 int c = '\0';
 int newind = 0;
 int stringp = 0;
 int escp = 0;
 int lastc = '\0';
 int nparen = 0;
 int obrace = 0;
 int cbrace = 0;
 int firstnwsp = 0;
 int colonp = 0;
 int questionp = 0;
 int slashp = 0;
 int astp = 0;
 int cpos = -1;
 int cppp = 0;
 *curi = 0;
 for (lo = 0; lo < ((lp)->l_used); lo++) {
  if (!((*__ctype_b_loc ())[(int) ((c = (((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short int) _ISspace))
   break;
  if (c == '\t'
      ) {
   nicol |= 0x07;
  }
  nicol++;
 }
 if (lo == ((lp)->l_used))
  nicol = 0;
 newind = 0;
 for (co = lo; co < ((lp)->l_used); co++) {
  c = (((unsigned char) ((lp)->l_text[(co)])));
  if (!firstnwsp && !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
   if (c == '#')
    cppp = 1;
   firstnwsp = 1;
  }
  if (c == '\\')
   escp = !escp;
  else if (stringp) {
   if (!escp && (c == '"' || c == '\'')) {
    if (getmatch(c, lastc))
     stringp = 0;
   }
  } else if (c == '"' || c == '\'') {
   stringp = 1;
   lastc = c;
  } else if (c == '(') {
   nparen++;
  } else if (c == ')') {
   nparen--;
  } else if (c == '{') {
   obrace++;
   firstnwsp = 0;
  } else if (c == '}') {
   cbrace++;
  } else if (c == '?') {
   questionp = 1;
  } else if (c == ':') {
   if (!questionp)
    colonp = 1;
  } else if (c == '/') {
   if (firstnwsp) {
    if (astp)
     cpos = -1;
    else
     slashp = 1;
   }
  } else if (c == '*') {
   if (slashp)
    cpos = co;
   else
    astp = 1;
  } else if (firstnwsp) {
   firstnwsp = 0;
  }
  if (c != '\\')
   escp = 0;
  if (c != '*')
   astp = 0;
  if (c != '/')
   slashp = 0;
 }
 if (colonp) {
  *curi += cc_colon_indent;
  newind -= cc_colon_indent;
 }
 *curi -= (cbrace) * cc_basic_indent;
 newind += obrace * cc_basic_indent;
 if (nparen < 0)
  newind -= cc_cont_indent;
 else if (nparen > 0)
  newind += cc_cont_indent;
 *curi += nicol;
 if (cppp) {
  newind = nicol;
  *curi = 0;
 } else {
  newind += nicol;
 }
 if (cpos != -1)
  newind = findcolpos(curbp, lp, cpos);
 return (newind);
}

canonical_original_code:
static int getindent(struct line *lp, int *curi)
{
 int lo; int co;
 int nicol = 0;
 int c = '\0';
 int newind = 0;
 int stringp = 0;
 int escp = 0;
 int lastc = '\0';
 int nparen = 0;
 int obrace = 0;
 int cbrace = 0;
 int firstnwsp = 0;
 int colonp = 0;
 int questionp = 0;
 int slashp = 0;
 int astp = 0;
 int cpos = -1;
 int cppp = 0;
 *curi = 0;
 for (lo = 0; lo < ((lp)->l_used); lo++) {
  if (!((*__ctype_b_loc ())[(int) ((c = (((unsigned char) ((lp)->l_text[(lo)])))))] & (unsigned short) _ISspace))
   break;
  if (c == '\t'
      ) {
   nicol |= 0x07;
  }
  nicol++;
 }
 if (lo == ((lp)->l_used))
  nicol = 0;
 newind = 0;
 for (co = lo; co < ((lp)->l_used); co++) {
  c = (((unsigned char) ((lp)->l_text[(co)])));
  if (!firstnwsp && !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
   if (c == '#')
    cppp = 1;
   firstnwsp = 1;
  }
  if (c == '\\')
   escp = !escp;
  else if (stringp) {
   if (!escp && (c == '"' || c == '\'')) {
    if (getmatch(c, lastc))
     stringp = 0;
   }
  } else if (c == '"' || c == '\'') {
   stringp = 1;
   lastc = c;
  } else if (c == '(') {
   nparen++;
  } else if (c == ')') {
   nparen--;
  } else if (c == '{') {
   obrace++;
   firstnwsp = 0;
  } else if (c == '}') {
   cbrace++;
  } else if (c == '?') {
   questionp = 1;
  } else if (c == ':') {
   if (!questionp)
    colonp = 1;
  } else if (c == '/') {
   if (firstnwsp) {
    if (astp)
     cpos = -1;
    else
     slashp = 1;
   }
  } else if (c == '*') {
   if (slashp)
    cpos = co;
   else
    astp = 1;
  } else if (firstnwsp) {
   firstnwsp = 0;
  }
  if (c != '\\')
   escp = 0;
  if (c != '*')
   astp = 0;
  if (c != '/')
   slashp = 0;
 }
 if (colonp) {
  *curi += cc_colon_indent;
  newind -= cc_colon_indent;
 }
 *curi -= (cbrace) * cc_basic_indent;
 newind += obrace * cc_basic_indent;
 if (nparen < 0)
  newind -= cc_cont_indent;
 else if (nparen > 0)
  newind += cc_cont_indent;
 *curi += nicol;
 if (cppp) {
  newind = nicol;
  *curi = 0;
 } else {
  newind += nicol;
 }
 if (cpos != -1)
  newind = findcolpos(curbp, lp, cpos);
 return (newind);
}

variable_types:
curi
int *

variable_types: co int

variable_types: nicol int

variable_types: newind int

variable_types: stringp int

variable_types: escp int

variable_types: lastc int

variable_types: nparen int

variable_types: obrace int

variable_types: cbrace int

variable_types: firstnwsp int

variable_types: colonp int

variable_types: questionp int

variable_types: cpos int

variable_types: cppp int


decompiled_code:
__int64 __fastcall cc_indent(__int64 a1, int a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v4; // ebx
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 0;
if ( a2 >= 0 )
{
undo_boundary_enable(8LL, 0LL);
deltrailwhite(8LL, 1LL);
v3 = findnonblank(*(_QWORD *)(curwp + 32LL));
v4 = getindent(v3, &v6);
delleadwhite(8LL, 1LL);
getindent(*(_QWORD *)(curwp + 32LL), v7);
if ( (signed int)(v7[0] + v4) < 0 )
v2 = indent(4LL, 0LL);
else
v2 = indent(4LL, v7[0] + v4);
undo_boundary_enable(8LL, 1LL);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v4; // ebx
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 0;
if ( a2 >= 0 )
{
undo_boundary_enable(8LL, 0LL);
deltrailwhite(8LL, 1LL);
v3 = func4(*(_QWORD *)(curwp + 32LL));
v4 = func6(v3, &v6);
delleadwhite(8LL, 1LL);
func6(*(_QWORD *)(curwp + 32LL), v7);
if ( (signed int)(v7[0] + v4) < 0 )
v2 = indent(4LL, 0LL);
else
v2 = indent(4LL, v7[0] + v4);
undo_boundary_enable(8LL, 1LL);
}
return v2;
}

original_code:
int
cc_indent(int f, int n)
{
 int pi, mi;
 int ci;
 struct line *lp;
 int ret;
 if (n < 0)
  return (0);
 undo_boundary_enable(8, 0);
 if (cc_strip_trailp)
  deltrailwhite(8, 1);
 lp = findnonblank(curwp->w_dotp);
 pi = getindent(lp, &mi);
 delleadwhite(8, 1);
 (void)getindent(curwp->w_dotp, &ci);
 if (pi + ci < 0)
  ret = indent(4, 0);
 else
  ret = indent(4, pi + ci);
 undo_boundary_enable(8, 1);
 return (ret);
}

canonical_original_code:
int cc_indent(int f, int n)
{
 int pi; int mi;
 int ci;
 struct line *lp;
 int ret;
 if (n < 0)
  return (0);
 undo_boundary_enable(8, 0);
 if (cc_strip_trailp)
  deltrailwhite(8, 1);
 lp = findnonblank(curwp->w_dotp);
 pi = getindent(lp, &mi);
 delleadwhite(8, 1);
 (void)getindent(curwp->w_dotp, &ci);
 if (pi + ci < 0)
  ret = indent(4, 0);
 else
  ret = indent(4, pi + ci);
 undo_boundary_enable(8, 1);
 return (ret);
}

variable_types: f int

variable_types: n int

variable_types: pi int

variable_types: mi int

variable_types: ci int

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

variable_types: ret int


decompiled_code:
__int64 __fastcall cc_char(__int64 a1, int a2)
{
if ( a2 < 0 )
return 0LL;
if ( (unsigned int)selfinsert(8LL) )
return cc_indent(8LL, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
if ( a2 < 0 )
return 0LL;
if ( (unsigned int)selfinsert(8LL) )
return func7(8LL, a2);
return 0LL;
}

original_code:
int
cc_char(int f, int n)
{
 if (n < 0)
  return (0);
 if (selfinsert(8, n) == 0)
  return (0);
 return (cc_indent(8, n));
}


decompiled_code:
__int64 __fastcall cc_brace(__int64 a1, int a2)
{
if ( a2 < 0 )
return 0LL;
if ( (unsigned int)showmatch(8LL, 1LL) )
return cc_indent(8LL, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
if ( a2 < 0 )
return 0LL;
if ( (unsigned int)showmatch(8LL, 1LL) )
return func7(8LL, a2);
return 0LL;
}

original_code:
int
cc_brace(int f, int n)
{
 if (n < 0)
  return (0);
 if (showmatch(8, 1) == 0)
  return (0);
 return (cc_indent(8, n));
}


decompiled_code:
__int64 __fastcall cc_tab(unsigned int a1)
{
__int64 v2; // rdi
int v3; // ebx
__int64 result; // rax

v2 = *(_QWORD *)(curwp + 32LL);
v3 = *(_DWORD *)(v2 + 20);
if ( (unsigned int)in_whitespace(v2, v3) || !v3 )
result = selfinsert(a1);
else
result = cc_indent(8LL, 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
__int64 v2; // rdi
int v3; // ebx
__int64 result; // rax

v2 = *(_QWORD *)(curwp + 32LL);
v3 = *(_DWORD *)(v2 + 20);
if ( (unsigned int)func2(v2, v3) || !v3 )
result = selfinsert(a1);
else
result = func7(8LL, 1);
return result;
}

original_code:
int
cc_tab(int f, int n)
{
 int inwhitep = 0;
 inwhitep = in_whitespace(curwp->w_dotp, ((curwp->w_dotp)->l_used));
 if (((curwp->w_dotp)->l_used) == 0 || inwhitep)
  return (selfinsert(f, n));
 return (cc_indent(8, 1));
}

variable_types: inwhitep int


decompiled_code:
__int64 __fastcall cc_lfindent(__int64 a1, int a2)
{
if ( a2 < 0 )
return 0LL;
if ( (unsigned int)newline(8LL, 1LL) )
return cc_indent(8LL, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
if ( a2 < 0 )
return 0LL;
if ( (unsigned int)newline(8LL, 1LL) )
return func7(8LL, a2);
return 0LL;
}

original_code:
int
cc_lfindent(int f, int n)
{
 if (n < 0)
  return (0);
 if (newline(8, 1) == 0)
  return (0);
 return (cc_indent(8, n));
}


decompiled_code:
__int64 cmode_init()
{
funmap_add(cmode, "c-mode");
funmap_add(cc_char, "c-handle-special-char");
funmap_add(cc_brace, "c-handle-special-brace");
funmap_add(cc_tab, "c-tab-or-indent");
funmap_add(cc_indent, "c-indent");
funmap_add(cc_lfindent, "c-indent-and-newline");
return maps_add(&cmodemap, &unk_ADC);
}

canonical_decompiled_code:
__int64 func12()
{
funmap_add(cmode, "c-mode");
funmap_add(cc_char, "c-handle-special-char");
funmap_add(cc_brace, "c-handle-special-brace");
funmap_add(cc_tab, "c-tab-or-indent");
funmap_add(cc_indent, "c-indent");
funmap_add(cc_lfindent, "c-indent-and-newline");
return maps_add(&cmodemap, &unk_ADC);
}

original_code:
void
cmode_init(void)
{
 funmap_add(cmode, "c-mode");
 funmap_add(cc_char, "c-handle-special-char");
 funmap_add(cc_brace, "c-handle-special-brace");
 funmap_add(cc_tab, "c-tab-or-indent");
 funmap_add(cc_indent, "c-indent");
 funmap_add(cc_lfindent, "c-indent-and-newline");
 maps_add((KEYMAP *)&cmodemap, "c");
}

canonical_original_code:
void cmode_init()
{
 funmap_add(cmode, "c-mode");
 funmap_add(cc_char, "c-handle-special-char");
 funmap_add(cc_brace, "c-handle-special-brace");
 funmap_add(cc_tab, "c-tab-or-indent");
 funmap_add(cc_indent, "c-indent");
 funmap_add(cc_lfindent, "c-indent-and-newline");
 maps_add((struct keymap_s *)&cmodemap, "c");
}


decompiled_code:
__int64 arc4random()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

pthread_mutex_lock(&arc4random_mtx);
rs_random_u32(v1);
pthread_mutex_unlock(&arc4random_mtx);
return v1[0];
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

pthread_mutex_lock(&arc4random_mtx);
func8(v1);
pthread_mutex_unlock(&arc4random_mtx);
return v1[0];
}

original_code:
uint32_t
arc4random(void)
{
 uint32_t val;
 pthread_mutex_lock(&arc4random_mtx);
 _rs_random_u32(&val);
 pthread_mutex_unlock(&arc4random_mtx);
 return val;
}

canonical_original_code:
unsigned int arc4random()
{
 unsigned int val;
 pthread_mutex_lock(&arc4random_mtx);
 _rs_random_u32(&val);
 pthread_mutex_unlock(&arc4random_mtx);
 return val;
}

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall arc4random_buf(void *dest, unsigned __int64 a2)
{
pthread_mutex_lock(&arc4random_mtx);
rs_random_buf(dest, a2);
return pthread_mutex_unlock(&arc4random_mtx);
}

canonical_decompiled_code:
int __fastcall func11(void *dest, unsigned __int64 a2)
{
pthread_mutex_lock(&arc4random_mtx);
func9(dest, a2);
return pthread_mutex_unlock(&arc4random_mtx);
}

original_code:
void
arc4random_buf(void *buf, size_t n)
{
 pthread_mutex_lock(&arc4random_mtx);
 _rs_random_buf(buf, n);
 pthread_mutex_unlock(&arc4random_mtx);
}

canonical_original_code:
void arc4random_buf(void *buf, unsigned long n)
{
 pthread_mutex_lock(&arc4random_mtx);
 _rs_random_buf(buf, n);
 pthread_mutex_unlock(&arc4random_mtx);
}

variable_types:
buf
void *

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall arc4random_uniform(unsigned int a1)
{
unsigned int v1; // eax

if ( a1 <= 1 )
return 0LL;
do
v1 = arc4random();
while ( -a1 % a1 > v1 );
return v1 % a1;
}

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

if ( a1 <= 1 )
return 0LL;
do
v1 = arc4random();
while ( -a1 % a1 > v1 );
return v1 % a1;
}

original_code:
uint32_t
arc4random_uniform(uint32_t upper_bound)
{
 uint32_t r, min;
 if (upper_bound < 2)
  return 0;
 min = -upper_bound % upper_bound;
 for (;;) {
  r = arc4random();
  if (r >= min)
   break;
 }
 return r % upper_bound;
}

canonical_original_code:
unsigned int arc4random_uniform(unsigned int upper_bound)
{
 unsigned int r; unsigned int min;
 if (upper_bound < 2)
  return 0;
 min = -upper_bound % upper_bound;
 for (;;) {
  r = arc4random();
  if (r >= min)
   break;
 }
 return r % upper_bound;
}

variable_types:
r
unsigned int

variable_types:
min
unsigned int


bellinit

decompiled_code:
void bellinit()
{
doaudiblebell = 1;
dovisiblebell = 0;
}

canonical_decompiled_code:
void func0()
{
doaudiblebell = 1;
dovisiblebell = 0;
}

original_code:
void
bellinit(void)
{
 doaudiblebell = 1;
 dovisiblebell = 0;
}


dobeep

decompiled_code:
int dobeep()
{
int result; // eax

if ( !doaudiblebell )
{
result = dovisiblebell;
if ( !dovisiblebell )
return result;
LABEL_5:
sgarbf = 1;
update(0LL);
return usleep(0xC350u);
}
ttbeep();
result = dovisiblebell;
if ( dovisiblebell )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

if ( !doaudiblebell )
{
result = dovisiblebell;
if ( !dovisiblebell )
return result;
LABEL_5:
sgarbf = 1;
update(0LL);
return usleep(0xC350u);
}
ttbeep();
result = dovisiblebell;
if ( dovisiblebell )
goto LABEL_5;
return result;
}

original_code:
void
dobeep(void)
{
 if (doaudiblebell) {
  ttbeep();
 }
 if (dovisiblebell) {
  sgarbf = 1;
  update(0);
  usleep(50000);
 }
}

canonical_original_code:
void dobeep()
{
 if (doaudiblebell) {
  ttbeep();
 }
 if (dovisiblebell) {
  sgarbf = 1;
  update(0);
  usleep(50000);
 }
}


toggleaudiblebell

decompiled_code:
__int64 __fastcall toggleaudiblebell(char a1, int a2)
{
if ( (a1 & 7) != 0 )
doaudiblebell = a2 > 0;
else
doaudiblebell = doaudiblebell == 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, int a2)
{
if ( (a1 & 7) != 0 )
doaudiblebell = a2 > 0;
else
doaudiblebell = doaudiblebell == 0;
return 1LL;
}

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


togglevisiblebell

decompiled_code:
__int64 __fastcall togglevisiblebell(char a1, int a2)
{
if ( (a1 & 7) != 0 )
dovisiblebell = a2 > 0;
else
dovisiblebell = dovisiblebell == 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, int a2)
{
if ( (a1 & 7) != 0 )
dovisiblebell = a2 > 0;
else
dovisiblebell = dovisiblebell == 0;
return 1LL;
}

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


ttykeymapinit

decompiled_code:
int ttykeymapinit()
{
char **v0; // rax
char *v1; // rdi
__int64 v2; // rdi
char **v3; // rax
const char *v4; // rdi

v0 = cur_term->type.Strings;
if ( v0[79] )
{
dobindkey(fundamental_mode, "backward-char");
v0 = cur_term->type.Strings;
}
if ( v0[83] )
{
dobindkey(fundamental_mode, "forward-char");
v0 = cur_term->type.Strings;
}
if ( v0[87] )
{
dobindkey(fundamental_mode, "previous-line");
v0 = cur_term->type.Strings;
}
if ( v0[61] )
{
dobindkey(fundamental_mode, "next-line");
v0 = cur_term->type.Strings;
}
if ( v0[158] || v0[76] )
{
dobindkey(fundamental_mode, "beginning-of-line");
v0 = cur_term->type.Strings;
}
if ( v0[164] )
{
dobindkey(fundamental_mode, "end-of-line");
v0 = cur_term->type.Strings;
}
if ( v0[81] )
{
dobindkey(fundamental_mode, "scroll-up");
v0 = cur_term->type.Strings;
}
if ( v0[82] )
{
dobindkey(fundamental_mode, "scroll-down");
v0 = cur_term->type.Strings;
}
if ( v0[59] )
dobindkey(fundamental_mode, "delete-char");
v1 = getenv("TERM");
if ( v1 )
{
v2 = startupfile(v1);
if ( v2 )
{
if ( (unsigned int)load(v2) != 1 )
ewprintf("Error reading key initialization file");
}
}
v3 = cur_term->type.Strings;
v4 = v3[89];
if ( v4 )
LODWORD(v3) = tputs(v4, 1, (int (*)(int))&ttputc);
return (int)v3;
}

canonical_decompiled_code:
int func0()
{
char **v0; // rax
char *v1; // rdi
__int64 v2; // rdi
char **v3; // rax
const char *v4; // rdi

v0 = cur_term->type.Strings;
if ( v0[79] )
{
dobindkey(fundamental_mode, "backward-char");
v0 = cur_term->type.Strings;
}
if ( v0[83] )
{
dobindkey(fundamental_mode, "forward-char");
v0 = cur_term->type.Strings;
}
if ( v0[87] )
{
dobindkey(fundamental_mode, "previous-line");
v0 = cur_term->type.Strings;
}
if ( v0[61] )
{
dobindkey(fundamental_mode, "next-line");
v0 = cur_term->type.Strings;
}
if ( v0[158] || v0[76] )
{
dobindkey(fundamental_mode, "beginning-of-line");
v0 = cur_term->type.Strings;
}
if ( v0[164] )
{
dobindkey(fundamental_mode, "end-of-line");
v0 = cur_term->type.Strings;
}
if ( v0[81] )
{
dobindkey(fundamental_mode, "scroll-up");
v0 = cur_term->type.Strings;
}
if ( v0[82] )
{
dobindkey(fundamental_mode, "scroll-down");
v0 = cur_term->type.Strings;
}
if ( v0[59] )
dobindkey(fundamental_mode, "delete-char");
v1 = getenv("TERM");
if ( v1 )
{
v2 = startupfile(v1);
if ( v2 )
{
if ( (unsigned int)load(v2) != 1 )
ewprintf("Error reading key initialization file");
}
}
v3 = cur_term->type.Strings;
v4 = v3[89];
if ( v4 )
LODWORD(v3) = tputs(v4, 1, (int (*)(int))&ttputc);
return (int)v3;
}

original_code:
void
ttykeymapinit(void)
{
 char *cp;
 if (((TERMTYPE *)(cur_term))-> Strings[79])
  dobindkey((fundamental_mode.p_map), "backward-char", ((TERMTYPE *)(cur_term))-> Strings[79]);
 if (((TERMTYPE *)(cur_term))-> Strings[83])
  dobindkey((fundamental_mode.p_map), "forward-char", ((TERMTYPE *)(cur_term))-> Strings[83]);
 if (((TERMTYPE *)(cur_term))-> Strings[87])
  dobindkey((fundamental_mode.p_map), "previous-line", ((TERMTYPE *)(cur_term))-> Strings[87]);
 if (((TERMTYPE *)(cur_term))-> Strings[61])
  dobindkey((fundamental_mode.p_map), "next-line", ((TERMTYPE *)(cur_term))-> Strings[61]);
 if (((TERMTYPE *)(cur_term))-> Strings[158])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((TERMTYPE *)(cur_term))-> Strings[158]);
 else if (((TERMTYPE *)(cur_term))-> Strings[76])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((TERMTYPE *)(cur_term))-> Strings[76]);
 if (((TERMTYPE *)(cur_term))-> Strings[164])
  dobindkey((fundamental_mode.p_map), "end-of-line", ((TERMTYPE *)(cur_term))-> Strings[164]);
 if (((TERMTYPE *)(cur_term))-> Strings[81])
  dobindkey((fundamental_mode.p_map), "scroll-up", ((TERMTYPE *)(cur_term))-> Strings[81]);
 if (((TERMTYPE *)(cur_term))-> Strings[82])
  dobindkey((fundamental_mode.p_map), "scroll-down", ((TERMTYPE *)(cur_term))-> Strings[82]);
 if (((TERMTYPE *)(cur_term))-> Strings[59])
  dobindkey((fundamental_mode.p_map), "delete-char", ((TERMTYPE *)(cur_term))-> Strings[59]);
 if ((cp = getenv("TERM"))) {
  if (((cp = startupfile(cp)) != ((void *)0)) && (load(cp) != 1))
   ewprintf("Error reading key initialization file");
 }
 if (((TERMTYPE *)(cur_term))-> Strings[89])
  tputs(((TERMTYPE *)(cur_term))-> Strings[89], 1, ttputc);
}

canonical_original_code:
void ttykeymapinit()
{
 char *cp;
 if (((struct termtype *)(cur_term))-> Strings[79])
  dobindkey((fundamental_mode.p_map), "backward-char", ((struct termtype *)(cur_term))-> Strings[79]);
 if (((struct termtype *)(cur_term))-> Strings[83])
  dobindkey((fundamental_mode.p_map), "forward-char", ((struct termtype *)(cur_term))-> Strings[83]);
 if (((struct termtype *)(cur_term))-> Strings[87])
  dobindkey((fundamental_mode.p_map), "previous-line", ((struct termtype *)(cur_term))-> Strings[87]);
 if (((struct termtype *)(cur_term))-> Strings[61])
  dobindkey((fundamental_mode.p_map), "next-line", ((struct termtype *)(cur_term))-> Strings[61]);
 if (((struct termtype *)(cur_term))-> Strings[158])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((struct termtype *)(cur_term))-> Strings[158]);
 else if (((struct termtype *)(cur_term))-> Strings[76])
  dobindkey((fundamental_mode.p_map), "beginning-of-line", ((struct termtype *)(cur_term))-> Strings[76]);
 if (((struct termtype *)(cur_term))-> Strings[164])
  dobindkey((fundamental_mode.p_map), "end-of-line", ((struct termtype *)(cur_term))-> Strings[164]);
 if (((struct termtype *)(cur_term))-> Strings[81])
  dobindkey((fundamental_mode.p_map), "scroll-up", ((struct termtype *)(cur_term))-> Strings[81]);
 if (((struct termtype *)(cur_term))-> Strings[82])
  dobindkey((fundamental_mode.p_map), "scroll-down", ((struct termtype *)(cur_term))-> Strings[82]);
 if (((struct termtype *)(cur_term))-> Strings[59])
  dobindkey((fundamental_mode.p_map), "delete-char", ((struct termtype *)(cur_term))-> Strings[59]);
 if ((cp = getenv("TERM"))) {
  if (((cp = startupfile(cp)) != ((void *)0)) && (load(cp) != 1))
   ewprintf("Error reading key initialization file");
 }
 if (((struct termtype *)(cur_term))-> Strings[89])
  tputs(((struct termtype *)(cur_term))-> Strings[89], 1, ttputc);
}

variable_types:
cp
char *

user_defined_types: struct termtype { char *term_names; char *str_table; char *Booleans; short *Numbers; char **Strings; char *ext_str_table; char **ext_Names; unsigned short num_Booleans; unsigned short num_Numbers; unsigned short num_Strings; unsigned short ext_Booleans; unsigned short ext_Numbers; unsigned short ext_Strings; }


ttykeymaptidy

decompiled_code:
int ttykeymaptidy()
{
char **v0; // rax
const char *v1; // rdi

v0 = cur_term->type.Strings;
v1 = v0[88];
if ( v1 )
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
return (int)v0;
}

canonical_decompiled_code:
int func1()
{
char **v0; // rax
const char *v1; // rdi

v0 = cur_term->type.Strings;
v1 = v0[88];
if ( v1 )
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
return (int)v0;
}

original_code:
void
ttykeymaptidy(void)
{
 if (((TERMTYPE *)(cur_term))-> Strings[88])
  tputs(((TERMTYPE *)(cur_term))-> Strings[88], 1, ttputc);
}

canonical_original_code:
void ttykeymaptidy()
{
 if (((struct termtype *)(cur_term))-> Strings[88])
  tputs(((struct termtype *)(cur_term))-> Strings[88], 1, ttputc);
}


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n", _progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n", _progname);
exit(1);
}

original_code:
static __attribute__((__noreturn__)) void
usage()
{
 fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n",
     __progname);
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n",
     __progname);
 exit(1);
}


quit

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

result = anycb(0LL);
if ( (_DWORD)result != 2 )
{
if ( (_DWORD)result == 3 )
{
result = 0LL;
}
else
{
if ( !(_DWORD)result || (unsigned int)eyesno("Modified buffers exist; really exit") == 1 )
{
vttidy();
closetags();
exit(0);
}
result = 1LL;
}
}
return result;
}

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

result = anycb(0LL);
if ( (_DWORD)result != 2 )
{
if ( (_DWORD)result == 3 )
{
result = 0LL;
}
else
{
if ( !(_DWORD)result || (unsigned int)eyesno("Modified buffers exist; really exit") == 1 )
{
vttidy();
closetags();
exit(0);
}
result = 1LL;
}
}
return result;
}

original_code:
int
quit(int f, int n)
{
 int s;
 if ((s = anycb(0)) == 2)
  return (2);
 if (s == 3 || s == 3)
  return (0);
 if (s == 0
     || eyesno("Modified buffers exist; really exit") == 1) {
  vttidy();
  closetags();
  exit(0);
 }
 return (1);
}

variable_types: s int


ctrlg

decompiled_code:
__int64 ctrlg()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 2LL;
}

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

canonical_original_code:
int ctrlg(int f, int n)
{
 return (2);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er13
char *v4; // r12
int v6; // eax
__int64 v7; // r15
int v8; // ebx
void (__fastcall *v9)(__int64, __int64); // r14
__int64 v10; // rdi
__int64 v11; // rdx
__int64 v12; // rdi
__int64 i; // rsi
__int64 j; // rax
__int64 v15; // rax
const char **v16; // r13
int v17; // ebx
const char **v18; // r15
const char *v19; // rbp
__int64 v20; // rbp
int v21; // eax
int v22; // eax
int v23; // eax
int v24; // eax
__int64 v25[8]; // [rsp+8h] [rbp-40h] BYREF

v3 = 0;
v4 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "nf:");
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
if ( v4 )
errx(1, "cannot specify more than one initial function");
v4 = optarg;
}
else
{
if ( v6 != 110 )
usage();
v3 = 1;
}
}
v7 = optind;
v8 = argc - optind;
setlocale(0, &locale);
maps_init();
funmap_init();
dired_init();
grep_init();
theo_init();
cmode_init();
if ( v4 )
{
v9 = (void (__fastcall *)(__int64, __int64))name_function(v4);
if ( !v9 )
errx(1, "Unknown function `%s'", v4);
}
else
{
v9 = 0LL;
}
vtinit();
dirinit();
edinit_constprop_0();
ttykeymapinit();
bellinit();
update(2LL);
v10 = startupfile(0LL);
if ( v10 )
load(v10);
v11 = bheadp;
v12 = defb_flag;
for ( i = defb_nmodes; v11; v11 = *(_QWORD *)v11 )
{
*(_BYTE *)(v11 + 91) = v12;
for ( j = 0LL; (int)i >= (int)j; ++j )
*(_QWORD *)(v11 + 8 * j + 48) = *((_QWORD *)&defb_modes + j);
}
if ( v9 )
{
i = 1LL;
v12 = 4LL;
v9(4LL, 1LL);
}
if ( v3 )
{
i = 0LL;
v12 = 7LL;
makebkfile(7LL, 0LL);
}
if ( v8 > 0 )
{
v15 = (unsigned int)(v8 - 1);
v16 = &argv[v7];
v17 = 0;
v18 = &(&argv[v15])[v7 + 1];
do
{
v19 = *v16;
if ( **v16 == 43
&& strlen(*v16) > 1
&& (v12 = (__int64)(v19 + 1),
i = 0xFFFFFFFF80000000LL,
v21 = strtonum(v19 + 1, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, v25),
(*v16)[1])
&& !v25[0] )
{
startrow = v21;
}
else
{
v12 = (__int64)*v16;
i = 0LL;
v20 = adjustname(*v16, 0LL);
if ( v20 )
{
if ( v17 == 1 )
splitwind(0LL, 1LL);
curbp = findbuffer(v20);
if ( !curbp )
{
vttidy();
errx(1, "Can't find current buffer!");
}
i = curwp;
showbuffer(curbp, curwp, 0LL);
v12 = v20;
if ( (unsigned int)readin(v20) == 1 )
{
if ( v4 )
{
i = 1LL;
v12 = 4LL;
v9(4LL, 1LL);
}
++v17;
}
else
{
v12 = curbp;
killbuffer(curbp);
}
}
}
++v16;
}
while ( v16 != v18 );
if ( v17 > 2 )
{
i = 1LL;
v12 = 0LL;
listbuffers(0LL, 1LL);
}
}
thisflag = 0;
while ( 1 )
{
v22 = epresf;
if ( epresf == 2 )
goto LABEL_50;
while ( 1 )
{
if ( v22 == 1 )
epresf = 2;
if ( winch_flag )
{
i = 0LL;
do_redraw(0LL, 0LL, 1LL);
winch_flag = 0;
}
v12 = 2LL;
update(2LL);
v23 = thisflag;
thisflag = 0;
lastflag = v23;
v24 = doin(2LL, i);
if ( v24 == 1 )
break;
if ( v24 == 2 )
{
v12 = (__int64)"Quit";
ewprintf("Quit");
}
macrodef = 0;
v22 = epresf;
if ( epresf == 2 )
{
LABEL_50:
eerase(v12, i);
v22 = epresf;
}
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er13
char *v4; // r12
int v6; // eax
__int64 v7; // r15
int v8; // ebx
void (__fastcall *v9)(__int64, __int64); // r14
__int64 v10; // rdi
__int64 v11; // rdx
__int64 v12; // rdi
__int64 i; // rsi
__int64 j; // rax
__int64 v15; // rax
const char **v16; // r13
int v17; // ebx
const char **v18; // r15
const char *v19; // rbp
__int64 v20; // rbp
int v21; // eax
int v22; // eax
int v23; // eax
int v24; // eax
__int64 v25[8]; // [rsp+8h] [rbp-40h] BYREF

v3 = 0;
v4 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "nf:");
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
if ( v4 )
errx(1, "cannot specify more than one initial function");
v4 = optarg;
}
else
{
if ( v6 != 110 )
func0();
v3 = 1;
}
}
v7 = optind;
v8 = argc - optind;
setlocale(0, &locale);
maps_init();
funmap_init();
dired_init();
grep_init();
theo_init();
cmode_init();
if ( v4 )
{
v9 = (void (__fastcall *)(__int64, __int64))name_function(v4);
if ( !v9 )
errx(1, "Unknown function `%s'", v4);
}
else
{
v9 = 0LL;
}
vtinit();
dirinit();
func1();
ttykeymapinit();
bellinit();
update(2LL);
v10 = startupfile(0LL);
if ( v10 )
load(v10);
v11 = bheadp;
v12 = defb_flag;
for ( i = defb_nmodes; v11; v11 = *(_QWORD *)v11 )
{
*(_BYTE *)(v11 + 91) = v12;
for ( j = 0LL; (int)i >= (int)j; ++j )
*(_QWORD *)(v11 + 8 * j + 48) = *((_QWORD *)&defb_modes + j);
}
if ( v9 )
{
i = 1LL;
v12 = 4LL;
v9(4LL, 1LL);
}
if ( v3 )
{
i = 0LL;
v12 = 7LL;
makebkfile(7LL, 0LL);
}
if ( v8 > 0 )
{
v15 = (unsigned int)(v8 - 1);
v16 = &argv[v7];
v17 = 0;
v18 = &(&argv[v15])[v7 + 1];
do
{
v19 = *v16;
if ( **v16 == 43
&& strlen(*v16) > 1
&& (v12 = (__int64)(v19 + 1),
i = 0xFFFFFFFF80000000LL,
v21 = strtonum(v19 + 1, 0xFFFFFFFF80000000LL, 0x7FFFFFFFLL, v25),
(*v16)[1])
&& !v25[0] )
{
startrow = v21;
}
else
{
v12 = (__int64)*v16;
i = 0LL;
v20 = adjustname(*v16, 0LL);
if ( v20 )
{
if ( v17 == 1 )
splitwind(0LL, 1LL);
curbp = findbuffer(v20);
if ( !curbp )
{
vttidy();
errx(1, "Can't find current buffer!");
}
i = curwp;
showbuffer(curbp, curwp, 0LL);
v12 = v20;
if ( (unsigned int)readin(v20) == 1 )
{
if ( v4 )
{
i = 1LL;
v12 = 4LL;
v9(4LL, 1LL);
}
++v17;
}
else
{
v12 = curbp;
killbuffer(curbp);
}
}
}
++v16;
}
while ( v16 != v18 );
if ( v17 > 2 )
{
i = 1LL;
v12 = 0LL;
listbuffers(0LL, 1LL);
}
}
thisflag = 0;
while ( 1 )
{
v22 = epresf;
if ( epresf == 2 )
goto LABEL_50;
while ( 1 )
{
if ( v22 == 1 )
epresf = 2;
if ( winch_flag )
{
i = 0LL;
do_redraw(0LL, 0LL, 1LL);
winch_flag = 0;
}
v12 = 2LL;
update(2LL);
v23 = thisflag;
thisflag = 0;
lastflag = v23;
v24 = doin(2LL, i);
if ( v24 == 1 )
break;
if ( v24 == 2 )
{
v12 = (__int64)"Quit";
ewprintf("Quit");
}
macrodef = 0;
v22 = epresf;
if ( epresf == 2 )
{
LABEL_50:
eerase(v12, i);
v22 = epresf;
}
}
}
}

original_code:
int
main(int argc, char **argv)
{
 char *cp, *init_fcn_name = ((void *)0);
 PF init_fcn = ((void *)0);
 int o, i, nfiles;
 int nobackups = 0;
 struct buffer *bp = ((void *)0);
 while ((o = getopt(argc, argv, "nf:")) != -1)
  switch (o) {
  case 'n':
   nobackups = 1;
   break;
  case 'f':
   if (init_fcn_name != ((void *)0))
    errx(1, "cannot specify more than one "
        "initial function");
   init_fcn_name = optarg;
   break;
  default:
   usage();
  }
 argc -= optind;
 argv += optind;
 setlocale(0, "");
 maps_init();
 funmap_init();
 {
  extern void grep_init(void);
  extern void theo_init(void);
  extern void cmode_init(void);
  extern void dired_init(void);
  dired_init();
  grep_init();
  theo_init();
  cmode_init();
 }
 if (init_fcn_name &&
     (init_fcn = name_function(init_fcn_name)) == ((void *)0))
  errx(1, "Unknown function `%s'", init_fcn_name);
 vtinit();
 dirinit();
 edinit(bp);
 ttykeymapinit();
 bellinit();
 update(2);
 if ((cp = startupfile(((void *)0))) != ((void *)0))
  (void)load(cp);
 for (bp = bheadp; bp != ((void *)0); bp = bp->b_list.l_p.x_bp) {
  bp->b_flag = defb_flag;
  for (i = 0; i <= defb_nmodes; i++) {
                 bp->b_modes[i] = defb_modes[i];
         }
 }
 if (init_fcn)
  init_fcn(4, 1);
 if (nobackups)
  makebkfile(7, 0);
 for (nfiles = 0, i = 0; i < argc; i++) {
  if (argv[i][0] == '+' && strlen(argv[i]) >= 2) {
   long long lval;
   const char *errstr;
   lval = strtonum(&argv[i][1], (-0x7fffffff - 1), 0x7fffffff, &errstr);
   if (argv[i][1] == '\0' || errstr != ((void *)0))
    goto notnum;
   startrow = lval;
  } else {
notnum:
   cp = adjustname(argv[i], 0);
   if (cp != ((void *)0)) {
    if (nfiles == 1)
     splitwind(0, 1);
    if ((curbp = findbuffer(cp)) == ((void *)0)) {
     vttidy();
     errx(1, "Can't find current buffer!");
    }
    (void)showbuffer(curbp, curwp, 0);
    if (readin(cp) != 1)
     killbuffer(curbp);
    else {
     if (init_fcn_name)
      init_fcn(4, 1);
     nfiles++;
    }
   }
  }
 }
 if (nfiles > 2)
  listbuffers(0, 1);
 thisflag = 0;
 for (;;) {
  if (epresf == 2)
   eerase();
  if (epresf == 1)
   epresf = 2;
  if (winch_flag) {
   do_redraw(0, 0, 1);
   winch_flag = 0;
  }
  update(2);
  lastflag = thisflag;
  thisflag = 0;
  switch (doin()) {
  case 1:
   break;
  case 2:
   ewprintf("Quit");
  case 0:
  default:
   macrodef = 0;
  }
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *cp; char *init_fcn_name = ((void *)0);
 int (*init_fcn)(int, int) = ((void *)0);
 int o; int i; int nfiles;
 int nobackups = 0;
 struct buffer *bp = ((void *)0);
 while ((o = getopt(argc, argv, "nf:")) != -1)
  switch (o) {
  case 'n':
   nobackups = 1;
   break;
  case 'f':
   if (init_fcn_name != ((void *)0))
    errx(1, "cannot specify more than one "
        "initial function");
   init_fcn_name = optarg;
   break;
  default:
   usage();
  }
 argc -= optind;
 argv += optind;
 setlocale(0, "");
 maps_init();
 funmap_init();
 {
  extern void grep_init();
  extern void theo_init();
  extern void cmode_init();
  extern void dired_init();
  dired_init();
  grep_init();
  theo_init();
  cmode_init();
 }
 if (init_fcn_name &&
     (init_fcn = name_function(init_fcn_name)) == ((void *)0))
  errx(1, "Unknown function `%s'", init_fcn_name);
 vtinit();
 dirinit();
 edinit(bp);
 ttykeymapinit();
 bellinit();
 update(2);
 if ((cp = startupfile(((void *)0))) != ((void *)0))
  (void)load(cp);
 for (bp = bheadp; bp != ((void *)0); bp = bp->b_list.l_p.x_bp) {
  bp->b_flag = defb_flag;
  for (i = 0; i <= defb_nmodes; i++) {
                 bp->b_modes[i] = defb_modes[i];
         }
 }
 if (init_fcn)
  init_fcn(4, 1);
 if (nobackups)
  makebkfile(7, 0);
 for (nfiles = 0, i = 0; i < argc; i++) {
  if (argv[i][0] == '+' && strlen(argv[i]) >= 2) {
   long long lval;
   char *errstr;
   lval = strtonum(&argv[i][1], (-0x7fffffff - 1), 0x7fffffff, &errstr);
   if (argv[i][1] == '\0' || errstr != ((void *)0))
    goto notnum;
   startrow = lval;
  } else {
notnum:
   cp = adjustname(argv[i], 0);
   if (cp != ((void *)0)) {
    if (nfiles == 1)
     splitwind(0, 1);
    if ((curbp = findbuffer(cp)) == ((void *)0)) {
     vttidy();
     errx(1, "Can't find current buffer!");
    }
    (void)showbuffer(curbp, curwp, 0);
    if (readin(cp) != 1)
     killbuffer(curbp);
    else {
     if (init_fcn_name)
      init_fcn(4, 1);
     nfiles++;
    }
   }
  }
 }
 if (nfiles > 2)
  listbuffers(0, 1);
 thisflag = 0;
 for (;;) {
  if (epresf == 2)
   eerase();
  if (epresf == 1)
   epresf = 2;
  if (winch_flag) {
   do_redraw(0, 0, 1);
   winch_flag = 0;
  }
  update(2);
  lastflag = thisflag;
  thisflag = 0;
  switch (doin()) {
  case 1:
   break;
  case 2:
   ewprintf("Quit");
  case 0:
  default:
   macrodef = 0;
  }
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: o int

variable_types: i int

variable_types: nfiles int

variable_types: nobackups int

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

variable_types:
lval
long long

variable_types:
errstr
char *


reposition

decompiled_code:
__int64 __fastcall reposition(char a1, unsigned int a2)
{
int v2; // edi
_DWORD *v3; // rax

v2 = a1 & 7;
if ( v2 )
v2 = (a2 < 0x80000000) + a2;
v3 = curwp;
sgarbf = 1;
*((_BYTE *)curwp + 68) |= 1u;
v3[16] = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, unsigned int a2)
{
int v2; // edi
_DWORD *v3; // rax

v2 = a1 & 7;
if ( v2 )
v2 = (a2 < 0x80000000) + a2;
v3 = curwp;
sgarbf = 1;
*((_BYTE *)curwp + 68) |= 1u;
v3[16] = v2;
return 1LL;
}

original_code:
int
reposition(int f, int n)
{
 curwp->w_frame = (f & 7) ? (n >= 0 ? n + 1 : n) : 0;
 curwp->w_rflag |= 0x01;
 sgarbf = 1;
 return (1);
}

variable_types: f int

variable_types: n int


redraw

decompiled_code:
__int64 __fastcall redraw(__int64 a1, __int64 a2)
{
return do_redraw(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return func1(a1, a2, 0);
}

original_code:
int
redraw(int f, int n)
{
 return (do_redraw(f, n, 0));
}


showversion

decompiled_code:
__int64 showversion()
{
ewprintf(&unk_34, "Mg 2a");
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
ewprintf(&unk_34, "Mg 2a");
return 1LL;
}

original_code:
int
showversion(int f, int n)
{
 ewprintf("%s", version);
 return (1);
}


decompiled_code:
void funmap_init()
{
__int64 v0; // rdx
void **i; // rax
bool v2; // zf

if ( off_1E8 )
{
v0 = funs;
for ( i = &functnames; ; i += 3 )
{
v2 = i[4] == 0LL;
i[2] = (void *)v0;
v0 = (__int64)i;
if ( v2 )
break;
}
funs = (__int64)i;
}
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rdx
void **i; // rax
bool v2; // zf

if ( off_1E8 )
{
v0 = funs;
for ( i = &functnames; ; i += 3 )
{
v2 = i[4] == 0LL;
i[2] = (void *)v0;
v0 = (__int64)i;
if ( v2 )
break;
}
funs = (__int64)i;
}
}

original_code:
void
funmap_init(void)
{
 struct funmap *fn;
 for (fn = functnames; fn->fn_name != ((void *)0); fn++) {
  fn->fn_next = funs;
  funs = fn;
 }
}

canonical_original_code:
void funmap_init()
{
 struct funmap *fn;
 for (fn = functnames; fn->fn_name != ((void *)0); fn++) {
  fn->fn_next = funs;
  funs = fn;
 }
}

variable_types: struct funmap { int (*fn_funct)(int, int); char *fn_name; struct funmap *fn_next; } *


decompiled_code:
__int64 __fastcall funmap_add(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0LL;
v3 = funs;
*v2 = a1;
v2[1] = a2;
v2[2] = v3;
funs = (__int64)v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0LL;
v3 = funs;
*v2 = a1;
v2[1] = a2;
v2[2] = v3;
funs = (__int64)v2;
return 1LL;
}

original_code:
int
funmap_add(PF fun, const char *fname)
{
 struct funmap *fn;
 if ((fn = malloc(sizeof(*fn))) == ((void *)0))
  return (0);
 fn->fn_funct = fun;
 fn->fn_name = fname;
 fn->fn_next = funs;
 funs = fn;
 return (1);
}

canonical_original_code:
int funmap_add(int (*fun)(int, int), char *fname)
{
 struct funmap *fn;
 if ((fn = malloc(sizeof(*fn))) == ((void *)0))
  return (0);
 fn->fn_funct = fun;
 fn->fn_name = fname;
 fn->fn_next = funs;
 funs = fn;
 return (1);
}

variable_types:
fun
int (*)(int, int)

variable_types:
fname
char *

user_defined_types: struct funmap { int (*fn_funct)(int, int); char *fn_name; struct funmap *fn_next; }


decompiled_code:
__int64 __fastcall name_function(char *s2)
{
__int64 v1; // rbx

v1 = funs;
if ( !funs )
return 0LL;
while ( strcmp(*(const char **)(v1 + 8), s2) )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
return *(_QWORD *)v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
__int64 v1; // rbx

v1 = funs;
if ( !funs )
return 0LL;
while ( strcmp(*(const char **)(v1 + 8), s2) )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
return *(_QWORD *)v1;
}

original_code:
PF
name_function(const char *fname)
{
 struct funmap *fn;
 for (fn = funs; fn != ((void *)0); fn = fn->fn_next) {
  if (strcmp(fn->fn_name, fname) == 0)
   return (fn->fn_funct);
 }
 return (((void *)0));
}

canonical_original_code:
int (*name_function(char *fname))(int, int)
{
 struct funmap *fn;
 for (fn = funs; fn != ((void *)0); fn = fn->fn_next) {
  if (strcmp(fn->fn_name, fname) == 0)
   return (fn->fn_funct);
 }
 return (((void *)0));
}

return_type: int (*)(int, int)


displaymatch

original_code:
static void
displaymatch(struct line *clp, int cbo)
{
 struct line *tlp;
 int tbo;
 int cp;
 int bufo;
 int c;
 int inwindow;
 char buf[256];
 inwindow = 0;
 for (tlp = curwp->w_linep; tlp != ((curwp->w_dotp)->l_fp);
     tlp = ((tlp)->l_fp))
  if (tlp == clp)
   inwindow = 1;
 if (inwindow == 1) {
  tlp = curwp->w_dotp;
  tbo = curwp->w_doto;
  curwp->w_dotp = clp;
  curwp->w_doto = cbo;
  curwp->w_rflag |= 0x02;
  update(2);
  ttwait(1000);
  curwp->w_dotp = tlp;
  curwp->w_doto = tbo;
  curwp->w_rflag |= 0x02;
  update(2);
 } else {
  bufo = 0;
  for (cp = 0; cp < ((clp)->l_used); cp++) {
   c = (((unsigned char) ((clp)->l_text[(cp)])));
   if (c != '\t'
    )
    if (((cinfo[((unsigned char) (c))]&0x08)!=0)) {
     buf[bufo++] = '^';
     buf[bufo++] = ((c) ^ 0x40);
    } else
     buf[bufo++] = c;
   else
    do {
     buf[bufo++] = ' ';
    } while (bufo & 7);
  }
  buf[bufo++] = '\0';
  ewprintf("Matches %s", buf);
 }
}

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

variable_types: cbo int

variable_types: tbo int

variable_types: cp int

variable_types: bufo int

variable_types: c int

variable_types: inwindow int

variable_types:
buf
char [256]


balance

decompiled_code:
__int64 balance()
{
__int64 v0; // rdx
int v1; // er8
int v2; // eax
int v3; // er9
int v4; // ecx
__int64 v5; // rdi
__int64 result; // rax
int v7; // edx

v0 = 0LL;
v1 = *((__int16 *)&key + key + 1);
v2 = 41;
while ( v2 != v1 )
{
++v0;
v2 = byte_2C1[2 * v0];
if ( !byte_2C1[2 * v0] )
{
v3 = *((__int16 *)&key + key + 1);
goto LABEL_5;
}
}
v3 = bal[2 * (int)v0];
LABEL_5:
v4 = 0;
v5 = *(_QWORD *)(curwp + 32LL);
result = (unsigned int)(*(_DWORD *)(curwp + 48LL) - 1);
while ( 1 )
{
if ( !(_DWORD)result )
{
v5 = *(_QWORD *)(v5 + 8);
if ( *(_QWORD *)(curbp + 40LL) == v5 )
return result;
result = *(unsigned int *)(v5 + 20);
v7 = 10;
LABEL_8:
if ( v3 != 10 )
goto LABEL_9;
goto LABEL_13;
}
result = (unsigned int)(result - 1);
if ( (_DWORD)result == *(_DWORD *)(v5 + 20) )
{
v7 = 10;
goto LABEL_8;
}
v7 = *(unsigned __int8 *)(*(_QWORD *)(v5 + 24) + (int)result);
if ( v7 != v3 )
goto LABEL_9;
LABEL_13:
if ( !v4 )
break;
--v4;
LABEL_9:
v4 += v7 == v1;
}
displaymatch((_QWORD *)v5, result);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdx
int v1; // er8
int v2; // eax
int v3; // er9
int v4; // ecx
__int64 v5; // rdi
__int64 result; // rax
int v7; // edx

v0 = 0LL;
v1 = *((__int16 *)&key + key + 1);
v2 = 41;
while ( v2 != v1 )
{
++v0;
v2 = byte_2C1[2 * v0];
if ( !byte_2C1[2 * v0] )
{
v3 = *((__int16 *)&key + key + 1);
goto LABEL_5;
}
}
v3 = bal[2 * (int)v0];
LABEL_5:
v4 = 0;
v5 = *(_QWORD *)(curwp + 32LL);
result = (unsigned int)(*(_DWORD *)(curwp + 48LL) - 1);
while ( 1 )
{
if ( !(_DWORD)result )
{
v5 = *(_QWORD *)(v5 + 8);
if ( *(_QWORD *)(curbp + 40LL) == v5 )
return result;
result = *(unsigned int *)(v5 + 20);
v7 = 10;
LABEL_8:
if ( v3 != 10 )
goto LABEL_9;
goto LABEL_13;
}
result = (unsigned int)(result - 1);
if ( (_DWORD)result == *(_DWORD *)(v5 + 20) )
{
v7 = 10;
goto LABEL_8;
}
v7 = *(unsigned __int8 *)(*(_QWORD *)(v5 + 24) + (int)result);
if ( v7 != v3 )
goto LABEL_9;
LABEL_13:
if ( !v4 )
break;
--v4;
LABEL_9:
v4 += v7 == v1;
}
func0((_QWORD *)v5, result);
return 1LL;
}

original_code:
static int
balance(void)
{
 struct line *clp;
 int cbo;
 int c, i, depth;
 int rbal, lbal;
 rbal = key.k_chars[key.k_count - 1];
 lbal = rbal;
 for (i = 0; bal[i].right != '\0'; i++)
  if (bal[i].right == rbal) {
   lbal = bal[i].left;
   break;
  }
 clp = curwp->w_dotp;
 cbo = curwp->w_doto - 1;
 depth = 0;
 for (;;) {
  if (cbo == 0) {
   clp = ((clp)->l_bp);
   if (clp == curbp->b_headp)
    return (0);
   cbo = ((clp)->l_used) + 1;
  }
  if (--cbo == ((clp)->l_used))
   c = '\n';
  else
   c = (((unsigned char) ((clp)->l_text[(cbo)])));
  if (c == lbal) {
   if (depth == 0) {
    displaymatch(clp, cbo);
    return (1);
   } else
    depth--;
  }
  if (c == rbal)
   depth++;
 }
}

canonical_original_code:
static int balance()
{
 struct line *clp;
 int cbo;
 int c; int i; int depth;
 int rbal; int lbal;
 rbal = key.k_chars[key.k_count - 1];
 lbal = rbal;
 for (i = 0; bal[i].right != '\0'; i++)
  if (bal[i].right == rbal) {
   lbal = bal[i].left;
   break;
  }
 clp = curwp->w_dotp;
 cbo = curwp->w_doto - 1;
 depth = 0;
 for (;;) {
  if (cbo == 0) {
   clp = ((clp)->l_bp);
   if (clp == curbp->b_headp)
    return (0);
   cbo = ((clp)->l_used) + 1;
  }
  if (--cbo == ((clp)->l_used))
   c = '\n';
  else
   c = (((unsigned char) ((clp)->l_text[(cbo)])));
  if (c == lbal) {
   if (depth == 0) {
    displaymatch(clp, cbo);
    return (1);
   } else
    depth--;
  }
  if (c == rbal)
   depth++;
 }
}

variable_types: i int

variable_types: depth int

variable_types: rbal int

variable_types: lbal int