#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*/ *);
int /*<<< orphan*/ *opendir(char *);
scalar_t__ renameat(int, char *, int /*<<< orphan*/, 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 > renameat(dfd, "arnold.layne", AT_FDCWD, "lucifer.sam"))
    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    11e1 <main+0xb1>
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    11e1 <main+0xb1>
mov    -0x14(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
lea    0xe58(%rip),%rsi
lea    0xe5e(%rip),%rcx
call   1050 <renameat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11d5 <main+0xa5>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e1 <main+0xb1>
mov    0x2dfc(%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     1189 <main+0x59>
mov    %rax,%rdi
call   1040 <dirfd@plt>
cmp    $0xffffffff,%eax
je     1189 <main+0x59>
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%edx
lea    0xe9c(%rip),%rsi
lea    0xea2(%rip),%rcx
mov    %eax,%edi
call   1050 <renameat@plt>
test   %rax,%rax
jns    1182 <main+0x52>
mov    0x2e60(%rip),%rbx
jmp    1189 <main+0x59>
mov    0x2e4f(%rip),%rbx
mov    (%rbx),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"arnold.layne\00"
@AT_FDCWD = global i32 0
@.str.2 = [12 x i8] c"lucifer.sam\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* %3
%18 = load i32, i32* @AT_FDCWD
%19 = call i64 @renameat(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 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
@.str.1 = [13 x i8] c"arnold.layne\00"
@AT_FDCWD = global i32 0
@.str.2 = [12 x i8] c"lucifer.sam\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 @renameat(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 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
}