// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/horder.cpp
// Function: layout_scg(horder_t*, double, unsigned int, sc_lay_t*)
void layout_scg(horder_t *h, double nw_thres, uint32_t occ_thres, sc_lay_t *r_sl)
{
    uint32_t k;
    osg_arc_t *p = NULL, *lp = NULL;
    uint8_t *vis = NULL; CALLOC(vis, h->sg.g->n_seq<<1);
    sc_lay_t sl; kv_init(sl);
    osg_t *lg = osg_init();
    qsort(h->sg.g->arc, h->sg.g->n_arc, sizeof(osg_arc_t), cmp_arc_nw);
    for (k = 0; k < h->sg.g->n_arc; k++)
    {
        p = &(h->sg.g->arc[k]);
        if(vis[p->u] || vis[p->v]) continue;
        ///different with slsa2
        if(p->nw <= nw_thres || p->occ <= occ_thres) continue;
        vis[p->u] = vis[p->v] = 1;
        lp = osg_arc_pushp(lg);
        (*lp) = (*p);
        lp = osg_arc_pushp(lg);
        (*lp) = (*p);
        lp->u = p->v;
        lp->v = p->u;
    }
    for (k = 0; k < h->sg.g->n_seq; k++)
    {
        osg_seq_set(lg, k, 0);
    }
    osg_cleanup(lg);
    radix_sort_osg(h->sg.g->arc, h->sg.g->arc + h->sg.g->n_arc);

    get_backbone_layout(h, &sl, lg, vis);

    // get_long_switch_scaffolds(h, &sl, lg);
    
    refine_layout(h, &sl, vis);
    
    // print_N50_layout(h->ug, &sl);

    update_ug_by_layout(h, &sl, NULL);

    print_N50(h->ug);

    if(r_sl){
        r_sl->a = sl.a; sl.a = NULL;
        r_sl->m = sl.m; sl.m = 0;
        r_sl->n = sl.n; sl.n = 0;

    }
    destory_sc_lay_t(&sl);
    osg_destroy(lg);
    free(vis);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x30(%rsp)
movl %esi, 0xc(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %rdi, %r12
movq 0xd8(%rdi), %rbx
movl 0x14(%rbx), %eax
addl %eax, %eax
movslq %eax, %rdi
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, %r14
callq 0x137824
movq %rax, (%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%rbx), %rdi
movl 0x4(%rbx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq -0x1669(%rip), %rcx     # 0x138b81
pushq $0x20
popq %rdx
callq 0x23f0
movsd 0x28(%rsp), %xmm0
xorl %r13d, %r13d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
xorl %ebx, %ebx
movq 0xd8(%r12), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rbx
jae 0x13a2b4
movq 0x8(%rax), %rbp
movl 0x4(%rbp,%r13), %eax
cmpb $0x0, (%r14,%rax)
jne 0x13a2a8
movq %rbp, %r15
addq %r13, %r15
movl (%r15), %ecx
cmpb $0x0, (%r14,%rcx)
jne 0x13a2a8
ucomisd 0x18(%rbp,%r13), %xmm0
jae 0x13a2a8
movl 0x8(%rbp,%r13), %edx
andl %esi, %edx
cmpl 0xc(%rsp), %edx
jbe 0x13a2a8
movb $0x1, %dl
movb %dl, (%r14,%rcx)
movb %dl, (%r14,%rax)
movq (%rsp), %rdi
callq 0x138b1d
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm0, (%rax)
movups %xmm1, 0x10(%rax)
movq (%rsp), %rdi
callq 0x138b1d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm0, (%rax)
movsd 0x28(%rsp), %xmm0
movups %xmm1, 0x10(%rax)
movl (%rbp,%r13), %ecx
movl %ecx, 0x4(%rax)
movl 0x4(%rbp,%r13), %ecx
movl %ecx, (%rax)
incq %rbx
addq $0x20, %r13
jmp 0x13a202
xorl %ebp, %ebp
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq (%rsp), %r15
movl 0x14(%rax), %eax
andl %ebx, %eax
movq %r15, %rdi
cmpl %eax, %ebp
jae 0x13a2e0
movl %ebp, %esi
xorl %edx, %edx
callq 0x13785d
incl %ebp
movq 0xd8(%r12), %rax
jmp 0x13a2bf
callq 0x137a11
movq 0xd8(%r12), %rax
movq 0x8(%rax), %rdi
movl 0x4(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shlq $0x5, %rsi
addq %rdi, %rsi
callq 0x12f4b6
leaq 0x10(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x138ba5
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x13984d
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x139d6e
movq 0xc8(%r12), %rdi
callq 0x131810
movq 0x30(%rsp), %rcx
testq %rcx, %rcx
je 0x13a370
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
andq $0x0, 0x10(%rsp)
movupd 0x18(%rsp), %xmm0
andq $0x0, 0x20(%rsp)
movupd %xmm0, 0x8(%rcx)
andq $0x0, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x13a151
movq (%rsp), %rdi
callq 0x13782f
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220