// File: /workspace/github_c_makefile_star2_O1/jonof[P]jfaudiolib/src/vorbis.c
// Function: MV_PlayLoopedVorbis
int MV_PlayLoopedVorbis
(
 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;
   vorbis_data * vd = 0;
   vorbis_info * vi = 0;

   (void)loopend;

   if ( !MV_Installed )
   {
      MV_SetErrorCode( MV_NotInstalled );
      return( MV_Error );
   }
   
   vd = (vorbis_data *) malloc( sizeof(vorbis_data) );
   if (!vd) {
      MV_SetErrorCode( MV_InvalidVorbisFile );
      return MV_Error;
   }
   
   memset(vd, 0, sizeof(vorbis_data));
   vd->ptr = ptr;
   vd->pos = 0;
   vd->length = ptrlength;
   vd->lastbitstream = -1;
   
   status = ov_open_callbacks((void *) vd, &vd->vf, 0, 0, vorbis_callbacks);
   if (status < 0) {
      ASS_Message("MV_PlayLoopedVorbis: err %d\n", status);
      MV_SetErrorCode( MV_InvalidVorbisFile );
      return MV_Error;
   }
   
   vi = ov_info(&vd->vf, 0);
   if (!vi) {
      ov_clear(&vd->vf);
      free(vd);
      MV_SetErrorCode( MV_InvalidVorbisFile );
      return MV_Error;
   }
   
   if (vi->channels != 1 && vi->channels != 2) {
      ov_clear(&vd->vf);
      free(vd);
      MV_SetErrorCode( MV_InvalidVorbisFile );
      return MV_Error;
   }
   
   // Request a voice from the voice pool
   voice = MV_AllocVoice( priority );
   if ( voice == NULL )
   {
      ov_clear(&vd->vf);
      free(vd);
      MV_SetErrorCode( MV_NoVoices );
      return( MV_Error );
   }
   
   voice->wavetype    = Vorbis;
   voice->bits        = 16;
   voice->channels    = vi->channels;
   voice->extra       = (void *) vd;
   voice->GetSound    = MV_GetNextVorbisBlock;
   voice->NextBlock   = vd->block;
   voice->DemandFeed  = NULL;
   voice->LoopCount   = (loopstart >= 0 ? TRUE : FALSE);
   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   = 0;
   voice->LoopEnd     = 0;
   voice->LoopSize    = 0;
   voice->Playing     = TRUE;
   voice->Paused      = FALSE;
   
   voice->SamplingRate = (unsigned)vi->rate;
   voice->RateScale    = ( voice->SamplingRate * voice->PitchScale ) / MV_MixRate;
   voice->FixedPointBufferSize = ( voice->RateScale * MixBufferSize ) -
      voice->RateScale;
   MV_SetVoiceMixMode( voice );

   MV_SetVoiceVolume( voice, vol, left, right );
   MV_PlayVoice( voice );
   
   return( voice->handle );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x9cc1(%rip), %rax      # 0x102d0
cmpl $0x0, (%rax)
je 0x67c0
movl %r9d, %r13d
movl %r8d, %ebp
movl %edx, %r15d
movl %esi, %ebx
movq %rdi, %r12
movl $0x83d0, %edi           # imm = 0x83D0
callq 0x2280
testq %rax, %rax
je 0x67f1
movq %rax, %r14
movl $0x83d0, %edx           # imm = 0x83D0
movq %rax, %rdi
xorl %esi, %esi
callq 0x20f0
movq %r12, (%r14)
movq $0x0, 0x10(%r14)
movl %ebx, %eax
movq %rax, 0x8(%r14)
movl $0xffffffff, 0x83c8(%r14) # imm = 0xFFFFFFFF
leaq 0x18(%r14), %rbx
movups 0x9bce(%rip), %xmm0     # 0x10240
movups %xmm0, 0x10(%rsp)
movups 0x9bb2(%rip), %xmm0     # 0x10230
movups %xmm0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x22c0
testl %eax, %eax
js 0x67e1
movl %r13d, 0x24(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2300
testq %rax, %rax
je 0x67cf
movq %rax, %r13
movl 0x4(%rax), %eax
decl %eax
cmpl $0x2, %eax
jae 0x67cf
movl 0x70(%rsp), %edi
callq 0x3a02
testq %rax, %rax
je 0x6812
movq %rax, %r12
movl 0x78(%rsp), %ebx
movl $0x4, 0x10(%rax)
movb $0x10, 0x14(%rax)
movb 0x4(%r13), %al
movb %al, 0x15(%r12)
movq %r14, 0x88(%r12)
leaq 0x133(%rip), %rax       # 0x6831
movq %rax, 0x18(%r12)
addq $0x3c8, %r14            # imm = 0x3C8
movq %r14, 0x28(%r12)
movq $0x0, 0x80(%r12)
notl %r15d
shrl $0x1f, %r15d
movl %r15d, 0x40(%r12)
xorl %r14d, %r14d
movl %r14d, 0x48(%r12)
movl %ebp, %edi
callq 0x649c
movl %eax, 0x4c(%r12)
movl %r14d, 0x60(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movl 0x70(%rsp), %ecx
movl %ecx, 0x7c(%r12)
movl %ebx, 0xa0(%r12)
movl %r14d, 0x44(%r12)
movups %xmm0, 0x30(%r12)
movq $0x1, 0x70(%r12)
movl 0x8(%r13), %ecx
movl %ecx, 0x64(%r12)
imull %ecx, %eax
leaq 0x12d80(%rip), %rcx     # 0x19500
xorl %edx, %edx
divl (%rcx)
movl %eax, 0x68(%r12)
movl %eax, %ecx
shll $0x8, %ecx
subl %eax, %ecx
movl %ecx, 0x50(%r12)
movq %r12, %rdi
callq 0x3cf8
movq %r12, %rdi
movl 0x24(%rsp), %esi
movl 0x60(%rsp), %edx
movl 0x68(%rsp), %ecx
callq 0x3e48
movq %r12, %rdi
callq 0x3619
movl 0x78(%r12), %eax
jmp 0x6803
leaq 0x9b0d(%rip), %rax      # 0x102d4
movl $0x2, (%rax)
jmp 0x67fe
movq %rbx, %rdi
callq 0x2100
movq %r14, %rdi
callq 0x2260
jmp 0x67f1
leaq 0x4448(%rip), %rdi      # 0xac30
movl %eax, %esi
xorl %eax, %eax
callq 0x8aa8
leaq 0x9adc(%rip), %rax      # 0x102d4
movl $0x9, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x2100
movq %r14, %rdi
callq 0x2260
leaq 0x9aab(%rip), %rax      # 0x102d4
movl $0x4, (%rax)
jmp 0x67fe