#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 /*<<< orphan*/ abort();
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int /*<<< orphan*/ err_exit(char *);
int to_nonblock(int);
void add_to_epoll(int epollfd, int fd) {
  int res = to_nonblock(fd);
  if (res == -1)
    abort();
  struct epoll_event event;
  event.data.fd = fd;
  event.events = EPOLLIN | EPOLLET;
  res = epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event);
  if (res == -1)
    err_exit("epoll_ctl");
}


x86 assembly (clang, -O0):
<add_to_epoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <to_nonblock@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    116a <add_to_epoll+0x2a>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    0x2e50(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1040 <epoll_ctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b6 <add_to_epoll+0x76>
lea    0xe4f(%rip),%rdi
call   1050 <err_exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_epoll>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    %esi,%edi
call   1060 <to_nonblock@plt>
cmp    $0xffffffff,%eax
je     1199 <add_to_epoll+0x59>
mov    0x2e8e(%rip),%rax
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ebx,0x4(%rsp)
mov    %ecx,(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebp,%edi
mov    %ebx,%edx
call   1040 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    1192 <add_to_epoll+0x52>
lea    0xe73(%rip),%rdi
call   1050 <err_exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@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 = [10 x i8] c"epoll_ctl\00"
define void @add_to_epoll(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.epoll_event
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @to_nonblock(i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %2
%14 = load i32, i32* %4
%15 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* @EPOLLIN
%18 = load i32, i32* @EPOLLET
%19 = or i32 %17, %18
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %3
%22 = load i32, i32* @EPOLL_CTL_ADD
%23 = load i32, i32* %4
%24 = call i32 @epoll_ctl(i32 %21, i32 %22, i32 %23, %struct.epoll_event* %6)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %13
%28 = call i32 @err_exit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %13
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 = [10 x i8] c"epoll_ctl\00"
define void @add_to_epoll(i32 %0, i32 %1) {
%3 = alloca %struct.epoll_event
%4 = tail call i32 @to_nonblock(i32 %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %2
%9 = bitcast %struct.epoll_event* %3 to i8*
%10 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 1, i32 0
store i32 %1, i32* %10
%11 = load i32, i32* @EPOLLIN
%12 = load i32, i32* @EPOLLET
%13 = or i32 %12, %11
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @EPOLL_CTL_ADD
%16 = call i32 @epoll_ctl(i32 %0, i32 %15, i32 %1, %struct.epoll_event* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = call i32 @err_exit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %8
ret void
}