#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 {
  scalar_t__ ai_addr;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memcpy(struct sockaddr_in6 *, struct sockaddr_in6 *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, short);
int _rtp_addressv6(struct sockaddr_in6 *address, short port) {
  struct addrinfo hints;
  struct addrinfo *result;
  char portname[8];
  memset(&hints, 0, sizeof(hints));
  sprintf(&(portname[0]), "%hu", port);
  if (getaddrinfo("::1", portname, &hints, &result) == 0) {
    memcpy(address, (struct sockaddr_in6 *)result->ai_addr,
           sizeof(struct sockaddr_in6));
    freeaddrinfo(result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<_rtp_addressv6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
lea    -0x28(%rbp),%rdi
lea    0xe82(%rip),%rsi
movswl -0xa(%rbp),%edx
call   1050 <sprintf@plt>
lea    -0x28(%rbp),%rsi
lea    0xe72(%rip),%rdi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <getaddrinfo@plt>
cmp    $0x0,%rax
jne    11c7 <_rtp_addressv6+0x77>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_rtp_addressv6>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
lea    0xe86(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <sprintf@plt>
lea    0xe74(%rip),%rdi
mov    %rsp,%rcx
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <getaddrinfo@plt>
test   %rax,%rax
jne    11c0 <_rtp_addressv6+0x70>
mov    (%rsp),%rax
mov    (%rax),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    (%rsp),%rdi
call   1070 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.addrinfo = type { i64 }
@.str = [4 x i8] c"%hu\00"
@.str.1 = [4 x i8] c"::1\00"
define i32 @_rtp_addressv6(%struct.sockaddr_in6* %0, i16 signext %1) {
%3 = alloca %struct.sockaddr_in6*
%4 = alloca i16
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca [8 x i8]
store %struct.sockaddr_in6* %0, %struct.sockaddr_in6** %3
store i16 %1, i16* %4
%8 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 8)
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%10 = load i16, i16* %4
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 signext %10)
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%13 = call i64 @getaddrinfo(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12, %struct.addrinfo* %5, %struct.addrinfo** %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %3
%17 = load %struct.addrinfo*, %struct.addrinfo** %6
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to %struct.sockaddr_in6*
%21 = call i32 @memcpy(%struct.sockaddr_in6* %16, %struct.sockaddr_in6* %20, i32 4)
%22 = load %struct.addrinfo*, %struct.addrinfo** %6
%23 = call i32 @freeaddrinfo(%struct.addrinfo* %22)
br label %24
24: ; preds = %15, %2
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.addrinfo = type { i64 }
@.str = [4 x i8] c"%hu\00"
@.str.1 = [4 x i8] c"::1\00"
define i32 @_rtp_addressv6(%struct.sockaddr_in6* %0, i16 signext %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [8 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 8)
%10 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 signext %1)
%11 = call i64 @getaddrinfo(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8, %struct.addrinfo* %3, %struct.addrinfo** %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load %struct.addrinfo*, %struct.addrinfo** %4
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i64 0, i32 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to %struct.sockaddr_in6*
%18 = call i32 @memcpy(%struct.sockaddr_in6* %0, %struct.sockaddr_in6* %17, i32 4)
%19 = load %struct.addrinfo*, %struct.addrinfo** %4
%20 = call i32 @freeaddrinfo(%struct.addrinfo* %19)
br label %21
21: ; preds = %13, %2
ret i32 0
}