// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
cmpl $0x2, %edi
jne 0x2878
movq 0x8(%rbx), %rsi
leaq 0x28(%rsp), %rbx
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2976
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x3b7d
callq 0x2330
movl %eax, %ebx
leaq 0x28bd(%rip), %rsi      # 0x5049
movl %eax, %edi
callq 0x24bc
pushq $0x2
popq %rdi
callq 0x2350
movl %eax, %ebp
leaq 0x28b2(%rip), %rsi      # 0x5056
movl %eax, %edi
callq 0x24bc
movl %ebp, %edi
xorl %esi, %esi
callq 0x2691
movl %ebp, 0xc(%rsp)
movl %ebp, %edi
movl %ebx, %esi
callq 0x2691
movq 0x28(%rsp), %rsi
pushq $0x8
popq %rdx
movl %ebx, %edi
callq 0x2120
leaq 0x288c(%rip), %rsi      # 0x5063
movl %eax, %edi
callq 0x24bc
movl $0x300, %edi            # imm = 0x300
callq 0x2030
movq %rax, %r14
leaq 0x10(%rsp), %r13
leaq 0x28(%rsp), %r15
movl 0xc(%rsp), %edi
movq %r14, %rsi
pushq $0x40
popq %rdx
pushq $-0x1
popq %rcx
callq 0x20f0
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
imulq $0xc, %rax, %rbp
xorl %r12d, %r12d
cmpq %r12, %rbp
je 0x284b
movl 0x4(%r14,%r12), %eax
testl %eax, %eax
je 0x283d
cmpl %ebx, %eax
jne 0x28bf
movl %ebx, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x26c0
jmp 0x2845
movq %r13, %rdi
callq 0x24d5
addq $0xc, %r12
jmp 0x2818
movq 0x5786(%rip), %rcx      # 0x7fd8
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rcx,%rax)
je 0x27f5
leaq 0x10(%rsp), %rdi
callq 0x2954
leaq 0x28(%rsp), %rdi
callq 0x20e0
xorl %eax, %eax
jmp 0x28b0
movq 0x5771(%rip), %rdi      # 0x7ff0
leaq 0x27b2(%rip), %rsi      # 0x5038
callq 0x21d0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x21d0
leaq 0x27a3(%rip), %rsi      # 0x5040
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
pushq $0x1
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27af(%rip), %rdi      # 0x5075
leaq 0x27ae(%rip), %rsi      # 0x507b
leaq 0x27b8(%rip), %rcx      # 0x508c
movl $0x90, %edx
callq 0x2130
jmp 0x28e4
jmp 0x28e4
jmp 0x28e4
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2954
leaq 0x28(%rsp), %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2310
nop