#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 *_exm_file_concat(char const *, char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ stat(char *, struct stat *);
unsigned char _exm_file_exists(const char *path, const char *filename) {
  char *tmp;
  struct stat buf;
  unsigned char res = 1;
  tmp = _exm_file_concat(path, filename);
  if (!tmp)
    return 0;
  if (stat(tmp, &buf) != 0)
    res = 0;
  free(tmp);
  return res;
}


x86 assembly (clang, -O0):
<_exm_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x1,-0x29(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <_exm_file_concat@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1169 <_exm_file_exists+0x39>
movb   $0x0,-0x1(%rbp)
jmp    1193 <_exm_file_exists+0x63>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1184 <_exm_file_exists+0x54>
movb   $0x0,-0x29(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x29(%rbp),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_exm_file_exists>:
push   %rbp
push   %rbx
push   %rax
call   1050 <_exm_file_concat@plt>
test   %rax,%rax
je     115c <_exm_file_exists+0x2c>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <stat@plt>
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    115e <_exm_file_exists+0x2e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define zeroext i8 @_exm_file_exists(i8* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.stat
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 1, i8* %8
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @_exm_file_concat(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i8 0, i8* %3
br label %24
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i64 @stat(i8* %16, %struct.stat* %7)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i8 0, i8* %8
br label %20
20: ; preds = %19, %15
%21 = load i8*, i8** %6
%22 = call i32 @free(i8* %21)
%23 = load i8, i8* %8
store i8 %23, i8* %3
br label %24
24: ; preds = %20, %14
%25 = load i8, i8* %3
ret i8 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define zeroext i8 @_exm_file_exists(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i8* @_exm_file_concat(i8* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = call i64 @stat(i8* %5, %struct.stat* %3)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i8
%11 = call i32 @free(i8* %5)
br label %12
12: ; preds = %2, %7
%13 = phi i8 [ %10, %7 ], [ 0, %2 ]
ret i8 %13
}