#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 unsigned long useconds_t;

/* Variables and functions */
double RAND_MAX;
double rand();
scalar_t__ usleep(unsigned long const);
long rnd_usleep(const useconds_t usecs) {
  long unsigned rnd10 = 10.0 * rand() / (RAND_MAX + 1.0) + 1;
  if (usleep(usecs * rnd10) == 0)
    return usecs * rnd10;
  else
    return -1;
}


x86 assembly (clang, -O0):
<rnd_usleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
call   1030 <rand@plt>
movsd  0xec5(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2ea2(%rip),%rax
movsd  (%rax),%xmm2
movsd  0xeb6(%rip),%xmm1
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe9b(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
imul   -0x18(%rbp),%rdi
call   1040 <usleep@plt>
cmp    $0x0,%rax
jne    11b2 <rnd_usleep+0x92>
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <rnd_usleep+0x9a>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnd_usleep>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mulsd  0xecd(%rip),%xmm0
mov    0x2eae(%rip),%rax
movsd  0xec6(%rip),%xmm1
movsd  (%rax),%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
subsd  0xeae(%rip),%xmm0
cvttsd2si %xmm0,%rdx
sar    $0x3f,%rcx
and    %rcx,%rdx
or     %rax,%rdx
imul   %rdx,%rbx
mov    %rbx,%rdi
call   1040 <usleep@plt>
neg    %rax
sbb    %rax,%rax
or     %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i64 @rnd_usleep(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = call double (...) @rand()
%6 = fmul double 1.000000e+01, %5
%7 = load double, double* @RAND_MAX
%8 = fadd double %7, 1.000000e+00
%9 = fdiv double %6, %8
%10 = fadd double %9, 1.000000e+00
%11 = fptoui double %10 to i64
store i64 %11, i64* %4
%12 = load i64, i64* %3
%13 = load i64, i64* %4
%14 = mul i64 %12, %13
%15 = call i64 @usleep(i64 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %1
%18 = load i64, i64* %3
%19 = load i64, i64* %4
%20 = mul i64 %18, %19
store i64 %20, i64* %2
br label %22
21: ; preds = %1
store i64 -1, i64* %2
br label %22
22: ; preds = %21, %17
%23 = load i64, i64* %2
ret i64 %23
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i64 @rnd_usleep(i64 %0) {
%2 = tail call double (...) @rand()
%3 = fmul double %2, 1.000000e+01
%4 = load double, double* @RAND_MAX
%5 = fadd double %4, 1.000000e+00
%6 = fdiv double %3, %5
%7 = fadd double %6, 1.000000e+00
%8 = fptoui double %7 to i64
%9 = mul i64 %8, %0
%10 = tail call i64 @usleep(i64 %9)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 %9, i64 -1
ret i64 %12
}