#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*/ R_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ handle_error(int /*<<< orphan*/, char *);
int /*<<< orphan*/ handle_errorf(int, char *, char const *);
scalar_t__ strlen(char const *);
bool file_is_readable(const char *path) {
  if (!path || strlen(path) == 0) {
    handle_error(0, "Invalid argument.");
    return false;
  }
  if (access(path, R_OK) != 0) {
    handle_errorf(1, "File '%s' is not readable (access denied).", path);
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<file_is_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116a <file_is_readable+0x2a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1184 <file_is_readable+0x44>
xor    %edi,%edi
lea    0xe8d(%rip),%rsi
call   1060 <handle_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <file_is_readable+0x88>
mov    -0x10(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
je     11c1 <file_is_readable+0x81>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe62(%rip),%rsi
call   1040 <handle_errorf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <file_is_readable+0x88>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_is_readable>:
push   %rbx
test   %rdi,%rdi
je     116c <file_is_readable+0x3c>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     116c <file_is_readable+0x3c>
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
je     117e <file_is_readable+0x4e>
lea    0xeb7(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
call   1030 <handle_errorf@plt>
xor    %ebx,%ebx
jmp    1183 <file_is_readable+0x53>
lea    0xe8d(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <handle_error@plt>
jmp    1183 <file_is_readable+0x53>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Invalid argument.\00"
@R_OK = global i32 0
@.str.1 = [43 x i8] c"File '%s' is not readable (access denied).\00"
define i32 @file_is_readable(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6, %1
%11 = call i32 @handle_error(i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %21
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = load i32, i32* @R_OK
%15 = call i64 @access(i8* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = call i32 @handle_errorf(i32 1, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 0, i32* %2
br label %21
20: ; preds = %12
store i32 1, i32* %2
br label %21
21: ; preds = %20, %17, %10
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [18 x i8] c"Invalid argument.\00"
@R_OK = global i32 0
@.str.1 = [43 x i8] c"File '%s' is not readable (access denied).\00"
define i32 @file_is_readable(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3, %1
%7 = tail call i32 @handle_error(i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %3
%9 = load i32, i32* @R_OK
%10 = tail call i64 @access(i8* %0, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @handle_errorf(i32 1, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %8, %12, %6
%15 = phi i32 [ 0, %6 ], [ 0, %12 ], [ 1, %8 ]
ret i32 %15
}