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


x86 assembly (clang, -O0):
<rand_dbl_bounded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     119c <rand_dbl_bounded+0x7c>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %eax,%xmm0
mov    0x2e80(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d2 <rand_dbl_bounded+0xb2>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %eax,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_dbl_bounded>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
test   $0x1,%bl
jne    1153 <rand_dbl_bounded+0x33>
call   1030 <sin@plt>
jmp    1166 <rand_dbl_bounded+0x46>
mov    0x2e8e(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define double @rand_dbl_bounded(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 2
store i32 %10, i32* %6
store double 0.000000e+00, double* %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 double
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to double
%18 = fdiv double %15, %17
store double %18, double* %7
%19 = load double, double* %4
%20 = load double, double* %7
%21 = load double, double* %5
%22 = load double, double* %4
%23 = fsub double %21, %22
%24 = call double @llvm.fmuladd.f64(double %20, double %23, double %19)
store double %24, double* %3
br label %35
25: ; preds = %2
%26 = call i32 (...) @rand()
%27 = sitofp i32 %26 to double
%28 = call double @sin(double %27)
store double %28, double* %8
%29 = load double, double* %4
%30 = load double, double* %8
%31 = load double, double* %5
%32 = load double, double* %4
%33 = fsub double %31, %32
%34 = call double @llvm.fmuladd.f64(double %30, double %33, double %29)
store double %34, double* %3
br label %35
35: ; preds = %25, %13
%36 = load double, double* %3
ret double %36
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define double @rand_dbl_bounded(double %0, double %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 double
br i1 %5, label %12, label %8
8: ; preds = %2
%9 = load i64, i64* @RAND_MAX
%10 = sitofp i64 %9 to double
%11 = fdiv double %7, %10
br label %14
12: ; preds = %2
%13 = tail call double @sin(double %7)
br label %14
14: ; preds = %12, %8
%15 = phi double [ %13, %12 ], [ %11, %8 ]
%16 = fsub double %1, %0
%17 = tail call double @llvm.fmuladd.f64(double %15, double %16, double %0)
ret double %17
}