#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_create(int);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int /*<<< orphan*/ perror(char *);
int init_epoll(int sock) {
  int epfd;
  struct epoll_event ev;
  if ((epfd = epoll_create(100)) < 0) {
    perror("epoll_create");
    return -1;
  }
  ev.events = EPOLLIN | EPOLLET;
  ev.data.fd = sock;
  if (epoll_ctl(epfd, EPOLL_CTL_ADD, sock, &ev) < 0) {
    perror("epoll_ctl");
    return -1;
  }
  return epfd;
}


x86 assembly (clang, -O0):
<init_epoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x64,%edi
call   1050 <epoll_create@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1169 <init_epoll+0x39>
lea    0xea8(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <init_epoll+0x94>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    0x2e57(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1030 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    11be <init_epoll+0x8e>
lea    0xe60(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <init_epoll+0x94>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_epoll>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x64,%edi
call   1050 <epoll_create@plt>
test   %eax,%eax
js     1181 <init_epoll+0x51>
mov    %eax,%ebx
mov    0x2e9c(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    %ebp,0x4(%rsp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <epoll_ctl@plt>
test   %rax,%rax
js     118a <init_epoll+0x5a>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe78(%rip),%rdi
jmp    1191 <init_epoll+0x61>
lea    0xe7c(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1178 <init_epoll+0x48>

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

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