#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 InterpolatedNoise_1_SIMD(float, float);
float PerlinNoise_2D_SIMD(float x, float y, float persistence, int octaves) {
  float total, p, frequency, amplitude;
  int i;
  for (i = 0; i < octaves; i++) {
    frequency = 2 * i;
    amplitude = persistence * i;
    total += InterpolatedNoise_1_SIMD(x * frequency, y * frequency) * amplitude;
  }
}


x86 assembly (clang, -O0):
<PerlinNoise_2D_SIMD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119d <PerlinNoise_2D_SIMD+0x8d>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x10(%rbp),%xmm0
cvtsi2ssl -0x28(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mulss  -0x20(%rbp),%xmm1
call   1030 <InterpolatedNoise_1_SIMD@plt>
movss  -0x24(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1131 <PerlinNoise_2D_SIMD+0x21>
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PerlinNoise_2D_SIMD>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    115a <PerlinNoise_2D_SIMD+0x4a>
mov    %edi,%ebx
movaps %xmm1,%xmm2
movaps %xmm0,%xmm3
xor    %ebp,%ebp
movss  %xmm1,0x4(%rsp)
movss  %xmm0,(%rsp)
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2ss %ebp,%xmm1
movaps %xmm1,%xmm0
mulss  %xmm3,%xmm0
mulss  %xmm2,%xmm1
call   1030 <InterpolatedNoise_1_SIMD@plt>
movss  (%rsp),%xmm3
movss  0x4(%rsp),%xmm2
add    $0x2,%ebp
add    $0xffffffff,%ebx
jne    1130 <PerlinNoise_2D_SIMD+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @PerlinNoise_2D_SIMD(float %0, float %1, float %2, i32 %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca i32
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store i32 %3, i32* %9
store i32 0, i32* %14
br label %15
15: ; preds = %37, %4
%16 = load i32, i32* %14
%17 = load i32, i32* %9
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %40
19: ; preds = %15
%20 = load i32, i32* %14
%21 = mul nsw i32 2, %20
%22 = sitofp i32 %21 to float
store float %22, float* %12
%23 = load float, float* %8
%24 = load i32, i32* %14
%25 = sitofp i32 %24 to float
%26 = fmul float %23, %25
store float %26, float* %13
%27 = load float, float* %6
%28 = load float, float* %12
%29 = fmul float %27, %28
%30 = load float, float* %7
%31 = load float, float* %12
%32 = fmul float %30, %31
%33 = call float @InterpolatedNoise_1_SIMD(float %29, float %32)
%34 = load float, float* %13
%35 = load float, float* %10
%36 = call float @llvm.fmuladd.f32(float %33, float %34, float %35)
store float %36, float* %10
br label %37
37: ; preds = %19
%38 = load i32, i32* %14
%39 = add nsw i32 %38, 1
store i32 %39, i32* %14
br label %15
40: ; preds = %15
%41 = load float, float* %5
ret float %41
}

LLVM IR (-O2):
define float @PerlinNoise_2D_SIMD(float %0, float %1, float %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %15
6: ; preds = %4, %6
%7 = phi i32 [ %13, %6 ], [ 0, %4 ]
%8 = shl nuw nsw i32 %7, 1
%9 = sitofp i32 %8 to float
%10 = fmul float %9, %0
%11 = fmul float %9, %1
%12 = tail call float @InterpolatedNoise_1_SIMD(float %10, float %11)
%13 = add nuw nsw i32 %7, 1
%14 = icmp eq i32 %13, %3
br i1 %14, label %15, label %6
15: ; preds = %6, %4
ret float undef
}