#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*/ printf(char *, ...);
int checkblock(volatile void *ptr, size_t size, unsigned bias, int doprint) {
  size_t n, i;
  unsigned long *pl;
  unsigned long val;
  pl = (unsigned long *)ptr;
  n = size / sizeof(unsigned long);
  for (i = 0; i < n; i++) {
    val = ((unsigned long)i ^ (unsigned long)bias);
    if (pl[i] != val) {
      if (doprint) {
        printf("\n");
      }
      printf("FAILED: data mismatch at offset %lu of block "
             "at 0x%lx: %lu vs. %lu\n",
             (unsigned long)(i * sizeof(unsigned long)),
             (unsigned long)(uintptr_t)pl, pl[i], val);
      return -1;
    }
    if (doprint && (i % 64 == 63)) {
      printf(".");
    }
  }
  if (doprint) {
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x3,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1202 <checkblock+0xf2>
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xor    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x40(%rbp),%rax
je     11c2 <checkblock+0xb2>
cmpl   $0x0,-0x20(%rbp)
je     118c <checkblock+0x7c>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
shl    $0x3,%rsi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x40(%rbp),%r8
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <checkblock+0x111>
cmpl   $0x0,-0x20(%rbp)
je     11ec <checkblock+0xdc>
mov    -0x30(%rbp),%rax
and    $0x3f,%rax
cmp    $0x3f,%rax
jne    11ec <checkblock+0xdc>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <checkblock+0xe1>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1142 <checkblock+0x32>
cmpl   $0x0,-0x20(%rbp)
je     121a <checkblock+0x10a>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkblock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
cmp    $0x8,%rsi
jae    114e <checkblock+0x2e>
xor    %ebx,%ebx
test   %r15d,%r15d
je     11df <checkblock+0xbf>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11df <checkblock+0xbf>
mov    %rsi,%r12
mov    %rdi,%r8
shr    $0x3,%r12
mov    %edx,%r13d
xor    %ebx,%ebx
xor    %r14d,%r14d
mov    %rdi,(%rsp)
jmp    117d <checkblock+0x5d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0x8,%rbx
cmp    %r14,%r12
je     1134 <checkblock+0x14>
mov    %r14,%rbp
xor    %r13,%rbp
mov    (%r8,%rbx,1),%rcx
cmp    %rbp,%rcx
jne    11ac <checkblock+0x8c>
test   %r15d,%r15d
je     1170 <checkblock+0x50>
mov    %r14d,%eax
and    $0x3f,%eax
cmp    $0x3f,%eax
jne    1170 <checkblock+0x50>
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    (%rsp),%r8
jmp    1170 <checkblock+0x50>
test   %r15d,%r15d
je     11c3 <checkblock+0xa3>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rsp),%r8
mov    (%r8,%rbx,1),%rcx
lea    0xe36(%rip),%rdi
mov    %rbx,%rsi
mov    %r8,%rdx
mov    %rbp,%r8
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [68 x i8] c"FAILED: data mismatch at offset %lu of block at 0x%lx: %lu vs. %lu\0A\00"
@.str.2 = [2 x i8] c".\00"
define i32 @checkblock(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64*
%13 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%14 = load i8*, i8** %6
%15 = bitcast i8* %14 to i64*
store i64* %15, i64** %12
%16 = load i64, i64* %7
%17 = udiv i64 %16, 8
store i64 %17, i64* %10
store i64 0, i64* %11
br label %18
18: ; preds = %59, %4
%19 = load i64, i64* %11
%20 = load i64, i64* %10
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %62
22: ; preds = %18
%23 = load i64, i64* %11
%24 = load i32, i32* %8
%25 = zext i32 %24 to i64
%26 = xor i64 %23, %25
store i64 %26, i64* %13
%27 = load i64*, i64** %12
%28 = load i64, i64* %11
%29 = getelementptr inbounds i64, i64* %27, i64 %28
%30 = load i64, i64* %29
%31 = load i64, i64* %13
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %49
33: ; preds = %22
%34 = load i32, i32* %9
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = load i64, i64* %11
%40 = mul i64 %39, 8
%41 = load i64*, i64** %12
%42 = ptrtoint i64* %41 to i64
%43 = load i64*, i64** %12
%44 = load i64, i64* %11
%45 = getelementptr inbounds i64, i64* %43, i64 %44
%46 = load i64, i64* %45
%47 = load i64, i64* %13
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i64 %40, i64 %42, i64 %46, i64 %47)
store i32 -1, i32* %5
br label %68
49: ; preds = %22
%50 = load i32, i32* %9
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i64, i64* %11
%54 = urem i64 %53, 64
%55 = icmp eq i64 %54, 63
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %56, %52, %49
br label %59
59: ; preds = %58
%60 = load i64, i64* %11
%61 = add i64 %60, 1
store i64 %61, i64* %11
br label %18
62: ; preds = %18
%63 = load i32, i32* %9
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
store i32 0, i32* %5
br label %68
68: ; preds = %67, %38
%69 = load i32, i32* %5
ret i32 %69
}

LLVM IR (-O2):
@.str.1 = [68 x i8] c"FAILED: data mismatch at offset %lu of block at 0x%lx: %lu vs. %lu\0A\00"
define i32 @checkblock(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = bitcast i8* %0 to i64*
%6 = icmp ult i64 %1, 8
br i1 %6, label %37, label %7
7: ; preds = %4
%8 = lshr i64 %1, 3
%9 = zext i32 %2 to i64
%10 = icmp ne i32 %3, 0
br label %11
11: ; preds = %7, %34
%12 = phi i64 [ 0, %7 ], [ %35, %34 ]
%13 = xor i64 %12, %9
%14 = getelementptr inbounds i64, i64* %5, i64 %12
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, %13
br i1 %16, label %28, label %17
17: ; preds = %11
%18 = icmp eq i32 %3, 0
br i1 %18, label %23, label %19
19: ; preds = %17
%20 = getelementptr inbounds i64, i64* %5, i64 %12
%21 = tail call i32 @putchar(i32 10)
%22 = load i64, i64* %20
br label %23
23: ; preds = %19, %17
%24 = phi i64 [ %22, %19 ], [ %15, %17 ]
%25 = shl i64 %12, 3
%26 = ptrtoint i8* %0 to i64
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i64 %25, i64 %26, i64 %24, i64 %13)
br label %41
28: ; preds = %11
%29 = and i64 %12, 63
%30 = icmp eq i64 %29, 63
%31 = select i1 %10, i1 %30, i1 false
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @putchar(i32 46)
br label %34
34: ; preds = %28, %32
%35 = add nuw nsw i64 %12, 1
%36 = icmp eq i64 %35, %8
br i1 %36, label %37, label %11
37: ; preds = %34, %4
%38 = icmp eq i32 %3, 0
br i1 %38, label %41, label %39
39: ; preds = %37
%40 = tail call i32 @putchar(i32 10)
br label %41
41: ; preds = %37, %39, %23
%42 = phi i32 [ -1, %23 ], [ 0, %39 ], [ 0, %37 ]
ret i32 %42
}