sysexReceiveByte

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

if ( a1 == -16 )
{
result = 0LL;
sysexSize = 0;
tempBuffer = 0LL;
*(_QWORD *)((char *)&tempBuffer + 398) = 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_constprop_0(sysexSize - 4);
}
else if ( *((_BYTE *)&tempBuffer + 1) == 97 && *((_BYTE *)&tempBuffer + 2) == 22 )
{
v3 = *((_BYTE *)&tempBuffer + 3);
if ( v3 == 1 )
{
v4 = sysexDescrambleBuffer_constprop_0();
storage_import(
*((unsigned __int8 *)&tempBuffer + 4),
(unsigned int)((_DWORD)&tempBuffer + 5),
(unsigned int)(__int16)(v4 - 1));
}
else if ( v3 == 2 )
{
midi_dumpPreset(*((_BYTE *)&tempBuffer + 4));
}
}
sysexSize = 0;
result = refreshFullState();
}
else
{
LODWORD(result) = sysexSize;
v2 = sysexSize + 1;
if ( sysexSize > 405 )
{
LODWORD(result) = 0;
v2 = 1;
}
result = (int)result;
sysexSize = v2;
*((_BYTE *)&tempBuffer + (int)result) = a1;
}
return result;
}

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

if ( a1 == -16 )
{
result = 0LL;
sysexSize = 0;
tempBuffer = 0LL;
*(_QWORD *)((char *)&tempBuffer + 398) = 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 )
func6(sysexSize - 4);
}
else if ( *((_BYTE *)&tempBuffer + 1) == 97 && *((_BYTE *)&tempBuffer + 2) == 22 )
{
v3 = *((_BYTE *)&tempBuffer + 3);
if ( v3 == 1 )
{
v4 = func7();
storage_import(
*((unsigned __int8 *)&tempBuffer + 4),
(unsigned int)((_DWORD)&tempBuffer + 5),
(unsigned int)(__int16)(v4 - 1));
}
else if ( v3 == 2 )
{
func16(*((_BYTE *)&tempBuffer + 4));
}
}
sysexSize = 0;
result = refreshFullState();
}
else
{
LODWORD(result) = sysexSize;
v2 = sysexSize + 1;
if ( sysexSize > 405 )
{
LODWORD(result) = 0;
v2 = 1;
}
result = (int)result;
sysexSize = v2;
*((_BYTE *)&tempBuffer + (int)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, __int16 a2, char a3, char a4, char a5)
{
__int64 result; // rax
__int16 v6; // bx

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

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

result = (unsigned __int16)sysexSize;
v6 = a2 + ~sysexSize;
if ( !sysexSize )
v6 = a2;
if ( v6 )
{
result = func17(a3);
if ( v6 != 1 )
{
result = func17(a4);
if ( v6 != 2 )
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; } *

variable_types:
count
unsigned short

return_type: void

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


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

v0 = 0;
v3[0] = 0;
do
{
while ( 1 )
{
result = preset_loadCurrent(v0);
if ( (_BYTE)result )
break;
if ( ++v0 == 100 )
return result;
}
v2 = v0++;
storage_export(v2, &tempBuffer, v3);
result = sysexSend_constprop_0(v3[0]);
}
while ( v0 != 100 );
return result;
}

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

v0 = 0;
v3[0] = 0;
do
{
while ( 1 )
{
result = preset_loadCurrent(v0);
if ( (_BYTE)result )
break;
if ( ++v0 == 100 )
return result;
}
v2 = v0++;
storage_export(v2, &tempBuffer, v3);
result = func14(v3[0]);
}
while ( v0 != 100 );
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

variable_types: size short


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

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

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

v4 = (unsigned __int8)settings[294];
v5 = a3 >> 9;
if ( a2 )
result = midi_send_noteon(&midi, v4, a1, v5);
else
result = midi_send_noteoff(&midi, v4, a1, v5);
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:
note
unsigned char

variable_types: gate char

variable_types:
velocity
unsigned short


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

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

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

if ( (a3 & 1) != 0 )
{
result = a1 ^ (unsigned int)(unsigned __int16)lastBend_1;
if ( (((unsigned __int16)a1 ^ (unsigned __int16)lastBend_1) & 0xFFFC) != 0 )
{
result = midi_send_pitchbend(&midi, (unsigned __int8)settings[294], (unsigned int)(__int16)a1);
lastBend_1 = a1;
}
}
if ( (a3 & 2) != 0 )
{
result = a2 ^ (unsigned int)(unsigned __int16)lastMod_0;
if ( (((unsigned __int16)a2 ^ (unsigned __int16)lastMod_0) & 0xFE00) != 0 )
{
result = midi_send_cc(&midi, (unsigned __int8)settings[294], 1LL, (unsigned __int16)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 ? 0 : 0x7F);
}

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

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

return_type: char


finishPreviousNote

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

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

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

if ( byte_602 != -1 )
{
v0 = byte_602 & 0x7F;
assigner_assignNote((unsigned __int8)((byte_602 & 0x7F) + BYTE1(qword_603) + 24), 0LL, 0LL, 0LL);
result = midi_sendNoteEvent((unsigned __int8)(BYTE1(qword_603) + v0 + 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();
byte_602 = -1;
word_600 = -1;
arp = -1LL;
xmmword_590 = -1LL;
xmmword_5A0 = -1LL;
xmmword_5B0 = -1LL;
xmmword_5C0 = -1LL;
xmmword_5D0 = -1LL;
xmmword_5E0 = -1LL;
xmmword_5F0 = -1LL;
return assigner_allKeysOff();
}

canonical_decompiled_code:
__int64 func2()
{
func1();
byte_602 = -1;
word_600 = -1;
arp = -1LL;
xmmword_590 = -1LL;
xmmword_5A0 = -1LL;
xmmword_5B0 = -1LL;
xmmword_5C0 = -1LL;
xmmword_5D0 = -1LL;
xmmword_5E0 = -1LL;
xmmword_5F0 = -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 killHeldNotes()
{
__int16 *v0; // rax
__int64 result; // rax

v0 = (__int16 *)&arp;
do
{
if ( *(char *)v0 < 0 )
*(_BYTE *)v0 = -1;
v0 = (__int16 *)((char *)v0 + 1);
}
while ( v0 != &word_600 );
result = isEmpty();
if ( (_BYTE)result )
result = finishPreviousNote();
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int16 *v0; // rax
__int64 result; // rax

v0 = (__int16 *)&arp;
do
{
if ( *(char *)v0 < 0 )
*(_BYTE *)v0 = -1;
v0 = (__int16 *)((char *)v0 + 1);
}
while ( v0 != &word_600 );
result = func0();
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(int a1, char a2)
{
bool v2; // zf

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

canonical_decompiled_code:
void __fastcall func4(int a1, char a2)
{
bool v2; // zf

if ( *(_DWORD *)((char *)&qword_603 + 5) != a1 )
{
func2();
if ( a1 )
{
v2 = settings[296] == 0;
word_600 = -1;
if ( v2 && (unsigned int)seq_getMode(0LL) != 2 && (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
}
}
if ( !a2 && BYTE2(qword_603) )
func3();
*(_DWORD *)((char *)&qword_603 + 5) = a1;
BYTE2(qword_603) = 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_603) = a1;
}

canonical_decompiled_code:
void __fastcall func5(char a1)
{
LOBYTE(qword_603) = 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:
__int64 __fastcall arp_resetCounter(char a1)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
word_600 = -1;
if ( a1 )
{
result = seq_getMode(0LL);
if ( (_DWORD)result != 2 )
{
result = seq_getMode(1LL);
if ( (_DWORD)result != 2 )
result = clock_reset();
}
}
return result;
}

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

result = 0xFFFFFFFFLL;
word_600 = -1;
if ( a1 )
{
result = seq_getMode(0LL);
if ( (_DWORD)result != 2 )
{
result = seq_getMode(1LL);
if ( (_DWORD)result != 2 )
result = clock_reset();
}
}
return result;
}

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_603 + 5);
}

canonical_decompiled_code:
__int64 func7()
{
return *(unsigned int *)((char *)&qword_603 + 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_603);
}

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

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:
void __fastcall arp_assignNote(__int64 a1, __int64 a2)
{
unsigned __int8 v2; // bl
int v3; // edx
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rax
bool v7; // zf
__int64 v8; // rax
__int64 v9; // rdx

if ( *(_DWORD *)((char *)&qword_603 + 5) )
{
v2 = a1 - 24;
if ( (_BYTE)a2 )
{
if ( (unsigned __int8)isEmpty(a1, a2, *(unsigned int *)((char *)&qword_603 + 5)) )
{
v7 = settings[296] == 0;
word_600 = -1;
if ( v7 )
{
if ( (unsigned int)seq_getMode(0LL) != 2 && (unsigned int)seq_getMode(1LL) != 2 )
clock_reset();
v3 = *(_DWORD *)((char *)&qword_603 + 5);
}
}
if ( v3 == 1 )
{
*((_BYTE *)&arp + v2) = v2;
*((_BYTE *)&arp + 127 - v2) = v2;
return;
}
v4 = 0LL;
while ( 1 )
{
v5 = (int)v4;
if ( *((_BYTE *)&arp + v4) == 0xFF )
break;
if ( ++v4 == 128 )
return;
}
LABEL_8:
*((_BYTE *)&arp + v5) = v2;
return;
}
if ( BYTE2(qword_603) )
{
if ( *(_DWORD *)((char *)&qword_603 + 5) == 1 )
{
*((_BYTE *)&arp + v2) |= 0x80u;
*((_BYTE *)&arp + 127 - v2) |= 0x80u;
return;
}
v6 = 0LL;
while ( 1 )
{
v5 = (int)v6;
if ( *((_BYTE *)&arp + v6) == v2 )
break;
if ( ++v6 == 128 )
return;
}
v2 |= 0x80u;
goto LABEL_8;
}
if ( *(_DWORD *)((char *)&qword_603 + 5) == 1 )
{
v9 = v2;
*((_BYTE *)&arp + v2) = -1;
*((_BYTE *)&arp + 127 - v2) = -1;
}
else
{
v8 = 0LL;
while ( 1 )
{
v9 = (int)v8;
if ( *((_BYTE *)&arp + v8) == v2 )
break;
if ( ++v8 == 128 )
goto LABEL_25;
}
*((_BYTE *)&arp + (int)v8) = -1;
}
LABEL_25:
if ( (unsigned __int8)isEmpty(a1, a2, v9) )
finishPreviousNote();
}
}

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();
  }
 }
}


decompiled_code:
__int64 __fastcall arp_update(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rdx
int v5; // eax
char v6; // bl
int v7; // eax

result = *(unsigned int *)((char *)&qword_603 + 5);
if ( *(_DWORD *)((char *)&qword_603 + 5) )
{
result = isEmpty(a1, a2, a3);
if ( !(_BYTE)result )
{
finishPreviousNote();
if ( *(_DWORD *)((char *)&qword_603 + 5) == 2 )
{
do
{
v7 = (int)random() % 128;
word_600 = v7;
v4 = (__int16)v7;
}
while ( *((_BYTE *)&arp + v7) == 0xFF );
}
else
{
result = *(_DWORD *)((_BYTE *)&qword_603 + 5) & 0xFFFFFFFD;
if ( (_DWORD)result != 1 )
return result;
LODWORD(v4) = word_600;
do
{
v5 = ((int)v4 + 1) % 128;
v4 = (__int16)v5;
}
while ( *((_BYTE *)&arp + v5) == 0xFF );
word_600 = v5;
}
v6 = *((_BYTE *)&arp + v4) & 0x7F;
assigner_assignNote((unsigned __int8)(v6 + qword_603 + 24), 1LL, 0x8000LL, 0LL);
midi_sendNoteEvent((unsigned __int8)(v6 + qword_603 + 24), 1LL, 0x8000LL);
byte_602 = *((_BYTE *)&arp + word_600);
result = (unsigned __int8)qword_603;
BYTE1(qword_603) = qword_603;
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rdx
int v5; // eax
char v6; // bl
int v7; // eax

result = *(unsigned int *)((char *)&qword_603 + 5);
if ( *(_DWORD *)((char *)&qword_603 + 5) )
{
result = func0(a1, a2, a3);
if ( !(_BYTE)result )
{
func1();
if ( *(_DWORD *)((char *)&qword_603 + 5) == 2 )
{
do
{
v7 = (int)random() % 128;
word_600 = v7;
v4 = (__int16)v7;
}
while ( *((_BYTE *)&arp + v7) == 0xFF );
}
else
{
result = *(_DWORD *)((_BYTE *)&qword_603 + 5) & 0xFFFFFFFD;
if ( (_DWORD)result != 1 )
return result;
LODWORD(v4) = word_600;
do
{
v5 = ((int)v4 + 1) % 128;
v4 = (__int16)v5;
}
while ( *((_BYTE *)&arp + v5) == 0xFF );
word_600 = v5;
}
v6 = *((_BYTE *)&arp + v4) & 0x7F;
assigner_assignNote((unsigned __int8)(v6 + qword_603 + 24), 1LL, 0x8000LL, 0LL);
midi_sendNoteEvent((unsigned __int8)(v6 + qword_603 + 24), 1LL, 0x8000LL);
byte_602 = *((_BYTE *)&arp + word_600);
result = (unsigned __int8)qword_603;
BYTE1(qword_603) = qword_603;
return result;
}
}
return result;
}

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:
__int64 arp_init()
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
qword_603 = 0LL;
byte_60B = 0;
word_600 = -1;
byte_602 = -1;
arp = -1LL;
xmmword_590 = -1LL;
xmmword_5A0 = -1LL;
xmmword_5B0 = -1LL;
xmmword_5C0 = -1LL;
xmmword_5D0 = -1LL;
xmmword_5E0 = -1LL;
xmmword_5F0 = -1LL;
return result;
}

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

result = 0xFFFFFFFFLL;
qword_603 = 0LL;
byte_60B = 0;
word_600 = -1;
byte_602 = -1;
arp = -1LL;
xmmword_590 = -1LL;
xmmword_5A0 = -1LL;
xmmword_5B0 = -1LL;
xmmword_5C0 = -1LL;
xmmword_5D0 = -1LL;
xmmword_5E0 = -1LL;
xmmword_5F0 = -1LL;
return result;
}

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)
{
BYTE10(display) = a2;
if ( src )
{
BYTE9(display) = 0;
strcpy(dest, src);
*(_WORD *)((char *)&display + strlen((const char *)&display + 15) + 15) = 32;
}
else
{
BYTE9(display) = -1;
}
}

canonical_decompiled_code:
void __fastcall func1(char *src, char a2)
{
BYTE10(display) = a2;
if ( src )
{
BYTE9(display) = 0;
strcpy(dest, src);
*(_WORD *)((char *)&display + strlen((const char *)&display + 15) + 15) = 32;
}
else
{
BYTE9(display) = -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_constprop_0(a1);
result = map_to_seg7_constprop_0(a2);
BYTE5(display) = result;
return result;
}

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

BYTE4(display) = func0(a1);
result = func0(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 = ~(1 << a1) & display;
result = WORD1(display) & ~(unsigned __int16)(1 << a1);
LOWORD(display) = v6;
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 = ~(1 << a1) & display;
result = WORD1(display) & ~(unsigned __int16)(1 << a1);
LOWORD(display) = v6;
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:
__int64 display_clear()
{
__int64 result; // rax

result = 0LL;
BYTE10(display) = 0;
LODWORD(display) = 0;
WORD2(display) = 0;
return result;
}

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

result = 0LL;
BYTE10(display) = 0;
LODWORD(display) = 0;
WORD2(display) = 0;
return result;
}

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


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

result = 0LL;
display = 0LL;
word_480 = 0;
HIBYTE(display) = 32;
*(_OWORD *)dest = 0LL;
xmmword_460 = 0LL;
xmmword_470 = 0LL;
return result;
}

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

result = 0LL;
display = 0LL;
word_480 = 0;
HIBYTE(display) = 32;
*(_OWORD *)dest = 0LL;
xmmword_460 = 0LL;
xmmword_470 = 0LL;
return result;
}

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


decompiled_code:
__int64 __fastcall display_update(char a1)
{
char v1; // bp
int v2; // esi
char v3; // dl
__int64 result; // rax
unsigned __int8 v5; // bl
int v6; // edx
int v7; // edx
char v8; // di

if ( a1 )
{
if ( ++BYTE6(display) > 0x14u )
{
BYTE6(display) = 0;
BYTE7(display) = BYTE7(display) == 0;
}
v1 = BYTE10(display);
if ( BYTE10(display) )
{
v5 = ++BYTE8(display);
strlen((const char *)&display + 15);
map_to_seg7_constprop_0(*((char *)&display + SBYTE9(display) + 15));
map_to_seg7_constprop_0(*((char *)&display + v6 + 15));
if ( v5 > 0xFu )
{
BYTE9(display) = v7;
BYTE8(display) = 0;
if ( !v7 && v1 > 0 )
BYTE10(display) = v1 - 1;
}
}
v2 = BYTE11(display);
if ( BYTE11(display) == 1 )
{
v8 = 9;
}
else
{
if ( BYTE11(display) != 2 )
{
v3 = 0;
if ( !BYTE11(display) )
{
v3 = display;
if ( BYTE7(display) )
v3 = BYTE2(display) ^ display;
}
LABEL_8:
*((_BYTE *)&display + v2 + 12) = v3;
goto LABEL_9;
}
v8 = 8;
}
led_getOn(v8);
if ( led_getBlinking(v8) && BYTE7(display) )
v3 += 0x80;
goto LABEL_8;
}
LABEL_9:
io_write(9LL, 0LL);
io_write(8LL, (unsigned __int8)(16 << SBYTE11(display)));
io_write(9LL, *((unsigned __int8 *)&display + BYTE11(display) + 12));
result = ((unsigned int)BYTE11(display) + 1) % 3;
BYTE11(display) = ((unsigned int)BYTE11(display) + 1) % 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
char v1; // bp
int v2; // esi
char v3; // dl
__int64 result; // rax
unsigned __int8 v5; // bl
int v6; // edx
int v7; // edx
char v8; // di

if ( a1 )
{
if ( ++BYTE6(display) > 0x14u )
{
BYTE6(display) = 0;
BYTE7(display) = BYTE7(display) == 0;
}
v1 = BYTE10(display);
if ( BYTE10(display) )
{
v5 = ++BYTE8(display);
strlen((const char *)&display + 15);
func0(*((char *)&display + SBYTE9(display) + 15));
func0(*((char *)&display + v6 + 15));
if ( v5 > 0xFu )
{
BYTE9(display) = v7;
BYTE8(display) = 0;
if ( !v7 && v1 > 0 )
BYTE10(display) = v1 - 1;
}
}
v2 = BYTE11(display);
if ( BYTE11(display) == 1 )
{
v8 = 9;
}
else
{
if ( BYTE11(display) != 2 )
{
v3 = 0;
if ( !BYTE11(display) )
{
v3 = display;
if ( BYTE7(display) )
v3 = BYTE2(display) ^ display;
}
LABEL_8:
*((_BYTE *)&display + v2 + 12) = v3;
goto LABEL_9;
}
v8 = 8;
}
func4(v8);
if ( func5(v8) && BYTE7(display) )
v3 += 0x80;
goto LABEL_8;
}
LABEL_9:
io_write(9LL, 0LL);
io_write(8LL, (unsigned __int8)(16 << SBYTE11(display)));
io_write(9LL, *((unsigned __int8 *)&display + BYTE11(display) + 12));
result = ((unsigned int)BYTE11(display) + 1) % 3;
BYTE11(display) = ((unsigned int)BYTE11(display) + 1) % 3;
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
__int64 v2; // r8
unsigned __int8 v3; // di
unsigned int v4; // eax
__int64 v5; // r8
unsigned __int8 v6; // di
char v7; // cl
unsigned int v8; // eax
__int64 v9; // r8
unsigned int v10; // esi
char v11; // cl

v1 = getPhaseInc(*(_BYTE *)(a1 + 25));
v3 = *(_BYTE *)(v2 + 27);
*(_DWORD *)(v2 + 8) = 16 * (v1 >> *(_BYTE *)(v2 + 40));
v4 = getPhaseInc(v3);
v6 = *(_BYTE *)(v5 + 29);
*(_DWORD *)(v5 + 12) = 16 * (v4 >> v7);
v8 = getPhaseInc(v6);
v10 = *(_DWORD *)(v9 + 44);
*(_DWORD *)(v9 + 16) = 16 * (v8 >> v11);
updateStageVars(v9, v10);
}

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

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

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

if ( a3 )
result = computeShape(a1, a2, 1LL);
else
result = (unsigned int)a1 >> 8;
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

return_type: unsigned short


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


decompiled_code:
void __fastcall adsr_init(_OWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

canonical_decompiled_code:
void __fastcall func12(_OWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

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 v2; // eax
bool v3; // cc
__int64 v4; // rdi
__int64 result; // rax

if ( !*((_BYTE *)a1 + 7) )
{
v2 = a1[11];
v3 = v2 <= 3;
if ( v2 != 3 )
goto LABEL_3;
LABEL_12:
v4 = *((unsigned __int16 *)a1 + 10);
goto LABEL_6;
}
handlePhaseOverflow((__int64)a1);
v2 = a1[11];
v3 = v2 <= 3;
if ( v2 == 3 )
goto LABEL_12;
LABEL_3:
if ( !v3 )
{
if ( v2 == 4 )
goto LABEL_8;
goto LABEL_10;
}
if ( v2 != 1 )
{
if ( v2 == 2 )
{
LABEL_8:
v4 = (unsigned __int16)~computeOutput(a1[1], (__int64)&decayCurveLookup, *((_BYTE *)a1 + 38));
goto LABEL_6;
}
LABEL_10:
v4 = 0LL;
goto LABEL_6;
}
v4 = (unsigned __int16)computeOutput(a1[1], (__int64)&attackCurveLookup, *((_BYTE *)a1 + 38));
LABEL_6:
*((_WORD *)a1 + 18) = *((_WORD *)a1 + 16) + scaleU16U16(v4, *((unsigned __int16 *)a1 + 17));
result = *a1;
a1[1] += result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1)
{
unsigned int v2; // eax
bool v3; // cc
__int64 v4; // rdi
__int64 result; // rax

if ( !*((_BYTE *)a1 + 7) )
{
v2 = a1[11];
v3 = v2 <= 3;
if ( v2 != 3 )
goto LABEL_3;
LABEL_12:
v4 = *((unsigned __int16 *)a1 + 10);
goto LABEL_6;
}
func3((__int64)a1);
v2 = a1[11];
v3 = v2 <= 3;
if ( v2 == 3 )
goto LABEL_12;
LABEL_3:
if ( !v3 )
{
if ( v2 == 4 )
goto LABEL_8;
goto LABEL_10;
}
if ( v2 != 1 )
{
if ( v2 == 2 )
{
LABEL_8:
v4 = (unsigned __int16)~func4(a1[1], (__int64)&decayCurveLookup, *((_BYTE *)a1 + 38));
goto LABEL_6;
}
LABEL_10:
v4 = 0LL;
goto LABEL_6;
}
v4 = (unsigned __int16)func4(a1[1], (__int64)&attackCurveLookup, *((_BYTE *)a1 + 38));
LABEL_6:
*((_WORD *)a1 + 18) = *((_WORD *)a1 + 16) + scaleU16U16(v4, *((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
int v2; // eax

v1 = *(_DWORD *)(a1 + 44);
*(_QWORD *)a1 = 0LL;
v2 = v1 + 1;
*(_DWORD *)(a1 + 44) = v2;
switch ( v2 )
{
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:
  ;
 }
}


original_code:
void midi_device_init(MidiDevice * device){
   device->input_state = IDLE;
   device->input_count = 0;
   bytequeue_init(&device->input_queue, device->input_queue_data, 192);
   device->input_cc_callback = 0;
   device->input_noteon_callback = 0;
   device->input_noteoff_callback = 0;
   device->input_aftertouch_callback = 0;
   device->input_pitchbend_callback = 0;
   device->input_songposition_callback = 0;
   device->input_progchange_callback = 0;
   device->input_chanpressure_callback = 0;
   device->input_songselect_callback = 0;
   device->input_tc_quarterframe_callback = 0;
   device->input_realtime_callback = 0;
   device->input_tunerequest_callback = 0;
   device->input_sysex_callback = 0;
   device->input_fallthrough_callback = 0;
   device->input_catchall_callback = 0;
   device->pre_input_process_callback = 0;
}

canonical_original_code:
void midi_device_init(struct _midi_device *device){
   device->input_state = IDLE;
   device->input_count = 0;
   bytequeue_init(&device->input_queue, device->input_queue_data, 192);
   device->input_cc_callback = 0;
   device->input_noteon_callback = 0;
   device->input_noteoff_callback = 0;
   device->input_aftertouch_callback = 0;
   device->input_pitchbend_callback = 0;
   device->input_songposition_callback = 0;
   device->input_progchange_callback = 0;
   device->input_chanpressure_callback = 0;
   device->input_songselect_callback = 0;
   device->input_tc_quarterframe_callback = 0;
   device->input_realtime_callback = 0;
   device->input_tunerequest_callback = 0;
   device->input_sysex_callback = 0;
   device->input_fallthrough_callback = 0;
   device->input_catchall_callback = 0;
   device->pre_input_process_callback = 0;
}

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 __fastcall midi_device_input(__int64 a1, char a2, unsigned __int8 *a3)
{
__int64 v3; // r12
unsigned __int8 *v4; // rbx
__int64 v5; // rsi
__int64 result; // rax

if ( a2 )
{
v3 = (__int64)&a3[(unsigned __int8)(a2 - 1) + 1];
v4 = a3;
do
{
v5 = *v4++;
result = bytequeue_enqueue(a1 + 344, v5);
}
while ( v4 != (unsigned __int8 *)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, unsigned __int8 *a3)
{
__int64 v3; // r12
unsigned __int8 *v4; // rbx
__int64 v5; // rsi
__int64 result; // rax

if ( a2 )
{
v3 = (__int64)&a3[(unsigned __int8)(a2 - 1) + 1];
v4 = a3;
do
{
v5 = *v4++;
result = bytequeue_enqueue(a1 + 344, v5);
}
while ( v4 != (unsigned __int8 *)v3 );
}
return result;
}

original_code:
void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input) {
   uint8_t i;
   for (i = 0; i < cnt; i++)
      bytequeue_enqueue(&device->input_queue, input[i]);
}

canonical_original_code:
void midi_device_input(struct _midi_device *device, unsigned char cnt, unsigned char *input) {
   unsigned char i;
   for (i = 0; i < cnt; i++)
      bytequeue_enqueue(&device->input_queue, input[i]);
}

variable_types:
cnt
unsigned char

variable_types:
input
unsigned char *

variable_types:
i
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:
void __fastcall midi_device_set_pre_input_process_func(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 128) = a2;
}

original_code:
void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func){
   device->pre_input_process_callback = pre_process_func;
}

canonical_original_code:
void midi_device_set_pre_input_process_func(struct _midi_device *device, void (*pre_process_func)(struct _midi_device *device)){
   device->pre_input_process_callback = pre_process_func;
}


decompiled_code:
__int64 __fastcall midi_process_byte(__int64 a1, unsigned __int8 a2)
{
int v3; // ebp
__int64 result; // rax
int v5; // edx
unsigned int v6; // eax
unsigned __int16 v7; // si
int v8; // eax
unsigned int v9; // edx
unsigned __int8 v10; // cl

if ( (unsigned __int8)midi_is_realtime(a2) )
{
v3 = *(_DWORD *)(a1 + 140);
*(_DWORD *)(a1 + 140) = 1;
result = (__int64)midi_input_callbacks(a1, 1u, a2, 0, 0);
*(_DWORD *)(a1 + 140) = v3;
return result;
}
result = midi_is_statusbyte(a2);
if ( (_BYTE)result )
{
if ( *(_DWORD *)(a1 + 140) != 4 )
{
*(_BYTE *)(a1 + 136) = a2;
*(_WORD *)(a1 + 144) = 1;
}
result = midi_packet_length(a2);
if ( (_DWORD)result == 2 )
{
*(_DWORD *)(a1 + 140) = 2;
return result;
}
if ( (unsigned int)result > 2 )
{
if ( (_DWORD)result == 3 )
{
*(_DWORD *)(a1 + 140) = 3;
return result;
}
}
else
{
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 140) = 1;
result = (__int64)midi_input_callbacks(a1, 1u, a2, 0, 0);
*(_DWORD *)(a1 + 140) = 0;
return result;
}
if ( a2 == 0xF0 )
{
*(_BYTE *)(a1 + 136) = -16;
*(_DWORD *)(a1 + 140) = 4;
*(_WORD *)(a1 + 144) = 1;
return result;
}
if ( a2 == 0xF7 )
{
v8 = *(unsigned __int16 *)(a1 + 144);
v9 = 43691 * v8;
LOWORD(v8) = v8 + 1;
*(_BYTE *)(a1 + (unsigned __int16)(*(_WORD *)(a1 + 144) - 3 * (v9 >> 17)) + 136) = -9;
v10 = *(_BYTE *)(a1 + 137);
*(_WORD *)(a1 + 144) = v8;
result = (__int64)midi_input_callbacks(a1, v8, *(_BYTE *)(a1 + 136), v10, *(_BYTE *)(a1 + 138));
*(_DWORD *)(a1 + 140) = 0;
return result;
}
}
*(_DWORD *)(a1 + 140) = 0;
*(_WORD *)(a1 + 144) = 0;
return result;
}
v5 = *(_DWORD *)(a1 + 140);
if ( v5 )
{
v6 = *(unsigned __int16 *)(a1 + 144);
v7 = v6 + 1;
result = v6 % 3;
*(_BYTE *)(a1 + (unsigned __int16)result + 136) = a2;
*(_WORD *)(a1 + 144) = v7;
if ( (_WORD)result == 1 )
{
if ( v5 == 2 )
{
result = (__int64)midi_input_callbacks(a1, v7, *(_BYTE *)(a1 + 136), *(_BYTE *)(a1 + 137), 0);
if ( *(_DWORD *)(a1 + 140) != 4 )
goto LABEL_17;
}
}
else if ( (_WORD)result == 2 )
{
result = (__int64)midi_input_callbacks(a1, v7, *(_BYTE *)(a1 + 136), *(_BYTE *)(a1 + 137), *(_BYTE *)(a1 + 138));
if ( *(_DWORD *)(a1 + 140) != 4 )
{
LABEL_17:
result = 1LL;
*(_WORD *)(a1 + 144) = 1;
return result;
}
}
}
return result;
}

original_code:
void midi_process_byte(MidiDevice * device, uint8_t input) {
   if (midi_is_realtime(input)) {
      input_state_t state = device->input_state;
      device->input_state = ONE_BYTE_MESSAGE;
      midi_input_callbacks(device, 1, input, 0, 0);
      device->input_state = state;
   } else if (midi_is_statusbyte(input)) {
      if (device->input_state != SYSEX_MESSAGE) {
         device->input_buffer[0] = input;
         device->input_count = 1;
      }
      switch (midi_packet_length(input)) {
         case ONE:
            device->input_state = ONE_BYTE_MESSAGE;;
            midi_input_callbacks(device, 1, input, 0, 0);
            device->input_state = IDLE;
            break;
         case TWO:
            device->input_state = TWO_BYTE_MESSAGE;
            break;
         case THREE:
            device->input_state = THREE_BYTE_MESSAGE;
            break;
         case UNDEFINED:
            switch(input) {
               case 0xF0:
                  device->input_state = SYSEX_MESSAGE;
                  device->input_buffer[0] = input;
                  device->input_count = 1;
                  break;
               case 0xF7:
                  device->input_buffer[device->input_count % 3] = input;
                  device->input_count += 1;
                  midi_input_callbacks(device, device->input_count,
                        device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
                  device->input_state = IDLE;
                  break;
               default:
                  device->input_state = IDLE;
                  device->input_count = 0;
            }
            break;
         default:
            device->input_state = IDLE;
            device->input_count = 0;
            break;
      }
   } else {
      if (device->input_state != IDLE) {
         device->input_buffer[device->input_count % 3] = input;
         uint16_t prev = device->input_count;
         device->input_count += 1;
         switch(prev % 3) {
            case 2:
               midi_input_callbacks(device, device->input_count,
                     device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
               if (device->input_state != SYSEX_MESSAGE) {
                  device->input_count = 1;
               }
               break;
            case 1:
               if (device->input_state == TWO_BYTE_MESSAGE) {
                  midi_input_callbacks(device, device->input_count,
                        device->input_buffer[0], device->input_buffer[1], 0);
                  if (device->input_state != SYSEX_MESSAGE) {
                     device->input_count = 1;
                  }
               }
               break;
            case 0:
            default:
               break;
         }
      }
   }
}

canonical_original_code:
void midi_process_byte(struct _midi_device *device, unsigned char input) {
   if (midi_is_realtime(input)) {
      enum input_state_t state = device->input_state;
      device->input_state = ONE_BYTE_MESSAGE;
      midi_input_callbacks(device, 1, input, 0, 0);
      device->input_state = state;
   } else if (midi_is_statusbyte(input)) {
      if (device->input_state != SYSEX_MESSAGE) {
         device->input_buffer[0] = input;
         device->input_count = 1;
      }
      switch (midi_packet_length(input)) {
         case ONE:
            device->input_state = ONE_BYTE_MESSAGE;;
            midi_input_callbacks(device, 1, input, 0, 0);
            device->input_state = IDLE;
            break;
         case TWO:
            device->input_state = TWO_BYTE_MESSAGE;
            break;
         case THREE:
            device->input_state = THREE_BYTE_MESSAGE;
            break;
         case UNDEFINED:
            switch(input) {
               case 0xF0:
                  device->input_state = SYSEX_MESSAGE;
                  device->input_buffer[0] = input;
                  device->input_count = 1;
                  break;
               case 0xF7:
                  device->input_buffer[device->input_count % 3] = input;
                  device->input_count += 1;
                  midi_input_callbacks(device, device->input_count,
                        device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
                  device->input_state = IDLE;
                  break;
               default:
                  device->input_state = IDLE;
                  device->input_count = 0;
            }
            break;
         default:
            device->input_state = IDLE;
            device->input_count = 0;
            break;
      }
   } else {
      if (device->input_state != IDLE) {
         device->input_buffer[device->input_count % 3] = input;
         unsigned short prev = device->input_count;
         device->input_count += 1;
         switch(prev % 3) {
            case 2:
               midi_input_callbacks(device, device->input_count,
                     device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
               if (device->input_state != SYSEX_MESSAGE) {
                  device->input_count = 1;
               }
               break;
            case 1:
               if (device->input_state == TWO_BYTE_MESSAGE) {
                  midi_input_callbacks(device, device->input_count,
                        device->input_buffer[0], device->input_buffer[1], 0);
                  if (device->input_state != SYSEX_MESSAGE) {
                     device->input_count = 1;
                  }
               }
               break;
            case 0:
            default:
               break;
         }
      }
   }
}

variable_types:
input
unsigned char

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

variable_types:
prev
unsigned short


decompiled_code:
__int64 __fastcall midi_device_process(__int64 a1)
{
void (*v1)(void); // rax
__int64 result; // rax
__int16 v3; // r13
int v4; // ebx
unsigned __int8 v5; // al

v1 = *(void (**)(void))(a1 + 128);
if ( v1 )
v1();
result = bytequeue_length(a1 + 344);
v3 = (unsigned __int8)result;
if ( (_BYTE)result )
{
v4 = 0;
do
{
++v4;
v5 = bytequeue_get(a1 + 344, 0LL);
midi_process_byte(a1, v5);
result = bytequeue_remove(a1 + 344, 1LL);
}
while ( (_WORD)v4 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
void (*v1)(void); // rax
__int64 result; // rax
__int16 v3; // r13
int v4; // ebx
unsigned __int8 v5; // al

v1 = *(void (**)(void))(a1 + 128);
if ( v1 )
v1();
result = bytequeue_length(a1 + 344);
v3 = (unsigned __int8)result;
if ( (_BYTE)result )
{
v4 = 0;
do
{
++v4;
v5 = bytequeue_get(a1 + 344, 0LL);
func4(a1, v5);
result = bytequeue_remove(a1 + 344, 1LL);
}
while ( (_WORD)v4 != v3 );
}
return result;
}

original_code:
void midi_device_process(MidiDevice * device) {
   if(device->pre_input_process_callback)
      device->pre_input_process_callback(device);
   byteQueueIndex_t len = bytequeue_length(&device->input_queue);
   uint16_t i;
   for(i = 0; i < len; i++) {
      uint8_t val = bytequeue_get(&device->input_queue, 0);
      midi_process_byte(device, val);
      bytequeue_remove(&device->input_queue, 1);
   }
}

canonical_original_code:
void midi_device_process(struct _midi_device *device) {
   if(device->pre_input_process_callback)
      device->pre_input_process_callback(device);
   unsigned char len = bytequeue_length(&device->input_queue);
   unsigned short i;
   for(i = 0; i < len; i++) {
      unsigned char val = bytequeue_get(&device->input_queue, 0);
      midi_process_byte(device, val);
      bytequeue_remove(&device->input_queue, 1);
   }
}

variable_types:
len
unsigned char

variable_types:
i
unsigned short

variable_types:
val
unsigned char


original_code:
void import_sysex(uint8_t * buf, int16_t size)
{
 int8_t presetNumber,i;
 uint8_t patchData[16];
 struct z80Patch_t * zp = (struct z80Patch_t *)patchData;
 struct preset_s p,savedP;
 uint16_t tmp;
 if(size!=35 || buf[0]!=0x01 || buf[1]!=0x02 || buf[2]>0x63)
  return;
 presetNumber=buf[2];
 for(i=0;i<16;++i)
  patchData[i]=(buf[i*2+3] & 0x0f) | (buf[i*2+4] << 4);
 tmp=zp->mixer<<10;
 p.continuousParameters[cpVolA]=(65535)-tmp;
 p.continuousParameters[cpVolB]=tmp;
 p.continuousParameters[cpFreqA]=zp->freqA<<10;
 p.continuousParameters[cpFreqB]=zp->freqB<<10;
 p.continuousParameters[cpFreqBFine]=((65535)/2+1)+(zp->fineB<<8);
 p.continuousParameters[cpAPW]=zp->pwA<<9;
 p.continuousParameters[cpBPW]=zp->pwB<<9;
 p.continuousParameters[cpCutoff]=zp->cutoff<<8;
 p.continuousParameters[cpResonance]=zp->reso<<10;
 p.continuousParameters[cpFilEnvAmt]=((65535)/2+1)+(zp->filEnvAmt<<11);
 p.continuousParameters[cpFilRel]=z80EnvCV[zp->filRel]<<8;
 p.continuousParameters[cpFilSus]=zp->filSus<<12;
 p.continuousParameters[cpFilDec]=z80EnvCV[zp->filDec]<<8;
 p.continuousParameters[cpFilAtt]=z80EnvCV[zp->filAtk]<<8;
 p.continuousParameters[cpAmpRel]=z80EnvCV[zp->ampRel]<<8;
 p.continuousParameters[cpAmpSus]=zp->ampSus<<12;
 p.continuousParameters[cpAmpDec]=z80EnvCV[zp->ampDec]<<8;
 p.continuousParameters[cpAmpAtt]=z80EnvCV[zp->ampAtk]<<8;
 p.continuousParameters[cpPModFilEnv]=((65535)/2+1)+(zp->pmodFilEnv<<11);
 p.continuousParameters[cpPModOscB]=zp->pmodOscB<<9;
 p.continuousParameters[cpLFOFreq]=zp->lfoFreq<<10;
 p.continuousParameters[cpLFOAmt]=zp->lfoAmt<<4;
 p.continuousParameters[cpGlide]=(zp->glide)?(0xc000+(zp->glide<<10)):0;
 p.continuousParameters[cpAmpVelocity]=0;
 p.continuousParameters[cpFilVelocity]=0;
 p.steppedParameters[spASaw]=zp->sawA;
 p.steppedParameters[spATri]=zp->triA;
 p.steppedParameters[spASqr]=zp->pulseA;
 p.steppedParameters[spBSaw]=zp->sawB;
 p.steppedParameters[spBTri]=zp->triB;
 p.steppedParameters[spBSqr]=zp->pulseB;
 p.steppedParameters[spSync]=zp->syncA;
 p.steppedParameters[spPModFA]=zp->pmodFreqA;
 p.steppedParameters[spPModFil]=zp->pmodFil;
 p.steppedParameters[spLFOShape]=zp->lfoShape;
 p.steppedParameters[spLFOShift]=0;
 p.steppedParameters[spLFOTargets]=zp->lfoPitch | (zp->lfoPW<<1) | (zp->lfoFil<<2);
 p.steppedParameters[spTrackingShift]=(zp->trackHalf?1:0) + (zp->trackFull?2:0);
 p.steppedParameters[spFilEnvExpo]=0;
 p.steppedParameters[spFilEnvSlow]=1;
 p.steppedParameters[spAmpEnvExpo]=0;
 p.steppedParameters[spAmpEnvSlow]=1;
 p.steppedParameters[spUnison]=zp->unison;
 p.steppedParameters[spAssignerPriority]=apLast;
 p.steppedParameters[spBenderSemitones]=3;
 p.steppedParameters[spBenderTarget]=modVCO;
 p.steppedParameters[spModwheelShift]=2;
 p.steppedParameters[spChromaticPitch]=1;

 {
  savedP=currentPreset;
  currentPreset=p;
  preset_saveCurrent(presetNumber);
  currentPreset=savedP;
 }
}

canonical_original_code:
void import_sysex(unsigned char *buf, short size)
{
 char presetNumber; char i;
 unsigned char patchData[16];
 struct z80Patch_t *zp = (struct z80Patch_t *)patchData;
 struct preset_s p; struct preset_s savedP;
 unsigned short tmp;
 if(size!=35 || buf[0]!=0x01 || buf[1]!=0x02 || buf[2]>0x63)
  return;
 presetNumber=buf[2];
 for(i=0;i<16;++i)
  patchData[i]=(buf[i*2+3] & 0x0f) | (buf[i*2+4] << 4);
 tmp=zp->mixer<<10;
 p.continuousParameters[cpVolA]=(65535)-tmp;
 p.continuousParameters[cpVolB]=tmp;
 p.continuousParameters[cpFreqA]=zp->freqA<<10;
 p.continuousParameters[cpFreqB]=zp->freqB<<10;
 p.continuousParameters[cpFreqBFine]=((65535)/2+1)+(zp->fineB<<8);
 p.continuousParameters[cpAPW]=zp->pwA<<9;
 p.continuousParameters[cpBPW]=zp->pwB<<9;
 p.continuousParameters[cpCutoff]=zp->cutoff<<8;
 p.continuousParameters[cpResonance]=zp->reso<<10;
 p.continuousParameters[cpFilEnvAmt]=((65535)/2+1)+(zp->filEnvAmt<<11);
 p.continuousParameters[cpFilRel]=z80EnvCV[zp->filRel]<<8;
 p.continuousParameters[cpFilSus]=zp->filSus<<12;
 p.continuousParameters[cpFilDec]=z80EnvCV[zp->filDec]<<8;
 p.continuousParameters[cpFilAtt]=z80EnvCV[zp->filAtk]<<8;
 p.continuousParameters[cpAmpRel]=z80EnvCV[zp->ampRel]<<8;
 p.continuousParameters[cpAmpSus]=zp->ampSus<<12;
 p.continuousParameters[cpAmpDec]=z80EnvCV[zp->ampDec]<<8;
 p.continuousParameters[cpAmpAtt]=z80EnvCV[zp->ampAtk]<<8;
 p.continuousParameters[cpPModFilEnv]=((65535)/2+1)+(zp->pmodFilEnv<<11);
 p.continuousParameters[cpPModOscB]=zp->pmodOscB<<9;
 p.continuousParameters[cpLFOFreq]=zp->lfoFreq<<10;
 p.continuousParameters[cpLFOAmt]=zp->lfoAmt<<4;
 p.continuousParameters[cpGlide]=(zp->glide)?(0xc000+(zp->glide<<10)):0;
 p.continuousParameters[cpAmpVelocity]=0;
 p.continuousParameters[cpFilVelocity]=0;
 p.steppedParameters[spASaw]=zp->sawA;
 p.steppedParameters[spATri]=zp->triA;
 p.steppedParameters[spASqr]=zp->pulseA;
 p.steppedParameters[spBSaw]=zp->sawB;
 p.steppedParameters[spBTri]=zp->triB;
 p.steppedParameters[spBSqr]=zp->pulseB;
 p.steppedParameters[spSync]=zp->syncA;
 p.steppedParameters[spPModFA]=zp->pmodFreqA;
 p.steppedParameters[spPModFil]=zp->pmodFil;
 p.steppedParameters[spLFOShape]=zp->lfoShape;
 p.steppedParameters[spLFOShift]=0;
 p.steppedParameters[spLFOTargets]=zp->lfoPitch | (zp->lfoPW<<1) | (zp->lfoFil<<2);
 p.steppedParameters[spTrackingShift]=(zp->trackHalf?1:0) + (zp->trackFull?2:0);
 p.steppedParameters[spFilEnvExpo]=0;
 p.steppedParameters[spFilEnvSlow]=1;
 p.steppedParameters[spAmpEnvExpo]=0;
 p.steppedParameters[spAmpEnvSlow]=1;
 p.steppedParameters[spUnison]=zp->unison;
 p.steppedParameters[spAssignerPriority]=apLast;
 p.steppedParameters[spBenderSemitones]=3;
 p.steppedParameters[spBenderTarget]=modVCO;
 p.steppedParameters[spModwheelShift]=2;
 p.steppedParameters[spChromaticPitch]=1;

 {
  savedP=currentPreset;
  currentPreset=p;
  preset_saveCurrent(presetNumber);
  currentPreset=savedP;
 }
}

variable_types:
buf
unsigned char *

variable_types: size short

variable_types: presetNumber char

variable_types: i char

variable_types:
patchData
unsigned char [16]

variable_types: struct z80Patch_t { unsigned short pwA; unsigned short pmodFilEnv; unsigned short lfoFreq; unsigned short pmodOscB; unsigned short lfoAmt; unsigned short freqB; unsigned short freqA; unsigned short fineB; unsigned short mixer; unsigned short cutoff; unsigned short reso; unsigned short filEnvAmt; unsigned short filRel; unsigned short filSus; unsigned short filDec; unsigned short filAtk; unsigned short ampRel; unsigned short ampSus; unsigned short ampDec; unsigned short ampAtk; unsigned short glide; unsigned short pwB; unsigned short pulseA; unsigned short pulseB; unsigned short trackFull; unsigned short trackHalf; unsigned short lfoShape; unsigned short lfoPitch; unsigned short lfoPW; unsigned short lfoFil; unsigned short sawA; unsigned short triA; unsigned short syncA; unsigned short sawB; unsigned short triB; unsigned short pmodFreqA; unsigned short pmodFil; unsigned short unison; } *

variable_types: struct preset_s { unsigned char steppedParameters[-1]; unsigned short continuousParameters[-1]; unsigned char voicePattern[6]; unsigned short perNoteTuning[12]; }

variable_types:
tmp
unsigned short


decompiled_code:
__int64 __fastcall dac_write(unsigned __int16 a1)
{
mem_write(16385LL, a1 >> 10);
return mem_write(0x4000LL, (unsigned __int8)(a1 >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
mem_write(16385LL, a1 >> 10);
return mem_write(0x4000LL, (unsigned __int8)(a1 >> 2));
}

original_code:
__attribute__ ((noinline)) void dac_write(uint16_t value)
{
 mem_write(0x4001,value>>10);
 mem_write(0x4000,value>>2);
}

canonical_original_code:
void dac_write(unsigned short value)
{
 mem_write(0x4001,value>>10);
 mem_write(0x4000,value>>2);
}

variable_types:
value
unsigned short


decompiled_code:
__int64 uart_init()
{
mem_write(24576LL, 3LL);
mem_write(24576LL, 149LL);
return mem_read(57344LL);
}

canonical_decompiled_code:
__int64 func0()
{
mem_write(24576LL, 3LL);
mem_write(24576LL, 149LL);
return mem_read(57344LL);
}


decompiled_code:
__int64 __fastcall uart_send(unsigned __int8 a1)
{
while ( (mem_read(57344LL) & 2) == 0 )
;
return mem_write(24577LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
while ( (mem_read(57344LL) & 2) == 0 )
;
return mem_write(24577LL, a1);
}

original_code:
void __attribute__ ((noinline)) uart_send(uint8_t data)
{
  uint8_t status;
 do
 {

  {
   status=mem_read(0xe000);
  }
  ;
 }
 while(!(status&0x02));

 {
  mem_write(0x6001,data);
  ;
 }
}

canonical_original_code:
void uart_send(unsigned char data)
{
  unsigned char status;
 do
 {

  {
   status=mem_read(0xe000);
  }
  ;
 }
 while(!(status&0x02));

 {
  mem_write(0x6001,data);
  ;
 }
}

variable_types:
data
unsigned char

variable_types:
status
unsigned char


decompiled_code:
__int64 uart_update()
{
__int64 result; // rax
char v1; // bl
unsigned __int8 v2; // al

result = hardware_getNMIState();
if ( (_BYTE)result )
{
result = mem_read(57344LL);
v1 = result;
if ( (result & 0x80u) != 0LL && (result & 1) != 0 )
{
v2 = mem_read(57345LL);
if ( (v1 & 0x10) != 0 )
result = uart_init();
else
result = synth_uartEvent(v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1; // bl
unsigned __int8 v2; // al

result = hardware_getNMIState();
if ( (_BYTE)result )
{
result = mem_read(57344LL);
v1 = result;
if ( (result & 0x80u) != 0LL && (result & 1) != 0 )
{
v2 = mem_read(57345LL);
if ( (v1 & 0x10) != 0 )
result = func0();
else
result = synth_uartEvent(v2);
}
}
return result;
}

original_code:
void uart_update(void)
{
 if(!hardware_getNMIState())
  return;

 {
  uint8_t data,status;
  status=mem_read(0xe000);
  ;
  if(!(status&0x80))
  {
   return;
  }
  if(!(status&0x01))
  {
   return;
  }
  data=mem_read(0xe001);
  ;
  if(status&0x10)
  {
   uart_init();
   return;
  }
  if(status&0x20)
  {
  }
  synth_uartEvent(data);
 }
}

canonical_original_code:
void uart_update()
{
 if(!hardware_getNMIState())
  return;

 {
  unsigned char data; unsigned char status;
  status=mem_read(0xe000);
  ;
  if(!(status&0x80))
  {
   return;
  }
  if(!(status&0x01))
  {
   return;
  }
  data=mem_read(0xe001);
  ;
  if(status&0x10)
  {
   uart_init();
   return;
  }
  if(status&0x20)
  {
  }
  synth_uartEvent(data);
 }
}


SetEndianness

decompiled_code:
void SetEndianness()
{
g_little_endian = 1;
}

canonical_decompiled_code:
void func0()
{
g_little_endian = 1;
}

original_code:
static void
SetEndianness(void)
{
    unsigned int endian_test = (unsigned int) 0xaabbccdd;
    unsigned char endian_test_char = *(unsigned char *) &endian_test;
    if (endian_test_char == 0xdd)
        g_little_endian = 1;
}

canonical_original_code:
static void SetEndianness()
{
    unsigned int endian_test = (unsigned int) 0xaabbccdd;
    unsigned char endian_test_char = *(unsigned char *) &endian_test;
    if (endian_test_char == 0xdd)
        g_little_endian = 1;
}


decompiled_code:
size_t print_version()
{
fprintf(stdout, "rtf2latex2e %s\n\n", "2-2-2");
fwrite("Copyright (C) 2012 Free Software Foundation, Inc.\n", 1uLL, 0x32uLL, stdout);
fwrite("This is free software; see the source for copying conditions. There is NO\n", 1uLL, 0x4BuLL, stdout);
return fwrite(
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n",
1uLL,
0x4DuLL,
stdout);
}

canonical_decompiled_code:
size_t func1()
{
fprintf(stdout, "rtf2latex2e %s\n\n", "2-2-2");
fwrite("Copyright (C) 2012 Free Software Foundation, Inc.\n", 1uLL, 0x32uLL, stdout);
fwrite("This is free software; see the source for copying conditions. There is NO\n", 1uLL, 0x4BuLL, stdout);
return fwrite(
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n",
1uLL,
0x4DuLL,
stdout);
}

original_code:
static void
print_version(void)
{
    fprintf(stdout, "rtf2latex2e %s\n\n", "2-2-2");
    fprintf(stdout, "Copyright (C) 2012 Free Software Foundation, Inc.\n");
    fprintf(stdout, "This is free software; see the source for copying conditions.  There is NO\n");
    fprintf(stdout, "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
}

canonical_original_code:
static void print_version()
{
    fprintf(stdout, "rtf2latex2e %s\n\n", "2-2-2");
    fprintf(stdout, "Copyright (C) 2012 Free Software Foundation, Inc.\n");
    fprintf(stdout, "This is free software; see the source for copying conditions.  There is NO\n");
    fprintf(stdout, "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
}


decompiled_code:
void __noreturn print_usage()
{
char *v0; // rax
char *v1; // rdx

fprintf(stdout, "rtf2latex2e %s - convert RTF to LaTeX.\n", "2-2-2");
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(" -h display help\n", 1uLL, 0x20uLL, stdout);
fwrite(" -b best attempt at matching RTF formatting\n", 1uLL, 0x3BuLL, stdout);
fwrite(" -f fractional document, omit latex preamble\n", 1uLL, 0x3CuLL, stdout);
fwrite(" -D make a new directory for latex and extracted images\n", 1uLL, 0x47uLL, stdout);
fwrite(" -e # equation conversion options\n", 1uLL, 0x2FuLL, stdout);
fwrite(" -e 1 convert to latex\n", 1uLL, 0x29uLL, stdout);
fwrite(" -e 2 insert image\n", 1uLL, 0x25uLL, stdout);
fwrite(" -e 4 keep intermediate eqn file\n", 1uLL, 0x33uLL, stdout);
fwrite(" -e 8 insert eqn file name in latex document\n", 1uLL, 0x3FuLL, stdout);
fwrite(" -n natural latex formatting ... easiest to edit\n", 1uLL, 0x40uLL, stdout);
fwrite(" -p # paragraph conversion options\n", 1uLL, 0x30uLL, stdout);
fwrite(" -p 1 'heading 1' style -> '\\section{}'\n", 1uLL, 0x3AuLL, stdout);
fwrite(" -p 2 convert indenting\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -p 4 convert space between paragraphs\n", 1uLL, 0x39uLL, stdout);
fwrite(" -p 8 convert line spacing\n", 1uLL, 0x2DuLL, stdout);
fwrite(" -p 16 convert margins\n", 1uLL, 0x28uLL, stdout);
fwrite(" -p 32 convert alignment\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -P path path to preferred preference directory\n", 1uLL, 0x3AuLL, stdout);
fwrite(" -t # text conversion options\n", 1uLL, 0x2BuLL, stdout);
fwrite(" -t 1 convert text size\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -t 2 convert text color\n", 1uLL, 0x2BuLL, stdout);
fwrite(" -t 4 convert text formatting\n", 1uLL, 0x30uLL, stdout);
fwrite(" -t 8 replace tabs with spaces\n", 1uLL, 0x31uLL, stdout);
fwrite(" -T # table conversion options\n", 1uLL, 0x2CuLL, stdout);
fwrite(" -T 1 keep column widths\n", 1uLL, 0x2BuLL, stdout);
fwrite(" -T 2 keep column alignment\n", 1uLL, 0x2EuLL, stdout);
fwrite(" -v version information\n", 1uLL, 0x27uLL, stdout);
fputc(10, stdout);
fwrite("Examples:\n", 1uLL, 0xAuLL, stdout);
fwrite(" rtf2latex2e foo convert foo.rtf to foo.tex\n", 1uLL, 0x3AuLL, stdout);
fwrite(" rtf2latex2e -n foo minimal mark-up\n", 1uLL, 0x2FuLL, stdout);
fwrite(" rtf2latex2e -e 15 foo help identify failed equation conversion\n", 1uLL, 0x48uLL, stdout);
fwrite(" rtf2latex2e foo-eqn003.eqn debug third equation (after above command)\n", 1uLL, 0x4AuLL, stdout);
fwrite(" rtf2latex2e -D foo put foo.tex and images in foo-latex dir\n", 1uLL, 0x47uLL, stdout);
fwrite(" rtf2latex2e foo.rtfd convert to foo.rtfd/TXT.tex\n", 1uLL, 0x3BuLL, stdout);
fputc(10, stdout);
fwrite("Preference Directory:\n", 1uLL, 0x16uLL, stdout);
fprintf(stdout, " Default = '%s'\n", "/usr/local/share/rtf2latex2e");
v0 = getenv("RTFPATH");
v1 = "not defined";
if ( v0 )
v1 = getenv("RTFPATH");
fprintf(stdout, " $RTFPATH = '%s'\n", v1);
fputc(10, stdout);
fwrite("Report bugs at http://sourceforge.net/projects/rtf2latex2e/\n\n", 1uLL, 0x3DuLL, stdout);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
char *v0; // rax
char *v1; // rdx

fprintf(stdout, "rtf2latex2e %s - convert RTF to LaTeX.\n", "2-2-2");
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(" -h display help\n", 1uLL, 0x20uLL, stdout);
fwrite(" -b best attempt at matching RTF formatting\n", 1uLL, 0x3BuLL, stdout);
fwrite(" -f fractional document, omit latex preamble\n", 1uLL, 0x3CuLL, stdout);
fwrite(" -D make a new directory for latex and extracted images\n", 1uLL, 0x47uLL, stdout);
fwrite(" -e # equation conversion options\n", 1uLL, 0x2FuLL, stdout);
fwrite(" -e 1 convert to latex\n", 1uLL, 0x29uLL, stdout);
fwrite(" -e 2 insert image\n", 1uLL, 0x25uLL, stdout);
fwrite(" -e 4 keep intermediate eqn file\n", 1uLL, 0x33uLL, stdout);
fwrite(" -e 8 insert eqn file name in latex document\n", 1uLL, 0x3FuLL, stdout);
fwrite(" -n natural latex formatting ... easiest to edit\n", 1uLL, 0x40uLL, stdout);
fwrite(" -p # paragraph conversion options\n", 1uLL, 0x30uLL, stdout);
fwrite(" -p 1 'heading 1' style -> '\\section{}'\n", 1uLL, 0x3AuLL, stdout);
fwrite(" -p 2 convert indenting\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -p 4 convert space between paragraphs\n", 1uLL, 0x39uLL, stdout);
fwrite(" -p 8 convert line spacing\n", 1uLL, 0x2DuLL, stdout);
fwrite(" -p 16 convert margins\n", 1uLL, 0x28uLL, stdout);
fwrite(" -p 32 convert alignment\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -P path path to preferred preference directory\n", 1uLL, 0x3AuLL, stdout);
fwrite(" -t # text conversion options\n", 1uLL, 0x2BuLL, stdout);
fwrite(" -t 1 convert text size\n", 1uLL, 0x2AuLL, stdout);
fwrite(" -t 2 convert text color\n", 1uLL, 0x2BuLL, stdout);
fwrite(" -t 4 convert text formatting\n", 1uLL, 0x30uLL, stdout);
fwrite(" -t 8 replace tabs with spaces\n", 1uLL, 0x31uLL, stdout);
fwrite(" -T # table conversion options\n", 1uLL, 0x2CuLL, stdout);
fwrite(" -T 1 keep column widths\n", 1uLL, 0x2BuLL, stdout);
fwrite(" -T 2 keep column alignment\n", 1uLL, 0x2EuLL, stdout);
fwrite(" -v version information\n", 1uLL, 0x27uLL, stdout);
fputc(10, stdout);
fwrite("Examples:\n", 1uLL, 0xAuLL, stdout);
fwrite(" rtf2latex2e foo convert foo.rtf to foo.tex\n", 1uLL, 0x3AuLL, stdout);
fwrite(" rtf2latex2e -n foo minimal mark-up\n", 1uLL, 0x2FuLL, stdout);
fwrite(" rtf2latex2e -e 15 foo help identify failed equation conversion\n", 1uLL, 0x48uLL, stdout);
fwrite(" rtf2latex2e foo-eqn003.eqn debug third equation (after above command)\n", 1uLL, 0x4AuLL, stdout);
fwrite(" rtf2latex2e -D foo put foo.tex and images in foo-latex dir\n", 1uLL, 0x47uLL, stdout);
fwrite(" rtf2latex2e foo.rtfd convert to foo.rtfd/TXT.tex\n", 1uLL, 0x3BuLL, stdout);
fputc(10, stdout);
fwrite("Preference Directory:\n", 1uLL, 0x16uLL, stdout);
fprintf(stdout, " Default = '%s'\n", "/usr/local/share/rtf2latex2e");
v0 = getenv("RTFPATH");
v1 = "not defined";
if ( v0 )
v1 = getenv("RTFPATH");
fprintf(stdout, " $RTFPATH = '%s'\n", v1);
fputc(10, stdout);
fwrite("Report bugs at http://sourceforge.net/projects/rtf2latex2e/\n\n", 1uLL, 0x3DuLL, stdout);
exit(1);
}

original_code:
static void
print_usage(void)
{
    fprintf(stdout, "rtf2latex2e %s - convert RTF to LaTeX.\n", "2-2-2");
    fprintf(stdout, "Options:\n");
    fprintf(stdout, "  -h               display help\n");
    fprintf(stdout, "  -b               best attempt at matching RTF formatting\n");
    fprintf(stdout, "  -f               fractional document, omit latex preamble\n");
    fprintf(stdout, "  -D               make a new directory for latex and extracted images\n");
    fprintf(stdout, "  -e #             equation conversion options\n");
    fprintf(stdout, "      -e 1              convert to latex\n");
    fprintf(stdout, "      -e 2              insert image\n");
    fprintf(stdout, "      -e 4              keep intermediate eqn file\n");
    fprintf(stdout, "      -e 8              insert eqn file name in latex document\n");
    fprintf(stdout, "  -n               natural latex formatting ... easiest to edit\n");
    fprintf(stdout, "  -p #             paragraph conversion options\n");
    fprintf(stdout, "      -p 1              'heading 1' style -> '\\section{}'\n");
    fprintf(stdout, "      -p 2              convert indenting\n");
    fprintf(stdout, "      -p 4              convert space between paragraphs\n");
    fprintf(stdout, "      -p 8              convert line spacing\n");
    fprintf(stdout, "      -p 16             convert margins\n");
    fprintf(stdout, "      -p 32             convert alignment\n");
    fprintf(stdout, "  -P path          path to preferred preference directory\n");
    fprintf(stdout, "  -t #             text conversion options\n");
    fprintf(stdout, "      -t 1              convert text size\n");
    fprintf(stdout, "      -t 2              convert text color\n");
    fprintf(stdout, "      -t 4              convert text formatting\n");
    fprintf(stdout, "      -t 8              replace tabs with spaces\n");
    fprintf(stdout, "  -T #             table conversion options\n");
    fprintf(stdout, "      -T 1              keep column widths\n");
    fprintf(stdout, "      -T 2              keep column alignment\n");
    fprintf(stdout, "  -v               version information\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "Examples:\n");
    fprintf(stdout, "  rtf2latex2e foo              convert foo.rtf to foo.tex\n");
    fprintf(stdout, "  rtf2latex2e -n foo           minimal mark-up\n");
    fprintf(stdout, "  rtf2latex2e -e 15 foo        help identify failed equation conversion\n");
    fprintf(stdout, "  rtf2latex2e foo-eqn003.eqn   debug third equation (after above command)\n");
    fprintf(stdout, "  rtf2latex2e -D foo           put foo.tex and images in foo-latex dir\n");
    fprintf(stdout, "  rtf2latex2e foo.rtfd         convert to foo.rtfd/TXT.tex\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "Preference Directory:\n");
    fprintf(stdout, "  Default  = '%s'\n", ("/usr/local/share/rtf2latex2e") ? "/usr/local/share/rtf2latex2e" : "not defined");
    fprintf(stdout, "  $RTFPATH = '%s'\n", (getenv("RTFPATH")) ? getenv("RTFPATH") : "not defined");
    fprintf(stdout, "\n");
    fprintf(stdout, "Report bugs at http://sourceforge.net/projects/rtf2latex2e/\n\n");
    exit(1);
}

canonical_original_code:
static void print_usage()
{
    fprintf(stdout, "rtf2latex2e %s - convert RTF to LaTeX.\n", "2-2-2");
    fprintf(stdout, "Options:\n");
    fprintf(stdout, "  -h               display help\n");
    fprintf(stdout, "  -b               best attempt at matching RTF formatting\n");
    fprintf(stdout, "  -f               fractional document, omit latex preamble\n");
    fprintf(stdout, "  -D               make a new directory for latex and extracted images\n");
    fprintf(stdout, "  -e #             equation conversion options\n");
    fprintf(stdout, "      -e 1              convert to latex\n");
    fprintf(stdout, "      -e 2              insert image\n");
    fprintf(stdout, "      -e 4              keep intermediate eqn file\n");
    fprintf(stdout, "      -e 8              insert eqn file name in latex document\n");
    fprintf(stdout, "  -n               natural latex formatting ... easiest to edit\n");
    fprintf(stdout, "  -p #             paragraph conversion options\n");
    fprintf(stdout, "      -p 1              'heading 1' style -> '\\section{}'\n");
    fprintf(stdout, "      -p 2              convert indenting\n");
    fprintf(stdout, "      -p 4              convert space between paragraphs\n");
    fprintf(stdout, "      -p 8              convert line spacing\n");
    fprintf(stdout, "      -p 16             convert margins\n");
    fprintf(stdout, "      -p 32             convert alignment\n");
    fprintf(stdout, "  -P path          path to preferred preference directory\n");
    fprintf(stdout, "  -t #             text conversion options\n");
    fprintf(stdout, "      -t 1              convert text size\n");
    fprintf(stdout, "      -t 2              convert text color\n");
    fprintf(stdout, "      -t 4              convert text formatting\n");
    fprintf(stdout, "      -t 8              replace tabs with spaces\n");
    fprintf(stdout, "  -T #             table conversion options\n");
    fprintf(stdout, "      -T 1              keep column widths\n");
    fprintf(stdout, "      -T 2              keep column alignment\n");
    fprintf(stdout, "  -v               version information\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "Examples:\n");
    fprintf(stdout, "  rtf2latex2e foo              convert foo.rtf to foo.tex\n");
    fprintf(stdout, "  rtf2latex2e -n foo           minimal mark-up\n");
    fprintf(stdout, "  rtf2latex2e -e 15 foo        help identify failed equation conversion\n");
    fprintf(stdout, "  rtf2latex2e foo-eqn003.eqn   debug third equation (after above command)\n");
    fprintf(stdout, "  rtf2latex2e -D foo           put foo.tex and images in foo-latex dir\n");
    fprintf(stdout, "  rtf2latex2e foo.rtfd         convert to foo.rtfd/TXT.tex\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "Preference Directory:\n");
    fprintf(stdout, "  Default  = '%s'\n", ("/usr/local/share/rtf2latex2e") ? "/usr/local/share/rtf2latex2e" : "not defined");
    fprintf(stdout, "  $RTFPATH = '%s'\n", (getenv("RTFPATH")) ? getenv("RTFPATH") : "not defined");
    fprintf(stdout, "\n");
    fprintf(stdout, "Report bugs at http://sourceforge.net/projects/rtf2latex2e/\n\n");
    exit(1);
}