#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 ethhdr {
  int /*<<< orphan*/ h_proto;
  int /*<<< orphan*/ h_dest;
  int /*<<< orphan*/ h_source;
};

/* Variables and functions */
scalar_t__ ether_aton(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void *, int);
struct ethhdr *CreateEthernetHeader(char *src_mac, char *dst_mac,
                                    int protocol) {
  struct ethhdr *ethernet_header;
  ethernet_header = (struct ethhdr *)malloc(sizeof(struct ethhdr));
  memcpy(ethernet_header->h_source, (void *)ether_aton(src_mac), 6);
  memcpy(ethernet_header->h_dest, (void *)ether_aton(dst_mac), 6);
  ethernet_header->h_proto = htons(protocol);
  return (ethernet_header);
}


x86 assembly (clang, -O0):
<CreateEthernetHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <ether_aton@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ether_aton@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateEthernetHeader>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rax),%ebp
mov    %r12,%rdi
call   1050 <ether_aton@plt>
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    0x4(%rbx),%ebp
mov    %r15,%rdi
call   1050 <ether_aton@plt>
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ethhdr = type { i32, i32, i32 }
define %struct.ethhdr* @CreateEthernetHeader(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.ethhdr*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = call i64 @malloc(i32 12)
%9 = inttoptr i64 %8 to %struct.ethhdr*
store %struct.ethhdr* %9, %struct.ethhdr** %7
%10 = load %struct.ethhdr*, %struct.ethhdr** %7
%11 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %10, i32 0, i32 2
%12 = load i32, i32* %11
%13 = load i8*, i8** %4
%14 = call i64 @ether_aton(i8* %13)
%15 = inttoptr i64 %14 to i8*
%16 = call i32 @memcpy(i32 %12, i8* %15, i32 6)
%17 = load %struct.ethhdr*, %struct.ethhdr** %7
%18 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i8*, i8** %5
%21 = call i64 @ether_aton(i8* %20)
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @memcpy(i32 %19, i8* %22, i32 6)
%24 = load i32, i32* %6
%25 = call i32 @htons(i32 %24)
%26 = load %struct.ethhdr*, %struct.ethhdr** %7
%27 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load %struct.ethhdr*, %struct.ethhdr** %7
ret %struct.ethhdr* %28
}

LLVM IR (-O2):
%struct.ethhdr = type { i32, i32, i32 }
define %struct.ethhdr* @CreateEthernetHeader(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @malloc(i32 12)
%5 = inttoptr i64 %4 to %struct.ethhdr*
%6 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %5, i64 0, i32 2
%7 = load i32, i32* %6
%8 = tail call i64 @ether_aton(i8* %0)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @memcpy(i32 %7, i8* %9, i32 6)
%11 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %5, i64 0, i32 1
%12 = load i32, i32* %11
%13 = tail call i64 @ether_aton(i8* %1)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @memcpy(i32 %12, i8* %14, i32 6)
%16 = tail call i32 @htons(i32 %2)
%17 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %5, i64 0, i32 0
store i32 %16, i32* %17
ret %struct.ethhdr* %5
}