// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: cal_exact_ug_o(dedup_idx_t*, ma_utg_t*, unsigned long)
int64_t cal_exact_ug_o(dedup_idx_t *idx, ma_utg_t *u, uint64_t f)
{
    if(u->n <= 0) return INT32_MIN;
    uint64_t sv, *sa, sn, ev, *ea, en, si, ei, zn, *za, rev, k, nf = (uint64_t)-1, m, fn, nfn; ma_utg_t *z;
    if(f == FATHER) nf = MOTHER; if(f == MOTHER) nf = FATHER;
    sv = u->a[0]>>32; sa = idx->ra + idx->ridx[sv>>1]; sn = idx->ridx[(sv>>1)+1]-idx->ridx[sv>>1];
    ev = u->a[u->n-1]>>32; ea = idx->ra + idx->ridx[ev>>1]; en = idx->ridx[(ev>>1)+1] - idx->ridx[ev>>1];
    for (si = 0; si < sn; si++) {
        z = &(idx->ug->u.a[sa[si]>>32]);
        if((z->n == 0) || (z->m == 0) || (idx->ug->g->seq[sa[si]>>32].del)) continue;
        assert(((z->a[(uint32_t)sa[si]]>>32)>>1) == (sv>>1));
        if((z->a[(uint32_t)sa[si]]>>32) == sv) rev = 0;
        else rev = 1;
        for (ei = 0; ei < en; ei++) {
            if((idx->ug->u.a[ea[ei]>>32].n == 0) || (idx->ug->u.a[ea[ei]>>32].m == 0) || (idx->ug->g->seq[ea[ei]>>32].del)) continue;
            assert(((idx->ug->u.a[ea[ei]>>32].a[(uint32_t)ea[ei]]>>32)>>1) == (ev>>1));
            if((sa[si]>>32) != (ea[ei]>>32)) continue;///not the same uid            
            if(((uint32_t)sa[si]) >= ((uint32_t)ea[ei])) {
                zn = ((uint32_t)sa[si]) - ((uint32_t)ea[ei]) + 1; za = z->a + ((uint32_t)ea[ei]);
            } else {
                zn = ((uint32_t)ea[ei]) - ((uint32_t)sa[si]) + 1; za = z->a + ((uint32_t)sa[si]);
            }
            if(u->n != zn) continue;
            if(!rev) {
                for (k = 0; (k < zn) && ((u->a[k]>>32) == ((za[k]>>32))); k++);
                if(k < zn) continue;
            } else {
                for (k = 0; (k < zn) && ((u->a[k]>>32) == (((uint64_t)(za[zn-k-1]>>32))^1)); k++);
                if(k < zn) continue;
            }
            
            assert(u->n <= z->n);
            if(u->n < z->n) {
                return -1;///delete u
            } else if(u->n == z->n) {
                for (m = fn = nfn = 0; m < u->n; m++) {
                    if(R_INF.trio_flag[u->a[m]>>33] == f) fn++;
                    if(R_INF.trio_flag[u->a[m]>>33] == nf) nfn++;
                }
                if(fn < nfn) return -1;///delete u
                else return sa[si]>>32;///delete z
            }
        }
    }
    return INT32_MIN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl 0x10(%rsi), %r8d
movq $-0x80000000, %rax      # imm = 0x80000000
testq %r8, %r8
je 0xda5aa
xorl %ecx, %ecx
cmpq $0x1, %rdx
sete %cl
leaq (%rcx,%rcx,2), %rcx
decq %rcx
cmpq $0x2, %rdx
movl $0x1, %r9d
cmovneq %rcx, %r9
movq 0x18(%rsi), %rbx
movq (%rbx), %rcx
movq 0x10(%rdi), %rsi
movq %rcx, 0x38(%rsp)
movq %rcx, %r10
shrq $0x21, %r10
movl (%rsi,%r10,4), %ecx
movq %r10, 0x50(%rsp)
movl 0x4(%rsi,%r10,4), %r11d
subl %ecx, %r11d
je 0xda5aa
movq %r9, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x18(%rdi), %rdx
leaq (%rdx,%rcx,8), %rax
movq %rax, 0x68(%rsp)
movq %r8, 0x18(%rsp)
leal -0x1(%r8), %ecx
movq %rbx, 0x8(%rsp)
movq (%rbx,%rcx,8), %rax
shrq $0x21, %rax
movl (%rsi,%rax,4), %ecx
leaq (%rdx,%rcx,8), %r12
movq %rax, 0x60(%rsp)
movl 0x4(%rsi,%rax,4), %eax
movl %eax, 0x14(%rsp)
movl %eax, %r13d
movq %rcx, 0x40(%rsp)
subl %ecx, %r13d
movq (%rdi), %rax
movq %rax, 0x58(%rsp)
movq 0x10(%rax), %r9
cmpl $0x1, %r13d
adcl $0x0, %r13d
cmpl $0x1, %r11d
adcl $0x0, %r11d
xorl %r15d, %r15d
movq 0x8(%rsp), %r14
movq 0x68(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, %rdi
shrq $0x20, %rdi
leaq (%rdi,%rdi,4), %rcx
movl 0x10(%r9,%rcx,8), %ebp
testl %ebp, %ebp
je 0xda51d
leaq (%r9,%rcx,8), %rcx
cmpl $0x0, 0xc(%rcx)
je 0xda51d
movq 0x58(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq 0x20(%rdx), %rdx
movq %rdx, 0x70(%rsp)
cmpl $0x0, (%rdx,%rdi,8)
js 0xda51d
movq 0x18(%rcx), %rdx
movl %eax, %ecx
movq %rdx, 0x20(%rsp)
movq (%rdx,%rcx,8), %r10
movq %r10, %rdx
shrq $0x21, %rdx
cmpl 0x50(%rsp), %edx
jne 0xda5d8
movl 0x14(%rsp), %edx
cmpl 0x40(%rsp), %edx
je 0xda51d
movq 0x20(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, 0x48(%rsp)
xorq 0x38(%rsp), %r10
shrq $0x20, %r10
xorl %r8d, %r8d
movq (%r12,%r8,8), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,4), %rsi
cmpl $0x0, 0x10(%r9,%rsi,8)
je 0xda511
leaq (%r9,%rsi,8), %rsi
cmpl $0x0, 0xc(%rsi)
je 0xda511
movq 0x70(%rsp), %rbx
cmpl $0x0, (%rbx,%rdx,8)
js 0xda511
movq 0x18(%rsi), %rbx
movl %ecx, %esi
movq (%rbx,%rsi,8), %rbx
shrq $0x21, %rbx
cmpl 0x60(%rsp), %ebx
jne 0xda5b9
cmpl %edx, %edi
jne 0xda511
movq %rax, %rbx
subq %rcx, %rbx
movq %rcx, %rdx
subq %rax, %rdx
cmpl %ecx, %eax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rsi,8), %rcx
cmovaeq %rbx, %rdx
cmovbq 0x48(%rsp), %rcx
incq %rdx
cmpl %edx, 0x18(%rsp)
jne 0xda511
movl %edx, %edx
testq %r10, %r10
jne 0xda4eb
testq %rdx, %rdx
je 0xda532
xorl %esi, %esi
movq (%rcx,%rsi,8), %rbx
xorq (%r14,%rsi,8), %rbx
shrq $0x20, %rbx
jne 0xda511
incq %rsi
cmpq %rsi, %rdx
jne 0xda4d3
jmp 0xda532
movq 0x8(%rsp), %rsi
testq %rdx, %rdx
je 0xda532
movq -0x8(%rcx,%rdx,8), %rbx
xorq (%rsi), %rbx
shrq $0x20, %rbx
cmpl $0x1, %ebx
jne 0xda511
addq $0x8, %rsi
decq %rdx
jne 0xda4f5
jmp 0xda532
incq %r8
cmpq %r13, %r8
jne 0xda447
incq %r15
cmpq %r11, %r15
jne 0xda3b4
movq $-0x80000000, %rax      # imm = 0x80000000
jmp 0xda5aa
movq 0x18(%rsp), %rbx
cmpl %ebp, %ebx
ja 0xda5f7
movq $-0x1, %rax
cmpl %ebp, %ebx
jb 0xda5aa
leaq 0x1bbcdf(%rip), %rax    # 0x296230
movq 0x28(%rax), %rcx
xorl %eax, %eax
xorl %edx, %edx
xorl %r8d, %r8d
movq 0x30(%rsp), %r10
movq 0x28(%rsp), %r14
movq 0x8(%rsp), %r11
movq (%r11,%r8,8), %rsi
shrq $0x21, %rsi
movzbl (%rcx,%rsi), %esi
xorl %r9d, %r9d
cmpq %r10, %rsi
sete %r9b
addq %r9, %rdx
xorl %r9d, %r9d
cmpq %rsi, %r14
sete %r9b
addq %r9, %rax
incq %r8
cmpq %r8, %rbx
jne 0xda56b
cmpq %rax, %rdx
movq $-0x1, %rax
cmovbq %rax, %rdi
movq %rdi, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15d24c(%rip), %rdi    # 0x23780c
leaq 0x15b8ca(%rip), %rsi    # 0x235e91
leaq 0x15d202(%rip), %rcx    # 0x2377d0
movl $0x53bb, %edx           # imm = 0x53BB
callq 0x2110
leaq 0x15d1c4(%rip), %rdi    # 0x2377a3
leaq 0x15b8ab(%rip), %rsi    # 0x235e91
leaq 0x15d1e3(%rip), %rcx    # 0x2377d0
movl $0x53b6, %edx           # imm = 0x53B6
callq 0x2110
leaq 0x15d251(%rip), %rdi    # 0x23784f
leaq 0x15b88c(%rip), %rsi    # 0x235e91
leaq 0x15d1c4(%rip), %rcx    # 0x2377d0
movl $0x53cb, %edx           # imm = 0x53CB
callq 0x2110