// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x80, %rsp
movb %r9b, %al
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movq %r8, -0x38(%rbp)
movb %al, -0x39(%rbp)
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq 0xb0(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rdi
addq $0x70, %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x2100
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0xd8(%rax), %rdi
callq 0x23f890
movq -0x18(%rbp), %rax
movq $0x0, 0xd8(%rax)
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0xcd6f0
movq -0x18(%rbp), %rax
movq $0x0, 0xc8(%rax)
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rdi
movb -0x39(%rbp), %al
movq -0x20(%rbp), %rdx
movzbl %al, %esi
callq 0x235380
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rax
movq 0x18(%rax), %rdi
callq 0xcd170
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x232ca0
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x245fcd
movq -0x18(%rbp), %rdi
addq $0x70, %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rcx
callq 0x234c00
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x241640
movq -0x18(%rbp), %rdi
movsd 0x1481b5(%rip), %xmm0   # 0x38e160
movl $0x13, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x245880
movq -0x18(%rbp), %rdi
callq 0x245ba0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x245f5f
movq -0x38(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x64, %rdi
callq 0x2270
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x1, %eax
jne 0x24600c
leaq 0x14231f(%rip), %rax    # 0x388325
movq %rax, -0x60(%rbp)
jmp 0x246019
leaq 0x142317(%rip), %rax    # 0x38832a
movq %rax, -0x60(%rbp)
jmp 0x246019
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rcx
leaq 0x143c11(%rip), %rsi    # 0x389c3d
movb $0x0, %al
callq 0x2050
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
movq -0x48(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x20(%rbp), %rax
movq 0x10(%rax), %r9
movq -0x20(%rbp), %rax
movq 0x18(%rax), %r14
movq -0x20(%rbp), %rax
movss 0x20(%rax), %xmm0
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rbx
movq -0x20(%rbp), %rax
movq 0x30(%rax), %r11
movq -0x20(%rbp), %rax
movss 0x38(%rax), %xmm1
movq -0x20(%rbp), %rax
movss 0x3c(%rax), %xmm2
movq -0x20(%rbp), %rax
movl 0x40(%rax), %r10d
movq -0x20(%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
movq -0x48(%rbp), %rdi
callq 0x2210
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw (%rax,%rax)