// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
addq $0x1f0, %rax            # imm = 0x1F0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rdi
shlq $0x2, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x30(%rax)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x3748c6
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x30(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x374892
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jle 0x374890
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3748b3
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3748b5
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x37481c
movq -0x38(%rbp), %rdi
movl $0x20, %esi
callq 0x2140
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x1e0(%rax), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rcx
leaq 0x10e(%rip), %rsi       # 0x374a20
callq 0x16d710
movq -0x8(%rbp), %rdi
callq 0x339940
movq -0x8(%rbp), %rdi
callq 0x33a750
movq -0x8(%rbp), %rdi
callq 0x33ee60
movq -0x8(%rbp), %rax
movq 0x1e0(%rax), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rcx
leaq 0x1ae(%rip), %rsi       # 0x374b00
callq 0x16d710
movq -0x50(%rbp), %rdi
callq 0x33f230
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x33f110
movq -0x8(%rbp), %rax
movq 0x1e0(%rax), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rcx
leaq 0x174(%rip), %rsi       # 0x374b00
callq 0x16d710
movq -0x50(%rbp), %rdi
callq 0x33f230
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x44(%rax), %rsi
callq 0x33f3d0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl %eax, %esi
callq 0xda630
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xe5910
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x70(%rax), %rsi
callq 0x372800
movq -0x8(%rbp), %rdi
callq 0x373160
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x370a90
movq -0x50(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq