#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int FileExists(char *sPath, char *sName) {
  struct stat st_buf;
  int status = stat(sPath, &st_buf);
  if (status != 0) {
    fprintf(stderr, "FileIsFile: unreachable file %s%s\n", sPath, sName);
    return -1;
  }
  if (S_ISREG(st_buf.st_mode)) {
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<FileExists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1183 <FileExists+0x53>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe8e(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <FileExists+0x78>
mov    -0x20(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     11a1 <FileExists+0x71>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <FileExists+0x78>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileExists>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     1168 <FileExists+0x38>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1176 <FileExists+0x46>
mov    (%rsp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"FileIsFile: unreachable file %s%s\0A\00"
define i32 @FileExists(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @stat(i8* %8, %struct.stat* %6)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
store i32 -1, i32* %3
br label %24
17: ; preds = %2
%18 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @S_ISREG(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %3
br label %24
23: ; preds = %17
store i32 -1, i32* %3
br label %24
24: ; preds = %23, %22, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"FileIsFile: unreachable file %s%s\0A\00"
define i32 @FileExists(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %0, %struct.stat* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %16
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i64 @S_ISREG(i32 %12)
%14 = icmp eq i64 %13, 0
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %10, %7
%17 = phi i32 [ -1, %7 ], [ %15, %10 ]
ret i32 %17
}