#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 */
typedef int /*<<< orphan*/ uint8_t;
struct sockaddr {
  int sa_family;
  int /*<<< orphan*/ sa_data;
};

/* Variables and functions */
#define ARPHRD_EETHER 131
#define ARPHRD_ETHER 130
#define ARPHRD_IEEE802 129
#define ARPHRD_LOOPBACK 128
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exitFatal(char *, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/, size_t);
void sockaddrToHwAddr(struct sockaddr const *addr, uint8_t mac[], size_t *len) {
  assert(addr != 0 && len != 0);
  switch (addr->sa_family) {
  case ARPHRD_EETHER:
  case ARPHRD_IEEE802:
  case ARPHRD_LOOPBACK:
  case ARPHRD_ETHER:
    *len = 6;
    break;
  default:
    exitFatal("Unsupported hardware-type",
              sizeof("Unsupported hardware-type") - 1);
  }
  assert(*len <= 6);
  memcpy(mac, addr->sa_data, *len);
}


x86 assembly (clang, -O0):
<sockaddrToHwAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     115f <sockaddrToHwAddr+0x2f>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
movzbl %al,%edi
and    $0x1,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     1194 <sockaddrToHwAddr+0x64>
jmp    1184 <sockaddrToHwAddr+0x54>
mov    -0x18(%rbp),%rax
movq   $0x6,(%rax)
jmp    11a5 <sockaddrToHwAddr+0x75>
lea    0xe65(%rip),%rdi
mov    $0x19,%esi
call   1030 <exitFatal@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x6,(%rax)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
call   1050 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockaddrToHwAddr>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rdx,%rdx
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    (%rbx),%eax
and    $0xfffffffc,%eax
cmp    $0x80,%eax
jne    116e <sockaddrToHwAddr+0x3e>
movq   $0x6,(%r15)
mov    $0x1,%edi
jmp    1189 <sockaddrToHwAddr+0x59>
lea    0xe8b(%rip),%rdi
mov    $0x19,%esi
call   1030 <exitFatal@plt>
xor    %edi,%edi
cmpq   $0x7,(%r15)
setb   %dil
call   1040 <assert@plt>
mov    0x4(%rbx),%esi
mov    (%r15),%rdx
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <memcpy@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32, i32 }
@.str = [26 x i8] c"Unsupported hardware-type\00"
define void @sockaddrToHwAddr(%struct.sockaddr* %0, i32* %1, i64* %2) {
%4 = alloca %struct.sockaddr*
%5 = alloca i32*
%6 = alloca i64*
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i32* %1, i32** %5
store i64* %2, i64** %6
%7 = load %struct.sockaddr*, %struct.sockaddr** %4
%8 = icmp ne %struct.sockaddr* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i64*, i64** %6
%11 = icmp ne i64* %10, null
br label %12
12: ; preds = %9, %3
%13 = phi i1 [ false, %3 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load %struct.sockaddr*, %struct.sockaddr** %4
%17 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %16, i32 0, i32 0
%18 = load i32, i32* %17
switch i32 %18, label %21 [
i32 131, label %19
i32 129, label %19
i32 128, label %19
i32 130, label %19
]
19: ; preds = %12, %12, %12, %12
%20 = load i64*, i64** %6
store i64 6, i64* %20
br label %23
21: ; preds = %12
%22 = call i32 @exitFatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 25)
br label %23
23: ; preds = %21, %19
%24 = load i64*, i64** %6
%25 = load i64, i64* %24
%26 = icmp ule i64 %25, 6
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32*, i32** %5
%30 = load %struct.sockaddr*, %struct.sockaddr** %4
%31 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %30, i32 0, i32 1
%32 = load i32, i32* %31
%33 = load i64*, i64** %6
%34 = load i64, i64* %33
%35 = call i32 @memcpy(i32* %29, i32 %32, i64 %34)
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32, i32 }
@.str = [26 x i8] c"Unsupported hardware-type\00"
define void @sockaddrToHwAddr(%struct.sockaddr* %0, i32* %1, i64* %2) {
%4 = icmp ne %struct.sockaddr* %0, null
%5 = icmp ne i64* %2, null
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = and i32 %10, -4
%12 = icmp eq i32 %11, 128
br i1 %12, label %13, label %14
13: ; preds = %3
store i64 6, i64* %2
br label %19
14: ; preds = %3
%15 = tail call i32 @exitFatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 25)
%16 = load i64, i64* %2
%17 = icmp ult i64 %16, 7
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %14, %13
%20 = phi i32 [ %18, %14 ], [ 1, %13 ]
%21 = tail call i32 @assert(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 1
%23 = load i32, i32* %22
%24 = load i64, i64* %2
%25 = tail call i32 @memcpy(i32* %1, i32 %23, i64 %24)
ret void
}