#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(void) {
  int len;
  int max;
  char line[10];
  char longest[10];
  max = 0;
  while ((len = getLine(line, 10)) > 0) {
    if (len > max) {
      max = len;
      copy(longest, line);
    }
  }
  printf("Longest line was: %d characters\n", max);
  if (max > 0) {
    printf("%s", longest);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x16(%rbp),%rdi
mov    $0xa,%esi
call   1050 <getLine@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1184 <main+0x54>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    117f <main+0x4f>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x16(%rbp),%rsi
call   1040 <copy@plt>
jmp    1146 <main+0x16>
mov    -0xc(%rbp),%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11b1 <main+0x81>
lea    -0x20(%rbp),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
call   1060 <getLine@plt>
test   %eax,%eax
jle    11bf <main+0x7f>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x4(%rsp),%r14
lea    0xe(%rsp),%r15
jmp    1183 <main+0x43>
nopl   (%rax)
mov    %r15,%rdi
mov    $0xa,%esi
call   1060 <getLine@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1196 <main+0x56>
cmp    %ebx,%ebp
jle    1170 <main+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <copy@plt>
mov    %ebp,%ebx
jmp    1170 <main+0x30>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    11cf <main+0x8f>
lea    0xe70(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cf <main+0x8f>
lea    0xe3a(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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