// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: if_potential_false_node(ma_hit_t_alloc*, unsigned long, ma_sub_t*, ma_sub_t*, int)
int if_potential_false_node(ma_hit_t_alloc* paf, uint64_t rLen, ma_sub_t* max_left, ma_sub_t* max_right, int if_set)
{
    max_left->s = max_right->s = rLen;
    max_left->e = max_right->e = 0;

    long long j;
    uint32_t qs, qe;
    for (j = 0; j < paf->length; j++)
    {
        if(paf->buffer[j].del) continue;
        if(paf->buffer[j].el != 1) continue;

        qs = Get_qs(paf->buffer[j]);
        qe = Get_qe(paf->buffer[j]);

        ///overlaps from left side
        if(qs == 0)
        {
            if(qs < max_left->s) max_left->s = qs;
            if(qe > max_left->e) max_left->e = qe;
        }

        ///overlaps from right side
        if(qe == rLen)
        {
            if(qs < max_right->s) max_right->s = qs;
            if(qe > max_right->e) max_right->e = qe;
        }

        ///note: if (qs == 0 && qe == rLen)
        ///this overlap would be added to both b_left and b_right
        ///that is what we want
    }

    if (max_left->e > max_right->s) return 0;

    long long new_left_e, new_right_s;
    new_left_e = max_left->e;
    new_right_s = max_right->s;

    for (j = 0; j < paf->length; j++)
    {
        if(paf->buffer[j].del) continue;
        if(paf->buffer[j].el != 1) continue;

        qs = Get_qs(paf->buffer[j]);
        qe = Get_qe(paf->buffer[j]);
        ///check contained overlaps
        if(qs != 0 && qe != rLen)
        {
            ///[qs, qe), [max_left.s, max_left.e)
            if(qs < max_left->e && qe > max_left->e)
            {
                ///if(qe > max_left->e) max_left->e = qe;
                if(qe > max_left->e && qe > new_left_e) new_left_e = qe;
            }

            ///[qs, qe), [max_right.s, max_right.e)
            if(qs < max_right->s && qe > max_right->s)
            {
                ///if(qs < max_right->s) max_right->s = qs;
                if(qs < max_right->s && qs < new_right_s) new_right_s = qs;
            }



            if(if_set)
            {
                max_left->e = new_left_e;
                max_right->s = new_right_s;
            }
        }
    }

    max_left->e = new_left_e;
    max_right->s = new_right_s;

    if (max_left->e > max_right->s) return 0;

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x80000000, %r9d       # imm = 0x80000000
movl (%rcx), %r10d
andl %r9d, %r10d
orl %eax, %r10d
movl %r10d, (%rcx)
andl (%rdx), %r9d
orl %eax, %r9d
movl %r9d, (%rdx)
xorl %eax, %eax
movl %eax, 0x4(%rcx)
movl %eax, 0x4(%rdx)
cmpl %eax, 0xc(%rdi)
je 0xafa5c
movl $0x20, %r9d
xorl %r10d, %r10d
movq (%rdi), %r11
cmpq $0x0, -0x8(%r11,%r9)
js 0xafa4c
cmpb $0x1, (%r11,%r9)
jne 0xafa4c
movl -0x20(%r11,%r9), %ebx
movl -0x18(%r11,%r9), %r11d
testl %ebx, %ebx
jne 0xafa1c
movl (%rdx), %ebp
testl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
je 0xafa12
andl $0x80000000, %ebp       # imm = 0x80000000
movl %ebp, (%rdx)
cmpl 0x4(%rdx), %r11d
jbe 0xafa1c
movl %r11d, 0x4(%rdx)
cmpq %rsi, %r11
jne 0xafa4c
movl (%rcx), %ebp
movl %ebp, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
cmpl %ebx, %r14d
jbe 0xafa42
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andl $0x80000000, %ebp       # imm = 0x80000000
orl %ebx, %ebp
movl %ebp, (%rcx)
cmpl 0x4(%rcx), %r11d
jbe 0xafa4c
movl %r11d, 0x4(%rcx)
incq %r10
movl 0xc(%rdi), %r11d
addq $0x28, %r9
cmpq %r11, %r10
jb 0xaf9e0
movl 0x4(%rdx), %r10d
movl (%rcx), %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
cmpl %r9d, %r10d
ja 0xafb3d
cmpl $0x0, 0xc(%rdi)
je 0xafb24
movl $0x20, %eax
xorl %r11d, %r11d
movl $0x80000000, %ebx       # imm = 0x80000000
movq (%rdi), %r15
cmpq $0x0, -0x8(%r15,%rax)
js 0xafb09
cmpb $0x1, (%r15,%rax)
jne 0xafb09
movq -0x20(%r15,%rax), %r14
testl %r14d, %r14d
je 0xafb09
movl -0x18(%r15,%rax), %r15d
cmpq %rsi, %r15
je 0xafb09
movl 0x4(%rdx), %ebp
cmpq %r15, %r10
movq %r15, %r12
cmovgq %r10, %r12
cmpl %ebp, %r15d
cmovbeq %r10, %r12
cmpl %r14d, %ebp
cmovaq %r12, %r10
movl %r14d, %r12d
movl (%rcx), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpq %r9, %r12
cmovgeq %r9, %r12
cmpl %ebp, %r15d
cmovbeq %r9, %r12
cmpl %r14d, %ebp
cmovaq %r12, %r9
testl %r8d, %r8d
je 0xafb09
movl %r10d, 0x4(%rdx)
movl %r9d, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl (%rcx), %r14d
andl %ebx, %r14d
orl %ebp, %r14d
movl %r14d, (%rcx)
incq %r11
movl 0xc(%rdi), %r14d
addq $0x28, %rax
cmpq %r14, %r11
jb 0xafa8a
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl %r10d, 0x4(%rdx)
movl $0x80000000, %eax       # imm = 0x80000000
andl (%rcx), %eax
orl %r9d, %eax
movl %eax, (%rcx)
xorl %eax, %eax
cmpl %r9d, 0x4(%rdx)
setbe %al
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq