// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: ma_sg_gen_ul(ma_hit_t_alloc*, long, ma_sub_t const*, R_to_U*, long, long, long)
asg_t *ma_sg_gen_ul(ma_hit_t_alloc* sources, int64_t n_read, const ma_sub_t *coverage_cut, 
R_to_U* ruIndex, int64_t max_hang, int64_t min_ovlp, int64_t ul_occ)
{
	int64_t i, j, r; asg_arc_t t, *p; const ma_hit_t *h; 
	asg_t *g = asg_init(); 
	for (i = 0; i < n_read; ++i) {
		asg_seq_set(g, i, coverage_cut[i].e - coverage_cut[i].s, coverage_cut[i].del);
        g->seq[i].c = coverage_cut[i].c;
	}
    CALLOC(g->seq_vis, (g->n_seq<<1));

    // prt_specific_overlap(sources, 22233, 22235, "+");
    // prt_specific_overlap(sources, 22235, 22233, "+");
    // fprintf(stderr, "[M::%s::] n_read::%ld\n", __func__, n_read);
    recover_contain_g(g, sources, ruIndex, max_hang, min_ovlp, ul_occ);

    for (i = 0; i < n_read; ++i) {
        if(g->seq[i].del) continue;
        for (j = 0; j < sources[i].length; j++) {
		    h = &(sources[i].buffer[j]);
            // if((Get_qn(*h) == 22233 && Get_tn(*h) == 22235)||
            //             (Get_qn(*h) == 22235 && Get_tn(*h) == 22233)) {
            //     fprintf(stderr, "[M::%s::] qn::%u, tn::%u, del::%u, bl::%u\n", __func__, Get_qn(*h), Get_tn(*h), 
            //         h->del, h->bl);
            // }
            if(h->del) continue;
		    r = ma_hit2arc(h, (coverage_cut[Get_qn(*h)].e-coverage_cut[Get_qn(*h)].s), 
                    (coverage_cut[Get_tn(*h)].e-coverage_cut[Get_tn(*h)].s), max_hang, asm_opt.max_hang_rate, min_ovlp, &t);
            assert(r >= 0);
            p = asg_arc_pushp(g); *p = t; 
            p->ou = ((h->bl>OU_MASK)?OU_MASK:h->bl);
            // if(Get_qn(*h) == 10498 && Get_tn(*h) == 10505) {
            //     fprintf(stderr, "[M::%s::] qn::%u, tn::%u, p->ou::%u, h->bl::%u\n", __func__, 
            //     Get_qn(*h), Get_tn(*h), p->ou, h->bl);
            // }
        }
    }

    asg_cleanup(g);
    asg_symm(g);
    g->r_seq = g->n_seq;
	return g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
callq 0x68f5d
movq %rax, (%rsp)
xorl %ebp, %ebp
testq %r15, %r15
cmovleq %rbp, %r15
leaq 0x8(%r12), %rbx
movq (%rsp), %r14
cmpq %rbp, %r15
je 0x6c649
movl -0x8(%rbx), %ecx
movl -0x4(%rbx), %edx
movl %ecx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
shrl $0x1f, %ecx
movq %r14, %rdi
movl %ebp, %esi
callq 0x69316
movb (%rbx), %al
movq 0x20(%r14), %rcx
movb %al, 0x4(%rcx,%rbp,8)
incq %rbp
addq $0xc, %rbx
jmp 0x6c615
movq (%rsp), %rbx
movl 0x14(%rbx), %eax
addl %eax, %eax
movslq %eax, %rdi
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq 0x80(%rsp), %r9
callq 0x1a6111
xorl %ecx, %ecx
movl $0x3fff, %ebp           # imm = 0x3FFF
movq %r15, 0x28(%rsp)
cmpq %r15, %rcx
je 0x6c7a0
movq (%rsp), %rax
movq 0x20(%rax), %rax
movq %rcx, 0x10(%rsp)
cmpl $0x0, (%rax,%rcx,8)
js 0x6c78e
imulq $0x18, 0x10(%rsp), %r14
addq 0x8(%rsp), %r14
xorl %r15d, %r15d
xorl %ebx, %ebx
movl 0xc(%r14), %eax
cmpq %rax, %rbx
jae 0x6c78e
movq (%r14), %r13
cmpq $0x0, 0x18(%r13,%r15)
js 0x6c782
leaq (%r15,%r13), %rdi
movl 0x4(%r13,%r15), %eax
movl 0xc(%r13,%r15), %ecx
imulq $0xc, %rax, %rax
movl 0x4(%r12,%rax), %esi
movl (%r12,%rax), %eax
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %eax
subl %eax, %esi
imulq $0xc, %rcx, %rax
movl 0x4(%r12,%rax), %edx
movl (%r12,%rax), %eax
andl %r8d, %eax
subl %eax, %edx
leaq 0x1e703e(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
leaq 0x30(%rsp), %r9
callq 0x6a4a7
testl %eax, %eax
js 0x6c7d1
movq (%rsp), %rdi
callq 0x6c45d
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x18(%r13,%r15), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
andl %ebp, %esi
movabsq $0x7fffc00000000000, %rdi # imm = 0x7FFFC00000000000
testq %rdi, %rdx
cmovnel %ebp, %esi
andl $0xffffc000, %ecx       # imm = 0xFFFFC000
orl %esi, %ecx
movw %cx, 0x10(%rax)
incq %rbx
addq $0x28, %r15
jmp 0x6c6bf
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %r15
jmp 0x6c68f
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x694eb
movq %rbx, %rdi
callq 0x69638
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%rbx), %eax
movl %eax, 0x18(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x179402(%rip), %rdi    # 0x1e5bda
leaq 0x17b5b2(%rip), %rsi    # 0x1e7d91
leaq 0x17b84e(%rip), %rcx    # 0x1e8034
movl $0xbc2, %edx            # imm = 0xBC2
callq 0x2110