#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 /*<<< orphan*/ events;
  TYPE_1__ data;
};

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int /*<<< orphan*/ perror(char *);
int fd_add(int efd, int fd) {
  struct epoll_event event;
  int rc;
  event.data.fd = fd;
  event.events = EPOLLIN;
  rc = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event);
  if (rc < 0) {
    perror("epoll_ctl");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fd_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1030 <epoll_ctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117d <fd_add+0x5d>
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <fd_add+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_add>:
push   %rax
mov    %esi,%edx
mov    %esi,0x4(%rsp)
mov    0x2eba(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
call   1030 <epoll_ctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
js     114e <fd_add+0x2e>
pop    %rcx
ret
lea    0xeab(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [10 x i8] c"epoll_ctl\00"
define i32 @fd_add(i32 %0, i32 %1) {
%3 = alloca %struct.epoll_event
%4 = bitcast %struct.epoll_event* %3 to i8*
%5 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 1, i32 0
store i32 %1, i32* %5
%6 = load i32, i32* @EPOLLIN
%7 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @EPOLL_CTL_ADD
%9 = call i32 @epoll_ctl(i32 %0, i32 %8, i32 %1, %struct.epoll_event* %3)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %2, %11
%14 = phi i32 [ -1, %11 ], [ 0, %2 ]
ret i32 %14
}