#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 noise3d(float, float, float);
float TURB_Turbulence3d(float x, float y, float z, long octaves, long mode) {
  float t, s;
  t = 0.0;
  s = 1.0;
  while (octaves--) {
    s *= 0.5;
    if (mode & 1)
      t += fabs(noise3d(x, y, z) * s);
    else
      t += noise3d(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;
  if (mode & 2)
    t = .5 + .5 * t;
  else
    t = fabs(t);
  return (t);
}


x86 assembly (clang, -O0):
<TURB_Turbulence3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xeb1(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     1254 <TURB_Turbulence3d+0x134>
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe9a(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11ca <TURB_Turbulence3d+0xaa>
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
call   1040 <noise3d@plt>
mulss  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    11f5 <TURB_Turbulence3d+0xd5>
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
call   1040 <noise3d@plt>
movss  -0x28(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe1a(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdfc(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdde(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1154 <TURB_Turbulence3d+0x34>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xda3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    127c <TURB_Turbulence3d+0x15c>
movss  0xd89(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd83(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12a4 <TURB_Turbulence3d+0x184>
movss  0xd65(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     12dd <TURB_Turbulence3d+0x1bd>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd51(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    12ec <TURB_Turbulence3d+0x1cc>
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):
<TURB_Turbulence3d>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
test   %rdi,%rdi
je     11b4 <TURB_Turbulence3d+0xa4>
mov    %rdi,%rbx
xorps  %xmm3,%xmm3
movss  0xecf(%rip),%xmm4
movss  %xmm4,(%rsp)
jmp    116f <TURB_Turbulence3d+0x5f>
nopl   0x0(%rax,%rax,1)
movaps 0x10(%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm3
movss  0x4(%rsp),%xmm0
addss  %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
addss  %xmm1,%xmm1
movss  0xc(%rsp),%xmm2
addss  %xmm2,%xmm2
test   %rbx,%rbx
je     11b7 <TURB_Turbulence3d+0xa7>
movaps %xmm3,0x10(%rsp)
add    $0xffffffffffffffff,%rbx
movss  %xmm0,0x4(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm2,0xc(%rsp)
call   1030 <noise3d@plt>
movss  (%rsp),%xmm1
mulss  0xe68(%rip),%xmm1
test   $0x1,%r14b
movss  %xmm1,(%rsp)
mulss  %xmm1,%xmm0
je     1140 <TURB_Turbulence3d+0x30>
andps  0xe5e(%rip),%xmm0
jmp    1140 <TURB_Turbulence3d+0x30>
xorps  %xmm3,%xmm3
movss  0xe41(%rip),%xmm1
minss  %xmm3,%xmm1
movss  0xe3d(%rip),%xmm0
maxss  %xmm1,%xmm0
test   $0x2,%r14b
jne    11de <TURB_Turbulence3d+0xce>
andps  0xe34(%rip),%xmm0
jmp    11f6 <TURB_Turbulence3d+0xe6>
cvtss2sd %xmm0,%xmm0
movsd  0xe36(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define float @TURB_Turbulence3d(float %0, float %1, float %2, i64 %3, i64 %4) {
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i64
%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 i64 %3, i64* %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 = %43, %5
%14 = load i64, i64* %9
%15 = add nsw i64 %14, -1
store i64 %15, i64* %9
%16 = icmp ne i64 %14, 0
br i1 %16, label %17, label %56
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 i64, i64* %10
%23 = and i64 %22, 1
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %17
%26 = load float, float* %6
%27 = load float, float* %7
%28 = load float, float* %8
%29 = call float @noise3d(float %26, float %27, float %28)
%30 = load float, float* %12
%31 = fmul float %29, %30
%32 = call float @fabs(float %31)
%33 = load float, float* %11
%34 = fadd float %33, %32
store float %34, float* %11
br label %43
35: ; preds = %17
%36 = load float, float* %6
%37 = load float, float* %7
%38 = load float, float* %8
%39 = call float @noise3d(float %36, float %37, float %38)
%40 = load float, float* %12
%41 = load float, float* %11
%42 = call float @llvm.fmuladd.f32(float %39, float %40, float %41)
store float %42, float* %11
br label %43
43: ; preds = %35, %25
%44 = load float, float* %6
%45 = fpext float %44 to double
%46 = fmul double %45, 2.000000e+00
%47 = fptrunc double %46 to float
store float %47, float* %6
%48 = load float, float* %7
%49 = fpext float %48 to double
%50 = fmul double %49, 2.000000e+00
%51 = fptrunc double %50 to float
store float %51, float* %7
%52 = load float, float* %8
%53 = fpext float %52 to double
%54 = fmul double %53, 2.000000e+00
%55 = fptrunc double %54 to float
store float %55, float* %8
br label %13
56: ; preds = %13
%57 = load float, float* %11
%58 = fpext float %57 to double
%59 = fcmp ogt double %58, 1.000000e+00
br i1 %59, label %60, label %61
60: ; preds = %56
store float 1.000000e+00, float* %11
br label %61
61: ; preds = %60, %56
%62 = load float, float* %11
%63 = fpext float %62 to double
%64 = fcmp olt double %63, -1.000000e+00
br i1 %64, label %65, label %66
65: ; preds = %61
store float -1.000000e+00, float* %11
br label %66
66: ; preds = %65, %61
%67 = load i64, i64* %10
%68 = and i64 %67, 2
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load float, float* %11
%72 = fpext float %71 to double
%73 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %72, double 5.000000e-01)
%74 = fptrunc double %73 to float
store float %74, float* %11
br label %78
75: ; preds = %66
%76 = load float, float* %11
%77 = call float @fabs(float %76)
store float %77, float* %11
br label %78
78: ; preds = %75, %70
%79 = load float, float* %11
ret float %79
}

LLVM IR (-O2):
define float @TURB_Turbulence3d(float %0, float %1, float %2, i64 %3, i64 %4) {
%6 = icmp eq i64 %3, 0
br i1 %6, label %32, label %7
7: ; preds = %5
%8 = and i64 %4, 1
%9 = icmp eq i64 %8, 0
br label %10
10: ; preds = %7, %26
%11 = phi i64 [ %3, %7 ], [ %17, %26 ]
%12 = phi float [ 1.000000e+00, %7 ], [ %18, %26 ]
%13 = phi float [ 0.000000e+00, %7 ], [ %27, %26 ]
%14 = phi float [ %0, %7 ], [ %28, %26 ]
%15 = phi float [ %2, %7 ], [ %30, %26 ]
%16 = phi float [ %1, %7 ], [ %29, %26 ]
%17 = add nsw i64 %11, -1
%18 = fmul float %12, 5.000000e-01
%19 = tail call float @noise3d(float %14, float %16, float %15)
br i1 %9, label %24, label %20
20: ; preds = %10
%21 = fmul float %18, %19
%22 = tail call float @llvm.fabs.f32(float %21)
%23 = fadd float %13, %22
br label %26
24: ; preds = %10
%25 = tail call float @llvm.fmuladd.f32(float %19, float %18, float %13)
br label %26
26: ; preds = %24, %20
%27 = phi float [ %23, %20 ], [ %25, %24 ]
%28 = fmul float %14, 2.000000e+00
%29 = fmul float %16, 2.000000e+00
%30 = fmul float %15, 2.000000e+00
%31 = icmp eq i64 %17, 0
br i1 %31, label %32, label %10
32: ; preds = %26, %5
%33 = phi float [ 0.000000e+00, %5 ], [ %27, %26 ]
%34 = fcmp ogt float %33, 1.000000e+00
%35 = select i1 %34, float 1.000000e+00, float %33
%36 = fcmp olt float %35, -1.000000e+00
%37 = select i1 %36, float -1.000000e+00, float %35
%38 = and i64 %4, 2
%39 = icmp eq i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %32
%41 = fpext float %37 to double
%42 = tail call double @llvm.fmuladd.f64(double %41, double 5.000000e-01, double 5.000000e-01)
%43 = fptrunc double %42 to float
br label %46
44: ; preds = %32
%45 = tail call float @llvm.fabs.f32(float %37)
br label %46
46: ; preds = %44, %40
%47 = phi float [ %43, %40 ], [ %45, %44 ]
ret float %47
}