#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_storage {
  scalar_t__ ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
char const *inet_ntop(scalar_t__, void *, char *, size_t);
const char *inet_sastos(const struct sockaddr_storage *addr, char *buf,
                        size_t len) {
  return inet_ntop(addr->ss_family,
                   addr->ss_family == AF_INET
                       ? (void *)&((struct sockaddr_in *)addr)->sin_addr
                       : (void *)&((struct sockaddr_in6 *)addr)->sin6_addr,
                   buf, len);
}


x86 assembly (clang, -O0):
<inet_sastos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2eab(%rip),%rcx
cmp    (%rcx),%rax
jne    1153 <inet_sastos+0x43>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    115b <inet_sastos+0x4b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <inet_ntop@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_sastos>:
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %rdi,%rsi
mov    (%rdi),%rdi
jmp    1030 <inet_ntop@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i64 0
define i8* @inet_sastos(%struct.sockaddr_storage* %0, i8* %1, i64 %2) {
%4 = alloca %struct.sockaddr_storage*
%5 = alloca i8*
%6 = alloca i64
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%8 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%11 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* @AF_INET
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%17 = bitcast %struct.sockaddr_storage* %16 to %struct.sockaddr_in*
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = bitcast i32* %18 to i8*
br label %25
20: ; preds = %3
%21 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%22 = bitcast %struct.sockaddr_storage* %21 to %struct.sockaddr_in6*
%23 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %22, i32 0, i32 0
%24 = bitcast i32* %23 to i8*
br label %25
25: ; preds = %20, %15
%26 = phi i8* [ %19, %15 ], [ %24, %20 ]
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = call i8* @inet_ntop(i64 %9, i8* %26, i8* %27, i64 %28)
ret i8* %29
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i64 }
@AF_INET = global i64 0
define i8* @inet_sastos(%struct.sockaddr_storage* %0, i8* %1, i64 %2) {
%4 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = bitcast %struct.sockaddr_storage* %0 to i8*
%7 = tail call i8* @inet_ntop(i64 %5, i8* %6, i8* %1, i64 %2)
ret i8* %7
}