// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x58, %rsp
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movb %al, -0x21(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x34(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x28c76b
cmpq $0x0, -0x20(%rbp)
je 0x28c566
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0xa8, %rdx, %rdx
addq %rdx, %rcx
cmpq 0x48(%rcx), %rax
jae 0x28c564
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movl -0x38(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x28c554
cmpq $0x0, -0x20(%rbp)
je 0x28c552
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movl -0x38(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0xa8, %rdx, %rdx
addq %rdx, %rcx
movq 0x58(%rcx), %rcx
movl -0x38(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x28c554
jmp 0x28c556
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x28c4a9
jmp 0x28c566
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
movzbl -0x21(%rbp), %ecx
cmpl %ecx, %eax
jne 0x28c75b
cmpl $-0x1, -0x2c(%rbp)
je 0x28c5ac
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0xa8, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jae 0x28c5f7
cmpl $-0x1, -0x2c(%rbp)
je 0x28c5c1
movl -0x30(%rbp), %eax
addl $0x1, %eax
subl -0x2c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x28c63b
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0xa8, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jb 0x28c61b
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x28c635
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x28c759
movq 0x137993(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %edx
addl $0x1, %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movl -0x28(%rbp), %esi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x1f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf8c63(%rip), %rax     # 0x385303
movsbl (%rax,%rcx), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %esi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movzbl 0x2c(%rax), %r8d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %esi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0x1c(%rax), %r9d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %esi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0x4(%rax), %ebx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %esi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0x8(%rax), %r11d
addl $0x1, %r11d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %esi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0x14(%rax), %r10d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %esi
imulq $0xa8, %rsi, %rsi
addq %rsi, %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
leaq 0x1046c8(%rip), %rsi    # 0x390e09
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x22a0
jmp 0x28c75b
jmp 0x28c75d
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x28c486
cmpl $-0x1, -0x2c(%rbp)
je 0x28c780
movl -0x30(%rbp), %eax
addl $0x1, %eax
subl -0x2c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)