// File: chhylp123[P]hifiasm/Correct.cpp
// Function: cal_no_bd_coor(ul_ov_t*, ul_ov_t*, idx_emask_t*, long)
uint64_t cal_no_bd_coor(ul_ov_t *in, ul_ov_t *ou, idx_emask_t *mm, int64_t bd)
{
    int64_t qs, qe, ts, te; emask_t *z;
    qs = in->qs; qe = in->qe; ts = in->ts; te = in->te;
    if(in->sec != ((uint32_t)(0x3fffffff))) {///might be an end mask; no need shrink
        if((in->sec < mm->a[in->qn].n) && (in->tn == mm->a[in->qn].a[in->sec].tn) && (in->rev == mm->a[in->qn].a[in->sec].rev) && 
            (in->qs == mm->a[in->qn].a[in->sec].qs) && (in->qe == mm->a[in->qn].a[in->sec].qe) && 
                (in->ts == mm->a[in->qn].a[in->sec].ts) && (in->te == mm->a[in->qn].a[in->sec].te)) {
            z = &(mm->a[in->qn].a[in->sec]); assert(z->el != ((uint32_t)-1));
            if(z->dir == 0) {
                qe -= (z->el>>1); 
                if(in->rev) ts += (z->el>>1);
                else te -= (z->el>>1);
            } else {
                qs += (z->el>>1); 
                if(in->rev) te -= (z->el>>1);
                else ts += (z->el>>1);
            }
            // fprintf(stderr, "+[M::%s]\tz->dir::%u\tz->el::%u\tq::[%ld,\t%ld)\tt::[%ld,\t%ld)\n", __func__, z->dir, z->el, qs, qe, ts, te); 
        } else {
            assert((in->sec < mm->a[in->tn].n) && (in->qn == mm->a[in->tn].a[in->sec].tn) && (in->rev == mm->a[in->tn].a[in->sec].rev) && 
                (in->qs == mm->a[in->tn].a[in->sec].ts) && (in->qe == mm->a[in->tn].a[in->sec].te) && 
                (in->ts == mm->a[in->tn].a[in->sec].qs) && (in->te == mm->a[in->tn].a[in->sec].qe));
            z = &(mm->a[in->tn].a[in->sec]); assert(z->el != ((uint32_t)-1));
            if(z->dir == 1) {
                qe -= (z->el>>1); 
                if(in->rev) ts += (z->el>>1);
                else te -= (z->el>>1);
            } else {
                qs += (z->el>>1); 
                if(in->rev) te -= (z->el>>1);
                else ts += (z->el>>1);
            }
            // fprintf(stderr, "-[M::%s]\tz->dir::%u\tz->el::%u\tq::[%ld,\t%ld)\tt::[%ld,\t%ld)\n", __func__, z->dir, z->el, qs, qe, ts, te); 
        }
    } else {///shrink anyway
        qs += bd; qe -= bd; ts += bd; te -= bd;
    }
    if(qe > qs && te > ts) {
        (*ou) = (*in);
        ou->qs = qs; ou->qe = qe; ou->ts = ts; ou->te = te;
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
je 0x7e019
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jae 0x7dd18
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0x7dd18
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movb 0x1c(%rcx), %cl
shrb $0x7, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x7dd18
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jne 0x7dd18
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jne 0x7dd18
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
jne 0x7dd18
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
jne 0x7dd18
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
je 0x7dc3c
jmp 0x7dc5b
leaq 0x307456(%rip), %rdi    # 0x385099
leaq 0x3046d1(%rip), %rsi    # 0x38231b
movl $0x506f, %edx           # imm = 0x506F
leaq 0x30745b(%rip), %rcx    # 0x3850b1
callq 0x2130
movq -0x50(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x1f, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x7dcc2
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x7dca8
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x7dcc0
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x7dd13
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x7dcfe
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x7dd11
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x7dd13
jmp 0x7e017
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpq 0x8(%rdx), %rcx
movb %al, -0x51(%rbp)
jae 0x7ded6
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0xc(%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
shlq $0x5, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x51(%rbp)
jne 0x7ded6
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
shrl $0x1f, %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0xc(%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rax
movb 0x1c(%rax), %al
shrb $0x7, %al
movzbl %al, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x51(%rbp)
jne 0x7ded6
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0xc(%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
shlq $0x5, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpl 0x14(%rdx), %ecx
movb %al, -0x51(%rbp)
jne 0x7ded6
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0xc(%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
shlq $0x5, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpl 0x18(%rdx), %ecx
movb %al, -0x51(%rbp)
jne 0x7ded6
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0xc(%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
shlq $0x5, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpl 0xc(%rdx), %ecx
movb %al, -0x51(%rbp)
jne 0x7ded6
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0xc(%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
sete %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x7dedf
jmp 0x7dee1
jmp 0x7df00
leaq 0x30720f(%rip), %rdi    # 0x3850f7
leaq 0x30442c(%rip), %rsi    # 0x38231b
movl $0x507d, %edx           # imm = 0x507D
leaq 0x3071b6(%rip), %rcx    # 0x3850b1
callq 0x2130
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
je 0x7df3e
jmp 0x7df5d
leaq 0x307154(%rip), %rdi    # 0x385099
leaq 0x3043cf(%rip), %rsi    # 0x38231b
movl $0x507e, %edx           # imm = 0x507E
leaq 0x307159(%rip), %rcx    # 0x3850b1
callq 0x2130
movq -0x50(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x1f, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x7dfc4
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x7dfaa
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x7dfc2
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x7e015
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x7e000
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x7e013
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x7e015
jmp 0x7e017
jmp 0x7e04f
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jle 0x7e0c5
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x7e0c5
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq $0x1, -0x8(%rbp)
jmp 0x7e0cd
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)