#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 */
int /*<<< orphan*/ SPC_MSG(int, char const *);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ lstat(char const *, struct stat *);
char const *strerror(int /*<<< orphan*/);
int file_or_dir(const char *path) {
  struct stat buf;
  if (lstat(path, &buf) < 0) {
    SPC_MSG(2, path);
    SPC_MSG(2, strerror(errno));
    return -1;
  }
  if (S_ISDIR(buf.st_mode)) {
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<file_or_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jge    1198 <file_or_dir+0x58>
mov    -0x10(%rbp),%rsi
mov    $0x2,%edi
call   1050 <SPC_MSG@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
mov    $0x2,%edi
call   1050 <SPC_MSG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <file_or_dir+0x7d>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11b6 <file_or_dir+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11bd <file_or_dir+0x7d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_or_dir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <lstat@plt>
test   %rax,%rax
js     116d <file_or_dir+0x2d>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    119a <file_or_dir+0x5a>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1050 <SPC_MSG@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    $0x2,%edi
mov    %rax,%rsi
call   1050 <SPC_MSG@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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