#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_3d(float const, float const, float const);
float perlin_octaves_3d(const float x, const float y, const float z,
                        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_3d(x * frequency, y * frequency,
                                          z * frequency) *
             amplitude;
    frequency *= 2;
    amplitude *= p;
  }
  return total;
}


x86 assembly (clang, -O0):
<perlin_octaves_3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xebf(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xeb2(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cvtsi2ssl -0x24(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11d6 <perlin_octaves_3d+0xc6>
movss  -0x4(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  -0x1c(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
mulss  -0x1c(%rbp),%xmm2
call   1030 <perlin_interpolated_noise_3d@plt>
movss  -0x20(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xe55(%rip),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115a <perlin_octaves_3d+0x4a>
movss  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

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

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

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