#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_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void us_delay(unsigned int usecs) {
  int rv;
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = usecs;
  do {
    rv = select(1, NULL, NULL, NULL, &tv);
  } while ((rv == -1) && (errno == EINTR));
}


x86 assembly (clang, -O0):
<us_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jne    116d <us_delay+0x5d>
mov    0x2e86(%rip),%rax
mov    (%rax),%rax
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1129 <us_delay+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<us_delay>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    %edi,(%rsp)
mov    %rsp,%r15
mov    0x2eb1(%rip),%r14
mov    0x2ea2(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1030 <select@plt>
cmp    $0xffffffff,%eax
jne    1160 <us_delay+0x50>
mov    (%rbx),%rax
cmp    %rax,(%r14)
je     1140 <us_delay+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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