// File: 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:
subq $0x4c4ed8, %rsp         # imm = 0x4C4ED8
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x4c4ed0(%rsp)
movq %rsi, 0x4c4ec8(%rsp)
leaq 0x4c4eb0(%rsp), %rdi
callq 0xdec0
movq 0x38(%rsp), %rdi
movl $0x4c4b40, 0x4c4eac(%rsp) # imm = 0x4C4B40
callq 0x30f0
movq %rax, %rsi
leaq 0x158(%rsp), %rdi
movl $0x8, %edx
callq 0x3540
jmp 0xb32a
movq 0x158(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x158(%rsp,%rax), %rdi
callq 0x3120
movb %al, 0x2f(%rsp)
jmp 0xb349
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0xb356
jmp 0xb3e5
movq 0x38(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x3100
jmp 0xb36a
leaq 0x128(%rsp), %rdi
callq 0xa100
jmp 0xb379
leaq 0x128(%rsp), %rdi
callq 0x3170
xorl %edi, %edi
callq 0x3340
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xb79c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xb78f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x3170
jmp 0xb78f
leaq 0x108(%rsp), %rdi
callq 0x33a0
movl $0x1, 0x104(%rsp)
movl $0x0, 0x100(%rsp)
movl $0x0, 0xfc(%rsp)
movq 0x158(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x158(%rsp,%rax), %rdi
callq 0x3550
movb %al, 0x2e(%rsp)
jmp 0xb432
movb 0x2e(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xb441
jmp 0xb6fe
leaq 0x158(%rsp), %rdi
leaq 0x360(%rsp), %rsi
movl $0x4c4b40, %edx         # imm = 0x4C4B40
callq 0x30c0
jmp 0xb45d
leaq 0xd7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x3500
movq 0x20(%rsp), %rdx
leaq 0xd8(%rsp), %rdi
leaq 0x360(%rsp), %rsi
callq 0x9280
jmp 0xb48b
leaq 0x108(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x3350
leaq 0xd8(%rsp), %rdi
callq 0x3170
leaq 0xd7(%rsp), %rdi
callq 0x32e0
cmpl $0x0, 0x104(%rsp)
je 0xb5f7
leaq 0xb0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x3100
jmp 0xb4df
movq 0x30(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x3100
jmp 0xb4f3
leaq 0xb0(%rsp), %rdi
leaq 0x4c4eb0(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xab60
movl %eax, 0x1c(%rsp)
jmp 0xb516
movl 0x1c(%rsp), %eax
movl %eax, 0x100(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x3170
leaq 0xb0(%rsp), %rdi
callq 0x3170
cmpl $0x0, 0x100(%rsp)
jne 0xb5d6
jmp 0xb413
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xb782
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xd7(%rsp), %rdi
callq 0x32e0
jmp 0xb782
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xb5c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x3170
leaq 0xb0(%rsp), %rdi
callq 0x3170
jmp 0xb782
movl $0x0, 0x104(%rsp)
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0xb6f9
leaq 0x68(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x3100
jmp 0xb60b
movq 0x30(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x3100
jmp 0xb61c
leaq 0x68(%rsp), %rdi
leaq 0x4c4eb0(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0xab60
movl %eax, 0x18(%rsp)
jmp 0xb639
leaq 0x48(%rsp), %rdi
callq 0x3170
leaq 0x68(%rsp), %rdi
callq 0x3170
movl 0x18(%rsp), %eax
movl %eax, 0x8c(%rsp)
cmpl $0x0, 0x8c(%rsp)
jne 0xb6aa
jmp 0xb413
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xb69b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x3170
leaq 0x68(%rsp), %rdi
callq 0x3170
jmp 0xb782
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
movl 0x8c(%rsp), %eax
cmpl 0x100(%rsp), %eax
je 0xb6f7
movl 0xfc(%rsp), %esi
movl 0x100(%rsp), %edx
movl 0x8c(%rsp), %ecx
leaq 0xd971(%rip), %rdi      # 0x19058
xorl %eax, %eax
callq 0x3040
jmp 0xb6f0
xorl %edi, %edi
callq 0x3340
jmp 0xb6f9
jmp 0xb413
leaq 0xd99d(%rip), %rdi      # 0x190a2
callq 0x152a0
jmp 0xb70c
movl 0xfc(%rsp), %edi
movl 0x100(%rsp), %esi
callq 0x13c40
movq %rax, 0x10(%rsp)
jmp 0xb726
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rsi
leaq 0x4c4eb0(%rsp), %rdi
callq 0xac90
jmp 0xb744
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x3170
leaq 0x158(%rsp), %rdi
callq 0x3080
leaq 0x4c4eb0(%rsp), %rdi
callq 0xded0
movq 0x8(%rsp), %rax
addq $0x4c4ed8, %rsp         # imm = 0x4C4ED8
retq
leaq 0x108(%rsp), %rdi
callq 0x3170
leaq 0x158(%rsp), %rdi
callq 0x3080
leaq 0x4c4eb0(%rsp), %rdi
callq 0xded0
movq 0x150(%rsp), %rdi
callq 0x34f0
nopw %cs:(%rax,%rax)