// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, 0x8(%rsp)
movq 0x88(%rsp), %r13
andq $0x0, (%r13)
movl 0x10(%rdi), %ecx
cmpl $0x2, %ecx
jb 0x7f7e6
movq %rdi, %rbx
cmpl $0x0, 0xc(%rdi)
je 0x7f7e6
movq 0x80(%rsp), %rdi
xorl %eax, %eax
movl %ecx, %edx
cmpq %rdx, %rax
jae 0x7f549
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shrq $0x21, %rcx
movb $0x1, (%rdi,%rcx)
incq %rax
movl 0x10(%rbx), %ecx
jmp 0x7f52a
movq %rsi, (%rsp)
pushq $0x1
popq %r14
leal -0x1(%r14), %r12d
cmpl %ecx, %r12d
jae 0x7f5f7
movq (%r13), %rbp
movq 0x10(%r13), %r15
cmpq 0x8(%r13), %rbp
jne 0x7f599
leaq (,%rbp,2), %rsi
testq %rbp, %rbp
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r13)
shlq $0x2, %rsi
movq %r15, %rdi
callq 0x2370
movq %rax, %r15
movq %rax, 0x10(%r13)
movq (%r13), %rbp
leaq 0x1(%rbp), %rax
movq %rax, (%r13)
movq %rbx, %rdi
movl %r12d, %esi
movl %r14d, %edx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %r9
pushq 0x80(%rsp)
pushq 0x70(%rsp)
movl 0x88(%rsp), %eax
pushq %rax
movl 0x88(%rsp), %eax
pushq %rax
pushq 0x38(%rsp)
pushq 0x88(%rsp)
callq 0x7e059
addq $0x30, %rsp
movl %eax, (%r15,%rbp,4)
movl 0x10(%rbx), %ecx
incl %r14d
jmp 0x7f551
shlq $0x20, (%rsp)
pushq $-0x1
popq %r9
xorl %r15d, %r15d
movl %r9d, %eax
movl %r9d, %r14d
movl 0x98(%rsp), %r8d
movl %ecx, %edx
cmpq %rdx, %r15
jae 0x7f706
testq %r15, %r15
je 0x7f634
movq 0x10(%r13), %rdx
cmpl %r8d, -0x4(%rdx,%r15,4)
jb 0x7f634
cmpl %r8d, (%rdx,%r15,4)
cmovbl %r15d, %eax
leal -0x1(%rcx), %edx
cmpq %rdx, %r15
jae 0x7f6fe
movq 0x10(%r13), %rdx
cmpl %r8d, (%rdx,%r15,4)
jae 0x7f6fe
cmpl %r8d, 0x4(%rdx,%r15,4)
jb 0x7f6fe
cmpl $-0x1, %eax
sete %sil
cmovel %r15d, %r14d
movl %eax, %edi
cmpq %rdi, %r15
setb %dil
orb %sil, %dil
je 0x7f67a
movl %r9d, %eax
jmp 0x7f6fe
movl %r9d, %esi
movl %r9d, %r12d
movl %eax, %eax
cmpq %rax, %r15
jb 0x7f697
movl (%rdx,%rax,4), %edi
cmpl %esi, %edi
cmovbl %edi, %esi
cmovbl %eax, %r12d
incl %eax
jmp 0x7f680
cmpl $-0x1, %r12d
je 0x7f6f3
movq 0x90(%rsp), %rbp
movq (%rbp), %rdx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rdx
jne 0x7f6e0
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbp)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
pushq $-0x1
popq %r9
movq %rax, 0x10(%rbp)
movq (%rbp), %rdx
movl 0x10(%rbx), %ecx
movl %r12d, %esi
orq (%rsp), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rbp)
movq %rsi, (%rax,%rdx,8)
movl %r9d, %eax
movl 0x98(%rsp), %r8d
incq %r15
jmp 0x7f611
cmpl $0x0, (%rbx)
jns 0x7f7bf
cmpl $-0x1, %eax
jne 0x7f71e
cmpl $-0x1, %r14d
je 0x7f7bf
cmpl $-0x1, %eax
je 0x7f743
movl %eax, %esi
pushq $-0x1
popq %rcx
movl %ecx, %eax
cmpq %rdx, %rsi
jae 0x7f748
movq 0x10(%r13), %rdi
movl (%rdi,%rsi,4), %edi
cmpl %ecx, %edi
cmovbl %edi, %ecx
cmovbl %esi, %eax
incq %rsi
jmp 0x7f72a
pushq $-0x1
popq %rcx
movl %ecx, %eax
cmpl $-0x1, %r14d
je 0x7f76c
movq 0x10(%r13), %rdx
incl %r14d
xorl %esi, %esi
cmpq %rsi, %r14
je 0x7f76c
movl (%rdx,%rsi,4), %edi
cmpl %ecx, %edi
cmovbl %edi, %ecx
cmovbl %esi, %eax
incq %rsi
jmp 0x7f757
cmpl $-0x1, %eax
je 0x7f7bf
movl %eax, %eax
movq (%rsp), %r14
orq %rax, %r14
movq 0x90(%rsp), %r15
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x7f7b4
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %r14, (%rax,%rcx,8)
xorl %eax, %eax
movq 0x80(%rsp), %rdx
movl 0x10(%rbx), %ecx
cmpq %rcx, %rax
jae 0x7f7e6
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shrq $0x21, %rcx
movb $0x0, (%rdx,%rcx)
incq %rax
jmp 0x7f7c9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq