// File: jflemer[P]boost-chat-server/chat_client.cpp
// Function: main
int main(int argc, char* argv[])
{
  try
  {
    if (argc != 3)
    {
      std::cerr << "Usage: chat_client <host> <port>\n";
      return 1;
    }

    boost::asio::io_service io_service;

    tcp::resolver resolver(io_service);
    tcp::resolver::query query(argv[1], argv[2]);
    tcp::resolver::iterator iterator = resolver.resolve(query);

    chat_client<> c(io_service, iterator);

    boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));

    char line[chat_message::max_body_length + 1];
    while (std::cin.getline(line, chat_message::max_body_length + 1))
    {
      using namespace std; // For strlen and memcpy.
      chat_message msg;
      msg.body_length(strlen(line));
      memcpy(msg.body(), line, msg.body_length());
      msg.encode_header();
      c.write(msg);
    }

    c.close();
    t.join();
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception: " << e.what() << "\n";
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8f0, %rsp            # imm = 0x8F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x8c31
movq 0x3e3e2(%rip), %rdi     # 0x46fe8
leaq 0x25470(%rip), %rsi     # 0x2e07d
callq 0x8400
jmp 0x8c14
movl $0x1, -0x4(%rbp)
jmp 0x90fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x905e
leaq -0x30(%rbp), %rdi
callq 0x9850
jmp 0x8c3c
xorl %eax, %eax
movl %eax, %edx
leaq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x9900
jmp 0x8c4f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8a8(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x8a0(%rbp)
callq 0x8760
movq -0x8a8(%rbp), %rsi
movq -0x8a0(%rbp), %rdx
leaq -0x108(%rbp), %rdi
callq 0x9950
jmp 0x8c8d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x8b8(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x8b0(%rbp)
callq 0x8760
movq -0x8b8(%rbp), %rsi
movq -0x8b0(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x9950
jmp 0x8ccb
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x130(%rbp), %rdx
movl $0x20, %ecx
callq 0x9a00
jmp 0x8cec
leaq -0x130(%rbp), %rdi
callq 0x8270
leaq -0x131(%rbp), %rdi
callq 0x8470
leaq -0x108(%rbp), %rdi
callq 0x8270
leaq -0x109(%rbp), %rdi
callq 0x8470
leaq -0x168(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x9b10
jmp 0x8d35
leaq -0x150(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x9bd0
jmp 0x8d4a
leaq -0x168(%rbp), %rdi
callq 0x9c20
leaq -0x438(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x9c40
jmp 0x8d6b
leaq -0x420(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x438(%rbp), %rdx
callq 0x9c80
jmp 0x8d84
leaq -0x438(%rbp), %rdi
callq 0x9da0
leaq 0x10b9(%rip), %rax      # 0x9e50
movq %rax, -0x470(%rbp)
movq $0x0, -0x468(%rbp)
movq -0x470(%rbp), %rsi
movq -0x468(%rbp), %rdx
leaq -0x460(%rbp), %rdi
leaq -0x30(%rbp), %rcx
callq 0x9dc0
jmp 0x8dc9
leaq -0x448(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x9ea0
jmp 0x8dde
jmp 0x8de0
movq 0x3e1e9(%rip), %rdi     # 0x46fd0
leaq -0x680(%rbp), %rsi
movl $0x201, %edx            # imm = 0x201
callq 0x8100
movq %rax, -0x8c0(%rbp)
jmp 0x8e01
movq -0x8c0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8550
movb %al, -0x8c1(%rbp)
jmp 0x8e1f
movb -0x8c1(%rbp), %al
testb $0x1, %al
jne 0x8e2e
jmp 0x8fc5
leaq -0x890(%rbp), %rdi
callq 0x9f10
jmp 0x8e3c
leaq -0x680(%rbp), %rdi
callq 0x81a0
movq %rax, %rsi
leaq -0x890(%rbp), %rdi
callq 0x9f30
jmp 0x8e59
leaq -0x890(%rbp), %rdi
callq 0x9f70
movq %rax, -0x8d0(%rbp)
jmp 0x8e6e
leaq -0x680(%rbp), %rax
movq %rax, -0x8e0(%rbp)
leaq -0x890(%rbp), %rdi
callq 0x9f90
movq %rax, -0x8d8(%rbp)
jmp 0x8e91
movq -0x8d8(%rbp), %rdx
movq -0x8e0(%rbp), %rsi
movq -0x8d0(%rbp), %rdi
callq 0x8360
leaq -0x890(%rbp), %rdi
callq 0x9fb0
jmp 0x8eb9
leaq -0x420(%rbp), %rdi
leaq -0x890(%rbp), %rsi
callq 0xa000
jmp 0x8ece
jmp 0x8de0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x9055
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x8f30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x8f18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x8270
leaq -0x131(%rbp), %rdi
callq 0x8470
leaq -0x108(%rbp), %rdi
callq 0x8270
leaq -0x109(%rbp), %rdi
callq 0x8470
jmp 0x904c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x9040
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x9c20
jmp 0x9040
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x9034
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x438(%rbp), %rdi
callq 0x9da0
jmp 0x9034
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x9028
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x448(%rbp), %rdi
callq 0xa1b0
jmp 0x9028
leaq -0x420(%rbp), %rdi
callq 0xa0c0
jmp 0x8fd3
leaq -0x448(%rbp), %rdi
callq 0xa110
jmp 0x8fe1
leaq -0x448(%rbp), %rdi
callq 0xa1b0
leaq -0x420(%rbp), %rdi
callq 0xa1f0
leaq -0x150(%rbp), %rdi
callq 0x9da0
leaq -0xe8(%rbp), %rdi
callq 0xa220
leaq -0x78(%rbp), %rdi
callq 0xa260
leaq -0x30(%rbp), %rdi
callq 0xa290
jmp 0x90dc
leaq -0x420(%rbp), %rdi
callq 0xa1f0
leaq -0x150(%rbp), %rdi
callq 0x9da0
leaq -0xe8(%rbp), %rdi
callq 0xa220
leaq -0x78(%rbp), %rdi
callq 0xa260
leaq -0x30(%rbp), %rdi
callq 0xa290
movl -0x1c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x9106
movq -0x18(%rbp), %rdi
callq 0x8170
movq %rax, -0x898(%rbp)
movq 0x3df63(%rip), %rdi     # 0x46fe8
leaq 0x25013(%rip), %rsi     # 0x2e09f
callq 0x8400
movq %rax, -0x8e8(%rbp)
jmp 0x909a
movq -0x898(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x8e8(%rbp), %rdi
movq %rax, %rsi
callq 0x8400
movq %rax, -0x8f0(%rbp)
jmp 0x90c2
movq -0x8f0(%rbp), %rdi
leaq 0x24fcd(%rip), %rsi     # 0x2e09d
callq 0x8400
jmp 0x90d7
callq 0x86e0
movl $0x0, -0x4(%rbp)
jmp 0x90fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x86e0
jmp 0x90f8
jmp 0x9106
movl -0x4(%rbp), %eax
addq $0x8f0, %rsp            # imm = 0x8F0
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x8730
movq %rax, %rdi
callq 0x9630
nopw (%rax,%rax)