#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 *);
scalar_t__ 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, 2, 0) < 0) {
    fprintf(stderr, "epoll_wait() failed: %s\n.", strerror(errno));
    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    12c2 <main+0x162>
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    12c2 <main+0x162>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <epoll_wait@plt>
cmp    $0x0,%rax
jge    12b6 <main+0x156>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xd8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c2 <main+0x162>
mov    0x2cdb(%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    $0x2,%edx
xor    %ecx,%ecx
call   1050 <epoll_wait@plt>
test   %rax,%rax
js     122c <main+0xcc>
mov    0x2dae(%rip),%rax
jmp    125b <main+0xfb>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ebx
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xdf6(%rip),%rsi
jmp    124a <main+0xea>
mov    0x2dad(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xdec(%rip),%rsi
jmp    124a <main+0xea>
mov    0x2d8d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xde5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2d45(%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"
@.str.2 = [26 x i8] c"epoll_wait() 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 %50
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 %50
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 i64 @epoll_wait(i32 %38, %struct.epoll_event* %39, i32 2, i32 0)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %1
br label %50
48: ; preds = %37
%49 = load i32, i32* @EXIT_SUCCESS
store i32 %49, i32* %1
br label %50
50: ; preds = %48, %42, %31, %11
%51 = load i32, i32* %1
ret i32 %51
}

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"
@.str.2 = [26 x i8] c"epoll_wait() 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 %46
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 %44
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 i64 @epoll_wait(i32 %15, %struct.epoll_event* %33, i32 2, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %31
%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 ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %31, %36
%42 = phi i32* [ @EXIT_FAILURE, %36 ], [ @EXIT_SUCCESS, %31 ]
%43 = load i32, i32* %42
br label %44
44: ; preds = %41, %25
%45 = phi i32 [ %30, %25 ], [ %43, %41 ]
br label %46
46: ; preds = %44, %8
%47 = phi i32 [ %13, %8 ], [ %45, %44 ]
ret i32 %47
}