#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EPOLLIN;
int EPOLLOUT;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int epoll_create1(int /*<<< orphan*/);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int sock;
  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    fprintf(stderr, "socket() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  int efd = epoll_create1(0);
  struct epoll_event event;
  event.data.fd = sock;
  event.events = EPOLLIN | EPOLLOUT;
  if (epoll_ctl(efd, EPOLL_CTL_ADD, sock, &event) < 0) {
    fprintf(stderr, "epoll_ctl() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  struct epoll_event events[2];
  if (epoll_wait(efd, events, -1, 0) != -1)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11d8 <main+0x78>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1295 <main+0x135>
xor    %edi,%edi
call   1070 <epoll_create1@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    0x2db8(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1030 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    125c <main+0xfc>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xdd0(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1295 <main+0x135>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1050 <epoll_wait@plt>
cmp    $0xffffffff,%eax
je     1289 <main+0x129>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1295 <main+0x135>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11ec <main+0x8c>
mov    %eax,%ebp
xor    %edi,%edi
call   1070 <epoll_create1@plt>
mov    %eax,%ebx
mov    0x2e44(%rip),%rax
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ebp,0xc(%rsp)
mov    %ecx,0x8(%rsp)
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <epoll_ctl@plt>
test   %rax,%rax
js     120c <main+0xac>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1050 <epoll_wait@plt>
cmp    $0xffffffff,%eax
jne    1234 <main+0xd4>
mov    0x2dae(%rip),%rax
jmp    123b <main+0xdb>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ebx
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xdf6(%rip),%rsi
jmp    122a <main+0xca>
mov    0x2dad(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xdec(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

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

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