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

/* Variables and functions */
int /*<<< orphan*/ INET6_ADDRSTRLEN;
int /*<<< orphan*/ INET_ADDRSTRLEN;
int MAX(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
char *inet_ntop(int, void *, char *, int);
int /*<<< orphan*/ printf(char *, char const *);
char *strerror(int /*<<< orphan*/);
void print_ip_addr(int af_family, void *addr) {
  char ip_addr_buf[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)];
  const char *output;
  output = inet_ntop(af_family, addr, ip_addr_buf, sizeof(ip_addr_buf));
  printf("%s", output ? output : strerror(errno));
}


x86 assembly (clang, -O0):
<print_ip_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
call   1040 <MAX@plt>
mov    %eax,%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    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b1 <print_ip_addr+0x71>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11c3 <print_ip_addr+0x83>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ip_addr>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
call   1040 <MAX@plt>
mov    %eax,%ecx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
jne    1195 <print_ip_addr+0x55>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe64(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@INET_ADDRSTRLEN = global i32 0
@INET6_ADDRSTRLEN = global i32 0
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
define void @print_ip_addr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i32, i32* @INET_ADDRSTRLEN
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = call i32 @MAX(i32 %8, i32 %9)
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = load i32, i32* %3
%15 = load i8*, i8** %4
%16 = trunc i64 %11 to i32
%17 = call i8* @inet_ntop(i32 %14, i8* %15, i8* %13, i32 %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = load i8*, i8** %7
br label %25
22: ; preds = %2
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
br label %25
25: ; preds = %22, %20
%26 = phi i8* [ %21, %20 ], [ %24, %22 ]
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@INET_ADDRSTRLEN = global i32 0
@INET6_ADDRSTRLEN = global i32 0
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
define void @print_ip_addr(i32 %0, i8* %1) {
%3 = load i32, i32* @INET_ADDRSTRLEN
%4 = load i32, i32* @INET6_ADDRSTRLEN
%5 = tail call i32 @MAX(i32 %3, i32 %4)
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i8* @inet_ntop(i32 %0, i8* %1, i8* %7, i32 %5)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
br label %13
13: ; preds = %2, %10
%14 = phi i8* [ %12, %10 ], [ %8, %2 ]
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
ret void
}