#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 */
typedef scalar_t__ ub;

/* Variables and functions */
double RAND_MAX;
int /*<<< orphan*/ assert(int);
float rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int random_chooser(int arr[], int lb, int ub) {
  static int first_shoot = 1;
  assert(arr != NULL && lb <= ub);
  if (lb >= ub)
    return -1;
  if (first_shoot) {
    first_shoot = 0;
    srand((unsigned)time(NULL));
  }
  return (((int)((float)((ub) - (lb)) * rand() / (RAND_MAX + 1.0))) + (lb));
}


x86 assembly (clang, -O0):
<random_chooser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     116e <random_chooser+0x2e>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1193 <random_chooser+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <random_chooser+0xc1>
cmpl   $0x0,0x2ea6(%rip)
je     11ba <random_chooser+0x7a>
movl   $0x0,0x2e96(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
movaps %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe18(%rip),%xmm1
mov    0x2df9(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_chooser>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
test   %rdi,%rdi
setne  %al
cmp    %esi,%edx
setge  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    $0xffffffff,%eax
sub    %ebx,%ebp
jle    11bb <random_chooser+0x7b>
cmpb   $0x0,0x2edc(%rip)
jne    1183 <random_chooser+0x43>
movb   $0x1,0x2ed3(%rip)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
mulss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x2e43(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xe4f(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@random_chooser.first_shoot = internal global i32 1
@RAND_MAX = global double 0.000000e+00
define i32 @random_chooser(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = icmp sle i32 %11, %12
br label %14
14: ; preds = %10, %3
%15 = phi i1 [ false, %3 ], [ %13, %10 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %4
br label %43
22: ; preds = %14
%23 = load i32, i32* @random_chooser.first_shoot
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
store i32 0, i32* @random_chooser.first_shoot
%26 = call i64 @time(i32* null)
%27 = trunc i64 %26 to i32
%28 = call i32 @srand(i32 %27)
br label %29
29: ; preds = %25, %22
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = sub nsw i32 %30, %31
%33 = sitofp i32 %32 to float
%34 = call float (...) @rand()
%35 = fmul float %33, %34
%36 = fpext float %35 to double
%37 = load double, double* @RAND_MAX
%38 = fadd double %37, 1.000000e+00
%39 = fdiv double %36, %38
%40 = fptosi double %39 to i32
%41 = load i32, i32* %6
%42 = add nsw i32 %40, %41
store i32 %42, i32* %4
br label %43
43: ; preds = %29, %21
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@random_chooser.first_shoot = internal unnamed_addr global i1 false
@RAND_MAX = global double 0.000000e+00
define i32 @random_chooser(i32* readnone %0, i32 %1, i32 %2) {
%4 = icmp ne i32* %0, null
%5 = icmp sge i32 %2, %1
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp sgt i32 %2, %1
br i1 %9, label %10, label %27
10: ; preds = %3
%11 = load i1, i1* @random_chooser.first_shoot
br i1 %11, label %16, label %12
12: ; preds = %10
store i1 true, i1* @random_chooser.first_shoot
%13 = tail call i64 @time(i32* null)
%14 = trunc i64 %13 to i32
%15 = tail call i32 @srand(i32 %14)
br label %16
16: ; preds = %12, %10
%17 = sub nsw i32 %2, %1
%18 = sitofp i32 %17 to float
%19 = tail call float (...) @rand()
%20 = fmul float %19, %18
%21 = fpext float %20 to double
%22 = load double, double* @RAND_MAX
%23 = fadd double %22, 1.000000e+00
%24 = fdiv double %21, %23
%25 = fptosi double %24 to i32
%26 = add nsw i32 %25, %1
br label %27
27: ; preds = %3, %16
%28 = phi i32 [ %26, %16 ], [ -1, %3 ]
ret i32 %28
}