#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_in6 {
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int BUFSIZ;
scalar_t__ EOF;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ err_quit(char *, char *);
int /*<<< orphan*/ err_sys(char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int sockfd, n;
  char recvline[BUFSIZ];
  struct sockaddr_in6 servaddr;
  if (argc != 2) {
    err_quit("Usage: %s IP-address", argv[0]);
  }
  if ((sockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0)
    err_sys("socket AF_INET SOCK_STREAM error");
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin6_family = AF_INET6;
  servaddr.sin6_port = htons(13);
  if (inet_pton(AF_INET6, argv[1], &servaddr.sin6_addr) <= 0) {
    err_sys("inet_pton error for: %s\n", argv[1]);
  }
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
    err_sys("connect error");
  while ((n = read(sockfd, recvline, BUFSIZ)) > 0) {
    recvline[n] = '\0';
    if (fputs(recvline, stdout) == EOF)
      err_sys("fputs error");
  }
  if (n < 0)
    err_sys("read error");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ff <main+0x5f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe06(%rip),%rdi
call   1070 <err_quit@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1232 <main+0x92>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <inet_pton@plt>
cmp    $0x0,%rax
jg     1295 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    12be <main+0x11e>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
jmp    12c3 <main+0x123>
mov    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1321 <main+0x181>
mov    -0x40(%rbp),%rdi
movslq -0x18(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    0x2cc9(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2ce3(%rip),%rcx
cmp    (%rcx),%rax
jne    131c <main+0x17c>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
jmp    12c3 <main+0x123>
cmpl   $0x0,-0x18(%rbp)
jge    1339 <main+0x199>
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
je     11e3 <main+0x43>
mov    0x0(%r13),%rsi
lea    0xe22(%rip),%rdi
call   1070 <err_quit@plt>
mov    0x2df6(%rip),%r15
mov    (%r15),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1212 <main+0x72>
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
lea    -0x38(%rbp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,-0x30(%rbp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    (%r15),%edi
mov    0x8(%r13),%rsi
mov    %r12,%rdx
call   1090 <inet_pton@plt>
test   %rax,%rax
jg     125e <main+0xbe>
mov    0x8(%r13),%rsi
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
lea    -0x38(%rbp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
jns    1282 <main+0xe2>
lea    0xdd4(%rip),%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1080 <read@plt>
test   %eax,%eax
jle    12fc <main+0x15c>
mov    0x2d1f(%rip),%r12
mov    0x2d40(%rip),%r13
lea    0xdae(%rip),%r15
jmp    12d8 <main+0x138>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2d01(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1080 <read@plt>
test   %eax,%eax
jle    12fc <main+0x15c>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
cmp    0x0(%r13),%rax
jne    12c0 <main+0x120>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
jmp    12c0 <main+0x120>
test   %eax,%eax
jns    130e <main+0x16e>
lea    0xd62(%rip),%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [21 x i8] c"Usage: %s IP-address\00"
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [33 x i8] c"socket AF_INET SOCK_STREAM error\00"
@.str.2 = [25 x i8] c"inet_pton error for: %s\0A\00"
@.str.3 = [14 x i8] c"connect error\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.4 = [12 x i8] c"fputs error\00"
@.str.5 = [11 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 i8*
%9 = alloca i64
%10 = alloca %struct.sockaddr_in6
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @err_quit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %17, %2
%23 = load i32, i32* @AF_INET6
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = call i32 @memset(%struct.sockaddr_in6* %10, i32 0, i32 12)
%31 = load i32, i32* @AF_INET6
%32 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 2
store i32 %31, i32* %32
%33 = call i32 @htons(i32 13)
%34 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 1
store i32 %33, i32* %34
%35 = load i32, i32* @AF_INET6
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 0
%40 = call i64 @inet_pton(i32 %35, i8* %38, i32* %39)
%41 = icmp sle i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %29
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %42, %29
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%50 = call i64 @connect(i32 %48, %struct.sockaddr* %49, i32 12)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %47
br label %55
55: ; preds = %70, %54
%56 = load i32, i32* %6
%57 = load i32, i32* @BUFSIZ
%58 = call i32 @read(i32 %56, i8* %14, i32 %57)
store i32 %58, i32* %7
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %71
60: ; preds = %55
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %14, i64 %62
store i8 0, i8* %63
%64 = load i32, i32* @stdout
%65 = call i64 @fputs(i8* %14, i32 %64)
%66 = load i64, i64* @EOF
%67 = icmp eq i64 %65, %66
br i1 %67, label %68, label %70
68: ; preds = %60
%69 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %68, %60
br label %55
71: ; preds = %55
%72 = load i32, i32* %7
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %71
%75 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %76
76: ; preds = %74, %71
%77 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [21 x i8] c"Usage: %s IP-address\00"
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [33 x i8] c"socket AF_INET SOCK_STREAM error\00"
@.str.2 = [25 x i8] c"inet_pton error for: %s\0A\00"
@.str.3 = [14 x i8] c"connect error\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.4 = [12 x i8] c"fputs error\00"
@.str.5 = [11 x i8] c"read error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in6
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast %struct.sockaddr_in6* %3 to i8*
%8 = icmp eq i32 %0, 2
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @err_quit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %9, %2
%13 = load i32, i32* @AF_INET6
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = call i32 @memset(%struct.sockaddr_in6* %3, i32 0, i32 12)
%21 = load i32, i32* @AF_INET6
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 13)
%24 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET6
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 0
%29 = call i64 @inet_pton(i32 %25, i8* %27, i32* %28)
%30 = icmp slt i64 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = load i8*, i8** %26
%33 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %19
%35 = bitcast %struct.sockaddr_in6* %3 to %struct.sockaddr*
%36 = call i64 @connect(i32 %15, %struct.sockaddr* %35, i32 12)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = load i32, i32* @BUFSIZ
%42 = call i32 @read(i32 %15, i8* %6, i32 %41)
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %58
44: ; preds = %40, %54
%45 = phi i32 [ %56, %54 ], [ %42, %40 ]
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %6, i64 %46
store i8 0, i8* %47
%48 = load i32, i32* @stdout
%49 = call i64 @fputs(i8* %6, i32 %48)
%50 = load i64, i64* @EOF
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %44
%55 = load i32, i32* @BUFSIZ
%56 = call i32 @read(i32 %15, i8* %6, i32 %55)
%57 = icmp sgt i32 %56, 0
br i1 %57, label %44, label %58
58: ; preds = %54, %40
%59 = phi i32 [ %42, %40 ], [ %56, %54 ]
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %61, %58
%64 = call i32 @exit(i32 0)
unreachable
}