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

/* Variables and functions */
unsigned char AF_INET;
unsigned char AF_INET6;
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, void const *, int);
void fill_sockaddr_storage(struct sockaddr_storage *sst, unsigned char family,
                           const void *addr) {
  sst->ss_family = family;
  if (family == AF_INET) {
    struct sockaddr_in *sin = (struct sockaddr_in *)sst;
    memcpy(&sin->sin_addr, addr, sizeof(sin->sin_addr));
  } else if (family == AF_INET6) {
    struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sst;
    memcpy(&sin6->sin6_addr, addr, sizeof(sin6->sin6_addr));
  }
}


x86 assembly (clang, -O0):
<fill_sockaddr_storage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x9(%rbp),%eax
mov    0x2eae(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1164 <fill_sockaddr_storage+0x54>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
jmp    1199 <fill_sockaddr_storage+0x89>
movzbl -0x9(%rbp),%eax
mov    0x2e71(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1194 <fill_sockaddr_storage+0x84>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
jmp    1199 <fill_sockaddr_storage+0x89>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_sockaddr_storage>:
mov    %sil,(%rdi)
mov    0x2ece(%rip),%rax
cmp    %sil,(%rax)
je     112c <fill_sockaddr_storage+0x1c>
mov    0x2eba(%rip),%rax
cmp    %sil,(%rax)
je     112c <fill_sockaddr_storage+0x1c>
ret
mov    %rdx,%rsi
mov    $0x4,%edx
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i8 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i8 0
@AF_INET6 = global i8 0
define void @fill_sockaddr_storage(%struct.sockaddr_storage* %0, i8 zeroext %1, i8* %2) {
%4 = alloca %struct.sockaddr_storage*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in*
%8 = alloca %struct.sockaddr_in6*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%9 = load i8, i8* %5
%10 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%11 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %10, i32 0, i32 0
store i8 %9, i8* %11
%12 = load i8, i8* %5
%13 = zext i8 %12 to i32
%14 = load i8, i8* @AF_INET
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %13, %15
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%19 = bitcast %struct.sockaddr_storage* %18 to %struct.sockaddr_in*
store %struct.sockaddr_in* %19, %struct.sockaddr_in** %7
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%22 = load i8*, i8** %6
%23 = call i32 @memcpy(i32* %21, i8* %22, i32 4)
br label %38
24: ; preds = %3
%25 = load i8, i8* %5
%26 = zext i8 %25 to i32
%27 = load i8, i8* @AF_INET6
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%32 = bitcast %struct.sockaddr_storage* %31 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %32, %struct.sockaddr_in6** %8
%33 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %8
%34 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %33, i32 0, i32 0
%35 = load i8*, i8** %6
%36 = call i32 @memcpy(i32* %34, i8* %35, i32 4)
br label %37
37: ; preds = %30, %24
br label %38
38: ; preds = %37, %17
ret void
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i8 }
@AF_INET = global i8 0
@AF_INET6 = global i8 0
define void @fill_sockaddr_storage(%struct.sockaddr_storage* %0, i8 zeroext %1, i8* %2) {
%4 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
store i8 %1, i8* %4
%5 = load i8, i8* @AF_INET
%6 = icmp eq i8 %5, %1
%7 = load i8, i8* @AF_INET6
%8 = icmp eq i8 %7, %1
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = bitcast %struct.sockaddr_storage* %0 to i32*
%12 = tail call i32 @memcpy(i32* %11, i8* %2, i32 4)
br label %13
13: ; preds = %3, %10
ret void
}