#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 */
scalar_t__ mult(int, double, double *, double *);
double interp(int j, int dims, double *pos, double *fx, double *b,
              int initialise) {
  static double fxInterpolated = 0.0;
  static int iter = 0;
  int i;
  if (initialise) {
    fxInterpolated = 0.0;
    iter = 0;
  }
  if (j == dims) {
    fxInterpolated += mult(dims, fx[iter], pos, b);
    iter++;
    return fxInterpolated;
  }
  for (i = 0; i < 2; i++) {
    pos[j] = (double)i;
    interp(j + 1, dims, pos, fx, b, 0);
  }
  return fxInterpolated;
}


x86 assembly (clang, -O0):
<interp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     115d <interp+0x3d>
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2ee5(%rip)
movl   $0x0,0x2ee3(%rip)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11bf <interp+0x9f>
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rax
movslq 0x2ec9(%rip),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <mult@plt>
cvtsi2sd %rax,%xmm0
addsd  0x2ea2(%rip),%xmm0
movsd  %xmm0,0x2e9a(%rip)
mov    0x2e9c(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e93(%rip)
movsd  0x2e83(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121a <interp+0xfa>
movl   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x30(%rbp)
jge    120d <interp+0xed>
cvtsi2sdl -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
xor    %r9d,%r9d
call   1030 <interp@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c6 <interp+0xa6>
movsd  0x2e23(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %edi,%ebp
test   %r9d,%r9d
je     1153 <interp+0x33>
movq   $0x0,0x2eef(%rip)
movl   $0x0,0x2eed(%rip)
cmp    %r12d,%ebp
jne    1193 <interp+0x73>
movslq 0x2ee1(%rip),%rax
movsd  (%r15,%rax,8),%xmm0
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <mult@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x2eb6(%rip),%xmm0
movsd  %xmm0,0x2eae(%rip)
addl   $0x1,0x2eaf(%rip)
jmp    11e3 <interp+0xc3>
movslq %ebp,%r13
add    $0x1,%ebp
movq   $0x0,(%rbx,%r13,8)
mov    %ebp,%edi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1030 <interp@plt>
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rbx,%r13,8)
mov    %ebp,%edi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1030 <interp@plt>
movsd  0x2e55(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@interp.fxInterpolated = internal unnamed_addr global double 0.000000e+00
@interp.iter = internal unnamed_addr global i32 0
define double @interp(i32 %0, i32 %1, double* %2, double* nocapture %3, double* %4, i32 %5) {
%7 = icmp eq i32 %5, 0
br i1 %7, label %9, label %8
8: ; preds = %6
store double 0.000000e+00, double* @interp.fxInterpolated
store i32 0, i32* @interp.iter
br label %9
9: ; preds = %8, %6
%10 = icmp eq i32 %0, %1
br i1 %10, label %18, label %11
11: ; preds = %9
%12 = sext i32 %0 to i64
%13 = getelementptr inbounds double, double* %2, i64 %12
%14 = add nsw i32 %0, 1
store double 0.000000e+00, double* %13
%15 = tail call double @interp(i32 %14, i32 %1, double* %2, double* %3, double* %4, i32 0)
store double 1.000000e+00, double* %13
%16 = tail call double @interp(i32 %14, i32 %1, double* %2, double* %3, double* %4, i32 0)
%17 = load double, double* @interp.fxInterpolated
br label %29
18: ; preds = %9
%19 = load i32, i32* @interp.iter
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %3, i64 %20
%22 = load double, double* %21
%23 = tail call i64 @mult(i32 %0, double %22, double* %2, double* %4)
%24 = sitofp i64 %23 to double
%25 = load double, double* @interp.fxInterpolated
%26 = fadd double %25, %24
store double %26, double* @interp.fxInterpolated
%27 = load i32, i32* @interp.iter
%28 = add nsw i32 %27, 1
store i32 %28, i32* @interp.iter
br label %29
29: ; preds = %11, %18
%30 = phi double [ %17, %11 ], [ %26, %18 ]
ret double %30
}