// File: maplechori[P]stata-reader-writer/State.cpp
// Function: OpenInnerValueLabel::process(Context&)
bool OpenInnerValueLabel::process(Context &ctx)
{
  char *ctxbuf = (char *)ctx.advance();
  char *txtorig = NULL;
  int curr = 0, sz = 0, totalSize = 0, entries = 0, txtlen = 0, *offsets = NULL;
  StataValueLabel *svl = new StataValueLabel();

  if (ctx.hdr.fileByteorder == LSF)
  {

    switch (ctx.hdr.fileRelease)
    {

    case R119:
    case R118:

      totalSize = GetLSF<uint32_t>(ctxbuf, 4);
      ctxbuf += 4;
      sz = strlen((char *)ctxbuf);
      svl->labname.assign(&ctxbuf[0], sz);
      ctxbuf += 132;
      entries = GetLSF<uint32_t>(ctxbuf, 4);
      ctxbuf += 4;
      txtlen = GetLSF<uint32_t>(ctxbuf, 4);
      ctxbuf += 4;

      offsets = new int[entries];

      for (int i = 0; i < entries; ctxbuf += 4, i++)
        offsets[i] = GetLSF<int32_t>(ctxbuf, 4);

      txtorig = ctxbuf + (entries * 4);

      for (int i = 0; i < entries; i++, ctxbuf += 4)
        svl->valuelabel[GetLSF<uint32_t>(ctxbuf, 4)].assign((char *)(&txtorig[offsets[i]]), strlen(&txtorig[offsets[i]]));

      ctxbuf += txtlen;
      break;

    case R117:
      totalSize = GetLSF<uint32_t>(ctxbuf, 4);
      ctxbuf += 4;
      sz = strlen((char *)ctxbuf);
      svl->labname.assign(&ctxbuf[0], sz);
      ctxbuf += 36;
      entries = GetLSF<uint32_t>(ctxbuf, 4);
      ctxbuf += 4;
      txtlen = GetLSF<uint32_t>(ctxbuf, 4);
      ctxbuf += 4;

      offsets = new int[entries];

      for (int i = 0; i < entries; ctxbuf += 4, i++)
        offsets[i] = GetLSF<int32_t>(ctxbuf, 4);

      txtorig = ctxbuf + (entries * 4);

      for (int i = 0; i < entries; i++, ctxbuf += 4)
        svl->valuelabel[GetLSF<uint32_t>(ctxbuf, 4)].assign((char *)(&txtorig[offsets[i]]), strlen(&txtorig[offsets[i]]));

      ctxbuf += txtlen;
      break;

    case R115:
    case R114:
    case R113:
    case R112:
      break;
    }
  }
  else
  {
  }

  if (ctxbuf[0] == '<' && ctxbuf[1] == '/' && ctxbuf[2] == 'l' && ctxbuf[6] == '<' && ctxbuf[8] != 'v')
  {
    setHasMoreLabels(true);
    ctx.advance();
    ctx.advance();
  }
  else
  {
    setHasMoreLabels(false);
    ctx.advance();
  }

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x15460
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x50, %edi
callq 0x8430
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
callq 0x14a20
jmp 0x17d66
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x64(%rax)
jne 0x1815a
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x84(%rbp)
subl $0x2, %eax
jb 0x17dd7
jmp 0x17d90
movl -0x84(%rbp), %eax
subl $0x2, %eax
je 0x17f99
jmp 0x17da1
movl -0x84(%rbp), %eax
addl $-0x3, %eax
subl $0x4, %eax
jb 0x18156
jmp 0x18158
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x50, %esi
callq 0x8440
jmp 0x181df
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x81c0
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x28(%rbp), %rdx
callq 0x85d0
movq -0x18(%rbp), %rax
addq $0x84, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movslq -0x30(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8030
movq %rax, -0x40(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x17ec3
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x19720
movl %eax, %edx
movq -0x40(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x17e89
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x17f83
movq -0x48(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movq -0xa0(%rbp), %rdi
movl %eax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x19790
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq -0x5c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
addq %rax, %rdi
callq 0x81c0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq %rax, %rdx
callq 0x85d0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
jmp 0x17ede
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x18158
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x81c0
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x28(%rbp), %rdx
callq 0x85d0
movq -0x18(%rbp), %rax
addq $0x24, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movslq -0x30(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8030
movq %rax, -0x40(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x18083
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x19720
movl %eax, %edx
movq -0x40(%rbp), %rax
movslq -0x64(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x18049
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x18143
movq -0x48(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18690
movq -0xb8(%rbp), %rdi
movl %eax, -0x6c(%rbp)
leaq -0x6c(%rbp), %rsi
callq 0x19790
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq -0x68(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rax
movslq -0x68(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
addq %rax, %rdi
callq 0x81c0
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
callq 0x85d0
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
jmp 0x1809e
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x18158
jmp 0x18158
jmp 0x1815c
jmp 0x1815c
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3c, %eax
jne 0x181be
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
jne 0x181be
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x6c, %eax
jne 0x181be
movq -0x18(%rbp), %rax
movsbl 0x6(%rax), %eax
cmpl $0x3c, %eax
jne 0x181be
movq -0x18(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x76, %eax
je 0x181be
movq -0x80(%rbp), %rdi
movl $0x1, %esi
callq 0x19870
movq -0x10(%rbp), %rdi
callq 0x15460
movq -0x10(%rbp), %rdi
callq 0x15460
jmp 0x181d2
movq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0x19870
movq -0x10(%rbp), %rdi
callq 0x15460
movb $0x1, %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x87c0
nopl (%rax,%rax)