#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;
  struct addrinfo *ai_next;
};
typedef int /*<<< orphan*/ ipstr;

/* Variables and functions */
scalar_t__ AF_INET;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ inet_ntop(scalar_t__, void *, char *, int);
int /*<<< orphan*/ printf(char *, int, char *, char *);
void print_addrinfo(struct addrinfo *input) {
  int addr_i = 0;
  for (struct addrinfo *p = input; p != NULL; p = p->ai_next) {
    char *ipver;
    void *addr;
    if (p->ai_family == AF_INET) {
      ipver = "IPv4";
      struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
      addr = &(ipv4->sin_addr);
    } else {
      ipver = "IPv6";
      struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
      addr = &(ipv6->sin6_addr);
    }
    char ipstr[INET6_ADDRSTRLEN];
    inet_ntop(p->ai_family, addr, ipstr, sizeof(ipstr));
    printf("%2d. %s: %s\n", ++addr_i, ipver, ipstr);
  }
}


x86 assembly (clang, -O0):
<print_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1213 <print_addrinfo+0xf3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <print_addrinfo+0x61>
lea    0xe9c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11a0 <print_addrinfo+0x80>
lea    0xe7d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x50(%rbp),%rcx
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
mov    -0x20(%rbp),%rdx
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    113b <print_addrinfo+0x1b>
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
push   %rax
test   %rdi,%rdi
je     11b5 <print_addrinfo+0x95>
mov    %rdi,%r13
mov    $0x1,%r14d
mov    %rsp,%r15
mov    0x0(%r13),%rax
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%rax
mov    0x8(%r13),%rsi
lea    0xea9(%rip),%r12
lea    0xe9d(%rip),%rax
cmove  %rax,%r12
mov    0x2e7a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x0(%r13),%rdi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
lea    0xe73(%rip),%rdi
mov    %r14d,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
mov    %r15,%rsp
mov    0x10(%r13),%r13
add    $0x1,%r14d
test   %r13,%r13
jne    1140 <print_addrinfo+0x20>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64, %struct.addrinfo* }
@AF_INET = global i64 0
@.str = [5 x i8] c"IPv4\00"
@.str.1 = [5 x i8] c"IPv6\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.2 = [13 x i8] c"%2d. %s: %s\0A\00"
define void @print_addrinfo(%struct.addrinfo* %0) {
%2 = icmp eq %struct.addrinfo* %0, null
br i1 %2, label %3, label %4
3: ; preds = %4, %1
ret void
4: ; preds = %1, %4
%5 = phi i32 [ %21, %4 ], [ 0, %1 ]
%6 = phi %struct.addrinfo* [ %24, %4 ], [ %0, %1 ]
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @AF_INET
%10 = icmp eq i64 %8, %9
%11 = select i1 %10, 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)
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 1
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to i8*
%15 = load i32, i32* @INET6_ADDRSTRLEN
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = load i64, i64* %7
%20 = call i32 @inet_ntop(i64 %19, i8* %14, i8* %18, i32 %15)
%21 = add nuw nsw i32 %5, 1
%22 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %21, i8* %11, i8* %18)
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 2
%24 = load %struct.addrinfo*, %struct.addrinfo** %23
%25 = icmp eq %struct.addrinfo* %24, null
br i1 %25, label %3, label %4
}