#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 BLI_hnoise(float, float, float, float);
float BLI_turbulence(float noisesize, float x, float y, float z, int nr) {
  float s, d = 0.5, div = 1.0;
  s = BLI_hnoise(noisesize, x, y, z);
  while (nr > 0) {
    s += d * BLI_hnoise(noisesize * d, x, y, z);
    div += d;
    d *= 0.5f;
    nr--;
  }
  return s / div;
}


x86 assembly (clang, -O0):
<BLI_turbulence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movss  0xecd(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xebc(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm3
call   1030 <BLI_hnoise@plt>
movss  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e2 <BLI_turbulence+0xd2>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm3
call   1030 <BLI_hnoise@plt>
movaps %xmm0,%xmm2
movss  -0x24(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x1c(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xe3a(%rip),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1167 <BLI_turbulence+0x57>
movss  -0x18(%rbp),%xmm0
divss  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BLI_turbulence>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movss  %xmm0,0x8(%rsp)
movss  %xmm1,0xc(%rsp)
movss  %xmm2,0x10(%rsp)
movss  %xmm3,0x14(%rsp)
call   1030 <BLI_hnoise@plt>
test   %ebx,%ebx
jle    11be <BLI_turbulence+0xae>
add    $0x1,%ebx
movss  0xebd(%rip),%xmm2
movss  0xeb1(%rip),%xmm1
nop
movss  %xmm2,0x18(%rsp)
movss  %xmm1,0x1c(%rsp)
movss  %xmm0,0x4(%rsp)
movaps %xmm2,%xmm0
mulss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
movss  0x10(%rsp),%xmm2
movss  0x14(%rsp),%xmm3
call   1030 <BLI_hnoise@plt>
movss  0x18(%rsp),%xmm2
mulss  %xmm2,%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x1c(%rsp),%xmm1
movss  0x4(%rsp),%xmm0
addss  %xmm2,%xmm1
mulss  0xe50(%rip),%xmm2
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1150 <BLI_turbulence+0x40>
jmp    11c6 <BLI_turbulence+0xb6>
movss  0xe3a(%rip),%xmm1
divss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @BLI_turbulence(float %0, float %1, float %2, float %3, i32 %4) {
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca float
%12 = alloca float
%13 = alloca float
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
store i32 %4, i32* %10
store float 5.000000e-01, float* %12
store float 1.000000e+00, float* %13
%14 = load float, float* %6
%15 = load float, float* %7
%16 = load float, float* %8
%17 = load float, float* %9
%18 = call float @BLI_hnoise(float %14, float %15, float %16, float %17)
store float %18, float* %11
br label %19
19: ; preds = %22, %5
%20 = load i32, i32* %10
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %19
%23 = load float, float* %12
%24 = load float, float* %6
%25 = load float, float* %12
%26 = fmul float %24, %25
%27 = load float, float* %7
%28 = load float, float* %8
%29 = load float, float* %9
%30 = call float @BLI_hnoise(float %26, float %27, float %28, float %29)
%31 = load float, float* %11
%32 = call float @llvm.fmuladd.f32(float %23, float %30, float %31)
store float %32, float* %11
%33 = load float, float* %12
%34 = load float, float* %13
%35 = fadd float %34, %33
store float %35, float* %13
%36 = load float, float* %12
%37 = fmul float %36, 5.000000e-01
store float %37, float* %12
%38 = load i32, i32* %10
%39 = add nsw i32 %38, -1
store i32 %39, i32* %10
br label %19
40: ; preds = %19
%41 = load float, float* %11
%42 = load float, float* %13
%43 = fdiv float %41, %42
ret float %43
}

LLVM IR (-O2):
define float @BLI_turbulence(float %0, float %1, float %2, float %3, i32 %4) {
%6 = tail call float @BLI_hnoise(float %0, float %1, float %2, float %3)
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %20
8: ; preds = %5, %8
%9 = phi float [ %16, %8 ], [ 1.000000e+00, %5 ]
%10 = phi float [ %17, %8 ], [ 5.000000e-01, %5 ]
%11 = phi float [ %15, %8 ], [ %6, %5 ]
%12 = phi i32 [ %18, %8 ], [ %4, %5 ]
%13 = fmul float %10, %0
%14 = tail call float @BLI_hnoise(float %13, float %1, float %2, float %3)
%15 = tail call float @llvm.fmuladd.f32(float %10, float %14, float %11)
%16 = fadd float %10, %9
%17 = fmul float %10, 5.000000e-01
%18 = add nsw i32 %12, -1
%19 = icmp ugt i32 %12, 1
br i1 %19, label %8, label %20
20: ; preds = %8, %5
%21 = phi float [ %6, %5 ], [ %15, %8 ]
%22 = phi float [ 1.000000e+00, %5 ], [ %16, %8 ]
%23 = fdiv float %21, %22
ret float %23
}