#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 cubic_weight(int);
double bicubic_interpolate_2D(double x, double y, double *f) {
  double sum = 0.0;
  int m, n;
  for (m = 0; m <= 3; m++) {
    for (n = 0; n <= 3; n++) {
      double fc = f[m * 4 + n];
      sum += fc * cubic_weight(m - 1 - y) * cubic_weight(n - 1 - x);
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<bicubic_interpolate_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jg     11f0 <bicubic_interpolate_2D+0xe0>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jg     11dd <bicubic_interpolate_2D+0xcd>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x2,%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
subsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cubic_weight@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
subsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cubic_weight@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1146 <bicubic_interpolate_2D+0x36>
jmp    11e2 <bicubic_interpolate_2D+0xd2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1135 <bicubic_interpolate_2D+0x25>
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bicubic_interpolate_2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  0xeda(%rip),%xmm2
subsd  %xmm0,%xmm2
cvttsd2si %xmm2,%eax
mov    %eax,0x1c(%rsp)
mov    %rdi,%rbx
movsd  %xmm1,0x20(%rsp)
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,0x18(%rsp)
movsd  0xeb1(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%r12d
movsd  0xea8(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%r13d
mov    $0xffffffff,%r14d
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
movsd  %xmm2,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
subsd  0x20(%rsp),%xmm0
cvttsd2si %xmm0,%ebp
movsd  (%rbx,%r15,1),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x1c(%rsp),%edi
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rbx,%r15,1),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x18(%rsp),%edi
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x10(%rbx,%r15,1),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r12d,%edi
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rbx,%r15,1),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r13d,%edi
call   1030 <cubic_weight@plt>
movapd %xmm0,%xmm2
mulsd  0x8(%rsp),%xmm2
addsd  0x10(%rsp),%xmm2
add    $0x1,%r14d
add    $0x20,%r15
cmp    $0x80,%r15
jne    1180 <bicubic_interpolate_2D+0x70>
movapd %xmm2,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @bicubic_interpolate_2D(double %0, double %1, double* nocapture %2) {
%4 = fsub double -1.000000e+00, %0
%5 = fptosi double %4 to i32
%6 = fsub double 0.000000e+00, %0
%7 = fptosi double %6 to i32
%8 = fsub double 1.000000e+00, %0
%9 = fptosi double %8 to i32
%10 = fsub double 2.000000e+00, %0
%11 = fptosi double %10 to i32
br label %12
12: ; preds = %3, %12
%13 = phi i64 [ 0, %3 ], [ %48, %12 ]
%14 = phi double [ 0.000000e+00, %3 ], [ %47, %12 ]
%15 = shl nsw i64 %13, 2
%16 = trunc i64 %13 to i32
%17 = add i32 %16, -1
%18 = sitofp i32 %17 to double
%19 = fsub double %18, %1
%20 = fptosi double %19 to i32
%21 = getelementptr inbounds double, double* %2, i64 %15
%22 = load double, double* %21
%23 = tail call double @cubic_weight(i32 %20)
%24 = fmul double %22, %23
%25 = tail call double @cubic_weight(i32 %5)
%26 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %14)
%27 = or i64 %15, 1
%28 = getelementptr inbounds double, double* %2, i64 %27
%29 = load double, double* %28
%30 = tail call double @cubic_weight(i32 %20)
%31 = fmul double %29, %30
%32 = tail call double @cubic_weight(i32 %7)
%33 = tail call double @llvm.fmuladd.f64(double %31, double %32, double %26)
%34 = or i64 %15, 2
%35 = getelementptr inbounds double, double* %2, i64 %34
%36 = load double, double* %35
%37 = tail call double @cubic_weight(i32 %20)
%38 = fmul double %36, %37
%39 = tail call double @cubic_weight(i32 %9)
%40 = tail call double @llvm.fmuladd.f64(double %38, double %39, double %33)
%41 = or i64 %15, 3
%42 = getelementptr inbounds double, double* %2, i64 %41
%43 = load double, double* %42
%44 = tail call double @cubic_weight(i32 %20)
%45 = fmul double %43, %44
%46 = tail call double @cubic_weight(i32 %11)
%47 = tail call double @llvm.fmuladd.f64(double %45, double %46, double %40)
%48 = add nuw nsw i64 %13, 1
%49 = icmp eq i64 %48, 4
br i1 %49, label %50, label %12
50: ; preds = %12
ret double %47
}