// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_deep_ref_trans(kv_u_trans_t*, scaf_res_t*, scaf_res_t*, asg_t*, ma_ug_t*, ma_sub_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, long long, float, long long, R_to_U*, float, float, int, int, bub_label_t*, ug_opt_t*)
kv_u_trans_t *gen_deep_ref_trans(kv_u_trans_t *in, scaf_res_t *cp0, scaf_res_t *cp1, asg_t *sg, ma_ug_t *ref, ma_sub_t* cover, ma_hit_t_alloc* src, ma_hit_t_alloc* rev,
long long tipsLen, float tip_drop_ratio, long long stops_threshold, R_to_U* ruIndex, float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp, bub_label_t* b_mask_t, ug_opt_t *opt)
{
    kvec_asg_arc_t_warp ne; kv_init(ne.a); kv_u_trans_t *p = NULL; CALLOC(p, 1);
    ma_ug_t *cref = gen_clean_ug(ref, cp0, cp1); ma_ug_t *ccref = copy_untig_graph(cref);
    asg_t *csg = copy_read_graph(sg); hap_cov_t *cov = NULL; ne.a.n = 0; 
    // print_debug_gfa(sg, cref, cover, "cl.sb.utg", src, ruIndex, opt->max_hang, opt->min_ovlp, 0, 0, 0);
    
    adjust_utg_by_primary(&cref, csg, TRIO_THRES, src, rev, cover, tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate, drop_ratio, max_hang, min_ovlp, &ne, &cov, b_mask_t, 1, 0);

    ma_ug_destroy(cref); asg_destroy(csg); kv_destroy(ne.a);
    if(in) {
        kv_resize(u_trans_t, cov->t_ch->k_trans, cov->t_ch->k_trans.n + in->n);
        memcpy(cov->t_ch->k_trans.a + cov->t_ch->k_trans.n, in->a, (in->n*sizeof((*(in->a)))));
        cov->t_ch->k_trans.n += in->n;
        clean_u_trans_t_idx_filter_adv(&(cov->t_ch->k_trans), ref, sg, 0.6, 1);///select best overlap for each pair of contigs
    }

    filter_u_trans(&(cov->t_ch->k_trans), asm_opt.is_bub_trans, asm_opt.is_topo_trans, asm_opt.is_read_trans, asm_opt.is_base_trans);
    if(asm_opt.is_base_trans) {
        ma_ug_seq(ccref, sg, cover, src, NULL, max_hang, min_ovlp, NULL, 0);///polish
        trans_base_infer(ccref, sg, opt, &(cov->t_ch->k_trans), NULL);
        ma_ug_destroy(ccref);
    } 
    clean_u_trans_t_idx_filter_adv(&(cov->t_ch->k_trans), ref, sg, 0.6, 0);

    p->n = cov->t_ch->k_trans.n; p->m = cov->t_ch->k_trans.m; p->a = cov->t_ch->k_trans.a; 
    p->idx.n = cov->t_ch->k_trans.idx.n; p->idx.m = cov->t_ch->k_trans.idx.m; p->idx.a = cov->t_ch->k_trans.idx.a;  
    cov->t_ch->k_trans.n = cov->t_ch->k_trans.m = 0; cov->t_ch->k_trans.a = NULL;
    cov->t_ch->k_trans.idx.n = cov->t_ch->k_trans.idx.m = 0; cov->t_ch->k_trans.idx.a = NULL;
    destory_hap_cov_t(&cov);
    return p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movss %xmm0, -0x5c(%rbp)
movss %xmm1, -0x60(%rbp)
movss %xmm2, -0x64(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x90(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2140
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x126df0
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x10ba70
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x10b830
movq %rax, -0xa8(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0x88(%rbp)
movq -0xa8(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq -0x58(%rbp), %r8
movq 0x20(%rbp), %r9
movss -0x5c(%rbp), %xmm1
movq 0x28(%rbp), %r12
movq 0x30(%rbp), %r15
movss -0x60(%rbp), %xmm2
movss -0x64(%rbp), %xmm3
movl 0x38(%rbp), %r14d
movl 0x40(%rbp), %ebx
movq 0x48(%rbp), %rax
leaq -0x98(%rbp), %rdi
movss 0x2572fa(%rip), %xmm0   # 0x38689c
leaq -0x88(%rbp), %r11
leaq -0xb0(%rbp), %r10
xorl %r13d, %r13d
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movl %r14d, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movq %r11, 0x20(%rsp)
movq %r10, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl $0x1, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
callq 0x10bde0
movq -0x98(%rbp), %rdi
callq 0xcd6f0
movq -0xa8(%rbp), %rdi
callq 0xcd170
movq -0x78(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x30(%rbp)
je 0x12f8a9
jmp 0x12f617
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rax
movq -0xb0(%rbp), %rcx
movq 0xa8(%rcx), %rcx
movq 0x138(%rcx), %rcx
movq -0x30(%rbp), %rdx
addq (%rdx), %rcx
cmpq %rcx, %rax
jae 0x12f812
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x138(%rax), %rcx
movq -0x30(%rbp), %rax
addq (%rax), %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
shrq %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
orq 0x140(%rax), %rcx
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
shrq $0x2, %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
orq 0x140(%rax), %rcx
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
shrq $0x4, %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
orq 0x140(%rax), %rcx
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
shrq $0x8, %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
orq 0x140(%rax), %rcx
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
shrq $0x10, %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
orq 0x140(%rax), %rcx
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x148(%rax), %rdi
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
imulq $0x30, 0x140(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rcx, 0x148(%rax)
jmp 0x12f814
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x148(%rax), %rdi
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
imulq $0x30, 0x138(%rax), %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
imulq $0x30, (%rax), %rdx
callq 0x2180
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
addq 0x138(%rax), %rcx
movq %rcx, 0x138(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movsd 0x252971(%rip), %xmm0   # 0x382210
movl $0x1, %ecx
callq 0x1054c0
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rdi
addq $0x138, %rdi            # imm = 0x138
leaq 0x294f33(%rip), %rax    # 0x3c47f8
movb 0x24d(%rax), %sil
leaq 0x294f25(%rip), %rax    # 0x3c47f8
movb 0x24c(%rax), %dl
leaq 0x294f18(%rip), %rax    # 0x3c47f8
movb 0x24b(%rax), %cl
leaq 0x294f0b(%rip), %rax    # 0x3c47f8
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl 0x24a(%rax), %r8d
callq 0x101a10
leaq 0x294eed(%rip), %rax    # 0x3c47f8
cmpb $0x0, 0x24a(%rax)
je 0x12f987
movq -0xa0(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x10(%rbp), %rcx
movl 0x38(%rbp), %r9d
movl 0x40(%rbp), %eax
xorl %r8d, %r8d
xorl %r10d, %r10d
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0xed140
movq -0xa0(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq 0x50(%rbp), %rdx
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rcx
addq $0x138, %rcx            # imm = 0x138
xorl %eax, %eax
movl %eax, %r8d
callq 0x307700
movq -0xa0(%rbp), %rdi
callq 0xcd6f0
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movsd 0x252864(%rip), %xmm0   # 0x382210
xorl %eax, %eax
movl %eax, %ecx
callq 0x1054c0
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x138(%rax), %rcx
movq -0x90(%rbp), %rax
movq %rcx, (%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x140(%rax), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x148(%rax), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x150(%rax), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x158(%rax), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x160(%rax), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq $0x0, 0x140(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq $0x0, 0x138(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq $0x0, 0x148(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq $0x0, 0x158(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq $0x0, 0x150(%rax)
movq -0xb0(%rbp), %rax
movq 0xa8(%rax), %rax
movq $0x0, 0x160(%rax)
leaq -0xb0(%rbp), %rdi
callq 0x10c960
movq -0x90(%rbp), %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop