// File: /workspace/github_cpp_makefile_star2_O2/cpearce[P]OggIndex/src/Validate.cpp
// Function: Vorbis::Decode(ogg_page*, long&)
virtual ogg_int64_t Decode(ogg_page* page, ogg_int64_t& end_time) {
    ogg_packet op;
    assert(ogg_stream_packetout(&mStreamState, &op) == 0);
    int ret = ogg_stream_pagein(&mStreamState, page);
    assert(ret == 0);
    int total_samples = 0;
    ogg_int64_t start_time = -1;
    int packet_count = 0;
    while (ogg_stream_packetout(&mStreamState, &op) == 1) {
      packet_count++;
      if (!mReadHeaders) {
        ogg_int32_t ret = vorbis_synthesis_headerin(&mInfo, &mComment, &op);
        if (ret == 0) {
          mHeaderPacketsRead++;
        }
        mReadHeaders = (mHeaderPacketsRead == 3);
        if (mReadHeaders) {
          ret = vorbis_synthesis_init(&mDsp, &mInfo);
          assert(ret == 0);
          ret = vorbis_block_init(&mDsp, &mBlock);
          assert(ret == 0);        
        }
        continue;
      }

      // We only expect the last packet in a page to have non -1 granulepos.
      assert(start_time == -1);
      int samples = 0;
      
      // Decode the vorbis to determine how many samples are in each packet.
      if (vorbis_synthesis(&mBlock, &op) == 0) {
        ret = vorbis_synthesis_blockin(&mDsp, &mBlock);
        assert(ret == 0);
      }
      while ((samples = vorbis_synthesis_pcmout(&mDsp, 0)) > 0) {
        total_samples += samples;
        ret = vorbis_synthesis_read(&mDsp, samples);
        assert(ret == 0);
      }
      // We only expect the last packet in a page to have a granulepos.
      assert(start_time == -1);
      if (op.granulepos != -1) {
        assert(op.granulepos == ogg_page_granulepos(page));
        ogg_int64_t start_granule =
          (total_samples < op.granulepos) ? (op.granulepos - total_samples) : 0;
        start_time = (1000 * start_granule) / mDsp.vi->rate;
        end_time = (1000 * ogg_page_granulepos(page)) / mDsp.vi->rate;
      }
    }

    return start_time;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x10(%rdi), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x4550
testl %eax, %eax
jne 0xcbf4
movq %r12, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rsi
callq 0x4500
testl %eax, %eax
jne 0xcc13
leaq 0x1a8(%r15), %r13
leaq 0x1e0(%r15), %rax
movq %rax, 0x20(%rsp)
leaq 0x200(%r15), %rbx
leaq 0x290(%r15), %rax
movq %rax, 0x8(%rsp)
pushq $-0x1
popq %rax
leaq 0x28(%rsp), %r14
xorl %ebp, %ebp
movq %rax, (%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x4550
cmpl $0x1, %eax
jne 0xcb84
cmpb $0x0, 0xc(%r15)
jne 0xcaa6
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
callq 0x4110
movl 0x350(%r15), %ecx
testl %eax, %eax
jne 0xca73
incl %ecx
movl %ecx, 0x350(%r15)
cmpl $0x3, %ecx
sete 0xc(%r15)
jne 0xca34
movq %rbx, %rdi
movq %r13, %rsi
callq 0x42f0
testl %eax, %eax
jne 0xcbb6
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x4490
testl %eax, %eax
je 0xca34
jmp 0xcbd5
cmpq $-0x1, (%rsp)
jne 0xcc32
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x41e0
testl %eax, %eax
jne 0xcad7
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x42a0
testl %eax, %eax
jne 0xcc70
movq %rbx, %rdi
xorl %esi, %esi
callq 0x43d0
testl %eax, %eax
jle 0xcafa
addl %eax, %ebp
movq %rbx, %rdi
movl %eax, %esi
callq 0x4510
testl %eax, %eax
je 0xcad7
jmp 0xcb97
movq 0x48(%rsp), %rcx
pushq $-0x1
popq %rax
movq %rax, (%rsp)
cmpq $-0x1, %rcx
je 0xca34
movq 0x10(%rsp), %rdi
movq %rcx, (%rsp)
callq 0x45c0
cmpq %rax, (%rsp)
jne 0xcc51
movl %ebp, %ecx
movq 0x48(%rsp), %rdx
movq %rdx, %rax
subq %rcx, %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
cmpq %rcx, %rdx
movl $0x0, %ecx
cmovleq %rcx, %rax
movq 0x208(%r15), %rcx
cqto
idivq 0x8(%rcx)
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
callq 0x45c0
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movq 0x208(%r15), %rcx
cqto
idivq 0x8(%rcx)
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
jmp 0xca34
movq (%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1466(%rip), %rdi      # 0xe004
leaq 0x2d9a(%rip), %rsi      # 0xf93f
leaq 0x3374(%rip), %rcx      # 0xff20
movl $0x143, %edx            # imm = 0x143
callq 0x4210
leaq 0x1447(%rip), %rdi      # 0xe004
leaq 0x2d7b(%rip), %rsi      # 0xf93f
leaq 0x3355(%rip), %rcx      # 0xff20
movl $0x130, %edx            # imm = 0x130
callq 0x4210
leaq 0x1428(%rip), %rdi      # 0xe004
leaq 0x2d5c(%rip), %rsi      # 0xf93f
leaq 0x3336(%rip), %rcx      # 0xff20
movl $0x132, %edx            # imm = 0x132
callq 0x4210
leaq 0x32f7(%rip), %rdi      # 0xfef2
leaq 0x2d3d(%rip), %rsi      # 0xf93f
leaq 0x3317(%rip), %rcx      # 0xff20
movl $0x120, %edx            # imm = 0x120
callq 0x4210
leaq 0x13ea(%rip), %rdi      # 0xe004
leaq 0x2d1e(%rip), %rsi      # 0xf93f
leaq 0x32f8(%rip), %rcx      # 0xff20
movl $0x122, %edx            # imm = 0x122
callq 0x4210
leaq 0x1b39(%rip), %rdi      # 0xe772
leaq 0x2cff(%rip), %rsi      # 0xf93f
leaq 0x32d9(%rip), %rcx      # 0xff20
movl $0x138, %edx            # imm = 0x138
callq 0x4210
leaq 0x311f(%rip), %rdi      # 0xfd77
leaq 0x2ce0(%rip), %rsi      # 0xf93f
leaq 0x32ba(%rip), %rcx      # 0xff20
movl $0x148, %edx            # imm = 0x148
callq 0x4210
leaq 0x138d(%rip), %rdi      # 0xe004
leaq 0x2cc1(%rip), %rsi      # 0xf93f
leaq 0x329b(%rip), %rcx      # 0xff20
movl $0x13e, %edx            # imm = 0x13E
callq 0x4210
nop