#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
void read_memory(void *addr, int pattern, unsigned long size) {
  unsigned long iterator;
  unsigned long read = 0;
  int *temp = (int *)addr;
  for (iterator = 0; iterator < (size / (sizeof(int))); iterator++) {
    if (*temp != pattern) {
      printf("Iterator %lu", iterator);
      printf("Correctness failed at loop read\n"
             "PATTERN MISMATCH OCCURED \n");
      exit(-1);
    }
    read++;
    temp++;
  }
}


x86 assembly (clang, -O0):
<read_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
jae    11c2 <read_memory+0xa2>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
je     1199 <read_memory+0x79>
mov    -0x20(%rbp),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114b <read_memory+0x2b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_memory>:
push   %rax
cmp    $0x4,%rdx
jb     114e <read_memory+0x1e>
shr    $0x2,%rdx
xor    %eax,%eax
nopl   (%rax)
cmp    %esi,(%rdi,%rax,4)
jne    1150 <read_memory+0x20>
add    $0x1,%rax
cmp    %rax,%rdx
jne    1140 <read_memory+0x10>
pop    %rax
ret
lea    0xea9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Iterator %lu\00"
@.str.1 = [59 x i8] c"Correctness failed at loop read\0APATTERN MISMATCH OCCURED \0A\00"
define void @read_memory(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store i64 0, i64* %8
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %9
store i64 0, i64* %7
br label %12
12: ; preds = %32, %3
%13 = load i64, i64* %7
%14 = load i64, i64* %6
%15 = udiv i64 %14, 4
%16 = icmp ult i64 %13, %15
br i1 %16, label %17, label %35
17: ; preds = %12
%18 = load i32*, i32** %9
%19 = load i32, i32* %18
%20 = load i32, i32* %5
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i64, i64* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %17
%28 = load i64, i64* %8
%29 = add i64 %28, 1
store i64 %29, i64* %8
%30 = load i32*, i32** %9
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %9
br label %32
32: ; preds = %27
%33 = load i64, i64* %7
%34 = add i64 %33, 1
store i64 %34, i64* %7
br label %12
35: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Iterator %lu\00"
@str = [58 x i8] c"Correctness failed at loop read\0APATTERN MISMATCH OCCURED \00"
define void @read_memory(i8* nocapture %0, i32 %1, i64 %2) {
%4 = icmp ult i64 %2, 4
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = lshr i64 %2, 2
%7 = bitcast i8* %0 to i32*
br label %8
8: ; preds = %5, %17
%9 = phi i32* [ %18, %17 ], [ %7, %5 ]
%10 = phi i64 [ %19, %17 ], [ 0, %5 ]
%11 = load i32, i32* %9
%12 = icmp eq i32 %11, %1
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %10)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %8
%18 = getelementptr inbounds i32, i32* %9, i64 1
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, %6
br i1 %20, label %21, label %8
21: ; preds = %17, %3
ret void
}