// File: /workspace/github_cpp_makefile_star2_O2/ashlall[P]StreamStats/Test/GK_test.cpp
// Function: test_reverseQuantile(double, double)
void test_reverseQuantile(double stream_size, double sample_size)
{
	GK m(sample_size);
	GK n(sample_size);
	double epsilon = log(stream_size)/sample_size;
	//cout << "e: " << error<<endl;
	bool check1, check2;
	double hold1, hold2;

	for(double i = 0; i<=stream_size; i++)
	{
		m.insert(i);
		n.insert(stream_size-i);
	}

	//If the sample_size is large enough, then the reverse quantile lookup should return the EXACT index. Here, we transformed into probability.
	if (sample_size >= stream_size*3)
	{
		for(double i = 0; i<=stream_size; i++)
		{ 
			hold1 = ((m.reverseQuantile(i, stream_size))/stream_size);
			check1 = (hold1 == i/stream_size);
			assert(check1==true);

			hold2 = ((n.reverseQuantile(i, stream_size))/stream_size);
			check2 = (hold2 == i/stream_size);
			assert(check2==true);
		}
	}

	//Theoratically, the reverse quantile lookup will generate 3epsilon.

	else
	{
		for(double i = 0; i<=stream_size; i++)
		{ 
			hold1 = ((m.reverseQuantile(i, stream_size))/stream_size);
			check1 = ((hold1 >= i/stream_size - 3*epsilon) &&  (hold1 <= i/stream_size + 3*epsilon));
			assert(check1==true);

			hold2 = ((n.reverseQuantile(i, stream_size))/stream_size);
			check2 = ((hold2 >= i/stream_size - 3*epsilon) &&  (hold2 <= i/stream_size + 3*epsilon));
			assert(check2==true);
		}			
	}		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
movsd %xmm0, -0x20(%rbp)
movsd %xmm1, -0x30(%rbp)
cvttsd2si %xmm1, %ebx
leaq -0xa8(%rbp), %rdi
movl %ebx, %esi
callq 0x12ba
leaq -0x78(%rbp), %rdi
movl %ebx, %esi
callq 0x12ba
movsd -0x20(%rbp), %xmm0
callq 0x1090
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
xorpd %xmm1, %xmm1
leaq -0xa8(%rbp), %rbx
leaq -0x78(%rbp), %r14
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x1f3b
movq %rbx, %rdi
movsd %xmm1, -0x28(%rbp)
movapd %xmm1, %xmm0
callq 0x1368
movsd -0x20(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movq %r14, %rdi
callq 0x1368
movsd -0x28(%rbp), %xmm1
addsd 0x10d7(%rip), %xmm1     # 0x3010
jmp 0x1efe
movsd 0x10fd(%rip), %xmm0     # 0x3040
movsd -0x20(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm2
ucomisd %xmm0, %xmm2
cvttsd2si %xmm1, %ebx
xorpd %xmm1, %xmm1
leaq -0xa8(%rbp), %r14
jae 0x2034
movsd 0x10d6(%rip), %xmm2     # 0x3048
movsd -0x38(%rbp), %xmm0
mulsd %xmm0, %xmm2
movsd %xmm2, -0x40(%rbp)
mulsd 0x10b8(%rip), %xmm0     # 0x3040
movsd %xmm0, -0x38(%rbp)
leaq -0x78(%rbp), %r15
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x20ac
movq %r14, %rdi
movapd %xmm1, %xmm0
movl %ebx, %esi
movsd %xmm1, -0x28(%rbp)
callq 0x124c
movsd -0x20(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd -0x28(%rbp), %xmm3
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
movsd -0x40(%rbp), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, -0x30(%rbp)
ucomisd %xmm1, %xmm0
jb 0x210d
addsd -0x38(%rbp), %xmm2
ucomisd %xmm0, %xmm2
jb 0x210d
movsd %xmm2, -0x48(%rbp)
movq %r15, %rdi
movapd %xmm3, %xmm0
movl %ebx, %esi
callq 0x124c
movsd -0x28(%rbp), %xmm1
divsd -0x20(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x20cf
movsd -0x48(%rbp), %xmm2
ucomisd %xmm0, %xmm2
jb 0x20cf
addsd 0xfe1(%rip), %xmm1      # 0x3010
jmp 0x1f91
leaq -0x78(%rbp), %r15
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x20ac
movq %r14, %rdi
movapd %xmm1, %xmm0
movl %ebx, %esi
movsd %xmm1, -0x28(%rbp)
callq 0x124c
movsd -0x20(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd -0x28(%rbp), %xmm3
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, -0x30(%rbp)
ucomisd %xmm2, %xmm0
jne 0x212c
jp 0x212c
movapd %xmm3, %xmm0
movq %r15, %rdi
movl %ebx, %esi
callq 0x124c
movsd -0x28(%rbp), %xmm1
divsd -0x20(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jne 0x20ee
jp 0x20ee
addsd 0xf66(%rip), %xmm1      # 0x3010
jmp 0x2038
leaq -0x78(%rbp), %rdi
callq 0x1322
leaq -0xa8(%rbp), %rdi
callq 0x1322
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10cb(%rip), %rdi      # 0x31a1
leaq 0xfce(%rip), %rsi       # 0x30ab
leaq 0x1093(%rip), %rcx      # 0x3177
movl $0xd4, %edx
callq 0x1070
leaq 0x10ac(%rip), %rdi      # 0x31a1
leaq 0xfaf(%rip), %rsi       # 0x30ab
leaq 0x1074(%rip), %rcx      # 0x3177
movl $0xc4, %edx
callq 0x1070
leaq 0x1056(%rip), %rdi      # 0x316a
leaq 0xf90(%rip), %rsi       # 0x30ab
leaq 0x1055(%rip), %rcx      # 0x3177
movl $0xd0, %edx
callq 0x1070
leaq 0x1037(%rip), %rdi      # 0x316a
leaq 0xf71(%rip), %rsi       # 0x30ab
leaq 0x1036(%rip), %rcx      # 0x3177
movl $0xc0, %edx
callq 0x1070
movq %rax, %rbx
jmp 0x2160
jmp 0x2154
jmp 0x2154
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x1322
leaq -0xa8(%rbp), %rdi
callq 0x1322
movq %rbx, %rdi
callq 0x1100