#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 */
struct stat {
  int st_mode;
};

/* Variables and functions */
char *__imlib_FileRealFile(char const *);
scalar_t__ __imlib_IsRealFile(char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ stat(char *, struct stat *);
char *strdup(char const *);
int __imlib_FilePermissions(const char *s) {
  struct stat st;
  char *fl;
  if ((!s) || (!*s))
    return 0;
  if (__imlib_IsRealFile(s))
    fl = strdup(s);
  else
    fl = __imlib_FileRealFile(s);
  if (!fl)
    return 0;
  if (stat(fl, &st) < 0) {
    free(fl);
    return 0;
  }
  free(fl);
  return st.st_mode;
}


x86 assembly (clang, -O0):
<__imlib_FilePermissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1174 <__imlib_FilePermissions+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1180 <__imlib_FilePermissions+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1204 <__imlib_FilePermissions+0xb4>
mov    -0x10(%rbp),%rdi
call   1060 <__imlib_IsRealFile@plt>
cmp    $0x0,%rax
je     11a5 <__imlib_FilePermissions+0x55>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    11b2 <__imlib_FilePermissions+0x62>
mov    -0x10(%rbp),%rdi
call   1040 <__imlib_FileRealFile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c9 <__imlib_FilePermissions+0x79>
movl   $0x0,-0x4(%rbp)
jmp    1204 <__imlib_FilePermissions+0xb4>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11f5 <__imlib_FilePermissions+0xa5>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1204 <__imlib_FilePermissions+0xb4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__imlib_FilePermissions>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     11ac <__imlib_FilePermissions+0x5c>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11ac <__imlib_FilePermissions+0x5c>
mov    %rbx,%rdi
call   1060 <__imlib_IsRealFile@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     117e <__imlib_FilePermissions+0x2e>
call   1070 <strdup@plt>
jmp    1183 <__imlib_FilePermissions+0x33>
call   1040 <__imlib_FileRealFile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ac <__imlib_FilePermissions+0x5c>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
js     11ac <__imlib_FilePermissions+0x5c>
mov    0x8(%rsp),%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @__imlib_FilePermissions(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %5
%9 = tail call i64 @__imlib_IsRealFile(i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i8* @strdup(i8* %0)
br label %15
13: ; preds = %8
%14 = tail call i8* @__imlib_FileRealFile(i8* %0)
br label %15
15: ; preds = %13, %11
%16 = phi i8* [ %12, %11 ], [ %14, %13 ]
%17 = icmp eq i8* %16, null
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = call i64 @stat(i8* %16, %struct.stat* %2)
%20 = icmp slt i64 %19, 0
%21 = call i32 @free(i8* %16)
br i1 %20, label %25, label %22
22: ; preds = %18
%23 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%24 = load i32, i32* %23
br label %25
25: ; preds = %18, %15, %1, %5, %22
%26 = phi i32 [ %24, %22 ], [ 0, %5 ], [ 0, %1 ], [ 0, %15 ], [ 0, %18 ]
ret i32 %26
}