#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 fabs(float);
float kknoise3d(float *, float, float, float);
float kkTURB_Turbulence3d(float *table, float x, float y, float z,
                          long octaves) {
  float t, s;
  t = 0.0;
  s = 1.0;
  while (octaves--) {
    s *= 0.5;
    t += kknoise3d(table, x, y, z) * s;
    x *= 2.0;
    y *= 2.0;
    z *= 2.0;
  }
  if (t > 1.0)
    t = 1.0;
  if (t < -1.0)
    t = -1.0;
  t = fabs(t);
  return (t);
}


x86 assembly (clang, -O0):
<kkTURB_Turbulence3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xeb1(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     1219 <kkTURB_Turbulence3d+0xf9>
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea2(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
call   1040 <kknoise3d@plt>
movss  -0x28(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe4d(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe11(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1154 <kkTURB_Turbulence3d+0x34>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdde(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1241 <kkTURB_Turbulence3d+0x121>
movss  0xdc4(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdbe(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1269 <kkTURB_Turbulence3d+0x149>
movss  0xda0(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <fabs@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kkTURB_Turbulence3d>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
je     11c7 <kkTURB_Turbulence3d+0xb7>
mov    %rsi,%rbx
movaps %xmm0,%xmm3
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movss  0xecc(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm4,0x10(%rsp)
movss  %xmm3,0x14(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0x4(%rsp)
movss  %xmm2,0xc(%rsp)
mov    %r14,%rdi
movaps %xmm3,%xmm0
movss  0x8(%rsp),%xmm1
movss  0xc(%rsp),%xmm2
call   1030 <kknoise3d@plt>
movss  0x10(%rsp),%xmm4
movss  0x14(%rsp),%xmm3
movss  0xc(%rsp),%xmm2
mulss  0xe75(%rip),%xmm4
mulss  %xmm4,%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x8(%rsp),%xmm1
movss  0x4(%rsp),%xmm0
addss  %xmm3,%xmm3
addss  %xmm1,%xmm1
addss  %xmm2,%xmm2
add    $0xffffffffffffffff,%rbx
jne    1140 <kkTURB_Turbulence3d+0x30>
jmp    11ca <kkTURB_Turbulence3d+0xba>
xorps  %xmm0,%xmm0
movss  0xe2e(%rip),%xmm1
minss  %xmm0,%xmm1
movss  0xe2a(%rip),%xmm0
maxss  %xmm1,%xmm0
andps  0xe27(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define float @kkTURB_Turbulence3d(float* %0, float %1, float %2, float %3, i64 %4) {
%6 = icmp eq i64 %4, 0
br i1 %6, label %22, label %7
7: ; preds = %5, %7
%8 = phi float [ %15, %7 ], [ 1.000000e+00, %5 ]
%9 = phi float [ %17, %7 ], [ 0.000000e+00, %5 ]
%10 = phi i64 [ %14, %7 ], [ %4, %5 ]
%11 = phi float [ %20, %7 ], [ %3, %5 ]
%12 = phi float [ %19, %7 ], [ %2, %5 ]
%13 = phi float [ %18, %7 ], [ %1, %5 ]
%14 = add nsw i64 %10, -1
%15 = fmul float %8, 5.000000e-01
%16 = tail call float @kknoise3d(float* %0, float %13, float %12, float %11)
%17 = tail call float @llvm.fmuladd.f32(float %16, float %15, float %9)
%18 = fmul float %13, 2.000000e+00
%19 = fmul float %12, 2.000000e+00
%20 = fmul float %11, 2.000000e+00
%21 = icmp eq i64 %14, 0
br i1 %21, label %22, label %7
22: ; preds = %7, %5
%23 = phi float [ 0.000000e+00, %5 ], [ %17, %7 ]
%24 = fcmp ogt float %23, 1.000000e+00
%25 = select i1 %24, float 1.000000e+00, float %23
%26 = fcmp olt float %25, -1.000000e+00
%27 = select i1 %26, float -1.000000e+00, float %25
%28 = tail call float @llvm.fabs.f32(float %27)
ret float %28
}