// File: /workspace/github_cpp_makefile_star2_O1/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 0x300fc
movq $0x0, 0x20(%rsp)
leaq 0x27c5e0(%rip), %rcx    # 0x28b230
movq %r13, 0x30(%rsp)
testq %r13, %r13
je 0xed5a
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %r12
movq $0x0, 0x28(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
cmpl $0x0, (%r15)
js 0xed3b
movq 0x28(%rcx), %rbx
movzbl (%rbx,%rbp), %r14d
testl %r14d, %r14d
je 0xed3b
movq 0x18(%rcx), %rax
movq (%rax,%rbp,8), %r13
movl %r13d, %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl 0x8(%rsp), %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %ecx
orl %eax, %ecx
movl %ecx, 0x8(%rsp)
movl 0x14(%rsp), %ecx
andl %edx, %ecx
orl %eax, %ecx
andl $0x0, 0xc(%rsp)
movl %ecx, 0x14(%rsp)
andl $0x0, 0x18(%rsp)
movq %r12, %rdi
movq %r13, %rsi
leaq 0x14(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movl %r14d, %r8d
callq 0xa236e
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
leaq 0x14(%rsp), %rcx
leaq 0x8(%rsp), %r8
movss 0x21aeb6(%rip), %xmm0   # 0x229bb8
movl %r14d, %r9d
callq 0xa2418
movl 0x8(%rsp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl %eax, 0x18(%rsp)
jbe 0xed2b
movb $0x0, (%rbx,%rbp)
incq 0x20(%rsp)
incq 0x28(%rsp)
jmp 0xed2f
incq (%rsp)
movq 0x30(%rsp), %r13
leaq 0x27c4f5(%rip), %rcx    # 0x28b230
incq %rbp
addq $0x18, %r12
addq $0xc, %r15
cmpq %rbp, %r13
jne 0xec7b
cmpq $0x0, 0x28(%rsp)
sete %al
jmp 0xed64
movb $0x1, %al
movq $0x0, (%rsp)
testb %al, %al
je 0xec55
movq 0x27b26d(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x21df37(%rip), %rsi    # 0x22ccb4
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