// File: /workspace/github_cpp_makefile_star2_O2/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), %rax
movq 0x118(%rsp), %r14
movq 0x110(%rsp), %rcx
movq 0x108(%rsp), %r12
movq 0x100(%rsp), %r13
movq 0xf8(%rsp), %rbx
movq 0xf0(%rsp), %rbp
movl 0xe8(%rsp), %r11d
orl $-0x1, (%rax)
movl 0xc0(%rsp), %r10d
orl $-0x1, (%r14)
movups 0xc8(%rsp), %xmm0
orl $-0x1, (%rcx)
movups 0xd8(%rsp), %xmm1
orl $-0x1, (%r12)
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 %rbp, 0x50(%rsp)
movl %r11d, 0x48(%rsp)
movups %xmm1, 0x38(%rsp)
movups %xmm0, 0x28(%rsp)
movl %r10d, 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 0xcaf57
addq $0x70, %rsp
testl %eax, %eax
je 0xcb6f4
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbx), %rdx
movslq (%rdx), %rcx
imulq $0x28, %rcx, %rcx
movq 0x18(%rax,%rcx), %rdi
movl %edi, %ecx
shrq $0x20, %rdi
movq %rdi, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq (%rbx), %rsi
movslq -0x4(%rdx,%rsi,4), %rdx
imulq $0x28, %rdx, %rdx
movq 0x18(%rax,%rdx), %rsi
movl %esi, %r8d
shrq $0x20, %rsi
movq %rsi, 0x10(%rsp)
movq %r8, 0x8(%rsp)
cmpq %rsi, %rdi
ja 0xcb6f4
cmpl %r8d, %ecx
ja 0xcb6f4
movq 0xa8(%rsp), %rax
movl (%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movq 0xb0(%rsp), %rbp
movl (%rbp), %r9d
andq %rax, %r9
leaq 0x8(%rsp), %r14
leaq 0x18(%rsp), %rbx
leaq 0x10(%rsp), %rax
leaq 0x20(%rsp), %r10
pushq %r14
pushq %rbx
pushq %rax
pushq %r10
callq 0xc7ff2
addq $0x20, %rsp
movq (%rbx), %rbx
movq (%r14), %r14
movl 0xe8(%rsp), %eax
testl %eax, %eax
je 0xcb581
movl (%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
notq %rbx
addq %rax, %rbx
notq %r14
movq %r14, %rcx
addq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %r14
movq %rcx, %rbx
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x48(%rsp), %r9
movq 0xa8(%rsp), %rdi
movq %r15, %rsi
callq 0xcaee0
leaq 0x60(%rsp), %r13
leaq 0x58(%rsp), %r12
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movq %r13, %r8
movq %r12, %r9
callq 0xcaee0
leaq 0x50(%rsp), %rax
movq (%rax), %rax
cmpq $-0x1, %rax
sete %cl
leaq 0x48(%rsp), %rdx
movq (%rdx), %r10
cmpq $-0x1, %r10
sete %dl
orb %cl, %dl
movq (%r13), %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 0xcb6f4
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 0xcaf57
addq $0x70, %rsp
testl %eax, %eax
je 0xcb6f4
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rcx
movslq (%rcx), %rdx
imulq $0x28, %rdx, %rdx
movl 0x1c(%rax,%rdx), %edx
movq 0x108(%rsp), %rsi
movl %edx, (%rsi)
movslq (%rcx), %rdx
imulq $0x28, %rdx, %rdx
movl 0x18(%rax,%rdx), %edx
movl %edx, (%r13)
movq (%rbp), %rdx
movslq -0x4(%rcx,%rdx,4), %rsi
imulq $0x28, %rsi, %rsi
movl 0x1c(%rax,%rsi), %esi
movl %esi, (%r12)
movslq -0x4(%rcx,%rdx,4), %rcx
imulq $0x28, %rcx, %rcx
movl 0x18(%rax,%rcx), %eax
movl %eax, (%r14)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq