// File: /workspace/github_cpp_makefile_star2_O1/GenisGE[P]evalAdmix/filereader_and_conversions.cpp
// Function: doBimFile(myPars*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bArray *doBimFile(myPars* pars,const char *filename,const std::string delim){
   ///@param filename A filename to read.@param delim A string of delimiters.
  
  std::vector<int> chromos;//for all lines
  std::vector<double> positions;//for all lines
  

  const int SIZE=500000;//this should only be 6 elements but lets make it big..
  char buffer[SIZE];
 
  std::ifstream pFile (filename,std::ios::in);
 
  
  if(!pFile){
    fileError(filename);
    exit(0);
  }

  
  std::string tmp_string;
  int itemsInRow;
  int numRows =0;
  while(!pFile.eof()){
    pFile.getline(buffer,SIZE);
    tmp_string = std::string(buffer);
    std::vector<std::string> tokens;
    itemsInRow = get_lexemes(tmp_string,tokens,delim);
      
    if (itemsInRow!=6 && itemsInRow!=0){
      printf("plink bim file:%s doesn't have 6 columns in row:%d\n",filename,numRows);
      exit(0);
    }else if(itemsInRow==0)
      break;
    chromos.push_back(atoi((tokens[0]).c_str()));
    positions.push_back(atof((tokens[3]).c_str()));
    numRows++;
  }

  int warn=0;
  //  copy(chromos.begin(), chromos.end(), std::ostream_iterator<int>(std::cout, ", "));  
  //  copy(positions.begin(), positions.end(), std::ostream_iterator<float>(std::cout, ", "));  
  bArray *ret = allocBoolArray(chromos.size());
  int numTrue = 0;
  for(unsigned int i=0;i<chromos.size();i++){
    ret->array[i] = 1;
    numTrue++;
 

  }
  ret->numTrue = numTrue;

  dArray *pos = allocDoubleArray(ret->numTrue);
  iArray *chr = allocIntArray(ret->numTrue);
  int atPos=0;
  for(int i=0;i<ret->x;i++){
    if(ret->array[i]){
      pos->array[atPos] = positions[i]/PLINK_POS_SCALING;
      chr->array[atPos] = chromos[i];
      
      atPos++;
    }

  }
  pars->chr  = chr;
  pars->position= pos;




  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7a428, %rsp          # imm = 0x7A428
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
leaq 0xf8(%rsp), %rdi
movl $0x8, %edx
callq 0x2440
movq %r14, 0x48(%rsp)
movq %rbx, 0xd0(%rsp)
movq 0xf8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x118(%rsp,%rax)
jne 0x8a51
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x0, 0xc(%rsp)
leaq 0x300(%rsp), %r13
leaq 0x70(%rsp), %r14
leaq 0xb0(%rsp), %r12
leaq 0x90(%rsp), %rbx
movq 0xf8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x118(%rsp,%rax)
jne 0x890b
leaq (%rsp,%rax), %rdi
addq $0xf8, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %ecx
movl $0x7a120, %edx          # imm = 0x7A120
leaq 0xf8(%rsp), %rdi
movq %r13, %rsi
callq 0x2460
leaq 0x80(%rsp), %rbp
movq %rbp, 0x70(%rsp)
movq %r13, %rdi
callq 0x20d0
leaq (%rsp,%rax), %rdx
addq $0x300, %rdx            # imm = 0x300
movq %r14, %rdi
movq %r13, %rsi
callq 0x618e
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x22a0
movq 0x70(%rsp), %rdi
cmpq %rbp, %rdi
je 0x87b4
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2230
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x5f92
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x5f92
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x694a
movl %eax, %ebp
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x8846
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x886b
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2230
testl %ebp, %ebp
je 0x88a2
cmpl $0x6, %ebp
jne 0x8a33
movq 0x70(%rsp), %rax
movq (%rax), %rdi
callq 0x2390
movl %eax, 0x28(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x88a6
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x88b5
xorl %ebp, %ebp
jmp 0x88fa
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x934c
movq 0x70(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x22b0
movsd %xmm0, 0x28(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x88e4
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x88f3
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x9488
incl 0xc(%rsp)
movb $0x1, %bpl
movq %r14, %rdi
callq 0x8f4c
testb %bpl, %bpl
jne 0x871b
movq 0x18(%rsp), %rdi
subq 0x10(%rsp), %rdi
shrq $0x2, %rdi
callq 0xad3f
movq %rax, %rbx
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
subq %rcx, %rax
je 0x894b
sarq $0x2, %rax
movq 0x8(%rbx), %rcx
xorl %edi, %edi
movl $0x1, (%rcx,%rdi,4)
incq %rdi
cmpq %rdi, %rax
ja 0x893a
jmp 0x894d
xorl %edi, %edi
movl %edi, 0x4(%rbx)
callq 0xadcc
movq %rax, %r14
movslq 0x4(%rbx), %rdi
callq 0xac62
cmpl $0x0, (%rbx)
jle 0x89b7
movq 0x8(%rbx), %rcx
movq 0x30(%rsp), %rdx
xorl %esi, %esi
movq 0x10(%rsp), %rdi
movsd 0x55e2(%rip), %xmm0     # 0xdf60
xorl %r8d, %r8d
cmpl $0x0, (%rcx,%rsi,4)
je 0x89ac
movsd (%rdx,%rsi,8), %xmm1
divsd %xmm0, %xmm1
movq 0x8(%r14), %r9
movslq %r8d, %r8
movsd %xmm1, (%r9,%r8,8)
movl (%rdi,%rsi,4), %r9d
movq 0x8(%rax), %r10
movl %r9d, (%r10,%r8,4)
incl %r8d
incq %rsi
movslq (%rbx), %r9
cmpq %r9, %rsi
jl 0x8981
movq 0xd0(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq %r14, 0x10(%rcx)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x89e3
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0xf8(%rsp), %rdi
callq 0x2070
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8a07
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8a1e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq %rbx, %rax
addq $0x7a428, %rsp          # imm = 0x7A428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5876(%rip), %rdi      # 0xe2b0
movq 0x48(%rsp), %rsi
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x2290
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rsi
callq 0x5efe
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6220
movq %rbx, %rdi
callq 0x20e0
jmp 0x8a4a
movq %rax, %rbx
jmp 0x8b20
jmp 0x8b01
jmp 0x8b01
jmp 0x8b01
movq %rax, %rbx
jmp 0x8b2d
jmp 0x8a9c
jmp 0x8a9c
movq %rax, %rbx
jmp 0x8af5
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x8ad0
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x8ad0
jmp 0x8b01
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x8af5
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0x70(%rsp), %rdi
callq 0x8f4c
jmp 0x8b04
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x8b20
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0xf8(%rsp), %rdi
callq 0x2070
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8b44
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8b5b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x2400