// File: /workspace/github_cpp_makefile_star2_O2/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 $0x468, %rsp            # imm = 0x468
movq %rdx, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rsi
leaq 0x260(%rsp), %r15
pushq $0x8
popq %rdx
movq %r15, %rdi
callq 0x5860
movq (%r15), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x280(%rsp,%rax)
je 0x62f7
leaq 0x26db2(%rip), %rsi     # 0x2d075
leaq 0x98(%rsp), %rdi
movq %rbx, %rdx
callq 0x967d
leaq 0x3b1f6(%rip), %rdi     # 0x414d0
leaq 0x98(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2bf18
leaq 0x98(%rsp), %rdi
callq 0x5908
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xd8(%rsp), %rdi
callq 0x5300
leaq 0x260(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x5090
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rax
andq $0x0, 0x10(%rax)
leaq 0x30(%rsp), %rcx
andq $0x0, 0x10(%rcx)
movapd %xmm0, (%rax)
movapd %xmm0, (%rcx)
leaq 0x48(%rsp), %r13
leaq 0x28ad0(%rip), %r15     # 0x2ee37
leaq 0xb8(%rsp), %rbx
leaq 0x68(%rsp), %r12
movq 0x260(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x280(%rsp,%rax)
jne 0x6459
leaq 0x260(%rsp), %rdi
movq %r13, %rsi
callq 0x5090
movq %r13, %rdi
movq %r15, %rsi
callq 0x96f3
testb %al, %al
jne 0x6374
movq 0xd8(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0xd8(%rsp), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x5790
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x3(%rsp), %rdx
callq 0x5160
leaq 0xf0(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x5690
movq %rbx, %rdi
callq 0x5908
movq %rbp, %rdi
movq %r13, %rsi
callq 0x5690
leaq 0xd8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x55c0
movq %rax, %rdi
leaq 0x4(%rsp), %rsi
callq 0x5250
movq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0x52b0
movq %rax, %rdi
movq %r12, %rsi
callq 0x52b0
leaq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x9700
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x971e
jmp 0x6374
movq 0x8(%r14), %rsi
subq (%r14), %rsi
sarq $0x2, %rsi
movq 0x8(%rsp), %rdi
callq 0x964c
xorl %eax, %eax
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
movabsq $0x100000000, %r15      # imm = 0x100000000
movl %eax, %r12d
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
jbe 0x6550
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq (%rax,%r12,4), %rdx
callq 0xa55f
cmpq 0x18(%rsp), %rax
je 0x652e
movq 0x10(%rsp), %rcx
xorl %edx, %edx
cmpq %rcx, %rax
sete %dl
leaq (%rax,%rdx,4), %rax
subq %rcx, %rax
shlq $0x1e, %rax
addq %rbx, %rax
movq %rax, %rdx
sarq $0x1e, %rdx
movl (%rcx,%rdx), %edx
movq (%r14), %rsi
movl (%rsi,%r12,4), %esi
movq %rax, %r8
sarq $0x1d, %r8
movq 0x30(%rsp), %rdi
movsd (%rdi,%r8), %xmm0
subl %edx, %esi
je 0x6538
addq %r15, %rax
movq %rax, %r8
sarq $0x1d, %r8
movsd (%rdi,%r8), %xmm1
subsd %xmm0, %xmm1
cvtsi2sd %rsi, %xmm2
mulsd %xmm1, %xmm2
sarq $0x1e, %rax
movl (%rcx,%rax), %eax
subl %edx, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm2
addsd %xmm2, %xmm0
jmp 0x6538
movq 0x38(%rsp), %rax
movsd -0x8(%rax), %xmm0
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r12,8)
leal 0x1(%r12), %eax
jmp 0x6484
leaq 0x30(%rsp), %rdi
callq 0xa19c
leaq 0x10(%rsp), %rdi
callq 0xa18e
leaq 0x78(%rsp), %rdi
callq 0x5908
leaq 0xd8(%rsp), %rdi
callq 0x5360
leaq 0x48(%rsp), %rdi
callq 0x5908
leaq 0x260(%rsp), %rdi
callq 0x58f8
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x660b
movq %rax, %rbx
jmp 0x6610
jmp 0x65d8
movq %rax, %rbx
jmp 0x65f9
movq %rax, %rbx
jmp 0x6606
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x5908
jmp 0x65db
jmp 0x65d8
jmp 0x65d8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xa19c
leaq 0x10(%rsp), %rdi
callq 0xa18e
leaq 0x78(%rsp), %rdi
callq 0x5908
leaq 0xd8(%rsp), %rdi
callq 0x5360
leaq 0x48(%rsp), %rdi
callq 0x5908
leaq 0x260(%rsp), %rdi
callq 0x58f8
movq %rbx, %rdi
callq 0x5800