#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 /*<<< 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);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11c8 <main+0x78>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <main+0x108>
xor    %edi,%edi
call   1060 <epoll_create1@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    0x2dc8(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1030 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    124c <main+0xfc>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xde0(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <main+0x108>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11c1 <main+0x71>
mov    %eax,%ebx
xor    %edi,%edi
call   1060 <epoll_create1@plt>
mov    0x2e57(%rip),%rcx
mov    0x2e20(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %ebx,0xc(%rsp)
mov    %edx,0x8(%rsp)
mov    0x2e35(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rcx
mov    %eax,%edi
mov    %ebx,%edx
call   1030 <epoll_ctl@plt>
test   %rax,%rax
js     11e1 <main+0x91>
mov    0x2dd9(%rip),%rax
jmp    1210 <main+0xc0>
mov    0x2df8(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe21(%rip),%rsi
jmp    11ff <main+0xaf>
mov    0x2dd8(%rip),%rax
mov    (%rax),%ebx
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe17(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
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
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 %16
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %1
br label %38
16: ; preds = %0
%17 = call i32 @epoll_create1(i32 0)
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* @EPOLLIN
%22 = load i32, i32* @EPOLLOUT
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %3
%26 = load i32, i32* @EPOLL_CTL_ADD
%27 = load i32, i32* %2
%28 = call i64 @epoll_ctl(i32 %25, i32 %26, i32 %27, %struct.epoll_event* %4)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %16
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %1
br label %38
36: ; preds = %16
%37 = load i32, i32* @EXIT_SUCCESS
store i32 %37, i32* %1
br label %38
38: ; preds = %36, %30, %10
%39 = load i32, i32* %1
ret i32 %39
}

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 = 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 %13
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
br label %32
13: ; preds = %0
%14 = tail call i32 @epoll_create1(i32 0)
%15 = bitcast %struct.epoll_event* %1 to i8*
%16 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 1, i32 0
store i32 %5, i32* %16
%17 = load i32, i32* @EPOLLIN
%18 = load i32, i32* @EPOLLOUT
%19 = or i32 %18, %17
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @EPOLL_CTL_ADD
%22 = call i64 @epoll_ctl(i32 %14, i32 %21, i32 %5, %struct.epoll_event* %1)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %13
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %13, %24
%30 = phi i32* [ @EXIT_FAILURE, %24 ], [ @EXIT_SUCCESS, %13 ]
%31 = load i32, i32* %30
br label %32
32: ; preds = %29, %7
%33 = phi i32 [ %12, %7 ], [ %31, %29 ]
ret i32 %33
}