#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 {
  long tv_sec;
  long tv_usec;
};

/* Variables and functions */
double RAND_MAX;
float rand();
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
void randsleep(float ms, unsigned int mult) {
  static struct timeval tv;
  long i;
  i = (1 + (int)(ms * rand() / (RAND_MAX + 1.0))) * mult;
  if (i > 999999L) {
    tv.tv_sec = i / 1000000;
    tv.tv_usec = i % 1000000;
  } else
    tv.tv_usec = i;
  select(0, NULL, NULL, NULL, &tv);
  return;
}


x86 assembly (clang, -O0):
<randsleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movaps %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea7(%rip),%xmm1
mov    0x2e88(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
imul   -0x8(%rbp),%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
cmpq   $0xf423f,-0x10(%rbp)
jle    11b6 <randsleep+0x96>
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,0x2e9c(%rip)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rdx,0x2e8f(%rip)
jmp    11c1 <randsleep+0xa1>
mov    -0x10(%rbp),%rax
mov    %rax,0x2e7f(%rip)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    0x2e6a(%rip),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randsleep>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
mulss  0xc(%rsp),%xmm0
mov    0x2ea7(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xeb3(%rip),%xmm1
cvtss2sd %xmm0,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
imul   %ebx,%eax
cmp    $0xf4240,%eax
jb     1182 <randsleep+0x62>
mov    %eax,%ecx
imul   $0x431bde83,%rcx,%rcx
shr    $0x32,%rcx
mov    %rcx,0x2ebe(%rip)
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,%eax
mov    %rax,0x2eb5(%rip)
lea    0x2ea6(%rip),%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
add    $0x10,%rsp
pop    %rbx
jmp    1030 <select@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@randsleep.tv = internal global %struct.timeval zeroinitializer
@RAND_MAX = global double 0.000000e+00
define void @randsleep(float %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca i64
store float %0, float* %3
store i32 %1, i32* %4
%6 = load float, float* %3
%7 = call float (...) @rand()
%8 = fmul float %6, %7
%9 = fpext float %8 to double
%10 = load double, double* @RAND_MAX
%11 = fadd double %10, 1.000000e+00
%12 = fdiv double %9, %11
%13 = fptosi double %12 to i32
%14 = add nsw i32 1, %13
%15 = load i32, i32* %4
%16 = mul i32 %14, %15
%17 = zext i32 %16 to i64
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = icmp sgt i64 %18, 999999
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i64, i64* %5
%22 = sdiv i64 %21, 1000000
store i64 %22, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @randsleep.tv, i32 0, i32 0)
%23 = load i64, i64* %5
%24 = srem i64 %23, 1000000
store i64 %24, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @randsleep.tv, i32 0, i32 1)
br label %27
25: ; preds = %2
%26 = load i64, i64* %5
store i64 %26, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @randsleep.tv, i32 0, i32 1)
br label %27
27: ; preds = %25, %20
%28 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* @randsleep.tv)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@randsleep.tv = internal global %struct.timeval zeroinitializer
@RAND_MAX = global double 0.000000e+00
define void @randsleep(float %0, i32 %1) {
%3 = tail call float (...) @rand()
%4 = fmul float %3, %0
%5 = fpext float %4 to double
%6 = load double, double* @RAND_MAX
%7 = fadd double %6, 1.000000e+00
%8 = fdiv double %5, %7
%9 = fptosi double %8 to i32
%10 = add nsw i32 %9, 1
%11 = mul i32 %10, %1
%12 = icmp ugt i32 %11, 999999
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = udiv i32 %11, 1000000
%15 = zext i32 %14 to i64
store i64 %15, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @randsleep.tv, i64 0, i32 0)
%16 = urem i32 %11, 1000000
br label %17
17: ; preds = %2, %13
%18 = phi i32 [ %16, %13 ], [ %11, %2 ]
%19 = zext i32 %18 to i64
store i64 %19, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @randsleep.tv, i64 0, i32 1)
%20 = tail call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* @randsleep.tv)
ret void
}