#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;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int maxlinelength(FILE *input) {
  char c;
  int maxlength = 0;
  int curlength = 0;
  while ((c = fgetc(input)) != EOF)
    if (c == '\n') {
      if (curlength > maxlength)
        maxlength = curlength;
      curlength = 0;
    } else
      curlength++;
  rewind(input);
  return maxlength;
}


x86 assembly (clang, -O0):
<maxlinelength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2e98(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1194 <maxlinelength+0x74>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1186 <maxlinelength+0x66>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    117a <maxlinelength+0x5a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    118f <maxlinelength+0x6f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <maxlinelength+0x1a>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxlinelength>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1040 <fgetc@plt>
mov    0x2eb1(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%al
je     1170 <maxlinelength+0x50>
xor    %r15d,%r15d
xor    %ecx,%ecx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rcx),%ebx
cmp    %ebp,%ecx
cmovle %ebp,%ecx
cmp    $0xa,%al
cmove  %ecx,%ebp
cmove  %r15d,%ebx
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %ebx,%ecx
cmp    (%r14),%al
jne    1150 <maxlinelength+0x30>
mov    %r12,%rdi
call   1030 <rewind@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @maxlinelength(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %27, %1
%7 = load i32*, i32** %2
%8 = call signext i8 @fgetc(i32* %7)
store i8 %8, i8* %3
%9 = sext i8 %8 to i32
%10 = load i8, i8* @EOF
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %9, %11
br i1 %12, label %13, label %28
13: ; preds = %6
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i32, i32* %5
store i32 %22, i32* %4
br label %23
23: ; preds = %21, %17
store i32 0, i32* %5
br label %27
24: ; preds = %13
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %27
27: ; preds = %24, %23
br label %6
28: ; preds = %6
%29 = load i32*, i32** %2
%30 = call i32 @rewind(i32* %29)
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@EOF = global i8 0
define i32 @maxlinelength(i32* nocapture %0) {
%2 = tail call signext i8 @fgetc(i32* %0)
%3 = load i8, i8* @EOF
%4 = icmp eq i8 %2, %3
br i1 %4, label %18, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %15, %5 ], [ %2, %1 ]
%7 = phi i32 [ %14, %5 ], [ 0, %1 ]
%8 = phi i32 [ %13, %5 ], [ 0, %1 ]
%9 = icmp eq i8 %6, 10
%10 = icmp sgt i32 %7, %8
%11 = add nsw i32 %7, 1
%12 = select i1 %9, i1 %10, i1 false
%13 = select i1 %12, i32 %7, i32 %8
%14 = select i1 %9, i32 0, i32 %11
%15 = tail call signext i8 @fgetc(i32* %0)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %5
18: ; preds = %5, %1
%19 = phi i32 [ 0, %1 ], [ %13, %5 ]
%20 = tail call i32 @rewind(i32* %0)
ret i32 %19
}