#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 (af == AF_INET6)
    return inet_ntop6(addr, buf, len);
  if (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)
mov    -0xc(%rbp),%eax
mov    0x2ea0(%rip),%rcx
cmp    (%rcx),%eax
jne    1161 <inet_ntop+0x41>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <inet_ntop6@plt>
mov    %rax,-0x8(%rbp)
jmp    11a6 <inet_ntop+0x86>
mov    -0xc(%rbp),%eax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
jne    118c <inet_ntop+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <inet_ntop4@plt>
mov    %rax,-0x8(%rbp)
jmp    11a6 <inet_ntop+0x86>
mov    0x2e35(%rip),%rax
mov    (%rax),%ecx
mov    0x2e34(%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>:
mov    0x2eb9(%rip),%rax
cmp    %edi,(%rax)
jne    1138 <inet_ntop+0x18>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1030 <inet_ntop6@plt>
mov    0x2ea9(%rip),%rax
cmp    %edi,(%rax)
jne    1150 <inet_ntop+0x30>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1040 <inet_ntop4@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    0x2e70(%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 i32, i32* %6
%11 = load i32, i32* @AF_INET6
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = load i8*, i8** %7
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = call i8* @inet_ntop6(i8* %14, i8* %15, i32 %16)
store i8* %17, i8** %5
br label %29
18: ; preds = %4
%19 = load i32, i32* %6
%20 = load i32, i32* @AF_INET
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i8*, i8** %7
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = call i8* @inet_ntop4(i8* %23, i8* %24, i32 %25)
store i8* %26, i8** %5
br label %29
27: ; preds = %18
%28 = load i32, i32* @EAFNOSUPPORT
store i32 %28, i32* @errno
store i8* null, i8** %5
br label %29
29: ; preds = %27, %22, %13
%30 = load i8*, i8** %5
ret i8* %30
}

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 = load i32, i32* @AF_INET6
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i8* @inet_ntop6(i8* %1, i8* %2, i32 %3)
br label %16
9: ; preds = %4
%10 = load i32, i32* @AF_INET
%11 = icmp eq i32 %10, %0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i8* @inet_ntop4(i8* %1, i8* %2, i32 %3)
br label %16
14: ; preds = %9
%15 = load i32, i32* @EAFNOSUPPORT
store i32 %15, i32* @errno
br label %16
16: ; preds = %14, %12, %7
%17 = phi i8* [ %8, %7 ], [ %13, %12 ], [ null, %14 ]
ret i8* %17
}