#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 */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ errno;
char const *inet_ntop4(void const *, char *, size_t);
char const *inet_ntop6(void const *, char *, size_t);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) {
  switch (af) {
  case AF_INET:
    return (inet_ntop4(src, dst, (size_t)size));
  case AF_INET6:
    return (inet_ntop6(src, dst, (size_t)size));
  default:
    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    %eax,-0x28(%rbp)
sub    $0x80,%eax
je     1179 <inet_ntop+0x59>
jmp    114c <inet_ntop+0x2c>
mov    -0x28(%rbp),%eax
sub    $0x81,%eax
jne    1193 <inet_ntop+0x73>
jmp    115f <inet_ntop+0x3f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rdx
call   1040 <inet_ntop4@plt>
mov    %rax,-0x8(%rbp)
jmp    11ad <inet_ntop+0x8d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rdx
call   1030 <inet_ntop6@plt>
mov    %rax,-0x8(%rbp)
jmp    11ad <inet_ntop+0x8d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3d(%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>:
cmp    $0x80,%edi
je     1141 <inet_ntop+0x21>
cmp    $0x81,%edi
jne    1152 <inet_ntop+0x32>
movslq %ecx,%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1040 <inet_ntop4@plt>
movslq %ecx,%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1030 <inet_ntop6@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    0x2e7e(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
ret

LLVM IR (-O0):
@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
switch i32 %10, label %23 [
i32 129, label %11
i32 128, label %17
]
11: ; preds = %4
%12 = load i8*, i8** %7
%13 = load i8*, i8** %8
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = call i8* @inet_ntop4(i8* %12, i8* %13, i64 %15)
store i8* %16, i8** %5
br label %25
17: ; preds = %4
%18 = load i8*, i8** %7
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = call i8* @inet_ntop6(i8* %18, i8* %19, i64 %21)
store i8* %22, i8** %5
br label %25
23: ; preds = %4
%24 = load i32, i32* @EAFNOSUPPORT
store i32 %24, i32* @errno
store i8* null, i8** %5
br label %25
25: ; preds = %23, %17, %11
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i8* @inet_ntop(i32 %0, i8* %1, i8* %2, i32 %3) {
switch i32 %0, label %11 [
i32 129, label %5
i32 128, label %8
]
5: ; preds = %4
%6 = sext i32 %3 to i64
%7 = tail call i8* @inet_ntop4(i8* %1, i8* %2, i64 %6)
br label %13
8: ; preds = %4
%9 = sext i32 %3 to i64
%10 = tail call i8* @inet_ntop6(i8* %1, i8* %2, i64 %9)
br label %13
11: ; preds = %4
%12 = load i32, i32* @EAFNOSUPPORT
store i32 %12, i32* @errno
br label %13
13: ; preds = %11, %8, %5
%14 = phi i8* [ null, %11 ], [ %10, %8 ], [ %7, %5 ]
ret i8* %14
}