#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 */

/* Variables and functions */
int /*<<< orphan*/ MD5Calc(unsigned char *, unsigned char *, char);
int /*<<< orphan*/ errorExit(char *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
void checkPacketMD5(char *pkt) {
  char md5[0x10] = {0x0};
  int md5len = 0x10;
  memcpy(md5, pkt + 2, md5len);
  memset(pkt + 2, 0x0, md5len);
  MD5Calc((unsigned char *)pkt + 0x2, (unsigned char *)pkt, pkt[1]);
  if (memcmp(md5, pkt + 2, md5len)) {
    errorExit("Packet MD5 value invalid!\n");
  }
}


x86 assembly (clang, -O0):
<checkPacketMD5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0x10,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x2,%rsi
mov    -0x24(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edx
call   1030 <MD5Calc@plt>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x2,%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11dc <checkPacketMD5+0x8c>
lea    0xe29(%rip),%rdi
call   1070 <errorExit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkPacketMD5>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0x2(%rdi),%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movsbl 0x1(%r14),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <MD5Calc@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11ba <checkPacketMD5+0x6a>
lea    0xe4b(%rip),%rdi
call   1070 <errorExit@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Packet MD5 value invalid!\0A\00"
define void @checkPacketMD5(i8* %0) {
%2 = alloca i8*
%3 = alloca [16 x i8]
%4 = alloca i32
store i8* %0, i8** %2
%5 = bitcast [16 x i8]* %3 to i8*
store i32 16, i32* %4
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 2
%9 = load i32, i32* %4
%10 = call i32 @memcpy(i8* %6, i8* %8, i32 %9)
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 2
%13 = load i32, i32* %4
%14 = call i32 @memset(i8* %12, i32 0, i32 %13)
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = load i8*, i8** %2
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = call i32 @MD5Calc(i8* %16, i8* %17, i8 signext %20)
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i32, i32* %4
%26 = call i64 @memcmp(i8* %22, i8* %24, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %1
%29 = call i32 @errorExit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %1
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Packet MD5 value invalid!\0A\00"
define void @checkPacketMD5(i8* %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds i8, i8* %0, i64 2
%5 = call i32 @memcpy(i8* %3, i8* %4, i32 16)
%6 = call i32 @memset(i8* %4, i32 0, i32 16)
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = call i32 @MD5Calc(i8* %4, i8* %0, i8 signext %8)
%10 = call i64 @memcmp(i8* %3, i8* %4, i32 16)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i32 @errorExit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
ret void
}