#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 */
int close(int);
int errno;
int gettid();
int /*<<< orphan*/ printf(char *, int, ...);
char *strerror(int);
int _close(int fd) {
  int ret;
  printf("%d: close(%d)\n", gettid(), fd);
  ret = close(fd);
  printf("%d: close(%d) = %d\n", gettid(), fd, ret);
  if (ret)
    printf("\terr %d (%s)\n", errno, strerror(errno));
  return ret;
}


x86 assembly (clang, -O0):
<_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <gettid@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <gettid@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11c5 <_close+0x85>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0xc(%rbp),%esi
mov    %rax,%rdx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_close>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <gettid@plt>
lea    0xead(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <gettid@plt>
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     11a9 <_close+0x69>
mov    0x2e53(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe86(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%d: close(%d)\0A\00"
@.str.1 = [20 x i8] c"%d: close(%d) = %d\0A\00"
@.str.2 = [14 x i8] c"\09err %d (%s)\0A\00"
@errno = global i32 0
define i32 @_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @gettid()
%5 = load i32, i32* %2
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = load i32, i32* %2
%8 = call i32 @close(i32 %7)
store i32 %8, i32* %3
%9 = call i32 (...) @gettid()
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10, i32 %11)
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load i32, i32* @errno
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8* %18)
br label %20
20: ; preds = %15, %1
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [15 x i8] c"%d: close(%d)\0A\00"
@.str.1 = [20 x i8] c"%d: close(%d) = %d\0A\00"
@.str.2 = [14 x i8] c"\09err %d (%s)\0A\00"
@errno = global i32 0
define i32 @_close(i32 %0) {
%2 = tail call i32 (...) @gettid()
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %0)
%4 = tail call i32 @close(i32 %0)
%5 = tail call i32 (...) @gettid()
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %0, i32 %4)
%7 = icmp eq i32 %4, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %9, i8* %10)
br label %12
12: ; preds = %8, %1
ret i32 %4
}