// File: /workspace/github_cpp_makefile_star2_O1/kn-sumanth[P]tcpproxy_server/tcpproxy_server.cpp
// Function: main
int main(int argc, char* argv[])
{
   signal(SIGINT,sig_handler);
   signal(SIGTERM,sig_handler);
   signal(SIGABRT,sig_handler);

   if (argc < 5)
   {
      std::cerr << "usage: tcpproxy_server <local host ip> <local port> <forward host ip> <forward port> <delay_ms>" << std::endl;
      return 1;
   }

   unsigned short delay = 0;
   const unsigned short local_port   = static_cast<unsigned short>(::atoi(argv[2]));
   const unsigned short forward_port = static_cast<unsigned short>(::atoi(argv[4]));
   if (argc > 5)
   {
     delay = static_cast<unsigned short>(::atoi(argv[5]));
   }
   const std::string local_host      = argv[1];
   const std::string forward_host    = argv[3];

   boost::asio::io_service ios;

   try
   {
      tcp_proxy::bridge::acceptor acceptor(ios, delay,
                                           local_host, local_port,
                                           forward_host, forward_port);

      acceptor.accept_connections();

      ios.run();
   }
   catch(std::exception& e)
   {
      std::cerr << "Error: " << e.what() << std::endl;
      return 1;
   }

   return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %r14
movl %edi, %r15d
leaq -0x25(%rip), %rbx       # 0x82fc
movl $0x2, %edi
movq %rbx, %rsi
callq 0x7380
movl $0xf, %edi
movq %rbx, %rsi
callq 0x7380
movl $0x6, %edi
movq %rbx, %rsi
callq 0x7380
cmpl $0x4, %r15d
jg 0x839a
movq 0x1bc9b(%rip), %rbx     # 0x23ff0
leaq 0xece4(%rip), %rsi      # 0x17040
movl $0x5f, %edx
movq %rbx, %rdi
callq 0x7360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7230
movl $0x1, %ebx
jmp 0x851b
movq 0x10(%r14), %rdi
callq 0x74d0
movl %eax, %ebx
movq 0x20(%r14), %rdi
callq 0x74d0
movl %eax, %ebp
cmpl $0x5, %r15d
jne 0x83bb
xorl %r15d, %r15d
jmp 0x83c7
movq 0x28(%r14), %rdi
callq 0x74d0
movl %eax, %r15d
movq 0x8(%r14), %rsi
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x7160
movq 0x18(%r14), %rsi
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x7160
leaq 0x10(%rsp), %rdi
callq 0x8866
movzwl %bp, %eax
movl %eax, (%rsp)
movzwl %r15w, %edx
movzwl %bx, %r8d
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rcx
leaq 0x30(%rsp), %r9
callq 0x8972
leaq 0x70(%rsp), %rdi
callq 0x8a50
leaq 0x20(%rsp), %rdi
callq 0xa8c0
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xa8ec
cmpb $0x1, 0x24(%rsp)
je 0x852b
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8462
callq 0x7300
movq 0xd8(%rsp), %rbx
testq %rbx, %rbx
je 0x848d
lock
decl 0x8(%rbx)
jne 0x848d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
lock
decl 0xc(%rbx)
jne 0x848d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq 0x80(%rsp), %rdi
callq 0xc0ca
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movq 0x38(%rax), %r14
testq %r14, %r14
je 0x84b9
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq 0x20(%r14), %r14
jmp 0x84a5
movq 0x10(%rsp), %r14
movq 0x38(%r14), %r15
testq %r15, %r15
je 0x84da
movq %r15, %rdi
movq (%r15), %rax
movq 0x20(%r15), %r15
callq *0x8(%rax)
movq %r15, 0x38(%r14)
jmp 0x84c2
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x84f5
leaq 0x8(%r14), %rdi
callq 0x7370
movq %r14, %rdi
callq 0x7300
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8508
callq 0x7300
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x851b
callq 0x7300
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x108(%rsp), %rdi
callq 0xb98e
leaq 0x108(%rsp), %rdi
callq 0x924b
movq %rdx, %r14
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xc0ca
jmp 0x85ab
jmp 0x861c
movq %rdx, %r14
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x8dd2
jmp 0x85a1
jmp 0x8626
movq %rax, %rbx
jmp 0x863c
movq %rax, %rbx
jmp 0x864f
movq %rdx, %r14
movq %rax, %rbx
jmp 0x85ab
movq %rdx, %r14
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x8bc0
cmpl $0x1, %r14d
jne 0x8610
movq %rbx, %rdi
callq 0x7170
movq %rax, %rbx
movq 0x1ba2d(%rip), %rdi     # 0x23ff0
leaq 0xead6(%rip), %rsi      # 0x170a0
movl $0x7, %edx
callq 0x7360
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x1ba0c(%rip), %rdi     # 0x23ff0
movq %rax, %rsi
callq 0x7320
movq %rax, %rdi
callq 0x71a0
movl $0x1, %ebx
callq 0x74f0
jmp 0x849c
movq %rax, %rbx
jmp 0x8610
movq %rax, %rbx
callq 0x74f0
leaq 0x10(%rsp), %rdi
callq 0x8c18
jmp 0x8629
movq %rax, %rdi
callq 0x883c
jmp 0x8626
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x863c
callq 0x7300
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x864f
callq 0x7300
movq %rbx, %rdi
callq 0x7520
nop