// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x238, %rsp            # imm = 0x238
movl $0x0, 0x234(%rsp)
movl %edi, 0x230(%rsp)
movq %rsi, 0x228(%rsp)
cmpl $0x1, 0x230(%rsp)
jne 0x2b4d
movq 0x154ae(%rip), %rdi     # 0x17fd0
leaq 0xd5ab(%rip), %rsi      # 0x100d4
callq 0x21b0
movq %rax, %rdi
movq 0x15480(%rip), %rsi     # 0x17fb8
callq 0x21f0
movl $0xffffffff, 0x234(%rsp) # imm = 0xFFFFFFFF
jmp 0x2e01
callq 0x3a30
movq %rax, %rdi
callq 0x3aa0
leaq 0xa0(%rsp), %rdi
callq 0x3ab0
movq 0x228(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x2310
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0x80(%rsp), %rdi
callq 0x2250
jmp 0x2ba0
leaq 0x7f(%rsp), %rdi
callq 0x2200
leaq 0x80(%rsp), %rdi
callq 0x2080
movq %rax, %rdi
leaq 0xd538(%rip), %rsi      # 0x100f9
callq 0x2210
movq %rax, 0x28(%rsp)
jmp 0x2bcd
movq 0x28(%rsp), %rax
movq %rax, 0x60(%rsp)
cmpq $0x0, 0x60(%rsp)
jne 0x2c9a
callq 0x2270
jmp 0x2e22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0x2200
jmp 0x2df2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
movq 0x70(%rsp), %rdi
callq 0x2070
movq 0x153a7(%rip), %rdi     # 0x17fd0
leaq 0xd4cb(%rip), %rsi      # 0x100fb
callq 0x21b0
movq %rax, 0x20(%rsp)
jmp 0x2c3c
movq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x2180
movq %rax, 0x18(%rsp)
jmp 0x2c55
movq 0x18(%rsp), %rdi
leaq 0xd4b7(%rip), %rsi      # 0x10118
callq 0x21b0
movq %rax, 0x10(%rsp)
jmp 0x2c6d
movq 0x10(%rsp), %rdi
movq 0x1533f(%rip), %rsi     # 0x17fb8
callq 0x21f0
jmp 0x2c80
movl $0xffffffff, 0x234(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x5c(%rsp)
callq 0x22d0
jmp 0x2cb1
jmp 0x2cce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
callq 0x22d0
jmp 0x2cc9
jmp 0x2dc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x2de5
jmp 0x2de5
movl $0x0, 0x58(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x60(%rsp), %rdi
callq 0x22a0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2cfa
jmp 0x2d94
jmp 0x2cfc
jmp 0x2cfe
movq 0x60(%rsp), %rdx
leaq 0x48(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2230
movq %rax, 0x8(%rsp)
jmp 0x2d19
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $-0x1, 0x40(%rsp)
jne 0x2d2d
jmp 0x2d8f
movq 0x48(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x3b20
jmp 0x2d41
cmpq $0x0, 0x48(%rsp)
je 0x2d53
movq 0x48(%rsp), %rdi
callq 0x2220
movq $0x0, 0x48(%rsp)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %eax
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x2d8a
leaq 0xa0(%rsp), %rdi
callq 0x3d00
jmp 0x2d88
jmp 0x2d8a
jmp 0x2cfc
jmp 0x2cdf
movq 0x60(%rsp), %rdi
callq 0x21c0
jmp 0x2da0
callq 0x3a30
movq %rax, (%rsp)
jmp 0x2dab
movq (%rsp), %rdi
callq 0x3d10
jmp 0x2db6
movl $0x0, 0x234(%rsp)
movl $0x1, 0x5c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x2110
leaq 0xa0(%rsp), %rdi
callq 0x3ed0
jmp 0x2e01
leaq 0x80(%rsp), %rdi
callq 0x2110
leaq 0xa0(%rsp), %rdi
callq 0x3ed0
jmp 0x2e10
movl 0x234(%rsp), %eax
addq $0x238, %rsp            # imm = 0x238
retq
movq 0x70(%rsp), %rdi
callq 0x2300
movq %rax, %rdi
callq 0x3b10
nopw %cs:(%rax,%rax)