// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x130, %rsp            # imm = 0x130
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movss %xmm0, -0x54(%rbp)
movss %xmm1, -0x58(%rbp)
movss %xmm2, -0x5c(%rbp)
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
movl $0x78, %edx
callq 0x2100
movq -0x30(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq 0x2b583e(%rip), %rax    # 0x3c47f8
movl 0x11c(%rax), %eax
shll %eax
cltq
movq %rax, -0xc0(%rbp)
movss 0x2778cd(%rip), %xmm0   # 0x3868a0
movss %xmm0, -0xb8(%rbp)
movq $0x3, -0xb0(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movss 0x2778ab(%rip), %xmm0   # 0x3868a4
movss %xmm0, -0xa0(%rbp)
movss 0x277893(%rip), %xmm0   # 0x38689c
movss %xmm0, -0x9c(%rbp)
movl 0x20(%rbp), %eax
movl %eax, -0x98(%rbp)
movl 0x28(%rbp), %eax
movl %eax, -0x94(%rbp)
movl $0x0, -0x90(%rbp)
movq 0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq 0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movl 0x20(%rbp), %r8d
movl 0x28(%rbp), %r9d
movq 0x18(%rbp), %r10
movq 0x38(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10e810
movq %rax, -0xe0(%rbp)
movq $0x0, -0xe8(%rbp)
movq -0x38(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x32, %rdi
callq 0x2270
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x278b93(%rip), %rsi    # 0x387c41
movb $0x0, %al
callq 0x2050
movq -0xf0(%rbp), %rdi
leaq 0x28a30f(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0xf8(%rbp)
movq -0xe0(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0xf8(%rbp), %rax
leaq 0x27d8b4(%rip), %r9     # 0x38c9a8
movq %rax, (%rsp)
callq 0xf1c10
movq -0xf8(%rbp), %rdi
callq 0x21a0
movq -0xf0(%rbp), %rdi
callq 0x2210
leaq 0x2b56dc(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x10f136
movq -0x38(%rbp), %rdi
callq 0xfd250
movq %rax, -0xe8(%rbp)
cmpq $0x0, -0xe8(%rbp)
jne 0x10f20a
movq -0xe0(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %r11d
movq 0x18(%rbp), %r10
movq 0x38(%rbp), %rax
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x10ebb0
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %r8
movl 0x20(%rbp), %ebx
movl 0x28(%rbp), %r11d
leaq 0x2b5652(%rip), %rax    # 0x3c47f8
movl 0x154(%rax), %r10d
movq -0xe8(%rbp), %rax
leaq 0x2b6115(%rip), %rdx    # 0x3c52d0
xorl %r9d, %r9d
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0xf1c80
leaq 0x2b560a(%rip), %rax    # 0x3c47f8
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x10f208
movq -0xe8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xfd080
jmp 0x10f20a
movq -0xe0(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0xe8(%rbp), %rdx
leaq -0xd8(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
callq 0x20d6b0
leaq -0xe8(%rbp), %rdi
callq 0xfc940
movq -0xe0(%rbp), %rdi
callq 0xcd6f0
movq -0x28(%rbp), %rdi
callq 0xcdd10
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl 0x20(%rbp), %r8d
movl 0x28(%rbp), %r9d
movq 0x30(%rbp), %r10
movq -0xa8(%rbp), %rax
xorl %edi, %edi
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x10f400
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
leaq 0x2b5554(%rip), %rax    # 0x3c47f8
movl 0x11c(%rax), %eax
shll %eax
movslq %eax, %r15
movq 0x18(%rbp), %r14
movl 0x20(%rbp), %ebx
movl 0x28(%rbp), %r11d
movq 0x30(%rbp), %rax
movl %eax, %r10d
movq 0x38(%rbp), %rax
movl $0x1, %ecx
movss 0x2775ce(%rip), %xmm0   # 0x3868a0
movss 0x2775ca(%rip), %xmm1   # 0x3868a4
movss 0x2775ba(%rip), %xmm2   # 0x38689c
xorl %r12d, %r12d
xorl %r12d, %r12d
movq %r15, (%rsp)
movq $0x3, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movl %r11d, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
callq 0x100cf0
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
leaq 0x2b54a8(%rip), %rax    # 0x3c47f8
movl 0x11c(%rax), %eax
shll %eax
movslq %eax, %r15
movq 0x18(%rbp), %r14
movl 0x20(%rbp), %ebx
movl 0x28(%rbp), %r11d
movq 0x30(%rbp), %rax
movl %eax, %r10d
movq 0x38(%rbp), %rax
movl $0x2, %ecx
movss 0x277522(%rip), %xmm0   # 0x3868a0
movss 0x27751e(%rip), %xmm1   # 0x3868a4
movss 0x27750e(%rip), %xmm2   # 0x38689c
xorl %r12d, %r12d
xorl %r12d, %r12d
movq %r15, (%rsp)
movq $0x3, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movl %r11d, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
callq 0x100cf0
addq $0x130, %rsp            # imm = 0x130
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)