#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int searh_for(char *file, char *str) {
  int line_num = 1;
  int find_result = 0;
  char temp[512];
  FILE *fp;
  fp = fopen(file, "r");
  if (!fp) {
  } else {
    while (fgets(temp, 512, fp) != NULL) {
      if ((strstr(temp, str)) != NULL) {
        find_result++;
      }
      line_num++;
    }
    return find_result;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<searh_for>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    118b <searh_for+0x4b>
jmp    11ee <searh_for+0xae>
jmp    1190 <searh_for+0x50>
lea    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11e3 <searh_for+0xa3>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11d5 <searh_for+0x95>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1190 <searh_for+0x50>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fa <searh_for+0xba>
mov    -0x228(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searh_for>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a9 <searh_for+0x69>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11b0 <searh_for+0x70>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1180 <searh_for+0x40>
jmp    11b0 <searh_for+0x70>
xor    %edi,%edi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @searh_for(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 1, i32* %6
store i32 0, i32* %7
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
br label %34
15: ; preds = %2
br label %16
16: ; preds = %29, %15
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %9
%19 = call i32* @fgets(i8* %17, i32 512, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%23 = load i8*, i8** %5
%24 = call i32* @strstr(i8* %22, i8* %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %29
29: ; preds = %26, %21
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %16
32: ; preds = %16
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %37
34: ; preds = %14
%35 = load i32*, i32** %9
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %34, %32
%38 = load i32, i32* %3
ret i32 %38
}

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