#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 AT_FDCWD;
int O_DIRECTORY;
int O_RDONLY;
int /*<<< orphan*/ execveat(int, char *, char *const *, int /*<<< orphan*/ *,
                            int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int linkat(int, char *, int, char *, int /*<<< orphan*/);
int openat(int, char *, int);
int renameat(int, char *, int, char *);
int renameat2(int, char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  int tmpd = openat(AT_FDCWD, "tmp", O_RDONLY | O_DIRECTORY);
  int subd = openat(tmpd, "subdir1", O_RDONLY | O_DIRECTORY);
  int sub2d = openat(tmpd, "subdir2", O_RDONLY | O_DIRECTORY);
  int testsd = openat(AT_FDCWD, "tests", O_RDONLY | O_DIRECTORY);
  int ret = linkat(testsd, "linkat.test", tmpd, "awesome.exe", 0);
  fprintf(stderr, "linkat -> %d\n", ret);
  ret = renameat(tmpd, "awesome.exe", subd, "awesome");
  fprintf(stderr, "renameat -> %d\n", ret);
  ret = renameat2(tmpd, "subdir1", sub2d, "hidden", 0);
  fprintf(stderr, "renameat2 -> %d\n", ret);
  char *const argv[] = {"awesome", NULL};
  execveat(testsd, "null.test", argv, NULL, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    0x2e50(%rip),%rax
or     (%rax),%edx
lea    0xe6f(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    0x2e2c(%rip),%rax
or     (%rax),%edx
lea    0xe4f(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    0x2e08(%rip),%rax
or     (%rax),%edx
lea    0xe33(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
mov    0x2dde(%rip),%rax
or     (%rax),%edx
lea    0xe11(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%edx
lea    0xe02(%rip),%rsi
lea    0xe07(%rip),%rcx
xor    %r8d,%r8d
call   1070 <linkat@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xdf5(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
lea    0xdd7(%rip),%rsi
lea    0xdea(%rip),%rcx
call   1080 <renameat@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xdd7(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%edx
lea    0xd81(%rip),%rsi
lea    0xdce(%rip),%rcx
xor    %r8d,%r8d
call   1060 <renameat2@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xdb7(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2b3c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2b39(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rdx
lea    0xd9f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <execveat@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e4b(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2e68(%rip),%r14
mov    0x2e51(%rip),%rbp
mov    0x0(%rbp),%edx
or     (%r14),%edx
lea    0xe6c(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%edx
or     (%r14),%edx
lea    0xe5c(%rip),%rsi
mov    %eax,%edi
call   1030 <openat@plt>
mov    %eax,%r12d
mov    0x0(%rbp),%edx
or     (%r14),%edx
lea    0xe4d(%rip),%rsi
mov    %ebx,%edi
call   1030 <openat@plt>
mov    %eax,%r15d
mov    0x0(%r13),%edi
mov    0x0(%rbp),%edx
or     (%r14),%edx
lea    0xe3a(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,%ebp
lea    0xe32(%rip),%rsi
lea    0xe37(%rip),%r13
mov    %eax,%edi
mov    %ebx,%edx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1070 <linkat@plt>
mov    0x2dcb(%rip),%r14
mov    (%r14),%edi
lea    0xe23(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
lea    0xe23(%rip),%rcx
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r12d,%edx
call   1080 <renameat@plt>
mov    (%r14),%edi
lea    0xe14(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
lea    0xe16(%rip),%rcx
mov    %ebx,%edi
lea    0xdb9(%rip),%rsi
mov    %r15d,%edx
xor    %r8d,%r8d
call   1060 <renameat2@plt>
mov    (%r14),%edi
lea    0xdff(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
movaps 0x2b82(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xdf7(%rip),%rsi
mov    %rsp,%rdx
mov    %ebp,%edi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <execveat@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AT_FDCWD = global i32 0
@.str = [4 x i8] c"tmp\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.1 = [8 x i8] c"subdir1\00"
@.str.2 = [8 x i8] c"subdir2\00"
@.str.3 = [6 x i8] c"tests\00"
@.str.4 = [12 x i8] c"linkat.test\00"
@.str.5 = [12 x i8] c"awesome.exe\00"
@stderr = global i32 0
@.str.6 = [14 x i8] c"linkat -> %d\0A\00"
@.str.7 = [8 x i8] c"awesome\00"
@.str.8 = [16 x i8] c"renameat -> %d\0A\00"
@.str.9 = [7 x i8] c"hidden\00"
@.str.10 = [17 x i8] c"renameat2 -> %d\0A\00"
@__const.main.argv = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i32 0, i32 0), i8* null]
@.str.11 = [10 x i8] c"null.test\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i8*]
store i32 0, i32* %1
%8 = load i32, i32* @AT_FDCWD
%9 = load i32, i32* @O_RDONLY
%10 = load i32, i32* @O_DIRECTORY
%11 = or i32 %9, %10
%12 = call i32 @openat(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_DIRECTORY
%16 = or i32 %14, %15
%17 = call i32 @openat(i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = load i32, i32* @O_RDONLY
%20 = load i32, i32* @O_DIRECTORY
%21 = or i32 %19, %20
%22 = call i32 @openat(i32 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %21)
store i32 %22, i32* %4
%23 = load i32, i32* @AT_FDCWD
%24 = load i32, i32* @O_RDONLY
%25 = load i32, i32* @O_DIRECTORY
%26 = or i32 %24, %25
%27 = call i32 @openat(i32 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = load i32, i32* %2
%30 = call i32 @linkat(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 0)
store i32 %30, i32* %6
%31 = load i32, i32* @stderr
%32 = load i32, i32* %6
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = call i32 @renameat(i32 %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
store i32 %36, i32* %6
%37 = load i32, i32* @stderr
%38 = load i32, i32* %6
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %2
%41 = load i32, i32* %4
%42 = call i32 @renameat2(i32 %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 0)
store i32 %42, i32* %6
%43 = load i32, i32* @stderr
%44 = load i32, i32* %6
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %44)
%46 = bitcast [2 x i8*]* %7 to i8*
%47 = load i32, i32* %5
%48 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%49 = call i32 @execveat(i32 %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8** %48, i32* null, i32 0)
ret i32 0
}

LLVM IR (-O2):
@AT_FDCWD = global i32 0
@.str = [4 x i8] c"tmp\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.1 = [8 x i8] c"subdir1\00"
@.str.2 = [8 x i8] c"subdir2\00"
@.str.3 = [6 x i8] c"tests\00"
@.str.4 = [12 x i8] c"linkat.test\00"
@.str.5 = [12 x i8] c"awesome.exe\00"
@stderr = global i32 0
@.str.6 = [14 x i8] c"linkat -> %d\0A\00"
@.str.7 = [8 x i8] c"awesome\00"
@.str.8 = [16 x i8] c"renameat -> %d\0A\00"
@.str.9 = [7 x i8] c"hidden\00"
@.str.10 = [17 x i8] c"renameat2 -> %d\0A\00"
@__const.main.argv = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i32 0, i32 0), i8* null]
@.str.11 = [10 x i8] c"null.test\00"
define i32 @main() {
%1 = alloca [2 x i8*]
%2 = load i32, i32* @AT_FDCWD
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_DIRECTORY
%5 = or i32 %4, %3
%6 = tail call i32 @openat(i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_DIRECTORY
%9 = or i32 %8, %7
%10 = tail call i32 @openat(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @O_RDONLY
%12 = load i32, i32* @O_DIRECTORY
%13 = or i32 %12, %11
%14 = tail call i32 @openat(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @AT_FDCWD
%16 = load i32, i32* @O_RDONLY
%17 = load i32, i32* @O_DIRECTORY
%18 = or i32 %17, %16
%19 = tail call i32 @openat(i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = tail call i32 @linkat(i32 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 0)
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %20)
%23 = tail call i32 @renameat(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %23)
%26 = tail call i32 @renameat2(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 0)
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %26)
%29 = bitcast [2 x i8*]* %1 to i8*
%30 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 0
%31 = call i32 @execveat(i32 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8** %30, i32* null, i32 0)
ret i32 0
}