#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*/ debugMsg(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
char *readFile(char *file) {
  debugMsg("readFile() ...");
  FILE *fptr = fopen(file, "r");
  debugMsg("readFile() ... open file ...");
  if (fptr == NULL) {
    debugMsg("readFile() ... open file ... fail ...");
    return NULL;
  }
  debugMsg("readFile() ... open file ... ok ...");
  char c, chr[102400];
  int i = 0;
  debugMsg("readFile() ... read char from stream ...");
  do {
    c = fgetc(fptr);
    if (feof(fptr)) {
      break;
    }
    chr[i] = c;
    i++;
  } while (1);
  debugMsg("readFile() ... read char from stream ... ok ...");
  debugMsg("readFile() ... close file ...");
  fclose(fptr);
  debugMsg("readFile() ... close file ... ok ...");
  debugMsg("readFile() ... malloc ...");
  char *ret_val = malloc(sizeof(*ret_val) * strlen(chr));
  debugMsg("readFile() ... malloc ... ok ...");
  sprintf(ret_val, "%s", chr);
  debugMsg("readFile() ... ok ...");
  return ret_val;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x19030,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe6a(%rip),%rdi
call   1060 <debugMsg@plt>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe5b(%rip),%rdi
call   1060 <debugMsg@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11df <readFile+0x5f>
lea    0xe61(%rip),%rdi
call   1060 <debugMsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ea <readFile+0x16a>
lea    0xe6e(%rip),%rdi
call   1060 <debugMsg@plt>
movl   $0x0,-0x19024(%rbp)
lea    0xe7c(%rip),%rdi
call   1060 <debugMsg@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1225 <readFile+0xa5>
jmp    1254 <readFile+0xd4>
mov    -0x19(%rbp),%cl
movslq -0x19024(%rbp),%rax
mov    %cl,-0x19020(%rbp,%rax,1)
mov    -0x19024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x19024(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1201 <readFile+0x81>
jmp    1254 <readFile+0xd4>
lea    0xe46(%rip),%rdi
call   1060 <debugMsg@plt>
lea    0xe6a(%rip),%rdi
call   1060 <debugMsg@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe73(%rip),%rdi
call   1060 <debugMsg@plt>
lea    0xe8c(%rip),%rdi
call   1060 <debugMsg@plt>
lea    -0x19020(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x19030(%rbp)
lea    0xe7a(%rip),%rdi
call   1060 <debugMsg@plt>
mov    -0x19030(%rbp),%rdi
lea    -0x19020(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   10a0 <sprintf@plt>
lea    0xe78(%rip),%rdi
call   1060 <debugMsg@plt>
mov    -0x19030(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x19030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x19000,%rsp
mov    %rdi,%rbx
lea    0xe6b(%rip),%rdi
call   1070 <debugMsg@plt>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe5e(%rip),%rdi
call   1070 <debugMsg@plt>
test   %r14,%r14
je     1290 <readFile+0x110>
lea    0xe8c(%rip),%rdi
call   1070 <debugMsg@plt>
lea    0xea4(%rip),%rdi
call   1070 <debugMsg@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    121e <readFile+0x9e>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %bpl,(%rbx)
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1080 <feof@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1200 <readFile+0x80>
lea    0xe7c(%rip),%rdi
call   1070 <debugMsg@plt>
lea    0xea0(%rip),%rdi
call   1070 <debugMsg@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xeaa(%rip),%rdi
call   1070 <debugMsg@plt>
lea    0xec3(%rip),%rdi
call   1070 <debugMsg@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xebc(%rip),%rdi
call   1070 <debugMsg@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xec6(%rip),%rdi
call   1070 <debugMsg@plt>
jmp    129e <readFile+0x11e>
lea    0xd97(%rip),%rdi
call   1070 <debugMsg@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x19000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"readFile() ...\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"readFile() ... open file ...\00"
@.str.3 = [38 x i8] c"readFile() ... open file ... fail ...\00"
@.str.4 = [36 x i8] c"readFile() ... open file ... ok ...\00"
@.str.5 = [41 x i8] c"readFile() ... read char from stream ...\00"
@.str.6 = [48 x i8] c"readFile() ... read char from stream ... ok ...\00"
@.str.7 = [30 x i8] c"readFile() ... close file ...\00"
@.str.8 = [37 x i8] c"readFile() ... close file ... ok ...\00"
@.str.9 = [26 x i8] c"readFile() ... malloc ...\00"
@.str.10 = [33 x i8] c"readFile() ... malloc ... ok ...\00"
@.str.11 = [3 x i8] c"%s\00"
@.str.12 = [22 x i8] c"readFile() ... ok ...\00"
define i8* @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca [102400 x i8]
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
%9 = call i32 @debugMsg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @debugMsg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %54
17: ; preds = %1
%18 = call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %7
%19 = call i32 @debugMsg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %34, %17
%21 = load i32*, i32** %4
%22 = call signext i8 @fgetc(i32* %21)
store i8 %22, i8* %5
%23 = load i32*, i32** %4
%24 = call i64 @feof(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
br label %35
27: ; preds = %20
%28 = load i8, i8* %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [102400 x i8], [102400 x i8]* %6, i64 0, i64 %30
store i8 %28, i8* %31
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %34
34: ; preds = %27
br i1 true, label %20, label %35
35: ; preds = %34, %26
%36 = call i32 @debugMsg(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 @debugMsg(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%38 = load i32*, i32** %4
%39 = call i32 @fclose(i32* %38)
%40 = call i32 @debugMsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
%41 = call i32 @debugMsg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%42 = getelementptr inbounds [102400 x i8], [102400 x i8]* %6, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = sext i32 %43 to i64
%45 = mul i64 1, %44
%46 = trunc i64 %45 to i32
%47 = call i8* @malloc(i32 %46)
store i8* %47, i8** %8
%48 = call i32 @debugMsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%49 = load i8*, i8** %8
%50 = getelementptr inbounds [102400 x i8], [102400 x i8]* %6, i64 0, i64 0
%51 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %50)
%52 = call i32 @debugMsg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
%53 = load i8*, i8** %8
store i8* %53, i8** %2
br label %54
54: ; preds = %35, %15
%55 = load i8*, i8** %2
ret i8* %55
}

LLVM IR (-O2):
@.str = [15 x i8] c"readFile() ...\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"readFile() ... open file ...\00"
@.str.3 = [38 x i8] c"readFile() ... open file ... fail ...\00"
@.str.4 = [36 x i8] c"readFile() ... open file ... ok ...\00"
@.str.5 = [41 x i8] c"readFile() ... read char from stream ...\00"
@.str.6 = [48 x i8] c"readFile() ... read char from stream ... ok ...\00"
@.str.7 = [30 x i8] c"readFile() ... close file ...\00"
@.str.8 = [37 x i8] c"readFile() ... close file ... ok ...\00"
@.str.9 = [26 x i8] c"readFile() ... malloc ...\00"
@.str.10 = [33 x i8] c"readFile() ... malloc ... ok ...\00"
@.str.12 = [22 x i8] c"readFile() ... ok ...\00"
define i8* @readFile(i8* nocapture %0) {
%2 = alloca [102400 x i8]
%3 = tail call i32 @debugMsg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %4, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @debugMsg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %35
9: ; preds = %1
%10 = tail call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%11 = getelementptr inbounds [102400 x i8], [102400 x i8]* %2, i64 0, i64 0
%12 = tail call i32 @debugMsg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%13 = tail call signext i8 @fgetc(i32* %4)
%14 = tail call i64 @feof(i32* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %9, %16
%17 = phi i64 [ %20, %16 ], [ 0, %9 ]
%18 = phi i8 [ %21, %16 ], [ %13, %9 ]
%19 = getelementptr inbounds [102400 x i8], [102400 x i8]* %2, i64 0, i64 %17
store i8 %18, i8* %19
%20 = add nuw i64 %17, 1
%21 = tail call signext i8 @fgetc(i32* %4)
%22 = tail call i64 @feof(i32* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %16, label %24
24: ; preds = %16, %9
%25 = tail call i32 @debugMsg(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
%26 = tail call i32 @debugMsg(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%27 = tail call i32 @fclose(i32* %4)
%28 = tail call i32 @debugMsg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
%29 = tail call i32 @debugMsg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%30 = call i32 @strlen(i8* %11)
%31 = call i8* @malloc(i32 %30)
%32 = call i32 @debugMsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%33 = call i8* @strcpy(i8* dereferenceable(1) %31, i8* %11)
%34 = call i32 @debugMsg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %35
35: ; preds = %24, %7
%36 = phi i8* [ null, %7 ], [ %31, %24 ]
ret i8* %36
}