// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]libcperciva/liball/../util/perftest.c
// Function: perftest_buffers
int
perftest_buffers(size_t nbytes, const size_t * sizes, size_t nsizes,
    size_t nbytes_warmup, int cputime,
    int init_func(void *, uint8_t *, size_t),
    int func(void *, uint8_t *, size_t, size_t),
    int clean_func(void *), void * cookie)
{
	uint8_t * buf;
	struct timeval begin, end;
	double * delta_s;
	double speed;
	size_t i;
	size_t buflen;
	size_t num_buffers;
	size_t nbuffers_warmup;
	size_t nbytes_in_buffer;
	size_t max_buflen = 0;

	/* Find the maximum buffer size. */
	for (i = 0; i < nsizes; i++) {
		if (max_buflen < sizes[i])
			max_buflen = sizes[i];
	}
	assert(max_buflen > 0);

	/* Allocate buffers. */
	if ((buf = malloc(max_buflen)) == NULL) {
		warnp("malloc");
		goto err0;
	}
	if ((delta_s = malloc(nsizes * sizeof(double))) == NULL) {
		warnp("malloc");
		goto err1;
	}

	/* Warm up. */
	if (nbytes_warmup > 0) {
		nbuffers_warmup = nbytes_warmup / max_buflen;
		if (init_func && init_func(cookie, buf, max_buflen))
			goto err2;
		if (func(cookie, buf, max_buflen, nbuffers_warmup))
			goto err3;
		if (clean_func && clean_func(cookie))
			goto err2;
	}

	/* Run operations. */
	for (i = 0; i < nsizes; i++) {
		/* Configure and sanity checks. */
		buflen = sizes[i];
		assert(buflen > 0);
		num_buffers = nbytes / buflen;

		/* Set up. */
		if (init_func && init_func(cookie, buf, buflen))
			goto err2;

		/* Get beginning time. */
		if (cputime) {
			if (monoclock_get_cputime(&begin)) {
				warnp("monoclock_get_cputime()");
				goto err3;
			}
		} else {
			if (monoclock_get(&begin)) {
				warnp("monoclock_get()");
				goto err3;
			}
		}

		/* Time actual code. */
		if (func(cookie, buf, buflen, num_buffers))
			goto err3;

		/* Get ending time. */
		if (cputime) {
			if (monoclock_get_cputime(&end)) {
				warnp("monoclock_get_cputime()");
				goto err3;
			}
		} else {
			if (monoclock_get(&end)) {
				warnp("monoclock_get()");
				goto err3;
			}
		}

		/* Store time. */
		delta_s[i] = timeval_diff(begin, end);

		/* Clean up. */
		if (clean_func && clean_func(cookie))
			goto err2;
	}

	/* Print output. */
	for (i = 0; i < nsizes; i++) {
		buflen = sizes[i];
		num_buffers = nbytes / buflen;

		/* We might not be processing an integer number of buffers. */
		nbytes_in_buffer = buflen * num_buffers;
		speed = (double)nbytes_in_buffer / 1e6 / delta_s[i];

		/* Print output. */
		printf("%zu blocks of size %zu\t%.06f s\t%.06f MB/s\n",
		    num_buffers, buflen, delta_s[i], speed);
	}

	/* Clean up. */
	free(delta_s);
	free(buf);

	/* Success! */
	return (0);

err3:
	if (clean_func)
		clean_func(cookie);
err2:
	free(delta_s);
err1:
	free(buf);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r15
movl %r8d, 0x14(%rsp)
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, 0x20(%rsp)
xorl %eax, %eax
xorl %ebx, %ebx
cmpq %rax, %r12
je 0x23d2
movq (%r13,%rax,8), %rcx
cmpq %rcx, %rbx
cmovbeq %rcx, %rbx
incq %rax
jmp 0x23bc
testq %rbx, %rbx
je 0x2741
movq %rbx, %rdi
callq 0x1140
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x25a0
leaq (,%r12,8), %rdi
callq 0x1140
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x25c3
testq %rbp, %rbp
je 0x2480
movq %rbp, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %rbp
testq %r15, %r15
je 0x243c
movq 0x90(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq *%r15
testl %eax, %eax
jne 0x2702
movq 0x90(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq *0x80(%rsp)
testl %eax, %eax
jne 0x26e8
cmpq $0x0, 0x88(%rsp)
je 0x2480
movq 0x90(%rsp), %rdi
callq *0x88(%rsp)
testl %eax, %eax
jne 0x2702
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x2629
movq (%r13,%r14,8), %rbx
testq %rbx, %rbx
je 0x2728
movq 0x20(%rsp), %rax
xorl %edx, %edx
divq %rbx
movq %rax, %rbp
testq %r15, %r15
je 0x24c7
movq 0x90(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq *%r15
testl %eax, %eax
jne 0x2702
cmpl $0x0, 0x14(%rsp)
je 0x24e1
leaq 0x38(%rsp), %rdi
callq 0x2bb4
testl %eax, %eax
je 0x24f3
jmp 0x260c
leaq 0x38(%rsp), %rdi
callq 0x2af0
testl %eax, %eax
jne 0x26b1
movq 0x90(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq *0x80(%rsp)
testl %eax, %eax
jne 0x26e8
cmpl $0x0, 0x14(%rsp)
je 0x252f
leaq 0x28(%rsp), %rdi
callq 0x2bb4
testl %eax, %eax
je 0x2541
jmp 0x260c
leaq 0x28(%rsp), %rdi
callq 0x2af0
testl %eax, %eax
jne 0x26b1
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
subq 0x38(%rsp), %rax
subq 0x40(%rsp), %rcx
cvtsi2sd %rax, %xmm0
cvtsi2sd %rcx, %xmm1
mulsd 0xee9(%rip), %xmm1      # 0x3450
addsd %xmm0, %xmm1
movq 0x18(%rsp), %rax
movsd %xmm1, (%rax,%r14,8)
cmpq $0x0, 0x88(%rsp)
je 0x2598
movq 0x90(%rsp), %rdi
callq *0x88(%rsp)
testl %eax, %eax
jne 0x2702
incq %r14
jmp 0x2483
callq 0x1080
cmpl $0x0, (%rax)
je 0x25e6
movq %rax, %rbx
leaq 0xf99(%rip), %rdi       # 0x354d
xorl %eax, %eax
callq 0x27dd
andl $0x0, (%rbx)
jmp 0x2716
callq 0x1080
cmpl $0x0, (%rax)
je 0x25f9
movq %rax, %rbx
leaq 0xf76(%rip), %rdi       # 0x354d
xorl %eax, %eax
callq 0x27dd
andl $0x0, (%rbx)
jmp 0x270c
leaq 0xf60(%rip), %rdi       # 0x354d
xorl %eax, %eax
callq 0x296c
jmp 0x2716
leaq 0xf4d(%rip), %rdi       # 0x354d
xorl %eax, %eax
callq 0x296c
jmp 0x270c
callq 0x1080
cmpl $0x0, (%rax)
je 0x26d1
movq %rax, %rbx
leaq 0xf30(%rip), %rdi       # 0x3554
jmp 0x26c5
xorl %r14d, %r14d
leaq 0xf49(%rip), %rbx       # 0x357c
movq 0x18(%rsp), %r15
cmpq %r14, %r12
je 0x269b
movq (%r13,%r14,8), %rcx
movq 0x20(%rsp), %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rdx
imulq %rcx, %rdx
movq %rdx, %xmm0
punpckldq 0xe00(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xe08(%rip), %xmm0      # 0x3470
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0xddc(%rip), %xmm1      # 0x3458
movsd (%r15,%r14,8), %xmm0
divsd %xmm0, %xmm1
movq %rbx, %rdi
movq %rax, %rsi
movq %rcx, %rdx
movb $0x2, %al
callq 0x10d0
incq %r14
jmp 0x2638
movq %r15, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
xorl %eax, %eax
jmp 0x2719
callq 0x1080
cmpl $0x0, (%rax)
je 0x26da
movq %rax, %rbx
leaq 0xea7(%rip), %rdi       # 0x356c
xorl %eax, %eax
callq 0x27dd
andl $0x0, (%rbx)
jmp 0x26e8
leaq 0xe7c(%rip), %rdi       # 0x3554
jmp 0x26e1
leaq 0xe8b(%rip), %rdi       # 0x356c
xorl %eax, %eax
callq 0x296c
cmpq $0x0, 0x88(%rsp)
je 0x2702
movq 0x90(%rsp), %rdi
callq *0x88(%rsp)
movq 0x18(%rsp), %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
pushq $-0x1
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd55(%rip), %rdi       # 0x3484
leaq 0xd59(%rip), %rsi       # 0x348f
leaq 0xd65(%rip), %rcx       # 0x34a2
pushq $0x50
jmp 0x2758
leaq 0xd38(%rip), %rdi       # 0x3480
leaq 0xd40(%rip), %rsi       # 0x348f
leaq 0xd4c(%rip), %rcx       # 0x34a2
pushq $0x35
popq %rdx
callq 0x10e0
nop