#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 */
double rndu();
double sqrt(double);
double rndTriangle(void) {
  double u, z;
  u = rndu();
  if (u > 0.5)
    z = sqrt(6.0) - 2.0 * sqrt(3.0 * (1.0 - u));
  else
    z = -sqrt(6.0) + 2.0 * sqrt(3.0 * u);
  return z;
}


x86 assembly (clang, -O0):
<rndTriangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <rndu@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xebf(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1195 <rndTriangle+0x75>
movsd  0xebd(%rip),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb3(%rip),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  0xe96(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11e2 <rndTriangle+0xc2>
movsd  0xe73(%rip),%xmm0
call   1040 <sqrt@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe42(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  -0x20(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndTriangle>:
push   %rax
xor    %eax,%eax
call   1030 <rndu@plt>
ucomisd 0xed0(%rip),%xmm0
jbe    1159 <rndTriangle+0x39>
movsd  0xede(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xec2(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     1171 <rndTriangle+0x51>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    117a <rndTriangle+0x5a>
mulsd  0xea7(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1190 <rndTriangle+0x70>
sqrtsd %xmm0,%xmm0
jmp    1195 <rndTriangle+0x75>
movapd %xmm1,%xmm0
call   1040 <sqrt@plt>
addsd  %xmm0,%xmm0
movsd  0xe9a(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret
call   1040 <sqrt@plt>
addsd  %xmm0,%xmm0
addsd  0xe6f(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @rndTriangle() {
%1 = alloca double
%2 = alloca double
%3 = call double (...) @rndu()
store double %3, double* %1
%4 = load double, double* %1
%5 = fcmp ogt double %4, 5.000000e-01
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = call double @sqrt(double 6.000000e+00)
%8 = load double, double* %1
%9 = fsub double 1.000000e+00, %8
%10 = fmul double 3.000000e+00, %9
%11 = call double @sqrt(double %10)
%12 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %11, double %7)
store double %12, double* %2
br label %20
13: ; preds = %0
%14 = call double @sqrt(double 6.000000e+00)
%15 = fneg double %14
%16 = load double, double* %1
%17 = fmul double 3.000000e+00, %16
%18 = call double @sqrt(double %17)
%19 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %18, double %15)
store double %19, double* %2
br label %20
20: ; preds = %13, %6
%21 = load double, double* %2
ret double %21
}

LLVM IR (-O2):
define double @rndTriangle() {
%1 = tail call double (...) @rndu()
%2 = fcmp ogt double %1, 5.000000e-01
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = fsub double 1.000000e+00, %1
%5 = fmul double %4, 3.000000e+00
%6 = tail call double @sqrt(double %5)
%7 = tail call double @llvm.fmuladd.f64(double %6, double -2.000000e+00, double 0x4003988E1409212E)
br label %12
8: ; preds = %0
%9 = fmul double %1, 3.000000e+00
%10 = tail call double @sqrt(double %9)
%11 = tail call double @llvm.fmuladd.f64(double %10, double 2.000000e+00, double 0xC003988E1409212E)
br label %12
12: ; preds = %8, %3
%13 = phi double [ %7, %3 ], [ %11, %8 ]
ret double %13
}