// File: 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
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x2f8(%rbp)
movq %rsi, -0x2f0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x20a0
movq %rax, %rdi
callq 0x3530
movq -0x2f8(%rbp), %rsi
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x2280
leaq -0x238(%rbp), %rdi
callq 0x2240
leaq -0x250(%rbp), %rdi
callq 0x35b0
movq -0x2f0(%rbp), %rdi
callq 0x2260
movl %eax, -0x254(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x2040
movq %rax, -0x300(%rbp)
jmp 0x319c
movq -0x300(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2230
movb %al, -0x301(%rbp)
jmp 0x31ba
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x31c9
jmp 0x34c5
leaq 0x2edc(%rip), %rsi      # 0x60ac
leaq -0x238(%rbp), %rdi
callq 0x35d0
movb %al, -0x302(%rbp)
jmp 0x31e4
movb -0x302(%rbp), %al
testb $0x1, %al
jne 0x31f0
jmp 0x3209
jmp 0x3180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x34f2
leaq -0x2a8(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x20c0
jmp 0x321e
movq -0x2f0(%rbp), %rsi
leaq -0x2c8(%rbp), %rdi
callq 0x20c0
jmp 0x3233
leaq -0x288(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
leaq -0x2c8(%rbp), %rdx
callq 0x3f60
jmp 0x324f
leaq -0x250(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x3600
leaq -0x288(%rbp), %rdi
callq 0x3630
leaq -0x2c8(%rbp), %rdi
callq 0x2308
leaq -0x2a8(%rbp), %rdi
callq 0x2308
leaq -0x250(%rbp), %rdi
callq 0x3690
testb $0x1, %al
jne 0x34c0
movl $0x0, -0x258(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x2260
movl %eax, -0x25c(%rbp)
leaq -0x250(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x2d0(%rbp), %rdi
callq 0x36d0
movq %rax, -0x2d8(%rbp)
movq -0x2d0(%rbp), %rdi
callq 0x3700
movq %rax, -0x2e0(%rbp)
leaq -0x2d8(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x3730
testb $0x1, %al
jne 0x3306
jmp 0x3452
leaq -0x2d8(%rbp), %rdi
callq 0x3770
movl (%rax), %eax
movl %eax, -0x2e4(%rbp)
movl -0x258(%rbp), %eax
cmpl -0x2e4(%rbp), %eax
jge 0x33b6
movslq -0x258(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x22f0
movq %rax, -0x310(%rbp)
jmp 0x3348
movq -0x310(%rbp), %rax
movsbl (%rax), %esi
movq 0x5c77(%rip), %rdi      # 0x8fd0
callq 0x2200
jmp 0x3360
jmp 0x3362
movl -0x258(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x258(%rbp)
jmp 0x331a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x33a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x2308
leaq -0x2a8(%rbp), %rdi
callq 0x2308
jmp 0x34f2
movq 0x5c13(%rip), %rdi      # 0x8fd0
leaq 0x5e04(%rip), %rsi      # 0x91c8
callq 0x2160
jmp 0x33cb
jmp 0x33cd
movl -0x258(%rbp), %eax
movl -0x2e4(%rbp), %ecx
addl -0x254(%rbp), %ecx
cmpl %ecx, %eax
jge 0x342a
movslq -0x258(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x22f0
movq %rax, -0x318(%rbp)
jmp 0x33ff
movq -0x318(%rbp), %rax
movsbl (%rax), %esi
movq 0x5bc0(%rip), %rdi      # 0x8fd0
callq 0x2200
jmp 0x3417
jmp 0x3419
movl -0x258(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x258(%rbp)
jmp 0x33cd
movq 0x5b9f(%rip), %rdi      # 0x8fd0
leaq 0x5d70(%rip), %rsi      # 0x91a8
callq 0x2160
jmp 0x343f
jmp 0x3441
leaq -0x2d8(%rbp), %rdi
callq 0x3790
jmp 0x32ea
jmp 0x3454
movl -0x258(%rbp), %eax
cmpl -0x25c(%rbp), %eax
jge 0x34a9
movslq -0x258(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x22f0
movq %rax, -0x320(%rbp)
jmp 0x347e
movq -0x320(%rbp), %rax
movsbl (%rax), %esi
movq 0x5b41(%rip), %rdi      # 0x8fd0
callq 0x2200
jmp 0x3496
jmp 0x3498
movl -0x258(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x258(%rbp)
jmp 0x3454
movq 0x5b20(%rip), %rdi      # 0x8fd0
movq 0x5b01(%rip), %rsi      # 0x8fb8
callq 0x21b0
jmp 0x34be
jmp 0x34c0
jmp 0x3180
leaq -0x250(%rbp), %rdi
callq 0x3630
leaq -0x238(%rbp), %rdi
callq 0x2308
leaq -0x218(%rbp), %rdi
callq 0x2050
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
leaq -0x250(%rbp), %rdi
callq 0x3630
leaq -0x238(%rbp), %rdi
callq 0x2308
leaq -0x218(%rbp), %rdi
callq 0x2050
movq -0x268(%rbp), %rdi
callq 0x22b0
nopw %cs:(%rax,%rax)
nopl (%rax)