// File: /workspace/github_cpp_makefile_star2_O2/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 $0x108, %rsp            # imm = 0x108
movq %r8, %r10
movq %r8, 0x80(%rsp)
movq %rcx, %r14
movq %rcx, 0x70(%rsp)
movq %rdx, %r15
movq %rdx, 0x60(%rsp)
movq %rsi, %rbp
movq %rsi, 0x78(%rsp)
movq %rdi, %r13
movq 0x168(%rsp), %rdx
movq 0x160(%rsp), %rcx
movl 0x158(%rsp), %r9d
movl 0x150(%rsp), %r8d
movq 0x148(%rsp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0xb0(%rsp)
movups %xmm0, 0xc0(%rsp)
movups %xmm0, 0xd0(%rsp)
movups %xmm0, 0xf0(%rsp)
movups %xmm0, 0xe0(%rsp)
andq $0x0, 0x100(%rsp)
movq %rsi, 0x90(%rsp)
movq %r14, 0x98(%rsp)
movq %r10, 0xa0(%rsp)
leaq 0x1c49cc(%rip), %rax    # 0x253758
movslq 0x11c(%rax), %rax
addq %rax, %rax
movq %rax, 0xa8(%rsp)
movl $0x3e19999a, 0xb0(%rsp) # imm = 0x3E19999A
movq $0x3, 0xb8(%rsp)
movq %rdi, 0xc0(%rsp)
movsd 0x158e6b(%rip), %xmm0   # 0x1e7c30
movsd %xmm0, 0xc8(%rsp)
movl %r8d, 0xd0(%rsp)
movl %r9d, 0xd4(%rsp)
movq %rdx, 0xf0(%rsp)
movq %rcx, 0xe0(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdi, (%rsp)
movq %r13, %rdi
movq %r14, %rdx
movq %r10, %rcx
callq 0x8e870
movq %rax, %r12
movq %r15, %rdi
callq 0x2090
leaq 0x32(%rax), %rdi
callq 0x2280
movq %rax, %rbx
leaq 0x15a133(%rip), %rsi    # 0x1e8f56
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x16b86a(%rip), %rsi    # 0x1fa6a1
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
movq %rax, (%rsp)
leaq 0x15ee2e(%rip), %r9     # 0x1edc7b
movq %r12, 0x68(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq 0x148(%rsp), %r8
callq 0x7de8f
movq %r15, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2220
leaq 0x1c48d6(%rip), %rax    # 0x253758
testb $0x4, (%rax)
je 0x8eea5
movq 0x60(%rsp), %rdi
callq 0x84211
movq %rax, %rbx
movq %rax, 0x88(%rsp)
testq %rax, %rax
jne 0x8ef68
movq 0x168(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x148(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x158(%rsp), %eax
movl %eax, (%rsp)
movq 0x68(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq 0x78(%rsp), %rbp
movq %rbp, %rdx
movq 0x70(%rsp), %r14
movq %r14, %rcx
movq 0x80(%rsp), %r8
movl 0x150(%rsp), %r15d
movl %r15d, %r9d
callq 0x8ead1
movq %rax, %rbx
movq %rax, 0x88(%rsp)
leaq 0x1c484a(%rip), %rax    # 0x253758
movl 0x154(%rax), %eax
movq %rbx, 0x28(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rsp)
movl %eax, 0x10(%rsp)
movl 0x158(%rsp), %eax
movl %eax, 0x8(%rsp)
movl %r15d, (%rsp)
leaq 0x1c52f5(%rip), %rdx    # 0x254230
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0x7debc
leaq 0x1c4802(%rip), %rax    # 0x253758
testb $0x4, (%rax)
je 0x8ef68
movq %rbx, %rdi
movq 0x60(%rsp), %rsi
callq 0x840ba
leaq 0x90(%rsp), %rcx
movq 0x68(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x11e429
leaq 0x88(%rsp), %rdi
callq 0x83bb0
movq %r14, %rdi
callq 0x6921d
movq %r13, %rdi
callq 0x694eb
andq $0x0, 0x10(%rsp)
movq 0x160(%rsp), %rax
movq %rax, (%rsp)
movq %rax, %rbx
xorl %edi, %edi
movq %r13, %rsi
movq 0x70(%rsp), %r14
movq %r14, %rdx
movq 0x78(%rsp), %rbp
movq %rbp, %rcx
movl 0x150(%rsp), %r8d
movl %r8d, %r15d
movl 0x158(%rsp), %r9d
movl %r9d, %r12d
callq 0x8f127
leaq 0x1c4766(%rip), %rax    # 0x253758
movslq 0x11c(%rax), %rax
addq %rax, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x168(%rsp), %r9
movq %r9, 0x38(%rsp)
movl %ebx, 0x28(%rsp)
movl %r12d, 0x20(%rsp)
movl %r15d, 0x18(%rsp)
movq 0x148(%rsp), %r15
movq %r15, 0x10(%rsp)
pushq $0x3
popq %rcx
movq %rcx, 0x8(%rsp)
movq %rax, (%rsp)
andq $0x0, 0x50(%rsp)
andl $0x0, 0x30(%rsp)
pushq $0x1
popq %rcx
movss 0x158c6a(%rip), %xmm0   # 0x1e7cb8
movss 0x158c66(%rip), %xmm1   # 0x1e7cbc
movss 0x158c56(%rip), %xmm2   # 0x1e7cb4
movq %r13, %rdi
movq %rbp, %rsi
movq 0x60(%rsp), %rbx
movq %rbx, %rdx
movq %r14, %r8
movq %r9, %r15
movq 0x80(%rsp), %r12
movq %r12, %r9
callq 0x86cbc
leaq 0x1c46cf(%rip), %rax    # 0x253758
movslq 0x11c(%rax), %rax
addq %rax, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq %r15, 0x38(%rsp)
movq 0x160(%rsp), %rcx
movl %ecx, 0x28(%rsp)
movl 0x158(%rsp), %ecx
movl %ecx, 0x20(%rsp)
movl 0x150(%rsp), %ecx
movl %ecx, 0x18(%rsp)
andq $0x0, 0x50(%rsp)
movq 0x148(%rsp), %rcx
movq %rcx, 0x10(%rsp)
andl $0x0, 0x30(%rsp)
pushq $0x3
popq %rcx
movq %rcx, 0x8(%rsp)
movq %rax, (%rsp)
pushq $0x2
popq %rcx
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r14, %r8
movq %r12, %r9
movss 0x158bb8(%rip), %xmm0   # 0x1e7cb8
movss 0x158bb4(%rip), %xmm1   # 0x1e7cbc
movss 0x158ba4(%rip), %xmm2   # 0x1e7cb4
callq 0x86cbc
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq