#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 get_line(char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(void) {
  int len = 0;
  int max = 0;
  char line[1000];
  char longest[1000];
  while ((len = get_line(line, 1000)) > 0) {
    if (len > max) {
      max = len;
      strncpy(longest, line, len);
    }
  }
  if (max > 0)
    printf("String:\n%sLength: %d\n", longest, max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    119a <main+0x6a>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1195 <main+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <strncpy@plt>
jmp    1150 <main+0x20>
cmpl   $0x0,-0xc(%rbp)
jle    11ba <main+0x8a>
lea    -0x7f0(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe4b(%rip),%rdi
call   1050 <printf@plt>
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   1040 <get_line@plt>
test   %eax,%eax
jle    11ad <main+0x7d>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %rsp,%r14
lea    0x3f0(%rsp),%r15
jmp    1183 <main+0x53>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x3e8,%esi
call   1040 <get_line@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1198 <main+0x68>
cmp    %ebx,%ebp
jle    1170 <main+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %ebp,%ebx
jmp    1170 <main+0x40>
test   %ebx,%ebx
jle    11ad <main+0x7d>
lea    0xe5d(%rip),%rdi
mov    %rsp,%rsi
mov    %ebx,%edx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"String:\0A%sLength: %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 @get_line(i8* %3, i32 1000)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %21
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 @strncpy(i8* %4, i8* %3, i32 %8)
br label %13
13: ; preds = %11, %7
%14 = phi i32 [ %8, %11 ], [ %9, %7 ]
%15 = call i32 @get_line(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 %21
19: ; preds = %17
%20 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %14)
br label %21
21: ; preds = %0, %19, %17
ret i32 0
}