#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 */
int /*<<< orphan*/ free(char *);
scalar_t__ lstat(char *, struct stat *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strdup(char const *);
int strlen(char const *);
int clind_file_exists(const char *dir, const char *file) {
  int ret = 0;
  if (file) {
    char *fname = strdup(file);
    struct stat statbuf;
    if (dir) {
      free(fname);
      fname = (char *)malloc(strlen(dir) + 1 + strlen(file) + 1);
      strcpy(fname, dir);
      strcpy(fname + strlen(fname), "/");
      strcpy(fname + strlen(fname), file);
    }
    if (lstat(fname, &statbuf) == 0) {
      ret = 1;
    }
    free(fname);
  }
  return ret;
}


x86 assembly (clang, -O0):
<clind_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1249 <clind_file_exists+0xe9>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1222 <clind_file_exists+0xc2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe06(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <lstat@plt>
cmp    $0x0,%rax
jne    1240 <clind_file_exists+0xe0>
movl   $0x1,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clind_file_exists>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1207 <clind_file_exists+0xa7>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
test   %r15,%r15
je     11e9 <clind_file_exists+0x89>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
lea    0xe32(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <lstat@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1209 <clind_file_exists+0xa9>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"/\00"
define i32 @clind_file_exists(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.stat
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %51
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %43
15: ; preds = %10
%16 = load i8*, i8** %6
%17 = call i32 @free(i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %20, %22
%24 = add nsw i32 %23, 1
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %6
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%36 = load i8*, i8** %6
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i8*, i8** %4
%42 = call i32 @strcpy(i8* %40, i8* %41)
br label %43
43: ; preds = %15, %10
%44 = load i8*, i8** %6
%45 = call i64 @lstat(i8* %44, %struct.stat* %7)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 1, i32* %5
br label %48
48: ; preds = %47, %43
%49 = load i8*, i8** %6
%50 = call i32 @free(i8* %49)
br label %51
51: ; preds = %48, %2
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"/\00"
define i32 @clind_file_exists(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = icmp eq i8* %1, null
br i1 %4, label %32, label %5
5: ; preds = %2
%6 = tail call i8* @strdup(i8* %1)
%7 = bitcast %struct.stat* %3 to i8*
%8 = icmp eq i8* %0, null
br i1 %8, label %26, label %9
9: ; preds = %5
%10 = tail call i32 @free(i8* %6)
%11 = tail call i32 @strlen(i8* %0)
%12 = tail call i32 @strlen(i8* %1)
%13 = add i32 %11, 2
%14 = add i32 %13, %12
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @strcpy(i8* %16, i8* %0)
%18 = tail call i32 @strlen(i8* %16)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = tail call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @strlen(i8* %16)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %16, i64 %23
%25 = tail call i32 @strcpy(i8* %24, i8* %1)
br label %26
26: ; preds = %9, %5
%27 = phi i8* [ %16, %9 ], [ %6, %5 ]
%28 = call i64 @lstat(i8* %27, %struct.stat* %3)
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
%31 = tail call i32 @free(i8* %27)
br label %32
32: ; preds = %26, %2
%33 = phi i32 [ %30, %26 ], [ 0, %2 ]
ret i32 %33
}