// File: /workspace/github_c_makefile_star2_O3/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 0x2861
movq 0x87b4(%rip), %rbx      # 0xafd0
leaq 0x483d(%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
jmp 0x29a6
movq %rsi, %rbx
leaq 0x8955(%rip), %r13      # 0xb1c0
cmpq $0x0, (%r13)
jne 0x2892
movl $0x28, %edi
callq 0x21f0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq $0x0, 0x20(%rax)
movq %rax, (%r13)
leaq 0x30(%rsp), %rdi
callq 0x2bee
movq 0x8(%rbx), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2080
movq 0x10(%rsp), %rdi
leaq 0x47ca(%rip), %rsi      # 0x7085
callq 0x2230
testq %rax, %rax
je 0x29ba
movq %rax, %rbx
movq $0x0, (%rsp)
movq %rax, %rdi
callq 0x22b0
testl %eax, %eax
jne 0x294e
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
cmpq $-0x1, %rax
jne 0x2911
movq %rbx, %rdi
callq 0x22b0
testl %eax, %eax
je 0x28ef
jmp 0x294e
movq (%rsp), %rsi
movq %r12, %rdi
callq 0x2a74
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x292b
callq 0x2240
movq $0x0, (%rsp)
incl %ebp
imull $0xcccccccd, %ebp, %eax # imm = 0xCCCCCCCD
rorl %eax
cmpl $0x1999999a, %eax       # imm = 0x1999999A
jae 0x28ef
movq %r12, %rdi
callq 0x5d50
jmp 0x28ef
movq %rbx, %rdi
callq 0x21e0
movq (%r13), %rdi
testq %rdi, %rdi
jne 0x2982
movl $0x28, %edi
callq 0x21f0
movq %rax, %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x20(%rax)
movq %rax, (%r13)
callq 0x2350
xorl %ebx, %ebx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x299c
callq 0x21c0
leaq 0x30(%rsp), %rdi
callq 0x2c88
movl %ebx, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2280
movq %rax, %rdi
callq 0x2090
movq 0x8602(%rip), %rdi      # 0xafd0
leaq 0x46b2(%rip), %rsi      # 0x7087
movl $0x1c, %edx
callq 0x2220
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x85e0(%rip), %rdi      # 0xafd0
callq 0x2220
movq %rax, %rbx
leaq 0x46a5(%rip), %rsi      # 0x70a4
movl $0x27, %edx
movq %rax, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x20c0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x22e0
jmp 0x2989
jmp 0x2a40
movq %rax, %rbx
callq 0x22e0
jmp 0x2a43
movq %rax, %rdi
callq 0x2a68
movq %rax, %rbx
jmp 0x2a56
jmp 0x2a40
jmp 0x2a40
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a56
callq 0x21c0
leaq 0x30(%rsp), %rdi
callq 0x2c88
movq %rbx, %rdi
callq 0x2310