#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_port;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_addr;
};
typedef int /*<<< orphan*/ straddr;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int INET6_ADDRSTRLEN;
char *inet_ntoa(int /*<<< orphan*/);
char *inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void printAddress(struct addrinfo *addr) {
  if (addr->ai_family == AF_INET) {
    struct sockaddr_in *v4Addr = (struct sockaddr_in *)addr->ai_addr;
    printf("UDP socket: %s:%d", inet_ntoa(v4Addr->sin_addr),
           ntohs(v4Addr->sin_port));
    printf("\r\n");
  } else if (addr->ai_family == AF_INET6) {
    char straddr[INET6_ADDRSTRLEN];
    struct sockaddr_in6 *v6Addr = (struct sockaddr_in6 *)addr->ai_addr;
    printf("UDP socket: %s:%d",
           inet_ntop(AF_INET6, &v6Addr->sin6_addr, straddr, sizeof(straddr)),
           ntohs(v6Addr->sin6_port));
    printf("\r\n");
  }
}


x86 assembly (clang, -O0):
<printAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%rax
jne    11b1 <printAddress+0x71>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1252 <printAddress+0x112>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
jne    124d <printAddress+0x10d>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%rdi
mov    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1252 <printAddress+0x112>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAddress>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rcx
mov    0x2e7c(%rip),%rax
cmp    (%rax),%rcx
jne    11a8 <printAddress+0x58>
mov    0x8(%rdi),%rbx
mov    0x4(%rbx),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%r14
mov    (%rbx),%edi
call   1070 <ntohs@plt>
lea    0xe7a(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe79(%rip),%rdi
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    0x2e29(%rip),%rax
cmp    (%rax),%rcx
jne    1210 <printAddress+0xc0>
mov    %rsp,%r14
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%ecx
mov    %rsp,%rdx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
sub    %rsi,%rdx
mov    %rdx,%rsp
mov    0x8(%rdi),%rbx
mov    (%rax),%rdi
lea    0x4(%rbx),%rsi
call   1030 <inet_ntop@plt>
mov    %rax,%r15
mov    (%rbx),%edi
call   1070 <ntohs@plt>
lea    0xe0b(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0a(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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