// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: determin_hap_alignment_boundary_single_side(unsigned long*, long long, long long, long long, long long, long long, long long, long long, float, int, unsigned long*, ma_hit_t_alloc*, asg_t*, R_to_U*, unsigned int*, unsigned int*, unsigned int*)
void determin_hap_alignment_boundary_single_side(uint64_t* readIDs, long long queryLen, long long targetBeg, 
long long targetEnd, long long targetID, long long eMatch, long long eTotal, long long dir, 
float H_rate, int is_local, uint64_t* position_index, ma_hit_t_alloc* reverse_sources, asg_t *read_g, 
R_to_U* ruIndex, uint32_t* n_matchLen, uint32_t* n_max_count, uint32_t* n_min_count)
{
    if(queryLen == 0)
    {
        (*n_matchLen) = (*n_min_count) = (*n_max_count) = 0;
        return;
    }
    long long i, maxId, min_count = eTotal, max_count = eMatch, matchLen = 0;
    long long rLen, score = 0, max_score = 0;
    uint32_t is_found, is_match;
    if(dir == 0)
    {
        for (i = 0, maxId = 0; i < queryLen; i++)
        {
            
            check_hap_match(readIDs[i]>>33, targetBeg, targetEnd, targetID, position_index, reverse_sources, 
            read_g, ruIndex, &is_found, &is_match);

            min_count += is_found;
            max_count += is_match;
            if(max_count > min_count*H_rate) maxId = i;

            if(is_local && is_found)
            {
                rLen = read_g->seq[readIDs[i]>>33].len;
                score += (is_match? rLen : (rLen*(-1)));
                if(score >= max_score) max_score = score, maxId = i;
            }
        }

        for (i = maxId; i >= 0; i--)
        {
            check_hap_match(readIDs[i]>>33, targetBeg, targetEnd, targetID, position_index, reverse_sources, 
            read_g, ruIndex, &is_found, &is_match);

            ///if(is_found > 0 && is_match > 0 && is_match > is_found*Hap_rate)
            if(is_found == 1 && is_match == 1)
            {
                break;
            }
            min_count -= is_found;
            max_count -= is_match;
        }
        
        matchLen = i+1;
    }
    else
    {
        for (i = queryLen - 1, maxId = queryLen - 1; i >= 0; i--)
        {
            check_hap_match(readIDs[i]>>33, targetBeg, targetEnd, targetID, position_index, reverse_sources, 
            read_g, ruIndex, &is_found, &is_match);

            min_count += is_found;
            max_count += is_match;
            if(max_count > min_count*H_rate) maxId = i;

            if(is_local && is_found)
            {
                rLen = read_g->seq[readIDs[i]>>33].len;
                score += (is_match? rLen : (rLen*(-1)));
                if(score >= max_score) max_score = score, maxId = i;
            }
        }

        for (i = maxId; i < queryLen; i++)
        {
            check_hap_match(readIDs[i]>>33, targetBeg, targetEnd, targetID, position_index, reverse_sources, 
            read_g, ruIndex, &is_found, &is_match);

            ///if(is_found > 0 && is_match > 0 && is_match > is_found*Hap_rate)
            if(is_found == 1 && is_match == 1)
            {
                break;
            }
            min_count -= is_found;
            max_count -= is_match;
        }

        matchLen = queryLen - i;
    }

    ///need to check if min_count == 0
    if(min_count == 0)
    {
        (*n_matchLen) = (*n_min_count) = (*n_max_count) = 0;
        return;
    }

    (*n_matchLen) = matchLen;
    (*n_min_count) = min_count;
    (*n_max_count) = max_count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movss %xmm0, 0x14(%rsp)
movq %r8, %r14
movq %rcx, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq 0xe8(%rsp), %rcx
movq 0xe0(%rsp), %rdx
movq 0xd8(%rsp), %r8
movq %rsi, 0x38(%rsp)
testq %rsi, %rsi
je 0x10b1e5
movq 0xc0(%rsp), %rdx
movq 0xa0(%rsp), %r8
cmpq $0x0, 0xa8(%rsp)
movq %rdi, 0x40(%rsp)
je 0x10b1f3
movq 0x38(%rsp), %rax
leaq -0x1(%rax), %rsi
testq %rax, %rax
jle 0x10b09f
movq $0x0, 0x50(%rsp)
leaq 0xc(%rsp), %rbx
movq $0x0, 0x48(%rsp)
movq %rsi, %r12
movq (%rdi,%r12,8), %rax
shrq $0x21, %rax
leaq (%rax,%rax,2), %rax
movl 0xc(%rdx,%rax,8), %ecx
movb $0x1, %r10b
testl %ecx, %ecx
je 0x10afd7
movl %ecx, 0x34(%rsp)
movq %rsi, 0x18(%rsp)
movq %r8, 0x28(%rsp)
movq %r9, 0x20(%rsp)
leaq (%rdx,%rax,8), %r15
movl $0xc, %r13d
xorl %ebp, %ebp
movq (%r15), %rax
movl (%rax,%r13), %esi
movl %esi, 0x8(%rsp)
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x10af60
movq 0xd0(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0xa3c62
movl 0x10(%rsp), %eax
cmpl %r14d, %eax
jne 0x10afa0
cmpl $-0x1, %eax
je 0x10afa0
cmpl $0x1, 0xc(%rsp)
jne 0x10afa0
movl 0x8(%rsp), %eax
movq 0xb8(%rsp), %rcx
movl (%rcx,%rax,8), %eax
cmpl 0x58(%rsp), %eax
setae %cl
cmpl 0x60(%rsp), %eax
setbe %al
testb %al, %cl
je 0x10afa0
jmp 0x10afdb
movq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %rbx, %rcx
callq 0xa3c62
movl 0x8(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0x10afa0
cmpl $0x1, 0xc(%rsp)
je 0x10afa0
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0x10af13
incq %rbp
movl 0xc(%r15), %eax
addq $0x28, %r13
cmpq %rax, %rbp
jb 0x10aef6
xorl %eax, %eax
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x40(%rsp), %rdi
movq 0xc0(%rsp), %rdx
movq 0x18(%rsp), %rsi
movb $0x1, %r10b
jmp 0x10afff
xorl %eax, %eax
jmp 0x10b003
movl $0x1, %eax
xorl %r10d, %r10d
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x40(%rsp), %rdi
movq 0xc0(%rsp), %rdx
movq 0x18(%rsp), %rsi
movl 0x34(%rsp), %ecx
cmpl $0x1, %ecx
sbbq $-0x1, %r8
addq %rax, %r9
xorps %xmm0, %xmm0
cvtsi2ss %r9, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r8, %xmm1
mulss 0x14(%rsp), %xmm1
ucomiss %xmm1, %xmm0
cmovaq %r12, %rsi
cmpl $0x0, 0xb0(%rsp)
je 0x10b083
testl %ecx, %ecx
je 0x10b083
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rdi,%r12,8), %rcx
shrq $0x21, %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, %rcx
negq %rcx
testb %r10b, %r10b
cmoveq %rax, %rcx
movq 0x48(%rsp), %r10
addq %rcx, %r10
movq 0x50(%rsp), %rax
cmpq %rax, %r10
cmovgeq %r12, %rsi
movq %r10, 0x48(%rsp)
cmovgq %r10, %rax
movq %rax, 0x50(%rsp)
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x10aebc
cmpq 0x38(%rsp), %rsi
jge 0x10b40a
movq %r9, 0x20(%rsp)
leaq 0x10(%rsp), %rbx
leaq 0xc(%rsp), %r13
movq %r8, 0x28(%rsp)
movq %rsi, 0x18(%rsp)
movq (%rdi,%rsi,8), %rax
shrq $0x21, %rax
leaq (%rax,%rax,2), %rax
movl 0xc(%rdx,%rax,8), %ecx
movl %ecx, 0x14(%rsp)
testl %ecx, %ecx
je 0x10b1a8
movq 0xc0(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movl $0xc, %ebp
xorl %r15d, %r15d
movq (%r12), %rax
movl (%rax,%rbp), %esi
movl %esi, 0x8(%rsp)
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x10b153
movq 0xd0(%rsp), %rdi
movq %rbx, %rdx
movq %r13, %rcx
callq 0xa3c62
movl 0x10(%rsp), %eax
cmpl %r14d, %eax
jne 0x10b193
cmpl $-0x1, %eax
je 0x10b193
cmpl $0x1, 0xc(%rsp)
jne 0x10b193
movl 0x8(%rsp), %eax
movq 0xb8(%rsp), %rcx
movl (%rcx,%rax,8), %eax
cmpl 0x58(%rsp), %eax
setae %cl
cmpl 0x60(%rsp), %eax
setbe %al
testb %al, %cl
je 0x10b193
jmp 0x10b3fb
movq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %r13, %rcx
callq 0xa3c62
movl 0x8(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0x10b193
cmpl $0x1, 0xc(%rsp)
je 0x10b193
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0x10b105
incq %r15
movl 0xc(%r12), %eax
addq $0x28, %rbp
cmpq %rax, %r15
jb 0x10b0e8
cmpl $0x1, 0x14(%rsp)
movq 0x28(%rsp), %r8
adcq $-0x1, %r8
movq 0x18(%rsp), %rsi
incq %rsi
cmpq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdi
movq 0xc0(%rsp), %rdx
jne 0x10b0ae
movq 0x38(%rsp), %rsi
movq 0x20(%rsp), %r9
jmp 0x10b40a
xorl %eax, %eax
movl %eax, (%rdx)
movl %eax, (%rcx)
movl %eax, (%r8)
jmp 0x10b5a3
cmpq $0x0, 0x38(%rsp)
jle 0x10b41a
movq $0x0, 0x50(%rsp)
leaq 0xc(%rsp), %rbx
movq $0x0, 0x48(%rsp)
xorl %r10d, %r10d
xorl %r12d, %r12d
movq (%rdi,%r12,8), %rax
shrq $0x21, %rax
leaq (%rax,%rax,2), %rax
movl 0xc(%rdx,%rax,8), %ecx
movb $0x1, %sil
testl %ecx, %ecx
je 0x10b338
movl %ecx, 0x34(%rsp)
movq %r10, 0x18(%rsp)
movq %r8, 0x28(%rsp)
movq %r9, 0x20(%rsp)
leaq (%rdx,%rax,8), %rbp
movl $0xc, %r15d
xorl %r13d, %r13d
movq (%rbp), %rax
movl (%rax,%r15), %esi
movl %esi, 0x8(%rsp)
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x10b2c2
movq 0xd0(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq %rbx, %rcx
callq 0xa3c62
movl 0x10(%rsp), %eax
cmpl %r14d, %eax
jne 0x10b302
cmpl $-0x1, %eax
je 0x10b302
cmpl $0x1, 0xc(%rsp)
jne 0x10b302
movl 0x8(%rsp), %eax
movq 0xb8(%rsp), %rcx
movl (%rcx,%rax,8), %eax
cmpl 0x58(%rsp), %eax
setae %cl
cmpl 0x60(%rsp), %eax
setbe %al
testb %al, %cl
je 0x10b302
jmp 0x10b33c
movq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %rbx, %rcx
callq 0xa3c62
movl 0x8(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0x10b302
cmpl $0x1, 0xc(%rsp)
je 0x10b302
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0x10b275
incq %r13
movl 0xc(%rbp), %eax
addq $0x28, %r15
cmpq %rax, %r13
jb 0x10b257
xorl %eax, %eax
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x40(%rsp), %rdi
movq 0xc0(%rsp), %rdx
movq 0x18(%rsp), %r10
movb $0x1, %sil
jmp 0x10b35f
xorl %eax, %eax
jmp 0x10b363
movl $0x1, %eax
xorl %esi, %esi
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x40(%rsp), %rdi
movq 0xc0(%rsp), %rdx
movq 0x18(%rsp), %r10
movl 0x34(%rsp), %ecx
cmpl $0x1, %ecx
sbbq $-0x1, %r8
addq %rax, %r9
xorps %xmm0, %xmm0
cvtsi2ss %r9, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r8, %xmm1
mulss 0x14(%rsp), %xmm1
ucomiss %xmm1, %xmm0
cmovaq %r12, %r10
cmpl $0x0, 0xb0(%rsp)
je 0x10b3e3
testl %ecx, %ecx
je 0x10b3e3
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rdi,%r12,8), %rcx
shrq $0x21, %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, %rcx
negq %rcx
testb %sil, %sil
cmoveq %rax, %rcx
movq 0x48(%rsp), %rsi
addq %rcx, %rsi
movq 0x50(%rsp), %rax
cmpq %rax, %rsi
cmovgeq %r12, %r10
movq %rsi, 0x48(%rsp)
cmovgq %rsi, %rax
movq %rax, 0x50(%rsp)
incq %r12
cmpq 0x38(%rsp), %r12
jne 0x10b21c
testq %r10, %r10
jns 0x10b41d
jmp 0x10b570
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rax
subq %rsi, %rax
movq %rax, %r10
jmp 0x10b573
xorl %r10d, %r10d
movq %r9, 0x20(%rsp)
leaq 0x10(%rsp), %rbx
leaq 0xc(%rsp), %r13
movq %r8, 0x28(%rsp)
movq %r10, 0x18(%rsp)
movq (%rdi,%r10,8), %rax
shrq $0x21, %rax
leaq (%rax,%rax,2), %rax
movl 0xc(%rdx,%rax,8), %ecx
movl %ecx, 0x14(%rsp)
testl %ecx, %ecx
je 0x10b526
movq 0xc0(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movl $0xc, %ebp
xorl %r15d, %r15d
movq (%r12), %rax
movl (%rax,%rbp), %esi
movl %esi, 0x8(%rsp)
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x10b4d1
movq 0xd0(%rsp), %rdi
movq %rbx, %rdx
movq %r13, %rcx
callq 0xa3c62
movl 0x10(%rsp), %eax
cmpl %r14d, %eax
jne 0x10b511
cmpl $-0x1, %eax
je 0x10b511
cmpl $0x1, 0xc(%rsp)
jne 0x10b511
movl 0x8(%rsp), %eax
movq 0xb8(%rsp), %rcx
movl (%rcx,%rax,8), %eax
cmpl 0x58(%rsp), %eax
setae %cl
cmpl 0x60(%rsp), %eax
setbe %al
testb %al, %cl
je 0x10b511
jmp 0x10b561
movq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %r13, %rcx
callq 0xa3c62
movl 0x8(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0x10b511
cmpl $0x1, 0xc(%rsp)
je 0x10b511
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0x10b483
incq %r15
movl 0xc(%r12), %eax
addq $0x28, %rbp
cmpq %rax, %r15
jb 0x10b466
cmpl $0x1, 0x14(%rsp)
movq 0x28(%rsp), %r8
adcq $-0x1, %r8
movq 0x18(%rsp), %rcx
leaq -0x1(%rcx), %r10
testq %rcx, %rcx
movq 0x40(%rsp), %rdi
movq 0xc0(%rsp), %rdx
jg 0x10b42c
movq $-0x1, %r10
movq 0x20(%rsp), %r9
jmp 0x10b570
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x18(%rsp), %r10
incq %r10
testq %r8, %r8
movq 0xe8(%rsp), %rcx
movq 0xe0(%rsp), %rdx
movq 0xd8(%rsp), %rsi
je 0x10b59b
movl %r10d, (%rsi)
movl %r8d, (%rcx)
movl %r9d, (%rdx)
jmp 0x10b5a3
xorl %eax, %eax
movl %eax, (%rdx)
movl %eax, (%rcx)
movl %eax, (%rsi)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq