// File: /workspace/github_cpp_makefile_star2_O1/GenisGE[P]evalAdmix/filereader_and_conversions.cpp
// Function: readmatrix_filty_memory(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
iMatrix *readmatrix_filty_memory(std::string filename,const std::string delim=",;: \t"){
  ///@param filename A filename to read.@param delim A string of delimiters.
  std::vector<std::string> tokens;

  const int SIZE = MAX_ELEMS_PER_LINE;//defined in conf.h
  char buffer[SIZE];
 
  std::ifstream pFile (filename.c_str(),std::ios::in);
 
  
  if(!pFile){
    fileError(filename);
    exit(0);
  }

  
  std::string tmp_string;
  int doFirstRow =1;
  int itemsInFirstRow=0;
  int numRows =0;
  while(!pFile.eof()){
     pFile.getline(buffer,SIZE);
    tmp_string = std::string(buffer);
    if(doFirstRow){
      //if file has a emptystart line
      itemsInFirstRow = get_lexemes(tmp_string,tokens,delim);
      
      if (itemsInFirstRow==0)
	continue;
      // printf("items in first rwo:%d\n",itemsInFirstRow);
      doFirstRow=0;
      numRows++;
    }
    else{
      int nItems = get_lexemes(tmp_string,tokens,delim);
	//if line is empty
	if(nItems==0)
	  continue;
	numRows++;
	if(nItems!=itemsInFirstRow){
	  printf("row length mismatch at line:%d numitems is:%d shouldn't be:%d\t will exit\n",numRows,itemsInFirstRow,nItems);
	  exit(0);
	}
      }
  }
  flush_print("\r\t-> File has been read in now, will now typecheck...                              ");
  iMatrix *data_ = allocIntMatrix(numRows,itemsInFirstRow);
  //now we have a token array of string coerce the types now
  typecast_stringarray_to_int_matrix(tokens,data_);
  //copy(tokens.begin(), tokens.end(), ostream_iterator<string>(cout, ", "));
  return data_; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4c4e58, %rsp         # imm = 0x4C4E58
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq (%rdi), %rsi
leaq 0x108(%rsp), %rdi
movl $0x8, %edx
callq 0x2440
movq 0x108(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x128(%rsp,%rax)
jne 0x72e7
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebp, %ebp
leaq 0x310(%rsp), %r12
movl $0x0, 0xc(%rsp)
xorl %r14d, %r14d
movq 0x108(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x128(%rsp,%rax)
jne 0x7258
leaq (%rsp,%rax), %rdi
addq $0x108, %rdi            # imm = 0x108
movl $0xa, %esi
callq 0x2200
movsbl %al, %ecx
movl $0x4c4b40, %edx         # imm = 0x4C4B40
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
callq 0x2460
leaq 0xd8(%rsp), %r15
movq %r15, 0xc8(%rsp)
movq %r12, %rdi
callq 0x20d0
leaq (%rsp,%rax), %rdx
addq $0x310, %rdx            # imm = 0x310
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x618e
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x22a0
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x70e3
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2230
testb $0x1, %bpl
je 0x71a4
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x5f92
leaq 0x98(%rsp), %rbp
movq %rbp, 0x88(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0x5f92
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x694a
movl %eax, %r15d
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x716a
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x7186
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
testl %r15d, %r15d
je 0x7199
incl %r14d
cmpl 0xc(%rsp), %r15d
jne 0x72c8
movb $0x1, %bpl
testl %r15d, %r15d
jmp 0x703c
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %r13
movq %r13, %rdi
callq 0x5f92
leaq 0xb8(%rsp), %r15
movq %r15, 0xa8(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rbp
movq %rbp, %rdi
callq 0x5f92
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x694a
movl %eax, 0xc(%rsp)
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x7223
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x723f
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2230
leal 0x1(%r14), %eax
cmpl $0x0, 0xc(%rsp)
setne %bpl
cmovel %r14d, %eax
movl %eax, %r14d
jmp 0x703c
leaq 0x6e33(%rip), %rdi      # 0xe092
callq 0xb282
movl %r14d, %edi
movl 0xc(%rsp), %esi
leaq 0x20(%rsp), %r14
callq 0xa5cc
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x6a0a
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x729c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2070
leaq 0x50(%rsp), %rdi
callq 0x8f4c
movq %rbx, %rax
addq $0x4c4e58, %rsp         # imm = 0x4C4E58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6d79(%rip), %rdi      # 0xe048
movl %r14d, %esi
movl 0xc(%rsp), %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x2290
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0x5f92
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6220
movq %rbx, %rdi
callq 0x20e0
jmp 0x72e0
movq %rax, %rbx
jmp 0x73db
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x7351
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x7351
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x73bf
movq 0x78(%rsp), %rsi
jmp 0x73b0
jmp 0x73bc
jmp 0x73bc
movq %rax, %rbx
jmp 0x73e8
movq %rax, %rbx
jmp 0x73c4
jmp 0x73bc
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x739c
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x739c
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x73bf
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x73bf
jmp 0x73bc
movq %rax, %rbx
leaq 0x20(%rsp), %r14
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x73db
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2070
leaq 0x50(%rsp), %rdi
callq 0x8f4c
movq %rbx, %rdi
callq 0x2400