#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 s_virtserv_state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int const);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int virtservDecodeICMPv6(struct s_virtserv_state *virtserv,
                         unsigned char *outbuf, const int outbuf_len,
                         const unsigned char *inbuf, const int inbuf_len) {
  if ((inbuf_len >= 8) && (outbuf_len >= (inbuf_len + 4))) {
    if ((inbuf[0] == 0x80) && (inbuf[1] == 0x00)) {
      outbuf[0] = 0x81;
      outbuf[1] = 0x00;
      memset(&outbuf[2], 0, 2);
      memcpy(&outbuf[4], &inbuf[4], (inbuf_len - 4));
      memset(&outbuf[inbuf_len], 0, 4);
      return inbuf_len;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<virtservDecodeICMPv6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jl     11de <virtservDecodeICMPv6+0xbe>
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    $0x4,%ecx
cmp    %ecx,%eax
jl     11de <virtservDecodeICMPv6+0xbe>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x80,%eax
jne    11d9 <virtservDecodeICMPv6+0xb9>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    11d9 <virtservDecodeICMPv6+0xb9>
mov    -0x18(%rbp),%rax
movb   $0x81,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rdi
add    $0x4,%rdi
mov    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x2c(%rbp),%edx
sub    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <virtservDecodeICMPv6+0xc5>
jmp    11de <virtservDecodeICMPv6+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<virtservDecodeICMPv6>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
cmp    $0x8,%r8d
jl     1185 <virtservDecodeICMPv6+0x65>
mov    %r8d,%ebx
mov    %rcx,%r15
lea    0x4(%rbx),%ecx
cmp    %edx,%ecx
jg     1185 <virtservDecodeICMPv6+0x65>
cmpb   $0x80,(%r15)
jne    1185 <virtservDecodeICMPv6+0x65>
cmpb   $0x0,0x1(%r15)
jne    1185 <virtservDecodeICMPv6+0x65>
mov    %rsi,%r14
movw   $0x81,(%rsi)
lea    0x2(%rsi),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <memset@plt>
lea    0x4(%r14),%rdi
add    $0x4,%r15
lea    -0x4(%rbx),%edx
mov    %r15,%rsi
call   1040 <memcpy@plt>
mov    %ebx,%edi
add    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.s_virtserv_state = type { i32 }
define i32 @virtservDecodeICMPv6(%struct.s_virtserv_state* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.s_virtserv_state*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store %struct.s_virtserv_state* %0, %struct.s_virtserv_state** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%12 = load i32, i32* %11
%13 = icmp sge i32 %12, 8
br i1 %13, label %14, label %53
14: ; preds = %5
%15 = load i32, i32* %9
%16 = load i32, i32* %11
%17 = add nsw i32 %16, 4
%18 = icmp sge i32 %15, %17
br i1 %18, label %19, label %53
19: ; preds = %14
%20 = load i8*, i8** %10
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 128
br i1 %24, label %25, label %52
25: ; preds = %19
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %52
31: ; preds = %25
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 -127, i8* %33
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8 0, i8* %35
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = call i32 @memset(i8* %37, i32 0, i32 2)
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i64 4
%41 = load i8*, i8** %10
%42 = getelementptr inbounds i8, i8* %41, i64 4
%43 = load i32, i32* %11
%44 = sub nsw i32 %43, 4
%45 = call i32 @memcpy(i8* %40, i8* %42, i32 %44)
%46 = load i8*, i8** %8
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = call i32 @memset(i8* %49, i32 0, i32 4)
%51 = load i32, i32* %11
store i32 %51, i32* %6
br label %54
52: ; preds = %25, %19
br label %53
53: ; preds = %52, %14, %5
store i32 0, i32* %6
br label %54
54: ; preds = %53, %31
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
%struct.s_virtserv_state = type { i32 }
define i32 @virtservDecodeICMPv6(%struct.s_virtserv_state* nocapture readnone %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = icmp slt i32 %4, 8
%7 = add nsw i32 %4, 4
%8 = icmp sgt i32 %7, %2
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %28, label %10
10: ; preds = %5
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, -128
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %3, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %13
store i8 -127, i8* %1
%18 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %18
%19 = getelementptr inbounds i8, i8* %1, i64 2
%20 = tail call i32 @memset(i8* %19, i32 0, i32 2)
%21 = getelementptr inbounds i8, i8* %1, i64 4
%22 = getelementptr inbounds i8, i8* %3, i64 4
%23 = add nsw i32 %4, -4
%24 = tail call i32 @memcpy(i8* %21, i8* %22, i32 %23)
%25 = zext i32 %4 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = tail call i32 @memset(i8* %26, i32 0, i32 4)
br label %28
28: ; preds = %5, %13, %10, %17
%29 = phi i32 [ %4, %17 ], [ 0, %10 ], [ 0, %13 ], [ 0, %5 ]
ret i32 %29
}