CfgNext

decompiled_code:
__int64 __fastcall CfgNext(int a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rdx
char **v4; // rdi
__int64 result; // rax

v2 = 4LL * a1;
v3 = qword_8E8[v2];
v4 = &(&configinfo)[v2];
if ( !a2 )
return v3;
result = a2 + 8;
if ( a2 + 8 > (unsigned __int64)(v3 + 8LL * (_QWORD)v4[2] - 8) )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rdx
char **v4; // rdi
__int64 result; // rax

v2 = 4LL * a1;
v3 = qword_8E8[v2];
v4 = &(&configinfo)[v2];
if ( !a2 )
return v3;
result = a2 + 8;
if ( a2 + 8 > (unsigned __int64)(v3 + 8LL * (_QWORD)v4[2] - 8) )
result = 0LL;
return result;
}

original_code:
ConfigEntryT **
CfgNext(int WhichCfg, ConfigEntryT ** last)
{
 if (last == ((void *)0)) {
  return (ConfigEntryT **) configinfo[WhichCfg].config_info;
 }
 last++;
 if (last
     > (ConfigEntryT **) configinfo[WhichCfg].config_info
     + configinfo[WhichCfg].config_info_size
     - 1
  ) {
  return ((void *)0);
 }
 return last;
}

canonical_original_code:
struct ConfigEntryT **CfgNext(int WhichCfg, struct ConfigEntryT **last)
{
 if (last == ((void *)0)) {
  return (struct ConfigEntryT **) configinfo[WhichCfg].config_info;
 }
 last++;
 if (last
     > (struct ConfigEntryT **) configinfo[WhichCfg].config_info
     + configinfo[WhichCfg].config_info_size
     - 1
  ) {
  return ((void *)0);
 }
 return last;
}

variable_types:
last
struct ConfigEntryT **


ConvertBabelName

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

result = SearchRtfCmd(a1, 4u);
if ( result )
result = (void *)ConvertString(result);
return result;
}

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

result = func3(a1, 4u);
if ( result )
result = (void *)ConvertString(result);
return result;
}

original_code:
void
ConvertBabelName(char *name)
{
 char *s = SearchRtfCmd(name, 4);
 if (s != ((void *)0))
  ConvertString(s);
}

variable_types:
name
char *

variable_types:
s
char *

return_type: void


IgnoreVar

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

do
result = getTexChar();
while ( (result & 0xDF) != 0 && (_BYTE)result != 10 );
return result;
}

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

do
result = getTexChar();
while ( (result & 0xDF) != 0 && (_BYTE)result != 10 );
return result;
}

original_code:
void
IgnoreVar(void)
{
 char c;
 while ((c = getTexChar()) && c != '\n' && c != ' '){}
}

canonical_original_code:
void IgnoreVar()
{
 char c;
 while ((c = getTexChar()) && c != '\n' && c != ' '){}
}

variable_types: c char


IgnoreCmd

decompiled_code:
__int64 IgnoreCmd()
{
char v0; // al
char v1; // bl

while ( 1 )
{
v0 = getTexChar();
if ( !v0 )
break;
if ( v0 == 92 )
goto LABEL_6;
}
v1 = getTexChar();
if ( !v1 )
return ungetTexChar(0LL);
while ( ((*_ctype_b_loc())[v1] & 0x400) == 0 )
{
LABEL_6:
v1 = getTexChar();
if ( !v1 )
return ungetTexChar(0LL);
}
return ungetTexChar((unsigned int)v1);
}

canonical_decompiled_code:
__int64 func1()
{
char v0; // al
char v1; // bl

while ( 1 )
{
v0 = getTexChar();
if ( !v0 )
break;
if ( v0 == 92 )
goto LABEL_6;
}
v1 = getTexChar();
if ( !v1 )
return ungetTexChar(0LL);
while ( ((*_ctype_b_loc())[v1] & 0x400) == 0 )
{
LABEL_6:
v1 = getTexChar();
if ( !v1 )
return ungetTexChar(0LL);
}
return ungetTexChar((unsigned int)v1);
}

original_code:
void
IgnoreCmd(void)
{
 char c;
 while ((c = getTexChar()) && c != '\\'){}
 while ((c = getTexChar()) && !((*__ctype_b_loc ())[(int) (((int)c))] & (unsigned short int) _ISalpha)){}
 ungetTexChar(c);
}

canonical_original_code:
void IgnoreCmd()
{
 char c;
 while ((c = getTexChar()) && c != '\\'){}
 while ((c = getTexChar()) && !((*__ctype_b_loc ())[(int) (((int)c))] & (unsigned short) _ISalpha)){}
 ungetTexChar(c);
}


decompiled_code:
__int64 __fastcall Ignore_Environment(const char *a1)
{
unsigned int v1; // ebp
void *v2; // r12
char v4[136]; // [rsp+0h] [rbp-88h] BYREF

diagnostics(4LL, "Entering IgnoreEnvironment <%s>", a1);
snprintf(v4, 0x64uLL, "\\%s%s%s", "end{", a1, "}");
v1 = TexFontNumber("Typewriter");
CmdEndParagraph(0LL);
CmdStartParagraph(1LL);
fprintRTF("\\qc [Sorry. Ignored ");
fprintRTF("{\\plain\\f%d\\\\begin\\{%s\\} ... \\\\end\\{%s\\}}]", v1, a1, a1);
CmdEndParagraph(0LL);
CmdIndent(2LL);
v2 = (void *)getTexUntil(v4, 0LL);
ConvertString(v4);
free(v2);
return diagnostics(4LL, "Exiting IgnoreEnvironment");
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // ebp
void *v2; // r12
char v4[136]; // [rsp+0h] [rbp-88h] BYREF

diagnostics(4LL, "Entering IgnoreEnvironment <%s>", a1);
snprintf(v4, 0x64uLL, "\\%s%s%s", "end{", a1, "}");
v1 = TexFontNumber("Typewriter");
CmdEndParagraph(0LL);
CmdStartParagraph(1LL);
fprintRTF("\\qc [Sorry. Ignored ");
fprintRTF("{\\plain\\f%d\\\\begin\\{%s\\} ... \\\\end\\{%s\\}}]", v1, a1, a1);
CmdEndParagraph(0LL);
CmdIndent(2LL);
v2 = (void *)getTexUntil(v4, 0LL);
ConvertString(v4);
free(v2);
return diagnostics(4LL, "Exiting IgnoreEnvironment");
}

original_code:
void
Ignore_Environment(char *cCommand)
{
 char unknown_environment[100];
 char *buffer;
 int font;
 diagnostics(4, "Entering IgnoreEnvironment <%s>", cCommand);
 snprintf(unknown_environment, 100, "\\%s%s%s", "end{", cCommand, "}");
 font = TexFontNumber("Typewriter");
 CmdEndParagraph(0);
 CmdStartParagraph(1);
 fprintRTF("\\qc [Sorry. Ignored ");
 fprintRTF("{\\plain\\f%d\\\\begin\\{%s\\} ... \\\\end\\{%s\\}}]", font, cCommand, cCommand);
 CmdEndParagraph(0);
 CmdIndent(2);
 buffer = getTexUntil(unknown_environment,0);
 ConvertString(unknown_environment);
 free(buffer);
 diagnostics(4, "Exiting IgnoreEnvironment");
}

variable_types:
cCommand
char *

variable_types:
buffer
char *

variable_types: font int


TryVariableIgnore

decompiled_code:
_BOOL8 __fastcall TryVariableIgnore(char *src)
{
size_t v2; // rax
unsigned int v3; // eax
_BOOL4 v4; // er13
const char *v5; // rax
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
char v11; // dl
bool v12; // cf
bool v13; // zf
__int64 v14; // rcx
char v15; // dl
bool v16; // cf
bool v17; // zf
__int64 v18; // rcx
char v19; // dl
bool v20; // cf
bool v21; // zf
const char *v22; // rdi
__int64 v23; // rcx
const char *v24; // rsi
bool v25; // dl
bool v26; // cf
bool v27; // zf
const char *v28; // rdi
__int64 v29; // rcx
const char *v30; // rsi
char v31; // dl
bool v32; // cf
bool v33; // zf
const char *v34; // rdi
__int64 v35; // rcx
const char *v36; // rsi
bool v37; // dl
bool v38; // cf
bool v39; // zf
const char *v40; // rdi
__int64 v41; // rcx
const char *v42; // rsi
_BOOL8 result; // rax
size_t v44; // rax
char *v45; // r13
char *v46; // rdi
_BYTE v47[144]; // [rsp+0h] [rbp-98h] BYREF

v2 = strlen(src);
if ( v2 > 0x63 )
{
diagnostics(1LL, "Command <%s> is too long", src);
result = 0LL;
}
else
{
v3 = v2 + 1;
*(_WORD *)v47 = 92;
if ( v3 < 8 )
{
if ( (v3 & 4) != 0 )
{
*(_DWORD *)&v47[1] = *(_DWORD *)src;
*(_DWORD *)&v47[v3 - 3] = *(_DWORD *)&src[v3 - 4];
}
else if ( v3 )
{
v47[1] = *src;
if ( (v3 & 2) != 0 )
*(_WORD *)&v47[v3 - 1] = *(_WORD *)&src[v3 - 2];
}
}
else
{
*(_QWORD *)&v47[1] = *(_QWORD *)src;
*(_QWORD *)&v47[v3 - 7] = *(_QWORD *)&src[v3 - 8];
qmemcpy(&v47[8], &src[-(&v47[1] - &v47[8])], 8LL * ((v3 + (unsigned int)(&v47[1] - &v47[8])) >> 3));
}
v4 = 0;
v5 = (const char *)SearchRtfCmd(v47, 2LL);
v6 = 0;
v7 = v5 == 0LL;
if ( v5 )
{
v8 = "NUMBER";
v9 = 7LL;
v10 = v5;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
goto LABEL_40;
v8 = "MEASURE";
v14 = 8LL;
v10 = v5;
do
{
if ( !v14 )
break;
v12 = *v10 < (unsigned int)*v8;
v13 = *v10++ == *v8++;
--v14;
}
while ( v13 );
v15 = (!v12 && !v13) - v12;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
goto LABEL_40;
v8 = "OTHER";
v18 = 6LL;
v10 = v5;
do
{
if ( !v18 )
break;
v16 = *v10 < (unsigned int)*v8;
v17 = *v10++ == *v8++;
--v18;
}
while ( v17 );
v19 = (!v16 && !v17) - v16;
v20 = 0;
v21 = v19 == 0;
if ( v19 )
{
v22 = "COMMAND";
v23 = 8LL;
v24 = v5;
do
{
if ( !v23 )
break;
v20 = *v24 < (unsigned int)*v22;
v21 = *v24++ == *v22++;
--v23;
}
while ( v21 );
if ( (!v20 && !v21) == v20 )
{
IgnoreCmd(v22, v24);
v4 = 1;
}
else
{
v4 = 1;
v25 = strcmp(v5, "SINGLE") != 0;
v26 = 0;
v27 = !v25;
if ( v25 )
{
v28 = "PARAMETER";
v29 = 10LL;
v30 = v5;
do
{
if ( !v29 )
break;
v26 = *v30 < (unsigned int)*v28;
v27 = *v30++ == *v28++;
--v29;
}
while ( v27 );
v31 = (!v26 && !v27) - v26;
v32 = 0;
v33 = v31 == 0;
if ( v31 )
{
v34 = "TWOPARAMETER";
v35 = 13LL;
v36 = v5;
do
{
if ( !v35 )
break;
v32 = *v36 < (unsigned int)*v34;
v33 = *v36++ == *v34++;
--v35;
}
while ( v33 );
if ( (!v32 && !v33) == v32 )
{
CmdIgnoreParameter(2LL, v36);
}
else
{
v37 = strcmp(v5, "ENVIRONMENT") != 0;
v38 = 0;
v39 = !v37;
if ( v37 )
{
v40 = "ENVCMD";
v41 = 7LL;
v42 = v5;
do
{
if ( !v41 )
break;
v38 = *v42 < (unsigned int)*v40;
v39 = *v42++ == *v40++;
--v41;
}
while ( v39 );
if ( (!v38 && !v39) == v38 )
{
v4 = 1;
PushEnvironment(9LL, v42);
}
else
{
v4 = strcmp(v5, "PACKAGE") == 0;
}
}
else
{
v44 = strlen(src);
v45 = (char *)malloc(v44 + 5);
if ( !v45 )
diagnostics(0LL, "malloc error -> out of memory!\n");
*(_DWORD *)v45 = 2070179429;
*(_WORD *)stpcpy(v45 + 4, src) = 125;
Ignore_Environment(v45);
v46 = v45;
v4 = 1;
free(v46);
}
}
}
else
{
CmdIgnoreParameter(1LL, v30);
}
}
}
}
else
{
LABEL_40:
IgnoreVar(v8, v10);
v4 = 1;
}
}
result = v4;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *src)
{
size_t v2; // rax
unsigned int v3; // eax
_BOOL4 v4; // er13
const char *v5; // rax
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
char v11; // dl
bool v12; // cf
bool v13; // zf
__int64 v14; // rcx
char v15; // dl
bool v16; // cf
bool v17; // zf
__int64 v18; // rcx
char v19; // dl
bool v20; // cf
bool v21; // zf
const char *v22; // rdi
__int64 v23; // rcx
const char *v24; // rsi
bool v25; // dl
bool v26; // cf
bool v27; // zf
const char *v28; // rdi
__int64 v29; // rcx
const char *v30; // rsi
char v31; // dl
bool v32; // cf
bool v33; // zf
const char *v34; // rdi
__int64 v35; // rcx
const char *v36; // rsi
bool v37; // dl
bool v38; // cf
bool v39; // zf
const char *v40; // rdi
__int64 v41; // rcx
const char *v42; // rsi
_BOOL8 result; // rax
size_t v44; // rax
char *v45; // r13
char *v46; // rdi
_BYTE v47[144]; // [rsp+0h] [rbp-98h] BYREF

v2 = strlen(src);
if ( v2 > 0x63 )
{
diagnostics(1LL, "Command <%s> is too long", src);
result = 0LL;
}
else
{
v3 = v2 + 1;
*(_WORD *)v47 = 92;
if ( v3 < 8 )
{
if ( (v3 & 4) != 0 )
{
*(_DWORD *)&v47[1] = *(_DWORD *)src;
*(_DWORD *)&v47[v3 - 3] = *(_DWORD *)&src[v3 - 4];
}
else if ( v3 )
{
v47[1] = *src;
if ( (v3 & 2) != 0 )
*(_WORD *)&v47[v3 - 1] = *(_WORD *)&src[v3 - 2];
}
}
else
{
*(_QWORD *)&v47[1] = *(_QWORD *)src;
*(_QWORD *)&v47[v3 - 7] = *(_QWORD *)&src[v3 - 8];
qmemcpy(&v47[8], &src[-(&v47[1] - &v47[8])], 8LL * ((v3 + (unsigned int)(&v47[1] - &v47[8])) >> 3));
}
v4 = 0;
v5 = (const char *)SearchRtfCmd(v47, 2LL);
v6 = 0;
v7 = v5 == 0LL;
if ( v5 )
{
v8 = "NUMBER";
v9 = 7LL;
v10 = v5;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
goto LABEL_40;
v8 = "MEASURE";
v14 = 8LL;
v10 = v5;
do
{
if ( !v14 )
break;
v12 = *v10 < (unsigned int)*v8;
v13 = *v10++ == *v8++;
--v14;
}
while ( v13 );
v15 = (!v12 && !v13) - v12;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
goto LABEL_40;
v8 = "OTHER";
v18 = 6LL;
v10 = v5;
do
{
if ( !v18 )
break;
v16 = *v10 < (unsigned int)*v8;
v17 = *v10++ == *v8++;
--v18;
}
while ( v17 );
v19 = (!v16 && !v17) - v16;
v20 = 0;
v21 = v19 == 0;
if ( v19 )
{
v22 = "COMMAND";
v23 = 8LL;
v24 = v5;
do
{
if ( !v23 )
break;
v20 = *v24 < (unsigned int)*v22;
v21 = *v24++ == *v22++;
--v23;
}
while ( v21 );
if ( (!v20 && !v21) == v20 )
{
func1(v22, v24);
v4 = 1;
}
else
{
v4 = 1;
v25 = strcmp(v5, "SINGLE") != 0;
v26 = 0;
v27 = !v25;
if ( v25 )
{
v28 = "PARAMETER";
v29 = 10LL;
v30 = v5;
do
{
if ( !v29 )
break;
v26 = *v30 < (unsigned int)*v28;
v27 = *v30++ == *v28++;
--v29;
}
while ( v27 );
v31 = (!v26 && !v27) - v26;
v32 = 0;
v33 = v31 == 0;
if ( v31 )
{
v34 = "TWOPARAMETER";
v35 = 13LL;
v36 = v5;
do
{
if ( !v35 )
break;
v32 = *v36 < (unsigned int)*v34;
v33 = *v36++ == *v34++;
--v35;
}
while ( v33 );
if ( (!v32 && !v33) == v32 )
{
CmdIgnoreParameter(2LL, v36);
}
else
{
v37 = strcmp(v5, "ENVIRONMENT") != 0;
v38 = 0;
v39 = !v37;
if ( v37 )
{
v40 = "ENVCMD";
v41 = 7LL;
v42 = v5;
do
{
if ( !v41 )
break;
v38 = *v42 < (unsigned int)*v40;
v39 = *v42++ == *v40++;
--v41;
}
while ( v39 );
if ( (!v38 && !v39) == v38 )
{
v4 = 1;
PushEnvironment(9LL, v42);
}
else
{
v4 = strcmp(v5, "PACKAGE") == 0;
}
}
else
{
v44 = strlen(src);
v45 = (char *)malloc(v44 + 5);
if ( !v45 )
diagnostics(0LL, "malloc error -> out of memory!\n");
*(_DWORD *)v45 = 2070179429;
*(_WORD *)stpcpy(v45 + 4, src) = 125;
func2(v45);
v46 = v45;
v4 = 1;
free(v46);
}
}
}
else
{
CmdIgnoreParameter(1LL, v30);
}
}
}
}
else
{
LABEL_40:
func0(v8, v10);
v4 = 1;
}
}
result = v4;
}
return result;
}

original_code:
bool
TryVariableIgnore(char *command)
{
 const char *RtfCommand;
 char TexCommand[128];
 bool result = 1;
 if (strlen(command) >= 100) {
  diagnostics(1, "Command <%s> is too long", command);
  return 0;
 }
 TexCommand[0] = '\\';
 TexCommand[1] = '\0';
 strcat(TexCommand, command);
 RtfCommand = SearchRtfCmd(TexCommand, 2);
 if (RtfCommand == ((void *)0))
  result = 0;
 else if (strcmp(RtfCommand, "NUMBER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "MEASURE") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "OTHER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "COMMAND") == 0)
  IgnoreCmd();
 else if (strcmp(RtfCommand, "SINGLE") == 0)
  {}
 else if (strcmp(RtfCommand, "PARAMETER") == 0)
  CmdIgnoreParameter(01);
    else if (strcmp(RtfCommand, "TWOPARAMETER") == 0)
         CmdIgnoreParameter(02);
 else if (strcmp(RtfCommand, "ENVIRONMENT") == 0) {
  char *str;
  str = malloc(strlen(command) + 5);
  if (str == ((void *)0))
   diagnostics(0, "malloc error -> out of memory!\n");
  strcpy(str, "end{");
  strcat(str, command);
  strcat(str, "}");
  Ignore_Environment(str);
  free(str);
 } else if (strcmp(RtfCommand, "ENVCMD") == 0)
  PushEnvironment(9);
 else if (strcmp(RtfCommand, "PACKAGE") == 0)
  {}
 else
  result = 0;
 return (result);
}

canonical_original_code:
int TryVariableIgnore(char *command)
{
 char *RtfCommand;
 char TexCommand[128];
 int result = 1;
 if (strlen(command) >= 100) {
  diagnostics(1, "Command <%s> is too long", command);
  return 0;
 }
 TexCommand[0] = '\\';
 TexCommand[1] = '\0';
 strcat(TexCommand, command);
 RtfCommand = SearchRtfCmd(TexCommand, 2);
 if (RtfCommand == ((void *)0))
  result = 0;
 else if (strcmp(RtfCommand, "NUMBER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "MEASURE") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "OTHER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "COMMAND") == 0)
  IgnoreCmd();
 else if (strcmp(RtfCommand, "SINGLE") == 0)
  {}
 else if (strcmp(RtfCommand, "PARAMETER") == 0)
  CmdIgnoreParameter(01);
    else if (strcmp(RtfCommand, "TWOPARAMETER") == 0)
         CmdIgnoreParameter(02);
 else if (strcmp(RtfCommand, "ENVIRONMENT") == 0) {
  char *str;
  str = malloc(strlen(command) + 5);
  if (str == ((void *)0))
   diagnostics(0, "malloc error -> out of memory!\n");
  strcpy(str, "end{");
  strcat(str, command);
  strcat(str, "}");
  Ignore_Environment(str);
  free(str);
 } else if (strcmp(RtfCommand, "ENVCMD") == 0)
  PushEnvironment(9);
 else if (strcmp(RtfCommand, "PACKAGE") == 0)
  {}
 else
  result = 0;
 return (result);
}

variable_types:
command
char *

variable_types:
RtfCommand
char *

variable_types:
TexCommand
char [128]

variable_types: result int

variable_types:
str
char *

return_type: int


myprintStack

decompiled_code:
__int64 myprintStack()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // r8

fprintf(stderr, "\nStack Status top=%d\n", (unsigned int)top);
result = (unsigned int)top;
if ( top > 0 )
{
v1 = 0LL;
do
{
v2 = (unsigned int)dword_364[2 * v1];
v3 = (unsigned int)dword_368[2 * v1++];
fprintf(stderr, " #%d lev=%d bracket=%d\n", (unsigned int)v1, v2, v3);
result = (unsigned int)(2 * v1);
}
while ( top > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // r8

fprintf(stderr, "\nStack Status top=%d\n", (unsigned int)top);
result = (unsigned int)top;
if ( top > 0 )
{
v1 = 0LL;
do
{
v2 = (unsigned int)dword_364[2 * v1];
v3 = (unsigned int)dword_368[2 * v1++];
fprintf(stderr, " #%d lev=%d bracket=%d\n", (unsigned int)v1, v2, v3);
result = (unsigned int)(2 * v1);
}
while ( top > (int)result );
}
return result;
}

original_code:
void
myprintStack(void)
{
int i, lev, brack;
 fprintf(stderr, "\nStack Status top=%d\n",top);
 i=0;
 while (2*i<top) {
  lev = stack[2*i+1];
  brack = stack[2*i+2];
  i++;
  fprintf(stderr, " #%d lev=%d bracket=%d\n", i, lev, brack);
 }
}

canonical_original_code:
void myprintStack()
{
int i; int lev; int brack;
 fprintf(stderr, "\nStack Status top=%d\n",top);
 i=0;
 while (2*i<top) {
  lev = stack[2*i+1];
  brack = stack[2*i+2];
  i++;
  fprintf(stderr, " #%d lev=%d bracket=%d\n", i, lev, brack);
 }
}

variable_types: i int

variable_types: lev int

variable_types: brack int


BasicPush

decompiled_code:
__int64 __fastcall BasicPush(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

v3 = top + 1;
top += 2;
result = (unsigned int)top;
stack[v3] = a1;
stack[(int)result] = a2;
if ( (int)result > 999 )
{
diagnostics(0LL, "Nesting too deep. latex2rtf bug, if file TeXs properly");
result = (unsigned int)top;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

v3 = top + 1;
top += 2;
result = (unsigned int)top;
stack[v3] = a1;
stack[(int)result] = a2;
if ( (int)result > 999 )
{
diagnostics(0LL, "Nesting too deep. latex2rtf bug, if file TeXs properly");
result = (unsigned int)top;
}
return result;
}

original_code:
int
BasicPush(int lev, int brack)
{
 ++top;
 stack[top] = lev;
 ++top;
 stack[top] = brack;
 if (top >= 1000)
  diagnostics(0, "Nesting too deep.  latex2rtf bug, if file TeXs properly");
 return top;
}


BasicPop

decompiled_code:
__int64 __fastcall BasicPop(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax

v2 = top;
*a2 = stack[top];
v3 = v2 - 1;
result = (unsigned int)(v2 - 2);
top = result;
*a1 = stack[v3];
if ( (int)result < 0 )
{
diagnostics(0LL, "Nesting problem. latex2rtf bug, if file TeXs properly");
result = (unsigned int)top;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax

v2 = top;
*a2 = stack[top];
v3 = v2 - 1;
result = (unsigned int)(v2 - 2);
top = result;
*a1 = stack[v3];
if ( (int)result < 0 )
{
diagnostics(0LL, "Nesting problem. latex2rtf bug, if file TeXs properly");
result = (unsigned int)top;
}
return result;
}

original_code:
int
BasicPop(int *lev, int *brack)
{
 *brack = stack[top];
 --top;
 *lev = stack[top];
 --top;
 if (top < 0)
  diagnostics(0, "Nesting problem.  latex2rtf bug, if file TeXs properly");
 return top;
}

variable_types:
lev
int *

variable_types:
brack
int *


PopLevels

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

BasicPop(v1, &BraceLevel);
return v1[0];
}

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

func2(v1, &BraceLevel);
return v1[0];
}

original_code:
int
PopLevels(void)
{
 int level;
 (void) BasicPop(&level, &BraceLevel);
 return level;
}

canonical_original_code:
int PopLevels()
{
 int level;
 (void) BasicPop(&level, &BraceLevel);
 return level;
}

variable_types: level int


getStackRecursionLevel

decompiled_code:
__int64 getStackRecursionLevel()
{
unsigned int v0; // er12
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = RecursionLevel;
BasicPop(&v2, v3);
while ( (int)BasicPop(&v2, v3) >= 0 && v3[0] >= BraceLevel )
v0 = v2;
BasicPush(v2, v3[0]);
BasicPush(v0, BraceLevel);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = RecursionLevel;
func2(&v2, v3);
while ( (int)func2(&v2, v3) >= 0 && v3[0] >= BraceLevel )
v0 = v2;
func1(v2, v3[0]);
func1(v0, BraceLevel);
return v0;
}

original_code:
int
getStackRecursionLevel(void)
{
int PopLevel, PopBrack, PPopLevel, PPopBrack, size;
  PPopLevel = RecursionLevel;
  PPopBrack = BraceLevel;
  size = BasicPop(&PopLevel, &PopBrack);
  while ((size = BasicPop(&PopLevel, &PopBrack)) >= 0) {
   if (PopBrack < BraceLevel) {
    break;
   }
   PPopLevel = PopLevel;
   PPopBrack = PopBrack;
  }
  (void) BasicPush(PopLevel, PopBrack);
  (void) BasicPush(PPopLevel, BraceLevel);
  return PPopLevel;
}

canonical_original_code:
int getStackRecursionLevel()
{
int PopLevel; int PopBrack; int PPopLevel; int PPopBrack; int size;
  PPopLevel = RecursionLevel;
  PPopBrack = BraceLevel;
  size = BasicPop(&PopLevel, &PopBrack);
  while ((size = BasicPop(&PopLevel, &PopBrack)) >= 0) {
   if (PopBrack < BraceLevel) {
    break;
   }
   PPopLevel = PopLevel;
   PPopBrack = PopBrack;
  }
  (void) BasicPush(PopLevel, PopBrack);
  (void) BasicPush(PPopLevel, BraceLevel);
  return PPopLevel;
}

variable_types: PopLevel int

variable_types: PopBrack int

variable_types: PPopLevel int

variable_types: PPopBrack int

variable_types: size int


CleanStack

decompiled_code:
__int64 CleanStack()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-18h] BYREF
int v2; // [rsp+4h] [rbp-14h] BYREF
int v3; // [rsp+8h] [rbp-10h] BYREF
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = diagnostics(5LL, "Cleaning Stack");
if ( top > 3 )
{
BasicPop(&v3, v4);
do
BasicPop(&v1, &v2);
while ( v3 == v1 && v4[0] == v2 && top > 0 );
result = BasicPush(v1, v2);
if ( v3 != v1 || v4[0] != v2 )
result = BasicPush(v3, v4[0]);
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-18h] BYREF
int v2; // [rsp+4h] [rbp-14h] BYREF
int v3; // [rsp+8h] [rbp-10h] BYREF
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = diagnostics(5LL, "Cleaning Stack");
if ( top > 3 )
{
func2(&v3, v4);
do
func2(&v1, &v2);
while ( v3 == v1 && v4[0] == v2 && top > 0 );
result = func1(v1, v2);
if ( v3 != v1 || v4[0] != v2 )
result = func1(v3, v4[0]);
}
return result;
}

original_code:
void
CleanStack(void)
{
int PopLevel, PopBrack, PPopLevel, PPopBrack;
 diagnostics(5, "Cleaning Stack");
 if (top<4) return;
 BasicPop(&PPopLevel, &PPopBrack);
 BasicPop(&PopLevel, &PopBrack);
 while (PPopLevel == PopLevel && PPopBrack == PopBrack && top>0)
  BasicPop(&PopLevel, &PopBrack);
 BasicPush(PopLevel, PopBrack);
 if (PPopLevel != PopLevel || PPopBrack != PopBrack)
  BasicPush(PPopLevel, PPopBrack);
}

canonical_original_code:
void CleanStack()
{
int PopLevel; int PopBrack; int PPopLevel; int PPopBrack;
 diagnostics(5, "Cleaning Stack");
 if (top<4) return;
 BasicPop(&PPopLevel, &PPopBrack);
 BasicPop(&PopLevel, &PopBrack);
 while (PPopLevel == PopLevel && PPopBrack == PopBrack && top>0)
  BasicPop(&PopLevel, &PopBrack);
 BasicPush(PopLevel, PopBrack);
 if (PPopLevel != PopLevel || PPopBrack != PopBrack)
  BasicPush(PPopLevel, PPopBrack);
}


PushLevels

decompiled_code:
__int64 PushLevels()
{
diagnostics(5LL, "PushLevels");
CleanStack();
return BasicPush(RecursionLevel, BraceLevel);
}

canonical_decompiled_code:
__int64 func6()
{
diagnostics(5LL, "PushLevels");
func5();
return func1(RecursionLevel, BraceLevel);
}

original_code:
void
PushLevels(void)
{
 diagnostics(5, "PushLevels");
 CleanStack();
 (void) BasicPush(RecursionLevel, BraceLevel);
}

canonical_original_code:
void PushLevels()
{
 diagnostics(5, "PushLevels");
 CleanStack();
 (void) BasicPush(RecursionLevel, BraceLevel);
}


InitializeStack

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

BraceLevel = 0;
RecursionLevel = 1;
result = PushLevels();
BraceLevel = 1;
return result;
}

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

BraceLevel = 0;
RecursionLevel = 1;
result = func6();
BraceLevel = 1;
return result;
}

original_code:
void
InitializeStack(void)
{
 BraceLevel=0;
 RecursionLevel = 1;
 PushLevels();
 BraceLevel=1;
}

canonical_original_code:
void InitializeStack()
{
 BraceLevel=0;
 RecursionLevel = 1;
 PushLevels();
 BraceLevel=1;
}


PushBrace

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

result = BasicPush(RecursionLevel, BraceLevel);
++BraceLevel;
return result;
}

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

result = func1(RecursionLevel, BraceLevel);
++BraceLevel;
return result;
}

original_code:
void
PushBrace(void)
{
 BasicPush(RecursionLevel,BraceLevel);
 ++BraceLevel;
}

canonical_original_code:
void PushBrace()
{
 BasicPush(RecursionLevel,BraceLevel);
 ++BraceLevel;
}


PopBrace

decompiled_code:
__int64 PopBrace()
{
int v0; // er12
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

diagnostics(6LL, "Popping Brace Level");
--BraceLevel;
v0 = RecursionLevel;
while ( 1 )
{
BasicPop(&v2, v3);
if ( v3[0] < BraceLevel )
break;
if ( v0 > v2 )
v0 = v2;
}
BasicPush(v2, v3[0]);
BasicPush(v0, BraceLevel);
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // er12
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

diagnostics(6LL, "Popping Brace Level");
--BraceLevel;
v0 = RecursionLevel;
while ( 1 )
{
func2(&v2, v3);
if ( v3[0] < BraceLevel )
break;
if ( v0 > v2 )
v0 = v2;
}
func1(v2, v3[0]);
func1(v0, BraceLevel);
return (unsigned int)v0;
}

original_code:
int
PopBrace(void)
{
int PopLevel, PopBrack, PPopLevel;
 diagnostics(6,"Popping Brace Level");
 BraceLevel--;
 PPopLevel = RecursionLevel;
 BasicPop(&PopLevel, &PopBrack);
 while (PopBrack >= BraceLevel) {
  if (PopLevel < PPopLevel) PPopLevel = PopLevel;
  BasicPop(&PopLevel, &PopBrack);
 }
 BasicPush(PopLevel, PopBrack);
 BasicPush(PPopLevel, BraceLevel);
 return PPopLevel;
}

canonical_original_code:
int PopBrace()
{
int PopLevel; int PopBrack; int PPopLevel;
 diagnostics(6,"Popping Brace Level");
 BraceLevel--;
 PPopLevel = RecursionLevel;
 BasicPop(&PopLevel, &PopBrack);
 while (PopBrack >= BraceLevel) {
  if (PopLevel < PPopLevel) PPopLevel = PopLevel;
  BasicPop(&PopLevel, &PopBrack);
 }
 BasicPush(PopLevel, PopBrack);
 BasicPush(PPopLevel, BraceLevel);
 return PPopLevel;
}


SetTexMode

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

result = abs32(a1);
if ( (_DWORD)result != g_TeX_mode )
result = diagnostics(
4LL,
"TeX mode changing from [%s] -> [%s]",
&TexModeName[25 * g_TeX_mode],
&TexModeName[25 * (int)result]);
if ( a1 < 0 )
{
g_TeX_mode = -a1;
}
else
{
result = (unsigned int)g_TeX_mode;
if ( a1 == 2 && g_TeX_mode == 6 )
{
result = CmdStartParagraph(2LL);
}
else if ( g_TeX_mode == 2 && a1 == 6 )
{
result = CmdEndParagraph(0LL);
}
g_TeX_mode = a1;
}
return result;
}

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

result = abs32(a1);
if ( (_DWORD)result != g_TeX_mode )
result = diagnostics(
4LL,
"TeX mode changing from [%s] -> [%s]",
&TexModeName[25 * g_TeX_mode],
&TexModeName[25 * (int)result]);
if ( a1 < 0 )
{
g_TeX_mode = -a1;
}
else
{
result = (unsigned int)g_TeX_mode;
if ( a1 == 2 && g_TeX_mode == 6 )
{
result = CmdStartParagraph(2LL);
}
else if ( g_TeX_mode == 2 && a1 == 6 )
{
result = CmdEndParagraph(0LL);
}
g_TeX_mode = a1;
}
return result;
}

original_code:
void SetTexMode(int mode)
{
 if (abs(mode) != g_TeX_mode)
  diagnostics(4, "TeX mode changing from [%s] -> [%s]", TexModeName[g_TeX_mode], TexModeName[abs(mode)]);
 if (mode < 0) {
  g_TeX_mode = -mode;
  return;
 }
 if (g_TeX_mode == 6 && mode == 2)
  CmdStartParagraph(2);
 if (g_TeX_mode == 2 && mode == 6)
  CmdEndParagraph(0);
 g_TeX_mode = mode;
}

variable_types: mode int


GetTexMode

decompiled_code:
__int64 GetTexMode()
{
return (unsigned int)g_TeX_mode;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)g_TeX_mode;
}

original_code:
int GetTexMode(void)
{
 return g_TeX_mode;
}

canonical_original_code:
int GetTexMode()
{
 return g_TeX_mode;
}


TranslateCommand

decompiled_code:
__int64 TranslateCommand()
{
unsigned int v0; // ebp
__int64 v1; // rdx
int v2; // er12
__int64 result; // rax
__int64 v4; // rbx
const unsigned __int16 **v5; // r13
int v6; // er12
int v7; // ebx
int v8; // ebx
int v9; // [rsp+0h] [rbp-98h] BYREF
__int16 v10; // [rsp+4h] [rbp-94h]
char v11; // [rsp+64h] [rbp-34h]

v0 = (char)getTexChar();
v2 = GetTexMode(5LL, "Beginning TranslateCommand() \\%c", v1);
result = diagnostics(5LL, "Beginning TranslateCommand() \\%c", v0);
switch ( (char)v0 )
{
case 10:
case 32:
if ( v2 == 6 )
SetTexMode(2);
fprintRTF(" ");
return skipSpaces();
case 33:
case 47:
case 64:
return CmdIgnore(0LL);
case 34:
if ( v2 == 6 )
SetTexMode(2);
return CmdUmlauteChar(0LL);
case 35:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("#");
case 36:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("$");
case 37:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("%%");
case 38:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("&");
case 39:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
goto LABEL_7;
return CmdRApostrophChar(0LL);
case 40:
return CmdEquation(16387LL);
case 41:
return CmdEquation(5LL);
case 43:
case 60:
if ( v2 == 6 )
result = SetTexMode(2);
if ( g_processing_tabbing )
goto LABEL_7;
return result;
case 44:
if ( v2 == 6 )
SetTexMode(2);
return CmdSpace(COERCE_DOUBLE((unsigned __int64)LC12));
case 45:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
goto LABEL_7;
return fprintRTF("\\-");
case 46:
if ( v2 == 6 )
SetTexMode(2);
return CmdDotChar(0LL);
case 51:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("{\\'df}");
case 59:
if ( v2 == 6 )
SetTexMode(2);
return CmdSpace(COERCE_DOUBLE((unsigned __int64)LC13));
case 61:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
{
PopBrace();
CmdTabset();
return PushBrace();
}
return CmdMacronChar(0LL);
case 62:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
{
PopBrace();
CmdTabjump();
return PushBrace();
}
return CmdSpace(COERCE_DOUBLE((unsigned __int64)LC11));
case 91:
return CmdEquation(16388LL);
case 92:
return CmdSlashSlash(0LL);
case 93:
return CmdEquation(6LL);
case 94:
if ( v2 == 6 )
SetTexMode(2);
return CmdHatChar(0LL);
case 95:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("_");
case 96:
if ( v2 == 6 )
SetTexMode(2);
if ( !g_processing_tabbing )
return CmdLApostrophChar(0LL);
LABEL_7:
PopBrace();
return PushBrace();
case 123:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("\\{");
case 125:
if ( v2 == 6 )
SetTexMode(2);
return fprintRTF("\\}");
case 126:
if ( v2 == 6 )
SetTexMode(2);
return CmdTildeChar(0LL);
default:
v4 = 0LL;
v5 = _ctype_b_loc();
while ( 1 )
{
v6 = v4;
if ( ((*v5)[v0] & 0x400) == 0 && v0 != 42 )
break;
*((_BYTE *)&v9 + v4++) = v0;
v0 = (char)getRawTexChar();
if ( v4 == 100 )
{
v11 = 0;
diagnostics(5LL, "TranslateCommand() <%s>", (const char *)&v9);
goto LABEL_22;
}
}
if ( v0 == 37 )
{
ungetTexChar(37LL);
v0 = (char)getTexChar();
}
v7 = 0;
break;
}
while ( v0 == 32 )
LABEL_18:
v0 = (char)getTexChar();
if ( v0 == 10 && !v7 )
{
v7 = 1;
goto LABEL_18;
}
ungetTexChar(v0);
*((_BYTE *)&v9 + v6) = 0;
result = diagnostics(5LL, "TranslateCommand() <%s>", (const char *)&v9);
if ( v6 )
{
LABEL_22:
if ( v9 == 1768383842 && v10 == 110 )
{
fprintRTF("{");
PushBrace();
}
result = CallCommandFunc(&v9);
if ( (_DWORD)result )
{
if ( v9 == 6581861 )
{
v8 = RecursionLevel;
ret = v8 - PopBrace();
result = fprintRTF("}");
}
}
else
{
result = TryDirectConvert(&v9);
if ( !(_DWORD)result )
{
result = TryVariableIgnore(&v9);
if ( !(_DWORD)result )
result = diagnostics(1LL, "Command \\%s not found - ignored", (const char *)&v9);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebp
__int64 v1; // rdx
int v2; // er12
__int64 result; // rax
__int64 v4; // rbx
const unsigned __int16 **v5; // r13
int v6; // er12
int v7; // ebx
int v8; // ebx
int v9; // [rsp+0h] [rbp-98h] BYREF
__int16 v10; // [rsp+4h] [rbp-94h]
char v11; // [rsp+64h] [rbp-34h]

v0 = (char)getTexChar();
v2 = func1(5LL, "Beginning TranslateCommand() \\%c", v1);
result = diagnostics(5LL, "Beginning TranslateCommand() \\%c", v0);
switch ( (char)v0 )
{
case 10:
case 32:
if ( v2 == 6 )
func0(2);
fprintRTF(" ");
return skipSpaces();
case 33:
case 47:
case 64:
return CmdIgnore(0LL);
case 34:
if ( v2 == 6 )
func0(2);
return CmdUmlauteChar(0LL);
case 35:
if ( v2 == 6 )
func0(2);
return fprintRTF("#");
case 36:
if ( v2 == 6 )
func0(2);
return fprintRTF("$");
case 37:
if ( v2 == 6 )
func0(2);
return fprintRTF("%%");
case 38:
if ( v2 == 6 )
func0(2);
return fprintRTF("&");
case 39:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
goto LABEL_7;
return CmdRApostrophChar(0LL);
case 40:
return CmdEquation(16387LL);
case 41:
return CmdEquation(5LL);
case 43:
case 60:
if ( v2 == 6 )
result = func0(2);
if ( g_processing_tabbing )
goto LABEL_7;
return result;
case 44:
if ( v2 == 6 )
func0(2);
return CmdSpace(COERCE_DOUBLE((unsigned __int64)LC12));
case 45:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
goto LABEL_7;
return fprintRTF("\\-");
case 46:
if ( v2 == 6 )
func0(2);
return CmdDotChar(0LL);
case 51:
if ( v2 == 6 )
func0(2);
return fprintRTF("{\\'df}");
case 59:
if ( v2 == 6 )
func0(2);
return CmdSpace(COERCE_DOUBLE((unsigned __int64)LC13));
case 61:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
{
PopBrace();
CmdTabset();
return PushBrace();
}
return CmdMacronChar(0LL);
case 62:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
{
PopBrace();
CmdTabjump();
return PushBrace();
}
return CmdSpace(COERCE_DOUBLE((unsigned __int64)LC11));
case 91:
return CmdEquation(16388LL);
case 92:
return CmdSlashSlash(0LL);
case 93:
return CmdEquation(6LL);
case 94:
if ( v2 == 6 )
func0(2);
return CmdHatChar(0LL);
case 95:
if ( v2 == 6 )
func0(2);
return fprintRTF("_");
case 96:
if ( v2 == 6 )
func0(2);
if ( !g_processing_tabbing )
return CmdLApostrophChar(0LL);
LABEL_7:
PopBrace();
return PushBrace();
case 123:
if ( v2 == 6 )
func0(2);
return fprintRTF("\\{");
case 125:
if ( v2 == 6 )
func0(2);
return fprintRTF("\\}");
case 126:
if ( v2 == 6 )
func0(2);
return CmdTildeChar(0LL);
default:
v4 = 0LL;
v5 = _ctype_b_loc();
while ( 1 )
{
v6 = v4;
if ( ((*v5)[v0] & 0x400) == 0 && v0 != 42 )
break;
*((_BYTE *)&v9 + v4++) = v0;
v0 = (char)getRawTexChar();
if ( v4 == 100 )
{
v11 = 0;
diagnostics(5LL, "TranslateCommand() <%s>", (const char *)&v9);
goto LABEL_22;
}
}
if ( v0 == 37 )
{
ungetTexChar(37LL);
v0 = (char)getTexChar();
}
v7 = 0;
break;
}
while ( v0 == 32 )
LABEL_18:
v0 = (char)getTexChar();
if ( v0 == 10 && !v7 )
{
v7 = 1;
goto LABEL_18;
}
ungetTexChar(v0);
*((_BYTE *)&v9 + v6) = 0;
result = diagnostics(5LL, "TranslateCommand() <%s>", (const char *)&v9);
if ( v6 )
{
LABEL_22:
if ( v9 == 1768383842 && v10 == 110 )
{
fprintRTF("{");
PushBrace();
}
result = CallCommandFunc(&v9);
if ( (_DWORD)result )
{
if ( v9 == 6581861 )
{
v8 = RecursionLevel;
ret = v8 - PopBrace();
result = fprintRTF("}");
}
}
else
{
result = TryDirectConvert(&v9);
if ( !(_DWORD)result )
{
result = TryVariableIgnore(&v9);
if ( !(_DWORD)result )
result = diagnostics(1LL, "Command \\%s not found - ignored", (const char *)&v9);
}
}
}
return result;
}

original_code:
void
TranslateCommand()
{
 char cCommand[100];
 int i,mode;
 int cThis;
 cThis = getTexChar();
 mode = GetTexMode();
 diagnostics(5, "Beginning TranslateCommand() \\%c", cThis);
 switch (cThis) {
 case '}':
  if (mode == 6) SetTexMode(2);
  fprintRTF("\\}");
  return;
 case '{':
  if (mode == 6) SetTexMode(2);
  fprintRTF("\\{");
  return;
 case '#':
  if (mode == 6) SetTexMode(2);
  fprintRTF("#");
  return;
 case '$':
  if (mode == 6) SetTexMode(2);
  fprintRTF("$");
  return;
 case '&':
  if (mode == 6) SetTexMode(2);
  fprintRTF("&");
  return;
 case '%':
  if (mode == 6) SetTexMode(2);
  fprintRTF("%%");
  return;
 case '_':
  if (mode == 6) SetTexMode(2);
  fprintRTF("_");
  return;
 case '\\':
  CmdSlashSlash(0);
  return;
 case ' ':
 case '\n':
  if (mode == 6) SetTexMode(2);
  fprintRTF(" ");
  skipSpaces();
  return;
 case '-':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  } else
   fprintRTF("\\-");
  return;
 case '+':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  }
  return;
 case '<':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  }
  return;
 case '>':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   CmdTabjump();
   PushBrace();
  } else
   CmdSpace(0.50);
  return;
 case '`':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  } else
   CmdLApostrophChar(0);
  return;
 case '\'':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
   return;
  } else
   CmdRApostrophChar(0);
  return;
 case '=':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   CmdTabset();
   PushBrace();
  }
  else
   CmdMacronChar(0);
  return;
 case '~':
  if (mode == 6) SetTexMode(2);
  CmdTildeChar(0);
  return;
 case '^':
  if (mode == 6) SetTexMode(2);
  CmdHatChar(0);
  return;
 case '.':
  if (mode == 6) SetTexMode(2);
  CmdDotChar(0);
  return;
 case '\"':
  if (mode == 6) SetTexMode(2);
  CmdUmlauteChar(0);
  return;
 case '(':
  CmdEquation(3 | 0x4000);
  return;
 case '[':
  CmdEquation(4 | 0x4000);
  return;
 case ')':
  CmdEquation(5 | 0x0000);
  return;
 case ']':
  CmdEquation(6 | 0x0000);
  return;
 case '/':
  CmdIgnore(0);
  return;
 case '!':
  CmdIgnore(0);
  return;
 case ',':
  if (mode == 6) SetTexMode(2);
  CmdSpace(0.33);
  return;
 case ';':
  if (mode == 6) SetTexMode(2);
  CmdSpace(0.75);
  return;
 case '@':
  CmdIgnore(0);
  return;
 case '3':
  if (mode == 6) SetTexMode(2);
  fprintRTF("{\\'df}");
  return;
 }
 for (i = 0; i < 100; i++) {
  if (!((*__ctype_b_loc ())[(int) (((int)cThis))] & (unsigned short int) _ISalpha) && (cThis != '*')) {
   bool found_nl = 0;
   if (cThis == '%'){
    ungetTexChar('%');
    cThis=getTexChar();
   }
   while (cThis == ' ' || (cThis == '\n' && !found_nl)) {
    if (cThis == '\n')
     found_nl = 1;
    cThis = getTexChar();
   }
   ungetTexChar(cThis);
   break;
  } else
   cCommand[i] = cThis;
  cThis = getRawTexChar();
 }
 cCommand[i] = '\0';
 diagnostics(5, "TranslateCommand() <%s>", cCommand);
 if (i == 0)
  return;
 if (strcmp(cCommand,"begin")==0){
  fprintRTF("{");
  PushBrace();
 }
 if (CallCommandFunc(cCommand)){
  if (strcmp(cCommand,"end")==0) {
   ret = RecursionLevel - PopBrace();
   fprintRTF("}");
  }
  return;
 }
 if (TryDirectConvert(cCommand)) return;
 if (TryVariableIgnore(cCommand)) return;
 diagnostics(1, "Command \\%s not found - ignored", cCommand);
}

canonical_original_code:
void TranslateCommand()
{
 char cCommand[100];
 int i; int mode;
 int cThis;
 cThis = getTexChar();
 mode = GetTexMode();
 diagnostics(5, "Beginning TranslateCommand() \\%c", cThis);
 switch (cThis) {
 case '}':
  if (mode == 6) SetTexMode(2);
  fprintRTF("\\}");
  return;
 case '{':
  if (mode == 6) SetTexMode(2);
  fprintRTF("\\{");
  return;
 case '#':
  if (mode == 6) SetTexMode(2);
  fprintRTF("#");
  return;
 case '$':
  if (mode == 6) SetTexMode(2);
  fprintRTF("$");
  return;
 case '&':
  if (mode == 6) SetTexMode(2);
  fprintRTF("&");
  return;
 case '%':
  if (mode == 6) SetTexMode(2);
  fprintRTF("%%");
  return;
 case '_':
  if (mode == 6) SetTexMode(2);
  fprintRTF("_");
  return;
 case '\\':
  CmdSlashSlash(0);
  return;
 case ' ':
 case '\n':
  if (mode == 6) SetTexMode(2);
  fprintRTF(" ");
  skipSpaces();
  return;
 case '-':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  } else
   fprintRTF("\\-");
  return;
 case '+':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  }
  return;
 case '<':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  }
  return;
 case '>':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   CmdTabjump();
   PushBrace();
  } else
   CmdSpace(0.50);
  return;
 case '`':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
  } else
   CmdLApostrophChar(0);
  return;
 case '\'':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   PushBrace();
   return;
  } else
   CmdRApostrophChar(0);
  return;
 case '=':
  if (mode == 6) SetTexMode(2);
  if (g_processing_tabbing){
   (void) PopBrace();
   CmdTabset();
   PushBrace();
  }
  else
   CmdMacronChar(0);
  return;
 case '~':
  if (mode == 6) SetTexMode(2);
  CmdTildeChar(0);
  return;
 case '^':
  if (mode == 6) SetTexMode(2);
  CmdHatChar(0);
  return;
 case '.':
  if (mode == 6) SetTexMode(2);
  CmdDotChar(0);
  return;
 case '\"':
  if (mode == 6) SetTexMode(2);
  CmdUmlauteChar(0);
  return;
 case '(':
  CmdEquation(3 | 0x4000);
  return;
 case '[':
  CmdEquation(4 | 0x4000);
  return;
 case ')':
  CmdEquation(5 | 0x0000);
  return;
 case ']':
  CmdEquation(6 | 0x0000);
  return;
 case '/':
  CmdIgnore(0);
  return;
 case '!':
  CmdIgnore(0);
  return;
 case ',':
  if (mode == 6) SetTexMode(2);
  CmdSpace(0.33);
  return;
 case ';':
  if (mode == 6) SetTexMode(2);
  CmdSpace(0.75);
  return;
 case '@':
  CmdIgnore(0);
  return;
 case '3':
  if (mode == 6) SetTexMode(2);
  fprintRTF("{\\'df}");
  return;
 }
 for (i = 0; i < 100; i++) {
  if (!((*__ctype_b_loc ())[(int) (((int)cThis))] & (unsigned short) _ISalpha) && (cThis != '*')) {
   int found_nl = 0;
   if (cThis == '%'){
    ungetTexChar('%');
    cThis=getTexChar();
   }
   while (cThis == ' ' || (cThis == '\n' && !found_nl)) {
    if (cThis == '\n')
     found_nl = 1;
    cThis = getTexChar();
   }
   ungetTexChar(cThis);
   break;
  } else
   cCommand[i] = cThis;
  cThis = getRawTexChar();
 }
 cCommand[i] = '\0';
 diagnostics(5, "TranslateCommand() <%s>", cCommand);
 if (i == 0)
  return;
 if (strcmp(cCommand,"begin")==0){
  fprintRTF("{");
  PushBrace();
 }
 if (CallCommandFunc(cCommand)){
  if (strcmp(cCommand,"end")==0) {
   ret = RecursionLevel - PopBrace();
   fprintRTF("}");
  }
  return;
 }
 if (TryDirectConvert(cCommand)) return;
 if (TryVariableIgnore(cCommand)) return;
 diagnostics(1, "Command \\%s not found - ignored", cCommand);
}

variable_types:
cCommand
char [100]

variable_types: cThis int


ConvertAllttString

decompiled_code:
void __fastcall ConvertAllttString(__int64 a1)
{
char v1; // al
int v2; // ebp

if ( a1 )
{
diagnostics(4LL, "Entering Convert() from StringAllttConvert()");
if ( !(unsigned int)PushSource(0LL, a1) )
{
LABEL_3:
while ( (unsigned int)StillSource() )
{
while ( 1 )
{
v1 = getRawTexChar();
if ( v1 == 123 )
break;
if ( v1 == 125 )
{
v2 = RecursionLevel;
ret = v2 - PopBrace();
fprintRTF("}");
goto LABEL_3;
}
if ( v1 == 92 )
{
PushLevels();
TranslateCommand();
CleanStack();
goto LABEL_3;
}
putRtfChar((unsigned int)v1);
if ( !(unsigned int)StillSource() )
goto LABEL_8;
}
PushBrace();
fprintRTF("{");
}
LABEL_8:
PopSource();
}
diagnostics(4LL, "Exiting Convert() from StringAllttConvert()");
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
char v1; // al
int v2; // ebp

if ( a1 )
{
diagnostics(4LL, "Entering Convert() from StringAllttConvert()");
if ( !(unsigned int)PushSource(0LL, a1) )
{
LABEL_3:
while ( (unsigned int)StillSource() )
{
while ( 1 )
{
v1 = getRawTexChar();
if ( v1 == 123 )
break;
if ( v1 == 125 )
{
v2 = RecursionLevel;
ret = v2 - PopBrace();
fprintRTF("}");
goto LABEL_3;
}
if ( v1 == 92 )
{
PushLevels();
func2();
CleanStack();
goto LABEL_3;
}
putRtfChar((unsigned int)v1);
if ( !(unsigned int)StillSource() )
goto LABEL_8;
}
PushBrace();
fprintRTF("{");
}
LABEL_8:
PopSource();
}
diagnostics(4LL, "Exiting Convert() from StringAllttConvert()");
}
}

original_code:
void
ConvertAllttString(char *s)
{
 char cThis;
 if (s==((void *)0)) return;
 diagnostics(4, "Entering Convert() from StringAllttConvert()");
 if(PushSource(((void *)0), s)==0) {
  while (StillSource()) {
   cThis = getRawTexChar();
   switch (cThis) {
    case '\\':
     PushLevels();
     TranslateCommand();
     CleanStack();
     break;
    case '{':
     PushBrace();
     fprintRTF("{");
     break;
    case '}':
     ret = RecursionLevel - PopBrace();
     fprintRTF("}");
     break;
    default:
     putRtfChar(cThis);
     break;
   }
  }
  PopSource();
 }
 diagnostics(4, "Exiting Convert() from StringAllttConvert()");
}

variable_types:
s
char *

variable_types: cThis char


Convert

decompiled_code:
__int64 Convert()
{
const char *v0; // rsi
const char *v1; // rdi
char v2; // bp
__int64 v3; // rdx
int i; // ebx
__int64 v5; // r8
unsigned int v6; // eax
__int64 v7; // rcx
__int64 v8; // r9
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
int v12; // eax
char v13; // dl
__int64 result; // rax
int v15; // ebp
int v16; // eax
__int64 v17; // rdx
__int64 v18; // r12
__int64 v19; // rbp
const char *v20; // rdi
char v21; // bp
unsigned int v22; // er12
__int64 v23; // rdx
int v24; // er8
__int64 v25; // r12
__int64 v26; // rbp
int v27; // eax
__int64 v28; // rdx
__int64 v29; // r12
__int64 v30; // rbp
__int64 v31; // rdx
__int64 v32; // rcx
__int64 v33; // r8
int v34; // eax
int v35; // ebx
char v36; // al
char v37; // al
char v38; // al
char v39; // al

v0 = "Entering Convert ret = %d";
v1 = (_BYTE *)&loc_3;
v2 = 0;
diagnostics(3LL, "Entering Convert ret = %d", (unsigned int)ret);
++RecursionLevel;
PushLevels();
for ( i = getTexChar(); (_BYTE)i; i = getTexChar() )
{
v6 = GetTexMode(v1, v0, v3, (unsigned int)ret, v5, RecursionLevel);
if ( (_BYTE)i != 10 )
{
v0 = "Current character is '%c' mode = %d ret = %d level = %d";
v1 = (_BYTE *)&loc_5;
diagnostics(
5LL,
"Current character is '%c' mode = %d ret = %d level = %d",
(unsigned int)(char)i,
v6,
(unsigned int)v7,
v8);
v12 = GetTexMode(
5LL,
"Current character is '%c' mode = %d ret = %d level = %d",
(unsigned int)(i - 9),
v9,
v10,
v11);
switch ( v13 )
{
case 0:
v0 = "This should not happen, ignoring \\t";
v1 = (_BYTE *)(SetTexMode + 1);
v2 = 32;
diagnostics(1LL, "This should not happen, ignoring \\t");
goto LABEL_8;
case 4:
v0 = "This should not happen, ignoring \\r";
v1 = (_BYTE *)(SetTexMode + 1);
v2 = 32;
diagnostics(1LL, "This should not happen, ignoring \\r");
goto LABEL_8;
case 23:
if ( (unsigned int)(v12 - 4) <= 2 )
goto LABEL_8;
if ( v2 == 32 || v2 == 10 )
goto LABEL_11;
if ( v12 == 3 )
{
LABEL_7:
v1 = "\\~";
v2 = i;
fprintRTF("\\~");
}
else
{
v1 = " ";
v2 = i;
fprintRTF(" ");
}
goto LABEL_8;
case 24:
if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = "!";
v2 = i;
fprintRTF("!");
}
else
{
SetTexMode(2);
v20 = "! ";
v21 = getTexChar();
if ( v21 == 96 )
{
v1 = "\\'a1 ";
v2 = i;
fprintRTF("\\'a1 ");
}
else
{
LABEL_26:
fprintRTF(v20);
v1 = (const char *)(unsigned int)v21;
v2 = i;
ungetTexChar(v1);
}
}
goto LABEL_8;
case 25:
v1 = (_BYTE *)&loc_2;
SetTexMode(2);
if ( GermanMode )
{
TranslateGerman();
v2 = i;
}
else
{
v1 = "\"";
v2 = i;
fprintRTF("\"");
}
goto LABEL_8;
case 27:
v0 = "Processing $, next char <%c>";
v22 = (char)getTexChar();
v2 = v22;
diagnostics(5LL, "Processing $, next char <%c>", v22);
if ( (_BYTE)v22 != 36 || (unsigned int)GetTexMode(5LL, "Processing $, next char <%c>", v23) == 4 )
{
v2 = i;
ungetTexChar(v22);
v1 = (const char *)16386;
CmdEquation(16386LL);
}
else
{
v1 = (const char *)16398;
CmdEquation(16398LL);
}
goto LABEL_8;
case 28:
v0 = "This should not happen, ignoring %%";
v1 = (_BYTE *)(SetTexMode + 1);
v2 = 32;
diagnostics(1LL, "This should not happen, ignoring %%");
goto LABEL_8;
case 29:
if ( g_processing_arrays )
{
v0 = (const char *)(unsigned int)g_field_separator;
v1 = "%c";
v2 = i;
fprintRTF("%c", v0);
}
else if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = "\\tab ";
v2 = i;
fprintRTF("\\tab ");
++g_equation_column;
}
else if ( g_processing_tabular )
{
v1 = "\\cell\\pard\\intbl\\q%c ";
v2 = i;
++actCol;
v0 = (const char *)(unsigned int)*(char *)(colFmt + actCol);
fprintRTF("\\cell\\pard\\intbl\\q%c ", v0);
}
else
{
v1 = "&";
v2 = i;
fprintRTF("&");
}
goto LABEL_8;
case 30:
if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = "'";
v2 = i;
fprintRTF("'");
}
else
{
SetTexMode(2);
v1 = (_BYTE *)(&loc_25 + 2);
v27 = getSameChar(39LL);
v28 = (unsigned int)(v27 + 1);
if ( v27 == 1 )
{
v1 = "\\rdblquote ";
v2 = i;
fprintRTF("\\rdblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v28);
}
else
{
v29 = (unsigned int)v28;
v30 = 0LL;
if ( v27 == -1 )
goto LABEL_11;
do
{
v1 = "\\rquote ";
++v30;
fprintRTF("\\rquote ");
}
while ( v29 != v30 );
v2 = i;
}
}
goto LABEL_8;
case 31:
if ( g_processing_fields && g_escape_parent )
{
v1 = "\\\\(";
v2 = i;
fprintRTF("\\\\(");
}
else
{
v1 = "(";
v2 = i;
fprintRTF("(");
}
goto LABEL_8;
case 32:
if ( g_processing_fields && (v0 = (const char *)g_escape_parent, g_escape_parent) )
{
v1 = "\\\\)";
v2 = i;
fprintRTF("\\\\)");
}
else
{
v1 = ")";
v2 = i;
fprintRTF(")");
}
goto LABEL_8;
case 35:
v2 = g_field_separator;
if ( g_field_separator == 44 && g_processing_fields )
{
v1 = "\\\\,";
fprintRTF("\\\\,");
}
else
{
v1 = ",";
v2 = i;
fprintRTF(",");
}
goto LABEL_8;
case 36:
if ( (unsigned int)(v12 - 4) <= 1
|| (SetTexMode(2), v1 = (_BYTE *)(&loc_29 + 4), (v24 = getSameChar(45LL)) == 0) )
{
v1 = "-";
v2 = i;
fprintRTF("-");
goto LABEL_8;
}
if ( v24 == 1 )
{
v1 = "\\endash ";
v2 = i;
fprintRTF("\\endash ");
goto LABEL_8;
}
if ( v24 == 2 )
{
LABEL_13:
v1 = "\\emdash ";
v2 = i;
fprintRTF("\\emdash ");
goto LABEL_8;
}
v25 = (unsigned int)(v24 + 1);
v26 = 0LL;
if ( v24 == -1 )
goto LABEL_11;
do
{
v1 = "-";
++v26;
fprintRTF("-");
}
while ( v25 != v26 );
v2 = i;
goto LABEL_8;
case 37:
if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = ".";
v2 = i;
fprintRTF(".");
}
else
{
v2 = i;
SetTexMode(2);
fprintRTF(".");
v1 = (const char *)(unsigned int)(char)getTexChar();
ungetTexChar(v1);
}
goto LABEL_8;
case 49:
if ( (unsigned int)(v12 - 4) > 1 && (SetTexMode(2), FrenchMode) )
{
v1 = "\\~:";
v2 = i;
fprintRTF("\\~:");
}
else
{
v1 = ":";
v2 = i;
fprintRTF(":");
}
goto LABEL_8;
case 50:
v2 = g_field_separator;
if ( g_field_separator == 59 && g_processing_fields )
{
v1 = "\\\\;";
fprintRTF("\\\\;");
}
else if ( FrenchMode )
{
v1 = "\\~;";
v2 = i;
fprintRTF("\\~;");
}
else
{
v1 = ";";
v2 = i;
fprintRTF(";");
}
goto LABEL_8;
case 51:
if ( v12 == 6 )
{
v1 = (_BYTE *)&loc_2;
SetTexMode(2);
}
if ( (unsigned int)GetTexMode(v1, "Current character is '%c' mode = %d ret = %d level = %d") == 2 )
{
v37 = getTexChar();
v2 = v37;
if ( v37 == 60 )
{
if ( FrenchMode )
{
skipSpaces();
v38 = getTexChar();
if ( v38 == 126 )
skipSpaces();
else
ungetTexChar((unsigned int)v38);
v1 = "\\'ab\\~";
fprintRTF("\\'ab\\~");
}
else
{
v1 = "\\'ab";
fprintRTF("\\'ab");
}
}
else
{
v2 = i;
ungetTexChar((unsigned int)v37);
v1 = "<";
fprintRTF("<");
}
}
else
{
v1 = "<";
v2 = i;
fprintRTF("<");
}
goto LABEL_8;
case 53:
if ( v12 == 6 )
{
v1 = (_BYTE *)&loc_2;
SetTexMode(2);
}
if ( (unsigned int)GetTexMode(v1, "Current character is '%c' mode = %d ret = %d level = %d") == 2 )
{
v39 = getTexChar();
v2 = v39;
if ( v39 == 62 )
{
v1 = "\\'bb";
fprintRTF("\\'bb");
}
else
{
v2 = i;
ungetTexChar((unsigned int)v39);
v1 = ">";
fprintRTF(">");
}
}
else
{
v1 = ">";
v2 = i;
fprintRTF(">");
}
goto LABEL_8;
case 54:
SetTexMode(2);
v20 = "? ";
v21 = getTexChar();
if ( v21 != 96 )
goto LABEL_26;
v1 = "\\'bf ";
v2 = i;
fprintRTF("\\'bf ");
goto LABEL_8;
case 83:
PushLevels();
TranslateCommand();
CleanStack();
if ( ret <= 0 )
goto LABEL_11;
result = diagnostics(
5LL,
"Exiting Convert via TranslateCommand ret = %d level = %d",
(unsigned int)ret,
RecursionLevel);
goto LABEL_126;
case 85:
v1 = 0LL;
v2 = i;
CmdSuperscript(0LL);
goto LABEL_8;
case 86:
v1 = 0LL;
v2 = i;
CmdSubscript(0LL);
goto LABEL_8;
case 87:
SetTexMode(2);
v1 = (_BYTE *)&loc_60;
v16 = getSameChar(96LL);
v17 = (unsigned int)(v16 + 1);
if ( v16 == 1 )
{
v1 = "\\ldblquote ";
v2 = i;
fprintRTF("\\ldblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v17);
}
else
{
v18 = (unsigned int)v17;
v19 = 0LL;
if ( v16 != -1 )
{
do
{
v1 = "\\lquote ";
++v19;
fprintRTF("\\lquote ");
}
while ( v18 != v19 );
}
LABEL_11:
v2 = i;
}
goto LABEL_8;
case 114:
if ( v12 == 6 )
SetTexMode(2);
CleanStack();
v2 = i;
PushBrace();
v1 = "{";
fprintRTF("{");
goto LABEL_8;
case 115:
if ( (unsigned int)(v12 - 4) > 1 )
goto LABEL_13;
v1 = "|";
v2 = i;
fprintRTF("|");
goto LABEL_8;
case 116:
CleanStack();
v15 = RecursionLevel;
v1 = "}";
ret = v15 - PopBrace();
fprintRTF("}");
if ( ret <= 0 )
goto LABEL_11;
result = diagnostics(5LL, "Exiting Convert via '}' ret = %d level = %d", (unsigned int)ret, RecursionLevel);
LABEL_126:
--ret;
--RecursionLevel;
return result;
case 117:
goto LABEL_7;
default:
if ( (unsigned int)(v12 - 4) > 1 )
{
SetTexMode(2);
v0 = (const char *)(unsigned int)(char)i;
}
else
{
v0 = (const char *)(unsigned int)(char)i;
if ( (unsigned __int8)((i & 0xDF) - 65) <= 0x19u )
{
v1 = "{\\i %c}";
v2 = i;
fprintRTF("{\\i %c}", (unsigned int)(char)i);
goto LABEL_8;
}
}
v1 = "%c";
v2 = i;
fprintRTF("%c", v0);
break;
}
goto LABEL_8;
}
v0 = "Current character is '\\n' mode = %d ret = %d level = %d";
diagnostics(5LL, "Current character is '\\n' mode = %d ret = %d level = %d", v6, v7, (unsigned int)v8);
v34 = GetTexMode(5LL, "Current character is '\\n' mode = %d ret = %d level = %d", v31, v32, v33);
tabcounter = 0;
v35 = v34;
if ( (unsigned int)(v34 - 4) > 1 )
{
v36 = getNonSpace();
if ( v36 != 10 )
{
v1 = (const char *)(unsigned int)v36;
ungetTexChar(v1);
if ( v35 == 6 || v2 == 32 )
{
v2 = 10;
}
else
{
v1 = " ";
v2 = 10;
fprintRTF(" ");
}
goto LABEL_8;
}
CmdEndParagraph(0LL);
}
v2 = 10;
v1 = (const char *)(unsigned int)(char)getNonBlank();
ungetTexChar(v1);
LABEL_8:
++tabcounter;
}
--RecursionLevel;
return diagnostics(5LL, "Exiting Convert via exhaustion ret = %d", (unsigned int)ret);
}

canonical_decompiled_code:
__int64 func4()
{
const char *v0; // rsi
const char *v1; // rdi
char v2; // bp
__int64 v3; // rdx
int i; // ebx
__int64 v5; // r8
unsigned int v6; // eax
__int64 v7; // rcx
__int64 v8; // r9
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
int v12; // eax
char v13; // dl
__int64 result; // rax
int v15; // ebp
int v16; // eax
__int64 v17; // rdx
__int64 v18; // r12
__int64 v19; // rbp
const char *v20; // rdi
char v21; // bp
unsigned int v22; // er12
__int64 v23; // rdx
int v24; // er8
__int64 v25; // r12
__int64 v26; // rbp
int v27; // eax
__int64 v28; // rdx
__int64 v29; // r12
__int64 v30; // rbp
__int64 v31; // rdx
__int64 v32; // rcx
__int64 v33; // r8
int v34; // eax
int v35; // ebx
char v36; // al
char v37; // al
char v38; // al
char v39; // al

v0 = "Entering Convert ret = %d";
v1 = (_BYTE *)&loc_3;
v2 = 0;
diagnostics(3LL, "Entering Convert ret = %d", (unsigned int)ret);
++RecursionLevel;
PushLevels();
for ( i = getTexChar(); (_BYTE)i; i = getTexChar() )
{
v6 = func1(v1, v0, v3, (unsigned int)ret, v5, RecursionLevel);
if ( (_BYTE)i != 10 )
{
v0 = "Current character is '%c' mode = %d ret = %d level = %d";
v1 = (_BYTE *)&loc_5;
diagnostics(
5LL,
"Current character is '%c' mode = %d ret = %d level = %d",
(unsigned int)(char)i,
v6,
(unsigned int)v7,
v8);
v12 = func1(
5LL,
"Current character is '%c' mode = %d ret = %d level = %d",
(unsigned int)(i - 9),
v9,
v10,
v11);
switch ( v13 )
{
case 0:
v0 = "This should not happen, ignoring \\t";
v1 = (_BYTE *)(SetTexMode + 1);
v2 = 32;
diagnostics(1LL, "This should not happen, ignoring \\t");
goto LABEL_8;
case 4:
v0 = "This should not happen, ignoring \\r";
v1 = (_BYTE *)(SetTexMode + 1);
v2 = 32;
diagnostics(1LL, "This should not happen, ignoring \\r");
goto LABEL_8;
case 23:
if ( (unsigned int)(v12 - 4) <= 2 )
goto LABEL_8;
if ( v2 == 32 || v2 == 10 )
goto LABEL_11;
if ( v12 == 3 )
{
LABEL_7:
v1 = "\\~";
v2 = i;
fprintRTF("\\~");
}
else
{
v1 = " ";
v2 = i;
fprintRTF(" ");
}
goto LABEL_8;
case 24:
if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = "!";
v2 = i;
fprintRTF("!");
}
else
{
func0(2);
v20 = "! ";
v21 = getTexChar();
if ( v21 == 96 )
{
v1 = "\\'a1 ";
v2 = i;
fprintRTF("\\'a1 ");
}
else
{
LABEL_26:
fprintRTF(v20);
v1 = (const char *)(unsigned int)v21;
v2 = i;
ungetTexChar(v1);
}
}
goto LABEL_8;
case 25:
v1 = (_BYTE *)&loc_2;
func0(2);
if ( GermanMode )
{
TranslateGerman();
v2 = i;
}
else
{
v1 = "\"";
v2 = i;
fprintRTF("\"");
}
goto LABEL_8;
case 27:
v0 = "Processing $, next char <%c>";
v22 = (char)getTexChar();
v2 = v22;
diagnostics(5LL, "Processing $, next char <%c>", v22);
if ( (_BYTE)v22 != 36 || (unsigned int)func1(5LL, "Processing $, next char <%c>", v23) == 4 )
{
v2 = i;
ungetTexChar(v22);
v1 = (const char *)16386;
CmdEquation(16386LL);
}
else
{
v1 = (const char *)16398;
CmdEquation(16398LL);
}
goto LABEL_8;
case 28:
v0 = "This should not happen, ignoring %%";
v1 = (_BYTE *)(SetTexMode + 1);
v2 = 32;
diagnostics(1LL, "This should not happen, ignoring %%");
goto LABEL_8;
case 29:
if ( g_processing_arrays )
{
v0 = (const char *)(unsigned int)g_field_separator;
v1 = "%c";
v2 = i;
fprintRTF("%c", v0);
}
else if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = "\\tab ";
v2 = i;
fprintRTF("\\tab ");
++g_equation_column;
}
else if ( g_processing_tabular )
{
v1 = "\\cell\\pard\\intbl\\q%c ";
v2 = i;
++actCol;
v0 = (const char *)(unsigned int)*(char *)(colFmt + actCol);
fprintRTF("\\cell\\pard\\intbl\\q%c ", v0);
}
else
{
v1 = "&";
v2 = i;
fprintRTF("&");
}
goto LABEL_8;
case 30:
if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = "'";
v2 = i;
fprintRTF("'");
}
else
{
func0(2);
v1 = (_BYTE *)(&loc_25 + 2);
v27 = getSameChar(39LL);
v28 = (unsigned int)(v27 + 1);
if ( v27 == 1 )
{
v1 = "\\rdblquote ";
v2 = i;
fprintRTF("\\rdblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v28);
}
else
{
v29 = (unsigned int)v28;
v30 = 0LL;
if ( v27 == -1 )
goto LABEL_11;
do
{
v1 = "\\rquote ";
++v30;
fprintRTF("\\rquote ");
}
while ( v29 != v30 );
v2 = i;
}
}
goto LABEL_8;
case 31:
if ( g_processing_fields && g_escape_parent )
{
v1 = "\\\\(";
v2 = i;
fprintRTF("\\\\(");
}
else
{
v1 = "(";
v2 = i;
fprintRTF("(");
}
goto LABEL_8;
case 32:
if ( g_processing_fields && (v0 = (const char *)g_escape_parent, g_escape_parent) )
{
v1 = "\\\\)";
v2 = i;
fprintRTF("\\\\)");
}
else
{
v1 = ")";
v2 = i;
fprintRTF(")");
}
goto LABEL_8;
case 35:
v2 = g_field_separator;
if ( g_field_separator == 44 && g_processing_fields )
{
v1 = "\\\\,";
fprintRTF("\\\\,");
}
else
{
v1 = ",";
v2 = i;
fprintRTF(",");
}
goto LABEL_8;
case 36:
if ( (unsigned int)(v12 - 4) <= 1
|| (func0(2), v1 = (_BYTE *)(&loc_29 + 4), (v24 = getSameChar(45LL)) == 0) )
{
v1 = "-";
v2 = i;
fprintRTF("-");
goto LABEL_8;
}
if ( v24 == 1 )
{
v1 = "\\endash ";
v2 = i;
fprintRTF("\\endash ");
goto LABEL_8;
}
if ( v24 == 2 )
{
LABEL_13:
v1 = "\\emdash ";
v2 = i;
fprintRTF("\\emdash ");
goto LABEL_8;
}
v25 = (unsigned int)(v24 + 1);
v26 = 0LL;
if ( v24 == -1 )
goto LABEL_11;
do
{
v1 = "-";
++v26;
fprintRTF("-");
}
while ( v25 != v26 );
v2 = i;
goto LABEL_8;
case 37:
if ( (unsigned int)(v12 - 4) <= 1 )
{
v1 = ".";
v2 = i;
fprintRTF(".");
}
else
{
v2 = i;
func0(2);
fprintRTF(".");
v1 = (const char *)(unsigned int)(char)getTexChar();
ungetTexChar(v1);
}
goto LABEL_8;
case 49:
if ( (unsigned int)(v12 - 4) > 1 && (func0(2), FrenchMode) )
{
v1 = "\\~:";
v2 = i;
fprintRTF("\\~:");
}
else
{
v1 = ":";
v2 = i;
fprintRTF(":");
}
goto LABEL_8;
case 50:
v2 = g_field_separator;
if ( g_field_separator == 59 && g_processing_fields )
{
v1 = "\\\\;";
fprintRTF("\\\\;");
}
else if ( FrenchMode )
{
v1 = "\\~;";
v2 = i;
fprintRTF("\\~;");
}
else
{
v1 = ";";
v2 = i;
fprintRTF(";");
}
goto LABEL_8;
case 51:
if ( v12 == 6 )
{
v1 = (_BYTE *)&loc_2;
func0(2);
}
if ( (unsigned int)func1(v1, "Current character is '%c' mode = %d ret = %d level = %d") == 2 )
{
v37 = getTexChar();
v2 = v37;
if ( v37 == 60 )
{
if ( FrenchMode )
{
skipSpaces();
v38 = getTexChar();
if ( v38 == 126 )
skipSpaces();
else
ungetTexChar((unsigned int)v38);
v1 = "\\'ab\\~";
fprintRTF("\\'ab\\~");
}
else
{
v1 = "\\'ab";
fprintRTF("\\'ab");
}
}
else
{
v2 = i;
ungetTexChar((unsigned int)v37);
v1 = "<";
fprintRTF("<");
}
}
else
{
v1 = "<";
v2 = i;
fprintRTF("<");
}
goto LABEL_8;
case 53:
if ( v12 == 6 )
{
v1 = (_BYTE *)&loc_2;
func0(2);
}
if ( (unsigned int)func1(v1, "Current character is '%c' mode = %d ret = %d level = %d") == 2 )
{
v39 = getTexChar();
v2 = v39;
if ( v39 == 62 )
{
v1 = "\\'bb";
fprintRTF("\\'bb");
}
else
{
v2 = i;
ungetTexChar((unsigned int)v39);
v1 = ">";
fprintRTF(">");
}
}
else
{
v1 = ">";
v2 = i;
fprintRTF(">");
}
goto LABEL_8;
case 54:
func0(2);
v20 = "? ";
v21 = getTexChar();
if ( v21 != 96 )
goto LABEL_26;
v1 = "\\'bf ";
v2 = i;
fprintRTF("\\'bf ");
goto LABEL_8;
case 83:
PushLevels();
func2();
CleanStack();
if ( ret <= 0 )
goto LABEL_11;
result = diagnostics(
5LL,
"Exiting Convert via TranslateCommand ret = %d level = %d",
(unsigned int)ret,
RecursionLevel);
goto LABEL_126;
case 85:
v1 = 0LL;
v2 = i;
CmdSuperscript(0LL);
goto LABEL_8;
case 86:
v1 = 0LL;
v2 = i;
CmdSubscript(0LL);
goto LABEL_8;
case 87:
func0(2);
v1 = (_BYTE *)&loc_60;
v16 = getSameChar(96LL);
v17 = (unsigned int)(v16 + 1);
if ( v16 == 1 )
{
v1 = "\\ldblquote ";
v2 = i;
fprintRTF("\\ldblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v17);
}
else
{
v18 = (unsigned int)v17;
v19 = 0LL;
if ( v16 != -1 )
{
do
{
v1 = "\\lquote ";
++v19;
fprintRTF("\\lquote ");
}
while ( v18 != v19 );
}
LABEL_11:
v2 = i;
}
goto LABEL_8;
case 114:
if ( v12 == 6 )
func0(2);
CleanStack();
v2 = i;
PushBrace();
v1 = "{";
fprintRTF("{");
goto LABEL_8;
case 115:
if ( (unsigned int)(v12 - 4) > 1 )
goto LABEL_13;
v1 = "|";
v2 = i;
fprintRTF("|");
goto LABEL_8;
case 116:
CleanStack();
v15 = RecursionLevel;
v1 = "}";
ret = v15 - PopBrace();
fprintRTF("}");
if ( ret <= 0 )
goto LABEL_11;
result = diagnostics(5LL, "Exiting Convert via '}' ret = %d level = %d", (unsigned int)ret, RecursionLevel);
LABEL_126:
--ret;
--RecursionLevel;
return result;
case 117:
goto LABEL_7;
default:
if ( (unsigned int)(v12 - 4) > 1 )
{
func0(2);
v0 = (const char *)(unsigned int)(char)i;
}
else
{
v0 = (const char *)(unsigned int)(char)i;
if ( (unsigned __int8)((i & 0xDF) - 65) <= 0x19u )
{
v1 = "{\\i %c}";
v2 = i;
fprintRTF("{\\i %c}", (unsigned int)(char)i);
goto LABEL_8;
}
}
v1 = "%c";
v2 = i;
fprintRTF("%c", v0);
break;
}
goto LABEL_8;
}
v0 = "Current character is '\\n' mode = %d ret = %d level = %d";
diagnostics(5LL, "Current character is '\\n' mode = %d ret = %d level = %d", v6, v7, (unsigned int)v8);
v34 = func1(5LL, "Current character is '\\n' mode = %d ret = %d level = %d", v31, v32, v33);
tabcounter = 0;
v35 = v34;
if ( (unsigned int)(v34 - 4) > 1 )
{
v36 = getNonSpace();
if ( v36 != 10 )
{
v1 = (const char *)(unsigned int)v36;
ungetTexChar(v1);
if ( v35 == 6 || v2 == 32 )
{
v2 = 10;
}
else
{
v1 = " ";
v2 = 10;
fprintRTF(" ");
}
goto LABEL_8;
}
CmdEndParagraph(0LL);
}
v2 = 10;
v1 = (const char *)(unsigned int)(char)getNonBlank();
ungetTexChar(v1);
LABEL_8:
++tabcounter;
}
--RecursionLevel;
return diagnostics(5LL, "Exiting Convert via exhaustion ret = %d", (unsigned int)ret);
}

original_code:
void
Convert()
{
 char cThis = '\n';
 char cLast = '\0';
 char cNext;
 int mode, count,pending_new_paragraph;
 diagnostics(3, "Entering Convert ret = %d", ret);
 RecursionLevel++;
 PushLevels();
 while ((cThis = getTexChar()) && cThis != '\0') {
  if (cThis == '\n')
   diagnostics(5, "Current character is '\\n' mode = %d ret = %d level = %d", GetTexMode(), ret, RecursionLevel);
  else
   diagnostics(5, "Current character is '%c' mode = %d ret = %d level = %d", cThis, GetTexMode(), ret, RecursionLevel);
  mode = GetTexMode();
  pending_new_paragraph--;
  switch (cThis) {
  case '\\':
   PushLevels();
   TranslateCommand();
   CleanStack();
   if (ret > 0) {
    diagnostics(5, "Exiting Convert via TranslateCommand ret = %d level = %d", ret, RecursionLevel);
    ret--;
    RecursionLevel--;
    return;
   }
   break;
  case '{':
   if (mode==6) SetTexMode(2);
   CleanStack();
   PushBrace();
   fprintRTF("{");
   break;
  case '}':
   CleanStack();
   ret = RecursionLevel - PopBrace();
   fprintRTF("}");
   if (ret > 0) {
    diagnostics(5, "Exiting Convert via '}' ret = %d level = %d", ret, RecursionLevel);
    ret--;
    RecursionLevel--;
    return;
   }
   break;
  case ' ':
   if (mode==6 || mode==4 || mode==5)
        cThis = cLast;
   else if ( cLast != ' ' && cLast != '\n' ) {
    if (GetTexMode()==3)
     fprintRTF("\\~");
    else
     fprintRTF(" ");
   }
   break;
  case '\n':
   tabcounter = 0;
   if (mode==4 || mode==5) {
    cNext = getNonBlank();
    ungetTexChar(cNext);
   } else {
    cNext = getNonSpace();
    if (cNext == '\n') {
     pending_new_paragraph=2;
     CmdEndParagraph(0);
     cNext = getNonBlank();
     ungetTexChar(cNext);
    } else {
     ungetTexChar(cNext);
     if (mode != 6 && cLast != ' ')
      fprintRTF(" ");
    }
   }
   break;
  case '$':
   cNext = getTexChar();
   diagnostics(5,"Processing $, next char <%c>",cNext);
   if (cNext == '$' && GetTexMode() != 4)
    CmdEquation(14 | 0x4000);
   else {
    ungetTexChar(cNext);
    CmdEquation(2 | 0x4000);
   }
   break;
  case '&':
   if (g_processing_arrays) {
    fprintRTF("%c",g_field_separator);
    break;
   }
   if (GetTexMode() == 4 || GetTexMode() == 5) {
    fprintRTF("\\tab ");
    g_equation_column++;
    break;
   }
   if (g_processing_tabular) {
    actCol++;
    fprintRTF("\\cell\\pard\\intbl\\q%c ", colFmt[actCol]);
    break;
   }
   fprintRTF("&");
   break;
  case '~':
   fprintRTF("\\~");
   break;
  case '^':
   CmdSuperscript(0);
   break;
  case '_':
   CmdSubscript(0);
   break;
  case '-':
   if (mode == 4 || mode == 5)
    fprintRTF("-");
   else {
    SetTexMode(2);
    count = getSameChar('-')+1;
    if (count == 1)
     fprintRTF("-");
    else if (count == 2)
     fprintRTF("\\endash ");
    else if (count == 3)
     fprintRTF("\\emdash ");
    else
     while (count--) fprintRTF("-");
   }
   break;
  case '|':
   if (mode == 4 || mode == 5)
    fprintRTF("|");
   else
    fprintRTF("\\emdash ");
   break;
  case '\'':
   if (mode == 4 || mode == 5)
     fprintRTF("'");
   else {
    SetTexMode(2);
    count = getSameChar('\'')+1;
    if (count == 2)
     fprintRTF("\\rdblquote ");
    else
     while (count--) fprintRTF("\\rquote ");
   }
   break;
  case '`':
   SetTexMode(2);
   count = getSameChar('`')+1;
   if (count == 2)
    fprintRTF("\\ldblquote ");
   else
    while (count--) fprintRTF("\\lquote ");
   break;
  case '\"':
   SetTexMode(2);
   if (GermanMode)
    TranslateGerman();
   else
    fprintRTF("\"");
   break;
  case '<':
   if (mode == 6) SetTexMode(2);
   if (GetTexMode() == 2){
    cNext = getTexChar();
    if (cNext == '<') {
     if (FrenchMode) {
      skipSpaces();
      cNext = getTexChar();
      if (cNext == '~')
       skipSpaces();
      else
       ungetTexChar(cNext);
      fprintRTF("\\'ab\\~");
     } else
      fprintRTF("\\'ab");
    } else {
     ungetTexChar(cNext);
     fprintRTF("<");
    }
   } else
    fprintRTF("<");
   break;
  case '>':
   if (mode == 6) SetTexMode(2);
   if (GetTexMode() == 2){
    cNext = getTexChar();
    if (cNext == '>')
     fprintRTF("\\'bb");
    else {
     ungetTexChar(cNext);
     fprintRTF(">");
    }
   } else
    fprintRTF(">");
   break;
  case '!':
   if (mode == 4 || mode == 5)
    fprintRTF("!");
   else {
    SetTexMode(2);
    if ((cNext = getTexChar()) && cNext == '`') {
     fprintRTF("\\'a1 ");
    } else {
     fprintRTF("! ");
     ungetTexChar(cNext);
    }
   }
   break;
  case '?':
   SetTexMode(2);
   if ((cNext = getTexChar()) && cNext == '`') {
    fprintRTF("\\'bf ");
   } else {
    fprintRTF("? ");
    ungetTexChar(cNext);
   }
   break;
  case ':':
   if (mode == 4 || mode == 5)
    fprintRTF(":");
   else {
    SetTexMode(2);
    if (FrenchMode)
     fprintRTF("\\~:");
      else
     fprintRTF(":");
   }
   break;
  case '.':
   if (mode == 4 || mode == 5)
    fprintRTF(".");
   else {
    SetTexMode(2);
    fprintRTF(".");
    cNext = getTexChar();
    if (0 && cNext == ' ' && (((*__ctype_b_loc ())[(int) (((int)cLast))] & (unsigned short int) _ISalpha) && !((*__ctype_b_loc ())[(int) (((int) cLast))] & (unsigned short int) _ISupper)))
     fprintRTF(" ");
    ungetTexChar(cNext);
   }
   break;
  case '\t':
   diagnostics(1, "This should not happen, ignoring \\t");
   cThis = ' ';
   break;
  case '\r':
   diagnostics(1, "This should not happen, ignoring \\r");
   cThis = ' ';
   break;
  case '%':
   diagnostics(1, "This should not happen, ignoring %%");
   cThis = ' ';
   break;
  case '(':
   if (g_processing_fields&&g_escape_parent)
    fprintRTF("\\\\(");
   else
    fprintRTF("(");
   break;
  case ')':
   if (g_processing_fields&&g_escape_parent)
    fprintRTF("\\\\)");
   else
    fprintRTF(")");
   break;
  case ';':
   if (g_field_separator == ';' && g_processing_fields)
    fprintRTF("\\\\;");
   else
    if (FrenchMode)
     fprintRTF("\\~;");
      else
     fprintRTF(";");
  break;
  case ',':
   if (g_field_separator == ',' && g_processing_fields)
    fprintRTF("\\\\,");
   else
    fprintRTF(",");
   break;
  default:
   if (mode == 4 || mode == 5) {
    if (('a' <= cThis && cThis <= 'z') || ('A' <= cThis && cThis <= 'Z'))
     fprintRTF("{\\i %c}", cThis);
    else
     fprintRTF("%c", cThis);
   } else {
    SetTexMode(2);
    fprintRTF("%c", cThis);
   }
   break;
  }
  tabcounter++;
  cLast = cThis;
 }
 RecursionLevel--;
 diagnostics(5, "Exiting Convert via exhaustion ret = %d", ret);
}

canonical_original_code:
void Convert()
{
 char cThis = '\n';
 char cLast = '\0';
 char cNext;
 int mode; int count; int pending_new_paragraph;
 diagnostics(3, "Entering Convert ret = %d", ret);
 RecursionLevel++;
 PushLevels();
 while ((cThis = getTexChar()) && cThis != '\0') {
  if (cThis == '\n')
   diagnostics(5, "Current character is '\\n' mode = %d ret = %d level = %d", GetTexMode(), ret, RecursionLevel);
  else
   diagnostics(5, "Current character is '%c' mode = %d ret = %d level = %d", cThis, GetTexMode(), ret, RecursionLevel);
  mode = GetTexMode();
  pending_new_paragraph--;
  switch (cThis) {
  case '\\':
   PushLevels();
   TranslateCommand();
   CleanStack();
   if (ret > 0) {
    diagnostics(5, "Exiting Convert via TranslateCommand ret = %d level = %d", ret, RecursionLevel);
    ret--;
    RecursionLevel--;
    return;
   }
   break;
  case '{':
   if (mode==6) SetTexMode(2);
   CleanStack();
   PushBrace();
   fprintRTF("{");
   break;
  case '}':
   CleanStack();
   ret = RecursionLevel - PopBrace();
   fprintRTF("}");
   if (ret > 0) {
    diagnostics(5, "Exiting Convert via '}' ret = %d level = %d", ret, RecursionLevel);
    ret--;
    RecursionLevel--;
    return;
   }
   break;
  case ' ':
   if (mode==6 || mode==4 || mode==5)
        cThis = cLast;
   else if ( cLast != ' ' && cLast != '\n' ) {
    if (GetTexMode()==3)
     fprintRTF("\\~");
    else
     fprintRTF(" ");
   }
   break;
  case '\n':
   tabcounter = 0;
   if (mode==4 || mode==5) {
    cNext = getNonBlank();
    ungetTexChar(cNext);
   } else {
    cNext = getNonSpace();
    if (cNext == '\n') {
     pending_new_paragraph=2;
     CmdEndParagraph(0);
     cNext = getNonBlank();
     ungetTexChar(cNext);
    } else {
     ungetTexChar(cNext);
     if (mode != 6 && cLast != ' ')
      fprintRTF(" ");
    }
   }
   break;
  case '$':
   cNext = getTexChar();
   diagnostics(5,"Processing $, next char <%c>",cNext);
   if (cNext == '$' && GetTexMode() != 4)
    CmdEquation(14 | 0x4000);
   else {
    ungetTexChar(cNext);
    CmdEquation(2 | 0x4000);
   }
   break;
  case '&':
   if (g_processing_arrays) {
    fprintRTF("%c",g_field_separator);
    break;
   }
   if (GetTexMode() == 4 || GetTexMode() == 5) {
    fprintRTF("\\tab ");
    g_equation_column++;
    break;
   }
   if (g_processing_tabular) {
    actCol++;
    fprintRTF("\\cell\\pard\\intbl\\q%c ", colFmt[actCol]);
    break;
   }
   fprintRTF("&");
   break;
  case '~':
   fprintRTF("\\~");
   break;
  case '^':
   CmdSuperscript(0);
   break;
  case '_':
   CmdSubscript(0);
   break;
  case '-':
   if (mode == 4 || mode == 5)
    fprintRTF("-");
   else {
    SetTexMode(2);
    count = getSameChar('-')+1;
    if (count == 1)
     fprintRTF("-");
    else if (count == 2)
     fprintRTF("\\endash ");
    else if (count == 3)
     fprintRTF("\\emdash ");
    else
     while (count--) fprintRTF("-");
   }
   break;
  case '|':
   if (mode == 4 || mode == 5)
    fprintRTF("|");
   else
    fprintRTF("\\emdash ");
   break;
  case '\'':
   if (mode == 4 || mode == 5)
     fprintRTF("'");
   else {
    SetTexMode(2);
    count = getSameChar('\'')+1;
    if (count == 2)
     fprintRTF("\\rdblquote ");
    else
     while (count--) fprintRTF("\\rquote ");
   }
   break;
  case '`':
   SetTexMode(2);
   count = getSameChar('`')+1;
   if (count == 2)
    fprintRTF("\\ldblquote ");
   else
    while (count--) fprintRTF("\\lquote ");
   break;
  case '\"':
   SetTexMode(2);
   if (GermanMode)
    TranslateGerman();
   else
    fprintRTF("\"");
   break;
  case '<':
   if (mode == 6) SetTexMode(2);
   if (GetTexMode() == 2){
    cNext = getTexChar();
    if (cNext == '<') {
     if (FrenchMode) {
      skipSpaces();
      cNext = getTexChar();
      if (cNext == '~')
       skipSpaces();
      else
       ungetTexChar(cNext);
      fprintRTF("\\'ab\\~");
     } else
      fprintRTF("\\'ab");
    } else {
     ungetTexChar(cNext);
     fprintRTF("<");
    }
   } else
    fprintRTF("<");
   break;
  case '>':
   if (mode == 6) SetTexMode(2);
   if (GetTexMode() == 2){
    cNext = getTexChar();
    if (cNext == '>')
     fprintRTF("\\'bb");
    else {
     ungetTexChar(cNext);
     fprintRTF(">");
    }
   } else
    fprintRTF(">");
   break;
  case '!':
   if (mode == 4 || mode == 5)
    fprintRTF("!");
   else {
    SetTexMode(2);
    if ((cNext = getTexChar()) && cNext == '`') {
     fprintRTF("\\'a1 ");
    } else {
     fprintRTF("! ");
     ungetTexChar(cNext);
    }
   }
   break;
  case '?':
   SetTexMode(2);
   if ((cNext = getTexChar()) && cNext == '`') {
    fprintRTF("\\'bf ");
   } else {
    fprintRTF("? ");
    ungetTexChar(cNext);
   }
   break;
  case ':':
   if (mode == 4 || mode == 5)
    fprintRTF(":");
   else {
    SetTexMode(2);
    if (FrenchMode)
     fprintRTF("\\~:");
      else
     fprintRTF(":");
   }
   break;
  case '.':
   if (mode == 4 || mode == 5)
    fprintRTF(".");
   else {
    SetTexMode(2);
    fprintRTF(".");
    cNext = getTexChar();
    if (0 && cNext == ' ' && (((*__ctype_b_loc ())[(int) (((int)cLast))] & (unsigned short) _ISalpha) && !((*__ctype_b_loc ())[(int) (((int) cLast))] & (unsigned short) _ISupper)))
     fprintRTF(" ");
    ungetTexChar(cNext);
   }
   break;
  case '\t':
   diagnostics(1, "This should not happen, ignoring \\t");
   cThis = ' ';
   break;
  case '\r':
   diagnostics(1, "This should not happen, ignoring \\r");
   cThis = ' ';
   break;
  case '%':
   diagnostics(1, "This should not happen, ignoring %%");
   cThis = ' ';
   break;
  case '(':
   if (g_processing_fields&&g_escape_parent)
    fprintRTF("\\\\(");
   else
    fprintRTF("(");
   break;
  case ')':
   if (g_processing_fields&&g_escape_parent)
    fprintRTF("\\\\)");
   else
    fprintRTF(")");
   break;
  case ';':
   if (g_field_separator == ';' && g_processing_fields)
    fprintRTF("\\\\;");
   else
    if (FrenchMode)
     fprintRTF("\\~;");
      else
     fprintRTF(";");
  break;
  case ',':
   if (g_field_separator == ',' && g_processing_fields)
    fprintRTF("\\\\,");
   else
    fprintRTF(",");
   break;
  default:
   if (mode == 4 || mode == 5) {
    if (('a' <= cThis && cThis <= 'z') || ('A' <= cThis && cThis <= 'Z'))
     fprintRTF("{\\i %c}", cThis);
    else
     fprintRTF("%c", cThis);
   } else {
    SetTexMode(2);
    fprintRTF("%c", cThis);
   }
   break;
  }
  tabcounter++;
  cLast = cThis;
 }
 RecursionLevel--;
 diagnostics(5, "Exiting Convert via exhaustion ret = %d", ret);
}

variable_types: cLast char

variable_types: cNext char

variable_types: count int


ConvertString

decompiled_code:
void __fastcall ConvertString(char *src)
{
size_t v1; // rbx
char v2[125]; // [rsp-7Ch] [rbp-118h] BYREF
int v3; // [rsp+1h] [rbp-9Bh]
char v4; // [rsp+5h] [rbp-97h]
char dest[150]; // [rsp+6h] [rbp-96h] BYREF

if ( src )
{
v1 = strlen(src);
if ( v1 <= 0xF9 )
{
strncpy(v2, src, 0xFAuLL);
if ( (unsigned int)PushSource(0LL, src) )
return;
}
else
{
strncpy(v2, src, 0x7DuLL);
v3 = 774778378;
v4 = 10;
strncpy(dest, &src[v1 - 125], 0x7DuLL);
dest[125] = 0;
if ( (unsigned int)PushSource(0LL, src) )
return;
}
diagnostics(4LL, "Entering Convert() from StringConvert()\n******\n%s\n*****", v2);
while ( (unsigned int)StillSource() )
Convert();
PopSource();
diagnostics(4LL, "Exiting Convert() from StringConvert()");
}
}

canonical_decompiled_code:
void __fastcall func5(char *src)
{
size_t v1; // rbx
char v2[125]; // [rsp-7Ch] [rbp-118h] BYREF
int v3; // [rsp+1h] [rbp-9Bh]
char v4; // [rsp+5h] [rbp-97h]
char dest[150]; // [rsp+6h] [rbp-96h] BYREF

if ( src )
{
v1 = strlen(src);
if ( v1 <= 0xF9 )
{
strncpy(v2, src, 0xFAuLL);
if ( (unsigned int)PushSource(0LL, src) )
return;
}
else
{
strncpy(v2, src, 0x7DuLL);
v3 = 774778378;
v4 = 10;
strncpy(dest, &src[v1 - 125], 0x7DuLL);
dest[125] = 0;
if ( (unsigned int)PushSource(0LL, src) )
return;
}
diagnostics(4LL, "Entering Convert() from StringConvert()\n******\n%s\n*****", v2);
while ( (unsigned int)StillSource() )
func4();
PopSource();
diagnostics(4LL, "Exiting Convert() from StringConvert()");
}
}

original_code:
void
ConvertString(char *string)
{
 char temp[256];
 if (string==((void *)0)) return;
 if (strlen(string)<250)
  strncpy(temp,string,250);
 else {
  strncpy(temp,string,125);
  strncpy(temp+125,"\n...\n", 5);
  strncpy(temp+130,string+strlen(string)-125,125);
  temp[255] = '\0';
 }
 if (PushSource(((void *)0), string) == 0) {
  diagnostics(4, "Entering Convert() from StringConvert()\n******\n%s\n*****",temp);
  while (StillSource())
   Convert();
  PopSource();
  diagnostics(4, "Exiting Convert() from StringConvert()");
 }
}

variable_types:
string
char *

variable_types:
temp
char [256]


CmdSignature

decompiled_code:
void *CmdSignature()
{
void *result; // rax

if ( g_letterSignature )
free(g_letterSignature);
result = (void *)getBraceParam();
g_letterSignature = result;
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

if ( g_letterSignature )
free(g_letterSignature);
result = (void *)getBraceParam();
g_letterSignature = result;
return result;
}

original_code:
void
CmdSignature(int code)
{
 if (g_letterSignature)
  free(g_letterSignature);
 g_letterSignature = getBraceParam();
}

variable_types: code int


CmdAddress

decompiled_code:
void *CmdAddress()
{
void *result; // rax

if ( g_letterReturnAddress )
free(g_letterReturnAddress);
result = (void *)getBraceParam();
g_letterReturnAddress = result;
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

if ( g_letterReturnAddress )
free(g_letterReturnAddress);
result = (void *)getBraceParam();
g_letterReturnAddress = result;
return result;
}

original_code:
void
CmdAddress(int code)
{
 if (g_letterReturnAddress)
  free(g_letterReturnAddress);
 g_letterReturnAddress = getBraceParam();
}


CmdLetter

decompiled_code:
void *__fastcall CmdLetter(__int16 a1)
{
void *result; // rax

if ( (a1 & 0x4000) == 0 )
return (void *)PopEnvironment();
PushEnvironment(8LL);
if ( g_letterToAddress )
free(g_letterToAddress);
result = (void *)getBraceParam();
g_letterToAddress = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int16 a1)
{
void *result; // rax

if ( (a1 & 0x4000) == 0 )
return (void *)PopEnvironment();
PushEnvironment(8LL);
if ( g_letterToAddress )
free(g_letterToAddress);
result = (void *)getBraceParam();
g_letterToAddress = result;
return result;
}

original_code:
void
CmdLetter(int code)
{
 if (code & 0x4000) {
  PushEnvironment(8);
  if (g_letterToAddress)
   free(g_letterToAddress);
  g_letterToAddress = getBraceParam();
 } else {
  PopEnvironment();
 }
}


CmdOpening

decompiled_code:
__int64 CmdOpening()
{
char v0; // bl
void *v1; // rbp

v0 = alignment;
alignment = 114;
fprintRTF("\n\\par\\pard\\q%c ", 114LL);
diagnostics(5LL, "Entering ConvertString() from CmdAddress");
ConvertString(g_letterReturnAddress);
diagnostics(5LL, "Exiting ConvertString() from CmdAddress");
fprintRTF("\\par\\chdate ");
alignment = 108;
fprintRTF("\n\\par\\pard\\q%c ", 108LL);
diagnostics(4LL, "Entering Convert() from CmdOpening");
ConvertString(g_letterToAddress);
diagnostics(4LL, "Exiting Convert() from CmdOpening");
v1 = (void *)getBraceParam();
ConvertString(v1);
free(v1);
alignment = v0;
return fprintRTF("\n\\par\\pard\\q%c ", (unsigned int)v0);
}

canonical_decompiled_code:
__int64 func3()
{
char v0; // bl
void *v1; // rbp

v0 = alignment;
alignment = 114;
fprintRTF("\n\\par\\pard\\q%c ", 114LL);
diagnostics(5LL, "Entering ConvertString() from CmdAddress");
ConvertString(g_letterReturnAddress);
diagnostics(5LL, "Exiting ConvertString() from CmdAddress");
fprintRTF("\\par\\chdate ");
alignment = 108;
fprintRTF("\n\\par\\pard\\q%c ", 108LL);
diagnostics(4LL, "Entering Convert() from CmdOpening");
ConvertString(g_letterToAddress);
diagnostics(4LL, "Exiting Convert() from CmdOpening");
v1 = (void *)getBraceParam();
ConvertString(v1);
free(v1);
alignment = v0;
return fprintRTF("\n\\par\\pard\\q%c ", (unsigned int)v0);
}

original_code:
void
CmdOpening(int code)
{
 char oldalignment;
 char *s;
 g_letterOpened = 1;
 oldalignment=alignment;
 alignment = 'r';
 fprintRTF("\n\\par\\pard\\q%c ", alignment);
 diagnostics(5, "Entering ConvertString() from CmdAddress");
 ConvertString(g_letterReturnAddress);
 diagnostics(5, "Exiting ConvertString() from CmdAddress");
 fprintRTF("\\par\\chdate ");
 alignment = 'l';
 fprintRTF("\n\\par\\pard\\q%c ", alignment);
 diagnostics(4, "Entering Convert() from CmdOpening");
 ConvertString(g_letterToAddress);
 diagnostics(4, "Exiting Convert() from CmdOpening");
 s = getBraceParam();
 ConvertString(s);
 free(s);
 alignment = oldalignment;
 fprintRTF("\n\\par\\pard\\q%c ", alignment);
}

variable_types: oldalignment char


CmdClosing

decompiled_code:
__int64 CmdClosing()
{
char v0; // bl
void *v1; // rbp

v0 = alignment;
alignment = 114;
fprintRTF("\n\\par\\pard\\q%c ", 114LL);
diagnostics(5LL, "Entering ConvertString() from CmdClosing");
v1 = (void *)getBraceParam();
ConvertString(v1);
free(v1);
diagnostics(5LL, "Exiting ConvertString() from CmdClosing");
fprintRTF("\n\\par\\par\\par ");
diagnostics(5LL, "Entering ConvertString() from CmdSignature");
ConvertString(g_letterSignature);
diagnostics(5LL, "Exiting ConvertString() from CmdSignature");
alignment = v0;
return fprintRTF("\n\\par\\pard\\q%c ", (unsigned int)v0);
}

canonical_decompiled_code:
__int64 func4()
{
char v0; // bl
void *v1; // rbp

v0 = alignment;
alignment = 114;
fprintRTF("\n\\par\\pard\\q%c ", 114LL);
diagnostics(5LL, "Entering ConvertString() from CmdClosing");
v1 = (void *)getBraceParam();
ConvertString(v1);
free(v1);
diagnostics(5LL, "Exiting ConvertString() from CmdClosing");
fprintRTF("\n\\par\\par\\par ");
diagnostics(5LL, "Entering ConvertString() from CmdSignature");
ConvertString(g_letterSignature);
diagnostics(5LL, "Exiting ConvertString() from CmdSignature");
alignment = v0;
return fprintRTF("\n\\par\\pard\\q%c ", (unsigned int)v0);
}

original_code:
void
CmdClosing( int code)
{
 char oldalignment;
 char *s;
 oldalignment = alignment;
 alignment = 'r';
 fprintRTF("\n\\par\\pard\\q%c ", alignment);
 diagnostics(5, "Entering ConvertString() from CmdClosing");
 s = getBraceParam();
 ConvertString(s);
 free(s);
 diagnostics(5, "Exiting ConvertString() from CmdClosing");
 fprintRTF("\n\\par\\par\\par ");
 diagnostics(5, "Entering ConvertString() from CmdSignature");
 ConvertString(g_letterSignature);
 diagnostics(5, "Exiting ConvertString() from CmdSignature");
 g_letterOpened = 0;
 alignment = oldalignment;
 fprintRTF("\n\\par\\pard\\q%c ", alignment);
}

canonical_original_code:
void CmdClosing(int code)
{
 char oldalignment;
 char *s;
 oldalignment = alignment;
 alignment = 'r';
 fprintRTF("\n\\par\\pard\\q%c ", alignment);
 diagnostics(5, "Entering ConvertString() from CmdClosing");
 s = getBraceParam();
 ConvertString(s);
 free(s);
 diagnostics(5, "Exiting ConvertString() from CmdClosing");
 fprintRTF("\n\\par\\par\\par ");
 diagnostics(5, "Entering ConvertString() from CmdSignature");
 ConvertString(g_letterSignature);
 diagnostics(5, "Exiting ConvertString() from CmdSignature");
 g_letterOpened = 0;
 alignment = oldalignment;
 fprintRTF("\n\\par\\pard\\q%c ", alignment);
}


CmdPs

decompiled_code:
void __fastcall CmdPs(int a1)
{
void *v1; // rbp

v1 = (void *)getBraceParam();
if ( a1 == 3 )
{
ConvertBabelName("ENCLNAME");
}
else if ( a1 == 2 )
{
ConvertBabelName("CCNAME");
}
ConvertString(v1);
free(v1);
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
void *v1; // rbp

v1 = (void *)getBraceParam();
if ( a1 == 3 )
{
ConvertBabelName("ENCLNAME");
}
else if ( a1 == 2 )
{
ConvertBabelName("CCNAME");
}
ConvertString(v1);
free(v1);
}

original_code:
void
CmdPs(int code)
{
 char * s = getBraceParam();
 if (code == 3)
  ConvertBabelName("ENCLNAME");
 else if (code == 2)
  ConvertBabelName("CCNAME");
 ConvertString(s);
 free(s);
}

canonical_original_code:
void CmdPs(int code)
{
 char *s = getBraceParam();
 if (code == 3)
  ConvertBabelName("ENCLNAME");
 else if (code == 2)
  ConvertBabelName("CCNAME");
 ConvertString(s);
 free(s);
}


setPackageCaption

decompiled_code:
char *__fastcall setPackageCaption(char *haystack)
{
char *result; // rax
const char *v2; // rbp

puts(haystack);
result = strstr(haystack, "labelsep");
if ( result )
{
v2 = result;
if ( strstr(result, "endash") )
{
result = (char *)g_labelsep;
*g_labelsep = 958880800;
strcpy(result + 4, "6 ");
}
else
{
result = strstr(v2, "period");
if ( result )
{
result = (char *)g_labelsep;
*g_labelsep = 2108960;
}
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *haystack)
{
char *result; // rax
const char *v2; // rbp

puts(haystack);
result = strstr(haystack, "labelsep");
if ( result )
{
v2 = result;
if ( strstr(result, "endash") )
{
result = (char *)g_labelsep;
*g_labelsep = 958880800;
strcpy(result + 4, "6 ");
}
else
{
result = strstr(v2, "period");
if ( result )
{
result = (char *)g_labelsep;
*g_labelsep = 2108960;
}
}
}
return result;
}

original_code:
void setPackageCaption(char *options)
{
    printf("%s\n",options);
    char *sep = strstr(options,"labelsep");
    if (sep) {
        if (strstr(sep,"endash")) strcpy(g_labelsep," \\'96 ");
 else
 if (strstr(sep,"period")) strcpy(g_labelsep," . ");
    }
}

variable_types:
options
char *

variable_types:
sep
char *


InsertBasicStyle

decompiled_code:
void __fastcall InsertBasicStyle(const char *a1, int a2)
{
char *v2; // rax
char *v3; // rax
const char *v4; // rdi
bool v5; // zf
char *v6; // rax
char *v7; // rax
char *v8; // rbp
__int64 i; // rsi
const char *v10; // [rsp+0h] [rbp-20h] BYREF

if ( a1 )
{
v2 = strchr(a1, 44);
v3 = strchr(v2 + 1, 44);
v4 = v3 + 1;
v5 = v3[1] == 32;
v10 = v3 + 1;
if ( v5 )
{
v6 = v3 + 2;
do
v4 = v6++;
while ( *v4 == 32 );
v10 = v4;
}
v7 = strchr(v4, 44);
v8 = v7;
if ( v7 )
{
*v7 = 32 * (a2 != 0);
for ( i = (unsigned int)*v10; *v10; i = (unsigned int)*v10 )
{
if ( (_BYTE)i == 42 )
WriteFontName(&v10);
else
fprintRTF("%c", i);
++v10;
}
*v8 = 44;
}
}
}

canonical_decompiled_code:
void __fastcall func1(const char *a1, int a2)
{
char *v2; // rax
char *v3; // rax
const char *v4; // rdi
bool v5; // zf
char *v6; // rax
char *v7; // rax
char *v8; // rbp
__int64 i; // rsi
const char *v10; // [rsp+0h] [rbp-20h] BYREF

if ( a1 )
{
v2 = strchr(a1, 44);
v3 = strchr(v2 + 1, 44);
v4 = v3 + 1;
v5 = v3[1] == 32;
v10 = v3 + 1;
if ( v5 )
{
v6 = v3 + 2;
do
v4 = v6++;
while ( *v4 == 32 );
v10 = v4;
}
v7 = strchr(v4, 44);
v8 = v7;
if ( v7 )
{
*v7 = 32 * (a2 != 0);
for ( i = (unsigned int)*v10; *v10; i = (unsigned int)*v10 )
{
if ( (_BYTE)i == 42 )
WriteFontName(&v10);
else
fprintRTF("%c", i);
++v10;
}
*v8 = 44;
}
}
}

original_code:
void InsertBasicStyle(const char *rtf, bool include_header_info)
{
 const char *style;
 char *comma;
 if (rtf == ((void *)0)) return;
 style=rtf;
 comma = strchr(style,',')+1;
 style = strchr(comma,',')+1;
 while (*style==' ') style++;
 comma = strchr(style,',');
 if (comma==((void *)0)) return;
 if (include_header_info)
  *comma = ' ';
 else
  *comma = '\0';
 while (*style != '\0') {
  if (*style == '*')
   WriteFontName(&style);
  else
   fprintRTF("%c", *style);
  style++;
 }
 *comma = ',';
}

canonical_original_code:
void InsertBasicStyle(char *rtf, int include_header_info)
{
 char *style;
 char *comma;
 if (rtf == ((void *)0)) return;
 style=rtf;
 comma = strchr(style,',')+1;
 style = strchr(comma,',')+1;
 while (*style==' ') style++;
 comma = strchr(style,',');
 if (comma==((void *)0)) return;
 if (include_header_info)
  *comma = ' ';
 else
  *comma = '\0';
 while (*style != '\0') {
  if (*style == '*')
   WriteFontName(&style);
  else
   fprintRTF("%c", *style);
  style++;
 }
 *comma = ',';
}

variable_types:
rtf
char *

variable_types:
style
char *

variable_types:
comma
char *


InsertStyle

decompiled_code:
void __fastcall InsertStyle(__int64 a1)
{
const char *v1; // rax

v1 = (const char *)SearchRtfCmd(a1, 3LL);
InsertBasicStyle(v1, 0);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
const char *v1; // rax

v1 = (const char *)SearchRtfCmd(a1, 3LL);
func1(v1, 0);
}

original_code:
void
InsertStyle(char *command)
{
 const char * rtf;
 rtf = SearchRtfCmd(command, 3);
 InsertBasicStyle(rtf,0);
}

canonical_original_code:
void InsertStyle(char *command)
{
 char *rtf;
 rtf = SearchRtfCmd(command, 3);
 InsertBasicStyle(rtf,0);
}

variable_types:
command
char *


TryStyleConvert

original_code:
bool
TryStyleConvert(char *command)
{
 char * rtf;
 char * RtfCommand;
 char * TexCommand;
 char * option[9];
 char * mandatory[9];
 char * rtf_piece[20];
 char * comma;
 int optional;
 int mandated;
 int i;
 TexCommand = strdup_together("\\",command);
 RtfCommand = SearchRtfCmd(TexCommand, 3);
 if (RtfCommand == ((void *)0))
  return 0;
 rtf=RtfCommand;
 StyleCount(rtf, &optional, &mandated);
 for (i=0; i<optional; i++) {
  option[i]=getBracketParam();
 }
 for (i=0; i<mandated; i++) {
  mandatory[i]=getBraceParam();
 }
 for (i=0; i<mandated+optional+1; i++) {
  comma = strchr(rtf,',');
  if (comma==((void *)0))
   diagnostics(0, "Not enough commas in style command <%s>", RtfCommand);
  *comma = '\0';
  rtf_piece[i] = my_strdup(rtf);
  diagnostics(1,"piece %d is %s",i,rtf_piece[i]);
  *comma = ',';
  rtf = comma +1;
 }
 for (i=0; i<optional; i++) {
  if (option[i]) free(option[i]);
 }
 for (i=0; i<mandated; i++) {
  if (mandatory[i]) free(mandatory[i]);
 }
 for (i=0; i<mandated+optional+1; i++) {
  if (rtf_piece[i]) free(rtf_piece[i]);
 }
 free(TexCommand);
 return 1;
}

canonical_original_code:
int TryStyleConvert(char *command)
{
 char *rtf;
 char *RtfCommand;
 char *TexCommand;
 char *option[9];
 char *mandatory[9];
 char *rtf_piece[20];
 char *comma;
 int optional;
 int mandated;
 int i;
 TexCommand = strdup_together("\\",command);
 RtfCommand = SearchRtfCmd(TexCommand, 3);
 if (RtfCommand == ((void *)0))
  return 0;
 rtf=RtfCommand;
 StyleCount(rtf, &optional, &mandated);
 for (i=0; i<optional; i++) {
  option[i]=getBracketParam();
 }
 for (i=0; i<mandated; i++) {
  mandatory[i]=getBraceParam();
 }
 for (i=0; i<mandated+optional+1; i++) {
  comma = strchr(rtf,',');
  if (comma==((void *)0))
   diagnostics(0, "Not enough commas in style command <%s>", RtfCommand);
  *comma = '\0';
  rtf_piece[i] = my_strdup(rtf);
  diagnostics(1,"piece %d is %s",i,rtf_piece[i]);
  *comma = ',';
  rtf = comma +1;
 }
 for (i=0; i<optional; i++) {
  if (option[i]) free(option[i]);
 }
 for (i=0; i<mandated; i++) {
  if (mandatory[i]) free(mandatory[i]);
 }
 for (i=0; i<mandated+optional+1; i++) {
  if (rtf_piece[i]) free(rtf_piece[i]);
 }
 free(TexCommand);
 return 1;
}

variable_types:
RtfCommand
char *

variable_types:
TexCommand
char *

variable_types:
option
char *[9]

variable_types:
mandatory
char *[9]

variable_types: optional int

variable_types: mandated int

variable_types: i int


CmdTikzPicture

decompiled_code:
void __fastcall CmdTikzPicture(__int16 a1)
{
__int64 v1; // rax
char *v2; // rbp
void *v3; // r14
void *v4; // r12
char *v5; // r13

v1 = getBracketParam();
if ( (a1 & 0x4000) != 0 )
{
v2 = (char *)v1;
v3 = (void *)my_strdup("\\begin{tikzpicture}");
v4 = (void *)my_strdup("\\end{tikzpicture}");
v5 = (char *)getTexUntil(v4, 0LL);
TikzToPng(v5, v2);
ConvertString(v4);
free(v3);
free(v4);
free(v5);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func1(__int16 a1)
{
__int64 v1; // rax
char *v2; // rbp
void *v3; // r14
void *v4; // r12
char *v5; // r13

v1 = getBracketParam();
if ( (a1 & 0x4000) != 0 )
{
v2 = (char *)v1;
v3 = (void *)my_strdup("\\begin{tikzpicture}");
v4 = (void *)my_strdup("\\end{tikzpicture}");
v5 = (char *)getTexUntil(v4, 0LL);
func0(v5, v2);
ConvertString(v4);
free(v3);
free(v4);
free(v5);
free(v2);
}
}

original_code:
void CmdTikzPicture(int code)
{
 char *pre, *post, *tikzcode, *param;
 param = getBracketParam();
 if (code & 0x4000) {
  pre = my_strdup("\\begin{tikzpicture}");
  post = my_strdup("\\end{tikzpicture}");
  tikzcode=getTexUntil(post,0);
  TikzToPng(tikzcode,param);
  ConvertString(post);
  free(pre);
  free(post);
  free(tikzcode);
  free(param);
 }
}

canonical_original_code:
void CmdTikzPicture(int code)
{
 char *pre; char *post; char *tikzcode; char *param;
 param = getBracketParam();
 if (code & 0x4000) {
  pre = my_strdup("\\begin{tikzpicture}");
  post = my_strdup("\\end{tikzpicture}");
  tikzcode=getTexUntil(post,0);
  TikzToPng(tikzcode,param);
  ConvertString(post);
  free(pre);
  free(post);
  free(tikzcode);
  free(param);
 }
}

variable_types:
pre
char *

variable_types:
post
char *

variable_types:
tikzcode
char *

variable_types:
param
char *


CmdTikzlib

decompiled_code:
__int64 CmdTikzlib()
{
__int64 v0; // r8
__int64 result; // rax
int v2; // edx

v0 = getBraceParam();
result = tikzlibsnum;
v2 = tikzlibsnum + 1;
tikzlibs[tikzlibsnum] = v0;
tikzlibsnum = v2;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r8
__int64 result; // rax
int v2; // edx

v0 = getBraceParam();
result = tikzlibsnum;
v2 = tikzlibsnum + 1;
tikzlibs[tikzlibsnum] = v0;
tikzlibsnum = v2;
return result;
}

original_code:
void CmdTikzlib(int code)
{
       char *tikzlib = getBraceParam();
       tikzlibsnum++;
       tikzlibs[tikzlibsnum-1]=tikzlib;
}

variable_types: code int

variable_types:
tikzlib
char *


decompiled_code:
__int64 __fastcall my_getopt(int a1, const char **a2, const char *a3)
{
__int64 v4; // rbx
unsigned int v5; // er12
char *v6; // rax
_BYTE *v7; // rbx
int v8; // eax
__int64 v10; // rcx
const char *v11; // rax

optarg = 0LL;
diagnostics(4LL, "Processing option `%s'", a2[optind]);
v4 = rem_0;
if ( !rem_0 )
{
if ( optind < a1 )
{
v11 = a2[optind];
if ( *v11 == 45 )
{
v5 = v11[1];
v4 = (__int64)(v11 + 1);
rem_0 = (__int64)(v11 + 1);
if ( (_BYTE)v5 )
{
if ( (_BYTE)v5 != 45 )
goto LABEL_3;
++optind;
}
}
}
return (unsigned int)-1;
}
v5 = *(char *)rem_0;
LABEL_3:
v6 = strchr(a3, v5);
if ( !v6 || v5 == 58 )
{
v10 = v5;
v5 = 63;
fprintf(stderr, "%s: illegal option -- %c\n", *a2, v10);
v7 = (_BYTE *)++rem_0;
}
else
{
if ( v6[1] == 58 )
{
v8 = optind;
if ( *(_BYTE *)(v4 + 1) )
{
optarg = v4 + 1;
}
else
{
v8 = optind + 1;
optind = v8;
if ( a1 <= v8 )
{
fprintf(stderr, "Missing argument after -%c\n", v5);
exit(1);
}
optarg = (__int64)a2[v8];
}
goto LABEL_9;
}
v7 = (_BYTE *)(v4 + 1);
rem_0 = (__int64)v7;
}
if ( !*v7 )
{
v8 = optind;
LABEL_9:
rem_0 = 0LL;
optind = v8 + 1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char **a2, const char *a3)
{
__int64 v4; // rbx
unsigned int v5; // er12
char *v6; // rax
_BYTE *v7; // rbx
int v8; // eax
__int64 v10; // rcx
const char *v11; // rax

optarg = 0LL;
diagnostics(4LL, "Processing option `%s'", a2[optind]);
v4 = rem_0;
if ( !rem_0 )
{
if ( optind < a1 )
{
v11 = a2[optind];
if ( *v11 == 45 )
{
v5 = v11[1];
v4 = (__int64)(v11 + 1);
rem_0 = (__int64)(v11 + 1);
if ( (_BYTE)v5 )
{
if ( (_BYTE)v5 != 45 )
goto LABEL_3;
++optind;
}
}
}
return (unsigned int)-1;
}
v5 = *(char *)rem_0;
LABEL_3:
v6 = strchr(a3, v5);
if ( !v6 || v5 == 58 )
{
v10 = v5;
v5 = 63;
fprintf(stderr, "%s: illegal option -- %c\n", *a2, v10);
v7 = (_BYTE *)++rem_0;
}
else
{
if ( v6[1] == 58 )
{
v8 = optind;
if ( *(_BYTE *)(v4 + 1) )
{
optarg = v4 + 1;
}
else
{
v8 = optind + 1;
optind = v8;
if ( a1 <= v8 )
{
fprintf(stderr, "Missing argument after -%c\n", v5);
exit(1);
}
optarg = (__int64)a2[v8];
}
goto LABEL_9;
}
v7 = (_BYTE *)(v4 + 1);
rem_0 = (__int64)v7;
}
if ( !*v7 )
{
v8 = optind;
LABEL_9:
rem_0 = 0LL;
optind = v8 + 1;
}
return v5;
}

original_code:
int
my_getopt(int argc, char **argv, char *optstring)
{
 char *q;
 static char *rem = ((void *)0);
 int c;
 int needarg = 0;
 optarg = ((void *)0);
 diagnostics(4, "Processing option `%s'", argv[optind]);
 if (!rem) {
  if (optind < argc && argv[optind][0] == '-') {
   rem = argv[optind] + 1;
   if (*rem == 0)
    return (-1);
   if (*rem == '-') {
    optind++;
    return (-1);
   }
  } else
   return (-1);
 }
 c = *rem;
 q = strchr(optstring, c);
 if (q && c != ':') {
  needarg = (q[1] == ':');
  if (needarg) {
   if (rem[1] != 0)
    optarg = rem + 1;
   else {
    optind++;
    if (optind < argc)
     optarg = argv[optind];
    else {
     fprintf(stderr, "Missing argument after -%c\n", c);
     exit(1);
    }
   }
  } else
   rem++;
 } else {
  fprintf(stderr, "%s: illegal option -- %c\n", argv[0], c);
  c = '?';
  rem++;
 }
 if (needarg || *rem == 0) {
  rem = ((void *)0);
  optind++;
 }
 return c;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
optstring
char *

variable_types:
q
char *

variable_types:
rem
char *

variable_types: c int

variable_types: needarg int