// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
movl %esi, 0xc(%rsp)
movsd %xmm0, 0x30(%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 0x153f45(%rip), %rcx    # 0x175977
pushq $0x20
popq %rdx
callq 0x23f0
movq 0xd8(%r12), %rax
testl $0x7fffffff, 0x4(%rax)  # imm = 0x7FFFFFFF
movq %r14, (%rsp)
je 0x21bc6
movq %r14, %rdi
xorl %r13d, %r13d
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movq 0x8(%rax), %rbx
movl 0x4(%rbx,%r13), %eax
cmpb $0x0, (%rdi,%rax)
jne 0x21ba5
leaq (%rbx,%r13), %r14
movl (%r14), %ecx
cmpb $0x0, (%rdi,%rcx)
jne 0x21ba5
movsd 0x30(%rsp), %xmm0
ucomisd 0x18(%rbx,%r13), %xmm0
jae 0x21ba5
movl 0x8(%rbx,%r13), %edx
andl %r8d, %edx
cmpl 0xc(%rsp), %edx
jbe 0x21ba5
movb $0x1, %dl
movb %dl, (%rdi,%rcx)
movb %dl, (%rdi,%rax)
movl 0x4(%r15), %ecx
andl %r8d, %ecx
movl (%r15), %eax
cmpl %eax, %ecx
jne 0x21ae9
leal (%rax,%rax), %esi
testl %eax, %eax
pushq $0x10
popq %rax
cmovel %eax, %esi
movl %esi, (%r15)
movq 0x8(%r15), %rdi
shlq $0x5, %rsi
callq 0x2370
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq (%rsp), %rdi
movq %rax, 0x8(%r15)
movq 0x8(%r15), %rax
movl 0x4(%r15), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl %r8d, %esi
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%r15)
shlq $0x5, %rdx
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movl 0x4(%r15), %ecx
andl %r8d, %ecx
movl (%r15), %eax
cmpl %eax, %ecx
jne 0x21b58
leal (%rax,%rax), %esi
testl %eax, %eax
pushq $0x10
popq %rax
cmovel %eax, %esi
movl %esi, (%r15)
movq 0x8(%r15), %rdi
shlq $0x5, %rsi
callq 0x2370
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq (%rsp), %rdi
movq %rax, 0x8(%r15)
movq 0x8(%r15), %rax
movl 0x4(%r15), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%r15)
shlq $0x5, %rdx
movupd (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rax,%rdx)
movupd %xmm0, (%rax,%rdx)
movl (%rbx,%r13), %ecx
movl %ecx, 0x4(%rax,%rdx)
movl 0x4(%rbx,%r13), %ecx
movl %ecx, (%rax,%rdx)
incq %rbp
movq 0xd8(%r12), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq $0x20, %r13
cmpq %rcx, %rbp
jb 0x21a61
movq 0xd8(%r12), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0x21bfd
xorl %ebp, %ebp
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x174c30
incl %ebp
movq 0xd8(%r12), %rax
movl 0x14(%rax), %eax
andl %ebx, %eax
cmpl %eax, %ebp
jb 0x21bde
movq %r15, %rdi
callq 0x174e07
movq 0xd8(%r12), %rax
movq 0x8(%rax), %rdi
movl 0x4(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shlq $0x5, %rsi
addq %rdi, %rsi
callq 0x16c76a
leaq 0x10(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movq (%rsp), %rbx
movq %rbx, %rcx
callq 0x21227
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x176308
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x1768f1
movq 0xc8(%r12), %rdi
callq 0x20357
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
je 0x21c9b
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
andq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rcx)
andq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rcx)
andq $0x0, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x1769db
movq %r15, %rdi
callq 0x174c02
movq (%rsp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220