#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*/ EX_NOINPUT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
size_t maxSizeInFile(char *filename) {
  FILE *f = fopen(filename, "r");
  if (f == NULL) {
    fprintf(stderr, "Cannot open file in maxSizeInFile.\n");
    exit(EX_NOINPUT);
  }
  size_t max = 0;
  char word[30];
  while (fgets(word, 30, f) != NULL) {
    size_t count = strlen(word);
    if (count > max)
      max = count;
  }
  fclose(f);
  return max - 1;
}


x86 assembly (clang, -O0):
<maxSizeInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ae <maxSizeInFile+0x4e>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movq   $0x0,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1e,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fa <maxSizeInFile+0x9a>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11f5 <maxSizeInFile+0x95>
mov    -0x48(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11b6 <maxSizeInFile+0x56>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxSizeInFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e6 <maxSizeInFile+0x86>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1e,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11ca <maxSizeInFile+0x6a>
xor    %ebx,%ebx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %rbx,%rax
cmova  %rax,%rbx
mov    %r15,%rdi
mov    $0x1e,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <maxSizeInFile+0x40>
add    $0xffffffffffffffff,%rbx
jmp    11d1 <maxSizeInFile+0x71>
mov    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Cannot open file in maxSizeInFile.\0A\00"
@EX_NOINPUT = global i32 0
define i64 @maxSizeInFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca [30 x i8]
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EX_NOINPUT
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
store i64 0, i64* %4
br label %17
17: ; preds = %30, %16
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i32* @fgets(i8* %18, i32 30, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
store i64 %24, i64* %6
%25 = load i64, i64* %6
%26 = load i64, i64* %4
%27 = icmp ugt i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load i64, i64* %6
store i64 %29, i64* %4
br label %30
30: ; preds = %28, %22
br label %17
31: ; preds = %17
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
%34 = load i64, i64* %4
%35 = sub i64 %34, 1
ret i64 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Cannot open file in maxSizeInFile.\0A\00"
@EX_NOINPUT = global i32 0
define i64 @maxSizeInFile(i8* nocapture %0) {
%2 = alloca [30 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EX_NOINPUT
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%12 = call i32* @fgets(i8* %11, i32 30, i32* %3)
%13 = icmp eq i32* %12, null
br i1 %13, label %23, label %14
14: ; preds = %10, %14
%15 = phi i64 [ %18, %14 ], [ 0, %10 ]
%16 = call i64 @strlen(i8* %11)
%17 = icmp ugt i64 %16, %15
%18 = select i1 %17, i64 %16, i64 %15
%19 = call i32* @fgets(i8* %11, i32 30, i32* %3)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = add i64 %18, -1
br label %23
23: ; preds = %21, %10
%24 = phi i64 [ -1, %10 ], [ %22, %21 ]
%25 = call i32 @fclose(i32* %3)
ret i64 %24
}