#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 */

/* Type definitions */
struct epoll_event {
  int dummy;
};

/* Variables and functions */
int epoll_create(int);
int /*<<< orphan*/ free(struct epoll_event *);
scalar_t__ malloc(int);
int setup_epoll(int size, struct epoll_event **events) {
  int fd;
  if ((*events = (struct epoll_event *)malloc(sizeof(struct epoll_event) *
                                              size)) == NULL)
    return -1;
  if ((fd = epoll_create(size)) == -1)
    free(*events);
  return fd;
}


x86 assembly (clang, -O0):
<setup_epoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    116b <setup_epoll+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <setup_epoll+0x61>
mov    -0x8(%rbp),%edi
call   1050 <epoll_create@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    118b <setup_epoll+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_epoll>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x0(,%rbx,4),%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     116e <setup_epoll+0x3e>
mov    %ebx,%edi
call   1050 <epoll_create@plt>
cmp    $0xffffffff,%eax
jne    116e <setup_epoll+0x3e>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.epoll_event = type { i32 }
define i32 @setup_epoll(i32 %0, %struct.epoll_event** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.epoll_event**
%6 = alloca i32
store i32 %0, i32* %4
store %struct.epoll_event** %1, %struct.epoll_event*** %5
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to %struct.epoll_event*
%13 = load %struct.epoll_event**, %struct.epoll_event*** %5
store %struct.epoll_event* %12, %struct.epoll_event** %13
%14 = icmp eq %struct.epoll_event* %12, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %26
16: ; preds = %2
%17 = load i32, i32* %4
%18 = call i32 @epoll_create(i32 %17)
store i32 %18, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load %struct.epoll_event**, %struct.epoll_event*** %5
%22 = load %struct.epoll_event*, %struct.epoll_event** %21
%23 = call i32 @free(%struct.epoll_event* %22)
br label %24
24: ; preds = %20, %16
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %15
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.epoll_event = type { i32 }
define i32 @setup_epoll(i32 %0, %struct.epoll_event** nocapture %1) {
%3 = shl i32 %0, 2
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to %struct.epoll_event*
store %struct.epoll_event* %5, %struct.epoll_event** %1
%6 = icmp eq i64 %4, 0
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = tail call i32 @epoll_create(i32 %0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load %struct.epoll_event*, %struct.epoll_event** %1
%12 = tail call i32 @free(%struct.epoll_event* %11)
br label %13
13: ; preds = %7, %10, %2
%14 = phi i32 [ -1, %2 ], [ -1, %10 ], [ %8, %7 ]
ret i32 %14
}