// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xb8, %rsp
movl 0x48(%rbp), %eax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movl %esi, -0x24(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movq 0x38(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jae 0xf485e
jmp 0xf4dbc
movq $0x0, -0x68(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0xf4875
jmp 0xf4dbc
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xf48b4
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x5c(%rbp)
movq 0x30(%rbp), %rax
movl -0x5c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xf487c
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xf49c9
jmp 0xf48cd
movq 0x38(%rbp), %rax
movq (%rax), %rax
movq 0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xf493e
movq 0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf48fd
movq 0x38(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0xf490b
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0xf490b
movq -0x88(%rbp), %rcx
movq 0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x38(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl -0x4c(%rbp), %edx
addl $0x1, %edx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x48(%rbp), %r9
movq 0x10(%rbp), %r15
movq -0x40(%rbp), %r14
movl 0x20(%rbp), %ebx
movl 0x28(%rbp), %r11d
movq 0x18(%rbp), %r10
movq 0x30(%rbp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0xf1ff0
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xf48bb
movl $0xffffffff, -0x70(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x78(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xf4bd2
cmpl $0x0, -0x4c(%rbp)
jbe 0xf4a33
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
cmpl 0x48(%rbp), %eax
jb 0xf4a33
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl 0x48(%rbp), %eax
jae 0xf4a33
movl -0x4c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0xf4bc2
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl 0x48(%rbp), %eax
jae 0xf4bc2
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
cmpl 0x48(%rbp), %eax
jb 0xf4bc2
movl -0x4c(%rbp), %eax
movl %eax, -0x70(%rbp)
cmpl $-0x1, -0x6c(%rbp)
jne 0xf4a8d
movl -0x4c(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $-0x1, -0x6c(%rbp)
je 0xf4bb4
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jb 0xf4bb4
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl -0x6c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x70(%rbp), %eax
ja 0xf4af6
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x54(%rbp), %eax
jae 0xf4ae9
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0xf4aeb
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xf4ab7
cmpl $-0x1, -0x58(%rbp)
je 0xf4bb2
movl -0x24(%rbp), %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x80(%rbp)
movl -0x58(%rbp), %eax
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x40(%rbp), %rax
movq (%rax), %rax
movq 0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xf4b8f
movq 0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf4b4e
movq 0x40(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0xf4b5c
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0xf4b5c
movq -0x90(%rbp), %rcx
movq 0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x40(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rdx
movq 0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x40(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0xf4bb2
jmp 0xf4bb4
movl $0xffffffff, -0x70(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
jmp 0xf4bc4
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xf49ec
cmpl $-0x1, -0x6c(%rbp)
je 0xf4be4
cmpl $-0x1, -0x70(%rbp)
jne 0xf4be4
movl -0x6c(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xf4d7d
cmpl $-0x1, -0x74(%rbp)
jne 0xf4c06
cmpl $-0x1, -0x78(%rbp)
je 0xf4d7d
movl -0x74(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x70(%rbp)
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
cmpl $-0x1, -0x6c(%rbp)
je 0xf4c71
movl -0x6c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xf4c6f
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x54(%rbp), %eax
jae 0xf4c62
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0xf4c64
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xf4c2c
jmp 0xf4c71
cmpl $-0x1, -0x70(%rbp)
je 0xf4cbf
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x70(%rbp), %eax
ja 0xf4cbd
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x54(%rbp), %eax
jae 0xf4cb0
movq 0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0xf4cb2
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xf4c7e
jmp 0xf4cbf
cmpl $-0x1, -0x58(%rbp)
je 0xf4d7b
movl -0x24(%rbp), %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x80(%rbp)
movl -0x58(%rbp), %eax
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x40(%rbp), %rax
movq (%rax), %rax
movq 0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xf4d58
movq 0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf4d17
movq 0x40(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0xf4d25
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0xf4d25
movq -0x98(%rbp), %rcx
movq 0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x40(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rdx
movq 0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x40(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0xf4d7b
jmp 0xf4d7d
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xf4dbc
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x5c(%rbp)
movq 0x30(%rbp), %rax
movl -0x5c(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xf4d84
addq $0xb8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)