#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long int length_of_longest_line_in(char *file_name) {
  FILE *file_to_be_measured;
  char file_character;
  long int max = 0;
  long int i;
  if (file_name != NULL) {
    if ((file_to_be_measured = fopen(file_name, "r")) != NULL) {
      i = 1;
      while ((file_character = fgetc(file_to_be_measured)) != EOF) {
        if (file_character == '\n') {
          if (i > max)
            max = i;
          i = 1;
        } else
          i++;
      }
      if (i > max)
        max = i;
    }
    fclose(file_to_be_measured);
  }
  return max + 1;
}


x86 assembly (clang, -O0):
<length_of_longest_line_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11fb <length_of_longest_line_in+0xcb>
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11f2 <length_of_longest_line_in+0xc2>
movq   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e5d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d7 <length_of_longest_line_in+0xa7>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    11c6 <length_of_longest_line_in+0x96>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    11b9 <length_of_longest_line_in+0x89>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
jmp    11d2 <length_of_longest_line_in+0xa2>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1175 <length_of_longest_line_in+0x45>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    11ed <length_of_longest_line_in+0xbd>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11f2 <length_of_longest_line_in+0xc2>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<length_of_longest_line_in>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1170 <length_of_longest_line_in+0x40>
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     1175 <length_of_longest_line_in+0x45>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e87(%rip),%r15
cmp    (%r15),%al
jne    117a <length_of_longest_line_in+0x4a>
mov    $0x1,%ebx
xor    %r12d,%r12d
jmp    11b5 <length_of_longest_line_in+0x85>
xor    %r12d,%r12d
jmp    11c4 <length_of_longest_line_in+0x94>
xor    %r12d,%r12d
jmp    11bc <length_of_longest_line_in+0x8c>
mov    $0x1,%r13d
xor    %r12d,%r12d
mov    $0x1,%ecx
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rbx
cmp    %r12,%rcx
cmovle %r12,%rcx
cmp    $0xa,%al
cmove  %rcx,%r12
cmove  %r13,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %rbx,%rcx
cmp    (%r15),%al
jne    1190 <length_of_longest_line_in+0x60>
cmp    %r12,%rbx
cmovg  %rbx,%r12
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x1,%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i64 @length_of_longest_line_in(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %5
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %46
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %43
13: ; preds = %9
store i64 1, i64* %6
br label %14
14: ; preds = %35, %13
%15 = load i32*, i32** %3
%16 = call signext i8 @fgetc(i32* %15)
store i8 %16, i8* %4
%17 = sext i8 %16 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %36
21: ; preds = %14
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i64, i64* %6
%27 = load i64, i64* %5
%28 = icmp sgt i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i64, i64* %6
store i64 %30, i64* %5
br label %31
31: ; preds = %29, %25
store i64 1, i64* %6
br label %35
32: ; preds = %21
%33 = load i64, i64* %6
%34 = add nsw i64 %33, 1
store i64 %34, i64* %6
br label %35
35: ; preds = %32, %31
br label %14
36: ; preds = %14
%37 = load i64, i64* %6
%38 = load i64, i64* %5
%39 = icmp sgt i64 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i64, i64* %6
store i64 %41, i64* %5
br label %42
42: ; preds = %40, %36
br label %43
43: ; preds = %42, %9
%44 = load i32*, i32** %3
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %43, %1
%47 = load i64, i64* %5
%48 = add nsw i64 %47, 1
ret i64 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i64 @length_of_longest_line_in(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %31, label %3
3: ; preds = %1
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %28, label %6
6: ; preds = %3
%7 = tail call signext i8 @fgetc(i32* %4)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %23, label %10
10: ; preds = %6, %10
%11 = phi i8 [ %20, %10 ], [ %7, %6 ]
%12 = phi i64 [ %19, %10 ], [ 1, %6 ]
%13 = phi i64 [ %18, %10 ], [ 0, %6 ]
%14 = icmp eq i8 %11, 10
%15 = icmp sgt i64 %12, %13
%16 = add nsw i64 %12, 1
%17 = select i1 %14, i1 %15, i1 false
%18 = select i1 %17, i64 %12, i64 %13
%19 = select i1 %14, i64 1, i64 %16
%20 = tail call signext i8 @fgetc(i32* %4)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %23, label %10
23: ; preds = %10, %6
%24 = phi i64 [ 0, %6 ], [ %18, %10 ]
%25 = phi i64 [ 1, %6 ], [ %19, %10 ]
%26 = icmp sgt i64 %25, %24
%27 = select i1 %26, i64 %25, i64 %24
br label %28
28: ; preds = %23, %3
%29 = phi i64 [ 0, %3 ], [ %27, %23 ]
%30 = tail call i32 @fclose(i32* %4)
br label %31
31: ; preds = %28, %1
%32 = phi i64 [ %29, %28 ], [ 0, %1 ]
%33 = add nsw i64 %32, 1
ret i64 %33
}