#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ asprintf(char **, char *, char const *, unsigned int);
int /*<<< orphan*/ assert(struct sockaddr_in6 const *);
char *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *, int);
unsigned int ntohs(int /*<<< orphan*/);
char *tow_internet6_socket_address_alloc_description(
    struct sockaddr_in6 const *socket_address) {
  assert(socket_address);
  char buffer[INET6_ADDRSTRLEN];
  char const *address =
      inet_ntop(AF_INET6, &socket_address->sin6_addr, buffer, sizeof buffer);
  if (!address)
    return NULL;
  unsigned port = ntohs(socket_address->sin6_port);
  char *description;
  asprintf(&description, "[%s]:%u", address, port);
  return description;
}


x86 assembly (clang, -O0):
<tow_internet6_socket_address_alloc_description>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e5c(%rip),%rcx
mov    (%rcx),%edi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b8 <tow_internet6_socket_address_alloc_description+0x78>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11ec <tow_internet6_socket_address_alloc_description+0xac>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%ecx
lea    -0x38(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1050 <asprintf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tow_internet6_socket_address_alloc_description>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
call   1040 <assert@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0x4(%r14),%rsi
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     11ad <tow_internet6_socket_address_alloc_description+0x6d>
mov    %rax,%rbx
mov    (%r14),%edi
call   1060 <ntohs@plt>
lea    0xe67(%rip),%rsi
lea    -0x18(%rbp),%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1050 <asprintf@plt>
mov    -0x18(%rbp),%rax
jmp    11af <tow_internet6_socket_address_alloc_description+0x6f>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
@.str = [8 x i8] c"[%s]:%u\00"
define i8* @tow_internet6_socket_address_alloc_description(%struct.sockaddr_in6* %0) {
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in6*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store %struct.sockaddr_in6* %0, %struct.sockaddr_in6** %3
%10 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %3
%11 = call i32 @assert(%struct.sockaddr_in6* %10)
%12 = load i32, i32* @INET6_ADDRSTRLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %4
%15 = alloca i8, i64 %13
store i64 %13, i64* %5
%16 = load i32, i32* @AF_INET6
%17 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %3
%18 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %17, i32 0, i32 1
%19 = trunc i64 %13 to i32
%20 = call i8* @inet_ntop(i32 %16, i32* %18, i8* %15, i32 %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %1
store i8* null, i8** %2
store i32 1, i32* %7
br label %33
24: ; preds = %1
%25 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %3
%26 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @ntohs(i32 %27)
store i32 %28, i32* %8
%29 = load i8*, i8** %6
%30 = load i32, i32* %8
%31 = call i32 @asprintf(i8** %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30)
%32 = load i8*, i8** %9
store i8* %32, i8** %2
store i32 1, i32* %7
br label %33
33: ; preds = %24, %23
%34 = load i8*, i8** %4
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
@.str = [8 x i8] c"[%s]:%u\00"
define i8* @tow_internet6_socket_address_alloc_description(%struct.sockaddr_in6* %0) {
%2 = alloca i8*
%3 = tail call i32 @assert(%struct.sockaddr_in6* %0)
%4 = load i32, i32* @INET6_ADDRSTRLEN
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = load i32, i32* @AF_INET6
%8 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %0, i64 0, i32 1
%9 = call i8* @inet_ntop(i32 %7, i32* %8, i8* %6, i32 %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %1
%12 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %0, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @ntohs(i32 %13)
%15 = bitcast i8** %2 to i8*
%16 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %14)
%17 = load i8*, i8** %2
br label %18
18: ; preds = %1, %11
%19 = phi i8* [ %17, %11 ], [ null, %1 ]
ret i8* %19
}