// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x1, -0x28(%rbp)
movl $0x1, -0x24(%rbp)
movq $0x0, -0x58(%rbp)
cmpl $0x4, -0x20(%rbp)
jg 0x7ac4
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
cmpq -0x38(%rbp), %rax
jbe 0x7a63
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x7a9b
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
cmpq -0x40(%rbp), %rax
jbe 0x7a99
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x7a9b
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x7a13
movq -0x58(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
subq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x7afa
movl $0x1f, -0x30(%rbp)
movl $0x1f, -0x2c(%rbp)
jmp 0x7c7a
cmpq $0x1, -0x48(%rbp)
ja 0x7b32
movq -0x58(%rbp), %rax
movslq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jb 0x7b32
movl $0x19, -0x2c(%rbp)
movq -0x48(%rbp), %rdx
movl $0x1f, %eax
movl $0x19, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x30(%rbp)
jmp 0x7c78
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jb 0x7b4c
movq -0x48(%rbp), %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x7b5f
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
jmp 0x7c76
cmpq $0xff, -0x58(%rbp)
jbe 0x7c28
movq -0x48(%rbp), %xmm0
movaps 0x24927(%rip), %xmm3    # 0x2c4a0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x2492b(%rip), %xmm2    # 0x2c4b0
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x248d4(%rip), %xmm1    # 0x2c470
mulsd %xmm1, %xmm0
movq -0x58(%rbp), %xmm4
punpckldq %xmm3, %xmm4    # xmm4 = xmm4[0],xmm3[0],xmm4[1],xmm3[1]
subpd %xmm2, %xmm4
movaps %xmm4, %xmm5
unpckhpd %xmm4, %xmm4            # xmm4 = xmm4[1,1]
addsd %xmm5, %xmm4
divsd %xmm4, %xmm0
movsd 0x248a4(%rip), %xmm4    # 0x2c468
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm4
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm4, %xmm0
mulsd %xmm1, %xmm0
movq -0x58(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x24856(%rip), %xmm1    # 0x2c468
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cltq
movq %rax, -0x50(%rbp)
movq $0xff, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x8, %rcx
orq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x2c(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x7c66
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x8, %rcx
orq -0x50(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
jmp 0x7c70
movl $0x1f, %eax
movl %eax, -0x5c(%rbp)
jmp 0x7c70
movl -0x5c(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x7c78
jmp 0x7c7a
movl $0x4, %eax
subl -0x24(%rbp), %eax
shll $0xc, %eax
movl $0x4, %ecx
subl -0x28(%rbp), %ecx
shll $0xa, %ecx
orl %ecx, %eax
movl -0x2c(%rbp), %ecx
shll $0x5, %ecx
orl %ecx, %eax
orl -0x30(%rbp), %eax
popq %rbp
retq
nop