#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 InterpolateNoise(double, double);
double pow(double, int);
double PerlinNoise_2D(double x, double y) {
  double total = 0, p, frequency, amplitude;
  int n, i;
  p = 3;
  n = 3 - 1;
  for (i = 0; i < n; i++) {
    frequency = pow(2, i);
    amplitude = pow(p, i);
    total = total + InterpolateNoise(x * frequency, y * frequency) * amplitude;
  }
  return total;
}


x86 assembly (clang, -O0):
<PerlinNoise_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x2,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11d0 <PerlinNoise_2D+0xb0>
mov    -0x38(%rbp),%edi
movsd  0xe9c(%rip),%xmm0
call   1040 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x38(%rbp),%edi
call   1040 <pow@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
call   1030 <InterpolateNoise@plt>
movsd  -0x40(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1155 <PerlinNoise_2D+0x35>
movsd  -0x18(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PerlinNoise_2D>:
sub    $0x28,%rsp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  0xec8(%rip),%xmm0
xor    %edi,%edi
call   1040 <pow@plt>
movsd  %xmm0,(%rsp)
movsd  0xebc(%rip),%xmm0
xor    %edi,%edi
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm1
call   1030 <InterpolateNoise@plt>
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe71(%rip),%xmm0
mov    $0x1,%edi
call   1040 <pow@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0xe61(%rip),%xmm0
mov    $0x1,%edi
call   1040 <pow@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  0x18(%rsp),%xmm1
call   1030 <InterpolateNoise@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @PerlinNoise_2D(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store double %0, double* %3
store double %1, double* %4
store double 0.000000e+00, double* %5
store double 3.000000e+00, double* %6
store i32 2, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %31, %2
%12 = load i32, i32* %10
%13 = load i32, i32* %9
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i32, i32* %10
%17 = call double @pow(double 2.000000e+00, i32 %16)
store double %17, double* %7
%18 = load double, double* %6
%19 = load i32, i32* %10
%20 = call double @pow(double %18, i32 %19)
store double %20, double* %8
%21 = load double, double* %5
%22 = load double, double* %3
%23 = load double, double* %7
%24 = fmul double %22, %23
%25 = load double, double* %4
%26 = load double, double* %7
%27 = fmul double %25, %26
%28 = call double @InterpolateNoise(double %24, double %27)
%29 = load double, double* %8
%30 = call double @llvm.fmuladd.f64(double %28, double %29, double %21)
store double %30, double* %5
br label %31
31: ; preds = %15
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %11
34: ; preds = %11
%35 = load double, double* %5
ret double %35
}

LLVM IR (-O2):
define double @PerlinNoise_2D(double %0, double %1) {
%3 = tail call double @pow(double 2.000000e+00, i32 0)
%4 = tail call double @pow(double 3.000000e+00, i32 0)
%5 = fmul double %3, %0
%6 = fmul double %3, %1
%7 = tail call double @InterpolateNoise(double %5, double %6)
%8 = tail call double @llvm.fmuladd.f64(double %7, double %4, double 0.000000e+00)
%9 = tail call double @pow(double 2.000000e+00, i32 1)
%10 = tail call double @pow(double 3.000000e+00, i32 1)
%11 = fmul double %9, %0
%12 = fmul double %9, %1
%13 = tail call double @InterpolateNoise(double %11, double %12)
%14 = tail call double @llvm.fmuladd.f64(double %13, double %10, double %8)
ret double %14
}