#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ cmpStr(int, int, char *);
int lseek(int, int, int);
int open(char *, int /*<<< orphan*/);
int printLine(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, count = 0, len, line = 0;
  char buffer, flag = 'y';
  fd = open(argv[2], O_RDWR);
  if (fd != -1) {
    len = lseek(fd, 0L, 2);
    while (lseek(fd, count, 0) < len) {
      count++;
      read(fd, &buffer, sizeof(char));
      if (argv[1][0] == (char)buffer) {
        if (cmpStr(fd, count, argv[1])) {
          count = printLine(fd, line);
          line = count;
        }
      } else if ((char)buffer == '\n')
        line = count;
    }
  } else
    printf("\nFile not found\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movb   $0x79,-0x22(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     126c <main+0xfc>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <lseek@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1040 <lseek@plt>
cmp    -0x1c(%rbp),%eax
jge    1267 <main+0xf7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    124a <main+0xda>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
call   1070 <cmpStr@plt>
cmp    $0x0,%rax
je     1245 <main+0xd5>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1090 <printLine@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1262 <main+0xf2>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    125d <main+0xed>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1262 <main+0xf2>
jmp    11cd <main+0x5d>
jmp    1278 <main+0x108>
lea    0xd8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1224 <main+0xb4>
xor    %r13d,%r13d
mov    %ebp,%edi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <lseek@plt>
mov    %eax,%r15d
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
cmp    %r15d,%eax
jge    1230 <main+0xc0>
lea    0x7(%rsp),%r12
xor    %ebx,%ebx
jmp    11e6 <main+0x76>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
cmove  %ebx,%r13d
mov    %ebp,%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
cmp    %r15d,%eax
jge    1230 <main+0xc0>
add    $0x1,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    0x8(%r14),%rdx
movzbl 0x7(%rsp),%eax
cmp    %al,(%rdx)
jne    11d0 <main+0x60>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <cmpStr@plt>
test   %rax,%rax
je     11d6 <main+0x66>
mov    %ebp,%edi
mov    %r13d,%esi
call   1090 <printLine@plt>
mov    %eax,%ebx
mov    %eax,%r13d
jmp    11d6 <main+0x66>
lea    0xdd5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [17 x i8] c"\0AFile not found\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %9
store i8 121, i8* %11
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %65
19: ; preds = %2
%20 = load i32, i32* %6
%21 = call i32 @lseek(i32 %20, i32 0, i32 2)
store i32 %21, i32* %8
br label %22
22: ; preds = %63, %19
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i32 @lseek(i32 %23, i32 %24, i32 0)
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %64
28: ; preds = %22
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
%31 = load i32, i32* %6
%32 = call i32 @read(i32 %31, i8* %10, i32 1)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = load i8, i8* %10
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %38, %40
br i1 %41, label %42, label %56
42: ; preds = %28
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i64 @cmpStr(i32 %43, i32 %44, i8* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %42
%51 = load i32, i32* %6
%52 = load i32, i32* %9
%53 = call i32 @printLine(i32 %51, i32 %52)
store i32 %53, i32* %7
%54 = load i32, i32* %7
store i32 %54, i32* %9
br label %55
55: ; preds = %50, %42
br label %63
56: ; preds = %28
%57 = load i8, i8* %10
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 10
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load i32, i32* %7
store i32 %61, i32* %9
br label %62
62: ; preds = %60, %56
br label %63
63: ; preds = %62, %55
br label %22
64: ; preds = %22
br label %67
65: ; preds = %2
%66 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %67
67: ; preds = %65, %64
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@str = [16 x i8] c"\0AFile not found\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = getelementptr inbounds i8*, i8** %1, i64 2
%5 = load i8*, i8** %4
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %37, label %9
9: ; preds = %2
%10 = tail call i32 @lseek(i32 %7, i32 0, i32 2)
%11 = tail call i32 @lseek(i32 %7, i32 0, i32 0)
%12 = icmp slt i32 %11, %10
br i1 %12, label %13, label %39
13: ; preds = %9
%14 = getelementptr inbounds i8*, i8** %1, i64 1
br label %15
15: ; preds = %13, %32
%16 = phi i32 [ 0, %13 ], [ %34, %32 ]
%17 = phi i32 [ 0, %13 ], [ %33, %32 ]
%18 = add nsw i32 %17, 1
%19 = call i32 @read(i32 %7, i8* %3, i32 1)
%20 = load i8*, i8** %14
%21 = load i8, i8* %20
%22 = load i8, i8* %3
%23 = icmp eq i8 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %15
%25 = tail call i64 @cmpStr(i32 %7, i32 %18, i8* %20)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = tail call i32 @printLine(i32 %7, i32 %16)
br label %32
29: ; preds = %15
%30 = icmp eq i8 %22, 10
%31 = select i1 %30, i32 %18, i32 %16
br label %32
32: ; preds = %29, %24, %27
%33 = phi i32 [ %28, %27 ], [ %18, %24 ], [ %18, %29 ]
%34 = phi i32 [ %28, %27 ], [ %16, %24 ], [ %31, %29 ]
%35 = tail call i32 @lseek(i32 %7, i32 %33, i32 0)
%36 = icmp slt i32 %35, %10
br i1 %36, label %15, label %39
37: ; preds = %2
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %39
39: ; preds = %32, %9, %37
%40 = tail call i32 @close(i32 %7)
ret i32 0
}