#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 */
struct timeval {
  int tv_usec;
  int tv_sec;
};

/* Variables and functions */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
int random_int(int imin, int imax) {
  struct timeval t1;
  gettimeofday(&t1, NULL);
  srand(t1.tv_usec * t1.tv_sec);
  int a = imin, b = imax;
  int val = a + (b - a) * (double)rand() / (double)RAND_MAX + 0.5;
  return val;
}


x86 assembly (clang, -O0):
<random_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%edi
imul   -0xc(%rbp),%edi
call   1040 <srand@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm2
mulsd  %xmm2,%xmm1
mov    0x2e4b(%rip),%rax
cvtsi2sdq (%rax),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  0xe4e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_int>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x4(%rsp),%edi
imul   (%rsp),%edi
call   1040 <srand@plt>
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x10(%rsp)
sub    %ebp,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0x8(%rsp),%xmm0
mov    0x2e62(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  0x10(%rsp),%xmm0
addsd  0xe63(%rip),%xmm0
cvttsd2si %xmm0,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@RAND_MAX = global i64 0
define i32 @random_int(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%13 = load i32, i32* %12
%14 = mul nsw i32 %11, %13
%15 = call i32 @srand(i32 %14)
%16 = load i32, i32* %3
store i32 %16, i32* %6
%17 = load i32, i32* %4
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = sitofp i32 %18 to double
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = sub nsw i32 %20, %21
%23 = sitofp i32 %22 to double
%24 = call i64 (...) @rand()
%25 = sitofp i64 %24 to double
%26 = fmul double %23, %25
%27 = load i64, i64* @RAND_MAX
%28 = sitofp i64 %27 to double
%29 = fdiv double %26, %28
%30 = fadd double %19, %29
%31 = fadd double %30, 5.000000e-01
%32 = fptosi double %31 to i32
store i32 %32, i32* %8
%33 = load i32, i32* %8
ret i32 %33
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@RAND_MAX = global i64 0
define i32 @random_int(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, %7
%11 = tail call i32 @srand(i32 %10)
%12 = sitofp i32 %0 to double
%13 = sub nsw i32 %1, %0
%14 = sitofp i32 %13 to double
%15 = tail call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = fmul double %14, %16
%18 = load i64, i64* @RAND_MAX
%19 = sitofp i64 %18 to double
%20 = fdiv double %17, %19
%21 = fadd double %20, %12
%22 = fadd double %21, 5.000000e-01
%23 = fptosi double %22 to i32
ret i32 %23
}