#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ filesize;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *BackUpFile(char *n, char *file_buffer) {
  struct stat st;
  int filesize;
  FILE *fp;
  char c;
  printf("%s\n", n);
  fp = fopen(n, "r");
  if (fp == NULL) {
    fprintf(stderr, "Can't open Input File");
    exit(1);
  }
  stat(n, &st);
  filesize = st.st_size;
  file_buffer = (char *)malloc(sizeof(filesize) + 5);
  do {
    static int i;
    c = fgetc(fp);
    file_buffer[i] = c;
    i++;
  } while (c != EOF);
  return file_buffer;
}


x86 assembly (clang, -O0):
<BackUpFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <BackUpFile+0x5e>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x9,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq 0x2e57(%rip),%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2e4e(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e45(%rip)
movsbl -0x29(%rbp),%eax
mov    0x2dc2(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11ef <BackUpFile+0x7f>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BackUpFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xe7d(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0xe72(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fb <BackUpFile+0x8b>
mov    %rax,%r15
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <stat@plt>
mov    $0x9,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x2e25(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1040 <fgetc@plt>
movslq 0x2e81(%rip),%rcx
mov    %al,(%rbx,%rcx,1)
addl   $0x1,0x2e77(%rip)
cmp    (%r14),%al
jne    11d0 <BackUpFile+0x60>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Can't open Input File\00"
@BackUpFile.i = internal global i32 0
@EOF = global i8 0
define i8* @BackUpFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8*, i8** %3
%21 = call i32 @stat(i8* %20, %struct.stat* %5)
%22 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%23 = load i32, i32* %22
store i32 %23, i32* %6
%24 = call i64 @malloc(i32 9)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %4
br label %26
26: ; preds = %36, %19
%27 = load i32*, i32** %7
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %8
%29 = load i8, i8* %8
%30 = load i8*, i8** %4
%31 = load i32, i32* @BackUpFile.i
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
%34 = load i32, i32* @BackUpFile.i
%35 = add nsw i32 %34, 1
store i32 %35, i32* @BackUpFile.i
br label %36
36: ; preds = %26
%37 = load i8, i8* %8
%38 = sext i8 %37 to i32
%39 = load i8, i8* @EOF
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %38, %40
br i1 %41, label %26, label %42
42: ; preds = %36
%43 = load i8*, i8** %4
ret i8* %43
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Can't open Input File\00"
@BackUpFile.i = internal unnamed_addr global i32 0
@EOF = global i8 0
define i8* @BackUpFile(i8* %0, i8* nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = call i32 @stat(i8* %0, %struct.stat* %3)
%14 = tail call i64 @malloc(i32 9)
%15 = inttoptr i64 %14 to i8*
br label %16
16: ; preds = %16, %12
%17 = tail call signext i8 @fgetc(i32* %6)
%18 = load i32, i32* @BackUpFile.i
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
store i8 %17, i8* %20
%21 = load i32, i32* @BackUpFile.i
%22 = add nsw i32 %21, 1
store i32 %22, i32* @BackUpFile.i
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %17, %23
br i1 %24, label %25, label %16
25: ; preds = %16
ret i8* %15
}