// File: chhylp123[P]hifiasm/horder.cpp
// Function: print_N50_layout(ma_ug_t*, sc_lay_t*)
void print_N50_layout(ma_ug_t* ug, sc_lay_t* sl)
{
    kvec_t(uint64_t) b; kv_init(b);
    lay_t *p = NULL;
    uint64_t i, k, s, ulen, len, occ = 0;
    for (i = s = 0; i < sl->n; ++i) 
    {
        p = &(sl->a[i]);
        for (k = ulen = 0; k < p->n; k+=2)
        {
            ulen += ug->u.a[p->a[k]>>1].len;
        }
        occ += p->n;
        
        kv_push(uint64_t, b, ulen);
        s += ulen;
    }
    len = s;
    
    radix_sort_ho64(b.a, b.a+b.n);
    fprintf(stderr, "[M::%s::] Scaffold Size: %lu, # Scaffolds: %u (occ-%lu), Largest Scaffold: %lu\n", 
    __func__, len, (uint32_t)sl->n, occ, b.a[b.n-1]);
    i = b.n; s = 0;
    while (i > 0)
    {
        i--;
        s += b.a[i];
        if(s >= (len>>1))
        {
            fprintf(stderr, "[M::%s::] N50: %lu\n", __func__, b.a[i]);
            break;
        }
    }
    
    kv_destroy(b);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x232fd9
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x232f4b
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq -0x40(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
jmp 0x232efd
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x232fa1
cmpq $0x0, -0x20(%rbp)
je 0x232f79
movq -0x20(%rbp), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x232f84
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x232f84
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x18(%rbp)
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x28(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x232ec8
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x22e3a0
movq 0x190fe0(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %r8d
movq -0x60(%rbp), %r9
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rdx
subq $0x1, %rdx
movq (%rax,%rdx,8), %rax
leaq 0x15b3c2(%rip), %rsi    # 0x38e3ef
leaq 0x15b40b(%rip), %rdx    # 0x38e43f
movq %rax, (%rsp)
movb $0x0, %al
callq 0x22a0
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x38(%rbp)
jbe 0x2330b5
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jb 0x2330b3
movq 0x190f53(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x15b338(%rip), %rsi    # 0x38e3db
leaq 0x15b395(%rip), %rdx    # 0x38e43f
movb $0x0, %al
callq 0x22a0
jmp 0x2330b5
jmp 0x23304f
movq -0x18(%rbp), %rdi
callq 0x2210
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)