// File: /workspace/github_cpp_makefile_star2_O1/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 %rax
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x1ab603
cmpq $0x7fffffff, (%rsi)     # imm = 0x7FFFFFFF
jne 0x1ab57d
decq %rax
movq %rax, (%rsi)
movl 0x8(%rdi), %r8d
incl %r8d
movq %r8, 0x90(%rsi)
movq 0x58(%rdi), %r8
shlq $0x5, %rax
movslq 0x4(%r8,%rax), %rax
movq %rax, 0x70(%rsi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x58(%rsi)
cmpq %rdx, 0x90(%rsi)
jl 0x1ab688
movq %rdx, 0x90(%rsi)
movq 0x60(%rsi), %rax
movq %rax, (%rcx)
cmpq %rdx, 0x70(%rsi)
je 0x1ab5f6
movq (%rsi), %r8
testq %r8, %r8
js 0x1ab5f6
movq 0x58(%rdi), %rax
leaq 0x1(%r8), %rdi
shlq $0x5, %r8
addq %rax, %r8
addq $0x1c, %r8
movslq -0x18(%r8), %r10
cmpq %rdx, %r10
jle 0x1ab5f6
movslq -0x1c(%r8), %r9
cmpq %rdx, %r9
jle 0x1ab60e
cmpl $0x0, (%r8)
je 0x1ab5df
subq %r9, %r10
addq %r10, 0x58(%rsi)
movl (%r8), %r10d
addq %r10, 0x60(%rsi)
movq %r9, 0x70(%rsi)
leaq -0x2(%rdi), %r9
movq %r9, (%rsi)
decq %rdi
addq $-0x20, %r8
testq %rdi, %rdi
jg 0x1ab5b9
movq 0x60(%rsi), %rax
movq %rax, (%rcx)
movq 0x58(%rsi), %rax
jmp 0x1ab60c
movq $0x0, (%rcx)
xorl %eax, %eax
popq %rcx
retq
movq $0x0, (%rcx)
movq (%rsi), %r8
shlq $0x5, %r8
movl 0x1c(%rax,%r8), %edi
testl %edi, %edi
je 0x1ab65f
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)
movq 0x60(%rsi), %rdi
addq %rdi, (%rcx)
movq (%rsi), %rcx
shlq $0x5, %rcx
cmpl $0x0, 0x1c(%rax,%rcx)
je 0x1ab680
addq %rcx, %rax
movslq 0x4(%rax), %rax
subq %rdx, %rax
jmp 0x1ab682
xorl %eax, %eax
addq 0x58(%rsi), %rax
jmp 0x1ab60c
leaq 0x89816(%rip), %rdi     # 0x234ea5
leaq 0x882f5(%rip), %rsi     # 0x23398b
leaq 0x8981b(%rip), %rcx     # 0x234eb8
movl $0x14bb, %edx           # imm = 0x14BB
callq 0x2110