// File: /workspace/github_cpp_makefile_star2_O1/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, 0x40(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, 0x38(%rsp)
movq %rdi, %rbx
movl 0x90(%rsp), %r13d
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movl $0x1, %edi
movl $0xe0, %esi
callq 0x2120
movq %rax, %r14
leaq 0x18(%rax), %r15
movq %rbp, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq 0x28(%rsp), %rbx
movq %rbx, %rcx
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x16f282
movq %r12, %rdi
callq 0xc802c
movq %rax, %r12
movq %rax, 0xd0(%r14)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x16fe2e
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 0xbe3b4
movq %rax, 0x8(%rbp)
movq %rbp, 0x30(%rsp)
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movl 0x40(%rbx), %r8d
movl 0x44(%rbx), %r9d
movq 0x50(%rbx), %rax
movq 0x30(%rbx), %rsi
xorl %edi, %edi
movq %rdi, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rax, (%rsp)
xorl %edi, %edi
movq %r12, %rsi
callq 0x927f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x174ad2
movq 0xc8(%r14), %rdi
callq 0x20357
testl %r13d, %r13d
je 0x176c17
movq %r14, %r12
addq $0x70, %r12
movq 0xc8(%r14), %rdx
movq 0xd0(%r14), %rcx
movq %r12, %rdi
movq %r15, %rsi
callq 0x16f95a
movq %r14, %rdi
callq 0x20a44
movq %r14, %rdi
movsd 0xba6c2(%rip), %xmm0    # 0x2312c0
movl $0x13, %esi
xorl %edx, %edx
callq 0x219c2
movq %r14, %rdi
callq 0x21cc4
decl %r13d
jne 0x176bd2
movq 0xc8(%r14), %rdi
movq 0xd0(%r14), %rsi
leaq 0x113b2c(%rip), %rax    # 0x28a758
movq 0x10(%rax), %rcx
movq (%rbx), %rdx
movq 0x8(%rbx), %r8
movq 0x30(%rbx), %rax
movl 0x40(%rbx), %r9d
movl 0x44(%rbx), %r10d
movl %r10d, 0x20(%rsp)
movl %r9d, 0x18(%rsp)
movq %rax, 0x10(%rsp)
callq 0x21d75
leaq 0x30(%rsp), %rdi
callq 0x16ea6f
movl $0x1, %edi
callq 0x2250