#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 */
int floor(float const);
float perlin_interpolate(float const, float const, float const);
float perlin_smooth_noise_2d(int const, int const);
float perlin_interpolated_noise_2d(const float x, const float y) {
  const int integer_X = floor(x);
  const float fractional_X = x - integer_X;
  const int integer_Y = floor(y);
  const float fractional_Y = y - integer_Y;
  const float v1 = perlin_smooth_noise_2d(integer_X, integer_Y);
  const float v2 = perlin_smooth_noise_2d(integer_X + 1, integer_Y);
  const float v3 = perlin_smooth_noise_2d(integer_X, integer_Y + 1);
  const float v4 = perlin_smooth_noise_2d(integer_X + 1, integer_Y + 1);
  const float i1 = perlin_interpolate(v1, v2, fractional_X);
  const float i2 = perlin_interpolate(v3, v4, fractional_X);
  return perlin_interpolate(i1, i2, fractional_Y);
}


x86 assembly (clang, -O0):
<perlin_interpolated_noise_2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <floor@plt>
mov    %eax,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <floor@plt>
mov    %eax,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    -0x14(%rbp),%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,-0x24(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
call   1030 <perlin_interpolate@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
call   1030 <perlin_interpolate@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
call   1030 <perlin_interpolate@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perlin_interpolated_noise_2d>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
call   1050 <floor@plt>
mov    %eax,%ebx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x8(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <floor@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,0x10(%rsp)
lea    0x1(%rbx),%r14d
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,0x1c(%rsp)
add    $0x1,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,0x18(%rsp)
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <perlin_smooth_noise_2d@plt>
movss  %xmm0,0x14(%rsp)
movss  0x10(%rsp),%xmm0
movss  0x1c(%rsp),%xmm1
movss  0x8(%rsp),%xmm2
call   1030 <perlin_interpolate@plt>
movss  %xmm0,0x10(%rsp)
movss  0x18(%rsp),%xmm0
movss  0x14(%rsp),%xmm1
movss  0x8(%rsp),%xmm2
call   1030 <perlin_interpolate@plt>
movaps %xmm0,%xmm1
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm2
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <perlin_interpolate@plt>

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

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