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

/* Variables and functions */
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, unsigned char *, int);
int write_ipv4_ethernet_header(unsigned char *buffer, unsigned char *source_mac,
                               unsigned char *dest_mac) {
  struct ether_header *eth_header = (struct ether_header *)buffer;
  memcpy(eth_header->ether_shost, source_mac, 6);
  memcpy(eth_header->ether_dhost, dest_mac, 6);
  eth_header->ether_type = htons(0x800);
  return sizeof(struct ether_header);
}


x86 assembly (clang, -O0):
<write_ipv4_ethernet_header>:
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    $0x800,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    $0xc,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ipv4_ethernet_header>:
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    $0x800,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
mov    $0xc,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ether_header = type { i32, i32, i32 }
define i32 @write_ipv4_ethernet_header(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.ether_header*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = bitcast i8* %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 i8*, i8** %5
%14 = call i32 @memcpy(i32 %12, i8* %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 i8*, i8** %6
%19 = call i32 @memcpy(i32 %17, i8* %18, i32 6)
%20 = call i32 @htons(i32 2048)
%21 = load %struct.ether_header*, %struct.ether_header** %7
%22 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %21, i32 0, i32 0
store i32 %20, i32* %22
ret i32 12
}

LLVM IR (-O2):
define i32 @write_ipv4_ethernet_header(i8* nocapture %0, i8* %1, i8* %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 8
%5 = bitcast i8* %4 to i32*
%6 = load i32, i32* %5
%7 = tail call i32 @memcpy(i32 %6, i8* %1, i32 6)
%8 = getelementptr inbounds i8, i8* %0, i64 4
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
%11 = tail call i32 @memcpy(i32 %10, i8* %2, i32 6)
%12 = tail call i32 @htons(i32 2048)
%13 = bitcast i8* %0 to i32*
store i32 %12, i32* %13
ret i32 12
}