#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*/ socklen_t;

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ errno;
char const *inet_ntop4(void const *, char *, int /*<<< orphan*/);
char const *inet_ntop6(void const *, char *, int /*<<< orphan*/);
const char *inet_ntop(int af, const void *addr, char *buf, socklen_t len) {
  if (addr && af == AF_INET6)
    return inet_ntop6(addr, buf, len);
  if (addr && af == AF_INET)
    return inet_ntop4(addr, buf, len);
  errno = EAFNOSUPPORT;
  return NULL;
}


x86 assembly (clang, -O0):
<inet_ntop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116c <inet_ntop+0x4c>
mov    -0xc(%rbp),%eax
mov    0x2e95(%rip),%rcx
cmp    (%rcx),%eax
jne    116c <inet_ntop+0x4c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <inet_ntop6@plt>
mov    %rax,-0x8(%rbp)
jmp    11bc <inet_ntop+0x9c>
cmpq   $0x0,-0x18(%rbp)
je     11a2 <inet_ntop+0x82>
mov    -0xc(%rbp),%eax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%eax
jne    11a2 <inet_ntop+0x82>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <inet_ntop4@plt>
mov    %rax,-0x8(%rbp)
jmp    11bc <inet_ntop+0x9c>
mov    0x2e1f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1e(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_ntop>:
test   %rsi,%rsi
je     113d <inet_ntop+0x1d>
mov    0x2eb4(%rip),%rax
cmp    %edi,(%rax)
jne    113d <inet_ntop+0x1d>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1030 <inet_ntop6@plt>
test   %rsi,%rsi
je     115a <inet_ntop+0x3a>
mov    0x2e9f(%rip),%rax
cmp    %edi,(%rax)
jne    115a <inet_ntop+0x3a>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1040 <inet_ntop4@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    0x2e66(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
ret

LLVM IR (-O0):
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i8* @inet_ntop(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %21
12: ; preds = %4
%13 = load i32, i32* %6
%14 = load i32, i32* @AF_INET6
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = load i8*, i8** %8
%19 = load i32, i32* %9
%20 = call i8* @inet_ntop6(i8* %17, i8* %18, i32 %19)
store i8* %20, i8** %5
br label %35
21: ; preds = %12, %4
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load i32, i32* %6
%26 = load i32, i32* @AF_INET
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = load i8*, i8** %8
%31 = load i32, i32* %9
%32 = call i8* @inet_ntop4(i8* %29, i8* %30, i32 %31)
store i8* %32, i8** %5
br label %35
33: ; preds = %24, %21
%34 = load i32, i32* @EAFNOSUPPORT
store i32 %34, i32* @errno
store i8* null, i8** %5
br label %35
35: ; preds = %33, %28, %16
%36 = load i8*, i8** %5
ret i8* %36
}

LLVM IR (-O2):
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i8* @inet_ntop(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = icmp ne i8* %1, null
%6 = load i32, i32* @AF_INET6
%7 = icmp eq i32 %6, %0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i8* @inet_ntop6(i8* %1, i8* %2, i32 %3)
br label %19
11: ; preds = %4
%12 = load i32, i32* @AF_INET
%13 = icmp eq i32 %12, %0
%14 = select i1 %5, i1 %13, i1 false
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i8* @inet_ntop4(i8* %1, i8* %2, i32 %3)
br label %19
17: ; preds = %11
%18 = load i32, i32* @EAFNOSUPPORT
store i32 %18, i32* @errno
br label %19
19: ; preds = %17, %15, %9
%20 = phi i8* [ %10, %9 ], [ %16, %15 ], [ null, %17 ]
ret i8* %20
}