#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 128
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ errno;
char const *inet_ntop(int const, char *, char *, size_t);
const char *_inet_ntop(struct sockaddr *sa, char *dst, size_t size) {
  switch (sa->sa_family) {
  case AF_INET:
    return (inet_ntop(AF_INET, (char *)&((struct sockaddr_in *)sa)->sin_addr,
                      dst, size));
  default:
    errno = EAFNOSUPPORT;
    return (NULL);
  }
}


x86 assembly (clang, -O0):
<_inet_ntop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    1159 <_inet_ntop+0x49>
jmp    113a <_inet_ntop+0x2a>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x80,%edi
call   1030 <inet_ntop@plt>
mov    %rax,-0x8(%rbp)
jmp    1173 <_inet_ntop+0x63>
mov    0x2e78(%rip),%rax
mov    (%rax),%ecx
mov    0x2e77(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_inet_ntop>:
cmpl   $0x80,(%rdi)
jne    112b <_inet_ntop+0x1b>
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %rdi,%rsi
mov    $0x80,%edi
jmp    1030 <inet_ntop@plt>
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    0x2ea5(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i8* @_inet_ntop(%struct.sockaddr* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca %struct.sockaddr*
%6 = alloca i8*
%7 = alloca i64
store %struct.sockaddr* %0, %struct.sockaddr** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load %struct.sockaddr*, %struct.sockaddr** %5
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %8, i32 0, i32 0
%10 = load i32, i32* %9
switch i32 %10, label %19 [
i32 128, label %11
]
11: ; preds = %3
%12 = load %struct.sockaddr*, %struct.sockaddr** %5
%13 = bitcast %struct.sockaddr* %12 to %struct.sockaddr_in*
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%15 = bitcast i32* %14 to i8*
%16 = load i8*, i8** %6
%17 = load i64, i64* %7
%18 = call i8* @inet_ntop(i32 128, i8* %15, i8* %16, i64 %17)
store i8* %18, i8** %4
br label %21
19: ; preds = %3
%20 = load i32, i32* @EAFNOSUPPORT
store i32 %20, i32* @errno
store i8* null, i8** %4
br label %21
21: ; preds = %19, %11
%22 = load i8*, i8** %4
ret i8* %22
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i8* @_inet_ntop(%struct.sockaddr* %0, i8* %1, i64 %2) {
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 128
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = bitcast %struct.sockaddr* %0 to i8*
%9 = tail call i8* @inet_ntop(i32 128, i8* %8, i8* %1, i64 %2)
br label %12
10: ; preds = %3
%11 = load i32, i32* @EAFNOSUPPORT
store i32 %11, i32* @errno
br label %12
12: ; preds = %10, %7
%13 = phi i8* [ %9, %7 ], [ null, %10 ]
ret i8* %13
}