#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 events;
  int revents;
};

/* Variables and functions */
int POLLERR;
int POLLHUP;
int POLLIN;
int POLLNVAL;
int POLLOUT;
int poll(struct pollfd *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int ipc_check_closed(int socket) {
  int r;
  struct pollfd test;
  test.fd = socket;
  test.events = POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL;
  r = poll(&test, 1, 0);
  printf("revents=%08x\n", test.revents);
  return 0;
}


x86 assembly (clang, -O0):
<ipc_check_closed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    0x2eb7(%rip),%rcx
or     (%rcx),%eax
mov    0x2e8e(%rip),%rcx
or     (%rcx),%eax
mov    0x2e8d(%rip),%rcx
or     (%rcx),%eax
mov    0x2e74(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <poll@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipc_check_closed>:
sub    $0x18,%rsp
mov    0x2e9d(%rip),%rax
mov    0x2ec6(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e9b(%rip),%rax
or     (%rax),%ecx
mov    %edi,0x8(%rsp)
mov    0x2e96(%rip),%rax
or     (%rax),%ecx
mov    0x2e7d(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <poll@plt>
mov    0x10(%rsp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@POLLERR = global i32 0
@POLLHUP = global i32 0
@POLLNVAL = global i32 0
@.str = [14 x i8] c"revents=%08x\0A\00"
define i32 @ipc_check_closed(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.pollfd
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* @POLLIN
%8 = load i32, i32* @POLLOUT
%9 = or i32 %7, %8
%10 = load i32, i32* @POLLERR
%11 = or i32 %9, %10
%12 = load i32, i32* @POLLHUP
%13 = or i32 %11, %12
%14 = load i32, i32* @POLLNVAL
%15 = or i32 %13, %14
%16 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i32 %15, i32* %16
%17 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 0)
store i32 %17, i32* %3
%18 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 2
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %19)
ret i32 0
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@POLLERR = global i32 0
@POLLHUP = global i32 0
@POLLNVAL = global i32 0
@.str = [14 x i8] c"revents=%08x\0A\00"
define i32 @ipc_check_closed(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 = load i32, i32* @POLLIN
%6 = load i32, i32* @POLLOUT
%7 = or i32 %6, %5
%8 = load i32, i32* @POLLERR
%9 = or i32 %7, %8
%10 = load i32, i32* @POLLHUP
%11 = or i32 %9, %10
%12 = load i32, i32* @POLLNVAL
%13 = or i32 %11, %12
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i32 %13, i32* %14
%15 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 0)
%16 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 2
%17 = load i32, i32* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %17)
ret i32 0
}