// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_overlap_contig_dir(unsigned int, unsigned int, ma_hit_t*, All_reads*, long long, unsigned int, unsigned int)
uint32_t get_overlap_contig_dir(uint32_t v, uint32_t tn, ma_hit_t *h, All_reads *RNF, long long ctg_beg,
uint32_t p_beg, uint32_t p_end)
{
    long long qs, qe, ts, te, c_beg, c_end;

    qs = Get_qs((*h)); qe = Get_qe((*h)) - 1;
    ts = Get_ts((*h)); te = Get_te((*h)) - 1;
    if(h->rev)
    {
        ts = (long long)(Get_READ_LENGTH((*RNF), tn)) - ((long long)(Get_te((*h))) - 1) - 1;
        te = (long long)(Get_READ_LENGTH((*RNF), tn)) - (long long)(Get_ts((*h))) - 1;
    }
    ts = qs - ts;
    te = qe + ((long long)(Get_READ_LENGTH((*RNF), tn)) - te - 1);
    c_beg = ts; c_end = te;

    if(v&1)
    {
        ts = (long long)(Get_READ_LENGTH((*RNF), v>>1)) - ts - 1;
        te = (long long)(Get_READ_LENGTH((*RNF), v>>1)) - te - 1;
        c_beg = te; c_end = ts;
    }

    c_end++;
    c_beg += ctg_beg; c_end += ctg_beg;

    if((p_beg != p_end && c_beg <= p_beg && c_end >= p_end) || 
                    (p_beg == p_end && c_beg < p_beg && c_end > p_end))
    {
        return 2;
    }

    if(c_beg < p_beg) return 0;
    if(c_end > p_end) return 1;

    return 2;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0x10(%rbp), %eax
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x0, %eax
je 0xf2b80
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
subq $0x1, %rcx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0xc(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
subq -0x50(%rbp), %rcx
subq $0x1, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xf2c17
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x8(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
subq -0x48(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x8(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
subq -0x50(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x10(%rbp), %eax
je 0xf2c5b
movq -0x58(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpq %rcx, %rax
jg 0xf2c5b
movq -0x60(%rbp), %rax
movl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jge 0xf2c7b
movl -0x2c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jne 0xf2c84
movq -0x58(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpq %rcx, %rax
jge 0xf2c84
movq -0x60(%rbp), %rax
movl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jle 0xf2c84
movl $0x2, -0x4(%rbp)
jmp 0xf2cb5
movq -0x58(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpq %rcx, %rax
jge 0xf2c99
movl $0x0, -0x4(%rbp)
jmp 0xf2cb5
movq -0x60(%rbp), %rax
movl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jle 0xf2cae
movl $0x1, -0x4(%rbp)
jmp 0xf2cb5
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)