#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 SmoothNoise(int, int);
double cosInterpolate(double, double, double);
double InterpolateNoise(double x, double y) {
  int intX, intY;
  double fractX, fractY, v1, v2, v3, v4, i1, i2;
  intX = (int)x;
  fractX = x - intX;
  intY = (int)y;
  fractY = y - intY;
  v1 = SmoothNoise(intX, intY);
  v2 = SmoothNoise(intX + 1, intY);
  v3 = SmoothNoise(intX, intY + 1);
  v4 = SmoothNoise(intX + 1, intY + 1);
  i1 = cosInterpolate(v1, v2, fractX);
  i2 = cosInterpolate(v3, v4, fractX);
  return cosInterpolate(i1, i2, fractY);
}


x86 assembly (clang, -O0):
<InterpolateNoise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
cvttsd2si -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    -0x18(%rbp),%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1040 <cosInterpolate@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1040 <cosInterpolate@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
call   1040 <cosInterpolate@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InterpolateNoise>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
cvttsd2si %xmm0,%ebx
cvttpd2dq %xmm0,%xmm2
cvtdq2pd %xmm2,%xmm3
cvttsd2si %xmm1,%ebp
cvttpd2dq %xmm1,%xmm2
subsd  %xmm3,%xmm0
movapd %xmm0,0x20(%rsp)
cvtdq2pd %xmm2,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,0x30(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,(%rsp)
lea    0x1(%rbx),%r14d
mov    %r14d,%edi
mov    %ebp,%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,0x18(%rsp)
add    $0x1,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r14d,%edi
mov    %ebp,%esi
call   1030 <SmoothNoise@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movaps 0x20(%rsp),%xmm2
call   1040 <cosInterpolate@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movaps 0x20(%rsp),%xmm2
call   1040 <cosInterpolate@plt>
movaps %xmm0,%xmm1
movsd  (%rsp),%xmm0
movaps 0x30(%rsp),%xmm2
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <cosInterpolate@plt>

LLVM IR (-O0):
define double @InterpolateNoise(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %3
store double %1, double* %4
%15 = load double, double* %3
%16 = fptosi double %15 to i32
store i32 %16, i32* %5
%17 = load double, double* %3
%18 = load i32, i32* %5
%19 = sitofp i32 %18 to double
%20 = fsub double %17, %19
store double %20, double* %7
%21 = load double, double* %4
%22 = fptosi double %21 to i32
store i32 %22, i32* %6
%23 = load double, double* %4
%24 = load i32, i32* %6
%25 = sitofp i32 %24 to double
%26 = fsub double %23, %25
store double %26, double* %8
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = call double @SmoothNoise(i32 %27, i32 %28)
store double %29, double* %9
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
%32 = load i32, i32* %6
%33 = call double @SmoothNoise(i32 %31, i32 %32)
store double %33, double* %10
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = call double @SmoothNoise(i32 %34, i32 %36)
store double %37, double* %11
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
%42 = call double @SmoothNoise(i32 %39, i32 %41)
store double %42, double* %12
%43 = load double, double* %9
%44 = load double, double* %10
%45 = load double, double* %7
%46 = call double @cosInterpolate(double %43, double %44, double %45)
store double %46, double* %13
%47 = load double, double* %11
%48 = load double, double* %12
%49 = load double, double* %7
%50 = call double @cosInterpolate(double %47, double %48, double %49)
store double %50, double* %14
%51 = load double, double* %13
%52 = load double, double* %14
%53 = load double, double* %8
%54 = call double @cosInterpolate(double %51, double %52, double %53)
ret double %54
}

LLVM IR (-O2):
define double @InterpolateNoise(double %0, double %1) {
%3 = fptosi double %0 to i32
%4 = sitofp i32 %3 to double
%5 = fsub double %0, %4
%6 = fptosi double %1 to i32
%7 = sitofp i32 %6 to double
%8 = fsub double %1, %7
%9 = tail call double @SmoothNoise(i32 %3, i32 %6)
%10 = add nsw i32 %3, 1
%11 = tail call double @SmoothNoise(i32 %10, i32 %6)
%12 = add nsw i32 %6, 1
%13 = tail call double @SmoothNoise(i32 %3, i32 %12)
%14 = tail call double @SmoothNoise(i32 %10, i32 %12)
%15 = tail call double @cosInterpolate(double %9, double %11, double %5)
%16 = tail call double @cosInterpolate(double %13, double %14, double %5)
%17 = tail call double @cosInterpolate(double %15, double %16, double %8)
ret double %17
}