#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 *allocateDoubleVector(int);
double interp(int /*<<< orphan*/, int, double *, double *, double *, int);
double linearInterpolation(double *fx, double **a, double *x, int dims) {
  double *b, *pos;
  int i;
  double fxInterpolated = 0.0;
  b = allocateDoubleVector(dims);
  pos = allocateDoubleVector(dims);
  for (i = 0; i < dims; i++)
    b[i] = (x[i] - a[i][0]) / (a[i][1] - a[i][0]);
  fxInterpolated = interp(0, dims, pos, fx, b, 1);
  return fxInterpolated;
}


x86 assembly (clang, -O0):
<linearInterpolation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <allocateDoubleVector@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <allocateDoubleVector@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c7 <linearInterpolation+0xa7>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
subsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
subsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115e <linearInterpolation+0x3e>
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%r8
xor    %edi,%edi
mov    $0x1,%r9d
call   1040 <interp@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linearInterpolation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %ecx,%edi
call   1030 <allocateDoubleVector@plt>
mov    %rax,%r12
mov    %r15d,%edi
call   1030 <allocateDoubleVector@plt>
test   %r15d,%r15d
jle    11ef <linearInterpolation+0xcf>
mov    %r15d,%edx
cmp    $0x1,%r15d
jne    115c <linearInterpolation+0x3c>
xor    %ecx,%ecx
jmp    11c5 <linearInterpolation+0xa5>
mov    %edx,%esi
and    $0xfffffffe,%esi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rbx,%rcx,8),%xmm0
mov    0x0(%rbp,%rcx,8),%rdi
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
subsd  %xmm1,%xmm0
subsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,(%r12,%rcx,8)
movsd  0x8(%rbx,%rcx,8),%xmm0
mov    0x8(%rbp,%rcx,8),%rdi
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
subsd  %xmm1,%xmm0
subsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%r12,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%rsi
jne    1170 <linearInterpolation+0x50>
test   $0x1,%dl
je     11ef <linearInterpolation+0xcf>
movsd  (%rbx,%rcx,8),%xmm0
mov    0x0(%rbp,%rcx,8),%rdx
movsd  (%rdx),%xmm1
movsd  0x8(%rdx),%xmm2
subsd  %xmm1,%xmm0
subsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,(%r12,%rcx,8)
xor    %edi,%edi
mov    %r15d,%esi
mov    %rax,%rdx
mov    %r14,%rcx
mov    %r12,%r8
mov    $0x1,%r9d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <interp@plt>

LLVM IR (-O0):
define double @linearInterpolation(double* %0, double** %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double**
%7 = alloca double*
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
store double* %0, double** %5
store double** %1, double*** %6
store double* %2, double** %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %12
%13 = load i32, i32* %8
%14 = call double* @allocateDoubleVector(i32 %13)
store double* %14, double** %9
%15 = load i32, i32* %8
%16 = call double* @allocateDoubleVector(i32 %15)
store double* %16, double** %10
store i32 0, i32* %11
br label %17
17: ; preds = %55, %4
%18 = load i32, i32* %11
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %58
21: ; preds = %17
%22 = load double*, double** %7
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double**, double*** %6
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double*, double** %27, i64 %29
%31 = load double*, double** %30
%32 = getelementptr inbounds double, double* %31, i64 0
%33 = load double, double* %32
%34 = fsub double %26, %33
%35 = load double**, double*** %6
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double*, double** %35, i64 %37
%39 = load double*, double** %38
%40 = getelementptr inbounds double, double* %39, i64 1
%41 = load double, double* %40
%42 = load double**, double*** %6
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double*, double** %42, i64 %44
%46 = load double*, double** %45
%47 = getelementptr inbounds double, double* %46, i64 0
%48 = load double, double* %47
%49 = fsub double %41, %48
%50 = fdiv double %34, %49
%51 = load double*, double** %9
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
store double %50, double* %54
br label %55
55: ; preds = %21
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %17
58: ; preds = %17
%59 = load i32, i32* %8
%60 = load double*, double** %10
%61 = load double*, double** %5
%62 = load double*, double** %9
%63 = call double @interp(i32 0, i32 %59, double* %60, double* %61, double* %62, i32 1)
store double %63, double* %12
%64 = load double, double* %12
ret double %64
}

LLVM IR (-O2):
define double @linearInterpolation(double* %0, double** nocapture %1, double* nocapture %2, i32 %3) {
%5 = tail call double* @allocateDoubleVector(i32 %3)
%6 = tail call double* @allocateDoubleVector(i32 %3)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %58
8: ; preds = %4
%9 = zext i32 %3 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %3, 1
br i1 %11, label %43, label %12
12: ; preds = %8
%13 = and i64 %9, 4294967294
br label %14
14: ; preds = %14, %12
%15 = phi i64 [ 0, %12 ], [ %40, %14 ]
%16 = phi i64 [ 0, %12 ], [ %41, %14 ]
%17 = getelementptr inbounds double, double* %2, i64 %15
%18 = load double, double* %17
%19 = getelementptr inbounds double*, double** %1, i64 %15
%20 = load double*, double** %19
%21 = load double, double* %20
%22 = fsub double %18, %21
%23 = getelementptr inbounds double, double* %20, i64 1
%24 = load double, double* %23
%25 = fsub double %24, %21
%26 = fdiv double %22, %25
%27 = getelementptr inbounds double, double* %5, i64 %15
store double %26, double* %27
%28 = or i64 %15, 1
%29 = getelementptr inbounds double, double* %2, i64 %28
%30 = load double, double* %29
%31 = getelementptr inbounds double*, double** %1, i64 %28
%32 = load double*, double** %31
%33 = load double, double* %32
%34 = fsub double %30, %33
%35 = getelementptr inbounds double, double* %32, i64 1
%36 = load double, double* %35
%37 = fsub double %36, %33
%38 = fdiv double %34, %37
%39 = getelementptr inbounds double, double* %5, i64 %28
store double %38, double* %39
%40 = add nuw nsw i64 %15, 2
%41 = add i64 %16, 2
%42 = icmp eq i64 %41, %13
br i1 %42, label %43, label %14
43: ; preds = %14, %8
%44 = phi i64 [ 0, %8 ], [ %40, %14 ]
%45 = icmp eq i64 %10, 0
br i1 %45, label %58, label %46
46: ; preds = %43
%47 = getelementptr inbounds double, double* %2, i64 %44
%48 = load double, double* %47
%49 = getelementptr inbounds double*, double** %1, i64 %44
%50 = load double*, double** %49
%51 = load double, double* %50
%52 = fsub double %48, %51
%53 = getelementptr inbounds double, double* %50, i64 1
%54 = load double, double* %53
%55 = fsub double %54, %51
%56 = fdiv double %52, %55
%57 = getelementptr inbounds double, double* %5, i64 %44
store double %56, double* %57
br label %58
58: ; preds = %46, %43, %4
%59 = tail call double @interp(i32 0, i32 %3, double* %6, double* %0, double* %5, i32 1)
ret double %59
}