// File: /workspace/github_cpp_makefile_star2_O3/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 0x6d21
leaq 0x8(%r15), %rdi
callq 0x4390
leaq 0x238(%r15), %rdi
callq 0x4530
leaq 0x8(%r15), %rbp
leaq 0x38(%rsp), %rsi
movq %rbp, %rdi
callq 0x4590
testl %eax, %eax
jne 0x729a
movq %rbp, %rdi
movq %rbx, 0x30(%rsp)
movq %rbx, %rsi
callq 0x4540
testl %eax, %eax
jne 0x72b9
leaq 0x38(%rsp), %rsi
movq %rbp, %rdi
callq 0x4590
cmpl $0x1, %eax
jne 0x7229
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 0x6f33
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x38(%rsp), %rdx
callq 0x4130
testl %eax, %eax
jne 0x6dda
incl 0x1dc(%r15)
leaq 0x1062f(%rip), %rdi     # 0x17410
callq 0x8b3a
testb %al, %al
je 0x6ee3
movq %rbp, %r13
movl $0x8, %edx
movq 0x101d3(%rip), %rbp     # 0x16fd0
movq %rbp, %rdi
leaq 0x9952(%rip), %rsi      # 0x10759
callq 0x4410
movq %r14, %rbx
movl (%r14), %esi
movq %rbp, %rdi
callq 0x4690
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0xa79c(%rip), %rsi      # 0x115c8
callq 0x4410
movq 0x38(%rsp), %rax
movb (%rax), %al
decb %al
leaq 0x977c(%rip), %r14      # 0x105bd
cmpb $0x4, %al
ja 0x6e56
movzbl %al, %eax
leaq 0x9a21(%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 0x9566(%rip), %rsi      # 0x103e1
callq 0x4410
xorl %edx, %edx
cmpq $0x0, 0x50(%rsp)
setne %dl
leaq 0x9557(%rip), %rsi      # 0x103e9
leaq 0xa581(%rip), %rax      # 0x1141a
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 0x6f18
movq %r13, %rdi
movq %r14, %rsi
callq 0x4310
testl %eax, %eax
jne 0x727b
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x44d0
testl %eax, %eax
jne 0x725c
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
callq 0x4590
cmpl $0x1, %eax
je 0x6dae
jmp 0x7229
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
testb %al, %al
je 0x72d8
cmpq $-0x1, 0x8(%rsp)
movq 0x18(%rsp), %rdi
jne 0x72f7
leaq 0x38(%rsp), %rsi
callq 0x41e0
testl %eax, %eax
jne 0x6f78
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x42b0
testl %eax, %eax
jne 0x7373
movq %r13, %rdi
xorl %esi, %esi
callq 0x4420
testl %eax, %eax
jle 0x6f9c
addl %eax, %r12d
movq %r13, %rdi
movl %eax, %esi
callq 0x4550
testl %eax, %eax
je 0x6f78
jmp 0x723d
movq %r14, 0x28(%rsp)
movq 0x58(%rsp), %r14
cmpq $-0x1, %r14
je 0x7199
movq 0x30(%rsp), %rdi
callq 0x4610
cmpq %rax, %r14
jne 0x7316
movq 0x58(%rsp), %r14
movl %r12d, %eax
subq %rax, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x74b2
cmpb $0x0, 0x1d8(%r15)
movl $0x0, %r13d
cmovneq %rax, %r13
testq %rax, %rax
cmovnsq %rax, %r13
movq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x74b2
movq %rax, 0x20(%rsp)
movb $0x1, 0x1d8(%r15)
leaq 0x103fd(%rip), %rax     # 0x17410
cmpb $0x0, 0x1(%rax)
movq %r13, 0x8(%rsp)
jne 0x7032
leaq 0x103eb(%rip), %rdi     # 0x17410
callq 0x8b3a
testb %al, %al
je 0x713a
movl $0x14, %edx
movq %r14, 0x68(%rsp)
movq 0xff8d(%rip), %r14      # 0x16fd0
movq %r14, %rdi
leaq 0x9765(%rip), %rsi      # 0x107b2
callq 0x4410
movq %r14, %rdi
movq %r13, %rsi
callq 0x4340
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0xa09f(%rip), %r13      # 0x1110e
movq %r13, %rsi
callq 0x4410
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x4340
movq %rax, %r14
movl $0xe, %edx
movq %rax, %rdi
leaq 0x9731(%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 0x90a9(%rip), %rsi      # 0x1018b
callq 0x4410
xorl %edx, %edx
cmpq $0x0, 0x50(%rsp)
setne %dl
leaq 0x92f0(%rip), %rsi      # 0x103e9
leaq 0xa31a(%rip), %rax      # 0x1141a
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 0x7335
cmpq 0x1b8(%r15), %r13
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %r13
jle 0x71ed
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 0x71b1
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x1c8(%r15)
jmp 0x71c3
movq $-0x1, 0x8(%rsp)
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %r13
jmp 0x6f18
movq 0x70(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x7502
movq 0x30(%rsp), %rdi
callq 0x4610
movq %r15, %rdi
movq %rax, %rsi
callq 0x74b2
leaq 0x10231(%rip), %rcx     # 0x17410
movslq 0x48(%rcx), %rcx
addq %rax, %rcx
movq %rcx, 0x1b8(%r15)
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
callq 0x4590
testl %eax, %eax
jne 0x7354
cmpq $-0x1, 0x1a8(%r15)
jne 0x7218
movq 0x8(%rsp), %rax
movq %rax, 0x1a8(%r15)
movq 0x20(%rsp), %rax
movq %rax, 0x1b0(%r15)
jmp 0x6f18
movb $0x1, %al
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8dc0(%rip), %rdi      # 0x10004
leaq 0x8dc2(%rip), %rsi      # 0x1000d
leaq 0x94cb(%rip), %rcx      # 0x1071d
movl $0x1e9, %edx            # imm = 0x1E9
callq 0x4210
leaq 0x8da1(%rip), %rdi      # 0x10004
leaq 0x8da3(%rip), %rsi      # 0x1000d
leaq 0x94ac(%rip), %rcx      # 0x1071d
movl $0x1d6, %edx            # imm = 0x1D6
callq 0x4210
leaq 0x8d82(%rip), %rdi      # 0x10004
leaq 0x8d84(%rip), %rsi      # 0x1000d
leaq 0x948d(%rip), %rcx      # 0x1071d
movl $0x1d4, %edx            # imm = 0x1D4
callq 0x4210
leaq 0x9450(%rip), %rdi      # 0x106f1
leaq 0x8d65(%rip), %rsi      # 0x1000d
leaq 0x946e(%rip), %rcx      # 0x1071d
movl $0x1be, %edx            # imm = 0x1BE
callq 0x4210
leaq 0x8d44(%rip), %rdi      # 0x10004
leaq 0x8d46(%rip), %rsi      # 0x1000d
leaq 0x944f(%rip), %rcx      # 0x1071d
movl $0x1c0, %edx            # imm = 0x1C0
callq 0x4210
leaq 0x9483(%rip), %rdi      # 0x10762
leaq 0x8d27(%rip), %rsi      # 0x1000d
leaq 0x9430(%rip), %rcx      # 0x1071d
movl $0x1da, %edx            # imm = 0x1DA
callq 0x4210
leaq 0x9474(%rip), %rdi      # 0x10772
leaq 0x8d08(%rip), %rsi      # 0x1000d
leaq 0x9411(%rip), %rcx      # 0x1071d
movl $0x1de, %edx            # imm = 0x1DE
callq 0x4210
leaq 0x9466(%rip), %rdi      # 0x10783
leaq 0x8ce9(%rip), %rsi      # 0x1000d
leaq 0x93f2(%rip), %rcx      # 0x1071d
movl $0x1ed, %edx            # imm = 0x1ED
callq 0x4210
leaq 0x949a(%rip), %rdi      # 0x107d6
leaq 0x8cca(%rip), %rsi      # 0x1000d
leaq 0x93d3(%rip), %rcx      # 0x1071d
movl $0x206, %edx            # imm = 0x206
callq 0x4210
leaq 0x9396(%rip), %rdi      # 0x106f1
leaq 0x8cab(%rip), %rsi      # 0x1000d
leaq 0x93b4(%rip), %rcx      # 0x1071d
movl $0x20c, %edx            # imm = 0x20C
callq 0x4210
leaq 0x8c8a(%rip), %rdi      # 0x10004
leaq 0x8c8c(%rip), %rsi      # 0x1000d
leaq 0x9395(%rip), %rcx      # 0x1071d
movl $0x1e4, %edx            # imm = 0x1E4
callq 0x4210