// File: /workspace/github_c_makefile_star2_O1/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
movl $0x2, 0x14(%rsp)
movl $0x10, 0x10(%rsp)
movl $0x7d00, 0xc(%rsp)      # imm = 0x7D00
cmpl $0x2, %edi
jl 0x26f1
movq %rsi, %r14
movl %edi, %ebp
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x20(%rsp)
leaq 0x7a75(%rip), %rbx      # 0xa04c
movl $0x1, %r15d
movq $0x0, 0x28(%rsp)
leaq 0x7a17(%rip), %r13      # 0xa004
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl $0xfffffffe, 0x8(%rsp)  # imm = 0xFFFFFFFE
movq (%r14,%r15,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x262b
movzbl 0x1(%rdi), %eax
leal -0x62(%rax), %ecx
cmpl $0x11, %ecx
ja 0x263b
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
addq $0x2, %rdi
callq 0x2340
movl %eax, 0x10(%rsp)
jmp 0x262e
movq %rdi, %rbx
incq %r15
cmpq %r15, %rbp
jne 0x25fd
jmp 0x2721
cmpl $0x4d, %eax
jne 0x262e
addq $0x2, %rdi
movq %rdi, 0x28(%rsp)
jmp 0x262e
movq $0x0, 0x30(%rsp)
addq $0x2, %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x22b0
movq 0x30(%rsp), %rdi
movq (%r14,%r15,8), %rcx
addq $0x2, %rcx
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
cmpq %rcx, %rdi
jbe 0x262e
cmpb $0x2c, (%rdi)
jne 0x262e
incq %rdi
xorl %esi, %esi
movl $0xa, %edx
movq %rax, 0x18(%rsp)
callq 0x22b0
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
movl %eax, 0x18(%rsp)
jmp 0x262e
addq $0x2, %rdi
callq 0x2340
movl %eax, 0xc(%rsp)
jmp 0x262e
addq $0x2, %rdi
callq 0x2340
movl %eax, 0x8(%rsp)
jmp 0x262e
addq $0x2, %rdi
callq 0x2340
movl %eax, %r12d
jmp 0x262e
addq $0x2, %rdi
callq 0x2340
movl %eax, 0x14(%rsp)
jmp 0x262e
leaq 0x7954(%rip), %rbx      # 0xa04c
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl $0xfffffffe, 0x8(%rsp)  # imm = 0xFFFFFFFE
movq $0x0, 0x28(%rsp)
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x20(%rsp)
xorl %eax, %eax
leaq 0x14(%rsp), %rdx
cmpl $0x2, (%rdx)
setge %al
incl %eax
movl %eax, (%rdx)
leaq 0x10(%rsp), %rcx
movl (%rcx), %eax
sarl $0x3, %eax
cmpl $0x2, %eax
movl $0x2, %esi
cmovll %eax, %esi
shll $0x3, %esi
testl %eax, %eax
movl $0x8, %eax
cmovlel %eax, %esi
movl %esi, (%rcx)
leaq 0xc(%rsp), %r8
movl (%r8), %eax
movl $0xbb80, %esi           # imm = 0xBB80
cmpl %esi, %eax
cmovll %eax, %esi
cmpl $0x1f41, %esi           # imm = 0x1F41
movl $0x1f40, %eax           # imm = 0x1F40
cmovgel %esi, %eax
movl %eax, (%r8)
movl 0x8(%rsp), %edi
movl $0x8, %esi
xorl %r9d, %r9d
callq 0x2f0f
testl %eax, %eax
jne 0x2837
movl %r12d, %edi
movq 0x28(%rsp), %rsi
callq 0x6b11
testl %eax, %eax
jne 0x2840
movq 0xd80a(%rip), %r12      # 0xffb8
movq (%r12), %r15
callq 0x3080
leaq 0x7a59(%rip), %rsi      # 0xa217
xorl %r14d, %r14d
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22d0
movq (%r12), %r15
callq 0x6c1f
leaq 0x7a4a(%rip), %rsi      # 0xa228
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22d0
movq (%r12), %rdi
movl 0xc(%rsp), %edx
movl 0x10(%rsp), %ecx
movl 0x14(%rsp), %r8d
leaq 0x7a39(%rip), %rsi      # 0xa23c
xorl %eax, %eax
callq 0x22d0
movq %rbx, %rdi
movl 0x18(%rsp), %esi
movq 0x20(%rsp), %rdx
callq 0x2967
callq 0x6bfa
callq 0x303d
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x23e0
jmp 0x2847
movl %eax, %edi
callq 0x2406
movl $0x1, %r14d
jmp 0x2825
callq 0x28e3
jmp 0x28db
leaq 0x77fd(%rip), %rdi      # 0xa05d
callq 0x2330
movl $0xa, %edi
callq 0x2290
leaq 0x77fd(%rip), %rdi      # 0xa073
callq 0x2330
leaq 0x7803(%rip), %rdi      # 0xa085
callq 0x2330
leaq 0x780c(%rip), %rdi      # 0xa09a
callq 0x2330
leaq 0x7832(%rip), %rdi      # 0xa0cc
callq 0x2330
leaq 0x7851(%rip), %rdi      # 0xa0f7
callq 0x2330
leaq 0x7878(%rip), %rdi      # 0xa12a
callq 0x2330
leaq 0x789a(%rip), %rdi      # 0xa158
callq 0x2330
leaq 0x78c3(%rip), %rdi      # 0xa18d
callq 0x2330
leaq 0x78e4(%rip), %rdi      # 0xa1ba
callq 0x2330
xorl %r14d, %r14d
jmp 0x2825