#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 dummy;
};
struct addrinfo {
  int ai_protocol;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ *ai_addr;
  int /*<<< orphan*/ *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  scalar_t__ ai_flags;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char const *gai_strerror(int);
int getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memcpy(struct sockaddr_in6 *, struct sockaddr_in6 *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
const char *real_address(const char *address, struct sockaddr_in6 *rval) {
  struct addrinfo hints;
  struct addrinfo *result;
  int s;
  if (rval == NULL)
    return ("rval can't be NULL.\n");
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET6;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = 17;
  hints.ai_flags = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  s = getaddrinfo(address, NULL, &hints, &result);
  if (s != 0)
    return (gai_strerror(s));
  struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)result->ai_addr;
  memcpy(rval, saddr, result->ai_addrlen);
  freeaddrinfo(result);
  return (NULL);
}


x86 assembly (clang, -O0):
<real_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <real_address+0x2b>
lea    0xe8e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122e <real_address+0xde>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0x11,-0x48(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     11fd <real_address+0xad>
mov    -0x54(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    %rax,-0x8(%rbp)
jmp    122e <real_address+0xde>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_address>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
test   %rsi,%rsi
je     11c6 <real_address+0x76>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
movl   $0x11,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movups %xmm0,0x28(%rsp)
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1060 <getaddrinfo@plt>
test   %eax,%eax
je     11cf <real_address+0x7f>
mov    %eax,%edi
call   1030 <gai_strerror@plt>
jmp    11ef <real_address+0x9f>
lea    0xe33(%rip),%rax
jmp    11ef <real_address+0x9f>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
mov    0x4(%rax),%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
mov    0x8(%rsp),%rdi
call   1070 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.addrinfo = type { i32, i32, i32*, i32*, i32*, i64, i32, i32 }
@.str = [21 x i8] c"rval can't be NULL.\0A\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
define i8* @real_address(i8* %0, %struct.sockaddr_in6* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in6*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca i32
%9 = alloca %struct.sockaddr_in6*
store i8* %0, i8** %4
store %struct.sockaddr_in6* %1, %struct.sockaddr_in6** %5
%10 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%11 = icmp eq %struct.sockaddr_in6* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %3
br label %44
13: ; preds = %2
%14 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 48)
%15 = load i32, i32* @AF_INET6
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 7
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_DGRAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i32 17, i32* %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store i64 0, i64* %20
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32* null, i32** %21
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i32* null, i32** %22
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32* null, i32** %23
%24 = load i8*, i8** %4
%25 = call i32 @getaddrinfo(i8* %24, i32* null, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %13
%29 = load i32, i32* %8
%30 = call i8* @gai_strerror(i32 %29)
store i8* %30, i8** %3
br label %44
31: ; preds = %13
%32 = load %struct.addrinfo*, %struct.addrinfo** %7
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i32 0, i32 2
%34 = load i32*, i32** %33
%35 = bitcast i32* %34 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %35, %struct.sockaddr_in6** %9
%36 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%37 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%38 = load %struct.addrinfo*, %struct.addrinfo** %7
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = call i32 @memcpy(%struct.sockaddr_in6* %36, %struct.sockaddr_in6* %37, i32 %40)
%42 = load %struct.addrinfo*, %struct.addrinfo** %7
%43 = call i32 @freeaddrinfo(%struct.addrinfo* %42)
store i8* null, i8** %3
br label %44
44: ; preds = %31, %28, %12
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.addrinfo = type { i32, i32, i32*, i32*, i32*, i64, i32, i32 }
@.str = [21 x i8] c"rval can't be NULL.\0A\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
define i8* @real_address(i8* %0, %struct.sockaddr_in6* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = icmp eq %struct.sockaddr_in6* %1, null
br i1 %7, label %31, label %8
8: ; preds = %2
%9 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 48)
%10 = load i32, i32* @AF_INET6
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 7
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_DGRAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 17, i32* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
%16 = bitcast i32** %15 to i8*
%17 = call i32 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %8
%20 = call i8* @gai_strerror(i32 %17)
br label %31
21: ; preds = %8
%22 = load %struct.addrinfo*, %struct.addrinfo** %4
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 2
%24 = bitcast i32** %23 to %struct.sockaddr_in6**
%25 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %24
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 @memcpy(%struct.sockaddr_in6* %1, %struct.sockaddr_in6* %25, i32 %27)
%29 = load %struct.addrinfo*, %struct.addrinfo** %4
%30 = call i32 @freeaddrinfo(%struct.addrinfo* %29)
br label %31
31: ; preds = %2, %21, %19
%32 = phi i8* [ %20, %19 ], [ null, %21 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %2 ]
ret i8* %32
}