#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int cclient(void) {
  int sockfd, numbytes;
  char host_name[40];
  char *marker_send = "go";
  char marker_recv[100];
  struct hostent *he;
  struct sockaddr_in their_addr;
  int len = strlen(marker_send);
  FILE *sockInfo;
  if ((sockInfo = fopen("sockets.optional", "r")) == NULL) {
    perror("can't find sockets.optional");
    exit(1);
  }
  fscanf(sockInfo, "%s", host_name);
  fclose(sockInfo);
  printf("server is at: %s\n", host_name);
  if ((he = gethostbyname(host_name)) == NULL) {
    perror("gethostbyname");
    exit(1);
  }
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(9000);
  their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  memset(&(their_addr.sin_zero), '\0', 8);
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  if (connect(sockfd, (struct sockaddr *)&their_addr,
              sizeof(struct sockaddr)) == -1) {
    perror("connect");
    exit(1);
  }
  printf("connected to server\n");
  if ((numbytes = send(sockfd, marker_send, len, 0)) == -1) {
    perror("send");
    exit(1);
  }
  printf("sent signal\n");
  if ((numbytes = recv(sockfd, marker_recv, 100 - 1, 0)) == -1) {
    perror("recv");
    exit(1);
  }
  marker_recv[numbytes] = '\0';
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<cclient>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
lea    0xdfe(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xbc(%rbp)
lea    0xdf4(%rip),%rdi
lea    0xde0(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xc8(%rbp)
cmp    $0x0,%rax
jne    124f <cclient+0x5f>
lea    0xdc5(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0xc8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xdc0(%rip),%rsi
call   10a0 <fscanf@plt>
mov    -0xc8(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x30(%rbp),%rsi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x30(%rbp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
jne    12b4 <cclient+0xc4>
lea    0xd91(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    $0x2328,%edi
call   1060 <htons@plt>
mov    %eax,-0xb0(%rbp)
mov    -0xa8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
lea    -0xb8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
mov    0x2cd0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    1333 <cclient+0x143>
lea    0xd20(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0xb8(%rbp),%rsi
mov    $0x4,%edx
call   1100 <connect@plt>
cmp    $0xffffffff,%eax
jne    1366 <cclient+0x176>
lea    0xcf4(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0xbc(%rbp),%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    13aa <cclient+0x1ba>
lea    0xccd(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    13f0 <cclient+0x200>
lea    0xc99(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movslq -0x8(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    -0x4(%rbp),%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cclient>:
push   %rbp
push   %r14
push   %rbx
sub    $0xb0,%rsp
lea    0xdee(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
lea    0xded(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1346 <cclient+0x146>
mov    %rax,%rbp
lea    0xddf(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rax,%rdi
mov    %rbx,%rdx
call   10b0 <fscanf@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xdc3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   10d0 <gethostbyname@plt>
test   %rax,%rax
je     134f <cclient+0x14f>
mov    %rax,%rbp
mov    0x2d64(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    $0x2328,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    (%rbx),%edi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     1358 <cclient+0x158>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
je     1361 <cclient+0x161>
lea    0xd72(%rip),%rdi
call   1040 <puts@plt>
lea    0xd0b(%rip),%rsi
mov    %ebp,%edi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
je     136a <cclient+0x16a>
lea    0xd62(%rip),%rdi
call   1040 <puts@plt>
lea    0x40(%rsp),%rsi
mov    %ebp,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1373 <cclient+0x173>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
mov    %ebp,%edi
call   10c0 <close@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xcb6(%rip),%rdi
jmp    137a <cclient+0x17a>
lea    0xcde(%rip),%rdi
jmp    137a <cclient+0x17a>
lea    0xce3(%rip),%rdi
jmp    137a <cclient+0x17a>
lea    0xce1(%rip),%rdi
jmp    137a <cclient+0x17a>
lea    0xce0(%rip),%rdi
jmp    137a <cclient+0x17a>
lea    0xcdc(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"go\00"
@.str.1 = [17 x i8] c"sockets.optional\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"can't find sockets.optional\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [18 x i8] c"server is at: %s\0A\00"
@.str.6 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.7 = [7 x i8] c"socket\00"
@.str.8 = [8 x i8] c"connect\00"
@.str.9 = [21 x i8] c"connected to server\0A\00"
@.str.10 = [5 x i8] c"send\00"
@.str.11 = [13 x i8] c"sent signal\0A\00"
@.str.12 = [5 x i8] c"recv\00"
define i32 @cclient() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [40 x i8]
%4 = alloca i8*
%5 = alloca [100 x i8]
%6 = alloca %struct.hostent*
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32*
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %8
%12 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32*, i32** %9
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%20 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %9
%22 = call i32 @fclose(i32* %21)
%23 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%26 = call %struct.hostent* @gethostbyname(i8* %25)
store %struct.hostent* %26, %struct.hostent** %6
%27 = icmp eq %struct.hostent* %26, null
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 3
store i32 %32, i32* %33
%34 = call i32 @htons(i32 9000)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%37 = load %struct.hostent*, %struct.hostent** %6
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = inttoptr i64 %39 to %struct.in_addr*
%41 = bitcast %struct.in_addr* %36 to i8*
%42 = bitcast %struct.in_addr* %40 to i8*
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%44 = call i32 @memset(i32* %43, i8 signext 0, i32 8)
%45 = load i32, i32* @AF_INET
%46 = load i32, i32* @SOCK_STREAM
%47 = call i32 @socket(i32 %45, i32 %46, i32 0)
store i32 %47, i32* %1
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %31
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %31
%53 = load i32, i32* %1
%54 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%55 = call i32 @connect(i32 %53, %struct.sockaddr* %54, i32 4)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %52
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%62 = load i32, i32* %1
%63 = load i8*, i8** %4
%64 = load i32, i32* %8
%65 = call i32 @send(i32 %62, i8* %63, i32 %64, i32 0)
store i32 %65, i32* %2
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %60
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
%72 = load i32, i32* %1
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%74 = call i32 @recv(i32 %72, i8* %73, i32 99, i32 0)
store i32 %74, i32* %2
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %70
%77 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %70
%80 = load i32, i32* %2
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %81
store i8 0, i8* %82
%83 = load i32, i32* %1
%84 = call i32 @close(i32 %83)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"go\00"
@.str.1 = [17 x i8] c"sockets.optional\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"can't find sockets.optional\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [18 x i8] c"server is at: %s\0A\00"
@.str.6 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.7 = [7 x i8] c"socket\00"
@.str.8 = [8 x i8] c"connect\00"
@.str.10 = [5 x i8] c"send\00"
@.str.12 = [5 x i8] c"recv\00"
@str = [20 x i8] c"connected to server\00"
@str.13 = [12 x i8] c"sent signal\00"
define i32 @cclient() {
%1 = alloca [40 x i8]
%2 = alloca [100 x i8]
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%15 = call i32 @fclose(i32* %8)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%17 = call %struct.hostent* @gethostbyname(i8* %4)
%18 = icmp eq %struct.hostent* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %23, i32* %24
%25 = call i32 @htons(i32 9000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 0
%28 = load i64, i64* %27
%29 = inttoptr i64 %28 to i32*
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%31 = load i32, i32* %29
store i32 %31, i32* %30
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%33 = call i32 @memset(i32* %32, i8 signext 0, i32 8)
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %22
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %22
%42 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%43 = call i32 @connect(i32 %36, %struct.sockaddr* %42, i32 4)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %41
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%50 = call i32 @send(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7, i32 0)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %48
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%57 = call i32 @recv(i32 %36, i8* %5, i32 99, i32 0)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %55
%63 = sext i32 %57 to i64
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %63
store i8 0, i8* %64
%65 = call i32 @close(i32 %36)
ret i32 0
}