#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ AF_INET;
char const *inet_ntop(scalar_t__, void *, char *, int /*<<< orphan*/);
const char *satostr(struct sockaddr *sa, char *dst, socklen_t size) {
  struct sockaddr_in *sin;
  struct sockaddr_in6 *sin6;
  void *src;
  if ((sa->sa_family) == AF_INET) {
    sin = (struct sockaddr_in *)sa;
    src = (void *)&sin->sin_addr.s_addr;
  } else {
    sin6 = (struct sockaddr_in6 *)sa;
    src = (void *)&sin6->sin6_addr;
  }
  return inet_ntop(sa->sa_family, src, dst, size);
}


x86 assembly (clang, -O0):
<satostr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2eb7(%rip),%rcx
cmp    (%rcx),%rax
jne    114f <satostr+0x3f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    115f <satostr+0x4f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <inet_ntop@plt>
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i64 0
define i8* @satostr(%struct.sockaddr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in*
%8 = alloca %struct.sockaddr_in6*
%9 = alloca i8*
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load %struct.sockaddr*, %struct.sockaddr** %4
%11 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %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 %22
15: ; preds = %3
%16 = load %struct.sockaddr*, %struct.sockaddr** %4
%17 = bitcast %struct.sockaddr* %16 to %struct.sockaddr_in*
store %struct.sockaddr_in* %17, %struct.sockaddr_in** %7
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
%21 = bitcast i32* %20 to i8*
store i8* %21, i8** %9
br label %28
22: ; preds = %3
%23 = load %struct.sockaddr*, %struct.sockaddr** %4
%24 = bitcast %struct.sockaddr* %23 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %24, %struct.sockaddr_in6** %8
%25 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %8
%26 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %25, i32 0, i32 0
%27 = bitcast i32* %26 to i8*
store i8* %27, i8** %9
br label %28
28: ; preds = %22, %15
%29 = load %struct.sockaddr*, %struct.sockaddr** %4
%30 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = load i8*, i8** %9
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = call i8* @inet_ntop(i64 %31, i8* %32, i8* %33, i32 %34)
ret i8* %35
}

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