#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 {
  int tv_sec;
  int tv_usec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ fatal(char *, int);
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
void delay(int n) {
  struct timeval tdelay;
  if (n <= 0 || n > 10000)
    fatal("unreasonable delay period (%d)", n);
  tdelay.tv_sec = n / 1000;
  tdelay.tv_usec = n * 1000 % 1000000;
  (void)select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tdelay);
}


x86 assembly (clang, -O0):
<delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1142 <delay+0x22>
cmpl   $0x2710,-0x4(%rbp)
jle    1151 <delay+0x31>
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
call   1040 <fatal@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
imul   $0x3e8,-0x4(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delay>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    -0x2711(%rbx),%eax
cmp    $0xffffd8ef,%eax
ja     1142 <delay+0x22>
lea    0xec5(%rip),%rdi
mov    %ebx,%esi
call   1040 <fatal@plt>
movslq %ebx,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,0x8(%rsp)
imul   $0x3e8,%ebx,%eax
cltq
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <select@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [31 x i8] c"unreasonable delay period (%d)\00"
define void @delay(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sle i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 10000
br i1 %8, label %9, label %12
9: ; preds = %6, %1
%10 = load i32, i32* %2
%11 = call i32 @fatal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %6
%13 = load i32, i32* %2
%14 = sdiv i32 %13, 1000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* %2
%17 = mul nsw i32 %16, 1000
%18 = srem i32 %17, 1000000
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %18, i32* %19
%20 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [31 x i8] c"unreasonable delay period (%d)\00"
define void @delay(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = add i32 %0, -10001
%5 = icmp ult i32 %4, -10000
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @fatal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %8
8: ; preds = %1, %6
%9 = sdiv i32 %0, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %9, i32* %10
%11 = mul nsw i32 %0, 1000
%12 = srem i32 %11, 1000000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
ret void
}