#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_MOD;
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_MOD, sock, &event) == 0)
    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    0x2e60(%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    122c <main+0xdc>
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    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1030 <epoll_ctl@plt>
cmp    $0x0,%rax
jne    1220 <main+0xd0>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122c <main+0xdc>
mov    0x2d71(%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    0x2e6a(%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    0x2e25(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rcx
mov    %eax,%edi
mov    %ebx,%edx
call   1030 <epoll_ctl@plt>
test   %rax,%rax
je     11e9 <main+0x99>
mov    0x2dd9(%rip),%rax
jmp    11f0 <main+0xa0>
mov    0x2df8(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe21(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2db0(%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_MOD = global i32 0
@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 %34
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_MOD
%27 = load i32, i32* %2
%28 = call i64 @epoll_ctl(i32 %25, i32 %26, i32 %27, %struct.epoll_event* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %16
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %1
br label %34
32: ; preds = %16
%33 = load i32, i32* @EXIT_SUCCESS
store i32 %33, i32* %1
br label %34
34: ; preds = %32, %30, %10
%35 = load i32, i32* %1
ret i32 %35
}

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_MOD = global i32 0
@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 %27
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_MOD
%22 = call i64 @epoll_ctl(i32 %14, i32 %21, i32 %5, %struct.epoll_event* %1)
%23 = icmp eq i64 %22, 0
%24 = load i32, i32* @EXIT_FAILURE
%25 = load i32, i32* @EXIT_SUCCESS
%26 = select i1 %23, i32 %24, i32 %25
br label %27
27: ; preds = %13, %7
%28 = phi i32 [ %12, %7 ], [ %26, %13 ]
ret i32 %28
}