#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();
int getline();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int len;
  extern int max;
  extern char longest[];
  max = 0;
  while ((len = getline()) > 0) {
    printf("len for this line is %d\n", len);
    if (len > max) {
      max = len;
      printf("max so far is %d\n", max);
      copy();
    }
  }
  if (max > 0) {
    printf("The longest line was: %s", longest);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
movl   $0x0,(%rax)
mov    $0x0,%al
call   1050 <getline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11b1 <main+0x81>
mov    -0x8(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%eax
jle    11ac <main+0x7c>
mov    -0x8(%rbp),%ecx
mov    0x2e54(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <copy@plt>
jmp    114c <main+0x1c>
mov    0x2e28(%rip),%rax
cmpl   $0x0,(%rax)
jle    11d6 <main+0xa6>
lea    0xe63(%rip),%rdi
mov    0x2e09(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2ea2(%rip),%rbx
movl   $0x0,(%rbx)
xor    %eax,%eax
call   1050 <getline@plt>
test   %eax,%eax
jle    11a4 <main+0x74>
mov    %eax,%ebp
lea    0xea8(%rip),%r15
lea    0xeba(%rip),%r14
jmp    117d <main+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getline@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11a4 <main+0x74>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    (%rbx),%ebp
jle    1170 <main+0x40>
mov    %ebp,(%rbx)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <copy@plt>
jmp    1170 <main+0x40>
cmpl   $0x0,(%rbx)
jle    11be <main+0x8e>
lea    0xe7b(%rip),%rdi
mov    0x2e21(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@max = external global i32
@.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"
@longest = external global [0 x i8]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* @max
br label %3
3: ; preds = %17, %0
%4 = call i32 (...) @getline()
store i32 %4, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
%10 = load i32, i32* @max
%11 = icmp sgt i32 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = load i32, i32* %2
store i32 %13, i32* @max
%14 = load i32, i32* @max
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @copy()
br label %17
17: ; preds = %12, %6
br label %3
18: ; preds = %3
%19 = load i32, i32* @max
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([0 x i8], [0 x i8]* @longest, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
ret i32 0
}

LLVM IR (-O2):
@max = external global i32
@.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"
@longest = external global [0 x i8]
define i32 @main() {
store i32 0, i32* @max
%1 = tail call i32 (...) @getline()
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %14
3: ; preds = %0, %11
%4 = phi i32 [ %12, %11 ], [ %1, %0 ]
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @max
%7 = icmp sgt i32 %4, %6
br i1 %7, label %8, label %11
8: ; preds = %3
store i32 %4, i32* @max
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%10 = tail call i32 (...) @copy()
br label %11
11: ; preds = %8, %3
%12 = tail call i32 (...) @getline()
%13 = icmp sgt i32 %12, 0
br i1 %13, label %3, label %14
14: ; preds = %11, %0
%15 = load i32, i32* @max
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([0 x i8], [0 x i8]* @longest, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
ret i32 0
}