#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 /*<<< orphan*/ assert(int);
double pmod(double, int);
double interpolate_symmetric_linear(int n, double *values, double argument) {
  assert(n > 0);
  assert(values != 0);
  argument = pmod(argument, 2 * n - 2);
  if (argument > n - 1)
    argument = 2 * n - 2 - argument;
  int int_argument = (int)argument;
  double bottom = values[int_argument];
  double top = values[int_argument + 1];
  double result = (top - bottom) * (argument - int_argument) + bottom;
  return result;
}


x86 assembly (clang, -O0):
<interpolate_symmetric_linear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x18(%rbp),%xmm0
mov    -0x4(%rbp),%edi
shl    $0x1,%edi
sub    $0x2,%edi
call   1040 <pmod@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
ucomisd %xmm1,%xmm0
jbe    119f <interpolate_symmetric_linear+0x7f>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
sub    $0x2,%eax
cvtsi2sd %eax,%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
cvtsi2sdl -0x1c(%rbp),%xmm1
subsd  %xmm1,%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate_symmetric_linear>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rsi,%r14
mov    %edi,%ebx
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
lea    (%rbx,%rbx,1),%ebp
add    $0xfffffffe,%ebp
movsd  0x8(%rsp),%xmm0
mov    %ebp,%edi
call   1040 <pmod@plt>
add    $0xffffffff,%ebx
cvtsi2sd %ebx,%xmm1
cvtsi2sd %ebp,%xmm2
subsd  %xmm0,%xmm2
cmpltsd %xmm0,%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
cvttsd2si %xmm1,%eax
cltq
movsd  (%r14,%rax,8),%xmm0
movsd  0x8(%r14,%rax,8),%xmm2
cvttpd2dq %xmm1,%xmm3
cvtdq2pd %xmm3,%xmm3
subsd  %xmm0,%xmm2
subsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define double @interpolate_symmetric_linear(i32 %0, double* %1, double %2) {
%4 = icmp sgt i32 %0, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne double* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = shl nsw i32 %0, 1
%11 = add nsw i32 %10, -2
%12 = tail call double @pmod(double %2, i32 %11)
%13 = add nsw i32 %0, -1
%14 = sitofp i32 %13 to double
%15 = fcmp ogt double %12, %14
%16 = sitofp i32 %11 to double
%17 = fsub double %16, %12
%18 = select i1 %15, double %17, double %12
%19 = fptosi double %18 to i32
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
%23 = add nsw i32 %19, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %1, i64 %24
%26 = load double, double* %25
%27 = fsub double %26, %22
%28 = sitofp i32 %19 to double
%29 = fsub double %18, %28
%30 = tail call double @llvm.fmuladd.f64(double %27, double %29, double %22)
ret double %30
}