// File: /workspace/github_cpp_makefile_star2_O2/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 0x7e094
cmpl $0x0, (%rdi)
jns 0x7e0e2
xorl %edx, %edx
jmp 0x7e099
cmpl $-0x1, %edx
je 0x7e0e2
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 0x79db6
addq $0x20, %rsp
movq (%rbp), %rdx
testb $0x1, %r13b
jne 0x7e0f2
shrq $0x21, %r12
jmp 0x7e0ee
movq 0x18(%r15), %rax
shrq $0x21, %r12
movq (%rax,%r12,8), %rdx
xorl %ecx, %ecx
jmp 0x7e105
movq 0x18(%r15), %rax
shrq $0x21, %r12
movq (%rax,%r12,8), %rax
movl %eax, %ecx
subl %edx, %ecx
movq %rax, %rdx
movq 0x78(%rsp), %rsi
movq 0x50(%rsp), %rdi
leal -0x1(%rdx), %r8d
imulq $0x18, %r12, %rax
leaq (%r14,%rax), %r9
subl %ecx, %edx
movl 0xc(%r14,%rax), %eax
imulq $0x28, %rax, %r10
xorl %r11d, %r11d
xorl %eax, %eax
cmpq %r11, %r10
je 0x7e19a
movq (%r9), %r14
movl 0xc(%r14,%r11), %r15d
movq 0x20(%rbx), %r12
cmpl $0x0, (%r12,%r15,8)
js 0x7e17a
cmpb $0x1, (%rsi,%r15)
jne 0x7e194
movl (%r14,%r11), %ebp
cmpl %ebp, %r8d
jl 0x7e194
movl 0x8(%r14,%r11), %r14d
decl %r14d
cmpl %r14d, %ecx
jg 0x7e194
cmpl %ebp, %ecx
cmovgl %ecx, %ebp
cmpl %r14d, %r8d
cmovll %r8d, %r14d
subl %ebp, %r14d
incl %r14d
movslq %r14d, %r14
addq %r14, %rax
jmp 0x7e194
cmpq %r15, (%rdi)
jbe 0x7e194
movq 0x8(%rdi), %r13
movslq (%r13,%r15,4), %r15
testq %r15, %r15
js 0x7e194
cmpl $0x0, (%r12,%r15,8)
jns 0x7e143
addq $0x28, %r11
jmp 0x7e12b
xorl %ecx, %ecx
testl %edx, %edx
jle 0x7e1af
testq %rax, %rax
jle 0x7e1af
movl %edx, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq