#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;
  scalar_t__ revents;
  scalar_t__ events;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
scalar_t__ POLLERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, ...);
int poll(struct pollfd *, int, int);
void poll_err(int fd) {
  struct pollfd pfd = {0};
  int ret;
  pfd.fd = fd;
  pfd.events = 0;
  ret = poll(&pfd, 1, 100);
  if (ret == -1)
    error(1, errno, "poll");
  if (ret == 0)
    error(1, 0, "poll: timeout");
  if (pfd.revents != POLLERR)
    error(1, 0, "poll 0x%x", pfd.revents);
}


x86 assembly (clang, -O0):
<poll_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x64,%edx
call   1040 <poll@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1195 <poll_err+0x65>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe72(%rip),%rdx
mov    $0x0,%al
call   1050 <error@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    11b4 <poll_err+0x84>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe58(%rip),%rdx
mov    $0x0,%al
call   1050 <error@plt>
mov    -0x20(%rbp),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
je     11e1 <poll_err+0xb1>
mov    -0x20(%rbp),%rcx
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe39(%rip),%rdx
mov    $0x0,%al
call   1050 <error@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll_err>:
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %edi,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
call   1030 <poll@plt>
test   %eax,%eax
je     1165 <poll_err+0x45>
cmp    $0xffffffff,%eax
jne    117a <poll_err+0x5a>
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xea2(%rip),%rdx
mov    $0x1,%edi
jmp    1173 <poll_err+0x53>
lea    0xe99(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <error@plt>
mov    0x8(%rsp),%rcx
mov    0x2e62(%rip),%rax
cmp    (%rax),%rcx
je     11a0 <poll_err+0x80>
lea    0xe81(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <error@plt>
add    $0x28,%rsp
ret

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

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