// File: /workspace/github_cpp_makefile_star2_O1/auton1[P]viterbi/viterbi.cpp
// Function: read_genetic_map_at_positions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::vector<unsigned int, std::allocator<unsigned int>>&, std::vector<double, std::allocator<double>>&)
void read_genetic_map_at_positions(string &filename, vector<unsigned int> &positions, vector<double> &map_out)
{
	// FILE FORMAT IS CHROM POS(BP) RATE(cM/Mb) MAP(cM)
	ifstream in(filename.c_str());
	if (!in.good())
		LOG.error("Could not open map file: " + filename);
	string line;
	stringstream ss;
	getline(in, line);	// Header
	string CHROM;
	int POS;
	double rate, map_pos;
	vector<int> pos;
	vector<double> map;

	while (!in.eof())
	{
		getline(in, line);
		if (line == "")
			continue;
		ss.clear(); ss.str("");
		ss.str(line);

		ss >> CHROM >> POS >> rate >> map_pos;

		pos.push_back(POS);
		map.push_back(map_pos);
	}
	// Interpolate map at positions
	map_out.resize(positions.size());

	for (unsigned int ui=0; ui<positions.size(); ui++)
	{
		vector<int>::iterator it = upper_bound(pos.begin(), pos.end(), positions[ui]);
		if (it == pos.end())
		{
			map_out[ui] = map[map.size()-1];
			continue;
		}
		else if (it != pos.begin())
			it--;

		int idx = distance(pos.begin(), it);
		int idx2 = idx+1;

		if (pos[idx] == positions[ui])
			map_out[ui] = map[idx];
		else
			map_out[ui] = map[idx] + ((map[idx2] - map[idx]) * (positions[ui] - pos[idx]) / (pos[idx2] - pos[idx]));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movq %rdx, 0x48(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, %r14
movq (%rdi), %rsi
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x5820
movq (%rbx), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x108(%rsp,%rax)
je 0x6ac2
leaq 0x3263d(%rip), %rsi     # 0x390c0
leaq 0xc8(%rsp), %rdi
movq %r14, %rdx
callq 0xb7dd
leaq 0x43a0e(%rip), %rdi     # 0x4a4a8
leaq 0xc8(%rsp), %rsi
movl $0x1, %edx
callq 0x3721e
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6ac2
callq 0x5410
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x2f0(%rsp), %r15
movq %r15, %rdi
callq 0x52e0
movq 0xe8(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x5440
movsbl %al, %edx
leaq 0xe8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x5830
leaq 0x90(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movq %rax, 0x40(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x108(%rsp,%rax)
jne 0x6cc7
leaq (%rsp,%rax), %rdi
addq $0xe8, %rdi
leaq 0xb0(%rsp), %r13
leaq 0x308(%rsp), %r12
leaq 0x60(%rsp), %rbp
leaq 0x3437b(%rip), %rbx     # 0x3aeff
leaq 0xa0(%rsp), %r14
movl $0xa, %esi
callq 0x5440
movsbl %al, %edx
leaq 0xe8(%rsp), %rdi
movq %rbp, %rsi
callq 0x5830
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x50e0
testl %eax, %eax
je 0x6ca6
movq 0x2f0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x5750
movq %r13, 0xa0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0xc868
movq %r12, %rdi
movq %r14, %rsi
callq 0x5640
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x6c05
callq 0x5410
movq %r12, %rdi
movq %rbp, %rsi
callq 0x5640
movq %r15, %rdi
leaq 0x80(%rsp), %rsi
callq 0x5590
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x5230
movq %rax, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x5290
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0x5290
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x6c67
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x6c76
leaq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0xca5a
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x6c97
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x6ca6
leaq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xcb8e
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0xe8, %rdi
testb $0x2, 0x20(%rdi)
je 0x6b8c
movq 0x58(%rsp), %rbx
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x2, %rsi
movq 0x48(%rsp), %rdi
callq 0xb7ac
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
je 0x6e04
sarq $0x2, %rcx
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %r14
movq %r14, %rsi
subq %rdx, %rsi
sarq $0x2, %rsi
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
movq 0x48(%rsp), %rdi
movq (%rdi), %r10
subq %r8, %r9
xorl %r11d, %r11d
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
movq %rdx, %r15
testq %rsi, %rsi
jle 0x6d67
movl (%rax,%r11,4), %ebp
movq %rsi, %rdi
movq %rdx, %r15
movq %rdi, %r12
shrq %r12
movq %r12, %r13
notq %r13
addq %rdi, %r13
leaq (%r15,%r12,4), %rdi
addq $0x4, %rdi
cmpl -0x4(%rdi), %ebp
cmovaeq %rdi, %r15
cmovbq %r12, %r13
movq %r13, %rdi
testq %r13, %r13
jg 0x6d3d
cmpq %r14, %r15
je 0x6de8
xorl %edi, %edi
cmpq %rdx, %r15
sete %dil
leaq (%r15,%rdi,4), %r15
subq %rdx, %r15
shlq $0x1e, %r15
addq %rbx, %r15
movq %r15, %rdi
sarq $0x1e, %rdi
movl (%rdx,%rdi), %ebp
movl (%rax,%r11,4), %r12d
movq %r15, %rdi
sarq $0x1d, %rdi
movsd (%r8,%rdi), %xmm0
subl %ebp, %r12d
je 0x6def
movabsq $0x100000000, %rdi      # imm = 0x100000000
addq %rdi, %r15
movq %r15, %rdi
sarq $0x1d, %rdi
movsd (%r8,%rdi), %xmm1
subsd %xmm0, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r12, %xmm2
mulsd %xmm1, %xmm2
sarq $0x1e, %r15
movl (%rdx,%r15), %edi
subl %ebp, %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm2
addsd %xmm2, %xmm0
jmp 0x6def
movsd -0x8(%r8,%r9), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
movl %r11d, %edi
cmpq %rdi, %rcx
ja 0x6d2b
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6e13
callq 0x5410
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x6e22
callq 0x5410
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x6e3c
callq 0x5410
movq 0x4313d(%rip), %rsi     # 0x49f80
leaq 0x2f0(%rsp), %rdi
callq 0x5330
leaq 0x370(%rsp), %rdi
callq 0x5100
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x6e71
callq 0x5410
leaq 0xe8(%rsp), %rdi
callq 0x58a0
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x6f37
movq %rax, %rbx
jmp 0x6f41
jmp 0x6ed1
movq %rax, %rbx
jmp 0x6f2d
movq %rax, %rbx
jmp 0x6f0c
jmp 0x6ed1
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x6ed4
callq 0x5410
jmp 0x6ed4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6ee3
callq 0x5410
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x6ef2
callq 0x5410
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x6f0c
callq 0x5410
movq 0x4306d(%rip), %rsi     # 0x49f80
leaq 0x2f0(%rsp), %rdi
callq 0x5330
leaq 0x370(%rsp), %rdi
callq 0x5100
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x6f41
callq 0x5410
leaq 0xe8(%rsp), %rdi
callq 0x58a0
movq %rbx, %rdi
callq 0x57d0