#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_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int epoll_create1(int /*<<< orphan*/);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
scalar_t__ epoll_pwait(int, struct epoll_event *, int, int /*<<< orphan*/,
                       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_DGRAM, IPPROTO_UDP)) < 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_pwait(efd, events, 2, 0, NULL) < 0) {
    fprintf(stderr, "epoll_pwait() 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    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2e08(%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    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c7 <main+0x167>
xor    %edi,%edi
call   1060 <epoll_create1@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    0x2dc0(%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    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xdd0(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c7 <main+0x167>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <epoll_pwait@plt>
cmp    $0x0,%rax
jge    12bb <main+0x15b>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xd8a(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c7 <main+0x167>
mov    0x2cde(%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    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11ef <main+0x8f>
mov    %eax,%ebp
xor    %edi,%edi
call   1060 <epoll_create1@plt>
mov    %eax,%ebx
mov    0x2e44(%rip),%rax
mov    0x2e15(%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     120f <main+0xaf>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <epoll_pwait@plt>
test   %rax,%rax
js     122f <main+0xcf>
mov    0x2db3(%rip),%rax
jmp    125e <main+0xfe>
mov    0x2dca(%rip),%rax
mov    (%rax),%ebx
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xdf3(%rip),%rsi
jmp    124d <main+0xed>
mov    0x2daa(%rip),%rax
mov    (%rax),%ebx
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xde9(%rip),%rsi
jmp    124d <main+0xed>
mov    0x2d8a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xde2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2d4a(%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_DGRAM = global i32 0
@IPPROTO_UDP = 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 = [27 x i8] c"epoll_pwait() 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_DGRAM
%8 = load i32, i32* @IPPROTO_UDP
%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_pwait(i32 %38, %struct.epoll_event* %39, i32 2, i32 0, i32* null)
%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 ([27 x i8], [27 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_DGRAM = global i32 0
@IPPROTO_UDP = 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 = [27 x i8] c"epoll_pwait() 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_DGRAM
%5 = load i32, i32* @IPPROTO_UDP
%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_pwait(i32 %15, %struct.epoll_event* %33, i32 2, i32 0, i32* null)
%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 ([27 x i8], [27 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
}