#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);
float TURB_Turbulence2d(float *table, float x, float y, long octaves) {
  float t, s;
  t = 0.0;
  s = 0.5;
  while (octaves--) {
    t += noise2d(table, 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     11e1 <TURB_Turbulence2d+0xd1>
mov    -0x8(%rbp),%rdi
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  0xe85(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe5f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe41(%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  0xe16(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1209 <TURB_Turbulence2d+0xf9>
movss  0xe00(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1227 <TURB_Turbulence2d+0x117>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TURB_Turbulence2d>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm2,%xmm2
test   %rsi,%rsi
je     1192 <TURB_Turbulence2d+0x82>
mov    %rsi,%rbx
mov    %rdi,%r14
xorps  %xmm2,%xmm2
movss  0xed0(%rip),%xmm3
movss  %xmm3,0x10(%rsp)
movss  %xmm2,0x14(%rsp)
movss  %xmm0,0x8(%rsp)
movss  %xmm1,0xc(%rsp)
mov    %r14,%rdi
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1030 <noise2d@plt>
movss  0x10(%rsp),%xmm3
movss  0x14(%rsp),%xmm2
movss  0xc(%rsp),%xmm1
mulss  %xmm3,%xmm0
addss  %xmm0,%xmm2
movss  0x8(%rsp),%xmm0
mulss  0xe7c(%rip),%xmm3
addss  %xmm0,%xmm0
addss  %xmm1,%xmm1
add    $0xffffffffffffffff,%rbx
jne    1130 <TURB_Turbulence2d+0x20>
movss  0xe6a(%rip),%xmm1
minss  %xmm2,%xmm1
xorps  %xmm0,%xmm0
maxss  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
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 %35
15: ; preds = %11
%16 = load float*, float** %5
%17 = load float, float* %6
%18 = load float, float* %7
%19 = call float @noise2d(float* %16, float %17, float %18)
%20 = load float, float* %10
%21 = load float, float* %9
%22 = call float @llvm.fmuladd.f32(float %19, float %20, float %21)
store float %22, float* %9
%23 = load float, float* %10
%24 = fpext float %23 to double
%25 = fmul double %24, 5.000000e-01
%26 = fptrunc double %25 to float
store float %26, float* %10
%27 = load float, float* %6
%28 = fpext float %27 to double
%29 = fmul double %28, 2.000000e+00
%30 = fptrunc double %29 to float
store float %30, float* %6
%31 = load float, float* %7
%32 = fpext float %31 to double
%33 = fmul double %32, 2.000000e+00
%34 = fptrunc double %33 to float
store float %34, float* %7
br label %11
35: ; preds = %11
%36 = load float, float* %9
%37 = fpext float %36 to double
%38 = fcmp ogt double %37, 1.000000e+00
br i1 %38, label %39, label %40
39: ; preds = %35
store float 1.000000e+00, float* %9
br label %40
40: ; preds = %39, %35
%41 = load float, float* %9
%42 = fpext float %41 to double
%43 = fcmp olt double %42, 0.000000e+00
br i1 %43, label %44, label %45
44: ; preds = %40
store float 0.000000e+00, float* %9
br label %45
45: ; preds = %44, %40
%46 = load float, float* %9
ret float %46
}

LLVM IR (-O2):
define float @TURB_Turbulence2d(float* %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* %0, 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
}