#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;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ inet_ntop(scalar_t__, void *, char *, int);
int /*<<< orphan*/ stderr;
void print_address(struct addrinfo *address_info) {
  char *type;
  void *address;
  char ip[INET6_ADDRSTRLEN];
  if (address_info->ai_family == AF_INET) {
    struct sockaddr_in *ipv4 = (struct sockaddr_in *)address_info->ai_addr;
    address = &(ipv4->sin_addr);
    type = "IPv4";
  } else {
    struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)address_info->ai_addr;
    address = &(ipv6->sin6_addr);
    type = "IPv6";
  }
  inet_ntop(address_info->ai_family, address, ip, sizeof ip);
  fprintf(stderr, "%s: %s ... ", type, ip);
}


x86 assembly (clang, -O0):
<print_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <print_address+0x77>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe72(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b6 <print_address+0x96>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x18(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x40(%rbp),%rcx
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe22(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_address>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2eba(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e95(%rip),%rdx
mov    (%rdi),%rax
mov    0x8(%rdi),%rsi
cmp    (%rdx),%rax
lea    0xea4(%rip),%rdx
lea    0xea2(%rip),%r14
cmove  %rdx,%r14
mov    %rax,%rdi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i64 0
@.str = [5 x i8] c"IPv4\00"
@.str.1 = [5 x i8] c"IPv6\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"%s: %s ... \00"
define void @print_address(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.sockaddr_in*
%8 = alloca %struct.sockaddr_in6*
store %struct.addrinfo* %0, %struct.addrinfo** %2
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load %struct.addrinfo*, %struct.addrinfo** %2
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %13, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @AF_INET
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %1
%19 = load %struct.addrinfo*, %struct.addrinfo** %2
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to %struct.sockaddr_in*
store %struct.sockaddr_in* %22, %struct.sockaddr_in** %7
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %23, i32 0, i32 0
%25 = bitcast i32* %24 to i8*
store i8* %25, i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
br label %34
26: ; preds = %1
%27 = load %struct.addrinfo*, %struct.addrinfo** %2
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %30, %struct.sockaddr_in6** %8
%31 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %8
%32 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %31, i32 0, i32 0
%33 = bitcast i32* %32 to i8*
store i8* %33, i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %34
34: ; preds = %26, %18
%35 = load %struct.addrinfo*, %struct.addrinfo** %2
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = load i8*, i8** %4
%39 = trunc i64 %10 to i32
%40 = call i32 @inet_ntop(i64 %37, i8* %38, i8* %12, i32 %39)
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %3
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %12)
%44 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i64 0
@.str = [5 x i8] c"IPv4\00"
@.str.1 = [5 x i8] c"IPv6\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"%s: %s ... \00"
define void @print_address(%struct.addrinfo* nocapture %0) {
%2 = load i32, i32* @INET6_ADDRSTRLEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %6, %7
%9 = select i1 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 1
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to i8*
%13 = call i32 @inet_ntop(i64 %6, i8* %12, i8* %4, i32 %2)
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %4)
ret void
}