// File: /workspace/github_cpp_makefile_star2_O1/waket[P]ThreadPool/main.cpp
// Function: main
int main(int argc, char* argv[])
{
   int result = 0;
   cout << "The purpose of this code is to show the usage of ThreadPoolTask library." << endl << endl;
   srand ( time(NULL) );

   // Synchronous start and stop
   {
      ThreadPoolTask tpt;
      cout << "Adding Taks... " << endl;
      for (unsigned int i = 0; i < random() % 15; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      cout << "Starting ThreadPoolTask... " << endl;
      if (tpt.start())
      {
         cout << "Starting ThreadPoolTask DONE" << endl;
      }
      else
      {
         cout << "Starting ThreadPoolTask ERROR" << endl;
      }

      cout << "Adding task... " << endl;
      for (unsigned int i = 0; i < random() % 15; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      sleep(random() % 15);

      cout << "Stopping ThreadPoolTask... " << endl;
      if (tpt.stop())
      {
         cout << "Stopping ThreadPoolTask DONE" << endl;
      }
      else
      {
         cout << "Stopping ThreadPoolTask ERROR" << endl;
      }
   }
   // Synchronous start and asynchronous stop
   {
      ThreadPoolTask tpt;
      cout << "Adding task... " << endl;
      for (unsigned int i = 0; i < random() % 15; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      cout << "Starting ThreadPoolTask... " << endl;
      if (tpt.start())
      {
         cout << "Starting ThreadPoolTask DONE" << endl;
      }
      else
      {
         cout << "Starting ThreadPoolTask ERROR" << endl;
      }

      cout << "Adding task... " << endl;
      for (unsigned int i = 0; i < random() % 5; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      cout << "Set worker count to ... " << endl;
      if (tpt.setWorkerCount(3)) {
          cout << "Set worker count DONE" << endl;
      }
      else
      {
          cout << "Set worker count ERROR" << endl;
      }

      sleep(random() % 10);

      cout << "Requesting ThreadPoolTask stop... " << endl;
      if (tpt.requestStop())
      {
         cout << "Requesting ThreadPoolTask stop DONE" << endl;
      }
      else
      {
         cout << "Requesting ThreadPoolTask stop ERROR" << endl;
      }

//      cout << "Requesting ThreadPoolTask stop... " << endl;
//      if (tpt.requestStop())
//      {
//         cout << "Requesting ThreadPoolTask stop DONE" << endl;
//      }
//      else
//      {
//         cout << "Requesting ThreadPoolTask stop ERROR" << endl;
//      }
//
//      cout << "Adding task... " << endl;
//      for (unsigned int i = 0; i < random() % 15; i++)
//          tpt.doTask(hello);
//      cout << "Adding task... DONE" << endl;

      cout << "Blocking for stop... " << endl;
      if (tpt.wait())
      {
         cout << "Blocking for stop DONE" << endl;
      }
      else
      {
         cout << "Blocking for stop ERROR" << endl;
      }
   }
   // Done
   cout << "OK" << endl;
   return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq 0x59e5(%rip), %rbx      # 0x7fd8
leaq 0x2a31(%rip), %rsi      # 0x502b
movl $0x48, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
xorl %edi, %edi
callq 0x21a0
movl %eax, %edi
callq 0x21b0
leaq 0x20(%rsp), %rdi
callq 0x2f82
leaq 0x29fd(%rip), %rsi      # 0x5074
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5936(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
callq 0x20d0
movq %rax, %rcx
movabsq $-0x7777777777777777, %rbp # imm = 0x8888888888888889
imulq %rbp
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rax,%rax,2), %rax
subq %rax, %rcx
leaq 0x54ba(%rip), %r12      # 0x7ba1
leaq -0x202(%rip), %r13      # 0x24ec
testq %rcx, %rcx
jle 0x2749
xorl %r15d, %r15d
leaq 0x20(%rsp), %rbx
movq %rsp, %r14
movq %r13, 0x8(%rsp)
movq %r12, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3dee
movq %r14, %rdi
callq 0x308a
callq 0x20d0
movq %rax, %rcx
imulq %rbp
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rax,%rax,2), %rax
subq %rax, %rcx
incq %r15
cmpq %r15, %rcx
jg 0x26fe
movq 0x5888(%rip), %rbx      # 0x7fd8
leaq 0x292d(%rip), %rsi      # 0x5084
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5856(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x5842(%rip), %rbx      # 0x7fd8
leaq 0x28fb(%rip), %rsi      # 0x5098
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5810(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x39fc
leaq 0x28ce(%rip), %rcx      # 0x50b4
leaq 0x28e4(%rip), %rsi      # 0x50d1
testb %al, %al
cmovneq %rcx, %rsi
movzbl %al, %edx
xorq $0x1d, %rdx
movq 0x57d7(%rip), %r14      # 0x7fd8
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x57b1(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x579d(%rip), %r14      # 0x7fd8
leaq 0x28ad(%rip), %rsi      # 0x50ef
movl $0xf, %edx
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x576b(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
callq 0x20d0
movq %rax, %rcx
imulq %rbp
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rax,%rax,2), %rax
subq %rax, %rcx
testq %rcx, %rcx
jle 0x28fb
xorl %ebx, %ebx
leaq 0x20(%rsp), %r14
movq %rsp, %r15
movq %r13, 0x8(%rsp)
movq %r12, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3dee
movq %r15, %rdi
callq 0x308a
callq 0x20d0
movq %rax, %rcx
imulq %rbp
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rax,%rax,2), %rax
subq %rax, %rcx
incq %rbx
cmpq %rbx, %rcx
jg 0x28b0
movq 0x56d6(%rip), %r14      # 0x7fd8
leaq 0x277b(%rip), %rsi      # 0x5084
movl $0x13, %edx
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x56a4(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
callq 0x20d0
movq %rax, %rdi
imulq %rbp
addq %rdi, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x3, %rdx
addl %eax, %edx
leal (%rdx,%rdx,4), %eax
leal (%rax,%rax,2), %eax
subl %eax, %edi
callq 0x2140
movq 0x5668(%rip), %r14      # 0x7fd8
leaq 0x2788(%rip), %rsi      # 0x50ff
movl $0x1b, %edx
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5636(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x3b58
leaq 0x275b(%rip), %rcx      # 0x511b
leaq 0x2771(%rip), %rsi      # 0x5138
testb %al, %al
cmovneq %rcx, %rsi
movzbl %al, %edx
xorq $0x1d, %rdx
movq 0x55fd(%rip), %r14      # 0x7fd8
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x55d7(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x32d4
leaq 0x20(%rsp), %rdi
callq 0x2f82
movq 0x55af(%rip), %r14      # 0x7fd8
leaq 0x26bf(%rip), %rsi      # 0x50ef
movl $0xf, %edx
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x557d(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
callq 0x20d0
movq %rax, %rcx
imulq %rbp
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rax,%rax,2), %rax
subq %rax, %rcx
testq %rcx, %rcx
jle 0x2ae9
xorl %ebx, %ebx
leaq 0x20(%rsp), %r14
movq %rsp, %r15
movq %r13, 0x8(%rsp)
movq %r12, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3dee
movq %r15, %rdi
callq 0x308a
callq 0x20d0
movq %rax, %rcx
imulq %rbp
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rax,%rax,2), %rax
subq %rax, %rcx
incq %rbx
cmpq %rbx, %rcx
jg 0x2a9e
movq 0x54e8(%rip), %r14      # 0x7fd8
leaq 0x258d(%rip), %rsi      # 0x5084
movl $0x13, %edx
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x54b6(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x54a2(%rip), %r14      # 0x7fd8
leaq 0x255b(%rip), %rsi      # 0x5098
movl $0x1b, %edx
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5470(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x39fc
testb %al, %al
leaq 0x2549(%rip), %rsi      # 0x50d1
leaq 0x2525(%rip), %rcx      # 0x50b4
cmovneq %rcx, %rsi
movzbl %al, %edx
xorq $0x1d, %rdx
movq 0x5437(%rip), %r14      # 0x7fd8
movq %r14, %rdi
callq 0x2220
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5411(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x53fd(%rip), %rbx      # 0x7fd8
leaq 0x250d(%rip), %rsi      # 0x50ef
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x53cb(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
callq 0x20d0
movq %rax, %rcx
movabsq $0x6666666666666667, %r15 # imm = 0x6666666666666667
imulq %r15
movq %rdx, %rax
shrq $0x3f, %rax
sarq %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
subq %rax, %rcx
testq %rcx, %rcx
jle 0x2c95
xorl %ebp, %ebp
leaq 0x20(%rsp), %rbx
movq %rsp, %r14
movq %r13, 0x8(%rsp)
movq %r12, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3dee
movq %r14, %rdi
callq 0x308a
callq 0x20d0
movq %rax, %rcx
imulq %r15
movq %rdx, %rax
shrq $0x3f, %rax
sarq %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
subq %rax, %rcx
incq %rbp
cmpq %rbp, %rcx
jg 0x2c52
movq 0x533c(%rip), %rbx      # 0x7fd8
leaq 0x23e1(%rip), %rsi      # 0x5084
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x530a(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x52f6(%rip), %rbx      # 0x7fd8
leaq 0x246d(%rip), %rsi      # 0x5156
movl $0x18, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x52c4(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
movl $0x3, %esi
callq 0x40a2
leaq 0x2438(%rip), %rcx      # 0x516f
leaq 0x2447(%rip), %rsi      # 0x5185
testb %al, %al
cmovneq %rcx, %rsi
movzbl %al, %eax
movl $0x16, %edx
subq %rax, %rdx
movq 0x5282(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x525c(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
callq 0x20d0
movq %rax, %rdi
imulq %r15
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x2, %rdx
addl %eax, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %eax
subl %eax, %edi
callq 0x2140
movq 0x5224(%rip), %rbx      # 0x7fd8
leaq 0x23e1(%rip), %rsi      # 0x519c
movl $0x22, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x51f2(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x3fc6
leaq 0x23bb(%rip), %rcx      # 0x51bf
leaq 0x23d8(%rip), %rsi      # 0x51e3
testb %al, %al
cmovneq %rcx, %rsi
movzbl %al, %eax
movl $0x24, %edx
subq %rax, %rdx
movq 0x51b5(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x518f(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x517b(%rip), %rbx      # 0x7fd8
leaq 0x23a4(%rip), %rsi      # 0x5208
movl $0x15, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5149(%rip), %rdi      # 0x7fd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x3f40
leaq 0x2371(%rip), %rcx      # 0x521e
leaq 0x2381(%rip), %rsi      # 0x5235
testb %al, %al
cmovneq %rcx, %rsi
movzbl %al, %edx
xorq $0x17, %rdx
movq 0x5110(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x50ea(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x32d4
leaq 0x233e(%rip), %rsi      # 0x524d
movl $0x2, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
xorl %eax, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f5d
jmp 0x2f5d
jmp 0x2f5d
movq %rax, %rbx
movq %rsp, %rdi
callq 0x308a
jmp 0x2f6f
jmp 0x2f6c
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x32d4
movq %rbx, %rdi
callq 0x2320
nop