// File: /workspace/github_cpp_makefile_star2_O2/cpearce[P]OggIndex/src/Validate.cpp
// Function: Skeleton::Decode(ogg_page*, long&)
virtual ogg_int64_t Decode(ogg_page* page, ogg_int64_t& end_time) {
    end_time = -1;
    int ret = ogg_stream_pagein(&mStreamState, page);
    assert(ret == 0);
    ogg_packet op;
    int packets_decoded = 0;
    while ((ret = ogg_stream_packetout(&mStreamState, &op)) != 0) {
      packets_decoded++;
      assert(!mReadHeaders);
      if (ret != 1) {
        cout << "WARNING: out of sync while reading skeleton packets!" << endl;
        continue;
      }

      if (IsFisheadPacket(&op)) {
        ogg_uint16_t ver_maj = LEUint16(op.packet + SKELETON_VERSION_MAJOR_OFFSET);
        ogg_uint16_t ver_min = LEUint16(op.packet + SKELETON_VERSION_MINOR_OFFSET);
        ogg_uint32_t version = SKELETON_VERSION(ver_maj, ver_min);
        if (version != SKELETON_VERSION(SKELETON_VERSION_MAJOR,SKELETON_VERSION_MINOR)) { 
          cerr << "FAIL: Skeleton version " << ver_maj << "." <<ver_min   
               << " detected. I can only validate version "
               << SKELETON_VERSION_MAJOR << "." << SKELETON_VERSION_MINOR << endl;
          exit(-1);
        }
        mContentOffset = LEUint64(op.packet + SKELETON_CONTENT_OFFSET);
        if (mContentOffset == 0) {
          cerr << "Verification Failure: content offset is 0" << endl;
          return false;
        }

        mFileLength = LEUint64(op.packet + SKELETON_FILE_LENGTH_OFFSET);
        continue;
      }
      
      if (IsFisbonePacket(&op)) {
        // Nothing to check here.
        continue;
      }
      
      if (IsIndexPacket(&op)) {
        bool r = DecodeIndex(mIndex, &op);
        if (!r) {
          cerr << "FAIL: Can't parse skeleton index packet." << endl;
        }
        continue;
      }

      if (op.e_o_s) {
        assert(ogg_page_eos(page) != 0);
        mReadHeaders = true;
        continue;
      }

      cout << "WARNING: Unknown packet in skeleton track!" << endl;
    }  
    if (packets_decoded != ogg_page_packets(page)) {
      cout << "WARNING: Only decoded " << packets_decoded << " packets from "
           << "skeleon page, but expected " << ogg_page_packets(page) << endl;
    }
    return true;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
orq $-0x1, (%rdx)
leaq 0x10(%rdi), %r15
movq %r15, %rdi
movq %rsi, 0x8(%rsp)
callq 0x4500
testl %eax, %eax
jne 0xd019
leaq 0x1a8(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x18(%rsp), %r12
movq 0x8234(%rip), %rbx      # 0x14fd0
leaq 0x3226(%rip), %r13      # 0xffc9
movq %r15, %rdi
movq %r12, %rsi
callq 0x4550
testl %eax, %eax
je 0xcee6
cmpb $0x1, 0xc(%r14)
je 0xcf80
cmpl $0x1, %eax
jne 0xce66
movq %r12, %rdi
callq 0xaf28
testb %al, %al
je 0xce80
movl %ebp, 0x4(%rsp)
movq %r15, %rbp
movq %r12, %r15
movq %rbx, %r13
movq 0x18(%rsp), %rdi
addq $0x8, %rdi
callq 0xb1cc
movl %eax, %r12d
movq 0x18(%rsp), %rdi
addq $0xa, %rdi
callq 0xb1cc
movl %r12d, %ecx
shll $0x10, %ecx
movzwl %ax, %ebx
orl %ebx, %ecx
cmpl $0x40000, %ecx          # imm = 0x40000
jne 0xcf9f
movq 0x18(%rsp), %rdi
addq $0x48, %rdi
callq 0xb036
movq %rax, 0x1e0(%r14)
testq %rax, %rax
je 0xcf51
movq %r13, %rbx
movq 0x18(%rsp), %rdi
addq $0x40, %rdi
callq 0xb036
movq %rax, 0x1d8(%r14)
movq %r15, %r12
movq %rbp, %r15
movl 0x4(%rsp), %ebp
leaq 0x3165(%rip), %r13      # 0xffc9
jmp 0xce79
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4340
movq %rax, %rdi
callq 0x41b0
incl %ebp
jmp 0xcda3
movq %r12, %rdi
callq 0xaf4b
testb %al, %al
jne 0xce79
movq %r12, %rdi
callq 0xa990
testb %al, %al
je 0xceb9
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x4dff
testb %al, %al
jne 0xce79
movq 0x8140(%rip), %rdi      # 0x14ff0
leaq 0x3199(%rip), %rsi      # 0x10050
jmp 0xce6c
cmpq $0x0, 0x30(%rsp)
je 0xceda
movq 0x8(%rsp), %rdi
callq 0x4100
testl %eax, %eax
je 0xd038
movb $0x1, 0xc(%r14)
jmp 0xce79
movq %rbx, %rdi
leaq 0x31ad(%rip), %rsi      # 0x10091
jmp 0xce6c
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x46b0
cmpl %ebp, %eax
jne 0xcefc
pushq $0x1
popq %rbx
jmp 0xcf6e
movq 0x80cd(%rip), %rdi      # 0x14fd0
leaq 0x31b2(%rip), %rsi      # 0x100bc
callq 0x4340
movq %rax, %rdi
movl %ebp, %esi
callq 0x4650
leaq 0x31b3(%rip), %rsi      # 0x100d3
movq %rax, %rdi
callq 0x4340
leaq 0x31b3(%rip), %rsi      # 0x100e2
movq %rax, %rdi
callq 0x4340
movq %rax, %rbx
movq %r14, %rdi
callq 0x46b0
movq %rbx, %rdi
movl %eax, %esi
callq 0x4650
pushq $0x1
popq %rbx
jmp 0xcf66
movq 0x8098(%rip), %rdi      # 0x14ff0
leaq 0x30c7(%rip), %rsi      # 0x10026
callq 0x4340
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x41b0
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3034(%rip), %rdi      # 0xffbb
leaq 0x29b1(%rip), %rsi      # 0xf93f
leaq 0x2fe6(%rip), %rcx      # 0xff7b
movl $0x1d7, %edx            # imm = 0x1D7
callq 0x4210
movq 0x804a(%rip), %rdi      # 0x14ff0
leaq 0x1199(%rip), %rsi      # 0xe146
callq 0x4340
movzwl %r12w, %esi
movq %rax, %rdi
callq 0x4610
leaq 0x1ba8(%rip), %r14      # 0xeb6d
movq %rax, %rdi
movq %r14, %rsi
callq 0x4340
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x301d(%rip), %rsi      # 0xfffe
movq %rax, %rdi
callq 0x4340
pushq $0x4
popq %rsi
movq %rax, %rdi
callq 0x4650
movq %rax, %rdi
movq %r14, %rsi
callq 0x4340
movq %rax, %rdi
xorl %esi, %esi
callq 0x4650
movq %rax, %rdi
callq 0x41b0
pushq $-0x1
popq %rdi
callq 0x43e0
leaq 0xfe4(%rip), %rdi       # 0xe004
leaq 0x2918(%rip), %rsi      # 0xf93f
leaq 0x2f4d(%rip), %rcx      # 0xff7b
movl $0x1d2, %edx            # imm = 0x1D2
callq 0x4210
leaq 0x303a(%rip), %rdi      # 0x10079
leaq 0x28f9(%rip), %rsi      # 0xf93f
leaq 0x2f2e(%rip), %rcx      # 0xff7b
movl $0x1ff, %edx            # imm = 0x1FF
callq 0x4210
nop