#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);
  mkdir("dir1", S_IREAD | S_IWRITE | S_IEXEC);
  mkdir("dir3", 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);
  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
mov    0x2e47(%rip),%rax
or     (%rax),%esi
lea    0xe6c(%rip),%rdi
call   1030 <mkdir@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
or     (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1030 <mkdir@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
mov    0x2e12(%rip),%rax
or     (%rax),%esi
lea    0xe31(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe0a(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1050 <rename@plt>
lea    0xdfd(%rip),%rdi
lea    0xe10(%rip),%rsi
call   1050 <rename@plt>
lea    0xe04(%rip),%rdi
lea    0xde8(%rip),%rsi
call   1050 <rename@plt>
lea    0xdeb(%rip),%rdi
lea    0xdea(%rip),%rsi
call   1050 <rename@plt>
lea    0xdde(%rip),%rdi
lea    0xddc(%rip),%rsi
call   1050 <rename@plt>
lea    0xdcb(%rip),%rdi
lea    0xdbe(%rip),%rsi
call   1050 <rename@plt>
lea    0xdb2(%rip),%rdi
mov    $0xffffffffffffffff,%rsi
call   1050 <rename@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x2e80(%rip),%r13
mov    0x2e91(%rip),%rbx
mov    (%rbx),%esi
or     0x0(%r13),%esi
lea    0xe9c(%rip),%r14
mov    %r14,%rdi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
mov    0x2e58(%rip),%r12
or     (%r12),%esi
lea    0xe7b(%rip),%r15
mov    %r15,%rdi
call   1030 <mkdir@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
or     (%r12),%esi
lea    0xe67(%rip),%r12
mov    %r12,%rdi
call   1030 <mkdir@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
lea    0xe57(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
lea    0xe4e(%rip),%r13
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <rename@plt>
lea    0xe42(%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    0xe1f(%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>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file1\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str.1 = [5 x i8] c"dir1\00"
@S_IEXEC = global i32 0
@.str.2 = [5 x i8] c"dir3\00"
@.str.3 = [10 x i8] c"dir3/file\00"
@.str.4 = [6 x i8] c"file2\00"
@.str.5 = [5 x i8] c"dir2\00"
@.str.6 = [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 = load i32, i32* @S_IEXEC
%13 = or i32 %11, %12
%14 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), 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 = call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %23)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
%27 = 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.4, i64 0, i64 0))
%28 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* inttoptr (i64 -1 to i8*))
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 = [5 x i8] c"dir1\00"
@S_IEXEC = global i32 0
@.str.2 = [5 x i8] c"dir3\00"
@.str.3 = [10 x i8] c"dir3/file\00"
@.str.4 = [6 x i8] c"file2\00"
@.str.5 = [5 x i8] c"dir2\00"
@.str.6 = [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 = load i32, i32* @S_IEXEC
%10 = or i32 %8, %9
%11 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @S_IREAD
%13 = load i32, i32* @S_IWRITE
%14 = or i32 %13, %12
%15 = load i32, i32* @S_IEXEC
%16 = or i32 %14, %15
%17 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @S_IREAD
%19 = load i32, i32* @S_IWRITE
%20 = or i32 %19, %18
%21 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = tail call i32 @close(i32 %21)
%23 = 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.4, i64 0, i64 0))
%24 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%25 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%27 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%28 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 @rename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* inttoptr (i64 -1 to i8*))
ret i32 0
}