// File: /workspace/github_cpp_makefile_star2_O3/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 $0x2b8, %rsp            # imm = 0x2B8
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rbx
leaq 0xb0(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2110
testl %eax, %eax
jne 0x2d67
movq %r12, %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x2190
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %r14, 0x88(%rsp)
movl 0x8(%r14), %eax
movl %eax, 0x3c(%rsp)
leaq 0xa0(%rsp), %r15
movq $0x0, 0x8(%rsp)
leaq 0x40(%rsp), %r13
movq 0x354e(%rip), %rbp      # 0x5fd0
xorl %ebx, %ebx
movq 0xb0(%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 0x2d17
leaq 0x18(%rsp), %rdi
leaq 0x15d1(%rip), %rsi      # 0x409c
callq 0x2050
testl %eax, %eax
je 0x2a84
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x28ce
movq %r15, 0x90(%rsp)
movq 0x88(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %r14
movq %r14, %rdi
callq 0x28ce
movq %r13, %rdi
leaq 0x68(%rsp), %rsi
movq %r14, %rdx
callq 0x2f01
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %rbx, %rbx
je 0x2b89
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movq %rbx, %rdi
callq 0x2150
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2b89
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ba6
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2bc2
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rsp), %rax
movq %rax, %rbx
cmpq 0x60(%rsp), %rax
je 0x2a84
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movq (%rsp), %rbx
movl (%rbx), %r14d
cmpl %r14d, %r15d
jge 0x2c25
movslq %r14d, %r12
movslq %r15d, %r15
movq 0x18(%rsp), %rax
movb (%rax,%r15), %al
movb %al, 0x40(%rsp)
movl $0x1, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2160
incq %r15
cmpq %r15, %r12
jne 0x2bfd
movl %r14d, %r15d
movq 0x350c(%rip), %rsi      # 0x6138
movq 0x350d(%rip), %rdx      # 0x6140
movq %rbp, %rdi
callq 0x2160
addl 0x3c(%rsp), %r14d
cmpl %r14d, %r15d
jge 0x2c73
movslq %r15d, %r15
movslq %r14d, %r12
movq 0x18(%rsp), %rax
movb (%rax,%r15), %al
movb %al, 0x40(%rsp)
movl $0x1, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2160
incq %r15
cmpq %r15, %r12
jne 0x2c4b
movl %r14d, %r15d
movq 0x349e(%rip), %rsi      # 0x6118
movq 0x349f(%rip), %rdx      # 0x6120
movq %rbp, %rdi
callq 0x2160
addq $0x4, %rbx
cmpq 0x60(%rsp), %rbx
jne 0x2bef
movq 0x8(%rsp), %rax
cmpl %eax, %r15d
jge 0x2ccc
movslq %r15d, %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 0x2ca8
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2120
leaq 0xb0(%rsp), %r12
leaq 0xa0(%rsp), %r15
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rsp), %rbx
jmp 0x2a84
testq %rbx, %rbx
je 0x2d2c
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movq %rbx, %rdi
callq 0x2150
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2d48
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0xb0(%rsp), %rdi
callq 0x2040
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3282(%rip), %rdi      # 0x5ff0
leaq 0x13a1(%rip), %rsi      # 0x4116
callq 0x2130
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2130
leaq 0x1393(%rip), %rsi      # 0x411f
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2170
leaq 0x28(%rsp), %r12
movq %rax, %r14
jmp 0x2e03
movq %r15, %rcx
leaq 0x78(%rsp), %r15
leaq 0x28(%rsp), %r12
movq %rax, %r14
movq 0x90(%rsp), %rdi
cmpq %rcx, %rdi
je 0x2dec
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2dec
leaq 0x78(%rsp), %r15
leaq 0x28(%rsp), %r12
movq %rax, %r14
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e03
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %r12, %rbx
jmp 0x2e47
movq %rax, %r14
movq (%rsp), %rdi
jmp 0x2e32
jmp 0x2e3b
jmp 0x2e3b
movq %rax, %r14
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
leaq 0x28(%rsp), %rbx
jmp 0x2e47
jmp 0x2e3b
movq %rax, %r14
leaq 0x28(%rsp), %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2e59
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2e70
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0xb0(%rsp), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x21b0
nopl (%rax)