decompiled_code:
void __fastcall midi_register_pitchbend_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 40) = a2;
}

original_code:
void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_t func){
   device->input_pitchbend_callback = func;
}

canonical_original_code:
void midi_register_pitchbend_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_pitchbend_callback = func;
}


decompiled_code:
void __fastcall midi_register_songposition_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 48) = a2;
}

original_code:
void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_func_t func){
   device->input_songposition_callback = func;
}

canonical_original_code:
void midi_register_songposition_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_songposition_callback = func;
}

variable_types: struct _midi_device { void (*send_func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_cc_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteon_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteoff_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_aftertouch_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_pitchbend_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_songposition_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_progchange_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_chanpressure_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_songselect_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_tc_quarterframe_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_realtime_callback)(struct _midi_device *device, unsigned char byte); void (*input_tunerequest_callback)(struct _midi_device *device, unsigned char byte); void (*input_sysex_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_fallthrough_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_catchall_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*pre_input_process_callback)(struct _midi_device *device); unsigned char input_buffer[3]; enum input_state_t { IDLE=0, ONE_BYTE_MESSAGE=1, TWO_BYTE_MESSAGE=2, THREE_BYTE_MESSAGE=3, SYSEX_MESSAGE=4 } input_state; unsigned short input_count; unsigned char input_queue_data[192]; struct byteQueue_t { unsigned char start; unsigned char end; unsigned char length; unsigned char *data; } input_queue; } *

variable_types: void (*)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)

return_type: void

user_defined_types: struct _midi_device { void (*send_func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_cc_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteon_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteoff_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_aftertouch_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_pitchbend_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_songposition_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_progchange_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_chanpressure_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_songselect_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_tc_quarterframe_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_realtime_callback)(struct _midi_device *device, unsigned char byte); void (*input_tunerequest_callback)(struct _midi_device *device, unsigned char byte); void (*input_sysex_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_fallthrough_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_catchall_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*pre_input_process_callback)(struct _midi_device *device); unsigned char input_buffer[3]; enum input_state_t input_state; unsigned short input_count; unsigned char input_queue_data[192]; struct byteQueue_t input_queue; }


decompiled_code:
void __fastcall midi_register_progchange_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 56) = a2;
}

original_code:
void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t func) {
   device->input_progchange_callback = func;
}

canonical_original_code:
void midi_register_progchange_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1)) {
   device->input_progchange_callback = func;
}

variable_types: void (*)(struct _midi_device *device, unsigned char byte0, unsigned char byte1)

user_defined_types: enum input_state_t { IDLE=0, ONE_BYTE_MESSAGE=1, TWO_BYTE_MESSAGE=2, THREE_BYTE_MESSAGE=3, SYSEX_MESSAGE=4 }

user_defined_types: struct byteQueue_t { unsigned char start; unsigned char end; unsigned char length; unsigned char *data; }


decompiled_code:
void __fastcall midi_register_chanpressure_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 64) = a2;
}

original_code:
void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func_t func) {
   device->input_chanpressure_callback = func;
}

canonical_original_code:
void midi_register_chanpressure_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1)) {
   device->input_chanpressure_callback = func;
}


decompiled_code:
void __fastcall midi_register_songselect_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 72) = a2;
}

original_code:
void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t func) {
   device->input_songselect_callback = func;
}

canonical_original_code:
void midi_register_songselect_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1)) {
   device->input_songselect_callback = func;
}


decompiled_code:
void __fastcall midi_register_tc_quarterframe_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 80) = a2;
}

original_code:
void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_func_t func) {
   device->input_tc_quarterframe_callback = func;
}

canonical_original_code:
void midi_register_tc_quarterframe_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1)) {
   device->input_tc_quarterframe_callback = func;
}


decompiled_code:
void __fastcall midi_register_realtime_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 88) = a2;
}

original_code:
void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t func){
   device->input_realtime_callback = func;
}

canonical_original_code:
void midi_register_realtime_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte)){
   device->input_realtime_callback = func;
}

variable_types: void (*)(struct _midi_device *device, unsigned char byte)


decompiled_code:
void __fastcall midi_register_tunerequest_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 96) = a2;
}

original_code:
void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_t func){
   device->input_tunerequest_callback = func;
}

canonical_original_code:
void midi_register_tunerequest_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte)){
   device->input_tunerequest_callback = func;
}


decompiled_code:
void __fastcall midi_register_sysex_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 104) = a2;
}

original_code:
void midi_register_sysex_callback(MidiDevice * device, midi_var_byte_func_t func){
   device->input_sysex_callback = func;
}

canonical_original_code:
void midi_register_sysex_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_sysex_callback = func;
}

variable_types: void (*)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2)


decompiled_code:
void __fastcall midi_register_fallthrough_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 112) = a2;
}

original_code:
void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_t func){
   device->input_fallthrough_callback = func;
}

canonical_original_code:
void midi_register_fallthrough_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_fallthrough_callback = func;
}


decompiled_code:
void __fastcall midi_register_catchall_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 120) = a2;
}

original_code:
void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t func){
   device->input_catchall_callback = func;
}

canonical_original_code:
void midi_register_catchall_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_catchall_callback = func;
}


updatePot

decompiled_code:
__int64 __fastcall updatePot(int a1)
{
int v1; // er15
int v2; // er14
int v3; // er13
int v4; // ebx
char v5; // r8
int v6; // eax
__int16 v7; // bx
int v8; // eax
__int64 result; // rax
int v10; // [rsp+0h] [rbp-3Ch]

v1 = -32768;
v2 = 0;
io_write(10LL, (32 >> (a1 >> 4)) | a1 & 0xFu);
v3 = (unsigned __int8)potBitDepth[a1];
v10 = 0xFFFF >> (16 - potBitDepth[a1]) << (16 - potBitDepth[a1]);
v4 = -1;
do
{
dac_write((unsigned __int16)v4);
v5 = io_read(9LL);
v6 = v4 + v1;
v4 -= v1;
if ( (v5 & 8) != 0 )
v4 = v6;
++v2;
LOWORD(v1) = (unsigned __int16)v1 >> 1;
}
while ( (char)v2 <= v3 );
io_write(10LL, 255LL);
v7 = v10 & v4;
v8 = (unsigned __int8)byte_244[a1];
word_264[a1] = v7;
result = abs32(v8 - HIBYTE(v7));
if ( (int)result > 4 )
{
byte_244[a1] = HIBYTE(v7);
result = (unsigned int)(1 << a1);
potmux |= result;
dword_2A8 = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // er15
int v2; // er14
int v3; // er13
int v4; // ebx
char v5; // r8
int v6; // eax
__int16 v7; // bx
int v8; // eax
__int64 result; // rax
int v10; // [rsp+0h] [rbp-3Ch]

v1 = -32768;
v2 = 0;
io_write(10LL, (32 >> (a1 >> 4)) | a1 & 0xFu);
v3 = (unsigned __int8)potBitDepth[a1];
v10 = 0xFFFF >> (16 - potBitDepth[a1]) << (16 - potBitDepth[a1]);
v4 = -1;
do
{
dac_write((unsigned __int16)v4);
v5 = io_read(9LL);
v6 = v4 + v1;
v4 -= v1;
if ( (v5 & 8) != 0 )
v4 = v6;
++v2;
LOWORD(v1) = (unsigned __int16)v1 >> 1;
}
while ( (char)v2 <= v3 );
io_write(10LL, 255LL);
v7 = v10 & v4;
v8 = (unsigned __int8)byte_244[a1];
word_264[a1] = v7;
result = abs32(v8 - HIBYTE(v7));
if ( (int)result > 4 )
{
byte_244[a1] = HIBYTE(v7);
result = (unsigned int)(1 << a1);
potmux |= result;
dword_2A8 = a1;
}
return result;
}

original_code:
static void updatePot(p600Pot_t pot)
{
 int8_t i,lower;
 uint8_t mux,bitDepth,cdv;
 uint16_t estimate,badMask;
 uint16_t bit;

 {
  mux=(pot&0x0f)|(0x20>>(pot>>4));
  io_write(0x0a,mux);
  ;
  estimate=(65535);
  bit=0x8000;
  bitDepth=potBitDepth[pot];
  badMask=16-bitDepth;
  badMask=((65535)>>badMask)<<badMask;
  for(i=0;i<=bitDepth;++i)
  {
   dac_write(estimate);
   ;
   lower=(io_read(0x09)&0x08)!=0;
   if (lower)
    estimate+=bit;
   else
    estimate-=bit;
   bit>>=1;
  }
  io_write(0x0a,0xff);
  ;
  estimate&=badMask;
  potmux.pots[pot]=estimate;
  cdv=estimate>>8;
  if(abs(potmux.changeDetect[pot]-cdv)>4)
  {
   potmux.changeDetect[pot]=cdv;
   potmux.potChanged|=(uint32_t)1<<pot;
   potmux.lastChanged=pot;
  }
 }
}

canonical_original_code:
static void updatePot(enum p600Pot_t pot)
{
 char i; char lower;
 unsigned char mux; unsigned char bitDepth; unsigned char cdv;
 unsigned short estimate; unsigned short badMask;
 unsigned short bit;

 {
  mux=(pot&0x0f)|(0x20>>(pot>>4));
  io_write(0x0a,mux);
  ;
  estimate=(65535);
  bit=0x8000;
  bitDepth=potBitDepth[pot];
  badMask=16-bitDepth;
  badMask=((65535)>>badMask)<<badMask;
  for(i=0;i<=bitDepth;++i)
  {
   dac_write(estimate);
   ;
   lower=(io_read(0x09)&0x08)!=0;
   if (lower)
    estimate+=bit;
   else
    estimate-=bit;
   bit>>=1;
  }
  io_write(0x0a,0xff);
  ;
  estimate&=badMask;
  potmux.pots[pot]=estimate;
  cdv=estimate>>8;
  if(abs(potmux.changeDetect[pot]-cdv)>4)
  {
   potmux.changeDetect[pot]=cdv;
   potmux.potChanged|=(unsigned int)1<<pot;
   potmux.lastChanged=pot;
  }
 }
}

variable_types: enum p600Pot_t { ppNone=-1, ppMixer=0, ppCutoff=1, ppResonance=2, ppFilEnvAmt=3, ppFilRel=4, ppFilSus=5, ppFilDec=6, ppFilAtt=7, ppAmpRel=8, ppAmpSus=9, ppAmpDec=10, ppAmpAtt=11, ppGlide=12, ppBPW=13, ppMVol=14, ppMTune=15, ppPitchWheel=16, ppModWheel=22, ppSpeed=23, ppAPW=24, ppPModFilEnv=25, ppLFOFreq=26, ppPModOscB=27, ppLFOAmt=28, ppFreqB=29, ppFreqA=30, ppFreqBFine=31 }

variable_types: i char

variable_types: lower char

variable_types:
mux
unsigned char

variable_types:
bitDepth
unsigned char

variable_types:
cdv
unsigned char

variable_types:
estimate
unsigned short

variable_types:
badMask
unsigned short

variable_types:
bit
unsigned short


decompiled_code:
__int64 __fastcall potmux_getValue(int a1)
{
return (unsigned __int16)word_264[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned __int16)word_264[a1];
}

original_code:
inline __attribute__((always_inline)) uint16_t potmux_getValue(p600Pot_t pot)
{
 return potmux.pots[pot];
}

canonical_original_code:
inline unsigned short potmux_getValue(enum p600Pot_t pot)
{
 return potmux.pots[pot];
}

return_type: unsigned short

user_defined_types: enum p600Pot_t { ppNone=-1, ppMixer=0, ppCutoff=1, ppResonance=2, ppFilEnvAmt=3, ppFilRel=4, ppFilSus=5, ppFilDec=6, ppFilAtt=7, ppAmpRel=8, ppAmpSus=9, ppAmpDec=10, ppAmpAtt=11, ppGlide=12, ppBPW=13, ppMVol=14, ppMTune=15, ppPitchWheel=16, ppModWheel=22, ppSpeed=23, ppAPW=24, ppPModFilEnv=25, ppLFOFreq=26, ppPModOscB=27, ppLFOAmt=28, ppFreqB=29, ppFreqA=30, ppFreqBFine=31 }


decompiled_code:
bool __fastcall potmux_hasChanged(char a1)
{
return (potmux & (1 << a1)) != 0;
}

canonical_decompiled_code:
bool __fastcall func2(char a1)
{
return (potmux & (1 << a1)) != 0;
}

original_code:
inline __attribute__((always_inline)) int8_t potmux_hasChanged(p600Pot_t pot)
{
 return (potmux.potChanged&((uint32_t)1<<pot))!=0;
}

canonical_original_code:
inline char potmux_hasChanged(enum p600Pot_t pot)
{
 return (potmux.potChanged&((unsigned int)1<<pot))!=0;
}

return_type: char


decompiled_code:
__int64 potmux_lastChanged()
{
return (unsigned int)dword_2A8;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)dword_2A8;
}

original_code:
inline __attribute__((always_inline)) p600Pot_t potmux_lastChanged(void)
{
 return potmux.lastChanged;
}

canonical_original_code:
inline enum p600Pot_t potmux_lastChanged()
{
 return potmux.lastChanged;
}

return_type: enum p600Pot_t { ppNone=-1, ppMixer=0, ppCutoff=1, ppResonance=2, ppFilEnvAmt=3, ppFilRel=4, ppFilSus=5, ppFilDec=6, ppFilAtt=7, ppAmpRel=8, ppAmpSus=9, ppAmpDec=10, ppAmpAtt=11, ppGlide=12, ppBPW=13, ppMVol=14, ppMTune=15, ppPitchWheel=16, ppModWheel=22, ppSpeed=23, ppAPW=24, ppPModFilEnv=25, ppLFOFreq=26, ppPModOscB=27, ppLFOAmt=28, ppFreqB=29, ppFreqA=30, ppFreqBFine=31 }


decompiled_code:
void potmux_resetChanged()
{
potmux = 0;
dword_2A8 = -1;
}

canonical_decompiled_code:
void func4()
{
potmux = 0;
dword_2A8 = -1;
}

original_code:
inline __attribute__((always_inline)) void potmux_resetChanged(void)
{
 potmux.potChanged=0;
 potmux.lastChanged=ppNone;
}

canonical_original_code:
inline void potmux_resetChanged()
{
 potmux.potChanged=0;
 potmux.lastChanged=ppNone;
}


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

result = 0LL;
if ( a1 <= 0x1F )
result = (0x82018008uLL >> a1) & 1;
return result;
}

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

result = 0LL;
if ( a1 <= 0x1F )
result = (0x82018008uLL >> a1) & 1;
return result;
}

original_code:
int8_t potmux_isPotZeroCentered(p600Pot_t pot)
{
 return pot==ppFilEnvAmt || pot==ppPModFilEnv || pot==ppFreqBFine || pot==ppMTune || pot==ppPitchWheel;
}

canonical_original_code:
char potmux_isPotZeroCentered(enum p600Pot_t pot)
{
 return pot==ppFilEnvAmt || pot==ppPModFilEnv || pot==ppFreqBFine || pot==ppMTune || pot==ppPitchWheel;
}


decompiled_code:
__int64 __fastcall potmux_update(unsigned __int8 a1)
{
char v2; // di
int v3; // ebp

v2 = byte_2A4;
if ( a1 )
{
v3 = 0;
do
{
updatePot(v2);
v2 = 22;
if ( byte_2A4 != 16 )
v2 = (byte_2A4 + 1) % 32;
++v3;
byte_2A4 = v2;
}
while ( (__int16)v3 < (int)a1 );
}
updatePot(1);
updatePot(16);
updatePot(30);
return updatePot(29);
}

original_code:
inline void potmux_update(uint8_t regularPotCount)
{
 int16_t i;
 for(i=0;i<regularPotCount;++i)
 {
  updatePot(potmux.currentRegularPot);
  if(potmux.currentRegularPot==ppPitchWheel)
   potmux.currentRegularPot=ppModWheel;
  else
   potmux.currentRegularPot=(potmux.currentRegularPot+1)%32;
 }
 for(i=0;i<4;++i)
  updatePot(priorityPots[i]);
}

canonical_original_code:
inline void potmux_update(unsigned char regularPotCount)
{
 short i;
 for(i=0;i<regularPotCount;++i)
 {
  updatePot(potmux.currentRegularPot);
  if(potmux.currentRegularPot==ppPitchWheel)
   potmux.currentRegularPot=ppModWheel;
  else
   potmux.currentRegularPot=(potmux.currentRegularPot+1)%32;
 }
 for(i=0;i<4;++i)
  updatePot(priorityPots[i]);
}

variable_types:
regularPotCount
unsigned char

variable_types: i short


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

result = 0LL;
dword_2A8 = -1;
memset(&potmux, 0, 0x68uLL);
return result;
}

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

result = 0LL;
dword_2A8 = -1;
memset(&potmux, 0, 0x68uLL);
return result;
}

original_code:
void potmux_init(void)
{
 memset(&potmux,0,sizeof(potmux));
 potmux.lastChanged=ppNone;
}

canonical_original_code:
void potmux_init()
{
 memset(&potmux,0,sizeof(potmux));
 potmux.lastChanged=ppNone;
}


decompiled_code:
__int64 __fastcall satAddU16U16(int a1, int a2)
{
__int16 v2; // ax
unsigned int v3; // edi
bool v4; // cf
__int64 result; // rax

v2 = a1;
v3 = a2 + a1;
v4 = (unsigned __int16)~v2 < (unsigned __int16)a2;
result = 0xFFFFFFFFLL;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int16 v2; // ax
unsigned int v3; // edi
bool v4; // cf
__int64 result; // rax

v2 = a1;
v3 = a2 + a1;
v4 = (unsigned __int16)~v2 < (unsigned __int16)a2;
result = 0xFFFFFFFFLL;
if ( !v4 )
result = v3;
return result;
}

original_code:
inline uint16_t satAddU16U16(uint16_t a, uint16_t b)
{
 uint16_t r;
 r = (b > (65535) - a) ? (65535) : b + a;
 return r;
}

canonical_original_code:
inline unsigned short satAddU16U16(unsigned short a, unsigned short b)
{
 unsigned short r;
 r = (b > (65535) - a) ? (65535) : b + a;
 return r;
}

variable_types:
a
unsigned short

variable_types:
b
unsigned short

variable_types:
r
unsigned short


decompiled_code:
__int64 __fastcall satAddU16S32(unsigned __int16 a1, int a2)
{
int v2; // edi
__int64 result; // rax

v2 = a2 + a1;
if ( v2 < 0 )
v2 = 0;
result = 0xFFFFLL;
if ( v2 <= 0xFFFF )
result = (unsigned int)v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1, int a2)
{
int v2; // edi
__int64 result; // rax

v2 = a2 + a1;
if ( v2 < 0 )
v2 = 0;
result = 0xFFFFLL;
if ( v2 <= 0xFFFF )
result = (unsigned int)v2;
return result;
}

canonical_original_code:
inline unsigned short satAddU16S32(unsigned short a, int b)
{
 int r;
 r=a;
 r+=b;
 r=(((r)>(0))?(r):(0));
 r=(((r)<((65535)))?(r):((65535)));
 return (unsigned short)r;
}

variable_types: b int

variable_types: r int


decompiled_code:
__int64 __fastcall satAddU16S16(unsigned __int16 a1, __int16 a2)
{
bool v2; // sf
unsigned int v3; // esi
__int64 result; // rax

v2 = a1 + a2 < 0;
v3 = a1 + a2;
result = 0LL;
if ( !v2 )
result = v3;
if ( (int)result > 0xFFFF )
result = 0xFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1, __int16 a2)
{
bool v2; // sf
unsigned int v3; // esi
__int64 result; // rax

v2 = a1 + a2 < 0;
v3 = a1 + a2;
result = 0LL;
if ( !v2 )
result = v3;
if ( (int)result > 0xFFFF )
result = 0xFFFFLL;
return result;
}

canonical_original_code:
inline unsigned short satAddU16S16(unsigned short a, short b)
{
 int r;
 r=a;
 r+=b;
 r=(((r)>(0))?(r):(0));
 r=(((r)<((65535)))?(r):((65535)));
 return r;
}

variable_types: b short


lerp

decompiled_code:
__int64 __fastcall lerp(int a1, unsigned __int16 a2, unsigned __int8 a3)
{
return ((a2 - (unsigned __int16)a1) >> 8) * (unsigned int)a3 + a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned __int16 a2, unsigned __int8 a3)
{
return ((a2 - (unsigned __int16)a1) >> 8) * (unsigned int)a3 + a1;
}

original_code:
inline uint16_t lerp(uint16_t a,uint16_t b,uint8_t x)
{
 return a+(x*((b-a)>>8));
}

canonical_original_code:
inline unsigned short lerp(unsigned short a, unsigned short b, unsigned char x)
{
 return a+(x*((b-a)>>8));
}

variable_types:
x
unsigned char


computeShape

decompiled_code:
__int64 __fastcall computeShape(unsigned int a1, __int64 a2, char a3)
{
__int64 v3; // rax
unsigned int v4; // edi
__int64 v5; // rcx

v3 = HIWORD(a1);
if ( !a3 )
return *(unsigned __int16 *)(a2 + 2 * v3);
v4 = a1 >> 8;
v5 = 510LL;
if ( (_BYTE)v3 != 0xFF )
v5 = 2LL * (unsigned __int8)(v3 + 1);
return lerp(*(unsigned __int16 *)(a2 + 2LL * (unsigned __int8)v3), *(_WORD *)(a2 + v5), v4);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, char a3)
{
__int64 v3; // rax
unsigned int v4; // edi
__int64 v5; // rcx

v3 = HIWORD(a1);
if ( !a3 )
return *(unsigned __int16 *)(a2 + 2 * v3);
v4 = a1 >> 8;
v5 = 510LL;
if ( (_BYTE)v3 != 0xFF )
v5 = 2LL * (unsigned __int8)(v3 + 1);
return func3(*(unsigned __int16 *)(a2 + 2LL * (unsigned __int8)v3), *(_WORD *)(a2 + v5), v4);
}

original_code:
inline uint16_t computeShape(uint32_t phase, const uint16_t lookup[], int8_t interpolate)
{
 uint8_t ai,bi,x;
 uint16_t a,b;
 if(interpolate)
 {
  x=phase>>8;
  bi=ai=phase>>16;
  if(ai<(255))
   bi=ai+1;
  a=lookup[ai];
  b=lookup[bi];
  return lerp(a,b,x);
 }
 else
 {
  return lookup[phase>>16];
 }
}

canonical_original_code:
inline unsigned short computeShape(unsigned int phase, unsigned short lookup[], char interpolate)
{
 unsigned char ai; unsigned char bi; unsigned char x;
 unsigned short a; unsigned short b;
 if(interpolate)
 {
  x=phase>>8;
  bi=ai=phase>>16;
  if(ai<(255))
   bi=ai+1;
  a=lookup[ai];
  b=lookup[bi];
  return lerp(a,b,x);
 }
 else
 {
  return lookup[phase>>16];
 }
}

variable_types:
phase
unsigned int

variable_types:
lookup
unsigned short []

variable_types: interpolate char

variable_types:
ai
unsigned char

variable_types:
bi
unsigned char


decompiled_code:
__int64 __fastcall scaleU16U16(unsigned __int16 a1, unsigned __int16 a2)
{
return (a2 * (unsigned int)a1) >> 16;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 a1, unsigned __int16 a2)
{
return (a2 * (unsigned int)a1) >> 16;
}

original_code:
inline uint16_t scaleU16U16(uint16_t a, uint16_t b)
{
 uint16_t r;
 r=((uint32_t)a*b)>>16;
 return r;
}

canonical_original_code:
inline unsigned short scaleU16U16(unsigned short a, unsigned short b)
{
 unsigned short r;
 r=((unsigned int)a*b)>>16;
 return r;
}


decompiled_code:
__int64 __fastcall scaleU16S16(unsigned __int16 a1, __int16 a2)
{
return (unsigned int)((a2 * a1) >> 16);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1, __int16 a2)
{
return (unsigned int)((a2 * a1) >> 16);
}

original_code:
inline int16_t scaleU16S16(uint16_t a, int16_t b)
{
 uint16_t r;
 r=((int32_t)a*b)>>16;
 return r;
}

canonical_original_code:
inline short scaleU16S16(unsigned short a, short b)
{
 unsigned short r;
 r=((int)a*b)>>16;
 return r;
}

return_type: short


lfsr

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

result = a1;
v3 = a2 - 1;
if ( (_BYTE)a2 )
{
do
{
--v3;
result = (2 * (_DWORD)result) | ((BYTE3(result) >> 1) ^ BYTE3(result) ^ ((int)result < 0) ^ ((unsigned int)result >> 29)) & 1;
}
while ( (_BYTE)v3 != 0xFF );
}
return result;
}

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

result = a1;
v3 = a2 - 1;
if ( (_BYTE)a2 )
{
do
{
--v3;
result = (2 * (_DWORD)result) | ((BYTE3(result) >> 1) ^ BYTE3(result) ^ ((int)result < 0) ^ ((unsigned int)result >> 29)) & 1;
}
while ( (_BYTE)v3 != 0xFF );
}
return result;
}

canonical_original_code:
inline unsigned int lfsr(unsigned int v, unsigned char taps)
{
 unsigned char b24;
 while(taps--)
 {
  b24=v>>24;
  v<<=1;
  v|=((b24>>7)^(b24>>5)^(b24>>1)^b24)&1;
 }
 return v;
}

variable_types:
v
unsigned int

variable_types:
taps
unsigned char

return_type: unsigned int


exponentialCourse

decompiled_code:
__int64 __fastcall exponentialCourse(unsigned __int16 a1, float a2, float a3)
{
return (unsigned int)(int)(float)(expf(COERCE_FLOAT(COERCE_UNSIGNED_INT((float)a1) ^ LC0) / a2) * a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int16 a1, float a2, float a3)
{
return (unsigned int)(int)(float)(expf(COERCE_FLOAT(COERCE_UNSIGNED_INT((float)a1) ^ LC0) / a2) * a3);
}

original_code:
uint16_t exponentialCourse(uint16_t v, float ratio, float range)
{
 return expf(-(float)v/ratio)*range;
}

canonical_original_code:
unsigned short exponentialCourse(unsigned short v, float ratio, float range)
{
 return expf(-(float)v/ratio)*range;
}

variable_types:
v
unsigned short

variable_types: ratio float

variable_types: range float


decompiled_code:
__int64 __fastcall uint16Compare(_WORD *a1, _WORD *a2)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a2 )
result = *a1 < *a2 ? -1 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_WORD *a1, _WORD *a2)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a2 )
result = *a1 < *a2 ? -1 : 1;
return result;
}

original_code:
int uint16Compare(const void * a,const void * b)
{
 if (*(uint16_t*)a==*(uint16_t*)b)
  return 0;
 else if (*(uint16_t*)a < *(uint16_t*)b)
  return -1;
 else
  return 1;
}

canonical_original_code:
int uint16Compare(void *a, void *b)
{
 if (*(unsigned short *)a==*(unsigned short *)b)
  return 0;
 else if (*(unsigned short *)a < *(unsigned short *)b)
  return -1;
 else
  return 1;
}

variable_types:
a
void *

variable_types:
b
void *

return_type: int


decompiled_code:
__int64 storageRead32()
{
unsigned int v0; // er8

v0 = *(_DWORD *)qword_D40;
qword_D40 += 4LL;
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er8

v0 = *(_DWORD *)qword_D40;
qword_D40 += 4LL;
return v0;
}

original_code:
static uint32_t storageRead32(void)
{
 uint32_t v;
 v=*(uint32_t*)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}

canonical_original_code:
static unsigned int storageRead32()
{
 unsigned int v;
 v=*(unsigned int *)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}


decompiled_code:
__int64 storageRead16()
{
unsigned int v0; // er8

v0 = *(unsigned __int16 *)qword_D40;
qword_D40 += 2LL;
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er8

v0 = *(unsigned __int16 *)qword_D40;
qword_D40 += 2LL;
return v0;
}

original_code:
static uint16_t storageRead16(void)
{
 uint16_t v;
 v=*(uint16_t*)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}

canonical_original_code:
static unsigned short storageRead16()
{
 unsigned short v;
 v=*(unsigned short *)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}


decompiled_code:
__int64 storageRead8()
{
return *(unsigned __int8 *)qword_D40++;
}

canonical_decompiled_code:
__int64 func2()
{
return *(unsigned __int8 *)qword_D40++;
}

original_code:
static uint8_t storageRead8(void)
{
 uint8_t v;
 v=*(uint8_t*)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}

canonical_original_code:
static unsigned char storageRead8()
{
 unsigned char v;
 v=*(unsigned char *)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}

variable_types:
v
unsigned char

return_type: unsigned char


decompiled_code:
__int64 storageReadS8()
{
return *(unsigned __int8 *)qword_D40++;
}

canonical_decompiled_code:
__int64 func3()
{
return *(unsigned __int8 *)qword_D40++;
}

original_code:
static int8_t storageReadS8(void)
{
 int8_t v;
 v=*(int8_t*)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}

canonical_original_code:
static char storageReadS8()
{
 char v;
 v=*(char *)storage.bufPtr;
 storage.bufPtr+=sizeof(v);
 return v;
}

variable_types: v char


decompiled_code:
__int64 __fastcall storageWrite16(__int16 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = qword_D40;
*(_WORD *)qword_D40 = a1;
result = v1 + 2;
qword_D40 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = qword_D40;
*(_WORD *)qword_D40 = a1;
result = v1 + 2;
qword_D40 = result;
return result;
}

original_code:
static void storageWrite16(uint16_t v)
{
 *(uint16_t*)storage.bufPtr=v;
 storage.bufPtr+=sizeof(v);
}

canonical_original_code:
static void storageWrite16(unsigned short v)
{
 *(unsigned short *)storage.bufPtr=v;
 storage.bufPtr+=sizeof(v);
}


decompiled_code:
__int64 __fastcall storageWrite8(char a1)
{
__int64 result; // rax

result = qword_D40;
*(_BYTE *)qword_D40++ = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
__int64 result; // rax

result = qword_D40;
*(_BYTE *)qword_D40++ = a1;
return result;
}

original_code:
static void storageWrite8(uint8_t v)
{
 *(uint8_t*)storage.bufPtr=v;
 storage.bufPtr+=sizeof(v);
}

canonical_original_code:
static void storageWrite8(unsigned char v)
{
 *(unsigned char *)storage.bufPtr=v;
 storage.bufPtr+=sizeof(v);
}


decompiled_code:
__int64 __fastcall storageWriteS8(char a1)
{
__int64 result; // rax

result = qword_D40;
*(_BYTE *)qword_D40++ = a1;
return result;
}

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

result = qword_D40;
*(_BYTE *)qword_D40++ = a1;
return result;
}

original_code:
static void storageWriteS8(int8_t v)
{
 *(int8_t*)storage.bufPtr=v;
 storage.bufPtr+=sizeof(v);
}

canonical_original_code:
static void storageWriteS8(char v)
{
 *(char *)storage.bufPtr=v;
 storage.bufPtr+=sizeof(v);
}


storagePrepareStore

decompiled_code:
__int64 storagePrepareStore()
{
byte_D48 = 7;
qword_D40 = (__int64)&storage;
memset(&storage, 0, 0x200uLL);
storageWrite32_constprop_0();
return storageWrite8(byte_D48);
}

canonical_decompiled_code:
__int64 func10()
{
byte_D48 = 7;
qword_D40 = (__int64)&storage;
memset(&storage, 0, 0x200uLL);
func9();
return func5(byte_D48);
}

original_code:
static void storagePrepareStore(void)
{
 memset(storage.buffer,0,sizeof(storage.buffer));
 storage.bufPtr=storage.buffer;
 storage.version=7;
 storageWrite32(0x006116a5);
 storageWrite8(storage.version);
}

canonical_original_code:
static void storagePrepareStore()
{
 memset(storage.buffer,0,sizeof(storage.buffer));
 storage.bufPtr=storage.buffer;
 storage.version=7;
 storageWrite32(0x006116a5);
 storageWrite8(storage.version);
}


decompiled_code:
__int64 settings_load()
{
__int64 result; // rax
unsigned __int64 v1; // rcx
bool v2; // zf
char *v3; // rdx
__int16 v4; // ax
__int64 v5; // rdx
char *v6; // rcx
__int64 v7; // rdx
char v8; // al
bool v9; // cc
char v10; // al
char v11; // al
char v12; // al
char v13; // al
__int64 v14; // rdx

result = storageLoad(0xDCu, 2);
if ( (_BYTE)result )
{
v1 = (unsigned int)((_DWORD)&settings + 36);
v2 = byte_D48 == 0;
*((_BYTE *)&settings + 295) = 63;
*(_WORD *)((char *)&settings + 297) = 0;
*((_WORD *)&settings + 150) = 0x8000;
if ( !v2 )
{
do
{
v3 = (char *)(v1 - 36);
do
{
v4 = storageRead16(220LL, 2LL, v3);
v3 = (char *)(v5 + 2);
*((_WORD *)v3 - 1) = v4;
}
while ( v3 != v6 );
v1 = (unsigned __int64)(v3 + 36);
}
while ( v3 != (char *)&settings + 288 );
*((_WORD *)&settings + 145) = storageRead16(220LL, 2LL, v3);
*((_WORD *)&settings + 144) = storageRead16(220LL, 2LL, v7);
*((_BYTE *)&settings + 292) = storageRead8();
v8 = storageReadS8();
v9 = (unsigned __int8)byte_D48 <= 1u;
*((_BYTE *)&settings + 293) = v8;
if ( !v9 )
{
*((_BYTE *)&settings + 295) = storageRead8();
v10 = storageReadS8();
v9 = (unsigned __int8)byte_D48 <= 2u;
*((_BYTE *)&settings + 294) = v10;
if ( !v9 )
{
v11 = storageRead8();
v9 = (unsigned __int8)byte_D48 <= 3u;
*((_BYTE *)&settings + 296) = v11;
if ( !v9 )
{
v12 = storageReadS8();
v9 = (unsigned __int8)byte_D48 <= 4u;
*((_BYTE *)&settings + 297) = v12;
if ( !v9 )
{
v13 = storageReadS8();
v9 = (unsigned __int8)byte_D48 <= 5u;
*((_BYTE *)&settings + 298) = v13;
if ( !v9 )
*((_WORD *)&settings + 150) = storageRead16(220LL, 2LL, v14);
}
}
}
}
}
result = 1LL;
}
return result;
}

original_code:
int8_t settings_load(void)
{
 int8_t i,j;

 {
  if (!storageLoad(((0xe000UL/256UL)-4),2))
   return 0;
  settings.voiceMask=0x3f;
  settings.spread=0;
  settings.vcfLimit=0;
  settings.seqArpClock=((65535)/2+1);
  if (storage.version<1)
   return 1;
  for(j=0;j<8;++j)
   for(i=0;i<(pcFil6-pcOsc1A+1);++i)
    settings.tunes[j][i]=storageRead16();
  settings.presetNumber=storageRead16();
  settings.benderMiddle=storageRead16();
  settings.presetMode=storageRead8();
  settings.midiReceiveChannel=storageReadS8();
  if (storage.version<2)
   return 1;
  settings.voiceMask=storageRead8();
  settings.midiSendChannel=storageReadS8();
  if (storage.version<3)
   return 1;
  settings.syncMode=storageRead8();
  if (storage.version<4)
   return 1;
  settings.spread=storageReadS8();
  if (storage.version<5)
   return 1;
  settings.vcfLimit=storageReadS8();
  if (storage.version<6)
   return 1;
  settings.seqArpClock=storageRead16();
  if (storage.version<7)
   return 1;
 }
 return 1;
}

canonical_original_code:
char settings_load()
{
 char i; char j;

 {
  if (!storageLoad(((0xe000UL/256UL)-4),2))
   return 0;
  settings.voiceMask=0x3f;
  settings.spread=0;
  settings.vcfLimit=0;
  settings.seqArpClock=((65535)/2+1);
  if (storage.version<1)
   return 1;
  for(j=0;j<8;++j)
   for(i=0;i<(pcFil6-pcOsc1A+1);++i)
    settings.tunes[j][i]=storageRead16();
  settings.presetNumber=storageRead16();
  settings.benderMiddle=storageRead16();
  settings.presetMode=storageRead8();
  settings.midiReceiveChannel=storageReadS8();
  if (storage.version<2)
   return 1;
  settings.voiceMask=storageRead8();
  settings.midiSendChannel=storageReadS8();
  if (storage.version<3)
   return 1;
  settings.syncMode=storageRead8();
  if (storage.version<4)
   return 1;
  settings.spread=storageReadS8();
  if (storage.version<5)
   return 1;
  settings.vcfLimit=storageReadS8();
  if (storage.version<6)
   return 1;
  settings.seqArpClock=storageRead16();
  if (storage.version<7)
   return 1;
 }
 return 1;
}

variable_types: i char

variable_types: j char


decompiled_code:
__int64 settings_save()
{
unsigned __int64 v0; // rcx
__int16 *v1; // rdx
__int16 *v2; // rcx
__int16 v3; // di

storagePrepareStore();
v0 = (unsigned int)((_DWORD)&settings + 36);
do
{
v1 = (__int16 *)(v0 - 36);
do
storageWrite16(*v1);
while ( v1 != v2 );
v0 = (unsigned __int64)(v1 + 18);
}
while ( v1 != (__int16 *)((char *)&settings + 288) );
storageWrite16(*((_WORD *)&settings + 145));
storageWrite16(*((_WORD *)&settings + 144));
storageWrite8(*((_BYTE *)&settings + 292));
storageWriteS8(*((_BYTE *)&settings + 293));
storageWrite8(*((_BYTE *)&settings + 295));
storageWriteS8(*((_BYTE *)&settings + 294));
storageWrite8(*((_BYTE *)&settings + 296));
storageWriteS8(*((_BYTE *)&settings + 297));
storageWriteS8(*((_BYTE *)&settings + 298));
v3 = *(&currentPreset + 42);
*((_WORD *)&settings + 150) = v3;
storageWrite16(v3);
return storageFinishStore(0xDCu, 2);
}

canonical_decompiled_code:
__int64 func12()
{
unsigned __int64 v0; // rcx
__int16 *v1; // rdx
__int16 *v2; // rcx
__int16 v3; // di

func10();
v0 = (unsigned int)((_DWORD)&settings + 36);
do
{
v1 = (__int16 *)(v0 - 36);
do
func4(*v1);
while ( v1 != v2 );
v0 = (unsigned __int64)(v1 + 18);
}
while ( v1 != (__int16 *)((char *)&settings + 288) );
func4(*((_WORD *)&settings + 145));
func4(*((_WORD *)&settings + 144));
func5(*((_BYTE *)&settings + 292));
func6(*((_BYTE *)&settings + 293));
func5(*((_BYTE *)&settings + 295));
func6(*((_BYTE *)&settings + 294));
func5(*((_BYTE *)&settings + 296));
func6(*((_BYTE *)&settings + 297));
func6(*((_BYTE *)&settings + 298));
v3 = *(&currentPreset + 42);
*((_WORD *)&settings + 150) = v3;
func4(v3);
return func8(0xDCu, 2);
}

original_code:
void settings_save(void)
{
 int8_t i,j;

 {
  storagePrepareStore();
  for(j=0;j<8;++j)
   for(i=0;i<(pcFil6-pcOsc1A+1);++i)
    storageWrite16(settings.tunes[j][i]);
  storageWrite16(settings.presetNumber);
  storageWrite16(settings.benderMiddle);
  storageWrite8(settings.presetMode);
  storageWriteS8(settings.midiReceiveChannel);
  storageWrite8(settings.voiceMask);
  storageWriteS8(settings.midiSendChannel);
  storageWrite8(settings.syncMode);
  storageWriteS8(settings.spread);
  storageWriteS8(settings.vcfLimit);
  settings.seqArpClock=currentPreset.continuousParameters[cpSeqArpClock];
  storageWrite16(settings.seqArpClock);
  storageFinishStore(((0xe000UL/256UL)-4),2);
 }
}

canonical_original_code:
void settings_save()
{
 char i; char j;

 {
  storagePrepareStore();
  for(j=0;j<8;++j)
   for(i=0;i<(pcFil6-pcOsc1A+1);++i)
    storageWrite16(settings.tunes[j][i]);
  storageWrite16(settings.presetNumber);
  storageWrite16(settings.benderMiddle);
  storageWrite8(settings.presetMode);
  storageWriteS8(settings.midiReceiveChannel);
  storageWrite8(settings.voiceMask);
  storageWriteS8(settings.midiSendChannel);
  storageWrite8(settings.syncMode);
  storageWriteS8(settings.spread);
  storageWriteS8(settings.vcfLimit);
  settings.seqArpClock=currentPreset.continuousParameters[cpSeqArpClock];
  storageWrite16(settings.seqArpClock);
  storageFinishStore(((0xe000UL/256UL)-4),2);
 }
}


decompiled_code:
__int64 __fastcall preset_saveCurrent(__int64 a1)
{
__int16 *v1; // rdx
char *v2; // rdx
__int64 i; // rdx
char *v4; // rdx
__int16 *v5; // rdx
__int16 *v6; // rcx

storagePrepareStore(a1, (unsigned int)a1);
v1 = (__int16 *)(unsigned int)((_DWORD)&currentPreset + 26);
do
storageWrite16(*v1);
while ( v1 != &currentPreset + 38 );
v2 = (char *)&currentPreset;
*((_BYTE *)&currentPreset + 16) = *((_BYTE *)&currentPreset + 25);
do
storageWrite8(*v2);
while ( v2 != (char *)&currentPreset + 23 );
for ( i = 0LL; i != 10; storageWrite16(*(__int16 *)((char *)&currentPreset + i + 76)) )
;
storageWrite8(*((_BYTE *)&currentPreset + 23));
storageWrite8(*((_BYTE *)&currentPreset + 24));
do
storageWrite8(*v4);
while ( v4 != (char *)(&currentPreset + 46) );
v5 = (__int16 *)(unsigned int)((_DWORD)&currentPreset + 92);
settings[150] = *(&currentPreset + 42);
do
storageWrite16(*v5);
while ( v6 != v5 );
return storageFinishStore(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int16 *v1; // rdx
char *v2; // rdx
__int64 i; // rdx
char *v4; // rdx
__int16 *v5; // rdx
__int16 *v6; // rcx

func10(a1, (unsigned int)a1);
v1 = (__int16 *)(unsigned int)((_DWORD)&currentPreset + 26);
do
func4(*v1);
while ( v1 != &currentPreset + 38 );
v2 = (char *)&currentPreset;
*((_BYTE *)&currentPreset + 16) = *((_BYTE *)&currentPreset + 25);
do
func5(*v2);
while ( v2 != (char *)&currentPreset + 23 );
for ( i = 0LL; i != 10; func4(*(__int16 *)((char *)&currentPreset + i + 76)) )
;
func5(*((_BYTE *)&currentPreset + 23));
func5(*((_BYTE *)&currentPreset + 24));
do
func5(*v4);
while ( v4 != (char *)(&currentPreset + 46) );
v5 = (__int16 *)(unsigned int)((_DWORD)&currentPreset + 92);
settings[150] = *(&currentPreset + 42);
do
func4(*v5);
while ( v6 != v5 );
return func8(a1, 1);
}

original_code:
void preset_saveCurrent(uint16_t number)
{
 uint8_t i;

 {
  storagePrepareStore();
  continuousParameter_t cp;
  for(cp=cpFreqA;cp<=cpFilVelocity;++cp)
   storageWrite16(currentPreset.continuousParameters[cp]);
  currentPreset.steppedParameters[holdPedal]=currentPreset.steppedParameters[spAmpEnvSlow];
  steppedParameter_t sp;
  for(sp=spASaw;sp<=spChromaticPitch;++sp)
   storageWrite8(currentPreset.steppedParameters[sp]);
  for(cp=cpModDelay;cp<=cpSeqArpClock;++cp)
   storageWrite16(currentPreset.continuousParameters[cp]);
  for(sp=spModwheelTarget;sp<=spVibTarget;++sp)
   storageWrite8(currentPreset.steppedParameters[sp]);
  for(i=0;i<6;++i)
   storageWrite8(currentPreset.voicePattern[i]);
  settings.seqArpClock=currentPreset.continuousParameters[cpSeqArpClock];
  for (i=0; i<12; i++)
   storageWrite16(currentPreset.perNoteTuning[i]);
  storageFinishStore(number,1);
 }
}

canonical_original_code:
void preset_saveCurrent(unsigned short number)
{
 unsigned char i;

 {
  storagePrepareStore();
  enum continuousParameter_t cp;
  for(cp=cpFreqA;cp<=cpFilVelocity;++cp)
   storageWrite16(currentPreset.continuousParameters[cp]);
  currentPreset.steppedParameters[holdPedal]=currentPreset.steppedParameters[spAmpEnvSlow];
  enum steppedParameter_t sp;
  for(sp=spASaw;sp<=spChromaticPitch;++sp)
   storageWrite8(currentPreset.steppedParameters[sp]);
  for(cp=cpModDelay;cp<=cpSeqArpClock;++cp)
   storageWrite16(currentPreset.continuousParameters[cp]);
  for(sp=spModwheelTarget;sp<=spVibTarget;++sp)
   storageWrite8(currentPreset.steppedParameters[sp]);
  for(i=0;i<6;++i)
   storageWrite8(currentPreset.voicePattern[i]);
  settings.seqArpClock=currentPreset.continuousParameters[cpSeqArpClock];
  for (i=0; i<12; i++)
   storageWrite16(currentPreset.perNoteTuning[i]);
  storageFinishStore(number,1);
 }
}

variable_types:
number
unsigned short

variable_types:
i
unsigned char

variable_types: enum continuousParameter_t { cpFreqA=0, cpVolA=1, cpAPW=2, cpFreqB=3, cpVolB=4, cpBPW=5, cpFreqBFine=6, cpCutoff=7, cpResonance=8, cpFilEnvAmt=9, cpFilRel=10, cpFilSus=11, cpFilDec=12, cpFilAtt=13, cpAmpRel=14, cpAmpSus=15, cpAmpDec=16, cpAmpAtt=17, cpPModFilEnv=18, cpPModOscB=19, cpLFOFreq=20, cpLFOAmt=21, cpGlide=22, cpAmpVelocity=23, cpFilVelocity=24, cpModDelay=25, cpVibFreq=26, cpVibAmt=27, cpUnisonDetune=28, cpSeqArpClock=29, cpCount=30 }

variable_types: enum steppedParameter_t { spASaw=0, spATri=1, spASqr=2, spBSaw=3, spBTri=4, spBSqr=5, spSync=6, spPModFA=7, spPModFil=8, spLFOShape=9, spLFOShift=10, spLFOTargets=11, spTrackingShift=12, spFilEnvExpo=13, spFilEnvSlow=14, spAmpEnvExpo=15, holdPedal=16, spUnison=17, spAssignerPriority=18, spBenderSemitones=19, spBenderTarget=20, spModwheelShift=21, spChromaticPitch=22, spModwheelTarget=23, spVibTarget=24, spAmpEnvSlow=25, spCount=26 }


decompiled_code:
__int64 __fastcall storage_loadSequencer(char a1, _BYTE *a2, unsigned __int8 a3)
{
_BYTE *v4; // rbx
__int64 v5; // rdi
__int64 result; // rax
_BYTE *v7; // rdx

v4 = a2;
v5 = (unsigned __int16)(a1 + 200);
result = storageLoad(v5, 1);
if ( (_BYTE)result )
{
v7 = &a2[a3];
if ( a3 )
{
do
*v4++ = storageRead8(v5, 1LL, v7);
while ( v4 != v7 );
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(char a1, _BYTE *a2, unsigned __int8 a3)
{
_BYTE *v4; // rbx
__int64 v5; // rdi
__int64 result; // rax
_BYTE *v7; // rdx

v4 = a2;
v5 = (unsigned __int16)(a1 + 200);
result = func7(v5, 1);
if ( (_BYTE)result )
{
v7 = &a2[a3];
if ( a3 )
{
do
*v4++ = func2(v5, 1LL, v7);
while ( v4 != v7 );
}
result = 1LL;
}
return result;
}

original_code:
int8_t storage_loadSequencer(int8_t track, uint8_t * data, uint8_t size)
{

 {
  if (!storageLoad(200 +track,1))
   return 0;
  while(size--)
   *data++=storageRead8();
 }
 return 1;
}

canonical_original_code:
char storage_loadSequencer(char track, unsigned char *data, unsigned char size)
{

 {
  if (!storageLoad(200 +track,1))
   return 0;
  while(size--)
   *data++=storageRead8();
 }
 return 1;
}

variable_types: track char

variable_types:
data
unsigned char *

variable_types:
size
unsigned char


decompiled_code:
__int64 __fastcall storage_saveSequencer(__int64 a1, char *a2)
{
char v2; // r9
char v3; // r8
char v4; // di
char *v5; // rdx

storagePrepareStore(a1, a2);
if ( v3 )
{
do
{
v4 = *a2++;
storageWrite8(v4);
}
while ( a2 != v5 );
}
return storageFinishStore(v2 + 200, 1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, char *a2)
{
char v2; // r9
char v3; // r8
char v4; // di
char *v5; // rdx

func10(a1, a2);
if ( v3 )
{
do
{
v4 = *a2++;
func5(v4);
}
while ( a2 != v5 );
}
return func8(v2 + 200, 1);
}

original_code:
void storage_saveSequencer(int8_t track, uint8_t * data, uint8_t size)
{

 {
  storagePrepareStore();
  while(size--)
   storageWrite8(*data++);
  storageFinishStore(200 +track,1);
 }
}

canonical_original_code:
void storage_saveSequencer(char track, unsigned char *data, unsigned char size)
{

 {
  storagePrepareStore();
  while(size--)
   storageWrite8(*data++);
  storageFinishStore(200 +track,1);
 }
}


decompiled_code:
__int64 __fastcall storage_import(unsigned __int16 a1, const void *a2, __int16 a3)
{
char *v3; // rbx

v3 = (char *)storage + a3;
memset(storage, 0, 0x200uLL);
memcpy(storage, a2, a3);
qword_D40 = (__int64)v3;
return storageFinishStore(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned __int16 a1, const void *a2, __int16 a3)
{
char *v3; // rbx

v3 = (char *)storage + a3;
memset(storage, 0, 0x200uLL);
memcpy(storage, a2, a3);
qword_D40 = (__int64)v3;
return func8(a1, 1);
}

original_code:
void storage_import(uint16_t number, uint8_t * buf, int16_t size)
{

 {
  memset(storage.buffer,0,sizeof(storage.buffer));
  memcpy(storage.buffer,buf,size);
  storage.bufPtr=storage.buffer+size;
  storageFinishStore(number,1);
 }
}

canonical_original_code:
void storage_import(unsigned short number, unsigned char *buf, short size)
{

 {
  memset(storage.buffer,0,sizeof(storage.buffer));
  memcpy(storage.buffer,buf,size);
  storage.bufPtr=storage.buffer+size;
  storageFinishStore(number,1);
 }
}

variable_types:
buf
unsigned char *

variable_types: size short


decompiled_code:
__int64 __fastcall preset_loadDefault(char a1)
{
__int64 result; // rax

result = 0LL;
memset(currentPreset, 0, 0x70uLL);
currentPreset[18] = 0x8000;
currentPreset[20] = -1;
currentPreset[28] = -1;
*(_DWORD *)&currentPreset[14] = -2147418113;
currentPreset[36] = 0x8000;
currentPreset[42] = 0x8000;
*(_DWORD *)&currentPreset[56] = 0;
currentPreset[22] = 0x8000;
currentPreset[39] = 0x8000;
HIBYTE(currentPreset[6]) = 1;
HIBYTE(currentPreset[7]) = 1;
*(_DWORD *)((char *)&currentPreset[9] + 1) = 33620229;
*(_DWORD *)&currentPreset[43] = -1;
currentPreset[45] = -1;
do
{
currentPreset[result + 46] = (int)((double)(int)result * 5461.3333333);
++result;
}
while ( result != 12 );
if ( a1 )
LOBYTE(currentPreset[0]) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(char a1)
{
__int64 result; // rax

result = 0LL;
memset(currentPreset, 0, 0x70uLL);
currentPreset[18] = 0x8000;
currentPreset[20] = -1;
currentPreset[28] = -1;
*(_DWORD *)&currentPreset[14] = -2147418113;
currentPreset[36] = 0x8000;
currentPreset[42] = 0x8000;
*(_DWORD *)&currentPreset[56] = 0;
currentPreset[22] = 0x8000;
currentPreset[39] = 0x8000;
HIBYTE(currentPreset[6]) = 1;
HIBYTE(currentPreset[7]) = 1;
*(_DWORD *)((char *)&currentPreset[9] + 1) = 33620229;
*(_DWORD *)&currentPreset[43] = -1;
currentPreset[45] = -1;
do
{
currentPreset[result + 46] = (int)((double)(int)result * 5461.3333333);
++result;
}
while ( result != 12 );
if ( a1 )
LOBYTE(currentPreset[0]) = 1;
return result;
}

original_code:
void preset_loadDefault(int8_t makeSound)
{
 uint8_t i;

 {
  memset(&currentPreset,0,sizeof(currentPreset));
  currentPreset.continuousParameters[cpAPW]=((65535)/2+1);
  currentPreset.continuousParameters[cpBPW]=((65535)/2+1);
  currentPreset.continuousParameters[cpCutoff]=(65535);
  currentPreset.continuousParameters[cpFilEnvAmt]=((65535)/2+1);
  currentPreset.continuousParameters[cpAmpSus]=(65535);
  currentPreset.continuousParameters[cpVolA]=(65535);
  currentPreset.continuousParameters[cpAmpVelocity]=((65535)/2+1);
  currentPreset.continuousParameters[cpSeqArpClock]=((65535)/2+1);
  currentPreset.continuousParameters[cpVibFreq]=((65535)/2+1);
  currentPreset.steppedParameters[spBenderSemitones]=5;
  currentPreset.steppedParameters[spBenderTarget]=modVCO;
  currentPreset.steppedParameters[spFilEnvExpo]=1;
  currentPreset.steppedParameters[spAmpEnvExpo]=1;
  currentPreset.steppedParameters[spModwheelShift]=1;
  currentPreset.steppedParameters[spChromaticPitch]=2;
  memset(currentPreset.voicePattern,(255),sizeof(currentPreset.voicePattern));
  for (i=0; i<12; i++)
   currentPreset.perNoteTuning[i] = i * 5461.3333333;
  if(makeSound)
   currentPreset.steppedParameters[spASaw]=1;
 }
}

canonical_original_code:
void preset_loadDefault(char makeSound)
{
 unsigned char i;

 {
  memset(&currentPreset,0,sizeof(currentPreset));
  currentPreset.continuousParameters[cpAPW]=((65535)/2+1);
  currentPreset.continuousParameters[cpBPW]=((65535)/2+1);
  currentPreset.continuousParameters[cpCutoff]=(65535);
  currentPreset.continuousParameters[cpFilEnvAmt]=((65535)/2+1);
  currentPreset.continuousParameters[cpAmpSus]=(65535);
  currentPreset.continuousParameters[cpVolA]=(65535);
  currentPreset.continuousParameters[cpAmpVelocity]=((65535)/2+1);
  currentPreset.continuousParameters[cpSeqArpClock]=((65535)/2+1);
  currentPreset.continuousParameters[cpVibFreq]=((65535)/2+1);
  currentPreset.steppedParameters[spBenderSemitones]=5;
  currentPreset.steppedParameters[spBenderTarget]=modVCO;
  currentPreset.steppedParameters[spFilEnvExpo]=1;
  currentPreset.steppedParameters[spAmpEnvExpo]=1;
  currentPreset.steppedParameters[spModwheelShift]=1;
  currentPreset.steppedParameters[spChromaticPitch]=2;
  memset(currentPreset.voicePattern,(255),sizeof(currentPreset.voicePattern));
  for (i=0; i<12; i++)
   currentPreset.perNoteTuning[i] = i * 5461.3333333;
  if(makeSound)
   currentPreset.steppedParameters[spASaw]=1;
 }
}

variable_types: makeSound char


decompiled_code:
__int64 __fastcall preset_loadCurrent(unsigned __int16 a1)
{
__int64 result; // rax
unsigned __int64 v2; // rdx
bool v3; // zf
__int16 v4; // ax
__int64 v5; // rdx
__int16 *v6; // rdx
char v7; // al
__int64 v8; // rdx
bool v9; // cc
__int64 i; // rdx
__int16 v11; // ax
__int64 v12; // rdx
__int64 v13; // rdx
char v14; // al
__int64 v15; // rdx
__int64 v16; // rcx
unsigned __int64 v17; // rdx
__int16 v18; // ax
__int64 v19; // rdx

result = storageLoad(a1, 1);
if ( (_BYTE)result )
{
preset_loadDefault(0);
v2 = (unsigned int)((_DWORD)currentPreset + 26);
v3 = byte_D48 == 0;
currentPreset[43] = -256;
*(_DWORD *)&currentPreset[44] = -1;
if ( !v3 )
{
do
{
v4 = storageRead16(0LL, 1LL, v2);
v2 = v5 + 2;
*(_WORD *)(v2 - 2) = v4;
}
while ( (__int16 *)v2 != &currentPreset[38] );
v6 = currentPreset;
do
{
v7 = storageRead8(0LL, 1LL, v6);
v6 = (__int16 *)(v8 + 1);
*((_BYTE *)v6 - 1) = v7;
}
while ( v6 != (__int16 *)((char *)&currentPreset[11] + 1) );
v9 = (unsigned __int8)byte_D48 <= 1u;
HIBYTE(currentPreset[12]) = currentPreset[8];
if ( !v9 )
{
for ( i = 0LL; i != 10; *(__int16 *)((char *)&currentPreset[37] + i) = v11 )
{
v11 = storageRead16(0LL, 1LL, i);
i = v12 + 2;
}
HIBYTE(currentPreset[11]) = storageRead8(0LL, 1LL, 10LL);
LOBYTE(currentPreset[12]) = storageRead8(0LL, 1LL, (unsigned int)((_DWORD)currentPreset + 86));
do
{
v14 = storageRead8(0LL, 1LL, v13);
v13 = v15 + 1;
*(_BYTE *)(v13 - 1) = v14;
}
while ( v16 != v13 );
v9 = (unsigned __int8)byte_D48 <= 6u;
currentPreset[42] = settings[150];
if ( !v9 )
{
v17 = (unsigned int)((_DWORD)currentPreset + 92);
do
{
v18 = storageRead16(0LL, 1LL, v17);
v17 = v19 + 2;
*(_WORD *)(v17 - 2) = v18;
}
while ( (__int16 *)v17 != &currentPreset[58] );
}
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned __int16 a1)
{
__int64 result; // rax
unsigned __int64 v2; // rdx
bool v3; // zf
__int16 v4; // ax
__int64 v5; // rdx
__int16 *v6; // rdx
char v7; // al
__int64 v8; // rdx
bool v9; // cc
__int64 i; // rdx
__int16 v11; // ax
__int64 v12; // rdx
__int64 v13; // rdx
char v14; // al
__int64 v15; // rdx
__int64 v16; // rcx
unsigned __int64 v17; // rdx
__int16 v18; // ax
__int64 v19; // rdx

result = func7(a1, 1);
if ( (_BYTE)result )
{
func18(0);
v2 = (unsigned int)((_DWORD)currentPreset + 26);
v3 = byte_D48 == 0;
currentPreset[43] = -256;
*(_DWORD *)&currentPreset[44] = -1;
if ( !v3 )
{
do
{
v4 = func1(0LL, 1LL, v2);
v2 = v5 + 2;
*(_WORD *)(v2 - 2) = v4;
}
while ( (__int16 *)v2 != &currentPreset[38] );
v6 = currentPreset;
do
{
v7 = func2(0LL, 1LL, v6);
v6 = (__int16 *)(v8 + 1);
*((_BYTE *)v6 - 1) = v7;
}
while ( v6 != (__int16 *)((char *)&currentPreset[11] + 1) );
v9 = (unsigned __int8)byte_D48 <= 1u;
HIBYTE(currentPreset[12]) = currentPreset[8];
if ( !v9 )
{
for ( i = 0LL; i != 10; *(__int16 *)((char *)&currentPreset[37] + i) = v11 )
{
v11 = func1(0LL, 1LL, i);
i = v12 + 2;
}
HIBYTE(currentPreset[11]) = func2(0LL, 1LL, 10LL);
LOBYTE(currentPreset[12]) = func2(0LL, 1LL, (unsigned int)((_DWORD)currentPreset + 86));
do
{
v14 = func2(0LL, 1LL, v13);
v13 = v15 + 1;
*(_BYTE *)(v13 - 1) = v14;
}
while ( v16 != v13 );
v9 = (unsigned __int8)byte_D48 <= 6u;
currentPreset[42] = settings[150];
if ( !v9 )
{
v17 = (unsigned int)((_DWORD)currentPreset + 92);
do
{
v18 = func1(0LL, 1LL, v17);
v17 = v19 + 2;
*(_WORD *)(v17 - 2) = v18;
}
while ( (__int16 *)v17 != &currentPreset[58] );
}
}
}
result = 1LL;
}
return result;
}

original_code:
int8_t preset_loadCurrent(uint16_t number)
{
 uint8_t i;

 {
  if(!storageLoad(number,1))
   return 0;
  preset_loadDefault(0);
  for(i=0;i<6;++i)
   currentPreset.voicePattern[i]=(i==0)?0:(255);
  if (storage.version<1)
   return 1;
  continuousParameter_t cp;
  for(cp=cpFreqA;cp<=cpFilVelocity;++cp)
   currentPreset.continuousParameters[cp]=storageRead16();
  steppedParameter_t sp;
  for(sp=spASaw;sp<=spChromaticPitch;++sp)
   currentPreset.steppedParameters[sp]=storageRead8();
  currentPreset.steppedParameters[spAmpEnvSlow]=currentPreset.steppedParameters[holdPedal];
  if (storage.version<2)
   return 1;
  for(cp=cpModDelay;cp<=cpSeqArpClock;++cp)
   currentPreset.continuousParameters[cp]=storageRead16();
  for(sp=spModwheelTarget;sp<=spVibTarget;++sp)
   currentPreset.steppedParameters[sp]=storageRead8();
  for(i=0;i<6;++i)
   currentPreset.voicePattern[i]=storageRead8();
  currentPreset.continuousParameters[cpSeqArpClock]=settings.seqArpClock;
  if (storage.version<7)
   return 1;
  for (i=0; i<12; i++)
   currentPreset.perNoteTuning[i]=storageRead16();
 }
 return 1;
}

canonical_original_code:
char preset_loadCurrent(unsigned short number)
{
 unsigned char i;

 {
  if(!storageLoad(number,1))
   return 0;
  preset_loadDefault(0);
  for(i=0;i<6;++i)
   currentPreset.voicePattern[i]=(i==0)?0:(255);
  if (storage.version<1)
   return 1;
  enum continuousParameter_t cp;
  for(cp=cpFreqA;cp<=cpFilVelocity;++cp)
   currentPreset.continuousParameters[cp]=storageRead16();
  enum steppedParameter_t sp;
  for(sp=spASaw;sp<=spChromaticPitch;++sp)
   currentPreset.steppedParameters[sp]=storageRead8();
  currentPreset.steppedParameters[spAmpEnvSlow]=currentPreset.steppedParameters[holdPedal];
  if (storage.version<2)
   return 1;
  for(cp=cpModDelay;cp<=cpSeqArpClock;++cp)
   currentPreset.continuousParameters[cp]=storageRead16();
  for(sp=spModwheelTarget;sp<=spVibTarget;++sp)
   currentPreset.steppedParameters[sp]=storageRead8();
  for(i=0;i<6;++i)
   currentPreset.voicePattern[i]=storageRead8();
  currentPreset.continuousParameters[cpSeqArpClock]=settings.seqArpClock;
  if (storage.version<7)
   return 1;
  for (i=0; i<12; i++)
   currentPreset.perNoteTuning[i]=storageRead16();
 }
 return 1;
}

user_defined_types: enum continuousParameter_t { cpFreqA=0, cpVolA=1, cpAPW=2, cpFreqB=3, cpVolB=4, cpBPW=5, cpFreqBFine=6, cpCutoff=7, cpResonance=8, cpFilEnvAmt=9, cpFilRel=10, cpFilSus=11, cpFilDec=12, cpFilAtt=13, cpAmpRel=14, cpAmpSus=15, cpAmpDec=16, cpAmpAtt=17, cpPModFilEnv=18, cpPModOscB=19, cpLFOFreq=20, cpLFOAmt=21, cpGlide=22, cpAmpVelocity=23, cpFilVelocity=24, cpModDelay=25, cpVibFreq=26, cpVibAmt=27, cpUnisonDetune=28, cpSeqArpClock=29, cpCount=30 }

user_defined_types: enum steppedParameter_t { spASaw=0, spATri=1, spASqr=2, spBSaw=3, spBTri=4, spBSqr=5, spSync=6, spPModFA=7, spPModFil=8, spLFOShape=9, spLFOShift=10, spLFOTargets=11, spTrackingShift=12, spFilEnvExpo=13, spFilEnvSlow=14, spAmpEnvExpo=15, holdPedal=16, spUnison=17, spAssignerPriority=18, spBenderSemitones=19, spBenderTarget=20, spModwheelShift=21, spChromaticPitch=22, spModwheelTarget=23, spVibTarget=24, spAmpEnvSlow=25, spCount=26 }


decompiled_code:
__int64 settings_loadDefault()
{
memset(settings, 0, 0x128uLL);
HIBYTE(settings[146]) = -1;
settings[144] = 0x8000;
HIBYTE(settings[147]) = 63;
*(_DWORD *)&settings[148] = 0;
settings[150] = 0x8000;
return tuner_init();
}

canonical_decompiled_code:
__int64 func20()
{
memset(settings, 0, 0x128uLL);
HIBYTE(settings[146]) = -1;
settings[144] = 0x8000;
HIBYTE(settings[147]) = 63;
*(_DWORD *)&settings[148] = 0;
settings[150] = 0x8000;
return tuner_init();
}

original_code:
void settings_loadDefault(void)
{

 {
  memset(&settings,0,sizeof(settings));
  settings.benderMiddle=((65535)/2+1);
  settings.midiReceiveChannel=-1;
  settings.voiceMask=0x3f;
  settings.seqArpClock=((65535)/2+1);
  tuner_init();
 }
}

canonical_original_code:
void settings_loadDefault()
{

 {
  memset(&settings,0,sizeof(settings));
  settings.benderMiddle=((65535)/2+1);
  settings.midiReceiveChannel=-1;
  settings.voiceMask=0x3f;
  settings.seqArpClock=((65535)/2+1);
  tuner_init();
 }
}


updateCV

decompiled_code:
__int64 __fastcall updateCV(unsigned int a1, unsigned __int16 a2)
{
dac_write(a2);
io_write(13LL, (unsigned __int8)a1 | 0xF8u);
io_write(13LL, ((unsigned __int8)a1 | 0xF8u) & (unsigned __int8)~(8 << (a1 >> 3)));
return io_write(13LL, (unsigned __int8)a1 | 0xF8u);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned __int16 a2)
{
dac_write(a2);
io_write(13LL, (unsigned __int8)a1 | 0xF8u);
io_write(13LL, ((unsigned __int8)a1 | 0xF8u) & (unsigned __int8)~(8 << (a1 >> 3)));
return io_write(13LL, (unsigned __int8)a1 | 0xF8u);
}

original_code:
static inline void updateCV(p600CV_t cv, uint16_t cvv)
{
 uint8_t dmux1,dmux2;
 dmux1=(cv&0x07)|0xf8;
 dmux2=dmux1&~(0x08<<(cv>>3));

 {
  dac_write(cvv);
  io_write(0x0d,dmux1);
  ;
  io_write(0x0d,dmux2);
  ;
  io_write(0x0d,dmux1);
  ;
 }
}

canonical_original_code:
static inline void updateCV(enum p600CV_t cv, unsigned short cvv)
{
 unsigned char dmux1; unsigned char dmux2;
 dmux1=(cv&0x07)|0xf8;
 dmux2=dmux1&~(0x08<<(cv>>3));

 {
  dac_write(cvv);
  io_write(0x0d,dmux1);
  ;
  io_write(0x0d,dmux2);
  ;
  io_write(0x0d,dmux1);
  ;
 }
}

variable_types: enum p600CV_t { pcOsc1A=0, pcOsc2A=1, pcOsc3A=2, pcOsc4A=3, pcOsc5A=4, pcOsc6A=5, pcOsc1B=6, pcOsc2B=7, pcOsc3B=8, pcOsc4B=9, pcOsc5B=10, pcOsc6B=11, pcFil1=12, pcFil2=13, pcFil3=14, pcFil4=15, pcFil5=16, pcFil6=17, pcAmp1=18, pcAmp2=19, pcAmp3=20, pcAmp4=21, pcAmp5=22, pcAmp6=23, pcPModOscB=24, pcVolA=25, pcVolB=26, pcMVol=27, pcAPW=28, pcExtFil=29, pcResonance=30, pcBPW=31 }

variable_types:
cvv
unsigned short


updateGates

decompiled_code:
__int64 updateGates()
{
return io_write(11LL, (unsigned __int8)byte_264);
}

canonical_decompiled_code:
__int64 func1()
{
return io_write(11LL, (unsigned __int8)byte_264);
}

original_code:
static inline void updateGates(void)
{

 {
  io_write(0x0b,sh.gateBits);
 }
}

canonical_original_code:
static inline void updateGates()
{

 {
  io_write(0x0b,sh.gateBits);
 }
}


decompiled_code:
__int64 __fastcall sh_setCV(unsigned int a1, unsigned __int16 a2, char a3)
{
__int64 result; // rax

if ( (a3 & 1) != 0 )
return updateCV(a1, a2);
word_224[a1] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned __int16 a2, char a3)
{
__int64 result; // rax

if ( (a3 & 1) != 0 )
return func0(a1, a2);
word_224[a1] = a2;
return result;
}

original_code:
inline void sh_setCV(p600CV_t cv,uint16_t value, uint8_t flags)
{
 if(flags&1)
 {
  updateCV(cv,value);
 }
 else
 {
  sh.cvs[cv]=value;
 }
}

canonical_original_code:
inline void sh_setCV(enum p600CV_t cv, unsigned short value, unsigned char flags)
{
 if(flags&1)
 {
  updateCV(cv,value);
 }
 else
 {
  sh.cvs[cv]=value;
 }
}

variable_types:
value
unsigned short

variable_types:
flags
unsigned char

user_defined_types: enum p600CV_t { pcOsc1A=0, pcOsc2A=1, pcOsc3A=2, pcOsc4A=3, pcOsc5A=4, pcOsc6A=5, pcOsc1B=6, pcOsc2B=7, pcOsc3B=8, pcOsc4B=9, pcOsc5B=10, pcOsc6B=11, pcFil1=12, pcFil2=13, pcFil3=14, pcFil4=15, pcFil5=16, pcFil6=17, pcAmp1=18, pcAmp2=19, pcAmp3=20, pcAmp4=21, pcAmp5=22, pcAmp6=23, pcPModOscB=24, pcVolA=25, pcVolB=26, pcMVol=27, pcAPW=28, pcExtFil=29, pcResonance=30, pcBPW=31 }


decompiled_code:
__int64 __fastcall sh_setCV32Sat(unsigned int a1, int a2, char a3)
{
if ( a2 > 0xFFFF )
a2 = 0xFFFF;
if ( a2 < 0 )
LOWORD(a2) = 0;
return sh_setCV(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2, char a3)
{
if ( a2 > 0xFFFF )
a2 = 0xFFFF;
if ( a2 < 0 )
LOWORD(a2) = 0;
return func2(a1, a2, a3);
}

original_code:
inline void sh_setCV32Sat(p600CV_t cv,int32_t value, uint8_t flags)
{
 if(value<0)
  value=0;
 else if (value>(65535))
  value=(65535);
 sh_setCV(cv,value,flags);
}

canonical_original_code:
inline void sh_setCV32Sat(enum p600CV_t cv, int value, unsigned char flags)
{
 if(value<0)
  value=0;
 else if (value>(65535))
  value=(65535);
 sh_setCV(cv,value,flags);
}

variable_types: value int


decompiled_code:
__int64 __fastcall sh_setCV_FastPath(unsigned int a1, unsigned __int16 a2)
{
dac_write(a2);
io_write(13LL, (unsigned __int8)a1 | 0xF8u);
io_write(13LL, ((unsigned __int8)a1 | 0xF8u) & (unsigned __int8)~(8 << (a1 >> 3)));
return io_write(13LL, (unsigned __int8)a1 | 0xF8u);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned __int16 a2)
{
dac_write(a2);
io_write(13LL, (unsigned __int8)a1 | 0xF8u);
io_write(13LL, ((unsigned __int8)a1 | 0xF8u) & (unsigned __int8)~(8 << (a1 >> 3)));
return io_write(13LL, (unsigned __int8)a1 | 0xF8u);
}

original_code:
inline __attribute__((always_inline)) void sh_setCV_FastPath(p600CV_t cv,uint16_t value)
{
 uint8_t dmux1,dmux2;
 dmux1=(cv&0x07)|0xf8;
 dmux2=dmux1&~(0x08<<(cv>>3));
 dac_write(value);
 io_write(0x0d,dmux1);
 ;
 io_write(0x0d,dmux2);

 io_write(0x0d,dmux1);
}

canonical_original_code:
inline void sh_setCV_FastPath(enum p600CV_t cv, unsigned short value)
{
 unsigned char dmux1; unsigned char dmux2;
 dmux1=(cv&0x07)|0xf8;
 dmux2=dmux1&~(0x08<<(cv>>3));
 dac_write(value);
 io_write(0x0d,dmux1);
 ;
 io_write(0x0d,dmux2);

 io_write(0x0d,dmux1);
}


decompiled_code:
__int64 __fastcall sh_setCV32Sat_FastPath(unsigned int a1, int a2)
{
__int64 v3; // rdi

v3 = 0xFFFFLL;
if ( a2 <= 0xFFFF )
v3 = (unsigned int)a2;
if ( (int)v3 < 0 )
v3 = 0LL;
dac_write(v3);
io_write(13LL, (unsigned __int8)a1 | 0xF8u);
io_write(13LL, ((unsigned __int8)a1 | 0xF8u) & (unsigned __int8)~(8 << (a1 >> 3)));
return io_write(13LL, (unsigned __int8)a1 | 0xF8u);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, int a2)
{
__int64 v3; // rdi

v3 = 0xFFFFLL;
if ( a2 <= 0xFFFF )
v3 = (unsigned int)a2;
if ( (int)v3 < 0 )
v3 = 0LL;
dac_write(v3);
io_write(13LL, (unsigned __int8)a1 | 0xF8u);
io_write(13LL, ((unsigned __int8)a1 | 0xF8u) & (unsigned __int8)~(8 << (a1 >> 3)));
return io_write(13LL, (unsigned __int8)a1 | 0xF8u);
}

original_code:
inline __attribute__((always_inline)) void sh_setCV32Sat_FastPath(p600CV_t cv,int32_t value)
{
 if(value<0)
  value=0;
 else if (value>(65535))
  value=(65535);
 sh_setCV_FastPath(cv,value);
}

canonical_original_code:
inline void sh_setCV32Sat_FastPath(enum p600CV_t cv, int value)
{
 if(value<0)
  value=0;
 else if (value>(65535))
  value=(65535);
 sh_setCV_FastPath(cv,value);
}


decompiled_code:
__int64 __fastcall sh_setGate(char a1, char a2)
{
char v2; // al

v2 = byte_264 & ~(1 << a1);
if ( a2 )
v2 |= 1 << a1;
byte_264 = v2;
return updateGates();
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, char a2)
{
char v2; // al

v2 = byte_264 & ~(1 << a1);
if ( a2 )
v2 |= 1 << a1;
byte_264 = v2;
return func1();
}

original_code:
inline void sh_setGate(p600Gate_t gate,int8_t on)
{
 uint8_t mask=1<<gate;
 sh.gateBits&=~mask;
 if (on) sh.gateBits|=mask;
 updateGates();
}

canonical_original_code:
inline void sh_setGate(enum p600Gate_t gate, char on)
{
 unsigned char mask = 1<<gate;
 sh.gateBits&=~mask;
 if (on) sh.gateBits|=mask;
 updateGates();
}

variable_types: enum p600Gate_t { pgASaw=0, pgATri=1, pgSync=2, pgBSaw=3, pgBTri=4, pgPModFA=5, pgPModFil=6 }

variable_types: on char

variable_types:
mask
unsigned char


decompiled_code:
void sh_init()
{
unk_260 = 0LL;
sh = 0LL;
xmmword_230 = 0LL;
xmmword_240 = 0LL;
xmmword_250 = 0LL;
}

canonical_decompiled_code:
void func7()
{
unk_260 = 0LL;
sh = 0LL;
xmmword_230 = 0LL;
xmmword_240 = 0LL;
xmmword_250 = 0LL;
}

original_code:
void sh_init()
{
 memset(&sh,0,sizeof(sh));
}


decompiled_code:
__int64 sh_update()
{
__int64 i; // rbx
unsigned __int16 v1; // si
unsigned int v2; // edi

for ( i = 0LL; i != 32; ++i )
{
v1 = word_224[i];
v2 = i;
updateCV(v2, v1);
}
return updateGates();
}

canonical_decompiled_code:
__int64 func8()
{
__int64 i; // rbx
unsigned __int16 v1; // si
unsigned int v2; // edi

for ( i = 0LL; i != 32; ++i )
{
v1 = word_224[i];
v2 = i;
func0(v2, v1);
}
return func1();
}

original_code:
void sh_update()
{
 uint8_t i;
 for(i=0;i<32;++i)
  updateCV(i,sh.cvs[i]);
 updateGates();
}

canonical_original_code:
void sh_update()
{
 unsigned char i;
 for(i=0;i<32;++i)
  updateCV(i,sh.cvs[i]);
 updateGates();
}

variable_types:
i
unsigned char


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

result = 0LL;
memset(&scanner, 0, 0x80uLL);
return result;
}

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

result = 0LL;
memset(&scanner, 0, 0x80uLL);
return result;
}

original_code:
void scanner_init(void)
{
 memset(&scanner,0,sizeof(scanner));
}

canonical_original_code:
void scanner_init()
{
 memset(&scanner,0,sizeof(scanner));
}


decompiled_code:
__int64 __fastcall scanner_keyState(char a1)
{
return scanner[(unsigned __int8)(a1 + 64)] & 1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return scanner[(unsigned __int8)(a1 + 64)] & 1;
}

original_code:
inline __attribute__((always_inline)) int8_t scanner_keyState(uint8_t key)
{
 return scanner_state(key+64);
}

canonical_original_code:
inline char scanner_keyState(unsigned char key)
{
 return scanner_state(key+64);
}

variable_types:
key
unsigned char


decompiled_code:
__int64 __fastcall scanner_buttonState(unsigned __int8 a1)
{
return scanner[a1] & 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
return scanner[a1] & 1;
}

original_code:
inline __attribute__((always_inline)) int8_t scanner_buttonState(p600Button_t button)
{
 return scanner_state(button);
}

canonical_original_code:
inline char scanner_buttonState(enum p600Button_t button)
{
 return scanner_state(button);
}

variable_types: enum p600Button_t { pb0=0, pb1=1, pb2=2, pb3=3, pb4=4, pb5=5, pb6=6, pb7=7, pb8=8, pb9=9, pbArpUD=10, pbArpAssign=11, pbPreset=12, pbRecord=13, pbToTape=14, pbFromTape=15, pbSeq1=16, pbSeq2=17, pbTune=18, pbASqr=24, pbBSqr=25, pbFilFull=26, pbFilHalf=27, pbLFOShape=28, pbLFOFreq=29, pbLFOPW=30, pbLFOFil=31, pbASaw=32, pbATri=33, pbSync=34, pbBSaw=35, pbBTri=36, pbPModFA=37, pbPModFil=38, pbUnison=39 }


decompiled_code:
__int64 __fastcall scanner_isKeyDown(char a1)
{
__int64 result; // rax

result = 0LL;
if ( (unsigned __int8)(a1 - 24) <= 0x3Cu )
result = scanner[(unsigned __int8)(a1 + 40)] & 1;
return result;
}

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

result = 0LL;
if ( (unsigned __int8)(a1 - 24) <= 0x3Cu )
result = scanner[(unsigned __int8)(a1 + 40)] & 1;
return result;
}

original_code:
int8_t scanner_isKeyDown(uint8_t note)
{
 if (note<24 || note>(24 +60))
  return 0;
 return scanner.state[note-24 +64]&1;
}

canonical_original_code:
char scanner_isKeyDown(unsigned char note)
{
 if (note<24 || note>(24 +60))
  return 0;
 return scanner.state[note-24 +64]&1;
}

variable_types:
note
unsigned char


decompiled_code:
__int64 __fastcall scanner_update(char a1)
{
unsigned __int8 v1; // al
unsigned int v2; // er12
unsigned int v3; // er15
char *v4; // r13
unsigned int v5; // ebp
char *v6; // rbx
unsigned __int8 v7; // r14
__int64 result; // rax
__int64 v9; // rdi

v1 = (a1 == 0) << 6;
v2 = (unsigned __int8)(8 * (a1 == 0));
v3 = (unsigned __int8)(v1 + 8);
v4 = &scanner[v1];
do
{
v5 = v3 - 8;
v6 = v4;
io_write(8LL, v2);
v7 = io_read(10LL);
do
{
while ( 1 )
{
result = (unsigned __int8)*v6;
if ( (result & 0xFE) == 0 )
break;
result = (unsigned int)(result - 2);
*v6 = result;
LABEL_4:
++v5;
v7 >>= 1;
++v6;
if ( v5 == v3 )
goto LABEL_9;
}
if ( (v7 & 1) == (_BYTE)result )
goto LABEL_4;
*v6 = v7 & 1 | 0xA;
if ( (unsigned __int8)v5 > 0x3Fu )
{
result = synth_keyEvent((unsigned __int8)(v5 - 40));
goto LABEL_4;
}
v9 = v5++;
v7 >>= 1;
++v6;
result = synth_buttonEvent(v9);
}
while ( v5 != v3 );
LABEL_9:
++v2;
v3 = v5 + 8;
v4 += 8;
}
while ( (unsigned __int8)v2 <= 0xFu );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
unsigned __int8 v1; // al
unsigned int v2; // er12
unsigned int v3; // er15
char *v4; // r13
unsigned int v5; // ebp
char *v6; // rbx
unsigned __int8 v7; // r14
__int64 result; // rax
__int64 v9; // rdi

v1 = (a1 == 0) << 6;
v2 = (unsigned __int8)(8 * (a1 == 0));
v3 = (unsigned __int8)(v1 + 8);
v4 = &scanner[v1];
do
{
v5 = v3 - 8;
v6 = v4;
io_write(8LL, v2);
v7 = io_read(10LL);
do
{
while ( 1 )
{
result = (unsigned __int8)*v6;
if ( (result & 0xFE) == 0 )
break;
result = (unsigned int)(result - 2);
*v6 = result;
LABEL_4:
++v5;
v7 >>= 1;
++v6;
if ( v5 == v3 )
goto LABEL_9;
}
if ( (v7 & 1) == (_BYTE)result )
goto LABEL_4;
*v6 = v7 & 1 | 0xA;
if ( (unsigned __int8)v5 > 0x3Fu )
{
result = synth_keyEvent((unsigned __int8)(v5 - 40));
goto LABEL_4;
}
v9 = v5++;
v7 >>= 1;
++v6;
result = synth_buttonEvent(v9);
}
while ( v5 != v3 );
LABEL_9:
++v2;
v3 = v5 + 8;
v4 += 8;
}
while ( (unsigned __int8)v2 <= 0xFu );
return result;
}

original_code:
void scanner_update(int8_t fullScan)
{
 uint8_t i,j,stateIdx;
 uint8_t ps,flag,curState;
 for(i=fullScan?0:(64/8);i<16;++i)
 {

  {
   io_write(0x08,i);
   ;
   ps=io_read(0x0a);
  }
  for(j=0;j<8;++j)
  {
   stateIdx=i*8+j;
   flag=ps&1;
   curState=scanner.state[stateIdx];
   if(curState&0xfe)
   {
    scanner.state[stateIdx]=curState-2;
   }
   else if(flag ^ (curState&1))
   {
    scanner.state[stateIdx]=flag|(5<<1);
    scanner_event(stateIdx,flag);
   }
   ps>>=1;
  }
 }
}

canonical_original_code:
void scanner_update(char fullScan)
{
 unsigned char i; unsigned char j; unsigned char stateIdx;
 unsigned char ps; unsigned char flag; unsigned char curState;
 for(i=fullScan?0:(64/8);i<16;++i)
 {

  {
   io_write(0x08,i);
   ;
   ps=io_read(0x0a);
  }
  for(j=0;j<8;++j)
  {
   stateIdx=i*8+j;
   flag=ps&1;
   curState=scanner.state[stateIdx];
   if(curState&0xfe)
   {
    scanner.state[stateIdx]=curState-2;
   }
   else if(flag ^ (curState&1))
   {
    scanner.state[stateIdx]=flag|(5<<1);
    scanner_event(stateIdx,flag);
   }
   ps>>=1;
  }
 }
}

variable_types: fullScan char

variable_types:
j
unsigned char

variable_types:
stateIdx
unsigned char

variable_types:
ps
unsigned char

variable_types:
flag
unsigned char

variable_types:
curState
unsigned char


midiFilterChannel

decompiled_code:
__int64 __fastcall midiFilterChannel(char a1)
{
unsigned int v1; // er8

v1 = 1;
if ( settings[293] >= 0 )
LOBYTE(v1) = (a1 & 0xF) == settings[293];
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
unsigned int v1; // er8

v1 = 1;
if ( settings[293] >= 0 )
LOBYTE(v1) = (a1 & 0xF) == settings[293];
return v1;
}

original_code:
static int8_t midiFilterChannel(uint8_t channel)
{
 return settings.midiReceiveChannel<0 || (channel&0x0F)==settings.midiReceiveChannel;
}

canonical_original_code:
static char midiFilterChannel(unsigned char channel)
{
 return settings.midiReceiveChannel<0 || (channel&0x0F)==settings.midiReceiveChannel;
}

variable_types:
channel
unsigned char


decompiled_code:
__int64 __fastcall midi_realtimeEvent(__int64 a1, unsigned __int8 a2)
{
return synth_realtimeEvent(a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 a2)
{
return synth_realtimeEvent(a2);
}

original_code:
static void midi_realtimeEvent(MidiDevice * device, uint8_t event)
{
 synth_realtimeEvent(event);
}

canonical_original_code:
static void midi_realtimeEvent(struct _midi_device *device, unsigned char event)
{
 synth_realtimeEvent(event);
}

variable_types: struct _midi_device { void (*send_func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_cc_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteon_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteoff_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_aftertouch_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_pitchbend_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_songposition_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_progchange_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_chanpressure_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_songselect_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_tc_quarterframe_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_realtime_callback)(struct _midi_device *device, unsigned char byte); void (*input_tunerequest_callback)(struct _midi_device *device, unsigned char byte); void (*input_sysex_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_fallthrough_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_catchall_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*pre_input_process_callback)(struct _midi_device *device); unsigned char input_buffer[3]; enum input_state_t { IDLE=0, ONE_BYTE_MESSAGE=1, TWO_BYTE_MESSAGE=2, THREE_BYTE_MESSAGE=3, SYSEX_MESSAGE=4 } input_state; unsigned short input_count; unsigned char input_queue_data[192]; struct byteQueue_t { unsigned char start; unsigned char end; unsigned char length; unsigned char *data; } input_queue; } *

variable_types:
event
unsigned char


decompiled_code:
__int64 __fastcall midi_progChangeEvent(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
__int16 v4; // bx

result = midiFilterChannel(a2);
if ( (_BYTE)result )
{
if ( settings[292] )
{
if ( v3 <= 0x63u )
{
v4 = v3;
if ( v3 != *(_WORD *)&settings[290] )
{
result = preset_loadCurrent(v3);
if ( (_BYTE)result )
{
*(_WORD *)&settings[290] = v4;
ui_setPresetModified(0LL);
settings_save();
result = refreshFullState();
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
__int16 v4; // bx

result = func0(a2);
if ( (_BYTE)result )
{
if ( settings[292] )
{
if ( v3 <= 0x63u )
{
v4 = v3;
if ( v3 != *(_WORD *)&settings[290] )
{
result = preset_loadCurrent(v3);
if ( (_BYTE)result )
{
*(_WORD *)&settings[290] = v4;
ui_setPresetModified(0LL);
settings_save();
result = refreshFullState();
}
}
}
}
}
return result;
}

original_code:
static void midi_progChangeEvent(MidiDevice * device, uint8_t channel, uint8_t program)
{
 if(!midiFilterChannel(channel))
  return;
 if(settings.presetMode && program<100 && program!=settings.presetNumber)
 {
  if(preset_loadCurrent(program))
  {
   settings.presetNumber=program;
   ui_setPresetModified(0);
   settings_save();
   refreshFullState();
  }
 }
}

canonical_original_code:
static void midi_progChangeEvent(struct _midi_device *device, unsigned char channel, unsigned char program)
{
 if(!midiFilterChannel(channel))
  return;
 if(settings.presetMode && program<100 && program!=settings.presetNumber)
 {
  if(preset_loadCurrent(program))
  {
   settings.presetNumber=program;
   ui_setPresetModified(0);
   settings_save();
   refreshFullState();
  }
 }
}

variable_types:
program
unsigned char


decompiled_code:
__int64 __fastcall midi_ccEvent(__int64 a1, char a2)
{
__int64 result; // rax
int v3; // edx
__int16 v4; // cx
int v5; // ebx
unsigned __int8 v6; // bp
int v7; // ecx
unsigned __int16 v8; // bx
int v9; // ebp
char v10; // bl

result = midiFilterChannel(a2);
if ( !(_BYTE)result )
return result;
v5 = v3;
v6 = v4;
if ( !(_BYTE)v3 && (unsigned __int8)v4 <= 1u )
{
v7 = settings[292];
if ( v7 == v6 )
{
if ( !(_BYTE)v7 )
return result;
goto LABEL_24;
}
settings[292] = v6;
settings_save();
refreshPresetMode();
result = refreshFullState();
LABEL_15:
if ( !settings[292] )
return result;
goto LABEL_16;
}
if ( (_BYTE)v3 == 1 )
{
result = synth_wheelEvent(0LL, (unsigned __int16)(v4 << 9), 2LL, 0LL);
goto LABEL_15;
}
if ( (_BYTE)v3 == 64 )
return assigner_holdEvent((unsigned int)(char)v4);
if ( !settings[292] )
return result;
if ( (unsigned __int8)(v3 - 16) <= 0x1Du )
{
result = (unsigned __int16)((unsigned __int8)v3 - 16) + 8LL;
if ( *((_WORD *)&currentPreset + result + 5) >> 9 == (unsigned __int8)v4 )
return result;
*((_WORD *)&currentPreset + result + 5) = *((_WORD *)&currentPreset + result + 5) & 0x1FC | (v4 << 9);
goto LABEL_13;
}
LABEL_24:
if ( (unsigned __int8)(v3 - 80) > 0x1Du )
{
LABEL_16:
result = (unsigned int)(v5 - 48);
if ( (unsigned __int8)(v5 - 48) > 0x19u )
return result;
v8 = (unsigned __int8)v5 - 48;
result = v8;
v9 = (int)v6 >> (7 - *((_BYTE *)&steppedParametersBits + v8));
if ( *((_BYTE *)&currentPreset + v8) == (_BYTE)v9 )
{
if ( v8 != 17 )
return result;
v10 = 0;
goto LABEL_20;
}
*((_BYTE *)&currentPreset + v8) = v9;
if ( v8 == 17 )
{
v10 = 1;
LABEL_20:
if ( (_BYTE)v9 )
assigner_latchPattern();
else
assigner_setPoly();
result = assigner_getPattern((unsigned int)((_DWORD)&currentPreset + 86), 0LL);
if ( v10 )
goto LABEL_13;
return result;
}
LABEL_13:
ui_setPresetModified(1LL);
return refreshFullState();
}
result = (unsigned __int16)((unsigned __int8)v3 - 80) + 8LL;
if ( ((*((_WORD *)&currentPreset + result + 5) >> 2) & 0x7F) != v6 )
{
*((_WORD *)&currentPreset + result + 5) = (4 * v6) | *((_WORD *)&currentPreset + result + 5) & 0xFE00;
goto LABEL_13;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
__int64 result; // rax
int v3; // edx
__int16 v4; // cx
int v5; // ebx
unsigned __int8 v6; // bp
int v7; // ecx
unsigned __int16 v8; // bx
int v9; // ebp
char v10; // bl

result = func0(a2);
if ( !(_BYTE)result )
return result;
v5 = v3;
v6 = v4;
if ( !(_BYTE)v3 && (unsigned __int8)v4 <= 1u )
{
v7 = settings[292];
if ( v7 == v6 )
{
if ( !(_BYTE)v7 )
return result;
goto LABEL_24;
}
settings[292] = v6;
settings_save();
refreshPresetMode();
result = refreshFullState();
LABEL_15:
if ( !settings[292] )
return result;
goto LABEL_16;
}
if ( (_BYTE)v3 == 1 )
{
result = synth_wheelEvent(0LL, (unsigned __int16)(v4 << 9), 2LL, 0LL);
goto LABEL_15;
}
if ( (_BYTE)v3 == 64 )
return assigner_holdEvent((unsigned int)(char)v4);
if ( !settings[292] )
return result;
if ( (unsigned __int8)(v3 - 16) <= 0x1Du )
{
result = (unsigned __int16)((unsigned __int8)v3 - 16) + 8LL;
if ( *((_WORD *)&currentPreset + result + 5) >> 9 == (unsigned __int8)v4 )
return result;
*((_WORD *)&currentPreset + result + 5) = *((_WORD *)&currentPreset + result + 5) & 0x1FC | (v4 << 9);
goto LABEL_13;
}
LABEL_24:
if ( (unsigned __int8)(v3 - 80) > 0x1Du )
{
LABEL_16:
result = (unsigned int)(v5 - 48);
if ( (unsigned __int8)(v5 - 48) > 0x19u )
return result;
v8 = (unsigned __int8)v5 - 48;
result = v8;
v9 = (int)v6 >> (7 - *((_BYTE *)&steppedParametersBits + v8));
if ( *((_BYTE *)&currentPreset + v8) == (_BYTE)v9 )
{
if ( v8 != 17 )
return result;
v10 = 0;
goto LABEL_20;
}
*((_BYTE *)&currentPreset + v8) = v9;
if ( v8 == 17 )
{
v10 = 1;
LABEL_20:
if ( (_BYTE)v9 )
assigner_latchPattern();
else
assigner_setPoly();
result = assigner_getPattern((unsigned int)((_DWORD)&currentPreset + 86), 0LL);
if ( v10 )
goto LABEL_13;
return result;
}
LABEL_13:
ui_setPresetModified(1LL);
return refreshFullState();
}
result = (unsigned __int16)((unsigned __int8)v3 - 80) + 8LL;
if ( ((*((_WORD *)&currentPreset + result + 5) >> 2) & 0x7F) != v6 )
{
*((_WORD *)&currentPreset + result + 5) = (4 * v6) | *((_WORD *)&currentPreset + result + 5) & 0xFE00;
goto LABEL_13;
}
return result;
}

original_code:
static void midi_ccEvent(MidiDevice * device, uint8_t channel, uint8_t control, uint8_t value)
{
 int16_t param;
 int8_t change=0;
 if(!midiFilterChannel(channel))
  return;
 if(control==0 && value<=1 && settings.presetMode!=value)
 {
  settings.presetMode=value;
  settings_save();
  refreshPresetMode();
  refreshFullState();
 }
 else if(control==1)
 {
  synth_wheelEvent(0,value<<9,2,0);
 }
 else if(control==64)
 {
  assigner_holdEvent(value);
  return;
 }
 if(!settings.presetMode)
  return;
 if(control>=16 && control<16 +cpCount)
 {
  param=control-16;
  if((currentPreset.continuousParameters[param]>>9)!=value)
  {
   currentPreset.continuousParameters[param]&=0x01fc;
   currentPreset.continuousParameters[param]|=(uint16_t)value<<9;
   change=1;
  }
 }
 else if(control>=80 && control<80 +cpCount)
 {
  param=control-80;
  if(((currentPreset.continuousParameters[param]>>2)&0x7f)!=value)
  {
   currentPreset.continuousParameters[param]&=0xfe00;
   currentPreset.continuousParameters[param]|=(uint16_t)value<<2;
   change=1;
  }
 }
 else if(control>=48 && control<48 +spCount)
 {
  param=control-48;
  uint8_t v;
  v=value>>(7-steppedParametersBits[param]);
  if(currentPreset.steppedParameters[param]!=v)
  {
   currentPreset.steppedParameters[param]=v;
   change=1;
  }
  if(param==spUnison)
  {
   if(v)
   {
    assigner_latchPattern();
   }
   else
   {
    assigner_setPoly();
   }
   assigner_getPattern(currentPreset.voicePattern,((void *)0));
  }
 }
 if(change)
 {
  ui_setPresetModified(1);
  refreshFullState();
 }
}

canonical_original_code:
static void midi_ccEvent(struct _midi_device *device, unsigned char channel, unsigned char control, unsigned char value)
{
 short param;
 char change = 0;
 if(!midiFilterChannel(channel))
  return;
 if(control==0 && value<=1 && settings.presetMode!=value)
 {
  settings.presetMode=value;
  settings_save();
  refreshPresetMode();
  refreshFullState();
 }
 else if(control==1)
 {
  synth_wheelEvent(0,value<<9,2,0);
 }
 else if(control==64)
 {
  assigner_holdEvent(value);
  return;
 }
 if(!settings.presetMode)
  return;
 if(control>=16 && control<16 +cpCount)
 {
  param=control-16;
  if((currentPreset.continuousParameters[param]>>9)!=value)
  {
   currentPreset.continuousParameters[param]&=0x01fc;
   currentPreset.continuousParameters[param]|=(unsigned short)value<<9;
   change=1;
  }
 }
 else if(control>=80 && control<80 +cpCount)
 {
  param=control-80;
  if(((currentPreset.continuousParameters[param]>>2)&0x7f)!=value)
  {
   currentPreset.continuousParameters[param]&=0xfe00;
   currentPreset.continuousParameters[param]|=(unsigned short)value<<2;
   change=1;
  }
 }
 else if(control>=48 && control<48 +spCount)
 {
  param=control-48;
  unsigned char v;
  v=value>>(7-steppedParametersBits[param]);
  if(currentPreset.steppedParameters[param]!=v)
  {
   currentPreset.steppedParameters[param]=v;
   change=1;
  }
  if(param==spUnison)
  {
   if(v)
   {
    assigner_latchPattern();
   }
   else
   {
    assigner_setPoly();
   }
   assigner_getPattern(currentPreset.voicePattern,((void *)0));
  }
 }
 if(change)
 {
  ui_setPresetModified(1);
  refreshFullState();
 }
}

variable_types:
control
unsigned char

variable_types:
value
unsigned char

variable_types: param short

variable_types: change char

variable_types:
v
unsigned char


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

result = midiFilterChannel(a2);
if ( (_BYTE)result )
result = assigner_assignNote(v3, 0LL, 0LL, 0LL);
return result;
}

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

result = func0(a2);
if ( (_BYTE)result )
result = assigner_assignNote(v3, 0LL, 0LL, 0LL);
return result;
}

original_code:
static void midi_noteOffEvent(MidiDevice * device, uint8_t channel, uint8_t note, uint8_t velocity)
{
 if(!midiFilterChannel(channel))
  return;
 assigner_assignNote(note,0,0,0);
}

canonical_original_code:
static void midi_noteOffEvent(struct _midi_device *device, unsigned char channel, unsigned char note, unsigned char velocity)
{
 if(!midiFilterChannel(channel))
  return;
 assigner_assignNote(note,0,0,0);
}

variable_types:
velocity
unsigned char


decompiled_code:
__int64 __fastcall midi_noteOnEvent(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
__int16 v4; // cx

result = midiFilterChannel(a2);
if ( (_BYTE)result )
result = assigner_assignNote(v3, (_BYTE)v4 != 0, (unsigned __int16)((v4 << 9) + 511), 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
__int16 v4; // cx

result = func0(a2);
if ( (_BYTE)result )
result = assigner_assignNote(v3, (_BYTE)v4 != 0, (unsigned __int16)((v4 << 9) + 511), 0LL);
return result;
}

original_code:
static void midi_noteOnEvent(MidiDevice * device, uint8_t channel, uint8_t note, uint8_t velocity)
{
 if(!midiFilterChannel(channel))
  return;
 assigner_assignNote(note,velocity!=0,(((uint32_t)velocity+1)<<9)-1,0);
}

canonical_original_code:
static void midi_noteOnEvent(struct _midi_device *device, unsigned char channel, unsigned char note, unsigned char velocity)
{
 if(!midiFilterChannel(channel))
  return;
 assigner_assignNote(note,velocity!=0,(((unsigned int)velocity+1)<<9)-1,0);
}

variable_types:
note
unsigned char


midiCombineBytes

decompiled_code:
__int64 __fastcall midiCombineBytes(unsigned __int8 a1, unsigned __int8 a2)
{
return (a2 << 7) | (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1, unsigned __int8 a2)
{
return (a2 << 7) | (unsigned int)a1;
}

original_code:
uint16_t midiCombineBytes(uint8_t first, uint8_t second)
{
   uint16_t _14bit;
   _14bit = (uint16_t)second;
   _14bit <<= 7;
   _14bit |= (uint16_t)first;
   return _14bit;
}

canonical_original_code:
unsigned short midiCombineBytes(unsigned char first, unsigned char second)
{
   unsigned short _14bit;
   _14bit = (unsigned short)second;
   _14bit <<= 7;
   _14bit |= (unsigned short)first;
   return _14bit;
}

variable_types:
first
unsigned char

variable_types:
second
unsigned char


decompiled_code:
__int64 __fastcall midi_pitchBendEvent(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
unsigned __int8 v4; // cl
__int16 v5; // ax
__int64 v6; // rdx
__int64 v7; // rcx

result = midiFilterChannel(a2);
if ( (_BYTE)result )
{
v5 = midiCombineBytes(v3, v4);
result = synth_wheelEvent((unsigned int)(__int16)(4 * (v5 - 0x2000)), 0LL, v6, v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
unsigned __int8 v4; // cl
__int16 v5; // ax
__int64 v6; // rdx
__int64 v7; // rcx

result = func0(a2);
if ( (_BYTE)result )
{
v5 = func8(v3, v4);
result = synth_wheelEvent((unsigned int)(__int16)(4 * (v5 - 0x2000)), 0LL, v6, v7);
}
return result;
}

original_code:
static void midi_pitchBendEvent(MidiDevice * device, uint8_t channel, uint8_t v1, uint8_t v2)
{
 if(!midiFilterChannel(channel))
  return;
 int16_t value;
 value=midiCombineBytes(v1,v2);
 value-=0x2000;
 value<<=2;
 synth_wheelEvent(value,0,1,0);
}

canonical_original_code:
static void midi_pitchBendEvent(struct _midi_device *device, unsigned char channel, unsigned char v1, unsigned char v2)
{
 if(!midiFilterChannel(channel))
  return;
 short value;
 value=midiCombineBytes(v1,v2);
 value-=0x2000;
 value<<=2;
 synth_wheelEvent(value,0,1,0);
}

variable_types: value short


decompiled_code:
__int64 midi_init()
{
midi_device_init(&midi);
midi_device_set_send_func(&midi, midi_sendFunc);
midi_register_noteon_callback(&midi, midi_noteOnEvent);
midi_register_noteoff_callback(&midi, midi_noteOffEvent);
midi_register_cc_callback(&midi, midi_ccEvent);
midi_register_progchange_callback(&midi, midi_progChangeEvent);
midi_register_pitchbend_callback(&midi, midi_pitchBendEvent);
midi_register_sysex_callback(&midi, midi_sysexEvent);
midi_register_realtime_callback(&midi, midi_realtimeEvent);
sysexSize = 0;
return bytequeue_init(&sendQueue, &sendQueueData, 32LL);
}

canonical_decompiled_code:
__int64 func10()
{
midi_device_init(&midi);
midi_device_set_send_func(&midi, midi_sendFunc);
midi_register_noteon_callback(&midi, midi_noteOnEvent);
midi_register_noteoff_callback(&midi, midi_noteOffEvent);
midi_register_cc_callback(&midi, midi_ccEvent);
midi_register_progchange_callback(&midi, midi_progChangeEvent);
midi_register_pitchbend_callback(&midi, midi_pitchBendEvent);
midi_register_sysex_callback(&midi, midi_sysexEvent);
midi_register_realtime_callback(&midi, midi_realtimeEvent);
sysexSize = 0;
return bytequeue_init(&sendQueue, &sendQueueData, 32LL);
}

original_code:
void midi_init(void)
{
 midi_device_init(&midi);
 midi_device_set_send_func(&midi,midi_sendFunc);
 midi_register_noteon_callback(&midi,midi_noteOnEvent);
 midi_register_noteoff_callback(&midi,midi_noteOffEvent);
 midi_register_cc_callback(&midi,midi_ccEvent);
 midi_register_progchange_callback(&midi,midi_progChangeEvent);
 midi_register_pitchbend_callback(&midi,midi_pitchBendEvent);
 midi_register_sysex_callback(&midi,midi_sysexEvent);
 midi_register_realtime_callback(&midi,midi_realtimeEvent);
 sysexSize=0;
 bytequeue_init(&sendQueue, sendQueueData, sizeof(sendQueueData));
}

canonical_original_code:
void midi_init()
{
 midi_device_init(&midi);
 midi_device_set_send_func(&midi,midi_sendFunc);
 midi_register_noteon_callback(&midi,midi_noteOnEvent);
 midi_register_noteoff_callback(&midi,midi_noteOffEvent);
 midi_register_cc_callback(&midi,midi_ccEvent);
 midi_register_progchange_callback(&midi,midi_progChangeEvent);
 midi_register_pitchbend_callback(&midi,midi_pitchBendEvent);
 midi_register_sysex_callback(&midi,midi_sysexEvent);
 midi_register_realtime_callback(&midi,midi_realtimeEvent);
 sysexSize=0;
 bytequeue_init(&sendQueue, sendQueueData, sizeof(sendQueueData));
}


decompiled_code:
__int64 __fastcall midi_update(char a1)
{
__int64 result; // rax
unsigned __int8 v2; // bl

if ( a1 )
{
result = bytequeue_length(&sendQueue);
if ( !(_BYTE)result )
return result;
LABEL_5:
v2 = bytequeue_get(&sendQueue, 0LL);
bytequeue_remove(&sendQueue, 1LL);
return uart_send(v2);
}
midi_device_process(&midi);
result = bytequeue_length(&sendQueue);
if ( (_BYTE)result )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char a1)
{
__int64 result; // rax
unsigned __int8 v2; // bl

if ( a1 )
{
result = bytequeue_length(&sendQueue);
if ( !(_BYTE)result )
return result;
LABEL_5:
v2 = bytequeue_get(&sendQueue, 0LL);
bytequeue_remove(&sendQueue, 1LL);
return uart_send(v2);
}
midi_device_process(&midi);
result = bytequeue_length(&sendQueue);
if ( (_BYTE)result )
goto LABEL_5;
return result;
}

original_code:
void midi_update(int8_t onlySend)
{
 if(!onlySend)
  midi_device_process(&midi);
 if(bytequeue_length(&sendQueue)>0)
 {
  uint8_t b;
  b=bytequeue_get(&sendQueue,0);
  bytequeue_remove(&sendQueue,1);
  uart_send(b);
 }
}

canonical_original_code:
void midi_update(char onlySend)
{
 if(!onlySend)
  midi_device_process(&midi);
 if(bytequeue_length(&sendQueue)>0)
 {
  unsigned char b;
  b=bytequeue_get(&sendQueue,0);
  bytequeue_remove(&sendQueue,1);
  uart_send(b);
 }
}

variable_types: onlySend char

variable_types:
b
unsigned char


sendEnqueue

decompiled_code:
__int64 __fastcall sendEnqueue(unsigned __int8 a1)
{
__int64 result; // rax

while ( 1 )
{
result = bytequeue_enqueue(&sendQueue, a1);
if ( (_BYTE)result )
break;
midi_update(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 a1)
{
__int64 result; // rax

while ( 1 )
{
result = bytequeue_enqueue(&sendQueue, a1);
if ( (_BYTE)result )
break;
func11(1);
}
return result;
}

original_code:
static void sendEnqueue(uint8_t b)
{
 for(;;)
 {
  if(bytequeue_enqueue(&sendQueue,b))
   break;
  midi_update(1);
 }
}

canonical_original_code:
static void sendEnqueue(unsigned char b)
{
 for(;;)
 {
  if(bytequeue_enqueue(&sendQueue,b))
   break;
  midi_update(1);
 }
}


decompiled_code:
__int64 __fastcall midi_sendFunc(__int64 a1, __int16 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 a5)
{
__int64 result; // rax

if ( a2 )
{
result = sendEnqueue(a3);
if ( a2 != 1 )
{
result = sendEnqueue(a4);
if ( a2 != 2 )
result = sendEnqueue(a5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int16 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 a5)
{
__int64 result; // rax

if ( a2 )
{
result = func12(a3);
if ( a2 != 1 )
{
result = func12(a4);
if ( a2 != 2 )
result = func12(a5);
}
}
return result;
}

original_code:
static void midi_sendFunc(MidiDevice * device, uint16_t count, uint8_t b0, uint8_t b1, uint8_t b2)
{
 if(count>0)
  sendEnqueue(b0);
 if(count>1)
  sendEnqueue(b1);
 if(count>2)
  sendEnqueue(b2);
}

canonical_original_code:
static void midi_sendFunc(struct _midi_device *device, unsigned short count, unsigned char b0, unsigned char b1, unsigned char b2)
{
 if(count>0)
  sendEnqueue(b0);
 if(count>1)
  sendEnqueue(b1);
 if(count>2)
  sendEnqueue(b2);
}

variable_types:
count
unsigned short


decompiled_code:
__int64 __fastcall midi_newData(char a1)
{
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
return midi_device_input(&midi, 1LL, v2);
}

canonical_decompiled_code:
__int64 __fastcall func15(char a1)
{
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
return midi_device_input(&midi, 1LL, v2);
}

original_code:
void midi_newData(uint8_t data)
{
 midi_device_input(&midi,1,&data);
}

canonical_original_code:
void midi_newData(unsigned char data)
{
 midi_device_input(&midi,1,&data);
}

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall midi_dumpPreset(unsigned __int8 a1)
{
__int64 result; // rax
__int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

result = 0LL;
v2[0] = 0;
if ( a1 <= 0x63u )
{
storage_export((unsigned int)(char)a1, &tempBuffer, v2);
result = sysexSend_constprop_0(v2[0]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int8 a1)
{
__int64 result; // rax
__int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

result = 0LL;
v2[0] = 0;
if ( a1 <= 0x63u )
{
storage_export((unsigned int)(char)a1, &tempBuffer, v2);
result = func14(v2[0]);
}
return result;
}

original_code:
void midi_dumpPreset(int8_t number)
{
 int16_t size=0;
 if(number<0 || number>99)
  return;
 storage_export(number,tempBuffer,&size);
 sysexSend(1,size);
}

canonical_original_code:
void midi_dumpPreset(char number)
{
 short size = 0;
 if(number<0 || number>99)
  return;
 storage_export(number,tempBuffer,&size);
 sysexSend(1,size);
}

variable_types: number char

variable_types: size short