// File: chhylp123[P]hifiasm/horder.cpp
// Function: scaffold_ug(horder_t*, ma_ug_t*, ug_opt_t*, unsigned int, char*, unsigned char)
void scaffold_ug(horder_t *h, ma_ug_t *ug, ug_opt_t *opt, 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;

    h->ug = ug;
    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);
    fprintf(stderr, "[M::%s::]***0***\n", __func__);
    for (i = 0; i < round; i++)
    {
        fprintf(stderr, "[M::%s::]*i->%u*\n", __func__, i);
        update_u_hits(&(h->u_hits), &(h->r_hits), h->ug, h->r_g);
        fprintf(stderr, "[M::%s::]**i->%u**\n", __func__, i);
        update_scg(h, NULL);
        fprintf(stderr, "[M::%s::]***i->%u***\n", __func__, i);
        layout_scg(h, 1.001, 19, NULL);
        fprintf(stderr, "[M::%s::]****i->%u****\n", __func__, i);
        renew_scaffold(h);
        fprintf(stderr, "[M::%s::]*****i->%u*****\n", __func__, i);
    }
    
    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 -0x20(%rbp), %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
movq 0x17ddf9(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1485d7(%rip), %rsi    # 0x38e7c8
leaq 0x1485e2(%rip), %rdx    # 0x38e7da
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x246325
movq 0x17ddc7(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x40(%rbp), %ecx
leaq 0x1485c0(%rip), %rsi    # 0x38e7e6
leaq 0x1485ad(%rip), %rdx    # 0x38e7da
movb $0x0, %al
callq 0x22a0
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 0x17dd7a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x40(%rbp), %ecx
leaq 0x148585(%rip), %rsi    # 0x38e7f8
leaq 0x148560(%rip), %rdx    # 0x38e7da
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x241640
movq 0x17dd4b(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x40(%rbp), %ecx
leaq 0x14856a(%rip), %rsi    # 0x38e80c
leaq 0x148531(%rip), %rdx    # 0x38e7da
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rdi
movsd 0x147ea4(%rip), %xmm0   # 0x38e160
movl $0x13, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x245880
movq 0x17dd0f(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x40(%rbp), %ecx
leaq 0x148544(%rip), %rsi    # 0x38e822
leaq 0x1484f5(%rip), %rdx    # 0x38e7da
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rdi
callq 0x245ba0
movq 0x17dce4(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x40(%rbp), %ecx
leaq 0x148531(%rip), %rsi    # 0x38e83a
leaq 0x1484ca(%rip), %rdx    # 0x38e7da
movb $0x0, %al
callq 0x22a0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x246206
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 0x246364
leaq 0x141fc7(%rip), %rax    # 0x388325
movq %rax, -0x60(%rbp)
jmp 0x246371
leaq 0x141fbf(%rip), %rax    # 0x38832a
movq %rax, -0x60(%rbp)
jmp 0x246371
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rcx
leaq 0x1438b9(%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 -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x28(%rbp), %rax
movq 0x10(%rax), %r9
movq -0x28(%rbp), %rax
movq 0x18(%rax), %r14
movq -0x28(%rbp), %rax
movss 0x20(%rax), %xmm0
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rbx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %r11
movq -0x28(%rbp), %rax
movss 0x38(%rax), %xmm1
movq -0x28(%rbp), %rax
movss 0x3c(%rax), %xmm2
movq -0x28(%rbp), %rax
movl 0x40(%rax), %r10d
movq -0x28(%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
nop