#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int dirfd(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
scalar_t__ symlinkat(char *, int, 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 > symlinkat("see.emily.play/gnome", dfd, "jugband.blues"))
    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    11d8 <main+0xa8>
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    11d8 <main+0xa8>
mov    -0x14(%rbp),%esi
lea    0xe61(%rip),%rdi
lea    0xe6f(%rip),%rdx
call   1050 <symlinkat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11cc <main+0x9c>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <main+0xa8>
mov    0x2e05(%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     1180 <main+0x50>
mov    %rax,%rdi
call   1040 <dirfd@plt>
cmp    $0xffffffff,%eax
je     1180 <main+0x50>
lea    0xea5(%rip),%rdi
lea    0xeb3(%rip),%rdx
mov    %eax,%esi
call   1050 <symlinkat@plt>
test   %rax,%rax
jns    1179 <main+0x49>
mov    0x2e69(%rip),%rbx
jmp    1180 <main+0x50>
mov    0x2e58(%rip),%rbx
mov    (%rbx),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"see.emily.play/gnome\00"
@.str.2 = [14 x i8] c"jugband.blues\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 %24
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 %24
16: ; preds = %9
%17 = load i32, i32* %3
%18 = call i64 @symlinkat(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp sgt i64 0, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %1
br label %24
22: ; preds = %16
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %1
br label %24
24: ; preds = %22, %20, %14, %7
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"see.emily.play/gnome\00"
@.str.2 = [14 x i8] c"jugband.blues\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 %10, label %3
3: ; preds = %0
%4 = tail call i32 @dirfd(i32* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i64 @symlinkat(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp slt i64 %7, 0
%9 = select i1 %8, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %10
10: ; preds = %3, %6, %0
%11 = phi i32* [ @EXIT_FAILURE, %0 ], [ @EXIT_FAILURE, %3 ], [ %9, %6 ]
%12 = load i32, i32* %11
ret i32 %12
}