#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*/ snprintf(char *, int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sockfd, numbytes;
  int port;
  char pn_str[16];
  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);
  }
  port = 12345;
  (void)snprintf(pn_str, sizeof pn_str, "%d", port);
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((rv = getaddrinfo(argv[1], pn_str, &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);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x100(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0xe0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xf8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xe8(%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>
movl   $0x3039,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    $0x10,%esi
lea    0xd8e(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
lea    -0xc8(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0xd4(%rbp)
cmp    $0x0,%eax
je     1335 <main+0x145>
mov    0x2cdb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x104(%rbp)
mov    -0xd4(%rbp),%edi
call   1080 <gai_strerror@plt>
mov    -0x104(%rbp),%edi
mov    %rax,%rdx
lea    0xd03(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0xec(%rbp)
jmp    14f1 <main+0x301>
mov    -0xc8(%rbp),%rax
mov    %rax,-0xd0(%rbp)
cmpq   $0x0,-0xd0(%rbp)
je     13eb <main+0x1fb>
mov    -0xd0(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0xd0(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0xd0(%rbp),%rax
mov    0x10(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1391 <main+0x1a1>
lea    0xca5(%rip),%rdi
call   10c0 <perror@plt>
jmp    13d4 <main+0x1e4>
mov    -0x14(%rbp),%edi
mov    -0xd0(%rbp),%rax
mov    (%rax),%rsi
mov    -0xd0(%rbp),%rax
mov    0xc(%rax),%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    13cf <main+0x1df>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
lea    0xc76(%rip),%rdi
call   10c0 <perror@plt>
jmp    13d4 <main+0x1e4>
jmp    13eb <main+0x1fb>
mov    -0xd0(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0xd0(%rbp)
jmp    1343 <main+0x153>
cmpq   $0x0,-0xd0(%rbp)
jne    1426 <main+0x236>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
lea    0xc42(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0xec(%rbp)
jmp    14f1 <main+0x301>
mov    -0xd0(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x108(%rbp)
mov    -0xd0(%rbp),%rax
mov    (%rax),%rdi
call   1050 <get_in_addr@plt>
mov    -0x108(%rbp),%edi
mov    -0xf8(%rbp),%rdx
mov    %eax,%esi
mov    -0x100(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0xf8(%rbp),%rsi
lea    0xbf6(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc8(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    14b9 <main+0x2c9>
lea    0xbd6(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rsi
lea    0xbb2(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xec(%rbp)
mov    -0xe0(%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    $0xb8,%rsp
mov    %rsp,-0x30(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x2,%edi
jne    13bf <main+0x1cf>
mov    %rsi,%r15
lea    0xde2(%rip),%rdx
lea    -0x70(%rbp),%r12
mov    %r12,%rdi
mov    $0x10,%esi
mov    $0x3039,%ecx
call   1070 <snprintf@plt>
lea    -0x58(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x8(%r15),%rdi
lea    -0x38(%rbp),%rcx
mov    %r12,%rsi
mov    %rbx,%rdx
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
je     12bb <main+0xcb>
mov    0x2d3b(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1080 <gai_strerror@plt>
lea    0xd76(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebx
jmp    13a7 <main+0x1b7>
mov    -0x38(%rbp),%rbx
test   %rbx,%rbx
je     1313 <main+0x123>
lea    0xd61(%rip),%r12
mov    0x14(%rbx),%esi
mov    0x8(%rbx),%edi
mov    0x10(%rbx),%edx
call   1110 <socket@plt>
mov    %r12,%rdi
cmp    $0xffffffff,%eax
je     1305 <main+0x115>
mov    %eax,%r15d
mov    (%rbx),%rsi
mov    0xc(%rbx),%edx
mov    %eax,%edi
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1331 <main+0x141>
mov    %r15d,%edi
call   10a0 <close@plt>
lea    0xd36(%rip),%rdi
call   10c0 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    12cb <main+0xdb>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x2,%ebx
jmp    13a7 <main+0x1b7>
mov    0x8(%rbx),%r12d
mov    (%rbx),%rdi
call   1050 <get_in_addr@plt>
mov    %r12d,%edi
mov    %eax,%esi
mov    %r13,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
lea    0xd12(%rip),%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
lea    -0xe0(%rbp),%rsi
xor    %ebx,%ebx
mov    %r15d,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     13e0 <main+0x1f0>
cltq
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    0xcf2(%rip),%rdi
lea    -0xe0(%rbp),%rsi
call   1060 <printf@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xc31(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xc99(%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"
@.str.1 = [3 x i8] c"%d\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca [100 x i8]
%11 = alloca %struct.addrinfo
%12 = alloca %struct.addrinfo*
%13 = alloca %struct.addrinfo*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i64
%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** %15
%21 = alloca i8, i64 %19
store i64 %19, i64* %16
%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
store i32 12345, i32* %8
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%30 = load i32, i32* %8
%31 = call i32 @snprintf(i8* %29, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 @memset(%struct.addrinfo* %11, i32 0, i32 32)
%33 = load i32, i32* @AF_UNSPEC
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 1
store i32 %33, i32* %34
%35 = load i32, i32* @SOCK_STREAM
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 4
store i32 %35, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%41 = call i32 @getaddrinfo(i8* %39, i8* %40, %struct.addrinfo* %11, %struct.addrinfo** %12)
store i32 %41, i32* %14
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %28
%44 = load i32, i32* @stderr
%45 = load i32, i32* %14
%46 = call i8* @gai_strerror(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %46)
store i32 1, i32* %3
store i32 1, i32* %17
br label %121
48: ; preds = %28
%49 = load %struct.addrinfo*, %struct.addrinfo** %12
store %struct.addrinfo* %49, %struct.addrinfo** %13
br label %50
50: ; preds = %82, %48
%51 = load %struct.addrinfo*, %struct.addrinfo** %13
%52 = icmp ne %struct.addrinfo* %51, null
br i1 %52, label %53, label %86
53: ; preds = %50
%54 = load %struct.addrinfo*, %struct.addrinfo** %13
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 1
%56 = load i32, i32* %55
%57 = load %struct.addrinfo*, %struct.addrinfo** %13
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 4
%59 = load i32, i32* %58
%60 = load %struct.addrinfo*, %struct.addrinfo** %13
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i32 0, i32 3
%62 = load i32, i32* %61
%63 = call i32 @socket(i32 %56, i32 %59, i32 %62)
store i32 %63, i32* %6
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %67
65: ; preds = %53
%66 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %82
67: ; preds = %53
%68 = load i32, i32* %6
%69 = load %struct.addrinfo*, %struct.addrinfo** %13
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 0
%71 = load i64, i64* %70
%72 = load %struct.addrinfo*, %struct.addrinfo** %13
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 2
%74 = load i32, i32* %73
%75 = call i32 @connect(i32 %68, i64 %71, i32 %74)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %81
77: ; preds = %67
%78 = load i32, i32* %6
%79 = call i32 @close(i32 %78)
%80 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %82
81: ; preds = %67
br label %86
82: ; preds = %77, %65
%83 = load %struct.addrinfo*, %struct.addrinfo** %13
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %83, i32 0, i32 5
%85 = load %struct.addrinfo*, %struct.addrinfo** %84
store %struct.addrinfo* %85, %struct.addrinfo** %13
br label %50
86: ; preds = %81, %50
%87 = load %struct.addrinfo*, %struct.addrinfo** %13
%88 = icmp eq %struct.addrinfo* %87, null
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
store i32 1, i32* %17
br label %121
92: ; preds = %86
%93 = load %struct.addrinfo*, %struct.addrinfo** %13
%94 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %93, i32 0, i32 1
%95 = load i32, i32* %94
%96 = load %struct.addrinfo*, %struct.addrinfo** %13
%97 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %96, i32 0, i32 0
%98 = load i64, i64* %97
%99 = inttoptr i64 %98 to %struct.sockaddr*
%100 = call i32 @get_in_addr(%struct.sockaddr* %99)
%101 = trunc i64 %19 to i32
%102 = call i32 @inet_ntop(i32 %95, i32 %100, i8* %21, i32 %101)
%103 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %21)
%104 = load %struct.addrinfo*, %struct.addrinfo** %12
%105 = call i32 @freeaddrinfo(%struct.addrinfo* %104)
%106 = load i32, i32* %6
%107 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%108 = call i32 @recv(i32 %106, i8* %107, i32 99, i32 0)
store i32 %108, i32* %7
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %113
110: ; preds = %92
%111 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %92
%114 = load i32, i32* %7
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 %115
store i8 0, i8* %116
%117 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%118 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %117)
%119 = load i32, i32* %6
%120 = call i32 @close(i32 %119)
store i32 0, i32* %3
store i32 1, i32* %17
br label %121
121: ; preds = %113, %89, %43
%122 = load i8*, i8** %15
%123 = load i32, i32* %3
ret i32 %123
}

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