// File: /workspace/github_cpp_makefile_star2_O1/ahupp[P]mural/mural_server.cpp
// Function: main
int main(int argc, char** argv) {

  if (argc != 2) {
    cerr << "usage: " << argv[0] << " tagfile" << endl;
    return 1;
  }

  string tags_file(argv[1]);

  vector<TagInfo> tags;
  read_tags_file(tags_file, tags);

#ifndef __APPLE__
  int inotify_fd = enforce(inotify_init(), "inotify_init");
  int efd = enforce(epoll_create(2), "epoll_create");

  mural_epoll_add(efd, 0);
  mural_epoll_add(efd, inotify_fd);

  enforce(
    inotify_add_watch(inotify_fd, tags_file.c_str(), IN_CLOSE_WRITE),
    "inotify_add_watch");

  const int MAXEVENTS = 64;
  struct epoll_event* events = new struct epoll_event[MAXEVENTS];

  while (1) {
    int n = epoll_wait(efd, events, MAXEVENTS, -1);
    for (int i = 0; i < n; ++i) {
      int active_fd = events[i].data.fd;
      if (active_fd == 0) {
        handle_one_query(tags);
      } else if (active_fd == inotify_fd) {
        read_inotify_events(inotify_fd, tags_file, tags);
      } else {
        assert(false);
      }
    }
    if (cin.eof()) {
      break;
    }
  }
#else

  while (!cin.eof()) {
    handle_one_query(tags);
  }

#endif
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
cmpl $0x2, %edi
jne 0x2aaa
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %rbx
leaq 0x30(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2be4
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x43a6
callq 0x2350
cmpl $-0x1, %eax
je 0x2b6e
movl %eax, %ebx
movl $0x2, %edi
callq 0x2380
cmpl $-0x1, %eax
je 0x2b73
movl %eax, %ebp
movl %eax, %edi
xorl %esi, %esi
callq 0x28bc
movl %ebp, %edi
movl %ebx, %esi
callq 0x28bc
movq 0x10(%rsp), %rsi
movl %ebx, %edi
movl $0x8, %edx
callq 0x2100
cmpl $-0x1, %eax
je 0x2b78
movl $0x300, %edi            # imm = 0x300
callq 0x2030
movq %rax, %r14
leaq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r12
movl %ebp, 0xc(%rsp)
movl %ebp, %edi
movq %r14, %rsi
movl $0x40, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x20d0
testl %eax, %eax
jle 0x2a65
movl %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rbp
xorl %r13d, %r13d
movl 0x4(%r14,%r13), %eax
testl %eax, %eax
je 0x2a54
cmpl %ebx, %eax
jne 0x2b4f
movl %ebx, %edi
movq %r12, %rsi
movq %r15, %rdx
callq 0x28e9
jmp 0x2a5c
movq %r15, %rdi
callq 0x25bd
addq $0xc, %r13
cmpq %r13, %rbp
jne 0x2a34
movq 0x556c(%rip), %rcx      # 0x7fd8
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rcx,%rax)
movl 0xc(%rsp), %ebp
je 0x2a0f
leaq 0x30(%rsp), %rdi
callq 0x2bb4
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2aa3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
xorl %eax, %eax
jmp 0x2b40
movq 0x553f(%rip), %rbx      # 0x7ff0
leaq 0x2580(%rip), %rsi      # 0x5038
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2230
movq (%r14), %r14
testq %r14, %r14
je 0x2ae9
movq %r14, %rdi
callq 0x20c0
movq 0x5514(%rip), %rdi      # 0x7ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x2230
jmp 0x2b00
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2300
leaq 0x2539(%rip), %rsi      # 0x5040
movl $0x8, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movl $0x1, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x251f(%rip), %rdi      # 0x5075
leaq 0x251e(%rip), %rsi      # 0x507b
leaq 0x2528(%rip), %rcx      # 0x508c
movl $0x90, %edx
callq 0x2110
callq 0x2402
callq 0x23ed
callq 0x23d8
jmp 0x2b83
jmp 0x2b83
jmp 0x2b83
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2bb4
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2bab
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330
nop