// File: /workspace/github_cpp_makefile_star2_O1/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 0xcf9f
movq $0x0, -0x30(%rbp)
cmpq $0x0, 0x18(%rbx)
movq %rax, -0x40(%rbp)
movq %rax, %r15
je 0xcf9b
leaq 0xd8(%rbx), %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
movq 0xc30a(%rip), %r12      # 0x18fc0
leaq 0x4a5b(%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 0xcf5c
movq (%r13), %rax
testq %rax, %rax
je 0xcfce
movl 0x20(%rax), %edi
leal -0xfff6(%rdi), %eax
cmpl $0x4, %eax
ja 0xcd56
leaq 0x47a1(%rip), %rcx      # 0x114bc
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 0xceb0
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xceb9
cmpl $0x8000, %edi           # imm = 0x8000
jne 0xcda2
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 0xcf53
leal -0x1(%rdi), %eax
cmpl $0x7fc, %eax            # imm = 0x7FC
ja 0xcec2
movq %r14, %rbx
movq %r12, %r14
incq %rdi
callq 0x7030
movq %rax, %r12
movq %rax, -0x30(%rbp)
movq (%r13), %rax
testq %rax, %rax
je 0xcfce
movslq 0x20(%rax), %rdx
incq %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x71e0
movq (%r13), %rax
testq %rax, %rax
je 0xcfce
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 0xcf2c
movq %r12, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xcf35
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 0xcf00
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xcf09
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 0xcf0e
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xcf17
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 0xcf1d
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xcf26
leaq -0x30(%rbp), %rdx
callq 0xea58
addq $0x4, %r15
jmp 0xcf53
movl $0xc, %edx
movq %r12, %rdi
leaq 0x4872(%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 0xcf53
leaq -0x30(%rbp), %rdx
callq 0xea58
incq %r15
jmp 0xcf53
leaq -0x30(%rbp), %rdx
callq 0xea58
addq $0x8, %r15
jmp 0xcf53
leaq -0x30(%rbp), %rdx
callq 0xea58
addq $0x2, %r15
jmp 0xcf53
leaq -0x30(%rbp), %rdx
callq 0xea58
movq %r14, %r12
movq (%r13), %rax
testq %rax, %rax
je 0xcfce
movq %rbx, %r14
movslq 0x20(%rax), %rax
addq %rax, %r15
movq -0x58(%rbp), %rbx
addq $0x10, %r13
jmp 0xccec
movq 0xe0(%rbx), %rsi
cmpq 0xe8(%rbx), %rsi
je 0xcf7d
movq -0x38(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0xe0(%rbx)
jmp 0xcf8a
movq -0x50(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0xeb7a
movq -0x48(%rbp), %rax
incq %rax
cmpq %rax, 0x18(%rbx)
ja 0xccc5
movq -0x40(%rbp), %rax
subl %eax, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0xb73a
movq %rbx, %rdi
callq 0xb87a
movq %rbx, %rdi
callq 0xb87a
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48e0(%rip), %rdi      # 0x118b5
leaq 0x48e1(%rip), %rsi      # 0x118bd
leaq 0x4906(%rip), %rcx      # 0x118e9
movl $0x2d8, %edx            # imm = 0x2D8
callq 0x7210
nop