// File: /workspace/github_cpp_makefile_star2_O2/chrislarson1[P]MVEE/include/utils.hpp
// Function: readCSV(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, char)
Eigen::MatrixXd readCSV(std::string file, char delim) 
{
	// Get dimensions for Eigen::MatrixXd constructor
	int rows = 0;
	int cols = 0;
	std::ifstream in;
	in.open(file);
	if (in.is_open())
	{
		std::string s;
		while(!in.eof()) 
		{
			getline(in, s);
			if (s != "")
			{
				rows++;
				if (!cols)
				{
					cols = count(s.begin(), s.end(), delim) + 1;
				} 
			}
		}
	}
	else
	{
		throw std::runtime_error("Error: Cannot open " + file + ".");
	}
	in.close();
	

	// Stream file into Eigen::MatrixXd container
	std::string line;
	Eigen::MatrixXd X = Eigen::MatrixXd(rows, cols);
	int row = 0;
	int col = 0;
	in.open(file);
	while (getline(in, line)) 
	{
		char* ptr = (char*) line.c_str();
		int len = line.length();
		col = 0;
		char* start = ptr;
		for (int i=0; i<len; i++) 
		{
			if (ptr[i] == delim) 
			{
				X(row, col++) = atof(start);
				start = ptr + i + 1;
			}
		}
		X(row, col) = atof(start);
		row++;
	}
	in.close();
	
	return X;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rsi, %r14
movq %rdi, %rbx
andl $0x0, 0x1c(%rsp)
movb %dl, 0xf(%rsp)
andl $0x0, 0x18(%rsp)
leaq 0x60(%rsp), %r15
movq %r15, %rdi
callq 0x581d0
pushq $0x8
popq %rdx
movq %r15, %rdi
movq %r14, 0x10(%rsp)
movq %r14, %rsi
callq 0x576a0
leaq 0xd8(%rsp), %rdi
callq 0x55890
testb %al, %al
je 0x5ac01
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebp, %ebp
leaq 0x60(%rsp), %r15
leaq 0x20(%rsp), %r12
leaq 0x24837(%rip), %r13     # 0x7f2b3
xorl %r14d, %r14d
movq 0x60(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x80(%rsp,%rax)
jne 0x5aada
movq %r15, %rdi
movq %r12, %rsi
callq 0x555b0
movq %r12, %rdi
movq %r13, %rsi
callq 0x573f0
testb %al, %al
je 0x5aa7f
incl %r14d
movl %r14d, 0x1c(%rsp)
testl %ebp, %ebp
jne 0x5aa7f
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
addq %rdi, %rsi
leaq 0xf(%rsp), %rdx
callq 0x579f0
movq %rax, %rbp
incl %ebp
movl %ebp, 0x18(%rsp)
jmp 0x5aa7f
leaq 0x20(%rsp), %rdi
callq 0x56290
leaq 0x60(%rsp), %rdi
callq 0x556e0
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
leaq 0x1c(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x597c0
leaq 0x60(%rsp), %rdi
pushq $0x8
popq %rdx
movq 0x10(%rsp), %rsi
callq 0x576a0
xorl %r14d, %r14d
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x555b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5abce
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %ebp
xorl %r15d, %r15d
testl %ebp, %ebp
cmovlel %r15d, %ebp
leaq 0x1(%rdi), %r12
movslq %r15d, %r13
subq $0x1, %rbp
jb 0x5aba3
movb -0x1(%r12), %al
cmpb 0xf(%rsp), %al
jne 0x5ab9e
callq 0x58560
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x58fd0
incl %r15d
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r12, %rdi
incq %r12
jmp 0x5ab61
callq 0x58560
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x58fd0
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
incq %r14
jmp 0x5ab2a
leaq 0x60(%rsp), %rdi
callq 0x556e0
leaq 0x20(%rsp), %rdi
callq 0x56290
leaq 0x60(%rsp), %rdi
callq 0x55940
movq %rbx, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x56470
movq %rax, %rbx
leaq 0x2468d(%rip), %rsi     # 0x7f2a0
leaq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rdx
callq 0x57810
leaq 0x2468b(%rip), %rdx     # 0x7f2b4
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x557d0
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x59710
xorl %ebp, %ebp
movq 0x6039f(%rip), %rsi     # 0xbaff0
movq 0x60368(%rip), %rdx     # 0xbafc0
movq %rbx, %rdi
callq 0x59a90
jmp 0x5aca2
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x56290
jmp 0x5ac77
movq %rax, %r14
movb $0x1, %bpl
leaq 0x40(%rsp), %rdi
callq 0x56290
testb %bpl, %bpl
jne 0x5ac8b
jmp 0x5acbc
movq %rax, %r14
movq %rbx, %rdi
callq 0x56ff0
jmp 0x5acbc
jmp 0x5aca2
jmp 0x5aca7
movq %rax, %r14
jmp 0x5acbc
jmp 0x5aca7
jmp 0x5aca7
movq %rax, %r14
jmp 0x5acb2
movq %rax, %r14
movq %rbx, %rdi
callq 0x55d60
leaq 0x20(%rsp), %rdi
callq 0x56290
leaq 0x60(%rsp), %rdi
callq 0x55940
movq %r14, %rdi
callq 0x59d40