// File: /workspace/github_c_makefile_star2_O2/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 0x91c6(%rip), %rax      # 0xf2e0
cmpl $0x0, (%rax)
je 0x62b4
movl %r9d, %r13d
movl %r8d, %ebp
movl %edx, %r14d
movl %esi, %ebx
movq %rdi, %r12
pushq $0x1
popq %rdi
movl $0x83d0, %esi           # imm = 0x83D0
callq 0x2150
testq %rax, %rax
je 0x62e5
movq %rax, %r15
movq %r12, (%rax)
movl %ebx, %eax
movq %rax, 0x8(%r15)
orl $-0x1, 0x83c8(%r15)
leaq 0x18(%r15), %rbx
movups 0x90ea(%rip), %xmm0     # 0xf250
movups %xmm0, 0x10(%rsp)
movups 0x90ce(%rip), %xmm0     # 0xf240
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x22e0
testl %eax, %eax
js 0x62d5
movl %r13d, 0x24(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2320
testq %rax, %rax
je 0x62c3
movq %rax, %r13
movl 0x4(%rax), %eax
decl %eax
cmpl $0x2, %eax
jae 0x62c3
movl 0x70(%rsp), %edi
callq 0x38e9
testq %rax, %rax
je 0x6304
movq %rax, %r12
movl 0x78(%rsp), %ebx
movl $0x4, 0x10(%rax)
movb $0x10, 0x14(%rax)
movb 0x4(%r13), %al
movb %al, 0x15(%r12)
movq %r15, 0x88(%r12)
leaq 0x131(%rip), %rax       # 0x6323
movq %rax, 0x18(%r12)
addq $0x3c8, %r15            # imm = 0x3C8
movq %r15, 0x28(%r12)
andq $0x0, 0x80(%r12)
movl 0x60(%rsp), %r15d
notl %r14d
shrl $0x1f, %r14d
movl %r14d, 0x40(%r12)
andl $0x0, 0x48(%r12)
movl %ebp, %edi
callq 0x5fe8
movl %eax, 0x4c(%r12)
andl $0x0, 0x60(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movl 0x70(%rsp), %ecx
movl %ecx, 0x7c(%r12)
movl %ebx, 0xa0(%r12)
andl $0x0, 0x44(%r12)
movups %xmm0, 0x30(%r12)
movq $0x1, 0x70(%r12)
movl 0x8(%r13), %ecx
movl %ecx, 0x64(%r12)
imull %ecx, %eax
leaq 0x1229a(%rip), %rcx     # 0x18510
xorl %edx, %edx
divl (%rcx)
movl %eax, 0x68(%r12)
imull $0xff, %eax, %eax
movl %eax, 0x50(%r12)
movq %r12, %rdi
callq 0x3b4d
movq %r12, %rdi
movl 0x24(%rsp), %esi
movl %r15d, %edx
movl 0x68(%rsp), %ecx
callq 0x3c9d
movq %r12, %rdi
callq 0x362a
movl 0x78(%r12), %eax
jmp 0x62f5
leaq 0x9029(%rip), %rax      # 0xf2e4
movl $0x2, (%rax)
jmp 0x62f2
movq %rbx, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2280
jmp 0x62e5
leaq 0x3914(%rip), %rdi      # 0x9bf0
movl %eax, %esi
xorl %eax, %eax
callq 0x813d
leaq 0x8ff8(%rip), %rax      # 0xf2e4
movl $0x9, (%rax)
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2280
leaq 0x8fc9(%rip), %rax      # 0xf2e4
movl $0x4, (%rax)
jmp 0x62f2