// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: overlap_statistics(overlap_region_alloc*, ma_ug_t*, long*, unsigned char)
uint32_t overlap_statistics(overlap_region_alloc* olist, ma_ug_t *ug, int64_t *tt, uint8_t mm)
{
	uint32_t k, sp = (uint32_t)-1, ep = (uint32_t)-1, l = 0;
	for (k = 0; k < olist->length; k++) {
		/**
		if(b->olist.list[k].y_id != 38) continue;
		**/		
		/**
		
		for (z = 0, te = ta = tua = 0; z < b->olist.list[k].w_list_length; z++) {
			if(b->olist.list[k].w_list[z].y_end != -1) {
				te += b->olist.list[k].w_list[z].error;
				ta += b->olist.list[k].w_list[z].x_end + 1 - b->olist.list[k].w_list[z].x_start;
				fprintf(stderr, "x->[%lu, %lu), y->[%d, %d), e->%d\n", b->olist.list[k].w_list[z].x_start, b->olist.list[k].w_list[z].x_end+1, 
					b->olist.list[k].w_list[z].y_start, b->olist.list[k].w_list[z].y_end+1, b->olist.list[k].w_list[z].error);
			}
			else {
				tua += b->olist.list[k].w_list[z].x_end + 1 - b->olist.list[k].w_list[z].x_start;
			}
		}
		fprintf(stderr, "[M::utg%.6d%c::is_match:%u] x->[%u, %u); y->[%u, %u), ualigned->%u, e_rate->%f\n", b->olist.list[k].y_id+1, "lc"[s->ug->u.a[b->olist.list[k].y_id].circ], 
		b->olist.list[k].is_match == 1, b->olist.list[k].x_pos_s, b->olist.list[k].x_pos_e+1, b->olist.list[k].y_pos_s, b->olist.list[k].y_pos_e+1, tua, (float)te/(float)ta);
		**/
		if(tt){
			uint32_t z;
			for (z = 0; z < olist->list[k].w_list.n; z++) {
				if(olist->list[k].w_list.a[z].y_end != -1) {
					if(tt) *tt += olist->list[k].w_list.a[z].x_end+1-olist->list[k].w_list.a[z].x_start;
				}
			}
		}
		if(olist->list[k].is_match == mm) {
			if(sp == (uint32_t)-1 || ep < olist->list[k].x_pos_s) {
				if(sp != (uint32_t)-1) l += ep + 1 - sp;
				sp = olist->list[k].x_pos_s;
				ep = olist->list[k].x_pos_e;
			} else {
				ep = MAX(ep, olist->list[k].x_pos_e);
			}
			if(ug) {
				fprintf(stderr, "[M::utg%.6d%c::is_match->%u] rev->%u, x->[%u, %u), y->[%u, %u)\n", (int)olist->list[k].y_id+1, "lc"[ug->u.a[olist->list[k].y_id].circ], olist->list[k].is_match, 
				olist->list[k].y_pos_strand, olist->list[k].x_pos_s, olist->list[k].x_pos_e+1, olist->list[k].y_pos_s, olist->list[k].y_pos_e+1);
			}
		}
	}
	if(sp != (uint32_t)-1) l += ep + 1 - sp;
	return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x10(%rsp)
cmpq $0x0, 0x10(%rdi)
je 0x1a7f3c
movl %ecx, %ebx
movq %rdx, %r14
movq %rdi, %r12
movzbl %bl, %eax
movl %eax, 0xc(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x1, %ecx
xorl %edx, %edx
movq $0x0, (%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq (%r12), %rax
testq %r14, %r14
je 0x1a7e56
imulq $0xa8, %rdx, %rsi
movq 0x48(%rax,%rsi), %r9
testq %r9, %r9
je 0x1a7e56
addq %rax, %rsi
addq $0x48, %rsi
movq 0x10(%rsi), %rdi
movl $0x1, %r8d
xorl %r10d, %r10d
shlq $0x5, %r10
cmpl $-0x1, 0xc(%rdi,%r10)
je 0x1a7e4b
addq %rdi, %r10
movl 0x4(%r10), %r9d
subl (%r10), %r9d
incl %r9d
movslq %r9d, %r9
addq %r9, (%r14)
movq (%rsi), %r9
movl %r8d, %r10d
incl %r8d
cmpq %r10, %r9
ja 0x1a7e29
imulq $0xa8, %rdx, %rdx
cmpb %bl, 0x2c(%rax,%rdx)
jne 0x1a7ea2
addq %rdx, %rax
movl 0x4(%rax), %r10d
cmpl $-0x1, %r15d
je 0x1a7e83
cmpl %r10d, %ebp
jae 0x1a7e8f
addl %ecx, %ebp
movq (%rsp), %rcx
addl %ebp, %ecx
incl %ecx
movq %rcx, (%rsp)
movl 0x8(%rax), %r11d
movl %r10d, %r15d
movl %r11d, %ebp
jmp 0x1a7e9a
movl 0x8(%rax), %r11d
cmpl %r11d, %ebp
cmovbel %r11d, %ebp
cmpq $0x0, 0x10(%rsp)
jne 0x1a7eba
incl %r13d
movl %r15d, %ecx
negl %ecx
movq %r13, %rdx
cmpq %r13, 0x10(%r12)
ja 0x1a7dfb
jmp 0x1a7f29
movq 0xed11f(%rip), %rcx     # 0x294fe0
movq (%rcx), %rdi
movl 0x10(%rax), %ecx
movl 0x14(%rax), %edx
movq %rdx, 0x20(%rsp)
leal 0x1(%rcx), %edx
movq 0x10(%rsp), %rsi
movq 0x10(%rsi), %rsi
leaq (%rcx,%rcx,4), %rcx
movl (%rsi,%rcx,8), %ecx
shrl $0x1f, %ecx
leaq 0x8c84f(%rip), %rsi     # 0x23473b
movsbl (%rcx,%rsi), %ecx
movl 0x1c(%rax), %r9d
incl %r11d
movl 0x18(%rax), %eax
incl %eax
movq %rax, 0x18(%rsp)
leaq 0x9832d(%rip), %rsi     # 0x240235
movl 0xc(%rsp), %r8d
xorl %eax, %eax
pushq 0x18(%rsp)
pushq 0x28(%rsp)
pushq %r11
pushq %r10
callq 0x22b0
addq $0x20, %rsp
jmp 0x1a7ea2
subl %r15d, %ebp
incl %ebp
xorl %eax, %eax
cmpl $-0x1, %r15d
cmovnel %ebp, %eax
addl (%rsp), %eax
jmp 0x1a7f3e
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq