// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/liball/../lib/datastruct/onlinequantile.c
// Function: onlinequantile_add
int
onlinequantile_add(struct onlinequantile * Q, double x)
{
	size_t i;
	double r;

	/* Figure out where the quantile falls after expansion. */
	hazenquantile(Q->N + 1, Q->q, &i, &r);

	/* Which heap needs to grow? */
	if (i + 1 > Q->N_smaller) {
		/* We need to expand the "smaller than quantile" heap. */

		/* Sanity-check. */
		assert(Q->N_smaller == i);

		if (x <= Q->larger_min) {
			/* Add to "smaller" heap. */
			if (doubleheap_add(Q->smaller, -x))
				goto err0;
			Q->N_smaller += 1;

			/* Update smaller_max if necessary. */
			if (Q->smaller_max < x)
				Q->smaller_max = x;
		} else {
			/*
			 * This value is going into the "larger" heap, but we
			 * want the "smaller" heap to be growing; so we need
			 * to take the least element from "larger" and move it
			 * into "smaller".
			 */

			/* Sanity-check. */
			assert(Q->N_smaller < Q->N);

			/* Add element to "smaller" heap. */
			if (doubleheap_add(Q->smaller, -Q->larger_min))
				goto err0;
			Q->N_smaller += 1;
			Q->smaller_max = Q->larger_min;

			/*
			 * Now replace the value we removed from the "larger"
			 * heap with our new value; and figure out what the
			 * new minimum value in that heap is.
			 */
			doubleheap_setmin(Q->larger, x);
			doubleheap_getmin(Q->larger, &Q->larger_min);
		}
	} else {
		/* We need to expand the "larger than quantile" heap. */

		/* Sanity-check. */
		assert(Q->N_smaller - 1 == i);

		/* Where does the new value land? */
		if (x >= Q->smaller_max) {
			/* Add to "larger" heap. */
			if (doubleheap_add(Q->larger, x))
				goto err0;

			/* Update larger_min if necessary. */
			if (Q->larger_min > x)
				Q->larger_min = x;
		} else {
			/*
			 * This value is going into the "smaller" heap, but we
			 * want the "larger" heap to be growing; so we need
			 * to take the greatest element from "smaller" and move
			 * it into "larger".
			 */

			/* Sanity-check. */
			assert(Q->N_smaller > 0);

			/* Add element to "larger" heap. */
			if (doubleheap_add(Q->larger, Q->smaller_max))
				goto err0;
			Q->larger_min = Q->smaller_max;

			/*
			 * Now replace the value we removed from the "smaller"
			 * heap with our new value; and figure out what the
			 * new maximum value in that heap is.
			 */
			doubleheap_setmin(Q->smaller, -x);
			doubleheap_getmin(Q->smaller, &Q->smaller_max);
			Q->smaller_max = - Q->smaller_max;
		}
	}

	/* We have added a new data point (somewhere). */
	Q->N += 1;

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq 0x20(%rdi), %rax
movq %rax, %rdx
incq %rdx
je 0x1fc6
movapd %xmm0, %xmm6
movq %rdi, %rbx
movsd 0x30(%rdi), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0x1fe5
movsd 0x1469(%rip), %xmm0     # 0x31d0
ucomisd %xmm1, %xmm0
jb 0x1fe5
movq %rdx, %xmm2
punpckldq 0x1422(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x142a(%rip), %xmm2     # 0x31b0
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
mulsd %xmm3, %xmm1
addsd 0x143a(%rip), %xmm1     # 0x31d8
cvttsd2si %xmm1, %rsi
movq %rsi, %rdi
movapd %xmm1, %xmm2
subsd 0x142e(%rip), %xmm2     # 0x31e0
cvttsd2si %xmm2, %rcx
sarq $0x3f, %rdi
andq %rdi, %rcx
orq %rsi, %rcx
xorpd %xmm2, %xmm2
je 0x1dd1
cmpq %rcx, %rdx
jne 0x1dd5
movq %rax, %rcx
jmp 0x1e01
xorl %ecx, %ecx
jmp 0x1e01
movq %rcx, %xmm2
punpckldq 0x13be(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x13c6(%rip), %xmm2     # 0x31b0
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
subsd %xmm3, %xmm1
decq %rcx
movapd %xmm1, %xmm2
movq %rcx, %xmm1
movq 0x1392(%rip), %xmm3     # 0x31a0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x1396(%rip), %xmm4     # 0x31b0
subpd %xmm4, %xmm1
movapd %xmm1, %xmm5
unpckhpd %xmm1, %xmm5            # xmm5 = xmm5[1],xmm1[1]
addsd %xmm1, %xmm5
addsd %xmm2, %xmm5
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm3
unpckhpd %xmm1, %xmm3            # xmm3 = xmm3[1],xmm1[1]
addsd %xmm1, %xmm3
ucomisd %xmm5, %xmm3
jb 0x2004
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
jb 0x2023
ucomisd %xmm2, %xmm0
jbe 0x2023
movq 0x28(%rbx), %rdx
cmpq %rdx, %rcx
movapd %xmm6, (%rsp)
jae 0x1eee
decq %rdx
cmpq %rcx, %rdx
jne 0x2042
movsd 0x18(%rbx), %xmm0
ucomisd %xmm0, %xmm6
movq (%rbx), %rdi
jae 0x1f58
callq 0x224c
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fbe
leaq 0x18(%rbx), %r14
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
movq 0x8(%rbx), %rdi
movaps (%rsp), %xmm0
xorps 0x12fa(%rip), %xmm0     # 0x31c0
callq 0x233b
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x2300
movsd 0x18(%rbx), %xmm0
xorpd 0x12dc(%rip), %xmm0     # 0x31c0
movlpd %xmm0, 0x18(%rbx)
jmp 0x1fb8
jne 0x2061
movsd 0x10(%rbx), %xmm0
ucomisd %xmm6, %xmm0
jae 0x1f83
cmpq %rax, %rcx
jae 0x2080
movq 0x8(%rbx), %rdi
xorpd 0x12a8(%rip), %xmm0     # 0x31c0
callq 0x224c
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fbe
incq 0x28(%rbx)
leaq 0x10(%rbx), %r14
movsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x18(%rbx)
movq (%rbx), %rdi
movapd (%rsp), %xmm0
callq 0x233b
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x2300
jmp 0x1fb8
movapd %xmm6, %xmm0
callq 0x224c
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fbe
movsd 0x10(%rbx), %xmm0
movapd (%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1fb8
movsd %xmm1, 0x10(%rbx)
jmp 0x1fb8
movq 0x8(%rbx), %rdi
movapd 0x1231(%rip), %xmm0     # 0x31c0
xorpd %xmm6, %xmm0
callq 0x224c
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fbe
incq 0x28(%rbx)
movapd (%rsp), %xmm0
ucomisd 0x18(%rbx), %xmm0
jbe 0x1fb8
movsd %xmm0, 0x18(%rbx)
incq 0x20(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
leaq 0x12ec(%rip), %rdi      # 0x32b9
leaq 0x12eb(%rip), %rsi      # 0x32bf
leaq 0x1306(%rip), %rcx      # 0x32e1
movl $0x25, %edx
callq 0x10c0
leaq 0x132c(%rip), %rdi      # 0x3318
leaq 0x12cc(%rip), %rsi      # 0x32bf
leaq 0x12e7(%rip), %rcx      # 0x32e1
movl $0x26, %edx
callq 0x10c0
leaq 0x1322(%rip), %rdi      # 0x332d
leaq 0x12ad(%rip), %rsi      # 0x32bf
leaq 0x12c8(%rip), %rcx      # 0x32e1
movl $0x3d, %edx
callq 0x10c0
leaq 0x1324(%rip), %rdi      # 0x334e
leaq 0x128e(%rip), %rsi      # 0x32bf
leaq 0x12a9(%rip), %rcx      # 0x32e1
movl $0x3e, %edx
callq 0x10c0
leaq 0x119f(%rip), %rdi      # 0x31e8
leaq 0x11ae(%rip), %rsi      # 0x31fe
leaq 0x122a(%rip), %rcx      # 0x3281
movl $0xa2, %edx
callq 0x10c0
leaq 0x1207(%rip), %rdi      # 0x326f
leaq 0x118f(%rip), %rsi      # 0x31fe
leaq 0x120b(%rip), %rcx      # 0x3281
movl $0x7a, %edx
callq 0x10c0
leaq 0x11d4(%rip), %rdi      # 0x325b
leaq 0x1170(%rip), %rsi      # 0x31fe
leaq 0x11ec(%rip), %rcx      # 0x3281
movl $0x8e, %edx
callq 0x10c0