#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 sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  struct addrinfo *ai_next;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sockfd, numbytes;
  char buf[100];
  struct addrinfo hints, *servinfo, *p;
  int rv;
  char s[INET6_ADDRSTRLEN];
  if (argc != 2) {
    fprintf(stderr, "usage: client hostname\n");
    exit(1);
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((rv = getaddrinfo(argv[1], "3490", &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    return 1;
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      perror("client: socket");
      continue;
    }
    if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
      close(sockfd);
      perror("client: connect");
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "client: failed to connect\n");
    return 2;
  }
  inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s,
            sizeof s);
  printf("client: connecting to %s\n", s);
  freeaddrinfo(servinfo);
  if ((numbytes = recv(sockfd, buf, 100 - 1, 0)) == -1) {
    perror("recv");
    exit(1);
  }
  buf[numbytes] = '\0';
  printf("client: received '%s'\n", buf);
  send(sockfd, "hey there", 9, 0);
  char buf2[100];
  int numb2;
  numb2 = recv(sockfd, buf2, 100 - 1, 0);
  buf2[numb2] = '\n';
  buf2[numb2 + 1] = '\0';
  printf("server says: %s\n", buf2);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x148(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0xc0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x140(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xc8(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1270 <main+0x80>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd68(%rip),%rsi
lea    -0xa0(%rbp),%rdx
lea    -0xa8(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0xb4(%rbp)
cmp    $0x0,%eax
je     1319 <main+0x129>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14c(%rbp)
mov    -0xb4(%rbp),%edi
call   1080 <gai_strerror@plt>
mov    -0x14c(%rbp),%edi
mov    %rax,%rdx
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0xcc(%rbp)
jmp    1533 <main+0x343>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
je     13cf <main+0x1df>
mov    -0xb0(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0xb0(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0xb0(%rbp),%rax
mov    0x10(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1375 <main+0x185>
lea    0xcc3(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b8 <main+0x1c8>
mov    -0x14(%rbp),%edi
mov    -0xb0(%rbp),%rax
mov    (%rax),%rsi
mov    -0xb0(%rbp),%rax
mov    0xc(%rax),%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    13b3 <main+0x1c3>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
lea    0xc94(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b8 <main+0x1c8>
jmp    13cf <main+0x1df>
mov    -0xb0(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0xb0(%rbp)
jmp    1327 <main+0x137>
cmpq   $0x0,-0xb0(%rbp)
jne    140a <main+0x21a>
mov    0x2bec(%rip),%rax
mov    (%rax),%edi
lea    0xc60(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0xcc(%rbp)
jmp    1533 <main+0x343>
mov    -0xb0(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x150(%rbp)
mov    -0xb0(%rbp),%rax
mov    (%rax),%rdi
call   1050 <get_in_addr@plt>
mov    -0x150(%rbp),%edi
mov    -0x140(%rbp),%rdx
mov    %eax,%esi
mov    -0x148(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x140(%rbp),%rsi
lea    0xc14(%rip),%rdi
call   1070 <printf@plt>
mov    -0xa8(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    149a <main+0x2aa>
lea    0xbf7(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xbd9(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xbe1(%rip),%rsi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x134(%rbp)
movslq -0x134(%rbp),%rax
movb   $0xa,-0x130(%rbp,%rax,1)
0a
mov    -0x134(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x130(%rbp,%rax,1)
lea    -0x130(%rbp),%rsi
lea    0xb93(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xcc(%rbp)
mov    -0xc0(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsp,%r13
mov    0x2dda(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x2,%edi
jne    13ff <main+0x20f>
mov    %rsi,%rbx
lea    -0x58(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x8(%rbx),%rdi
lea    0xdb4(%rip),%rsi
lea    -0x38(%rbp),%rcx
mov    %r15,%rdx
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
je     12a1 <main+0xb1>
mov    0x2d55(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1080 <gai_strerror@plt>
lea    0xd92(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebx
jmp    13eb <main+0x1fb>
mov    %r13,-0x30(%rbp)
mov    -0x38(%rbp),%r13
test   %r13,%r13
je     1302 <main+0x112>
lea    0xd79(%rip),%rbx
mov    0x14(%r13),%esi
mov    0x8(%r13),%edi
mov    0x10(%r13),%edx
call   1110 <socket@plt>
mov    %rbx,%rdi
cmp    $0xffffffff,%eax
je     12f4 <main+0x104>
mov    %eax,%r15d
mov    0x0(%r13),%rsi
mov    0xc(%r13),%edx
mov    %eax,%edi
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1323 <main+0x133>
mov    %r15d,%edi
call   10a0 <close@plt>
lea    0xd49(%rip),%rdi
call   10c0 <perror@plt>
mov    0x18(%r13),%r13
test   %r13,%r13
jne    12b5 <main+0xc5>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x2,%ebx
jmp    13e7 <main+0x1f7>
mov    0x8(%r13),%ebx
mov    0x0(%r13),%rdi
call   1050 <get_in_addr@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
lea    0xd22(%rip),%rdi
mov    %r12,%rsi
call   1070 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
lea    -0xc0(%rbp),%rsi
xor    %ebx,%ebx
mov    %r15d,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     1420 <main+0x230>
cltq
movb   $0x0,-0xc0(%rbp,%rax,1)
lea    0xcfe(%rip),%rdi
lea    -0xc0(%rbp),%rsi
call   1070 <printf@plt>
lea    0xd02(%rip),%rsi
mov    %r15d,%edi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    -0x130(%rbp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cltq
movw   $0xa,-0x130(%rbp,%rax,1)
lea    0xcd1(%rip),%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    -0x30(%rbp),%r13
mov    %r13,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bca(%rip),%rax
mov    (%rax),%edi
lea    0xbf1(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xc5b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"usage: client hostname\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"3490\00"
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [15 x i8] c"client: socket\00"
@.str.4 = [16 x i8] c"client: connect\00"
@.str.5 = [27 x i8] c"client: failed to connect\0A\00"
@.str.6 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.7 = [5 x i8] c"recv\00"
@.str.8 = [23 x i8] c"client: received '%s'\0A\00"
@.str.9 = [10 x i8] c"hey there\00"
@.str.10 = [17 x i8] c"server says: %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.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca %struct.addrinfo*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca [100 x i8]
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* @INET6_ADDRSTRLEN
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %13
%21 = alloca i8, i64 %19
store i64 %19, i64* %14
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 2
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 32)
%30 = load i32, i32* @AF_UNSPEC
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 1
store i32 %30, i32* %31
%32 = load i32, i32* @SOCK_STREAM
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i32 %32, i32* %33
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @getaddrinfo(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %37, i32* %12
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %28
%40 = load i32, i32* @stderr
%41 = load i32, i32* %12
%42 = call i8* @gai_strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 1, i32* %3
store i32 1, i32* %15
br label %131
44: ; preds = %28
%45 = load %struct.addrinfo*, %struct.addrinfo** %10
store %struct.addrinfo* %45, %struct.addrinfo** %11
br label %46
46: ; preds = %78, %44
%47 = load %struct.addrinfo*, %struct.addrinfo** %11
%48 = icmp ne %struct.addrinfo* %47, null
br i1 %48, label %49, label %82
49: ; preds = %46
%50 = load %struct.addrinfo*, %struct.addrinfo** %11
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load %struct.addrinfo*, %struct.addrinfo** %11
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 4
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %11
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 3
%58 = load i32, i32* %57
%59 = call i32 @socket(i32 %52, i32 %55, i32 %58)
store i32 %59, i32* %6
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %49
%62 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %78
63: ; preds = %49
%64 = load i32, i32* %6
%65 = load %struct.addrinfo*, %struct.addrinfo** %11
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = load %struct.addrinfo*, %struct.addrinfo** %11
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 2
%70 = load i32, i32* %69
%71 = call i32 @connect(i32 %64, i64 %67, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %77
73: ; preds = %63
%74 = load i32, i32* %6
%75 = call i32 @close(i32 %74)
%76 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %78
77: ; preds = %63
br label %82
78: ; preds = %73, %61
%79 = load %struct.addrinfo*, %struct.addrinfo** %11
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 5
%81 = load %struct.addrinfo*, %struct.addrinfo** %80
store %struct.addrinfo* %81, %struct.addrinfo** %11
br label %46
82: ; preds = %77, %46
%83 = load %struct.addrinfo*, %struct.addrinfo** %11
%84 = icmp eq %struct.addrinfo* %83, null
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
store i32 1, i32* %15
br label %131
88: ; preds = %82
%89 = load %struct.addrinfo*, %struct.addrinfo** %11
%90 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %89, i32 0, i32 1
%91 = load i32, i32* %90
%92 = load %struct.addrinfo*, %struct.addrinfo** %11
%93 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %92, i32 0, i32 0
%94 = load i64, i64* %93
%95 = inttoptr i64 %94 to %struct.sockaddr*
%96 = call i32 @get_in_addr(%struct.sockaddr* %95)
%97 = trunc i64 %19 to i32
%98 = call i32 @inet_ntop(i32 %91, i32 %96, i8* %21, i32 %97)
%99 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %21)
%100 = load %struct.addrinfo*, %struct.addrinfo** %10
%101 = call i32 @freeaddrinfo(%struct.addrinfo* %100)
%102 = load i32, i32* %6
%103 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%104 = call i32 @recv(i32 %102, i8* %103, i32 99, i32 0)
store i32 %104, i32* %7
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %109
106: ; preds = %88
%107 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %88
%110 = load i32, i32* %7
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %111
store i8 0, i8* %112
%113 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%114 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %113)
%115 = load i32, i32* %6
%116 = call i32 @send(i32 %115, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 9, i32 0)
%117 = load i32, i32* %6
%118 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%119 = call i32 @recv(i32 %117, i8* %118, i32 99, i32 0)
store i32 %119, i32* %17
%120 = load i32, i32* %17
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 %121
store i8 10, i8* %122
%123 = load i32, i32* %17
%124 = add nsw i32 %123, 1
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 %125
store i8 0, i8* %126
%127 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%128 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i8* %127)
%129 = load i32, i32* %6
%130 = call i32 @close(i32 %129)
store i32 0, i32* %3
store i32 1, i32* %15
br label %131
131: ; preds = %109, %85, %39
%132 = load i8*, i8** %13
%133 = load i32, i32* %3
ret i32 %133
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"usage: client hostname\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"3490\00"
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [15 x i8] c"client: socket\00"
@.str.4 = [16 x i8] c"client: connect\00"
@.str.5 = [27 x i8] c"client: failed to connect\0A\00"
@.str.6 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.7 = [5 x i8] c"recv\00"
@.str.8 = [23 x i8] c"client: received '%s'\0A\00"
@.str.9 = [10 x i8] c"hey there\00"
@.str.10 = [17 x i8] c"server says: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca [100 x i8]
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.addrinfo* %4 to i8*
%9 = bitcast %struct.addrinfo** %5 to i8*
%10 = load i32, i32* @INET6_ADDRSTRLEN
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = icmp eq i32 %0, 2
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 32)
%21 = load i32, i32* @AF_UNSPEC
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %23, i32* %24
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @getaddrinfo(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %5)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = load %struct.addrinfo*, %struct.addrinfo** %5
%31 = icmp eq %struct.addrinfo* %30, null
br i1 %31, label %61, label %36
32: ; preds = %19
%33 = load i32, i32* @stderr
%34 = call i8* @gai_strerror(i32 %27)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %94
36: ; preds = %29, %55
%37 = phi %struct.addrinfo* [ %59, %55 ], [ %30, %29 ]
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 4
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 3
%43 = load i32, i32* %42
%44 = call i32 @socket(i32 %39, i32 %41, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %55, label %46
46: ; preds = %36
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 0
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 2
%50 = load i32, i32* %49
%51 = call i32 @connect(i32 %44, i64 %48, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %64
53: ; preds = %46
%54 = call i32 @close(i32 %44)
br label %55
55: ; preds = %36, %53
%56 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), %53 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %36 ]
%57 = call i32 @perror(i8* %56)
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 5
%59 = load %struct.addrinfo*, %struct.addrinfo** %58
%60 = icmp eq %struct.addrinfo* %59, null
br i1 %60, label %61, label %36
61: ; preds = %55, %29
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %94
64: ; preds = %46
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 1
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 0
%67 = load i32, i32* %65
%68 = load i64, i64* %66
%69 = inttoptr i64 %68 to %struct.sockaddr*
%70 = call i32 @get_in_addr(%struct.sockaddr* %69)
%71 = call i32 @inet_ntop(i32 %67, i32 %70, i8* %13, i32 %10)
%72 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%73 = load %struct.addrinfo*, %struct.addrinfo** %5
%74 = call i32 @freeaddrinfo(%struct.addrinfo* %73)
%75 = call i32 @recv(i32 %44, i8* %7, i32 99, i32 0)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %80
77: ; preds = %64
%78 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %64
%81 = sext i32 %75 to i64
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %81
store i8 0, i8* %82
%83 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%84 = call i32 @send(i32 %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 9, i32 0)
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%86 = call i32 @recv(i32 %44, i8* %85, i32 99, i32 0)
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %87
store i8 10, i8* %88
%89 = add nsw i32 %86, 1
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %90
store i8 0, i8* %91
%92 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i8* %85)
%93 = call i32 @close(i32 %44)
br label %94
94: ; preds = %80, %61, %32
%95 = phi i32 [ 1, %32 ], [ 2, %61 ], [ 0, %80 ]
ret i32 %95
}