#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 {
  int sll_ifindex;
  int /*<<< orphan*/ sll_addr;
  int /*<<< orphan*/ sll_halen;
  int /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ sll_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ETHER_ADDR_LEN;
int /*<<< orphan*/ htons(int const);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, unsigned char const *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_ll *, int /*<<< orphan*/, int);
void init_sockaddr_ll(struct sockaddr_ll *pSockAddrLl,
                      const unsigned char ethernet_addr[ETHER_ADDR_LEN],
                      const int ifindex, const int protocol) {
  memset(pSockAddrLl, 0, sizeof(struct sockaddr_ll));
  pSockAddrLl->sll_family = AF_PACKET;
  pSockAddrLl->sll_protocol = htons(protocol);
  pSockAddrLl->sll_ifindex = ifindex;
  pSockAddrLl->sll_halen = ETHER_ADDR_LEN;
  memcpy(pSockAddrLl->sll_addr, ethernet_addr, ETHER_ADDR_LEN);
}


x86 assembly (clang, -O0):
<init_sockaddr_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x18(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e69(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_sockaddr_ll>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbp)
mov    %ebx,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rbp)
mov    %r15d,0x0(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    %edx,0x8(%rbp)
mov    0x4(%rbp),%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <memcpy@plt>

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32 }
@ETHER_ADDR_LEN = global i32 0
@AF_PACKET = global i32 0
define void @init_sockaddr_ll(%struct.sockaddr_ll* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.sockaddr_ll*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store %struct.sockaddr_ll* %0, %struct.sockaddr_ll** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* @ETHER_ADDR_LEN
%10 = zext i32 %9 to i64
%11 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%12 = call i32 @memset(%struct.sockaddr_ll* %11, i32 0, i32 20)
%13 = load i32, i32* @AF_PACKET
%14 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%15 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 4
store i32 %13, i32* %15
%16 = load i32, i32* %8
%17 = call i32 @htons(i32 %16)
%18 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%19 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %18, i32 0, i32 3
store i32 %17, i32* %19
%20 = load i32, i32* %7
%21 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%22 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* @ETHER_ADDR_LEN
%24 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%25 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %24, i32 0, i32 2
store i32 %23, i32* %25
%26 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%27 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = load i8*, i8** %6
%30 = load i32, i32* @ETHER_ADDR_LEN
%31 = call i32 @memcpy(i32 %28, i8* %29, i32 %30)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32 }
@ETHER_ADDR_LEN = global i32 0
@AF_PACKET = global i32 0
define void @init_sockaddr_ll(%struct.sockaddr_ll* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @memset(%struct.sockaddr_ll* %0, i32 0, i32 20)
%6 = load i32, i32* @AF_PACKET
%7 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %0, i64 0, i32 4
store i32 %6, i32* %7
%8 = tail call i32 @htons(i32 %3)
%9 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %0, i64 0, i32 3
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %0, i64 0, i32 0
store i32 %2, i32* %10
%11 = load i32, i32* @ETHER_ADDR_LEN
%12 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %0, i64 0, i32 2
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %0, i64 0, i32 1
%14 = load i32, i32* %13
%15 = tail call i32 @memcpy(i32 %14, i8* %1, i32 %11)
ret void
}