#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 access(char *, int);
int /*<<< orphan*/ dirname(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char *filename = malloc(128);
  strcpy(filename, "./file");
  char *tmp = malloc(strlen(filename));
  strcpy(tmp, filename);
  dirname(tmp);
  printf("%s\n%s\n%d\n", filename, tmp, access(tmp, R_OK | W_OK));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1060 <dirname@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    0x2e14(%rip),%rax
or     (%rax),%esi
call   1080 <access@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    %eax,%ecx
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe88(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <dirname@plt>
mov    0x2e2c(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1080 <access@plt>
lea    0xe41(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"./file\00"
@.str.1 = [10 x i8] c"%s\0A%s\0A%d\0A\00"
@R_OK = global i32 0
@W_OK = global i32 0
define i32 @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @malloc(i32 128)
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = call i32 @strlen(i8* %6)
%8 = call i8* @malloc(i32 %7)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = load i8*, i8** %1
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = load i8*, i8** %2
%13 = call i32 @dirname(i8* %12)
%14 = load i8*, i8** %1
%15 = load i8*, i8** %2
%16 = load i8*, i8** %2
%17 = load i32, i32* @R_OK
%18 = load i32, i32* @W_OK
%19 = or i32 %17, %18
%20 = call i32 @access(i8* %16, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15, i32 %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"./file\00"
@.str.1 = [10 x i8] c"%s\0A%s\0A%d\0A\00"
@R_OK = global i32 0
@W_OK = global i32 0
define i32 @main() {
%1 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%2 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i32 @strcpy(i8* %4, i8* %1)
%6 = tail call i32 @dirname(i8* %4)
%7 = load i32, i32* @R_OK
%8 = load i32, i32* @W_OK
%9 = or i32 %8, %7
%10 = tail call i32 @access(i8* %4, i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %4, i32 %10)
ret i32 0
}