#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 interpolate(double, double, double, double, double);
int /*<<< orphan*/ printf(char *, double);
double table_interp(double x, double xv[], double yv[], int nv) {
  int i;
  for (i = 0; i < nv - 1; i++) {
    if (xv[i] <= x && xv[i + 1] > x)
      return interpolate(x, xv[i], yv[i], xv[i + 1], yv[i + 1]);
  }
  printf("tabe_interp: x value %g is not in table, your program is buggy.\n",
         x);
  return 0.0;
}


x86 assembly (clang, -O0):
<table_interp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ee <table_interp+0xce>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11db <table_interp+0xbb>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11db <table_interp+0xbb>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm3
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm4
call   1040 <interpolate@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1207 <table_interp+0xe7>
jmp    11e0 <table_interp+0xc0>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    113f <table_interp+0x1f>
movsd  -0x10(%rbp),%xmm0
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<table_interp>:
push   %rax
cmp    $0x2,%edx
jl     1161 <table_interp+0x41>
add    $0xffffffff,%edx
xor    %eax,%eax
jmp    1139 <table_interp+0x19>
nopl   (%rax)
add    $0x1,%rax
cmp    %rax,%rdx
je     1161 <table_interp+0x41>
movsd  (%rdi,%rax,8),%xmm1
ucomisd %xmm1,%xmm0
jb     1130 <table_interp+0x10>
movsd  0x8(%rdi,%rax,8),%xmm3
ucomisd %xmm0,%xmm3
jbe    1130 <table_interp+0x10>
movsd  (%rsi,%rax,8),%xmm2
movsd  0x8(%rsi,%rax,8),%xmm4
pop    %rax
jmp    1040 <interpolate@plt>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
xorpd  %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [65 x i8] c"tabe_interp: x value %g is not in table, your program is buggy.\0A\00"
define double @table_interp(double %0, double* %1, double* %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
store double %0, double* %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %59, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %9
%14 = sub nsw i32 %13, 1
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %62
16: ; preds = %11
%17 = load double*, double** %7
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = load double, double* %6
%23 = fcmp ole double %21, %22
br i1 %23, label %24, label %58
24: ; preds = %16
%25 = load double*, double** %7
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %25, i64 %28
%30 = load double, double* %29
%31 = load double, double* %6
%32 = fcmp ogt double %30, %31
br i1 %32, label %33, label %58
33: ; preds = %24
%34 = load double, double* %6
%35 = load double*, double** %7
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %8
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double*, double** %7
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %45, i64 %48
%50 = load double, double* %49
%51 = load double*, double** %8
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = call double @interpolate(double %34, double %39, double %44, double %50, double %56)
store double %57, double* %5
br label %65
58: ; preds = %24, %16
br label %59
59: ; preds = %58
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %11
62: ; preds = %11
%63 = load double, double* %6
%64 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), double %63)
store double 0.000000e+00, double* %5
br label %65
65: ; preds = %62, %33
%66 = load double, double* %5
ret double %66
}

LLVM IR (-O2):
@.str = [65 x i8] c"tabe_interp: x value %g is not in table, your program is buggy.\0A\00"
define double @table_interp(double %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 1
br i1 %5, label %6, label %29
6: ; preds = %4
%7 = add nsw i32 %3, -1
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %6, %27
%10 = phi i64 [ 0, %6 ], [ %14, %27 ]
%11 = getelementptr inbounds double, double* %1, i64 %10
%12 = load double, double* %11
%13 = fcmp ugt double %12, %0
%14 = add nuw nsw i64 %10, 1
br i1 %13, label %27, label %15
15: ; preds = %9
%16 = getelementptr inbounds double, double* %1, i64 %14
%17 = load double, double* %16
%18 = fcmp ogt double %17, %0
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = and i64 %10, 4294967295
%21 = and i64 %14, 4294967295
%22 = getelementptr inbounds double, double* %2, i64 %20
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %2, i64 %21
%25 = load double, double* %24
%26 = tail call double @interpolate(double %0, double %12, double %23, double %17, double %25)
br label %31
27: ; preds = %9, %15
%28 = icmp eq i64 %14, %8
br i1 %28, label %29, label %9
29: ; preds = %27, %4
%30 = tail call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), double %0)
br label %31
31: ; preds = %29, %19
%32 = phi double [ %26, %19 ], [ 0.000000e+00, %29 ]
ret double %32
}