// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_break_point_cov_advance(unsigned int, long long, asg_t*, All_reads*, ma_hit_t_alloc*, R_to_U*, unsigned char*, kvec_t_u64_warp*, long long, unsigned int, unsigned int*)
void get_break_point_cov_advance(uint32_t v, long long c_beg, asg_t* read_g, All_reads *RNF, 
ma_hit_t_alloc* sources, R_to_U* ruIndex, uint8_t* r_flag, kvec_t_u64_warp* depth, long long utg_len, 
uint32_t is_circle, uint32_t* uID)
{
    uint32_t i, tn, is_Unitig;
    long long v_beg, v_end, w_beg, w_end;
    
    v_beg = 0; v_end = Get_READ_LENGTH((*RNF), (v>>1)) - 1;
    if(uID && (r_flag[v>>1]&1) && (!(r_flag[v>>1]&2)))
    {
        if(push_cov_interval_advance(depth, v_beg+c_beg, v_end+c_beg, utg_len, is_circle)) r_flag[v>>1] |= 2;
        return;    
    } 
    

    ma_hit_t_alloc* x = &(sources[v>>1]);
    ma_hit_t *h = NULL;
    long long qs, qe, ts, te;
    ///[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;
        tn = Get_tn((*h));///must!!!!
        
        if(r_flag[tn]&2) continue;

        qs = Get_qs((*h)); qe = Get_qe((*h)) - 1;
        ts = Get_ts((*h)); te = Get_te((*h)) - 1;
        if(h->rev)
        {
            ts = (long long)(Get_READ_LENGTH((*RNF), tn)) - ((long long)(Get_te((*h))) - 1) - 1;
            te = (long long)(Get_READ_LENGTH((*RNF), tn)) - (long long)(Get_ts((*h))) - 1;
        }
        ts = qs - ts;
        te = qe + ((long long)(Get_READ_LENGTH((*RNF), tn)) - te - 1);
        w_beg = ts; w_end = te;

        if(v&1)
        {
            ts = (long long)(Get_READ_LENGTH((*RNF), v>>1)) - ts - 1;
            te = (long long)(Get_READ_LENGTH((*RNF), v>>1)) - te - 1;
            w_beg = te; w_end = ts;
        }

        if(push_cov_interval_advance(depth, w_beg+c_beg, w_end+c_beg, utg_len, is_circle)) r_flag[tn] |= 2;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r12
movq %rcx, 0x10(%rsp)
movq %rdx, %rbx
movq %rsi, 0x18(%rsp)
movq 0x60(%rsp), %rsi
movl %edi, 0xc(%rsp)
movl %edi, %ecx
shrl %ecx
cmpq $0x0, 0x80(%rsp)
je 0xb9466
movb (%rsi,%rcx), %al
andb $0x3, %al
cmpb $0x1, %al
jne 0xb9466
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rcx, %rbx
movq (%rax,%rcx,8), %rax
movq 0x18(%rsp), %rsi
leaq -0x1(%rsi,%rax), %rdx
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rcx
movl 0x78(%rsp), %r8d
callq 0xb9319
movq 0x60(%rsp), %rcx
testl %eax, %eax
je 0xb958b
orb $0x2, (%rcx,%rbx)
jmp 0xb958b
movq %rcx, 0x20(%rsp)
leaq (%rcx,%rcx,2), %rax
cmpl $0x0, 0xc(%r8,%rax,8)
je 0xb958b
leaq (%r8,%rax,8), %r15
movl $0x18, %r13d
xorl %r14d, %r14d
movq (%r15), %rax
movl -0xc(%rax,%r13), %ebp
movq 0x20(%rbx), %rcx
cmpl $0x0, (%rcx,%rbp,8)
movq %rbp, %rdx
js 0xb94d4
testb $0x1, (%rsi,%rdx)
je 0xb9577
testb $0x2, (%rsi,%rbp)
jne 0xb9577
movl -0x8(%rax,%r13), %edi
movl -0x4(%rax,%r13), %edx
testb $-0x80, 0x3(%rax,%r13)
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rcx
jne 0xb94f8
decl %edx
movq (%rcx,%rbp,8), %r8
jmp 0xb950e
cmpq %rbp, (%r12)
jbe 0xb9577
movq 0x8(%r12), %rdx
movslq (%rdx,%rbp,4), %rdx
testq %rdx, %rdx
js 0xb9577
cmpl $0x0, (%rcx,%rdx,8)
jns 0xb949d
jmp 0xb9577
movq (%rcx,%rbp,8), %r8
movq %r8, %rsi
subq %rdx, %rsi
notq %rdi
movq %rdi, %rdx
addq %r8, %rdx
movq %rsi, %rdi
movl -0x18(%rax,%r13), %esi
movl -0x10(%rax,%r13), %eax
subq %rdi, %rsi
decl %eax
addq %r8, %rax
notq %rdx
addq %rax, %rdx
testb $0x1, 0xc(%rsp)
je 0xb954b
movq 0x20(%rsp), %rax
movq (%rcx,%rax,8), %rax
notq %rsi
addq %rax, %rsi
notq %rdx
movq %rdx, %rcx
addq %rax, %rcx
movq %rsi, %rdx
movq %rcx, %rsi
movq 0x18(%rsp), %rax
addq %rax, %rsi
addq %rax, %rdx
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rcx
movl 0x78(%rsp), %r8d
callq 0xb9319
testl %eax, %eax
movq 0x60(%rsp), %rsi
je 0xb9577
orb $0x2, (%rsi,%rbp)
incq %r14
movl 0xc(%r15), %eax
addq $0x28, %r13
cmpq %rax, %r14
jb 0xb9488
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq