#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;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int pipefd[2];
  if (pipe(pipefd) == -1) {
    perror("pipe");
    exit(1);
  }
  int fd = open("/dev/null", O_RDONLY);
  struct pollfd pfd[1];
  pfd[0].fd = pipefd[0];
  pfd[0].events = POLLIN;
  int rc = poll(pfd, 1, -1);
  printf("ERROR:  rc = %d; errno = %d\n", rc, errno);
  close(fd);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11a7 <main+0x37>
lea    0xe68(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe4e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1060 <poll@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x7a>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%eax
mov    %eax,(%rsp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1060 <poll@plt>
mov    0x2e08(%rip),%rcx
mov    (%rcx),%edx
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe0f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@.str = [5 x i8] c"pipe\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
@POLLIN = global i32 0
@.str.2 = [29 x i8] c"ERROR: rc = %d; errno = %d\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [1 x %struct.pollfd]
%5 = alloca i32
store i32 0, i32* %1
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %3
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%18 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* @POLLIN
%20 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%21 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %20, i32 0, i32 1
store i32 %19, i32* %21
%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 -1)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = load i32, i32* @errno
%26 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32, i32* %3
%28 = call i32 @close(i32 %27)
ret i32 1
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@.str = [5 x i8] c"pipe\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
@POLLIN = global i32 0
@.str.2 = [29 x i8] c"ERROR: rc = %d; errno = %d\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [1 x %struct.pollfd]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = bitcast [1 x %struct.pollfd]* %2 to i8*
%14 = load i32, i32* %4
%15 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0
%16 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* @POLLIN
%18 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0, i32 1
store i32 %17, i32* %18
%19 = call i32 @poll(%struct.pollfd* %15, i32 1, i32 -1)
%20 = load i32, i32* @errno
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
%22 = call i32 @close(i32 %12)
ret i32 1
}