// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x2510
movsd %xmm0, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x1, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x161b2b
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x161b26
movq -0x18(%rbp), %rax
imulq $0xc, -0x28(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1619e2
jmp 0x161b15
leaq 0x2638e7(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x161a05
jmp 0x161b15
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
leaq 0x2638b8(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
movl -0x60(%rbp), %eax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x54(%rbp), %eax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
imulq $0x18, -0x28(%rbp), %rax
addq %rax, %rdi
leaq 0x263863(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x30(%rbp), %rax
movl %eax, %r8d
leaq -0x54(%rbp), %rdx
leaq -0x60(%rbp), %rcx
callq 0xd19f0
movq -0x8(%rbp), %rdi
imulq $0x18, -0x28(%rbp), %rax
addq %rax, %rdi
leaq 0x263830(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x30(%rbp), %rax
movl %eax, %r9d
xorl %eax, %eax
movl %eax, %esi
leaq -0x54(%rbp), %rcx
leaq -0x60(%rbp), %r8
movss 0x224dd1(%rip), %xmm0   # 0x386898
callq 0xd1b50
movl -0x50(%rbp), %eax
movl -0x60(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jbe 0x161b13
leaq 0x2637ed(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x161b15
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1619b9
jmp 0x161996
movq 0x2624ae(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
leaq 0x227f87(%rip), %rsi    # 0x389acf
movb $0x0, %al
callq 0x22a0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)