#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 EOF;
scalar_t__ Strstr(char *, char *);
int getchar();
int /*<<< orphan*/ printf(char *, char *);
void FastGrep(char pattern[]) {
  int c;
  int size = 0;
  char line[1000 + 1];
  while ((c = getchar()) != EOF) {
    if (size < 1000)
      line[size++] = c;
    if (c == '\n') {
      line[size] = '\0';
      if (Strstr(line, pattern))
        printf("%s", line);
      size = 0;
    }
  }
  if (size > 0) {
    line[size] = '\0';
    if (Strstr(line, pattern))
      printf("%s", line);
  }
}


x86 assembly (clang, -O0):
<FastGrep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%eax
je     11d4 <FastGrep+0xa4>
cmpl   $0x3e8,-0x10(%rbp)
jge    1185 <FastGrep+0x55>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0x400(%rbp,%rax,1)
cmpl   $0xa,-0xc(%rbp)
jne    11cf <FastGrep+0x9f>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <Strstr@plt>
cmp    $0x0,%rax
je     11c8 <FastGrep+0x98>
lea    -0x400(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    1146 <FastGrep+0x16>
cmpl   $0x0,-0x10(%rbp)
jle    121c <FastGrep+0xec>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <Strstr@plt>
cmp    $0x0,%rax
je     1217 <FastGrep+0xe7>
lea    -0x400(%rbp),%rsi
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
jmp    121c <FastGrep+0xec>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FastGrep>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e98(%rip),%rbx
cmp    (%rbx),%eax
je     11e0 <FastGrep+0xb0>
mov    %rsp,%r14
lea    0xe9e(%rip),%r15
xor    %ebp,%ebp
jmp    117b <FastGrep+0x4b>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%rbx),%eax
je     11b7 <FastGrep+0x87>
cmp    $0x3e7,%ebp
jg     118c <FastGrep+0x5c>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%rsp,%rcx,1)
cmp    $0xa,%eax
jne    1170 <FastGrep+0x40>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <Strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1170 <FastGrep+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
jmp    1170 <FastGrep+0x40>
test   %ebp,%ebp
jle    11e0 <FastGrep+0xb0>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    %r12,%rsi
call   1050 <Strstr@plt>
test   %rax,%rax
je     11e0 <FastGrep+0xb0>
lea    0xe28(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [3 x i8] c"%s\00"
define void @FastGrep(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1001 x i8]
store i8* %0, i8** %2
store i32 0, i32* %4
br label %6
6: ; preds = %35, %1
%7 = call i32 (...) @getchar()
store i32 %7, i32* %3
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %36
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1000
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %3
%15 = trunc i32 %14 to i8
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 %18
store i8 %15, i8* %19
br label %20
20: ; preds = %13, %10
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %2
%29 = call i64 @Strstr(i8* %27, i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %23
store i32 0, i32* %4
br label %35
35: ; preds = %34, %20
br label %6
36: ; preds = %6
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %36
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%44 = load i8*, i8** %2
%45 = call i64 @Strstr(i8* %43, i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %39
%48 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %39
br label %51
51: ; preds = %50, %36
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [3 x i8] c"%s\00"
define void @FastGrep(i8* %0) {
%2 = alloca [1001 x i8]
%3 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 0
%4 = call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %40, label %7
7: ; preds = %1, %26
%8 = phi i32 [ %28, %26 ], [ %4, %1 ]
%9 = phi i32 [ %27, %26 ], [ 0, %1 ]
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = trunc i32 %8 to i8
%13 = add nsw i32 %9, 1
%14 = sext i32 %9 to i64
%15 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 %14
store i8 %12, i8* %15
br label %16
16: ; preds = %11, %7
%17 = phi i32 [ %13, %11 ], [ %9, %7 ]
%18 = icmp eq i32 %8, 10
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i64 @Strstr(i8* %3, i8* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %26
26: ; preds = %19, %24, %16
%27 = phi i32 [ %17, %16 ], [ 0, %24 ], [ 0, %19 ]
%28 = call i32 (...) @getchar()
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %7
31: ; preds = %26
%32 = icmp sgt i32 %27, 0
br i1 %32, label %33, label %40
33: ; preds = %31
%34 = zext i32 %27 to i64
%35 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i64 @Strstr(i8* %3, i8* %0)
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %40
40: ; preds = %1, %33, %38, %31
ret void
}