#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;
};
typedef int /*<<< orphan*/ pollfds;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ POLLHUP;
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ poll(struct pollfd *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int sock1, sock2;
  if ((sock1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return (EXIT_FAILURE);
  if ((sock2 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return (EXIT_FAILURE);
  struct pollfd pollfds[2];
  pollfds[0].fd = sock1;
  pollfds[0].events = POLLHUP;
  pollfds[1].fd = sock2;
  pollfds[1].events = POLLIN;
  if (poll(pollfds, sizeof(pollfds) / sizeof(struct pollfd), 1) < 0) {
    fprintf(stderr, "poll() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    118c <main+0x4c>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <main+0x113>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11c9 <main+0x89>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <main+0x113>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <poll@plt>
cmp    $0x0,%rax
jge    1247 <main+0x107>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdcf(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <main+0x113>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e8e(%rip),%r14
mov    (%r14),%edi
mov    0x2e5c(%rip),%r15
mov    (%r15),%esi
mov    0x2e72(%rip),%r12
mov    (%r12),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11f1 <main+0xb1>
mov    %eax,%ebx
mov    (%r14),%edi
mov    (%r15),%esi
mov    (%r12),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11f1 <main+0xb1>
mov    %ebx,(%rsp)
mov    0x2e56(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
mov    %eax,0x8(%rsp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %rsp,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <poll@plt>
test   %rax,%rax
js     11c9 <main+0x89>
mov    0x2dd9(%rip),%rax
jmp    11f8 <main+0xb8>
mov    0x2df0(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe19(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@POLLHUP = global i32 0
@POLLIN = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"poll() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x %struct.pollfd]
store i32 0, i32* %1
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = call i32 @socket(i32 %5, i32 %6, i32 %7)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %1
br label %44
12: ; preds = %0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = load i32, i32* @IPPROTO_TCP
%16 = call i32 @socket(i32 %13, i32 %14, i32 %15)
store i32 %16, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %1
br label %44
20: ; preds = %12
%21 = load i32, i32* %2
%22 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%23 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* @POLLHUP
%25 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%26 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %25, i32 0, i32 1
store i32 %24, i32* %26
%27 = load i32, i32* %3
%28 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1
%29 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* @POLLIN
%31 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1
%32 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %31, i32 0, i32 1
store i32 %30, i32* %32
%33 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%34 = call i64 @poll(%struct.pollfd* %33, i32 2, i32 1)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %20
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
store i32 %41, i32* %1
br label %44
42: ; preds = %20
%43 = load i32, i32* @EXIT_SUCCESS
store i32 %43, i32* %1
br label %44
44: ; preds = %42, %36, %18, %10
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@POLLHUP = global i32 0
@POLLIN = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"poll() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [2 x %struct.pollfd]
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_STREAM
%4 = load i32, i32* @IPPROTO_TCP
%5 = tail call i32 @socket(i32 %2, i32 %3, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i32, i32* @EXIT_FAILURE
br label %36
9: ; preds = %0
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = load i32, i32* @IPPROTO_TCP
%13 = tail call i32 @socket(i32 %10, i32 %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = load i32, i32* @EXIT_FAILURE
br label %36
17: ; preds = %9
%18 = bitcast [2 x %struct.pollfd]* %1 to i8*
%19 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0
%20 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 0
store i32 %5, i32* %20
%21 = load i32, i32* @POLLHUP
%22 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 0
store i32 %13, i32* %23
%24 = load i32, i32* @POLLIN
%25 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 1
store i32 %24, i32* %25
%26 = call i64 @poll(%struct.pollfd* %19, i32 2, i32 1)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %17
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %17, %28
%34 = phi i32* [ @EXIT_FAILURE, %28 ], [ @EXIT_SUCCESS, %17 ]
%35 = load i32, i32* %34
br label %36
36: ; preds = %33, %15, %7
%37 = phi i32 [ %8, %7 ], [ %16, %15 ], [ %35, %33 ]
ret i32 %37
}