// File: /workspace/github_cpp_makefile_star2_O2/cpearce[P]OggIndex/src/Decoder.cpp
// Function: SkeletonDecoder::Decode(ogg_page*, long)
bool SkeletonDecoder::Decode(ogg_page* page, ogg_int64_t offset) {
  int ret = ogg_stream_pagein(&mState, page);
  assert(ret == 0);

  ogg_packet packet;
  int num_packets = 0;
  while (true) {

    ret = ogg_stream_packetout(&mState, &packet);
    if (ret == 0) {
      // We need another page to decode more packets.
      return true;
    }
    if (ret == -1) {
      // Some kind of error?
      return true;
    }
    assert(ret == 1);
    num_packets++;

    if (IsIndexPacket(&packet)) {
      assert(!packet.e_o_s);
      if (SKELETON_VERSION(SKELETON_VERSION_MAJOR,SKELETON_VERSION_MINOR) != mVersion) {
        cerr << "WARNING: Encountered an index packet of version " 
             << mVersionMajor << "." << mVersionMinor
             << ". I can only read version "
             << SKELETON_VERSION_MAJOR << "." << SKELETON_VERSION_MINOR 
             << ", so skipping index packet." << endl;
      } else if (!::DecodeIndex(mIndex, &packet)) {
        cerr << "WARNING: Index packet " << packet.packetno << " of stream "
             << ogg_page_serialno(page) << " failed to parse." << endl;
      }
    } else if (IsSkeletonPacket(&packet)) {
      assert(!IsIndexPacket(&packet));
      // Don't record index packets, we'll recompute them.
      mPackets.push_back(Clone(&packet));
    }
    
    // Check if the skeleton version is 3.x, fail otherwise.
    if (IsFisheadPacket(&packet)) {
      mVersionMajor = LEUint16(packet.packet + 8);
      mVersionMinor = LEUint16(packet.packet + 10);
      mVersion = SKELETON_VERSION(mVersionMajor, mVersionMinor);
      if (mVersion < SKELETON_VERSION(3,0) ||
          mVersion > SKELETON_VERSION(4,0)) { 
        cerr << "FAIL: Skeleton version " << mVersionMajor << "." << mVersionMinor   
             << " detected. I can only handle version [3.x,4.0]" << endl;
        exit(-1);
      }
    }
    
    // We've read all headers when we receive the EOS packet.
    if (packet.e_o_s) {
      mGotAllHeaders = true;
      return true;
    }
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %r15
movq %r15, %rdi
movq %rsi, 0x10(%rsp)
callq 0x4500
testl %eax, %eax
jne 0x4de0
leaq 0x1d0(%rbx), %r12
leaq 0x1e8(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x28(%rsp), %rbp
movq 0x1050d(%rip), %r14     # 0x14ff0
movq %r15, 0x8(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4550
cmpl $0x1, %eax
jne 0x4d0c
movq %rbp, %rdi
callq 0xa990
movq 0x40(%rsp), %rcx
testb %al, %al
je 0x4b9b
testq %rcx, %rcx
jne 0x4d43
cmpl $0x40000, 0x220(%rbx)   # imm = 0x40000
jne 0x4c18
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x4dff
testb %al, %al
jne 0x4c9d
movq %r14, %rdi
leaq 0x95b0(%rip), %rsi      # 0xe0f9
callq 0x4340
movq 0x50(%rsp), %rsi
movq %rax, %rdi
callq 0x4320
movq %rax, %rdi
leaq 0x95ab(%rip), %rsi      # 0xe110
callq 0x4340
movq %r14, %r13
movq %rax, %r14
movq 0x10(%rsp), %rdi
callq 0x42c0
movq %r14, %rdi
movq %r13, %r14
movq 0x8(%rsp), %r15
movl %eax, %esi
callq 0x4650
movq %rax, %rdi
leaq 0x9586(%rip), %rsi      # 0xe11c
jmp 0x4c90
testq %rcx, %rcx
setne %cl
movq 0x30(%rsp), %rax
testq %rax, %rax
sete %dl
testb %dl, %cl
jne 0x4be9
cmpq $0x9, %rax
jl 0x4bd9
movq 0x28(%rsp), %rax
movabsq $0x64616568736966, %rcx # imm = 0x64616568736966
cmpq %rcx, (%rax)
je 0x4be9
movabsq $0x656e6f62736966, %rcx # imm = 0x656E6F62736966
cmpq %rcx, (%rax)
je 0x4be9
movq %rbp, %rdi
callq 0xa990
testb %al, %al
je 0x4c9d
movq %rbp, %rdi
callq 0xa990
testb %al, %al
jne 0x4dc1
movq %rbp, %rdi
callq 0xa935
movq %rax, 0x20(%rsp)
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x6f9a
jmp 0x4c9d
movq %r14, %rdi
leaq 0x946f(%rip), %rsi      # 0xe091
callq 0x4340
movzwl 0x21a(%rbx), %esi
movq %rax, %rdi
callq 0x4610
movq %rax, %rdi
leaq 0x9f2d(%rip), %r13      # 0xeb6d
movq %r13, %rsi
callq 0x4340
movzwl 0x21c(%rbx), %esi
movq %rax, %rdi
callq 0x4610
movq %rax, %rdi
leaq 0x9461(%rip), %rsi      # 0xe0c2
callq 0x4340
movq %rax, %rdi
pushq $0x4
popq %rsi
callq 0x4650
movq %rax, %rdi
movq %r13, %rsi
callq 0x4340
movq %rax, %rdi
xorl %esi, %esi
callq 0x4650
movq %rax, %rdi
leaq 0x944d(%rip), %rsi      # 0xe0dd
callq 0x4340
movq %rax, %rdi
callq 0x41b0
movq %rbp, %rdi
callq 0xaf28
testb %al, %al
je 0x4cf7
movq 0x28(%rsp), %rdi
addq $0x8, %rdi
callq 0xb1cc
movw %ax, 0x21a(%rbx)
movq 0x28(%rsp), %rdi
addq $0xa, %rdi
callq 0xb1cc
movw %ax, 0x21c(%rbx)
movzwl 0x21a(%rbx), %ecx
movl %ecx, %edx
shll $0x10, %edx
movzwl %ax, %eax
orl %edx, %eax
movl %eax, 0x220(%rbx)
cmpw $0x3, %cx
jb 0x4d62
cmpl $0x40001, %eax          # imm = 0x40001
jae 0x4d62
cmpq $0x0, 0x40(%rsp)
je 0x4ae8
movb $0x1, 0x218(%rbx)
jmp 0x4d13
incl %eax
cmpl $0x2, %eax
jae 0x4d24
movb $0x1, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x934f(%rip), %rdi      # 0xe07a
leaq 0x92db(%rip), %rsi      # 0xe00d
leaq 0x9303(%rip), %rcx      # 0xe03c
movl $0x3c0, %edx            # imm = 0x3C0
callq 0x4210
leaq 0x9339(%rip), %rdi      # 0xe083
leaq 0x92bc(%rip), %rsi      # 0xe00d
leaq 0x92e4(%rip), %rcx      # 0xe03c
movl $0x3c4, %edx            # imm = 0x3C4
callq 0x4210
movq 0x10287(%rip), %rdi     # 0x14ff0
leaq 0x93d6(%rip), %rsi      # 0xe146
callq 0x4340
movzwl 0x21a(%rbx), %esi
movq %rax, %rdi
callq 0x4610
leaq 0x9de2(%rip), %rsi      # 0xeb6d
movq %rax, %rdi
callq 0x4340
movzwl 0x21c(%rbx), %esi
movq %rax, %rdi
callq 0x4610
leaq 0x93b5(%rip), %rsi      # 0xe15e
movq %rax, %rdi
callq 0x4340
movq %rax, %rdi
callq 0x41b0
pushq $-0x1
popq %rdi
callq 0x43e0
leaq 0x9366(%rip), %rdi      # 0xe12e
leaq 0x923e(%rip), %rsi      # 0xe00d
leaq 0x9266(%rip), %rcx      # 0xe03c
movl $0x3d0, %edx            # imm = 0x3D0
callq 0x4210
leaq 0x921d(%rip), %rdi      # 0xe004
leaq 0x921f(%rip), %rsi      # 0xe00d
leaq 0x9247(%rip), %rcx      # 0xe03c
movl $0x3b1, %edx            # imm = 0x3B1
callq 0x4210