// File: /workspace/github_c_makefile_star2_O2/lh3[P]bgt/atomic.c
// Function: bcf_atom2bcf2
void bcf_atom2bcf2(const bcf_atom_t *a, bcf1_t *b, int write_M, int id_GT, int use_missing)
{
	static uint8_t conv[4] = { 1<<1, 2<<1, 0<<1, 3<<1 };
	static uint8_t conv_no_M[4] = { 1<<1, 2<<1, 0<<1, 1<<1 };
	static uint8_t conv_no_M_missing[4] = { 1<<1, 2<<1, 0<<1, 0<<1 };
	b->rid = a->rid, b->pos = a->pos, b->rlen = a->rlen;
	b->qual = 0, b->n_info = b->n_fmt = b->n_sample = 0;
	b->n_allele = write_M && a->has_multi? 3 : 2;
	b->shared.l = b->indiv.l = 0;
	bcf_enc_size(&b->shared, 0, BCF_BT_CHAR); // empty ID
	bcf_enc_vchar(&b->shared, a->alt - a->ref.s - 1, a->ref.s);
	bcf_enc_vchar(&b->shared, a->ref.s + a->ref.l - a->alt, a->alt);
	if (b->n_allele > 2) bcf_enc_vchar(&b->shared, 3, "<M>");
	bcf_enc_vint(&b->shared, 0, 0, -1); // empty FILTER
	b->unpacked = 0;

	if (id_GT >= 0) {
		int i;
		b->n_fmt = 1; b->n_sample = a->n_gt>>1;
		bcf_enc_int1(&b->indiv, id_GT);
		bcf_enc_size(&b->indiv, 2, BCF_BT_INT8);
		ks_resize(&b->indiv, b->indiv.l + b->n_sample*2 + 1);
		if (write_M) {
			for (i = 0; i < b->n_sample<<1; ++i)
				b->indiv.s[b->indiv.l++] = conv[a->gt[i]] | a->phased;
		} else {
			if (use_missing)
				for (i = 0; i < b->n_sample<<1; ++i)
					b->indiv.s[b->indiv.l++] = conv_no_M_missing[a->gt[i]] | a->phased;
			else
				for (i = 0; i < b->n_sample<<1; ++i)
					b->indiv.s[b->indiv.l++] = conv_no_M[a->gt[i]] | a->phased;
		}
		b->indiv.s[b->indiv.l] = 0;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %ebp
movl %ecx, %r12d
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movq 0x20(%rdi), %rax
movq %rax, (%rsi)
movl 0x28(%rdi), %eax
movl %eax, 0x8(%rsi)
andl $0x0, 0xc(%rsi)
movzwl 0x12(%rsi), %eax
shll $0x10, %eax
movq %rax, 0x10(%rsi)
testl %edx, %edx
je 0xef18
movb 0x33(%r14), %al
andb $0x20, %al
shrb $0x5, %al
movzbl %al, %eax
shll $0x10, %eax
orq $0x20000, %rax          # imm = 0x20000
jmp 0xef1d
movl $0x20000, %eax          # imm = 0x20000
movq %rax, 0x10(%rbx)
andq $0x0, 0x30(%rbx)
leaq 0x18(%rbx), %r13
andq $0x0, 0x18(%rbx)
pushq $0x7
popq %rdi
movq %r13, %rsi
callq 0xe7ba
movq 0x10(%r14), %rdx
movl %edx, %esi
notl %esi
addl 0x18(%r14), %esi
movq %r13, %rdi
callq 0xb092
movl 0x10(%r14), %esi
addl (%r14), %esi
movq 0x18(%r14), %rdx
subl %edx, %esi
movq %r13, %rdi
callq 0xb092
cmpl $0x30000, 0x10(%rbx)    # imm = 0x30000
jb 0xef7e
leaq 0xa59b(%rip), %rdx      # 0x1950e
pushq $0x3
popq %rsi
movq %r13, %rdi
callq 0xb092
pushq $-0x1
popq %rcx
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xad8f
andl $0x0, 0x88(%rbx)
testl %r12d, %r12d
js 0xf18d
leaq 0x30(%rbx), %r13
movabsq $-0xff00000001, %rax    # imm = 0xFFFFFF00FFFFFFFF
andq 0x10(%rbx), %rax
btsq $0x20, %rax
movq %rax, 0x10(%rbx)
movl 0x2c(%r14), %ecx
shrl %ecx
shlq $0x28, %rcx
movabsq $0x1ffffffff, %rdx      # imm = 0x1FFFFFFFF
andq %rax, %rdx
orq %rcx, %rdx
movq %rdx, 0x10(%rbx)
cmpl $0x7f, %r12d
ja 0xeff4
pushq $0x11
popq %rdi
movq %r13, %rsi
callq 0xe7ba
movl %r12d, %edi
movq %r13, %rsi
callq 0xe7ba
jmp 0xf03c
cmpl $0x7fff, %r12d          # imm = 0x7FFF
ja 0xf018
leaq 0x2(%rsp), %rax
movw %r12w, (%rax)
movq %rax, %r12
pushq $0x12
popq %rdi
movq %r13, %rsi
callq 0xe7ba
pushq $0x2
jmp 0xf030
leaq 0x4(%rsp), %rax
movl %r12d, (%rax)
movq %rax, %r12
pushq $0x13
popq %rdi
movq %r13, %rsi
callq 0xe7ba
pushq $0x4
popq %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0xe64b
pushq $0x21
popq %rdi
movq %r13, %rsi
callq 0xe7ba
movq 0x10(%rbx), %rax
movq 0x30(%rbx), %rcx
shrq $0x28, %rax
leaq (%rcx,%rax,2), %rdx
incq %rdx
cmpq %rdx, 0x38(%rbx)
jae 0xf0a9
leaq (%rcx,%rax,2), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x38(%rbx)
movq 0x40(%rbx), %rdi
callq 0x2340
movq %rax, 0x40(%rbx)
xorl %eax, %eax
testl %r15d, %r15d
je 0xf0f7
leaq 0xa4c2(%rip), %rcx      # 0x19579
movq 0x10(%rbx), %rdx
shrq $0x27, %rdx
andl $-0x2, %edx
cmpq %rdx, %rax
jae 0xf181
movq 0x38(%r14), %rdx
movzbl (%rdx,%rax), %edx
movl 0x30(%r14), %esi
shrl $0x1f, %esi
orb (%rdx,%rcx), %sil
movq 0x30(%rbx), %rdx
movq 0x40(%rbx), %rdi
leaq 0x1(%rdx), %r8
movq %r8, 0x30(%rbx)
movb %sil, (%rdi,%rdx)
incq %rax
jmp 0xf0b7
testl %ebp, %ebp
je 0xf13e
leaq 0xa47f(%rip), %rcx      # 0x19581
movq 0x10(%rbx), %rdx
shrq $0x27, %rdx
andl $-0x2, %edx
cmpq %rdx, %rax
jae 0xf181
movq 0x38(%r14), %rdx
movzbl (%rdx,%rax), %edx
movl 0x30(%r14), %esi
shrl $0x1f, %esi
orb (%rdx,%rcx), %sil
movq 0x30(%rbx), %rdx
movq 0x40(%rbx), %rdi
leaq 0x1(%rdx), %r8
movq %r8, 0x30(%rbx)
movb %sil, (%rdi,%rdx)
incq %rax
jmp 0xf102
leaq 0xa438(%rip), %rcx      # 0x1957d
movq 0x10(%rbx), %rdx
shrq $0x27, %rdx
andl $-0x2, %edx
cmpq %rdx, %rax
jae 0xf181
movq 0x38(%r14), %rdx
movzbl (%rdx,%rax), %edx
movl 0x30(%r14), %esi
shrl $0x1f, %esi
orb (%rdx,%rcx), %sil
movq 0x30(%rbx), %rdx
movq 0x40(%rbx), %rdi
leaq 0x1(%rdx), %r8
movq %r8, 0x30(%rbx)
movb %sil, (%rdi,%rdx)
incq %rax
jmp 0xf145
movq 0x30(%rbx), %rax
movq 0x40(%rbx), %rcx
movb $0x0, (%rcx,%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq