#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*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *, size_t, void **);
int /*<<< orphan*/ stderr;
void check_block(void *mem, size_t size) {
  void **p = (void **)mem;
  for (size_t i = 0; i < size / sizeof(void *); ++i) {
    if (p[i] != mem) {
      fprintf(stderr,
              "ERROR: memory contents changed in block %p [%#zx] @ %p\n", mem,
              size, &p[i]);
      assert(0 == 1);
    }
  }
}


x86 assembly (clang, -O0):
<check_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    $0x3,%rcx
cmp    %rcx,%rax
jae    11b4 <check_block+0x94>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x8(%rbp),%rax
je     119e <check_block+0x7e>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%r8
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1030 <assert@plt>
jmp    11a3 <check_block+0x83>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1140 <check_block+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x8,%rsi
jae    1140 <check_block+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%r13
shr    $0x3,%r13
mov    0x2e8c(%rip),%rbp
lea    0xea5(%rip),%r15
mov    %rdi,%rbx
jmp    116a <check_block+0x4a>
add    $0x8,%rbx
add    $0xffffffffffffffff,%r13
je     1131 <check_block+0x11>
cmp    %r12,(%rbx)
je     1160 <check_block+0x40>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1030 <assert@plt>
jmp    1160 <check_block+0x40>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"ERROR: memory contents changed in block %p [%#zx] @ %p\0A\00"
define void @check_block(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = bitcast i8* %7 to i8**
store i8** %8, i8*** %5
store i64 0, i64* %6
br label %9
9: ; preds = %31, %2
%10 = load i64, i64* %6
%11 = load i64, i64* %4
%12 = udiv i64 %11, 8
%13 = icmp ult i64 %10, %12
br i1 %13, label %14, label %34
14: ; preds = %9
%15 = load i8**, i8*** %5
%16 = load i64, i64* %6
%17 = getelementptr inbounds i8*, i8** %15, i64 %16
%18 = load i8*, i8** %17
%19 = load i8*, i8** %3
%20 = icmp ne i8* %18, %19
br i1 %20, label %21, label %30
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %3
%24 = load i64, i64* %4
%25 = load i8**, i8*** %5
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8*, i8** %25, i64 %26
%28 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %23, i64 %24, i8** %27)
%29 = call i32 @assert(i32 0)
br label %30
30: ; preds = %21, %14
br label %31
31: ; preds = %30
%32 = load i64, i64* %6
%33 = add i64 %32, 1
store i64 %33, i64* %6
br label %9
34: ; preds = %9
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"ERROR: memory contents changed in block %p [%#zx] @ %p\0A\00"
define void @check_block(i8* %0, i64 %1) {
%3 = bitcast i8* %0 to i8**
%4 = icmp ult i64 %1, 8
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = lshr i64 %1, 3
br label %8
7: ; preds = %17, %2
ret void
8: ; preds = %5, %17
%9 = phi i64 [ %18, %17 ], [ 0, %5 ]
%10 = getelementptr inbounds i8*, i8** %3, i64 %9
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, %0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i8** %10)
%16 = tail call i32 @assert(i32 0)
br label %17
17: ; preds = %8, %13
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %7, label %8
}