#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 bilinearInterpolation(double, double, double, double, double, double);
void scaleBilinearBW(int *srcImgVector, int srcImgWidth, int srcImgHeight,
                     int *dstImgVector, int dstImgWidth, int dstImgHeight) {
  const double dblSrcW = (double)srcImgWidth;
  const double dblSrcH = (double)srcImgHeight;
  const double dblDstW = (double)dstImgWidth;
  const double dblDstH = (double)dstImgHeight;
  const double scaleX = dblSrcW / dblDstW;
  const double scaleY = dblSrcH / dblDstH;
  double dblX = 0;
  double dblY = 0;
  double gx = 0;
  double gy = 0;
  int gxi = 0;
  int gyi = 0;
  int location00 = 0;
  int location10 = 0;
  int location01 = 0;
  int location11 = 0;
  double pixel00 = 0;
  double pixel10 = 0;
  double pixel01 = 0;
  double pixel11 = 0;
  double result = 0;
  int currentPixel = 0;
  for (int y = 0; y < dstImgHeight; ++y) {
    for (int x = 0; x < dstImgWidth; ++x) {
      dblX = (double)x;
      dblY = (double)y;
      gx = dblX * scaleX;
      gy = dblY * scaleY;
      gxi = (int)gx;
      gyi = (int)gy;
      location00 = (gyi * srcImgWidth) + gxi;
      location10 = (gyi * srcImgWidth) + gxi + 1;
      location01 = ((gyi + 1) * srcImgWidth) + gxi;
      location11 = ((gyi + 1) * srcImgWidth) + gxi + 1;
      pixel00 = srcImgVector[location00];
      pixel10 = srcImgVector[location10];
      pixel01 = srcImgVector[location01];
      pixel11 = srcImgVector[location11];
      result = bilinearInterpolation(pixel00, pixel10, pixel01, pixel11,
                                     (gx - gxi), (gy - gyi));
      currentPixel = (y * dstImgWidth) + x;
      dstImgVector[currentPixel] = result;
    }
  }
}


x86 assembly (clang, -O0):
<scaleBilinearBW>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
movl   $0x0,-0x88(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movl   $0x0,-0xb4(%rbp)
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    13c4 <scaleBilinearBW+0x2b4>
movl   $0x0,-0xbc(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13ab <scaleBilinearBW+0x29b>
cvtsi2sdl -0xbc(%rbp),%xmm0
ff
movsd  %xmm0,-0x58(%rbp)
cvtsi2sdl -0xb8(%rbp),%xmm0
ff
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
cvttsd2si -0x68(%rbp),%eax
mov    %eax,-0x74(%rbp)
cvttsd2si -0x70(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
imul   -0xc(%rbp),%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x78(%rbp),%eax
imul   -0xc(%rbp),%eax
add    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
imul   -0xc(%rbp),%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
imul   -0xc(%rbp),%eax
add    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x7c(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x8(%rbp),%rax
movslq -0x80(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x8(%rbp),%rax
movslq -0x84(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
mov    -0x8(%rbp),%rax
movslq -0x88(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x98(%rbp),%xmm1
ff
movsd  -0xa0(%rbp),%xmm2
ff
movsd  -0xa8(%rbp),%xmm3
ff
movsd  -0x68(%rbp),%xmm4
cvtsi2sdl -0x74(%rbp),%xmm5
subsd  %xmm5,%xmm4
movsd  -0x70(%rbp),%xmm5
cvtsi2sdl -0x78(%rbp),%xmm6
subsd  %xmm6,%xmm5
call   1030 <bilinearInterpolation@plt>
movsd  %xmm0,-0xb0(%rbp)
ff
mov    -0xb8(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    -0xbc(%rbp),%eax
mov    %eax,-0xb4(%rbp)
cvttsd2si -0xb0(%rbp),%edx
ff
mov    -0x18(%rbp),%rax
movslq -0xb4(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    122b <scaleBilinearBW+0x11b>
jmp    13b0 <scaleBilinearBW+0x2a0>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1212 <scaleBilinearBW+0x102>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scaleBilinearBW>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8d,0x4(%rsp)
mov    %esi,(%rsp)
test   %r9d,%r9d
jle    1272 <scaleBilinearBW+0x162>
mov    %rcx,%rbx
mov    %rdi,%rbp
cvtsi2sdl (%rsp),%xmm1
cvtsi2sd %edx,%xmm2
mov    0x4(%rsp),%eax
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %r9d,%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
cltq
mov    %r9d,%ecx
mov    %rcx,0x18(%rsp)
mov    %eax,%r14d
shl    $0x2,%rax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
movsd  %xmm1,0x28(%rsp)
jmp    11b1 <scaleBilinearBW+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
add    0x20(%rsp),%rbx
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
cmp    0x18(%rsp),%rcx
je     1272 <scaleBilinearBW+0x162>
cmpl   $0x0,0x4(%rsp)
jle    1190 <scaleBilinearBW+0x80>
xorps  %xmm2,%xmm2
cvtsi2sdl 0x8(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm2
cvttsd2si %xmm2,%r12d
mov    %r12d,%r15d
mov    (%rsp),%eax
imul   %eax,%r15d
add    $0x1,%r12d
imul   %eax,%r12d
cvttpd2dq %xmm2,%xmm0
cvtdq2pd %xmm0,%xmm0
subsd  %xmm0,%xmm2
movapd %xmm2,0x30(%rsp)
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm4,%xmm4
cvtsi2sd %r13d,%xmm4
mulsd  %xmm1,%xmm4
cvttsd2si %xmm4,%eax
lea    (%r15,%rax,1),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
cvtsi2sdl 0x0(%rbp,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl 0x4(%rbp,%rcx,4),%xmm1
add    %r12d,%eax
cltq
xorps  %xmm2,%xmm2
cvtsi2sdl 0x0(%rbp,%rax,4),%xmm2
xorps  %xmm3,%xmm3
cvtsi2sdl 0x4(%rbp,%rax,4),%xmm3
cvttpd2dq %xmm4,%xmm5
cvtdq2pd %xmm5,%xmm5
subsd  %xmm5,%xmm4
movaps 0x30(%rsp),%xmm5
call   1030 <bilinearInterpolation@plt>
movsd  0x28(%rsp),%xmm1
cvttsd2si %xmm0,%eax
mov    %eax,(%rbx,%r13,4)
add    $0x1,%r13
cmp    %r13,%r14
jne    1200 <scaleBilinearBW+0xf0>
jmp    1190 <scaleBilinearBW+0x80>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @scaleBilinearBW(i32* nocapture %0, i32 %1, i32 %2, i32* nocapture writeonly %3, i32 %4, i32 %5) {
%7 = sitofp i32 %1 to double
%8 = sitofp i32 %2 to double
%9 = sitofp i32 %4 to double
%10 = sitofp i32 %5 to double
%11 = fdiv double %7, %9
%12 = fdiv double %8, %10
%13 = icmp sgt i32 %5, 0
br i1 %13, label %14, label %32
14: ; preds = %6
%15 = icmp sgt i32 %4, 0
%16 = sext i32 %4 to i64
%17 = zext i32 %5 to i64
%18 = zext i32 %4 to i64
br label %19
19: ; preds = %14, %33
%20 = phi i64 [ 0, %14 ], [ %34, %33 ]
br i1 %15, label %21, label %33
21: ; preds = %19
%22 = trunc i64 %20 to i32
%23 = sitofp i32 %22 to double
%24 = fmul double %12, %23
%25 = fptosi double %24 to i32
%26 = mul nsw i32 %25, %1
%27 = add nsw i32 %25, 1
%28 = mul nsw i32 %27, %1
%29 = sitofp i32 %25 to double
%30 = fsub double %24, %29
%31 = mul nsw i64 %20, %16
br label %36
32: ; preds = %33, %6
ret void
33: ; preds = %36, %19
%34 = add nuw nsw i64 %20, 1
%35 = icmp eq i64 %34, %17
br i1 %35, label %32, label %19
36: ; preds = %21, %36
%37 = phi i64 [ 0, %21 ], [ %68, %36 ]
%38 = trunc i64 %37 to i32
%39 = sitofp i32 %38 to double
%40 = fmul double %11, %39
%41 = fptosi double %40 to i32
%42 = add nsw i32 %26, %41
%43 = add nsw i32 %42, 1
%44 = add nsw i32 %28, %41
%45 = add nsw i32 %44, 1
%46 = sext i32 %42 to i64
%47 = getelementptr inbounds i32, i32* %0, i64 %46
%48 = load i32, i32* %47
%49 = sitofp i32 %48 to double
%50 = sext i32 %43 to i64
%51 = getelementptr inbounds i32, i32* %0, i64 %50
%52 = load i32, i32* %51
%53 = sitofp i32 %52 to double
%54 = sext i32 %44 to i64
%55 = getelementptr inbounds i32, i32* %0, i64 %54
%56 = load i32, i32* %55
%57 = sitofp i32 %56 to double
%58 = sext i32 %45 to i64
%59 = getelementptr inbounds i32, i32* %0, i64 %58
%60 = load i32, i32* %59
%61 = sitofp i32 %60 to double
%62 = sitofp i32 %41 to double
%63 = fsub double %40, %62
%64 = tail call double @bilinearInterpolation(double %49, double %53, double %57, double %61, double %63, double %30)
%65 = add nsw i64 %37, %31
%66 = fptosi double %64 to i32
%67 = getelementptr inbounds i32, i32* %3, i64 %65
store i32 %66, i32* %67
%68 = add nuw nsw i64 %37, 1
%69 = icmp eq i64 %68, %18
br i1 %69, label %33, label %36
}