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

/* Variables and functions */
scalar_t__ EISDIR;
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(int argc, char **argv) {
  int fd;
  int ret;
  char path[PATH_MAX];
  char buff[(4096)];
  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));
  }
  ret = read(fd, buff, sizeof(buff));
  if (ret >= 0) {
    fprintf(stderr, "read() on a directory should fail, but did not\n");
    close(fd);
    exit((1));
  }
  if (errno != EISDIR) {
    fprintf(stderr,
            "read() on a directory should set errno to EISDIR, "
            "instead got: %d - %s\n",
            errno, strerror(errno));
    close(fd);
    exit((1));
  }
  close(fd);
  exit((0));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x1040(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1038(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ea <main+0x7a>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x1038(%rbp),%rdi
mov    -0x1040(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe04(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x1038(%rbp),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    126e <main+0xfe>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1044(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x1044(%rbp),%edi
mov    %rax,%rdx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     12b8 <main+0x148>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%rax
mov    0x2d17(%rip),%rcx
cmp    (%rcx),%rax
je     1331 <main+0x1c1>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1054(%rbp)
mov    0x2cd8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1050(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x1054(%rbp),%edi
mov    -0x1050(%rbp),%rdx
mov    %rax,%rcx
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rax
mov    0x2e66(%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     11c3 <main+0x53>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x8(%rax),%rcx
lea    0xe3f(%rip),%rdx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
jns    1220 <main+0xb0>
mov    0x2dd6(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc5(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xe08(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    %eax,%ebx
lea    -0x1020(%rbp),%rsi
mov    %eax,%edi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1252 <main+0xe2>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    129f <main+0x12f>
mov    0x2d67(%rip),%rax
mov    (%rax),%r14
mov    0x2d7d(%rip),%rax
cmp    (%rax),%r14
jne    1276 <main+0x106>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%r15d
mov    %r14,%rdi
call   1090 <strerror@plt>
lea    0xdc9(%rip),%rsi
mov    %r15d,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1080 <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 i64 0
@.str.3 = [48 x i8] c"read() on a directory should fail, but did not\0A\00"
@EISDIR = global i64 0
@.str.4 = [72 x i8] c"read() on a directory should set errno to EISDIR, 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
%10 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %2
%22 = trunc i64 %12 to i32
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @snprintf(i8* %14, i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %14, i32 %27)
store i32 %28, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = load i64, i64* @errno
%33 = call i8* @strerror(i64 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %21
%37 = load i32, i32* %6
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 4096)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %36
%49 = load i64, i64* @errno
%50 = load i64, i64* @EISDIR
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i64, i64* @errno
%55 = load i64, i64* @errno
%56 = call i8* @strerror(i64 %55)
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i64 %54, i8* %56)
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %48
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
%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 i64 0
@.str.3 = [48 x i8] c"read() on a directory should fail, but did not\0A\00"
@EISDIR = global i64 0
@.str.4 = [72 x i8] c"read() on a directory should set errno to EISDIR, instead got: %d - %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 2)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %6, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %13
%27 = call i32 @read(i32 %18, i8* %7, i32 4096)
%28 = icmp sgt i32 %27, -1
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @close(i32 %18)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = load i64, i64* @errno
%36 = load i64, i64* @EISDIR
%37 = icmp eq i64 %35, %36
br i1 %37, label %44, label %38
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i8* @strerror(i64 %35)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i64 %35, i8* %40)
%42 = call i32 @close(i32 %18)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
%45 = call i32 @close(i32 %18)
%46 = call i32 @exit(i32 0)
unreachable
}