// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_base_boundary_advance(R_to_U*, ma_hit_t_alloc*, ma_sub_t*, asg_t*, unsigned long*, int, int, ma_utg_t*, ma_utg_t*, unsigned int, unsigned int, long long, long long, long long, long long, unsigned int, kvec_asg_arc_t_offset*, kvec_t_i32_warp*, kvec_t_i32_warp*, unsigned int*, unsigned int*, unsigned int*, unsigned int*)
void get_base_boundary_advance(R_to_U* ruIndex, ma_hit_t_alloc* reverse_sources, ma_sub_t *coverage_cut, 
asg_t *read_g, uint64_t* position_index, int max_hang, int min_ovlp, ma_utg_t *xReads, ma_utg_t *yReads,
uint32_t xUid, uint32_t yUid, long long xBegIndex, long long xEndIndex, long long yBegIndex, long long yEndIndex, 
uint32_t rev, kvec_asg_arc_t_offset* u_buffer, kvec_t_i32_warp* tailIndex, kvec_t_i32_warp* prevIndex,
uint32_t* xBeg, uint32_t* xEnd, uint32_t* yBeg, uint32_t* yEnd)
{
    long long offset;
    long long new_xBeg, new_yBeg, new_xEnd, new_yEnd;
    long long new_xIdxBeg, new_yIdxBeg, new_xIdxEnd, new_yIdxEnd;

    (*xBeg) = (*xEnd) = (*yBeg) = (*yEnd) = (uint32_t)-1;
    if(!get_base_boundary_chain(ruIndex, reverse_sources, coverage_cut, read_g, position_index, 
    max_hang, min_ovlp, xReads, yReads, xUid, yUid, xBegIndex, xEndIndex, yBegIndex, yEndIndex, 
    rev, u_buffer, tailIndex, prevIndex))
    {
        return;
    }
    ///base
    new_xBeg = Get_xOff(u_buffer->a.a[tailIndex->a.a[0]].Off);
    new_yBeg = Get_yOff(u_buffer->a.a[tailIndex->a.a[0]].Off);
    new_xEnd = Get_xOff(u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].Off);
    new_yEnd = Get_yOff(u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].Off);

    if(new_xBeg > new_xEnd || new_yBeg > new_yEnd) return;
    
    classify_hap_overlap(new_xBeg, new_xEnd, xReads->len, new_yBeg, new_yEnd, yReads->len, 
                                                        &new_xBeg, &new_xEnd, &new_yBeg, &new_yEnd);

    if(rev) 
    {
        new_yBeg = yReads->len - new_yBeg - 1;
        new_yEnd = yReads->len - new_yEnd - 1;
        offset = new_yBeg; new_yBeg = new_yEnd; new_yEnd = offset;
    }
    ///idx
    get_idx_by_base(xReads, read_g, new_xBeg, new_xEnd, &new_xIdxBeg, &new_xIdxEnd);
    get_idx_by_base(yReads, read_g, new_yBeg, new_yEnd, &new_yIdxBeg, &new_yIdxEnd);
    if(new_xIdxBeg == -1 || new_xIdxEnd == -1 || new_yIdxBeg == -1 || new_yIdxEnd == -1) return;
    
    if(!get_base_boundary_chain(ruIndex, reverse_sources, coverage_cut, read_g, position_index, 
    max_hang, min_ovlp, xReads, yReads, xUid, yUid, new_xIdxBeg, new_xIdxEnd, new_yIdxBeg, 
    new_yIdxEnd, rev, u_buffer, tailIndex, prevIndex))
    {
        return;
    }

    (*xBeg) = Get_xOff(u_buffer->a.a[tailIndex->a.a[0]].Off);
    (*yBeg) = Get_yOff(u_buffer->a.a[tailIndex->a.a[0]].Off);
    (*xEnd) = Get_xOff(u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].Off);
    (*yEnd) = Get_yOff(u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].Off);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r15
movq 0x120(%rsp), %rcx
movq 0x118(%rsp), %r12
movq 0x110(%rsp), %r14
movq 0x108(%rsp), %rbp
movq 0x100(%rsp), %r13
movq 0xf8(%rsp), %rbx
movq 0xf0(%rsp), %r10
movl 0xe8(%rsp), %r11d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%rcx)
movl %eax, (%r12)
movl %eax, (%r14)
movl %eax, (%rbp)
movl 0xc0(%rsp), %ebp
movups 0xc8(%rsp), %xmm0
movups 0xd8(%rsp), %xmm1
movl 0xb8(%rsp), %r14d
movq 0xb0(%rsp), %r12
movq 0xa8(%rsp), %rcx
movl 0xa0(%rsp), %eax
subq $0x70, %rsp
movq %r13, 0x60(%rsp)
movq %rbx, 0x58(%rsp)
movq %r10, 0x50(%rsp)
movl %r11d, 0x48(%rsp)
movups %xmm1, 0x38(%rsp)
movups %xmm0, 0x28(%rsp)
movl %ebp, 0x20(%rsp)
movl %r14d, 0x18(%rsp)
movq %r12, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movl %eax, (%rsp)
movq %rdi, 0x98(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0xa8(%rsp)
movq %r15, %rcx
movq %r8, 0xb0(%rsp)
movl %r9d, 0x74(%rsp)
callq 0x10e5a9
addq $0x70, %rsp
testl %eax, %eax
je 0x10f0fe
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbx), %rdx
movslq (%rdx), %rcx
leaq (%rcx,%rcx,4), %rcx
movq 0x18(%rax,%rcx,8), %rdi
movl %edi, %ecx
shrq $0x20, %rdi
movq %rdi, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq (%rbx), %rsi
movslq -0x4(%rdx,%rsi,4), %rdx
leaq (%rdx,%rdx,4), %rdx
movq 0x18(%rax,%rdx,8), %rsi
movl %esi, %r8d
shrq $0x20, %rsi
movq %rsi, 0x10(%rsp)
movq %r8, 0x8(%rsp)
cmpq %rsi, %rdi
ja 0x10f0fe
cmpl %r8d, %ecx
ja 0x10f0fe
movq 0xa8(%rsp), %rax
movl (%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movq 0xb0(%rsp), %r9
movl (%r9), %r14d
andq %rax, %r14
leaq 0x8(%rsp), %r12
leaq 0x18(%rsp), %rbx
leaq 0x10(%rsp), %rax
leaq 0x20(%rsp), %r10
movq %r14, %r9
pushq %r12
pushq %rbx
pushq %rax
pushq %r10
callq 0x10a6e3
addq $0x20, %rsp
movq (%rbx), %rbx
movq (%r12), %r13
movl 0xe8(%rsp), %eax
testl %eax, %eax
je 0x10ef88
notq %rbx
addq %r14, %rbx
notq %r13
movq %r13, %rax
addq %r14, %rax
movq %rax, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %r13
movq %rax, %rbx
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
leaq 0x60(%rsp), %r14
leaq 0x48(%rsp), %r9
movq 0xa8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %r8
callq 0x10e52e
leaq 0x58(%rsp), %rbp
leaq 0x50(%rsp), %r12
movq 0xb0(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq %rbp, %r8
movq %r12, %r9
callq 0x10e52e
movq (%r14), %rax
cmpq $-0x1, %rax
sete %cl
leaq 0x48(%rsp), %rdx
movq (%rdx), %r10
cmpq $-0x1, %r10
sete %dl
orb %cl, %dl
movq (%rbp), %r11
cmpq $-0x1, %r11
sete %cl
movq (%r12), %rbx
cmpq $-0x1, %rbx
sete %sil
orb %cl, %sil
orb %dl, %sil
movq 0x120(%rsp), %r14
movq 0x110(%rsp), %r12
movq 0x118(%rsp), %r13
movq 0xf8(%rsp), %rbp
jne 0x10f0fe
subq $0x8, %rsp
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %r15, %rcx
movq 0x48(%rsp), %r8
movl 0xc(%rsp), %r9d
pushq 0x108(%rsp)
pushq %rbp
pushq 0x108(%rsp)
movl 0x108(%rsp), %r15d
pushq %r15
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
movl 0x108(%rsp), %eax
pushq %rax
movl 0x108(%rsp), %eax
pushq %rax
pushq 0x108(%rsp)
pushq 0x108(%rsp)
movl 0x108(%rsp), %eax
pushq %rax
callq 0x10e5a9
addq $0x70, %rsp
testl %eax, %eax
je 0x10f0fe
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rcx
movslq (%rcx), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x1c(%rax,%rdx,8), %edx
movq 0x108(%rsp), %rsi
movl %edx, (%rsi)
movslq (%rcx), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x18(%rax,%rdx,8), %edx
movl %edx, (%r13)
movq (%rbp), %rdx
movslq -0x4(%rcx,%rdx,4), %rsi
leaq (%rsi,%rsi,4), %rsi
movl 0x1c(%rax,%rsi,8), %esi
movl %esi, (%r12)
movslq -0x4(%rcx,%rdx,4), %rcx
leaq (%rcx,%rcx,4), %rcx
movl 0x18(%rax,%rcx,8), %eax
movl %eax, (%r14)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq