// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, %rbx
movq 0x18(%rdi), %rax
movl %esi, %ecx
movl 0x10(%rdi), %r8d
leal -0x1(%r8), %r9d
xorl %esi, %r9d
xorl %edx, %r8d
orl %r9d, %r8d
jne 0xb8156
movl (%rdi), %edx
notl %edx
sarl $0x1f, %edx
movq (%rax,%rcx,8), %r12
cmpl $-0x1, %edx
je 0xb81c1
movq %r12, %r13
shrq $0x20, %r13
movq 0x80(%rsp), %rcx
movl 0x78(%rsp), %r10d
movl 0x70(%rsp), %r9d
movq 0x68(%rsp), %rsi
movl %edx, %edx
movl 0x4(%rax,%rdx,8), %eax
leaq 0x10(%rsp), %rbp
movq %r14, %rdi
movq %rbx, %r8
pushq %rbp
pushq %rax
pushq %r13
pushq %r10
callq 0xb3953
addq $0x20, %rsp
movq (%rbp), %rdx
xorl %esi, %esi
testb $0x1, %r13b
je 0xb81d2
movq 0x18(%r15), %rax
movq %r12, %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
subl %edx, %esi
movq %rax, %rdx
jmp 0xb81d2
movq 0x18(%r15), %rax
movq %r12, %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rdx
xorl %esi, %esi
shrq $0x21, %r12
leaq (%r12,%r12,2), %rdi
movl %edx, %eax
subl %esi, %eax
movl %eax, 0xc(%rsp)
movl 0xc(%r14,%rdi,8), %ecx
testq %rcx, %rcx
je 0xb82db
movq 0x88(%rsp), %r8
movq 0x60(%rsp), %r9
decl %edx
leaq (%r14,%rdi,8), %rdi
movq (%rdi), %r10
movq 0x20(%rbx), %r11
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rbx
xorl %r14d, %r14d
xorl %ecx, %ecx
movl 0xc(%r10,%r14), %edi
cmpl $0x0, (%r11,%rdi,8)
movl %edi, %r12d
js 0xb8284
movl %r12d, %edi
cmpl $0x0, (%r11,%rdi,8)
js 0xb82cc
cmpb $0x1, (%r8,%rdi)
jne 0xb82cc
movl (%r10,%r14), %r12d
movl 0x8(%r10,%r14), %r13d
decl %r13d
cmpl %r13d, %esi
setg %al
cmpl %r12d, %edx
setl %dil
orb %al, %dil
jne 0xb8271
cmpl %r12d, %esi
cmovgl %esi, %r12d
cmpl %r13d, %edx
cmovll %edx, %r13d
movl %r12d, %r15d
movl %r13d, %ebp
testb %dil, %dil
jne 0xb82cc
movl %ebp, %eax
subl %r15d, %eax
incl %eax
cltq
addq %rax, %rcx
jmp 0xb82cc
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq %rdi, (%r9)
jbe 0xb82ae
movq 0x8(%r9), %r13
movl (%r13,%rdi,4), %r13d
cmpl $-0x1, %r13d
je 0xb82ae
movl %r13d, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
shrl $0x1f, %r13d
jmp 0xb82b1
xorl %r13d, %r13d
cmpl $-0x1, %r12d
sete %dil
orb %r13b, %dil
jne 0xb82cc
movl %r12d, %edi
cmpl $0x0, (%r11,%rdi,8)
jns 0xb8226
addq $0x28, %r14
cmpq %r14, %rbx
jne 0xb8217
jmp 0xb82dd
xorl %ecx, %ecx
movl 0xc(%rsp), %edx
testl %edx, %edx
jle 0xb82fc
testq %rcx, %rcx
movl $0x0, %eax
jle 0xb82fe
movslq %edx, %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
jmp 0xb82fe
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq