// File: /workspace/github_cpp_makefile_star2_O3/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 $0x7a418, %rsp          # imm = 0x7A418
movq %rdx, %r15
movq %rdi, 0xc0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
leaq 0xe8(%rsp), %rdi
movq %rsi, 0x38(%rsp)
movl $0x8, %edx
callq 0x2440
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rcx
testb $0x5, 0x108(%rsp,%rcx)
jne 0x8ab8
leaq 0x70(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
movq -0x18(%rax), %rax
testb $0x2, 0x108(%rsp,%rax)
jne 0x8972
leaq (%rsp,%rax), %rdi
addq $0xe8, %rdi
xorl %ebp, %ebp
leaq 0x2f0(%rsp), %r13
leaq 0x40(%rsp), %r14
leaq 0xa0(%rsp), %rbx
movl $0xa, %esi
callq 0x2200
movsbl %al, %ecx
movl $0x7a120, %edx          # imm = 0x7A120
leaq 0xe8(%rsp), %rdi
movq %r13, %rsi
callq 0x2460
leaq 0x50(%rsp), %r12
movq %r12, 0x40(%rsp)
movq %r13, %rdi
callq 0x20d0
leaq (%rsp,%rax), %rdx
addq $0x2f0, %rdx            # imm = 0x2F0
movq %r14, %rdi
movq %r13, %rsi
callq 0x61b8
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x22a0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x87f2
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2230
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0x5fae
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x5fae
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x698a
movl %eax, %r12d
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x888c
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x88b1
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2230
cmpl $0x6, %r12d
jne 0x895f
movq 0x40(%rsp), %r12
movq (%r12), %rdi
callq 0x2390
movl %eax, 0x18(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x88e6
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x88f8
movq %rsp, %rdi
leaq 0x18(%rsp), %rdx
callq 0x9416
movq 0x40(%rsp), %r12
movq 0x60(%r12), %rdi
callq 0x22b0
movsd %xmm0, 0x18(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x8923
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x8932
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x9552
incl %ebp
movq %r14, %rdi
callq 0x900c
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0xe8, %rdi
testb $0x2, 0x20(%rdi)
je 0x8784
jmp 0x8972
testl %r12d, %r12d
jne 0x8a9c
leaq 0x40(%rsp), %rdi
callq 0x900c
movq 0x8(%rsp), %rdi
subq (%rsp), %rdi
shrq $0x2, %rdi
callq 0xae94
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
subq %rcx, %rax
je 0x89b0
sarq $0x2, %rax
movq 0x8(%rbx), %rcx
xorl %edi, %edi
movl $0x1, (%rcx,%rdi,4)
incq %rdi
cmpq %rdi, %rax
ja 0x899f
jmp 0x89b2
xorl %edi, %edi
movl %edi, 0x4(%rbx)
callq 0xaf20
movq %rax, %r14
movslq 0x4(%rbx), %rdi
callq 0xadb7
movl (%rbx), %r9d
testl %r9d, %r9d
jle 0x8a21
movq 0x8(%rbx), %rcx
movq 0x20(%rsp), %rdx
xorl %esi, %esi
movq (%rsp), %rdi
movsd 0x557b(%rip), %xmm0     # 0xdf60
xorl %r8d, %r8d
cmpl $0x0, (%rcx,%rsi,4)
je 0x8a16
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
movl (%rbx), %r9d
incq %rsi
movslq %r9d, %r10
cmpq %r10, %rsi
jl 0x89e8
movq 0xc0(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq %r14, 0x10(%rcx)
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x8a4d
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0xe8(%rsp), %rdi
callq 0x2070
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x8a71
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8a87
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq %rbx, %rax
addq $0x7a418, %rsp          # imm = 0x7A418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x580d(%rip), %rdi      # 0xe2b0
movq 0x38(%rsp), %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x2290
leaq 0xc8(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq 0x38(%rsp), %rsi
callq 0x5f1a
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6250
movq %rbx, %rdi
callq 0x20e0
jmp 0x8ab1
movq %rax, %rbx
jmp 0x8b87
jmp 0x8b68
jmp 0x8b68
jmp 0x8b68
movq %rax, %rbx
jmp 0x8bab
jmp 0x8b59
jmp 0x8b59
movq %rax, %rbx
jmp 0x8b32
jmp 0x8b68
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x8b32
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x8b5c
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x8b5c
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x900c
jmp 0x8b6b
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x8b87
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0xe8(%rsp), %rdi
callq 0x2070
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x8bab
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8bc1
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x2400