// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
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)
andl $0x0, 0x4(%rcx)
andl $0x0, 0x4(%rdx)
movabsq $0x20, %rax
xorl %r10d, %r10d
movl 0xc(%rdi), %r9d
cmpq %r9, %r10
jae 0x7678d
movq (%rdi), %r9
cmpq $0x0, -0x8(%r9,%rax)
js 0x76784
cmpb $0x1, (%r9,%rax)
jne 0x76784
movl -0x20(%r9,%rax), %r11d
movl -0x18(%r9,%rax), %r9d
testl %r11d, %r11d
jne 0x7675b
movl (%rdx), %ebx
testl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
je 0x76751
andl $0x80000000, %ebx       # imm = 0x80000000
movl %ebx, (%rdx)
cmpl 0x4(%rdx), %r9d
jbe 0x7675b
movl %r9d, 0x4(%rdx)
cmpq %rsi, %r9
jne 0x76784
movl (%rcx), %ebx
movl %ebx, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpl %r11d, %ebp
jbe 0x7677a
andl $0x80000000, %ebx       # imm = 0x80000000
orl %r11d, %ebx
movl %ebx, (%rcx)
cmpl 0x4(%rcx), %r9d
jbe 0x76784
movl %r9d, 0x4(%rcx)
incq %r10
addq $0x28, %rax
jmp 0x76715
movl 0x4(%rdx), %r15d
movl (%rcx), %r10d
movl %r10d, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %eax, %eax
cmpl %r14d, %r15d
ja 0x76882
movabsq $0x20, %rax
xorl %r11d, %r11d
movl %r9d, %ebx
cmpq %rbx, %r11
jae 0x76862
movq (%rdi), %rbx
cmpq $0x0, -0x8(%rbx,%rax)
js 0x767e5
cmpb $0x1, (%rbx,%rax)
jne 0x767e5
movq -0x20(%rbx,%rax), %rbp
testl %ebp, %ebp
je 0x767e5
movl -0x18(%rbx,%rax), %ebx
cmpq %rsi, %rbx
jne 0x767fa
movq %r15, %r12
movq %r14, %r13
incq %r11
addq $0x28, %rax
movq %r12, %r15
movq %r13, %r14
jmp 0x767b6
movl 0x4(%rdx), %r13d
cmpq %rbx, %r15
movq %rbx, %r12
cmovgq %r15, %r12
cmpl %r13d, %ebx
cmovbeq %r15, %r12
cmpl %ebp, %r13d
cmovbeq %r15, %r12
movl %ebp, %r13d
movl %r10d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmpq %r14, %r13
cmovgeq %r14, %r13
cmpl %r15d, %ebx
cmovbeq %r14, %r13
cmpl %ebp, %r15d
cmovbeq %r14, %r13
testl %r8d, %r8d
je 0x767eb
movl %r12d, 0x4(%rdx)
movl %r13d, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl (%rcx), %r10d
movl $0x80000000, %ebx       # imm = 0x80000000
andl %ebx, %r10d
orl %r9d, %r10d
movl %r10d, (%rcx)
movl 0xc(%rdi), %r9d
jmp 0x767eb
movl %r15d, 0x4(%rdx)
movl $0x80000000, %eax       # imm = 0x80000000
andl (%rcx), %eax
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
orl %r14d, %eax
movl %eax, (%rcx)
xorl %eax, %eax
cmpl %r14d, 0x4(%rdx)
setbe %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq