#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_fd(int);
scalar_t__ errno;
int openat_(int, char const *, int);
int /*<<< orphan*/ printf(char *, int, char *, int);
int check_openat(int dfd, const char *path, int flags) {
  int fd;
  errno = 0;
  printf("Check success of openat(%d, '%s', %x)... ", dfd, path ?: "(null)",
         flags);
  fd = openat_(dfd, path, flags);
  return check_fd(fd);
}


x86 assembly (clang, -O0):
<check_openat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e97(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1175 <check_openat+0x45>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1185 <check_openat+0x55>
lea    0xeae(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1185 <check_openat+0x55>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <openat_@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <check_fd@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_openat>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e9d(%rip),%rax
movq   $0x0,(%rax)
test   %rsi,%rsi
lea    0xed6(%rip),%rdx
cmovne %rsi,%rdx
lea    0xea1(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%ecx
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <openat_@plt>
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <check_fd@plt>

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

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