#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 {
  unsigned int tv_sec;
  unsigned int tv_usec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void ACL_Delay(unsigned int delay) {
  struct timeval tv;
  int rv = 1;
  tv.tv_sec = delay / 1000000;
  tv.tv_usec = (delay % 1000000);
  errno = EINTR;
  while (rv != 0 && (errno == EINTR)) {
    errno = 0;
    rv = select(0, NULL, NULL, NULL, &tv);
  }
}


x86 assembly (clang, -O0):
<ACL_Delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0xc(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%rcx
mov    0x2e8f(%rip),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
je     117d <ACL_Delay+0x6d>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    118d <ACL_Delay+0x7d>
jmp    11b8 <ACL_Delay+0xa8>
mov    0x2e4c(%rip),%rax
movq   $0x0,(%rax)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
mov    %eax,-0x14(%rbp)
jmp    1154 <ACL_Delay+0x44>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ACL_Delay>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%eax
imul   $0x431bde83,%rax,%rax
shr    $0x32,%rax
mov    %eax,0x8(%rsp)
imul   $0xf4240,%eax,%eax
sub    %eax,%edi
mov    %edi,0xc(%rsp)
mov    0x2ea3(%rip),%rbx
lea    0x8(%rsp),%r14
mov    0x2e8f(%rip),%r15
nopl   0x0(%rax)
movq   $0x0,(%rbx)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1030 <select@plt>
test   %eax,%eax
je     1173 <ACL_Delay+0x63>
mov    (%r15),%rax
cmp    %rax,(%rbx)
je     1150 <ACL_Delay+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@EINTR = global i64 0
@errno = global i64 0
define void @ACL_Delay(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %4
%5 = load i32, i32* %2
%6 = udiv i32 %5, 1000000
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* %2
%9 = urem i32 %8, 1000000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i64, i64* @EINTR
store i64 %11, i64* @errno
br label %12
12: ; preds = %21, %1
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %23
21: ; preds = %19
store i64 0, i64* @errno
%22 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
store i32 %22, i32* %4
br label %12
23: ; preds = %19
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@EINTR = global i64 0
@errno = global i64 0
define void @ACL_Delay(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = udiv i32 %0, 1000000
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %4, i32* %5
%6 = urem i32 %0, 1000000
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %6, i32* %7
br label %8
8: ; preds = %1, %8
store i64 0, i64* @errno
%9 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
%10 = icmp ne i32 %9, 0
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %8, label %15
15: ; preds = %8
ret void
}