#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 perlin_interpolated_noise_2d(float const, float const);
float perlin_octaves_2d(const float x, const float y, const float p,
                        const float n) {
  float total = 0.;
  float frequency = 1., amplitude = 1.;
  int i;
  for (i = 0; i < n; ++i) {
    total +=
        perlin_interpolated_noise_2d(x * frequency, y * frequency) * amplitude;
    frequency *= 2;
    amplitude *= p;
  }
  return total;
}


x86 assembly (clang, -O0):
<perlin_octaves_2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xec4(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xeb7(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cvtsi2ssl -0x20(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11c7 <perlin_octaves_2d+0xb7>
movss  -0x4(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  -0x18(%rbp),%xmm1
call   1030 <perlin_interpolated_noise_2d@plt>
movss  -0x1c(%rbp),%xmm2
movss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe64(%rip),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1155 <perlin_octaves_2d+0x45>
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perlin_octaves_2d>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm5,%xmm5
ucomiss %xmm5,%xmm3
jbe    11ce <perlin_octaves_2d+0xbe>
movaps %xmm1,%xmm4
movaps %xmm0,%xmm1
xorps  %xmm5,%xmm5
movss  0xece(%rip),%xmm6
mov    $0x1,%ebx
movaps %xmm6,%xmm7
movss  %xmm3,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
movss  %xmm4,0x8(%rsp)
movss  %xmm0,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm7,0x14(%rsp)
movss  %xmm6,0x18(%rsp)
movss  %xmm5,0x1c(%rsp)
movaps %xmm7,%xmm0
mulss  %xmm1,%xmm0
movaps %xmm7,%xmm1
mulss  %xmm4,%xmm1
call   1030 <perlin_interpolated_noise_2d@plt>
movss  0x14(%rsp),%xmm7
movss  0x18(%rsp),%xmm6
movss  0x1c(%rsp),%xmm5
movss  0x4(%rsp),%xmm1
movss  0x8(%rsp),%xmm4
movss  0xc(%rsp),%xmm2
movss  0x10(%rsp),%xmm3
mulss  %xmm6,%xmm0
addss  %xmm0,%xmm5
addss  %xmm7,%xmm7
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  %xmm2,%xmm6
add    $0x1,%ebx
ucomiss %xmm0,%xmm3
ja     1160 <perlin_octaves_2d+0x50>
movaps %xmm5,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define float @perlin_octaves_2d(float %0, float %1, float %2, float %3) {
%5 = fcmp ogt float %3, 0.000000e+00
br i1 %5, label %6, label %20
6: ; preds = %4, %6
%7 = phi i32 [ %17, %6 ], [ 0, %4 ]
%8 = phi float [ %16, %6 ], [ 1.000000e+00, %4 ]
%9 = phi float [ %15, %6 ], [ 1.000000e+00, %4 ]
%10 = phi float [ %14, %6 ], [ 0.000000e+00, %4 ]
%11 = fmul float %9, %0
%12 = fmul float %9, %1
%13 = tail call float @perlin_interpolated_noise_2d(float %11, float %12)
%14 = tail call float @llvm.fmuladd.f32(float %13, float %8, float %10)
%15 = fmul float %9, 2.000000e+00
%16 = fmul float %8, %2
%17 = add nuw nsw i32 %7, 1
%18 = sitofp i32 %17 to float
%19 = fcmp olt float %18, %3
br i1 %19, label %6, label %20
20: ; preds = %6, %4
%21 = phi float [ 0.000000e+00, %4 ], [ %14, %6 ]
ret float %21
}