#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 */
struct osn_context {
  int dummy;
};

/* Variables and functions */
float open_simplex_noise2(struct osn_context *, double, double);
double open_simplex_noise2_oct(struct osn_context *ctx, double x, double y,
                               int octaves, float pers) {
  float max_amp = 0;
  float amp = 1;
  float noise = 0;
  float freq = 1.0f;
  for (int i = 0; i < octaves; i++) {
    noise += open_simplex_noise2(ctx, x * freq, y * freq) * amp;
    max_amp += amp;
    amp *= pers;
    freq *= 2.0f;
  }
  noise /= max_amp;
  return noise;
}


x86 assembly (clang, -O0):
<open_simplex_noise2_oct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movss  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xec2(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  0xead(%rip),%xmm0
movss  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ed <open_simplex_noise2_oct+0xdd>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movss  -0x30(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm1
call   1030 <open_simplex_noise2@plt>
movss  -0x28(%rbp),%xmm2
movss  -0x2c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x28(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  0xe2f(%rip),%xmm0
mulss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115f <open_simplex_noise2_oct+0x4f>
movss  -0x24(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_simplex_noise2_oct>:
push   %r14
push   %rbx
sub    $0x28,%rsp
test   %esi,%esi
jle    11e5 <open_simplex_noise2_oct+0xd5>
mov    %esi,%ebx
movapd %xmm1,%xmm3
movapd %xmm0,%xmm4
mov    %rdi,%r14
xorpd  %xmm0,%xmm0
movss  0xed0(%rip),%xmm1
movaps %xmm1,%xmm6
xorps  %xmm5,%xmm5
movss  %xmm2,0xc(%rsp)
movsd  %xmm3,0x20(%rsp)
movsd  %xmm4,0x18(%rsp)
movss  %xmm6,0x10(%rsp)
movss  %xmm5,0x14(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0x4(%rsp)
movss  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movaps %xmm1,%xmm0
mulsd  %xmm4,%xmm0
mulsd  %xmm3,%xmm1
mov    %r14,%rdi
call   1030 <open_simplex_noise2@plt>
movss  0x10(%rsp),%xmm6
movss  0x14(%rsp),%xmm5
movsd  0x18(%rsp),%xmm4
movsd  0x20(%rsp),%xmm3
movss  0xc(%rsp),%xmm2
mulss  %xmm6,%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x8(%rsp),%xmm1
movss  0x4(%rsp),%xmm0
addss  %xmm6,%xmm5
mulss  %xmm2,%xmm6
addss  %xmm1,%xmm1
add    $0xffffffff,%ebx
jne    1150 <open_simplex_noise2_oct+0x40>
divss  %xmm5,%xmm0
cvtss2sd %xmm0,%xmm0
jmp    11ed <open_simplex_noise2_oct+0xdd>
movsd  0xe13(%rip),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

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