#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_ll {
  size_t sll_halen;
  int /*<<< orphan*/ *sll_addr;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
  int /*<<< orphan*/ *sa_data;
};
typedef int sa_family_t;

/* Variables and functions */
#define AF_INET 130
#define AF_INET6 129
#define AF_PACKET 128
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, void *, size_t);
void makeSockaddr(sa_family_t p_family, struct sockaddr *p_dest, void *p_data,
                  size_t p_size) {
  switch (p_family) {
  case AF_INET:
    memcpy(&((struct sockaddr_in *)p_dest)->sin_addr, p_data, p_size);
    break;
  case AF_INET6:
    memcpy(&((struct sockaddr_in6 *)p_dest)->sin6_addr, p_data, p_size);
    break;
  case AF_PACKET:
    memcpy(((struct sockaddr_ll *)p_dest)->sll_addr, p_data, p_size);
    ((struct sockaddr_ll *)p_dest)->sll_halen = p_size;
    break;
  default:
    memcpy(p_dest->sa_data, p_data, p_size);
    break;
  }
  p_dest->sa_family = p_family;
}


x86 assembly (clang, -O0):
<makeSockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     118f <makeSockaddr+0x7f>
jmp    113d <makeSockaddr+0x2d>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
je     1179 <makeSockaddr+0x69>
jmp    1150 <makeSockaddr+0x40>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
jne    11b4 <makeSockaddr+0xa4>
jmp    1163 <makeSockaddr+0x53>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
jmp    11c9 <makeSockaddr+0xb9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
jmp    11c9 <makeSockaddr+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11c9 <makeSockaddr+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeSockaddr>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x80,%edi
je     1139 <makeSockaddr+0x29>
cmp    $0x81,%ebp
je     1134 <makeSockaddr+0x24>
cmp    $0x82,%ebp
jne    114d <makeSockaddr+0x3d>
mov    %rbx,%rdi
jmp    1151 <makeSockaddr+0x41>
mov    0x8(%rbx),%rdi
mov    %rdx,%rsi
mov    %r14,%rdx
call   1030 <memcpy@plt>
mov    %r14,(%rbx)
jmp    115c <makeSockaddr+0x4c>
mov    0x8(%rbx),%rdi
mov    %rdx,%rsi
mov    %r14,%rdx
call   1030 <memcpy@plt>
mov    %ebp,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32, i32* }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_ll = type { i64, i32* }
define void @makeSockaddr(i32 %0, %struct.sockaddr* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%9 = load i32, i32* %5
switch i32 %9, label %36 [
i32 130, label %10
i32 129, label %17
i32 128, label %24
]
10: ; preds = %4
%11 = load %struct.sockaddr*, %struct.sockaddr** %6
%12 = bitcast %struct.sockaddr* %11 to %struct.sockaddr_in*
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%14 = load i8*, i8** %7
%15 = load i64, i64* %8
%16 = call i32 @memcpy(i32* %13, i8* %14, i64 %15)
br label %43
17: ; preds = %4
%18 = load %struct.sockaddr*, %struct.sockaddr** %6
%19 = bitcast %struct.sockaddr* %18 to %struct.sockaddr_in6*
%20 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %19, i32 0, i32 0
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = call i32 @memcpy(i32* %20, i8* %21, i64 %22)
br label %43
24: ; preds = %4
%25 = load %struct.sockaddr*, %struct.sockaddr** %6
%26 = bitcast %struct.sockaddr* %25 to %struct.sockaddr_ll*
%27 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %26, i32 0, i32 1
%28 = load i32*, i32** %27
%29 = load i8*, i8** %7
%30 = load i64, i64* %8
%31 = call i32 @memcpy(i32* %28, i8* %29, i64 %30)
%32 = load i64, i64* %8
%33 = load %struct.sockaddr*, %struct.sockaddr** %6
%34 = bitcast %struct.sockaddr* %33 to %struct.sockaddr_ll*
%35 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %34, i32 0, i32 0
store i64 %32, i64* %35
br label %43
36: ; preds = %4
%37 = load %struct.sockaddr*, %struct.sockaddr** %6
%38 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %37, i32 0, i32 1
%39 = load i32*, i32** %38
%40 = load i8*, i8** %7
%41 = load i64, i64* %8
%42 = call i32 @memcpy(i32* %39, i8* %40, i64 %41)
br label %43
43: ; preds = %36, %24, %17, %10
%44 = load i32, i32* %5
%45 = load %struct.sockaddr*, %struct.sockaddr** %6
%46 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %45, i32 0, i32 0
store i32 %44, i32* %46
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32, i32* }
define void @makeSockaddr(i32 %0, %struct.sockaddr* %1, i8* %2, i64 %3) {
switch i32 %0, label %16 [
i32 130, label %5
i32 129, label %8
i32 128, label %11
]
5: ; preds = %4
%6 = getelementptr %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%7 = tail call i32 @memcpy(i32* %6, i8* %2, i64 %3)
br label %20
8: ; preds = %4
%9 = getelementptr %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%10 = tail call i32 @memcpy(i32* %9, i8* %2, i64 %3)
br label %20
11: ; preds = %4
%12 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 1
%13 = load i32*, i32** %12
%14 = tail call i32 @memcpy(i32* %13, i8* %2, i64 %3)
%15 = bitcast %struct.sockaddr* %1 to i64*
store i64 %3, i64* %15
br label %20
16: ; preds = %4
%17 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 1
%18 = load i32*, i32** %17
%19 = tail call i32 @memcpy(i32* %18, i8* %2, i64 %3)
br label %20
20: ; preds = %16, %11, %8, %5
%21 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
store i32 %0, i32* %21
ret void
}