// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x2c(%rsp)
cmpl $0x3, %edx
ja 0xc92fb
movq %rsi, %r10
movq %rdi, %rbp
movq 0x130(%rsp), %r12
movl 0x110(%rsp), %r9d
movl 0xe0(%rsp), %r13d
movl 0xd8(%rsp), %edi
movl 0xd0(%rsp), %r11d
movl %edx, %eax
leaq 0x12278e(%rip), %rdx    # 0x1eb5c8
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
movl 0xc8(%rsp), %ebx
movl 0xb8(%rsp), %r14d
movl 0xb0(%rsp), %edx
movl 0xa8(%rsp), %esi
movl 0xa0(%rsp), %r15d
jmpq *%rax
movl %esi, %r8d
leal (%rdx,%rsi), %eax
decl %eax
movq %r10, 0x10(%rsp)
movl 0x10(%r10), %edx
addq $0x3, %rax
leaq -0x1(%rdx), %rcx
cmpq %rdx, %rax
cmovbq %rax, %rcx
cmpq $0x4, %r8
pushq $0x3
popq %rdx
movq %r8, 0x8(%rsp)
cmovaeq %r8, %rdx
addq $-0x3, %rdx
movl 0x98(%rsp), %eax
movq %rax, %r12
movl %r12d, %edi
shlq $0x3, %rdi
addq 0x18(%rbp), %rdi
movl %r15d, %esi
movl %r13d, %r8d
movl 0x78(%rsp), %r9d
movl 0xe8(%rsp), %eax
leaq 0x18(%rsp), %r10
leaq 0x20(%rsp), %r11
movq %rsp, %r13
movss %xmm0, 0x4(%rsp)
pushq %r10
pushq %r11
pushq %r13
movq 0x120(%rsp), %r10
pushq %r10
movq 0x120(%rsp), %r10
pushq %r10
movq 0x120(%rsp), %r10
pushq %r10
movq 0x120(%rsp), %r10
pushq %r10
pushq %rax
pushq $0x1
movl 0xc8(%rsp), %eax
pushq %rax
callq 0xc870c
addq $0x50, %rsp
addl %r12d, %r15d
movl (%r13), %eax
subq %rax, %r15
movl 0xc0(%rsp), %eax
leal (%rax,%r14), %r13d
decq %r13
addl %r14d, %eax
decl %eax
movl 0x10(%rbp), %edx
addq $0x3, %rax
leaq -0x1(%rdx), %rcx
cmpq %rdx, %rax
cmovbq %rax, %rcx
cmpl $0x4, %r14d
pushq $0x3
popq %rdx
cmovael %r14d, %edx
addq $-0x3, %rdx
movl %ebx, %edi
shlq $0x3, %rdi
movq 0x10(%rsp), %rax
addq 0x18(%rax), %rdi
movl 0xd0(%rsp), %eax
movq %rax, %rbp
movl %eax, %esi
movl 0xd8(%rsp), %r8d
movl 0x2c(%rsp), %r9d
movl 0x70(%rsp), %eax
movl 0x110(%rsp), %r12d
movl %r12d, %r10d
leaq 0x30(%rsp), %r11
leaq 0x34(%rsp), %r14
movss 0x4(%rsp), %xmm0
pushq %r11
pushq %r14
leaq 0x10(%rsp), %r11
pushq %r11
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
movl 0x120(%rsp), %r11d
pushq %r11
pushq %r10
pushq %rax
callq 0xc870c
addq $0x50, %rsp
testl %r12d, %r12d
je 0xc926b
movl 0xb0(%rsp), %eax
movq %rax, %rcx
movl 0xa8(%rsp), %eax
addl %eax, %ecx
addl %ebx, %ebp
jmp 0xc92b4
movq %r10, %rbx
movl 0x10(%r10), %eax
decl %eax
leaq 0x18(%rsp), %r10
leaq 0x20(%rsp), %r12
movq %rbp, %rdi
movl 0x98(%rsp), %esi
movl %r15d, %edx
movl %r14d, %ecx
movl 0xc0(%rsp), %r8d
movl %r13d, %r9d
pushq %r10
movq %r10, %r14
pushq %r12
pushq $0x0
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
movl 0x120(%rsp), %r10d
pushq %r10
pushq %rax
pushq $0x0
callq 0xc8b0b
addq $0x50, %rsp
movl 0x10(%rbx), %ebx
decq %rbx
movq (%r12), %r15
xorl %ebp, %ebp
movq (%r14), %r13
jmp 0xc92bf
movl 0x10(%rbp), %r13d
leal -0x1(%r13), %eax
decq %r13
leaq 0x18(%rsp), %r15
leaq 0x20(%rsp), %rbp
movl %edi, %r14d
movq %r10, %rdi
movq %r9, %r10
movl %ebx, %ecx
movl %r11d, %r8d
movl %r14d, %r9d
pushq %r15
movq %r15, %rbx
pushq %rbp
pushq %r10
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
movl 0x120(%rsp), %r10d
pushq %r10
pushq %rax
pushq $0x0
callq 0xc8b0b
addq $0x50, %rsp
movq (%rbp), %rbp
xorl %r15d, %r15d
movq (%rbx), %rbx
jmp 0xc92c7
movl %ebx, %edi
leal (%r11,%rbx), %edx
decl %edx
movq %r10, 0x10(%rsp)
movl 0x10(%r10), %esi
addq $0x3, %rdx
leaq -0x1(%rsi), %rax
cmpq %rsi, %rdx
cmovbq %rdx, %rax
cmpq $0x4, %rdi
pushq $0x3
popq %r12
movq %r12, %rdx
movq %rdi, 0x8(%rsp)
cmovaeq %rdi, %rdx
addq $-0x3, %rdx
movl %r14d, %edi
shlq $0x3, %rdi
addq 0x18(%rbp), %rdi
movl 0xc0(%rsp), %esi
movl %esi, %esi
movl %r13d, %r10d
movl %ecx, %r9d
movl %r8d, %r11d
movq %rsp, %r13
movq %rax, %rcx
movq %r10, %r8
movss %xmm0, 0x4(%rsp)
leaq 0x18(%rsp), %rax
pushq %rax
leaq 0x28(%rsp), %rax
pushq %rax
pushq %r13
movq 0x120(%rsp), %rax
pushq %rax
movq 0x120(%rsp), %rax
pushq %rax
movq 0x120(%rsp), %rax
pushq %rax
pushq 0x120(%rsp)
movl 0x120(%rsp), %eax
pushq %rax
pushq $0x0
pushq %r11
callq 0xc870c
addq $0x50, %rsp
addl (%r13), %r14d
movq %r14, %r13
decq %r13
movl 0x98(%rsp), %eax
movq %rax, %rsi
addl %r15d, %eax
decl %eax
movl 0x10(%rbp), %edx
addq $0x3, %rax
leaq -0x1(%rdx), %rcx
cmpq %rdx, %rax
cmovbq %rax, %rcx
movl %esi, %r15d
cmpq $0x4, %r15
cmovaeq %r15, %r12
addq $-0x3, %r12
movl 0xa8(%rsp), %eax
movl %eax, %edi
shlq $0x3, %rdi
movq 0x10(%rsp), %rax
addq 0x18(%rax), %rdi
movl 0xb0(%rsp), %eax
movl %eax, %esi
movl 0xd8(%rsp), %r8d
movl 0x88(%rsp), %r9d
movl 0x90(%rsp), %eax
pushq $0x1
popq %r10
movl 0x110(%rsp), %ebp
subl %ebp, %r10d
leaq 0x30(%rsp), %r11
leaq 0x34(%rsp), %r14
movq %r12, %rdx
movss 0x4(%rsp), %xmm0
pushq %r11
pushq %r14
leaq 0x10(%rsp), %r11
pushq %r11
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
pushq 0x120(%rsp)
movl 0x120(%rsp), %r11d
pushq %r11
pushq %r10
pushq %rax
callq 0xc870c
addq $0x50, %rsp
testl %ebp, %ebp
je 0xc9298
movl 0xa8(%rsp), %ebx
addl (%rsp), %ebx
decq %rbx
movq 0x130(%rsp), %r12
movq 0x128(%rsp), %rax
movq 0x120(%rsp), %rcx
movq 0x118(%rsp), %rdx
movq 0x8(%rsp), %rbp
jmp 0xc92df
movl 0xd0(%rsp), %eax
movq %rax, %rcx
addl %ebx, %ecx
movl 0xb0(%rsp), %ebp
movl 0xa8(%rsp), %eax
addl %eax, %ebp
movl (%rsp), %eax
subq %rax, %rbp
movl %ecx, %ebx
decq %rbx
movq 0x130(%rsp), %r12
movq 0x128(%rsp), %rax
movq 0x120(%rsp), %rcx
movq 0x118(%rsp), %rdx
movq %r15, (%rdx)
movq %r13, (%rcx)
movq %rbp, (%rax)
movq %rbx, (%r12)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20f0