// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/perf/perfstats.c
// Function: flush
static int
flush(struct perfstats * P)
{
	STR logline;
	struct reqstats * r;
	struct reqstats ** rs;
	double p50, p99;
	char * s;
	size_t linelen;
	size_t nrs;
	size_t i, j;

	/* Export statistics from the elastic array. */
	if (reqstatslist_exportdup(P->stats, &rs, &nrs))
		goto err0;

	/* Sort the statistics by request type. */
	for (i = 0; i < nrs; i++) {
		for (j = i + 1; j < nrs; j++) {
			if (rs[i]->reqtype > rs[j]->reqtype) {
				r = rs[i];
				rs[i] = rs[j];
				rs[j] = r;
			}
		}
	}

	/* Gather statistics for each request type. */
	if ((logline = str_init(0)) == NULL)
		goto err1;
	for (i = 0; i < nrs; i++) {
		r = rs[i];
		onlinequantile_get(r->p50, &p50);
		onlinequantile_get(r->p99, &p99);
		if (asprintf(&s, "|%s|%06zu|%08.3f|%08.3f|%08.3f|%08.3f",
		    reqtypes_lookup(r->reqtype), r->N, 1000 * r->mu,
		        1000 * p50, 1000 * p99, 1000 * r->p100) == -1)
			goto err2;
		if (str_append(logline, s, strlen(s)))
			goto err3;
		free(s);
	}
	if (str_append(logline, "\0", 1))
		goto err2;
	if (str_export(logline, &s, &linelen))
		goto err2;
	logging_printf(P->L, "%s", s);
	free(s);

	/* Free the statistics and empty the elastic array. */
	for (i = 0; i < nrs; i++) {
		r = rs[i];
		onlinequantile_free(r->p99);
		onlinequantile_free(r->p50);
		free(r);
	}
	free(rs);
	reqstatslist_resize(P->stats, 0);

	/* Success! */
	return (0);

err3:
	free(s);
err2:
	str_free(logline);
err1:
	free(rs);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x48c0
cmpl $0x0, %eax
je 0x45fb
jmp 0x48a8
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x46a0
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x468d
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl (%rcx), %eax
jbe 0x467d
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x467f
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x461d
jmp 0x468f
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x4603
xorl %eax, %eax
movl %eax, %edi
callq 0x48f0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x46b8
jmp 0x489f
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x47bb
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0xc9c0
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0xc9c0
movq -0x20(%rbp), %rax
movl (%rax), %edi
callq 0x49d0
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movsd 0xde9e(%rip), %xmm0     # 0x125c0
mulsd 0x10(%rax), %xmm0
movsd 0xde91(%rip), %xmm1     # 0x125c0
mulsd -0x30(%rbp), %xmm1
movsd 0xde84(%rip), %xmm2     # 0x125c0
mulsd -0x38(%rbp), %xmm2
movq -0x20(%rbp), %rax
movsd 0xde73(%rip), %xmm3     # 0x125c0
mulsd 0x28(%rax), %xmm3
leaq -0x40(%rbp), %rdi
leaq 0xde93(%rip), %rsi      # 0x125f0
movb $0x4, %al
callq 0x8e20
cmpl $-0x1, %eax
jne 0x476e
jmp 0x4896
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2160
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
callq 0x4920
cmpl $0x0, %eax
je 0x47a1
jmp 0x488d
movq -0x40(%rbp), %rdi
callq 0x2040
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x46c0
movq -0x18(%rbp), %rdi
leaq 0xde50(%rip), %rsi      # 0x12616
movl $0x1, %edx
callq 0x4920
cmpl $0x0, %eax
je 0x47da
jmp 0x4896
movq -0x18(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x4950
cmpl $0x0, %eax
je 0x47f5
jmp 0x4896
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
leaq 0xd97c(%rip), %rsi      # 0x12183
movb $0x0, %al
callq 0xd670
movq -0x40(%rbp), %rdi
callq 0x2040
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x486a
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xd040
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xd040
movq -0x20(%rbp), %rdi
callq 0x2040
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x481f
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4980
movl $0x0, -0x4(%rbp)
jmp 0x48af
movq -0x40(%rbp), %rdi
callq 0x2040
movq -0x18(%rbp), %rdi
callq 0x49b0
movq -0x28(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)