// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movl %r9d, 0x40(%rsp)
xorl %eax, %eax
movl %eax, 0x28(%rsp)
movl %eax, 0x2c(%rsp)
movl %eax, 0xc(%rsp)
movl %eax, 0x4(%rsp)
cmpl $0x3, %edx
ja 0x10768a
movq %rsi, %r13
movq %rdi, %rbp
movq 0x140(%rsp), %r15
movl 0xf0(%rsp), %r9d
movl 0xe8(%rsp), %edi
movl 0xe0(%rsp), %esi
movl %edx, %eax
leaq 0x12638c(%rip), %rdx    # 0x22d4d8
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
movl 0xd8(%rsp), %r10d
movl 0xc8(%rsp), %ebx
movl 0xc0(%rsp), %edx
movl 0xb8(%rsp), %r12d
movl 0xb0(%rsp), %r14d
jmpq *%rax
movl 0x90(%rsp), %r11d
movl 0x88(%rsp), %eax
leaq 0x4(%rsp), %rcx
movl %eax, (%rcx)
leaq 0xc(%rsp), %r10
movl %r11d, (%r10)
movl %r12d, %r8d
addl %r12d, %edx
decl %edx
movl 0x10(%r13), %esi
addq $0x3, %rdx
leaq -0x1(%rsi), %rcx
cmpq %rsi, %rdx
cmovbq %rdx, %rcx
cmpq $0x4, %r8
movl $0x3, %r15d
movl $0x3, %edx
movq %r8, 0x38(%rsp)
cmovgeq %r8, %rdx
addq $-0x3, %rdx
movl 0xa8(%rsp), %esi
movl %esi, %edi
shlq $0x3, %rdi
addq 0x18(%rbp), %rdi
movl %r14d, %esi
movl %r9d, %r8d
movl %eax, %r9d
movl %r11d, %eax
movq %rsp, %r11
movss %xmm0, 0x8(%rsp)
pushq %r10
leaq 0xc(%rsp), %r10
pushq %r10
pushq %r11
movq 0x130(%rsp), %r10
pushq %r10
movq 0x130(%rsp), %r10
pushq %r10
movq 0x130(%rsp), %r10
pushq %r10
movq 0x130(%rsp), %r10
pushq %r10
movl 0x130(%rsp), %r10d
pushq %r10
pushq $0x1
pushq %rax
callq 0x1066b9
addq $0x50, %rsp
movl 0xa8(%rsp), %eax
addl %eax, %r14d
movq %r14, 0x20(%rsp)
movq %rsp, %rax
movl (%rax), %eax
subq %rax, %r14
movq %r14, 0x20(%rsp)
movl 0xd0(%rsp), %eax
movq %rax, %rcx
addl %ebx, %eax
decq %rax
movq %rax, 0x30(%rsp)
leaq 0x2c(%rsp), %rax
movl 0x40(%rsp), %r9d
movl %r9d, (%rax)
leaq 0x28(%rsp), %r10
movl 0x80(%rsp), %r11d
movl %r11d, (%r10)
movl %ebx, %edx
leal (%rcx,%rbx), %esi
decl %esi
movl 0x10(%rbp), %edi
addq $0x3, %rsi
leaq -0x1(%rdi), %rcx
cmpq %rdi, %rsi
cmovbq %rsi, %rcx
cmpq $0x4, %rdx
cmovgeq %rdx, %r15
addq $-0x3, %r15
movl 0xd8(%rsp), %edx
movq %rdx, %rbp
movl %edx, %edi
shlq $0x3, %rdi
addq 0x18(%r13), %rdi
movl 0xe0(%rsp), %edx
movq %rdx, %r14
movl %edx, %esi
movl 0xe8(%rsp), %r8d
movl %r9d, %r9d
movl %r11d, %r11d
movl 0x120(%rsp), %r13d
movl %r13d, %ebx
movq %r15, %rdx
movss 0x8(%rsp), %xmm0
pushq %r10
pushq %rax
leaq 0x10(%rsp), %rax
pushq %rax
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
movl 0x130(%rsp), %eax
pushq %rax
pushq %rbx
pushq %r11
callq 0x1066b9
addq $0x50, %rsp
testl %r13d, %r13d
je 0x1075f9
movl 0xc0(%rsp), %eax
movq %rax, %rcx
addl %r12d, %ecx
addl %ebp, %r14d
jmp 0x107626
movl 0x10(%r13), %eax
decl %eax
leaq 0x30(%rsp), %r10
leaq 0x20(%rsp), %r11
movq %r15, %r12
xorl %r15d, %r15d
movq %rbp, %rdi
movl 0xa8(%rsp), %esi
movl %r14d, %edx
movl %ebx, %ecx
movl 0xd0(%rsp), %r8d
pushq %r10
pushq %r11
pushq %r15
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
movl 0x130(%rsp), %r10d
pushq %r10
pushq %rax
pushq %r15
movq %r12, %r15
callq 0x106e4f
addq $0x50, %rsp
movq $0x0, 0x18(%rsp)
movl 0x10(%r13), %eax
decq %rax
movq %rax, 0x10(%rsp)
jmp 0x107643
movq $0x0, 0x20(%rsp)
movl 0x10(%rbp), %ecx
leal -0x1(%rcx), %eax
decq %rcx
movq %rcx, 0x30(%rsp)
movq %r10, %rcx
leaq 0x10(%rsp), %r10
movl %edi, %r9d
leaq 0x18(%rsp), %r11
movq %r13, %rdi
movq %rsi, %r8
movl %r12d, %esi
pushq %r10
pushq %r11
movl 0x130(%rsp), %r10d
pushq %r10
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
movl 0x130(%rsp), %r10d
pushq %r10
pushq %rax
pushq $0x0
callq 0x106e4f
addq $0x50, %rsp
jmp 0x107643
leaq 0x4(%rsp), %rax
movl %ecx, (%rax)
leaq 0xc(%rsp), %rax
movl %r8d, (%rax)
movl %r10d, %edi
leal (%rsi,%r10), %edx
decl %edx
movl 0x10(%r13), %esi
addq $0x3, %rdx
leaq -0x1(%rsi), %rax
cmpq %rsi, %rdx
cmovbq %rdx, %rax
cmpq $0x4, %rdi
movl $0x3, %r15d
movl $0x3, %edx
movq %rdi, 0x38(%rsp)
cmovgeq %rdi, %rdx
addq $-0x3, %rdx
movl %ebx, %edi
shlq $0x3, %rdi
addq 0x18(%rbp), %rdi
movl 0xd0(%rsp), %esi
movl %esi, %esi
movl %r9d, %r10d
movl %ecx, %r9d
movl %r8d, %r11d
movq %r13, 0x40(%rsp)
movq %rsp, %r13
movq %rax, %rcx
movq %r10, %r8
movss %xmm0, 0x8(%rsp)
leaq 0xc(%rsp), %rax
pushq %rax
leaq 0xc(%rsp), %rax
pushq %rax
pushq %r13
movq 0x130(%rsp), %rax
pushq %rax
movq 0x130(%rsp), %rax
pushq %rax
movq 0x130(%rsp), %rax
pushq %rax
movq 0x130(%rsp), %rax
pushq %rax
movl 0x130(%rsp), %eax
pushq %rax
pushq $0x0
pushq %r11
callq 0x1066b9
addq $0x50, %rsp
movl 0xa8(%rsp), %eax
movq %rax, %rcx
movl %ecx, %edx
movq %rdx, 0x20(%rsp)
addl (%r13), %ebx
decq %rbx
movq %rbx, 0x30(%rsp)
leaq 0x2c(%rsp), %rax
movl 0x98(%rsp), %r9d
movl %r9d, (%rax)
leaq 0x28(%rsp), %r10
movl 0xa0(%rsp), %r11d
movl %r11d, (%r10)
leal (%r14,%rcx), %esi
decl %esi
movl 0x10(%rbp), %edi
addq $0x3, %rsi
leaq -0x1(%rdi), %rcx
cmpq %rdi, %rsi
cmovbq %rsi, %rcx
cmpq $0x4, %rdx
cmovgeq %rdx, %r15
addq $-0x3, %r15
movl %r12d, %edi
shlq $0x3, %rdi
movq 0x40(%rsp), %rdx
addq 0x18(%rdx), %rdi
movl 0xc0(%rsp), %edx
movq %rdx, %r14
movl %edx, %esi
movl 0xe8(%rsp), %r8d
movl %r9d, %r9d
movl %r11d, %r11d
movl $0x1, %ebx
movl 0x120(%rsp), %r13d
subl %r13d, %ebx
movq %r15, %rdx
movss 0x8(%rsp), %xmm0
pushq %r10
pushq %rax
leaq 0x10(%rsp), %rax
pushq %rax
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
pushq 0x130(%rsp)
movl 0x130(%rsp), %eax
pushq %rax
pushq %rbx
pushq %r11
callq 0x1066b9
addq $0x50, %rsp
testl %r13d, %r13d
je 0x107610
movq 0x38(%rsp), %rax
movq %rax, 0x18(%rsp)
addl (%rsp), %r12d
decq %r12
movq %r12, 0x10(%rsp)
jmp 0x10763b
movq 0x38(%rsp), %rax
movq %rax, 0x18(%rsp)
addl (%rsp), %ebp
decq %rbp
movq %rbp, 0x10(%rsp)
jmp 0x10763b
movl 0xe0(%rsp), %eax
movq %rax, %rcx
movl 0xd8(%rsp), %eax
addl %eax, %ecx
addl %r12d, %r14d
movl (%rsp), %eax
subq %rax, %r14
movq %r14, 0x18(%rsp)
movl %ecx, %eax
decq %rax
movq %rax, 0x10(%rsp)
movq 0x140(%rsp), %r15
movq 0x138(%rsp), %rcx
movq 0x130(%rsp), %rdx
movq 0x128(%rsp), %rsi
movq 0x20(%rsp), %rax
movq %rax, (%rsi)
movq 0x30(%rsp), %rax
movq %rax, (%rdx)
movq 0x18(%rsp), %rax
movq %rax, (%rcx)
movq 0x10(%rsp), %rax
movq %rax, (%r15)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20f0