// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x0, 0x1c(%rdx)
je 0x7bfd1
movq (%rdi), %rax
movq 0x10(%rax), %rax
movl 0x10(%rbx), %ecx
leaq (%rcx,%rcx,4), %rcx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl (%rax,%rcx,8), %edx
movl 0x4(%r14), %eax
notl %eax
addl %edx, %eax
movl %edx, %ecx
subl 0x8(%r14), %ecx
jmp 0x7bfdb
movl 0x4(%r14), %ecx
movl 0x8(%r14), %eax
decl %eax
movl 0x14(%rbx), %ebp
movl 0x18(%rbx), %r12d
cmpl %ebp, %ecx
cmoval %ecx, %ebp
cmpl %r12d, %eax
cmovbl %eax, %r12d
cmpl %r12d, %ebp
jbe 0x7bffa
xorl %eax, %eax
jmp 0x7c142
movq %rdi, 0x8(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7be29
movq %rax, %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7be29
movq %rax, %rsi
movq %r13, 0x10(%rsp)
cmpq %rax, %r13
jg 0x7c151
cmpl $0x0, 0x1c(%rbx)
je 0x7c05b
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl 0x10(%rbx), %ecx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
notq %r12
addq %r13, %r12
subq %rbp, %r13
movq %r12, %rbp
jmp 0x7c061
incq %r12
movq %r12, %r13
movl 0x4(%r14), %eax
movl 0x8(%r14), %ecx
movq %rcx, %rdx
subq %r13, %rdx
subq %rcx, %r13
movl %ecx, %r12d
subl %eax, %r12d
movq %rax, %rcx
subq %rbp, %rcx
subq %rax, %rbp
testb $0x1, (%r14)
cmovneq %rdx, %rbp
cmovneq %rcx, %r13
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x7c0cb
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x10(%r15)
movq (%r15), %rdi
leaq (%rax,%rax,8), %rcx
movq %rsi, 0x8(%rsp)
leaq (%rcx,%rcx,2), %rsi
addq %rax, %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq %rax, (%r15)
movq (%r15), %rax
movq 0x8(%r15), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%r15)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movl (%rbx), %edx
movl %edx, (%rax,%rcx)
movq 0x10(%rsp), %rdx
movl %edx, 0x4(%rax,%rcx)
incl %esi
movl %esi, 0x8(%rax,%rcx)
movl $0x80000000, %edx       # imm = 0x80000000
movl %edx, 0xc(%rax,%rcx)
movl (%r14), %esi
shrl %esi
orl %edx, %esi
movl %esi, 0xc(%rax,%rcx)
movl %ebp, 0x10(%rax,%rcx)
addl %r13d, %r12d
movl %r12d, 0x14(%rax,%rcx)
andl 0x18(%rax,%rcx), %edx
movl $0x40000000, %esi       # imm = 0x40000000
orl %esi, %edx
movl %edx, 0x18(%rax,%rcx)
movl (%r14), %edx
andl $0x1, %edx
cmpl %edx, 0x1c(%rbx)
movl $0xc0000000, %edx       # imm = 0xC0000000
cmovel %esi, %edx
movl %edx, 0x18(%rax,%rcx)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1acb91(%rip), %rdi    # 0x228ce9
leaq 0x1a94e4(%rip), %rsi    # 0x225643
leaq 0x1acb8d(%rip), %rcx    # 0x228cf3
movl $0x581f, %edx           # imm = 0x581F
callq 0x2110