#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 */
int EAGAIN;
int EINPROGRESS;
int EINTR;
int errno;
int poll(struct pollfd *, int /*<<< orphan*/, int);
int WaitressPollLoop(struct pollfd *fds, nfds_t nfds, int timeout) {
  int pollres = -1;
  int pollerr = 0;
  do {
    pollres = poll(fds, nfds, timeout);
    pollerr = errno;
    errno = 0;
  } while (pollerr == EINTR || pollerr == EINPROGRESS || pollerr == EAGAIN);
  return pollres;
}


x86 assembly (clang, -O0):
<WaitressPollLoop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <poll@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e83(%rip),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%ecx
mov    $0x1,%al
mov    0x2e69(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     119b <WaitressPollLoop+0x8b>
mov    -0x18(%rbp),%ecx
mov    $0x1,%al
mov    0x2e6a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     119b <WaitressPollLoop+0x8b>
mov    -0x18(%rbp),%eax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1130 <WaitressPollLoop+0x20>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WaitressPollLoop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
mov    0x2ead(%rip),%rbp
mov    0x2e9e(%rip),%r12
mov    0x2eaf(%rip),%r13
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <poll@plt>
mov    0x0(%rbp),%ecx
movl   $0x0,0x0(%rbp)
cmp    (%r12),%ecx
je     1140 <WaitressPollLoop+0x30>
cmp    0x0(%r13),%ecx
je     1140 <WaitressPollLoop+0x30>
mov    0x2e55(%rip),%rdx
cmp    (%rdx),%ecx
je     1140 <WaitressPollLoop+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32 }
@errno = global i32 0
@EINTR = global i32 0
@EINPROGRESS = global i32 0
@EAGAIN = global i32 0
define i32 @WaitressPollLoop(%struct.pollfd* %0, i32 %1, i32 %2) {
%4 = alloca %struct.pollfd*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.pollfd* %0, %struct.pollfd** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %27, %3
%10 = load %struct.pollfd*, %struct.pollfd** %4
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @poll(%struct.pollfd* %10, i32 %11, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* @errno
store i32 %14, i32* %8
store i32 0, i32* @errno
br label %15
15: ; preds = %9
%16 = load i32, i32* %8
%17 = load i32, i32* @EINTR
%18 = icmp eq i32 %16, %17
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = load i32, i32* %8
%21 = load i32, i32* @EINPROGRESS
%22 = icmp eq i32 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32, i32* %8
%25 = load i32, i32* @EAGAIN
%26 = icmp eq i32 %24, %25
br label %27
27: ; preds = %23, %19, %15
%28 = phi i1 [ true, %19 ], [ true, %15 ], [ %26, %23 ]
br i1 %28, label %9, label %29
29: ; preds = %27
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
%struct.pollfd = type { i32 }
@errno = global i32 0
@EINTR = global i32 0
@EINPROGRESS = global i32 0
@EAGAIN = global i32 0
define i32 @WaitressPollLoop(%struct.pollfd* %0, i32 %1, i32 %2) {
br label %4
4: ; preds = %4, %3
%5 = tail call i32 @poll(%struct.pollfd* %0, i32 %1, i32 %2)
%6 = load i32, i32* @errno
store i32 0, i32* @errno
%7 = load i32, i32* @EINTR
%8 = icmp eq i32 %6, %7
%9 = load i32, i32* @EINPROGRESS
%10 = icmp eq i32 %6, %9
%11 = select i1 %8, i1 true, i1 %10
%12 = load i32, i32* @EAGAIN
%13 = icmp eq i32 %6, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %4, label %15
15: ; preds = %4
ret i32 %5
}