#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 perlin_noise_2d(int const, int const);
float perlin_smooth_noise_2d(const int x, const int y) {
  const float corners =
      (perlin_noise_2d(x - 1, y - 1) + perlin_noise_2d(x + 1, y - 1) +
       perlin_noise_2d(x - 1, y + 1) + perlin_noise_2d(x + 1, y + 1)) /
      4;
  const float sides = (perlin_noise_2d(x - 1, y) + perlin_noise_2d(x + 1, y) +
                       perlin_noise_2d(x, y - 1) + perlin_noise_2d(x, y + 1)) /
                      4;
  const float center = perlin_noise_2d(x, y) / 4;
  return corners + sides + center;
}


x86 assembly (clang, -O0):
<perlin_smooth_noise_2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <perlin_noise_2d@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perlin_smooth_noise_2d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,%ebx
mov    %rbx,0x10(%rsp)
lea    -0x1(%rbx),%r12d
lea    -0x1(%rsi),%ebp
mov    %ebp,(%rsp)
mov    %r12d,%edi
mov    %ebp,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%r13d
lea    0x1(%rbx),%r15d
mov    %r15d,%edi
mov    %ebp,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%r14d
add    %r13d,%r14d
mov    0x8(%rsp),%rbp
lea    0x1(%rbp),%r13d
mov    %r12d,%edi
mov    %r13d,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ebx
add    %r14d,%ebx
mov    %r15d,%edi
mov    %r13d,%esi
call   1030 <perlin_noise_2d@plt>
mov    %ebx,%ecx
add    %eax,%ecx
lea    0x3(%rax,%rbx,1),%eax
cmovns %ecx,%eax
sar    $0x2,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x4(%rsp)
mov    %r12d,%edi
mov    %rbp,%r14
mov    %r14d,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %r14d,%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%r15d
add    %ebx,%r15d
mov    0x10(%rsp),%rbp
mov    %ebp,%edi
mov    (%rsp),%esi
call   1030 <perlin_noise_2d@plt>
mov    %eax,%ebx
add    %r15d,%ebx
mov    %ebp,%edi
mov    %r13d,%esi
call   1030 <perlin_noise_2d@plt>
mov    %ebx,%ecx
add    %eax,%ecx
lea    0x3(%rax,%rbx,1),%eax
cmovns %ecx,%eax
sar    $0x2,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0x4(%rsp),%xmm0
movss  %xmm0,(%rsp)
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <perlin_noise_2d@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
addss  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define float @perlin_smooth_noise_2d(i32 %0, i32 %1) {
%3 = add nsw i32 %0, -1
%4 = add nsw i32 %1, -1
%5 = tail call i32 @perlin_noise_2d(i32 %3, i32 %4)
%6 = add nsw i32 %0, 1
%7 = tail call i32 @perlin_noise_2d(i32 %6, i32 %4)
%8 = add nsw i32 %7, %5
%9 = add nsw i32 %1, 1
%10 = tail call i32 @perlin_noise_2d(i32 %3, i32 %9)
%11 = add nsw i32 %8, %10
%12 = tail call i32 @perlin_noise_2d(i32 %6, i32 %9)
%13 = add nsw i32 %11, %12
%14 = sdiv i32 %13, 4
%15 = sitofp i32 %14 to float
%16 = tail call i32 @perlin_noise_2d(i32 %3, i32 %1)
%17 = tail call i32 @perlin_noise_2d(i32 %6, i32 %1)
%18 = add nsw i32 %17, %16
%19 = tail call i32 @perlin_noise_2d(i32 %0, i32 %4)
%20 = add nsw i32 %18, %19
%21 = tail call i32 @perlin_noise_2d(i32 %0, i32 %9)
%22 = add nsw i32 %20, %21
%23 = sdiv i32 %22, 4
%24 = sitofp i32 %23 to float
%25 = tail call i32 @perlin_noise_2d(i32 %0, i32 %1)
%26 = sdiv i32 %25, 4
%27 = sitofp i32 %26 to float
%28 = fadd float %15, %24
%29 = fadd float %28, %27
ret float %29
}