// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_break_point_cov(ma_utg_t*, unsigned int, unsigned int, asg_t*, All_reads*, ma_hit_t_alloc*, R_to_U*, ma_sub_t*, int, int, kvec_asg_arc_t_warp*, unsigned char*)
uint32_t get_break_point_cov(ma_utg_t* collection, uint32_t cur_i, uint32_t next_i, 
asg_t* read_g, All_reads *RNF, ma_hit_t_alloc* sources, R_to_U* ruIndex, ma_sub_t *coverage_cut, 
int max_hang, int min_ovlp, kvec_asg_arc_t_warp* edge, uint8_t* r_flag)
{
    uint32_t v, w, i, tn, is_Unitig;
    int v_beg, v_end, v_sub_beg, v_sub_end;
    asg_arc_t t;

    v = (uint64_t)(collection->a[cur_i])>>32;
    ///last element
    if(cur_i == collection->n-1 && next_i == collection->n)
    {
        if(!collection->circ)
        {
            next_i = (uint32_t)-1;
        }
        else
        {
            next_i = 0;
        }
    }

    if(next_i != ((uint32_t)-1))
    {
        w = (uint64_t)(collection->a[next_i])>>32;

        get_specific_edge(sources, coverage_cut, NULL, edge, read_g, max_hang, min_ovlp, v, w, &t);
        v_beg = 0; v_end = asg_arc_len(t) - 1; 
        if(v&1)
        {
            v_beg = Get_READ_LENGTH((*RNF), (v>>1)) - v_beg - 1;
            v_end = Get_READ_LENGTH((*RNF), (v>>1)) - v_end - 1;
            w = v_beg; v_beg = v_end; v_end = w;
        }
    }
    else
    {
        v_beg = 0; v_end = Get_READ_LENGTH((*RNF), (v>>1)) - 1;
    }

    ma_hit_t_alloc* x = &(sources[v>>1]);
    ma_hit_t *h = NULL;
    long long R_bases = v_end + 1 - v_beg, C_bases = 0;
    ///[v_beg, v_end] must be the end of read, which means v_beg = 0 or v_end = Get_READ_LENGTH((*RNF), (v>>1)) - 1
    for (i = 0; i < x->length; i++)
    {
        h = &(x->buffer[i]);
        tn = Get_tn((*h));
        if(read_g->seq[tn].del == 1)
        {
            ///get the id of read that contains it 
            get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
            if(tn == (uint32_t)-1 || is_Unitig == 1 || read_g->seq[tn].del == 1) continue;
        }
        if(read_g->seq[tn].del == 1) continue;
        if(r_flag[tn] != 1) continue;


        if(inter_interval(v_beg, v_end, Get_qs((*h)), Get_qe((*h)) - 1, 
                                                &v_sub_beg, &v_sub_end) == 0)
        {
            continue;
        }

        C_bases += (v_sub_end + 1 - v_sub_beg);
    }
    if(R_bases <= 0 || C_bases <= 0) return 0;

    return C_bases/R_bases;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, %rbx
movq 0x18(%rdi), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %r12
movl 0x10(%rdi), %ecx
leal -0x1(%rcx), %r8d
xorl %esi, %r8d
xorl %edx, %ecx
orl %r8d, %ecx
jne 0xb90f9
cmpl $0x0, (%rdi)
jns 0xb9147
xorl %edx, %edx
jmp 0xb90fe
cmpl $-0x1, %edx
je 0xb9147
movq 0x70(%rsp), %rcx
movl 0x68(%rsp), %r10d
movl 0x60(%rsp), %r9d
movq 0x58(%rsp), %rsi
movq %r12, %r13
shrq $0x20, %r13
movl %edx, %edx
movl 0x4(%rax,%rdx,8), %eax
movq %rsp, %rbp
movq %r14, %rdi
movq %rbx, %r8
pushq %rbp
pushq %rax
pushq %r13
pushq %r10
callq 0xb4a8d
addq $0x20, %rsp
movq (%rbp), %rdx
testb $0x1, %r13b
jne 0xb9157
shrq $0x21, %r12
jmp 0xb9153
movq 0x18(%r15), %rax
shrq $0x21, %r12
movq (%rax,%r12,8), %rdx
xorl %ecx, %ecx
jmp 0xb916a
movq 0x18(%r15), %rax
shrq $0x21, %r12
movq (%rax,%r12,8), %rax
movl %eax, %ecx
subl %edx, %ecx
movq %rax, %rdx
leaq (%r12,%r12,2), %rsi
movl 0xc(%r14,%rsi,8), %eax
testq %rax, %rax
je 0xb9221
movq 0x78(%rsp), %rdi
movq 0x50(%rsp), %r8
leal -0x1(%rdx), %r9d
leaq (%r14,%rsi,8), %r10
subl %ecx, %edx
movslq %edx, %rsi
movq (%r10), %r10
movq 0x20(%rbx), %r11
shlq $0x3, %rax
leaq (%rax,%rax,4), %rbx
xorl %r14d, %r14d
xorl %eax, %eax
movl 0xc(%r10,%r14), %r15d
cmpl $0x0, (%r11,%r15,8)
js 0xb91ea
cmpb $0x1, (%rdi,%r15)
jne 0xb9203
movl (%r10,%r14), %ebp
cmpl %ebp, %r9d
jl 0xb9203
movl 0x8(%r10,%r14), %r15d
decl %r15d
cmpl %r15d, %ecx
jg 0xb9203
cmpl %ebp, %ecx
cmovgl %ecx, %ebp
cmpl %r15d, %r9d
cmovll %r9d, %r15d
subl %ebp, %r15d
incl %r15d
movslq %r15d, %r15
addq %r15, %rax
jmp 0xb9203
cmpq %r15, (%r8)
jbe 0xb9203
movq 0x8(%r8), %r12
movslq (%r12,%r15,4), %r15
testq %r15, %r15
js 0xb9203
cmpl $0x0, (%r11,%r15,8)
jns 0xb91b3
addq $0x28, %r14
cmpq %r14, %rbx
jne 0xb91a7
xorl %ecx, %ecx
testl %edx, %edx
jle 0xb9223
testq %rax, %rax
jle 0xb9223
xorl %edx, %edx
divq %rsi
movq %rax, %rcx
jmp 0xb9223
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq