// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/src/teksnd.c
// Function: playsong
int
playsong(int sn)
{
     int       rv;
     int       midilen;

     if( !musicstarted || (toggles[TOGGLE_MUSIC] == 0) ) {
          return(0);
     }
     if( (sn < 0) || (sn >= SONGSPERLEVEL) || (songplaying == sn) ) {
          return(0);
     }

     removesong(sn);
     if( songlengths[sn] == 0 )
         return(0);

     klseek(fhsongs, songoffsets[sn], SEEK_SET);
     rv=kread(fhsongs, songdata, songlengths[sn]);
     if( rv != songlengths[sn] ) {
         crashgame("playsong: bad read");
     }

     midilen = transmutehmp(songdata);
     if (midilen <= 0) {
          buildprintf("playsong: could not convert song to MIDI\n");
          return 0;
     }

     rv = MUSIC_PlaySong(songdata, midilen, 1);
     if( rv != MUSIC_Ok ) {
          buildprintf("playsong: could not play song: %s\n", MUSIC_ErrorString(MUSIC_ErrorCode));
          return 0;
     }

    #ifdef MUSICDEBUG
     showmessage("PLAYING SONG %2d", sn);
    #endif
     songplaying = sn;

     return(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
xorl %ebp, %ebp
cmpb $0x1, 0x20c991(%rip)    # 0x229274
jne 0x1cd76
leaq 0xb5170(%rip), %rax     # 0xd1a60
cmpl $0x0, 0x10(%rax)
je 0x1cd76
cmpl $0x2, %edi
ja 0x1cd76
cmpl %edi, 0xb5ec3(%rip)     # 0xd27cc
je 0x1cd76
movl %edi, %ebx
leaq 0x20de68(%rip), %r14    # 0x22a780
cmpl $0x0, (%r14,%rbx,4)
je 0x1cd76
movl %edi, 0xc(%rsp)
movl 0xb5ea7(%rip), %edi     # 0xd27d4
leaq 0x20de58(%rip), %rax    # 0x22a78c
movl (%rax,%rbx,4), %esi
xorl %edx, %edx
callq 0x345aa
movl 0xb5e90(%rip), %edi     # 0xd27d4
movl (%r14,%rbx,4), %edx
leaq 0x20de51(%rip), %r15    # 0x22a7a0
movq %r15, %rsi
callq 0x343bc
cmpl (%r14,%rbx,4), %eax
je 0x1c96b
leaq 0x73773(%rip), %rdi     # 0x900d7
xorl %eax, %eax
callq 0x2eb88
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x50(%rsp)
movabsq $0x100000002, %rcx      # imm = 0x100000002
movq %rcx, 0x58(%rsp)
movl %eax, 0x8c(%rsp)
movabsq $0x504944494d494d48, %rax # imm = 0x504944494D494D48
xorq 0x20ddeb(%rip), %rax    # 0x22a7a0
movabsq $0x35393133313050, %rcx # imm = 0x35393133313050
xorq 0x20dde1(%rip), %rcx    # 0x22a7a7
orq %rax, %rcx
je 0x1c9e0
leaq 0x73718(%rip), %rdi     # 0x900ea
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x372d1
jmp 0x1cd76
movl 0x20ddea(%rip), %esi    # 0x22a7d0
movzwl 0x20dde7(%rip), %eax    # 0x22a7d4
movl 0x20dde5(%rip), %ecx    # 0x22a7d8
movabsq $0x60000006468544d, %rdx # imm = 0x60000006468544D
movq %rdx, 0x20dd9c(%rip)    # 0x22a7a0
movw $0x100, 0x20dd9b(%rip)  # imm = 0x100
movl %esi, %edx
rolw $0x8, %dx
movw %dx, 0x20dd90(%rip)     # 0x22a7aa
rolw $0x8, %ax
movw %ax, 0x20dd87(%rip)     # 0x22a7ac
movl %esi, 0x1c(%rsp)
testl %esi, %esi
jle 0x1cd2a
xorl %edi, %edi
movl $0x7270e00, %eax        # imm = 0x7270E00
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
shrl $0x10, %ecx
movl %ecx, 0x14(%rsp)
movl %eax, 0x18(%rsp)
shrl $0x8, %eax
movl %eax, 0x10(%rsp)
movl $0xe, %esi
movl $0x388, %eax            # imm = 0x388
movabsq $0x100000000, %r9       # imm = 0x100000000
movq %rdi, 0x28(%rsp)
movl %eax, 0x20(%rsp)
cltq
movslq %esi, %rbx
movl 0x4(%rax,%r15), %ecx
leal -0xc(%rcx), %r8d
movq %rcx, 0x38(%rsp)
leal -0x5(%rcx), %edx
testl %edi, %edi
movl %r8d, 0x8(%rsp)
cmovnel %r8d, %edx
movl $0x6b72544d, (%rbx,%r15) # imm = 0x6B72544D
movq %rdx, %rcx
movq %rdx, 0x30(%rsp)
bswapl %ecx
movl %ecx, 0x4(%rbx,%r15)
movq %rsi, 0x40(%rsp)
je 0x1cab5
addq %r15, %rbx
addq $0x8, %rbx
jmp 0x1cad8
addq %r15, %rbx
movl $0x351ff00, 0x8(%rbx)   # imm = 0x351FF00
movl 0x14(%rsp), %ecx
movb %cl, 0xc(%rbx)
movl 0x10(%rsp), %ecx
movb %cl, 0xd(%rbx)
movl 0x18(%rsp), %ecx
movb %cl, 0xe(%rbx)
addq $0xf, %rbx
cmpl $0x0, 0x8(%rsp)
jle 0x1ccf1
leaq 0x20dcb6(%rip), %rcx    # 0x22a7a0
leaq (%rax,%rcx), %r13
addq $0xc, %r13
addq %rcx, %rax
addq $0xe, %rax
movq %rax, 0x48(%rsp)
xorl %r12d, %r12d
xorl %esi, %esi
movslq %r12d, %r10
movq 0x48(%rsp), %rax
leaq (%rax,%r10), %r11
movq %r10, %rax
shlq $0x20, %rax
addl $0x2, %r10d
movb $-0x1, %dil
xorl %r15d, %r15d
movl %r12d, %ecx
movq %r15, %r8
movl %r10d, %r14d
addq %r9, %rax
movb -0x2(%r11,%r15), %dl
movl %edx, %r10d
andb $0x7f, %r10b
movzbl %r8b, %r15d
movb %r10b, 0x24(%rsp,%r15)
incl %ecx
leaq 0x1(%r8), %r15
incb %dil
leal 0x1(%r14), %r10d
testb %dl, %dl
jns 0x1cb23
movzbl %dil, %edx
leaq (%rsp,%rdx), %r10
addq $0x24, %r10
movq $-0x3, %r12
xorl %edi, %edi
movzbl 0x3(%r10,%r12), %edx
movl %edx, %ebp
orb $-0x80, %bpl
cmpb %dil, %r8b
movzbl %bpl, %ebp
cmovel %edx, %ebp
movb %bpl, (%rbx,%rdi)
incq %rdi
decq %r12
leal (%r12,%r8), %edx
cmpb $-0x4, %dl
jne 0x1cb67
sarq $0x20, %rax
movb (%r13,%rax), %r8b
testb %r8b, %r8b
js 0x1cbf9
addq %rdi, %rbx
movl %esi, %eax
shrb $0x4, %al
andb $0x7, %al
movzbl %al, %eax
leaq 0x7363e(%rip), %rdx     # 0x901f0
movl (%rdx,%rax,4), %r10d
movq %rbx, %rax
movl %esi, %r8d
movl %ecx, %r12d
testl %r10d, %r10d
jle 0x1cbe3
movslq %r12d, %r12
leaq (%r12,%r13), %rcx
leal 0x1(%r10), %esi
addl %r10d, %r12d
movb (%rcx), %dl
movb %dl, (%rax)
incq %rax
incq %rcx
decl %esi
cmpl $0x1, %esi
ja 0x1cbd2
movl %r8d, %esi
movq %rax, %rbx
cmpl 0x8(%rsp), %r12d
jl 0x1cb03
jmp 0x1ccf1
movzbl %r8b, %esi
leaq (%rbx,%rdi), %rax
incq %rax
movb %r8b, -0x1(%rax)
leal 0x1(%rcx), %r12d
movl %esi, %edx
shrl $0x2, %edx
andl $0x1c, %edx
leaq 0x735d5(%rip), %r10     # 0x901f0
movl (%rdx,%r10), %r10d
movl %esi, %edx
andl $-0x10, %edx
cmpl $0xb0, %edx
je 0x1cc60
cmpl $0xf0, %edx
jne 0x1cbbf
andl $0xf, %esi
cmpq $0xf, %rsi
je 0x1cc95
testl %esi, %esi
jne 0x1ccb9
movslq %r14d, %rcx
addq %r13, %rcx
movb (%rcx), %dl
movb %dl, (%rax)
incq %rax
incq %rcx
incl %r14d
testb %dl, %dl
jns 0x1cc47
movl %r14d, %r12d
jmp 0x1cbbf
movslq %r12d, %rdx
movb (%r13,%rdx), %sil
leal -0x66(%rsi), %edx
cmpb $0x11, %dl
ja 0x1cbbf
movq 0x28(%rsp), %rax
cmpl $0x1, %eax
jne 0x1ccc3
cmpb $0x6e, %sil
jne 0x1ccc3
movb $0x76, 0x1(%rbx,%rdi)
movb (%r15,%r11), %al
andb $0x7f, %al
movb %al, 0x2(%rbx,%rdi)
jmp 0x1ccde
movslq %r12d, %rax
movb (%r13,%rax), %dl
leaq (%rbx,%rdi), %rax
addq $0x3, %rax
movb %dl, -0x2(%rax)
addl $0x3, %ecx
movzbl (%r15,%r11), %r10d
movb %r10b, -0x1(%rax)
jmp 0x1cbbc
movl 0x50(%rsp,%rsi,4), %r10d
jmp 0x1cbbf
cmpl $0x1, %eax
jne 0x1ccd7
cmpb $0x6f, %sil
jne 0x1ccd7
movw $0x7f77, 0x1(%rbx,%rdi) # imm = 0x7F77
jmp 0x1ccde
movw $0x66, 0x1(%rbx,%rdi)
leaq (%rbx,%rdi), %rax
addq $0x3, %rax
addl $0x3, %ecx
movl %ecx, %r12d
jmp 0x1cbe3
movq 0x38(%rsp), %rax
addl 0x20(%rsp), %eax
movq 0x40(%rsp), %rsi
movq 0x30(%rsp), %rcx
addl %ecx, %esi
addl $0x8, %esi
movq 0x28(%rsp), %rdi
incl %edi
cmpl 0x1c(%rsp), %edi
leaq 0x20da85(%rip), %r15    # 0x22a7a0
jne 0x1ca64
testl %esi, %esi
jg 0x1cd2f
jmp 0x1c9cb
movl $0xe, %esi
leaq 0x20da6a(%rip), %rdi    # 0x22a7a0
movl $0x1, %ebp
movl $0x1, %edx
callq 0x8a8d9
testl %eax, %eax
je 0x1cd6c
leaq 0xc7d9e8(%rip), %rax    # 0xc9a738
movl (%rax), %edi
callq 0x8a718
leaq 0x733b6(%rip), %rdi     # 0x90114
xorl %ebp, %ebp
movq %rax, %rsi
xorl %eax, %eax
callq 0x372d1
jmp 0x1cd76
movl 0xc(%rsp), %eax
movl %eax, 0xb5a56(%rip)     # 0xd27cc
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq