#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;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int select(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, struct timeval *);
void nap(int sec, int msec) {
  struct timeval tv;
  tv.tv_sec = sec;
  tv.tv_usec = msec * 1000;
  while (-1 == select(0, 0, 0, 0, &tv) && EINTR == errno)
    ;
}


x86 assembly (clang, -O0):
<nap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
imul   $0x3e8,-0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %ecx,%ecx
lea    -0x10(%rbp),%r8
mov    %ecx,%edi
mov    %ecx,%esi
mov    %ecx,%edx
call   1030 <select@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
jne    116d <nap+0x5d>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    117d <nap+0x6d>
jmp    1182 <nap+0x72>
jmp    112e <nap+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nap>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,0x8(%rsp)
imul   $0x3e8,%esi,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%r15
mov    0x2ea5(%rip),%r14
mov    0x2ea6(%rip),%rbx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1030 <select@plt>
cmp    $0xffffffff,%eax
jne    115d <nap+0x4d>
mov    (%rbx),%rax
cmp    %rax,(%r14)
je     1140 <nap+0x30>
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 @nap(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* %4
%9 = mul nsw i32 %8, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 %9, i32* %10
br label %11
11: ; preds = %20, %2
%12 = call i32 @select(i32 0, i32 0, i32 0, i32 0, %struct.timeval* %5)
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i64, i64* @EINTR
%16 = load i64, i64* @errno
%17 = icmp eq i64 %15, %16
br label %18
18: ; preds = %14, %11
%19 = phi i1 [ false, %11 ], [ %17, %14 ]
br i1 %19, label %20, label %21
20: ; preds = %18
br label %11
21: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@EINTR = global i64 0
@errno = global i64 0
define void @nap(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 %0, i32* %5
%6 = mul nsw i32 %1, 1000
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i32 %6, i32* %7
br label %8
8: ; preds = %8, %2
%9 = call i32 @select(i32 0, i32 0, i32 0, i32 0, %struct.timeval* %3)
%10 = icmp eq i32 %9, -1
%11 = load i64, i64* @EINTR
%12 = load i64, i64* @errno
%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
}