// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: determine_hap_overlap_type_advance(hap_candidates*, ma_utg_t*, ma_utg_t*, R_to_U*, ma_hit_t_alloc*, ma_sub_t*, asg_t*, unsigned long*, int, int, unsigned int, unsigned int, kvec_asg_arc_t_offset*, kvec_t_i32_warp*, kvec_t_i32_warp*, long long*, long long*, long long*, long long*)
uint32_t determine_hap_overlap_type_advance(hap_candidates* hap_can, ma_utg_t *xReads, ma_utg_t *yReads,
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, uint32_t xUid, uint32_t yUid, kvec_asg_arc_t_offset* u_buffer, kvec_t_i32_warp* tailIndex, 
kvec_t_i32_warp* prevIndex, long long* r_x_pos_beg, long long* r_x_pos_end, long long* r_y_pos_beg, long long* r_y_pos_end)
{
    uint32_t x_pos_beg, y_pos_beg, x_pos_end, y_pos_end;
    /*************************x***************************/
    get_base_boundary_advance(ruIndex, reverse_sources, coverage_cut, read_g, position_index, 
    max_hang, min_ovlp, xReads, yReads, xUid, yUid, Get_x_beg(*hap_can), Get_x_end(*hap_can), 
    Get_y_beg(*hap_can), Get_y_end(*hap_can), Get_rev(*hap_can), u_buffer, tailIndex, prevIndex, 
    &x_pos_beg, &x_pos_end, &y_pos_beg, &y_pos_end);
    /*************************x***************************/
    if(x_pos_beg == (uint32_t)-1 || y_pos_beg == (uint32_t)-1 
                    || x_pos_end == (uint32_t)-1 || y_pos_end == (uint32_t)-1)
    {
        return (uint32_t)-1;
    }
    if(x_pos_beg > x_pos_end || y_pos_beg > y_pos_end) return (uint32_t)-1;

    /**
    #define X2Y 0
    #define Y2X 1
    #define XCY 2
    #define YCX 3
    **/
    hap_can->index_end = classify_hap_overlap(x_pos_beg, x_pos_end, xReads->len, y_pos_beg, y_pos_end, yReads->len, 
    r_x_pos_beg, r_x_pos_end, r_y_pos_beg, r_y_pos_end);
    hap_can->x_beg_pos = MIN((uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[0]].x.ul>>33]), 
                                (uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].x.ul>>33]));
    hap_can->x_end_pos = MAX((uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[0]].x.ul>>33]), 
                                (uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].x.ul>>33]));
    hap_can->y_beg_pos = MIN((uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[0]].x.v>>1]), 
                                (uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].x.v>>1]));
    hap_can->y_end_pos = MAX((uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[0]].x.v>>1]), 
                                (uint32_t)(position_index[u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]].x.v>>1]));
    double xLeftMatch, xLeftTotal;
    get_pair_hap_similarity(xReads->a + hap_can->x_beg_pos, hap_can->x_end_pos + 1 - hap_can->x_beg_pos, 
        yUid, reverse_sources, read_g, ruIndex, &xLeftMatch, &xLeftTotal);
    if(xLeftMatch == 0 || xLeftTotal == 0) return (uint32_t)-1;
    hap_can->weight = xLeftMatch;
    hap_can->index_beg = xLeftTotal;
    hap_can->score = get_chain_score(xReads, read_g, u_buffer, tailIndex, prevIndex, reverse_sources, 
                                                                        (*r_x_pos_beg), (*r_x_pos_end));
    if(hap_can->score <= 0) return (uint32_t)-1;
    return hap_can->index_end;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rax
movq %r8, %rbx
movq %rsi, 0x38(%rsp)
movq 0x98(%rsp), %r8
movq 0x90(%rsp), %r9
movl 0x8(%rdi), %esi
movq %rsi, 0x30(%rsp)
movl 0xc(%rdi), %esi
movq %rsi, 0x28(%rsp)
movl 0x10(%rdi), %r15d
movl 0x14(%rdi), %r14d
movq %rdi, 0x10(%rsp)
movzbl 0x28(%rdi), %ebp
subq $0x8, %rsp
leaq 0x10(%rsp), %r12
leaq 0x14(%rsp), %r11
leaq 0x50(%rsp), %r13
leaq 0x54(%rsp), %r10
movq %rcx, 0x20(%rsp)
movq %rcx, %rdi
movq %rbx, 0x28(%rsp)
movq %rbx, %rsi
movq %rdx, %rbx
movq %rax, %rdx
movq %r9, %rcx
movl 0xa8(%rsp), %r9d
pushq %r12
pushq %r11
pushq %r13
pushq %r10
movq %r10, %r12
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq %rbp
movq 0x80(%rsp), %rbp
pushq %r14
pushq %r15
movl 0x110(%rsp), %r15d
pushq 0x80(%rsp)
pushq 0x90(%rsp)
pushq %r15
movl 0x120(%rsp), %eax
pushq %rax
pushq %rbx
pushq %rbp
movl 0x130(%rsp), %eax
pushq %rax
callq 0x109c3e
addq $0x90, %rsp
movl (%r12), %edi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rdi
sete %cl
leaq 0xc(%rsp), %rax
movl (%rax), %eax
cmpl $-0x1, %eax
sete %sil
orb %cl, %sil
movl (%r13), %edx
cmpl $-0x1, %edx
sete %cl
leaq 0x8(%rsp), %r8
movl (%r8), %r8d
cmpl $-0x1, %r8d
sete %r9b
orb %cl, %r9b
orb %sil, %r9b
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x10ab56
movl %eax, %ecx
movl %edx, %esi
movl %r8d, %r8d
cmpl %esi, %edi
seta %al
cmpl %r8d, %ecx
seta %dl
orb %al, %dl
jne 0x10ab56
movl (%rbp), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl (%rbx), %r9d
andq %rax, %r9
pushq 0xf0(%rsp)
pushq 0xf0(%rsp)
pushq 0xf0(%rsp)
pushq 0xf0(%rsp)
callq 0x105f44
addq $0x20, %rsp
movq 0x10(%rsp), %rbx
movl %eax, 0x1c(%rbx)
movq 0xc0(%rsp), %r13
movq 0x10(%r13), %rax
movq 0xc8(%rsp), %r12
movq (%r12), %rdx
movq 0x10(%r12), %rdi
movslq (%rdi), %rcx
leaq (%rcx,%rcx,4), %rcx
movq (%rax,%rcx,8), %rcx
shrq $0x21, %rcx
movq 0x98(%rsp), %r10
movl (%r10,%rcx,8), %esi
movslq -0x4(%rdi,%rdx,4), %rcx
leaq (%rcx,%rcx,4), %rcx
movq (%rax,%rcx,8), %rcx
shrq $0x21, %rcx
movl (%r10,%rcx,8), %ecx
cmpl %ecx, %esi
cmovbl %esi, %ecx
movl %ecx, 0x8(%rbx)
movslq (%rdi), %rsi
leaq (%rsi,%rsi,4), %rsi
movq (%rax,%rsi,8), %rsi
shrq $0x21, %rsi
movl (%r10,%rsi,8), %r8d
movslq -0x4(%rdi,%rdx,4), %rsi
leaq (%rsi,%rsi,4), %rsi
movq (%rax,%rsi,8), %rsi
shrq $0x21, %rsi
movl (%r10,%rsi,8), %esi
cmpl %esi, %r8d
cmoval %r8d, %esi
movl %esi, 0xc(%rbx)
movslq (%rdi), %r8
leaq (%r8,%r8,4), %r8
movl 0x8(%rax,%r8,8), %r8d
shrl %r8d
movl (%r10,%r8,8), %r8d
movslq -0x4(%rdi,%rdx,4), %r9
leaq (%r9,%r9,4), %r9
movl 0x8(%rax,%r9,8), %r9d
shrl %r9d
movl (%r10,%r9,8), %r9d
cmpl %r9d, %r8d
cmovbl %r8d, %r9d
movl %r9d, 0x10(%rbx)
movslq (%rdi), %r8
leaq (%r8,%r8,4), %r8
movl 0x8(%rax,%r8,8), %r8d
shrl %r8d
movl (%r10,%r8,8), %r8d
movslq -0x4(%rdi,%rdx,4), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x8(%rax,%rdx,8), %eax
shrl %eax
movl (%r10,%rax,8), %eax
cmpl %eax, %r8d
cmoval %r8d, %eax
movl %eax, 0x14(%rbx)
leaq (,%rcx,8), %rdi
addq 0x18(%rbp), %rdi
subl %ecx, %esi
incl %esi
leaq 0x40(%rsp), %rax
leaq 0x50(%rsp), %r14
movl %r15d, %edx
movq 0x20(%rsp), %r15
movq %r15, %rcx
movq 0x90(%rsp), %r8
movq 0x18(%rsp), %r9
pushq %rax
pushq %r14
callq 0x1064d3
addq $0x10, %rsp
movsd (%r14), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x10aad8
jnp 0x10ab56
movsd 0x40(%rsp), %xmm1
ucomisd %xmm2, %xmm1
jne 0x10aae6
jnp 0x10ab56
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x11a76e(%rip), %xmm0   # 0x225268
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq %rdx, (%rbx)
cvttsd2si %xmm1, %rax
movl %eax, 0x18(%rbx)
movq %rbp, %rdi
movq 0x90(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
movq 0xd0(%rsp), %r8
movq %r15, %r9
movq 0xe0(%rsp), %rax
pushq (%rax)
movq 0xe0(%rsp), %rax
pushq (%rax)
callq 0x10a468
addq $0x10, %rsp
movq %rax, 0x20(%rbx)
testq %rax, %rax
jle 0x10ab56
movl 0x1c(%rbx), %r14d
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq