#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *realloc(char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  size_t max = 0;
  size_t n = 0;
  ssize_t len = 0;
  char *line = NULL;
  char *longest = NULL;
  while ((len = getline(&line, &n, stdin)) != -1) {
    if (len > max) {
      max = len;
      longest = realloc(longest, len);
      strncpy(longest, line, len);
    }
  }
  if (max > 0) {
    printf("%s", longest);
    printf("\n%ld chars long\n", max);
  }
  free(line);
  free(longest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11ea <main+0x9a>
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11e5 <main+0x95>
movslq -0x24(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <strncpy@plt>
jmp    118d <main+0x3d>
cmpq   $0x0,-0x18(%rbp)
jbe    1219 <main+0xc9>
mov    -0x38(%rbp),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     121d <main+0xcd>
mov    %eax,%ebp
xor    %r12d,%r12d
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
xor    %r13d,%r13d
jmp    11cb <main+0x7b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <getline@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11f4 <main+0xa4>
movslq %ebp,%rbx
cmp    %rbx,%r13
jae    11b0 <main+0x60>
mov    %r12,%rdi
mov    %ebp,%esi
call   1060 <realloc@plt>
mov    %rax,%r12
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <strncpy@plt>
mov    %rbx,%r13
jmp    11b0 <main+0x60>
test   %r13,%r13
je     1220 <main+0xd0>
lea    0xe00(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf2(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1220 <main+0xd0>
xor    %r12d,%r12d
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [17 x i8] c"\0A%ld chars long\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i64 0, i64* %7
store i32 0, i32* %8
store i8* null, i8** %9
store i8* null, i8** %10
br label %11
11: ; preds = %30, %2
%12 = load i32, i32* @stdin
%13 = call i32 @getline(i8** %9, i64* %7, i32 %12)
store i32 %13, i32* %8
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = load i64, i64* %6
%19 = icmp ugt i64 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
store i64 %22, i64* %6
%23 = load i8*, i8** %10
%24 = load i32, i32* %8
%25 = call i8* @realloc(i8* %23, i32 %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = load i8*, i8** %9
%28 = load i32, i32* %8
%29 = call i32 @strncpy(i8* %26, i8* %27, i32 %28)
br label %30
30: ; preds = %20, %15
br label %11
31: ; preds = %11
%32 = load i64, i64* %6
%33 = icmp ugt i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8*, i8** %10
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = load i64, i64* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %37)
br label %39
39: ; preds = %34, %31
%40 = load i8*, i8** %9
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %10
%43 = call i32 @free(i8* %42)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [17 x i8] c"\0A%ld chars long\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %4, i64* %3, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %31, label %10
10: ; preds = %2, %20
%11 = phi i32 [ %24, %20 ], [ %8, %2 ]
%12 = phi i8* [ %22, %20 ], [ null, %2 ]
%13 = phi i64 [ %21, %20 ], [ 0, %2 ]
%14 = sext i32 %11 to i64
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = call i8* @realloc(i8* %12, i32 %11)
%18 = load i8*, i8** %4
%19 = call i32 @strncpy(i8* %17, i8* %18, i32 %11)
br label %20
20: ; preds = %16, %10
%21 = phi i64 [ %14, %16 ], [ %13, %10 ]
%22 = phi i8* [ %17, %16 ], [ %12, %10 ]
%23 = load i32, i32* @stdin
%24 = call i32 @getline(i8** %4, i64* %3, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %10
26: ; preds = %20
%27 = icmp eq i64 %21, 0
br i1 %27, label %31, label %28
28: ; preds = %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %21)
br label %31
31: ; preds = %2, %28, %26
%32 = phi i8* [ %22, %28 ], [ %22, %26 ], [ null, %2 ]
%33 = load i8*, i8** %4
%34 = call i32 @free(i8* %33)
%35 = call i32 @free(i8* %32)
ret i32 0
}