#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*/ R_OK;
int /*<<< orphan*/ SEEK_END;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ *fopen(char *, char *);
long fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *read_file(char *local_path) {
  FILE *fdesc;
  int access_status;
  char *input_str;
  long file_size, test;
  access_status = access(local_path, R_OK);
  if (access_status != 0)
    err(1, "cannot find the platform_properties.txt file from path %s",
        local_path);
  fdesc = fopen(local_path, "r");
  if (fdesc == NULL)
    err(1, "failed to open file %s\n", local_path);
  fseek(fdesc, 0, SEEK_END);
  file_size = ftell(fdesc);
  rewind(fdesc);
  input_str = (char *)malloc(sizeof(char) * file_size);
  if (input_str == NULL)
    err(1, " failed to malloc buffer for reading input file %s size = %ld",
        local_path, file_size);
  test = fread(input_str, 1, file_size, fdesc);
  if (test != file_size)
    err(1, "read size, %ld != file_size %ld for file %s", test, file_size,
        local_path);
  return input_str;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c2 <read_file+0x42>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1060 <err@plt>
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f8 <read_file+0x78>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1060 <err@plt>
mov    -0x10(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    125b <read_file+0xdb>
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%edi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1060 <err@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     12a2 <read_file+0x122>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    $0x1,%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1060 <err@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
test   %eax,%eax
je     11b3 <read_file+0x33>
lea    0xe5c(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <err@plt>
lea    0xe80(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e0 <read_file+0x60>
lea    0xe6b(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <err@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <rewind@plt>
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    122f <read_file+0xaf>
lea    0xe37(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <err@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
je     1263 <read_file+0xe3>
lea    0xe44(%rip),%rsi
mov    $0x1,%edi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1060 <err@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@R_OK = global i32 0
@.str = [58 x i8] c"cannot find the platform_properties.txt file from path %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"failed to open file %s\0A\00"
@SEEK_END = global i32 0
@.str.3 = [62 x i8] c" failed to malloc buffer for reading input file %s size = %ld\00"
@.str.4 = [44 x i8] c"read size, %ld != file_size %ld for file %s\00"
define i8* @read_file(i8* %0) {
%2 = load i32, i32* @R_OK
%3 = tail call i32 @access(i8* %0, i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %1
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %7
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @fseek(i32* %8, i32 0, i32 %13)
%15 = tail call i64 @ftell(i32* %8)
%16 = tail call i32 @rewind(i32* %8)
%17 = trunc i64 %15 to i32
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = icmp eq i64 %18, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0), i8* %0, i64 %15)
br label %23
23: ; preds = %21, %12
%24 = tail call i64 @fread(i8* %19, i32 1, i64 %15, i32* %8)
%25 = icmp eq i64 %24, %15
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i64 %24, i64 %15, i8* %0)
br label %28
28: ; preds = %26, %23
ret i8* %19
}