// File: /workspace/github_cpp_makefile_star2_O2/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 $0x7a438, %rsp          # imm = 0x7A438
movq %rdx, 0x58(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movapd %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0x108(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2450
movq %r14, 0x28(%rsp)
movq %rbx, 0x50(%rsp)
movq 0x108(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x128(%rsp,%rax)
jne 0x75bd
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x0, 0x4(%rsp)
leaq 0x310(%rsp), %r13
leaq 0x60(%rsp), %r14
leaq 0x88(%rsp), %r12
leaq 0xc8(%rsp), %r15
leaq 0xa8(%rsp), %rbp
movq 0x108(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x128(%rsp,%rax)
jne 0x74ae
movl $0x7a120, %edx          # imm = 0x7A120
leaq 0x108(%rsp), %rdi
movq %r13, %rsi
callq 0x20b0
movq %r14, %rdi
movq %r13, %rbx
movq %r13, %rsi
leaq 0x8(%rsp), %rdx
callq 0x5646
movq %r12, %rdi
movq %r14, %rsi
callq 0x2290
movq %r14, %rdi
callq 0x20f0
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x22f0
movq %rbp, %rdi
movq 0x58(%rsp), %rsi
callq 0x22f0
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x5f0c
movl %eax, %r13d
movq %rbp, %rdi
callq 0x20f0
movq %r15, %rdi
callq 0x20f0
testl %r13d, %r13d
je 0x7497
cmpl $0x6, %r13d
jne 0x759f
movq 0x60(%rsp), %rax
movq (%rax), %rdi
callq 0x23a0
movl %eax, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0x7dd8
movq 0x60(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x22a0
movsd %xmm0, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x7f4e
incl 0x4(%rsp)
movb $0x1, %r13b
jmp 0x749a
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x7976
testb %r13b, %r13b
movq %rbx, %r13
jne 0x739d
movq 0x18(%rsp), %rdi
subq 0x10(%rsp), %rdi
shrq $0x2, %rdi
callq 0x9753
movq %rax, %rbx
movq 0x18(%rsp), %rdi
subq 0x10(%rsp), %rdi
sarq $0x2, %rdi
xorl %eax, %eax
cmpq %rax, %rdi
jbe 0x74e9
movq 0x8(%rbx), %rcx
movl $0x1, (%rcx,%rax,4)
incq %rax
jmp 0x74d4
movl %edi, 0x4(%rbx)
callq 0x97cc
movq %rax, %r14
movslq 0x4(%rbx), %rdi
callq 0x967f
movq 0x30(%rsp), %rcx
xorl %edx, %edx
movq 0x10(%rsp), %rsi
movsd 0x4a0f(%rip), %xmm0     # 0xbf20
xorl %edi, %edi
movslq (%rbx), %r8
cmpq %r8, %rdx
jge 0x754f
movq 0x8(%rbx), %r8
cmpl $0x0, (%r8,%rdx,4)
je 0x754a
movsd (%rcx,%rdx,8), %xmm1
divsd %xmm0, %xmm1
movq 0x8(%r14), %r8
movslq %edi, %rdi
movsd %xmm1, (%r8,%rdi,8)
movl (%rsi,%rdx,4), %r8d
movq 0x8(%rax), %r9
movl %r8d, (%r9,%rdi,4)
incl %edi
incq %rdx
jmp 0x7513
movq 0x50(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq %r14, 0x10(%rcx)
leaq 0x88(%rsp), %rdi
callq 0x20f0
leaq 0x108(%rsp), %rdi
callq 0x2070
leaq 0x30(%rsp), %rdi
callq 0x7da4
leaq 0x10(%rsp), %rdi
callq 0x7d70
movq %rbx, %rax
addq $0x7a438, %rsp          # imm = 0x7A438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4cca(%rip), %rdi      # 0xc270
movq 0x28(%rsp), %rsi
movl 0x4(%rsp), %edx
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x2280
leaq 0xe8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
movq 0x28(%rsp), %rsi
callq 0x5646
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x590c
movq %rbx, %rdi
callq 0x20f0
jmp 0x75b6
movq %rax, %rbx
jmp 0x764a
jmp 0x760c
jmp 0x760c
jmp 0x760c
movq %rax, %rbx
jmp 0x7657
jmp 0x7611
jmp 0x7611
jmp 0x760c
movq %rax, %rbx
jmp 0x7626
movq %rax, %rbx
jmp 0x763d
movq %rax, %rbx
jmp 0x7633
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x20f0
leaq 0xc8(%rsp), %rdi
callq 0x20f0
leaq 0x60(%rsp), %rdi
callq 0x7976
leaq 0x88(%rsp), %rdi
callq 0x20f0
leaq 0x108(%rsp), %rdi
callq 0x2070
leaq 0x30(%rsp), %rdi
callq 0x7da4
leaq 0x10(%rsp), %rdi
callq 0x7d70
movq %rbx, %rdi
callq 0x2410