// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rdx, 0x38(%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 %r15
movq %r15, %rsi
callq 0x2120
movq %rax, %r14
pushq $0x28
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %r15
xorpd %xmm0, %xmm0
andq $0x0, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movq 0x8(%rbx), %rdi
movl 0x4(%rbx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq 0x15b6ec(%rip), %rcx    # 0x17c506
pushq $0x20
popq %rdx
callq 0x23f0
movq %r12, 0x30(%rsp)
movq 0xd8(%r12), %rcx
testl $0x7fffffff, 0x4(%rcx)  # imm = 0x7FFFFFFF
je 0x20fea
xorl %r13d, %r13d
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
xorl %eax, %eax
xorl %r10d, %r10d
xorl %r9d, %r9d
xorl %ebx, %ebx
movsd 0x28(%rsp), %xmm0
movq %r15, 0x40(%rsp)
movq 0x8(%rcx), %rbp
movl 0x4(%rbp,%r13), %edx
cmpb $0x0, (%r14,%rdx)
jne 0x20fd1
movq %rbp, %r12
addq %r13, %r12
movl (%r12), %esi
cmpb $0x0, (%r14,%rsi)
jne 0x20fd1
ucomisd 0x18(%rbp,%r13), %xmm0
jae 0x20fd1
movl 0x8(%rbp,%r13), %edi
andl %r8d, %edi
cmpl 0xc(%rsp), %edi
jbe 0x20fd1
movb $0x1, %cl
movb %cl, (%r14,%rsi)
movb %cl, (%r14,%rdx)
movl %r9d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %r10d, %ecx
jne 0x20ee7
leal (%r10,%r10), %esi
testl %r10d, %r10d
pushq $0x10
popq %rcx
cmovel %ecx, %esi
movl %esi, (%r15)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x8(%r15)
movl 0x4(%r15), %r9d
movl %r9d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leal 0x1(%r9), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %r9d       # imm = 0x80000000
orl %edx, %r9d
movl %r9d, 0x4(%r15)
movl %ecx, %ecx
shlq $0x5, %rcx
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movl (%r15), %r10d
movl 0x4(%r15), %r9d
movq %r15, %rdx
movl %r9d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmpl %r10d, %r15d
jne 0x20f6d
leal (%r15,%r15), %esi
testl %r15d, %r15d
pushq $0x10
popq %rax
cmovel %eax, %esi
movq %rsi, 0x48(%rsp)
movl %esi, (%rdx)
movq 0x8(%rdx), %rdi
shlq $0x5, %rsi
movq %r9, 0x50(%rsp)
callq 0x2370
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %r10
movq 0x50(%rsp), %r9
movq %rax, 0x8(%rdx)
jmp 0x20f71
movq 0x8(%rdx), %rax
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
leal 0x1(%r9), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %r9d       # imm = 0x80000000
orl %ecx, %r9d
movl %r9d, 0x4(%rdx)
shlq $0x5, %r15
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%rax,%r15)
movups %xmm0, (%rax,%r15)
movl (%rbp,%r13), %ecx
movl %ecx, 0x4(%rax,%r15)
movl 0x4(%rbp,%r13), %ecx
movl %ecx, (%rax,%r15)
movq 0x30(%rsp), %rcx
movq 0xd8(%rcx), %rcx
movq %rdx, %r15
movsd 0x28(%rsp), %xmm0
incq %rbx
movl 0x4(%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
addq $0x20, %r13
cmpq %rdx, %rbx
jb 0x20e5a
testl $0x7fffffff, 0x14(%rcx) # imm = 0x7FFFFFFF
movq 0x30(%rsp), %r12
je 0x2101e
xorl %ebp, %ebp
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x17b776
incl %ebp
movq 0xd8(%r12), %rax
movl 0x14(%rax), %eax
andl %ebx, %eax
cmpl %eax, %ebp
jb 0x20fff
movq %r15, %rdi
callq 0x17b968
movq 0xd8(%r12), %rax
movq 0x8(%rax), %rdi
movl 0x4(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shlq $0x5, %rsi
addq %rdi, %rsi
callq 0x1731ac
leaq 0x10(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2062a
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x17ce73
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x17d438
movq 0xc8(%r12), %rdi
callq 0x1f729
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0x210b1
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 0x17d55e
movq %r15, %rdi
callq 0x17b748
movq %r14, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220