#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 */
float randf(int);
int random();
float randRangeMaybe(float min, float max, float likelihood, float def) {
  if (randf(1) < likelihood)
    return def;
  float scale = max - min;
  return min + (float)(random() % 1000001) / 1000000.0f * scale;
}


x86 assembly (clang, -O0):
<randRangeMaybe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  %xmm3,-0x14(%rbp)
mov    $0x1,%edi
call   1040 <randf@plt>
movaps %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1166 <randRangeMaybe+0x46>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11b5 <randRangeMaybe+0x95>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
movss  -0x1c(%rbp),%xmm1
mov    $0xf4241,%ecx
cltd
idiv   %ecx
cvtsi2ss %edx,%xmm0
movss  0xe61(%rip),%xmm2
divss  %xmm2,%xmm0
movss  -0x18(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randRangeMaybe>:
sub    $0x18,%rsp
movss  %xmm3,0x10(%rsp)
movss  %xmm2,0x14(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0xc(%rsp)
mov    $0x1,%edi
call   1040 <randf@plt>
movss  0x14(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    115c <randRangeMaybe+0x3c>
movss  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
cltq
imul   $0x431bda1d,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4241,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xe5e(%rip),%xmm0
mulss  0x8(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @randRangeMaybe(float %0, float %1, float %2, float %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
%11 = call float @randf(i32 1)
%12 = load float, float* %8
%13 = fcmp olt float %11, %12
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = load float, float* %9
store float %15, float* %5
br label %27
16: ; preds = %4
%17 = load float, float* %7
%18 = load float, float* %6
%19 = fsub float %17, %18
store float %19, float* %10
%20 = load float, float* %6
%21 = call i32 (...) @random()
%22 = srem i32 %21, 1000001
%23 = sitofp i32 %22 to float
%24 = fdiv float %23, 1.000000e+06
%25 = load float, float* %10
%26 = call float @llvm.fmuladd.f32(float %24, float %25, float %20)
store float %26, float* %5
br label %27
27: ; preds = %16, %14
%28 = load float, float* %5
ret float %28
}

LLVM IR (-O2):
define float @randRangeMaybe(float %0, float %1, float %2, float %3) {
%5 = tail call float @randf(i32 1)
%6 = fcmp olt float %5, %2
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = fsub float %1, %0
%9 = tail call i32 (...) @random()
%10 = srem i32 %9, 1000001
%11 = sitofp i32 %10 to float
%12 = fdiv float %11, 1.000000e+06
%13 = tail call float @llvm.fmuladd.f32(float %12, float %8, float %0)
br label %14
14: ; preds = %4, %7
%15 = phi float [ %13, %7 ], [ %3, %4 ]
ret float %15
}