#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_noise3(struct osn_context *, double, double, double);
double open_simplex_noise3_oct(struct osn_context *ctx, double x, double y,
                               double z, 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_noise3(ctx, x * freq, y * freq, z * freq) * amp;
    max_amp += amp;
    amp *= pers;
    freq *= 2.0f;
  }
  noise /= max_amp;
  return noise;
}


x86 assembly (clang, -O0):
<open_simplex_noise3_oct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
movss  %xmm3,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  0xebd(%rip),%xmm0
movss  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  0xea8(%rip),%xmm0
movss  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1204 <open_simplex_noise3_oct+0xf4>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movss  -0x38(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movss  -0x38(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x20(%rbp),%xmm2
movss  -0x38(%rbp),%xmm3
cvtss2sd %xmm3,%xmm3
mulsd  %xmm3,%xmm2
call   1030 <open_simplex_noise3@plt>
movss  -0x30(%rbp),%xmm2
movss  -0x34(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm0
addss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x28(%rbp),%xmm0
mulss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  0xe18(%rip),%xmm0
mulss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1164 <open_simplex_noise3_oct+0x54>
movss  -0x2c(%rbp),%xmm1
movss  -0x34(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_simplex_noise3_oct>:
push   %r14
push   %rbx
sub    $0x38,%rsp
test   %esi,%esi
jle    1202 <open_simplex_noise3_oct+0xf2>
mov    %esi,%ebx
movapd %xmm2,%xmm4
movapd %xmm1,%xmm5
movapd %xmm0,%xmm1
mov    %rdi,%r14
xorpd  %xmm0,%xmm0
movss  0xecc(%rip),%xmm2
movaps %xmm2,%xmm7
xorps  %xmm6,%xmm6
movss  %xmm3,0x14(%rsp)
movsd  %xmm4,0x30(%rsp)
movsd  %xmm5,0x28(%rsp)
movsd  %xmm1,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movss  %xmm7,0x18(%rsp)
movss  %xmm6,0x1c(%rsp)
movss  %xmm2,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
movaps %xmm2,%xmm0
mulsd  %xmm1,%xmm0
movaps %xmm2,%xmm1
mulsd  %xmm5,%xmm1
mulsd  %xmm4,%xmm2
mov    %r14,%rdi
call   1030 <open_simplex_noise3@plt>
movss  0x18(%rsp),%xmm7
movss  0x1c(%rsp),%xmm6
movsd  0x20(%rsp),%xmm1
movsd  0x28(%rsp),%xmm5
movsd  0x30(%rsp),%xmm4
movss  0x14(%rsp),%xmm3
mulss  %xmm7,%xmm0
movss  0xc(%rsp),%xmm2
addss  %xmm0,%xmm2
movss  %xmm2,0xc(%rsp)
movss  0x10(%rsp),%xmm2
movss  0xc(%rsp),%xmm0
addss  %xmm7,%xmm6
mulss  %xmm3,%xmm7
addss  %xmm2,%xmm2
add    $0xffffffff,%ebx
jne    1160 <open_simplex_noise3_oct+0x50>
divss  %xmm6,%xmm0
cvtss2sd %xmm0,%xmm0
jmp    120a <open_simplex_noise3_oct+0xfa>
movsd  0xdf6(%rip),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

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

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