// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
ja 0x12576e
movq $-0x80000000, -0x8(%rbp) # imm = 0x80000000
jmp 0x125e0a
movq $-0x1, -0x88(%rbp)
cmpq $0x1, -0x20(%rbp)
jne 0x12578b
movq $0x2, -0x88(%rbp)
cmpq $0x2, -0x20(%rbp)
jne 0x12579d
movq $0x1, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%rbp), %rdx
shrq %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
shrq %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%rbp), %rdx
shrq %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
shrq %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
shrq %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
shrq %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x125e02
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x1258f3
movq -0xa8(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1258f3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1258f8
jmp 0x125df1
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
shrq %rax
movq -0x28(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jne 0x12592a
jmp 0x125949
leaq 0x262a5d(%rip), %rdi    # 0x38838e
leaq 0x260f85(%rip), %rsi    # 0x3868bd
movl $0x53b6, %edx           # imm = 0x53B6
leaq 0x262a77(%rip), %rcx    # 0x3883bb
callq 0x2130
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
cmpq -0x28(%rbp), %rax
jne 0x12597a
movq $0x0, -0x78(%rbp)
jmp 0x125982
movq $0x1, -0x78(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x125def
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x10(%rax)
je 0x125a12
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
je 0x125a12
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x125a17
jmp 0x125dde
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
shrq %rax
movq -0x40(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jne 0x125a64
jmp 0x125a83
leaq 0x26298c(%rip), %rdi    # 0x3883f7
leaq 0x260e4b(%rip), %rsi    # 0x3868bd
movl $0x53bb, %edx           # imm = 0x53BB
leaq 0x26293d(%rip), %rcx    # 0x3883bb
callq 0x2130
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x125aad
jmp 0x125dde
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jb 0x125b12
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
subl %ecx, %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
jmp 0x125b59
movq -0x48(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
subl %ecx, %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
cmpq -0x68(%rbp), %rax
je 0x125b6b
jmp 0x125dde
cmpq $0x0, -0x78(%rbp)
jne 0x125bec
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rcx
xorl %eax, %eax
cmpq -0x68(%rbp), %rcx
movb %al, -0xa9(%rbp)
jae 0x125bbc
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x70(%rbp), %rcx
movq -0x80(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
sete %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x125bc8
jmp 0x125bd8
jmp 0x125bca
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x125b7a
movq -0x80(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x125be7
jmp 0x125dde
jmp 0x125c6f
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rcx
xorl %eax, %eax
cmpq -0x68(%rbp), %rcx
movb %al, -0xaa(%rbp)
jae 0x125c42
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq -0x80(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
xorq $0x1, %rcx
cmpq %rcx, %rax
sete %al
movb %al, -0xaa(%rbp)
movb -0xaa(%rbp), %al
testb $0x1, %al
jne 0x125c4e
jmp 0x125c5e
jmp 0x125c50
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x125bf4
movq -0x80(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x125c6d
jmp 0x125dde
jmp 0x125c6f
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0xa8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
ja 0x125c84
jmp 0x125ca3
leaq 0x2627af(%rip), %rdi    # 0x38843a
leaq 0x260c2b(%rip), %rsi    # 0x3868bd
movl $0x53cb, %edx           # imm = 0x53CB
leaq 0x26271d(%rip), %rcx    # 0x3883bb
callq 0x2130
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0xa8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x125cc3
movq $-0x1, -0x8(%rbp)
jmp 0x125e0a
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0xa8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x125dda
movq $0x0, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x125daa
leaq 0x29f5b7(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x90(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
cmpq -0x20(%rbp), %rax
jne 0x125d50
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
leaq 0x29f579(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x90(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
cmpq -0x88(%rbp), %rax
jne 0x125d91
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x125d93
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x125cfb
movq -0x98(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jae 0x125dc4
movq $-0x1, -0x8(%rbp)
jmp 0x125e0a
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x8(%rbp)
jmp 0x125e0a
jmp 0x125ddc
jmp 0x125dde
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x12598a
jmp 0x125df1
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x125878
movq $-0x80000000, -0x8(%rbp) # imm = 0x80000000
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)