#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int getpid();
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sockfd, numbytes;
  char buf[100];
  struct hostent *he;
  struct sockaddr_in their_addr;
  if (argc != 2) {
    fprintf(stderr, "usage: client hostname\n");
    exit(1);
  }
  if ((he = gethostbyname(argv[1])) == NULL) {
    herror("gethostbyname");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(9999);
  their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  bzero(&(their_addr.sin_zero), 8);
  if (connect(sockfd, (struct sockaddr *)&their_addr,
              sizeof(struct sockaddr)) == -1) {
    perror("connect");
    exit(1);
  }
  while (1) {
    if (send(sockfd, "Hello, world!\n", 14, 0) == -1) {
      perror("send");
      exit(1);
    }
    printf("After the send function \n");
    if ((numbytes = recv(sockfd, buf, 100, 0)) == -1) {
      perror("recv");
      exit(1);
    }
    buf[numbytes] = '\0';
    printf("Received in pid=%d, text=: %s \n", getpid(), buf);
    sleep(1);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1222 <main+0x42>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    1256 <main+0x76>
lea    0xdd1(%rip),%rdi
call   10a0 <herror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1291 <main+0xb1>
lea    0xda4(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,-0x90(%rbp)
mov    -0x88(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
lea    -0x98(%rbp),%rdi
mov    $0x8,%esi
call   10c0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x98(%rbp),%rsi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1306 <main+0x126>
lea    0xd36(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    130b <main+0x12b>
mov    -0x14(%rbp),%edi
lea    0xd20(%rip),%rsi
mov    $0xe,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
jne    1340 <main+0x160>
lea    0xd13(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1383 <main+0x1a3>
lea    0xcef(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    -0x80(%rbp),%rdx
lea    0xcc8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
jmp    130b <main+0x12b>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
cmp    $0x2,%edi
jne    1229 <main+0x39>
mov    0x8(%rsi),%rdi
call   1090 <gethostbyname@plt>
test   %rax,%rax
jne    1248 <main+0x58>
lea    0xdfe(%rip),%rdi
call   10b0 <herror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rax,%r14
mov    0x2d96(%rip),%r15
mov    (%r15),%edi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
jne    1276 <main+0x86>
lea    0xdb5(%rip),%rdi
jmp    136b <main+0x17b>
mov    %eax,%ebx
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%r14),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   10d0 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12c6 <main+0xd6>
lea    0xd6c(%rip),%rdi
jmp    136b <main+0x17b>
lea    0xd68(%rip),%rsi
mov    %ebx,%edi
mov    $0xe,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
je     135b <main+0x16b>
lea    0xd83(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xd57(%rip),%r12
lea    0xd37(%rip),%r13
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1364 <main+0x174>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0xe,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
jne    1300 <main+0x110>
lea    0xce2(%rip),%rdi
jmp    136b <main+0x17b>
lea    0xcde(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <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 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: client hostname\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [15 x i8] c"Hello, world!\0A\00"
@.str.5 = [5 x i8] c"send\00"
@.str.6 = [26 x i8] c"After the send function \0A\00"
@.str.7 = [5 x i8] c"recv\00"
@.str.8 = [32 x i8] c"Received in pid=%d, text=: %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca %struct.hostent*
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call %struct.hostent* @gethostbyname(i8* %20)
store %struct.hostent* %21, %struct.hostent** %9
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %35, i32* %36
%37 = call i32 @htons(i32 9999)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%40 = load %struct.hostent*, %struct.hostent** %9
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to %struct.in_addr*
%44 = bitcast %struct.in_addr* %39 to i8*
%45 = bitcast %struct.in_addr* %43 to i8*
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%47 = call i32 @bzero(i32* %46, i32 8)
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%50 = call i32 @connect(i32 %48, %struct.sockaddr* %49, i32 4)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %34
%53 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %34
br label %56
56: ; preds = %55, %72
%57 = load i32, i32* %6
%58 = call i32 @send(i32 %57, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 14, i32 0)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %56
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%65 = load i32, i32* %6
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%67 = call i32 @recv(i32 %65, i8* %66, i32 100, i32 0)
store i32 %67, i32* %7
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %63
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %74
store i8 0, i8* %75
%76 = call i32 (...) @getpid()
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %76, i8* %77)
%79 = call i32 @sleep(i32 1)
br label %56
}

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 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: client hostname\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [15 x i8] c"Hello, world!\0A\00"
@.str.5 = [5 x i8] c"send\00"
@.str.7 = [5 x i8] c"recv\00"
@.str.8 = [32 x i8] c"Received in pid=%d, text=: %s \0A\00"
@str = [25 x i8] c"After the send function \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %29, i32* %30
%31 = tail call i32 @htons(i32 9999)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i32*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%37 = load i32, i32* %35
store i32 %37, i32* %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%39 = call i32 @bzero(i32* %38, i32 8)
%40 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%41 = call i32 @connect(i32 %23, %struct.sockaddr* %40, i32 4)
%42 = icmp eq i32 %41, -1
br i1 %42, label %46, label %43
43: ; preds = %28
%44 = call i32 @send(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 14, i32 0)
%45 = icmp eq i32 %44, -1
br i1 %45, label %49, label %52
46: ; preds = %28
%47 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %59, %43
%50 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %43, %59
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%54 = call i32 @recv(i32 %23, i8* %5, i32 100, i32 0)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %52
%60 = sext i32 %54 to i64
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %60
store i8 0, i8* %61
%62 = call i32 (...) @getpid()
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %62, i8* %5)
%64 = call i32 @sleep(i32 1)
%65 = call i32 @send(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 14, i32 0)
%66 = icmp eq i32 %65, -1
br i1 %66, label %49, label %52
}