// File: /workspace/github_c_makefile_star2_O1/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, 0x209ace(%rip)    # 0x226254
jne 0x1cc19
leaq 0xb22cd(%rip), %rax     # 0xcea60
cmpl $0x0, 0x10(%rax)
je 0x1cc19
cmpl $0x2, %edi
ja 0x1cc19
cmpl %edi, 0xb3020(%rip)     # 0xcf7cc
je 0x1cc19
movl %edi, %ebx
leaq 0x20afa5(%rip), %r14    # 0x227760
cmpl $0x0, (%r14,%rbx,4)
je 0x1cc19
movl %edi, 0xc(%rsp)
movl 0xb3004(%rip), %edi     # 0xcf7d4
leaq 0x20af95(%rip), %rax    # 0x22776c
movl (%rax,%rbx,4), %esi
xorl %edx, %edx
callq 0x33214
movl 0xb2fed(%rip), %edi     # 0xcf7d4
movl (%r14,%rbx,4), %edx
leaq 0x20af8e(%rip), %r15    # 0x227780
movq %r15, %rsi
callq 0x3302e
cmpl (%r14,%rbx,4), %eax
je 0x1c80e
leaq 0x707f0(%rip), %rdi     # 0x8cff7
xorl %eax, %eax
callq 0x2d800
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, 0x50(%rsp)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x58(%rsp)
movl %esi, 0x8c(%rsp)
movabsq $0x504944494d494d48, %rax # imm = 0x504944494D494D48
xorq 0x20af28(%rip), %rax    # 0x227780
movabsq $0x35393133313050, %rcx # imm = 0x35393133313050
xorq 0x20af1e(%rip), %rcx    # 0x227787
orq %rax, %rcx
jne 0x1cbbc
movl 0x20af38(%rip), %esi    # 0x2277b0
movzwl 0x20af35(%rip), %eax    # 0x2277b4
movl 0x20af33(%rip), %ecx    # 0x2277b8
movabsq $0x60000006468544d, %rdx # imm = 0x60000006468544D
movq %rdx, 0x20aeea(%rip)    # 0x227780
movw $0x100, 0x20aee9(%rip)  # imm = 0x100
movl %esi, %edx
rolw $0x8, %dx
movw %dx, 0x20aede(%rip)     # 0x22778a
rolw $0x8, %ax
movw %ax, 0x20aed5(%rip)     # 0x22778c
movl %esi, 0x1c(%rsp)
testl %esi, %esi
jle 0x1cbb7
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 0x1c947
addq %r15, %rbx
addq $0x8, %rbx
jmp 0x1c96a
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 0x1cb85
leaq 0x20ae04(%rip), %rcx    # 0x227780
leaq (%rax,%rcx), %r13
addq $0xc, %r13
addq %rcx, %rax
addq $0xe, %rax
movq %rax, 0x48(%rsp)
xorl %r12d, %r12d
xorl %r8d, %r8d
movl %r8d, %r10d
movslq %r12d, %r8
movq 0x48(%rsp), %rax
leaq (%rax,%r8), %r11
movq %r8, %rax
shlq $0x20, %rax
addl $0x2, %r8d
movb $-0x1, %sil
xorl %r15d, %r15d
movl %r12d, %ecx
movq %r15, %rdi
movl %r8d, %r14d
addq %r9, %rax
movb -0x2(%r11,%r15), %dl
movl %edx, %r8d
andb $0x7f, %r8b
movzbl %dil, %r15d
movb %r8b, 0x24(%rsp,%r15)
incl %ecx
leaq 0x1(%rdi), %r15
incb %sil
leal 0x1(%r14), %r8d
testb %dl, %dl
jns 0x1c9b9
movzbl %sil, %edx
leaq (%rsp,%rdx), %r8
addq $0x24, %r8
movq $-0x3, %r12
xorl %esi, %esi
movzbl 0x3(%r8,%r12), %edx
movl %edx, %ebp
orb $-0x80, %bpl
cmpb %sil, %dil
movzbl %bpl, %ebp
cmovel %edx, %ebp
movb %bpl, (%rbx,%rsi)
incq %rsi
decq %r12
leal (%r12,%rdi), %edx
cmpb $-0x4, %dl
jne 0x1c9fd
sarq $0x20, %rax
movb (%r13,%rax), %r8b
testb %r8b, %r8b
js 0x1ca8a
addq %rsi, %rbx
movl %r10d, %eax
shrb $0x4, %al
andb $0x7, %al
movzbl %al, %eax
leaq 0x706c7(%rip), %rdx     # 0x8d110
movl (%rdx,%rax,4), %edi
movq %rbx, %rax
movl %r10d, %r8d
movl %ecx, %r12d
testl %edi, %edi
jle 0x1ca77
movslq %r12d, %r12
leaq (%r12,%r13), %rcx
leal 0x1(%rdi), %esi
addl %edi, %r12d
movb (%rcx), %dl
movb %dl, (%rax)
incq %rax
incq %rcx
decl %esi
cmpl $0x1, %esi
jg 0x1ca66
movq %rax, %rbx
cmpl 0x8(%rsp), %r12d
jl 0x1c996
jmp 0x1cb85
movzbl %r8b, %r10d
leaq (%rbx,%rsi), %rax
incq %rax
movb %r8b, -0x1(%rax)
leal 0x1(%rcx), %r12d
movl %r10d, %edx
shrl $0x2, %edx
andl $0x1c, %edx
leaq 0x70663(%rip), %rdi     # 0x8d110
movl (%rdx,%rdi), %edi
movl %r10d, %edx
andl $-0x10, %edx
cmpl $0xb0, %edx
je 0x1caf4
cmpl $0xf0, %edx
jne 0x1ca55
andl $0xf, %r10d
cmpq $0xf, %r10
je 0x1cb2a
testl %r10d, %r10d
jne 0x1cb4e
movslq %r14d, %rcx
addq %r13, %rcx
movb (%rcx), %dl
movb %dl, (%rax)
incq %rax
incq %rcx
incl %r14d
testb %dl, %dl
jns 0x1cadb
movl %r14d, %r12d
jmp 0x1ca55
movslq %r12d, %rdx
movb (%r13,%rdx), %r10b
leal -0x66(%r10), %edx
cmpb $0x11, %dl
ja 0x1ca55
movq 0x28(%rsp), %rax
cmpl $0x1, %eax
jne 0x1cb58
cmpb $0x6e, %r10b
jne 0x1cb58
movb $0x76, 0x1(%rbx,%rsi)
movb (%r15,%r11), %al
andb $0x7f, %al
movb %al, 0x2(%rbx,%rsi)
jmp 0x1cb73
movslq %r12d, %rax
movb (%r13,%rax), %dl
leaq (%rbx,%rsi), %rax
addq $0x3, %rax
movb %dl, -0x2(%rax)
addl $0x3, %ecx
movzbl (%r15,%r11), %edi
movb %dil, -0x1(%rax)
jmp 0x1ca52
movl 0x50(%rsp,%r10,4), %edi
jmp 0x1ca55
cmpl $0x1, %eax
jne 0x1cb6c
cmpb $0x6f, %r10b
jne 0x1cb6c
movw $0x7f77, 0x1(%rbx,%rsi) # imm = 0x7F77
jmp 0x1cb73
movw $0x66, 0x1(%rbx,%rsi)
leaq (%rbx,%rsi), %rax
addq $0x3, %rax
addl $0x3, %ecx
xorl %edi, %edi
jmp 0x1ca52
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 0x20abd1(%rip), %r15    # 0x227780
jne 0x1c8f6
jmp 0x1cbbc
movl $0xe, %esi
testl %esi, %esi
jle 0x1cbfd
leaq 0x20abb9(%rip), %rdi    # 0x227780
movl $0x1, %ebp
movl $0x1, %edx
callq 0x87cbe
testl %eax, %eax
je 0x1cc0f
leaq 0xc7ab47(%rip), %rax    # 0xc97728
movl (%rax), %edi
callq 0x87b08
leaq 0x70445(%rip), %rdi     # 0x8d034
xorl %ebp, %ebp
movq %rax, %rsi
xorl %eax, %eax
callq 0x36050
jmp 0x1cc19
leaq 0x70406(%rip), %rdi     # 0x8d00a
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x36050
jmp 0x1cc19
movl 0xc(%rsp), %eax
movl %eax, 0xb2bb3(%rip)     # 0xcf7cc
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq