#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 */
char *canonicalize_file_name(char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int verify_file(const char *filename) {
  char *buffer = malloc(100);
  char *canonicalized_filename = malloc(100);
  canonicalized_filename = canonicalize_file_name(filename);
  printf("%s\n", canonicalized_filename);
  FILE *fd = fopen(filename, "r");
  if (fd == NULL) {
    printf("File cannot be opened\n");
  } else {
    fread(buffer, 2, 100, fd);
    printf("%s\n", buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<verify_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <canonicalize_file_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c9 <verify_file+0x79>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f2 <verify_file+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
mov    $0x64,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <canonicalize_file_name@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     119f <verify_file+0x4f>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x64,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
jmp    11a6 <verify_file+0x56>
lea    0xe5c(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"File cannot be opened\0A\00"
define i32 @verify_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 100)
store i8* %6, i8** %3
%7 = call i8* @malloc(i32 100)
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = call i8* @canonicalize_file_name(i8* %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %2
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %24
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = load i32*, i32** %5
%21 = call i32 @fread(i8* %19, i32 2, i32 100, i32* %20)
%22 = load i8*, i8** %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %18, %16
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@str = [22 x i8] c"File cannot be opened\00"
define i32 @verify_file(i8* %0) {
%2 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%3 = tail call i8* @canonicalize_file_name(i8* %0)
%4 = tail call i32 @puts(i8* dereferenceable(1) %3)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @fread(i8* %2, i32 2, i32 100, i32* %5)
br label %9
9: ; preds = %1, %7
%10 = phi i8* [ %2, %7 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0), %1 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
ret i32 0
}