// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x18, %rsp
movsd %xmm0, 0x10(%rsp)
movl %esi, %ebp
movq %rdi, %r14
callq 0x3ea9
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x3ced
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rdi
movl $0x8, %esi
callq 0x4503
xorl %r15d, %r15d
testq %rax, %rax
je 0x3d36
movq 0x20(%r14), %rdi
movl $0x8, %edx
movq %r15, %rsi
callq 0x4645
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpl %ebp, (%rax)
je 0x3d36
incq %r15
movq 0x20(%r14), %rdi
movl $0x8, %esi
callq 0x4503
cmpq %rax, %r15
jb 0x3d03
movq 0x20(%r14), %rdi
movl $0x8, %esi
callq 0x4503
cmpq %rax, %r15
jne 0x3df5
movl $0x30, %edi
callq 0x22a0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3ce0
movl %ebp, (%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
movsd 0x86e0(%rip), %xmm0     # 0xc458
callq 0x9110
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx)
testq %rax, %rax
je 0x3de6
movsd 0x86cd(%rip), %xmm0     # 0xc460
callq 0x9110
movq 0x8(%rsp), %rcx
movq %rax, 0x20(%rcx)
testq %rax, %rax
je 0x3dd8
movq $0x0, 0x28(%rcx)
movq 0x20(%r14), %rdi
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
movl $0x8, %ecx
callq 0x450c
testl %eax, %eax
je 0x3df5
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x9757
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x9757
movq 0x8(%rsp), %rdi
callq 0x2040
jmp 0x3ce0
movq 0x20(%r14), %rdi
movl $0x8, %edx
movq %r15, %rsi
callq 0x4645
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rax), %rcx
incq %rcx
movq %rcx, 0x8(%rax)
movsd 0x10(%rax), %xmm4
movsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
movq %rcx, %xmm2
punpckldq 0x863b(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x8643(%rip), %xmm2     # 0xc480
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 0x93b3
testl %eax, %eax
jne 0x3ce0
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
movsd 0x10(%rsp), %xmm0
callq 0x93b3
testl %eax, %eax
jne 0x3ce0
movq 0x8(%rsp), %rax
xorl %ebx, %ebx
movsd 0x10(%rsp), %xmm0
ucomisd 0x28(%rax), %xmm0
jbe 0x3ce0
movsd %xmm0, 0x28(%rax)
jmp 0x3ce0