#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ *strstr(char *, char *);
int find(char *pattern, FILE *fp) {
  int found = 0;
  char line[1024];
  while (fgets(line, 1024, fp) != NULL) {
    if (strstr(line, pattern) != NULL) {
      fprintf(stdout, "%s", line);
      ++found;
    }
  }
  return (found == 0) ? 0 : 1;
}


x86 assembly (clang, -O0):
<find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11ad <find+0x7d>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11a8 <find+0x78>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <find+0x1a>
mov    -0x14(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1030 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11b9 <find+0x89>
mov    %rsp,%rbx
mov    0x2e78(%rip),%r13
lea    0xe91(%rip),%r12
jmp    1195 <find+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11b9 <find+0x89>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1180 <find+0x50>
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
add    $0x1,%ebp
jmp    1180 <find+0x50>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @find(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %7
7: ; preds = %23, %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = load i32*, i32** %4
%10 = call i32* @fgets(i8* %8, i32 1024, i32* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32* @strstr(i8* %13, i8* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* @stdout
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %23
23: ; preds = %17, %12
br label %7
24: ; preds = %7
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 0, i32 1
ret i32 %28
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @find(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32* @fgets(i8* %4, i32 1024, i32* %1)
%6 = icmp eq i32* %5, null
br i1 %6, label %19, label %7
7: ; preds = %2, %15
%8 = phi i32 [ %16, %15 ], [ 0, %2 ]
%9 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i32, i32* @stdout
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%14 = add nsw i32 %8, 1
br label %15
15: ; preds = %11, %7
%16 = phi i32 [ %14, %11 ], [ %8, %7 ]
%17 = call i32* @fgets(i8* %4, i32 1024, i32* %1)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %7
19: ; preds = %15, %2
%20 = phi i32 [ 0, %2 ], [ %16, %15 ]
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i32
ret i32 %22
}