// File: /workspace/github_c_makefile_star2_O3/jonof[P]jfaudiolib/src/vorbis.c
// Function: MV_GetNextVorbisBlock
static playbackstatus MV_GetNextVorbisBlock
(
 VoiceNode *voice
 )

{
   vorbis_data * vd = (vorbis_data *) voice->extra;
   int bytes = 0, bytesread = 0;
   int bitstream = 0, err = 0;

   voice->Playing = TRUE;
   
   bytesread = 0;
   do {
      bytes = (int)ov_read(&vd->vf, vd->block + bytesread, sizeof(vd->block) - bytesread, 0, 2, 1, &bitstream);
      //ASS_Message("ov_read = %d\n", bytes);
      if (bytes == OV_HOLE) continue;
      if (bytes == 0) {
         if (voice->LoopCount) {
            err = ov_pcm_seek_page(&vd->vf, 0);
            if (err != 0) {
               ASS_Message("MV_GetNextVorbisBlock ov_pcm_seek_page: err %d\n", err);
            } else {
               continue;
            }
         } else {
           break;
         }
      } else if (bytes < 0) {
         ASS_Message("MV_GetNextVorbisBlock ov_read: err %d\n", bytes);
         voice->Playing = FALSE;
         return NoMoreData;
      }

      bytesread += bytes;
   } while (bytesread < (int)sizeof(vd->block));

   if (bytesread == 0) {
      voice->Playing = FALSE;
      return NoMoreData;
   }
      
   if (bitstream != vd->lastbitstream) {
      vorbis_info * vi = 0;
      
      vi = ov_info(&vd->vf, -1);
      if (!vi) {
         voice->Playing = FALSE;
         return NoMoreData;
      }
      
      if (vi->channels != 1 && vi->channels != 2) {
         voice->Playing = FALSE;
         return NoMoreData;
      }
      
      voice->channels = vi->channels;
      voice->SamplingRate = (unsigned)vi->rate;
      voice->RateScale    = ( voice->SamplingRate * voice->PitchScale ) / MV_MixRate;
      voice->FixedPointBufferSize = ( voice->RateScale * MixBufferSize ) -
         voice->RateScale;
      MV_SetVoiceMixMode( voice );
   }
   vd->lastbitstream = bitstream;
   
   bytesread /= 2 * voice->channels;
   
   voice->position    = 0;
   voice->sound       = vd->block;
   voice->BlockLength = 0;
   voice->length      = bytesread << 16;
   
   return( KeepPlaying );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x88(%rdi), %rax
leaq 0xc(%rsp), %r15
movl $0x0, (%r15)
movl $0x1, 0x70(%rdi)
leaq 0x18(%rax), %r14
movq %rax, 0x10(%rsp)
leaq 0x3c8(%rax), %r13
xorl %ebp, %ebp
movslq %ebp, %rax
leaq (%rax,%r13), %rsi
movl $0x8000, %edx           # imm = 0x8000
subl %eax, %edx
movq %r15, (%rsp)
movq %r14, %rdi
xorl %ecx, %ecx
movl $0x2, %r8d
movl $0x1, %r9d
callq 0x23c0
movq %rax, %r12
cmpl $-0x3, %r12d
je 0x6951
testl %r12d, %r12d
jne 0x6948
cmpl $0x0, 0x40(%rbx)
je 0x69e4
movq %r14, %rdi
xorl %esi, %esi
callq 0x2370
testl %eax, %eax
je 0x6951
leaq 0x4340(%rip), %rdi      # 0xac7d
movl %eax, %esi
xorl %eax, %eax
callq 0x8b10
jmp 0x694e
js 0x69f7
addl %r12d, %ebp
cmpl $0x8000, %ebp           # imm = 0x8000
jl 0x68e8
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %r15
cmpl 0x83c8(%r15), %eax
je 0x69b9
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2310
testq %rax, %rax
je 0x69ec
movl 0x4(%rax), %ecx
leal -0x1(%rcx), %edx
cmpl $0x2, %edx
jae 0x69ec
movb %cl, 0x15(%rbx)
movl 0x8(%rax), %eax
movl %eax, 0x64(%rbx)
imull 0x4c(%rbx), %eax
leaq 0x12b64(%rip), %rcx     # 0x19500
xorl %edx, %edx
divl (%rcx)
movl %eax, 0x68(%rbx)
movl %eax, %ecx
shll $0x8, %ecx
subl %eax, %ecx
movl %ecx, 0x50(%rbx)
movq %rbx, %rdi
callq 0x3cfd
movl 0xc(%rsp), %eax
movl %eax, 0x83c8(%r15)
movsbl 0x15(%rbx), %ecx
addl %ecx, %ecx
movl %ebp, %eax
cltd
idivl %ecx
xorl %ecx, %ecx
movl %ecx, 0x6c(%rbx)
movq %r13, 0x58(%rbx)
movl %ecx, 0x48(%rbx)
shll $0x10, %eax
movl %eax, 0x60(%rbx)
movl $0x1, %ebp
jmp 0x6a11
testl %ebp, %ebp
jne 0x6959
movl $0x0, 0x70(%rbx)
xorl %ebp, %ebp
jmp 0x6a11
leaq 0x42af(%rip), %rdi      # 0xacad
xorl %ebp, %ebp
movl %r12d, %esi
xorl %eax, %eax
callq 0x8b10
movl $0x0, 0x70(%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq