#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 memcmp(void *, void *, unsigned int);
int /*<<< orphan*/ printk(char *, unsigned int, unsigned int, unsigned int,
                          unsigned int *);
int Mali_MemCmp(unsigned int *malidata_page, unsigned int mali_va,
                unsigned int *refdata, unsigned int refoffset,
                unsigned int len) {
  int res;
  int i;
  int j;
  int step = 4;
  res = memcmp((void *)((char *)malidata_page + (mali_va % 4096)),
               (void *)((char *)refdata + (refoffset)),
               len * sizeof(unsigned int));
  if (res) {
    printk("Error during check of %x bytes from address PA:%x, VA:%x with "
           "reference data at address %x\n",
           len * 4, ((unsigned int)malidata_page + (mali_va % 4096)), mali_va,
           refdata);
    return -1;
  } else {
    return 0;
  };
}


x86 assembly (clang, -O0):
<Mali_MemCmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x4,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
and    $0xfff,%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%eax
add    %rax,%rsi
mov    -0x28(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ac <Mali_MemCmp+0x8c>
mov    -0x28(%rbp),%esi
shl    $0x2,%esi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    -0x14(%rbp),%eax
and    $0xfff,%eax
add    %eax,%edx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xe65(%rip),%rdi
call   1030 <printk@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <Mali_MemCmp+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mali_MemCmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%ebp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
mov    %esi,%ebx
and    $0xfff,%ebx
add    %rbx,%rdi
mov    %ecx,%esi
add    %rdx,%rsi
shl    $0x2,%ebp
mov    %ebp,%edx
call   1040 <memcmp@plt>
test   %eax,%eax
je     1172 <Mali_MemCmp+0x52>
add    %r12d,%ebx
lea    0xea4(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r14,%r8
call   1030 <printk@plt>
mov    $0xffffffff,%eax
jmp    1174 <Mali_MemCmp+0x54>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [92 x i8] c"Error during check of %x bytes from address PA:%x, VA:%x with reference data at address %x\0A\00"
define i32 @Mali_MemCmp(i32* %0, i32 %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 4, i32* %15
%16 = load i32*, i32** %7
%17 = bitcast i32* %16 to i8*
%18 = load i32, i32* %8
%19 = urem i32 %18, 4096
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i32*, i32** %9
%23 = bitcast i32* %22 to i8*
%24 = load i32, i32* %10
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i32, i32* %11
%28 = zext i32 %27 to i64
%29 = mul i64 %28, 4
%30 = trunc i64 %29 to i32
%31 = call i32 @memcmp(i8* %21, i8* %26, i32 %30)
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %5
%35 = load i32, i32* %11
%36 = mul i32 %35, 4
%37 = load i32*, i32** %7
%38 = ptrtoint i32* %37 to i32
%39 = load i32, i32* %8
%40 = urem i32 %39, 4096
%41 = add i32 %38, %40
%42 = load i32, i32* %8
%43 = load i32*, i32** %9
%44 = call i32 @printk(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %41, i32 %42, i32* %43)
store i32 -1, i32* %6
br label %46
45: ; preds = %5
store i32 0, i32* %6
br label %46
46: ; preds = %45, %34
%47 = load i32, i32* %6
ret i32 %47
}

LLVM IR (-O2):
@.str = [92 x i8] c"Error during check of %x bytes from address PA:%x, VA:%x with reference data at address %x\0A\00"
define i32 @Mali_MemCmp(i32* %0, i32 %1, i32* %2, i32 %3, i32 %4) {
%6 = bitcast i32* %0 to i8*
%7 = and i32 %1, 4095
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = bitcast i32* %2 to i8*
%11 = zext i32 %3 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = shl i32 %4, 2
%14 = tail call i32 @memcmp(i8* %9, i8* %12, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %5
%17 = ptrtoint i32* %0 to i64
%18 = trunc i64 %17 to i32
%19 = add i32 %7, %18
%20 = tail call i32 @printk(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %19, i32 %1, i32* %2)
br label %21
21: ; preds = %5, %16
%22 = phi i32 [ -1, %16 ], [ 0, %5 ]
ret i32 %22
}