// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/horder.cpp
// Function: break_scaffold_mean(horder_t*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, int, h_covs*)
uint64_t break_scaffold_mean(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);
                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), %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, %rbx
testq %rcx, %rcx
jne 0x1748c6
movl $0x1, %edi
movl $0x18, %esi
callq 0x2120
xorps %xmm0, %xmm0
movq %rax, %rbx
xorl %eax, %eax
movq %rax, 0x8(%rbx)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x70(%r14), %rax
testq %rax, %rax
je 0x174a70
leaq 0x70(%r14), %rcx
movq %rcx, 0x8(%rsp)
movq 0xc8(%r14), %rcx
movq %rcx, 0x30(%rsp)
movl $0x1, %r12d
movq $0x0, (%rsp)
movq %r14, 0x28(%rsp)
cmpq %rax, %r12
je 0x174954
movq 0x80(%r14), %rax
movq %r12, %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 0x174954
movq (%rsp), %rcx
jmp 0x174a58
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x80(%r14), %rcx
movq (%rsp), %rdx
shlq $0x5, %rdx
movq (%rcx,%rdx), %rdx
addq %rdx, %rdx
movb 0xb8(%r14), %sil
xorl %ecx, %ecx
subb %sil, %cl
shrq %cl, %rdx
leaq (%rdx,%rdx,4), %rcx
leaq (%rax,%rcx,8), %rdi
movl (%rdi), %ebp
movq $0x0, 0x18(%rsp)
leaq 0x10(%rsp), %rsi
callq 0x173d34
movq 0x18(%rsp), %r15
movq %r12, %rcx
testq %r15, %r15
je 0x174a58
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %r14
xorl %r13d, %r13d
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %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 0x173f3c
addq $0x50, %rsp
cmpq $0x0, 0x108(%rsp)
je 0x174a40
testl %eax, %eax
je 0x174a40
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %r13, -0x8(%rax,%rcx,8)
incq %r13
addq $0x18, %r14
cmpq %r13, %r15
jne 0x1749be
movq %r12, %rcx
movq 0x28(%rsp), %r14
incq %r12
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rcx, (%rsp)
cmpq %rax, %r12
jbe 0x17490b
cmpq $0x0, 0x108(%rsp)
jne 0x174a8e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1710c8
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