#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*/ F_OK;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ access(char const *, int /*<<< orphan*/);
scalar_t__ calloc(long, int);
int /*<<< orphan*/ debug(char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void readFile(const char *filename) {
  FILE *fp;
  char *content;
  long file_len;
  debug(filename);
  if (access(filename, F_OK)) {
    debug("文件不存在");
    exit(0);
  }
  fp = fopen(filename, "r");
  fseek(fp, 0, SEEK_END);
  file_len = ftell(fp);
  printf("文件长度:%ld\n", file_len);
  content = (char *)calloc(file_len, sizeof(char));
  fseek(fp, 0, SEEK_SET);
  fread(content, file_len, 1, fp);
  printf("contnet:%s\n", content);
  free(content);
  fclose(fp);
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <debug@plt>
mov    -0x8(%rbp),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     11f4 <readFile+0x44>
lea    0xe18(%rip),%rdi
call   1060 <debug@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1060 <debug@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <access@plt>
test   %rax,%rax
jne    1274 <readFile+0xc4>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
lea    0xe04(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
lea    0xdcf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>
lea    0xd85(%rip),%rdi
call   1060 <debug@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [16 x i8] c"\E6\96\87\E4\BB\B6\E4\B8\8D\E5\AD\98\E5\9C\A8\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.2 = [18 x i8] c"\E6\96\87\E4\BB\B6\E9\95\BF\E5\BA\A6:%ld\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"contnet:%s\0A\00"
define void @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @debug(i8* %6)
%8 = load i8*, i8** %2
%9 = load i32, i32* @F_OK
%10 = call i64 @access(i8* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %3
%18 = load i32*, i32** %3
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = load i32*, i32** %3
%22 = call i64 @ftell(i32* %21)
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %23)
%25 = load i64, i64* %5
%26 = call i64 @calloc(i64 %25, i32 1)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %4
%28 = load i32*, i32** %3
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i8*, i8** %4
%32 = load i64, i64* %5
%33 = load i32*, i32** %3
%34 = call i32 @fread(i8* %31, i64 %32, i32 1, i32* %33)
%35 = load i8*, i8** %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
ret void
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [16 x i8] c"\E6\96\87\E4\BB\B6\E4\B8\8D\E5\AD\98\E5\9C\A8\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.2 = [18 x i8] c"\E6\96\87\E4\BB\B6\E9\95\BF\E5\BA\A6:%ld\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"contnet:%s\0A\00"
define void @readFile(i8* %0) {
%2 = tail call i32 @debug(i8* %0)
%3 = load i32, i32* @F_OK
%4 = tail call i64 @access(i8* %0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %1
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %10, i32 0, i32 %11)
%13 = tail call i64 @ftell(i32* %10)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %13)
%15 = tail call i64 @calloc(i64 %13, i32 1)
%16 = inttoptr i64 %15 to i8*
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @fseek(i32* %10, i32 0, i32 %17)
%19 = tail call i32 @fread(i8* %16, i64 %13, i32 1, i32* %10)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%21 = tail call i32 @free(i8* %16)
%22 = tail call i32 @fclose(i32* %10)
ret void
}