#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 *, char *, ...);
int main() {
  int len;
  int max;
  char line[1000];
  char longest[1000];
  max = 0;
  while ((len = get_line(line, 1000)) != 0) {
    printf("Line: %sLength: %d\n", line, len);
    if (len > max) {
      max = len;
      copy(longest, line);
    }
  }
  printf("Longest is: %s", 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 <get_line@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     11a8 <main+0x78>
lea    -0x400(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11a3 <main+0x73>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1050 <copy@plt>
jmp    1149 <main+0x19>
lea    -0x7f0(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
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   %r12
push   %rbx
sub    $0x7e0,%rsp
lea    0x3f0(%rsp),%rdi
mov    $0x3e8,%esi
call   1030 <get_line@plt>
test   %eax,%eax
je     11a5 <main+0x75>
mov    %eax,%ebp
lea    0xea2(%rip),%r14
lea    0x3f0(%rsp),%r12
mov    %rsp,%r15
xor    %ebx,%ebx
jmp    1183 <main+0x53>
nopl   (%rax)
mov    %r12,%rdi
mov    $0x3e8,%esi
call   1030 <get_line@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11a5 <main+0x75>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebx,%ebp
jle    1170 <main+0x40>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <copy@plt>
mov    %ebp,%ebx
jmp    1170 <main+0x40>
lea    0xe68(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7e0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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