#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__ floor(double);
int /*<<< orphan*/ printf(char *);
double bilinear_interpolate(double x, double y, int naxis1, int naxis2,
                            double **image) {
  double f_R[2];
  double f_Q[2][2];
  double x1, x2, y1, y2;
  int xi, yi;
  double new_value;
  xi = (int)floor(x);
  yi = (int)floor(y);
  x1 = (double)xi;
  x2 = x1 + 1;
  y1 = (double)yi;
  y2 = y1 + 1;
  if ((xi == naxis1) || (xi == 0) || (yi == naxis2) || (yi == 0)) {
    printf("Interpolation boundary issues.\n");
    new_value = image[yi][xi];
  } else {
    f_Q[0][0] = image[yi][xi];
    f_Q[1][0] = image[yi][xi + 1];
    f_Q[0][1] = image[yi + 1][xi];
    f_Q[1][1] = image[yi + 1][xi + 1];
    f_R[0] =
        ((x2 - x) / (x2 - x1)) * f_Q[0][0] + ((x - x1) / (x2 - x1)) * f_Q[1][0];
    f_R[1] =
        ((x2 - x) / (x2 - x1)) * f_Q[0][1] + ((x - x1) / (x2 - x1)) * f_Q[1][1];
    new_value =
        ((y2 - y) / (y2 - y1)) * f_R[0] + ((y - y1) / (y2 - y1)) * f_R[1];
  }
  return new_value;
}


x86 assembly (clang, -O0):
<bilinear_interpolate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x74(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x78(%rbp)
cvtsi2sdl -0x74(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe95(%rip),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
cvtsi2sdl -0x78(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xe79(%rip),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11bd <bilinear_interpolate+0x9d>
cmpl   $0x0,-0x74(%rbp)
je     11bd <bilinear_interpolate+0x9d>
mov    -0x78(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11bd <bilinear_interpolate+0x9d>
cmpl   $0x0,-0x78(%rbp)
jne    11e8 <bilinear_interpolate+0xc8>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x74(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    1339 <bilinear_interpolate+0x219>
mov    -0x20(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x74(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x74(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x78(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x74(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x78(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x74(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm3
subsd  -0x58(%rbp),%xmm3
divsd  %xmm3,%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm3
subsd  -0x58(%rbp),%xmm3
divsd  %xmm3,%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x70(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
subsd  -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
subsd  -0x68(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm3
subsd  -0x68(%rbp),%xmm3
divsd  %xmm3,%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bilinear_interpolate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,%ebp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <floor@plt>
mov    %rax,%r15
movsd  (%rsp),%xmm0
call   1040 <floor@plt>
mov    %rax,%rbx
cmp    %ebp,%r15d
je     123c <bilinear_interpolate+0x11c>
test   %r15d,%r15d
je     123c <bilinear_interpolate+0x11c>
cmp    %r12d,%ebx
je     123c <bilinear_interpolate+0x11c>
test   %ebx,%ebx
je     123c <bilinear_interpolate+0x11c>
cvtsi2sd %r15d,%xmm3
movsd  0xe7c(%rip),%xmm5
movapd %xmm3,%xmm4
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
addsd  %xmm5,%xmm4
addsd  %xmm1,%xmm5
shl    $0x20,%rbx
mov    %rbx,%rax
sar    $0x1d,%rax
mov    (%r14,%rax,1),%rcx
shl    $0x20,%r15
mov    %r15,%rax
sar    $0x1d,%rax
movabs $0x100000000,%rdx
add    %rdx,%r15
sar    $0x1d,%r15
add    %rdx,%rbx
sar    $0x1d,%rbx
mov    (%r14,%rbx,1),%rdx
movapd %xmm4,%xmm2
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm2
subsd  %xmm3,%xmm4
divsd  %xmm4,%xmm2
subsd  %xmm3,%xmm0
divsd  %xmm4,%xmm0
movsd  (%rcx,%r15,1),%xmm3
mulsd  %xmm0,%xmm3
movsd  (%rcx,%rax,1),%xmm4
mulsd  %xmm2,%xmm4
mulsd  (%rdx,%r15,1),%xmm0
addsd  %xmm3,%xmm4
mulsd  (%rdx,%rax,1),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm5,%xmm3
movsd  (%rsp),%xmm0
subsd  %xmm0,%xmm3
subsd  %xmm1,%xmm5
divsd  %xmm5,%xmm3
mulsd  %xmm4,%xmm3
subsd  %xmm1,%xmm0
divsd  %xmm5,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
jmp    1257 <bilinear_interpolate+0x137>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
movslq %ebx,%rax
mov    (%r14,%rax,8),%rax
movslq %r15d,%rcx
movsd  (%rax,%rcx,8),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Interpolation boundary issues.\0A\00"
define double @bilinear_interpolate(double %0, double %1, i32 %2, i32 %3, double** %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double**
%11 = alloca [2 x double]
%12 = alloca [2 x [2 x double]]
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store double** %4, double*** %10
%20 = load double, double* %6
%21 = call i64 @floor(double %20)
%22 = trunc i64 %21 to i32
store i32 %22, i32* %17
%23 = load double, double* %7
%24 = call i64 @floor(double %23)
%25 = trunc i64 %24 to i32
store i32 %25, i32* %18
%26 = load i32, i32* %17
%27 = sitofp i32 %26 to double
store double %27, double* %13
%28 = load double, double* %13
%29 = fadd double %28, 1.000000e+00
store double %29, double* %14
%30 = load i32, i32* %18
%31 = sitofp i32 %30 to double
store double %31, double* %15
%32 = load double, double* %15
%33 = fadd double %32, 1.000000e+00
store double %33, double* %16
%34 = load i32, i32* %17
%35 = load i32, i32* %8
%36 = icmp eq i32 %34, %35
br i1 %36, label %47, label %37
37: ; preds = %5
%38 = load i32, i32* %17
%39 = icmp eq i32 %38, 0
br i1 %39, label %47, label %40
40: ; preds = %37
%41 = load i32, i32* %18
%42 = load i32, i32* %9
%43 = icmp eq i32 %41, %42
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = load i32, i32* %18
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %44, %40, %37, %5
%48 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%49 = load double**, double*** %10
%50 = load i32, i32* %18
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double*, double** %49, i64 %51
%53 = load double*, double** %52
%54 = load i32, i32* %17
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
store double %57, double* %19
br label %173
58: ; preds = %44
%59 = load double**, double*** %10
%60 = load i32, i32* %18
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double*, double** %59, i64 %61
%63 = load double*, double** %62
%64 = load i32, i32* %17
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 0
%69 = getelementptr inbounds [2 x double], [2 x double]* %68, i64 0, i64 0
store double %67, double* %69
%70 = load double**, double*** %10
%71 = load i32, i32* %18
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double*, double** %70, i64 %72
%74 = load double*, double** %73
%75 = load i32, i32* %17
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %74, i64 %77
%79 = load double, double* %78
%80 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 1
%81 = getelementptr inbounds [2 x double], [2 x double]* %80, i64 0, i64 0
store double %79, double* %81
%82 = load double**, double*** %10
%83 = load i32, i32* %18
%84 = add nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double*, double** %82, i64 %85
%87 = load double*, double** %86
%88 = load i32, i32* %17
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double, double* %87, i64 %89
%91 = load double, double* %90
%92 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 0
%93 = getelementptr inbounds [2 x double], [2 x double]* %92, i64 0, i64 1
store double %91, double* %93
%94 = load double**, double*** %10
%95 = load i32, i32* %18
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds double*, double** %94, i64 %97
%99 = load double*, double** %98
%100 = load i32, i32* %17
%101 = add nsw i32 %100, 1
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %99, i64 %102
%104 = load double, double* %103
%105 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 1
%106 = getelementptr inbounds [2 x double], [2 x double]* %105, i64 0, i64 1
store double %104, double* %106
%107 = load double, double* %14
%108 = load double, double* %6
%109 = fsub double %107, %108
%110 = load double, double* %14
%111 = load double, double* %13
%112 = fsub double %110, %111
%113 = fdiv double %109, %112
%114 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 0
%115 = getelementptr inbounds [2 x double], [2 x double]* %114, i64 0, i64 0
%116 = load double, double* %115
%117 = load double, double* %6
%118 = load double, double* %13
%119 = fsub double %117, %118
%120 = load double, double* %14
%121 = load double, double* %13
%122 = fsub double %120, %121
%123 = fdiv double %119, %122
%124 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 1
%125 = getelementptr inbounds [2 x double], [2 x double]* %124, i64 0, i64 0
%126 = load double, double* %125
%127 = fmul double %123, %126
%128 = call double @llvm.fmuladd.f64(double %113, double %116, double %127)
%129 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 0
store double %128, double* %129
%130 = load double, double* %14
%131 = load double, double* %6
%132 = fsub double %130, %131
%133 = load double, double* %14
%134 = load double, double* %13
%135 = fsub double %133, %134
%136 = fdiv double %132, %135
%137 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 0
%138 = getelementptr inbounds [2 x double], [2 x double]* %137, i64 0, i64 1
%139 = load double, double* %138
%140 = load double, double* %6
%141 = load double, double* %13
%142 = fsub double %140, %141
%143 = load double, double* %14
%144 = load double, double* %13
%145 = fsub double %143, %144
%146 = fdiv double %142, %145
%147 = getelementptr inbounds [2 x [2 x double]], [2 x [2 x double]]* %12, i64 0, i64 1
%148 = getelementptr inbounds [2 x double], [2 x double]* %147, i64 0, i64 1
%149 = load double, double* %148
%150 = fmul double %146, %149
%151 = call double @llvm.fmuladd.f64(double %136, double %139, double %150)
%152 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 1
store double %151, double* %152
%153 = load double, double* %16
%154 = load double, double* %7
%155 = fsub double %153, %154
%156 = load double, double* %16
%157 = load double, double* %15
%158 = fsub double %156, %157
%159 = fdiv double %155, %158
%160 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 0
%161 = load double, double* %160
%162 = load double, double* %7
%163 = load double, double* %15
%164 = fsub double %162, %163
%165 = load double, double* %16
%166 = load double, double* %15
%167 = fsub double %165, %166
%168 = fdiv double %164, %167
%169 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 1
%170 = load double, double* %169
%171 = fmul double %168, %170
%172 = call double @llvm.fmuladd.f64(double %159, double %161, double %171)
store double %172, double* %19
br label %173
173: ; preds = %58, %47
%174 = load double, double* %19
ret double %174
}

LLVM IR (-O2):
@str = [31 x i8] c"Interpolation boundary issues.\00"
define double @bilinear_interpolate(double %0, double %1, i32 %2, i32 %3, double** nocapture %4) {
%6 = tail call i64 @floor(double %0)
%7 = trunc i64 %6 to i32
%8 = tail call i64 @floor(double %1)
%9 = trunc i64 %8 to i32
%10 = sitofp i32 %7 to double
%11 = fadd double %10, 1.000000e+00
%12 = sitofp i32 %9 to double
%13 = fadd double %12, 1.000000e+00
%14 = icmp eq i32 %7, %2
%15 = icmp eq i32 %7, 0
%16 = or i1 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %5
%18 = icmp eq i32 %9, %3
%19 = icmp eq i32 %9, 0
%20 = or i1 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17, %5
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%23 = shl i64 %8, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds double*, double** %4, i64 %24
%26 = load double*, double** %25
%27 = shl i64 %6, 32
%28 = ashr exact i64 %27, 32
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
br label %68
31: ; preds = %17
%32 = shl i64 %8, 32
%33 = ashr exact i64 %32, 32
%34 = getelementptr inbounds double*, double** %4, i64 %33
%35 = load double*, double** %34
%36 = shl i64 %6, 32
%37 = ashr exact i64 %36, 32
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = add i64 %36, 4294967296
%41 = ashr exact i64 %40, 32
%42 = getelementptr inbounds double, double* %35, i64 %41
%43 = load double, double* %42
%44 = add i64 %32, 4294967296
%45 = ashr exact i64 %44, 32
%46 = getelementptr inbounds double*, double** %4, i64 %45
%47 = load double*, double** %46
%48 = getelementptr inbounds double, double* %47, i64 %37
%49 = load double, double* %48
%50 = getelementptr inbounds double, double* %47, i64 %41
%51 = load double, double* %50
%52 = fsub double %11, %0
%53 = fsub double %11, %10
%54 = fdiv double %52, %53
%55 = fsub double %0, %10
%56 = fdiv double %55, %53
%57 = fmul double %56, %43
%58 = tail call double @llvm.fmuladd.f64(double %54, double %39, double %57)
%59 = fmul double %56, %51
%60 = tail call double @llvm.fmuladd.f64(double %54, double %49, double %59)
%61 = fsub double %13, %1
%62 = fsub double %13, %12
%63 = fdiv double %61, %62
%64 = fsub double %1, %12
%65 = fdiv double %64, %62
%66 = fmul double %65, %60
%67 = tail call double @llvm.fmuladd.f64(double %63, double %58, double %66)
br label %68
68: ; preds = %31, %21
%69 = phi double [ %30, %21 ], [ %67, %31 ]
ret double %69
}