#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void failOpenNonexistingFile() {
  int fd;
  if ((fd = open("./nosuchfile", O_RDONLY)) == -1) {
    fprintf(stderr, "Unable to open './nosuchfile': %s\n", strerror(errno));
  }
  (void)close(fd);
}


x86 assembly (clang, -O0):
<failOpenNonexistingFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    1195 <failOpenNonexistingFile+0x55>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<failOpenNonexistingFile>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1187 <failOpenNonexistingFile+0x47>
mov    0x2e72(%rip),%rax
mov    (%rax),%ebp
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe90(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <close@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"./nosuchfile\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [35 x i8] c"Unable to open './nosuchfile': %s\0A\00"
@errno = global i32 0
define void @failOpenNonexistingFile() {
%1 = alloca i32
%2 = load i32, i32* @O_RDONLY
%3 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %5, %0
%11 = load i32, i32* %1
%12 = call i32 @close(i32 %11)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"./nosuchfile\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [35 x i8] c"Unable to open './nosuchfile': %s\0A\00"
@errno = global i32 0
define void @failOpenNonexistingFile() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %4, %0
%10 = tail call i32 @close(i32 %2)
ret void
}