decompiled_code:
__int64 __fastcall effects_stm_D_volumeslide(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax
char v4; // dl

if ( *(_DWORD *)(a1 + 120) )
{
v2 = *(_QWORD *)a1 + 104LL * a2;
result = *(unsigned __int8 *)(v2 + 39);
if ( (*(_BYTE *)(v2 + 39) & 0xF) != 0 )
{
if ( (result & 0xF0) == 0 )
{
result = *(char *)(v2 + 31) - (*(_BYTE *)(v2 + 39) & 0xFu);
if ( (int)result < 0 )
result = 0LL;
*(_BYTE *)(v2 + 31) = result;
}
}
else
{
result = *(char *)(v2 + 31) + (unsigned int)((unsigned __int8)result >> 4);
if ( (int)result > 64 )
result = 64LL;
*(_BYTE *)(v2 + 31) = result;
}
}
else
{
result = *(_QWORD *)a1 + 104LL * a2;
v4 = *(_BYTE *)(result + 34);
if ( v4 )
*(_BYTE *)(result + 39) = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax
char v4; // dl

if ( *(_DWORD *)(a1 + 120) )
{
v2 = *(_QWORD *)a1 + 104LL * a2;
result = *(unsigned __int8 *)(v2 + 39);
if ( (*(_BYTE *)(v2 + 39) & 0xF) != 0 )
{
if ( (result & 0xF0) == 0 )
{
result = *(char *)(v2 + 31) - (*(_BYTE *)(v2 + 39) & 0xFu);
if ( (int)result < 0 )
result = 0LL;
*(_BYTE *)(v2 + 31) = result;
}
}
else
{
result = *(char *)(v2 + 31) + (unsigned int)((unsigned __int8)result >> 4);
if ( (int)result > 64 )
result = 64LL;
*(_BYTE *)(v2 + 31) = result;
}
}
else
{
result = *(_QWORD *)a1 + 104LL * a2;
v4 = *(_BYTE *)(result + 34);
if ( v4 )
*(_BYTE *)(result + 39) = v4;
}
return result;
}

original_code:
void effects_stm_D_volumeslide(player_t * player, int channel)
{
    int tmp;
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value)
            player->channels[channel].effect_last_value[4] = player->channels[channel].effect_value;
        return;
    }
    if ((player->channels[channel].effect_last_value[4] & 0x0f) == 0x00) {
        tmp = player->channels[channel].volume + (player->channels[channel].effect_last_value[4] >> 4);
        if (tmp > 64)
            tmp = 64;
        player->channels[channel].volume = tmp;
    } else if ((player->channels[channel].effect_last_value[4] & 0xf0) == 0x00) {
        tmp = (int)player->channels[channel].volume - (int)(player->channels[channel].effect_last_value[4] & 0x0f);
        if (tmp < 0)
            tmp = 0;
        player->channels[channel].volume = tmp;
    }
}

canonical_original_code:
void effects_stm_D_volumeslide(struct player_t *player, int channel)
{
    int tmp;
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value)
            player->channels[channel].effect_last_value[4] = player->channels[channel].effect_value;
        return;
    }
    if ((player->channels[channel].effect_last_value[4] & 0x0f) == 0x00) {
        tmp = player->channels[channel].volume + (player->channels[channel].effect_last_value[4] >> 4);
        if (tmp > 64)
            tmp = 64;
        player->channels[channel].volume = tmp;
    } else if ((player->channels[channel].effect_last_value[4] & 0xf0) == 0x00) {
        tmp = (int)player->channels[channel].volume - (int)(player->channels[channel].effect_last_value[4] & 0x0f);
        if (tmp < 0)
            tmp = 0;
        player->channels[channel].volume = tmp;
    }
}

variable_types: tmp int

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


repo: vlohacks/misc

original_code:
void effects_stm_I_tremor(player_t * player, int channel)
{
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value) {
            player->channels[channel].effect_last_value[9] = player->channels[channel].effect_value;
        }
    }
    uint8_t tremor_on = (player->channels[channel].effect_last_value[9] >> 4) + 1;
    uint8_t tremor_off = (player->channels[channel].effect_last_value[9] & 0x0f) + 1;
    if (player->channels[channel].tremor_state < tremor_on)
        player->channels[channel].volume_master = 64;
    else
        player->channels[channel].volume_master = 0;
    player->channels[channel].tremor_state++;
    if (player->channels[channel].tremor_state > (tremor_on + tremor_off))
        player->channels[channel].tremor_state = 0;
}

canonical_original_code:
void effects_stm_I_tremor(struct player_t *player, int channel)
{
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value) {
            player->channels[channel].effect_last_value[9] = player->channels[channel].effect_value;
        }
    }
    unsigned char tremor_on = (player->channels[channel].effect_last_value[9] >> 4) + 1;
    unsigned char tremor_off = (player->channels[channel].effect_last_value[9] & 0x0f) + 1;
    if (player->channels[channel].tremor_state < tremor_on)
        player->channels[channel].volume_master = 64;
    else
        player->channels[channel].volume_master = 0;
    player->channels[channel].tremor_state++;
    if (player->channels[channel].tremor_state > (tremor_on + tremor_off))
        player->channels[channel].tremor_state = 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; } *

variable_types: channel 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: 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_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_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; }


decompiled_code:
void effects_stm_unimplemented()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void effects_stm_unimplemented(player_t * player, int channel)
{
}

canonical_original_code:
void effects_stm_unimplemented(struct player_t *player, int channel)
{
}

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


decompiled_code:
__int64 __fastcall effects_stm_E_slidedown(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 v5; // cl
__int64 v6; // rdx
char v7; // cl

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
result = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + result;
v5 = *(_BYTE *)(v4 + 40);
if ( v5 <= 0xDFu )
{
*(_WORD *)(v4 + 16) += 4 * v5;
result = player_channel_set_frequency(a1, *(unsigned __int16 *)(*(_QWORD *)a1 + result + 16), v2);
}
}
else
{
result = 104LL * (int)a2;
v6 = *(_QWORD *)a1 + result;
v7 = *(_BYTE *)(v6 + 34);
if ( v7 )
{
*(_BYTE *)(v6 + 40) = v7;
result += *(_QWORD *)a1;
*(_BYTE *)(result + 41) = *(_BYTE *)(result + 40);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 v5; // cl
__int64 v6; // rdx
char v7; // cl

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
result = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + result;
v5 = *(_BYTE *)(v4 + 40);
if ( v5 <= 0xDFu )
{
*(_WORD *)(v4 + 16) += 4 * v5;
result = player_channel_set_frequency(a1, *(unsigned __int16 *)(*(_QWORD *)a1 + result + 16), v2);
}
}
else
{
result = 104LL * (int)a2;
v6 = *(_QWORD *)a1 + result;
v7 = *(_BYTE *)(v6 + 34);
if ( v7 )
{
*(_BYTE *)(v6 + 40) = v7;
result += *(_QWORD *)a1;
*(_BYTE *)(result + 41) = *(_BYTE *)(result + 40);
}
}
return result;
}

original_code:
void effects_stm_E_slidedown(player_t * player, int channel)
{
    int tmp;
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value) {
            player->channels[channel].effect_last_value[5] = player->channels[channel].effect_value;
            player->channels[channel].effect_last_value[6] = player->channels[channel].effect_last_value[5];
        }
        return;
    }
    if ((player->channels[channel].effect_last_value[5]) < 0xe0) {
        tmp = (int)player->channels[channel].period + ((player->channels[channel].effect_last_value[5]) << 2);
        player->channels[channel].period = tmp;
        player_channel_set_frequency(player, player->channels[channel].period, channel);
    }
}

canonical_original_code:
void effects_stm_E_slidedown(struct player_t *player, int channel)
{
    int tmp;
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value) {
            player->channels[channel].effect_last_value[5] = player->channels[channel].effect_value;
            player->channels[channel].effect_last_value[6] = player->channels[channel].effect_last_value[5];
        }
        return;
    }
    if ((player->channels[channel].effect_last_value[5]) < 0xe0) {
        tmp = (int)player->channels[channel].period + ((player->channels[channel].effect_last_value[5]) << 2);
        player->channels[channel].period = tmp;
        player_channel_set_frequency(player, player->channels[channel].period, channel);
    }
}


decompiled_code:
__int64 __fastcall effects_stm_F_slideup(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 v5; // cl
__int64 v6; // rdx
char v7; // cl

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
result = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + result;
v5 = *(_BYTE *)(v4 + 41);
if ( v5 <= 0xDFu )
{
*(_WORD *)(v4 + 16) -= 4 * v5;
result = player_channel_set_frequency(a1, *(unsigned __int16 *)(*(_QWORD *)a1 + result + 16), v2);
}
}
else
{
result = 104LL * (int)a2;
v6 = *(_QWORD *)a1 + result;
v7 = *(_BYTE *)(v6 + 34);
if ( v7 )
{
*(_BYTE *)(v6 + 41) = v7;
result += *(_QWORD *)a1;
*(_BYTE *)(result + 40) = *(_BYTE *)(result + 41);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 v5; // cl
__int64 v6; // rdx
char v7; // cl

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
result = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + result;
v5 = *(_BYTE *)(v4 + 41);
if ( v5 <= 0xDFu )
{
*(_WORD *)(v4 + 16) -= 4 * v5;
result = player_channel_set_frequency(a1, *(unsigned __int16 *)(*(_QWORD *)a1 + result + 16), v2);
}
}
else
{
result = 104LL * (int)a2;
v6 = *(_QWORD *)a1 + result;
v7 = *(_BYTE *)(v6 + 34);
if ( v7 )
{
*(_BYTE *)(v6 + 41) = v7;
result += *(_QWORD *)a1;
*(_BYTE *)(result + 40) = *(_BYTE *)(result + 41);
}
}
return result;
}

original_code:
void effects_stm_F_slideup(player_t * player, int channel)
{
    int tmp;
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value) {
            player->channels[channel].effect_last_value[6] = player->channels[channel].effect_value;
            player->channels[channel].effect_last_value[5] = player->channels[channel].effect_last_value[6];
        }
        return;
    }
    if ((player->channels[channel].effect_last_value[6]) < 0xe0) {
        tmp = (int)player->channels[channel].period - ((player->channels[channel].effect_last_value[6]) << 2);
        player->channels[channel].period = tmp;
        player_channel_set_frequency(player, player->channels[channel].period, channel);
    }
}

canonical_original_code:
void effects_stm_F_slideup(struct player_t *player, int channel)
{
    int tmp;
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value) {
            player->channels[channel].effect_last_value[6] = player->channels[channel].effect_value;
            player->channels[channel].effect_last_value[5] = player->channels[channel].effect_last_value[6];
        }
        return;
    }
    if ((player->channels[channel].effect_last_value[6]) < 0xe0) {
        tmp = (int)player->channels[channel].period - ((player->channels[channel].effect_last_value[6]) << 2);
        player->channels[channel].period = tmp;
        player_channel_set_frequency(player, player->channels[channel].period, channel);
    }
}


decompiled_code:
__int64 __fastcall effects_stm_G_slidetonote(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 result; // rax
unsigned __int16 v6; // si
int v7; // esi
char v8; // dl
__int64 v9; // rax
unsigned __int16 v10; // si

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
v3 = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + v3;
result = *(unsigned __int16 *)(v4 + 26);
if ( (_WORD)result )
{
v6 = *(_WORD *)(v4 + 16);
if ( (unsigned __int16)result >= v6 )
{
if ( (unsigned __int16)result > v6 )
{
*(_WORD *)(v4 + 16) = v6 + 4 * *(unsigned __int8 *)(v4 + 42);
v9 = *(_QWORD *)a1 + v3;
v10 = *(_WORD *)(v9 + 26);
if ( *(_WORD *)(v9 + 16) > v10 )
*(_WORD *)(v9 + 16) = v10;
}
}
else
{
v7 = v6 - 4 * *(unsigned __int8 *)(v4 + 42);
if ( (unsigned __int16)result < v7 )
LOWORD(result) = v7;
*(_WORD *)(v4 + 16) = result;
}
result = player_channel_set_frequency(a1, *(unsigned __int16 *)(*(_QWORD *)a1 + v3 + 16), v2);
}
}
else
{
result = *(_QWORD *)a1 + 104LL * (int)a2;
v8 = *(_BYTE *)(result + 34);
if ( v8 )
*(_BYTE *)(result + 42) = v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 result; // rax
unsigned __int16 v6; // si
int v7; // esi
char v8; // dl
__int64 v9; // rax
unsigned __int16 v10; // si

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
v3 = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + v3;
result = *(unsigned __int16 *)(v4 + 26);
if ( (_WORD)result )
{
v6 = *(_WORD *)(v4 + 16);
if ( (unsigned __int16)result >= v6 )
{
if ( (unsigned __int16)result > v6 )
{
*(_WORD *)(v4 + 16) = v6 + 4 * *(unsigned __int8 *)(v4 + 42);
v9 = *(_QWORD *)a1 + v3;
v10 = *(_WORD *)(v9 + 26);
if ( *(_WORD *)(v9 + 16) > v10 )
*(_WORD *)(v9 + 16) = v10;
}
}
else
{
v7 = v6 - 4 * *(unsigned __int8 *)(v4 + 42);
if ( (unsigned __int16)result < v7 )
LOWORD(result) = v7;
*(_WORD *)(v4 + 16) = result;
}
result = player_channel_set_frequency(a1, *(unsigned __int16 *)(*(_QWORD *)a1 + v3 + 16), v2);
}
}
else
{
result = *(_QWORD *)a1 + 104LL * (int)a2;
v8 = *(_BYTE *)(result + 34);
if ( v8 )
*(_BYTE *)(result + 42) = v8;
}
return result;
}

original_code:
void effects_stm_G_slidetonote(player_t * player, int channel)
{
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value)
            player->channels[channel].effect_last_value[7] = player->channels[channel].effect_value;
        return;
    }
    if (player->channels[channel].dest_period == 0)
        return;
    if (player->channels[channel].period > player->channels[channel].dest_period) {
        int tmp = (int)player->channels[channel].period - ((int)player->channels[channel].effect_last_value[7] << 2);
        if (tmp < player->channels[channel].dest_period)
            tmp = player->channels[channel].dest_period;
        player->channels[channel].period = (uint16_t)tmp;
    } else if (player->channels[channel].period < player->channels[channel].dest_period) {
        player->channels[channel].period += (player->channels[channel].effect_last_value[7] << 2);
        if (player->channels[channel].period > player->channels[channel].dest_period)
            player->channels[channel].period = player->channels[channel].dest_period;
    }
    player_channel_set_frequency(player, player->channels[channel].period, channel);
}

canonical_original_code:
void effects_stm_G_slidetonote(struct player_t *player, int channel)
{
    if (player->current_tick == 0) {
        if (player->channels[channel].effect_value)
            player->channels[channel].effect_last_value[7] = player->channels[channel].effect_value;
        return;
    }
    if (player->channels[channel].dest_period == 0)
        return;
    if (player->channels[channel].period > player->channels[channel].dest_period) {
        int tmp = (int)player->channels[channel].period - ((int)player->channels[channel].effect_last_value[7] << 2);
        if (tmp < player->channels[channel].dest_period)
            tmp = player->channels[channel].dest_period;
        player->channels[channel].period = (unsigned short)tmp;
    } else if (player->channels[channel].period < player->channels[channel].dest_period) {
        player->channels[channel].period += (player->channels[channel].effect_last_value[7] << 2);
        if (player->channels[channel].period > player->channels[channel].dest_period)
            player->channels[channel].period = player->channels[channel].dest_period;
    }
    player_channel_set_frequency(player, player->channels[channel].period, channel);
}


decompiled_code:
__int64 __fastcall effects_stm_H_vibrato(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 v3; // rbp
__int64 v4; // rax
__int16 v5; // si
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rcx
char v9; // dl

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
v3 = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + v3;
v5 = (unsigned __int16)((unsigned __int8)defs_mod_sine_table[*(_DWORD *)(v4 + 88) & 0x1F]
* *(unsigned __int8 *)(v4 + *(unsigned __int8 *)(v4 + 33) + 61)) >> 5;
if ( *(int *)(v4 + 88) < 0 )
player_channel_set_frequency(a1, (unsigned __int16)(*(_WORD *)(v4 + 16) - v5), v2);
else
player_channel_set_frequency(a1, (unsigned __int16)(*(_WORD *)(v4 + 16) + v5), v2);
*(_DWORD *)(*(_QWORD *)a1 + v3 + 88) += *(unsigned __int8 *)(*(_QWORD *)a1
+ v3
+ *(unsigned __int8 *)(*(_QWORD *)a1 + v3 + 33)
+ 35);
v6 = *(_QWORD *)a1 + v3;
result = *(unsigned int *)(v6 + 88);
if ( (int)result > 31 )
{
result = (unsigned int)(result - 64);
*(_DWORD *)(v6 + 88) = result;
}
}
else
{
v8 = *(_QWORD *)a1 + 104LL * (int)a2;
v9 = *(_BYTE *)(v8 + 34) >> 4;
if ( v9 )
*(_BYTE *)(v8 + *(unsigned __int8 *)(v8 + 33) + 35) = v9;
result = *(_QWORD *)a1 + 104LL * (int)a2;
if ( (*(_BYTE *)(result + 34) & 0xF) != 0 )
*(_BYTE *)(result + *(unsigned __int8 *)(result + 33) + 61) = *(_BYTE *)(result + 34) & 0xF;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 v3; // rbp
__int64 v4; // rax
__int16 v5; // si
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rcx
char v9; // dl

v2 = a2;
if ( *(_DWORD *)(a1 + 120) )
{
v3 = 104LL * (int)a2;
v4 = *(_QWORD *)a1 + v3;
v5 = (unsigned __int16)((unsigned __int8)defs_mod_sine_table[*(_DWORD *)(v4 + 88) & 0x1F]
* *(unsigned __int8 *)(v4 + *(unsigned __int8 *)(v4 + 33) + 61)) >> 5;
if ( *(int *)(v4 + 88) < 0 )
player_channel_set_frequency(a1, (unsigned __int16)(*(_WORD *)(v4 + 16) - v5), v2);
else
player_channel_set_frequency(a1, (unsigned __int16)(*(_WORD *)(v4 + 16) + v5), v2);
*(_DWORD *)(*(_QWORD *)a1 + v3 + 88) += *(unsigned __int8 *)(*(_QWORD *)a1
+ v3
+ *(unsigned __int8 *)(*(_QWORD *)a1 + v3 + 33)
+ 35);
v6 = *(_QWORD *)a1 + v3;
result = *(unsigned int *)(v6 + 88);
if ( (int)result > 31 )
{
result = (unsigned int)(result - 64);
*(_DWORD *)(v6 + 88) = result;
}
}
else
{
v8 = *(_QWORD *)a1 + 104LL * (int)a2;
v9 = *(_BYTE *)(v8 + 34) >> 4;
if ( v9 )
*(_BYTE *)(v8 + *(unsigned __int8 *)(v8 + 33) + 35) = v9;
result = *(_QWORD *)a1 + 104LL * (int)a2;
if ( (*(_BYTE *)(result + 34) & 0xF) != 0 )
*(_BYTE *)(result + *(unsigned __int8 *)(result + 33) + 61) = *(_BYTE *)(result + 34) & 0xF;
}
return result;
}

original_code:
void effects_stm_H_vibrato(player_t * player, int channel)
{
    uint8_t temp;
    uint16_t delta;
    if (player->current_tick == 0) {
        if ((player->channels[channel].effect_value >> 4) != 0x00)
            player->channels[channel].effect_last_value[player->channels[channel].effect_num] = (player->channels[channel].effect_value >> 4);
        if ((player->channels[channel].effect_value & 0xf) != 0x00)
            player->channels[channel].effect_last_value_y[player->channels[channel].effect_num] = (player->channels[channel].effect_value & 0xf);
        return;
    }
    temp = player->channels[channel].vibrato_state & 0x1f;
    delta = defs_mod_sine_table[temp];
    delta *= (player->channels[channel].effect_last_value_y[player->channels[channel].effect_num]);
    delta /= 32;
    if (player->channels[channel].vibrato_state >= 0)
        player_channel_set_frequency(player, player->channels[channel].period + delta, channel);
    else
        player_channel_set_frequency(player, player->channels[channel].period - delta, channel);
    player->channels[channel].vibrato_state += player->channels[channel].effect_last_value[player->channels[channel].effect_num];
    if (player->channels[channel].vibrato_state > 31)
        player->channels[channel].vibrato_state -= 64;
}

canonical_original_code:
void effects_stm_H_vibrato(struct player_t *player, int channel)
{
    unsigned char temp;
    unsigned short delta;
    if (player->current_tick == 0) {
        if ((player->channels[channel].effect_value >> 4) != 0x00)
            player->channels[channel].effect_last_value[player->channels[channel].effect_num] = (player->channels[channel].effect_value >> 4);
        if ((player->channels[channel].effect_value & 0xf) != 0x00)
            player->channels[channel].effect_last_value_y[player->channels[channel].effect_num] = (player->channels[channel].effect_value & 0xf);
        return;
    }
    temp = player->channels[channel].vibrato_state & 0x1f;
    delta = defs_mod_sine_table[temp];
    delta *= (player->channels[channel].effect_last_value_y[player->channels[channel].effect_num]);
    delta /= 32;
    if (player->channels[channel].vibrato_state >= 0)
        player_channel_set_frequency(player, player->channels[channel].period + delta, channel);
    else
        player_channel_set_frequency(player, player->channels[channel].period - delta, channel);
    player->channels[channel].vibrato_state += player->channels[channel].effect_last_value[player->channels[channel].effect_num];
    if (player->channels[channel].vibrato_state > 31)
        player->channels[channel].vibrato_state -= 64;
}

variable_types:
temp
unsigned char

variable_types:
delta
unsigned short


decompiled_code:
__int64 __fastcall effects_stm_J_arpeggio(__int64 a1, unsigned int a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
int v4; // er12
int v5; // ecx

result = *(_QWORD *)a1 + 104LL * (int)a2;
v3 = *(_BYTE *)(result + 34);
if ( v3 )
{
LOWORD(v4) = *(_WORD *)(result + 16);
if ( (_WORD)v4 )
{
v5 = *(_DWORD *)(a1 + 120) % 3;
if ( (_BYTE)v5 == 1 )
{
v4 = (int)((double)(unsigned __int16)v4 * pow(2.0, (float)((float)(v3 >> 4) / -12.0)));
}
else if ( (unsigned __int8)v5 == 2 )
{
v4 = (int)((double)(unsigned __int16)v4 * pow(2.0, (float)((float)(v3 & 0xF) / -12.0)));
}
result = player_channel_set_frequency(a1, (unsigned __int16)v4, a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
int v4; // er12
int v5; // ecx

result = *(_QWORD *)a1 + 104LL * (int)a2;
v3 = *(_BYTE *)(result + 34);
if ( v3 )
{
LOWORD(v4) = *(_WORD *)(result + 16);
if ( (_WORD)v4 )
{
v5 = *(_DWORD *)(a1 + 120) % 3;
if ( (_BYTE)v5 == 1 )
{
v4 = (int)((double)(unsigned __int16)v4 * pow(2.0, (float)((float)(v3 >> 4) / -12.0)));
}
else if ( (unsigned __int8)v5 == 2 )
{
v4 = (int)((double)(unsigned __int16)v4 * pow(2.0, (float)((float)(v3 & 0xF) / -12.0)));
}
result = player_channel_set_frequency(a1, (unsigned __int16)v4, a2);
}
}
return result;
}

original_code:
void effects_stm_J_arpeggio(player_t * player, int channel_num)
{
    player_channel_t * channel = &(player->channels[channel_num]);
    if (channel->effect_value == 0)
        return;
    uint8_t temp = player->current_tick % 3;
    int temp2 = channel->period;
    if (!channel->period)
        return;
    switch (temp) {
    case 0:
        break;
    case 1:
        temp2 *= pow(2.0f, (float)(channel->effect_value >> 4) / -12.0f);
        break;
    case 2:
        temp2 *= pow(2.0f, (float)(channel->effect_value & 0xf) / -12.0f);
        break;
    }
    player_channel_set_frequency(player, (uint16_t)temp2, channel_num);
}

canonical_original_code:
void effects_stm_J_arpeggio(struct player_t *player, int channel_num)
{
    struct player_channel_t *channel = &(player->channels[channel_num]);
    if (channel->effect_value == 0)
        return;
    unsigned char temp = player->current_tick % 3;
    int temp2 = channel->period;
    if (!channel->period)
        return;
    switch (temp) {
    case 0:
        break;
    case 1:
        temp2 *= pow(2.0f, (float)(channel->effect_value >> 4) / -12.0f);
        break;
    case 2:
        temp2 *= pow(2.0f, (float)(channel->effect_value & 0xf) / -12.0f);
        break;
    }
    player_channel_set_frequency(player, (unsigned short)temp2, channel_num);
}

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


decompiled_code:
__int64 __fastcall effects_stm_get_tuned_period(_QWORD *a1, unsigned __int16 a2, int a3)
{
unsigned __int8 v3; // dl
__int64 result; // rax

v3 = *(_BYTE *)(*a1 + 104LL * a3);
result = 1LL;
if ( v3 )
result = (unsigned int)(8363 * a2 / *(unsigned __int16 *)(*(_QWORD *)(a1[1] + 376LL) + 80LL * v3 - 42));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, unsigned __int16 a2, int a3)
{
unsigned __int8 v3; // dl
__int64 result; // rax

v3 = *(_BYTE *)(*a1 + 104LL * a3);
result = 1LL;
if ( v3 )
result = (unsigned int)(8363 * a2 / *(unsigned __int16 *)(*(_QWORD *)(a1[1] + 376LL) + 80LL * v3 - 42));
return result;
}

original_code:
uint16_t effects_stm_get_tuned_period(player_t * player, uint16_t base_period, int channel)
{
    if (player->channels[channel].sample_num == 0)
        return 1;
    module_sample_t * sample = &(player->module->samples[player->channels[channel].sample_num - 1]);
    return (base_period * 8363) / sample->header.c2spd;
}

canonical_original_code:
unsigned short effects_stm_get_tuned_period(struct player_t *player, unsigned short base_period, int channel)
{
    if (player->channels[channel].sample_num == 0)
        return 1;
    struct module_sample_t *sample = &(player->module->samples[player->channels[channel].sample_num - 1]);
    return (base_period * 8363) / sample->header.c2spd;
}

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

return_type: unsigned short


original_code:
void effects_stm_newrowaction(player_t * player, module_pattern_data_t * data, int channel_num)
{
    if ((data->effect_num == 19) && ((data->effect_value >> 4) == 0xd)) {
        if (data->period_index >= 0) {
                player->channels[channel_num].dest_period = effects_stm_get_tuned_period(player, player->period_table[data->period_index], channel_num);
                player->channels[channel_num].dest_sample_num = data->sample_num;
                player->channels[channel_num].dest_volume = data->volume;
        } else {
            player->channels[channel_num].dest_period = 0;
        }
        return;
    }
    if (data->sample_num > 0) {
        player->channels[channel_num].sample_num = data->sample_num;
        player->channels[channel_num].volume = player->module->samples[player->channels[channel_num].sample_num - 1].header.volume;
    }
    if (data->volume >= 0) {
        player->channels[channel_num].volume = data->volume;
    }
    if (data->period_index >= 0) {
        if (player->channels[channel_num].vibrato_waveform < 4)
            player->channels[channel_num].vibrato_state = 0;
        player->channels[channel_num].period_index = data->period_index;
        if (data->period_index == 254) {
            player->channels[channel_num].sample_num = 0;
            return;
        } else {
            if (data->effect_num == 0x7) {
                player->channels[channel_num].dest_period = effects_stm_get_tuned_period(player, player->period_table[data->period_index], channel_num);
            } else {
                player->channels[channel_num].dest_period = 0;
                if (!(player->pattern_delay_active)) {
                    player->channels[channel_num].period = effects_stm_get_tuned_period(player, player->period_table[data->period_index], channel_num);
                    player->channels[channel_num].sample_pos = 0;
                }
            }
        }
    }
    player->channels[channel_num].volume_master = 64;
    if ((data->effect_num != 0x7) && (data->effect_num != 0x5) && (data->effect_num != 0x6) && (data->effect_num != 0x8)) {
        if (data->period_index >= 0)
            player_channel_set_frequency(player, player->channels[channel_num].period, channel_num);
    }
}

canonical_original_code:
void effects_stm_newrowaction(struct player_t *player, struct module_pattern_data_t *data, int channel_num)
{
    if ((data->effect_num == 19) && ((data->effect_value >> 4) == 0xd)) {
        if (data->period_index >= 0) {
                player->channels[channel_num].dest_period = effects_stm_get_tuned_period(player, player->period_table[data->period_index], channel_num);
                player->channels[channel_num].dest_sample_num = data->sample_num;
                player->channels[channel_num].dest_volume = data->volume;
        } else {
            player->channels[channel_num].dest_period = 0;
        }
        return;
    }
    if (data->sample_num > 0) {
        player->channels[channel_num].sample_num = data->sample_num;
        player->channels[channel_num].volume = player->module->samples[player->channels[channel_num].sample_num - 1].header.volume;
    }
    if (data->volume >= 0) {
        player->channels[channel_num].volume = data->volume;
    }
    if (data->period_index >= 0) {
        if (player->channels[channel_num].vibrato_waveform < 4)
            player->channels[channel_num].vibrato_state = 0;
        player->channels[channel_num].period_index = data->period_index;
        if (data->period_index == 254) {
            player->channels[channel_num].sample_num = 0;
            return;
        } else {
            if (data->effect_num == 0x7) {
                player->channels[channel_num].dest_period = effects_stm_get_tuned_period(player, player->period_table[data->period_index], channel_num);
            } else {
                player->channels[channel_num].dest_period = 0;
                if (!(player->pattern_delay_active)) {
                    player->channels[channel_num].period = effects_stm_get_tuned_period(player, player->period_table[data->period_index], channel_num);
                    player->channels[channel_num].sample_pos = 0;
                }
            }
        }
    }
    player->channels[channel_num].volume_master = 64;
    if ((data->effect_num != 0x7) && (data->effect_num != 0x5) && (data->effect_num != 0x6) && (data->effect_num != 0x8)) {
        if (data->period_index >= 0)
            player_channel_set_frequency(player, player->channels[channel_num].period, channel_num);
    }
}

variable_types:
data
struct module_pattern_data_t *


decompiled_code:
__int64 __fastcall output_portaudio_callback(__int64 a1, _WORD *a2, __int64 a3)
{
__int64 i; // rbx
__int16 v7; // [rsp+0h] [rbp-1Ch] BYREF
__int16 v8[13]; // [rsp+2h] [rbp-1Ah] BYREF

if ( !a3 )
return 0LL;
for ( i = 0LL; i != a3; ++i )
{
if ( (unsigned int)player_read(output_portaudio_player, v8, &v7) == 2 )
{
*a2 = v8[0];
a2[1] = v7;
a2 += 2;
}
else
{
*(_DWORD *)(output_portaudio_player + 168) = 0;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _WORD *a2, __int64 a3)
{
__int64 i; // rbx
__int16 v7; // [rsp+0h] [rbp-1Ch] BYREF
__int16 v8[13]; // [rsp+2h] [rbp-1Ah] BYREF

if ( !a3 )
return 0LL;
for ( i = 0LL; i != a3; ++i )
{
if ( (unsigned int)player_read(output_portaudio_player, v8, &v7) == 2 )
{
*a2 = v8[0];
a2[1] = v7;
a2 += 2;
}
else
{
*(_DWORD *)(output_portaudio_player + 168) = 0;
}
}
return 0LL;
}

original_code:
int output_portaudio_callback(
        const void * inputBuffer,
        void * outputBuffer,
        unsigned long framesPerBuffer,
        const PaStreamCallbackTimeInfo * timeInfo,
        PaStreamCallbackFlags statusFlags,
        void * userData)
{
    unsigned long i;
    int ret;
    sample_t * out = outputBuffer;
    sample_t mix_l, mix_r;
    for (i=0; i < framesPerBuffer; i++) {
        ret = player_read(output_portaudio_player, &mix_l, &mix_r);
        if (ret != 2) {
            output_portaudio_player->playing = 0;
        } else {
            *out++ = mix_l;
            *out++ = mix_r;
        }
    }
    return 0;
}

canonical_original_code:
int output_portaudio_callback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, struct PaStreamCallbackTimeInfo *timeInfo, unsigned long statusFlags, void *userData)
{
    unsigned long i;
    int ret;
    short *out = outputBuffer;
    short mix_l; short mix_r;
    for (i=0; i < framesPerBuffer; i++) {
        ret = player_read(output_portaudio_player, &mix_l, &mix_r);
        if (ret != 2) {
            output_portaudio_player->playing = 0;
        } else {
            *out++ = mix_l;
            *out++ = mix_r;
        }
    }
    return 0;
}

variable_types:
inputBuffer
void *

variable_types:
outputBuffer
void *

variable_types:
framesPerBuffer
unsigned long

variable_types: struct PaStreamCallbackTimeInfo { double inputBufferAdcTime; double currentTime; double outputBufferDacTime; } *

variable_types:
statusFlags
unsigned long

variable_types:
userData
void *

variable_types:
i
unsigned long

variable_types: ret int

variable_types:
out
short *

return_type: int


decompiled_code:
__int64 __fastcall output_portaudio_init(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
const char *v4; // rax
const char *v5; // rax

v1 = Pa_Initialize();
if ( v1 )
{
v4 = (const char *)Pa_GetErrorText(v1);
fprintf(stderr, "Error initializing PortAudio: %s", v4);
exit(1);
}
v2 = Pa_OpenDefaultStream(
&output_portaudio_stream,
0LL,
2LL,
8LL,
*(int *)(a1 + 4),
output_portaudio_callback,
(double)*(int *)(a1 + 8),
0LL);
if ( v2 )
{
v5 = (const char *)Pa_GetErrorText(v2);
fprintf(stderr, "Error initializing PortAudio Stream: %s", v5);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
const char *v4; // rax
const char *v5; // rax

v1 = Pa_Initialize();
if ( v1 )
{
v4 = (const char *)Pa_GetErrorText(v1);
fprintf(stderr, "Error initializing PortAudio: %s", v4);
exit(1);
}
v2 = Pa_OpenDefaultStream(
&output_portaudio_stream,
0LL,
2LL,
8LL,
*(int *)(a1 + 4),
output_portaudio_callback,
(double)*(int *)(a1 + 8),
0LL);
if ( v2 )
{
v5 = (const char *)Pa_GetErrorText(v2);
fprintf(stderr, "Error initializing PortAudio Stream: %s", v5);
exit(1);
}
return 0LL;
}

original_code:
int output_portaudio_init(output_opts_t * output_opts)
{
    PaError err;
    err = Pa_Initialize();
    if (err != paNoError) {
        fprintf(stderr, "Error initializing PortAudio: %s", Pa_GetErrorText(err));
        exit(1);
    }
    err = Pa_OpenDefaultStream(
        &output_portaudio_stream,
        0,
        2,
        ((PaSampleFormat) 0x00000008),
        output_opts->sample_rate,
        output_opts->buffer_size,
        output_portaudio_callback,
        0 );
    if( err != paNoError ) {
        fprintf(stderr, "Error initializing PortAudio Stream: %s", Pa_GetErrorText(err));
        exit(1);
    }
    return 0;
}

canonical_original_code:
int output_portaudio_init(struct output_opts_t *output_opts)
{
    int err;
    err = Pa_Initialize();
    if (err != paNoError) {
        fprintf(stderr, "Error initializing PortAudio: %s", Pa_GetErrorText(err));
        exit(1);
    }
    err = Pa_OpenDefaultStream(
        &output_portaudio_stream,
        0,
        2,
        ((unsigned long) 0x00000008),
        output_opts->sample_rate,
        output_opts->buffer_size,
        output_portaudio_callback,
        0 );
    if( err != paNoError ) {
        fprintf(stderr, "Error initializing PortAudio Stream: %s", Pa_GetErrorText(err));
        exit(1);
    }
    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; } *

variable_types: err int

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


decompiled_code:
__int64 output_portaudio_cleanup()
{
unsigned int v0; // eax
const char *v2; // rax

v0 = Pa_Terminate();
if ( v0 )
{
v2 = (const char *)Pa_GetErrorText(v0);
fprintf(stderr, "Error terminating PortAudio: %s", v2);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax
const char *v2; // rax

v0 = Pa_Terminate();
if ( v0 )
{
v2 = (const char *)Pa_GetErrorText(v0);
fprintf(stderr, "Error terminating PortAudio: %s", v2);
exit(1);
}
return 0LL;
}

original_code:
int output_portaudio_cleanup()
{
    PaError err;
    err = Pa_Terminate();
    if (err != paNoError) {
        fprintf(stderr, "Error terminating PortAudio: %s", Pa_GetErrorText(err));
        exit(1);
    }
    return 0;
}

canonical_original_code:
int output_portaudio_cleanup()
{
    int err;
    err = Pa_Terminate();
    if (err != paNoError) {
        fprintf(stderr, "Error terminating PortAudio: %s", Pa_GetErrorText(err));
        exit(1);
    }
    return 0;
}


decompiled_code:
__int64 __fastcall output_portaudio_start(__int64 a1)
{
unsigned int v1; // eax
const char *v3; // rax

output_portaudio_player = a1;
*(_DWORD *)(a1 + 168) = 1;
v1 = Pa_StartStream(output_portaudio_stream);
if ( v1 )
{
v3 = (const char *)Pa_GetErrorText(v1);
fprintf(stderr, "Error starting PortAudio Stream: %s", v3);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // eax
const char *v3; // rax

output_portaudio_player = a1;
*(_DWORD *)(a1 + 168) = 1;
v1 = Pa_StartStream(output_portaudio_stream);
if ( v1 )
{
v3 = (const char *)Pa_GetErrorText(v1);
fprintf(stderr, "Error starting PortAudio Stream: %s", v3);
exit(1);
}
return 0LL;
}

original_code:
int output_portaudio_start(player_t * player)
{
    PaError err;
    output_portaudio_player = player;
    player->playing = 1;
    err = Pa_StartStream(output_portaudio_stream);
    if(err != paNoError) {
        fprintf(stderr, "Error starting PortAudio Stream: %s", Pa_GetErrorText(err));
        exit(1);
    }
    return 0;
}

canonical_original_code:
int output_portaudio_start(struct player_t *player)
{
    int err;
    output_portaudio_player = player;
    player->playing = 1;
    err = Pa_StartStream(output_portaudio_stream);
    if(err != paNoError) {
        fprintf(stderr, "Error starting PortAudio Stream: %s", Pa_GetErrorText(err));
        exit(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_portaudio_stop()
{
Pa_StopStream(output_portaudio_stream);
return 0LL;
}

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

original_code:
int output_portaudio_stop()
{
    Pa_StopStream(output_portaudio_stream);
    return 0;
}


decompiled_code:
__int64 output_portaudio_wait()
{
return Pa_Sleep(0LL);
}

canonical_decompiled_code:
__int64 func5()
{
return Pa_Sleep(0LL);
}

original_code:
void output_portaudio_wait()
{
    Pa_Sleep(0);
}


decompiled_code:
void __fastcall dllist_init(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 16) = 0;
}

original_code:
void dllist_init(dllist_t * list) {
    list->first = list->last = 0;
    list->count = 0;
}

canonical_original_code:
void dllist_init(struct dllist_t *list) {
    list->first = list->last = 0;
    list->count = 0;
}

variable_types: struct dllist_t { struct dllist_element_s { struct dllist_element_s *next; struct dllist_element_s *prev; void *data; } *first; struct dllist_element_s *last; int count; } *

user_defined_types: struct dllist_t { struct dllist_element_s *first; struct dllist_element_s *last; int count; }


original_code:
void dllist_push(dllist_t * list, dllist_element_t * child) {
    if (list->count) {
        list->last->next = child;
        child->prev = list->last;
        list->last = child;
    } else {
        list->last = child;
        list->first = child;
    }
    list->count++;
}

canonical_original_code:
void dllist_push(struct dllist_t *list, struct dllist_element_s *child) {
    if (list->count) {
        list->last->next = child;
        child->prev = list->last;
        list->last = child;
    } else {
        list->last = child;
        list->first = child;
    }
    list->count++;
}

variable_types:
child
struct dllist_element_s *

user_defined_types: struct dllist_element_s { struct dllist_element_s *next; struct dllist_element_s *prev; void *data; }


original_code:
dllist_element_t * dllist_pop(dllist_t * list) {
    if (list->count == 0)
        return 0;
    dllist_element_t * ret = list->last;
    list->last = ret->prev;
    if (list->last)
        list->last->next = 0;
    ret->prev = 0;
    list->count--;
    if (list->count == 0)
        list->first = 0;
    return ret;
}

canonical_original_code:
struct dllist_element_s *dllist_pop(struct dllist_t *list) {
    if (list->count == 0)
        return 0;
    struct dllist_element_s *ret = list->last;
    list->last = ret->prev;
    if (list->last)
        list->last->next = 0;
    ret->prev = 0;
    list->count--;
    if (list->count == 0)
        list->first = 0;
    return ret;
}

variable_types: struct dllist_t { struct dllist_element_s *first; struct dllist_element_s *last; int count; } *

variable_types: struct dllist_element_s { struct dllist_element_s *next; struct dllist_element_s *prev; void *data; } *


decompiled_code:
__int64 __fastcall io_mem_tell(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)a1 + 16LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)a1 + 16LL);
}

original_code:
size_t io_mem_tell(io_handle_t * handle)
{
    io_mem_native_handle_t * native_handle = (io_mem_native_handle_t *)handle->native_handle;
    return native_handle->pos;
}

canonical_original_code:
unsigned long io_mem_tell(struct io_handle_t *handle)
{
    struct io_mem_native_handle_t *native_handle = (io_mem_native_handle_t *)handle->native_handle;
    return native_handle->pos;
}

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: struct io_mem_native_handle_t { char *ptr; unsigned long size; unsigned long pos; } *

return_type: unsigned long

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 io_mem_seek(struct io_handle_t * handle, size_t n, io_seek_direction_t direction)
{
    io_mem_native_handle_t * native_handle = (io_mem_native_handle_t *)handle->native_handle;
    switch (direction) {
        case io_seek_cur:
            native_handle->pos += n;
            break;
        case io_seek_set:
            native_handle->pos = n;
            break;
        case io_seek_end:
            native_handle->pos = native_handle->size - n;
            break;
    }
    if (native_handle->pos > native_handle->size)
        native_handle->pos = native_handle->size;
    return 0;
}

canonical_original_code:
int io_mem_seek(struct io_handle_t *handle, unsigned long n, enum io_seek_direction_t direction)
{
    struct io_mem_native_handle_t *native_handle = (io_mem_native_handle_t *)handle->native_handle;
    switch (direction) {
        case io_seek_cur:
            native_handle->pos += n;
            break;
        case io_seek_set:
            native_handle->pos = n;
            break;
        case io_seek_end:
            native_handle->pos = native_handle->size - n;
            break;
    }
    if (native_handle->pos > native_handle->size)
        native_handle->pos = native_handle->size;
    return 0;
}

variable_types:
n
unsigned long

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

user_defined_types: struct io_mem_native_handle_t { char *ptr; unsigned long size; unsigned long pos; }


decompiled_code:
_BOOL8 __fastcall io_mem_feof(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)a1 + 16LL) >= *(_QWORD *)(*(_QWORD *)a1 + 8LL);
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)a1 + 16LL) >= *(_QWORD *)(*(_QWORD *)a1 + 8LL);
}

original_code:
int io_mem_feof(struct io_handle_t * handle ) {
    io_mem_native_handle_t * native_handle = (io_mem_native_handle_t *)handle->native_handle;
    return (native_handle->pos >= native_handle->size);
}

canonical_original_code:
int io_mem_feof(struct io_handle_t *handle) {
    struct io_mem_native_handle_t *native_handle = (io_mem_native_handle_t *)handle->native_handle;
    return (native_handle->pos >= native_handle->size);
}

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


decompiled_code:
__int64 __fastcall io_mem_read(void *dest, size_t n, __int64 a3, _QWORD **a4)
{
__int64 v4; // r14
_QWORD *v5; // rbx
__int64 v8; // r13
__int64 v9; // rsi

v4 = a3;
v5 = *a4;
if ( a3 )
{
v8 = 0LL;
while ( 1 )
{
v9 = v5[2];
if ( v9 + n >= v5[1] )
break;
memcpy(dest, (const void *)(*v5 + v9), n);
v5[2] += n;
dest = (char *)dest + n;
if ( ++v8 == v4 )
return v4;
}
v4 = v8;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *dest, size_t n, __int64 a3, _QWORD **a4)
{
__int64 v4; // r14
_QWORD *v5; // rbx
__int64 v8; // r13
__int64 v9; // rsi

v4 = a3;
v5 = *a4;
if ( a3 )
{
v8 = 0LL;
while ( 1 )
{
v9 = v5[2];
if ( v9 + n >= v5[1] )
break;
memcpy(dest, (const void *)(*v5 + v9), n);
v5[2] += n;
dest = (char *)dest + n;
if ( ++v8 == v4 )
return v4;
}
v4 = v8;
}
return v4;
}

original_code:
size_t io_mem_read(void * ptr, size_t size, size_t n, io_handle_t * handle)
{
    int i;
    io_mem_native_handle_t * native_handle = (io_mem_native_handle_t *)handle->native_handle;
    for (i = 0; i < n; i++) {
        if (native_handle->pos + size < native_handle->size) {
            memcpy(ptr, (void *)(native_handle->ptr + native_handle->pos), size);
            native_handle->pos += size;
            ptr += size;
        } else {
            break;
        }
    }
    return i;
}

canonical_original_code:
unsigned long io_mem_read(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle)
{
    int i;
    struct io_mem_native_handle_t *native_handle = (io_mem_native_handle_t *)handle->native_handle;
    for (i = 0; i < n; i++) {
        if (native_handle->pos + size < native_handle->size) {
            memcpy(ptr, (void *)(native_handle->ptr + native_handle->pos), size);
            native_handle->pos += size;
            ptr += size;
        } else {
            break;
        }
    }
    return i;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types: i int


decompiled_code:
__int64 __fastcall io_mem_write(void *src, size_t n, __int64 a3, _QWORD **a4)
{
__int64 v4; // r14
_QWORD *v5; // rbx
__int64 v7; // r13
__int64 v8; // rdi

v4 = a3;
v5 = *a4;
if ( a3 )
{
v7 = 0LL;
while ( 1 )
{
v8 = v5[2];
if ( v8 + n >= v5[1] )
break;
memcpy((void *)(*v5 + v8), src, n);
v5[2] += n;
src = (char *)src + n;
if ( ++v7 == v4 )
return v4;
}
v4 = v7;
}
return v4;
}

original_code:
size_t io_mem_write(const void * ptr, size_t size, size_t n, io_handle_t * handle)
{
    int i;
    io_mem_native_handle_t * native_handle = (io_mem_native_handle_t *)handle->native_handle;
    for (i = 0; i < n; i++) {
        if (native_handle->pos + size < native_handle->size) {
            memcpy((void *)(native_handle->ptr + native_handle->pos), ptr, size);
            native_handle->pos += size;
            ptr += size;
        } else {
            break;
        }
    }
    return i;
}

canonical_original_code:
unsigned long io_mem_write(void *ptr, unsigned long size, unsigned long n, struct io_handle_t *handle)
{
    int i;
    struct io_mem_native_handle_t *native_handle = (io_mem_native_handle_t *)handle->native_handle;
    for (i = 0; i < n; i++) {
        if (native_handle->pos + size < native_handle->size) {
            memcpy((void *)(native_handle->ptr + native_handle->pos), ptr, size);
            native_handle->pos += size;
            ptr += size;
        } else {
            break;
        }
    }
    return i;
}


decompiled_code:
__int64 __fastcall io_mem_close(void *ptr)
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
int io_mem_close(io_handle_t * handle) {
    free((io_mem_native_handle_t *)handle->native_handle);
    free(handle);
    return 0;
}

canonical_original_code:
int io_mem_close(struct io_handle_t *handle) {
    free((struct io_mem_native_handle_t *)handle->native_handle);
    free(handle);
    return 0;
}


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

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

original_code: static inline sample_t sample_from_s16(int16_t s) { return (sample_t)s; }

canonical_original_code: static inline short sample_from_s16(short s) { return (short)s; }

variable_types: s short

return_type: short


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

canonical_decompiled_code:
__int64 __fastcall func1(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


original_code:
int loader_s3m_check(io_handle_t * h)
{
    char signature[4];
    size_t saved_pos;
    memset(signature, 0, 4);
    saved_pos = h->tell(h);
    h->seek(h, 0x2c, io_seek_set);
    h->read(signature, 1, 4, h);
    h->seek(h, saved_pos, io_seek_set);
    if (memcmp(signature, "SCRM", 4))
        return 0;
    return 1;
}

canonical_original_code:
int loader_s3m_check(struct io_handle_t *h)
{
    char signature[4];
    unsigned long saved_pos;
    memset(signature, 0, 4);
    saved_pos = h->tell(h);
    h->seek(h, 0x2c, io_seek_set);
    h->read(signature, 1, 4, h);
    h->seek(h, saved_pos, io_seek_set);
    if (memcmp(signature, "SCRM", 4))
        return 0;
    return 1;
}

variable_types:
signature
char [4]


decompiled_code:
__int64 loader_loadmem_by_header()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbx

v0 = io_mem_open();
if ( !v0 )
return 0LL;
v1 = 0LL;
while ( !((unsigned int (__fastcall *)(__int64))*(&loader_formats + 4 * v1))(v0) )
{
if ( ++v1 == 6 )
{
v2 = 0LL;
goto LABEL_6;
}
}
v2 = ((__int64 (__fastcall *)(__int64))*(&off_248 + 4 * (int)v1))(v0);
LABEL_6:
io_mem_close(v0);
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbx

v0 = io_mem_open();
if ( !v0 )
return 0LL;
v1 = 0LL;
while ( !((unsigned int (__fastcall *)(__int64))*(&loader_formats + 4 * v1))(v0) )
{
if ( ++v1 == 6 )
{
v2 = 0LL;
goto LABEL_6;
}
}
v2 = ((__int64 (__fastcall *)(__int64))*(&off_248 + 4 * (int)v1))(v0);
LABEL_6:
io_mem_close(v0);
return v2;
}

original_code:
module_t * loader_loadmem_by_header(void * ptr, size_t size)
{
    int i;
    io_handle_t * h = io_mem_open(ptr, size);
    module_t * module = 0;
    if (h) {
        for (i = 0; i < 6; i++) {
            if (loader_formats[i].check(h)) {
                module = loader_formats[i].load(h);
                break;
            }
        }
        io_mem_close(h);
    }
    return module;
}

canonical_original_code:
struct module_t *loader_loadmem_by_header(void *ptr, unsigned long size)
{
    int i;
    struct io_handle_t *h = io_mem_open(ptr, size);
    struct module_t *module = 0;
    if (h) {
        for (i = 0; i < 6; i++) {
            if (loader_formats[i].check(h)) {
                module = loader_formats[i].load(h);
                break;
            }
        }
        io_mem_close(h);
    }
    return module;
}

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

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_sample_t { struct module_sample_header_t header; short *data; }


decompiled_code:
__int64 __fastcall loader_loadfile_by_header(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rbx

v1 = io_file_open(a1, &unk_199);
if ( !v1 )
return 0LL;
v2 = 0LL;
while ( !((unsigned int (__fastcall *)(__int64))*(&loader_formats + 4 * v2))(v1) )
{
if ( ++v2 == 6 )
{
v3 = 0LL;
goto LABEL_6;
}
}
v3 = ((__int64 (__fastcall *)(__int64))*(&off_248 + 4 * (int)v2))(v1);
LABEL_6:
io_file_close(v1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rbx

v1 = io_file_open(a1, &unk_199);
if ( !v1 )
return 0LL;
v2 = 0LL;
while ( !((unsigned int (__fastcall *)(__int64))*(&loader_formats + 4 * v2))(v1) )
{
if ( ++v2 == 6 )
{
v3 = 0LL;
goto LABEL_6;
}
}
v3 = ((__int64 (__fastcall *)(__int64))*(&off_248 + 4 * (int)v2))(v1);
LABEL_6:
io_file_close(v1);
return v3;
}

original_code:
module_t * loader_loadfile_by_header(char * filename)
{
    int i;
    io_handle_t * h = io_file_open(filename, "rb");
    module_t * module = 0;
    if (h) {
        for (i = 0; i < 6; i++) {
            if (loader_formats[i].check(h)) {
                module = loader_formats[i].load(h);
                break;
            }
        }
        io_file_close(h);
    }
    return module;
}

canonical_original_code:
struct module_t *loader_loadfile_by_header(char *filename)
{
    int i;
    struct io_handle_t *h = io_file_open(filename, "rb");
    struct module_t *module = 0;
    if (h) {
        for (i = 0; i < 6; i++) {
            if (loader_formats[i].check(h)) {
                module = loader_formats[i].load(h);
                break;
            }
        }
        io_file_close(h);
    }
    return module;
}

variable_types:
filename
char *

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

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


decompiled_code:
__int64 __fastcall loader_loadfile_by_extension(char *s)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rbp
size_t v4; // rax
char *v5; // rax
__int64 v6; // rbx
char dest[3]; // [rsp+Ch] [rbp-1Ch] BYREF
char v9; // [rsp+Fh] [rbp-19h] BYREF

v1 = io_file_open(s, &unk_199);
v2 = v1;
if ( v1 )
{
v3 = v1;
v4 = strlen(s);
v9 = 0;
strncpy(dest, &s[v4 - 3], 3uLL);
v5 = dest;
do
{
if ( (unsigned __int8)(*v5 - 65) <= 0x19u )
*v5 += 32;
++v5;
}
while ( v5 != &v9 );
v6 = 0LL;
while ( strcmp(dest, (const char *)*(&off_250 + 4 * v6)) )
{
if ( ++v6 == 6 )
{
v2 = 0LL;
goto LABEL_10;
}
}
v2 = ((__int64 (__fastcall *)(__int64))*(&off_248 + 4 * (int)v6))(v3);
LABEL_10:
io_file_close(v3);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rbp
size_t v4; // rax
char *v5; // rax
__int64 v6; // rbx
char dest[3]; // [rsp+Ch] [rbp-1Ch] BYREF
char v9; // [rsp+Fh] [rbp-19h] BYREF

v1 = io_file_open(s, &unk_199);
v2 = v1;
if ( v1 )
{
v3 = v1;
v4 = strlen(s);
v9 = 0;
strncpy(dest, &s[v4 - 3], 3uLL);
v5 = dest;
do
{
if ( (unsigned __int8)(*v5 - 65) <= 0x19u )
*v5 += 32;
++v5;
}
while ( v5 != &v9 );
v6 = 0LL;
while ( strcmp(dest, (const char *)*(&off_250 + 4 * v6)) )
{
if ( ++v6 == 6 )
{
v2 = 0LL;
goto LABEL_10;
}
}
v2 = ((__int64 (__fastcall *)(__int64))*(&off_248 + 4 * (int)v6))(v3);
LABEL_10:
io_file_close(v3);
}
return v2;
}

original_code:
module_t * loader_loadfile_by_extension(char * filename)
{
    char tmp[4];
    int i;
    io_handle_t * h = io_file_open(filename, "rb");
    char * ext = filename + (strlen(filename) - 3);
    module_t * module = 0;
    if (h) {
        tmp[3] = 0;
        strncpy (tmp, ext, 3);
        for (i = 0; i < 3; i++) {
            if ((tmp[i] <= 90) && tmp[i] >= 65)
                tmp[i] += 32;
        }
        for (i = 0; i < 6; i++) {
            if (!strcmp(tmp, loader_formats[i].extension)) {
                module = loader_formats[i].load(h);
                break;
            }
        }
        io_file_close(h);
    }
    return module;
}

canonical_original_code:
struct module_t *loader_loadfile_by_extension(char *filename)
{
    char tmp[4];
    int i;
    struct io_handle_t *h = io_file_open(filename, "rb");
    char *ext = filename + (strlen(filename) - 3);
    struct module_t *module = 0;
    if (h) {
        tmp[3] = 0;
        strncpy (tmp, ext, 3);
        for (i = 0; i < 3; i++) {
            if ((tmp[i] <= 90) && tmp[i] >= 65)
                tmp[i] += 32;
        }
        for (i = 0; i < 6; i++) {
            if (!strcmp(tmp, loader_formats[i].extension)) {
                module = loader_formats[i].load(h);
                break;
            }
        }
        io_file_close(h);
    }
    return module;
}

variable_types:
tmp
char [4]

variable_types:
ext
char *

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 __fastcall sample_to_s16(unsigned int a1)
{
return a1;
}

original_code: static inline int16_t sample_to_s16(sample_t s) { return s; }

canonical_original_code: static inline short sample_to_s16(short s) { return s; }


decompiled_code:
__int64 output_alsa_cleanup()
{
snd_pcm_close(playback_handle);
free(output_buffer);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
snd_pcm_close(playback_handle);
free(output_buffer);
return 0LL;
}

original_code:
int output_alsa_cleanup()
{
    snd_pcm_close(playback_handle);
    free(output_buffer);
    return 0;
}


decompiled_code:
__int64 __fastcall output_alsa_start(__int64 a1)
{
unsigned int v1; // eax
const char *v3; // rax

puts("shouldplay2");
output_alsa_player = a1;
*(_DWORD *)(a1 + 168) = 1;
v1 = snd_async_add_pcm_handler(&callback_handle, playback_handle, output_alsa_callback, 0LL);
if ( v1 )
{
v3 = (const char *)snd_strerror(v1);
fprintf(stderr, "handler failed (%s)\n", v3);
}
if ( (unsigned int)snd_pcm_start(playback_handle) )
fwrite("start failed\n", 1uLL, 0xDuLL, stderr);
puts("shouldplay");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // eax
const char *v3; // rax

puts("shouldplay2");
output_alsa_player = a1;
*(_DWORD *)(a1 + 168) = 1;
v1 = snd_async_add_pcm_handler(&callback_handle, playback_handle, output_alsa_callback, 0LL);
if ( v1 )
{
v3 = (const char *)snd_strerror(v1);
fprintf(stderr, "handler failed (%s)\n", v3);
}
if ( (unsigned int)snd_pcm_start(playback_handle) )
fwrite("start failed\n", 1uLL, 0xDuLL, stderr);
puts("shouldplay");
return 0LL;
}

original_code:
int output_alsa_start(player_t * player) {
    printf( "shouldplay2\n");
    output_alsa_player = player;
    player->playing = 1;
    int err = snd_async_add_pcm_handler(&callback_handle, playback_handle, output_alsa_callback, 0);
    if (err != 0)
        fprintf(stderr, "handler failed (%s)\n", snd_strerror(err));
    if (snd_pcm_start(playback_handle) != 0)
        fprintf(stderr, "start failed\n");
    printf( "shouldplay\n");
    return 0;
}

canonical_original_code:
int output_alsa_start(struct player_t *player) {
    printf( "shouldplay2\n");
    output_alsa_player = player;
    player->playing = 1;
    int err = snd_async_add_pcm_handler(&callback_handle, playback_handle, output_alsa_callback, 0);
    if (err != 0)
        fprintf(stderr, "handler failed (%s)\n", snd_strerror(err));
    if (snd_pcm_start(playback_handle) != 0)
        fprintf(stderr, "start failed\n");
    printf( "shouldplay\n");
    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; } *

variable_types: err int

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_alsa_stop()
{
snd_pcm_drop(playback_handle);
snd_async_del_handler(callback_handle);
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
snd_pcm_drop(playback_handle);
snd_async_del_handler(callback_handle);
return 0LL;
}

original_code:
int output_alsa_stop() {
    snd_pcm_drop(playback_handle);
    snd_async_del_handler (callback_handle);
    return 0;
}


decompiled_code:
__int64 __fastcall output_alsa_write(float a1, float a2)
{
unsigned int v3; // eax
const char *v4; // rax

*((_WORD *)output_buffer + output_buffer_pos) = (int)(float)(a1 * 32767.0);
*((_WORD *)output_buffer + output_buffer_pos + 1) = (int)(float)(a2 * 32767.0);
output_buffer_pos += 2;
if ( output_buffer_pos <= (unsigned __int64)output_buffer_size )
return 2LL;
v3 = snd_pcm_writei(playback_handle, output_buffer);
if ( v3 != (unsigned __int64)output_buffer_size >> 1 )
{
v4 = (const char *)snd_strerror(v3);
fprintf(stderr, "write to audio interface failed (%s)\n", v4);
exit(1);
}
output_buffer_pos = 0;
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(float a1, float a2)
{
unsigned int v3; // eax
const char *v4; // rax

*((_WORD *)output_buffer + output_buffer_pos) = (int)(float)(a1 * 32767.0);
*((_WORD *)output_buffer + output_buffer_pos + 1) = (int)(float)(a2 * 32767.0);
output_buffer_pos += 2;
if ( output_buffer_pos <= (unsigned __int64)output_buffer_size )
return 2LL;
v3 = snd_pcm_writei(playback_handle, output_buffer);
if ( v3 != (unsigned __int64)output_buffer_size >> 1 )
{
v4 = (const char *)snd_strerror(v3);
fprintf(stderr, "write to audio interface failed (%s)\n", v4);
exit(1);
}
output_buffer_pos = 0;
return 2LL;
}

original_code:
int output_alsa_write(float l, float r)
{
    int err;
    output_buffer[output_buffer_pos] = (int16_t)(l * 32767);
    output_buffer[output_buffer_pos + 1] = (int16_t)(r * 32767);
    output_buffer_pos += 2;
    if (output_buffer_pos > (output_buffer_size) ) {
        if ((err = snd_pcm_writei(playback_handle, output_buffer, output_buffer_size / 2)) != (output_buffer_size / 2)) {
            fprintf (stderr, "write to audio interface failed (%s)\n",
                    snd_strerror (err));
            exit (1);
        }
        output_buffer_pos = 0;
    }
    return 2;
}

canonical_original_code:
int output_alsa_write(float l, float r)
{
    int err;
    output_buffer[output_buffer_pos] = (short)(l * 32767);
    output_buffer[output_buffer_pos + 1] = (short)(r * 32767);
    output_buffer_pos += 2;
    if (output_buffer_pos > (output_buffer_size) ) {
        if ((err = snd_pcm_writei(playback_handle, output_buffer, output_buffer_size / 2)) != (output_buffer_size / 2)) {
            fprintf (stderr, "write to audio interface failed (%s)\n",
                    snd_strerror (err));
            exit (1);
        }
        output_buffer_pos = 0;
    }
    return 2;
}

variable_types: l float

variable_types: r float


original_code:
scalar_t osc_fetch_sample(osc_t * osc, scalar_t sample_freq)
{
 const scalar_t PI_2 = 6.283185307;
 scalar_t sample;
 switch (osc->type) {
 case OSC_TYPE_SINE:
 default:
  osc->phase += ((osc->freq / sample_freq) * PI_2);
  while (osc->phase > PI_2)
   osc->phase -= PI_2;
  sample = sin(osc->phase);
  break;
 case OSC_TYPE_SAWTOOTH:
  osc->phase += (osc->freq / sample_freq) * 2;
  if (osc->phase > 1)
   osc->phase -= 2;
  sample = osc->phase;
  break;
 case OSC_TYPE_SQUARE:
  osc->phase += (osc->freq / sample_freq) * 2;
  if (osc->phase > 1)
   osc->phase -= 2;
  sample = (osc->phase > 0) ? 1 : -1;
  break;
 }
 return sample;
}

canonical_original_code:
float osc_fetch_sample(struct osc_t *osc, float sample_freq)
{
 float PI_2 = 6.283185307;
 float sample;
 switch (osc->type) {
 case OSC_TYPE_SINE:
 default:
  osc->phase += ((osc->freq / sample_freq) * PI_2);
  while (osc->phase > PI_2)
   osc->phase -= PI_2;
  sample = sin(osc->phase);
  break;
 case OSC_TYPE_SAWTOOTH:
  osc->phase += (osc->freq / sample_freq) * 2;
  if (osc->phase > 1)
   osc->phase -= 2;
  sample = osc->phase;
  break;
 case OSC_TYPE_SQUARE:
  osc->phase += (osc->freq / sample_freq) * 2;
  if (osc->phase > 1)
   osc->phase -= 2;
  sample = (osc->phase > 0) ? 1 : -1;
  break;
 }
 return sample;
}

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

variable_types: sample float

return_type: float

user_defined_types: struct osc_t { enum osc_type_t type; float phase; float phase_offset; float freq; float *waveform; float waveform_length; }


decompiled_code:
int __fastcall filter_moog_set_params(float *a1, float a2, float a3)
{
int result; // eax
float v4; // xmm1_4

fprintf(stderr, "filter: cutoff=%3.2f, resonance=%3.2f\n", a2, a3);
result = fflush(stderr);
v4 = (float)((float)(a2 * 0.80000001) * (float)(1.0 - a2)) + a2;
a1[1] = v4;
*a1 = (float)(v4 + v4) - 1.0;
a1[2] = (float)((float)((float)((float)((float)((float)(1.0 - a2) * 5.5999999) * (float)(1.0 - a2))
+ (float)(1.0 - (float)(1.0 - a2)))
* (float)((float)(1.0 - a2) * 0.5))
+ 1.0)
* a3;
return result;
}

canonical_decompiled_code:
int __fastcall func10(float *a1, float a2, float a3)
{
int result; // eax
float v4; // xmm1_4

fprintf(stderr, "filter: cutoff=%3.2f, resonance=%3.2f\n", a2, a3);
result = fflush(stderr);
v4 = (float)((float)(a2 * 0.80000001) * (float)(1.0 - a2)) + a2;
a1[1] = v4;
*a1 = (float)(v4 + v4) - 1.0;
a1[2] = (float)((float)((float)((float)((float)((float)(1.0 - a2) * 5.5999999) * (float)(1.0 - a2))
+ (float)(1.0 - (float)(1.0 - a2)))
* (float)((float)(1.0 - a2) * 0.5))
+ 1.0)
* a3;
return result;
}

original_code:
void filter_moog_set_params(filter_moog_t * f, scalar_t frequency, scalar_t resonance)
{
 fprintf(stderr, "filter: cutoff=%3.2f, resonance=%3.2f\n", frequency, resonance);
 fflush(stderr);
 f->q = 1.0f - frequency;
 f->p = frequency + 0.8f * frequency * f->q;
 f->f = f->p + f->p - 1.0f;
 f->q = resonance * (1.0f + 0.5f * f->q * (1.0f - f->q + 5.6f * f->q * f->q));
}

canonical_original_code:
void filter_moog_set_params(struct filter_moog_t *f, float frequency, float resonance)
{
 fprintf(stderr, "filter: cutoff=%3.2f, resonance=%3.2f\n", frequency, resonance);
 fflush(stderr);
 f->q = 1.0f - frequency;
 f->p = frequency + 0.8f * frequency * f->q;
 f->f = f->p + f->p - 1.0f;
 f->q = resonance * (1.0f + 0.5f * f->q * (1.0f - f->q + 5.6f * f->q * f->q));
}

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

variable_types: frequency float

variable_types: resonance float


variable_types:
sample
float *

variable_types: in float

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


decompiled_code:
int __fastcall make_noise(__int64 a1, int a2, float *a3, float a4, float a5, float a6)
{
int v6; // er12
int result; // eax
__int64 v9; // rbx
float v10; // xmm0_4
__int16 ptr; // [rsp+1Ah] [rbp-3Eh] BYREF
float v12[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v6 = (int)(float)(a4 * a5);
if ( v6 > 0 )
{
do
{
v12[0] = 0.0;
if ( a2 > 0 )
{
v9 = a1;
do
{
v10 = osc_fetch_sample(v9, a5);
v12[0] = v10 + v12[0];
v9 += 32LL;
}
while ( v9 != a1 + 32LL * (unsigned int)(a2 - 1) + 32 );
}
v12[0] = v12[0] / (float)a2;
if ( a3 )
filter_moog_process(a3, v12);
v12[0] = (float)((float)v6 * a6) * v12[0];
ptr = (int)(float)(v12[0] * 32767.0);
fwrite(&ptr, 2uLL, 1uLL, stdout);
result = fflush(stdout);
--v6;
}
while ( v6 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1, int a2, float *a3, float a4, float a5, float a6)
{
int v6; // er12
int result; // eax
__int64 v9; // rbx
float v10; // xmm0_4
__int16 ptr; // [rsp+1Ah] [rbp-3Eh] BYREF
float v12[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v6 = (int)(float)(a4 * a5);
if ( v6 > 0 )
{
do
{
v12[0] = 0.0;
if ( a2 > 0 )
{
v9 = a1;
do
{
v10 = func8(v9, a5);
v12[0] = v10 + v12[0];
v9 += 32LL;
}
while ( v9 != a1 + 32LL * (unsigned int)(a2 - 1) + 32 );
}
v12[0] = v12[0] / (float)a2;
if ( a3 )
func11(a3, v12);
v12[0] = (float)((float)v6 * a6) * v12[0];
ptr = (int)(float)(v12[0] * 32767.0);
fwrite(&ptr, 2uLL, 1uLL, stdout);
result = fflush(stdout);
--v6;
}
while ( v6 );
}
return result;
}

original_code:
void make_noise(osc_t * osc, int osc_count, scalar_t duration, scalar_t sample_freq, scalar_t decay, filter_moog_t *f)
{
 int i, j;
 scalar_t sample;
 int16_t sample_int;
 int duration_sec = (int)(sample_freq * duration);
 for (i=0; i < duration_sec; i++) {
  sample = 0;
  for (j=0; j<osc_count; j++) {
   sample += osc_fetch_sample(&osc[j], sample_freq);
  }
  sample /= (scalar_t)osc_count;
  if (f != ((void *)0))
   filter_moog_process(f, &sample);
  sample *= (duration_sec - i) * decay;
  sample_int = (int16_t)(sample * 32767);
  fwrite(&sample_int, sizeof(int16_t), 1, stdout);
  fflush(stdout);
 }
}

canonical_original_code:
void make_noise(struct osc_t *osc, int osc_count, float duration, float sample_freq, float decay, struct filter_moog_t *f)
{
 int i; int j;
 float sample;
 short sample_int;
 int duration_sec = (int)(sample_freq * duration);
 for (i=0; i < duration_sec; i++) {
  sample = 0;
  for (j=0; j<osc_count; j++) {
   sample += osc_fetch_sample(&osc[j], sample_freq);
  }
  sample /= (float)osc_count;
  if (f != ((void *)0))
   filter_moog_process(f, &sample);
  sample *= (duration_sec - i) * decay;
  sample_int = (short)(sample * 32767);
  fwrite(&sample_int, sizeof(short), 1, stdout);
  fflush(stdout);
 }
}

variable_types: duration float

variable_types: decay float

variable_types: i int

variable_types: j int

user_defined_types: 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 }


decompiled_code:
float __fastcall note2freq(int a1, int a2)
{
float v2; // xmm0_4
float result; // xmm0_4

v2 = pow(1.059463143348694, (double)a1) * 440.0;
if ( a2 > 3 )
result = v2 * (float)(1 << (a2 - 4));
else
result = v2 / (float)(1 << (4 - a2));
return result;
}

canonical_decompiled_code:
float __fastcall func13(int a1, int a2)
{
float v2; // xmm0_4
float result; // xmm0_4

v2 = pow(1.059463143348694, (double)a1) * 440.0;
if ( a2 > 3 )
result = v2 * (float)(1 << (a2 - 4));
else
result = v2 / (float)(1 << (4 - a2));
return result;
}

original_code:
scalar_t note2freq(note_t note, int octave)
{
 const scalar_t sqr2 = 1.0594630943593;
 scalar_t freq = 440 * pow(sqr2, note);
 if (octave < 4)
  freq /= (scalar_t)(1 << (4 - octave));
 else
  freq *= (scalar_t)(1 << (octave - 4));
 return freq;
}

canonical_original_code:
float note2freq(enum note_t note, int octave)
{
 float sqr2 = 1.0594630943593;
 float freq = 440 * pow(sqr2, note);
 if (octave < 4)
  freq /= (scalar_t)(1 << (4 - octave));
 else
  freq *= (scalar_t)(1 << (octave - 4));
 return freq;
}

variable_types: octave int

variable_types: freq float