// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/horder.cpp
// Function: scaffold_hap(horder_t*, ug_opt_t*, trans_col_t*, unsigned int, char*, unsigned char)
void scaffold_hap(horder_t *h, ug_opt_t *opt, trans_col_t *t_idx, uint32_t round, char *output_file_name, uint8_t flag)
{
    uint32_t i;
    kv_destroy(h->u_hits.a);
    kv_destroy(h->u_hits.idx);
    kv_destroy(h->u_hits.occ);
    memset(&(h->u_hits), 0, sizeof(h->u_hits));
    kv_destroy(h->avoid);
    h->avoid.m = h->avoid.n = 0;
    h->avoid.a = NULL;
    osg_destroy(h->sg.g);
    h->sg.g = NULL;
    ma_ug_destroy(h->ug);
    h->ug = NULL;

    h->ug = get_trio_unitig_graph(h->r_g, flag, opt);
    asg_destroy(h->ug->g);
    h->ug->g = NULL;
    // kv_push(uint64_t, h->occ, h->ug->u.n);
    // CALLOC(h->hf.a, h->ug->u.n); h->hf.n = h->hf.m = h->ug->u.n;

    print_N50(h->ug);

    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);
    }
    
    char* gfa_name = (char*)malloc(strlen(output_file_name)+100);
    sprintf(gfa_name, "%s.%s", output_file_name, (flag==FATHER?"hap1":"hap2"));

    print_scaffold(h->ug, h->r_g, opt->coverage_cut, gfa_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);

    free(gfa_name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %ebp
movq %r8, 0x30(%rsp)
movl %ecx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x70(%rdi), %r13
movq 0x80(%rdi), %rdi
callq 0x2220
movq 0x98(%r14), %rdi
callq 0x2220
movq 0xb0(%r14), %rdi
callq 0x2220
xorps %xmm0, %xmm0
movups %xmm0, 0xb0(%r14)
movups %xmm0, 0xa0(%r14)
movups %xmm0, 0x90(%r14)
movups %xmm0, 0x80(%r14)
movups %xmm0, 0x70(%r14)
andq $0x0, 0xc0(%r14)
movq 0x10(%r14), %rdi
callq 0x2220
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq 0xd8(%r14), %rdi
callq 0x13782f
andq $0x0, 0xd8(%r14)
movq 0xc8(%r14), %rdi
callq 0x6921d
andq $0x0, 0xc8(%r14)
movq 0xd0(%r14), %rdi
movl %ebp, 0x2c(%rsp)
movl %ebp, %esi
movq %rbx, %rdx
callq 0x132d50
movq %rax, 0xc8(%r14)
movq 0x18(%rax), %rdi
callq 0x68f68
movq 0xc8(%r14), %rdi
andq $0x0, 0x18(%rdi)
callq 0x131810
leaq 0x18(%r14), %r15
pushq $0x13
popq %rbp
subl $0x1, %r12d
jb 0x13a6fd
movq 0xc8(%r14), %rdx
movq 0xd0(%r14), %rcx
movq %r13, %rdi
movq %r15, %rsi
callq 0x13292a
movq %r14, %rdi
callq 0x138496
movq %r14, %rdi
movsd 0xb4ce6(%rip), %xmm0    # 0x1ef3d0
movl %ebp, %esi
xorl %edx, %edx
callq 0x13a185
movq %r14, %rdi
callq 0x13a399
jmp 0x13a6b8
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x2090
leaq 0x64(%rax), %rdi
callq 0x2280
movq %rax, %r15
cmpb $0x1, 0x2c(%rsp)
leaq 0xaef18(%rip), %rax     # 0x1e963a
leaq 0xaef16(%rip), %rcx     # 0x1e963f
cmoveq %rax, %rcx
leaq 0xb07de(%rip), %rsi     # 0x1eaf12
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2050
movq 0xc8(%r14), %rdi
movq 0xd0(%r14), %rsi
movq (%rbx), %rdx
movq 0x8(%rbx), %r8
movq 0x30(%rbx), %rax
movl 0x40(%rbx), %ecx
movl 0x44(%rbx), %r9d
movl %r9d, 0x20(%rsp)
movl %ecx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %r15, %rcx
callq 0x13a44a
movq %r15, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220