#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 */
int AT_FDCWD;
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ ENOTDIR;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ _check_openat_fail(int, char *, int /*<<< orphan*/,
                              int /*<<< orphan*/, char *);
scalar_t__ check_open(char *, int /*<<< orphan*/);
scalar_t__ check_openat(int, char *, int /*<<< orphan*/);
scalar_t__ check_proc();
scalar_t__ check_setfl();
int openat_or_die(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ prerequisites();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int fail = 0;
  int dot_dfd;
  int subdir_dfd;
  int file_fd;
  prerequisites();
  dot_dfd = openat_or_die(AT_FDCWD, ".", O_RDONLY);
  subdir_dfd = openat_or_die(AT_FDCWD, "subdir", O_RDONLY);
  file_fd = openat_or_die(AT_FDCWD, "topfile", O_RDONLY);
  fail += check_open("topfile", O_RDONLY);
  fail += check_open("subdir/bottomfile", O_RDONLY);
  fail += check_openat(AT_FDCWD, "topfile", O_RDONLY);
  fail += check_openat(AT_FDCWD, "subdir/bottomfile", O_RDONLY);
  fail += check_openat(dot_dfd, "topfile", O_RDONLY);
  fail += check_openat(dot_dfd, "subdir/bottomfile", O_RDONLY);
  fail += check_openat(dot_dfd, "subdir/../topfile", O_RDONLY);
  fail += check_open("subdir/../topfile", O_RDONLY);
  fail += check_openat(subdir_dfd, "../topfile", O_RDONLY);
  fail += check_openat(subdir_dfd, "bottomfile", O_RDONLY);
  fail += check_openat(subdir_dfd, "../subdir/bottomfile", O_RDONLY);
  fail += check_openat(subdir_dfd, "symlinkup", O_RDONLY);
  fail += check_openat(subdir_dfd, "symlinkout", O_RDONLY);
  fail += check_open("/etc/passwd", O_RDONLY);
  fail += check_openat(AT_FDCWD, "/etc/passwd", O_RDONLY);
  fail += check_openat(dot_dfd, "/etc/passwd", O_RDONLY);
  fail += check_openat(subdir_dfd, "/etc/passwd", O_RDONLY);
  fail += _check_openat_fail(AT_FDCWD, "bogus", O_RDONLY, ENOENT, "ENOENT");
  fail += _check_openat_fail(dot_dfd, "bogus", O_RDONLY, ENOENT, "ENOENT");
  fail += _check_openat_fail(999, "bogus", O_RDONLY, EBADF, "EBADF");
  fail += _check_openat_fail(file_fd, "bogus", O_RDONLY, ENOTDIR, "ENOTDIR");
  printf("Skipping O_BENEATH tests due to missing #define\n");
  fail += check_proc();
  fail += check_setfl();
  if (fail > 0)
    printf("%d tests failed\n", fail);
  return fail;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1090 <prerequisites@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    0xe43(%rip),%rsi
call   1070 <openat_or_die@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
lea    0xe24(%rip),%rsi
call   1070 <openat_or_die@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
lea    0xe14(%rip),%rsi
call   1070 <openat_or_die@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
lea    0xdfc(%rip),%rdi
call   1030 <check_open@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    0xde5(%rip),%rdi
call   1030 <check_open@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
lea    0xdaf(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
lea    0xd8f(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
lea    0xd5f(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d10(%rip),%rax
mov    (%rax),%edx
lea    0xd45(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2ceb(%rip),%rax
mov    (%rax),%edx
lea    0xd0b(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%esi
lea    0xce9(%rip),%rdi
call   1030 <check_open@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2ca4(%rip),%rax
mov    (%rax),%edx
lea    0xccb(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c7f(%rip),%rax
mov    (%rax),%edx
lea    0xcbb(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c5a(%rip),%rax
mov    (%rax),%edx
lea    0xc8c(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c35(%rip),%rax
mov    (%rax),%edx
lea    0xc7c(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c10(%rip),%rax
mov    (%rax),%edx
lea    0xc61(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2bee(%rip),%rax
mov    (%rax),%esi
lea    0xc4a(%rip),%rdi
call   1030 <check_open@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2ba4(%rip),%rax
mov    (%rax),%edi
mov    0x2bc3(%rip),%rax
mov    (%rax),%edx
lea    0xc1f(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2b9e(%rip),%rax
mov    (%rax),%edx
lea    0xbfa(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2b79(%rip),%rax
mov    (%rax),%edx
lea    0xbd5(%rip),%rsi
call   1060 <check_openat@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2b2f(%rip),%rax
mov    (%rax),%edi
mov    0x2b4e(%rip),%rax
mov    (%rax),%edx
mov    0x2b25(%rip),%rax
mov    (%rax),%ecx
lea    0xbad(%rip),%rsi
lea    0xbac(%rip),%r8
call   1040 <_check_openat_fail@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2b19(%rip),%rax
mov    (%rax),%edx
mov    0x2af0(%rip),%rax
mov    (%rax),%ecx
lea    0xb78(%rip),%rsi
lea    0xb77(%rip),%r8
call   1040 <_check_openat_fail@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2ae7(%rip),%rax
mov    (%rax),%edx
mov    0x2ace(%rip),%rax
mov    (%rax),%ecx
mov    $0x3e7,%edi
lea    0xb41(%rip),%rsi
lea    0xb47(%rip),%r8
call   1040 <_check_openat_fail@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2aad(%rip),%rax
mov    (%rax),%edx
mov    0x2abc(%rip),%rax
mov    (%rax),%ecx
lea    0xb0c(%rip),%rsi
lea    0xb18(%rip),%r8
call   1040 <_check_openat_fail@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
lea    0xb07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <check_proc@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   10a0 <check_setfl@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    15af <main+0x42f>
mov    -0x14(%rbp),%esi
lea    0xaf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10a0 <prerequisites@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    %rax,%rbx
mov    0x2e2b(%rip),%r12
mov    (%r12),%edx
lea    0xe40(%rip),%rsi
call   1080 <openat_or_die@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    (%r12),%edx
lea    0xe2d(%rip),%rsi
call   1080 <openat_or_die@plt>
mov    %eax,%r13d
mov    (%rbx),%edi
mov    %rbx,%rbp
mov    (%r12),%edx
lea    0xe26(%rip),%r15
mov    %r15,%rsi
call   1080 <openat_or_die@plt>
mov    %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %r15,%rdi
call   1030 <check_open@plt>
mov    %rax,%rbx
mov    (%r12),%esi
lea    0xe0b(%rip),%rdi
call   1030 <check_open@plt>
mov    %rax,%r14
add    %ebx,%r14d
mov    0x0(%rbp),%edi
mov    (%r12),%edx
mov    %r15,%rsi
call   1070 <check_openat@plt>
mov    %rax,%rbx
add    %r14d,%ebx
mov    0x0(%rbp),%edi
mov    (%r12),%edx
lea    0xddd(%rip),%rsi
call   1070 <check_openat@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    (%r12),%edx
mov    (%rsp),%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <check_openat@plt>
mov    %rax,%r14
add    %ebp,%r14d
mov    (%r12),%edx
mov    %ebx,%edi
mov    %ebx,%r15d
lea    0xdac(%rip),%rsi
call   1070 <check_openat@plt>
mov    %rax,%rbp
add    %r14d,%ebp
mov    (%r12),%edx
lea    0xd81(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <check_openat@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    (%r12),%esi
mov    %r14,%rdi
call   1030 <check_open@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    (%r12),%edx
lea    0xd5d(%rip),%rsi
mov    %r13d,%edi
call   1070 <check_openat@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    (%r12),%edx
lea    0xd5a(%rip),%rsi
mov    %r13d,%edi
call   1070 <check_openat@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    (%r12),%edx
lea    0xd38(%rip),%rsi
mov    %r13d,%edi
call   1070 <check_openat@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    (%r12),%edx
lea    0xd35(%rip),%rsi
mov    %r13d,%edi
call   1070 <check_openat@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    (%r12),%edx
lea    0xd27(%rip),%rsi
mov    %r13d,%edi
call   1070 <check_openat@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    (%r12),%esi
lea    0xd1a(%rip),%r14
mov    %r14,%rdi
call   1030 <check_open@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%edx
mov    %r14,%rsi
call   1070 <check_openat@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    (%r12),%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   1070 <check_openat@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    (%r12),%edx
mov    %r13d,%edi
mov    %r14,%rsi
call   1070 <check_openat@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%edx
mov    0x2c32(%rip),%r13
mov    0x0(%r13),%ecx
lea    0xcb8(%rip),%r14
lea    0xcb7(%rip),%r8
mov    %r14,%rsi
call   1050 <_check_openat_fail@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    (%r12),%edx
mov    0x0(%r13),%ecx
mov    %r15d,%edi
mov    %r14,%rsi
lea    0xc95(%rip),%r8
call   1050 <_check_openat_fail@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    (%r12),%edx
mov    0x2bf9(%rip),%rax
mov    (%rax),%ecx
lea    0xc7e(%rip),%r8
mov    $0x3e7,%edi
mov    %r14,%rsi
call   1050 <_check_openat_fail@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    (%r12),%edx
mov    0x2bfb(%rip),%rax
mov    (%rax),%ecx
lea    0xc5e(%rip),%r8
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   1050 <_check_openat_fail@plt>
mov    %rax,%rbx
add    %ebp,%ebx
lea    0xc5f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <check_proc@plt>
mov    %rax,%rbp
add    %ebx,%ebp
xor    %eax,%eax
call   10b0 <check_setfl@plt>
mov    %rax,%rbx
add    %ebp,%ebx
test   %ebx,%ebx
jle    144f <main+0x2bf>
lea    0xc26(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AT_FDCWD = global i32 0
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"subdir\00"
@.str.2 = [8 x i8] c"topfile\00"
@.str.3 = [18 x i8] c"subdir/bottomfile\00"
@.str.4 = [18 x i8] c"subdir/../topfile\00"
@.str.5 = [11 x i8] c"../topfile\00"
@.str.6 = [11 x i8] c"bottomfile\00"
@.str.7 = [21 x i8] c"../subdir/bottomfile\00"
@.str.8 = [10 x i8] c"symlinkup\00"
@.str.9 = [11 x i8] c"symlinkout\00"
@.str.10 = [12 x i8] c"/etc/passwd\00"
@.str.11 = [6 x i8] c"bogus\00"
@ENOENT = global i32 0
@.str.12 = [7 x i8] c"ENOENT\00"
@EBADF = global i32 0
@.str.13 = [6 x i8] c"EBADF\00"
@ENOTDIR = global i32 0
@.str.14 = [8 x i8] c"ENOTDIR\00"
@.str.15 = [49 x i8] c"Skipping O_BENEATH tests due to missing #define\0A\00"
@.str.16 = [17 x i8] c"%d tests failed\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 i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = call i32 (...) @prerequisites()
%11 = load i32, i32* @AT_FDCWD
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @openat_or_die(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* @AT_FDCWD
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @openat_or_die(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* @AT_FDCWD
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @openat_or_die(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* @O_RDONLY
%21 = call i64 @check_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = add nsw i64 %23, %21
%25 = trunc i64 %24 to i32
store i32 %25, i32* %6
%26 = load i32, i32* @O_RDONLY
%27 = call i64 @check_open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %6
%32 = load i32, i32* @AT_FDCWD
%33 = load i32, i32* @O_RDONLY
%34 = call i64 @check_openat(i32 %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %6
%39 = load i32, i32* @AT_FDCWD
%40 = load i32, i32* @O_RDONLY
%41 = call i64 @check_openat(i32 %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = add nsw i64 %43, %41
%45 = trunc i64 %44 to i32
store i32 %45, i32* %6
%46 = load i32, i32* %7
%47 = load i32, i32* @O_RDONLY
%48 = call i64 @check_openat(i32 %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %6
%53 = load i32, i32* %7
%54 = load i32, i32* @O_RDONLY
%55 = call i64 @check_openat(i32 %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = add nsw i64 %57, %55
%59 = trunc i64 %58 to i32
store i32 %59, i32* %6
%60 = load i32, i32* %7
%61 = load i32, i32* @O_RDONLY
%62 = call i64 @check_openat(i32 %60, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = add nsw i64 %64, %62
%66 = trunc i64 %65 to i32
store i32 %66, i32* %6
%67 = load i32, i32* @O_RDONLY
%68 = call i64 @check_open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = add nsw i64 %70, %68
%72 = trunc i64 %71 to i32
store i32 %72, i32* %6
%73 = load i32, i32* %8
%74 = load i32, i32* @O_RDONLY
%75 = call i64 @check_openat(i32 %73, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = add nsw i64 %77, %75
%79 = trunc i64 %78 to i32
store i32 %79, i32* %6
%80 = load i32, i32* %8
%81 = load i32, i32* @O_RDONLY
%82 = call i64 @check_openat(i32 %80, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %6
%84 = sext i32 %83 to i64
%85 = add nsw i64 %84, %82
%86 = trunc i64 %85 to i32
store i32 %86, i32* %6
%87 = load i32, i32* %8
%88 = load i32, i32* @O_RDONLY
%89 = call i64 @check_openat(i32 %87, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %88)
%90 = load i32, i32* %6
%91 = sext i32 %90 to i64
%92 = add nsw i64 %91, %89
%93 = trunc i64 %92 to i32
store i32 %93, i32* %6
%94 = load i32, i32* %8
%95 = load i32, i32* @O_RDONLY
%96 = call i64 @check_openat(i32 %94, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %95)
%97 = load i32, i32* %6
%98 = sext i32 %97 to i64
%99 = add nsw i64 %98, %96
%100 = trunc i64 %99 to i32
store i32 %100, i32* %6
%101 = load i32, i32* %8
%102 = load i32, i32* @O_RDONLY
%103 = call i64 @check_openat(i32 %101, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 %102)
%104 = load i32, i32* %6
%105 = sext i32 %104 to i64
%106 = add nsw i64 %105, %103
%107 = trunc i64 %106 to i32
store i32 %107, i32* %6
%108 = load i32, i32* @O_RDONLY
%109 = call i64 @check_open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %108)
%110 = load i32, i32* %6
%111 = sext i32 %110 to i64
%112 = add nsw i64 %111, %109
%113 = trunc i64 %112 to i32
store i32 %113, i32* %6
%114 = load i32, i32* @AT_FDCWD
%115 = load i32, i32* @O_RDONLY
%116 = call i64 @check_openat(i32 %114, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %115)
%117 = load i32, i32* %6
%118 = sext i32 %117 to i64
%119 = add nsw i64 %118, %116
%120 = trunc i64 %119 to i32
store i32 %120, i32* %6
%121 = load i32, i32* %7
%122 = load i32, i32* @O_RDONLY
%123 = call i64 @check_openat(i32 %121, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %122)
%124 = load i32, i32* %6
%125 = sext i32 %124 to i64
%126 = add nsw i64 %125, %123
%127 = trunc i64 %126 to i32
store i32 %127, i32* %6
%128 = load i32, i32* %8
%129 = load i32, i32* @O_RDONLY
%130 = call i64 @check_openat(i32 %128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %129)
%131 = load i32, i32* %6
%132 = sext i32 %131 to i64
%133 = add nsw i64 %132, %130
%134 = trunc i64 %133 to i32
store i32 %134, i32* %6
%135 = load i32, i32* @AT_FDCWD
%136 = load i32, i32* @O_RDONLY
%137 = load i32, i32* @ENOENT
%138 = call i64 @_check_openat_fail(i32 %135, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %136, i32 %137, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%139 = load i32, i32* %6
%140 = sext i32 %139 to i64
%141 = add nsw i64 %140, %138
%142 = trunc i64 %141 to i32
store i32 %142, i32* %6
%143 = load i32, i32* %7
%144 = load i32, i32* @O_RDONLY
%145 = load i32, i32* @ENOENT
%146 = call i64 @_check_openat_fail(i32 %143, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %144, i32 %145, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%147 = load i32, i32* %6
%148 = sext i32 %147 to i64
%149 = add nsw i64 %148, %146
%150 = trunc i64 %149 to i32
store i32 %150, i32* %6
%151 = load i32, i32* @O_RDONLY
%152 = load i32, i32* @EBADF
%153 = call i64 @_check_openat_fail(i32 999, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %151, i32 %152, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%154 = load i32, i32* %6
%155 = sext i32 %154 to i64
%156 = add nsw i64 %155, %153
%157 = trunc i64 %156 to i32
store i32 %157, i32* %6
%158 = load i32, i32* %9
%159 = load i32, i32* @O_RDONLY
%160 = load i32, i32* @ENOTDIR
%161 = call i64 @_check_openat_fail(i32 %158, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %159, i32 %160, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
%162 = load i32, i32* %6
%163 = sext i32 %162 to i64
%164 = add nsw i64 %163, %161
%165 = trunc i64 %164 to i32
store i32 %165, i32* %6
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.15, i64 0, i64 0))
%167 = call i64 (...) @check_proc()
%168 = load i32, i32* %6
%169 = sext i32 %168 to i64
%170 = add nsw i64 %169, %167
%171 = trunc i64 %170 to i32
store i32 %171, i32* %6
%172 = call i64 (...) @check_setfl()
%173 = load i32, i32* %6
%174 = sext i32 %173 to i64
%175 = add nsw i64 %174, %172
%176 = trunc i64 %175 to i32
store i32 %176, i32* %6
%177 = load i32, i32* %6
%178 = icmp sgt i32 %177, 0
br i1 %178, label %179, label %182
179: ; preds = %2
%180 = load i32, i32* %6
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), i32 %180)
br label %182
182: ; preds = %179, %2
%183 = load i32, i32* %6
ret i32 %183
}

LLVM IR (-O2):
@AT_FDCWD = global i32 0
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"subdir\00"
@.str.2 = [8 x i8] c"topfile\00"
@.str.3 = [18 x i8] c"subdir/bottomfile\00"
@.str.4 = [18 x i8] c"subdir/../topfile\00"
@.str.5 = [11 x i8] c"../topfile\00"
@.str.6 = [11 x i8] c"bottomfile\00"
@.str.7 = [21 x i8] c"../subdir/bottomfile\00"
@.str.8 = [10 x i8] c"symlinkup\00"
@.str.9 = [11 x i8] c"symlinkout\00"
@.str.10 = [12 x i8] c"/etc/passwd\00"
@.str.11 = [6 x i8] c"bogus\00"
@ENOENT = global i32 0
@.str.12 = [7 x i8] c"ENOENT\00"
@EBADF = global i32 0
@.str.13 = [6 x i8] c"EBADF\00"
@ENOTDIR = global i32 0
@.str.14 = [8 x i8] c"ENOTDIR\00"
@.str.16 = [17 x i8] c"%d tests failed\0A\00"
@str = [48 x i8] c"Skipping O_BENEATH tests due to missing #define\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @prerequisites()
%4 = load i32, i32* @AT_FDCWD
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @openat_or_die(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @AT_FDCWD
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @openat_or_die(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @AT_FDCWD
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @openat_or_die(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @O_RDONLY
%14 = tail call i64 @check_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @O_RDONLY
%16 = tail call i64 @check_open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = add i64 %16, %14
%18 = load i32, i32* @AT_FDCWD
%19 = load i32, i32* @O_RDONLY
%20 = tail call i64 @check_openat(i32 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = add i64 %17, %20
%22 = load i32, i32* @AT_FDCWD
%23 = load i32, i32* @O_RDONLY
%24 = tail call i64 @check_openat(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = add i64 %21, %24
%26 = load i32, i32* @O_RDONLY
%27 = tail call i64 @check_openat(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = add i64 %25, %27
%29 = load i32, i32* @O_RDONLY
%30 = tail call i64 @check_openat(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = add i64 %28, %30
%32 = load i32, i32* @O_RDONLY
%33 = tail call i64 @check_openat(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = add i64 %31, %33
%35 = load i32, i32* @O_RDONLY
%36 = tail call i64 @check_open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = add i64 %34, %36
%38 = load i32, i32* @O_RDONLY
%39 = tail call i64 @check_openat(i32 %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = add i64 %37, %39
%41 = load i32, i32* @O_RDONLY
%42 = tail call i64 @check_openat(i32 %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%43 = add i64 %40, %42
%44 = load i32, i32* @O_RDONLY
%45 = tail call i64 @check_openat(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %44)
%46 = add i64 %43, %45
%47 = load i32, i32* @O_RDONLY
%48 = tail call i64 @check_openat(i32 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %47)
%49 = add i64 %46, %48
%50 = load i32, i32* @O_RDONLY
%51 = tail call i64 @check_openat(i32 %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 %50)
%52 = add i64 %49, %51
%53 = load i32, i32* @O_RDONLY
%54 = tail call i64 @check_open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %53)
%55 = add i64 %52, %54
%56 = load i32, i32* @AT_FDCWD
%57 = load i32, i32* @O_RDONLY
%58 = tail call i64 @check_openat(i32 %56, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %57)
%59 = add i64 %55, %58
%60 = load i32, i32* @O_RDONLY
%61 = tail call i64 @check_openat(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %60)
%62 = add i64 %59, %61
%63 = load i32, i32* @O_RDONLY
%64 = tail call i64 @check_openat(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %63)
%65 = add i64 %62, %64
%66 = load i32, i32* @AT_FDCWD
%67 = load i32, i32* @O_RDONLY
%68 = load i32, i32* @ENOENT
%69 = tail call i64 @_check_openat_fail(i32 %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %67, i32 %68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%70 = add i64 %65, %69
%71 = load i32, i32* @O_RDONLY
%72 = load i32, i32* @ENOENT
%73 = tail call i64 @_check_openat_fail(i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %71, i32 %72, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%74 = add i64 %70, %73
%75 = load i32, i32* @O_RDONLY
%76 = load i32, i32* @EBADF
%77 = tail call i64 @_check_openat_fail(i32 999, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %75, i32 %76, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%78 = add i64 %74, %77
%79 = load i32, i32* @O_RDONLY
%80 = load i32, i32* @ENOTDIR
%81 = tail call i64 @_check_openat_fail(i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %79, i32 %80, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
%82 = add i64 %78, %81
%83 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%84 = tail call i64 (...) @check_proc()
%85 = add i64 %82, %84
%86 = tail call i64 (...) @check_setfl()
%87 = add i64 %85, %86
%88 = trunc i64 %87 to i32
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %2
%91 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), i32 %88)
br label %92
92: ; preds = %90, %2
ret i32 %88
}