// File: /workspace/github_c_makefile_star2_O2/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 %rbx
movl $0x1, %ebp
xorl %r14d, %r14d
movl %ebp, %eax
movl %ebp, %r9d
xorl %ebx, %ebx
xorl %r11d, %r11d
xorl %r10d, %r10d
cmpq $0x80, %r14
je 0x5787
movq 0x30(%rsi,%r14), %r15
cmpq %rbx, %r15
jbe 0x5771
movq %rbx, %r11
movl %eax, %r9d
movl %ebp, %eax
movq %r15, %rbx
jmp 0x577c
cmpq %r11, %r15
cmoval %ebp, %r9d
cmovaq %r15, %r11
addq %r15, %r10
addq $0x20, %r14
incl %ebp
jmp 0x5751
testq %r10, %r10
je 0x589c
movq %r10, %rsi
subq %rbx, %rsi
cmpq $0x2, %rsi
setae %bpl
movslq %ecx, %rcx
cmpq %rcx, %r10
setb %cl
orb %bpl, %cl
je 0x58a8
movslq %r8d, %rcx
cmpq %rcx, %rbx
setb %r8b
movslq %edx, %rcx
cmpq %rcx, %rsi
seta %dl
xorl %ecx, %ecx
orb %r8b, %dl
movl $0x0, %edx
jne 0x58c7
movq %rsi, %xmm1
subq %r11, %rsi
movq %rsi, %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
cmpq $0x100, %r10            # imm = 0x100
jb 0x5869
movdqa 0x13c8b(%rip), %xmm1    # 0x19480
pand %xmm0, %xmm1
por 0x13c8f(%rip), %xmm1    # 0x19490
psrlq $0x20, %xmm0
por 0x13c92(%rip), %xmm0    # 0x194a0
subpd 0x13c9a(%rip), %xmm0    # 0x194b0
movq %r10, %xmm2
punpckldq 0x13c9d(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x13ca5(%rip), %xmm2    # 0x194d0
addpd %xmm1, %xmm0
mulpd 0x13ca9(%rip), %xmm0    # 0x194e0
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 0x13c9d(%rip), %xmm0    # 0x194f0
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 0x58bf
movq 0x8(%rdi), %rdx
movq %xmm0, %rsi
orq %rsi, %r10
movzbl (%rdx,%r10), %edx
jmp 0x58c4
movl $0x1f, %edx
movl $0x3e0, %ecx            # imm = 0x3E0
jmp 0x58c7
cmpq %rbx, %r10
movl $0x1f, %ecx
movl $0x19, %edx
cmovel %ecx, %edx
movl $0x320, %ecx            # imm = 0x320
jmp 0x58c7
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 %r14
popq %r15
popq %rbp
retq