// File: chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_xy_pos(asg_t*, asg_arc_t*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned long*, unsigned char*)
inline uint64_t get_xy_pos(asg_t *read_g, asg_arc_t* t, uint32_t v_in_unitig, uint32_t w_in_unitig, 
uint32_t xUnitigLen, uint32_t yUnitigLen, uint64_t* position_index, 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 = (position_index[v_in_unitig>>1]>>32) + 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 = (position_index[v_in_unitig>>1]>>32);
        x_dir = 1;
    }
    else
    {
        fprintf(stderr, "ERROR\n");
    }
    
    if(t->v == w_in_unitig)
    {
        y_pos = (position_index[w_in_unitig>>1]>>32) + t->ol - 1;
        y_dir = 0;
    }
    else if(t->v == (w_in_unitig^1))
    {
        y_pos = (position_index[w_in_unitig>>1]>>32) + 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
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl -0x14(%rbp), %ecx
cmpq %rcx, %rax
jne 0x185a85
movq 0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x14(%rbp), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
jmp 0x185ad6
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl -0x14(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x185abc
movq 0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x24(%rbp)
movl $0x1, -0x2c(%rbp)
jmp 0x185ad4
movq 0x23e51d(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x203fe2(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
jmp 0x185ad6
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x185b17
movq 0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x185b90
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x18(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x185b76
movq 0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x18(%rbp), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
subq %rcx, %rax
movl %eax, -0x28(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x185b8e
movq 0x23e463(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x203f28(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
jmp 0x185b90
movl -0x2c(%rbp), %eax
xorl -0x30(%rbp), %eax
movb %al, %cl
movq 0x18(%rbp), %rax
movb %cl, (%rax)
movq 0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0x185bc6
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
ja 0x185bb8
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
jmp 0x185bc4
movl -0x20(%rbp), %eax
subl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x185bc6
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jb 0x185bd5
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jb 0x185be4
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl -0x24(%rbp), %eax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop