#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 */
scalar_t__ noise(float, float, float);
float pow(int, int);
float simplex_noise(int octaves, float x, float y, float z) {
  float value = 0.0;
  int i;
  for (i = 0; i < octaves; ++i)
    value += noise(x * pow(2, i), y * pow(2, i), z * pow(2, i));
  return value;
}


x86 assembly (clang, -O0):
<simplex_noise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f4 <simplex_noise+0xd4>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x18(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x18(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
movss  -0x24(%rbp),%xmm2
movss  -0x20(%rbp),%xmm1
movaps %xmm0,%xmm3
movss  -0x1c(%rbp),%xmm0
mulss  %xmm3,%xmm2
call   1030 <noise@plt>
cvtsi2ss %rax,%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <simplex_noise+0x29>
movss  -0x14(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplex_noise>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11c6 <simplex_noise+0xa6>
mov    %edi,%ebx
xorps  %xmm3,%xmm3
xor    %ebp,%ebp
movss  %xmm2,0x8(%rsp)
movss  %xmm1,0x4(%rsp)
movss  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
movss  %xmm3,0x14(%rsp)
mov    $0x2,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
mulss  (%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
mov    $0x2,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
mulss  0x4(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
mov    $0x2,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movaps %xmm0,%xmm2
mulss  0x8(%rsp),%xmm2
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1030 <noise@plt>
movss  0x14(%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm3
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1150 <simplex_noise+0x30>
jmp    11c9 <simplex_noise+0xa9>
xorps  %xmm3,%xmm3
movaps %xmm3,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @simplex_noise(i32 %0, float %1, float %2, float %3) {
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
store i32 %0, i32* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
store float 0.000000e+00, float* %9
store i32 0, i32* %10
br label %11
11: ; preds = %32, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = load float, float* %6
%17 = load i32, i32* %10
%18 = call float @pow(i32 2, i32 %17)
%19 = fmul float %16, %18
%20 = load float, float* %7
%21 = load i32, i32* %10
%22 = call float @pow(i32 2, i32 %21)
%23 = fmul float %20, %22
%24 = load float, float* %8
%25 = load i32, i32* %10
%26 = call float @pow(i32 2, i32 %25)
%27 = fmul float %24, %26
%28 = call i64 @noise(float %19, float %23, float %27)
%29 = sitofp i64 %28 to float
%30 = load float, float* %9
%31 = fadd float %30, %29
store float %31, float* %9
br label %32
32: ; preds = %15
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
store i32 %34, i32* %10
br label %11
35: ; preds = %11
%36 = load float, float* %9
ret float %36
}

LLVM IR (-O2):
define float @simplex_noise(i32 %0, float %1, float %2, float %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %20
6: ; preds = %4, %6
%7 = phi i32 [ %18, %6 ], [ 0, %4 ]
%8 = phi float [ %17, %6 ], [ 0.000000e+00, %4 ]
%9 = tail call float @pow(i32 2, i32 %7)
%10 = fmul float %9, %1
%11 = tail call float @pow(i32 2, i32 %7)
%12 = fmul float %11, %2
%13 = tail call float @pow(i32 2, i32 %7)
%14 = fmul float %13, %3
%15 = tail call i64 @noise(float %10, float %12, float %14)
%16 = sitofp i64 %15 to float
%17 = fadd float %8, %16
%18 = add nuw nsw i32 %7, 1
%19 = icmp eq i32 %18, %0
br i1 %19, label %20, label %6
20: ; preds = %6, %4
%21 = phi float [ 0.000000e+00, %4 ], [ %17, %6 ]
ret float %21
}