int close(int fd) {
  int res;
  res = p_close(fd);
  dprint(4, check_fd(fd), "%s(%d) => %d", __FUNCTION__, fd, res);
  if (check_fd(fd))
    remove_fd(fd);
  return res;
}


x86 assembly (clang, -O0):
<close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1030 <p_close@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <check_fd@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%r8d
mov    -0x8(%rbp),%r9d
mov    $0x4,%edi
lea    0xe88(%rip),%rdx
lea    0xe8e(%rip),%rcx
mov    $0x0,%al
call   1060 <dprint@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <check_fd@plt>
cmp    $0x0,%eax
je     11a3 <close+0x63>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <remove_fd@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <p_close@plt>
mov    %eax,%ebp
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <check_fd@plt>
lea    0xea2(%rip),%rdx
lea    0xea8(%rip),%rcx
mov    $0x4,%edi
mov    %eax,%esi
mov    %ebx,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
call   1060 <dprint@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <check_fd@plt>
test   %eax,%eax
je     118f <close+0x4f>
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <remove_fd@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%s(%d) => %d\00"
@__FUNCTION__.close = [6 x i8] c"close\00"
define i32 @close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 (i32, ...) bitcast (i32 (...)* @p_close to i32 (i32, ...)*)(i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %2
%7 = call i32 (i32, ...) bitcast (i32 (...)* @check_fd to i32 (i32, ...)*)(i32 %6)
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = call i32 (i32, i32, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @dprint to i32 (i32, i32, i8*, i8*, i32, i32, ...)*)(i32 4, i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__FUNCTION__.close, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %2
%12 = call i32 (i32, ...) bitcast (i32 (...)* @check_fd to i32 (i32, ...)*)(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* %2
%16 = call i32 (i32, ...) bitcast (i32 (...)* @remove_fd to i32 (i32, ...)*)(i32 %15)
br label %17
17: ; preds = %14, %1
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@.str = [13 x i8] c"%s(%d) => %d\00"
@__FUNCTION__.close = [6 x i8] c"close\00"
define i32 @close(i32 %0) {
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @p_close to i32 (i32, ...)*)(i32 %0)
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_fd to i32 (i32, ...)*)(i32 %0)
%4 = tail call i32 (i32, i32, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @dprint to i32 (i32, i32, i8*, i8*, i32, i32, ...)*)(i32 4, i32 %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__FUNCTION__.close, i64 0, i64 0), i32 %0, i32 %2)
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_fd to i32 (i32, ...)*)(i32 %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @remove_fd to i32 (i32, ...)*)(i32 %0)
br label %9
9: ; preds = %7, %1
ret i32 %2
}