// File: 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:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq 0x78(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movq 0x68(%rsp), %rax
movq $-0x1, (%rax)
addq $0x10, %rdi
movq 0x70(%rsp), %rsi
callq 0x5620
movl %eax, 0x64(%rsp)
cmpl $0x0, 0x64(%rsp)
jne 0x1b157
jmp 0x1b176
leaq 0x1ea6(%rip), %rdi      # 0x1d004
leaq 0x37e2(%rip), %rsi      # 0x1e947
movl $0x1d2, %edx            # imm = 0x1D2
leaq 0x3e4c(%rip), %rcx      # 0x1efbd
callq 0x5280
movl $0x0, 0x2c(%rsp)
movq 0x18(%rsp), %rdi
addq $0x10, %rdi
leaq 0x30(%rsp), %rsi
callq 0x5680
movl %eax, 0x64(%rsp)
cmpl $0x0, %eax
je 0x1b444
movq 0x18(%rsp), %rax
movl 0x2c(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x2c(%rsp)
movb 0xc(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1b1b9
jmp 0x1b1bb
jmp 0x1b1da
leaq 0x3e3b(%rip), %rdi      # 0x1effd
leaq 0x377e(%rip), %rsi      # 0x1e947
movl $0x1d7, %edx            # imm = 0x1D7
leaq 0x3de8(%rip), %rcx      # 0x1efbd
callq 0x5280
cmpl $0x1, 0x64(%rsp)
je 0x1b208
movq 0xcde8(%rip), %rdi      # 0x27fd0
leaq 0x3e1c(%rip), %rsi      # 0x1f00b
callq 0x53d0
movq %rax, %rdi
movq 0xcdc2(%rip), %rsi      # 0x27fc0
callq 0x5430
jmp 0x1b17e
leaq 0x30(%rsp), %rdi
callq 0x168f0
testb $0x1, %al
jne 0x1b21b
jmp 0x1b368
movq 0x30(%rsp), %rdi
addq $0x8, %rdi
callq 0x16f90
movw %ax, 0x2a(%rsp)
movq 0x30(%rsp), %rdi
addq $0xa, %rdi
callq 0x16f90
movw %ax, 0x28(%rsp)
movzwl 0x2a(%rsp), %eax
shll $0x10, %eax
movzwl 0x28(%rsp), %ecx
orl %ecx, %eax
movl %eax, 0x24(%rsp)
cmpl $0x40000, 0x24(%rsp)    # imm = 0x40000
je 0x1b2ec
movq 0xcd87(%rip), %rdi      # 0x27ff0
leaq 0x1ed6(%rip), %rsi      # 0x1d146
callq 0x53d0
movq %rax, %rdi
movzwl 0x2a(%rsp), %esi
callq 0x5740
movq %rax, %rdi
leaq 0x28c1(%rip), %rsi      # 0x1db4d
callq 0x53d0
movq %rax, %rdi
movzwl 0x28(%rsp), %esi
callq 0x5740
movq %rax, %rdi
leaq 0x3d98(%rip), %rsi      # 0x1f040
callq 0x53d0
movq %rax, %rdi
movl $0x4, %esi
callq 0x57a0
movq %rax, %rdi
leaq 0x2889(%rip), %rsi      # 0x1db4d
callq 0x53d0
movq %rax, %rdi
xorl %esi, %esi
callq 0x57a0
movq %rax, %rdi
movq 0xcce3(%rip), %rsi      # 0x27fc0
callq 0x5430
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x54c0
movq 0x30(%rsp), %rdi
addq $0x48, %rdi
callq 0x16ba0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x1e0(%rax)
cmpq $0x0, 0x1e0(%rax)
jne 0x1b346
movq 0xccd6(%rip), %rdi      # 0x27ff0
leaq 0x3d47(%rip), %rsi      # 0x1f068
callq 0x53d0
movq %rax, %rdi
movq 0xcc90(%rip), %rsi      # 0x27fc0
callq 0x5430
movq $0x0, 0x80(%rsp)
jmp 0x1b4d3
movq 0x30(%rsp), %rdi
addq $0x40, %rdi
callq 0x16ba0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x1d8(%rax)
jmp 0x1b17e
leaq 0x30(%rsp), %rdi
callq 0x16950
testb $0x1, %al
jne 0x1b378
jmp 0x1b37d
jmp 0x1b17e
leaq 0x30(%rsp), %rdi
callq 0x15ec0
testb $0x1, %al
jne 0x1b38d
jmp 0x1b3d7
movq 0x18(%rsp), %rdi
addq $0x1a8, %rdi            # imm = 0x1A8
leaq 0x30(%rsp), %rsi
callq 0x62d0
andb $0x1, %al
movb %al, 0x23(%rsp)
testb $0x1, 0x23(%rsp)
jne 0x1b3d2
movq 0xcc39(%rip), %rdi      # 0x27ff0
leaq 0x3cd4(%rip), %rsi      # 0x1f092
callq 0x53d0
movq %rax, %rdi
movq 0xcbf3(%rip), %rsi      # 0x27fc0
callq 0x5430
jmp 0x1b17e
cmpq $0x0, 0x48(%rsp)
je 0x1b41d
movq 0x70(%rsp), %rdi
callq 0x5120
cmpl $0x0, %eax
je 0x1b3f0
jmp 0x1b40f
leaq 0x3cc4(%rip), %rdi      # 0x1f0bb
leaq 0x3549(%rip), %rsi      # 0x1e947
movl $0x1ff, %edx            # imm = 0x1FF
leaq 0x3bb3(%rip), %rcx      # 0x1efbd
callq 0x5280
movq 0x18(%rsp), %rax
movb $0x1, 0xc(%rax)
jmp 0x1b17e
movq 0xcbac(%rip), %rdi      # 0x27fd0
leaq 0x3ca8(%rip), %rsi      # 0x1f0d3
callq 0x53d0
movq %rax, %rdi
movq 0xcb86(%rip), %rsi      # 0x27fc0
callq 0x5430
jmp 0x1b17e
movl 0x2c(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x70(%rsp), %rdi
callq 0x5820
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
je 0x1b4c7
movq 0xcb69(%rip), %rdi      # 0x27fd0
leaq 0x3c90(%rip), %rsi      # 0x1f0fe
callq 0x53d0
movq %rax, %rdi
movl 0x2c(%rsp), %esi
callq 0x57a0
movq %rax, %rdi
leaq 0x3c8c(%rip), %rsi      # 0x1f115
callq 0x53d0
movq %rax, %rdi
leaq 0x3c8c(%rip), %rsi      # 0x1f124
callq 0x53d0
movq %rax, 0x8(%rsp)
movq 0x70(%rsp), %rdi
callq 0x5820
movq 0x8(%rsp), %rdi
movl %eax, %esi
callq 0x57a0
movq %rax, %rdi
movq 0xcafe(%rip), %rsi      # 0x27fc0
callq 0x5430
movq $0x1, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)