#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 */
double f_up(double);
double interpolate(double X, double Values[][2], double step, int N) {
  int i;
  if (X > Values[0][0] && X < Values[N - 1][0])
    for (i = 0; i < N - 1; i++) {
      if (Values[i][0] <= X && Values[i + 1][0] > X)
        return Values[i][1] * f_up((X - Values[i][0]) / step) +
               Values[i + 1][1] * f_up((X - Values[i + 1][0]) / step);
    }
  return 0.0;
}


x86 assembly (clang, -O0):
<interpolate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
ucomisd (%rax),%xmm0
jbe    1285 <interpolate+0x175>
movsd  -0x10(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1285 <interpolate+0x175>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1280 <interpolate+0x170>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     126d <interpolate+0x15d>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    126d <interpolate+0x15d>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
subsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <f_up@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
subsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <f_up@plt>
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128d <interpolate+0x17d>
jmp    1272 <interpolate+0x162>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116a <interpolate+0x5a>
jmp    1285 <interpolate+0x175>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  (%rdi),%xmm2
ucomisd %xmm2,%xmm0
jbe    1183 <interpolate+0x73>
mov    %rdi,%r14
movapd %xmm0,%xmm3
movslq %esi,%rax
shl    $0x4,%rax
movsd  -0x10(%rax,%rdi,1),%xmm0
ucomisd %xmm3,%xmm0
jbe    1183 <interpolate+0x73>
cmp    $0x2,%esi
jl     1183 <interpolate+0x73>
add    $0xffffffff,%esi
mov    %esi,%eax
shl    $0x4,%rax
mov    $0x10,%ebx
ucomisd %xmm2,%xmm3
jb     116c <interpolate+0x5c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r14,%rbx,1),%xmm0
ucomisd %xmm3,%xmm0
ja     118f <interpolate+0x7f>
cmp    %rbx,%rax
je     1183 <interpolate+0x73>
movsd  (%r14,%rbx,1),%xmm2
add    $0x10,%rbx
ucomisd %xmm2,%xmm3
jae    1160 <interpolate+0x50>
jmp    116c <interpolate+0x5c>
xorpd  %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
movsd  -0x8(%r14,%rbx,1),%xmm0
movsd  %xmm0,0x20(%rsp)
movapd %xmm3,%xmm0
subsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
movsd  %xmm3,(%rsp)
call   1030 <f_up@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%r14,%rbx,1),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
subsd  (%r14,%rbx,1),%xmm0
divsd  0x8(%rsp),%xmm0
call   1030 <f_up@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
addsd  %xmm1,%xmm0
jmp    1187 <interpolate+0x77>

LLVM IR (-O0):
define double @interpolate(double %0, [2 x double]* %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca [2 x double]*
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store double %0, double* %6
store [2 x double]* %1, [2 x double]** %7
store double %2, double* %8
store i32 %3, i32* %9
%11 = load double, double* %6
%12 = load [2 x double]*, [2 x double]** %7
%13 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0
%14 = getelementptr inbounds [2 x double], [2 x double]* %13, i64 0, i64 0
%15 = load double, double* %14
%16 = fcmp ogt double %11, %15
br i1 %16, label %17, label %96
17: ; preds = %4
%18 = load double, double* %6
%19 = load [2 x double]*, [2 x double]** %7
%20 = load i32, i32* %9
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [2 x double], [2 x double]* %19, i64 %22
%24 = getelementptr inbounds [2 x double], [2 x double]* %23, i64 0, i64 0
%25 = load double, double* %24
%26 = fcmp olt double %18, %25
br i1 %26, label %27, label %96
27: ; preds = %17
store i32 0, i32* %10
br label %28
28: ; preds = %92, %27
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = sub nsw i32 %30, 1
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %95
33: ; preds = %28
%34 = load [2 x double]*, [2 x double]** %7
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [2 x double], [2 x double]* %34, i64 %36
%38 = getelementptr inbounds [2 x double], [2 x double]* %37, i64 0, i64 0
%39 = load double, double* %38
%40 = load double, double* %6
%41 = fcmp ole double %39, %40
br i1 %41, label %42, label %91
42: ; preds = %33
%43 = load [2 x double]*, [2 x double]** %7
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [2 x double], [2 x double]* %43, i64 %46
%48 = getelementptr inbounds [2 x double], [2 x double]* %47, i64 0, i64 0
%49 = load double, double* %48
%50 = load double, double* %6
%51 = fcmp ogt double %49, %50
br i1 %51, label %52, label %91
52: ; preds = %42
%53 = load [2 x double]*, [2 x double]** %7
%54 = load i32, i32* %10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [2 x double], [2 x double]* %53, i64 %55
%57 = getelementptr inbounds [2 x double], [2 x double]* %56, i64 0, i64 1
%58 = load double, double* %57
%59 = load double, double* %6
%60 = load [2 x double]*, [2 x double]** %7
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [2 x double], [2 x double]* %60, i64 %62
%64 = getelementptr inbounds [2 x double], [2 x double]* %63, i64 0, i64 0
%65 = load double, double* %64
%66 = fsub double %59, %65
%67 = load double, double* %8
%68 = fdiv double %66, %67
%69 = call double @f_up(double %68)
%70 = load [2 x double]*, [2 x double]** %7
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [2 x double], [2 x double]* %70, i64 %73
%75 = getelementptr inbounds [2 x double], [2 x double]* %74, i64 0, i64 1
%76 = load double, double* %75
%77 = load double, double* %6
%78 = load [2 x double]*, [2 x double]** %7
%79 = load i32, i32* %10
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [2 x double], [2 x double]* %78, i64 %81
%83 = getelementptr inbounds [2 x double], [2 x double]* %82, i64 0, i64 0
%84 = load double, double* %83
%85 = fsub double %77, %84
%86 = load double, double* %8
%87 = fdiv double %85, %86
%88 = call double @f_up(double %87)
%89 = fmul double %76, %88
%90 = call double @llvm.fmuladd.f64(double %58, double %69, double %89)
store double %90, double* %5
br label %97
91: ; preds = %42, %33
br label %92
92: ; preds = %91
%93 = load i32, i32* %10
%94 = add nsw i32 %93, 1
store i32 %94, i32* %10
br label %28
95: ; preds = %28
br label %96
96: ; preds = %95, %17, %4
store double 0.000000e+00, double* %5
br label %97
97: ; preds = %96, %52
%98 = load double, double* %5
ret double %98
}

LLVM IR (-O2):
define double @interpolate(double %0, [2 x double]* nocapture %1, double %2, i32 %3) {
%5 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 0
%6 = load double, double* %5
%7 = fcmp olt double %6, %0
br i1 %7, label %8, label %48
8: ; preds = %4
%9 = add nsw i32 %3, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %10, i64 0
%12 = load double, double* %11
%13 = fcmp ogt double %12, %0
%14 = icmp sgt i32 %3, 1
%15 = and i1 %13, %14
br i1 %15, label %16, label %48
16: ; preds = %8
%17 = zext i32 %9 to i64
br label %18
18: ; preds = %45, %16
%19 = phi double [ %6, %16 ], [ %47, %45 ]
%20 = phi i64 [ 0, %16 ], [ %22, %45 ]
%21 = fcmp ugt double %19, %0
%22 = add nuw nsw i64 %20, 1
br i1 %21, label %43, label %23
23: ; preds = %18
%24 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %22, i64 0
%25 = load double, double* %24
%26 = fcmp ogt double %25, %0
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = and i64 %20, 4294967295
%29 = and i64 %22, 4294967295
%30 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %28, i64 1
%31 = load double, double* %30
%32 = fsub double %0, %19
%33 = fdiv double %32, %2
%34 = tail call double @f_up(double %33)
%35 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %29, i64 1
%36 = load double, double* %35
%37 = load double, double* %24
%38 = fsub double %0, %37
%39 = fdiv double %38, %2
%40 = tail call double @f_up(double %39)
%41 = fmul double %36, %40
%42 = tail call double @llvm.fmuladd.f64(double %31, double %34, double %41)
br label %48
43: ; preds = %18, %23
%44 = icmp eq i64 %22, %17
br i1 %44, label %48, label %45
45: ; preds = %43
%46 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %22, i64 0
%47 = load double, double* %46
br label %18
48: ; preds = %43, %4, %8, %27
%49 = phi double [ %42, %27 ], [ 0.000000e+00, %8 ], [ 0.000000e+00, %4 ], [ 0.000000e+00, %43 ]
ret double %49
}