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

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ ENOSPC;
int /*<<< orphan*/ errno;
char const *inet_ntop4(void const *, char *, int);
char const *inet_ntop6(void const *, char *, int);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) {
  if (size < 1) {
    errno = ENOSPC;
    return NULL;
  }
  switch (af) {
  case AF_INET:
    return inet_ntop4(src, dst, size);
  case AF_INET6:
    return inet_ntop6(src, dst, 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)
cmpl   $0x1,-0x24(%rbp)
jge    115f <inet_ntop+0x3f>
mov    0x2e91(%rip),%rax
mov    (%rax),%ecx
mov    0x2e90(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11d4 <inet_ntop+0xb4>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x80,%eax
je     11a1 <inet_ntop+0x81>
jmp    1175 <inet_ntop+0x55>
mov    -0x28(%rbp),%eax
sub    $0x81,%eax
jne    11ba <inet_ntop+0x9a>
jmp    1188 <inet_ntop+0x68>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <inet_ntop4@plt>
mov    %rax,-0x8(%rbp)
jmp    11d4 <inet_ntop+0xb4>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <inet_ntop6@plt>
mov    %rax,-0x8(%rbp)
jmp    11d4 <inet_ntop+0xb4>
mov    0x2e0f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e16(%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   %ecx,%ecx
jle    1141 <inet_ntop+0x21>
cmp    $0x80,%edi
je     114a <inet_ntop+0x2a>
cmp    $0x81,%edi
jne    1157 <inet_ntop+0x37>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1040 <inet_ntop4@plt>
mov    0x2e90(%rip),%rax
jmp    115e <inet_ntop+0x3e>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
jmp    1030 <inet_ntop6@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    0x2e79(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
ret

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

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