main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
float v4; // xmm3_4
float i; // [rsp+Ch] [rbp-1BCh]
float v6[8]; // [rsp+10h] [rbp-1B8h] BYREF
char v7[12]; // [rsp+30h] [rbp-198h] BYREF
float v8; // [rsp+3Ch] [rbp-18Ch]
float v9; // [rsp+5Ch] [rbp-16Ch]
float v10; // [rsp+7Ch] [rbp-14Ch]
float v11; // [rsp+9Ch] [rbp-12Ch]
float v12; // [rsp+BCh] [rbp-10Ch]
float v13; // [rsp+DCh] [rbp-ECh]
float v14; // [rsp+FCh] [rbp-CCh]
float v15; // [rsp+11Ch] [rbp-ACh]
float v16; // [rsp+13Ch] [rbp-8Ch]
float v17; // [rsp+15Ch] [rbp-6Ch]
float v18; // [rsp+17Ch] [rbp-4Ch]
float v19; // [rsp+19Ch] [rbp-2Ch]
char v20; // [rsp+1B0h] [rbp-18h] BYREF

v3 = v7;
do
{
osc_init(v3, 4);
v3 += 32;
}
while ( v3 != &v20 );
filter_moog_init(v6);
filter_moog_set_params(v6, 0.050000001, 0.0);
for ( i = 0.2; ; i = 0.0 )
{
do
{
v12 = note2freq(0LL, 2LL) - 1.0;
v13 = note2freq(0LL, 2LL) + 1.0;
v14 = note2freq(0LL, 1LL);
v15 = note2freq(0LL, 0LL);
v8 = note2freq(2LL, 2LL) - 1.0;
v9 = note2freq(2LL, 2LL) + 1.0;
v10 = note2freq(2LL, 1LL);
v11 = note2freq(2LL, 0LL);
v16 = note2freq(6LL, 2LL) - 1.0;
v17 = note2freq(6LL, 2LL) + 1.0;
v18 = note2freq(6LL, 1LL);
v19 = note2freq(6LL, 0LL);
make_noise((__int64)v7, 12, v6, 0.60000002, 44100.0, 0.0000099999997);
v4 = i + 0.2;
i = v4;
}
while ( v4 < 1.0 );
}
}

original_code:
int main(void)
{
 scalar_t sample_freq = 44100;
 scalar_t i, j, freq;
 scalar_t b;
 int n;
 osc_t osc[12];
 for (n = 0; n<12;n++)
  osc_init(&osc[n], OSC_TYPE_SAWTOOTH);
 filter_moog_t f;
 filter_moog_init(&f);
 i = 0.06f;
 j = -0.01f;
 b = 0;
 filter_moog_set_params(&f, 0.05, 0.0f);
 for (;;) {
  if ((b+=.2) >= 1) {
   b = 0;
   j *= -1;
  }
  osc[4].freq = note2freq(A, 2) - 1;
  osc[5].freq = note2freq(A, 2) + 1;
  osc[6].freq = note2freq(A, 1);
  osc[7].freq = note2freq(A, 0);
  osc[0].freq = note2freq(C, 2) - 1;
  osc[1].freq = note2freq(C, 2) + 1;
  osc[2].freq = note2freq(C, 1);
  osc[3].freq = note2freq(C, 0);
  osc[8].freq = note2freq(E, 2) - 1;
  osc[9].freq = note2freq(E, 2) + 1;
  osc[10].freq = note2freq(E, 1);
  osc[11].freq = note2freq(E, 0);
  i += j;
  make_noise(osc, 12, 0.6f, sample_freq, 0.00001, &f);
 }
}

canonical_original_code:
int main()
{
 float sample_freq = 44100;
 float i; float j; float freq;
 float b;
 int n;
 struct osc_t osc[12];
 for (n = 0; n<12;n++)
  osc_init(&osc[n], OSC_TYPE_SAWTOOTH);
 struct filter_moog_t f;
 filter_moog_init(&f);
 i = 0.06f;
 j = -0.01f;
 b = 0;
 filter_moog_set_params(&f, 0.05, 0.0f);
 for (;;) {
  if ((b+=.2) >= 1) {
   b = 0;
   j *= -1;
  }
  osc[4].freq = note2freq(A, 2) - 1;
  osc[5].freq = note2freq(A, 2) + 1;
  osc[6].freq = note2freq(A, 1);
  osc[7].freq = note2freq(A, 0);
  osc[0].freq = note2freq(C, 2) - 1;
  osc[1].freq = note2freq(C, 2) + 1;
  osc[2].freq = note2freq(C, 1);
  osc[3].freq = note2freq(C, 0);
  osc[8].freq = note2freq(E, 2) - 1;
  osc[9].freq = note2freq(E, 2) + 1;
  osc[10].freq = note2freq(E, 1);
  osc[11].freq = note2freq(E, 0);
  i += j;
  make_noise(osc, 12, 0.6f, sample_freq, 0.00001, &f);
 }
}

variable_types: i float

variable_types: j float

variable_types: b float

variable_types: n int

variable_types: struct osc_t { enum osc_type_t { OSC_TYPE_SINE=0, OSC_TYPE_SQUARE=1, OSC_TYPE_TRIANGLE=2, OSC_TYPE_SAWTOOTH=4, OSC_TYPE_NOISE_WHITE=5, OSC_TYPE_WAVE=10 } type; float phase; float phase_offset; float freq; float *waveform; float waveform_length; } [12]

variable_types: struct filter_moog_t { float f; float b0; }


repo: vlohacks/misc

decompiled_code:
void *__fastcall output_benchmark_writer(void *a1)
{
time_t v1; // rbx
char v3[2]; // [rsp+0h] [rbp-Ch] BYREF
char v4[10]; // [rsp+2h] [rbp-Ah] BYREF

if ( !output_benchmark_thread_running )
return 0LL;
do
{
v1 = time(0LL);
if ( (unsigned int)player_read(output_benchmark_player, v4, v3) != 2 )
*(_DWORD *)(output_benchmark_player + 168) = 0;
++output_benchmark_sample_count;
if ( last_time != v1 )
{
printf("%lu samples/sec\n", output_benchmark_sample_count);
output_benchmark_sample_count = 0LL;
last_time = v1;
}
}
while ( output_benchmark_thread_running );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
time_t v1; // rbx
char v3[2]; // [rsp+0h] [rbp-Ch] BYREF
char v4[10]; // [rsp+2h] [rbp-Ah] BYREF

if ( !output_benchmark_thread_running )
return 0LL;
do
{
v1 = time(0LL);
if ( (unsigned int)player_read(output_benchmark_player, v4, v3) != 2 )
*(_DWORD *)(output_benchmark_player + 168) = 0;
++output_benchmark_sample_count;
if ( last_time != v1 )
{
printf("%lu samples/sec\n", output_benchmark_sample_count);
output_benchmark_sample_count = 0LL;
last_time = v1;
}
}
while ( output_benchmark_thread_running );
return 0LL;
}

original_code:
void * output_benchmark_writer(void * p) {
    sample_t mix_l, mix_r;
    time_t current_time;
    int ret;
    while (output_benchmark_thread_running) {
        current_time = time(0);
        ret = player_read((player_t *)output_benchmark_player, &mix_l, &mix_r);
        if (ret != 2)
            output_benchmark_player->playing = 0;
        output_benchmark_sample_count++;
        if (current_time != last_time) {
            printf("%lu samples/sec\n", output_benchmark_sample_count);
            output_benchmark_sample_count = 0;
            last_time = current_time;
        }
    }
    return 0;
}

canonical_original_code:
void *output_benchmark_writer(void *p) {
    short mix_l; short mix_r;
    long current_time;
    int ret;
    while (output_benchmark_thread_running) {
        current_time = time(0);
        ret = player_read((struct player_t *)output_benchmark_player, &mix_l, &mix_r);
        if (ret != 2)
            output_benchmark_player->playing = 0;
        output_benchmark_sample_count++;
        if (current_time != last_time) {
            printf("%lu samples/sec\n", output_benchmark_sample_count);
            output_benchmark_sample_count = 0;
            last_time = current_time;
        }
    }
    return 0;
}

variable_types:
p
void *

variable_types: ret int

return_type: void *

user_defined_types: struct player_t { struct player_channel_t *channels; struct module_t *module; void (**effect_map)(struct player_t *, int); void (*newrow_action)(struct player_t *, struct module_pattern_data_t *, int); void *callback_user_ptr; void (*order_callback)(struct player_t *, void *user_ptr); void (*row_callback)(struct player_t *, void *user_ptr); void (*tick_callback)(struct player_t *, void *user_ptr); void (*channel_sample_callback)(struct player_t *, void *user_ptr); unsigned int channel_sample_callback_mask; unsigned short *period_table; enum player_resampling_t resampling; enum defs_mod_paulafreq_index_t paula_freq_index; int protracker_strict_mode; unsigned short period_top; unsigned short period_bottom; unsigned char speed; unsigned short bpm; float tick_pos; float tick_duration; unsigned int sample_rate; int current_tick; int current_pattern; int current_order; int current_row; int do_break; int next_order; int next_row; int pattern_delay; int pattern_delay_active; int loop_module; int loop_pattern; int solo_channel; int playing; }

user_defined_types: enum player_resampling_t { player_resampling_none=0, player_resampling_linear=1 }

user_defined_types: enum defs_mod_paulafreq_index_t { PAL=0, NTSC=1 }

user_defined_types: struct player_channel_t { unsigned char sample_num; float sample_pos; float sample_step; int period_index; unsigned short period; unsigned int frequency; unsigned char sample_delay; unsigned short dest_period; unsigned char dest_sample_num; char dest_volume; unsigned char panning; char volume; char volume_master; unsigned char effect_num; unsigned char effect_value; unsigned char effect_last_value[26]; unsigned char effect_last_value_y[26]; int vibrato_state; int tremolo_state; int tremor_state; unsigned char vibrato_waveform; unsigned char tremolo_waveform; unsigned char pattern_loop_position; unsigned char pattern_loop_count; }

user_defined_types: struct module_t { char song_title[21]; struct module_info_t module_info; enum module_type_t module_type; unsigned short num_channels; unsigned short num_samples; unsigned short num_instruments; unsigned short num_patterns; unsigned short num_orders; unsigned char orders[256]; struct module_sample_t *samples; struct module_instrument_t *instruments; struct module_pattern_t *patterns; unsigned char initial_speed; unsigned char initial_bpm; unsigned char initial_master_volume; unsigned char mix_volume; unsigned char initial_panning[64]; unsigned char channel_volume[64]; unsigned char panning_separation; char *song_message; }

user_defined_types: struct module_info_t { char default_file_extension[8]; char description[64]; union { struct { char signature[8]; } flags_mod; struct { unsigned char st2vibrato; unsigned char st2tempo; unsigned char amigaslides; unsigned char amigalimits; unsigned char st30volumeslides; unsigned short st3_version; unsigned char default_panning; unsigned char mono; } flags_s3m; struct { unsigned char version_major; unsigned char version_minor; } flags_stm; struct { unsigned char stereo; unsigned char use_instruments; unsigned char linear_slides; unsigned char old_effects; unsigned char g_effect_link_memory; unsigned short created_with; unsigned short compatible_with; } flags_it; }; }

user_defined_types: enum module_type_t { module_type_mod=0, module_type_s3m=1, module_type_mtm=2, module_type_stm=3, module_type_it=4 }

user_defined_types: struct module_sample_t { struct module_sample_header_t header; short *data; }

user_defined_types: struct module_instrument_t { char name[26]; unsigned char new_note_action; unsigned char duplicate_check_type; unsigned char duplicate_check_action; unsigned char fadeout; char pitch_pan_separation; unsigned char pitch_pan_center; unsigned char default_pan; unsigned char random_volume_variation; unsigned char random_panning_variation; unsigned char note_sample_table[240]; struct module_instrument_envelope_t volume_envelope; struct module_instrument_envelope_t pan_envelope; struct module_instrument_envelope_t pitch_envelope; }

user_defined_types: struct module_pattern_t { unsigned short num_rows; struct module_pattern_row_t *rows; }

user_defined_types: struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; }

user_defined_types: struct module_instrument_envelope_t { unsigned char flags; unsigned char num_nodes; unsigned char loop_start; unsigned char loop_end; unsigned char susloop_start; unsigned char susloop_end; struct module_instrument_envelope_node_t *nodes; }

user_defined_types: struct module_pattern_row_t { struct module_pattern_data_t *data; }

user_defined_types: struct module_instrument_envelope_node_t { unsigned char value; unsigned short tick; }

user_defined_types: struct module_pattern_data_t { unsigned char sample_num; int period_index; char volume; unsigned char effect_num; unsigned char effect_value; }


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

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

original_code:
int output_benchmark_init(output_opts_t * output_opts)
{
    return 0;
}

canonical_original_code:
int output_benchmark_init(struct output_opts_t *output_opts)
{
    return 0;
}

variable_types: struct output_opts_t { enum output_drivers_t { output_driver_portaudio=0, output_driver_alsa=1, output_driver_raw=2, output_driver_benchmark=3, output_driver_sb16=4 } driver; int buffer_size; int sample_rate; char *output_device; } *

return_type: int

user_defined_types: struct output_opts_t { enum output_drivers_t driver; int buffer_size; int sample_rate; char *output_device; }


decompiled_code:
_BOOL8 __fastcall output_benchmark_start(__int64 a1)
{
output_benchmark_player = a1;
output_benchmark_thread_running = 1;
last_time = time(0LL);
output_benchmark_sample_count = 0LL;
*(_DWORD *)(a1 + 168) = 1;
return pthread_create(&output_benchmark_thread, 0LL, output_benchmark_writer, 0LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
output_benchmark_player = a1;
output_benchmark_thread_running = 1;
last_time = time(0LL);
output_benchmark_sample_count = 0LL;
*(_DWORD *)(a1 + 168) = 1;
return pthread_create(&output_benchmark_thread, 0LL, output_benchmark_writer, 0LL) != 0;
}

original_code:
int output_benchmark_start(player_t * player) {
    output_benchmark_player = player;
    output_benchmark_thread_running = 1;
    last_time = time(0);
    output_benchmark_sample_count = 0;
    player->playing = 1;
    if (pthread_create(&output_benchmark_thread, 0, output_benchmark_writer, 0))
        return 1;
    return 0;
}

canonical_original_code:
int output_benchmark_start(struct player_t *player) {
    output_benchmark_player = player;
    output_benchmark_thread_running = 1;
    last_time = time(0);
    output_benchmark_sample_count = 0;
    player->playing = 1;
    if (pthread_create(&output_benchmark_thread, 0, output_benchmark_writer, 0))
        return 1;
    return 0;
}

variable_types: struct player_t { struct player_channel_t { unsigned char sample_num; float sample_pos; float sample_step; int period_index; unsigned short period; unsigned int frequency; unsigned char sample_delay; unsigned short dest_period; unsigned char dest_sample_num; char dest_volume; unsigned char panning; char volume; char volume_master; unsigned char effect_num; unsigned char effect_value; unsigned char effect_last_value[26]; unsigned char effect_last_value_y[26]; int vibrato_state; int tremolo_state; int tremor_state; unsigned char vibrato_waveform; unsigned char tremolo_waveform; unsigned char pattern_loop_position; unsigned char pattern_loop_count; } *channels; struct module_t { char song_title[21]; struct module_info_t { char default_file_extension[8]; char description[64]; union { struct { char signature[8]; } flags_mod; struct { unsigned char st2vibrato; unsigned char st2tempo; unsigned char amigaslides; unsigned char amigalimits; unsigned char st30volumeslides; unsigned short st3_version; unsigned char default_panning; unsigned char mono; } flags_s3m; struct { unsigned char version_major; unsigned char version_minor; } flags_stm; struct { unsigned char stereo; unsigned char use_instruments; unsigned char linear_slides; unsigned char old_effects; unsigned char g_effect_link_memory; unsigned short created_with; unsigned short compatible_with; } flags_it; }; } module_info; enum module_type_t { module_type_mod=0, module_type_s3m=1, module_type_mtm=2, module_type_stm=3, module_type_it=4 } module_type; unsigned short num_channels; unsigned short num_samples; unsigned short num_instruments; unsigned short num_patterns; unsigned short num_orders; unsigned char orders[256]; struct module_sample_t { struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; } header; short *data; } *samples; struct module_instrument_t { char name[26]; unsigned char new_note_action; unsigned char duplicate_check_type; unsigned char duplicate_check_action; unsigned char fadeout; char pitch_pan_separation; unsigned char pitch_pan_center; unsigned char default_pan; unsigned char random_volume_variation; unsigned char random_panning_variation; unsigned char note_sample_table[240]; struct module_instrument_envelope_t { unsigned char flags; unsigned char num_nodes; unsigned char loop_start; unsigned char loop_end; unsigned char susloop_start; unsigned char susloop_end; struct module_instrument_envelope_node_t { unsigned char value; unsigned short tick; } *nodes; } volume_envelope; struct module_instrument_envelope_t pan_envelope; struct module_instrument_envelope_t pitch_envelope; } *instruments; struct module_pattern_t { unsigned short num_rows; struct module_pattern_row_t { struct module_pattern_data_t { unsigned char sample_num; int period_index; char volume; unsigned char effect_num; unsigned char effect_value; } *data; } *rows; } *patterns; unsigned char initial_speed; unsigned char initial_bpm; unsigned char initial_master_volume; unsigned char mix_volume; unsigned char initial_panning[64]; unsigned char channel_volume[64]; unsigned char panning_separation; char *song_message; } *module; void (**effect_map)(struct player_t *, int); void (*newrow_action)(struct player_t *, struct module_pattern_data_t *, int); void *callback_user_ptr; void (*order_callback)(struct player_t *, void *user_ptr); void (*row_callback)(struct player_t *, void *user_ptr); void (*tick_callback)(struct player_t *, void *user_ptr); void (*channel_sample_callback)(struct player_t *, void *user_ptr); unsigned int channel_sample_callback_mask; unsigned short *period_table; enum player_resampling_t { player_resampling_none=0, player_resampling_linear=1 } resampling; enum defs_mod_paulafreq_index_t { PAL=0, NTSC=1 } paula_freq_index; int protracker_strict_mode; unsigned short period_top; unsigned short period_bottom; unsigned char speed; unsigned short bpm; float tick_pos; float tick_duration; unsigned int sample_rate; int current_tick; int current_pattern; int current_order; int current_row; int do_break; int next_order; int next_row; int pattern_delay; int pattern_delay_active; int loop_module; int loop_pattern; int solo_channel; int playing; } *


decompiled_code:
__int64 output_benchmark_stop()
{
output_benchmark_thread_running = 0;
pthread_join(output_benchmark_thread, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
output_benchmark_thread_running = 0;
pthread_join(output_benchmark_thread, 0LL);
return 0LL;
}

original_code:
int output_benchmark_stop() {
    output_benchmark_thread_running = 0;
    pthread_join(output_benchmark_thread, 0);
    return 0;
}


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

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

original_code:
int output_benchmark_cleanup() {
    return 0;
}


decompiled_code:
__int64 __fastcall player_command_next_order(__int64 a1)
{
int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 128);
result = (unsigned int)*(unsigned __int16 *)(*(_QWORD *)(a1 + 8) + 116LL) - 1;
if ( v1 < (int)result )
*(_DWORD *)(a1 + 140) = v1 + 1;
*(_DWORD *)(a1 + 144) = 0;
*(_DWORD *)(a1 + 136) = 1;
return result;
}

original_code:
void player_command_next_order(player_t * player)
{
    if (player->current_order < (player->module->num_orders - 1))
        player->next_order = player->current_order + 1;
    player->next_row = 0;
    player->do_break = 1;
}

canonical_original_code:
void player_command_next_order(struct player_t *player)
{
    if (player->current_order < (player->module->num_orders - 1))
        player->next_order = player->current_order + 1;
    player->next_row = 0;
    player->do_break = 1;
}

return_type: void


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

if ( a2 == 1 )
return player_command_next_order((__int64)a1);
if ( a2 == 2 )
result = player_command_prev_order(a1);
return result;
}

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

if ( a2 == 1 )
return func0((__int64)a1);
if ( a2 == 2 )
result = func1(a1);
return result;
}

original_code:
void player_command_action_dispatch(player_t * player, player_command_action_t action)
{
    switch(action) {
        case player_command_action_next_order: player_command_next_order(player); break;
        case player_command_action_prev_order: player_command_prev_order(player); break;
        default: break;
    }
}

canonical_original_code:
void player_command_action_dispatch(struct player_t *player, enum player_command_action_t action)
{
    switch(action) {
        case player_command_action_next_order: player_command_next_order(player); break;
        case player_command_action_prev_order: player_command_prev_order(player); break;
        default: break;
    }
}

variable_types: enum player_command_action_t { player_command_action_none=0, player_command_action_next_order=1, player_command_action_prev_order=2, player_command_action_next_song=3, player_command_action_prev_song=4, player_command_action_quit=5 }


decompiled_code:
__int64 __fastcall sample_from_s8(char a1)
{
return (unsigned int)(a1 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (unsigned int)(a1 << 8);
}

original_code: static inline sample_t sample_from_s8(int8_t s) { return (sample_t)s << 8; }

canonical_original_code: static inline short sample_from_s8(char s) { return (short)s << 8; }

variable_types: s char

return_type: short


decompiled_code:
__int16 __fastcall swap_endian_u16(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func1(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static inline uint16_t swap_endian_u16(uint16_t i) {
    return ((i >> 8) | (i << 8));
}

canonical_original_code:
static inline unsigned short swap_endian_u16(unsigned short i) {
    return ((i >> 8) | (i << 8));
}

variable_types:
i
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall swap_endian_u32(unsigned int a1)
{
return (a1 >> 8) & 0xFF00 | (a1 << 8) & 0xFF0000 | (a1 << 24) | HIBYTE(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return (a1 >> 8) & 0xFF00 | (a1 << 8) & 0xFF0000 | (a1 << 24) | HIBYTE(a1);
}

canonical_original_code:
static inline unsigned int swap_endian_u32(unsigned int i) {
    return ((i>>24)&0xff) | ((i<<8)&0xff0000) | ((i>>8)&0xff00) | ((i<<24)&0xff000000);
}

variable_types:
i
unsigned int

return_type: unsigned int


original_code:
int loader_mod_check(io_handle_t * h)
{
    int r, i;
    uint32_t signature = 0;
    size_t saved_pos;
    char tmp[5];
    saved_pos = h->tell(h);
    h->seek(h, 0x438, 0);
    r = h->read(&signature, 1, 4, h);
    h->seek(h, saved_pos, io_seek_set);
    if (r != 4)
        return 0;
    for (i = 0; i < loader_mod_num_modtypes; i++) {
        if (signature == loader_mod_modtypes[i].signature)
            return 1;
    }
    for (i = 10; i <= 32; i += 2) {
        sprintf(tmp, "%02iCH", i);
        if (memcmp (&signature, tmp, 4) == 0)
            return 1;
    }
    return 0;
}

canonical_original_code:
int loader_mod_check(struct io_handle_t *h)
{
    int r; int i;
    unsigned int signature = 0;
    unsigned long saved_pos;
    char tmp[5];
    saved_pos = h->tell(h);
    h->seek(h, 0x438, 0);
    r = h->read(&signature, 1, 4, h);
    h->seek(h, saved_pos, io_seek_set);
    if (r != 4)
        return 0;
    for (i = 0; i < loader_mod_num_modtypes; i++) {
        if (signature == loader_mod_modtypes[i].signature)
            return 1;
    }
    for (i = 10; i <= 32; i += 2) {
        sprintf(tmp, "%02iCH", i);
        if (memcmp (&signature, tmp, 4) == 0)
            return 1;
    }
    return 0;
}

variable_types: struct io_handle_t { void *native_handle; unsigned long (*read)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); unsigned long (*write)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); int (*seek)(struct io_handle_t *handle, unsigned long n, enum io_seek_direction_t { io_seek_set=0, io_seek_end=1, io_seek_cur=2 } direction); unsigned long (*tell)(struct io_handle_t *handle); int (*feof)(struct io_handle_t *handle); } *

variable_types: r int

variable_types: i int

variable_types:
signature
unsigned int

variable_types:
tmp
char [5]

user_defined_types: struct io_handle_t { void *native_handle; unsigned long (*read)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); unsigned long (*write)(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle); int (*seek)(struct io_handle_t *handle, unsigned long n, enum io_seek_direction_t direction); unsigned long (*tell)(struct io_handle_t *handle); int (*feof)(struct io_handle_t *handle); }


original_code:
int loader_mod_read_sample_header(module_sample_header_t * hdr, io_handle_t * h)
{
    uint16_t word;
    uint8_t byte;
    int8_t sbyte;
    int r;
    r = h->read (&(hdr->name), 1, 22, h);
    if (r != 22)
        return 1;
    hdr->name[22] = 0;
    r = h->read (&word, 2, 1, h);
    if (r != 1)
        return 1;
    hdr->length = swap_endian_u16(word) << 1;
    r = h->read (&sbyte, 1, 1, h);
    if (r != 1)
        return 1;
    hdr->finetune = sbyte & 0xf;
    r = h->read (&byte, 1, 1, h);
    if (r != 1)
        return 1;
    hdr->volume = byte;
    r = h->read (&word, 2, 1, h);
    if (r != 1)
        return 1;
    hdr->loop_start = (swap_endian_u16(word) << 1);
    r = h->read (&word, 2, 1, h);
    if (r != 1)
        return 1;
    hdr->loop_length = (swap_endian_u16(word) << 1);
    hdr->loop_end = (hdr->loop_length + hdr->loop_start) - 1;
    hdr->loop_enabled = 0;
    if (hdr->loop_length > 2)
        hdr->loop_enabled = 1;
    return 0;
}

canonical_original_code:
int loader_mod_read_sample_header(struct module_sample_header_t *hdr, struct io_handle_t *h)
{
    unsigned short word;
    unsigned char byte;
    char sbyte;
    int r;
    r = h->read (&(hdr->name), 1, 22, h);
    if (r != 22)
        return 1;
    hdr->name[22] = 0;
    r = h->read (&word, 2, 1, h);
    if (r != 1)
        return 1;
    hdr->length = swap_endian_u16(word) << 1;
    r = h->read (&sbyte, 1, 1, h);
    if (r != 1)
        return 1;
    hdr->finetune = sbyte & 0xf;
    r = h->read (&byte, 1, 1, h);
    if (r != 1)
        return 1;
    hdr->volume = byte;
    r = h->read (&word, 2, 1, h);
    if (r != 1)
        return 1;
    hdr->loop_start = (swap_endian_u16(word) << 1);
    r = h->read (&word, 2, 1, h);
    if (r != 1)
        return 1;
    hdr->loop_length = (swap_endian_u16(word) << 1);
    hdr->loop_end = (hdr->loop_length + hdr->loop_start) - 1;
    hdr->loop_enabled = 0;
    if (hdr->loop_length > 2)
        hdr->loop_enabled = 1;
    return 0;
}

variable_types: struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; } *

variable_types:
word
unsigned short

variable_types:
byte
unsigned char

variable_types: sbyte char

user_defined_types: enum io_seek_direction_t { io_seek_set=0, io_seek_end=1, io_seek_cur=2 }


original_code:
void loader_mod_read_sample_data(module_sample_t * sample, io_handle_t * h)
{
    int i;
    int8_t s;
    if (sample->header.length == 0) {
        sample->data = ((void *)0);
        return;
    }
    sample->data = (sample_t *)malloc(sizeof(sample_t) * sample->header.length);
    for (i = 0; i < sample->header.length; i++) {
        h->read(&s, 1, 1, h);
        sample->data[i] = sample_from_s8(s);
    }
}

canonical_original_code:
void loader_mod_read_sample_data(struct module_sample_t *sample, struct io_handle_t *h)
{
    int i;
    char s;
    if (sample->header.length == 0) {
        sample->data = ((void *)0);
        return;
    }
    sample->data = (short *)malloc(sizeof(sample_t) * sample->header.length);
    for (i = 0; i < sample->header.length; i++) {
        h->read(&s, 1, 1, h);
        sample->data[i] = sample_from_s8(s);
    }
}

variable_types: struct module_sample_t { struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; } header; short *data; } *


decompiled_code:
__int64 __fastcall loader_mod_lookup_period_index(__int16 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( defs_mod_periods[v1] == a1 )
break;
if ( ++v1 == 60 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int16 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( defs_mod_periods[v1] == a1 )
break;
if ( ++v1 == 60 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int loader_mod_lookup_period_index(const uint16_t period)
{
    int i;
    for (i = 0; i < defs_mod_num_periods; i++) {
        if (defs_mod_periods[i] == period)
            return i;
    }
    return -1;
}

canonical_original_code:
int loader_mod_lookup_period_index(unsigned short period)
{
    int i;
    for (i = 0; i < defs_mod_num_periods; i++) {
        if (defs_mod_periods[i] == period)
            return i;
    }
    return -1;
}

variable_types:
period
unsigned short


decompiled_code:
__int64 __fastcall loader_mod_read_pattern_data(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // eax
__int16 v5; // r13
unsigned int v6; // ebx
int v7; // eax
char v8; // dl
__int64 v9; // rax
unsigned int v10; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = (*(__int64 (__fastcall **)(unsigned int *, __int64, __int64, __int64))(a2 + 8))(&v10, 4LL, 1LL, a2);
result = 1LL;
if ( v2 == 1 )
{
v4 = swap_endian_u32(v10);
v10 = v4;
*(_BYTE *)a1 = ((unsigned __int16)v4 >> 12) | HIBYTE(v4) & 0xF0;
v5 = HIWORD(v4) & 0xFFF;
v6 = HIWORD(v4) & 0xFFF;
v7 = loader_mod_lookup_period_index(HIWORD(v4) & 0xFFF);
*(_DWORD *)(a1 + 4) = v7;
if ( v7 == -1 )
{
if ( v5 )
{
v9 = (*(__int64 (__fastcall **)(__int64))(a2 + 32))(a2);
fprintf(stderr, "Loader: WARNING: Non-standard period: %i @ %x\n", v6, v9);
}
}
v8 = v10;
*(_BYTE *)(a1 + 9) = BYTE1(v10) & 0xF;
*(_BYTE *)(a1 + 10) = v8;
*(_BYTE *)(a1 + 8) = -1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // eax
__int16 v5; // r13
unsigned int v6; // ebx
int v7; // eax
char v8; // dl
__int64 v9; // rax
unsigned int v10; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = (*(__int64 (__fastcall **)(unsigned int *, __int64, __int64, __int64))(a2 + 8))(&v10, 4LL, 1LL, a2);
result = 1LL;
if ( v2 == 1 )
{
v4 = func2(v10);
v10 = v4;
*(_BYTE *)a1 = ((unsigned __int16)v4 >> 12) | HIBYTE(v4) & 0xF0;
v5 = HIWORD(v4) & 0xFFF;
v6 = HIWORD(v4) & 0xFFF;
v7 = func6(HIWORD(v4) & 0xFFF);
*(_DWORD *)(a1 + 4) = v7;
if ( v7 == -1 )
{
if ( v5 )
{
v9 = (*(__int64 (__fastcall **)(__int64))(a2 + 32))(a2);
fprintf(stderr, "Loader: WARNING: Non-standard period: %i @ %x\n", v6, v9);
}
}
v8 = v10;
*(_BYTE *)(a1 + 9) = BYTE1(v10) & 0xF;
*(_BYTE *)(a1 + 10) = v8;
*(_BYTE *)(a1 + 8) = -1;
result = 0LL;
}
return result;
}

original_code:
int loader_mod_read_pattern_data(module_pattern_data_t * data, io_handle_t * h)
{
    uint32_t dw;
    uint16_t tmp;
    int r;
    r = h->read(&dw, 4, 1, h);
    if (r != 1)
        return 1;
    dw = swap_endian_u32(dw);
    data->sample_num = ((uint8_t)(dw >> 24) & 0xf0) | ((uint8_t)(dw >> 12) & 0x0f);
    tmp = (uint16_t)((dw >> 16) & 0x0fff);
    data->period_index = loader_mod_lookup_period_index(tmp);
    if (tmp && data->period_index == -1) {
        fprintf(stderr, "Loader: WARNING: Non-standard period: %i @ %x\n", tmp, (unsigned int)h->tell(h));
    }
    data->effect_num = (uint8_t)((dw & 0x0f00) >> 8);
    data->effect_value = (uint8_t)(dw & 0xff);
    data->volume = -1;
    return 0;
}

canonical_original_code:
int loader_mod_read_pattern_data(struct module_pattern_data_t *data, struct io_handle_t *h)
{
    unsigned int dw;
    unsigned short tmp;
    int r;
    r = h->read(&dw, 4, 1, h);
    if (r != 1)
        return 1;
    dw = swap_endian_u32(dw);
    data->sample_num = ((unsigned char)(dw >> 24) & 0xf0) | ((unsigned char)(dw >> 12) & 0x0f);
    tmp = (unsigned short)((dw >> 16) & 0x0fff);
    data->period_index = loader_mod_lookup_period_index(tmp);
    if (tmp && data->period_index == -1) {
        fprintf(stderr, "Loader: WARNING: Non-standard period: %i @ %x\n", tmp, (unsigned int)h->tell(h));
    }
    data->effect_num = (unsigned char)((dw & 0x0f00) >> 8);
    data->effect_value = (unsigned char)(dw & 0xff);
    data->volume = -1;
    return 0;
}

variable_types: struct module_pattern_data_t { unsigned char sample_num; int period_index; char volume; unsigned char effect_num; unsigned char effect_value; } *

variable_types:
dw
unsigned int

variable_types:
tmp
unsigned short


original_code:
module_t * loader_mod_load(io_handle_t * h)
{
    int i, j, k, r;
    uint8_t tmp8;
    char tmp[5];
    uint32_t signature;
    module_t * module = (module_t *)malloc(sizeof(module_t));
    if (!module)
        return 0;
    module->module_type = module_type_mod;
    module->initial_bpm = 125;
    module->initial_speed = 6;
    module->instruments = 0;
    module->num_instruments = 0;
    h->seek(h, 0x438, 0);
    r = h->read(&signature, 1, 4, h);
    if (r != 4) {
        free(module);
        return 0;
    }
    module->num_samples = 0;
    for (i = 0; i < loader_mod_num_modtypes; i++) {
        if (signature == loader_mod_modtypes[i].signature) {
            module->num_channels = loader_mod_modtypes[i].num_channels;
            module->num_samples = 31;
            memcpy(module->module_info.flags_mod.signature, &signature, 4);
            module->module_info.flags_mod.signature[4] = 0;
            strcpy(module->module_info.description, loader_mod_modtypes[i].description);
            strcpy(module->module_info.default_file_extension, "MOD");
            break;
        }
    }
    for (i = 10; i <= 32; i += 2) {
        sprintf(tmp, "%02iCH", i);
        if (memcmp (&signature, tmp, 4) == 0) {
            module->num_channels = i;
            module->num_samples = 31;
            memcpy(module->module_info.flags_mod.signature, &signature, 4);
            module->module_info.flags_mod.signature[4] = 0;
            strcpy(module->module_info.description, "Fasttracker Multichannel MOD");
            strcpy(module->module_info.default_file_extension, "MOD");
            break;
        }
    }
    if (module->num_samples == 0) {
        module->num_samples = 15;
        module->num_channels = 4;
        strcpy(module->module_info.default_file_extension, "STK");
        strcpy(module->module_info.flags_mod.signature, "(none)");
        strcpy(module->module_info.description, "Amiga Ultimate Soundtracker module");
    }
    h->seek(h, 0, io_seek_set);
    r = h->read(module->song_title, 1, 20, h);
    if (r != 20) {
        free(module);
        return 0;
    }
    module->samples = (module_sample_t *)malloc(sizeof(module_sample_t) * module->num_samples);
    for (i = 0; i < module->num_samples; i++) {
        if (loader_mod_read_sample_header(&(module->samples[i].header), h)) {
            free(module);
            return 0;
        }
    }
    r = h->read(&tmp8, 1, 1, h);
    if (r != 1) {
        free(module);
        return 0;
    }
    module->num_orders = (uint16_t)tmp8;
    r = h->read(&tmp8, 1, 1, h);
    if (r != 1) {
        free(module);
        return 0;
    }
    r = h->read(&(module->orders), 1, 128, h);
    if (r != 128) {
        free(module);
        return 0;
    }
    if (module->num_samples > 15) {
        r = h->read(&signature, 4, 1, h);
        if (r != 1) {
            free(module);
            return 0;
        }
    }
    module->num_patterns = 0;
    for (i = 0;i < module->num_orders; i++) {
        if (module->orders[i] > module->num_patterns)
            module->num_patterns = module->orders[i];
    }
    module->num_patterns++;
    module->patterns = (module_pattern_t *)malloc(sizeof(module_pattern_t) * module->num_patterns);
    for (i = 0; i < module->num_patterns; i++) {
        module->patterns[i].num_rows = 64;
        module->patterns[i].rows = (module_pattern_row_t *)malloc(sizeof(module_pattern_row_t) * module->patterns[i].num_rows);
        for (j = 0; j < module->patterns[i].num_rows; j++) {
            module->patterns[i].rows[j].data = (module_pattern_data_t *)malloc(sizeof(module_pattern_data_t) * module->num_channels);
            for (k = 0; k < module->num_channels; k++) {
                if(loader_mod_read_pattern_data (&(module->patterns[i].rows[j].data[k]), h)) {
                    free(module);
                    return 0;
                }
            }
        }
    }
    for (i = 0; i < module->num_samples; i++)
        loader_mod_read_sample_data(&(module->samples[i]), h);
    for (i = 0; i < module->num_channels; i++) {
        if (((i % 4) == 1) || ((i % 4) == 2))
            module->initial_panning[i] = 0xff;
        else
            module->initial_panning[i] = 0x00;
    }
    module->song_message = 0;
    return module;
}

canonical_original_code:
struct module_t *loader_mod_load(struct io_handle_t *h)
{
    int i; int j; int k; int r;
    unsigned char tmp8;
    char tmp[5];
    unsigned int signature;
    struct module_t *module = (module_t *)malloc(sizeof(module_t));
    if (!module)
        return 0;
    module->module_type = module_type_mod;
    module->initial_bpm = 125;
    module->initial_speed = 6;
    module->instruments = 0;
    module->num_instruments = 0;
    h->seek(h, 0x438, 0);
    r = h->read(&signature, 1, 4, h);
    if (r != 4) {
        free(module);
        return 0;
    }
    module->num_samples = 0;
    for (i = 0; i < loader_mod_num_modtypes; i++) {
        if (signature == loader_mod_modtypes[i].signature) {
            module->num_channels = loader_mod_modtypes[i].num_channels;
            module->num_samples = 31;
            memcpy(module->module_info.flags_mod.signature, &signature, 4);
            module->module_info.flags_mod.signature[4] = 0;
            strcpy(module->module_info.description, loader_mod_modtypes[i].description);
            strcpy(module->module_info.default_file_extension, "MOD");
            break;
        }
    }
    for (i = 10; i <= 32; i += 2) {
        sprintf(tmp, "%02iCH", i);
        if (memcmp (&signature, tmp, 4) == 0) {
            module->num_channels = i;
            module->num_samples = 31;
            memcpy(module->module_info.flags_mod.signature, &signature, 4);
            module->module_info.flags_mod.signature[4] = 0;
            strcpy(module->module_info.description, "Fasttracker Multichannel MOD");
            strcpy(module->module_info.default_file_extension, "MOD");
            break;
        }
    }
    if (module->num_samples == 0) {
        module->num_samples = 15;
        module->num_channels = 4;
        strcpy(module->module_info.default_file_extension, "STK");
        strcpy(module->module_info.flags_mod.signature, "(none)");
        strcpy(module->module_info.description, "Amiga Ultimate Soundtracker module");
    }
    h->seek(h, 0, io_seek_set);
    r = h->read(module->song_title, 1, 20, h);
    if (r != 20) {
        free(module);
        return 0;
    }
    module->samples = (struct module_sample_t *)malloc(sizeof(module_sample_t) * module->num_samples);
    for (i = 0; i < module->num_samples; i++) {
        if (loader_mod_read_sample_header(&(module->samples[i].header), h)) {
            free(module);
            return 0;
        }
    }
    r = h->read(&tmp8, 1, 1, h);
    if (r != 1) {
        free(module);
        return 0;
    }
    module->num_orders = (unsigned short)tmp8;
    r = h->read(&tmp8, 1, 1, h);
    if (r != 1) {
        free(module);
        return 0;
    }
    r = h->read(&(module->orders), 1, 128, h);
    if (r != 128) {
        free(module);
        return 0;
    }
    if (module->num_samples > 15) {
        r = h->read(&signature, 4, 1, h);
        if (r != 1) {
            free(module);
            return 0;
        }
    }
    module->num_patterns = 0;
    for (i = 0;i < module->num_orders; i++) {
        if (module->orders[i] > module->num_patterns)
            module->num_patterns = module->orders[i];
    }
    module->num_patterns++;
    module->patterns = (struct module_pattern_t *)malloc(sizeof(module_pattern_t) * module->num_patterns);
    for (i = 0; i < module->num_patterns; i++) {
        module->patterns[i].num_rows = 64;
        module->patterns[i].rows = (struct module_pattern_row_t *)malloc(sizeof(module_pattern_row_t) * module->patterns[i].num_rows);
        for (j = 0; j < module->patterns[i].num_rows; j++) {
            module->patterns[i].rows[j].data = (struct module_pattern_data_t *)malloc(sizeof(module_pattern_data_t) * module->num_channels);
            for (k = 0; k < module->num_channels; k++) {
                if(loader_mod_read_pattern_data (&(module->patterns[i].rows[j].data[k]), h)) {
                    free(module);
                    return 0;
                }
            }
        }
    }
    for (i = 0; i < module->num_samples; i++)
        loader_mod_read_sample_data(&(module->samples[i]), h);
    for (i = 0; i < module->num_channels; i++) {
        if (((i % 4) == 1) || ((i % 4) == 2))
            module->initial_panning[i] = 0xff;
        else
            module->initial_panning[i] = 0x00;
    }
    module->song_message = 0;
    return module;
}

variable_types: j int

variable_types: k int

variable_types: struct module_t { char song_title[21]; struct module_info_t { char default_file_extension[8]; char description[64]; union { struct { char signature[8]; } flags_mod; struct { unsigned char st2vibrato; unsigned char st2tempo; unsigned char amigaslides; unsigned char amigalimits; unsigned char st30volumeslides; unsigned short st3_version; unsigned char default_panning; unsigned char mono; } flags_s3m; struct { unsigned char version_major; unsigned char version_minor; } flags_stm; struct { unsigned char stereo; unsigned char use_instruments; unsigned char linear_slides; unsigned char old_effects; unsigned char g_effect_link_memory; unsigned short created_with; unsigned short compatible_with; } flags_it; }; } module_info; enum module_type_t { module_type_mod=0, module_type_s3m=1, module_type_mtm=2, module_type_stm=3, module_type_it=4 } module_type; unsigned short num_channels; unsigned short num_samples; unsigned short num_instruments; unsigned short num_patterns; unsigned short num_orders; unsigned char orders[256]; struct module_sample_t { struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; } header; short *data; } *samples; struct module_instrument_t { char name[26]; unsigned char new_note_action; unsigned char duplicate_check_type; unsigned char duplicate_check_action; unsigned char fadeout; char pitch_pan_separation; unsigned char pitch_pan_center; unsigned char default_pan; unsigned char random_volume_variation; unsigned char random_panning_variation; unsigned char note_sample_table[240]; struct module_instrument_envelope_t { unsigned char flags; unsigned char num_nodes; unsigned char loop_start; unsigned char loop_end; unsigned char susloop_start; unsigned char susloop_end; struct module_instrument_envelope_node_t { unsigned char value; unsigned short tick; } *nodes; } volume_envelope; struct module_instrument_envelope_t pan_envelope; struct module_instrument_envelope_t pitch_envelope; } *instruments; struct module_pattern_t { unsigned short num_rows; struct module_pattern_row_t { struct module_pattern_data_t { unsigned char sample_num; int period_index; char volume; unsigned char effect_num; unsigned char effect_value; } *data; } *rows; } *patterns; unsigned char initial_speed; unsigned char initial_bpm; unsigned char initial_master_volume; unsigned char mix_volume; unsigned char initial_panning[64]; unsigned char channel_volume[64]; unsigned char panning_separation; char *song_message; } *


decompiled_code:
__int64 __fastcall output_raw_init(__int64 a1)
{
output_raw_file = 0LL;
output_raw_filename = *(char **)(a1 + 16);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
output_raw_file = 0LL;
output_raw_filename = *(char **)(a1 + 16);
return 0LL;
}

original_code:
int output_raw_init(output_opts_t * output_opts)
{
    output_raw_file = 0;
    output_raw_filename = output_opts->output_device;
    return 0;
}

canonical_original_code:
int output_raw_init(struct output_opts_t *output_opts)
{
    output_raw_file = 0;
    output_raw_filename = output_opts->output_device;
    return 0;
}

variable_types: struct output_opts_t { enum output_drivers_t { output_driver_portaudio=0, output_driver_alsa=1, output_driver_raw=2, output_driver_benchmark=3, output_driver_sb16=4 } driver; int buffer_size; int sample_rate; char *output_device; } *


decompiled_code:
_BOOL8 __fastcall output_raw_start(__int64 a1)
{
_BOOL4 v1; // edx

output_raw_player = a1;
thread_running = 1;
*(_DWORD *)(a1 + 168) = 1;
output_raw_file = fopen(output_raw_filename, "wb");
v1 = 1;
if ( output_raw_file )
v1 = pthread_create(&writer_thread, 0LL, output_raw_writer, 0LL) != 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
_BOOL4 v1; // edx

output_raw_player = a1;
thread_running = 1;
*(_DWORD *)(a1 + 168) = 1;
output_raw_file = fopen(output_raw_filename, "wb");
v1 = 1;
if ( output_raw_file )
v1 = pthread_create(&writer_thread, 0LL, output_raw_writer, 0LL) != 0;
return v1;
}

original_code:
int output_raw_start(player_t * player) {
    output_raw_player = player;
    thread_running = 1;
    player->playing = 1;
    output_raw_file = fopen(output_raw_filename, "wb");
    if (output_raw_file == 0)
        return 1;
    if (pthread_create(&writer_thread, 0, output_raw_writer, 0))
        return 1;
    return 0;
}

canonical_original_code:
int output_raw_start(struct player_t *player) {
    output_raw_player = player;
    thread_running = 1;
    player->playing = 1;
    output_raw_file = fopen(output_raw_filename, "wb");
    if (output_raw_file == 0)
        return 1;
    if (pthread_create(&writer_thread, 0, output_raw_writer, 0))
        return 1;
    return 0;
}

variable_types: struct player_t { struct player_channel_t { unsigned char sample_num; float sample_pos; float sample_step; int period_index; unsigned short period; unsigned int frequency; unsigned char sample_delay; unsigned short dest_period; unsigned char dest_sample_num; char dest_volume; unsigned char panning; char volume; char volume_master; unsigned char effect_num; unsigned char effect_value; unsigned char effect_last_value[26]; unsigned char effect_last_value_y[26]; int vibrato_state; int tremolo_state; int tremor_state; unsigned char vibrato_waveform; unsigned char tremolo_waveform; unsigned char pattern_loop_position; unsigned char pattern_loop_count; } *channels; struct module_t { char song_title[21]; struct module_info_t { char default_file_extension[8]; char description[64]; union { struct { char signature[8]; } flags_mod; struct { unsigned char st2vibrato; unsigned char st2tempo; unsigned char amigaslides; unsigned char amigalimits; unsigned char st30volumeslides; unsigned short st3_version; unsigned char default_panning; unsigned char mono; } flags_s3m; struct { unsigned char version_major; unsigned char version_minor; } flags_stm; struct { unsigned char stereo; unsigned char use_instruments; unsigned char linear_slides; unsigned char old_effects; unsigned char g_effect_link_memory; unsigned short created_with; unsigned short compatible_with; } flags_it; }; } module_info; enum module_type_t { module_type_mod=0, module_type_s3m=1, module_type_mtm=2, module_type_stm=3, module_type_it=4 } module_type; unsigned short num_channels; unsigned short num_samples; unsigned short num_instruments; unsigned short num_patterns; unsigned short num_orders; unsigned char orders[256]; struct module_sample_t { struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; } header; short *data; } *samples; struct module_instrument_t { char name[26]; unsigned char new_note_action; unsigned char duplicate_check_type; unsigned char duplicate_check_action; unsigned char fadeout; char pitch_pan_separation; unsigned char pitch_pan_center; unsigned char default_pan; unsigned char random_volume_variation; unsigned char random_panning_variation; unsigned char note_sample_table[240]; struct module_instrument_envelope_t { unsigned char flags; unsigned char num_nodes; unsigned char loop_start; unsigned char loop_end; unsigned char susloop_start; unsigned char susloop_end; struct module_instrument_envelope_node_t { unsigned char value; unsigned short tick; } *nodes; } volume_envelope; struct module_instrument_envelope_t pan_envelope; struct module_instrument_envelope_t pitch_envelope; } *instruments; struct module_pattern_t { unsigned short num_rows; struct module_pattern_row_t { struct module_pattern_data_t { unsigned char sample_num; int period_index; char volume; unsigned char effect_num; unsigned char effect_value; } *data; } *rows; } *patterns; unsigned char initial_speed; unsigned char initial_bpm; unsigned char initial_master_volume; unsigned char mix_volume; unsigned char initial_panning[64]; unsigned char channel_volume[64]; unsigned char panning_separation; char *song_message; } *module; void (**effect_map)(struct player_t *, int); void (*newrow_action)(struct player_t *, struct module_pattern_data_t *, int); void *callback_user_ptr; void (*order_callback)(struct player_t *, void *user_ptr); void (*row_callback)(struct player_t *, void *user_ptr); void (*tick_callback)(struct player_t *, void *user_ptr); void (*channel_sample_callback)(struct player_t *, void *user_ptr); unsigned int channel_sample_callback_mask; unsigned short *period_table; enum player_resampling_t { player_resampling_none=0, player_resampling_linear=1 } resampling; enum defs_mod_paulafreq_index_t { PAL=0, NTSC=1 } paula_freq_index; int protracker_strict_mode; unsigned short period_top; unsigned short period_bottom; unsigned char speed; unsigned short bpm; float tick_pos; float tick_duration; unsigned int sample_rate; int current_tick; int current_pattern; int current_order; int current_row; int do_break; int next_order; int next_row; int pattern_delay; int pattern_delay_active; int loop_module; int loop_pattern; int solo_channel; int playing; } *

user_defined_types: struct player_t { struct player_channel_t *channels; struct module_t *module; void (**effect_map)(struct player_t *, int); void (*newrow_action)(struct player_t *, struct module_pattern_data_t *, int); void *callback_user_ptr; void (*order_callback)(struct player_t *, void *user_ptr); void (*row_callback)(struct player_t *, void *user_ptr); void (*tick_callback)(struct player_t *, void *user_ptr); void (*channel_sample_callback)(struct player_t *, void *user_ptr); unsigned int channel_sample_callback_mask; unsigned short *period_table; enum player_resampling_t resampling; enum defs_mod_paulafreq_index_t paula_freq_index; int protracker_strict_mode; unsigned short period_top; unsigned short period_bottom; unsigned char speed; unsigned short bpm; float tick_pos; float tick_duration; unsigned int sample_rate; int current_tick; int current_pattern; int current_order; int current_row; int do_break; int next_order; int next_row; int pattern_delay; int pattern_delay_active; int loop_module; int loop_pattern; int solo_channel; int playing; }


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

original_code:
int output_raw_cleanup() {
    return 0;
}

canonical_original_code:
int output_raw_cleanup() {
    return 0;
}


decompiled_code:
int __fastcall ui_periodindex2note(int a1, char *a2, int a3)
{
int result; // eax

result = a1;
*a2 = 46;
a2[1] = 46;
a2[2] = 46;
a2[3] = 0;
if ( a1 == 254 )
{
*(_DWORD *)a2 = 6184542;
}
else if ( a1 >= 0 )
{
result = sprintf(a2, "%s%1u", notes_0[a1 % 12], (unsigned int)(a1 / 12 + a3));
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, char *a2, int a3)
{
int result; // eax

result = a1;
*a2 = 46;
a2[1] = 46;
a2[2] = 46;
a2[3] = 0;
if ( a1 == 254 )
{
*(_DWORD *)a2 = 6184542;
}
else if ( a1 >= 0 )
{
result = sprintf(a2, "%s%1u", notes_0[a1 % 12], (unsigned int)(a1 / 12 + a3));
}
return result;
}

original_code:
void ui_periodindex2note(int period_index, char * dest, int first_octave)
{
    static const char * notes[] = {
        "C-",
        "C#",
        "D-",
        "D#",
        "E-",
        "F-",
        "F#",
        "G-",
        "G#",
        "A-",
        "A#",
        "B-"
    };
    int i;
    for (i=0; i<3; i++)
        dest[i] = '.';
    dest[3] = 0;
    if (period_index == 254) {
        strcpy(dest, "^^^");
        return;
    }
    if (period_index >= 0)
        sprintf(dest, "%s%1u", notes[period_index % 12], (period_index / 12) + first_octave);
}

canonical_original_code:
void ui_periodindex2note(int period_index, char *dest, int first_octave)
{
    static char *notes[] = {
        "C-",
        "C#",
        "D-",
        "D#",
        "E-",
        "F-",
        "F#",
        "G-",
        "G#",
        "A-",
        "A#",
        "B-"
    };
    int i;
    for (i=0; i<3; i++)
        dest[i] = '.';
    dest[3] = 0;
    if (period_index == 254) {
        strcpy(dest, "^^^");
        return;
    }
    if (period_index >= 0)
        sprintf(dest, "%s%1u", notes[period_index % 12], (period_index / 12) + first_octave);
}

variable_types:
dest
char *

variable_types:
notes
char *[]

variable_types: i int


decompiled_code:
int __fastcall ui_map_effect_num(char *a1, int a2, unsigned __int8 a3)
{
int result; // eax

if ( a2 == 1 )
result = sprintf(a1, "%c", (unsigned int)byte_967[a3]);
else
result = sprintf(a1, "%X", a3);
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *a1, int a2, unsigned __int8 a3)
{
int result; // eax

if ( a2 == 1 )
result = sprintf(a1, "%c", (unsigned int)byte_967[a3]);
else
result = sprintf(a1, "%X", a3);
return result;
}

original_code:
void ui_map_effect_num(char * target, const module_type_t type, const uint8_t effect_num)
{
    switch (type) {
        case module_type_s3m:
            sprintf(target, "%c", ".ABCDEFGHIJKLMNOPQRSTUVWXYZ"[effect_num]);
            break;
        case module_type_mtm:
        case module_type_mod:
        default:
            sprintf(target, "%X", effect_num);
            break;
    }
}

canonical_original_code:
void ui_map_effect_num(char *target, enum module_type_t type, unsigned char effect_num)
{
    switch (type) {
        case module_type_s3m:
            sprintf(target, "%c", ".ABCDEFGHIJKLMNOPQRSTUVWXYZ"[effect_num]);
            break;
        case module_type_mtm:
        case module_type_mod:
        default:
            sprintf(target, "%X", effect_num);
            break;
    }
}

variable_types:
target
char *

variable_types: enum module_type_t { module_type_mod=0, module_type_s3m=1, module_type_mtm=2, module_type_stm=3, module_type_it=4 }


decompiled_code:
void __fastcall ui_effect_to_humanreadable(char *s, unsigned __int8 a2, unsigned __int8 a3, __int64 a4, unsigned int a5)
{
char v6; // dl
char v7; // al
char v8; // dl
char v9; // dl
char v10[26]; // [rsp+Eh] [rbp-1Ah] BYREF

*s = 0;
if ( a5 != 2 )
{
if ( a5 > 2 )
{
if ( a5 != 3 )
return;
goto LABEL_4;
}
if ( a5 )
{
LABEL_4:
v6 = *(_BYTE *)(a4 + a2);
switch ( a2 )
{
case 0u:
return;
case 1u:
goto LABEL_37;
case 3u:
goto LABEL_22;
case 4u:
v7 = v6 & 0xF;
if ( (v6 & 0xF) != 15 )
{
if ( (v6 & 0xF0) == 0xF0 )
{
strcpy(s, "fine volslide down");
if ( v7 )
return;
}
else if ( v7 )
{
goto LABEL_41;
}
strcpy(s, "volume slide up");
return;
}
strcpy(s, "fine volslide up");
LABEL_41:
if ( (v6 & 0xF0) == 0 )
strcpy(s, "volume slide down");
return;
case 5u:
v8 = v6 & 0xF0;
if ( v8 == -16 )
{
strcpy(s, "fine portamento down");
}
else if ( v8 == -32 )
{
strcpy(s, "extrafine portamento down");
}
else
{
strcpy(s, "portamento down");
}
return;
case 6u:
v9 = v6 & 0xF0;
if ( v9 == -16 )
{
strcpy(s, "fine portamento up");
}
else if ( v9 == -32 )
{
strcpy(s, "extrafine portamento up");
}
else
{
strcpy(s, "portamento up");
}
return;
case 7u:
goto LABEL_12;
case 8u:
*(_QWORD *)s = 0x6F746172626976LL;
return;
case 0xAu:
strcpy(s, "arpeggio");
return;
case 0xBu:
strcpy(s, "vibrato + volume slide");
return;
case 0xCu:
strcpy(s, "note portamento + vol slide");
return;
case 0xFu:
goto LABEL_18;
case 0x11u:
strcpy(s, "retrigger + volume slide");
return;
case 0x12u:
*(_QWORD *)s = 0x6F6C6F6D657274LL;
return;
case 0x13u:
switch ( a3 >> 4 )
{
case 3:
goto LABEL_63;
case 4:
goto LABEL_28;
case 8:
*(_QWORD *)s = 0x676E696E6E6170LL;
break;
case 10:
strcpy(s, "stereo control");
break;
case 12:
goto LABEL_33;
case 13:
goto LABEL_34;
default:
ui_map_effect_num(v10, a5, 0x13u);
sprintf(s, "UNIMPLEMENTED: %s%2x", v10, a3);
break;
}
return;
case 0x14u:
strcpy(s, "set tempo");
return;
case 0x18u:
*(_QWORD *)s = 0x676E696E6E6170LL;
return;
default:
ui_map_effect_num(v10, a5, a2);
sprintf(s, "UNIMPLEMENTED: %s%2x", v10, a3);
return;
}
}
}
switch ( a2 )
{
case 0u:
if ( a3 )
strcpy(s, "arpeggio");
break;
case 1u:
strcpy(s, "portamento up");
break;
case 2u:
strcpy(s, "portamento down");
break;
case 3u:
LABEL_12:
strcpy(s, "portamento to note");
break;
case 4u:
*(_QWORD *)s = 0x6F746172626976LL;
break;
case 5u:
strcpy(s, "port. to note + vol. slide");
break;
case 6u:
strcpy(s, "vibrato + vol. slide");
break;
case 7u:
*(_QWORD *)s = 0x6F6C6F6D657274LL;
break;
case 8u:
*(_QWORD *)s = 0x676E696E6E6170LL;
break;
case 9u:
LABEL_18:
strcpy(s, "sample offset");
break;
case 0xAu:
strcpy(s, "volume slide");
break;
case 0xBu:
strcpy(s, "position jump");
break;
case 0xCu:
strcpy(s, "set volume");
break;
case 0xDu:
LABEL_22:
strcpy(s, "pattern break");
break;
case 0xEu:
if ( a3 > 0xEFu )
{
LABEL_36:
sprintf(s, "UNIMPLEMENTED: %1x%2x", 14LL, a3);
}
else
{
switch ( a3 >> 4 )
{
case 0:
case 3:
case 5:
goto LABEL_36;
case 1:
strcpy(s, "fine porta up");
break;
case 2:
strcpy(s, "fine porta down");
break;
case 4:
LABEL_63:
strcpy(s, "set vibrato waveform");
break;
case 6:
strcpy(s, "pattern loop");
break;
case 7:
LABEL_28:
strcpy(s, "set tremolo waveform");
break;
case 8:
*(_QWORD *)s = 0x676E696E6E6170LL;
break;
case 9:
strcpy(s, "retrigger sample");
break;
case 10:
strcpy(s, "fine volume up");
break;
case 11:
strcpy(s, "fine volume down");
break;
case 12:
LABEL_33:
strcpy(s, "note cut");
break;
case 13:
LABEL_34:
strcpy(s, "note delay");
break;
case 14:
strcpy(s, "pattern delay");
break;
}
}
break;
case 0xFu:
LABEL_37:
strcpy(s, "set speed");
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func2(char *s, unsigned __int8 a2, unsigned __int8 a3, __int64 a4, unsigned int a5)
{
char v6; // dl
char v7; // al
char v8; // dl
char v9; // dl
char v10[26]; // [rsp+Eh] [rbp-1Ah] BYREF

*s = 0;
if ( a5 != 2 )
{
if ( a5 > 2 )
{
if ( a5 != 3 )
return;
goto LABEL_4;
}
if ( a5 )
{
LABEL_4:
v6 = *(_BYTE *)(a4 + a2);
switch ( a2 )
{
case 0u:
return;
case 1u:
goto LABEL_37;
case 3u:
goto LABEL_22;
case 4u:
v7 = v6 & 0xF;
if ( (v6 & 0xF) != 15 )
{
if ( (v6 & 0xF0) == 0xF0 )
{
strcpy(s, "fine volslide down");
if ( v7 )
return;
}
else if ( v7 )
{
goto LABEL_41;
}
strcpy(s, "volume slide up");
return;
}
strcpy(s, "fine volslide up");
LABEL_41:
if ( (v6 & 0xF0) == 0 )
strcpy(s, "volume slide down");
return;
case 5u:
v8 = v6 & 0xF0;
if ( v8 == -16 )
{
strcpy(s, "fine portamento down");
}
else if ( v8 == -32 )
{
strcpy(s, "extrafine portamento down");
}
else
{
strcpy(s, "portamento down");
}
return;
case 6u:
v9 = v6 & 0xF0;
if ( v9 == -16 )
{
strcpy(s, "fine portamento up");
}
else if ( v9 == -32 )
{
strcpy(s, "extrafine portamento up");
}
else
{
strcpy(s, "portamento up");
}
return;
case 7u:
goto LABEL_12;
case 8u:
*(_QWORD *)s = 0x6F746172626976LL;
return;
case 0xAu:
strcpy(s, "arpeggio");
return;
case 0xBu:
strcpy(s, "vibrato + volume slide");
return;
case 0xCu:
strcpy(s, "note portamento + vol slide");
return;
case 0xFu:
goto LABEL_18;
case 0x11u:
strcpy(s, "retrigger + volume slide");
return;
case 0x12u:
*(_QWORD *)s = 0x6F6C6F6D657274LL;
return;
case 0x13u:
switch ( a3 >> 4 )
{
case 3:
goto LABEL_63;
case 4:
goto LABEL_28;
case 8:
*(_QWORD *)s = 0x676E696E6E6170LL;
break;
case 10:
strcpy(s, "stereo control");
break;
case 12:
goto LABEL_33;
case 13:
goto LABEL_34;
default:
func1(v10, a5, 0x13u);
sprintf(s, "UNIMPLEMENTED: %s%2x", v10, a3);
break;
}
return;
case 0x14u:
strcpy(s, "set tempo");
return;
case 0x18u:
*(_QWORD *)s = 0x676E696E6E6170LL;
return;
default:
func1(v10, a5, a2);
sprintf(s, "UNIMPLEMENTED: %s%2x", v10, a3);
return;
}
}
}
switch ( a2 )
{
case 0u:
if ( a3 )
strcpy(s, "arpeggio");
break;
case 1u:
strcpy(s, "portamento up");
break;
case 2u:
strcpy(s, "portamento down");
break;
case 3u:
LABEL_12:
strcpy(s, "portamento to note");
break;
case 4u:
*(_QWORD *)s = 0x6F746172626976LL;
break;
case 5u:
strcpy(s, "port. to note + vol. slide");
break;
case 6u:
strcpy(s, "vibrato + vol. slide");
break;
case 7u:
*(_QWORD *)s = 0x6F6C6F6D657274LL;
break;
case 8u:
*(_QWORD *)s = 0x676E696E6E6170LL;
break;
case 9u:
LABEL_18:
strcpy(s, "sample offset");
break;
case 0xAu:
strcpy(s, "volume slide");
break;
case 0xBu:
strcpy(s, "position jump");
break;
case 0xCu:
strcpy(s, "set volume");
break;
case 0xDu:
LABEL_22:
strcpy(s, "pattern break");
break;
case 0xEu:
if ( a3 > 0xEFu )
{
LABEL_36:
sprintf(s, "UNIMPLEMENTED: %1x%2x", 14LL, a3);
}
else
{
switch ( a3 >> 4 )
{
case 0:
case 3:
case 5:
goto LABEL_36;
case 1:
strcpy(s, "fine porta up");
break;
case 2:
strcpy(s, "fine porta down");
break;
case 4:
LABEL_63:
strcpy(s, "set vibrato waveform");
break;
case 6:
strcpy(s, "pattern loop");
break;
case 7:
LABEL_28:
strcpy(s, "set tremolo waveform");
break;
case 8:
*(_QWORD *)s = 0x676E696E6E6170LL;
break;
case 9:
strcpy(s, "retrigger sample");
break;
case 10:
strcpy(s, "fine volume up");
break;
case 11:
strcpy(s, "fine volume down");
break;
case 12:
LABEL_33:
strcpy(s, "note cut");
break;
case 13:
LABEL_34:
strcpy(s, "note delay");
break;
case 14:
strcpy(s, "pattern delay");
break;
}
}
break;
case 0xFu:
LABEL_37:
strcpy(s, "set speed");
break;
default:
return;
}
}

original_code:
void ui_effect_to_humanreadable(char * buf, const uint8_t effect_num, const uint8_t effect_value, const uint8_t * effect_values_mem, const module_type_t module_type)
{
    *buf = 0;
    char effect[2];
    uint8_t effect_value_mem = effect_values_mem[effect_num];
    switch (module_type) {
        case module_type_mtm:
        case module_type_mod:
            switch (effect_num) {
                case 0:
                    if (effect_value)
                        strcpy(buf, "arpeggio");
                    break;
                case 0x1: strcpy(buf, "portamento up"); break;
                case 0x2: strcpy(buf, "portamento down"); break;
                case 0x3: strcpy(buf, "portamento to note"); break;
                case 0x4: strcpy(buf, "vibrato"); break;
                case 0x5: strcpy(buf, "port. to note + vol. slide"); break;
                case 0x6: strcpy(buf, "vibrato + vol. slide"); break;
                case 0x7: strcpy(buf, "tremolo"); break;
                case 0x8: strcpy(buf, "panning"); break;
                case 0x9: strcpy(buf, "sample offset"); break;
                case 0xa: strcpy(buf, "volume slide"); break;
                case 0xb: strcpy(buf, "position jump"); break;
                case 0xc: strcpy(buf, "set volume"); break;
                case 0xd: strcpy(buf, "pattern break"); break;
                case 0xe:
                    switch (effect_value >> 4) {
                        case 0x1: strcpy(buf, "fine porta up"); break;
                        case 0x2: strcpy(buf, "fine porta down"); break;
                        case 0x4: strcpy(buf, "set vibrato waveform"); break;
                        case 0x6: strcpy(buf, "pattern loop"); break;
                        case 0x7: strcpy(buf, "set tremolo waveform"); break;
                        case 0x8: strcpy(buf, "panning"); break;
                        case 0x9: strcpy(buf, "retrigger sample"); break;
                        case 0xa: strcpy(buf, "fine volume up"); break;
                        case 0xb: strcpy(buf, "fine volume down"); break;
                        case 0xc: strcpy(buf, "note cut"); break;
                        case 0xd: strcpy(buf, "note delay"); break;
                        case 0xe: strcpy(buf, "pattern delay"); break;
                        default: sprintf(buf, "UNIMPLEMENTED: %1x%2x", effect_num, effect_value); break;
                    }
                    break;
                case 0xf: strcpy(buf, "set speed"); break;
            }
            break;
        case module_type_stm:
        case module_type_s3m:
            switch (effect_num) {
                case 0: break;
                case 1: strcpy(buf, "set speed"); break;
                case 3: strcpy(buf, "pattern break"); break;
                case 4:
                    if ((effect_value_mem & 0x0f) == 0x0f)
                        strcpy(buf, "fine volslide up");
                    else if ((effect_value_mem & 0xf0) == 0xf0)
                        strcpy(buf, "fine volslide down");
                    if ((effect_value_mem & 0x0f) == 0x00)
                        strcpy(buf, "volume slide up");
                    else if ((effect_value_mem & 0xf0) == 0x00)
                        strcpy(buf, "volume slide down");
                    break;
                case 5:
                    if ((effect_value_mem & 0xf0) == 0xf0)
                        strcpy(buf, "fine portamento down");
                    else if ((effect_value_mem & 0xf0) == 0xe0)
                        strcpy(buf, "extrafine portamento down");
                    else
                        strcpy(buf, "portamento down");
                    break;
                case 6:
                    if ((effect_value_mem & 0xf0) == 0xf0)
                        strcpy(buf, "fine portamento up");
                    else if ((effect_value_mem & 0xf0) == 0xe0)
                        strcpy(buf, "extrafine portamento up");
                    else
                        strcpy(buf, "portamento up");
                    break;
                case 7: strcpy(buf, "portamento to note"); break;
                case 8: strcpy(buf, "vibrato"); break;
                case 10: strcpy(buf, "arpeggio"); break;
                case 11: strcpy(buf, "vibrato + volume slide"); break;
                case 12: strcpy(buf, "note portamento + vol slide"); break;
                case 15: strcpy(buf, "sample offset"); break;
                case 17: strcpy(buf, "retrigger + volume slide"); break;
                case 18: strcpy(buf, "tremolo"); break;
                case 19:
                    switch (effect_value >> 4) {
                        case 0x3: strcpy(buf, "set vibrato waveform"); break;
                        case 0x4: strcpy(buf, "set tremolo waveform"); break;
                        case 0x8: strcpy(buf, "panning"); break;
                        case 0xA: strcpy(buf, "stereo control"); break;
                        case 0xC: strcpy(buf, "note cut"); break;
                        case 0xD: strcpy(buf, "note delay"); break;
                        default:
                            ui_map_effect_num(effect, module_type, effect_num);
                            sprintf(buf, "UNIMPLEMENTED: %s%2x", effect, effect_value);
                            break;
                    }
                    break;
                case 20: strcpy(buf, "set tempo"); break;
                case 24: strcpy(buf, "panning"); break;
                default:
                    ui_map_effect_num(effect, module_type, effect_num);
                    sprintf(buf, "UNIMPLEMENTED: %s%2x", effect, effect_value);
                    break;
            }
            break;
    }
}

canonical_original_code:
void ui_effect_to_humanreadable(char *buf, unsigned char effect_num, unsigned char effect_value, unsigned char *effect_values_mem, enum module_type_t module_type)
{
    *buf = 0;
    char effect[2];
    unsigned char effect_value_mem = effect_values_mem[effect_num];
    switch (module_type) {
        case module_type_mtm:
        case module_type_mod:
            switch (effect_num) {
                case 0:
                    if (effect_value)
                        strcpy(buf, "arpeggio");
                    break;
                case 0x1: strcpy(buf, "portamento up"); break;
                case 0x2: strcpy(buf, "portamento down"); break;
                case 0x3: strcpy(buf, "portamento to note"); break;
                case 0x4: strcpy(buf, "vibrato"); break;
                case 0x5: strcpy(buf, "port. to note + vol. slide"); break;
                case 0x6: strcpy(buf, "vibrato + vol. slide"); break;
                case 0x7: strcpy(buf, "tremolo"); break;
                case 0x8: strcpy(buf, "panning"); break;
                case 0x9: strcpy(buf, "sample offset"); break;
                case 0xa: strcpy(buf, "volume slide"); break;
                case 0xb: strcpy(buf, "position jump"); break;
                case 0xc: strcpy(buf, "set volume"); break;
                case 0xd: strcpy(buf, "pattern break"); break;
                case 0xe:
                    switch (effect_value >> 4) {
                        case 0x1: strcpy(buf, "fine porta up"); break;
                        case 0x2: strcpy(buf, "fine porta down"); break;
                        case 0x4: strcpy(buf, "set vibrato waveform"); break;
                        case 0x6: strcpy(buf, "pattern loop"); break;
                        case 0x7: strcpy(buf, "set tremolo waveform"); break;
                        case 0x8: strcpy(buf, "panning"); break;
                        case 0x9: strcpy(buf, "retrigger sample"); break;
                        case 0xa: strcpy(buf, "fine volume up"); break;
                        case 0xb: strcpy(buf, "fine volume down"); break;
                        case 0xc: strcpy(buf, "note cut"); break;
                        case 0xd: strcpy(buf, "note delay"); break;
                        case 0xe: strcpy(buf, "pattern delay"); break;
                        default: sprintf(buf, "UNIMPLEMENTED: %1x%2x", effect_num, effect_value); break;
                    }
                    break;
                case 0xf: strcpy(buf, "set speed"); break;
            }
            break;
        case module_type_stm:
        case module_type_s3m:
            switch (effect_num) {
                case 0: break;
                case 1: strcpy(buf, "set speed"); break;
                case 3: strcpy(buf, "pattern break"); break;
                case 4:
                    if ((effect_value_mem & 0x0f) == 0x0f)
                        strcpy(buf, "fine volslide up");
                    else if ((effect_value_mem & 0xf0) == 0xf0)
                        strcpy(buf, "fine volslide down");
                    if ((effect_value_mem & 0x0f) == 0x00)
                        strcpy(buf, "volume slide up");
                    else if ((effect_value_mem & 0xf0) == 0x00)
                        strcpy(buf, "volume slide down");
                    break;
                case 5:
                    if ((effect_value_mem & 0xf0) == 0xf0)
                        strcpy(buf, "fine portamento down");
                    else if ((effect_value_mem & 0xf0) == 0xe0)
                        strcpy(buf, "extrafine portamento down");
                    else
                        strcpy(buf, "portamento down");
                    break;
                case 6:
                    if ((effect_value_mem & 0xf0) == 0xf0)
                        strcpy(buf, "fine portamento up");
                    else if ((effect_value_mem & 0xf0) == 0xe0)
                        strcpy(buf, "extrafine portamento up");
                    else
                        strcpy(buf, "portamento up");
                    break;
                case 7: strcpy(buf, "portamento to note"); break;
                case 8: strcpy(buf, "vibrato"); break;
                case 10: strcpy(buf, "arpeggio"); break;
                case 11: strcpy(buf, "vibrato + volume slide"); break;
                case 12: strcpy(buf, "note portamento + vol slide"); break;
                case 15: strcpy(buf, "sample offset"); break;
                case 17: strcpy(buf, "retrigger + volume slide"); break;
                case 18: strcpy(buf, "tremolo"); break;
                case 19:
                    switch (effect_value >> 4) {
                        case 0x3: strcpy(buf, "set vibrato waveform"); break;
                        case 0x4: strcpy(buf, "set tremolo waveform"); break;
                        case 0x8: strcpy(buf, "panning"); break;
                        case 0xA: strcpy(buf, "stereo control"); break;
                        case 0xC: strcpy(buf, "note cut"); break;
                        case 0xD: strcpy(buf, "note delay"); break;
                        default:
                            ui_map_effect_num(effect, module_type, effect_num);
                            sprintf(buf, "UNIMPLEMENTED: %s%2x", effect, effect_value);
                            break;
                    }
                    break;
                case 20: strcpy(buf, "set tempo"); break;
                case 24: strcpy(buf, "panning"); break;
                default:
                    ui_map_effect_num(effect, module_type, effect_num);
                    sprintf(buf, "UNIMPLEMENTED: %s%2x", effect, effect_value);
                    break;
            }
            break;
    }
}

variable_types:
buf
char *

variable_types:
effect
char [2]


decompiled_code:
__int64 __fastcall ui_lookup_period_index(int a1, __int16 a2)
{
unsigned int v2; // edx
_WORD *v4; // rdi
int v5; // ecx
__int64 v6; // rax

if ( a1 == 1 )
{
v4 = &defs_s3m_periods;
v5 = 108;
}
else
{
v2 = -1;
if ( (a1 & 0xFFFFFFFD) != 0 )
return v2;
v4 = &defs_mod_periods;
v5 = 60;
}
v6 = 0LL;
while ( 1 )
{
v2 = v6;
if ( v4[v6] == a2 )
break;
if ( ++v6 == v5 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int16 a2)
{
unsigned int v2; // edx
_WORD *v4; // rdi
int v5; // ecx
__int64 v6; // rax

if ( a1 == 1 )
{
v4 = &defs_s3m_periods;
v5 = 108;
}
else
{
v2 = -1;
if ( (a1 & 0xFFFFFFFD) != 0 )
return v2;
v4 = &defs_mod_periods;
v5 = 60;
}
v6 = 0LL;
while ( 1 )
{
v2 = v6;
if ( v4[v6] == a2 )
break;
if ( ++v6 == v5 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int ui_lookup_period_index(const module_type_t type, const uint16_t period)
{
    int i;
    int num_periods;
    uint16_t * period_table;
    switch (type) {
        case module_type_mtm:
        case module_type_mod:
            num_periods = defs_mod_num_periods;
            period_table = (uint16_t *)defs_mod_periods;
            break;
        case module_type_s3m:
            num_periods = defs_s3m_num_periods;
            period_table = (uint16_t *)defs_s3m_periods;
            break;
        default:
            return -1;
    }
    for (i = 0; i < num_periods; i++) {
        if (period_table[i] == period)
            return i;
    }
    return -1;
}

canonical_original_code:
int ui_lookup_period_index(enum module_type_t type, unsigned short period)
{
    int i;
    int num_periods;
    unsigned short *period_table;
    switch (type) {
        case module_type_mtm:
        case module_type_mod:
            num_periods = defs_mod_num_periods;
            period_table = (unsigned short *)defs_mod_periods;
            break;
        case module_type_s3m:
            num_periods = defs_s3m_num_periods;
            period_table = (unsigned short *)defs_s3m_periods;
            break;
        default:
            return -1;
    }
    for (i = 0; i < num_periods; i++) {
        if (period_table[i] == period)
            return i;
    }
    return -1;
}


decompiled_code:
__int16 __fastcall sample_to_s8(__int16 a1)
{
return a1 >> 8;
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return a1 >> 8;
}

original_code: static inline int8_t sample_to_s8(sample_t s) { return (uint8_t)(s >> 8); }

canonical_original_code: static inline char sample_to_s8(short s) { return (unsigned char)(s >> 8); }

variable_types: s short

return_type: char