#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_nsec;
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ memset(struct timespec *, int /*<<< orphan*/, int);
int nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ perror(char *);
int rand();
void delay(int r, int m) {
  struct timespec nSleepTime;
  memset(&nSleepTime, 0, sizeof(struct timespec));
  int t = rand() % (r - m) + m;
  nSleepTime.tv_nsec = t % (1000000000);
  nSleepTime.tv_sec = t / (1000000000);
  {{if ((nanosleep(&nSleepTime, &nSleepTime)) == -1){perror("nanosleep");
}
}
}
;
}


x86 assembly (clang, -O0):
<delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x4(%rbp),%ecx
sub    -0x8(%rbp),%ecx
cltd
idiv   %ecx
add    -0x8(%rbp),%edx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rsi
mov    %rsi,%rdi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    11b1 <delay+0x71>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delay>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
xor    %eax,%eax
call   1060 <rand@plt>
sub    %ebp,%ebx
cltd
idiv   %ebx
add    %ebp,%edx
movslq %edx,%rax
imul   $0x44b82fa1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x3c,%rcx
add    %edx,%ecx
imul   $0x3b9aca00,%ecx,%edx
sub    %edx,%eax
mov    %eax,0x8(%rsp)
mov    %ecx,0xc(%rsp)
mov    %r14,%rdi
mov    %r14,%rsi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
je     11ae <delay+0x6e>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
jmp    11a5 <delay+0x65>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [10 x i8] c"nanosleep\00"
define void @delay(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 = call i32 @memset(%struct.timespec* %5, i32 0, i32 8)
%8 = call i32 (...) @rand()
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = sub nsw i32 %9, %10
%12 = srem i32 %8, %11
%13 = load i32, i32* %4
%14 = add nsw i32 %12, %13
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = srem i32 %15, 1000000000
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %6
%19 = sdiv i32 %18, 1000000000
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
store i32 %19, i32* %20
%21 = call i32 @nanosleep(%struct.timespec* %5, %struct.timespec* %5)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %2
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [10 x i8] c"nanosleep\00"
define void @delay(i32 %0, i32 %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = call i32 @memset(%struct.timespec* %3, i32 0, i32 8)
%6 = call i32 (...) @rand()
%7 = sub nsw i32 %0, %1
%8 = srem i32 %6, %7
%9 = add nsw i32 %8, %1
%10 = srem i32 %9, 1000000000
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 %10, i32* %11
%12 = sdiv i32 %9, 1000000000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @nanosleep(%struct.timespec* %3, %struct.timespec* %3)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
ret void
}