// File: /workspace/github_c_makefile_star2_O2/evanwire[P]GitClone/client.c
// Function: connect_to_WTFserver
char* connect_to_WTFserver(char* message_to_server){
  //Checking for .configure file, throwing an error if it does not exist
  int config_fd = open(".configure", O_RDONLY);
  if(config_fd < 0){
    printf("\nError: Could not open the .configure file. Please run the configure command before trying again.\n");
    exit(1);
  }

  //Read address and port number from file
  int i;
  int j = 0;
  char config_buffer[1024];
  char address[1020];
  char port[5];
  int bytes_read = read(config_fd, config_buffer, 1024);

  for(i = 0; i < bytes_read; i++){
    if(config_buffer[i] == ' '){
      break;
    }
    address[i] = config_buffer[i];
  }

  address[i] = '\0';

  for(i += 1; i < bytes_read; i++){
    port[j] = config_buffer[i];
    j++;
  }

  port[4] = '\0';

  //Creating the structs/variables neccesary to connect to server
  int sockfd = 0,n = 0;
  struct sockaddr_in serv_addr;

  //Create the socket
  if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0){
    printf("\n Error: Could not create socket \n");
    exit(1);
  }

  //Set connection configurations
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(atoi(port));
  serv_addr.sin_addr.s_addr = inet_addr(address);

  //Attempting to connect to server, retrying every three seconds
  while(1){
    if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0){
      printf("\n Error: Could not find server. Will attempt to recconect in 3 seconds.\n");
      sleep(3);
    }else{
      printf("\nSTATUS: Successfully connected to server.\n");
      break;
    }
  }

  //Prepare buffer for communicating with server
  char* recvBuff = (char*)malloc(1024);
  memset(recvBuff, 0, sizeof(recvBuff));

  //Write to server
  n = write(sockfd, message_to_server, strlen(message_to_server));

  //Read from server, return its response
  while((n = read(sockfd, recvBuff, 1023)) > 0){
    recvBuff[n] = 0;
  }

  return recvBuff;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x828, %rsp            # imm = 0x828
movq %rdi, %r14
leaq 0x1349(%rip), %rdi      # 0x5381
xorl %ebx, %ebx
xorl %esi, %esi
xorl %eax, %eax
callq 0x10f0
testl %eax, %eax
js 0x4197
leaq -0x850(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
movl %eax, %edi
callq 0x11b0
testl %eax, %eax
movl %eax, %ecx
cmovlel %ebx, %ecx
cmpq %rbx, %rcx
je 0x4085
movb -0x850(%rbp,%rbx), %dl
cmpb $0x20, %dl
je 0x4082
movb %dl, -0x450(%rbp,%rbx)
incq %rbx
jmp 0x4065
movq %rbx, %rcx
movb $0x0, -0x450(%rbp,%rcx)
cltq
incq %rcx
leaq -0x2d(%rbp), %rdx
cmpq %rax, %rcx
jge 0x40ae
movb -0x850(%rbp,%rcx), %sil
movb %sil, (%rdx)
incq %rcx
incq %rdx
jmp 0x4096
movq %r14, -0x38(%rbp)
movb $0x0, -0x29(%rbp)
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x1070
testl %eax, %eax
js 0x41a0
movl %eax, %r14d
leaq -0x48(%rbp), %r15
movw $0x2, (%r15)
leaq -0x2d(%rbp), %rdi
callq 0x11f0
rolw $0x8, %ax
movw %ax, 0x2(%r15)
leaq -0x450(%rbp), %rdi
callq 0x1150
movl %eax, 0x4(%r15)
pushq $0x10
popq %r12
leaq 0x2031(%rip), %r13      # 0x6136
pushq $0x3
popq %rbx
movl %r14d, %edi
movq %r15, %rsi
movl %r12d, %edx
callq 0x1110
testl %eax, %eax
jns 0x412b
movq %r13, %rdi
callq 0x11d0
movl %ebx, %edi
callq 0x1100
jmp 0x4108
leaq 0x1fd9(%rip), %rdi      # 0x610b
callq 0x11d0
movl $0x400, %edi            # imm = 0x400
callq 0x1180
movq %rax, %r15
andq $0x0, (%rax)
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x10a0
movl %r14d, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1080
movl $0x3ff, %edx            # imm = 0x3FF
movl %r14d, %edi
movq %r15, %rsi
callq 0x11b0
testl %eax, %eax
jle 0x4182
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, (%r15,%rax)
jmp 0x4162
movq %r15, %rax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2002(%rip), %rdi      # 0x61a0
jmp 0x41a7
leaq 0x1fd7(%rip), %rdi      # 0x617e
callq 0x11d0
pushq $0x1
popq %rdi
callq 0x1170