#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 EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int file_input(char *input, char *filepath) {
  FILE *fp = fopen(filepath, "r");
  if (!fp) {
    printf("[ERROR]:Not find file %s, exit.\n", filepath);
    exit(0);
  }
  int i = 0;
  int ch;
  ch = fgetc(fp);
  while (ch != EOF) {
    input[i++] = ch;
    ch = fgetc(fp);
  }
  input[i] = '\0';
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<file_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1196 <file_input+0x46>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%eax
je     11e6 <file_input+0x96>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
jmp    11a9 <file_input+0x59>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_input>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe9b(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c2 <file_input+0x72>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e64(%rip),%r15
cmp    (%r15),%eax
jne    118d <file_input+0x3d>
xor    %eax,%eax
jmp    11a7 <file_input+0x57>
xor    %ebx,%ebx
nop
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    1190 <file_input+0x40>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe39(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [33 x i8] c"[ERROR]:Not find file %s, exit.\0A\00"
@EOF = global i32 0
define i32 @file_input(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%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 i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
store i32 0, i32* %6
%17 = load i32*, i32** %5
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %7
br label %19
19: ; preds = %23, %16
%20 = load i32, i32* %7
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32, i32* %7
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 %25, i8* %30
%31 = load i32*, i32** %5
%32 = call i32 @fgetc(i32* %31)
store i32 %32, i32* %7
br label %19
33: ; preds = %19
%34 = load i8*, i8** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i32*, i32** %5
%39 = call i32 @fclose(i32* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [33 x i8] c"[ERROR]:Not find file %s, exit.\0A\00"
@EOF = global i32 0
define i32 @file_input(i8* nocapture writeonly %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = tail call i32 @fgetc(i32* %3)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %23, label %12
12: ; preds = %8, %12
%13 = phi i64 [ %16, %12 ], [ 0, %8 ]
%14 = phi i32 [ %18, %12 ], [ %9, %8 ]
%15 = trunc i32 %14 to i8
%16 = add nuw i64 %13, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %15, i8* %17
%18 = tail call i32 @fgetc(i32* %3)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %12
21: ; preds = %12
%22 = and i64 %16, 4294967295
br label %23
23: ; preds = %21, %8
%24 = phi i64 [ 0, %8 ], [ %22, %21 ]
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @fclose(i32* %3)
ret i32 0
}