#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;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int EPOLLET;
int EPOLLRDHUP;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
void add_event(int epfd, int fd, int event_flag) {
  struct epoll_event event = {0};
  event.data.fd = fd;
  event.events = event_flag | EPOLLET | EPOLLRDHUP;
  if (-1 == epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event)) {
    perror("epoll_ctl ADD: ");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<add_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e5f(%rip),%rcx
or     (%rcx),%eax
mov    0x2e5e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1040 <epoll_ctl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11bc <add_event+0x7c>
lea    0xe53(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_event>:
sub    $0x18,%rsp
mov    %esi,%eax
mov    0x2e93(%rip),%rcx
or     (%rcx),%edx
movl   $0x0,0x10(%rsp)
mov    0x2e8a(%rip),%rcx
or     (%rcx),%edx
mov    %esi,0xc(%rsp)
mov    %edx,0x8(%rsp)
mov    0x2e89(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rcx
mov    %eax,%edx
call   1030 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     1177 <add_event+0x47>
add    $0x18,%rsp
ret
lea    0xe82(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

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

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