// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_contig_overlap_interval(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*)
uint32_t get_contig_overlap_interval(uint32_t is_reverse, 
uint32_t q_beg, uint32_t q_end, uint32_t qLen, uint32_t t_beg, uint32_t t_end, uint32_t tLen, 
uint32_t* r_q_beg, uint32_t* r_q_end, uint32_t* r_t_beg, uint32_t* r_t_end)
{
    uint32_t k;
    (*r_q_beg) = (*r_q_end) = (*r_t_beg) = (*r_t_end) = (uint32_t)-1;
    if(q_end >= qLen || t_end >= tLen) return 0;
    if(q_beg >= qLen || t_beg >= tLen) return 0;

    if(is_reverse)
    {
        ///k = q_beg; q_beg = q_end; q_end = k;
        ///q_beg = qLen - q_beg - 1; q_end = qLen - q_end - 1; k = q_beg; q_beg = q_end; q_end = k;
        ///k = t_beg; t_beg = t_end; t_end = k;
        t_beg = tLen - t_beg - 1; t_end = tLen - t_end - 1; k = t_beg; t_beg = t_end; t_end = k;
    }




    if(q_beg <= t_beg)
    {
        t_beg = t_beg - q_beg; q_beg = 0;
    }
    else
    {
        q_beg = q_beg - t_beg; t_beg = 0;
    }

    uint32_t q_right_length = qLen - q_end - 1;
    uint32_t t_right_length = tLen - t_end - 1;
    if(q_right_length <= t_right_length)
    {
        q_end = qLen - 1; t_end = t_end + q_right_length;
    }
    else
    {
        t_end = tLen - 1; q_end = q_end + t_right_length;
    }

    if(is_reverse)
    {
        ///q_beg = qLen - q_beg - 1; q_end = qLen - q_end - 1; k = q_beg; q_beg = q_end; q_end = k;
        t_beg = tLen - t_beg - 1; t_end = tLen - t_end - 1; k = t_beg; t_beg = t_end; t_end = k;
    }

    (*r_q_beg) = q_beg; (*r_q_end) = q_end;
    (*r_t_beg) = t_beg; (*r_t_end) = t_end;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movq 0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x142ce3
movl -0x1c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jb 0x142cef
movl $0x0, -0x4(%rbp)
jmp 0x142e06
movl -0xc(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x142cff
movl -0x18(%rbp), %eax
cmpl 0x10(%rbp), %eax
jb 0x142d0b
movl $0x0, -0x4(%rbp)
jmp 0x142e06
cmpl $0x0, -0x8(%rbp)
je 0x142d3b
movl 0x10(%rbp), %eax
subl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
movl 0x10(%rbp), %eax
subl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x18(%rbp), %eax
ja 0x142d55
movl -0x18(%rbp), %eax
subl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0xc(%rbp)
jmp 0x142d65
movl -0xc(%rbp), %eax
subl -0x18(%rbp), %eax
movl %eax, -0xc(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x14(%rbp), %eax
subl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
movl 0x10(%rbp), %eax
subl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
ja 0x142d99
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x1c(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x142dab
movl 0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x10(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x8(%rbp)
je 0x142ddb
movl 0x10(%rbp), %eax
subl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
movl 0x10(%rbp), %eax
subl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0xc(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x18(%rbp), %ecx
movq 0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq 0x30(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)