#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 getmyline(char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
int main() {
  int len;
  int max;
  char line[1000];
  char longest[1000];
  while ((len = getmyline(line, 1000)) > 0) {
    max = 0;
    if (len > max) {
      max = len;
      copy(longest, line);
    }
    if (max > 0) {
      printf("%s, length is %d\n", longest, max);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <getmyline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11b0 <main+0x80>
movl   $0x0,-0xc(%rbp)
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   1050 <copy@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11ab <main+0x7b>
lea    -0x7f0(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
jmp    1142 <main+0x12>
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
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1030 <getmyline@plt>
test   %eax,%eax
jle    119b <main+0x6b>
mov    %eax,%ebp
lea    0x3f0(%rsp),%r14
mov    %rsp,%rbx
lea    0xe9e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <copy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1030 <getmyline@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1170 <main+0x40>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%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
br label %6
6: ; preds = %26, %0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = call i32 @getmyline(i8* %7, i32 1000)
store i32 %8, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %6
store i32 0, i32* %3
%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
%20 = load i32, i32* %3
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %24)
br label %26
26: ; preds = %22, %19
br label %6
27: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"%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 @getmyline(i8* %3, i32 1000)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %0, %7
%8 = phi i32 [ %11, %7 ], [ %5, %0 ]
%9 = call i32 @copy(i8* %4, i8* %3)
%10 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %8)
%11 = call i32 @getmyline(i8* %3, i32 1000)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %7, %0
ret i32 0
}