#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);
scalar_t__ mult(int, double, double *, double *);
double interp2D(int dims, double *fx, double *b) {
  int i, j;
  double val = 0.0, *pos;
  pos = allocateDoubleVector(dims);
  for (i = 0; i < 2; i++) {
    for (j = 0; j < 2; j++) {
      pos[0] = i;
      pos[1] = j;
      val += mult(dims, fx[j + i * 2], pos, b);
    }
  }
  return val;
}


x86 assembly (clang, -O0):
<interp2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <allocateDoubleVector@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    11db <interp2D+0xbb>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    11c8 <interp2D+0xa8>
cvtsi2sdl -0x1c(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
cvtsi2sdl -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%edx
shl    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <mult@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115f <interp2D+0x3f>
jmp    11cd <interp2D+0xad>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <interp2D+0x2e>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interp2D>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
call   1030 <allocateDoubleVector@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,(%rax)
movsd  (%r15),%xmm0
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <mult@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
xorpd  %xmm0,%xmm0
movhpd 0xe98(%rip),%xmm0
movupd %xmm0,(%rbx)
movsd  0x8(%r15),%xmm0
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <mult@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe67(%rip),%xmm0
movups %xmm0,(%rbx)
movsd  0x10(%r15),%xmm0
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <mult@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movaps 0xe48(%rip),%xmm0
movups %xmm0,(%rbx)
movsd  0x18(%r15),%xmm0
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <mult@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @interp2D(i32 %0, double* nocapture %1, double* %2) {
%4 = tail call double* @allocateDoubleVector(i32 %0)
%5 = bitcast double* %4 to i8*
%6 = load double, double* %1
%7 = tail call i64 @mult(i32 %0, double %6, double* %4, double* %2)
%8 = sitofp i64 %7 to double
%9 = bitcast double* %4 to <2 x double>*
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %9
%10 = getelementptr inbounds double, double* %1, i64 1
%11 = load double, double* %10
%12 = tail call i64 @mult(i32 %0, double %11, double* %4, double* %2)
%13 = sitofp i64 %12 to double
%14 = fadd double %8, %13
%15 = bitcast double* %4 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 0.000000e+00>, <2 x double>* %15
%16 = getelementptr inbounds double, double* %1, i64 2
%17 = load double, double* %16
%18 = tail call i64 @mult(i32 %0, double %17, double* %4, double* %2)
%19 = sitofp i64 %18 to double
%20 = fadd double %14, %19
%21 = bitcast double* %4 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %21
%22 = getelementptr inbounds double, double* %1, i64 3
%23 = load double, double* %22
%24 = tail call i64 @mult(i32 %0, double %23, double* %4, double* %2)
%25 = sitofp i64 %24 to double
%26 = fadd double %20, %25
ret double %26
}