// File: /workspace/github_c_makefile_star2_O0/jonof[P]jfaudiolib/src/test.c
// Function: playsong
void playsong(const char * song, int loopstart, int loopend)
{
    int status;
    int length;
    char * data;
    FILE * fp;

    fp = fopen(song, "rb");
    if (!fp) {
        fprintf(stderr, "Error opening %s\n", song);
        return;
    }

    fseek(fp, 0, SEEK_END);
    length = (int)ftell(fp);
    if (length <= 0) {
        fclose(fp);
        return;
    }

    data = (char *) malloc(length);
    if (!data) {
        fclose(fp);
        return;
    }

    fseek(fp, 0, SEEK_SET);

    if (fread(data, length, 1, fp) != 1) {
        fclose(fp);
        free(data);
        return;
    }

    fclose(fp);

    printf("Playing %s\n", song);

    if (memcmp(data, "MThd", 4) == 0) {
        status = MUSIC_PlaySong(data, length, 0);
        if (status != MUSIC_Ok) {
            fprintf(stderr, "Error playing music: %s\n", MUSIC_ErrorString(MUSIC_ErrorCode));
        } else {
            while (MUSIC_SongPlaying()) {
                ASS_Sleep(500);
            }
        }
    } else {
        if (loopstart >= 0) {
            printf("Looping from %d to %d\n", loopstart, loopend);
            status = FX_PlayLoopedAuto(data, length, loopstart, loopend,
                0, 255, 255, 255, FX_MUSIC_PRIORITY, 1);
        } else {
            status = FX_PlayAuto(data, length, 0, 255, 255, 255, FX_MUSIC_PRIORITY, 1);
        }
        if (status >= FX_Ok) {
            while (FX_SoundActive(status)) {
                ASS_Sleep(500);
            }
        } else {
            fprintf(stderr, "Error playing sound: %s\n", FX_ErrorString(FX_ErrorCode));
        }
    }

    free(data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xc6f9(%rip), %rsi      # 0xf216
callq 0x2250
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2b4e
movq 0x124ac(%rip), %rax     # 0x14fe0
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0xc6d7(%rip), %rsi      # 0xf219
movb $0x0, %al
callq 0x22d0
jmp 0x2d62
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x2220
movq -0x28(%rbp), %rdi
callq 0x2030
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jg 0x2b80
movq -0x28(%rbp), %rdi
callq 0x21f0
jmp 0x2d62
movslq -0x18(%rbp), %rdi
callq 0x2290
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2ba2
movq -0x28(%rbp), %rdi
callq 0x21f0
jmp 0x2d62
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2220
movq -0x20(%rbp), %rdi
movslq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl $0x1, %edx
callq 0x22f0
cmpq $0x1, %rax
je 0x2be4
movq -0x28(%rbp), %rdi
callq 0x21f0
movq -0x20(%rbp), %rdi
callq 0x2270
jmp 0x2d62
movq -0x28(%rbp), %rdi
callq 0x21f0
movq -0x8(%rbp), %rsi
leaq 0xc633(%rip), %rdi      # 0xf22b
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rax
movl (%rax), %eax
subl $0x6468544d, %eax       # imm = 0x6468544D
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2c7e
movq -0x20(%rbp), %rdi
movl -0x18(%rbp), %esi
xorl %edx, %edx
callq 0xa860
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x2c5f
movq 0x123ad(%rip), %rax     # 0x14fe0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x1c327(%rip), %rax     # 0x1ef68
movl (%rax), %edi
callq 0xa4f0
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0xc5e6(%rip), %rsi      # 0xf23c
movb $0x0, %al
callq 0x22d0
jmp 0x2c79
jmp 0x2c61
callq 0xa800
cmpl $0x0, %eax
je 0x2c77
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xd5f0
jmp 0x2c61
jmp 0x2c79
jmp 0x2d59
cmpl $0x0, -0xc(%rbp)
jl 0x2cd7
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq 0xc5c4(%rip), %rdi      # 0xf255
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
xorl %r8d, %r8d
movl $0xff, %r9d
movl $0xff, (%rsp)
movl $0xff, 0x8(%rsp)
movl $0x7fffffff, 0x10(%rsp) # imm = 0x7FFFFFFF
movl $0x1, 0x18(%rsp)
callq 0x41f0
movl %eax, -0x14(%rbp)
jmp 0x2d03
movq -0x20(%rbp), %rdi
movl -0x18(%rbp), %esi
xorl %edx, %edx
movl $0xff, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
movl $0x7fffffff, (%rsp)     # imm = 0x7FFFFFFF
movl $0x1, 0x8(%rsp)
callq 0x40b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x2d26
jmp 0x2d0b
movl -0x14(%rbp), %edi
callq 0x3f00
cmpl $0x0, %eax
je 0x2d24
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xd5f0
jmp 0x2d0b
jmp 0x2d57
movq 0x122b3(%rip), %rax     # 0x14fe0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
leaq 0x12f49(%rip), %rax     # 0x15c84
movl (%rax), %edi
callq 0x3500
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0xc51c(%rip), %rsi      # 0xf26c
movb $0x0, %al
callq 0x22d0
jmp 0x2d59
movq -0x20(%rbp), %rdi
callq 0x2270
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)