#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 /*<<< orphan*/ copy(char *, char *);
int getaline(char *, int);
int /*<<< orphan*/ printf(char *, char *, int, char *, char *);
int main() {
  int len;
  int max;
  char line[1000];
  char longest[1000];
  max = 0;
  while ((len = getaline(line, 1000)) > 0) {
    if (len > max) {
      max = len;
      copy(longest, line);
    }
    printf("%s: %3d  %s: %s", "Chars", len, "Line", line);
  }
  if (max > 0) {
    printf("%s: %3d  %s: %s", "Chars", max, "Long", longest);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <getaline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11b4 <main+0x84>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    118b <main+0x5b>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1050 <copy@plt>
mov    -0x8(%rbp),%edx
lea    -0x400(%rbp),%r8
lea    0xe64(%rip),%rdi
lea    0xe6d(%rip),%rsi
lea    0xe6c(%rip),%rcx
call   1040 <printf@plt>
jmp    1149 <main+0x19>
cmpl   $0x0,-0xc(%rbp)
jle    11e2 <main+0xb2>
mov    -0xc(%rbp),%edx
lea    -0x7f0(%rbp),%r8
lea    0xe31(%rip),%rdi
lea    0xe3a(%rip),%rsi
lea    0xe3e(%rip),%rcx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7d8,%rsp
lea    0x3f0(%rsp),%rdi
mov    $0x3e8,%esi
call   1030 <getaline@plt>
test   %eax,%eax
jle    11dc <main+0xac>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x3f0(%rsp),%r15
lea    0xe92(%rip),%r12
lea    0xe9b(%rip),%r13
lea    0xe9a(%rip),%r14
jmp    11a6 <main+0x76>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %r15,%r8
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x3e8,%esi
call   1030 <getaline@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11b9 <main+0x89>
cmp    %ebx,%ebp
jle    1180 <main+0x50>
mov    %rsp,%rdi
mov    %r15,%rsi
call   1050 <copy@plt>
mov    %ebp,%ebx
jmp    1180 <main+0x50>
test   %ebx,%ebx
jle    11dc <main+0xac>
lea    0xe3c(%rip),%rdi
lea    0xe45(%rip),%rsi
lea    0xe49(%rip),%rcx
mov    %rsp,%r8
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%s: %3d %s: %s\00"
@.str.1 = [6 x i8] c"Chars\00"
@.str.2 = [5 x i8] c"Line\00"
@.str.3 = [5 x i8] c"Long\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %19, %0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = call i32 @getaline(i8* %7, i32 1000)
store i32 %8, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* %2
store i32 %15, i32* %3
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%18 = call i32 @copy(i8* %16, i8* %17)
br label %19
19: ; preds = %14, %10
%20 = load i32, i32* %2
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %6
23: ; preds = %6
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* %3
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %23
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"%s: %3d %s: %s\00"
@.str.1 = [6 x i8] c"Chars\00"
@.str.2 = [5 x i8] c"Line\00"
@.str.3 = [5 x i8] c"Long\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 @getaline(i8* %3, i32 1000)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %0, %13
%8 = phi i32 [ %16, %13 ], [ %5, %0 ]
%9 = phi i32 [ %14, %13 ], [ 0, %0 ]
%10 = icmp sgt i32 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @copy(i8* %4, i8* %3)
br label %13
13: ; preds = %11, %7
%14 = phi i32 [ %8, %11 ], [ %9, %7 ]
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%16 = call i32 @getaline(i8* %3, i32 1000)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %7, label %18
18: ; preds = %13
%19 = icmp sgt i32 %14, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %22
22: ; preds = %0, %20, %18
ret i32 0
}