#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;
};

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


x86 assembly (clang, -O0):
<print_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     121f <print_addr+0xff>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
jne    11b8 <print_addr+0x98>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe5f(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d7 <print_addr+0xb7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe40(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x18(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x48(%rbp),%rdx
mov    -0x20(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1142 <print_addr+0x22>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_addr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
test   %r15,%r15
je     11c7 <print_addr+0x97>
lea    0xeb1(%rip),%r14
nopl   0x0(%rax)
mov    %rsp,%r13
mov    0x2e7e(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%r15),%rdi
mov    0x8(%r15),%rsi
mov    0x2e52(%rip),%rax
cmp    (%rax),%rdi
lea    0xe6d(%rip),%r12
lea    0xe61(%rip),%rax
cmove  %rax,%r12
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rsp
mov    0x10(%r15),%r15
test   %r15,%r15
jne    1160 <print_addr+0x30>
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 }
@.str = [14 x i8] c"IP addresses\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i64 0
@.str.1 = [5 x i8] c"IPv4\00"
@.str.2 = [5 x i8] c"IPv6\00"
@.str.3 = [10 x i8] c" %s: %s\0A\00"
define void @print_addr(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.addrinfo*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.sockaddr_in*
%9 = alloca %struct.sockaddr_in6*
store %struct.addrinfo* %0, %struct.addrinfo** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%11 = load %struct.addrinfo*, %struct.addrinfo** %2
store %struct.addrinfo* %11, %struct.addrinfo** %3
br label %12
12: ; preds = %51, %1
%13 = load %struct.addrinfo*, %struct.addrinfo** %3
%14 = icmp ne %struct.addrinfo* %13, null
br i1 %14, label %15, label %55
15: ; preds = %12
%16 = load i32, i32* @INET6_ADDRSTRLEN
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %6
%19 = alloca i8, i64 %17
store i64 %17, i64* %7
%20 = load %struct.addrinfo*, %struct.addrinfo** %3
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* @AF_INET
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %15
%26 = load %struct.addrinfo*, %struct.addrinfo** %3
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 1
%28 = load i64, i64* %27
%29 = inttoptr i64 %28 to %struct.sockaddr_in*
store %struct.sockaddr_in* %29, %struct.sockaddr_in** %8
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 0
%32 = bitcast i32* %31 to i8*
store i8* %32, i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %41
33: ; preds = %15
%34 = load %struct.addrinfo*, %struct.addrinfo** %3
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 1
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %37, %struct.sockaddr_in6** %9
%38 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%39 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %38, i32 0, i32 0
%40 = bitcast i32* %39 to i8*
store i8* %40, i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %41
41: ; preds = %33, %25
%42 = load %struct.addrinfo*, %struct.addrinfo** %3
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = load i8*, i8** %4
%46 = trunc i64 %17 to i32
%47 = call i32 @inet_ntop(i64 %44, i8* %45, i8* %19, i32 %46)
%48 = load i8*, i8** %5
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %19)
%50 = load i8*, i8** %6
br label %51
51: ; preds = %41
%52 = load %struct.addrinfo*, %struct.addrinfo** %3
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 2
%54 = load %struct.addrinfo*, %struct.addrinfo** %53
store %struct.addrinfo* %54, %struct.addrinfo** %3
br label %12
55: ; preds = %12
ret void
}

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