// File: /workspace/github_cpp_makefile_star2_O2/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 0x9c6c
movl %ebp, %r14d
movq 0x4e8(%rbx), %rdx
andl $0x0, (%rdx,%r14,4)
movq 0x3c0(%rbx), %rax
xorl %ecx, %ecx
cmpl (%r12), %ecx
jae 0x20abe
leal (%rcx,%r13), %esi
movl %esi, %esi
cmpb $-0x7f, (%rax,%rsi)
je 0x20abe
incl %ecx
movl %ecx, (%rdx,%r14,4)
jmp 0x20aa4
cmpl $0x2, %ecx
je 0x20b2a
cmpl $0x1, %ecx
je 0x20ae7
testl %ecx, %ecx
jne 0x20b79
movabsq $-0x100000002, %rax     # imm = 0xFFFFFFFEFFFFFFFE
leaq 0x8(%rsp), %rdx
movq %rax, (%rdx)
jmp 0x20c51
pushq $0x7c
popq %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x20d28
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 0x20c51
movl (%r15), %ecx
movb (%rax,%rcx), %dl
movzbl 0x1(%rax,%rcx), %r12d
movl %edx, %eax
sarb %al
decb %al
cmpb $-0x80, %dl
movzbl %al, %eax
movl $0xff, %r15d
cmovnel %eax, %r15d
cmpq $0x80, %r12
jne 0x20c0d
pushq $0x2f
popq %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x20d28
movabsq $-0x100000002, %rax     # imm = 0xFFFFFFFEFFFFFFFE
addq $0x2, %rax
jmp 0x20c40
leaq 0x3e0(%rbx), %rdx
leaq 0xe093(%rip), %rsi      # 0x2ec1a
leaq 0x68(%rsp), %r15
movq %r15, %rdi
callq 0x967d
leaq 0xe452(%rip), %rdx      # 0x2efed
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x98b6
movl 0x400(%rbx), %esi
leaq 0x28(%rsp), %rdi
pushq $-0x1
popq %rdx
callq 0x12c9c
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x9be3
leaq 0x208fa(%rip), %rdi     # 0x414d0
leaq 0x48(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2bf18
leaq 0x48(%rsp), %rdi
callq 0x5908
leaq 0x28(%rsp), %rdi
callq 0x5908
leaq 0x8(%rsp), %rdi
callq 0x5908
leaq 0x68(%rsp), %rdi
callq 0x5908
jmp 0x20c5b
movl %r12d, %eax
andl $0x1, %eax
leaq 0xdfde(%rip), %rcx      # 0x2ebf8
movsbl (%rax,%rcx), %edx
sarb %r12b
movq %rbx, %rdi
movl %ebp, %esi
callq 0x20d28
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 0x20cc4
addq $0x560, %rbx            # imm = 0x560
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9cc0
orq %rdx, (%rax)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5908
jmp 0x20c94
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5908
jmp 0x20ca3
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5908
jmp 0x20cb2
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5908
movq %rbx, %rdi
callq 0x5800