// File: /workspace/github_cpp_makefile_star2_O3/cpearce[P]OggIndex/src/SkeletonEncoder.cpp
// Function: SkeletonEncoder::AddFisbonePackets()
void
SkeletonEncoder::AddFisbonePackets() {
  if (HasFisbonePackets()) {
    // We have fisbone packets from the existing skeleton track. Convert to
    // Skeleton 4.0.
    for (ogg_uint32_t i=1; i<mSkeletonDecoder->mPackets.size()-1; i++) {
      ogg_packet* fisbone = UpdateFisbone(mSkeletonDecoder->mPackets[i]);
      if (fisbone) {
        mIndexPackets.push_back(fisbone);
      }
      mPacketCount++;
    }
  } else {
    // Have to construct fisbone packets.
    for (ogg_uint32_t i=0; i<mDecoders.size(); i++) {
      FisboneInfo info = mDecoders[i]->GetFisboneInfo();
      string headers = info.MessageHeaders();
      unsigned packetSize = FISBONE_HEADER_OFFSET + headers.size();

      ogg_packet* packet = new ogg_packet();
      memset(packet, 0, sizeof(ogg_packet));
      
      packet->packet = new unsigned char[packetSize];
      memset(packet->packet, 0, packetSize);

      // Magic bytes identifier.
      memcpy(packet->packet, FISBONE_MAGIC, FISBONE_MAGIC_LEN);
      
      // Offset of the message header fields.
      WriteLEInt32(packet->packet+FISBONE_HEADERS_OFFSET_FIELD_OFFSET,
                   FISBONE_HEADER_OFFSET);
      
      // Serialno of the stream.
      WriteLEUint32(packet->packet+FISBONE_SERIALNO_OFFSET,
                    mDecoders[i]->GetSerial());

      // Number of header packets. 3 for both vorbis and theora.
      WriteLEUint32(packet->packet+FISBONE_NUM_HEADERS_OFFSET, 3);
      
      // Granulrate numerator.
      WriteLEInt64(packet->packet+FISBONE_GRAN_NUMER_OFFSET, info.mGranNumer);
      
      // Granulrate denominator.
      WriteLEInt64(packet->packet+FISBONE_GRAN_DENOM_OFFSET, info.mGranDenom);
      
      // Start granule.
      WriteLEInt64(packet->packet+FISBONE_START_GRAN_OFFSET, 0);
      
      // Preroll.
      WriteLEUint32(packet->packet+FISBONE_PREROLL_OFFSET, info.mPreroll);
      
      // Granule shift.
      WriteLEUint32(packet->packet+FISBONE_GRAN_SHIFT_OFFSET, info.mGranuleShift);

      // Message header field, Content-Type */
      memcpy(packet->packet+FISBONE_HEADER_OFFSET,
             headers.c_str(),
             headers.size());

      packet->b_o_s = 0;
      packet->e_o_s = 0;
      packet->bytes = packetSize;

      packet->packetno = mPacketCount;      
      mIndexPackets.push_back(packet);
      mPacketCount++;
    }        
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %rax
testq %rax, %rax
je 0x99f1
movq 0x1d0(%rax), %rcx
movq 0x1d8(%rax), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
movq %rsi, %rdi
subq %rax, %rdi
sarq $0x3, %rdi
addq $0x2, %rdi
cmpq %rdi, %rdx
jne 0x99f8
addq $-0x3, %rdx
cmpq $-0x3, %rdx
ja 0x9c27
leaq 0x38(%rbx), %r14
movl $0x1, %eax
movl $0x2, %ebp
leaq 0x38(%rsp), %r15
movq (%rcx,%rax,8), %rsi
movq %rbx, %rdi
callq 0xaeda
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x99c4
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x99b9
movq %rax, (%rsi)
addq $0x8, 0x40(%rbx)
jmp 0x99c4
movq %r14, %rdi
movq %r15, %rdx
callq 0xbd32
incl 0x34(%rbx)
movl %ebp, %eax
movq 0x18(%rbx), %rdx
movq 0x1d0(%rdx), %rcx
movq 0x1d8(%rdx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
decq %rdx
incl %ebp
cmpq %rax, %rdx
ja 0x998f
jmp 0x9c27
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
cmpq %rax, %rsi
je 0x9c27
leaq 0x38(%rbx), %rcx
movq %rcx, 0x30(%rsp)
movl $0x1, %r12d
xorl %r15d, %r15d
movq (%rax,%r15,8), %rsi
movq (%rsi), %rax
leaq 0x38(%rsp), %r14
movq %r14, %rdi
callq *0x40(%rax)
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0xb70a
movq 0x18(%rsp), %rbp
movl $0x30, %edi
callq 0x4380
movq %rax, %r13
addl $0x34, %ebp
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq %rbp, %rdi
callq 0x4030
movq %rax, %r14
movq %rax, (%r13)
movq %rax, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x41f0
movabsq $0x656e6f62736966, %rax # imm = 0x656E6F62736966
movq %rax, (%r14)
addq $0x8, %r14
movq %r14, %rdi
movl $0x34, %esi
callq 0xc9c2
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0xc, %rdi
movq (%rbx), %rax
movq (%rax,%r15,8), %rax
movl 0x1a0(%rax), %esi
callq 0xc95e
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x10, %rdi
movl $0x3, %esi
callq 0xc95e
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x14, %rdi
movq 0x38(%rsp), %rsi
callq 0xc8f3
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x1c, %rdi
movq 0x40(%rsp), %rsi
callq 0xc8f3
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x24, %rdi
xorl %esi, %esi
callq 0xc8f3
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x2c, %rdi
movl 0x48(%rsp), %esi
callq 0xc95e
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movl 0x4c(%rsp), %esi
callq 0xc95e
movq 0x8(%rsp), %r14
movq (%r14), %rdi
addq $0x34, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x42c0
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
movq %rbp, 0x8(%r14)
movslq 0x34(%rbx), %rax
movq %rax, 0x28(%r14)
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x9b74
movq %r14, (%rsi)
addq $0x8, 0x40(%rbx)
jmp 0x9b86
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xbd32
movl 0x34(%rbx), %eax
incl %eax
movl %eax, 0x34(%rbx)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x9ba7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x9bcc
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x9bee
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x9c0a
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x43a0
movl %r12d, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %r12d
cmpq %r15, %rcx
ja 0x9a13
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x9c5d
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x9c5d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43a0
leaq 0x38(%rsp), %rdi
callq 0x6c34
movq %rbx, %rdi
callq 0x46d0
nop