#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);
int get_line(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char str[1001];
  int len;
  char longest_line[1001];
  int longest_line_len = 0;
  while ((len = get_line(str)) > 0) {
    if (len > longest_line_len) {
      longest_line_len = len;
      copy(str, longest_line, len);
    }
  }
  printf("Len = %d\n", longest_line_len);
  printf("Line = %s\n", longest_line);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x7e4(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1030 <get_line@plt>
mov    %eax,-0x3f4(%rbp)
cmp    $0x0,%eax
jle    11a3 <main+0x73>
mov    -0x3f4(%rbp),%eax
cmp    -0x7e4(%rbp),%eax
jle    119e <main+0x6e>
mov    -0x3f4(%rbp),%eax
mov    %eax,-0x7e4(%rbp)
lea    -0x3f0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
mov    -0x3f4(%rbp),%edx
call   1050 <copy@plt>
jmp    114c <main+0x1c>
mov    -0x7e4(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7e0(%rbp),%rsi
lea    0xe45(%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   %rbx
sub    $0x7e8,%rsp
lea    0x3f0(%rsp),%rdi
call   1030 <get_line@plt>
test   %eax,%eax
jle    1183 <main+0x53>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x3f0(%rsp),%r14
mov    %rsp,%r15
jmp    116e <main+0x3e>
nop
mov    %r14,%rdi
call   1030 <get_line@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1185 <main+0x55>
cmp    %ebx,%ebp
jle    1160 <main+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <copy@plt>
mov    %ebp,%ebx
jmp    1160 <main+0x30>
xor    %ebx,%ebx
lea    0xe74(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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