#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 */
float InterpolateNoise(float);
float pow(float, int);
float PerlinNoise(float x, float persistence, int octaves) {
  float total = 0.0;
  for (int i = 0; i < octaves - 1; i++) {
    float frequency = pow(2, i);
    float amplitude = pow(persistence, i);
    total = total + InterpolateNoise(x * frequency) * amplitude;
  }
  return total;
}


x86 assembly (clang, -O0):
<PerlinNoise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ba <PerlinNoise+0x9a>
mov    -0x14(%rbp),%edi
movss  0xea0(%rip),%xmm0
call   1040 <pow@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1040 <pow@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
call   1030 <InterpolateNoise@plt>
movss  -0x20(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <PerlinNoise+0x24>
movss  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PerlinNoise>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cmp    $0x2,%edi
jl     11b2 <PerlinNoise+0x92>
mov    %edi,%ebx
add    $0xffffffff,%ebx
xor    %ebp,%ebp
xorps  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm0,0x4(%rsp)
movss  0xea2(%rip),%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
movss  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
movss  %xmm0,0x14(%rsp)
movss  0x10(%rsp),%xmm0
mulss  0x8(%rsp),%xmm0
call   1030 <InterpolateNoise@plt>
mulss  0x14(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x4(%rsp),%xmm0
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1150 <PerlinNoise+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define float @PerlinNoise(float %0, float %1, i32 %2) {
%4 = add i32 %2, -1
%5 = icmp sgt i32 %2, 1
br i1 %5, label %8, label %6
6: ; preds = %8, %3
%7 = phi float [ 0.000000e+00, %3 ], [ %15, %8 ]
ret float %7
8: ; preds = %3, %8
%9 = phi float [ %15, %8 ], [ 0.000000e+00, %3 ]
%10 = phi i32 [ %16, %8 ], [ 0, %3 ]
%11 = tail call float @pow(float 2.000000e+00, i32 %10)
%12 = tail call float @pow(float %1, i32 %10)
%13 = fmul float %11, %0
%14 = tail call float @InterpolateNoise(float %13)
%15 = tail call float @llvm.fmuladd.f32(float %14, float %12, float %9)
%16 = add nuw nsw i32 %10, 1
%17 = icmp eq i32 %16, %4
br i1 %17, label %6, label %8
}