// File: 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:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq 0x80(%rsp), %rdi
movq %rdi, 0x10(%rsp)
addq $0x10, %rdi
leaq 0x40(%rsp), %rsi
callq 0x5680
cmpl $0x0, %eax
jne 0x1ac3b
jmp 0x1ac5a
leaq 0x42f2(%rip), %rdi      # 0x1ef34
leaq 0x3cfe(%rip), %rsi      # 0x1e947
movl $0x120, %edx            # imm = 0x120
leaq 0x430d(%rip), %rcx      # 0x1ef62
callq 0x5280
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
movq 0x78(%rsp), %rsi
callq 0x5620
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jne 0x1ac7a
jmp 0x1ac99
leaq 0x2383(%rip), %rdi      # 0x1d004
leaq 0x3cbf(%rip), %rsi      # 0x1e947
movl $0x122, %edx            # imm = 0x122
leaq 0x42ce(%rip), %rcx      # 0x1ef62
callq 0x5280
movl $0x0, 0x38(%rsp)
movq $-0x1, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
leaq 0x40(%rsp), %rsi
callq 0x5680
cmpl $0x1, %eax
jne 0x1afd9
movq 0x10(%rsp), %rax
movl 0x2c(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x2c(%rsp)
testb $0x1, 0xc(%rax)
jne 0x1addb
movq 0x10(%rsp), %rsi
movq %rsi, %rdi
addq $0x1a8, %rdi            # imm = 0x1A8
addq $0x1e0, %rsi            # imm = 0x1E0
leaq 0x40(%rsp), %rdx
callq 0x5130
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
jne 0x1ad27
movq 0x10(%rsp), %rax
movl 0x350(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x350(%rax)
movq 0x10(%rsp), %rax
cmpl $0x3, 0x350(%rax)
sete %cl
andb $0x1, %cl
movb %cl, 0xc(%rax)
testb $0x1, 0xc(%rax)
je 0x1add6
movq 0x10(%rsp), %rsi
movq %rsi, %rdi
addq $0x200, %rdi            # imm = 0x200
addq $0x1a8, %rsi            # imm = 0x1A8
callq 0x5390
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
jne 0x1ad6e
jmp 0x1ad8d
leaq 0x228f(%rip), %rdi      # 0x1d004
leaq 0x3bcb(%rip), %rsi      # 0x1e947
movl $0x130, %edx            # imm = 0x130
leaq 0x41da(%rip), %rcx      # 0x1ef62
callq 0x5280
movq 0x10(%rsp), %rsi
movq %rsi, %rdi
addq $0x200, %rdi            # imm = 0x200
addq $0x290, %rsi            # imm = 0x290
callq 0x55a0
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
jne 0x1adb5
jmp 0x1add4
leaq 0x2248(%rip), %rdi      # 0x1d004
leaq 0x3b84(%rip), %rsi      # 0x1e947
movl $0x132, %edx            # imm = 0x132
leaq 0x4193(%rip), %rcx      # 0x1ef62
callq 0x5280
jmp 0x1add6
jmp 0x1acb2
cmpq $-0x1, 0x30(%rsp)
jne 0x1ade5
jmp 0x1ae04
leaq 0x2986(%rip), %rdi      # 0x1d772
leaq 0x3b54(%rip), %rsi      # 0x1e947
movl $0x138, %edx            # imm = 0x138
leaq 0x4163(%rip), %rcx      # 0x1ef62
callq 0x5280
movq 0x10(%rsp), %rdi
movl $0x0, 0x24(%rsp)
addq $0x290, %rdi            # imm = 0x290
leaq 0x40(%rsp), %rsi
callq 0x5220
cmpl $0x0, %eax
jne 0x1ae70
movq 0x10(%rsp), %rsi
movq %rsi, %rdi
addq $0x200, %rdi            # imm = 0x200
addq $0x290, %rsi            # imm = 0x290
callq 0x5330
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jne 0x1ae4f
jmp 0x1ae6e
leaq 0x21ae(%rip), %rdi      # 0x1d004
leaq 0x3aea(%rip), %rsi      # 0x1e947
movl $0x13e, %edx            # imm = 0x13E
leaq 0x40f9(%rip), %rcx      # 0x1ef62
callq 0x5280
jmp 0x1ae70
jmp 0x1ae72
movq 0x10(%rsp), %rdi
addq $0x200, %rdi            # imm = 0x200
xorl %eax, %eax
movl %eax, %esi
callq 0x54b0
movl %eax, 0x24(%rsp)
cmpl $0x0, %eax
jle 0x1aedf
movq 0x10(%rsp), %rdi
movl 0x24(%rsp), %eax
addl 0x38(%rsp), %eax
movl %eax, 0x38(%rsp)
addq $0x200, %rdi            # imm = 0x200
movl 0x24(%rsp), %esi
callq 0x5640
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jne 0x1aebe
jmp 0x1aedd
leaq 0x213f(%rip), %rdi      # 0x1d004
leaq 0x3a7b(%rip), %rsi      # 0x1e947
movl $0x143, %edx            # imm = 0x143
leaq 0x408a(%rip), %rcx      # 0x1ef62
callq 0x5280
jmp 0x1ae72
cmpq $-0x1, 0x30(%rsp)
jne 0x1aee9
jmp 0x1af08
leaq 0x2882(%rip), %rdi      # 0x1d772
leaq 0x3a50(%rip), %rsi      # 0x1e947
movl $0x146, %edx            # imm = 0x146
leaq 0x405f(%rip), %rcx      # 0x1ef62
callq 0x5280
cmpq $-0x1, 0x60(%rsp)
je 0x1afd4
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x78(%rsp), %rdi
callq 0x56e0
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jne 0x1af37
jmp 0x1af56
leaq 0x3e41(%rip), %rdi      # 0x1ed7f
leaq 0x3a02(%rip), %rsi      # 0x1e947
movl $0x148, %edx            # imm = 0x148
leaq 0x4011(%rip), %rcx      # 0x1ef62
callq 0x5280
movslq 0x38(%rsp), %rax
cmpq 0x60(%rsp), %rax
jge 0x1af75
movq 0x60(%rsp), %rax
movslq 0x38(%rsp), %rcx
subq %rcx, %rax
movq %rax, (%rsp)
jmp 0x1af7d
xorl %eax, %eax
movq %rax, (%rsp)
jmp 0x1af7d
movq 0x10(%rsp), %rcx
movq (%rsp), %rax
movq %rax, 0x18(%rsp)
imulq $0x3e8, 0x18(%rsp), %rax # imm = 0x3E8
movq 0x208(%rcx), %rcx
cqto
idivq 0x8(%rcx)
movq %rax, 0x30(%rsp)
movq 0x78(%rsp), %rdi
callq 0x56e0
movq 0x10(%rsp), %rcx
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movq 0x208(%rcx), %rcx
cqto
idivq 0x8(%rcx)
movq %rax, %rcx
movq 0x70(%rsp), %rax
movq %rcx, (%rax)
jmp 0x1acb2
movq 0x30(%rsp), %rax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)