// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, %rbx
movq %rsi, %r14
cmpl $0x0, 0x1c(%rdx)
je 0x48a90
movq (%rdi), %rax
movq 0x10(%rax), %rax
movl 0x10(%rbx), %edx
imulq $0x28, %rdx, %rsi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl (%rax,%rsi), %edx
movl 0x4(%r14), %eax
notl %eax
addl %edx, %eax
subl 0x8(%r14), %edx
jmp 0x48a9a
movl 0x4(%r14), %edx
movl 0x8(%r14), %eax
decl %eax
movl 0x14(%rbx), %ebp
movl 0x18(%rbx), %r12d
cmpl %ebp, %edx
cmoval %edx, %ebp
cmpl %r12d, %eax
cmovbl %eax, %r12d
cmpl %r12d, %ebp
jbe 0x48ab9
xorl %eax, %eax
jmp 0x48bf3
movq %rdi, 0x8(%rsp)
movq %rcx, %r13
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x48903
movq %rax, %r15
movq %rbx, %rdi
movq %r12, %rsi
callq 0x48903
movq %rax, %rdi
movq %r15, 0x10(%rsp)
cmpq %rax, %r15
jg 0x48c02
cmpl $0x0, 0x1c(%rbx)
movq %r13, %r15
je 0x48b20
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl 0x10(%rbx), %ecx
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
notq %r12
addq %r13, %r12
subq %rbp, %r13
movq %r12, %rbp
jmp 0x48b26
incq %r12
movq %r12, %r13
movl 0x8(%r14), %eax
movl (%r14), %ecx
movl 0x4(%r14), %edx
movq %rax, %rsi
subq %r13, %rsi
subq %rax, %r13
movl %eax, %r12d
subl %edx, %r12d
movq %rdx, %rax
subq %rbp, %rax
subq %rdx, %rbp
testb $0x1, %cl
cmovneq %rsi, %rbp
cmovneq %rax, %r13
movq (%r15), %rax
movq 0x8(%r15), %rdx
cmpq 0x10(%r15), %rdx
jne 0x48b93
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmovneq %rcx, %rdx
movq %rdx, 0x10(%r15)
imulq $0x1c, %rdx, %rsi
movq %rdi, 0x8(%rsp)
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, (%r15)
movq 0x8(%r15), %rdx
movl (%r14), %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r15)
imulq $0x1c, %rdx, %rdx
movl (%rbx), %esi
movl %esi, (%rax,%rdx)
movq 0x10(%rsp), %rsi
movl %esi, 0x4(%rax,%rdx)
incl %edi
movl %edi, 0x8(%rax,%rdx)
shrl %ecx
movl $0x80000000, %esi       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0xc(%rax,%rdx)
movl %ebp, 0x10(%rax,%rdx)
addl %r13d, %r12d
movl %r12d, 0x14(%rax,%rdx)
andl 0x18(%rax,%rdx), %esi
movl $0x40000000, %ecx       # imm = 0x40000000
orl %ecx, %esi
movl %esi, 0x18(%rax,%rdx)
movl (%r14), %esi
andl $0x1, %esi
cmpl %esi, 0x1c(%rbx)
movl $0xc0000000, %esi       # imm = 0xC0000000
cmovel %ecx, %esi
movl %esi, 0x18(%rax,%rdx)
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19e140(%rip), %rdi    # 0x1e6d49
leaq 0x19aa93(%rip), %rsi    # 0x1e36a3
leaq 0x19e13c(%rip), %rcx    # 0x1e6d53
movl $0x581f, %edx           # imm = 0x581F
callq 0x2110