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

   {
   riff_header   riff;
   format_header format;
   data_header   data;
   VoiceNode     *voice;
   char *dataptr = ptr;
   int length;
   int absloopend;
   int absloopstart;
   int sizemask;

   (void)ptrlength;

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

   memcpy(&riff, dataptr, sizeof(riff_header));
   riff.file_size   = LITTLE32(riff.file_size);
   riff.format_size = LITTLE32(riff.format_size);
   dataptr += sizeof(riff_header);

   if ( ( memcmp( riff.RIFF, "RIFF", 4 ) != 0 ) ||
      ( memcmp( riff.WAVE, "WAVE", 4 ) != 0 ) ||
      ( memcmp( riff.fmt, "fmt ", 4) != 0 ) )
      {
      MV_SetErrorCode( MV_InvalidWAVFile );
      return( MV_Error );
      }

   memcpy(&format, dataptr, sizeof(format_header));
   format.wFormatTag      = LITTLE16(format.wFormatTag);
   format.nChannels       = LITTLE16(format.nChannels);
   format.nSamplesPerSec  = LITTLE32(format.nSamplesPerSec);
   format.nAvgBytesPerSec = LITTLE32(format.nAvgBytesPerSec);
   format.nBlockAlign     = LITTLE16(format.nBlockAlign);
   format.nBitsPerSample  = LITTLE16(format.nBitsPerSample);
   dataptr += riff.format_size;

   memcpy(&data, dataptr, sizeof(data_header));
   data.size = LITTLE32(data.size);

   // Check if it's PCM data.
   if ( format.wFormatTag != 1 )
      {
      MV_SetErrorCode( MV_InvalidWAVFile );
      return( MV_Error );
      }

   if ( format.nChannels != 1 && format.nChannels != 2 )
      {
      MV_SetErrorCode( MV_InvalidWAVFile );
      return( MV_Error );
      }

   if ( ( format.nBitsPerSample != 8 ) &&
      ( format.nBitsPerSample != 16 ) )
      {
      MV_SetErrorCode( MV_InvalidWAVFile );
      return( MV_Error );
      }

   if ( memcmp( data.DATA, "data", 4 ) != 0 )
      {
      MV_SetErrorCode( MV_InvalidWAVFile );
      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    = WAV;
   voice->bits        = format.nBitsPerSample;
   voice->channels    = format.nChannels;
   voice->GetSound    = MV_GetNextWAVBlock;

   length = data.size;
   absloopstart = loopstart;
   absloopend   = loopend;
   sizemask = 0;
   if ( voice->bits == 16 )
      {
      loopstart  *= 2;
      loopend    *= 2;
      length     /= 2;
      sizemask    = 1;
      }
   if ( voice->channels == 2 )
      {
      loopstart  *= 2;
      loopend    *= 2;
      length     /= 2;
      sizemask    = (sizemask<<1) | 1;
      }
   data.size  &= ~sizemask;

   loopend    = (int)min( (unsigned int)loopend, data.size );
   absloopend = (int)min( (unsigned int)absloopend, (unsigned int)length );

   voice->Playing     = TRUE;
   voice->Paused      = FALSE;
   voice->DemandFeed  = NULL;
   voice->LoopStart   = NULL;
   voice->LoopCount   = 0;
   voice->position    = 0;
   voice->length      = 0;
   voice->BlockLength = absloopend;
   voice->NextBlock   = dataptr + sizeof(data_header);
   voice->next        = NULL;
   voice->prev        = NULL;
   voice->priority    = priority;
   voice->callbackval = callbackval;
   voice->LoopStart   = voice->NextBlock + loopstart;
   voice->LoopEnd     = voice->NextBlock + loopend;
   voice->LoopSize    = absloopend - absloopstart;

   if ( ( loopstart >= (int)data.size ) || ( loopstart < 0 ) )
      {
      voice->LoopStart = NULL;
      voice->LoopEnd   = NULL;
      voice->BlockLength = length;
      }

   MV_SetVoicePitch( voice, format.nSamplesPerSec, pitchoffset );
   MV_SetVoiceVolume( voice, vol, left, right );
   MV_PlayVoice( voice );

   return( voice->handle );
   }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpl $0x0, 0xf6f5(%rip)      # 0x15c90
jne 0x65b3
movl $0x2, 0xf6ed(%rip)      # 0x15c94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x699a
movq -0x60(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x30(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x60(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x60(%rbp)
leaq -0x38(%rbp), %rax
movl (%rax), %eax
subl $0x46464952, %eax       # imm = 0x46464952
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x662e
leaq -0x38(%rbp), %rax
addq $0x8, %rax
movl (%rax), %eax
subl $0x45564157, %eax       # imm = 0x45564157
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x662e
leaq -0x38(%rbp), %rax
addq $0xc, %rax
movl (%rax), %eax
subl $0x20746d66, %eax       # imm = 0x20746D66
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x6644
movl $0x8, 0xf65c(%rip)      # 0x15c94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x699a
movq -0x60(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movw -0x48(%rbp), %ax
movw %ax, -0x48(%rbp)
movw -0x46(%rbp), %ax
movw %ax, -0x46(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movw -0x3c(%rbp), %ax
movw %ax, -0x3c(%rbp)
movw -0x3a(%rbp), %ax
movw %ax, -0x3a(%rbp)
movl -0x28(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movzwl -0x48(%rbp), %eax
cmpl $0x1, %eax
je 0x66c3
movl $0x8, 0xf5dd(%rip)      # 0x15c94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x699a
movzwl -0x46(%rbp), %eax
cmpl $0x1, %eax
je 0x66eb
movzwl -0x46(%rbp), %eax
cmpl $0x2, %eax
je 0x66eb
movl $0x8, 0xf5b5(%rip)      # 0x15c94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x699a
movzwl -0x3a(%rbp), %eax
cmpl $0x8, %eax
je 0x6713
movzwl -0x3a(%rbp), %eax
cmpl $0x10, %eax
je 0x6713
movl $0x8, 0xf58d(%rip)      # 0x15c94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x699a
leaq -0x50(%rbp), %rax
movl (%rax), %eax
subl $0x61746164, %eax       # imm = 0x61746164
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x673f
movl $0x8, 0xf561(%rip)      # 0x15c94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x699a
movl 0x20(%rbp), %edi
callq 0x4af0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x6768
movl $0x4, 0xf538(%rip)      # 0x15c94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x699a
movq -0x58(%rbp), %rax
movl $0x3, 0x10(%rax)
movw -0x3a(%rbp), %ax
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, 0x14(%rax)
movw -0x46(%rbp), %ax
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, 0x15(%rax)
movq -0x58(%rbp), %rax
leaq 0x4e8(%rip), %rcx       # 0x6c80
movq %rcx, 0x18(%rax)
movl -0x4c(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl $0x0, -0x70(%rbp)
movq -0x58(%rbp), %rax
movsbl 0x14(%rax), %eax
cmpl $0x10, %eax
jne 0x67e7
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movl -0x64(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x64(%rbp)
movl $0x1, -0x70(%rbp)
movq -0x58(%rbp), %rax
movsbl 0x15(%rax), %eax
cmpl $0x2, %eax
jne 0x681d
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movl -0x64(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x64(%rbp)
movl -0x70(%rbp), %eax
shll %eax
orl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
xorl $-0x1, %eax
andl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x6839
movl -0x1c(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x683f
movl -0x4c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x6855
movl -0x68(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x685b
movl -0x64(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movl $0x1, 0x70(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x74(%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x80(%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x6c(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x60(%rax)
movl -0x68(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x60(%rbp), %rcx
addq $0x8, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x58(%rbp), %rax
movq $0x0, (%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x8(%rax)
movl 0x20(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x7c(%rax)
movl 0x28(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0xa0(%rax)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0x18(%rbp), %rax
addq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0x1c(%rbp), %rax
addq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x38(%rax)
movl -0x68(%rbp), %ecx
subl -0x6c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x44(%rax)
movl -0x18(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x6944
cmpl $0x0, -0x18(%rbp)
jge 0x6966
movq -0x58(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x38(%rax)
movl -0x64(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x58(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x4dd0
movq -0x58(%rbp), %rdi
movl -0x24(%rbp), %esi
movl 0x10(%rbp), %edx
movl 0x18(%rbp), %ecx
callq 0x5220
movq -0x58(%rbp), %rdi
callq 0x45a0
movq -0x58(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)