#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 rand();
int /*<<< orphan*/ usleep(int);
void nap(int ms) {
  int usec = ms * 1000;
  if (usec <= 1)
    usec = 1;
  else
    usec = usec / 2 + rand() % usec;
  if (usec >= 10000000)
    usec = 990000 + rand() % 10000;
  usleep(usec);
}


x86 assembly (clang, -O0):
<nap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
imul   $0x3e8,-0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     114b <nap+0x2b>
movl   $0x1,-0x8(%rbp)
jmp    116c <nap+0x4c>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
cltd
idivl  -0x8(%rbp)
mov    -0xc(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x989680,-0x8(%rbp)
jl     1191 <nap+0x71>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
add    $0xf1b30,%edx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <usleep@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nap>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%eax
imul   $0x3e8,%edi,%ebx
mov    $0x1,%edi
cmp    $0x2,%ebx
jl     117f <nap+0x5f>
imul   $0x1f4,%eax,%ebp
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebx
mov    %edx,%edi
add    %ebp,%edi
cmp    $0x989680,%edi
jl     117f <nap+0x5f>
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0xf1b30,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <usleep@plt>

LLVM IR (-O0):
define void @nap(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = mul nsw i32 %4, 1000
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %3
br label %16
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 2
%12 = call i32 (...) @rand()
%13 = load i32, i32* %3
%14 = srem i32 %12, %13
%15 = add nsw i32 %11, %14
store i32 %15, i32* %3
br label %16
16: ; preds = %9, %8
%17 = load i32, i32* %3
%18 = icmp sge i32 %17, 10000000
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 10000
%22 = add nsw i32 990000, %21
store i32 %22, i32* %3
br label %23
23: ; preds = %19, %16
%24 = load i32, i32* %3
%25 = call i32 @usleep(i32 %24)
ret void
}

LLVM IR (-O2):
define void @nap(i32 %0) {
%2 = mul nsw i32 %0, 1000
%3 = icmp slt i32 %2, 2
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = mul nsw i32 %0, 500
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, %2
%8 = add nsw i32 %7, %5
%9 = icmp sgt i32 %8, 9999999
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 10000
%13 = add nsw i32 %12, 990000
br label %14
14: ; preds = %1, %10, %4
%15 = phi i32 [ %13, %10 ], [ %8, %4 ], [ 1, %1 ]
%16 = tail call i32 @usleep(i32 %15)
ret void
}