// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_xy_pos_by_pos(asg_t*, asg_arc_t*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned char*)
uint64_t get_xy_pos_by_pos(asg_t *read_g, asg_arc_t* t, uint32_t v_in_unitig, uint32_t w_in_unitig, 
uint32_t v_in_pos, uint32_t w_in_pos, uint32_t xUnitigLen, uint32_t yUnitigLen, uint8_t* rev)
{
    uint32_t x_pos, y_pos, x_dir = 0, y_dir = 0;
    uint64_t tmp;
    x_pos = y_pos = (uint32_t)-1;
    if((t->ul>>32)==v_in_unitig)///end pos
    {
        x_pos = v_in_pos + read_g->seq[v_in_unitig>>1].len - 1;
        x_dir = 0;
    }
    else if((t->ul>>32)==(v_in_unitig^1))///start pos
    {
        x_pos = v_in_pos;
        x_dir = 1;
    }
    else
    {
        fprintf(stderr, "ERROR\n");
    }
    
    if(t->v == w_in_unitig)
    {
        y_pos = w_in_pos + t->ol - 1;
        y_dir = 0;
    }
    else if(t->v == (w_in_unitig^1))
    {
        y_pos = w_in_pos + read_g->seq[w_in_unitig>>1].len - t->ol;
        y_dir = 1;
    }
    else
    {
        fprintf(stderr, "ERROR\n");
    }

    (*rev) = x_dir^y_dir;
    if((*rev))
    {
        if(yUnitigLen <= y_pos)
        {
            y_pos = (uint32_t)-1;
        }
        else
        {
            y_pos = yUnitigLen - y_pos - 1;
        }
    } 

    if(x_pos>=xUnitigLen) x_pos = (uint32_t)-1;
    if(y_pos>=yUnitigLen) y_pos = (uint32_t)-1;
    
    tmp = x_pos; tmp = tmp << 32; tmp = tmp | y_pos;
    return tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r14d
movl %r8d, %ebx
movl %ecx, %r12d
movq %rsi, %r15
movq %rdi, %r13
movq (%rsi), %rax
shrq $0x20, %rax
movl %edx, %ecx
cmpq %rcx, %rax
jne 0xc9df0
movq 0x20(%r13), %rax
shrl %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl (%rax,%rdx,8), %ecx
addl %ecx, %ebx
decl %ebx
xorl %ebp, %ebp
jmp 0xc9dfe
xorl $0x1, %edx
movb $0x1, %bpl
cmpl %edx, %eax
jne 0xc9e8e
movq 0x50(%rsp), %r8
movl 0x8(%r15), %eax
cmpl %r12d, %eax
jne 0xc9e1f
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0xc(%r15), %eax
leal (%r14,%rax), %ecx
decl %ecx
xorl %esi, %esi
jmp 0xc9e49
xorl %r12d, %eax
cmpl $0x1, %eax
jne 0xc9eb2
movq 0x20(%r13), %rax
shrl %r12d
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl (%rax,%r12,8), %ecx
andl %edx, %ecx
addl %r14d, %ecx
andl 0xc(%r15), %edx
subl %edx, %ecx
movb $0x1, %sil
movl 0x48(%rsp), %edx
movl 0x40(%rsp), %eax
movl %esi, %edi
xorb %bpl, %dil
movb %dil, (%r8)
cmpb %sil, %bpl
je 0xc9e6b
cmpl %edx, %ecx
jae 0xc9e68
notl %ecx
addl %edx, %ecx
jmp 0xc9e6b
pushq $-0x1
popq %rcx
cmpl %eax, %ebx
pushq $-0x1
popq %rax
cmovael %eax, %ebx
cmpl %edx, %ecx
cmovbl %ecx, %eax
shlq $0x20, %rbx
orq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rbx
movq 0x189148(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x120ee2(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xc9dec
movq 0x189127(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x120ec1(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
movq %r8, %r14
callq 0x2410
movq %r14, %r8
pushq $-0x1
popq %rcx
jmp 0xc9e1b