// File: /workspace/github_cpp_makefile_star2_O1/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 %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq 0x60(%rsp), %r9
movl %edi, 0xc(%rsp)
movl %edi, %edx
shrl %edx
cmpq $0x0, 0x80(%rsp)
je 0xb8542
movb (%r9,%rdx), %al
andb $0x3, %al
cmpb $0x1, %al
jne 0xb8542
movq 0x18(%rcx), %rax
movq %rdx, %rbx
movq (%rax,%rdx,8), %rax
movq 0x10(%rsp), %rsi
leaq (%rsi,%rax), %rdx
decq %rdx
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rcx
movl 0x78(%rsp), %r8d
callq 0xb83f1
movq 0x60(%rsp), %rcx
testl %eax, %eax
je 0xb869f
orb $0x2, (%rcx,%rbx)
jmp 0xb869f
movq %rdx, 0x18(%rsp)
leaq (%rdx,%rdx,2), %rax
cmpl $0x0, 0xc(%r8,%rax,8)
je 0xb869f
leaq (%r8,%rax,8), %r13
movl $0x18, %r14d
xorl %r15d, %r15d
movq %rcx, 0x20(%rsp)
movq (%r13), %rax
movl -0xc(%rax,%r14), %ebp
movq 0x20(%rbx), %r8
cmpl $0x0, (%r8,%rbp,8)
movl %ebp, %edx
js 0xb85b8
movl %edx, %edx
cmpl $0x0, (%r8,%rdx,8)
js 0xb868b
testb $0x1, (%r9,%rdx)
je 0xb868b
testb $0x2, (%r9,%rbp)
jne 0xb868b
movl -0x8(%rax,%r14), %r8d
movl -0x4(%rax,%r14), %edx
testb $-0x80, 0x3(%rax,%r14)
jne 0xb85fd
decl %edx
jmp 0xb8617
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rbp, (%r12)
jbe 0xb85dd
movq 0x8(%r12), %rsi
movl (%rsi,%rbp,4), %esi
cmpl $-0x1, %esi
je 0xb85dd
movl %esi, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %esi
jmp 0xb85df
xorl %esi, %esi
cmpl $-0x1, %edx
sete %dil
orb %sil, %dil
jne 0xb868b
movl %edx, %esi
cmpl $0x0, (%r8,%rsi,8)
jns 0xb857f
jmp 0xb868b
movq 0x18(%rcx), %rsi
movq (%rsi,%rbp,8), %rsi
movq %rsi, %rdi
subq %rdx, %rdi
notq %r8
movq %r8, %rdx
addq %rsi, %rdx
movq %rdi, %r8
movl -0x18(%rax,%r14), %esi
movl -0x10(%rax,%r14), %edi
subq %r8, %rsi
decl %edi
movq 0x18(%rcx), %rax
notq %rdx
addq %rdi, %rdx
addq (%rax,%rbp,8), %rdx
testb $0x1, 0xc(%rsp)
je 0xb8659
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
notq %rsi
addq %rax, %rsi
notq %rdx
movq %rdx, %rcx
addq %rax, %rcx
movq %rsi, %rdx
movq %rcx, %rsi
movq 0x10(%rsp), %rax
addq %rax, %rsi
addq %rax, %rdx
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rcx
movl 0x78(%rsp), %r8d
callq 0xb83f1
testl %eax, %eax
movq 0x60(%rsp), %r9
movq 0x20(%rsp), %rcx
je 0xb868b
orb $0x2, (%r9,%rbp)
incq %r15
movl 0xc(%r13), %eax
addq $0x28, %r14
cmpq %rax, %r15
jb 0xb8569
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq