// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movq %rcx, %r13
movq %rdx, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %rbp
movl 0x90(%rsp), %ebx
pushq $0x1
popq %rdi
movl $0xe0, %esi
callq 0x2120
movq %rax, %r14
leaq 0x18(%rax), %r15
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x13229e
movq %r13, %rdi
movq 0x88(%rsp), %r13
callq 0x8c8a9
movq %rax, %rbp
movq %rax, 0xd0(%r14)
movq %rax, %rdi
movq %r12, %rsi
callq 0x132def
movl 0x14(%rbp), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %r12, %rdi
movq 0x80(%rsp), %rdx
callq 0x131a7c
movq %rax, 0x40(%rsp)
movq (%r13), %rcx
movq 0x8(%r13), %rdx
movl 0x40(%r13), %r8d
movl 0x44(%r13), %r9d
movq 0x50(%r13), %rax
movq 0x30(%r13), %rsi
andq $0x0, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rax, (%rsp)
xorl %edi, %edi
movq %rbp, %rsi
callq 0x8f127
movq %r14, %rdi
movq %r13, %rsi
callq 0x13771a
movq 0xc8(%r14), %rdi
callq 0x131810
movq %r14, %r12
addq $0x70, %r12
pushq $0x13
popq %rbp
movq 0xc8(%r14), %rdx
movq 0xd0(%r14), %rcx
subl $0x1, %ebx
jb 0x13abb4
movq %r12, %rdi
movq %r15, %rsi
callq 0x13292a
movq %r14, %rdi
callq 0x138496
movq %r14, %rdi
movsd 0xb482f(%rip), %xmm0    # 0x1ef3d0
movl %ebp, %esi
xorl %edx, %edx
callq 0x13a185
movq %r14, %rdi
callq 0x13a399
jmp 0x13ab70
leaq 0x118b9d(%rip), %rax    # 0x253758
movq 0x10(%rax), %rax
movq (%r13), %r9
movq 0x8(%r13), %r8
movq 0x30(%r13), %rsi
movl 0x40(%r13), %edi
movl 0x44(%r13), %r10d
movl %r10d, 0x20(%rsp)
movl %edi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, %rdi
movq %rcx, %rsi
movq %r9, %rdx
movq %rax, %rcx
callq 0x13a44a
leaq 0x40(%rsp), %rdi
callq 0x131abd
pushq $0x1
popq %rdi
callq 0x2250