#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*/ __set_errno(int /*<<< orphan*/);
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 *src, char *dst, socklen_t size) {
  switch (af) {
  case AF_INET:
    return (inet_ntop4(src, dst, size));
  case AF_INET6:
    return (inet_ntop6(src, dst, size));
  default:
    __set_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     1188 <inet_ntop+0x58>
jmp    115c <inet_ntop+0x2c>
mov    -0x28(%rbp),%eax
sub    $0x81,%eax
jne    11a1 <inet_ntop+0x71>
jmp    116f <inet_ntop+0x3f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <inet_ntop4@plt>
mov    %rax,-0x8(%rbp)
jmp    11b7 <inet_ntop+0x87>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <inet_ntop6@plt>
mov    %rax,-0x8(%rbp)
jmp    11b7 <inet_ntop+0x87>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_ntop>:
cmp    $0x80,%edi
je     114d <inet_ntop+0x1d>
cmp    $0x81,%edi
jne    115a <inet_ntop+0x2a>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1050 <inet_ntop4@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1040 <inet_ntop6@plt>
push   %rax
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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