// File: /workspace/github_c_makefile_star2_O3/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
movl $0x47, %esi
movl $0x54, %edx
callq 0x3d2d8
testq %rax, %rax
je 0x3d23d
movq %rax, %r15
movq %rbx, %rdi
movl $0x47, %esi
movl $0x51, %edx
callq 0x3d2d8
movq %rax, %r12
movq %rbx, %rdi
movl $0x53, %esi
movl $0x50, %edx
callq 0x3d2d8
xorl %ebp, %ebp
movl $0x0, %r14d
testq %rax, %rax
je 0x3d191
movslq 0x5c(%rbx), %rcx
testq %rcx, %rcx
jle 0x3d191
xorl %edx, %edx
xorl %r14d, %r14d
testb $0x3f, (%r15,%rdx)
je 0x3d189
movl (%rax,%rdx,4), %esi
cmpl %esi, %r14d
cmovlel %esi, %r14d
incq %rdx
cmpq %rdx, %rcx
jne 0x3d178
movl 0x5c(%rbx), %eax
testq %r12, %r12
je 0x3d1be
testl %eax, %eax
jle 0x3d248
xorl %ecx, %ecx
xorl %ebp, %ebp
testb $0x3f, (%r15,%rcx)
je 0x3d1b6
movzbl (%r12,%rcx), %edx
cmpl %edx, %ebp
cmovlel %edx, %ebp
incq %rcx
cmpq %rcx, %rax
jne 0x3d1a5
testl %eax, %eax
jle 0x3d24a
xorl %edx, %edx
xorl %ecx, %ecx
movzbl (%r15,%rdx), %esi
movl %esi, %edi
shrl $0x3, %edi
testb $0x7, %sil
sete %r8b
testb $0x7, %dil
setne %r9b
testb %r9b, %r8b
jne 0x3d1fe
testb $0x7, %dil
setne %dil
testb $0x7, %sil
sete %sil
orb %dil, %sil
jne 0x3d20f
testq %r12, %r12
je 0x3d20d
cmpb $0x14, (%r12,%rdx)
sbbl $-0x1, %ecx
jmp 0x3d20f
incl %ecx
incq %rdx
cmpq %rdx, %rax
jne 0x3d1ca
testl %ecx, %ecx
je 0x3d24a
cvtsi2sd %ecx, %xmm0
callq 0x3330
mulsd 0x8bec(%rip), %xmm0     # 0x45e18
addsd 0x1dfc(%rip), %xmm0     # 0x3f030
cvttsd2si %xmm0, %eax
subl %eax, %r14d
jmp 0x3d24a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3d2c8
xorl %ebp, %ebp
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 0x3d294
movq $0x2, 0x8(%rsp)
movl $0x2, %edi
callq 0x3240
movq %rax, 0x10(%rsp)
movq $0x1, (%rsp)
movw $0x3b, (%rax)
leaq 0x8c05(%rip), %rsi      # 0x45ea0
movq %rsp, %r12
movq %r12, %rdi
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x21b28
movq 0x10(%r12), %rsi
movl (%r12), %edx
movq %rbx, %rdi
callq 0x3c07b
movq 0x10(%r12), %rdi
callq 0x3350
movl %r15d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq