// File: chhylp123[P]hifiasm/inter.cpp
// Function: cal_sec_e_min(overlap_region*, unsigned long*, long, long, long*)
int64_t cal_sec_e_min(overlap_region *z, uint64_t *w_idx, int64_t wl, int64_t ql, int64_t *sec_err)
{
	int64_t wid, k, wn = z->w_list.n, ws, we, o[2], tot_e, sc; uint64_t self_err;
	o[0] = o[1] = tot_e = 0;
	for (k = 0; k < wn; k++) {
		wid = z->w_list.a[k].x_start/wl;
		if(w_idx[wid] == (uint64_t)-1) continue;
		ws = wid*wl; we = ws+wl; if(we > ql) we = ql; we--;
		self_err = THRESHOLD_MAX_SIZE + 1;
		if(z->w_list.a[k].y_end != -1) self_err = z->w_list.a[k].error;
		
		if(ws == z->w_list.a[k].x_start && we == z->w_list.a[k].x_end) {
			if(self_err <= w_idx[wid]) {
				o[0] += we+1-ws;
			} else {
				o[1] += we+1-ws; tot_e += self_err - w_idx[wid];
			}
		}
	}
	if(sec_err) (*sec_err) = tot_e;

	sc = o[0] - (o[1]*ERROR_RATE)-(tot_e*5);
	return sc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x2acd22
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
cqto
idivq -0x18(%rbp)
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
jne 0x2acc06
jmp 0x2acd11
movq -0x30(%rbp), %rax
imulq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
jle 0x2acc31
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
movq $0x20, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x2acc7a
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0x14(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movslq (%rcx), %rcx
cmpq %rcx, %rax
jne 0x2acd0f
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movslq 0x4(%rcx), %rcx
cmpq %rcx, %rax
jne 0x2acd0f
movq -0x78(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
ja 0x2acce1
movq -0x50(%rbp), %rax
addq $0x1, %rax
subq -0x48(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x2acd0d
movq -0x50(%rbp), %rax
addq $0x1, %rax
subq -0x48(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x78(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x2acd0f
jmp 0x2acd11
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2acbc4
cmpq $0x0, -0x28(%rbp)
je 0x2acd34
movq -0x68(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
cvtsi2sdq -0x60(%rbp), %xmm1
cvtsi2sdq -0x58(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0xd54a1(%rip), %xmm2    # 0x382200
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
imulq $0x5, -0x68(%rbp), %rax
cvtsi2sd %rax, %xmm1
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)