#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ *strstr(char *, char *);
void search(char *filename, FILE *stream, char *string) {
  char buffer[512];
  while (fgets(buffer, 512, stream) != NULL) {
    if (strstr(buffer, string) != NULL) {
      if (filename != NULL)
        printf("%s:", filename);
      fputs(buffer, stdout);
    }
  }
}


x86 assembly (clang, -O0):
<search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11c5 <search+0x85>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11c0 <search+0x80>
cmpq   $0x0,-0x8(%rbp)
je     11ab <search+0x6b>
mov    -0x8(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x220(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    1157 <search+0x17>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d2 <search+0x92>
mov    %rsp,%rbx
mov    0x2e67(%rip),%rbp
lea    0xe80(%rip),%r13
jmp    11b0 <search+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d2 <search+0x92>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     119b <search+0x5b>
test   %r15,%r15
je     1190 <search+0x50>
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
jmp    1190 <search+0x50>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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