// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_ul2ul(ul_resolve_t*, ug_opt_t*, ulg_opt_t*, unsigned int, unsigned long)
ul2ul_idx_t *gen_ul2ul(ul_resolve_t *uidx, ug_opt_t *uopt, ulg_opt_t *ulopt, uint32_t keep_raw_utg, uint64_t is_bridg)
{
    uint64_t k, m;
    ma_ug_t *ug = uidx->l1_ug; all_ul_t *uls = uidx->idx; 
    ul2ul_idx_t *z = &(uidx->uovl); ul_str_idx_t *str_idx = &(uidx->pstr);
    z->uln = uls->n; z->gn = ug->g->n_seq; 
    z->tot = uls->n + ug->g->n_seq; MALLOC(z->item_idx, z->tot);
    for (k = m = 0; k < z->tot; k++) {
        z->item_idx[k] = (uint32_t)-1;
        if(k < z->uln) {///is a ul read
            if(str_idx->str.a[k].cn > 1) {
                z->item_idx[k] = m; m++;
            }
        } else {//is a node in graph
            z->item_idx[k] = m; m++;
        }
    }
    CALLOC(z->a, m); z->n = z->m = m;

    kt_for(uidx->str_b.n_thread, worker_integer_postprecess, uidx, uls->n);
    gen_integer_normalize(uidx);

    chimeric_integer_deal(uidx);
    append_utg_es(uidx);


    kt_for(uidx->str_b.n_thread, worker_integert_debug_sym, uidx, z->tot);///all ul + ug
    print_integert_ovlp_stat(z);
    remove_integert_containment(uidx, keep_raw_utg);

    kt_for(uidx->str_b.n_thread, worker_integert_debug_sym, uidx, z->tot);///all ul + ug
    print_integert_ovlp_stat(z);
    // print_uls_seq(uidx, asm_opt.output_file_name);
    // print_uls_ovs(uidx, asm_opt.output_file_name);
    
    z->i_g = integer_sg_gen(uidx, uopt->min_ovlp);
    asg_arc_del_trans(z->i_g, uopt->gap_fuzz);

    z->i_ug = ma_ug_gen(z->i_g);
    // CALLOC(z->i_ug->g->seq_vis, z->i_ug->g->n_seq*2);
    renew_u2g_cov(uidx, uidx->uopt->te); 
    renew_u2g_bg(uidx);
    
    // output_integer_graph(uidx, z->i_ug, asm_opt.output_file_name);
    u2g_clean(uidx, ulopt, keep_raw_utg, is_bridg);
    // renew_ul2_utg(uidx);

    // output_integer_graph(uidx, z->i_ug, asm_opt.output_file_name, 0);
    return z;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, 0x10(%rsp)
movl %ecx, %ebp
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, %r15
movq 0x18(%rdi), %rax
movq 0x30(%rdi), %rcx
movq 0x50(%rcx), %rbx
movq %rbx, 0x208(%rdi)
movq 0x18(%rax), %rax
movl 0x14(%rax), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andq %rdx, %rcx
movq %rcx, 0x210(%rdi)
movl 0x14(%rax), %r13d
andq %rdx, %r13
addq %rbx, %r13
movq %r13, 0x218(%rdi)
leaq (,%r13,4), %rdi
callq 0x2280
movq %rax, 0x220(%r15)
testq %r13, %r13
jne 0x2c365
xorl %r14d, %r14d
jmp 0x2c399
pushq $0x18
popq %rcx
xorl %edx, %edx
xorl %r14d, %r14d
orl $-0x1, (%rax,%rdx,4)
cmpq %rbx, %rdx
jae 0x2c386
movq 0x1d0(%r15), %rsi
testl $0x7ffffffe, (%rsi,%rcx) # imm = 0x7FFFFFFE
je 0x2c38d
movl %r14d, (%rax,%rdx,4)
incq %r14
incq %rdx
addq $0x20, %rcx
cmpq %rdx, %r13
jne 0x2c36d
leaq 0x1f0(%r15), %r13
pushq $0x20
popq %rsi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x1f0(%r15)
movq %r14, 0x200(%r15)
movq %r14, 0x1f8(%r15)
movl 0x1e0(%r15), %edi
leaq 0x1fdaa3(%rip), %rsi    # 0x229e71
movq %r15, %rdx
movq %rbx, %rcx
callq 0x108f2c
movq %r15, %rdi
callq 0x207b05
movq %r15, %rdi
callq 0x208213
movq %r15, %rdi
callq 0x20a1c4
movl 0x1e0(%r15), %edi
movq 0x218(%r15), %rcx
leaq 0x1fdae8(%rip), %rbx    # 0x229eee
movq %rbx, %rsi
movq %r15, %rdx
callq 0x108f2c
movq %r13, %rdi
callq 0x2b5da
movq %r15, %rdi
movl %ebp, %esi
callq 0x20a380
movl 0x1e0(%r15), %edi
movq 0x218(%r15), %rcx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x108f2c
movq %r13, %rdi
callq 0x2b5da
movslq 0x44(%r12), %rsi
movq %r15, %rdi
callq 0x20a43b
movq %rax, 0x228(%r15)
movl 0x50(%r12), %esi
movq %rax, %rdi
callq 0xa9d09
movq 0x228(%r15), %rdi
callq 0xb10cd
movq %rax, 0x230(%r15)
movq (%r15), %rax
movq 0x70(%rax), %rsi
movq %r15, %rdi
callq 0x228c08
movq %r15, %rdi
callq 0x229159
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
movq 0x10(%rsp), %rcx
callq 0x227b51
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq