// File: /workspace/github_cpp_makefile_star2_O3/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, %r13
movq %rdi, 0x38(%rsp)
callq 0x2f3fc
movq $0x0, 0x20(%rsp)
leaq 0x287536(%rip), %rcx    # 0x296230
movq %r13, 0x30(%rsp)
testq %r13, %r13
je 0xee05
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %r12
movq $0x0, 0x28(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
cmpl $0x0, (%r15)
js 0xede3
movq 0x28(%rcx), %rbx
movzbl (%rbx,%rbp), %r14d
testl %r14d, %r14d
je 0xede3
movq 0x18(%rcx), %rcx
movq (%rcx,%rbp,8), %r13
movl %r13d, %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 %r12, %rdi
movq %r13, %rsi
leaq 0x8(%rsp), %rdx
leaq 0x14(%rsp), %rcx
movl %r14d, %r8d
callq 0xa2f64
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
leaq 0x8(%rsp), %rcx
leaq 0x14(%rsp), %r8
movss 0x227008(%rip), %xmm0   # 0x235db0
movl %r14d, %r9d
callq 0xa3008
movl 0x14(%rsp), %eax
movl %eax, %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
cmpl %ecx, 0xc(%rsp)
jbe 0xedd3
movb $0x0, (%rbx,%rbp)
incq 0x20(%rsp)
incq 0x28(%rsp)
jmp 0xedd7
incq (%rsp)
movq 0x30(%rsp), %r13
leaq 0x28744d(%rip), %rcx    # 0x296230
incq %rbp
addq $0x18, %r12
addq $0xc, %r15
cmpq %rbp, %r13
jne 0xed25
cmpq $0x0, 0x28(%rsp)
jne 0xecff
jmp 0xee0d
movq $0x0, (%rsp)
movq 0x2861cc(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x22a086(%rip), %rsi    # 0x238ea4
movq %r13, %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