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)
{
unsigned __int8 *v3; // rbx
__int64 v4; // r12
__int64 result; // rax

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

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

if ( a2 )
{
v3 = a3;
v4 = (__int64)&a3[(unsigned __int8)(a2 - 1) + 1];
do
result = bytequeue_enqueue(a1 + 344, *v3++);
while ( v3 != (unsigned __int8 *)v4 );
}
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

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

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


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
{
v5 = bytequeue_get(a1 + 344, 0LL);
midi_process_byte(a1, v5);
result = bytequeue_remove(a1 + 344, 1LL);
++v4;
}
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
{
v5 = bytequeue_get(a1 + 344, 0LL);
func4(a1, v5);
result = bytequeue_remove(a1 + 344, 1LL);
++v4;
}
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


decompiled_code:
void __fastcall import_sysex(_BYTE *a1, __int16 a2)
{
unsigned __int8 v2; // cl
__int64 v3; // rax
__int16 v4; // r12
__int16 v5; // ax
unsigned __int8 v6; // dl
bool v7; // bp
bool v8; // bl
char v9; // r13
bool v10; // r11
bool v11; // r10
bool v12; // r9
bool v13; // r8
char v14; // si
bool v15; // al
unsigned __int16 v16; // [rsp+0h] [rbp-F6h]
__int16 v17; // [rsp+4h] [rbp-F2h]
__int16 v18; // [rsp+6h] [rbp-F0h]
__int16 v19; // [rsp+8h] [rbp-EEh]
__int16 v20; // [rsp+Ah] [rbp-ECh]
__int16 v21; // [rsp+Ch] [rbp-EAh]
__int16 v22; // [rsp+Eh] [rbp-E8h]
__int16 v23; // [rsp+10h] [rbp-E6h]
__int16 v24; // [rsp+12h] [rbp-E4h]
__int16 v25; // [rsp+14h] [rbp-E2h]
__int16 v26; // [rsp+16h] [rbp-E0h]
__int16 v27; // [rsp+18h] [rbp-DEh]
__int16 v28; // [rsp+1Ah] [rbp-DCh]
__int16 v29; // [rsp+1Ch] [rbp-DAh]
__int16 v30; // [rsp+1Eh] [rbp-D8h]
__int16 v31; // [rsp+20h] [rbp-D6h]
__int16 v32; // [rsp+22h] [rbp-D4h]
__int16 v33; // [rsp+24h] [rbp-D2h]
__int16 v34; // [rsp+26h] [rbp-D0h]
__int16 v35; // [rsp+28h] [rbp-CEh]
__int16 v36; // [rsp+2Ah] [rbp-CCh]
char v37; // [rsp+2Dh] [rbp-C9h]
__m128i v38; // [rsp+2Eh] [rbp-C8h] BYREF
__m128i v39; // [rsp+3Eh] [rbp-B8h] BYREF
__m128i v40; // [rsp+4Eh] [rbp-A8h] BYREF
__m128i v41; // [rsp+5Eh] [rbp-98h] BYREF
__m128i v42; // [rsp+6Eh] [rbp-88h] BYREF
__m128i v43; // [rsp+7Eh] [rbp-78h] BYREF
__m128i v44; // [rsp+8Eh] [rbp-68h] BYREF
int v45; // [rsp+9Eh] [rbp-58h]
__int16 v46; // [rsp+AEh] [rbp-48h]
unsigned __int16 v47; // [rsp+B0h] [rbp-46h]
unsigned __int16 v48; // [rsp+B2h] [rbp-44h]
unsigned __int16 v49; // [rsp+B4h] [rbp-42h]
unsigned __int16 v50; // [rsp+B6h] [rbp-40h]
unsigned __int8 v51; // [rsp+B8h] [rbp-3Eh]
unsigned __int8 v52; // [rsp+B9h] [rbp-3Dh]
unsigned __int8 v53; // [rsp+BAh] [rbp-3Ch]
unsigned __int8 v54; // [rsp+BBh] [rbp-3Bh]
unsigned __int8 v55; // [rsp+BCh] [rbp-3Ah]
unsigned __int8 v56; // [rsp+BDh] [rbp-39h]
unsigned __int8 v57; // [rsp+BEh] [rbp-38h]
char v58; // [rsp+BFh] [rbp-37h]

if ( a2 == 35 && *a1 == 1 && a1[1] == 2 )
{
v2 = a1[2];
v3 = 0LL;
if ( v2 <= 0x63u )
{
do
{
*((_BYTE *)&v46 + v3) = (16 * a1[2 * v3 + 4]) | a1[2 * v3 + 3] & 0xF;
++v3;
}
while ( v3 != 16 );
v4 = v49 >> 7 << 10;
v17 = v48 >> 6 << 10;
v18 = (unsigned __int8)v48 << 10;
v19 = ((v49 & 0x7F) << 8) + 0x8000;
v20 = (unsigned __int8)v46 << 9;
v21 = v56 << 9;
v22 = (v50 & 0x7F) << 8;
v23 = v50 >> 7 << 10;
v24 = ((v51 & 0xF) << 11) + 0x8000;
v25 = (unsigned __int8)z80EnvCV[v51 >> 4] << 8;
v26 = v52 << 12;
v27 = (unsigned __int8)z80EnvCV[v52 >> 4] << 8;
v28 = (unsigned __int8)z80EnvCV[v53 & 0xF] << 8;
v29 = (unsigned __int8)z80EnvCV[v53 >> 4] << 8;
v30 = v54 << 12;
v31 = (unsigned __int8)z80EnvCV[v54 >> 4] << 8;
v5 = v55;
v32 = (unsigned __int8)z80EnvCV[v55 & 0xF] << 8;
v33 = ((16 * v46) & 0x7800) + 0x8000;
v34 = (unsigned __int8)v47 << 9;
v35 = ((HIBYTE(v46) >> 3) & 0xF) << 10;
v36 = (v47 >> 3) & 0x1F0;
v16 = 0;
if ( (v55 & 0xF0) != 0 )
{
LOBYTE(v5) = v55 >> 4;
v16 = (v5 << 10) - 0x4000;
}
v6 = v57;
v37 = v56 >> 7;
v7 = (v58 & 4) != 0;
v8 = (v58 & 8) != 0;
v9 = v57 & 1;
v10 = (v58 & 2) != 0;
v11 = (v58 & 0x10) != 0;
v12 = (v58 & 0x20) != 0;
v13 = (v57 & 8) != 0;
v14 = ((v57 & 0x10) != 0) | (2 * ((v57 & 0x20) != 0)) | (4 * ((v57 & 0x40) != 0));
v15 = (v58 & 0x40) != 0;
v38 = _mm_loadu_si128((const __m128i *)&currentPreset);
v39 = _mm_loadu_si128((const __m128i *)&currentPreset + 1);
v40 = _mm_loadu_si128((const __m128i *)&currentPreset + 2);
v41 = _mm_loadu_si128((const __m128i *)&currentPreset + 3);
v42 = _mm_loadu_si128((const __m128i *)&currentPreset + 4);
v43 = _mm_loadu_si128((const __m128i *)&currentPreset + 5);
v44 = _mm_loadu_si128((const __m128i *)&currentPreset + 6);
v45 = *((_DWORD *)&currentPreset + 28);
currentPreset = v57 >> 7;
*((_BYTE *)&currentPreset + 1) = v58 & 1;
*((_BYTE *)&currentPreset + 2) = v37;
*((_BYTE *)&currentPreset + 3) = v7;
*((_BYTE *)&currentPreset + 4) = v8;
*((_BYTE *)&currentPreset + 5) = v9;
*((_BYTE *)&currentPreset + 6) = v10;
*((_BYTE *)&currentPreset + 7) = v11;
*((_BYTE *)&currentPreset + 8) = v12;
*(_WORD *)((char *)&currentPreset + 9) = v13;
*((_BYTE *)&currentPreset + 11) = v14;
*((_WORD *)&currentPreset + 6) = ((v6 & 4) != 0) | v6 & 2;
*((_BYTE *)&currentPreset + 14) = 1;
*((_BYTE *)&currentPreset + 15) = 0;
*((_BYTE *)&currentPreset + 17) = v15;
*((_BYTE *)&currentPreset + 18) = 0;
*((_BYTE *)&currentPreset + 19) = 3;
*((_BYTE *)&currentPreset + 20) = 1;
*((_BYTE *)&currentPreset + 21) = 2;
*((_BYTE *)&currentPreset + 22) = 1;
*((_BYTE *)&currentPreset + 25) = 1;
*((_WORD *)&currentPreset + 13) = v17;
*((_WORD *)&currentPreset + 14) = ~v4;
*((_WORD *)&currentPreset + 15) = v20;
*((_WORD *)&currentPreset + 16) = v18;
*((_WORD *)&currentPreset + 17) = v4;
*((_WORD *)&currentPreset + 18) = v21;
*((_WORD *)&currentPreset + 19) = v19;
*((_WORD *)&currentPreset + 20) = v22;
*((_WORD *)&currentPreset + 21) = v23;
*((_WORD *)&currentPreset + 22) = v24;
*((_WORD *)&currentPreset + 23) = v25;
*((_WORD *)&currentPreset + 24) = v26;
*((_WORD *)&currentPreset + 25) = v27;
*((_WORD *)&currentPreset + 26) = v28;
*((_WORD *)&currentPreset + 27) = v29;
*((_WORD *)&currentPreset + 28) = v30;
*((_WORD *)&currentPreset + 29) = v31;
*((_WORD *)&currentPreset + 30) = v32;
*((_WORD *)&currentPreset + 31) = v33;
*((_WORD *)&currentPreset + 32) = v34;
*((_WORD *)&currentPreset + 33) = v35;
*((_WORD *)&currentPreset + 34) = v36;
*(_DWORD *)((char *)&currentPreset + 70) = v16;
*((_WORD *)&currentPreset + 37) = 0;
preset_saveCurrent((unsigned __int16)(char)v2);
currentPreset = _mm_loadu_si128(&v38);
*((__m128i *)&currentPreset + 1) = _mm_loadu_si128(&v39);
*((__m128i *)&currentPreset + 2) = _mm_loadu_si128(&v40);
*((__m128i *)&currentPreset + 3) = _mm_loadu_si128(&v41);
*((__m128i *)&currentPreset + 4) = _mm_loadu_si128(&v42);
*((__m128i *)&currentPreset + 5) = _mm_loadu_si128(&v43);
*((__m128i *)&currentPreset + 6) = _mm_loadu_si128(&v44);
*((_DWORD *)&currentPreset + 28) = v45;
}
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1, __int16 a2)
{
unsigned __int8 v2; // cl
__int64 v3; // rax
__int16 v4; // r12
__int16 v5; // ax
unsigned __int8 v6; // dl
bool v7; // bp
bool v8; // bl
char v9; // r13
bool v10; // r11
bool v11; // r10
bool v12; // r9
bool v13; // r8
char v14; // si
bool v15; // al
unsigned __int16 v16; // [rsp+0h] [rbp-F6h]
__int16 v17; // [rsp+4h] [rbp-F2h]
__int16 v18; // [rsp+6h] [rbp-F0h]
__int16 v19; // [rsp+8h] [rbp-EEh]
__int16 v20; // [rsp+Ah] [rbp-ECh]
__int16 v21; // [rsp+Ch] [rbp-EAh]
__int16 v22; // [rsp+Eh] [rbp-E8h]
__int16 v23; // [rsp+10h] [rbp-E6h]
__int16 v24; // [rsp+12h] [rbp-E4h]
__int16 v25; // [rsp+14h] [rbp-E2h]
__int16 v26; // [rsp+16h] [rbp-E0h]
__int16 v27; // [rsp+18h] [rbp-DEh]
__int16 v28; // [rsp+1Ah] [rbp-DCh]
__int16 v29; // [rsp+1Ch] [rbp-DAh]
__int16 v30; // [rsp+1Eh] [rbp-D8h]
__int16 v31; // [rsp+20h] [rbp-D6h]
__int16 v32; // [rsp+22h] [rbp-D4h]
__int16 v33; // [rsp+24h] [rbp-D2h]
__int16 v34; // [rsp+26h] [rbp-D0h]
__int16 v35; // [rsp+28h] [rbp-CEh]
__int16 v36; // [rsp+2Ah] [rbp-CCh]
char v37; // [rsp+2Dh] [rbp-C9h]
__m128i v38; // [rsp+2Eh] [rbp-C8h] BYREF
__m128i v39; // [rsp+3Eh] [rbp-B8h] BYREF
__m128i v40; // [rsp+4Eh] [rbp-A8h] BYREF
__m128i v41; // [rsp+5Eh] [rbp-98h] BYREF
__m128i v42; // [rsp+6Eh] [rbp-88h] BYREF
__m128i v43; // [rsp+7Eh] [rbp-78h] BYREF
__m128i v44; // [rsp+8Eh] [rbp-68h] BYREF
int v45; // [rsp+9Eh] [rbp-58h]
__int16 v46; // [rsp+AEh] [rbp-48h]
unsigned __int16 v47; // [rsp+B0h] [rbp-46h]
unsigned __int16 v48; // [rsp+B2h] [rbp-44h]
unsigned __int16 v49; // [rsp+B4h] [rbp-42h]
unsigned __int16 v50; // [rsp+B6h] [rbp-40h]
unsigned __int8 v51; // [rsp+B8h] [rbp-3Eh]
unsigned __int8 v52; // [rsp+B9h] [rbp-3Dh]
unsigned __int8 v53; // [rsp+BAh] [rbp-3Ch]
unsigned __int8 v54; // [rsp+BBh] [rbp-3Bh]
unsigned __int8 v55; // [rsp+BCh] [rbp-3Ah]
unsigned __int8 v56; // [rsp+BDh] [rbp-39h]
unsigned __int8 v57; // [rsp+BEh] [rbp-38h]
char v58; // [rsp+BFh] [rbp-37h]

if ( a2 == 35 && *a1 == 1 && a1[1] == 2 )
{
v2 = a1[2];
v3 = 0LL;
if ( v2 <= 0x63u )
{
do
{
*((_BYTE *)&v46 + v3) = (16 * a1[2 * v3 + 4]) | a1[2 * v3 + 3] & 0xF;
++v3;
}
while ( v3 != 16 );
v4 = v49 >> 7 << 10;
v17 = v48 >> 6 << 10;
v18 = (unsigned __int8)v48 << 10;
v19 = ((v49 & 0x7F) << 8) + 0x8000;
v20 = (unsigned __int8)v46 << 9;
v21 = v56 << 9;
v22 = (v50 & 0x7F) << 8;
v23 = v50 >> 7 << 10;
v24 = ((v51 & 0xF) << 11) + 0x8000;
v25 = (unsigned __int8)z80EnvCV[v51 >> 4] << 8;
v26 = v52 << 12;
v27 = (unsigned __int8)z80EnvCV[v52 >> 4] << 8;
v28 = (unsigned __int8)z80EnvCV[v53 & 0xF] << 8;
v29 = (unsigned __int8)z80EnvCV[v53 >> 4] << 8;
v30 = v54 << 12;
v31 = (unsigned __int8)z80EnvCV[v54 >> 4] << 8;
v5 = v55;
v32 = (unsigned __int8)z80EnvCV[v55 & 0xF] << 8;
v33 = ((16 * v46) & 0x7800) + 0x8000;
v34 = (unsigned __int8)v47 << 9;
v35 = ((HIBYTE(v46) >> 3) & 0xF) << 10;
v36 = (v47 >> 3) & 0x1F0;
v16 = 0;
if ( (v55 & 0xF0) != 0 )
{
LOBYTE(v5) = v55 >> 4;
v16 = (v5 << 10) - 0x4000;
}
v6 = v57;
v37 = v56 >> 7;
v7 = (v58 & 4) != 0;
v8 = (v58 & 8) != 0;
v9 = v57 & 1;
v10 = (v58 & 2) != 0;
v11 = (v58 & 0x10) != 0;
v12 = (v58 & 0x20) != 0;
v13 = (v57 & 8) != 0;
v14 = ((v57 & 0x10) != 0) | (2 * ((v57 & 0x20) != 0)) | (4 * ((v57 & 0x40) != 0));
v15 = (v58 & 0x40) != 0;
v38 = _mm_loadu_si128((const __m128i *)&currentPreset);
v39 = _mm_loadu_si128((const __m128i *)&currentPreset + 1);
v40 = _mm_loadu_si128((const __m128i *)&currentPreset + 2);
v41 = _mm_loadu_si128((const __m128i *)&currentPreset + 3);
v42 = _mm_loadu_si128((const __m128i *)&currentPreset + 4);
v43 = _mm_loadu_si128((const __m128i *)&currentPreset + 5);
v44 = _mm_loadu_si128((const __m128i *)&currentPreset + 6);
v45 = *((_DWORD *)&currentPreset + 28);
currentPreset = v57 >> 7;
*((_BYTE *)&currentPreset + 1) = v58 & 1;
*((_BYTE *)&currentPreset + 2) = v37;
*((_BYTE *)&currentPreset + 3) = v7;
*((_BYTE *)&currentPreset + 4) = v8;
*((_BYTE *)&currentPreset + 5) = v9;
*((_BYTE *)&currentPreset + 6) = v10;
*((_BYTE *)&currentPreset + 7) = v11;
*((_BYTE *)&currentPreset + 8) = v12;
*(_WORD *)((char *)&currentPreset + 9) = v13;
*((_BYTE *)&currentPreset + 11) = v14;
*((_WORD *)&currentPreset + 6) = ((v6 & 4) != 0) | v6 & 2;
*((_BYTE *)&currentPreset + 14) = 1;
*((_BYTE *)&currentPreset + 15) = 0;
*((_BYTE *)&currentPreset + 17) = v15;
*((_BYTE *)&currentPreset + 18) = 0;
*((_BYTE *)&currentPreset + 19) = 3;
*((_BYTE *)&currentPreset + 20) = 1;
*((_BYTE *)&currentPreset + 21) = 2;
*((_BYTE *)&currentPreset + 22) = 1;
*((_BYTE *)&currentPreset + 25) = 1;
*((_WORD *)&currentPreset + 13) = v17;
*((_WORD *)&currentPreset + 14) = ~v4;
*((_WORD *)&currentPreset + 15) = v20;
*((_WORD *)&currentPreset + 16) = v18;
*((_WORD *)&currentPreset + 17) = v4;
*((_WORD *)&currentPreset + 18) = v21;
*((_WORD *)&currentPreset + 19) = v19;
*((_WORD *)&currentPreset + 20) = v22;
*((_WORD *)&currentPreset + 21) = v23;
*((_WORD *)&currentPreset + 22) = v24;
*((_WORD *)&currentPreset + 23) = v25;
*((_WORD *)&currentPreset + 24) = v26;
*((_WORD *)&currentPreset + 25) = v27;
*((_WORD *)&currentPreset + 26) = v28;
*((_WORD *)&currentPreset + 27) = v29;
*((_WORD *)&currentPreset + 28) = v30;
*((_WORD *)&currentPreset + 29) = v31;
*((_WORD *)&currentPreset + 30) = v32;
*((_WORD *)&currentPreset + 31) = v33;
*((_WORD *)&currentPreset + 32) = v34;
*((_WORD *)&currentPreset + 33) = v35;
*((_WORD *)&currentPreset + 34) = v36;
*(_DWORD *)((char *)&currentPreset + 70) = v16;
*((_WORD *)&currentPreset + 37) = 0;
preset_saveCurrent((unsigned __int16)(char)v2);
currentPreset = _mm_loadu_si128(&v38);
*((__m128i *)&currentPreset + 1) = _mm_loadu_si128(&v39);
*((__m128i *)&currentPreset + 2) = _mm_loadu_si128(&v40);
*((__m128i *)&currentPreset + 3) = _mm_loadu_si128(&v41);
*((__m128i *)&currentPreset + 4) = _mm_loadu_si128(&v42);
*((__m128i *)&currentPreset + 5) = _mm_loadu_si128(&v43);
*((__m128i *)&currentPreset + 6) = _mm_loadu_si128(&v44);
*((_DWORD *)&currentPreset + 28) = v45;
}
}
}

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


decompiled_code:
__int64 __fastcall identify_filename(const char *a1)
{
int v1; // eax
int v2; // ebp
bool v3; // zf
int v4; // edx
__int64 result; // rax
const char *v6; // rbx
int v7; // edx
int v8; // edx

if ( !a1 )
return 4LL;
v1 = strlen(a1);
v2 = v1;
v3 = v1 == 5;
if ( v1 <= 5 )
{
result = 4LL;
if ( !v3 )
return result;
}
else
{
v4 = strcasecmp(&a1[v1 - 5], ".rtfd");
result = 2LL;
if ( !v4 )
return result;
}
v6 = &a1[v2 - 4];
v7 = strcasecmp(v6, ".rtf");
result = 0LL;
if ( v7 )
{
v8 = strcasecmp(v6, ".eqn");
result = 1LL;
if ( v8 )
result = 3 - ((unsigned int)(strcasecmp(v6, ".rqn") == 0) - 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
int v1; // eax
int v2; // ebp
bool v3; // zf
int v4; // edx
__int64 result; // rax
const char *v6; // rbx
int v7; // edx
int v8; // edx

if ( !a1 )
return 4LL;
v1 = strlen(a1);
v2 = v1;
v3 = v1 == 5;
if ( v1 <= 5 )
{
result = 4LL;
if ( !v3 )
return result;
}
else
{
v4 = strcasecmp(&a1[v1 - 5], ".rtfd");
result = 2LL;
if ( !v4 )
return result;
}
v6 = &a1[v2 - 4];
v7 = strcasecmp(v6, ".rtf");
result = 0LL;
if ( v7 )
{
v8 = strcasecmp(v6, ".eqn");
result = 1LL;
if ( v8 )
result = 3 - ((unsigned int)(strcasecmp(v6, ".rqn") == 0) - 1);
}
return result;
}

original_code:
static enum INPUT_FILE_TYPE identify_filename(char *name)
{
    int len;
    if (!name) return TYPE_UNKNOWN;
    len = strlen(name);
    if (len > 5 && strcasecmp(name+len-5,".rtfd")==0)
        return TYPE_RTFD;
    if (len > 4 && strcasecmp(name+len-4,".rtf")==0)
        return TYPE_RTF;
    if (len > 4 && strcasecmp(name+len-4,".eqn")==0)
        return TYPE_EQN;
    if (len > 4 && strcasecmp(name+len-4,".rqn")==0)
        return TYPE_RAWEQN;
    return TYPE_UNKNOWN;
}

variable_types:
name
char *

variable_types: len int

return_type: enum INPUT_FILE_TYPE { TYPE_RTF=0, TYPE_EQN=1, TYPE_RTFD=2, TYPE_RAWEQN=3, TYPE_UNKNOWN=4 }


decompiled_code:
char *__fastcall short_name(char *s)
{
char *v1; // rax
char *result; // rax

v1 = strrchr(s, 47);
if ( v1 )
result = strdup(v1 + 1);
else
result = strdup(s);
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *s)
{
char *v1; // rax
char *result; // rax

v1 = strrchr(s, 47);
if ( v1 )
result = strdup(v1 + 1);
else
result = strdup(s);
return result;
}

original_code:
static char * short_name(char *path)
{
    char *s;
    s = strrchr(path,'/');
    if (s == ((void *)0))
        return strdup(path);
    else
        return strdup(s+1);
}

canonical_original_code:
static char *short_name(char *path)
{
    char *s;
    s = strrchr(path,'/');
    if (s == ((void *)0))
        return strdup(path);
    else
        return strdup(s+1);
}

variable_types:
path
char *

variable_types:
s
char *

return_type: char *


decompiled_code:
char *__fastcall make_output_filename(char *src)
{
char *v1; // rbp
char *v2; // r12
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
char *v6; // rbp
char *v7; // rax

if ( !src )
return 0LL;
if ( g_input_file_type == 2 )
{
v5 = strlen(src);
v6 = (char *)malloc(v5 + 6);
strcpy(v6, src);
v7 = strstr(v6, ".rtfd");
if ( v7 || (v7 = strstr(v6, ".RTFD")) != 0LL )
strcpy(v7, "-latex");
else
strcat(v6, "-latex");
mkdir(v6, 0x1EDu);
v1 = (char *)append_file_to_path(v6, "TXT.ltx");
}
else if ( (g_input_file_type & 0xFFFFFFFD) == 1 || !g_create_new_directory )
{
v1 = strdup(src);
strcpy(&v1[strlen(v1) - 4], ".ltx");
}
else
{
v1 = 0LL;
if ( !g_input_file_type )
{
v2 = short_name(src);
strcpy(&v2[strlen(v2) - 4], ".ltx");
v3 = strlen(src);
v4 = (char *)malloc(v3 + 6);
strcpy(v4, src);
strcpy(&v4[strlen(v4) - 4], "-latex");
mkdir(v4, 0x1EDu);
v1 = (char *)append_file_to_path(v4, v2);
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func6(char *src)
{
char *v1; // rbp
char *v2; // r12
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
char *v6; // rbp
char *v7; // rax

if ( !src )
return 0LL;
if ( g_input_file_type == 2 )
{
v5 = strlen(src);
v6 = (char *)malloc(v5 + 6);
strcpy(v6, src);
v7 = strstr(v6, ".rtfd");
if ( v7 || (v7 = strstr(v6, ".RTFD")) != 0LL )
strcpy(v7, "-latex");
else
strcat(v6, "-latex");
mkdir(v6, 0x1EDu);
v1 = (char *)append_file_to_path(v6, "TXT.ltx");
}
else if ( (g_input_file_type & 0xFFFFFFFD) == 1 || !g_create_new_directory )
{
v1 = strdup(src);
strcpy(&v1[strlen(v1) - 4], ".ltx");
}
else
{
v1 = 0LL;
if ( !g_input_file_type )
{
v2 = func5(src);
strcpy(&v2[strlen(v2) - 4], ".ltx");
v3 = strlen(src);
v4 = (char *)malloc(v3 + 6);
strcpy(v4, src);
strcpy(&v4[strlen(v4) - 4], "-latex");
mkdir(v4, 0x1EDu);
v1 = (char *)append_file_to_path(v4, v2);
}
}
return v1;
}

original_code:
static char * make_output_filename(char * name)
{
    char *s, *dir, *file, *out;
    if (!name) return ((void *)0);
    if (g_input_file_type == TYPE_RTFD) {
        dir = malloc(strlen(name)+strlen("-latex"));
        strcpy(dir,name);
        s = strstr(dir, ".rtfd");
        if (!s)
         s = strstr(dir, ".RTFD");
        if (s)
         strcpy(s,"-latex");
        else
         strcat(dir,"-latex");
        mkdir(dir, 0755);
        out = append_file_to_path(dir,"TXT.ltx");
        return out;
    }
    if (!g_create_new_directory || g_input_file_type == TYPE_EQN || g_input_file_type == TYPE_RAWEQN) {
        s = strdup(name);
        strcpy(s+strlen(s)-4, ".ltx");
        return s;
    }
    if (g_input_file_type == TYPE_RTF || g_input_file_type == TYPE_RTFD) {
        file = short_name(name);
        strcpy(file+strlen(file)-4, ".ltx");
        dir = malloc(strlen(name)+strlen("-latex"));
        strcpy(dir,name);
        strcpy(dir+strlen(dir)-4,"-latex");
        mkdir(dir, 0755);
        out = append_file_to_path(dir,file);
        return out;
    }
    return ((void *)0);
}

canonical_original_code:
static char *make_output_filename(char *name)
{
    char *s; char *dir; char *file; char *out;
    if (!name) return ((void *)0);
    if (g_input_file_type == TYPE_RTFD) {
        dir = malloc(strlen(name)+strlen("-latex"));
        strcpy(dir,name);
        s = strstr(dir, ".rtfd");
        if (!s)
         s = strstr(dir, ".RTFD");
        if (s)
         strcpy(s,"-latex");
        else
         strcat(dir,"-latex");
        mkdir(dir, 0755);
        out = append_file_to_path(dir,"TXT.ltx");
        return out;
    }
    if (!g_create_new_directory || g_input_file_type == TYPE_EQN || g_input_file_type == TYPE_RAWEQN) {
        s = strdup(name);
        strcpy(s+strlen(s)-4, ".ltx");
        return s;
    }
    if (g_input_file_type == TYPE_RTF || g_input_file_type == TYPE_RTFD) {
        file = short_name(name);
        strcpy(file+strlen(file)-4, ".ltx");
        dir = malloc(strlen(name)+strlen("-latex"));
        strcpy(dir,name);
        strcpy(dir+strlen(dir)-4,"-latex");
        mkdir(dir, 0755);
        out = append_file_to_path(dir,file);
        return out;
    }
    return ((void *)0);
}

variable_types:
dir
char *

variable_types:
file
char *

variable_types:
out
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
int result; // eax
__int64 v5; // r12
int v6; // er13
char v7; // al
char v8; // al
char v9; // al
char v10; // al
const char **v11; // rbp
const char **v12; // r13
__int64 v13; // r12
char *v14; // r12
char *v15; // rbx
int v16; // [rsp+0h] [rbp-38h] BYREF
int v17; // [rsp+4h] [rbp-34h] BYREF
int v18; // [rsp+8h] [rbp-30h] BYREF
int v19; // [rsp+Ch] [rbp-2Ch] BYREF

SetEndianness();
v19 = -1;
v18 = -1;
v17 = -1;
v16 = -1;
while ( 2 )
{
v3 = my_getopt((unsigned int)argc, argv, "bDe:fhnp:P:t:T:v");
if ( v3 != -1 )
{
switch ( v3 )
{
case 'D':
g_create_new_directory = 1;
continue;
case 'P':
g_library_path = (__int64)strdup(optarg);
continue;
case 'T':
_isoc99_sscanf(optarg, "%d", &v16);
continue;
case 'V':
case 'v':
print_version();
return 0;
case 'b':
v19 = 63;
v18 = 7;
v17 = 1;
v16 = 3;
continue;
case 'e':
_isoc99_sscanf(optarg, "%d", &v17);
continue;
case 'f':
g_shouldIncludePreamble = 0;
continue;
case 'n':
v19 = 33;
v18 = 12;
v17 = 1;
v16 = 0;
continue;
case 'p':
_isoc99_sscanf(optarg, "%d", &v19);
continue;
case 't':
_isoc99_sscanf(optarg, "%d", &v18);
continue;
default:
print_usage();
return result;
}
}
break;
}
v5 = optind;
v6 = argc - optind;
if ( argc == optind )
print_usage();
InitConverter();
v7 = v19;
if ( v19 >= 0 )
{
prefs[8] = v19 & 1;
prefs[9] = v7 & 2;
prefs[10] = v7 & 4;
prefs[11] = v7 & 8;
prefs[20] = v7 & 0x10;
prefs[21] = v7 & 0x20;
}
v8 = v18;
if ( v18 >= 0 )
{
prefs[6] = v18 & 1;
prefs[4] = v8 & 2;
prefs[7] = v8 & 4;
prefs[22] = v8 & 8;
}
v9 = v17;
if ( v17 >= 0 )
{
prefs[14] = v17 & 1;
g_eqn_insert_image = v9 & 2;
g_eqn_keep_file = v9 & 4;
g_eqn_insert_name = v9 & 8;
}
v10 = v16;
if ( v16 >= 0 )
{
prefs[23] = v16 & 1;
prefs[24] = v10 & 2;
prefs[25] = v10 & 4;
}
if ( v6 > 0 )
{
v11 = &argv[v5];
v12 = &(&argv[v6 - 1])[v5 + 1];
do
{
RTFInit();
v15 = establish_filename((char *)*v11);
if ( g_input_file_type == 2 )
{
g_create_new_directory = 1;
}
else if ( g_input_file_type == 4 )
{
if ( v15 )
{
RTFMsg("* Skipping non-RTF file '%s'\n", *v11);
free(v15);
}
else
{
RTFMsg("* Skipping non-existent file '%s'\n", *v11);
}
goto LABEL_40;
}
ifp = fopen(v15, "rb");
if ( !ifp )
{
RTFPanic("* Cannot open input file %s\n", v15);
exit(1);
}
RTFSetInputName(v15);
RTFSetStream(ifp);
if ( (g_input_file_type & 0xFFFFFFFD) == 1 )
goto LABEL_33;
v13 = ftell(ifp);
RTFGetToken();
RTFGetToken();
if ( (unsigned __int16)RTFCheckCMM(3LL, 0LL, 0LL) )
{
fseek(ifp, v13, 0);
LABEL_33:
RTFInit();
v14 = make_output_filename(v15);
ofp = (__int64)fopen(v14, "wb+");
if ( ofp )
{
RTFSetOutputName(v14);
RTFSetOutputStream(ofp);
fprintf(stderr, "Processing %s\n", v15);
if ( (unsigned int)BeginLaTeXFile() )
{
if ( g_input_file_type == 1 )
{
ConvertEquationFile(v15);
}
else if ( g_input_file_type == 3 )
{
ConvertRawEquationFile(v15);
}
else
{
RTFRead();
}
EndLaTeXFile();
}
fclose(ifp);
free(v15);
free(v14);
}
else
{
RTFMsg("Cannot open output file %s\n", v14);
free(v15);
free(v14);
}
goto LABEL_40;
}
RTFMsg("* Yikes! '%s' is not actually a RTF file! Skipping....\n", v15);
fclose(ifp);
free(v15);
LABEL_40:
++v11;
}
while ( v11 != v12 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
int result; // eax
__int64 v5; // r12
int v6; // er13
char v7; // al
char v8; // al
char v9; // al
char v10; // al
const char **v11; // rbp
const char **v12; // r13
__int64 v13; // r12
char *v14; // r12
char *v15; // rbx
int v16; // [rsp+0h] [rbp-38h] BYREF
int v17; // [rsp+4h] [rbp-34h] BYREF
int v18; // [rsp+8h] [rbp-30h] BYREF
int v19; // [rsp+Ch] [rbp-2Ch] BYREF

func0();
v19 = -1;
v18 = -1;
v17 = -1;
v16 = -1;
while ( 2 )
{
v3 = my_getopt((unsigned int)argc, argv, "bDe:fhnp:P:t:T:v");
if ( v3 != -1 )
{
switch ( v3 )
{
case 'D':
g_create_new_directory = 1;
continue;
case 'P':
g_library_path = (__int64)strdup(optarg);
continue;
case 'T':
_isoc99_sscanf(optarg, "%d", &v16);
continue;
case 'V':
case 'v':
func1();
return 0;
case 'b':
v19 = 63;
v18 = 7;
v17 = 1;
v16 = 3;
continue;
case 'e':
_isoc99_sscanf(optarg, "%d", &v17);
continue;
case 'f':
g_shouldIncludePreamble = 0;
continue;
case 'n':
v19 = 33;
v18 = 12;
v17 = 1;
v16 = 0;
continue;
case 'p':
_isoc99_sscanf(optarg, "%d", &v19);
continue;
case 't':
_isoc99_sscanf(optarg, "%d", &v18);
continue;
default:
func2();
return result;
}
}
break;
}
v5 = optind;
v6 = argc - optind;
if ( argc == optind )
func2();
InitConverter();
v7 = v19;
if ( v19 >= 0 )
{
prefs[8] = v19 & 1;
prefs[9] = v7 & 2;
prefs[10] = v7 & 4;
prefs[11] = v7 & 8;
prefs[20] = v7 & 0x10;
prefs[21] = v7 & 0x20;
}
v8 = v18;
if ( v18 >= 0 )
{
prefs[6] = v18 & 1;
prefs[4] = v8 & 2;
prefs[7] = v8 & 4;
prefs[22] = v8 & 8;
}
v9 = v17;
if ( v17 >= 0 )
{
prefs[14] = v17 & 1;
g_eqn_insert_image = v9 & 2;
g_eqn_keep_file = v9 & 4;
g_eqn_insert_name = v9 & 8;
}
v10 = v16;
if ( v16 >= 0 )
{
prefs[23] = v16 & 1;
prefs[24] = v10 & 2;
prefs[25] = v10 & 4;
}
if ( v6 > 0 )
{
v11 = &argv[v5];
v12 = &(&argv[v6 - 1])[v5 + 1];
do
{
RTFInit();
v15 = func4((char *)*v11);
if ( g_input_file_type == 2 )
{
g_create_new_directory = 1;
}
else if ( g_input_file_type == 4 )
{
if ( v15 )
{
RTFMsg("* Skipping non-RTF file '%s'\n", *v11);
free(v15);
}
else
{
RTFMsg("* Skipping non-existent file '%s'\n", *v11);
}
goto LABEL_40;
}
ifp = fopen(v15, "rb");
if ( !ifp )
{
RTFPanic("* Cannot open input file %s\n", v15);
exit(1);
}
RTFSetInputName(v15);
RTFSetStream(ifp);
if ( (g_input_file_type & 0xFFFFFFFD) == 1 )
goto LABEL_33;
v13 = ftell(ifp);
RTFGetToken();
RTFGetToken();
if ( (unsigned __int16)RTFCheckCMM(3LL, 0LL, 0LL) )
{
fseek(ifp, v13, 0);
LABEL_33:
RTFInit();
v14 = func6(v15);
ofp = (__int64)fopen(v14, "wb+");
if ( ofp )
{
RTFSetOutputName(v14);
RTFSetOutputStream(ofp);
fprintf(stderr, "Processing %s\n", v15);
if ( (unsigned int)BeginLaTeXFile() )
{
if ( g_input_file_type == 1 )
{
ConvertEquationFile(v15);
}
else if ( g_input_file_type == 3 )
{
ConvertRawEquationFile(v15);
}
else
{
RTFRead();
}
EndLaTeXFile();
}
fclose(ifp);
free(v15);
free(v14);
}
else
{
RTFMsg("Cannot open output file %s\n", v14);
free(v15);
free(v14);
}
goto LABEL_40;
}
RTFMsg("* Yikes! '%s' is not actually a RTF file! Skipping....\n", v15);
fclose(ifp);
free(v15);
LABEL_40:
++v11;
}
while ( v11 != v12 );
}
return 0;
}

original_code:
int
main(int argc, char **argv)
{
    char c, *input_filename, *output_filename;
    int fileCounter, cli_paragraph, cli_text, cli_equation, cli_table;
    long cursorPos;
    extern char *optarg;
    extern int optind;
    SetEndianness();
    cli_paragraph = -1;
    cli_text = -1;
    cli_equation = -1;
    cli_table = -1;
    while ((c = my_getopt(argc, argv, "bDe:fhnp:P:t:T:v")) != (-1)) {
        switch (c) {
        case 'b':
            cli_paragraph = 63;
            cli_text = 7;
            cli_equation = 1;
            cli_table = 3;
            break;
        case 'D':
            g_create_new_directory = 1;
            break;
        case 'e':
            sscanf(optarg, "%d", &cli_equation);
            break;
        case 'f':
            g_shouldIncludePreamble = 0;
            break;
        case 'n':
            cli_paragraph = 33;
            cli_text = 12;
            cli_equation = 1;
            cli_table = 0;
            break;
        case 'p':
            sscanf(optarg, "%d", &cli_paragraph);
            break;
        case 'P':
            g_library_path = strdup(optarg);
            break;
        case 't':
            sscanf(optarg, "%d", &cli_text);
            break;
        case 'T':
            sscanf(optarg, "%d", &cli_table);
            break;
        case 'v':
        case 'V':
            print_version();
            return (0);
        case 'h':
        case '?':
        default:
            print_usage();
        }
    }
    argc -= optind;
    argv += optind;
    if (!argc) print_usage();
    InitConverter();
    if (cli_paragraph >= 0) {
        prefs[pConvertParagraphStyle] = cli_paragraph & 1;
        prefs[pConvertParagraphIndent] = cli_paragraph & 2;
        prefs[pConvertInterParagraphSpace] = cli_paragraph & 4;
        prefs[pConvertLineSpacing] = cli_paragraph & 8;
        prefs[pConvertParagraphMargin] = cli_paragraph & 16;
        prefs[pConvertParagraphAlignment] = cli_paragraph & 32;
    }
    if (cli_text >= 0) {
        prefs[pConvertTextSize] = cli_text & 1;
        prefs[pConvertTextColor] = cli_text & 2;
        prefs[pConvertTextForm] = cli_text & 4;
        prefs[pConvertTextNoTab] = cli_text & 8;
    }
    if (cli_equation >= 0) {
        prefs[pConvertEquation] = cli_equation & 1;
        g_eqn_insert_image = cli_equation & 2;
        g_eqn_keep_file = cli_equation & 4;
        g_eqn_insert_name = cli_equation & 8;
    }
    if (cli_table >= 0) {
        prefs[pConvertTableWidths] = cli_table & 1;
        prefs[pConvertTableAlignment] = cli_table & 2;
        prefs[pConvertTableBorders] = cli_table & 4;
    }
    for (fileCounter = 0; fileCounter < argc; fileCounter++) {
        RTFInit();
        input_filename = establish_filename(argv[fileCounter]);
     if (g_input_file_type == TYPE_RTFD)
      g_create_new_directory = 1;
        if (g_input_file_type == TYPE_UNKNOWN) {
            if (!input_filename)
                RTFMsg("* Skipping non-existent file '%s'\n", argv[fileCounter]);
            else
                RTFMsg("* Skipping non-RTF file '%s'\n", argv[fileCounter]);
            if (input_filename) free(input_filename);
            continue;
        }
        ifp = fopen(input_filename, "rb");
        if (!ifp) {
            RTFPanic("* Cannot open input file %s\n", input_filename);
            exit(1);
        }
        RTFSetInputName(input_filename);
        RTFSetStream(ifp);
        if (g_input_file_type != TYPE_EQN && g_input_file_type != TYPE_RAWEQN) {
            cursorPos = ftell(ifp);
            RTFGetToken();
            RTFGetToken();
            if (!RTFCheckCMM(3, 0, 0)) {
                RTFMsg("* Yikes! '%s' is not actually a RTF file!  Skipping....\n", input_filename);
                fclose(ifp);
                free(input_filename);
                continue;
            }
            fseek(ifp, cursorPos, 0);
        }
        RTFInit();
        output_filename = make_output_filename(input_filename);
        ofp = fopen(output_filename, "wb+");
        if (!ofp) {
            RTFMsg("Cannot open output file %s\n", output_filename);
            free(input_filename);
            free(output_filename);
            continue;
        }
        RTFSetOutputName(output_filename);
        RTFSetOutputStream(ofp);
        fprintf(stderr, "Processing %s\n", input_filename);
        if (BeginLaTeXFile()) {
            if (g_input_file_type == TYPE_EQN)
                (void) ConvertEquationFile(input_filename);
            else if (g_input_file_type == TYPE_RAWEQN) {
                (void) ConvertRawEquationFile(input_filename);
            } else
                RTFRead();
            EndLaTeXFile();
        }
        fclose(ifp);
        free(input_filename);
        free(output_filename);
    }
    return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    char c; char *input_filename; char *output_filename;
    int fileCounter; int cli_paragraph; int cli_text; int cli_equation; int cli_table;
    long cursorPos;
    extern char *optarg;
    extern int optind;
    SetEndianness();
    cli_paragraph = -1;
    cli_text = -1;
    cli_equation = -1;
    cli_table = -1;
    while ((c = my_getopt(argc, argv, "bDe:fhnp:P:t:T:v")) != (-1)) {
        switch (c) {
        case 'b':
            cli_paragraph = 63;
            cli_text = 7;
            cli_equation = 1;
            cli_table = 3;
            break;
        case 'D':
            g_create_new_directory = 1;
            break;
        case 'e':
            sscanf(optarg, "%d", &cli_equation);
            break;
        case 'f':
            g_shouldIncludePreamble = 0;
            break;
        case 'n':
            cli_paragraph = 33;
            cli_text = 12;
            cli_equation = 1;
            cli_table = 0;
            break;
        case 'p':
            sscanf(optarg, "%d", &cli_paragraph);
            break;
        case 'P':
            g_library_path = strdup(optarg);
            break;
        case 't':
            sscanf(optarg, "%d", &cli_text);
            break;
        case 'T':
            sscanf(optarg, "%d", &cli_table);
            break;
        case 'v':
        case 'V':
            print_version();
            return (0);
        case 'h':
        case '?':
        default:
            print_usage();
        }
    }
    argc -= optind;
    argv += optind;
    if (!argc) print_usage();
    InitConverter();
    if (cli_paragraph >= 0) {
        prefs[pConvertParagraphStyle] = cli_paragraph & 1;
        prefs[pConvertParagraphIndent] = cli_paragraph & 2;
        prefs[pConvertInterParagraphSpace] = cli_paragraph & 4;
        prefs[pConvertLineSpacing] = cli_paragraph & 8;
        prefs[pConvertParagraphMargin] = cli_paragraph & 16;
        prefs[pConvertParagraphAlignment] = cli_paragraph & 32;
    }
    if (cli_text >= 0) {
        prefs[pConvertTextSize] = cli_text & 1;
        prefs[pConvertTextColor] = cli_text & 2;
        prefs[pConvertTextForm] = cli_text & 4;
        prefs[pConvertTextNoTab] = cli_text & 8;
    }
    if (cli_equation >= 0) {
        prefs[pConvertEquation] = cli_equation & 1;
        g_eqn_insert_image = cli_equation & 2;
        g_eqn_keep_file = cli_equation & 4;
        g_eqn_insert_name = cli_equation & 8;
    }
    if (cli_table >= 0) {
        prefs[pConvertTableWidths] = cli_table & 1;
        prefs[pConvertTableAlignment] = cli_table & 2;
        prefs[pConvertTableBorders] = cli_table & 4;
    }
    for (fileCounter = 0; fileCounter < argc; fileCounter++) {
        RTFInit();
        input_filename = establish_filename(argv[fileCounter]);
     if (g_input_file_type == TYPE_RTFD)
      g_create_new_directory = 1;
        if (g_input_file_type == TYPE_UNKNOWN) {
            if (!input_filename)
                RTFMsg("* Skipping non-existent file '%s'\n", argv[fileCounter]);
            else
                RTFMsg("* Skipping non-RTF file '%s'\n", argv[fileCounter]);
            if (input_filename) free(input_filename);
            continue;
        }
        ifp = fopen(input_filename, "rb");
        if (!ifp) {
            RTFPanic("* Cannot open input file %s\n", input_filename);
            exit(1);
        }
        RTFSetInputName(input_filename);
        RTFSetStream(ifp);
        if (g_input_file_type != TYPE_EQN && g_input_file_type != TYPE_RAWEQN) {
            cursorPos = ftell(ifp);
            RTFGetToken();
            RTFGetToken();
            if (!RTFCheckCMM(3, 0, 0)) {
                RTFMsg("* Yikes! '%s' is not actually a RTF file!  Skipping....\n", input_filename);
                fclose(ifp);
                free(input_filename);
                continue;
            }
            fseek(ifp, cursorPos, 0);
        }
        RTFInit();
        output_filename = make_output_filename(input_filename);
        ofp = fopen(output_filename, "wb+");
        if (!ofp) {
            RTFMsg("Cannot open output file %s\n", output_filename);
            free(input_filename);
            free(output_filename);
            continue;
        }
        RTFSetOutputName(output_filename);
        RTFSetOutputStream(ofp);
        fprintf(stderr, "Processing %s\n", input_filename);
        if (BeginLaTeXFile()) {
            if (g_input_file_type == TYPE_EQN)
                (void) ConvertEquationFile(input_filename);
            else if (g_input_file_type == TYPE_RAWEQN) {
                (void) ConvertRawEquationFile(input_filename);
            } else
                RTFRead();
            EndLaTeXFile();
        }
        fclose(ifp);
        free(input_filename);
        free(output_filename);
    }
    return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c char

variable_types: fileCounter int

variable_types: cursorPos long

variable_types:
optarg
char *

variable_types: optind int

return_type: int


Search

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

if ( !a1 )
return 0LL;
while ( 1 )
{
v2 = *a1++;
if ( !v2 )
break;
if ( v2 == a2 )
return 1LL;
}
return 0LL;
}

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

if ( !a1 )
return 0LL;
while ( 1 )
{
v2 = *a1++;
if ( !v2 )
break;
if ( v2 == a2 )
return 1LL;
}
return 0LL;
}

original_code:
static int Search (char *s, char c)
{
char c2;
 if (s != (char *) ((void *)0))
 {
  while ((c2 = *s++) != '\0')
  {
   if (c == c2)
    return (1);
  }
 }
 return (0);
}

canonical_original_code:
static int Search(char *s, char c)
{
char c2;
 if (s != (char *) ((void *)0))
 {
  while ((c2 = *s++) != '\0')
  {
   if (c == c2)
    return (1);
  }
 }
 return (0);
}


TSSetScanner

decompiled_code:
__int64 __fastcall TSSetScanner(__int64 a1)
{
__int64 (__fastcall *v1)(); // rax
void *v2; // rax
void *v3; // rax
void *v4; // rax
void *v5; // rax
__int64 result; // rax

if ( a1 )
{
curScan = *(__int64 (**)(void))a1;
v1 = *(__int64 (__fastcall **)())(a1 + 8);
if ( !v1 )
v1 = CanonScan;
off_388 = v1;
v2 = *(void **)(a1 + 16);
if ( !v2 )
v2 = &unk_3D0;
off_390 = v2;
v3 = *(void **)(a1 + 24);
if ( !v3 )
v3 = &unk_3CD;
off_398 = v3;
v4 = *(void **)(a1 + 32);
if ( !v4 )
v4 = &unk_3CB;
off_3A0 = v4;
v5 = *(void **)(a1 + 40);
if ( !v5 )
v5 = &unk_3C8;
off_3A8 = v5;
result = *(unsigned int *)(a1 + 48);
}
else
{
curScan = 0LL;
off_388 = CanonScan;
off_390 = &unk_3D0;
off_398 = &unk_3CD;
off_3A0 = &unk_3CB;
off_3A8 = &unk_3C8;
result = 0LL;
}
dword_3B0 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 (__fastcall *v1)(); // rax
void *v2; // rax
void *v3; // rax
void *v4; // rax
void *v5; // rax
__int64 result; // rax

if ( a1 )
{
curScan = *(__int64 (**)(void))a1;
v1 = *(__int64 (__fastcall **)())(a1 + 8);
if ( !v1 )
v1 = CanonScan;
off_388 = v1;
v2 = *(void **)(a1 + 16);
if ( !v2 )
v2 = &unk_3D0;
off_390 = v2;
v3 = *(void **)(a1 + 24);
if ( !v3 )
v3 = &unk_3CD;
off_398 = v3;
v4 = *(void **)(a1 + 32);
if ( !v4 )
v4 = &unk_3CB;
off_3A0 = v4;
v5 = *(void **)(a1 + 40);
if ( !v5 )
v5 = &unk_3C8;
off_3A8 = v5;
result = *(unsigned int *)(a1 + 48);
}
else
{
curScan = 0LL;
off_388 = CanonScan;
off_390 = &unk_3D0;
off_398 = &unk_3CD;
off_3A0 = &unk_3CB;
off_3A8 = &unk_3C8;
result = 0LL;
}
dword_3B0 = result;
return result;
}

original_code:
void TSSetScanner (TSScanner *p)
{
 if (p == (TSScanner *) ((void *)0) || p->scanInit == (VoidProc) ((void *)0))
  curScan.scanInit = defScan.scanInit;
 else
  curScan.scanInit = p->scanInit;
 if (p == (TSScanner *) ((void *)0) || p->scanScan == (CharPtrProc) ((void *)0))
  curScan.scanScan = defScan.scanScan;
 else
  curScan.scanScan = p->scanScan;
 if (p == (TSScanner *) ((void *)0) || p->scanDelim == (char *) ((void *)0))
  curScan.scanDelim = defScan.scanDelim;
 else
  curScan.scanDelim = p->scanDelim;
 if (p == (TSScanner *) ((void *)0) || p->scanQuote == (char *) ((void *)0))
  curScan.scanQuote = defScan.scanQuote;
 else
  curScan.scanQuote = p->scanQuote;
 if (p == (TSScanner *) ((void *)0) || p->scanEscape == (char *) ((void *)0))
  curScan.scanEscape = defScan.scanEscape;
 else
  curScan.scanEscape = p->scanEscape;
 if (p == (TSScanner *) ((void *)0) || p->scanEos == (char *) ((void *)0))
  curScan.scanEos = defScan.scanEos;
 else
  curScan.scanEos = p->scanEos;
 if (p == (TSScanner *) ((void *)0) || p->scanFlags == 0)
  curScan.scanFlags = defScan.scanFlags;
 else
  curScan.scanFlags = p->scanFlags;
}

canonical_original_code:
void TSSetScanner(struct TSScanner *p)
{
 if (p == (struct TSScanner *) ((void *)0) || p->scanInit == (VoidProc) ((void *)0))
  curScan.scanInit = defScan.scanInit;
 else
  curScan.scanInit = p->scanInit;
 if (p == (struct TSScanner *) ((void *)0) || p->scanScan == (CharPtrProc) ((void *)0))
  curScan.scanScan = defScan.scanScan;
 else
  curScan.scanScan = p->scanScan;
 if (p == (struct TSScanner *) ((void *)0) || p->scanDelim == (char *) ((void *)0))
  curScan.scanDelim = defScan.scanDelim;
 else
  curScan.scanDelim = p->scanDelim;
 if (p == (struct TSScanner *) ((void *)0) || p->scanQuote == (char *) ((void *)0))
  curScan.scanQuote = defScan.scanQuote;
 else
  curScan.scanQuote = p->scanQuote;
 if (p == (struct TSScanner *) ((void *)0) || p->scanEscape == (char *) ((void *)0))
  curScan.scanEscape = defScan.scanEscape;
 else
  curScan.scanEscape = p->scanEscape;
 if (p == (struct TSScanner *) ((void *)0) || p->scanEos == (char *) ((void *)0))
  curScan.scanEos = defScan.scanEos;
 else
  curScan.scanEos = p->scanEos;
 if (p == (struct TSScanner *) ((void *)0) || p->scanFlags == 0)
  curScan.scanFlags = defScan.scanFlags;
 else
  curScan.scanFlags = p->scanFlags;
}

variable_types: struct TSScanner { void (*scanInit)(char *p); char *(*scanScan)(); char *scanDelim; char *scanQuote; char *scanEscape; char *scanEos; int scanFlags; } *


TSGetScanner

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

*(_QWORD *)a1 = curScan;
*(_QWORD *)(a1 + 8) = off_388;
*(_QWORD *)(a1 + 16) = off_390;
*(_QWORD *)(a1 + 24) = off_398;
*(_QWORD *)(a1 + 32) = off_3A0;
*(_QWORD *)(a1 + 40) = off_3A8;
result = (unsigned int)dword_3B0;
*(_DWORD *)(a1 + 48) = dword_3B0;
return result;
}

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

*(_QWORD *)a1 = curScan;
*(_QWORD *)(a1 + 8) = off_388;
*(_QWORD *)(a1 + 16) = off_390;
*(_QWORD *)(a1 + 24) = off_398;
*(_QWORD *)(a1 + 32) = off_3A0;
*(_QWORD *)(a1 + 40) = off_3A8;
result = (unsigned int)dword_3B0;
*(_DWORD *)(a1 + 48) = dword_3B0;
return result;
}

original_code:
void TSGetScanner (TSScanner *p)
{
 p->scanInit = curScan.scanInit;
 p->scanScan = curScan.scanScan;
 p->scanDelim = curScan.scanDelim;
 p->scanQuote = curScan.scanQuote;
 p->scanEscape = curScan.scanEscape;
 p->scanEos = curScan.scanEos;
 p->scanFlags = curScan.scanFlags;
}

canonical_original_code:
void TSGetScanner(struct TSScanner *p)
{
 p->scanInit = curScan.scanInit;
 p->scanScan = curScan.scanScan;
 p->scanDelim = curScan.scanDelim;
 p->scanQuote = curScan.scanQuote;
 p->scanEscape = curScan.scanEscape;
 p->scanEos = curScan.scanEos;
 p->scanFlags = curScan.scanFlags;
}

user_defined_types: struct TSScanner { void (*scanInit)(char *p); char *(*scanScan)(); char *scanDelim; char *scanQuote; char *scanEscape; char *scanEos; int scanFlags; }


TSSetScanPos

decompiled_code:
void __fastcall TSSetScanPos(__int64 a1)
{
curPos = a1;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
curPos = a1;
}

original_code:
void TSSetScanPos (char *p)
{
 curPos = p;
}

canonical_original_code:
void TSSetScanPos(char *p)
{
 curPos = p;
}

variable_types:
p
char *


TSGetScanPos

decompiled_code:
__int64 TSGetScanPos()
{
return curPos;
}

canonical_decompiled_code:
__int64 func4()
{
return curPos;
}

original_code:
char * TSGetScanPos (void)
{
 return (curPos);
}

canonical_original_code:
char *TSGetScanPos()
{
 return (curPos);
}


TSIsScanDelim

decompiled_code:
__int64 __fastcall TSIsScanDelim(char a1)
{
return Search((char *)off_390, a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
return func0((char *)off_390, a1);
}

original_code:
int TSIsScanDelim (char c)
{
 return (Search (curScan.scanDelim, c));
}

canonical_original_code:
int TSIsScanDelim(char c)
{
 return (Search (curScan.scanDelim, c));
}


TSIsScanQuote

decompiled_code:
__int64 __fastcall TSIsScanQuote(char a1)
{
return Search((char *)off_398, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
return func0((char *)off_398, a1);
}

original_code:
int TSIsScanQuote (char c)
{
 return (Search (curScan.scanQuote, c));
}

canonical_original_code:
int TSIsScanQuote(char c)
{
 return (Search (curScan.scanQuote, c));
}


TSIsScanEscape

decompiled_code:
__int64 __fastcall TSIsScanEscape(char a1)
{
return Search((char *)off_3A0, a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return func0((char *)off_3A0, a1);
}

original_code:
int TSIsScanEscape (char c)
{
 return (Search (curScan.scanEscape, c));
}

canonical_original_code:
int TSIsScanEscape(char c)
{
 return (Search (curScan.scanEscape, c));
}


TSIsScanEos

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

result = 1LL;
if ( a1 )
result = Search((char *)off_3A8, a1);
return result;
}

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

result = 1LL;
if ( a1 )
result = func0((char *)off_3A8, a1);
return result;
}

original_code:
int TSIsScanEos (char c)
{
 if (c == '\0')
  return (1);
 return (Search (curScan.scanEos, c));
}

canonical_original_code:
int TSIsScanEos(char c)
{
 if (c == '\0')
  return (1);
 return (Search (curScan.scanEos, c));
}


TSTestScanFlags

decompiled_code:
_BOOL8 __fastcall TSTestScanFlags(int a1)
{
return (dword_3B0 & a1) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1)
{
return (dword_3B0 & a1) == a1;
}

original_code:
int TSTestScanFlags (int flags)
{
 return ((curScan.scanFlags & flags) == flags);
}

canonical_original_code:
int TSTestScanFlags(int flags)
{
 return ((curScan.scanFlags & flags) == flags);
}

variable_types: flags int


CanonScan

decompiled_code:
char *CanonScan()
{
int v0; // ebp
char *v1; // r14
char *v2; // rbx
char v3; // r12
char *v4; // rax
char *v6; // [rsp+0h] [rbp-40h]
int v7; // [rsp+8h] [rbp-38h]
char v8; // [rsp+Fh] [rbp-31h]

v0 = emptyToken;
if ( emptyToken )
{
emptyToken = 0;
v6 = (char *)&unk_3D3;
}
else
{
v6 = (char *)TSGetScanPos();
if ( !TSTestScanFlags(1) )
{
while ( (unsigned int)TSIsScanDelim(*v6) )
++v6;
}
v1 = v6;
v2 = v6 + 1;
v7 = v0;
v8 = 0;
while ( 1 )
{
v3 = *(v2 - 1);
if ( (unsigned int)TSIsScanEos(v3) )
break;
if ( v0 )
{
*v1 = v3;
v0 = 0;
++v1;
}
else
{
v0 = TSIsScanEscape(v3);
if ( v0 )
{
v0 = 1;
}
else if ( v8 )
{
if ( v8 == v3 )
v8 = 0;
else
*v1++ = v3;
}
else if ( (unsigned int)TSIsScanQuote(v3) )
{
v8 = v3;
}
else
{
v0 = TSIsScanDelim(v3);
if ( v0 )
{
if ( (unsigned int)TSIsScanEos(*v2) && TSTestScanFlags(1) )
emptyToken = 1;
*v1 = 0;
TSSetScanPos((__int64)v2);
return v6;
}
*v1++ = v3;
}
}
++v2;
v7 = 1;
}
*v1 = 0;
TSSetScanPos((__int64)(v2 - 1));
v4 = 0LL;
if ( v7 )
v4 = v6;
v6 = v4;
}
return v6;
}

canonical_decompiled_code:
char *func10()
{
int v0; // ebp
char *v1; // r14
char *v2; // rbx
char v3; // r12
char *v4; // rax
char *v6; // [rsp+0h] [rbp-40h]
int v7; // [rsp+8h] [rbp-38h]
char v8; // [rsp+Fh] [rbp-31h]

v0 = emptyToken;
if ( emptyToken )
{
emptyToken = 0;
v6 = (char *)&unk_3D3;
}
else
{
v6 = (char *)func4();
if ( !func9(1) )
{
while ( (unsigned int)func5(*v6) )
++v6;
}
v1 = v6;
v2 = v6 + 1;
v7 = v0;
v8 = 0;
while ( 1 )
{
v3 = *(v2 - 1);
if ( (unsigned int)func8(v3) )
break;
if ( v0 )
{
*v1 = v3;
v0 = 0;
++v1;
}
else
{
v0 = func7(v3);
if ( v0 )
{
v0 = 1;
}
else if ( v8 )
{
if ( v8 == v3 )
v8 = 0;
else
*v1++ = v3;
}
else if ( (unsigned int)func6(v3) )
{
v8 = v3;
}
else
{
v0 = func5(v3);
if ( v0 )
{
if ( (unsigned int)func8(*v2) && func9(1) )
emptyToken = 1;
*v1 = 0;
func3((__int64)v2);
return v6;
}
*v1++ = v3;
}
}
++v2;
v7 = 1;
}
*v1 = 0;
func3((__int64)(v2 - 1));
v4 = 0LL;
if ( v7 )
v4 = v6;
v6 = v4;
}
return v6;
}

original_code:
static char * CanonScan (void)
{
char *pos, *start, *p, c, quote = 0;
int escape = 0, haveToken = 0;
 if (emptyToken)
 {
  emptyToken = 0;
  return ("");
 }
 pos = TSGetScanPos ();
 if (!TSTestScanFlags (0x01))
 {
  while (TSIsScanDelim (*pos))
   ++pos;
 }
 start = p = pos;
 while (!TSIsScanEos (c = *pos))
 {
  haveToken = 1;
  if (escape)
  {
   *p++ = *pos++;
   escape = 0;
  }
  else if (TSIsScanEscape (c))
  {
   ++pos;
   escape = 1;
  }
  else if (quote)
  {
   if (c == quote)
    quote = 0;
   else
    *p++ = *pos;
   ++pos;
  }
  else if (TSIsScanQuote (c))
  {
   ++pos;
   quote = c;
  }
  else if (TSIsScanDelim (c))
  {
   ++pos;
   if (TSIsScanEos (*pos)
    && TSTestScanFlags (0x01))
    ++emptyToken;
   break;
  }
  else
   *p++ = *pos++;
 }
 *p = '\0';
 TSSetScanPos (pos);
 return (haveToken ? start : (char *) ((void *)0));
}

canonical_original_code:
static char *CanonScan()
{
char *pos; char *start; char *p; char c; char quote = 0;
int escape = 0; int haveToken = 0;
 if (emptyToken)
 {
  emptyToken = 0;
  return ("");
 }
 pos = TSGetScanPos ();
 if (!TSTestScanFlags (0x01))
 {
  while (TSIsScanDelim (*pos))
   ++pos;
 }
 start = p = pos;
 while (!TSIsScanEos (c = *pos))
 {
  haveToken = 1;
  if (escape)
  {
   *p++ = *pos++;
   escape = 0;
  }
  else if (TSIsScanEscape (c))
  {
   ++pos;
   escape = 1;
  }
  else if (quote)
  {
   if (c == quote)
    quote = 0;
   else
    *p++ = *pos;
   ++pos;
  }
  else if (TSIsScanQuote (c))
  {
   ++pos;
   quote = c;
  }
  else if (TSIsScanDelim (c))
  {
   ++pos;
   if (TSIsScanEos (*pos)
    && TSTestScanFlags (0x01))
    ++emptyToken;
   break;
  }
  else
   *p++ = *pos++;
 }
 *p = '\0';
 TSSetScanPos (pos);
 return (haveToken ? start : (char *) ((void *)0));
}

variable_types:
pos
char *

variable_types:
start
char *

variable_types: quote char

variable_types: escape int

variable_types: haveToken int


TSScan

decompiled_code:
__int64 TSScan()
{
return off_388();
}

original_code:
char * TSScan (void)
{
 return ((*curScan.scanScan) ());
}

canonical_original_code:
char *TSScan()
{
 return ((*curScan.scanScan) ());
}


decompiled_code:
__int64 __fastcall fil_sreadU16(unsigned __int16 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1)
{
return *a1;
}

original_code:
uint16_t fil_sreadU16(uint8_t * in)
{
    uint16_t ret;
    ret = *((uint16_t *) in);
    return ret;
}

canonical_original_code:
unsigned short fil_sreadU16(unsigned char *in)
{
    unsigned short ret;
    ret = *((unsigned short *) in);
    return ret;
}

variable_types:
in
unsigned char *

variable_types:
ret
unsigned short

return_type: unsigned short


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

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

original_code:
uint32_t fil_sreadU32(uint8_t * in)
{
    uint32_t ret;
    ret = *((uint32_t *) in);
    return ret;
}

canonical_original_code:
unsigned int fil_sreadU32(unsigned char *in)
{
    unsigned int ret;
    ret = *((unsigned int *) in);
    return ret;
}

variable_types:
ret
unsigned int

return_type: unsigned int


hexdump

original_code:
void hexdump(void *ptr, void *zero, uint32_t length, char *msg)
{
    unsigned char *pm, *m, *start;
    char buff[18];
    long offset;
    if (!ptr) {
        fprintf(stderr,"Cannot show memory because pointer is NULL\n");
        return;
    }
    m = (unsigned char *) ptr;
    start = (zero) ? (unsigned char *) zero : m;
    buff[8] = ' ';
    buff[17] = '\0';
    if (msg)
        printf("%s from 0x%p length 0x%08x (%d bytes)\n", msg, m, (unsigned int) length, (int) length);
    for (pm = m; (uint32_t) (pm - m) < length; pm++) {
        offset = (pm - m) % 16;
        if (offset == 0)
            printf("%08lx  ", (unsigned long) ((pm - m) + (m - start)));
        buff[offset + (offset < 8 ? 0 : 1)] = (((*__ctype_b_loc ())[(int) ((*pm))] & (unsigned short int) _ISprint) ? (char) *pm : '.');
        if (!((pm - m + 1) % 16))
            printf("%02x  %s\n", *pm, buff);
        else if (!((pm - m + 1) % 8))
            printf("%02x  ", *pm);
        else
            printf("%02x ", *pm);
    }
    offset = (pm - m) % 16;
    if (offset) {
        int i;
        for (i = 0; i < (16 - offset) * 3 - 1; i++)
            printf(" ");
        if (offset != 8)
            buff[offset] = 0;
        printf("  %s\n", buff);
    }
}

canonical_original_code:
void hexdump(void *ptr, void *zero, unsigned int length, char *msg)
{
    unsigned char *pm; unsigned char *m; unsigned char *start;
    char buff[18];
    long offset;
    if (!ptr) {
        fprintf(stderr,"Cannot show memory because pointer is NULL\n");
        return;
    }
    m = (unsigned char *) ptr;
    start = (zero) ? (unsigned char *) zero : m;
    buff[8] = ' ';
    buff[17] = '\0';
    if (msg)
        printf("%s from 0x%p length 0x%08x (%d bytes)\n", msg, m, (unsigned int) length, (int) length);
    for (pm = m; (unsigned int) (pm - m) < length; pm++) {
        offset = (pm - m) % 16;
        if (offset == 0)
            printf("%08lx  ", (unsigned long) ((pm - m) + (m - start)));
        buff[offset + (offset < 8 ? 0 : 1)] = (((*__ctype_b_loc ())[(int) ((*pm))] & (unsigned short) _ISprint) ? (char) *pm : '.');
        if (!((pm - m + 1) % 16))
            printf("%02x  %s\n", *pm, buff);
        else if (!((pm - m + 1) % 8))
            printf("%02x  ", *pm);
        else
            printf("%02x ", *pm);
    }
    offset = (pm - m) % 16;
    if (offset) {
        int i;
        for (i = 0; i < (16 - offset) * 3 - 1; i++)
            printf(" ");
        if (offset != 8)
            buff[offset] = 0;
        printf("  %s\n", buff);
    }
}

variable_types:
ptr
void *

variable_types:
zero
void *

variable_types:
length
unsigned int

variable_types:
msg
char *

variable_types:
pm
unsigned char *

variable_types:
m
unsigned char *

variable_types:
start
unsigned char *

variable_types:
buff
char [18]

variable_types: offset long

variable_types: i int


decompiled_code:
__int64 __fastcall reorder_pps_tree(__int64 a1, unsigned __int16 a2)
{
unsigned int v3; // edx
__int64 result; // rax
_BYTE *v5; // rdi
unsigned int v6; // edx
_BYTE *v7; // rdi
unsigned int v8; // edx
__int64 v9; // rcx
unsigned int *v10; // rax

*(_WORD *)(a1 + 68) = a2;
v3 = *(_DWORD *)(a1 + 64);
if ( v3 == -1
|| (result = 0LL, v3 <= num_of_pps)
&& (v5 = (_BYTE *)(pps_list + 100LL * v3), result = 0LL, *v5)
&& (result = reorder_pps_tree(v5, (unsigned __int16)(a2 + 1)), (_DWORD)result) )
{
v6 = *(_DWORD *)(a1 + 60);
if ( v6 == -1 )
{
last_next_link_visited = a1 + 60;
}
else
{
result = 0LL;
if ( v6 > num_of_pps )
return result;
v7 = (_BYTE *)(pps_list + 100LL * v6);
result = 0LL;
if ( !*v7 )
return result;
result = reorder_pps_tree(v7, a2);
if ( !(_DWORD)result )
return result;
}
v8 = *(_DWORD *)(a1 + 92);
result = 1LL;
if ( v8 != -1 )
{
result = 0LL;
if ( v8 <= num_of_pps )
{
v9 = pps_list;
result = 0LL;
if ( *(_BYTE *)(pps_list + 100LL * v8) )
{
v10 = (unsigned int *)last_next_link_visited;
*(_DWORD *)last_next_link_visited = v8;
*(_DWORD *)(a1 + 92) = -1;
result = (unsigned int)reorder_pps_tree(v9 + 100LL * *v10, a2) != 0;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int16 a2)
{
unsigned int v3; // edx
__int64 result; // rax
_BYTE *v5; // rdi
unsigned int v6; // edx
_BYTE *v7; // rdi
unsigned int v8; // edx
__int64 v9; // rcx
unsigned int *v10; // rax

*(_WORD *)(a1 + 68) = a2;
v3 = *(_DWORD *)(a1 + 64);
if ( v3 == -1
|| (result = 0LL, v3 <= num_of_pps)
&& (v5 = (_BYTE *)(pps_list + 100LL * v3), result = 0LL, *v5)
&& (result = func0(v5, (unsigned __int16)(a2 + 1)), (_DWORD)result) )
{
v6 = *(_DWORD *)(a1 + 60);
if ( v6 == -1 )
{
last_next_link_visited = a1 + 60;
}
else
{
result = 0LL;
if ( v6 > num_of_pps )
return result;
v7 = (_BYTE *)(pps_list + 100LL * v6);
result = 0LL;
if ( !*v7 )
return result;
result = func0(v7, a2);
if ( !(_DWORD)result )
return result;
}
v8 = *(_DWORD *)(a1 + 92);
result = 1LL;
if ( v8 != -1 )
{
result = 0LL;
if ( v8 <= num_of_pps )
{
v9 = pps_list;
result = 0LL;
if ( *(_BYTE *)(pps_list + 100LL * v8) )
{
v10 = (unsigned int *)last_next_link_visited;
*(_DWORD *)last_next_link_visited = v8;
*(_DWORD *)(a1 + 92) = -1;
result = (unsigned int)func0(v9 + 100LL * *v10, a2) != 0;
}
}
}
}
return result;
}

original_code:
int reorder_pps_tree(pps_entry * node, uint16_t level)
{
    node->level = level;
    if (node->dir != (uint32_t) 0xffffffff) {
        if (node->dir > num_of_pps || !pps_list[node->dir].name[0])
            return 0;
        if (!reorder_pps_tree(&pps_list[node->dir], level + 1))
            return 0;
    }
    if (node->next != (uint32_t) 0xffffffff) {
        if (node->next > num_of_pps || !pps_list[node->next].name[0])
            return 0;
        else if (!reorder_pps_tree(&pps_list[node->next], level))
            return 0;
    } else
        last_next_link_visited = &node->next;
    if (node->previous != (uint32_t) 0xffffffff) {
        if (node->previous > num_of_pps || !pps_list[node->previous].name[0])
            return 0;
        *last_next_link_visited = node->previous;
        node->previous = (uint32_t) 0xffffffff;
        if (!reorder_pps_tree(&pps_list[*last_next_link_visited], level))
            return 0;
    }
    return 1;
}

canonical_original_code:
int reorder_pps_tree(struct pps_block *node, unsigned short level)
{
    node->level = level;
    if (node->dir != (unsigned int) 0xffffffff) {
        if (node->dir > num_of_pps || !pps_list[node->dir].name[0])
            return 0;
        if (!reorder_pps_tree(&pps_list[node->dir], level + 1))
            return 0;
    }
    if (node->next != (unsigned int) 0xffffffff) {
        if (node->next > num_of_pps || !pps_list[node->next].name[0])
            return 0;
        else if (!reorder_pps_tree(&pps_list[node->next], level))
            return 0;
    } else
        last_next_link_visited = &node->next;
    if (node->previous != (unsigned int) 0xffffffff) {
        if (node->previous > num_of_pps || !pps_list[node->previous].name[0])
            return 0;
        *last_next_link_visited = node->previous;
        node->previous = (unsigned int) 0xffffffff;
        if (!reorder_pps_tree(&pps_list[*last_next_link_visited], level))
            return 0;
    }
    return 1;
}

variable_types: struct pps_block { char name[32]; char filename[-1]; unsigned char type; unsigned int size; unsigned int next; unsigned int dir; unsigned short level; unsigned int seconds1; unsigned int seconds2; unsigned int days1; unsigned int days2; unsigned int start; unsigned int previous; unsigned int ppsnumber; } *

variable_types:
level
unsigned short


ends

decompiled_code:
void ends()
{
if ( Block )
free(Block);
if ( Root )
free(Root);
if ( sbd_list )
free(sbd_list);
if ( root_list )
free(root_list);
}

canonical_decompiled_code:
void func1()
{
if ( Block )
free(Block);
if ( Root )
free(Root);
if ( sbd_list )
free(sbd_list);
if ( root_list )
free(root_list);
}

original_code:
void ends(void)
{
    if (Block) free(Block);
    if (Root) free(Root);
    if (sbd_list) free(sbd_list);
    if (root_list) free(root_list);
}

canonical_original_code:
void ends()
{
    if (Block) free(Block);
    if (Root) free(Root);
    if (sbd_list) free(sbd_list);
    if (root_list) free(root_list);
}