// File: /workspace/github_c_makefile_star2_O1/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 0x1fd3
movapd %xmm0, %xmm6
movq %rdi, %rbx
movsd 0x30(%rdi), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0x1ff2
movsd 0x1430(%rip), %xmm0     # 0x3190
ucomisd %xmm1, %xmm0
jb 0x1ff2
movq %rdx, %xmm2
punpckldq 0x1439(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x1441(%rip), %xmm2     # 0x31c0
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
mulsd %xmm3, %xmm1
addsd 0x1401(%rip), %xmm1     # 0x3198
cvttsd2si %xmm1, %rsi
movq %rsi, %rdi
movapd %xmm1, %xmm2
subsd 0x13f5(%rip), %xmm2     # 0x31a0
cvttsd2si %xmm2, %rcx
sarq $0x3f, %rdi
andq %rdi, %rcx
orq %rsi, %rcx
xorpd %xmm2, %xmm2
je 0x1dca
cmpq %rcx, %rdx
jne 0x1dce
movq %rax, %rcx
jmp 0x1dfa
xorl %ecx, %ecx
jmp 0x1dfa
movq %rcx, %xmm2
punpckldq 0x13d5(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x13dd(%rip), %xmm2     # 0x31c0
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 0x13a9(%rip), %xmm3     # 0x31b0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x13ad(%rip), %xmm4     # 0x31c0
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 0x2011
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
jb 0x2030
ucomisd %xmm2, %xmm0
jbe 0x2030
leaq 0x1(%rcx), %rsi
movq 0x28(%rbx), %rdx
cmpq %rdx, %rsi
movapd %xmm6, (%rsp)
jbe 0x1ee4
cmpq %rcx, %rdx
jne 0x204f
movsd 0x10(%rbx), %xmm0
ucomisd %xmm6, %xmm0
jae 0x1f62
cmpq %rax, %rdx
jae 0x208d
movq 0x8(%rbx), %rdi
xorpd 0x132f(%rip), %xmm0     # 0x31d0
callq 0x2278
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fcb
incq 0x28(%rbx)
leaq 0x10(%rbx), %r14
movsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x18(%rbx)
movq (%rbx), %rdi
movapd (%rsp), %xmm0
callq 0x2367
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x232c
jmp 0x1fc5
leaq -0x1(%rdx), %rax
cmpq %rcx, %rax
jne 0x206e
movsd 0x18(%rbx), %xmm0
ucomisd %xmm0, %xmm6
jae 0x1f99
testq %rdx, %rdx
je 0x20ac
movq (%rbx), %rdi
callq 0x2278
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fcb
leaq 0x18(%rbx), %r14
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
movq 0x8(%rbx), %rdi
movaps (%rsp), %xmm0
xorps 0x1293(%rip), %xmm0     # 0x31d0
callq 0x2367
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x232c
movsd 0x18(%rbx), %xmm0
xorpd 0x1275(%rip), %xmm0     # 0x31d0
movlpd %xmm0, 0x18(%rbx)
jmp 0x1fc5
movq 0x8(%rbx), %rdi
movapd 0x1262(%rip), %xmm0     # 0x31d0
xorpd %xmm6, %xmm0
callq 0x2278
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fcb
incq 0x28(%rbx)
movapd (%rsp), %xmm0
ucomisd 0x18(%rbx), %xmm0
jbe 0x1fc5
movsd %xmm0, 0x18(%rbx)
jmp 0x1fc5
movq (%rbx), %rdi
movapd %xmm6, %xmm0
callq 0x2278
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1fcb
movsd 0x10(%rbx), %xmm0
movapd (%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1fc5
movsd %xmm1, 0x10(%rbx)
incq 0x20(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
leaq 0x12e8(%rip), %rdi      # 0x32c2
leaq 0x12e7(%rip), %rsi      # 0x32c8
leaq 0x1302(%rip), %rcx      # 0x32ea
movl $0x25, %edx
callq 0x10c0
leaq 0x1328(%rip), %rdi      # 0x3321
leaq 0x12c8(%rip), %rsi      # 0x32c8
leaq 0x12e3(%rip), %rcx      # 0x32ea
movl $0x26, %edx
callq 0x10c0
leaq 0x131e(%rip), %rdi      # 0x3336
leaq 0x12a9(%rip), %rsi      # 0x32c8
leaq 0x12c4(%rip), %rcx      # 0x32ea
movl $0x3d, %edx
callq 0x10c0
leaq 0x1320(%rip), %rdi      # 0x3357
leaq 0x128a(%rip), %rsi      # 0x32c8
leaq 0x12a5(%rip), %rcx      # 0x32ea
movl $0x3e, %edx
callq 0x10c0
leaq 0x1211(%rip), %rdi      # 0x3267
leaq 0x1199(%rip), %rsi      # 0x31f6
leaq 0x1215(%rip), %rcx      # 0x3279
movl $0x7a, %edx
callq 0x10c0
leaq 0x116b(%rip), %rdi      # 0x31e0
leaq 0x117a(%rip), %rsi      # 0x31f6
leaq 0x11f6(%rip), %rcx      # 0x3279
movl $0xa2, %edx
callq 0x10c0
leaq 0x11bf(%rip), %rdi      # 0x3253
leaq 0x115b(%rip), %rsi      # 0x31f6
leaq 0x11d7(%rip), %rcx      # 0x3279
movl $0x8e, %edx
callq 0x10c0
leaq 0x11fe(%rip), %rdi      # 0x32b1
leaq 0x113c(%rip), %rsi      # 0x31f6
leaq 0x11b8(%rip), %rcx      # 0x3279
movl $0xb6, %edx
callq 0x10c0