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

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EXIT_FAILURE;
int epoll_create(int);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int, char *, int);
int /*<<< orphan*/ memset(struct epoll_event *, int /*<<< orphan*/, int);
int start_epoll(int sockfd) {
  int efd = epoll_create(1);
  if (efd == -1) {
    error(EXIT_FAILURE, errno, "Error %d creating epoll descriptor", errno);
  }
  struct epoll_event ev;
  memset(&ev, 0, sizeof(struct epoll_event));
  ev.events = EPOLLIN;
  ev.data.fd = sockfd;
  int err = epoll_ctl(efd, EPOLL_CTL_ADD, sockfd, &ev);
  if (err == -1) {
    error(EXIT_FAILURE, errno, "Error %d adding to epoll descriptor", errno);
  }
  return efd;
}


x86 assembly (clang, -O0):
<start_epoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1,%edi
call   1060 <epoll_create@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1189 <start_epoll+0x49>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e55(%rip),%rax
mov    (%rax),%ecx
lea    0xe7c(%rip),%rdx
call   1050 <error@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
lea    -0x10(%rbp),%rcx
call   1040 <epoll_ctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f7 <start_epoll+0xb7>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    0x2de7(%rip),%rax
mov    (%rax),%ecx
lea    0xe31(%rip),%rdx
call   1050 <error@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_epoll>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    $0x1,%edi
call   1060 <epoll_create@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117b <start_epoll+0x3b>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%ecx
lea    0xe8c(%rip),%rdx
mov    %ecx,%esi
call   1050 <error@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,0x8(%rsp)
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    11da <start_epoll+0x9a>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%ecx
lea    0xe50(%rip),%rdx
mov    %ecx,%esi
call   1050 <error@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [35 x i8] c"Error %d creating epoll descriptor\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [36 x i8] c"Error %d adding to epoll descriptor\00"
define i32 @start_epoll(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.epoll_event
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 @epoll_create(i32 1)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* @EXIT_FAILURE
%11 = load i32, i32* @errno
%12 = load i32, i32* @errno
%13 = call i32 @error(i32 %10, i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %9, %1
%15 = call i32 @memset(%struct.epoll_event* %4, i32 0, i32 8)
%16 = load i32, i32* @EPOLLIN
%17 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* %2
%19 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %3
%22 = load i32, i32* @EPOLL_CTL_ADD
%23 = load i32, i32* %2
%24 = call i32 @epoll_ctl(i32 %21, i32 %22, i32 %23, %struct.epoll_event* %4)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %14
%28 = load i32, i32* @EXIT_FAILURE
%29 = load i32, i32* @errno
%30 = load i32, i32* @errno
%31 = call i32 @error(i32 %28, i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %27, %14
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [35 x i8] c"Error %d creating epoll descriptor\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [36 x i8] c"Error %d adding to epoll descriptor\00"
define i32 @start_epoll(i32 %0) {
%2 = alloca %struct.epoll_event
%3 = tail call i32 @epoll_create(i32 1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @EXIT_FAILURE
%7 = load i32, i32* @errno
%8 = tail call i32 @error(i32 %6, i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %5, %1
%10 = bitcast %struct.epoll_event* %2 to i8*
%11 = call i32 @memset(%struct.epoll_event* %2, i32 0, i32 8)
%12 = load i32, i32* @EPOLLIN
%13 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 0, i32 0
store i32 %0, i32* %14
%15 = load i32, i32* @EPOLL_CTL_ADD
%16 = call i32 @epoll_ctl(i32 %3, i32 %15, i32 %0, %struct.epoll_event* %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %9
%19 = load i32, i32* @EXIT_FAILURE
%20 = load i32, i32* @errno
%21 = call i32 @error(i32 %19, i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %9
ret i32 %3
}