// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x70, %rsp
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x1, %edi
movl $0xe0, %esi
callq 0x2140
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x18, %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %rax
movq %rax, (%rsp)
callq 0x234040
movq -0x30(%rbp), %rdi
callq 0x10b830
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x2354a0
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %esi
movq 0x10(%rbp), %rdx
callq 0x2330d0
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rsi
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq 0x18(%rbp), %rax
movq (%rax), %rcx
movq 0x18(%rbp), %rax
movl 0x40(%rax), %r8d
movq 0x18(%rbp), %rax
movl 0x44(%rax), %r9d
movq 0x18(%rbp), %rax
movq 0x50(%rax), %r10
movq 0x18(%rbp), %rax
movq 0x30(%rax), %rax
xorl %edi, %edi
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x10f400
movq -0x58(%rbp), %rdi
movq 0x18(%rbp), %rsi
callq 0x23f670
movq -0x58(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x232ca0
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl 0x20(%rbp), %eax
jae 0x246692
movq -0x58(%rbp), %rdi
addq $0x70, %rdi
movq -0x58(%rbp), %rsi
addq $0x18, %rsi
movq -0x58(%rbp), %rax
movq 0xc8(%rax), %rdx
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rcx
callq 0x234c00
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x241640
movq -0x58(%rbp), %rdi
movsd 0x147af0(%rip), %xmm0   # 0x38e160
movl $0x13, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x245880
movq -0x58(%rbp), %rdi
callq 0x245ba0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x246624
movq -0x58(%rbp), %rax
movq 0xc8(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rsi
movq 0x18(%rbp), %rax
movq (%rax), %rdx
leaq 0x17e142(%rip), %rax    # 0x3c47f8
movq 0x10(%rax), %rcx
movq 0x18(%rbp), %rax
movq 0x8(%rax), %r8
movq 0x18(%rbp), %rax
movq 0x10(%rax), %r9
movq 0x18(%rbp), %rax
movq 0x18(%rax), %r14
movq 0x18(%rbp), %rax
movss 0x20(%rax), %xmm0
movq 0x18(%rbp), %rax
movq 0x28(%rax), %rbx
movq 0x18(%rbp), %rax
movq 0x30(%rax), %r11
movq 0x18(%rbp), %rax
movss 0x38(%rax), %xmm1
movq 0x18(%rbp), %rax
movss 0x3c(%rax), %xmm2
movq 0x18(%rbp), %rax
movl 0x40(%rax), %r10d
movq 0x18(%rbp), %rax
movl 0x44(%rax), %eax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x245c70
leaq -0x50(%rbp), %rdi
callq 0x233130
movl $0x1, %edi
callq 0x2240
nopl (%rax,%rax)