decompiled_code:
__int64 __fastcall parse_option(const char *a1)
{
__int64 result; // rax

if ( !strcmp(a1, "bios") )
{
pc = 0;
result = 1LL;
}
else
{
fprintf(stderr, "Invalid option : %s\n", a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 result; // rax

if ( !strcmp(a1, "bios") )
{
pc = 0;
result = 1LL;
}
else
{
fprintf(stderr, "Invalid option : %s\n", a1);
result = 0LL;
}
return result;
}

original_code:
int parse_option(char *attr, char *val)
{
 if (!strcmp(attr,"bios")) {
  pc = 0;
 } else {
  fprintf(stderr,"Invalid option : %s\n",attr);
  return 0;
 }
 return 1;
}

variable_types:
attr
char *

variable_types:
val
char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char **v3; // rbp
char *v4; // rax
char *v5; // rax
size_t i; // rbx
const unsigned __int16 **v7; // rax
__int64 v8; // r12
FILE *v9; // rax
FILE *v10; // rbx
__int64 v11; // rbp
__int64 v12; // rbp

pc = 1024;
if ( argc > 1 )
{
v3 = (char **)(argv + 1);
while ( 1 )
{
if ( **v3 == 45 )
{
v4 = strtok(*v3, "=");
if ( v4 )
{
strncpy(attr_1, v4 + 1, 0x3FFuLL);
byte_303F = 0;
}
else
{
attr_1[0] = 0;
}
v5 = strtok(0LL, "=");
if ( v5 )
{
strncpy(&val_0, v5, 0x3FFuLL);
byte_2C3F = 0;
}
else
{
val_0 = 0;
}
for ( i = 0LL; strlen(attr_1) > i; ++i )
{
v7 = _ctype_b_loc();
v8 = attr_1[i];
if ( ((*v7)[v8] & 0x100) != 0 )
attr_1[i] = (*_ctype_tolower_loc())[v8];
}
if ( !(unsigned int)parse_option(attr_1) )
exit(1);
}
else
{
strncat(&file_3, *v3, 0x3FFuLL);
byte_343F = 0;
}
if ( ++v3 == (char **)&argv[(unsigned int)(argc - 2) + 2] )
{
if ( !file_3 )
{
fwrite("Error: file name missing\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v9 = fopen(&file_3, "rb");
v10 = v9;
if ( v9 )
{
fseek(v9, 0LL, 2);
v11 = ftell(v10);
if ( v11 > 0x2000 )
{
printf("Invalid image size");
fclose(v10);
exit(0);
}
rewind(v10);
if ( v11 != fread(&rom[(unsigned __int16)pc], 1uLL, v11, v10) )
{
printf("Error loading %s\n", argv[1]);
fclose(v10);
exit(0);
}
fclose(v10);
v12 = (unsigned __int16)pc + v11;
while ( (unsigned __int16)pc < v12 )
pc += disasm(pc);
exit(0);
}
printf("Error loading %s\n", argv[1]);
exit(0);
}
}
}
puts("Usage: dis48 [file] [-bios]");
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char **v3; // rbp
char *v4; // rax
char *v5; // rax
size_t i; // rbx
const unsigned __int16 **v7; // rax
__int64 v8; // r12
FILE *v9; // rax
FILE *v10; // rbx
__int64 v11; // rbp
__int64 v12; // rbp

pc = 1024;
if ( argc > 1 )
{
v3 = (char **)(argv + 1);
while ( 1 )
{
if ( **v3 == 45 )
{
v4 = strtok(*v3, "=");
if ( v4 )
{
strncpy(attr_1, v4 + 1, 0x3FFuLL);
byte_303F = 0;
}
else
{
attr_1[0] = 0;
}
v5 = strtok(0LL, "=");
if ( v5 )
{
strncpy(&val_0, v5, 0x3FFuLL);
byte_2C3F = 0;
}
else
{
val_0 = 0;
}
for ( i = 0LL; strlen(attr_1) > i; ++i )
{
v7 = _ctype_b_loc();
v8 = attr_1[i];
if ( ((*v7)[v8] & 0x100) != 0 )
attr_1[i] = (*_ctype_tolower_loc())[v8];
}
if ( !(unsigned int)func1(attr_1) )
exit(1);
}
else
{
strncat(&file_3, *v3, 0x3FFuLL);
byte_343F = 0;
}
if ( ++v3 == (char **)&argv[(unsigned int)(argc - 2) + 2] )
{
if ( !file_3 )
{
fwrite("Error: file name missing\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v9 = fopen(&file_3, "rb");
v10 = v9;
if ( v9 )
{
fseek(v9, 0LL, 2);
v11 = ftell(v10);
if ( v11 > 0x2000 )
{
printf("Invalid image size");
fclose(v10);
exit(0);
}
rewind(v10);
if ( v11 != fread(&rom[(unsigned __int16)pc], 1uLL, v11, v10) )
{
printf("Error loading %s\n", argv[1]);
fclose(v10);
exit(0);
}
fclose(v10);
v12 = (unsigned __int16)pc + v11;
while ( (unsigned __int16)pc < v12 )
pc += func0(pc);
exit(0);
}
printf("Error loading %s\n", argv[1]);
exit(0);
}
}
}
puts("Usage: dis48 [file] [-bios]");
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
    int i, cnt, cnt2;
    static char file[1024], attr[1024], val[1024], *p, *binver;
    binver = "UNIX binary";
    printf("%s %s\n", "\nO2EM v" "1.18" " " "(Jan/2007)" "  - ", binver);
    printf(
            "Free Odyssey2 / Videopac+ Emulator - http://o2em.sourceforge.net\n");
    printf("Created by Daniel Boris (c)1996/1998\n");
    printf("Developed by:\n");
    printf("     Andre de la Rocha since version 0.80\n");
    printf("     Arlindo M. de Oliveira since version 1.16\n");
    printf("\n");
    app_data.debug = 0;
    app_data.stick[0] = app_data.stick[1] = 1;
    app_data.sticknumber[0] = app_data.sticknumber[1] = 0;
    set_defjoykeys(0, 0);
    set_defjoykeys(1, 1);
    set_defsystemkeys();
    app_data.bank = 0;
    app_data.limit = 1;
    app_data.sound_en = 1;
    app_data.speed = 100;
    app_data.wsize = 2;
    app_data.fullscreen = 0;
    app_data.scanlines = 0;
    app_data.voice = 1;
    app_data.window_title = "O2EM v" "1.18";
    app_data.svolume = 100;
    app_data.vvolume = 100;
    app_data.filter = 0;
    app_data.exrom = 0;
    app_data.three_k = 0;
    app_data.crc = 0;
    app_data.scshot = scshot;
    app_data.statefile = statefile;
    app_data.euro = 0;
    app_data.openb = 0;
    app_data.vpp = 0;
    app_data.bios = 0;
    app_data.scoretype = 0;
    app_data.scoreaddress = 0;
    app_data.default_highscore = 0;
    app_data.breakpoint = 65535;
    app_data.megaxrom = 0;
    strcpy(file, "");
    strcpy(file_l, "");
    strcpy(bios_l, "");
    strcpy(bios, "");
    strcpy(scshot, "");
    strcpy(statefile, "");
    strcpy(xrom, "");
    strcpy(scorefile, "highscore.txt");
    read_default_config();
    if (argc >= 2) {
        for (i = 1; i < argc; i++) {
            if (argv[i][0] != '-') {
                strncat(file, argv[i], 1024 - 1);
                file[1024 - 1] = 0;
                strcpy(file_v, file);
            } else {
                p = strtok(argv[i], "=");
                if (p) {
                    strncpy(attr, p + 1, 1024 - 1);
                    attr[1024 - 1] = 0;
                } else {
                    strcpy(attr, "");
                }
                p = strtok(((void *)0), "=");
                if (p) {
                    strncpy(val, p, 1024 - 1);
                    val[1024 - 1] = 0;
                    if (!strcmp(attr, "romdir") || !strcmp(attr, "ROMDIR")) {
                        strcpy(romdir, val);
                        strcat(romdir, file);
                        strcpy(file, romdir);
                        strcpy(romdir, val);
                    }
                    if (!strcmp(attr, "biosdir") || !strcmp(attr, "BIOSDIR")) {
                        strcpy(biosdir, val);
                    }
                } else {
                    strcpy(val, "");
                }
                _alemu_strlwr(attr);
                if (!parse_option(attr, val)) {
                    exit(1);
                }
            }
        }
        if (helpflag) {
            helpus();
        }
        if (strlen(file) == 0) {
            fprintf(stderr, "Error: file name missing\n");
            exit(1);
        }
        printf("Starting emulation ...\n");
        _install_allegro_version_check(0, &(*__errno_location ()), (int (*)(void (*)(void)))atexit, (((4)<<16)|((4)<<8)|(2)));
        install_timer();
        init_audio();
        printf("Using Allegro %s\n", allegro_id);
        k = strchr(romdir, '/');
        launcher_flag_r = strchr(file, '\\');
        if (k != 0) {
            strcpy(xrom, romdir);
        } else if (!launcher_flag_r) {
            strcpy(xrom, "roms/");
            strcpy(romdir, file);
            strcpy(file, xrom);
            strcat(file, romdir);
            strcpy(romdir, xrom);
        } else {
            cnt = 0;
            cnt2 = 0;
            for (cnt = 0; file[cnt] != '\0'; cnt = cnt + 1) {
                if (file[cnt] == '\\') {
                    cnt2 = cnt;
                }
            }
            for (cnt = 0; cnt <= cnt2; cnt++) {
                file_l[cnt] = file[cnt];
            }
            strcpy(romdir, file_l);
            strcpy(xrom, romdir);
        }
        file_name(xrom);
        if (contax < 3) {
            printf("\nROMs directory empty!\n");
            exit(1);
        }
        app_data.crc = crc32_file(file);
        crcx = app_data.crc;
        suck_roms();
        launcher_flag_b = strchr(bios, '\\');
        if (!launcher_flag_b) {
            k = strchr(biosdir, '/');
            if (k != 0) {
                strcpy(xbios, biosdir);
            } else {
                strcpy(xbios, "bios/");
                strcpy(biosdir, xbios);
            }
            file_name(xbios);
            if (contax < 3) {
                printf("\nBIOS directory empty!\n");
                exit(1);
            }
            suck_bios();
            c_j = strcmp(bios, "jopac");
            if ((rom_f != 1) && (c_j != 0)) {
                strcpy(bios, g7400);
            }
            if ((!o2flag) && (!jopflag) && (!c52flag) && (!g74flag)) {
                printf("\ndir '%s' without BIOS !\n", biosdir);
                exit(1);
            }
            printf("BIOS found:\n");
            if (!strcmp(bios, "g7400")) {
                strcpy(bios, g7400);
                if (g74flag != 1) {
                    printf("\nG7400 BIOS not found !\n");
                    exit(1);
                }
            }
            if (g74flag)
                printf("  G7400 VP+\n");
            if (!strcmp(bios, "c52")) {
                strcpy(bios, c52);
                if (c52flag != 1) {
                    printf("\nC52 BIOS not found !\n");
                    exit(1);
                }
            }
            if (c52flag)
                printf("  C52\n");
            if (!strcmp(bios, "jopac")) {
                strcpy(bios, jopac);
                if (jopflag != 1) {
                    printf("\nJOPAC BIOS not found !\n");
                    exit(1);
                }
            }
            if (jopflag)
                printf("  JOPAC VP+\n");
            if ((!strcmp(bios, "")) || (!strcmp(bios, "o2rom"))) {
                strcpy(bios, odyssey2);
                if ((!o2flag) && (!c52flag) && (rom_f)) {
                    printf("Odyssey2 BIOS not found !\n");
                    exit(1);
                }
                if ((!o2flag) && (c52flag) && (rom_f)) {
                    printf("\nOdyssey2 BIOS not found !\n");
                    printf("Loading C52 BIOS ... ");
                    strcpy(bios, c52);
                }
            }
            if (o2flag)
                printf("  Odyssey 2\n");
        }
        if (launcher_flag_b) {
            identify_bios(bios);
            if (rom_f != 1) {
                if (!((g74flag) || (jopflag))) {
                    fprintf(stderr, "\nError: ROM only VP+ BIOS");
                    exit(1);
                }
            }
        } else {
            if (rom_f != 1) {
                if (!((g74flag) || (jopflag))) {
                    printf("\nROM only VP+ BIOS\n");
                    exit(1);
                }
                if (!(g74flag)) {
                    printf("\nVP+ G7400 BIOS not found !");
                    printf("\nLoading VP+ Jopac BIOS ...");
                    strcpy(bios, jopac);
                }
            }
        }
        load_bios(bios);
        load_cart(file);
        if (app_data.voice)
            load_voice_samples(path);
        init_display();
        init_cpu();
        init_system();
        set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);
        int stateError;
        if ((stateError = loadstate(app_data.statefile)) == 0) {
            printf("Savefile loaded.");
        } else if (stateError >= 199) {
            if (stateError == 199)
                fprintf(stderr, "Wrong ROM-File for Savefile.");
            else if (stateError == 200 + 1)
                fprintf(stderr, "Wrong BIOS for Savefile: O2ROM needed.");
            else if (stateError == 200 + 2)
                fprintf(stderr, "Wrong BIOS for Savefile: G7400 ROM needed.");
            else if (stateError == 200 + 3)
                fprintf(stderr, "Wrong BIOS for Savefile: C52 ROM needed.");
            else if (stateError == 200 + 4)
                fprintf(stderr, "Wrong BIOS for Savefile: JOPAC ROM needed.");
            else
                fprintf(stderr, "Wrong BIOS for Savefile: UNKNOWN ROM needed.");
            return (0);
        }
        if (app_data.debug)
            key_debug = 1;
        run();
        if (app_data.scoretype != 0)
            save_highscore(get_score(app_data.scoretype, app_data.scoreaddress),
                    scorefile);
        exit(0);
    }
    if (!strcmp(attr, "help") || !strcmp(attr, "HELP"))
        helpus();
    printf("type o2em -help\n");
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int i; int cnt; int cnt2;
    static char file[1024]; static char attr[1024]; static char val[1024]; static char *p; static char *binver;
    binver = "UNIX binary";
    printf("%s %s\n", "\nO2EM v" "1.18" " " "(Jan/2007)" "  - ", binver);
    printf(
            "Free Odyssey2 / Videopac+ Emulator - http://o2em.sourceforge.net\n");
    printf("Created by Daniel Boris (c)1996/1998\n");
    printf("Developed by:\n");
    printf("     Andre de la Rocha since version 0.80\n");
    printf("     Arlindo M. de Oliveira since version 1.16\n");
    printf("\n");
    app_data.debug = 0;
    app_data.stick[0] = app_data.stick[1] = 1;
    app_data.sticknumber[0] = app_data.sticknumber[1] = 0;
    set_defjoykeys(0, 0);
    set_defjoykeys(1, 1);
    set_defsystemkeys();
    app_data.bank = 0;
    app_data.limit = 1;
    app_data.sound_en = 1;
    app_data.speed = 100;
    app_data.wsize = 2;
    app_data.fullscreen = 0;
    app_data.scanlines = 0;
    app_data.voice = 1;
    app_data.window_title = "O2EM v" "1.18";
    app_data.svolume = 100;
    app_data.vvolume = 100;
    app_data.filter = 0;
    app_data.exrom = 0;
    app_data.three_k = 0;
    app_data.crc = 0;
    app_data.scshot = scshot;
    app_data.statefile = statefile;
    app_data.euro = 0;
    app_data.openb = 0;
    app_data.vpp = 0;
    app_data.bios = 0;
    app_data.scoretype = 0;
    app_data.scoreaddress = 0;
    app_data.default_highscore = 0;
    app_data.breakpoint = 65535;
    app_data.megaxrom = 0;
    strcpy(file, "");
    strcpy(file_l, "");
    strcpy(bios_l, "");
    strcpy(bios, "");
    strcpy(scshot, "");
    strcpy(statefile, "");
    strcpy(xrom, "");
    strcpy(scorefile, "highscore.txt");
    read_default_config();
    if (argc >= 2) {
        for (i = 1; i < argc; i++) {
            if (argv[i][0] != '-') {
                strncat(file, argv[i], 1024 - 1);
                file[1024 - 1] = 0;
                strcpy(file_v, file);
            } else {
                p = strtok(argv[i], "=");
                if (p) {
                    strncpy(attr, p + 1, 1024 - 1);
                    attr[1024 - 1] = 0;
                } else {
                    strcpy(attr, "");
                }
                p = strtok(((void *)0), "=");
                if (p) {
                    strncpy(val, p, 1024 - 1);
                    val[1024 - 1] = 0;
                    if (!strcmp(attr, "romdir") || !strcmp(attr, "ROMDIR")) {
                        strcpy(romdir, val);
                        strcat(romdir, file);
                        strcpy(file, romdir);
                        strcpy(romdir, val);
                    }
                    if (!strcmp(attr, "biosdir") || !strcmp(attr, "BIOSDIR")) {
                        strcpy(biosdir, val);
                    }
                } else {
                    strcpy(val, "");
                }
                _alemu_strlwr(attr);
                if (!parse_option(attr, val)) {
                    exit(1);
                }
            }
        }
        if (helpflag) {
            helpus();
        }
        if (strlen(file) == 0) {
            fprintf(stderr, "Error: file name missing\n");
            exit(1);
        }
        printf("Starting emulation ...\n");
        _install_allegro_version_check(0, &(*__errno_location ()), (int (*)(void (*)()))atexit, (((4)<<16)|((4)<<8)|(2)));
        install_timer();
        init_audio();
        printf("Using Allegro %s\n", allegro_id);
        k = strchr(romdir, '/');
        launcher_flag_r = strchr(file, '\\');
        if (k != 0) {
            strcpy(xrom, romdir);
        } else if (!launcher_flag_r) {
            strcpy(xrom, "roms/");
            strcpy(romdir, file);
            strcpy(file, xrom);
            strcat(file, romdir);
            strcpy(romdir, xrom);
        } else {
            cnt = 0;
            cnt2 = 0;
            for (cnt = 0; file[cnt] != '\0'; cnt = cnt + 1) {
                if (file[cnt] == '\\') {
                    cnt2 = cnt;
                }
            }
            for (cnt = 0; cnt <= cnt2; cnt++) {
                file_l[cnt] = file[cnt];
            }
            strcpy(romdir, file_l);
            strcpy(xrom, romdir);
        }
        file_name(xrom);
        if (contax < 3) {
            printf("\nROMs directory empty!\n");
            exit(1);
        }
        app_data.crc = crc32_file(file);
        crcx = app_data.crc;
        suck_roms();
        launcher_flag_b = strchr(bios, '\\');
        if (!launcher_flag_b) {
            k = strchr(biosdir, '/');
            if (k != 0) {
                strcpy(xbios, biosdir);
            } else {
                strcpy(xbios, "bios/");
                strcpy(biosdir, xbios);
            }
            file_name(xbios);
            if (contax < 3) {
                printf("\nBIOS directory empty!\n");
                exit(1);
            }
            suck_bios();
            c_j = strcmp(bios, "jopac");
            if ((rom_f != 1) && (c_j != 0)) {
                strcpy(bios, g7400);
            }
            if ((!o2flag) && (!jopflag) && (!c52flag) && (!g74flag)) {
                printf("\ndir '%s' without BIOS !\n", biosdir);
                exit(1);
            }
            printf("BIOS found:\n");
            if (!strcmp(bios, "g7400")) {
                strcpy(bios, g7400);
                if (g74flag != 1) {
                    printf("\nG7400 BIOS not found !\n");
                    exit(1);
                }
            }
            if (g74flag)
                printf("  G7400 VP+\n");
            if (!strcmp(bios, "c52")) {
                strcpy(bios, c52);
                if (c52flag != 1) {
                    printf("\nC52 BIOS not found !\n");
                    exit(1);
                }
            }
            if (c52flag)
                printf("  C52\n");
            if (!strcmp(bios, "jopac")) {
                strcpy(bios, jopac);
                if (jopflag != 1) {
                    printf("\nJOPAC BIOS not found !\n");
                    exit(1);
                }
            }
            if (jopflag)
                printf("  JOPAC VP+\n");
            if ((!strcmp(bios, "")) || (!strcmp(bios, "o2rom"))) {
                strcpy(bios, odyssey2);
                if ((!o2flag) && (!c52flag) && (rom_f)) {
                    printf("Odyssey2 BIOS not found !\n");
                    exit(1);
                }
                if ((!o2flag) && (c52flag) && (rom_f)) {
                    printf("\nOdyssey2 BIOS not found !\n");
                    printf("Loading C52 BIOS ... ");
                    strcpy(bios, c52);
                }
            }
            if (o2flag)
                printf("  Odyssey 2\n");
        }
        if (launcher_flag_b) {
            identify_bios(bios);
            if (rom_f != 1) {
                if (!((g74flag) || (jopflag))) {
                    fprintf(stderr, "\nError: ROM only VP+ BIOS");
                    exit(1);
                }
            }
        } else {
            if (rom_f != 1) {
                if (!((g74flag) || (jopflag))) {
                    printf("\nROM only VP+ BIOS\n");
                    exit(1);
                }
                if (!(g74flag)) {
                    printf("\nVP+ G7400 BIOS not found !");
                    printf("\nLoading VP+ Jopac BIOS ...");
                    strcpy(bios, jopac);
                }
            }
        }
        load_bios(bios);
        load_cart(file);
        if (app_data.voice)
            load_voice_samples(path);
        init_display();
        init_cpu();
        init_system();
        set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);
        int stateError;
        if ((stateError = loadstate(app_data.statefile)) == 0) {
            printf("Savefile loaded.");
        } else if (stateError >= 199) {
            if (stateError == 199)
                fprintf(stderr, "Wrong ROM-File for Savefile.");
            else if (stateError == 200 + 1)
                fprintf(stderr, "Wrong BIOS for Savefile: O2ROM needed.");
            else if (stateError == 200 + 2)
                fprintf(stderr, "Wrong BIOS for Savefile: G7400 ROM needed.");
            else if (stateError == 200 + 3)
                fprintf(stderr, "Wrong BIOS for Savefile: C52 ROM needed.");
            else if (stateError == 200 + 4)
                fprintf(stderr, "Wrong BIOS for Savefile: JOPAC ROM needed.");
            else
                fprintf(stderr, "Wrong BIOS for Savefile: UNKNOWN ROM needed.");
            return (0);
        }
        if (app_data.debug)
            key_debug = 1;
        run();
        if (app_data.scoretype != 0)
            save_highscore(get_score(app_data.scoretype, app_data.scoreaddress),
                    scorefile);
        exit(0);
    }
    if (!strcmp(attr, "help") || !strcmp(attr, "HELP"))
        helpus();
    printf("type o2em -help\n");
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: cnt int

variable_types:
file
char [1024]

variable_types:
attr
char [1024]

variable_types:
val
char [1024]

variable_types:
p
char *

variable_types:
binver
char *

variable_types: stateError int

return_type: int


disasm

decompiled_code:
__int64 __fastcall disasm(unsigned __int16 a1)
{
unsigned __int8 v1; // r12
const char **v2; // r13
char v3; // al

v1 = rom[a1];
printf("%04x %02x", (unsigned int)(unsigned __int16)(a1 + 1) - 1, v1);
if ( lookup[16 * v1 + 8] == 2 )
printf(" %02x", (unsigned __int8)rom[(unsigned __int16)(a1 + 1)]);
else
printf(" ");
v2 = (const char **)&lookup[16 * v1];
printf(" %s", *v2);
v3 = *((_BYTE *)v2 + 9);
if ( v3 == 2 )
{
printf(" $%03x\n", (unsigned __int16)(unsigned __int8)rom[(unsigned __int16)(a1 + 1)] | (8 * v1) & 0x700u);
}
else if ( (unsigned __int8)v3 > 2u )
{
if ( v3 == 3 )
printf(" $%02x\n", (unsigned __int8)rom[(unsigned __int16)(a1 + 1)]);
}
else if ( v3 )
{
printf(" #%02x\n", (unsigned __int8)rom[(unsigned __int16)(a1 + 1)]);
}
else
{
putchar(10);
}
if ( (v1 & 0xEF) == 0x83 || lookup[16 * v1 + 8] + (_BYTE)a1 + 1 == 1 )
putchar(10);
return lookup[16 * v1 + 8];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
unsigned __int8 v1; // r12
const char **v2; // r13
char v3; // al

v1 = rom[a1];
printf("%04x %02x", (unsigned int)(unsigned __int16)(a1 + 1) - 1, v1);
if ( lookup[16 * v1 + 8] == 2 )
printf(" %02x", (unsigned __int8)rom[(unsigned __int16)(a1 + 1)]);
else
printf(" ");
v2 = (const char **)&lookup[16 * v1];
printf(" %s", *v2);
v3 = *((_BYTE *)v2 + 9);
if ( v3 == 2 )
{
printf(" $%03x\n", (unsigned __int16)(unsigned __int8)rom[(unsigned __int16)(a1 + 1)] | (8 * v1) & 0x700u);
}
else if ( (unsigned __int8)v3 > 2u )
{
if ( v3 == 3 )
printf(" $%02x\n", (unsigned __int8)rom[(unsigned __int16)(a1 + 1)]);
}
else if ( v3 )
{
printf(" #%02x\n", (unsigned __int8)rom[(unsigned __int16)(a1 + 1)]);
}
else
{
putchar(10);
}
if ( (v1 & 0xEF) == 0x83 || lookup[16 * v1 + 8] + (_BYTE)a1 + 1 == 1 )
putchar(10);
return lookup[16 * v1 + 8];
}

original_code:
static int disasm(ADDRESS p) {
 Byte op,d;
 ADDRESS adr;
 op=rom[p++];
 printf("%04x  %02x",p-1,op);
 if (lookup[op].bytes == 2) printf(" %02x",rom[p]); else printf("   ");
 printf("   %s",lookup[op].mnemonic);
 switch(lookup[op].type) {
  case 0:
   printf("\n");
   break;
  case 1:
   d=rom[p];
   printf(" #%02x\n",d);
   break;
  case 2:
   adr=rom[p];
   adr = adr | ((op & 0xE0) << 3);
   printf(" $%03x\n",adr);
   break;
  case 3:
   printf(" $%02x\n",rom[p]);
   break;
 }
 if (op == 0x83 || op == 0x93 || (((p-2+lookup[op].bytes) & 0xff) == 0xff)) printf("\n");
 return lookup[op].bytes;
}

canonical_original_code:
static int disasm(unsigned short p) {
 unsigned char op; unsigned char d;
 unsigned short adr;
 op=rom[p++];
 printf("%04x  %02x",p-1,op);
 if (lookup[op].bytes == 2) printf(" %02x",rom[p]); else printf("   ");
 printf("   %s",lookup[op].mnemonic);
 switch(lookup[op].type) {
  case 0:
   printf("\n");
   break;
  case 1:
   d=rom[p];
   printf(" #%02x\n",d);
   break;
  case 2:
   adr=rom[p];
   adr = adr | ((op & 0xE0) << 3);
   printf(" $%03x\n",adr);
   break;
  case 3:
   printf(" $%02x\n",rom[p]);
   break;
 }
 if (op == 0x83 || op == 0x93 || (((p-2+lookup[op].bytes) & 0xff) == 0xff)) printf("\n");
 return lookup[op].bytes;
}

variable_types:
p
unsigned short

variable_types:
op
unsigned char

variable_types:
d
unsigned char

variable_types:
adr
unsigned short


decompiled_code:
int __fastcall load_voice_samples(const char *a1)
{
__int64 v1; // r12
int v2; // er13
__int64 v3; // rax
unsigned int j; // ebx
__int64 *v5; // rbp
unsigned int v6; // er14
int result; // eax
int i; // [rsp+4h] [rbp-444h]
__int64 *v9; // [rsp+8h] [rbp-440h]
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

printf("Loading voice samples... ");
fflush(stdout);
v9 = &voices;
v1 = 0LL;
v2 = 0;
for ( i = 0; i != 9; ++i )
{
v6 = i + 231;
if ( !i )
v6 = 228;
v5 = v9;
for ( j = 128; j != 256; ++j )
{
sprintf(s, "%svoice/%02x%02x.wav", a1, v6, j);
v3 = load_sample(s);
*v5 = v3;
if ( v3 || (sprintf(s, "%svoice/%02X%02X.WAV", a1, v6, j), v3 = load_sample(s), (*v5 = v3) != 0) )
{
++v2;
if ( !v1 )
v1 = v3;
}
++v5;
}
v9 += 128;
}
result = printf("%d samples loaded\n", (unsigned int)v2);
if ( v2 > 0 )
{
result = allocate_voice(v1);
voice_num = result;
if ( result == -1 )
{
result = puts(" ERROR: could not allocate sound card voice");
voice_ok = 0;
}
else
{
voice_ok = 1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
__int64 v1; // r12
int v2; // er13
__int64 v3; // rax
unsigned int j; // ebx
__int64 *v5; // rbp
unsigned int v6; // er14
int result; // eax
int i; // [rsp+4h] [rbp-444h]
__int64 *v9; // [rsp+8h] [rbp-440h]
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

printf("Loading voice samples... ");
fflush(stdout);
v9 = &voices;
v1 = 0LL;
v2 = 0;
for ( i = 0; i != 9; ++i )
{
v6 = i + 231;
if ( !i )
v6 = 228;
v5 = v9;
for ( j = 128; j != 256; ++j )
{
sprintf(s, "%svoice/%02x%02x.wav", a1, v6, j);
v3 = load_sample(s);
*v5 = v3;
if ( v3 || (sprintf(s, "%svoice/%02X%02X.WAV", a1, v6, j), v3 = load_sample(s), (*v5 = v3) != 0) )
{
++v2;
if ( !v1 )
v1 = v3;
}
++v5;
}
v9 += 128;
}
result = printf("%d samples loaded\n", (unsigned int)v2);
if ( v2 > 0 )
{
result = allocate_voice(v1);
voice_num = result;
if ( result == -1 )
{
result = puts(" ERROR: could not allocate sound card voice");
voice_ok = 0;
}
else
{
voice_ok = 1;
}
}
return result;
}

original_code:
void load_voice_samples(char *path)
{
    int bank, sam, i, ld = 0;
    char name[1024];
    SAMPLE *sp = ((void *)0);
    printf("Loading voice samples...  ");
    fflush(stdout);
    for (i = 0; i < 9; i++) {
        for (sam = 0; sam < 128; sam++) {
            if (i)
                bank = 0xE8 + i - 1;
            else
                bank = 0xE4;
            sprintf(name, "%svoice/%02x%02x.wav", path, bank, sam + 0x80);
            voices[i][sam] = load_sample(name);
            if (!voices[i][sam]) {
                sprintf(name, "%svoice/%02X%02X.WAV", path, bank, sam + 0x80);
                voices[i][sam] = load_sample(name);
            }
            if (voices[i][sam]) {
                ld++;
                if (!sp)
                    sp = voices[i][sam];
            }
        }
    }
    printf("%d samples loaded\n", ld);
    if (ld > 0) {
        voice_num = allocate_voice(sp);
        if (voice_num != -1)
            voice_ok = 1;
        else {
            printf("  ERROR: could not allocate sound card voice\n");
            voice_ok = 0;
        }
    }
}

canonical_original_code:
void load_voice_samples(char *path)
{
    int bank; int sam; int i; int ld = 0;
    char name[1024];
    struct SAMPLE *sp = ((void *)0);
    printf("Loading voice samples...  ");
    fflush(stdout);
    for (i = 0; i < 9; i++) {
        for (sam = 0; sam < 128; sam++) {
            if (i)
                bank = 0xE8 + i - 1;
            else
                bank = 0xE4;
            sprintf(name, "%svoice/%02x%02x.wav", path, bank, sam + 0x80);
            voices[i][sam] = load_sample(name);
            if (!voices[i][sam]) {
                sprintf(name, "%svoice/%02X%02X.WAV", path, bank, sam + 0x80);
                voices[i][sam] = load_sample(name);
            }
            if (voices[i][sam]) {
                ld++;
                if (!sp)
                    sp = voices[i][sam];
            }
        }
    }
    printf("%d samples loaded\n", ld);
    if (ld > 0) {
        voice_num = allocate_voice(sp);
        if (voice_num != -1)
            voice_ok = 1;
        else {
            printf("  ERROR: could not allocate sound card voice\n");
            voice_ok = 0;
        }
    }
}

variable_types:
path
char *

variable_types: bank int

variable_types: sam int

variable_types: ld int

variable_types:
name
char [1024]

variable_types: struct SAMPLE { int bits; int stereo; int freq; int priority; unsigned long len; unsigned long loop_start; unsigned long loop_end; unsigned long param; void *data; } *

return_type: void


decompiled_code:
void update_voice()
{
if ( voice_ok )
{
if ( voice_st == 2 )
{
if ( (int)voice_get_position((unsigned int)voice_num) < 0
&& (unsigned int)voice_bank <= 8
&& (unsigned int)(voice_addr - 128) <= 0x7F )
{
if ( voices[128 * (__int64)voice_bank - 128 + voice_addr] )
{
reallocate_voice((unsigned int)voice_num);
voice_set_volume((unsigned int)voice_num, (unsigned int)(255 * app_data[14] / 100));
voice_start((unsigned int)voice_num);
clk_voice_start = clk_counter;
voice_st = 1;
}
else
{
voice_st = 0;
}
}
}
else if ( voice_st == 1
&& ((int)voice_get_position((unsigned int)voice_num) < 0
|| (unsigned __int64)(clk_counter - clk_voice_start) > 0x14) )
{
voice_st = 0;
}
}
}

canonical_decompiled_code:
void func1()
{
if ( voice_ok )
{
if ( voice_st == 2 )
{
if ( (int)voice_get_position((unsigned int)voice_num) < 0
&& (unsigned int)voice_bank <= 8
&& (unsigned int)(voice_addr - 128) <= 0x7F )
{
if ( voices[128 * (__int64)voice_bank - 128 + voice_addr] )
{
reallocate_voice((unsigned int)voice_num);
voice_set_volume((unsigned int)voice_num, (unsigned int)(255 * app_data[14] / 100));
voice_start((unsigned int)voice_num);
clk_voice_start = clk_counter;
voice_st = 1;
}
else
{
voice_st = 0;
}
}
}
else if ( voice_st == 1
&& ((int)voice_get_position((unsigned int)voice_num) < 0
|| (unsigned __int64)(clk_counter - clk_voice_start) > 0x14) )
{
voice_st = 0;
}
}
}

original_code:
void update_voice(void)
{
    if (!voice_ok)
        return;
    if (voice_st == 2) {
        if (voice_get_position(voice_num) < 0) {
            if ((voice_bank >= 0) && (voice_bank < 9) && (voice_addr >= 0x80)
                    && (voice_addr <= 0xff)) {
                if (voices[voice_bank][voice_addr - 0x80]) {
                    reallocate_voice(voice_num,
                            voices[voice_bank][voice_addr - 0x80]);
                    voice_set_volume(voice_num, (255 * app_data.vvolume) / 100);
                    voice_start(voice_num);
                    clk_voice_start = clk_counter;
                    voice_st = 1;
                } else {
                    voice_st = 0;
                }
            }
        }
    } else if (voice_st == 1) {
        if ((voice_get_position(voice_num) < 0)
                || (clk_counter - clk_voice_start > 20)) {
            voice_st = 0;
        }
    }
}

canonical_original_code:
void update_voice()
{
    if (!voice_ok)
        return;
    if (voice_st == 2) {
        if (voice_get_position(voice_num) < 0) {
            if ((voice_bank >= 0) && (voice_bank < 9) && (voice_addr >= 0x80)
                    && (voice_addr <= 0xff)) {
                if (voices[voice_bank][voice_addr - 0x80]) {
                    reallocate_voice(voice_num,
                            voices[voice_bank][voice_addr - 0x80]);
                    voice_set_volume(voice_num, (255 * app_data.vvolume) / 100);
                    voice_start(voice_num);
                    clk_voice_start = clk_counter;
                    voice_st = 1;
                } else {
                    voice_st = 0;
                }
            }
        }
    } else if (voice_st == 1) {
        if ((voice_get_position(voice_num) < 0)
                || (clk_counter - clk_voice_start > 20)) {
            voice_st = 0;
        }
    }
}


decompiled_code:
void __fastcall trigger_voice(int a1)
{
if ( voice_ok )
{
if ( !voice_st || (update_voice(), !voice_st) )
{
if ( (unsigned int)voice_bank <= 8 && (unsigned int)(a1 - 128) <= 0x7F )
{
voice_addr = a1;
voice_st = 2;
update_voice();
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
if ( voice_ok )
{
if ( !voice_st || (func1(), !voice_st) )
{
if ( (unsigned int)voice_bank <= 8 && (unsigned int)(a1 - 128) <= 0x7F )
{
voice_addr = a1;
voice_st = 2;
func1();
}
}
}
}

original_code:
void trigger_voice(int addr)
{
    if (voice_ok) {
        if (voice_st)
            update_voice();
        if ((voice_st == 0) && (voice_bank >= 0) && (voice_bank < 9)
                && (addr >= 0x80) && (addr <= 0xff)) {
            voice_addr = addr;
            voice_st = 2;
            update_voice();
        }
    }
}

variable_types: addr int


decompiled_code:
void __fastcall set_voice_bank(unsigned int a1)
{
if ( voice_ok )
{
if ( a1 <= 8 )
voice_bank = a1;
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned int a1)
{
if ( voice_ok )
{
if ( a1 <= 8 )
voice_bank = a1;
}
}

original_code:
void set_voice_bank(int bank)
{
    if (!voice_ok)
        return;
    if ((bank >= 0) && (bank <= 8))
        voice_bank = bank;
}


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

result = (unsigned int)voice_ok;
if ( voice_ok )
{
update_voice();
result = voice_st != 0;
}
return result;
}

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

result = (unsigned int)voice_ok;
if ( voice_ok )
{
func1();
result = voice_st != 0;
}
return result;
}

original_code:
int get_voice_status(void)
{
    if (voice_ok) {
        update_voice();
        if (voice_st)
            return 1;
    }
    return 0;
}

canonical_original_code:
int get_voice_status()
{
    if (voice_ok) {
        update_voice();
        if (voice_st)
            return 1;
    }
    return 0;
}


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

if ( voice_ok )
{
result = voice_stop((unsigned int)voice_num);
voice_bank = 0;
voice_addr = 0;
voice_st = 0;
}
return result;
}

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

if ( voice_ok )
{
result = voice_stop((unsigned int)voice_num);
voice_bank = 0;
voice_addr = 0;
voice_st = 0;
}
return result;
}

original_code:
void reset_voice(void)
{
    if (voice_ok) {
        voice_stop(voice_num);
        voice_bank = 0;
        voice_addr = 0;
        voice_st = 0;
    }
}

canonical_original_code:
void reset_voice()
{
    if (voice_ok) {
        voice_stop(voice_num);
        voice_bank = 0;
        voice_addr = 0;
        voice_st = 0;
    }
}


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

if ( voice_ok )
result = voice_stop((unsigned int)voice_num);
return result;
}

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

if ( voice_ok )
result = voice_stop((unsigned int)voice_num);
return result;
}

original_code:
void mute_voice(void)
{
    if (voice_ok) {
        voice_stop(voice_num);
    }
}

canonical_original_code:
void mute_voice()
{
    if (voice_ok) {
        voice_stop(voice_num);
    }
}


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

result = reset_voice();
voice_ok = 0;
return result;
}

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

result = func5();
voice_ok = 0;
return result;
}

original_code:
void close_voice(void)
{
    reset_voice();
    voice_ok = 0;
}

canonical_original_code:
void close_voice()
{
    reset_voice();
    voice_ok = 0;
}


decompiled_code:
int __fastcall set_joykeys(unsigned int a1, int a2, int a3, int a4, int a5, int a6)
{
unsigned __int64 v10; // rax
__int64 v11; // rcx
int *v12; // rax
int *v13; // rax

LODWORD(v10) = printf("Setting joypad controller %d \n", a1);
if ( a1 <= 1 )
{
v11 = 5LL * (int)a1;
joykeys[v11] = a2;
joykeys[v11 + 1] = a3;
joykeys[v11 + 2] = a4;
joykeys[v11 + 3] = a5;
joykeys[v11 + 4] = a6;
v12 = joykeystab;
do
*v12++ = 0;
while ( v12 != (int *)(unsigned int)((_DWORD)joykeystab + 512) );
v13 = joykeys;
do
{
if ( (unsigned int)(*v13 - 1) > 0x7E )
*v13 = 0;
else
joykeystab[*v13] = 1;
++v13;
}
while ( v13 != (int *)(unsigned int)((_DWORD)joykeys + 20) );
v10 = (unsigned int)((_DWORD)joykeys + 20);
do
{
if ( (unsigned int)(*(_DWORD *)v10 - 1) <= 0x7E )
joykeystab[*(int *)v10] = 1;
else
*(_DWORD *)v10 = 0;
v10 += 4LL;
}
while ( v10 != (_DWORD)joykeys + 40 );
}
return v10;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, int a2, int a3, int a4, int a5, int a6)
{
unsigned __int64 v10; // rax
__int64 v11; // rcx
int *v12; // rax
int *v13; // rax

LODWORD(v10) = printf("Setting joypad controller %d \n", a1);
if ( a1 <= 1 )
{
v11 = 5LL * (int)a1;
joykeys[v11] = a2;
joykeys[v11 + 1] = a3;
joykeys[v11 + 2] = a4;
joykeys[v11 + 3] = a5;
joykeys[v11 + 4] = a6;
v12 = joykeystab;
do
*v12++ = 0;
while ( v12 != (int *)(unsigned int)((_DWORD)joykeystab + 512) );
v13 = joykeys;
do
{
if ( (unsigned int)(*v13 - 1) > 0x7E )
*v13 = 0;
else
joykeystab[*v13] = 1;
++v13;
}
while ( v13 != (int *)(unsigned int)((_DWORD)joykeys + 20) );
v10 = (unsigned int)((_DWORD)joykeys + 20);
do
{
if ( (unsigned int)(*(_DWORD *)v10 - 1) <= 0x7E )
joykeystab[*(int *)v10] = 1;
else
*(_DWORD *)v10 = 0;
v10 += 4LL;
}
while ( v10 != (_DWORD)joykeys + 40 );
}
return v10;
}

original_code:
void set_joykeys(int stick_number, int up, int down, int left, int right, int fire){
    printf("Setting joypad controller %d \n", stick_number);
    int i, j;
    if ((stick_number<0) || (stick_number>1)) {
        return;
    }
    joykeys[stick_number][0] = up;
    joykeys[stick_number][1] = down;
    joykeys[stick_number][2] = left;
    joykeys[stick_number][3] = right;
    joykeys[stick_number][4] = fire;
    for (i=0; i<128; i++) {
        joykeystab[i]=0;
    }
    for (j=0; j<2; j++) {
        for (i=0; i<5; i++) {
            if ((joykeys[j][i]<1) || (joykeys[j][i]>127)) {
                joykeys[j][i] = 0;
            } else {
                joykeystab[joykeys[j][i]] = 1;
            }
        }
    }
}

canonical_original_code:
void set_joykeys(int stick_number, int up, int down, int left, int right, int fire){
    printf("Setting joypad controller %d \n", stick_number);
    int i; int j;
    if ((stick_number<0) || (stick_number>1)) {
        return;
    }
    joykeys[stick_number][0] = up;
    joykeys[stick_number][1] = down;
    joykeys[stick_number][2] = left;
    joykeys[stick_number][3] = right;
    joykeys[stick_number][4] = fire;
    for (i=0; i<128; i++) {
        joykeystab[i]=0;
    }
    for (j=0; j<2; j++) {
        for (i=0; i<5; i++) {
            if ((joykeys[j][i]<1) || (joykeys[j][i]>127)) {
                joykeys[j][i] = 0;
            } else {
                joykeystab[joykeys[j][i]] = 1;
            }
        }
    }
}

variable_types: up int

variable_types: down int

variable_types: left int

variable_types: right int

variable_types: fire int

variable_types: i int

variable_types: j int


decompiled_code:
int __fastcall set_defjoykeys(unsigned int a1, unsigned int a2)
{
int result; // eax

printf("Setting keyboard controller %d to %d\n", a1, a2);
if ( a2 )
result = set_joykeys(a1, 23, 19, 1, 4, 75);
else
result = set_joykeys(a1, 84, 85, 82, 83, 12);
return result;
}

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

printf("Setting keyboard controller %d to %d\n", a1, a2);
if ( a2 )
result = func0(a1, 23, 19, 1, 4, 75);
else
result = func0(a1, 84, 85, 82, 83, 12);
return result;
}

original_code:
void set_defjoykeys(int stick_number, int control_scheme){
    printf("Setting keyboard controller %d to %d\n", stick_number, control_scheme);
    if (control_scheme) {
        set_joykeys(stick_number, __allegro_KEY_W, __allegro_KEY_S, __allegro_KEY_A, __allegro_KEY_D, __allegro_KEY_SPACE);
    } else {
        set_joykeys(stick_number,__allegro_KEY_UP,__allegro_KEY_DOWN,__allegro_KEY_LEFT,__allegro_KEY_RIGHT,__allegro_KEY_L);
    }
}


decompiled_code:
__int64 __fastcall set_systemkeys(int a1, int a2, int a3, int a4, int a5, int a6, int a7, unsigned int a8)
{
__int64 result; // rax

syskeys = a1;
*(&syskeys + 1) = a2;
*(&syskeys + 2) = a3;
*(&syskeys + 3) = a4;
*(&syskeys + 4) = a5;
*(&syskeys + 5) = a6;
*(&syskeys + 6) = a7;
result = a8;
*(&syskeys + 7) = a8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4, int a5, int a6, int a7, unsigned int a8)
{
__int64 result; // rax

syskeys = a1;
*(&syskeys + 1) = a2;
*(&syskeys + 2) = a3;
*(&syskeys + 3) = a4;
*(&syskeys + 4) = a5;
*(&syskeys + 5) = a6;
*(&syskeys + 6) = a7;
result = a8;
*(&syskeys + 7) = a8;
return result;
}

original_code:
void set_systemkeys(int k_quit,int k_pause,int k_debug,int k_reset,int k_screencap,int k_save,int k_load,int k_inject)
{
    syskeys[0] = k_quit;
    syskeys[1] = k_pause;
    syskeys[2] = k_debug;
    syskeys[3] = k_reset;
    syskeys[4] = k_screencap;
    syskeys[5] = k_save;
    syskeys[6] = k_load;
    syskeys[7] = k_inject;
}

canonical_original_code:
void set_systemkeys(int k_quit, int k_pause, int k_debug, int k_reset, int k_screencap, int k_save, int k_load, int k_inject)
{
    syskeys[0] = k_quit;
    syskeys[1] = k_pause;
    syskeys[2] = k_debug;
    syskeys[3] = k_reset;
    syskeys[4] = k_screencap;
    syskeys[5] = k_save;
    syskeys[6] = k_load;
    syskeys[7] = k_inject;
}


decompiled_code:
__int64 set_defsystemkeys()
{
return set_systemkeys(58, 47, 50, 51, 54, 48, 49, 0x34u);
}

original_code:
void set_defsystemkeys(void)
{
    set_systemkeys(__allegro_KEY_F12,__allegro_KEY_F1,__allegro_KEY_F4,__allegro_KEY_F5,__allegro_KEY_F8,__allegro_KEY_F2,__allegro_KEY_F3,__allegro_KEY_F6);
}

canonical_original_code:
void set_defsystemkeys()
{
    set_systemkeys(__allegro_KEY_F12,__allegro_KEY_F1,__allegro_KEY_F4,__allegro_KEY_F5,__allegro_KEY_F8,__allegro_KEY_F2,__allegro_KEY_F3,__allegro_KEY_F6);
}


decompiled_code:
__int64 handle_key()
{
const char *v0; // rbp
char *v1; // rax
char *v2; // rbx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rcx
__int64 v6; // rbx
int v7; // eax
__int64 result; // rax
_BYTE v9[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( NeedsPoll )
poll_keyboard();
if ( key[syskeys] || key[59] )
{
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[syskeys] || key[59] );
key_done = 1;
}
if ( key[*(&syskeys + 1)] )
{
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 1)] );
mute_audio();
mute_voice();
abaut();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
if ( key[119] && key[67] )
{
*((_DWORD *)&app_data + 10) = *((_DWORD *)&app_data + 10) == 0;
grmode();
abaut();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[67] );
}
}
while ( !key[*(&syskeys + 1)] && !key[59] && !key[syskeys] );
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 1)] );
((void (*)(void))init_sound_stream)();
}
if ( key[*(&syskeys + 5)] )
{
if ( !(unsigned int)savestate(*((_QWORD *)&app_data + 17)) )
display_msg("Savefile saved.", 5LL);
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 5)] );
}
if ( key[*(&syskeys + 6)] )
{
v7 = loadstate(*((_QWORD *)&app_data + 17));
if ( v7 )
{
if ( v7 > 198 )
{
switch ( v7 )
{
case 199:
display_msg("Wrong ROM-File for Savefile.", 5LL);
break;
case 201:
display_msg("Wrong BIOS for Savefile: O2ROM needed.", 5LL);
break;
case 202:
display_msg("Wrong BIOS for Savefile: G7400 ROM needed.", 5LL);
break;
case 203:
display_msg("Wrong BIOS for Savefile: C52 ROM needed.", 5LL);
break;
case 204:
display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.", 5LL);
break;
default:
display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.", 5LL);
break;
}
}
}
else
{
display_msg("Savefile loaded.", 5LL);
}
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 6)] );
}
if ( key[*(&syskeys + 2)] )
key_debug = 1;
if ( key[*(&syskeys + 3)] )
{
init_cpu();
init_roms();
init_vpp();
clearscr();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 3)] );
}
if ( key[*(&syskeys + 7)] )
set_score(*((unsigned int *)&app_data + 30), *((unsigned int *)&app_data + 31), *((unsigned int *)&app_data + 32));
if ( key[*(&syskeys + 4)] )
{
v0 = (const char *)*((_QWORD *)&app_data + 14);
if ( *v0 )
{
v1 = strchr(*((const char **)&app_data + 14), 64);
v2 = v1;
if ( v1 )
{
*v1 = 0;
v3 = (unsigned int)scshot_counter_1++;
sprintf(name_0, "%s%02d%s", *((const char **)&app_data + 14), v3, v1 + 1);
*v2 = 64;
}
else
{
strcpy(name_0, v0);
}
get_palette(v9);
if ( gfx_driver )
{
v4 = *(unsigned int *)(gfx_driver + 220LL);
v5 = *(unsigned int *)(gfx_driver + 216LL);
}
else
{
v4 = 0LL;
v5 = 0LL;
}
v6 = create_sub_bitmap(screen, 0LL, 0LL, v5, v4);
save_bitmap(name_0, v6, v9);
destroy_bitmap(v6);
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 4)] );
}
}
result = key[119];
if ( (_BYTE)result )
{
result = key[67];
if ( (_BYTE)result )
{
*((_DWORD *)&app_data + 10) = *((_DWORD *)&app_data + 10) == 0;
grmode();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
result = key[67];
}
while ( (_BYTE)result );
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
const char *v0; // rbp
char *v1; // rax
char *v2; // rbx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rcx
__int64 v6; // rbx
int v7; // eax
__int64 result; // rax
_BYTE v9[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( NeedsPoll )
poll_keyboard();
if ( key[syskeys] || key[59] )
{
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[syskeys] || key[59] );
key_done = 1;
}
if ( key[*(&syskeys + 1)] )
{
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 1)] );
mute_audio();
mute_voice();
abaut();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
if ( key[119] && key[67] )
{
*((_DWORD *)&app_data + 10) = *((_DWORD *)&app_data + 10) == 0;
grmode();
abaut();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[67] );
}
}
while ( !key[*(&syskeys + 1)] && !key[59] && !key[syskeys] );
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 1)] );
((void (*)(void))init_sound_stream)();
}
if ( key[*(&syskeys + 5)] )
{
if ( !(unsigned int)savestate(*((_QWORD *)&app_data + 17)) )
display_msg("Savefile saved.", 5LL);
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 5)] );
}
if ( key[*(&syskeys + 6)] )
{
v7 = loadstate(*((_QWORD *)&app_data + 17));
if ( v7 )
{
if ( v7 > 198 )
{
switch ( v7 )
{
case 199:
display_msg("Wrong ROM-File for Savefile.", 5LL);
break;
case 201:
display_msg("Wrong BIOS for Savefile: O2ROM needed.", 5LL);
break;
case 202:
display_msg("Wrong BIOS for Savefile: G7400 ROM needed.", 5LL);
break;
case 203:
display_msg("Wrong BIOS for Savefile: C52 ROM needed.", 5LL);
break;
case 204:
display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.", 5LL);
break;
default:
display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.", 5LL);
break;
}
}
}
else
{
display_msg("Savefile loaded.", 5LL);
}
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 6)] );
}
if ( key[*(&syskeys + 2)] )
key_debug = 1;
if ( key[*(&syskeys + 3)] )
{
init_cpu();
init_roms();
init_vpp();
clearscr();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 3)] );
}
if ( key[*(&syskeys + 7)] )
set_score(*((unsigned int *)&app_data + 30), *((unsigned int *)&app_data + 31), *((unsigned int *)&app_data + 32));
if ( key[*(&syskeys + 4)] )
{
v0 = (const char *)*((_QWORD *)&app_data + 14);
if ( *v0 )
{
v1 = strchr(*((const char **)&app_data + 14), 64);
v2 = v1;
if ( v1 )
{
*v1 = 0;
v3 = (unsigned int)scshot_counter_1++;
sprintf(name_0, "%s%02d%s", *((const char **)&app_data + 14), v3, v1 + 1);
*v2 = 64;
}
else
{
strcpy(name_0, v0);
}
get_palette(v9);
if ( gfx_driver )
{
v4 = *(unsigned int *)(gfx_driver + 220LL);
v5 = *(unsigned int *)(gfx_driver + 216LL);
}
else
{
v4 = 0LL;
v5 = 0LL;
}
v6 = create_sub_bitmap(screen, 0LL, 0LL, v5, v4);
save_bitmap(name_0, v6, v9);
destroy_bitmap(v6);
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
}
while ( key[*(&syskeys + 4)] );
}
}
result = key[119];
if ( (_BYTE)result )
{
result = key[67];
if ( (_BYTE)result )
{
*((_DWORD *)&app_data + 10) = *((_DWORD *)&app_data + 10) == 0;
grmode();
do
{
rest(5LL);
if ( NeedsPoll )
poll_keyboard();
result = key[67];
}
while ( (_BYTE)result );
}
}
return result;
}

original_code:
void handle_key(void){
    if (NeedsPoll) poll_keyboard();
    if (key[syskeys[0]] || key[__allegro_KEY_ESC]) {
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[0]] || key[__allegro_KEY_ESC]);
        key_done=1;
    }
    if (key[syskeys[1]]) {
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[1]]);
        mute_audio();
        mute_voice();
        abaut();
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
            if (key[__allegro_KEY_ALT] && key[__allegro_KEY_ENTER]) {
                app_data.fullscreen = app_data.fullscreen ? 0 : 1;
                grmode();
                abaut();
                do {
                    rest(5);
                    if (NeedsPoll) poll_keyboard();
                } while (key[__allegro_KEY_ENTER]);
            }
        } while ((!key[syskeys[1]]) && (!key[__allegro_KEY_ESC]) && (!key[syskeys[0]]));
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[1]]);
        init_sound_stream();
    }
    if (key[syskeys[5]]) {
        if (savestate(app_data.statefile)==0) {
            display_msg("Savefile saved.",5);
        }
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[5]]);
    }
    if (key[syskeys[6]]) {
        int stateError;
        if ((stateError=loadstate(app_data.statefile))==0) {
            display_msg("Savefile loaded.",5);
        } else if (stateError>=199) {
            if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5);
            else if (stateError==200+1) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5);
            else if (stateError==200+2) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5);
            else if (stateError==200+3) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5);
            else if (stateError==200+4) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5);
            else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5);
        }
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[6]]);
    }
    if (key[syskeys[2]]) key_debug=1;
    if (key[syskeys[3]]) {
        init_cpu();
        init_roms();
        init_vpp();
        clearscr();
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[3]]);
    }
    if (key[syskeys[7]]) {
        set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);
    }
    if (key[syskeys[4]]) {
        BITMAP *bmp;
        PALETTE pal;
        char *p;
        static char name[1024];
        static int scshot_counter = 0;
        if (strlen(app_data.scshot)>0){
            if ((p=strchr(app_data.scshot,'@'))) {
                *p = 0;
                sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1);
                *p = '@';
            } else {
                strcpy(name, app_data.scshot);
            }
            get_palette(pal);
            bmp = create_sub_bitmap(screen, 0, 0, (gfx_driver ? gfx_driver->w : 0), (gfx_driver ? gfx_driver->h : 0));
            save_bitmap(name, bmp, pal);
            destroy_bitmap(bmp);
            do {
                rest(5);
                if (NeedsPoll) poll_keyboard();
            } while (key[syskeys[4]]);
        }
    }
    if (key[__allegro_KEY_ALT] && key[__allegro_KEY_ENTER]) {
        app_data.fullscreen = app_data.fullscreen ? 0 : 1;
        grmode();
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[__allegro_KEY_ENTER]);
    }
}

canonical_original_code:
void handle_key(){
    if (NeedsPoll) poll_keyboard();
    if (key[syskeys[0]] || key[__allegro_KEY_ESC]) {
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[0]] || key[__allegro_KEY_ESC]);
        key_done=1;
    }
    if (key[syskeys[1]]) {
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[1]]);
        mute_audio();
        mute_voice();
        abaut();
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
            if (key[__allegro_KEY_ALT] && key[__allegro_KEY_ENTER]) {
                app_data.fullscreen = app_data.fullscreen ? 0 : 1;
                grmode();
                abaut();
                do {
                    rest(5);
                    if (NeedsPoll) poll_keyboard();
                } while (key[__allegro_KEY_ENTER]);
            }
        } while ((!key[syskeys[1]]) && (!key[__allegro_KEY_ESC]) && (!key[syskeys[0]]));
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[1]]);
        init_sound_stream();
    }
    if (key[syskeys[5]]) {
        if (savestate(app_data.statefile)==0) {
            display_msg("Savefile saved.",5);
        }
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[5]]);
    }
    if (key[syskeys[6]]) {
        int stateError;
        if ((stateError=loadstate(app_data.statefile))==0) {
            display_msg("Savefile loaded.",5);
        } else if (stateError>=199) {
            if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5);
            else if (stateError==200+1) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5);
            else if (stateError==200+2) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5);
            else if (stateError==200+3) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5);
            else if (stateError==200+4) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5);
            else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5);
        }
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[6]]);
    }
    if (key[syskeys[2]]) key_debug=1;
    if (key[syskeys[3]]) {
        init_cpu();
        init_roms();
        init_vpp();
        clearscr();
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[syskeys[3]]);
    }
    if (key[syskeys[7]]) {
        set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);
    }
    if (key[syskeys[4]]) {
        struct BITMAP *bmp;
        struct RGB pal[256];
        char *p;
        static char name[1024];
        static int scshot_counter = 0;
        if (strlen(app_data.scshot)>0){
            if ((p=strchr(app_data.scshot,'@'))) {
                *p = 0;
                sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1);
                *p = '@';
            } else {
                strcpy(name, app_data.scshot);
            }
            get_palette(pal);
            bmp = create_sub_bitmap(screen, 0, 0, (gfx_driver ? gfx_driver->w : 0), (gfx_driver ? gfx_driver->h : 0));
            save_bitmap(name, bmp, pal);
            destroy_bitmap(bmp);
            do {
                rest(5);
                if (NeedsPoll) poll_keyboard();
            } while (key[syskeys[4]]);
        }
    }
    if (key[__allegro_KEY_ALT] && key[__allegro_KEY_ENTER]) {
        app_data.fullscreen = app_data.fullscreen ? 0 : 1;
        grmode();
        do {
            rest(5);
            if (NeedsPoll) poll_keyboard();
        } while (key[__allegro_KEY_ENTER]);
    }
}

variable_types: stateError int

variable_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; } *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH { short w; unsigned char dat[]; } *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D { int x; int u; int c; } *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f { float x; float u; int c; } *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); } *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; } *

variable_types: struct RGB { unsigned char r; unsigned char filler; } [256]

variable_types:
p
char *

user_defined_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; }

user_defined_types: struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); }


keyjoy

decompiled_code:
char __fastcall keyjoy(unsigned int a1)
{
char result; // al

result = -1;
if ( a1 <= 1 )
{
if ( NeedsPoll )
poll_keyboard();
result = (key[joykeys[5 * a1]] == 0) - 2;
if ( key[joykeys[5 * a1 + 1]] )
result &= 0xFBu;
if ( key[joykeys[5 * a1 + 2]] )
result &= 0xF7u;
if ( key[joykeys[5 * a1 + 3]] )
result &= 0xFDu;
if ( key[joykeys[5 * a1 + 4]] )
result &= 0xEFu;
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(unsigned int a1)
{
char result; // al

result = -1;
if ( a1 <= 1 )
{
if ( NeedsPoll )
poll_keyboard();
result = (key[joykeys[5 * a1]] == 0) - 2;
if ( key[joykeys[5 * a1 + 1]] )
result &= 0xFBu;
if ( key[joykeys[5 * a1 + 2]] )
result &= 0xF7u;
if ( key[joykeys[5 * a1 + 3]] )
result &= 0xFDu;
if ( key[joykeys[5 * a1 + 4]] )
result &= 0xEFu;
}
return result;
}

original_code:
Byte keyjoy(int jn){
    Byte d;
    d=0xFF;
    if ((jn>=0) && (jn<=1)){
        if (NeedsPoll) poll_keyboard();
        if (key[joykeys[jn][0]]) d &= 0xFE;
        if (key[joykeys[jn][1]]) d &= 0xFB;
        if (key[joykeys[jn][2]]) d &= 0xF7;
        if (key[joykeys[jn][3]]) d &= 0xFD;
        if (key[joykeys[jn][4]]) d &= 0xEF;
    }
    return d;
}

canonical_original_code:
unsigned char keyjoy(int jn){
    unsigned char d;
    d=0xFF;
    if ((jn>=0) && (jn<=1)){
        if (NeedsPoll) poll_keyboard();
        if (key[joykeys[jn][0]]) d &= 0xFE;
        if (key[joykeys[jn][1]]) d &= 0xFB;
        if (key[joykeys[jn][2]]) d &= 0xF7;
        if (key[joykeys[jn][3]]) d &= 0xFD;
        if (key[joykeys[jn][4]]) d &= 0xEF;
    }
    return d;
}

variable_types: jn int

variable_types:
d
unsigned char

return_type: unsigned char


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

key_done = 0;
key_debug = 0;
install_keyboard();
new_int = 1;
result = keyboard_needs_poll();
NeedsPoll = result;
return result;
}

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

key_done = 0;
key_debug = 0;
install_keyboard();
new_int = 1;
result = keyboard_needs_poll();
NeedsPoll = result;
return result;
}

original_code:
void init_keyboard(void){
    key_done=0;
    key_debug=0;
    install_keyboard();
    new_int=1;
    NeedsPoll = keyboard_needs_poll();
}

canonical_original_code:
void init_keyboard(){
    key_done=0;
    key_debug=0;
    install_keyboard();
    new_int=1;
    NeedsPoll = keyboard_needs_poll();
}


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

result = remove_keyboard();
new_int = 0;
return result;
}

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

result = remove_keyboard();
new_int = 0;
return result;
}

original_code:
void Set_Old_Int9(void){
   remove_keyboard();
   new_int=0;
}

canonical_original_code:
void Set_Old_Int9(){
   remove_keyboard();
   new_int=0;
}


original_code:
int get_score(int scoretype, int scoreaddress)
{
 int score=0;
 if (scoretype!=0)
 {
  int position;
  int i;
  Byte *RAM;
  int count = scoretype%10;
  int direction = ((scoretype/10)%10)==1?1:-1;
  float valuetype = (float) (3-((scoretype/100)%10))/2;
  int ramtype = scoretype/1000;
  position = scoreaddress+ (direction==1?0:(count*valuetype-1));
  RAM = ramtype==1?extRAM:intRAM;
  for(i=0;i<count;i++)
  {
   score = score*10+((RAM[position+(int)(valuetype*i*direction)]>>(((i+1)%2)*4)*(abs((int) ((valuetype-1)*2))))&15);
  }
 }
 return(score);
}

canonical_original_code:
int get_score(int scoretype, int scoreaddress)
{
 int score = 0;
 if (scoretype!=0)
 {
  int position;
  int i;
  unsigned char *RAM;
  int count = scoretype%10;
  int direction = ((scoretype/10)%10)==1?1:-1;
  float valuetype = (float) (3-((scoretype/100)%10))/2;
  int ramtype = scoretype/1000;
  position = scoreaddress+ (direction==1?0:(count*valuetype-1));
  RAM = ramtype==1?extRAM:intRAM;
  for(i=0;i<count;i++)
  {
   score = score*10+((RAM[position+(int)(valuetype*i*direction)]>>(((i+1)%2)*4)*(abs((int) ((valuetype-1)*2))))&15);
  }
 }
 return(score);
}

variable_types: scoretype int

variable_types: scoreaddress int

variable_types: score int

variable_types: position int

variable_types:
RAM
unsigned char *

variable_types: count int

variable_types: direction int

variable_types: valuetype float

variable_types: ramtype int


power

decompiled_code:
__int64 __fastcall power(unsigned int a1, int a2)
{
unsigned int v2; // edx
int v3; // esi
int v4; // eax

v2 = 1;
if ( a2 )
{
if ( a2 <= 1 )
{
v2 = a1;
}
else
{
v3 = a2 + 1;
v2 = a1;
v4 = 2;
do
{
v2 *= a1;
++v4;
}
while ( v4 != v3 );
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
unsigned int v2; // edx
int v3; // esi
int v4; // eax

v2 = 1;
if ( a2 )
{
if ( a2 <= 1 )
{
v2 = a1;
}
else
{
v3 = a2 + 1;
v2 = a1;
v4 = 2;
do
{
v2 *= a1;
++v4;
}
while ( v4 != v3 );
}
}
return v2;
}

original_code:
int power(int base, int higher)
{
 if (higher==0) {
  return(1);
 } else if (higher==1) {
  return(base);
 } else {
  int i;
  int value=base;
  for (i=2;i<=higher;i++)
  {
   value = value*base;
  }
  return(value);
 }
}

canonical_original_code:
int power(int base, int higher)
{
 if (higher==0) {
  return(1);
 } else if (higher==1) {
  return(base);
 } else {
  int i;
  int value = base;
  for (i=2;i<=higher;i++)
  {
   value = value*base;
  }
  return(value);
 }
}

variable_types: base int

variable_types: higher int

variable_types: i int

variable_types: value int


original_code:
void set_score(int scoretype, int scoreaddress, int score)
{
 if (scoretype!=0 && score>0)
 {
  int position;
  int i;
  Byte *RAM;
  int digit;
  int count = scoretype%10;
  int direction = ((scoretype/10)%10)==1?-1:1;
  float valuetype = (float) (3-((scoretype/100)%10))/2;
  int ramtype = scoretype/1000;
  position = scoreaddress+ (direction==1?0:(count*valuetype-1));
  RAM = ramtype==1?extRAM:intRAM;
  for(i=count-1;i>=0;i--)
  {
   digit = score / power(10,i);
   RAM[position+(int)(valuetype*i*direction)]=((valuetype==0.5)&&(i%2==0))?(RAM[position+(int)(valuetype*i*direction)]<<4)+digit:digit;
   score = score - digit*power(10,i);
  }
 }
}

canonical_original_code:
void set_score(int scoretype, int scoreaddress, int score)
{
 if (scoretype!=0 && score>0)
 {
  int position;
  int i;
  unsigned char *RAM;
  int digit;
  int count = scoretype%10;
  int direction = ((scoretype/10)%10)==1?-1:1;
  float valuetype = (float) (3-((scoretype/100)%10))/2;
  int ramtype = scoretype/1000;
  position = scoreaddress+ (direction==1?0:(count*valuetype-1));
  RAM = ramtype==1?extRAM:intRAM;
  for(i=count-1;i>=0;i--)
  {
   digit = score / power(10,i);
   RAM[position+(int)(valuetype*i*direction)]=((valuetype==0.5)&&(i%2==0))?(RAM[position+(int)(valuetype*i*direction)]<<4)+digit:digit;
   score = score - digit*power(10,i);
  }
 }
}

variable_types: digit int


original_code:
void audio_process(unsigned char *buffer){
 unsigned long aud_data;
 int volume, re_circ, noise, enabled, intena, period, pnt, cnt, rndbit, pos;
 aud_data = (VDCwrite[0xA9] | (VDCwrite[0xA8] << 8) | (VDCwrite[0xA7] << 16));
 intena = VDCwrite[0xA0] & 0x04;
 pnt = cnt = 0;
 noise = VDCwrite[0xAA] & 0x10;
 enabled = VDCwrite[0xAA] & 0x80;
 rndbit = (enabled && noise) ? (rand()%2) : 0;
 while (pnt < 1056) {
  pos = (tweakedaudio) ? (pnt/3) : (500 -1);
  volume = AudioVector[pos] & 0x0F;
  enabled = AudioVector[pos] & 0x80;
  period = (AudioVector[pos] & 0x20) ? 11 : 44;
  re_circ = AudioVector[pos] & 0x40;
  buffer[pnt++] = (enabled) ? ((aud_data & 0x01)^rndbit) * (0x10 * volume) : 0;
  cnt++;
  if (cnt >= period) {
   cnt=0;
   aud_data = (re_circ) ? ((aud_data >> 1) | ((aud_data & 1) << 23)) : (aud_data >> 1);
   rndbit = (enabled && noise) ? (rand()%2) : 0;
   if (enabled && intena && (!sound_IRQ)) {
    sound_IRQ = 1;
    ext_IRQ();
   }
  }
 }
 if (app_data.filter) filter(buffer, 1056);
}

canonical_original_code:
void audio_process(unsigned char *buffer){
 unsigned long aud_data;
 int volume; int re_circ; int noise; int enabled; int intena; int period; int pnt; int cnt; int rndbit; int pos;
 aud_data = (VDCwrite[0xA9] | (VDCwrite[0xA8] << 8) | (VDCwrite[0xA7] << 16));
 intena = VDCwrite[0xA0] & 0x04;
 pnt = cnt = 0;
 noise = VDCwrite[0xAA] & 0x10;
 enabled = VDCwrite[0xAA] & 0x80;
 rndbit = (enabled && noise) ? (rand()%2) : 0;
 while (pnt < 1056) {
  pos = (tweakedaudio) ? (pnt/3) : (500 -1);
  volume = AudioVector[pos] & 0x0F;
  enabled = AudioVector[pos] & 0x80;
  period = (AudioVector[pos] & 0x20) ? 11 : 44;
  re_circ = AudioVector[pos] & 0x40;
  buffer[pnt++] = (enabled) ? ((aud_data & 0x01)^rndbit) * (0x10 * volume) : 0;
  cnt++;
  if (cnt >= period) {
   cnt=0;
   aud_data = (re_circ) ? ((aud_data >> 1) | ((aud_data & 1) << 23)) : (aud_data >> 1);
   rndbit = (enabled && noise) ? (rand()%2) : 0;
   if (enabled && intena && (!sound_IRQ)) {
    sound_IRQ = 1;
    ext_IRQ();
   }
  }
 }
 if (app_data.filter) filter(buffer, 1056);
}

variable_types:
buffer
unsigned char *

variable_types: volume int

variable_types: noise int

variable_types: enabled int

variable_types: intena int

variable_types: period int

variable_types: pnt int

variable_types: cnt int

variable_types: rndbit int

variable_types: pos int


decompiled_code:
void update_audio()
{
void *v0; // rax
const void *v1; // rbx

if ( app_data[7] )
{
v0 = (void *)get_audio_stream_buffer(stream);
v1 = v0;
if ( v0 )
{
audio_process(v0);
if ( sndlog )
fwrite(v1, 1uLL, 0x420uLL, sndlog);
free_audio_stream_buffer(stream);
}
}
}

canonical_decompiled_code:
void func2()
{
void *v0; // rax
const void *v1; // rbx

if ( app_data[7] )
{
v0 = (void *)get_audio_stream_buffer(stream);
v1 = v0;
if ( v0 )
{
func1(v0);
if ( sndlog )
fwrite(v1, 1uLL, 0x420uLL, sndlog);
free_audio_stream_buffer(stream);
}
}
}

original_code:
void update_audio(void) {
 unsigned char *p;
 if (app_data.sound_en) {
  p = (unsigned char *)get_audio_stream_buffer(stream);
  if (p) {
   audio_process(p);
   if (sndlog) fwrite(p,1,1056,sndlog);
   free_audio_stream_buffer(stream);
  }
    }
}

canonical_original_code:
void update_audio() {
 unsigned char *p;
 if (app_data.sound_en) {
  p = (unsigned char *)get_audio_stream_buffer(stream);
  if (p) {
   audio_process(p);
   if (sndlog) fwrite(p,1,1056,sndlog);
   free_audio_stream_buffer(stream);
  }
    }
}

variable_types:
p
unsigned char *


decompiled_code:
void init_sound_stream()
{
int v0; // eax
__int64 v1; // r8

if ( app_data[7] )
{
v0 = 255 * app_data[13];
if ( app_data[17] )
v1 = (1374389535LL * v0) >> 37;
else
v1 = (1374389535LL * v0) >> 38;
stream = play_audio_stream(1056LL, 8LL, 0LL, 44100LL, (unsigned int)(v1 - (v0 >> 31)), 128LL);
if ( !stream )
{
puts("Error creating audio stream!");
app_data[7] = 0;
}
flt_b = 0LL;
flt_a = 0LL;
flt_prv = 0;
}
}

canonical_decompiled_code:
void func3()
{
int v0; // eax
__int64 v1; // r8

if ( app_data[7] )
{
v0 = 255 * app_data[13];
if ( app_data[17] )
v1 = (1374389535LL * v0) >> 37;
else
v1 = (1374389535LL * v0) >> 38;
stream = play_audio_stream(1056LL, 8LL, 0LL, 44100LL, (unsigned int)(v1 - (v0 >> 31)), 128LL);
if ( !stream )
{
puts("Error creating audio stream!");
app_data[7] = 0;
}
flt_b = 0LL;
flt_a = 0LL;
flt_prv = 0;
}
}

original_code:
void init_sound_stream(void){
 int vol;
 if (app_data.sound_en){
  if (app_data.filter)
   vol = (255*app_data.svolume)/100;
  else
   vol = (255*app_data.svolume)/200;
  stream = play_audio_stream(1056,8,0,44100,vol,128);
  if (!stream) {
   printf("Error creating audio stream!\n");
   app_data.sound_en=0;
  }
  flt_a = flt_b = 0.0;
  flt_prv = 0;
 }
}

canonical_original_code:
void init_sound_stream(){
 int vol;
 if (app_data.sound_en){
  if (app_data.filter)
   vol = (255*app_data.svolume)/100;
  else
   vol = (255*app_data.svolume)/200;
  stream = play_audio_stream(1056,8,0,44100,vol,128);
  if (!stream) {
   printf("Error creating audio stream!\n");
   app_data.sound_en=0;
  }
  flt_a = flt_b = 0.0;
  flt_prv = 0;
 }
}

variable_types: vol int


decompiled_code:
void init_audio()
{
_BYTE *v0; // rax

sound_IRQ = 0;
if ( app_data[12] | app_data[7] )
{
puts("Initializing sound system...");
if ( (unsigned int)install_sound(0xFFFFFFFFLL, 0LL, 0LL) )
{
printf(" ERROR: could not initialize sound card\n %s\n", (const char *)&allegro_error);
puts(" Sound system disabled");
app_data[7] = 0;
app_data[12] = 0;
}
else
{
v0 = *(_BYTE **)(digi_driver + 8LL);
if ( v0 && *v0 )
{
puts(" Sound system initialized ok");
printf(" Sound driver [%s] detected\n", *(const char **)(digi_driver + 8LL));
set_volume(0xFFFFFFFFLL, 0xFFFFFFFFLL);
init_sound_stream();
}
else
{
puts(" ERROR: could not initialize sound card");
puts(" Sound system disabled");
app_data[7] = 0;
app_data[12] = 0;
}
}
sndlog = 0LL;
}
else
{
sndlog = 0LL;
}
}

canonical_decompiled_code:
void func4()
{
_BYTE *v0; // rax

sound_IRQ = 0;
if ( app_data[12] | app_data[7] )
{
puts("Initializing sound system...");
if ( (unsigned int)install_sound(0xFFFFFFFFLL, 0LL, 0LL) )
{
printf(" ERROR: could not initialize sound card\n %s\n", (const char *)&allegro_error);
puts(" Sound system disabled");
app_data[7] = 0;
app_data[12] = 0;
}
else
{
v0 = *(_BYTE **)(digi_driver + 8LL);
if ( v0 && *v0 )
{
puts(" Sound system initialized ok");
printf(" Sound driver [%s] detected\n", *(const char **)(digi_driver + 8LL));
set_volume(0xFFFFFFFFLL, 0xFFFFFFFFLL);
func3();
}
else
{
puts(" ERROR: could not initialize sound card");
puts(" Sound system disabled");
app_data[7] = 0;
app_data[12] = 0;
}
}
sndlog = 0LL;
}
else
{
sndlog = 0LL;
}
}

original_code:
void init_audio(void) {
 int i;
 sound_IRQ=0;
 if ((app_data.sound_en) || (app_data.voice)) {
  printf("Initializing sound system...\n");
  i = install_sound(-1, 0, ((void *)0));
  if (i != 0) {
     printf("  ERROR: could not initialize sound card\n   %s\n",allegro_error);
     printf("  Sound system disabled\n");
     app_data.sound_en = 0;
     app_data.voice = 0;
  }
  else {
   if (digi_driver->name && (strlen(digi_driver->name)>0)){
    printf("  Sound system initialized ok\n");
    printf("  Sound driver [%s] detected\n",digi_driver->name);
    set_volume(-1,-1);
    init_sound_stream();
   } else {
    printf("  ERROR: could not initialize sound card\n");
    printf("  Sound system disabled\n");
    app_data.sound_en = 0;
    app_data.voice = 0;
   }
  }
 }
 sndlog = ((void *)0);
}

canonical_original_code:
void init_audio() {
 int i;
 sound_IRQ=0;
 if ((app_data.sound_en) || (app_data.voice)) {
  printf("Initializing sound system...\n");
  i = install_sound(-1, 0, ((void *)0));
  if (i != 0) {
     printf("  ERROR: could not initialize sound card\n   %s\n",allegro_error);
     printf("  Sound system disabled\n");
     app_data.sound_en = 0;
     app_data.voice = 0;
  }
  else {
   if (digi_driver->name && (strlen(digi_driver->name)>0)){
    printf("  Sound system initialized ok\n");
    printf("  Sound driver [%s] detected\n",digi_driver->name);
    set_volume(-1,-1);
    init_sound_stream();
   } else {
    printf("  ERROR: could not initialize sound card\n");
    printf("  Sound system disabled\n");
    app_data.sound_en = 0;
    app_data.voice = 0;
   }
  }
 }
 sndlog = ((void *)0);
}


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

if ( app_data[7] )
{
if ( stream )
{
result = stop_audio_stream();
stream = 0LL;
}
}
return result;
}

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

if ( app_data[7] )
{
if ( stream )
{
result = stop_audio_stream();
stream = 0LL;
}
}
return result;
}

original_code:
void mute_audio(void){
 if (app_data.sound_en && stream){
  stop_audio_stream(stream);
  stream=((void *)0);
 }
}

canonical_original_code:
void mute_audio(){
 if (app_data.sound_en && stream){
  stop_audio_stream(stream);
  stream=((void *)0);
 }
}


decompiled_code:
int close_audio()
{
int result; // eax

if ( app_data[7] && stream )
result = stop_audio_stream();
if ( sndlog )
result = fclose(sndlog);
app_data[7] = 0;
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax

if ( app_data[7] && stream )
result = stop_audio_stream();
if ( sndlog )
result = fclose(sndlog);
app_data[7] = 0;
return result;
}

original_code:
void close_audio(void) {
 if (app_data.sound_en && stream) {
  stop_audio_stream(stream);
 }
 if (sndlog) fclose(sndlog);
 app_data.sound_en=0;
}

canonical_original_code:
void close_audio() {
 if (app_data.sound_en && stream) {
  stop_audio_stream(stream);
 }
 if (sndlog) fclose(sndlog);
 app_data.sound_en=0;
}


gettimeticks

decompiled_code:
__int64 gettimeticks()
{
clock_t v0; // rbx
struct tms v2; // [rsp+0h] [rbp-28h] BYREF

v0 = times(&v2);
return 10000 * v0 / sysconf(2);
}

canonical_decompiled_code:
__int64 func0()
{
clock_t v0; // rbx
struct tms v2; // [rsp+0h] [rbp-28h] BYREF

v0 = times(&v2);
return 10000 * v0 / sysconf(2);
}

original_code:
long gettimeticks(void){
 struct tms t;
 return (long)((((long long)times(&t))*10000)/sysconf(_SC_CLK_TCK));
}

canonical_original_code:
long gettimeticks(){
 struct tms t;
 return (long)((((long long)times(&t))*10000)/sysconf(_SC_CLK_TCK));
}

variable_types: struct tms { long tms_utime; long tms_stime; long tms_cutime; long tms_cstime; }

return_type: long


decompiled_code:
__int64 __fastcall crc32_buf(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
unsigned int v3; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = -1;
do
v3 = crc32tab[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( v2 != a1 );
}
else
{
v3 = -1;
}
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
unsigned int v3; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = -1;
do
v3 = crc32tab[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( v2 != a1 );
}
else
{
v3 = -1;
}
return ~v3;
}

original_code:
uint32_t crc32_buf(const void *buf, size_t size)
{
    uint32_t crc = ~0;
    const uint8_t *p = buf;
    while (size--) crc = (crc >> 8) ^ crc32tab[(crc ^ (*p++)) & 0xFF];
    return ~crc;
}

canonical_original_code:
unsigned int crc32_buf(void *buf, unsigned long size)
{
    unsigned int crc = ~0;
    unsigned char *p = buf;
    while (size--) crc = (crc >> 8) ^ crc32tab[(crc ^ (*p++)) & 0xFF];
    return ~crc;
}

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types:
crc
unsigned int

return_type: unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v4; // r14
char *v5; // r13
char *v6; // rbp
__int64 v7; // r12
__int64 v8; // r13
bool v9; // r14
const char *v10; // rdi
void *v11; // rax
void (__fastcall *v12)(void *, __int64, __int64); // r15
const char *v13; // rdi
int v14; // ebx
void *v15; // rdi
void *v17; // rbx
struct timespec v18; // [rsp+10h] [rbp-58h] BYREF
struct timespec tp; // [rsp+20h] [rbp-48h] BYREF

getenv("DEBUG");
v4 = getenv("USE_MMAP") != 0LL;
v5 = getenv("XRES");
v6 = getenv("YRES");
v7 = 960LL;
if ( v5 )
v7 = strtol(v5, 0LL, 10);
v8 = 960LL;
if ( v6 )
v8 = strtol(v6, 0LL, 10);
v9 = argc > 2 || v4;
v10 = 0LL;
if ( argc > 1 )
v10 = argv[1];
v11 = dlopen(v10, 2);
v12 = (void (__fastcall *)(void *, __int64, __int64))dlsym(v11, "rgbfunc");
clock_gettime(0, &tp);
if ( !v9 )
{
v17 = malloc(6 * v8 * v7);
v12(v17, v7, v8);
write(1, v17, 6 * v8 * v7);
goto LABEL_12;
}
v13 = 0LL;
if ( argc > 2 )
v13 = argv[2];
v14 = open(v13, 66, 420LL);
ftruncate(v14, 6 * v8 * v7);
v15 = mmap(0LL, 6 * v8 * v7, 3, 1, v14, 0LL);
if ( v15 != (void *)-1LL )
{
v12(v15, v7, v8);
LABEL_12:
clock_gettime(0, &v18);
fprintf(
stderr,
"%s: Elapsed time, %g seconds.\n",
"main",
(double)SLODWORD(v18.tv_nsec) / 1000000000.0
+ (double)SLODWORD(v18.tv_sec)
- ((double)SLODWORD(tp.tv_nsec) / 1000000000.0
+ (double)SLODWORD(tp.tv_sec)));
return 0;
}
perror("mmap");
return -1;
}

original_code:
int main(int argc, char *argv[]) {
  long int debug = getenv("DEBUG") != ((void *)0);
  long int use_mmap = getenv("USE_MMAP") != ((void *)0);
  char *env_XRES = getenv("XRES");
  char *env_YRES = getenv("YRES");
  u_int16_t mono;
  long int xres = env_XRES != ((void *)0) ? strtol(env_XRES,((void *)0),10) : 960, yres = env_YRES != ((void *)0) ? strtol(env_YRES,((void *)0),10) : 960;
  size_t img_sz = xres*yres*sizeof(u_int16_t)*3;
  u_int16_t *rgb;
  void *handle;
  int (*rgbfunc)(u_int16_t *rgb, long int xres, long int yres);
  struct timespec before, after;
  use_mmap |= (argc>2);
  handle = dlopen(argc>1?argv[1]:((void *)0), 0x00002);
  rgbfunc = dlsym(handle, "rgbfunc");
  clock_gettime(0, &before);
  if (!use_mmap) {
    rgb = malloc(img_sz);
    rgbfunc(rgb, xres, yres);
    write(1,rgb,img_sz);
  }
  else {
    mode_t mode = 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3);
    char *filename = argc>2 ? argv[2] : ((void *)0);
    int fd = open(filename,02|0100,mode);
    int ftruncate_retval = ftruncate(fd,img_sz);
    void *m;
    m = mmap(((void *)0), img_sz, 0x1 | 0x2, 0x01, fd, 0);
    if (m==((void *) -1)) {
      perror("mmap");
      return -1;
    }
    rgb = (u_int16_t*) m;
    rgbfunc(rgb, xres, yres);
  }
  clock_gettime(0, &after);
  fprintf(stderr, "%s: Elapsed time, %g seconds.\n", __FUNCTION__, (after.tv_sec + after.tv_nsec / 1000000000.0) - (before.tv_sec + before.tv_nsec / 1000000000.0));
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  long debug = getenv("DEBUG") != ((void *)0);
  long use_mmap = getenv("USE_MMAP") != ((void *)0);
  char *env_XRES = getenv("XRES");
  char *env_YRES = getenv("YRES");
  unsigned int mono;
  long xres = env_XRES != ((void *)0) ? strtol(env_XRES,((void *)0),10) : 960; long yres = env_YRES != ((void *)0) ? strtol(env_YRES,((void *)0),10) : 960;
  unsigned long img_sz = xres*yres*sizeof(u_int16_t)*3;
  unsigned int *rgb;
  void *handle;
  int (*rgbfunc)(unsigned int *rgb, long xres, long yres);
  struct timespec before; struct timespec after;
  use_mmap |= (argc>2);
  handle = dlopen(argc>1?argv[1]:((void *)0), 0x00002);
  rgbfunc = dlsym(handle, "rgbfunc");
  clock_gettime(0, &before);
  if (!use_mmap) {
    rgb = malloc(img_sz);
    rgbfunc(rgb, xres, yres);
    write(1,rgb,img_sz);
  }
  else {
    unsigned int mode = 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3);
    char *filename = argc>2 ? argv[2] : ((void *)0);
    int fd = open(filename,02|0100,mode);
    int ftruncate_retval = ftruncate(fd,img_sz);
    void *m;
    m = mmap(((void *)0), img_sz, 0x1 | 0x2, 0x01, fd, 0);
    if (m==((void *) -1)) {
      perror("mmap");
      return -1;
    }
    rgb = (unsigned int *) m;
    rgbfunc(rgb, xres, yres);
  }
  clock_gettime(0, &after);
  fprintf(stderr, "%s: Elapsed time, %g seconds.\n", __FUNCTION__, (after.tv_sec + after.tv_nsec / 1000000000.0) - (before.tv_sec + before.tv_nsec / 1000000000.0));
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: debug long

variable_types:
mono
unsigned int

variable_types: xres long

variable_types: yres long

variable_types:
rgb
unsigned int *

variable_types:
handle
void *

variable_types: int (*)(unsigned int *rgb, long xres, long yres)

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types:
mode
unsigned int

variable_types:
filename
char *

variable_types: fd int

variable_types:
m
void *


repo: lvella/libestream

original_code:
static uint32_t
lfsr_step(sosemanuk_state *state)
{
  uint32_t *s = state->s;
  uint8_t t = state->t;
  uint32_t st0 = s[t];
  uint32_t st3 = s[(t+3)%10];
  s[t] = s[(t+9)%10]
    ^ (st3 >> 8) ^ div_a[st3 & 0xff]
    ^ (st0 << 8) ^ mul_a[st0 >> 24];
  state->t = (t+1) % 10;
  return st0;
}

canonical_original_code:
static unsigned int lfsr_step(struct sosemanuk_state *state)
{
  unsigned int *s = state->s;
  unsigned char t = state->t;
  unsigned int st0 = s[t];
  unsigned int st3 = s[(t+3)%10];
  s[t] = s[(t+9)%10]
    ^ (st3 >> 8) ^ div_a[st3 & 0xff]
    ^ (st0 << 8) ^ mul_a[st0 >> 24];
  state->t = (t+1) % 10;
  return st0;
}

variable_types: struct sosemanuk_state { unsigned int r[2]; unsigned int s[10]; unsigned char t; } *

variable_types:
s
unsigned int *

variable_types:
t
unsigned char


canonical_original_code:
static inline void sbox_apply(unsigned char sbox_idx, unsigned int *in, unsigned int *out)
{
  switch(sbox_idx)
    {
    case 0:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t6; register unsigned int t7; register unsigned int t8; register unsigned int t10; register unsigned int t11; register unsigned int t12; register unsigned int t14;
 t1 = in[0] ^ in[3]; t2 = in[0] & in[3]; t3 = in[2] ^ t1; t4 = in[1] ^ t3; out[3] = t2 ^ t4; t6 = in[1] & t1; t7 = in[0] ^ t6; t8 = in[2] | t7; out[2] = t4 ^ t8; t10 = ~t3; t11 = t3 ^ t7; t12 = out[3] & t11; out[1] = t10 ^ t12; t14 = ~t7; out[0] = t12 ^ t14;
 break;
      }
    case 1:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t7; register unsigned int t8; register unsigned int t9; register unsigned int t11; register unsigned int t13;
 t1 = ~in[0]; t2 = in[1] ^ t1; t3 = in[0] | t2; t4 = in[3] | t2; t5 = in[2] ^ t3; out[2] = in[3] ^ t5; t7 = in[1] ^ t4; t8 = t2 ^ out[2]; t9 = t5 & t7; out[3] = t8 ^ t9; t11 = t5 ^ t7; out[1] = out[3] ^ t11; t13 = t8 & t11; out[0] = t5 ^ t13;
 break;
      }
    case 2:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t5; register unsigned int t6; register unsigned int t7; register unsigned int t9; register unsigned int t10; register unsigned int t11; register unsigned int t13; register unsigned int t14; register unsigned int t15;
 t1 = ~in[0]; t2 = in[1] ^ in[3]; t3 = in[2] & t1; out[0] = t2 ^ t3; t5 = in[2] ^ t1; t6 = in[2] ^ out[0]; t7 = in[1] & t6; out[3] = t5 ^ t7; t9 = in[3] | t7; t10 = out[0] | t5; t11 = t9 & t10; out[2] = in[0] ^ t11; t13 = in[3] | t1; t14 = t2 ^ out[3]; t15 = out[2] ^ t13; out[1] = t14 ^ t15;
 break;
      }
    case 3:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t6; register unsigned int t8; register unsigned int t9; register unsigned int t10; register unsigned int t12; register unsigned int t14; register unsigned int t15;
 t1 = in[0] ^ in[1]; t2 = in[0] & in[2]; t3 = in[0] | in[3]; t4 = in[2] ^ in[3]; t5 = t1 & t3; t6 = t2 | t5; out[2] = t4 ^ t6; t8 = in[1] ^ t3; t9 = t6 ^ t8; t10 = t4 & t9; out[0] = t1 ^ t10; t12 = out[2] & out[0]; out[1] = t9 ^ t12; t14 = in[1] | in[3]; t15 = t4 ^ t12; out[3] = t14 ^ t15;
 break;
      }
    case 4:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t6; register unsigned int t7; register unsigned int t9; register unsigned int t10; register unsigned int t11; register unsigned int t13; register unsigned int t14;
 t1 = in[0] ^ in[3]; t2 = in[3] & t1; t3 = in[2] ^ t2; t4 = in[1] | t3; out[3] = t1 ^ t4; t6 = ~in[1]; t7 = t1 | t6; out[0] = t3 ^ t7; t9 = in[0] & out[0]; t10 = t1 ^ t6; t11 = t4 & t10; out[2] = t9 ^ t11; t13 = in[0] ^ t3; t14 = t10 & out[2]; out[1] = t13 ^ t14;
 break;
      }
    case 5:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t7; register unsigned int t8; register unsigned int t10; register unsigned int t11; register unsigned int t12; register unsigned int t14; register unsigned int t15;
 t1 = ~in[0]; t2 = in[0] ^ in[1]; t3 = in[0] ^ in[3]; t4 = in[2] ^ t1; t5 = t2 | t3; out[0] = t4 ^ t5; t7 = in[3] & out[0]; t8 = t2 ^ out[0]; out[1] = t7 ^ t8; t10 = t1 | out[0]; t11 = t2 | t7; t12 = t3 ^ t10; out[2] = t11 ^ t12; t14 = in[1] ^ t7; t15 = out[1] & t12; out[3] = t14 ^ t15;
 break;
      }
    case 6:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t7; register unsigned int t8; register unsigned int t9; register unsigned int t11; register unsigned int t13; register unsigned int t14;
 t1 = ~in[0]; t2 = in[0] ^ in[3]; t3 = in[1] ^ t2; t4 = t1 | t2; t5 = in[2] ^ t4; out[1] = in[1] ^ t5; t7 = t2 | out[1]; t8 = in[3] ^ t7; t9 = t5 & t8; out[2] = t3 ^ t9; t11 = t5 ^ t8; out[0] = out[2] ^ t11; t13 = ~t5; t14 = t3 & t11; out[3] = t13 ^ t14;
 break;
      }
    case 7:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t6; register unsigned int t8; register unsigned int t9; register unsigned int t11; register unsigned int t12; register unsigned int t14; register unsigned int t15;
 t1 = in[1] ^ in[2]; t2 = in[2] & t1; t3 = in[3] ^ t2; t4 = in[0] ^ t3; t5 = in[3] | t1; t6 = t4 & t5; out[1] = in[1] ^ t6; t8 = t3 | out[1]; t9 = in[0] & t4; out[3] = t1 ^ t9; t11 = t4 ^ t8; t12 = out[3] & t11; out[2] = t3 ^ t12; t14 = ~t11; t15 = out[3] & out[2]; out[0] = t14 ^ t15;
 break;
      }
    }
}

variable_types:
in
unsigned int *

variable_types:
out
unsigned int *