#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 noise1d(float);
float TURB_Turbulence1d(float x, long octaves, long mode) {
  float t, s;
  t = 0.0;
  s = 1.0;
  while (octaves--) {
    s *= 0.5;
    if (mode & 1)
      t += fabs(noise1d(x) * s);
    else
      t += noise1d(x) * s;
    x *= 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_Turbulence1d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xebb(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     11fa <TURB_Turbulence1d+0xda>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11b6 <TURB_Turbulence1d+0x96>
movss  -0x4(%rbp),%xmm0
call   1030 <noise1d@plt>
mulss  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11d7 <TURB_Turbulence1d+0xb7>
movss  -0x4(%rbp),%xmm0
call   1030 <noise1d@plt>
movss  -0x20(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe38(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    114a <TURB_Turbulence1d+0x2a>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdfd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1222 <TURB_Turbulence1d+0x102>
movss  0xde3(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xddd(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    124a <TURB_Turbulence1d+0x12a>
movss  0xdbf(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     1283 <TURB_Turbulence1d+0x163>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdab(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1292 <TURB_Turbulence1d+0x172>
movss  -0x1c(%rbp),%xmm0
call   1040 <fabs@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TURB_Turbulence1d>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
test   %rdi,%rdi
je     1196 <TURB_Turbulence1d+0x86>
mov    %rdi,%rbx
xorps  %xmm2,%xmm2
movss  0xed3(%rip),%xmm1
movss  %xmm1,0x8(%rsp)
jmp    115b <TURB_Turbulence1d+0x4b>
cs nopw 0x0(%rax,%rax,1)
nop
movaps 0x10(%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm2
movss  0xc(%rsp),%xmm0
addss  %xmm0,%xmm0
test   %rbx,%rbx
je     1199 <TURB_Turbulence1d+0x89>
movaps %xmm2,0x10(%rsp)
add    $0xffffffffffffffff,%rbx
movss  %xmm0,0xc(%rsp)
call   1030 <noise1d@plt>
movss  0x8(%rsp),%xmm1
mulss  0xe87(%rip),%xmm1
test   $0x1,%r14b
movss  %xmm1,0x8(%rsp)
mulss  %xmm1,%xmm0
je     1140 <TURB_Turbulence1d+0x30>
andps  0xe7c(%rip),%xmm0
jmp    1140 <TURB_Turbulence1d+0x30>
xorps  %xmm2,%xmm2
movss  0xe5f(%rip),%xmm1
minss  %xmm2,%xmm1
movss  0xe5b(%rip),%xmm0
maxss  %xmm1,%xmm0
test   $0x2,%r14b
jne    11c0 <TURB_Turbulence1d+0xb0>
andps  0xe52(%rip),%xmm0
jmp    11d8 <TURB_Turbulence1d+0xc8>
cvtss2sd %xmm0,%xmm0
movsd  0xe54(%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_Turbulence1d(float %0, i64 %1, i64 %2) {
%4 = alloca float
%5 = alloca i64
%6 = alloca i64
%7 = alloca float
%8 = alloca float
store float %0, float* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store float 0.000000e+00, float* %7
store float 1.000000e+00, float* %8
br label %9
9: ; preds = %35, %3
%10 = load i64, i64* %5
%11 = add nsw i64 %10, -1
store i64 %11, i64* %5
%12 = icmp ne i64 %10, 0
br i1 %12, label %13, label %40
13: ; preds = %9
%14 = load float, float* %8
%15 = fpext float %14 to double
%16 = fmul double %15, 5.000000e-01
%17 = fptrunc double %16 to float
store float %17, float* %8
%18 = load i64, i64* %6
%19 = and i64 %18, 1
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %13
%22 = load float, float* %4
%23 = call float @noise1d(float %22)
%24 = load float, float* %8
%25 = fmul float %23, %24
%26 = call float @fabs(float %25)
%27 = load float, float* %7
%28 = fadd float %27, %26
store float %28, float* %7
br label %35
29: ; preds = %13
%30 = load float, float* %4
%31 = call float @noise1d(float %30)
%32 = load float, float* %8
%33 = load float, float* %7
%34 = call float @llvm.fmuladd.f32(float %31, float %32, float %33)
store float %34, float* %7
br label %35
35: ; preds = %29, %21
%36 = load float, float* %4
%37 = fpext float %36 to double
%38 = fmul double %37, 2.000000e+00
%39 = fptrunc double %38 to float
store float %39, float* %4
br label %9
40: ; preds = %9
%41 = load float, float* %7
%42 = fpext float %41 to double
%43 = fcmp ogt double %42, 1.000000e+00
br i1 %43, label %44, label %45
44: ; preds = %40
store float 1.000000e+00, float* %7
br label %45
45: ; preds = %44, %40
%46 = load float, float* %7
%47 = fpext float %46 to double
%48 = fcmp olt double %47, -1.000000e+00
br i1 %48, label %49, label %50
49: ; preds = %45
store float -1.000000e+00, float* %7
br label %50
50: ; preds = %49, %45
%51 = load i64, i64* %6
%52 = and i64 %51, 2
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load float, float* %7
%56 = fpext float %55 to double
%57 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %56, double 5.000000e-01)
%58 = fptrunc double %57 to float
store float %58, float* %7
br label %62
59: ; preds = %50
%60 = load float, float* %7
%61 = call float @fabs(float %60)
store float %61, float* %7
br label %62
62: ; preds = %59, %54
%63 = load float, float* %7
ret float %63
}

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