#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 /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int link(char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ report_test(int, int /*<<< orphan*/, int /*<<< orphan*/,
                               char *);
void link_dir(void) {
  int rv;
  rv = link(".", "badcalldir");
  report_test(rv, errno, EINVAL, "hard link of .");
  if (rv == 0) {
    remove("badcalldir");
  }
}


x86 assembly (clang, -O0):
<link_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed9(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <link@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
lea    0xea1(%rip),%rcx
call   1030 <report_test@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1185 <link_dir+0x55>
lea    0xe80(%rip),%rdi
call   1040 <remove@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<link_dir>:
push   %rbx
lea    0xee0(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <link@plt>
mov    %eax,%ebx
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    0xeac(%rip),%rcx
mov    %ebx,%edi
call   1030 <report_test@plt>
test   %ebx,%ebx
je     116c <link_dir+0x3c>
pop    %rbx
ret
lea    0xe8d(%rip),%rdi
pop    %rbx
jmp    1040 <remove@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [11 x i8] c"badcalldir\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.2 = [15 x i8] c"hard link of .\00"
define void @link_dir() {
%1 = alloca i32
%2 = call i32 @link(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = load i32, i32* @errno
%5 = load i32, i32* @EINVAL
%6 = call i32 @report_test(i32 %3, i32 %4, i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @remove(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [11 x i8] c"badcalldir\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.2 = [15 x i8] c"hard link of .\00"
define void @link_dir() {
%1 = tail call i32 @link(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%2 = load i32, i32* @errno
%3 = load i32, i32* @EINVAL
%4 = tail call i32 @report_test(i32 %1, i32 %2, i32 %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @remove(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
ret void
}