#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 raw_noise_3d(float const, float const, float const);
float octave_noise_3d(const float octaves, const float persistence,
                      const float scale, const float x, const float y,
                      const float z) {
  float total = 0;
  float frequency = scale;
  float amplitude = 1;
  float maxAmplitude = 0;
  for (int i = 0; i < octaves; i++) {
    total +=
        raw_noise_3d(x * frequency, y * frequency, z * frequency) * amplitude;
    frequency *= 2;
    maxAmplitude += amplitude;
    amplitude *= persistence;
  }
  return total / maxAmplitude;
}


x86 assembly (clang, -O0):
<octave_noise_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)
movss  %xmm5,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xeb0(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cvtsi2ssl -0x2c(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11ef <octave_noise_3d+0xdf>
movss  -0x10(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
mulss  -0x20(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
mulss  -0x20(%rbp),%xmm2
call   1030 <raw_noise_3d@plt>
movss  -0x24(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xe4b(%rip),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
addss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1164 <octave_noise_3d+0x54>
movss  -0x1c(%rbp),%xmm0
divss  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octave_noise_3d>:
push   %rbx
sub    $0x30,%rsp
xorps  %xmm9,%xmm9
ucomiss %xmm9,%xmm0
jbe    11ff <octave_noise_3d+0xef>
movss  0xed9(%rip),%xmm6
mov    $0x1,%ebx
xorps  %xmm8,%xmm8
movss  %xmm5,0x20(%rsp)
movss  %xmm4,0x1c(%rsp)
movss  %xmm3,0x18(%rsp)
movss  %xmm1,0x14(%rsp)
movss  %xmm0,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm6,0x24(%rsp)
movss  %xmm8,0x28(%rsp)
movss  %xmm9,0x2c(%rsp)
movss  %xmm2,0xc(%rsp)
movaps %xmm2,%xmm0
mulss  %xmm3,%xmm0
movaps %xmm2,%xmm1
mulss  %xmm4,%xmm1
movss  0xc(%rsp),%xmm2
mulss  %xmm5,%xmm2
call   1030 <raw_noise_3d@plt>
movss  0x24(%rsp),%xmm6
movss  0x28(%rsp),%xmm8
movss  0x14(%rsp),%xmm1
movss  0x2c(%rsp),%xmm9
movss  0xc(%rsp),%xmm2
movss  0x18(%rsp),%xmm3
movss  0x1c(%rsp),%xmm4
movss  0x20(%rsp),%xmm5
mulss  %xmm6,%xmm0
addss  %xmm0,%xmm8
addss  %xmm2,%xmm2
addss  %xmm6,%xmm9
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  %xmm1,%xmm6
add    $0x1,%ebx
movss  0x10(%rsp),%xmm7
ucomiss %xmm0,%xmm7
ja     1160 <octave_noise_3d+0x50>
divss  %xmm9,%xmm8
jmp    1208 <octave_noise_3d+0xf8>
movss  0xdf8(%rip),%xmm8
movaps %xmm8,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

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