#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(double, double, double);
scalar_t__ floor(double);
double interpolate_pixel_cubic(float *data, int w, int h, double x, double y,
                               double a, double b) {
  int x0, y0;
  double p, q;
  int i, j, u, v;
  if (x < 3 || x >= w - 3 || y < 3 || y >= h - 3)
    return 0.0;
  x0 = (int)floor(x);
  y0 = (int)floor(y);
  q = 0.0;
  for (j = 0; j < 4; j++) {
    p = 0.0;
    v = y0 + j - 1;
    for (i = 0; i < 4; i++) {
      u = x0 + i - 1;
      p += data[v * w + u] * cubic_weight(x - (double)u, a, b);
    }
    q += p * cubic_weight(y - (double)v, a, b);
  }
  return q;
}


x86 assembly (clang, -O0):
<interpolate_pixel_cubic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
movsd  %xmm3,-0x38(%rbp)
movsd  0xeb2(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     119e <interpolate_pixel_cubic+0x7e>
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
cvtsi2sd %eax,%xmm1
ucomisd %xmm1,%xmm0
jae    119e <interpolate_pixel_cubic+0x7e>
movsd  0xe86(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
ja     119e <interpolate_pixel_cubic+0x7e>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
cvtsi2sd %eax,%xmm1
ucomisd %xmm1,%xmm0
jb     11ab <interpolate_pixel_cubic+0x8b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12cc <interpolate_pixel_cubic+0x1ac>
movsd  -0x20(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x58(%rbp)
cmpl   $0x4,-0x58(%rbp)
jge    12c2 <interpolate_pixel_cubic+0x1a2>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x40(%rbp),%eax
add    -0x58(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x4,-0x54(%rbp)
jge    1273 <interpolate_pixel_cubic+0x153>
mov    -0x3c(%rbp),%eax
add    -0x54(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x60(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x5c(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
call   1030 <cubic_weight@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f9 <interpolate_pixel_cubic+0xd9>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x60(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
call   1030 <cubic_weight@plt>
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11d4 <interpolate_pixel_cubic+0xb4>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate_pixel_cubic>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
xorpd  %xmm6,%xmm6
movsd  0xec6(%rip),%xmm5
ucomisd %xmm0,%xmm5
ja     1379 <interpolate_pixel_cubic+0x259>
mov    %esi,%r14d
lea    -0x3(%r14),%eax
cvtsi2sd %eax,%xmm4
ucomisd %xmm4,%xmm0
jae    1379 <interpolate_pixel_cubic+0x259>
ucomisd %xmm1,%xmm5
ja     1379 <interpolate_pixel_cubic+0x259>
add    $0xfffffffd,%edx
xorps  %xmm4,%xmm4
cvtsi2sd %edx,%xmm4
ucomisd %xmm4,%xmm1
movsd  %xmm3,0x20(%rsp)
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x30(%rsp)
jae    1379 <interpolate_pixel_cubic+0x259>
mov    %rdi,%r13
movsd  %xmm0,0x28(%rsp)
call   1040 <floor@plt>
mov    %rax,%r12
movsd  0x30(%rsp),%xmm0
call   1040 <floor@plt>
mov    %rax,%r15
lea    -0x1(%r12),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x28(%rsp),%xmm3
movapd %xmm3,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
subsd  %xmm0,%xmm2
movsd  %xmm2,0x48(%rsp)
movapd %xmm3,%xmm2
lea    0x1(%r12),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  %xmm1,%xmm2
movsd  %xmm2,0x40(%rsp)
movapd %xmm3,%xmm2
lea    0x2(%r12),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
subsd  %xmm0,%xmm2
movsd  %xmm2,0x38(%rsp)
subsd  %xmm1,%xmm3
movsd  %xmm3,0x28(%rsp)
add    $0xffffffff,%r15d
mov    %r15d,%ebx
imul   %r14d,%ebx
add    %r12d,%ebx
xor    %r12d,%r12d
xorpd  %xmm6,%xmm6
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm6,0x50(%rsp)
lea    (%r15,%r12,1),%ebp
lea    -0x1(%rbx),%eax
cltq
movss  0x0(%r13,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x48(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   1030 <cubic_weight@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0xd93(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movslq %ebx,%rbx
movss  0x0(%r13,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x40(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   1030 <cubic_weight@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%eax
cltq
movss  0x0(%r13,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x38(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   1030 <cubic_weight@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x2(%rbx),%eax
cltq
movss  0x0(%r13,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x28(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   1030 <cubic_weight@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0x30(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   1030 <cubic_weight@plt>
movsd  0x50(%rsp),%xmm6
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm6
add    $0x1,%r12
add    %r14d,%ebx
cmp    $0x4,%r12
jne    1230 <interpolate_pixel_cubic+0x110>
movapd %xmm6,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @interpolate_pixel_cubic(float* %0, i32 %1, i32 %2, double %3, double %4, double %5, double %6) {
%8 = alloca double
%9 = alloca float*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
%19 = alloca double
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store float* %0, float** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store double %3, double* %12
store double %4, double* %13
store double %5, double* %14
store double %6, double* %15
%24 = load double, double* %12
%25 = fcmp olt double %24, 3.000000e+00
br i1 %25, label %41, label %26
26: ; preds = %7
%27 = load double, double* %12
%28 = load i32, i32* %10
%29 = sub nsw i32 %28, 3
%30 = sitofp i32 %29 to double
%31 = fcmp oge double %27, %30
br i1 %31, label %41, label %32
32: ; preds = %26
%33 = load double, double* %13
%34 = fcmp olt double %33, 3.000000e+00
br i1 %34, label %41, label %35
35: ; preds = %32
%36 = load double, double* %13
%37 = load i32, i32* %11
%38 = sub nsw i32 %37, 3
%39 = sitofp i32 %38 to double
%40 = fcmp oge double %36, %39
br i1 %40, label %41, label %42
41: ; preds = %35, %32, %26, %7
store double 0.000000e+00, double* %8
br label %103
42: ; preds = %35
%43 = load double, double* %12
%44 = call i64 @floor(double %43)
%45 = trunc i64 %44 to i32
store i32 %45, i32* %16
%46 = load double, double* %13
%47 = call i64 @floor(double %46)
%48 = trunc i64 %47 to i32
store i32 %48, i32* %17
store double 0.000000e+00, double* %19
store i32 0, i32* %21
br label %49
49: ; preds = %98, %42
%50 = load i32, i32* %21
%51 = icmp slt i32 %50, 4
br i1 %51, label %52, label %101
52: ; preds = %49
store double 0.000000e+00, double* %18
%53 = load i32, i32* %17
%54 = load i32, i32* %21
%55 = add nsw i32 %53, %54
%56 = sub nsw i32 %55, 1
store i32 %56, i32* %23
store i32 0, i32* %20
br label %57
57: ; preds = %84, %52
%58 = load i32, i32* %20
%59 = icmp slt i32 %58, 4
br i1 %59, label %60, label %87
60: ; preds = %57
%61 = load i32, i32* %16
%62 = load i32, i32* %20
%63 = add nsw i32 %61, %62
%64 = sub nsw i32 %63, 1
store i32 %64, i32* %22
%65 = load float*, float** %9
%66 = load i32, i32* %23
%67 = load i32, i32* %10
%68 = mul nsw i32 %66, %67
%69 = load i32, i32* %22
%70 = add nsw i32 %68, %69
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds float, float* %65, i64 %71
%73 = load float, float* %72
%74 = fpext float %73 to double
%75 = load double, double* %12
%76 = load i32, i32* %22
%77 = sitofp i32 %76 to double
%78 = fsub double %75, %77
%79 = load double, double* %14
%80 = load double, double* %15
%81 = call double @cubic_weight(double %78, double %79, double %80)
%82 = load double, double* %18
%83 = call double @llvm.fmuladd.f64(double %74, double %81, double %82)
store double %83, double* %18
br label %84
84: ; preds = %60
%85 = load i32, i32* %20
%86 = add nsw i32 %85, 1
store i32 %86, i32* %20
br label %57
87: ; preds = %57
%88 = load double, double* %18
%89 = load double, double* %13
%90 = load i32, i32* %23
%91 = sitofp i32 %90 to double
%92 = fsub double %89, %91
%93 = load double, double* %14
%94 = load double, double* %15
%95 = call double @cubic_weight(double %92, double %93, double %94)
%96 = load double, double* %19
%97 = call double @llvm.fmuladd.f64(double %88, double %95, double %96)
store double %97, double* %19
br label %98
98: ; preds = %87
%99 = load i32, i32* %21
%100 = add nsw i32 %99, 1
store i32 %100, i32* %21
br label %49
101: ; preds = %49
%102 = load double, double* %19
store double %102, double* %8
br label %103
103: ; preds = %101, %41
%104 = load double, double* %8
ret double %104
}

LLVM IR (-O2):
define double @interpolate_pixel_cubic(float* nocapture %0, i32 %1, i32 %2, double %3, double %4, double %5, double %6) {
%8 = fcmp olt double %3, 3.000000e+00
br i1 %8, label %76, label %9
9: ; preds = %7
%10 = add nsw i32 %1, -3
%11 = sitofp i32 %10 to double
%12 = fcmp ole double %11, %3
%13 = fcmp olt double %4, 3.000000e+00
%14 = or i1 %12, %13
br i1 %14, label %76, label %15
15: ; preds = %9
%16 = add nsw i32 %2, -3
%17 = sitofp i32 %16 to double
%18 = fcmp ugt double %17, %4
br i1 %18, label %19, label %76
19: ; preds = %15
%20 = tail call i64 @floor(double %3)
%21 = trunc i64 %20 to i32
%22 = tail call i64 @floor(double %4)
%23 = trunc i64 %22 to i32
%24 = add i32 %23, -1
%25 = add i32 %21, -1
%26 = sitofp i32 %25 to double
%27 = fsub double %3, %26
%28 = sitofp i32 %21 to double
%29 = fsub double %3, %28
%30 = add i32 %21, 1
%31 = sitofp i32 %30 to double
%32 = fsub double %3, %31
%33 = add i32 %21, 2
%34 = sitofp i32 %33 to double
%35 = fsub double %3, %34
br label %36
36: ; preds = %19, %36
%37 = phi i64 [ 0, %19 ], [ %74, %36 ]
%38 = phi double [ 0.000000e+00, %19 ], [ %73, %36 ]
%39 = trunc i64 %37 to i32
%40 = add i32 %24, %39
%41 = mul nsw i32 %40, %1
%42 = add nsw i32 %25, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds float, float* %0, i64 %43
%45 = load float, float* %44
%46 = fpext float %45 to double
%47 = tail call double @cubic_weight(double %27, double %5, double %6)
%48 = tail call double @llvm.fmuladd.f64(double %46, double %47, double 0.000000e+00)
%49 = add nsw i32 %41, %21
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds float, float* %0, i64 %50
%52 = load float, float* %51
%53 = fpext float %52 to double
%54 = tail call double @cubic_weight(double %29, double %5, double %6)
%55 = tail call double @llvm.fmuladd.f64(double %53, double %54, double %48)
%56 = add nsw i32 %30, %41
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds float, float* %0, i64 %57
%59 = load float, float* %58
%60 = fpext float %59 to double
%61 = tail call double @cubic_weight(double %32, double %5, double %6)
%62 = tail call double @llvm.fmuladd.f64(double %60, double %61, double %55)
%63 = add nsw i32 %33, %41
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds float, float* %0, i64 %64
%66 = load float, float* %65
%67 = fpext float %66 to double
%68 = tail call double @cubic_weight(double %35, double %5, double %6)
%69 = tail call double @llvm.fmuladd.f64(double %67, double %68, double %62)
%70 = sitofp i32 %40 to double
%71 = fsub double %4, %70
%72 = tail call double @cubic_weight(double %71, double %5, double %6)
%73 = tail call double @llvm.fmuladd.f64(double %69, double %72, double %38)
%74 = add nuw nsw i64 %37, 1
%75 = icmp eq i64 %74, 4
br i1 %75, label %76, label %36
76: ; preds = %36, %7, %9, %15
%77 = phi double [ 0.000000e+00, %15 ], [ 0.000000e+00, %9 ], [ 0.000000e+00, %7 ], [ %73, %36 ]
ret double %77
}