// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rsi, %r12
movq %rdi, %r14
callq 0x13662b
movsd %xmm0, 0x8(%rsp)
testq %r12, %r12
jne 0x193368
leaq 0x1b5(%rip), %rsi       # 0x193500
movq $0x0, (%rsp)
xorl %edi, %edi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x108f2c
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x1933c5
movl $0xc0, %eax
addq (%r14), %rax
xorpd %xmm0, %xmm0
movq %r12, %rcx
movupd %xmm0, (%rax)
addq $0x5c0, %rax            # imm = 0x5C0
decq %rcx
jne 0x193377
leaq 0x173(%rip), %rsi       # 0x193500
movl %r12d, %edi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x108f2c
movl $0xc8, %eax
addq (%r14), %rax
xorl %r15d, %r15d
movq %r12, %rcx
xorl %r13d, %r13d
addq -0x8(%rax), %r13
addq (%rax), %r15
addq $0x5c0, %rax            # imm = 0x5C0
decq %rcx
jne 0x1933ac
movl %r12d, %eax
movq %rax, (%rsp)
testq %rbp, %rbp
js 0x19341f
cmpq $0x0, 0x1031b6(%rip)    # 0x296588
jne 0x1933f6
movq %rbx, 0x1031a5(%rip)    # 0x296580
movq %rbx, 0x103196(%rip)    # 0x296578
movl $0x18, %esi
movq %rbx, %rdi
callq 0x2120
movq %rax, 0x103192(%rip)    # 0x296588
testq %r12, %r12
movq %rbx, 0x10(%rsp)
jne 0x193452
leaq 0x207(%rip), %rsi       # 0x19360e
movq (%rsp), %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x108f2c
xorl %ebx, %ebx
xorl %ebp, %ebp
jmp 0x1934a4
movq 0x101bba(%rip), %rax    # 0x294fe0
movq (%rax), %rbx
callq 0x13662b
subsd 0x8(%rsp), %xmm0
leaq 0xac32e(%rip), %rsi     # 0x23f769
movq %rbx, %rdi
movq %r13, %rdx
movq %r15, %rcx
movb $0x1, %al
callq 0x22b0
xorl %ebp, %ebp
jmp 0x1934ee
movl $0xc0, %eax
addq (%r14), %rax
xorpd %xmm0, %xmm0
movq %r12, %rcx
movupd %xmm0, (%rax)
addq $0x5c0, %rax            # imm = 0x5C0
decq %rcx
jne 0x193461
leaq 0x197(%rip), %rsi       # 0x19360e
movq (%rsp), %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x108f2c
movl $0xc8, %eax
addq (%r14), %rax
xorl %ebp, %ebp
xorl %ebx, %ebx
addq -0x8(%rax), %rbx
addq (%rax), %rbp
addq $0x5c0, %rax            # imm = 0x5C0
decq %r12
jne 0x193492
leaq 0x6da(%rip), %rsi       # 0x193b85
movq (%rsp), %rdi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
callq 0x108f2c
movq 0x101b1d(%rip), %rax    # 0x294fe0
movq (%rax), %r14
callq 0x13662b
subsd 0x8(%rsp), %xmm0
leaq 0xac236(%rip), %rsi     # 0x23f70e
movq %r14, %rdi
movq %rbx, %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %r15, %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