#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_halen;
  int /*<<< orphan*/ sll_hatype;
  int /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ sll_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ARPHRD_ETHER;
int /*<<< orphan*/ ETH_ALEN;
int /*<<< orphan*/ ETH_P_ALL;
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_ll *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sendto(int, char *, size_t, int /*<<< orphan*/,
                          struct sockaddr *, int);
ssize_t raw_send(int sock, int dev_id, char *buffer, size_t len) {
  struct sockaddr_ll sa;
  memset(&sa, 0, sizeof(struct sockaddr_ll));
  sa.sll_family = AF_PACKET;
  sa.sll_protocol = htons(ETH_P_ALL);
  sa.sll_hatype = ARPHRD_ETHER;
  sa.sll_halen = ETH_ALEN;
  sa.sll_ifindex = dev_id;
  return (sendto(sock, buffer, len, 0, (struct sockaddr *)&sa, sizeof(sa)));
}


x86 assembly (clang, -O0):
<raw_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0x14,%r9d
call   1050 <sendto@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw_send>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,0x8(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x14,%r9d
call   1050 <sendto@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_PACKET = global i32 0
@ETH_P_ALL = global i32 0
@ARPHRD_ETHER = global i32 0
@ETH_ALEN = global i32 0
define i32 @raw_send(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.sockaddr_ll
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%10 = call i32 @memset(%struct.sockaddr_ll* %9, i32 0, i32 20)
%11 = load i32, i32* @AF_PACKET
%12 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 4
store i32 %11, i32* %12
%13 = load i32, i32* @ETH_P_ALL
%14 = call i32 @htons(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 3
store i32 %14, i32* %15
%16 = load i32, i32* @ARPHRD_ETHER
%17 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* @ETH_ALEN
%19 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* %6
%21 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* %5
%23 = load i8*, i8** %7
%24 = load i64, i64* %8
%25 = bitcast %struct.sockaddr_ll* %9 to %struct.sockaddr*
%26 = call i32 @sendto(i32 %22, i8* %23, i64 %24, i32 0, %struct.sockaddr* %25, i32 20)
ret i32 %26
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_PACKET = global i32 0
@ETH_P_ALL = global i32 0
@ARPHRD_ETHER = global i32 0
@ETH_ALEN = global i32 0
define i32 @raw_send(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca %struct.sockaddr_ll
%6 = bitcast %struct.sockaddr_ll* %5 to i8*
%7 = call i32 @memset(%struct.sockaddr_ll* %5, i32 0, i32 20)
%8 = load i32, i32* @AF_PACKET
%9 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %5, i64 0, i32 4
store i32 %8, i32* %9
%10 = load i32, i32* @ETH_P_ALL
%11 = call i32 @htons(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %5, i64 0, i32 3
store i32 %11, i32* %12
%13 = load i32, i32* @ARPHRD_ETHER
%14 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %5, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @ETH_ALEN
%16 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %5, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %5, i64 0, i32 0
store i32 %1, i32* %17
%18 = bitcast %struct.sockaddr_ll* %5 to %struct.sockaddr*
%19 = call i32 @sendto(i32 %0, i8* %2, i64 %3, i32 0, %struct.sockaddr* %18, i32 20)
ret i32 %19
}