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


x86 assembly (clang, -O0):
<simplex3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
movss  %xmm3,-0x14(%rbp)
movss  %xmm4,-0x18(%rbp)
movss  0xec4(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xeb7(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xeaa(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
call   1030 <noise3@plt>
movss  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fc <simplex3+0xec>
movss  -0x18(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
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 <noise3@plt>
movss  -0x20(%rbp),%xmm2
movss  -0x28(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117b <simplex3+0x6b>
movss  -0x28(%rbp),%xmm1
divss  -0x24(%rbp),%xmm1
movss  0xdf2(%rip),%xmm0
addss  %xmm1,%xmm0
movss  0xdea(%rip),%xmm1
divss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplex3>:
push   %rbx
sub    $0x30,%rsp
movss  %xmm4,0x20(%rsp)
movss  %xmm3,0x1c(%rsp)
mov    %edi,%ebx
movss  %xmm0,0x10(%rsp)
movss  %xmm1,0x14(%rsp)
movss  %xmm2,0x18(%rsp)
call   1030 <noise3@plt>
cmp    $0x2,%ebx
jl     11db <simplex3+0xcb>
add    $0xffffffff,%ebx
movss  0xeb2(%rip),%xmm1
movaps %xmm1,%xmm2
movaps %xmm1,%xmm3
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm0,0xc(%rsp)
mulss  0x20(%rsp),%xmm3
movss  %xmm3,0x24(%rsp)
mulss  0x1c(%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
call   1030 <noise3@plt>
movss  0x24(%rsp),%xmm3
movss  0x28(%rsp),%xmm2
mulss  %xmm2,%xmm0
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
movss  0x2c(%rsp),%xmm1
movss  0xc(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1160 <simplex3+0x50>
jmp    11e3 <simplex3+0xd3>
movss  0xe1d(%rip),%xmm1
divss  %xmm1,%xmm0
addss  0xe11(%rip),%xmm0
mulss  0xe0d(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

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