// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: cal_ec_multiple(ec_ovec_buf_t*, unsigned long, unsigned long, unsigned long*)
uint64_t cal_ec_multiple(ec_ovec_buf_t *b, uint64_t n_thre, uint64_t n_a, uint64_t *r_base)
{
    double tt0 = yak_realtime_0();
    uint64_t k, num_base = 0, num_correct = 0; (*r_base) = 0;

    if(!(scc.a)) {
        scc.n = scc.m = n_a; CALLOC(scc.a, n_a); CALLOC(scc.f, n_a);
    }

    if(!(scb.a)) {
        scb.n = scb.m = n_a; CALLOC(scb.a, n_a);
    }

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

    kt_for(n_thre, worker_hap_ec, 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];
    }

    // fprintf(stderr, "\n[M::%s] # reads->%lu\n", __func__, n_a);
    // 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] running time\n", __func__, yak_realtime_0()-tt0);
    fprintf(stderr, "[M::pec::%.3f] # bases: %lu; # corrected bases: %lu\n", yak_realtime_0()-tt0, num_base, num_correct);

    (*r_base) = num_base;
    return num_correct;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %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, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, 0x15ea33(%rip)    # 0x3c55e8
jne 0x266bf3
movq -0x18(%rbp), %rax
movq %rax, 0x15ea1e(%rip)    # 0x3c55e0
movq %rax, 0x15ea0f(%rip)    # 0x3c55d8
movq -0x18(%rbp), %rdi
movl $0x18, %esi
callq 0x2140
movq %rax, 0x15ea0a(%rip)    # 0x3c55e8
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, 0x15e9fd(%rip)    # 0x3c55f0
cmpq $0x0, 0x15ea0d(%rip)    # 0x3c5608
jne 0x266c24
movq -0x18(%rbp), %rax
movq %rax, 0x15e9f8(%rip)    # 0x3c5600
movq %rax, 0x15e9e9(%rip)    # 0x3c55f8
movq -0x18(%rbp), %rdi
movl $0x18, %esi
callq 0x2140
movq %rax, 0x15e9e4(%rip)    # 0x3c5608
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x266c7e
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 0x266c2c
movq -0x10(%rbp), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0xbd(%rip), %rsi        # 0x266d50
callq 0x16d710
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x266cfa
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 0x266ca0
movq 0x15d2df(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
callq 0x1b7cc0
movq -0x48(%rbp), %rdi
subsd -0x28(%rbp), %xmm0
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
leaq 0x129432(%rip), %rsi    # 0x390157
movb $0x1, %al
callq 0x22a0
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)