decompiled_code:
__int64 __fastcall pdf_len(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v5; // ebx
int v6; // er15
unsigned __int8 *v7; // r14
unsigned __int8 *v8; // rbp
int v9; // edx
char v10; // al
_BYTE *i; // rbp
int v12; // er14
unsigned int v13; // ebx
int v14; // ebx
int j; // ebx
int v16; // ebx

result = 0LL;
if ( a3 < a2 )
{
v5 = a3 + pdf_ws(a1, a2, a3);
v6 = *(unsigned __int8 *)(a1 + v5);
if ( strchr("0123456789+-.", v6) )
{
if ( (unsigned int)pdf_type(a1, a2, v5) == 114 )
return (unsigned int)memchr((const void *)(a1 + v5), 82, a2 - v5) - (a3 + (_DWORD)a1) + 1;
if ( a2 > ++v5 )
{
v7 = (unsigned __int8 *)(a1 + v5);
do
{
if ( !strchr("0123456789.", *v7) )
break;
++v5;
++v7;
}
while ( a2 != v5 );
}
}
switch ( v6 )
{
case '(':
if ( a2 > ++v5 )
{
v9 = 1;
do
{
v10 = *(_BYTE *)(a1 + v5);
switch ( v10 )
{
case '(':
++v9;
break;
case ')':
--v9;
break;
case '\\':
++v5;
break;
}
++v5;
}
while ( a2 > v5 && v9 > 0 );
}
break;
case '<':
if ( v5 + 1 < a2 && *(_BYTE *)(a1 + v5 + 1) == 60 )
{
v12 = v5 + 2;
v5 += 4;
if ( a2 > v5 )
{
while ( *(_BYTE *)(a1 + v12) != 62 || *(_BYTE *)(a1 + v12 + 1) != 62 )
{
v13 = pdf_len(a1, (unsigned int)a2, (unsigned int)v12) + v12;
v14 = pdf_len(a1, (unsigned int)a2, v13) + v13;
v12 = v14 + pdf_ws(a1, a2, v14);
v5 = v12 + 2;
if ( v12 + 2 >= a2 )
{
v5 = v12;
return (unsigned int)(v5 - a3);
}
}
if ( a2 <= v5 )
v5 = v12;
}
else
{
v5 = v12;
}
}
else if ( v5 < a2 )
{
for ( i = (_BYTE *)(v5 + a1); *i != 62; ++i )
{
if ( a2 == ++v5 )
return (unsigned int)(v5 - a3);
}
if ( a2 > v5 )
++v5;
}
return (unsigned int)(v5 - a3);
case '/':
if ( a2 > ++v5 )
{
v8 = (unsigned __int8 *)(v5 + a1);
do
{
if ( strchr(asc_9E9, *v8) )
break;
++v5;
++v8;
}
while ( a2 != v5 );
}
return (unsigned int)(v5 - a3);
case '[':
for ( j = v5 + 1; a2 > j; j = pdf_ws(a1, a2, v16) + v16 )
{
if ( *(_BYTE *)(a1 + j) == 93 )
break;
v16 = pdf_len(a1, (unsigned int)a2, (unsigned int)j) + j;
}
v5 = j + 1;
break;
}
return (unsigned int)(v5 - a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v5; // ebx
int v6; // er15
unsigned __int8 *v7; // r14
unsigned __int8 *v8; // rbp
int v9; // edx
char v10; // al
_BYTE *i; // rbp
int v12; // er14
unsigned int v13; // ebx
int v14; // ebx
int j; // ebx
int v16; // ebx

result = 0LL;
if ( a3 < a2 )
{
v5 = a3 + func5(a1, a2, a3);
v6 = *(unsigned __int8 *)(a1 + v5);
if ( strchr("0123456789+-.", v6) )
{
if ( (unsigned int)func6(a1, a2, v5) == 114 )
return (unsigned int)memchr((const void *)(a1 + v5), 82, a2 - v5) - (a3 + (_DWORD)a1) + 1;
if ( a2 > ++v5 )
{
v7 = (unsigned __int8 *)(a1 + v5);
do
{
if ( !strchr("0123456789.", *v7) )
break;
++v5;
++v7;
}
while ( a2 != v5 );
}
}
switch ( v6 )
{
case '(':
if ( a2 > ++v5 )
{
v9 = 1;
do
{
v10 = *(_BYTE *)(a1 + v5);
switch ( v10 )
{
case '(':
++v9;
break;
case ')':
--v9;
break;
case '\\':
++v5;
break;
}
++v5;
}
while ( a2 > v5 && v9 > 0 );
}
break;
case '<':
if ( v5 + 1 < a2 && *(_BYTE *)(a1 + v5 + 1) == 60 )
{
v12 = v5 + 2;
v5 += 4;
if ( a2 > v5 )
{
while ( *(_BYTE *)(a1 + v12) != 62 || *(_BYTE *)(a1 + v12 + 1) != 62 )
{
v13 = func7(a1, (unsigned int)a2, (unsigned int)v12) + v12;
v14 = func7(a1, (unsigned int)a2, v13) + v13;
v12 = v14 + func5(a1, a2, v14);
v5 = v12 + 2;
if ( v12 + 2 >= a2 )
{
v5 = v12;
return (unsigned int)(v5 - a3);
}
}
if ( a2 <= v5 )
v5 = v12;
}
else
{
v5 = v12;
}
}
else if ( v5 < a2 )
{
for ( i = (_BYTE *)(v5 + a1); *i != 62; ++i )
{
if ( a2 == ++v5 )
return (unsigned int)(v5 - a3);
}
if ( a2 > v5 )
++v5;
}
return (unsigned int)(v5 - a3);
case '/':
if ( a2 > ++v5 )
{
v8 = (unsigned __int8 *)(v5 + a1);
do
{
if ( strchr(asc_9E9, *v8) )
break;
++v5;
++v8;
}
while ( a2 != v5 );
}
return (unsigned int)(v5 - a3);
case '[':
for ( j = v5 + 1; a2 > j; j = func5(a1, a2, v16) + v16 )
{
if ( *(_BYTE *)(a1 + j) == 93 )
break;
v16 = func7(a1, (unsigned int)a2, (unsigned int)j) + j;
}
v5 = j + 1;
break;
}
return (unsigned int)(v5 - a3);
}
return result;
}

original_code:
int pdf_len(char *pdf, int len, int pos)
{
 int c;
 int old = pos;
 if (pos >= len)
  return 0;
 pos += pdf_ws(pdf, len, pos);
 c = (unsigned char) pdf[pos];
 if (strchr("0123456789+-.", c)) {
  if (pdf_type(pdf, len, pos) == 'r') {
   char *r = memchr(pdf + pos, 'R', len - pos);
   return r - (pdf + old) + 1;
  }
  pos++;
  while (pos < len && strchr("0123456789.", (unsigned char) pdf[pos]))
   pos++;
 }
 if (c == '(') {
  int depth = 1;
  pos++;
  while (pos < len && depth > 0) {
   if (pdf[pos] == '(')
    depth++;
   if (pdf[pos] == ')')
    depth--;
   if (pdf[pos] == '\\')
    pos++;
   pos++;
  }
 }
 if (c == '<' && pos + 1 < len && pdf[pos + 1] == '<') {
  pos += 2;
  while (pos + 2 < len && (pdf[pos] != '>' || pdf[pos + 1] != '>')) {
   pos += pdf_len(pdf, len, pos);
   pos += pdf_len(pdf, len, pos);
   pos += pdf_ws(pdf, len, pos);
  }
  if (pos + 2 < len)
   pos += 2;
 } else if (c == '<') {
  while (pos < len && pdf[pos] != '>')
   pos++;
  if (pos < len)
   pos++;
 }
 if (c == '/') {
  pos++;
  while (pos < len && !strchr(" \t\r\n\f()<>[]{}/%",
     (unsigned char) pdf[pos]))
   pos++;
 }
 if (c == '[') {
  pos++;
  while (pos < len && pdf[pos] != ']') {
   pos += pdf_len(pdf, len, pos);
   pos += pdf_ws(pdf, len, pos);
  }
  pos++;
 }
 return pos - old;
}

variable_types: c int

variable_types: old int

variable_types:
r
char *

variable_types: depth int


repo: litcave/neatpost

decompiled_code:
__int64 __fastcall pdf_obj(__int64 a1, int a2, int a3, int *a4, int *a5)
{
int v8; // eax

if ( (unsigned int)pdf_type(a1, a2, a3) != 114 )
return 0xFFFFFFFFLL;
*a4 = atoi((const char *)(a1 + a3));
v8 = pdf_len(a1, a2, a3);
*a5 = atoi((const char *)(a1 + a3 + v8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3, int *a4, int *a5)
{
int v8; // eax

if ( (unsigned int)func6(a1, a2, a3) != 114 )
return 0xFFFFFFFFLL;
*a4 = atoi((const char *)(a1 + a3));
v8 = func7(a1, a2, a3);
*a5 = atoi((const char *)(a1 + a3 + v8));
return 0LL;
}

original_code:
int pdf_obj(char *pdf, int len, int pos, int *obj, int *rev)
{
 if (pdf_type(pdf, len, pos) != 'r')
  return -1;
 *obj = atoi(pdf + pos);
 pos += pdf_len(pdf, len, pos);
 *rev = atoi(pdf + pos);
 return 0;
}

variable_types:
pdf
char *

variable_types: len int

variable_types: pos int

variable_types:
obj
int *

variable_types:
rev
int *

return_type: int


decompiled_code:
__int64 __fastcall pdf_dval(__int64 a1, int a2, int a3, const char *a4)
{
int v5; // ebx
__int64 result; // rax
int v7; // ebx
int v8; // ebp
int v9; // ebx

v5 = a3 + 2;
result = 0xFFFFFFFFLL;
if ( a2 > a3 + 4 )
{
do
{
if ( *(_BYTE *)(a1 + v5) == 62 && *(_BYTE *)(a1 + v5 + 1) == 62 )
return 0xFFFFFFFFLL;
v7 = pdf_ws(a1, a2, v5) + v5;
v8 = pdf_len(a1, a2, v7);
if ( v8 == strlen(a4) && (unsigned int)startswith((__int64)a4, a1 + v7) )
return v8 + v7 + (unsigned int)pdf_ws(a1, a2, v8 + v7);
v9 = pdf_len(a1, a2, v8 + v7) + v8 + v7;
v5 = pdf_ws(a1, a2, v9) + v9;
}
while ( v5 + 2 < a2 );
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3, const char *a4)
{
int v5; // ebx
__int64 result; // rax
int v7; // ebx
int v8; // ebp
int v9; // ebx

v5 = a3 + 2;
result = 0xFFFFFFFFLL;
if ( a2 > a3 + 4 )
{
do
{
if ( *(_BYTE *)(a1 + v5) == 62 && *(_BYTE *)(a1 + v5 + 1) == 62 )
return 0xFFFFFFFFLL;
v7 = func5(a1, a2, v5) + v5;
v8 = func7(a1, a2, v7);
if ( v8 == strlen(a4) && (unsigned int)func0((__int64)a4, a1 + v7) )
return v8 + v7 + (unsigned int)func5(a1, a2, v8 + v7);
v9 = func7(a1, a2, v8 + v7) + v8 + v7;
v5 = func5(a1, a2, v9) + v9;
}
while ( v5 + 2 < a2 );
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int pdf_dval(char *pdf, int len, int pos, char *key)
{
 pos += 2;
 while (pos + 2 < len && (pdf[pos] != '>' || pdf[pos + 1] != '>')) {
  pos += pdf_ws(pdf, len, pos);
  if (pdf_len(pdf, len, pos) == strlen(key) && startswith(key, pdf + pos)) {
   pos += pdf_len(pdf, len, pos);
   pos += pdf_ws(pdf, len, pos);
   return pos;
  }
  pos += pdf_len(pdf, len, pos);
  pos += pdf_len(pdf, len, pos);
  pos += pdf_ws(pdf, len, pos);
 }
 return -1;
}

variable_types:
key
char *


decompiled_code:
__int64 __fastcall pdf_dkey(__int64 a1, int a2, int a3, int a4)
{
int v4; // ebx
int v6; // er13
unsigned int v7; // ebx
int v8; // ebx
int v9; // ebx

v4 = a3 + 2;
if ( a2 <= a3 + 4 )
return (unsigned int)-1;
v6 = 0;
do
{
if ( *(_BYTE *)(a1 + v4) == 62 && *(_BYTE *)(a1 + v4 + 1) == 62 )
return (unsigned int)-1;
v7 = pdf_ws(a1, a2, v4) + v4;
if ( a4 == v6 )
return v7;
v8 = pdf_len(a1, a2, v7) + v7;
v9 = pdf_len(a1, a2, v8) + v8;
v4 = pdf_ws(a1, a2, v9) + v9;
++v6;
}
while ( v4 + 2 < a2 );
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, int a3, int a4)
{
int v4; // ebx
int v6; // er13
unsigned int v7; // ebx
int v8; // ebx
int v9; // ebx

v4 = a3 + 2;
if ( a2 <= a3 + 4 )
return (unsigned int)-1;
v6 = 0;
do
{
if ( *(_BYTE *)(a1 + v4) == 62 && *(_BYTE *)(a1 + v4 + 1) == 62 )
return (unsigned int)-1;
v7 = func5(a1, a2, v4) + v4;
if ( a4 == v6 )
return v7;
v8 = func7(a1, a2, v7) + v7;
v9 = func7(a1, a2, v8) + v8;
v4 = func5(a1, a2, v9) + v9;
++v6;
}
while ( v4 + 2 < a2 );
return (unsigned int)-1;
}

original_code:
int pdf_dkey(char *pdf, int len, int pos, int key)
{
 int i = 0;
 pos += 2;
 while (pos + 2 < len && (pdf[pos] != '>' || pdf[pos + 1] != '>')) {
  pos += pdf_ws(pdf, len, pos);
  if (i++ == key)
   return pos;
  pos += pdf_len(pdf, len, pos);
  pos += pdf_len(pdf, len, pos);
  pos += pdf_ws(pdf, len, pos);
 }
 return -1;
}

variable_types: key int

variable_types: i int


decompiled_code:
__int64 __fastcall pdf_lval(__int64 a1, int a2, int a3, int a4)
{
int v4; // ebx
int v6; // er13
int v7; // ebx

v4 = a3 + 1;
if ( a3 + 1 >= a2 )
{
v4 = -1;
}
else
{
v6 = 0;
while ( *(_BYTE *)(a1 + v4) != 93 )
{
if ( a4 == v6 )
return (unsigned int)v4;
v7 = pdf_len(a1, a2, v4) + v4;
v4 = pdf_ws(a1, a2, v7) + v7;
++v6;
if ( a2 <= v4 )
return (unsigned int)-1;
}
v4 = -1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, int a3, int a4)
{
int v4; // ebx
int v6; // er13
int v7; // ebx

v4 = a3 + 1;
if ( a3 + 1 >= a2 )
{
v4 = -1;
}
else
{
v6 = 0;
while ( *(_BYTE *)(a1 + v4) != 93 )
{
if ( a4 == v6 )
return (unsigned int)v4;
v7 = func7(a1, a2, v4) + v4;
v4 = func5(a1, a2, v7) + v7;
++v6;
if ( a2 <= v4 )
return (unsigned int)-1;
}
v4 = -1;
}
return (unsigned int)v4;
}

original_code:
int pdf_lval(char *pdf, int len, int pos, int idx)
{
 int i = 0;
 pos++;
 while (pos < len && pdf[pos] != ']') {
  if (i++ == idx)
   return pos;
  pos += pdf_len(pdf, len, pos);
  pos += pdf_ws(pdf, len, pos);
 }
 return -1;
}

variable_types: idx int


decompiled_code:
__int64 __fastcall pdf_trailer(unsigned __int8 *a1, __int64 a2)
{
int v2; // ebx

v2 = prevline(a1, a2, a2);
while ( !(unsigned int)startswith((__int64)&a1[v2], (__int64)"trailer") )
{
v2 = prevline(a1, (unsigned int)a2, v2);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
}
return nextline((__int64)a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 *a1, __int64 a2)
{
int v2; // ebx

v2 = func2(a1, a2, a2);
while ( !(unsigned int)func0((__int64)&a1[v2], (__int64)"trailer") )
{
v2 = func2(a1, (unsigned int)a2, v2);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
}
return func3((__int64)a1, a2, v2);
}

original_code:
int pdf_trailer(char *pdf, int len)
{
 int pos = prevline(pdf, len, len);
 while (!startswith(pdf + pos, "trailer"))
  if ((pos = prevline(pdf, len, pos)) < 0)
   return -1;
 return nextline(pdf, len, pos);
}


decompiled_code:
__int64 __fastcall pdf_find(unsigned __int8 *a1, __int64 a2, int a3, int a4)
{
int v6; // eax
int v7; // ebx
__int64 result; // rax
int v9; // ebp
int v10; // eax
char *v11; // rax
int v12[2]; // [rsp+0h] [rbp-48h] BYREF
int v13; // [rsp+8h] [rbp-40h]
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v6 = pdf_xref(a1, a2);
if ( v6 < 0 )
return 0xFFFFFFFFLL;
v7 = v6;
result = 0xFFFFFFFFLL;
if ( (int)a2 > v7 )
{
while ( 1 )
{
if ( (unsigned int)_isoc99_sscanf(&a1[v7], "%d %d", v14) != 2 )
return 0xFFFFFFFFLL;
v9 = 0;
if ( v13 > 0 )
break;
LABEL_5:
if ( (int)a2 <= v7 )
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v10 = nextline((__int64)a1, a2, v7);
v7 = v10;
if ( v10 < 0 )
return 0xFFFFFFFFLL;
if ( (unsigned int)_isoc99_sscanf(&a1[v10], "%d %d", v12) != 2 )
return 0xFFFFFFFFLL;
if ( v14[0] + v9 == a3 && v12[1] == a4 )
break;
if ( v13 <= ++v9 )
goto LABEL_5;
}
if ( v12[0] >= (int)a2 || v12[0] < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v11 = strstr((const char *)&a1[v12[0]], "obj");
if ( v11 )
result = (_DWORD)v11 - (_DWORD)a1 + 3 + (unsigned int)pdf_ws((__int64)a1, a2, (int)v11 - (int)a1 + 3);
else
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 *a1, __int64 a2, int a3, int a4)
{
int v6; // eax
int v7; // ebx
__int64 result; // rax
int v9; // ebp
int v10; // eax
char *v11; // rax
int v12[2]; // [rsp+0h] [rbp-48h] BYREF
int v13; // [rsp+8h] [rbp-40h]
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v6 = func4(a1, a2);
if ( v6 < 0 )
return 0xFFFFFFFFLL;
v7 = v6;
result = 0xFFFFFFFFLL;
if ( (int)a2 > v7 )
{
while ( 1 )
{
if ( (unsigned int)_isoc99_sscanf(&a1[v7], "%d %d", v14) != 2 )
return 0xFFFFFFFFLL;
v9 = 0;
if ( v13 > 0 )
break;
LABEL_5:
if ( (int)a2 <= v7 )
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v10 = func3((__int64)a1, a2, v7);
v7 = v10;
if ( v10 < 0 )
return 0xFFFFFFFFLL;
if ( (unsigned int)_isoc99_sscanf(&a1[v10], "%d %d", v12) != 2 )
return 0xFFFFFFFFLL;
if ( v14[0] + v9 == a3 && v12[1] == a4 )
break;
if ( v13 <= ++v9 )
goto LABEL_5;
}
if ( v12[0] >= (int)a2 || v12[0] < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v11 = strstr((const char *)&a1[v12[0]], "obj");
if ( v11 )
result = (_DWORD)v11 - (_DWORD)a1 + 3 + (unsigned int)func5((__int64)a1, a2, (int)v11 - (int)a1 + 3);
else
result = 0xFFFFFFFFLL;
}
}
return result;
}

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 *


decompiled_code:
__int64 __fastcall pdf_ref(unsigned __int8 *a1, unsigned 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, v5, &v4) )
result = 0xFFFFFFFFLL;
else
result = pdf_find(a1, a2, v5[0], v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 *a1, unsigned 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)func8((__int64)a1, a2, a3, v5, &v4) )
result = 0xFFFFFFFFLL;
else
result = func13(a1, a2, v5[0], v4);
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);
}


decompiled_code:
__int64 __fastcall pdf_dval_val(unsigned __int8 *a1, unsigned int a2, int a3, const char *a4)
{
int v4; // eax
unsigned int v5; // ebx
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 )
{
pdf_obj((__int64)a1, a2, v5, v8, &v7);
v5 = pdf_find(a1, a2, v8[0], v7);
}
return v5;
}

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

v4 = func9((__int64)a1, a2, a3, a4);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
if ( (unsigned int)func6((__int64)a1, a2, v4) == 114 )
{
func8((__int64)a1, a2, v5, v8, &v7);
v5 = func13(a1, a2, v8[0], v7);
}
return v5;
}

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


decompiled_code:
__int64 __fastcall pdf_dval_obj(unsigned __int8 *a1, unsigned 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 func16(unsigned __int8 *a1, unsigned int a2, int a3, const char *a4)
{
int v4; // eax
__int64 result; // rax

v4 = func9((__int64)a1, a2, a3, a4);
if ( v4 < 0 )
result = 0xFFFFFFFFLL;
else
result = func14(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);
 }
}

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 *s2)
{
char v1; // bl
unsigned int v2; // eax
__int64 v3; // rbx
__int64 result; // rax
size_t v5; // rax
int v6; // ebx
unsigned int v7; // ebx
int v8; // ebx
unsigned int v9; // ebx

v1 = *s2;
if ( *s2 == 35 )
{
v5 = strlen(s2);
if ( v5 == 7 )
{
v8 = clrcomp(s2 + 1, 2);
v9 = ((unsigned int)clrcomp(s2 + 3, 2) << 8) | (v8 << 16);
return v9 | (unsigned int)clrcomp(s2 + 5, 2);
}
if ( v5 == 4 )
{
v6 = clrcomp(s2 + 1, 1);
v7 = ((unsigned int)clrcomp(s2 + 2, 1) << 8) | (v6 << 16);
return v7 | (unsigned int)clrcomp(s2 + 3, 1);
}
}
if ( ((*_ctype_b_loc())[v1] & 0x800) != 0 )
{
v2 = atoi(s2);
v3 = 0LL;
if ( v2 > 7 )
goto LABEL_10;
result = (unsigned int)dword_268[4 * v2];
}
else
{
v3 = 0LL;
LABEL_10:
while ( strcmp((&colors)[2 * v3], s2) )
{
if ( ++v3 == 8 )
return 0LL;
}
result = (unsigned int)dword_268[4 * (int)v3];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
char v1; // bl
unsigned int v2; // eax
__int64 v3; // rbx
__int64 result; // rax
size_t v5; // rax
int v6; // ebx
unsigned int v7; // ebx
int v8; // ebx
unsigned int v9; // ebx

v1 = *s2;
if ( *s2 == 35 )
{
v5 = strlen(s2);
if ( v5 == 7 )
{
v8 = func0(s2 + 1, 2);
v9 = ((unsigned int)func0(s2 + 3, 2) << 8) | (v8 << 16);
return v9 | (unsigned int)func0(s2 + 5, 2);
}
if ( v5 == 4 )
{
v6 = func0(s2 + 1, 1);
v7 = ((unsigned int)func0(s2 + 2, 1) << 8) | (v6 << 16);
return v7 | (unsigned int)func0(s2 + 3, 1);
}
}
if ( ((*_ctype_b_loc())[v1] & 0x800) != 0 )
{
v2 = atoi(s2);
v3 = 0LL;
if ( v2 > 7 )
goto LABEL_10;
result = (unsigned int)dword_268[4 * v2];
}
else
{
v3 = 0LL;
LABEL_10:
while ( strcmp((&colors)[2 * v3], s2) )
{
if ( ++v3 == 8 )
return 0LL;
}
result = (unsigned int)dword_268[4 * (int)v3];
}
return result;
}

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

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

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

LOBYTE(result) = *(_BYTE *)sstr_s;
if ( !*(_BYTE *)sstr_s )
return 0xFFFFFFFFLL;
++sstr_s;
return (unsigned __int8)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 func2()
{
--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 func3(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)
{
return a1[(int)utf8len(*a1)] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(unsigned __int8 *a1)
{
return a1[(int)func3(*a1)] == 0;
}

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


decompiled_code:
__int64 __fastcall utf8read(_QWORD *a1, __int64 a2)
{
int v3; // eax
int v4; // esi
__int64 v5; // rcx
__int64 i; // rax

v3 = utf8len(*(unsigned __int8 *)*a1);
v4 = v3;
if ( v3 > 0 )
{
v5 = (unsigned int)v3;
for ( i = 0LL; i != v5; ++i )
*(_BYTE *)(a2 + i) = *(_BYTE *)(*a1 + i);
}
*(_BYTE *)(a2 + v4) = 0;
*a1 += v4;
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
int v3; // eax
int v4; // esi
__int64 v5; // rcx
__int64 i; // rax

v3 = func3(*(unsigned __int8 *)*a1);
v4 = v3;
if ( v3 > 0 )
{
v5 = (unsigned int)v3;
for ( i = 0LL; i != v5; ++i )
*(_BYTE *)(a2 + i) = *(_BYTE *)(*a1 + i);
}
*(_BYTE *)(a2 + v4) = 0;
*a1 += v4;
return (unsigned int)v4;
}

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

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:
unsigned int __fastcall charnext_str(char *dest, char *src)
{
int v2; // ebp
unsigned int v3; // er12

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

canonical_decompiled_code:
unsigned int __fastcall func8(char *dest, char *src)
{
int v2; // ebp
unsigned int v3; // er12

v2 = (unsigned __int8)*src;
v3 = c_ec;
if ( v2 == 4 || c_ec == v2 || !src[1] || func4((unsigned __int8 *)src) )
return (unsigned int)strcpy(dest, src);
if ( !src[2] && (unsigned int)func3(v2) == 1 )
return sprintf(dest, "%c(%s", v3, src);
return sprintf(dest, "%cC'%s'", v3, src);
}

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()
{
char v1[32]; // [rsp+0h] [rbp-88h] BYREF
char v2[16]; // [rsp+20h] [rbp-68h] BYREF
char src[32]; // [rsp+30h] [rbp-58h] BYREF
char s[56]; // [rsp+50h] [rbp-38h] BYREF

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

canonical_decompiled_code:
__int64 func9()
{
char v1[32]; // [rsp+0h] [rbp-88h] BYREF
char v2[16]; // [rsp+20h] [rbp-68h] BYREF
char src[32]; // [rsp+30h] [rbp-58h] BYREF
char s[56]; // [rsp+50h] [rbp-38h] BYREF

func10(s);
sbuf_init(v2);
while ( (int)func11(src) >= 0 )
{
func8(v1, src);
sbuf_append(v2, v1);
}
return sbuf_out(v2);
}

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; // ebx

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

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

v5 = func10(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(char **a1, _QWORD *a2)
{
unsigned int v2; // ebp
size_t v4; // rax
char *v5; // rax
char v6; // dl
char *v7; // rdx
char v8; // cl

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

LODWORD(result) = sstr_n++;
result = (int)result;
sstr_bufs[(int)result] = sstr_s;
sstr_s = a1;
return result;
}

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

LODWORD(result) = sstr_n++;
result = (int)result;
sstr_bufs[(int)result] = sstr_s;
sstr_s = a1;
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; // rdx

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

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rdx

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 *a2)
{
unsigned int v2; // ebp

sstr_push(*a1);
v2 = charnext(a2, sstr_next, (__int64)sstr_back);
*a1 = sstr_pop();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 *a1, char *a2)
{
unsigned int v2; // ebp

func13(*a1);
v2 = func10(a2, sstr_next, (__int64)sstr_back);
*a1 = func14();
return v2;
}

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 *a2, const char *a3)
{
unsigned int v4; // ebp

sstr_push(*a1);
v4 = charnext_delim(a2, sstr_next, (__int64)sstr_back, a3);
*a1 = sstr_pop();
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1, char *a2, const char *a3)
{
unsigned int v4; // ebp

func13(*a1);
v4 = func11(a2, sstr_next, (__int64)sstr_back, a3);
*a1 = func14();
return v4;
}

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)
{
unsigned int v2; // edx

v2 = 1;
if ( *(char *)*a1 == a2 )
{
++*a1;
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2)
{
unsigned int v2; // edx

v2 = 1;
if ( *(char *)*a1 == a2 )
{
++*a1;
v2 = 0;
}
return v2;
}

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; // ebx

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

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

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

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

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(__int64 *a1)
{
unsigned int v1; // ebx

if ( (unsigned int)evalisnum((unsigned __int8 **)a1) )
return (unsigned int)evalnum(a1);
v1 = 0;
if ( !(unsigned int)evaljmp(a1, 45) )
return (unsigned int)-(int)evalatom(a1);
if ( !(unsigned int)evaljmp(a1, 43) )
return (unsigned int)evalatom(a1);
if ( !(unsigned int)evaljmp(a1, 124) )
return (unsigned int)(abspos + evalatom(a1));
if ( !(unsigned int)evaljmp(a1, 40) )
{
v1 = evalexpr(a1);
evaljmp(a1, 41);
}
return v1;
}

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

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

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(__int64 *a1)
{
int v1; // ebp
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // er12

v1 = evalatom(a1);
while ( *(_BYTE *)*a1 )
{
if ( (unsigned int)evaljmp(a1, 43) )
{
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, 61) )
v1 = (int)evalatom(a1) > v1;
else
v1 = (int)evalatom(a1) >= v1;
continue;
}
if ( !(unsigned int)evaljmp(a1, 62) )
{
if ( (unsigned int)evaljmp(a1, 61) )
v1 = (int)evalatom(a1) < v1;
else
v1 = (int)evalatom(a1) <= v1;
continue;
}
v5 = evaljmp(a1, 61);
if ( ((unsigned int)evaljmp(a1, 61) == 0) + (v5 == 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 )
{
v1 = 1;
continue;
}
LABEL_27:
v1 = (int)evalatom(a1) > 0;
continue;
}
if ( v1 > 0 )
goto LABEL_27;
v1 = 0;
}
}
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);
}
}
else
{
v1 += evalatom(a1);
}
}
return (unsigned int)v1;
}

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

v1 = func5(a1);
while ( *(_BYTE *)*a1 )
{
if ( (unsigned int)func0(a1, 43) )
{
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, 61) )
v1 = (int)func5(a1) > v1;
else
v1 = (int)func5(a1) >= v1;
continue;
}
if ( !(unsigned int)func0(a1, 62) )
{
if ( (unsigned int)func0(a1, 61) )
v1 = (int)func5(a1) < v1;
else
v1 = (int)func5(a1) <= v1;
continue;
}
v5 = func0(a1, 61);
if ( ((unsigned int)func0(a1, 61) == 0) + (v5 == 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 )
{
v1 = 1;
continue;
}
LABEL_27:
v1 = (int)func5(a1) > 0;
continue;
}
if ( v1 > 0 )
goto LABEL_27;
v1 = 0;
}
}
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);
}
}
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(__int64 *a1, int a2)
{
__int64 v4; // rdi
int v5; // ebp

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, int a2)
{
__int64 v4; // rdi
int v5; // ebp

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

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(char *a1, int a2, int a3)
{
char v5; // dl
__int64 result; // rax
__int64 v7[2]; // [rsp+8h] [rbp-10h] BYREF

v7[0] = (__int64)a1;
v5 = *a1;
if ( ((*a1 - 43) & 0xFD) != 0 )
return eval_up(v7, a3);
v7[0] = (__int64)(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(char *a1, int a2, int a3)
{
char v5; // dl
__int64 result; // rax
__int64 v7[2]; // [rsp+8h] [rbp-10h] BYREF

v7[0] = (__int64)a1;
v5 = *a1;
if ( ((*a1 - 43) & 0xFD) != 0 )
return func7(v7, a3);
v7[0] = (__int64)(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(__int64 a1, int a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 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(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
return sbuf_extend((__int64)a1, 512);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 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 v3; // ebp
int v4; // esi
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, const char *a2)
{
int v3; // ebp
int v4; // esi
void *result; // rax

v3 = strlen(a2);
v4 = *(_DWORD *)(a1 + 12) + v3 + 1;
if ( v4 >= *(_DWORD *)(a1 + 8) )
func0(a1, v4);
result = memcpy((void *)(*(_QWORD *)a1 + *(int *)(a1 + 12)), a2, v3);
*(_DWORD *)(a1 + 12) += v3;
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;
*a1 = 0LL;
a1[1] = 0LL;
return result;
}

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

result = *a1;
*a1 = 0LL;
a1[1] = 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; // r12
__int64 i; // rbx
const char *v4; // rdi
size_t v5; // rbp
void *v6; // rax

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

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

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

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:
char *__fastcall in_push(char *src, __int64 a2)
{
__int64 v2; // rbx
int v3; // er12
char *v4; // r13
char *v5; // rax
char *result; // rax

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

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

v2 = a2;
v3 = strlen(src);
func0();
v4 = buf;
*((_QWORD *)v4 + 129) = xmalloc(v3 + 1);
v5 = buf;
*((_DWORD *)buf + 296) = v3;
strcpy(*((char **)v5 + 129), src);
if ( a2 )
v2 = func1(a2);
result = buf;
*((_QWORD *)buf + 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:
_BOOL8 in_nextfile()
{
char *v0; // rbx
int v1; // edi

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

canonical_decompiled_code:
_BOOL8 func6()
{
char *v0; // rbx
int v1; // edi

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

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(const char *a1)
{
int v2; // edi
int result; // eax

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

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
int v2; // edi
int result; // eax

v2 = nfiles;
if ( nfiles <= 15 )
{
if ( !a1 )
a1 = (const char *)&unk_46CD;
++nfiles;
result = snprintf(&files[1024 * (__int64)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;
}


decompiled_code:
int in_next()
{
int v0; // edx
int result; // eax
char *v2; // rax
int v3; // edx
__int64 v4; // rcx
int v5; // edx

while ( buf || !in_nextfile() )
{
v2 = buf;
v3 = *((_DWORD *)buf + 294);
if ( v3 )
{
v0 = v3 - 1;
*((_DWORD *)buf + 294) = v0;
return *(_DWORD *)&v2[4 * v0 + 1048];
}
if ( *((_QWORD *)buf + 129) )
{
if ( *((_DWORD *)buf + 295) < *((_DWORD *)buf + 296) )
goto LABEL_10;
}
else
{
result = getc(*((FILE **)buf + 128));
if ( result >= 0 )
{
if ( result == 10 )
++*((_DWORD *)buf + 297);
return result;
}
}
in_pop();
}
v2 = buf;
if ( buf )
{
LABEL_10:
v4 = *((_QWORD *)v2 + 129);
v5 = *((_DWORD *)v2 + 295);
*((_DWORD *)v2 + 295) = v5 + 1;
return *(unsigned __int8 *)(v4 + v5);
}
return -1;
}

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 )
return 0xFFFFFFFFLL;
v0 = *((_DWORD *)buf + 294);
if ( v0 )
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 )
return 0xFFFFFFFFLL;
v0 = *((_DWORD *)buf + 294);
if ( v0 )
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;
}


cwid

decompiled_code:
__int64 __fastcall cwid(__int64 a1)
{
unsigned int v1; // ebx
_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; // ebx
_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:
c
char *

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, _BYTE *a3)
{
int v4; // er12
int v5; // er14
unsigned int v6; // ebp
int v7; // ebp
int v9; // [rsp+4h] [rbp-44h]
unsigned int v10; // [rsp+8h] [rbp-40h]

v4 = dev_res * *(_DWORD *)nreg(115LL) / 72;
v10 = cwid((__int64)a3);
if ( a2 < 0 )
{
wb_vmov(a1, (unsigned int)a2);
v9 = -a2;
if ( !v4 )
{
v5 = 0;
v6 = -a2;
goto LABEL_13;
}
}
else
{
if ( !v4 )
{
v5 = 0;
v6 = a2;
v9 = a2;
goto LABEL_4;
}
v9 = a2;
}
v6 = v9 % v4;
v5 = v9 / v4;
if ( v4 <= v9 )
{
LABEL_4:
if ( !v6 )
{
LABEL_5:
v7 = 0;
if ( v5 <= 0 )
goto LABEL_8;
do
{
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v10);
++v7;
}
while ( v7 < v5 );
if ( v4 <= v9 )
goto LABEL_8;
goto LABEL_18;
}
LABEL_13:
if ( vchar(a3) )
{
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v10);
wb_vmov(a1, v6 - v4);
}
else
{
wb_vmov(a1, v6);
}
goto LABEL_5;
}
wb_vmov(a1, (unsigned int)(v9 / 2 - v4));
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v10);
LABEL_18:
wb_vmov(a1, (unsigned int)(v9 / 2));
LABEL_8:
if ( a2 < 0 )
wb_vmov(a1, (unsigned int)-v9);
return wb_hmov(a1, v10);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, _BYTE *a3)
{
int v4; // er12
int v5; // er14
unsigned int v6; // ebp
int v7; // ebp
int v9; // [rsp+4h] [rbp-44h]
unsigned int v10; // [rsp+8h] [rbp-40h]

v4 = dev_res * *(_DWORD *)nreg(115LL) / 72;
v10 = func2((__int64)a3);
if ( a2 < 0 )
{
wb_vmov(a1, (unsigned int)a2);
v9 = -a2;
if ( !v4 )
{
v5 = 0;
v6 = -a2;
goto LABEL_13;
}
}
else
{
if ( !v4 )
{
v5 = 0;
v6 = a2;
v9 = a2;
goto LABEL_4;
}
v9 = a2;
}
v6 = v9 % v4;
v5 = v9 / v4;
if ( v4 <= v9 )
{
LABEL_4:
if ( !v6 )
{
LABEL_5:
v7 = 0;
if ( v5 <= 0 )
goto LABEL_8;
do
{
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v10);
++v7;
}
while ( v7 < v5 );
if ( v4 <= v9 )
goto LABEL_8;
goto LABEL_18;
}
LABEL_13:
if ( func1(a3) )
{
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v10);
wb_vmov(a1, v6 - v4);
}
else
{
wb_vmov(a1, v6);
}
goto LABEL_5;
}
wb_vmov(a1, (unsigned int)(v9 / 2 - v4));
wb_vmov(a1, (unsigned int)v4);
wb_putexpand(a1, a3);
wb_hmov(a1, -v10);
LABEL_18:
wb_vmov(a1, (unsigned int)(v9 / 2));
LABEL_8:
if ( a2 < 0 )
wb_vmov(a1, (unsigned int)-v9);
return wb_hmov(a1, v10);
}

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 v3; // er15
__int64 result; // rax
int v6; // er14
int v7; // er13
unsigned int v8; // ebx
int v9; // ebx

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

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

v3 = a2;
result = func2((__int64)a3);
v6 = result;
if ( a2 < 0 )
{
wb_hmov(a1, (unsigned int)a2);
v3 = -a2;
if ( !v6 )
{
v7 = 0;
v8 = -a2;
LABEL_14:
if ( func0(a3) )
{
wb_putexpand(a1, a3);
result = wb_hmov(a1, v8 - v6);
}
else
{
result = wb_hmov(a1, v8);
}
goto LABEL_5;
}
}
else if ( !(_DWORD)result )
{
v7 = 0;
v8 = a2;
goto LABEL_4;
}
result = (unsigned int)(v3 / v6);
v8 = v3 % v6;
v7 = v3 / v6;
if ( v6 > v3 )
{
wb_hmov(a1, (unsigned int)((v3 - v6) / 2));
wb_putexpand(a1, a3);
return wb_hmov(a1, (unsigned int)(~(v6 - v3) / 2));
}
LABEL_4:
if ( v8 )
goto LABEL_14;
LABEL_5:
v9 = 0;
if ( v7 > 0 )
{
do
{
result = wb_putexpand(a1, a3);
++v9;
}
while ( v9 < v7 );
if ( v6 > v3 )
return wb_hmov(a1, (unsigned int)(~(v6 - v3) / 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:
char *__fastcall ren_hlcmd(__int64 a1, char *a2)
{
int v2; // ebx
char *result; // rax
char *v4; // [rsp+8h] [rbp-40h] BYREF
char v5[56]; // [rsp+10h] [rbp-38h] BYREF

v4 = a2;
v2 = eval_up(&v4);
if ( *v4 == c_ec && v4[1] == 38 )
v4 += 2;
result = v4;
if ( !*v4 || (result = (char *)charread(&v4, v5), (int)result < 0) )
strcpy(v5, "ru");
if ( v2 )
result = (char *)ren_hline(a1, v2, v5);
return result;
}

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

v4 = a2;
v2 = eval_up(&v4);
if ( *v4 == c_ec && v4[1] == 38 )
v4 += 2;
result = v4;
if ( !*v4 || (result = (char *)charread(&v4, v5), (int)result < 0) )
strcpy(v5, "ru");
if ( v2 )
result = (char *)func6(a1, v2, v5);
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:
char *__fastcall ren_vlcmd(__int64 a1, char *a2)
{
int v2; // ebx
char *result; // rax
char *v4; // [rsp+8h] [rbp-40h] BYREF
char v5[56]; // [rsp+10h] [rbp-38h] BYREF

v4 = a2;
v2 = eval_up(&v4);
if ( *v4 == c_ec && v4[1] == 38 )
v4 += 2;
result = v4;
if ( !*v4 || (result = (char *)charread(&v4, v5), (int)result < 0) )
strcpy(v5, "br");
if ( v2 )
result = (char *)ren_vline(a1, v2, v5);
return result;
}

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

v4 = a2;
v2 = eval_up(&v4);
if ( *v4 == c_ec && v4[1] == 38 )
v4 += 2;
result = v4;
if ( !*v4 || (result = (char *)charread(&v4, v5), (int)result < 0) )
strcpy(v5, "br");
if ( v2 )
result = (char *)func5(a1, v2, v5);
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; // ebp
__int64 result; // rax
unsigned int v4; // er12
unsigned int v5; // eax
char *v6; // rcx
int i; // edx
char *v8; // rax
char *v9; // [rsp+8h] [rbp-70h] BYREF
char v10[72]; // [rsp+10h] [rbp-68h] BYREF
unsigned int v11; // [rsp+58h] [rbp-20h] BYREF
unsigned int v12[7]; // [rsp+5Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char *a2)
{
unsigned int v2; // ebp
__int64 result; // rax
unsigned int v4; // er12
unsigned int v5; // eax
char *v6; // rcx
int i; // edx
char *v8; // rax
char *v9; // [rsp+8h] [rbp-70h] BYREF
char v10[72]; // [rsp+10h] [rbp-68h] BYREF
unsigned int v11; // [rsp+58h] [rbp-20h] BYREF
unsigned int v12[7]; // [rsp+5Ch] [rbp-1Ch] BYREF

v9 = a2 + 1;
v2 = *a2;
result = (unsigned int)(tolower(v2) - 97);
switch ( (int)result )
{
case 0:
v12[0] = func3(&v9);
v11 = func3(&v9);
v4 = func3(&v9);
v5 = func3(&v9);
result = wb_drawa(a1, v2, v12[0], v11, v4, v5);
break;
case 2:
v12[0] = func3(&v9);
result = wb_drawc(a1, v2, v12[0]);
break;
case 4:
v12[0] = func3(&v9);
v11 = func3(&v9);
result = wb_drawe(a1, v2, v12[0], v11);
break;
case 11:
v12[0] = func3(&v9);
v11 = func3(&v9);
result = wb_drawl(a1, v2, v12[0], v11);
break;
case 15:
case 29:
wb_drawxbeg(a1, v2);
while ( *v9 )
{
if ( func4(&v9, 109LL, v12) || func4(&v9, 118LL, &v11) )
{
v6 = v10;
for ( i = 0; i != 63; ++i )
{
v8 = v9;
if ( (*v9 & 0xDF) == 0 )
break;
++v9;
*v6++ = *v8;
}
v10[i] = 0;
wb_drawxcmd(a1, v10, i, v6);
}
else
{
wb_drawxdot(a1, v12[0], v11);
}
}
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
unsigned int v11; // er13
_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);
v7 = wb_wid(v14);
wb_hmov(v14, (unsigned int)-v7);
v8 = (_DWORD *)nreg(115LL);
wb_vmov(v14, (unsigned int)(dev_res * *v8 / 72));
++v6;
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) / 2;
v12 = (_DWORD *)nreg(115LL);
wb_vmov(a1, v11 + dev_res * *v12 / 72);
wb_cat(a1, v14);
wb_done(v14);
wb_vmov(a1, v11);
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
unsigned int v11; // er13
_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);
v7 = wb_wid(v14);
wb_hmov(v14, (unsigned int)-v7);
v8 = (_DWORD *)nreg(115LL);
wb_vmov(v14, (unsigned int)(dev_res * *v8 / 72));
++v6;
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) / 2;
v12 = (_DWORD *)nreg(115LL);
wb_vmov(a1, v11 + dev_res * *v12 / 72);
wb_cat(a1, v14);
wb_done(v14);
wb_vmov(a1, v11);
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; // ebp
int v6; // eax
unsigned int v7; // ebx
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(v12);
v3 = (unsigned __int64)v11;
wb_init(v11);
v4 = sstr_next();
if ( v4 < 0 )
{
v5 = 0;
}
else
{
v3 = (unsigned int)v4;
v5 = 0;
do
{
sstr_back(v3);
ren_char(v11, &sstr_next, &sstr_back);
v6 = wb_wid(v11);
if ( v5 < v6 )
v5 = v6;
v7 = v6 / -2;
wb_hmov(v12, (unsigned int)(v6 / -2));
wb_cat(v12, v11);
wb_hmov(v12, v7);
v8 = sstr_next();
v3 = (unsigned int)v8;
}
while ( v8 >= 0 );
}
sstr_pop(v3);
v9 = v5 / 2;
wb_hmov(a1, v9);
wb_cat(a1, v12);
wb_hmov(a1, v9);
wb_done(v11);
return wb_done(v12);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // rdi
int v4; // eax
int v5; // ebp
int v6; // eax
unsigned int v7; // ebx
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(v12);
v3 = (unsigned __int64)v11;
wb_init(v11);
v4 = sstr_next();
if ( v4 < 0 )
{
v5 = 0;
}
else
{
v3 = (unsigned int)v4;
v5 = 0;
do
{
sstr_back(v3);
ren_char(v11, &sstr_next, &sstr_back);
v6 = wb_wid(v11);
if ( v5 < v6 )
v5 = v6;
v7 = v6 / -2;
wb_hmov(v12, (unsigned int)(v6 / -2));
wb_cat(v12, v11);
wb_hmov(v12, v7);
v8 = sstr_next();
v3 = (unsigned int)v8;
}
while ( v8 >= 0 );
}
sstr_pop(v3);
v9 = v5 / 2;
wb_hmov(a1, v9);
wb_cat(a1, v12);
wb_hmov(a1, v9);
wb_done(v11);
return wb_done(v12);
}

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; // ebp
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; // ebp
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 *s2)
{
unsigned __int8 v1; // bl
unsigned int v2; // eax
__int64 v3; // rbx
__int64 result; // rax
size_t v5; // rax
int v6; // eax
int v7; // ebx
unsigned int v8; // ebx
int v9; // ebx
unsigned int v10; // ebx
int v11; // eax

v1 = *s2;
if ( *s2 == 35 )
{
v5 = strlen(s2);
switch ( v5 )
{
case 7uLL:
v7 = ccom(s2 + 1, 2);
v8 = ((unsigned int)ccom(s2 + 3, 2) << 8) | (v7 << 16);
return v8 | (unsigned int)ccom(s2 + 5, 2);
case 4uLL:
v9 = ccom(s2 + 1, 1);
v10 = ((unsigned int)ccom(s2 + 2, 1) << 8) | (v9 << 16);
return v10 | (unsigned int)ccom(s2 + 3, 1);
case 3uLL:
v11 = ccom(s2 + 1, 2);
return v11 | (v11 << 8) | (unsigned int)(v11 << 16);
case 2uLL:
v6 = ccom(s2 + 1, 1);
return v6 | (v6 << 8) | (unsigned int)(v6 << 16);
}
}
if ( ((*_ctype_b_loc())[v1] & 0x800) != 0 )
{
v2 = atoi(s2);
v3 = 0LL;
if ( v2 > 7 )
goto LABEL_14;
result = (unsigned int)dword_2A8[4 * v2];
}
else
{
v3 = 0LL;
LABEL_14:
while ( strcmp((&colors)[2 * v3], s2) )
{
if ( ++v3 == 8 )
return 0LL;
}
result = (unsigned int)dword_2A8[4 * (int)v3];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
unsigned __int8 v1; // bl
unsigned int v2; // eax
__int64 v3; // rbx
__int64 result; // rax
size_t v5; // rax
int v6; // eax
int v7; // ebx
unsigned int v8; // ebx
int v9; // ebx
unsigned int v10; // ebx
int v11; // eax

v1 = *s2;
if ( *s2 == 35 )
{
v5 = strlen(s2);
switch ( v5 )
{
case 7uLL:
v7 = func0(s2 + 1, 2);
v8 = ((unsigned int)func0(s2 + 3, 2) << 8) | (v7 << 16);
return v8 | (unsigned int)func0(s2 + 5, 2);
case 4uLL:
v9 = func0(s2 + 1, 1);
v10 = ((unsigned int)func0(s2 + 2, 1) << 8) | (v9 << 16);
return v10 | (unsigned int)func0(s2 + 3, 1);
case 3uLL:
v11 = func0(s2 + 1, 2);
return v11 | (v11 << 8) | (unsigned int)(v11 << 16);
case 2uLL:
v6 = func0(s2 + 1, 1);
return v6 | (v6 << 8) | (unsigned int)(v6 << 16);
}
}
if ( ((*_ctype_b_loc())[v1] & 0x800) != 0 )
{
v2 = atoi(s2);
v3 = 0LL;
if ( v2 > 7 )
goto LABEL_14;
result = (unsigned int)dword_2A8[4 * v2];
}
else
{
v3 = 0LL;
LABEL_14:
while ( strcmp((&colors)[2 * v3], s2) )
{
if ( ++v3 == 8 )
return 0LL;
}
result = (unsigned int)dword_2A8[4 * (int)v3];
}
return result;
}

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)
{
const char *v1; // rbp
unsigned int v2; // ebx
__int64 v3; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
const char *v1; // rbp
unsigned int v2; // ebx
__int64 v3; // rax

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

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()
{
__int64 result; // rax
char *v1; // rbx

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

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

result = func1();
v1 = (char *)fn_font;
do
{
if ( *(_QWORD *)v1 )
result = font_close();
*(_QWORD *)v1 = 0LL;
v1 += 8;
}
while ( v1 != 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; // ebx
const char *v4; // rbp

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

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

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

v1 = a1[1];
v2 = a1 + 2;
if ( v1 )
{
do
{
if ( *v2 )
{
if ( (unsigned int)fspecial_n <= 0x1F )
{
snprintf(&fspecial_fn[32 * fspecial_n], 0x20uLL, "%s", v1);
snprintf(&fspecial_sp[32 * fspecial_n], 0x20uLL, "%s", *v2);
++fspecial_n;
}
}
++v2;
}
while ( v2 != a1 + 32 );
}
else
{
fspecial_n = 0;
}
}

canonical_decompiled_code:
void __fastcall func12(const char **a1)
{
const char *v1; // r13
const char **v2; // rbx

v1 = a1[1];
v2 = a1 + 2;
if ( v1 )
{
do
{
if ( *v2 )
{
if ( (unsigned int)fspecial_n <= 0x1F )
{
snprintf(&fspecial_fn[32 * fspecial_n], 0x20uLL, "%s", v1);
snprintf(&fspecial_sp[32 * fspecial_n], 0x20uLL, "%s", *v2);
++fspecial_n;
}
}
++v2;
}
while ( v2 != a1 + 32 );
}
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:
_QWORD *iset_make()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)xmalloc(32LL);
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = 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 v1; // rbx

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

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

if ( *((int *)ptr + 6) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 6) > (int)v1 );
}
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 *


decompiled_code:
__int64 __fastcall iset_has(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // ecx
_DWORD *v5; // rax
__int64 v6; // rcx

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 24) > a2 )
{
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * a2);
if ( v4 <= 0 )
{
result = 0LL;
}
else
{
v5 = *(_DWORD **)(*(_QWORD *)a1 + 8LL * a2);
v6 = (__int64)&v5[v4 - 1 + 1];
while ( *v5 != a3 )
{
if ( ++v5 == (_DWORD *)v6 )
return 0LL;
}
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // ecx
_DWORD *v5; // rax
__int64 v6; // rcx

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 24) > a2 )
{
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * a2);
if ( v4 <= 0 )
{
result = 0LL;
}
else
{
v5 = *(_DWORD **)(*(_QWORD *)a1 + 8LL * a2);
v6 = (__int64)&v5[v4 - 1 + 1];
while ( *v5 != a3 )
{
if ( ++v5 == (_DWORD *)v6 )
return 0LL;
}
result = 1LL;
}
}
return result;
}

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