#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ *strstr(char *, char const *);
int find_str(FILE *fp, const char *str) {
  char buf[256] = "";
  int count = 0;
  if (fp == NULL || str == NULL)
    return (-1);
  else
    rewind(fp);
  while (fgets(buf, 256, fp) != NULL)
    if (strstr(buf, str) != NULL) {
      ++count;
      fputs(buf, stdout);
    }
  if (feof(fp))
    return count;
  else
    return (-1);
}


x86 assembly (clang, -O0):
<find_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movl   $0x0,-0x124(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a6 <find_str+0x46>
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <find_str+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <find_str+0xea>
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
jmp    11c0 <find_str+0x60>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1222 <find_str+0xc2>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     121d <find_str+0xbd>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    11c0 <find_str+0x60>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1243 <find_str+0xe3>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124a <find_str+0xea>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_str>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1256 <find_str+0x106>
mov    %rsi,%r14
test   %rsi,%rsi
je     1256 <find_str+0x106>
mov    %rdi,%r15
call   1030 <rewind@plt>
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1246 <find_str+0xf6>
mov    %rsp,%rbx
mov    0x2dd8(%rip),%r12
jmp    1225 <find_str+0xd5>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1246 <find_str+0xf6>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1210 <find_str+0xc0>
add    $0x1,%ebp
mov    (%r12),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
jmp    1210 <find_str+0xc0>
mov    %r15,%rdi
call   1060 <feof@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @find_str(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = bitcast [256 x i8]* %6 to i8*
store i32 0, i32* %7
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i32 -1, i32* %3
br label %43
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = call i32 @rewind(i32* %16)
br label %18
18: ; preds = %15
br label %19
19: ; preds = %35, %18
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = load i32*, i32** %4
%22 = call i32* @fgets(i8* %20, i32 256, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %36
24: ; preds = %19
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32* @strstr(i8* %25, i8* %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%33 = load i32, i32* @stdout
%34 = call i32 @fputs(i8* %32, i32 %33)
br label %35
35: ; preds = %29, %24
br label %19
36: ; preds = %19
%37 = load i32*, i32** %4
%38 = call i64 @feof(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i32, i32* %7
store i32 %41, i32* %3
br label %43
42: ; preds = %36
store i32 -1, i32* %3
br label %43
43: ; preds = %42, %40, %14
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @find_str(i32* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
br i1 %7, label %29, label %8
8: ; preds = %2
%9 = tail call i32 @rewind(i32* %0)
%10 = call i32* @fgets(i8* %4, i32 256, i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %24, label %12
12: ; preds = %8, %20
%13 = phi i32 [ %21, %20 ], [ 0, %8 ]
%14 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %1)
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = add nsw i32 %13, 1
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* %4, i32 %18)
br label %20
20: ; preds = %16, %12
%21 = phi i32 [ %17, %16 ], [ %13, %12 ]
%22 = call i32* @fgets(i8* %4, i32 256, i32* %0)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %12
24: ; preds = %20, %8
%25 = phi i32 [ 0, %8 ], [ %21, %20 ]
%26 = call i64 @feof(i32* %0)
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i32 -1, i32 %25
br label %29
29: ; preds = %24, %2
%30 = phi i32 [ -1, %2 ], [ %28, %24 ]
ret i32 %30
}