#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 check_fail(int, int, char const *);
scalar_t__ errno;
int openat_(int, char const *, int);
int /*<<< orphan*/ printf(char *, int, char *, int, char const *);
int _check_openat_fail(int dfd, const char *path, int flags, int expected_errno,
                       const char *errno_str) {
  int rc;
  printf("Check failure of openat(%d, '%s', %x) with %s... ", dfd,
         path ?: "(null)", flags, errno_str);
  errno = 0;
  rc = openat_(dfd, path, flags);
  return check_fail(rc, expected_errno, errno_str);
}


x86 assembly (clang, -O0):
<_check_openat_fail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     116e <_check_openat_fail+0x3e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    117e <_check_openat_fail+0x4e>
lea    0xebd(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    117e <_check_openat_fail+0x4e>
mov    -0x34(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e41(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <openat_@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <check_fail@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_check_openat_fail>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r15
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %edi,%ebp
test   %rsi,%rsi
lea    0xee2(%rip),%rdx
cmovne %rsi,%rdx
lea    0xea5(%rip),%rdi
mov    %ebp,%esi
mov    %r12d,%ecx
call   1030 <printf@plt>
mov    0x2e74(%rip),%rax
movq   $0x0,(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <openat_@plt>
mov    %eax,%edi
mov    %r14d,%esi
mov    %r15,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <check_fail@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"Check failure of openat(%d, '%s', %x) with %s... \00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i64 0
define i32 @_check_openat_fail(i32 %0, i8* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %5
br label %17
16: ; preds = %5
br label %17
17: ; preds = %16, %15
%18 = phi i8* [ %13, %15 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %16 ]
%19 = load i32, i32* %8
%20 = load i8*, i8** %10
%21 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %18, i32 %19, i8* %20)
store i64 0, i64* @errno
%22 = load i32, i32* %6
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @openat_(i32 %22, i8* %23, i32 %24)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = load i32, i32* %9
%28 = load i8*, i8** %10
%29 = call i32 @check_fail(i32 %26, i32 %27, i8* %28)
ret i32 %29
}

LLVM IR (-O2):
@.str = [50 x i8] c"Check failure of openat(%d, '%s', %x) with %s... \00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i64 0
define i32 @_check_openat_fail(i32 %0, i8* %1, i32 %2, i32 %3, i8* %4) {
%6 = icmp eq i8* %1, null
%7 = select i1 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %7, i32 %2, i8* %4)
store i64 0, i64* @errno
%9 = tail call i32 @openat_(i32 %0, i8* %1, i32 %2)
%10 = tail call i32 @check_fail(i32 %9, i32 %3, i8* %4)
ret i32 %10
}