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


x86 assembly (clang, -O0):
<BLI_turbulence1>:
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  0xee1(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xed0(%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>
addss  %xmm0,%xmm0
movss  0xea2(%rip),%xmm1
addss  %xmm1,%xmm0
movaps 0xe87(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1214 <BLI_turbulence1+0x104>
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,%xmm1
movss  -0x24(%rbp),%xmm0
addss  %xmm1,%xmm1
movss  0xe48(%rip),%xmm2
addss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movaps 0xe29(%rip),%xmm1
pand   %xmm1,%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x1c(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xe1c(%rip),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <BLI_turbulence1+0x72>
movss  -0x18(%rbp),%xmm0
divss  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BLI_turbulence1>:
push   %rbx
sub    $0x30,%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>
addss  %xmm0,%xmm0
addss  0xec0(%rip),%xmm0
andps  0xec9(%rip),%xmm0
test   %ebx,%ebx
jle    11ed <BLI_turbulence1+0xdd>
add    $0x1,%ebx
movss  0xeae(%rip),%xmm2
movss  0xea2(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm2,0x18(%rsp)
movss  %xmm1,0x1c(%rsp)
movaps %xmm0,0x20(%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
addss  %xmm0,%xmm0
addss  0xe4d(%rip),%xmm0
mulss  %xmm2,%xmm0
andps  0xe52(%rip),%xmm0
movaps 0x20(%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,0x20(%rsp)
movss  0x1c(%rsp),%xmm1
movaps 0x20(%rsp),%xmm0
addss  %xmm2,%xmm1
mulss  0xe25(%rip),%xmm2
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1170 <BLI_turbulence1+0x60>
jmp    11f5 <BLI_turbulence1+0xe5>
movss  0xe0f(%rip),%xmm1
divss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @BLI_turbulence1(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)
%19 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %18, float -1.000000e+00)
%20 = call float @llvm.fabs.f32(float %19)
store float %20, float* %11
br label %21
21: ; preds = %24, %5
%22 = load i32, i32* %10
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %45
24: ; preds = %21
%25 = load float, float* %12
%26 = load float, float* %6
%27 = load float, float* %12
%28 = fmul float %26, %27
%29 = load float, float* %7
%30 = load float, float* %8
%31 = load float, float* %9
%32 = call float @BLI_hnoise(float %28, float %29, float %30, float %31)
%33 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %32, float -1.000000e+00)
%34 = fmul float %25, %33
%35 = call float @llvm.fabs.f32(float %34)
%36 = load float, float* %11
%37 = fadd float %36, %35
store float %37, float* %11
%38 = load float, float* %12
%39 = load float, float* %13
%40 = fadd float %39, %38
store float %40, float* %13
%41 = load float, float* %12
%42 = fmul float %41, 5.000000e-01
store float %42, float* %12
%43 = load i32, i32* %10
%44 = add nsw i32 %43, -1
store i32 %44, i32* %10
br label %21
45: ; preds = %21
%46 = load float, float* %11
%47 = load float, float* %13
%48 = fdiv float %46, %47
ret float %48
}

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