#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *, unsigned int, char *);
char *strstr(char *, char const *);
void scan_file(const char *keyword, const char *file_name) {
  FILE *fp = NULL;
  char buf[2048] = {0};
  char *ret = NULL;
  unsigned int line = 0;
  fp = fopen(file_name, "r");
  if (NULL == fp) {
    ;
    goto exit;
  }
  while (fgets(buf, sizeof(buf), fp) != NULL) {
    line++;
    ret = strstr(buf, keyword);
    if (ret != NULL) {
      if (0 == (ret - buf)) {
        printf("%s|%d| %s", file_name, line, buf);
      }
    }
  }
exit:
  if (NULL != fp) {
    fclose(fp);
  }
  return;
}


x86 assembly (clang, -O0):
<scan_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
movq   $0x0,-0x828(%rbp)
movl   $0x0,-0x82c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11c8 <scan_file+0x68>
jmp    1268 <scan_file+0x108>
jmp    11cd <scan_file+0x6d>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1263 <scan_file+0x103>
mov    -0x82c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x82c(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
je     125e <scan_file+0xfe>
mov    -0x828(%rbp),%rcx
lea    -0x820(%rbp),%rax
sub    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1259 <scan_file+0xf9>
mov    -0x10(%rbp),%rsi
mov    -0x82c(%rbp),%edx
lea    -0x820(%rbp),%rcx
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
jmp    125e <scan_file+0xfe>
jmp    11cd <scan_file+0x6d>
jmp    1268 <scan_file+0x108>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     127d <scan_file+0x11d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x800,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe73(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1217 <scan_file+0xb7>
mov    %rax,%r12
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120f <scan_file+0xaf>
mov    $0x1,%ebp
lea    0xe41(%rip),%r13
jmp    11e8 <scan_file+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
je     120f <scan_file+0xaf>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11d0 <scan_file+0x70>
cmp    %rbx,%rax
jne    11d0 <scan_file+0x70>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <printf@plt>
jmp    11d0 <scan_file+0x70>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"%s|%d| %s\00"
define void @scan_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [2048 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32* null, i32** %5
%9 = bitcast [2048 x i8]* %6 to i8*
store i8* null, i8** %7
store i32 0, i32* %8
%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** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %15
14: ; preds = %2
br label %44
15: ; preds = %2
br label %16
16: ; preds = %42, %15
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32* @fgets(i8* %17, i32 2048, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %43
21: ; preds = %16
%22 = load i32, i32* %8
%23 = add i32 %22, 1
store i32 %23, i32* %8
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i8* @strstr(i8* %24, i8* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %42
29: ; preds = %21
%30 = load i8*, i8** %7
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = icmp eq i64 0, %34
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %37, i32 %38, i8* %39)
br label %41
41: ; preds = %36, %29
br label %42
42: ; preds = %41, %21
br label %16
43: ; preds = %16
br label %44
44: ; preds = %43, %14
%45 = load i32*, i32** %5
%46 = icmp ne i32* null, %45
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32*, i32** %5
%49 = call i32 @fclose(i32* %48)
br label %50
50: ; preds = %47, %44
ret void
}

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