// File: /workspace/github_c_makefile_star2_O1/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 0x6dec
movl %ebx, %eax
movl %ebp, %r9d
movq %r13, %r12
movq %r15, %r11
movq %r13, %r15
movl %ebx, %ebp
jmp 0x6dfc
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 0x6dd0
testq %r10, %r10
je 0x6f27
movq %r10, %rsi
subq %r12, %rsi
cmpq $0x2, %rsi
setae %bl
movslq %ecx, %rcx
cmpq %rcx, %r10
setb %cl
orb %bl, %cl
je 0x6f33
movslq %r8d, %rcx
cmpq %rcx, %r12
setb %cl
movslq %edx, %rdx
cmpq %rdx, %rsi
seta %r8b
xorl %edx, %edx
orb %cl, %r8b
movl $0x0, %ecx
jne 0x6f52
movq %rsi, %rcx
subq %r11, %rcx
cmpq $0x100, %r10            # imm = 0x100
jb 0x6f02
movq %rsi, %xmm0
movq 0x15558(%rip), %xmm1    # 0x1c3d0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1555c(%rip), %xmm2    # 0x1c3e0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movsd 0x155fc(%rip), %xmm0    # 0x1c498
mulsd %xmm0, %xmm3
movq %r10, %xmm4
punpckldq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
addsd %xmm4, %xmm5
divsd %xmm5, %xmm3
movsd 0x155cb(%rip), %xmm4    # 0x1c490
addsd %xmm4, %xmm3
cvttsd2si %xmm3, %edx
movslq %edx, %rsi
movq %rcx, %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
addsd %xmm3, %xmm1
mulsd %xmm0, %xmm1
divsd %xmm5, %xmm1
addsd %xmm4, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
movl $0xff, %r10d
movq (%rdi), %rdx
shlq $0x8, %r10
movq %r10, %r8
orq %rsi, %r8
movzbl (%rdx,%r8), %edx
testq %rsi, %rsi
je 0x6f4a
movq 0x8(%rdi), %rsi
orq %rcx, %r10
movzbl (%rsi,%r10), %ecx
jmp 0x6f4f
movl $0x1f, %ecx
movl $0x3e0, %edx            # imm = 0x3E0
jmp 0x6f52
testq %rsi, %rsi
movl $0x1f, %edx
movl $0x19, %ecx
cmovel %edx, %ecx
movl $0x320, %edx            # imm = 0x320
jmp 0x6f52
movl $0x1f, %ecx
shll $0x5, %edx
orl %ecx, %edx
shll $0xc, %eax
movl $0x4000, %ecx           # imm = 0x4000
subl %eax, %ecx
shll $0xa, %r9d
movl $0x1000, %eax           # imm = 0x1000
subl %r9d, %eax
orl %ecx, %eax
orl %edx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq