// File: /workspace/github_c_makefile_star2_O0/opencoff[P]crypto-rand/t_arc4rand_bench.c
// Function: bench
static void
bench(int fd, size_t siz, size_t niter)
{
    size_t j;
    uint8_t *buf = malloc(siz);
    uint64_t s0, s1, s2;
    uint64_t ta = 0;    // cumulative time for arc4rand
    uint64_t ts = 0;    // cumulative time for system rand
    ssize_t m;

    crypto_rand_state st;

    int r = crypto_rand_init(&st, CRYPTO_RAND_CHACHA20, getentropy);
    assert(r == 0);

    for (j = 0; j < niter; ++j) {
        s0 = sys_cpu_timestamp();
        crypto_rand_buf(&st, buf, siz);
        s1 = sys_cpu_timestamp();
        m  =  read(fd, buf, siz);
        s2 = sys_cpu_timestamp();

        if (m < 0) error(1, errno, "Partial read from /dev/urandom; exp %d, saw %d", siz, m);

        ta += s1 - s0;
        ts += s2 - s1;
    }

#define _d(x)   ((double)(x))
    double aa = _d(ta) / _d(niter);     // average of n runs for arc4random
    double as = _d(ts) / _d(niter);     // average of n runs for sysrand
    double sa = aa / _d(siz);           // cycles/byte for arc4random
    double ss = as / _d(siz);           // cycles/byte for sysrand

    double speedup = ss / sa;

    printf("%6lu, %9.4f,\t%9.4f,\t%6.2f\n", siz, sa, ss, speedup);

    free(buf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5c0, %rsp            # imm = 0x5C0
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10c0
movq %rax, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
leaq -0x588(%rbp), %rdi
movl $0x2, %esi
leaq 0x293a(%rip), %rdx      # 0x3c70
callq 0x1590
movl %eax, -0x58c(%rbp)
cmpl $0x0, -0x58c(%rbp)
jne 0x134c
jmp 0x136b
leaq 0x2d29(%rip), %rdi      # 0x407c
leaq 0x2d29(%rip), %rsi      # 0x4083
movl $0x23, %edx
leaq 0x2d30(%rip), %rcx      # 0x4096
callq 0x1060
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x141e
callq 0x1560
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x588(%rbp), %rdi
callq 0x1860
callq 0x1560
movq %rax, -0x38(%rbp)
movl -0x4(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x1090
movq %rax, -0x58(%rbp)
callq 0x1560
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x58(%rbp)
jge 0x13ed
callq 0x1040
movl (%rax), %esi
movq -0x10(%rbp), %rcx
movq -0x58(%rbp), %r8
movl $0x1, %edi
leaq 0x2cd0(%rip), %rdx      # 0x40b6
movb $0x0, %al
callq 0x3b50
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1373
movq -0x48(%rbp), %xmm0
movaps 0x2be6(%rip), %xmm3     # 0x4010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x2bea(%rip), %xmm2     # 0x4020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x18(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm4
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x598(%rbp)
movq -0x50(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x18(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm4
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x5a0(%rbp)
movsd -0x598(%rbp), %xmm0
movq -0x10(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm4
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x5a8(%rbp)
movsd -0x5a0(%rbp), %xmm0
movq -0x10(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x5b0(%rbp)
movsd -0x5b0(%rbp), %xmm0
divsd -0x5a8(%rbp), %xmm0
movsd %xmm0, -0x5b8(%rbp)
movq -0x10(%rbp), %rsi
movsd -0x5a8(%rbp), %xmm0
movsd -0x5b0(%rbp), %xmm1
movsd -0x5b8(%rbp), %xmm2
leaq 0x2bad(%rip), %rdi      # 0x40e5
movb $0x3, %al
callq 0x1050
movq -0x28(%rbp), %rdi
callq 0x1030
addq $0x5c0, %rsp            # imm = 0x5C0
popq %rbp
retq
nopw %cs:(%rax,%rax)