// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, (%rsp)
movq 0x80(%rsp), %r13
movl $0x1, %edi
movl $0x48, %esi
callq 0x2120
movq %rax, %rbx
testq %r15, %r15
jle 0xa3367
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %r14
xorl %ebp, %ebp
movl -0x8(%r14), %ecx
movl -0x4(%r14), %edx
movl %ecx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
shrl $0x1f, %ecx
movq %rbx, %rdi
movl %ebp, %esi
callq 0xa0115
movb (%r14), %al
movq 0x20(%rbx), %rcx
movb %al, 0x4(%rcx,%rbp,8)
incq %rbp
addq $0xc, %r14
cmpq %rbp, %r15
jne 0xa3332
movl 0x14(%rbx), %eax
addl %eax, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x2120
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
movq (%rsp), %rsi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %r13, %r9
callq 0x1e6153
testq %r15, %r15
jle 0xa3532
xorl %ecx, %ecx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r15, 0x28(%rsp)
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq 0x20(%rbx), %rax
movq %rcx, 0x8(%rsp)
cmpl $0x0, (%rax,%rcx,8)
js 0xa351c
movq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq (%rsp), %rcx
cmpl $0x0, 0xc(%rcx,%rax,8)
je 0xa351c
movq (%rsp), %rcx
leaq (%rcx,%rax,8), %r15
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%r15), %rbp
cmpq $0x0, 0x18(%rbp,%r14)
js 0xa3508
leaq (%r14,%rbp), %rdi
movl 0x4(%rbp,%r14), %eax
movl 0xc(%rbp,%r14), %ecx
leaq (%rax,%rax,2), %rax
movq 0x10(%rsp), %r9
movl 0x4(%r9,%rax,4), %esi
movl (%r9,%rax,4), %eax
andl %r8d, %eax
subl %eax, %esi
leaq (%rcx,%rcx,2), %rax
movl 0x4(%r9,%rax,4), %edx
movl (%r9,%rax,4), %eax
andl %r8d, %eax
subl %eax, %edx
leaq 0x1e731d(%rip), %rax    # 0x28a758
movss 0x158(%rax), %xmm0
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
leaq 0x30(%rsp), %r9
callq 0xa159b
testl %eax, %eax
js 0xa3572
movl 0x4(%rbx), %ecx
andl %r12d, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
jne 0xa349b
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x40(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x18(%rbp,%r14), %rsi
movq %rsi, %rdi
shrq $0x20, %rdi
movl $0x3fff, %r9d           # imm = 0x3FFF
andl %r9d, %edi
movabsq $0x7fffc00000000000, %r10 # imm = 0x7FFFC00000000000
testq %r10, %rsi
cmovnel %r9d, %edi
andl $0xffffc000, %edx       # imm = 0xFFFFC000
orl %edi, %edx
movw %dx, 0x10(%rax,%rcx,8)
incq %r13
movl 0xc(%r15), %eax
addq $0x28, %r14
cmpq %rax, %r13
jb 0xa33ee
movq 0x8(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %r15
cmpq %r15, %rcx
jne 0xa33b5
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
movl 0x14(%rbx), %eax
movl %eax, %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x14(%rbx)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, 0x18(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x184601(%rip), %rdi    # 0x227b7a
leaq 0x186721(%rip), %rsi    # 0x229ca1
leaq 0x1869bd(%rip), %rcx    # 0x229f44
movl $0xbc2, %edx            # imm = 0xBC2
callq 0x2110