#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*/ EXIT_FAILURE;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
int stat(char const *, struct stat *);
void verify_dir(const char *dir) {
  struct stat sb;
  int rc;
  rc = stat(dir, &sb);
  if (rc < 0)
    err(EXIT_FAILURE, "Could not access directory: %s", dir);
  if (!S_ISDIR(sb.st_mode))
    errx(EXIT_FAILURE, "Is not a directory: %s", dir);
}


x86 assembly (clang, -O0):
<verify_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117f <verify_dir+0x3f>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe86(%rip),%rsi
call   1060 <err@plt>
mov    -0x10(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11a9 <verify_dir+0x69>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1030 <errx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_dir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %eax,%eax
jns    116e <verify_dir+0x2e>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdx
call   1060 <err@plt>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
je     1181 <verify_dir+0x41>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdx
add    $0x10,%rsp
pop    %rbx
jmp    1030 <errx@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"Could not access directory: %s\00"
@.str.1 = [23 x i8] c"Is not a directory: %s\00"
define void @verify_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @stat(i8* %5, %struct.stat* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @EXIT_FAILURE
%11 = load i8*, i8** %2
%12 = call i32 @err(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %9, %1
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @S_ISDIR(i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i32, i32* @EXIT_FAILURE
%20 = load i8*, i8** %2
%21 = call i32 @errx(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %13
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"Could not access directory: %s\00"
@.str.1 = [23 x i8] c"Is not a directory: %s\00"
define void @verify_dir(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @err(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %6, %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @S_ISDIR(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @errx(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %14, %9
ret void
}