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 ( a1 == 6 && g_TeX_mode == 2 )
{
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 ( a1 == 6 && g_TeX_mode == 2 )
{
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;
}

return_type: int


TranslateCommand

decompiled_code:
char TranslateCommand()
{
char v0; // bl
int v1; // ebp
int v2; // er12
int v3; // eax
const unsigned __int16 **v4; // r14
__int64 v5; // rbx
int v6; // ebx
bool v7; // cf
bool v8; // zf
char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx
int v12; // eax
bool v13; // cf
bool v14; // zf
char *v15; // rsi
const char *v16; // rdi
__int64 v17; // rcx
int v18; // ebx
int v19; // er12
char v21[152]; // [rsp+0h] [rbp-98h] BYREF

v0 = getTexChar();
v1 = v0;
v2 = GetTexMode();
LOBYTE(v3) = diagnostics(5LL, "Beginning TranslateCommand() \\%c", (unsigned int)v0);
switch ( v0 )
{
case 10:
case 32:
if ( v2 == 6 )
SetTexMode(2);
fprintRTF(" ");
LOBYTE(v3) = skipSpaces();
return v3;
case 33:
case 47:
case 64:
LOBYTE(v3) = CmdIgnore(0LL);
return v3;
case 34:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = CmdUmlauteChar(0LL);
return v3;
case 35:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("#");
return v3;
case 36:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("$");
return v3;
case 37:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("%%");
return v3;
case 38:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("&");
return v3;
case 39:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
goto LABEL_49;
LOBYTE(v3) = CmdRApostrophChar(0LL);
return v3;
case 40:
LOBYTE(v3) = CmdEquation(16387LL);
return v3;
case 41:
LOBYTE(v3) = CmdEquation(5LL);
return v3;
case 43:
if ( v2 == 6 )
LOBYTE(v3) = SetTexMode(2);
if ( g_processing_tabbing )
goto LABEL_49;
return v3;
case 44:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = CmdSpace(0.33000001);
return v3;
case 45:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
goto LABEL_49;
LOBYTE(v3) = fprintRTF("\\-");
return v3;
case 46:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = CmdDotChar(0LL);
return v3;
case 51:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("{\\'df}");
return v3;
case 59:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = CmdSpace(0.75);
return v3;
case 60:
if ( v2 == 6 )
LOBYTE(v3) = SetTexMode(2);
if ( g_processing_tabbing )
goto LABEL_49;
return v3;
case 61:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
{
((void (*)(void))PopBrace)();
CmdTabset();
LOBYTE(v3) = ((__int64 (*)(void))PushBrace)();
}
else
{
LOBYTE(v3) = CmdMacronChar(0LL);
}
return v3;
case 62:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
{
((void (*)(void))PopBrace)();
CmdTabjump();
LOBYTE(v3) = ((__int64 (*)(void))PushBrace)();
}
else
{
LOBYTE(v3) = CmdSpace(0.5);
}
return v3;
case 91:
LOBYTE(v3) = CmdEquation(16388LL);
return v3;
case 92:
LOBYTE(v3) = CmdSlashSlash(0LL);
return v3;
case 93:
LOBYTE(v3) = CmdEquation(6LL);
return v3;
case 94:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = CmdHatChar(0LL);
return v3;
case 95:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("_");
return v3;
case 96:
if ( v2 == 6 )
SetTexMode(2);
if ( g_processing_tabbing )
{
LABEL_49:
((void (*)(void))PopBrace)();
LOBYTE(v3) = ((__int64 (*)(void))PushBrace)();
}
else
{
LOBYTE(v3) = CmdLApostrophChar(0LL);
}
return v3;
case 123:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("\\{");
return v3;
case 125:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = fprintRTF("\\}");
return v3;
case 126:
if ( v2 == 6 )
SetTexMode(2);
LOBYTE(v3) = CmdTildeChar(0LL);
return v3;
default:
v4 = _ctype_b_loc();
v5 = 0LL;
while ( 1 )
{
v19 = v5;
if ( ((*v4)[v1] & 0x400) == 0 && v1 != 42 )
break;
v21[v5] = v1;
v1 = (char)getRawTexChar();
v19 = ++v5;
if ( v5 == 100 )
goto LABEL_93;
}
if ( v1 == 37 )
{
ungetTexChar(37LL);
v1 = (char)getTexChar();
}
v6 = 0;
break;
}
while ( v1 == 32 )
LABEL_88:
v1 = (char)getTexChar();
if ( v1 == 10 && !v6 )
{
v6 = 1;
goto LABEL_88;
}
ungetTexChar((unsigned int)(char)v1);
LABEL_93:
v21[v19] = 0;
LOBYTE(v3) = diagnostics(5LL, "TranslateCommand() <%s>", v21);
v7 = 0;
v8 = v19 == 0;
if ( v19 )
{
v9 = v21;
v10 = "begin";
v11 = 6LL;
do
{
if ( !v11 )
break;
v7 = (unsigned __int8)*v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
if ( (!v7 && !v8) == v7 )
{
fprintRTF("{");
PushBrace("{", v9);
}
v12 = CallCommandFunc(v21, v9);
v13 = 0;
v14 = v12 == 0;
if ( v12 )
{
v15 = v21;
v16 = "end";
v17 = 4LL;
do
{
if ( !v17 )
break;
v13 = (unsigned __int8)*v15 < (unsigned int)*v16;
v14 = *v15++ == *v16++;
--v17;
}
while ( v14 );
LOBYTE(v3) = (!v13 && !v14) - v13;
if ( !(_BYTE)v3 )
{
v18 = RecursionLevel;
ret = v18 - PopBrace(v16, v15);
LOBYTE(v3) = fprintRTF("}");
}
}
else
{
v3 = TryDirectConvert(v21);
if ( !v3 )
{
v3 = TryVariableIgnore(v21);
if ( !v3 )
LOBYTE(v3) = diagnostics(1LL, "Command \\%s not found - ignored", v21);
}
}
}
return v3;
}

canonical_decompiled_code:
char func2()
{
char v0; // bl
int v1; // ebp
int v2; // er12
int v3; // eax
const unsigned __int16 **v4; // r14
__int64 v5; // rbx
int v6; // ebx
bool v7; // cf
bool v8; // zf
char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx
int v12; // eax
bool v13; // cf
bool v14; // zf
char *v15; // rsi
const char *v16; // rdi
__int64 v17; // rcx
int v18; // ebx
int v19; // er12
char v21[152]; // [rsp+0h] [rbp-98h] BYREF

v0 = getTexChar();
v1 = v0;
v2 = func1();
LOBYTE(v3) = diagnostics(5LL, "Beginning TranslateCommand() \\%c", (unsigned int)v0);
switch ( v0 )
{
case 10:
case 32:
if ( v2 == 6 )
func0(2);
fprintRTF(" ");
LOBYTE(v3) = skipSpaces();
return v3;
case 33:
case 47:
case 64:
LOBYTE(v3) = CmdIgnore(0LL);
return v3;
case 34:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = CmdUmlauteChar(0LL);
return v3;
case 35:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("#");
return v3;
case 36:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("$");
return v3;
case 37:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("%%");
return v3;
case 38:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("&");
return v3;
case 39:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
goto LABEL_49;
LOBYTE(v3) = CmdRApostrophChar(0LL);
return v3;
case 40:
LOBYTE(v3) = CmdEquation(16387LL);
return v3;
case 41:
LOBYTE(v3) = CmdEquation(5LL);
return v3;
case 43:
if ( v2 == 6 )
LOBYTE(v3) = func0(2);
if ( g_processing_tabbing )
goto LABEL_49;
return v3;
case 44:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = CmdSpace(0.33000001);
return v3;
case 45:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
goto LABEL_49;
LOBYTE(v3) = fprintRTF("\\-");
return v3;
case 46:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = CmdDotChar(0LL);
return v3;
case 51:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("{\\'df}");
return v3;
case 59:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = CmdSpace(0.75);
return v3;
case 60:
if ( v2 == 6 )
LOBYTE(v3) = func0(2);
if ( g_processing_tabbing )
goto LABEL_49;
return v3;
case 61:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
{
((void (*)(void))PopBrace)();
CmdTabset();
LOBYTE(v3) = ((__int64 (*)(void))PushBrace)();
}
else
{
LOBYTE(v3) = CmdMacronChar(0LL);
}
return v3;
case 62:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
{
((void (*)(void))PopBrace)();
CmdTabjump();
LOBYTE(v3) = ((__int64 (*)(void))PushBrace)();
}
else
{
LOBYTE(v3) = CmdSpace(0.5);
}
return v3;
case 91:
LOBYTE(v3) = CmdEquation(16388LL);
return v3;
case 92:
LOBYTE(v3) = CmdSlashSlash(0LL);
return v3;
case 93:
LOBYTE(v3) = CmdEquation(6LL);
return v3;
case 94:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = CmdHatChar(0LL);
return v3;
case 95:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("_");
return v3;
case 96:
if ( v2 == 6 )
func0(2);
if ( g_processing_tabbing )
{
LABEL_49:
((void (*)(void))PopBrace)();
LOBYTE(v3) = ((__int64 (*)(void))PushBrace)();
}
else
{
LOBYTE(v3) = CmdLApostrophChar(0LL);
}
return v3;
case 123:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("\\{");
return v3;
case 125:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = fprintRTF("\\}");
return v3;
case 126:
if ( v2 == 6 )
func0(2);
LOBYTE(v3) = CmdTildeChar(0LL);
return v3;
default:
v4 = _ctype_b_loc();
v5 = 0LL;
while ( 1 )
{
v19 = v5;
if ( ((*v4)[v1] & 0x400) == 0 && v1 != 42 )
break;
v21[v5] = v1;
v1 = (char)getRawTexChar();
v19 = ++v5;
if ( v5 == 100 )
goto LABEL_93;
}
if ( v1 == 37 )
{
ungetTexChar(37LL);
v1 = (char)getTexChar();
}
v6 = 0;
break;
}
while ( v1 == 32 )
LABEL_88:
v1 = (char)getTexChar();
if ( v1 == 10 && !v6 )
{
v6 = 1;
goto LABEL_88;
}
ungetTexChar((unsigned int)(char)v1);
LABEL_93:
v21[v19] = 0;
LOBYTE(v3) = diagnostics(5LL, "TranslateCommand() <%s>", v21);
v7 = 0;
v8 = v19 == 0;
if ( v19 )
{
v9 = v21;
v10 = "begin";
v11 = 6LL;
do
{
if ( !v11 )
break;
v7 = (unsigned __int8)*v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
if ( (!v7 && !v8) == v7 )
{
fprintRTF("{");
PushBrace("{", v9);
}
v12 = CallCommandFunc(v21, v9);
v13 = 0;
v14 = v12 == 0;
if ( v12 )
{
v15 = v21;
v16 = "end";
v17 = 4LL;
do
{
if ( !v17 )
break;
v13 = (unsigned __int8)*v15 < (unsigned int)*v16;
v14 = *v15++ == *v16++;
--v17;
}
while ( v14 );
LOBYTE(v3) = (!v13 && !v14) - v13;
if ( !(_BYTE)v3 )
{
v18 = RecursionLevel;
ret = v18 - PopBrace(v16, v15);
LOBYTE(v3) = fprintRTF("}");
}
}
else
{
v3 = TryDirectConvert(v21);
if ( !v3 )
{
v3 = TryVariableIgnore(v21);
if ( !v3 )
LOBYTE(v3) = diagnostics(1LL, "Command \\%s not found - ignored", v21);
}
}
}
return v3;
}

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

variable_types: cThis int

return_type: void


ConvertAllttString

decompiled_code:
void __fastcall ConvertAllttString(__int64 a1)
{
const char *v2; // rdi
char v3; // al
int v4; // ebx

if ( a1 )
{
diagnostics(4LL, "Entering Convert() from StringAllttConvert()");
v2 = 0LL;
if ( !(unsigned int)PushSource(0LL, a1) )
{
while ( (unsigned int)StillSource() )
{
v3 = getRawTexChar();
switch ( v3 )
{
case '{':
PushBrace(v2, a1);
v2 = "{";
fprintRTF("{");
break;
case '}':
v4 = RecursionLevel;
ret = v4 - PopBrace(v2, a1);
v2 = "}";
fprintRTF("}");
break;
case '\\':
PushLevels();
TranslateCommand();
CleanStack();
break;
default:
v2 = (const char *)(unsigned int)v3;
putRtfChar(v2);
break;
}
}
PopSource();
}
diagnostics(4LL, "Exiting Convert() from StringAllttConvert()");
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
const char *v2; // rdi
char v3; // al
int v4; // ebx

if ( a1 )
{
diagnostics(4LL, "Entering Convert() from StringAllttConvert()");
v2 = 0LL;
if ( !(unsigned int)PushSource(0LL, a1) )
{
while ( (unsigned int)StillSource() )
{
v3 = getRawTexChar();
switch ( v3 )
{
case '{':
PushBrace(v2, a1);
v2 = "{";
fprintRTF("{");
break;
case '}':
v4 = RecursionLevel;
ret = v4 - PopBrace(v2, a1);
v2 = "}";
fprintRTF("}");
break;
case '\\':
PushLevels();
func2();
CleanStack();
break;
default:
v2 = (const char *)(unsigned int)v3;
putRtfChar(v2);
break;
}
}
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()
{
char v0; // r12
unsigned int v1; // eax
int v2; // ebp
char v3; // al
__int64 result; // rax
char v5; // bl
unsigned int v6; // eax
__int64 v7; // rdi
int v8; // ebp
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
char v13; // al
char v14; // al
int v15; // eax
__int64 v16; // r12
__int64 v17; // rbp
unsigned int v18; // eax
__int64 v19; // r12
__int64 v20; // rbp
__int64 v21; // rax
unsigned int v22; // eax
__int64 v23; // r12
__int64 v24; // rbp
__int64 v25; // rax
char v26; // al
char v27; // al
char v28; // al
char v29; // bp
char v30; // bp
char v31; // al

diagnostics(3LL, "Entering Convert ret = %d", (unsigned int)ret);
++RecursionLevel;
PushLevels();
v0 = 0;
while ( 1 )
{
v5 = getTexChar();
if ( !v5 )
break;
if ( v5 == 10 )
{
v1 = GetTexMode();
diagnostics(
5LL,
"Current character is '\\n' mode = %d ret = %d level = %d",
v1,
(unsigned int)ret,
RecursionLevel);
v2 = GetTexMode();
LABEL_3:
tabcounter = 0;
if ( (unsigned int)(v2 - 4) <= 1 )
{
v13 = getNonBlank();
ungetTexChar((unsigned int)v13);
v0 = 10;
}
else
{
v3 = getNonSpace();
if ( v3 == 10 )
{
CmdEndParagraph(0LL);
v14 = getNonBlank();
ungetTexChar((unsigned int)v14);
v0 = 10;
}
else
{
ungetTexChar((unsigned int)v3);
if ( v2 == 6 || v0 == 32 )
{
v0 = 10;
}
else
{
fprintRTF(" ");
v0 = 10;
}
}
}
}
else
{
v6 = GetTexMode();
v7 = 5LL;
diagnostics(
5LL,
"Current character is '%c' mode = %d ret = %d level = %d",
(unsigned int)v5,
v6,
(unsigned int)ret,
RecursionLevel);
v2 = GetTexMode();
switch ( v5 )
{
case 9:
diagnostics(1LL, "This should not happen, ignoring \\t");
v0 = 32;
break;
case 10:
goto LABEL_3;
case 13:
diagnostics(1LL, "This should not happen, ignoring \\r");
v0 = 32;
break;
case 32:
if ( (unsigned int)(v2 - 4) > 2 )
{
if ( v0 == 32 || v0 == 10 )
{
v0 = v5;
}
else
{
if ( v2 == 3 )
fprintRTF("\\~");
else
fprintRTF(" ");
v0 = v5;
}
}
break;
case 33:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("!");
v0 = v5;
}
else
{
SetTexMode(2);
v29 = getTexChar();
if ( v29 == 96 )
{
fprintRTF("\\'a1 ");
}
else
{
fprintRTF("! ");
ungetTexChar((unsigned int)v29);
}
v0 = v5;
}
break;
case 34:
SetTexMode(2);
if ( GermanMode )
TranslateGerman();
else
fprintRTF("\"");
v0 = v5;
break;
case 36:
v0 = getTexChar();
diagnostics(5LL, "Processing $, next char <%c>", (unsigned int)v0);
if ( v0 == 36 && (unsigned int)GetTexMode() != 4 )
{
CmdEquation(16398LL);
}
else
{
ungetTexChar((unsigned int)v0);
CmdEquation(16386LL);
v0 = v5;
}
break;
case 37:
diagnostics(1LL, "This should not happen, ignoring %%");
v0 = 32;
break;
case 38:
if ( g_processing_arrays )
{
fprintRTF("%c", (unsigned int)g_field_separator);
v0 = v5;
}
else if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("\\tab ");
++g_equation_column;
v0 = v5;
}
else
{
if ( g_processing_tabular )
{
++actCol;
fprintRTF("\\cell\\pard\\intbl\\q%c ", (unsigned int)*(char *)(colFmt + actCol));
}
else
{
fprintRTF("&");
}
v0 = v5;
}
break;
case 39:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("'");
v0 = v5;
}
else
{
SetTexMode(2);
v18 = getSameChar(39LL);
if ( v18 == 1 )
{
fprintRTF("\\rdblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v18 + 1);
v0 = v5;
}
else
{
v19 = v18;
v20 = 0LL;
if ( v18 == -1 )
{
v0 = v5;
}
else
{
do
{
fprintRTF("\\rquote ");
v21 = v20++;
}
while ( v19 != v21 );
v0 = v5;
}
}
}
break;
case 40:
if ( g_processing_fields && g_escape_parent )
{
fprintRTF("\\\\(");
v0 = v5;
}
else
{
fprintRTF("(");
v0 = v5;
}
break;
case 41:
if ( g_processing_fields && g_escape_parent )
{
fprintRTF("\\\\)");
v0 = v5;
}
else
{
fprintRTF(")");
v0 = v5;
}
break;
case 44:
v0 = g_field_separator;
if ( g_field_separator == 44 && g_processing_fields )
{
fprintRTF("\\\\,");
}
else
{
fprintRTF(",");
v0 = v5;
}
break;
case 45:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("-");
v0 = v5;
}
else
{
SetTexMode(2);
v15 = getSameChar(45LL);
if ( v15 )
{
if ( v15 == 1 )
{
fprintRTF("\\endash ");
v0 = v5;
}
else if ( v15 == 2 )
{
LABEL_59:
fprintRTF("\\emdash ");
v0 = v5;
}
else
{
v16 = (unsigned int)(v15 + 1);
v17 = 0LL;
if ( v15 == -1 )
{
v0 = v5;
}
else
{
do
{
fprintRTF("-");
++v17;
}
while ( v17 != v16 );
v0 = v5;
}
}
}
else
{
fprintRTF("-", "Current character is '%c' mode = %d ret = %d level = %d", (unsigned int)(v15 + 1));
v0 = v5;
}
}
break;
case 46:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF(".");
}
else
{
SetTexMode(2);
fprintRTF(".");
v31 = getTexChar();
ungetTexChar((unsigned int)v31);
}
v0 = v5;
break;
case 58:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF(":");
v0 = v5;
}
else
{
SetTexMode(2);
if ( FrenchMode )
fprintRTF("\\~:");
else
fprintRTF(":");
v0 = v5;
}
break;
case 59:
v0 = g_field_separator;
if ( g_field_separator == 59 && g_processing_fields )
{
fprintRTF("\\\\;");
}
else
{
if ( FrenchMode )
fprintRTF("\\~;");
else
fprintRTF(";");
v0 = v5;
}
break;
case 60:
if ( v2 == 6 )
SetTexMode(2);
if ( (unsigned int)GetTexMode() == 2 )
{
v26 = getTexChar();
v0 = v26;
if ( v26 == 60 )
{
if ( FrenchMode )
{
skipSpaces();
v27 = getTexChar();
if ( v27 == 126 )
skipSpaces();
else
ungetTexChar((unsigned int)v27);
fprintRTF("\\'ab\\~");
}
else
{
fprintRTF("\\'ab");
}
}
else
{
ungetTexChar((unsigned int)v26);
fprintRTF("<");
v0 = v5;
}
}
else
{
fprintRTF("<");
v0 = v5;
}
break;
case 62:
if ( v2 == 6 )
SetTexMode(2);
if ( (unsigned int)GetTexMode() == 2 )
{
v28 = getTexChar();
v0 = v28;
if ( v28 == 62 )
{
fprintRTF("\\'bb");
}
else
{
ungetTexChar((unsigned int)v28);
fprintRTF(">");
v0 = v5;
}
}
else
{
fprintRTF(">");
v0 = v5;
}
break;
case 63:
SetTexMode(2);
v30 = getTexChar();
if ( v30 == 96 )
{
fprintRTF("\\'bf ");
}
else
{
fprintRTF("? ");
ungetTexChar((unsigned int)v30);
}
v0 = v5;
break;
case 92:
PushLevels();
TranslateCommand();
CleanStack();
if ( ret > 0 )
{
result = diagnostics(
5LL,
"Exiting Convert via TranslateCommand ret = %d level = %d",
(unsigned int)ret,
RecursionLevel);
--ret;
--RecursionLevel;
return result;
}
v0 = v5;
break;
case 94:
CmdSuperscript(0LL);
v0 = v5;
break;
case 95:
CmdSubscript(0LL);
v0 = v5;
break;
case 96:
SetTexMode(2);
v22 = getSameChar(96LL);
if ( v22 == 1 )
{
fprintRTF("\\ldblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v22 + 1);
v0 = v5;
}
else
{
v23 = v22;
v24 = 0LL;
if ( v22 == -1 )
{
v0 = v5;
}
else
{
do
{
fprintRTF("\\lquote ");
v25 = v24++;
}
while ( v25 != v23 );
v0 = v5;
}
}
break;
case 123:
if ( v2 == 6 )
{
v7 = 2LL;
SetTexMode(2);
}
CleanStack();
PushBrace(v7, "Current character is '%c' mode = %d ret = %d level = %d");
fprintRTF("{");
v0 = v5;
break;
case 124:
if ( (unsigned int)(v2 - 4) > 1 )
goto LABEL_59;
fprintRTF("|");
v0 = v5;
break;
case 125:
CleanStack();
v8 = RecursionLevel;
ret = v8 - PopBrace(5LL, "Current character is '%c' mode = %d ret = %d level = %d", v9, v10, v11, v12);
fprintRTF("}");
if ( ret > 0 )
{
result = diagnostics(5LL, "Exiting Convert via '}' ret = %d level = %d", (unsigned int)ret, RecursionLevel);
--ret;
--RecursionLevel;
return result;
}
v0 = v5;
break;
case 126:
fprintRTF("\\~");
v0 = v5;
break;
default:
if ( (unsigned int)(v2 - 4) > 1 )
{
SetTexMode(2);
fprintRTF("%c", (unsigned int)v5);
v0 = v5;
}
else
{
if ( (unsigned __int8)((v5 & 0xDF) - 65) > 0x19u )
fprintRTF("%c", (unsigned int)v5);
else
fprintRTF("{\\i %c}", (unsigned int)v5);
v0 = v5;
}
break;
}
}
++tabcounter;
}
--RecursionLevel;
return diagnostics(5LL, "Exiting Convert via exhaustion ret = %d", (unsigned int)ret);
}

canonical_decompiled_code:
__int64 func4()
{
char v0; // r12
unsigned int v1; // eax
int v2; // ebp
char v3; // al
__int64 result; // rax
char v5; // bl
unsigned int v6; // eax
__int64 v7; // rdi
int v8; // ebp
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
char v13; // al
char v14; // al
int v15; // eax
__int64 v16; // r12
__int64 v17; // rbp
unsigned int v18; // eax
__int64 v19; // r12
__int64 v20; // rbp
__int64 v21; // rax
unsigned int v22; // eax
__int64 v23; // r12
__int64 v24; // rbp
__int64 v25; // rax
char v26; // al
char v27; // al
char v28; // al
char v29; // bp
char v30; // bp
char v31; // al

diagnostics(3LL, "Entering Convert ret = %d", (unsigned int)ret);
++RecursionLevel;
PushLevels();
v0 = 0;
while ( 1 )
{
v5 = getTexChar();
if ( !v5 )
break;
if ( v5 == 10 )
{
v1 = func1();
diagnostics(
5LL,
"Current character is '\\n' mode = %d ret = %d level = %d",
v1,
(unsigned int)ret,
RecursionLevel);
v2 = func1();
LABEL_3:
tabcounter = 0;
if ( (unsigned int)(v2 - 4) <= 1 )
{
v13 = getNonBlank();
ungetTexChar((unsigned int)v13);
v0 = 10;
}
else
{
v3 = getNonSpace();
if ( v3 == 10 )
{
CmdEndParagraph(0LL);
v14 = getNonBlank();
ungetTexChar((unsigned int)v14);
v0 = 10;
}
else
{
ungetTexChar((unsigned int)v3);
if ( v2 == 6 || v0 == 32 )
{
v0 = 10;
}
else
{
fprintRTF(" ");
v0 = 10;
}
}
}
}
else
{
v6 = func1();
v7 = 5LL;
diagnostics(
5LL,
"Current character is '%c' mode = %d ret = %d level = %d",
(unsigned int)v5,
v6,
(unsigned int)ret,
RecursionLevel);
v2 = func1();
switch ( v5 )
{
case 9:
diagnostics(1LL, "This should not happen, ignoring \\t");
v0 = 32;
break;
case 10:
goto LABEL_3;
case 13:
diagnostics(1LL, "This should not happen, ignoring \\r");
v0 = 32;
break;
case 32:
if ( (unsigned int)(v2 - 4) > 2 )
{
if ( v0 == 32 || v0 == 10 )
{
v0 = v5;
}
else
{
if ( v2 == 3 )
fprintRTF("\\~");
else
fprintRTF(" ");
v0 = v5;
}
}
break;
case 33:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("!");
v0 = v5;
}
else
{
func0(2);
v29 = getTexChar();
if ( v29 == 96 )
{
fprintRTF("\\'a1 ");
}
else
{
fprintRTF("! ");
ungetTexChar((unsigned int)v29);
}
v0 = v5;
}
break;
case 34:
func0(2);
if ( GermanMode )
TranslateGerman();
else
fprintRTF("\"");
v0 = v5;
break;
case 36:
v0 = getTexChar();
diagnostics(5LL, "Processing $, next char <%c>", (unsigned int)v0);
if ( v0 == 36 && (unsigned int)func1() != 4 )
{
CmdEquation(16398LL);
}
else
{
ungetTexChar((unsigned int)v0);
CmdEquation(16386LL);
v0 = v5;
}
break;
case 37:
diagnostics(1LL, "This should not happen, ignoring %%");
v0 = 32;
break;
case 38:
if ( g_processing_arrays )
{
fprintRTF("%c", (unsigned int)g_field_separator);
v0 = v5;
}
else if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("\\tab ");
++g_equation_column;
v0 = v5;
}
else
{
if ( g_processing_tabular )
{
++actCol;
fprintRTF("\\cell\\pard\\intbl\\q%c ", (unsigned int)*(char *)(colFmt + actCol));
}
else
{
fprintRTF("&");
}
v0 = v5;
}
break;
case 39:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("'");
v0 = v5;
}
else
{
func0(2);
v18 = getSameChar(39LL);
if ( v18 == 1 )
{
fprintRTF("\\rdblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v18 + 1);
v0 = v5;
}
else
{
v19 = v18;
v20 = 0LL;
if ( v18 == -1 )
{
v0 = v5;
}
else
{
do
{
fprintRTF("\\rquote ");
v21 = v20++;
}
while ( v19 != v21 );
v0 = v5;
}
}
}
break;
case 40:
if ( g_processing_fields && g_escape_parent )
{
fprintRTF("\\\\(");
v0 = v5;
}
else
{
fprintRTF("(");
v0 = v5;
}
break;
case 41:
if ( g_processing_fields && g_escape_parent )
{
fprintRTF("\\\\)");
v0 = v5;
}
else
{
fprintRTF(")");
v0 = v5;
}
break;
case 44:
v0 = g_field_separator;
if ( g_field_separator == 44 && g_processing_fields )
{
fprintRTF("\\\\,");
}
else
{
fprintRTF(",");
v0 = v5;
}
break;
case 45:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF("-");
v0 = v5;
}
else
{
func0(2);
v15 = getSameChar(45LL);
if ( v15 )
{
if ( v15 == 1 )
{
fprintRTF("\\endash ");
v0 = v5;
}
else if ( v15 == 2 )
{
LABEL_59:
fprintRTF("\\emdash ");
v0 = v5;
}
else
{
v16 = (unsigned int)(v15 + 1);
v17 = 0LL;
if ( v15 == -1 )
{
v0 = v5;
}
else
{
do
{
fprintRTF("-");
++v17;
}
while ( v17 != v16 );
v0 = v5;
}
}
}
else
{
fprintRTF("-", "Current character is '%c' mode = %d ret = %d level = %d", (unsigned int)(v15 + 1));
v0 = v5;
}
}
break;
case 46:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF(".");
}
else
{
func0(2);
fprintRTF(".");
v31 = getTexChar();
ungetTexChar((unsigned int)v31);
}
v0 = v5;
break;
case 58:
if ( (unsigned int)(v2 - 4) <= 1 )
{
fprintRTF(":");
v0 = v5;
}
else
{
func0(2);
if ( FrenchMode )
fprintRTF("\\~:");
else
fprintRTF(":");
v0 = v5;
}
break;
case 59:
v0 = g_field_separator;
if ( g_field_separator == 59 && g_processing_fields )
{
fprintRTF("\\\\;");
}
else
{
if ( FrenchMode )
fprintRTF("\\~;");
else
fprintRTF(";");
v0 = v5;
}
break;
case 60:
if ( v2 == 6 )
func0(2);
if ( (unsigned int)func1() == 2 )
{
v26 = getTexChar();
v0 = v26;
if ( v26 == 60 )
{
if ( FrenchMode )
{
skipSpaces();
v27 = getTexChar();
if ( v27 == 126 )
skipSpaces();
else
ungetTexChar((unsigned int)v27);
fprintRTF("\\'ab\\~");
}
else
{
fprintRTF("\\'ab");
}
}
else
{
ungetTexChar((unsigned int)v26);
fprintRTF("<");
v0 = v5;
}
}
else
{
fprintRTF("<");
v0 = v5;
}
break;
case 62:
if ( v2 == 6 )
func0(2);
if ( (unsigned int)func1() == 2 )
{
v28 = getTexChar();
v0 = v28;
if ( v28 == 62 )
{
fprintRTF("\\'bb");
}
else
{
ungetTexChar((unsigned int)v28);
fprintRTF(">");
v0 = v5;
}
}
else
{
fprintRTF(">");
v0 = v5;
}
break;
case 63:
func0(2);
v30 = getTexChar();
if ( v30 == 96 )
{
fprintRTF("\\'bf ");
}
else
{
fprintRTF("? ");
ungetTexChar((unsigned int)v30);
}
v0 = v5;
break;
case 92:
PushLevels();
func2();
CleanStack();
if ( ret > 0 )
{
result = diagnostics(
5LL,
"Exiting Convert via TranslateCommand ret = %d level = %d",
(unsigned int)ret,
RecursionLevel);
--ret;
--RecursionLevel;
return result;
}
v0 = v5;
break;
case 94:
CmdSuperscript(0LL);
v0 = v5;
break;
case 95:
CmdSubscript(0LL);
v0 = v5;
break;
case 96:
func0(2);
v22 = getSameChar(96LL);
if ( v22 == 1 )
{
fprintRTF("\\ldblquote ", "Current character is '%c' mode = %d ret = %d level = %d", v22 + 1);
v0 = v5;
}
else
{
v23 = v22;
v24 = 0LL;
if ( v22 == -1 )
{
v0 = v5;
}
else
{
do
{
fprintRTF("\\lquote ");
v25 = v24++;
}
while ( v25 != v23 );
v0 = v5;
}
}
break;
case 123:
if ( v2 == 6 )
{
v7 = 2LL;
func0(2);
}
CleanStack();
PushBrace(v7, "Current character is '%c' mode = %d ret = %d level = %d");
fprintRTF("{");
v0 = v5;
break;
case 124:
if ( (unsigned int)(v2 - 4) > 1 )
goto LABEL_59;
fprintRTF("|");
v0 = v5;
break;
case 125:
CleanStack();
v8 = RecursionLevel;
ret = v8 - PopBrace(5LL, "Current character is '%c' mode = %d ret = %d level = %d", v9, v10, v11, v12);
fprintRTF("}");
if ( ret > 0 )
{
result = diagnostics(5LL, "Exiting Convert via '}' ret = %d level = %d", (unsigned int)ret, RecursionLevel);
--ret;
--RecursionLevel;
return result;
}
v0 = v5;
break;
case 126:
fprintRTF("\\~");
v0 = v5;
break;
default:
if ( (unsigned int)(v2 - 4) > 1 )
{
func0(2);
fprintRTF("%c", (unsigned int)v5);
v0 = v5;
}
else
{
if ( (unsigned __int8)((v5 & 0xDF) - 65) > 0x19u )
fprintRTF("%c", (unsigned int)v5);
else
fprintRTF("{\\i %c}", (unsigned int)v5);
v0 = v5;
}
break;
}
}
++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; // rax
char v2[125]; // [rsp-7Ch] [rbp-108h] BYREF
int v3; // [rsp+1h] [rbp-8Bh]
char v4; // [rsp+5h] [rbp-87h]
char dest[134]; // [rsp+6h] [rbp-86h] BYREF

if ( src )
{
if ( strlen(src) > 0xF9 )
{
strncpy(v2, src, 0x7DuLL);
v3 = 774778378;
v4 = 10;
v1 = strlen(src);
strncpy(dest, &src[v1 - 125], 0x7DuLL);
dest[125] = 0;
}
else
{
strncpy(v2, src, 0xFAuLL);
}
if ( !(unsigned int)PushSource(0LL, src) )
{
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; // rax
char v2[125]; // [rsp-7Ch] [rbp-108h] BYREF
int v3; // [rsp+1h] [rbp-8Bh]
char v4; // [rsp+5h] [rbp-87h]
char dest[134]; // [rsp+6h] [rbp-86h] BYREF

if ( src )
{
if ( strlen(src) > 0xF9 )
{
strncpy(v2, src, 0x7DuLL);
v3 = 774778378;
v4 = 10;
v1 = strlen(src);
strncpy(dest, &src[v1 - 125], 0x7DuLL);
dest[125] = 0;
}
else
{
strncpy(v2, src, 0xFAuLL);
}
if ( !(unsigned int)PushSource(0LL, src) )
{
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; // rbx

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

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

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

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
const char *v5; // rax
char *v6; // rax
char *v7; // rbp
char i; // si
const char *v9; // [rsp+0h] [rbp-20h] BYREF

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

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

if ( a1 )
{
v2 = strchr(a1, 44);
v3 = strchr(v2 + 1, 44);
v4 = v3 + 1;
v9 = v3 + 1;
if ( v3[1] == 32 )
{
v5 = v3 + 2;
do
{
v4 = v5;
v9 = v5++;
}
while ( *(v5 - 1) == 32 );
}
v6 = strchr(v4, 44);
v7 = v6;
if ( v6 )
{
*v6 = 32 * (a2 != 0);
for ( i = *v9; *v9; i = *v9 )
{
if ( i == 42 )
WriteFontName(&v9);
else
fprintRTF("%c", (unsigned int)i);
++v9;
}
*v7 = 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

decompiled_code:
__int64 __fastcall TryStyleConvert(__int64 a1)
{
void *v1; // r14
const char *v2; // r13
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbx
const char *v6; // r15
__int64 v7; // rbp
void *v8; // rax
char *v9; // rbx
__int64 v10; // rbx
void *v11; // rdi
__int64 v12; // rbx
void *v13; // rdi
__int64 v14; // rbx
void *v15; // rdi
int v16; // [rsp+8h] [rbp-180h] BYREF
int v17; // [rsp+Ch] [rbp-17Ch] BYREF
void *v18[47]; // [rsp+10h] [rbp-178h]

v1 = (void *)strdup_together("\\", a1);
v2 = (const char *)SearchRtfCmd(v1, 3LL);
result = 0LL;
if ( v2 )
{
StyleCount(v2, &v17, &v16);
if ( v17 > 0 )
{
v4 = 0LL;
do
v18[v4++ + 30] = (void *)getBracketParam();
while ( v17 > (int)v4 );
}
if ( v16 > 0 )
{
v5 = 0LL;
do
v18[v5++ + 20] = (void *)getBraceParam();
while ( v16 > (int)v5 );
}
if ( v16 + v17 >= 0 )
{
v6 = v2;
v7 = 0LL;
do
{
v9 = strchr(v6, 44);
if ( !v9 )
diagnostics(0LL, "Not enough commas in style command <%s>", v2);
*v9 = 0;
v8 = (void *)my_strdup(v6);
v18[v7] = v8;
diagnostics(1LL, "piece %d is %s", (unsigned int)v7, (const char *)v8);
*v9 = 44;
v6 = v9 + 1;
++v7;
}
while ( v16 + v17 >= (int)v7 );
}
if ( v17 > 0 )
{
v10 = 0LL;
do
{
v11 = v18[v10 + 30];
if ( v11 )
free(v11);
++v10;
}
while ( v17 > (int)v10 );
}
if ( v16 > 0 )
{
v12 = 0LL;
do
{
v13 = v18[v12 + 20];
if ( v13 )
free(v13);
++v12;
}
while ( v16 > (int)v12 );
}
if ( v16 + v17 >= 0 )
{
v14 = 0LL;
do
{
v15 = v18[v14];
if ( v15 )
free(v15);
++v14;
}
while ( v16 + v17 >= (int)v14 );
}
free(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
void *v1; // r14
const char *v2; // r13
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbx
const char *v6; // r15
__int64 v7; // rbp
void *v8; // rax
char *v9; // rbx
__int64 v10; // rbx
void *v11; // rdi
__int64 v12; // rbx
void *v13; // rdi
__int64 v14; // rbx
void *v15; // rdi
int v16; // [rsp+8h] [rbp-180h] BYREF
int v17; // [rsp+Ch] [rbp-17Ch] BYREF
void *v18[47]; // [rsp+10h] [rbp-178h]

v1 = (void *)strdup_together("\\", a1);
v2 = (const char *)SearchRtfCmd(v1, 3LL);
result = 0LL;
if ( v2 )
{
func0(v2, &v17, &v16);
if ( v17 > 0 )
{
v4 = 0LL;
do
v18[v4++ + 30] = (void *)getBracketParam();
while ( v17 > (int)v4 );
}
if ( v16 > 0 )
{
v5 = 0LL;
do
v18[v5++ + 20] = (void *)getBraceParam();
while ( v16 > (int)v5 );
}
if ( v16 + v17 >= 0 )
{
v6 = v2;
v7 = 0LL;
do
{
v9 = strchr(v6, 44);
if ( !v9 )
diagnostics(0LL, "Not enough commas in style command <%s>", v2);
*v9 = 0;
v8 = (void *)my_strdup(v6);
v18[v7] = v8;
diagnostics(1LL, "piece %d is %s", (unsigned int)v7, (const char *)v8);
*v9 = 44;
v6 = v9 + 1;
++v7;
}
while ( v16 + v17 >= (int)v7 );
}
if ( v17 > 0 )
{
v10 = 0LL;
do
{
v11 = v18[v10 + 30];
if ( v11 )
free(v11);
++v10;
}
while ( v17 > (int)v10 );
}
if ( v16 > 0 )
{
v12 = 0LL;
do
{
v13 = v18[v12 + 20];
if ( v13 )
free(v13);
++v12;
}
while ( v16 > (int)v12 );
}
if ( v16 + v17 >= 0 )
{
v14 = 0LL;
do
{
v15 = v18[v14];
if ( v15 )
free(v15);
++v14;
}
while ( v16 + v17 >= (int)v14 );
}
free(v1);
result = 1LL;
}
return result;
}

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; // r13
void *v4; // rbx
char *v5; // r12

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; // r13
void *v4; // rbx
char *v5; // r12

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

v0 = getBraceParam();
LODWORD(result) = tikzlibsnum++;
result = (int)result;
tikzlibs[(int)result] = v0;
return result;
}

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

v0 = getBraceParam();
LODWORD(result) = tikzlibsnum++;
result = (int)result;
tikzlibs[(int)result] = v0;
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; // r12
unsigned int v5; // ebp
char *v6; // rax
const char *v8; // rax
char v9; // al
int v10; // eax

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

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char **a2, const char *a3)
{
__int64 v4; // r12
unsigned int v5; // ebp
char *v6; // rax
const char *v8; // rax
char v9; // al
int v10; // eax

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


WriteFontName

decompiled_code:
__int64 __fastcall WriteFontName(char **a1, __int64 a2)
{
const char *v2; // r12
char v3; // al
__int64 v4; // rbx
__int64 result; // rax
char *v6; // rax
int v7; // ecx
int v8; // eax
char v9[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = *a1 + 1;
*a1 = (char *)v2;
v3 = *v2;
v4 = 0LL;
if ( *v2 == 42 )
return fprintRTF(&unk_163, a2);
do
{
if ( !v3 || (int)v4 > 99 )
diagnostics(0LL, "No terminating '*' in font name\nFound in cfg file command <%s>", v2);
v6 = *a1;
v9[v4] = **a1;
v7 = v4 + 1;
*a1 = v6 + 1;
v3 = v6[1];
++v4;
}
while ( v3 != 42 );
v9[v7] = 0;
v8 = RtfFontNumber(v9);
if ( v8 < 0 )
result = diagnostics(0LL, "Unknown font <%s>\nFound in cfg file command <%s>", v9, v2);
else
result = fprintRTF(&unk_165, (unsigned int)v8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, __int64 a2)
{
const char *v2; // r12
char v3; // al
__int64 v4; // rbx
__int64 result; // rax
char *v6; // rax
int v7; // ecx
int v8; // eax
char v9[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = *a1 + 1;
*a1 = (char *)v2;
v3 = *v2;
v4 = 0LL;
if ( *v2 == 42 )
return fprintRTF(&unk_163, a2);
do
{
if ( !v3 || (int)v4 > 99 )
diagnostics(0LL, "No terminating '*' in font name\nFound in cfg file command <%s>", v2);
v6 = *a1;
v9[v4] = **a1;
v7 = v4 + 1;
*a1 = v6 + 1;
v3 = v6[1];
++v4;
}
while ( v3 != 42 );
v9[v7] = 0;
v8 = RtfFontNumber(v9);
if ( v8 < 0 )
result = diagnostics(0LL, "Unknown font <%s>\nFound in cfg file command <%s>", v9, v2);
else
result = fprintRTF(&unk_165, (unsigned int)v8);
return result;
}

original_code:
void WriteFontName(const char **buffpoint)
{
 char fontname[100 + 1];
 int i;
 int fnumber;
 const char *buff;
 (*buffpoint)++;
 buff = *buffpoint;
 if (**buffpoint == '*') {
  fprintRTF("*");
  return;
 }
 i = 0;
 while (**buffpoint != '*') {
  if ((i >= 100) || (**buffpoint == '\0'))
   diagnostics(0, "No terminating '*' in font name\nFound in cfg file command <%s>",buff);
  fontname[i] = **buffpoint;
  i++;
  (*buffpoint)++;
 }
 fontname[i] = '\0';
 fnumber = RtfFontNumber(fontname);
 if (fnumber< 0)
  diagnostics(0,"Unknown font <%s>\nFound in cfg file command <%s>",fontname,buff);
 else
  fprintRTF("%u", (unsigned int) fnumber);
}

canonical_original_code:
void WriteFontName(char **buffpoint)
{
 char fontname[-1];
 int i;
 int fnumber;
 char *buff;
 (*buffpoint)++;
 buff = *buffpoint;
 if (**buffpoint == '*') {
  fprintRTF("*");
  return;
 }
 i = 0;
 while (**buffpoint != '*') {
  if ((i >= 100) || (**buffpoint == '\0'))
   diagnostics(0, "No terminating '*' in font name\nFound in cfg file command <%s>",buff);
  fontname[i] = **buffpoint;
  i++;
  (*buffpoint)++;
 }
 fontname[i] = '\0';
 fnumber = RtfFontNumber(fontname);
 if (fnumber< 0)
  diagnostics(0,"Unknown font <%s>\nFound in cfg file command <%s>",fontname,buff);
 else
  fprintRTF("%u", (unsigned int) fnumber);
}

variable_types:
buffpoint
char **

variable_types:
fontname
char [-1]

variable_types: fnumber int

variable_types:
buff
char *


TryDirectConvert

decompiled_code:
__int64 __fastcall TryDirectConvert(__int64 a1)
{
char *v1; // rbx
char *v2; // rcx
__int64 result; // rax
__int64 i; // rsi
char *v5; // [rsp+8h] [rbp-10h] BYREF

v1 = (char *)strdup_together(&unk_168, a1);
v2 = (char *)SearchRtfCmd(v1, 0LL);
result = 0LL;
if ( v2 )
{
v5 = v2;
diagnostics(4LL, "Directly converting %s to %s", v1, v2);
for ( i = (unsigned __int8)*v5; (_BYTE)i; i = (unsigned __int8)*v5 )
{
if ( (_BYTE)i == 42 )
WriteFontName(&v5, i);
else
fprintRTF("%c", (unsigned int)(char)i);
++v5;
}
free(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v1; // rbx
char *v2; // rcx
__int64 result; // rax
__int64 i; // rsi
char *v5; // [rsp+8h] [rbp-10h] BYREF

v1 = (char *)strdup_together(&unk_168, a1);
v2 = (char *)SearchRtfCmd(v1, 0LL);
result = 0LL;
if ( v2 )
{
v5 = v2;
diagnostics(4LL, "Directly converting %s to %s", v1, v2);
for ( i = (unsigned __int8)*v5; (_BYTE)i; i = (unsigned __int8)*v5 )
{
if ( (_BYTE)i == 42 )
func0(&v5, i);
else
fprintRTF("%c", (unsigned int)(char)i);
++v5;
}
free(v1);
result = 1LL;
}
return result;
}

original_code:
bool
TryDirectConvert(char *command)
{
 const char *buffpoint;
 const char *RtfCommand;
 char *TexCommand;
 TexCommand = strdup_together("\\",command);
 RtfCommand = SearchRtfCmd(TexCommand, 0);
 if (RtfCommand == ((void *)0))
  return 0;
 buffpoint = RtfCommand;
 diagnostics(4, "Directly converting %s to %s", TexCommand, RtfCommand);
 while (buffpoint[0] != '\0') {
  if (buffpoint[0] == '*')
   WriteFontName(&buffpoint);
  else
   fprintRTF("%c", *buffpoint);
  ++buffpoint;
 }
 free(TexCommand);
 return 1;
}

canonical_original_code:
int TryDirectConvert(char *command)
{
 char *buffpoint;
 char *RtfCommand;
 char *TexCommand;
 TexCommand = strdup_together("\\",command);
 RtfCommand = SearchRtfCmd(TexCommand, 0);
 if (RtfCommand == ((void *)0))
  return 0;
 buffpoint = RtfCommand;
 diagnostics(4, "Directly converting %s to %s", TexCommand, RtfCommand);
 while (buffpoint[0] != '\0') {
  if (buffpoint[0] == '*')
   WriteFontName(&buffpoint);
  else
   fprintRTF("%c", *buffpoint);
  ++buffpoint;
 }
 free(TexCommand);
 return 1;
}

variable_types:
command
char *

variable_types:
buffpoint
char *

variable_types:
RtfCommand
char *

variable_types:
TexCommand
char *


usage

repo: raas/mbw

decompiled_code:
int usage()
{
printf("mbw memory benchmark v%s, https://github.com/raas/mbw\n", "1.5");
puts("Usage: mbw [options] array_size_in_MiB");
puts("Options:");
puts("\t-n: number of runs per test (0 to run forever)");
puts("\t-a: Don't display average");
printf("\t-t%d: memcpy test\n", 0LL);
printf("\t-t%d: dumb (b[i]=a[i] style) test\n", 1LL);
printf("\t-t%d: memcpy test with fixed block size\n", 2LL);
printf("\t-b <size>: block size in bytes for -t2 (default: %d)\n", 0x40000LL);
puts("\t-q: quiet (print statistics only)");
puts("(will then use two arrays, watch out for swapping)");
puts("'Bandwidth' is amount of data copied over the time this operation took.");
return puts("\nThe default is to run all tests available.");
}

canonical_decompiled_code:
int func7()
{
printf("mbw memory benchmark v%s, https://github.com/raas/mbw\n", "1.5");
puts("Usage: mbw [options] array_size_in_MiB");
puts("Options:");
puts("\t-n: number of runs per test (0 to run forever)");
puts("\t-a: Don't display average");
printf("\t-t%d: memcpy test\n", 0LL);
printf("\t-t%d: dumb (b[i]=a[i] style) test\n", 1LL);
printf("\t-t%d: memcpy test with fixed block size\n", 2LL);
printf("\t-b <size>: block size in bytes for -t2 (default: %d)\n", 0x40000LL);
puts("\t-q: quiet (print statistics only)");
puts("(will then use two arrays, watch out for swapping)");
puts("'Bandwidth' is amount of data copied over the time this operation took.");
return puts("\nThe default is to run all tests available.");
}

original_code:
void usage()
{
    printf("mbw memory benchmark v%s, https://github.com/raas/mbw\n", "1.5");
    printf("Usage: mbw [options] array_size_in_MiB\n");
    printf("Options:\n");
    printf("	-n: number of runs per test (0 to run forever)\n");
    printf("	-a: Don't display average\n");
    printf("	-t%d: memcpy test\n", 0);
    printf("	-t%d: dumb (b[i]=a[i] style) test\n", 1);
    printf("	-t%d: memcpy test with fixed block size\n", 2);
    printf("	-b <size>: block size in bytes for -t2 (default: %d)\n", 262144);
    printf("	-q: quiet (print statistics only)\n");
    printf("(will then use two arrays, watch out for swapping)\n");
    printf("'Bandwidth' is amount of data copied over the time this operation took.\n");
    printf("\nThe default is to run all tests available.\n");
}


worker

decompiled_code:
double __fastcall worker(__int64 a1, char *a2, char *a3, int a4, size_t a5)
{
char *v5; // r12
size_t v7; // r14
__int64 i; // rax
struct timeval v11; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v5 = a2;
v7 = 8 * a1;
switch ( a4 )
{
case 0:
gettimeofday(&tv, 0LL);
memcpy(a3, a2, v7);
gettimeofday(&v11, 0LL);
return (double)(LODWORD(v11.tv_usec) + 1000000 * (LODWORD(v11.tv_sec) - LODWORD(tv.tv_sec)) - LODWORD(tv.tv_usec))
/ 1000000.0;
case 2:
gettimeofday(&tv, 0LL);
for ( ; a5 <= v7; v5 += a5 )
{
memcpy(a3, v5, a5);
a3 += a5;
v7 -= a5;
}
if ( v7 )
memcpy(a3, v5, v7);
goto LABEL_10;
case 1:
gettimeofday(&tv, 0LL);
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
*(_QWORD *)&a3[8 * i] = *(_QWORD *)&a2[8 * i];
}
LABEL_10:
gettimeofday(&v11, 0LL);
break;
}
return (double)(LODWORD(v11.tv_usec) + 1000000 * (LODWORD(v11.tv_sec) - LODWORD(tv.tv_sec)) - LODWORD(tv.tv_usec))
/ 1000000.0;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1, char *a2, char *a3, int a4, size_t a5)
{
char *v5; // r12
size_t v7; // r14
__int64 i; // rax
struct timeval v11; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v5 = a2;
v7 = 8 * a1;
switch ( a4 )
{
case 0:
gettimeofday(&tv, 0LL);
memcpy(a3, a2, v7);
gettimeofday(&v11, 0LL);
return (double)(LODWORD(v11.tv_usec) + 1000000 * (LODWORD(v11.tv_sec) - LODWORD(tv.tv_sec)) - LODWORD(tv.tv_usec))
/ 1000000.0;
case 2:
gettimeofday(&tv, 0LL);
for ( ; a5 <= v7; v5 += a5 )
{
memcpy(a3, v5, a5);
a3 += a5;
v7 -= a5;
}
if ( v7 )
memcpy(a3, v5, v7);
goto LABEL_10;
case 1:
gettimeofday(&tv, 0LL);
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
*(_QWORD *)&a3[8 * i] = *(_QWORD *)&a2[8 * i];
}
LABEL_10:
gettimeofday(&v11, 0LL);
break;
}
return (double)(LODWORD(v11.tv_usec) + 1000000 * (LODWORD(v11.tv_sec) - LODWORD(tv.tv_sec)) - LODWORD(tv.tv_usec))
/ 1000000.0;
}

original_code:
double worker(unsigned long long asize, long *a, long *b, int type, unsigned long long block_size)
{
    unsigned long long t;
    struct timeval starttime, endtime;
    double te;
    unsigned int long_size=sizeof(long);
    unsigned long long array_bytes=asize*long_size;
    if(type==0) {
        gettimeofday(&starttime, ((void *)0));
        memcpy(b, a, array_bytes);
        gettimeofday(&endtime, ((void *)0));
    } else if(type==2) {
        char* src = (char*)a;
        char* dst = (char*)b;
        gettimeofday(&starttime, ((void *)0));
        for (t=array_bytes; t >= block_size; t-=block_size, src+=block_size){
            dst=(char *) memcpy(dst, src, block_size) + block_size;
        }
        if(t) {
            dst=(char *) memcpy(dst, src, t) + t;
        }
        gettimeofday(&endtime, ((void *)0));
    } else if(type==1) {
        gettimeofday(&starttime, ((void *)0));
        for(t=0; t<asize; t++) {
            b[t]=a[t];
        }
        gettimeofday(&endtime, ((void *)0));
    }
    te=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
    return te;
}

canonical_original_code:
double worker(unsigned long long asize, long *a, long *b, int type, unsigned long long block_size)
{
    unsigned long long t;
    struct timeval starttime; struct timeval endtime;
    double te;
    unsigned int long_size = sizeof(long);
    unsigned long long array_bytes = asize*long_size;
    if(type==0) {
        gettimeofday(&starttime, ((void *)0));
        memcpy(b, a, array_bytes);
        gettimeofday(&endtime, ((void *)0));
    } else if(type==2) {
        char *src = (char*)a;
        char *dst = (char*)b;
        gettimeofday(&starttime, ((void *)0));
        for (t=array_bytes; t >= block_size; t-=block_size, src+=block_size){
            dst=(char *) memcpy(dst, src, block_size) + block_size;
        }
        if(t) {
            dst=(char *) memcpy(dst, src, t) + t;
        }
        gettimeofday(&endtime, ((void *)0));
    } else if(type==1) {
        gettimeofday(&starttime, ((void *)0));
        for(t=0; t<asize; t++) {
            b[t]=a[t];
        }
        gettimeofday(&endtime, ((void *)0));
    }
    te=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
    return te;
}

variable_types:
asize
unsigned long long

variable_types:
a
long *

variable_types:
b
long *

variable_types: type int

variable_types:
t
unsigned long long

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: te double

variable_types:
src
char *

variable_types:
dst
char *

return_type: double


printout

decompiled_code:
int __fastcall printout(int a1, double a2, double a3)
{
switch ( a1 )
{
case 1:
printf("Method: DUMB\t");
break;
case 2:
printf("Method: MCBLOCK\t");
break;
case 0:
printf("Method: MEMCPY\t");
break;
}
printf("Elapsed: %.5f\t", a2);
printf("MiB: %.5f\t", a3);
return printf("Copy: %.3f MiB/s\n", a3 / a2);
}

canonical_decompiled_code:
int __fastcall func9(int a1, double a2, double a3)
{
switch ( a1 )
{
case 1:
printf("Method: DUMB\t");
break;
case 2:
printf("Method: MCBLOCK\t");
break;
case 0:
printf("Method: MEMCPY\t");
break;
}
printf("Elapsed: %.5f\t", a2);
printf("MiB: %.5f\t", a3);
return printf("Copy: %.3f MiB/s\n", a3 / a2);
}

original_code:
void printout(double te, double mt, int type)
{
    switch(type) {
        case 0:
            printf("Method: MEMCPY\t");
            break;
        case 1:
            printf("Method: DUMB\t");
            break;
        case 2:
            printf("Method: MCBLOCK\t");
            break;
    }
    printf("Elapsed: %.5f\t", te);
    printf("MiB: %.5f\t", mt);
    printf("Copy: %.3f MiB/s\n", mt/te);
    return;
}

variable_types: mt double


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
unsigned __int64 v4; // rbx
int v5; // ebp
int v6; // eax
unsigned __int64 v7; // rax
int v8; // eax
unsigned __int64 v9; // rax
double v10; // xmm0_8
unsigned __int64 v11; // r14
char *v12; // r15
__int64 i; // r13
int v14; // er12
int result; // eax
double v16; // [rsp+8h] [rbp-70h]
double v17; // [rsp+10h] [rbp-68h]
double v18; // [rsp+18h] [rbp-60h]
char *ptr; // [rsp+20h] [rbp-58h]
int v20; // [rsp+2Ch] [rbp-4Ch]
int v21; // [rsp+34h] [rbp-44h]
int v22; // [rsp+38h] [rbp-40h]
int v23; // [rsp+3Ch] [rbp-3Ch]

v21 = 0;
v22 = 0;
v23 = 0;
v3 = 0;
v20 = 1;
v4 = 0x40000LL;
v5 = 10;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "haqn:t:b:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'a':
v20 = 0;
break;
case 'b':
v4 = strtoull(optarg, 0LL, 10);
if ( !v4 )
{
puts("Error: what block size do you mean?");
exit(1);
}
return result;
case 'h':
usage();
exit(1);
case 'n':
v5 = strtoul(optarg, 0LL, 10);
break;
case 'q':
v3 = 1;
break;
case 't':
v7 = strtoul(optarg, 0LL, 10);
if ( v7 > 2 )
{
printf("Error: test number must be between 0 and %d\n", 2LL);
exit(1);
}
*(&v21 + v7) = 1;
break;
default:
continue;
}
}
if ( !(v23 + v21 + v22) )
{
v21 = 1;
v22 = 1;
v23 = 1;
if ( v5 )
goto LABEL_15;
LABEL_27:
puts("Error: nr_loops can be zero if only one test selected!");
exit(1);
}
if ( !v5 && v23 + v21 + v22 != 1 )
goto LABEL_27;
LABEL_15:
v8 = _bss_start;
if ( _bss_start >= argc )
{
puts("Error: no array size given!");
exit(1);
}
++_bss_start;
v9 = strtoul(argv[v8], 0LL, 10);
if ( (v9 & 0x8000000000000000LL) != 0LL )
v18 = (double)(int)(v9 & 1 | (v9 >> 1)) + (double)(int)(v9 & 1 | (v9 >> 1));
else
v18 = (double)(int)v9;
if ( v18 <= 0.0 )
{
puts("Error: array size wrong!");
exit(1);
}
v10 = v18 * 131072.0;
if ( v18 * 131072.0 >= 9.223372036854776e18 )
v11 = (unsigned int)(int)(v10 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v11 = (unsigned int)(int)v10;
if ( 8 * v11 < v4 )
{
printf("Error: array size larger than block size (%llu bytes)!\n", v4);
exit(1);
}
if ( v3 )
{
v12 = (char *)make_array(v11);
ptr = (char *)make_array(v11);
}
else
{
printf("Long uses %d bytes. ", 8LL);
printf("Allocating 2*%lld elements = %lld bytes of memory.\n", v11, 16 * v11);
if ( v23 )
printf("Using %lld bytes as blocks for memcpy block copy test.\n", v4);
v12 = (char *)make_array(v11);
ptr = (char *)make_array(v11);
printf("Getting down to business... Doing %d runs per test.\n", (unsigned int)v5);
}
for ( i = 0LL; i != 3; ++i )
{
if ( *(&v21 + i) )
{
if ( v5 < 0 )
{
v17 = 0.0;
}
else
{
v14 = 0;
v17 = 0.0;
do
{
do
{
v16 = worker(v11, v12, ptr, i, v4);
v17 = v17 + v16;
printf("%d\t", (unsigned int)v14);
printout(i, v16, v18);
++v14;
}
while ( v5 > v14 );
}
while ( !v5 );
}
if ( v20 )
{
printf("AVG\t");
printout(i, v17 / (double)v5, v18);
}
}
}
free(v12);
free(ptr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
unsigned __int64 v4; // rbx
int v5; // ebp
int v6; // eax
unsigned __int64 v7; // rax
int v8; // eax
unsigned __int64 v9; // rax
double v10; // xmm0_8
unsigned __int64 v11; // r14
char *v12; // r15
__int64 i; // r13
int v14; // er12
int result; // eax
double v16; // [rsp+8h] [rbp-70h]
double v17; // [rsp+10h] [rbp-68h]
double v18; // [rsp+18h] [rbp-60h]
char *ptr; // [rsp+20h] [rbp-58h]
int v20; // [rsp+2Ch] [rbp-4Ch]
int v21; // [rsp+34h] [rbp-44h]
int v22; // [rsp+38h] [rbp-40h]
int v23; // [rsp+3Ch] [rbp-3Ch]

v21 = 0;
v22 = 0;
v23 = 0;
v3 = 0;
v20 = 1;
v4 = 0x40000LL;
v5 = 10;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "haqn:t:b:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'a':
v20 = 0;
break;
case 'b':
v4 = strtoull(optarg, 0LL, 10);
if ( !v4 )
{
puts("Error: what block size do you mean?");
exit(1);
}
return result;
case 'h':
func7();
exit(1);
case 'n':
v5 = strtoul(optarg, 0LL, 10);
break;
case 'q':
v3 = 1;
break;
case 't':
v7 = strtoul(optarg, 0LL, 10);
if ( v7 > 2 )
{
printf("Error: test number must be between 0 and %d\n", 2LL);
exit(1);
}
*(&v21 + v7) = 1;
break;
default:
continue;
}
}
if ( !(v23 + v21 + v22) )
{
v21 = 1;
v22 = 1;
v23 = 1;
if ( v5 )
goto LABEL_15;
LABEL_27:
puts("Error: nr_loops can be zero if only one test selected!");
exit(1);
}
if ( !v5 && v23 + v21 + v22 != 1 )
goto LABEL_27;
LABEL_15:
v8 = _bss_start;
if ( _bss_start >= argc )
{
puts("Error: no array size given!");
exit(1);
}
++_bss_start;
v9 = strtoul(argv[v8], 0LL, 10);
if ( (v9 & 0x8000000000000000LL) != 0LL )
v18 = (double)(int)(v9 & 1 | (v9 >> 1)) + (double)(int)(v9 & 1 | (v9 >> 1));
else
v18 = (double)(int)v9;
if ( v18 <= 0.0 )
{
puts("Error: array size wrong!");
exit(1);
}
v10 = v18 * 131072.0;
if ( v18 * 131072.0 >= 9.223372036854776e18 )
v11 = (unsigned int)(int)(v10 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v11 = (unsigned int)(int)v10;
if ( 8 * v11 < v4 )
{
printf("Error: array size larger than block size (%llu bytes)!\n", v4);
exit(1);
}
if ( v3 )
{
v12 = (char *)make_array(v11);
ptr = (char *)make_array(v11);
}
else
{
printf("Long uses %d bytes. ", 8LL);
printf("Allocating 2*%lld elements = %lld bytes of memory.\n", v11, 16 * v11);
if ( v23 )
printf("Using %lld bytes as blocks for memcpy block copy test.\n", v4);
v12 = (char *)make_array(v11);
ptr = (char *)make_array(v11);
printf("Getting down to business... Doing %d runs per test.\n", (unsigned int)v5);
}
for ( i = 0LL; i != 3; ++i )
{
if ( *(&v21 + i) )
{
if ( v5 < 0 )
{
v17 = 0.0;
}
else
{
v14 = 0;
v17 = 0.0;
do
{
do
{
v16 = func8(v11, v12, ptr, i, v4);
v17 = v17 + v16;
printf("%d\t", (unsigned int)v14);
func9(i, v16, v18);
++v14;
}
while ( v5 > v14 );
}
while ( !v5 );
}
if ( v20 )
{
printf("AVG\t");
func9(i, v17 / (double)v5, v18);
}
}
}
free(v12);
free(ptr);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    unsigned int long_size=0;
    double te, te_sum;
    unsigned long long asize=0;
    int i;
    long *a, *b;
    int o;
    unsigned long testno;
    int nr_loops=10;
    unsigned long long block_size=262144;
    int showavg=1;
    int tests[3];
    double mt=0;
    int quiet=0;
    tests[0]=0;
    tests[1]=0;
    tests[2]=0;
    while((o=getopt(argc, argv, "haqn:t:b:")) != (-1)) {
        switch(o) {
            case 'h':
                usage();
                exit(1);
                break;
            case 'a':
                showavg=0;
                break;
            case 'n':
                nr_loops=strtoul(optarg, (char **)((void *)0), 10);
                break;
            case 't':
                testno=strtoul(optarg, (char **)((void *)0), 10);
                if(testno>3 -1) {
                    printf("Error: test number must be between 0 and %d\n", 3 -1);
                    exit(1);
                }
                tests[testno]=1;
                break;
            case 'b':
                block_size=strtoull(optarg, (char **)((void *)0), 10);
                if(0>=block_size) {
                    printf("Error: what block size do you mean?\n");
                    exit(1);
                }
                break;
            case 'q':
                quiet=1;
                break;
            default:
                break;
        }
    }
    if( (tests[0]+tests[1]+tests[2]) == 0) {
        tests[0]=1;
        tests[1]=1;
        tests[2]=1;
    }
    if( nr_loops==0 && ((tests[0]+tests[1]+tests[2]) != 1) ) {
        printf("Error: nr_loops can be zero if only one test selected!\n");
        exit(1);
    }
    if(optind<argc) {
        mt=strtoul(argv[optind++], (char **)((void *)0), 10);
    } else {
        printf("Error: no array size given!\n");
        exit(1);
    }
    if(0>=mt) {
        printf("Error: array size wrong!\n");
        exit(1);
    }
    long_size=sizeof(long);
    asize=1024*1024/long_size*mt;
    if(asize*long_size < block_size) {
        printf("Error: array size larger than block size (%llu bytes)!\n", block_size);
        exit(1);
    }
    if(!quiet) {
        printf("Long uses %d bytes. ", long_size);
        printf("Allocating 2*%lld elements = %lld bytes of memory.\n", asize, 2*asize*long_size);
        if(tests[2]) {
            printf("Using %lld bytes as blocks for memcpy block copy test.\n", block_size);
        }
    }
    a=make_array(asize);
    b=make_array(asize);
    if(!quiet) {
        printf("Getting down to business... Doing %d runs per test.\n", nr_loops);
    }
    for(testno=0; testno<3; testno++) {
        te_sum=0;
        if(tests[testno]) {
            for (i=0; nr_loops==0 || i<nr_loops; i++) {
                te=worker(asize, a, b, testno, block_size);
                te_sum+=te;
                printf("%d\t", i);
                printout(te, mt, testno);
            }
            if(showavg) {
                printf("AVG\t");
                printout(te_sum/nr_loops, mt, testno);
            }
        }
    }
    free(a);
    free(b);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned int long_size = 0;
    double te; double te_sum;
    unsigned long long asize = 0;
    int i;
    long *a; long *b;
    int o;
    unsigned long testno;
    int nr_loops = 10;
    unsigned long long block_size = 262144;
    int showavg = 1;
    int tests[3];
    double mt = 0;
    int quiet = 0;
    tests[0]=0;
    tests[1]=0;
    tests[2]=0;
    while((o=getopt(argc, argv, "haqn:t:b:")) != (-1)) {
        switch(o) {
            case 'h':
                usage();
                exit(1);
                break;
            case 'a':
                showavg=0;
                break;
            case 'n':
                nr_loops=strtoul(optarg, (char **)((void *)0), 10);
                break;
            case 't':
                testno=strtoul(optarg, (char **)((void *)0), 10);
                if(testno>3 -1) {
                    printf("Error: test number must be between 0 and %d\n", 3 -1);
                    exit(1);
                }
                tests[testno]=1;
                break;
            case 'b':
                block_size=strtoull(optarg, (char **)((void *)0), 10);
                if(0>=block_size) {
                    printf("Error: what block size do you mean?\n");
                    exit(1);
                }
                break;
            case 'q':
                quiet=1;
                break;
            default:
                break;
        }
    }
    if( (tests[0]+tests[1]+tests[2]) == 0) {
        tests[0]=1;
        tests[1]=1;
        tests[2]=1;
    }
    if( nr_loops==0 && ((tests[0]+tests[1]+tests[2]) != 1) ) {
        printf("Error: nr_loops can be zero if only one test selected!\n");
        exit(1);
    }
    if(optind<argc) {
        mt=strtoul(argv[optind++], (char **)((void *)0), 10);
    } else {
        printf("Error: no array size given!\n");
        exit(1);
    }
    if(0>=mt) {
        printf("Error: array size wrong!\n");
        exit(1);
    }
    long_size=sizeof(long);
    asize=1024*1024/long_size*mt;
    if(asize*long_size < block_size) {
        printf("Error: array size larger than block size (%llu bytes)!\n", block_size);
        exit(1);
    }
    if(!quiet) {
        printf("Long uses %d bytes. ", long_size);
        printf("Allocating 2*%lld elements = %lld bytes of memory.\n", asize, 2*asize*long_size);
        if(tests[2]) {
            printf("Using %lld bytes as blocks for memcpy block copy test.\n", block_size);
        }
    }
    a=make_array(asize);
    b=make_array(asize);
    if(!quiet) {
        printf("Getting down to business... Doing %d runs per test.\n", nr_loops);
    }
    for(testno=0; testno<3; testno++) {
        te_sum=0;
        if(tests[testno]) {
            for (i=0; nr_loops==0 || i<nr_loops; i++) {
                te=worker(asize, a, b, testno, block_size);
                te_sum+=te;
                printf("%d\t", i);
                printout(te, mt, testno);
            }
            if(showavg) {
                printf("AVG\t");
                printout(te_sum/nr_loops, mt, testno);
            }
        }
    }
    free(a);
    free(b);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: o int

variable_types:
testno
unsigned long

variable_types: showavg int

variable_types:
tests
int [3]

variable_types: quiet int


decompiled_code:
__int64 __fastcall mount_list_size(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

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

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int mount_list_size(MountList *mount_list) {
    int size = -1;
    for (size = 0; mount_list -> mounts[size] != ((void *)0); size++);
    return size;
}

canonical_original_code:
int mount_list_size(struct MountList *mount_list) {
    int size = -1;
    for (size = 0; mount_list -> mounts[size] != ((void *)0); size++);
    return size;
}

variable_types: struct MountList { struct Mount { char *directory_path; char *device; } *mounts[100]; } *

variable_types: size int

user_defined_types: struct MountList { struct Mount *mounts[100]; }