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

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ stderr;
void print_ip(struct addrinfo *res) {
  char ipstr[INET6_ADDRSTRLEN];
  if (res->ai_family == AF_INET) {
    struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr;
    inet_ntop(AF_INET, &(ipv4->sin_addr), ipstr, sizeof(ipstr));
  } else {
    struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)res->ai_addr;
    inet_ntop(AF_INET6, &(ipv6->sin6_addr), ipstr, sizeof(ipstr));
  }
  fprintf(stderr, "%s\n", ipstr);
}


x86 assembly (clang, -O0):
<print_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%rax
jne    11a1 <print_ip+0x81>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x2e52(%rip),%rcx
mov    (%rcx),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
jmp    11ca <print_ip+0xaa>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x2e1c(%rip),%rcx
mov    (%rcx),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x30(%rbp),%rdx
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ip>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rdi,%rax
mov    0x2eb8(%rip),%rcx
mov    (%rcx),%ecx
mov    %rsp,%rbx
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%rbx
mov    %rbx,%rsp
mov    (%rdi),%rdi
mov    0x8(%rax),%rsi
mov    0x2e8c(%rip),%rax
cmp    (%rax),%rdi
je     1163 <print_ip+0x43>
mov    0x2e78(%rip),%rax
mov    (%rax),%rdi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i64 0
@AF_INET6 = global i64 0
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @print_ip(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.sockaddr_in6*
store %struct.addrinfo* %0, %struct.addrinfo** %2
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = load %struct.addrinfo*, %struct.addrinfo** %2
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* @AF_INET
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %1
%17 = load %struct.addrinfo*, %struct.addrinfo** %2
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i32 0, i32 1
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to %struct.sockaddr_in*
store %struct.sockaddr_in* %20, %struct.sockaddr_in** %5
%21 = load i64, i64* @AF_INET
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
%24 = trunc i64 %8 to i32
%25 = call i32 @inet_ntop(i64 %21, i32* %23, i8* %10, i32 %24)
br label %36
26: ; preds = %1
%27 = load %struct.addrinfo*, %struct.addrinfo** %2
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %30, %struct.sockaddr_in6** %6
%31 = load i64, i64* @AF_INET6
%32 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %6
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %32, i32 0, i32 0
%34 = trunc i64 %8 to i32
%35 = call i32 @inet_ntop(i64 %31, i32* %33, i8* %10, i32 %34)
br label %36
36: ; preds = %26, %16
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%39 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i64 0
@AF_INET6 = global i64 0
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @print_ip(%struct.addrinfo* nocapture %0) {
%2 = load i32, i32* @INET6_ADDRSTRLEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %6, %7
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 1
%10 = load i64, i64* %9
br i1 %8, label %11, label %15
11: ; preds = %1
%12 = inttoptr i64 %10 to %struct.sockaddr_in*
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i64 0, i32 0
%14 = call i32 @inet_ntop(i64 %6, i32* %13, i8* %4, i32 %2)
br label %20
15: ; preds = %1
%16 = inttoptr i64 %10 to %struct.sockaddr_in6*
%17 = load i64, i64* @AF_INET6
%18 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %16, i64 0, i32 0
%19 = call i32 @inet_ntop(i64 %17, i32* %18, i8* %4, i32 %2)
br label %20
20: ; preds = %15, %11
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
ret void
}