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

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

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

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

variable_types:
i
unsigned short


repo: vlohacks/misc

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

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

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

variable_types:
i
unsigned int

return_type: unsigned int


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

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

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

variable_types: r int

variable_types: i int

variable_types:
signature
unsigned int

variable_types:
tmp
char [5]

return_type: int

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


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

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

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

variable_types:
word
unsigned short

variable_types:
byte
unsigned char

variable_types: sbyte char

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


decompiled_code:
void __fastcall loader_mod_read_sample_data(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
__int16 v5; // ax
_WORD *v6; // rdx
char v7[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = *(unsigned int *)(a1 + 32);
if ( (_DWORD)v3 )
{
v4 = 0LL;
*(_QWORD *)(a1 + 72) = malloc(2 * v3);
do
{
(*(void (__fastcall **)(char *, __int64, __int64, __int64))(a2 + 8))(v7, 1LL, 1LL, a2);
++v4;
v5 = sample_from_s8(v7[0]);
*v6 = v5;
}
while ( *(_DWORD *)(a1 + 32) > (unsigned int)v4 );
}
else
{
*(_QWORD *)(a1 + 72) = 0LL;
}
}

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

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

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

variable_types: s char

return_type: void

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


decompiled_code:
__int64 __fastcall loader_mod_lookup_period_index(__int16 a1)
{
__int64 result; // rax
__int16 i; // dx

result = 0LL;
for ( i = 1712; ; i = defs_mod_periods[result] )
{
if ( a1 == i )
return (unsigned int)result;
if ( ++result == 60 )
break;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int16 a1)
{
__int64 result; // rax
__int16 i; // dx

result = 0LL;
for ( i = 1712; ; i = defs_mod_periods[result] )
{
if ( a1 == i )
return (unsigned int)result;
if ( ++result == 60 )
break;
}
return 0xFFFFFFFFLL;
}

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

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

variable_types:
period
unsigned short


decompiled_code:
__int64 __fastcall loader_mod_read_pattern_data(__int64 a1, __int64 a2)
{
int v3; // er8
__int64 result; // rax
unsigned int v5; // eax
unsigned int v6; // er12
__int16 v7; // si
int v8; // eax
__int16 v9; // cx
__int64 v10; // rax
unsigned int v11[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
int v3; // er8
__int64 result; // rax
unsigned int v5; // eax
unsigned int v6; // er12
__int16 v7; // si
int v8; // eax
__int16 v9; // cx
__int64 v10; // rax
unsigned int v11[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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

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

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

variable_types:
dw
unsigned int

variable_types:
tmp
unsigned short


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

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

variable_types: j int

variable_types: k int

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

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_pattern_t { unsigned short num_rows; struct module_pattern_row_t *rows; }

user_defined_types: struct module_pattern_row_t { struct module_pattern_data_t *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_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; }


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

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

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

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

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

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


decompiled_code:
_BOOL8 __fastcall output_raw_start(__int64 a1)
{
FILE *v1; // rax
_BOOL4 v2; // er8

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

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
FILE *v1; // rax
_BOOL4 v2; // er8

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

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

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

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

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


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

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

original_code:
int output_raw_cleanup() {
    return 0;
}

canonical_original_code:
int output_raw_cleanup() {
    return 0;
}


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

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

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

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

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

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

variable_types:
dest
char *

variable_types:
notes
char *[]

variable_types: i int


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

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

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

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

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

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

variable_types:
target
char *

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


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

*s = 0;
if ( a5 != 2 )
{
if ( a5 > 2 )
{
if ( a5 != 3 )
return;
goto LABEL_4;
}
if ( a5 )
{
LABEL_4:
v6 = *(_BYTE *)(a4 + a2);
switch ( a2 )
{
case 0u:
return;
case 1u:
goto LABEL_14;
case 3u:
goto LABEL_15;
case 4u:
v9 = v6 & 0xF0;
v10 = *(_BYTE *)(a4 + a2) & 0xF;
if ( v10 != 15 )
{
if ( v9 == -16 )
{
strcpy(s + 16, "wn");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC16);
if ( v10 )
return;
}
else if ( v10 )
{
goto LABEL_34;
}
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC17);
return;
}
v16 = _mm_load_si128((const __m128i *)&LC15);
s[16] = 0;
*(__m128i *)s = v16;
LABEL_34:
if ( !v9 )
{
v11 = _mm_load_si128((const __m128i *)&LC18);
*((_WORD *)s + 8) = 110;
*(__m128i *)s = v11;
}
return;
case 5u:
v8 = v6 & 0xF0;
if ( v8 == -16 )
{
strcpy(s + 16, "down");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC19);
}
else
{
if ( v8 != -32 )
goto LABEL_17;
strcpy(s + 16, "ento down");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC20);
}
return;
case 6u:
v12 = v6 & 0xF0;
if ( v12 == -16 )
{
strcpy(s + 16, "up");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC19);
}
else
{
if ( v12 != -32 )
goto LABEL_18;
v13 = _mm_load_si128((const __m128i *)&LC20);
*((_QWORD *)s + 2) = 0x7075206F746E65LL;
*(__m128i *)s = v13;
}
return;
case 7u:
goto LABEL_16;
case 8u:
goto LABEL_12;
case 0xAu:
goto LABEL_23;
case 0xBu:
strcpy(s + 16, " slide");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC21);
return;
case 0xCu:
strcpy(s + 16, "+ vol slide");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC22);
return;
case 0xFu:
goto LABEL_13;
case 0x11u:
strcpy(s + 16, "me slide");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC23);
return;
case 0x12u:
goto LABEL_11;
case 0x13u:
switch ( a3 >> 4 )
{
case 3:
goto LABEL_48;
case 4:
goto LABEL_47;
case 8:
goto LABEL_10;
case 10:
strcpy(s, "stereo control");
break;
case 12:
goto LABEL_46;
case 13:
goto LABEL_45;
default:
v7 = 19;
goto LABEL_9;
}
return;
case 0x14u:
strcpy(s, "set tempo");
return;
case 0x18u:
goto LABEL_10;
default:
v7 = a2;
LABEL_9:
ui_map_effect_num(v17, a5, v7);
sprintf(s, "UNIMPLEMENTED: %s%2x", v17, a3);
return;
}
}
}
switch ( a2 )
{
case 0u:
if ( a3 )
LABEL_23:
strcpy(s, "arpeggio");
break;
case 1u:
LABEL_18:
strcpy(s, "portamento up");
break;
case 2u:
LABEL_17:
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC6);
break;
case 3u:
LABEL_16:
strcpy(s + 16, "te");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC7);
break;
case 4u:
LABEL_12:
*(_QWORD *)s = 0x6F746172626976LL;
break;
case 5u:
strcpy(s + 16, "vol. slide");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC8);
break;
case 6u:
strcpy(s + 16, "lide");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC9);
break;
case 7u:
LABEL_11:
*(_QWORD *)s = 0x6F6C6F6D657274LL;
break;
case 8u:
LABEL_10:
*(_QWORD *)s = 0x676E696E6E6170LL;
break;
case 9u:
LABEL_13:
strcpy(s, "sample offset");
break;
case 0xAu:
strcpy(s, "volume slide");
break;
case 0xBu:
strcpy(s, "position jump");
break;
case 0xCu:
strcpy(s, "set volume");
break;
case 0xDu:
LABEL_15:
strcpy(s, "pattern break");
break;
case 0xEu:
if ( a3 > 0xEFu )
{
LABEL_57:
sprintf(s, "UNIMPLEMENTED: %1x%2x", 14LL, a3);
}
else
{
switch ( a3 >> 4 )
{
case 0:
case 3:
case 5:
goto LABEL_57;
case 1:
strcpy(s, "fine porta up");
break;
case 2:
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC10);
break;
case 4:
LABEL_48:
strcpy(s + 16, "form");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC11);
break;
case 6:
strcpy(s, "pattern loop");
break;
case 7:
LABEL_47:
strcpy(s + 16, "form");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC12);
break;
case 8:
goto LABEL_10;
case 9:
v14 = _mm_load_si128((const __m128i *)&LC13);
s[16] = 0;
*(__m128i *)s = v14;
break;
case 10:
strcpy(s, "fine volume up");
break;
case 11:
v15 = _mm_load_si128((const __m128i *)&LC14);
s[16] = 0;
*(__m128i *)s = v15;
break;
case 12:
LABEL_46:
strcpy(s, "note cut");
break;
case 13:
LABEL_45:
strcpy(s, "note delay");
break;
case 14:
strcpy(s, "pattern delay");
break;
}
}
break;
case 0xFu:
LABEL_14:
strcpy(s, "set speed");
break;
default:
return;
}
}

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

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

variable_types:
buf
char *

variable_types:
effect
char [2]

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 }


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

if ( a1 == 1 )
{
v4 = 27392;
v5 = &defs_s3m_periods;
v6 = 108LL;
}
else
{
v2 = -1;
if ( (a1 & 0xFFFFFFFD) != 0 )
return v2;
v4 = 1712;
v5 = &defs_mod_periods;
v6 = 60LL;
}
for ( i = 0LL; ; v4 = v5[i] )
{
v2 = i;
if ( a2 == v4 )
break;
if ( ++i == v6 )
return 0xFFFFFFFFLL;
}
return v2;
}

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

if ( a1 == 1 )
{
v4 = 27392;
v5 = &defs_s3m_periods;
v6 = 108LL;
}
else
{
v2 = -1;
if ( (a1 & 0xFFFFFFFD) != 0 )
return v2;
v4 = 1712;
v5 = &defs_mod_periods;
v6 = 60LL;
}
for ( i = 0LL; ; v4 = v5[i] )
{
v2 = i;
if ( a2 == v4 )
break;
if ( ++i == v6 )
return 0xFFFFFFFFLL;
}
return v2;
}

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

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


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

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

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

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

variable_types: s short

return_type: char


decompiled_code:
void *__fastcall module_dump_c(char *a1)
{
__int64 v1; // r14
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // r13
char v5; // al
unsigned int v6; // edx
__int64 v7; // r12
__int64 v8; // r14
__int64 v9; // rbp
__int64 v10; // r12
unsigned __int16 *v11; // rax
unsigned int v12; // er8
__int64 v13; // rax
__int64 v14; // r13
__int64 v15; // rbp
unsigned __int16 *v16; // rax
unsigned int v17; // eax
__int64 v18; // rbp
char *v19; // rbp
char *v20; // rbp
char *v21; // rbp
char *v22; // rbp
void *result; // rax
_QWORD *v24; // rax
int v25; // er13
unsigned __int8 *v26; // rax
unsigned int v27; // [rsp+0h] [rbp-68h]
__int64 v28; // [rsp+0h] [rbp-68h]
__int64 v29[2]; // [rsp+10h] [rbp-58h] BYREF
int v30; // [rsp+20h] [rbp-48h]

v1 = 0LL;
v30 = 0;
v29[1] = 0LL;
v29[0] = 0LL;
puts("#ifndef _CONSTMOD_H\n#define _CONSTMOD_H\n\n#include \"module.h\"");
if ( *((_WORD *)a1 + 55) )
{
do
{
v2 = 0LL;
printf("const int8_t sample_data_%02i[] = {", (unsigned int)v1);
v3 = *((_QWORD *)a1 + 47);
v4 = 80 * v1;
if ( *(_DWORD *)(v3 + 80 * v1 + 32) )
{
do
{
while ( 1 )
{
if ( (v2 & 0xF) == 0 )
{
putchar(10);
v3 = *((_QWORD *)a1 + 47);
}
v5 = sample_to_s8(*(_WORD *)(*(_QWORD *)(v3 + v4 + 72) + 2 * v2));
printf("%6i", (unsigned int)v5);
v3 = *((_QWORD *)a1 + 47);
v6 = *(_DWORD *)(v3 + v4 + 32);
if ( v6 > (int)v2 + 1 )
break;
if ( v6 <= (unsigned int)++v2 )
goto LABEL_9;
}
++v2;
printf(", ");
v3 = *((_QWORD *)a1 + 47);
}
while ( *(_DWORD *)(v3 + v4 + 32) > (unsigned int)v2 );
}
LABEL_9:
++v1;
puts("};\n");
}
while ( *((unsigned __int16 *)a1 + 55) > (int)v1 );
}
v7 = 0LL;
printf("const module_sample_t samples[] = { ");
if ( *((_WORD *)a1 + 55) )
{
do
{
puts("\t{ ");
printf("\t\t.header.length = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 32));
printf("\t\t.header.finetune = %i,\n", (unsigned int)*(char *)(*((_QWORD *)a1 + 47) + 80 * v7 + 36));
printf("\t\t.header.c2spd = %u,\n", *(unsigned __int16 *)(*((_QWORD *)a1 + 47) + 80 * v7 + 38));
printf("\t\t.header.volume = %u,\n", *(unsigned __int8 *)(*((_QWORD *)a1 + 47) + 80 * v7 + 40));
printf("\t\t.header.loop_enabled = %u,\n", *(unsigned __int8 *)(*((_QWORD *)a1 + 47) + 80 * v7 + 41));
printf("\t\t.header.loop_start = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 44));
printf("\t\t.header.loop_length = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 48));
printf("\t\t.header.loop_end = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 52));
printf("\t\t.data = sample_data_%02i\n", (unsigned int)v7++);
puts("\t},");
}
while ( *((unsigned __int16 *)a1 + 55) > (int)v7 );
}
v8 = 0LL;
puts("};");
if ( *((_WORD *)a1 + 57) )
{
do
{
v9 = 0LL;
v10 = 16 * v8;
v11 = (unsigned __int16 *)(16 * v8 + *((_QWORD *)a1 + 49));
if ( *v11 )
{
do
{
v12 = MurmurHash2A(
*(_QWORD *)(*((_QWORD *)v11 + 1) + 8 * v9),
12 * (unsigned int)*((unsigned __int16 *)a1 + 54),
3735928559LL);
v13 = v29[0];
v14 = v12;
if ( v29[0] )
{
while ( v12 != (unsigned __int64)*(unsigned int *)(v13 + 16) )
{
v13 = *(_QWORD *)v13;
if ( !v13 )
goto LABEL_40;
}
}
else
{
LABEL_40:
v27 = v12;
v24 = malloc(0x18uLL);
v24[2] = v14;
v25 = 0;
v24[1] = 0LL;
*v24 = 0LL;
dllist_push(v29, v24);
printf("const module_pattern_data_t pattern_data_%08x[] = {", v27);
v28 = 0LL;
if ( *((_WORD *)a1 + 54) )
{
do
{
++v25;
v26 = (unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 49) + v10 + 8) + 8 * v9) + v28);
printf(
"{.sample_num=%3u, .period_index=%6i, .volume=%4i, .effect_num=%3u, .effect_value=%3u }",
*v26,
*((unsigned int *)v26 + 1),
(unsigned int)(char)v26[8],
v26[9],
v26[10]);
if ( v25 >= *((unsigned __int16 *)a1 + 54) )
break;
printf(", ");
v28 += 12LL;
}
while ( v25 < *((unsigned __int16 *)a1 + 54) );
}
puts("};");
}
++v9;
v11 = (unsigned __int16 *)(v10 + *((_QWORD *)a1 + 49));
}
while ( *v11 > (int)v9 );
}
v15 = 0LL;
printf("const module_pattern_row_t pattern_rows_%02i[] = {\n", (unsigned int)v8);
v16 = (unsigned __int16 *)(v10 + *((_QWORD *)a1 + 49));
if ( *v16 )
{
do
{
v17 = MurmurHash2A(
*(_QWORD *)(*((_QWORD *)v16 + 1) + 8 * v15),
12 * (unsigned int)*((unsigned __int16 *)a1 + 54),
3735928559LL);
printf("{ .data = pattern_data_%08x }", v17);
if ( *(unsigned __int16 *)(*((_QWORD *)a1 + 49) + 16 * v8) <= (int)v15 + 1 )
break;
++v15;
printf(", ");
v16 = (unsigned __int16 *)(v10 + *((_QWORD *)a1 + 49));
}
while ( *v16 > (int)v15 );
}
++v8;
puts("\n};\n");
}
while ( *((unsigned __int16 *)a1 + 57) > (int)v8 );
}
v18 = 0LL;
puts("const module_pattern_t patterns[] = {");
if ( *((_WORD *)a1 + 57) )
{
do
{
printf(
"{ .num_rows = %03u, .rows = pattern_rows_%02i }",
*(unsigned __int16 *)(*((_QWORD *)a1 + 49) + 16 * v18),
(unsigned int)v18);
if ( *((unsigned __int16 *)a1 + 57) <= (int)v18 + 1 )
break;
++v18;
printf(", ");
}
while ( *((unsigned __int16 *)a1 + 57) > (int)v18 );
}
v19 = a1 + 1;
puts("};");
puts("const module_t static_module = {");
printf("\t.song_title = { ");
printf(" %3i", (unsigned int)*a1);
do
{
++v19;
printf(", ");
printf(" %3i", (unsigned int)*(v19 - 1));
}
while ( a1 + 21 != v19 );
v20 = a1 + 119;
puts("},");
printf("\t.module_type = %i,\n", *((unsigned int *)a1 + 26));
printf("\t.num_channels = %u,\n", *((unsigned __int16 *)a1 + 54));
printf("\t.num_samples = %u,\n", *((unsigned __int16 *)a1 + 55));
printf("\t.num_instruments = %u,\n", *((unsigned __int16 *)a1 + 56));
printf("\t.num_patterns = %u,\n", *((unsigned __int16 *)a1 + 57));
printf("\t.num_orders = %u,\n", *((unsigned __int16 *)a1 + 58));
printf("\t.orders = { ");
printf(" %3u", (unsigned __int8)a1[118]);
do
{
++v20;
printf(", ");
printf(" %3u", (unsigned __int8)*(v20 - 1));
}
while ( a1 + 374 != v20 );
v21 = a1 + 405;
puts("},");
puts("\t.samples = samples,");
puts("\t.patterns = patterns,");
printf("\t.initial_speed = %u,\n", (unsigned __int8)a1[400]);
printf("\t.initial_bpm = %u,\n", (unsigned __int8)a1[401]);
printf("\t.initial_master_volume = %u,\n", (unsigned __int8)a1[402]);
printf("\t.mix_volume = %u,\n", (unsigned __int8)a1[403]);
printf("\t.initial_panning = { ");
printf(" %3u", (unsigned __int8)a1[404]);
do
{
++v21;
printf(", ");
printf(" %3u", (unsigned __int8)*(v21 - 1));
}
while ( v21 != a1 + 468 );
v22 = a1 + 469;
puts("},");
printf("\t.channel_volume = { ");
printf(" %3u", (unsigned __int8)a1[468]);
do
{
++v22;
printf(", ");
printf(" %3u", (unsigned __int8)*(v22 - 1));
}
while ( a1 + 532 != v22 );
puts("}");
puts("};");
printf("#endif");
while ( 1 )
{
result = (void *)dllist_pop(v29);
if ( !result )
break;
free(result);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(char *a1)
{
__int64 v1; // r14
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // r13
char v5; // al
unsigned int v6; // edx
__int64 v7; // r12
__int64 v8; // r14
__int64 v9; // rbp
__int64 v10; // r12
unsigned __int16 *v11; // rax
unsigned int v12; // er8
__int64 v13; // rax
__int64 v14; // r13
__int64 v15; // rbp
unsigned __int16 *v16; // rax
unsigned int v17; // eax
__int64 v18; // rbp
char *v19; // rbp
char *v20; // rbp
char *v21; // rbp
char *v22; // rbp
void *result; // rax
_QWORD *v24; // rax
int v25; // er13
unsigned __int8 *v26; // rax
unsigned int v27; // [rsp+0h] [rbp-68h]
__int64 v28; // [rsp+0h] [rbp-68h]
__int64 v29[2]; // [rsp+10h] [rbp-58h] BYREF
int v30; // [rsp+20h] [rbp-48h]

v1 = 0LL;
v30 = 0;
v29[1] = 0LL;
v29[0] = 0LL;
puts("#ifndef _CONSTMOD_H\n#define _CONSTMOD_H\n\n#include \"module.h\"");
if ( *((_WORD *)a1 + 55) )
{
do
{
v2 = 0LL;
printf("const int8_t sample_data_%02i[] = {", (unsigned int)v1);
v3 = *((_QWORD *)a1 + 47);
v4 = 80 * v1;
if ( *(_DWORD *)(v3 + 80 * v1 + 32) )
{
do
{
while ( 1 )
{
if ( (v2 & 0xF) == 0 )
{
putchar(10);
v3 = *((_QWORD *)a1 + 47);
}
v5 = func0(*(_WORD *)(*(_QWORD *)(v3 + v4 + 72) + 2 * v2));
printf("%6i", (unsigned int)v5);
v3 = *((_QWORD *)a1 + 47);
v6 = *(_DWORD *)(v3 + v4 + 32);
if ( v6 > (int)v2 + 1 )
break;
if ( v6 <= (unsigned int)++v2 )
goto LABEL_9;
}
++v2;
printf(", ");
v3 = *((_QWORD *)a1 + 47);
}
while ( *(_DWORD *)(v3 + v4 + 32) > (unsigned int)v2 );
}
LABEL_9:
++v1;
puts("};\n");
}
while ( *((unsigned __int16 *)a1 + 55) > (int)v1 );
}
v7 = 0LL;
printf("const module_sample_t samples[] = { ");
if ( *((_WORD *)a1 + 55) )
{
do
{
puts("\t{ ");
printf("\t\t.header.length = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 32));
printf("\t\t.header.finetune = %i,\n", (unsigned int)*(char *)(*((_QWORD *)a1 + 47) + 80 * v7 + 36));
printf("\t\t.header.c2spd = %u,\n", *(unsigned __int16 *)(*((_QWORD *)a1 + 47) + 80 * v7 + 38));
printf("\t\t.header.volume = %u,\n", *(unsigned __int8 *)(*((_QWORD *)a1 + 47) + 80 * v7 + 40));
printf("\t\t.header.loop_enabled = %u,\n", *(unsigned __int8 *)(*((_QWORD *)a1 + 47) + 80 * v7 + 41));
printf("\t\t.header.loop_start = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 44));
printf("\t\t.header.loop_length = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 48));
printf("\t\t.header.loop_end = %u,\n", *(unsigned int *)(*((_QWORD *)a1 + 47) + 80 * v7 + 52));
printf("\t\t.data = sample_data_%02i\n", (unsigned int)v7++);
puts("\t},");
}
while ( *((unsigned __int16 *)a1 + 55) > (int)v7 );
}
v8 = 0LL;
puts("};");
if ( *((_WORD *)a1 + 57) )
{
do
{
v9 = 0LL;
v10 = 16 * v8;
v11 = (unsigned __int16 *)(16 * v8 + *((_QWORD *)a1 + 49));
if ( *v11 )
{
do
{
v12 = MurmurHash2A(
*(_QWORD *)(*((_QWORD *)v11 + 1) + 8 * v9),
12 * (unsigned int)*((unsigned __int16 *)a1 + 54),
3735928559LL);
v13 = v29[0];
v14 = v12;
if ( v29[0] )
{
while ( v12 != (unsigned __int64)*(unsigned int *)(v13 + 16) )
{
v13 = *(_QWORD *)v13;
if ( !v13 )
goto LABEL_40;
}
}
else
{
LABEL_40:
v27 = v12;
v24 = malloc(0x18uLL);
v24[2] = v14;
v25 = 0;
v24[1] = 0LL;
*v24 = 0LL;
dllist_push(v29, v24);
printf("const module_pattern_data_t pattern_data_%08x[] = {", v27);
v28 = 0LL;
if ( *((_WORD *)a1 + 54) )
{
do
{
++v25;
v26 = (unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 49) + v10 + 8) + 8 * v9) + v28);
printf(
"{.sample_num=%3u, .period_index=%6i, .volume=%4i, .effect_num=%3u, .effect_value=%3u }",
*v26,
*((unsigned int *)v26 + 1),
(unsigned int)(char)v26[8],
v26[9],
v26[10]);
if ( v25 >= *((unsigned __int16 *)a1 + 54) )
break;
printf(", ");
v28 += 12LL;
}
while ( v25 < *((unsigned __int16 *)a1 + 54) );
}
puts("};");
}
++v9;
v11 = (unsigned __int16 *)(v10 + *((_QWORD *)a1 + 49));
}
while ( *v11 > (int)v9 );
}
v15 = 0LL;
printf("const module_pattern_row_t pattern_rows_%02i[] = {\n", (unsigned int)v8);
v16 = (unsigned __int16 *)(v10 + *((_QWORD *)a1 + 49));
if ( *v16 )
{
do
{
v17 = MurmurHash2A(
*(_QWORD *)(*((_QWORD *)v16 + 1) + 8 * v15),
12 * (unsigned int)*((unsigned __int16 *)a1 + 54),
3735928559LL);
printf("{ .data = pattern_data_%08x }", v17);
if ( *(unsigned __int16 *)(*((_QWORD *)a1 + 49) + 16 * v8) <= (int)v15 + 1 )
break;
++v15;
printf(", ");
v16 = (unsigned __int16 *)(v10 + *((_QWORD *)a1 + 49));
}
while ( *v16 > (int)v15 );
}
++v8;
puts("\n};\n");
}
while ( *((unsigned __int16 *)a1 + 57) > (int)v8 );
}
v18 = 0LL;
puts("const module_pattern_t patterns[] = {");
if ( *((_WORD *)a1 + 57) )
{
do
{
printf(
"{ .num_rows = %03u, .rows = pattern_rows_%02i }",
*(unsigned __int16 *)(*((_QWORD *)a1 + 49) + 16 * v18),
(unsigned int)v18);
if ( *((unsigned __int16 *)a1 + 57) <= (int)v18 + 1 )
break;
++v18;
printf(", ");
}
while ( *((unsigned __int16 *)a1 + 57) > (int)v18 );
}
v19 = a1 + 1;
puts("};");
puts("const module_t static_module = {");
printf("\t.song_title = { ");
printf(" %3i", (unsigned int)*a1);
do
{
++v19;
printf(", ");
printf(" %3i", (unsigned int)*(v19 - 1));
}
while ( a1 + 21 != v19 );
v20 = a1 + 119;
puts("},");
printf("\t.module_type = %i,\n", *((unsigned int *)a1 + 26));
printf("\t.num_channels = %u,\n", *((unsigned __int16 *)a1 + 54));
printf("\t.num_samples = %u,\n", *((unsigned __int16 *)a1 + 55));
printf("\t.num_instruments = %u,\n", *((unsigned __int16 *)a1 + 56));
printf("\t.num_patterns = %u,\n", *((unsigned __int16 *)a1 + 57));
printf("\t.num_orders = %u,\n", *((unsigned __int16 *)a1 + 58));
printf("\t.orders = { ");
printf(" %3u", (unsigned __int8)a1[118]);
do
{
++v20;
printf(", ");
printf(" %3u", (unsigned __int8)*(v20 - 1));
}
while ( a1 + 374 != v20 );
v21 = a1 + 405;
puts("},");
puts("\t.samples = samples,");
puts("\t.patterns = patterns,");
printf("\t.initial_speed = %u,\n", (unsigned __int8)a1[400]);
printf("\t.initial_bpm = %u,\n", (unsigned __int8)a1[401]);
printf("\t.initial_master_volume = %u,\n", (unsigned __int8)a1[402]);
printf("\t.mix_volume = %u,\n", (unsigned __int8)a1[403]);
printf("\t.initial_panning = { ");
printf(" %3u", (unsigned __int8)a1[404]);
do
{
++v21;
printf(", ");
printf(" %3u", (unsigned __int8)*(v21 - 1));
}
while ( v21 != a1 + 468 );
v22 = a1 + 469;
puts("},");
printf("\t.channel_volume = { ");
printf(" %3u", (unsigned __int8)a1[468]);
do
{
++v22;
printf(", ");
printf(" %3u", (unsigned __int8)*(v22 - 1));
}
while ( a1 + 532 != v22 );
puts("}");
puts("};");
printf("#endif");
while ( 1 )
{
result = (void *)dllist_pop(v29);
if ( !result )
break;
free(result);
}
return result;
}

original_code:
void module_dump_c(module_t * module)
{
    int i, j, k;
    uint32_t hash;
    dllist_t list;
    dllist_element_t * tmp_elem;
    list.first=list.last=list.count = 0;
    printf("#ifndef _CONSTMOD_H\n#define _CONSTMOD_H\n\n#include \"module.h\"\n");
    for (i = 0; i < module->num_samples; i++) {
        printf ("const int8_t sample_data_%02i[] = {", i);
        for (j = 0; j < module->samples[i].header.length; j++) {
            if (!(j % 16))
                printf("\n");
            printf("%6i", sample_to_s8(module->samples[i].data[j]));
            if (j+1 < module->samples[i].header.length)
                printf(", ");
        }
        printf("};\n\n");
    }
    printf ("const module_sample_t samples[] = { ");
    for (i = 0; i < module->num_samples; i++) {
        printf("\t{ \n");
        printf("\t\t.header.length = %u,\n", module->samples[i].header.length);
        printf("\t\t.header.finetune = %i,\n", module->samples[i].header.finetune);
        printf("\t\t.header.c2spd = %u,\n", module->samples[i].header.c2spd);
        printf("\t\t.header.volume = %u,\n", module->samples[i].header.volume);
        printf("\t\t.header.loop_enabled = %u,\n", module->samples[i].header.loop_enabled);
        printf("\t\t.header.loop_start = %u,\n", module->samples[i].header.loop_start);
        printf("\t\t.header.loop_length = %u,\n", module->samples[i].header.loop_length);
        printf("\t\t.header.loop_end = %u,\n", module->samples[i].header.loop_end);
        printf("\t\t.data = sample_data_%02i\n", i);
        printf("\t},\n");
    }
    printf("};\n");
    for (i = 0; i < module->num_patterns; i++) {
        for (j = 0; j < module->patterns[i].num_rows; j++) {
            hash = MurmurHash2A(module->patterns[i].rows[j].data, (sizeof(module_pattern_data_t) * module->num_channels), 0xdeadbeef);
            for (tmp_elem = list.first; tmp_elem; tmp_elem = tmp_elem->next) {
                if (!tmp_elem)
                    break;
                if ((uint32_t)(tmp_elem->data) == (void *)hash)
                    break;
            }
            if (!tmp_elem) {
                tmp_elem = malloc(sizeof(dllist_element_t));
                tmp_elem->next = tmp_elem->prev = 0;
                tmp_elem->data = hash;
                dllist_push(&list, tmp_elem);
                printf("const module_pattern_data_t pattern_data_%08x[] = {", hash);
                for (k = 0; k < module->num_channels; k++) {
                    module_pattern_data_t * data = &(module->patterns[i].rows[j].data[k]);
                    printf("{.sample_num=%3u, .period_index=%6i, .volume=%4i, .effect_num=%3u, .effect_value=%3u }", data->sample_num, data->period_index, data->volume, data->effect_num, data->effect_value);
                    if (k+1 < module->num_channels)
                        printf(", ");
                }
                printf("};\n");
            }
        }
        printf("const module_pattern_row_t pattern_rows_%02i[] = {\n", i);
        for (j = 0; j < module->patterns[i].num_rows; j++) {
            hash = MurmurHash2A(module->patterns[i].rows[j].data, (sizeof(module_pattern_data_t) * module->num_channels), 0xdeadbeef);
            printf("{ .data = pattern_data_%08x }", hash);
            if (j+1 < module->patterns[i].num_rows)
                printf(", ");
        }
        printf("\n};\n\n");
    }
    printf("const module_pattern_t patterns[] = {\n");
    for (i = 0; i < module->num_patterns; i++) {
        printf("{ .num_rows = %03u, .rows = pattern_rows_%02i }", module->patterns[i].num_rows, i);
        if (i+1 < module->num_patterns)
            printf(", ");
    }
    printf("};\n");
    printf("const module_t static_module = {\n");
    printf("\t.song_title = { ");
    for (i = 0; i < 21; i++) {
        printf(" %3i", module->song_title[i]);
        if (i < 20)
            printf(", ");
    }
    printf("},\n");
    printf("\t.module_type = %i,\n", module->module_type);
    printf("\t.num_channels = %u,\n", module->num_channels);
    printf("\t.num_samples = %u,\n", module->num_samples);
    printf("\t.num_instruments = %u,\n", module->num_instruments);
    printf("\t.num_patterns = %u,\n", module->num_patterns);
    printf("\t.num_orders = %u,\n", module->num_orders);
    printf("\t.orders = { ");
    for (i = 0; i < 256; i++) {
        printf(" %3u", module->orders[i]);
        if (i < 255)
            printf(", ");
    }
    printf("},\n");
    printf("\t.samples = samples,\n");
    printf("\t.patterns = patterns,\n");
    printf("\t.initial_speed = %u,\n", module->initial_speed);
    printf("\t.initial_bpm = %u,\n", module->initial_bpm);
    printf("\t.initial_master_volume = %u,\n", module->initial_master_volume);
    printf("\t.mix_volume = %u,\n", module->mix_volume);
    printf("\t.initial_panning = { ");
    for (i = 0; i < 64; i++) {
        printf(" %3u", module->initial_panning[i]);
        if (i < 63)
            printf(", ");
    }
    printf("},\n");
    printf("\t.channel_volume = { ");
    for (i = 0; i < 64; i++) {
        printf(" %3u", module->channel_volume[i]);
        if (i < 63)
            printf(", ");
    }
    printf("}\n");
    printf("};\n");
    printf("#endif");
    while ((tmp_elem = dllist_pop(&list)) != 0)
        free(tmp_elem);
}

canonical_original_code:
void module_dump_c(struct module_t *module)
{
    int i; int j; int k;
    unsigned int hash;
    struct dllist_t list;
    struct dllist_element_s *tmp_elem;
    list.first=list.last=list.count = 0;
    printf("#ifndef _CONSTMOD_H\n#define _CONSTMOD_H\n\n#include \"module.h\"\n");
    for (i = 0; i < module->num_samples; i++) {
        printf ("const int8_t sample_data_%02i[] = {", i);
        for (j = 0; j < module->samples[i].header.length; j++) {
            if (!(j % 16))
                printf("\n");
            printf("%6i", sample_to_s8(module->samples[i].data[j]));
            if (j+1 < module->samples[i].header.length)
                printf(", ");
        }
        printf("};\n\n");
    }
    printf ("const module_sample_t samples[] = { ");
    for (i = 0; i < module->num_samples; i++) {
        printf("\t{ \n");
        printf("\t\t.header.length = %u,\n", module->samples[i].header.length);
        printf("\t\t.header.finetune = %i,\n", module->samples[i].header.finetune);
        printf("\t\t.header.c2spd = %u,\n", module->samples[i].header.c2spd);
        printf("\t\t.header.volume = %u,\n", module->samples[i].header.volume);
        printf("\t\t.header.loop_enabled = %u,\n", module->samples[i].header.loop_enabled);
        printf("\t\t.header.loop_start = %u,\n", module->samples[i].header.loop_start);
        printf("\t\t.header.loop_length = %u,\n", module->samples[i].header.loop_length);
        printf("\t\t.header.loop_end = %u,\n", module->samples[i].header.loop_end);
        printf("\t\t.data = sample_data_%02i\n", i);
        printf("\t},\n");
    }
    printf("};\n");
    for (i = 0; i < module->num_patterns; i++) {
        for (j = 0; j < module->patterns[i].num_rows; j++) {
            hash = MurmurHash2A(module->patterns[i].rows[j].data, (sizeof(module_pattern_data_t) * module->num_channels), 0xdeadbeef);
            for (tmp_elem = list.first; tmp_elem; tmp_elem = tmp_elem->next) {
                if (!tmp_elem)
                    break;
                if ((unsigned int)(tmp_elem->data) == (void *)hash)
                    break;
            }
            if (!tmp_elem) {
                tmp_elem = malloc(sizeof(dllist_element_t));
                tmp_elem->next = tmp_elem->prev = 0;
                tmp_elem->data = hash;
                dllist_push(&list, tmp_elem);
                printf("const module_pattern_data_t pattern_data_%08x[] = {", hash);
                for (k = 0; k < module->num_channels; k++) {
                    struct module_pattern_data_t *data = &(module->patterns[i].rows[j].data[k]);
                    printf("{.sample_num=%3u, .period_index=%6i, .volume=%4i, .effect_num=%3u, .effect_value=%3u }", data->sample_num, data->period_index, data->volume, data->effect_num, data->effect_value);
                    if (k+1 < module->num_channels)
                        printf(", ");
                }
                printf("};\n");
            }
        }
        printf("const module_pattern_row_t pattern_rows_%02i[] = {\n", i);
        for (j = 0; j < module->patterns[i].num_rows; j++) {
            hash = MurmurHash2A(module->patterns[i].rows[j].data, (sizeof(module_pattern_data_t) * module->num_channels), 0xdeadbeef);
            printf("{ .data = pattern_data_%08x }", hash);
            if (j+1 < module->patterns[i].num_rows)
                printf(", ");
        }
        printf("\n};\n\n");
    }
    printf("const module_pattern_t patterns[] = {\n");
    for (i = 0; i < module->num_patterns; i++) {
        printf("{ .num_rows = %03u, .rows = pattern_rows_%02i }", module->patterns[i].num_rows, i);
        if (i+1 < module->num_patterns)
            printf(", ");
    }
    printf("};\n");
    printf("const module_t static_module = {\n");
    printf("\t.song_title = { ");
    for (i = 0; i < 21; i++) {
        printf(" %3i", module->song_title[i]);
        if (i < 20)
            printf(", ");
    }
    printf("},\n");
    printf("\t.module_type = %i,\n", module->module_type);
    printf("\t.num_channels = %u,\n", module->num_channels);
    printf("\t.num_samples = %u,\n", module->num_samples);
    printf("\t.num_instruments = %u,\n", module->num_instruments);
    printf("\t.num_patterns = %u,\n", module->num_patterns);
    printf("\t.num_orders = %u,\n", module->num_orders);
    printf("\t.orders = { ");
    for (i = 0; i < 256; i++) {
        printf(" %3u", module->orders[i]);
        if (i < 255)
            printf(", ");
    }
    printf("},\n");
    printf("\t.samples = samples,\n");
    printf("\t.patterns = patterns,\n");
    printf("\t.initial_speed = %u,\n", module->initial_speed);
    printf("\t.initial_bpm = %u,\n", module->initial_bpm);
    printf("\t.initial_master_volume = %u,\n", module->initial_master_volume);
    printf("\t.mix_volume = %u,\n", module->mix_volume);
    printf("\t.initial_panning = { ");
    for (i = 0; i < 64; i++) {
        printf(" %3u", module->initial_panning[i]);
        if (i < 63)
            printf(", ");
    }
    printf("},\n");
    printf("\t.channel_volume = { ");
    for (i = 0; i < 64; i++) {
        printf(" %3u", module->channel_volume[i]);
        if (i < 63)
            printf(", ");
    }
    printf("}\n");
    printf("};\n");
    printf("#endif");
    while ((tmp_elem = dllist_pop(&list)) != 0)
        free(tmp_elem);
}

variable_types:
hash
unsigned int

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

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

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: struct module_sample_header_t { char name[29]; unsigned int length; char finetune; unsigned short c2spd; unsigned char volume; unsigned char loop_enabled; unsigned int loop_start; unsigned int loop_length; unsigned int loop_end; unsigned int susloop_start; unsigned int susloop_end; unsigned char global_volume; unsigned char vibrato_speed; unsigned char vibrato_depth; unsigned char vibrato_waveform; unsigned char vibrato_rate; unsigned char pan; }

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


getHighScoreList

repo: FrostTree-Games/PrinceProtect

decompiled_code:
__int64 __fastcall getHighScoreList(_QWORD *a1)
{
__int64 result; // rax

*a1 = scores[0];
a1[1] = scores[1];
result = scores[2];
a1[2] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 result; // rax

*a1 = scores[0];
a1[1] = scores[1];
result = scores[2];
a1[2] = result;
return result;
}

original_code:
void getHighScoreList(HighScore* scoreList)
{
 int i;
 for (i = 0; i < 3; i++)
 {
  scoreList[i] = scores[i];
 }
}

canonical_original_code:
void getHighScoreList(struct HighScore *scoreList)
{
 int i;
 for (i = 0; i < 3; i++)
 {
  scoreList[i] = scores[i];
 }
}

variable_types: struct HighScore { char playerCount; char name[3]; int score; } *


isHighScore

decompiled_code:
_BOOL8 __fastcall isHighScore(int a1)
{
return SHIDWORD(scores[2]) <= a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
return SHIDWORD(scores[2]) <= a1;
}

original_code:
int isHighScore(int score)
{
 if (scores[3 - 1].score > score)
 {
  return 0;
 }
 else
 {
  return 1;
 }
}

variable_types: score int


pushHighScore

decompiled_code:
__int64 __fastcall pushHighScore(__int64 a1)
{
__int64 result; // rax
int v2; // edx

result = isHighScore(SHIDWORD(a1));
if ( (_DWORD)result )
{
if ( v2 > SHIDWORD(scores[0]) )
{
scores[2] = scores[1];
scores[1] = scores[0];
result = 0LL;
}
else if ( v2 > SHIDWORD(scores[1]) )
{
scores[2] = scores[1];
result = 1LL;
}
else
{
if ( v2 <= SHIDWORD(scores[2]) )
return result;
result = 2LL;
}
scores[result] = a1;
}
return result;
}

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

result = func1(SHIDWORD(a1));
if ( (_DWORD)result )
{
if ( v2 > SHIDWORD(scores[0]) )
{
scores[2] = scores[1];
scores[1] = scores[0];
result = 0LL;
}
else if ( v2 > SHIDWORD(scores[1]) )
{
scores[2] = scores[1];
result = 1LL;
}
else
{
if ( v2 <= SHIDWORD(scores[2]) )
return result;
result = 2LL;
}
scores[result] = a1;
}
return result;
}

original_code:
void pushHighScore(HighScore h)
{
 int i,j;
 if (!isHighScore(h.score))
 {
  return;
 }
 for (i = 0; i < 3; i++)
 {
  if (h.score > scores[i].score)
  {
   for (j = 3 - 1; j > i; j--)
   {
    scores[j] = scores[j - 1];
   }
   scores[i] = h;
   break;
  }
 }
}

canonical_original_code:
void pushHighScore(struct HighScore h)
{
 int i; int j;
 if (!isHighScore(h.score))
 {
  return;
 }
 for (i = 0; i < 3; i++)
 {
  if (h.score > scores[i].score)
  {
   for (j = 3 - 1; j > i; j--)
   {
    scores[j] = scores[j - 1];
   }
   scores[i] = h;
   break;
  }
 }
}

variable_types: struct HighScore { char playerCount; char name[3]; int score; }

variable_types: j int


updatePushMessages

decompiled_code:
__int64 updatePushMessages()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)queueRear;
if ( queueRear >= 0 )
{
result = (unsigned int)getTimeSingleton() - LODWORD(messageQueue[0]);
if ( (unsigned int)result > 0x9C4 )
{
result = queueRear;
v1 = queueRear - 1;
if ( queueRear <= 0 )
{
--queueRear;
if ( v1 < 0 )
return result;
}
else
{
memmove(messageQueue, (const void *)(unsigned int)((_DWORD)messageQueue + 36), 36LL * queueRear);
queueRear = v1;
}
result = getTimeSingleton();
LODWORD(messageQueue[0]) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)queueRear;
if ( queueRear >= 0 )
{
result = (unsigned int)getTimeSingleton() - LODWORD(messageQueue[0]);
if ( (unsigned int)result > 0x9C4 )
{
result = queueRear;
v1 = queueRear - 1;
if ( queueRear <= 0 )
{
--queueRear;
if ( v1 < 0 )
return result;
}
else
{
memmove(messageQueue, (const void *)(unsigned int)((_DWORD)messageQueue + 36), 36LL * queueRear);
queueRear = v1;
}
result = getTimeSingleton();
LODWORD(messageQueue[0]) = result;
}
}
return result;
}

original_code:
void updatePushMessages()
{
 int i;
 if (queueRear < 0)
 {
  return;
 }
 if (getTimeSingleton() - messageQueue[0].startTime > 2500)
 {
  for (i = 0; i < queueRear; i++)
  {
   messageQueue[i] = messageQueue[i+1];
  }
  queueRear--;
  if (queueRear > -1)
  {
   messageQueue[0].startTime = getTimeSingleton();
  }
 }
}


pushNewMessage

decompiled_code:
__int64 __fastcall pushNewMessage(char *src)
{
__int64 result; // rax
int v2; // ebx
__int64 v4; // rbx
size_t v5; // rax
__int64 v6; // rdx
char *v7; // rdi
unsigned int v8; // eax
unsigned __int64 v9; // rsi
char *v10; // rdi
char *v11; // rbp
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // edx
__int64 v15; // rcx

if ( !src )
return 2LL;
result = 1LL;
v2 = queueRear;
if ( queueRear <= 3 )
{
++queueRear;
v4 = v2 + 1;
v5 = strlen(src);
v6 = 36 * v4 + 4;
v7 = (char *)messageQueue + 36 * v4 + 4;
if ( v5 <= 0x1F )
{
v8 = v5 + 1;
if ( v8 < 8 )
{
if ( (v8 & 4) != 0 )
{
*(_DWORD *)((char *)messageQueue + v6) = *(_DWORD *)src;
*(_DWORD *)((char *)messageQueue + 36 * v4 + v8) = *(_DWORD *)&src[v8 - 4];
}
else if ( v8 )
{
*((_BYTE *)messageQueue + v6) = *src;
if ( (v8 & 2) != 0 )
*(_WORD *)&v7[v8 - 2] = *(_WORD *)&src[v8 - 2];
}
}
else
{
v9 = (unsigned __int64)(v7 + 8) & 0xFFFFFFFFFFFFFFF8LL;
*(__int64 *)((char *)messageQueue + v6) = *(_QWORD *)src;
*(_QWORD *)&v7[v8 - 8] = *(_QWORD *)&src[v8 - 8];
v10 = &v7[-v9];
v11 = (char *)(src - v10);
v12 = ((_DWORD)v10 + v8) & 0xFFFFFFF8;
if ( v12 >= 8 )
{
v13 = v12 & 0xFFFFFFF8;
v14 = 0;
do
{
v15 = v14;
v14 += 8;
*(_QWORD *)(v9 + v15) = *(_QWORD *)&v11[v15];
}
while ( v14 < v13 );
}
}
}
else
{
strncpy(v7, src, 0x1FuLL);
*((_BYTE *)&messageQueue[4] + 36 * v4 + 3) = 0;
}
*((_DWORD *)messageQueue + 9 * v4) = getTimeSingleton();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
__int64 result; // rax
int v2; // ebx
__int64 v4; // rbx
size_t v5; // rax
__int64 v6; // rdx
char *v7; // rdi
unsigned int v8; // eax
unsigned __int64 v9; // rsi
char *v10; // rdi
char *v11; // rbp
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // edx
__int64 v15; // rcx

if ( !src )
return 2LL;
result = 1LL;
v2 = queueRear;
if ( queueRear <= 3 )
{
++queueRear;
v4 = v2 + 1;
v5 = strlen(src);
v6 = 36 * v4 + 4;
v7 = (char *)messageQueue + 36 * v4 + 4;
if ( v5 <= 0x1F )
{
v8 = v5 + 1;
if ( v8 < 8 )
{
if ( (v8 & 4) != 0 )
{
*(_DWORD *)((char *)messageQueue + v6) = *(_DWORD *)src;
*(_DWORD *)((char *)messageQueue + 36 * v4 + v8) = *(_DWORD *)&src[v8 - 4];
}
else if ( v8 )
{
*((_BYTE *)messageQueue + v6) = *src;
if ( (v8 & 2) != 0 )
*(_WORD *)&v7[v8 - 2] = *(_WORD *)&src[v8 - 2];
}
}
else
{
v9 = (unsigned __int64)(v7 + 8) & 0xFFFFFFFFFFFFFFF8LL;
*(__int64 *)((char *)messageQueue + v6) = *(_QWORD *)src;
*(_QWORD *)&v7[v8 - 8] = *(_QWORD *)&src[v8 - 8];
v10 = &v7[-v9];
v11 = (char *)(src - v10);
v12 = ((_DWORD)v10 + v8) & 0xFFFFFFF8;
if ( v12 >= 8 )
{
v13 = v12 & 0xFFFFFFF8;
v14 = 0;
do
{
v15 = v14;
v14 += 8;
*(_QWORD *)(v9 + v15) = *(_QWORD *)&v11[v15];
}
while ( v14 < v13 );
}
}
}
else
{
strncpy(v7, src, 0x1FuLL);
*((_BYTE *)&messageQueue[4] + 36 * v4 + 3) = 0;
}
*((_DWORD *)messageQueue + 9 * v4) = getTimeSingleton();
result = 0LL;
}
return result;
}

original_code:
int pushNewMessage(char* text)
{
 if (text == ((void *)0))
 {
  return 2;
 }
 if (queueRear > 3)
 {
  return 1;
 }
 queueRear++;
 if (strlen(text) > 31)
 {
  strncpy(messageQueue[queueRear].message, text, 31);
  (messageQueue[queueRear].message)[31] = '\0';
 }
 else
 {
  strcpy(messageQueue[queueRear].message, text);
 }
 messageQueue[queueRear].startTime = getTimeSingleton();
 return 0;
}

canonical_original_code:
int pushNewMessage(char *text)
{
 if (text == ((void *)0))
 {
  return 2;
 }
 if (queueRear > 3)
 {
  return 1;
 }
 queueRear++;
 if (strlen(text) > 31)
 {
  strncpy(messageQueue[queueRear].message, text, 31);
  (messageQueue[queueRear].message)[31] = '\0';
 }
 else
 {
  strcpy(messageQueue[queueRear].message, text);
 }
 messageQueue[queueRear].startTime = getTimeSingleton();
 return 0;
}

variable_types:
text
char *


getCurrentMessage

decompiled_code:
__int64 *getCurrentMessage()
{
__int64 *result; // rax

result = messageQueue;
if ( queueRear < 0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 *func2()
{
__int64 *result; // rax

result = messageQueue;
if ( queueRear < 0 )
result = 0LL;
return result;
}

original_code:
PushMessage* getCurrentMessage()
{
 if (queueRear < 0)
 {
  return ((void *)0);
 }
 else
 {
  return messageQueue;
 }
}

canonical_original_code:
struct PushMessage *getCurrentMessage()
{
 if (queueRear < 0)
 {
  return ((void *)0);
 }
 else
 {
  return messageQueue;
 }
}

return_type: struct PushMessage { unsigned int startTime; char message[32]; } *


initalizeParticleList

decompiled_code:
_BOOL8 initalizeParticleList()
{
if ( particleList )
return 1LL;
particleList = calloc(0x64uLL, 0x18uLL);
return particleList != 0LL;
}

canonical_decompiled_code:
_BOOL8 func0()
{
if ( particleList )
return 1LL;
particleList = calloc(0x64uLL, 0x18uLL);
return particleList != 0LL;
}

original_code:
int initalizeParticleList()
{
 if (particleList != ((void *)0))
 {
  return 1;
 }
 particleList = (Particle*)calloc(100, sizeof(Particle));
 if (particleList == ((void *)0))
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int initalizeParticleList()
{
 if (particleList != ((void *)0))
 {
  return 1;
 }
 particleList = (struct Particle *)calloc(100, sizeof(Particle));
 if (particleList == ((void *)0))
 {
  return 0;
 }
 return 1;
}

user_defined_types: struct Particle { enum ParticleType type; float x; float xVelo; unsigned int startTime; }

user_defined_types: enum ParticleType { NONE=0, ICE=1, MUD=2, BLOOD=3, SWEAT=4, HEALTHSPARK=5, TELESPARK=6, FIRE=7, LIFETEXT=8 }


freeParticleList

decompiled_code:
void freeParticleList()
{
free(particleList);
particleList = 0LL;
}

canonical_decompiled_code:
void func1()
{
free(particleList);
particleList = 0LL;
}

original_code:
void freeParticleList()
{
 free(particleList);
 particleList = ((void *)0);
}