#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__ {
  void *ptr;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int sp_add(int efd, int sock, void *ud) {
  struct epoll_event ev;
  ev.events = EPOLLIN;
  ev.data.ptr = ud;
  if (epoll_ctl(efd, EPOLL_CTL_ADD, sock, &ev) == -1) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sp_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ebf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
lea    -0x28(%rbp),%rcx
call   1030 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    1163 <sp_add+0x53>
movl   $0x1,-0x4(%rbp)
jmp    116a <sp_add+0x5a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp_add>:
sub    $0x18,%rsp
mov    %esi,%eax
mov    0x2ecb(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rcx
mov    %eax,%edx
call   1030 <epoll_ctl@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
mov    %ecx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
define i32 @sp_add(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.epoll_event
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i32, i32* @EPOLLIN
%10 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i8*, i8** %7
%12 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i8* %11, i8** %13
%14 = load i32, i32* %5
%15 = load i32, i32* @EPOLL_CTL_ADD
%16 = load i32, i32* %6
%17 = call i32 @epoll_ctl(i32 %14, i32 %15, i32 %16, %struct.epoll_event* %8)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 1, i32* %4
br label %21
20: ; preds = %3
store i32 0, i32* %4
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
define i32 @sp_add(i32 %0, i32 %1, i8* %2) {
%4 = alloca %struct.epoll_event
%5 = bitcast %struct.epoll_event* %4 to i8*
%6 = load i32, i32* @EPOLLIN
%7 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0, i32 0
store i8* %2, i8** %8
%9 = load i32, i32* @EPOLL_CTL_ADD
%10 = call i32 @epoll_ctl(i32 %0, i32 %9, i32 %1, %struct.epoll_event* %4)
%11 = icmp eq i32 %10, -1
%12 = zext i1 %11 to i32
ret i32 %12
}