// File: /workspace/github_cpp_makefile_star2_O2/maplechori[P]stata-reader-writer/State.cpp
// Function: OpenVarTypes::process(Context&)
bool OpenVarTypes::process(Context &ctx)
{
  char *ctxbuf = (char *)ctx.advance();
  int curr = 0;
  StataVariablesImpl<double> *sta_double;
  StataVariablesImpl<float> *sta_float;
  StataVariablesImpl<long> *sta_long;
  StataVariablesImpl<short> *sta_integer;
  StataVariablesImpl<int8_t> *sta_byte;
  StataVariablesImpl<string> *sta_char;

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

    while (*ctxbuf != '<')
    {
      int stataType = GetLSF<unsigned int>(ctxbuf, 2);

      switch (stataType)
      {
      case ST_STRL:
        cout << "STRL" << endl;

        // handle STRLs
        break;
      case ST_DOUBLE:
        sta_double = new StataVariablesImpl<double>();
        sta_double->type = stataType;
        ctx.vList.push_back(boost::shared_ptr<StataVariables>(sta_double));
        break;
      case ST_FLOAT:
        sta_float = new StataVariablesImpl<float>();
        sta_float->type = stataType;
        ctx.vList.push_back(boost::shared_ptr<StataVariables>(sta_float));
        break;
      case ST_LONG:
        sta_long = new StataVariablesImpl<long>();
        sta_long->type = stataType;
        ctx.vList.push_back(boost::shared_ptr<StataVariables>(sta_long));
        break;
      case ST_INT:
        sta_integer = new StataVariablesImpl<short>();
        sta_integer->type = stataType;
        ctx.vList.push_back(boost::shared_ptr<StataVariables>(sta_integer));
        break;
      case ST_BYTE:
        sta_byte = new StataVariablesImpl<int8_t>();
        sta_byte->type = stataType;
        ctx.vList.push_back(boost::shared_ptr<StataVariables>(sta_byte));
        break;
      default:
        if (stataType > 0 && stataType <= 2045)
        {
          sta_char = new StataVariablesImpl<string>();
          sta_char->type = stataType;
          ctx.vList.push_back(boost::shared_ptr<StataVariables>(sta_char));
        }
        else
          cout << "UNKNOWN TYPE " << hex << stataType << endl;
        break;
      }

      ctxbuf += 2;
      curr++;
    }
  }
  else
  {
    // not implemented yet
  }

  ctx.advance();
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rsi, %rdi
callq 0xa876
cmpl $0x0, 0x64(%r15)
je 0xaf5a
movq %r15, %rdi
callq 0xa876
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0xc0(%r15), %rax
movq %rax, -0x40(%rbp)
leaq -0x30(%rbp), %r12
cmpb $0x3c, (%r14)
je 0xaf41
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0xbd9e
movl %eax, %ebx
leal -0xfff6(%rbx), %eax
cmpl $0x4, %eax
ja 0xafd6
leaq 0x44ff(%rip), %rcx      # 0xf490
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x98, %edi
callq 0x7310
movq %rax, %rbx
movq %rax, %rdi
callq 0xbeac
movl $0xfff6, 0x28(%rbx)     # imm = 0xFFF6
leaq -0x38(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0xbed0
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0xcd32
jmp 0xb139
cmpl $0x8000, %ebx           # imm = 0x8000
jne 0xaff6
movq 0xcfdb(%rip), %rdi      # 0x17fc0
leaq 0x4744(%rip), %rsi      # 0xf730
callq 0x7300
jmp 0xb176
movl %ebx, %eax
decl %eax
cmpl $0x7fc, %eax            # imm = 0x7FC
ja 0xb144
movq %r15, %r13
movl $0xb0, %edi
callq 0x7310
movq %rax, %r15
movq %rax, %rdi
callq 0xc096
movl %ebx, 0x28(%r15)
leaq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc0d6
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0xcd32
leaq -0x30(%rbp), %rdi
callq 0x87c4
movq %r13, %r15
leaq -0x30(%rbp), %r12
jmp 0xb17e
movl $0x98, %edi
callq 0x7310
movq %rax, %rbx
movq %rax, %rdi
callq 0xc034
movl $0xfffa, 0x28(%rbx)     # imm = 0xFFFA
leaq -0x38(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0xc058
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0xcd32
jmp 0xb139
movl $0x98, %edi
callq 0x7310
movq %rax, %rbx
movq %rax, %rdi
callq 0xbf70
movl $0xfff8, 0x28(%rbx)     # imm = 0xFFF8
leaq -0x38(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0xbf94
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0xcd32
jmp 0xb139
movl $0x98, %edi
callq 0x7310
movq %rax, %rbx
movq %rax, %rdi
callq 0xbfd2
movl $0xfff9, 0x28(%rbx)     # imm = 0xFFF9
leaq -0x38(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0xbff6
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0xcd32
movq %r12, %rdi
jmp 0xb13d
movl $0x98, %edi
callq 0x7310
movq %rax, %rbx
movq %rax, %rdi
callq 0xbf0e
movl $0xfff7, 0x28(%rbx)     # imm = 0xFFF7
leaq -0x38(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0xbf32
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0xcd32
leaq -0x30(%rbp), %rdi
callq 0x87c4
jmp 0xb17e
movq 0xce75(%rip), %rdi      # 0x17fc0
leaq 0x45e3(%rip), %rsi      # 0xf735
callq 0x7300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movl %ebx, %esi
callq 0x7580
movq %rax, %rdi
callq 0x7160
addq $0x2, %r14
jmp 0xaf6c
jmp 0xb197
jmp 0xb197
jmp 0xb197
jmp 0xb197
movq %rax, %rbx
movq %r12, %rdi
jmp 0xb19e
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x87c4
movq %rbx, %rdi
callq 0x75b0
nop