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

/* Variables and functions */
int checksum_icmpv6(char *, int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ *, int);
char *redirect(char *buffer, uint8_t *IPv6_address, uint8_t *dst_address,
               uint8_t *target_addres, uint8_t *mac_address) {
  int offset = 0;
  uint16_t payload_length = 0;
  uint16_t checksum = 0;
  uint8_t dst_addres_copy[16];
  int i;
  for (i = 0; i < 16; i++) {
    dst_addres_copy[i] = dst_address[i];
  }
  buffer[0] = 0x60;
  buffer[1] = 0;
  buffer[2] = 0;
  buffer[3] = 0;
  offset += 4;
  offset += 2;
  buffer[offset] = 0x3a;
  offset += 1;
  buffer[offset] = 1;
  offset += 1;
  memcpy(&buffer[offset], &IPv6_address[0], 16);
  offset += 16;
  memcpy(&buffer[offset], &dst_address[0], 16);
  offset += 16;
  buffer[offset] = 0x89;
  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;
  memcpy(&buffer[offset], &target_addres[0], 16);
  offset += 16;
  memcpy(&buffer[offset], &dst_addres_copy[0], 16);
  offset += 16;
  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):
<redirect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x84(%rbp)
cmpl   $0x10,-0x84(%rbp)
jge    1198 <redirect+0x78>
mov    -0x18(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0x84(%rbp),%rax
mov    %ecx,-0x80(%rbp,%rax,4)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    115e <redirect+0x3e>
mov    -0x8(%rbp),%rax
movb   $0x60,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x89,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
lea    -0x80(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
sub    $0x28,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x30(%rbp),%eax
sar    $0x0,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <checksum_icmpv6@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2a(%rax)
mov    -0x34(%rbp),%eax
sar    $0x0,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2b(%rax)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redirect>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rdi,%rbx
movups (%rdx),%xmm0
movups 0x10(%rdx),%xmm1
movups 0x20(%rdx),%xmm2
movups 0x30(%rdx),%xmm3
movaps %xmm3,0x30(%rsp)
movaps %xmm2,0x20(%rsp)
movaps %xmm1,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x60,(%rdi)
movw   $0x13a,0x6(%rdi)
add    $0x8,%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    0x18(%rbx),%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movw   $0x89,0x28(%rbx)
lea    0x30(%rbx),%rdi
movl   $0x0,0x2c(%rbx)
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    0x40(%rbx),%rdi
mov    %rsp,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movw   $0x101,0x50(%rbx)
lea    0x52(%rbx),%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
movw   $0x3000,0x4(%rbx)
mov    %rbx,%rdi
mov    $0x58,%esi
call   1030 <checksum_icmpv6@plt>
rol    $0x8,%ax
mov    %ax,0x2a(%rbx)
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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