#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 noise4(float, float, float, float);
float fbm_noise4(float x, float y, float z, float w, int octaves,
                 float persistence, float lacunarity) {
  float freq = 1.0f;
  float amp = 1.0f;
  float max = 1.0f;
  float total = noise4(x, y, z, w);
  int i;
  for (i = 1; i < octaves; ++i) {
    freq *= lacunarity;
    amp *= persistence;
    max += amp;
    total += noise4(x * freq, y * freq, z * freq, w * freq) * amp;
  }
  return total / max;
}


x86 assembly (clang, -O0):
<fbm_noise4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movss  %xmm4,-0x18(%rbp)
movss  %xmm5,-0x1c(%rbp)
movss  0xebf(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xeb2(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xea5(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm3
call   1030 <noise4@plt>
movss  %xmm0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1210 <fbm_noise4+0x100>
movss  -0x1c(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
addss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  -0x20(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
mulss  -0x20(%rbp),%xmm2
movss  -0x10(%rbp),%xmm3
mulss  -0x20(%rbp),%xmm3
call   1030 <noise4@plt>
movss  -0x24(%rbp),%xmm2
movss  -0x2c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1185 <fbm_noise4+0x75>
movss  -0x2c(%rbp),%xmm0
divss  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fbm_noise4>:
push   %rbx
sub    $0x30,%rsp
movss  %xmm5,0x24(%rsp)
movss  %xmm4,0x20(%rsp)
mov    %edi,%ebx
movss  %xmm0,0x10(%rsp)
movss  %xmm1,0x14(%rsp)
movss  %xmm2,0x18(%rsp)
movss  %xmm3,0x1c(%rsp)
call   1030 <noise4@plt>
cmp    $0x2,%ebx
jl     11eb <fbm_noise4+0xdb>
add    $0xffffffff,%ebx
movss  0xeac(%rip),%xmm1
movaps %xmm1,%xmm2
movaps %xmm1,%xmm3
nopw   0x0(%rax,%rax,1)
movss  %xmm0,0x8(%rsp)
mulss  0x24(%rsp),%xmm3
movss  %xmm3,0xc(%rsp)
mulss  0x20(%rsp),%xmm2
movss  %xmm2,0x28(%rsp)
addss  %xmm2,%xmm1
movss  %xmm1,0x2c(%rsp)
movaps %xmm3,%xmm0
mulss  0x10(%rsp),%xmm0
movaps %xmm3,%xmm1
mulss  0x14(%rsp),%xmm1
movaps %xmm3,%xmm2
mulss  0x18(%rsp),%xmm2
movss  0xc(%rsp),%xmm3
mulss  0x1c(%rsp),%xmm3
call   1030 <noise4@plt>
movss  0xc(%rsp),%xmm3
movss  0x28(%rsp),%xmm2
mulss  %xmm2,%xmm0
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x2c(%rsp),%xmm1
movss  0x8(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1160 <fbm_noise4+0x50>
jmp    11f3 <fbm_noise4+0xe3>
movss  0xe0d(%rip),%xmm1
divss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

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