// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
callq 0x130403
movsd %xmm0, 0x8(%rsp)
testq %r12, %r12
je 0x18ab26
movl $0xc0, %eax
addq (%r15), %rax
xorpd %xmm0, %xmm0
movq %r12, %rcx
movupd %xmm0, (%rax)
addq $0x5c0, %rax            # imm = 0x5C0
decq %rcx
jne 0x18ab17
leaq 0x15e(%rip), %rsi       # 0x18ac8b
movl %r12d, %edi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1047b4
testq %r12, %r12
jne 0x18ab47
xorl %ebp, %ebp
xorl %r13d, %r13d
jmp 0x18ab69
movl $0xc8, %eax
addq (%r15), %rax
xorl %r13d, %r13d
movq %r12, %rcx
xorl %ebp, %ebp
addq -0x8(%rax), %rbp
addq (%rax), %r13
addq $0x5c0, %rax            # imm = 0x5C0
decq %rcx
jne 0x18ab57
testq %rbx, %rbx
movq %rbx, 0x10(%rsp)
js 0x18abe7
cmpq $0x0, 0x100a0d(%rip)    # 0x28b588
jne 0x18ab9f
movq %r14, 0x1009fc(%rip)    # 0x28b580
movq %r14, 0x1009ed(%rip)    # 0x28b578
movl $0x18, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x1009e9(%rip)    # 0x28b588
testq %r12, %r12
je 0x18abc2
movl $0xc0, %eax
addq (%r15), %rax
xorpd %xmm0, %xmm0
movq %r12, %rcx
movupd %xmm0, (%rax)
addq $0x5c0, %rax            # imm = 0x5C0
decq %rcx
jne 0x18abb3
leaq 0x1e1(%rip), %rsi       # 0x18adaa
movl %r12d, %edi
movq %r15, %rdx
movq %r14, (%rsp)
movq %r14, %rcx
callq 0x1047b4
testq %r12, %r12
jne 0x18abee
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x18ac10
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x18ac26
movl $0xc8, %eax
addq (%r15), %rax
xorl %ebx, %ebx
movq %r12, %rcx
xorl %r14d, %r14d
addq -0x8(%rax), %r14
addq (%rax), %rbx
addq $0x5c0, %rax            # imm = 0x5C0
decq %rcx
jne 0x18abfe
leaq 0x709(%rip), %rsi       # 0x18b320
movl %r12d, %edi
movq %r15, %rdx
movq (%rsp), %rcx
callq 0x1047b4
movq 0xff3b3(%rip), %rax     # 0x289fe0
movq (%rax), %r15
callq 0x130403
subsd 0x8(%rsp), %xmm0
cmpq $0x0, 0x10(%rsp)
js 0x18ac62
leaq 0xa8874(%rip), %rsi     # 0x2334be
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %r13, %r9
movb $0x1, %al
callq 0x22b0
jmp 0x18ac79
leaq 0xa88b0(%rip), %rsi     # 0x233519
movq %r15, %rdi
movq %rbp, %rdx
movq %r13, %rcx
movb $0x1, %al
callq 0x22b0
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq