// File: /workspace/github_c_makefile_star2_O3/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 0x3ebb
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x3d09
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rdi
movl $0x8, %esi
callq 0x450a
xorl %r15d, %r15d
testq %rax, %rax
je 0x3d51
movq 0x20(%r14), %rdi
movl $0x8, %edx
movq %r15, %rsi
callq 0x464c
movq (%rax), %rax
movq %rax, (%rsp)
cmpl %ebp, (%rax)
je 0x3d51
incq %r15
movq 0x20(%r14), %rdi
movl $0x8, %esi
callq 0x450a
cmpq %rax, %r15
jb 0x3d1f
movq 0x20(%r14), %rdi
movl $0x8, %esi
callq 0x450a
cmpq %rax, %r15
jne 0x3e0a
movl $0x30, %edi
callq 0x22a0
movq %rax, (%rsp)
testq %rax, %rax
je 0x3cfa
movq %rax, %r12
movl %ebp, (%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
movsd 0x9663(%rip), %xmm0     # 0xd3f8
callq 0x91b0
movq %rax, 0x18(%r12)
testq %rax, %rax
je 0x3dfd
movsd 0x9654(%rip), %xmm0     # 0xd400
callq 0x91b0
movq %rax, 0x20(%r12)
testq %rax, %rax
je 0x3def
movq $0x0, 0x28(%r12)
movq 0x20(%r14), %rdi
movq %rsp, %rsi
movl $0x1, %edx
movl $0x8, %ecx
callq 0x4513
testl %eax, %eax
je 0x3e0a
movq (%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x97b3
movq (%rsp), %r12
movq 0x18(%r12), %rdi
callq 0x97b3
movq (%rsp), %r12
movq %r12, %rdi
callq 0x2040
jmp 0x3cfa
movq 0x20(%r14), %rdi
movl $0x8, %edx
movq %r15, %rsi
callq 0x464c
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 0x95c7(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x95cf(%rip), %xmm2     # 0xd420
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 0x9442
testl %eax, %eax
jne 0x3cfa
movq (%rsp), %rax
movq 0x20(%rax), %rdi
movsd 0x8(%rsp), %xmm0
callq 0x9442
testl %eax, %eax
jne 0x3cfa
movq (%rsp), %rax
xorl %ebx, %ebx
movsd 0x8(%rsp), %xmm0
ucomisd 0x28(%rax), %xmm0
jbe 0x3cfa
movsd %xmm0, 0x28(%rax)
jmp 0x3cfa