// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/perf/perfstats.c
// Function: perfstats_add
int
perfstats_add(struct perfstats * P, uint32_t reqtype, double t)
{
	struct reqstats * r;
	size_t i;

	/* Flush statistics if appropriate. */
	if (poke(P))
		goto err0;

	/* Do we have statistics for this request type yet? */
	for (i = 0; i < reqstatslist_getsize(P->stats); i++) {
		r = *reqstatslist_get(P->stats, i);
		if (r->reqtype == reqtype)
			break;
	}

	/* If not, allocate a new structure and add it. */
	if (i == reqstatslist_getsize(P->stats)) {
		/* Allocate a new structure. */
		if ((r = malloc(sizeof(struct reqstats))) == NULL)
			goto err0;
		r->reqtype = reqtype;
		r->N = 0;
		r->mu = 0.0;
		if ((r->p50 = onlinequantile_init(0.50)) == NULL)
			goto err1;
		if ((r->p99 = onlinequantile_init(0.99)) == NULL)
			goto err2;
		r->p100 = 0.0;

		/* Add to the elastic array. */
		if (reqstatslist_append(P->stats, &r, 1))
			goto err3;
	}

	/* Add to the statistics for this request type. */
	r = *reqstatslist_get(P->stats, i);
	r->N++;
	r->mu += (t - r->mu) / (double)r->N;
	if (onlinequantile_add(r->p50, t))
		goto err0;
	if (onlinequantile_add(r->p99, t))
		goto err0;
	if (r->p100 < t)
		r->p100 = t;

	/* Success! */
	return (0);

err3:
	onlinequantile_free(r->p99);
err2:
	onlinequantile_free(r->p50);
err1:
	free(r);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movsd %xmm0, 0x8(%rsp)
movl %esi, %ebp
movq %rdi, %r14
callq 0x3823
pushq $-0x1
popq %rbx
testl %eax, %eax
je 0x36a3
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
movq 0x20(%r14), %rdi
callq 0x3865
cmpq %rax, %r15
jae 0x36d0
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x386d
movq (%rax), %rax
movq %rax, (%rsp)
cmpl %ebp, (%rax)
je 0x36d0
incq %r15
jmp 0x36a6
movq 0x20(%r14), %rdi
callq 0x3865
cmpq %r15, %rax
jne 0x3777
pushq $0x30
popq %rdi
callq 0x22a0
movq %rax, (%rsp)
testq %rax, %rax
je 0x3694
movq %rax, %r12
movl %ebp, (%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
movsd 0x7cef(%rip), %xmm0     # 0xb3f8
callq 0x83dc
movq %rax, 0x18(%r12)
testq %rax, %rax
je 0x376a
movsd 0x7ce0(%rip), %xmm0     # 0xb400
callq 0x83dc
movq %rax, 0x20(%r12)
testq %rax, %rax
je 0x375c
andq $0x0, 0x28(%r12)
movq 0x20(%r14), %rdi
movq %rsp, %rsi
pushq $0x1
popq %rdx
pushq $0x8
popq %rcx
callq 0x3df6
testl %eax, %eax
je 0x3777
movq (%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x8892
movq (%rsp), %r12
movq 0x18(%r12), %rdi
callq 0x8892
movq (%rsp), %r12
movq %r12, %rdi
callq 0x2040
jmp 0x3694
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x386d
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x8(%rax), %rcx
incq %rcx
movq %rcx, 0x8(%rax)
movsd 0x10(%rax), %xmm4
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
movq %rcx, %xmm2
punpckldq 0x7c5f(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x7c67(%rip), %xmm2     # 0xb420
subsd %xmm4, %xmm1
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
divsd %xmm3, %xmm1
addsd %xmm4, %xmm1
movsd %xmm1, 0x10(%rax)
movq 0x18(%rax), %rdi
callq 0x8689
testl %eax, %eax
jne 0x3694
movq (%rsp), %rax
movq 0x20(%rax), %rdi
movsd 0x8(%rsp), %xmm0
callq 0x8689
testl %eax, %eax
jne 0x3694
movq (%rsp), %rax
xorl %ebx, %ebx
movsd 0x8(%rsp), %xmm0
ucomisd 0x28(%rax), %xmm0
jbe 0x3694
movsd %xmm0, 0x28(%rax)
jmp 0x3694