// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
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 0x173753
movl -0x1c(%rbp), %eax
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
addl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
jmp 0x173794
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl -0x14(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x17377a
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl $0x1, -0x2c(%rbp)
jmp 0x173792
movq 0x25085f(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x216324(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
jmp 0x173794
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x1737c1
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x173824
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x18(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x17380a
movl -0x20(%rbp), %eax
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
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
subl %ecx, %eax
movl %eax, -0x28(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x173822
movq 0x2507cf(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x216294(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
jmp 0x173824
movl -0x2c(%rbp), %eax
xorl -0x30(%rbp), %eax
movb %al, %cl
movq 0x20(%rbp), %rax
movb %cl, (%rax)
movq 0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0x17385a
movl 0x18(%rbp), %eax
cmpl -0x28(%rbp), %eax
ja 0x17384c
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
jmp 0x173858
movl 0x18(%rbp), %eax
subl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x17385a
movl -0x24(%rbp), %eax
cmpl 0x10(%rbp), %eax
jb 0x173869
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movl -0x28(%rbp), %eax
cmpl 0x18(%rbp), %eax
jb 0x173878
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
nopw %cs:(%rax,%rax)