#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 in_addr {
  int dummy;
};
struct sockaddr_in6 {
  int sin6_port;
  struct in_addr sin6_addr;
};
struct sockaddr_in {
  int sin_port;
  struct in_addr sin_addr;
};
typedef struct in_addr in6_addr;
struct addrinfo {
  char *ai_canonname;
  int ai_flags;
  int ai_family;
  int ai_socktype;
  int ai_protocol;
  int ai_addrlen;
  scalar_t__ ai_addr;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int INET6_ADDRSTRLEN;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ inet_ntop(int, struct in_addr *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
void debug_addrinfo(struct addrinfo *ai) {
  printf("\naddrinfo for %s\n", ai->ai_canonname);
  printf("ai_flag: %d, ai_family: %d, ai_socktype: %d, ai_protocol: %d "
         "ai_addrlen: %d\n",
         ai->ai_flags, ai->ai_family, ai->ai_socktype, ai->ai_protocol,
         ai->ai_addrlen);
  switch (ai->ai_family) {
  case AF_INET: {
    char ipstr[INET_ADDRSTRLEN];
    struct sockaddr_in *sockaddr_in_ptr;
    struct in_addr *in_addr_ptr;
    sockaddr_in_ptr = (struct sockaddr_in *)ai->ai_addr;
    in_addr_ptr = &(sockaddr_in_ptr->sin_addr);
    inet_ntop(ai->ai_family, in_addr_ptr, ipstr, sizeof ipstr);
    printf("IPv4: %s:%d\n", ipstr, sockaddr_in_ptr->sin_port);
  } break;
  case AF_INET6: {
    char ipstr[INET6_ADDRSTRLEN];
    struct sockaddr_in6 *sockaddr_in6_ptr;
    struct in6_addr *in6_addr_ptr;
    sockaddr_in6_ptr = (struct sockaddr_in6 *)ai->ai_addr;
    in6_addr_ptr = &(sockaddr_in6_ptr->sin6_addr);
    inet_ntop(ai->ai_family, in6_addr_ptr, ipstr, sizeof ipstr);
    printf("IPv6: %s:%d\n", ipstr, sockaddr_in6_ptr->sin6_port);
  } break;
  }
}


x86 assembly (clang, -O0):
<debug_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    0xec6(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x4d(%rbp)
call   1040 <printf@plt>
mov    -0x4d(%rbp),%al
mov    -0x8(%rbp),%rdi
mov    0x8(%rdi),%esi
mov    0xc(%rdi),%edx
mov    0x10(%rdi),%ecx
mov    0x14(%rdi),%r8d
mov    0x18(%rdi),%r9d
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x80,%eax
je     120f <debug_addrinfo+0xef>
jmp    1182 <debug_addrinfo+0x62>
mov    -0x4c(%rbp),%eax
sub    $0x81,%eax
jne    1284 <debug_addrinfo+0x164>
jmp    1195 <debug_addrinfo+0x75>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rcx
mov    0x20(%rcx),%rcx
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
add    $0x4,%rcx
mov    %rcx,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
mov    0xc(%rcx),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x58(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
jmp    1284 <debug_addrinfo+0x164>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rcx
mov    0x20(%rcx),%rcx
mov    %rcx,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
add    $0x4,%rcx
mov    %rcx,-0x48(%rbp)
mov    -0x8(%rbp),%rcx
mov    0xc(%rcx),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x60(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_addrinfo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rsi
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%esi
mov    0xc(%rbx),%edx
mov    0x10(%rbx),%ecx
mov    0x14(%rbx),%r8d
mov    0x18(%rbx),%r9d
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%eax
cmp    $0x80,%eax
je     11b4 <debug_addrinfo+0x94>
cmp    $0x81,%eax
jne    1200 <debug_addrinfo+0xe0>
mov    %rsp,%r15
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r14
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x20(%rbx),%r12
lea    0x4(%r12),%rsi
mov    0xc(%rbx),%edi
mov    %r14,%rdx
call   1030 <inet_ntop@plt>
mov    (%r12),%edx
lea    0xead(%rip),%rdi
jmp    11f3 <debug_addrinfo+0xd3>
mov    %rsp,%r15
mov    0x2e2a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r14
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x20(%rbx),%r12
lea    0x4(%r12),%rsi
mov    0xc(%rbx),%edi
mov    %r14,%rdx
call   1030 <inet_ntop@plt>
mov    (%r12),%edx
lea    0xe79(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i8*, i32, i32, i32, i32, i32, i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr }
%struct.in_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, %struct.in_addr }
%struct.in6_addr = type opaque
@.str = [18 x i8] c"\0Aaddrinfo for %s\0A\00"
@.str.1 = [77 x i8] c"ai_flag: %d, ai_family: %d, ai_socktype: %d, ai_protocol: %d ai_addrlen: %d\0A\00"
@INET_ADDRSTRLEN = global i32 0
@.str.2 = [13 x i8] c"IPv4: %s:%d\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.3 = [13 x i8] c"IPv6: %s:%d\0A\00"
define void @debug_addrinfo(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.in_addr*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.sockaddr_in6*
%10 = alloca %struct.in6_addr*
store %struct.addrinfo* %0, %struct.addrinfo** %2
%11 = load %struct.addrinfo*, %struct.addrinfo** %2
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load %struct.addrinfo*, %struct.addrinfo** %2
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load %struct.addrinfo*, %struct.addrinfo** %2
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %18, i32 0, i32 2
%20 = load i32, i32* %19
%21 = load %struct.addrinfo*, %struct.addrinfo** %2
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i32 0, i32 3
%23 = load i32, i32* %22
%24 = load %struct.addrinfo*, %struct.addrinfo** %2
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i32 0, i32 4
%26 = load i32, i32* %25
%27 = load %struct.addrinfo*, %struct.addrinfo** %2
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 5
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %20, i32 %23, i32 %26, i32 %29)
%31 = load %struct.addrinfo*, %struct.addrinfo** %2
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 2
%33 = load i32, i32* %32
switch i32 %33, label %80 [
i32 129, label %34
i32 128, label %56
]
34: ; preds = %1
%35 = load i32, i32* @INET_ADDRSTRLEN
%36 = zext i32 %35 to i64
%37 = call i8* @llvm.stacksave()
store i8* %37, i8** %3
%38 = alloca i8, i64 %36
store i64 %36, i64* %4
%39 = load %struct.addrinfo*, %struct.addrinfo** %2
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 6
%41 = load i64, i64* %40
%42 = inttoptr i64 %41 to %struct.sockaddr_in*
store %struct.sockaddr_in* %42, %struct.sockaddr_in** %5
%43 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %43, i32 0, i32 1
store %struct.in_addr* %44, %struct.in_addr** %6
%45 = load %struct.addrinfo*, %struct.addrinfo** %2
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 2
%47 = load i32, i32* %46
%48 = load %struct.in_addr*, %struct.in_addr** %6
%49 = trunc i64 %36 to i32
%50 = call i32 @inet_ntop(i32 %47, %struct.in_addr* %48, i8* %38, i32 %49)
%51 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %53)
%55 = load i8*, i8** %3
br label %80
56: ; preds = %1
%57 = load i32, i32* @INET6_ADDRSTRLEN
%58 = zext i32 %57 to i64
%59 = call i8* @llvm.stacksave()
store i8* %59, i8** %7
%60 = alloca i8, i64 %58
store i64 %58, i64* %8
%61 = load %struct.addrinfo*, %struct.addrinfo** %2
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 6
%63 = load i64, i64* %62
%64 = inttoptr i64 %63 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %64, %struct.sockaddr_in6** %9
%65 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%66 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %65, i32 0, i32 1
%67 = bitcast %struct.in_addr* %66 to %struct.in6_addr*
store %struct.in6_addr* %67, %struct.in6_addr** %10
%68 = load %struct.addrinfo*, %struct.addrinfo** %2
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 2
%70 = load i32, i32* %69
%71 = load %struct.in6_addr*, %struct.in6_addr** %10
%72 = bitcast %struct.in6_addr* %71 to %struct.in_addr*
%73 = trunc i64 %58 to i32
%74 = call i32 @inet_ntop(i32 %70, %struct.in_addr* %72, i8* %60, i32 %73)
%75 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%76 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %75, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %60, i32 %77)
%79 = load i8*, i8** %7
br label %80
80: ; preds = %1, %56, %34
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i8*, i32, i32, i32, i32, i32, i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr }
%struct.in_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, %struct.in_addr }
@.str = [18 x i8] c"\0Aaddrinfo for %s\0A\00"
@.str.1 = [77 x i8] c"ai_flag: %d, ai_family: %d, ai_socktype: %d, ai_protocol: %d ai_addrlen: %d\0A\00"
@INET_ADDRSTRLEN = global i32 0
@.str.2 = [13 x i8] c"IPv4: %s:%d\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.3 = [13 x i8] c"IPv6: %s:%d\0A\00"
define void @debug_addrinfo(%struct.addrinfo* nocapture %0) {
%2 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%3 = load i8*, i8** %2
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 2
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 3
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 4
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 5
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %8, i32 %10, i32 %12, i32 %14)
%16 = load i32, i32* %7
switch i32 %16, label %47 [
i32 129, label %17
i32 128, label %31
]
17: ; preds = %1
%18 = load i32, i32* @INET_ADDRSTRLEN
%19 = zext i32 %18 to i64
%20 = tail call i8* @llvm.stacksave()
%21 = alloca i8, i64 %19
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 6
%23 = load i64, i64* %22
%24 = inttoptr i64 %23 to %struct.sockaddr_in*
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i64 0, i32 1
%26 = load i32, i32* %7
%27 = call i32 @inet_ntop(i32 %26, %struct.in_addr* %25, i8* %21, i32 %18)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i64 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %29)
br label %45
31: ; preds = %1
%32 = load i32, i32* @INET6_ADDRSTRLEN
%33 = zext i32 %32 to i64
%34 = tail call i8* @llvm.stacksave()
%35 = alloca i8, i64 %33
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 6
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to %struct.sockaddr_in6*
%39 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %38, i64 0, i32 1
%40 = load i32, i32* %7
%41 = call i32 @inet_ntop(i32 %40, %struct.in_addr* %39, i8* %35, i32 %32)
%42 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %38, i64 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %35, i32 %43)
br label %45
45: ; preds = %17, %31
%46 = phi i8* [ %34, %31 ], [ %20, %17 ]
br label %47
47: ; preds = %45, %1
ret void
}