// File: /workspace/github_cpp_makefile_star2_O2/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
callq 0x9ac6
testb %al, %al
je 0x8be9
leaq 0x38(%rbx), %r14
pushq $0x1
popq %r12
leaq 0x38(%rsp), %r15
movl %r12d, %r12d
movq 0x18(%rbx), %rcx
movq 0x1d0(%rcx), %rax
movq 0x1d8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
decq %rcx
cmpq %r12, %rcx
jbe 0x8d94
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
callq 0x9b24
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x8be1
movq %r14, %rdi
movq %r15, %rsi
callq 0xa030
incl 0x34(%rbx)
incl %r12d
jmp 0x8b98
leaq 0x38(%rbx), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x38(%rsp), %r13
leaq 0x18(%rsp), %r12
movl %r14d, %r14d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x8d94
movq (%rax,%r14,8), %rsi
movq (%rsi), %rax
movq %r13, %rdi
callq *0x40(%rax)
movq %r12, %r15
movq %r12, %rdi
movq %r13, %rsi
callq 0xa190
movq 0x20(%rsp), %r13
pushq $0x30
popq %rdi
callq 0x4350
movq %rax, %rbp
addl $0x34, %r13d
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq %r13, %rdi
callq 0x4030
movq %rax, %r12
movq %rax, (%rbp)
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x41f0
movabsq $0x656e6f62736966, %rax # imm = 0x656E6F62736966
movq %rax, (%r12)
addq $0x8, %r12
movq %r12, %rdi
pushq $0x34
popq %rsi
callq 0xb10d
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0xc, %rdi
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
movl 0x1a0(%rax), %esi
callq 0xb0a7
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x10, %rdi
pushq $0x3
popq %rsi
callq 0xb0a7
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x14, %rdi
movq 0x38(%rsp), %rsi
callq 0xb03a
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x1c, %rdi
movq 0x40(%rsp), %rsi
callq 0xb03a
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x24, %rdi
xorl %esi, %esi
callq 0xb03a
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x2c, %rdi
movl 0x48(%rsp), %esi
callq 0xb0a7
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movl 0x4c(%rsp), %esi
callq 0xb0a7
movq 0x8(%rsp), %r12
movq (%r12), %rdi
addq $0x34, %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x42b0
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movq %r13, 0x8(%r12)
movslq 0x34(%rbx), %rax
movq %rax, 0x28(%r12)
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xa030
incl 0x34(%rbx)
movq %r15, %r12
movq %r15, %rdi
callq 0x4170
leaq 0x38(%rsp), %r13
movq %r13, %rdi
callq 0x6744
incl %r14d
jmp 0x8bff
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x8db8
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4170
leaq 0x38(%rsp), %rdi
callq 0x6744
movq %rbx, %rdi
callq 0x4680