// File: 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:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movl %esi, 0x11c(%rsp)
movq %rdx, 0x110(%rsp)
movq %rcx, 0x108(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x110(%rsp), %rcx
movl (%rcx), %ecx
movl %ecx, 0x100(%rsp)
movw 0x1decc(%rip), %cx      # 0x75b47
movw %cx, 0xfe(%rsp)
movq %rax, %rdi
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0x10140
movq 0x18(%rsp), %rdi
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0xecf0
movl $0x0, (%rax)
movl $0x0, 0xf8(%rsp)
movl 0xf8(%rsp), %eax
movq 0x108(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x57d50
movq 0x18(%rsp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movl 0x100(%rsp), %eax
movl %eax, %esi
callq 0x209b0
movb (%rax), %al
movb %al, 0x107(%rsp)
movsbl 0x107(%rsp), %eax
cmpl $-0x7f, %eax
jne 0x57d07
jmp 0x57d50
movq 0x18(%rsp), %rdi
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0xecf0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl 0x100(%rsp), %eax
addq $0x1, %rax
movl %eax, 0x100(%rsp)
movl 0xf8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x57cc2
movq 0x18(%rsp), %rdi
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0xecf0
cmpl $0x0, (%rax)
jne 0x57dc8
movl 0x11c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl $0xfffffffe, 0xec(%rsp) # imm = 0xFFFFFFFE
movl $0xfffffffe, 0xe8(%rsp) # imm = 0xFFFFFFFE
leaq 0xec(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x397b0
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %esi
movq %rax, 0xf0(%rsp)
leaq 0xf0(%rsp), %rdx
callq 0x581d0
jmp 0x5817e
movq 0x18(%rsp), %rdi
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0xecf0
cmpl $0x1, (%rax)
jne 0x57eb5
movq 0x18(%rsp), %rdi
movl 0x11c(%rsp), %esi
movl $0x7c, %edx
callq 0x58340
movq 0x18(%rsp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movq 0x110(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
callq 0x209b0
movb (%rax), %al
movb %al, 0x107(%rsp)
movsbl 0x107(%rsp), %eax
cmpl $-0x80, %eax
jne 0x57e3e
movb $-0x1, 0x107(%rsp)
jmp 0x57e52
movsbl 0x107(%rsp), %eax
sarl %eax
subl $0x1, %eax
movb %al, 0x107(%rsp)
movl 0x11c(%rsp), %eax
movl %eax, 0x10(%rsp)
movl $0xfffffffe, 0xd4(%rsp) # imm = 0xFFFFFFFE
leaq 0x107(%rsp), %rdi
leaq 0xd4(%rsp), %rsi
callq 0x592a0
movq %rax, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x592d0
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %esi
leaq 0xe0(%rsp), %rdx
callq 0x581d0
jmp 0x5817c
movq 0x18(%rsp), %rdi
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0xecf0
cmpl $0x2, (%rax)
jne 0x58029
movq 0x18(%rsp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movq 0x110(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
callq 0x209b0
movq 0x18(%rsp), %rdi
movb (%rax), %al
movb %al, 0x107(%rsp)
addq $0x3c0, %rdi            # imm = 0x3C0
movq 0x110(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
addq $0x1, %rsi
callq 0x209b0
movb (%rax), %al
movb %al, 0x106(%rsp)
movsbl 0x107(%rsp), %eax
cmpl $-0x80, %eax
jne 0x57f3f
movb $-0x1, 0x107(%rsp)
jmp 0x57f53
movsbl 0x107(%rsp), %eax
sarl %eax
subl $0x1, %eax
movb %al, 0x107(%rsp)
movsbl 0x106(%rsp), %eax
cmpl $-0x80, %eax
jne 0x57f80
movq 0x18(%rsp), %rdi
movb $-0x1, 0x106(%rsp)
movl 0x11c(%rsp), %esi
movl $0x2f, %edx
callq 0x58340
jmp 0x57fc8
movq 0x18(%rsp), %rdi
movsbl 0x106(%rsp), %eax
andl $0x1, %eax
cltq
movb 0xfe(%rsp,%rax), %al
movb %al, 0xd3(%rsp)
movsbl 0x106(%rsp), %eax
sarl %eax
subl $0x1, %eax
movb %al, 0x106(%rsp)
movl 0x11c(%rsp), %esi
movsbl 0xd3(%rsp), %edx
callq 0x58340
movl 0x11c(%rsp), %eax
movl %eax, 0xc(%rsp)
movsbl 0x107(%rsp), %eax
movl %eax, 0xc4(%rsp)
movsbl 0x106(%rsp), %eax
movl %eax, 0xc0(%rsp)
leaq 0xc4(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x397b0
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %esi
movq %rax, 0xc8(%rsp)
leaq 0xc8(%rsp), %rdx
callq 0x581d0
jmp 0x5817a
movq 0x18(%rsp), %rdi
addq $0x4e8, %rdi            # imm = 0x4E8
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0xecf0
cmpl $0x2, (%rax)
jle 0x58178
movq 0x18(%rsp), %rdx
addq $0x3e0, %rdx            # imm = 0x3E0
leaq 0x1dab3(%rip), %rsi     # 0x75b12
leaq 0x60(%rsp), %rdi
movq %rdi, (%rsp)
callq 0xe8d0
movq (%rsp), %rsi
leaq 0x1de67(%rip), %rdx     # 0x75edf
leaq 0x80(%rsp), %rdi
callq 0xf4a0
jmp 0x58087
movq 0x18(%rsp), %rax
movl 0x400(%rax), %esi
leaq 0x30(%rsp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x30500
jmp 0x580a3
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xffb0
jmp 0x580bf
leaq 0x3b53a(%rip), %rdi     # 0x93600
leaq 0xa0(%rsp), %rsi
movl $0x1, %edx
callq 0x712f0
jmp 0x580da
leaq 0xa0(%rsp), %rdi
callq 0x6b50
leaq 0x30(%rsp), %rdi
callq 0x6b50
leaq 0x80(%rsp), %rdi
callq 0x6b50
leaq 0x60(%rsp), %rdi
callq 0x6b50
jmp 0x58178
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x5816c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x5815f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x58155
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x6b50
leaq 0x30(%rsp), %rdi
callq 0x6b50
leaq 0x80(%rsp), %rdi
callq 0x6b50
leaq 0x60(%rsp), %rdi
callq 0x6b50
jmp 0x581b9
jmp 0x5817a
jmp 0x5817c
jmp 0x5817e
movq 0x18(%rsp), %rdi
addq $0x560, %rdi            # imm = 0x560
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0x102b0
movq %rax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
leaq 0x20(%rsp), %rdi
movl $0x1, %esi
callq 0x1bd30
addq $0x128, %rsp            # imm = 0x128
retq
movq 0x58(%rsp), %rdi
callq 0x69e0
nopw %cs:(%rax,%rax)