#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;
};
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in6 *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr_in6 *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ panic(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, scalar_t__, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int main(int count, char *strings[]) {
  int sd, portnum;
  struct sockaddr_in6 addr;
  char line[100];
  if (count == 3)
    portnum = atoi(strings[2]);
  else
    portnum = 9999;
  bzero(&addr, sizeof(addr));
  if ((sd = socket(PF_INET6, SOCK_STREAM, 0)) < 0)
    panic("socket");
  addr.sin6_family = AF_INET6;
  addr.sin6_port = htons(portnum);
  if (inet_pton(AF_INET6, strings[1], &addr.sin6_addr) == 0)
    panic("inet_aton");
  if (connect(sd, &addr, sizeof(addr)) != 0)
    panic("connect6");
  do {
    fgets(line, sizeof(line), stdin);
    send(sd, line, strlen(line) + 1, 0);
    recv(sd, line, sizeof(line), 0);
    printf("client=%s", line);
  } while (strcmp(line, "bye\n") != 0);
  close(sd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1218 <main+0x38>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    121f <main+0x3f>
movl   $0x270f,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    125e <main+0x7e>
lea    0xda7(%rip),%rdi
call   1080 <panic@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x28(%rbp),%rdx
call   10c0 <inet_pton@plt>
cmp    $0x0,%rax
jne    12a5 <main+0xc5>
lea    0xd67(%rip),%rdi
call   1080 <panic@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
je     12cc <main+0xec>
lea    0xd4a(%rip),%rdi
call   1080 <panic@plt>
jmp    12d1 <main+0xf1>
lea    -0x90(%rbp),%rdi
mov    0x2d01(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x90(%rbp),%rsi
lea    0xccd(%rip),%rdi
call   1070 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xcc4(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    12d1 <main+0xf1>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r14
mov    $0x270f,%r15d
cmp    $0x3,%edi
jne    1209 <main+0x29>
mov    0x10(%r14),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    %rsp,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1241 <main+0x61>
lea    0xdc4(%rip),%rdi
call   1080 <panic@plt>
mov    0x2d90(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
mov    0x8(%r14),%rsi
mov    %rsp,%rdx
call   10c0 <inet_pton@plt>
test   %rax,%rax
jne    1279 <main+0x99>
lea    0xd93(%rip),%rdi
call   1080 <panic@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
je     1299 <main+0xb9>
lea    0xd7d(%rip),%rdi
call   1080 <panic@plt>
mov    0x2d40(%rip),%r12
lea    0x10(%rsp),%rbx
lea    0xd6e(%rip),%r14
lea    0xd71(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
jne    12c0 <main+0xe0>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
@PF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET6 = global i32 0
@.str.1 = [10 x i8] c"inet_aton\00"
@.str.2 = [9 x i8] c"connect6\00"
@stdin = global i32 0
@.str.3 = [10 x i8] c"client=%s\00"
@.str.4 = [5 x i8] c"bye\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 %struct.sockaddr_in6
%9 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
br label %18
17: ; preds = %2
store i32 9999, i32* %7
br label %18
18: ; preds = %17, %12
%19 = call i32 @bzero(%struct.sockaddr_in6* %8, i32 12)
%20 = load i32, i32* @PF_INET6
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %18
%27 = load i32, i32* @AF_INET6
%28 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* %7
%30 = call i32 @htons(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 1
store i32 %30, i32* %31
%32 = load i32, i32* @AF_INET6
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 0
%37 = call i64 @inet_pton(i32 %32, i8* %35, i32* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %26
%40 = call i32 @panic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %26
%42 = load i32, i32* %6
%43 = call i64 @connect(i32 %42, %struct.sockaddr_in6* %8, i32 12)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @panic(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
br label %48
48: ; preds = %63, %47
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%50 = load i32, i32* @stdin
%51 = call i32 @fgets(i8* %49, i32 100, i32 %50)
%52 = load i32, i32* %6
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%55 = call i64 @strlen(i8* %54)
%56 = add nsw i64 %55, 1
%57 = call i32 @send(i32 %52, i8* %53, i64 %56, i32 0)
%58 = load i32, i32* %6
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%60 = call i32 @recv(i32 %58, i8* %59, i32 100, i32 0)
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%62 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %48
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%65 = call i64 @strcmp(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%66 = icmp ne i64 %65, 0
br i1 %66, label %48, label %67
67: ; preds = %63
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
@PF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET6 = global i32 0
@.str.1 = [10 x i8] c"inet_aton\00"
@.str.2 = [9 x i8] c"connect6\00"
@stdin = global i32 0
@.str.3 = [10 x i8] c"client=%s\00"
@.str.4 = [5 x i8] c"bye\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in6
%4 = alloca [100 x i8]
%5 = bitcast %struct.sockaddr_in6* %3 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %2, %8
%13 = phi i32 [ %11, %8 ], [ 9999, %2 ]
%14 = call i32 @bzero(%struct.sockaddr_in6* %3, i32 12)
%15 = load i32, i32* @PF_INET6
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = tail call i32 @panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %12
%22 = load i32, i32* @AF_INET6
%23 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 %13)
%25 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET6
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 0
%30 = call i64 @inet_pton(i32 %26, i8* %28, i32* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @panic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = call i64 @connect(i32 %17, %struct.sockaddr_in6* %3, i32 12)
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = call i32 @panic(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
br label %40
40: ; preds = %39, %40
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %6, i32 100, i32 %41)
%43 = call i64 @strlen(i8* %6)
%44 = add nsw i64 %43, 1
%45 = call i32 @send(i32 %17, i8* %6, i64 %44, i32 0)
%46 = call i32 @recv(i32 %17, i8* %6, i32 100, i32 0)
%47 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%48 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %40
50: ; preds = %40
%51 = call i32 @close(i32 %17)
ret i32 0
}