// File: /workspace/github_cpp_makefile_star2_O1/auton1[P]viterbi/bcf_entry_setters.cpp
// Function: bcf_entry::set_indv_GENOTYPE_and_PHASE(unsigned int, unsigned int const&, unsigned int const&)
void bcf_entry::set_indv_GENOTYPE_and_PHASE(unsigned int indv, const unsigned int &pos, const unsigned int &size)
{
	int8_t tmp, tmp2;
	unsigned int cur_pos = pos;
	char phased[2] = {'/', '|'};
	ploidy.resize(N_indv);
	ploidy[indv] = 0;

	for (unsigned int ui=0; ui<size; ui++)
	{
		tmp = *reinterpret_cast<const int8_t*>(&line[cur_pos]);
		if ( tmp == (int8_t)0x81 )
			break;
		ploidy[indv]++;
		cur_pos += sizeof(int8_t);
	}

	if (ploidy[indv] == 0)
	{
		set_indv_GENOTYPE_alleles(indv, make_pair(-2, -2));
	}
	else if (ploidy[indv] == 1)
	{
		set_indv_PHASE(indv, '|');
		tmp = *reinterpret_cast<const int8_t*>(&line[pos]);
		if (tmp == (int8_t)0x80)
			tmp = -1;
		else
			tmp = (tmp >> 1) - 1;
		set_indv_GENOTYPE_alleles(indv, make_pair(tmp, -2));
	}
	else if (ploidy[indv] == 2)
	{
		tmp = *reinterpret_cast<const int8_t*>(&line[pos]);
		tmp2 = *reinterpret_cast<const int8_t*>(&line[pos+sizeof(int8_t)]);

		if (tmp == (int8_t)0x80)
			tmp = -1;
		else
			tmp = (tmp >> 1) - 1;

		if (tmp2 == (int8_t)0x80)
		{
			tmp2 = -1;
			set_indv_PHASE(indv, '/');
		}
		else
		{
			char phase = phased[ tmp2 & (int8_t)1 ];
			tmp2 = (tmp2 >> 1) - 1;
			set_indv_PHASE(indv, phase);
		}
		set_indv_GENOTYPE_alleles(indv, make_pair((int)tmp, (int)tmp2));
	}
	else if (ploidy[indv] > 2)
		LOG.error("Polyploidy found, and is not supported by vcftools: " + CHROM + ":" + header::int2str(POS));
	parsed_GT[indv] = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r12
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
movl (%rdx), %r13d
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x8(%rbx), %esi
callq 0xc1c0
movl %ebp, %r14d
movq 0x4e8(%rbx), %rax
movl $0x0, (%rax,%r14,4)
cmpl $0x0, (%r12)
je 0x27e44
movq 0x3c0(%rbx), %rcx
xorl %edx, %edx
leal (%rdx,%r13), %esi
cmpb $-0x7f, (%rcx,%rsi)
je 0x27e44
incl (%rax,%r14,4)
incl %edx
cmpl (%r12), %edx
jb 0x27e2e
movl (%rax,%r14,4), %eax
cmpl $0x2, %eax
je 0x27eb6
cmpl $0x1, %eax
je 0x27e71
testl %eax, %eax
jne 0x27f0e
movabsq $-0x100000002, %rax     # imm = 0xFFFFFFFEFFFFFFFE
leaq 0x8(%rsp), %rdx
movq %rax, (%rdx)
jmp 0x27fb3
movq %rbx, %rdi
movl %ebp, %esi
movl $0x7c, %edx
callq 0x28202
movl (%r15), %eax
movq 0x3c0(%rbx), %rcx
movb (%rcx,%rax), %al
movl %eax, %ecx
sarb %cl
decb %cl
cmpb $-0x80, %al
movzbl %cl, %eax
movl $0xff, %ecx
cmovnel %eax, %ecx
movsbl %cl, %eax
leaq 0x8(%rsp), %rdx
movl %eax, (%rdx)
movl $0xfffffffe, 0x4(%rdx)  # imm = 0xFFFFFFFE
jmp 0x27fb3
movl (%r15), %eax
movq 0x3c0(%rbx), %rcx
movb (%rcx,%rax), %dl
movzbl 0x1(%rcx,%rax), %r12d
movl %edx, %eax
sarb %al
decb %al
cmpb $-0x80, %dl
movzbl %al, %eax
movl $0xff, %r15d
cmovnel %eax, %r15d
cmpq $0x80, %r12
jne 0x27f6f
movq %rbx, %rdi
movl %ebp, %esi
movl $0x2f, %edx
callq 0x28202
movabsq $-0x100000002, %rax     # imm = 0xFFFFFFFEFFFFFFFE
addq $0x2, %rax
jmp 0x27fa2
cmpl $0x3, %eax
jl 0x27fbd
leaq 0x3e0(%rbx), %rdx
leaq 0x12db5(%rip), %rsi     # 0x3acda
leaq 0x68(%rsp), %r15
movq %r15, %rdi
callq 0xb7dd
leaq 0x1317c(%rip), %rsi     # 0x3b0b5
movq %r15, %rdi
callq 0x5870
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x27feb
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x27ff2
movl %r12d, %eax
andl $0x1, %eax
leaq 0x12d3c(%rip), %rcx     # 0x3acb8
movsbl (%rax,%rcx), %edx
sarb %r12b
movq %rbx, %rdi
movl %ebp, %esi
callq 0x28202
movsbq %r12b, %rcx
shlq $0x20, %rcx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
movsbq %r15b, %rcx
movl %ecx, %ecx
orq %rax, %rcx
leaq 0x8(%rsp), %rdx
movq %rcx, (%rdx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x28190
movq 0x560(%rbx), %rax
movl %r14d, %edx
movl $0x1, %esi
movl %r14d, %ecx
shlq %cl, %rsi
shrl $0x6, %edx
orq %rsi, (%rax,%rdx,8)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl 0x400(%rbx), %esi
leaq 0x48(%rsp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x17284
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x50(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r15, %rcx
je 0x28041
movq 0x18(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x28060
leaq 0x58(%rsp), %rdi
movl $0xf, %esi
cmpq %rdi, -0x10(%rdi)
je 0x2805b
movq 0x58(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x28071
movq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x50f0
jmp 0x2807f
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
leaq 0x38(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x280a3
movq %rsi, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x280a9
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x223db(%rip), %rdi     # 0x4a4a8
leaq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x3721e
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x280ef
callq 0x5410
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28102
callq 0x5410
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x28111
callq 0x5410
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x27fbd
callq 0x5410
jmp 0x27fbd
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28148
callq 0x5410
jmp 0x28148
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28160
callq 0x5410
jmp 0x28160
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x28174
callq 0x5410
jmp 0x28174
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28187
callq 0x5410
movq %rbx, %rdi
callq 0x57d0
nop