// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movl $0x1, -0x30(%rbp)
cmpl $0x3, %edi
jne 0x14c6
movq %rsi, %rbx
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rdx
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, (%rdx)
movq 0x8(%rsi), %rdi
movq 0x10(%rsi), %rsi
leaq -0x40(%rbp), %rcx
callq 0x1110
testl %eax, %eax
jne 0x14e5
movq -0x40(%rbp), %rax
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x1040
movl %eax, -0x2c(%rbp)
leaq -0x30(%rbp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x1170
testl %eax, %eax
js 0x14b8
movl -0x2c(%rbp), %edi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
callq 0x10a0
testl %eax, %eax
js 0x14ea
leaq -0x106(%rip), %rsi      # 0x131c
leaq -0x38(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0x150a
xorl %r13d, %r13d
leaq -0x480(%rbp), %rbx
movq 0x2b98(%rip), %r12      # 0x3fd8
leaq 0xc44(%rip), %r14       # 0x208b
movl $0x401, %edx            # imm = 0x401
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1090
movq (%r12), %rdx
movq %rbx, %rdi
movl $0x401, %esi            # imm = 0x401
callq 0x1150
movl -0x2c(%rbp), %r15d
movq %rbx, %rdi
callq 0x1060
movl %r15d, %edi
movq %rbx, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x1080
cmpl $-0x1, %eax
je 0x1490
testb $0x1, %r13b
je 0x1447
jmp 0x149d
movq %r14, %rdi
callq 0x10b0
movb $0x1, %r13b
jmp 0x1488
cmpq $0x0, -0x38(%rbp)
jne 0x1505
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rbx), %rdi
callq 0x11a7
jmp 0x1400
leaq 0xbe5(%rip), %rdi       # 0x20b2
callq 0x1140
leaq 0xbf7(%rip), %rdi       # 0x20d0
callq 0x1140
xorl %edi, %edi
callq 0x1100
callq 0x1190
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x11ca
cmpq $0x0, -0x38(%rbp)
jne 0x1505
movq %rax, %rdi
callq 0x1160
callq 0x1050