#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 getline(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int len;
  int max;
  char line[1000];
  char longest[1000];
  max = 0;
  while ((len = getline(line, 1000)) > 0) {
    printf("len for this line is %d\n", len);
    if (len > max) {
      max = len;
      printf("max so far is %d\n", max);
      copy(longest, line);
    }
  }
  if (max > 0) {
    printf("The longest line was: %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   1050 <getline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11b2 <main+0x82>
mov    -0x8(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11ad <main+0x7d>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1040 <copy@plt>
jmp    1149 <main+0x19>
cmpl   $0x0,-0xc(%rbp)
jle    11d1 <main+0xa1>
lea    -0x7f0(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <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   1050 <getline@plt>
test   %eax,%eax
jle    11d3 <main+0xa3>
mov    %eax,%ebp
lea    0xea0(%rip),%r12
lea    0xeb2(%rip),%r14
mov    %rsp,%r15
lea    0x3f0(%rsp),%r13
xor    %ebx,%ebx
jmp    1193 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x3e8,%esi
call   1050 <getline@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11be <main+0x8e>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %ebx,%ebp
jle    1180 <main+0x50>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <copy@plt>
mov    %ebp,%ebx
jmp    1180 <main+0x50>
test   %ebx,%ebx
jle    11d3 <main+0xa3>
lea    0xe62(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
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):
@.str = [25 x i8] c"len for this line is %d\0A\00"
@.str.1 = [18 x i8] c"max so far is %d\0A\00"
@.str.2 = [25 x i8] c"The longest line was: %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 = %23, %0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = call i32 @getline(i8* %7, i32 1000)
store i32 %8, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = load i32, i32* %2
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = call i32 @copy(i8* %20, i8* %21)
br label %23
23: ; preds = %16, %10
br label %6
24: ; preds = %6
%25 = load i32, i32* %3
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %24
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"len for this line is %d\0A\00"
@.str.1 = [18 x i8] c"max so far is %d\0A\00"
@.str.2 = [25 x i8] c"The longest line was: %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 @getline(i8* %3, i32 1000)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %0, %15
%8 = phi i32 [ %17, %15 ], [ %5, %0 ]
%9 = phi i32 [ %16, %15 ], [ 0, %0 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8)
%11 = icmp sgt i32 %8, %9
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%14 = call i32 @copy(i8* %4, i8* %3)
br label %15
15: ; preds = %12, %7
%16 = phi i32 [ %8, %12 ], [ %9, %7 ]
%17 = call i32 @getline(i8* %3, i32 1000)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %7, label %19
19: ; preds = %15
%20 = icmp sgt i32 %16, 0
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %23
23: ; preds = %0, %21, %19
ret i32 0
}