#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 sockaddr {
  int sa_family;
};
typedef int in_port_t;
typedef int /*<<< orphan*/ addrString;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ *inet_ntop(int, void *, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ sysError(char *, char *);
void printAddrInfo(struct sockaddr *address) {
  if (address == NULL)
    sysError("address", "failed to get address pointer");
  void *addrPointer;
  char addrString[INET6_ADDRSTRLEN];
  in_port_t port;
  switch (address->sa_family) {
  case AF_INET:
    addrPointer = &((struct sockaddr_in *)address)->sin_addr;
    port = ntohs(((struct sockaddr_in *)address)->sin_port);
    break;
  case AF_INET6:
    addrPointer = &((struct sockaddr_in6 *)address)->sin6_addr;
    port = ntohs(((struct sockaddr_in6 *)address)->sin6_port);
    break;
  default:
    sysError("address", "failed to retrieve address");
  }
  if (inet_ntop(address->sa_family, addrPointer, addrString,
                sizeof(addrString)) == NULL)
    sysError("error", "error retreiving address");
  fprintf(stdout, "Address: [%s]:%d\n", addrString, port);
}


x86 assembly (clang, -O0):
<printAddrInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116a <printAddrInfo+0x2a>
lea    0xed3(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1040 <sysError@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%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,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
sub    $0x80,%eax
je     11e5 <printAddrInfo+0xa5>
jmp    11b3 <printAddrInfo+0x73>
mov    -0x28(%rbp),%eax
sub    $0x81,%eax
jne    1204 <printAddrInfo+0xc4>
jmp    11c6 <printAddrInfo+0x86>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    %eax,-0x24(%rbp)
jmp    1217 <printAddrInfo+0xd7>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    %eax,-0x24(%rbp)
jmp    1217 <printAddrInfo+0xd7>
lea    0xe26(%rip),%rdi
lea    0xe0c(%rip),%rsi
call   1040 <sysError@plt>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%edi
mov    -0x10(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    124d <printAddrInfo+0x10d>
lea    0xdf8(%rip),%rdi
lea    0xdf7(%rip),%rsi
call   1040 <sysError@plt>
mov    -0x30(%rbp),%rdx
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%ecx
lea    0xdf4(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAddrInfo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1166 <printAddrInfo+0x26>
lea    0xed7(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <sysError@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r14
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    (%rbx),%edi
cmp    $0x81,%edi
je     1198 <printAddrInfo+0x58>
cmp    $0x80,%edi
jne    11f4 <printAddrInfo+0xb4>
mov    $0x80,%edi
call   1060 <ntohs@plt>
mov    %eax,%r12d
mov    (%rbx),%edi
add    $0x4,%rbx
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
jne    11cc <printAddrInfo+0x8c>
lea    0xe79(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1040 <sysError@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
mov    %r14,%rdx
mov    %r12d,%ecx
call   1050 <fprintf@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe36(%rip),%rdi
lea    0xe1c(%rip),%rsi
call   1040 <sysError@plt>

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"address\00"
@.str.1 = [30 x i8] c"failed to get address pointer\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.2 = [27 x i8] c"failed to retrieve address\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [25 x i8] c"error retreiving address\00"
@stdout = global i32 0
@.str.5 = [18 x i8] c"Address: [%s]:%d\0A\00"
define void @printAddrInfo(%struct.sockaddr* %0) {
%2 = icmp eq %struct.sockaddr* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @sysError(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %3, %1
%6 = load i32, i32* @INET6_ADDRSTRLEN
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%10 = load i32, i32* %9
switch i32 %10, label %12 [
i32 129, label %14
i32 128, label %11
]
11: ; preds = %5
br label %14
12: ; preds = %5
%13 = tail call i32 @sysError(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
unreachable
14: ; preds = %5, %11
%15 = phi i32 [ 128, %11 ], [ %10, %5 ]
%16 = tail call i32 @ntohs(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 1, i32 0
%18 = bitcast i32* %17 to i8*
%19 = load i32, i32* %9
%20 = call i32* @inet_ntop(i32 %19, i8* %18, i8* %8, i32 %6)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @sysError(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %22, %14
%25 = load i32, i32* @stdout
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %8, i32 %16)
ret void
}