// File: 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:
subq $0x168, %rsp            # imm = 0x168
movl $0x0, 0x164(%rsp)
movl %edi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
movl $0x2, %edi
leaq -0x3d(%rip), %rsi       # 0x7c70
callq 0x73a0
movl $0xf, %edi
leaq -0x4e(%rip), %rsi       # 0x7c70
callq 0x73a0
movl $0x6, %edi
leaq -0x5f(%rip), %rsi       # 0x7c70
callq 0x73a0
cmpl $0x5, 0x160(%rsp)
jge 0x7d10
movq 0x35303(%rip), %rdi     # 0x3cfe8
leaq 0x21318(%rip), %rsi     # 0x29004
callq 0x7330
movq %rax, %rdi
movq 0x352ad(%rip), %rsi     # 0x3cfa8
callq 0x7350
movl $0x1, 0x164(%rsp)
jmp 0x8068
movw $0x0, 0x156(%rsp)
movq 0x158(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x7530
movw %ax, 0x154(%rsp)
movq 0x158(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x7530
movw %ax, 0x152(%rsp)
cmpl $0x5, 0x160(%rsp)
jle 0x7d6f
movq 0x158(%rsp), %rax
movq 0x28(%rax), %rdi
callq 0x7530
movw %ax, 0x156(%rsp)
movq 0x158(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
leaq 0x12f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x75c0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x130(%rsp), %rdi
callq 0x7460
jmp 0x7dab
leaq 0x12f(%rsp), %rdi
callq 0x7360
movq 0x158(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x75c0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0xf8(%rsp), %rdi
callq 0x7460
jmp 0x7df4
leaq 0xf7(%rsp), %rdi
callq 0x7360
leaq 0xe0(%rsp), %rdi
callq 0x8630
jmp 0x7e10
movzwl 0x156(%rsp), %edx
movzwl 0x154(%rsp), %r8d
movzwl 0x152(%rsp), %ecx
movq %rsp, %rax
movl %ecx, (%rax)
leaq 0x48(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x130(%rsp), %rcx
leaq 0xf8(%rsp), %r9
callq 0x86f0
jmp 0x7e52
leaq 0x48(%rsp), %rdi
callq 0x8860
jmp 0x7e5e
leaq 0xe0(%rsp), %rdi
callq 0x8a70
jmp 0x7e6d
leaq 0x48(%rsp), %rdi
callq 0x8ac0
jmp 0x7e79
jmp 0x7fdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x12f(%rsp), %rdi
callq 0x7360
jmp 0x8077
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xf7(%rsp), %rdi
callq 0x7360
jmp 0x8057
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x8046
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x7f1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x8ac0
jmp 0x7f19
jmp 0x7f1b
movl 0x11c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x8010
movq 0x120(%rsp), %rdi
callq 0x7150
movq %rax, 0x40(%rsp)
movq 0x350a0(%rip), %rdi     # 0x3cfe8
leaq 0x21115(%rip), %rsi     # 0x29064
callq 0x7330
movq %rax, 0x10(%rsp)
jmp 0x7f5b
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x7330
movq %rax, 0x8(%rsp)
jmp 0x7f7d
movq 0x8(%rsp), %rdi
movq 0x3501f(%rip), %rsi     # 0x3cfa8
callq 0x7350
jmp 0x7f90
movl $0x1, 0x164(%rsp)
movl $0x1, 0x3c(%rsp)
callq 0x7550
jmp 0x7fc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
callq 0x7550
jmp 0x7fdd
jmp 0x7ff2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x8010
jmp 0x8010
movl $0x0, 0x164(%rsp)
movl $0x1, 0x3c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x8b60
jmp 0x8001
leaq 0xf8(%rsp), %rdi
callq 0x7200
jmp 0x8021
leaq 0xe0(%rsp), %rdi
callq 0x8b60
jmp 0x801f
jmp 0x8046
leaq 0x130(%rsp), %rdi
callq 0x7200
jmp 0x8068
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x8057
leaq 0xf8(%rsp), %rdi
callq 0x7200
jmp 0x8055
jmp 0x8057
leaq 0x130(%rsp), %rdi
callq 0x7200
jmp 0x8066
jmp 0x8077
movl 0x164(%rsp), %eax
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x120(%rsp), %rdi
callq 0x7590
movq %rax, %rdi
callq 0x84c0
nopl (%rax)