#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 in6_addr {
  struct in6_addr const *s6_addr32;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
scalar_t__ IN6_IS_ADDR_V4MAPPED(struct in6_addr const *);
char const *inet_ntop(int /*<<< orphan*/, struct in6_addr const *, char *,
                      size_t);
const char *addr_ntop(char *dst, size_t bufflen, const struct in6_addr *addr) {
  if (IN6_IS_ADDR_V4MAPPED(addr)) {
    return inet_ntop(AF_INET, &addr->s6_addr32[3], dst, bufflen);
  } else {
    return inet_ntop(AF_INET6, addr, dst, bufflen);
  }
}


x86 assembly (clang, -O0):
<addr_ntop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <IN6_IS_ADDR_V4MAPPED@plt>
cmp    $0x0,%rax
je     1171 <addr_ntop+0x51>
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
add    $0x18,%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    %rax,-0x8(%rbp)
jmp    118f <addr_ntop+0x6f>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addr_ntop>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <IN6_IS_ADDR_V4MAPPED@plt>
test   %rax,%rax
je     114d <addr_ntop+0x2d>
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rsi
add    $0x18,%rsi
jmp    1159 <addr_ntop+0x39>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <inet_ntop@plt>

LLVM IR (-O0):
%struct.in6_addr = type { %struct.in6_addr* }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i8* @addr_ntop(i8* %0, i64 %1, %struct.in6_addr* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.in6_addr*
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.in6_addr* %2, %struct.in6_addr** %7
%8 = load %struct.in6_addr*, %struct.in6_addr** %7
%9 = call i64 @IN6_IS_ADDR_V4MAPPED(%struct.in6_addr* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %3
%12 = load i32, i32* @AF_INET
%13 = load %struct.in6_addr*, %struct.in6_addr** %7
%14 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %13, i32 0, i32 0
%15 = load %struct.in6_addr*, %struct.in6_addr** %14
%16 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %15, i64 3
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i8* @inet_ntop(i32 %12, %struct.in6_addr* %16, i8* %17, i64 %18)
store i8* %19, i8** %4
br label %26
20: ; preds = %3
%21 = load i32, i32* @AF_INET6
%22 = load %struct.in6_addr*, %struct.in6_addr** %7
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i8* @inet_ntop(i32 %21, %struct.in6_addr* %22, i8* %23, i64 %24)
store i8* %25, i8** %4
br label %26
26: ; preds = %20, %11
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
%struct.in6_addr = type { %struct.in6_addr* }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i8* @addr_ntop(i8* %0, i64 %1, %struct.in6_addr* %2) {
%4 = tail call i64 @IN6_IS_ADDR_V4MAPPED(%struct.in6_addr* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %2, i64 0, i32 0
%9 = load %struct.in6_addr*, %struct.in6_addr** %8
%10 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %9, i64 3
%11 = tail call i8* @inet_ntop(i32 %7, %struct.in6_addr* %10, i8* %0, i64 %1)
br label %15
12: ; preds = %3
%13 = load i32, i32* @AF_INET6
%14 = tail call i8* @inet_ntop(i32 %13, %struct.in6_addr* %2, i8* %0, i64 %1)
br label %15
15: ; preds = %12, %6
%16 = phi i8* [ %11, %6 ], [ %14, %12 ]
ret i8* %16
}