// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
callq 0x23f870
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movl 0x4(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %esi
movl $0x20, %edx
leaq -0x3049(%rip), %rcx     # 0x2428e0
callq 0x23e0
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0xd8(%rcx), %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x245a6c
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %ecx
cmpb $0x0, (%rax,%rcx)
jne 0x245992
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movl (%rcx), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x245997
jmp 0x245a5e
movq -0x30(%rbp), %rax
movsd 0x18(%rax), %xmm1
movsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x2459bc
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x14(%rbp), %eax
ja 0x2459c1
jmp 0x245a5e
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movl (%rcx), %ecx
movb $0x1, (%rax,%rcx)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %ecx
movb $0x1, (%rax,%rcx)
movq -0x60(%rbp), %rdi
callq 0x242830
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0x60(%rbp), %rdi
callq 0x242830
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x245935
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0xd8(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x245aa7
movq -0x60(%rbp), %rdi
movl -0x24(%rbp), %esi
xorl %edx, %edx
callq 0x23f8e0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x245a73
movq -0x60(%rbp), %rdi
callq 0x23fcd0
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movq 0x8(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movl 0x4(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cltq
shlq $0x5, %rax
addq %rax, %rsi
callq 0x22e8e0
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x40(%rbp), %rcx
leaq -0x58(%rbp), %rsi
callq 0x242940
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq -0x58(%rbp), %rsi
callq 0x244570
movq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x245130
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x232ca0
cmpq $0x0, -0x20(%rbp)
je 0x245b78
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x58(%rbp)
movq -0x48(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x48(%rbp)
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x50(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x245820
movq -0x60(%rbp), %rdi
callq 0x23f890
movq -0x40(%rbp), %rdi
callq 0x2210
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)