// File: ahupp[P]mural/tags.cpp
// Function: read_etags_file(std::basic_ifstream<char, std::char_traits<char>>&, std::vector<TagInfo, std::allocator<TagInfo>>&)
void read_etags_file(ifstream& tag_stream, vector<TagInfo>& tags) {

  bool expecting_filename = false;
  string current_filename;
  while (!tag_stream.eof()) {
    string line;
    getline(tag_stream, line);

    if (expecting_filename) {
      expecting_filename = false;

      size_t comma = line.find(',');
      if (comma != string::npos) {
        current_filename = line.substr(0, comma);
        tags.push_back(TagInfo(current_filename, current_filename, 0));
      }
    } else if (line[0] == 0x0C) {
      expecting_filename = true;
      continue;
    } else {

      size_t tag_start = line.find(0x7F);
      if (tag_start == string::npos) {
        continue;
      }
      size_t tag_end = line.find(0x01, tag_start);
      if (tag_end == string::npos) {
        continue;
      }
      size_t row_end = line.find(',', tag_end);
      if (row_end == string::npos) {
        continue;
      }

      string symbol = line.substr(tag_start + 1, tag_end-tag_start-1);
      string row = line.substr(tag_end+1, row_end);

      tags.push_back(TagInfo(symbol, current_filename, atoi(row.c_str())));
    }
  }
}

// Assembly:
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movb $0x0, 0x1e7(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x3350
movq 0x1f0(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3450
movb %al, 0x37(%rsp)
jmp 0x7809
movb 0x37(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7818
jmp 0x7bdb
leaq 0x190(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x3350
movq 0x28(%rsp), %rsi
movq 0x1f0(%rsp), %rdi
callq 0x3070
jmp 0x783e
testb $0x1, 0x1e7(%rsp)
je 0x7973
movb $0x0, 0x1e7(%rsp)
leaq 0x190(%rsp), %rdi
movl $0x2c, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3330
movq %rax, 0x188(%rsp)
cmpq $-0x1, 0x188(%rsp)
je 0x796e
movq 0x188(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x168(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x3260
jmp 0x78a4
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
leaq 0x168(%rsp), %rsi
movq %rsi, 0x10(%rsp)
callq 0x32f0
movq 0x10(%rsp), %rdi
callq 0x3170
movq 0x18(%rsp), %rdx
movq 0x1e8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x100(%rsp), %rdi
xorl %ecx, %ecx
movq %rdx, %rsi
callq 0x8000
jmp 0x78f3
movq 0x20(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x7fd0
jmp 0x7907
leaq 0x100(%rsp), %rdi
callq 0x4140
jmp 0x796e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x7bf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x7bcc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x4140
jmp 0x7bcc
jmp 0x7b9d
xorl %eax, %eax
movl %eax, %esi
leaq 0x190(%rsp), %rdi
callq 0x3490
movq %rax, 0x8(%rsp)
jmp 0x798b
movq 0x8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xc, %eax
jne 0x79b0
movb $0x1, 0x1e7(%rsp)
movl $0x2, 0xfc(%rsp)
jmp 0x7ba8
leaq 0x190(%rsp), %rdi
movl $0x7f, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3330
movq %rax, 0xf0(%rsp)
cmpq $-0x1, 0xf0(%rsp)
jne 0x79e9
movl $0x2, 0xfc(%rsp)
jmp 0x7ba8
movq 0xf0(%rsp), %rdx
leaq 0x190(%rsp), %rdi
movl $0x1, %esi
callq 0x3330
movq %rax, 0xe8(%rsp)
cmpq $-0x1, 0xe8(%rsp)
jne 0x7a26
movl $0x2, 0xfc(%rsp)
jmp 0x7ba8
movq 0xe8(%rsp), %rdx
leaq 0x190(%rsp), %rdi
movl $0x2c, %esi
callq 0x3330
movq %rax, 0xe0(%rsp)
cmpq $-0x1, 0xe0(%rsp)
jne 0x7a63
movl $0x2, 0xfc(%rsp)
jmp 0x7ba8
movq 0xf0(%rsp), %rcx
movq %rcx, %rdx
incq %rdx
movq 0xe8(%rsp), %rax
notq %rcx
addq %rax, %rcx
leaq 0xc0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x3260
jmp 0x7a96
movq 0xe8(%rsp), %rdx
incq %rdx
movq 0xe0(%rsp), %rcx
leaq 0xa0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x3260
jmp 0x7ac0
movq 0x1e8(%rsp), %rax
movq %rax, (%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33b0
movl %eax, %ecx
leaq 0x38(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x1c0(%rsp), %rdx
callq 0x8000
jmp 0x7aff
movq (%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x7fd0
jmp 0x7b0f
leaq 0x38(%rsp), %rdi
callq 0x4140
leaq 0xa0(%rsp), %rdi
callq 0x3170
leaq 0xc0(%rsp), %rdi
callq 0x3170
jmp 0x7b9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x7b8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x7b7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x4140
leaq 0xa0(%rsp), %rdi
callq 0x3170
leaq 0xc0(%rsp), %rdi
callq 0x3170
jmp 0x7bcc
jmp 0x7b9d
movl $0x0, 0xfc(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x3170
movl 0xfc(%rsp), %eax
testl %eax, %eax
je 0x7bc7
jmp 0x7bc2
jmp 0x77ec
jmp 0x77ec
leaq 0x190(%rsp), %rdi
callq 0x3170
jmp 0x7bf0
leaq 0x1c0(%rsp), %rdi
callq 0x3170
addq $0x1f8, %rsp            # imm = 0x1F8
retq
leaq 0x1c0(%rsp), %rdi
callq 0x3170
movq 0x1b8(%rsp), %rdi
callq 0x33f0
nopw (%rax,%rax)