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

/* Variables and functions */
int POLLIN;
int POLLOUT;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *);
int main(void) {
  struct pollfd fds[2];
  int ret;
  fds[0].fd = STDIN_FILENO;
  fds[0].events = POLLIN;
  fds[1].fd = STDOUT_FILENO;
  fds[1].events = POLLOUT;
  ret = poll(fds, 2, 5 * 1000);
  if (ret == -1)
    return 1;
  else if (!ret)
    return 0;
  if (fds[0].revents * POLLOUT) {
    printf("stdout is writable\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1388,%edx
call   1040 <poll@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    118b <main+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    11cf <main+0xaf>
cmpl   $0x0,-0x24(%rbp)
jne    11a1 <main+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11cf <main+0xaf>
jmp    11a6 <main+0x86>
mov    -0x1c(%rbp),%eax
mov    0x2e48(%rip),%rcx
imul   (%rcx),%eax
cmp    $0x0,%eax
je     11c8 <main+0xa8>
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2ea6(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    %rsp,%rdi
mov    $0x2,%esi
mov    $0x1388,%edx
call   1040 <poll@plt>
cmp    $0xffffffff,%eax
je     1177 <main+0x57>
test   %eax,%eax
jne    117e <main+0x5e>
xor    %ebx,%ebx
jmp    1197 <main+0x77>
mov    $0x1,%ebx
jmp    1197 <main+0x77>
mov    (%rbx),%eax
imul   0x4(%rsp),%eax
xor    %ebx,%ebx
test   %eax,%eax
je     1197 <main+0x77>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@STDOUT_FILENO = global i32 0
@POLLOUT = global i32 0
@.str = [20 x i8] c"stdout is writable\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x %struct.pollfd]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @STDIN_FILENO
%5 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i32 0, i32 2
store i32 %4, i32* %6
%7 = load i32, i32* @POLLIN
%8 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %8, i32 0, i32 0
store i32 %7, i32* %9
%10 = load i32, i32* @STDOUT_FILENO
%11 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 1
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %11, i32 0, i32 2
store i32 %10, i32* %12
%13 = load i32, i32* @POLLOUT
%14 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 1
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %14, i32 0, i32 0
store i32 %13, i32* %15
%16 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%17 = call i32 @poll(%struct.pollfd* %16, i32 2, i32 5000)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %0
store i32 1, i32* %1
br label %36
21: ; preds = %0
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %21
store i32 0, i32* %1
br label %36
25: ; preds = %21
br label %26
26: ; preds = %25
%27 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%28 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = load i32, i32* @POLLOUT
%31 = mul nsw i32 %29, %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
store i32 0, i32* %1
br label %36
36: ; preds = %35, %24, %20
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@STDOUT_FILENO = global i32 0
@POLLOUT = global i32 0
@str = [19 x i8] c"stdout is writable\00"
define i32 @main() {
%1 = alloca [2 x %struct.pollfd]
%2 = bitcast [2 x %struct.pollfd]* %1 to i8*
%3 = load i32, i32* @STDIN_FILENO
%4 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0
%5 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 2
store i32 %3, i32* %5
%6 = load i32, i32* @POLLIN
%7 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @STDOUT_FILENO
%9 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @POLLOUT
%11 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 0
store i32 %10, i32* %11
%12 = call i32 @poll(%struct.pollfd* %4, i32 2, i32 5000)
switch i32 %12, label %14 [
i32 -1, label %22
i32 0, label %13
]
13: ; preds = %0
br label %22
14: ; preds = %0
%15 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 1
%16 = load i32, i32* %15
%17 = load i32, i32* @POLLOUT
%18 = mul nsw i32 %17, %16
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %14, %20, %0, %13
%23 = phi i32 [ 0, %13 ], [ 1, %0 ], [ 0, %20 ], [ 0, %14 ]
ret i32 %23
}