#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 raw_noise_2d(float const, float const);
float octave_noise_2d(const float octaves, const float persistence,
                      const float scale, const float x, const float y) {
  float total = 0;
  float frequency = scale;
  float amplitude = 1;
  float maxAmplitude = 0;
  for (int i = 0; i < octaves; i++) {
    total += raw_noise_2d(x * frequency, y * frequency) * amplitude;
    frequency *= 2;
    maxAmplitude += amplitude;
    amplitude *= persistence;
  }
  return total / maxAmplitude;
}


x86 assembly (clang, -O0):
<octave_noise_2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xeb5(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cvtsi2ssl -0x28(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11e0 <octave_noise_2d+0xd0>
movss  -0x10(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
mulss  -0x1c(%rbp),%xmm1
call   1030 <raw_noise_2d@plt>
movss  -0x20(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xe5a(%rip),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x20(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115f <octave_noise_2d+0x4f>
movss  -0x18(%rbp),%xmm0
divss  -0x24(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octave_noise_2d>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm5,%xmm5
ucomiss %xmm5,%xmm0
jbe    11d7 <octave_noise_2d+0xc7>
movss  0xedb(%rip),%xmm7
mov    $0x1,%ebx
xorps  %xmm8,%xmm8
movss  %xmm4,0xc(%rsp)
movss  %xmm3,0x8(%rsp)
movss  %xmm1,0x4(%rsp)
movss  %xmm0,(%rsp)
nopl   0x0(%rax)
movss  %xmm7,0x10(%rsp)
movss  %xmm8,0x14(%rsp)
movss  %xmm5,0x18(%rsp)
movss  %xmm2,0x1c(%rsp)
movaps %xmm2,%xmm0
mulss  %xmm3,%xmm0
movaps %xmm2,%xmm1
mulss  %xmm4,%xmm1
call   1030 <raw_noise_2d@plt>
movss  0x10(%rsp),%xmm7
movss  0x14(%rsp),%xmm8
movss  0x4(%rsp),%xmm1
movss  0x18(%rsp),%xmm5
movss  0x1c(%rsp),%xmm2
movss  0x8(%rsp),%xmm3
movss  0xc(%rsp),%xmm4
mulss  %xmm7,%xmm0
addss  %xmm0,%xmm8
addss  %xmm2,%xmm2
addss  %xmm7,%xmm5
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  %xmm1,%xmm7
add    $0x1,%ebx
movss  (%rsp),%xmm6
ucomiss %xmm0,%xmm6
ja     1150 <octave_noise_2d+0x40>
divss  %xmm5,%xmm8
jmp    11e0 <octave_noise_2d+0xd0>
movss  0xe20(%rip),%xmm8
movaps %xmm8,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define float @octave_noise_2d(float %0, float %1, float %2, float %3, float %4) {
%6 = fcmp ogt float %0, 0.000000e+00
br i1 %6, label %11, label %9
7: ; preds = %11
%8 = fdiv float %20, %22
br label %9
9: ; preds = %7, %5
%10 = phi float [ %8, %7 ], [ 0x7FF8000000000000, %5 ]
ret float %10
11: ; preds = %5, %11
%12 = phi i32 [ %24, %11 ], [ 0, %5 ]
%13 = phi float [ %22, %11 ], [ 0.000000e+00, %5 ]
%14 = phi float [ %23, %11 ], [ 1.000000e+00, %5 ]
%15 = phi float [ %21, %11 ], [ %2, %5 ]
%16 = phi float [ %20, %11 ], [ 0.000000e+00, %5 ]
%17 = fmul float %15, %3
%18 = fmul float %15, %4
%19 = tail call float @raw_noise_2d(float %17, float %18)
%20 = tail call float @llvm.fmuladd.f32(float %19, float %14, float %16)
%21 = fmul float %15, 2.000000e+00
%22 = fadd float %14, %13
%23 = fmul float %14, %1
%24 = add nuw nsw i32 %12, 1
%25 = sitofp i32 %24 to float
%26 = fcmp olt float %25, %0
br i1 %26, label %11, label %7
}