// File: /workspace/github_cpp_makefile_star2_O3/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, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdi, %rbx
movq 0x88(%rsp), %rdi
movq $0x0, (%rdi)
cmpl $0x2, 0x10(%rbx)
jb 0xbaabc
cmpl $0x0, 0xc(%rbx)
je 0xbaabc
movq %rdx, %rbp
movq %rsi, 0x8(%rsp)
movq 0x90(%rsp), %r9
movq 0x80(%rsp), %r11
xorl %eax, %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shrq $0x21, %rcx
movb $0x1, (%r11,%rcx)
incq %rax
movl 0x10(%rbx), %ecx
cmpq %rcx, %rax
jb 0xba74e
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
testl %ecx, %ecx
je 0xba97b
xorl %r15d, %r15d
movq (%rdi), %r13
movq 0x10(%rdi), %r14
cmpq 0x8(%rdi), %r13
jne 0xba7be
leaq (,%r13,2), %rsi
testq %r13, %r13
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rdi)
shlq $0x2, %rsi
movq %r14, %rdi
callq 0x2370
movq 0x88(%rsp), %rdi
movq %rax, %r14
movq %rax, 0x10(%rdi)
movq (%rdi), %r13
movq 0x80(%rsp), %r10
leaq 0x1(%r13), %rax
movq %rax, (%rdi)
leal 0x1(%r15), %r12d
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
movq %rbp, %rcx
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %r9
pushq %r10
pushq 0x70(%rsp)
movl 0x88(%rsp), %eax
pushq %rax
movl 0x88(%rsp), %eax
pushq %rax
pushq 0x38(%rsp)
pushq 0x88(%rsp)
callq 0xb90be
movq 0xb8(%rsp), %rdi
addq $0x30, %rsp
movl %eax, (%r14,%r13,4)
movl 0x10(%rbx), %ecx
movl %r12d, %r15d
cmpl %ecx, %r12d
jb 0xba77b
testl %ecx, %ecx
je 0xba987
movq 0x8(%rsp), %r15
shlq $0x20, %r15
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x1, %r12d
xorl %r13d, %r13d
movl %ecx, %eax
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq 0x80(%rsp), %r11
movq 0x90(%rsp), %r9
movl 0x98(%rsp), %r10d
testq %r13, %r13
je 0xba884
movq 0x10(%rdi), %rdx
cmpl %r10d, -0x4(%rdx,%r13,4)
jb 0xba884
cmpl %r10d, (%rdx,%r13,4)
cmovbl %r13d, %r8d
leal -0x1(%rax), %edx
cmpq %rdx, %r13
jae 0xba968
movq 0x10(%rdi), %rdx
cmpl %r10d, (%rdx,%r13,4)
jae 0xba968
cmpl %r10d, 0x4(%rdx,%r13,4)
jb 0xba968
cmpl $-0x1, %r8d
sete %dil
cmovel %r13d, %r14d
movl %r8d, %esi
cmpq %rsi, %r13
setb %r8b
orb %dil, %r8b
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
jne 0xba960
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl (%rdx,%rsi,4), %r8d
cmpl %edi, %r8d
cmovbl %r8d, %edi
cmovbl %esi, %ebp
incq %rsi
cmpq %rsi, %r12
jne 0xba8d8
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl $-0x1, %ebp
je 0xba960
movq (%r9), %rdx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rdx
jne 0xba94e
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r9)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl 0x98(%rsp), %r10d
movq 0x90(%rsp), %r9
movq 0x80(%rsp), %r11
movq %rax, 0x10(%r9)
movq (%r9), %rdx
movl 0x10(%rbx), %ecx
movl %ebp, %esi
orq %r15, %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%r9)
movq %rsi, (%rax,%rdx,8)
movl %ecx, %eax
movq 0x88(%rsp), %rdi
incq %r13
movl %eax, %edx
incq %r12
cmpq %rdx, %r13
jb 0xba86c
jmp 0xba9a7
xorl %ecx, %ecx
xorl %eax, %eax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0xba9a7
xorl %ecx, %ecx
xorl %eax, %eax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x80(%rsp), %r11
movq 0x90(%rsp), %r9
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl $0x0, (%rbx)
jns 0xbaa9a
cmpl $-0x1, %r8d
jne 0xba9c0
cmpl $-0x1, %r14d
je 0xbaa9a
movq %r9, %r12
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpl %eax, %r8d
jae 0xbaa00
movq 0x88(%rsp), %rdx
movq 0x10(%rdx), %rdi
movl %r8d, %r8d
movl %eax, %r9d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl (%rdi,%r8,4), %r10d
cmpl %esi, %r10d
cmovbl %r10d, %esi
cmovbl %r8d, %edx
incq %r8
cmpq %r8, %r9
jne 0xba9e9
cmpl $-0x1, %r14d
je 0xbaa2f
movq 0x88(%rsp), %rdi
movq 0x10(%rdi), %rdi
incl %r14d
xorl %r8d, %r8d
movl (%rdi,%r8,4), %r9d
cmpl %esi, %r9d
cmovbl %r9d, %esi
cmovbl %r8d, %edx
incq %r8
cmpl %r8d, %r14d
jne 0xbaa18
cmpl $-0x1, %edx
je 0xbaa9a
movq 0x8(%rsp), %rax
shlq $0x20, %rax
movl %edx, %r14d
orq %rax, %r14
movq %r12, %rdi
movq (%r12), %rdx
cmpq 0x8(%r12), %rdx
jne 0xbaa89
leaq (%rdx,%rdx), %rax
testq %rdx, %rdx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x8(%rdi)
movq 0x10(%rdi), %rdi
shlq $0x3, %rsi
movq %r11, %r15
callq 0x2370
movq %r12, %rdi
movq %r15, %r11
movq %rax, 0x10(%r12)
movq (%r12), %rdx
movl 0x10(%rbx), %ecx
jmp 0xbaa8d
movq 0x10(%rdi), %rax
leaq 0x1(%rdx), %rsi
movq %rsi, (%rdi)
movq %r14, (%rax,%rdx,8)
movl %ecx, %eax
testl %eax, %eax
je 0xbaabc
xorl %eax, %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shrq $0x21, %rcx
movb $0x0, (%r11,%rcx)
incq %rax
movl 0x10(%rbx), %ecx
cmpq %rcx, %rax
jb 0xbaaa0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq