#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 */
scalar_t__ RAND_MAX;
int rand();
double bimodal_dist(double min, double max, double sep, double heavy) {
  int r = rand();
  if ((double)r < (double)RAND_MAX * heavy) {
    return sep + r * (max - sep) / (double)RAND_MAX;
  } else {
    return min + r * (sep - min) / (double)RAND_MAX;
  }
}


x86 assembly (clang, -O0):
<bimodal_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
mov    0x2ea6(%rip),%rax
cvtsi2sdq (%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    118c <bimodal_dist+0x7c>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
subsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
mov    0x2e73(%rip),%rax
cvtsi2sdq (%rax),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11bd <bimodal_dist+0xad>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm1
mov    0x2e3d(%rip),%rax
cvtsi2sdq (%rax),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bimodal_dist>:
sub    $0x38,%rsp
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
movaps %xmm1,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand@plt>
movsd  0x8(%rsp),%xmm5
movsd  0x10(%rsp),%xmm4
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mov    0x2e9c(%rip),%rax
xorps  %xmm2,%xmm2
cvtsi2sdq (%rax),%xmm2
movsd  0x18(%rsp),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
movapd %xmm0,%xmm7
movapd %xmm4,%xmm3
subsd  %xmm5,%xmm3
movapd 0x20(%rsp),%xmm6
subsd  %xmm4,%xmm6
movapd %xmm1,%xmm0
cmpltsd %xmm7,%xmm0
andpd  %xmm0,%xmm6
andnpd %xmm3,%xmm0
orpd   %xmm6,%xmm0
ja     1193 <bimodal_dist+0x83>
movapd %xmm5,%xmm4
mulsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm4,%xmm0
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
@RAND_MAX = global i64 0
define double @bimodal_dist(double %0, double %1, double %2, double %3) {
%5 = tail call i32 (...) @rand()
%6 = sitofp i32 %5 to double
%7 = load i64, i64* @RAND_MAX
%8 = sitofp i64 %7 to double
%9 = fmul double %8, %3
%10 = fcmp ogt double %9, %6
%11 = fsub double %2, %0
%12 = fsub double %1, %2
%13 = select i1 %10, double %12, double %11
%14 = select i1 %10, double %2, double %0
%15 = fmul double %13, %6
%16 = fdiv double %15, %8
%17 = fadd double %16, %14
ret double %17
}