// File: /workspace/github_cpp_makefile_star2_O2/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, 0x38(%rsp)
movl %ecx, %ebx
movq %rdx, 0x30(%rsp)
movq %rsi, %r15
movq %rdi, %r14
leaq 0x70(%rdi), %rax
movq %rax, 0x40(%rsp)
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 %r15, 0xc8(%r14)
movq 0x18(%r15), %rdi
callq 0x68f68
movq 0xc8(%r14), %rdi
andq $0x0, 0x18(%rdi)
callq 0x131810
movq 0x118780(%rip), %r12    # 0x252fe0
movq (%r12), %rdi
leaq 0xb51cd(%rip), %rsi     # 0x1efa38
leaq 0xb51d8(%rip), %rbp     # 0x1efa4a
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0x18(%r14), %r15
xorl %r13d, %r13d
cmpl %r13d, %ebx
je 0x13a94c
movq (%r12), %rdi
leaq 0xb51bf(%rip), %rsi     # 0x1efa56
movq %rbp, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x22b0
movq 0xc8(%r14), %rdx
movq 0xd0(%r14), %rcx
movq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x13292a
movq (%r12), %rdi
leaq 0xb519e(%rip), %rsi     # 0x1efa68
movq %rbp, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
callq 0x138496
movq (%r12), %rdi
leaq 0xb5192(%rip), %rsi     # 0x1efa7c
movq %rbp, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
movsd 0xb4ace(%rip), %xmm0    # 0x1ef3d0
pushq $0x13
popq %rsi
xorl %edx, %edx
callq 0x13a185
movq (%r12), %rdi
leaq 0xb517b(%rip), %rsi     # 0x1efa92
movq %rbp, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
callq 0x13a399
movq (%r12), %rdi
leaq 0xb5173(%rip), %rsi     # 0x1efaaa
movq %rbp, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x22b0
incl %r13d
jmp 0x13a883
movq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x2090
leaq 0x64(%rax), %rdi
callq 0x2280
movq %rax, %r15
cmpb $0x1, 0x2c(%rsp)
leaq 0xaecc9(%rip), %rax     # 0x1e963a
leaq 0xaecc7(%rip), %rcx     # 0x1e963f
cmoveq %rax, %rcx
leaq 0xb058f(%rip), %rsi     # 0x1eaf12
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2050
movq 0xc8(%r14), %rdi
movq 0xd0(%r14), %rsi
movq 0x30(%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 %r15, %rcx
callq 0x13a44a
movq %r15, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220