void build_arp(unsigned int source_addr_msb, unsigned int source_addr_lsb,
               unsigned int sender_ip, unsigned int target_ip,
               unsigned char *buf, unsigned int *len) {
  *len = 42;
  buf[0] = 0xFF;
  buf[1] = 0xFF;
  buf[2] = 0xFF;
  buf[3] = 0xFF;
  buf[4] = 0xFF;
  buf[5] = 0xFF;
  buf[6] = (source_addr_msb >> 16) & 0xFF;
  buf[7] = (source_addr_msb >> 8) & 0xFF;
  buf[8] = source_addr_msb & 0xFF;
  buf[9] = (source_addr_lsb >> 16) & 0xFF;
  buf[10] = (source_addr_lsb >> 8) & 0xFF;
  buf[11] = source_addr_lsb & 0xFF;
  buf[12] = 0x08;
  buf[13] = 0x06;
  buf[14] = 0x00;
  buf[15] = 0x01;
  buf[16] = 0x08;
  buf[17] = 0x00;
  buf[18] = 0x06;
  buf[19] = 0x04;
  buf[20] = 0x00;
  buf[21] = 0x01;
  buf[22] = (source_addr_msb >> 16) & 0xFF;
  buf[23] = (source_addr_msb >> 8) & 0xFF;
  buf[24] = source_addr_msb & 0xFF;
  buf[25] = (source_addr_lsb >> 16) & 0xFF;
  buf[26] = (source_addr_lsb >> 8) & 0xFF;
  buf[27] = source_addr_lsb & 0xFF;
  buf[28] = (sender_ip >> 24) & 0xFF;
  buf[29] = (sender_ip >> 16) & 0xFF;
  buf[30] = (sender_ip >> 8) & 0xFF;
  buf[31] = (sender_ip)&0xFF;
  buf[32] = 0;
  buf[33] = 0;
  buf[34] = 0;
  buf[35] = 0;
  buf[36] = 0;
  buf[37] = 0;
  buf[38] = (target_ip >> 24) & 0xFF;
  buf[39] = (target_ip >> 16) & 0xFF;
  buf[40] = (target_ip >> 8) & 0xFF;
  buf[41] = (target_ip)&0xFF;
}


x86 assembly (clang, -O0):
<build_arp>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x2a,(%rax)
mov    -0x18(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x18(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0xff,0x2(%rax)
mov    -0x18(%rbp),%rax
movb   $0xff,0x3(%rax)
mov    -0x18(%rbp),%rax
movb   $0xff,0x4(%rax)
mov    -0x18(%rbp),%rax
movb   $0xff,0x5(%rax)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0xa(%rax)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0xb(%rax)
mov    -0x18(%rbp),%rax
movb   $0x8,0xc(%rax)
mov    -0x18(%rbp),%rax
movb   $0x6,0xd(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0xe(%rax)
mov    -0x18(%rbp),%rax
movb   $0x1,0xf(%rax)
mov    -0x18(%rbp),%rax
movb   $0x8,0x10(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x11(%rax)
mov    -0x18(%rbp),%rax
movb   $0x6,0x12(%rax)
mov    -0x18(%rbp),%rax
movb   $0x4,0x13(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x14(%rax)
mov    -0x18(%rbp),%rax
movb   $0x1,0x15(%rax)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x16(%rax)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x17(%rax)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x18(%rax)
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x19(%rax)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1a(%rax)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1b(%rax)
mov    -0xc(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1c(%rax)
mov    -0xc(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1d(%rax)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1e(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1f(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x20(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x21(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x22(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x23(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x24(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x25(%rax)
mov    -0x10(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x26(%rax)
mov    -0x10(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x27(%rax)
mov    -0x10(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x28(%rax)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x29(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_arp>:
push   %rbx
mov    %r8,%rax
movl   $0x2a,(%r9)
mov    %edi,%r8d
shr    $0x10,%r8d
movw   $0xffff,0x4(%rax)
movl   $0xffffffff,(%rax)
mov    %r8b,0x6(%rax)
mov    %edi,%r9d
shr    $0x8,%r9d
mov    %r9b,0x7(%rax)
mov    %dil,0x8(%rax)
mov    %esi,%r10d
shr    $0x10,%r10d
mov    %r10b,0x9(%rax)
mov    %esi,%r11d
shr    $0x8,%r11d
mov    %r11b,0xa(%rax)
mov    %sil,0xb(%rax)
movabs $0x406000801000608,%rbx
mov    %rbx,0xc(%rax)
movw   $0x100,0x14(%rax)
mov    %r8b,0x16(%rax)
mov    %r9b,0x17(%rax)
mov    %dil,0x18(%rax)
mov    %r10b,0x19(%rax)
mov    %r11b,0x1a(%rax)
mov    %sil,0x1b(%rax)
mov    %edx,%esi
shr    $0x18,%esi
mov    %sil,0x1c(%rax)
mov    %edx,%esi
shr    $0x10,%esi
mov    %sil,0x1d(%rax)
mov    %dh,0x1e(%rax)
mov    %dl,0x1f(%rax)
movw   $0x0,0x24(%rax)
movl   $0x0,0x20(%rax)
bswap  %ecx
mov    %ecx,0x26(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define void @build_arp(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32* %5, i32** %12
%13 = load i32*, i32** %12
store i32 42, i32* %13
%14 = load i8*, i8** %11
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 -1, i8* %15
%16 = load i8*, i8** %11
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 -1, i8* %17
%18 = load i8*, i8** %11
%19 = getelementptr inbounds i8, i8* %18, i64 2
store i8 -1, i8* %19
%20 = load i8*, i8** %11
%21 = getelementptr inbounds i8, i8* %20, i64 3
store i8 -1, i8* %21
%22 = load i8*, i8** %11
%23 = getelementptr inbounds i8, i8* %22, i64 4
store i8 -1, i8* %23
%24 = load i8*, i8** %11
%25 = getelementptr inbounds i8, i8* %24, i64 5
store i8 -1, i8* %25
%26 = load i32, i32* %7
%27 = lshr i32 %26, 16
%28 = and i32 %27, 255
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %11
%31 = getelementptr inbounds i8, i8* %30, i64 6
store i8 %29, i8* %31
%32 = load i32, i32* %7
%33 = lshr i32 %32, 8
%34 = and i32 %33, 255
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %11
%37 = getelementptr inbounds i8, i8* %36, i64 7
store i8 %35, i8* %37
%38 = load i32, i32* %7
%39 = and i32 %38, 255
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %11
%42 = getelementptr inbounds i8, i8* %41, i64 8
store i8 %40, i8* %42
%43 = load i32, i32* %8
%44 = lshr i32 %43, 16
%45 = and i32 %44, 255
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %11
%48 = getelementptr inbounds i8, i8* %47, i64 9
store i8 %46, i8* %48
%49 = load i32, i32* %8
%50 = lshr i32 %49, 8
%51 = and i32 %50, 255
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %11
%54 = getelementptr inbounds i8, i8* %53, i64 10
store i8 %52, i8* %54
%55 = load i32, i32* %8
%56 = and i32 %55, 255
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %11
%59 = getelementptr inbounds i8, i8* %58, i64 11
store i8 %57, i8* %59
%60 = load i8*, i8** %11
%61 = getelementptr inbounds i8, i8* %60, i64 12
store i8 8, i8* %61
%62 = load i8*, i8** %11
%63 = getelementptr inbounds i8, i8* %62, i64 13
store i8 6, i8* %63
%64 = load i8*, i8** %11
%65 = getelementptr inbounds i8, i8* %64, i64 14
store i8 0, i8* %65
%66 = load i8*, i8** %11
%67 = getelementptr inbounds i8, i8* %66, i64 15
store i8 1, i8* %67
%68 = load i8*, i8** %11
%69 = getelementptr inbounds i8, i8* %68, i64 16
store i8 8, i8* %69
%70 = load i8*, i8** %11
%71 = getelementptr inbounds i8, i8* %70, i64 17
store i8 0, i8* %71
%72 = load i8*, i8** %11
%73 = getelementptr inbounds i8, i8* %72, i64 18
store i8 6, i8* %73
%74 = load i8*, i8** %11
%75 = getelementptr inbounds i8, i8* %74, i64 19
store i8 4, i8* %75
%76 = load i8*, i8** %11
%77 = getelementptr inbounds i8, i8* %76, i64 20
store i8 0, i8* %77
%78 = load i8*, i8** %11
%79 = getelementptr inbounds i8, i8* %78, i64 21
store i8 1, i8* %79
%80 = load i32, i32* %7
%81 = lshr i32 %80, 16
%82 = and i32 %81, 255
%83 = trunc i32 %82 to i8
%84 = load i8*, i8** %11
%85 = getelementptr inbounds i8, i8* %84, i64 22
store i8 %83, i8* %85
%86 = load i32, i32* %7
%87 = lshr i32 %86, 8
%88 = and i32 %87, 255
%89 = trunc i32 %88 to i8
%90 = load i8*, i8** %11
%91 = getelementptr inbounds i8, i8* %90, i64 23
store i8 %89, i8* %91
%92 = load i32, i32* %7
%93 = and i32 %92, 255
%94 = trunc i32 %93 to i8
%95 = load i8*, i8** %11
%96 = getelementptr inbounds i8, i8* %95, i64 24
store i8 %94, i8* %96
%97 = load i32, i32* %8
%98 = lshr i32 %97, 16
%99 = and i32 %98, 255
%100 = trunc i32 %99 to i8
%101 = load i8*, i8** %11
%102 = getelementptr inbounds i8, i8* %101, i64 25
store i8 %100, i8* %102
%103 = load i32, i32* %8
%104 = lshr i32 %103, 8
%105 = and i32 %104, 255
%106 = trunc i32 %105 to i8
%107 = load i8*, i8** %11
%108 = getelementptr inbounds i8, i8* %107, i64 26
store i8 %106, i8* %108
%109 = load i32, i32* %8
%110 = and i32 %109, 255
%111 = trunc i32 %110 to i8
%112 = load i8*, i8** %11
%113 = getelementptr inbounds i8, i8* %112, i64 27
store i8 %111, i8* %113
%114 = load i32, i32* %9
%115 = lshr i32 %114, 24
%116 = and i32 %115, 255
%117 = trunc i32 %116 to i8
%118 = load i8*, i8** %11
%119 = getelementptr inbounds i8, i8* %118, i64 28
store i8 %117, i8* %119
%120 = load i32, i32* %9
%121 = lshr i32 %120, 16
%122 = and i32 %121, 255
%123 = trunc i32 %122 to i8
%124 = load i8*, i8** %11
%125 = getelementptr inbounds i8, i8* %124, i64 29
store i8 %123, i8* %125
%126 = load i32, i32* %9
%127 = lshr i32 %126, 8
%128 = and i32 %127, 255
%129 = trunc i32 %128 to i8
%130 = load i8*, i8** %11
%131 = getelementptr inbounds i8, i8* %130, i64 30
store i8 %129, i8* %131
%132 = load i32, i32* %9
%133 = and i32 %132, 255
%134 = trunc i32 %133 to i8
%135 = load i8*, i8** %11
%136 = getelementptr inbounds i8, i8* %135, i64 31
store i8 %134, i8* %136
%137 = load i8*, i8** %11
%138 = getelementptr inbounds i8, i8* %137, i64 32
store i8 0, i8* %138
%139 = load i8*, i8** %11
%140 = getelementptr inbounds i8, i8* %139, i64 33
store i8 0, i8* %140
%141 = load i8*, i8** %11
%142 = getelementptr inbounds i8, i8* %141, i64 34
store i8 0, i8* %142
%143 = load i8*, i8** %11
%144 = getelementptr inbounds i8, i8* %143, i64 35
store i8 0, i8* %144
%145 = load i8*, i8** %11
%146 = getelementptr inbounds i8, i8* %145, i64 36
store i8 0, i8* %146
%147 = load i8*, i8** %11
%148 = getelementptr inbounds i8, i8* %147, i64 37
store i8 0, i8* %148
%149 = load i32, i32* %10
%150 = lshr i32 %149, 24
%151 = and i32 %150, 255
%152 = trunc i32 %151 to i8
%153 = load i8*, i8** %11
%154 = getelementptr inbounds i8, i8* %153, i64 38
store i8 %152, i8* %154
%155 = load i32, i32* %10
%156 = lshr i32 %155, 16
%157 = and i32 %156, 255
%158 = trunc i32 %157 to i8
%159 = load i8*, i8** %11
%160 = getelementptr inbounds i8, i8* %159, i64 39
store i8 %158, i8* %160
%161 = load i32, i32* %10
%162 = lshr i32 %161, 8
%163 = and i32 %162, 255
%164 = trunc i32 %163 to i8
%165 = load i8*, i8** %11
%166 = getelementptr inbounds i8, i8* %165, i64 40
store i8 %164, i8* %166
%167 = load i32, i32* %10
%168 = and i32 %167, 255
%169 = trunc i32 %168 to i8
%170 = load i8*, i8** %11
%171 = getelementptr inbounds i8, i8* %170, i64 41
store i8 %169, i8* %171
ret void
}

LLVM IR (-O2):
define void @build_arp(i32 %0, i32 %1, i32 %2, i32 %3, i8* writeonly %4, i32* nocapture writeonly %5) {
store i32 42, i32* %5
%7 = lshr i32 %0, 16
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds i8, i8* %4, i64 6
store i8 %8, i8* %9
%10 = lshr i32 %0, 8
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds i8, i8* %4, i64 7
store i8 %11, i8* %12
%13 = trunc i32 %0 to i8
%14 = getelementptr inbounds i8, i8* %4, i64 8
store i8 %13, i8* %14
%15 = lshr i32 %1, 16
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %4, i64 9
store i8 %16, i8* %17
%18 = lshr i32 %1, 8
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %4, i64 10
store i8 %19, i8* %20
%21 = trunc i32 %1 to i8
%22 = getelementptr inbounds i8, i8* %4, i64 11
store i8 %21, i8* %22
%23 = getelementptr inbounds i8, i8* %4, i64 12
store i8 8, i8* %23
%24 = getelementptr inbounds i8, i8* %4, i64 13
store i8 6, i8* %24
%25 = getelementptr inbounds i8, i8* %4, i64 14
store i8 0, i8* %25
%26 = getelementptr inbounds i8, i8* %4, i64 15
store i8 1, i8* %26
%27 = getelementptr inbounds i8, i8* %4, i64 16
store i8 8, i8* %27
%28 = getelementptr inbounds i8, i8* %4, i64 17
store i8 0, i8* %28
%29 = getelementptr inbounds i8, i8* %4, i64 18
store i8 6, i8* %29
%30 = getelementptr inbounds i8, i8* %4, i64 19
store i8 4, i8* %30
%31 = getelementptr inbounds i8, i8* %4, i64 20
store i8 0, i8* %31
%32 = getelementptr inbounds i8, i8* %4, i64 21
store i8 1, i8* %32
%33 = getelementptr inbounds i8, i8* %4, i64 22
store i8 %8, i8* %33
%34 = getelementptr inbounds i8, i8* %4, i64 23
store i8 %11, i8* %34
%35 = getelementptr inbounds i8, i8* %4, i64 24
store i8 %13, i8* %35
%36 = getelementptr inbounds i8, i8* %4, i64 25
store i8 %16, i8* %36
%37 = getelementptr inbounds i8, i8* %4, i64 26
store i8 %19, i8* %37
%38 = getelementptr inbounds i8, i8* %4, i64 27
store i8 %21, i8* %38
%39 = lshr i32 %2, 24
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds i8, i8* %4, i64 28
store i8 %40, i8* %41
%42 = lshr i32 %2, 16
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds i8, i8* %4, i64 29
store i8 %43, i8* %44
%45 = lshr i32 %2, 8
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds i8, i8* %4, i64 30
store i8 %46, i8* %47
%48 = trunc i32 %2 to i8
%49 = getelementptr inbounds i8, i8* %4, i64 31
store i8 %48, i8* %49
%50 = getelementptr inbounds i8, i8* %4, i64 32
%51 = lshr i32 %3, 24
%52 = trunc i32 %51 to i8
%53 = getelementptr inbounds i8, i8* %4, i64 38
store i8 %52, i8* %53
%54 = lshr i32 %3, 16
%55 = trunc i32 %54 to i8
%56 = getelementptr inbounds i8, i8* %4, i64 39
store i8 %55, i8* %56
%57 = lshr i32 %3, 8
%58 = trunc i32 %57 to i8
%59 = getelementptr inbounds i8, i8* %4, i64 40
store i8 %58, i8* %59
%60 = trunc i32 %3 to i8
%61 = getelementptr inbounds i8, i8* %4, i64 41
store i8 %60, i8* %61
ret void
}