// File: cpearce[P]OggIndex/src/SkeletonEncoder.cpp
// Function: SkeletonEncoder::ConstructPages()
void
SkeletonEncoder::ConstructPages() {
  
  assert(mIndexPackets.size() == 2 * mDecoders.size() + 2);
  
  ClearIndexPages();

  ogg_int32_t ret = 0;
  ogg_page page;
  ogg_stream_state state;
  memset(&state, 0, sizeof(ogg_stream_state));
  memset(&page, 0, sizeof(ogg_page));
  
  ret = ogg_stream_init(&state, mSerial);
  assert(ret == 0);

  // BOS packet, must be on own page.
  ret = ogg_stream_packetin(&state, mIndexPackets[0]);
  assert(ret == 0);
  ret = ogg_stream_flush(&state, &page);
  assert(ret != 0);
  AppendPage(page);

  // Output non-eos packets.
  for (ogg_uint32_t i=1; i<mIndexPackets.size()-1; i++) {
    ret = ogg_stream_packetin(&state, mIndexPackets[i]);
    assert(ret == 0);
  }
  
  while (ogg_stream_pageout(&state, &page) != 0) {
    assert(!ogg_page_bos(&page));
    AppendPage(page);
  }

  ret = ogg_stream_flush(&state, &page);
  if (ret != 0) {
    AppendPage(page);
  }

  // Output the eos page. It must be on its own page.
  ret = ogg_stream_packetin(&state, mIndexPackets.back());
  assert(ret == 0);
  ret = ogg_stream_flush(&state, &page);
  if (ret != 0) {
    AppendPage(page);
  }

  ogg_stream_clear(&state);
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, 0x1e0(%rsp)
movq 0x1e0(%rsp), %rdi
movq %rdi, 0x8(%rsp)
addq $0x38, %rdi
callq 0x6980
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rsp)
callq 0x140a0
movq %rax, %rcx
movq 0x10(%rsp), %rax
shlq %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
jne 0x124ba
jmp 0x124d9
leaq 0xbc8e(%rip), %rdi      # 0x1e14f
leaq 0xbb1c(%rip), %rsi      # 0x1dfe4
movl $0x16b, %edx            # imm = 0x16B
leaq 0xbcac(%rip), %rcx      # 0x1e180
callq 0x5280
movq 0x8(%rsp), %rdi
callq 0x11640
movl $0x0, 0x1dc(%rsp)
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x198, %edx            # imm = 0x198
callq 0x5230
leaq 0x1b8(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x5230
movq 0x8(%rsp), %rax
movl 0x30(%rax), %esi
leaq 0x20(%rsp), %rdi
callq 0x5830
movl %eax, 0x1dc(%rsp)
cmpl $0x0, 0x1dc(%rsp)
jne 0x12538
jmp 0x12557
leaq 0xaac5(%rip), %rdi      # 0x1d004
leaq 0xba9e(%rip), %rsi      # 0x1dfe4
movl $0x176, %edx            # imm = 0x176
leaq 0xbc2e(%rip), %rcx      # 0x1e180
callq 0x5280
movq 0x8(%rsp), %rdi
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x69a0
movq (%rax), %rsi
leaq 0x20(%rsp), %rdi
callq 0x5070
movl %eax, 0x1dc(%rsp)
cmpl $0x0, 0x1dc(%rsp)
jne 0x12589
jmp 0x125a8
leaq 0xaa74(%rip), %rdi      # 0x1d004
leaq 0xba4d(%rip), %rsi      # 0x1dfe4
movl $0x17a, %edx            # imm = 0x17A
leaq 0xbbdd(%rip), %rcx      # 0x1e180
callq 0x5280
leaq 0x20(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x5670
movl %eax, 0x1dc(%rsp)
cmpl $0x0, 0x1dc(%rsp)
je 0x125cd
jmp 0x125ec
leaq 0xbbd3(%rip), %rdi      # 0x1e1a7
leaq 0xba09(%rip), %rsi      # 0x1dfe4
movl $0x17c, %edx            # imm = 0x17C
leaq 0xbb99(%rip), %rcx      # 0x1e180
callq 0x5280
movq 0x8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x13120
movl $0x1, 0x1c(%rsp)
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %eax
movq %rax, (%rsp)
addq $0x38, %rdi
callq 0x6980
movq %rax, %rcx
movq (%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x12691
movq 0x8(%rsp), %rdi
addq $0x38, %rdi
movl 0x1c(%rsp), %eax
movl %eax, %esi
callq 0x69a0
movq (%rax), %rsi
leaq 0x20(%rsp), %rdi
callq 0x5070
movl %eax, 0x1dc(%rsp)
cmpl $0x0, 0x1dc(%rsp)
jne 0x12660
jmp 0x1267f
leaq 0xa99d(%rip), %rdi      # 0x1d004
leaq 0xb976(%rip), %rsi      # 0x1dfe4
movl $0x182, %edx            # imm = 0x182
leaq 0xbb06(%rip), %rcx      # 0x1e180
callq 0x5280
jmp 0x12681
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x12606
jmp 0x12693
leaq 0x20(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x5590
cmpl $0x0, %eax
je 0x126fa
leaq 0x1b8(%rsp), %rdi
callq 0x57f0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x126c5
jmp 0x126c7
jmp 0x126e6
leaq 0xbae2(%rip), %rdi      # 0x1e1b0
leaq 0xb90f(%rip), %rsi      # 0x1dfe4
movl $0x186, %edx            # imm = 0x186
leaq 0xba9f(%rip), %rcx      # 0x1e180
callq 0x5280
movq 0x8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x13120
jmp 0x12693
leaq 0x20(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x5670
movl %eax, 0x1dc(%rsp)
cmpl $0x0, 0x1dc(%rsp)
je 0x1272f
movq 0x8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x13120
movq 0x8(%rsp), %rdi
addq $0x38, %rdi
callq 0xc100
movq (%rax), %rsi
leaq 0x20(%rsp), %rdi
callq 0x5070
movl %eax, 0x1dc(%rsp)
cmpl $0x0, 0x1dc(%rsp)
jne 0x1275d
jmp 0x1277c
leaq 0xa8a0(%rip), %rdi      # 0x1d004
leaq 0xb879(%rip), %rsi      # 0x1dfe4
movl $0x191, %edx            # imm = 0x191
leaq 0xba09(%rip), %rcx      # 0x1e180
callq 0x5280
leaq 0x20(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x5670
movl %eax, 0x1dc(%rsp)
cmpl $0x0, 0x1dc(%rsp)
je 0x127b1
movq 0x8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x13120
leaq 0x20(%rsp), %rdi
callq 0x57c0
addq $0x1e8, %rsp            # imm = 0x1E8
retq
nopw %cs:(%rax,%rax)