// File: /workspace/github_cpp_makefile_star2_O1/cpearce[P]OggIndex/src/Decoder.cpp
// Function: VorbisDecoder::Decode(ogg_page*, long)
bool Decode(ogg_page* page, ogg_int64_t offset) {
    if (GotAllHeaders()) {
      // Reset the vorbis syntheis. This simulates what happens when we seek
      // to this page and start decoding with no prior knowledge. This forces
      // the decoder to preroll again.
      ogg_stream_reset(&mState);
      vorbis_synthesis_restart(&mDsp);
    }

    ogg_packet packet;
    assert(ogg_stream_packetout(&mState, &packet) == 0);
    int ret = ogg_stream_pagein(&mState, page);
    assert(ret == 0);
    int total_samples = 0;
    ogg_int64_t start_time = -1;

    while ((ret = ogg_stream_packetout(&mState, &packet)) == 1) {

      if (!GotAllHeaders()) {
        ogg_int32_t ret = vorbis_synthesis_headerin(&mInfo, &mComment, &packet);
        if (ret == 0) {
          mHeadersRead++;
        }
        if (gOptions.GetDumpPackets()) {
          cout << "[V] ver="
               << (int)mInfo.version << " "
               << VorbisHeaderType(&packet) << " packet"
               << (packet.e_o_s ? " eos" : "")
               << endl;
        }
        if (GotAllHeaders()) {
          ret = vorbis_synthesis_init(&mDsp, &mInfo);
          assert(ret == 0);
          ret = vorbis_block_init(&mDsp, &mBlock);
          assert(ret == 0);
        }
        continue;
      }
      assert(GotAllHeaders());

      // Decode page, get start and end time.
      // 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, &packet) == 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);
      }

      if (packet.granulepos != -1) {
        assert(packet.granulepos == ogg_page_granulepos(page));
        ogg_int64_t start_granule = packet.granulepos - total_samples;
        start_time = Time(start_granule);
        if (!mGotFirstContentPage && start_time < 0) {
          // The first content page may specify fewer samples in its granulepos
          // than are actually in the the first page. As per the vorbis spec,
          // these should not be played, so we exclude them here.
          start_time = 0;
        }
        ogg_int64_t end_time = Time(packet.granulepos);

        mGotFirstContentPage = true;


        // First packet will be included in the index, the cut off threshold
        // is then set relative to that.

        if (gOptions.GetDumpKeyPackets() || gOptions.GetDumpPackets()) {
          cout << "[V] sample time_ms=[" << start_time << "," << end_time
               << "] granulepos=[" << start_granule << ","
               << packet.granulepos << "]"
               << (packet.e_o_s ? " eos" : "")
               << endl;
        }    

        assert(start_time >= 0);
        if (start_time > mNextKeyframeThreshold) {
          mKeyFrames.push_back(KeyFrameInfo(offset, start_time));
          mNextKeyframeThreshold = Time(ogg_page_granulepos(page)) +
                                   gOptions.GetKeyPointInterval();
        }
        assert(ogg_stream_packetout(&mState, &packet) == 0);
        
        if (mStartTime == -1) {
          mStartTime = start_time;
        }
        mEndTime = end_time;

      }
    } // while packetout

    return true;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, 0x78(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
je 0x6de1
leaq 0x8(%r15), %rdi
callq 0x4390
leaq 0x238(%r15), %rdi
callq 0x4540
leaq 0x8(%r15), %rbp
leaq 0x38(%rsp), %rsi
movq %rbp, %rdi
callq 0x45a0
testl %eax, %eax
jne 0x735a
movq %rbp, %rdi
movq %rbx, 0x30(%rsp)
movq %rbx, %rsi
callq 0x4550
testl %eax, %eax
jne 0x7379
leaq 0x38(%rsp), %rsi
movq %rbp, %rdi
callq 0x45a0
cmpl $0x1, %eax
jne 0x72e9
leaq 0x1e0(%r15), %r14
leaq 0x218(%r15), %rbx
leaq 0x238(%r15), %r13
leaq 0x2c8(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x1c0(%r15), %rax
movq %rax, 0x70(%rsp)
movq $-0x1, 0x8(%rsp)
xorl %r12d, %r12d
movq %r13, 0x10(%rsp)
movq %rbx, 0x80(%rsp)
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
testb %al, %al
jne 0x6ff3
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x38(%rsp), %rdx
callq 0x4130
testl %eax, %eax
jne 0x6e9a
incl 0x1dc(%r15)
leaq 0x1057f(%rip), %rdi     # 0x17420
callq 0x8c4e
testb %al, %al
je 0x6fa3
movq %rbp, %r13
movl $0x8, %edx
movq 0x10113(%rip), %rbp     # 0x16fd0
movq %rbp, %rdi
leaq 0x9892(%rip), %rsi      # 0x10759
callq 0x4410
movq %r14, %rbx
movl (%r14), %esi
movq %rbp, %rdi
callq 0x46a0
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0xa6ec(%rip), %rsi      # 0x115d8
callq 0x4410
movq 0x38(%rsp), %rax
movb (%rax), %al
decb %al
leaq 0x96bc(%rip), %r14      # 0x105bd
cmpb $0x4, %al
ja 0x6f16
movzbl %al, %eax
leaq 0x9961(%rip), %rcx      # 0x10870
movslq (%rcx,%rax,4), %r14
addq %rcx, %r14
movq %r14, %rdi
callq 0x4170
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4410
movl $0x7, %edx
movq %rbp, %rdi
leaq 0x94a6(%rip), %rsi      # 0x103e1
callq 0x4410
xorl %edx, %edx
cmpq $0x0, 0x50(%rsp)
setne %dl
leaq 0x9497(%rip), %rsi      # 0x103e9
leaq 0xa4d1(%rip), %rax      # 0x1142a
cmoveq %rax, %rsi
shll $0x2, %edx
movq %rbp, %rdi
callq 0x4410
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x4360
movsbl %al, %esi
movq %rbp, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4250
movq %r13, %rbp
movq %rbx, %r14
movq 0x80(%rsp), %rbx
movq 0x10(%rsp), %r13
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
testb %al, %al
je 0x6fd8
movq %r13, %rdi
movq %r14, %rsi
callq 0x4310
testl %eax, %eax
jne 0x733b
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x44d0
testl %eax, %eax
jne 0x731c
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
callq 0x45a0
cmpl $0x1, %eax
je 0x6e6e
jmp 0x72e9
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
testb %al, %al
je 0x7398
cmpq $-0x1, 0x8(%rsp)
movq 0x18(%rsp), %rdi
jne 0x73b7
leaq 0x38(%rsp), %rsi
callq 0x41e0
testl %eax, %eax
jne 0x7038
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x42b0
testl %eax, %eax
jne 0x7433
movq %r13, %rdi
xorl %esi, %esi
callq 0x4420
testl %eax, %eax
jle 0x705c
addl %eax, %r12d
movq %r13, %rdi
movl %eax, %esi
callq 0x4560
testl %eax, %eax
je 0x7038
jmp 0x72fd
movq %r14, 0x28(%rsp)
movq 0x58(%rsp), %r14
cmpq $-0x1, %r14
je 0x7259
movq 0x30(%rsp), %rdi
callq 0x4620
cmpq %rax, %r14
jne 0x73d6
movq 0x58(%rsp), %r14
movl %r12d, %eax
subq %rax, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x757c
cmpb $0x0, 0x1d8(%r15)
movl $0x0, %r13d
cmovneq %rax, %r13
testq %rax, %rax
cmovnsq %rax, %r13
movq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x757c
movq %rax, 0x20(%rsp)
movb $0x1, 0x1d8(%r15)
leaq 0x1034d(%rip), %rax     # 0x17420
cmpb $0x0, 0x1(%rax)
movq %r13, 0x8(%rsp)
jne 0x70f2
leaq 0x1033b(%rip), %rdi     # 0x17420
callq 0x8c4e
testb %al, %al
je 0x71fa
movl $0x14, %edx
movq %r14, 0x68(%rsp)
movq 0xfecd(%rip), %r14      # 0x16fd0
movq %r14, %rdi
leaq 0x96a5(%rip), %rsi      # 0x107b2
callq 0x4410
movq %r14, %rdi
movq %r13, %rsi
callq 0x4340
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9fef(%rip), %r13      # 0x1111e
movq %r13, %rsi
callq 0x4410
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x4340
movq %rax, %r14
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9671(%rip), %rsi      # 0x107c7
callq 0x4410
movq %r14, %rdi
movq 0x68(%rsp), %rsi
callq 0x4340
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %r13
callq 0x4410
movq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x4340
movq %rbp, %r14
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x8fe9(%rip), %rsi      # 0x1018b
callq 0x4410
xorl %edx, %edx
cmpq $0x0, 0x50(%rsp)
setne %dl
leaq 0x9230(%rip), %rsi      # 0x103e9
leaq 0xa26a(%rip), %rax      # 0x1142a
cmoveq %rax, %rsi
shll $0x2, %edx
movq %rbp, %rdi
callq 0x4410
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x4360
movsbl %al, %esi
movq %rbp, %rdi
movq %r14, %rbp
callq 0x4040
movq %rax, %rdi
callq 0x4250
testq %r13, %r13
js 0x73f5
cmpq 0x1b8(%r15), %r13
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %r13
jle 0x72ad
movq 0x78(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x1c8(%r15), %rsi
cmpq 0x1d0(%r15), %rsi
je 0x7271
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x1c8(%r15)
jmp 0x7283
movq $-0x1, 0x8(%rsp)
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %r13
jmp 0x6fd8
movq 0x70(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x75cc
movq 0x30(%rsp), %rdi
callq 0x4620
movq %r15, %rdi
movq %rax, %rsi
callq 0x757c
leaq 0x10181(%rip), %rcx     # 0x17420
movslq 0x48(%rcx), %rcx
addq %rax, %rcx
movq %rcx, 0x1b8(%r15)
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
callq 0x45a0
testl %eax, %eax
jne 0x7414
cmpq $-0x1, 0x1a8(%r15)
jne 0x72d8
movq 0x8(%rsp), %rax
movq %rax, 0x1a8(%r15)
movq 0x20(%rsp), %rax
movq %rax, 0x1b0(%r15)
jmp 0x6fd8
movb $0x1, %al
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8d00(%rip), %rdi      # 0x10004
leaq 0x8d02(%rip), %rsi      # 0x1000d
leaq 0x940b(%rip), %rcx      # 0x1071d
movl $0x1e9, %edx            # imm = 0x1E9
callq 0x4210
leaq 0x8ce1(%rip), %rdi      # 0x10004
leaq 0x8ce3(%rip), %rsi      # 0x1000d
leaq 0x93ec(%rip), %rcx      # 0x1071d
movl $0x1d6, %edx            # imm = 0x1D6
callq 0x4210
leaq 0x8cc2(%rip), %rdi      # 0x10004
leaq 0x8cc4(%rip), %rsi      # 0x1000d
leaq 0x93cd(%rip), %rcx      # 0x1071d
movl $0x1d4, %edx            # imm = 0x1D4
callq 0x4210
leaq 0x9390(%rip), %rdi      # 0x106f1
leaq 0x8ca5(%rip), %rsi      # 0x1000d
leaq 0x93ae(%rip), %rcx      # 0x1071d
movl $0x1be, %edx            # imm = 0x1BE
callq 0x4210
leaq 0x8c84(%rip), %rdi      # 0x10004
leaq 0x8c86(%rip), %rsi      # 0x1000d
leaq 0x938f(%rip), %rcx      # 0x1071d
movl $0x1c0, %edx            # imm = 0x1C0
callq 0x4210
leaq 0x93c3(%rip), %rdi      # 0x10762
leaq 0x8c67(%rip), %rsi      # 0x1000d
leaq 0x9370(%rip), %rcx      # 0x1071d
movl $0x1da, %edx            # imm = 0x1DA
callq 0x4210
leaq 0x93b4(%rip), %rdi      # 0x10772
leaq 0x8c48(%rip), %rsi      # 0x1000d
leaq 0x9351(%rip), %rcx      # 0x1071d
movl $0x1de, %edx            # imm = 0x1DE
callq 0x4210
leaq 0x93a6(%rip), %rdi      # 0x10783
leaq 0x8c29(%rip), %rsi      # 0x1000d
leaq 0x9332(%rip), %rcx      # 0x1071d
movl $0x1ed, %edx            # imm = 0x1ED
callq 0x4210
leaq 0x93da(%rip), %rdi      # 0x107d6
leaq 0x8c0a(%rip), %rsi      # 0x1000d
leaq 0x9313(%rip), %rcx      # 0x1071d
movl $0x206, %edx            # imm = 0x206
callq 0x4210
leaq 0x92d6(%rip), %rdi      # 0x106f1
leaq 0x8beb(%rip), %rsi      # 0x1000d
leaq 0x92f4(%rip), %rcx      # 0x1071d
movl $0x20c, %edx            # imm = 0x20C
callq 0x4210
leaq 0x8bca(%rip), %rdi      # 0x10004
leaq 0x8bcc(%rip), %rsi      # 0x1000d
leaq 0x92d5(%rip), %rcx      # 0x1071d
movl $0x1e4, %edx            # imm = 0x1E4
callq 0x4210