#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 */
typedef double int32_t;

/* Variables and functions */
scalar_t__ RAND_MAX;
double random();
double sqrt(int);
int32_t random_triangular(int32_t low, int32_t high) {
  int32_t range = high - low;
  double U = random() / (double)RAND_MAX;
  if (U <= 0.5) {
    return low + sqrt(U * range * range / 2);
  } else {
    return high - sqrt((1 - U) * range * range / 2);
  }
}


x86 assembly (clang, -O0):
<random_triangular>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    0x2e99(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9b(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     11b4 <random_triangular+0x94>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11fb <random_triangular+0xdb>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe4a(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xe2b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_triangular>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
mov    0x2ea1(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xea5(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    119e <random_triangular+0x7e>
movsd  0xe9f(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  0xe7e(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xe4d(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
addsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define double @random_triangular(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %4
store double %1, double* %5
%8 = load double, double* %5
%9 = load double, double* %4
%10 = fsub double %8, %9
store double %10, double* %6
%11 = call double (...) @random()
%12 = load i64, i64* @RAND_MAX
%13 = sitofp i64 %12 to double
%14 = fdiv double %11, %13
store double %14, double* %7
%15 = load double, double* %7
%16 = fcmp ole double %15, 5.000000e-01
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = load double, double* %4
%19 = load double, double* %7
%20 = load double, double* %6
%21 = fmul double %19, %20
%22 = load double, double* %6
%23 = fmul double %21, %22
%24 = fdiv double %23, 2.000000e+00
%25 = fptosi double %24 to i32
%26 = call double @sqrt(i32 %25)
%27 = fadd double %18, %26
store double %27, double* %3
br label %40
28: ; preds = %2
%29 = load double, double* %5
%30 = load double, double* %7
%31 = fsub double 1.000000e+00, %30
%32 = load double, double* %6
%33 = fmul double %31, %32
%34 = load double, double* %6
%35 = fmul double %33, %34
%36 = fdiv double %35, 2.000000e+00
%37 = fptosi double %36 to i32
%38 = call double @sqrt(i32 %37)
%39 = fsub double %29, %38
store double %39, double* %3
br label %40
40: ; preds = %28, %17
%41 = load double, double* %3
ret double %41
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define double @random_triangular(double %0, double %1) {
%3 = fsub double %1, %0
%4 = tail call double (...) @random()
%5 = load i64, i64* @RAND_MAX
%6 = sitofp i64 %5 to double
%7 = fdiv double %4, %6
%8 = fcmp ugt double %7, 5.000000e-01
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = fmul double %3, %7
%11 = fmul double %3, %10
%12 = fmul double %11, 5.000000e-01
%13 = fptosi double %12 to i32
%14 = tail call double @sqrt(i32 %13)
%15 = fadd double %14, %0
br label %24
16: ; preds = %2
%17 = fsub double 1.000000e+00, %7
%18 = fmul double %3, %17
%19 = fmul double %3, %18
%20 = fmul double %19, 5.000000e-01
%21 = fptosi double %20 to i32
%22 = tail call double @sqrt(i32 %21)
%23 = fsub double %1, %22
br label %24
24: ; preds = %16, %9
%25 = phi double [ %15, %9 ], [ %23, %16 ]
ret double %25
}