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

/* Variables and functions */
int epoll_ctl(int, int, int, struct epoll_event *);
int /*<<< orphan*/ memset(struct epoll_event *, int /*<<< orphan*/, int);
int /*<<< orphan*/ panic(char *);
void set_epoll_descriptor(int fd_epoll, int action, int fd_toadd, int events) {
  int ret;
  struct epoll_event ev;
  memset(&ev, 0, sizeof(ev));
  ev.events = events;
  ev.data.fd = fd_toadd;
  ret = epoll_ctl(fd_epoll, action, fd_toadd, &ev);
  if (ret < 0)
    panic("Cannot add socket for epoll!\n");
}


x86 assembly (clang, -O0):
<set_epoll_descriptor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1050 <epoll_ctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118b <set_epoll_descriptor+0x5b>
lea    0xe7a(%rip),%rdi
call   1030 <panic@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_epoll_descriptor>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    %ebx,0x8(%rsp)
mov    %ebp,0xc(%rsp)
mov    %r15d,%edi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   1050 <epoll_ctl@plt>
test   %eax,%eax
jns    1182 <set_epoll_descriptor+0x52>
lea    0xe83(%rip),%rdi
call   1030 <panic@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [30 x i8] c"Cannot add socket for epoll!\0A\00"
define void @set_epoll_descriptor(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.epoll_event
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = call i32 @memset(%struct.epoll_event* %10, i32 0, i32 8)
%12 = load i32, i32* %8
%13 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %7
%15 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, 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* %5
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = call i32 @epoll_ctl(i32 %17, i32 %18, i32 %19, %struct.epoll_event* %10)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %4
%24 = call i32 @panic(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %4
ret void
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [30 x i8] c"Cannot add socket for epoll!\0A\00"
define void @set_epoll_descriptor(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.epoll_event
%6 = bitcast %struct.epoll_event* %5 to i8*
%7 = call i32 @memset(%struct.epoll_event* %5, i32 0, i32 8)
%8 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 0
store i32 %3, i32* %8
%9 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 1, i32 0
store i32 %2, i32* %9
%10 = call i32 @epoll_ctl(i32 %0, i32 %1, i32 %2, %struct.epoll_event* %5)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i32 @panic(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %4
ret void
}