// File: /workspace/github_cpp_makefile_star2_O1/maxgodfrey2004[P]gss/src/fileutils.cc
// Function: gss::fileutils::Match(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Match(std::string filename, std::string pattern) {
  CheckAccessible(filename.c_str());
  std::ifstream infile(filename);
  std::string line;
  std::vector<int> occurrences;
  int pattern_length = static_cast<int>(pattern.length());
  int line_idx;
  int line_length;

  while (std::getline(infile, line)) {
    if (line == "") {
      continue;
    }
    occurrences = kmp::FindMatches(line, pattern);
    if (!occurrences.empty()) {
      line_idx = 0;
      line_length = static_cast<int>(line.length());
      for (int occ_idx : occurrences) {
        for (; line_idx < occ_idx; ++line_idx) {
          std::cout << line[line_idx];
        }
        std::cout << color::RED;
        for (; line_idx < occ_idx + pattern_length; ++line_idx) {
          std::cout << line[line_idx];
        }
        std::cout << color::RESET;
      }
      for (; line_idx < line_length; ++line_idx) {
        std::cout << line[line_idx];
      }
      std::cout << std::endl;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rbx
leaq 0xa0(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2110
testl %eax, %eax
jne 0x2d45
movq %r12, %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x2190
leaq 0x28(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq $0x0, -0x8(%rbx)
movb $0x0, (%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x3c(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x40(%rsp), %r13
movq 0x3562(%rip), %rbp      # 0x5fd0
xorl %r15d, %r15d
leaq 0xa0(%rsp), %r12
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %edx
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2cfa
leaq 0x18(%rsp), %rdi
leaq 0x15dc(%rip), %rsi      # 0x409c
callq 0x2050
testl %eax, %eax
je 0x2a79
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x28d6
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %r12
movq %r12, %rdi
callq 0x28d6
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
movq %r12, %rdx
callq 0x2ebe
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq 0x48(%rsp), %r12
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %r15, %r15
je 0x2b5c
movq 0x8(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x2150
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2b73
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2b95
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x2bb1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rsp), %rax
movq %rax, %r15
cmpq %r12, %rax
je 0x2a71
movq %r14, 0x98(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
movq (%rsp), %r14
movslq (%r14), %r15
cmpl %r15d, %ebx
jge 0x2c12
movslq %ebx, %rbx
movq 0x18(%rsp), %rax
movb (%rax,%rbx), %al
movb %al, 0x40(%rsp)
movl $0x1, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2160
incq %rbx
cmpq %rbx, %r15
jne 0x2bee
movq 0x351f(%rip), %rsi      # 0x6138
movq 0x3520(%rip), %rdx      # 0x6140
movq %rbp, %rdi
callq 0x2160
addl 0x3c(%rsp), %r15d
cmpl %r15d, %ebx
jge 0x2c5c
movslq %ebx, %rbx
movslq %r15d, %r15
movq 0x18(%rsp), %rax
movb (%rax,%rbx), %al
movb %al, 0x40(%rsp)
movl $0x1, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2160
incq %rbx
cmpq %rbx, %r15
jne 0x2c38
movq 0x34b5(%rip), %rsi      # 0x6118
movq 0x34b6(%rip), %rdx      # 0x6120
movq %rbp, %rdi
callq 0x2160
addq $0x4, %r14
cmpq %r12, %r14
jne 0x2be3
movq 0x8(%rsp), %rax
cmpl %eax, %ebx
jge 0x2cb2
movslq %ebx, %rbx
movslq %eax, %r14
movq 0x18(%rsp), %rax
movb (%rax,%rbx), %al
movb %al, 0x40(%rsp)
movl $0x1, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2160
incq %rbx
cmpq %rbx, %r14
jne 0x2c8e
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
leaq 0x28(%rsp), %rbx
callq 0x2120
movq 0x98(%rsp), %r14
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rsp), %r15
jmp 0x2a71
testq %r15, %r15
je 0x2d0f
movq 0x8(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x2150
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2d26
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0xa0(%rsp), %rdi
callq 0x2040
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x32a4(%rip), %rdi      # 0x5ff0
leaq 0x13c3(%rip), %rsi      # 0x4116
callq 0x2130
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2130
leaq 0x13b5(%rip), %rsi      # 0x411f
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2170
leaq 0x68(%rsp), %r12
movq %rax, %r14
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2dba
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2dba
jmp 0x2ddc
leaq 0x68(%rsp), %r12
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ddf
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2ddf
movq %rax, %r14
jmp 0x2df8
jmp 0x2df0
jmp 0x2df0
movq %rax, %r14
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r15, %rdi
jmp 0x2dfc
jmp 0x2df0
movq %rax, %r14
leaq 0x28(%rsp), %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2e0e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2e25
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0xa0(%rsp), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x21b0
nop