#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 *str) {
  FILE *fp;
  int line_num = 0;
  int find_result = 0, find_line = 0;
  char temp[512];
  if ((fp = fopen("savage.txt", "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);
  if (find_result == 0)
    return 0;
  return find_line;
}


x86 assembly (clang, -O0):
<Search_in_File>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe95(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1191 <Search_in_File+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    121c <Search_in_File+0xdc>
jmp    1196 <Search_in_File+0x56>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11ec <Search_in_File+0xac>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11de <Search_in_File+0x9e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <Search_in_File+0x56>
cmpq   $0x0,-0x18(%rbp)
je     1200 <Search_in_File+0xc0>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x20(%rbp)
jne    1216 <Search_in_File+0xd6>
movl   $0x0,-0x4(%rbp)
jmp    121c <Search_in_File+0xdc>
mov    -0x24(%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   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
lea    0xea5(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11d1 <Search_in_File+0x91>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     11c7 <Search_in_File+0x87>
mov    %rsp,%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
cmovne %ebp,%r13d
add    %ecx,%ebx
add    $0x1,%ebp
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <Search_in_File+0x50>
test   %ebx,%ebx
cmove  %ebx,%r13d
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11d7 <Search_in_File+0x97>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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