// File: /workspace/github_cpp_makefile_star2_O1/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 $0xe8, %rsp
movq %r8, %r10
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movq 0x148(%rsp), %rdx
movq 0x140(%rsp), %rcx
movl 0x138(%rsp), %r9d
movl 0x130(%rsp), %r8d
movq 0x128(%rsp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
xorl %eax, %eax
movq %rax, 0xe0(%rsp)
xorl %edi, %edi
movq %r12, 0x70(%rsp)
movq %r14, 0x78(%rsp)
movq %r10, 0x80(%rsp)
leaq 0x1c0c0c(%rip), %rax    # 0x28a758
movslq 0x11c(%rax), %rax
addq %rax, %rax
movq %rax, 0x88(%rsp)
movl $0x3e19999a, 0x90(%rsp) # imm = 0x3E19999A
movq $0x3, 0x98(%rsp)
movq %rsi, 0xa0(%rsp)
movabsq $0x3f6666663d4ccccd, %rax # imm = 0x3F6666663D4CCCCD
movq %rax, 0xa8(%rsp)
movl %r8d, 0xb0(%rsp)
movl %r9d, 0xb4(%rsp)
movl %edi, 0xb8(%rsp)
xorl %ebx, %ebx
movq %rdx, 0xd0(%rsp)
movq %rcx, 0xc0(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r10, 0x68(%rsp)
movq %r10, %rcx
callq 0xc9540
movq %rax, %rbp
movq %rbx, 0x58(%rsp)
movq %r15, %rdi
callq 0x2090
leaq 0x32(%rax), %rdi
callq 0x2280
movq %rax, %rbx
leaq 0x16126c(%rip), %rsi    # 0x22ae66
movq %rax, %rdi
movq %r15, 0x60(%rsp)
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1727eb(%rip), %rsi    # 0x23c3fe
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq 0x165f11(%rip), %rax    # 0x22fb3b
movq %rax, 0x8(%rsp)
xorl %eax, %eax
movl %eax, (%rsp)
leaq 0x1c15f5(%rip), %rsi    # 0x28b230
movq %rbp, %rdi
movq %r13, %rdx
movq %r12, %rcx
movq %r14, %r8
movq 0x128(%rsp), %r9
callq 0xb688e
movq %r15, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2220
leaq 0x1c0aed(%rip), %rax    # 0x28a758
testb $0x4, (%rax)
je 0xc9c7f
movq 0x60(%rsp), %rdi
callq 0xbeaa7
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0xc9d32
movq 0x148(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x138(%rsp), %r15d
movl %r15d, (%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq 0x68(%rsp), %r8
movl 0x130(%rsp), %ebx
movl %ebx, %r9d
callq 0xc9884
movq %rax, 0x58(%rsp)
leaq 0x1c0a7b(%rip), %rcx    # 0x28a758
movl 0x154(%rcx), %ecx
movq %rax, 0x28(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
movl %r15d, 0x8(%rsp)
movl %ebx, (%rsp)
leaq 0x1c152d(%rip), %rdx    # 0x28b230
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0xb7f72
leaq 0x1c0a3a(%rip), %rax    # 0x28a758
testb $0x4, (%rax)
je 0xc9d32
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0xbe947
leaq 0x58(%rsp), %rbx
movq (%rbx), %rdx
xorl %r15d, %r15d
leaq 0x70(%rsp), %rcx
movq %rbp, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x15cba4
movq %rbx, %rdi
callq 0xbe6d4
movq %rbp, %rdi
callq 0xa0004
movq %r13, %rdi
callq 0xa02fa
movq %r15, 0x10(%rsp)
movq 0x140(%rsp), %rax
movq %rax, (%rsp)
movq %rax, %rbx
xorl %edi, %edi
movq %r13, %rsi
movq %r14, %rdx
movq %r12, %rcx
movl 0x130(%rsp), %r8d
movl %r8d, %ebp
movl 0x138(%rsp), %r15d
movl %r15d, %r9d
callq 0x927f
leaq 0x1c09ac(%rip), %rax    # 0x28a758
movslq 0x11c(%rax), %rax
addq %rax, %rax
xorl %edx, %edx
movq %rdx, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x148(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movl %edx, 0x30(%rsp)
movl %ebx, 0x28(%rsp)
movl %r15d, 0x20(%rsp)
movl %ebp, 0x18(%rsp)
movq 0x128(%rsp), %r15
movq %r15, 0x10(%rsp)
movl $0x3, %ecx
movq %rcx, 0x8(%rsp)
movq %rax, (%rsp)
movss 0x15fdba(%rip), %xmm0   # 0x229bc0
movss 0x15fdb6(%rip), %xmm1   # 0x229bc4
movss 0x15fda6(%rip), %xmm2   # 0x229bbc
movq %r13, %rdi
movq %r12, %rsi
movq 0x60(%rsp), %rbx
movq %rbx, %rdx
movl $0x1, %ecx
movq %r14, %r8
movq 0x68(%rsp), %rbp
movq %rbp, %r9
callq 0xc21cc
leaq 0x1c0918(%rip), %rax    # 0x28a758
movslq 0x11c(%rax), %rax
addq %rax, %rax
xorl %ecx, %ecx
movq %rcx, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movq 0x148(%rsp), %rdx
movq %rdx, 0x38(%rsp)
movl %ecx, 0x30(%rsp)
movq 0x140(%rsp), %rcx
movl %ecx, 0x28(%rsp)
movl 0x138(%rsp), %ecx
movl %ecx, 0x20(%rsp)
movl 0x130(%rsp), %ecx
movl %ecx, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movl $0x3, %ecx
movq %rcx, 0x8(%rsp)
movq %rax, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl $0x2, %ecx
movq %r14, %r8
movq %rbp, %r9
movss 0x15fd05(%rip), %xmm0   # 0x229bc0
movss 0x15fd01(%rip), %xmm1   # 0x229bc4
movss 0x15fcf1(%rip), %xmm2   # 0x229bbc
callq 0xc21cc
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq