// File: /workspace/github_cpp_makefile_star2_O2/iu-vail[P]iprimal/Assignment.cpp
// Function: Assignment::ImportMatrix(std::basic_ifstream<char, std::char_traits<char>>&, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>&)
void
Assignment::ImportMatrix(ifstream& input_file, mat& matrix){

  string line;
  vector<double> numstream;

  uint num_rows = 0;
  uint num_cols = 0;

  if (input_file.is_open())
  {
    while (!input_file.eof() )
    {
      getline (input_file,line);

      uint local_num_cols=0;
      vector<double> local_numstream;
      string word;

      stringstream parse(line);
      while(parse >> word){
	//if comment line, ignore it
	if(word[0] == '#')
	  break;
	//numstream.push_back(atoi(word.c_str()));  //if not number, then convert to zero
	numstream.push_back(atof(word.c_str()));  //if not number, then convert to zero
	//local_numstream.push_back(atoi(word.c_str()));
	local_numstream.push_back(atof(word.c_str()));

	//matrix(num_rows, num_cols)= atoi(word.c_str()); 	
	local_num_cols++;
      } //end inner while

      //double check if the matrix format is correct or not
      if(num_cols && local_num_cols && num_cols!=local_num_cols){
	cerr<<endl<<"Please input a correct matrix format!"<<endl<<endl;
	exit(0);
      }
      //update column number if everything looks normal
      if(local_num_cols)
	num_cols = local_num_cols;
      //update row number if everything looks normal
      if(line.length()&&local_numstream.size())
        num_rows++;

    } //end out layer while

    input_file.close();

    matrix.clear();
    //put elements into matrix
    //matrix.resize(num_rows, num_cols);
    matrix.resize(num_rows);
    for(uint i=0; i<num_rows; i++)
      matrix[i].resize(num_cols);

    vector<double>::iterator itr = numstream.begin();
    for(uint i=0; i<num_rows; i++)
      for(uint j=0; j<num_cols; j++)
	matrix[i][j] = *itr++;
  } //end outmost if
  else{ 
    cerr <<endl<<"Error: Unable to open file! Stopped."<<endl<<endl; 
    exit(0);
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, 0x8(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %r14
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0x78(%rsi), %rdi
callq 0x2080
testb %al, %al
je 0x2901
movl $0x0, 0x4(%rsp)
leaq 0x80(%rsp), %rbp
leaq 0xa0(%rsp), %r12
leaq 0x60(%rsp), %r13
leaq 0x18(%rsp), %r15
leaq 0x20(%rsp), %rbx
movl $0x0, (%rsp)
movq %r14, 0x10(%rsp)
movq (%r14), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%r14,%rax)
jne 0x281b
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2050
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
andq $0x0, 0x68(%rsp)
movb $0x0, 0x70(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x18
popq %rdx
callq 0x2320
xorl %r14d, %r14d
leaq 0x40(%rsp), %rbp
movq %r12, %rdi
movq %r13, %rsi
callq 0x2280
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x27ab
movq 0x60(%rsp), %rdi
cmpb $0x23, (%rdi)
je 0x27ab
callq 0x2270
movsd %xmm0, 0x18(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x30a0
movq 0x60(%rsp), %rdi
callq 0x2270
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x30a0
incl %r14d
jmp 0x2752
movl (%rsp), %edx
testl %edx, %edx
sete %al
testl %r14d, %r14d
sete %cl
orb %al, %cl
cmpl %r14d, %edx
sete %al
orb %cl, %al
je 0x28cf
testl %r14d, %r14d
cmovnel %r14d, %edx
movl %edx, (%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x27f1
movq 0x28(%rsp), %rax
xorl %ecx, %ecx
cmpq 0x20(%rsp), %rax
setne %cl
addl %ecx, 0x4(%rsp)
movq 0x10(%rsp), %r14
movq %r12, %rdi
callq 0x21a0
movq %r13, %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x3082
leaq 0x80(%rsp), %rbp
jmp 0x26fb
movq %r14, %rdi
callq 0x2060
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x2bba
movl 0x4(%rsp), %ebx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2bc2
movl (%rsp), %r14d
imulq $0x18, %rbx, %r15
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x2868
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %r12, %rdi
movq %r14, %rsi
callq 0x2bf8
addq $0x18, %r12
jmp 0x284a
movq 0x40(%rsp), %rax
shlq $0x3, %r14
xorl %ecx, %ecx
cmpq %rbx, %rcx
je 0x28a6
imulq $0x18, %rcx, %rsi
movq 0x8(%rsp), %rdx
addq (%rdx), %rsi
xorl %edx, %edx
cmpq %rdx, %r14
je 0x289e
movsd (%rax,%rdx), %xmm0
movq (%rsi), %rdi
movsd %xmm0, (%rdi,%rdx)
addq $0x8, %rdx
jmp 0x2886
incq %rcx
addq %rdx, %rax
jmp 0x2873
leaq 0x40(%rsp), %rdi
callq 0x3082
leaq 0x80(%rsp), %rdi
callq 0x2110
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb71a(%rip), %rdi      # 0xdff0
callq 0x2120
leaq 0x674e(%rip), %rsi      # 0x9030
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x2120
xorl %edi, %edi
callq 0x2260
movq 0xb6e8(%rip), %rdi      # 0xdff0
callq 0x2120
leaq 0x6742(%rip), %rsi      # 0x9056
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x2120
jmp 0x28fa
jmp 0x2939
jmp 0x2942
jmp 0x2939
movq %rax, %rbx
jmp 0x2952
movq %rax, %rbx
jmp 0x2966
jmp 0x2942
jmp 0x2942
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x21a0
leaq 0x60(%rsp), %rdi
callq 0x2110
leaq 0x20(%rsp), %rdi
callq 0x3082
leaq 0x40(%rsp), %rdi
callq 0x3082
leaq 0x80(%rsp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x2390
nop