#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_shost;
  int /*<<< orphan*/ ether_dhost;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ ETHERTYPE_IP;
int /*<<< orphan*/ ETH_ALEN;
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, unsigned char const *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *, int, unsigned char const,
                          unsigned char const, unsigned char const,
                          unsigned char const, unsigned char const,
                          unsigned char const, unsigned char const,
                          unsigned char const, unsigned char const,
                          unsigned char const, unsigned char const,
                          unsigned char const);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
void tx(int s, const char *ifname, int ifindex, const unsigned char *src,
        const unsigned char *dst) {
  char buf[1500], *pos;
  struct ether_header *eth;
  int i;
  printf("TX: %s(ifindex=%d) "
         "%02x:%02x:%02x:%02x:%02x:%02x"
         " -> "
         "%02x:%02x:%02x:%02x:%02x:%02x"
         "\n",
         ifname, ifindex, (src)[0], (src)[1], (src)[2], (src)[3], (src)[4],
         (src)[5], (dst)[0], (dst)[1], (dst)[2], (dst)[3], (dst)[4], (dst)[5]);
  eth = (struct ether_header *)buf;
  memcpy(eth->ether_dhost, dst, ETH_ALEN);
  memcpy(eth->ether_shost, src, ETH_ALEN);
  eth->ether_type = htons(ETHERTYPE_IP);
  pos = (char *)(eth + 1);
  for (i = 0; i < sizeof(buf) - sizeof(*eth); i++)
    *pos++ = i;
  if (send(s, buf, sizeof(buf), 0) < 0)
    perror("send");
}


x86 assembly (clang, -O0):
<tx>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x678,%rsp
mov    %edi,-0x2c(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %edx,-0x3c(%rbp)
mov    %rcx,-0x48(%rbp)
mov    %r8,-0x50(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    -0x48(%rbp),%rax
mov    (%rax),%cl
mov    -0x48(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x48(%rbp),%rax
mov    0x2(%rax),%r9b
mov    -0x48(%rbp),%rax
mov    0x3(%rax),%al
mov    -0x48(%rbp),%rdi
mov    0x4(%rdi),%r13b
mov    -0x48(%rbp),%rdi
mov    0x5(%rdi),%r12b
mov    -0x50(%rbp),%rdi
mov    (%rdi),%r15b
mov    -0x50(%rbp),%rdi
mov    0x1(%rdi),%r14b
mov    -0x50(%rbp),%rdi
mov    0x2(%rdi),%bl
mov    -0x50(%rbp),%rdi
mov    0x3(%rdi),%r11b
mov    -0x50(%rbp),%rdi
mov    0x4(%rdi),%r10b
mov    -0x50(%rbp),%rdi
mov    %rdi,-0x650(%rbp)
lea    0xe1e(%rip),%rdi
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %al,%eax
mov    %eax,(%rsp)
mov    -0x650(%rbp),%rax
movzbl %r13b,%r13d
mov    %r13d,0x8(%rsp)
movzbl %r12b,%r12d
mov    %r12d,0x10(%rsp)
movzbl %r15b,%r15d
mov    %r15d,0x18(%rsp)
movzbl %r14b,%r14d
mov    %r14d,0x20(%rsp)
movzbl %bl,%ebx
mov    %ebx,0x28(%rsp)
movzbl %r11b,%r11d
mov    %r11d,0x30(%rsp)
movzbl %r10b,%r10d
mov    %r10d,0x38(%rsp)
movzbl 0x5(%rax),%eax
mov    %eax,0x40(%rsp)
call   1050 <printf@plt>
lea    -0x630(%rbp),%rax
mov    %rax,-0x640(%rbp)
mov    -0x640(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x50(%rbp),%rsi
mov    0x2d79(%rip),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
mov    -0x640(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x48(%rbp),%rsi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x640(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x640(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x638(%rbp)
movl   $0x0,-0x644(%rbp)
movslq -0x644(%rbp),%rax
cmp    $0x5d0,%rax
jae    1305 <tx+0x1b5>
mov    -0x644(%rbp),%eax
mov    %al,%cl
mov    -0x638(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x638(%rbp)
mov    %cl,(%rax)
mov    -0x644(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x644(%rbp)
jmp    12bf <tx+0x16f>
mov    -0x2c(%rbp),%edi
lea    -0x630(%rbp),%rsi
mov    $0x5dc,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    1331 <tx+0x1e1>
lea    0xd27(%rip),%rdi
call   1070 <perror@plt>
add    $0x678,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<tx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x608,%rsp
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %edi,0xc(%rsp)
movzbl (%rcx),%ecx
movzbl 0x1(%rbx),%r8d
movzbl 0x2(%rbx),%r9d
movzbl 0x3(%rbx),%eax
mov    %rax,0x18(%rsp)
movzbl 0x4(%rbx),%eax
mov    %rax,0x10(%rsp)
movzbl 0x5(%rbx),%r15d
movzbl 0x0(%rbp),%r12d
movzbl 0x1(%rbp),%r13d
movzbl 0x2(%rbp),%r11d
movzbl 0x3(%rbp),%r14d
movzbl 0x4(%rbp),%r10d
movzbl 0x5(%rbp),%eax
sub    $0x8,%rsp
lea    0xe89(%rip),%rdi
push   %rax
push   %r10
push   %r14
push   %r11
push   %r13
push   %r12
push   %r15
push   0x50(%rsp)
push   0x60(%rsp)
call   1050 <printf@plt>
add    $0x50,%rsp
mov    0x2e04(%rip),%r14
mov    (%r14),%edx
mov    %rbp,%rsi
call   1060 <memcpy@plt>
mov    (%r14),%edx
mov    %rbx,%rsi
call   1060 <memcpy@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,0x20(%rsp)
movdqa 0xdf4(%rip),%xmm0
mov    $0x2c,%eax
movdqa 0xdf7(%rip),%xmm1
movdqa 0xdff(%rip),%xmm2
movdqa 0xe07(%rip),%xmm3
nopl   0x0(%rax)
movdqu %xmm0,(%rsp,%rax,1)
movdqa %xmm0,%xmm4
paddb  %xmm1,%xmm4
movdqu %xmm4,0x10(%rsp,%rax,1)
movdqa %xmm0,%xmm4
paddb  %xmm2,%xmm4
movdqu %xmm4,0x20(%rsp,%rax,1)
paddb  %xmm3,%xmm0
add    $0x30,%rax
cmp    $0x5fc,%rax
jne    1230 <tx+0xe0>
lea    0x20(%rsp),%rsi
mov    0xc(%rsp),%edi
mov    $0x5dc,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     128d <tx+0x13d>
add    $0x608,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdff(%rip),%rdi
call   1070 <perror@plt>
jmp    127b <tx+0x12b>

LLVM IR (-O0):
%struct.ether_header = type { i32, i32, i32 }
@.str = [83 x i8] c"TX: %s(ifindex=%d) %02x:%02x:%02x:%02x:%02x:%02x -> %02x:%02x:%02x:%02x:%02x:%02x\0A\00"
@ETH_ALEN = global i32 0
@ETHERTYPE_IP = global i32 0
@.str.1 = [5 x i8] c"send\00"
define void @tx(i32 %0, i8* %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [1500 x i8]
%12 = alloca i8*
%13 = alloca %struct.ether_header*
%14 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = load i8*, i8** %9
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = load i8*, i8** %9
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = load i8*, i8** %9
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i8, i8* %24
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i64 3
%28 = load i8, i8* %27
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i64 4
%31 = load i8, i8* %30
%32 = load i8*, i8** %9
%33 = getelementptr inbounds i8, i8* %32, i64 5
%34 = load i8, i8* %33
%35 = load i8*, i8** %10
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = load i8*, i8** %10
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = load i8*, i8** %10
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i8, i8* %42
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i64 3
%46 = load i8, i8* %45
%47 = load i8*, i8** %10
%48 = getelementptr inbounds i8, i8* %47, i64 4
%49 = load i8, i8* %48
%50 = load i8*, i8** %10
%51 = getelementptr inbounds i8, i8* %50, i64 5
%52 = load i8, i8* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16, i8 zeroext %19, i8 zeroext %22, i8 zeroext %25, i8 zeroext %28, i8 zeroext %31, i8 zeroext %34, i8 zeroext %37, i8 zeroext %40, i8 zeroext %43, i8 zeroext %46, i8 zeroext %49, i8 zeroext %52)
%54 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 0
%55 = bitcast i8* %54 to %struct.ether_header*
store %struct.ether_header* %55, %struct.ether_header** %13
%56 = load %struct.ether_header*, %struct.ether_header** %13
%57 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %56, i32 0, i32 2
%58 = load i32, i32* %57
%59 = load i8*, i8** %10
%60 = load i32, i32* @ETH_ALEN
%61 = call i32 @memcpy(i32 %58, i8* %59, i32 %60)
%62 = load %struct.ether_header*, %struct.ether_header** %13
%63 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %62, i32 0, i32 1
%64 = load i32, i32* %63
%65 = load i8*, i8** %9
%66 = load i32, i32* @ETH_ALEN
%67 = call i32 @memcpy(i32 %64, i8* %65, i32 %66)
%68 = load i32, i32* @ETHERTYPE_IP
%69 = call i32 @htons(i32 %68)
%70 = load %struct.ether_header*, %struct.ether_header** %13
%71 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %70, i32 0, i32 0
store i32 %69, i32* %71
%72 = load %struct.ether_header*, %struct.ether_header** %13
%73 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %72, i64 1
%74 = bitcast %struct.ether_header* %73 to i8*
store i8* %74, i8** %12
store i32 0, i32* %14
br label %75
75: ; preds = %84, %5
%76 = load i32, i32* %14
%77 = sext i32 %76 to i64
%78 = icmp ult i64 %77, 1488
br i1 %78, label %79, label %87
79: ; preds = %75
%80 = load i32, i32* %14
%81 = trunc i32 %80 to i8
%82 = load i8*, i8** %12
%83 = getelementptr inbounds i8, i8* %82, i32 1
store i8* %83, i8** %12
store i8 %81, i8* %82
br label %84
84: ; preds = %79
%85 = load i32, i32* %14
%86 = add nsw i32 %85, 1
store i32 %86, i32* %14
br label %75
87: ; preds = %75
%88 = load i32, i32* %6
%89 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 0
%90 = call i64 @send(i32 %88, i8* %89, i32 1500, i32 0)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %87
%93 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %94
94: ; preds = %92, %87
ret void
}

LLVM IR (-O2):
@.str = [83 x i8] c"TX: %s(ifindex=%d) %02x:%02x:%02x:%02x:%02x:%02x -> %02x:%02x:%02x:%02x:%02x:%02x\0A\00"
@ETH_ALEN = global i32 0
@ETHERTYPE_IP = global i32 0
@.str.1 = [5 x i8] c"send\00"
define void @tx(i32 %0, i8* %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca [1500 x i8]
%7 = getelementptr inbounds [1500 x i8], [1500 x i8]* %6, i64 0, i64 0
%8 = load i8, i8* %3
%9 = getelementptr inbounds i8, i8* %3, i64 1
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %3, i64 2
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %3, i64 3
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %3, i64 4
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %3, i64 5
%18 = load i8, i8* %17
%19 = load i8, i8* %4
%20 = getelementptr inbounds i8, i8* %4, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %4, i64 2
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %4, i64 3
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %4, i64 4
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %4, i64 5
%29 = load i8, i8* %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i8 zeroext %8, i8 zeroext %10, i8 zeroext %12, i8 zeroext %14, i8 zeroext %16, i8 zeroext %18, i8 zeroext %19, i8 zeroext %21, i8 zeroext %23, i8 zeroext %25, i8 zeroext %27, i8 zeroext %29)
%31 = load i32, i32* @ETH_ALEN
%32 = tail call i32 @memcpy(i32 undef, i8* %4, i32 %31)
%33 = load i32, i32* @ETH_ALEN
%34 = tail call i32 @memcpy(i32 undef, i8* %3, i32 %33)
%35 = load i32, i32* @ETHERTYPE_IP
%36 = tail call i32 @htons(i32 %35)
%37 = bitcast [1500 x i8]* %6 to i32*
store i32 %36, i32* %37
%38 = getelementptr inbounds [1500 x i8], [1500 x i8]* %6, i64 0, i64 12
br label %39
39: ; preds = %39, %5
%40 = phi i64 [ 0, %5 ], [ %52, %39 ]
%41 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %5 ], [ %53, %39 ]
%42 = getelementptr i8, i8* %38, i64 %40
%43 = bitcast i8* %42 to <16 x i8>*
store <16 x i8> %41, <16 x i8>* %43
%44 = add nuw nsw i64 %40, 16
%45 = add <16 x i8> %41, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%46 = getelementptr i8, i8* %38, i64 %44
%47 = bitcast i8* %46 to <16 x i8>*
store <16 x i8> %45, <16 x i8>* %47
%48 = add nuw nsw i64 %40, 32
%49 = add <16 x i8> %41, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%50 = getelementptr i8, i8* %38, i64 %48
%51 = bitcast i8* %50 to <16 x i8>*
store <16 x i8> %49, <16 x i8>* %51
%52 = add nuw nsw i64 %40, 48
%53 = add <16 x i8> %41, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%54 = icmp eq i64 %52, 1488
br i1 %54, label %55, label %39
55: ; preds = %39
%56 = call i64 @send(i32 %0, i8* %7, i32 1500, i32 0)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
ret void
}