#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 **allocateDoubleMatrix(int, int);
double *allocateDoubleVector(int);
double linearInterpolation(double *, double **, double *, int);
int /*<<< orphan*/ printf(char *, ...);
void testInterpolation() {
  double *fx, **a, *x;
  int dims = 2;
  x = allocateDoubleVector(dims);
  a = allocateDoubleMatrix(dims, 2);
  fx = allocateDoubleVector(dims * 2);
  x[0] = 0.25;
  x[1] = 0.4;
  a[0][0] = 0;
  a[0][1] = 1;
  a[1][0] = 0;
  a[1][1] = 1;
  fx[0] = 1;
  fx[1] = 3;
  fx[2] = 2;
  fx[3] = 4;
  printf("\nInterpolation\n");
  printf("%f\n", linearInterpolation(fx, a, x, dims));
}


x86 assembly (clang, -O0):
<testInterpolation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <allocateDoubleVector@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x2,%esi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
shl    $0x1,%edi
call   1040 <allocateDoubleVector@plt>
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
movsd  0xea1(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0xe5f(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0xe3b(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe2a(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe12(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0xdf9(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0xde0(%rip),%xmm0
movsd  %xmm0,0x18(%rax)
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1060 <linearInterpolation@plt>
lea    0xdf2(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testInterpolation>:
push   %r15
push   %r14
push   %rbx
mov    $0x2,%edi
call   1050 <allocateDoubleVector@plt>
mov    %rax,%r14
mov    $0x2,%edi
mov    $0x2,%esi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,%r15
mov    $0x4,%edi
call   1050 <allocateDoubleVector@plt>
mov    %rax,%rbx
movaps 0xe78(%rip),%xmm0
movups %xmm0,(%r14)
xorps  %xmm0,%xmm0
movhps 0xe9a(%rip),%xmm0
mov    (%r15),%rax
movups %xmm0,(%rax)
mov    0x8(%r15),%rax
movups %xmm0,(%rax)
movaps 0xe66(%rip),%xmm0
movups %xmm0,(%rbx)
movaps 0xe6c(%rip),%xmm0
movups %xmm0,0x10(%rbx)
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1070 <linearInterpolation@plt>
lea    0xe5a(%rip),%rdi
mov    $0x1,%al
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"\0AInterpolation\0A\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define void @testInterpolation() {
%1 = alloca double*
%2 = alloca double**
%3 = alloca double*
%4 = alloca i32
store i32 2, i32* %4
%5 = load i32, i32* %4
%6 = call double* @allocateDoubleVector(i32 %5)
store double* %6, double** %3
%7 = load i32, i32* %4
%8 = call double** @allocateDoubleMatrix(i32 %7, i32 2)
store double** %8, double*** %2
%9 = load i32, i32* %4
%10 = mul nsw i32 %9, 2
%11 = call double* @allocateDoubleVector(i32 %10)
store double* %11, double** %1
%12 = load double*, double** %3
%13 = getelementptr inbounds double, double* %12, i64 0
store double 2.500000e-01, double* %13
%14 = load double*, double** %3
%15 = getelementptr inbounds double, double* %14, i64 1
store double 4.000000e-01, double* %15
%16 = load double**, double*** %2
%17 = getelementptr inbounds double*, double** %16, i64 0
%18 = load double*, double** %17
%19 = getelementptr inbounds double, double* %18, i64 0
store double 0.000000e+00, double* %19
%20 = load double**, double*** %2
%21 = getelementptr inbounds double*, double** %20, i64 0
%22 = load double*, double** %21
%23 = getelementptr inbounds double, double* %22, i64 1
store double 1.000000e+00, double* %23
%24 = load double**, double*** %2
%25 = getelementptr inbounds double*, double** %24, i64 1
%26 = load double*, double** %25
%27 = getelementptr inbounds double, double* %26, i64 0
store double 0.000000e+00, double* %27
%28 = load double**, double*** %2
%29 = getelementptr inbounds double*, double** %28, i64 1
%30 = load double*, double** %29
%31 = getelementptr inbounds double, double* %30, i64 1
store double 1.000000e+00, double* %31
%32 = load double*, double** %1
%33 = getelementptr inbounds double, double* %32, i64 0
store double 1.000000e+00, double* %33
%34 = load double*, double** %1
%35 = getelementptr inbounds double, double* %34, i64 1
store double 3.000000e+00, double* %35
%36 = load double*, double** %1
%37 = getelementptr inbounds double, double* %36, i64 2
store double 2.000000e+00, double* %37
%38 = load double*, double** %1
%39 = getelementptr inbounds double, double* %38, i64 3
store double 4.000000e+00, double* %39
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%41 = load double*, double** %1
%42 = load double**, double*** %2
%43 = load double*, double** %3
%44 = load i32, i32* %4
%45 = call double @linearInterpolation(double* %41, double** %42, double* %43, i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %45)
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%f\0A\00"
@str = [15 x i8] c"\0AInterpolation\00"
define void @testInterpolation() {
%1 = tail call double* @allocateDoubleVector(i32 2)
%2 = tail call double** @allocateDoubleMatrix(i32 2, i32 2)
%3 = tail call double* @allocateDoubleVector(i32 4)
%4 = bitcast double* %1 to <2 x double>*
store <2 x double> <double 2.500000e-01, double 4.000000e-01>, <2 x double>* %4
%5 = bitcast double** %2 to <2 x double>**
%6 = load <2 x double>*, <2 x double>** %5
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %6
%7 = getelementptr inbounds double*, double** %2, i64 1
%8 = bitcast double** %7 to <2 x double>**
%9 = load <2 x double>*, <2 x double>** %8
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %9
%10 = bitcast double* %3 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 3.000000e+00>, <2 x double>* %10
%11 = getelementptr inbounds double, double* %3, i64 2
%12 = bitcast double* %11 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 4.000000e+00>, <2 x double>* %12
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%14 = tail call double @linearInterpolation(double* %3, double** %2, double* %1, i32 2)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %14)
ret void
}