#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 */
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ AT_FDCWD;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int dirfd(int /*<<< orphan*/ *);
scalar_t__ linkat(int /*<<< orphan*/, char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int main(void) {
  DIR *dot = opendir(".");
  if (NULL == dot)
    return EXIT_FAILURE;
  int dfd = dirfd(dot);
  if (-1 == dfd)
    return EXIT_FAILURE;
  if (0 > linkat(AT_FDCWD, "see.emily.play/gnome", dfd, "arnold.layne.hard", 0))
    return EXIT_FAILURE;
  else
    return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    116c <main+0x3c>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <main+0xb4>
mov    -0x10(%rbp),%rdi
call   1040 <dirfd@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1197 <main+0x67>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <main+0xb4>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe58(%rip),%rsi
lea    0xe66(%rip),%rcx
xor    %r8d,%r8d
call   1050 <linkat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11d8 <main+0xa8>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <main+0xb4>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <opendir@plt>
mov    0x2e9c(%rip),%rbx
test   %rax,%rax
je     118c <main+0x5c>
mov    %rax,%rdi
call   1040 <dirfd@plt>
cmp    $0xffffffff,%eax
je     118c <main+0x5c>
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%edi
lea    0xe9c(%rip),%rsi
lea    0xeaa(%rip),%rcx
mov    %eax,%edx
xor    %r8d,%r8d
call   1050 <linkat@plt>
test   %rax,%rax
jns    1185 <main+0x55>
mov    0x2e5d(%rip),%rbx
jmp    118c <main+0x5c>
mov    0x2e4c(%rip),%rbx
mov    (%rbx),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@EXIT_FAILURE = global i32 0
@AT_FDCWD = global i32 0
@.str.1 = [21 x i8] c"see.emily.play/gnome\00"
@.str.2 = [18 x i8] c"arnold.layne.hard\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* null, %5
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i32, i32* @EXIT_FAILURE
store i32 %8, i32* %1
br label %25
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @dirfd(i32* %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %1
br label %25
16: ; preds = %9
%17 = load i32, i32* @AT_FDCWD
%18 = load i32, i32* %3
%19 = call i64 @linkat(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 0)
%20 = icmp sgt i64 0, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %1
br label %25
23: ; preds = %16
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %1
br label %25
25: ; preds = %23, %21, %14, %7
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@EXIT_FAILURE = global i32 0
@AT_FDCWD = global i32 0
@.str.1 = [21 x i8] c"see.emily.play/gnome\00"
@.str.2 = [18 x i8] c"arnold.layne.hard\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = tail call i32 @dirfd(i32* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = load i32, i32* @AT_FDCWD
%8 = tail call i64 @linkat(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 0)
%9 = icmp slt i64 %8, 0
%10 = select i1 %9, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %11
11: ; preds = %3, %6, %0
%12 = phi i32* [ @EXIT_FAILURE, %0 ], [ @EXIT_FAILURE, %3 ], [ %10, %6 ]
%13 = load i32, i32* %12
ret i32 %13
}