#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 fd;
  int /*<<< orphan*/ events;
};
typedef int /*<<< orphan*/ pollfd;

/* Variables and functions */
scalar_t__ EAGAIN;
int /*<<< orphan*/ POLLIN;
scalar_t__ errno;
int /*<<< orphan*/ error(int, scalar_t__, char *);
int /*<<< orphan*/ memset(struct pollfd *, int /*<<< orphan*/, int);
int poll(struct pollfd *, int, int);
void __poll(int fd) {
  struct pollfd pollfd;
  int ret;
  memset(&pollfd, 0, sizeof(pollfd));
  pollfd.events = POLLIN;
  pollfd.fd = fd;
  ret = poll(&pollfd, 1, 100);
  if (ret == -1 && errno != EAGAIN)
    error(1, errno, "poll");
}


x86 assembly (clang, -O0):
<__poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x64,%edx
call   1040 <poll@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b2 <__poll+0x82>
mov    0x2e54(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
je     11b2 <__poll+0x82>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xe53(%rip),%rdx
call   1050 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__poll>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %ebx,(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
call   1040 <poll@plt>
cmp    $0xffffffff,%eax
jne    1196 <__poll+0x66>
mov    0x2e62(%rip),%rax
mov    (%rax),%rsi
mov    0x2e48(%rip),%rax
cmp    (%rax),%rsi
je     1196 <__poll+0x66>
lea    0xe74(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [5 x i8] c"poll\00"
define void @__poll(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.pollfd
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @memset(%struct.pollfd* %3, i32 0, i32 8)
%6 = load i32, i32* @POLLIN
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* %2
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i32 0, i32 0
store i32 %8, i32* %9
%10 = call i32 @poll(%struct.pollfd* %3, i32 1, i32 100)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = load i64, i64* @errno
%15 = load i64, i64* @EAGAIN
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = call i32 @error(i32 1, i64 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %13, %1
ret void
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [5 x i8] c"poll\00"
define void @__poll(i32 %0) {
%2 = alloca %struct.pollfd
%3 = bitcast %struct.pollfd* %2 to i8*
%4 = call i32 @memset(%struct.pollfd* %2, i32 0, i32 8)
%5 = load i32, i32* @POLLIN
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 0
store i32 %0, i32* %7
%8 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 100)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp eq i64 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @error(i32 1, i64 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %10, %1
ret void
}