#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 */
int fabs(double);
int pow(double, int);
double sqrt(double);
double rayleighPDF(double r) {
  double u = 0, d = 0, q = 0;
  if ((r > 1) || (r < 0))
    r = 1. / fabs(r);
  ;
  q = -8 * r + 4;
  d = 1 + (pow(q, 2) / 4.);
  u = pow(-(q / 2.) + sqrt(d), 1. / 3.);
  return (u - (1 / u));
}


x86 assembly (clang, -O0):
<rayleighPDF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     117a <rayleighPDF+0x4a>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1199 <rayleighPDF+0x69>
movsd  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe70(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe5e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe3a(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe1e(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe10(%rip),%xmm1
divsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
xor    %edi,%edi
call   1040 <pow@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdb5(%rip),%xmm1
divsd  -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rayleighPDF>:
push   %rax
ucomisd 0xec7(%rip),%xmm0
ja     1145 <rayleighPDF+0x15>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    115d <rayleighPDF+0x2d>
call   1030 <fabs@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0xea7(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  0xea3(%rip),%xmm0
addsd  0xea3(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe8d(%rip),%xmm0
addsd  0xe6d(%rip),%xmm0
movsd  (%rsp),%xmm1
mulsd  0xe80(%rip),%xmm1
movsd  %xmm1,(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b5 <rayleighPDF+0x85>
sqrtsd %xmm0,%xmm0
jmp    11ba <rayleighPDF+0x8a>
call   1050 <sqrt@plt>
subsd  (%rsp),%xmm0
xor    %edi,%edi
call   1040 <pow@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0xe53(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @rayleighPDF(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
%6 = load double, double* %2
%7 = fcmp ogt double %6, 1.000000e+00
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load double, double* %2
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %16
11: ; preds = %8, %1
%12 = load double, double* %2
%13 = call i32 @fabs(double %12)
%14 = sitofp i32 %13 to double
%15 = fdiv double 1.000000e+00, %14
store double %15, double* %2
br label %16
16: ; preds = %11, %8
%17 = load double, double* %2
%18 = call double @llvm.fmuladd.f64(double -8.000000e+00, double %17, double 4.000000e+00)
store double %18, double* %5
%19 = load double, double* %5
%20 = call i32 @pow(double %19, i32 2)
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, 4.000000e+00
%23 = fadd double 1.000000e+00, %22
store double %23, double* %4
%24 = load double, double* %5
%25 = fdiv double %24, 2.000000e+00
%26 = fneg double %25
%27 = load double, double* %4
%28 = call double @sqrt(double %27)
%29 = fadd double %26, %28
%30 = call i32 @pow(double %29, i32 0)
%31 = sitofp i32 %30 to double
store double %31, double* %3
%32 = load double, double* %3
%33 = load double, double* %3
%34 = fdiv double 1.000000e+00, %33
%35 = fsub double %32, %34
ret double %35
}

LLVM IR (-O2):
define double @rayleighPDF(double %0) {
%2 = fcmp ogt double %0, 1.000000e+00
%3 = fcmp olt double %0, 0.000000e+00
%4 = or i1 %2, %3
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i32 @fabs(double %0)
%7 = sitofp i32 %6 to double
%8 = fdiv double 1.000000e+00, %7
br label %9
9: ; preds = %1, %5
%10 = phi double [ %8, %5 ], [ %0, %1 ]
%11 = tail call double @llvm.fmuladd.f64(double %10, double -8.000000e+00, double 4.000000e+00)
%12 = tail call i32 @pow(double %11, i32 2)
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 2.500000e-01
%15 = fadd double %14, 1.000000e+00
%16 = fmul double %11, 5.000000e-01
%17 = tail call double @sqrt(double %15)
%18 = fsub double %17, %16
%19 = tail call i32 @pow(double %18, i32 0)
%20 = sitofp i32 %19 to double
%21 = fdiv double 1.000000e+00, %20
%22 = fsub double %20, %21
ret double %22
}