// File: /workspace/github_c_makefile_star2_O2/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 0x26af
movq 0x793d(%rip), %rdi      # 0x9fd0
leaq 0x39da(%rip), %rsi      # 0x6074
callq 0x21b0
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rbx
jmp 0x27a5
movq %rsi, %rbx
callq 0x2842
leaq 0x30(%rsp), %rdi
callq 0x2a96
movq 0x8(%rbx), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2070
movq 0x10(%rsp), %rdi
leaq 0x39b9(%rip), %rsi      # 0x6099
callq 0x2200
testq %rax, %rax
je 0x27b9
movq %rax, %rbx
movq %rsp, %rax
andq $0x0, (%rax)
xorl %r14d, %r14d
leaq 0x8(%rsp), %r15
leaq 0x30(%rsp), %r12
movq %rbx, %rdi
callq 0x2290
testl %eax, %eax
jne 0x277a
movl %r14d, %eax
negl %eax
incl %r14d
movl %r14d, %ebp
movl %eax, %r14d
movl %ebp, %eax
xorl %edx, %edx
pushq $0xa
popq %rcx
divl %ecx
movl %eax, %r13d
movq %rsp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2220
cmpq $-0x1, %rax
je 0x2775
movq (%rsp), %rsi
movq %r12, %rdi
callq 0x287a
imull $0xa, %r13d, %r13d
movq (%rsp), %rdi
callq 0x2210
andq $0x0, (%rsp)
addl %r14d, %r13d
cmpl $0x1, %r13d
jne 0x276e
movq %r12, %rdi
callq 0x5656
decl %r14d
incl %ebp
jmp 0x271f
negl %r14d
jmp 0x2705
movq %rbx, %rdi
callq 0x21c0
callq 0x2842
movq %rax, %rdi
callq 0x2980
xorl %ebx, %ebx
leaq 0x10(%rsp), %rdi
callq 0x20a0
leaq 0x30(%rsp), %rdi
callq 0x2b34
movl %ebx, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2260
jmp 0x2822
movq %rax, %rdi
callq 0x2080
movq 0x7801(%rip), %rdi      # 0x9fd0
leaq 0x38c5(%rip), %rsi      # 0x609b
callq 0x21b0
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x2180
leaq 0x38c9(%rip), %rsi      # 0x60b8
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20c0
callq 0x22c0
pushq $-0x1
popq %rbx
jmp 0x2791
jmp 0x2822
movq %rax, %rbx
callq 0x22c0
jmp 0x2825
movq %rax, %rdi
callq 0x286e
movq %rax, %rbx
jmp 0x282f
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x20a0
leaq 0x30(%rsp), %rdi
callq 0x2b34
movq %rbx, %rdi
callq 0x22f0
nop