#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 /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
struct cxl_afu_h {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ cxl_afu_fd(struct cxl_afu_h *);
int /*<<< orphan*/ errno;
scalar_t__ event_cached(struct cxl_afu_h *);
int poll(struct pollfd *, int, int /*<<< orphan*/);
int cxl_event_pending(struct cxl_afu_h *afu) {
  struct pollfd fds[1] = {{cxl_afu_fd(afu), POLLIN, 0}};
  if (afu == NULL) {
    errno = EINVAL;
    return -1;
  }
  if (event_cached(afu))
    return 1;
  return poll(fds, 1, 0);
}


x86 assembly (clang, -O0):
<cxl_event_pending>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cxl_afu_fd@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <cxl_event_pending+0x54>
mov    0x2e63(%rip),%rax
mov    (%rax),%ecx
mov    0x2e62(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <cxl_event_pending+0x86>
mov    -0x10(%rbp),%rdi
call   1040 <event_cached@plt>
cmp    $0x0,%rax
je     11a3 <cxl_event_pending+0x73>
movl   $0x1,-0x4(%rbp)
jmp    11b6 <cxl_event_pending+0x86>
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <poll@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxl_event_pending>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <cxl_afu_fd@plt>
mov    %eax,(%rsp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
movl   $0x0,0x8(%rsp)
test   %rbx,%rbx
je     1180 <cxl_event_pending+0x50>
mov    %rbx,%rdi
call   1040 <event_cached@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1197 <cxl_event_pending+0x67>
mov    %rsp,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <poll@plt>
jmp    1197 <cxl_event_pending+0x67>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    0x2e48(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.cxl_afu_h = type { i32 }
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
define i32 @cxl_event_pending(%struct.cxl_afu_h* %0) {
%2 = alloca i32
%3 = alloca %struct.cxl_afu_h*
%4 = alloca [1 x %struct.pollfd]
store %struct.cxl_afu_h* %0, %struct.cxl_afu_h** %3
%5 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i32 0, i32 0
%7 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %3
%8 = call i32 @cxl_afu_fd(%struct.cxl_afu_h* %7)
store i32 %8, i32* %6
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i32 0, i32 1
%10 = load i32, i32* @POLLIN
store i32 %10, i32* %9
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i32 0, i32 2
store i32 0, i32* %11
%12 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %3
%13 = icmp eq %struct.cxl_afu_h* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i32, i32* @EINVAL
store i32 %15, i32* @errno
store i32 -1, i32* %2
br label %24
16: ; preds = %1
%17 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %3
%18 = call i64 @event_cached(%struct.cxl_afu_h* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 1, i32* %2
br label %24
21: ; preds = %16
%22 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%23 = call i32 @poll(%struct.pollfd* %22, i32 1, i32 0)
store i32 %23, i32* %2
br label %24
24: ; preds = %21, %20, %14
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.cxl_afu_h = type { i32 }
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
define i32 @cxl_event_pending(%struct.cxl_afu_h* %0) {
%2 = alloca [1 x %struct.pollfd]
%3 = bitcast [1 x %struct.pollfd]* %2 to i8*
%4 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0, i32 0
%6 = tail call i32 @cxl_afu_fd(%struct.cxl_afu_h* %0)
store i32 %6, i32* %5
%7 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0, i32 1
%8 = load i32, i32* @POLLIN
store i32 %8, i32* %7
%9 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0, i32 2
store i32 0, i32* %9
%10 = icmp eq %struct.cxl_afu_h* %0, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
br label %18
13: ; preds = %1
%14 = tail call i64 @event_cached(%struct.cxl_afu_h* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 0)
br label %18
18: ; preds = %13, %16, %11
%19 = phi i32 [ -1, %11 ], [ %17, %16 ], [ 1, %13 ]
ret i32 %19
}