// File: chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_hap_alignment_boundary(ma_utg_t*, ma_utg_t*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, float, int, unsigned long*, ma_hit_t_alloc*, asg_t*, R_to_U*, unsigned int, long long*, long long*, long long*, long long*)
void get_hap_alignment_boundary(ma_utg_t* xReads, ma_utg_t* yReads, uint32_t type, 
uint32_t xLeftMatch, uint32_t xLeftTotal, uint32_t yLeftMatch, uint32_t yLeftTotal, 
uint32_t xRightMatch, uint32_t xRightTotal, uint32_t yRightMatch, uint32_t yRightTotal,
uint32_t xLeftBeg, uint32_t xLeftLen, uint32_t yLeftBeg, uint32_t yLeftLen,
uint32_t xRightBeg, uint32_t xRightLen, uint32_t yRightBeg, uint32_t yRightLen,
uint32_t xUid, uint32_t yUid, float Hap_rate, int is_local, uint64_t* position_index,
ma_hit_t_alloc* reverse_sources, asg_t *read_g, R_to_U* ruIndex, uint32_t rev,
long long* r_x_interval_beg, long long* r_x_interval_end, 
long long* r_y_interval_beg, long long* r_y_interval_end)
{
    
    uint32_t x_max_count, x_min_count, y_max_count, y_min_count, n_matchLen;
    long long x_interval_beg, x_interval_end, y_interval_beg, y_interval_end;
    long long target_beg, target_end;
    x_max_count = x_min_count = y_max_count = y_min_count = 0;
    if(type == X2Y)
    {
        /********************x*********************/
        x_max_count = xRightMatch;
        x_min_count = xRightTotal;

        modify_target_interval(yLeftBeg, yLeftBeg+yLeftLen-1, yReads->n, &target_beg, &target_end);
        determin_hap_alignment_boundary_single_side(xReads->a+xLeftBeg, xLeftLen, 
        /**yLeftBeg, yLeftBeg+yLeftLen-1,**/ target_beg, target_end, yUid, 
        x_max_count, x_min_count, 1, Hap_rate, is_local, position_index, reverse_sources, 
        read_g, ruIndex, &n_matchLen, &x_max_count, &x_min_count);

        x_interval_beg = xLeftBeg + xLeftLen; x_interval_beg -= n_matchLen;
        x_interval_end = xRightBeg + xRightLen; x_interval_end -= 1;
        /********************x*********************/

        /********************y*********************/
        y_max_count = yLeftMatch;
        y_min_count = yLeftTotal;
        modify_target_interval(xRightBeg, xRightBeg+xRightLen-1, xReads->n, &target_beg, &target_end);
        determin_hap_alignment_boundary_single_side(yReads->a+yRightBeg, yRightLen,
        /**xRightBeg, xRightBeg+xRightLen-1,**/ target_beg, target_end, xUid, 
        y_max_count, y_min_count, rev, Hap_rate, is_local, position_index, reverse_sources, 
        read_g, ruIndex, &n_matchLen, &y_max_count, &y_min_count);
        if(rev == 0)
        {
            y_interval_beg = yLeftBeg;
            y_interval_end = yRightBeg + n_matchLen; y_interval_end -= 1;
        }
        else
        {
            y_interval_beg = yRightBeg + yRightLen; y_interval_beg -= n_matchLen;
            y_interval_end = yLeftBeg + yLeftLen; y_interval_end -= 1;
        }
        
        /********************y*********************/
    }
    else if(type == Y2X)
    {
        /********************x*********************/
        x_max_count = xLeftMatch;
        x_min_count = xLeftTotal;
        modify_target_interval(yRightBeg, yRightBeg+yRightLen-1, yReads->n, &target_beg, &target_end);
        determin_hap_alignment_boundary_single_side(xReads->a+xRightBeg, xRightLen,
        /**yRightBeg, yRightBeg+yRightLen-1,**/ target_beg, target_end, yUid, 
        x_max_count, x_min_count, 0, Hap_rate, is_local, position_index, reverse_sources, 
        read_g, ruIndex, &n_matchLen, &x_max_count, &x_min_count);

        x_interval_beg = xLeftBeg;
        x_interval_end = xRightBeg + n_matchLen; x_interval_end -= 1;
        /********************x*********************/

        /********************y*********************/
        y_max_count = yRightMatch;
        y_min_count = yRightTotal;
        modify_target_interval(xLeftBeg, xLeftBeg+xLeftLen-1, xReads->n, &target_beg, &target_end);
        determin_hap_alignment_boundary_single_side(yReads->a+yLeftBeg, yLeftLen,
        /**xLeftBeg, xLeftBeg+xLeftLen-1,**/ target_beg, target_end, xUid, 
        y_max_count, y_min_count, 1-rev, Hap_rate, is_local, position_index, reverse_sources, 
        read_g, ruIndex, &n_matchLen, &y_max_count, &y_min_count);
        if(rev == 0)
        {
            y_interval_beg = yLeftBeg + yLeftLen; y_interval_beg -= n_matchLen;
            y_interval_end = yRightBeg + yRightLen; y_interval_end -= 1;
        }
        else
        {
            y_interval_beg = yRightBeg;
            y_interval_end = yLeftBeg + n_matchLen; y_interval_end -= 1;
        }
        /********************y*********************/
    }
    else if(type == XCY)
    {
        /********************x*********************/   
        bi_direction_hap_alignment_extention(xReads, xLeftBeg, xLeftLen, xRightBeg, xRightLen, 
        yUid, 0, yReads->n - 1, Hap_rate, is_local, position_index, reverse_sources, read_g, ruIndex, 0,
        &x_interval_beg, &x_interval_end);
        /********************x*********************/

        /********************y*********************/
        y_interval_beg = 0;
        y_interval_end = yReads->n; y_interval_end -= 1;
        /********************y*********************/
    }
    else if(type == YCX)
    {
        /********************x*********************/  
        x_interval_beg = 0;
        x_interval_end = xReads->n; x_interval_end -= 1;
        /********************x*********************/  

        /********************y*********************/
        bi_direction_hap_alignment_extention(yReads, yLeftBeg, yLeftLen, yRightBeg, yRightLen,
        xUid, 0, xReads->n - 1, Hap_rate, is_local, position_index, reverse_sources, read_g, ruIndex, rev,
        &y_interval_beg, &y_interval_end);
        /********************y*********************/
    } else abort();

    (*r_x_interval_beg) = x_interval_beg;
    (*r_x_interval_end) = x_interval_end;
    (*r_y_interval_beg) = y_interval_beg;
    (*r_y_interval_end) = y_interval_end;    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq 0xd0(%rbp), %rax
movq 0xc8(%rbp), %rax
movq 0xc0(%rbp), %rax
movq 0xb8(%rbp), %rax
movl 0xb0(%rbp), %eax
movq 0xa8(%rbp), %rax
movq 0xa0(%rbp), %rax
movq 0x98(%rbp), %rax
movq 0x90(%rbp), %rax
movl 0x88(%rbp), %eax
movl 0x80(%rbp), %eax
movl 0x78(%rbp), %eax
movl 0x70(%rbp), %eax
movl 0x68(%rbp), %eax
movl 0x60(%rbp), %eax
movl 0x58(%rbp), %eax
movl 0x50(%rbp), %eax
movl 0x48(%rbp), %eax
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movl %edx, -0x3c(%rbp)
movl %ecx, -0x40(%rbp)
movl %r8d, -0x44(%rbp)
movl %r9d, -0x48(%rbp)
movss %xmm0, -0x4c(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x50(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x172023
movl 0x18(%rbp), %eax
movl %eax, -0x50(%rbp)
movl 0x20(%rbp), %eax
movl %eax, -0x54(%rbp)
movl 0x48(%rbp), %eax
movl %eax, %edi
movl 0x48(%rbp), %eax
addl 0x50(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
leaq -0x88(%rbp), %rcx
leaq -0x90(%rbp), %r8
callq 0x185980
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movl 0x38(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x40(%rbp), %eax
movl %eax, %esi
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rcx
movl 0x80(%rbp), %eax
movl %eax, %r8d
movl -0x50(%rbp), %eax
movl %eax, %r9d
movl -0x54(%rbp), %eax
movq %rax, -0xb8(%rbp)
movss -0x4c(%rbp), %xmm0
movl 0x88(%rbp), %r13d
movq 0x90(%rbp), %r12
movq 0x98(%rbp), %r15
movq 0xa0(%rbp), %r14
movq 0xa8(%rbp), %rbx
leaq -0x60(%rbp), %r11
leaq -0x50(%rbp), %r10
leaq -0x54(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, (%rsp)
movq -0xb0(%rbp), %rax
movq $0x1, 0x8(%rsp)
movl %r13d, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x1713e0
movl 0x38(%rbp), %eax
addl 0x40(%rbp), %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movl -0x60(%rbp), %eax
movl %eax, %ecx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movl 0x58(%rbp), %eax
addl 0x60(%rbp), %eax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x58(%rbp)
movl 0x10(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl 0x58(%rbp), %eax
movl %eax, %edi
movl 0x58(%rbp), %eax
addl 0x60(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
leaq -0x88(%rbp), %rcx
leaq -0x90(%rbp), %r8
callq 0x185980
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movl 0x68(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x70(%rbp), %eax
movl %eax, %esi
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rcx
movl 0x78(%rbp), %eax
movl %eax, %r8d
movl -0x58(%rbp), %eax
movl %eax, %r9d
movl -0x5c(%rbp), %eax
movq %rax, -0xa8(%rbp)
movl 0xb0(%rbp), %eax
movq %rax, -0xa0(%rbp)
movss -0x4c(%rbp), %xmm0
movl 0x88(%rbp), %r13d
movq 0x90(%rbp), %r12
movq 0x98(%rbp), %r15
movq 0xa0(%rbp), %r14
movq 0xa8(%rbp), %rbx
leaq -0x60(%rbp), %r11
leaq -0x58(%rbp), %r10
leaq -0x5c(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, (%rsp)
movq -0xa0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x98(%rbp), %rax
movl %r13d, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x1713e0
cmpl $0x0, 0xb0(%rbp)
jne 0x171fea
movl 0x48(%rbp), %eax
movq %rax, -0x78(%rbp)
movl 0x68(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x17201e
movl 0x68(%rbp), %eax
addl 0x70(%rbp), %eax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movl -0x60(%rbp), %eax
movl %eax, %ecx
movq -0x78(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x78(%rbp)
movl 0x48(%rbp), %eax
addl 0x50(%rbp), %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x17245b
cmpl $0x1, -0x3c(%rbp)
jne 0x1722bb
movl -0x40(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movl 0x68(%rbp), %eax
movl %eax, %edi
movl 0x68(%rbp), %eax
addl 0x70(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
leaq -0x88(%rbp), %rcx
leaq -0x90(%rbp), %r8
callq 0x185980
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movl 0x58(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x60(%rbp), %eax
movl %eax, %esi
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rcx
movl 0x80(%rbp), %eax
movl %eax, %r8d
movl -0x50(%rbp), %eax
movl %eax, %r9d
movl -0x54(%rbp), %eax
movq %rax, -0xe0(%rbp)
movss -0x4c(%rbp), %xmm0
movl 0x88(%rbp), %r13d
movq 0x90(%rbp), %r12
movq 0x98(%rbp), %r15
movq 0xa0(%rbp), %r14
movq 0xa8(%rbp), %rbx
xorl %eax, %eax
leaq -0x60(%rbp), %r11
leaq -0x50(%rbp), %r10
leaq -0x54(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, (%rsp)
movq -0xd8(%rbp), %rax
movq $0x0, 0x8(%rsp)
movl %r13d, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x1713e0
movl 0x38(%rbp), %eax
movq %rax, -0x68(%rbp)
movl 0x58(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
movl 0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
movl 0x30(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl 0x38(%rbp), %eax
movl %eax, %edi
movl 0x38(%rbp), %eax
addl 0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
leaq -0x88(%rbp), %rcx
leaq -0x90(%rbp), %r8
callq 0x185980
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movl 0x48(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x50(%rbp), %eax
movl %eax, %esi
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rcx
movl 0x78(%rbp), %eax
movl %eax, %r8d
movl -0x58(%rbp), %eax
movl %eax, %r9d
movl -0x5c(%rbp), %eax
movq %rax, -0xd0(%rbp)
movl $0x1, %eax
subl 0xb0(%rbp), %eax
movl %eax, %eax
movq %rax, -0xc8(%rbp)
movss -0x4c(%rbp), %xmm0
movl 0x88(%rbp), %r13d
movq 0x90(%rbp), %r12
movq 0x98(%rbp), %r15
movq 0xa0(%rbp), %r14
movq 0xa8(%rbp), %rbx
leaq -0x60(%rbp), %r11
leaq -0x58(%rbp), %r10
leaq -0x5c(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, (%rsp)
movq -0xc8(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xc0(%rbp), %rax
movl %r13d, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x1713e0
cmpl $0x0, 0xb0(%rbp)
jne 0x172297
movl 0x48(%rbp), %eax
addl 0x50(%rbp), %eax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movl -0x60(%rbp), %eax
movl %eax, %ecx
movq -0x78(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x78(%rbp)
movl 0x68(%rbp), %eax
addl 0x70(%rbp), %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1722b6
movl 0x68(%rbp), %eax
movq %rax, -0x78(%rbp)
movl 0x48(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x172459
cmpl $0x2, -0x3c(%rbp)
jne 0x17237b
movq -0x30(%rbp), %rdi
movl 0x38(%rbp), %esi
movl 0x40(%rbp), %edx
movl 0x58(%rbp), %ecx
movl 0x60(%rbp), %r8d
movl 0x80(%rbp), %r9d
movq -0x38(%rbp), %rax
movl 0x10(%rax), %r13d
subl $0x1, %r13d
movss -0x4c(%rbp), %xmm0
movl 0x88(%rbp), %r12d
movq 0x90(%rbp), %r15
movq 0x98(%rbp), %r14
movq 0xa0(%rbp), %rbx
movq 0xa8(%rbp), %r11
xorl %eax, %eax
leaq -0x68(%rbp), %r10
leaq -0x70(%rbp), %rax
movl $0x0, (%rsp)
movl %r13d, 0x8(%rsp)
movl %r12d, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x171910
movq $0x0, -0x78(%rbp)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x172457
cmpl $0x3, -0x3c(%rbp)
jne 0x172450
movq $0x0, -0x68(%rbp)
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rdi
movl 0x48(%rbp), %esi
movl 0x50(%rbp), %edx
movl 0x68(%rbp), %ecx
movl 0x70(%rbp), %r8d
movl 0x78(%rbp), %r9d
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0xec(%rbp)
movss -0x4c(%rbp), %xmm0
movl 0x88(%rbp), %r13d
movq 0x90(%rbp), %r12
movq 0x98(%rbp), %r15
movq 0xa0(%rbp), %r14
movq 0xa8(%rbp), %rbx
movl 0xb0(%rbp), %r11d
xorl %eax, %eax
leaq -0x78(%rbp), %r10
leaq -0x80(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl -0xec(%rbp), %eax
movl $0x0, (%rsp)
movl %eax, 0x8(%rsp)
movq -0xe8(%rbp), %rax
movl %r13d, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movl %r11d, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x171910
jmp 0x172455
callq 0x2110
jmp 0x172457
jmp 0x172459
jmp 0x17245b
movq -0x68(%rbp), %rcx
movq 0xb8(%rbp), %rax
movq %rcx, (%rax)
movq -0x70(%rbp), %rcx
movq 0xc0(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rcx
movq 0xc8(%rbp), %rax
movq %rcx, (%rax)
movq -0x80(%rbp), %rcx
movq 0xd0(%rbp), %rax
movq %rcx, (%rax)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)