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


x86 assembly (clang, -O0):
<simplex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  %xmm3,-0x14(%rbp)
movss  0xec9(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xebc(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xeaf(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
call   1030 <noise2@plt>
movss  %xmm0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e8 <simplex2+0xd8>
movss  -0x14(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  -0x18(%rbp),%xmm1
call   1030 <noise2@plt>
movss  -0x1c(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1171 <simplex2+0x61>
movss  -0x24(%rbp),%xmm1
divss  -0x20(%rbp),%xmm1
movss  0xe06(%rip),%xmm0
addss  %xmm1,%xmm0
movss  0xdfe(%rip),%xmm1
divss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplex2>:
push   %rbx
sub    $0x20,%rsp
movss  %xmm3,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
mov    %edi,%ebx
movss  %xmm0,0x4(%rsp)
movss  %xmm1,0x8(%rsp)
call   1030 <noise2@plt>
cmp    $0x2,%ebx
jl     11be <simplex2+0xae>
add    $0xffffffff,%ebx
movss  0xeb8(%rip),%xmm1
movaps %xmm1,%xmm2
movaps %xmm1,%xmm3
xchg   %ax,%ax
movss  %xmm0,(%rsp)
mulss  0x10(%rsp),%xmm3
movss  %xmm3,0x14(%rsp)
mulss  0xc(%rsp),%xmm2
movss  %xmm2,0x18(%rsp)
addss  %xmm2,%xmm1
movss  %xmm1,0x1c(%rsp)
movaps %xmm3,%xmm0
mulss  0x4(%rsp),%xmm0
movaps %xmm3,%xmm1
mulss  0x8(%rsp),%xmm1
call   1030 <noise2@plt>
movss  0x14(%rsp),%xmm3
movss  0x18(%rsp),%xmm2
mulss  %xmm2,%xmm0
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
movss  0x1c(%rsp),%xmm1
movss  (%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1150 <simplex2+0x40>
jmp    11c6 <simplex2+0xb6>
movss  0xe3a(%rip),%xmm1
divss  %xmm1,%xmm0
addss  0xe2e(%rip),%xmm0
mulss  0xe2a(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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