// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: fix_binned_reads(ma_hit_t_alloc*, unsigned long, ma_sub_t*)
void fix_binned_reads(ma_hit_t_alloc* paf, uint64_t n_read, ma_sub_t* coverage_cut)
{
    double startTime = Get_T();
    uint64_t i, binned_flag, binned_reads = 0, binned_error_reads = 0, reduce = 1;
    ma_sub_t max_left, max_right;
    while (reduce != 0)
    {    
        reduce = 0;
        binned_reads = 0;
        for (i = 0; i < n_read; ++i) 
        {
            if(coverage_cut[i].del) continue;
            binned_flag = R_INF.trio_flag[i];
            if(binned_flag == AMBIGU) continue;
            binned_reads++;
            max_left.s = max_right.s = Get_READ_LENGTH(R_INF,i);
            max_left.e = max_right.e = 0;
            collect_sides_trio(&(paf[i]), Get_READ_LENGTH(R_INF,i), &max_left, &max_right, binned_flag);
            collect_contain_trio(&(paf[i]), NULL, Get_READ_LENGTH(R_INF,i), &max_left, &max_right, 0.1,
            binned_flag);
            if(max_left.e > max_right.s)
            {
                R_INF.trio_flag[i] = AMBIGU;
                binned_error_reads++;
                reduce++;
                binned_reads--;
            } 
            /**
            if(max_left.e > max_right.s)
            {
                fprintf(stderr, "\ni: %lu, reference: %.*s, len: %lu, %c\n", 
                    i, (int)Get_NAME_LENGTH(R_INF, i), Get_NAME(R_INF, i), 
                    Get_READ_LENGTH(R_INF, i), "apmaaa"[binned_flag]);

                for (uint64_t j = 0; j < paf[i].length; j++)
                {
                    if(R_INF.trio_flag[Get_tn(paf[i].buffer[j])] == binned_flag)
                    {
                        fprintf(stderr, "###Compatible, ");
                    }
                    else
                    {
                        fprintf(stderr, "***Conflict, ");
                    }

                    fprintf(stderr, "%c, qs: %u, qe: %u, ts: %u, te: %u, len: %lu, %.*s\n", 
                    "apmaaa"[R_INF.trio_flag[Get_tn(paf[i].buffer[j])]],
                    Get_qs(paf[i].buffer[j]),
                    Get_qe(paf[i].buffer[j]),
                    Get_ts(paf[i].buffer[j]),
                    Get_te(paf[i].buffer[j]),
                    Get_READ_LENGTH(R_INF, Get_tn(paf[i].buffer[j])),
                    (int)Get_NAME_LENGTH(R_INF, Get_tn(paf[i].buffer[j])), 
                    Get_NAME(R_INF, Get_tn(paf[i].buffer[j])));
                }
            }
            **/
        }
    }

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }

    fprintf(stderr, "n_read: %lu, binned_reads: %lu, binned_error_reads: %lu\n", 
    (unsigned long)n_read, (unsigned long)binned_reads, (unsigned long)binned_error_reads);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x40(%rsp)
movq %rsi, %rbp
movq %rdi, 0x38(%rsp)
callq 0x251c
pushq $0x1
popq %rdx
movq $0x0, (%rsp)
leaq 0x1947a4(%rip), %rcx    # 0x254230
movq $0x0, 0x20(%rsp)
movq %rbp, 0x30(%rsp)
testq %rdx, %rdx
je 0xbfba3
movq 0x38(%rsp), %r15
movq 0x40(%rsp), %r12
xorl %r14d, %r14d
movq $0x0, (%rsp)
movq $0x0, 0x28(%rsp)
cmpq %r14, %rbp
je 0xbfb99
cmpl $0x0, (%r12)
js 0xbfb89
movq 0x28(%rcx), %rbx
movzbl (%rbx,%r14), %r13d
testl %r13d, %r13d
je 0xbfb89
movq 0x18(%rcx), %rcx
movq (%rcx,%r14,8), %rbp
movl %ebp, %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %eax
orl %ecx, %eax
movl %eax, 0x14(%rsp)
movl 0x8(%rsp), %eax
andl %edx, %eax
orl %ecx, %eax
andl $0x0, 0x18(%rsp)
movl %eax, 0x8(%rsp)
andl $0x0, 0xc(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x8(%rsp), %rdx
leaq 0x14(%rsp), %rcx
movl %r13d, %r8d
callq 0x6b14e
movq %r15, %rdi
xorl %esi, %esi
movq %rbp, %rdx
leaq 0x8(%rsp), %rcx
leaq 0x14(%rsp), %r8
movss 0x128163(%rip), %xmm0   # 0x1e7cb0
movl %r13d, %r9d
callq 0x6b1e9
movl 0x14(%rsp), %eax
movl %eax, %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
cmpl %ecx, 0xc(%rsp)
jbe 0xbfb79
movb $0x0, (%rbx,%r14)
incq 0x20(%rsp)
incq 0x28(%rsp)
jmp 0xbfb7d
incq (%rsp)
movq 0x30(%rsp), %rbp
leaq 0x1946a7(%rip), %rcx    # 0x254230
incq %r14
addq $0xc, %r12
addq $0x18, %r15
jmp 0xbfac1
movq 0x28(%rsp), %rdx
jmp 0xbfa9a
movq 0x193436(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x12b1f0(%rip), %rsi    # 0x1eada4
movq %rbp, %rdx
movq (%rsp), %rcx
movq 0x20(%rsp), %r8
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0