#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_storage {
  scalar_t__ ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
scalar_t__ AF_INET;
int AF_INET6;
scalar_t__ EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fputs(char *, int /*<<< orphan*/);
scalar_t__ getpeername(int, struct sockaddr *, int *);
char *inet_ntop(int /*<<< orphan*/, void const *, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int tcp_connect(char *, char *);
int main(int argc, char **argv) {
  int sockfd, n;
  char recvline[4096 + 1];
  if (argc != 3) {
    fprintf(stderr, "usage: %s <hostname/IP> <service/port#>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((sockfd = tcp_connect(argv[1], argv[2])) == -1) {
    fprintf(stderr, "tcp_connect() error");
    exit(EXIT_FAILURE);
  }
  {
    struct sockaddr_storage cliaddr;
    socklen_t len = sizeof(struct sockaddr_storage);
    if (getpeername(sockfd, (struct sockaddr *)&cliaddr, &len) < 0) {
      perror("getpeername() error");
      exit(EXIT_FAILURE);
    }
    if (cliaddr.ss_family == AF_INET) {
      struct sockaddr_in *sockp = (struct sockaddr_in *)&cliaddr;
      char IPstr[INET_ADDRSTRLEN];
      printf("tcp_connect() connected to %s:%d\n",
             inet_ntop(sockp->sin_family, (const void *)&sockp->sin_addr, IPstr,
                       INET_ADDRSTRLEN),
             ntohs(sockp->sin_port));
    } else if (cliaddr.ss_family == AF_INET6) {
      struct sockaddr_in6 *sockp = (struct sockaddr_in6 *)&cliaddr;
      char IPstr[46];
      printf("connected to %s:%d\n",
             inet_ntop(sockp->sin6_family, (const void *)&sockp->sin6_addr,
                       IPstr, 46),
             ntohs(sockp->sin6_port));
    } else {
      fprintf(stderr,
              "getpeername() error, AF_INET:%d, AF_INET6:%d, "
              "sockp->sin_family:%d\n",
              AF_INET6, AF_INET6, cliaddr.ss_family);
    }
  }
  while ((n = read(sockfd, recvline, 4096)) > 0) {
    recvline[n] = 0;
    if (fputs(recvline, stdout) == EOF) {
      fprintf(stderr, "fputs() error");
      exit(EXIT_FAILURE);
    }
  }
  if (n < 0) {
    fprintf(stderr, "read() error");
    exit(EXIT_FAILURE);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1090,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ef <main+0x4f>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <tcp_connect@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1235 <main+0x95>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
movl   $0x8,-0x102c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1028(%rbp),%rsi
lea    -0x102c(%rbp),%rdx
call   1050 <getpeername@plt>
cmp    $0x0,%rax
jge    1279 <main+0xd9>
lea    0xdd7(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x1028(%rbp),%rax
mov    0x2d61(%rip),%rcx
cmp    (%rcx),%rax
jne    1328 <main+0x188>
lea    -0x1028(%rbp),%rax
mov    %rax,-0x1038(%rbp)
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x1040(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rax,-0x1048(%rbp)
mov    -0x1038(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x1038(%rbp),%rsi
add    $0x4,%rsi
mov    0x2cd8(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x1088(%rbp)
mov    -0x1038(%rbp),%rax
mov    (%rax),%edi
call   10a0 <ntohs@plt>
mov    -0x1088(%rbp),%rsi
mov    %eax,%edx
lea    0xd3d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1040(%rbp),%rax
mov    %rax,%rsp
jmp    13da <main+0x23a>
mov    -0x1028(%rbp),%rax
mov    0x2ca2(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jne    13a5 <main+0x205>
lea    -0x1028(%rbp),%rax
mov    %rax,-0x1050(%rbp)
mov    -0x1050(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x1050(%rbp),%rsi
add    $0x4,%rsi
lea    -0x1080(%rbp),%rdx
mov    $0x2e,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x1090(%rbp)
mov    -0x1050(%rbp),%rax
mov    (%rax),%edi
call   10a0 <ntohs@plt>
mov    -0x1090(%rbp),%rsi
mov    %eax,%edx
lea    0xcc4(%rip),%rdi
call   1060 <printf@plt>
jmp    13d5 <main+0x235>
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
mov    0x2c23(%rip),%rax
mov    (%rax),%edx
mov    0x2c1a(%rip),%rax
mov    (%rax),%ecx
mov    -0x1028(%rbp),%r8
lea    0xca5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    13da <main+0x23a>
jmp    13df <main+0x23f>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    145a <main+0x2ba>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rdi
mov    0x2b97(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
mov    0x2bb9(%rip),%rcx
cmp    (%rcx),%rax
jne    1455 <main+0x2b5>
mov    0x2b91(%rip),%rax
mov    (%rax),%edi
lea    0xc77(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    13df <main+0x23f>
cmpl   $0x0,-0x18(%rbp)
jge    1489 <main+0x2e9>
mov    0x2b5d(%rip),%rax
mov    (%rax),%edi
lea    0xc51(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
cmp    $0x3,%edi
jne    1335 <main+0x195>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1040 <tcp_connect@plt>
cmp    $0xffffffff,%eax
je     1351 <main+0x1b1>
mov    %eax,%r14d
movl   $0x8,-0x2c(%rbp)
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %eax,%edi
call   1050 <getpeername@plt>
test   %rax,%rax
js     1363 <main+0x1c3>
mov    -0x28(%rbp),%r8
mov    0x2dea(%rip),%rax
cmp    (%rax),%r8
jne    124f <main+0xaf>
mov    %rsp,%r15
mov    0x2db3(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    -0x20(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rbx
mov    -0x28(%rbp),%edi
call   10a0 <ntohs@plt>
lea    0xe11(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <printf@plt>
mov    %r15,%rsp
jmp    12ad <main+0x10d>
mov    0x2d82(%rip),%rax
movslq (%rax),%rcx
cmp    %rcx,%r8
jne    1294 <main+0xf4>
mov    -0x20(%rbp),%edi
lea    -0x24(%rbp),%rsi
lea    -0x1030(%rbp),%rdx
mov    $0x2e,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rbx
mov    -0x28(%rbp),%edi
call   10a0 <ntohs@plt>
lea    0xdd7(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <printf@plt>
jmp    12ad <main+0x10d>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    -0x1030(%rbp),%rbx
mov    0x2cf5(%rip),%r15
mov    0x2d1e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1324 <main+0x184>
mov    %eax,%eax
movb   $0x0,-0x1030(%rbp,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1070 <fputs@plt>
cmp    (%r12),%rax
jne    12d0 <main+0x130>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
js     1371 <main+0x1d1>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xcb8(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1316 <main+0x176>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
lea    0xcc8(%rip),%rsi
jmp    130f <main+0x16f>
lea    0xcd3(%rip),%rdi
call   10b0 <perror@plt>
jmp    1316 <main+0x176>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
jmp    130f <main+0x16f>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"usage: %s <hostname/IP> <service/port#>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"tcp_connect() error\00"
@.str.2 = [20 x i8] c"getpeername() error\00"
@AF_INET = global i64 0
@INET_ADDRSTRLEN = global i32 0
@.str.3 = [34 x i8] c"tcp_connect() connected to %s:%d\0A\00"
@AF_INET6 = global i32 0
@.str.4 = [20 x i8] c"connected to %s:%d\0A\00"
@.str.5 = [68 x i8] c"getpeername() error, AF_INET:%d, AF_INET6:%d, sockp->sin_family:%d\0A\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.6 = [14 x i8] c"fputs() error\00"
@.str.7 = [13 x i8] c"read() error\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 [4097 x i8]
%9 = alloca %struct.sockaddr_storage
%10 = alloca i32
%11 = alloca %struct.sockaddr_in*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca %struct.sockaddr_in6*
%15 = alloca [46 x i8]
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 %26
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @tcp_connect(i8* %29, i8* %32)
store i32 %33, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %26
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %26
store i32 8, i32* %10
%41 = load i32, i32* %6
%42 = bitcast %struct.sockaddr_storage* %9 to %struct.sockaddr*
%43 = call i64 @getpeername(i32 %41, %struct.sockaddr* %42, i32* %10)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %40
%50 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %9, i32 0, i32 0
%51 = load i64, i64* %50
%52 = load i64, i64* @AF_INET
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %74
54: ; preds = %49
%55 = bitcast %struct.sockaddr_storage* %9 to %struct.sockaddr_in*
store %struct.sockaddr_in* %55, %struct.sockaddr_in** %11
%56 = load i32, i32* @INET_ADDRSTRLEN
%57 = zext i32 %56 to i64
%58 = call i8* @llvm.stacksave()
store i8* %58, i8** %12
%59 = alloca i8, i64 %57
store i64 %57, i64* %13
%60 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %60, i32 0, i32 2
%62 = load i32, i32* %61
%63 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %63, i32 0, i32 1
%65 = bitcast i32* %64 to i8*
%66 = load i32, i32* @INET_ADDRSTRLEN
%67 = call i8* @inet_ntop(i32 %62, i8* %65, i8* %59, i32 %66)
%68 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 @ntohs(i32 %70)
%72 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %67, i32 %71)
%73 = load i8*, i8** %12
br label %103
74: ; preds = %49
%75 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %9, i32 0, i32 0
%76 = load i64, i64* %75
%77 = load i32, i32* @AF_INET6
%78 = sext i32 %77 to i64
%79 = icmp eq i64 %76, %78
br i1 %79, label %80, label %95
80: ; preds = %74
%81 = bitcast %struct.sockaddr_storage* %9 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %81, %struct.sockaddr_in6** %14
%82 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %14
%83 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %82, i32 0, i32 2
%84 = load i32, i32* %83
%85 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %14
%86 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %85, i32 0, i32 1
%87 = bitcast i32* %86 to i8*
%88 = getelementptr inbounds [46 x i8], [46 x i8]* %15, i64 0, i64 0
%89 = call i8* @inet_ntop(i32 %84, i8* %87, i8* %88, i32 46)
%90 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %14
%91 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %90, i32 0, i32 0
%92 = load i32, i32* %91
%93 = call i32 @ntohs(i32 %92)
%94 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %89, i32 %93)
br label %102
95: ; preds = %74
%96 = load i32, i32* @stderr
%97 = load i32, i32* @AF_INET6
%98 = load i32, i32* @AF_INET6
%99 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %9, i32 0, i32 0
%100 = load i64, i64* %99
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0), i32 %97, i32 %98, i64 %100)
br label %102
102: ; preds = %95, %80
br label %103
103: ; preds = %102, %54
br label %104
104: ; preds = %123, %103
%105 = load i32, i32* %6
%106 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%107 = call i32 @read(i32 %105, i8* %106, i32 4096)
store i32 %107, i32* %7
%108 = icmp sgt i32 %107, 0
br i1 %108, label %109, label %124
109: ; preds = %104
%110 = load i32, i32* %7
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 %111
store i8 0, i8* %112
%113 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%114 = load i32, i32* @stdout
%115 = call i64 @fputs(i8* %113, i32 %114)
%116 = load i64, i64* @EOF
%117 = icmp eq i64 %115, %116
br i1 %117, label %118, label %123
118: ; preds = %109
%119 = load i32, i32* @stderr
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%121 = load i32, i32* @EXIT_FAILURE
%122 = call i32 @exit(i32 %121)
unreachable
123: ; preds = %109
br label %104
124: ; preds = %104
%125 = load i32, i32* %7
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %132
127: ; preds = %124
%128 = load i32, i32* @stderr
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%130 = load i32, i32* @EXIT_FAILURE
%131 = call i32 @exit(i32 %130)
unreachable
132: ; preds = %124
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr_in6 = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [41 x i8] c"usage: %s <hostname/IP> <service/port#>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"tcp_connect() error\00"
@.str.2 = [20 x i8] c"getpeername() error\00"
@AF_INET = global i64 0
@INET_ADDRSTRLEN = global i32 0
@.str.3 = [34 x i8] c"tcp_connect() connected to %s:%d\0A\00"
@AF_INET6 = global i32 0
@.str.4 = [20 x i8] c"connected to %s:%d\0A\00"
@.str.5 = [68 x i8] c"getpeername() error, AF_INET:%d, AF_INET6:%d, sockp->sin_family:%d\0A\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.6 = [14 x i8] c"fputs() error\00"
@.str.7 = [13 x i8] c"read() error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4097 x i8]
%4 = alloca %struct.sockaddr_storage
%5 = alloca i32
%6 = alloca [46 x i8]
%7 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 0
%8 = icmp eq i32 %0, 3
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([41 x i8], [41 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 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @tcp_connect(i8* %17, i8* %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %15
%28 = bitcast %struct.sockaddr_storage* %4 to i8*
%29 = bitcast i32* %5 to i8*
store i32 8, i32* %5
%30 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
%31 = call i64 @getpeername(i32 %20, %struct.sockaddr* %30, i32* %5)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %27
%38 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i64 0, i32 0
%39 = load i64, i64* %38
%40 = load i64, i64* @AF_INET
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %59
42: ; preds = %37
%43 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr_in*
%44 = load i32, i32* @INET_ADDRSTRLEN
%45 = zext i32 %44 to i64
%46 = call i8* @llvm.stacksave()
%47 = alloca i8, i64 %45
%48 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i64 1
%49 = bitcast %struct.sockaddr_storage* %48 to i32*
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %43, i64 0, i32 1
%52 = bitcast i32* %51 to i8*
%53 = load i32, i32* @INET_ADDRSTRLEN
%54 = call i8* @inet_ntop(i32 %50, i8* %52, i8* %47, i32 %53)
%55 = bitcast %struct.sockaddr_storage* %4 to i32*
%56 = load i32, i32* %55
%57 = call i32 @ntohs(i32 %56)
%58 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %54, i32 %57)
br label %79
59: ; preds = %37
%60 = load i32, i32* @AF_INET6
%61 = sext i32 %60 to i64
%62 = icmp eq i64 %39, %61
br i1 %62, label %63, label %76
63: ; preds = %59
%64 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr_in6*
%65 = getelementptr inbounds [46 x i8], [46 x i8]* %6, i64 0, i64 0
%66 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i64 1
%67 = bitcast %struct.sockaddr_storage* %66 to i32*
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %64, i64 0, i32 1
%70 = bitcast i32* %69 to i8*
%71 = call i8* @inet_ntop(i32 %68, i8* %70, i8* %65, i32 46)
%72 = bitcast %struct.sockaddr_storage* %4 to i32*
%73 = load i32, i32* %72
%74 = call i32 @ntohs(i32 %73)
%75 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %71, i32 %74)
br label %79
76: ; preds = %59
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0), i32 %60, i32 %60, i64 %39)
br label %79
79: ; preds = %63, %76, %42
br label %80
80: ; preds = %83, %79
%81 = call i32 @read(i32 %20, i8* %7, i32 4096)
%82 = icmp sgt i32 %81, 0
br i1 %82, label %83, label %95
83: ; preds = %80
%84 = zext i32 %81 to i64
%85 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 %84
store i8 0, i8* %85
%86 = load i32, i32* @stdout
%87 = call i64 @fputs(i8* %7, i32 %86)
%88 = load i64, i64* @EOF
%89 = icmp eq i64 %87, %88
br i1 %89, label %90, label %80
90: ; preds = %83
%91 = load i32, i32* @stderr
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%93 = load i32, i32* @EXIT_FAILURE
%94 = call i32 @exit(i32 %93)
unreachable
95: ; preds = %80
%96 = icmp slt i32 %81, 0
br i1 %96, label %97, label %102
97: ; preds = %95
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%100 = load i32, i32* @EXIT_FAILURE
%101 = call i32 @exit(i32 %100)
unreachable
102: ; preds = %95
ret i32 0
}