// File: chhylp123[P]hifiasm/Correct.cpp
// Function: gen_contain_ov(ul_idx_t const*, utg_ct_t*, overlap_region*, kv_ul_ov_t*)
int64_t gen_contain_ov(const ul_idx_t *uref, utg_ct_t *p, overlap_region* o, kv_ul_ov_t *res)
{
	int64_t y_s, y_e, y_bs, y_be, x_s, x_e, q_s, q_e;
	if(o->y_pos_strand) {
		y_s = uref->ug->u.a[o->y_id].len - p->e;
		y_e = uref->ug->u.a[o->y_id].len - p->s - 1;
	} else {
		y_s = p->s; y_e = p->e - 1;
	}

	y_s = MAX(y_s, (int64_t)o->y_pos_s); y_e = MIN(y_e, (int64_t)o->y_pos_e);
	if(y_s > y_e) return 0;
	x_s = get_chain_x_by_y(o, y_s); x_e = get_chain_x_by_y(o, y_e) + 1;
    assert(x_s < x_e);
	// if(x_s >= x_e) fprintf(stderr, "+++y_s->%ld, y_e->%ld, x_s->%ld, x_e->%ld\n", y_s, y_e, x_s, x_e);
	if(o->y_pos_strand) {
		y_bs = uref->ug->u.a[o->y_id].len - (y_e+1);
		y_be = uref->ug->u.a[o->y_id].len - y_s;
	} else {
		y_bs = y_s; y_be = y_e + 1;
	}

	q_s = 0; q_e = p->e - p->s;
	if(p->x&1) {
		q_s += (p->e - y_be);
		q_e -= (y_bs - p->s);
	} else {
		q_s += (y_bs - p->s);
		q_e -= (p->e - y_be); 
	}

	ul_ov_t *x = NULL;
	kv_pushp(ul_ov_t, *res, &x);
	x->qn = o->x_id; x->qs = x_s; x->qe = x_e;
	x->tn = (uint32_t)(0x80000000); x->tn |= (p->x>>1);
	x->ts = q_s; x->te = q_e; x->el = 1;x->sec = 0; x->rev = ((o->y_pos_strand == (p->x&1))?0:1);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x8aad4
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
subl 0x8(%rcx), %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
subl 0x4(%rcx), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0x8aaef
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x14(%rcx), %ecx
cmpq %rcx, %rax
jl 0x8ab09
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x8ab14
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x18(%rcx), %ecx
cmpq %rcx, %rax
jg 0x8ab36
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x8ab41
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jle 0x8ab60
movq $0x0, -0x8(%rbp)
jmp 0x8ae0e
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x8a800
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x8a800
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x8ab92
jmp 0x8abb1
leaq 0x2fae28(%rip), %rdi    # 0x3859c1
leaq 0x2f777b(%rip), %rsi    # 0x38231b
movl $0x581f, %edx           # imm = 0x581F
leaq 0x2fae1f(%rip), %rcx    # 0x3859cb
callq 0x2130
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x8ac18
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x8ac2c
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8ac84
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
subq -0x48(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
subq %rax, %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x8acb2
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
subq %rcx, %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
subq -0x48(%rbp), %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x8ad27
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x8aceb
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0x8acf9
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0x8acf9
movq -0x88(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x70(%rbp), %rax
movl $0x80000000, 0xc(%rax)  # imm = 0x80000000
movq -0x18(%rbp), %rax
movl (%rax), %ecx
shrl %ecx
movq -0x70(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x70(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x18(%rax)
movq -0x70(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x0, %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x18(%rbp), %rax
movl (%rax), %esi
andl $0x1, %esi
movl $0x1, %edx
xorl %eax, %eax
cmpl %esi, %ecx
cmovel %eax, %edx
movq -0x70(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq $0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)