// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq 0x70(%rbp), %rax
movq 0x68(%rbp), %rax
movq 0x60(%rbp), %rax
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq 0x18(%rbp), %r8
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl 0x30(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl 0x38(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0xa8(%rbp)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x28(%rax), %r13d
movq 0x40(%rbp), %r12
movq 0x48(%rbp), %r15
movq 0x50(%rbp), %r14
leaq -0x64(%rbp), %rbx
leaq -0x6c(%rbp), %r11
leaq -0x68(%rbp), %r10
leaq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, (%rsp)
movq -0xc0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xb8(%rbp), %rax
movq %rax, 0x10(%rsp)
movl -0xb0(%rbp), %eax
movl %eax, 0x18(%rsp)
movl -0xac(%rbp), %eax
movl %eax, 0x20(%rsp)
movq -0xa8(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0xa0(%rbp), %rax
movq %rax, 0x30(%rsp)
movq -0x98(%rbp), %rax
movq %rax, 0x38(%rsp)
movq -0x90(%rbp), %rax
movq %rax, 0x40(%rsp)
movq -0x88(%rbp), %rax
movl %r13d, 0x48(%rsp)
movq %r12, 0x50(%rsp)
movq %r15, 0x58(%rsp)
movq %r14, 0x60(%rsp)
movq %rbx, 0x68(%rsp)
movq %r11, 0x70(%rsp)
movq %r10, 0x78(%rsp)
movq %rax, 0x80(%rsp)
callq 0x175e30
cmpl $-0x1, -0x64(%rbp)
je 0x1774bd
cmpl $-0x1, -0x68(%rbp)
je 0x1774bd
cmpl $-0x1, -0x6c(%rbp)
je 0x1774bd
cmpl $-0x1, -0x70(%rbp)
jne 0x1774c9
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1779ce
movl -0x64(%rbp), %eax
cmpl -0x6c(%rbp), %eax
ja 0x1774d9
movl -0x68(%rbp), %eax
cmpl -0x70(%rbp), %eax
jbe 0x1774e5
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1779ce
movl -0x64(%rbp), %eax
movl %eax, %edi
movl -0x6c(%rbp), %eax
movl %eax, %esi
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
movl -0x68(%rbp), %eax
movl %eax, %ecx
movl -0x70(%rbp), %eax
movl %eax, %r8d
movq -0x48(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %r9d
movq 0x58(%rbp), %rbx
movq 0x60(%rbp), %r11
movq 0x68(%rbp), %r10
movq 0x70(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x170800
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
movq 0x18(%rbp), %rcx
movq 0x40(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq 0x10(%rsi), %rsi
movq 0x48(%rbp), %rdi
movq (%rdi), %rdi
subq $0x1, %rdi
movslq (%rsi,%rdi,4), %rsi
imulq $0x28, %rsi, %rsi
addq %rsi, %rdx
movq (%rdx), %rdx
shrq $0x21, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
ja 0x1775dd
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0xc8(%rbp)
jmp 0x177618
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq (%rsi), %rsi
subq $0x1, %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
movq 0x18(%rbp), %rcx
movq 0x40(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq 0x10(%rsi), %rsi
movq 0x48(%rbp), %rdi
movq (%rdi), %rdi
subq $0x1, %rdi
movslq (%rsi,%rdi,4), %rsi
imulq $0x28, %rsi, %rsi
addq %rsi, %rdx
movq (%rdx), %rdx
shrq $0x21, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jb 0x1776b8
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0xcc(%rbp)
jmp 0x1776f3
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq (%rsi), %rsi
subq $0x1, %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0xcc(%rbp)
movl -0xcc(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq 0x18(%rbp), %rcx
movq 0x40(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq 0x10(%rsi), %rsi
movq 0x48(%rbp), %rdi
movq (%rdi), %rdi
subq $0x1, %rdi
movslq (%rsi,%rdi,4), %rsi
imulq $0x28, %rsi, %rsi
addq %rsi, %rdx
movl 0x8(%rdx), %edx
shrl %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
ja 0x177793
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xd0(%rbp)
jmp 0x1777ce
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq (%rsi), %rsi
subq $0x1, %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x10(%rax)
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq 0x18(%rbp), %rcx
movq 0x40(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq 0x10(%rsi), %rsi
movq 0x48(%rbp), %rdi
movq (%rdi), %rdi
subq $0x1, %rdi
movslq (%rsi,%rdi,4), %rsi
imulq $0x28, %rsi, %rsi
addq %rsi, %rdx
movl 0x8(%rdx), %edx
shrl %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jb 0x17786e
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xd4(%rbp)
jmp 0x1778a9
movq 0x18(%rbp), %rax
movq 0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq 0x48(%rbp), %rsi
movq (%rsi), %rsi
subq $0x1, %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x38(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
movq -0x38(%rbp), %rax
subl 0x8(%rax), %esi
movl 0x38(%rbp), %edx
movq -0x58(%rbp), %rcx
movq 0x10(%rbp), %r8
movq -0x50(%rbp), %r9
leaq -0x78(%rbp), %r10
leaq -0x80(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x1711f0
movsd -0x78(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x177914
jp 0x177914
jmp 0x177924
movsd -0x80(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x177930
jp 0x177930
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1779ce
movsd -0x78(%rbp), %xmm0
movsd 0x20a6bb(%rip), %xmm2   # 0x381ff8
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
cvttsd2si -0x80(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x40(%rbp), %rdi
movq 0x10(%rbp), %rsi
movq 0x40(%rbp), %rdx
movq 0x48(%rbp), %rcx
movq 0x50(%rbp), %r8
movq -0x58(%rbp), %r9
movq 0x58(%rbp), %rax
movq (%rax), %r10
movq 0x60(%rbp), %rax
movq (%rax), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x176bd0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jg 0x1779c4
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1779ce
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)