// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: push_LCA_edges_rev(hc_edge*, hc_edge*, long long, long long, long long, unsigned int, unsigned int, unsigned long*, unsigned long*)
void push_LCA_edges_rev(hc_edge *hx, hc_edge *hy, 
long long xLen, long long yLen, long long rLen, 
uint32_t v, uint32_t w, uint64_t *e0, uint64_t *e1)
{
    long long x_beg, x_end, y_beg, y_end, dx, dy;
    uint64_t d, rev;
    dx = (hx->dis>>3); 
    if((hx->dis&(uint64_t)2))
    {
        x_beg = rLen - dx - 1; x_end = x_beg + xLen - 1;
    }
    else
    {
        x_end = dx; x_beg = x_end - xLen + 1;
    } 
    
    dy = (hy->dis>>3);
    if((hy->dis&(uint64_t)2))
    {
        y_beg = rLen - dy - 1; y_end = y_beg + yLen - 1;
    } 
    else
    {
        y_end = dy; y_beg = y_end - yLen + 1;
    }

    long long ovlp = ((MIN(x_end, y_end) >= MAX(x_beg, y_beg))? 
                                    MIN(x_end, y_end) - MAX(x_beg, y_beg) + 1 : 0);
    if(ovlp != xLen && ovlp != yLen)
    {
        d = MAX(x_end, y_end) - MIN(x_beg, y_beg) + 1;
        if(x_end >= y_end) rev = 1;
        else rev = 0;

        (*e0) = d;
        (*e0) <<= 1;
        (*e0) += 1;
        (*e0) <<= 1;
        (*e0) += ((v&1)^rev);//s-direction
        (*e0) <<= 1;
        (*e0) += ((w&1)^rev);//e-direction

        rev ^= 1;
        (*e1) = d;
        (*e1) <<= 1;
        (*e1) += 1;
        (*e1) <<= 1;
        (*e1) += ((w&1)^rev);//s-direction
        (*e1) <<= 1;
        (*e1) += ((v&1)^rev);//e-direction
    }
    else
    {
        if(xLen >= yLen) d = (x_beg + 1) + (y_end - y_beg + 1);
        else d = (x_end - x_beg + 1) + (yLen - y_end - 1);
        (*e0) = d;
        (*e0) <<= 1;
        (*e0) += 1;
        (*e0) <<= 1;
        (*e0) += (v&1);//s-direction
        (*e0) <<= 1;
        (*e0) += (w&1);//e-direction

        if(xLen >= yLen) d = (y_end - y_beg + 1) + (xLen - x_end - 1);
        else d = (y_beg + 1) + (x_end - x_beg + 1);
        (*e1) = d;
        (*e1) <<= 1;
        (*e1) += 1;
        (*e1) <<= 1;
        (*e1) += (w&1);//s-direction
        (*e1) <<= 1;
        (*e1) += (v&1);//e-direction
    }
}

// Assembly:
movq 0x10(%rdi), %rax
movq %rax, %rdi
shrq $0x3, %rdi
testb $0x2, %al
jne 0x13d967
movq %rdi, %r10
subq %rdx, %r10
incq %r10
jmp 0x13d977
notq %rdi
movq %rdi, %r10
addq %r8, %r10
leaq (%rdx,%r10), %rdi
decq %rdi
movq 0x10(%rsi), %rsi
movq %rsi, %rax
shrq $0x3, %rax
testb $0x2, %sil
jne 0x13d993
movq %rax, %r11
subq %rcx, %r11
incq %r11
jmp 0x13d9a3
notq %rax
movq %rax, %r11
addq %r8, %r11
leaq (%rcx,%r11), %rax
decq %rax
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rbx
movl 0x30(%rsp), %r8d
cmpq %rax, %rdi
movq %rax, %r14
cmovlq %rdi, %r14
cmpq %r11, %r10
movq %r11, %r15
cmovgq %r10, %r15
xorl %r12d, %r12d
subq %r15, %r14
leaq 0x1(%r14), %r14
cmovgeq %r14, %r12
cmpq %rdx, %r12
sete %bpl
cmpq %rcx, %r12
sete %r14b
orb %bpl, %r14b
je 0x13da00
cmpq %rcx, %rdx
jge 0x13da51
leaq (%rcx,%rdi), %r14
subq %r10, %r14
subq %rax, %r14
jmp 0x13da5c
xorl %ecx, %ecx
cmpq %rax, %rdi
cmovgq %rdi, %rax
setge %cl
cmpq %r11, %r10
cmovlq %r10, %r11
subq %r11, %rax
andl $0x1, %r9d
movq %rcx, %rdx
xorq %r9, %rdx
leaq (%rdx,%rax,4), %rdx
addq $0x6, %rdx
andl $0x1, %r8d
movq %rcx, %rdi
xorq %r8, %rdi
leaq (%rdi,%rdx,2), %rdx
movq %rdx, (%rbx)
xorq $0x1, %rcx
xorq %rcx, %r8
leaq (%r8,%rax,4), %rax
addq $0x6, %rax
xorq %r9, %rcx
leaq (%rcx,%rax,2), %rax
jmp 0x13da9f
leaq (%r10,%rax), %r14
subq %r11, %r14
addq $0x2, %r14
andl $0x1, %r9d
leaq (%r9,%r9), %r15
andl $0x1, %r8d
leaq (%r15,%r14,8), %r14
addq %r8, %r14
addq $0x4, %r14
movq %r14, (%rbx)
cmpq %rcx, %rdx
jge 0x13da88
subq %r10, %rdi
leaq (%rdi,%r11), %rax
addq $0x2, %rax
jmp 0x13da91
addq %rdx, %rax
addq %r11, %rdi
subq %rdi, %rax
addq %r8, %r8
leaq (%r8,%rax,8), %rax
addq %r9, %rax
addq $0x4, %rax
movq %rax, (%rsi)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq