// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/bcfutils.c
// Function: bcf_anno_max
int bcf_anno_max(bcf1_t *b)
{
	int k, max_gq, max_sp, n_het;
	kstring_t str;
	uint8_t *gt, *gq;
	int32_t *sp;
	max_gq = max_sp = n_het = 0;
	gt = locate_field(b, "GT", 2);
	if (gt == 0) return -1;
	gq = locate_field(b, "GQ", 2);
	sp = locate_field(b, "SP", 2);
	if (sp)
		for (k = 0; k < b->n_smpl; ++k)
			if (gt[k]&0x3f)
				max_sp = max_sp > (int)sp[k]? max_sp : sp[k];
	if (gq)
		for (k = 0; k < b->n_smpl; ++k)
			if (gt[k]&0x3f)
				max_gq = max_gq > (int)gq[k]? max_gq : gq[k];
	for (k = 0; k < b->n_smpl; ++k) {
		int a1, a2;
		a1 = gt[k]&7; a2 = gt[k]>>3&7;
		if ((!a1 && a2) || (!a2 && a1)) { // a het
			if (gq == 0) ++n_het;
			else if (gq[k] >= 20) ++n_het;
		}
	}
	if (n_het) max_sp -= (int)(4.343 * log(n_het) + .499);
	if (max_sp < 0) max_sp = 0;
	memset(&str, 0, sizeof(kstring_t));
	if (*b->info) kputc(';', &str);
	ksprintf(&str, "MXSP=%d;MXGQ=%d", max_sp, max_gq);
	bcf_append_info(b, str.s, str.l);
	free(str.s);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
leaq 0x8494(%rip), %rsi      # 0x44d58
callq 0x3cac3
testq %rax, %rax
je 0x3c9b1
movq %rax, %r15
leaq 0x84b4(%rip), %rsi      # 0x44d90
movq %rbx, %rdi
callq 0x3cac3
movq %rax, %r12
leaq 0x428b(%rip), %rsi      # 0x40b79
movq %rbx, %rdi
callq 0x3cac3
xorl %ebp, %ebp
movl $0x0, %r14d
testq %rax, %rax
je 0x3c92a
movslq 0x5c(%rbx), %rcx
testq %rcx, %rcx
jle 0x3c92a
xorl %edx, %edx
xorl %r14d, %r14d
testb $0x3f, (%r15,%rdx)
je 0x3c922
movl (%rax,%rdx,4), %esi
cmpl %esi, %r14d
cmovlel %esi, %r14d
incq %rdx
cmpq %rdx, %rcx
jne 0x3c911
testq %r12, %r12
je 0x3c955
movslq 0x5c(%rbx), %rax
testq %rax, %rax
jle 0x3c955
xorl %ecx, %ecx
xorl %ebp, %ebp
testb $0x3f, (%r15,%rcx)
je 0x3c94d
movzbl (%r12,%rcx), %edx
cmpl %edx, %ebp
cmovlel %edx, %ebp
incq %rcx
cmpq %rcx, %rax
jne 0x3c93c
movslq 0x5c(%rbx), %rcx
testq %rcx, %rcx
jle 0x3c9bc
xorl %edx, %edx
xorl %eax, %eax
movzbl (%r15,%rdx), %esi
movl %esi, %edi
shrl $0x3, %edi
testb $0x7, %sil
sete %r8b
testb $0x7, %dil
setne %r9b
testb %r9b, %r8b
jne 0x3c996
testb $0x7, %dil
setne %dil
testb $0x7, %sil
sete %sil
orb %dil, %sil
jne 0x3c9a7
testq %r12, %r12
je 0x3c9a5
cmpb $0x14, (%r12,%rdx)
sbbl $-0x1, %eax
jmp 0x3c9a7
incl %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x3c962
jmp 0x3c9be
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3cab3
xorl %eax, %eax
testl %eax, %eax
je 0x3c9e2
cvtsi2sd %eax, %xmm0
callq 0x3330
mulsd 0x8335(%rip), %xmm0     # 0x44d08
addsd 0x1645(%rip), %xmm0     # 0x3e020
cvttsd2si %xmm0, %eax
subl %eax, %r14d
xorl %r15d, %r15d
testl %r14d, %r14d
cmovlel %r15d, %r14d
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x38(%rbx), %rax
cmpb $0x0, (%rax)
je 0x3ca7f
movq (%rsp), %rax
incq %rax
cmpq 0x8(%rsp), %rax
jb 0x3ca5d
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, 0x8(%rsp)
movq 0x10(%rsp), %rdi
callq 0x3720
movq %rax, 0x10(%rsp)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rsp)
movb $0x3b, (%rcx,%rax)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rcx,%rax)
leaq 0x830d(%rip), %rsi      # 0x44d93
movq %rsp, %r12
movq %r12, %rdi
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x21558
movq 0x10(%r12), %rsi
movl (%r12), %edx
movq %rbx, %rdi
callq 0x3b898
movq 0x10(%r12), %rdi
callq 0x3350
movl %r15d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq