// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: detect_break_point(ma_utg_t*, unsigned int, asg_t*, All_reads*, ma_sub_t*, ma_hit_t_alloc*, R_to_U*, kvec_asg_arc_t_warp*, int, int, unsigned char*, kvec_t_u32_warp*, kvec_t_u64_warp*, unsigned int)
void detect_break_point(ma_utg_t *u, uint32_t uID, asg_t* read_g, All_reads *RNF, ma_sub_t* coverage_cut, 
ma_hit_t_alloc* sources, R_to_U* ruIndex, kvec_asg_arc_t_warp* edge, int max_hang, int min_ovlp,
uint8_t* r_flag, kvec_t_u32_warp* depth, kvec_t_u64_warp* res, uint32_t b_low_cov)
{
    depth->a.n = 0;
    ///res->a.n = 0;
    if(u->n < 2) return;
    uint32_t k, i, min, min_idx, rId, *p = NULL, beg_idx, end_idx, cir_beg_idx, cir_end_idx;
    uint64_t tmp;
    if(u->m == 0) return;
    for (k = 0; k < u->n; k++)
    {
        rId = u->a[k]>>33;
        r_flag[rId] = 1;
    }


    for (k = 0; k < u->n; k++)
    {
        kv_pushp(uint32_t, depth->a, &p);
        (*p) = get_break_point_cov(u, k, k+1, read_g, RNF, sources, ruIndex, coverage_cut, max_hang, min_ovlp, edge, r_flag);
    }


    beg_idx = end_idx = (uint32_t)-1;
    cir_beg_idx = cir_end_idx = (uint32_t)-1;
    for (k = 0; k < u->n; k++)
    {
        if(k > 0 && depth->a.a[k-1] >= b_low_cov && depth->a.a[k] < b_low_cov)
        {
            beg_idx = k;
        }

        if(k < u->n-1 && depth->a.a[k] < b_low_cov && depth->a.a[k+1] >= b_low_cov)
        {
            end_idx = k;
            if(beg_idx == (uint32_t)-1) cir_end_idx = k;
            if(beg_idx != (uint32_t)-1 && end_idx >= beg_idx)
            {
                min = min_idx = (uint32_t)-1;
                for (i = beg_idx; i <= end_idx; i++)
                {
                    if(depth->a.a[i] < min)
                    {
                        min = depth->a.a[i];
                        min_idx = i;
                    }
                }
                if(min_idx != (uint32_t)-1)
                {
                    tmp = uID; tmp <<=32; tmp += min_idx;
                    kv_push(uint64_t, res->a, tmp);
                } 
            }
            beg_idx = end_idx = (uint32_t)-1;
        }
    }

    if(beg_idx != (uint32_t)-1 && end_idx == (uint32_t)-1) cir_beg_idx = beg_idx;

    if(u->circ && (cir_beg_idx != (uint32_t)-1 || cir_end_idx != (uint32_t)-1))
    {
        beg_idx = cir_beg_idx;
        end_idx = cir_end_idx;

        min = min_idx = (uint32_t)-1;

        if(beg_idx != (uint32_t)-1)
        {
            for (i = beg_idx; i < u->n; i++)
            {
                if(depth->a.a[i] < min)
                {
                    min = depth->a.a[i];
                    min_idx = i;
                }
            }
        }

        if(end_idx != (uint32_t)-1)
        {
            for (i = 0; i <= end_idx; i++)
            {
                if(depth->a.a[i] < min)
                {
                    min = depth->a.a[i];
                    min_idx = i;
                }
            }
        }

        if(min_idx != (uint32_t)-1)
        {
            tmp = uID; tmp <<=32; tmp += min_idx;
            kv_push(uint64_t, res->a, tmp);
        } 
    }


    for (k = 0; k < u->n; k++)
    {
        rId = u->a[k]>>33;
        r_flag[rId] = 0;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, (%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x88(%rsp), %r12
movq $0x0, (%r12)
cmpl $0x2, 0x10(%rdi)
jb 0xb9b82
movq %rdi, %rbx
cmpl $0x0, 0xc(%rdi)
je 0xb9b82
movq %rsi, 0x10(%rsp)
movq 0x80(%rsp), %rdx
cmpl $0x0, 0x10(%rbx)
je 0xb9895
xorl %eax, %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shrq $0x21, %rcx
movb $0x1, (%rdx,%rcx)
incq %rax
movl 0x10(%rbx), %ecx
cmpq %rcx, %rax
jb 0xb987a
cmpl $0x0, 0x10(%rbx)
je 0xb9943
xorl %r14d, %r14d
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0xb98d5
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %r13
movq 0x10(%r12), %rbp
leaq 0x1(%r13), %rax
movq %rax, (%r12)
leal 0x1(%r14), %r15d
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq 0x8(%rsp), %r9
pushq 0x80(%rsp)
pushq 0x70(%rsp)
movl 0x88(%rsp), %eax
pushq %rax
movl 0x88(%rsp), %eax
pushq %rax
pushq 0x20(%rsp)
pushq 0x88(%rsp)
callq 0xb811f
addq $0x30, %rsp
movl %eax, (%rbp,%r13,4)
movl %r15d, %r14d
cmpl 0x10(%rbx), %r15d
jb 0xb98a2
movq 0x90(%rsp), %r9
movl 0x10(%rbx), %eax
testl %eax, %eax
je 0xb9a86
movl 0x98(%rsp), %edi
movq 0x10(%rsp), %r8
shlq $0x20, %r8
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl $0x1, %r14d
xorl %r13d, %r13d
movl $0x2, %r11d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %r13, %r13
je 0xb999a
movq 0x10(%r12), %rcx
cmpl %edi, -0x4(%rcx,%r13,4)
jb 0xb999a
cmpl %edi, (%rcx,%r13,4)
cmovbl %r13d, %r15d
decl %eax
cmpq %rax, %r13
jae 0xb9a72
movq 0x10(%r12), %rax
cmpl %edi, (%rax,%r13,4)
jae 0xb9a72
cmpl %edi, 0x4(%rax,%r13,4)
jb 0xb9a72
cmpl $-0x1, %r15d
sete %dl
cmovel %r13d, %r10d
movl %r15d, %ecx
cmpq %rcx, %r13
setb %sil
orb %dl, %sil
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jne 0xb9a72
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl (%rax,%rcx,4), %esi
cmpl %edx, %esi
cmovbl %esi, %edx
cmovbl %ecx, %ebp
incq %rcx
cmpq %rcx, %r14
jne 0xb99ed
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %ebp
je 0xb9a72
movq 0x8(%r9), %rax
cmpq %rax, (%r9)
jne 0xb9a5b
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r11, %rsi
movq %rsi, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x3, %rsi
movq %r10, 0x8(%rsp)
movq %r8, (%rsp)
callq 0x2370
movl $0x2, %r11d
movq (%rsp), %r8
movl 0x98(%rsp), %edi
movq 0x8(%rsp), %r10
movq 0x90(%rsp), %r9
movq %rax, 0x10(%r9)
movl %ebp, %eax
orq %r8, %rax
movq (%r9), %rcx
movq 0x10(%r9), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r9)
movq %rax, (%rdx,%rcx,8)
incq %r13
movl 0x10(%rbx), %eax
incq %r14
cmpq %rax, %r13
jb 0xb9981
jmp 0xb9a92
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
cmpl $0x0, (%rbx)
jns 0xb9b57
cmpl $-0x1, %r15d
jne 0xb9aab
cmpl $-0x1, %r10d
je 0xb9b57
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl %eax, %r15d
jae 0xb9ada
movq 0x10(%r12), %rsi
movl %r15d, %edi
movl %eax, %eax
movl (%rsi,%rdi,4), %r8d
cmpl %edx, %r8d
cmovbl %r8d, %edx
cmovbl %edi, %ecx
incq %rdi
cmpq %rdi, %rax
jne 0xb9ac4
cmpl $-0x1, %r10d
je 0xb9afd
movq 0x10(%r12), %rax
incl %r10d
xorl %esi, %esi
movl (%rax,%rsi,4), %edi
cmpl %edx, %edi
cmovbl %edi, %edx
cmovbl %esi, %ecx
incq %rsi
cmpl %esi, %r10d
jne 0xb9aea
cmpl $-0x1, %ecx
je 0xb9b57
movq 0x10(%rsp), %rax
shlq $0x20, %rax
movl %ecx, %r14d
orq %rax, %r14
movq 0x8(%r9), %rax
cmpq %rax, (%r9)
jne 0xb9b45
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x3, %rsi
movq %r9, %r15
callq 0x2370
movq %r15, %r9
movq %rax, 0x10(%r15)
movq (%r9), %rax
movq 0x10(%r9), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r9)
movq %r14, (%rcx,%rax,8)
cmpl $0x0, 0x10(%rbx)
movq 0x80(%rsp), %rdx
je 0xb9b82
xorl %eax, %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shrq $0x21, %rcx
movb $0x0, (%rdx,%rcx)
incq %rax
movl 0x10(%rbx), %ecx
cmpq %rcx, %rax
jb 0xb9b67
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq