// File: /workspace/github_c_makefile_star2_O3/jonof[P]jfaudiolib/src/test.c
// Function: main
int main(int argc, char ** argv)
{
    int status = 0;
    int FXDevice = ASS_AutoDetect;
    int MusicDevice = ASS_AutoDetect;
    int NumVoices = 8;
    int NumChannels = 2;
    int NumBits = 16;
    int MixRate = 32000;
    int arg = 0;
    int loopstart = -1, loopend = -1;
    void * initdata = 0;
    const char * musicinit = 0;
    const char * song = "samples/test.wav";

    for (arg = 1; arg < argc; arg++) {
        if (argv[arg][0] == '-') {
            if (argv[arg][1] == 'h') {
                puts("test [options] [song]");
                puts("");
                puts("-h     This text.");
                puts("-l     List drivers.");
                puts("-fn    Set specific FX device (n = device number)");
                puts("-cn    Set 'n' FX output channels (1 or 2)");
                puts("-bn    Set 'n' FX output bits-per-sample (8 or 16)");
                puts("-sx    Set 'n' FX sample rate (8000 to 48000)");
                puts("-mn    Set specific Music device (n = device number)");
                puts("-M...  Specify music device parameter string");
                puts("-rx,y  Loop FX from samples x to y (0,-1 loops fully)");
                return 0;
            } else if (argv[arg][1] == 'l') {
                listdevs();
                return 0;
            } else if (argv[arg][1] == 'f') {
                FXDevice = atoi(argv[arg] + 2);
            } else if (argv[arg][1] == 'c') {
                NumChannels = atoi(argv[arg] + 2);
            } else if (argv[arg][1] == 'b') {
                NumBits = atoi(argv[arg] + 2);
            } else if (argv[arg][1] == 's') {
                MixRate = atoi(argv[arg] + 2);
            } else if (argv[arg][1] == 'm') {
                MusicDevice = atoi(argv[arg] + 2);
            } else if (argv[arg][1] == 'M') {
                musicinit = argv[arg] + 2;
            } else if (argv[arg][1] == 'r') {
                char *comma = NULL;
                loopstart = (int)strtol(argv[arg] + 2, &comma, 10);
                if (comma > argv[arg] + 2 && *comma == ',')
                    loopend = (int)strtol(comma + 1, NULL, 10);
                else
                    loopstart = -1;
            }
        } else {
            song = argv[arg];
        }
    }

    NumChannels = bound(1, NumChannels, 2);
    NumBits = bound(1, (NumBits >> 3), 2) << 3;
    MixRate = bound(8000, MixRate, 48000);

#ifdef _WIN32
    initdata = win_gethwnd();
#endif

    status = FX_Init( FXDevice, NumVoices, &NumChannels, &NumBits, &MixRate, initdata );
    if (status != FX_Ok) {
        fprintf(stderr, "FX_Init error %s\n", FX_ErrorString(status));
        return 1;
    }
    
    status = MUSIC_Init(MusicDevice, musicinit);
    if (status != MUSIC_Ok) {
        fprintf(stderr, "MUSIC_Init error %s\n", MUSIC_ErrorString(status));
        FX_Shutdown();
        return 1;
    }

    fprintf(stdout, "FX driver is %s\n", FX_GetCurrentDriverName());
    fprintf(stdout, "Music driver is %s\n", MUSIC_GetCurrentDriverName());
    fprintf(stdout, "Format is %dHz %d-bit %d-channel\n", MixRate, NumBits, NumChannels);

    playsong(song, loopstart, loopend);

    MUSIC_Shutdown();
    FX_Shutdown();

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x1, %edi
jle 0x26ef
movq %rsi, %r12
movl %edi, %ebx
movl $0xfffffffe, 0x1c(%rsp) # imm = 0xFFFFFFFE
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x28(%rsp)
leaq 0x7a7b(%rip), %r14      # 0xa04c
movl $0x1, %r13d
movl $0x2, 0xc(%rsp)
movl $0x10, 0x10(%rsp)
movl $0x7d00, 0x18(%rsp)     # imm = 0x7D00
movq $0x0, 0x30(%rsp)
leaq 0x7a05(%rip), %r15      # 0xa004
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xfffffffe, 0x14(%rsp) # imm = 0xFFFFFFFE
movq (%r12,%r13,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x2639
movzbl 0x1(%rdi), %eax
leal -0x62(%rax), %ecx
cmpl $0x11, %ecx
ja 0x2649
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
addq $0x2, %rdi
callq 0x2350
movl %eax, 0x10(%rsp)
jmp 0x263c
movq %rdi, %r14
incq %r13
cmpq %r13, %rbx
jne 0x260c
jmp 0x2721
cmpl $0x4d, %eax
jne 0x263c
addq $0x2, %rdi
movq %rdi, 0x30(%rsp)
jmp 0x263c
movq $0x0, (%rsp)
addq $0x2, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x22c0
movq %rax, %rbp
movq (%rsp), %rdi
movq (%r12,%r13,8), %rax
addq $0x2, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rax, %rdi
jbe 0x26a6
cmpb $0x2c, (%rdi)
jne 0x26a6
incq %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x22c0
movq %rax, 0x28(%rsp)
movl %ebp, %ecx
movl %ecx, %ebp
jmp 0x263c
addq $0x2, %rdi
callq 0x2350
movl %eax, 0x18(%rsp)
jmp 0x263c
addq $0x2, %rdi
callq 0x2350
movl %eax, 0x14(%rsp)
jmp 0x263c
addq $0x2, %rdi
callq 0x2350
movl %eax, 0x1c(%rsp)
jmp 0x263c
addq $0x2, %rdi
callq 0x2350
movl %eax, 0xc(%rsp)
jmp 0x263c
movl $0x2, (%rsp)
movl $0x10, %eax
movl $0x7d00, %edx           # imm = 0x7D00
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq 0x793a(%rip), %r14      # 0xa04c
xorl %r15d, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
jmp 0x2765
xorl %eax, %eax
cmpl $0x2, 0xc(%rsp)
setge %al
incl %eax
movl 0x10(%rsp), %edx
sarl $0x3, %edx
movl %eax, (%rsp)
cmpl $0x2, %edx
movl $0x2, %ecx
cmovll %edx, %ecx
shll $0x3, %ecx
testl %edx, %edx
movl $0x8, %eax
cmovgl %ecx, %eax
movq 0x28(%rsp), %r13
movl 0x1c(%rsp), %ebx
movq 0x30(%rsp), %r15
movl 0x18(%rsp), %edx
movl 0x14(%rsp), %edi
leaq 0x24(%rsp), %rcx
movl %eax, (%rcx)
movl $0xbb80, %eax           # imm = 0xBB80
cmpl %eax, %edx
cmovll %edx, %eax
cmpl $0x1f41, %eax           # imm = 0x1F41
movl $0x1f40, %edx           # imm = 0x1F40
cmovgel %eax, %edx
leaq 0x20(%rsp), %r8
movl %edx, (%r8)
movq %rsp, %rdx
movl $0x8, %esi
xorl %r9d, %r9d
callq 0x2f19
testl %eax, %eax
jne 0x283e
movl %ebx, %edi
movq %r15, %rsi
callq 0x6b93
testl %eax, %eax
jne 0x2847
movq 0xd7fc(%rip), %r12      # 0xffb8
movq (%r12), %r15
callq 0x3085
leaq 0x7a4b(%rip), %rsi      # 0xa217
xorl %ebx, %ebx
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22e0
movq (%r12), %r15
callq 0x6caa
leaq 0x7a3d(%rip), %rsi      # 0xa228
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22e0
movq (%r12), %rdi
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %ecx
movl (%rsp), %r8d
leaq 0x7a2d(%rip), %rsi      # 0xa23c
xorl %eax, %eax
callq 0x22e0
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x296c
callq 0x6c85
callq 0x3042
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x23f0
jmp 0x284e
movl %eax, %edi
callq 0x2416
movl $0x1, %ebx
jmp 0x282d
callq 0x28e8
jmp 0x28e1
leaq 0x77f7(%rip), %rdi      # 0xa05d
callq 0x2340
movl $0xa, %edi
callq 0x22a0
leaq 0x77f7(%rip), %rdi      # 0xa073
callq 0x2340
leaq 0x77fd(%rip), %rdi      # 0xa085
callq 0x2340
leaq 0x7806(%rip), %rdi      # 0xa09a
callq 0x2340
leaq 0x782c(%rip), %rdi      # 0xa0cc
callq 0x2340
leaq 0x784b(%rip), %rdi      # 0xa0f7
callq 0x2340
leaq 0x7872(%rip), %rdi      # 0xa12a
callq 0x2340
leaq 0x7894(%rip), %rdi      # 0xa158
callq 0x2340
leaq 0x78bd(%rip), %rdi      # 0xa18d
callq 0x2340
leaq 0x78de(%rip), %rdi      # 0xa1ba
callq 0x2340
xorl %ebx, %ebx
jmp 0x282d