// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x2c(%rsp)
movq %r8, 0x30(%rsp)
movl %ecx, %r13d
movq %rdx, 0x38(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
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 0x17b748
andq $0x0, 0xd8(%r14)
movq %rbx, 0xc8(%r14)
movq 0x18(%rbx), %rdi
callq 0xa0494
movq 0xc8(%r14), %rdi
andq $0x0, 0x18(%rdi)
callq 0x1f729
movq 0x273a46(%rip), %r12    # 0x294fe0
movq (%r12), %rdi
leaq 0x21c5d3(%rip), %rsi    # 0x23db78
leaq 0x21c5de(%rip), %rdx    # 0x23db8a
xorl %eax, %eax
callq 0x22b0
testl %r13d, %r13d
je 0x21697
leaq 0x70(%r14), %rax
movq %rax, 0x40(%rsp)
leaq 0x18(%r14), %rbp
leaq 0x21c5ba(%rip), %rbx    # 0x23db8a
xorl %r15d, %r15d
movq (%r12), %rdi
leaq 0x21c5b8(%rip), %rsi    # 0x23db96
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
movq 0xc8(%r14), %rdx
movq 0xd0(%r14), %rcx
movq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x17650e
movq (%r12), %rdi
leaq 0x21c597(%rip), %rsi    # 0x23dba8
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
callq 0x1fe67
movq (%r12), %rdi
leaq 0x21c58b(%rip), %rsi    # 0x23dbbc
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
movsd 0x21bec7(%rip), %xmm0   # 0x23d510
pushq $0x13
popq %rsi
xorl %edx, %edx
callq 0x20daa
movq (%r12), %rdi
leaq 0x21c574(%rip), %rsi    # 0x23dbd2
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
callq 0x210d9
movq (%r12), %rdi
leaq 0x21c56c(%rip), %rsi    # 0x23dbea
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
incl %r15d
cmpl %r15d, %r13d
jne 0x215d3
movq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x2090
leaq 0x64(%rax), %rdi
callq 0x2280
movq %rax, %rbx
cmpb $0x1, 0x2c(%rsp)
leaq 0x21607e(%rip), %rax    # 0x23773a
leaq 0x21607c(%rip), %rcx    # 0x23773f
cmoveq %rax, %rcx
leaq 0x217944(%rip), %rsi    # 0x239012
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq 0xc8(%r14), %rdi
movq 0xd0(%r14), %rsi
movq 0x38(%rsp), %r9
movq (%r9), %rdx
movq 0x8(%r9), %r8
movq 0x30(%r9), %rax
movl 0x40(%r9), %ecx
movl 0x44(%r9), %r9d
movl %r9d, 0x20(%rsp)
movl %ecx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %rbx, %rcx
callq 0x2118a
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220