#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_in {
  int sin_family;
  int sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  int ai_family;
  int ai_socktype;
  int ai_protocol;
  int ai_addrlen;
  char *ai_canonname;
  struct addrinfo *ai_next;
  scalar_t__ ai_addr;
};

/* Variables and functions */
int AF_INET;
int AF_INET6;
int IPPROTO_TCP;
int IPPROTO_UDP;
int SOCK_DGRAM;
int SOCK_STREAM;
char *inet_ntop(int, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
void print_addrinfo(struct addrinfo *info) {
  if (info != NULL) {
    printf("\nai_family  : %3d \t(AF_INET:%d, AF_INET6:%d)\n", info->ai_family,
           AF_INET, AF_INET6);
    printf("ai_socktype: %3d \t(SOCK_DGRAM:%d, SOCK_STREAM:%d)\n",
           info->ai_socktype, SOCK_DGRAM, SOCK_STREAM);
    printf("ai_protocol: %3d \t(IPPROTO_UDP:%d, IPPROTO_TCP:%d)\n",
           info->ai_protocol, IPPROTO_UDP, IPPROTO_TCP);
    printf("ai_addrlen: %d\n", info->ai_addrlen);
    if (info->ai_canonname != NULL)
      printf("ai_canonname: %s\n", info->ai_canonname);
    printf("ai_addr(struct sockaddr_in):\n");
    struct sockaddr_in *saddr = (struct sockaddr_in *)info->ai_addr;
    char ipv4[16];
    printf("\tsin_family: %d, sin_port:%d, sin_addr:%s\n", saddr->sin_family,
           saddr->sin_port,
           inet_ntop(saddr->sin_family, &saddr->sin_addr, ipv4, 16));
    print_addrinfo(info->ai_next);
  }
}


x86 assembly (clang, -O0):
<print_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1262 <print_addrinfo+0x132>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
mov    0x2e73(%rip),%rax
mov    (%rax),%ecx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%esi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    0x2e35(%rip),%rax
mov    (%rax),%ecx
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     11f5 <print_addrinfo+0xc5>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
lea    -0x20(%rbp),%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <print_addrinfo@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_addrinfo>:
test   %rdi,%rdi
je     1234 <print_addrinfo+0xf4>
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    (%rdi),%esi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x4(%rbx),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    0x2e37(%rip),%rax
mov    (%rax),%ecx
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    0x2e34(%rip),%rax
mov    (%rax),%ecx
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rbx),%esi
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%rsi
test   %rsi,%rsi
je     11e4 <print_addrinfo+0xa4>
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
mov    0x20(%rbx),%rsi
mov    (%rsi),%ebp
mov    0x4(%rsi),%r14d
add    $0x8,%rsi
mov    %rsp,%rdx
mov    %ebp,%edi
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
lea    0xea3(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%rdi
call   1050 <print_addrinfo@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i8*, %struct.addrinfo*, i64 }
%struct.sockaddr_in = type { i32, i32, i32 }
@.str = [46 x i8] c"\0Aai_family : %3d \09(AF_INET:%d, AF_INET6:%d)\0A\00"
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@.str.1 = [51 x i8] c"ai_socktype: %3d \09(SOCK_DGRAM:%d, SOCK_STREAM:%d)\0A\00"
@SOCK_DGRAM = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [52 x i8] c"ai_protocol: %3d \09(IPPROTO_UDP:%d, IPPROTO_TCP:%d)\0A\00"
@IPPROTO_UDP = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [16 x i8] c"ai_addrlen: %d\0A\00"
@.str.4 = [18 x i8] c"ai_canonname: %s\0A\00"
@.str.5 = [30 x i8] c"ai_addr(struct sockaddr_in):\0A\00"
@.str.6 = [43 x i8] c"\09sin_family: %d, sin_port:%d, sin_addr:%s\0A\00"
define void @print_addrinfo(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.sockaddr_in*
%4 = alloca [16 x i8]
store %struct.addrinfo* %0, %struct.addrinfo** %2
%5 = load %struct.addrinfo*, %struct.addrinfo** %2
%6 = icmp ne %struct.addrinfo* %5, null
br i1 %6, label %7, label %62
7: ; preds = %1
%8 = load %struct.addrinfo*, %struct.addrinfo** %2
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @AF_INET6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11, i32 %12)
%14 = load %struct.addrinfo*, %struct.addrinfo** %2
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load i32, i32* @SOCK_DGRAM
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = load %struct.addrinfo*, %struct.addrinfo** %2
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = load i32, i32* @IPPROTO_UDP
%24 = load i32, i32* @IPPROTO_TCP
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %23, i32 %24)
%26 = load %struct.addrinfo*, %struct.addrinfo** %2
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 3
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load %struct.addrinfo*, %struct.addrinfo** %2
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 4
%32 = load i8*, i8** %31
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %39
34: ; preds = %7
%35 = load %struct.addrinfo*, %struct.addrinfo** %2
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 4
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %34, %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%41 = load %struct.addrinfo*, %struct.addrinfo** %2
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 6
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to %struct.sockaddr_in*
store %struct.sockaddr_in* %44, %struct.sockaddr_in** %3
%45 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %48, i32 0, i32 1
%50 = load i32, i32* %49
%51 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %54, i32 0, i32 2
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%57 = call i8* @inet_ntop(i32 %53, i32* %55, i8* %56, i32 16)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %47, i32 %50, i8* %57)
%59 = load %struct.addrinfo*, %struct.addrinfo** %2
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 5
%61 = load %struct.addrinfo*, %struct.addrinfo** %60
br label %62
62: ; preds = %39, %1
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i8*, %struct.addrinfo*, i64 }
%struct.sockaddr_in = type { i32, i32, i32 }
@.str = [46 x i8] c"\0Aai_family : %3d \09(AF_INET:%d, AF_INET6:%d)\0A\00"
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@.str.1 = [51 x i8] c"ai_socktype: %3d \09(SOCK_DGRAM:%d, SOCK_STREAM:%d)\0A\00"
@SOCK_DGRAM = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [52 x i8] c"ai_protocol: %3d \09(IPPROTO_UDP:%d, IPPROTO_TCP:%d)\0A\00"
@IPPROTO_UDP = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [16 x i8] c"ai_addrlen: %d\0A\00"
@.str.4 = [18 x i8] c"ai_canonname: %s\0A\00"
@.str.6 = [43 x i8] c"\09sin_family: %d, sin_port:%d, sin_addr:%s\0A\00"
@str = [29 x i8] c"ai_addr(struct sockaddr_in):\00"
define void @print_addrinfo(%struct.addrinfo* %0) {
%2 = alloca [16 x i8]
%3 = icmp eq %struct.addrinfo* %0, null
br i1 %3, label %43, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @AF_INET6
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7, i32 %8)
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 1
%11 = load i32, i32* %10
%12 = load i32, i32* @SOCK_DGRAM
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12, i32 %13)
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 2
%16 = load i32, i32* %15
%17 = load i32, i32* @IPPROTO_UDP
%18 = load i32, i32* @IPPROTO_TCP
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 3
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 4
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %4
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %28
28: ; preds = %26, %4
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 6
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to %struct.sockaddr_in*
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i64 0, i32 0
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i64 0, i32 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i64 0, i32 2
%39 = call i8* @inet_ntop(i32 %35, i32* %38, i8* %33, i32 16)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %35, i32 %37, i8* %39)
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 5
%42 = load %struct.addrinfo*, %struct.addrinfo** %41
br label %43
43: ; preds = %28, %1
ret void
}