// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
movq 0x108(%rsp), %rax
andq $0x0, 0xb0(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x90(%rsp)
movaps %xmm0, 0xa0(%rsp)
andq $0x0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x60(%rsp)
movq %rax, %rbx
testq %rax, %rax
jne 0x13729e
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x2120
xorps %xmm0, %xmm0
movq %rax, %rbx
andq $0x0, 0x8(%rbx)
leaq 0x10(%rsp), %rax
andq $0x0, 0x10(%rax)
pushq $0x1
popq %r15
movaps %xmm0, (%rax)
movq 0xc8(%r14), %r13
leaq 0x70(%r14), %rax
movq %rax, 0x8(%rsp)
movq $0x0, (%rsp)
movq %r14, 0x30(%rsp)
movq %r13, 0x28(%rsp)
movq 0x8(%rsp), %rax
cmpq (%rax), %r15
ja 0x137442
movq 0x80(%r14), %rax
jne 0x13730c
movq (%rsp), %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rax
addq %rax, %rax
movb 0xb8(%r14), %dl
xorl %ecx, %ecx
subb %dl, %cl
shrq %cl, %rax
jmp 0x137349
movq %r15, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rdx
addq %rdx, %rdx
movb 0xb8(%r14), %sil
xorl %ecx, %ecx
subb %sil, %cl
shrq %cl, %rdx
movq (%rsp), %rsi
shlq $0x5, %rsi
movq (%rax,%rsi), %rax
addq %rax, %rax
shrq %cl, %rax
cmpq %rax, %rdx
jne 0x137349
movq (%rsp), %rcx
jmp 0x137436
movq 0x10(%r13), %rdi
imulq $0x28, %rax, %rax
movl (%rdi,%rax), %ebp
andq $0x0, 0x18(%rsp)
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq %r15, %rcx
cmpl $0x4c4b40, %ebp         # imm = 0x4C4B40
jb 0x137436
addq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x136882
movq 0x18(%rsp), %r12
movq %r15, %rcx
testq %r12, %r12
je 0x137436
movq 0x10(%rsp), %r14
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x137429
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
leaq 0xa8(%rsp), %rcx
movq %r14, %r8
movq %rbp, %r9
movl 0x108(%rsp), %eax
pushq %rax
pushq 0x68(%rsp)
pushq %rbx
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0x80(%rsp)
pushq 0x80(%rsp)
pushq 0x80(%rsp)
callq 0x136bf6
addq $0x50, %rsp
cmpq $0x0, 0x108(%rsp)
je 0x13741d
testl %eax, %eax
je 0x13741d
movq (%rbx), %rax
imulq $0x18, 0x8(%rbx), %rcx
movq %r13, -0x8(%rax,%rcx)
incq %r13
addq $0x18, %r14
jmp 0x137395
movq %r15, %rcx
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r13
incq %r15
movq %rcx, (%rsp)
jmp 0x1372d6
cmpq $0x0, 0x108(%rsp)
jne 0x137460
movq %r14, %rdi
movq %rbx, %rsi
callq 0x133fc9
movq (%rbx), %rdi
callq 0x2220
movq 0xb0(%rsp), %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq 0x60(%rsp), %rdi
callq 0x2220
movq 0x10(%rsp), %rdi
callq 0x2220
movq 0x8(%rbx), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq