#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int ceil(double);
int floor(double);
double quantile(double *x, int n, double p) {
  int i[2];
  double Q;
  double remain;
  Q = (n + 1) * p - 1;
  i[0] = floor(Q);
  remain = Q - i[0];
  i[1] = ceil(Q);
  Q = x[i[0]] + (x[i[1]] - x[i[0]]) * remain;
  return (Q);
}


x86 assembly (clang, -O0):
<quantile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeb1(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quantile>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
add    $0x1,%esi
cvtsi2sd %esi,%xmm1
mov    %rdi,%rbx
mulsd  %xmm1,%xmm0
addsd  0xec4(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <floor@plt>
mov    %eax,%ebp
cvtsi2sd %eax,%xmm2
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1030 <ceil@plt>
movslq %ebp,%rcx
movsd  (%rbx,%rcx,8),%xmm1
cltq
movsd  (%rbx,%rax,8),%xmm0
subsd  %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @quantile(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca [2 x i32]
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = sitofp i32 %11 to double
%13 = load double, double* %6
%14 = call double @llvm.fmuladd.f64(double %12, double %13, double -1.000000e+00)
store double %14, double* %8
%15 = load double, double* %8
%16 = call i32 @floor(double %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %16, i32* %17
%18 = load double, double* %8
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%20 = load i32, i32* %19
%21 = sitofp i32 %20 to double
%22 = fsub double %18, %21
store double %22, double* %9
%23 = load double, double* %8
%24 = call i32 @ceil(double %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %24, i32* %25
%26 = load double*, double** %4
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %26, i64 %29
%31 = load double, double* %30
%32 = load double*, double** %4
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %32, i64 %35
%37 = load double, double* %36
%38 = load double*, double** %4
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%40 = load i32, i32* %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = load double, double* %42
%44 = fsub double %37, %43
%45 = load double, double* %9
%46 = call double @llvm.fmuladd.f64(double %44, double %45, double %31)
store double %46, double* %8
%47 = load double, double* %8
ret double %47
}

LLVM IR (-O2):
define double @quantile(double* nocapture %0, i32 %1, double %2) {
%4 = add nsw i32 %1, 1
%5 = sitofp i32 %4 to double
%6 = tail call double @llvm.fmuladd.f64(double %5, double %2, double -1.000000e+00)
%7 = tail call i32 @floor(double %6)
%8 = sitofp i32 %7 to double
%9 = fsub double %6, %8
%10 = tail call i32 @ceil(double %6)
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds double, double* %0, i64 %11
%13 = load double, double* %12
%14 = sext i32 %10 to i64
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = fsub double %16, %13
%18 = tail call double @llvm.fmuladd.f64(double %17, double %9, double %13)
ret double %18
}