// File: /workspace/github_c_makefile_star2_O3/lh3[P]fermi2/correct.c
// Function: fmc_intv2tip
int fmc_intv2tip(uint8_t *qtab[2], const rldintv_t t[6], int max_ec_depth, int q1_depth, int min_occ) // given a "tip" compute the consensus and the quality
{
	int c, max_c, max_c2, q1, q2;
	uint64_t max, max2, rest, rest2, sum;
	for (c = 1, max = max2 = 0, max_c = max_c2 = 1, sum = 0; c <= 4; ++c) { // get the top 2 bases
		if (t[c].x[2] > max) max2 = max, max_c2 = max_c, max = t[c].x[2], max_c = c;
		else if (t[c].x[2] > max2) max2 = t[c].x[2], max_c2 = c;
		sum += t[c].x[2];
	}
	rest = sum - max; rest2 = sum - max - max2; // the following always stands: rest2 <= rest <= sum and 0 <= max2 <= max <= sum
	if (sum == 0) {
		q1 = q2 = FMC_Q_NULL;
	} else if (rest <= 1 && sum >= q1_depth) { // if rest=1, max=sum-1 and max2=1, then rest2=0
		q1 = FMC_Q_1;
		q2 = rest? FMC_Q_1 : FMC_Q_NULL;
	} else if (max < min_occ || rest > max_ec_depth) {
		q1 = q2 = 0;
	} else {
		if (sum > 255) {
			rest  = (int)(255. * rest  / sum + .499);
			rest2 = (int)(255. * rest2 / sum + .499);
			sum = 255;
		}
		q1 = qtab[0][sum<<8|rest];
		q2 = rest? qtab[1][sum<<8|rest2] : FMC_Q_NULL;
	}
	return fmc_cell_set_val(4-max_c, 4-max_c2, q1, q2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl $0x1, %ebx
xorl %r14d, %r14d
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %r15d, %r15d
movl $0x1, %r9d
movl $0x1, %ebp
movq 0x30(%rsi,%r14), %r13
cmpq %r15, %r13
jbe 0x6b4c
movl %ebx, %eax
movl %ebp, %r9d
movq %r13, %r12
movq %r15, %r11
movq %r13, %r15
movl %ebx, %ebp
jmp 0x6b5c
cmpq %r11, %r13
cmoval %ebx, %r9d
cmovaq %r13, %r11
movl %ebp, %eax
movq %r15, %r12
addq %r13, %r10
addq $0x20, %r14
incl %ebx
cmpq $0x80, %r14
jne 0x6b30
testq %r10, %r10
je 0x6c81
movq %r10, %rsi
subq %r12, %rsi
cmpq $0x2, %rsi
setae %bl
movslq %ecx, %rcx
cmpq %rcx, %r10
setb %cl
orb %bl, %cl
je 0x6c8d
movslq %r8d, %rcx
cmpq %rcx, %r12
setb %r8b
movslq %edx, %rcx
cmpq %rcx, %rsi
seta %dl
xorl %ecx, %ecx
orb %r8b, %dl
movl $0x0, %edx
jne 0x6cac
movq %rsi, %xmm1
subq %r11, %rsi
movq %rsi, %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
cmpq $0x100, %r10            # imm = 0x100
jb 0x6c4e
movdqa 0x168c6(%rip), %xmm1    # 0x1d4a0
pand %xmm0, %xmm1
por 0x168ca(%rip), %xmm1    # 0x1d4b0
psrlq $0x20, %xmm0
por 0x168cd(%rip), %xmm0    # 0x1d4c0
subpd 0x168d5(%rip), %xmm0    # 0x1d4d0
movq %r10, %xmm2
punpckldq 0x168d8(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x168e0(%rip), %xmm2    # 0x1d4f0
addpd %xmm1, %xmm0
mulpd 0x168e4(%rip), %xmm0    # 0x1d500
movapd %xmm2, %xmm1
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addpd %xmm1, %xmm2
divpd %xmm2, %xmm0
addpd 0x168d8(%rip), %xmm0    # 0x1d510
cvttpd2dq %xmm0, %xmm0
xorpd %xmm1, %xmm1
pcmpgtd %xmm0, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movl $0xff, %r10d
movq (%rdi), %rcx
shlq $0x8, %r10
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
movq %xmm1, %rdx
movq %r10, %rsi
orq %rdx, %rsi
movzbl (%rcx,%rsi), %ecx
testq %rdx, %rdx
je 0x6ca4
movq 0x8(%rdi), %rdx
movq %xmm0, %rsi
orq %rsi, %r10
movzbl (%rdx,%r10), %edx
jmp 0x6ca9
movl $0x1f, %edx
movl $0x3e0, %ecx            # imm = 0x3E0
jmp 0x6cac
cmpq %r12, %r10
movl $0x1f, %ecx
movl $0x19, %edx
cmovel %ecx, %edx
movl $0x320, %ecx            # imm = 0x320
jmp 0x6cac
movl $0x1f, %edx
shll $0x5, %ecx
orl %edx, %ecx
shll $0xc, %eax
movl $0x4000, %edx           # imm = 0x4000
subl %eax, %edx
shll $0xa, %r9d
movl $0x1000, %eax           # imm = 0x1000
subl %r9d, %eax
orl %edx, %eax
orl %ecx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq