#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;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int __imlib_FilePermissions(char *);
char *__imlib_FileRealFile(char const *);
scalar_t__ __imlib_IsRealFile(char const *);
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
int __imlib_FileCanRead(const char *s) {
  char *fl;
  int val;
  if (__imlib_IsRealFile(s))
    fl = strdup(s);
  else
    fl = __imlib_FileRealFile(s);
  if (!fl)
    return 0;
  if (!(__imlib_FilePermissions(fl) & (S_IRUSR | S_IRGRP | S_IROTH))) {
    free(fl);
    return 0;
  }
  val = (1 + access(fl, R_OK));
  free(fl);
  return val;
}


x86 assembly (clang, -O0):
<__imlib_FileCanRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <__imlib_IsRealFile@plt>
cmp    $0x0,%rax
je     1191 <__imlib_FileCanRead+0x31>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    119e <__imlib_FileCanRead+0x3e>
mov    -0x10(%rbp),%rdi
call   1050 <__imlib_FileRealFile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <__imlib_FileCanRead+0x55>
movl   $0x0,-0x4(%rbp)
jmp    1220 <__imlib_FileCanRead+0xc0>
mov    -0x18(%rbp),%rdi
call   1030 <__imlib_FilePermissions@plt>
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e12(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e01(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    11f9 <__imlib_FileCanRead+0x99>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1220 <__imlib_FileCanRead+0xc0>
mov    -0x18(%rbp),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__imlib_FileCanRead>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <__imlib_IsRealFile@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     117a <__imlib_FileCanRead+0x1a>
call   1080 <strdup@plt>
jmp    117f <__imlib_FileCanRead+0x1f>
call   1050 <__imlib_FileRealFile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c6 <__imlib_FileCanRead+0x66>
mov    %rbx,%rdi
call   1030 <__imlib_FilePermissions@plt>
mov    0x2e3a(%rip),%rcx
mov    0x2e43(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e30(%rip),%rcx
or     (%rcx),%edx
test   %eax,%edx
je     11ca <__imlib_FileCanRead+0x6a>
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
mov    %eax,%ebp
add    $0x1,%ebp
jmp    11cc <__imlib_FileCanRead+0x6c>
xor    %ebp,%ebp
jmp    11d4 <__imlib_FileCanRead+0x74>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@R_OK = global i32 0
define i32 @__imlib_FileCanRead(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @__imlib_IsRealFile(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %4
br label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i8* @__imlib_FileRealFile(i8* %13)
store i8* %14, i8** %4
br label %15
15: ; preds = %12, %9
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15
store i32 0, i32* %2
br label %40
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i32 @__imlib_FilePermissions(i8* %20)
%22 = load i32, i32* @S_IRUSR
%23 = load i32, i32* @S_IRGRP
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IROTH
%26 = or i32 %24, %25
%27 = and i32 %21, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
store i32 0, i32* %2
br label %40
32: ; preds = %19
%33 = load i8*, i8** %4
%34 = load i32, i32* @R_OK
%35 = call i32 @access(i8* %33, i32 %34)
%36 = add nsw i32 1, %35
store i32 %36, i32* %5
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %5
store i32 %39, i32* %2
br label %40
40: ; preds = %32, %29, %18
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@R_OK = global i32 0
define i32 @__imlib_FileCanRead(i8* %0) {
%2 = tail call i64 @__imlib_IsRealFile(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
br label %8
6: ; preds = %1
%7 = tail call i8* @__imlib_FileRealFile(i8* %0)
br label %8
8: ; preds = %6, %4
%9 = phi i8* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i8* %9, null
br i1 %10, label %27, label %11
11: ; preds = %8
%12 = tail call i32 @__imlib_FilePermissions(i8* %9)
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = and i32 %17, %12
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %11
%21 = load i32, i32* @R_OK
%22 = tail call i32 @access(i8* %9, i32 %21)
%23 = add nsw i32 %22, 1
br label %24
24: ; preds = %11, %20
%25 = phi i32 [ %23, %20 ], [ 0, %11 ]
%26 = tail call i32 @free(i8* %9)
br label %27
27: ; preds = %24, %8
%28 = phi i32 [ 0, %8 ], [ %25, %24 ]
ret i32 %28
}