#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 R_OK;
int W_OK;
int X_OK;
int access(char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char *, char);
int maildir_access(const char *fname) {
  char path[1024];
  char *p;
  strcpy(path, fname);
  p = strrchr(path, '/');
  if (p != NULL)
    *p = '\0';
  if (p == NULL || *path == '\0')
    strcpy(path, ".");
  return access(path, R_OK | W_OK | X_OK);
}


x86 assembly (clang, -O0):
<maildir_access>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     117f <maildir_access+0x4f>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x418(%rbp)
je     119d <maildir_access+0x6d>
movsbl -0x410(%rbp),%eax
cmp    $0x0,%eax
jne    11b0 <maildir_access+0x80>
lea    -0x410(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
call   1050 <access@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maildir_access>:
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1161 <maildir_access+0x31>
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
jne    1170 <maildir_access+0x40>
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    0x2e59(%rip),%rax
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
mov    %rsp,%rdi
call   1050 <access@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
define i32 @maildir_access(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i8*
store i8* %0, i8** %2
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @strcpy(i8* %5, i8* %6)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = call i8* @strrchr(i8* %8, i8 signext 47)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i8*, i8** %4
store i8 0, i8* %13
br label %14
14: ; preds = %12, %1
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17, %14
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %22, %17
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = load i32, i32* @R_OK
%28 = load i32, i32* @W_OK
%29 = or i32 %27, %28
%30 = load i32, i32* @X_OK
%31 = or i32 %29, %30
%32 = call i32 @access(i8* %26, i32 %31)
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
define i32 @maildir_access(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i8* @strrchr(i8* %3, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %1
store i8 0, i8* %5
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1, %7
%11 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %7, %10
%13 = load i32, i32* @R_OK
%14 = load i32, i32* @W_OK
%15 = or i32 %14, %13
%16 = load i32, i32* @X_OK
%17 = or i32 %15, %16
%18 = call i32 @access(i8* %3, i32 %17)
ret i32 %18
}