#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 */
typedef size_t tmpv;
typedef scalar_t__ *dimx;

/* Variables and functions */
double UCHAR_MAX;
double _cubic(double);
unsigned char p3dBicubicInterpolation_p2c_8(unsigned char *in_im, int dimx,
                                            int dimy, double x0, double y0) {
  int u0 = (int)x0;
  int v0 = (int)y0;
  int u, tmpu, tmpv;
  int v;
  double p;
  int i, j;
  double q = 0;
  for (j = -1; j <= 2; j++) {
    v = v0 + j;
    p = 0;
    for (i = -1; i <= 2; i++) {
      u = u0 + i;
      tmpu = u;
      tmpv = v;
      if (u < 0)
        tmpu = 0;
      if (u > ((int)dimx - 1))
        tmpu = (int)dimx - 1;
      if (v < 0)
        tmpv = v + (int)dimy;
      if (v > ((int)dimy - 1))
        tmpv = v - (int)dimy;
      p = p + in_im[((tmpv) * (dimx) + (tmpu))] * _cubic(x0 - u);
    }
    q = q + p * _cubic(y0 - v);
  }
  q = q + 0.5;
  if (q < 0.0)
    q = 0.0;
  if (q >= UCHAR_MAX)
    q = UCHAR_MAX;
  return (unsigned char)q;
}


x86 assembly (clang, -O0):
<p3dBicubicInterpolation_p2c_8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
cvttsd2si -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0xffffffff,-0x48(%rbp)
cmpl   $0x2,-0x48(%rbp)
jg     1296 <p3dBicubicInterpolation_p2c_8+0x186>
mov    -0x28(%rbp),%eax
add    -0x48(%rbp),%eax
mov    %eax,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
cmpl   $0x2,-0x44(%rbp)
jg     1247 <p3dBicubicInterpolation_p2c_8+0x137>
mov    -0x24(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    119d <p3dBicubicInterpolation_p2c_8+0x8d>
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11b7 <p3dBicubicInterpolation_p2c_8+0xa7>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11ca <p3dBicubicInterpolation_p2c_8+0xba>
mov    -0x38(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11e4 <p3dBicubicInterpolation_p2c_8+0xd4>
mov    -0x38(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
subsd  %xmm1,%xmm0
call   1030 <_cubic@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    116d <p3dBicubicInterpolation_p2c_8+0x5d>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x38(%rbp),%xmm1
subsd  %xmm1,%xmm0
call   1030 <_cubic@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    114b <p3dBicubicInterpolation_p2c_8+0x3b>
movsd  0xd62(%rip),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    12be <p3dBicubicInterpolation_p2c_8+0x1ae>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    0x2d26(%rip),%rax
ucomisd (%rax),%xmm0
jb     12e4 <p3dBicubicInterpolation_p2c_8+0x1d4>
mov    0x2d15(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
cvttsd2si -0x50(%rbp),%eax
movzbl %al,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dBicubicInterpolation_p2c_8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %edx,%r15d
cvttsd2si %xmm0,%eax
movsd  %xmm1,0x30(%rsp)
cvttsd2si %xmm1,%ebp
lea    -0x1(%rsi),%r8d
neg    %edx
mov    %edx,0x14(%rsp)
xor    %r9d,%r9d
mov    %eax,%edx
add    $0xffffffff,%edx
mov    $0x0,%ebx
cmovns %edx,%ebx
test   %eax,%eax
mov    $0x0,%ecx
cmovns %eax,%ecx
cmp    %esi,%eax
cmovg  %r8d,%ebx
mov    %rbx,0x20(%rsp)
cvtsi2sd %edx,%xmm3
cmovge %r8d,%ecx
mov    %rcx,0x18(%rsp)
cvttpd2dq %xmm0,%xmm1
mov    %rdi,%rbx
movapd %xmm0,%xmm4
cvtdq2pd %xmm1,%xmm1
mov    %eax,%edx
add    $0x1,%edx
mov    $0x0,%r13d
cmovns %edx,%r13d
cmp    %esi,%edx
cmovge %r8d,%r13d
cvtsi2sd %edx,%xmm2
subsd  %xmm3,%xmm4
movapd %xmm4,0x60(%rsp)
movapd %xmm0,%xmm3
add    $0x2,%eax
cmovns %eax,%r9d
subsd  %xmm1,%xmm3
movapd %xmm3,0x50(%rsp)
movapd %xmm0,%xmm1
mov    %rsi,0x28(%rsp)
cmp    %esi,%eax
cmovge %r8d,%r9d
mov    %r9d,0x10(%rsp)
subsd  %xmm2,%xmm1
movapd %xmm1,0x40(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movapd %xmm0,0x70(%rsp)
add    $0xffffffff,%ebp
mov    $0x4,%r12d
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x38(%rsp)
mov    %ebp,%r14d
sar    $0x1f,%r14d
and    %r15d,%r14d
cmp    %r15d,%ebp
cmovge 0x14(%rsp),%r14d
add    %ebp,%r14d
imul   0x28(%rsp),%r14d
mov    0x20(%rsp),%rax
add    %r14d,%eax
cltq
movzbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
movapd 0x60(%rsp),%xmm0
call   1030 <_cubic@plt>
mulsd  (%rsp),%xmm0
addsd  0xdb4(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    0x18(%rsp),%rax
add    %r14d,%eax
cltq
movzbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x50(%rsp),%xmm0
call   1030 <_cubic@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%r13,1),%eax
cltq
movzbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x40(%rsp),%xmm0
call   1030 <_cubic@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
add    0x10(%rsp),%r14d
movslq %r14d,%rax
movzbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x70(%rsp),%xmm0
call   1030 <_cubic@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0x30(%rsp),%xmm0
subsd  %xmm1,%xmm0
call   1030 <_cubic@plt>
movsd  0x38(%rsp),%xmm1
mulsd  (%rsp),%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%ebp
add    $0xffffffff,%r12d
jne    1200 <p3dBicubicInterpolation_p2c_8+0xf0>
addsd  0xcd1(%rip),%xmm1
xorpd  %xmm0,%xmm0
maxsd  %xmm1,%xmm0
mov    0x2cb2(%rip),%rax
movsd  (%rax),%xmm1
movapd %xmm1,%xmm2
cmplesd %xmm0,%xmm2
movapd %xmm2,%xmm3
andnpd %xmm0,%xmm3
andpd  %xmm1,%xmm2
orpd   %xmm3,%xmm2
cvttsd2si %xmm2,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@UCHAR_MAX = global double 0.000000e+00
define zeroext i8 @p3dBicubicInterpolation_p2c_8(i8* nocapture %0, i32 %1, i32 %2, double %3, double %4) {
%6 = fptosi double %3 to i32
%7 = fptosi double %4 to i32
%8 = add nsw i32 %1, -1
%9 = sub i32 0, %2
%10 = add nsw i32 %6, -1
%11 = icmp sgt i32 %10, 0
%12 = select i1 %11, i32 %10, i32 0
%13 = icmp sgt i32 %6, %1
%14 = select i1 %13, i32 %8, i32 %12
%15 = sitofp i32 %10 to double
%16 = fsub double %3, %15
%17 = icmp sgt i32 %6, 0
%18 = select i1 %17, i32 %6, i32 0
%19 = icmp slt i32 %6, %1
%20 = select i1 %19, i32 %18, i32 %8
%21 = sitofp i32 %6 to double
%22 = fsub double %3, %21
%23 = add nsw i32 %6, 1
%24 = icmp sgt i32 %23, 0
%25 = select i1 %24, i32 %23, i32 0
%26 = icmp slt i32 %23, %1
%27 = select i1 %26, i32 %25, i32 %8
%28 = sitofp i32 %23 to double
%29 = fsub double %3, %28
%30 = add nsw i32 %6, 2
%31 = icmp sgt i32 %30, 0
%32 = select i1 %31, i32 %30, i32 0
%33 = icmp slt i32 %30, %1
%34 = select i1 %33, i32 %32, i32 %8
%35 = sitofp i32 %30 to double
%36 = fsub double %3, %35
br label %37
37: ; preds = %5, %37
%38 = phi double [ 0.000000e+00, %5 ], [ %78, %37 ]
%39 = phi i32 [ -1, %5 ], [ %79, %37 ]
%40 = add nsw i32 %39, %7
%41 = icmp slt i32 %40, 0
%42 = select i1 %41, i32 %2, i32 0
%43 = icmp slt i32 %40, %2
%44 = select i1 %43, i32 %42, i32 %9
%45 = add i32 %44, %40
%46 = mul nsw i32 %45, %1
%47 = add nsw i32 %14, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = load i8, i8* %49
%51 = uitofp i8 %50 to double
%52 = tail call double @_cubic(double %16)
%53 = tail call double @llvm.fmuladd.f64(double %51, double %52, double 0.000000e+00)
%54 = add nsw i32 %20, %46
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %0, i64 %55
%57 = load i8, i8* %56
%58 = uitofp i8 %57 to double
%59 = tail call double @_cubic(double %22)
%60 = tail call double @llvm.fmuladd.f64(double %58, double %59, double %53)
%61 = add nsw i32 %27, %46
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %0, i64 %62
%64 = load i8, i8* %63
%65 = uitofp i8 %64 to double
%66 = tail call double @_cubic(double %29)
%67 = tail call double @llvm.fmuladd.f64(double %65, double %66, double %60)
%68 = add nsw i32 %34, %46
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %0, i64 %69
%71 = load i8, i8* %70
%72 = uitofp i8 %71 to double
%73 = tail call double @_cubic(double %36)
%74 = tail call double @llvm.fmuladd.f64(double %72, double %73, double %67)
%75 = sitofp i32 %40 to double
%76 = fsub double %4, %75
%77 = tail call double @_cubic(double %76)
%78 = tail call double @llvm.fmuladd.f64(double %74, double %77, double %38)
%79 = add nsw i32 %39, 1
%80 = icmp eq i32 %79, 3
br i1 %80, label %81, label %37
81: ; preds = %37
%82 = fadd double %78, 5.000000e-01
%83 = fcmp olt double %82, 0.000000e+00
%84 = select i1 %83, double 0.000000e+00, double %82
%85 = load double, double* @UCHAR_MAX
%86 = fcmp oge double %84, %85
%87 = select i1 %86, double %85, double %84
%88 = fptoui double %87 to i8
ret i8 %88
}