// File: chhylp123[P]hifiasm/horder.cpp
// Function: verbose_misjoin(unsigned long*, unsigned long)
void verbose_misjoin(uint64_t *a, uint64_t a_n)
{
    radix_sort_ho64(a, a + a_n);
    uint64_t k, l, i, len, s, C[2], N[2];
    C[0] = C[1] = N[0] = N[1] = 0;
    for (k = 1, l = 0; k <= a_n; ++k) 
    {   
        if (k == a_n || (a[k]>>63) != (a[l]>>63))
        {
            for (i = l, s = 0; i < k; i++) s += ((a[i]<<1)>>1);
            len = s;

            i = k; s = 0;
            while (i > l)
            {
                i--;
                s += ((a[i]<<1)>>1);
                if(s >= (len>>1))
                {
                    N[a[l]>>63] = ((a[i]<<1)>>1);
                    C[a[l]>>63] = k - l;
                    // fprintf(stderr, "[M::%s::] N50: %lu\n", __func__, b.a[i]);
                    break;
                }
            }
            
            l = k;
        }
    }

    fprintf(stderr, "[M::stat] # misjoined unitigs: %lu (N50: %lu); # corrected unitigs: %lu (N50: %lu)\n", 
    C[0], N[0], C[1], N[1]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x22e3a0
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x1, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x10(%rbp), %rax
ja 0x23b1bd
movq -0x18(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x23b0b9
movq -0x8(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x3f, %rax
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x3f, %rcx
cmpq %rcx, %rax
je 0x23b1aa
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x23b0fb
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shlq %rax
shrq %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x23b0c9
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x23b1a2
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shlq %rax
shrq %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jb 0x23b19d
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
shlq %rcx
shrq %rcx
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rdx
movq (%rax,%rdx,8), %rax
shrq $0x3f, %rax
movq %rcx, -0x60(%rbp,%rax,8)
movq -0x18(%rbp), %rcx
subq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rdx
movq (%rax,%rdx,8), %rax
shrq $0x3f, %rax
movq %rcx, -0x50(%rbp,%rax,8)
jmp 0x23b1a2
jmp 0x23b113
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x23b1ac
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x23b078
movq 0x188e1c(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x58(%rbp), %r9
leaq 0x153391(%rip), %rsi    # 0x38e56f
movb $0x0, %al
callq 0x22a0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)