// File: /workspace/github_cpp_makefile_star2_O3/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, 0x30(%rsp)
movq $0x0, 0x40(%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 0x732d
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebp, %ebp
leaq 0x310(%rsp), %r15
leaq 0xc8(%rsp), %r12
leaq 0x48(%rsp), %r14
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
movq 0x108(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x128(%rsp,%rax)
jne 0x72bc
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 %r15, %rsi
callq 0x2460
leaq 0xd8(%rsp), %r13
movq %r13, 0xc8(%rsp)
movq %r15, %rdi
callq 0x20d0
leaq (%rsp,%rax), %rdx
addq $0x310, %rdx            # imm = 0x310
movq %r12, %rdi
movq %r15, %rsi
callq 0x61b8
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x22a0
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x712c
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2230
testb $0x1, %bpl
je 0x71e4
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 0x5fae
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x5fae
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x698a
movl %eax, %r13d
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x71a5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x71c1
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2230
movb $0x1, %bpl
testl %r13d, %r13d
je 0x708d
incl 0xc(%rsp)
movb $0x1, %bpl
cmpl 0x8(%rsp), %r13d
je 0x708d
jmp 0x736a
leaq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %r13
movq %r13, %rdi
callq 0x5fae
leaq 0x88(%rsp), %rbp
leaq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x5fae
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
callq 0x698a
movl %eax, %r13d
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x7273
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x7298
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2230
xorl %ebp, %ebp
movl $0x0, 0x8(%rsp)
testl %r13d, %r13d
je 0x708d
incl 0xc(%rsp)
movb $0x1, %bpl
movl %r13d, 0x8(%rsp)
jmp 0x708d
leaq 0x6dcf(%rip), %rdi      # 0xe092
callq 0xb482
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %esi
leaq 0x20(%rsp), %r14
callq 0xa698
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x6a4a
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x7301
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2070
leaq 0x30(%rsp), %rdi
callq 0x900c
movq %rbx, %rax
addq $0x4c4e58, %rsp         # imm = 0x4C4E58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0x5fae
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6250
movq %rbx, %rdi
callq 0x20e0
jmp 0x7383
leaq 0x6cd7(%rip), %rdi      # 0xe048
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x2290
movq %rax, %rbx
jmp 0x7454
movq %rax, %rbx
jmp 0x73c4
jmp 0x7435
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x73c4
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x7438
movq 0xb8(%rsp), %rsi
jmp 0x7427
jmp 0x7435
movq %rax, %rbx
jmp 0x7461
movq %rax, %rbx
jmp 0x743d
movq %rax, %rbx
jmp 0x7413
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x7413
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x7438
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x7438
jmp 0x7435
jmp 0x7435
movq %rax, %rbx
leaq 0x20(%rsp), %r14
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x7454
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2070
leaq 0x30(%rsp), %rdi
callq 0x900c
movq %rbx, %rdi
callq 0x2400