#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 */
int /*<<< orphan*/ assert(int);
int ceil(double);
int floor(double);
double generate_rand_zero_one(unsigned int *);
int generate_int_range(unsigned int *seed_p, int min, int max) {
  double rand_zero_one = generate_rand_zero_one(seed_p);
  double tmp_result = rand_zero_one * (max - min);
  assert(min <= max);
  if (tmp_result - floor(tmp_result) < ceil(tmp_result) - tmp_result)
    tmp_result = floor(tmp_result) + min;
  else
    tmp_result = ceil(tmp_result) + min;
  return ((int)tmp_result);
}


x86 assembly (clang, -O0):
<generate_int_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <generate_rand_zero_one@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <floor@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  -0x28(%rbp),%xmm1
cvtsi2sd %eax,%xmm0
subsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ee <generate_int_range+0xae>
movsd  -0x20(%rbp),%xmm0
call   1060 <floor@plt>
add    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1204 <generate_int_range+0xc4>
movsd  -0x20(%rbp),%xmm0
call   1030 <ceil@plt>
add    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_int_range>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
call   1040 <generate_rand_zero_one@plt>
xor    %edi,%edi
sub    %ebx,%ebp
cvtsi2sd %ebp,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
setge  %dil
call   1050 <assert@plt>
movsd  0x8(%rsp),%xmm0
call   1060 <floor@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
call   1030 <ceil@plt>
movsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
subsd  %xmm0,%xmm1
ucomisd 0x10(%rsp),%xmm1
jbe    11b5 <generate_int_range+0x75>
call   1060 <floor@plt>
jmp    11ba <generate_int_range+0x7a>
call   1030 <ceil@plt>
add    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @generate_int_range(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32*, i32** %4
%10 = call double @generate_rand_zero_one(i32* %9)
store double %10, double* %7
%11 = load double, double* %7
%12 = load i32, i32* %6
%13 = load i32, i32* %5
%14 = sub nsw i32 %12, %13
%15 = sitofp i32 %14 to double
%16 = fmul double %11, %15
store double %16, double* %8
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp sle i32 %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load double, double* %8
%23 = load double, double* %8
%24 = call i32 @floor(double %23)
%25 = sitofp i32 %24 to double
%26 = fsub double %22, %25
%27 = load double, double* %8
%28 = call i32 @ceil(double %27)
%29 = sitofp i32 %28 to double
%30 = load double, double* %8
%31 = fsub double %29, %30
%32 = fcmp olt double %26, %31
br i1 %32, label %33, label %39
33: ; preds = %3
%34 = load double, double* %8
%35 = call i32 @floor(double %34)
%36 = load i32, i32* %5
%37 = add nsw i32 %35, %36
%38 = sitofp i32 %37 to double
store double %38, double* %8
br label %45
39: ; preds = %3
%40 = load double, double* %8
%41 = call i32 @ceil(double %40)
%42 = load i32, i32* %5
%43 = add nsw i32 %41, %42
%44 = sitofp i32 %43 to double
store double %44, double* %8
br label %45
45: ; preds = %39, %33
%46 = load double, double* %8
%47 = fptosi double %46 to i32
ret i32 %47
}

LLVM IR (-O2):
define i32 @generate_int_range(i32* %0, i32 %1, i32 %2) {
%4 = tail call double @generate_rand_zero_one(i32* %0)
%5 = sub nsw i32 %2, %1
%6 = sitofp i32 %5 to double
%7 = fmul double %4, %6
%8 = icmp sge i32 %2, %1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @floor(double %7)
%12 = sitofp i32 %11 to double
%13 = fsub double %7, %12
%14 = tail call i32 @ceil(double %7)
%15 = sitofp i32 %14 to double
%16 = fsub double %15, %7
%17 = fcmp olt double %13, %16
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = tail call i32 @floor(double %7)
br label %22
20: ; preds = %3
%21 = tail call i32 @ceil(double %7)
br label %22
22: ; preds = %20, %18
%23 = phi i32 [ %19, %18 ], [ %21, %20 ]
%24 = add nsw i32 %23, %1
ret i32 %24
}