#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 scalar_t__ time_t;

/* Variables and functions */
int /*<<< orphan*/ puts(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ time(scalar_t__ *);
int main() {
  char ch, line[512];
  time_t lasttm = 0;
  int c = 0;
  while (read(0, &ch, 1) == 1) {
    line[c++] = ch;
    if (ch == '\n')
      if (lasttm < time(NULL) - 5) {
        line[c - 1] = c = 0;
        puts(line);
        time(&lasttm);
      } else
        c = 0;
    else if (c > 500)
      c = 500;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x218(%rbp)
movl   $0x0,-0x21c(%rbp)
xor    %edi,%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1236 <main+0x106>
mov    -0x5(%rbp),%cl
mov    -0x21c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x21c(%rbp)
cltq
mov    %cl,-0x210(%rbp,%rax,1)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    1212 <main+0xe2>
mov    -0x218(%rbp),%rax
mov    %rax,-0x228(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%ecx
mov    -0x228(%rbp),%rax
sub    $0x5,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    1203 <main+0xd3>
movl   $0x0,-0x21c(%rbp)
mov    -0x21c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rdi
call   1030 <puts@plt>
lea    -0x218(%rbp),%rdi
call   1050 <time@plt>
jmp    120d <main+0xdd>
movl   $0x0,-0x21c(%rbp)
jmp    1231 <main+0x101>
cmpl   $0x1f4,-0x21c(%rbp)
jle    122c <main+0xfc>
movl   $0x1f4,-0x21c(%rbp)
jmp    1231 <main+0x101>
jmp    1157 <main+0x27>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
movq   $0x0,0x8(%rsp)
xor    %ebx,%ebx
lea    0x7(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    11e0 <main+0xb0>
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x7(%rsp),%r12
mov    $0x1f3,%r13d
jmp    11a1 <main+0x71>
nopl   0x0(%rax)
cmp    $0x1f3,%ebx
cmovge %r13d,%ebx
add    $0x1,%ebx
xor    %edi,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    11e0 <main+0xb0>
movzbl 0x7(%rsp),%eax
movslq %ebx,%rcx
mov    %al,0x10(%rsp,%rcx,1)
cmp    $0xa,%al
jne    1180 <main+0x50>
mov    0x8(%rsp),%rbp
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <time@plt>
add    $0xfffffffb,%eax
cltq
cmp    %rax,%rbp
jge    118d <main+0x5d>
movb   $0x0,0xf(%rsp)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1050 <time@plt>
jmp    118d <main+0x5d>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [512 x i8]
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %39, %0
%7 = call i32 @read(i32 0, i8* %2, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = load i8, i8* %2
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 1
store i32 %12, i32* %5
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %13
store i8 %10, i8* %14
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %34
18: ; preds = %9
%19 = load i64, i64* %4
%20 = call i32 @time(i64* null)
%21 = sub nsw i32 %20, 5
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %19, %22
br i1 %23, label %24, label %32
24: ; preds = %18
store i32 0, i32* %5
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%30 = call i32 @puts(i8* %29)
%31 = call i32 @time(i64* %4)
br label %33
32: ; preds = %18
store i32 0, i32* %5
br label %33
33: ; preds = %32, %24
br label %39
34: ; preds = %9
%35 = load i32, i32* %5
%36 = icmp sgt i32 %35, 500
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 500, i32* %5
br label %38
38: ; preds = %37, %34
br label %39
39: ; preds = %38, %33
br label %6
40: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i8
%2 = alloca [512 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = call i32 @read(i32 0, i8* %1, i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %33
8: ; preds = %0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 -1
br label %10
10: ; preds = %8, %29
%11 = phi i32 [ 0, %8 ], [ %30, %29 ]
%12 = load i8, i8* %1
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %13
store i8 %12, i8* %14
%15 = icmp eq i8 %12, 10
br i1 %15, label %16, label %25
16: ; preds = %10
%17 = load i64, i64* %3
%18 = call i32 @time(i64* null)
%19 = add nsw i32 %18, -5
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %17, %20
br i1 %21, label %22, label %29
22: ; preds = %16
store i8 0, i8* %9
%23 = call i32 @puts(i8* %4)
%24 = call i32 @time(i64* %3)
br label %29
25: ; preds = %10
%26 = icmp slt i32 %11, 499
%27 = select i1 %26, i32 %11, i32 499
%28 = add nsw i32 %27, 1
br label %29
29: ; preds = %16, %22, %25
%30 = phi i32 [ 0, %22 ], [ %28, %25 ], [ 0, %16 ]
%31 = call i32 @read(i32 0, i8* %1, i32 1)
%32 = icmp eq i32 %31, 1
br i1 %32, label %10, label %33
33: ; preds = %29, %0
ret i32 0
}