long CANCREAT(path)
long *path;
{
  register char *p;
  int i;
  if (access((char *)path, 02) == 0)
    return (0);
  if (p = strrchr((char *)path, '/')) {
    *p = '\0';
    i = access((char *)path, 03);
    *p = '/';
    return ((long)i);
  } else
    return ((long)access(".", 03));
}


x86 assembly (clang, -O0):
<CANCREAT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <access@plt>
cmp    $0x0,%eax
jne    1152 <CANCREAT+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <CANCREAT+0x95>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119c <CANCREAT+0x7c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b5 <CANCREAT+0x95>
lea    0xe5d(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <access@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANCREAT>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <access@plt>
test   %eax,%eax
je     117b <CANCREAT+0x5b>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1165 <CANCREAT+0x45>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <access@plt>
movb   $0x2f,(%rbx)
jmp    1178 <CANCREAT+0x58>
lea    0xe94(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <access@plt>
movslq %eax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i64 @CANCREAT(i64* %0) {
%2 = bitcast i64* %0 to i8*
%3 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @access to i32 (i8*, i32, ...)*)(i8* %2, i32 2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i32 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
store i8 0, i8* %6
%9 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @access to i32 (i8*, i32, ...)*)(i8* %2, i32 3)
store i8 47, i8* %6
%10 = sext i32 %9 to i64
br label %14
11: ; preds = %5
%12 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @access to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 3)
%13 = sext i32 %12 to i64
br label %14
14: ; preds = %1, %11, %8
%15 = phi i64 [ %10, %8 ], [ %13, %11 ], [ 0, %1 ]
ret i64 %15
}