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


x86 assembly (clang, -O0):
<_check_open_fail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1165 <_check_open_fail+0x35>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1175 <_check_open_fail+0x45>
lea    0xec0(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1175 <_check_open_fail+0x45>
mov    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e4d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
call   1040 <open_@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <check_fail@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_check_open_fail>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xee0(%rip),%rsi
cmovne %rdi,%rsi
lea    0xea9(%rip),%rdi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    0x2e7b(%rip),%rax
movq   $0x0,(%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1040 <open_@plt>
mov    %eax,%edi
mov    %r14d,%esi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <check_fail@plt>

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

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