// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: cal_sec_ec_multiple(ec_ovec_buf_t*, unsigned long, unsigned long, long)
uint64_t cal_sec_ec_multiple(ec_ovec_buf_t *b, uint64_t n_thre, uint64_t n_a, int64_t round)
{
    double tt0 = yak_realtime_0();
    uint64_t k, num_base, num_correct, rb, urb;
    num_base = num_correct = 0;
    
    ////counting
    rb = urb = 0;
    for (k = 0; k < n_thre; ++k) b->a[k].cnt[0] = b->a[k].cnt[1] = 0;

    kt_for(n_thre, worker_hap_dc_ec, b, n_a);///debug_for_fix
    
    for (k = 0; k < n_thre; ++k) {
        rb += b->a[k].cnt[0]; urb += b->a[k].cnt[1];
    }

    if(round >= 0) {
        if(!(sca.a)) {
            sca.n = sca.m = n_a; CALLOC(sca.a, n_a);
        }
        ////correct
        
        for (k = 0; k < n_thre; ++k) b->a[k].cnt[0] = b->a[k].cnt[1] = 0;
        
        kt_for(n_thre, worker_hap_dc_ec0, b, n_a);///debug_for_fix

        for (k = 0; k < n_thre; ++k) {
            num_base += b->a[k].cnt[0];
            num_correct += b->a[k].cnt[1];
        }

        kt_for(n_thre, update_scb0, b, n_a);
    }

    if(round >= 0) {
        fprintf(stderr, "[M::sec::%.3f] # bases: %lu; # corrected bases: %lu; # reads: %lu; # corrected reads: %lu\n", yak_realtime_0()-tt0, num_base, num_correct, rb, urb);
    } else {
        fprintf(stderr, "[M::sec::%.3f] # reads: %lu; # corrected reads: %lu\n", yak_realtime_0()-tt0, rb, urb);
    }

    // fprintf(stderr, "\n[M::%s] # reads->%lu\n", __func__, n_a);
    // fprintf(stderr, "[M::%s] # corrected reads->%lu\n", __func__, rb);
    // fprintf(stderr, "[M::%s] # uncorrected reads->%lu\n", __func__, urb);
    // if(round >= 0) {
    //     fprintf(stderr, "[M::%s] # input bases->%lu\n", __func__, num_base);
    //     fprintf(stderr, "[M::%s] # corrected bases->%lu\n", __func__, num_correct);
    //     fprintf(stderr, "[M::%s::%.3f] ==> round %ld\n", __func__, yak_realtime_0()-tt0, round);
    // }
    return num_correct;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbp
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movl $0xc0, %ebx
callq 0xefeb7
movsd %xmm0, 0x8(%rsp)
xorpd %xmm0, %xmm0
movq %r15, %rax
subq $0x1, %rax
jb 0x14cbdb
movq (%r14), %rcx
movupd %xmm0, (%rcx,%rbx)
addq $0x5c0, %rbx            # imm = 0x5C0
jmp 0x14cbc4
leaq 0x155(%rip), %rsi       # 0x14cd37
movl %r15d, %edi
movq %r14, %rdx
movq 0x10(%rsp), %rbx
movq %rbx, %rcx
callq 0xc67c0
movl $0xc8, %eax
xorl %r12d, %r12d
movq %r15, %rcx
xorl %r13d, %r13d
subq $0x1, %rcx
jb 0x14cc1d
movq (%r14), %rdx
addq -0x8(%rdx,%rax), %r12
addq (%rdx,%rax), %r13
addq $0x5c0, %rax            # imm = 0x5C0
jmp 0x14cc03
testq %rbp, %rbp
js 0x14cc6e
cmpq $0x0, 0x10795e(%rip)    # 0x254588
jne 0x14cc4c
movq %rbx, 0x10794d(%rip)    # 0x254580
movq %rbx, 0x10793e(%rip)    # 0x254578
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x2120
movq %rax, 0x10793c(%rip)    # 0x254588
movl $0xc0, %eax
xorpd %xmm0, %xmm0
movq %r15, %rcx
subq $0x1, %rcx
jb 0x14cca1
movq (%r14), %rdx
movupd %xmm0, (%rdx,%rax)
addq $0x5c0, %rax            # imm = 0x5C0
jmp 0x14cc58
movq 0x10636b(%rip), %rax    # 0x252fe0
movq (%rax), %rbx
callq 0xefeb7
subsd 0x8(%rsp), %xmm0
leaq 0xa499f(%rip), %rsi     # 0x1f1629
movq %rbx, %rdi
movq %r12, %rdx
movq %r13, %rcx
movb $0x1, %al
callq 0x22b0
xorl %ebp, %ebp
jmp 0x14cd25
leaq 0x197(%rip), %rsi       # 0x14ce3f
movl %r15d, %edi
movq %r14, %rdx
movq %rbx, %rcx
callq 0xc67c0
movl $0xc8, %eax
xorl %ebx, %ebx
movq %r15, %rcx
xorl %ebp, %ebp
subq $0x1, %rcx
jb 0x14ccdc
movq (%r14), %rdx
addq -0x8(%rdx,%rax), %rbx
addq (%rdx,%rax), %rbp
addq $0x5c0, %rax            # imm = 0x5C0
jmp 0x14ccc2
leaq 0x611(%rip), %rsi       # 0x14d2f4
movl %r15d, %edi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
callq 0xc67c0
movq 0x1062e6(%rip), %rax    # 0x252fe0
movq (%rax), %r14
callq 0xefeb7
subsd 0x8(%rsp), %xmm0
leaq 0xa48bf(%rip), %rsi     # 0x1f15ce
movq %r14, %rdi
movq %rbx, %rdx
movq %rbp, %rcx
movq %r12, %r8
movq %r13, %r9
movb $0x1, %al
callq 0x22b0
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq