#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 */

/* Variables and functions */
scalar_t__ EFAULT;
scalar_t__ ENOENT;
scalar_t__ ENOTDIR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int openat(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int fd;
  fd = openat(0, "foo", O_RDONLY);
  if (fd >= 0 || errno != ENOTDIR) {
    printf("1. %d %d\n", fd, (int)errno);
    exit(EXIT_FAILURE);
  }
  fd = openat(0, "", O_RDONLY);
  if (fd >= 0 || errno != ENOENT) {
    printf("2. %d %d\n", fd, (int)errno);
    exit(EXIT_FAILURE);
  }
  fd = openat(0, NULL, O_RDONLY);
  if (fd >= 0 || errno != EFAULT) {
    printf("3. %d %d\n", fd, (int)errno);
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
lea    0xeaf(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117d <main+0x4d>
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
je     11a6 <main+0x76>
mov    -0x8(%rbp),%esi
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
lea    0xe55(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11e4 <main+0xb4>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%rax
je     120d <main+0xdd>
mov    -0x8(%rbp),%esi
mov    0x2dda(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <openat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1248 <main+0x118>
mov    0x2d93(%rip),%rax
mov    (%rax),%rax
mov    0x2db1(%rip),%rcx
cmp    (%rcx),%rax
je     1271 <main+0x141>
mov    -0x8(%rbp),%esi
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
lea    0xdba(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e9d(%rip),%r14
mov    (%r14),%edx
lea    0xebb(%rip),%rsi
xor    %edi,%edi
call   1030 <openat@plt>
mov    0x2e75(%rip),%rbx
mov    (%rbx),%rdx
test   %eax,%eax
jns    11b7 <main+0x87>
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%rdx
jne    11b7 <main+0x87>
mov    (%r14),%edx
lea    0xe9d(%rip),%rsi
xor    %edi,%edi
call   1030 <openat@plt>
mov    (%rbx),%rdx
test   %eax,%eax
jns    11c0 <main+0x90>
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rdx
jne    11c0 <main+0x90>
mov    (%r14),%edx
xor    %edi,%edi
xor    %esi,%esi
call   1030 <openat@plt>
mov    (%rbx),%rdx
test   %eax,%eax
jns    11c9 <main+0x99>
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%rdx
jne    11c9 <main+0x99>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
lea    0xe46(%rip),%rdi
jmp    11d0 <main+0xa0>
lea    0xe47(%rip),%rdi
jmp    11d0 <main+0xa0>
lea    0xe48(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"foo\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOTDIR = global i64 0
@.str.1 = [10 x i8] c"1. %d %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@ENOENT = global i64 0
@.str.3 = [10 x i8] c"2. %d %d\0A\00"
@EFAULT = global i64 0
@.str.4 = [10 x i8] c"3. %d %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @openat(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp sge i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOTDIR
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %18
11: ; preds = %7, %0
%12 = load i32, i32* %2
%13 = load i64, i64* @errno
%14 = trunc i64 %13 to i32
%15 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %7
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @openat(i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = icmp sge i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENOENT
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %23, %18
%28 = load i32, i32* %2
%29 = load i64, i64* @errno
%30 = trunc i64 %29 to i32
%31 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %23
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @openat(i32 0, i8* null, i32 %35)
store i32 %36, i32* %2
%37 = load i32, i32* %2
%38 = icmp sge i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %34
%40 = load i64, i64* @errno
%41 = load i64, i64* @EFAULT
%42 = icmp ne i64 %40, %41
br i1 %42, label %43, label %50
43: ; preds = %39, %34
%44 = load i32, i32* %2
%45 = load i64, i64* @errno
%46 = trunc i64 %45 to i32
%47 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %39
%51 = load i32, i32* @EXIT_SUCCESS
%52 = call i32 @exit(i32 %51)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"foo\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOTDIR = global i64 0
@.str.1 = [10 x i8] c"1. %d %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@ENOENT = global i64 0
@.str.3 = [10 x i8] c"2. %d %d\0A\00"
@EFAULT = global i64 0
@.str.4 = [10 x i8] c"3. %d %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @openat(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
%4 = load i64, i64* @errno
%5 = load i64, i64* @ENOTDIR
%6 = icmp eq i64 %4, %5
%7 = select i1 %3, i1 %6, i1 false
br i1 %7, label %13, label %8
8: ; preds = %0
%9 = trunc i64 %4 to i32
%10 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @openat(i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp slt i32 %15, 0
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOENT
%19 = icmp eq i64 %17, %18
%20 = select i1 %16, i1 %19, i1 false
br i1 %20, label %26, label %21
21: ; preds = %13
%22 = trunc i64 %17 to i32
%23 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %13
%27 = load i32, i32* @O_RDONLY
%28 = tail call i32 @openat(i32 0, i8* null, i32 %27)
%29 = icmp slt i32 %28, 0
%30 = load i64, i64* @errno
%31 = load i64, i64* @EFAULT
%32 = icmp eq i64 %30, %31
%33 = select i1 %29, i1 %32, i1 false
br i1 %33, label %39, label %34
34: ; preds = %26
%35 = trunc i64 %30 to i32
%36 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %28, i32 %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %26
%40 = load i32, i32* @EXIT_SUCCESS
%41 = tail call i32 @exit(i32 %40)
unreachable
}