#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 ether_header {
  int /*<<< orphan*/ ether_type;
  int /*<<< orphan*/ ether_dhost;
  int /*<<< orphan*/ ether_shost;
};

/* Variables and functions */
int /*<<< orphan*/ ETH_P_IP;
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
void sock_layer2_encapsulate(uint8_t *buf, uint8_t *srcmac, uint8_t *dstmac) {
  struct ether_header *eth = (struct ether_header *)buf;
  memcpy(eth->ether_shost, srcmac, 6);
  memcpy(eth->ether_dhost, dstmac, 6);
  eth->ether_type = htons(ETH_P_IP);
}


x86 assembly (clang, -O0):
<sock_layer2_encapsulate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_layer2_encapsulate>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x8(%rdi),%edi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    0x4(%rbx),%edi
mov    %r14,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ether_header = type { i32, i32, i32 }
@ETH_P_IP = global i32 0
define void @sock_layer2_encapsulate(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca %struct.ether_header*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%8 = load i32*, i32** %4
%9 = bitcast i32* %8 to %struct.ether_header*
store %struct.ether_header* %9, %struct.ether_header** %7
%10 = load %struct.ether_header*, %struct.ether_header** %7
%11 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %10, i32 0, i32 2
%12 = load i32, i32* %11
%13 = load i32*, i32** %5
%14 = call i32 @memcpy(i32 %12, i32* %13, i32 6)
%15 = load %struct.ether_header*, %struct.ether_header** %7
%16 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load i32*, i32** %6
%19 = call i32 @memcpy(i32 %17, i32* %18, i32 6)
%20 = load i32, i32* @ETH_P_IP
%21 = call i32 @htons(i32 %20)
%22 = load %struct.ether_header*, %struct.ether_header** %7
%23 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %22, i32 0, i32 0
store i32 %21, i32* %23
ret void
}

LLVM IR (-O2):
@ETH_P_IP = global i32 0
define void @sock_layer2_encapsulate(i32* nocapture %0, i32* %1, i32* %2) {
%4 = getelementptr inbounds i32, i32* %0, i64 2
%5 = load i32, i32* %4
%6 = tail call i32 @memcpy(i32 %5, i32* %1, i32 6)
%7 = getelementptr inbounds i32, i32* %0, i64 1
%8 = load i32, i32* %7
%9 = tail call i32 @memcpy(i32 %8, i32* %2, i32 6)
%10 = load i32, i32* @ETH_P_IP
%11 = tail call i32 @htons(i32 %10)
store i32 %11, i32* %0
ret void
}