#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 / 1000;
  tv.tv_usec = (delay % 1000) * 1000;
  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    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%rcx
mov    0x2e89(%rip),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
je     1183 <ACL_Delay+0x73>
mov    0x2e70(%rip),%rax
mov    (%rax),%rax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1193 <ACL_Delay+0x83>
jmp    11be <ACL_Delay+0xae>
mov    0x2e46(%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    115a <ACL_Delay+0x4a>
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   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %eax,0x8(%rsp)
imul   $0x3e8,%eax,%eax
sub    %eax,%edi
imul   $0x3e8,%edi,%eax
mov    %eax,0xc(%rsp)
mov    0x2e9d(%rip),%rbx
lea    0x8(%rsp),%r14
mov    0x2e89(%rip),%r15
nop
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, 1000
%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, 1000
%10 = mul i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %10, i32* %11
%12 = load i64, i64* @EINTR
store i64 %12, i64* @errno
br label %13
13: ; preds = %22, %1
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ false, %13 ], [ %19, %16 ]
br i1 %21, label %22, label %24
22: ; preds = %20
store i64 0, i64* @errno
%23 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
store i32 %23, i32* %4
br label %13
24: ; preds = %20
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, 1000
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %4, i32* %5
%6 = urem i32 %0, 1000
%7 = mul nuw nsw i32 %6, 1000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %7, i32* %8
br label %9
9: ; preds = %1, %9
store i64 0, i64* @errno
%10 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
%11 = icmp ne i32 %10, 0
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %9, label %16
16: ; preds = %9
ret void
}