original_code:
fix16_t fix16_mul(fix16_t inArg0, fix16_t inArg1)
{
  int64_t product = (int64_t)inArg0 * inArg1;
  uint32_t upper = (product >> 47);
  if (product < 0)
  {
    if (~upper)
        return fix16_overflow;
    product--;
  }
  else
  {
    if (upper)
        return fix16_overflow;
  }
  fix16_t result = product >> 16;
  result += (product & 0x8000) >> 15;
  return result;
}

canonical_original_code:
int fix16_mul(int inArg0, int inArg1)
{
  long product = (int64_t)inArg0 * inArg1;
  unsigned int upper = (product >> 47);
  if (product < 0)
  {
    if (~upper)
        return fix16_overflow;
    product--;
  }
  else
  {
    if (upper)
        return fix16_overflow;
  }
  int result = product >> 16;
  result += (product & 0x8000) >> 15;
  return result;
}

variable_types: product long

variable_types:
upper
unsigned int


repo: tehn/aleph

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

result = fix16_mul(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != v3 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

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

result = func8(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != v3 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_smul(fix16_t inArg0, fix16_t inArg1) {
  fix16_t result = fix16_mul(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}

canonical_original_code:
int fix16_smul(int inArg0, int inArg1) {
  int result = fix16_mul(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}

variable_types: result int

return_type: int


original_code:
fix16_t fix16_div(fix16_t a, fix16_t b)
{
  if (b == 0)
      return fix16_min;
  uint32_t remainder = (a >= 0) ? a : (-a);
  uint32_t divider = (b >= 0) ? b : (-b);
  uint32_t quotient = 0;
  int bit_pos = 17;
  if (divider & 0xFFF00000)
  {
    uint32_t shifted_div = ((divider >> 17) + 1);
    quotient = remainder / shifted_div;
    remainder -= ((uint64_t)quotient * divider) >> 17;
  }
  while (!(divider & 0xF) && bit_pos >= 4)
  {
    divider >>= 4;
    bit_pos -= 4;
  }
  while (remainder && bit_pos >= 0)
  {
    int shift = __builtin_clzl(remainder);
    if (shift > bit_pos) shift = bit_pos;
    remainder <<= shift;
    bit_pos -= shift;
    uint32_t div = remainder / divider;
    remainder = remainder % divider;
    quotient += div << bit_pos;
    if (div & ~(0xFFFFFFFF >> bit_pos))
        return fix16_overflow;
    remainder <<= 1;
    bit_pos--;
  }
  quotient++;
  fix16_t result = quotient >> 1;
  if ((a ^ b) & 0x80000000)
  {
    if (result == fix16_min)
        return fix16_overflow;
    result = -result;
  }
  return result;
}

canonical_original_code:
int fix16_div(int a, int b)
{
  if (b == 0)
      return fix16_min;
  unsigned int remainder = (a >= 0) ? a : (-a);
  unsigned int divider = (b >= 0) ? b : (-b);
  unsigned int quotient = 0;
  int bit_pos = 17;
  if (divider & 0xFFF00000)
  {
    unsigned int shifted_div = ((divider >> 17) + 1);
    quotient = remainder / shifted_div;
    remainder -= ((unsigned long)quotient * divider) >> 17;
  }
  while (!(divider & 0xF) && bit_pos >= 4)
  {
    divider >>= 4;
    bit_pos -= 4;
  }
  while (remainder && bit_pos >= 0)
  {
    int shift = __builtin_clzl(remainder);
    if (shift > bit_pos) shift = bit_pos;
    remainder <<= shift;
    bit_pos -= shift;
    unsigned int div = remainder / divider;
    remainder = remainder % divider;
    quotient += div << bit_pos;
    if (div & ~(0xFFFFFFFF >> bit_pos))
        return fix16_overflow;
    remainder <<= 1;
    bit_pos--;
  }
  quotient++;
  int result = quotient >> 1;
  if ((a ^ b) & 0x80000000)
  {
    if (result == fix16_min)
        return fix16_overflow;
    result = -result;
  }
  return result;
}

variable_types: a int

variable_types: b int

variable_types:
remainder
unsigned int

variable_types:
divider
unsigned int

variable_types:
quotient
unsigned int

variable_types: shift int

variable_types:
div
unsigned int


decompiled_code:
__int64 __fastcall fix16_sdiv(int a1, int a2)
{
__int64 result; // rax

result = fix16_div(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

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

result = func10(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1) {
  fix16_t result = fix16_div(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}

canonical_original_code:
int fix16_sdiv(int inArg0, int inArg1) {
  int result = fix16_div(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}


original_code:
fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract) {
 int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -8);
 return (fix16_t)int64_lo(tempOut);
}

canonical_original_code:
int fix16_lerp8(int inArg0, int inArg1, unsigned char inFract) {
 long tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -8);
 return (int)int64_lo(tempOut);
}

variable_types:
inFract
unsigned char

variable_types: tempOut long


original_code:
fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract) {
 int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -16);
 return (fix16_t)int64_lo(tempOut);
}

canonical_original_code:
int fix16_lerp16(int inArg0, int inArg1, unsigned short inFract) {
 long tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -16);
 return (int)int64_lo(tempOut);
}

variable_types:
inFract
unsigned short


decompiled_code:
__int64 __fastcall fix16_lerp32(int a1, int a2, unsigned int a3)
{
return (__int64)(a2 * (unsigned __int64)a3 + -a3 * (__int64)a1) >> 32;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, unsigned int a3)
{
return (__int64)(a2 * (unsigned __int64)a3 + -a3 * (__int64)a1) >> 32;
}

original_code:
fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract) {
 int64_t tempOut;
 tempOut = ((int64_t)inArg0 * (0 - inFract));
 tempOut += ((int64_t)inArg1 * inFract);
 tempOut >>= 32;
 return (fix16_t)tempOut;
}

canonical_original_code:
int fix16_lerp32(int inArg0, int inArg1, unsigned int inFract) {
 long tempOut;
 tempOut = ((long)inArg0 * (0 - inFract));
 tempOut += ((long)inArg1 * inFract);
 tempOut >>= 32;
 return (int)tempOut;
}

variable_types:
inFract
unsigned int


decompiled_code:
__int64 __fastcall handle_MonomeGridKey(unsigned int a1)
{
return monome_grid_key_handler(monomeOpFocus, a1);
}

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

original_code:
static void handle_MonomeGridKey(s32 data) {
  (*monome_grid_key_handler)(monomeOpFocus, data);
}

canonical_original_code:
static void handle_MonomeGridKey(int data) {
  (*monome_grid_key_handler)(monomeOpFocus, data);
}

variable_types: data int

return_type: void


decompiled_code:
void handle_MonomeGridTilt()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static void handle_MonomeGridTilt(s32 data) {
}

canonical_original_code:
static void handle_MonomeGridTilt(int data) {
}


decompiled_code:
__int64 __fastcall handle_MonomeRingEnc(unsigned int a1)
{
return monome_ring_enc_handler(monomeOpFocus, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return monome_ring_enc_handler(monomeOpFocus, a1);
}

original_code:
static void handle_MonomeRingEnc(s32 data) {
  (*monome_ring_enc_handler)(monomeOpFocus, data);
}

canonical_original_code:
static void handle_MonomeRingEnc(int data) {
  (*monome_ring_enc_handler)(monomeOpFocus, data);
}


decompiled_code:
// attributes: thunk
__int64 handle_MidiPacket()
{
return net_handle_midi_packet();
}

canonical_decompiled_code:
__int64 func3()
{
return net_handle_midi_packet();
}

original_code:
static void handle_MidiPacket(s32 data) {
  net_handle_midi_packet(data);
}

canonical_original_code:
static void handle_MidiPacket(int data) {
  net_handle_midi_packet(data);
}


decompiled_code:
// attributes: thunk
__int64 handle_MidiDisconnect()
{
return timers_unset_midi();
}

canonical_decompiled_code:
__int64 func4()
{
return timers_unset_midi();
}

original_code:
static void handle_MidiDisconnect(s32 data) {
  timers_unset_midi();
}

canonical_original_code:
static void handle_MidiDisconnect(int data) {
  timers_unset_midi();
}


decompiled_code:
// attributes: thunk
__int64 handle_MidiConnect()
{
return timers_set_midi();
}

canonical_decompiled_code:
__int64 func5()
{
return timers_set_midi();
}

original_code:
static void handle_MidiConnect(s32 data) {
  timers_set_midi();
}

canonical_original_code:
static void handle_MidiConnect(int data) {
  timers_set_midi();
}


decompiled_code:
// attributes: thunk
__int64 handle_MonomeDisconnect()
{
return timers_unset_monome();
}

canonical_decompiled_code:
__int64 func6()
{
return timers_unset_monome();
}

original_code:
static void handle_MonomeDisconnect(s32 data) {
  timers_unset_monome();
}

canonical_original_code:
static void handle_MonomeDisconnect(int data) {
  timers_unset_monome();
}


decompiled_code:
// attributes: thunk
__int64 handle_MonomeConnect()
{
return timers_set_monome();
}

canonical_decompiled_code:
__int64 func7()
{
return timers_set_monome();
}

original_code:
static void handle_MonomeConnect(s32 data) {
  timers_set_monome();
}

canonical_original_code:
static void handle_MonomeConnect(int data) {
  timers_set_monome();
}


decompiled_code:
__int64 __fastcall handle_Switch7(int a1)
{
return op_sw_sys_input(opSysSw[5], a1 > 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return op_sw_sys_input(opSysSw[5], a1 > 0);
}

original_code:
static void handle_Switch7(s32 data) {
  op_sw_sys_input(opSysSw[5], data > 0);
}

canonical_original_code:
static void handle_Switch7(int data) {
  op_sw_sys_input(opSysSw[5], data > 0);
}


decompiled_code:
__int64 __fastcall handle_Switch6(int a1)
{
return op_sw_sys_input(opSysSw[4], a1 > 0);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return op_sw_sys_input(opSysSw[4], a1 > 0);
}

original_code:
static void handle_Switch6(s32 data) {
  op_sw_sys_input(opSysSw[4], data > 0);
}

canonical_original_code:
static void handle_Switch6(int data) {
  op_sw_sys_input(opSysSw[4], data > 0);
}


decompiled_code:
__int64 handle_Switch5()
{
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot("powering down");
return delay_ms(100LL);
}

canonical_decompiled_code:
__int64 func10()
{
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot(&unk_3E0);
render_boot("powering down");
return delay_ms(100LL);
}

original_code:
static void handle_Switch5(s32 data) {
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("powering down");
  delay_ms(100);
}

canonical_original_code:
static void handle_Switch5(int data) {
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("powering down");
  delay_ms(100);
}


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

if ( a1 > 0 )
result = pages_toggle_play();
return result;
}

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

if ( a1 > 0 )
result = pages_toggle_play();
return result;
}

original_code:
static void handle_Switch4(s32 data) {
  if(data > 0) {
    if(pages_toggle_play()) {
    } else {
    }
  }
}

canonical_original_code:
static void handle_Switch4(int data) {
  if(data > 0) {
    if(pages_toggle_play()) {
    } else {
    }
  }
}


decompiled_code:
__int64 __fastcall handle_Adc3(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 3LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 3LL, a1);
}

original_code:
static void handle_Adc3(s32 data) {
  op_adc_sys_input(opSysAdc, 3, data);}

canonical_original_code:
static void handle_Adc3(int data) {
  op_adc_sys_input(opSysAdc, 3, data);}


decompiled_code:
__int64 __fastcall handle_Adc2(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 2LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 2LL, a1);
}

original_code:
static void handle_Adc2(s32 data) {
  op_adc_sys_input(opSysAdc, 2, data);
}

canonical_original_code:
static void handle_Adc2(int data) {
  op_adc_sys_input(opSysAdc, 2, data);
}


decompiled_code:
__int64 __fastcall handle_Adc1(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 1LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 1LL, a1);
}

original_code:
static void handle_Adc1(s32 data) {
  op_adc_sys_input(opSysAdc, 1, data);
}

canonical_original_code:
static void handle_Adc1(int data) {
  op_adc_sys_input(opSysAdc, 1, data);
}


decompiled_code:
__int64 __fastcall handle_Adc0(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int16 a1)
{
return op_adc_sys_input(opSysAdc, 0LL, a1);
}

original_code:
static void handle_Adc0(s32 data) {
  op_adc_sys_input(opSysAdc, 0, data);
}

canonical_original_code:
static void handle_Adc0(int data) {
  op_adc_sys_input(opSysAdc, 0, data);
}


decompiled_code:
void handle_HidByte()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
static void handle_HidByte(s32 data) {
}

canonical_original_code:
static void handle_HidByte(int data) {
}


decompiled_code:
void handle_HidDisconnect()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
static void handle_HidDisconnect(s32 data) {
}

canonical_original_code:
static void handle_HidDisconnect(int data) {
}


decompiled_code:
void handle_HidConnect()
{
;
}

canonical_decompiled_code:
void func19()
{
;
}

original_code:
static void handle_HidConnect(s32 data) {
}

canonical_original_code:
static void handle_HidConnect(int data) {
}


decompiled_code:
void handle_MonomeRingKey()
{
;
}

canonical_decompiled_code:
void func20()
{
;
}

original_code:
static void handle_MonomeRingKey(s32 data) {
}

canonical_original_code:
static void handle_MonomeRingKey(int data) {
}


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

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

original_code:
io_t scale_knob_value_small(io_t val) {
  return val;
}

canonical_original_code:
short scale_knob_value_small(short val) {
  return val;
}

variable_types: val short

return_type: short


decompiled_code:
__int64 __fastcall scale_knob_value(__int16 a1)
{
__int64 result; // rax
unsigned int v2; // edi
__int64 v3; // rdi
int v4; // edx

if ( a1 < 0 )
{
result = 4294965504LL;
v2 = (__int16)-a1;
if ( v2 <= 0x17 )
{
v3 = (int)(v2 - 1);
v4 = knobScale_1[v3];
LOWORD(v4) = (__int16)v4 >> 15;
result = v4 - (v4 ^ (unsigned int)knobScale_1[v3]);
}
}
else
{
result = 1792LL;
if ( a1 <= 23 )
result = LOWORD(knobScale_1[(__int16)(a1 - 1)]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int16 a1)
{
__int64 result; // rax
unsigned int v2; // edi
__int64 v3; // rdi
int v4; // edx

if ( a1 < 0 )
{
result = 4294965504LL;
v2 = (__int16)-a1;
if ( v2 <= 0x17 )
{
v3 = (int)(v2 - 1);
v4 = knobScale_1[v3];
LOWORD(v4) = (__int16)v4 >> 15;
result = v4 - (v4 ^ (unsigned int)knobScale_1[v3]);
}
}
else
{
result = 1792LL;
if ( a1 <= 23 )
result = LOWORD(knobScale_1[(__int16)(a1 - 1)]);
}
return result;
}

variable_types:
knobScale
unsigned int [24]

variable_types: vabs short

variable_types: ret short


decompiled_code:
__int64 __fastcall scale_knob_value_fast(__int16 a1)
{
__int64 result; // rax
unsigned int v2; // edi
__int64 v3; // rdi
int v4; // edx

if ( a1 < 0 )
{
result = 4294938624LL;
v2 = (__int16)-a1;
if ( v2 <= 0x17 )
{
v3 = (int)(v2 - 1);
v4 = knobScale_0[v3];
LOWORD(v4) = (__int16)v4 >> 15;
result = v4 - (v4 ^ (unsigned int)knobScale_0[v3]);
}
}
else
{
result = 28672LL;
if ( a1 <= 23 )
result = LOWORD(knobScale_0[(__int16)(a1 - 1)]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int16 a1)
{
__int64 result; // rax
unsigned int v2; // edi
__int64 v3; // rdi
int v4; // edx

if ( a1 < 0 )
{
result = 4294938624LL;
v2 = (__int16)-a1;
if ( v2 <= 0x17 )
{
v3 = (int)(v2 - 1);
v4 = knobScale_0[v3];
LOWORD(v4) = (__int16)v4 >> 15;
result = v4 - (v4 ^ (unsigned int)knobScale_0[v3]);
}
}
else
{
result = 28672LL;
if ( a1 <= 23 )
result = LOWORD(knobScale_0[(__int16)(a1 - 1)]);
}
return result;
}


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

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

original_code: static inline int64_t int64_from_int32(int32_t x) { return (int64_t)x; }

canonical_original_code: static inline long int64_from_int32(int x) { return (long)x; }

variable_types: x int

return_type: long


decompiled_code:
__int64 __fastcall int64_lo(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1;
}

original_code: static inline uint32_t int64_lo(int64_t x) { return (x & ((1ULL << 32) - 1)); }

canonical_original_code: static inline unsigned int int64_lo(long x) { return (x & ((1ULL << 32) - 1)); }

variable_types: x long

return_type: unsigned int


decompiled_code:
__int64 __fastcall int64_add(__int64 a1, __int64 a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return a1 + a2;
}

original_code: static inline int64_t int64_add(int64_t x, int64_t y) { return (x + y); }

canonical_original_code: static inline long int64_add(long x, long y) { return (x + y); }

variable_types: y long


decompiled_code:
__int64 __fastcall int64_mul_i64_i32(__int64 a1, int a2)
{
return a1 * a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return a1 * a2;
}

original_code: static inline int64_t int64_mul_i64_i32(int64_t x, int32_t y) { return (x * y); }

canonical_original_code: static inline long int64_mul_i64_i32(long x, int y) { return (x * y); }

variable_types: y int


decompiled_code:
__int64 __fastcall int64_div_i64_i32(__int64 a1, int a2)
{
return a1 / a2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return a1 / a2;
}

original_code: static inline int64_t int64_div_i64_i32(int64_t x, int32_t y) { return (x / y); }

canonical_original_code: static inline long int64_div_i64_i32(long x, int y) { return (x / y); }


decompiled_code:
__int64 __fastcall fix16_exp(int a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // r8
__int64 v5; // r8
__int64 v6; // rax
__int64 v7; // r11
__int64 v8; // rax
int v9; // er10
int v10; // esi
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // r9
__int64 v14; // rax
int v15; // ecx

result = 0x10000LL;
if ( a1 )
{
if ( a1 == 0x10000 )
{
result = 178145LL;
}
else
{
result = 0x7FFFFFFFLL;
if ( a1 <= 681391 )
{
result = 0LL;
if ( a1 >= -726817 )
{
v2 = ((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF;
if ( fix16_exp_cache_index[v2] == a1 )
{
result = (unsigned int)fix16_exp_cache_value[v2];
}
else
{
int64_from_int32(a1);
v3 = int64_from_int32(0x10000);
int64_add(v3, v4);
int64_from_int32(0x8000);
do
{
v6 = int64_mul_i64_i32(v5, a1);
v8 = int64_add(v6, v7);
v10 = v9;
v11 = int64_shift_constprop_0(v8);
v12 = int64_div_i64_i32(v11, v10);
v14 = int64_add(v13, v12);
}
while ( v15 != 13 );
fix16_exp_cache_index[v2] = a1;
result = int64_lo(v14);
fix16_exp_cache_value[v2] = result;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // r8
__int64 v5; // r8
__int64 v6; // rax
__int64 v7; // r11
__int64 v8; // rax
int v9; // er10
int v10; // esi
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // r9
__int64 v14; // rax
int v15; // ecx

result = 0x10000LL;
if ( a1 )
{
if ( a1 == 0x10000 )
{
result = 178145LL;
}
else
{
result = 0x7FFFFFFFLL;
if ( a1 <= 681391 )
{
result = 0LL;
if ( a1 >= -726817 )
{
v2 = ((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 4)) & 0xFFF;
if ( fix16_exp_cache_index[v2] == a1 )
{
result = (unsigned int)fix16_exp_cache_value[v2];
}
else
{
func0(a1);
v3 = func0(0x10000);
func2(v3, v4);
func0(0x8000);
do
{
v6 = func3(v5, a1);
v8 = func2(v6, v7);
v10 = v9;
v11 = func5(v8);
v12 = func4(v11, v10);
v14 = func2(v13, v12);
}
while ( v15 != 13 );
fix16_exp_cache_index[v2] = a1;
result = func1(v14);
fix16_exp_cache_value[v2] = result;
}
}
}
}
}
return result;
}

original_code:
fix16_t fix16_exp(fix16_t inValue) {
 if(inValue == 0)
  return fix16_one;
 if(inValue == fix16_one)
  return fix16_e;
 if(inValue > 681391)
  return fix16_max;
 if(inValue < -726817)
  return 0;
 fix16_t tempIndex = (inValue ^ (inValue >> 16));
 tempIndex = (inValue ^ (inValue >> 4)) & 0x0FFF;
 if(_fix16_exp_cache_index[tempIndex] == inValue)
  return _fix16_exp_cache_value[tempIndex];
 int64_t tempOut = int64_add(int64_from_int32(fix16_one), int64_from_int32(inValue));
 int64_t tempValue = int64_from_int32(inValue);
 uint32_t i, n;
 for(i = 3, n = 2; i < 13; n *= i, i++) {
  tempValue = int64_mul_i64_i32(tempValue, inValue);
  tempValue = int64_add(tempValue, int64_from_int32(fix16_one >> 1));
  tempValue = int64_shift(tempValue, -16);
  tempOut = int64_add(tempOut, int64_div_i64_i32(tempValue, n));
 }
 _fix16_exp_cache_index[tempIndex] = inValue;
 _fix16_exp_cache_value[tempIndex] = int64_lo(tempOut);
 return int64_lo(tempOut);
}

canonical_original_code:
int fix16_exp(int inValue) {
 if(inValue == 0)
  return fix16_one;
 if(inValue == fix16_one)
  return fix16_e;
 if(inValue > 681391)
  return fix16_max;
 if(inValue < -726817)
  return 0;
 int tempIndex = (inValue ^ (inValue >> 16));
 tempIndex = (inValue ^ (inValue >> 4)) & 0x0FFF;
 if(_fix16_exp_cache_index[tempIndex] == inValue)
  return _fix16_exp_cache_value[tempIndex];
 long tempOut = int64_add(int64_from_int32(fix16_one), int64_from_int32(inValue));
 long tempValue = int64_from_int32(inValue);
 unsigned int i; unsigned int n;
 for(i = 3, n = 2; i < 13; n *= i, i++) {
  tempValue = int64_mul_i64_i32(tempValue, inValue);
  tempValue = int64_add(tempValue, int64_from_int32(fix16_one >> 1));
  tempValue = int64_shift(tempValue, -16);
  tempOut = int64_add(tempOut, int64_div_i64_i32(tempValue, n));
 }
 _fix16_exp_cache_index[tempIndex] = inValue;
 _fix16_exp_cache_value[tempIndex] = int64_lo(tempOut);
 return int64_lo(tempOut);
}

variable_types: inValue int

variable_types: tempIndex int

variable_types: tempValue long

variable_types:
i
unsigned int

variable_types:
n
unsigned int


decompiled_code:
__int64 __fastcall list_get_name(__int64 a1, __int16 a2)
{
return ((32 * a2) & 0x1FE0) + a1 + 64;
}

original_code:
const char* list_get_name(dirList_t* list, u8 idx) {
  return (const char*) ( list->nameBuf + (idx * 32) );
}

canonical_original_code:
char *list_get_name(struct _dirList *list, unsigned char idx) {
  return (char *) ( list->nameBuf + (idx * 32) );
}

variable_types: struct _dirList { char path[64]; char nameBuf[1024]; unsigned int num; } *

variable_types:
idx
unsigned char

return_type: char *


decompiled_code:
bool __fastcall check_ext(const char *a1, const char *a2)
{
int v2; // edx
__int64 v3; // rax
const char *v4; // rdi
bool result; // al

v2 = strlen(a1);
v3 = (__int64)&a1[v2 - 1];
while ( v2 > 0 )
{
v4 = (const char *)v3--;
--v2;
if ( *(_BYTE *)(v3 + 1) == 46 )
return (unsigned __int8)strcmp(v4, a2) == 0;
}
result = 0;
if ( v2 )
return result;
v4 = 0LL;
return (unsigned __int8)strcmp(v4, a2) == 0;
}

canonical_decompiled_code:
bool __fastcall func1(const char *a1, const char *a2)
{
int v2; // edx
__int64 v3; // rax
const char *v4; // rdi
bool result; // al

v2 = strlen(a1);
v3 = (__int64)&a1[v2 - 1];
while ( v2 > 0 )
{
v4 = (const char *)v3--;
--v2;
if ( *(_BYTE *)(v3 + 1) == 46 )
return (unsigned __int8)strcmp(v4, a2) == 0;
}
result = 0;
if ( v2 )
return result;
v4 = 0LL;
return (unsigned __int8)strcmp(v4, a2) == 0;
}

original_code:
bool check_ext(char* str, const char* extB ) {
  int i;
  char* extA = ((void *)0);
  bool res;
  i = strlen(str);
  while(i > 0) {
    --i;
    if(str[i] == '.') {
      extA = str + i;
      break;
    }
  }
  if(i < 0) {
    return 0;
  } else {
    res = strcmp(extA, extB);
    if(res == 0) { return 1; } else { return 0; }
  }
}

canonical_original_code:
unsigned char check_ext(char *str, char *extB) {
  int i;
  char *extA = ((void *)0);
  unsigned char res;
  i = strlen(str);
  while(i > 0) {
    --i;
    if(str[i] == '.') {
      extA = str + i;
      break;
    }
  }
  if(i < 0) {
    return 0;
  } else {
    res = strcmp(extA, extB);
    if(res == 0) { return 1; } else { return 0; }
  }
}

variable_types:
str
char *

variable_types:
extB
char *

variable_types: i int

variable_types:
extA
char *

variable_types:
res
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall strip_ext(const char *a1)
{
int v1; // edx
__int64 v2; // rax
_BYTE *v3; // rcx

v1 = strlen(a1);
v2 = (__int64)&a1[v1 - 1];
do
{
if ( v1 <= 0 )
return 0LL;
v3 = (_BYTE *)v2--;
--v1;
}
while ( *(_BYTE *)(v2 + 1) != 46 );
*v3 = 0;
return 1LL;
}

original_code:
bool strip_ext(char* str) {
  int i;
  int dotpos = -1;
  i = strlen(str);
  while(i > 0) {
    --i;
    if(str[i] == '.') {
      dotpos = i;
      break;
    }
  }
  if(dotpos >= 0) {
    str[dotpos] = '\0';
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
unsigned char strip_ext(char *str) {
  int i;
  int dotpos = -1;
  i = strlen(str);
  while(i > 0) {
    --i;
    if(str[i] == '.') {
      dotpos = i;
      break;
    }
  }
  if(dotpos >= 0) {
    str[dotpos] = '\0';
    return 1;
  } else {
    return 0;
  }
}

variable_types: dotpos int


decompiled_code:
__int64 files_init()
{
return print_dbg("\r\n BEES file_init, scanning directories..");
}

canonical_decompiled_code:
__int64 func3()
{
return print_dbg("\r\n BEES file_init, scanning directories..");
}

original_code:
void files_init(void) {
  print_dbg("\r\n BEES file_init, scanning directories..");
  list_scan(&dspList, "/mod/");
  list_scan(&sceneList, "/data/bees/scenes/");
  list_scan(&scalerList, "/data/bees/scalers/");
}

canonical_original_code:
void files_init() {
  print_dbg("\r\n BEES file_init, scanning directories..");
  list_scan(&dspList, "/mod/");
  list_scan(&sceneList, "/data/bees/scenes/");
  list_scan(&scalerList, "/data/bees/scalers/");
}


decompiled_code:
__int64 __fastcall files_get_dsp_name(unsigned __int8 a1)
{
return list_get_name((__int64)&dspList, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
return func0((__int64)&dspList, a1);
}

original_code:
const volatile char* files_get_dsp_name(u8 idx) {
  return list_get_name(&dspList, idx);
}

canonical_original_code:
char *files_get_dsp_name(unsigned char idx) {
  return list_get_name(&dspList, idx);
}


decompiled_code:
__int64 __fastcall files_load_dsp(unsigned __int8 a1)
{
char *v1; // rax

v1 = (char *)files_get_dsp_name(a1);
return files_load_dsp_name(v1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
char *v1; // rax

v1 = (char *)func4(a1);
return func5(v1);
}

original_code:
u8 files_load_dsp(u8 idx) {
  return files_load_dsp_name((const char*)files_get_dsp_name(idx));
}

canonical_original_code:
unsigned char files_load_dsp(unsigned char idx) {
  return files_load_dsp_name((char *)files_get_dsp_name(idx));
}


decompiled_code:
__int64 files_get_dsp_count()
{
return (unsigned __int8)byte_10C0;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int8)byte_10C0;
}

original_code:
u8 files_get_dsp_count(void) {
  return dspList.num;
}

canonical_original_code:
unsigned char files_get_dsp_count() {
  return dspList.num;
}


decompiled_code:
__int64 __fastcall files_get_scene_name(unsigned __int8 a1)
{
return list_get_name((__int64)&sceneList, a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1)
{
return func0((__int64)&sceneList, a1);
}

original_code:
const volatile char* files_get_scene_name(u8 idx) {
  return list_get_name(&sceneList, idx);
}

canonical_original_code:
char *files_get_scene_name(unsigned char idx) {
  return list_get_name(&sceneList, idx);
}


decompiled_code:
__int64 __fastcall files_load_scene(unsigned __int8 a1)
{
char *v1; // rax

v1 = (char *)files_get_scene_name(a1);
return files_load_scene_name(v1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
char *v1; // rax

v1 = (char *)func8(a1);
return func9(v1);
}

original_code:
u8 files_load_scene(u8 idx) {
  return files_load_scene_name((const char*)files_get_scene_name(idx));
}

canonical_original_code:
unsigned char files_load_scene(unsigned char idx) {
  return files_load_scene_name((char *)files_get_scene_name(idx));
}


decompiled_code:
int __fastcall files_store_scene(unsigned __int8 a1)
{
const char *v1; // rax

v1 = (const char *)files_get_scene_name(a1);
return files_store_scene_name(v1);
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int8 a1)
{
const char *v1; // rax

v1 = (const char *)func8(a1);
return func11(v1);
}

original_code:
void files_store_scene(u8 idx) {
  files_store_scene_name((const char*)files_get_scene_name(idx));
}

canonical_original_code:
void files_store_scene(unsigned char idx) {
  files_store_scene_name((char *)files_get_scene_name(idx));
}


decompiled_code:
__int64 files_get_scene_count()
{
return (unsigned __int8)byte_C60;
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned __int8)byte_C60;
}

original_code:
u8 files_get_scene_count(void) {
  return sceneList.num;
}

canonical_original_code:
unsigned char files_get_scene_count() {
  return sceneList.num;
}


decompiled_code:
__int64 __fastcall files_get_scaler_name(unsigned __int8 a1)
{
return list_get_name((__int64)&scalerList, a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 a1)
{
return func0((__int64)&scalerList, a1);
}

original_code:
const volatile char* files_get_scaler_name(u8 idx) {
  return list_get_name(&scalerList, idx);
}

canonical_original_code:
char *files_get_scaler_name(unsigned char idx) {
  return list_get_name(&scalerList, idx);
}


decompiled_code:
__int64 files_load_scaler_name()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
return 0LL;
}

original_code:
u8 files_load_scaler_name(const char* name, s32* dst, u32 dstSize) {
  return 0;
}

canonical_original_code:
unsigned char files_load_scaler_name(char *name, int *dst, unsigned int dstSize) {
  return 0;
}

variable_types:
name
char *

variable_types:
dst
int *

variable_types:
dstSize
unsigned int


decompiled_code:
char __fastcall strip_filename(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // rax
char v3; // dl

LOBYTE(v2) = a2 - 1;
if ( a2 != 1 )
{
v2 = (unsigned __int8)v2;
do
{
v3 = *(_BYTE *)(a1 + v2);
if ( v3 )
{
if ( v3 != 47 )
return v2;
if ( a2 - 1 > (int)v2 )
*(_BYTE *)(a1 + v2 + 1) = 0;
}
--v2;
}
while ( v2 );
}
return v2;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // rax
char v3; // dl

LOBYTE(v2) = a2 - 1;
if ( a2 != 1 )
{
v2 = (unsigned __int8)v2;
do
{
v3 = *(_BYTE *)(a1 + v2);
if ( v3 )
{
if ( v3 != 47 )
return v2;
if ( a2 - 1 > (int)v2 )
*(_BYTE *)(a1 + v2 + 1) = 0;
}
--v2;
}
while ( v2 );
}
return v2;
}

original_code:
void strip_filename(char* str, u8 len) {
  u8 i;
  for( i=(len-1); i>0; i-- ) {
    if(str[i] == 0) { continue; }
    else if(str[i] == '/') {
  if(i<(len-1)) {
   str[i+1] = 0;
  }
 }
    else { break; }
  }
}

canonical_original_code:
void strip_filename(char *str, unsigned char len) {
  unsigned char i;
  for( i=(len-1); i>0; i-- ) {
    if(str[i] == 0) { continue; }
    else if(str[i] == '/') {
  if(i<(len-1)) {
   str[i+1] = 0;
  }
 }
    else { break; }
  }
}

variable_types:
len
unsigned char

variable_types:
i
unsigned char


decompiled_code:
char *__fastcall scan_ext(const char *a1, char *a2)
{
int v3; // ecx
char *result; // rax
int v5; // edx
const char *v6; // rsi

v3 = strlen(a1);
result = (char *)&a1[v3 - 1];
v5 = v3;
while ( v5 > 0 )
{
v6 = result--;
--v5;
if ( result[1] == 46 )
return strncpy(a2, v6, v3 - v5 + 1);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, char *a2)
{
int v3; // ecx
char *result; // rax
int v5; // edx
const char *v6; // rsi

v3 = strlen(a1);
result = (char *)&a1[v3 - 1];
v5 = v3;
while ( v5 > 0 )
{
v6 = result--;
--v5;
if ( result[1] == 46 )
return strncpy(a2, v6, v3 - v5 + 1);
}
return result;
}

original_code:
void scan_ext(char* filename, char* ext) {
  int len;
  int i;
  int dotpos = -1;
  len = strlen(filename);
  i = len;
  while(i > 0) {
    --i;
    if(filename[i] == '.') {
      dotpos = i;
      break;
    }
  }
  if(dotpos >= 0) {
    strncpy(ext, filename + dotpos, len - i + 1);
  }
}

canonical_original_code:
void scan_ext(char *filename, char *ext) {
  int len;
  int i;
  int dotpos = -1;
  len = strlen(filename);
  i = len;
  while(i > 0) {
    --i;
    if(filename[i] == '.') {
      dotpos = i;
      break;
    }
  }
  if(dotpos >= 0) {
    strncpy(ext, filename + dotpos, len - i + 1);
  }
}

variable_types:
filename
char *

variable_types:
ext
char *

variable_types: len int


decompiled_code:
__int64 write_scn()
{
const char *v0; // rax
__int128 v2[8]; // [rsp+0h] [rbp-88h] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
strcpy((char *)v2, workingDir);
v0 = (const char *)scene_get_name();
strcat((char *)v2, v0);
strip_space_constprop_0(v2);
strcat((char *)v2, ".scn");
printf("\r\n writing .scn binary; name: %s", (const char *)v2);
return files_store_scene_name(v2);
}

canonical_decompiled_code:
__int64 func2()
{
const char *v0; // rax
__int128 v2[8]; // [rsp+0h] [rbp-88h] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
strcpy((char *)v2, workingDir);
v0 = (const char *)scene_get_name();
strcat((char *)v2, v0);
strip_space_constprop_0(v2);
strcat((char *)v2, ".scn");
printf("\r\n writing .scn binary; name: %s", (const char *)v2);
return files_store_scene_name(v2);
}

original_code:
void write_scn(void) {
  char str[128];
  memset(str, '\0', 64);
  strcpy(str, workingDir);
  strcat( str, scene_get_name());
  strip_space(str, 64);
  strcat(str, ".scn");
  printf("\r\n writing .scn binary; name: %s", str);
  files_store_scene_name(str);
}

canonical_original_code:
void write_scn() {
  char str[128];
  memset(str, '\0', 64);
  strcpy(str, workingDir);
  strcat( str, scene_get_name());
  strip_space(str, 64);
  strcat(str, ".scn");
  printf("\r\n writing .scn binary; name: %s", str);
  files_store_scene_name(str);
}

variable_types:
str
char [128]


decompiled_code:
int write_json()
{
const char *v0; // rax
__int128 v2[8]; // [rsp+0h] [rbp-88h] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
strcpy((char *)v2, workingDir);
v0 = (const char *)scene_get_name();
strcat((char *)v2, v0);
strip_space_constprop_0(v2);
strcat((char *)v2, ".json");
printf("\r\n writing %s...", (const char *)v2);
net_write_json_native(v2);
return printf("\r\n done.");
}

canonical_decompiled_code:
int func3()
{
const char *v0; // rax
__int128 v2[8]; // [rsp+0h] [rbp-88h] BYREF

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
strcpy((char *)v2, workingDir);
v0 = (const char *)scene_get_name();
strcat((char *)v2, v0);
strip_space_constprop_0(v2);
strcat((char *)v2, ".json");
printf("\r\n writing %s...", (const char *)v2);
net_write_json_native(v2);
return printf("\r\n done.");
}

original_code:
void write_json(void) {
  char str[128];
  memset(str, '\0', 64);
  strcpy(str, workingDir);
  strcat( str, scene_get_name());
  strip_space(str, 64);
  strcat(str, ".json");
  printf("\r\n writing %s...", str);
  net_write_json_native(str);
  printf("\r\n done.");
}

canonical_original_code:
void write_json() {
  char str[128];
  memset(str, '\0', 64);
  strcpy(str, workingDir);
  strcat( str, scene_get_name());
  strip_space(str, 64);
  strcat(str, ".json");
  printf("\r\n writing %s...", str);
  net_write_json_native(str);
  printf("\r\n done.");
}


decompiled_code:
int write_gv()
{
const char *v0; // rax
FILE *v1; // rbp
__int128 v3[8]; // [rsp+0h] [rbp-88h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
strcpy((char *)v3, workingDir);
v0 = (const char *)scene_get_name();
strcat((char *)v3, v0);
strip_space_constprop_0(v3);
*(_DWORD *)((char *)v3 + strlen((const char *)v3)) = 7759662;
v1 = fopen((const char *)v3, "w");
net_write_dot(v1);
return fclose(v1);
}

canonical_decompiled_code:
int func4()
{
const char *v0; // rax
FILE *v1; // rbp
__int128 v3[8]; // [rsp+0h] [rbp-88h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
strcpy((char *)v3, workingDir);
v0 = (const char *)scene_get_name();
strcat((char *)v3, v0);
strip_space_constprop_0(v3);
*(_DWORD *)((char *)v3 + strlen((const char *)v3)) = 7759662;
v1 = fopen((const char *)v3, "w");
net_write_dot(v1);
return fclose(v1);
}

original_code:
void write_gv(void) {
  char str[128];
  void* fp;
  memset(str, '\0', 64);
  strcpy(str, workingDir);
  strcat( str, scene_get_name());
  strip_space(str, 64);
  strcat(str, ".gv");
  fp = fopen(str, "w");
  net_write_dot(fp);
  fclose(fp);
}

canonical_original_code:
void write_gv() {
  char str[128];
  void *fp;
  memset(str, '\0', 64);
  strcpy(str, workingDir);
  strcat( str, scene_get_name());
  strip_space(str, 64);
  strcat(str, ".gv");
  fp = fopen(str, "w");
  net_write_dot(fp);
  fclose(fp);
}

variable_types:
fp
void *


decompiled_code:
__int64 __fastcall fract32_create(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a2 > a1 )
result = a1 % a2 * (0xFFFFFFFF / (a2 - 1));
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a2 > a1 )
result = a1 % a2 * (0xFFFFFFFF / (a2 - 1));
return result;
}

original_code:
fract32_t fract32_create(uint32_t inNumerator, uint32_t inDenominator) {
 if(inDenominator <= inNumerator)
  return 0xFFFFFFFF;
 uint32_t tempMod = (inNumerator % inDenominator);
 uint32_t tempDiv = (0xFFFFFFFF / (inDenominator - 1));
 return (tempMod * tempDiv);
}

canonical_original_code:
unsigned int fract32_create(unsigned int inNumerator, unsigned int inDenominator) {
 if(inDenominator <= inNumerator)
  return 0xFFFFFFFF;
 unsigned int tempMod = (inNumerator % inDenominator);
 unsigned int tempDiv = (0xFFFFFFFF / (inDenominator - 1));
 return (tempMod * tempDiv);
}

variable_types:
inNumerator
unsigned int

variable_types:
inDenominator
unsigned int

variable_types:
tempMod
unsigned int

variable_types:
tempDiv
unsigned int


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

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

original_code:
fract32_t fract32_invert(fract32_t inFract) {
 return (0xFFFFFFFF - inFract);
}

canonical_original_code:
unsigned int fract32_invert(unsigned int inFract) {
 return (0xFFFFFFFF - inFract);
}

variable_types:
inFract
unsigned int


decompiled_code:
unsigned __int64 __fastcall fract32_usmul(unsigned int a1, unsigned int a2)
{
return (a2 * (unsigned __int64)a1) >> 32;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return (a2 * (unsigned __int64)a1) >> 32;
}

original_code:
uint32_t fract32_usmul(uint32_t inVal, fract32_t inFract) {
 return (uint32_t)(((uint64_t)inVal * (uint64_t)inFract) >> 32);
}

canonical_original_code:
unsigned int fract32_usmul(unsigned int inVal, unsigned int inFract) {
 return (unsigned int)(((unsigned long)inVal * (unsigned long)inFract) >> 32);
}

variable_types:
inVal
unsigned int


decompiled_code:
unsigned __int64 __fastcall fract32_smul(signed int a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
result = (unsigned int)-(__int64)fract32_usmul(-a1, a2);
else
result = fract32_usmul(a1, a2);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(signed int a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
result = (unsigned int)-(__int64)func2(-a1, a2);
else
result = func2(a1, a2);
return result;
}

original_code:
int32_t fract32_smul(int32_t inVal, fract32_t inFract) {
 if(inVal < 0)
  return -fract32_usmul(-inVal, inFract);
 return fract32_usmul(inVal, inFract);
}

canonical_original_code:
int fract32_smul(int inVal, unsigned int inFract) {
 if(inVal < 0)
  return -fract32_usmul(-inVal, inFract);
 return fract32_usmul(inVal, inFract);
}

variable_types: inVal int


decompiled_code:
// attributes: thunk
__int64 flash_read_scene()
{
return scene_read_buf();
}

canonical_decompiled_code:
__int64 func0()
{
return scene_read_buf();
}

original_code:
void flash_read_scene(void) {
  scene_read_buf();
}

canonical_original_code:
void flash_read_scene() {
  scene_read_buf();
}


decompiled_code:
// attributes: thunk
__int64 flash_write_scene()
{
return scene_write_buf();
}

canonical_decompiled_code:
__int64 func1()
{
return scene_write_buf();
}

original_code:
void flash_write_scene(void) {
  scene_write_buf();
}

canonical_original_code:
void flash_write_scene() {
  scene_write_buf();
}


decompiled_code:
__int64 flash_init_scaler_data()
{
unsigned int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // eax
__int64 result; // rax
__int64 v4; // rbp
__int64 v5; // rbp
__int64 v6; // rdi

v0 = 0;
print_dbg("\r\n initializing NV data for param scaling, total bytes: ");
print_dbg_ulong(24576LL);
print_dbg("\r\n application data address in flash: 0x");
v1 = flash_app_data();
print_dbg_hex(v1);
print_dbg("\r\n scaler data address: 0x");
v2 = flash_app_data();
print_dbg_hex(v2);
flash_app_data();
do
{
while ( !(unsigned int)scaler_get_data_bytes(v0) )
{
result = scaler_get_rep_bytes(v0);
if ( (_DWORD)result )
goto LABEL_6;
LABEL_3:
if ( ++v0 == 9 )
return result;
}
v4 = scaler_get_data_path(v0);
print_dbg("\r\n writing scaler data to flash: ");
print_dbg(v4);
files_load_scaler_name(v4, scalerBuf, 1024LL);
LODWORD(v4) = scaler_get_nv_data(v0);
print_dbg("\r\n writing scaler val data to flash at address: 0x");
print_dbg_hex((unsigned int)v4);
result = scaler_get_rep_bytes(v0);
if ( !(_DWORD)result )
goto LABEL_3;
LABEL_6:
v5 = scaler_get_rep_path(v0);
print_dbg("\r\n writing scaler data to flash: ");
print_dbg(v5);
files_load_scaler_name(v5, scalerBuf, 1024LL);
v6 = v0++;
LODWORD(v5) = scaler_get_nv_rep(v6);
print_dbg("\r\n writing scaler rep data to flash at address: 0x");
result = print_dbg_hex((unsigned int)v5);
}
while ( v0 != 9 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // eax
__int64 result; // rax
__int64 v4; // rbp
__int64 v5; // rbp
__int64 v6; // rdi

v0 = 0;
print_dbg("\r\n initializing NV data for param scaling, total bytes: ");
print_dbg_ulong(24576LL);
print_dbg("\r\n application data address in flash: 0x");
v1 = flash_app_data();
print_dbg_hex(v1);
print_dbg("\r\n scaler data address: 0x");
v2 = flash_app_data();
print_dbg_hex(v2);
flash_app_data();
do
{
while ( !(unsigned int)scaler_get_data_bytes(v0) )
{
result = scaler_get_rep_bytes(v0);
if ( (_DWORD)result )
goto LABEL_6;
LABEL_3:
if ( ++v0 == 9 )
return result;
}
v4 = scaler_get_data_path(v0);
print_dbg("\r\n writing scaler data to flash: ");
print_dbg(v4);
files_load_scaler_name(v4, scalerBuf, 1024LL);
LODWORD(v4) = scaler_get_nv_data(v0);
print_dbg("\r\n writing scaler val data to flash at address: 0x");
print_dbg_hex((unsigned int)v4);
result = scaler_get_rep_bytes(v0);
if ( !(_DWORD)result )
goto LABEL_3;
LABEL_6:
v5 = scaler_get_rep_path(v0);
print_dbg("\r\n writing scaler data to flash: ");
print_dbg(v5);
files_load_scaler_name(v5, scalerBuf, 1024LL);
v6 = v0++;
LODWORD(v5) = scaler_get_nv_rep(v6);
print_dbg("\r\n writing scaler rep data to flash at address: 0x");
result = print_dbg_hex((unsigned int)v5);
}
while ( v0 != 9 );
return result;
}

original_code:
void flash_init_scaler_data(void) {
  u32 b;
  const char* path;
  u8 p;
  u8* dst;
  void* scalerBytes;
  print_dbg("\r\n initializing NV data for param scaling, total bytes: ");
  print_dbg_ulong(((1024 * 4 * 2) + 0 + 0 + 0 + (1024 * 4) + (1024 * 4) + (1024 * 4) + 0 + (1024 * 4) ));
  print_dbg("\r\n application data address in flash: 0x");
  print_dbg_hex((u32)flash_app_data());
  print_dbg("\r\n scaler data address: 0x");
  print_dbg_hex((u32) &(((beesFlashData*)(flash_app_data()))->scalerBytes) );
  scalerBytes = (void*)&(((beesFlashData*)(flash_app_data()))->scalerBytes);
  for(p=0; p<eParamNumTypes; ++p) {
    b = scaler_get_data_bytes(p);
    if(b > 0) {
      path = scaler_get_data_path(p);
      print_dbg("\r\n writing scaler data to flash: ");
      print_dbg(path);
      files_load_scaler_name(path, scalerBuf, scalerMaxValues);
      dst = (void*)scaler_get_nv_data(p);
      print_dbg("\r\n writing scaler val data to flash at address: 0x");
      print_dbg_hex((u32)dst);
    }
    b = scaler_get_rep_bytes(p);
    if(b > 0) {
      path = scaler_get_rep_path(p);
      print_dbg("\r\n writing scaler data to flash: ");
      print_dbg(path);
      files_load_scaler_name(path, scalerBuf, scalerMaxValues);
      dst = (void*)scaler_get_nv_rep(p);
      print_dbg("\r\n writing scaler rep data to flash at address: 0x");
      print_dbg_hex((u32)dst);
    }
  }
}

canonical_original_code:
void flash_init_scaler_data() {
  unsigned int b;
  char *path;
  unsigned char p;
  unsigned char *dst;
  void *scalerBytes;
  print_dbg("\r\n initializing NV data for param scaling, total bytes: ");
  print_dbg_ulong(((1024 * 4 * 2) + 0 + 0 + 0 + (1024 * 4) + (1024 * 4) + (1024 * 4) + 0 + (1024 * 4) ));
  print_dbg("\r\n application data address in flash: 0x");
  print_dbg_hex((unsigned int)flash_app_data());
  print_dbg("\r\n scaler data address: 0x");
  print_dbg_hex((u32) &(((struct beesFlashData *)(flash_app_data()))->scalerBytes) );
  scalerBytes = (void *)&(((struct beesFlashData *)(flash_app_data()))->scalerBytes);
  for(p=0; p<eParamNumTypes; ++p) {
    b = scaler_get_data_bytes(p);
    if(b > 0) {
      path = scaler_get_data_path(p);
      print_dbg("\r\n writing scaler data to flash: ");
      print_dbg(path);
      files_load_scaler_name(path, scalerBuf, scalerMaxValues);
      dst = (void *)scaler_get_nv_data(p);
      print_dbg("\r\n writing scaler val data to flash at address: 0x");
      print_dbg_hex((unsigned int)dst);
    }
    b = scaler_get_rep_bytes(p);
    if(b > 0) {
      path = scaler_get_rep_path(p);
      print_dbg("\r\n writing scaler data to flash: ");
      print_dbg(path);
      files_load_scaler_name(path, scalerBuf, scalerMaxValues);
      dst = (void *)scaler_get_nv_rep(p);
      print_dbg("\r\n writing scaler rep data to flash at address: 0x");
      print_dbg_hex((unsigned int)dst);
    }
  }
}

variable_types:
b
unsigned int

variable_types:
path
char *

variable_types:
p
unsigned char

variable_types:
dst
unsigned char *

variable_types:
scalerBytes
void *

user_defined_types: struct beesFlashData { unsigned char scalerBytes[-1]; }


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

result = alloc_mem(4096LL);
scalerBuf = result;
return result;
}

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

result = alloc_mem(4096LL);
scalerBuf = result;
return result;
}

original_code:
void flash_bees_init(void) {
  scalerBuf = (s32*)alloc_mem(scalerMaxValues * 4);
}

canonical_original_code:
void flash_bees_init() {
  scalerBuf = (int *)alloc_mem(scalerMaxValues * 4);
}


original_code:
fix16_t fix16_sqrt(fix16_t inValue) {
  uint8_t neg = (inValue < 0);
  uint32_t num = (neg ? -inValue : inValue);
  uint32_t result = 0;
  uint32_t bit;
  uint8_t n;
  if (num & 0xFFF00000)
    bit = (uint32_t)1 << 30;
  else
    bit = (uint32_t)1 << 18;
  while (bit > num) bit >>= 2;
  for (n = 0; n < 2; n++)
  {
    while (bit)
    {
      if (num >= result + bit)
      {
        num -= result + bit;
        result = (result >> 1) + bit;
      }
      else
      {
        result = (result >> 1);
      }
      bit >>= 2;
    }
    if (n == 0)
    {
      if (num > 65535)
      {
        num -= result;
        num = (num << 16) - 0x8000;
        result = (result << 16) + 0x8000;
      }
      else
      {
        num <<= 16;
        result <<= 16;
      }
      bit = 1 << 14;
    }
  }
  if (num > result)
  {
    result++;
  }
  return (neg ? -result : result);
}

canonical_original_code:
int fix16_sqrt(int inValue) {
  unsigned char neg = (inValue < 0);
  unsigned int num = (neg ? -inValue : inValue);
  unsigned int result = 0;
  unsigned int bit;
  unsigned char n;
  if (num & 0xFFF00000)
    bit = (unsigned int)1 << 30;
  else
    bit = (unsigned int)1 << 18;
  while (bit > num) bit >>= 2;
  for (n = 0; n < 2; n++)
  {
    while (bit)
    {
      if (num >= result + bit)
      {
        num -= result + bit;
        result = (result >> 1) + bit;
      }
      else
      {
        result = (result >> 1);
      }
      bit >>= 2;
    }
    if (n == 0)
    {
      if (num > 65535)
      {
        num -= result;
        num = (num << 16) - 0x8000;
        result = (result << 16) + 0x8000;
      }
      else
      {
        num <<= 16;
        result <<= 16;
      }
      bit = 1 << 14;
    }
  }
  if (num > result)
  {
    result++;
  }
  return (neg ? -result : result);
}

variable_types: inValue int

variable_types:
neg
unsigned char

variable_types:
num
unsigned int

variable_types:
result
unsigned int

variable_types:
bit
unsigned int

variable_types:
n
unsigned char


decompiled_code:
__int64 app_init()
{
print_dbg("\r\n preset_init...");
presets_init();
print_dbg("\r\n net_init... ");
net_init();
print_dbg("\r\n scene_init...");
scene_init();
print_dbg("\r\n files_init...");
files_init();
print_dbg("\r\n render_init...");
render_init();
print_dbg("\r\n flash_bees_init...");
return flash_bees_init();
}

canonical_decompiled_code:
__int64 func0()
{
print_dbg("\r\n preset_init...");
presets_init();
print_dbg("\r\n net_init... ");
net_init();
print_dbg("\r\n scene_init...");
scene_init();
print_dbg("\r\n files_init...");
files_init();
print_dbg("\r\n render_init...");
render_init();
print_dbg("\r\n flash_bees_init...");
return flash_bees_init();
}

original_code:
void app_init(void) {
  print_dbg("\r\n preset_init...");
  presets_init();
  print_dbg("\r\n net_init... ");
  net_init();
  print_dbg("\r\n scene_init...");
  scene_init();
  print_dbg("\r\n files_init...");
  files_init();
  print_dbg("\r\n render_init...");
  render_init();
  print_dbg("\r\n flash_bees_init...");
  flash_bees_init();
}

canonical_original_code:
void app_init() {
  print_dbg("\r\n preset_init...");
  presets_init();
  print_dbg("\r\n net_init... ");
  net_init();
  print_dbg("\r\n scene_init...");
  scene_init();
  print_dbg("\r\n files_init...");
  files_init();
  print_dbg("\r\n render_init...");
  render_init();
  print_dbg("\r\n flash_bees_init...");
  flash_bees_init();
}


decompiled_code:
__int64 __fastcall app_launch(unsigned __int8 a1)
{
print_dbg("\r\n launching app with firstrun: ");
print_dbg_ulong(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
print_dbg("\r\n launching app with firstrun: ");
print_dbg_ulong(a1);
return 1LL;
}

original_code:
u8 app_launch(u8 firstrun) {
  print_dbg("\r\n launching app with firstrun: ");
  print_dbg_ulong(firstrun);
  return 1;
}

canonical_original_code:
unsigned char app_launch(unsigned char firstrun) {
  print_dbg("\r\n launching app with firstrun: ");
  print_dbg_ulong(firstrun);
  return 1;
}

variable_types:
firstrun
unsigned char


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

result = 0LL;
if ( a1 )
{
if ( a1 > 0xFFFF )
{
a1 >>= 16;
LODWORD(result) = 16;
}
if ( a1 > 0xFF )
{
a1 >>= 8;
LODWORD(result) = result + 8;
}
if ( a1 > 0xF )
{
a1 >>= 4;
LODWORD(result) = result + 4;
}
if ( a1 > 3 )
{
a1 >>= 2;
LODWORD(result) = result + 2;
}
result = (a1 != 1) + (unsigned int)result;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
if ( a1 > 0xFFFF )
{
a1 >>= 16;
LODWORD(result) = 16;
}
if ( a1 > 0xFF )
{
a1 >>= 8;
LODWORD(result) = result + 8;
}
if ( a1 > 0xF )
{
a1 >>= 4;
LODWORD(result) = result + 4;
}
if ( a1 > 3 )
{
a1 >>= 2;
LODWORD(result) = result + 2;
}
result = (a1 != 1) + (unsigned int)result;
}
return result;
}

original_code:
uint32_t uint32_log2(uint32_t inVal) {
 if(inVal == 0)
  return 0;
 uint32_t tempOut = 0;
 if(inVal >= (1 << 16)) { inVal >>= 16; tempOut += 16; }
 if(inVal >= (1 << 8)) { inVal >>= 8; tempOut += 8; }
 if(inVal >= (1 << 4)) { inVal >>= 4; tempOut += 4; }
 if(inVal >= (1 << 2)) { inVal >>= 2; tempOut += 2; }
 if(inVal >= (1 << 1)) { tempOut += 1; }
 return tempOut;
}

canonical_original_code:
unsigned int uint32_log2(unsigned int inVal) {
 if(inVal == 0)
  return 0;
 unsigned int tempOut = 0;
 if(inVal >= (1 << 16)) { inVal >>= 16; tempOut += 16; }
 if(inVal >= (1 << 8)) { inVal >>= 8; tempOut += 8; }
 if(inVal >= (1 << 4)) { inVal >>= 4; tempOut += 4; }
 if(inVal >= (1 << 2)) { inVal >>= 2; tempOut += 2; }
 if(inVal >= (1 << 1)) { tempOut += 1; }
 return tempOut;
}

variable_types:
tempOut
unsigned int


shiftStartOffset

repo: tejacques/c-deque

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

result = a1[3] & (unsigned int)(a2 + *a1);
*a1 = result;
return result;
}

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

result = a1[3] & (unsigned int)(a2 + *a1);
*a1 = result;
return result;
}

original_code:
int shiftStartOffset(deque *deque, int amount)
{
    return (deque->startOffset =
            (deque->startOffset + amount) & deque->lengthMinusOne);
}

canonical_original_code:
int shiftStartOffset(struct deque *deque, int amount)
{
    return (deque->startOffset =
            (deque->startOffset + amount) & deque->lengthMinusOne);
}

variable_types: struct deque { int startOffset; int endOffset; int length; int lengthMinusOne; int count; void **buffer; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *key); } *

variable_types: amount int


copyMemory

decompiled_code:
void *__fastcall copyMemory(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
return memcpy((void *)(a3 + 8LL * a4), (const void *)(a1 + 8LL * a2), 8LL * a5);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
return memcpy((void *)(a3 + 8LL * a4), (const void *)(a1 + 8LL * a2), 8LL * a5);
}

original_code:
void copyMemory(
        void **source,
        int sourceIndex,
        void **dest,
        int destIndex,
        int num)
{
    ;
    ;
    for (int i = 0; i < num; i++)
    {
        ;
    }
    memcpy( (void *)(dest+destIndex),
            (const void *)(source+sourceIndex),
            (size_t)(num * sizeof(void*)));
    ;
    for (int i = 0; i < num; i++)
    {
        ;
    }
    ;
}

canonical_original_code:
void copyMemory(void **source, int sourceIndex, void **dest, int destIndex, int num)
{
    ;
    ;
    for (int i = 0; i < num; i++)
    {
        ;
    }
    memcpy( (void *)(dest+destIndex),
            (void *)(source+sourceIndex),
            (unsigned long)(num * sizeof(void *)));
    ;
    for (int i = 0; i < num; i++)
    {
        ;
    }
    ;
}

variable_types:
source
void **

variable_types: sourceIndex int

variable_types:
dest
void **

variable_types: destIndex int

variable_types: num int

variable_types: i int


resizeDeque

decompiled_code:
__int64 __fastcall resizeDeque(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax
int v4; // ebp
void *v5; // rax
void *v6; // r12
int v7; // eax

if ( a2 <= 0 )
return 0LL;
if ( *(_DWORD *)(a1 + 16) > a2 )
return 0LL;
v3 = power_of_two_greater_than((unsigned int)a2);
v4 = v3;
if ( *(_DWORD *)(a1 + 8) == v3 )
return 0LL;
v5 = malloc(8LL * v3);
v6 = v5;
if ( !v5 )
return 0LL;
copyBuffer_constprop_0(a1, (__int64)v5, v4);
free(*(void **)(a1 + 24));
v7 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 24) = v6;
*(_DWORD *)(a1 + 4) = v7;
result = 1LL;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 12) = v4 - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax
int v4; // ebp
void *v5; // rax
void *v6; // r12
int v7; // eax

if ( a2 <= 0 )
return 0LL;
if ( *(_DWORD *)(a1 + 16) > a2 )
return 0LL;
v3 = power_of_two_greater_than((unsigned int)a2);
v4 = v3;
if ( *(_DWORD *)(a1 + 8) == v3 )
return 0LL;
v5 = malloc(8LL * v3);
v6 = v5;
if ( !v5 )
return 0LL;
func4(a1, (__int64)v5, v4);
free(*(void **)(a1 + 24));
v7 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 24) = v6;
*(_DWORD *)(a1 + 4) = v7;
result = 1LL;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 12) = v4 - 1;
return result;
}

original_code:
_Bool resizeDeque(deque *deque, int length)
{
    if (length <= 0)
    {
        return 0;
    }
    else if (length < ((deque)->count))
    {
        return 0;
    }
    length = power_of_two_greater_than(length);
    if (length == ((deque)->length))
    {
        return 0;
    }
    void **newBuffer = malloc(sizeof(void*) * length);
    if (!newBuffer)
    {
        return 0;
    }
    copyBuffer(deque, newBuffer, length, 0);
    free(deque->buffer);
    deque->buffer = newBuffer;
    deque->startOffset = 0;
    deque->endOffset = deque->count;
    deque->length = length;
    deque->lengthMinusOne = length-1;
    return 1;
}

canonical_original_code:
_Bool resizeDeque(struct deque *deque, int length)
{
    if (length <= 0)
    {
        return 0;
    }
    else if (length < ((deque)->count))
    {
        return 0;
    }
    length = power_of_two_greater_than(length);
    if (length == ((deque)->length))
    {
        return 0;
    }
    void **newBuffer = malloc(sizeof(void*) * length);
    if (!newBuffer)
    {
        return 0;
    }
    copyBuffer(deque, newBuffer, length, 0);
    free(deque->buffer);
    deque->buffer = newBuffer;
    deque->startOffset = 0;
    deque->endOffset = deque->count;
    deque->length = length;
    deque->lengthMinusOne = length-1;
    return 1;
}

variable_types: length int

variable_types:
newBuffer
void **

user_defined_types: struct deque { int startOffset; int endOffset; int length; int lengthMinusOne; int count; void **buffer; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *key); }


ensureCapacityFor

decompiled_code:
__int64 __fastcall ensureCapacityFor(__int64 a1, int a2)
{
int v2; // esi
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 16) + a2;
if ( v2 > *(_DWORD *)(a1 + 8) )
result = resizeDeque(a1, v2);
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // esi
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 16) + a2;
if ( v2 > *(_DWORD *)(a1 + 8) )
result = func5(a1, v2);
else
result = 1LL;
return result;
}

original_code:
_Bool ensureCapacityFor(deque *deque, int numElements)
{
    if (deque->count + numElements > deque->length)
    {
        return resizeDeque(deque, deque->count + numElements);
    }
    return 1;
}

canonical_original_code:
_Bool ensureCapacityFor(struct deque *deque, int numElements)
{
    if (deque->count + numElements > deque->length)
    {
        return resizeDeque(deque, deque->count + numElements);
    }
    return 1;
}

variable_types: numElements int


dequeCreate

original_code:
deque *dequeCreate(void)
{
    struct deque *deque;
    if ((deque = malloc(sizeof(*deque))) == ((void *)0))
    {
        return ((void *)0);
    }
    deque->length = 8;
    deque->startOffset = 0;
    deque->endOffset = 0;
    deque->lengthMinusOne = deque->length - 1;
    deque->count = 0;
    deque->dup = ((void *)0);
    deque->free = ((void *)0);
    deque->match = ((void *)0);
    if ((deque->buffer = malloc(sizeof(void *) * deque->length)) == ((void *)0))
    {
        free(deque);
        return ((void *)0);
    }
    return deque;
}

canonical_original_code:
struct deque *dequeCreate()
{
    struct deque *deque;
    if ((deque = malloc(sizeof(*deque))) == ((void *)0))
    {
        return ((void *)0);
    }
    deque->length = 8;
    deque->startOffset = 0;
    deque->endOffset = 0;
    deque->lengthMinusOne = deque->length - 1;
    deque->count = 0;
    deque->dup = ((void *)0);
    deque->free = ((void *)0);
    deque->match = ((void *)0);
    if ((deque->buffer = malloc(sizeof(void *) * deque->length)) == ((void *)0))
    {
        free(deque);
        return ((void *)0);
    }
    return deque;
}

return_type: struct deque { int startOffset; int endOffset; int length; int lengthMinusOne; int count; void **buffer; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *key); } *


dequeAddTail

decompiled_code:
__int64 __fastcall dequeAddTail(__int64 a1, __int64 a2)
{
char v2; // r8
__int64 result; // rax
int v4; // eax
__int64 v5; // rdx

v2 = ensureCapacityFor(a1, 1);
result = 0LL;
if ( v2 )
{
preShiftEndOffset_constprop_0(a1);
*(_QWORD *)(v5 + 8LL * v4) = a2;
result = a1;
++*(_DWORD *)(a1 + 16);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
char v2; // r8
__int64 result; // rax
int v4; // eax
__int64 v5; // rdx

v2 = func6(a1, 1);
result = 0LL;
if ( v2 )
{
func8(a1);
*(_QWORD *)(v5 + 8LL * v4) = a2;
result = a1;
++*(_DWORD *)(a1 + 16);
}
return result;
}

original_code:
deque *dequeAddTail(deque *deque, void *value)
{
    if (!ensureCapacityFor(deque, 1))
    {
        return ((void *)0);
    }
    deque->buffer[preShiftEndOffset(deque, 1)] = value;
    deque->count++;
    return deque;
}

canonical_original_code:
struct deque *dequeAddTail(struct deque *deque, void *value)
{
    if (!ensureCapacityFor(deque, 1))
    {
        return ((void *)0);
    }
    deque->buffer[preShiftEndOffset(deque, 1)] = value;
    deque->count++;
    return deque;
}

variable_types:
deque
struct deque *

variable_types:
value
void *


dequeInsertRange

decompiled_code:
__int64 __fastcall dequeInsertRange(__int64 a1, int a2)
{
int v3; // ebx
bool v4; // al
__int64 v5; // rdx
int v6; // ecx
__int64 v7; // r13
int v8; // er12
int v9; // er8
int v10; // edi
int v11; // ecx
int v12; // esi
int v13; // ecx
int v14; // er9
int v15; // eax
_QWORD *v16; // r10
__int64 v17; // r8
int v18; // edi
int v19; // er9
int v20; // edx
int v21; // er8
int v23; // edi
int v24; // esi
int v25; // ecx
int v26; // ecx
int v27; // eax
_QWORD *v28; // r10
__int64 v29; // r9
int v30; // er8

v3 = a2;
v4 = indexOutOfRange_isra_0(*(_DWORD *)(a1 + 16), a2 - 1);
if ( !v6 )
return 0LL;
if ( v4 )
return 0LL;
v7 = v5;
v8 = v6;
if ( !(unsigned __int8)ensureCapacityFor(a1, v6) )
return 0LL;
v9 = *(_DWORD *)(a1 + 16);
if ( v9 / 2 <= a2 )
{
if ( v9 > a2 && v9 - a2 > 0 )
{
v23 = *(_DWORD *)a1;
v24 = *(_DWORD *)(a1 + 12);
v25 = v3;
do
{
toBufferIndex_isra_0(v23, v24, v25);
v27 = toBufferIndex_isra_0(v23, v24, v8 + v26);
*(_QWORD *)(v29 + 8LL * v27) = *v28;
}
while ( v30 != v25 );
}
shiftEndOffset_isra_0(a1, v8);
}
else
{
if ( a2 > 0 )
{
v10 = *(_DWORD *)a1;
v11 = 0;
v12 = *(_DWORD *)(a1 + 12);
do
{
toBufferIndex_isra_0(v10, v12, v11);
v15 = toBufferIndex_isra_0(v10, v12, v13 + v14);
*(_QWORD *)(v17 + 8LL * v15) = *v16;
}
while ( v3 != v11 );
}
shiftStartOffset((_DWORD *)a1, -v8);
}
if ( v8 > 0 )
{
v18 = *(_DWORD *)a1;
v19 = *(_DWORD *)(a1 + 12);
do
{
v20 = v3++;
v7 += 8LL;
*(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL * (int)toBufferIndex_isra_0(v18, v19, v20)) = *(_QWORD *)(v7 - 8);
}
while ( v3 != v21 );
}
*(_DWORD *)(a1 + 16) += v8;
return a1;
}

original_code:
deque *dequeInsertRange(deque *deque, int index, void **values, int num)
{
    if (indexOutOfRange(deque, index - 1))
    {
        return ((void *)0);
    }
    if (0 == num)
    {
        return ((void *)0);
    }
    if (!ensureCapacityFor(deque, num))
    {
        return ((void *)0);
    }
    if (index < deque->count / 2)
    {
        if (index > 0)
        {
            int copyCount = index;
            int shiftIndex = deque->length - num;
            for (int i = 0; i < copyCount; ++i)
            {
                deque->buffer[toBufferIndex(deque, shiftIndex + i)] =
                    deque->buffer[toBufferIndex(deque, i)];
            }
        }
        shiftStartOffset(deque, -num);
    }
    else
    {
        if (index < deque->count)
        {
            int copyCount = deque->count - index;
            int shiftIndex = index + num;
            for (int i = 0; i < copyCount; ++i)
            {
                deque->buffer[toBufferIndex(deque, shiftIndex + i)] =
                    deque->buffer[toBufferIndex(deque, index + i)];
            }
        }
        shiftEndOffset(deque, num);
    }
    int i = index;
    for(int j = 0; j < num; ++j)
    {
        deque->buffer[toBufferIndex(deque, i)] = values[j];
        ++i;
    }
    deque->count += num;
    return deque;
}

canonical_original_code:
struct deque *dequeInsertRange(struct deque *deque, int index, void **values, int num)
{
    if (indexOutOfRange(deque, index - 1))
    {
        return ((void *)0);
    }
    if (0 == num)
    {
        return ((void *)0);
    }
    if (!ensureCapacityFor(deque, num))
    {
        return ((void *)0);
    }
    if (index < deque->count / 2)
    {
        if (index > 0)
        {
            int copyCount = index;
            int shiftIndex = deque->length - num;
            for (int i = 0; i < copyCount; ++i)
            {
                deque->buffer[toBufferIndex(deque, shiftIndex + i)] =
                    deque->buffer[toBufferIndex(deque, i)];
            }
        }
        shiftStartOffset(deque, -num);
    }
    else
    {
        if (index < deque->count)
        {
            int copyCount = deque->count - index;
            int shiftIndex = index + num;
            for (int i = 0; i < copyCount; ++i)
            {
                deque->buffer[toBufferIndex(deque, shiftIndex + i)] =
                    deque->buffer[toBufferIndex(deque, index + i)];
            }
        }
        shiftEndOffset(deque, num);
    }
    int i = index;
    for(int j = 0; j < num; ++j)
    {
        deque->buffer[toBufferIndex(deque, i)] = values[j];
        ++i;
    }
    deque->count += num;
    return deque;
}

variable_types: index int

variable_types:
values
void **

variable_types: copyCount int

variable_types: shiftIndex int

variable_types: j int


dequeAddHeadRange

decompiled_code:
__int64 __fastcall dequeAddHeadRange(__int64 a1)
{
return dequeInsertRange(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func13(a1, 0);
}

original_code:
deque *dequeAddHeadRange(deque *deque, void **values, int num)
{
    return dequeInsertRange(deque, 0, values, num);
}

canonical_original_code:
struct deque *dequeAddHeadRange(struct deque *deque, void **values, int num)
{
    return dequeInsertRange(deque, 0, values, num);
}


dequeAddTailRange

decompiled_code:
__int64 __fastcall dequeAddTailRange(__int64 a1)
{
return dequeInsertRange(a1, *(_DWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func13(a1, *(_DWORD *)(a1 + 16));
}

original_code:
deque *dequeAddTailRange(deque *deque, void **values, int num)
{
    return dequeInsertRange(deque, deque->count, values, num);
}

canonical_original_code:
struct deque *dequeAddTailRange(struct deque *deque, void **values, int num)
{
    return dequeInsertRange(deque, deque->count, values, num);
}


dequeGet

decompiled_code:
__int64 __fastcall dequeGet(__int64 a1, int a2)
{
int v2; // edx
int *v3; // rcx
int v4; // eax
__int64 v5; // rcx

if ( indexOutOfRange_isra_0(*(_DWORD *)(a1 + 16), a2) )
return 0LL;
v4 = toBufferIndex_isra_0(*v3, v3[3], v2);
return *(_QWORD *)(*(_QWORD *)(v5 + 24) + 8LL * v4);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2)
{
int v2; // edx
int *v3; // rcx
int v4; // eax
__int64 v5; // rcx

if ( func9(*(_DWORD *)(a1 + 16), a2) )
return 0LL;
v4 = func10(*v3, v3[3], v2);
return *(_QWORD *)(*(_QWORD *)(v5 + 24) + 8LL * v4);
}

original_code:
void *dequeGet(deque *deque, int index)
{
    if (indexOutOfRange(deque, index))
    {
        return ((void *)0);
    }
    return deque->buffer[toBufferIndex(deque, index)];
}

canonical_original_code:
void *dequeGet(struct deque *deque, int index)
{
    if (indexOutOfRange(deque, index))
    {
        return ((void *)0);
    }
    return deque->buffer[toBufferIndex(deque, index)];
}

variable_types: struct deque { int startOffset; int endOffset; int length; int lengthMinusOne; int count; void **buffer; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *key); } *

return_type: void *


dequeRelease

decompiled_code:
void __fastcall dequeRelease(void *ptr)
{
int v1; // ebx
int v2; // esi
__int64 v3; // rax

if ( *((_QWORD *)ptr + 5) && *((int *)ptr + 4) > 0 )
{
v1 = 0;
do
{
v2 = v1++;
v3 = dequeGet((__int64)ptr, v2);
(*((void (__fastcall **)(__int64))ptr + 5))(v3);
}
while ( *((_DWORD *)ptr + 4) > v1 );
}
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void dequeRelease(deque *deque)
{
    if (deque->free)
    {
        for(int i = 0; i < deque->count; ++i)
        {
            void *val = dequeGet(deque, i);
            deque->free(val);
        }
    }
    free(deque->buffer);
    free(deque);
}

canonical_original_code:
void dequeRelease(struct deque *deque)
{
    if (deque->free)
    {
        for(int i = 0; i < deque->count; ++i)
        {
            void *val = dequeGet(deque, i);
            deque->free(val);
        }
    }
    free(deque->buffer);
    free(deque);
}

variable_types:
val
void *


dequeSet

decompiled_code:
__int64 __fastcall dequeSet(__int64 a1, int a2)
{
int *v2; // rcx
int v3; // er8
int v4; // eax
__int64 v5; // rcx
__int64 v6; // r9

if ( indexOutOfRange_isra_0(*(_DWORD *)(a1 + 16), a2) )
return 0LL;
v4 = toBufferIndex_isra_0(*v2, v2[3], v3);
*(_QWORD *)(*(_QWORD *)(v5 + 24) + 8LL * v4) = v6;
return v5;
}

original_code:
deque *dequeSet(deque *deque, int index, void *value)
{
    if (indexOutOfRange(deque, index))
    {
        return ((void *)0);
    }
    deque->buffer[toBufferIndex(deque, index)] = value;
    return deque;
}

canonical_original_code:
struct deque *dequeSet(struct deque *deque, int index, void *value)
{
    if (indexOutOfRange(deque, index))
    {
        return ((void *)0);
    }
    deque->buffer[toBufferIndex(deque, index)] = value;
    return deque;
}


main

canonical_name: main

repo: teknopaul/escape

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *i; // r12
int v4; // eax

opterr = 0;
for ( i = "c"; ; i = (const char *)optarg )
{
v4 = getopt(argc, (char *const *)argv, "f:");
if ( v4 == -1 )
break;
if ( v4 == 63 )
{
if ( optopt == 102 )
fwrite("Specify the escape format\n", 1uLL, 0x1AuLL, stderr);
else
fprintf(stderr, "Unknown option character `\\x%x'\n", (unsigned int)optopt);
return 1;
}
if ( v4 != 102 )
return 1;
}
if ( !strcmp("c", i) || !strcmp("json", i) || !strcmp("html", i) || !strcmp("xml", i) )
return escape_isra_0(stdin, _bss_start);
if ( !strcmp("sanename", i) )
return sanename(stdin, _bss_start);
fprintf(stderr, "Unknown format '%s'\n", i);
return 2;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *i; // r12
int v4; // eax

opterr = 0;
for ( i = "c"; ; i = (const char *)optarg )
{
v4 = getopt(argc, (char *const *)argv, "f:");
if ( v4 == -1 )
break;
if ( v4 == 63 )
{
if ( optopt == 102 )
fwrite("Specify the escape format\n", 1uLL, 0x1AuLL, stderr);
else
fprintf(stderr, "Unknown option character `\\x%x'\n", (unsigned int)optopt);
return 1;
}
if ( v4 != 102 )
return 1;
}
if ( !strcmp("c", i) || !strcmp("json", i) || !strcmp("html", i) || !strcmp("xml", i) )
return func9(stdin, _bss_start);
if ( !strcmp("sanename", i) )
return func8(stdin, _bss_start);
fprintf(stderr, "Unknown format '%s'\n", i);
return 2;
}

original_code:
int main (int argc, char *argv[]) {
  char *fvalue = "c";
  int ch;
  opterr = 0;
  while ((ch = getopt (argc, argv, "f:")) != -1) {
    switch (ch)
    {
      case 'f':
        fvalue = optarg;
        break;
      case '?':
        if (optopt == 'f') {
          fprintf(stderr, "Specify the escape format\n");
        }
        else {
          fprintf(stderr, "Unknown option character `\\x%x'\n", optopt);
        }
        return 1;;
      default:
        return 1;;
    }
  }
  if ( strcmp("c", fvalue) == 0 ) {
    return escape(stdin, stdout, c);
  }
  if ( strcmp("json", fvalue) == 0 ) {
    return escape(stdin, stdout, json);
  }
  if ( strcmp("html", fvalue) == 0 ) {
    return escape(stdin, stdout, html);
  }
  if ( strcmp("xml", fvalue) == 0 ) {
    return escape(stdin, stdout, xml);
  }
  if ( strcmp("sanename", fvalue) == 0 ) {
    return sanename(stdin, stdout);
  }
  fprintf(stderr, "Unknown format '%s'\n", fvalue);
  return 2;;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char *fvalue = "c";
  int ch;
  opterr = 0;
  while ((ch = getopt (argc, argv, "f:")) != -1) {
    switch (ch)
    {
      case 'f':
        fvalue = optarg;
        break;
      case '?':
        if (optopt == 'f') {
          fprintf(stderr, "Specify the escape format\n");
        }
        else {
          fprintf(stderr, "Unknown option character `\\x%x'\n", optopt);
        }
        return 1;;
      default:
        return 1;;
    }
  }
  if ( strcmp("c", fvalue) == 0 ) {
    return escape(stdin, stdout, c);
  }
  if ( strcmp("json", fvalue) == 0 ) {
    return escape(stdin, stdout, json);
  }
  if ( strcmp("html", fvalue) == 0 ) {
    return escape(stdin, stdout, html);
  }
  if ( strcmp("xml", fvalue) == 0 ) {
    return escape(stdin, stdout, xml);
  }
  if ( strcmp("sanename", fvalue) == 0 ) {
    return sanename(stdin, stdout);
  }
  fprintf(stderr, "Unknown format '%s'\n", fvalue);
  return 2;;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
fvalue
char *

variable_types: ch int


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

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(char *)(a2 + result) != a3 )
{
if ( ++result == a1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(char *)(a2 + result) != a3 )
{
if ( ++result == a1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
static int index_of(int len, const char in_chars[], int ch) {
  int i;
  for(i = 0 ; i < len ; i++) {
    if (ch == in_chars[i]) return i;
  }
  return -1;
}

canonical_original_code:
static int index_of(int len, char in_chars[], int ch) {
  int i;
  for(i = 0 ; i < len ; i++) {
    if (ch == in_chars[i]) return i;
  }
  return -1;
}

variable_types: len int

variable_types: i int


repo: telehash/telehash-c

decompiled_code:
__int64 __fastcall hashname_free(__int128 *a1)
{
if ( a1 == &hn_vtmp )
return util_sys_log(7LL, "src/lib/hashname.c", 26LL, "hashname_free", "programmer error");
if ( a1 )
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int128 *a1)
{
if ( a1 == &hn_vtmp )
return util_sys_log(7LL, "src/lib/hashname.c", 26LL, "hashname_free", "programmer error");
if ( a1 )
free(a1);
return 0LL;
}

original_code:
hashname_t hashname_free(hashname_t hn)
{
  if(hn == &hn_vtmp) return util_sys_log(7, "src/lib/hashname.c", 26, __func__, "programmer error");
  if(hn) free(hn);
  return ((void *)0);
}

canonical_original_code:
struct hashname_struct *hashname_free(struct hashname_struct *hn)
{
  if(hn == &hn_vtmp) return util_sys_log(7, "src/lib/hashname.c", 26, __func__, "programmer error");
  if(hn) free(hn);
  return ((void *)0);
}

variable_types:
hn
struct hashname_struct *

return_type: struct hashname_struct { unsigned char bin[32]; } *


decompiled_code:
__int64 __fastcall hashname_bin(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1;
}

original_code:
uint8_t *hashname_bin(hashname_t hn)
{
  if(!hn) return ((void *)0);
  return hn->bin;
}

canonical_original_code:
unsigned char *hashname_bin(struct hashname_struct *hn)
{
  if(!hn) return ((void *)0);
  return hn->bin;
}

variable_types: struct hashname_struct { unsigned char bin[32]; } *

return_type: unsigned char *


decompiled_code:
void *__fastcall hashname_char(__int64 a1)
{
if ( !a1 )
return 0LL;
base32_encode(a1, 32LL, &hn_ctmp, 53LL);
return &hn_ctmp;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
if ( !a1 )
return 0LL;
base32_encode(a1, 32LL, &hn_ctmp, 53LL);
return &hn_ctmp;
}

original_code:
char *hashname_char(hashname_t hn)
{
  if(!hn) return ((void *)0);
  base32_encode(hn->bin,32,hn_ctmp,53);
  return hn_ctmp;
}

canonical_original_code:
char *hashname_char(struct hashname_struct *hn)
{
  if(!hn) return ((void *)0);
  base32_encode(hn->bin,32,hn_ctmp,53);
  return hn_ctmp;
}

user_defined_types: struct hashname_struct { unsigned char bin[32]; }


decompiled_code:
int __fastcall hashname_cmp(const void *a1, const void *a2)
{
int result; // eax

if ( a1 && a2 )
result = memcmp(a1, a2, 0x20uLL);
else
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func3(const void *a1, const void *a2)
{
int result; // eax

if ( a1 && a2 )
result = memcmp(a1, a2, 0x20uLL);
else
result = -1;
return result;
}

original_code:
int hashname_cmp(hashname_t a, hashname_t b)
{
  if(!a || !b) return -1;
  return memcmp(a->bin,b->bin,32);
}

canonical_original_code:
int hashname_cmp(struct hashname_struct *a, struct hashname_struct *b)
{
  if(!a || !b) return -1;
  return memcmp(a->bin,b->bin,32);
}

variable_types:
b
struct hashname_struct *


decompiled_code:
__int64 __fastcall hashname_id(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
unsigned int v3; // er13
const char *v4; // rax
const char *v5; // rbp
char v7[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( !a1 || !a2 )
return 0;
v2 = 0;
v3 = 0;
while ( 1 )
{
v4 = (const char *)lob_get_index(a1, v2);
v5 = v4;
if ( !v4 )
break;
if ( strlen(v4) == 2 && lob_get(a2, v5) )
{
v7[0] = 0;
util_unhex(v5, 2LL, v7);
if ( (unsigned __int8)v3 < (unsigned int)v7[0] )
v3 = (unsigned __int8)v7[0];
}
v2 += 2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
unsigned int v3; // er13
const char *v4; // rax
const char *v5; // rbp
char v7[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( !a1 || !a2 )
return 0;
v2 = 0;
v3 = 0;
while ( 1 )
{
v4 = (const char *)lob_get_index(a1, v2);
v5 = v4;
if ( !v4 )
break;
if ( strlen(v4) == 2 && lob_get(a2, v5) )
{
v7[0] = 0;
util_unhex(v5, 2LL, v7);
if ( (unsigned __int8)v3 < (unsigned int)v7[0] )
v3 = (unsigned __int8)v7[0];
}
v2 += 2;
}
return v3;
}

original_code:
uint8_t hashname_id(lob_t a, lob_t b)
{
  uint8_t id, best;
  uint32_t i;
  char *key;
  if(!a || !b) return 0;
  best = 0;
  for(i=0;(key = lob_get_index(a,i));i+=2)
  {
    if(strlen(key) != 2) continue;
    if(!lob_get(b,key)) continue;
    id = 0;
    util_unhex(key,2,&id);
    if(id > best) best = id;
  }
  return best;
}

canonical_original_code:
unsigned char hashname_id(struct lob_struct *a, struct lob_struct *b)
{
  unsigned char id; unsigned char best;
  unsigned int i;
  char *key;
  if(!a || !b) return 0;
  best = 0;
  for(i=0;(key = lob_get_index(a,i));i+=2)
  {
    if(strlen(key) != 2) continue;
    if(!lob_get(b,key)) continue;
    id = 0;
    util_unhex(key,2,&id);
    if(id > best) best = id;
  }
  return best;
}

variable_types: struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *

variable_types:
b
struct lob_struct *

variable_types:
id
unsigned char

variable_types:
best
unsigned char

variable_types:
i
unsigned int

variable_types:
key
char *


decompiled_code:
__int64 __fastcall hashname_im(__int64 a1, char a2)
{
void *v2; // r15
unsigned int v3; // ebx
size_t v4; // rax
const char *v5; // rbp
const char *v6; // r12
size_t v7; // rax
size_t v8; // rax
__int64 v9; // r14
size_t v10; // rax
__int64 v12; // [rsp+0h] [rbp-78h]
char v13[17]; // [rsp+Ch] [rbp-6Ch] BYREF
char v14[3]; // [rsp+1Dh] [rbp-5Bh] BYREF
char v15[88]; // [rsp+20h] [rbp-58h] BYREF

v13[0] = a2;
if ( !a1 )
return util_sys_log(7LL, "src/lib/hashname.c", 155LL, "hashname_im", "bad args");
v2 = 0LL;
v3 = 0;
v12 = lob_new();
util_hex(v13, 1LL, v14);
while ( 1 )
{
v5 = (const char *)lob_get_index(a1, v3);
if ( !v5 )
break;
v6 = (const char *)lob_get_index(a1, v3 + 1);
v7 = strlen(v5);
if ( v6 && v7 == 2 )
{
v8 = strlen(v6);
v9 = base32_decode_floor(v8);
if ( !v13[0] || (unsigned int)util_cmp(v14, v5) )
{
v2 = (void *)util_reallocf(v2, v9);
if ( !v2 )
return lob_free(v12);
v4 = strlen(v6);
if ( base32_decode(v6, v4, v2, v9) == v9 )
{
e3x_hash(v2, v9, v15);
lob_set_base32(v12, v5, v15, 32LL);
}
}
else
{
lob_body(v12, 0LL, v9);
v10 = strlen(v6);
if ( base32_decode(v6, v10, *(_QWORD *)(v12 + 8), v9) == v9 )
lob_set_raw(v12, v5, 0LL, "true", 4LL);
}
}
v3 += 2;
}
if ( v2 )
free(v2);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
void *v2; // r15
unsigned int v3; // ebx
size_t v4; // rax
const char *v5; // rbp
const char *v6; // r12
size_t v7; // rax
size_t v8; // rax
__int64 v9; // r14
size_t v10; // rax
__int64 v12; // [rsp+0h] [rbp-78h]
char v13[17]; // [rsp+Ch] [rbp-6Ch] BYREF
char v14[3]; // [rsp+1Dh] [rbp-5Bh] BYREF
char v15[88]; // [rsp+20h] [rbp-58h] BYREF

v13[0] = a2;
if ( !a1 )
return util_sys_log(7LL, "src/lib/hashname.c", 155LL, "hashname_im", "bad args");
v2 = 0LL;
v3 = 0;
v12 = lob_new();
util_hex(v13, 1LL, v14);
while ( 1 )
{
v5 = (const char *)lob_get_index(a1, v3);
if ( !v5 )
break;
v6 = (const char *)lob_get_index(a1, v3 + 1);
v7 = strlen(v5);
if ( v6 && v7 == 2 )
{
v8 = strlen(v6);
v9 = base32_decode_floor(v8);
if ( !v13[0] || (unsigned int)util_cmp(v14, v5) )
{
v2 = (void *)util_reallocf(v2, v9);
if ( !v2 )
return lob_free(v12);
v4 = strlen(v6);
if ( base32_decode(v6, v4, v2, v9) == v9 )
{
e3x_hash(v2, v9, v15);
lob_set_base32(v12, v5, v15, 32LL);
}
}
else
{
lob_body(v12, 0LL, v9);
v10 = strlen(v6);
if ( base32_decode(v6, v10, *(_QWORD *)(v12 + 8), v9) == v9 )
lob_set_raw(v12, v5, 0LL, "true", 4LL);
}
}
v3 += 2;
}
if ( v2 )
free(v2);
return v12;
}

original_code:
lob_t hashname_im(lob_t keys, uint8_t id)
{
  uint32_t i;
  size_t len;
  uint8_t *buf, hash[32];
  char *key, *value, hex[3];
  lob_t im;
  if(!keys) return util_sys_log(7, "src/lib/hashname.c", 155, __func__, "bad args");
  im = lob_new();
  buf = ((void *)0);
  util_hex(&id,1,hex);
  for(i=0;(key = lob_get_index(keys,i));i+=2)
  {
    value = lob_get_index(keys,i+1);
    if(strlen(key) != 2 || !value) continue;
    len = base32_decode_floor(strlen(value));
    if(id && util_cmp(hex,key) == 0)
    {
      lob_body(im,((void *)0),len);
      if(base32_decode(value,strlen(value),im->body,len) != len) continue;
      lob_set_raw(im,key,0,"true",4);
    }else{
      buf = util_reallocf(buf,len);
      if(!buf) return lob_free(im);
      if(base32_decode(value,strlen(value),buf,len) != len) continue;
      e3x_hash(buf,len,hash);
      lob_set_base32(im,key,hash,32);
    }
  }
  if(buf) free(buf);
  return im;
}

canonical_original_code:
struct lob_struct *hashname_im(struct lob_struct *keys, unsigned char id)
{
  unsigned int i;
  unsigned long len;
  unsigned char *buf; unsigned char hash[32];
  char *key; char *value; char hex[3];
  struct lob_struct *im;
  if(!keys) return util_sys_log(7, "src/lib/hashname.c", 155, __func__, "bad args");
  im = lob_new();
  buf = ((void *)0);
  util_hex(&id,1,hex);
  for(i=0;(key = lob_get_index(keys,i));i+=2)
  {
    value = lob_get_index(keys,i+1);
    if(strlen(key) != 2 || !value) continue;
    len = base32_decode_floor(strlen(value));
    if(id && util_cmp(hex,key) == 0)
    {
      lob_body(im,((void *)0),len);
      if(base32_decode(value,strlen(value),im->body,len) != len) continue;
      lob_set_raw(im,key,0,"true",4);
    }else{
      buf = util_reallocf(buf,len);
      if(!buf) return lob_free(im);
      if(base32_decode(value,strlen(value),buf,len) != len) continue;
      e3x_hash(buf,len,hash);
      lob_set_base32(im,key,hash,32);
    }
  }
  if(buf) free(buf);
  return im;
}

variable_types:
keys
struct lob_struct *

variable_types:
len
unsigned long

variable_types:
buf
unsigned char *

variable_types:
hash
unsigned char [32]

variable_types:
value
char *

variable_types:
hex
char [3]

return_type: struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *


decompiled_code:
__int64 __fastcall hashname_vkeys(__int64 a1)
{
__int64 v1; // rbp
__int128 *v2; // r12

if ( !a1 )
return util_sys_log(7LL, "src/lib/hashname.c", 96LL, "hashname_vkeys", "bad args");
v1 = hashname_im(a1, 0);
v2 = hashname_vkey(v1, 0);
lob_free(v1);
return (__int64)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbp
__int128 *v2; // r12

if ( !a1 )
return util_sys_log(7LL, "src/lib/hashname.c", 96LL, "hashname_vkeys", "bad args");
v1 = func5(a1, 0);
v2 = hashname_vkey(v1, 0);
lob_free(v1);
return (__int64)v2;
}

original_code:
hashname_t hashname_vkeys(lob_t keys)
{
  hashname_t hn;
  lob_t im;
  if(!keys) return util_sys_log(7, "src/lib/hashname.c", 96, __func__, "bad args");
  im = hashname_im(keys,0);
  hn = hashname_vkey(im,0);
  lob_free(im);
  return hn;
}

canonical_original_code:
struct hashname_struct *hashname_vkeys(struct lob_struct *keys)
{
  struct hashname_struct *hn;
  struct lob_struct *im;
  if(!keys) return util_sys_log(7, "src/lib/hashname.c", 96, __func__, "bad args");
  im = hashname_im(keys,0);
  hn = hashname_vkey(im,0);
  lob_free(im);
  return hn;
}

user_defined_types: struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; }


decompiled_code:
char *__fastcall hashname_short(__int64 a1)
{
void *v1; // rdx
unsigned __int64 v2; // rcx

if ( !a1 )
return 0LL;
v1 = &unk_85A;
if ( tog_0 )
v1 = &hn_ctmp;
v2 = (-(__int64)(tog_0 == 0) & 0xFFFFFFFFFFFFFFE6LL) + 53;
tog_0 = tog_0 == 0 ? 0x1A : 0;
base32_encode(a1, 5LL, v1, v2);
return (char *)&hn_ctmp + (unsigned __int8)tog_0;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
void *v1; // rdx
unsigned __int64 v2; // rcx

if ( !a1 )
return 0LL;
v1 = &unk_85A;
if ( tog_0 )
v1 = &hn_ctmp;
v2 = (-(__int64)(tog_0 == 0) & 0xFFFFFFFFFFFFFFE6LL) + 53;
tog_0 = tog_0 == 0 ? 0x1A : 0;
base32_encode(a1, 5LL, v1, v2);
return (char *)&hn_ctmp + (unsigned __int8)tog_0;
}

original_code:
char *hashname_short(hashname_t hn)
{
  static uint8_t tog = 1;
  if(!hn) return ((void *)0);
  tog = tog ? 0 : 26;
  base32_encode(hn->bin,5,hn_ctmp+tog,53-tog);
  return hn_ctmp+tog;
}

canonical_original_code:
char *hashname_short(struct hashname_struct *hn)
{
  static unsigned char tog = 1;
  if(!hn) return ((void *)0);
  tog = tog ? 0 : 26;
  base32_encode(hn->bin,5,hn_ctmp+tog,53-tog);
  return hn_ctmp+tog;
}

variable_types:
tog
unsigned char


decompiled_code:
int __fastcall hashname_scmp(const void *a1, const void *a2)
{
int result; // eax

if ( a1 && a2 )
result = memcmp(a1, a2, 5uLL);
else
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func8(const void *a1, const void *a2)
{
int result; // eax

if ( a1 && a2 )
result = memcmp(a1, a2, 5uLL);
else
result = -1;
return result;
}

original_code:
int hashname_scmp(hashname_t a, hashname_t b)
{
  if(!a || !b) return -1;
  return memcmp(a->bin,b->bin,5);
}

canonical_original_code:
int hashname_scmp(struct hashname_struct *a, struct hashname_struct *b)
{
  if(!a || !b) return -1;
  return memcmp(a->bin,b->bin,5);
}


decompiled_code:
__int64 __fastcall hashname_isshort(__int64 a1)
{
_BYTE *v1; // rax

if ( a1 )
{
v1 = (_BYTE *)(a1 + 5);
while ( !*v1 )
{
if ( ++v1 == (_BYTE *)(a1 + 32) )
return a1;
}
}
return 0LL;
}

original_code:
hashname_t hashname_isshort(hashname_t hn)
{
  if(!hn) return ((void *)0);
  uint8_t i;
  for(i=5;i<32;i++) if(hn->bin[i]) return ((void *)0);
  return hn;
}

canonical_original_code:
struct hashname_struct *hashname_isshort(struct hashname_struct *hn)
{
  if(!hn) return ((void *)0);
  unsigned char i;
  for(i=5;i<32;i++) if(hn->bin[i]) return ((void *)0);
  return hn;
}

variable_types:
i
unsigned char


variable_types:
pcarry
unsigned int *

variable_types:
key
void *

variable_types: len int

variable_types:
c
unsigned int

variable_types:
ptr
unsigned char *

variable_types:
end
unsigned char *

variable_types: n int

variable_types: i int


canonical_original_code:
unsigned int PMurHash32_Result(unsigned int h, unsigned int carry, unsigned int total_length)
{
  unsigned int k1;
  int n = carry & 3;
  if(n) {
    k1 = carry >> (4-n)*8;
    k1 *= (0xcc9e2d51); k1 = (((unsigned int)k1 << 15) | ((unsigned int)k1 >> (32 - 15))); k1 *= (0x1b873593); h ^= k1;
  }
  h ^= total_length;
  h ^= h >> 16;
  h *= 0x85ebca6b;
  h ^= h >> 13;
  h *= 0xc2b2ae35;
  h ^= h >> 16;
  return h;
}

variable_types:
h
unsigned int

variable_types:
carry
unsigned int


decompiled_code:
__int64 __fastcall PMurHash32(int a1, unsigned __int64 a2, unsigned int a3)
{
int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = a1;
v6[0] = 0;
PMurHash32_Process(&v5, v6, a2, a3);
return PMurHash32_Result(v5, v6[0], a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, unsigned __int64 a2, unsigned int a3)
{
int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = a1;
v6[0] = 0;
func0(&v5, v6, a2, a3);
return func1(v5, v6[0], a3);
}

original_code:
uint32_t PMurHash32(uint32_t seed, const void *key, int len)
{
  uint32_t h1=seed, carry=0;
  PMurHash32_Process(&h1, &carry, key, len);
  return PMurHash32_Result(h1, carry, len);
}

canonical_original_code:
unsigned int PMurHash32(unsigned int seed, void *key, int len)
{
  unsigned int h1 = seed; unsigned int carry = 0;
  PMurHash32_Process(&h1, &carry, key, len);
  return PMurHash32_Result(h1, carry, len);
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 __fastcall murmur4(unsigned __int64 a1, unsigned int a2)
{
return PMurHash32(0, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1, unsigned int a2)
{
return func2(0, a1, a2);
}

original_code:
uint32_t murmur4(const uint8_t *data, uint32_t len)
{
  return PMurHash32(0, data, len);
}

canonical_original_code:
unsigned int murmur4(unsigned char *data, unsigned int len)
{
  return PMurHash32(0, data, len);
}

variable_types:
data
unsigned char *

variable_types:
len
unsigned int


decompiled_code:
char *__fastcall murmur8(unsigned __int64 a1, unsigned int a2, char *a3)
{
unsigned int v4; // eax

v4 = PMurHash32(0, a1, a2);
sprintf(a3, "%08lx", v4);
return a3;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned __int64 a1, unsigned int a2, char *a3)
{
unsigned int v4; // eax

v4 = func2(0, a1, a2);
sprintf(a3, "%08lx", v4);
return a3;
}

original_code:
char *murmur8(const uint8_t *data, uint32_t len, char *hex)
{
  uint32_t hash = PMurHash32(0, data, len);
  sprintf(hex,"%08lx",(unsigned long)hash);
  return hex;
}

canonical_original_code:
char *murmur8(unsigned char *data, unsigned int len, char *hex)
{
  unsigned int hash = PMurHash32(0, data, len);
  sprintf(hex,"%08lx",(unsigned long)hash);
  return hex;
}

variable_types:
hex
char *

variable_types:
hash
unsigned int


decompiled_code:
__int64 cs3a_init()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
e3x_cipher_t cs3a_init(lob_t options)
{
  return ((void *)0);
}

canonical_original_code:
struct e3x_cipher_struct *cs3a_init(struct lob_struct *options)
{
  return ((void *)0);
}

variable_types:
options
struct lob_struct *

return_type: struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; } *

user_defined_types: struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; }


original_code:
size_t base32_decode(const char *encoded, size_t length, uint8_t *result, size_t bufSize) {
  int buffer = 0;
  size_t bitsLeft = 0;
  size_t count = 0;
  const char *ptr = encoded;
  if(!encoded || !result || bufSize <= 0) return 0;
  if(!length) length = strlen(encoded);
  for (; (size_t)(ptr-encoded) < length && count < bufSize; ++ptr) {
    uint8_t ch = (uint8_t)*ptr;
    if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-') {
      continue;
    }
    buffer <<= 5;
    if (ch == '0') {
      ch = 'O';
    } else if (ch == '1') {
      ch = 'L';
    } else if (ch == '8') {
      ch = 'B';
    }
    if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
      ch = (ch & 0x1F) - 1;
    } else if (ch >= '2' && ch <= '7') {
      ch -= '2' - 26;
    } else {
      return 0;
    }
    buffer |= ch;
    bitsLeft += 5;
    if (bitsLeft >= 8) {
      result[count++] = buffer >> (bitsLeft - 8);
      bitsLeft -= 8;
    }
  }
  if (count < bufSize) {
    result[count] = '\000';
  }
  return count;
}

canonical_original_code:
unsigned long base32_decode(char *encoded, unsigned long length, unsigned char *result, unsigned long bufSize) {
  int buffer = 0;
  unsigned long bitsLeft = 0;
  unsigned long count = 0;
  char *ptr = encoded;
  if(!encoded || !result || bufSize <= 0) return 0;
  if(!length) length = strlen(encoded);
  for (; (unsigned long)(ptr-encoded) < length && count < bufSize; ++ptr) {
    unsigned char ch = (uint8_t)*ptr;
    if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-') {
      continue;
    }
    buffer <<= 5;
    if (ch == '0') {
      ch = 'O';
    } else if (ch == '1') {
      ch = 'L';
    } else if (ch == '8') {
      ch = 'B';
    }
    if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
      ch = (ch & 0x1F) - 1;
    } else if (ch >= '2' && ch <= '7') {
      ch -= '2' - 26;
    } else {
      return 0;
    }
    buffer |= ch;
    bitsLeft += 5;
    if (bitsLeft >= 8) {
      result[count++] = buffer >> (bitsLeft - 8);
      bitsLeft -= 8;
    }
  }
  if (count < bufSize) {
    result[count] = '\000';
  }
  return count;
}

variable_types:
encoded
char *

variable_types:
length
unsigned long

variable_types:
result
unsigned char *

variable_types:
bufSize
unsigned long

variable_types: buffer int

variable_types:
bitsLeft
unsigned long

variable_types:
count
unsigned long

variable_types:
ptr
char *

variable_types:
ch
unsigned char

return_type: unsigned long