// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
callq 0x1b7cc0
movsd %xmm0, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x26868c
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq $0x0, 0xc8(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq $0x0, 0xc0(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x26863a
movq -0x10(%rbp), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x21f(%rip), %rsi       # 0x2688c0
callq 0x16d710
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x268708
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq 0xc0(%rax), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq 0xc8(%rax), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x2686ae
cmpq $0x0, -0x20(%rbp)
jl 0x268834
cmpq $0x0, 0x15cf0d(%rip)    # 0x3c5628
jne 0x268744
movq -0x18(%rbp), %rax
movq %rax, 0x15cef8(%rip)    # 0x3c5620
movq %rax, 0x15cee9(%rip)    # 0x3c5618
movq -0x18(%rbp), %rdi
movl $0x18, %esi
callq 0x2140
movq %rax, 0x15cee4(%rip)    # 0x3c5628
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x26879e
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq $0x0, 0xc8(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq $0x0, 0xc0(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x26874c
movq -0x10(%rbp), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x2ad(%rip), %rsi       # 0x268a60
callq 0x16d710
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x26881a
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq 0xc0(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x5c0, -0x30(%rbp), %rcx # imm = 0x5C0
addq %rcx, %rax
movq 0xc8(%rax), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x2687c0
movq -0x10(%rbp), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0xa31(%rip), %rsi       # 0x269260
callq 0x16d710
cmpq $0x0, -0x20(%rbp)
jl 0x268877
movq 0x15b79e(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x1b7cc0
movq -0x58(%rbp), %rdi
subsd -0x28(%rbp), %xmm0
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
leaq 0x127a7f(%rip), %rsi    # 0x3902ed
movb $0x1, %al
callq 0x22a0
jmp 0x2688a9
movq 0x15b762(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x1b7cc0
movq -0x60(%rbp), %rdi
subsd -0x28(%rbp), %xmm0
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
leaq 0x127aa6(%rip), %rsi    # 0x390348
movb $0x1, %al
callq 0x22a0
movq -0x40(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)