#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 EPOLL_CTL_DEL;
int epoll_ctl(int, int, int, struct epoll_event *);
int /*<<< orphan*/ memset(struct epoll_event *, int /*<<< orphan*/, int);
int ctl_epoll(int epfd, int cfd, int action, int event_type) {
  int ret;
  if (action != EPOLL_CTL_DEL) {
    struct epoll_event ev;
    memset(&ev, 0, sizeof(struct epoll_event));
    ev.data.fd = cfd;
    ev.events = event_type;
    ret = epoll_ctl(epfd, action, cfd, &ev);
  } else {
    ret = epoll_ctl(epfd, action, cfd, NULL);
  }
  return ret;
}


x86 assembly (clang, -O0):
<ctl_epoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2eba(%rip),%rcx
cmp    (%rcx),%eax
je     117c <ctl_epoll+0x5c>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1040 <epoll_ctl@plt>
mov    %eax,-0x14(%rbp)
jmp    1191 <ctl_epoll+0x71>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <epoll_ctl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctl_epoll>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
mov    0x2ebe(%rip),%rax
cmp    %edx,(%rax)
jne    1158 <ctl_epoll+0x38>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %ecx,%ecx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <epoll_ctl@plt>
mov    %ecx,%r15d
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    %ebx,0xc(%rsp)
mov    %r15d,0x8(%rsp)
mov    %r14d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r12,%rcx
call   1040 <epoll_ctl@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 }
@EPOLL_CTL_DEL = global i32 0
define i32 @ctl_epoll(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 = load i32, i32* %7
%12 = load i32, i32* @EPOLL_CTL_DEL
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %4
%15 = call i32 @memset(%struct.epoll_event* %10, i32 0, i32 8)
%16 = load i32, i32* %6
%17 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* %8
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %5
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = call i32 @epoll_ctl(i32 %21, i32 %22, i32 %23, %struct.epoll_event* %10)
store i32 %24, i32* %9
br label %30
25: ; preds = %4
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = call i32 @epoll_ctl(i32 %26, i32 %27, i32 %28, %struct.epoll_event* null)
store i32 %29, i32* %9
br label %30
30: ; preds = %25, %14
%31 = load i32, i32* %9
ret i32 %31
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLL_CTL_DEL = global i32 0
define i32 @ctl_epoll(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.epoll_event
%6 = load i32, i32* @EPOLL_CTL_DEL
%7 = icmp eq i32 %6, %2
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = bitcast %struct.epoll_event* %5 to i8*
%10 = call i32 @memset(%struct.epoll_event* %5, i32 0, i32 8)
%11 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 1, i32 0
store i32 %1, i32* %11
%12 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 0
store i32 %3, i32* %12
%13 = call i32 @epoll_ctl(i32 %0, i32 %2, i32 %1, %struct.epoll_event* %5)
br label %16
14: ; preds = %4
%15 = tail call i32 @epoll_ctl(i32 %0, i32 %2, i32 %1, %struct.epoll_event* null)
br label %16
16: ; preds = %14, %8
%17 = phi i32 [ %13, %8 ], [ %15, %14 ]
ret i32 %17
}