#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*/ fprintf(int /*<<< orphan*/, char *, size_t,
                           int /*<<< orphan*/, int);
int memcmp(char const *, char const *, int);
int /*<<< orphan*/ stderr;
void checkRandomBuffer4k(const char *buffer, const size_t len) {
  for (size_t i = 4096; i < len; i += 4096) {
    int ret = memcmp(buffer, buffer + i, 4096);
    if (ret) {
      fprintf(stderr,
              "*error* 4k chunk starting %zd is different from chunk starting "
              "at %d (ret %d)\n",
              i, 0, ret);
    }
  }
}


x86 assembly (clang, -O0):
<checkRandomBuffer4k>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1000,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a0 <checkRandomBuffer4k+0x80>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1188 <checkRandomBuffer4k+0x68>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%r8d
lea    0xe7f(%rip),%rsi
xor    %ecx,%ecx
call   1040 <fprintf@plt>
jmp    118d <checkRandomBuffer4k+0x6d>
mov    -0x18(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <checkRandomBuffer4k+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkRandomBuffer4k>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x1001,%rsi
jb     1187 <checkRandomBuffer4k+0x67>
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1000,%ebx
mov    0x2e9c(%rip),%r13
lea    0xeb5(%rip),%r12
jmp    115c <checkRandomBuffer4k+0x3c>
nopl   (%rax)
add    $0x1000,%rbx
cmp    %r14,%rbx
jae    1187 <checkRandomBuffer4k+0x67>
lea    (%r15,%rbx,1),%rsi
mov    %r15,%rdi
mov    $0x1000,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1150 <checkRandomBuffer4k+0x30>
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
mov    %eax,%r8d
call   1040 <fprintf@plt>
jmp    1150 <checkRandomBuffer4k+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [79 x i8] c"*error* 4k chunk starting %zd is different from chunk starting at %d (ret %d)\0A\00"
define void @checkRandomBuffer4k(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 4096, i64* %5
br label %7
7: ; preds = %25, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = call i32 @memcmp(i8* %12, i8* %15, i32 4096)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = load i64, i64* %5
%22 = load i32, i32* %6
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i64 %21, i32 0, i32 %22)
br label %24
24: ; preds = %19, %11
br label %25
25: ; preds = %24
%26 = load i64, i64* %5
%27 = add i64 %26, 4096
store i64 %27, i64* %5
br label %7
28: ; preds = %7
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [79 x i8] c"*error* 4k chunk starting %zd is different from chunk starting at %d (ret %d)\0A\00"
define void @checkRandomBuffer4k(i8* %0, i64 %1) {
%3 = icmp ugt i64 %1, 4096
br i1 %3, label %5, label %4
4: ; preds = %13, %2
ret void
5: ; preds = %2, %13
%6 = phi i64 [ %14, %13 ], [ 4096, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = tail call i32 @memcmp(i8* %0, i8* %7, i32 4096)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i64 %6, i32 0, i32 %8)
br label %13
13: ; preds = %10, %5
%14 = add i64 %6, 4096
%15 = icmp ult i64 %14, %1
br i1 %15, label %5, label %4
}