#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 rand_double();
int sqrt(int);
double rand_triangle(double a, double b) {
  double y = rand_double(), x = 0;
  if (y < a / (a - b)) {
    x = a * (1 - sqrt(y * (1 - b / a)));
  } else {
    x = b * (1 - sqrt((1 - y) * (1 - a / b)));
  }
  return x;
}


x86 assembly (clang, -O0):
<rand_triangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand_double@plt>
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ba <rand_triangle+0x9a>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
divsd  -0x8(%rbp),%xmm2
movsd  0xe77(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x28(%rbp),%xmm0
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120f <rand_triangle+0xef>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe34(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
divsd  -0x10(%rbp),%xmm2
movsd  0xe1d(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x30(%rbp),%xmm0
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_triangle>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand_double@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm1
subsd  %xmm4,%xmm1
movapd %xmm3,%xmm2
divsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jbe    1163 <rand_triangle+0x43>
divsd  %xmm3,%xmm4
movapd %xmm4,%xmm1
jmp    1181 <rand_triangle+0x61>
movsd  0xe95(%rip),%xmm2
subsd  %xmm0,%xmm2
divsd  %xmm4,%xmm3
movapd %xmm3,%xmm1
movapd %xmm2,%xmm0
movsd  %xmm4,0x8(%rsp)
movsd  0xe77(%rip),%xmm2
subsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
cvttsd2si %xmm2,%edi
call   1040 <sqrt@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @rand_triangle(double %0, double %1) {
%3 = tail call double (...) @rand_double()
%4 = fsub double %0, %1
%5 = fdiv double %0, %4
%6 = fcmp olt double %3, %5
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = fdiv double %1, %0
br label %12
9: ; preds = %2
%10 = fsub double 1.000000e+00, %3
%11 = fdiv double %0, %1
br label %12
12: ; preds = %9, %7
%13 = phi double [ %11, %9 ], [ %8, %7 ]
%14 = phi double [ %10, %9 ], [ %3, %7 ]
%15 = phi double [ %1, %9 ], [ %0, %7 ]
%16 = fsub double 1.000000e+00, %13
%17 = fmul double %16, %14
%18 = fptosi double %17 to i32
%19 = tail call i32 @sqrt(i32 %18)
%20 = sub nsw i32 1, %19
%21 = sitofp i32 %20 to double
%22 = fmul double %15, %21
ret double %22
}