// File: /workspace/github_cpp_makefile_star2_O2/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 $0x4c4e68, %rsp         # imm = 0x4C4E68
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq (%rdi), %rsi
leaq 0x118(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2450
movq 0x118(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x138(%rsp,%rax)
jne 0x6547
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r15d, %r15d
leaq 0x320(%rsp), %rbp
leaq 0xf8(%rsp), %r12
leaq 0x98(%rsp), %r14
leaq 0x78(%rsp), %r13
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movq 0x118(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x138(%rsp,%rax)
jne 0x64e8
movl $0x4c4b40, %edx         # imm = 0x4C4B40
leaq 0x118(%rsp), %rdi
movq %rbp, %rbx
movq %rbp, %rsi
callq 0x20b0
movq %r12, %rdi
movq %rbx, %rbp
movq %rbx, %rsi
leaq 0x17(%rsp), %rdx
callq 0x5646
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2290
movq %r12, %rdi
callq 0x20f0
testb $0x1, %r15b
je 0x647d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22f0
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x22f0
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x5f0c
movl %eax, %ebx
movq %r13, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x20f0
movb $0x1, %r15b
testl %ebx, %ebx
je 0x63bf
incl 0x10(%rsp)
movb $0x1, %r15b
cmpl 0xc(%rsp), %ebx
je 0x63bf
jmp 0x6571
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x22f0
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x22f0
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x5f0c
movl %eax, %ebx
movq %r15, %rdi
callq 0x20f0
leaq 0x38(%rsp), %rdi
callq 0x20f0
xorl %r15d, %r15d
movl $0x0, 0xc(%rsp)
testl %ebx, %ebx
je 0x63bf
incl 0x10(%rsp)
movb $0x1, %r15b
movl %ebx, 0xc(%rsp)
jmp 0x63bf
leaq 0x5b63(%rip), %rdi      # 0xc052
callq 0x9c5e
movl 0x10(%rsp), %edi
movl 0xc(%rsp), %esi
callq 0x90f4
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x5f92
leaq 0x58(%rsp), %rdi
callq 0x20f0
leaq 0x118(%rsp), %rdi
callq 0x2070
leaq 0x20(%rsp), %rdi
callq 0x7976
movq %rbx, %rax
addq $0x4c4e68, %rsp         # imm = 0x4C4E68
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd8(%rsp), %rdi
movq %rbx, %rsi
callq 0x22f0
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
callq 0x590c
movq %rbx, %rdi
callq 0x20f0
jmp 0x6589
leaq 0x5a90(%rip), %rdi      # 0xc008
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x2280
movq %rax, %rbx
jmp 0x65ee
movq %rax, %rbx
jmp 0x65ac
jmp 0x65e1
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x20f0
leaq 0x38(%rsp), %rdi
jmp 0x65d6
jmp 0x65e1
movq %rax, %rbx
jmp 0x65fb
jmp 0x65e1
movq %rax, %rbx
jmp 0x65ce
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x20f0
leaq 0x98(%rsp), %rdi
callq 0x20f0
jmp 0x65e4
jmp 0x65e1
jmp 0x65e1
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x20f0
leaq 0x118(%rsp), %rdi
callq 0x2070
leaq 0x20(%rsp), %rdi
callq 0x7976
movq %rbx, %rdi
callq 0x2410