// File: /workspace/github_cpp_makefile_star2_O3/maplechori[P]stata-reader-writer/State.cpp
// Function: OpenData::process(Context&)
bool OpenData::process(Context &ctx)
{
  char *ctxbuf = (char *)ctx.getCursor(), *start_ctx = NULL;
  int curr = 0, sz = 0;
  
  start_ctx = ctxbuf;
  
  if (ctx.hdr.fileByteorder == LSF)
  {
    char * buf = NULL;
  
    for (int j = 0; j < ctx.hdr.observations; j++)
    {
      int k = 0;
      vector<char *> * v = new vector<char *>(0);
      for (vector<boost::shared_ptr<StataVariables> >::iterator it = ctx.vList.begin(); it != ctx.vList.end(); ++it)
      {

        switch ((*it)->type)
        {
        case ST_STRL:
          cout << "STRL" << endl;
          ctx.strls = true;
          // handle STRLs
          break;
        case ST_DOUBLE:
          buf = new char[8];
          memcpy(buf, ctxbuf, 8); 
          v->push_back(buf);   
          ctxbuf += 8;
          break;
        case ST_FLOAT:
          buf = new char[4];
          memcpy(buf, ctxbuf, 4); 
          v->push_back(buf);
          ctxbuf += 4;
          break;
        case ST_LONG:
          buf = new char[4];
          memcpy(buf, ctxbuf, 4); 
          v->push_back(buf);
          ctxbuf += 4;
          break;
        case ST_INT:
          buf = new char[2];
          memcpy(buf, ctxbuf, 2); 
          v->push_back(buf);
          ctxbuf += 2;
          break;
        case ST_BYTE:
          buf = new char[1];
          memcpy(buf, ctxbuf,1); 
          v->push_back(buf);          
          ctxbuf++;
          break;
        default:
          if ((*it)->type > 0 && (*it)->type <= 2045)
          {
            buf = new char[(*it)->type + 1];
            memset(buf, 0, (*it)->type + 1);
            memcpy(buf, ctxbuf,(*it)->type);
            v->push_back(buf);
            
            ctxbuf += (*it)->type;
          }
          else
            cout << "UNKNOWN TYPE" << endl;
          break;
        }
      }

      ctx.vData.push_back(v);    
    }
  }
  else
  {
    // not implemented yet
  }
 
  ctx.advanceData(ctxbuf-start_ctx);
  ctx.advance();
  ctx.advance();  
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq 0x100(%rsi), %rax
cmpl $0x0, 0x64(%rsi)
movq %rax, %r15
jne 0xcf1d
movq $0x0, -0x30(%rbp)
cmpq $0x0, 0x18(%rbx)
movq %rax, -0x40(%rbp)
movq %rax, %r15
je 0xcf19
leaq 0xd8(%rbx), %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
movq 0xc38c(%rip), %r12      # 0x18fc0
leaq 0x4add(%rip), %r14      # 0x11718
movq -0x40(%rbp), %r15
movq %rbx, -0x58(%rbp)
movq %rax, -0x48(%rbp)
movl $0x18, %edi
callq 0x7330
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, -0x38(%rbp)
movq 0xc0(%rbx), %r13
cmpq 0xc8(%rbx), %r13
je 0xceda
movq (%r13), %rax
testq %rax, %rax
je 0xcf4c
movl 0x20(%rax), %edi
leal -0xfff6(%rdi), %eax
cmpl $0x4, %eax
ja 0xccd4
leaq 0x4807(%rip), %rcx      # 0x114a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, %edi
callq 0x7030
movq %rax, -0x30(%rbp)
movl (%r15), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xce2e
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xce37
cmpl $0x8000, %edi           # imm = 0x8000
jne 0xcd20
movl $0x4, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x73b0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x7300
movsbl %al, %esi
movq %r12, %rdi
callq 0x7050
movq %rax, %rdi
callq 0x7230
movb $0x1, 0xb0(%rbx)
jmp 0xced1
leal -0x1(%rdi), %eax
cmpl $0x7fc, %eax            # imm = 0x7FC
ja 0xce40
movq %r14, %rbx
movq %r12, %r14
incq %rdi
callq 0x7030
movq %rax, %r12
movq %rax, -0x30(%rbp)
movq (%r13), %rax
testq %rax, %rax
je 0xcf4c
movslq 0x20(%rax), %rdx
incq %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x71e0
movq (%r13), %rax
testq %rax, %rax
je 0xcf4c
movslq 0x20(%rax), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x72a0
movq -0x38(%rbp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xceaa
movq %r12, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xceb3
movl $0x1, %edi
callq 0x7030
movq %rax, -0x30(%rbp)
movb (%r15), %cl
movb %cl, (%rax)
movq -0x38(%rbp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xce7e
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xce87
movl $0x8, %edi
callq 0x7030
movq %rax, -0x30(%rbp)
movq (%r15), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xce8c
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xce95
movl $0x2, %edi
callq 0x7030
movq %rax, -0x30(%rbp)
movzwl (%r15), %ecx
movw %cx, (%rax)
movq -0x38(%rbp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xce9b
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xcea4
leaq -0x30(%rbp), %rdx
callq 0xe9e4
addq $0x4, %r15
jmp 0xced1
movl $0xc, %edx
movq %r12, %rdi
leaq 0x48f4(%rip), %rsi      # 0x11743
callq 0x73b0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x7300
movsbl %al, %esi
movq %r12, %rdi
callq 0x7050
movq %rax, %rdi
callq 0x7230
jmp 0xced1
leaq -0x30(%rbp), %rdx
callq 0xe9e4
incq %r15
jmp 0xced1
leaq -0x30(%rbp), %rdx
callq 0xe9e4
addq $0x8, %r15
jmp 0xced1
leaq -0x30(%rbp), %rdx
callq 0xe9e4
addq $0x2, %r15
jmp 0xced1
leaq -0x30(%rbp), %rdx
callq 0xe9e4
movq %r14, %r12
movq (%r13), %rax
testq %rax, %rax
je 0xcf4c
movq %rbx, %r14
movslq 0x20(%rax), %rax
addq %rax, %r15
movq -0x58(%rbp), %rbx
addq $0x10, %r13
jmp 0xcc6a
movq 0xe0(%rbx), %rsi
cmpq 0xe8(%rbx), %rsi
je 0xcefb
movq -0x38(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0xe0(%rbx)
jmp 0xcf08
movq -0x50(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0xeb06
movq -0x48(%rbp), %rax
incq %rax
cmpq %rax, 0x18(%rbx)
ja 0xcc43
movq -0x40(%rbp), %rax
subl %eax, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0xb714
movq %rbx, %rdi
callq 0xb856
movq %rbx, %rdi
callq 0xb856
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4962(%rip), %rdi      # 0x118b5
leaq 0x4963(%rip), %rsi      # 0x118bd
leaq 0x4988(%rip), %rcx      # 0x118e9
movl $0x2d8, %edx            # imm = 0x2D8
callq 0x7210
nop