decompiled_code:
__int64 __fastcall pdf_find(_BYTE *a1, int a2, int a3, int a4)
{
int v5; // eax
int v6; // er15
__int64 v7; // r12
int v8; // ebx
int v9; // eax
char *v10; // rax
int v13; // [rsp+10h] [rbp-48h] BYREF
int v14; // [rsp+14h] [rbp-44h]
int v15; // [rsp+18h] [rbp-40h]
int v16[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v5 = pdf_xref(a1, a2);
if ( v5 >= 0 )
{
v6 = v5;
v7 = v5;
if ( a2 > v5 )
{
while ( (unsigned int)_isoc99_sscanf(&a1[v7], "%d %d", &v13) == 2 )
{
v8 = 0;
if ( v14 > 0 )
{
do
{
v9 = nextline((__int64)a1, a2, v6);
v6 = v9;
if ( v9 < 0 )
return 0xFFFFFFFFLL;
v7 = v9;
if ( (unsigned int)_isoc99_sscanf(&a1[v9], "%d %d", v16) != 2 )
return 0xFFFFFFFFLL;
if ( v8 + v13 == a3 && v15 == a4 )
{
if ( v16[0] < a2 && v16[0] >= 0 )
{
v10 = strstr(&a1[v16[0]], "obj");
if ( v10 )
return (_DWORD)v10 - (_DWORD)a1 + 3 + (unsigned int)pdf_ws((__int64)a1, a2, (int)v10 - (int)a1 + 3);
}
return 0xFFFFFFFFLL;
}
}
while ( v14 > ++v8 );
}
if ( a2 <= v6 )
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1, int a2, int a3, int a4)
{
int v5; // eax
int v6; // er15
__int64 v7; // r12
int v8; // ebx
int v9; // eax
char *v10; // rax
int v13; // [rsp+10h] [rbp-48h] BYREF
int v14; // [rsp+14h] [rbp-44h]
int v15; // [rsp+18h] [rbp-40h]
int v16[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v5 = func3(a1, a2);
if ( v5 >= 0 )
{
v6 = v5;
v7 = v5;
if ( a2 > v5 )
{
while ( (unsigned int)_isoc99_sscanf(&a1[v7], "%d %d", &v13) == 2 )
{
v8 = 0;
if ( v14 > 0 )
{
do
{
v9 = func1((__int64)a1, a2, v6);
v6 = v9;
if ( v9 < 0 )
return 0xFFFFFFFFLL;
v7 = v9;
if ( (unsigned int)_isoc99_sscanf(&a1[v9], "%d %d", v16) != 2 )
return 0xFFFFFFFFLL;
if ( v8 + v13 == a3 && v15 == a4 )
{
if ( v16[0] < a2 && v16[0] >= 0 )
{
v10 = strstr(&a1[v16[0]], "obj");
if ( v10 )
return (_DWORD)v10 - (_DWORD)a1 + 3 + (unsigned int)func4((__int64)a1, a2, (int)v10 - (int)a1 + 3);
}
return 0xFFFFFFFFLL;
}
}
while ( v14 > ++v8 );
}
if ( a2 <= v6 )
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}

original_code:
int pdf_find(char *pdf, int len, int obj, int rev)
{
 int obj_beg, obj_cnt;
 int cur_rev, cur_pos;
 char *beg;
 int i;
 int pos = pdf_xref(pdf, len);
 if (pos < 0)
  return -1;
 while (pos < len && sscanf(pdf + pos, "%d %d", &obj_beg, &obj_cnt) == 2) {
  for (i = 0; i < obj_cnt; i++) {
   if ((pos = nextline(pdf, len, pos)) < 0)
    return -1;
   if (sscanf(pdf + pos, "%d %d", &cur_pos, &cur_rev) != 2)
    return -1;
   if (obj_beg + i == obj && cur_rev == rev) {
    if (cur_pos < 0 || cur_pos >= len)
     return -1;
    if (!(beg = strstr(pdf + cur_pos, "obj")))
     return -1;
    pos = beg - pdf + 3;
    pos += pdf_ws(pdf, len, pos);
    return pos;
   }
  }
 }
 return -1;
}

canonical_original_code:
int pdf_find(char *pdf, int len, int obj, int rev)
{
 int obj_beg; int obj_cnt;
 int cur_rev; int cur_pos;
 char *beg;
 int i;
 int pos = pdf_xref(pdf, len);
 if (pos < 0)
  return -1;
 while (pos < len && sscanf(pdf + pos, "%d %d", &obj_beg, &obj_cnt) == 2) {
  for (i = 0; i < obj_cnt; i++) {
   if ((pos = nextline(pdf, len, pos)) < 0)
    return -1;
   if (sscanf(pdf + pos, "%d %d", &cur_pos, &cur_rev) != 2)
    return -1;
   if (obj_beg + i == obj && cur_rev == rev) {
    if (cur_pos < 0 || cur_pos >= len)
     return -1;
    if (!(beg = strstr(pdf + cur_pos, "obj")))
     return -1;
    pos = beg - pdf + 3;
    pos += pdf_ws(pdf, len, pos);
    return pos;
   }
  }
 }
 return -1;
}

variable_types: obj int

variable_types: rev int

variable_types:
beg
char *


repo: litcave/neatpost

decompiled_code:
__int64 __fastcall pdf_ref(_BYTE *a1, int a2, int a3)
{
__int64 result; // rax
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)pdf_obj((__int64)a1, a2, a3, &v4, v5) )
result = 0xFFFFFFFFLL;
else
result = pdf_find(a1, a2, v4, v5[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_BYTE *a1, int a2, int a3)
{
__int64 result; // rax
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)func7((__int64)a1, a2, a3, &v4, v5) )
result = 0xFFFFFFFFLL;
else
result = func12(a1, a2, v4, v5[0]);
return result;
}

original_code:
int pdf_ref(char *pdf, int len, int pos)
{
 int obj, rev;
 if (pdf_obj(pdf, len, pos, &obj, &rev))
  return -1;
 return pdf_find(pdf, len, obj, rev);
}

canonical_original_code:
int pdf_ref(char *pdf, int len, int pos)
{
 int obj; int rev;
 if (pdf_obj(pdf, len, pos, &obj, &rev))
  return -1;
 return pdf_find(pdf, len, obj, rev);
}

variable_types:
pdf
char *

variable_types: len int

variable_types: pos int

return_type: int


decompiled_code:
__int64 __fastcall pdf_dval_val(_BYTE *a1, int a2, int a3, const char *a4)
{
int v4; // eax
unsigned int v5; // er12
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = pdf_dval((__int64)a1, a2, a3, a4);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
if ( (unsigned int)pdf_type((__int64)a1, a2, v4) != 114 )
return v5;
pdf_obj((__int64)a1, a2, v5, &v7, v8);
return (unsigned int)pdf_find(a1, a2, v7, v8[0]);
}

canonical_decompiled_code:
__int64 __fastcall func14(_BYTE *a1, int a2, int a3, const char *a4)
{
int v4; // eax
unsigned int v5; // er12
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = func8((__int64)a1, a2, a3, a4);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
if ( (unsigned int)func5((__int64)a1, a2, v4) != 114 )
return v5;
func7((__int64)a1, a2, v5, &v7, v8);
return (unsigned int)func12(a1, a2, v7, v8[0]);
}

original_code:
int pdf_dval_val(char *pdf, int len, int pos, char *key)
{
 int val = pdf_dval(pdf, len, pos, key);
 int val_obj, val_rev;
 if (val < 0)
  return -1;
 if (pdf_type(pdf, len, val) == 'r') {
  pdf_obj(pdf, len, val, &val_obj, &val_rev);
  return pdf_find(pdf, len, val_obj, val_rev);
 }
 return val;
}

canonical_original_code:
int pdf_dval_val(char *pdf, int len, int pos, char *key)
{
 int val = pdf_dval(pdf, len, pos, key);
 int val_obj; int val_rev;
 if (val < 0)
  return -1;
 if (pdf_type(pdf, len, val) == 'r') {
  pdf_obj(pdf, len, val, &val_obj, &val_rev);
  return pdf_find(pdf, len, val_obj, val_rev);
 }
 return val;
}

variable_types:
key
char *

variable_types: val int


decompiled_code:
__int64 __fastcall pdf_dval_obj(_BYTE *a1, int a2, int a3, const char *a4)
{
int v4; // eax
__int64 result; // rax

v4 = pdf_dval((__int64)a1, a2, a3, a4);
if ( v4 < 0 )
result = 0xFFFFFFFFLL;
else
result = pdf_ref(a1, a2, v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(_BYTE *a1, int a2, int a3, const char *a4)
{
int v4; // eax
__int64 result; // rax

v4 = func8((__int64)a1, a2, a3, a4);
if ( v4 < 0 )
result = 0xFFFFFFFFLL;
else
result = func13(a1, a2, v4);
return result;
}

original_code:
int pdf_dval_obj(char *pdf, int len, int pos, char *key)
{
 int val = pdf_dval(pdf, len, pos, key);
 if (val < 0)
  return -1;
 return pdf_ref(pdf, len, val);
}


decompiled_code:
__int64 dev_close()
{
__int64 *v0; // rbx
__int64 result; // rax

v0 = fn_font;
do
{
if ( *v0 )
result = font_close();
*v0++ = 0LL;
}
while ( v0 != (__int64 *)&fn_name );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 *v0; // rbx
__int64 result; // rax

v0 = fn_font;
do
{
if ( *v0 )
result = font_close();
*v0++ = 0LL;
}
while ( v0 != (__int64 *)&fn_name );
return result;
}

original_code:
void dev_close(void)
{
 int i;
 for (i = 0; i < 1024; i++) {
  if (fn_font[i])
   font_close(fn_font[i]);
  fn_font[i] = ((void *)0);
 }
}

canonical_original_code:
void dev_close()
{
 int i;
 for (i = 0; i < 1024; i++) {
  if (fn_font[i])
   font_close(fn_font[i]);
  fn_font[i] = ((void *)0);
 }
}

variable_types: i int

return_type: void


decompiled_code:
const char *__fastcall clr_str(int a1)
{
if ( !a1 )
return "0";
sprintf(clr_buf_1, "#%02x%02x%02x", BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
return clr_buf_1;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
if ( !a1 )
return "0";
sprintf(clr_buf_1, "#%02x%02x%02x", BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
return clr_buf_1;
}

original_code:
char *clr_str(int c)
{
 static char clr_buf[32];
 if (!c)
  return "0";
 sprintf(clr_buf, "#%02x%02x%02x", (((c) >> 16) & 0xff), (((c) >> 8) & 0xff), ((c) & 0xff));
 return clr_buf;
}

variable_types: c int

return_type: char *


decompiled_code:
__int64 __fastcall clr_get(char *nptr)
{
__int64 v2; // rbx
__int64 v3; // rbx
const char *v4; // rdi
unsigned int v6; // eax
size_t v7; // rax
int v8; // ebx
unsigned int v9; // ebx
int v10; // ebx
unsigned int v11; // ebx

v2 = *nptr;
if ( (_BYTE)v2 == 35 )
{
v7 = strlen(nptr);
if ( v7 == 7 )
{
v10 = clrcomp(nptr + 1, 2);
v11 = ((unsigned int)clrcomp(nptr + 3, 2) << 8) | (v10 << 16);
return v11 | (unsigned int)clrcomp(nptr + 5, 2);
}
if ( v7 == 4 )
{
v8 = clrcomp(nptr + 1, 1);
v9 = ((unsigned int)clrcomp(nptr + 2, 1) << 8) | (v8 << 16);
return v9 | (unsigned int)clrcomp(nptr + 3, 1);
}
}
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
{
v3 = 0LL;
v4 = "black";
goto LABEL_5;
}
v3 = 0LL;
v6 = atoi(nptr);
v4 = "black";
if ( v6 <= 7 )
return (unsigned int)dword_2A8[4 * v6];
LABEL_5:
while ( strcmp(v4, nptr) )
{
if ( ++v3 == 8 )
return 0LL;
v4 = (&colors)[2 * v3];
}
return (unsigned int)dword_2A8[4 * (int)v3];
}

canonical_decompiled_code:
__int64 __fastcall func2(char *nptr)
{
__int64 v2; // rbx
__int64 v3; // rbx
const char *v4; // rdi
unsigned int v6; // eax
size_t v7; // rax
int v8; // ebx
unsigned int v9; // ebx
int v10; // ebx
unsigned int v11; // ebx

v2 = *nptr;
if ( (_BYTE)v2 == 35 )
{
v7 = strlen(nptr);
if ( v7 == 7 )
{
v10 = func0(nptr + 1, 2);
v11 = ((unsigned int)func0(nptr + 3, 2) << 8) | (v10 << 16);
return v11 | (unsigned int)func0(nptr + 5, 2);
}
if ( v7 == 4 )
{
v8 = func0(nptr + 1, 1);
v9 = ((unsigned int)func0(nptr + 2, 1) << 8) | (v8 << 16);
return v9 | (unsigned int)func0(nptr + 3, 1);
}
}
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
{
v3 = 0LL;
v4 = "black";
goto LABEL_5;
}
v3 = 0LL;
v6 = atoi(nptr);
v4 = "black";
if ( v6 <= 7 )
return (unsigned int)dword_2A8[4 * v6];
LABEL_5:
while ( strcmp(v4, nptr) )
{
if ( ++v3 == 8 )
return 0LL;
v4 = (&colors)[2 * v3];
}
return (unsigned int)dword_2A8[4 * (int)v3];
}

original_code:
int clr_get(char *s)
{
 int i;
 if (s[0] == '#' && strlen(s) == 7)
  return (((clrcomp(s + 1, 2)) << 16) | ((clrcomp(s + 3, 2)) << 8) | (clrcomp(s + 5, 2)));
 if (s[0] == '#' && strlen(s) == 4)
  return (((clrcomp(s + 1, 1)) << 16) | ((clrcomp(s + 2, 1)) << 8) | (clrcomp(s + 3, 1)));
 if (((*__ctype_b_loc ())[(int) ((s[0]))] & (unsigned short int) _ISdigit) && atoi(s) >= 0 && atoi(s) < (sizeof(colors) / sizeof((colors)[0])))
  return colors[atoi(s)].value;
 for (i = 0; i < (sizeof(colors) / sizeof((colors)[0])); i++)
  if (!strcmp(colors[i].name, s))
   return colors[i].value;
 return 0;
}

canonical_original_code:
int clr_get(char *s)
{
 int i;
 if (s[0] == '#' && strlen(s) == 7)
  return (((clrcomp(s + 1, 2)) << 16) | ((clrcomp(s + 3, 2)) << 8) | (clrcomp(s + 5, 2)));
 if (s[0] == '#' && strlen(s) == 4)
  return (((clrcomp(s + 1, 1)) << 16) | ((clrcomp(s + 2, 1)) << 8) | (clrcomp(s + 3, 1)));
 if (((*__ctype_b_loc ())[(int) ((s[0]))] & (unsigned short) _ISdigit) && atoi(s) >= 0 && atoi(s) < (sizeof(colors) / sizeof((colors)[0])))
  return colors[atoi(s)].value;
 for (i = 0; i < (sizeof(colors) / sizeof((colors)[0])); i++)
  if (!strcmp(colors[i].name, s))
   return colors[i].value;
 return 0;
}

variable_types:
s
char *


repo: litcave/neatroff

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

result = *(unsigned __int8 *)sstr_s;
if ( !(_BYTE)result )
return 0xFFFFFFFFLL;
++sstr_s;
return result;
}

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

result = *(unsigned __int8 *)sstr_s;
if ( !(_BYTE)result )
return 0xFFFFFFFFLL;
++sstr_s;
return result;
}

original_code:
int sstr_next(void)
{
 return *sstr_s ? (unsigned char) *sstr_s++ : -1;
}

canonical_original_code:
int sstr_next()
{
 return *sstr_s ? (unsigned char) *sstr_s++ : -1;
}


decompiled_code:
void sstr_back()
{
--sstr_s;
}

canonical_decompiled_code:
void func1()
{
--sstr_s;
}

original_code:
void sstr_back(int c)
{
 sstr_s--;
}

canonical_original_code:
void sstr_back(int c)
{
 sstr_s--;
}


decompiled_code:
__int64 __fastcall utf8len(int a1)
{
__int64 result; // rax

if ( (~(_BYTE)a1 & 0xC0) != 0 )
return a1 > 0;
result = 2LL;
if ( (a1 & 0x20) != 0 )
{
result = 3LL;
if ( (a1 & 0x10) != 0 )
result = (a1 & 8) == 0 ? 4 : 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 result; // rax

if ( (~(_BYTE)a1 & 0xC0) != 0 )
return a1 > 0;
result = 2LL;
if ( (a1 & 0x20) != 0 )
{
result = 3LL;
if ( (a1 & 0x10) != 0 )
result = (a1 & 8) == 0 ? 4 : 1;
}
return result;
}

original_code:
int utf8len(int c)
{
 if (~c & 0xc0)
  return c > 0;
 if (~c & 0x20)
  return 2;
 if (~c & 0x10)
  return 3;
 if (~c & 0x08)
  return 4;
 return 1;
}


decompiled_code:
_BOOL8 __fastcall utf8one(unsigned __int8 *a1)
{
int v1; // eax
__int64 v2; // rdx

v1 = utf8len(*a1);
return *(_BYTE *)(v2 + v1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned __int8 *a1)
{
int v1; // eax
__int64 v2; // rdx

v1 = func4(*a1);
return *(_BYTE *)(v2 + v1) == 0;
}

original_code:
int utf8one(char *s)
{
 return !s[utf8len((unsigned char) *s)];
}


decompiled_code:
__int64 __fastcall utf8read(unsigned __int8 **a1, __int64 a2)
{
char v2; // dl
_QWORD *v3; // rcx
int v4; // er8
__int64 v5; // rax
__int64 result; // rax

v4 = utf8len(**a1);
v5 = 0LL;
if ( v4 > 0 )
{
while ( 1 )
{
*(_BYTE *)(a2 + v5++) = v2;
if ( v5 == v4 )
break;
v2 = *(_BYTE *)(*v3 + v5);
}
}
*(_BYTE *)(a2 + v4) = 0;
result = (unsigned int)v4;
*v3 += v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 **a1, __int64 a2)
{
char v2; // dl
_QWORD *v3; // rcx
int v4; // er8
__int64 v5; // rax
__int64 result; // rax

v4 = func4(**a1);
v5 = 0LL;
if ( v4 > 0 )
{
while ( 1 )
{
*(_BYTE *)(a2 + v5++) = v2;
if ( v5 == v4 )
break;
v2 = *(_BYTE *)(*v3 + v5);
}
}
*(_BYTE *)(a2 + v4) = 0;
result = (unsigned int)v4;
*v3 += v4;
return result;
}

original_code:
int utf8read(char **s, char *d)
{
 int l = utf8len((unsigned char) **s);
 int i;
 for (i = 0; i < l; i++)
  d[i] = (*s)[i];
 d[l] = '\0';
 *s += l;
 return l;
}

variable_types:
s
char **

variable_types:
d
char *

variable_types: l int


original_code:
int utf8next(char *s, int (*next)(void))
{
 int c = next();
 int l = utf8len(c);
 int i;
 if (c < 0)
  return 0;
 s[0] = c;
 for (i = 1; i < l; i++)
  s[i] = next();
 s[l] = '\0';
 return l;
}

canonical_original_code:
int utf8next(char *s, int (*next)())
{
 int c = next();
 int l = utf8len(c);
 int i;
 if (c < 0)
  return 0;
 s[0] = c;
 for (i = 1; i < l; i++)
  s[i] = next();
 s[l] = '\0';
 return l;
}

variable_types:
next
int (*)()


unquotednext

decompiled_code:
__int64 __fastcall unquotednext(unsigned int a1, __int64 (*a2)(void), void (__fastcall *a3)(_QWORD))
{
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v9; // ebp
unsigned int v10; // eax
_BYTE v11[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = a1;
v5 = a2();
sbuf_init(v11);
if ( a1 == 115 && ((v5 - 43) & 0xFFFFFFFD) == 0 )
{
v4 = v5;
sbuf_add(v11, v5);
v5 = a2();
}
if ( v5 == 40 )
{
v6 = a2();
sbuf_add(v11, v6);
v7 = a2();
sbuf_add(v11, v7);
}
else if ( !*(_DWORD *)nreg(67LL) && v5 == 91 )
{
while ( 1 )
{
v10 = a2();
if ( v10 == 10 || (int)v10 <= 0 || v10 == 93 )
break;
sbuf_add(v11, v10);
}
}
else
{
sbuf_add(v11, v5);
if ( *(_DWORD *)nreg(67LL) && v5 - 49 <= 2 && v4 == 115 )
{
v9 = a2();
if ( ((*_ctype_b_loc())[v9] & 0x800) != 0 )
sbuf_add(v11, v9);
else
a3(v9);
}
}
return sbuf_out(v11);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 (*a2)(void), void (__fastcall *a3)(_QWORD))
{
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v9; // ebp
unsigned int v10; // eax
_BYTE v11[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = a1;
v5 = a2();
sbuf_init(v11);
if ( a1 == 115 && ((v5 - 43) & 0xFFFFFFFD) == 0 )
{
v4 = v5;
sbuf_add(v11, v5);
v5 = a2();
}
if ( v5 == 40 )
{
v6 = a2();
sbuf_add(v11, v6);
v7 = a2();
sbuf_add(v11, v7);
}
else if ( !*(_DWORD *)nreg(67LL) && v5 == 91 )
{
while ( 1 )
{
v10 = a2();
if ( v10 == 10 || (int)v10 <= 0 || v10 == 93 )
break;
sbuf_add(v11, v10);
}
}
else
{
sbuf_add(v11, v5);
if ( *(_DWORD *)nreg(67LL) && v5 - 49 <= 2 && v4 == 115 )
{
v9 = a2();
if ( ((*_ctype_b_loc())[v9] & 0x800) != 0 )
sbuf_add(v11, v9);
else
a3(v9);
}
}
return sbuf_out(v11);
}

original_code:
char *unquotednext(int cmd, int (*next)(void), void (*back)(int))
{
 int c = next();
 struct sbuf sb;
 sbuf_init(&sb);
 if (cmd == 's' && (c == '-' || c == '+')) {
  cmd = c;
  sbuf_add(&sb, c);
  c = next();
 }
 if (c == '(') {
  sbuf_add(&sb, next());
  sbuf_add(&sb, next());
 } else if (!(*nreg(('C'))) && c == '[') {
  c = next();
  while (c > 0 && c != '\n' && c != ']') {
   sbuf_add(&sb, c);
   c = next();
  }
 } else {
  sbuf_add(&sb, c);
  if ((*nreg(('C'))) && cmd == 's' && c >= '1' && c <= '3') {
   c = next();
   if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
    sbuf_add(&sb, c);
   else
    back(c);
  }
 }
 return sbuf_out(&sb);
}

canonical_original_code:
char *unquotednext(int cmd, int (*next)(), void (*back)(int))
{
 int c = next();
 struct sbuf sb;
 sbuf_init(&sb);
 if (cmd == 's' && (c == '-' || c == '+')) {
  cmd = c;
  sbuf_add(&sb, c);
  c = next();
 }
 if (c == '(') {
  sbuf_add(&sb, next());
  sbuf_add(&sb, next());
 } else if (!(*nreg(('C'))) && c == '[') {
  c = next();
  while (c > 0 && c != '\n' && c != ']') {
   sbuf_add(&sb, c);
   c = next();
  }
 } else {
  sbuf_add(&sb, c);
  if ((*nreg(('C'))) && cmd == 's' && c >= '1' && c <= '3') {
   c = next();
   if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
    sbuf_add(&sb, c);
   else
    back(c);
  }
 }
 return sbuf_out(&sb);
}

variable_types: cmd int

variable_types:
back
void (*)(int)

variable_types:
sb
struct sbuf { char *s; int sz; int n; }


decompiled_code:
int __fastcall charnext_str(char *dest, char *a2)
{
int v2; // er9
char *v3; // r8
int v4; // er9
unsigned int v5; // er10
__int64 v7; // rdx
int result; // eax

v2 = (unsigned __int8)*a2;
if ( c_ec == v2 || v2 == 4 || !a2[1] )
return (unsigned int)strcpy(dest, a2);
if ( utf8one((unsigned __int8 *)a2) )
return (unsigned int)strcpy(v3, a2);
v7 = v5;
if ( !a2[2] && (unsigned int)utf8len(v4) == 1 )
result = sprintf(v3, "%c(%s", v7, a2);
else
result = sprintf(v3, "%cC'%s'", v7, a2);
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *dest, char *a2)
{
int v2; // er9
char *v3; // r8
int v4; // er9
unsigned int v5; // er10
__int64 v7; // rdx
int result; // eax

v2 = (unsigned __int8)*a2;
if ( c_ec == v2 || v2 == 4 || !a2[1] )
return (unsigned int)strcpy(dest, a2);
if ( func5((unsigned __int8 *)a2) )
return (unsigned int)strcpy(v3, a2);
v7 = v5;
if ( !a2[2] && (unsigned int)func4(v4) == 1 )
result = sprintf(v3, "%c(%s", v7, a2);
else
result = sprintf(v3, "%cC'%s'", v7, a2);
return result;
}

original_code:
void charnext_str(char *d, char *c)
{
 int c0 = (unsigned char) c[0];
 if (c0 == c_ec || c0 == 4 || !c[1] || utf8one(c)) {
  strcpy(d, c);
  return;
 }
 if (!c[2] && utf8len(c0) == 1)
  sprintf(d, "%c(%s", c_ec, c);
 else
  sprintf(d, "%cC'%s'", c_ec, c);
}

variable_types:
c
char *


quotednext

decompiled_code:
__int64 quotednext()
{
_BYTE v1[16]; // [rsp+0h] [rbp-88h] BYREF
char s[32]; // [rsp+10h] [rbp-78h] BYREF
char s1[32]; // [rsp+30h] [rbp-58h] BYREF
char dest[56]; // [rsp+50h] [rbp-38h] BYREF

charnext(s);
sbuf_init(v1);
while ( (int)charnext_delim(s1) >= 0 )
{
charnext_str(dest, s1);
sbuf_append(v1, dest);
}
return sbuf_out(v1);
}

canonical_decompiled_code:
__int64 func10()
{
_BYTE v1[16]; // [rsp+0h] [rbp-88h] BYREF
char s[32]; // [rsp+10h] [rbp-78h] BYREF
char s1[32]; // [rsp+30h] [rbp-58h] BYREF
char dest[56]; // [rsp+50h] [rbp-38h] BYREF

func11(s);
sbuf_init(v1);
while ( (int)func12(s1) >= 0 )
{
func9(dest, s1);
sbuf_append(v1, dest);
}
return sbuf_out(v1);
}

original_code:
char *quotednext(int (*next)(void), void (*back)(int))
{
 char delim[32], cs[32];
 struct sbuf sb;
 char d[32];
 charnext(delim, next, back);
 sbuf_init(&sb);
 while (charnext_delim(cs, next, back, delim) >= 0) {
  charnext_str(d, cs);
  sbuf_append(&sb, d);
 }
 return sbuf_out(&sb);
}

canonical_original_code:
char *quotednext(int (*next)(), void (*back)(int))
{
 char delim[32]; char cs[32];
 struct sbuf sb;
 char d[32];
 charnext(delim, next, back);
 sbuf_init(&sb);
 while (charnext_delim(cs, next, back, delim) >= 0) {
  charnext_str(d, cs);
  sbuf_append(&sb, d);
 }
 return sbuf_out(&sb);
}

variable_types:
delim
char [32]

variable_types:
cs
char [32]

variable_types:
d
char [32]


charnext

original_code:
int charnext(char *c, int (*next)(void), void (*back)(int))
{
 int l, n;
 if (!utf8next(c, next))
  return -1;
 if (c[0] == 4) {
  utf8next(c + 1, next);
  return 4;
 }
 if (c[0] == c_ec) {
  utf8next(c + 1, next);
  if (c[1] == '(') {
   l = utf8next(c, next);
   l += utf8next(c + l, next);
   return '(';
  } else if (!(*nreg(('C'))) && c[1] == '[') {
   l = 0;
   n = next();
   while (n >= 0 && n != '\n' && n != ']' && l < 32 - 1) {
    c[l++] = n;
    n = next();
   }
   c[l] = '\0';
   return '[';
  } else if (c[1] == 'C') {
   char *chr = quotednext(next, back);
   snprintf(c, 32, "%s", chr);
   free(chr);
   return 'C';
  }
  return '\\';
 }
 return '\0';
}

canonical_original_code:
int charnext(char *c, int (*next)(), void (*back)(int))
{
 int l; int n;
 if (!utf8next(c, next))
  return -1;
 if (c[0] == 4) {
  utf8next(c + 1, next);
  return 4;
 }
 if (c[0] == c_ec) {
  utf8next(c + 1, next);
  if (c[1] == '(') {
   l = utf8next(c, next);
   l += utf8next(c + l, next);
   return '(';
  } else if (!(*nreg(('C'))) && c[1] == '[') {
   l = 0;
   n = next();
   while (n >= 0 && n != '\n' && n != ']' && l < 32 - 1) {
    c[l++] = n;
    n = next();
   }
   c[l] = '\0';
   return '[';
  } else if (c[1] == 'C') {
   char *chr = quotednext(next, back);
   snprintf(c, 32, "%s", chr);
   free(chr);
   return 'C';
  }
  return '\\';
 }
 return '\0';
}

variable_types: n int

variable_types:
chr
char *


decompiled_code:
__int64 __fastcall charnext_delim(char *s1, __int64 (*a2)(void), __int64 a3, const char *a4)
{
unsigned int v5; // er12

v5 = charnext(s1, a2, a3);
if ( !strcmp(s1, a4) )
v5 = -1;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s1, __int64 (*a2)(void), __int64 a3, const char *a4)
{
unsigned int v5; // er12

v5 = func11(s1, a2, a3);
if ( !strcmp(s1, a4) )
v5 = -1;
return v5;
}

original_code:
int charnext_delim(char *c, int (*next)(void), void (*back)(int), char *delim)
{
 int t = charnext(c, next, back);
 return strcmp(c, delim) ? t : -1;
}

canonical_original_code:
int charnext_delim(char *c, int (*next)(), void (*back)(int), char *delim)
{
 int t = charnext(c, next, back);
 return strcmp(c, delim) ? t : -1;
}

variable_types:
delim
char *

variable_types: t int


escread

decompiled_code:
__int64 __fastcall escread(unsigned __int8 **a1, _QWORD *a2)
{
unsigned int v2; // er12
size_t v4; // rax
unsigned __int8 *v5; // rax
unsigned __int8 v6; // dl
char *v7; // rdx
unsigned __int8 v8; // cl

if ( !**a1 )
return (unsigned int)-1;
*a2 = &buf_0;
utf8read(a1, (__int64)&buf_0);
if ( buf_0 != c_ec )
{
if ( buf_0 == 4 )
utf8read(a1, (__int64)&byte_901);
return 0;
}
utf8read(a1, (__int64)&byte_901);
if ( byte_901 == 40 )
{
v2 = 0;
utf8read(a1, (__int64)&buf_0);
v4 = strlen(&buf_0);
utf8read(a1, (__int64)(&buf_0 + v4));
return v2;
}
v2 = *(_DWORD *)nreg(67LL);
if ( !v2 && byte_901 == 91 )
{
v5 = *a1;
v6 = **a1;
if ( !v6 || v6 == 93 )
{
v7 = &buf_0;
}
else
{
v7 = &buf_0;
do
{
++v7;
*a1 = v5 + 1;
*(v7 - 1) = *v5;
v5 = *a1;
v8 = **a1;
}
while ( v8 && v8 != 93 );
}
*v7 = 0;
if ( **a1 == 93 )
{
++*a1;
return v2;
}
return 0;
}
v2 = byte_901;
if ( !strchr("CDfhmsvXx<>", byte_901) )
return 0;
buf_0 = 0;
if ( strchr("*fgkmns", v2) )
unquotedread_constprop_0((char **)a1);
if ( strchr("bCDhHjlLNoRSvwxXZ?", v2) )
quotedread_constprop_0((char **)a1);
if ( v2 == 67 )
return 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 **a1, _QWORD *a2)
{
unsigned int v2; // er12
size_t v4; // rax
unsigned __int8 *v5; // rax
unsigned __int8 v6; // dl
char *v7; // rdx
unsigned __int8 v8; // cl

if ( !**a1 )
return (unsigned int)-1;
*a2 = &buf_0;
func6(a1, (__int64)&buf_0);
if ( buf_0 != c_ec )
{
if ( buf_0 == 4 )
func6(a1, (__int64)&byte_901);
return 0;
}
func6(a1, (__int64)&byte_901);
if ( byte_901 == 40 )
{
v2 = 0;
func6(a1, (__int64)&buf_0);
v4 = strlen(&buf_0);
func6(a1, (__int64)(&buf_0 + v4));
return v2;
}
v2 = *(_DWORD *)nreg(67LL);
if ( !v2 && byte_901 == 91 )
{
v5 = *a1;
v6 = **a1;
if ( !v6 || v6 == 93 )
{
v7 = &buf_0;
}
else
{
v7 = &buf_0;
do
{
++v7;
*a1 = v5 + 1;
*(v7 - 1) = *v5;
v5 = *a1;
v8 = **a1;
}
while ( v8 && v8 != 93 );
}
*v7 = 0;
if ( **a1 == 93 )
{
++*a1;
return v2;
}
return 0;
}
v2 = byte_901;
if ( !strchr("CDfhmsvXx<>", byte_901) )
return 0;
buf_0 = 0;
if ( strchr("*fgkmns", v2) )
func2((char **)a1);
if ( strchr("bCDhHjlLNoRSvwxXZ?", v2) )
func3((char **)a1);
if ( v2 == 67 )
return 0;
return v2;
}

original_code:
int escread(char **s, char **d)
{
 static char buf[1 << 12];
 char *r;
 if (!**s)
  return -1;
 r = buf;
 *d = buf;
 utf8read(s, r);
 if (r[0] == c_ec) {
  utf8read(s, r + 1);
  if (r[1] == '(') {
   utf8read(s, r);
   utf8read(s, r + strlen(r));
  } else if (!(*nreg(('C'))) && r[1] == '[') {
   while (**s && **s != ']')
    *r++ = *(*s)++;
   *r = '\0';
   if (**s == ']')
    (*s)++;
  } else if (strchr("CDfhmsvXx<>", r[1])) {
   int c = r[1];
   r[0] = '\0';
   if (strchr("*fgkmns", c))
    unquotedread(s, r);
   if (strchr("bCDhHjlLNoRSvwxXZ?", c))
    quotedread(s, r);
   return c == 'C' ? 0 : c;
  }
 } else if (r[0] == 4) {
  utf8read(s, r + 1);
 }
 return 0;
}

canonical_original_code:
int escread(char **s, char **d)
{
 static char buf[-1];
 char *r;
 if (!**s)
  return -1;
 r = buf;
 *d = buf;
 utf8read(s, r);
 if (r[0] == c_ec) {
  utf8read(s, r + 1);
  if (r[1] == '(') {
   utf8read(s, r);
   utf8read(s, r + strlen(r));
  } else if (!(*nreg(('C'))) && r[1] == '[') {
   while (**s && **s != ']')
    *r++ = *(*s)++;
   *r = '\0';
   if (**s == ']')
    (*s)++;
  } else if (strchr("CDfhmsvXx<>", r[1])) {
   int c = r[1];
   r[0] = '\0';
   if (strchr("*fgkmns", c))
    unquotedread(s, r);
   if (strchr("bCDhHjlLNoRSvwxXZ?", c))
    quotedread(s, r);
   return c == 'C' ? 0 : c;
  }
 } else if (r[0] == 4) {
  utf8read(s, r + 1);
 }
 return 0;
}

variable_types:
d
char **

variable_types:
buf
char [-1]

variable_types:
r
char *

variable_types: c int


decompiled_code:
__int64 __fastcall sstr_push(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = sstr_n++;
v2 = sstr_s;
sstr_s = a1;
sstr_bufs[result] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = sstr_n++;
v2 = sstr_s;
sstr_s = a1;
sstr_bufs[result] = v2;
return result;
}

original_code:
void sstr_push(char *s)
{
 sstr_bufs[sstr_n++] = sstr_s;
 sstr_s = s;
}

variable_types:
s
char *


decompiled_code:
__int64 sstr_pop()
{
__int64 v0; // r8

v0 = sstr_s;
sstr_s = sstr_bufs[--sstr_n];
return v0;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 v0; // r8

v0 = sstr_s;
sstr_s = sstr_bufs[--sstr_n];
return v0;
}

original_code:
char *sstr_pop(void)
{
 char *ret = sstr_s;
 sstr_s = sstr_bufs[--sstr_n];
 return ret;
}

canonical_original_code:
char *sstr_pop()
{
 char *ret = sstr_s;
 sstr_s = sstr_bufs[--sstr_n];
 return ret;
}

variable_types:
ret
char *


charread

decompiled_code:
__int64 __fastcall charread(__int64 *a1)
{
char *v2; // r8
char *v3; // rdi
unsigned int v4; // eax
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
unsigned int v8; // er9

sstr_push(*a1);
v3 = v2;
v4 = charnext(v2, sstr_next, (__int64)sstr_back);
*a1 = sstr_pop(v3, sstr_next, v5, v6, v7, v4);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1)
{
char *v2; // r8
char *v3; // rdi
unsigned int v4; // eax
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
unsigned int v8; // er9

func14(*a1);
v3 = v2;
v4 = func11(v2, sstr_next, (__int64)sstr_back);
*a1 = func15(v3, sstr_next, v5, v6, v7, v4);
return v8;
}

original_code:
int charread(char **s, char *c)
{
 int ret;
 sstr_push(*s);
 ret = charnext(c, sstr_next, sstr_back);
 *s = sstr_pop();
 return ret;
}

variable_types:
s
char **

variable_types: ret int


decompiled_code:
__int64 __fastcall charread_delim(__int64 *a1)
{
char *v2; // r8
char *v3; // rdi
const char *v4; // rcx
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
unsigned int v9; // er9

sstr_push(*a1);
v3 = v2;
v5 = charnext_delim(v2, sstr_next, (__int64)sstr_back, v4);
*a1 = sstr_pop(v3, sstr_next, v6, v7, v8, v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 *a1)
{
char *v2; // r8
char *v3; // rdi
const char *v4; // rcx
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
unsigned int v9; // er9

func14(*a1);
v3 = v2;
v5 = func12(v2, sstr_next, (__int64)sstr_back, v4);
*a1 = func15(v3, sstr_next, v6, v7, v8, v5);
return v9;
}

original_code:
int charread_delim(char **s, char *c, char *delim)
{
 int ret;
 sstr_push(*s);
 ret = charnext_delim(c, sstr_next, sstr_back, delim);
 *s = sstr_pop();
 return ret;
}


evaljmp

decompiled_code:
__int64 __fastcall evaljmp(_QWORD *a1, int a2)
{
if ( *(char *)*a1 != a2 )
return 1LL;
++*a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2)
{
if ( *(char *)*a1 != a2 )
return 1LL;
++*a1;
return 0LL;
}

original_code:
static int evaljmp(char **s, int c)
{
 if (**s == c) {
  (*s)++;
  return 0;
 }
 return 1;
}


readunit

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

v2 = a2;
switch ( a1 )
{
case 'P':
result = (unsigned int)((int)(dev_res * a2) / 6);
break;
case 'c':
result = (unsigned int)((int)(50 * dev_res * a2) / 127);
break;
case 'i':
v2 = dev_res * a2;
goto LABEL_3;
case 'm':
result = (unsigned int)((int)(*(_DWORD *)nreg(115LL) * a2 * dev_res) / 72);
break;
case 'n':
result = (unsigned int)((int)(*(_DWORD *)nreg(115LL) * a2 * dev_res) / 144);
break;
case 'p':
result = (unsigned int)((int)(dev_res * a2) / 72);
break;
case 'v':
result = *(_DWORD *)nreg(118LL) * a2;
break;
default:
LABEL_3:
result = v2;
break;
}
return result;
}

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

v2 = a2;
switch ( a1 )
{
case 'P':
result = (unsigned int)((int)(dev_res * a2) / 6);
break;
case 'c':
result = (unsigned int)((int)(50 * dev_res * a2) / 127);
break;
case 'i':
v2 = dev_res * a2;
goto LABEL_3;
case 'm':
result = (unsigned int)((int)(*(_DWORD *)nreg(115LL) * a2 * dev_res) / 72);
break;
case 'n':
result = (unsigned int)((int)(*(_DWORD *)nreg(115LL) * a2 * dev_res) / 144);
break;
case 'p':
result = (unsigned int)((int)(dev_res * a2) / 72);
break;
case 'v':
result = *(_DWORD *)nreg(118LL) * a2;
break;
default:
LABEL_3:
result = v2;
break;
}
return result;
}

original_code:
static int readunit(int c, int n)
{
 switch (c) {
 case 'i':
  return n * (dev_res);
 case 'c':
  return n * (dev_res) * 50 / 127;
 case 'p':
  return n * (dev_res) / 72;
 case 'P':
  return n * (dev_res) / 6;
 case 'v':
  return n * (*nreg(('v')));
 case 'm':
  return n * (*nreg(('s'))) * (dev_res) / 72;
 case 'n':
  return n * (*nreg(('s'))) * (dev_res) / 144;
 case 'u':
  return n;
 }
 return n;
}


nonzero

decompiled_code:
__int64 __fastcall nonzero(unsigned int a1)
{
if ( !a1 )
errdie("neatroff: divide by zero\n");
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
if ( !a1 )
errdie("neatroff: divide by zero\n");
return a1;
}

original_code:
static int nonzero(int n)
{
 if (!n)
  errdie("neatroff: divide by zero\n");
 return n;
}


evalnum

decompiled_code:
__int64 __fastcall evalnum(unsigned __int8 **a1)
{
unsigned int v1; // er13
unsigned __int8 *v2; // r14
int v3; // ebx
const unsigned __int16 *v4; // rcx
int v5; // eax
int v6; // ebp
int v7; // eax

v1 = 0;
v2 = *a1;
v3 = 0;
v4 = *_ctype_b_loc();
LABEL_2:
while ( 1 )
{
v5 = (char)*v2;
if ( (v4[*v2] & 0x800) == 0 && (_BYTE)v5 != 46 )
break;
while ( 1 )
{
++v2;
if ( v3 == 100000 || v3 > 0 && v1 > 0xBEBC200 )
break;
if ( (_BYTE)v5 == 46 )
{
v3 = 1;
goto LABEL_2;
}
v1 = v5 + 10 * v1 - 48;
v5 = (char)*v2;
v3 *= 10;
if ( (v4[*v2] & 0x800) == 0 && (_BYTE)v5 != 46 )
goto LABEL_10;
}
}
LABEL_10:
if ( (_BYTE)v5 && (v6 = (char)v5, strchr("icpPvmnu", (char)v5)) )
++v2;
else
v6 = defunit;
v7 = readunit(v6, v1);
*a1 = v2;
if ( v3 <= 0 )
v3 = 1;
return (unsigned int)(v7 / v3);
}

original_code:
static int evalnum(char **_s)
{
 char *s = *_s;
 int n = 0;
 int mag = 0;
 while (((*__ctype_b_loc ())[(int) (((unsigned char) *s))] & (unsigned short int) _ISdigit) || *s == '.') {
  if (mag == 100000 || (mag > 0 && n > 200000000u)) {
   s++;
   continue;
  }
  if (*s == '.') {
   mag = 1;
   s++;
   continue;
  }
  mag *= 10;
  n = n * 10 + *s++ - '0';
 }
 n = readunit(*s && strchr("icpPvmnu", *s) ? *s++ : defunit, n);
 *_s = s;
 return n / (mag > 0 ? mag : 1);
}

canonical_original_code:
static int evalnum(char **_s)
{
 char *s = *_s;
 int n = 0;
 int mag = 0;
 while (((*__ctype_b_loc ())[(int) (((unsigned char) *s))] & (unsigned short) _ISdigit) || *s == '.') {
  if (mag == 100000 || (mag > 0 && n > 200000000u)) {
   s++;
   continue;
  }
  if (*s == '.') {
   mag = 1;
   s++;
   continue;
  }
  mag *= 10;
  n = n * 10 + *s++ - '0';
 }
 n = readunit(*s && strchr("icpPvmnu", *s) ? *s++ : defunit, n);
 *_s = s;
 return n / (mag > 0 ? mag : 1);
}

variable_types: mag int


evalatom

decompiled_code:
__int64 __fastcall evalatom(unsigned __int8 **a1)
{
int v1; // ebx
unsigned int v2; // er9
int v4; // er9

v1 = 1;
do
{
if ( (unsigned int)evalisnum_isra_0(*a1) )
return (unsigned int)evalnum(a1) * v1;
while ( !(unsigned int)evaljmp(a1, 45) )
{
v1 = -v1;
if ( (unsigned int)evalisnum_isra_0(*a1) )
return (unsigned int)evalnum(a1) * v1;
}
}
while ( !(unsigned int)evaljmp(a1, 43) );
if ( !(unsigned int)evaljmp(a1, 124) )
return (unsigned int)(v1 * (abspos + evalatom()));
if ( !(unsigned int)evaljmp(a1, 40) )
{
evalexpr();
evaljmp(a1, 41);
v2 = v1 * v4;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 **a1)
{
int v1; // ebx
unsigned int v2; // er9
int v4; // er9

v1 = 1;
do
{
if ( (unsigned int)func4(*a1) )
return (unsigned int)func3(a1) * v1;
while ( !(unsigned int)func0(a1, 45) )
{
v1 = -v1;
if ( (unsigned int)func4(*a1) )
return (unsigned int)func3(a1) * v1;
}
}
while ( !(unsigned int)func0(a1, 43) );
if ( !(unsigned int)func0(a1, 124) )
return (unsigned int)(v1 * (abspos + func5()));
if ( !(unsigned int)func0(a1, 40) )
{
func6();
func0(a1, 41);
v2 = v1 * v4;
}
return v2;
}

original_code:
static int evalatom(char **s)
{
 int ret;
 if (evalisnum(s))
  return evalnum(s);
 if (!evaljmp(s, '-'))
  return -evalatom(s);
 if (!evaljmp(s, '+'))
  return evalatom(s);
 if (!evaljmp(s, '|'))
  return abspos + evalatom(s);
 if (!evaljmp(s, '(')) {
  ret = evalexpr(s);
  evaljmp(s, ')');
  return ret;
 }
 return 0;
}


evalexpr

decompiled_code:
__int64 __fastcall evalexpr(unsigned __int8 **a1)
{
int v1; // er12
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // eax
int v6; // ecx

v1 = evalatom(a1);
while ( **a1 )
{
while ( !(unsigned int)evaljmp(a1, 43) )
{
v1 += evalatom(a1);
if ( !**a1 )
return (unsigned int)v1;
}
if ( (unsigned int)evaljmp(a1, 45) )
{
if ( (unsigned int)evaljmp(a1, 47) )
{
if ( (unsigned int)evaljmp(a1, 42) )
{
if ( (unsigned int)evaljmp(a1, 37) )
{
if ( (unsigned int)evaljmp(a1, 60) )
{
if ( (unsigned int)evaljmp(a1, 62) )
{
evaljmp(a1, 61);
v5 = evaljmp(a1, 61);
if ( (v5 == 0) + (v6 == 0) )
{
v1 = evalatom(a1) == v1;
}
else if ( (unsigned int)evaljmp(a1, 38) )
{
if ( (unsigned int)evaljmp(a1, 58) )
return (unsigned int)v1;
if ( v1 <= 0 )
LABEL_30:
v1 = (int)evalatom(a1) > 0;
else
v1 = 1;
}
else
{
if ( v1 > 0 )
goto LABEL_30;
v1 = 0;
}
}
else if ( (unsigned int)evaljmp(a1, 61) )
{
v1 = (int)evalatom(a1) < v1;
}
else
{
v1 = (int)evalatom(a1) <= v1;
}
}
else if ( (unsigned int)evaljmp(a1, 61) )
{
v1 = (int)evalatom(a1) > v1;
}
else
{
v1 = (int)evalatom(a1) >= v1;
}
}
else
{
v4 = evalatom(a1);
v1 %= (int)nonzero(v4);
}
}
else
{
v1 *= (unsigned int)evalatom(a1);
}
}
else
{
v3 = evalatom(a1);
v1 /= (int)nonzero(v3);
}
}
else
{
v1 -= evalatom(a1);
}
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 **a1)
{
int v1; // er12
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // eax
int v6; // ecx

v1 = func5(a1);
while ( **a1 )
{
while ( !(unsigned int)func0(a1, 43) )
{
v1 += func5(a1);
if ( !**a1 )
return (unsigned int)v1;
}
if ( (unsigned int)func0(a1, 45) )
{
if ( (unsigned int)func0(a1, 47) )
{
if ( (unsigned int)func0(a1, 42) )
{
if ( (unsigned int)func0(a1, 37) )
{
if ( (unsigned int)func0(a1, 60) )
{
if ( (unsigned int)func0(a1, 62) )
{
func0(a1, 61);
v5 = func0(a1, 61);
if ( (v5 == 0) + (v6 == 0) )
{
v1 = func5(a1) == v1;
}
else if ( (unsigned int)func0(a1, 38) )
{
if ( (unsigned int)func0(a1, 58) )
return (unsigned int)v1;
if ( v1 <= 0 )
LABEL_30:
v1 = (int)func5(a1) > 0;
else
v1 = 1;
}
else
{
if ( v1 > 0 )
goto LABEL_30;
v1 = 0;
}
}
else if ( (unsigned int)func0(a1, 61) )
{
v1 = (int)func5(a1) < v1;
}
else
{
v1 = (int)func5(a1) <= v1;
}
}
else if ( (unsigned int)func0(a1, 61) )
{
v1 = (int)func5(a1) > v1;
}
else
{
v1 = (int)func5(a1) >= v1;
}
}
else
{
v4 = func5(a1);
v1 %= (int)func2(v4);
}
}
else
{
v1 *= (unsigned int)func5(a1);
}
}
else
{
v3 = func5(a1);
v1 /= (int)func2(v3);
}
}
else
{
v1 -= func5(a1);
}
}
return (unsigned int)v1;
}

original_code:
static int evalexpr(char **s)
{
 int ret = evalatom(s);
 while (**s) {
  if (!evaljmp(s, '+'))
   ret += evalatom(s);
  else if (!evaljmp(s, '-'))
   ret -= evalatom(s);
  else if (!evaljmp(s, '/'))
   ret /= nonzero(evalatom(s));
  else if (!evaljmp(s, '*'))
   ret *= evalatom(s);
  else if (!evaljmp(s, '%'))
   ret %= nonzero(evalatom(s));
  else if (!evaljmp(s, '<'))
   ret = !evaljmp(s, '=') ? ret <= evalatom(s) : ret < evalatom(s);
  else if (!evaljmp(s, '>'))
   ret = !evaljmp(s, '=') ? ret >= evalatom(s) : ret > evalatom(s);
  else if (!evaljmp(s, '=') + !evaljmp(s, '='))
   ret = ret == evalatom(s);
  else if (!evaljmp(s, '&'))
   ret = ret > 0 && evalatom(s) > 0;
  else if (!evaljmp(s, ':'))
   ret = ret > 0 || evalatom(s) > 0;
  else
   break;
 }
 return ret;
}


decompiled_code:
__int64 __fastcall eval_up(unsigned __int8 **a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
int v5; // ebx

defunit = a2;
if ( a2 == 118 )
{
abspos = -*(_DWORD *)nreg(100LL);
result = evalexpr(a1);
}
else if ( a2 == 109 )
{
v4 = (unsigned int)map(".b0");
v5 = *(_DWORD *)nreg(v4);
abspos = v5 - f_hpos();
result = evalexpr(a1);
}
else
{
result = evalexpr(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 **a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
int v5; // ebx

defunit = a2;
if ( a2 == 118 )
{
abspos = -*(_DWORD *)nreg(100LL);
result = func6(a1);
}
else if ( a2 == 109 )
{
v4 = (unsigned int)map(".b0");
v5 = *(_DWORD *)nreg(v4);
abspos = v5 - f_hpos();
result = func6(a1);
}
else
{
result = func6(a1);
}
return result;
}

original_code:
int eval_up(char **s, int unit)
{
 defunit = unit;
 if (unit == 'v')
  abspos = -(*nreg(('d')));
 if (unit == 'm')
  abspos = (*nreg(map(".b0"))) - f_hpos();
 return evalexpr(s);
}

variable_types: unit int


decompiled_code:
__int64 __fastcall eval_re(unsigned __int8 *a1, int a2, int a3)
{
unsigned __int8 v5; // dl
__int64 result; // rax
unsigned __int8 *v7[2]; // [rsp+8h] [rbp-10h] BYREF

v7[0] = a1;
v5 = *a1;
if ( ((*a1 - 43) & 0xFD) != 0 )
return eval_up(v7, a3);
v7[0] = a1 + 1;
if ( v5 == 43 )
result = a2 + (unsigned int)eval_up(v7, a3);
else
result = a2 - (unsigned int)eval_up(v7, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1, int a2, int a3)
{
unsigned __int8 v5; // dl
__int64 result; // rax
unsigned __int8 *v7[2]; // [rsp+8h] [rbp-10h] BYREF

v7[0] = a1;
v5 = *a1;
if ( ((*a1 - 43) & 0xFD) != 0 )
return func7(v7, a3);
v7[0] = a1 + 1;
if ( v5 == 43 )
result = a2 + (unsigned int)func7(v7, a3);
else
result = a2 - (unsigned int)func7(v7, a3);
return result;
}

original_code:
int eval_re(char *s, int orig, int unit)
{
 int n;
 int rel = 0;
 if (*s == '+' || *s == '-') {
  rel = *s == '+' ? 1 : -1;
  s++;
 }
 n = eval_up(&s, unit);
 if (rel)
  return rel > 0 ? orig + n : orig - n;
 return n;
}

variable_types: orig int

variable_types: rel int


eval

decompiled_code:
__int64 __fastcall eval(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
return eval_up(&v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
return func7(&v3, a2);
}

original_code:
int eval(char *s, int unit)
{
 return eval_up(&s, unit);
}


decompiled_code:
__int64 __fastcall sbuf_extend(__int64 a1, int a2)
{
signed int v2; // esi
__int64 result; // rax

v2 = (a2 + 511) & 0xFFFFFE00;
*(_DWORD *)(a1 + 8) = v2;
result = mextend(*(_QWORD *)a1, *(int *)(a1 + 12), v2, 1LL);
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
signed int v2; // esi
__int64 result; // rax

v2 = (a2 + 511) & 0xFFFFFE00;
*(_DWORD *)(a1 + 8) = v2;
result = mextend(*(_QWORD *)a1, *(int *)(a1 + 12), v2, 1LL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
static void sbuf_extend(struct sbuf *sbuf, int amount)
{
 sbuf->sz = (((amount) + (512) - 1) & ~((512) - 1));
 sbuf->s = mextend(sbuf->s, sbuf->n, sbuf->sz, sizeof(sbuf->s[0]));
}

variable_types: struct sbuf { char *s; int sz; int n; } *

variable_types: amount int


decompiled_code:
__int64 __fastcall sbuf_init(_OWORD *a1)
{
*a1 = 0LL;
return sbuf_extend((__int64)a1, 512);
}

canonical_decompiled_code:
__int64 __fastcall func1(_OWORD *a1)
{
*a1 = 0LL;
return func0((__int64)a1, 512);
}

original_code:
void sbuf_init(struct sbuf *sbuf)
{
 memset(sbuf, 0, sizeof(*sbuf));
 sbuf_extend(sbuf, 512);
}


decompiled_code:
void *__fastcall sbuf_append(__int64 a1, const char *a2)
{
int v4; // eax
__int64 v5; // rdi
int v6; // ebp
int v7; // esi
void *result; // rax

v4 = strlen(a2);
v5 = *(int *)(a1 + 12);
v6 = v4;
v7 = v5 + v4 + 1;
if ( v7 >= *(_DWORD *)(a1 + 8) )
{
sbuf_extend(a1, v7);
v5 = *(int *)(a1 + 12);
}
result = memcpy((void *)(*(_QWORD *)a1 + v5), a2, v6);
*(_DWORD *)(a1 + 12) += v6;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, const char *a2)
{
int v4; // eax
__int64 v5; // rdi
int v6; // ebp
int v7; // esi
void *result; // rax

v4 = strlen(a2);
v5 = *(int *)(a1 + 12);
v6 = v4;
v7 = v5 + v4 + 1;
if ( v7 >= *(_DWORD *)(a1 + 8) )
{
func0(a1, v7);
v5 = *(int *)(a1 + 12);
}
result = memcpy((void *)(*(_QWORD *)a1 + v5), a2, v6);
*(_DWORD *)(a1 + 12) += v6;
return result;
}

original_code:
void sbuf_append(struct sbuf *sbuf, char *s)
{
 int len = strlen(s);
 if (sbuf->n + len + 1 >= sbuf->sz)
  sbuf_extend(sbuf, sbuf->n + len + 1);
 memcpy(sbuf->s + sbuf->n, s, len);
 sbuf->n += len;
}

variable_types: len int


decompiled_code:
void *sbuf_printf(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x400uLL, a2, arg);
return sbuf_append(a1, s);
}

canonical_decompiled_code:
void *func4(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x400uLL, a2, arg);
return func3(a1, s);
}

original_code:
void sbuf_printf(struct sbuf *sbuf, char *s, ...)
{
 char buf[1024];
 va_list ap;
 __builtin_va_start(ap,s);
 vsnprintf(buf, sizeof(buf), s, ap);
 __builtin_va_end(ap);
 sbuf_append(sbuf, buf);
}

canonical_original_code:
void sbuf_printf(struct sbuf *sbuf, char *s, ...)
{
 char buf[1024];
 __builtin_va_list ap;
 __builtin_va_start(ap,s);
 vsnprintf(buf, sizeof(buf), s, ap);
 __builtin_va_end(ap);
 sbuf_append(sbuf, buf);
}

variable_types:
buf
char [1024]


decompiled_code:
_BOOL8 __fastcall sbuf_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 12) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return *(_DWORD *)(a1 + 12) == 0;
}

original_code:
int sbuf_empty(struct sbuf *sbuf)
{
 return !sbuf->n;
}


decompiled_code:
__int64 __fastcall sbuf_buf(int *a1)
{
*(_BYTE *)(*(_QWORD *)a1 + a1[3]) = 0;
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1)
{
*(_BYTE *)(*(_QWORD *)a1 + a1[3]) = 0;
return *(_QWORD *)a1;
}

original_code:
char *sbuf_buf(struct sbuf *sbuf)
{
 sbuf->s[sbuf->n] = '\0';
 return sbuf->s;
}


decompiled_code:
__int64 __fastcall sbuf_len(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int sbuf_len(struct sbuf *sbuf)
{
 return sbuf->n;
}


decompiled_code:
void __fastcall sbuf_cut(__int64 a1, int a2)
{
if ( *(_DWORD *)(a1 + 12) > a2 )
*(_DWORD *)(a1 + 12) = a2;
}

original_code:
void sbuf_cut(struct sbuf *sbuf, int n)
{
 if (sbuf->n > n)
  sbuf->n = n;
}

variable_types: n int


decompiled_code:
void __fastcall sbuf_done(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func9(void **a1)
{
free(*a1);
}

original_code:
void sbuf_done(struct sbuf *sbuf)
{
 free(sbuf->s);
}


decompiled_code:
__int64 __fastcall sbuf_out(__int64 *a1)
{
__int64 result; // rax

result = *a1;
*(_OWORD *)a1 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1)
{
__int64 result; // rax

result = *a1;
*(_OWORD *)a1 = 0LL;
return result;
}

original_code:
char *sbuf_out(struct sbuf *sbuf)
{
 char *s = sbuf->s;
 memset(sbuf, 0, sizeof(*sbuf));
 return s;
}


decompiled_code:
__int64 __fastcall args_init(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // r13
const char *v4; // rdi
size_t v5; // r12
void *v6; // rax

v2 = 0LL;
v3 = xmalloc(256LL);
do
{
*(_QWORD *)(v3 + v2) = 0LL;
v4 = *(const char **)(a1 + v2);
if ( v4 )
{
v5 = (int)(strlen(v4) + 1);
v6 = (void *)xmalloc(v5);
*(_QWORD *)(v3 + v2) = v6;
memcpy(v6, *(const void **)(a1 + v2), v5);
}
v2 += 8LL;
}
while ( v2 != 256 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // r13
const char *v4; // rdi
size_t v5; // r12
void *v6; // rax

v2 = 0LL;
v3 = xmalloc(256LL);
do
{
*(_QWORD *)(v3 + v2) = 0LL;
v4 = *(const char **)(a1 + v2);
if ( v4 )
{
v5 = (int)(strlen(v4) + 1);
v6 = (void *)xmalloc(v5);
*(_QWORD *)(v3 + v2) = v6;
memcpy(v6, *(const void **)(a1 + v2), v5);
}
v2 += 8LL;
}
while ( v2 != 256 );
return v3;
}

original_code:
static char **args_init(char **args)
{
 char **out = xmalloc(32 * sizeof(*out));
 int i;
 for (i = 0; i < 32; i++) {
  out[i] = ((void *)0);
  if (args[i]) {
   int len = strlen(args[i]) + 1;
   out[i] = xmalloc(len);
   memcpy(out[i], args[i], len);
  }
 }
 return out;
}

variable_types:
args
char **

variable_types:
out
char **

variable_types: i int

return_type: char **


decompiled_code:
void __fastcall args_free(void *ptr)
{
void **v1; // rbx

v1 = (void **)ptr;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)((char *)ptr + 256) );
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void **v1; // rbx

v1 = (void **)ptr;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)((char *)ptr + 256) );
free(ptr);
}

original_code:
static void args_free(char **args)
{
 int i;
 for (i = 0; i < 32; i++)
  if (args[i])
   free(args[i]);
 free(args);
}


decompiled_code:
__int64 __fastcall in_push(char *src, __int64 a2)
{
__int64 v2; // rbp
int v3; // ebx
char *v4; // r13
char *v5; // r13
__int64 result; // rax

v2 = a2;
v3 = strlen(src);
in_new();
v4 = buf;
*((_QWORD *)v4 + 129) = xmalloc(v3 + 1);
v5 = buf;
*((_DWORD *)buf + 296) = v3;
result = (__int64)strcpy(*((char **)v5 + 129), src);
if ( a2 )
{
result = args_init(a2);
v5 = buf;
v2 = result;
}
*((_QWORD *)v5 + 130) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, __int64 a2)
{
__int64 v2; // rbp
int v3; // ebx
char *v4; // r13
char *v5; // r13
__int64 result; // rax

v2 = a2;
v3 = strlen(src);
func0();
v4 = buf;
*((_QWORD *)v4 + 129) = xmalloc(v3 + 1);
v5 = buf;
*((_DWORD *)buf + 296) = v3;
result = (__int64)strcpy(*((char **)v5 + 129), src);
if ( a2 )
{
result = func1(a2);
v5 = buf;
v2 = result;
}
*((_QWORD *)v5 + 130) = v2;
return result;
}

original_code:
void in_push(char *s, char **args)
{
 int len = strlen(s);
 in_new();
 buf->buf = xmalloc(len + 1);
 buf->len = len;
 strcpy(buf->buf, s);
 buf->args = args ? args_init(args) : ((void *)0);
}


decompiled_code:
__int64 in_nextfile()
{
__int64 v0; // rdi

if ( buf )
return 0LL;
v0 = cfile;
if ( cfile >= nfiles )
return 1LL;
do
{
cfile = v0 + 1;
in_so(&files[1024 * v0]);
if ( buf )
return 0LL;
v0 = cfile;
}
while ( cfile < nfiles );
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rdi

if ( buf )
return 0LL;
v0 = cfile;
if ( cfile >= nfiles )
return 1LL;
do
{
cfile = v0 + 1;
func5(&files[1024 * v0]);
if ( buf )
return 0LL;
v0 = cfile;
}
while ( cfile < nfiles );
return 1LL;
}

original_code:
static int in_nextfile(void)
{
 while (!buf && cfile < nfiles)
  in_so(files[cfile++]);
 return !buf;
}

canonical_original_code:
static int in_nextfile()
{
 while (!buf && cfile < nfiles)
  in_so(files[cfile++]);
 return !buf;
}


decompiled_code:
int __fastcall in_queue(void *a1)
{
__int64 v2; // rdi
int result; // eax

v2 = nfiles;
if ( nfiles <= 15 )
{
if ( !a1 )
a1 = &unk_476D;
++nfiles;
result = snprintf(&files[1024 * v2], 0x400uLL, "%s", a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(void *a1)
{
__int64 v2; // rdi
int result; // eax

v2 = nfiles;
if ( nfiles <= 15 )
{
if ( !a1 )
a1 = &unk_476D;
++nfiles;
result = snprintf(&files[1024 * v2], 0x400uLL, "%s", a1);
}
return result;
}

original_code:
void in_queue(char *path)
{
 if (nfiles < 16)
  snprintf(files[nfiles++], 1024, "%s", path ? path : "");
}

variable_types:
path
char *


decompiled_code:
void __fastcall in_nx(const char *a1)
{
while ( buf )
in_pop();
if ( a1 )
in_so(a1);
}

canonical_decompiled_code:
void __fastcall func9(const char *a1)
{
while ( buf )
func3();
if ( a1 )
func5(a1);
}

original_code:
void in_nx(char *path)
{
 while (buf)
  in_pop();
 if (path)
  in_so(path);
}


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

if ( buf )
{
do
in_pop();
while ( buf );
result = (unsigned int)nfiles;
cfile = nfiles;
}
else
{
result = (unsigned int)nfiles;
cfile = nfiles;
}
return result;
}

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

if ( buf )
{
do
func3();
while ( buf );
result = (unsigned int)nfiles;
cfile = nfiles;
}
else
{
result = (unsigned int)nfiles;
cfile = nfiles;
}
return result;
}

original_code:
void in_ex(void)
{
 while (buf)
  in_pop();
 cfile = nfiles;
}

canonical_original_code:
void in_ex()
{
 while (buf)
  in_pop();
 cfile = nfiles;
}


original_code:
int in_next(void)
{
 int c;
 while (buf || !in_nextfile()) {
  if (buf->un)
   return buf->unbuf[--buf->un];
  if (buf->buf && buf->pos < buf->len)
   break;
  if (!buf->buf && (c = getc(buf->fin)) >= 0) {
   if (c == '\n')
    buf->lnum++;
   return c;
  }
  in_pop();
 }
 return buf ? (unsigned char) buf->buf[buf->pos++] : -1;
}

canonical_original_code:
int in_next()
{
 int c;
 while (buf || !in_nextfile()) {
  if (buf->un)
   return buf->unbuf[--buf->un];
  if (buf->buf && buf->pos < buf->len)
   break;
  if (!buf->buf && (c = getc(buf->fin)) >= 0) {
   if (c == '\n')
    buf->lnum++;
   return c;
  }
  in_pop();
 }
 return buf ? (unsigned char) buf->buf[buf->pos++] : -1;
}

variable_types: c int


original_code:
void in_back(int c)
{
 if (c < 0)
  return;
 if (buf && buf->un < sizeof(buf->unbuf))
  buf->unbuf[buf->un++] = c;
}


decompiled_code:
__int64 in_top()
{
int v0; // eax
__int64 result; // rax

if ( buf && (v0 = *((_DWORD *)buf + 294)) != 0 )
result = *(unsigned int *)&buf[4 * v0 + 1044];
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // eax
__int64 result; // rax

if ( buf && (v0 = *((_DWORD *)buf + 294)) != 0 )
result = *(unsigned int *)&buf[4 * v0 + 1044];
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int in_top(void)
{
 return buf && buf->un ? buf->unbuf[buf->un - 1] : -1;
}

canonical_original_code:
int in_top()
{
 return buf && buf->un ? buf->unbuf[buf->un - 1] : -1;
}


hchar

decompiled_code:
__int64 __fastcall hchar(char *a1)
{
int v1; // eax
char v2; // cl
char v3; // dl
__int64 result; // rax

v1 = *a1;
v2 = a1[1];
v3 = *a1;
if ( v1 == c_ec )
return (v2 == 45) | (unsigned __int8)(v2 == 95);
if ( !v2 )
return v3 == 95;
if ( (_BYTE)v1 == 114 )
{
result = 1LL;
if ( v2 != 117 )
return (v3 == 114) & (unsigned __int8)(v2 == 110);
}
else
{
if ( (_BYTE)v1 != 117 )
return (v3 == 114) & (unsigned __int8)(v2 == 110);
result = v2 == 108;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
int v1; // eax
char v2; // cl
char v3; // dl
__int64 result; // rax

v1 = *a1;
v2 = a1[1];
v3 = *a1;
if ( v1 == c_ec )
return (v2 == 45) | (unsigned __int8)(v2 == 95);
if ( !v2 )
return v3 == 95;
if ( (_BYTE)v1 == 114 )
{
result = 1LL;
if ( v2 != 117 )
return (v3 == 114) & (unsigned __int8)(v2 == 110);
}
else
{
if ( (_BYTE)v1 != 117 )
return (v3 == 114) & (unsigned __int8)(v2 == 110);
result = v2 == 108;
}
return result;
}

variable_types:
c
char *


vchar

decompiled_code:
_BOOL8 __fastcall vchar(char *a1)
{
char v1; // al
char v2; // dl

v1 = a1[1];
v2 = *a1;
if ( !v1 )
return v2 == 95;
if ( v2 == 98 )
return (v1 & 0xFB) == 114;
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *a1)
{
char v1; // al
char v2; // dl

v1 = a1[1];
v2 = *a1;
if ( !v1 )
return v2 == 95;
if ( v2 == 98 )
return (v1 & 0xFB) == 114;
return 0LL;
}


cwid

decompiled_code:
__int64 __fastcall cwid(__int64 a1)
{
unsigned int v1; // er12
_BYTE v3[8312]; // [rsp+0h] [rbp-2078h] BYREF

wb_init(v3);
wb_putexpand(v3, a1);
v1 = wb_wid(v3);
wb_done(v3);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // er12
_BYTE v3[8312]; // [rsp+0h] [rbp-2078h] BYREF

wb_init(v3);
wb_putexpand(v3, a1);
v1 = wb_wid(v3);
wb_done(v3);
return v1;
}

original_code:
static int cwid(char *c)
{
 struct wb wb;
 int w;
 wb_init(&wb);
 wb_putexpand(&wb, c);
 w = wb_wid(&wb);
 wb_done(&wb);
 return w;
}

variable_types: struct wb { struct sbuf { char *s; int sz; int n; } sbuf; int f; int r_f; int part; int cost; int els_neg; int h; int ct; int llx; int icleft; char sub_c[256][32]; int sub_n; int sub_collect; }

variable_types: w int

user_defined_types: struct wb { struct sbuf sbuf; int f; int r_f; int part; int cost; int els_neg; int h; int ct; int llx; int icleft; char sub_c[256][32]; int sub_n; int sub_collect; }


original_code:
static int tok_num(char **s, int scale)
{
 while (**s == ' ' || **s == '\t')
  (*s)++;
 return eval_up(s, scale);
}

variable_types:
s
char **

variable_types: scale int


original_code:
static int tok_numpt(char **s, int scale, int *i)
{
 char *o;
 while (**s == ' ' || **s == '\t')
  (*s)++;
 o = *s;
 *i = eval_up(s, scale);
 return o == *s ? 1 : 0;
}

variable_types:
i
int *

variable_types:
o
char *


decompiled_code:
__int64 __fastcall ren_vline(__int64 a1, int a2, char *a3)
{
int v4; // er12
unsigned int v6; // er14
int v7; // ebx
int v8; // er15
unsigned int v9; // [rsp+4h] [rbp-44h]
int v10; // [rsp+Ch] [rbp-3Ch]

v4 = dev_res * *(_DWORD *)nreg(115LL) / 72;
v9 = cwid((__int64)a3);
if ( a2 < 0 )
{
wb_vmov(a1, (unsigned int)a2);
v10 = -a2;
if ( !v4 )
{
v6 = -a2;
v7 = 0;
goto LABEL_13;
}
}
else
{
if ( !v4 )
{
if ( !a2 )
return wb_hmov(a1, v9);
v6 = a2;
v7 = 0;
v10 = a2;
goto LABEL_13;
}
v10 = a2;
}
if ( v4 > v10 )
{
wb_vmov(a1, (unsigned int)((v10 >> 1) - v4));
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v9);
LABEL_6:
wb_vmov(a1, (unsigned int)(v10 >> 1));
goto LABEL_7;
}
v7 = v10 / v4;
v6 = v10 % v4;
if ( !(v10 % v4) )
{
if ( v10 / v4 <= 0 )
goto LABEL_7;
goto LABEL_16;
}
LABEL_13:
if ( vchar(a3) )
{
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v9);
wb_vmov(a1, v6 - v4);
}
else
{
wb_vmov(a1, v6);
}
if ( v7 > 0 )
{
LABEL_16:
v8 = 0;
do
{
++v8;
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v9);
}
while ( v8 < v7 );
}
if ( v4 > v10 )
goto LABEL_6;
LABEL_7:
if ( a2 < 0 )
wb_vmov(a1, (unsigned int)-v10);
return wb_hmov(a1, v9);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, char *a3)
{
int v4; // er12
unsigned int v6; // er14
int v7; // ebx
int v8; // er15
unsigned int v9; // [rsp+4h] [rbp-44h]
int v10; // [rsp+Ch] [rbp-3Ch]

v4 = dev_res * *(_DWORD *)nreg(115LL) / 72;
v9 = func2((__int64)a3);
if ( a2 < 0 )
{
wb_vmov(a1, (unsigned int)a2);
v10 = -a2;
if ( !v4 )
{
v6 = -a2;
v7 = 0;
goto LABEL_13;
}
}
else
{
if ( !v4 )
{
if ( !a2 )
return wb_hmov(a1, v9);
v6 = a2;
v7 = 0;
v10 = a2;
goto LABEL_13;
}
v10 = a2;
}
if ( v4 > v10 )
{
wb_vmov(a1, (unsigned int)((v10 >> 1) - v4));
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v9);
LABEL_6:
wb_vmov(a1, (unsigned int)(v10 >> 1));
goto LABEL_7;
}
v7 = v10 / v4;
v6 = v10 % v4;
if ( !(v10 % v4) )
{
if ( v10 / v4 <= 0 )
goto LABEL_7;
goto LABEL_16;
}
LABEL_13:
if ( func1(a3) )
{
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v9);
wb_vmov(a1, v6 - v4);
}
else
{
wb_vmov(a1, v6);
}
if ( v7 > 0 )
{
LABEL_16:
v8 = 0;
do
{
++v8;
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v9);
}
while ( v8 < v7 );
}
if ( v4 > v10 )
goto LABEL_6;
LABEL_7:
if ( a2 < 0 )
wb_vmov(a1, (unsigned int)-v10);
return wb_hmov(a1, v9);
}

original_code:
static void ren_vline(struct wb *wb, int l, char *c)
{
 int w, n, i, rem, hw, neg;
 neg = l < 0;
 w = ((*nreg(('s'))) * (dev_res) / 72);
 hw = cwid(c);
 if (l < 0) {
  wb_vmov(wb, l);
  l = -l;
 }
 n = w ? l / w : 0;
 rem = w ? l % w : l;
 if (l < w) {
  n = 1;
  rem = 0;
  wb_vmov(wb, -w + l / 2);
 }
 if (rem) {
  if (vchar(c)) {
   wb_vmov(wb, w);
   wb_putexpand(wb, c);
   wb_hmov(wb, -hw);
   wb_vmov(wb, rem - w);
  } else {
   wb_vmov(wb, rem);
  }
 }
 for (i = 0; i < n; i++) {
  wb_vmov(wb, w);
  wb_putexpand(wb, c);
  wb_hmov(wb, -hw);
 }
 if (l < w)
  wb_vmov(wb, l / 2);
 if (neg)
  wb_vmov(wb, -l);
 wb_hmov(wb, hw);
}

canonical_original_code:
static void ren_vline(struct wb *wb, int l, char *c)
{
 int w; int n; int i; int rem; int hw; int neg;
 neg = l < 0;
 w = ((*nreg(('s'))) * (dev_res) / 72);
 hw = cwid(c);
 if (l < 0) {
  wb_vmov(wb, l);
  l = -l;
 }
 n = w ? l / w : 0;
 rem = w ? l % w : l;
 if (l < w) {
  n = 1;
  rem = 0;
  wb_vmov(wb, -w + l / 2);
 }
 if (rem) {
  if (vchar(c)) {
   wb_vmov(wb, w);
   wb_putexpand(wb, c);
   wb_hmov(wb, -hw);
   wb_vmov(wb, rem - w);
  } else {
   wb_vmov(wb, rem);
  }
 }
 for (i = 0; i < n; i++) {
  wb_vmov(wb, w);
  wb_putexpand(wb, c);
  wb_hmov(wb, -hw);
 }
 if (l < w)
  wb_vmov(wb, l / 2);
 if (neg)
  wb_vmov(wb, -l);
 wb_hmov(wb, hw);
}

variable_types: struct wb { struct sbuf { char *s; int sz; int n; } sbuf; int f; int r_f; int part; int cost; int els_neg; int h; int ct; int llx; int icleft; char sub_c[256][32]; int sub_n; int sub_collect; } *

variable_types: l int

variable_types: rem int

variable_types: hw int

variable_types: neg int


decompiled_code:
__int64 __fastcall ren_hline(__int64 a1, int a2, char *a3)
{
int v4; // ebx
__int64 result; // rax
int v6; // er14
int v7; // er15
int v8; // er13
int v9; // ebx

v4 = a2;
result = cwid((__int64)a3);
v6 = result;
if ( a2 < 0 )
{
v4 = -a2;
wb_hmov(a1, (unsigned int)a2);
if ( !v6 )
{
LABEL_9:
v7 = v4;
v8 = 0;
goto LABEL_10;
}
}
else if ( !(_DWORD)result )
{
if ( !a2 )
return result;
goto LABEL_9;
}
if ( v6 > v4 )
{
wb_hmov(a1, (unsigned int)((v4 - v6) / 2));
wb_putexpand(a1, a3);
return wb_hmov(a1, (unsigned int)(~(v6 - v4) / 2));
}
v7 = v4;
result = (unsigned int)(v4 / v6);
v8 = v4 / v6;
v4 %= v6;
if ( !v4 )
{
if ( (int)result <= 0 )
return result;
goto LABEL_13;
}
LABEL_10:
if ( (unsigned int)hchar(a3) )
{
wb_putexpand(a1, a3);
result = wb_hmov(a1, (unsigned int)(v4 - v6));
}
else
{
result = wb_hmov(a1, (unsigned int)v4);
}
if ( v8 > 0 )
{
LABEL_13:
v9 = 0;
do
{
++v9;
result = wb_putexpand(a1, a3);
}
while ( v9 < v8 );
}
if ( v6 > v7 )
{
v4 = v7;
return wb_hmov(a1, (unsigned int)(~(v6 - v4) / 2));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, char *a3)
{
int v4; // ebx
__int64 result; // rax
int v6; // er14
int v7; // er15
int v8; // er13
int v9; // ebx

v4 = a2;
result = func2((__int64)a3);
v6 = result;
if ( a2 < 0 )
{
v4 = -a2;
wb_hmov(a1, (unsigned int)a2);
if ( !v6 )
{
LABEL_9:
v7 = v4;
v8 = 0;
goto LABEL_10;
}
}
else if ( !(_DWORD)result )
{
if ( !a2 )
return result;
goto LABEL_9;
}
if ( v6 > v4 )
{
wb_hmov(a1, (unsigned int)((v4 - v6) / 2));
wb_putexpand(a1, a3);
return wb_hmov(a1, (unsigned int)(~(v6 - v4) / 2));
}
v7 = v4;
result = (unsigned int)(v4 / v6);
v8 = v4 / v6;
v4 %= v6;
if ( !v4 )
{
if ( (int)result <= 0 )
return result;
goto LABEL_13;
}
LABEL_10:
if ( (unsigned int)func0(a3) )
{
wb_putexpand(a1, a3);
result = wb_hmov(a1, (unsigned int)(v4 - v6));
}
else
{
result = wb_hmov(a1, (unsigned int)v4);
}
if ( v8 > 0 )
{
LABEL_13:
v9 = 0;
do
{
++v9;
result = wb_putexpand(a1, a3);
}
while ( v9 < v8 );
}
if ( v6 > v7 )
{
v4 = v7;
return wb_hmov(a1, (unsigned int)(~(v6 - v4) / 2));
}
return result;
}

original_code:
void ren_hline(struct wb *wb, int l, char *c)
{
 int w, n, i, rem;
 w = cwid(c);
 if (l < 0) {
  wb_hmov(wb, l);
  l = -l;
 }
 n = w ? l / w : 0;
 rem = w ? l % w : l;
 if (l < w) {
  n = 1;
  rem = 0;
  wb_hmov(wb, -(w - l) / 2);
 }
 if (rem) {
  if (hchar(c)) {
   wb_putexpand(wb, c);
   wb_hmov(wb, rem - w);
  } else {
   wb_hmov(wb, rem);
  }
 }
 for (i = 0; i < n; i++)
  wb_putexpand(wb, c);
 if (l < w)
  wb_hmov(wb, -(w - l + 1) / 2);
}

canonical_original_code:
void ren_hline(struct wb *wb, int l, char *c)
{
 int w; int n; int i; int rem;
 w = cwid(c);
 if (l < 0) {
  wb_hmov(wb, l);
  l = -l;
 }
 n = w ? l / w : 0;
 rem = w ? l % w : l;
 if (l < w) {
  n = 1;
  rem = 0;
  wb_hmov(wb, -(w - l) / 2);
 }
 if (rem) {
  if (hchar(c)) {
   wb_putexpand(wb, c);
   wb_hmov(wb, rem - w);
  } else {
   wb_hmov(wb, rem);
  }
 }
 for (i = 0; i < n; i++)
  wb_putexpand(wb, c);
 if (l < w)
  wb_hmov(wb, -(w - l + 1) / 2);
}

variable_types: n int


decompiled_code:
__int64 __fastcall ren_hlcmd(__int64 a1, char *a2)
{
int v2; // eax
char *v3; // rdx
int v4; // ebp
char v5; // al
__int64 result; // rax
char *v7; // [rsp+8h] [rbp-40h] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v7 = a2;
v2 = eval_up(&v7);
v3 = v7;
v4 = v2;
v5 = *v7;
if ( *v7 == c_ec && v7[1] == 38 )
{
v7 += 2;
v5 = v3[2];
}
if ( v5 )
{
result = charread(&v7, v8);
if ( (int)result >= 0 )
{
if ( !v4 )
return result;
return ren_hline(a1, v4, v8);
}
}
result = 30066LL;
strcpy(v8, "ru");
if ( v4 )
return ren_hline(a1, v4, v8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2)
{
int v2; // eax
char *v3; // rdx
int v4; // ebp
char v5; // al
__int64 result; // rax
char *v7; // [rsp+8h] [rbp-40h] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v7 = a2;
v2 = eval_up(&v7);
v3 = v7;
v4 = v2;
v5 = *v7;
if ( *v7 == c_ec && v7[1] == 38 )
{
v7 += 2;
v5 = v3[2];
}
if ( v5 )
{
result = charread(&v7, v8);
if ( (int)result >= 0 )
{
if ( !v4 )
return result;
return func6(a1, v4, v8);
}
}
result = 30066LL;
strcpy(v8, "ru");
if ( v4 )
return func6(a1, v4, v8);
return result;
}

original_code:
void ren_hlcmd(struct wb *wb, char *arg)
{
 char lc[32];
 int l = eval_up(&arg, 'm');
 if (arg[0] == c_ec && arg[1] == '&')
  arg += 2;
 if (!*arg || charread(&arg, lc) < 0)
  strcpy(lc, "ru");
 if (l)
  ren_hline(wb, l, lc);
}

variable_types:
arg
char *

variable_types:
lc
char [32]


decompiled_code:
__int64 __fastcall ren_vlcmd(__int64 a1, char *a2)
{
int v2; // eax
char *v3; // rdx
int v4; // ebp
char v5; // al
__int64 result; // rax
char *v7; // [rsp+8h] [rbp-40h] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v7 = a2;
v2 = eval_up(&v7);
v3 = v7;
v4 = v2;
v5 = *v7;
if ( *v7 == c_ec && v7[1] == 38 )
{
v7 += 2;
v5 = v3[2];
}
if ( v5 )
{
result = charread(&v7, v8);
if ( (int)result >= 0 )
{
if ( !v4 )
return result;
return ren_vline(a1, v4, v8);
}
}
result = 29282LL;
strcpy(v8, "br");
if ( v4 )
return ren_vline(a1, v4, v8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
int v2; // eax
char *v3; // rdx
int v4; // ebp
char v5; // al
__int64 result; // rax
char *v7; // [rsp+8h] [rbp-40h] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v7 = a2;
v2 = eval_up(&v7);
v3 = v7;
v4 = v2;
v5 = *v7;
if ( *v7 == c_ec && v7[1] == 38 )
{
v7 += 2;
v5 = v3[2];
}
if ( v5 )
{
result = charread(&v7, v8);
if ( (int)result >= 0 )
{
if ( !v4 )
return result;
return func5(a1, v4, v8);
}
}
result = 29282LL;
strcpy(v8, "br");
if ( v4 )
return func5(a1, v4, v8);
return result;
}

original_code:
void ren_vlcmd(struct wb *wb, char *arg)
{
 char lc[32];
 int l = eval_up(&arg, 'v');
 if (arg[0] == c_ec && arg[1] == '&')
  arg += 2;
 if (!*arg || charread(&arg, lc) < 0)
  strcpy(lc, "br");
 if (l)
  ren_vline(wb, l, lc);
}


decompiled_code:
__int64 __fastcall ren_dcmd(__int64 a1, char *a2)
{
unsigned int v2; // er12
__int64 result; // rax
unsigned int v4; // ebx
unsigned int v5; // eax
char *v6; // rdx
__int64 v7; // rax
__int64 v8; // rcx
char *v9[2]; // [rsp+8h] [rbp-70h] BYREF
unsigned int v10; // [rsp+18h] [rbp-60h] BYREF
unsigned int v11; // [rsp+1Ch] [rbp-5Ch] BYREF
char v12[88]; // [rsp+20h] [rbp-58h] BYREF

v9[0] = a2 + 1;
v2 = *a2;
result = (unsigned int)(tolower(v2) - 97);
switch ( (int)result )
{
case 0:
v10 = tok_num(v9);
v11 = tok_num(v9);
v4 = tok_num(v9);
v5 = tok_num(v9);
result = wb_drawa(a1, v2, v10, v11, v4, v5);
break;
case 2:
v10 = tok_num(v9);
result = wb_drawc(a1, v2, v10);
break;
case 4:
v10 = tok_num(v9);
v11 = tok_num(v9);
result = wb_drawe(a1, v2, v10, v11);
break;
case 11:
v10 = tok_num(v9);
v11 = tok_num(v9);
result = wb_drawl(a1, v2, v10, v11);
break;
case 15:
case 29:
wb_drawxbeg(a1, v2);
while ( *v9[0] )
{
while ( !tok_numpt(v9, 109LL, &v10) && !tok_numpt(v9, 118LL, &v11) )
{
wb_drawxdot(a1, v10, v11);
if ( !*v9[0] )
goto LABEL_7;
}
v6 = v9[0];
v7 = 0LL;
while ( 1 )
{
v8 = (int)v7;
if ( (*v6 & 0xDF) == 0 )
break;
v9[0] = ++v6;
v12[v7++] = *(v6 - 1);
if ( v7 == 63 )
{
v8 = 63LL;
break;
}
}
v12[v8] = 0;
wb_drawxcmd(a1, v12);
}
LABEL_7:
result = wb_drawxend(a1);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char *a2)
{
unsigned int v2; // er12
__int64 result; // rax
unsigned int v4; // ebx
unsigned int v5; // eax
char *v6; // rdx
__int64 v7; // rax
__int64 v8; // rcx
char *v9[2]; // [rsp+8h] [rbp-70h] BYREF
unsigned int v10; // [rsp+18h] [rbp-60h] BYREF
unsigned int v11; // [rsp+1Ch] [rbp-5Ch] BYREF
char v12[88]; // [rsp+20h] [rbp-58h] BYREF

v9[0] = a2 + 1;
v2 = *a2;
result = (unsigned int)(tolower(v2) - 97);
switch ( (int)result )
{
case 0:
v10 = func3(v9);
v11 = func3(v9);
v4 = func3(v9);
v5 = func3(v9);
result = wb_drawa(a1, v2, v10, v11, v4, v5);
break;
case 2:
v10 = func3(v9);
result = wb_drawc(a1, v2, v10);
break;
case 4:
v10 = func3(v9);
v11 = func3(v9);
result = wb_drawe(a1, v2, v10, v11);
break;
case 11:
v10 = func3(v9);
v11 = func3(v9);
result = wb_drawl(a1, v2, v10, v11);
break;
case 15:
case 29:
wb_drawxbeg(a1, v2);
while ( *v9[0] )
{
while ( !func4(v9, 109LL, &v10) && !func4(v9, 118LL, &v11) )
{
wb_drawxdot(a1, v10, v11);
if ( !*v9[0] )
goto LABEL_7;
}
v6 = v9[0];
v7 = 0LL;
while ( 1 )
{
v8 = (int)v7;
if ( (*v6 & 0xDF) == 0 )
break;
v9[0] = ++v6;
v12[v7++] = *(v6 - 1);
if ( v7 == 63 )
{
v8 = 63LL;
break;
}
}
v12[v8] = 0;
wb_drawxcmd(a1, v12);
}
LABEL_7:
result = wb_drawxend(a1);
break;
default:
return result;
}
return result;
}

original_code:
void ren_dcmd(struct wb *wb, char *s)
{
 int h1, h2, v1, v2;
 int c = *s++;
 switch (tolower(c)) {
 case 'l':
  h1 = tok_num(&s, 'm');
  v1 = tok_num(&s, 'v');
  wb_drawl(wb, c, h1, v1);
  break;
 case 'c':
  h1 = tok_num(&s, 'm');
  wb_drawc(wb, c, h1);
  break;
 case 'e':
  h1 = tok_num(&s, 'm');
  v1 = tok_num(&s, 'v');
  wb_drawe(wb, c, h1, v1);
  break;
 case 'a':
  h1 = tok_num(&s, 'm');
  v1 = tok_num(&s, 'v');
  h2 = tok_num(&s, 'm');
  v2 = tok_num(&s, 'v');
  wb_drawa(wb, c, h1, v1, h2, v2);
  break;
 case '~':
 case 'p':
  wb_drawxbeg(wb, c);
  while (*s) {
   if (tok_numpt(&s, 'm', &h1) || tok_numpt(&s, 'v', &v1)) {
    char tok[64];
    int i = 0;
    while (i < sizeof(tok) - 1 && *s && *s != ' ')
     tok[i++] = *s++;
    tok[i] = '\0';
    wb_drawxcmd(wb, tok);
   } else {
    wb_drawxdot(wb, h1, v1);
   }
  }
  wb_drawxend(wb);
  break;
 }
}

canonical_original_code:
void ren_dcmd(struct wb *wb, char *s)
{
 int h1; int h2; int v1; int v2;
 int c = *s++;
 switch (tolower(c)) {
 case 'l':
  h1 = tok_num(&s, 'm');
  v1 = tok_num(&s, 'v');
  wb_drawl(wb, c, h1, v1);
  break;
 case 'c':
  h1 = tok_num(&s, 'm');
  wb_drawc(wb, c, h1);
  break;
 case 'e':
  h1 = tok_num(&s, 'm');
  v1 = tok_num(&s, 'v');
  wb_drawe(wb, c, h1, v1);
  break;
 case 'a':
  h1 = tok_num(&s, 'm');
  v1 = tok_num(&s, 'v');
  h2 = tok_num(&s, 'm');
  v2 = tok_num(&s, 'v');
  wb_drawa(wb, c, h1, v1, h2, v2);
  break;
 case '~':
 case 'p':
  wb_drawxbeg(wb, c);
  while (*s) {
   if (tok_numpt(&s, 'm', &h1) || tok_numpt(&s, 'v', &v1)) {
    char tok[64];
    int i = 0;
    while (i < sizeof(tok) - 1 && *s && *s != ' ')
     tok[i++] = *s++;
    tok[i] = '\0';
    wb_drawxcmd(wb, tok);
   } else {
    wb_drawxdot(wb, h1, v1);
   }
  }
  wb_drawxend(wb);
  break;
 }
}

variable_types:
s
char *

variable_types:
tok
char [64]

variable_types: i int


decompiled_code:
__int64 __fastcall ren_bcmd(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // rdi
int v4; // eax
int v5; // ebp
int v6; // ebx
int v7; // eax
_DWORD *v8; // rax
int v9; // eax
int v10; // er13
int v11; // kr00_4
_DWORD *v12; // rax
_BYTE v14[8344]; // [rsp+0h] [rbp-2098h] BYREF

sstr_push(a2);
v3 = (unsigned __int64)v14;
wb_init(v14);
v4 = sstr_next();
if ( v4 < 0 )
{
v5 = 0;
v6 = 0;
}
else
{
v3 = (unsigned int)v4;
v5 = 0;
v6 = 0;
do
{
sstr_back(v3);
ren_char(v14, &sstr_next, &sstr_back);
if ( (int)wb_wid(v14) > v5 )
v5 = wb_wid(v14);
++v6;
v7 = wb_wid(v14);
wb_hmov(v14, (unsigned int)-v7);
v8 = (_DWORD *)nreg(115LL);
wb_vmov(v14, (unsigned int)(dev_res * *v8 / 72));
v9 = sstr_next();
v3 = (unsigned int)v9;
}
while ( v9 >= 0 );
}
sstr_pop(v3);
v10 = dev_res * *(_DWORD *)nreg(115LL) / -72;
v11 = v10 - dev_res * *(_DWORD *)nreg(115LL) / 72 * v6;
v12 = (_DWORD *)nreg(115LL);
wb_vmov(a1, (unsigned int)(v11 / 2 + dev_res * *v12 / 72));
wb_cat(a1, v14);
wb_done(v14);
wb_vmov(a1, (unsigned int)(v11 / 2));
return wb_hmov(a1, (unsigned int)v5);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // rdi
int v4; // eax
int v5; // ebp
int v6; // ebx
int v7; // eax
_DWORD *v8; // rax
int v9; // eax
int v10; // er13
int v11; // kr00_4
_DWORD *v12; // rax
_BYTE v14[8344]; // [rsp+0h] [rbp-2098h] BYREF

sstr_push(a2);
v3 = (unsigned __int64)v14;
wb_init(v14);
v4 = sstr_next();
if ( v4 < 0 )
{
v5 = 0;
v6 = 0;
}
else
{
v3 = (unsigned int)v4;
v5 = 0;
v6 = 0;
do
{
sstr_back(v3);
ren_char(v14, &sstr_next, &sstr_back);
if ( (int)wb_wid(v14) > v5 )
v5 = wb_wid(v14);
++v6;
v7 = wb_wid(v14);
wb_hmov(v14, (unsigned int)-v7);
v8 = (_DWORD *)nreg(115LL);
wb_vmov(v14, (unsigned int)(dev_res * *v8 / 72));
v9 = sstr_next();
v3 = (unsigned int)v9;
}
while ( v9 >= 0 );
}
sstr_pop(v3);
v10 = dev_res * *(_DWORD *)nreg(115LL) / -72;
v11 = v10 - dev_res * *(_DWORD *)nreg(115LL) / 72 * v6;
v12 = (_DWORD *)nreg(115LL);
wb_vmov(a1, (unsigned int)(v11 / 2 + dev_res * *v12 / 72));
wb_cat(a1, v14);
wb_done(v14);
wb_vmov(a1, (unsigned int)(v11 / 2));
return wb_hmov(a1, (unsigned int)v5);
}

original_code:
void ren_bcmd(struct wb *wb, char *arg)
{
 struct wb wb2;
 int n = 0, w = 0;
 int c, center;
 sstr_push(arg);
 wb_init(&wb2);
 c = sstr_next();
 while (c >= 0) {
  sstr_back(c);
  ren_char(&wb2, sstr_next, sstr_back);
  if (wb_wid(&wb2) > w)
   w = wb_wid(&wb2);
  wb_hmov(&wb2, -wb_wid(&wb2));
  wb_vmov(&wb2, ((*nreg(('s'))) * (dev_res) / 72));
  n++;
  c = sstr_next();
 }
 sstr_pop();
 center = -(n * ((*nreg(('s'))) * (dev_res) / 72) + ((*nreg(('s'))) * (dev_res) / 72)) / 2;
 wb_vmov(wb, center + ((*nreg(('s'))) * (dev_res) / 72));
 wb_cat(wb, &wb2);
 wb_done(&wb2);
 wb_vmov(wb, center);
 wb_hmov(wb, w);
}

canonical_original_code:
void ren_bcmd(struct wb *wb, char *arg)
{
 struct wb wb2;
 int n = 0; int w = 0;
 int c; int center;
 sstr_push(arg);
 wb_init(&wb2);
 c = sstr_next();
 while (c >= 0) {
  sstr_back(c);
  ren_char(&wb2, sstr_next, sstr_back);
  if (wb_wid(&wb2) > w)
   w = wb_wid(&wb2);
  wb_hmov(&wb2, -wb_wid(&wb2));
  wb_vmov(&wb2, ((*nreg(('s'))) * (dev_res) / 72));
  n++;
  c = sstr_next();
 }
 sstr_pop();
 center = -(n * ((*nreg(('s'))) * (dev_res) / 72) + ((*nreg(('s'))) * (dev_res) / 72)) / 2;
 wb_vmov(wb, center + ((*nreg(('s'))) * (dev_res) / 72));
 wb_cat(wb, &wb2);
 wb_done(&wb2);
 wb_vmov(wb, center);
 wb_hmov(wb, w);
}

variable_types: struct wb { struct sbuf { char *s; int sz; int n; } sbuf; int f; int r_f; int part; int cost; int els_neg; int h; int ct; int llx; int icleft; char sub_c[256][32]; int sub_n; int sub_collect; }

variable_types: c int

variable_types: center int


decompiled_code:
__int64 __fastcall ren_ocmd(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // rdi
int v4; // eax
int v5; // ebx
int v6; // eax
unsigned int v7; // ebp
int v8; // eax
unsigned int v9; // ebp
_BYTE v11[8304]; // [rsp+0h] [rbp-40F8h] BYREF
char v12[8328]; // [rsp+2070h] [rbp-2088h] BYREF

sstr_push(a2);
wb_init(v11);
v3 = (unsigned __int64)v12;
wb_init(v12);
v4 = sstr_next();
if ( v4 < 0 )
{
v9 = 0;
}
else
{
v3 = (unsigned int)v4;
v5 = 0;
do
{
sstr_back(v3);
ren_char(v12, &sstr_next, &sstr_back);
v6 = wb_wid(v12);
if ( v5 < v6 )
v5 = v6;
v7 = v6 / -2;
wb_hmov(v11, (unsigned int)(v6 / -2));
wb_cat(v11, v12);
wb_hmov(v11, v7);
v8 = sstr_next();
v3 = (unsigned int)v8;
}
while ( v8 >= 0 );
v9 = v5 >> 1;
}
sstr_pop(v3);
wb_hmov(a1, v9);
wb_cat(a1, v11);
wb_hmov(a1, v9);
wb_done(v12);
return wb_done(v11);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // rdi
int v4; // eax
int v5; // ebx
int v6; // eax
unsigned int v7; // ebp
int v8; // eax
unsigned int v9; // ebp
_BYTE v11[8304]; // [rsp+0h] [rbp-40F8h] BYREF
char v12[8328]; // [rsp+2070h] [rbp-2088h] BYREF

sstr_push(a2);
wb_init(v11);
v3 = (unsigned __int64)v12;
wb_init(v12);
v4 = sstr_next();
if ( v4 < 0 )
{
v9 = 0;
}
else
{
v3 = (unsigned int)v4;
v5 = 0;
do
{
sstr_back(v3);
ren_char(v12, &sstr_next, &sstr_back);
v6 = wb_wid(v12);
if ( v5 < v6 )
v5 = v6;
v7 = v6 / -2;
wb_hmov(v11, (unsigned int)(v6 / -2));
wb_cat(v11, v12);
wb_hmov(v11, v7);
v8 = sstr_next();
v3 = (unsigned int)v8;
}
while ( v8 >= 0 );
v9 = v5 >> 1;
}
sstr_pop(v3);
wb_hmov(a1, v9);
wb_cat(a1, v11);
wb_hmov(a1, v9);
wb_done(v12);
return wb_done(v11);
}

original_code:
void ren_ocmd(struct wb *wb, char *arg)
{
 struct wb wb2, wb3;
 int w = 0, wc;
 int c;
 sstr_push(arg);
 wb_init(&wb2);
 wb_init(&wb3);
 c = sstr_next();
 while (c >= 0) {
  sstr_back(c);
  ren_char(&wb3, sstr_next, sstr_back);
  wc = wb_wid(&wb3);
  if (wc > w)
   w = wc;
  wb_hmov(&wb2, -wc / 2);
  wb_cat(&wb2, &wb3);
  wb_hmov(&wb2, -wc / 2);
  c = sstr_next();
 }
 sstr_pop();
 wb_hmov(wb, w / 2);
 wb_cat(wb, &wb2);
 wb_hmov(wb, w / 2);
 wb_done(&wb3);
 wb_done(&wb2);
}

canonical_original_code:
void ren_ocmd(struct wb *wb, char *arg)
{
 struct wb wb2; struct wb wb3;
 int w = 0; int wc;
 int c;
 sstr_push(arg);
 wb_init(&wb2);
 wb_init(&wb3);
 c = sstr_next();
 while (c >= 0) {
  sstr_back(c);
  ren_char(&wb3, sstr_next, sstr_back);
  wc = wb_wid(&wb3);
  if (wc > w)
   w = wc;
  wb_hmov(&wb2, -wc / 2);
  wb_cat(&wb2, &wb3);
  wb_hmov(&wb2, -wc / 2);
  c = sstr_next();
 }
 sstr_pop();
 wb_hmov(wb, w / 2);
 wb_cat(wb, &wb2);
 wb_hmov(wb, w / 2);
 wb_done(&wb3);
 wb_done(&wb2);
}

variable_types: w int

variable_types: wc int


decompiled_code:
__int64 __fastcall ren_zcmd(__int64 a1, __int64 a2)
{
int v2; // er12
int v3; // ebx
int v4; // eax
int v5; // eax
int v6; // eax

v2 = ((__int64 (*)(void))wb_hpos)();
v3 = wb_vpos(a1);
sstr_push(a2);
while ( 1 )
{
v4 = sstr_next();
if ( v4 < 0 )
break;
sstr_back((unsigned int)v4);
ren_char(a1, &sstr_next, &sstr_back);
}
sstr_pop((unsigned int)v4);
v5 = wb_hpos(a1);
wb_hmov(a1, (unsigned int)(v2 - v5));
v6 = wb_vpos(a1);
return wb_vmov(a1, (unsigned int)(v3 - v6));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // er12
int v3; // ebx
int v4; // eax
int v5; // eax
int v6; // eax

v2 = ((__int64 (*)(void))wb_hpos)();
v3 = wb_vpos(a1);
sstr_push(a2);
while ( 1 )
{
v4 = sstr_next();
if ( v4 < 0 )
break;
sstr_back((unsigned int)v4);
ren_char(a1, &sstr_next, &sstr_back);
}
sstr_pop((unsigned int)v4);
v5 = wb_hpos(a1);
wb_hmov(a1, (unsigned int)(v2 - v5));
v6 = wb_vpos(a1);
return wb_vmov(a1, (unsigned int)(v3 - v6));
}

original_code:
void ren_zcmd(struct wb *wb, char *arg)
{
 int h, v;
 int c;
 h = wb_hpos(wb);
 v = wb_vpos(wb);
 sstr_push(arg);
 while ((c = sstr_next()) >= 0) {
  sstr_back(c);
  ren_char(wb, sstr_next, sstr_back);
 }
 sstr_pop();
 wb_hmov(wb, h - wb_hpos(wb));
 wb_vmov(wb, v - wb_vpos(wb));
}

canonical_original_code:
void ren_zcmd(struct wb *wb, char *arg)
{
 int h; int v;
 int c;
 h = wb_hpos(wb);
 v = wb_vpos(wb);
 sstr_push(arg);
 while ((c = sstr_next()) >= 0) {
  sstr_back(c);
  ren_char(wb, sstr_next, sstr_back);
 }
 sstr_pop();
 wb_hmov(wb, h - wb_hpos(wb));
 wb_vmov(wb, v - wb_vpos(wb));
}

variable_types: h int

variable_types: v int


decompiled_code:
const char *__fastcall clr_str(int a1)
{
if ( !a1 )
return "0";
sprintf(clr_buf_1, "#%02x%02x%02x", BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
return clr_buf_1;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
if ( !a1 )
return "0";
sprintf(clr_buf_1, "#%02x%02x%02x", BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
return clr_buf_1;
}

original_code:
char *clr_str(int c)
{
 static char clr_buf[32];
 if (!c)
  return "0";
 sprintf(clr_buf, "#%02x%02x%02x", (((c) >> 16) & 0xff), (((c) >> 8) & 0xff), ((c) & 0xff));
 return clr_buf;
}


decompiled_code:
__int64 __fastcall clr_get(char *nptr)
{
__int64 v2; // rbx
__int64 v3; // rbx
const char *v4; // rdi
unsigned int v6; // eax
size_t v7; // rax
char *v8; // rdi
int v9; // esi
int v10; // eax
int v11; // ebx
unsigned int v12; // ebx
int v13; // ebx
unsigned int v14; // ebx

v2 = (unsigned __int8)*nptr;
if ( (_BYTE)v2 == 35 )
{
v7 = strlen(nptr);
if ( v7 == 7 )
{
v11 = ccom(nptr + 1, 2);
v12 = ((unsigned int)ccom(nptr + 3, 2) << 8) | (v11 << 16);
return v12 | (unsigned int)ccom(nptr + 5, 2);
}
if ( v7 == 4 )
{
v13 = ccom(nptr + 1, 1);
v14 = ((unsigned int)ccom(nptr + 2, 1) << 8) | (v13 << 16);
return v14 | (unsigned int)ccom(nptr + 3, 1);
}
v8 = nptr + 1;
v9 = 2;
if ( v7 != 3 )
{
if ( v7 != 2 )
goto LABEL_2;
v8 = nptr + 1;
v9 = 1;
}
v10 = ccom(v8, v9);
return v10 | (v10 << 8) | (unsigned int)(v10 << 16);
}
LABEL_2:
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
{
v3 = 0LL;
v4 = "black";
goto LABEL_5;
}
v3 = 0LL;
v6 = atoi(nptr);
v4 = "black";
if ( v6 <= 7 )
return (unsigned int)dword_2E8[4 * v6];
LABEL_5:
while ( strcmp(v4, nptr) )
{
if ( ++v3 == 8 )
return 0LL;
v4 = (&colors)[2 * v3];
}
return (unsigned int)dword_2E8[4 * (int)v3];
}

canonical_decompiled_code:
__int64 __fastcall func2(char *nptr)
{
__int64 v2; // rbx
__int64 v3; // rbx
const char *v4; // rdi
unsigned int v6; // eax
size_t v7; // rax
char *v8; // rdi
int v9; // esi
int v10; // eax
int v11; // ebx
unsigned int v12; // ebx
int v13; // ebx
unsigned int v14; // ebx

v2 = (unsigned __int8)*nptr;
if ( (_BYTE)v2 == 35 )
{
v7 = strlen(nptr);
if ( v7 == 7 )
{
v11 = func0(nptr + 1, 2);
v12 = ((unsigned int)func0(nptr + 3, 2) << 8) | (v11 << 16);
return v12 | (unsigned int)func0(nptr + 5, 2);
}
if ( v7 == 4 )
{
v13 = func0(nptr + 1, 1);
v14 = ((unsigned int)func0(nptr + 2, 1) << 8) | (v13 << 16);
return v14 | (unsigned int)func0(nptr + 3, 1);
}
v8 = nptr + 1;
v9 = 2;
if ( v7 != 3 )
{
if ( v7 != 2 )
goto LABEL_2;
v8 = nptr + 1;
v9 = 1;
}
v10 = func0(v8, v9);
return v10 | (v10 << 8) | (unsigned int)(v10 << 16);
}
LABEL_2:
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
{
v3 = 0LL;
v4 = "black";
goto LABEL_5;
}
v3 = 0LL;
v6 = atoi(nptr);
v4 = "black";
if ( v6 <= 7 )
return (unsigned int)dword_2E8[4 * v6];
LABEL_5:
while ( strcmp(v4, nptr) )
{
if ( ++v3 == 8 )
return 0LL;
v4 = (&colors)[2 * v3];
}
return (unsigned int)dword_2E8[4 * (int)v3];
}

original_code:
int clr_get(char *s)
{
 int c = (unsigned char) s[0];
 int i;
 if (c == '#' && strlen(s) == 7)
  return (((ccom(s + 1, 2)) << 16) | ((ccom(s + 3, 2)) << 8) | (ccom(s + 5, 2)));
 if (c == '#' && strlen(s) == 4)
  return (((ccom(s + 1, 1)) << 16) | ((ccom(s + 2, 1)) << 8) | (ccom(s + 3, 1)));
 if (c == '#' && strlen(s) == 3)
  return (((ccom(s + 1, 2)) << 16) | ((ccom(s + 1, 2)) << 8) | (ccom(s + 1, 2)));
 if (c == '#' && strlen(s) == 2)
  return (((ccom(s + 1, 1)) << 16) | ((ccom(s + 1, 1)) << 8) | (ccom(s + 1, 1)));
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) && atoi(s) >= 0 && atoi(s) < (sizeof(colors) / sizeof((colors)[0])))
  return colors[atoi(s)].value;
 for (i = 0; i < (sizeof(colors) / sizeof((colors)[0])); i++)
  if (!strcmp(colors[i].name, s))
   return colors[i].value;
 return 0;
}

canonical_original_code:
int clr_get(char *s)
{
 int c = (unsigned char) s[0];
 int i;
 if (c == '#' && strlen(s) == 7)
  return (((ccom(s + 1, 2)) << 16) | ((ccom(s + 3, 2)) << 8) | (ccom(s + 5, 2)));
 if (c == '#' && strlen(s) == 4)
  return (((ccom(s + 1, 1)) << 16) | ((ccom(s + 2, 1)) << 8) | (ccom(s + 3, 1)));
 if (c == '#' && strlen(s) == 3)
  return (((ccom(s + 1, 2)) << 16) | ((ccom(s + 1, 2)) << 8) | (ccom(s + 1, 2)));
 if (c == '#' && strlen(s) == 2)
  return (((ccom(s + 1, 1)) << 16) | ((ccom(s + 1, 1)) << 8) | (ccom(s + 1, 1)));
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) && atoi(s) >= 0 && atoi(s) < (sizeof(colors) / sizeof((colors)[0])))
  return colors[atoi(s)].value;
 for (i = 0; i < (sizeof(colors) / sizeof((colors)[0])); i++)
  if (!strcmp(colors[i].name, s))
   return colors[i].value;
 return 0;
}


decompiled_code:
__int64 dev_prologue()
{
out("x T %s\n", dev_dev);
out("x res %d %d %d\n", (unsigned int)dev_res, (unsigned int)dev_hor, (unsigned int)dev_ver);
return out("x init\n");
}

canonical_decompiled_code:
__int64 func0()
{
out("x T %s\n", dev_dev);
out("x res %d %d %d\n", (unsigned int)dev_res, (unsigned int)dev_hor, (unsigned int)dev_ver);
return out("x init\n");
}

original_code:
static void dev_prologue(void)
{
 out("x T %s\n", dev_dev);
 out("x res %d %d %d\n", dev_res, dev_hor, dev_ver);
 out("x init\n");
}

canonical_original_code:
static void dev_prologue()
{
 out("x T %s\n", dev_dev);
 out("x res %d %d %d\n", dev_res, dev_hor, dev_ver);
 out("x init\n");
}


decompiled_code:
__int64 dev_epilogue()
{
out("x trailer\n");
return out("x stop\n");
}

canonical_decompiled_code:
__int64 func1()
{
out("x trailer\n");
return out("x stop\n");
}

original_code:
static void dev_epilogue(void)
{
 out("x trailer\n");
 out("x stop\n");
}

canonical_original_code:
static void dev_epilogue()
{
 out("x trailer\n");
 out("x stop\n");
}


decompiled_code:
__int64 __fastcall dev_position(char *s2)
{
unsigned int v1; // er12
const char *v2; // rbx
__int64 v4; // rax

v1 = 1;
v2 = s1;
while ( strcmp(v2, s2) )
{
++v1;
v2 += 32;
if ( v1 == 32 )
{
v4 = 1LL;
while ( 1 )
{
v1 = v4;
if ( !fn_font[v4] )
break;
if ( ++v4 == 32 )
return 0LL;
}
return v1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
unsigned int v1; // er12
const char *v2; // rbx
__int64 v4; // rax

v1 = 1;
v2 = s1;
while ( strcmp(v2, s2) )
{
++v1;
v2 += 32;
if ( v1 == 32 )
{
v4 = 1LL;
while ( 1 )
{
v1 = v4;
if ( !fn_font[v4] )
break;
if ( ++v4 == 32 )
return 0LL;
}
return v1;
}
}
return v1;
}

original_code:
static int dev_position(char *id)
{
 int i;
 for (i = 1; i < 32; i++)
  if (!strcmp(fn_name[i], id))
   return i;
 for (i = 1; i < 32; i++)
  if (!fn_font[i])
   return i;
 return 0;
}

variable_types:
id
char *


decompiled_code:
__int64 dev_close()
{
char *v0; // rbx
__int64 result; // rax

v0 = (char *)fn_font;
result = dev_epilogue();
do
{
if ( *(_QWORD *)v0 )
result = font_close();
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != fn_name );
return result;
}

canonical_decompiled_code:
__int64 func6()
{
char *v0; // rbx
__int64 result; // rax

v0 = (char *)fn_font;
result = func1();
do
{
if ( *(_QWORD *)v0 )
result = font_close();
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != fn_name );
return result;
}

original_code:
void dev_close(void)
{
 int i;
 dev_epilogue();
 for (i = 0; i < 32; i++) {
  if (fn_font[i])
   font_close(fn_font[i]);
  fn_font[i] = ((void *)0);
 }
}

canonical_original_code:
void dev_close()
{
 int i;
 dev_epilogue();
 for (i = 0; i < 32; i++) {
  if (fn_font[i])
   font_close(fn_font[i]);
  fn_font[i] = ((void *)0);
 }
}


decompiled_code:
__int64 __fastcall dev_pos(char *nptr)
{
unsigned int v1; // eax
unsigned int v2; // er12
const char *v4; // rbx

if ( ((*_ctype_b_loc())[*nptr] & 0x800) != 0 )
{
v1 = atoi(nptr);
v2 = v1;
if ( v1 > 0x1F || !fn_font[v1] )
{
v2 = -1;
errmsg("neatroff: bad font position %s\n", nptr);
}
}
else
{
v4 = s1;
v2 = 1;
while ( strcmp(v4, nptr) )
{
++v2;
v4 += 32;
if ( v2 == 32 )
{
v2 = strcmp(fn_name, nptr);
if ( !v2 )
return v2;
return dev_mnt(0, nptr, nptr);
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *nptr)
{
unsigned int v1; // eax
unsigned int v2; // er12
const char *v4; // rbx

if ( ((*_ctype_b_loc())[*nptr] & 0x800) != 0 )
{
v1 = atoi(nptr);
v2 = v1;
if ( v1 > 0x1F || !fn_font[v1] )
{
v2 = -1;
errmsg("neatroff: bad font position %s\n", nptr);
}
}
else
{
v4 = s1;
v2 = 1;
while ( strcmp(v4, nptr) )
{
++v2;
v4 += 32;
if ( v2 == 32 )
{
v2 = strcmp(fn_name, nptr);
if ( !v2 )
return v2;
return func4(0, nptr, nptr);
}
}
}
return v2;
}

original_code:
int dev_pos(char *id)
{
 int i;
 if (((*__ctype_b_loc ())[(int) ((id[0]))] & (unsigned short int) _ISdigit)) {
  int num = atoi(id);
  if (num < 0 || num >= 32 || !fn_font[num]) {
   errmsg("neatroff: bad font position %s\n", id);
   return -1;
  }
  return num;
 }
 for (i = 1; i < 32; i++)
  if (!strcmp(fn_name[i], id))
   return i;
 if (!strcmp(fn_name[0], id))
  return 0;
 return dev_mnt(0, id, id);
}

canonical_original_code:
int dev_pos(char *id)
{
 int i;
 if (((*__ctype_b_loc ())[(int) ((id[0]))] & (unsigned short) _ISdigit)) {
  int num = atoi(id);
  if (num < 0 || num >= 32 || !fn_font[num]) {
   errmsg("neatroff: bad font position %s\n", id);
   return -1;
  }
  return num;
 }
 for (i = 1; i < 32; i++)
  if (!strcmp(fn_name[i], id))
   return i;
 if (!strcmp(fn_name[0], id))
  return 0;
 return dev_mnt(0, id, id);
}

variable_types: num int


decompiled_code:
void __fastcall tr_fspecial(__int64 a1)
{
_QWORD *v1; // rbp
const char *v2; // r12
_QWORD *v3; // rbx

v1 = (_QWORD *)(a1 + 256);
v2 = *(const char **)(a1 + 8);
v3 = (_QWORD *)(a1 + 16);
if ( v2 )
{
do
{
while ( !*v3 || (unsigned int)fspecial_n > 0x1F )
{
if ( ++v3 == v1 )
return;
}
++v3;
snprintf(&fspecial_fn[32 * fspecial_n], 0x20uLL, "%s", v2);
snprintf(&fspecial_sp[32 * fspecial_n], 0x20uLL, "%s", (const char *)*(v3 - 1));
++fspecial_n;
}
while ( v3 != v1 );
}
else
{
fspecial_n = 0;
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
_QWORD *v1; // rbp
const char *v2; // r12
_QWORD *v3; // rbx

v1 = (_QWORD *)(a1 + 256);
v2 = *(const char **)(a1 + 8);
v3 = (_QWORD *)(a1 + 16);
if ( v2 )
{
do
{
while ( !*v3 || (unsigned int)fspecial_n > 0x1F )
{
if ( ++v3 == v1 )
return;
}
++v3;
snprintf(&fspecial_fn[32 * fspecial_n], 0x20uLL, "%s", v2);
snprintf(&fspecial_sp[32 * fspecial_n], 0x20uLL, "%s", (const char *)*(v3 - 1));
++fspecial_n;
}
while ( v3 != v1 );
}
else
{
fspecial_n = 0;
}
}

original_code:
void tr_fspecial(char **args)
{
 char *fn = args[1];
 int i;
 if (!fn) {
  fspecial_n = 0;
  return;
 }
 for (i = 2; i < 32; i++) {
  if (args[i] && fspecial_n < (sizeof(fspecial_fn) / sizeof((fspecial_fn)[0]))) {
   snprintf(fspecial_fn[fspecial_n],
    sizeof(fspecial_fn[fspecial_n]), "%s", fn);
   snprintf(fspecial_sp[fspecial_n],
    sizeof(fspecial_sp[fspecial_n]), "%s", args[i]);
   fspecial_n++;
  }
 }
}

variable_types:
args
char **

variable_types:
fn
char *


original_code:
static void iset_extend(struct iset *iset, int cnt)
{
 iset->set = mextend(iset->set, iset->cnt, cnt, sizeof(iset->set[0]));
 iset->sz = mextend(iset->sz, iset->cnt, cnt, sizeof(iset->sz[0]));
 iset->len = mextend(iset->len, iset->cnt, cnt, sizeof(iset->len[0]));
 iset->cnt = cnt;
}

variable_types: struct iset { int **set; int *sz; int *len; int cnt; } *

variable_types: cnt int


decompiled_code:
_OWORD *iset_make()
{
_OWORD *v0; // r12

v0 = (_OWORD *)xmalloc(32LL);
*v0 = 0LL;
v0[1] = 0LL;
iset_extend((__int64)v0, 1024);
return v0;
}

original_code:
struct iset *iset_make(void)
{
 struct iset *iset = xmalloc(sizeof(*iset));
 memset(iset, 0, sizeof(*iset));
 iset_extend(iset, (1 << 10));
 return iset;
}

canonical_original_code:
struct iset *iset_make()
{
 struct iset *iset = xmalloc(sizeof(*iset));
 memset(iset, 0, sizeof(*iset));
 iset_extend(iset, (1 << 10));
 return iset;
}

return_type: struct iset { int **set; int *sz; int *len; int cnt; } *


decompiled_code:
void __fastcall iset_free(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 6) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2++);
free(v3);
}
while ( *((_DWORD *)ptr + 6) > (int)v2 );
}
free(*(void **)ptr);
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 6) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2++);
free(v3);
}
while ( *((_DWORD *)ptr + 6) > (int)v2 );
}
free(*(void **)ptr);
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void iset_free(struct iset *iset)
{
 int i;
 for (i = 0; i < iset->cnt; i++)
  free(iset->set[i]);
 free(iset->set);
 free(iset->len);
 free(iset->sz);
 free(iset);
}

user_defined_types: struct iset { int **set; int *sz; int *len; int cnt; }


decompiled_code:
__int64 __fastcall iset_get(__int64 a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 24) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 24) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
int *iset_get(struct iset *iset, int key)
{
 return key >= 0 && key < iset->cnt ? iset->set[key] : ((void *)0);
}

variable_types: key int

return_type: int *


decompiled_code:
__int64 __fastcall iset_len(__int64 a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 24) > a2 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * a2);
return result;
}

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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 24) > a2 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * a2);
return result;
}

original_code:
int iset_len(struct iset *iset, int key)
{
 return key >= 0 && key < iset->cnt ? iset->len[key] : 0;
}


original_code:
void iset_put(struct iset *iset, int key, int ent)
{
 if (key < 0 || key >= (1 << 20))
  return;
 if (key >= iset->cnt)
  iset_extend(iset, (((key + 1) + ((1 << 10)) - 1) & ~(((1 << 10)) - 1)));
 if (key >= 0 && key < iset->cnt && iset->len[key] + 1 >= iset->sz[key]) {
  int olen = iset->sz[key];
  int nlen = olen ? olen * 2 : 8;
  void *nset = xmalloc(nlen * sizeof(iset->set[key][0]));
  if (iset->set[key]) {
   memcpy(nset, iset->set[key],
    olen * sizeof(iset->set[key][0]));
   free(iset->set[key]);
  }
  iset->sz[key] = nlen;
  iset->set[key] = nset;
 }
 iset->set[key][iset->len[key]++] = ent;
 iset->set[key][iset->len[key]] = -1;
}

variable_types: ent int

variable_types: olen int

variable_types: nlen int

variable_types:
nset
void *


original_code:
int iset_has(struct iset *iset, int key, int ent)
{
 int i;
 if (key < 0 || key >= iset->cnt || iset->len[key] == 0)
  return 0;
 for (i = 0; i < iset->len[key]; i++)
  if (iset->set[key][i] == ent)
   return 1;
 return 0;
}

variable_types: i int


cmdmac

decompiled_code:
__int64 __fastcall cmdmac(const char *a1, const char *a2)
{
_BOOL4 v2; // er8
__int64 result; // rax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s/%s.tmac", a1, a2);
if ( !xopens(v4) )
snprintf(v4, 0x400uLL, "%s/tmac.%s", a1, a2);
if ( !xopens(v4) )
snprintf(v4, 0x400uLL, "%s/%s", a1, a2);
v2 = xopens(v4);
result = 1LL;
if ( v2 )
{
in_queue(v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
_BOOL4 v2; // er8
__int64 result; // rax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s/%s.tmac", a1, a2);
if ( !func0(v4) )
snprintf(v4, 0x400uLL, "%s/tmac.%s", a1, a2);
if ( !func0(v4) )
snprintf(v4, 0x400uLL, "%s/%s", a1, a2);
v2 = func0(v4);
result = 1LL;
if ( v2 )
{
in_queue(v4);
result = 0LL;
}
return result;
}

original_code:
static int cmdmac(char *dir, char *arg)
{
 char path[1024];
 snprintf(path, sizeof(path), "%s/%s.tmac", dir, arg);
 if (!xopens(path))
  snprintf(path, sizeof(path), "%s/tmac.%s", dir, arg);
 if (!xopens(path))
  snprintf(path, sizeof(path), "%s/%s", dir, arg);
 if (!xopens(path))
  return 1;
 in_queue(path);
 return 0;
}

variable_types:
dir
char *

variable_types:
arg
char *

variable_types:
path
char [1024]


cmddef

original_code:
static void cmddef(char *arg, int *reg, char **def)
{
 char regname[128] = "";
 char *eq = strchr(arg, '=');
 memcpy(regname, arg, eq ? ((128 - 1) < (eq - arg) ? (128 - 1) : (eq - arg)) : 1);
 *reg = map(regname);
 *def = eq ? eq + 1 : arg + 1;
}

variable_types:
reg
int *

variable_types:
def
char **

variable_types:
regname
char [128]

variable_types:
eq
char *


errmsg

decompiled_code:
int errmsg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
void errmsg(char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void errmsg(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
}

variable_types:
fmt
char *


errdie

decompiled_code:
void __fastcall __noreturn errdie(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

original_code:
void errdie(char *msg)
{
 fprintf(stderr, "%s", msg);
 exit(1);
}

variable_types:
msg
char *


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
errdie("neatroff: malloc() failed\n");
return result;
}

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func4("neatroff: malloc() failed\n");
return result;
}

original_code:
void *xmalloc(long len)
{
 void *m = malloc(len);
 if (!m)
  errdie("neatroff: malloc() failed\n");
 return m;
}

variable_types: len long

variable_types:
m
void *

return_type: void *


mextend

decompiled_code:
char *__fastcall mextend(void *ptr, __int64 a2, __int64 a3, int a4)
{
__int64 v4; // r13
size_t v5; // r15
__int64 v6; // rbx
char *v7; // r12

v4 = a4;
v5 = a2 * a4;
v6 = a3 - a2;
v7 = (char *)xmalloc(a3 * a4);
memcpy(v7, ptr, v5);
memset(&v7[v5], 0, v4 * v6);
free(ptr);
return v7;
}

canonical_decompiled_code:
char *__fastcall func6(void *ptr, __int64 a2, __int64 a3, int a4)
{
__int64 v4; // r13
size_t v5; // r15
__int64 v6; // rbx
char *v7; // r12

v4 = a4;
v5 = a2 * a4;
v6 = a3 - a2;
v7 = (char *)func5(a3 * a4);
memcpy(v7, ptr, v5);
memset(&v7[v5], 0, v4 * v6);
free(ptr);
return v7;
}

original_code:
void *mextend(void *old, long oldsz, long newsz, int memsz)
{
 void *new = xmalloc(newsz * memsz);
 memcpy(new, old, oldsz * memsz);
 memset(new + oldsz * memsz, 0, (newsz - oldsz) * memsz);
 free(old);
 return new;
}

variable_types:
old
void *

variable_types: oldsz long

variable_types: newsz long

variable_types: memsz int

variable_types:
new
void *