// File: WeiqiangZhou[P]BIRD/source/predict_function.cpp
// Function: QuantileNorm(double*, double*, int)
void QuantileNorm(double *indata, double *quantile, int dataLength) 
{
	int *index = new int[dataLength];
	double *indata_copy = new double[dataLength];
    double *ranks = new double[dataLength];

	for (int i = 0; i < dataLength; i++)
	{
		index[i] = i;
		indata_copy[i] = indata[i];
	}

	ShellSort(indata_copy, index, dataLength);
    GetRank(ranks, indata_copy, dataLength);
    
	for (int i = 0; i < dataLength; i++)
	{
        if (ranks[i] - floor(ranks[i]) > 0.4)
        {
            indata[index[i]] = 0.5 * (quantile[(size_t)floor(ranks[i])-1] + quantile[(size_t)floor(ranks[i])]);
        }
        else
        {
            indata[index[i]] = quantile[(size_t)floor(ranks[i])-1];
        }
	}

	delete[] index;
    delete[] ranks;
	delete[] indata_copy;
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movslq -0x14(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x20(%rbp)
movslq -0x14(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x28(%rbp)
movslq -0x14(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x79d0
movl -0x34(%rbp), %edx
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x7995
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x76f0
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x7810
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x7b25
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x2390
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd 0x7a85(%rip), %xmm1     # 0xf4c0
ucomisd %xmm1, %xmm0
jbe 0x7ab3
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x2390
movq -0x48(%rbp), %rax
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
movsd 0x7a52(%rip), %xmm1     # 0xf4c8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rsi, %rdx
orq %rdx, %rcx
movsd -0x8(%rax,%rcx,8), %xmm1
addsd (%rax,%rcx,8), %xmm1
movsd 0x7a38(%rip), %xmm0     # 0xf4d0
mulsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x7b15
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x2390
movq -0x50(%rbp), %rax
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
movsd 0x79e0(%rip), %xmm1     # 0xf4c8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rsi, %rdx
orq %rdx, %rcx
subq $0x1, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x7b17
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x79f7
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x7b3c
movq -0x58(%rbp), %rdi
callq 0x2260
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x7b53
movq -0x60(%rbp), %rdi
callq 0x2260
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x7b6a
movq -0x68(%rbp), %rdi
callq 0x2260
addq $0x70, %rsp
popq %rbp
retq