#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 EOF;
int /*<<< orphan*/ copy(char *, char *);
int getchar();
int /*<<< orphan*/ printf(char *, int, char *);
int readline(char *, int);
main() {
  int len, c;
  int max;
  char line[1000];
  char longest[1000];
  max = 0;
  while ((len = readline(line, 1000)) > 0) {
    if (line[len - 1] != '\n') {
      while ((c = getchar()) != EOF && c != '\n') {
        ++len;
      }
      if (c == '\n') {
        ++len;
      }
    }
    if (len > max) {
      max = len;
      copy(longest, line);
    }
  }
  if (max > 0) {
    printf("Longest line was %d characters long\n%s\n", max, longest);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <readline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1227 <main+0xe7>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11fd <main+0xbd>
jmp    1194 <main+0x54>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e3f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x7f1(%rbp)
je     11c4 <main+0x84>
cmpl   $0xa,-0xc(%rbp)
setne  %al
mov    %al,-0x7f1(%rbp)
mov    -0x7f1(%rbp),%al
test   $0x1,%al
jne    11d7 <main+0x97>
jmp    11e5 <main+0xa5>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1194 <main+0x54>
cmpl   $0xa,-0xc(%rbp)
jne    11f8 <main+0xb8>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11fd <main+0xbd>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1222 <main+0xe2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1050 <copy@plt>
jmp    1159 <main+0x19>
cmpl   $0x0,-0x10(%rbp)
jle    1247 <main+0x107>
mov    -0x10(%rbp),%esi
lea    -0x7f0(%rbp),%rdx
lea    0xdbe(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7d8,%rsp
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <readline@plt>
test   %eax,%eax
jle    11f0 <main+0xb0>
mov    %eax,%ebx
lea    0x3f0(%rsp),%r14
mov    %rsp,%r15
mov    0x2e6e(%rip),%r13
xor    %r12d,%r12d
jmp    1193 <main+0x53>
nop
mov    %r15,%rdi
mov    $0x3e8,%esi
call   1040 <readline@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    11d4 <main+0x94>
lea    -0x1(%rbx),%ebp
cmpb   $0xa,(%rsp,%rbp,1)
je     11bf <main+0x7f>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
add    $0x1,%ebp
cmp    $0xa,%eax
je     11b5 <main+0x75>
cmp    0x0(%r13),%eax
jne    11a0 <main+0x60>
xor    %ebx,%ebx
cmp    $0xa,%eax
sete   %bl
add    %ebp,%ebx
cmp    %r12d,%ebx
jle    1180 <main+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <copy@plt>
mov    %ebx,%r12d
jmp    1180 <main+0x40>
test   %r12d,%r12d
jle    11f0 <main+0xb0>
lea    0xe20(%rip),%rdi
lea    0x3f0(%rsp),%rdx
mov    %r12d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [40 x i8] c"Longest line was %d characters long\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %4
br label %7
7: ; preds = %48, %0
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%9 = call i32 @readline(i8* %8, i32 1000)
store i32 %9, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %49
11: ; preds = %7
%12 = load i32, i32* %2
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %39
19: ; preds = %11
br label %20
20: ; preds = %29, %19
%21 = call i32 (...) @getchar()
store i32 %21, i32* %3
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 10
br label %27
27: ; preds = %24, %20
%28 = phi i1 [ false, %20 ], [ %26, %24 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %20
32: ; preds = %27
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %38
38: ; preds = %35, %32
br label %39
39: ; preds = %38, %11
%40 = load i32, i32* %2
%41 = load i32, i32* %4
%42 = icmp sgt i32 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32, i32* %2
store i32 %44, i32* %4
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%47 = call i32 @copy(i8* %45, i8* %46)
br label %48
48: ; preds = %43, %39
br label %7
49: ; preds = %7
%50 = load i32, i32* %4
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i32, i32* %4
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%55 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %53, i8* %54)
br label %56
56: ; preds = %52, %49
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [40 x i8] c"Longest line was %d characters long\0A%s\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = call i32 @readline(i8* %3, i32 1000)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %40
7: ; preds = %0, %32
%8 = phi i32 [ %34, %32 ], [ %5, %0 ]
%9 = phi i32 [ %33, %32 ], [ 0, %0 ]
%10 = add nsw i32 %8, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %27, label %15
15: ; preds = %7, %15
%16 = phi i32 [ %22, %15 ], [ %8, %7 ]
%17 = call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
%20 = icmp ne i32 %17, 10
%21 = and i1 %20, %19
%22 = add nsw i32 %16, 1
br i1 %21, label %15, label %23
23: ; preds = %15
%24 = icmp eq i32 %17, 10
%25 = zext i1 %24 to i32
%26 = add nsw i32 %16, %25
br label %27
27: ; preds = %23, %7
%28 = phi i32 [ %8, %7 ], [ %26, %23 ]
%29 = icmp sgt i32 %28, %9
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @copy(i8* %4, i8* %3)
br label %32
32: ; preds = %30, %27
%33 = phi i32 [ %28, %30 ], [ %9, %27 ]
%34 = call i32 @readline(i8* %3, i32 1000)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %7, label %36
36: ; preds = %32
%37 = icmp sgt i32 %33, 0
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %33, i8* %4)
br label %40
40: ; preds = %0, %38, %36
ret i32 0
}