// File: 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
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rsi, -0x308(%rbp)
movq %rdi, -0x320(%rbp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, -0x318(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
leaq -0x228(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x1e1290
movq -0x310(%rbp), %rdi
movq -0x308(%rbp), %rsi
movl $0x8, %edx
callq 0x1dc6b0
jmp 0x1f031b
leaq -0x228(%rbp), %rdi
callq 0x1e9340
movb %al, -0x321(%rbp)
jmp 0x1f032f
movb -0x321(%rbp), %al
testb $0x1, %al
jne 0x1f033e
jmp 0x1f047c
leaq -0x258(%rbp), %rdi
callq 0x1e5340
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x1ed520
movb %al, -0x322(%rbp)
jmp 0x1f036a
movb -0x322(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1f037b
jmp 0x1f046b
leaq -0x228(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x1d0950
jmp 0x1f0390
leaq 0xaef11(%rip), %rsi     # 0x29f2a8
leaq -0x258(%rbp), %rdi
callq 0x1db660
movb %al, -0x323(%rbp)
jmp 0x1f03ab
movb -0x323(%rbp), %al
testb $0x1, %al
jne 0x1f03ba
jmp 0x1f0466
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x1f0464
leaq -0x258(%rbp), %rdi
movq %rdi, -0x338(%rbp)
callq 0x1dc960
movq -0x338(%rbp), %rdi
movq %rax, -0x260(%rbp)
callq 0x1d7b10
movq %rax, -0x268(%rbp)
movq -0x260(%rbp), %rdi
movq -0x268(%rbp), %rsi
leaq -0x11(%rbp), %rdx
callq 0x1e3dc0
movq %rax, -0x330(%rbp)
jmp 0x1f041a
movq -0x330(%rbp), %rax
addq $0x1, %rax
movl %eax, -0x1c(%rbp)
jmp 0x1f0464
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x1f081a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x1d85c0
jmp 0x1f081a
jmp 0x1f0466
jmp 0x1f034a
leaq -0x258(%rbp), %rdi
callq 0x1d85c0
jmp 0x1f0575
movb $0x1, -0x2a9(%rbp)
movl $0x10, %edi
callq 0x1d5b00
movq -0x308(%rbp), %rdx
movq %rax, -0x340(%rbp)
leaq 0xaedf3(%rip), %rsi     # 0x29f295
leaq -0x2a8(%rbp), %rdi
callq 0x1dd0a0
jmp 0x1f04b0
leaq 0xc4494(%rip), %rdx     # 0x2b494b
leaq -0x288(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x1d1630
jmp 0x1f04cc
movq -0x340(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x1e9890
jmp 0x1f04e1
movq -0x340(%rbp), %rdi
movb $0x0, -0x2a9(%rbp)
movq 0x139afa(%rip), %rsi    # 0x329ff0
movq 0x139a6b(%rip), %rdx    # 0x329f68
callq 0x1eafa0
jmp 0x1f0832
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x1f0559
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x1f054d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x1d85c0
leaq -0x2a8(%rbp), %rdi
callq 0x1d85c0
testb $0x1, -0x2a9(%rbp)
jne 0x1f0564
jmp 0x1f0570
movq -0x340(%rbp), %rdi
callq 0x1d9f20
jmp 0x1f081a
leaq -0x228(%rbp), %rdi
callq 0x1d1110
jmp 0x1f0583
leaq -0x2d0(%rbp), %rdi
callq 0x1e5340
movq -0x320(%rbp), %rdi
movb $0x0, -0x2d1(%rbp)
leaq -0x18(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
callq 0x1e9d90
jmp 0x1f05ac
movq -0x308(%rbp), %rsi
movl $0x0, -0x2d8(%rbp)
movl $0x0, -0x2dc(%rbp)
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x1dc6b0
jmp 0x1f05da
jmp 0x1f05dc
leaq -0x228(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x1d0950
movq %rax, -0x348(%rbp)
jmp 0x1f05f8
movq -0x348(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x1e3110
movb %al, -0x349(%rbp)
jmp 0x1f0616
movb -0x349(%rbp), %al
testb $0x1, %al
jne 0x1f0625
jmp 0x1f07bc
leaq -0x2d0(%rbp), %rdi
callq 0x1d4680
movq %rax, -0x2e8(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x1e7380
movl %eax, -0x2ec(%rbp)
movl $0x0, -0x2dc(%rbp)
movq -0x2e8(%rbp), %rax
movq %rax, -0x2f8(%rbp)
movl $0x0, -0x2fc(%rbp)
movl -0x2fc(%rbp), %eax
cmpl -0x2ec(%rbp), %eax
jge 0x1f075e
movq -0x2e8(%rbp), %rax
movslq -0x2fc(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
jne 0x1f0748
movq -0x2f8(%rbp), %rdi
callq 0x1e2a70
movq -0x320(%rbp), %rdi
movsd %xmm0, -0x360(%rbp)
movslq -0x2d8(%rbp), %rsi
movslq -0x2dc(%rbp), %rdx
movl %edx, %eax
incl %eax
movl %eax, -0x2dc(%rbp)
callq 0x1e6f60
movq %rax, -0x358(%rbp)
jmp 0x1f06dd
movq -0x358(%rbp), %rax
movsd -0x360(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x2e8(%rbp), %rax
movslq -0x2fc(%rbp), %rcx
addq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x2f8(%rbp)
jmp 0x1f0748
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x1f080e
movq -0x320(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
callq 0x1d5cb0
jmp 0x1f080e
jmp 0x1f074a
movl -0x2fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2fc(%rbp)
jmp 0x1f066c
movq -0x2f8(%rbp), %rdi
callq 0x1e2a70
movq -0x320(%rbp), %rdi
movsd %xmm0, -0x370(%rbp)
movslq -0x2d8(%rbp), %rsi
movslq -0x2dc(%rbp), %rdx
callq 0x1e6f60
movq %rax, -0x368(%rbp)
jmp 0x1f0795
movq -0x368(%rbp), %rax
movsd -0x370(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x2d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2d8(%rbp)
jmp 0x1f05dc
leaq -0x228(%rbp), %rdi
callq 0x1d1110
jmp 0x1f07ca
movb $0x1, -0x2d1(%rbp)
testb $0x1, -0x2d1(%rbp)
jne 0x1f07e6
movq -0x320(%rbp), %rdi
callq 0x1d5cb0
leaq -0x2d0(%rbp), %rdi
callq 0x1d85c0
leaq -0x228(%rbp), %rdi
callq 0x1d1e20
movq -0x318(%rbp), %rax
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
leaq -0x2d0(%rbp), %rdi
callq 0x1d85c0
leaq -0x228(%rbp), %rdi
callq 0x1d1e20
movq -0x230(%rbp), %rdi
callq 0x1ebeb0
nopw %cs:(%rax,%rax)