#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 timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int rand();
int waitThinkTime(int minThinkTimeMS, int maxThinkTimeMS) {
  struct timespec waitPeriod;
  int randomWaitTimeMS;
  randomWaitTimeMS =
      minThinkTimeMS + (rand() % (1 + maxThinkTimeMS - minThinkTimeMS));
  waitPeriod.tv_sec = randomWaitTimeMS / 1000;
  waitPeriod.tv_nsec = ((int)randomWaitTimeMS % 1000) * 1000000;
  nanosleep(&waitPeriod, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<waitThinkTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    -0x4(%rbp),%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0xf4240,%edx,%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitThinkTime>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <rand@plt>
sub    %ebp,%ebx
add    $0x1,%ebx
cltd
idiv   %ebx
add    %ebp,%edx
movslq %edx,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rsp)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0xf4240,%eax,%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define i32 @waitThinkTime(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i32 (...) @rand()
%9 = load i32, i32* %4
%10 = add nsw i32 1, %9
%11 = load i32, i32* %3
%12 = sub nsw i32 %10, %11
%13 = srem i32 %8, %12
%14 = add nsw i32 %7, %13
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = sdiv i32 %15, 1000
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %6
%19 = srem i32 %18, 1000
%20 = mul nsw i32 %19, 1000000
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
store i32 %20, i32* %21
%22 = call i32 @nanosleep(%struct.timespec* %5, i32* null)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define i32 @waitThinkTime(i32 %0, i32 %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = tail call i32 (...) @rand()
%6 = sub i32 1, %0
%7 = add i32 %6, %1
%8 = srem i32 %5, %7
%9 = add nsw i32 %8, %0
%10 = sdiv i32 %9, 1000
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 %10, i32* %11
%12 = srem i32 %9, 1000
%13 = mul nsw i32 %12, 1000000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
ret i32 0
}