#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ mylog(char *, char *);
char *read_text_from_file(long int maxsize, char *filename) {
  FILE *f = fopen(filename, "rb");
  char c = (char)fgetc(f);
  long int i = 0;
  char *result = malloc(sizeof(char) * (maxsize + 1));
  while (i < maxsize && c != (char)EOF) {
    result[i] = c;
    i++;
    c = (char)fgetc(f);
    if (c == ' ' || c == '\r' || c == '\n') {
      result[i] = ' ';
      i++;
      while (c == ' ' || c == '\r' || c == '\n')
        c = (char)fgetc(f);
    }
  }
  result[i] = 0;
  char *cutted_result = malloc(sizeof(char) * (i + 1));
  int j = 0;
  for (j = 0; j <= i; j++)
    cutted_result[j] = result[j];
  free(result);
  mylog("file was succesfully read", "logs.txt");
  fclose(f);
  return cutted_result;
}


x86 assembly (clang, -O0):
<read_text_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x3d(%rbp)
jge    11db <read_text_from_file+0x7b>
movsbl -0x19(%rbp),%eax
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%rcx
movsbl %cl,%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    11eb <read_text_from_file+0x8b>
jmp    12ac <read_text_from_file+0x14c>
mov    -0x19(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
je     1238 <read_text_from_file+0xd8>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
je     1238 <read_text_from_file+0xd8>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    12a7 <read_text_from_file+0x147>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movsbl -0x19(%rbp),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x3e(%rbp)
je     1281 <read_text_from_file+0x121>
movsbl -0x19(%rbp),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x3e(%rbp)
je     1281 <read_text_from_file+0x121>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x3e(%rbp)
mov    -0x3e(%rbp),%al
test   $0x1,%al
jne    1291 <read_text_from_file+0x131>
jmp    12a2 <read_text_from_file+0x142>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
jmp    1250 <read_text_from_file+0xf0>
jmp    12a7 <read_text_from_file+0x147>
jmp    11af <read_text_from_file+0x4f>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jg     130f <read_text_from_file+0x1af>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12dd <read_text_from_file+0x17d>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xce4(%rip),%rdi
lea    0xcf7(%rip),%rsi
call   1080 <mylog@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_text_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbp
lea    0xe78(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rbx
lea    0x1(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
xor    %r15d,%r15d
mov    %rbp,(%rsp)
test   %rbp,%rbp
jle    125a <read_text_from_file+0xea>
movsbl %bl,%eax
mov    0x2e25(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %eax,%ecx
je     125a <read_text_from_file+0xea>
xor    %r15d,%r15d
movabs $0x100002400,%rbp
nopl   0x0(%rax,%rax,1)
mov    %bl,(%r14,%r15,1)
lea    0x1(%r15),%r12
mov    %r13,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rbx
cmp    $0x20,%bl
ja     1240 <read_text_from_file+0xd0>
movzbl %bl,%eax
bt     %rax,%rbp
jae    1240 <read_text_from_file+0xd0>
movb   $0x20,(%r14,%r12,1)
cmp    $0x20,%bl
ja     1229 <read_text_from_file+0xb9>
nopl   0x0(%rax,%rax,1)
movzbl %bl,%eax
bt     %rax,%rbp
jae    1229 <read_text_from_file+0xb9>
mov    %r13,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rbx
cmp    $0x20,%bl
jbe    1210 <read_text_from_file+0xa0>
add    $0x2,%r15
cmp    (%rsp),%r15
jl     1249 <read_text_from_file+0xd9>
jmp    125a <read_text_from_file+0xea>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%r15
cmp    (%rsp),%r15
jge    125a <read_text_from_file+0xea>
movsbl %bl,%eax
mov    0x2d95(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %eax,%ecx
jne    11e0 <read_text_from_file+0x70>
movb   $0x0,(%r14,%r15,1)
lea    0x1(%r15),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %r15,%r15
js     1282 <read_text_from_file+0x112>
add    $0x1,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xd72(%rip),%rdi
lea    0xd85(%rip),%rsi
call   1090 <mylog@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EOF = global i64 0
@.str.1 = [26 x i8] c"file was succesfully read\00"
@.str.2 = [9 x i8] c"logs.txt\00"
define i8* @read_text_from_file(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i64 %0, i64* %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = call i64 @fgetc(i32* %13)
%15 = trunc i64 %14 to i8
store i8 %15, i8* %6
store i64 0, i64* %7
%16 = load i64, i64* %3
%17 = add nsw i64 %16, 1
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %8
br label %21
21: ; preds = %80, %2
%22 = load i64, i64* %7
%23 = load i64, i64* %3
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
%28 = load i64, i64* @EOF
%29 = trunc i64 %28 to i8
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %27, %30
br label %32
32: ; preds = %25, %21
%33 = phi i1 [ false, %21 ], [ %31, %25 ]
br i1 %33, label %34, label %81
34: ; preds = %32
%35 = load i8, i8* %6
%36 = load i8*, i8** %8
%37 = load i64, i64* %7
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 %35, i8* %38
%39 = load i64, i64* %7
%40 = add nsw i64 %39, 1
store i64 %40, i64* %7
%41 = load i32*, i32** %5
%42 = call i64 @fgetc(i32* %41)
%43 = trunc i64 %42 to i8
store i8 %43, i8* %6
%44 = load i8, i8* %6
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 32
br i1 %46, label %55, label %47
47: ; preds = %34
%48 = load i8, i8* %6
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 13
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i8, i8* %6
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %80
55: ; preds = %51, %47, %34
%56 = load i8*, i8** %8
%57 = load i64, i64* %7
%58 = getelementptr inbounds i8, i8* %56, i64 %57
store i8 32, i8* %58
%59 = load i64, i64* %7
%60 = add nsw i64 %59, 1
store i64 %60, i64* %7
br label %61
61: ; preds = %75, %55
%62 = load i8, i8* %6
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 32
br i1 %64, label %73, label %65
65: ; preds = %61
%66 = load i8, i8* %6
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 13
br i1 %68, label %73, label %69
69: ; preds = %65
%70 = load i8, i8* %6
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 10
br label %73
73: ; preds = %69, %65, %61
%74 = phi i1 [ true, %65 ], [ true, %61 ], [ %72, %69 ]
br i1 %74, label %75, label %79
75: ; preds = %73
%76 = load i32*, i32** %5
%77 = call i64 @fgetc(i32* %76)
%78 = trunc i64 %77 to i8
store i8 %78, i8* %6
br label %61
79: ; preds = %73
br label %80
80: ; preds = %79, %51
br label %21
81: ; preds = %32
%82 = load i8*, i8** %8
%83 = load i64, i64* %7
%84 = getelementptr inbounds i8, i8* %82, i64 %83
store i8 0, i8* %84
%85 = load i64, i64* %7
%86 = add nsw i64 %85, 1
%87 = mul i64 1, %86
%88 = trunc i64 %87 to i32
%89 = call i8* @malloc(i32 %88)
store i8* %89, i8** %9
store i32 0, i32* %10
store i32 0, i32* %10
br label %90
90: ; preds = %105, %81
%91 = load i32, i32* %10
%92 = sext i32 %91 to i64
%93 = load i64, i64* %7
%94 = icmp sle i64 %92, %93
br i1 %94, label %95, label %108
95: ; preds = %90
%96 = load i8*, i8** %8
%97 = load i32, i32* %10
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = load i8, i8* %99
%101 = load i8*, i8** %9
%102 = load i32, i32* %10
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %101, i64 %103
store i8 %100, i8* %104
br label %105
105: ; preds = %95
%106 = load i32, i32* %10
%107 = add nsw i32 %106, 1
store i32 %107, i32* %10
br label %90
108: ; preds = %90
%109 = load i8*, i8** %8
%110 = call i32 @free(i8* %109)
%111 = call i32 @mylog(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%112 = load i32*, i32** %5
%113 = call i32 @fclose(i32* %112)
%114 = load i8*, i8** %9
ret i8* %114
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i64 0
@.str.1 = [26 x i8] c"file was succesfully read\00"
@.str.2 = [9 x i8] c"logs.txt\00"
define noalias i8* @read_text_from_file(i64 %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @fgetc(i32* %3)
%5 = trunc i64 %4 to i8
%6 = trunc i64 %0 to i32
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp sgt i64 %0, 0
%10 = sext i8 %5 to i32
%11 = load i64, i64* @EOF
%12 = trunc i64 %11 to i32
%13 = shl i32 %12, 24
%14 = ashr exact i32 %13, 24
%15 = icmp ne i32 %14, %10
%16 = select i1 %9, i1 %15, i1 false
br i1 %16, label %17, label %44
17: ; preds = %2, %33
%18 = phi i8 [ %35, %33 ], [ %5, %2 ]
%19 = phi i64 [ %34, %33 ], [ 0, %2 ]
%20 = getelementptr inbounds i8, i8* %8, i64 %19
store i8 %18, i8* %20
%21 = add nsw i64 %19, 1
%22 = tail call i64 @fgetc(i32* %3)
%23 = trunc i64 %22 to i8
switch i8 %23, label %33 [
i8 32, label %24
i8 13, label %24
i8 10, label %24
]
24: ; preds = %17, %17, %17
%25 = getelementptr inbounds i8, i8* %8, i64 %21
store i8 32, i8* %25
br label %26
26: ; preds = %28, %24
%27 = phi i8 [ %23, %24 ], [ %30, %28 ]
switch i8 %27, label %31 [
i8 32, label %28
i8 13, label %28
i8 10, label %28
]
28: ; preds = %26, %26, %26
%29 = tail call i64 @fgetc(i32* %3)
%30 = trunc i64 %29 to i8
br label %26
31: ; preds = %26
%32 = add nsw i64 %19, 2
br label %33
33: ; preds = %31, %17
%34 = phi i64 [ %21, %17 ], [ %32, %31 ]
%35 = phi i8 [ %23, %17 ], [ %27, %31 ]
%36 = icmp slt i64 %34, %0
%37 = sext i8 %35 to i32
%38 = load i64, i64* @EOF
%39 = trunc i64 %38 to i32
%40 = shl i32 %39, 24
%41 = ashr exact i32 %40, 24
%42 = icmp ne i32 %41, %37
%43 = select i1 %36, i1 %42, i1 false
br i1 %43, label %17, label %44
44: ; preds = %33, %2
%45 = phi i64 [ 0, %2 ], [ %34, %33 ]
%46 = getelementptr inbounds i8, i8* %8, i64 %45
store i8 0, i8* %46
%47 = trunc i64 %45 to i32
%48 = add i32 %47, 1
%49 = tail call i8* @malloc(i32 %48)
%50 = icmp slt i64 %45, 0
br i1 %50, label %53, label %51
51: ; preds = %44
%52 = add nuw nsw i64 %45, 1
br label %53
53: ; preds = %51, %44
%54 = tail call i32 @free(i8* %8)
%55 = tail call i32 @mylog(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%56 = tail call i32 @fclose(i32* %3)
ret i8* %49
}