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

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
size_t write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int s, sfd, r;
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  char buf[512], *pt;
  ssize_t nread, nwrite;
  if (argc != 3) {
    printf("Usage: %s nom_machine_distante port_serveur\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  s = getaddrinfo(argv[1], argv[2], &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    sfd = socket(AF_INET6, SOCK_STREAM, 0);
    if (sfd == -1)
      continue;
    r = connect(sfd, rp->ai_addr, rp->ai_addrlen);
    if (r != -1)
      break;
    close(sfd);
  }
  if (rp == NULL) {
    perror("connect");
    exit(EXIT_FAILURE);
  }
  freeaddrinfo(result);
  for (;;) {
    nread = read(sfd, buf, 512);
    if (nread == 0) {
      printf("Connexion rompue\n");
      exit(EXIT_SUCCESS);
    } else if (nread < 0) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    buf[nread] = '\0';
    printf("Message recu '%s'", buf);
    pt = fgets(buf, 512, stdin);
    if (pt == NULL) {
      printf("Sortie du client\n");
      exit(EXIT_SUCCESS);
    }
    nwrite = write(sfd, buf, strlen(buf));
    if (nwrite < 0) {
      perror("write");
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1236 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12d2 <main+0xe2>
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x27c(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x27c(%rbp),%edi
mov    %rax,%rdx
lea    0xd6e(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1350 <main+0x160>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1310 <main+0x120>
jmp    133f <main+0x14f>
mov    -0x18(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   10e0 <connect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     1337 <main+0x147>
jmp    1350 <main+0x160>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    12da <main+0xea>
cmpq   $0x0,-0x58(%rbp)
jne    1375 <main+0x185>
lea    0xcdc(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x50(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
mov    -0x18(%rbp),%edi
lea    -0x260(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %rax,-0x270(%rbp)
cmpq   $0x0,-0x270(%rbp)
jne    13c3 <main+0x1d3>
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpq   $0x0,-0x270(%rbp)
jae    13eb <main+0x1fb>
lea    0xc80(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    13f0 <main+0x200>
mov    -0x270(%rbp),%rax
movb   $0x0,-0x260(%rbp,%rax,1)
lea    -0x260(%rbp),%rsi
lea    0xc50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x260(%rbp),%rdi
mov    0x2bbe(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   10a0 <fgets@plt>
mov    %rax,-0x268(%rbp)
cmpq   $0x0,-0x268(%rbp)
jne    145f <main+0x26f>
lea    0xc25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28c(%rbp)
lea    -0x260(%rbp),%rax
mov    %rax,-0x288(%rbp)
lea    -0x260(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28c(%rbp),%edi
mov    -0x288(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x278(%rbp)
cmpq   $0x0,-0x278(%rbp)
jae    14c5 <main+0x2d5>
lea    0xbcf(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2afa(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    137e <main+0x18e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x230,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    127c <main+0x7c>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2d81(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    %rsp,%rcx
mov    %r14,%rdx
call   1100 <getaddrinfo@plt>
test   %eax,%eax
jne    128f <main+0x8f>
mov    (%rsp),%rbx
test   %rbx,%rbx
jne    12be <main+0xbe>
lea    0xdc9(%rip),%rdi
call   10d0 <perror@plt>
jmp    12b0 <main+0xb0>
mov    (%rbx),%rsi
lea    0xd7a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12b0 <main+0xb0>
mov    0x2d32(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <gai_strerror@plt>
lea    0xd87(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10c0 <fprintf@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2d13(%rip),%r14
jmp    12d9 <main+0xd9>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     126e <main+0x6e>
mov    (%r14),%edi
mov    (%r15),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     12d0 <main+0xd0>
mov    %eax,%ebp
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1307 <main+0x107>
mov    %ebp,%edi
call   1090 <close@plt>
jmp    12d0 <main+0xd0>
mov    (%rsp),%rdi
call   1110 <freeaddrinfo@plt>
lea    0x30(%rsp),%rsi
mov    %ebp,%edi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %rax,%rax
je     1390 <main+0x190>
lea    0xd19(%rip),%r14
lea    0x30(%rsp),%r15
mov    0x2ca7(%rip),%r12
nopl   0x0(%rax)
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x200,%esi
call   10b0 <fgets@plt>
test   %rax,%rax
je     1399 <main+0x199>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %rax,%rax
jne    1340 <main+0x140>
lea    0xcd2(%rip),%rdi
jmp    13a0 <main+0x1a0>
lea    0xcb8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i64, i64, i32, i32 }
@.str = [45 x i8] c"Usage: %s nom_machine_distante port_serveur\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@AF_INET6 = global i32 0
@.str.2 = [8 x i8] c"connect\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [18 x i8] c"Message recu '%s'\00"
@stdin = global i32 0
@str = [17 x i8] c"Sortie du client\00"
@str.8 = [17 x i8] c"Connexion rompue\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [512 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%17 = load i32, i32* @AF_UNSPEC
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i32 %17, i32* %18
%19 = load i32, i32* @SOCK_STREAM
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = bitcast i64* %21 to i8*
%24 = load i8*, i8** %22
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @getaddrinfo(i8* %24, i8* %26, %struct.addrinfo* %3, %struct.addrinfo** %4)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %15
%30 = load %struct.addrinfo*, %struct.addrinfo** %4
%31 = icmp eq %struct.addrinfo* %30, null
br i1 %31, label %57, label %38
32: ; preds = %15
%33 = load i32, i32* @stderr
%34 = call i8* @gai_strerror(i32 %27)
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29, %53
%39 = phi %struct.addrinfo* [ %55, %53 ], [ %30, %29 ]
%40 = load i32, i32* @AF_INET6
%41 = load i32, i32* @SOCK_STREAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %53, label %44
44: ; preds = %38
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 1
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @connect(i32 %42, i32 %46, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %61
51: ; preds = %44
%52 = call i32 @close(i32 %42)
br label %53
53: ; preds = %38, %51
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 2
%55 = load %struct.addrinfo*, %struct.addrinfo** %54
%56 = icmp eq %struct.addrinfo* %55, null
br i1 %56, label %57, label %38
57: ; preds = %53, %29
%58 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %44
%62 = load %struct.addrinfo*, %struct.addrinfo** %4
%63 = call i32 @freeaddrinfo(%struct.addrinfo* %62)
%64 = call i64 @read(i32 %42, i8* %8, i32 512)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %81, %61
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%68 = load i32, i32* @EXIT_SUCCESS
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %61, %81
%71 = phi i64 [ %84, %81 ], [ %64, %61 ]
%72 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %71
store i8 0, i8* %72
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%74 = load i32, i32* @stdin
%75 = call i8* @fgets(i8* %8, i32 512, i32 %74)
%76 = icmp eq i8* %75, null
br i1 %76, label %77, label %81
77: ; preds = %70
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%79 = load i32, i32* @EXIT_SUCCESS
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %70
%82 = call i32 @strlen(i8* %8)
%83 = call i64 @write(i32 %42, i8* %8, i32 %82)
%84 = call i64 @read(i32 %42, i8* %8, i32 512)
%85 = icmp eq i64 %84, 0
br i1 %85, label %66, label %70
}