// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq 0x108(%rsp), %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
xorl %eax, %eax
movq %rax, 0xb0(%rsp)
movq %rax, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %rax, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq %rcx, %rax
testq %rcx, %rcx
jne 0x17b17a
movl $0x1, %edi
movl $0x18, %esi
callq 0x2120
xorps %xmm0, %xmm0
movq %rax, (%rsp)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rcx, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x70(%rbx), %rax
testq %rax, %rax
je 0x17b32d
leaq 0x70(%rbx), %rcx
movq %rcx, 0x8(%rsp)
movq 0xc8(%rbx), %r14
movl $0x1, %r12d
xorl %r13d, %r13d
movq %rbx, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movq 0x80(%rbx), %rdx
cmpq %rax, %r12
jne 0x17b1e7
movq %r13, %rax
shlq $0x5, %rax
movq (%rdx,%rax), %rax
addq %rax, %rax
movb 0xb8(%rbx), %dl
xorl %ecx, %ecx
subb %dl, %cl
shrq %cl, %rax
jmp 0x17b220
movq %r12, %rax
shlq $0x5, %rax
movq (%rdx,%rax), %rsi
addq %rsi, %rsi
movb 0xb8(%rbx), %al
xorl %ecx, %ecx
subb %al, %cl
shrq %cl, %rsi
movq %r13, %rax
shlq $0x5, %rax
movq (%rdx,%rax), %rax
addq %rax, %rax
shrq %cl, %rax
cmpq %rax, %rsi
jne 0x17b220
movq %r13, %rcx
jmp 0x17b316
movq 0x10(%r14), %rdx
leaq (%rax,%rax,4), %rax
movl (%rdx,%rax,8), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq $0x0, 0x18(%rsp)
movq %r12, %rcx
cmpl $0x4c4b40, %ebp         # imm = 0x4C4B40
jb 0x17b316
leaq (%rdx,%rax,8), %rdi
leaq 0x10(%rsp), %rsi
callq 0x17a897
movq (%rsp), %r10
movq 0x18(%rsp), %r15
movq %r12, %rcx
testq %r15, %r15
je 0x17b316
movq 0x10(%rsp), %r14
xorl %ebx, %ebx
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq 0xa8(%rsp), %rcx
movq %r14, %r8
movq %rbp, %r9
movl 0x108(%rsp), %eax
pushq %rax
pushq 0x68(%rsp)
pushq %r10
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 0x17aaaf
movq 0x50(%rsp), %r10
addq $0x50, %rsp
cmpq $0x0, 0x108(%rsp)
je 0x17b2f9
testl %eax, %eax
je 0x17b2f9
movq (%r10), %rax
movq 0x8(%r10), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rbx, -0x8(%rax,%rcx,8)
incq %rbx
addq $0x18, %r14
cmpq %rbx, %r15
jne 0x17b273
movq %r12, %rcx
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r14
incq %r12
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rcx, %r13
cmpq %rax, %r12
jbe 0x17b1be
cmpq $0x0, 0x108(%rsp)
jne 0x17b34f
movq %rbx, %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0x177cbc
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 (%rsp), %rax
movq 0x8(%rax), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq