// File: /workspace/github_cpp_makefile_star2_O3/hinrikHelga[P]Botnet/client.cpp
// Function: main
int main(int argc, char* argv[])
{
   struct addrinfo hints, *svr;              // Network host entry for server
   struct sockaddr_in server_addr;           // Socket address for server
   int serverSocket;                         // Socket used for server
   int nwrite;                               // No. bytes written to server
   char buffer[1025];                        // buffer for writing to server
   bool finished;
   int set = 1;                              // Toggle for setsockopt

   if(argc != 3)
   {
        printf("Usage: chat_client <ip  port>\n");
        printf("Ctrl-C to terminate\n");
        exit(0);
   }

   hints.ai_family   = AF_INET;            // IPv4 only addresses
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags    = AI_PASSIVE;

   memset(&hints,   0, sizeof(hints));

   if(getaddrinfo(argv[1], argv[2], &hints, &svr) != 0)
   {
       perror("getaddrinfo failed: ");
       exit(0);
   }

   serverSocket = socket(svr->ai_family, svr->ai_socktype, svr->ai_protocol);

   // Turn on SO_REUSEADDR to allow socket to be quickly reused after
   // program exit.

   if(setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &set, sizeof(set)) < 0)
   {
       printf("Failed to set SO_REUSEADDR for port %s\n", argv[2]);
       perror("setsockopt failed: ");
   }

   if(connect(serverSocket, svr->ai_addr, svr->ai_addrlen )< 0)
   {
       printf("Failed to open socket to server: %s\n", argv[1]);
       perror("Connect failed: ");
       exit(0);
   }

    // Listen and print replies from server
   std::thread serverThread(listenServer, serverSocket);

   finished = false;
   while(!finished)
   {
       bzero(buffer, sizeof(buffer));

       fgets(buffer, sizeof(buffer), stdin);

       nwrite = send(serverSocket, buffer, strlen(buffer),0);

       if(nwrite  == -1)
       {
           perror("send() to server failed: ");
           finished = true;
       }

   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movl $0x1, -0x20(%rbp)
cmpl $0x3, %edi
jne 0x14a4
movq %rsi, %rbx
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %rdx
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq 0x8(%rsi), %rdi
movq 0x10(%rsi), %rsi
leaq -0x30(%rbp), %rcx
callq 0x1110
testl %eax, %eax
jne 0x14c3
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x1040
movl %eax, %r14d
movl %eax, -0x1c(%rbp)
leaq -0x20(%rbp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x1170
testl %eax, %eax
jns 0x1404
leaq 0x10(%rbx), %rdi
callq 0x11a7
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
movl %r14d, %edi
callq 0x10a0
testl %eax, %eax
js 0x14c8
leaq -0x10a(%rip), %rsi      # 0x131c
leaq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rdx
callq 0x14e8
leaq -0x470(%rbp), %rbx
movq 0x2b97(%rip), %r15      # 0x3fd8
movl $0x401, %edx            # imm = 0x401
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1090
movq (%r15), %rdx
movq %rbx, %rdi
movl $0x401, %esi            # imm = 0x401
callq 0x1150
movl -0x1c(%rbp), %r14d
movq %rbx, %rdi
callq 0x1060
movl %r14d, %edi
movq %rbx, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x1080
cmpl $-0x1, %eax
jne 0x1441
leaq 0xc03(%rip), %rdi       # 0x208b
callq 0x10b0
cmpq $0x0, -0x28(%rbp)
jne 0x14e3
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc07(%rip), %rdi       # 0x20b2
callq 0x1140
leaq 0xc19(%rip), %rdi       # 0x20d0
callq 0x1140
xorl %edi, %edi
callq 0x1100
callq 0x1190
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x11ca
cmpq $0x0, -0x28(%rbp)
jne 0x14e3
movq %rax, %rdi
callq 0x1160
callq 0x1050