// File: /workspace/github_cpp_makefile_star2_O1/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 0x174c02
andq $0x0, 0xd8(%r14)
movq %rbx, 0xc8(%r14)
movq 0x18(%rbx), %rdi
callq 0x9fcdb
movq 0xc8(%r14), %rdi
andq $0x0, 0x18(%rdi)
callq 0x20357
movq 0x267e5b(%rip), %r12    # 0x289fe0
movq (%r12), %rdi
leaq 0x20f798(%rip), %rsi    # 0x231928
leaq 0x20f7a3(%rip), %rdx    # 0x23193a
xorl %eax, %eax
callq 0x22b0
testl %r13d, %r13d
je 0x22282
leaq 0x70(%r14), %rax
movq %rax, 0x40(%rsp)
leaq 0x18(%r14), %rbp
leaq 0x20f77f(%rip), %rbx    # 0x23193a
xorl %r15d, %r15d
movq (%r12), %rdi
leaq 0x20f77d(%rip), %rsi    # 0x231946
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 0x16f95a
movq (%r12), %rdi
leaq 0x20f75c(%rip), %rsi    # 0x231958
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
callq 0x20a44
movq (%r12), %rdi
leaq 0x20f750(%rip), %rsi    # 0x23196c
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
movsd 0x20f08c(%rip), %xmm0   # 0x2312c0
pushq $0x13
popq %rsi
xorl %edx, %edx
callq 0x219c2
movq (%r12), %rdi
leaq 0x20f739(%rip), %rsi    # 0x231982
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
callq 0x21cc4
movq (%r12), %rdi
leaq 0x20f731(%rip), %rsi    # 0x23199a
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x22b0
incl %r15d
cmpl %r15d, %r13d
jne 0x221be
movq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x2090
leaq 0x64(%rax), %rdi
callq 0x2280
movq %rax, %rbx
cmpb $0x1, 0x2c(%rsp)
leaq 0x2092a3(%rip), %rax    # 0x22b54a
leaq 0x2092a1(%rip), %rcx    # 0x22b54f
cmoveq %rax, %rcx
leaq 0x20ab69(%rip), %rsi    # 0x22ce22
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 0x21d75
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220