#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int main(void) {
  FILE *fp;
  printf("errno = %d\n", errno);
  fp = fopen("test.txt", "r");
  if (fp == NULL) {
    printf("errno = %d\n", errno);
    printf("strerror(errno) = %s\n", strerror(errno));
    perror("fopen error!");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d6 <main+0x96>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <main+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e95(%rip),%r14
mov    (%r14),%esi
lea    0xeab(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea7(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1180 <main+0x40>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%r14),%esi
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%edi
call   1060 <strerror@plt>
lea    0xe77(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe7c(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1176 <main+0x36>

LLVM IR (-O0):
@.str = [12 x i8] c"errno = %d\0A\00"
@errno = global i32 0
@.str.1 = [9 x i8] c"test.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"strerror(errno) = %s\0A\00"
@.str.4 = [13 x i8] c"fopen error!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = load i32, i32* @errno
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %16
15: ; preds = %0
store i32 0, i32* %1
br label %16
16: ; preds = %15, %8
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [12 x i8] c"errno = %d\0A\00"
@errno = global i32 0
@.str.1 = [9 x i8] c"test.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"strerror(errno) = %s\0A\00"
@.str.4 = [13 x i8] c"fopen error!\00"
define i32 @main() {
%1 = load i32, i32* @errno
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %0, %5
%13 = phi i32 [ -1, %5 ], [ 0, %0 ]
ret i32 %13
}