// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %r13
movslq %edi, %rbp
leaq 0x6b45(%rip), %rbx      # 0x904c
pushq $-0x1
popq %rdx
pushq $-0x2
popq %rax
pushq $0x1
popq %r14
pushq $0x2
popq %rcx
movl %ecx, 0x4(%rsp)
pushq $0x10
popq %rcx
movl %ecx, 0x8(%rsp)
movl $0x7d00, 0xc(%rsp)      # imm = 0x7D00
movq $0x0, 0x28(%rsp)
leaq 0x6acd(%rip), %r15      # 0x9004
movl %eax, 0x10(%rsp)
movl %eax, (%rsp)
movl %edx, %r12d
movl %edx, %eax
movq %rax, 0x20(%rsp)
cmpq %rbp, %r14
jge 0x263e
movq (%r13,%r14,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x2583
movzbl 0x1(%rdi), %eax
leal -0x62(%rax), %ecx
cmpl $0x11, %ecx
ja 0x258b
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
addq $0x2, %rdi
callq 0x2360
movl %eax, 0x8(%rsp)
movl %eax, 0x18(%rsp)
jmp 0x2586
movq %rdi, %rbx
incq %r14
jmp 0x2548
cmpl $0x4d, %eax
jne 0x2586
addq $0x2, %rdi
movq %rdi, 0x28(%rsp)
jmp 0x2586
andq $0x0, 0x30(%rsp)
addq $0x2, %rdi
leaq 0x30(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x22d0
movq %rax, %r12
movq 0x30(%rsp), %rdi
movq (%r13,%r14,8), %rax
addq $0x2, %rax
cmpq %rax, %rdi
jbe 0x2633
cmpb $0x2c, (%rdi)
pushq $-0x1
popq %rax
jne 0x2636
incq %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x22d0
movq %rax, 0x20(%rsp)
movl %r12d, %eax
jmp 0x2636
addq $0x2, %rdi
callq 0x2360
movl %eax, 0xc(%rsp)
movl %eax, 0x14(%rsp)
jmp 0x2586
addq $0x2, %rdi
callq 0x2360
movl %eax, 0x10(%rsp)
jmp 0x2586
addq $0x2, %rdi
callq 0x2360
movl %eax, (%rsp)
jmp 0x2586
addq $0x2, %rdi
callq 0x2360
movl %eax, 0x4(%rsp)
movl %eax, 0x1c(%rsp)
jmp 0x2586
pushq $-0x1
popq %rax
movl %eax, %r12d
jmp 0x2586
xorl %eax, %eax
cmpl $0x2, 0x4(%rsp)
setge %al
incl %eax
leaq 0x1c(%rsp), %rdx
movl %eax, (%rdx)
movl 0x8(%rsp), %ecx
sarl $0x3, %ecx
cmpl $0x2, %ecx
pushq $0x2
popq %rax
cmovll %ecx, %eax
shll $0x3, %eax
testl %ecx, %ecx
pushq $0x8
popq %rsi
cmovlel %esi, %eax
leaq 0x18(%rsp), %rcx
movl %eax, (%rcx)
movl $0xbb80, %eax           # imm = 0xBB80
movl 0xc(%rsp), %edi
cmpl %eax, %edi
cmovll %edi, %eax
cmpl $0x1f41, %eax           # imm = 0x1F41
movl $0x1f40, %edi           # imm = 0x1F40
cmovgel %eax, %edi
leaq 0x14(%rsp), %r8
movl %edi, (%r8)
movl 0x10(%rsp), %edi
xorl %r9d, %r9d
callq 0x2e92
testl %eax, %eax
jne 0x27da
movl (%rsp), %edi
movq 0x28(%rsp), %rsi
callq 0x65fa
testl %eax, %eax
jne 0x2801
movq 0xc8f2(%rip), %r15      # 0xefb8
movq (%r15), %r14
callq 0x2fdb
leaq 0x6b42(%rip), %rsi      # 0x9217
xorl %ebp, %ebp
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22f0
movq (%r15), %r14
callq 0x66f2
leaq 0x6b35(%rip), %rsi      # 0x9228
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22f0
movq (%r15), %rdi
movl 0x14(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %r8d
leaq 0x6b25(%rip), %rsi      # 0x923c
xorl %eax, %eax
callq 0x22f0
movq %rbx, %rdi
movl %r12d, %esi
movq 0x20(%rsp), %rdx
callq 0x28b9
callq 0x66cd
callq 0x2f9d
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2833
jmp 0x27d3
leaq 0x6903(%rip), %rdi      # 0x905d
callq 0x2350
pushq $0xa
popq %rdi
callq 0x22b0
leaq 0x6905(%rip), %rdi      # 0x9073
callq 0x2350
leaq 0x690b(%rip), %rdi      # 0x9085
callq 0x2350
leaq 0x6914(%rip), %rdi      # 0x909a
callq 0x2350
leaq 0x693a(%rip), %rdi      # 0x90cc
callq 0x2350
leaq 0x6959(%rip), %rdi      # 0x90f7
callq 0x2350
leaq 0x6980(%rip), %rdi      # 0x912a
callq 0x2350
leaq 0x69a2(%rip), %rdi      # 0x9158
callq 0x2350
leaq 0x69cb(%rip), %rdi      # 0x918d
callq 0x2350
leaq 0x69ec(%rip), %rdi      # 0x91ba
callq 0x2350
xorl %ebp, %ebp
jmp 0x2738
movq 0xc7f7(%rip), %rcx      # 0xefd8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x2e3c
leaq 0x69fe(%rip), %rsi      # 0x91f0
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22f0
jmp 0x282b
movq 0xc7d0(%rip), %rcx      # 0xefd8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x65ac
leaq 0x69e9(%rip), %rsi      # 0x9202
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22f0
callq 0x2f9d
pushq $0x1
popq %rbp
jmp 0x2738