// File: /workspace/github_c_makefile_star2_O2/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 $0xa8, %rsp
xorl %ebp, %ebp
cmpb $0x1, 0x2041ea(%rip)    # 0x21f274
jne 0x1b180
leaq 0xac9c9(%rip), %rax     # 0xc7a60
cmpl $0x0, 0x10(%rax)
je 0x1b180
cmpl $0x2, %edi
ja 0x1b180
cmpl %edi, 0xad71c(%rip)     # 0xc87cc
je 0x1b180
movl %edi, 0xc(%rsp)
movl 0xc(%rsp), %edi
callq 0x1b056
movl 0xc(%rsp), %ebx
leaq 0x2056b2(%rip), %r14    # 0x220780
cmpl $0x0, (%r14,%rbx,4)
je 0x1b180
movl 0xad6f5(%rip), %edi     # 0xc87d4
leaq 0x2056a6(%rip), %rax    # 0x22078c
movl (%rax,%rbx,4), %esi
xorl %edx, %edx
callq 0x306cb
movl 0xad6de(%rip), %edi     # 0xc87d4
movl (%r14,%rbx,4), %edx
leaq 0x20569f(%rip), %rsi    # 0x2207a0
callq 0x304e7
cmpl (%r14,%rbx,4), %eax
je 0x1b11a
leaq 0x66f58(%rip), %rdi     # 0x8206b
xorl %eax, %eax
callq 0x2acb8
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
orl $-0x1, 0x60(%rsp)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x68(%rsp)
orl $-0x1, 0x9c(%rsp)
leaq 0x67010(%rip), %rdi     # 0x8216a
leaq 0x20563f(%rip), %rbx    # 0x2207a0
pushq $0xf
popq %rdx
movq %rbx, %rsi
callq 0x89f0
testl %eax, %eax
je 0x1b194
leaq 0x66f07(%rip), %rdi     # 0x8207e
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x33127
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x205636(%rip), %esi    # 0x2207d0
movzwl 0x205633(%rip), %ecx    # 0x2207d4
movl $0x7270e00, %eax        # imm = 0x7270E00
xorl %edx, %edx
divl 0x20562a(%rip)          # 0x2207d8
movabsq $0x60000006468544d, %rdx # imm = 0x60000006468544D
movq %rdx, 0x2055e1(%rip)    # 0x2207a0
movw $0x100, 0x2055e0(%rip)  # imm = 0x100
movl %esi, %edx
rolw $0x8, %dx
movw %dx, 0x2055d5(%rip)     # 0x2207aa
xorl %edx, %edx
rolw $0x8, %cx
movw %cx, 0x2055ca(%rip)     # 0x2207ac
movl %eax, %ecx
shrl $0x10, %ecx
movl %ecx, 0x20(%rsp)
movl %eax, 0x24(%rsp)
shrl $0x8, %eax
movl %eax, 0x1c(%rsp)
testl %esi, %esi
cmovlel %edx, %esi
movl %esi, 0x28(%rsp)
movl $0x388, %eax            # imm = 0x388
pushq $0xe
popq %rsi
movabsq $0x100000000, %r9       # imm = 0x100000000
cmpl 0x28(%rsp), %edx
je 0x1b4d1
movl %eax, 0x2c(%rsp)
cltq
movq %rsi, 0x50(%rsp)
movslq %esi, %r8
movl 0x4(%rax,%rbx), %ecx
leal -0xc(%rcx), %edi
movq %rcx, 0x48(%rsp)
leal -0x5(%rcx), %esi
testl %edx, %edx
movl %edi, 0x30(%rsp)
cmovnel %edi, %esi
movl $0x6b72544d, (%r8,%rbx) # imm = 0x6B72544D
movq %rsi, %rcx
movq %rsi, 0x40(%rsp)
bswapl %ecx
movl %ecx, 0x4(%r8,%rbx)
movq %rdx, 0x38(%rsp)
je 0x1b268
addq %rbx, %r8
addq $0x8, %r8
jmp 0x1b28f
addq %rbx, %r8
movl $0x351ff00, 0x8(%r8)    # imm = 0x351FF00
movl 0x20(%rsp), %ecx
movb %cl, 0xc(%r8)
movl 0x1c(%rsp), %ecx
movb %cl, 0xd(%r8)
movl 0x24(%rsp), %ecx
movb %cl, 0xe(%r8)
addq $0xf, %r8
leaq (%rax,%rbx), %rcx
addq $0xc, %rcx
movq %rcx, 0x10(%rsp)
addq %rbx, %rax
addq $0xe, %rax
movq %rax, 0x58(%rsp)
xorl %edx, %edx
xorl %ebx, %ebx
cmpl 0x30(%rsp), %ebx
jge 0x1b4a6
movslq %ebx, %rcx
movq 0x58(%rsp), %rax
leaq (%rax,%rcx), %r14
shlq $0x20, %rcx
leal 0x2(%rbx), %r10d
movb $-0x1, %r11b
xorl %r15d, %r15d
movq %r15, %r12
movl %r10d, %esi
addq %r9, %rcx
movb -0x2(%r14,%r15), %bpl
movl %ebp, %r10d
andb $0x7f, %r10b
movzbl %r12b, %r15d
movb %r10b, 0x34(%rsp,%r15)
incl %ebx
leaq 0x1(%r12), %r15
incb %r11b
leal 0x1(%rsi), %r10d
testb %bpl, %bpl
jns 0x1b2d0
leaq -0x1(%r15), %rbp
movzbl %r11b, %r10d
addq %rsp, %r10
addq $0x34, %r10
pushq $-0x3
popq %r13
xorl %r11d, %r11d
movzbl 0x3(%r10,%r13), %eax
movl %eax, %edi
orb $-0x80, %dil
cmpb %r11b, %bpl
movzbl %dil, %edi
cmovel %eax, %edi
movb %dil, (%r8,%r11)
incq %r11
decq %r13
leal (%r12,%r13), %eax
cmpb $-0x4, %al
jne 0x1b317
sarq $0x20, %rcx
movq 0x10(%rsp), %rax
movb (%rax,%rcx), %cl
testb %cl, %cl
js 0x1b396
addq %r11, %r8
movl %edx, %eax
shrb $0x4, %al
andb $0x7, %al
movzbl %al, %eax
leaq 0x66e1d(%rip), %rcx     # 0x82180
movl (%rcx,%rax,4), %ebp
movq %r8, %r12
movl %edx, %ecx
movl %ebx, %edx
movslq %edx, %rsi
addq 0x10(%rsp), %rsi
movl %edx, %ebx
movq %r12, %r8
testl %ebp, %ebp
jle 0x1b38f
movb (%rsi), %al
movb %al, (%r8)
incq %r8
decl %ebp
incl %ebx
incq %rsi
jmp 0x1b37a
movl %ecx, %edx
jmp 0x1b2ac
movzbl %cl, %r10d
leaq (%r8,%r11), %r12
incq %r12
movb %cl, -0x1(%r12)
leal 0x1(%rbx), %edx
movl %r10d, %eax
shrl $0x2, %eax
andl $0x1c, %eax
leaq 0x66dc7(%rip), %rdi     # 0x82180
movl (%rax,%rdi), %ebp
movl %r10d, %r13d
andl $-0x10, %r13d
cmpl $0xb0, %r13d
je 0x1b409
cmpl $0xf0, %r13d
jne 0x1b36d
andl $0xf, %r10d
cmpq $0xf, %r10
je 0x1b443
testl %r10d, %r10d
jne 0x1b46d
movslq %esi, %rdx
addq 0x10(%rsp), %rdx
movb (%rdx), %al
movb %al, (%r12)
incq %r12
incq %rdx
incl %esi
testb %al, %al
jns 0x1b3f0
movl %esi, %edx
jmp 0x1b36d
movslq %edx, %rax
movq 0x10(%rsp), %rsi
movb (%rsi,%rax), %sil
leal -0x66(%rsi), %eax
cmpb $0x11, %al
ja 0x1b36d
movq 0x38(%rsp), %rax
cmpl $0x1, %eax
jne 0x1b477
cmpb $0x6e, %sil
jne 0x1b477
movb $0x76, 0x1(%r8,%r11)
movb (%r15,%r14), %al
andb $0x7f, %al
movb %al, 0x2(%r8,%r11)
jmp 0x1b494
movslq %edx, %rax
movq 0x10(%rsp), %rdx
movb (%rdx,%rax), %al
leaq (%r8,%r11), %r12
addq $0x3, %r12
movb %al, -0x2(%r12)
addl $0x3, %ebx
movzbl (%r15,%r14), %ebp
movb %bpl, -0x1(%r12)
jmp 0x1b36b
movl 0x60(%rsp,%r10,4), %ebp
jmp 0x1b36d
cmpl $0x1, %eax
jne 0x1b48c
cmpb $0x6f, %sil
jne 0x1b48c
movw $0x7f77, 0x1(%r8,%r11)  # imm = 0x7F77
jmp 0x1b494
movw $0x66, 0x1(%r8,%r11)
leaq (%r8,%r11), %r12
addq $0x3, %r12
addl $0x3, %ebx
xorl %ebp, %ebp
jmp 0x1b36b
movq 0x48(%rsp), %rax
addl 0x2c(%rsp), %eax
movq 0x50(%rsp), %rsi
movq 0x40(%rsp), %rcx
addl %ecx, %esi
addl $0x8, %esi
movq 0x38(%rsp), %rdx
incl %edx
leaq 0x2052d4(%rip), %rbx    # 0x2207a0
jmp 0x1b211
testl %esi, %esi
jle 0x1b170
leaq 0x2052c0(%rip), %rdi    # 0x2207a0
pushq $0x1
popq %rbp
movl %ebp, %edx
callq 0x7d3ea
testl %eax, %eax
je 0x1b514
leaq 0xc75243(%rip), %rax    # 0xc90738
movl (%rax), %edi
callq 0x7d254
leaq 0x66ba5(%rip), %rdi     # 0x820a8
xorl %ebp, %ebp
movq %rax, %rsi
xorl %eax, %eax
callq 0x33127
jmp 0x1b180
movl 0xc(%rsp), %eax
movl %eax, 0xad2ae(%rip)     # 0xc87cc
jmp 0x1b180