#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  TYPE_1__ *ai_addr;
  int /*<<< orphan*/ ai_addrlen;
};
typedef int in_port_t;
typedef int /*<<< orphan*/ iaddr6;
typedef int /*<<< orphan*/ iaddr4;
typedef int /*<<< orphan*/ hbuf;
struct TYPE_2__ {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int INET6_ADDRSTRLEN;
int INET_ADDRSTRLEN;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NAMEREQD;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ getnameinfo(TYPE_1__ *, int /*<<< orphan*/, char *, int,
                               int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/);
char *inet_ntop(int const, int /*<<< orphan*/ *, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char const *, int);
void print_addrinfo(struct addrinfo *rp) {
  in_port_t iport;
  char hbuf[NI_MAXHOST];
  const char *iaddr;
  char iaddr4[INET_ADDRSTRLEN];
  char iaddr6[INET6_ADDRSTRLEN];
  struct sockaddr_in *sa4;
  struct sockaddr_in6 *sa6;
  iport = 0;
  assert(rp != 0);
  if (!getnameinfo(rp->ai_addr, rp->ai_addrlen, hbuf, sizeof(hbuf), 0, 0,
                   NI_NAMEREQD)) {
    switch (rp->ai_addr->sa_family) {
    case AF_INET:
      sa4 = (struct sockaddr_in *)rp->ai_addr;
      iaddr = inet_ntop(AF_INET, &sa4->sin_addr, iaddr4, sizeof(iaddr4));
      iport = ntohs(sa4->sin_port);
      break;
    case AF_INET6:
      sa6 = (struct sockaddr_in6 *)rp->ai_addr;
      iaddr = inet_ntop(AF_INET6, &sa6->sin6_addr, iaddr6, sizeof(iaddr6));
      iport = ntohs(sa6->sin6_port);
      break;
    }
    printf("Trying %s(%s):%d\n", hbuf, iaddr, iport);
  }
}


x86 assembly (clang, -O0):
<print_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x78(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x68(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%esi
mov    %eax,%ecx
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %r9d,%r8d
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
cmp    $0x0,%eax
jne    12f7 <print_addrinfo+0x1a7>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
sub    $0x80,%eax
je     12a7 <print_addrinfo+0x157>
jmp    1256 <print_addrinfo+0x106>
mov    -0x7c(%rbp),%eax
sub    $0x81,%eax
jne    12e0 <print_addrinfo+0x190>
jmp    1269 <print_addrinfo+0x119>
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rcx,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
mov    $0x81,%edi
call   1030 <inet_ntop@plt>
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohs@plt>
mov    %eax,-0xc(%rbp)
jmp    12e0 <print_addrinfo+0x190>
mov    -0x60(%rbp),%rdx
mov    -0x68(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rcx,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
mov    $0x80,%edi
call   1030 <inet_ntop@plt>
mov    %rax,-0x28(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohs@plt>
mov    %eax,-0xc(%rbp)
mov    -0x58(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xd0e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_addrinfo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
mov    0x2e5d(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%r14
mov    %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,-0x38(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
mov    %rax,-0x30(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1060 <assert@plt>
mov    (%r12),%rdi
mov    0x8(%r12),%esi
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %r14,%rdx
mov    %r13d,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    1250 <print_addrinfo+0x100>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%r12),%r12
lea    0x4(%r12),%rsi
cmpl   $0x81,(%r12)
jne    1221 <print_addrinfo+0xd1>
mov    $0x81,%edi
mov    %rbx,%rdx
jmp    122b <print_addrinfo+0xdb>
mov    $0x80,%edi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rbx
mov    (%r12),%edi
call   1070 <ntohs@plt>
lea    0xdbd(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1040 <printf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { %struct.TYPE_2__*, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_in6 = type { i32, i32 }
@NI_MAXHOST = global i32 0
@INET_ADDRSTRLEN = global i32 0
@INET6_ADDRSTRLEN = global i32 0
@NI_NAMEREQD = global i32 0
@.str = [18 x i8] c"Trying %s(%s):%d\0A\00"
define void @print_addrinfo(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca %struct.sockaddr_in*
%10 = alloca %struct.sockaddr_in6*
store %struct.addrinfo* %0, %struct.addrinfo** %2
%11 = load i32, i32* @NI_MAXHOST
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = load i32, i32* @INET_ADDRSTRLEN
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
store i64 %16, i64* %7
%18 = load i32, i32* @INET6_ADDRSTRLEN
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %8
store i32 0, i32* %3
%21 = load %struct.addrinfo*, %struct.addrinfo** %2
%22 = icmp ne %struct.addrinfo* %21, null
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load %struct.addrinfo*, %struct.addrinfo** %2
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i32 0, i32 0
%27 = load %struct.TYPE_2__*, %struct.TYPE_2__** %26
%28 = load %struct.addrinfo*, %struct.addrinfo** %2
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = trunc i64 %12 to i32
%32 = load i32, i32* @NI_NAMEREQD
%33 = call i32 @getnameinfo(%struct.TYPE_2__* %27, i32 %30, i8* %14, i32 %31, i32 0, i32 0, i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %71, label %35
35: ; preds = %1
%36 = load %struct.addrinfo*, %struct.addrinfo** %2
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 0
%38 = load %struct.TYPE_2__*, %struct.TYPE_2__** %37
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
%40 = load i32, i32* %39
switch i32 %40, label %67 [
i32 129, label %41
i32 128, label %54
]
41: ; preds = %35
%42 = load %struct.addrinfo*, %struct.addrinfo** %2
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 0
%44 = load %struct.TYPE_2__*, %struct.TYPE_2__** %43
%45 = bitcast %struct.TYPE_2__* %44 to %struct.sockaddr_in*
store %struct.sockaddr_in* %45, %struct.sockaddr_in** %9
%46 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %46, i32 0, i32 1
%48 = trunc i64 %16 to i32
%49 = call i8* @inet_ntop(i32 129, i32* %47, i8* %17, i32 %48)
store i8* %49, i8** %6
%50 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @ntohs(i32 %52)
store i32 %53, i32* %3
br label %67
54: ; preds = %35
%55 = load %struct.addrinfo*, %struct.addrinfo** %2
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 0
%57 = load %struct.TYPE_2__*, %struct.TYPE_2__** %56
%58 = bitcast %struct.TYPE_2__* %57 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %58, %struct.sockaddr_in6** %10
%59 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %10
%60 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %59, i32 0, i32 1
%61 = trunc i64 %19 to i32
%62 = call i8* @inet_ntop(i32 128, i32* %60, i8* %20, i32 %61)
store i8* %62, i8** %6
%63 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %10
%64 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 @ntohs(i32 %65)
store i32 %66, i32* %3
br label %67
67: ; preds = %35, %54, %41
%68 = load i8*, i8** %6
%69 = load i32, i32* %3
%70 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %68, i32 %69)
br label %71
71: ; preds = %67, %1
%72 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.TYPE_2__*, i32 }
%struct.TYPE_2__ = type { i32 }
@NI_MAXHOST = global i32 0
@INET_ADDRSTRLEN = global i32 0
@INET6_ADDRSTRLEN = global i32 0
@NI_NAMEREQD = global i32 0
@.str = [18 x i8] c"Trying %s(%s):%d\0A\00"
define void @print_addrinfo(%struct.addrinfo* %0) {
%2 = load i32, i32* @NI_MAXHOST
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = load i32, i32* @INET_ADDRSTRLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i32, i32* @INET6_ADDRSTRLEN
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = icmp ne %struct.addrinfo* %0, null
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%15 = load %struct.TYPE_2__*, %struct.TYPE_2__** %14
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 1
%17 = load i32, i32* %16
%18 = load i32, i32* @NI_NAMEREQD
%19 = call i32 @getnameinfo(%struct.TYPE_2__* %15, i32 %17, i8* %4, i32 %2, i32 0, i32 0, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %1
%22 = load %struct.TYPE_2__*, %struct.TYPE_2__** %14
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 0, i32 0
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 129
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 1, i32 0
br i1 %25, label %27, label %29
27: ; preds = %21
%28 = call i8* @inet_ntop(i32 129, i32* %26, i8* %7, i32 %5)
br label %31
29: ; preds = %21
%30 = call i8* @inet_ntop(i32 128, i32* %26, i8* %10, i32 %8)
br label %31
31: ; preds = %29, %27
%32 = phi i8* [ %30, %29 ], [ %28, %27 ]
%33 = load i32, i32* %23
%34 = call i32 @ntohs(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %32, i32 %34)
br label %36
36: ; preds = %31, %1
ret void
}