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

/* Variables and functions */
scalar_t__ ce_poller_add(int, int);
scalar_t__ ce_poller_init(int);
int /*<<< orphan*/ ce_poller_initialized();
scalar_t__ ce_poller_lookup(int, int);
int /*<<< orphan*/ printf(char *, int);
int ce_listen(int fd, int event) {
  if (!ce_poller_initialized()) {
    if (ce_poller_init(1024) != 0) {
      return -1;
    }
  }
  if (ce_poller_lookup(fd, event) == 0) {
    printf("INFO: Event already listened on fd %d\n", fd);
    return 0;
  }
  if (ce_poller_add(fd, event) != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ce_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1070 <ce_poller_initialized@plt>
cmp    $0x0,%eax
jne    1193 <ce_listen+0x43>
mov    $0x400,%edi
call   1030 <ce_poller_init@plt>
cmp    $0x0,%rax
je     118e <ce_listen+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <ce_listen+0x9b>
jmp    1193 <ce_listen+0x43>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <ce_poller_lookup@plt>
cmp    $0x0,%rax
jne    11c3 <ce_listen+0x73>
mov    -0x8(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11eb <ce_listen+0x9b>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <ce_poller_add@plt>
cmp    $0x0,%rax
je     11e4 <ce_listen+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <ce_listen+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ce_listen>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1070 <ce_poller_initialized@plt>
test   %eax,%eax
je     1180 <ce_listen+0x30>
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <ce_poller_lookup@plt>
test   %rax,%rax
je     1199 <ce_listen+0x49>
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <ce_poller_add@plt>
neg    %rax
sbb    %eax,%eax
jmp    11a9 <ce_listen+0x59>
mov    $0x400,%edi
call   1030 <ce_poller_init@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11a9 <ce_listen+0x59>
jmp    1162 <ce_listen+0x12>
lea    0xe60(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"INFO: Event already listened on fd %d\0A\00"
define i32 @ce_listen(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = call i32 (...) @ce_poller_initialized()
%7 = icmp ne i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = call i64 @ce_poller_init(i32 1024)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 -1, i32* %3
br label %28
12: ; preds = %8
br label %13
13: ; preds = %12, %2
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i64 @ce_poller_lookup(i32 %14, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 0, i32* %3
br label %28
21: ; preds = %13
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i64 @ce_poller_add(i32 %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %3
br label %28
27: ; preds = %21
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26, %18, %11
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [39 x i8] c"INFO: Event already listened on fd %d\0A\00"
define i32 @ce_listen(i32 %0, i32 %1) {
%3 = tail call i32 (...) @ce_poller_initialized()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 @ce_poller_init(i32 1024)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %5, %2
%9 = tail call i64 @ce_poller_lookup(i32 %0, i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %17
13: ; preds = %8
%14 = tail call i64 @ce_poller_add(i32 %0, i32 %1)
%15 = icmp ne i64 %14, 0
%16 = sext i1 %15 to i32
br label %17
17: ; preds = %13, %5, %11
%18 = phi i32 [ 0, %11 ], [ -1, %5 ], [ %16, %13 ]
ret i32 %18
}