#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*/ ENOTDIR;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ run_err(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void verifydir(char *cp) {
  struct stat stb;
  if (!stat(cp, &stb)) {
    if (S_ISDIR(stb.st_mode))
      return;
    errno = ENOTDIR;
  }
  run_err("%s: %s", cp, strerror(errno));
  exit(1);
}


x86 assembly (clang, -O0):
<verifydir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%eax
jne    119c <verifydir+0x4c>
mov    -0x10(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     118a <verifydir+0x3a>
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2e67(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3e(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe41(%rip),%rdi
call   1040 <run_err@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<verifydir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %eax,%eax
jne    117a <verifydir+0x2a>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     1185 <verifydir+0x35>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
jmp    1197 <verifydir+0x47>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e43(%rip),%rax
mov    %edi,(%rax)
call   1070 <strerror@plt>
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <run_err@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@ENOTDIR = global i32 0
@errno = global i32 0
@.str = [7 x i8] c"%s: %s\00"
define void @verifydir(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @stat(i8* %4, %struct.stat* %3)
%6 = icmp ne i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i64 @S_ISDIR(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7
ret void
13: ; preds = %7
%14 = load i32, i32* @ENOTDIR
store i32 %14, i32* @errno
br label %15
15: ; preds = %13, %1
%16 = load i8*, i8** %2
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @run_err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@ENOTDIR = global i32 0
@errno = global i32 0
@.str = [7 x i8] c"%s: %s\00"
define void @verifydir(i8* %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, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = load i32, i32* @errno
br label %16
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @S_ISDIR(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %8
ret void
14: ; preds = %8
%15 = load i32, i32* @ENOTDIR
store i32 %15, i32* @errno
br label %16
16: ; preds = %6, %14
%17 = phi i32 [ %7, %6 ], [ %15, %14 ]
%18 = tail call i32 @strerror(i32 %17)
%19 = tail call i32 @run_err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %18)
%20 = tail call i32 @exit(i32 1)
unreachable
}