#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 get_line(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
main() {
  int len;
  int max;
  int prevlen;
  char line[5];
  char longest[5];
  char temp[5];
  max = prevlen = 0;
  while ((len = get_line(line, 5)) > 0) {
    if (prevlen + len > max) {
      max = prevlen + len;
      if (!prevlen) {
        copy(longest, line);
      } else {
        copy(longest, temp);
      }
    }
    if (line[len - 1] != '\n') {
      if (!prevlen)
        copy(temp, line);
      prevlen += len;
    } else
      prevlen = 0;
  }
  if (max > 0) {
    putchar('\n');
    printf("The longest line has %d characters and is: \n", max);
    if (longest[max - 1] == '\n') {
      printf("%s", longest);
    } else {
      printf("%s...\n", longest);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x15(%rbp),%rdi
mov    $0x5,%esi
call   1040 <get_line@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1204 <main+0xc4>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11bd <main+0x7d>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11ab <main+0x6b>
lea    -0x1a(%rbp),%rdi
lea    -0x15(%rbp),%rsi
call   1060 <copy@plt>
jmp    11b8 <main+0x78>
lea    -0x1a(%rbp),%rdi
lea    -0x1f(%rbp),%rsi
call   1060 <copy@plt>
jmp    11bd <main+0x7d>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x15(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     11f8 <main+0xb8>
cmpl   $0x0,-0x10(%rbp)
jne    11ea <main+0xaa>
lea    -0x1f(%rbp),%rdi
lea    -0x15(%rbp),%rsi
call   1060 <copy@plt>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11ff <main+0xbf>
movl   $0x0,-0x10(%rbp)
jmp    115d <main+0x1d>
cmpl   $0x0,-0xc(%rbp)
jle    126d <main+0x12d>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x1a(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1256 <main+0x116>
lea    -0x1a(%rbp),%rsi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1268 <main+0x128>
lea    -0x1a(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126d <main+0x12d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe(%rsp),%rdi
mov    $0x5,%esi
call   1040 <get_line@plt>
test   %eax,%eax
jle    1231 <main+0xf1>
mov    %eax,%ebx
xor    %r14d,%r14d
lea    0xe(%rsp),%r12
lea    0x13(%rsp),%r15
xor    %r13d,%r13d
jmp    1198 <main+0x58>
mov    %ebp,%r13d
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    %r12,%rdi
mov    $0x5,%esi
call   1040 <get_line@plt>
mov    %eax,%ebx
mov    %ebp,%r14d
test   %eax,%eax
jle    11e9 <main+0xa9>
lea    (%rbx,%r14,1),%ebp
cmp    %r13d,%ebp
jle    11b6 <main+0x76>
lea    0x9(%rsp),%rdi
test   %r14d,%r14d
je     11c7 <main+0x87>
mov    %r15,%rsi
call   1060 <copy@plt>
mov    %ebp,%r13d
add    $0xffffffff,%ebx
cmpb   $0xa,0xe(%rsp,%rbx,1)
je     1180 <main+0x40>
test   %r14d,%r14d
jne    1182 <main+0x42>
jmp    11dc <main+0x9c>
mov    %r12,%rsi
call   1060 <copy@plt>
add    $0xffffffff,%ebx
cmpb   $0xa,0xe(%rsp,%rbx,1)
mov    %ebp,%r13d
je     1179 <main+0x39>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <copy@plt>
jmp    1182 <main+0x42>
test   %r13d,%r13d
jle    1231 <main+0xf1>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe01(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%r13d
cmpb   $0xa,0x9(%rsp,%r13,1)
lea    0xe13(%rip),%rax
lea    0xe0f(%rip),%rdi
cmove  %rax,%rdi
lea    0x9(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"The longest line has %d characters and is: \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"%s...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x i8]
%6 = alloca [5 x i8]
%7 = alloca [5 x i8]
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %3
br label %8
8: ; preds = %53, %0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%10 = call i32 @get_line(i8* %9, i32 5)
store i32 %10, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %54
12: ; preds = %8
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = add nsw i32 %13, %14
%16 = load i32, i32* %3
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %12
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = add nsw i32 %19, %20
store i32 %21, i32* %3
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%27 = call i32 @copy(i8* %25, i8* %26)
br label %32
28: ; preds = %18
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%31 = call i32 @copy(i8* %29, i8* %30)
br label %32
32: ; preds = %28, %24
br label %33
33: ; preds = %32, %12
%34 = load i32, i32* %2
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %52
41: ; preds = %33
%42 = load i32, i32* %4
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%47 = call i32 @copy(i8* %45, i8* %46)
br label %48
48: ; preds = %44, %41
%49 = load i32, i32* %2
%50 = load i32, i32* %4
%51 = add nsw i32 %50, %49
store i32 %51, i32* %4
br label %53
52: ; preds = %33
store i32 0, i32* %4
br label %53
53: ; preds = %52, %48
br label %8
54: ; preds = %8
%55 = load i32, i32* %3
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %75
57: ; preds = %54
%58 = call i32 @putchar(i8 signext 10)
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %3
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 10
br i1 %67, label %68, label %71
68: ; preds = %57
%69 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %69)
br label %74
71: ; preds = %57
%72 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %71, %68
br label %75
75: ; preds = %74, %54
ret i32 0
}

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