#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_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ __PHYSFS_setError(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int stat(char const *, struct stat *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int __PHYSFS_platformIsDirectory(const char *fname) {
  struct stat statbuf;
  if (stat(fname, &statbuf) == -1) {
    __PHYSFS_setError(strerror(errno));
    return 0;
  };
  return ((S_ISDIR(statbuf.st_mode)) ? 1 : 0);
}


x86 assembly (clang, -O0):
<__PHYSFS_platformIsDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1183 <__PHYSFS_platformIsDirectory+0x43>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%edi
call   1050 <__PHYSFS_setError@plt>
movl   $0x0,-0x4(%rbp)
jmp    119f <__PHYSFS_platformIsDirectory+0x5f>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__PHYSFS_platformIsDirectory>:
push   %rax
mov    %rsp,%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     1163 <__PHYSFS_platformIsDirectory+0x23>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
pop    %rcx
ret
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%edi
call   1050 <__PHYSFS_setError@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i32 0
define i32 @__PHYSFS_platformIsDirectory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @stat(i8* %5, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @__PHYSFS_setError(i32 %10)
store i32 0, i32* %2
br label %19
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 1, i32 0
store i32 %18, i32* %2
br label %19
19: ; preds = %12, %8
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i32 0
define i32 @__PHYSFS_platformIsDirectory(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @__PHYSFS_setError(i32 %8)
br label %16
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i64 @S_ISDIR(i32 %12)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %10, %6
%17 = phi i32 [ 0, %6 ], [ %15, %10 ]
ret i32 %17
}