#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 floor(double);
double frctl(const double *xx, double p, unsigned int n) {
  double zi, th;
  int i;
  zi = p * n - .5;
  i = floor(zi);
  if (zi < 0)
    return xx[0];
  else if (zi > n - 1)
    return xx[n - 1];
  th = zi - i;
  return ((1 - th) * xx[i] + th * xx[i + 1]);
}


x86 assembly (clang, -O0):
<frctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xec3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <floor@plt>
mov    %eax,-0x34(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1173 <frctl+0x63>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11fe <frctl+0xee>
movsd  -0x28(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
cvtsi2sd %rax,%xmm1
ucomisd %xmm1,%xmm0
jbe    11a8 <frctl+0x98>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11fe <frctl+0xee>
jmp    11ad <frctl+0x9d>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe40(%rip),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frctl>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %esi,%eax
cvtsi2sd %rax,%xmm1
mov    %rdi,%r14
mulsd  %xmm0,%xmm1
addsd  0xed4(%rip),%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1030 <floor@plt>
movsd  (%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1150 <frctl+0x40>
movsd  (%r14),%xmm0
jmp    1195 <frctl+0x85>
add    $0xffffffff,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
ucomisd %xmm0,%xmm1
jbe    116b <frctl+0x5b>
mov    %ebx,%eax
movsd  (%r14,%rax,8),%xmm0
jmp    1195 <frctl+0x85>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
subsd  %xmm1,%xmm0
cltq
mulsd  0x8(%r14,%rax,8),%xmm1
mulsd  (%r14,%rax,8),%xmm0
addsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @frctl(double* %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double* %0, double** %5
store double %1, double* %6
store i32 %2, i32* %7
%11 = load double, double* %6
%12 = load i32, i32* %7
%13 = uitofp i32 %12 to double
%14 = call double @llvm.fmuladd.f64(double %11, double %13, double -5.000000e-01)
store double %14, double* %8
%15 = load double, double* %8
%16 = call i32 @floor(double %15)
store i32 %16, i32* %10
%17 = load double, double* %8
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
store double %22, double* %4
br label %58
23: ; preds = %3
%24 = load double, double* %8
%25 = load i32, i32* %7
%26 = sub i32 %25, 1
%27 = uitofp i32 %26 to double
%28 = fcmp ogt double %24, %27
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load double*, double** %5
%31 = load i32, i32* %7
%32 = sub i32 %31, 1
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds double, double* %30, i64 %33
%35 = load double, double* %34
store double %35, double* %4
br label %58
36: ; preds = %23
br label %37
37: ; preds = %36
%38 = load double, double* %8
%39 = load i32, i32* %10
%40 = sitofp i32 %39 to double
%41 = fsub double %38, %40
store double %41, double* %9
%42 = load double, double* %9
%43 = fsub double 1.000000e+00, %42
%44 = load double*, double** %5
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double, double* %9
%50 = load double*, double** %5
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %50, i64 %53
%55 = load double, double* %54
%56 = fmul double %49, %55
%57 = call double @llvm.fmuladd.f64(double %43, double %48, double %56)
store double %57, double* %4
br label %58
58: ; preds = %37, %29, %19
%59 = load double, double* %4
ret double %59
}

LLVM IR (-O2):
define double @frctl(double* nocapture %0, double %1, i32 %2) {
%4 = uitofp i32 %2 to double
%5 = tail call double @llvm.fmuladd.f64(double %1, double %4, double -5.000000e-01)
%6 = tail call i32 @floor(double %5)
%7 = fcmp olt double %5, 0.000000e+00
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = load double, double* %0
br label %31
10: ; preds = %3
%11 = add i32 %2, -1
%12 = uitofp i32 %11 to double
%13 = fcmp ogt double %5, %12
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = zext i32 %11 to i64
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
br label %31
18: ; preds = %10
%19 = sitofp i32 %6 to double
%20 = fsub double %5, %19
%21 = fsub double 1.000000e+00, %20
%22 = sext i32 %6 to i64
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = load double, double* %23
%25 = add nsw i32 %6, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %0, i64 %26
%28 = load double, double* %27
%29 = fmul double %20, %28
%30 = tail call double @llvm.fmuladd.f64(double %21, double %24, double %29)
br label %31
31: ; preds = %18, %14, %8
%32 = phi double [ %9, %8 ], [ %17, %14 ], [ %30, %18 ]
ret double %32
}