decompiled_code:
__int64 __fastcall ai_assign_value(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax

if ( !a2 )
_assert_fail("value != NULL", "AI_new.c", 0x174u, "ai_assign_value");
if ( !a3 )
_assert_fail("len > 0", "AI_new.c", 0x175u, "ai_assign_value");
result = (unsigned int)(a4 + 1);
if ( (result & 0xFFFFFFFD) != 0 )
_assert_fail("sign == -1 || sign == 1", "AI_new.c", 0x176u, "ai_assign_value");
if ( *(_QWORD *)a1 )
result = AI_free();
*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
*(_DWORD *)(a1 + 16) = a4;
return result;
}

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

if ( !a2 )
_assert_fail("value != NULL", "AI_new.c", 0x174u, "ai_assign_value");
if ( !a3 )
_assert_fail("len > 0", "AI_new.c", 0x175u, "ai_assign_value");
result = (unsigned int)(a4 + 1);
if ( (result & 0xFFFFFFFD) != 0 )
_assert_fail("sign == -1 || sign == 1", "AI_new.c", 0x176u, "ai_assign_value");
if ( *(_QWORD *)a1 )
result = AI_free();
*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
*(_DWORD *)(a1 + 16) = a4;
return result;
}

original_code:
static void
ai_assign_value(ArbInt *ai, aibase_t *value, unsigned long len, int sign)
{
  ((void) sizeof ((value != ((void *)0)) ? 1 : 0), __extension__ ({ if (value != ((void *)0)) ; else __assert_fail ("value != NULL", "AI_new.c", 372, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((len > 0) ? 1 : 0), __extension__ ({ if (len > 0) ; else __assert_fail ("len > 0", "AI_new.c", 373, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sign == -1 || sign == 1) ? 1 : 0), __extension__ ({ if (sign == -1 || sign == 1) ; else __assert_fail ("sign == -1 || sign == 1", "AI_new.c", 374, __extension__ __PRETTY_FUNCTION__); }));
  if (ai->data != ((void *)0)) {
    AI_free(ai->data);
  }
  ai->data = value;
  ai->dataLen = len;
  ai->sign = sign;
}

canonical_original_code:
static void ai_assign_value(struct arbint *ai, unsigned int *value, unsigned long len, int sign)
{
  ((void) sizeof ((value != ((void *)0)) ? 1 : 0), __extension__ ({ if (value != ((void *)0)) ; else __assert_fail ("value != NULL", "AI_new.c", 372, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((len > 0) ? 1 : 0), __extension__ ({ if (len > 0) ; else __assert_fail ("len > 0", "AI_new.c", 373, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sign == -1 || sign == 1) ? 1 : 0), __extension__ ({ if (sign == -1 || sign == 1) ; else __assert_fail ("sign == -1 || sign == 1", "AI_new.c", 374, __extension__ __PRETTY_FUNCTION__); }));
  if (ai->data != ((void *)0)) {
    AI_free(ai->data);
  }
  ai->data = value;
  ai->dataLen = len;
  ai->sign = sign;
}

variable_types:
value
unsigned int *

variable_types: sign int


repo: matthewdalton/arbint

decompiled_code:
__int64 __fastcall AI_NewArbInt_FromValue(int a1, int a2)
{
__int64 v2; // rbx
_DWORD *v3; // rax

v2 = ai_new_empty();
if ( v2 )
{
v3 = (_DWORD *)AI_malloc(4LL);
if ( v3 )
{
*v3 = a1;
ai_assign_value(v2, (__int64)v3, 1LL, a2);
}
else
{
AI_free(v2);
v2 = 0LL;
}
}
return v2;
}

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

v2 = func0();
if ( v2 )
{
v3 = (_DWORD *)AI_malloc(4LL);
if ( v3 )
{
*v3 = a1;
func1(v2, (__int64)v3, 1LL, a2);
}
else
{
AI_free(v2);
v2 = 0LL;
}
}
return v2;
}

original_code:
ArbInt *AI_NewArbInt_FromValue(aibase_t value, int sign)
{
  ArbInt *ai = ai_new_empty();
  if (ai != ((void *)0)) {
    aibase_t *lv = AI_malloc(sizeof(aibase_t));
    if (lv == ((void *)0)) {
      goto error_exit;
    }
    *lv = value;
    ai_assign_value(ai, lv, 1, sign);
  }
  return ai;
 error_exit:
  if (ai != ((void *)0)) {
    AI_free(ai);
  }
  return ((void *)0);
}

canonical_original_code:
struct arbint *AI_NewArbInt_FromValue(unsigned int value, int sign)
{
  struct arbint *ai = ai_new_empty();
  if (ai != ((void *)0)) {
    unsigned int *lv = AI_malloc(sizeof(aibase_t));
    if (lv == ((void *)0)) {
      goto error_exit;
    }
    *lv = value;
    ai_assign_value(ai, lv, 1, sign);
  }
  return ai;
 error_exit:
  if (ai != ((void *)0)) {
    AI_free(ai);
  }
  return ((void *)0);
}

variable_types:
value
unsigned int

variable_types: struct arbint { unsigned int *data; unsigned long dataLen; int sign; } *

variable_types:
lv
unsigned int *


decompiled_code:
__int64 __fastcall AI_NewArbInt_FromLong(int a1)
{
int v1; // esi

v1 = 1;
if ( a1 < 0 )
{
a1 = -a1;
v1 = -1;
}
return AI_NewArbInt_FromValue(a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // esi

v1 = 1;
if ( a1 < 0 )
{
a1 = -a1;
v1 = -1;
}
return func2(a1, v1);
}

original_code:
ArbInt *AI_NewArbInt_FromLong(int32_t value)
{
  int sign = 1;
  if (value < 0) {
    value = -value;
    sign = -1;
  }
  return AI_NewArbInt_FromValue((aibase_t)value, sign);
}

canonical_original_code:
struct arbint *AI_NewArbInt_FromLong(int value)
{
  int sign = 1;
  if (value < 0) {
    value = -value;
    sign = -1;
  }
  return AI_NewArbInt_FromValue((unsigned int)value, sign);
}

variable_types: value int

return_type: struct arbint { unsigned int *data; unsigned long dataLen; int sign; } *


decompiled_code:
__int64 AI_NewArbInt()
{
return AI_NewArbInt_FromLong(0);
}

canonical_decompiled_code:
__int64 func4()
{
return func3(0);
}

original_code:
ArbInt *AI_NewArbInt(void)
{
  return AI_NewArbInt_FromLong(0);
}

canonical_original_code:
struct arbint *AI_NewArbInt()
{
  return AI_NewArbInt_FromLong(0);
}

user_defined_types: struct arbint { unsigned int *data; unsigned long dataLen; int sign; }


decompiled_code:
__int64 __fastcall AI_NewArbInt_From32(int a1)
{
return AI_NewArbInt_FromLong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return func3(a1);
}

original_code:
ArbInt *AI_NewArbInt_From32(int32_t value)
{
  return AI_NewArbInt_FromLong(value);
}

canonical_original_code:
struct arbint *AI_NewArbInt_From32(int value)
{
  return AI_NewArbInt_FromLong(value);
}


decompiled_code:
__int64 __fastcall AI_FreeArbInt(__int64 *a1)
{
__int64 v2; // rdi

v2 = *a1;
if ( v2 )
AI_free(v2);
return AI_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 v2; // rdi

v2 = *a1;
if ( v2 )
AI_free(v2);
return AI_free(a1);
}

original_code:
void AI_FreeArbInt(ArbInt *aival)
{
  if (aival->data != ((void *)0)) {
    AI_free(aival->data);
  }
  if (aival != ((void *)0)) {
    AI_free(aival);
  }
}

canonical_original_code:
void AI_FreeArbInt(struct arbint *aival)
{
  if (aival->data != ((void *)0)) {
    AI_free(aival->data);
  }
  if (aival != ((void *)0)) {
    AI_free(aival);
  }
}

return_type: void


decompiled_code:
__int64 __fastcall AI_NewArbInt_FromCopy(const void **a1)
{
__int64 v1; // rbp
__int64 v2; // r12
const void *v3; // rdx

v1 = ai_new_empty();
if ( v1 )
{
v2 = AI_malloc(4LL * (_QWORD)a1[1]);
if ( v2 )
{
AI_memcpy(v2, *a1, 4LL * (_QWORD)a1[1]);
ai_assign_value(v1, v2, (__int64)a1[1], *((_DWORD *)a1 + 4));
v3 = a1[1];
if ( v3 != *(const void **)(v1 + 8) )
_assert_fail("ai->dataLen == ret->dataLen", "AI_new.c", 0xD7u, "AI_NewArbInt_FromCopy");
if ( memcmp(*a1, *(const void **)v1, 4LL * (_QWORD)v3) )
_assert_fail(
"memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0",
"AI_new.c",
0xD9u,
"AI_NewArbInt_FromCopy");
}
else
{
AI_FreeArbInt((__int64 *)v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(const void **a1)
{
__int64 v1; // rbp
__int64 v2; // r12
const void *v3; // rdx

v1 = func0();
if ( v1 )
{
v2 = AI_malloc(4LL * (_QWORD)a1[1]);
if ( v2 )
{
AI_memcpy(v2, *a1, 4LL * (_QWORD)a1[1]);
func1(v1, v2, (__int64)a1[1], *((_DWORD *)a1 + 4));
v3 = a1[1];
if ( v3 != *(const void **)(v1 + 8) )
_assert_fail("ai->dataLen == ret->dataLen", "AI_new.c", 0xD7u, "AI_NewArbInt_FromCopy");
if ( memcmp(*a1, *(const void **)v1, 4LL * (_QWORD)v3) )
_assert_fail(
"memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0",
"AI_new.c",
0xD9u,
"AI_NewArbInt_FromCopy");
}
else
{
func6((__int64 *)v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
ArbInt *AI_NewArbInt_FromCopy(ArbInt const *ai)
{
  ArbInt *ret = ai_new_empty();
  if (ret == ((void *)0))
    return ((void *)0);
  aibase_t *lv = AI_malloc(ai->dataLen * sizeof(aibase_t));
  if (lv == ((void *)0)) {
    AI_FreeArbInt(ret);
    return ((void *)0);
  }
  AI_memcpy(lv, ai->data, ai->dataLen * sizeof(aibase_t));
  ai_assign_value(ret, lv, ai->dataLen, ai->sign);
  ((void) sizeof ((ai->dataLen == ret->dataLen) ? 1 : 0), __extension__ ({ if (ai->dataLen == ret->dataLen) ; else __assert_fail ("ai->dataLen == ret->dataLen", "AI_new.c", 215, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ai->sign == ai->sign) ? 1 : 0), __extension__ ({ if (ai->sign == ai->sign) ; else __assert_fail ("ai->sign == ai->sign", "AI_new.c", 216, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0) ? 1 : 0), __extension__ ({ if (memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0) ; else __assert_fail ("memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0", "AI_new.c", 217, __extension__ __PRETTY_FUNCTION__); }));
  return ret;
}

canonical_original_code:
struct arbint *AI_NewArbInt_FromCopy(struct arbint *ai)
{
  struct arbint *ret = ai_new_empty();
  if (ret == ((void *)0))
    return ((void *)0);
  unsigned int *lv = AI_malloc(ai->dataLen * sizeof(aibase_t));
  if (lv == ((void *)0)) {
    AI_FreeArbInt(ret);
    return ((void *)0);
  }
  AI_memcpy(lv, ai->data, ai->dataLen * sizeof(aibase_t));
  ai_assign_value(ret, lv, ai->dataLen, ai->sign);
  ((void) sizeof ((ai->dataLen == ret->dataLen) ? 1 : 0), __extension__ ({ if (ai->dataLen == ret->dataLen) ; else __assert_fail ("ai->dataLen == ret->dataLen", "AI_new.c", 215, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ai->sign == ai->sign) ? 1 : 0), __extension__ ({ if (ai->sign == ai->sign) ; else __assert_fail ("ai->sign == ai->sign", "AI_new.c", 216, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0) ? 1 : 0), __extension__ ({ if (memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0) ; else __assert_fail ("memcmp(ai->data, ret->data, ai->dataLen * sizeof(aibase_t)) == 0", "AI_new.c", 217, __extension__ __PRETTY_FUNCTION__); }));
  return ret;
}

variable_types:
ai
struct arbint *


decompiled_code:
__int64 __fastcall ai_pow_by_power2(__int64 a1, int a2)
{
int v2; // ebx
__int64 i; // rdi

v2 = a2;
for ( i = AI_NewArbInt_FromCopy(); v2; --v2 )
i = AI_Mul(i, i);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
int v2; // ebx
__int64 i; // rdi

v2 = a2;
for ( i = AI_NewArbInt_FromCopy(); v2; --v2 )
i = AI_Mul(i, i);
return i;
}

original_code:
ArbInt *ai_pow_by_power2(ArbInt const *A, aibase_t exponent)
{
  ArbInt *ans = AI_NewArbInt_FromCopy(A);
  ArbInt *val;
  while (exponent > 0) {
    val = AI_Mul(ans, ans);
    ans = val;
    exponent--;
  }
  return ans;
}

canonical_original_code:
struct arbint *ai_pow_by_power2(struct arbint *A, unsigned int exponent)
{
  struct arbint *ans = AI_NewArbInt_FromCopy(A);
  struct arbint *val;
  while (exponent > 0) {
    val = AI_Mul(ans, ans);
    ans = val;
    exponent--;
  }
  return ans;
}

variable_types:
A
struct arbint *

variable_types:
exponent
unsigned int


decompiled_code:
__int64 __fastcall ai_pow_positive(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // er13
__int64 v4; // rbp
int v5; // ebx
__int64 v6; // rsi
__int64 v7; // r15

v2 = AI_NewArbInt_From32(1LL);
v3 = arbint_get_hsb_position(a2);
v4 = AI_Make_Bit_Iter(a2);
v5 = 0;
do
{
if ( v5 == v3 )
break;
if ( (unsigned int)AI_Bit_Iter_Get(v4) )
{
v6 = ai_pow_by_power2(a1, v5);
v7 = AI_Mul(v2, v6);
AI_FreeArbInt(v2);
v2 = v7;
}
++v5;
}
while ( (unsigned int)AI_Bit_Iter_Inc(v4) );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // er13
__int64 v4; // rbp
int v5; // ebx
__int64 v6; // rsi
__int64 v7; // r15

v2 = AI_NewArbInt_From32(1LL);
v3 = arbint_get_hsb_position(a2);
v4 = AI_Make_Bit_Iter(a2);
v5 = 0;
do
{
if ( v5 == v3 )
break;
if ( (unsigned int)AI_Bit_Iter_Get(v4) )
{
v6 = func0(a1, v5);
v7 = AI_Mul(v2, v6);
AI_FreeArbInt(v2);
v2 = v7;
}
++v5;
}
while ( (unsigned int)AI_Bit_Iter_Inc(v4) );
return v2;
}

original_code:
ArbInt *ai_pow_positive(ArbInt const *A, ArbInt const *B)
{
  ArbInt *ans = AI_NewArbInt_From32(1);
  ArbInt *val;
  aibase_t hsb = arbint_get_hsb_position(B);
  ArbInt_BitIterator *bi = AI_Make_Bit_Iter(B);
  aibase_t bitNum = 0;
  aibase_t exp = 1;
  while (bitNum < hsb) {
    int isSet = AI_Bit_Iter_Get(bi);
    if (isSet) {
      val = AI_Mul(ans, ai_pow_by_power2(A, bitNum));
      AI_FreeArbInt(ans);
      ans = val;
    }
    bitNum++;
    exp++;
    if (!AI_Bit_Iter_Inc(bi)) {
      break;
    }
  }
  return ans;
}

canonical_original_code:
struct arbint *ai_pow_positive(struct arbint *A, struct arbint *B)
{
  struct arbint *ans = AI_NewArbInt_From32(1);
  struct arbint *val;
  unsigned int hsb = arbint_get_hsb_position(B);
  struct arbint_bititerator *bi = AI_Make_Bit_Iter(B);
  unsigned int bitNum = 0;
  unsigned int exp = 1;
  while (bitNum < hsb) {
    int isSet = AI_Bit_Iter_Get(bi);
    if (isSet) {
      val = AI_Mul(ans, ai_pow_by_power2(A, bitNum));
      AI_FreeArbInt(ans);
      ans = val;
    }
    bitNum++;
    exp++;
    if (!AI_Bit_Iter_Inc(bi)) {
      break;
    }
  }
  return ans;
}

variable_types:
B
struct arbint *

variable_types:
hsb
unsigned int

variable_types: struct arbint_bititerator { unsigned int *begin; unsigned int *end; unsigned int *byte; unsigned int bit; } *

variable_types:
bitNum
unsigned int

variable_types:
exp
unsigned int

variable_types: isSet int


decompiled_code:
__int64 __fastcall AI_Pow(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

v2 = AI_NewArbInt_From32(0LL);
v3 = AI_NewArbInt_From32(1LL);
if ( (unsigned int)AI_Equal(a2, v2) )
{
AI_FreeArbInt(v2);
}
else if ( (unsigned int)AI_Equal(a2, v3) )
{
AI_FreeArbInt(v2);
AI_FreeArbInt(v3);
v3 = AI_NewArbInt_FromCopy(a1);
}
else if ( (unsigned int)AI_Less(a2, v2) )
{
AI_FreeArbInt(v2);
AI_FreeArbInt(v3);
v3 = v2;
}
else
{
AI_FreeArbInt(v2);
AI_FreeArbInt(v3);
v3 = ai_pow_positive(a1, a2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

v2 = AI_NewArbInt_From32(0LL);
v3 = AI_NewArbInt_From32(1LL);
if ( (unsigned int)AI_Equal(a2, v2) )
{
AI_FreeArbInt(v2);
}
else if ( (unsigned int)AI_Equal(a2, v3) )
{
AI_FreeArbInt(v2);
AI_FreeArbInt(v3);
v3 = AI_NewArbInt_FromCopy(a1);
}
else if ( (unsigned int)AI_Less(a2, v2) )
{
AI_FreeArbInt(v2);
AI_FreeArbInt(v3);
v3 = v2;
}
else
{
AI_FreeArbInt(v2);
AI_FreeArbInt(v3);
v3 = func1(a1, a2);
}
return v3;
}

original_code:
ArbInt *AI_Pow(ArbInt const *A, ArbInt const *B)
{
  ArbInt *zero = AI_NewArbInt_From32(0);
  ArbInt *one = AI_NewArbInt_From32(1);
  if (AI_Equal(B, zero)) {
    AI_FreeArbInt(zero);
    return one;
  }
  if (AI_Equal(B, one)) {
    AI_FreeArbInt(zero);
    AI_FreeArbInt(one);
    return AI_NewArbInt_FromCopy(A);
  }
  if (AI_Less(B, zero)) {
    AI_FreeArbInt(zero);
    AI_FreeArbInt(one);
    return zero;
  }
  AI_FreeArbInt(zero);
  AI_FreeArbInt(one);
  return ai_pow_positive(A, B);
}

canonical_original_code:
struct arbint *AI_Pow(struct arbint *A, struct arbint *B)
{
  struct arbint *zero = AI_NewArbInt_From32(0);
  struct arbint *one = AI_NewArbInt_From32(1);
  if (AI_Equal(B, zero)) {
    AI_FreeArbInt(zero);
    return one;
  }
  if (AI_Equal(B, one)) {
    AI_FreeArbInt(zero);
    AI_FreeArbInt(one);
    return AI_NewArbInt_FromCopy(A);
  }
  if (AI_Less(B, zero)) {
    AI_FreeArbInt(zero);
    AI_FreeArbInt(one);
    return zero;
  }
  AI_FreeArbInt(zero);
  AI_FreeArbInt(one);
  return ai_pow_positive(A, B);
}


decompiled_code:
__int64 __fastcall ai_pow_by_val(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // ebp
__int64 v4; // r13

if ( !a2 )
return AI_NewArbInt_From32(1LL);
if ( a2 == 1 )
return AI_NewArbInt_FromCopy(a1);
v2 = AI_Mul(a1, a1);
v3 = a2 - 2;
if ( a2 != 2 )
{
do
{
v4 = v2;
v2 = AI_Mul(v2, a1);
AI_FreeArbInt(v4);
--v3;
}
while ( v3 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // ebp
__int64 v4; // r13

if ( !a2 )
return AI_NewArbInt_From32(1LL);
if ( a2 == 1 )
return AI_NewArbInt_FromCopy(a1);
v2 = AI_Mul(a1, a1);
v3 = a2 - 2;
if ( a2 != 2 )
{
do
{
v4 = v2;
v2 = AI_Mul(v2, a1);
AI_FreeArbInt(v4);
--v3;
}
while ( v3 );
}
return v2;
}

original_code:
ArbInt *ai_pow_by_val(ArbInt const *A, aibase_t val)
{
  if (val == 0) {
    return AI_NewArbInt_From32(1);
  } else if (val == 1) {
    return AI_NewArbInt_FromCopy(A);
  }
  ArbInt *result = AI_Mul(A, A);
  val -= 2;
  while (val > 0) {
    ArbInt *tmp = AI_Mul(result, A);
    AI_FreeArbInt(result);
    result = tmp;
    val--;
  }
  return result;
}

canonical_original_code:
struct arbint *ai_pow_by_val(struct arbint *A, unsigned int val)
{
  if (val == 0) {
    return AI_NewArbInt_From32(1);
  } else if (val == 1) {
    return AI_NewArbInt_FromCopy(A);
  }
  struct arbint *result = AI_Mul(A, A);
  val -= 2;
  while (val > 0) {
    struct arbint *tmp = AI_Mul(result, A);
    AI_FreeArbInt(result);
    result = tmp;
    val--;
  }
  return result;
}

variable_types:
val
unsigned int


original_code:
char const *AI_ToString(ArbInt const *value)
{
  if (value == ((void *)0)) return nullstr;
  size_t i;
  int zero_crop = 1;
  int len =
    2 * value->dataLen * sizeof(aibase_t) + 1 + (value->sign == 0 ? 0 : 1);
  char *str = (char *)AI_malloc(len);
  char *p = str;
  aibase_t *vp = value->data;
  int shift = 28;
  if (p == ((void *)0)) {
    return ((void *)0);
  }
  if (value->sign == -1) {
    *p++ = '-';
  }
  while (((((*vp >> shift) & 0x0000000F) <= 9) ? (((*vp >> shift) & 0x0000000F) + '0') : (((*vp >> shift) & 0x0000000F) + 55)) == '0' && shift >= 0) {
    shift -= 4;
  }
  *p++ = '0';
  *p++ = 'x';
  for (i = 0; i < value->dataLen; i++) {
    while (shift >= 0) {
      *p++ = ((((*vp >> shift) & 0x0000000F) <= 9) ? (((*vp >> shift) & 0x0000000F) + '0') : (((*vp >> shift) & 0x0000000F) + 55));
      shift -= 4;
    }
    shift = 28;
    vp++;
  }
  *p = '\0';
  return str;
}

canonical_original_code:
char *AI_ToString(struct arbint *value)
{
  if (value == ((void *)0)) return nullstr;
  unsigned long i;
  int zero_crop = 1;
  int len = 2 * value->dataLen * sizeof(aibase_t) + 1 + (value->sign == 0 ? 0 : 1);
  char *str = (char *)AI_malloc(len);
  char *p = str;
  unsigned int *vp = value->data;
  int shift = 28;
  if (p == ((void *)0)) {
    return ((void *)0);
  }
  if (value->sign == -1) {
    *p++ = '-';
  }
  while (((((*vp >> shift) & 0x0000000F) <= 9) ? (((*vp >> shift) & 0x0000000F) + '0') : (((*vp >> shift) & 0x0000000F) + 55)) == '0' && shift >= 0) {
    shift -= 4;
  }
  *p++ = '0';
  *p++ = 'x';
  for (i = 0; i < value->dataLen; i++) {
    while (shift >= 0) {
      *p++ = ((((*vp >> shift) & 0x0000000F) <= 9) ? (((*vp >> shift) & 0x0000000F) + '0') : (((*vp >> shift) & 0x0000000F) + 55));
      shift -= 4;
    }
    shift = 28;
    vp++;
  }
  *p = '\0';
  return str;
}

variable_types:
i
unsigned long

variable_types: len int

variable_types:
str
char *

variable_types:
p
char *

variable_types:
vp
unsigned int *

variable_types: shift int

return_type: char *


decompiled_code:
const char *__fastcall ai_reverse_str(const char *a1)
{
int v2; // eax
int v3; // edi
char *v4; // rdx
__int64 v5; // rax
char v6; // cl

v2 = strlen(a1);
v3 = v2 / 2;
if ( v2 > 1 )
{
v4 = (char *)&a1[v2 - 1];
v5 = 0LL;
do
{
v6 = a1[v5];
a1[v5] = *v4;
*v4 = v6;
++v5;
--v4;
}
while ( v3 > (int)v5 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
int v2; // eax
int v3; // edi
char *v4; // rdx
__int64 v5; // rax
char v6; // cl

v2 = strlen(a1);
v3 = v2 / 2;
if ( v2 > 1 )
{
v4 = (char *)&a1[v2 - 1];
v5 = 0LL;
do
{
v6 = a1[v5];
a1[v5] = *v4;
*v4 = v6;
++v5;
--v4;
}
while ( v3 > (int)v5 );
}
return a1;
}

original_code:
char const *ai_reverse_str(char *in_out)
{
  int len = strlen(in_out);
  char swap;
  int i;
  for (i = 0; i < len/2; i++) {
    swap = in_out[i];
    in_out[i] = in_out[len - i - 1];
    in_out[len - i - 1] = swap;
  }
  return in_out;
}

canonical_original_code:
char *ai_reverse_str(char *in_out)
{
  int len = strlen(in_out);
  char swap;
  int i;
  for (i = 0; i < len/2; i++) {
    swap = in_out[i];
    in_out[i] = in_out[len - i - 1];
    in_out[len - i - 1] = swap;
  }
  return in_out;
}

variable_types: swap char

variable_types: i int


original_code:
char const *AI_ToStringBase(ArbInt const *value, int base, int approxLen)
{
  if (base > 10 || base <= 0 || base != 1000000000 || base != 16, value == ((void *)0)) return nullstr;
  int sign = value->sign;
  char *str = AI_malloc(approxLen + 2);
  char *p = str;
  ArbInt *ai_base = AI_NewArbInt_FromLong(base);
  ArbInt *copy = AI_NewArbInt_FromCopy(value);
  copy->sign = 1;
  ArbInt *digit;
  while (AI_Greater(copy, ai_base)) {
    int i;
    ArbInt *tmp = AI_Div(copy, ai_base, &digit);
    AI_FreeArbInt(copy);
    copy = tmp;
    if (base != 1000000000) {
      *p++ = (((digit->data[0]) <= 9) ? ((digit->data[0]) + '0') : ((digit->data[0]) + 55));
      if (approxLen-- == 0) {
        return nullstr;
      }
    } else {
      {
        char s[11];
        sprintf(s, "%09u", digit->data[0]);
        for (i = 0; i < 9; i++) {
          *p++ = s[8 - i];
        }
      }
      if (approxLen-- == 0) {
        return nullstr;
      }
      if (approxLen-- == 0) {
        return nullstr;
      }
      if (approxLen-- == 0) {
        return nullstr;
      }
    }
    AI_FreeArbInt(digit);
  }
  if (base != 1000000000) {
    *p++ = (((copy->data[0]) <= 9) ? ((copy->data[0]) + '0') : ((copy->data[0]) + 55));
  } else {
    {
      int i;
      char s[11];
      int prezero = 0;
      sprintf(s, "%09u", copy->data[0]);
      for (i = 0; i < 9; i++) {
        if (s[i] != '0') break;
        prezero++;
      }
      for (i = 0; i < 9 - prezero; i++) {
          *p++ = s[8 - i];
      }
    }
  }
  if (base == 16) { *p++ = 'x'; *p++ = '0'; }
  if (sign == -1) *p++ = '-';
  *p = '\0';
  return ai_reverse_str(str);
}

canonical_original_code:
char *AI_ToStringBase(struct arbint *value, int base, int approxLen)
{
  if (base > 10 || base <= 0 || base != 1000000000 || base != 16, value == ((void *)0)) return nullstr;
  int sign = value->sign;
  char *str = AI_malloc(approxLen + 2);
  char *p = str;
  struct arbint *ai_base = AI_NewArbInt_FromLong(base);
  struct arbint *copy = AI_NewArbInt_FromCopy(value);
  copy->sign = 1;
  struct arbint *digit;
  while (AI_Greater(copy, ai_base)) {
    int i;
    struct arbint *tmp = AI_Div(copy, ai_base, &digit);
    AI_FreeArbInt(copy);
    copy = tmp;
    if (base != 1000000000) {
      *p++ = (((digit->data[0]) <= 9) ? ((digit->data[0]) + '0') : ((digit->data[0]) + 55));
      if (approxLen-- == 0) {
        return nullstr;
      }
    } else {
      {
        char s[11];
        sprintf(s, "%09u", digit->data[0]);
        for (i = 0; i < 9; i++) {
          *p++ = s[8 - i];
        }
      }
      if (approxLen-- == 0) {
        return nullstr;
      }
      if (approxLen-- == 0) {
        return nullstr;
      }
      if (approxLen-- == 0) {
        return nullstr;
      }
    }
    AI_FreeArbInt(digit);
  }
  if (base != 1000000000) {
    *p++ = (((copy->data[0]) <= 9) ? ((copy->data[0]) + '0') : ((copy->data[0]) + 55));
  } else {
    {
      int i;
      char s[11];
      int prezero = 0;
      sprintf(s, "%09u", copy->data[0]);
      for (i = 0; i < 9; i++) {
        if (s[i] != '0') break;
        prezero++;
      }
      for (i = 0; i < 9 - prezero; i++) {
          *p++ = s[8 - i];
      }
    }
  }
  if (base == 16) { *p++ = 'x'; *p++ = '0'; }
  if (sign == -1) *p++ = '-';
  *p = '\0';
  return ai_reverse_str(str);
}

variable_types: struct arbint { unsigned int *data; unsigned long dataLen; int sign; } *

variable_types: base int

variable_types: approxLen int

variable_types: sign int

variable_types:
s
char [11]

variable_types: prezero int


decompiled_code:
const char *__fastcall AI_ToStringDec(__int64 a1)
{
const char *result; // rax

result = "(null)";
if ( a1 )
result = AI_ToStringBase(a1, 0x3B9ACA00u, 10 * (unsigned int)*(_QWORD *)(a1 + 8));
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1)
{
const char *result; // rax

result = "(null)";
if ( a1 )
result = func2(a1, 0x3B9ACA00u, 10 * (unsigned int)*(_QWORD *)(a1 + 8));
return result;
}

original_code:
char const *AI_ToStringDec(ArbInt const *value)
{
  if (value == ((void *)0)) return nullstr;
  return AI_ToStringBase(value, 1000000000, 10 * value->dataLen);
}

canonical_original_code:
char *AI_ToStringDec(struct arbint *value)
{
  if (value == ((void *)0)) return nullstr;
  return AI_ToStringBase(value, 1000000000, 10 * value->dataLen);
}


decompiled_code:
__int64 __fastcall AI_Make_Bit_Iter(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // rcx

result = AI_malloc(32LL);
if ( result )
{
v2 = *a1 + 4LL * a1[1] - 4;
*(_QWORD *)result = v2;
*(_QWORD *)(result + 8) = *a1 - 4LL;
*(_QWORD *)(result + 16) = v2;
*(_DWORD *)(result + 24) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // rcx

result = AI_malloc(32LL);
if ( result )
{
v2 = *a1 + 4LL * a1[1] - 4;
*(_QWORD *)result = v2;
*(_QWORD *)(result + 8) = *a1 - 4LL;
*(_QWORD *)(result + 16) = v2;
*(_DWORD *)(result + 24) = 1;
}
return result;
}

original_code:
ArbInt_BitIterator *AI_Make_Bit_Iter(ArbInt const *ai)
{
  ArbInt_BitIterator *bi = AI_malloc(sizeof(ArbInt_BitIterator));
  if (bi != ((void *)0)) {
    bi->begin = ai->data + ai->dataLen - 1;
    bi->end = ai->data - 1;
    bi->byte = bi->begin;
    bi->bit = 0x01;
  }
  return bi;
}

canonical_original_code:
struct arbint_bititerator *AI_Make_Bit_Iter(struct arbint *ai)
{
  struct arbint_bititerator *bi = AI_malloc(sizeof(ArbInt_BitIterator));
  if (bi != ((void *)0)) {
    bi->begin = ai->data + ai->dataLen - 1;
    bi->end = ai->data - 1;
    bi->byte = bi->begin;
    bi->bit = 0x01;
  }
  return bi;
}

variable_types: struct arbint_bititerator { unsigned int *begin; unsigned int *end; unsigned int *byte; unsigned int bit; } *


original_code:
int AI_Bit_Iter_Inc(ArbInt_BitIterator *bi)
{
  bi->bit <<= 1;
  if (bi->bit == 0) {
    bi->byte--;
    bi->bit = 0x01;
  }
  if (bi->byte > bi->end) {
    return 1;
  } else {
    bi->byte = bi->end;
    return 0;
  }
}

canonical_original_code:
int AI_Bit_Iter_Inc(struct arbint_bititerator *bi)
{
  bi->bit <<= 1;
  if (bi->bit == 0) {
    bi->byte--;
    bi->bit = 0x01;
  }
  if (bi->byte > bi->end) {
    return 1;
  } else {
    bi->byte = bi->end;
    return 0;
  }
}

return_type: int

user_defined_types: struct arbint_bititerator { unsigned int *begin; unsigned int *end; unsigned int *byte; unsigned int bit; }


original_code:
int AI_Bit_Iter_Get(ArbInt_BitIterator const *bi)
{
  return (*(bi->byte) & bi->bit) ? 1 : 0;
}

canonical_original_code:
int AI_Bit_Iter_Get(struct arbint_bititerator *bi)
{
  return (*(bi->byte) & bi->bit) ? 1 : 0;
}


OCLErrorMessage

repo: matthewharvey/OCLHelperFunctions

decompiled_code:
const char *__fastcall OCLErrorMessage(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -63:
result = "CL:Invalid Global Work Size";
break;
case -62:
result = "CL:Invalid Mip Level";
break;
case -61:
result = "CL:Invalid Buffer Size";
break;
case -60:
result = "CL:Invalid GL Object";
break;
case -59:
result = "CL:Invalid Operation";
break;
case -58:
result = "CL:Invalid Event";
break;
case -57:
result = "CL:Invalid Event Wait List";
break;
case -56:
result = "CL:Invalid Global Offset";
break;
case -55:
result = "CL:Invalid Work Item Size";
break;
case -54:
result = "CL:Invalid Work Group Size";
break;
case -53:
result = "CL:Invalid Work Dimension";
break;
case -52:
result = "CL:Invalid Kernel Arguments";
break;
case -51:
result = "CL:Invalid Argument Size";
break;
case -50:
result = "CL:Invalid Argument Value";
break;
case -49:
result = "CL:Invalid Argument Index";
break;
case -48:
result = "CL:Invalid Kernel";
break;
case -47:
result = "CL:Invalid Kernel Definition";
break;
case -46:
result = "CL:Invalid Kernel Name";
break;
case -45:
result = "CL:Invalid Program Executable";
break;
case -44:
result = "CL:Invalid Program";
break;
case -43:
result = "CL:Invalid Build Options";
break;
case -42:
result = "CL:Invalid Binary";
break;
case -41:
result = "CL:Invalid Sampler";
break;
case -40:
result = "CL:Invalid Image Size";
break;
case -39:
result = "CL:Invalid Image Format Descriptor";
break;
case -38:
result = "CL:Invalid Memory Object";
break;
case -37:
result = "CL:Invalid Host Pointer";
break;
case -36:
result = "CL:Invalid Command Queue";
break;
case -35:
result = "CL:Invalid Queue Properties";
break;
case -34:
result = "CL:Invalid Context";
break;
case -33:
result = "CL:Invalid Device";
break;
case -32:
result = "CL:Invalid Platform";
break;
case -31:
result = "CL:Invalid Device Type";
break;
case -30:
result = "CL:Invalid Value";
break;
case -12:
result = "CL:Map Failure";
break;
case -11:
result = "CL:Build Program Failure";
break;
case -10:
result = "CL:Image Format Not Supported";
break;
case -9:
result = "CL:Image Format Mismatch";
break;
case -8:
result = "CL:Memory copy overlap";
break;
case -7:
result = "CL:Profiling info is not available";
break;
case -6:
result = "CL:Out of Host Memory";
break;
case -5:
result = "CL:Out of Resources";
break;
case -4:
result = "CL:Memory Object Allocation Failed";
break;
case -3:
result = "CL:Compiler not Available";
break;
case -2:
result = "CL:Device not Available";
break;
case -1:
result = "CL:Device not Found";
break;
case 0:
result = 0LL;
break;
default:
result = "CL:Unknown Error";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -63:
result = "CL:Invalid Global Work Size";
break;
case -62:
result = "CL:Invalid Mip Level";
break;
case -61:
result = "CL:Invalid Buffer Size";
break;
case -60:
result = "CL:Invalid GL Object";
break;
case -59:
result = "CL:Invalid Operation";
break;
case -58:
result = "CL:Invalid Event";
break;
case -57:
result = "CL:Invalid Event Wait List";
break;
case -56:
result = "CL:Invalid Global Offset";
break;
case -55:
result = "CL:Invalid Work Item Size";
break;
case -54:
result = "CL:Invalid Work Group Size";
break;
case -53:
result = "CL:Invalid Work Dimension";
break;
case -52:
result = "CL:Invalid Kernel Arguments";
break;
case -51:
result = "CL:Invalid Argument Size";
break;
case -50:
result = "CL:Invalid Argument Value";
break;
case -49:
result = "CL:Invalid Argument Index";
break;
case -48:
result = "CL:Invalid Kernel";
break;
case -47:
result = "CL:Invalid Kernel Definition";
break;
case -46:
result = "CL:Invalid Kernel Name";
break;
case -45:
result = "CL:Invalid Program Executable";
break;
case -44:
result = "CL:Invalid Program";
break;
case -43:
result = "CL:Invalid Build Options";
break;
case -42:
result = "CL:Invalid Binary";
break;
case -41:
result = "CL:Invalid Sampler";
break;
case -40:
result = "CL:Invalid Image Size";
break;
case -39:
result = "CL:Invalid Image Format Descriptor";
break;
case -38:
result = "CL:Invalid Memory Object";
break;
case -37:
result = "CL:Invalid Host Pointer";
break;
case -36:
result = "CL:Invalid Command Queue";
break;
case -35:
result = "CL:Invalid Queue Properties";
break;
case -34:
result = "CL:Invalid Context";
break;
case -33:
result = "CL:Invalid Device";
break;
case -32:
result = "CL:Invalid Platform";
break;
case -31:
result = "CL:Invalid Device Type";
break;
case -30:
result = "CL:Invalid Value";
break;
case -12:
result = "CL:Map Failure";
break;
case -11:
result = "CL:Build Program Failure";
break;
case -10:
result = "CL:Image Format Not Supported";
break;
case -9:
result = "CL:Image Format Mismatch";
break;
case -8:
result = "CL:Memory copy overlap";
break;
case -7:
result = "CL:Profiling info is not available";
break;
case -6:
result = "CL:Out of Host Memory";
break;
case -5:
result = "CL:Out of Resources";
break;
case -4:
result = "CL:Memory Object Allocation Failed";
break;
case -3:
result = "CL:Compiler not Available";
break;
case -2:
result = "CL:Device not Available";
break;
case -1:
result = "CL:Device not Found";
break;
case 0:
result = 0LL;
break;
default:
result = "CL:Unknown Error";
break;
}
return result;
}

original_code:
const char* OCLErrorMessage(cl_int retval)
{
    const char* message = ((void *)0);
    switch (retval)
    {
    case 0:
        break;
    case -1:
        message = "CL:Device not Found";
        break;
    case -2:
        message = "CL:Device not Available";
        break;
    case -3:
        message = "CL:Compiler not Available";
        break;
    case -4:
        message = "CL:Memory Object Allocation Failed";
        break;
    case -5:
        message = "CL:Out of Resources";
        break;
    case -6:
        message = "CL:Out of Host Memory";
        break;
    case -7:
        message = "CL:Profiling info is not available";
        break;
    case -8:
        message = "CL:Memory copy overlap";
        break;
    case -9:
        message = "CL:Image Format Mismatch";
        break;
    case -10:
        message = "CL:Image Format Not Supported";
        break;
    case -11:
        message = "CL:Build Program Failure";
        break;
    case -12:
        message = "CL:Map Failure";
        break;
    case -30:
        message = "CL:Invalid Value";
        break;
    case -31:
        message = "CL:Invalid Device Type";
        break;
    case -32:
        message = "CL:Invalid Platform";
        break;
    case -33:
        message = "CL:Invalid Device";
        break;
    case -34:
        message = "CL:Invalid Context";
        break;
    case -35:
        message = "CL:Invalid Queue Properties";
        break;
    case -36:
        message = "CL:Invalid Command Queue";
        break;
    case -37:
        message = "CL:Invalid Host Pointer";
        break;
    case -38:
        message = "CL:Invalid Memory Object";
        break;
    case -39:
        message = "CL:Invalid Image Format Descriptor";
        break;
    case -40:
        message = "CL:Invalid Image Size";
        break;
    case -41:
        message = "CL:Invalid Sampler";
        break;
    case -42:
        message = "CL:Invalid Binary";
        break;
    case -43:
        message = "CL:Invalid Build Options";
        break;
    case -44:
        message = "CL:Invalid Program";
        break;
    case -45:
        message = "CL:Invalid Program Executable";
        break;
    case -46:
        message = "CL:Invalid Kernel Name";
        break;
    case -47:
        message = "CL:Invalid Kernel Definition";
        break;
    case -48:
        message = "CL:Invalid Kernel";
        break;
    case -49:
        message = "CL:Invalid Argument Index";
        break;
    case -50:
        message = "CL:Invalid Argument Value";
        break;
    case -51:
        message = "CL:Invalid Argument Size";
        break;
    case -52:
        message = "CL:Invalid Kernel Arguments";
        break;
    case -53:
        message = "CL:Invalid Work Dimension";
        break;
    case -54:
        message = "CL:Invalid Work Group Size";
        break;
    case -55:
        message = "CL:Invalid Work Item Size";
        break;
    case -56:
        message = "CL:Invalid Global Offset";
        break;
    case -57:
        message = "CL:Invalid Event Wait List";
        break;
    case -58:
        message = "CL:Invalid Event";
        break;
    case -59:
        message = "CL:Invalid Operation";
        break;
    case -60:
        message = "CL:Invalid GL Object";
        break;
    case -61:
        message = "CL:Invalid Buffer Size";
        break;
    case -62:
        message = "CL:Invalid Mip Level";
        break;
    case -63:
        message = "CL:Invalid Global Work Size";
        break;
    default:
        message = "CL:Unknown Error";
        break;
    }
    return message;
}

canonical_original_code:
char *OCLErrorMessage(int retval)
{
    char *message = ((void *)0);
    switch (retval)
    {
    case 0:
        break;
    case -1:
        message = "CL:Device not Found";
        break;
    case -2:
        message = "CL:Device not Available";
        break;
    case -3:
        message = "CL:Compiler not Available";
        break;
    case -4:
        message = "CL:Memory Object Allocation Failed";
        break;
    case -5:
        message = "CL:Out of Resources";
        break;
    case -6:
        message = "CL:Out of Host Memory";
        break;
    case -7:
        message = "CL:Profiling info is not available";
        break;
    case -8:
        message = "CL:Memory copy overlap";
        break;
    case -9:
        message = "CL:Image Format Mismatch";
        break;
    case -10:
        message = "CL:Image Format Not Supported";
        break;
    case -11:
        message = "CL:Build Program Failure";
        break;
    case -12:
        message = "CL:Map Failure";
        break;
    case -30:
        message = "CL:Invalid Value";
        break;
    case -31:
        message = "CL:Invalid Device Type";
        break;
    case -32:
        message = "CL:Invalid Platform";
        break;
    case -33:
        message = "CL:Invalid Device";
        break;
    case -34:
        message = "CL:Invalid Context";
        break;
    case -35:
        message = "CL:Invalid Queue Properties";
        break;
    case -36:
        message = "CL:Invalid Command Queue";
        break;
    case -37:
        message = "CL:Invalid Host Pointer";
        break;
    case -38:
        message = "CL:Invalid Memory Object";
        break;
    case -39:
        message = "CL:Invalid Image Format Descriptor";
        break;
    case -40:
        message = "CL:Invalid Image Size";
        break;
    case -41:
        message = "CL:Invalid Sampler";
        break;
    case -42:
        message = "CL:Invalid Binary";
        break;
    case -43:
        message = "CL:Invalid Build Options";
        break;
    case -44:
        message = "CL:Invalid Program";
        break;
    case -45:
        message = "CL:Invalid Program Executable";
        break;
    case -46:
        message = "CL:Invalid Kernel Name";
        break;
    case -47:
        message = "CL:Invalid Kernel Definition";
        break;
    case -48:
        message = "CL:Invalid Kernel";
        break;
    case -49:
        message = "CL:Invalid Argument Index";
        break;
    case -50:
        message = "CL:Invalid Argument Value";
        break;
    case -51:
        message = "CL:Invalid Argument Size";
        break;
    case -52:
        message = "CL:Invalid Kernel Arguments";
        break;
    case -53:
        message = "CL:Invalid Work Dimension";
        break;
    case -54:
        message = "CL:Invalid Work Group Size";
        break;
    case -55:
        message = "CL:Invalid Work Item Size";
        break;
    case -56:
        message = "CL:Invalid Global Offset";
        break;
    case -57:
        message = "CL:Invalid Event Wait List";
        break;
    case -58:
        message = "CL:Invalid Event";
        break;
    case -59:
        message = "CL:Invalid Operation";
        break;
    case -60:
        message = "CL:Invalid GL Object";
        break;
    case -61:
        message = "CL:Invalid Buffer Size";
        break;
    case -62:
        message = "CL:Invalid Mip Level";
        break;
    case -63:
        message = "CL:Invalid Global Work Size";
        break;
    default:
        message = "CL:Unknown Error";
        break;
    }
    return message;
}

variable_types: retval int

variable_types:
message
char *


decompiled_code:
const char *base2_type_string_internal()
{
return "base2";
}

canonical_decompiled_code:
const char *func0()
{
return "base2";
}

original_code:
static const char *
base2_type_string_internal (base2_handle base2_h)
{
    return ("base2");
}

canonical_original_code:
static char *base2_type_string_internal(struct base2_st_ *base2_h)
{
    return ("base2");
}

variable_types: struct base2_st_ { struct base2_private_st_ { struct base2_vtable_st_ { void (*delete_fn)(struct base2_st_ *base2_h); char *(*type_string_fn)(struct base2_st_ *base2_h); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_fn)(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_size_fn)(struct base2_st_ *base2_h, unsigned long *buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*increase_val1_fn)(struct base2_st_ *base2_h); } *vtable; } *private_h; unsigned int val1; } *

user_defined_types: struct base2_st_ { struct base2_private_st_ *private_h; unsigned int val1; }

user_defined_types: struct base2_private_st_ { struct base2_vtable_st_ *vtable; }

user_defined_types: struct base2_vtable_st_ { void (*delete_fn)(struct base2_st_ *base2_h); char *(*type_string_fn)(struct base2_st_ *base2_h); enum my_rc_e_ (*string_fn)(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size); enum my_rc_e_ (*string_size_fn)(struct base2_st_ *base2_h, unsigned long *buffer_size); enum my_rc_e_ (*increase_val1_fn)(struct base2_st_ *base2_h); }


decompiled_code:
__int64 __fastcall base2_string_size_internal(const void *a1, _QWORD *a2)
{
__int64 result; // rax

if ( a1 && a2 )
{
*a2 = 64LL;
result = 1LL;
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) buffer_size(%p)\n", "base2.c", 74LL, a1, a2);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, _QWORD *a2)
{
__int64 result; // rax

if ( a1 && a2 )
{
*a2 = 64LL;
result = 1LL;
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) buffer_size(%p)\n", "base2.c", 74LL, a1, a2);
result = 2LL;
}
return result;
}

original_code:
static my_rc_e
base2_string_size_internal (base2_handle base2_h, size_t *buffer_size)
{
    if ((((void *)0) == base2_h) || (((void *)0) == buffer_size)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) buffer_size(%p)" "\n", "base2.c", 74, base2_h, buffer_size); } while (0);
        return (MY_RC_E_EINVAL);
    }
    *buffer_size = 64;
    return (MY_RC_E_SUCCESS);
}

canonical_original_code:
static enum my_rc_e_ base2_string_size_internal(struct base2_st_ *base2_h, unsigned long *buffer_size)
{
    if ((((void *)0) == base2_h) || (((void *)0) == buffer_size)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) buffer_size(%p)" "\n", "base2.c", 74, base2_h, buffer_size); } while (0);
        return (MY_RC_E_EINVAL);
    }
    *buffer_size = 64;
    return (MY_RC_E_SUCCESS);
}

return_type: enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 }


decompiled_code:
void __fastcall base2_delete_internal(void *ptr, char a2)
{
void *v3; // rdi

if ( ptr )
{
v3 = *(void **)ptr;
if ( v3 )
{
free(v3);
*(_QWORD *)ptr = 0LL;
}
if ( a2 )
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, char a2)
{
void *v3; // rdi

if ( ptr )
{
v3 = *(void **)ptr;
if ( v3 )
{
free(v3);
*(_QWORD *)ptr = 0LL;
}
if ( a2 )
free(ptr);
}
}

original_code:
static void
base2_delete_internal (base2_handle base2_h, _Bool free_base2_h)
{
    if (((void *)0) == base2_h) {
        return;
    }
    if (((void *)0) != base2_h->private_h) {
        free(base2_h->private_h);
        base2_h->private_h = ((void *)0);
    }
    if (free_base2_h) {
        free(base2_h);
    }
}

canonical_original_code:
static void base2_delete_internal(struct base2_st_ *base2_h, _Bool free_base2_h)
{
    if (((void *)0) == base2_h) {
        return;
    }
    if (((void *)0) != base2_h->private_h) {
        free(base2_h->private_h);
        base2_h->private_h = ((void *)0);
    }
    if (free_base2_h) {
        free(base2_h);
    }
}

user_defined_types: enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 }


decompiled_code:
void __fastcall base2_private_delete(void *a1)
{
base2_delete_internal(a1, 1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
func2(a1, 1);
}

original_code:
static void
base2_private_delete (base2_handle base2_h)
{
    base2_delete_internal(base2_h, 1);
}

canonical_original_code:
static void base2_private_delete(struct base2_st_ *base2_h)
{
    base2_delete_internal(base2_h, 1);
}


decompiled_code:
__int64 __fastcall base2_string_internal(unsigned int *a1, char *a2, size_t a3)
{
_QWORD *v4; // r8
_QWORD *v5; // r9
__int64 v6; // rbp
unsigned __int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a1 && a2 )
{
v4 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v5 = (_QWORD *)*v4;
if ( *v4 )
{
LODWORD(v6) = 1;
if ( !v5[3] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) string_size_fn(%p)\n",
"base2.c",
162LL,
a1,
v4,
v5,
0LL);
LODWORD(v6) = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 162LL, a1, v4, 0LL);
LODWORD(v6) = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 162LL, a1, 0LL);
LODWORD(v6) = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok((unsigned int)v6) )
{
v6 = (*(unsigned int (__fastcall **)(unsigned int *, unsigned __int64 *))(**(_QWORD **)a1 + 24LL))(a1, v8);
if ( !(unsigned __int8)my_rc_e_is_notok(v6) )
{
if ( v8[0] > a3 )
{
printf("(%s:%u) ERROR: Invalid input, buffer_size(%zu)\n", "base2.c", 173LL, a3);
LODWORD(v6) = 2;
}
else
{
snprintf(a2, a3, "val1(%u)", a1[2]);
LODWORD(v6) = 1;
}
}
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) buffer(%p) buffer_size(%zu)\n", "base2.c", 157LL, a1, a2, a3);
LODWORD(v6) = 2;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, char *a2, size_t a3)
{
_QWORD *v4; // r8
_QWORD *v5; // r9
__int64 v6; // rbp
unsigned __int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a1 && a2 )
{
v4 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v5 = (_QWORD *)*v4;
if ( *v4 )
{
LODWORD(v6) = 1;
if ( !v5[3] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) string_size_fn(%p)\n",
"base2.c",
162LL,
a1,
v4,
v5,
0LL);
LODWORD(v6) = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 162LL, a1, v4, 0LL);
LODWORD(v6) = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 162LL, a1, 0LL);
LODWORD(v6) = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok((unsigned int)v6) )
{
v6 = (*(unsigned int (__fastcall **)(unsigned int *, unsigned __int64 *))(**(_QWORD **)a1 + 24LL))(a1, v8);
if ( !(unsigned __int8)my_rc_e_is_notok(v6) )
{
if ( v8[0] > a3 )
{
printf("(%s:%u) ERROR: Invalid input, buffer_size(%zu)\n", "base2.c", 173LL, a3);
LODWORD(v6) = 2;
}
else
{
snprintf(a2, a3, "val1(%u)", a1[2]);
LODWORD(v6) = 1;
}
}
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) buffer(%p) buffer_size(%zu)\n", "base2.c", 157LL, a1, a2, a3);
LODWORD(v6) = 2;
}
return (unsigned int)v6;
}

original_code:
static my_rc_e
base2_string_internal (base2_handle base2_h, char *buffer, size_t buffer_size)
{
    size_t min_size;
    my_rc_e rc = MY_RC_E_SUCCESS;
    if ((((void *)0) == base2_h) || (((void *)0) == buffer)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) buffer(%p) buffer_size(%zu)" "\n", "base2.c", 157, base2_h, buffer, buffer_size); } while (0);
        return (MY_RC_E_EINVAL);
    }
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 162,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 162,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 162,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->string_size_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "string_size_fn" "(%p)" "\n", "base2.c", 162,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    rc = base2_h->private_h->vtable->string_size_fn(base2_h, &min_size);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    if (buffer_size < min_size) {
        do { printf("(%s:%u) ERROR: " "Invalid input, buffer_size(%zu)" "\n", "base2.c", 173, buffer_size); } while (0);
        return (MY_RC_E_EINVAL);
    }
    snprintf(buffer, buffer_size, "val1(%u)", base2_h->val1);
    return (MY_RC_E_SUCCESS);
}

canonical_original_code:
static enum my_rc_e_ base2_string_internal(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size)
{
    unsigned long min_size;
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    if ((((void *)0) == base2_h) || (((void *)0) == buffer)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) buffer(%p) buffer_size(%zu)" "\n", "base2.c", 157, base2_h, buffer, buffer_size); } while (0);
        return (MY_RC_E_EINVAL);
    }
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 162,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 162,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 162,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->string_size_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "string_size_fn" "(%p)" "\n", "base2.c", 162,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    rc = base2_h->private_h->vtable->string_size_fn(base2_h, &min_size);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    if (buffer_size < min_size) {
        do { printf("(%s:%u) ERROR: " "Invalid input, buffer_size(%zu)" "\n", "base2.c", 173, buffer_size); } while (0);
        return (MY_RC_E_EINVAL);
    }
    snprintf(buffer, buffer_size, "val1(%u)", base2_h->val1);
    return (MY_RC_E_SUCCESS);
}

variable_types:
buffer
char *

variable_types: enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 }


decompiled_code:
__int64 __fastcall base2_string_size(const void *a1, __int64 a2)
{
_QWORD *v2; // r8
_QWORD *v3; // r9
unsigned int v4; // ebp

if ( a1 )
{
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
v4 = 1;
if ( !v3[3] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) string_size_fn(%p)\n",
"base2.c",
54LL,
a1,
v2,
v3,
0LL);
v4 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 54LL, a1, v2, 0LL);
v4 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 54LL, a1, 0LL);
v4 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 54LL, 0LL);
v4 = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok(v4) )
v4 = (*(__int64 (__fastcall **)(const void *, __int64))(**(_QWORD **)a1 + 24LL))(a1, a2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(const void *a1, __int64 a2)
{
_QWORD *v2; // r8
_QWORD *v3; // r9
unsigned int v4; // ebp

if ( a1 )
{
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
v4 = 1;
if ( !v3[3] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) string_size_fn(%p)\n",
"base2.c",
54LL,
a1,
v2,
v3,
0LL);
v4 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 54LL, a1, v2, 0LL);
v4 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 54LL, a1, 0LL);
v4 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 54LL, 0LL);
v4 = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok(v4) )
v4 = (*(__int64 (__fastcall **)(const void *, __int64))(**(_QWORD **)a1 + 24LL))(a1, a2);
return v4;
}

original_code:
my_rc_e
base2_string_size (base2_handle base2_h, size_t *buffer_size)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 54,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 54,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 54,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->string_size_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "string_size_fn" "(%p)" "\n", "base2.c", 54,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    return (base2_h->private_h->vtable->string_size_fn(base2_h, buffer_size));
}

canonical_original_code:
enum my_rc_e_ base2_string_size(struct base2_st_ *base2_h, unsigned long *buffer_size)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 54,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 54,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 54,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->string_size_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "string_size_fn" "(%p)" "\n", "base2.c", 54,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    return (base2_h->private_h->vtable->string_size_fn(base2_h, buffer_size));
}


decompiled_code:
void *__fastcall base2_type_string(const void *a1)
{
_QWORD *v2; // r8
_QWORD *v3; // r9
__int64 v4; // rdi
char v5; // dl
void *result; // rax

if ( a1 )
{
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
v4 = 1LL;
if ( !v3[1] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) type_string_fn(%p)\n",
"base2.c",
109LL,
a1,
v2,
v3,
0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 109LL, a1, v2, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 109LL, a1, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 109LL, 0LL);
v4 = 2LL;
}
v5 = my_rc_e_is_notok(v4);
result = &unk_9AA;
if ( !v5 )
result = (void *)(*(__int64 (__fastcall **)(const void *))(**(_QWORD **)a1 + 8LL))(a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func6(const void *a1)
{
_QWORD *v2; // r8
_QWORD *v3; // r9
__int64 v4; // rdi
char v5; // dl
void *result; // rax

if ( a1 )
{
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
v4 = 1LL;
if ( !v3[1] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) type_string_fn(%p)\n",
"base2.c",
109LL,
a1,
v2,
v3,
0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 109LL, a1, v2, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 109LL, a1, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 109LL, 0LL);
v4 = 2LL;
}
v5 = my_rc_e_is_notok(v4);
result = &unk_9AA;
if ( !v5 )
result = (void *)(*(__int64 (__fastcall **)(const void *))(**(_QWORD **)a1 + 8LL))(a1);
return result;
}

original_code:
const char *
base2_type_string (base2_handle base2_h)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 109,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 109,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 109,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->type_string_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "type_string_fn" "(%p)" "\n", "base2.c", 109,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->type_string_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return ("");
    }
    return (base2_h->private_h->vtable->type_string_fn(base2_h));
}

canonical_original_code:
char *base2_type_string(struct base2_st_ *base2_h)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 109,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 109,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 109,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->type_string_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "type_string_fn" "(%p)" "\n", "base2.c", 109,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->type_string_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return ("");
    }
    return (base2_h->private_h->vtable->type_string_fn(base2_h));
}


decompiled_code:
__int64 __fastcall base2_string(const void *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // r8
_QWORD *v5; // r9
unsigned int v6; // ebp

if ( a1 )
{
v4 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v5 = (_QWORD *)*v4;
if ( *v4 )
{
v6 = 1;
if ( !v5[2] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) string_fn(%p)\n",
"base2.c",
131LL,
a1,
v4,
v5,
0LL);
v6 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 131LL, a1, v4, 0LL);
v6 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 131LL, a1, 0LL);
v6 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 131LL, 0LL);
v6 = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok(v6) )
v6 = (*(__int64 (__fastcall **)(const void *, __int64, __int64))(**(_QWORD **)a1 + 16LL))(a1, a2, a3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // r8
_QWORD *v5; // r9
unsigned int v6; // ebp

if ( a1 )
{
v4 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v5 = (_QWORD *)*v4;
if ( *v4 )
{
v6 = 1;
if ( !v5[2] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) string_fn(%p)\n",
"base2.c",
131LL,
a1,
v4,
v5,
0LL);
v6 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 131LL, a1, v4, 0LL);
v6 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 131LL, a1, 0LL);
v6 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 131LL, 0LL);
v6 = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok(v6) )
v6 = (*(__int64 (__fastcall **)(const void *, __int64, __int64))(**(_QWORD **)a1 + 16LL))(a1, a2, a3);
return v6;
}

original_code:
my_rc_e
base2_string (base2_handle base2_h, char *buffer, size_t buffer_size)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 131,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 131,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 131,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->string_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "string_fn" "(%p)" "\n", "base2.c", 131,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->string_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    return (base2_h->private_h->vtable->string_fn(base2_h, buffer,
                                                  buffer_size));
}

canonical_original_code:
enum my_rc_e_ base2_string(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 131,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 131,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 131,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->string_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "string_fn" "(%p)" "\n", "base2.c", 131,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->string_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    return (base2_h->private_h->vtable->string_fn(base2_h, buffer,
                                                  buffer_size));
}


decompiled_code:
void __fastcall base2_friend_delete(void *a1)
{
base2_delete_internal(a1, 0);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
func2(a1, 0);
}

original_code:
void
base2_friend_delete (base2_handle base2_h)
{
    base2_delete_internal(base2_h, 0);
}

canonical_original_code:
void base2_friend_delete(struct base2_st_ *base2_h)
{
    base2_delete_internal(base2_h, 0);
}


decompiled_code:
__int64 __fastcall base2_delete(_QWORD ***a1)
{
_QWORD **v2; // r8
_QWORD *v3; // r9
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
v3 = *v2;
if ( *v2 )
{
v4 = 1LL;
if ( !*v3 )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) delete_fn(%p)\n",
"base2.c",
250LL,
a1,
v2,
v3,
0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 250LL, a1, v2, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 250LL, a1, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 250LL, 0LL);
v4 = 2LL;
}
result = my_rc_e_is_notok(v4);
if ( !(_BYTE)result )
result = ((__int64 (__fastcall *)(_QWORD ***))***a1)(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD ***a1)
{
_QWORD **v2; // r8
_QWORD *v3; // r9
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
v3 = *v2;
if ( *v2 )
{
v4 = 1LL;
if ( !*v3 )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) delete_fn(%p)\n",
"base2.c",
250LL,
a1,
v2,
v3,
0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 250LL, a1, v2, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 250LL, a1, 0LL);
v4 = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 250LL, 0LL);
v4 = 2LL;
}
result = my_rc_e_is_notok(v4);
if ( !(_BYTE)result )
result = ((__int64 (__fastcall *)(_QWORD ***))***a1)(a1);
return result;
}

original_code:
void
base2_delete (base2_handle base2_h)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 250,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 250,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 250,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->delete_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "delete_fn" "(%p)" "\n", "base2.c", 250,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->delete_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return;
    }
    return (base2_h->private_h->vtable->delete_fn(base2_h));
}

canonical_original_code:
void base2_delete(struct base2_st_ *base2_h)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 250,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 250,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 250,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->delete_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "delete_fn" "(%p)" "\n", "base2.c", 250,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->delete_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return;
    }
    return (base2_h->private_h->vtable->delete_fn(base2_h));
}


decompiled_code:
__int64 __fastcall base2_increase_val1(const void *a1)
{
_QWORD *v1; // r8
_QWORD *v2; // r9
unsigned int v3; // ebp

if ( a1 )
{
v1 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v2 = (_QWORD *)*v1;
if ( *v1 )
{
v3 = 1;
if ( !v2[4] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) increase_val1_fn(%p)\n",
"base2.c",
269LL,
a1,
v1,
v2,
0LL);
v3 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 269LL, a1, v1, 0LL);
v3 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 269LL, a1, 0LL);
v3 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 269LL, 0LL);
v3 = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok(v3) )
v3 = (*(__int64 (__fastcall **)(const void *))(**(_QWORD **)a1 + 32LL))(a1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(const void *a1)
{
_QWORD *v1; // r8
_QWORD *v2; // r9
unsigned int v3; // ebp

if ( a1 )
{
v1 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
v2 = (_QWORD *)*v1;
if ( *v1 )
{
v3 = 1;
if ( !v2[4] )
{
printf(
"(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p) increase_val1_fn(%p)\n",
"base2.c",
269LL,
a1,
v1,
v2,
0LL);
v3 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p) vtable(%p)\n", "base2.c", 269LL, a1, v1, 0LL);
v3 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) private_h(%p)\n", "base2.c", 269LL, a1, 0LL);
v3 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 269LL, 0LL);
v3 = 2;
}
if ( !(unsigned __int8)my_rc_e_is_notok(v3) )
v3 = (*(__int64 (__fastcall **)(const void *))(**(_QWORD **)a1 + 32LL))(a1);
return v3;
}

original_code:
my_rc_e
base2_increase_val1 (base2_handle base2_h)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 269,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 269,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 269,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->increase_val1_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "increase_val1_fn" "(%p)" "\n", "base2.c", 269,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->increase_val1_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    return (base2_h->private_h->vtable->increase_val1_fn(base2_h));
}

canonical_original_code:
enum my_rc_e_ base2_increase_val1(struct base2_st_ *base2_h)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    do { if (((void *)0) == base2_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p)" "\n", "base2.c", 269,base2_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p)" "\n", "base2.c", 269,base2_h, base2_h->private_h); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p)" "\n", "base2.c", 269,base2_h, base2_h->private_h, base2_h->private_h->vtable); } while (0); rc = MY_RC_E_EINVAL; break; } if (((void *)0) == base2_h->private_h->vtable->increase_val1_fn) { do { printf("(%s:%u) ERROR: " "Invalid input, " "base2_h" "(%p) " "private_h" "(%p) " "vtable" "(%p) " "increase_val1_fn" "(%p)" "\n", "base2.c", 269,base2_h, base2_h->private_h, base2_h->private_h->vtable, base2_h->private_h->vtable->increase_val1_fn); } while (0); rc = MY_RC_E_EINVAL; break; } } while (0);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    return (base2_h->private_h->vtable->increase_val1_fn(base2_h));
}


decompiled_code:
__int64 __fastcall base2_get_val1(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

if ( a1 && a2 )
{
*a2 = a1[2];
result = 1LL;
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) val1(%p)\n", "base2.c", 288LL, a1, a2);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

if ( a1 && a2 )
{
*a2 = a1[2];
result = 1LL;
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) val1(%p)\n", "base2.c", 288LL, a1, a2);
result = 2LL;
}
return result;
}

original_code:
my_rc_e
base2_get_val1 (base2_handle base2_h, uint32_t *val1)
{
    if ((((void *)0) == base2_h) || (((void *)0) == val1)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) val1(%p)" "\n", "base2.c", 288, base2_h, val1); } while (0);
        return (MY_RC_E_EINVAL);
    }
    *val1 = base2_h->val1;
    return (MY_RC_E_SUCCESS);
}

canonical_original_code:
enum my_rc_e_ base2_get_val1(struct base2_st_ *base2_h, unsigned int *val1)
{
    if ((((void *)0) == base2_h) || (((void *)0) == val1)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) val1(%p)" "\n", "base2.c", 288, base2_h, val1); } while (0);
        return (MY_RC_E_EINVAL);
    }
    *val1 = base2_h->val1;
    return (MY_RC_E_SUCCESS);
}


decompiled_code:
__int64 __fastcall base2_inherit_vtable(__int64 *a1, __int64 *a2, char a3)
{
__int64 result; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax

if ( a1 && a2 )
{
if ( *a2 || (v4 = *a1, *a2 = *a1, v4) || !a3 )
{
if ( a2[1] || (v5 = a1[1], (a2[1] = v5) != 0) || !a3 )
{
if ( a2[2] || (v6 = a1[2], (a2[2] = v6) != 0) || !a3 )
{
if ( a2[3] || (v7 = a1[3], (a2[3] = v7) != 0) || !a3 )
{
result = 1LL;
if ( !a2[4] )
{
v8 = a1[4];
a2[4] = v8;
if ( !v8 && a3 )
{
printf("(%s:%u) ERROR: Invalid input, increase_val1_fn(%p)\n", "base2.c", 343LL, 0LL);
result = 2LL;
}
else
{
result = 1LL;
}
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, string_size_fn(%p)\n", "base2.c", 341LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, string_fn(%p)\n", "base2.c", 339LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, type_string_fn(%p)\n", "base2.c", 337LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, delete_fn(%p)\n", "base2.c", 335LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, parent_vtable(%p) child_vtable(%p)\n", "base2.c", 330LL, a1, a2);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, __int64 *a2, char a3)
{
__int64 result; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax

if ( a1 && a2 )
{
if ( *a2 || (v4 = *a1, *a2 = *a1, v4) || !a3 )
{
if ( a2[1] || (v5 = a1[1], (a2[1] = v5) != 0) || !a3 )
{
if ( a2[2] || (v6 = a1[2], (a2[2] = v6) != 0) || !a3 )
{
if ( a2[3] || (v7 = a1[3], (a2[3] = v7) != 0) || !a3 )
{
result = 1LL;
if ( !a2[4] )
{
v8 = a1[4];
a2[4] = v8;
if ( !v8 && a3 )
{
printf("(%s:%u) ERROR: Invalid input, increase_val1_fn(%p)\n", "base2.c", 343LL, 0LL);
result = 2LL;
}
else
{
result = 1LL;
}
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, string_size_fn(%p)\n", "base2.c", 341LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, string_fn(%p)\n", "base2.c", 339LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, type_string_fn(%p)\n", "base2.c", 337LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, delete_fn(%p)\n", "base2.c", 335LL, 0LL);
result = 2LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, parent_vtable(%p) child_vtable(%p)\n", "base2.c", 330LL, a1, a2);
result = 2LL;
}
return result;
}

original_code:
my_rc_e
base2_inherit_vtable (const base2_vtable_st *parent_vtable,
                      base2_vtable_st *child_vtable,
                      _Bool do_null_check)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    extern char (*CT_ASSERT(void)) [sizeof(char[1 - 2*!(5 == (sizeof(base2_vtable_st)/sizeof(void*)))])];
    if ((((void *)0) == parent_vtable) || (((void *)0) == child_vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, parent_vtable(%p) " "child_vtable(%p)" "\n", "base2.c", 330, parent_vtable, child_vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    do { if (((void *)0) == child_vtable->delete_fn) { child_vtable->delete_fn = parent_vtable->delete_fn; if (do_null_check && (((void *)0) == child_vtable->delete_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "delete_fn" "(%p)" "\n", "base2.c", 335, child_vtable->delete_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->type_string_fn) { child_vtable->type_string_fn = parent_vtable->type_string_fn; if (do_null_check && (((void *)0) == child_vtable->type_string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "type_string_fn" "(%p)" "\n", "base2.c", 337, child_vtable->type_string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_fn) { child_vtable->string_fn = parent_vtable->string_fn; if (do_null_check && (((void *)0) == child_vtable->string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_fn" "(%p)" "\n", "base2.c", 339, child_vtable->string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_size_fn) { child_vtable->string_size_fn = parent_vtable->string_size_fn; if (do_null_check && (((void *)0) == child_vtable->string_size_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_size_fn" "(%p)" "\n", "base2.c", 341, child_vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->increase_val1_fn) { child_vtable->increase_val1_fn = parent_vtable->increase_val1_fn; if (do_null_check && (((void *)0) == child_vtable->increase_val1_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "increase_val1_fn" "(%p)" "\n", "base2.c", 343, child_vtable->increase_val1_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    return (MY_RC_E_SUCCESS);
err_exit:
    return (rc);
}

canonical_original_code:
enum my_rc_e_ base2_inherit_vtable(struct base2_vtable_st_ *parent_vtable, struct base2_vtable_st_ *child_vtable, _Bool do_null_check)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    extern char (*CT_ASSERT())[-1];
    if ((((void *)0) == parent_vtable) || (((void *)0) == child_vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, parent_vtable(%p) " "child_vtable(%p)" "\n", "base2.c", 330, parent_vtable, child_vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    do { if (((void *)0) == child_vtable->delete_fn) { child_vtable->delete_fn = parent_vtable->delete_fn; if (do_null_check && (((void *)0) == child_vtable->delete_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "delete_fn" "(%p)" "\n", "base2.c", 335, child_vtable->delete_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->type_string_fn) { child_vtable->type_string_fn = parent_vtable->type_string_fn; if (do_null_check && (((void *)0) == child_vtable->type_string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "type_string_fn" "(%p)" "\n", "base2.c", 337, child_vtable->type_string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_fn) { child_vtable->string_fn = parent_vtable->string_fn; if (do_null_check && (((void *)0) == child_vtable->string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_fn" "(%p)" "\n", "base2.c", 339, child_vtable->string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_size_fn) { child_vtable->string_size_fn = parent_vtable->string_size_fn; if (do_null_check && (((void *)0) == child_vtable->string_size_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_size_fn" "(%p)" "\n", "base2.c", 341, child_vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->increase_val1_fn) { child_vtable->increase_val1_fn = parent_vtable->increase_val1_fn; if (do_null_check && (((void *)0) == child_vtable->increase_val1_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "increase_val1_fn" "(%p)" "\n", "base2.c", 343, child_vtable->increase_val1_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    return (MY_RC_E_SUCCESS);
err_exit:
    return (rc);
}

variable_types: struct base2_vtable_st_ { void (*delete_fn)(struct base2_st_ { struct base2_private_st_ { struct base2_vtable_st_ *vtable; } *private_h; unsigned int val1; } *base2_h); char *(*type_string_fn)(struct base2_st_ *base2_h); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_fn)(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_size_fn)(struct base2_st_ *base2_h, unsigned long *buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*increase_val1_fn)(struct base2_st_ *base2_h); } *


decompiled_code:
__int64 __fastcall base2_set_vtable(__int64 ***a1, __int64 *a2)
{
unsigned int v2; // er12

if ( a1 && a2 )
{
if ( *a1 )
{
v2 = base2_inherit_vtable((__int64 *)base2_vtable, a2, 1);
if ( !(unsigned __int8)my_rc_e_is_notok(v2) )
{
**a1 = a2;
v2 = 1;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)->private_h(%p)\n", "base2.c", 373LL, a1, 0LL);
v2 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) vtable(%p)\n", "base2.c", 368LL, a1, a2);
v2 = 2;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 ***a1, __int64 *a2)
{
unsigned int v2; // er12

if ( a1 && a2 )
{
if ( *a1 )
{
v2 = func12((__int64 *)base2_vtable, a2, 1);
if ( !(unsigned __int8)my_rc_e_is_notok(v2) )
{
**a1 = a2;
v2 = 1;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)->private_h(%p)\n", "base2.c", 373LL, a1, 0LL);
v2 = 2;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) vtable(%p)\n", "base2.c", 368LL, a1, a2);
v2 = 2;
}
return v2;
}

original_code:
my_rc_e
base2_set_vtable (base2_handle base2_h, base2_vtable_st *vtable)
{
    my_rc_e rc;
    if ((((void *)0) == base2_h) || (((void *)0) == vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) vtable(%p)" "\n", "base2.c", 368, base2_h, vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    if (((void *)0) == base2_h->private_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)->private_h(%p)" "\n", "base2.c", 373, base2_h, base2_h->private_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    rc = base2_inherit_vtable(&base2_vtable, vtable, 1);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    base2_h->private_h->vtable = vtable;
    return (MY_RC_E_SUCCESS);
}

canonical_original_code:
enum my_rc_e_ base2_set_vtable(struct base2_st_ *base2_h, struct base2_vtable_st_ *vtable)
{
    enum my_rc_e_ rc;
    if ((((void *)0) == base2_h) || (((void *)0) == vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) vtable(%p)" "\n", "base2.c", 368, base2_h, vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    if (((void *)0) == base2_h->private_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)->private_h(%p)" "\n", "base2.c", 373, base2_h, base2_h->private_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    rc = base2_inherit_vtable(&base2_vtable, vtable, 1);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    base2_h->private_h->vtable = vtable;
    return (MY_RC_E_SUCCESS);
}

variable_types:
vtable
struct base2_vtable_st_ *


decompiled_code:
__int64 __fastcall base2_init(__int64 a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = calloc(1uLL, 8uLL);
*(_QWORD *)a1 = v1;
if ( v1 )
{
*v1 = base2_vtable;
*(_DWORD *)(a1 + 8) = 7;
result = 1LL;
}
else
{
result = 3LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 404LL, 0LL);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = calloc(1uLL, 8uLL);
*(_QWORD *)a1 = v1;
if ( v1 )
{
*v1 = base2_vtable;
*(_DWORD *)(a1 + 8) = 7;
result = 1LL;
}
else
{
result = 3LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 404LL, 0LL);
result = 2LL;
}
return result;
}

original_code:
my_rc_e
base2_init (base2_handle base2_h)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    if (((void *)0) == base2_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)" "\n", "base2.c", 404, base2_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    base2_h->private_h = calloc(1, sizeof(*base2_h->private_h));
    if (((void *)0) == base2_h->private_h) {
        rc = MY_RC_E_ENOMEM;
        goto err_exit;
    }
    base2_h->private_h->vtable = &base2_vtable;
    base2_h->val1 = 7;
    return (MY_RC_E_SUCCESS);
err_exit:
    if (((void *)0) != base2_h->private_h) {
        free(base2_h->private_h);
        base2_h->private_h = ((void *)0);
    }
    return (rc);
}

canonical_original_code:
enum my_rc_e_ base2_init(struct base2_st_ *base2_h)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    if (((void *)0) == base2_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)" "\n", "base2.c", 404, base2_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    base2_h->private_h = calloc(1, sizeof(*base2_h->private_h));
    if (((void *)0) == base2_h->private_h) {
        rc = MY_RC_E_ENOMEM;
        goto err_exit;
    }
    base2_h->private_h->vtable = &base2_vtable;
    base2_h->val1 = 7;
    return (MY_RC_E_SUCCESS);
err_exit:
    if (((void *)0) != base2_h->private_h) {
        free(base2_h->private_h);
        base2_h->private_h = ((void *)0);
    }
    return (rc);
}


decompiled_code:
bool __fastcall my_rc_e_is_notok(int a1)
{
return a1 != 1;
}

canonical_decompiled_code:
bool __fastcall func0(int a1)
{
return a1 != 1;
}

original_code:
_Bool
my_rc_e_is_notok (my_rc_e rc)
{
    return (MY_RC_E_SUCCESS != rc);
}

canonical_original_code:
_Bool my_rc_e_is_notok(enum my_rc_e_ rc)
{
    return (MY_RC_E_SUCCESS != rc);
}


decompiled_code:
bool __fastcall my_rc_e_is_ok(int a1)
{
return a1 == 1;
}

canonical_decompiled_code:
bool __fastcall func1(int a1)
{
return a1 == 1;
}

original_code:
_Bool
my_rc_e_is_ok (my_rc_e rc)
{
    return (MY_RC_E_SUCCESS == rc);
}

canonical_original_code:
_Bool my_rc_e_is_ok(enum my_rc_e_ rc)
{
    return (MY_RC_E_SUCCESS == rc);
}


decompiled_code:
bool __fastcall my_rc_e_is_valid(unsigned int a1)
{
return a1 <= 4;
}

canonical_decompiled_code:
bool __fastcall func2(unsigned int a1)
{
return a1 <= 4;
}

original_code:
_Bool
my_rc_e_is_valid (my_rc_e rc)
{
    return ((rc >= MY_RC_E_INVALID) && (rc <= MY_RC_E_MAX));
}

canonical_original_code:
_Bool my_rc_e_is_valid(enum my_rc_e_ rc)
{
    return ((rc >= MY_RC_E_INVALID) && (rc <= MY_RC_E_MAX));
}


decompiled_code:
const char *__fastcall my_rc_e_get_string(unsigned int a1)
{
bool v1; // dl
const char *result; // rax

v1 = my_rc_e_is_valid(a1);
result = "__Invalid__";
if ( v1 )
result = my_rc_e_string[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned int a1)
{
bool v1; // dl
const char *result; // rax

v1 = func2(a1);
result = "__Invalid__";
if ( v1 )
result = my_rc_e_string[a1];
return result;
}

original_code:
const char *
my_rc_e_get_string (my_rc_e rc)
{
    const char* retval = "__Invalid__";
    if (my_rc_e_is_valid(rc)) {
        retval = my_rc_e_string[rc];
    }
    return (retval);
}

canonical_original_code:
char *my_rc_e_get_string(enum my_rc_e_ rc)
{
    char *retval = "__Invalid__";
    if (my_rc_e_is_valid(rc)) {
        retval = my_rc_e_string[rc];
    }
    return (retval);
}

variable_types:
retval
char *


initialiseTime

repo: matthewpage/wavegen

decompiled_code:
struct tm *__fastcall initialiseTime(__int64 a1)
{
struct tm *v1; // rax
struct tm *result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF
int v4; // [rsp+14h] [rbp-14h] BYREF
int v5; // [rsp+18h] [rbp-10h] BYREF
int v6; // [rsp+1Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, "%d:%d:%d", &v6, &v5, &v4);
time(&timer);
v1 = localtime(&timer);
currentTime = v1;
v1->tm_hour = v6;
v1->tm_min = v5;
result = currentTime;
currentTime->tm_sec = v4;
return result;
}

canonical_decompiled_code:
struct tm *__fastcall func0(__int64 a1)
{
struct tm *v1; // rax
struct tm *result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF
int v4; // [rsp+14h] [rbp-14h] BYREF
int v5; // [rsp+18h] [rbp-10h] BYREF
int v6; // [rsp+1Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, "%d:%d:%d", &v6, &v5, &v4);
time(&timer);
v1 = localtime(&timer);
currentTime = v1;
v1->tm_hour = v6;
v1->tm_min = v5;
result = currentTime;
currentTime->tm_sec = v4;
return result;
}

original_code:
void initialiseTime(char* startTime) {
 int hour;
 int min;
 int sec;
 sscanf(startTime, "%d:%d:%d", &hour, &min, &sec);
 time_t tmpTime;
 time(&tmpTime);
 currentTime = localtime(&tmpTime);
 currentTime->tm_hour = hour;
 currentTime->tm_min = min;
 currentTime->tm_sec = sec;
}

canonical_original_code:
void initialiseTime(char *startTime) {
 int hour;
 int min;
 int sec;
 sscanf(startTime, "%d:%d:%d", &hour, &min, &sec);
 long tmpTime;
 time(&tmpTime);
 currentTime = localtime(&tmpTime);
 currentTime->tm_hour = hour;
 currentTime->tm_min = min;
 currentTime->tm_sec = sec;
}

variable_types:
startTime
char *

variable_types: hour int

variable_types: min int

variable_types: sec int

variable_types: tmpTime long


incrementTime

decompiled_code:
time_t __fastcall incrementTime(int a1)
{
currentTime->tm_sec += a1;
return mktime(currentTime);
}

canonical_decompiled_code:
time_t __fastcall func1(int a1)
{
currentTime->tm_sec += a1;
return mktime(currentTime);
}

original_code:
void incrementTime(int s) {
 currentTime->tm_sec += s;
 mktime(currentTime);
}

variable_types: s int


drawTimeLine

decompiled_code:
__int64 drawTimeLine()
{
unsigned int v0; // er13
unsigned int v1; // ebp
int v2; // er12
__int64 result; // rax
unsigned int v4; // ebx
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v0 = imageHeight - 10;
v1 = imageHeight - 22;
v2 = secondsPerTick * gConfig[14];
result = (unsigned int)(imageWidth + v2);
if ( (int)result > 0 )
{
v4 = 0;
do
{
gdImageLine(imageHandle, v4, v0, v4, (unsigned int)imageHeight, (unsigned int)textColour);
sprintf(
s,
"%02d:%02d:%02d",
(unsigned int)currentTime->tm_hour,
(unsigned int)currentTime->tm_min,
(unsigned int)currentTime->tm_sec);
gdImageString(imageHandle, fontHandle, v4 - 24, v1, s, (unsigned int)textColour);
incrementTime(secondsPerTick);
result = v4;
v4 += v2;
}
while ( imageWidth > (int)result );
}
imageHasChanged = 1;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er13
unsigned int v1; // ebp
int v2; // er12
__int64 result; // rax
unsigned int v4; // ebx
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v0 = imageHeight - 10;
v1 = imageHeight - 22;
v2 = secondsPerTick * gConfig[14];
result = (unsigned int)(imageWidth + v2);
if ( (int)result > 0 )
{
v4 = 0;
do
{
gdImageLine(imageHandle, v4, v0, v4, (unsigned int)imageHeight, (unsigned int)textColour);
sprintf(
s,
"%02d:%02d:%02d",
(unsigned int)currentTime->tm_hour,
(unsigned int)currentTime->tm_min,
(unsigned int)currentTime->tm_sec);
gdImageString(imageHandle, fontHandle, v4 - 24, v1, s, (unsigned int)textColour);
func1(secondsPerTick);
result = v4;
v4 += v2;
}
while ( imageWidth > (int)result );
}
imageHasChanged = 1;
return result;
}

original_code:
void drawTimeLine() {
 int lineHeight = imageHeight - 10;
 int textHeight = imageHeight - 22;
 int pixelsPerTick = gConfig.peaksPerSecond * secondsPerTick;
 int i;
 for (i = 0; i < (imageWidth + pixelsPerTick); i += pixelsPerTick) {
  int position = i;
  gdImageLine(imageHandle, position, lineHeight, position, imageHeight,
    textColour);
  char newTime[8];
  sprintf(newTime, "%02d:%02d:%02d", currentTime->tm_hour,
    currentTime->tm_min, currentTime->tm_sec);
  gdImageString(imageHandle, fontHandle, position - 24, textHeight,
    newTime, textColour);
  incrementTime(secondsPerTick);
 }
 imageHasChanged = 1;
}

variable_types: lineHeight int

variable_types: textHeight int

variable_types: pixelsPerTick int

variable_types: i int

variable_types: position int

variable_types:
newTime
char [8]


startImageFile

decompiled_code:
__int64 startImageFile()
{
debug(7LL, "Starting a new image file");
imageWidth = gConfig[15] * gConfig[14];
imageHandle = gdImageCreateTrueColor((unsigned int)imageWidth, (unsigned int)imageHeight);
fontHandle = gdFontGetSmall();
waveformColour = gdImageColorAllocate(imageHandle, 0LL, 255LL, 0LL);
textColour = gdImageColorAllocate(imageHandle, 255LL, 255LL, 255LL);
currentPixel = 0;
return drawTimeLine();
}

canonical_decompiled_code:
__int64 func4()
{
debug(7LL, "Starting a new image file");
imageWidth = gConfig[15] * gConfig[14];
imageHandle = gdImageCreateTrueColor((unsigned int)imageWidth, (unsigned int)imageHeight);
fontHandle = gdFontGetSmall();
waveformColour = gdImageColorAllocate(imageHandle, 0LL, 255LL, 0LL);
textColour = gdImageColorAllocate(imageHandle, 255LL, 255LL, 255LL);
currentPixel = 0;
return func2();
}

original_code:
void startImageFile() {
 debug(7, "Starting a new image file");
 imageWidth = gConfig.peaksPerSecond * gConfig.secondsPerFile;
 imageHandle = gdImageCreateTrueColor(imageWidth, imageHeight);
 fontHandle = gdFontGetSmall();
 waveformColour = gdImageColorAllocate(imageHandle, 0, 255, 0);
 textColour = gdImageColorAllocate(imageHandle, 255, 255, 255);
 currentPixel = 0;
 drawTimeLine();
}


endImageFile

decompiled_code:
time_t endImageFile()
{
debug(7LL, "Closing image file");
updateImageFile(1);
++currentFile;
return incrementTime(-secondsPerTick);
}

canonical_decompiled_code:
time_t func5()
{
debug(7LL, "Closing image file");
func3(1);
++currentFile;
return func1(-secondsPerTick);
}

original_code:
void endImageFile() {
 debug(7, "Closing image file");
 updateImageFile(1);
 currentFile++;
 incrementTime(-secondsPerTick);
}


defaultConfig

original_code:
static void defaultConfig()
{
 gConfig.inputFile = "";
 gConfig.outputPath = "";
 gConfig.baseFileName = "waveform_";
 gConfig.startTime = "00:00:00";
 gConfig.peaksPerSecond = 16;
 gConfig.secondsPerFile = 300;
 gConfig.sampleRate = 44100;
 gConfig.channels = 1;
 gConfig.fileStartOffset = 0;
 gConfig.waitTime = 1;
 gConfig.timesToCheck = 5;
}


debug

decompiled_code:
int debug(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( debugLevel >= a1 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
result = fflush(stderr);
}
return result;
}

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

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( debugLevel >= a1 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
result = fflush(stderr);
}
return result;
}

original_code:
void debug(int level, const char * template, ...)
{
 va_list ap;
 __builtin_va_start(ap,template);
 if (debugLevel < level) return;
 vfprintf(stderr, template, ap);
 fprintf(stderr,"\n");
 fflush(stderr);
 __builtin_va_end(ap);
 return;
}

canonical_original_code:
void debug(int level, char *template, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,template);
 if (debugLevel < level) return;
 vfprintf(stderr, template, ap);
 fprintf(stderr,"\n");
 fflush(stderr);
 __builtin_va_end(ap);
 return;
}

variable_types: level int

variable_types:
template
char *