// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbp
movq 0x110(%rsp), %rcx
movq 0x108(%rsp), %rsi
movq 0x100(%rsp), %rdx
movq 0xf8(%rsp), %r11
movq 0xf0(%rsp), %r14
movq 0xe8(%rsp), %rdi
movq 0xe0(%rsp), %r10
movl 0xd8(%rsp), %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%rcx)
movl %eax, (%rsi)
movl %eax, (%rdx)
movl %eax, (%r11)
movl 0xb0(%rsp), %esi
movups 0xb8(%rsp), %xmm0
movups 0xc8(%rsp), %xmm1
movl 0xa8(%rsp), %r11d
movq 0xa0(%rsp), %rdx
movq 0x98(%rsp), %rcx
movl 0x90(%rsp), %eax
subq $0x70, %rsp
movq %r14, 0x60(%rsp)
movq %rdi, 0x58(%rsp)
movq %r10, 0x50(%rsp)
movl %ebx, 0x48(%rsp)
movups %xmm1, 0x38(%rsp)
movups %xmm0, 0x28(%rsp)
movl %esi, 0x20(%rsp)
movl %r11d, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movl %eax, (%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r8, 0xa0(%rsp)
movl %r9d, 0x8c(%rsp)
callq 0x1096b5
addq $0x70, %rsp
testl %eax, %eax
je 0x109f8e
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0xe8(%rsp), %rsi
movq 0x10(%rsi), %rdx
movslq (%rdx), %rcx
leaq (%rcx,%rcx,4), %rcx
movq 0x18(%rax,%rcx,8), %rdi
movl %edi, %ecx
shrq $0x20, %rdi
movq %rdi, 0x28(%rsp)
movq %rcx, 0x10(%rsp)
movq (%rsi), %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, 0x20(%rsp)
movq %r8, 0x8(%rsp)
cmpq %rsi, %rdi
ja 0x109f8e
cmpl %r8d, %ecx
ja 0x109f8e
movq 0x98(%rsp), %rax
movl (%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movq 0xa0(%rsp), %r9
movl (%r9), %ebx
andq %rax, %rbx
leaq 0x8(%rsp), %rax
leaq 0x10(%rsp), %r10
leaq 0x20(%rsp), %r11
leaq 0x28(%rsp), %r14
movq %rbx, %r9
pushq %rax
pushq %r10
pushq %r11
pushq %r14
callq 0x105f44
addq $0x20, %rsp
movl 0xd8(%rsp), %eax
testl %eax, %eax
je 0x109e19
movq 0x10(%rsp), %rax
notq %rax
addq %rbx, %rax
movq 0x8(%rsp), %rcx
notq %rcx
addq %rbx, %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x38(%rsp), %r9
movq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x10963a
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
leaq 0x50(%rsp), %r14
leaq 0x48(%rsp), %rbx
movq 0xa0(%rsp), %rdi
movq %r15, %rsi
movq %r14, %r8
movq %rbx, %r9
callq 0x10963a
leaq 0x40(%rsp), %rax
movq (%rax), %rax
cmpq $-0x1, %rax
sete %cl
leaq 0x38(%rsp), %rdx
movq (%rdx), %r10
cmpq $-0x1, %r10
sete %dl
orb %cl, %dl
movq (%r14), %r11
cmpq $-0x1, %r11
sete %cl
movq (%rbx), %rbx
cmpq $-0x1, %rbx
sete %sil
orb %cl, %sil
orb %dl, %sil
movq 0x110(%rsp), %r14
jne 0x109f8e
subq $0x8, %rsp
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x38(%rsp), %r8
movl 0x24(%rsp), %r9d
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
movl 0xf8(%rsp), %r15d
pushq %r15
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
movl 0xf8(%rsp), %eax
pushq %rax
movl 0xf8(%rsp), %eax
pushq %rax
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
movl 0xf8(%rsp), %eax
pushq %rax
callq 0x1096b5
addq $0x70, %rsp
testl %eax, %eax
je 0x109f8e
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0xe8(%rsp), %rdi
movq 0x10(%rdi), %rcx
movslq (%rcx), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x1c(%rax,%rdx,8), %edx
movq 0xf8(%rsp), %rsi
movl %edx, (%rsi)
movslq (%rcx), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x18(%rax,%rdx,8), %edx
movq 0x108(%rsp), %rsi
movl %edx, (%rsi)
movq (%rdi), %rdx
movslq -0x4(%rcx,%rdx,4), %rsi
leaq (%rsi,%rsi,4), %rsi
movl 0x1c(%rax,%rsi,8), %esi
movq 0x100(%rsp), %rdi
movl %esi, (%rdi)
movslq -0x4(%rcx,%rdx,4), %rcx
leaq (%rcx,%rcx,4), %rcx
movl 0x18(%rax,%rcx,8), %eax
movl %eax, (%r14)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq