#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 */

/* Variables and functions */
int getlinelen(char *, int);
int /*<<< orphan*/ printf(char *, int);
main() {
  int len, max, templen;
  char buffer[5];
  max = len = 0;
  while ((templen = getlinelen(buffer, 5)) > 0) {
    len += templen;
    if (buffer[templen - 1] == '\n') {
      if (len > max) {
        max = len;
      }
      len = 0;
    }
  }
  printf("\nLen of longest line: %d\n", max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x15(%rbp),%rdi
mov    $0x5,%esi
call   1030 <getlinelen@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    1194 <main+0x74>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x15(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    118f <main+0x6f>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1188 <main+0x68>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    113d <main+0x1d>
mov    -0xc(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0x3(%rsp),%rdi
mov    $0x5,%esi
call   1030 <getlinelen@plt>
test   %eax,%eax
jle    117b <main+0x5b>
xor    %r15d,%r15d
lea    0x3(%rsp),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
add    %eax,%ebp
add    $0xffffffff,%eax
cmp    %ebx,%ebp
mov    %ebx,%ecx
cmovg  %ebp,%ecx
cmpb   $0xa,0x3(%rsp,%rax,1)
cmove  %ecx,%ebx
cmove  %r15d,%ebp
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <getlinelen@plt>
test   %eax,%eax
jg     1150 <main+0x30>
jmp    117d <main+0x5d>
xor    %ebx,%ebx
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"\0ALen of longest line: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %6
6: ; preds = %28, %0
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%8 = call i32 @getlinelen(i8* %7, i32 5)
store i32 %8, i32* %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %6
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = add nsw i32 %12, %11
store i32 %13, i32* %2
%14 = load i32, i32* %4
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %28
21: ; preds = %10
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* %2
store i32 %26, i32* %3
br label %27
27: ; preds = %25, %21
store i32 0, i32* %2
br label %28
28: ; preds = %27, %10
br label %6
29: ; preds = %6
%30 = load i32, i32* %3
%31 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"\0ALen of longest line: %d\0A\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @getlinelen(i8* %2, i32 5)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %21
5: ; preds = %0, %5
%6 = phi i32 [ %19, %5 ], [ %3, %0 ]
%7 = phi i32 [ %18, %5 ], [ 0, %0 ]
%8 = phi i32 [ %17, %5 ], [ 0, %0 ]
%9 = add nsw i32 %6, %7
%10 = add nsw i32 %6, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
%15 = icmp sgt i32 %9, %8
%16 = select i1 %14, i1 %15, i1 false
%17 = select i1 %16, i32 %9, i32 %8
%18 = select i1 %14, i32 0, i32 %9
%19 = call i32 @getlinelen(i8* %2, i32 5)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %5, label %21
21: ; preds = %5, %0
%22 = phi i32 [ 0, %0 ], [ %17, %5 ]
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %22)
ret i32 0
}