#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_storage {
  int dummy;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int INET6_ADDRSTRLEN;
char *inet_sastos(struct sockaddr_storage const *, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, char *, int);
void print_addr(const char *str, const struct sockaddr_storage *addr) {
  char buf[INET6_ADDRSTRLEN];
  printf("%s is %s %d\n", str, inet_sastos(addr, buf, sizeof(buf)),
         ntohs(((struct sockaddr_in6 *)(addr))->sin6_port));
}


x86 assembly (clang, -O0):
<print_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
mov    %rcx,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
call   1050 <inet_sastos@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %eax,%ecx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_addr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rsi
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
mov    %rbx,%rdi
call   1050 <inet_sastos@plt>
mov    %rax,%r15
mov    (%rbx),%edi
call   1040 <ntohs@plt>
lea    0xe8a(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <printf@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [13 x i8] c"%s is %s %d\0A\00"
define void @print_addr(i8* %0, %struct.sockaddr_storage* %1) {
%3 = alloca i8*
%4 = alloca %struct.sockaddr_storage*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %4
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i8, i64 %8
store i64 %8, i64* %6
%11 = load i8*, i8** %3
%12 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%13 = trunc i64 %8 to i32
%14 = call i8* @inet_sastos(%struct.sockaddr_storage* %12, i8* %10, i32 %13)
%15 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%16 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr_in6*
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @ntohs(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %14, i32 %19)
%21 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [13 x i8] c"%s is %s %d\0A\00"
define void @print_addr(i8* %0, %struct.sockaddr_storage* %1) {
%3 = load i32, i32* @INET6_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i8* @inet_sastos(%struct.sockaddr_storage* %1, i8* %5, i32 %3)
%7 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @ntohs(i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %6, i32 %9)
ret void
}