#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 S_IEXEC;
int S_IREAD;
int S_IWRITE;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ rename(char *, char *);
int main() {
  int fd1;
  fd1 = creat("file1", S_IREAD | S_IWRITE);
  close(fd1);
  fd1 = creat("file3", S_IREAD | S_IWRITE);
  close(fd1);
  mkdir("dir1", S_IREAD | S_IWRITE | S_IEXEC);
  mkdir("dir3", S_IREAD | S_IWRITE | S_IEXEC);
  mkdir("dir5", S_IREAD | S_IWRITE | S_IEXEC);
  fd1 = creat("dir3/file", S_IREAD | S_IWRITE);
  close(fd1);
  rename("file1", "file2");
  rename("dir1", "dir2");
  rename("dir2", "dir3");
  rename("file2", "dir2");
  rename("dir2", "dir2/dir4");
  rename("dir2", "file2");
  rename("file2", (char *)-1);
  rename((char *)-1, "file2");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    0x2e89(%rip),%rax
or     (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
lea    0xe75(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    0x2e37(%rip),%rax
or     (%rax),%esi
mov    0x2e1e(%rip),%rax
or     (%rax),%esi
lea    0xe49(%rip),%rdi
call   1030 <mkdir@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
lea    0xe27(%rip),%rdi
call   1030 <mkdir@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
mov    0x2dd0(%rip),%rax
or     (%rax),%esi
lea    0xe05(%rip),%rdi
call   1030 <mkdir@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    0x2dc2(%rip),%rax
or     (%rax),%esi
lea    0xdec(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xdba(%rip),%rdi
lea    0xdd8(%rip),%rsi
call   1050 <rename@plt>
lea    0xdb3(%rip),%rdi
lea    0xdcb(%rip),%rsi
call   1050 <rename@plt>
lea    0xdbf(%rip),%rdi
lea    0xd9e(%rip),%rsi
call   1050 <rename@plt>
lea    0xda6(%rip),%rdi
lea    0xda5(%rip),%rsi
call   1050 <rename@plt>
lea    0xd99(%rip),%rdi
lea    0xd97(%rip),%rsi
call   1050 <rename@plt>
lea    0xd86(%rip),%rdi
lea    0xd79(%rip),%rsi
call   1050 <rename@plt>
lea    0xd6d(%rip),%rdi
mov    $0xffffffffffffffff,%rsi
call   1050 <rename@plt>
mov    $0xffffffffffffffff,%rdi
lea    0xd53(%rip),%rsi
call   1050 <rename@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e7e(%rip),%r13
mov    0x2e8f(%rip),%rbx
mov    (%rbx),%esi
or     0x0(%r13),%esi
lea    0xe9a(%rip),%r14
mov    %r14,%rdi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
lea    0xe84(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
mov    0x2e3d(%rip),%rbp
or     0x0(%rbp),%esi
lea    0xe67(%rip),%r15
mov    %r15,%rdi
call   1030 <mkdir@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
or     0x0(%rbp),%esi
lea    0xe54(%rip),%r12
mov    %r12,%rdi
call   1030 <mkdir@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
or     0x0(%rbp),%esi
lea    0xe41(%rip),%rdi
call   1030 <mkdir@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
lea    0xe34(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
lea    0xe2b(%rip),%r13
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <rename@plt>
lea    0xe1f(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <rename@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <rename@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <rename@plt>
lea    0xdfc(%rip),%rsi
mov    %rbx,%rdi
call   1050 <rename@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <rename@plt>
mov    %r13,%rdi
mov    $0xffffffffffffffff,%rsi
call   1050 <rename@plt>
mov    $0xffffffffffffffff,%rdi
mov    %r13,%rsi
call   1050 <rename@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file1\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str.1 = [6 x i8] c"file3\00"
@.str.2 = [5 x i8] c"dir1\00"
@S_IEXEC = global i32 0
@.str.3 = [5 x i8] c"dir3\00"
@.str.4 = [5 x i8] c"dir5\00"
@.str.5 = [10 x i8] c"dir3/file\00"
@.str.6 = [6 x i8] c"file2\00"
@.str.7 = [5 x i8] c"dir2\00"
@.str.8 = [10 x i8] c"dir2/dir4\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @S_IREAD
%4 = load i32, i32* @S_IWRITE
%5 = or i32 %3, %4
%6 = call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @close(i32 %7)
%9 = load i32, i32* @S_IREAD
%10 = load i32, i32* @S_IWRITE
%11 = or i32 %9, %10
%12 = call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* @S_IREAD
%16 = load i32, i32* @S_IWRITE
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IEXEC
%19 = or i32 %17, %18
%20 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @S_IREAD
%22 = load i32, i32* @S_IWRITE
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IEXEC
%25 = or i32 %23, %24
%26 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @S_IREAD
%28 = load i32, i32* @S_IWRITE
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IEXEC
%31 = or i32 %29, %30
%32 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @S_IREAD
%34 = load i32, i32* @S_IWRITE
%35 = or i32 %33, %34
%36 = call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %35)
store i32 %36, i32* %2
%37 = load i32, i32* %2
%38 = call i32 @close(i32 %37)
%39 = call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%41 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%44 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* inttoptr (i64 -1 to i8*))
%46 = call i32 @rename(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"file1\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str.1 = [6 x i8] c"file3\00"
@.str.2 = [5 x i8] c"dir1\00"
@S_IEXEC = global i32 0
@.str.3 = [5 x i8] c"dir3\00"
@.str.4 = [5 x i8] c"dir5\00"
@.str.5 = [10 x i8] c"dir3/file\00"
@.str.6 = [6 x i8] c"file2\00"
@.str.7 = [5 x i8] c"dir2\00"
@.str.8 = [10 x i8] c"dir2/dir4\00"
define i32 @main() {
%1 = load i32, i32* @S_IREAD
%2 = load i32, i32* @S_IWRITE
%3 = or i32 %2, %1
%4 = tail call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @close(i32 %4)
%6 = load i32, i32* @S_IREAD
%7 = load i32, i32* @S_IWRITE
%8 = or i32 %7, %6
%9 = tail call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 @close(i32 %9)
%11 = load i32, i32* @S_IREAD
%12 = load i32, i32* @S_IWRITE
%13 = or i32 %12, %11
%14 = load i32, i32* @S_IEXEC
%15 = or i32 %13, %14
%16 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @S_IREAD
%18 = load i32, i32* @S_IWRITE
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IEXEC
%21 = or i32 %19, %20
%22 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @S_IREAD
%24 = load i32, i32* @S_IWRITE
%25 = or i32 %24, %23
%26 = load i32, i32* @S_IEXEC
%27 = or i32 %25, %26
%28 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @S_IREAD
%30 = load i32, i32* @S_IWRITE
%31 = or i32 %30, %29
%32 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = tail call i32 @close(i32 %32)
%34 = tail call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%35 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%36 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%37 = tail call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%38 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%39 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%40 = tail call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* inttoptr (i64 -1 to i8*))
%41 = tail call i32 @rename(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}