#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 dummy;
};

/* 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_FileExists(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 1;
}


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

x86 assembly (clang, -O2):
<__imlib_FileExists>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r15d,%r15d
test   %rdi,%rdi
je     11ad <__imlib_FileExists+0x5d>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11ad <__imlib_FileExists+0x5d>
mov    %rbx,%rdi
call   1060 <__imlib_IsRealFile@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     1180 <__imlib_FileExists+0x30>
call   1070 <strdup@plt>
jmp    1185 <__imlib_FileExists+0x35>
call   1040 <__imlib_FileRealFile@plt>
mov    %rax,%r14
test   %rax,%rax
je     11ad <__imlib_FileExists+0x5d>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <free@plt>
shr    $0x3f,%r15
xor    $0x1,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @__imlib_FileExists(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 %37
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 %37
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 %37
34: ; preds = %27
%35 = load i8*, i8** %5
%36 = call i32 @free(i8* %35)
store i32 1, i32* %2
br label %37
37: ; preds = %34, %31, %26, %12
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @__imlib_FileExists(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %24, 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 %24, label %18
18: ; preds = %15
%19 = call i64 @stat(i8* %16, %struct.stat* %2)
%20 = call i32 @free(i8* %16)
%21 = lshr i64 %19, 63
%22 = trunc i64 %21 to i32
%23 = xor i32 %22, 1
br label %24
24: ; preds = %18, %15, %1, %5
%25 = phi i32 [ 0, %5 ], [ 0, %1 ], [ 0, %15 ], [ %23, %18 ]
ret i32 %25
}