#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 */
typedef scalar_t__ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, unsigned long long, unsigned long long);
int verify_pattern(char *buf, size_t len, uint64_t off) {
  size_t i;
  for (i = 0; i < len; i += sizeof(uint64_t)) {
    uint64_t expected = i + off;
    uint64_t actual = *(uint64_t *)(buf + i);
    if (expected != actual) {
      printf("error: offset %llu had %llu\n", (unsigned long long)expected,
             (unsigned long long)actual);
      exit(1);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<verify_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a8 <verify_pattern+0x88>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     1192 <verify_pattern+0x72>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    1197 <verify_pattern+0x77>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <verify_pattern+0x1c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_pattern>:
push   %rax
test   %rsi,%rsi
je     1146 <verify_pattern+0x26>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
lea    (%rdx,%rax,1),%rcx
mov    (%rdi,%rax,1),%r8
cmp    %r8,%rcx
jne    114a <verify_pattern+0x2a>
add    $0x8,%rax
cmp    %rsi,%rax
jb     1130 <verify_pattern+0x10>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeaf(%rip),%rdi
mov    %rcx,%rsi
mov    %r8,%rdx
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
@.str = [29 x i8] c"error: offset %llu had %llu\0A\00"
define i32 @verify_pattern(i8* nocapture %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %18, label %7
5: ; preds = %7
%6 = icmp ult i64 %14, %1
br i1 %6, label %7, label %18
7: ; preds = %3, %5
%8 = phi i64 [ %14, %5 ], [ 0, %3 ]
%9 = add i64 %8, %2
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = bitcast i8* %10 to i64*
%12 = load i64, i64* %11
%13 = icmp eq i64 %9, %12
%14 = add i64 %8, 8
br i1 %13, label %5, label %15
15: ; preds = %7
%16 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %9, i64 %12)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %5, %3
ret i32 0
}