// File: /workspace/github_c_makefile_star2_O2/jonof[P]jfaudiolib/src/multivoc.c
// Function: MV_PlayLoopedVOC
int MV_PlayLoopedVOC
   (
   char *ptr,
   unsigned int ptrlength,
   int   loopstart,
   int   loopend,
   int   pitchoffset,
   int   vol,
   int   left,
   int   right,
   int   priority,
   unsigned int callbackval
   )

   {
   VoiceNode   *voice;
   int          status;

   (void)ptrlength;

   if ( !MV_Installed )
      {
      MV_SetErrorCode( MV_NotInstalled );
      return( MV_Error );
      }

   // Make sure it's a valid VOC file.
   status = memcmp( ptr, "Creative Voice File", 19 );
   if ( status != 0 )
      {
      MV_SetErrorCode( MV_InvalidVOCFile );
      return( MV_Error );
      }

   // Request a voice from the voice pool
   voice = MV_AllocVoice( priority );
   if ( voice == NULL )
      {
      MV_SetErrorCode( MV_NoVoices );
      return( MV_Error );
      }

   voice->wavetype    = VOC;
   voice->bits        = 8;
   voice->channels    = 1;
   voice->GetSound    = MV_GetNextVOCBlock;
   voice->NextBlock   = ptr + LITTLE16(*( unsigned short * )( ptr + 0x14 ));
   voice->DemandFeed  = NULL;
   voice->LoopStart   = NULL;
   voice->LoopCount   = 0;
   voice->BlockLength = 0;
   voice->PitchScale  = PITCH_GetScale( pitchoffset );
   voice->length      = 0;
   voice->next        = NULL;
   voice->prev        = NULL;
   voice->priority    = priority;
   voice->callbackval = callbackval;
   voice->LoopStart   = ( char * )(intptr_t)loopstart;
   voice->LoopEnd     = ( char * )(intptr_t)loopend;
   voice->LoopSize    = loopend - loopstart + 1;

   if ( loopstart < 0 )
      {
      voice->LoopStart = NULL;
      voice->LoopEnd   = NULL;
      }

   MV_SetVoiceVolume( voice, vol, left, right );
   MV_PlayVoice( voice );

   return( voice->handle );
   }

// Assembly:
cmpl $0x0, 0xa82c(%rip)      # 0xf2e0
je 0x4af4
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %ebx
movl %r8d, %r12d
movl %ecx, %ebp
movl %edx, %r15d
movq %rdi, %r13
leaq 0x4c52(%rip), %rsi      # 0x9728
pushq $0x13
popq %rdx
callq 0x2200
testl %eax, %eax
je 0x4b02
movl $0x7, 0xa7f8(%rip)      # 0xf2e4
pushq $-0x1
popq %rax
jmp 0x4bc0
movl $0x2, 0xa7e6(%rip)      # 0xf2e4
pushq $-0x1
popq %rax
retq
movl 0x50(%rsp), %edi
callq 0x38e9
testq %rax, %rax
je 0x4bcf
movq %rax, %r14
movl $0x1, 0x10(%rax)
movw $0x108, 0x14(%rax)      # imm = 0x108
leaq 0xb3(%rip), %rax        # 0x4bde
movq %rax, 0x18(%r14)
movzwl 0x14(%r13), %eax
addq %r13, %rax
movq %rax, 0x28(%r14)
andq $0x0, 0x80(%r14)
movl 0x58(%rsp), %r13d
andq $0x0, 0x30(%r14)
andl $0x0, 0x40(%r14)
andl $0x0, 0x48(%r14)
movl %r12d, %edi
callq 0x5fe8
movl %eax, 0x4c(%r14)
andl $0x0, 0x60(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl 0x50(%rsp), %eax
movl %eax, 0x7c(%r14)
movl %r13d, 0xa0(%r14)
movslq %r15d, %rax
movq %rax, 0x30(%r14)
movslq %ebp, %rcx
movq %rcx, 0x38(%r14)
subl %eax, %ecx
incl %ecx
movl %ecx, 0x44(%r14)
testl %eax, %eax
jns 0x4ba2
movq %r14, %rax
addq $0x30, %rax
movups %xmm0, (%rax)
movq %r14, %rdi
movl %ebx, %esi
movl 0x40(%rsp), %edx
movl 0x48(%rsp), %ecx
callq 0x3c9d
movq %r14, %rdi
callq 0x362a
movl 0x78(%r14), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, 0xa70b(%rip)      # 0xf2e4
jmp 0x4aec