#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 EPOLLET;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, int, int);
void epoll_watch_fd(int epfd, int fd) {
  struct epoll_event ev;
  ev.events = EPOLLIN | EPOLLET;
  ev.data.fd = fd;
  if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
    printf("epoll_ctl(EPOLL_CTL_ADD, %d) failed: error = %d\n", fd, errno);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<epoll_watch_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    0x2e7a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x10(%rbp),%rcx
call   1040 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    119c <epoll_watch_fd+0x6c>
mov    -0x8(%rbp),%esi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epoll_watch_fd>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    0x2eaa(%rip),%rax
mov    0x2e83(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    %esi,0xc(%rsp)
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %ebx,%edx
call   1040 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     1171 <epoll_watch_fd+0x41>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [49 x i8] c"epoll_ctl(EPOLL_CTL_ADD, %d) failed: error = %d\0A\00"
@errno = global i32 0
define void @epoll_watch_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.epoll_event
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* @EPOLLIN
%7 = load i32, i32* @EPOLLET
%8 = or i32 %6, %7
%9 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i32 0, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* %4
%11 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load i32, i32* %3
%14 = load i32, i32* @EPOLL_CTL_ADD
%15 = load i32, i32* %4
%16 = call i32 @epoll_ctl(i32 %13, i32 %14, i32 %15, %struct.epoll_event* %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* %4
%20 = load i32, i32* @errno
%21 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20)
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [49 x i8] c"epoll_ctl(EPOLL_CTL_ADD, %d) failed: error = %d\0A\00"
@errno = global i32 0
define void @epoll_watch_fd(i32 %0, i32 %1) {
%3 = alloca %struct.epoll_event
%4 = bitcast %struct.epoll_event* %3 to i8*
%5 = load i32, i32* @EPOLLIN
%6 = load i32, i32* @EPOLLET
%7 = or i32 %6, %5
%8 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 0
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 1, i32 0
store i32 %1, i32* %9
%10 = load i32, i32* @EPOLL_CTL_ADD
%11 = call i32 @epoll_ctl(i32 %0, i32 %10, i32 %1, %struct.epoll_event* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %14)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
ret void
}