// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xb8, %rsp
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, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xf207b
movl -0x20(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0xf207b
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xf2072
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
jmp 0xf2079
movl $0x0, -0x20(%rbp)
jmp 0xf207b
cmpl $-0x1, -0x20(%rbp)
je 0xf214b
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq 0x30(%rbp), %rcx
movq -0x28(%rbp), %r8
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %ebx
movl -0x3c(%rbp), %r11d
movl -0x40(%rbp), %r10d
xorl %eax, %eax
movl %eax, %edx
leaq -0x78(%rbp), %rax
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0xea7d0
movl $0x0, -0x50(%rbp)
movq -0x78(%rbp), %rax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xf2149
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movslq -0x50(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0xf216c
movl $0x0, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
subq $0x1, %rax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
subl -0x50(%rbp), %eax
cltq
movq %rax, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x80(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0xf22ba
movq -0x80(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xf2236
movq 0x10(%rbp), %rdi
movl -0x48(%rbp), %esi
leaq -0x48(%rbp), %rdx
leaq -0x4c(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x48(%rbp)
je 0xf2232
cmpl $0x1, -0x4c(%rbp)
je 0xf2232
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xf2234
jmp 0xf22ac
jmp 0xf2236
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xf224e
jmp 0xf22ac
movq 0x38(%rbp), %rax
movl -0x48(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
je 0xf2260
jmp 0xf22ac
movl -0x50(%rbp), %edi
movl -0x54(%rbp), %esi
movq -0x88(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
movq -0x88(%rbp), %rax
movl 0x8(%rax), %ecx
subl $0x1, %ecx
leaq -0x58(%rbp), %r8
leaq -0x5c(%rbp), %r9
callq 0x1670e0
cmpl $0x0, %eax
jne 0xf2293
jmp 0xf22ac
movl -0x5c(%rbp), %eax
addl $0x1, %eax
subl -0x58(%rbp), %eax
cltq
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xf21b1
cmpq $0x0, -0x90(%rbp)
jle 0xf22ce
cmpq $0x0, -0x98(%rbp)
jg 0xf22d7
movl $0x0, -0xc(%rbp)
jmp 0xf22ea
movq -0x98(%rbp), %rax
cqto
idivq -0x90(%rbp)
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)