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

canonical_decompiled_code:
__int64 func20()
{
memset(settings, 0, 0x128uLL);
*(_DWORD *)&settings[148] = 0;
settings[144] = 0x8000;
HIBYTE(settings[146]) = -1;
HIBYTE(settings[147]) = 63;
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

return_type: void


updateGates

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

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

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_244[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_244[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_284 & ~(1 << a1);
if ( a2 )
v2 |= 1 << a1;
byte_284 = v2;
return updateGates();
}

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

v2 = byte_284 & ~(1 << a1);
if ( a2 )
v2 |= 1 << a1;
byte_284 = 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()
{
sh = 0LL;
qword_248 = 0LL;
qword_250 = 0LL;
qword_258 = 0LL;
qword_260 = 0LL;
qword_268 = 0LL;
qword_270 = 0LL;
qword_278 = 0LL;
unk_280 = 0LL;
}

canonical_decompiled_code:
void func7()
{
sh = 0LL;
qword_248 = 0LL;
qword_250 = 0LL;
qword_258 = 0LL;
qword_260 = 0LL;
qword_268 = 0LL;
qword_270 = 0LL;
qword_278 = 0LL;
unk_280 = 0LL;
}

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


decompiled_code:
__int64 sh_update()
{
__int64 i; // rbx

for ( i = 0LL; i != 32; ++i )
updateCV(i, word_244[i]);
return updateGates();
}

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

return_type: 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(unsigned __int8 a1)
{
__int64 result; // rax

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

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

result = 0LL;
if ( (unsigned __int8)(a1 - 24) <= 0x3Cu )
result = byte_148[a1] & 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 int v1; // er13
char v2; // r12
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 v5; // bp
unsigned __int8 v6; // bl
int v7; // eax

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

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
unsigned int v1; // er13
char v2; // r12
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 v5; // bp
unsigned __int8 v6; // bl
int v7; // eax

v1 = (unsigned __int8)(8 * (a1 == 0));
v2 = ((a1 == 0) << 6) + 8;
do
{
io_write(8LL, v1);
v5 = io_read(10LL);
v6 = v2 - 8;
do
{
v7 = (unsigned __int8)scanner[v6];
if ( (v7 & 0xFE) != 0 )
{
result = (unsigned int)(v7 - 2);
scanner[v6] = result;
}
else
{
result = v7 & 1;
if ( (_BYTE)result != (v5 & 1) )
{
scanner[v6] = v5 & 1 | 0xA;
v4 = v5 & 1;
if ( v6 > 0x3Fu )
result = synth_keyEvent((unsigned __int8)(v6 - 40), v4);
else
result = synth_buttonEvent(v6, v4);
}
}
v5 >>= 1;
++v6;
}
while ( v2 != v6 );
++v1;
v2 += 8;
}
while ( v2 != -120 );
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:
_BOOL8 __fastcall midiFilterChannel(char a1)
{
char v1; // dl
_BOOL8 result; // rax

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

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
char v1; // dl
_BOOL8 result; // rax

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

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 func2(__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

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:
__int64 __fastcall midi_progChangeEvent(__int64 a1, char a2, unsigned __int8 a3)
{
__int64 result; // rax

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

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

result = func1(a2);
if ( (_BYTE)result && settings[292] && a3 <= 0x63u && a3 != *(_WORD *)&settings[290] )
{
result = preset_loadCurrent(a3);
if ( (_BYTE)result )
{
*(_WORD *)&settings[290] = a3;
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

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:
__int64 __fastcall midi_ccEvent(__int64 a1, char a2, int a3, __int16 a4)
{
__int64 result; // rax
__int16 v7; // bx
__int16 v8; // bx
int v9; // ebp
char v10; // bl
__int16 v11; // bx

result = midiFilterChannel(a2);
if ( !(_BYTE)result )
return result;
if ( (_BYTE)a3 || (unsigned __int8)a4 > 1u )
{
if ( (_BYTE)a3 != 1 )
{
if ( (_BYTE)a3 == 64 )
return assigner_holdEvent((unsigned int)(char)a4);
if ( !settings[292] )
return result;
if ( (unsigned __int8)(a3 - 16) <= 0x1Du )
{
v11 = (unsigned __int8)a3 - 16;
result = (unsigned int)v11;
if ( *((_WORD *)&currentPreset + v11 + 13) >> 9 == (unsigned __int8)a4 )
return result;
*((_WORD *)&currentPreset + v11 + 13) = *((_WORD *)&currentPreset + v11 + 13) & 0x1FC | (a4 << 9);
goto LABEL_25;
}
goto LABEL_6;
}
result = synth_wheelEvent(0LL, (unsigned __int16)(a4 << 9), 2LL, 0LL);
}
else
{
result = (unsigned __int8)a4;
if ( (char)settings[292] == (unsigned __int8)a4 )
{
if ( !settings[292] )
return result;
LABEL_6:
if ( (unsigned __int8)(a3 - 80) <= 0x1Du )
{
v7 = (unsigned __int8)a3 - 80;
result = *((unsigned __int16 *)&currentPreset + v7 + 13);
if ( ((*((_WORD *)&currentPreset + v7 + 13) >> 2) & 0x7F) == (unsigned __int8)a4 )
return result;
*((_WORD *)&currentPreset + v7 + 13) = (4 * (unsigned __int8)a4) | result & 0xFE00;
goto LABEL_25;
}
goto LABEL_11;
}
settings[292] = a4;
settings_save();
refreshPresetMode();
result = refreshFullState();
}
if ( !settings[292] )
return result;
LABEL_11:
result = (unsigned int)(a3 - 48);
if ( (unsigned __int8)(a3 - 48) > 0x19u )
return result;
v8 = (unsigned __int8)a3 - 48;
result = v8;
v9 = (int)(unsigned __int8)a4 >> (7 - *((_BYTE *)&steppedParametersBits + v8));
if ( *((_BYTE *)&currentPreset + v8) == (_BYTE)v9 )
{
if ( v8 != 17 )
return result;
v10 = 0;
}
else
{
*((_BYTE *)&currentPreset + v8) = v9;
if ( v8 != 17 )
{
LABEL_25:
ui_setPresetModified(1LL);
return refreshFullState();
}
v10 = 1;
}
if ( (_BYTE)v9 )
assigner_latchPattern();
else
assigner_setPoly();
result = assigner_getPattern((unsigned int)((_DWORD)&currentPreset + 86), 0LL);
if ( v10 )
goto LABEL_25;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2, int a3, __int16 a4)
{
__int64 result; // rax
__int16 v7; // bx
__int16 v8; // bx
int v9; // ebp
char v10; // bl
__int16 v11; // bx

result = func1(a2);
if ( !(_BYTE)result )
return result;
if ( (_BYTE)a3 || (unsigned __int8)a4 > 1u )
{
if ( (_BYTE)a3 != 1 )
{
if ( (_BYTE)a3 == 64 )
return assigner_holdEvent((unsigned int)(char)a4);
if ( !settings[292] )
return result;
if ( (unsigned __int8)(a3 - 16) <= 0x1Du )
{
v11 = (unsigned __int8)a3 - 16;
result = (unsigned int)v11;
if ( *((_WORD *)&currentPreset + v11 + 13) >> 9 == (unsigned __int8)a4 )
return result;
*((_WORD *)&currentPreset + v11 + 13) = *((_WORD *)&currentPreset + v11 + 13) & 0x1FC | (a4 << 9);
goto LABEL_25;
}
goto LABEL_6;
}
result = synth_wheelEvent(0LL, (unsigned __int16)(a4 << 9), 2LL, 0LL);
}
else
{
result = (unsigned __int8)a4;
if ( (char)settings[292] == (unsigned __int8)a4 )
{
if ( !settings[292] )
return result;
LABEL_6:
if ( (unsigned __int8)(a3 - 80) <= 0x1Du )
{
v7 = (unsigned __int8)a3 - 80;
result = *((unsigned __int16 *)&currentPreset + v7 + 13);
if ( ((*((_WORD *)&currentPreset + v7 + 13) >> 2) & 0x7F) == (unsigned __int8)a4 )
return result;
*((_WORD *)&currentPreset + v7 + 13) = (4 * (unsigned __int8)a4) | result & 0xFE00;
goto LABEL_25;
}
goto LABEL_11;
}
settings[292] = a4;
settings_save();
refreshPresetMode();
result = refreshFullState();
}
if ( !settings[292] )
return result;
LABEL_11:
result = (unsigned int)(a3 - 48);
if ( (unsigned __int8)(a3 - 48) > 0x19u )
return result;
v8 = (unsigned __int8)a3 - 48;
result = v8;
v9 = (int)(unsigned __int8)a4 >> (7 - *((_BYTE *)&steppedParametersBits + v8));
if ( *((_BYTE *)&currentPreset + v8) == (_BYTE)v9 )
{
if ( v8 != 17 )
return result;
v10 = 0;
}
else
{
*((_BYTE *)&currentPreset + v8) = v9;
if ( v8 != 17 )
{
LABEL_25:
ui_setPresetModified(1LL);
return refreshFullState();
}
v10 = 1;
}
if ( (_BYTE)v9 )
assigner_latchPattern();
else
assigner_setPoly();
result = assigner_getPattern((unsigned int)((_DWORD)&currentPreset + 86), 0LL);
if ( v10 )
goto LABEL_25;
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, unsigned __int8 a3)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2, unsigned __int8 a3)
{
__int64 result; // rax

result = func1(a2);
if ( (_BYTE)result )
result = assigner_assignNote(a3, 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, unsigned __int8 a3, __int16 a4)
{
__int64 result; // rax

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

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

result = func1(a2);
if ( (_BYTE)result )
result = assigner_assignNote(a3, (_BYTE)a4 != 0, (unsigned __int16)((a4 << 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

return_type: unsigned short


decompiled_code:
__int64 __fastcall midi_pitchBendEvent(__int64 a1, char a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 result; // rax
__int16 v7; // ax

result = midiFilterChannel(a2);
if ( (_BYTE)result )
{
v7 = midiCombineBytes(a3, a4);
result = synth_wheelEvent((unsigned int)(__int16)(4 * (v7 - 0x2000)), 0LL, 1LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 result; // rax
__int16 v7; // ax

result = func1(a2);
if ( (_BYTE)result )
{
v7 = func8(a3, a4);
result = synth_wheelEvent((unsigned int)(__int16)(4 * (v7 - 0x2000)), 0LL, 1LL, 0LL);
}
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 )
midi_device_process(&midi);
result = bytequeue_length(&sendQueue);
if ( (_BYTE)result )
{
v2 = bytequeue_get(&sendQueue, 0LL);
bytequeue_remove(&sendQueue, 1LL);
result = uart_send(v2);
}
return result;
}

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

if ( !a1 )
midi_device_process(&midi);
result = bytequeue_length(&sendQueue);
if ( (_BYTE)result )
{
v2 = bytequeue_get(&sendQueue, 0LL);
bytequeue_remove(&sendQueue, 1LL);
result = uart_send(v2);
}
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, unsigned __int16 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 a5)
{
__int64 result; // rax

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

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

if ( a2 )
{
result = func12(a3);
if ( a2 > 1u )
result = func12(a4);
if ( a2 > 2u )
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

v2[0] = 0;
if ( a1 <= 0x63u )
{
storage_export((unsigned __int16)(char)a1, &tempBuffer, v2);
result = sysexSend(1u, v2[0]);
}
return result;
}

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

v2[0] = 0;
if ( a1 <= 0x63u )
{
storage_export((unsigned __int16)(char)a1, &tempBuffer, v2);
result = func14(1u, 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


sysexReceiveByte

decompiled_code:
__int64 __fastcall sysexReceiveByte(char a1)
{
__int64 result; // rax
char v2; // al
__int16 v3; // ax

if ( a1 == -16 )
{
sysexSize = 0;
tempBuffer = 0LL;
*(_QWORD *)((char *)&tempBuffer + 398) = 0LL;
result = 0LL;
memset(
(void *)(((_DWORD)&tempBuffer + 8) & 0xFFFFFFF8),
0,
8LL * (((unsigned int)&tempBuffer - (((_DWORD)&tempBuffer + 8) & 0xFFFFFFF8) + 406) >> 3));
}
else if ( a1 == -9 )
{
if ( tempBuffer == 1 )
{
if ( *((_BYTE *)&tempBuffer + 1) == 2 )
import_sysex(&tempBuffer, (unsigned int)sysexSize);
}
else if ( tempBuffer )
{
if ( tempBuffer == 126 && *((_BYTE *)&tempBuffer + 2) == 8 && *((_BYTE *)&tempBuffer + 3) == 1 )
mtsReceiveBulkTuningDump((unsigned int)((_DWORD)&tempBuffer + 4), sysexSize - 4);
}
else if ( *((_BYTE *)&tempBuffer + 1) == 97 && *((_BYTE *)&tempBuffer + 2) == 22 )
{
v2 = *((_BYTE *)&tempBuffer + 3);
if ( v2 == 1 )
{
v3 = sysexDescrambleBuffer(4);
storage_import(
*((unsigned __int8 *)&tempBuffer + 4),
(unsigned int)((_DWORD)&tempBuffer + 5),
(unsigned int)(__int16)(v3 - 1));
}
else if ( v2 == 2 )
{
midi_dumpPreset(*((_BYTE *)&tempBuffer + 4));
}
}
sysexSize = 0;
result = refreshFullState();
}
else
{
if ( sysexSize > 405 )
sysexSize = 0;
LOWORD(result) = sysexSize++;
result = (__int16)result;
*((_BYTE *)&tempBuffer + (__int16)result) = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(char a1)
{
__int64 result; // rax
char v2; // al
__int16 v3; // ax

if ( a1 == -16 )
{
sysexSize = 0;
tempBuffer = 0LL;
*(_QWORD *)((char *)&tempBuffer + 398) = 0LL;
result = 0LL;
memset(
(void *)(((_DWORD)&tempBuffer + 8) & 0xFFFFFFF8),
0,
8LL * (((unsigned int)&tempBuffer - (((_DWORD)&tempBuffer + 8) & 0xFFFFFFF8) + 406) >> 3));
}
else if ( a1 == -9 )
{
if ( tempBuffer == 1 )
{
if ( *((_BYTE *)&tempBuffer + 1) == 2 )
import_sysex(&tempBuffer, (unsigned int)sysexSize);
}
else if ( tempBuffer )
{
if ( tempBuffer == 126 && *((_BYTE *)&tempBuffer + 2) == 8 && *((_BYTE *)&tempBuffer + 3) == 1 )
func3((unsigned int)((_DWORD)&tempBuffer + 4), sysexSize - 4);
}
else if ( *((_BYTE *)&tempBuffer + 1) == 97 && *((_BYTE *)&tempBuffer + 2) == 22 )
{
v2 = *((_BYTE *)&tempBuffer + 3);
if ( v2 == 1 )
{
v3 = func0(4);
storage_import(
*((unsigned __int8 *)&tempBuffer + 4),
(unsigned int)((_DWORD)&tempBuffer + 5),
(unsigned int)(__int16)(v3 - 1));
}
else if ( v2 == 2 )
{
func16(*((_BYTE *)&tempBuffer + 4));
}
}
sysexSize = 0;
result = refreshFullState();
}
else
{
if ( sysexSize > 405 )
sysexSize = 0;
LOWORD(result) = sysexSize++;
result = (__int16)result;
*((_BYTE *)&tempBuffer + (__int16)result) = a1;
}
return result;
}

original_code:
static void sysexReceiveByte(uint8_t b)
{
 int16_t size;
 switch(b)
 {
 case 0xF0:
  sysexSize=0;
  memset(tempBuffer,0,406);
  break;
 case 0xF7:
  if(tempBuffer[0]==0x01 && tempBuffer[1]==0x02)
  {
   import_sysex(tempBuffer,sysexSize);
  }
  else if(tempBuffer[0]==0x00 && tempBuffer[1]==0x61 && tempBuffer[2]==0x16)
  {
   switch(tempBuffer[3])
   {
   case 1:
    size=sysexDescrambleBuffer(4);
    storage_import(tempBuffer[4],&tempBuffer[5],size-1);
    break;
   case 2:
    midi_dumpPreset(tempBuffer[4]);
    break;
   }
  }
  else if(tempBuffer[0]==0x7E)
  {
   switch(tempBuffer[2])
   {
   case 0x08:
    switch(tempBuffer[3])
    {
     case 0x01:
      mtsReceiveBulkTuningDump(&tempBuffer[4],sysexSize-4);
     break;
     case 0x00:
     break;
    }
    break;
   }
  }
  sysexSize=0;
  refreshFullState();
  break;
 default:
  if(sysexSize>=406)
  {
   sysexSize=0;
  }
  tempBuffer[sysexSize++]=b;
 }
}

canonical_original_code:
static void sysexReceiveByte(unsigned char b)
{
 short size;
 switch(b)
 {
 case 0xF0:
  sysexSize=0;
  memset(tempBuffer,0,406);
  break;
 case 0xF7:
  if(tempBuffer[0]==0x01 && tempBuffer[1]==0x02)
  {
   import_sysex(tempBuffer,sysexSize);
  }
  else if(tempBuffer[0]==0x00 && tempBuffer[1]==0x61 && tempBuffer[2]==0x16)
  {
   switch(tempBuffer[3])
   {
   case 1:
    size=sysexDescrambleBuffer(4);
    storage_import(tempBuffer[4],&tempBuffer[5],size-1);
    break;
   case 2:
    midi_dumpPreset(tempBuffer[4]);
    break;
   }
  }
  else if(tempBuffer[0]==0x7E)
  {
   switch(tempBuffer[2])
   {
   case 0x08:
    switch(tempBuffer[3])
    {
     case 0x01:
      mtsReceiveBulkTuningDump(&tempBuffer[4],sysexSize-4);
     break;
     case 0x00:
     break;
    }
    break;
   }
  }
  sysexSize=0;
  refreshFullState();
  break;
 default:
  if(sysexSize>=406)
  {
   sysexSize=0;
  }
  tempBuffer[sysexSize++]=b;
 }
}


decompiled_code:
__int64 __fastcall midi_sysexEvent(__int64 a1, unsigned __int16 a2, char a3, char a4, char a5)
{
__int64 result; // rax
unsigned __int16 v6; // bx

result = (unsigned __int16)sysexSize;
v6 = a2 + ~sysexSize;
if ( !sysexSize )
v6 = a2;
if ( v6 )
{
result = sysexReceiveByte(a3);
if ( v6 > 1u )
result = sysexReceiveByte(a4);
if ( v6 > 2u )
result = sysexReceiveByte(a5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned __int16 a2, char a3, char a4, char a5)
{
__int64 result; // rax
unsigned __int16 v6; // bx

result = (unsigned __int16)sysexSize;
v6 = a2 + ~sysexSize;
if ( !sysexSize )
v6 = a2;
if ( v6 )
{
result = func17(a3);
if ( v6 > 1u )
result = func17(a4);
if ( v6 > 2u )
result = func17(a5);
}
return result;
}

original_code:
static void midi_sysexEvent(MidiDevice * device, uint16_t count, uint8_t b0, uint8_t b1, uint8_t b2)
{
 if(sysexSize)
  count=count-sysexSize-1;
 if(count>0)
  sysexReceiveByte(b0);
 if(count>1)
  sysexReceiveByte(b1);
 if(count>2)
  sysexReceiveByte(b2);
}

canonical_original_code:
static void midi_sysexEvent(struct _midi_device *device, unsigned short count, unsigned char b0, unsigned char b1, unsigned char b2)
{
 if(sysexSize)
  count=count-sysexSize-1;
 if(count>0)
  sysexReceiveByte(b0);
 if(count>1)
  sysexReceiveByte(b1);
 if(count>2)
  sysexReceiveByte(b2);
}

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; } *


decompiled_code:
__int64 midi_dumpPresets()
{
unsigned int i; // ebx
__int64 result; // rax
__int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

v2[0] = 0;
for ( i = 0; i != 100; ++i )
{
result = preset_loadCurrent(i);
if ( (_BYTE)result )
{
storage_export(i, &tempBuffer, v2);
result = sysexSend(1u, v2[0]);
}
}
return result;
}

canonical_decompiled_code:
__int64 func19()
{
unsigned int i; // ebx
__int64 result; // rax
__int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

v2[0] = 0;
for ( i = 0; i != 100; ++i )
{
result = preset_loadCurrent(i);
if ( (_BYTE)result )
{
storage_export(i, &tempBuffer, v2);
result = func14(1u, v2[0]);
}
}
return result;
}

original_code:
void midi_dumpPresets(void)
{
 int8_t i;
 int16_t size=0;
 for(i=0;i<100;++i)
 {
  if(preset_loadCurrent(i))
  {
   storage_export(i,tempBuffer,&size);
   sysexSend(1,size);
  }
 }
}

canonical_original_code:
void midi_dumpPresets()
{
 char i;
 short size = 0;
 for(i=0;i<100;++i)
 {
  if(preset_loadCurrent(i))
  {
   storage_export(i,tempBuffer,&size);
   sysexSend(1,size);
  }
 }
}

variable_types: i char


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

if ( a2 )
result = midi_send_noteon(&midi, (unsigned __int8)settings[294], a1, a3 >> 9);
else
result = midi_send_noteoff(&midi, (unsigned __int8)settings[294], a1, a3 >> 9);
return result;
}

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

if ( a2 )
result = midi_send_noteon(&midi, (unsigned __int8)settings[294], a1, a3 >> 9);
else
result = midi_send_noteoff(&midi, (unsigned __int8)settings[294], a1, a3 >> 9);
return result;
}

original_code:
void midi_sendNoteEvent(uint8_t note, int8_t gate, uint16_t velocity)
{
 if(gate)
  midi_send_noteon(&midi,settings.midiSendChannel,note,velocity>>9);
 else
  midi_send_noteoff(&midi,settings.midiSendChannel,note,velocity>>9);
}

canonical_original_code:
void midi_sendNoteEvent(unsigned char note, char gate, unsigned short velocity)
{
 if(gate)
  midi_send_noteon(&midi,settings.midiSendChannel,note,velocity>>9);
 else
  midi_send_noteoff(&midi,settings.midiSendChannel,note,velocity>>9);
}

variable_types: gate char

variable_types:
velocity
unsigned short


decompiled_code:
__int16 __fastcall midi_sendWheelEvent(__int16 a1, unsigned __int16 a2, char a3)
{
__int16 result; // ax

if ( (a3 & 1) != 0 )
{
result = lastBend_1 ^ a1;
if ( (((unsigned __int16)lastBend_1 ^ (unsigned __int16)a1) & 0xFFFC) != 0 )
{
result = midi_send_pitchbend(&midi, (unsigned __int8)settings[294], (unsigned int)a1);
lastBend_1 = a1;
}
}
if ( (a3 & 2) != 0 )
{
result = lastMod_0 ^ a2;
if ( (((unsigned __int16)lastMod_0 ^ a2) & 0xFE00) != 0 )
{
result = midi_send_cc(&midi, (unsigned __int8)settings[294], 1LL, a2 >> 9);
lastMod_0 = a2;
}
}
return result;
}

canonical_decompiled_code:
__int16 __fastcall func21(__int16 a1, unsigned __int16 a2, char a3)
{
__int16 result; // ax

if ( (a3 & 1) != 0 )
{
result = lastBend_1 ^ a1;
if ( (((unsigned __int16)lastBend_1 ^ (unsigned __int16)a1) & 0xFFFC) != 0 )
{
result = midi_send_pitchbend(&midi, (unsigned __int8)settings[294], (unsigned int)a1);
lastBend_1 = a1;
}
}
if ( (a3 & 2) != 0 )
{
result = lastMod_0 ^ a2;
if ( (((unsigned __int16)lastMod_0 ^ a2) & 0xFE00) != 0 )
{
result = midi_send_cc(&midi, (unsigned __int8)settings[294], 1LL, a2 >> 9);
lastMod_0 = a2;
}
}
return result;
}

original_code:
void midi_sendWheelEvent(int16_t bend, uint16_t modulation, uint8_t mask)
{
 static int16_t lastBend=0;
 static uint16_t lastMod=0;
 if(mask&1 && (bend&0xfffc)!=(lastBend&0xfffc))
 {
  midi_send_pitchbend(&midi,settings.midiSendChannel,bend);
  lastBend=bend;
 }
 if(mask&2 && (modulation&0xfe00)!=(lastMod&0xfe00))
 {
  midi_send_cc(&midi,settings.midiSendChannel,1,modulation>>9);
  lastMod=modulation;
 }
}

canonical_original_code:
void midi_sendWheelEvent(short bend, unsigned short modulation, unsigned char mask)
{
 static short lastBend = 0;
 static unsigned short lastMod = 0;
 if(mask&1 && (bend&0xfffc)!=(lastBend&0xfffc))
 {
  midi_send_pitchbend(&midi,settings.midiSendChannel,bend);
  lastBend=bend;
 }
 if(mask&2 && (modulation&0xfe00)!=(lastMod&0xfe00))
 {
  midi_send_cc(&midi,settings.midiSendChannel,1,modulation>>9);
  lastMod=modulation;
 }
}

variable_types: bend short

variable_types:
modulation
unsigned short

variable_types:
mask
unsigned char

variable_types: lastBend short

variable_types:
lastMod
unsigned short


decompiled_code:
__int64 __fastcall midi_sendSustainEvent(char a1)
{
return midi_send_cc(&midi, (unsigned __int8)settings[294], 64LL, a1 != 0 ? 0x7F : 0);
}

canonical_decompiled_code:
__int64 __fastcall func22(char a1)
{
return midi_send_cc(&midi, (unsigned __int8)settings[294], 64LL, a1 != 0 ? 0x7F : 0);
}

original_code:
void midi_sendSustainEvent(int8_t on)
{
 midi_send_cc(&midi,settings.midiSendChannel,64,on?0x7f:0x00);
}

canonical_original_code:
void midi_sendSustainEvent(char on)
{
 midi_send_cc(&midi,settings.midiSendChannel,64,on?0x7f:0x00);
}

variable_types: on char


isEmpty

original_code:
static int8_t isEmpty(void)
{
 int16_t i;
 for(i=0;i<128;++i)
  if(arp.notes[i]!=(255))
   return 0;
 return 1;
}

canonical_original_code:
static char isEmpty()
{
 short i;
 for(i=0;i<128;++i)
  if(arp.notes[i]!=(255))
   return 0;
 return 1;
}

variable_types: i short


finishPreviousNote

decompiled_code:
__int64 finishPreviousNote()
{
char v0; // di
__int64 result; // rax

v0 = byte_622;
if ( byte_622 != -1 )
{
assigner_assignNote((unsigned __int8)(BYTE1(qword_623) + (byte_622 & 0x7F) + 24), 0LL, 0LL, 0LL);
result = midi_sendNoteEvent((unsigned __int8)(BYTE1(qword_623) + (v0 & 0x7F) + 24), 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
char v0; // di
__int64 result; // rax

v0 = byte_622;
if ( byte_622 != -1 )
{
assigner_assignNote((unsigned __int8)(BYTE1(qword_623) + (byte_622 & 0x7F) + 24), 0LL, 0LL, 0LL);
result = midi_sendNoteEvent((unsigned __int8)(BYTE1(qword_623) + (v0 & 0x7F) + 24), 0LL, 0LL);
}
return result;
}

original_code:
static void finishPreviousNote(void)
{
 if(arp.previousNote!=(255))
 {
  uint8_t n=arp.previousNote&~0x80;
  assigner_assignNote(n+24 +arp.previousTranspose,0,0,0);
  midi_sendNoteEvent(n+24 +arp.previousTranspose,0,0);
 }
}

canonical_original_code:
static void finishPreviousNote()
{
 if(arp.previousNote!=(255))
 {
  unsigned char n = arp.previousNote&~0x80;
  assigner_assignNote(n+24 +arp.previousTranspose,0,0,0);
  midi_sendNoteEvent(n+24 +arp.previousTranspose,0,0);
 }
}

variable_types:
n
unsigned char


killAllNotes

decompiled_code:
__int64 killAllNotes()
{
finishPreviousNote();
word_620 = -1;
byte_622 = -1;
arp = -1LL;
qword_5A8 = -1LL;
qword_5B0 = -1LL;
qword_5B8 = -1LL;
qword_5C0 = -1LL;
qword_5C8 = -1LL;
qword_5D0 = -1LL;
qword_5D8 = -1LL;
qword_5E0 = -1LL;
qword_5E8 = -1LL;
qword_5F0 = -1LL;
qword_5F8 = -1LL;
qword_600 = -1LL;
qword_608 = -1LL;
qword_610 = -1LL;
qword_618 = -1LL;
return assigner_allKeysOff();
}

canonical_decompiled_code:
__int64 func2()
{
func1();
word_620 = -1;
byte_622 = -1;
arp = -1LL;
qword_5A8 = -1LL;
qword_5B0 = -1LL;
qword_5B8 = -1LL;
qword_5C0 = -1LL;
qword_5C8 = -1LL;
qword_5D0 = -1LL;
qword_5D8 = -1LL;
qword_5E0 = -1LL;
qword_5E8 = -1LL;
qword_5F0 = -1LL;
qword_5F8 = -1LL;
qword_600 = -1LL;
qword_608 = -1LL;
qword_610 = -1LL;
qword_618 = -1LL;
return assigner_allKeysOff();
}

original_code:
static void killAllNotes(void)
{
 finishPreviousNote();
 arp.noteIndex=-1;
 arp.previousNote=(255);
 memset(arp.notes,(255),128);
 assigner_allKeysOff();
}

canonical_original_code:
static void killAllNotes()
{
 finishPreviousNote();
 arp.noteIndex=-1;
 arp.previousNote=(255);
 memset(arp.notes,(255),128);
 assigner_allKeysOff();
}


killHeldNotes

decompiled_code:
__int64 __fastcall killHeldNotes(__int64 a1, __int64 a2)
{
__int16 *v2; // rax
__int64 result; // rax

v2 = (__int16 *)&arp;
do
{
if ( *(char *)v2 < 0 )
*(_BYTE *)v2 = -1;
v2 = (__int16 *)((char *)v2 + 1);
}
while ( v2 != &word_620 );
result = isEmpty(a1, a2, &word_620);
if ( (_BYTE)result )
result = finishPreviousNote();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int16 *v2; // rax
__int64 result; // rax

v2 = (__int16 *)&arp;
do
{
if ( *(char *)v2 < 0 )
*(_BYTE *)v2 = -1;
v2 = (__int16 *)((char *)v2 + 1);
}
while ( v2 != &word_620 );
result = func0(a1, a2, &word_620);
if ( (_BYTE)result )
result = func1();
return result;
}

original_code:
static void killHeldNotes(void)
{
 int16_t i;
 for(i=0;i<128;++i)
  if(arp.notes[i]&0x80)
   arp.notes[i]=(255);
 if(isEmpty())
  finishPreviousNote();
}

canonical_original_code:
static void killHeldNotes()
{
 short i;
 for(i=0;i<128;++i)
  if(arp.notes[i]&0x80)
   arp.notes[i]=(255);
 if(isEmpty())
  finishPreviousNote();
}


decompiled_code:
void __fastcall arp_setMode(__int64 a1, __int64 a2)
{
int v2; // ebx

v2 = a1;
if ( *(_DWORD *)((char *)&qword_623 + 5) != (_DWORD)a1 )
{
killAllNotes();
if ( (_DWORD)a1 )
{
word_620 = -1;
if ( !settings[296] )
{
a1 = 0LL;
if ( (unsigned int)seq_getMode(0LL) != 2 )
{
a1 = 1LL;
if ( (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
}
}
}
}
if ( !(_BYTE)a2 && BYTE2(qword_623) )
killHeldNotes(a1, a2);
*(_DWORD *)((char *)&qword_623 + 5) = v2;
BYTE2(qword_623) = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebx

v2 = a1;
if ( *(_DWORD *)((char *)&qword_623 + 5) != (_DWORD)a1 )
{
func2();
if ( (_DWORD)a1 )
{
word_620 = -1;
if ( !settings[296] )
{
a1 = 0LL;
if ( (unsigned int)seq_getMode(0LL) != 2 )
{
a1 = 1LL;
if ( (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
}
}
}
}
if ( !(_BYTE)a2 && BYTE2(qword_623) )
func3(a1, a2);
*(_DWORD *)((char *)&qword_623 + 5) = v2;
BYTE2(qword_623) = a2;
}

original_code:
inline void arp_setMode(arpMode_t mode, int8_t hold)
{
 if(mode!=arp.mode)
 {
  killAllNotes();
  if (mode!=amOff)
   arp_resetCounter(settings.syncMode==smInternal);
 }
 if(!hold && arp.hold)
  killHeldNotes();
 arp.mode=mode;
 arp.hold=hold;
}

canonical_original_code:
inline void arp_setMode(enum arpMode_t mode, char hold)
{
 if(mode!=arp.mode)
 {
  killAllNotes();
  if (mode!=amOff)
   arp_resetCounter(settings.syncMode==smInternal);
 }
 if(!hold && arp.hold)
  killHeldNotes();
 arp.mode=mode;
 arp.hold=hold;
}

variable_types: enum arpMode_t { amOff=0, amUpDown=1, amRandom=2, amAssign=3 }

variable_types: hold char


decompiled_code:
void __fastcall arp_setTranspose(char a1)
{
LOBYTE(qword_623) = a1;
}

canonical_decompiled_code:
void __fastcall func5(char a1)
{
LOBYTE(qword_623) = a1;
}

original_code:
inline __attribute__((always_inline)) void arp_setTranspose(int8_t transpose)
{
 arp.transpose=transpose;
}

canonical_original_code:
inline void arp_setTranspose(char transpose)
{
 arp.transpose=transpose;
}

variable_types: transpose char


decompiled_code:
void __fastcall arp_resetCounter(char a1)
{
word_620 = -1;
if ( a1 && (unsigned int)seq_getMode(0LL) != 2 && (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
}

canonical_decompiled_code:
void __fastcall func6(char a1)
{
word_620 = -1;
if ( a1 && (unsigned int)seq_getMode(0LL) != 2 && (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
}

original_code:
inline __attribute__((always_inline)) void arp_resetCounter(int8_t beatReset)
{
 arp.noteIndex=-1;
 if (beatReset&&seq_getMode(0)!=smPlaying&&seq_getMode(1)!=smPlaying)
  clock_reset();
}

canonical_original_code:
inline void arp_resetCounter(char beatReset)
{
 arp.noteIndex=-1;
 if (beatReset&&seq_getMode(0)!=smPlaying&&seq_getMode(1)!=smPlaying)
  clock_reset();
}

variable_types: beatReset char


decompiled_code:
__int64 arp_getMode()
{
return *(unsigned int *)((char *)&qword_623 + 5);
}

canonical_decompiled_code:
__int64 func7()
{
return *(unsigned int *)((char *)&qword_623 + 5);
}

original_code:
inline __attribute__((always_inline)) arpMode_t arp_getMode(void)
{
 return arp.mode;
}

canonical_original_code:
inline enum arpMode_t arp_getMode()
{
 return arp.mode;
}

return_type: enum arpMode_t { amOff=0, amUpDown=1, amRandom=2, amAssign=3 }


decompiled_code:
__int64 arp_getHold()
{
return BYTE2(qword_623);
}

canonical_decompiled_code:
__int64 func8()
{
return BYTE2(qword_623);
}

original_code:
inline __attribute__((always_inline)) int8_t arp_getHold(void)
{
 return arp.hold;
}

canonical_original_code:
inline char arp_getHold()
{
 return arp.hold;
}


decompiled_code:
__int64 __fastcall arp_assignNote(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int8 v4; // bl
__int64 v5; // rax

result = *(unsigned int *)((char *)&qword_623 + 5);
if ( *(_DWORD *)((char *)&qword_623 + 5) )
{
v4 = a1 - 24;
if ( (_BYTE)a2 )
{
if ( (unsigned __int8)isEmpty(a1, a2, a3) )
{
word_620 = -1;
if ( !settings[296] && (unsigned int)seq_getMode(0LL) != 2 && (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
}
if ( *(_DWORD *)((char *)&qword_623 + 5) == 1 )
{
*((_BYTE *)&arp + v4) = v4;
result = 127 - v4;
*((_BYTE *)&arp + result) = v4;
}
else
{
result = 0LL;
while ( *((_BYTE *)&arp + result) != 0xFF )
{
if ( ++result == 128 )
return result;
}
*((_BYTE *)&arp + (int)result) = v4;
}
}
else if ( BYTE2(qword_623) )
{
if ( *(_DWORD *)((char *)&qword_623 + 5) == 1 )
{
*((_BYTE *)&arp + v4) |= 0x80u;
result = 127 - v4;
*((_BYTE *)&arp + result) |= 0x80u;
}
else
{
result = 0LL;
while ( *((_BYTE *)&arp + result) != v4 )
{
if ( ++result == 128 )
return result;
}
*((_BYTE *)&arp + (int)result) = v4 | 0x80;
}
}
else
{
if ( *(_DWORD *)((char *)&qword_623 + 5) == 1 )
{
a3 = v4;
*((_BYTE *)&arp + v4) = -1;
*((_BYTE *)&arp + 127 - v4) = -1;
}
else
{
v5 = 0LL;
while ( *((_BYTE *)&arp + v5) != v4 )
{
if ( ++v5 == 128 )
goto LABEL_30;
}
a3 = (int)v5;
*((_BYTE *)&arp + (int)v5) = -1;
}
LABEL_30:
result = isEmpty(a1, a2, a3);
if ( (_BYTE)result )
result = finishPreviousNote();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int8 v4; // bl
__int64 v5; // rax

result = *(unsigned int *)((char *)&qword_623 + 5);
if ( *(_DWORD *)((char *)&qword_623 + 5) )
{
v4 = a1 - 24;
if ( (_BYTE)a2 )
{
if ( (unsigned __int8)func0(a1, a2, a3) )
{
word_620 = -1;
if ( !settings[296] && (unsigned int)seq_getMode(0LL) != 2 && (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
}
if ( *(_DWORD *)((char *)&qword_623 + 5) == 1 )
{
*((_BYTE *)&arp + v4) = v4;
result = 127 - v4;
*((_BYTE *)&arp + result) = v4;
}
else
{
result = 0LL;
while ( *((_BYTE *)&arp + result) != 0xFF )
{
if ( ++result == 128 )
return result;
}
*((_BYTE *)&arp + (int)result) = v4;
}
}
else if ( BYTE2(qword_623) )
{
if ( *(_DWORD *)((char *)&qword_623 + 5) == 1 )
{
*((_BYTE *)&arp + v4) |= 0x80u;
result = 127 - v4;
*((_BYTE *)&arp + result) |= 0x80u;
}
else
{
result = 0LL;
while ( *((_BYTE *)&arp + result) != v4 )
{
if ( ++result == 128 )
return result;
}
*((_BYTE *)&arp + (int)result) = v4 | 0x80;
}
}
else
{
if ( *(_DWORD *)((char *)&qword_623 + 5) == 1 )
{
a3 = v4;
*((_BYTE *)&arp + v4) = -1;
*((_BYTE *)&arp + 127 - v4) = -1;
}
else
{
v5 = 0LL;
while ( *((_BYTE *)&arp + v5) != v4 )
{
if ( ++v5 == 128 )
goto LABEL_30;
}
a3 = (int)v5;
*((_BYTE *)&arp + (int)v5) = -1;
}
LABEL_30:
result = func0(a1, a2, a3);
if ( (_BYTE)result )
result = func1();
}
}
return result;
}

original_code:
void arp_assignNote(uint8_t note, int8_t on)
{
 int16_t i;
 if(arp.mode==amOff)
  return;
 note-=24;
 if(on)
 {
  if(isEmpty())
   arp_resetCounter(settings.syncMode==smInternal);
  if(arp.mode!=amUpDown)
  {
   for(i=0;i<128;++i)
    if(arp.notes[i]==(255))
    {
     arp.notes[i]=note;
     break;
    }
  }
  else
  {
   arp.notes[note]=note;
   arp.notes[(128 -1)-note]=note;
  }
 }
 else
 {
  if(arp.hold)
  {
   if(arp.mode!=amUpDown)
   {
    for(i=0;i<128;++i)
     if(arp.notes[i]==note)
     {
      arp.notes[i]|=0x80;
      break;
     }
   }
   else
   {
    arp.notes[note]|=0x80;
    arp.notes[(128 -1)-note]|=0x80;
   }
  }
  else
  {
   if(arp.mode!=amUpDown)
   {
    for(i=0;i<128;++i)
     if(arp.notes[i]==note)
     {
      arp.notes[i]=(255);
      break;
     }
   }
   else
   {
    arp.notes[note]=(255);
    arp.notes[(128 -1)-note]=(255);
   }
   if(isEmpty())
    finishPreviousNote();
  }
 }
}

canonical_original_code:
void arp_assignNote(unsigned char note, char on)
{
 short i;
 if(arp.mode==amOff)
  return;
 note-=24;
 if(on)
 {
  if(isEmpty())
   arp_resetCounter(settings.syncMode==smInternal);
  if(arp.mode!=amUpDown)
  {
   for(i=0;i<128;++i)
    if(arp.notes[i]==(255))
    {
     arp.notes[i]=note;
     break;
    }
  }
  else
  {
   arp.notes[note]=note;
   arp.notes[(128 -1)-note]=note;
  }
 }
 else
 {
  if(arp.hold)
  {
   if(arp.mode!=amUpDown)
   {
    for(i=0;i<128;++i)
     if(arp.notes[i]==note)
     {
      arp.notes[i]|=0x80;
      break;
     }
   }
   else
   {
    arp.notes[note]|=0x80;
    arp.notes[(128 -1)-note]|=0x80;
   }
  }
  else
  {
   if(arp.mode!=amUpDown)
   {
    for(i=0;i<128;++i)
     if(arp.notes[i]==note)
     {
      arp.notes[i]=(255);
      break;
     }
   }
   else
   {
    arp.notes[note]=(255);
    arp.notes[(128 -1)-note]=(255);
   }
   if(isEmpty())
    finishPreviousNote();
  }
 }
}

variable_types:
note
unsigned char


decompiled_code:
void __fastcall arp_update(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // edx
char v4; // bl

if ( *(_DWORD *)((char *)&qword_623 + 5) && !(unsigned __int8)isEmpty(a1, a2, a3) )
{
finishPreviousNote();
if ( *(_DWORD *)((char *)&qword_623 + 5) == 2 )
{
do
word_620 = (int)random() % 128;
while ( *((_BYTE *)&arp + word_620) == 0xFF );
}
else
{
if ( (*(_DWORD *)((_BYTE *)&qword_623 + 5) & 0xFFFFFFFD) != 1 )
return;
LOWORD(v3) = word_620;
do
v3 = ((__int16)v3 + 1) % 128;
while ( *((_BYTE *)&arp + (__int16)v3) == 0xFF );
word_620 = v3;
}
v4 = *((_BYTE *)&arp + word_620) & 0x7F;
assigner_assignNote((unsigned __int8)(v4 + qword_623 + 24), 1LL, 0x8000LL, 0LL);
midi_sendNoteEvent((unsigned __int8)(v4 + qword_623 + 24), 1LL, 0x8000LL);
byte_622 = *((_BYTE *)&arp + word_620);
BYTE1(qword_623) = qword_623;
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // edx
char v4; // bl

if ( *(_DWORD *)((char *)&qword_623 + 5) && !(unsigned __int8)func0(a1, a2, a3) )
{
func1();
if ( *(_DWORD *)((char *)&qword_623 + 5) == 2 )
{
do
word_620 = (int)random() % 128;
while ( *((_BYTE *)&arp + word_620) == 0xFF );
}
else
{
if ( (*(_DWORD *)((_BYTE *)&qword_623 + 5) & 0xFFFFFFFD) != 1 )
return;
LOWORD(v3) = word_620;
do
v3 = ((__int16)v3 + 1) % 128;
while ( *((_BYTE *)&arp + (__int16)v3) == 0xFF );
word_620 = v3;
}
v4 = *((_BYTE *)&arp + word_620) & 0x7F;
assigner_assignNote((unsigned __int8)(v4 + qword_623 + 24), 1LL, 0x8000LL, 0LL);
midi_sendNoteEvent((unsigned __int8)(v4 + qword_623 + 24), 1LL, 0x8000LL);
byte_622 = *((_BYTE *)&arp + word_620);
BYTE1(qword_623) = qword_623;
}
}

original_code:
void arp_update(void)
{
 uint8_t n;
 if(arp.mode==amOff)
  return;
 if(isEmpty())
  return;
 finishPreviousNote();
 switch(arp.mode)
 {
 case amUpDown:
 case amAssign:
  do
   arp.noteIndex=(arp.noteIndex+1)%128;
  while(arp.notes[arp.noteIndex]==(255));
  break;
 case amRandom:
  do
   arp.noteIndex=random()%128;
  while(arp.notes[arp.noteIndex]==(255));
  break;
 default:
  return;
 }
 n=arp.notes[arp.noteIndex]&~0x80;
 assigner_assignNote(n+24 +arp.transpose,1,((65535)/2+1),0);
 midi_sendNoteEvent(n+24 +arp.transpose,1,((65535)/2+1));
 arp.previousNote=arp.notes[arp.noteIndex];
 arp.previousTranspose=arp.transpose;
}

canonical_original_code:
void arp_update()
{
 unsigned char n;
 if(arp.mode==amOff)
  return;
 if(isEmpty())
  return;
 finishPreviousNote();
 switch(arp.mode)
 {
 case amUpDown:
 case amAssign:
  do
   arp.noteIndex=(arp.noteIndex+1)%128;
  while(arp.notes[arp.noteIndex]==(255));
  break;
 case amRandom:
  do
   arp.noteIndex=random()%128;
  while(arp.notes[arp.noteIndex]==(255));
  break;
 default:
  return;
 }
 n=arp.notes[arp.noteIndex]&~0x80;
 assigner_assignNote(n+24 +arp.transpose,1,((65535)/2+1),0);
 midi_sendNoteEvent(n+24 +arp.transpose,1,((65535)/2+1));
 arp.previousNote=arp.notes[arp.noteIndex];
 arp.previousTranspose=arp.transpose;
}


decompiled_code:
void arp_init()
{
qword_623 = 0LL;
byte_62B = 0;
arp = -1LL;
qword_5A8 = -1LL;
qword_5B0 = -1LL;
qword_5B8 = -1LL;
qword_5C0 = -1LL;
qword_5C8 = -1LL;
qword_5D0 = -1LL;
qword_5D8 = -1LL;
qword_5E0 = -1LL;
qword_5E8 = -1LL;
qword_5F0 = -1LL;
qword_5F8 = -1LL;
qword_600 = -1LL;
qword_608 = -1LL;
qword_610 = -1LL;
qword_618 = -1LL;
word_620 = -1;
byte_622 = -1;
}

canonical_decompiled_code:
void func11()
{
qword_623 = 0LL;
byte_62B = 0;
arp = -1LL;
qword_5A8 = -1LL;
qword_5B0 = -1LL;
qword_5B8 = -1LL;
qword_5C0 = -1LL;
qword_5C8 = -1LL;
qword_5D0 = -1LL;
qword_5D8 = -1LL;
qword_5E0 = -1LL;
qword_5E8 = -1LL;
qword_5F0 = -1LL;
qword_5F8 = -1LL;
qword_600 = -1LL;
qword_608 = -1LL;
qword_610 = -1LL;
qword_618 = -1LL;
word_620 = -1;
byte_622 = -1;
}

original_code:
void arp_init(void)
{
 memset(&arp,0,sizeof(arp));
 memset(arp.notes,(255),128);
 arp.noteIndex=-1;
 arp.previousNote=(255);
}

canonical_original_code:
void arp_init()
{
 memset(&arp,0,sizeof(arp));
 memset(arp.notes,(255),128);
 arp.noteIndex=-1;
 arp.previousNote=(255);
}


decompiled_code:
void __fastcall sevenSeg_scrollText(char *src, char a2)
{
BYTE2(qword_488) = a2;
if ( src )
{
BYTE1(qword_488) = 0;
strcpy(dest, src);
*(_WORD *)((char *)&qword_488 + strlen((const char *)&qword_488 + 7) + 7) = 32;
}
else
{
BYTE1(qword_488) = -1;
}
}

canonical_decompiled_code:
void __fastcall func1(char *src, char a2)
{
BYTE2(qword_488) = a2;
if ( src )
{
BYTE1(qword_488) = 0;
strcpy(dest, src);
*(_WORD *)((char *)&qword_488 + strlen((const char *)&qword_488 + 7) + 7) = 32;
}
else
{
BYTE1(qword_488) = -1;
}
}

original_code:
void sevenSeg_scrollText(const char * text, int8_t times)
{
 display.scrollTimes=times;
 display.scrollPos=-1;
 if (text)
 {
  display.scrollTimes=times;
  display.scrollPos=0;
  strcpy(&display.scrollText[1],text);
  strcat(display.scrollText," ");
 }
}

canonical_original_code:
void sevenSeg_scrollText(char *text, char times)
{
 display.scrollTimes=times;
 display.scrollPos=-1;
 if (text)
 {
  display.scrollTimes=times;
  display.scrollPos=0;
  strcpy(&display.scrollText[1],text);
  strcat(display.scrollText," ");
 }
}

variable_types:
text
char *

variable_types: times char


decompiled_code:
__int64 __fastcall sevenSeg_setAscii(char a1, char a2)
{
__int64 result; // rax

BYTE4(display) = map_to_seg7((__int64)&sevenSeg_map, a1);
result = map_to_seg7((__int64)&sevenSeg_map, a2);
BYTE5(display) = result;
return result;
}

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

BYTE4(display) = func0((__int64)&sevenSeg_map, a1);
result = func0((__int64)&sevenSeg_map, a2);
BYTE5(display) = result;
return result;
}

original_code:
void sevenSeg_setAscii(char left, char right)
{
 display.sevenSegs[0]=map_to_seg7(&sevenSeg_map,left);
 display.sevenSegs[1]=map_to_seg7(&sevenSeg_map,right);
}

variable_types: left char

variable_types: right char


decompiled_code:
__int64 __fastcall sevenSeg_setNumber(int a1)
{
return sevenSeg_setAscii((unsigned __int8)(a1 % 100 / 10) + 48, (unsigned __int8)(a1 % 100 % 10) + 48);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return func2((unsigned __int8)(a1 % 100 / 10) + 48, (unsigned __int8)(a1 % 100 % 10) + 48);
}

original_code:
void sevenSeg_setNumber(int32_t n)
{
 n%=100;
 sevenSeg_setAscii('0'+(n/10),'0'+(n%10));
}

canonical_original_code:
void sevenSeg_setNumber(int n)
{
 n%=100;
 sevenSeg_setAscii('0'+(n/10),'0'+(n%10));
}

variable_types: n int


decompiled_code:
_BOOL8 __fastcall led_getOn(char a1)
{
return ((unsigned __int16)(1 << a1) & (unsigned __int16)display) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char a1)
{
return ((unsigned __int16)(1 << a1) & (unsigned __int16)display) != 0;
}

original_code:
int led_getOn(p600LED_t led)
{
 uint16_t mask=1<<led;
 return !!(display.ledOn&mask);
}

canonical_original_code:
int led_getOn(enum p600LED_t led)
{
 unsigned short mask = 1<<led;
 return !!(display.ledOn&mask);
}

variable_types: enum p600LED_t { plSeq1=0, plSeq2=1, plArpUD=2, plArpAssign=3, plPreset=4, plRecord=5, plToTape=6, plFromTape=7, plTune=8, plDot=9 }

variable_types:
mask
unsigned short

return_type: int


decompiled_code:
_BOOL8 __fastcall led_getBlinking(char a1)
{
return ((unsigned __int16)(1 << a1) & WORD1(display)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(char a1)
{
return ((unsigned __int16)(1 << a1) & WORD1(display)) != 0;
}

original_code:
int led_getBlinking(p600LED_t led)
{
 uint16_t mask=1<<led;
 return !!(display.ledBlinking&mask);
}

canonical_original_code:
int led_getBlinking(enum p600LED_t led)
{
 unsigned short mask = 1<<led;
 return !!(display.ledBlinking&mask);
}

user_defined_types: enum p600LED_t { plSeq1=0, plSeq2=1, plArpUD=2, plArpAssign=3, plPreset=4, plRecord=5, plToTape=6, plFromTape=7, plTune=8, plDot=9 }


decompiled_code:
__int16 __fastcall led_set(char a1, char a2, char a3)
{
int v5; // edx
__int16 v6; // cx
__int16 result; // ax

v5 = 1 << a1;
v6 = display & ~(unsigned __int16)(1 << a1);
LOWORD(display) = v6;
result = WORD1(display) & ~(unsigned __int16)(1 << a1);
WORD1(display) = result;
if ( a2 )
{
LOWORD(display) = v5 | v6;
if ( a3 )
{
result |= v5;
WORD1(display) = result;
}
}
return result;
}

canonical_decompiled_code:
__int16 __fastcall func6(char a1, char a2, char a3)
{
int v5; // edx
__int16 v6; // cx
__int16 result; // ax

v5 = 1 << a1;
v6 = display & ~(unsigned __int16)(1 << a1);
LOWORD(display) = v6;
result = WORD1(display) & ~(unsigned __int16)(1 << a1);
WORD1(display) = result;
if ( a2 )
{
LOWORD(display) = v5 | v6;
if ( a3 )
{
result |= v5;
WORD1(display) = result;
}
}
return result;
}

original_code:
void led_set(p600LED_t led, int8_t on, int8_t blinking)
{
 uint16_t mask=1<<led;
 display.ledOn&=~mask;
 display.ledBlinking&=~mask;
 if (on) display.ledOn|=mask;
 if (on && blinking) display.ledBlinking|=mask;
}

canonical_original_code:
void led_set(enum p600LED_t led, char on, char blinking)
{
 unsigned short mask = 1<<led;
 display.ledOn&=~mask;
 display.ledBlinking&=~mask;
 if (on) display.ledOn|=mask;
 if (on && blinking) display.ledBlinking|=mask;
}

variable_types: blinking char


decompiled_code:
void display_clear()
{
WORD2(display) = 0;
LODWORD(display) = 0;
BYTE2(qword_488) = 0;
}

canonical_decompiled_code:
void func7()
{
WORD2(display) = 0;
LODWORD(display) = 0;
BYTE2(qword_488) = 0;
}

original_code:
void display_clear()
{
 display.sevenSegs[0]=0;
 display.sevenSegs[1]=0;
 display.ledOn=0;
 display.ledBlinking=0;
 display.scrollTimes=0;
}


decompiled_code:
void display_init()
{
display = 0LL;
qword_488 = 0x2000000000000000LL;
*(_QWORD *)dest = 0LL;
qword_498 = 0LL;
qword_4A0 = 0LL;
qword_4A8 = 0LL;
qword_4B0 = 0LL;
qword_4B8 = 0LL;
word_4C0 = 0;
}

canonical_decompiled_code:
void func8()
{
display = 0LL;
qword_488 = 0x2000000000000000LL;
*(_QWORD *)dest = 0LL;
qword_498 = 0LL;
qword_4A0 = 0LL;
qword_4A8 = 0LL;
qword_4B0 = 0LL;
qword_4B8 = 0LL;
word_4C0 = 0;
}

original_code:
void display_init()
{
 memset(&display,0,sizeof(display));
 display.scrollText[0]=' ';
}


decompiled_code:
__int64 __fastcall display_update(char a1)
{
char v1; // r12
unsigned __int8 v2; // bp
int v3; // er13
char v4; // r14
char v5; // bl
int v6; // ebp
char v7; // bl
__int64 result; // rax

if ( a1 )
{
if ( ++BYTE6(display) > 0x14u )
{
HIBYTE(display) = HIBYTE(display) == 0;
BYTE6(display) = 0;
}
v1 = BYTE2(qword_488);
if ( BYTE2(qword_488) )
{
LOBYTE(qword_488) = qword_488 + 1;
v2 = qword_488;
v3 = (SBYTE1(qword_488) + 1) % (char)strlen((const char *)&qword_488 + 7);
v4 = map_to_seg7((__int64)&sevenSeg_map, *((char *)&qword_488 + SBYTE1(qword_488) + 7));
v5 = map_to_seg7((__int64)&sevenSeg_map, *((char *)&qword_488 + (char)v3 + 7));
if ( v2 > 0xFu )
{
BYTE1(qword_488) = v3;
LOBYTE(qword_488) = 0;
if ( v1 > 0 && !(_BYTE)v3 )
BYTE2(qword_488) = v1 - 1;
}
}
else
{
v4 = BYTE4(display);
v5 = BYTE5(display);
}
v6 = BYTE3(qword_488);
if ( BYTE3(qword_488) == 1 )
{
v7 = v4 & 0x7F;
if ( led_getOn(9) )
v7 |= 0x80u;
if ( led_getBlinking(9) && HIBYTE(display) )
v7 += 0x80;
}
else if ( BYTE3(qword_488) == 2 )
{
v7 = v5 & 0x7F;
if ( led_getOn(8) )
v7 |= 0x80u;
if ( led_getBlinking(8) && HIBYTE(display) )
v7 += 0x80;
}
else
{
v7 = 0;
if ( !BYTE3(qword_488) )
{
v7 = display;
if ( HIBYTE(display) )
v7 = BYTE2(display) ^ display;
}
}
*((_BYTE *)&qword_488 + v6 + 4) = v7;
}
io_write(9LL, 0LL);
io_write(8LL, (unsigned __int8)(16 << SBYTE3(qword_488)));
io_write(9LL, *((unsigned __int8 *)&qword_488 + BYTE3(qword_488) + 4));
result = (unsigned int)(BYTE3(qword_488) + 1 - 3 * ((unsigned __int64)(1431655766LL * (BYTE3(qword_488) + 1)) >> 32));
BYTE3(qword_488) = BYTE3(qword_488) + 1 - 3 * ((unsigned __int64)(1431655766LL * (BYTE3(qword_488) + 1)) >> 32);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
char v1; // r12
unsigned __int8 v2; // bp
int v3; // er13
char v4; // r14
char v5; // bl
int v6; // ebp
char v7; // bl
__int64 result; // rax

if ( a1 )
{
if ( ++BYTE6(display) > 0x14u )
{
HIBYTE(display) = HIBYTE(display) == 0;
BYTE6(display) = 0;
}
v1 = BYTE2(qword_488);
if ( BYTE2(qword_488) )
{
LOBYTE(qword_488) = qword_488 + 1;
v2 = qword_488;
v3 = (SBYTE1(qword_488) + 1) % (char)strlen((const char *)&qword_488 + 7);
v4 = func0((__int64)&sevenSeg_map, *((char *)&qword_488 + SBYTE1(qword_488) + 7));
v5 = func0((__int64)&sevenSeg_map, *((char *)&qword_488 + (char)v3 + 7));
if ( v2 > 0xFu )
{
BYTE1(qword_488) = v3;
LOBYTE(qword_488) = 0;
if ( v1 > 0 && !(_BYTE)v3 )
BYTE2(qword_488) = v1 - 1;
}
}
else
{
v4 = BYTE4(display);
v5 = BYTE5(display);
}
v6 = BYTE3(qword_488);
if ( BYTE3(qword_488) == 1 )
{
v7 = v4 & 0x7F;
if ( func4(9) )
v7 |= 0x80u;
if ( func5(9) && HIBYTE(display) )
v7 += 0x80;
}
else if ( BYTE3(qword_488) == 2 )
{
v7 = v5 & 0x7F;
if ( func4(8) )
v7 |= 0x80u;
if ( func5(8) && HIBYTE(display) )
v7 += 0x80;
}
else
{
v7 = 0;
if ( !BYTE3(qword_488) )
{
v7 = display;
if ( HIBYTE(display) )
v7 = BYTE2(display) ^ display;
}
}
*((_BYTE *)&qword_488 + v6 + 4) = v7;
}
io_write(9LL, 0LL);
io_write(8LL, (unsigned __int8)(16 << SBYTE3(qword_488)));
io_write(9LL, *((unsigned __int8 *)&qword_488 + BYTE3(qword_488) + 4));
result = (unsigned int)(BYTE3(qword_488) + 1 - 3 * ((unsigned __int64)(1431655766LL * (BYTE3(qword_488) + 1)) >> 32));
BYTE3(qword_488) = BYTE3(qword_488) + 1 - 3 * ((unsigned __int64)(1431655766LL * (BYTE3(qword_488) + 1)) >> 32);
return result;
}

original_code:
void display_update(int8_t fullUpdate)
{
 if(fullUpdate)
 {
  uint8_t localSevenSegs[2];
  display.blinkCounter++;
  if (display.blinkCounter>20)
  {
   display.blinkState=!display.blinkState;
   display.blinkCounter=0;
  }
  if(display.scrollTimes)
  {
   int8_t l,p,p2;
   display.scrollCounter++;
   l=strlen(display.scrollText);
   p=display.scrollPos;
   p2=(display.scrollPos+1)%l;
   localSevenSegs[0]=map_to_seg7(&sevenSeg_map,display.scrollText[p]);
   localSevenSegs[1]=map_to_seg7(&sevenSeg_map,display.scrollText[p2]);
   if (display.scrollCounter>15)
   {
    display.scrollPos=p2;
    display.scrollCounter=0;
    if(p2==0 && display.scrollTimes>0)
     --display.scrollTimes;
   }
  }
  else
  {
   localSevenSegs[0]=display.sevenSegs[0];
   localSevenSegs[1]=display.sevenSegs[1];
  }
  uint8_t b=0;
  switch (display.activeCol)
  {
  case 0:
   b=display.ledOn;
   if (display.blinkState) b^=display.ledBlinking;
   break;
  case 1:
   b=localSevenSegs[0]&0x7f;
   if (led_getOn(plDot)) b|=0x80;
   if (led_getBlinking(plDot) && display.blinkState) b^=0x80;
   break;
  case 2:
   b=localSevenSegs[1]&0x7f;
   if (led_getOn(plTune)) b|=0x80;
   if (led_getBlinking(plTune) && display.blinkState) b^=0x80;
   break;
  }
  display.activeRows[display.activeCol]=b;
 }

 {
  io_write(0x09,0x00);
  ;
  io_write(0x08,0x10<<display.activeCol);
  ;
  io_write(0x09,display.activeRows[display.activeCol]);
 }
 display.activeCol=(display.activeCol+1)%3;
}

canonical_original_code:
void display_update(char fullUpdate)
{
 if(fullUpdate)
 {
  unsigned char localSevenSegs[2];
  display.blinkCounter++;
  if (display.blinkCounter>20)
  {
   display.blinkState=!display.blinkState;
   display.blinkCounter=0;
  }
  if(display.scrollTimes)
  {
   char l; char p; char p2;
   display.scrollCounter++;
   l=strlen(display.scrollText);
   p=display.scrollPos;
   p2=(display.scrollPos+1)%l;
   localSevenSegs[0]=map_to_seg7(&sevenSeg_map,display.scrollText[p]);
   localSevenSegs[1]=map_to_seg7(&sevenSeg_map,display.scrollText[p2]);
   if (display.scrollCounter>15)
   {
    display.scrollPos=p2;
    display.scrollCounter=0;
    if(p2==0 && display.scrollTimes>0)
     --display.scrollTimes;
   }
  }
  else
  {
   localSevenSegs[0]=display.sevenSegs[0];
   localSevenSegs[1]=display.sevenSegs[1];
  }
  unsigned char b = 0;
  switch (display.activeCol)
  {
  case 0:
   b=display.ledOn;
   if (display.blinkState) b^=display.ledBlinking;
   break;
  case 1:
   b=localSevenSegs[0]&0x7f;
   if (led_getOn(plDot)) b|=0x80;
   if (led_getBlinking(plDot) && display.blinkState) b^=0x80;
   break;
  case 2:
   b=localSevenSegs[1]&0x7f;
   if (led_getOn(plTune)) b|=0x80;
   if (led_getBlinking(plTune) && display.blinkState) b^=0x80;
   break;
  }
  display.activeRows[display.activeCol]=b;
 }

 {
  io_write(0x09,0x00);
  ;
  io_write(0x08,0x10<<display.activeCol);
  ;
  io_write(0x09,display.activeRows[display.activeCol]);
 }
 display.activeCol=(display.activeCol+1)%3;
}

variable_types: fullUpdate char

variable_types:
localSevenSegs
unsigned char [2]

variable_types: l char

variable_types: p char

variable_types:
b
unsigned char


getPhaseInc

decompiled_code:
__int64 __fastcall getPhaseInc(unsigned __int8 a1)
{
return (unsigned __int8)phaseLookupLo[a1] | ((unsigned __int8)phaseLookupHi[a1] << 16) | ((unsigned __int8)phaseLookupMid[a1] << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return (unsigned __int8)phaseLookupLo[a1] | ((unsigned __int8)phaseLookupHi[a1] << 16) | ((unsigned __int8)phaseLookupMid[a1] << 8);
}

original_code:
static uint32_t getPhaseInc(uint8_t v)
{
 uint32_t r=0;
 r|=(uint32_t)(*(uint8_t*)(&phaseLookupLo[v]));
 r|=(uint32_t)(*(uint8_t*)(&phaseLookupMid[v]))<<8;
 r|=(uint32_t)(*(uint8_t*)(&phaseLookupHi[v]))<<16;
 return r;
}

canonical_original_code:
static unsigned int getPhaseInc(unsigned char v)
{
 unsigned int r = 0;
 r|=(unsigned int)(*(unsigned char *)(&phaseLookupLo[v]));
 r|=(unsigned int)(*(unsigned char *)(&phaseLookupMid[v]))<<8;
 r|=(unsigned int)(*(unsigned char *)(&phaseLookupHi[v]))<<16;
 return r;
}

variable_types:
v
unsigned char

variable_types:
r
unsigned int

return_type: unsigned int


updateStageVars

original_code:
static inline void updateStageVars(struct adsr_s * a, adsrStage_t s)
{
 switch(s)
 {
 case sAttack:
  a->stageAdd=scaleU16U16(a->stageLevel,a->levelCV);
  a->stageMul=scaleU16U16((65535)-a->stageLevel,a->levelCV);
  a->stageIncrement=a->attackIncrement;
  break;
 case sDecay:
  a->stageAdd=scaleU16U16(a->sustainCV,a->levelCV);
  a->stageMul=scaleU16U16((65535)-a->sustainCV,a->levelCV);
  a->stageIncrement=a->decayIncrement;
  break;
 case sSustain:
  a->stageAdd=0;
  a->stageMul=a->levelCV;
  a->stageIncrement=0;
  break;
 case sRelease:
  a->stageAdd=0;
  a->stageMul=scaleU16U16(a->stageLevel,a->levelCV);
  a->stageIncrement=a->releaseIncrement;
  break;
 default:
  a->stageAdd=0;
  a->stageMul=0;
  a->stageIncrement=0;
 }
}

canonical_original_code:
static inline void updateStageVars(struct adsr_s *a, enum adsrStage_t s)
{
 switch(s)
 {
 case sAttack:
  a->stageAdd=scaleU16U16(a->stageLevel,a->levelCV);
  a->stageMul=scaleU16U16((65535)-a->stageLevel,a->levelCV);
  a->stageIncrement=a->attackIncrement;
  break;
 case sDecay:
  a->stageAdd=scaleU16U16(a->sustainCV,a->levelCV);
  a->stageMul=scaleU16U16((65535)-a->sustainCV,a->levelCV);
  a->stageIncrement=a->decayIncrement;
  break;
 case sSustain:
  a->stageAdd=0;
  a->stageMul=a->levelCV;
  a->stageIncrement=0;
  break;
 case sRelease:
  a->stageAdd=0;
  a->stageMul=scaleU16U16(a->stageLevel,a->levelCV);
  a->stageIncrement=a->releaseIncrement;
  break;
 default:
  a->stageAdd=0;
  a->stageMul=0;
  a->stageIncrement=0;
 }
}

variable_types: struct adsr_s { unsigned int stageIncrement; unsigned int phase; unsigned int attackIncrement; unsigned short sustainCV; unsigned short attackCV; unsigned short stageLevel; unsigned short output; char expOutput; unsigned char speedShift; enum adsrStage_t { sWait=0, sAttack=1, sDecay=2, sSustain=3, sRelease=4, sDone=5 } stage; } *

user_defined_types: struct adsr_s { unsigned int stageIncrement; unsigned int phase; unsigned int attackIncrement; unsigned short sustainCV; unsigned short attackCV; unsigned short stageLevel; unsigned short output; char expOutput; unsigned char speedShift; enum adsrStage_t stage; }


updateIncrements

decompiled_code:
void __fastcall updateIncrements(__int64 a1)
{
unsigned int v1; // eax
char v2; // bp

v1 = getPhaseInc(*(_BYTE *)(a1 + 25));
v2 = *(_BYTE *)(a1 + 40);
*(_DWORD *)(a1 + 8) = 16 * (v1 >> v2);
*(_DWORD *)(a1 + 12) = 16 * ((unsigned int)getPhaseInc(*(_BYTE *)(a1 + 27)) >> v2);
*(_DWORD *)(a1 + 16) = 16 * ((unsigned int)getPhaseInc(*(_BYTE *)(a1 + 29)) >> v2);
updateStageVars(a1, *(_DWORD *)(a1 + 44));
}

original_code:
static void updateIncrements(struct adsr_s * adsr)
{
 adsr->attackIncrement=(getPhaseInc(adsr->attackCV>>8)>>adsr->speedShift)<<4;
 adsr->decayIncrement=(getPhaseInc(adsr->decayCV>>8)>>adsr->speedShift)<<4;
 adsr->releaseIncrement=(getPhaseInc(adsr->releaseCV>>8)>>adsr->speedShift)<<4;
 updateStageVars(adsr,adsr->stage);
}

canonical_original_code:
static void updateIncrements(struct adsr_s *adsr)
{
 adsr->attackIncrement=(getPhaseInc(adsr->attackCV>>8)>>adsr->speedShift)<<4;
 adsr->decayIncrement=(getPhaseInc(adsr->decayCV>>8)>>adsr->speedShift)<<4;
 adsr->releaseIncrement=(getPhaseInc(adsr->releaseCV>>8)>>adsr->speedShift)<<4;
 updateStageVars(adsr,adsr->stage);
}

user_defined_types: enum adsrStage_t { sWait=0, sAttack=1, sDecay=2, sSustain=3, sRelease=4, sDone=5 }


computeOutput

decompiled_code:
__int64 __fastcall computeOutput(__int64 a1, __int64 a2, char a3)
{
__int64 result; // rax

result = (unsigned int)a1 >> 8;
if ( a3 )
result = computeShape(a1, a2, 1LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, char a3)
{
__int64 result; // rax

result = (unsigned int)a1 >> 8;
if ( a3 )
result = computeShape(a1, a2, 1LL);
return result;
}

original_code:
static inline uint16_t computeOutput(uint32_t phase, const uint16_t lookup[], int8_t isExp)
{
 if(isExp)
  return computeShape(phase,lookup,1);
 else
  return phase>>8;
}

canonical_original_code:
static inline unsigned short computeOutput(unsigned int phase, unsigned short lookup[], char isExp)
{
 if(isExp)
  return computeShape(phase,lookup,1);
 else
  return phase>>8;
}

variable_types:
phase
unsigned int

variable_types:
lookup
unsigned short []

variable_types: isExp char


original_code:
void adsr_setCVs(struct adsr_s * adsr, uint16_t atk, uint16_t dec, uint16_t sus, uint16_t rls, uint16_t lvl, uint8_t mask)
{
 int8_t m=mask&0x80;
 if(mask&0x01 && adsr->attackCV!=atk)
 {
  m=1;
  adsr->attackCV=atk;
 }
 if(mask&0x02 && adsr->decayCV!=dec)
 {
  m=1;
  adsr->decayCV=dec;
 }
 if(mask&0x04 && adsr->sustainCV!=sus)
 {
  m=1;
  adsr->sustainCV=sus;
 }
 if(mask&0x08 && adsr->releaseCV!=rls)
 {
  m=1;
  adsr->releaseCV=rls;
 }
 if(mask&0x10 && adsr->levelCV!=lvl)
 {
  m=1;
  adsr->levelCV=lvl;
 }
 if(m)
  updateIncrements(adsr);
}

canonical_original_code:
void adsr_setCVs(struct adsr_s *adsr, unsigned short atk, unsigned short dec, unsigned short sus, unsigned short rls, unsigned short lvl, unsigned char mask)
{
 char m = mask&0x80;
 if(mask&0x01 && adsr->attackCV!=atk)
 {
  m=1;
  adsr->attackCV=atk;
 }
 if(mask&0x02 && adsr->decayCV!=dec)
 {
  m=1;
  adsr->decayCV=dec;
 }
 if(mask&0x04 && adsr->sustainCV!=sus)
 {
  m=1;
  adsr->sustainCV=sus;
 }
 if(mask&0x08 && adsr->releaseCV!=rls)
 {
  m=1;
  adsr->releaseCV=rls;
 }
 if(mask&0x10 && adsr->levelCV!=lvl)
 {
  m=1;
  adsr->levelCV=lvl;
 }
 if(m)
  updateIncrements(adsr);
}

variable_types:
atk
unsigned short

variable_types:
dec
unsigned short

variable_types:
sus
unsigned short

variable_types:
rls
unsigned short

variable_types:
lvl
unsigned short

variable_types:
mask
unsigned char

variable_types: m char


original_code:
void adsr_setGate(struct adsr_s * a, int8_t gate)
{
 a->phase=0;
 a->stageLevel=((uint32_t)a->output<<16)/a->levelCV;
 if(gate)
 {
  a->stage=sAttack;
  updateStageVars(a,sAttack);
 }
 else
 {
  a->stage=sRelease;
  updateStageVars(a,sRelease);
 }
 a->gate=gate;
}

canonical_original_code:
void adsr_setGate(struct adsr_s *a, char gate)
{
 a->phase=0;
 a->stageLevel=((unsigned int)a->output<<16)/a->levelCV;
 if(gate)
 {
  a->stage=sAttack;
  updateStageVars(a,sAttack);
 }
 else
 {
  a->stage=sRelease;
  updateStageVars(a,sRelease);
 }
 a->gate=gate;
}

variable_types: gate char


original_code:
void adsr_reset(struct adsr_s * adsr)
{
 adsr->gate=0;
 adsr->output=0;
 adsr->phase=0;
 adsr->stageLevel=0;
 adsr->stage=sWait;
 updateStageVars(adsr,sWait);
}

canonical_original_code:
void adsr_reset(struct adsr_s *adsr)
{
 adsr->gate=0;
 adsr->output=0;
 adsr->phase=0;
 adsr->stageLevel=0;
 adsr->stage=sWait;
 updateStageVars(adsr,sWait);
}


decompiled_code:
void __fastcall adsr_setShape(__int64 a1, char a2)
{
*(_BYTE *)(a1 + 38) = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char a2)
{
*(_BYTE *)(a1 + 38) = a2;
}

original_code:
inline void adsr_setShape(struct adsr_s * adsr, int8_t isExp)
{
 adsr->expOutput=isExp;
}

canonical_original_code:
inline void adsr_setShape(struct adsr_s *adsr, char isExp)
{
 adsr->expOutput=isExp;
}


decompiled_code:
void __fastcall adsr_setSpeedShift(__int64 a1, char a2)
{
*(_BYTE *)(a1 + 40) = a2;
updateIncrements(a1);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, char a2)
{
*(_BYTE *)(a1 + 40) = a2;
func2(a1);
}

original_code:
void adsr_setSpeedShift(struct adsr_s * adsr, uint8_t shift)
{
 adsr->speedShift=shift;
 updateIncrements(adsr);
}

canonical_original_code:
void adsr_setSpeedShift(struct adsr_s *adsr, unsigned char shift)
{
 adsr->speedShift=shift;
 updateIncrements(adsr);
}

variable_types:
shift
unsigned char


decompiled_code:
__int64 __fastcall adsr_getStage(__int64 a1)
{
return *(unsigned int *)(a1 + 44);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return *(unsigned int *)(a1 + 44);
}

original_code:
inline adsrStage_t adsr_getStage(struct adsr_s * adsr)
{
 return adsr->stage;
}

canonical_original_code:
inline enum adsrStage_t adsr_getStage(struct adsr_s *adsr)
{
 return adsr->stage;
}

return_type: enum adsrStage_t { sWait=0, sAttack=1, sDecay=2, sSustain=3, sRelease=4, sDone=5 }


decompiled_code:
__int64 __fastcall adsr_getOutput(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 36);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 36);
}

original_code:
inline uint16_t adsr_getOutput(struct adsr_s * adsr)
{
 return adsr->output;
}

canonical_original_code:
inline unsigned short adsr_getOutput(struct adsr_s *adsr)
{
 return adsr->output;
}


original_code:
void adsr_init(struct adsr_s * adsr)
{
 memset(adsr,0,sizeof(struct adsr_s));
}

canonical_original_code:
void adsr_init(struct adsr_s *adsr)
{
 memset(adsr,0,sizeof(struct adsr_s));
}


decompiled_code:
__int64 __fastcall adsr_update(unsigned int *a1)
{
unsigned int v1; // eax
unsigned __int16 v2; // ax
__int64 result; // rax

if ( *((_BYTE *)a1 + 7) )
handlePhaseOverflow((__int64)a1);
v1 = a1[11];
if ( v1 == 3 )
{
v2 = *((_WORD *)a1 + 10);
goto LABEL_11;
}
if ( v1 > 3 )
{
if ( v1 != 4 )
{
v2 = 0;
goto LABEL_11;
}
}
else
{
if ( v1 == 1 )
{
v2 = computeOutput(a1[1], (__int64)&attackCurveLookup, *((_BYTE *)a1 + 38));
goto LABEL_11;
}
if ( v1 != 2 )
{
v2 = 0;
goto LABEL_11;
}
}
v2 = ~(unsigned __int16)computeOutput(a1[1], (__int64)&decayCurveLookup, *((_BYTE *)a1 + 38));
LABEL_11:
*((_WORD *)a1 + 18) = *((_WORD *)a1 + 16) + scaleU16U16(v2, *((unsigned __int16 *)a1 + 17));
result = *a1;
a1[1] += result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1)
{
unsigned int v1; // eax
unsigned __int16 v2; // ax
__int64 result; // rax

if ( *((_BYTE *)a1 + 7) )
func3((__int64)a1);
v1 = a1[11];
if ( v1 == 3 )
{
v2 = *((_WORD *)a1 + 10);
goto LABEL_11;
}
if ( v1 > 3 )
{
if ( v1 != 4 )
{
v2 = 0;
goto LABEL_11;
}
}
else
{
if ( v1 == 1 )
{
v2 = func4(a1[1], (__int64)&attackCurveLookup, *((_BYTE *)a1 + 38));
goto LABEL_11;
}
if ( v1 != 2 )
{
v2 = 0;
goto LABEL_11;
}
}
v2 = ~(unsigned __int16)func4(a1[1], (__int64)&decayCurveLookup, *((_BYTE *)a1 + 38));
LABEL_11:
*((_WORD *)a1 + 18) = *((_WORD *)a1 + 16) + scaleU16U16(v2, *((unsigned __int16 *)a1 + 17));
result = *a1;
a1[1] += result;
return result;
}

original_code:
inline void adsr_update(struct adsr_s * a)
{
 if(a->phase>>24)
  handlePhaseOverflow(a);
 uint16_t o=0;
 switch(a->stage)
 {
 case sAttack:
  o=computeOutput(a->phase,attackCurveLookup,a->expOutput);
  break;
 case sDecay:
 case sRelease:
  o=(65535)-computeOutput(a->phase,decayCurveLookup,a->expOutput);
  break;
 case sSustain:
  o=a->sustainCV;
  break;
 default:
  ;
 }
 a->output=scaleU16U16(o,a->stageMul)+a->stageAdd;
 a->phase+=a->stageIncrement;
}

canonical_original_code:
inline void adsr_update(struct adsr_s *a)
{
 if(a->phase>>24)
  handlePhaseOverflow(a);
 unsigned short o = 0;
 switch(a->stage)
 {
 case sAttack:
  o=computeOutput(a->phase,attackCurveLookup,a->expOutput);
  break;
 case sDecay:
 case sRelease:
  o=(65535)-computeOutput(a->phase,decayCurveLookup,a->expOutput);
  break;
 case sSustain:
  o=a->sustainCV;
  break;
 default:
  ;
 }
 a->output=scaleU16U16(o,a->stageMul)+a->stageAdd;
 a->phase+=a->stageIncrement;
}

variable_types:
o
unsigned short


handlePhaseOverflow

decompiled_code:
void __fastcall handlePhaseOverflow(__int64 a1)
{
int v1; // eax

*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)a1 = 0;
v1 = *(_DWORD *)(a1 + 44) + 1;
*(_DWORD *)(a1 + 44) = v1;
switch ( v1 )
{
case 3:
updateStageVars(a1, 3u);
break;
case 5:
*(_DWORD *)(a1 + 44) = 0;
*(_WORD *)(a1 + 36) = 0;
break;
case 2:
*(_WORD *)(a1 + 36) = *(_WORD *)(a1 + 22);
updateStageVars(a1, 2u);
break;
}
}

original_code:
static __attribute__ ((noinline)) void handlePhaseOverflow(struct adsr_s * a)
{
 a->phase=0;
 a->stageIncrement=0;
 ++a->stage;
 switch(a->stage)
 {
 case sDecay:
  a->output=a->levelCV;
  updateStageVars(a,sDecay);
  return;
 case sSustain:
  updateStageVars(a,sSustain);
  return;
 case sDone:
  a->stage=sWait;
  a->output=0;
  return;
 default:
  ;
 }
}

canonical_original_code:
static void handlePhaseOverflow(struct adsr_s *a)
{
 a->phase=0;
 a->stageIncrement=0;
 ++a->stage;
 switch(a->stage)
 {
 case sDecay:
  a->output=a->levelCV;
  updateStageVars(a,sDecay);
  return;
 case sSustain:
  updateStageVars(a,sSustain);
  return;
 case sDone:
  a->stage=sWait;
  a->output=0;
  return;
 default:
  ;
 }
}