#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 floor(double);
double distorter_bilinear_filtering(double *map, double x, double y, int n_rows,
                                    int n_cols) {
  if (x < 0.0) {
    x = 0.0;
  }
  if (y < 0.0) {
    y = 0.0;
  }
  double v_row = y * (n_rows - 1);
  int r0 = (int)floor(v_row);
  double r_w1;
  if (r0 >= n_rows - 1) {
    r_w1 = 1.0;
    r0 = n_rows - 2;
  } else {
    r_w1 = v_row - floor(v_row);
  }
  int r1 = r0 + 1;
  double v_col = x * (n_cols - 1);
  int c0 = (int)floor(v_col);
  double c_w1;
  if (c0 >= n_cols - 1) {
    c_w1 = 1.0;
    c0 = n_cols - 2;
  } else {
    c_w1 = v_col - c0;
  }
  int c1 = c0 + 1;
  double final_val = map[r0 * n_cols + c0] * (1.0 - r_w1) * (1.0 - c_w1) +
                     map[r1 * n_cols + c0] * r_w1 * (1.0 - c_w1) +
                     map[r0 * n_cols + c1] * (1.0 - r_w1) * c_w1 +
                     map[r1 * n_cols + c1] * r_w1 * c_w1;
  return final_val;
}


x86 assembly (clang, -O0):
<distorter_bilinear_filtering>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1142 <distorter_bilinear_filtering+0x32>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1158 <distorter_bilinear_filtering+0x48>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     11ad <distorter_bilinear_filtering+0x9d>
movsd  0xe66(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d2 <distorter_bilinear_filtering+0xc2>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     1230 <distorter_bilinear_filtering+0x120>
movsd  0xde3(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x4c(%rbp)
jmp    1243 <distorter_bilinear_filtering+0x133>
movsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x4c(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x4c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xd96(%rip),%xmm1
subsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd85(%rip),%xmm2
subsd  -0x58(%rbp),%xmm2
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x4c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  -0x38(%rbp),%xmm1
movsd  0xd5d(%rip),%xmm3
subsd  -0x58(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x5c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  0xd2e(%rip),%xmm2
subsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x5c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distorter_bilinear_filtering>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r14
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
maxsd  %xmm0,%xmm3
movsd  %xmm3,0x10(%rsp)
maxsd  %xmm1,%xmm2
lea    -0x1(%rbx),%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <floor@plt>
cvttsd2si %xmm0,%eax
add    $0xfffffffe,%ebx
movsd  0xea0(%rip),%xmm1
cmp    %eax,%ebp
jle    116e <distorter_bilinear_filtering+0x5e>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
cmovg  %eax,%ebx
lea    -0x1(%r15),%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1030 <floor@plt>
cvttsd2si %xmm0,%ecx
lea    -0x2(%r15),%eax
cmp    %ecx,%ebp
cmovg  %ecx,%eax
jg     11ba <distorter_bilinear_filtering+0xaa>
movsd  0xe52(%rip),%xmm5
movapd %xmm5,%xmm3
movsd  0x8(%rsp),%xmm0
jmp    11da <distorter_bilinear_filtering+0xca>
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
movsd  0x10(%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  0x8(%rsp),%xmm0
movsd  0xe26(%rip),%xmm5
lea    0x1(%rbx),%ecx
imul   %r15d,%ebx
lea    (%rbx,%rax,1),%edx
movslq %edx,%rdx
movapd %xmm5,%xmm4
subsd  %xmm0,%xmm4
movsd  (%r14,%rdx,8),%xmm1
mulsd  %xmm4,%xmm1
subsd  %xmm3,%xmm5
imul   %r15d,%ecx
lea    (%rcx,%rax,1),%edx
movslq %edx,%rdx
movsd  (%r14,%rdx,8),%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm5,%xmm2
mulsd  %xmm1,%xmm5
addsd  %xmm2,%xmm5
lea    0x1(%rax,%rbx,1),%edx
movslq %edx,%rdx
mulsd  (%r14,%rdx,8),%xmm4
mulsd  %xmm3,%xmm4
addsd  %xmm5,%xmm4
lea    0x1(%rcx,%rax,1),%eax
cltq
mulsd  (%r14,%rax,8),%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @distorter_bilinear_filtering(double* nocapture %0, double %1, double %2, i32 %3, i32 %4) {
%6 = fcmp olt double %1, 0.000000e+00
%7 = select i1 %6, double 0.000000e+00, double %1
%8 = fcmp olt double %2, 0.000000e+00
%9 = select i1 %8, double 0.000000e+00, double %2
%10 = add nsw i32 %3, -1
%11 = sitofp i32 %10 to double
%12 = fmul double %9, %11
%13 = tail call double @llvm.floor.f64(double %12)
%14 = fptosi double %13 to i32
%15 = icmp sgt i32 %10, %14
%16 = add nsw i32 %3, -2
%17 = fsub double %12, %13
%18 = select i1 %15, double %17, double 1.000000e+00
%19 = select i1 %15, i32 %14, i32 %16
%20 = add nsw i32 %4, -1
%21 = sitofp i32 %20 to double
%22 = fmul double %7, %21
%23 = tail call double @llvm.floor.f64(double %22)
%24 = fptosi double %23 to i32
%25 = icmp sgt i32 %20, %24
%26 = add nsw i32 %4, -2
%27 = sitofp i32 %24 to double
%28 = fsub double %22, %27
%29 = select i1 %25, i32 %24, i32 %26
%30 = select i1 %25, double %28, double 1.000000e+00
%31 = add nsw i32 %19, 1
%32 = add nsw i32 %29, 1
%33 = mul nsw i32 %19, %4
%34 = add nsw i32 %33, %29
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %0, i64 %35
%37 = load double, double* %36
%38 = fsub double 1.000000e+00, %18
%39 = fmul double %38, %37
%40 = fsub double 1.000000e+00, %30
%41 = mul nsw i32 %31, %4
%42 = add nsw i32 %41, %29
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = load double, double* %44
%46 = fmul double %18, %45
%47 = fmul double %40, %46
%48 = tail call double @llvm.fmuladd.f64(double %39, double %40, double %47)
%49 = add nsw i32 %32, %33
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %0, i64 %50
%52 = load double, double* %51
%53 = fmul double %38, %52
%54 = tail call double @llvm.fmuladd.f64(double %53, double %30, double %48)
%55 = add nsw i32 %41, %32
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %0, i64 %56
%58 = load double, double* %57
%59 = fmul double %18, %58
%60 = tail call double @llvm.fmuladd.f64(double %59, double %30, double %54)
ret double %60
}