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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ htons(int);
char *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
void test_address() {
  struct sockaddr_in6 addr;
  char buf[1024];
  memset(&addr, 0, sizeof(addr));
  addr.sin6_family = AF_INET;
  addr.sin6_port = htons(13);
  inet_pton(AF_INET6, "0:0:0:0:0:0:0:1", &addr.sin6_addr);
  printf("addr ip:%s, port:%u\n",
         inet_ntop(AF_INET6, &addr.sin6_addr, buf, 1024),
         ntohs(addr.sin6_port));
}


x86 assembly (clang, -O0):
<test_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rdx
add    $0x4,%rdx
lea    0xe54(%rip),%rsi
call   1070 <inet_pton@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
add    $0x4,%rsi
lea    -0x410(%rbp),%rdx
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x418(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <ntohs@plt>
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_address>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    0x2e46(%rip),%rbx
mov    (%rbx),%edi
lea    0x4(%rsp),%r14
lea    0xe58(%rip),%rsi
mov    %r14,%rdx
call   1070 <inet_pton@plt>
mov    (%rbx),%edi
lea    0x10(%rsp),%rdx
mov    %r14,%rsi
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rbx
mov    (%rsp),%edi
call   1080 <ntohs@plt>
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@.str = [16 x i8] c"0:0:0:0:0:0:0:1\00"
@.str.1 = [21 x i8] c"addr ip:%s, port:%u\0A\00"
define void @test_address() {
%1 = alloca %struct.sockaddr_in6
%2 = alloca [1024 x i8]
%3 = call i32 @memset(%struct.sockaddr_in6* %1, i32 0, i32 12)
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i32 0, i32 2
store i32 %4, i32* %5
%6 = call i32 @htons(i32 13)
%7 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @AF_INET6
%9 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i32 0, i32 1
%10 = call i32 @inet_pton(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* %9)
%11 = load i32, i32* @AF_INET6
%12 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i32 0, i32 1
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = call i8* @inet_ntop(i32 %11, i32* %12, i8* %13, i32 1024)
%15 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @ntohs(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %17)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@.str = [16 x i8] c"0:0:0:0:0:0:0:1\00"
@.str.1 = [21 x i8] c"addr ip:%s, port:%u\0A\00"
define void @test_address() {
%1 = alloca %struct.sockaddr_in6
%2 = alloca [1024 x i8]
%3 = bitcast %struct.sockaddr_in6* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(%struct.sockaddr_in6* %1, i32 0, i32 12)
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 2
store i32 %6, i32* %7
%8 = call i32 @htons(i32 13)
%9 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* @AF_INET6
%11 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 1
%12 = call i32 @inet_pton(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* %11)
%13 = load i32, i32* @AF_INET6
%14 = call i8* @inet_ntop(i32 %13, i32* %11, i8* %4, i32 1024)
%15 = load i32, i32* %9
%16 = call i32 @ntohs(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %16)
ret void
}