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

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in6 *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int htons(int);
char *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *, int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ panic(char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int count, char *strings[]) {
  int sd, portnum;
  struct sockaddr_in6 addr;
  if (count == 2)
    portnum = atoi(strings[1]);
  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, "0::0", &addr.sin6_addr) == 0)
    panic("inet_pton");
  if (bind(sd, (struct sockaddr *)&addr, sizeof(addr)) != 0)
    panic("bind6");
  if (listen(sd, 15) != 0)
    panic("listen6");
  while (1) {
    int sent, size = sizeof(addr);
    int client;
    char line[100];
    client = accept(sd, (struct sockaddr *)&addr, &size);
    fprintf(stderr, "Connected: %s port=%d\n",
            inet_ntop(AF_INET6, &addr.sin6_addr, line, sizeof(line)),
            addr.sin6_port);
    do {
      sent = send(client, line, recv(client, line, sizeof(line), 0), 0);
      fprintf(stderr, "server=%s", line);
    } while (sent > 0 && strcmp(line, "bye\n") != 0);
    close(client);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1228 <main+0x38>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    122f <main+0x3f>
movl   $0x270f,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    126e <main+0x7e>
lea    0xd97(%rip),%rdi
call   1070 <panic@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rdx
add    $0x4,%rdx
lea    0xd6a(%rip),%rsi
call   10b0 <inet_pton@plt>
cmp    $0x0,%rax
jne    12b8 <main+0xc8>
lea    0xd59(%rip),%rdi
call   1070 <panic@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
je     12df <main+0xef>
lea    0xd3c(%rip),%rdi
call   1070 <panic@plt>
mov    -0x14(%rbp),%edi
mov    $0xf,%esi
call   10c0 <listen@plt>
cmp    $0x0,%rax
je     1302 <main+0x112>
lea    0xd1f(%rip),%rdi
call   1070 <panic@plt>
jmp    1307 <main+0x117>
movl   $0xc,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x34(%rbp)
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
lea    -0xa0(%rbp),%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
mov    -0xa4(%rbp),%edi
mov    %rax,%rdx
mov    -0x28(%rbp),%ecx
lea    0xcbf(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x34(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rdx
lea    0xc72(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0xb5(%rbp)
jle    1402 <main+0x212>
lea    -0xa0(%rbp),%rdi
lea    0xc55(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xb5(%rbp)
mov    -0xb5(%rbp),%al
test   $0x1,%al
jne    136c <main+0x17c>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
jmp    1307 <main+0x117>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    $0x270f,%ebx
cmp    $0x2,%edi
jne    1216 <main+0x26>
mov    0x8(%rsi),%rdi
call   1100 <atoi@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jns    1252 <main+0x62>
lea    0xdb3(%rip),%rdi
call   1070 <panic@plt>
mov    0x2d87(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x0(%rbp),%edi
lea    0x14(%rsp),%rdx
lea    0xd8d(%rip),%rsi
call   10b0 <inet_pton@plt>
test   %rax,%rax
jne    1290 <main+0xa0>
lea    0xd81(%rip),%rdi
call   1070 <panic@plt>
lea    0x10(%rsp),%rsi
mov    0xc(%rsp),%edi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
je     12b4 <main+0xc4>
lea    0xd67(%rip),%rdi
call   1070 <panic@plt>
mov    0xc(%rsp),%edi
mov    $0xf,%esi
call   10c0 <listen@plt>
test   %rax,%rax
je     12d3 <main+0xe3>
lea    0xd4e(%rip),%rdi
call   1070 <panic@plt>
mov    0x2cf6(%rip),%r13
lea    0x20(%rsp),%rbx
lea    0xd55(%rip),%r14
lea    0xd58(%rip),%r15
jmp    12f8 <main+0x108>
nop
mov    %r12d,%edi
call   1080 <close@plt>
movl   $0xc,0x1c(%rsp)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
lea    0x1c(%rsp),%rdx
call   10f0 <accept@plt>
mov    %eax,%r12d
mov    0x0(%r13),%ebp
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
lea    0x14(%rsp),%rsi
mov    %rbx,%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
mov    0x10(%rsp),%ecx
mov    %ebp,%edi
lea    0xce2(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,%ebp
mov    0x0(%r13),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
test   %ebp,%ebp
jle    12f0 <main+0x100>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1350 <main+0x160>
jmp    12f0 <main+0x100>

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { 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 = [5 x i8] c"0::0\00"
@.str.2 = [10 x i8] c"inet_pton\00"
@.str.3 = [6 x i8] c"bind6\00"
@.str.4 = [8 x i8] c"listen6\00"
@stderr = global i32 0
@.str.5 = [23 x i8] c"Connected: %s port=%d\0A\00"
@.str.6 = [10 x i8] c"server=%s\00"
@.str.7 = [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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
br label %21
20: ; preds = %2
store i32 9999, i32* %7
br label %21
21: ; preds = %20, %15
%22 = call i32 @bzero(%struct.sockaddr_in6* %8, i32 12)
%23 = load i32, i32* @PF_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 = %21
%28 = call i32 @panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = load i32, i32* @AF_INET6
%31 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* %7
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* @AF_INET6
%36 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 1
%37 = call i64 @inet_pton(i32 %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = call i32 @panic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %29
%42 = load i32, i32* %6
%43 = bitcast %struct.sockaddr_in6* %8 to %struct.sockaddr*
%44 = call i64 @bind(i32 %42, %struct.sockaddr* %43, i32 12)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @panic(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
%49 = load i32, i32* %6
%50 = call i64 @listen(i32 %49, i32 15)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @panic(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
br label %55
55: ; preds = %54, %86
store i32 12, i32* %10
%56 = load i32, i32* %6
%57 = bitcast %struct.sockaddr_in6* %8 to %struct.sockaddr*
%58 = call i32 @accept(i32 %56, %struct.sockaddr* %57, i32* %10)
store i32 %58, i32* %11
%59 = load i32, i32* @stderr
%60 = load i32, i32* @AF_INET6
%61 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 1
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%63 = call i8* @inet_ntop(i32 %60, i32* %61, i8* %62, i32 100)
%64 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %63, i32 %65)
br label %67
67: ; preds = %84, %55
%68 = load i32, i32* %11
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%70 = load i32, i32* %11
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%72 = call i32 @recv(i32 %70, i8* %71, i32 100, i32 0)
%73 = call i32 @send(i32 %68, i8* %69, i32 %72, i32 0)
store i32 %73, i32* %9
%74 = load i32, i32* @stderr
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%76 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %75)
br label %77
77: ; preds = %67
%78 = load i32, i32* %9
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %77
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%82 = call i64 @strcmp(i8* %81, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%83 = icmp ne i64 %82, 0
br label %84
84: ; preds = %80, %77
%85 = phi i1 [ false, %77 ], [ %83, %80 ]
br i1 %85, label %67, label %86
86: ; preds = %84
%87 = load i32, i32* %11
%88 = call i32 @close(i32 %87)
br label %55
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { 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 = [5 x i8] c"0::0\00"
@.str.2 = [10 x i8] c"inet_pton\00"
@.str.3 = [6 x i8] c"bind6\00"
@.str.4 = [8 x i8] c"listen6\00"
@stderr = global i32 0
@.str.5 = [23 x i8] c"Connected: %s port=%d\0A\00"
@.str.6 = [10 x i8] c"server=%s\00"
@.str.7 = [5 x i8] c"bye\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in6
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = bitcast %struct.sockaddr_in6* %3 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%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 0
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET6
%27 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 1
%28 = call i64 @inet_pton(i32 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @panic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %21
%33 = bitcast %struct.sockaddr_in6* %3 to %struct.sockaddr*
%34 = call i64 @bind(i32 %17, %struct.sockaddr* %33, i32 12)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %32
%37 = call i32 @panic(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = call i64 @listen(i32 %17, i32 15)
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call i32 @panic(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = bitcast i32* %4 to i8*
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
br label %46
46: ; preds = %62, %43
store i32 12, i32* %4
%47 = call i32 @accept(i32 %17, %struct.sockaddr* %33, i32* %4)
%48 = load i32, i32* @stderr
%49 = load i32, i32* @AF_INET6
%50 = call i8* @inet_ntop(i32 %49, i32* %27, i8* %45, i32 100)
%51 = load i32, i32* %25
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %50, i32 %51)
br label %53
53: ; preds = %59, %46
%54 = call i32 @recv(i32 %47, i8* %45, i32 100, i32 0)
%55 = call i32 @send(i32 %47, i8* %45, i32 %54, i32 0)
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %45)
%58 = icmp sgt i32 %55, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %53
62: ; preds = %53, %59
%63 = call i32 @close(i32 %47)
br label %46
}