decompiled_code:
__int64 re_forwsrch()
{
__int64 *v0; // rbx
__int64 result; // rax
int v2; // ebp
__int64 v3; // rax

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

canonical_decompiled_code:
__int64 func1()
{
__int64 *v0; // rbx
__int64 result; // rax
int v2; // ebp
__int64 v3; // rax

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

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

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

variable_types: tbo int

variable_types: tdotline int


repo: scott-parker/mg-openbsd

decompiled_code:
__int64 __fastcall re_backsrch()
{
regmatch_t v0; // rbp
__int64 v1; // rbx
int v2; // er13
regoff_t v3; // er12
__int64 v5; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2()
{
regmatch_t v0; // rbp
__int64 v1; // rbx
int v2; // er13
regoff_t v3; // er12
__int64 v5; // rax

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

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

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

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

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

return_type: int


countmatches

decompiled_code:
__int64 __fastcall countmatches(int a1)
{
__int64 *v1; // rbx
unsigned int v2; // er12
int v3; // eax

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

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 *v1; // rbx
unsigned int v2; // er12
int v3; // eax

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

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

variable_types: cond int

variable_types: error int

variable_types: count int

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


decompiled_code:
__int64 __fastcall re_doreplace(unsigned int a1, char *a2)
{
__int64 result; // rax
int v4; // er13
unsigned int v5; // ebp
int v6; // edx
char v7; // cl
char v8; // cl
char v9; // r12
regoff_t v10; // esi
int v11; // eax
int v12; // er14
__int64 v13; // [rsp+0h] [rbp-148h]
char dest[312]; // [rsp+10h] [rbp-138h] BYREF

v13 = *(_QWORD *)(curwp + 32LL);
result = 0LL;
v4 = 0;
v5 = 1;
v6 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
if ( !v5 )
{
dest[v6] = 0;
return lreplace(a1, dest);
}
if ( (_DWORD)result != 1 )
break;
v7 = *a2;
if ( (unsigned __int8)(*a2 - 48) > 9u )
{
if ( v7 )
{
dest[v6++] = v7;
if ( v6 > 255 )
return 0LL;
++a2;
v5 = 1;
result = 0LL;
}
else
{
v5 = 0;
}
}
else
{
v4 = v7 - 48;
++a2;
v5 = 1;
result = 2LL;
}
}
if ( (_DWORD)result == 2 )
break;
v8 = *a2;
if ( *a2 == 92 )
{
++a2;
result = v5;
}
else if ( v8 )
{
dest[v6++] = v8;
if ( v6 > 255 )
return result;
++a2;
}
else
{
v5 = 0;
}
}
v9 = *a2;
if ( (unsigned __int8)(*a2 - 48) > 9u )
break;
v4 = v9 + 10 * v4 - 48;
++a2;
}
if ( v4 > 9 )
return 0LL;
v10 = regex_match[v4].rm_so;
v11 = regex_match[v4].rm_eo - v10;
v12 = v11 + v6;
if ( v11 + v6 > 255 )
return 0LL;
memmove(&dest[v6], (const void *)(*(_QWORD *)(v13 + 24) + v10), v11);
if ( !v9 )
break;
if ( v9 != 92 )
goto LABEL_23;
++a2;
result = v5;
v6 = v12;
}
v5 = 0;
LABEL_23:
dest[v12] = v9;
v6 = v12 + 1;
if ( v12 + 1 > 255 )
return 0LL;
++a2;
result = 0LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, char *a2)
{
__int64 result; // rax
int v4; // er13
unsigned int v5; // ebp
int v6; // edx
char v7; // cl
char v8; // cl
char v9; // r12
regoff_t v10; // esi
int v11; // eax
int v12; // er14
__int64 v13; // [rsp+0h] [rbp-148h]
char dest[312]; // [rsp+10h] [rbp-138h] BYREF

v13 = *(_QWORD *)(curwp + 32LL);
result = 0LL;
v4 = 0;
v5 = 1;
v6 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
if ( !v5 )
{
dest[v6] = 0;
return lreplace(a1, dest);
}
if ( (_DWORD)result != 1 )
break;
v7 = *a2;
if ( (unsigned __int8)(*a2 - 48) > 9u )
{
if ( v7 )
{
dest[v6++] = v7;
if ( v6 > 255 )
return 0LL;
++a2;
v5 = 1;
result = 0LL;
}
else
{
v5 = 0;
}
}
else
{
v4 = v7 - 48;
++a2;
v5 = 1;
result = 2LL;
}
}
if ( (_DWORD)result == 2 )
break;
v8 = *a2;
if ( *a2 == 92 )
{
++a2;
result = v5;
}
else if ( v8 )
{
dest[v6++] = v8;
if ( v6 > 255 )
return result;
++a2;
}
else
{
v5 = 0;
}
}
v9 = *a2;
if ( (unsigned __int8)(*a2 - 48) > 9u )
break;
v4 = v9 + 10 * v4 - 48;
++a2;
}
if ( v4 > 9 )
return 0LL;
v10 = regex_match[v4].rm_so;
v11 = regex_match[v4].rm_eo - v10;
v12 = v11 + v6;
if ( v11 + v6 > 255 )
return 0LL;
memmove(&dest[v6], (const void *)(*(_QWORD *)(v13 + 24) + v10), v11);
if ( !v9 )
break;
if ( v9 != 92 )
goto LABEL_23;
++a2;
result = v5;
v6 = v12;
}
v5 = 0;
LABEL_23:
dest[v12] = v9;
v6 = v12 + 1;
if ( v12 + 1 > 255 )
return 0LL;
++a2;
result = 0LL;
}
}

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

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

variable_types: plen int

variable_types:
st
char *

variable_types: j int

variable_types: k int

variable_types: s int

variable_types: more int

variable_types: num int

variable_types: state int

variable_types:
repstr
char [256]


killmatches

decompiled_code:
__int64 __fastcall killmatches(int a1)
{
__int64 *v1; // rbx
int v2; // er12
__int64 v3; // rax
__int64 result; // rax
int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
__int64 *v1; // rbx
int v2; // er12
__int64 v3; // rax
__int64 result; // rax
int v5; // eax

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

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

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


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

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

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

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

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

variable_types: f int

variable_types: n int


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

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

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

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

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


decompiled_code:
__int64 re_searchagain()
{
unsigned int v0; // ebx

if ( re_srch_lastdir == -3 )
{
dobeep();
ewprintf("No last search");
return 0;
}
if ( re_srch_lastdir == -1 )
{
v0 = re_forwsrch();
if ( v0 )
return 1;
LABEL_8:
dobeep();
ewprintf("Search failed: \"%s\"", &re_pat);
return v0;
}
v0 = 1;
if ( re_srch_lastdir == -2 )
{
v0 = re_backsrch();
if ( v0 )
return 1;
goto LABEL_8;
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // ebx

if ( re_srch_lastdir == -3 )
{
dobeep();
ewprintf("No last search");
return 0;
}
if ( re_srch_lastdir == -1 )
{
v0 = func1();
if ( v0 )
return 1;
LABEL_8:
dobeep();
ewprintf("Search failed: \"%s\"", &re_pat);
return v0;
}
v0 = 1;
if ( re_srch_lastdir == -2 )
{
v0 = func2();
if ( v0 )
return 1;
goto LABEL_8;
}
return v0;
}

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


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

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

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

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

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

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

variable_types: rcnt int

variable_types:
news
char [80]


setcasefold

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

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

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


delmatchlines

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

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

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

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

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


delnonmatchlines

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

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

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

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

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


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

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


ttraw

decompiled_code:
__int64 ttraw()
{
tcflag_t v0; // eax
__int64 result; // rax

if ( tcgetattr(0, &oldtty) < 0 )
{
dobeep();
ewprintf("ttopen can't get terminal attributes");
result = 0LL;
}
else
{
v0 = oldtty.c_iflag;
*(_QWORD *)&newtty.c_iflag = *(_QWORD *)&oldtty.c_iflag;
*(_QWORD *)&newtty.c_cflag = *(_QWORD *)&oldtty.c_cflag;
*(__m128i *)&newtty.c_line = _mm_load_si128((const __m128i *)&oldtty.c_line);
*(__m128i *)&newtty.c_cc[15] = _mm_load_si128((const __m128i *)&oldtty.c_cc[15]);
*(_QWORD *)&newtty.c_cc[31] = *(_QWORD *)&oldtty.c_cc[31];
newtty.c_ospeed = oldtty.c_ospeed;
newtty.c_cc[6] = 1;
newtty.c_cc[5] = 0;
newtty.c_oflag &= 0xFFFFFFFE;
newtty.c_lflag &= 0xFFFF7FB4;
newtty.c_iflag = v0 & 0xFFFFFA15 | 1;
newtty.c_cflag = newtty.c_cflag & 0xFFFFFECF | 0x30;
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()
{
tcflag_t v0; // eax
__int64 result; // rax

if ( tcgetattr(0, &oldtty) < 0 )
{
dobeep();
ewprintf("ttopen can't get terminal attributes");
result = 0LL;
}
else
{
v0 = oldtty.c_iflag;
*(_QWORD *)&newtty.c_iflag = *(_QWORD *)&oldtty.c_iflag;
*(_QWORD *)&newtty.c_cflag = *(_QWORD *)&oldtty.c_cflag;
*(__m128i *)&newtty.c_line = _mm_load_si128((const __m128i *)&oldtty.c_line);
*(__m128i *)&newtty.c_cc[15] = _mm_load_si128((const __m128i *)&oldtty.c_cc[15]);
*(_QWORD *)&newtty.c_cc[31] = *(_QWORD *)&oldtty.c_cc[31];
newtty.c_ospeed = oldtty.c_ospeed;
newtty.c_cc[6] = 1;
newtty.c_cc[5] = 0;
newtty.c_oflag &= 0xFFFFFFFE;
newtty.c_lflag &= 0xFFFF7FB4;
newtty.c_iflag = v0 & 0xFFFFFA15 | 1;
newtty.c_cflag = newtty.c_cflag & 0xFFFFFECF | 0x30;
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:
void __fastcall panic(char *s)
{
if ( !panicking_0 )
{
panicking_0 = 1;
ttclose(s);
fwrite("panic: ", 1uLL, 7uLL, stderr);
fputs(s, stderr);
fputc(10, stderr);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func2(char *s)
{
if ( !panicking_0 )
{
panicking_0 = 1;
func7(s);
fwrite("panic: ", 1uLL, 7uLL, stderr);
fputs(s, stderr);
fputc(10, stderr);
exit(1);
}
}

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:
void ttopen()
{
if ( !isatty(0) || !isatty(1) )
panic("standard input and output must be a terminal");
if ( !(unsigned int)ttraw() )
panic("aborting due to terminal initialize failure");
}

canonical_decompiled_code:
void func3()
{
if ( !isatty(0) || !isatty(1) )
func2("standard input and output must be a terminal");
if ( !(unsigned int)func0() )
func2("aborting due to terminal initialize failure");
}

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()
{
char *v0; // rbp
size_t v1; // rbx
int v2; // eax
ssize_t v3; // rax
ssize_t v4; // rbx

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

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

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

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; // edx
__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; // edx
__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

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

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

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

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

variable_types: c int


ttclose

decompiled_code:
void ttclose()
{
if ( ttstarted )
{
if ( !(unsigned int)ttcooked() )
panic((char *)&byte_770);
ttstarted = 0;
}
}

canonical_decompiled_code:
void func7()
{
if ( ttstarted )
{
if ( !(unsigned int)func5() )
func2((char *)&byte_770);
ttstarted = 0;
}
}

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()
{
int v0; // eax
ssize_t v1; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

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

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

do
{
while ( 1 )
{
v1 = read(0, buf, 1uLL);
if ( v1 != -1 )
break;
v0 = *_errno_location();
if ( v0 == 4 )
{
if ( winch_flag )
{
redraw(0LL, 0LL);
winch_flag = 0;
}
}
else if ( v0 == 5 )
{
func2("lost stdin");
}
}
}
while ( v1 != 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; // ebx

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

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

v0 = macrodef;
if ( macrodef != 1 )
return 0;
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; // ebp
_QWORD *v1; // rbx
void *v2; // rdi
_QWORD *v3; // rbx

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

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebp
_QWORD *v1; // rbx
void *v2; // rdi
_QWORD *v3; // rbx

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

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; // er12
int v3; // er13
int v5; // ebx
__int64 v6; // rsi
__int64 v7; // rdi
__int64 (__fastcall *v8)(__int64, __int64); // rax
unsigned int v9; // eax

v2 = macrodef;
if ( macrodef )
goto LABEL_4;
v3 = a2;
if ( macrocount <= 255 )
{
if ( !macrocount )
return 1;
LABEL_7:
inmacro = 1;
if ( a2 > 0 )
{
do
{
maclcur = *(_QWORD *)maclhead;
if ( macrocount > 1 )
{
v7 = v2;
v5 = v2;
v6 = 1LL;
do
{
v8 = (__int64 (__fastcall *)(__int64, __int64))macro[v5];
if ( (char *)v8 == (char *)&universal_argument )
{
v6 = LODWORD(macro[++v5]);
v7 = 7LL;
}
else
{
v9 = v8(v7, v6);
v6 = v9;
if ( v9 != 1 )
{
inmacro = 0;
return v2;
}
lastflag = thisflag;
thisflag = 0;
v7 = v2;
}
++v5;
}
while ( macrocount - 1 > v5 );
}
--v3;
}
while ( v3 );
}
inmacro = 0;
return 1;
}
if ( !macro[255] )
goto LABEL_7;
LABEL_4:
dobeep();
ewprintf("Macro too long. Aborting.");
return 0;
}

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

v2 = macrodef;
if ( macrodef )
goto LABEL_4;
v3 = a2;
if ( macrocount <= 255 )
{
if ( !macrocount )
return 1;
LABEL_7:
inmacro = 1;
if ( a2 > 0 )
{
do
{
maclcur = *(_QWORD *)maclhead;
if ( macrocount > 1 )
{
v7 = v2;
v5 = v2;
v6 = 1LL;
do
{
v8 = (__int64 (__fastcall *)(__int64, __int64))macro[v5];
if ( (char *)v8 == (char *)&universal_argument )
{
v6 = LODWORD(macro[++v5]);
v7 = 7LL;
}
else
{
v9 = v8(v7, v6);
v6 = v9;
if ( v9 != 1 )
{
inmacro = 0;
return v2;
}
lastflag = thisflag;
thisflag = 0;
v7 = v2;
}
++v5;
}
while ( macrocount - 1 > v5 );
}
--v3;
}
while ( v3 );
}
inmacro = 0;
return 1;
}
if ( !macro[255] )
goto LABEL_7;
LABEL_4:
dobeep();
ewprintf("Macro too long. Aborting.");
return 0;
}

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)
{
__int64 result; // rax
unsigned int i; // ebp
void *v6; // rax
void *v7; // rbx
char v8[16]; // [rsp+0h] [rbp-98h] BYREF
char v9[88]; // [rsp+10h] [rbp-88h] BYREF
__int64 v10[6]; // [rsp+68h] [rbp-30h] BYREF

result = addlinef(a1, &unk_689, &unk_688);
if ( (_DWORD)result )
{
for ( i = 0; i != 256; ++i )
{
v6 = (void *)doscan(a2, i, v10);
v7 = v6;
if ( v6 != &selfinsert && v6 != &rescan )
{
getkeyname(v9, 80LL, i);
snprintf(v8, 0x10uLL, "%s%s ", a3, v9);
if ( v7 )
{
function_name(v7);
result = addlinef(a1, "%-16s%s", v8);
if ( !(_DWORD)result )
return result;
}
else
{
result = showall(a1, v10[0], v8);
if ( !(_DWORD)result )
return result;
}
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, const char *a3)
{
__int64 result; // rax
unsigned int i; // ebp
void *v6; // rax
void *v7; // rbx
char v8[16]; // [rsp+0h] [rbp-98h] BYREF
char v9[88]; // [rsp+10h] [rbp-88h] BYREF
__int64 v10[6]; // [rsp+68h] [rbp-30h] BYREF

result = addlinef(a1, &unk_689, &unk_688);
if ( (_DWORD)result )
{
for ( i = 0; i != 256; ++i )
{
v6 = (void *)doscan(a2, i, v10);
v7 = v6;
if ( v6 != &selfinsert && v6 != &rescan )
{
getkeyname(v9, 80LL, i);
snprintf(v8, 0x10uLL, "%s%s ", a3, v9);
if ( v7 )
{
function_name(v7);
result = addlinef(a1, "%-16s%s", v8);
if ( !(_DWORD)result )
return result;
}
else
{
result = func0(a1, v10[0], v8);
if ( !(_DWORD)result )
return result;
}
}
}
result = 1LL;
}
return result;
}

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; // ebx
unsigned int v7; // er15
__int64 v9; // rax
char v10[16]; // [rsp+0h] [rbp-68h] BYREF
char v11[24]; // [rsp+10h] [rbp-58h] BYREF
__int64 v12[8]; // [rsp+28h] [rbp-40h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, char *a3, size_t a4)
{
unsigned int i; // ebx
unsigned int v7; // er15
__int64 v9; // rax
char v10[16]; // [rsp+0h] [rbp-68h] BYREF
char v11[24]; // [rsp+10h] [rbp-58h] BYREF
__int64 v12[8]; // [rsp+28h] [rbp-40h] BYREF

for ( i = 0; i != 256; ++i )
{
v9 = doscan(a1, i, v12);
if ( v9 == a2 )
{
getkeyname(a3, a4, i);
return 1;
}
if ( !v9 )
{
v7 = func1(v12[0], a2, v11, 16LL);
if ( v7 == 1 )
{
getkeyname(v10, 16LL, i);
snprintf(a3, a4, "%s %s", v10, v11);
return v7;
}
}
}
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; // rbx
__int64 result; // rax
__int64 v5; // rsi
__int64 (__fastcall *v6)(); // rax

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

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

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

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
char *v2; // rbp
int v3; // er13
__int64 v4; // rbx
void *v5; // rax
unsigned int v6; // ebx
int v7; // eax
_BYTE *v8; // r12
__int16 v9; // ax
__int64 v10; // rsi
char v11[88]; // [rsp+0h] [rbp-88h] BYREF
__int64 v12[6]; // [rsp+58h] [rbp-30h] BYREF

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

canonical_decompiled_code:
__int64 func3()
{
unsigned int v1; // eax
char *v2; // rbp
int v3; // er13
__int64 v4; // rbx
void *v5; // rax
unsigned int v6; // ebx
int v7; // eax
_BYTE *v8; // r12
__int16 v9; // ax
__int64 v10; // rsi
char v11[88]; // [rsp+0h] [rbp-88h] BYREF
__int64 v12[6]; // [rsp+58h] [rbp-30h] BYREF

if ( inmacro )
return 1LL;
v1 = strlcpy(v11, "Describe key briefly: ", 80LL);
if ( v1 >= 0x50 )
v1 = 79;
v2 = &v11[v1];
key = 0;
v3 = *(__int16 *)(curbp + 88LL);
v12[0] = **(_QWORD **)(curbp + 8LL * *(__int16 *)(curbp + 88LL) + 48);
while ( 1 )
{
LABEL_16:
while ( 1 )
{
ewprintf("%s");
*(v2 - 1) = 32;
v6 = getkey(0LL);
v7 = key++;
*((_WORD *)&key + v7 + 2) = v6;
v8 = (_BYTE *)getkeyname(v2, v11 - v2 + 80, (unsigned int)(__int16)v6);
v5 = (void *)doscan(v12[0], v6, v12);
if ( v5 )
break;
v2 = v8 + 1;
*v8 = 45;
v8[1] = 0;
}
if ( v5 != &rescan )
goto LABEL_21;
v9 = *((_WORD *)&key + key + 1);
if ( (*((_BYTE *)&cinfo + (unsigned __int8)v9) & 2) == 0 )
goto LABEL_10;
v5 = (void *)doscan(v12[0], (unsigned int)(v9 + 32), v12);
if ( v5 )
break;
v2 = v8 + 1;
*v8 = 45;
v8[1] = 0;
}
if ( v5 == &rescan )
{
LABEL_10:
while ( --v3 >= 0 )
{
v12[0] = **(_QWORD **)(curbp + 8LL * v3 + 48);
if ( key <= 0 )
{
LABEL_15:
v2 = v8 + 1;
*v8 = 45;
v8[1] = 0;
goto LABEL_16;
}
v4 = 0LL;
while ( 1 )
{
v5 = (void *)doscan(v12[0], (unsigned int)*((__int16 *)&key + v4 + 2), v12);
if ( v5 )
break;
if ( key <= (int)++v4 )
goto LABEL_15;
}
if ( key - 1 == (_DWORD)v4 && v5 != &rescan )
goto LABEL_21;
}
goto LABEL_25;
}
LABEL_21:
if ( v5 == &selfinsert || v5 == &rescan )
{
LABEL_25:
ewprintf("%k is not bound to any function");
return 1LL;
}
v10 = function_name(v5);
if ( v10 )
ewprintf("%k runs the command %s", v10);
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; // rbx
int v1; // edx
__int64 result; // rax
int v3; // ebp

v0 = bfind("*help*", 1LL);
v1 = bclear(v0);
result = 0LL;
if ( v1 == 1 )
{
*(_BYTE *)(v0 + 91) |= 0x10u;
v3 = *(__int16 *)(curbp + 88LL);
if ( v3 <= 0 )
{
LABEL_7:
result = addlinef(v0, "%s", "Global bindings:");
if ( (_DWORD)result )
{
result = showall(v0, fundamental_mode, (const char *)&unk_688);
if ( (_DWORD)result )
result = popbuftop(v0, 0LL);
}
}
else
{
while ( 1 )
{
result = addlinef(
v0,
"Local keybindings for mode %s:",
*(const char **)(*(_QWORD *)(curbp + 8LL * v3 + 48) + 8LL));
if ( !(_DWORD)result )
break;
result = showall(v0, **(_QWORD **)(curbp + 8LL * v3 + 48), (const char *)&unk_688);
if ( !(_DWORD)result )
break;
result = addlinef(v0, "%s", (const char *)&unk_688);
if ( !(_DWORD)result )
break;
if ( !--v3 )
goto LABEL_7;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
int v1; // edx
__int64 result; // rax
int v3; // ebp

v0 = bfind("*help*", 1LL);
v1 = bclear(v0);
result = 0LL;
if ( v1 == 1 )
{
*(_BYTE *)(v0 + 91) |= 0x10u;
v3 = *(__int16 *)(curbp + 88LL);
if ( v3 <= 0 )
{
LABEL_7:
result = addlinef(v0, "%s", "Global bindings:");
if ( (_DWORD)result )
{
result = func0(v0, fundamental_mode, (const char *)&unk_688);
if ( (_DWORD)result )
result = popbuftop(v0, 0LL);
}
}
else
{
while ( 1 )
{
result = addlinef(
v0,
"Local keybindings for mode %s:",
*(const char **)(*(_QWORD *)(curbp + 8LL * v3 + 48) + 8LL));
if ( !(_DWORD)result )
break;
result = func0(v0, **(_QWORD **)(curbp + 8LL * v3 + 48), (const char *)&unk_688);
if ( !(_DWORD)result )
break;
result = addlinef(v0, "%s", (const char *)&unk_688);
if ( !(_DWORD)result )
break;
if ( !--v3 )
goto LABEL_7;
}
}
}
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; // r12
unsigned int v1; // ebp
__int64 v3; // rax
__int64 v4; // r13
_QWORD *v5; // rbx
const char *v6; // rbp
__int64 v7; // rax
char v8[32]; // [rsp+0h] [rbp-68h] BYREF
char needle[72]; // [rsp+20h] [rbp-48h] BYREF

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

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // r12
unsigned int v1; // ebp
__int64 v3; // rax
__int64 v4; // r13
_QWORD *v5; // rbx
const char *v6; // rbp
__int64 v7; // rax
char v8[32]; // [rsp+0h] [rbp-68h] BYREF
char needle[72]; // [rsp+20h] [rbp-48h] BYREF

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

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)
{
_BOOL8 result; // rax

if ( a1 == 40 )
return a2 == 41;
if ( a1 <= 40 )
{
if ( a1 == 34 )
{
result = a2 == 34;
}
else if ( a1 == 39 )
{
result = a2 == 39;
}
else
{
result = 0LL;
}
}
else if ( a1 == 91 )
{
result = a2 == 93;
}
else if ( a1 == 123 )
{
result = a2 == 125;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2)
{
_BOOL8 result; // rax

if ( a1 == 40 )
return a2 == 41;
if ( a1 <= 40 )
{
if ( a1 == 34 )
{
result = a2 == 34;
}
else if ( a1 == 39 )
{
result = a2 == 39;
}
else
{
result = 0LL;
}
}
else if ( a1 == 91 )
{
result = a2 == 93;
}
else if ( a1 == 123 )
{
result = a2 == 125;
}
else
{
result = 0LL;
}
return result;
}

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

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

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 *v3; // r8
__int64 v4; // rax
unsigned int v5; // edx
int v6; // esi

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
const unsigned __int16 *v3; // r8
__int64 v4; // rax
unsigned int v5; // edx
int v6; // esi

if ( a2 <= 0 )
return 0LL;
v3 = *_ctype_b_loc();
v4 = 0LL;
v5 = 0;
v6 = a2 - 1;
do
{
if ( (v3[*(unsigned __int8 *)(*(_QWORD *)(a1 + 24) + v4)] & 0x2000) == 0 )
break;
if ( v6 == (_DWORD)v4 )
v5 = 1;
++v4;
}
while ( v4 != a2 );
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; // rdi
unsigned __int8 *v4; // rax
__int64 v5; // r8
int v6; // ecx
unsigned int v7; // er9
int v8; // edx
int v9; // esi

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

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

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

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


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; // ebx
__int64 v3; // rax
int v4; // ebx
int v5; // ebx
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rax
int v4; // ebx
int v5; // ebx
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = 0;
if ( a2 >= 0 )
{
undo_boundary_enable(8LL, 0LL);
deltrailwhite(8LL, 1LL);
v3 = func4(*(_QWORD *)(curwp + 32LL));
v4 = func6(v3, v8);
delleadwhite(8LL, 1LL);
func6(*(_QWORD *)(curwp + 32LL), &v7);
v5 = v7 + v4;
if ( v5 < 0 )
v2 = indent(4LL, 0LL);
else
v2 = indent(4LL, (unsigned int)v5);
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)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 )
{
result = selfinsert(8LL);
if ( (_DWORD)result )
result = cc_indent(8LL, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 )
{
result = selfinsert(8LL);
if ( (_DWORD)result )
result = func7(8LL, a2);
}
return result;
}

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

result = 0LL;
if ( a2 >= 0 )
{
result = showmatch(8LL, 1LL);
if ( (_DWORD)result )
result = cc_indent(8LL, a2);
}
return result;
}

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

result = 0LL;
if ( a2 >= 0 )
{
result = showmatch(8LL, 1LL);
if ( (_DWORD)result )
result = func7(8LL, a2);
}
return result;
}

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; // er12
__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; // er12
__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)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 )
{
result = newline(8LL, 1LL);
if ( (_DWORD)result )
result = cc_indent(8LL, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 )
{
result = newline(8LL, 1LL);
if ( (_DWORD)result )
result = func7(8LL, a2);
}
return result;
}

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

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

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 func13()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

pthread_mutex_lock(&arc4random_mtx);
func11(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 func14(void *dest, unsigned __int64 a2)
{
pthread_mutex_lock(&arc4random_mtx);
func12(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 = ttbeep();
if ( dovisiblebell )
{
sgarbf = 1;
update(0LL);
result = usleep(0xC350u);
}
return result;
}

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

if ( doaudiblebell )
result = ttbeep();
if ( dovisiblebell )
{
sgarbf = 1;
update(0LL);
result = usleep(0xC350u);
}
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)
{
_BOOL4 v2; // eax

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

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

if ( (a1 & 7) != 0 )
v2 = a2 > 0;
else
v2 = doaudiblebell == 0;
doaudiblebell = v2;
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)
{
_BOOL4 v2; // eax

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

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

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

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