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


x86 assembly (clang, -O0):
<TURB_Turbulence2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xec6(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     11dd <TURB_Turbulence2d+0xcd>
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
call   1030 <noise2d@plt>
movss  -0x20(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe89(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe63(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe45(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    113f <TURB_Turbulence2d+0x2f>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe1a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1205 <TURB_Turbulence2d+0xf5>
movss  0xe04(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1223 <TURB_Turbulence2d+0x113>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TURB_Turbulence2d>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm2,%xmm2
test   %rsi,%rsi
je     118c <TURB_Turbulence2d+0x7c>
mov    %rsi,%rbx
xorps  %xmm2,%xmm2
movss  0xed5(%rip),%xmm3
nopl   0x0(%rax,%rax,1)
movss  %xmm3,0x8(%rsp)
movss  %xmm2,0xc(%rsp)
movss  %xmm0,(%rsp)
movss  %xmm1,0x4(%rsp)
movss  (%rsp),%xmm0
movss  0x4(%rsp),%xmm1
call   1030 <noise2d@plt>
movss  0x8(%rsp),%xmm3
movss  0xc(%rsp),%xmm2
movss  0x4(%rsp),%xmm1
mulss  %xmm3,%xmm0
addss  %xmm0,%xmm2
movss  (%rsp),%xmm0
mulss  0xe82(%rip),%xmm3
addss  %xmm0,%xmm0
addss  %xmm1,%xmm1
add    $0xffffffffffffffff,%rbx
jne    1130 <TURB_Turbulence2d+0x20>
movss  0xe70(%rip),%xmm1
minss  %xmm2,%xmm1
xorps  %xmm0,%xmm0
maxss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @TURB_Turbulence2d(float* %0, float %1, float %2, i64 %3) {
%5 = alloca float*
%6 = alloca float
%7 = alloca float
%8 = alloca i64
%9 = alloca float
%10 = alloca float
store float* %0, float** %5
store float %1, float* %6
store float %2, float* %7
store i64 %3, i64* %8
store float 0.000000e+00, float* %9
store float 5.000000e-01, float* %10
br label %11
11: ; preds = %15, %4
%12 = load i64, i64* %8
%13 = add nsw i64 %12, -1
store i64 %13, i64* %8
%14 = icmp ne i64 %12, 0
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load float, float* %6
%17 = load float, float* %7
%18 = call float @noise2d(float %16, float %17)
%19 = load float, float* %10
%20 = load float, float* %9
%21 = call float @llvm.fmuladd.f32(float %18, float %19, float %20)
store float %21, float* %9
%22 = load float, float* %10
%23 = fpext float %22 to double
%24 = fmul double %23, 5.000000e-01
%25 = fptrunc double %24 to float
store float %25, float* %10
%26 = load float, float* %6
%27 = fpext float %26 to double
%28 = fmul double %27, 2.000000e+00
%29 = fptrunc double %28 to float
store float %29, float* %6
%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
br label %11
34: ; preds = %11
%35 = load float, float* %9
%36 = fpext float %35 to double
%37 = fcmp ogt double %36, 1.000000e+00
br i1 %37, label %38, label %39
38: ; preds = %34
store float 1.000000e+00, float* %9
br label %39
39: ; preds = %38, %34
%40 = load float, float* %9
%41 = fpext float %40 to double
%42 = fcmp olt double %41, 0.000000e+00
br i1 %42, label %43, label %44
43: ; preds = %39
store float 0.000000e+00, float* %9
br label %44
44: ; preds = %43, %39
%45 = load float, float* %9
ret float %45
}

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