#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 search(double *, int, double);
double inter_get_raw(double *x, double *data, int len, double pos) {
  double x0;
  double x1;
  double y0;
  double y1;
  double ret;
  int i = 0;
  if (pos < x[0]) {
    return 0.0;
  }
  if (pos >= x[len - 1]) {
    i = len - 1;
    x0 = x[i - 1];
    x1 = x[i];
    y0 = data[i - 1];
    y1 = data[i];
  } else {
    i = search(x, len, pos);
    x0 = x[i];
    x1 = x[i + 1];
    y0 = data[i];
    y1 = data[i + 1];
  }
  ret = y0 + ((y1 - y0) / (x1 - x0)) * (pos - x0);
  return ret;
}


x86 assembly (clang, -O0):
<inter_get_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x54(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1153 <inter_get_raw+0x43>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1274 <inter_get_raw+0x164>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     11d0 <inter_get_raw+0xc0>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1236 <inter_get_raw+0x126>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
call   1030 <search@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x54(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
subsd  -0x30(%rbp),%xmm2
divsd  %xmm2,%xmm0
movsd  -0x28(%rbp),%xmm2
subsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inter_get_raw>:
push   %r14
push   %rbx
push   %rax
movsd  (%rdi),%xmm1
ucomisd %xmm0,%xmm1
jbe    1124 <inter_get_raw+0x14>
xorpd  %xmm0,%xmm0
jmp    118e <inter_get_raw+0x7e>
mov    %rsi,%r14
mov    %rdi,%rbx
movslq %edx,%rax
movsd  -0x8(%rdi,%rax,8),%xmm4
ucomisd %xmm4,%xmm0
jae    115c <inter_get_raw+0x4c>
mov    %rbx,%rdi
mov    %edx,%esi
movsd  %xmm0,(%rsp)
call   1030 <search@plt>
movsd  (%rsp),%xmm0
movslq %eax,%rcx
movsd  0x8(%rbx,%rcx,8),%xmm4
add    $0x1,%rcx
jmp    1163 <inter_get_raw+0x53>
lea    -0x1(%rax),%rcx
add    $0xfffffffe,%eax
cltq
movsd  (%r14,%rcx,8),%xmm1
movsd  (%r14,%rax,8),%xmm2
movsd  (%rbx,%rax,8),%xmm3
subsd  %xmm2,%xmm1
subsd  %xmm3,%xmm4
divsd  %xmm4,%xmm1
subsd  %xmm3,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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