// File: /workspace/github_c_makefile_star2_O1/aspone[P]OrderBook/main.cpp
// Function: main
int main(int argc, char **argv) {
   if (argc == 1) {
      std::cout << "Usage: OrderBookProcessor <filename>" << std::endl;
      return -1;
   }

   FHErrorTracker::instance()->init();

/* Performance is actually better without SCHED_RR... hm.  Not the 1st time
   I've seen this.
   struct sched_param sp;
   sp.sched_priority = sched_get_priority_max(SCHED_RR);
   if (sched_setscheduler(0, SCHED_RR, &sp) == -1) {
      std::cout << "Error setting scheduler to SCHED_RR.  Please run with " <<
         "permissions for realtime scheduling.  Aborting." << std::endl;
      return -1;
   }
*/

   FeedHandler<uint32_t, OrderLevelEntry> feed;
   const std::string filename(argv[1]);

   FILE *pFile;
   try {
      pFile = fopen(filename.c_str(), "r");
      if (pFile == NULL) {
         throw;
      }
   }
   catch (...) {
      std::cout << "Error occured opening file: " <<
         filename <<
         ".  Please check the file and try again." << std::endl;
      return -1;
   }

   uint32_t counter = 0;
   size_t len;
   char *buffer = NULL;
   while (!feof (pFile)) {
      while (1) {
         ssize_t read = getline(&buffer, &len, pFile);
         if (read == -1) break;

         feed.processMessage(buffer);

         if (buffer) free(buffer);
         buffer = 0;

         ++counter;
         if (counter % 10 == 0) {
            feed.printCurrentOrderBook();
         }
      }
   }
   fclose(pFile);
   
   FHErrorTracker::instance()->printStatistics();
   return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
cmpl $0x1, %edi
jne 0x28b7
movq 0x876d(%rip), %rbx      # 0xafd0
leaq 0x47f6(%rip), %rsi      # 0x7060
movl $0x24, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rbx
leaq 0x88ff(%rip), %rax      # 0xb1c0
cmpq $0x0, (%rax)
jne 0x28ed
movl $0x28, %edi
callq 0x21f0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq $0x0, 0x20(%rax)
leaq 0x88d6(%rip), %rcx      # 0xb1c0
movq %rax, (%rcx)
leaq 0x30(%rsp), %rdi
callq 0x2c8a
movq 0x8(%rbx), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2080
movq 0x10(%rsp), %rdi
leaq 0x476f(%rip), %rsi      # 0x7085
callq 0x2230
testq %rax, %rax
je 0x2a0e
movq %rax, %rbx
movq $0x0, (%rsp)
movq %rax, %rdi
callq 0x22b0
testl %eax, %eax
jne 0x29ae
xorl %ebp, %ebp
movq %rsp, %r14
leaq 0x8(%rsp), %r15
leaq 0x30(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2250
movq %rax, %r13
cmpq $-0x1, %rax
je 0x299c
movq (%rsp), %rsi
movq %r12, %rdi
callq 0x2ac6
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x297b
callq 0x2240
movq $0x0, (%rsp)
incl %ebp
imull $0xcccccccd, %ebp, %eax # imm = 0xCCCCCCCD
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
ja 0x299c
movq %r12, %rdi
callq 0x5f8e
cmpq $-0x1, %r13
jne 0x294a
movq %rbx, %rdi
callq 0x22b0
testl %eax, %eax
je 0x294a
movq %rbx, %rdi
callq 0x21e0
leaq 0x8803(%rip), %rbx      # 0xb1c0
cmpq $0x0, (%rbx)
jne 0x29e2
movl $0x28, %edi
callq 0x21f0
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x20(%rax)
movq %rax, (%rbx)
movq (%rbx), %rdi
callq 0x2350
xorl %ebx, %ebx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29ff
callq 0x21c0
leaq 0x30(%rsp), %rdi
callq 0x2d24
jmp 0x28a3
callq 0x2280
jmp 0x2a92
movq %rax, %rdi
callq 0x2090
movq 0x85ac(%rip), %rdi      # 0xafd0
leaq 0x465c(%rip), %rsi      # 0x7087
movl $0x1c, %edx
callq 0x2220
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x858a(%rip), %rdi      # 0xafd0
callq 0x2220
movq %rax, %rbx
leaq 0x464f(%rip), %rsi      # 0x70a4
movl $0x27, %edx
movq %rax, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x20c0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x22e0
jmp 0x29ec
jmp 0x2a92
movq %rax, %rbx
callq 0x22e0
jmp 0x2a95
movq %rax, %rdi
callq 0x2aba
movq %rax, %rbx
jmp 0x2aa8
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2aa8
callq 0x21c0
leaq 0x30(%rsp), %rdi
callq 0x2d24
movq %rbx, %rdi
callq 0x2310