// File: 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
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3390
leaq -0x50(%rbp), %rdi
callq 0x4400
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3420
movb %al, -0x259(%rbp)
jmp 0x38e8
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x38f7
jmp 0x3cc4
jmp 0x38f9
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x34d0
movb %al, -0x25a(%rbp)
jmp 0x3914
movb -0x25a(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3925
jmp 0x3b97
movq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3060
jmp 0x3934
movl $0x0, -0x68(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4400
leaq -0xa0(%rbp), %rdi
callq 0x3390
movl $0x10, %edi
movl $0x8, %esi
callq 0x4420
movl %eax, -0x260(%rbp)
jmp 0x3967
movl -0x260(%rbp), %edx
leaq -0x228(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3410
jmp 0x397f
jmp 0x3981
leaq -0x228(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3360
movq %rax, -0x268(%rbp)
jmp 0x399d
movq -0x268(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3350
movb %al, -0x269(%rbp)
jmp 0x39bb
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0x39ca
jmp 0x3aa0
xorl %eax, %eax
movl %eax, %esi
leaq -0xa0(%rbp), %rdi
callq 0x3510
movq %rax, -0x278(%rbp)
jmp 0x39e3
movq -0x278(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x3a36
jmp 0x3aa0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x3d4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x3b7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x31e0
jmp 0x3b7d
leaq -0xa0(%rbp), %rdi
callq 0x3100
movq %rax, %rdi
callq 0x3340
movsd %xmm0, -0x230(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x4440
jmp 0x3a64
leaq -0xa0(%rbp), %rdi
callq 0x3100
movq %rax, %rdi
callq 0x3340
movsd %xmm0, -0x238(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x4440
jmp 0x3a92
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x3981
cmpl $0x0, -0x58(%rbp)
je 0x3b24
cmpl $0x0, -0x68(%rbp)
je 0x3b24
movl -0x58(%rbp), %eax
cmpl -0x68(%rbp), %eax
je 0x3b24
movq 0x23535(%rip), %rdi     # 0x26ff0
movq 0x234ee(%rip), %rsi     # 0x26fb0
callq 0x32b0
movq %rax, -0x280(%rbp)
jmp 0x3ad0
movq -0x280(%rbp), %rdi
leaq 0x16526(%rip), %rsi     # 0x1a004
callq 0x3270
movq %rax, -0x288(%rbp)
jmp 0x3aec
movq -0x288(%rbp), %rdi
movq 0x234b6(%rip), %rsi     # 0x26fb0
callq 0x32b0
movq %rax, -0x290(%rbp)
jmp 0x3b08
movq -0x290(%rbp), %rdi
movq 0x2349a(%rip), %rsi     # 0x26fb0
callq 0x32b0
jmp 0x3b1d
xorl %edi, %edi
callq 0x3320
cmpl $0x0, -0x68(%rbp)
je 0x3b30
movl -0x68(%rbp), %eax
movl %eax, -0x58(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x33e0
cmpq $0x0, %rax
je 0x3b57
leaq -0x80(%rbp), %rdi
callq 0x4470
cmpq $0x0, %rax
je 0x3b57
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x31e0
leaq -0xa0(%rbp), %rdi
callq 0x3180
leaq -0x80(%rbp), %rdi
callq 0x4490
jmp 0x38f9
leaq -0xa0(%rbp), %rdi
callq 0x3180
leaq -0x80(%rbp), %rdi
callq 0x4490
jmp 0x3d4f
movq -0x10(%rbp), %rdi
callq 0x3070
jmp 0x3ba2
movq -0x18(%rbp), %rdi
callq 0x4280
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x42a0
jmp 0x3bbb
movl $0x0, -0x23c(%rbp)
movl -0x23c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x3c03
movq -0x18(%rbp), %rdi
movl -0x23c(%rbp), %eax
movl %eax, %esi
callq 0x4330
movq %rax, %rdi
movl -0x58(%rbp), %eax
movl %eax, %esi
callq 0x4350
jmp 0x3bf0
jmp 0x3bf2
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x3bc5
leaq -0x50(%rbp), %rdi
callq 0x44f0
movq %rax, -0x248(%rbp)
movl $0x0, -0x24c(%rbp)
movl -0x24c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x3cc2
movl $0x0, -0x250(%rbp)
movl -0x250(%rbp), %eax
cmpl -0x58(%rbp), %eax
jae 0x3cac
leaq -0x248(%rbp), %rdi
xorl %esi, %esi
callq 0x4520
movq %rax, -0x258(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x4560
movsd (%rax), %xmm0
movsd %xmm0, -0x298(%rbp)
movq -0x18(%rbp), %rdi
movl -0x24c(%rbp), %eax
movl %eax, %esi
callq 0x4330
movq %rax, %rdi
movl -0x250(%rbp), %eax
movl %eax, %esi
callq 0x43e0
movsd -0x298(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x250(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x250(%rbp)
jmp 0x3c36
jmp 0x3cae
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24c(%rbp)
jmp 0x3c1d
jmp 0x3d34
movq 0x23325(%rip), %rdi     # 0x26ff0
movq 0x232de(%rip), %rsi     # 0x26fb0
callq 0x32b0
movq %rax, -0x2a0(%rbp)
jmp 0x3ce0
movq -0x2a0(%rbp), %rdi
leaq 0x1633c(%rip), %rsi     # 0x1a02a
callq 0x3270
movq %rax, -0x2a8(%rbp)
jmp 0x3cfc
movq -0x2a8(%rbp), %rdi
movq 0x232a6(%rip), %rsi     # 0x26fb0
callq 0x32b0
movq %rax, -0x2b0(%rbp)
jmp 0x3d18
movq -0x2b0(%rbp), %rdi
movq 0x2328a(%rip), %rsi     # 0x26fb0
callq 0x32b0
jmp 0x3d2d
xorl %edi, %edi
callq 0x3320
leaq -0x50(%rbp), %rdi
callq 0x4490
leaq -0x38(%rbp), %rdi
callq 0x3180
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x4490
leaq -0x38(%rbp), %rdi
callq 0x3180
movq -0x60(%rbp), %rdi
callq 0x3490
nopw (%rax,%rax)