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

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                              int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ sysWarn(char *);
void printSocketAddress(struct sockaddr_in6 addr) {
  char IP[INET6_ADDRSTRLEN];
  in_port_t port = ntohs(addr.sin6_port);
  if (inet_ntop(AF_INET6, &addr.sin6_addr, IP, sizeof(IP)) == NULL) {
    sysWarn("failed to get address");
    return;
  }
  fprintf(stdout, "address: [%s]:%d\n", IP, port);
}


x86 assembly (clang, -O0):
<printSocketAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x28(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <ntohs@plt>
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,-0x1c(%rbp)
mov    0x2e48(%rip),%rcx
mov    (%rcx),%edi
lea    -0x8(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    11c7 <printSocketAddress+0x87>
lea    0xe4a(%rip),%rdi
call   1040 <sysWarn@plt>
movl   $0x1,-0x20(%rbp)
jmp    11ea <printSocketAddress+0xaa>
mov    -0x30(%rbp),%rdx
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%ecx
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printSocketAddress>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,-0x20(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
shr    $0x20,%rdi
call   1060 <ntohs@plt>
mov    %eax,%r14d
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
mov    %rbx,%rdx
mov    %r15d,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     11b2 <printSocketAddress+0x72>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1050 <fprintf@plt>
jmp    11be <printSocketAddress+0x7e>
lea    0xe47(%rip),%rdi
call   1040 <sysWarn@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
@.str = [22 x i8] c"failed to get address\00"
@stdout = global i32 0
@.str.1 = [18 x i8] c"address: [%s]:%d\0A\00"
define void @printSocketAddress(i64 %0) {
%2 = alloca %struct.sockaddr_in6
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in6* %2 to i64*
store i64 %0, i64* %7
%8 = load i32, i32* @INET6_ADDRSTRLEN
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %2, i32 0, i32 1
%13 = load i32, i32* %12
%14 = call i32 @ntohs(i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* @AF_INET6
%16 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %2, i32 0, i32 0
%17 = trunc i64 %9 to i32
%18 = call i32* @inet_ntop(i32 %15, i32* %16, i8* %11, i32 %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = call i32 @sysWarn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %26
22: ; preds = %1
%23 = load i32, i32* @stdout
%24 = load i32, i32* %5
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %24)
store i32 0, i32* %6
br label %26
26: ; preds = %22, %20
%27 = load i8*, i8** %3
%28 = load i32, i32* %6
switch i32 %28, label %30 [
i32 0, label %29
i32 1, label %29
]
29: ; preds = %26, %26
ret void
30: ; preds = %26
unreachable
}

LLVM IR (-O2):
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
@.str = [22 x i8] c"failed to get address\00"
@stdout = global i32 0
@.str.1 = [18 x i8] c"address: [%s]:%d\0A\00"
define void @printSocketAddress(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i32, i32* @INET6_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = lshr i64 %0, 32
%7 = trunc i64 %6 to i32
%8 = tail call i32 @ntohs(i32 %7)
%9 = load i32, i32* @AF_INET6
%10 = bitcast i64* %2 to i32*
%11 = call i32* @inet_ntop(i32 %9, i32* %10, i8* %5, i32 %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @sysWarn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %18
15: ; preds = %1
%16 = load i32, i32* @stdout
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 %8)
br label %18
18: ; preds = %15, %13
ret void
}