// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/horder.cpp
// Function: init_horder_t(kvec_pe_hit*, unsigned long, unsigned long, asg_t*, ma_ug_t*, bubble_type*, kv_u_trans_t*, ug_opt_t*, unsigned int)
horder_t *init_horder_t(kvec_pe_hit *i_hits, uint64_t i_hits_uid_bits, uint64_t i_hits_pos_mode, 
asg_t *i_rg, ma_ug_t* i_ug, bubble_type* bub, kv_u_trans_t *ref, ug_opt_t *opt, uint32_t round)
{
    uint32_t i;
    trans_col_t *t_idx = NULL;
    horder_t *h = NULL; CALLOC(h, 1);
    get_r_hits(i_hits, &(h->r_hits), i_rg, i_ug, bub, i_hits_uid_bits, i_hits_pos_mode);
    h->r_g = copy_read_graph(i_rg);
    horder_clean_sg_by_utg(h->r_g, i_ug);
    t_idx = init_trans_col(i_ug, h->r_g->n_seq, ref);
    // output_hic_rtg(i_ug, h->r_g, opt, asm_opt.output_file_name);

    // reduce_hamming_error(h->r_g, opt->sources, opt->coverage_cut, opt->max_hang, opt->min_ovlp, opt->gap_fuzz);
    reduce_hamming_error_adv(NULL, h->r_g, opt->sources, opt->coverage_cut, opt->max_hang, opt->min_ovlp, opt->gap_fuzz, opt->ruIndex, NULL);
    /**
    scaffold_hap(h, t_idx, opt, round, asm_opt.output_file_name, FATHER);
    scaffold_hap(h, t_idx, opt, round, asm_opt.output_file_name, MOTHER);
    **/
    
    
    generate_haplotypes(h, opt);
    print_N50(h->ug);
    
    // update_u_hits(&(h->u_hits), &(h->r_hits), h->ug, h->r_g);
    // break_contig(h, 10, 20);  
    for (i = 0; i < round; i++)
    {
        update_u_hits(&(h->u_hits), &(h->r_hits), h->ug, h->r_g);
        update_scg(h, t_idx);
        layout_scg(h, 1.001, 19, NULL);
        renew_scaffold(h);
    }
    

    print_scaffold(h->ug, h->r_g, opt->coverage_cut, asm_opt.output_file_name, 
    opt->sources, opt->reverse_sources, opt->tipsLen, opt->tip_drop_ratio, 
    opt->stops_threshold, opt->ruIndex, opt->chimeric_rate, opt->drop_ratio, 
    opt->max_hang, opt->min_ovlp);
    
    destory_trans_col(&t_idx);
    exit(1);
    return h;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x38(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %rbp
movq %rdx, %rbx
movq %rsi, 0x30(%rsp)
movq %rdi, %r12
movl 0x90(%rsp), %r13d
movl $0x1, %edi
movl $0xe0, %esi
callq 0x2120
movq %rax, %r14
leaq 0x18(%rax), %r15
movq %rbx, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq 0x28(%rsp), %rbx
movq %rbx, %rcx
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x175db3
movq %rbp, %rdi
callq 0xc8dad
movq %rax, %r12
movq %rax, 0xd0(%r14)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1769f0
movl 0x14(%r12), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, %rbp
movq 0x80(%rsp), %rax
movq %rax, (%rbp)
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
movq 0x88(%rsp), %rbx
callq 0xbf373
movq %rax, 0x8(%rbp)
movq %rbp, 0x40(%rsp)
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movl 0x40(%rbx), %r8d
movl 0x44(%rbx), %r9d
movq 0x50(%rbx), %rax
movq 0x30(%rbx), %rsi
movq %rsi, 0x8(%rsp)
movq %rax, (%rsp)
movq $0x0, 0x10(%rsp)
xorl %edi, %edi
movq %r12, %rsi
callq 0x922b
movq %r14, %rdi
movq %rbx, %rsi
callq 0x17b61d
movq 0xc8(%r14), %r12
movq %r12, %rdi
callq 0x1f729
testl %r13d, %r13d
je 0x17d79f
movq %r14, %r12
addq $0x70, %r12
movq 0xc8(%r14), %rdx
movq 0xd0(%r14), %rcx
movq %r12, %rdi
movq %r15, %rsi
callq 0x17650e
movq %r14, %rdi
callq 0x1fe67
movq %r14, %rdi
movsd 0xbfd91(%rip), %xmm0    # 0x23d510
movl $0x13, %esi
xorl %edx, %edx
callq 0x20daa
movq %r14, %rdi
callq 0x210d9
decl %r13d
jne 0x17d753
movq 0xc8(%r14), %r12
movq 0xd0(%r14), %rsi
leaq 0x117fab(%rip), %rax    # 0x295758
movq 0x10(%rax), %rcx
movq (%rbx), %rdx
movq 0x8(%rbx), %r8
movq 0x30(%rbx), %rax
movl 0x40(%rbx), %edi
movl 0x44(%rbx), %r9d
movl %r9d, 0x20(%rsp)
movl %edi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x2118a
leaq 0x40(%rsp), %rdi
callq 0x17557d
movl $0x1, %edi
callq 0x2250