#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int openfile(const char *file_name, char **data, size_t *len, char **error) {
  FILE *pFile;
  pFile = fopen(file_name, "r");
  if (pFile == NULL) {
    *error = "fopen attrib.txt file fail!!!\n";
    return 1;
  } else {
    fseek(pFile, 0, SEEK_END);
    size_t size = ftell(pFile);
    char *buff = (char *)malloc(sizeof(char) * (size + 1));
    rewind(pFile);
    size_t result = fread(buff, 1, size, pFile);
    if (result != size) {
      *error = "read attrib.txt file error!!!\n";
      fclose(pFile);
      return 1;
    }
    buff[size] = '\0';
    *data = buff;
    *len = size;
    fclose(pFile);
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<openfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c1 <openfile+0x51>
mov    -0x28(%rbp),%rax
lea    0xe50(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    127f <openfile+0x10f>
mov    -0x30(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     124d <openfile+0xdd>
mov    -0x28(%rbp),%rax
lea    0xdec(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    127f <openfile+0x10f>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%r15
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1205 <openfile+0x95>
mov    %rax,%rbx
mov    %rbp,(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r13
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    $0x1,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %r13,%rax
jne    1217 <openfile+0xa7>
movb   $0x0,(%r14,%r13,1)
mov    %r14,(%r15)
mov    (%rsp),%rax
mov    %r13,(%rax)
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
jmp    122a <openfile+0xba>
lea    0xdf6(%rip),%rax
mov    %rax,(%r12)
mov    $0x1,%ebp
jmp    122a <openfile+0xba>
lea    0xe03(%rip),%rax
mov    %rax,(%r12)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"fopen attrib.txt file fail!!!\0A\00"
@SEEK_END = global i32 0
@.str.2 = [31 x i8] c"read attrib.txt file error!!!\0A\00"
define i32 @openfile(i8* %0, i8** %1, i64* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64*
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i64* %2, i64** %8
store i8** %3, i8*** %9
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %10
%16 = load i32*, i32** %10
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i8**, i8*** %9
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8** %19
store i32 1, i32* %5
br label %55
20: ; preds = %4
%21 = load i32*, i32** %10
%22 = load i32, i32* @SEEK_END
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32*, i32** %10
%25 = call i64 @ftell(i32* %24)
store i64 %25, i64* %11
%26 = load i64, i64* %11
%27 = add i64 %26, 1
%28 = mul i64 1, %27
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %12
%32 = load i32*, i32** %10
%33 = call i32 @rewind(i32* %32)
%34 = load i8*, i8** %12
%35 = load i64, i64* %11
%36 = load i32*, i32** %10
%37 = call i64 @fread(i8* %34, i32 1, i64 %35, i32* %36)
store i64 %37, i64* %13
%38 = load i64, i64* %13
%39 = load i64, i64* %11
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %20
%42 = load i8**, i8*** %9
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8** %42
%43 = load i32*, i32** %10
%44 = call i32 @fclose(i32* %43)
store i32 1, i32* %5
br label %55
45: ; preds = %20
%46 = load i8*, i8** %12
%47 = load i64, i64* %11
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %12
%50 = load i8**, i8*** %7
store i8* %49, i8** %50
%51 = load i64, i64* %11
%52 = load i64*, i64** %8
store i64 %51, i64* %52
%53 = load i32*, i32** %10
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %5
br label %55
55: ; preds = %45, %41, %18
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"fopen attrib.txt file fail!!!\0A\00"
@SEEK_END = global i32 0
@.str.2 = [31 x i8] c"read attrib.txt file error!!!\0A\00"
define i32 @openfile(i8* nocapture %0, i8** nocapture writeonly %1, i64* nocapture writeonly %2, i8** nocapture writeonly %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %4
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %24
8: ; preds = %4
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %5, i32 0, i32 %9)
%11 = tail call i64 @ftell(i32* %5)
%12 = trunc i64 %11 to i32
%13 = add i32 %12, 1
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @rewind(i32* %5)
%17 = tail call i64 @fread(i8* %15, i32 1, i64 %11, i32* %5)
%18 = icmp eq i64 %17, %11
br i1 %18, label %21, label %19
19: ; preds = %8
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8** %3
%20 = tail call i32 @fclose(i32* %5)
br label %24
21: ; preds = %8
%22 = getelementptr inbounds i8, i8* %15, i64 %11
store i8 0, i8* %22
store i8* %15, i8** %1
store i64 %11, i64* %2
%23 = tail call i32 @fclose(i32* %5)
br label %24
24: ; preds = %19, %21, %7
%25 = phi i32 [ 1, %7 ], [ 1, %19 ], [ 0, %21 ]
ret i32 %25
}