#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ remove(char *);
int main() {
  char *file_name;
  FILE *file;
  FILE *file_ptr;
  file = fopen("test1", "w+");
  if (file == NULL) {
    printf("%s\n", "Could not access file\n");
  }
  if (remove("test1") != 0) {
    printf("%s\n", "Could not remove file\n");
  }
  file_ptr = fopen("test1", "r");
  if (file_ptr == NULL) {
    printf("File not found\n");
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <main+0x46>
lea    0xe91(%rip),%rdi
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe73(%rip),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
je     11b1 <main+0x71>
lea    0xe66(%rip),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe48(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e1 <main+0xa1>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1168 <main+0x28>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe91(%rip),%rdi
call   1030 <remove@plt>
test   %rax,%rax
je     1185 <main+0x45>
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe74(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11a9 <main+0x69>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"test1\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [23 x i8] c"Could not access file\0A\00"
@.str.4 = [23 x i8] c"Could not remove file\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [16 x i8] c"File not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i64 @remove(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"test1\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.3 = [23 x i8] c"Could not access file\0A\00"
@.str.4 = [23 x i8] c"Could not remove file\0A\00"
@.str.5 = [2 x i8] c"r\00"
@str = [15 x i8] c"File not found\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 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 %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i64 @remove(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @fclose(i32* %1)
ret i32 0
}