#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 fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main() {
  FILE *fp;
  int r;
  fp = fopen("test.txt", "r");
  if (fp == NULL) {
    fprintf(stderr, "Unable to open that file!\n");
    return (1);
  }
  printf("File opened\n");
  r = fclose(fp);
  if (r != 0) {
    fprintf(stderr, "Unable to close file\n");
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <main+0x52>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dc <main+0x9c>
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d5 <main+0x95>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dc <main+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117d <main+0x3d>
mov    %rax,%rbx
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %eax,%eax
je     1199 <main+0x59>
lea    0xeab(%rip),%rsi
jmp    1184 <main+0x44>
lea    0xe87(%rip),%rsi
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Unable to open that file!\0A\00"
@.str.3 = [13 x i8] c"File opened\0A\00"
@.str.4 = [22 x i8] c"Unable to close file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %20
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32*, i32** %2
%13 = call i32 @fclose(i32* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %20
19: ; preds = %10
store i32 0, i32* %1
br label %20
20: ; preds = %19, %16, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Unable to open that file!\0A\00"
@.str.4 = [22 x i8] c"Unable to close file\0A\00"
@str = [12 x i8] c"File opened\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @fclose(i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %3, %0
%8 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), %0 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), %3 ]
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* %8)
br label %11
11: ; preds = %7, %3
%12 = phi i32 [ 0, %3 ], [ 1, %7 ]
ret i32 %12
}