// File: /workspace/github_cpp_makefile_star2_O2/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 0x1453
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 0x146d
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)
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
leaq -0x20(%rbp), %rcx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x1170
testl %eax, %eax
jns 0x13b1
movq 0x10(%rbx), %rsi
leaq 0xc7b(%rip), %rdi       # 0x2019
xorl %eax, %eax
callq 0x1030
leaq 0xc95(%rip), %rdi       # 0x2041
callq 0x10b0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
movl %r14d, %edi
callq 0x10a0
testl %eax, %eax
js 0x1476
leaq -0x117(%rip), %rsi      # 0x12bc
leaq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rdx
callq 0x14b0
leaq -0x470(%rbp), %rbx
movq 0x2bea(%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 0x13ee
leaq 0xc56(%rip), %rdi       # 0x208b
callq 0x10b0
leaq -0x28(%rbp), %rdi
callq 0x1528
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc58(%rip), %rdi       # 0x20b2
callq 0x1140
leaq 0xc6a(%rip), %rdi       # 0x20d0
callq 0x1140
jmp 0x1494
leaq 0xb90(%rip), %rdi       # 0x2004
jmp 0x148f
movq 0x8(%rbx), %rsi
leaq 0xbd4(%rip), %rdi       # 0x2055
xorl %eax, %eax
callq 0x1030
leaq 0xbeb(%rip), %rdi       # 0x207a
callq 0x10b0
xorl %edi, %edi
callq 0x1100
movq %rax, %rbx
leaq -0x28(%rbp), %rdi
callq 0x1528
movq %rbx, %rdi
callq 0x1160
nop