#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(int);
int fileMissing(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
main() {
  char filename[] = "test.dat";
  FILE *fp;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "Can't open file %s\n", filename);
    exit(-1);
  } else {
    printf("Missing Int= %d\n", fileMissing(fp));
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xe98(%rip),%al
mov    %al,-0x5(%rbp)
lea    -0xd(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <main+0x65>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    -0xd(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fileMissing@plt>
mov    %eax,%esi
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movabs $0x7461642e74736574,%rax
64 61 74
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xe9a(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <fopen@plt>
test   %rax,%rax
jne    11a2 <main+0x52>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    %rax,%rdi
call   1060 <fileMissing@plt>
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.main.filename = [9 x i8] c"test.dat\00"
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Can't open file %s\0A\00"
@.str.2 = [17 x i8] c"Missing Int= %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = alloca i32*
store i32 0, i32* %1
%4 = bitcast [9 x i8]* %2 to i8*
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = load i32*, i32** %3
%16 = call i32 @fileMissing(i32* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.filename = [9 x i8] c"test.dat\00"
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Can't open file %s\0A\00"
@.str.2 = [17 x i8] c"Missing Int= %d\0A\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%3 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = tail call i32 @fileMissing(i32* %3)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 @exit(i32 0)
unreachable
}