// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %r9, %r15
movq %r8, %r14
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r13
movl $0x1, %edi
movl $0x48, %esi
callq 0x2120
movq %rax, %rdi
testq %rbx, %rbx
movq %rax, 0x8(%rsp)
jle 0xa4534
movq %rbx, %rax
movq %r12, 0x18(%rsp)
leaq 0x8(%rbp), %rbx
xorl %r12d, %r12d
movq %rax, 0x20(%rsp)
movl -0x8(%rbx), %ecx
movl -0x4(%rbx), %edx
movl %ecx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
shrl $0x1f, %ecx
movl %r12d, %esi
callq 0xa0887
movq 0x8(%rsp), %rdi
movb (%rbx), %al
movq 0x20(%rdi), %rcx
movb %al, 0x4(%rcx,%r12,8)
incq %r12
addq $0xc, %rbx
cmpq %r12, 0x20(%rsp)
jne 0xa4143
movl 0x14(%rdi), %eax
addl %eax, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x2120
movq 0x8(%rsp), %rcx
movq %rax, 0x30(%rcx)
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movq %r15, %r8
movq 0xb0(%rsp), %r9
callq 0x1f0a97
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rax
testq %rax, %rax
jle 0xa456c
xorl %ecx, %ecx
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl %edx, 0x14(%rsp)
movq %r13, 0x60(%rsp)
movq %r15, 0x68(%rsp)
movq %r14, 0x38(%rsp)
movq %rbp, 0x58(%rsp)
movq 0x20(%rdi), %rax
cmpl $0x0, (%rax,%rcx,8)
movq %rcx, 0x50(%rsp)
js 0xa451c
leaq (%rcx,%rcx,2), %rcx
movl 0xc(%r13,%rcx,8), %eax
testl %eax, %eax
je 0xa451c
leaq (,%rcx,8), %r11
addq %r13, %r11
movl $0x21, %ebx
xorl %edx, %edx
movq %r11, 0x28(%rsp)
movq (%r11), %r9
movq -0x9(%r9,%rbx), %rsi
testq %rsi, %rsi
js 0xa450a
movl -0x15(%r9,%rbx), %edi
leaq (%rdi,%rdi,2), %rcx
movl 0x4(%rbp,%rcx,4), %eax
movl (%rbp,%rcx,4), %ecx
andl %r10d, %ecx
subl %ecx, %eax
movq %rsi, 0x18(%rsp)
testl %esi, %esi
movq %rdx, 0x70(%rsp)
movq %rdi, 0x30(%rsp)
js 0xa4270
movl -0x11(%r9,%rbx), %edi
movl -0xd(%r9,%rbx), %esi
subl %esi, %eax
movl %eax, %ecx
movl %edi, %eax
jmp 0xa427e
movl -0x11(%r9,%rbx), %edi
movl -0xd(%r9,%rbx), %esi
subl %esi, %eax
movl %edi, %ecx
movq -0x21(%r9,%rbx), %r12
movq %r12, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
movq %rbx, %r8
movl 0x4(%rbp,%rdx,4), %ebx
movl (%rbp,%rdx,4), %edx
andl %r10d, %edx
subl %edx, %ebx
cmpl %r12d, %eax
movl %r12d, %r11d
cmovll %eax, %r11d
movq %r8, 0x48(%rsp)
movq %r9, 0x40(%rsp)
movl -0x19(%r9,%r8), %edx
movl %ebx, %r10d
subl %edx, %r10d
cmpl %ecx, %r10d
movl %ecx, %r8d
cmovll %r10d, %r8d
cmpl %r14d, %r11d
jg 0xa45ac
cmpl 0x38(%rsp), %r8d
jg 0xa45ac
movl %edx, %r9d
subl %r12d, %r9d
cvtsi2ss %r9, %xmm1
addl %r11d, %r9d
addl %r8d, %r9d
cvtsi2ss %r9, %xmm2
leaq 0x1f1460(%rip), %r14    # 0x295758
movss 0x158(%r14), %xmm0
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0xa45ac
subl %edi, %esi
xorps %xmm1, %xmm1
cvtsi2ss %rsi, %xmm1
addl %r11d, %r8d
addl %esi, %r8d
xorps %xmm2, %xmm2
cvtsi2ss %r8, %xmm2
mulss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
ja 0xa45ac
cmpl %ecx, %r10d
setl %sil
setg %r10b
cmpl %eax, %r12d
setg %r11b
setl %dil
orb %r10b, %r11b
cmpb $0x1, %r11b
jne 0xa45ac
orb %sil, %dil
je 0xa45ac
cmpl %r15d, %r9d
jl 0xa45ac
cmpl %r15d, %r8d
jl 0xa45ac
cmpl $0x0, 0x18(%rsp)
setns %r14b
addl %edx, %ecx
movl %ebx, %edx
subl %ecx, %edx
xorl %r13d, %r13d
movl %r12d, %ebp
subl %eax, %ebp
setle %r9b
setg %sil
cmovlel %edx, %ebp
testl %ebp, %ebp
js 0xa45ac
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
movb -0x1(%rcx,%rax), %dl
movb %dl, 0x7(%rsp)
movzbl (%rcx,%rax), %r15d
movq 0x8(%rsp), %rdi
movl 0x4(%rdi), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rdi), %ecx
jne 0xa4410
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%rdi)
movq 0x8(%rdi), %rdi
shlq $0x3, %rax
movb %sil, 0x6(%rsp)
leaq (%rax,%rax,2), %rsi
movb %r9b, 0x5(%rsp)
callq 0x2370
movb 0x5(%rsp), %r9b
movb 0x6(%rsp), %sil
movq 0x8(%rsp), %rdi
movq %rax, 0x8(%rdi)
movl 0x4(%rdi), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0xa4414
movq 0x8(%rdi), %rax
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq 0x28(%rsp), %r11
movq 0x30(%rsp), %r8
movb %r9b, %r13b
shrq $0x1f, %r12
andl $-0x2, %r12d
orl %r12d, %r13d
xorb %sil, %r14b
movzbl %r14b, %esi
leal (%rsi,%r8,2), %esi
shlq $0x20, %r13
movq %rbp, %r9
addq %r13, %r9
subl %ebp, %ebx
leal 0x1(%rdx), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %r8d, %edx
movl %edx, 0x4(%rdi)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq %r9, (%rax,%rcx,8)
movl %esi, 0x8(%rax,%rcx,8)
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl %ebx, 0xc(%rax,%rcx,8)
movq 0x18(%rsp), %r14
shrl $0x10, %r14d
andl $0x4000, %r14d          # imm = 0x4000
movl 0x14(%rsp), %edx
andl $0x3fff, %edx           # imm = 0x3FFF
shll $0xf, %r15d
orl %r14d, %edx
orl %r15d, %edx
movl %edx, 0x14(%rsp)
movw %dx, 0x10(%rax,%rcx,8)
movb 0x7(%rsp), %dl
movb %dl, 0x12(%rax,%rcx,8)
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %rdx
movq -0x9(%rdx,%rbx), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
movl $0x3fff, %r8d           # imm = 0x3FFF
andl %r8d, %esi
movabsq $0x7fffc00000000000, %r9 # imm = 0x7FFFC00000000000
testq %r9, %rdx
cmovnel %r8d, %esi
movzwl %r14w, %edx
orl %edx, %r15d
orl %esi, %r15d
movw %r15w, 0x10(%rax,%rcx,8)
movl 0xc(%r11), %eax
movq 0x68(%rsp), %r15
movq 0x38(%rsp), %r14
movq 0x60(%rsp), %r13
movq 0x58(%rsp), %rbp
movq 0x70(%rsp), %rdx
incq %rdx
movl %eax, %ecx
addq $0x28, %rbx
cmpq %rcx, %rdx
jb 0xa4224
movq 0x50(%rsp), %rcx
incq %rcx
movq 0x20(%rsp), %rax
cmpq %rax, %rcx
jne 0xa41e9
jmp 0xa456c
movl $0x1, %esi
xorl %edi, %edi
callq 0x2120
movq 0x8(%rsp), %rcx
movq %rax, 0x30(%rcx)
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
movq 0xb0(%rsp), %r9
callq 0x1f0a97
movq 0x8(%rsp), %rdi
movq %rdi, %rbx
callq 0xa0a7d
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
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 $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18f6d7(%rip), %rdi    # 0x233c8a
leaq 0x1918d7(%rip), %rsi    # 0x235e91
leaq 0x191b73(%rip), %rcx    # 0x236134
movl $0xbc2, %edx            # imm = 0xBC2
callq 0x2110