#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int main() {
  FILE *fp;
  fp = fopen("filedoesnotexist.txt", "rb");
  if (fp == NULL) {
    printf("Value of errno: %d\n", errno);
    printf("Error opening the file: %s\n", strerror(errno));
    perror("Error printed by perror");
    exit(EXIT_FAILURE);
    printf("I will not be printed\n");
  } else {
    fclose(fp);
    exit(EXIT_SUCCESS);
    printf("I will not be printed\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e1 <main+0x81>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    11c2 <main+0x62>
mov    0x2e60(%rip),%rbx
mov    (%rbx),%esi
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1080 <strerror@plt>
lea    0xe8e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"filedoesnotexist.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"Value of errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"Error opening the file: %s\0A\00"
@.str.4 = [24 x i8] c"Error printed by perror\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = load i32, i32* @EXIT_SUCCESS
%19 = call i32 @exit(i32 %18)
unreachable
}

LLVM IR (-O2):
@.str = [21 x i8] c"filedoesnotexist.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"Value of errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"Error opening the file: %s\0A\00"
@.str.4 = [24 x i8] c"Error printed by perror\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = load i32, i32* @errno
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = tail call i32 @fclose(i32* %1)
%14 = load i32, i32* @EXIT_SUCCESS
%15 = tail call i32 @exit(i32 %14)
unreachable
}