#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 /*<<< orphan*/ F_OK;
int access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ rename(char const *, char const *);
int main() {
  const char *src_file = "f1/test1";
  const char *dest_file = "f1/test2";
  int x = access(dest_file, F_OK);
  if (x != 0) {
    printf("The file may not exist OR the program might not have enough "
           "permissions on this file\n");
    if (rename(src_file, dest_file) == 0) {
      printf("File was successfully renamed\n");
    } else {
      printf("Rename failed. The program might not have enough permissions to "
             "perform this operation\n");
    }
  } else {
    printf("File exists. Rename fails.\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11c9 <main+0x89>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <rename@plt>
cmp    $0x0,%rax
jne    11b8 <main+0x78>
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
jmp    11c4 <main+0x84>
lea    0xec8(%rip),%rdi
call   1030 <printf@plt>
jmp    11dc <main+0x9c>
lea    0xf0f(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1040 <access@plt>
test   %eax,%eax
je     1197 <main+0x57>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe93(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1050 <rename@plt>
test   %rax,%rax
lea    0xf56(%rip),%rax
lea    0xef8(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"f1/test1\00"
@.str.1 = [9 x i8] c"f1/test2\00"
@F_OK = global i32 0
@.str.2 = [86 x i8] c"The file may not exist OR the program might not have enough permissions on this file\0A\00"
@.str.3 = [31 x i8] c"File was successfully renamed\0A\00"
@.str.4 = [88 x i8] c"Rename failed. The program might not have enough permissions to perform this operation\0A\00"
@.str.5 = [28 x i8] c"File exists. Rename fails.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @F_OK
%7 = call i32 @access(i8* %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
%12 = load i8*, i8** %2
%13 = load i8*, i8** %3
%14 = call i64 @rename(i8* %12, i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %20
18: ; preds = %10
%19 = call i32 @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
br label %24
21: ; preds = %0
%22 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %20
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [9 x i8] c"f1/test1\00"
@.str.1 = [9 x i8] c"f1/test2\00"
@F_OK = global i32 0
@str = [27 x i8] c"File exists. Rename fails.\00"
@str.6 = [85 x i8] c"The file may not exist OR the program might not have enough permissions on this file\00"
@str.7 = [87 x i8] c"Rename failed. The program might not have enough permissions to perform this operation\00"
@str.8 = [30 x i8] c"File was successfully renamed\00"
define i32 @main() {
%1 = load i32, i32* @F_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i64 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([87 x i8], [87 x i8]* @str.7, i64 0, i64 0)
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
ret i32 0
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
}