#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 /*<<< orphan*/ R_OK;
int /*<<< orphan*/ W_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ concat(char *, char *);
int /*<<< orphan*/ toLog(int /*<<< orphan*/);
bool canDelete(char *filename) {
  bool state = true;
  if (access(filename, F_OK) == -1) {
    toLog(concat("File does not exist: ", filename));
    state = false;
  }
  if (access(filename, R_OK) == -1) {
    toLog(concat("User does not have read permission for file: ", filename));
    state = false;
  }
  if (access(filename, W_OK) == -1) {
    toLog(concat("User does not have write permission for file: ", filename));
    state = false;
  }
  return state;
}


x86 assembly (clang, -O0):
<canDelete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    117c <canDelete+0x4c>
mov    -0x8(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1040 <concat@plt>
mov    %eax,%edi
call   1030 <toLog@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    11b5 <canDelete+0x85>
mov    -0x8(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1040 <concat@plt>
mov    %eax,%edi
call   1030 <toLog@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    11ee <canDelete+0xbe>
mov    -0x8(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1040 <concat@plt>
mov    %eax,%edi
call   1030 <toLog@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canDelete>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
jne    1166 <canDelete+0x36>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
call   1040 <concat@plt>
mov    %eax,%edi
call   1030 <toLog@plt>
xor    %ebp,%ebp
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    1194 <canDelete+0x64>
lea    0xe93(%rip),%rdi
mov    %rbx,%rsi
call   1040 <concat@plt>
mov    %eax,%edi
call   1030 <toLog@plt>
xor    %ebp,%ebp
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    11c2 <canDelete+0x92>
lea    0xe93(%rip),%rdi
mov    %rbx,%rsi
call   1040 <concat@plt>
mov    %eax,%edi
call   1030 <toLog@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [22 x i8] c"File does not exist: \00"
@R_OK = global i32 0
@.str.1 = [46 x i8] c"User does not have read permission for file: \00"
@W_OK = global i32 0
@.str.2 = [47 x i8] c"User does not have write permission for file: \00"
define i32 @canDelete(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %3
%4 = load i8*, i8** %2
%5 = load i32, i32* @F_OK
%6 = call i32 @access(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @concat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 @toLog(i32 %10)
store i32 0, i32* %3
br label %12
12: ; preds = %8, %1
%13 = load i8*, i8** %2
%14 = load i32, i32* @R_OK
%15 = call i32 @access(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i8*, i8** %2
%19 = call i32 @concat(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @toLog(i32 %19)
store i32 0, i32* %3
br label %21
21: ; preds = %17, %12
%22 = load i8*, i8** %2
%23 = load i32, i32* @W_OK
%24 = call i32 @access(i8* %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i8*, i8** %2
%28 = call i32 @concat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @toLog(i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %26, %21
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [22 x i8] c"File does not exist: \00"
@R_OK = global i32 0
@.str.1 = [46 x i8] c"User does not have read permission for file: \00"
@W_OK = global i32 0
@.str.2 = [47 x i8] c"User does not have write permission for file: \00"
define i32 @canDelete(i8* %0) {
%2 = load i32, i32* @F_OK
%3 = tail call i32 @access(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @concat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 @toLog(i32 %6)
br label %8
8: ; preds = %5, %1
%9 = phi i32 [ 0, %5 ], [ 1, %1 ]
%10 = load i32, i32* @R_OK
%11 = tail call i32 @access(i8* %0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @concat(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%15 = tail call i32 @toLog(i32 %14)
br label %16
16: ; preds = %13, %8
%17 = phi i32 [ 0, %13 ], [ %9, %8 ]
%18 = load i32, i32* @W_OK
%19 = tail call i32 @access(i8* %0, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = tail call i32 @concat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%23 = tail call i32 @toLog(i32 %22)
br label %24
24: ; preds = %21, %16
%25 = phi i32 [ 0, %21 ], [ %17, %16 ]
ret i32 %25
}