// File: chhylp123[P]hifiasm/horder.cpp
// Function: break_scaffold(horder_t*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, int, h_covs*)
uint64_t break_scaffold(horder_t *h, uint64_t cutoff_s, uint64_t cutoff_e, uint64_t force_cutoff, uint64_t force_cutoff_cov,
uint64_t local_bound, int unique_only, h_covs *r_b_points)
{
    uint64_t k, l, i, ulen;
    kvec_t_u64_warp b; kv_init(b.a);
    h_covs cov_buf; kv_init(cov_buf);
    h_covs res; kv_init(res);
    h_covs *b_points = NULL; 
    if(r_b_points) b_points = r_b_points;
    else CALLOC(b_points, 1);
    b_points->n = 0;
    h_covs Ns; kv_init(Ns);
    ma_ug_t *ug = h->ug;
    kvec_pe_hit *hits = &(h->u_hits);
    for (k = 1, l = 0; k <= hits->a.n; ++k) 
    {   
        if (k == hits->a.n || (get_hit_suid(*hits, k) != get_hit_suid(*hits, l))) 
        {
            ulen = ug->u.a[get_hit_suid(*hits, l)].len;
            Ns.n = 0;
            if(ulen >= BREAK_THRES)
            {
                get_Ns(&(ug->u.a[get_hit_suid(*hits, l)]), &Ns);
                // fprintf(stderr, "\n[M::%s::] utg%.6lul, ulen: %lu, # Ns: %lu\n", 
                //         __func__, get_hit_suid(*hits, l)+1, ulen, (uint64_t)(Ns.n));
                if(Ns.n)
                {
                    for (i = 0; i < Ns.n; i++)
                    {
                        if(detect_lowNs(hits, l, k, &b, &(Ns.a[i]), ulen, cutoff_s, cutoff_e, force_cutoff,
                        force_cutoff_cov, &res, &cov_buf, b_points, local_bound, unique_only) && r_b_points){
                            b_points->a[b_points->n-1].dp = i;
                        }
                    }
                }
            }  
            l = k;
        }
    }

    if(!r_b_points){
        break_utg_horder(h, b_points);
        kv_destroy(*b_points);
    }
    
    kv_destroy(b.a);
    kv_destroy(cov_buf);
    kv_destroy(res);
    kv_destroy(Ns);

    return b_points->n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
cmpq $0x0, 0x18(%rbp)
je 0x23ef15
movq 0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x23ef2b
movl $0x1, %edi
movl $0x18, %esi
callq 0x2140
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq $0x0, 0x8(%rax)
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xe8(%rbp)
movq -0x30(%rbp), %rax
movq 0xc8(%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0x30(%rbp), %rax
addq $0x70, %rax
movq %rax, -0xf8(%rbp)
movq $0x1, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq -0xf8(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x23f1ef
movq -0x60(%rbp), %rax
movq -0xf8(%rbp), %rcx
cmpq (%rcx), %rax
je 0x23f01a
movq -0xf8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0xf8(%rbp), %rdx
movl $0x40, %ecx
subq 0x48(%rdx), %rcx
shrq %cl, %rax
movq -0xf8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x68(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
shlq %rdx
movq -0xf8(%rbp), %rsi
movl $0x40, %ecx
subq 0x48(%rsi), %rcx
shrq %cl, %rdx
movq %rdx, %rcx
cmpq %rcx, %rax
je 0x23f1dc
movq -0xf0(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xf8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x68(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
shlq %rdx
movq -0xf8(%rbp), %rsi
movl $0x40, %ecx
subq 0x48(%rsi), %rcx
shrq %cl, %rdx
movq %rdx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq $0x0, -0xe0(%rbp)
cmpq $0x4c4b40, -0x78(%rbp)  # imm = 0x4C4B40
jb 0x23f1d4
movq -0xf0(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xf8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0xf8(%rbp), %rdx
movl $0x40, %ecx
subq 0x48(%rdx), %rcx
shrq %cl, %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq -0xe8(%rbp), %rsi
callq 0x23d2e0
cmpq $0x0, -0xe0(%rbp)
je 0x23f1d2
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0xe0(%rbp), %rax
jae 0x23f1d0
movq -0xf8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0xe8(%rbp), %r8
imulq $0x18, -0x70(%rbp), %rax
addq %rax, %r8
movq -0x78(%rbp), %r9
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %r13
movq -0x48(%rbp), %r12
movq -0x50(%rbp), %r15
movq -0xd0(%rbp), %r11
movq -0x58(%rbp), %r10
movl 0x10(%rbp), %ecx
movl %ecx, -0xfc(%rbp)
leaq -0x98(%rbp), %rcx
leaq -0xc8(%rbp), %r14
leaq -0xb0(%rbp), %rbx
movq %rax, (%rsp)
movl -0xfc(%rbp), %eax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movl %eax, 0x40(%rsp)
callq 0x23e000
cmpl $0x0, %eax
je 0x23f1bd
cmpq $0x0, 0x18(%rbp)
je 0x23f1bd
movq -0x70(%rbp), %rcx
movq -0xd0(%rbp), %rax
movq (%rax), %rax
movq -0xd0(%rbp), %rdx
movq 0x8(%rdx), %rdx
subq $0x1, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
jmp 0x23f1bf
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x23f0e7
jmp 0x23f1d2
jmp 0x23f1d4
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x23f1de
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x23ef8c
cmpq $0x0, 0x18(%rbp)
jne 0x23f215
movq -0x30(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x238530
movq -0xd0(%rbp), %rax
movq (%rax), %rdi
callq 0x2210
movq -0x88(%rbp), %rdi
callq 0x2210
movq -0xb0(%rbp), %rdi
callq 0x2210
movq -0xc8(%rbp), %rdi
callq 0x2210
movq -0xe8(%rbp), %rdi
callq 0x2210
movq -0xd0(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)