#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 my_getline(char *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  char line[1000];
  char longest[1000];
  int len;
  int lineLength = 0;
  int max = 0;
  while ((len = my_getline(line, 1000)) > 0) {
    if (len == 1000 - 1) {
      if (line[1000 - 2] != '\n') {
        lineLength += len;
        continue;
      }
    } else {
      lineLength += len;
    }
    if (lineLength > max) {
      max = lineLength;
    }
    lineLength = 0;
  }
  printf("the length of longest line is :%d\n", max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x7e8(%rbp)
movl   $0x0,-0x7ec(%rbp)
lea    -0x3f0(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <my_getline@plt>
mov    %eax,-0x7e4(%rbp)
cmp    $0x0,%eax
jle    11de <main+0xbe>
cmpl   $0x3e7,-0x7e4(%rbp)
jne    119f <main+0x7f>
movsbl -0xa(%rbp),%eax
cmp    $0xa,%eax
je     119a <main+0x7a>
mov    -0x7e4(%rbp),%eax
add    -0x7e8(%rbp),%eax
mov    %eax,-0x7e8(%rbp)
jmp    1146 <main+0x26>
jmp    11b1 <main+0x91>
mov    -0x7e4(%rbp),%eax
add    -0x7e8(%rbp),%eax
mov    %eax,-0x7e8(%rbp)
mov    -0x7e8(%rbp),%eax
cmp    -0x7ec(%rbp),%eax
jle    11cf <main+0xaf>
mov    -0x7e8(%rbp),%eax
mov    %eax,-0x7ec(%rbp)
movl   $0x0,-0x7e8(%rbp)
jmp    1146 <main+0x26>
mov    -0x7ec(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <my_getline@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    119a <main+0x7a>
mov    %rsp,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x3e7,%eax
jne    1180 <main+0x60>
cmpb   $0xa,0x3e6(%rsp)
0a
je     1182 <main+0x62>
add    $0x3e7,%ebp
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <my_getline@plt>
test   %eax,%eax
jg     1150 <main+0x30>
jmp    119a <main+0x7a>
nopw   0x0(%rax,%rax,1)
add    %eax,%ebp
cmp    %r14d,%ebp
cmovg  %ebp,%r14d
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <my_getline@plt>
test   %eax,%eax
jg     1142 <main+0x22>
lea    0xe5f(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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