#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_lookup(int, int);
scalar_t__ close(int);
int /*<<< orphan*/ printf(char *);
int ce_close(int fd) {
  if (ce_poller_lookup(fd, 1) != 0 && ce_poller_lookup(fd, 2) != 0) {
    if (close(fd) != 0) {
      printf("ERROR: Failed to close fd\n");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ce_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1050 <ce_poller_lookup@plt>
cmp    $0x0,%rax
je     1198 <ce_close+0x68>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1050 <ce_poller_lookup@plt>
cmp    $0x0,%rax
je     1198 <ce_close+0x68>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     1193 <ce_close+0x63>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <ce_close+0x6f>
jmp    1198 <ce_close+0x68>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ce_close>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x1,%esi
call   1050 <ce_poller_lookup@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1174 <ce_close+0x44>
mov    %ebp,%edi
mov    $0x2,%esi
call   1050 <ce_poller_lookup@plt>
test   %rax,%rax
je     1174 <ce_close+0x44>
mov    %ebp,%edi
call   1040 <close@plt>
test   %rax,%rax
je     1174 <ce_close+0x44>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"ERROR: Failed to close fd\0A\00"
define i32 @ce_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i64 @ce_poller_lookup(i32 %4, i32 1)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i64 @ce_poller_lookup(i32 %8, i32 2)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i32, i32* %3
%13 = call i64 @close(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %19
17: ; preds = %11
br label %18
18: ; preds = %17, %7, %1
store i32 0, i32* %2
br label %19
19: ; preds = %18, %15
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@str = [26 x i8] c"ERROR: Failed to close fd\00"
define i32 @ce_close(i32 %0) {
%2 = tail call i64 @ce_poller_lookup(i32 %0, i32 1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i64 @ce_poller_lookup(i32 %0, i32 2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i64 @close(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %1, %4, %7, %10
%13 = phi i32 [ -1, %10 ], [ 0, %7 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %13
}