#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*/ etherTypeT;

/* Variables and functions */
short htons(int);
int /*<<< orphan*/ memcpy(char *, ...);
char *write_ethernet(char *bufferptr, unsigned char *dest_mac,
                     unsigned char *local_mac) {
  memcpy(bufferptr, dest_mac, 6);
  bufferptr += 6;
  memcpy(bufferptr, local_mac, 6);
  bufferptr += 6;
  short int etherTypeT = htons(0x0800);
  memcpy(bufferptr, &(etherTypeT), sizeof(etherTypeT));
  return bufferptr + 2;
}


x86 assembly (clang, -O0):
<write_ethernet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
mov    $0x800,%edi
call   1030 <htons@plt>
mov    %ax,-0x1a(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
lea    -0x1a(%rbp),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ethernet>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    0x6(%rbx),%rdi
mov    %r14,%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    0xc(%rbx),%r14
mov    $0x800,%edi
call   1030 <htons@plt>
mov    %ax,0x6(%rsp)
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <memcpy@plt>
add    $0xe,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @write_ethernet(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i16
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i32 (i8*, ...) @memcpy(i8* %8, i8* %9, i32 6)
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 6
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = call i32 (i8*, ...) @memcpy(i8* %13, i8* %14, i32 6)
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 6
store i8* %17, i8** %4
%18 = call signext i16 @htons(i32 2048)
store i16 %18, i16* %7
%19 = load i8*, i8** %4
%20 = call i32 (i8*, ...) @memcpy(i8* %19, i16* %7, i64 2)
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 2
ret i8* %22
}

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