// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: output_hic_graph_polyploid(asg_t*, ma_sub_t*, char*, ma_hit_t_alloc*, ma_hit_t_alloc*, long long, float, long long, R_to_U*, float, float, int, int, long long, bub_label_t*)
void output_hic_graph_polyploid(asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name, 
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, 
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, 
long long gap_fuzz, bub_label_t* b_mask_t)
{ 
    ug_opt_t opt; memset(&opt, 0, sizeof(opt));
    opt.coverage_cut = coverage_cut;
    opt.sources = sources;
    opt.reverse_sources = reverse_sources; 
    opt.tipsLen = (asm_opt.max_short_tip*2);
    opt.tip_drop_ratio = 0.15;
    opt.stops_threshold = 3;
    opt.ruIndex = ruIndex; 
    opt.chimeric_rate = 0.05;
    opt.drop_ratio = 0.9;
    opt.max_hang = max_hang;
    opt.min_ovlp = min_ovlp;
    opt.is_bench = 0;
    opt.b_mask_t = b_mask_t;
    opt.gap_fuzz = gap_fuzz;

    
    ma_ug_t *ug = get_poly_ug(sg, coverage_cut, sources, reverse_sources, max_hang, min_ovlp, ruIndex, b_mask_t);    
    trans_chain* t_ch = NULL;

    char* gfa_name = (char*)malloc(strlen(output_file_name)+50);
    sprintf(gfa_name, "%s.pre.clean_d_utg.noseq.gfa", output_file_name);
    FILE* output_file = fopen(gfa_name, "w");
    ma_ug_print_simple(ug, sg, coverage_cut, sources, ruIndex, "utg", output_file);
    fclose(output_file);
    free(gfa_name);

    if((asm_opt.flag & HA_F_VERBOSE_GFA)) t_ch = load_hc_trans(output_file_name);
    if(!t_ch)
    {
        t_ch = get_hic_polyploid_trans_chain(ug, sg, coverage_cut, sources, reverse_sources, max_hang, min_ovlp, ruIndex, b_mask_t);
        ma_ug_print_bed(ug, sg, &R_INF, coverage_cut, sources, NULL, 
                max_hang, min_ovlp, asm_opt.hic_inconsist_rate, NULL, NULL, t_ch);
        if((asm_opt.flag & HA_F_VERBOSE_GFA)) write_trans_chain(t_ch, output_file_name);
    } 

    hic_analysis(ug, sg, t_ch, &opt, NULL, NULL);
    destory_trans_chain(&t_ch); 
    ma_ug_destroy(ug);
    asg_cleanup(sg);

    // reduce_hamming_error(sg, sources, coverage_cut, max_hang, min_ovlp, gap_fuzz);
    reduce_hamming_error_adv(NULL, sg, sources, coverage_cut, max_hang, min_ovlp, gap_fuzz, opt.ruIndex, NULL);

    output_trio_unitig_graph(sg, coverage_cut, output_file_name, FATHER, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, ruIndex, 
    0.05, 0.9, max_hang, min_ovlp, gap_fuzz, 0, b_mask_t, NULL, NULL, NULL);
    output_trio_unitig_graph(sg, coverage_cut, output_file_name, MOTHER, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, ruIndex, 
    0.05, 0.9, max_hang, min_ovlp, gap_fuzz, 0, b_mask_t, NULL, NULL, NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, %r10
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r13
movq 0x158(%rsp), %rdx
movq 0x150(%rsp), %rcx
movl 0x148(%rsp), %r9d
movl 0x140(%rsp), %r8d
movq 0x138(%rsp), %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rsp)
movups %xmm0, 0xb0(%rsp)
movups %xmm0, 0xc0(%rsp)
movups %xmm0, 0xe0(%rsp)
movups %xmm0, 0xd0(%rsp)
movq $0x0, 0xf0(%rsp)
movq %r14, 0x80(%rsp)
movq %r12, 0x88(%rsp)
movq %r10, 0x90(%rsp)
leaq 0x1ca949(%rip), %rax    # 0x295758
movslq 0x11c(%rax), %rax
addq %rax, %rax
movq %rax, 0x98(%rsp)
movl $0x3e19999a, 0xa0(%rsp) # imm = 0x3E19999A
movq $0x3, 0xa8(%rsp)
movq %rsi, 0xb0(%rsp)
movsd 0x16aee8(%rip), %xmm0   # 0x235d30
movsd %xmm0, 0xb8(%rsp)
movl %r8d, 0xc0(%rsp)
movl %r9d, 0xc4(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rcx, 0xd0(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, (%rsp)
movq %r14, %rsi
movq %r12, %rdx
movq %r10, 0x70(%rsp)
movq %r10, %rcx
callq 0xca80e
movq %rax, %rbp
movq %r15, %rdi
callq 0x2090
leaq 0x32(%rax), %rdi
callq 0x2280
movq %rax, %rbx
leaq 0x16c1ab(%rip), %rsi    # 0x237056
movq %rax, %rdi
movq %r15, 0x58(%rsp)
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x17d81e(%rip), %rsi    # 0x2486e2
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq 0x170eb0(%rip), %rax    # 0x23bd8b
movq %rax, 0x8(%rsp)
movl $0x0, (%rsp)
leaq 0x1cb342(%rip), %rsi    # 0x296230
movq %rbp, %rdi
movq %r13, %rdx
movq %r14, 0x60(%rsp)
movq %r14, %rcx
movq %r12, 0x68(%rsp)
movq %r12, %r8
movq 0x138(%rsp), %r9
callq 0xb7823
movq %r15, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2220
leaq 0x1ca830(%rip), %rax    # 0x295758
testb $0x4, (%rax)
je 0xcaf48
movq 0x58(%rsp), %rdi
callq 0xbf9e8
movq %rax, %rbx
movq %rax, 0x78(%rsp)
testq %rax, %rax
jne 0xcb000
movq 0x158(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x148(%rsp), %eax
movl %eax, (%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq 0x60(%rsp), %r14
movq %r14, %rdx
movq 0x68(%rsp), %r15
movq %r15, %rcx
movq 0x70(%rsp), %r8
movl 0x140(%rsp), %r12d
movl %r12d, %r9d
callq 0xcab56
movq %rax, %rbx
movq %rax, 0x78(%rsp)
leaq 0x1ca7b2(%rip), %rax    # 0x295758
movl 0x154(%rax), %eax
movq %rbx, 0x28(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rsp)
movl %eax, 0x10(%rsp)
movl 0x148(%rsp), %eax
movl %eax, 0x8(%rsp)
movl %r12d, (%rsp)
leaq 0x1cb25d(%rip), %rdx    # 0x296230
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rcx
movq %r15, %r8
xorl %r9d, %r9d
callq 0xb8f0d
leaq 0x1ca76a(%rip), %rax    # 0x295758
testb $0x4, (%rax)
je 0xcb000
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
callq 0xbf888
xorl %r14d, %r14d
leaq 0x80(%rsp), %rcx
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x16364b
leaq 0x78(%rsp), %rdi
callq 0xbf611
movq %rbp, %rdi
callq 0xa0761
movq %r13, %rdi
callq 0xa0a7d
movq %r14, 0x10(%rsp)
movq 0x150(%rsp), %rax
movq %rax, (%rsp)
movq %rax, %rbx
xorl %edi, %edi
movq %r13, %rsi
movq 0x68(%rsp), %r12
movq %r12, %rdx
movq 0x60(%rsp), %r14
movq %r14, %rcx
movl 0x140(%rsp), %r8d
movl %r8d, %ebp
movl 0x148(%rsp), %r15d
movl %r15d, %r9d
callq 0x922b
leaq 0x1ca6d4(%rip), %rax    # 0x295758
movslq 0x11c(%rax), %rax
addq %rax, %rax
xorl %edx, %edx
movq %rdx, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x158(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movl %edx, 0x30(%rsp)
movl %ebx, 0x28(%rsp)
movl %r15d, 0x20(%rsp)
movl %ebp, 0x18(%rsp)
movq 0x138(%rsp), %r15
movq %r15, 0x10(%rsp)
movl $0x3, %ecx
movq %rcx, 0x8(%rsp)
movq %rax, (%rsp)
movss 0x16acda(%rip), %xmm0   # 0x235db8
movss 0x16acd6(%rip), %xmm1   # 0x235dbc
movss 0x16acc6(%rip), %xmm2   # 0x235db4
movq %r13, %rdi
movq %r14, %rsi
movq 0x58(%rsp), %rbx
movq %rbx, %rdx
movl $0x1, %ecx
movq %r12, %r8
movq 0x70(%rsp), %rbp
movq %rbp, %r9
callq 0xc30dd
leaq 0x1ca640(%rip), %rax    # 0x295758
movslq 0x11c(%rax), %rax
addq %rax, %rax
xorl %ecx, %ecx
movq %rcx, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x158(%rsp), %rdx
movq %rdx, 0x38(%rsp)
movl %ecx, 0x30(%rsp)
movq 0x150(%rsp), %rcx
movl %ecx, 0x28(%rsp)
movl 0x148(%rsp), %ecx
movl %ecx, 0x20(%rsp)
movl 0x140(%rsp), %ecx
movl %ecx, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movl $0x3, %ecx
movq %rcx, 0x8(%rsp)
movq %rax, (%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x2, %ecx
movq %r12, %r8
movq %rbp, %r9
movss 0x16ac25(%rip), %xmm0   # 0x235db8
movss 0x16ac21(%rip), %xmm1   # 0x235dbc
movss 0x16ac11(%rip), %xmm2   # 0x235db4
callq 0xc30dd
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq