#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int checksum_icmpv6(char *, int);
int /*<<< orphan*/ memcpy(char *, int *, int);
char *router_solicitation(uint8_t *src_address, char *buffer,
                          uint8_t *mac_address) {
  int offset = 0;
  uint8_t dst_address[16] = {0xff, 0x02, 0, 0, 0, 0, 0, 0,
                             0,    0,    0, 0, 0, 0, 0, 0x02};
  uint16_t payload_length;
  uint16_t checksum = 0;
  buffer[0] = 0x60;
  buffer[1] = 0;
  buffer[2] = 0;
  buffer[3] = 0;
  offset += 4;
  offset += 2;
  buffer[offset] = 0x3a;
  offset += 1;
  buffer[offset] = 255;
  offset += 1;
  memcpy(&buffer[offset], &src_address[0], 16);
  offset += 16;
  memcpy(&buffer[offset], &dst_address[0], 16);
  offset += 16;
  buffer[offset] = 0x85;
  offset += 1;
  buffer[offset] = 0;
  offset += 1;
  offset += 2;
  buffer[offset] = 0;
  buffer[offset + 1] = 0;
  buffer[offset + 2] = 0;
  buffer[offset + 3] = 0;
  offset += 4;
  buffer[offset] = 1;
  offset += 1;
  buffer[offset] = 1;
  offset += 1;
  memcpy(&buffer[offset], &mac_address[0], 6);
  offset += 6;
  payload_length = (offset - 40);
  buffer[4] = (payload_length >> 8) & 255;
  buffer[5] = (payload_length >> 0) & 255;
  checksum = checksum_icmpv6(buffer, (offset));
  buffer[42] = (checksum >> 8) & 255;
  buffer[43] = (checksum >> 0) & 255;
  return buffer;
}


x86 assembly (clang, -O0):
<router_solicitation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movl   $0xff,-0x60(%rbp)
movl   $0x2,-0x5c(%rbp)
movl   $0x2,-0x24(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x60,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x85,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x6,%edx
call   1050 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x28,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x64(%rbp),%eax
sar    $0x0,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <checksum_icmpv6@plt>
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2a(%rax)
mov    -0x68(%rbp),%eax
sar    $0x0,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2b(%rax)
mov    -0x10(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<router_solicitation>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rsi
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movabs $0x2000000ff,%rax
mov    %rax,(%rsp)
movl   $0x2,0x3c(%rsp)
movl   $0x60,(%rbx)
movw   $0xff3a,0x6(%rbx)
lea    0x8(%rbx),%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    0x18(%rbx),%rdi
mov    %rsp,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movw   $0x85,0x28(%rbx)
movl   $0x0,0x2c(%rbx)
movw   $0x101,0x30(%rbx)
lea    0x32(%rbx),%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
movw   $0x1000,0x4(%rbx)
mov    %rbx,%rdi
mov    $0x38,%esi
call   1030 <checksum_icmpv6@plt>
rol    $0x8,%ax
mov    %ax,0x2a(%rbx)
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @router_solicitation(i32* %0, i8* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [16 x i32]
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%11 = bitcast [16 x i32]* %8 to i8*
%12 = bitcast i8* %11 to [16 x i32]*
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i32 0, i32 0
store i32 255, i32* %13
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i32 0, i32 1
store i32 2, i32* %14
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i32 0, i32 15
store i32 2, i32* %15
store i32 0, i32* %10
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 96, i8* %17
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 2
store i8 0, i8* %21
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 3
store i8 0, i8* %23
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 4
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 2
store i32 %27, i32* %7
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 58, i8* %31
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
%34 = load i8*, i8** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 -1, i8* %37
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = load i8*, i8** %5
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i32*, i32** %4
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = call i32 @memcpy(i8* %43, i32* %45, i32 16)
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 16
store i32 %48, i32* %7
%49 = load i8*, i8** %5
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%54 = call i32 @memcpy(i8* %52, i32* %53, i32 16)
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 16
store i32 %56, i32* %7
%57 = load i8*, i8** %5
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 -123, i8* %60
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
%63 = load i8*, i8** %5
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 2
store i32 %70, i32* %7
%71 = load i8*, i8** %5
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
store i8 0, i8* %74
%75 = load i8*, i8** %5
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %75, i64 %78
store i8 0, i8* %79
%80 = load i8*, i8** %5
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 2
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %80, i64 %83
store i8 0, i8* %84
%85 = load i8*, i8** %5
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 3
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %85, i64 %88
store i8 0, i8* %89
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 4
store i32 %91, i32* %7
%92 = load i8*, i8** %5
%93 = load i32, i32* %7
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
store i8 1, i8* %95
%96 = load i32, i32* %7
%97 = add nsw i32 %96, 1
store i32 %97, i32* %7
%98 = load i8*, i8** %5
%99 = load i32, i32* %7
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %98, i64 %100
store i8 1, i8* %101
%102 = load i32, i32* %7
%103 = add nsw i32 %102, 1
store i32 %103, i32* %7
%104 = load i8*, i8** %5
%105 = load i32, i32* %7
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %104, i64 %106
%108 = load i32*, i32** %6
%109 = getelementptr inbounds i32, i32* %108, i64 0
%110 = call i32 @memcpy(i8* %107, i32* %109, i32 6)
%111 = load i32, i32* %7
%112 = add nsw i32 %111, 6
store i32 %112, i32* %7
%113 = load i32, i32* %7
%114 = sub nsw i32 %113, 40
store i32 %114, i32* %9
%115 = load i32, i32* %9
%116 = ashr i32 %115, 8
%117 = and i32 %116, 255
%118 = trunc i32 %117 to i8
%119 = load i8*, i8** %5
%120 = getelementptr inbounds i8, i8* %119, i64 4
store i8 %118, i8* %120
%121 = load i32, i32* %9
%122 = ashr i32 %121, 0
%123 = and i32 %122, 255
%124 = trunc i32 %123 to i8
%125 = load i8*, i8** %5
%126 = getelementptr inbounds i8, i8* %125, i64 5
store i8 %124, i8* %126
%127 = load i8*, i8** %5
%128 = load i32, i32* %7
%129 = call i32 @checksum_icmpv6(i8* %127, i32 %128)
store i32 %129, i32* %10
%130 = load i32, i32* %10
%131 = ashr i32 %130, 8
%132 = and i32 %131, 255
%133 = trunc i32 %132 to i8
%134 = load i8*, i8** %5
%135 = getelementptr inbounds i8, i8* %134, i64 42
store i8 %133, i8* %135
%136 = load i32, i32* %10
%137 = ashr i32 %136, 0
%138 = and i32 %137, 255
%139 = trunc i32 %138 to i8
%140 = load i8*, i8** %5
%141 = getelementptr inbounds i8, i8* %140, i64 43
store i8 %139, i8* %141
%142 = load i8*, i8** %5
ret i8* %142
}

LLVM IR (-O2):
define i8* @router_solicitation(i32* %0, i8* returned %1, i32* %2) {
%4 = alloca [16 x i32]
%5 = bitcast [16 x i32]* %4 to i8*
%6 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 0
store i32 255, i32* %6
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 1
store i32 2, i32* %7
%8 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 15
store i32 2, i32* %8
store i8 96, i8* %1
%9 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %9
%10 = getelementptr inbounds i8, i8* %1, i64 2
store i8 0, i8* %10
%11 = getelementptr inbounds i8, i8* %1, i64 3
store i8 0, i8* %11
%12 = getelementptr inbounds i8, i8* %1, i64 6
store i8 58, i8* %12
%13 = getelementptr inbounds i8, i8* %1, i64 7
store i8 -1, i8* %13
%14 = getelementptr inbounds i8, i8* %1, i64 8
%15 = tail call i32 @memcpy(i8* %14, i32* %0, i32 16)
%16 = getelementptr inbounds i8, i8* %1, i64 24
%17 = call i32 @memcpy(i8* %16, i32* %6, i32 16)
%18 = getelementptr inbounds i8, i8* %1, i64 40
store i8 -123, i8* %18
%19 = getelementptr inbounds i8, i8* %1, i64 41
store i8 0, i8* %19
%20 = getelementptr inbounds i8, i8* %1, i64 44
%21 = getelementptr inbounds i8, i8* %1, i64 48
%22 = bitcast i8* %20 to i32*
store i32 0, i32* %22
store i8 1, i8* %21
%23 = getelementptr inbounds i8, i8* %1, i64 49
store i8 1, i8* %23
%24 = getelementptr inbounds i8, i8* %1, i64 50
%25 = call i32 @memcpy(i8* %24, i32* %2, i32 6)
%26 = getelementptr inbounds i8, i8* %1, i64 4
store i8 0, i8* %26
%27 = getelementptr inbounds i8, i8* %1, i64 5
store i8 16, i8* %27
%28 = call i32 @checksum_icmpv6(i8* %1, i32 56)
%29 = lshr i32 %28, 8
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds i8, i8* %1, i64 42
store i8 %30, i8* %31
%32 = trunc i32 %28 to i8
%33 = getelementptr inbounds i8, i8* %1, i64 43
store i8 %32, i8* %33
ret i8* %1
}