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

/* Variables and functions */
int /*<<< orphan*/ ENOTDIR;
int S_IFDIR;
int S_IFMT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(char *, char const *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ stat(char const *, struct stat *);
char *strerror(int /*<<< orphan*/);
void verifydir(const char *cp) {
  struct stat stb;
  if (stat(cp, &stb) >= 0) {
    if ((stb.st_mode & S_IFMT) == S_IFDIR)
      return;
    errno = ENOTDIR;
  }
  error("mrcp: %s: %s.\n", 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   1030 <stat@plt>
cmp    $0x0,%rax
jl     1196 <verifydir+0x56>
mov    -0x10(%rbp),%eax
mov    0x2e6b(%rip),%rcx
and    (%rcx),%eax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
jne    1184 <verifydir+0x44>
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2e6d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3c(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
lea    0xe46(%rip),%rdi
call   1040 <error@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<verifydir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
js     1175 <verifydir+0x35>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%eax
jne    1180 <verifydir+0x40>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
jmp    1192 <verifydir+0x52>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e40(%rip),%rax
mov    %edi,(%rax)
call   1060 <strerror@plt>
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <error@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@ENOTDIR = global i32 0
@errno = global i32 0
@.str = [15 x i8] c"mrcp: %s: %s.\0A\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 i64 @stat(i8* %4, %struct.stat* %3)
%6 = icmp sge i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* @S_IFMT
%11 = and i32 %9, %10
%12 = load i32, i32* @S_IFDIR
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %7
ret void
15: ; preds = %7
%16 = load i32, i32* @ENOTDIR
store i32 %16, i32* @errno
br label %17
17: ; preds = %15, %1
%18 = load i8*, i8** %2
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
}

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