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


x86 assembly (clang, -O0):
<Search_in_File>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1192 <Search_in_File+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <Search_in_File+0xc7>
jmp    1197 <Search_in_File+0x57>
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11ed <Search_in_File+0xad>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11df <Search_in_File+0x9f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1197 <Search_in_File+0x57>
cmpq   $0x0,-0x20(%rbp)
je     1201 <Search_in_File+0xc1>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Search_in_File>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11bb <Search_in_File+0x7b>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c2 <Search_in_File+0x82>
mov    $0x1,%ebx
xor    %ebp,%ebp
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
cmovne %ebx,%ebp
add    $0x1,%ebx
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <Search_in_File+0x50>
jmp    11c4 <Search_in_File+0x84>
mov    $0xffffffff,%ebp
jmp    11cc <Search_in_File+0x8c>
xor    %ebp,%ebp
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @Search_in_File(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 %22, 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 %19, label %10
10: ; preds = %7, %10
%11 = phi i32 [ %15, %10 ], [ 0, %7 ]
%12 = phi i32 [ %16, %10 ], [ 1, %7 ]
%13 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %1)
%14 = icmp eq i32* %13, null
%15 = select i1 %14, i32 %11, i32 %12
%16 = add nuw nsw i32 %12, 1
%17 = call i32* @fgets(i8* %4, i32 512, i32* %5)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %10
19: ; preds = %10, %7
%20 = phi i32 [ 0, %7 ], [ %15, %10 ]
%21 = call i32 @fclose(i32* %5)
br label %22
22: ; preds = %2, %19
%23 = phi i32 [ %20, %19 ], [ -1, %2 ]
ret i32 %23
}