// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: get_overlap_region_sub_err(overlap_region*, rtrace_iter*, long, long*)
int64_t get_overlap_region_sub_err(overlap_region *o, rtrace_iter *it, int64_t qs, int64_t *sec_err)
{
	if(o->w_list.n <= 0) {
		(*sec_err) = 0;
		return 0;
	}
	if(it->k == INT32_MAX) {
		it->k = o->w_list.n-1;
		it->cur_qoff = o->x_pos_e+1;
		it->qoff = o->w_list.a[it->k].x_end;
		it->werr = 0; it->werr0 = 0;
	}
	assert(qs <= it->cur_qoff);
	it->cur_qoff = qs; (*sec_err) = it->werr0;

	if(qs == it->qoff) {
		(*sec_err) = it->werr0;
		return it->werr;
	}
	double rr; int64_t terr;
	for (; (it->k >= 0) && (qs < o->w_list.a[it->k].x_end); it->k--) {
		if(qs >= o->w_list.a[it->k].x_start && qs < o->w_list.a[it->k].x_end) {
			(*sec_err) = 0;
			if(o->w_list.a[it->k].clen > 0) {
				rr = ((double)(o->w_list.a[it->k].x_end-qs))/
								((double)(o->w_list.a[it->k].x_end-o->w_list.a[it->k].x_start));
				(*sec_err) = rr*o->w_list.a[it->k].clen;
				// if((*sec_err) == 0) (*sec_err) = 1;
			}
			(*sec_err) += it->werr0;

			terr = ((o->w_list.a[it->k].clen > 0)?(o->w_list.a[it->k].x_end-qs):(0));
			return it->werr + terr;
		}
		if(o->w_list.a[it->k].clen > 0) {
			it->werr += o->w_list.a[it->k].x_end-o->w_list.a[it->k].x_start;
			it->werr0 += o->w_list.a[it->k].clen;
		}
		it->qoff = o->w_list.a[it->k].x_start;
	}
	
	(*sec_err) = it->werr0;
	return it->werr;
}

// Assembly:
pushq %rbx
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x1b465a
cmpq $0x7fffffff, (%rsi)     # imm = 0x7FFFFFFF
jne 0x1b4668
decq %rax
movq %rax, (%rsi)
movl 0x8(%rdi), %r8d
incl %r8d
movq %r8, 0x90(%rsi)
movq 0x58(%rdi), %r9
shlq $0x5, %rax
movslq 0x4(%r9,%rax), %rax
movq %rax, 0x70(%rsi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x58(%rsi)
jmp 0x1b466f
movq $0x0, (%rcx)
xorl %eax, %eax
jmp 0x1b46e9
movq 0x90(%rsi), %r8
cmpq %rdx, %r8
jl 0x1b4769
movq %rdx, 0x90(%rsi)
movq 0x60(%rsi), %r8
movq %r8, (%rcx)
cmpq %rdx, 0x70(%rsi)
je 0x1b46e5
movq (%rsi), %r9
testq %r9, %r9
js 0x1b46e2
movq 0x58(%rdi), %rax
leaq 0x1(%r9), %rdi
shlq $0x5, %r9
addq %rax, %r9
movslq 0x4(%r9), %r11
cmpq %rdx, %r11
jle 0x1b46e2
movslq (%r9), %r10
cmpq %rdx, %r10
jle 0x1b46eb
movl 0x1c(%r9), %ebx
testq %rbx, %rbx
je 0x1b46cb
subq %r10, %r11
addq %r11, 0x58(%rsi)
addq %rbx, %r8
movq %r8, 0x60(%rsi)
movq %r10, 0x70(%rsi)
leaq -0x2(%rdi), %r10
movq %r10, (%rsi)
decq %rdi
addq $-0x20, %r9
testq %rdi, %rdi
jg 0x1b46a3
movq %r8, (%rcx)
movq 0x58(%rsi), %rax
popq %rbx
retq
movq $0x0, (%rcx)
movq (%rsi), %r8
shlq $0x5, %r8
movl 0x1c(%rax,%r8), %edi
testl %edi, %edi
je 0x1b473e
addq %rax, %r8
movslq 0x4(%r8), %r9
movq %r9, %r10
subq %rdx, %r10
xorps %xmm0, %xmm0
cvtsi2sd %r10, %xmm0
movl (%r8), %r8d
subl %r8d, %r9d
cvtsi2sd %r9d, %xmm1
divsd %xmm1, %xmm0
movl %edi, %edi
xorps %xmm1, %xmm1
cvtsi2sd %rdi, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movq %rdi, (%rcx)
jmp 0x1b4740
xorl %edi, %edi
addq 0x60(%rsi), %rdi
movq %rdi, (%rcx)
movq (%rsi), %rcx
shlq $0x5, %rcx
cmpl $0x0, 0x1c(%rax,%rcx)
je 0x1b4761
addq %rcx, %rax
movslq 0x4(%rax), %rax
subq %rdx, %rax
jmp 0x1b4763
xorl %eax, %eax
addq 0x58(%rsi), %rax
jmp 0x1b46e9
leaq 0x8ca05(%rip), %rdi     # 0x241175
leaq 0x8b4e4(%rip), %rsi     # 0x23fc5b
leaq 0x8ca0a(%rip), %rcx     # 0x241188
movl $0x14bb, %edx           # imm = 0x14BB
callq 0x2110