int chkaccess(path)
char *path;
{
  int x;
  if (path) {
    printf("   access check: no temporary id swapping...\n");
    x = access(path, 2);
    printf("   write-access to %s %s\n", path, x ? "FAILED" : "OK");
    return (x);
  }
  return (1);
}


x86 assembly (clang, -O0):
<chkaccess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118d <chkaccess+0x6d>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <access@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xee9(%rip),%rdx
lea    0xedb(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <chkaccess+0x74>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chkaccess>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     117f <chkaccess+0x4f>
mov    %rdi,%rbx
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <access@plt>
mov    %eax,%ebp
test   %eax,%eax
lea    0xec0(%rip),%rax
lea    0xeb2(%rip),%rdx
cmove  %rax,%rdx
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1184 <chkaccess+0x54>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c" access check: no temporary id swapping...\0A\00"
@.str.1 = [26 x i8] c" write-access to %s %s\0A\00"
@.str.2 = [7 x i8] c"FAILED\00"
@.str.3 = [3 x i8] c"OK\00"
define i32 @chkaccess(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @access to i32 (i8*, i32, ...)*)(i8* %9, i32 2)
store i32 %10, i32* %4
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %15)
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %19
18: ; preds = %1
store i32 1, i32* %2
br label %19
19: ; preds = %18, %7
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c" write-access to %s %s\0A\00"
@.str.2 = [7 x i8] c"FAILED\00"
@.str.3 = [3 x i8] c"OK\00"
@str = [45 x i8] c" access check: no temporary id swapping...\00"
define i32 @chkaccess(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @access to i32 (i8*, i32, ...)*)(i8* %0, i32 2)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %7)
br label %9
9: ; preds = %1, %3
%10 = phi i32 [ %5, %3 ], [ 1, %1 ]
ret i32 %10
}