#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 pollfd {
  int dummy;
};
typedef int /*<<< orphan*/ nfds_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int /*<<< orphan*/, int);
int Poll(struct pollfd *client, nfds_t nfds, int timeout) {
  int nready;
  while (1) {
    nready = poll(client, nfds, timeout);
    if (nready == -1 && errno != EINTR) {
      perror("poll() error");
      exit(0);
    } else if (nready == -1 && errno == EINTR)
      continue;
    else if (nready > 0)
      return nready;
  }
}


x86 assembly (clang, -O0):
<Poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <poll@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118b <Poll+0x5b>
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
je     118b <Poll+0x5b>
lea    0xe81(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1050 <exit@plt>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b4 <Poll+0x84>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    11b4 <Poll+0x84>
jmp    1142 <Poll+0x12>
cmpl   $0x0,-0x14(%rbp)
jle    11c7 <Poll+0x97>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11cc <Poll+0x9c>
jmp    11d1 <Poll+0xa1>
jmp    1142 <Poll+0x12>

x86 assembly (clang, -O2):
<Poll>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e99(%rip),%r15
mov    0x2e8a(%rip),%r12
jmp    1159 <Poll+0x29>
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1178 <Poll+0x48>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <poll@plt>
cmp    $0xffffffff,%eax
je     1150 <Poll+0x20>
test   %eax,%eax
jle    1159 <Poll+0x29>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe81(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.pollfd = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"poll() error\00"
define i32 @Poll(%struct.pollfd* %0, i32 %1, i32 %2) {
%4 = alloca %struct.pollfd*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.pollfd* %0, %struct.pollfd** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %8
8: ; preds = %3, %29, %37
%9 = load %struct.pollfd*, %struct.pollfd** %4
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @poll(%struct.pollfd* %9, i32 %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %15, %8
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
br label %8
30: ; preds = %25, %22
%31 = load i32, i32* %7
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* %7
ret i32 %34
35: ; preds = %30
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %8
}

LLVM IR (-O2):
%struct.pollfd = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"poll() error\00"
define i32 @Poll(%struct.pollfd* %0, i32 %1, i32 %2) {
br label %4
4: ; preds = %16, %3
%5 = tail call i32 @poll(%struct.pollfd* %0, i32 %1, i32 %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %4
%15 = icmp sgt i32 %5, 0
br i1 %15, label %17, label %16
16: ; preds = %14, %7
br label %4
17: ; preds = %14
ret i32 %5
}