#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();
float sinf(float);
float rand_flt_bounded(float M, float N) {
  int choice = rand() % 2;
  float v = 0.0;
  if (choice) {
    v = ((float)rand() / (float)RAND_MAX);
    return M + v * (N - M);
  } else {
    float v = sinf((float)rand());
    return M + v * (N - M);
  }
}


x86 assembly (clang, -O0):
<rand_flt_bounded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     119c <rand_flt_bounded+0x7c>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %eax,%xmm0
mov    0x2e80(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
subss  -0x8(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11d2 <rand_flt_bounded+0xb2>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %eax,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
subss  -0x8(%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):
<rand_flt_bounded>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
test   $0x1,%bl
jne    1154 <rand_flt_bounded+0x34>
call   1030 <sinf@plt>
jmp    1167 <rand_flt_bounded+0x47>
mov    0x2e8d(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
movss  0xc(%rsp),%xmm1
movss  0x8(%rsp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm0,%xmm1
addss  %xmm2,%xmm1
movaps %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define float @rand_flt_bounded(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca float
%8 = alloca float
store float %0, float* %4
store float %1, float* %5
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 2
store i32 %10, i32* %6
store float 0.000000e+00, float* %7
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %2
%14 = call i32 (...) @rand()
%15 = sitofp i32 %14 to float
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to float
%18 = fdiv float %15, %17
store float %18, float* %7
%19 = load float, float* %4
%20 = load float, float* %7
%21 = load float, float* %5
%22 = load float, float* %4
%23 = fsub float %21, %22
%24 = call float @llvm.fmuladd.f32(float %20, float %23, float %19)
store float %24, float* %3
br label %35
25: ; preds = %2
%26 = call i32 (...) @rand()
%27 = sitofp i32 %26 to float
%28 = call float @sinf(float %27)
store float %28, float* %8
%29 = load float, float* %4
%30 = load float, float* %8
%31 = load float, float* %5
%32 = load float, float* %4
%33 = fsub float %31, %32
%34 = call float @llvm.fmuladd.f32(float %30, float %33, float %29)
store float %34, float* %3
br label %35
35: ; preds = %25, %13
%36 = load float, float* %3
ret float %36
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define float @rand_flt_bounded(float %0, float %1) {
%3 = tail call i32 (...) @rand()
%4 = and i32 %3, 1
%5 = icmp eq i32 %4, 0
%6 = tail call i32 (...) @rand()
%7 = sitofp i32 %6 to float
br i1 %5, label %12, label %8
8: ; preds = %2
%9 = load i64, i64* @RAND_MAX
%10 = sitofp i64 %9 to float
%11 = fdiv float %7, %10
br label %14
12: ; preds = %2
%13 = tail call float @sinf(float %7)
br label %14
14: ; preds = %12, %8
%15 = phi float [ %13, %12 ], [ %11, %8 ]
%16 = fsub float %1, %0
%17 = tail call float @llvm.fmuladd.f32(float %15, float %16, float %0)
ret float %17
}