// File: /workspace/github_c_makefile_star2_O3/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 0x9c35(%rip), %rax      # 0x102d0
cmpl $0x0, (%rax)
je 0x683a
movl %r9d, %r13d
movl %r8d, %ebp
movl %edx, %r14d
movl %esi, %ebx
movq %rdi, %r12
movl $0x1, %edi
movl $0x83d0, %esi           # imm = 0x83D0
callq 0x2150
testq %rax, %rax
je 0x686b
movq %rax, %r15
movq %r12, (%rax)
movl %ebx, %eax
movq %rax, 0x8(%r15)
movl $0xffffffff, 0x83c8(%r15) # imm = 0xFFFFFFFF
leaq 0x18(%r15), %rbx
movups 0x9b54(%rip), %xmm0     # 0x10240
movups %xmm0, 0x10(%rsp)
movups 0x9b38(%rip), %xmm0     # 0x10230
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x22d0
testl %eax, %eax
js 0x685b
movl %r13d, 0x24(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2310
testq %rax, %rax
je 0x6849
movq %rax, %r13
movl 0x4(%rax), %eax
decl %eax
cmpl $0x2, %eax
jae 0x6849
movl 0x70(%rsp), %edi
callq 0x3a07
testq %rax, %rax
je 0x688c
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 0x133(%rip), %rax       # 0x68ab
movq %rax, 0x18(%r12)
addq $0x3c8, %r15            # imm = 0x3C8
movq %r15, 0x28(%r12)
movq $0x0, 0x80(%r12)
notl %r14d
shrl $0x1f, %r14d
movl %r14d, 0x40(%r12)
xorl %r14d, %r14d
movl %r14d, 0x48(%r12)
movl %ebp, %edi
callq 0x6520
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 0x12d06(%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 0x3cfd
movq %r12, %rdi
movl 0x24(%rsp), %esi
movl 0x60(%rsp), %edx
movl 0x68(%rsp), %ecx
callq 0x3e4d
movq %r12, %rdi
callq 0x360b
movl 0x78(%r12), %eax
jmp 0x687d
leaq 0x9a93(%rip), %rax      # 0x102d4
movl $0x2, (%rax)
jmp 0x6878
movq %rbx, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2270
jmp 0x686b
leaq 0x43fe(%rip), %rdi      # 0xac60
movl %eax, %esi
xorl %eax, %eax
callq 0x8b10
leaq 0x9a62(%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 %r15, %rdi
callq 0x2270
leaq 0x9a31(%rip), %rax      # 0x102d4
movl $0x4, (%rax)
jmp 0x6878