#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 EOF;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void getfile(char *array, char *temp) {
  FILE *fp;
  char ch;
  int i = 0;
  fp = fopen(temp, "r");
  bzero(array, 500);
  if (fp == NULL) {
    strcpy(array, "No file found\n");
  } else {
    while (1) {
      ch = fgetc(fp);
      if (ch == EOF)
        break;
      array[i++] = ch;
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<getfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1f4,%esi
call   1070 <bzero@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <getfile+0x59>
mov    -0x8(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fb <getfile+0xab>
jmp    11ae <getfile+0x5e>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    0x2e23(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11d5 <getfile+0x85>
jmp    11f2 <getfile+0xa2>
mov    -0x19(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ae <getfile+0x5e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfile>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xe9e(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   1070 <bzero@plt>
test   %r14,%r14
je     11c0 <getfile+0x70>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e5a(%rip),%r15
cmp    (%r15),%al
je     11b3 <getfile+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %al,(%rbx)
mov    %r14,%rdi
call   1050 <fgetc@plt>
add    $0x1,%rbx
cmp    (%r15),%al
jne    11a0 <getfile+0x50>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"No file found\0A\00"
@EOF = global i8 0
define void @getfile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i8*, i8** %3
%11 = call i32 @bzero(i8* %10, i32 500)
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %37
17: ; preds = %2
br label %18
18: ; preds = %17, %27
%19 = load i32*, i32** %5
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %6
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %18
br label %34
27: ; preds = %18
%28 = load i8, i8* %6
%29 = load i8*, i8** %3
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 %28, i8* %33
br label %18
34: ; preds = %26
%35 = load i32*, i32** %5
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %34, %14
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"No file found\0A\00"
@EOF = global i8 0
define void @getfile(i8* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @bzero(i8* %0, i32 500)
%5 = icmp eq i32* %3, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call signext i8 @fgetc(i32* %3)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %20, label %12
10: ; preds = %2
%11 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %6, %12
%13 = phi i64 [ %15, %12 ], [ 0, %6 ]
%14 = phi i8 [ %17, %12 ], [ %7, %6 ]
%15 = add nuw i64 %13, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %14, i8* %16
%17 = tail call signext i8 @fgetc(i32* %3)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %20, label %12
20: ; preds = %12, %6
%21 = tail call i32 @fclose(i32* %3)
br label %22
22: ; preds = %20, %10
ret void
}