// File: /workspace/github_cpp_makefile_star2_O2/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 0x16b25c
cmpq $0x7fffffff, (%rsi)     # imm = 0x7FFFFFFF
jne 0x16b264
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 0x16b26b
andq $0x0, (%rcx)
xorl %eax, %eax
jmp 0x16b2dd
movq 0x90(%rsi), %r8
cmpq %rdx, %r8
jl 0x16b354
movq %rdx, 0x90(%rsi)
movq 0x60(%rsi), %r8
movq %r8, (%rcx)
cmpq %rdx, 0x70(%rsi)
je 0x16b2d9
movq (%rsi), %r9
movq %r9, %r10
shlq $0x5, %r10
testq %r9, %r9
js 0x16b2d6
movq 0x58(%rdi), %rax
movslq 0x4(%rax,%r10), %rbx
cmpq %rdx, %rbx
jle 0x16b2d6
movslq (%rax,%r10), %r11
cmpq %rdx, %r11
jle 0x16b2df
movl 0x1c(%rax,%r10), %eax
testq %rax, %rax
je 0x16b2c6
subq %r11, %rbx
addq %rbx, 0x58(%rsi)
addq %rax, %r8
movq %r8, 0x60(%rsi)
movq %r11, 0x70(%rsi)
decq %r9
movq %r9, (%rsi)
addq $-0x20, %r10
jmp 0x16b292
movq %r8, (%rcx)
movq 0x58(%rsi), %rax
popq %rbx
retq
andq $0x0, (%rcx)
movq (%rsi), %r8
shlq $0x5, %r8
movl 0x1c(%rax,%r8), %edi
testl %edi, %edi
je 0x16b329
addq %rax, %r8
movslq 0x4(%r8), %r9
movq %r9, %r10
subq %rdx, %r10
cvtsi2sd %r10, %xmm0
movl (%r8), %r8d
subl %r8d, %r9d
cvtsi2sd %r9d, %xmm1
divsd %xmm1, %xmm0
movl %edi, %edi
cvtsi2sd %rdi, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movq %rdi, (%rcx)
jmp 0x16b32b
xorl %edi, %edi
addq 0x60(%rsi), %rdi
movq %rdi, (%rcx)
movq (%rsi), %rcx
shlq $0x5, %rcx
cmpl $0x0, 0x1c(%rax,%rcx)
je 0x16b34c
addq %rcx, %rax
movslq 0x4(%rax), %rax
subq %rdx, %rax
jmp 0x16b34e
xorl %eax, %eax
addq 0x58(%rsi), %rax
jmp 0x16b2dd
leaq 0x87ce2(%rip), %rdi     # 0x1f303d
leaq 0x867c1(%rip), %rsi     # 0x1f1b23
leaq 0x87ce7(%rip), %rcx     # 0x1f3050
movl $0x14bb, %edx           # imm = 0x14BB
callq 0x2110