#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 */
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int ENODEV;
unsigned int *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned int *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                   int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(unsigned int *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char **argv) {
  int fd;
  unsigned int *ptr;
  char path[PATH_MAX];
  if (argc < 2) {
    fprintf(stderr, "Usage: path\n");
    exit((2));
  }
  snprintf(path, sizeof(path), "%s/.", argv[1]);
  if ((fd = open(path, O_RDONLY)) < 0) {
    fprintf(stderr, "Cannot open ./. : %s\n", strerror(errno));
    exit((2));
  }
  ptr = mmap(NULL, (4096), PROT_READ, MAP_PRIVATE, fd, 0);
  close(fd);
  if (ptr != MAP_FAILED) {
    fprintf(stderr,
            "mmap() on a directory should produce return "
            "MAP_FAILED, instead got %p\n",
            ptr);
    munmap(ptr, (4096));
    exit((1));
  }
  if (errno != ENODEV) {
    fprintf(stderr,
            "mmap() on a directory should return ENODEV, "
            "instead got %d (%s)\n",
            errno, strerror(errno));
    exit((1));
  }
  exit((0));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f1 <main+0x71>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe03(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1265 <main+0xe5>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edx
mov    0x2d3b(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%rax
mov    0x2d05(%rip),%rcx
cmp    (%rcx),%rax
je     12df <main+0x15f>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1000,%esi
call   1070 <munmap@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
mov    0x2cc9(%rip),%rcx
cmp    (%rcx),%eax
je     133e <main+0x1be>
mov    0x2cca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2cb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%edx
mov    %rax,%rcx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%rax
mov    0x2e57(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
cmp    $0x1,%edi
jg     11ca <main+0x4a>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x8(%rax),%rcx
lea    0xe38(%rip),%rdx
mov    %rbx,%rdi
call   1040 <snprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
jns    1226 <main+0xa6>
mov    0x2dcf(%rip),%rax
mov    (%rax),%ebx
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe02(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    %eax,%ebx
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
mov    0x2d78(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x2d4b(%rip),%rax
cmp    (%rax),%r14
jne    127d <main+0xfd>
mov    0x2d57(%rip),%rax
mov    (%rax),%ebx
mov    0x2d46(%rip),%rax
cmp    (%rax),%ebx
jne    12ae <main+0x12e>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    $0x1000,%esi
call   1070 <munmap@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%r14d
mov    %ebx,%edi
call   10a0 <strerror@plt>
lea    0xdaa(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"Usage: path\0A\00"
@.str.1 = [5 x i8] c"%s/.\00"
@O_RDONLY = global i32 0
@.str.2 = [22 x i8] c"Cannot open ./. : %s\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i32* null
@.str.3 = [72 x i8] c"mmap() on a directory should produce return MAP_FAILED, instead got %p\0A\00"
@ENODEV = global i32 0
@.str.4 = [65 x i8] c"mmap() on a directory should return ENODEV, instead got %d (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i8, i64 %11
store i64 %11, i64* %9
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %2
%21 = trunc i64 %11 to i32
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @snprintf(i8* %13, i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %13, i32 %26)
store i32 %27, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 2)
unreachable
35: ; preds = %20
%36 = load i32, i32* @PROT_READ
%37 = load i32, i32* @MAP_PRIVATE
%38 = load i32, i32* %6
%39 = call i32* @mmap(i32* null, i32 4096, i32 %36, i32 %37, i32 %38, i32 0)
store i32* %39, i32** %7
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
%42 = load i32*, i32** %7
%43 = load i32*, i32** @MAP_FAILED
%44 = icmp ne i32* %42, %43
br i1 %44, label %45, label %52
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = load i32*, i32** %7
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i32* %47)
%49 = load i32*, i32** %7
%50 = call i32 @munmap(i32* %49, i32 4096)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %35
%53 = load i32, i32* @errno
%54 = load i32, i32* @ENODEV
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %63
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %58, i8* %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %52
%64 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"Usage: path\0A\00"
@.str.1 = [5 x i8] c"%s/.\00"
@O_RDONLY = global i32 0
@.str.2 = [22 x i8] c"Cannot open ./. : %s\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i32* null
@.str.3 = [72 x i8] c"mmap() on a directory should produce return MAP_FAILED, instead got %p\0A\00"
@ENODEV = global i32 0
@.str.4 = [65 x i8] c"mmap() on a directory should return ENODEV, instead got %d (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %5, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 2)
unreachable
24: ; preds = %11
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @MAP_PRIVATE
%27 = call i32* @mmap(i32* null, i32 4096, i32 %25, i32 %26, i32 %16, i32 0)
%28 = call i32 @close(i32 %16)
%29 = load i32*, i32** @MAP_FAILED
%30 = icmp eq i32* %27, %29
br i1 %30, label %36, label %31
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i32* %27)
%34 = call i32 @munmap(i32* %27, i32 4096)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %24
%37 = load i32, i32* @errno
%38 = load i32, i32* @ENODEV
%39 = icmp eq i32 %37, %38
br i1 %39, label %45, label %40
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i8* @strerror(i32 %37)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %37, i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
%46 = call i32 @exit(i32 0)
unreachable
}