// File: /workspace/github_cpp_makefile_star2_O1/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
movl %edx, 0xc(%rsp)
movq %rsi, %rbx
movq %rdi, %rbp
leaq 0x60(%rsp), %r15
movq %r15, %rdi
callq 0x12bc0
movq %r15, %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x128d0
leaq 0xd8(%rsp), %rdi
callq 0x12220
testb %al, %al
je 0x13a86
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x60(%rsp), %rax
movq -0x18(%rax), %rax
xorl %r14d, %r14d
testb $0x2, 0x80(%rsp,%rax)
movl $0x0, %r15d
jne 0x13864
leaq (%rsp,%rax), %rdi
addq $0x60, %rdi
xorl %r15d, %r15d
leaq 0x10(%rsp), %r12
leaq 0x22ac2(%rip), %r13     # 0x362a3
xorl %r14d, %r14d
movl $0xa, %esi
callq 0x129c0
movsbl %al, %edx
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x13340
movq %r12, %rdi
movq %r13, %rsi
callq 0x122b0
testl %eax, %eax
je 0x1384d
incl %r14d
testl %r15d, %r15d
jne 0x1384d
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x13847
movq 0x10(%rsp), %rcx
xorl %edx, %edx
xorl %r15d, %r15d
movl 0xc(%rsp), %edi
xorl %esi, %esi
cmpb %dil, (%rcx,%rdx)
sete %sil
addq %rsi, %r15
incq %rdx
cmpq %rdx, %rax
jne 0x1382d
incl %r15d
jmp 0x1384d
movl $0x1, %r15d
movq 0x60(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0x60, %rdi
testb $0x2, 0x20(%rdi)
je 0x137e4
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x13880
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x12a90
leaq 0x60(%rsp), %rdi
callq 0x121d0
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %rax, 0x10(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
movslq %r14d, %r8
movslq %r15d, %rcx
movq %rcx, %rax
orq %r8, %rax
js 0x13ad9
testl %r14d, %r14d
je 0x138df
testl %r15d, %r15d
je 0x138df
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
xorl %edx, %edx
idivq %rcx
cmpq %r8, %rax
jl 0x13af8
movq %rcx, %rsi
imulq %r8, %rsi
movq %rbp, %rdi
movq %r8, %rdx
callq 0x12180
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x128d0
movq $0x0, 0x30(%rsp)
movq %rbp, 0x38(%rsp)
movq 0x60(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x129c0
movsbl %al, %edx
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x13340
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x13a22
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r14
testl %r14d, %r14d
jle 0x139d0
movq 0x30(%rsp), %rax
leaq (,%rax,8), %r15
addq (%rbp), %r15
movq 0x8(%rbp), %rbx
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq 0x1(%rdi), %rbp
xorl %r13d, %r13d
movl 0xc(%rsp), %eax
cmpb %al, -0x1(%rbp)
jne 0x139c6
testl %r13d, %r13d
js 0x13a67
cmpq 0x30(%rsp), %rbx
jle 0x13a67
movslq %r13d, %r12
movq 0x38(%rsp), %rax
cmpq %r12, 0x10(%rax)
jle 0x13a67
callq 0x12cb0
movl 0xc(%rsp), %eax
imulq %rbx, %r12
incl %r13d
movsd %xmm0, (%r15,%r12,8)
movq %rbp, %rdi
incq %rbp
decq %r14
jne 0x13982
jmp 0x139d3
xorl %r13d, %r13d
testl %r13d, %r13d
movq 0x38(%rsp), %rbp
js 0x13a67
movq 0x8(%rbp), %rbx
cmpq 0x30(%rsp), %rbx
jle 0x13a67
movslq %r13d, %r14
cmpq %r14, 0x10(%rbp)
jle 0x13a67
callq 0x12cb0
imulq %r14, %rbx
shlq $0x3, %rbx
addq (%rbp), %rbx
movq 0x30(%rsp), %rax
movsd %xmm0, (%rbx,%rax,8)
incq %rax
movq %rax, 0x30(%rsp)
leaq 0x60(%rsp), %r14
jmp 0x13914
leaq 0x60(%rsp), %rdi
callq 0x121d0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x13a48
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x12a90
leaq 0x60(%rsp), %rdi
callq 0x12250
movq %rbp, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2296c(%rip), %rdi     # 0x363da
leaq 0x22878(%rip), %rsi     # 0x362ed
leaq 0x22993(%rip), %rcx     # 0x3640f
movl $0x16f, %edx            # imm = 0x16F
callq 0x126c0
movl $0x10, %edi
callq 0x12510
movq %rbx, %rdx
movq %rax, %rbx
leaq 0x227f3(%rip), %rsi     # 0x36290
leaq 0x40(%rsp), %rdi
callq 0x12920
leaq 0x227f6(%rip), %rsi     # 0x362a4
leaq 0x40(%rsp), %rdi
callq 0x133d0
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x13b26
movups (%rcx), %xmm0
movups %xmm0, (%r15)
jmp 0x13b33
leaq 0x229bf(%rip), %rdi     # 0x3649f
leaq 0x22b47(%rip), %rsi     # 0x3662e
leaq 0x22b75(%rip), %rcx     # 0x36663
movl $0x115, %edx            # imm = 0x115
callq 0x126c0
movl $0x8, %edi
callq 0x12510
movq 0x454af(%rip), %rcx     # 0x58fb8
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x454b9(%rip), %rsi     # 0x58fd0
movq 0x4548a(%rip), %rdx     # 0x58fa8
movq %rax, %rdi
callq 0x13170
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %bpl
movq %rbx, %rdi
callq 0x13080
xorl %ebp, %ebp
movq 0x4548d(%rip), %rsi     # 0x58ff0
movq 0x45456(%rip), %rdx     # 0x58fc0
movq %rbx, %rdi
callq 0x13170
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x13b94
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x12a90
jmp 0x13b94
movq %rax, %r14
movb $0x1, %bpl
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13bb7
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x12a90
jmp 0x13bb7
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x13bfc
movq %rbx, %rdi
callq 0x12760
jmp 0x13bfc
jmp 0x13bd4
jmp 0x13bd4
movq %rax, %r14
jmp 0x13bfc
movq %rax, %r14
jmp 0x13be0
movq %rax, %r14
movq (%rbp), %rdi
callq 0x12c50
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x13bfc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x12a90
leaq 0x60(%rsp), %rdi
callq 0x12250
movq %r14, %rdi
callq 0x13210