findTypeInScope

decompiled_code:
int *__fastcall findTypeInScope(const char *a1, int ****a2)
{
int **v2; // rax
int **v3; // r12
const char *v4; // rbp
int *result; // rax

g_log(0LL, 32LL, "findTypeInScope(identifier: %s, scope: <ScopeChain at %p>)", a1, a2);
v2 = findDeclarationInScope(a1, a2);
v3 = v2;
if ( v2 )
{
v4 = (const char *)stringFromType(v2[1]);
g_log(0LL, 32LL, "findTypeInScope() = <VariableType - %s>", v4);
g_free(v4);
result = v3[1];
}
else
{
g_log(0LL, 32LL, "findTypeInScope() = NULL");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func18(const char *a1, int ****a2)
{
int **v2; // rax
int **v3; // r12
const char *v4; // rbp
int *result; // rax

g_log(0LL, 32LL, "findTypeInScope(identifier: %s, scope: <ScopeChain at %p>)", a1, a2);
v2 = func16(a1, a2);
v3 = v2;
if ( v2 )
{
v4 = (const char *)func4(v2[1]);
g_log(0LL, 32LL, "findTypeInScope() = <VariableType - %s>", v4);
g_free(v4);
result = v3[1];
}
else
{
g_log(0LL, 32LL, "findTypeInScope() = NULL");
result = 0LL;
}
return result;
}

original_code:
VariableType *findTypeInScope(char *identifier, ScopeChain *scope) {
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "findTypeInScope(identifier: %s, scope: <ScopeChain at %p>)", identifier, scope);
    VariableDeclaration *declaration = findDeclarationInScope(identifier, scope);
    if (declaration != ((void *)0)) {
        char *type_s = stringFromType(declaration->type);
        g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "findTypeInScope() = <VariableType - %s>", type_s);
        g_free(type_s);
        return declaration->type;
    } else {
        g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "findTypeInScope() = NULL");
        return ((void *)0);
    }
}

canonical_original_code:
struct _VariableType *findTypeInScope(char *identifier, struct _ScopeChain *scope) {
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "findTypeInScope(identifier: %s, scope: <ScopeChain at %p>)", identifier, scope);
    struct _VariableDeclaration *declaration = findDeclarationInScope(identifier, scope);
    if (declaration != ((void *)0)) {
        char *type_s = stringFromType(declaration->type);
        g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "findTypeInScope() = <VariableType - %s>", type_s);
        g_free(type_s);
        return declaration->type;
    } else {
        g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "findTypeInScope() = NULL");
        return ((void *)0);
    }
}


checkIsInteger

decompiled_code:
__int64 __fastcall checkIsInteger(int *a1)
{
const char *v1; // rbp
__int64 result; // rax

if ( !a1 )
return g_log(0LL, 16LL, "checkIsInteger(type: <NULL>)");
v1 = (const char *)stringFromType(a1);
g_log(0LL, 32LL, "checkIsInteger(type: <VariableType at %p - %s>)", a1, v1);
g_free(v1);
result = (unsigned int)*a1;
if ( (_DWORD)result )
{
g_log(0LL, 8LL, "expression must be an int");
exit(3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(int *a1)
{
const char *v1; // rbp
__int64 result; // rax

if ( !a1 )
return g_log(0LL, 16LL, "checkIsInteger(type: <NULL>)");
v1 = (const char *)func4(a1);
g_log(0LL, 32LL, "checkIsInteger(type: <VariableType at %p - %s>)", a1, v1);
g_free(v1);
result = (unsigned int)*a1;
if ( (_DWORD)result )
{
g_log(0LL, 8LL, "expression must be an int");
exit(3);
}
return result;
}

original_code:
void checkIsInteger(VariableType *type) {
    if (type == ((void *)0)) {
        g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "checkIsInteger(type: <NULL>)");
        return;
    }
    char *type_s = stringFromType(type);
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "checkIsInteger(type: <VariableType at %p - %s>)", type, type_s);
    g_free(type_s);
    if (type->rank != 0) {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "expression must be an int");
        exit(StatusSemanticError);
    }
}

canonical_original_code:
void checkIsInteger(struct _VariableType *type) {
    if (type == ((void *)0)) {
        g_log (((char *) 0), G_LOG_LEVEL_WARNING, "checkIsInteger(type: <NULL>)");
        return;
    }
    char *type_s = stringFromType(type);
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "checkIsInteger(type: <VariableType at %p - %s>)", type, type_s);
    g_free(type_s);
    if (type->rank != 0) {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "expression must be an int");
        exit(StatusSemanticError);
    }
}

variable_types: struct _VariableType { int rank; enum PrimitiveType { PrimitiveUndefined=0, PrimitiveInt=1 } primitive; } *

return_type: void

user_defined_types: struct _VariableType { int rank; enum PrimitiveType primitive; }


checkIsArray

decompiled_code:
__int64 __fastcall checkIsArray(int *a1)
{
const char *v1; // rbp
__int64 result; // rax

if ( !a1 )
return g_log(0LL, 16LL, "checkIsArray(type: <NULL>)");
v1 = (const char *)stringFromType(a1);
g_log(0LL, 32LL, "checkIsArray(type: <VariableType at %p - %s>)", a1, v1);
g_free(v1);
result = (unsigned int)*a1;
if ( (int)result <= 0 )
{
g_log(0LL, 8LL, "expression must be an array");
exit(3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(int *a1)
{
const char *v1; // rbp
__int64 result; // rax

if ( !a1 )
return g_log(0LL, 16LL, "checkIsArray(type: <NULL>)");
v1 = (const char *)func4(a1);
g_log(0LL, 32LL, "checkIsArray(type: <VariableType at %p - %s>)", a1, v1);
g_free(v1);
result = (unsigned int)*a1;
if ( (int)result <= 0 )
{
g_log(0LL, 8LL, "expression must be an array");
exit(3);
}
return result;
}

original_code:
void checkIsArray(VariableType *type) {
    if (type == ((void *)0)) {
        g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "checkIsArray(type: <NULL>)");
        return;
    }
    char *type_s = stringFromType(type);
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "checkIsArray(type: <VariableType at %p - %s>)", type, type_s);
    g_free(type_s);
    if (type->rank <= 0) {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "expression must be an array");
        exit(StatusSemanticError);
    }
}

canonical_original_code:
void checkIsArray(struct _VariableType *type) {
    if (type == ((void *)0)) {
        g_log (((char *) 0), G_LOG_LEVEL_WARNING, "checkIsArray(type: <NULL>)");
        return;
    }
    char *type_s = stringFromType(type);
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "checkIsArray(type: <VariableType at %p - %s>)", type, type_s);
    g_free(type_s);
    if (type->rank <= 0) {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "expression must be an array");
        exit(StatusSemanticError);
    }
}

user_defined_types: enum PrimitiveType { PrimitiveUndefined=0, PrimitiveInt=1 }


decompiled_code:
__int64 __fastcall stringFromType0(int *a1)
{
const char *v1; // r13
__int64 v2; // rbp

if ( !a1 )
return g_strdup("<NULL>");
v1 = (const char *)stringFromType(a1);
v2 = g_string_new(&s);
g_string_printf(v2, "<VariableType at %p - %s>", a1, v1);
g_free(v1);
return g_string_free(v2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func21(int *a1)
{
const char *v1; // r13
__int64 v2; // rbp

if ( !a1 )
return g_strdup("<NULL>");
v1 = (const char *)func4(a1);
v2 = g_string_new(&s);
g_string_printf(v2, "<VariableType at %p - %s>", a1, v1);
g_free(v1);
return g_string_free(v2, 0LL);
}

original_code:
char *stringFromType0(VariableType *type) {
    if (type == ((void *)0)) return g_strdup("<NULL>");
    char *type_s = stringFromType(type);
    GString *result = g_string_new("");
    g_string_printf(result, "<VariableType at %p - %s>", type, type_s);
    g_free(type_s);
    return g_string_free(result, (0));
}

canonical_original_code:
char *stringFromType0(struct _VariableType *type) {
    if (type == ((void *)0)) return g_strdup("<NULL>");
    char *type_s = stringFromType(type);
    struct _GString *result = g_string_new("");
    g_string_printf(result, "<VariableType at %p - %s>", type, type_s);
    g_free(type_s);
    return g_string_free(result, (0));
}

variable_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *

return_type: char *


checkSameType

decompiled_code:
__int64 __fastcall checkSameType(int *a1, int *a2)
{
const char *v2; // r14
const char *v3; // rax
const char *v4; // r13

v2 = (const char *)stringFromType0(a1);
v3 = (const char *)stringFromType0(a2);
v4 = v3;
if ( !a1 || !a2 )
return g_log(0LL, 16LL, "checkSameType(left: %s, right: %s)", v2, v3);
g_log(0LL, 32LL, "checkSameType(left: %s, right: %s)", v2, v3);
if ( !eqVariableType(a1, a2) )
{
g_log(0LL, 8LL, "checkSameType(): left-hand-type must be equal to right-hand-type");
exit(3);
}
g_free(v2);
return g_free(v4);
}

canonical_decompiled_code:
__int64 __fastcall func22(int *a1, int *a2)
{
const char *v2; // r14
const char *v3; // rax
const char *v4; // r13

v2 = (const char *)func21(a1);
v3 = (const char *)func21(a2);
v4 = v3;
if ( !a1 || !a2 )
return g_log(0LL, 16LL, "checkSameType(left: %s, right: %s)", v2, v3);
g_log(0LL, 32LL, "checkSameType(left: %s, right: %s)", v2, v3);
if ( !func2(a1, a2) )
{
g_log(0LL, 8LL, "checkSameType(): left-hand-type must be equal to right-hand-type");
exit(3);
}
g_free(v2);
return g_free(v4);
}

original_code:
void checkSameType(VariableType *left, VariableType *right) {
    char *left_s = stringFromType0(left);
    char *right_s = stringFromType0(right);
    if (left == ((void *)0) || right == ((void *)0)) {
        g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "checkSameType(left: %s, right: %s)", left_s, right_s);
        return;
    }
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "checkSameType(left: %s, right: %s)", left_s, right_s);
    if (!eqVariableType(left, right)) {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "checkSameType(): left-hand-type must be equal to right-hand-type");
        exit(StatusSemanticError);
    }
    g_free(left_s);
    g_free(right_s);
}

canonical_original_code:
void checkSameType(struct _VariableType *left, struct _VariableType *right) {
    char *left_s = stringFromType0(left);
    char *right_s = stringFromType0(right);
    if (left == ((void *)0) || right == ((void *)0)) {
        g_log (((char *) 0), G_LOG_LEVEL_WARNING, "checkSameType(left: %s, right: %s)", left_s, right_s);
        return;
    }
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "checkSameType(left: %s, right: %s)", left_s, right_s);
    if (!eqVariableType(left, right)) {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "checkSameType(): left-hand-type must be equal to right-hand-type");
        exit(StatusSemanticError);
    }
    g_free(left_s);
    g_free(right_s);
}

variable_types:
right
struct _VariableType *


repo: miminashi/KAGE

original_code:
KGString* kg_string_set_size(KGString *target, int newSize){
  target->len = newSize;
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  target->str[target->len] = '\0';
  return target;
}

canonical_original_code:
struct _KGString *kg_string_set_size(struct _KGString *target, int newSize){
  target->len = newSize;
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  target->str[target->len] = '\0';
  return target;
}

variable_types:
target
struct _KGString *

variable_types: newSize int

return_type: struct _KGString { char *str; int len; } *


decompiled_code:
__int64 __fastcall kg_string_append_len(__int64 a1, const char *a2, int a3)
{
int v5; // esi
char *v6; // rax

v5 = a3 + *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v5;
v6 = (char *)realloc(*(void **)a1, v5 + 1);
*(_QWORD *)a1 = v6;
strncat(v6, a2, a3);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
int v5; // esi
char *v6; // rax

v5 = a3 + *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v5;
v6 = (char *)realloc(*(void **)a1, v5 + 1);
*(_QWORD *)a1 = v6;
strncat(v6, a2, a3);
return a1;
}

original_code:
KGString* kg_string_append_len(KGString *target, char *appendString, int length){
  target->len = target->len + length;
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strncat(target->str, appendString, length);
  return target;
}

canonical_original_code:
struct _KGString *kg_string_append_len(struct _KGString *target, char *appendString, int length){
  target->len = target->len + length;
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strncat(target->str, appendString, length);
  return target;
}

variable_types:
appendString
char *

variable_types: length int

user_defined_types: struct _KGString { char *str; int len; }


decompiled_code:
__int64 __fastcall kg_string_append(__int64 a1, const char *a2)
{
int v3; // eax
void *v4; // rdi
char *v5; // rax

v3 = *(_DWORD *)(a1 + 8) + strlen(a2);
v4 = *(void **)a1;
*(_DWORD *)(a1 + 8) = v3;
v5 = (char *)realloc(v4, v3 + 1);
*(_QWORD *)a1 = v5;
strcat(v5, a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
int v3; // eax
void *v4; // rdi
char *v5; // rax

v3 = *(_DWORD *)(a1 + 8) + strlen(a2);
v4 = *(void **)a1;
*(_DWORD *)(a1 + 8) = v3;
v5 = (char *)realloc(v4, v3 + 1);
*(_QWORD *)a1 = v5;
strcat(v5, a2);
return a1;
}

original_code:
KGString* kg_string_append(KGString *target, char *appendString){
  target->len = target->len + strlen(appendString);
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strcat(target->str, appendString);
  return target;
}

canonical_original_code:
struct _KGString *kg_string_append(struct _KGString *target, char *appendString){
  target->len = target->len + strlen(appendString);
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strcat(target->str, appendString);
  return target;
}


decompiled_code:
__int64 __fastcall kg_string_erase(__int64 a1, int a2, int a3)
{
size_t v4; // rbp
char *v5; // rax
char *v6; // r15
char *v7; // r13
char *v8; // rax
int v10; // [rsp+Ch] [rbp-3Ch]

v10 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v10 - a3;
v4 = v10 - a3 + 1;
v5 = (char *)malloc(v4);
v6 = *(char **)a1;
v7 = v5;
strncpy(v5, *(const char **)a1, a2);
v7[a2] = 0;
if ( a3 + a2 < v10 )
strcat(v7, &v6[a2 + (__int64)a3]);
v8 = (char *)realloc(v6, v4);
*(_QWORD *)a1 = v8;
strcpy(v8, v7);
free(v7);
return a1;
}

original_code:
KGString* kg_string_erase(KGString *target, int startPoint, int length){
  char *tmp;
  int oldLength;
  oldLength = target->len;
  target->len = target->len - length;
  tmp = (char *)malloc(target->len + 1);
  strncpy(tmp, target->str, startPoint);
  tmp[startPoint] = '\0';
  if(oldLength > startPoint + length) strcat(tmp, target->str + startPoint + length);
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strcpy(target->str, tmp);
  free(tmp);
  return target;
}

canonical_original_code:
struct _KGString *kg_string_erase(struct _KGString *target, int startPoint, int length){
  char *tmp;
  int oldLength;
  oldLength = target->len;
  target->len = target->len - length;
  tmp = (char *)malloc(target->len + 1);
  strncpy(tmp, target->str, startPoint);
  tmp[startPoint] = '\0';
  if(oldLength > startPoint + length) strcat(tmp, target->str + startPoint + length);
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strcpy(target->str, tmp);
  free(tmp);
  return target;
}

variable_types: startPoint int

variable_types:
tmp
char *

variable_types: oldLength int


decompiled_code:
__int64 __fastcall kg_string_assign(__int64 a1, const char *a2)
{
int v3; // eax
void *v4; // rdi
char *v5; // rax

v3 = strlen(a2);
v4 = *(void **)a1;
*(_DWORD *)(a1 + 8) = v3;
v5 = (char *)realloc(v4, v3 + 1);
*(_QWORD *)a1 = v5;
strcpy(v5, a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
int v3; // eax
void *v4; // rdi
char *v5; // rax

v3 = strlen(a2);
v4 = *(void **)a1;
*(_DWORD *)(a1 + 8) = v3;
v5 = (char *)realloc(v4, v3 + 1);
*(_QWORD *)a1 = v5;
strcpy(v5, a2);
return a1;
}

original_code:
KGString* kg_string_assign(KGString *target, char *assignString){
  target->len = strlen(assignString);
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strcpy(target->str, assignString);
  return target;
}

canonical_original_code:
struct _KGString *kg_string_assign(struct _KGString *target, char *assignString){
  target->len = strlen(assignString);
  target->str = (char *)realloc((char *)target->str, target->len + 1);
  strcpy(target->str, assignString);
  return target;
}

variable_types:
assignString
char *


doCombine

decompiled_code:
char __fastcall doCombine(const void **a1, __int64 a2)
{
__int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // r12
__int64 v7; // r15
bool v8; // zf
int v9; // eax
__int64 v10; // rcx
__int64 v11; // rcx
__int64 v12; // rsi
__int64 v13; // rdi
__int64 v14; // rax
__int64 v15; // rdx
__int64 v16; // rax
__int64 v17; // rax
__int64 v19; // [rsp+0h] [rbp-78h]
__int64 v20; // [rsp+8h] [rbp-70h]
char v21[104]; // [rsp+10h] [rbp-68h] BYREF

v4 = kg_string_new(&unk_10C4);
v19 = kg_string_new(&unk_10C4);
v5 = kg_string_new(&unk_10C4);
v6 = kg_string_new(&unk_10C4);
v20 = kg_string_new(&unk_10C4);
v7 = kg_string_new(&unk_10C4);
kg_string_set_size(a2, 0LL);
v8 = memcmp(*a1, "u2ff", 4uLL) == 0;
LOBYTE(v9) = !v8;
if ( v8 )
{
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
switch ( (char)v9 )
{
case '0':
divideInto2(a1, v4, v5);
v9 = *(_DWORD *)(v4 + 8);
if ( v9 )
{
generateGlyphByIDS(v4, v6, 1LL);
v9 = *(_DWORD *)(v6 + 8);
if ( v9 )
{
v14 = CalcSizes(v6, 0LL);
v15 = 2LL;
v6 = v14;
goto LABEL_14;
}
}
return v9;
case '1':
divideInto2(a1, v4, v5);
v9 = *(_DWORD *)(v4 + 8);
if ( v9 )
{
LOBYTE(v9) = generateGlyphByIDS(v4, v6, 3LL);
if ( *(_DWORD *)(v6 + 8) )
{
v6 = CalcSizes(v6, 0LL);
goto LABEL_31;
}
}
return v9;
case '2':
LOBYTE(v9) = divideInto3(a1, v4, v19, v5);
if ( *(_DWORD *)(v4 + 8) )
{
LOBYTE(v9) = generateGlyphByIDS(v4, v6, 1LL);
if ( *(_DWORD *)(v6 + 8) )
{
v6 = CalcSizes(v6, 0LL);
LOBYTE(v9) = generateGlyphByIDS(v19, v20, 1LL);
if ( *(_DWORD *)(v20 + 8) )
{
v17 = CalcSizes(v20, 0LL);
v15 = 2LL;
v20 = v17;
goto LABEL_14;
}
}
}
return v9;
case '3':
LOBYTE(v9) = divideInto3(a1, v4, v19, v5);
if ( *(_DWORD *)(v4 + 8) )
{
LOBYTE(v9) = generateGlyphByIDS(v4, v6, 3LL);
if ( *(_DWORD *)(v6 + 8) )
{
v6 = CalcSizes(v6, 0LL);
generateGlyphByIDS(v19, v20, 3LL);
v9 = *(_DWORD *)(v20 + 8);
if ( v9 )
{
v20 = CalcSizes(v20, 0LL);
LABEL_31:
v15 = 4LL;
goto LABEL_14;
}
}
}
return v9;
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'a':
LOBYTE(v9) = divideInto2(a1, v4, v5);
if ( *(_DWORD *)(v4 + 8) )
{
LOBYTE(v9) = generateGlyphByIDS(v4, v6, 5LL);
if ( *(_DWORD *)(v6 + 8) )
{
v16 = CalcSizes(v6, 0LL);
v15 = 6LL;
v6 = v16;
LABEL_14:
LOBYTE(v9) = generateGlyphByIDS(v5, v7, v15);
if ( *(_DWORD *)(v7 + 8) )
{
v7 = CalcSizes(v7, 0LL);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
goto LABEL_16;
}
}
}
return v9;
default:
LABEL_16:
switch ( (char)v9 )
{
case '0':
combineYoko2(v6, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '1':
combineTate2(v6, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '2':
combineYoko3(v6, v20, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '3':
combineTate3(v6, v20, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '4':
v10 = 15LL;
goto LABEL_4;
case '5':
v10 = 7LL;
goto LABEL_4;
case '6':
v10 = 11LL;
goto LABEL_4;
case '7':
v10 = 13LL;
goto LABEL_4;
case '8':
v10 = 5LL;
goto LABEL_4;
case '9':
v10 = 6LL;
goto LABEL_4;
case 'a':
v10 = 9LL;
LABEL_4:
combineHame2(v6, v7, v21, v10);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
default:
break;
}
if ( (char)v9 > 51 )
{
if ( (char)v9 <= 57 || (_BYTE)v9 == 97 )
goto LABEL_8;
}
else
{
if ( (char)v9 > 49 )
{
addStrokeWithTransform(v6, 1LL, v21, a2, 1LL);
v13 = v20;
v11 = a2;
v12 = 2LL;
goto LABEL_9;
}
LOBYTE(v9) = v9 - 48;
if ( (unsigned __int8)v9 <= 1u )
{
LABEL_8:
v11 = a2;
v12 = 1LL;
v13 = v6;
LABEL_9:
addStrokeWithTransform(v13, v12, v21, v11, 1LL);
LOBYTE(v9) = addStrokeWithTransform(v7, 3LL, v21, a2, 1LL);
return v9;
}
}
break;
}
}
return v9;
}

canonical_decompiled_code:
char __fastcall func0(const void **a1, __int64 a2)
{
__int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // r12
__int64 v7; // r15
bool v8; // zf
int v9; // eax
__int64 v10; // rcx
__int64 v11; // rcx
__int64 v12; // rsi
__int64 v13; // rdi
__int64 v14; // rax
__int64 v15; // rdx
__int64 v16; // rax
__int64 v17; // rax
__int64 v19; // [rsp+0h] [rbp-78h]
__int64 v20; // [rsp+8h] [rbp-70h]
char v21[104]; // [rsp+10h] [rbp-68h] BYREF

v4 = kg_string_new(&unk_10C4);
v19 = kg_string_new(&unk_10C4);
v5 = kg_string_new(&unk_10C4);
v6 = kg_string_new(&unk_10C4);
v20 = kg_string_new(&unk_10C4);
v7 = kg_string_new(&unk_10C4);
kg_string_set_size(a2, 0LL);
v8 = memcmp(*a1, "u2ff", 4uLL) == 0;
LOBYTE(v9) = !v8;
if ( v8 )
{
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
switch ( (char)v9 )
{
case '0':
divideInto2(a1, v4, v5);
v9 = *(_DWORD *)(v4 + 8);
if ( v9 )
{
func2(v4, v6, 1LL);
v9 = *(_DWORD *)(v6 + 8);
if ( v9 )
{
v14 = CalcSizes(v6, 0LL);
v15 = 2LL;
v6 = v14;
goto LABEL_14;
}
}
return v9;
case '1':
divideInto2(a1, v4, v5);
v9 = *(_DWORD *)(v4 + 8);
if ( v9 )
{
LOBYTE(v9) = func2(v4, v6, 3LL);
if ( *(_DWORD *)(v6 + 8) )
{
v6 = CalcSizes(v6, 0LL);
goto LABEL_31;
}
}
return v9;
case '2':
LOBYTE(v9) = divideInto3(a1, v4, v19, v5);
if ( *(_DWORD *)(v4 + 8) )
{
LOBYTE(v9) = func2(v4, v6, 1LL);
if ( *(_DWORD *)(v6 + 8) )
{
v6 = CalcSizes(v6, 0LL);
LOBYTE(v9) = func2(v19, v20, 1LL);
if ( *(_DWORD *)(v20 + 8) )
{
v17 = CalcSizes(v20, 0LL);
v15 = 2LL;
v20 = v17;
goto LABEL_14;
}
}
}
return v9;
case '3':
LOBYTE(v9) = divideInto3(a1, v4, v19, v5);
if ( *(_DWORD *)(v4 + 8) )
{
LOBYTE(v9) = func2(v4, v6, 3LL);
if ( *(_DWORD *)(v6 + 8) )
{
v6 = CalcSizes(v6, 0LL);
func2(v19, v20, 3LL);
v9 = *(_DWORD *)(v20 + 8);
if ( v9 )
{
v20 = CalcSizes(v20, 0LL);
LABEL_31:
v15 = 4LL;
goto LABEL_14;
}
}
}
return v9;
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'a':
LOBYTE(v9) = divideInto2(a1, v4, v5);
if ( *(_DWORD *)(v4 + 8) )
{
LOBYTE(v9) = func2(v4, v6, 5LL);
if ( *(_DWORD *)(v6 + 8) )
{
v16 = CalcSizes(v6, 0LL);
v15 = 6LL;
v6 = v16;
LABEL_14:
LOBYTE(v9) = func2(v5, v7, v15);
if ( *(_DWORD *)(v7 + 8) )
{
v7 = CalcSizes(v7, 0LL);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
goto LABEL_16;
}
}
}
return v9;
default:
LABEL_16:
switch ( (char)v9 )
{
case '0':
combineYoko2(v6, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '1':
combineTate2(v6, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '2':
combineYoko3(v6, v20, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '3':
combineTate3(v6, v20, v7, v21);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
case '4':
v10 = 15LL;
goto LABEL_4;
case '5':
v10 = 7LL;
goto LABEL_4;
case '6':
v10 = 11LL;
goto LABEL_4;
case '7':
v10 = 13LL;
goto LABEL_4;
case '8':
v10 = 5LL;
goto LABEL_4;
case '9':
v10 = 6LL;
goto LABEL_4;
case 'a':
v10 = 9LL;
LABEL_4:
combineHame2(v6, v7, v21, v10);
LOBYTE(v9) = *((_BYTE *)*a1 + 4);
break;
default:
break;
}
if ( (char)v9 > 51 )
{
if ( (char)v9 <= 57 || (_BYTE)v9 == 97 )
goto LABEL_8;
}
else
{
if ( (char)v9 > 49 )
{
addStrokeWithTransform(v6, 1LL, v21, a2, 1LL);
v13 = v20;
v11 = a2;
v12 = 2LL;
goto LABEL_9;
}
LOBYTE(v9) = v9 - 48;
if ( (unsigned __int8)v9 <= 1u )
{
LABEL_8:
v11 = a2;
v12 = 1LL;
v13 = v6;
LABEL_9:
addStrokeWithTransform(v13, v12, v21, v11, 1LL);
LOBYTE(v9) = addStrokeWithTransform(v7, 3LL, v21, a2, 1LL);
return v9;
}
}
break;
}
}
return v9;
}

original_code:
void doCombine(const KGString *in, KGString *out){
  KGString *partIDS1, *partIDS2, *partIDS3;
  KGString *partStroke1, *partStroke2, *partStroke3;
  int result[12];
  partIDS1 = kg_string_new("");
  partIDS2 = kg_string_new("");
  partIDS3 = kg_string_new("");
  partStroke1 = kg_string_new("");
  partStroke2 = kg_string_new("");
  partStroke3 = kg_string_new("");
  kg_string_set_size(out, 0);
  if(strncmp(in->str, "u2ff", 4) != 0) return;
  switch((in->str)[4]){
  case '0':
    divideInto2(in, partIDS1, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 1);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 2);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '1':
    divideInto2(in, partIDS1, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 3);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 4);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
  case 'a':
    divideInto2(in, partIDS1, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 5);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 6);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '2':
    divideInto3(in, partIDS1, partIDS2, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 1);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS2, partStroke2, 1);
    if(partStroke2->len == 0) return;
    partStroke2 = CalcSizes(partStroke2, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 2);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '3':
    divideInto3(in, partIDS1, partIDS2, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 3);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS2, partStroke2, 3);
    if(partStroke2->len == 0) return;
    partStroke2 = CalcSizes(partStroke2, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 4);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  }
  switch((in->str)[4]){
  case '0':
    combineYoko2(partStroke1, partStroke3, result);
    break;
  case '1':
    combineTate2(partStroke1, partStroke3, result);
    break;
  case '2':
    combineYoko3(partStroke1, partStroke2, partStroke3, result);
    break;
  case '3':
    combineTate3(partStroke1, partStroke2, partStroke3, result);
    break;
  case '4':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 2 |
                 4 |
                 8);
    break;
  case '5':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 2 |
                 4);
    break;
  case '6':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 2 |
                 8);
    break;
  case '7':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 4 |
                 8);
    break;
  case '8':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 4);
    break;
  case '9':
    combineHame2(partStroke1, partStroke3, result,
                 2 |
                 4);
    break;
  case 'a':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 8);
    break;
  }
  switch((in->str)[4]){
  case '0':
  case '1':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
  case 'a':
    addStrokeWithTransform(partStroke1, 1, result, out, 1);
    addStrokeWithTransform(partStroke3, 3, result, out, 1);
    break;
  case '2':
  case '3':
    addStrokeWithTransform(partStroke1, 1, result, out, 1);
    addStrokeWithTransform(partStroke2, 2, result, out, 1);
    addStrokeWithTransform(partStroke3, 3, result, out, 1);
    break;
  }
}

canonical_original_code:
void doCombine(struct _KGString *in, struct _KGString *out){
  struct _KGString *partIDS1; struct _KGString *partIDS2; struct _KGString *partIDS3;
  struct _KGString *partStroke1; struct _KGString *partStroke2; struct _KGString *partStroke3;
  int result[12];
  partIDS1 = kg_string_new("");
  partIDS2 = kg_string_new("");
  partIDS3 = kg_string_new("");
  partStroke1 = kg_string_new("");
  partStroke2 = kg_string_new("");
  partStroke3 = kg_string_new("");
  kg_string_set_size(out, 0);
  if(strncmp(in->str, "u2ff", 4) != 0) return;
  switch((in->str)[4]){
  case '0':
    divideInto2(in, partIDS1, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 1);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 2);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '1':
    divideInto2(in, partIDS1, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 3);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 4);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
  case 'a':
    divideInto2(in, partIDS1, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 5);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 6);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '2':
    divideInto3(in, partIDS1, partIDS2, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 1);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS2, partStroke2, 1);
    if(partStroke2->len == 0) return;
    partStroke2 = CalcSizes(partStroke2, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 2);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  case '3':
    divideInto3(in, partIDS1, partIDS2, partIDS3);
    if(partIDS1->len == 0) return;
    generateGlyphByIDS(partIDS1, partStroke1, 3);
    if(partStroke1->len == 0) return;
    partStroke1 = CalcSizes(partStroke1, 0);
    generateGlyphByIDS(partIDS2, partStroke2, 3);
    if(partStroke2->len == 0) return;
    partStroke2 = CalcSizes(partStroke2, 0);
    generateGlyphByIDS(partIDS3, partStroke3, 4);
    if(partStroke3->len == 0) return;
    partStroke3 = CalcSizes(partStroke3, 0);
    break;
  }
  switch((in->str)[4]){
  case '0':
    combineYoko2(partStroke1, partStroke3, result);
    break;
  case '1':
    combineTate2(partStroke1, partStroke3, result);
    break;
  case '2':
    combineYoko3(partStroke1, partStroke2, partStroke3, result);
    break;
  case '3':
    combineTate3(partStroke1, partStroke2, partStroke3, result);
    break;
  case '4':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 2 |
                 4 |
                 8);
    break;
  case '5':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 2 |
                 4);
    break;
  case '6':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 2 |
                 8);
    break;
  case '7':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 4 |
                 8);
    break;
  case '8':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 4);
    break;
  case '9':
    combineHame2(partStroke1, partStroke3, result,
                 2 |
                 4);
    break;
  case 'a':
    combineHame2(partStroke1, partStroke3, result,
                 1 |
                 8);
    break;
  }
  switch((in->str)[4]){
  case '0':
  case '1':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
  case 'a':
    addStrokeWithTransform(partStroke1, 1, result, out, 1);
    addStrokeWithTransform(partStroke3, 3, result, out, 1);
    break;
  case '2':
  case '3':
    addStrokeWithTransform(partStroke1, 1, result, out, 1);
    addStrokeWithTransform(partStroke2, 2, result, out, 1);
    addStrokeWithTransform(partStroke3, 3, result, out, 1);
    break;
  }
}

variable_types: struct _KGString { char *str; int len; } *

variable_types:
out
struct _KGString *

variable_types:
result
int [12]


generateGlyph

decompiled_code:
char __fastcall generateGlyph(__int64 a1, __int64 a2)
{
const void **v3; // r12
_QWORD *v4; // rax
int v5; // eax

do
{
v3 = (const void **)a1;
a1 = kg_string_new(&unk_10C4);
kg_string_set_size(a2, 0LL);
searchPartsData(v3, a1);
if ( *(_DWORD *)(a1 + 8) )
{
v4 = (_QWORD *)CalcSizes(a1, 1LL);
LOBYTE(v5) = kg_string_assign(a2, *v4);
return v5;
}
searchAliasData(v3, a1);
}
while ( *(_DWORD *)(a1 + 8) );
v5 = isIDS(v3);
if ( v5 )
LOBYTE(v5) = doCombine(v3, a2);
return v5;
}

canonical_decompiled_code:
char __fastcall func1(__int64 a1, __int64 a2)
{
const void **v3; // r12
_QWORD *v4; // rax
int v5; // eax

do
{
v3 = (const void **)a1;
a1 = kg_string_new(&unk_10C4);
kg_string_set_size(a2, 0LL);
searchPartsData(v3, a1);
if ( *(_DWORD *)(a1 + 8) )
{
v4 = (_QWORD *)CalcSizes(a1, 1LL);
LOBYTE(v5) = kg_string_assign(a2, *v4);
return v5;
}
searchAliasData(v3, a1);
}
while ( *(_DWORD *)(a1 + 8) );
v5 = isIDS(v3);
if ( v5 )
LOBYTE(v5) = func0(v3, a2);
return v5;
}

original_code:
void generateGlyph(const KGString *in, KGString *out){
  KGString *tmp;
  tmp = kg_string_new("");
  kg_string_set_size(out, 0);
  searchPartsData(in, tmp);
  if(tmp->len != 0){
    tmp = CalcSizes(tmp, 1);
    out = kg_string_assign(out, tmp->str);
    return;
  }
  searchAliasData(in, tmp);
  if(tmp->len != 0){
    generateGlyph(tmp, out);
    if(out->len == 0) return;
    return;
  }
  if(isIDS(in)){
    doCombine(in, out);
    if(out->len == 0) return;
    return;
  }
}

canonical_original_code:
void generateGlyph(struct _KGString *in, struct _KGString *out){
  struct _KGString *tmp;
  tmp = kg_string_new("");
  kg_string_set_size(out, 0);
  searchPartsData(in, tmp);
  if(tmp->len != 0){
    tmp = CalcSizes(tmp, 1);
    out = kg_string_assign(out, tmp->str);
    return;
  }
  searchAliasData(in, tmp);
  if(tmp->len != 0){
    generateGlyph(tmp, out);
    if(out->len == 0) return;
    return;
  }
  if(isIDS(in)){
    doCombine(in, out);
    if(out->len == 0) return;
    return;
  }
}


generateGlyphByIDS

decompiled_code:
char __fastcall generateGlyphByIDS(_BYTE **a1, __int64 a2, int a3)
{
_QWORD *v3; // rbp
_BYTE *v4; // rdi
__int64 v6; // r13
int v7; // eax

v3 = a1;
v4 = *a1;
if ( *v4 != 117 )
goto LABEL_12;
v6 = kg_string_new(v4);
v3 = (_QWORD *)kg_string_new(*v3);
if ( (unsigned int)(a3 - 1) > 6 )
goto LABEL_11;
if ( *(_DWORD *)(v6 + 8) == 7 )
{
if ( a3 != 1 )
goto LABEL_5;
LABEL_14:
kg_string_append(v6, "01");
goto LABEL_11;
}
kg_string_append(v6, "-");
if ( a3 == 1 )
goto LABEL_14;
LABEL_5:
switch ( a3 )
{
case 2:
kg_string_append(v6, "02");
break;
case 3:
kg_string_append(v6, "03");
break;
case 4:
kg_string_append(v6, "04");
break;
case 5:
kg_string_append(v6, "05");
break;
case 6:
kg_string_append(v6, "06");
break;
}
LABEL_11:
generateGlyph(v6, a2);
v7 = *(_DWORD *)(a2 + 8);
if ( !v7 )
LABEL_12:
LOBYTE(v7) = generateGlyph((__int64)v3, a2);
return v7;
}

canonical_decompiled_code:
char __fastcall func2(_BYTE **a1, __int64 a2, int a3)
{
_QWORD *v3; // rbp
_BYTE *v4; // rdi
__int64 v6; // r13
int v7; // eax

v3 = a1;
v4 = *a1;
if ( *v4 != 117 )
goto LABEL_12;
v6 = kg_string_new(v4);
v3 = (_QWORD *)kg_string_new(*v3);
if ( (unsigned int)(a3 - 1) > 6 )
goto LABEL_11;
if ( *(_DWORD *)(v6 + 8) == 7 )
{
if ( a3 != 1 )
goto LABEL_5;
LABEL_14:
kg_string_append(v6, "01");
goto LABEL_11;
}
kg_string_append(v6, "-");
if ( a3 == 1 )
goto LABEL_14;
LABEL_5:
switch ( a3 )
{
case 2:
kg_string_append(v6, "02");
break;
case 3:
kg_string_append(v6, "03");
break;
case 4:
kg_string_append(v6, "04");
break;
case 5:
kg_string_append(v6, "05");
break;
case 6:
kg_string_append(v6, "06");
break;
}
LABEL_11:
func1(v6, a2);
v7 = *(_DWORD *)(a2 + 8);
if ( !v7 )
LABEL_12:
LOBYTE(v7) = func1((__int64)v3, a2);
return v7;
}

original_code:
void generateGlyphByIDS(const KGString *in, KGString *out, int flag){
  KGString *tmp1, *tmp2;
  if((in->str)[0] != 'u'){
    generateGlyph(in, out);
    return;
  }
  if(in->len < 5 && 7 < in->len){
    generateGlyph(in, out);
    return;
  }
  tmp1 = kg_string_new(in->str);
  tmp2 = kg_string_new(in->str);
  if(1 <= flag && flag <= 7){
    if(tmp1->len != 7) kg_string_append(tmp1, "-");
    if(flag == 1) kg_string_append(tmp1, "01");
    else if(flag == 2) kg_string_append(tmp1, "02");
    else if(flag == 3) kg_string_append(tmp1, "03");
    else if(flag == 4) kg_string_append(tmp1, "04");
    else if(flag == 5) kg_string_append(tmp1, "05");
    else if(flag == 6) kg_string_append(tmp1, "06");
  }
  generateGlyph(tmp1, out);
  if(out->len != 0) return;
  generateGlyph(tmp2, out);
  if(out->len != 0) return;
  return;
}

canonical_original_code:
void generateGlyphByIDS(struct _KGString *in, struct _KGString *out, int flag){
  struct _KGString *tmp1; struct _KGString *tmp2;
  if((in->str)[0] != 'u'){
    generateGlyph(in, out);
    return;
  }
  if(in->len < 5 && 7 < in->len){
    generateGlyph(in, out);
    return;
  }
  tmp1 = kg_string_new(in->str);
  tmp2 = kg_string_new(in->str);
  if(1 <= flag && flag <= 7){
    if(tmp1->len != 7) kg_string_append(tmp1, "-");
    if(flag == 1) kg_string_append(tmp1, "01");
    else if(flag == 2) kg_string_append(tmp1, "02");
    else if(flag == 3) kg_string_append(tmp1, "03");
    else if(flag == 4) kg_string_append(tmp1, "04");
    else if(flag == 5) kg_string_append(tmp1, "05");
    else if(flag == 6) kg_string_append(tmp1, "06");
  }
  generateGlyph(tmp1, out);
  if(out->len != 0) return;
  generateGlyph(tmp2, out);
  if(out->len != 0) return;
  return;
}

variable_types: flag int


drawGlyph

decompiled_code:
void __fastcall drawGlyph(_QWORD *a1, int a2)
{
char *v2; // rbp
int v3; // er12
int v4; // ebx
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = (char *)convertStroke(*a1, 0LL, v8);
if ( v8[0] > 0 )
{
v3 = 0;
v4 = 0;
do
{
while ( !a2 )
{
v5 = v3;
++v4;
v3 += 11;
v6 = 4 * (v5 + 10);
dfDrawFont(
*(unsigned int *)&v2[v6 - 40],
*(unsigned int *)&v2[v6 - 36],
*(unsigned int *)&v2[v6 - 32],
*(unsigned int *)&v2[v6 - 28],
*(unsigned int *)&v2[v6 - 24],
*(unsigned int *)&v2[v6 - 20],
*(unsigned int *)&v2[v6 - 16],
*(unsigned int *)&v2[v6 - 12],
*(unsigned int *)&v2[v6 - 8],
*(unsigned int *)&v2[v6 - 4],
*(unsigned int *)&v2[v6]);
if ( v8[0] <= v4 )
goto LABEL_8;
}
if ( a2 == 1 )
{
v7 = 4 * (v3 + 10LL);
dfDrawFont(
*(unsigned int *)&v2[v7 - 40],
0LL,
0LL,
*(unsigned int *)&v2[v7 - 28],
*(unsigned int *)&v2[v7 - 24],
*(unsigned int *)&v2[v7 - 20],
*(unsigned int *)&v2[v7 - 16],
*(unsigned int *)&v2[v7 - 12],
*(unsigned int *)&v2[v7 - 8],
*(unsigned int *)&v2[v7 - 4],
*(unsigned int *)&v2[v7]);
}
++v4;
v3 += 11;
}
while ( v8[0] > v4 );
}
LABEL_8:
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, int a2)
{
char *v2; // rbp
int v3; // er12
int v4; // ebx
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = (char *)convertStroke(*a1, 0LL, v8);
if ( v8[0] > 0 )
{
v3 = 0;
v4 = 0;
do
{
while ( !a2 )
{
v5 = v3;
++v4;
v3 += 11;
v6 = 4 * (v5 + 10);
dfDrawFont(
*(unsigned int *)&v2[v6 - 40],
*(unsigned int *)&v2[v6 - 36],
*(unsigned int *)&v2[v6 - 32],
*(unsigned int *)&v2[v6 - 28],
*(unsigned int *)&v2[v6 - 24],
*(unsigned int *)&v2[v6 - 20],
*(unsigned int *)&v2[v6 - 16],
*(unsigned int *)&v2[v6 - 12],
*(unsigned int *)&v2[v6 - 8],
*(unsigned int *)&v2[v6 - 4],
*(unsigned int *)&v2[v6]);
if ( v8[0] <= v4 )
goto LABEL_8;
}
if ( a2 == 1 )
{
v7 = 4 * (v3 + 10LL);
dfDrawFont(
*(unsigned int *)&v2[v7 - 40],
0LL,
0LL,
*(unsigned int *)&v2[v7 - 28],
*(unsigned int *)&v2[v7 - 24],
*(unsigned int *)&v2[v7 - 20],
*(unsigned int *)&v2[v7 - 16],
*(unsigned int *)&v2[v7 - 12],
*(unsigned int *)&v2[v7 - 8],
*(unsigned int *)&v2[v7 - 4],
*(unsigned int *)&v2[v7]);
}
++v4;
v3 += 11;
}
while ( v8[0] > v4 );
}
LABEL_8:
free(v2);
}

variable_types: mode int

variable_types: i int

variable_types: j int

variable_types:
buf
int *


finalAdjustment

original_code:
KGString* finalAdjustment(const KGString *in){
  int i, j, k, l, m, n;
  int *buf;
  KGString *temp;
  n = kShotai;
  kShotai = 1;
  temp = kg_string_new("");
  DrawBox();
  drawGlyph(in, 1);
  buf = convertStroke(in->str, buf, &j);
  for(i = 0; i < j; i++){
    m = 0;
    if(buf[i * 11 + 2] == 13){
      for(k = buf[i * 11 + 5] - 6; k < buf[i * 11 + 5] + 6; k++){
        for(l = buf[i * 11 + 6] + 5 * 3 * 0.5; l < buf[i * 11 + 6] + 5 * 3 + 200 * 0.1; l++){
          if(0 <= l && l < 400 && 0 <= k && k < 400 && kageCanvas[l][k] != 0xFF) m++;
        }
      }
      if(m != 0) buf[i * 11 + 2] = 23;
    }
  }
  convertArray(buf, temp, j, 0);
  free(buf);
  kShotai = n;
  return kg_string_new(temp->str);
}

canonical_original_code:
struct _KGString *finalAdjustment(struct _KGString *in){
  int i; int j; int k; int l; int m; int n;
  int *buf;
  struct _KGString *temp;
  n = kShotai;
  kShotai = 1;
  temp = kg_string_new("");
  DrawBox();
  drawGlyph(in, 1);
  buf = convertStroke(in->str, buf, &j);
  for(i = 0; i < j; i++){
    m = 0;
    if(buf[i * 11 + 2] == 13){
      for(k = buf[i * 11 + 5] - 6; k < buf[i * 11 + 5] + 6; k++){
        for(l = buf[i * 11 + 6] + 5 * 3 * 0.5; l < buf[i * 11 + 6] + 5 * 3 + 200 * 0.1; l++){
          if(0 <= l && l < 400 && 0 <= k && k < 400 && kageCanvas[l][k] != 0xFF) m++;
        }
      }
      if(m != 0) buf[i * 11 + 2] = 23;
    }
  }
  convertArray(buf, temp, j, 0);
  free(buf);
  kShotai = n;
  return kg_string_new(temp->str);
}

variable_types:
in
struct _KGString *

variable_types: k int

variable_types: l int

variable_types: m int

variable_types: n int


icPolygon

decompiled_code:
__int64 __fastcall icPolygon(double *a1, __int64 a2)
{
double *v2; // r12
__int64 result; // rax
double *v4; // rbx
double v5; // xmm0_8
int v6; // ebx
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v2 = a1;
result = (unsigned int)kMode;
switch ( kMode )
{
case 0:
return fillPolygon(a1, a2, 0LL, kageCanvas);
case 1:
strcpy(s, "<path d=\"M ");
kg_string_append(kResultText, s);
if ( (int)a2 > 0 )
{
v6 = 0;
while ( 1 )
{
++v6;
sprintf(s, "%.0f,%.0f ", *v2 * 5.0, 5.0 * v2[1]);
kg_string_append(kResultText, s);
if ( (_DWORD)a2 == v6 )
break;
if ( v6 == 1 )
{
strcpy(s, "L ");
kg_string_append(kResultText, s);
}
v2 += 2;
}
}
strcpy(s, "Z\"/>");
result = kg_string_append(kResultText, s);
break;
case 2:
sprintf(s, "%.0f %.0f moveto\n", 5.0 * *a1, 1000.0 - a1[1] * 5.0 - 200.0);
kg_string_append(kResultText, s);
if ( (int)a2 > 1 )
{
v4 = a1 + 2;
do
{
v5 = v4[1];
v4 += 2;
sprintf(s, " %.0f %.0f lineto\n", 5.0 * *(v4 - 2), 1000.0 - v5 * 5.0 - 200.0);
kg_string_append(kResultText, s);
}
while ( &a1[2 * (unsigned int)(a2 - 2) + 4] != v4 );
}
sprintf(s, " %.0f %.0f lineto\n", 5.0 * *a1, 1000.0 - a1[1] * 5.0 - 200.0);
kg_string_append(kResultText, s);
result = kg_string_append(kResultText, "closepath\n");
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, __int64 a2)
{
double *v2; // r12
__int64 result; // rax
double *v4; // rbx
double v5; // xmm0_8
int v6; // ebx
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v2 = a1;
result = (unsigned int)kMode;
switch ( kMode )
{
case 0:
return fillPolygon(a1, a2, 0LL, kageCanvas);
case 1:
strcpy(s, "<path d=\"M ");
kg_string_append(kResultText, s);
if ( (int)a2 > 0 )
{
v6 = 0;
while ( 1 )
{
++v6;
sprintf(s, "%.0f,%.0f ", *v2 * 5.0, 5.0 * v2[1]);
kg_string_append(kResultText, s);
if ( (_DWORD)a2 == v6 )
break;
if ( v6 == 1 )
{
strcpy(s, "L ");
kg_string_append(kResultText, s);
}
v2 += 2;
}
}
strcpy(s, "Z\"/>");
result = kg_string_append(kResultText, s);
break;
case 2:
sprintf(s, "%.0f %.0f moveto\n", 5.0 * *a1, 1000.0 - a1[1] * 5.0 - 200.0);
kg_string_append(kResultText, s);
if ( (int)a2 > 1 )
{
v4 = a1 + 2;
do
{
v5 = v4[1];
v4 += 2;
sprintf(s, " %.0f %.0f lineto\n", 5.0 * *(v4 - 2), 1000.0 - v5 * 5.0 - 200.0);
kg_string_append(kResultText, s);
}
while ( &a1[2 * (unsigned int)(a2 - 2) + 4] != v4 );
}
sprintf(s, " %.0f %.0f lineto\n", 5.0 * *a1, 1000.0 - a1[1] * 5.0 - 200.0);
kg_string_append(kResultText, s);
result = kg_string_append(kResultText, "closepath\n");
break;
}
return result;
}

original_code:
void icPolygon(kPoint *poly, int number){
  int i;
  char buf[256];
  if(kMode == 0){
    fillPolygon(poly, number, 0, kageCanvas);
  }
  else if(kMode == 1){
    sprintf(buf, "<path d=\"M ");
    kg_string_append(kResultText, buf);
    for(i = 0; i < number; i++){
      if(i == 1){
 sprintf(buf, "L ");
 kg_string_append(kResultText, buf);
      }
      sprintf(buf, "%.0f,%.0f ", poly[i].X * 5, poly[i].Y * 5);
      kg_string_append(kResultText, buf);
    }
    sprintf(buf, "Z\"/>");
    kg_string_append(kResultText, buf);
  }
  else if(kMode == 2){
    sprintf(buf, "%.0f %.0f moveto\n", poly[0].X * 5, 1000 - (poly[0].Y * 5) - 200);
    kg_string_append(kResultText, buf);
    for(i = 1; i < number; i++){
      sprintf(buf, " %.0f %.0f lineto\n", poly[i].X * 5, 1000 - (poly[i].Y * 5) - 200);
      kg_string_append(kResultText, buf);
    }
    sprintf(buf, " %.0f %.0f lineto\n", poly[0].X * 5, 1000 - (poly[0].Y * 5) - 200);
    kg_string_append(kResultText, buf);
    kg_string_append(kResultText, "closepath\n");
  }
}

canonical_original_code:
void icPolygon(struct _kPoint *poly, int number){
  int i;
  char buf[256];
  if(kMode == 0){
    fillPolygon(poly, number, 0, kageCanvas);
  }
  else if(kMode == 1){
    sprintf(buf, "<path d=\"M ");
    kg_string_append(kResultText, buf);
    for(i = 0; i < number; i++){
      if(i == 1){
 sprintf(buf, "L ");
 kg_string_append(kResultText, buf);
      }
      sprintf(buf, "%.0f,%.0f ", poly[i].X * 5, poly[i].Y * 5);
      kg_string_append(kResultText, buf);
    }
    sprintf(buf, "Z\"/>");
    kg_string_append(kResultText, buf);
  }
  else if(kMode == 2){
    sprintf(buf, "%.0f %.0f moveto\n", poly[0].X * 5, 1000 - (poly[0].Y * 5) - 200);
    kg_string_append(kResultText, buf);
    for(i = 1; i < number; i++){
      sprintf(buf, " %.0f %.0f lineto\n", poly[i].X * 5, 1000 - (poly[i].Y * 5) - 200);
      kg_string_append(kResultText, buf);
    }
    sprintf(buf, " %.0f %.0f lineto\n", poly[0].X * 5, 1000 - (poly[0].Y * 5) - 200);
    kg_string_append(kResultText, buf);
    kg_string_append(kResultText, "closepath\n");
  }
}

variable_types: struct _kPoint { double X; double Y; } *

variable_types: number int

variable_types:
buf
char [256]


initDB

decompiled_code:
__int64 initDB()
{
db_create(&kPartsdbDatabase, 0LL, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, const char *, _QWORD, __int64, __int64, __int64))(kPartsdbDatabase + 1008))(
kPartsdbDatabase,
0LL,
"/var/www/kagedb/partsdb",
0LL,
2LL,
1024LL,
420LL);
db_create(&kIdsdbDatabase, 0LL, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, const char *, _QWORD, __int64, __int64, int))(kIdsdbDatabase + 1008))(
kIdsdbDatabase,
0LL,
"/var/www/kagedb/idsdb",
0LL,
2LL,
1024LL,
420);
db_create(&kAliasdbDatabase, 0LL, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, const char *, _QWORD, __int64, __int64, int))(kAliasdbDatabase + 1008))(
kAliasdbDatabase,
0LL,
"/var/www/kagedb/aliasdb",
0LL,
2LL,
1024LL,
420);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
db_create(&kPartsdbDatabase, 0LL, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, const char *, _QWORD, __int64, __int64, __int64))(kPartsdbDatabase + 1008))(
kPartsdbDatabase,
0LL,
"/var/www/kagedb/partsdb",
0LL,
2LL,
1024LL,
420LL);
db_create(&kIdsdbDatabase, 0LL, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, const char *, _QWORD, __int64, __int64, int))(kIdsdbDatabase + 1008))(
kIdsdbDatabase,
0LL,
"/var/www/kagedb/idsdb",
0LL,
2LL,
1024LL,
420);
db_create(&kAliasdbDatabase, 0LL, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, const char *, _QWORD, __int64, __int64, int))(kAliasdbDatabase + 1008))(
kAliasdbDatabase,
0LL,
"/var/www/kagedb/aliasdb",
0LL,
2LL,
1024LL,
420);
return 0LL;
}

original_code:
int initDB(){
  db_create(&kPartsdbDatabase, ((void *)0), 0);
  kPartsdbDatabase->open(kPartsdbDatabase, ((void *)0), "/var/www/kagedb/partsdb", ((void *)0), DB_HASH, 0x00000400, 0644);
  db_create(&kIdsdbDatabase, ((void *)0), 0);
  kIdsdbDatabase->open(kIdsdbDatabase, ((void *)0), "/var/www/kagedb/idsdb", ((void *)0), DB_HASH, 0x00000400, 0644);
  db_create(&kAliasdbDatabase, ((void *)0), 0);
  kAliasdbDatabase->open(kAliasdbDatabase, ((void *)0), "/var/www/kagedb/aliasdb", ((void *)0), DB_HASH, 0x00000400, 0644);
  return 0;
}

return_type: int


closeDB

decompiled_code:
__int64 closeDB()
{
(*(void (__fastcall **)(__int64, _QWORD))(kPartsdbDatabase + 568))(kPartsdbDatabase, 0LL);
(*(void (__fastcall **)(__int64, _QWORD))(kIdsdbDatabase + 568))(kIdsdbDatabase, 0LL);
(*(void (__fastcall **)(__int64, _QWORD))(kAliasdbDatabase + 568))(kAliasdbDatabase, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
(*(void (__fastcall **)(__int64, _QWORD))(kPartsdbDatabase + 568))(kPartsdbDatabase, 0LL);
(*(void (__fastcall **)(__int64, _QWORD))(kIdsdbDatabase + 568))(kIdsdbDatabase, 0LL);
(*(void (__fastcall **)(__int64, _QWORD))(kAliasdbDatabase + 568))(kAliasdbDatabase, 0LL);
return 0LL;
}

original_code:
int closeDB(){
  kPartsdbDatabase->close(kPartsdbDatabase, 0);
  kIdsdbDatabase->close(kIdsdbDatabase, 0);
  kAliasdbDatabase->close(kAliasdbDatabase, 0);
  return 0;
}


searchPartsData

decompiled_code:
__int64 __fastcall searchPartsData(_QWORD *a1, __int64 a2)
{
__int64 v3; // rbx
__int64 result; // rax
size_t v5; // rbx
const void *v6; // r8
int v7; // edx
char *v8; // r12
__int64 v9; // r13
__int128 v10[2]; // [rsp+0h] [rbp-88h] BYREF
__int64 v11; // [rsp+20h] [rbp-68h]
size_t n[2]; // [rsp+30h] [rbp-58h] BYREF
__int128 v13; // [rsp+40h] [rbp-48h]
__int64 v14; // [rsp+50h] [rbp-38h]

v3 = kg_string_new(*a1);
if ( **(_BYTE **)v3 == 117 )
{
v6 = (const void *)(*(_QWORD *)v3 + *(int *)(v3 + 8) - 4LL);
v7 = *(_DWORD *)(v3 + 8);
if ( !memcmp(v6, "-j00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v7 - 4));
}
else if ( !memcmp(v6, "-g00", 4uLL)
|| !memcmp(v6, "-t00", 4uLL)
|| !memcmp(v6, "-k00", 4uLL)
|| !memcmp(v6, "-v00", 4uLL)
|| !memcmp(v6, "-u00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v7 - 2));
}
}
v11 = 0LL;
v10[0] = 0LL;
v10[1] = 0LL;
*(_OWORD *)n = 0LL;
v13 = 0LL;
v14 = 0LL;
*(_QWORD *)&v10[0] = *(_QWORD *)v3;
DWORD2(v10[0]) = *(_DWORD *)(v3 + 8);
kg_string_set_size(a2, 0LL);
result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int128 *, size_t *, _QWORD))(kPartsdbDatabase + 632))(
kPartsdbDatabase,
0LL,
v10,
n,
0LL);
v5 = LODWORD(n[1]);
if ( LODWORD(n[1]) )
{
v8 = (char *)malloc((unsigned int)(LODWORD(n[1]) + 1));
strncpy(v8, (const char *)n[0], v5);
v8[v5] = 0;
v9 = kg_string_new(v8);
free(v8);
result = convert99(v9, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 v3; // rbx
__int64 result; // rax
size_t v5; // rbx
const void *v6; // r8
int v7; // edx
char *v8; // r12
__int64 v9; // r13
__int128 v10[2]; // [rsp+0h] [rbp-88h] BYREF
__int64 v11; // [rsp+20h] [rbp-68h]
size_t n[2]; // [rsp+30h] [rbp-58h] BYREF
__int128 v13; // [rsp+40h] [rbp-48h]
__int64 v14; // [rsp+50h] [rbp-38h]

v3 = kg_string_new(*a1);
if ( **(_BYTE **)v3 == 117 )
{
v6 = (const void *)(*(_QWORD *)v3 + *(int *)(v3 + 8) - 4LL);
v7 = *(_DWORD *)(v3 + 8);
if ( !memcmp(v6, "-j00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v7 - 4));
}
else if ( !memcmp(v6, "-g00", 4uLL)
|| !memcmp(v6, "-t00", 4uLL)
|| !memcmp(v6, "-k00", 4uLL)
|| !memcmp(v6, "-v00", 4uLL)
|| !memcmp(v6, "-u00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v7 - 2));
}
}
v11 = 0LL;
v10[0] = 0LL;
v10[1] = 0LL;
*(_OWORD *)n = 0LL;
v13 = 0LL;
v14 = 0LL;
*(_QWORD *)&v10[0] = *(_QWORD *)v3;
DWORD2(v10[0]) = *(_DWORD *)(v3 + 8);
kg_string_set_size(a2, 0LL);
result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int128 *, size_t *, _QWORD))(kPartsdbDatabase + 632))(
kPartsdbDatabase,
0LL,
v10,
n,
0LL);
v5 = LODWORD(n[1]);
if ( LODWORD(n[1]) )
{
v8 = (char *)malloc((unsigned int)(LODWORD(n[1]) + 1));
strncpy(v8, (const char *)n[0], v5);
v8[v5] = 0;
v9 = kg_string_new(v8);
free(v8);
result = convert99(v9, a2);
}
return result;
}

original_code:
void searchPartsData(const KGString *in, KGString *out){
  DBT dbkey, dbdata;
  char *buf;
  KGString *temp, *temp2;
  temp = kg_string_new(in->str);
  if((temp->str)[0] == 'u'){
    if(strncmp(temp->str + temp->len - 4, "-j00", 4) == 0) kg_string_set_size(temp, temp->len - 4);
    else if(strncmp(temp->str + temp->len - 4, "-g00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-t00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-k00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-v00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-u00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
  }
  memset(&dbkey,0,sizeof(DBT));
  memset(&dbdata,0,sizeof(DBT));
  dbkey.data = temp->str;
  dbkey.size = temp->len;
  kg_string_set_size(out, 0);
  kPartsdbDatabase->get(kPartsdbDatabase, ((void *)0), &dbkey, &dbdata, 0);
  if(dbdata.size != 0){
    buf = (char *)malloc(dbdata.size + 1);
    strncpy(buf, dbdata.data, dbdata.size);
    buf[dbdata.size] = '\0';
    temp2 = kg_string_new(buf);
    free(buf);
    convert99(temp2, out);
    return;
  }
}

canonical_original_code:
void searchPartsData(struct _KGString *in, struct _KGString *out){
  struct __db_dbt dbkey; struct __db_dbt dbdata;
  char *buf;
  struct _KGString *temp; struct _KGString *temp2;
  temp = kg_string_new(in->str);
  if((temp->str)[0] == 'u'){
    if(strncmp(temp->str + temp->len - 4, "-j00", 4) == 0) kg_string_set_size(temp, temp->len - 4);
    else if(strncmp(temp->str + temp->len - 4, "-g00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-t00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-k00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-v00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-u00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
  }
  memset(&dbkey,0,sizeof(DBT));
  memset(&dbdata,0,sizeof(DBT));
  dbkey.data = temp->str;
  dbkey.size = temp->len;
  kg_string_set_size(out, 0);
  kPartsdbDatabase->get(kPartsdbDatabase, ((void *)0), &dbkey, &dbdata, 0);
  if(dbdata.size != 0){
    buf = (char *)malloc(dbdata.size + 1);
    strncpy(buf, dbdata.data, dbdata.size);
    buf[dbdata.size] = '\0';
    temp2 = kg_string_new(buf);
    free(buf);
    convert99(temp2, out);
    return;
  }
}

variable_types: struct __db_dbt { void *data; unsigned int size; unsigned int ulen; unsigned int dlen; unsigned int doff; void *app_data; unsigned int flags; }

variable_types:
buf
char *


searchAliasData

decompiled_code:
void __fastcall searchAliasData(_QWORD *a1, __int64 a2)
{
__int64 v3; // rbx
size_t v4; // r12
size_t v5; // rbx
char *v6; // r12
char *v7; // r13
const void *v8; // r8
int v9; // edx
__int128 v10; // [rsp+0h] [rbp-88h] BYREF
__int128 v11; // [rsp+10h] [rbp-78h]
__int64 v12; // [rsp+20h] [rbp-68h]
size_t n[2]; // [rsp+30h] [rbp-58h] BYREF
__int128 v14; // [rsp+40h] [rbp-48h]
__int64 v15; // [rsp+50h] [rbp-38h]

v3 = kg_string_new(*a1);
if ( **(_BYTE **)v3 == 117 )
{
v8 = (const void *)(*(_QWORD *)v3 + *(int *)(v3 + 8) - 4LL);
v9 = *(_DWORD *)(v3 + 8);
if ( !memcmp(v8, "-j00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v9 - 4));
}
else if ( !memcmp(v8, "-g00", 4uLL)
|| !memcmp(v8, "-t00", 4uLL)
|| !memcmp(v8, "-k00", 4uLL)
|| !memcmp(v8, "-v00", 4uLL)
|| !memcmp(v8, "-u00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v9 - 2));
}
}
v12 = 0LL;
v10 = 0LL;
v11 = 0LL;
*(_OWORD *)n = 0LL;
v14 = 0LL;
v15 = 0LL;
*(_QWORD *)&v10 = *(_QWORD *)v3;
DWORD2(v10) = *(_DWORD *)(v3 + 8);
kg_string_set_size(a2, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, __int128 *, size_t *, _QWORD))(kAliasdbDatabase + 632))(
kAliasdbDatabase,
0LL,
&v10,
n,
0LL);
v4 = LODWORD(n[1]);
if ( LODWORD(n[1]) )
{
v7 = (char *)malloc((unsigned int)(LODWORD(n[1]) + 1));
strncpy(v7, (const char *)n[0], v4);
v7[v4] = 0;
kg_string_append(a2, v7, 0.0);
free(v7);
}
else
{
v10 = 0LL;
v11 = 0LL;
*(_OWORD *)n = 0LL;
v14 = 0LL;
v12 = 0LL;
v15 = 0LL;
*(_QWORD *)&v10 = *(_QWORD *)v3;
DWORD2(v10) = *(_DWORD *)(v3 + 8);
kg_string_set_size(a2, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, __int128 *, size_t *, _QWORD, double))(kIdsdbDatabase + 632))(
kIdsdbDatabase,
0LL,
&v10,
n,
0LL,
0.0);
v5 = LODWORD(n[1]);
if ( LODWORD(n[1]) )
{
v6 = (char *)malloc((unsigned int)(LODWORD(n[1]) + 1));
strncpy(v6, (const char *)n[0], v5);
v6[v5] = 0;
kg_string_append(a2, v6, 0.0);
free(v6);
}
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, __int64 a2)
{
__int64 v3; // rbx
size_t v4; // r12
size_t v5; // rbx
char *v6; // r12
char *v7; // r13
const void *v8; // r8
int v9; // edx
__int128 v10; // [rsp+0h] [rbp-88h] BYREF
__int128 v11; // [rsp+10h] [rbp-78h]
__int64 v12; // [rsp+20h] [rbp-68h]
size_t n[2]; // [rsp+30h] [rbp-58h] BYREF
__int128 v14; // [rsp+40h] [rbp-48h]
__int64 v15; // [rsp+50h] [rbp-38h]

v3 = kg_string_new(*a1);
if ( **(_BYTE **)v3 == 117 )
{
v8 = (const void *)(*(_QWORD *)v3 + *(int *)(v3 + 8) - 4LL);
v9 = *(_DWORD *)(v3 + 8);
if ( !memcmp(v8, "-j00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v9 - 4));
}
else if ( !memcmp(v8, "-g00", 4uLL)
|| !memcmp(v8, "-t00", 4uLL)
|| !memcmp(v8, "-k00", 4uLL)
|| !memcmp(v8, "-v00", 4uLL)
|| !memcmp(v8, "-u00", 4uLL) )
{
kg_string_set_size(v3, (unsigned int)(v9 - 2));
}
}
v12 = 0LL;
v10 = 0LL;
v11 = 0LL;
*(_OWORD *)n = 0LL;
v14 = 0LL;
v15 = 0LL;
*(_QWORD *)&v10 = *(_QWORD *)v3;
DWORD2(v10) = *(_DWORD *)(v3 + 8);
kg_string_set_size(a2, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, __int128 *, size_t *, _QWORD))(kAliasdbDatabase + 632))(
kAliasdbDatabase,
0LL,
&v10,
n,
0LL);
v4 = LODWORD(n[1]);
if ( LODWORD(n[1]) )
{
v7 = (char *)malloc((unsigned int)(LODWORD(n[1]) + 1));
strncpy(v7, (const char *)n[0], v4);
v7[v4] = 0;
kg_string_append(a2, v7, 0.0);
free(v7);
}
else
{
v10 = 0LL;
v11 = 0LL;
*(_OWORD *)n = 0LL;
v14 = 0LL;
v12 = 0LL;
v15 = 0LL;
*(_QWORD *)&v10 = *(_QWORD *)v3;
DWORD2(v10) = *(_DWORD *)(v3 + 8);
kg_string_set_size(a2, 0LL);
(*(void (__fastcall **)(__int64, _QWORD, __int128 *, size_t *, _QWORD, double))(kIdsdbDatabase + 632))(
kIdsdbDatabase,
0LL,
&v10,
n,
0LL,
0.0);
v5 = LODWORD(n[1]);
if ( LODWORD(n[1]) )
{
v6 = (char *)malloc((unsigned int)(LODWORD(n[1]) + 1));
strncpy(v6, (const char *)n[0], v5);
v6[v5] = 0;
kg_string_append(a2, v6, 0.0);
free(v6);
}
}
}

original_code:
void searchAliasData(const KGString *in, KGString *out){
  DBT dbkey, dbdata;
  char *buf;
  KGString *temp;
  temp = kg_string_new(in->str);
  if((temp->str)[0] == 'u'){
    if(strncmp(temp->str + temp->len - 4, "-j00", 4) == 0) kg_string_set_size(temp, temp->len - 4);
    else if(strncmp(temp->str + temp->len - 4, "-g00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-t00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-k00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-v00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-u00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
  }
  memset(&dbkey,0,sizeof(DBT));
  memset(&dbdata,0,sizeof(DBT));
  dbkey.data = temp->str;
  dbkey.size = temp->len;
  kg_string_set_size(out, 0);
  kAliasdbDatabase->get(kAliasdbDatabase, ((void *)0), &dbkey, &dbdata, 0);
  if(dbdata.size != 0){
    buf = (char *)malloc(dbdata.size + 1);
    strncpy(buf, dbdata.data, dbdata.size);
    buf[dbdata.size] = '\0';
    kg_string_append(out, buf);
    free(buf);
    return;
  }
  memset(&dbkey,0,sizeof(DBT));
  memset(&dbdata,0,sizeof(DBT));
  dbkey.data = temp->str;
  dbkey.size = temp->len;
  kg_string_set_size(out, 0);
  kIdsdbDatabase->get(kIdsdbDatabase, ((void *)0), &dbkey, &dbdata, 0);
  if(dbdata.size != 0){
    buf = (char *)malloc(dbdata.size + 1);
    strncpy(buf, dbdata.data, dbdata.size);
    buf[dbdata.size] = '\0';
    kg_string_append(out, buf);
    free(buf);
  }
}

canonical_original_code:
void searchAliasData(struct _KGString *in, struct _KGString *out){
  struct __db_dbt dbkey; struct __db_dbt dbdata;
  char *buf;
  struct _KGString *temp;
  temp = kg_string_new(in->str);
  if((temp->str)[0] == 'u'){
    if(strncmp(temp->str + temp->len - 4, "-j00", 4) == 0) kg_string_set_size(temp, temp->len - 4);
    else if(strncmp(temp->str + temp->len - 4, "-g00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-t00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-k00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-v00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
    else if(strncmp(temp->str + temp->len - 4, "-u00", 4) == 0) kg_string_set_size(temp, temp->len - 2);
  }
  memset(&dbkey,0,sizeof(DBT));
  memset(&dbdata,0,sizeof(DBT));
  dbkey.data = temp->str;
  dbkey.size = temp->len;
  kg_string_set_size(out, 0);
  kAliasdbDatabase->get(kAliasdbDatabase, ((void *)0), &dbkey, &dbdata, 0);
  if(dbdata.size != 0){
    buf = (char *)malloc(dbdata.size + 1);
    strncpy(buf, dbdata.data, dbdata.size);
    buf[dbdata.size] = '\0';
    kg_string_append(out, buf);
    free(buf);
    return;
  }
  memset(&dbkey,0,sizeof(DBT));
  memset(&dbdata,0,sizeof(DBT));
  dbkey.data = temp->str;
  dbkey.size = temp->len;
  kg_string_set_size(out, 0);
  kIdsdbDatabase->get(kIdsdbDatabase, ((void *)0), &dbkey, &dbdata, 0);
  if(dbdata.size != 0){
    buf = (char *)malloc(dbdata.size + 1);
    strncpy(buf, dbdata.data, dbdata.size);
    buf[dbdata.size] = '\0';
    kg_string_append(out, buf);
    free(buf);
  }
}

variable_types: struct _KGString { char *str; int len; } *

variable_types:
out
struct _KGString *

user_defined_types: struct __db_dbt { void *data; unsigned int size; unsigned int ulen; unsigned int dlen; unsigned int doff; void *app_data; unsigned int flags; }


fillPolygon

original_code:
void fillPolygon(kPoint *p, int number, int col, unsigned char **image){
  int miny, maxy;
  int cross[16], num;
  int i, j, k, l, m;
  kPoint tpoly[(1000 / 20 + 1) * 2 + 2];
  int tnum;
  double a, b;
  tnum = 0;
  tpoly[tnum].X = p[0].X;
  tpoly[tnum].Y = p[0].Y;
  miny = maxy = tpoly[tnum].Y;
  tnum++;
  for(i = 1; i < number; i++){
    if(p[i].X != tpoly[tnum - 1].X || p[i].Y != tpoly[tnum - 1].Y){
      tpoly[tnum].X = p[i].X;
      tpoly[tnum].Y = p[i].Y;
      if(tpoly[tnum].Y < miny) miny = tpoly[tnum].Y;
      if(tpoly[tnum].Y > maxy) maxy = tpoly[tnum].Y;
      tnum++;
    }
  }
  tpoly[tnum].X = tpoly[0].X;
  tpoly[tnum].Y = tpoly[0].Y;
  tpoly[tnum + 1].X = tpoly[1].X;
  tpoly[tnum + 1].Y = tpoly[1].Y;
  for(j = miny; j <= maxy; j++){
    num = 0;
    for(i = 0; i < tnum; i++){
      if(tpoly[i].Y == tpoly[i + 1].Y){
 if(tpoly[i].Y == j){
   cross[num] = tpoly[i + 1].X;
   num++;
 }
      }
      else if(tpoly[i].X == tpoly[i + 1].X){
 if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) ||
  (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){
   cross[num] = tpoly[i].X;
   num++;
   if(tpoly[i + 1].Y == j &&
    ((tpoly[i].Y > tpoly[i + 1].Y &&
    tpoly[i + 1].Y < tpoly[i + 2].Y) ||
    (tpoly[i].Y < tpoly[i + 1].Y &&
    tpoly[i + 1].Y > tpoly[i + 2].Y))){
     cross[num] = tpoly[i + 1].X;
     num++;
   }
 }
      }
      else if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) ||
       (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){
 a = (tpoly[i + 1].Y - tpoly[i].Y)
  / (tpoly[i + 1].X - tpoly[i].X);
 b = tpoly[i].Y - a * tpoly[i].X;
 cross[num] = (j - b) / a;
 num++;
 if(tpoly[i + 1].Y == j &&
  ((tpoly[i].Y > tpoly[i + 1].Y &&
  tpoly[i + 1].Y < tpoly[i + 2].Y) ||
  (tpoly[i].Y < tpoly[i + 1].Y &&
  tpoly[i + 1].Y > tpoly[i + 2].Y))){
   cross[num] = tpoly[i + 1].X;
   num++;
 }
      }
    }
    if(num != 0){
      for(k = 0; k < num - 1; k++){
 for(l = num - 1; l > k; l--){
   if(cross[l] < cross[l - 1]){
     m = cross[l];
     cross[l] = cross[l - 1];
     cross[l - 1] = m;
   }
 }
      }
      for(k = 0 ; k < num; k = k + 2){
 for(l = cross[k]; l <= cross[k + 1]; l++){
   if(0 <= j && j < 400 && 0 <= l && l < 400)
    image[j][l] = col;
 }
      }
    }
  }
}

canonical_original_code:
void fillPolygon(struct _kPoint *p, int number, int col, unsigned char **image){
  int miny; int maxy;
  int cross[16]; int num;
  int i; int j; int k; int l; int m;
  struct _kPoint tpoly[-1];
  int tnum;
  double a; double b;
  tnum = 0;
  tpoly[tnum].X = p[0].X;
  tpoly[tnum].Y = p[0].Y;
  miny = maxy = tpoly[tnum].Y;
  tnum++;
  for(i = 1; i < number; i++){
    if(p[i].X != tpoly[tnum - 1].X || p[i].Y != tpoly[tnum - 1].Y){
      tpoly[tnum].X = p[i].X;
      tpoly[tnum].Y = p[i].Y;
      if(tpoly[tnum].Y < miny) miny = tpoly[tnum].Y;
      if(tpoly[tnum].Y > maxy) maxy = tpoly[tnum].Y;
      tnum++;
    }
  }
  tpoly[tnum].X = tpoly[0].X;
  tpoly[tnum].Y = tpoly[0].Y;
  tpoly[tnum + 1].X = tpoly[1].X;
  tpoly[tnum + 1].Y = tpoly[1].Y;
  for(j = miny; j <= maxy; j++){
    num = 0;
    for(i = 0; i < tnum; i++){
      if(tpoly[i].Y == tpoly[i + 1].Y){
 if(tpoly[i].Y == j){
   cross[num] = tpoly[i + 1].X;
   num++;
 }
      }
      else if(tpoly[i].X == tpoly[i + 1].X){
 if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) ||
  (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){
   cross[num] = tpoly[i].X;
   num++;
   if(tpoly[i + 1].Y == j &&
    ((tpoly[i].Y > tpoly[i + 1].Y &&
    tpoly[i + 1].Y < tpoly[i + 2].Y) ||
    (tpoly[i].Y < tpoly[i + 1].Y &&
    tpoly[i + 1].Y > tpoly[i + 2].Y))){
     cross[num] = tpoly[i + 1].X;
     num++;
   }
 }
      }
      else if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) ||
       (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){
 a = (tpoly[i + 1].Y - tpoly[i].Y)
  / (tpoly[i + 1].X - tpoly[i].X);
 b = tpoly[i].Y - a * tpoly[i].X;
 cross[num] = (j - b) / a;
 num++;
 if(tpoly[i + 1].Y == j &&
  ((tpoly[i].Y > tpoly[i + 1].Y &&
  tpoly[i + 1].Y < tpoly[i + 2].Y) ||
  (tpoly[i].Y < tpoly[i + 1].Y &&
  tpoly[i + 1].Y > tpoly[i + 2].Y))){
   cross[num] = tpoly[i + 1].X;
   num++;
 }
      }
    }
    if(num != 0){
      for(k = 0; k < num - 1; k++){
 for(l = num - 1; l > k; l--){
   if(cross[l] < cross[l - 1]){
     m = cross[l];
     cross[l] = cross[l - 1];
     cross[l - 1] = m;
   }
 }
      }
      for(k = 0 ; k < num; k = k + 2){
 for(l = cross[k]; l <= cross[k + 1]; l++){
   if(0 <= j && j < 400 && 0 <= l && l < 400)
    image[j][l] = col;
 }
      }
    }
  }
}

variable_types: col int

variable_types:
image
unsigned char **

variable_types: miny int

variable_types: maxy int

variable_types:
cross
int [16]

variable_types: num int

variable_types: struct _kPoint { double X; double Y; } [-1]

variable_types: tnum int

variable_types: a double

variable_types: b double


indir

decompiled_code:
_BOOL8 __fastcall indir(__int64 a1, char *a2)
{
return a2 == strstr(*(const char **)(a1 + 8), a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, char *a2)
{
return a2 == strstr(*(const char **)(a1 + 8), a2);
}

original_code:
int indir(struct mntent *mnt, const char *dir) {
 return strstr(mnt->mnt_dir, dir) == dir;
}

canonical_original_code:
int indir(struct mntent *mnt, char *dir) {
 return strstr(mnt->mnt_dir, dir) == dir;
}

variable_types: struct mntent { char *mnt_fsname; char *mnt_dir; char *mnt_type; char *mnt_opts; int mnt_freq; int mnt_passno; } *

variable_types:
dir
char *


mountedby

decompiled_code:
_BOOL8 __fastcall mountedby(__int64 a1, const char *a2)
{
char *v3; // rax
char *v4; // rbp
char *v5; // rax
_BOOL4 v6; // er12
char *stringp; // [rsp+8h] [rbp-20h] BYREF

v3 = strdup(*(const char **)(a1 + 24));
if ( !v3 )
errx(1, "out of memory");
stringp = v3;
v4 = v3;
do
{
v5 = strsep(&stringp, ",");
if ( !v5 )
{
v6 = 0;
goto LABEL_6;
}
}
while ( memcmp(v5, "uname=", 6uLL) );
v6 = strcmp(v5 + 6, a2) == 0;
LABEL_6:
free(v4);
return v6;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, const char *a2)
{
char *v3; // rax
char *v4; // rbp
char *v5; // rax
_BOOL4 v6; // er12
char *stringp; // [rsp+8h] [rbp-20h] BYREF

v3 = strdup(*(const char **)(a1 + 24));
if ( !v3 )
errx(1, "out of memory");
stringp = v3;
v4 = v3;
do
{
v5 = strsep(&stringp, ",");
if ( !v5 )
{
v6 = 0;
goto LABEL_6;
}
}
while ( memcmp(v5, "uname=", 6uLL) );
v6 = strcmp(v5 + 6, a2) == 0;
LABEL_6:
free(v4);
return v6;
}

original_code:
int mountedby(struct mntent *mnt, const char *user) {
 char* ds = strdup(mnt->mnt_opts);
 if (!ds)
  errx(1, "out of memory");
 char* s = ds;
        char* tok;
        int ret = 0;
        while ((tok = strsep(&s, ","))) {
  if (strstr(tok, "uname=") == tok) {
   ret = strcmp(tok + 6, user) == 0;
                        break;
  }
 }
 free(ds);
 return ret;
}

canonical_original_code:
int mountedby(struct mntent *mnt, char *user) {
 char *ds = strdup(mnt->mnt_opts);
 if (!ds)
  errx(1, "out of memory");
 char *s = ds;
        char *tok;
        int ret = 0;
        while ((tok = strsep(&s, ","))) {
  if (strstr(tok, "uname=") == tok) {
   ret = strcmp(tok + 6, user) == 0;
                        break;
  }
 }
 free(ds);
 return ret;
}

variable_types:
user
char *

variable_types:
ds
char *

variable_types:
s
char *

variable_types:
tok
char *

variable_types: ret int

user_defined_types: struct mntent { char *mnt_fsname; char *mnt_dir; char *mnt_type; char *mnt_opts; int mnt_freq; int mnt_passno; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
const char *v5; // rdi
const char *v6; // rsi
const char **v7; // rbx
__int64 i; // rdx
int result; // eax
__int64 v10; // [rsp-8h] [rbp-10h]

SetupSound(argc, argv, envp);
v3 = sexy_load(argv[1]);
if ( v3 )
{
v4 = v3;
v5 = "Game:\t%s\nTitle:\t%s\nArtist:\t%s\nYear:\t%s\nGenre:\t%s\nPSF By:\t%s\nCopyright:\t%s\n";
v6 = *(const char **)(v3 + 32);
printf(
"Game:\t%s\nTitle:\t%s\nArtist:\t%s\nYear:\t%s\nGenre:\t%s\nPSF By:\t%s\nCopyright:\t%s\n",
v6,
*(const char **)(v3 + 16),
*(const char **)(v3 + 24),
*(const char **)(v3 + 40),
*(const char **)(v3 + 48),
*(const char **)(v3 + 56),
*(const char **)(v3 + 72));
v7 = *(const char ***)(v4 + 80);
for ( i = v10; v7; v7 = (const char **)v7[2] )
{
v6 = *v7;
v5 = "%s:\t%s\n";
printf("%s:\t%s\n", *v7, v7[1]);
}
sexy_execute(v5, v6, i);
result = 0;
}
else
{
puts("Error loading PSF");
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 PSFINFO *pi;
 SetupSound();
 if(!(pi=sexy_load(argv[1])))
 {
  puts("Error loading PSF");
  return(-1);
 }
 printf("Game:\t%s\nTitle:\t%s\nArtist:\t%s\nYear:\t%s\nGenre:\t%s\nPSF By:\t%s\nCopyright:\t%s\n",
  pi->game,pi->title,pi->artist,pi->year,pi->genre,pi->psfby,pi->copyright);
 {
  PSFTAG *recur=pi->tags;
   while(recur)
  {
   printf("%s:\t%s\n",recur->key,recur->value);
   recur=recur->next;
  }
 }
 sexy_execute();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct PSFINFO *pi;
 SetupSound();
 if(!(pi=sexy_load(argv[1])))
 {
  puts("Error loading PSF");
  return(-1);
 }
 printf("Game:\t%s\nTitle:\t%s\nArtist:\t%s\nYear:\t%s\nGenre:\t%s\nPSF By:\t%s\nCopyright:\t%s\n",
  pi->game,pi->title,pi->artist,pi->year,pi->genre,pi->psfby,pi->copyright);
 {
  struct __PSFTAG *recur = pi->tags;
   while(recur)
  {
   printf("%s:\t%s\n",recur->key,recur->value);
   recur=recur->next;
  }
 }
 sexy_execute();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct PSFINFO { unsigned int length; unsigned int stop; unsigned int fade; char *title; struct __PSFTAG { char *key; char *value; struct __PSFTAG *next; } *tags; } *

user_defined_types: struct PSFINFO { unsigned int length; unsigned int stop; unsigned int fade; char *title; struct __PSFTAG *tags; }


decompiled_code:
__int64 __fastcall BFLIP32(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return a1;
}

original_code:
static inline u32 BFLIP32(u32 x)
{
 return x;
}

canonical_original_code:
static inline unsigned int BFLIP32(unsigned int x)
{
 return x;
}

variable_types:
x
unsigned int

return_type: unsigned int


psxRcntUpd

decompiled_code:
__int64 __fastcall psxRcntUpd(unsigned int a1)
{
__int64 result; // rax
char *v2; // rdx
int v3; // edx
bool v4; // zf
_DWORD *v5; // rdx
unsigned int v6; // eax

result = a1;
v2 = (char *)&psxCounters[7 * a1];
*((_DWORD *)v2 + 3) = psxRegs[68];
v3 = *((_DWORD *)v2 + 1);
if ( (v3 & 1) != 0 && a1 == 2 || (v3 & 0x30) == 0 )
{
psxCounters[7 * a1 + 4] = -1;
}
else
{
v4 = (v3 & 0x10) == 0;
v5 = &psxCounters[7 * a1];
if ( v4 )
v6 = v5[5] * (0xFFFF - *v5);
else
v6 = v5[5] * (v5[2] - *v5);
result = v6 >> 1;
v5[4] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax
char *v2; // rdx
int v3; // edx
bool v4; // zf
_DWORD *v5; // rdx
unsigned int v6; // eax

result = a1;
v2 = (char *)&psxCounters[7 * a1];
*((_DWORD *)v2 + 3) = psxRegs[68];
v3 = *((_DWORD *)v2 + 1);
if ( (v3 & 1) != 0 && a1 == 2 || (v3 & 0x30) == 0 )
{
psxCounters[7 * a1 + 4] = -1;
}
else
{
v4 = (v3 & 0x10) == 0;
v5 = &psxCounters[7 * a1];
if ( v4 )
v6 = v5[5] * (0xFFFF - *v5);
else
v6 = v5[5] * (v5[2] - *v5);
result = v6 >> 1;
v5[4] = result;
}
return result;
}

original_code:
static void psxRcntUpd(u32 index) {
 psxCounters[index].sCycle = psxRegs.cycle;
 if (((!(psxCounters[index].mode & 1)) || (index!=2)) &&
  psxCounters[index].mode & 0x30) {
  if (psxCounters[index].mode & 0x10) {
   psxCounters[index].Cycle = ((psxCounters[index].target - psxCounters[index].count) * psxCounters[index].rate) / 2;
  } else {
   psxCounters[index].Cycle = ((0xffff - psxCounters[index].count) * psxCounters[index].rate) / 2;
  }
 } else psxCounters[index].Cycle = 0xffffffff;
}

canonical_original_code:
static void psxRcntUpd(unsigned int index) {
 psxCounters[index].sCycle = psxRegs.cycle;
 if (((!(psxCounters[index].mode & 1)) || (index!=2)) &&
  psxCounters[index].mode & 0x30) {
  if (psxCounters[index].mode & 0x10) {
   psxCounters[index].Cycle = ((psxCounters[index].target - psxCounters[index].count) * psxCounters[index].rate) / 2;
  } else {
   psxCounters[index].Cycle = ((0xffff - psxCounters[index].count) * psxCounters[index].rate) / 2;
  }
 } else psxCounters[index].Cycle = 0xffffffff;
}

variable_types:
index
unsigned int


psxRcntSet

decompiled_code:
__int64 psxRcntSet()
{
int v0; // ecx
__int64 result; // rax
_DWORD *v2; // rdx
char v3; // r8
int v4; // esi

v0 = psxRegs[68];
psxNextCounter = 0x7FFFFFFF;
psxNextsCounter = v0;
result = (unsigned int)cnts;
if ( cnts > 0 )
{
v2 = psxCounters;
v3 = 0;
v4 = 0x7FFFFFFF;
do
{
result = (unsigned int)v2[4];
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(v2[3] + result - v0);
if ( (int)result < 0 )
{
psxNextCounter = 0;
return result;
}
if ( v4 > (int)result )
{
v4 = result;
v3 = 1;
}
}
v2 += 7;
}
while ( &psxCounters[7 * (cnts - 1) + 7] != v2 );
if ( v3 )
psxNextCounter = v4;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ecx
__int64 result; // rax
_DWORD *v2; // rdx
char v3; // r8
int v4; // esi

v0 = psxRegs[68];
psxNextCounter = 0x7FFFFFFF;
psxNextsCounter = v0;
result = (unsigned int)cnts;
if ( cnts > 0 )
{
v2 = psxCounters;
v3 = 0;
v4 = 0x7FFFFFFF;
do
{
result = (unsigned int)v2[4];
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(v2[3] + result - v0);
if ( (int)result < 0 )
{
psxNextCounter = 0;
return result;
}
if ( v4 > (int)result )
{
v4 = result;
v3 = 1;
}
}
v2 += 7;
}
while ( &psxCounters[7 * (cnts - 1) + 7] != v2 );
if ( v3 )
psxNextCounter = v4;
}
return result;
}

original_code:
static void psxRcntSet() {
 int i;
 psxNextCounter = 0x7fffffff;
 psxNextsCounter = psxRegs.cycle;
 for (i=0; i<cnts; i++) {
  s32 count;
  if (psxCounters[i].Cycle == 0xffffffff) continue;
  count = psxCounters[i].Cycle - (psxRegs.cycle - psxCounters[i].sCycle);
  if (count < 0) {
   psxNextCounter = 0; break;
  }
  if (count < (s32)psxNextCounter) {
   psxNextCounter = count;
  }
 }
}

canonical_original_code:
static void psxRcntSet() {
 int i;
 psxNextCounter = 0x7fffffff;
 psxNextsCounter = psxRegs.cycle;
 for (i=0; i<cnts; i++) {
  int count;
  if (psxCounters[i].Cycle == 0xffffffff) continue;
  count = psxCounters[i].Cycle - (psxRegs.cycle - psxCounters[i].sCycle);
  if (count < 0) {
   psxNextCounter = 0; break;
  }
  if (count < (int)psxNextCounter) {
   psxNextCounter = count;
  }
 }
}

variable_types: i int

variable_types: count int


CounterSPURun

decompiled_code:
__int64 CounterSPURun()
{
unsigned int v0; // ecx
unsigned int v1; // edi
__int64 result; // rax

v0 = psxRegs[68];
v1 = v0 - last;
if ( v0 < last )
v1 = v0 + ~last;
result = 1LL;
if ( v1 > 0xF )
{
result = SPUasync();
if ( (_DWORD)result )
{
last = psxRegs[68];
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ecx
unsigned int v1; // edi
__int64 result; // rax

v0 = psxRegs[68];
v1 = v0 - last;
if ( v0 < last )
v1 = v0 + ~last;
result = 1LL;
if ( v1 > 0xF )
{
result = SPUasync();
if ( (_DWORD)result )
{
last = psxRegs[68];
result = 1LL;
}
}
return result;
}

original_code:
int CounterSPURun(void)
{
 u32 cycles;
 if(psxRegs.cycle<last)
 {
  cycles=0xFFFFFFFF-last;
  cycles+=psxRegs.cycle;
 }
 else
  cycles=psxRegs.cycle-last;
 if(cycles>=16)
 {
  if(!SPUasync(cycles)) return(0);
  last=psxRegs.cycle;
 }
 return(1);
}

canonical_original_code:
int CounterSPURun()
{
 unsigned int cycles;
 if(psxRegs.cycle<last)
 {
  cycles=0xFFFFFFFF-last;
  cycles+=psxRegs.cycle;
 }
 else
  cycles=psxRegs.cycle-last;
 if(cycles>=16)
 {
  if(!SPUasync(cycles)) return(0);
  last=psxRegs.cycle;
 }
 return(1);
}

variable_types:
cycles
unsigned int


CounterDeadLoopSkip

decompiled_code:
__int64 CounterDeadLoopSkip()
{
_DWORD *v0; // rdx
int v1; // ecx
int v2; // edi
__int64 result; // rax

v0 = psxCounters;
v1 = 0x7FFFFFFF;
v2 = psxRegs[68];
do
{
result = (unsigned int)v0[4];
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(v0[3] + result - v2);
if ( v1 > (int)result )
v1 = result;
}
v0 += 7;
}
while ( &psxCounters[28] != v0 );
if ( v1 > 0 )
psxRegs[68] = v2 + v1;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
_DWORD *v0; // rdx
int v1; // ecx
int v2; // edi
__int64 result; // rax

v0 = psxCounters;
v1 = 0x7FFFFFFF;
v2 = psxRegs[68];
do
{
result = (unsigned int)v0[4];
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(v0[3] + result - v2);
if ( v1 > (int)result )
v1 = result;
}
v0 += 7;
}
while ( &psxCounters[28] != v0 );
if ( v1 > 0 )
psxRegs[68] = v2 + v1;
return result;
}

original_code:
void CounterDeadLoopSkip()
{
 s32 min,x,lmin;
 lmin=0x7FFFFFFF;
 for(x=0;x<4;x++)
 {
  if (psxCounters[x].Cycle != 0xffffffff)
  {
    min=psxCounters[x].Cycle;
   min-=(psxRegs.cycle - psxCounters[x].sCycle);
   if(min<lmin) lmin=min;
  }
 }
 if(lmin>0)
 {
  psxRegs.cycle+=lmin;
 }
}

canonical_original_code:
void CounterDeadLoopSkip()
{
 int min; int x; int lmin;
 lmin=0x7FFFFFFF;
 for(x=0;x<4;x++)
 {
  if (psxCounters[x].Cycle != 0xffffffff)
  {
    min=psxCounters[x].Cycle;
   min-=(psxRegs.cycle - psxCounters[x].sCycle);
   if(min<lmin) lmin=min;
  }
 }
 if(lmin>0)
 {
  psxRegs.cycle+=lmin;
 }
}

variable_types: min int

variable_types: x int

variable_types: lmin int


psxUpdateVSyncRate

decompiled_code:
_DWORD *psxUpdateVSyncRate()
{
_DWORD *result; // rax

result = psxCounters;
psxCounters[26] = 564480;
return result;
}

canonical_decompiled_code:
_DWORD *func6()
{
_DWORD *result; // rax

result = psxCounters;
psxCounters[26] = 564480;
return result;
}

original_code:
void psxUpdateVSyncRate() {
 psxCounters[3].rate = (33868800 / 60);
}


psxRcntInit

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

memset(psxCounters, 0, 0x88uLL);
psxCounters[27] = 1;
*(_QWORD *)&psxCounters[5] = 0x1000000001LL;
*(_QWORD *)&psxCounters[12] = 0x2000000001LL;
*(_QWORD *)&psxCounters[19] = 0x4000000001LL;
*(_QWORD *)&psxCounters[22] = 0x100000058LL;
psxCounters[34] = 0;
psxUpdateVSyncRate();
cnts = 4;
psxRcntUpd(0);
psxRcntUpd(1u);
psxRcntUpd(2u);
psxRcntUpd(3u);
result = psxRcntSet();
last = 0;
return result;
}

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

memset(psxCounters, 0, 0x88uLL);
psxCounters[27] = 1;
*(_QWORD *)&psxCounters[5] = 0x1000000001LL;
*(_QWORD *)&psxCounters[12] = 0x2000000001LL;
*(_QWORD *)&psxCounters[19] = 0x4000000001LL;
*(_QWORD *)&psxCounters[22] = 0x100000058LL;
psxCounters[34] = 0;
func6();
cnts = 4;
func1(0);
func1(1u);
func1(2u);
func1(3u);
result = func3();
last = 0;
return result;
}

original_code:
void psxRcntInit() {
 memset(psxCounters, 0, sizeof(psxCounters));
        psxCounters[0].rate = 1; psxCounters[0].interrupt = 0x10;
        psxCounters[1].rate = 1; psxCounters[1].interrupt = 0x20;
 psxCounters[2].rate = 1; psxCounters[2].interrupt = 64;
 psxCounters[3].interrupt = 1;
 psxCounters[3].mode = 0x58;
 psxCounters[3].target = 1;
 psxUpdateVSyncRate();
 cnts = 4;
        psxRcntUpd(0); psxRcntUpd(1); psxRcntUpd(2); psxRcntUpd(3);
        psxRcntSet();
 last=0;
}


psxRcntUpdate

decompiled_code:
__int64 psxRcntUpdate()
{
_DWORD *v0; // r10
int v1; // eax
__int64 v3; // r11
__int64 v4; // r11
__int64 v5; // r11
__int64 v6; // r10

v0 = psxCounters;
v1 = psxRegs[68];
if ( (unsigned int)(v1 - psxCounters[24]) >= psxCounters[25] )
{
psxRcntUpd(3u);
*(_DWORD *)(psxH + 4208LL) |= BFLIP32(1u);
v1 = *(_DWORD *)(v3 + 272);
if ( (unsigned int)(v1 - v0[3]) < v0[4] )
{
LABEL_3:
if ( (unsigned int)(v1 - v0[10]) < v0[11] )
goto LABEL_4;
LABEL_8:
psxRcntReset(1u);
if ( (unsigned int)(*(_DWORD *)(v5 + 272) - *(_DWORD *)(v6 + 68)) < *(_DWORD *)(v6 + 72) )
return psxRcntSet();
goto LABEL_9;
}
}
else if ( (unsigned int)(v1 - psxCounters[3]) < psxCounters[4] )
{
goto LABEL_3;
}
psxRcntReset(0);
v1 = *(_DWORD *)(v4 + 272);
if ( (unsigned int)(v1 - v0[10]) >= v0[11] )
goto LABEL_8;
LABEL_4:
if ( (unsigned int)(v1 - v0[17]) < v0[18] )
return psxRcntSet();
LABEL_9:
psxRcntReset(2u);
return psxRcntSet();
}

canonical_decompiled_code:
__int64 func8()
{
_DWORD *v0; // r10
int v1; // eax
__int64 v3; // r11
__int64 v4; // r11
__int64 v5; // r11
__int64 v6; // r10

v0 = psxCounters;
v1 = psxRegs[68];
if ( (unsigned int)(v1 - psxCounters[24]) >= psxCounters[25] )
{
func1(3u);
*(_DWORD *)(psxH + 4208LL) |= func0(1u);
v1 = *(_DWORD *)(v3 + 272);
if ( (unsigned int)(v1 - v0[3]) < v0[4] )
{
LABEL_3:
if ( (unsigned int)(v1 - v0[10]) < v0[11] )
goto LABEL_4;
LABEL_8:
func2(1u);
if ( (unsigned int)(*(_DWORD *)(v5 + 272) - *(_DWORD *)(v6 + 68)) < *(_DWORD *)(v6 + 72) )
return func3();
goto LABEL_9;
}
}
else if ( (unsigned int)(v1 - psxCounters[3]) < psxCounters[4] )
{
goto LABEL_3;
}
func2(0);
v1 = *(_DWORD *)(v4 + 272);
if ( (unsigned int)(v1 - v0[10]) >= v0[11] )
goto LABEL_8;
LABEL_4:
if ( (unsigned int)(v1 - v0[17]) < v0[18] )
return func3();
LABEL_9:
func2(2u);
return func3();
}

original_code:
void psxRcntUpdate()
{
        if ((psxRegs.cycle - psxCounters[3].sCycle) >= psxCounters[3].Cycle) {
                psxRcntUpd(3);
                (*(u32*)&psxH[(0x1070) & 0xffff])|= BFLIP32(1);
        }
        if ((psxRegs.cycle - psxCounters[0].sCycle) >= psxCounters[0].Cycle) {
                psxRcntReset(0);
        }
        if ((psxRegs.cycle - psxCounters[1].sCycle) >= psxCounters[1].Cycle) {
                psxRcntReset(1);
        }
        if ((psxRegs.cycle - psxCounters[2].sCycle) >= psxCounters[2].Cycle) {
                psxRcntReset(2);
        }
        psxRcntSet();
}

canonical_original_code:
void psxRcntUpdate()
{
        if ((psxRegs.cycle - psxCounters[3].sCycle) >= psxCounters[3].Cycle) {
                psxRcntUpd(3);
                (*(unsigned int *)&psxH[(0x1070) & 0xffff])|= BFLIP32(1);
        }
        if ((psxRegs.cycle - psxCounters[0].sCycle) >= psxCounters[0].Cycle) {
                psxRcntReset(0);
        }
        if ((psxRegs.cycle - psxCounters[1].sCycle) >= psxCounters[1].Cycle) {
                psxRcntReset(1);
        }
        if ((psxRegs.cycle - psxCounters[2].sCycle) >= psxCounters[2].Cycle) {
                psxRcntReset(2);
        }
        psxRcntSet();
}


psxRcntWcount

decompiled_code:
__int64 __fastcall psxRcntWcount(unsigned int a1, int a2)
{
psxCounters[7 * a1] = a2;
psxRcntUpd(a1);
return psxRcntSet();
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
psxCounters[7 * a1] = a2;
func1(a1);
return func3();
}

original_code:
void psxRcntWcount(u32 index, u32 value) {
 psxCounters[index].count = value;
 psxRcntUpd(index);
 psxRcntSet();
}

canonical_original_code:
void psxRcntWcount(unsigned int index, unsigned int value) {
 psxCounters[index].count = value;
 psxRcntUpd(index);
 psxRcntSet();
}

variable_types:
value
unsigned int


psxRcntWmode

decompiled_code:
__int64 __fastcall psxRcntWmode(unsigned int a1, int a2)
{
_DWORD *v2; // rax
__int64 result; // rax
int v4; // eax

v2 = &psxCounters[7 * a1];
v2[1] = a2;
*v2 = 0;
if ( a1 )
{
if ( a1 == 1 )
{
if ( (a2 & 0x300) == 256 )
{
psxCounters[12] = psxCounters[26] / 0x106u;
goto LABEL_4;
}
psxCounters[12] = 1;
psxRcntUpd(1u);
result = psxRcntSet();
}
else
{
if ( a1 != 2 )
goto LABEL_4;
v4 = 1;
if ( (a2 & 0x300) == 512 )
v4 = 8;
psxCounters[19] = v4;
psxRcntUpd(2u);
result = psxRcntSet();
}
}
else
{
if ( (a2 & 0x300) != 256 )
{
psxCounters[5] = 1;
LABEL_4:
psxRcntUpd(a1);
return psxRcntSet();
}
psxCounters[5] = psxCounters[26] / 0x18B0Cu;
psxRcntUpd(0);
result = psxRcntSet();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, int a2)
{
_DWORD *v2; // rax
__int64 result; // rax
int v4; // eax

v2 = &psxCounters[7 * a1];
v2[1] = a2;
*v2 = 0;
if ( a1 )
{
if ( a1 == 1 )
{
if ( (a2 & 0x300) == 256 )
{
psxCounters[12] = psxCounters[26] / 0x106u;
goto LABEL_4;
}
psxCounters[12] = 1;
func1(1u);
result = func3();
}
else
{
if ( a1 != 2 )
goto LABEL_4;
v4 = 1;
if ( (a2 & 0x300) == 512 )
v4 = 8;
psxCounters[19] = v4;
func1(2u);
result = func3();
}
}
else
{
if ( (a2 & 0x300) != 256 )
{
psxCounters[5] = 1;
LABEL_4:
func1(a1);
return func3();
}
psxCounters[5] = psxCounters[26] / 0x18B0Cu;
func1(0);
result = func3();
}
return result;
}

original_code:
void psxRcntWmode(u32 index, u32 value) {
 psxCounters[index].mode = value;
 psxCounters[index].count = 0;
        if(index == 0) {
                switch (value & 0x300) {
                        case 0x100:
                                psxCounters[index].rate = ((psxCounters[3].rate ) / 386) / 262;
                                break;
                        default:
                                psxCounters[index].rate = 1;
                }
        }
        else if(index == 1) {
                switch (value & 0x300) {
                        case 0x100:
                                psxCounters[index].rate = (psxCounters[3].rate ) / 262;
                                break;
                        default:
                                psxCounters[index].rate = 1;
                }
        }
 else if(index == 2) {
  switch (value & 0x300) {
   case 0x200:
    psxCounters[index].rate = 8;
    break;
   default:
    psxCounters[index].rate = 1;
  }
 }
 psxRcntUpd(index);
 psxRcntSet();
}

canonical_original_code:
void psxRcntWmode(unsigned int index, unsigned int value) {
 psxCounters[index].mode = value;
 psxCounters[index].count = 0;
        if(index == 0) {
                switch (value & 0x300) {
                        case 0x100:
                                psxCounters[index].rate = ((psxCounters[3].rate ) / 386) / 262;
                                break;
                        default:
                                psxCounters[index].rate = 1;
                }
        }
        else if(index == 1) {
                switch (value & 0x300) {
                        case 0x100:
                                psxCounters[index].rate = (psxCounters[3].rate ) / 262;
                                break;
                        default:
                                psxCounters[index].rate = 1;
                }
        }
 else if(index == 2) {
  switch (value & 0x300) {
   case 0x200:
    psxCounters[index].rate = 8;
    break;
   default:
    psxCounters[index].rate = 1;
  }
 }
 psxRcntUpd(index);
 psxRcntSet();
}


psxRcntWtarget

decompiled_code:
__int64 __fastcall psxRcntWtarget(unsigned int a1, int a2)
{
psxCounters[7 * a1 + 2] = a2;
psxRcntUpd(a1);
return psxRcntSet();
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, int a2)
{
psxCounters[7 * a1 + 2] = a2;
func1(a1);
return func3();
}

original_code:
void psxRcntWtarget(u32 index, u32 value) {
 psxCounters[index].target = value;
 psxRcntUpd(index);
 psxRcntSet();
}

canonical_original_code:
void psxRcntWtarget(unsigned int index, unsigned int value) {
 psxCounters[index].target = value;
 psxRcntUpd(index);
 psxRcntSet();
}


psxRcntRcount

decompiled_code:
__int64 __fastcall psxRcntRcount(int a1)
{
_DWORD *v1; // rdx
unsigned int v2; // eax

v1 = &psxCounters[7 * a1];
v2 = psxRegs[68];
if ( (v1[1] & 8) != 0 )
v2 -= v1[3];
return (unsigned __int16)(*v1 + 2 * (v2 / v1[5]));
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
_DWORD *v1; // rdx
unsigned int v2; // eax

v1 = &psxCounters[7 * a1];
v2 = psxRegs[68];
if ( (v1[1] & 8) != 0 )
v2 -= v1[3];
return (unsigned __int16)(*v1 + 2 * (v2 / v1[5]));
}

original_code:
u32 psxRcntRcount(u32 index) {
 u32 ret;
  if (psxCounters[index].mode & 0x08) {
    ret = (psxCounters[index].count + 2 * ((psxRegs.cycle - psxCounters[index].sCycle) / psxCounters[index].rate)) & 0xffff;
  } else {
   ret = (psxCounters[index].count + 2 * (psxRegs.cycle / psxCounters[index].rate)) & 0xffff;
  }
 return ret;
}

canonical_original_code:
unsigned int psxRcntRcount(unsigned int index) {
 unsigned int ret;
  if (psxCounters[index].mode & 0x08) {
    ret = (psxCounters[index].count + 2 * ((psxRegs.cycle - psxCounters[index].sCycle) / psxCounters[index].rate)) & 0xffff;
  } else {
   ret = (psxCounters[index].count + 2 * (psxRegs.cycle / psxCounters[index].rate)) & 0xffff;
  }
 return ret;
}

variable_types:
ret
unsigned int


hleBootstrap

decompiled_code:
void hleBootstrap()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static void hleBootstrap() {
}

canonical_original_code:
static void hleBootstrap() {
}


hleExecRet

decompiled_code:
__int64 __fastcall hleExecRet(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rcx
int v3; // eax
__int64 v4; // rcx
unsigned int v5; // edi
int v6; // esi
__int64 v7; // rdx
int v8; // eax
__int64 v9; // rcx
unsigned int v10; // edi
__int64 v11; // rdx
int v12; // eax
__int64 v13; // rcx
unsigned int v14; // edi
__int64 v15; // rdx
int v16; // eax
__int64 v17; // rcx
unsigned int v18; // edi
__int64 v19; // rdx
__int64 result; // rax
_DWORD *v21; // rdx

v1 = psxRegs[16];
v2 = *(_QWORD *)(psxMemLUT + 8LL * HIWORD(v1));
if ( !v2 )
hleExecRet_cold(a1, psxMemLUT);
v3 = BFLIP32(*(_DWORD *)((unsigned __int16)v1 + v2 + 52));
v5 = *(_DWORD *)(v4 + 40);
v6 = v3;
*(_DWORD *)(v7 + 124) = v3;
v8 = BFLIP32(v5);
v10 = *(_DWORD *)(v9 + 44);
*(_DWORD *)(v11 + 116) = v8;
v12 = BFLIP32(v10);
v14 = *(_DWORD *)(v13 + 48);
*(_DWORD *)(v15 + 120) = v12;
v16 = BFLIP32(v14);
v18 = *(_DWORD *)(v17 + 56);
*(_DWORD *)(v19 + 112) = v16;
result = BFLIP32(v18);
v21[2] = 1;
v21[16] = result;
v21[66] = v6;
return result;
}

original_code:
static void hleExecRet() {
 EXEC *header = (EXEC*)(psxMemLUT[(psxRegs.GPR.n.s0) >> 16] == 0 ? ((void *)0) : (void*)(psxMemLUT[(psxRegs.GPR.n.s0) >> 16] + ((psxRegs.GPR.n.s0) & 0xffff)));
 psxRegs.GPR.n.ra = BFLIP32(header->ret);
 psxRegs.GPR.n.sp = BFLIP32(header->_sp);
 psxRegs.GPR.n.s8 = BFLIP32(header->_fp);
 psxRegs.GPR.n.gp = BFLIP32(header->_gp);
 psxRegs.GPR.n.s0 = BFLIP32(header->base);
 psxRegs.GPR.n.v0 = 1;
 psxRegs.pc = psxRegs.GPR.n.ra;
}

canonical_original_code:
static void hleExecRet() {
 struct EXEC *header = (EXEC*)(psxMemLUT[(psxRegs.GPR.n.s0) >> 16] == 0 ? ((void *)0) : (void*)(psxMemLUT[(psxRegs.GPR.n.s0) >> 16] + ((psxRegs.GPR.n.s0) & 0xffff)));
 psxRegs.GPR.n.ra = BFLIP32(header->ret);
 psxRegs.GPR.n.sp = BFLIP32(header->_sp);
 psxRegs.GPR.n.s8 = BFLIP32(header->_fp);
 psxRegs.GPR.n.gp = BFLIP32(header->_gp);
 psxRegs.GPR.n.s0 = BFLIP32(header->base);
 psxRegs.GPR.n.v0 = 1;
 psxRegs.pc = psxRegs.GPR.n.ra;
}

variable_types: struct EXEC { unsigned int _pc0; unsigned int gp0; unsigned int t_addr; unsigned int t_size; unsigned int d_addr; unsigned int d_size; unsigned int b_addr; unsigned int b_size; unsigned int S_addr; unsigned int s_size; unsigned int _sp; } *


decompiled_code:
__int64 hleC0()
{
void (*v0)(void); // rdx

v0 = (void (*)(void))biosC0[LOBYTE(psxRegs[9])];
if ( v0 )
v0();
return psxBranchTest();
}

canonical_decompiled_code:
__int64 func3()
{
void (*v0)(void); // rdx

v0 = (void (*)(void))biosC0[LOBYTE(psxRegs[9])];
if ( v0 )
v0();
return psxBranchTest();
}

original_code:
static void hleC0() {
 u32 call = psxRegs.GPR.n.t1 & 0xff;
 if (biosC0[call]) biosC0[call]();
 psxBranchTest();
}

canonical_original_code:
static void hleC0() {
 unsigned int call = psxRegs.GPR.n.t1 & 0xff;
 if (biosC0[call]) biosC0[call]();
 psxBranchTest();
}

variable_types:
call
unsigned int


decompiled_code:
__int64 hleB0()
{
void (*v0)(void); // rdx

v0 = (void (*)(void))biosB0[LOBYTE(psxRegs[9])];
if ( v0 )
v0();
return psxBranchTest();
}

canonical_decompiled_code:
__int64 func4()
{
void (*v0)(void); // rdx

v0 = (void (*)(void))biosB0[LOBYTE(psxRegs[9])];
if ( v0 )
v0();
return psxBranchTest();
}

original_code:
static void hleB0() {
 u32 call = psxRegs.GPR.n.t1 & 0xff;
 if (biosB0[call]) biosB0[call]();
 psxBranchTest();
}

canonical_original_code:
static void hleB0() {
 unsigned int call = psxRegs.GPR.n.t1 & 0xff;
 if (biosB0[call]) biosB0[call]();
 psxBranchTest();
}


decompiled_code:
__int64 hleA0()
{
void (*v0)(void); // rdx

v0 = (void (*)(void))biosA0[LOBYTE(psxRegs[9])];
if ( v0 )
v0();
return psxBranchTest();
}

canonical_decompiled_code:
__int64 func5()
{
void (*v0)(void); // rdx

v0 = (void (*)(void))biosA0[LOBYTE(psxRegs[9])];
if ( v0 )
v0();
return psxBranchTest();
}

original_code:
static void hleA0() {
 u32 call = psxRegs.GPR.n.t1 & 0xff;
 if (biosA0[call]) biosA0[call]();
 psxBranchTest();
}

canonical_original_code:
static void hleA0() {
 unsigned int call = psxRegs.GPR.n.t1 & 0xff;
 if (biosA0[call]) biosA0[call]();
 psxBranchTest();
}


hleDummy

decompiled_code:
__int64 hleDummy()
{
psxRegs[66] = psxRegs[31];
return psxBranchTest();
}

canonical_decompiled_code:
__int64 func6()
{
psxRegs[66] = psxRegs[31];
return psxBranchTest();
}

original_code:
static void hleDummy() {
 psxRegs.pc = psxRegs.GPR.n.ra;
 psxBranchTest();
}


decompiled_code:
__int64 __fastcall BFLIP32(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return a1;
}

original_code:
static inline u32 BFLIP32(u32 x)
{
 return x;
}


ccomp

decompiled_code:
__int64 __fastcall ccomp(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
static int ccomp(const void *v1, const void *v2)
{
 const LIBNCACHE *a1,*a2;
 a1=v1; a2=v2;
 return(a1->num - a2->num);
}

canonical_original_code:
static int ccomp(void *v1, void *v2)
{
 struct LIBNCACHE *a1; struct LIBNCACHE *a2;
 a1=v1; a2=v2;
 return(a1->num - a2->num);
}

variable_types: struct LIBNCACHE { int num; char *value; } *


FreeTags

decompiled_code:
void __fastcall FreeTags(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

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

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

original_code:
static void FreeTags(PSFTAG *tags)
{
 while(tags)
 {
  PSFTAG *tmp=tags->next;
  free(tags->key);
  free(tags->value);
  free(tags);
  tags=tmp;
 }
}

canonical_original_code:
static void FreeTags(struct __PSFTAG *tags)
{
 while(tags)
 {
  struct __PSFTAG *tmp = tags->next;
  free(tags->key);
  free(tags->value);
  free(tags);
  tags=tmp;
 }
}

variable_types: struct __PSFTAG { char *key; char *value; struct __PSFTAG *next; } *


TimeToMS

variable_types:
str
char *

variable_types: c int

variable_types: acc int

variable_types:
s
char [100]

return_type: long


GetFileWithBase

decompiled_code:
void *__fastcall GetFileWithBase(void *src, char *a2)
{
char *v2; // rbx
size_t v3; // rax
size_t v4; // rbx
char *v5; // rax
void *result; // rax
size_t v7; // r12

v2 = strrchr((const char *)src, 47);
v3 = strlen(a2);
if ( v2 )
{
v4 = v2 - (_BYTE *)src;
ret_1 = (__int64)malloc(v4 + v3 + 2);
v5 = (char *)memcpy((void *)ret_1, src, v4);
v5[v4] = 47;
v5[v4 + 1] = 0;
result = strcat(v5, a2);
}
else
{
v7 = v3 + 1;
ret_1 = (__int64)malloc(v3 + 1);
result = memcpy((void *)ret_1, a2, v7);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(void *src, char *a2)
{
char *v2; // rbx
size_t v3; // rax
size_t v4; // rbx
char *v5; // rax
void *result; // rax
size_t v7; // r12

v2 = strrchr((const char *)src, 47);
v3 = strlen(a2);
if ( v2 )
{
v4 = v2 - (_BYTE *)src;
ret_1 = (__int64)malloc(v4 + v3 + 2);
v5 = (char *)memcpy((void *)ret_1, src, v4);
v5[v4] = 47;
v5[v4 + 1] = 0;
result = strcat(v5, a2);
}
else
{
v7 = v3 + 1;
ret_1 = (__int64)malloc(v3 + 1);
result = memcpy((void *)ret_1, a2, v7);
}
return result;
}

original_code:
char *GetFileWithBase(const char *f, const char *newfile)
{
  static char *ret;
  char *tp1;
     tp1=((char *)strrchr(f,'/'));
     if(!tp1)
     {
      ret=malloc(strlen(newfile)+1);
      strcpy(ret,newfile);
     }
     else
     {
      ret=malloc(tp1-f+2+strlen(newfile));
      memcpy(ret,f,tp1-f);
      ret[tp1-f]='/';
      ret[tp1-f+1]=0;
      strcat(ret,newfile);
     }
    return(ret);
}

canonical_original_code:
char *GetFileWithBase(char *f, char *newfile)
{
  static char *ret;
  char *tp1;
     tp1=((char *)strrchr(f,'/'));
     if(!tp1)
     {
      ret=malloc(strlen(newfile)+1);
      strcpy(ret,newfile);
     }
     else
     {
      ret=malloc(tp1-f+2+strlen(newfile));
      memcpy(ret,f,tp1-f);
      ret[tp1-f]='/';
      ret[tp1-f+1]=0;
      strcat(ret,newfile);
     }
    return(ret);
}

variable_types:
f
char *

variable_types:
newfile
char *

variable_types:
ret
char *


decompiled_code:
void __fastcall sexy_freepsfinfo(void *ptr)
{
FreeTags(*((void **)ptr + 10));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
func2(*((void **)ptr + 10));
free(ptr);
}

original_code:
void sexy_freepsfinfo(PSFINFO *info)
{
 FreeTags(info->tags);
 free(info);
}

canonical_original_code:
void sexy_freepsfinfo(struct PSFINFO *info)
{
 FreeTags(info->tags);
 free(info);
}

variable_types: struct PSFINFO { unsigned int length; unsigned int stop; unsigned int fade; char *title; struct __PSFTAG { char *key; char *value; struct __PSFTAG *next; } *tags; } *