#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 _getline(char *, int);
int /*<<< orphan*/ copy(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int length;
  int max;
  char line[1000];
  char longest[1000];
  max = 0;
  while ((length = _getline(line, 1000)) > 0) {
    if (length > max) {
      max = length;
      copy(longest, line);
    }
  }
  if (max > 0) {
    if (max > 1000) {
      printf("\nStorage limit exceeded by: %d\n", max - 1000);
      printf("String length: %d\n", max);
      printf("%s\n", longest);
    } else {
      printf("Longest line is %s\n", longest);
      printf("It's length is: %d\n", max);
    }
  }
  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    1190 <main+0x60>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    118b <main+0x5b>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1040 <copy@plt>
jmp    1149 <main+0x19>
cmpl   $0x0,-0xc(%rbp)
jle    1214 <main+0xe4>
cmpl   $0x3e8,-0xc(%rbp)
jle    11e9 <main+0xb9>
mov    -0xc(%rbp),%esi
sub    $0x3e8,%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x7f0(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <main+0xdf>
lea    -0x7f0(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <main+0xe4>
xor    %eax,%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x7d8,%rsp
lea    0x3f0(%rsp),%rdi
mov    $0x3e8,%esi
call   1060 <_getline@plt>
test   %eax,%eax
jle    1201 <main+0xc1>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %rsp,%r14
lea    0x3f0(%rsp),%r15
jmp    1193 <main+0x53>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x3e8,%esi
call   1060 <_getline@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11a6 <main+0x66>
cmp    %ebx,%ebp
jle    1180 <main+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <copy@plt>
mov    %ebp,%ebx
jmp    1180 <main+0x40>
test   %ebx,%ebx
jle    1201 <main+0xc1>
cmp    $0x3e9,%ebx
jb     11e0 <main+0xa0>
lea    -0x3e8(%rbx),%esi
lea    0xe41(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
call   1030 <puts@plt>
jmp    1201 <main+0xc1>
lea    0xe4c(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\0AStorage limit exceeded by: %d\0A\00"
@.str.1 = [19 x i8] c"String length: %d\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [20 x i8] c"Longest line is %s\0A\00"
@.str.4 = [20 x i8] c"It's length is: %d\0A\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 = %19, %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 %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 [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [1000 x i8], [1000 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 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 1000
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 1000
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %39
34: ; preds = %23
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %34, %26
br label %40
40: ; preds = %39, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"\0AStorage limit exceeded by: %d\0A\00"
@.str.1 = [19 x i8] c"String length: %d\0A\00"
@.str.3 = [20 x i8] c"Longest line is %s\0A\00"
@.str.4 = [20 x i8] c"It's length is: %d\0A\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 %29
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* %4, i8* %3)
br label %13
13: ; preds = %11, %7
%14 = phi i32 [ %8, %11 ], [ %9, %7 ]
%15 = call i32 @_getline(i8* %3, i32 1000)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %7, label %17
17: ; preds = %13
%18 = icmp sgt i32 %14, 0
br i1 %18, label %19, label %29
19: ; preds = %17
%20 = icmp ugt i32 %14, 1000
br i1 %20, label %21, label %26
21: ; preds = %19
%22 = add nsw i32 %14, -1000
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%25 = call i32 @puts(i8* %4)
br label %29
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %29
29: ; preds = %0, %21, %26, %17
ret i32 0
}