#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);
int /*<<< orphan*/ sort(float *, int);
double lowerQuartile(float *data, int n) {
  int lq;
  sort(data, n);
  if ((double)((0.25 * (n + 1) - (int)(0.25 * (n + 1)) >= 0.5))) {
    lq = ceil(0.25 * (n + 1));
  } else {
    lq = floor(0.25 * (n + 1));
  }
  return (double)*(data + lq - 1);
}


x86 assembly (clang, -O0):
<lowerQuartile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <sort@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
movsd  0xea1(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvttsd2si %xmm1,%eax
cvtsi2sd %eax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe76(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe5e(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
cvtsi2sd %eax,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ca <lowerQuartile+0x9a>
jp     11ca <lowerQuartile+0x9a>
jmp    11ed <lowerQuartile+0xbd>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe2c(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x10(%rbp)
jmp    120b <lowerQuartile+0xdb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe09(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  -0x4(%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lowerQuartile>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <sort@plt>
add    $0x1,%ebp
cvtsi2sd %ebp,%xmm0
mulsd  0xeb4(%rip),%xmm0
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
ucomisd 0xea4(%rip),%xmm2
jae    116d <lowerQuartile+0x3d>
call   1050 <floor@plt>
jmp    1172 <lowerQuartile+0x42>
call   1030 <ceil@plt>
cltq
movss  -0x4(%rbx,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @lowerQuartile(float* %0, i32 %1) {
%3 = alloca float*
%4 = alloca i32
%5 = alloca i32
store float* %0, float** %3
store i32 %1, i32* %4
%6 = load float*, float** %3
%7 = load i32, i32* %4
%8 = call i32 @sort(float* %6, i32 %7)
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = sitofp i32 %10 to double
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = fmul double 2.500000e-01, %14
%16 = fptosi double %15 to i32
%17 = sitofp i32 %16 to double
%18 = fneg double %17
%19 = call double @llvm.fmuladd.f64(double 2.500000e-01, double %11, double %18)
%20 = fcmp oge double %19, 5.000000e-01
%21 = zext i1 %20 to i32
%22 = sitofp i32 %21 to double
%23 = fcmp une double %22, 0.000000e+00
br i1 %23, label %24, label %30
24: ; preds = %2
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
%27 = sitofp i32 %26 to double
%28 = fmul double 2.500000e-01, %27
%29 = call i32 @ceil(double %28)
store i32 %29, i32* %5
br label %36
30: ; preds = %2
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
%33 = sitofp i32 %32 to double
%34 = fmul double 2.500000e-01, %33
%35 = call i32 @floor(double %34)
store i32 %35, i32* %5
br label %36
36: ; preds = %30, %24
%37 = load float*, float** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds float, float* %37, i64 %39
%41 = getelementptr inbounds float, float* %40, i64 -1
%42 = load float, float* %41
%43 = fpext float %42 to double
ret double %43
}

LLVM IR (-O2):
define double @lowerQuartile(float* %0, i32 %1) {
%3 = tail call i32 @sort(float* %0, i32 %1)
%4 = add nsw i32 %1, 1
%5 = sitofp i32 %4 to double
%6 = fmul double %5, 2.500000e-01
%7 = fptosi double %6 to i32
%8 = sitofp i32 %7 to double
%9 = fneg double %8
%10 = tail call double @llvm.fmuladd.f64(double %5, double 2.500000e-01, double %9)
%11 = fcmp ult double %10, 5.000000e-01
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @ceil(double %6)
br label %16
14: ; preds = %2
%15 = tail call i32 @floor(double %6)
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ %13, %12 ], [ %15, %14 ]
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds float, float* %0, i64 %18
%20 = getelementptr inbounds float, float* %19, i64 -1
%21 = load float, float* %20
%22 = fpext float %21 to double
ret double %22
}