#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*/ exit(int);
int /*<<< orphan*/ printf(char *);
void check_pattern(char *buf, unsigned seed) {
  int i;
  unsigned *lbuf = (unsigned *)buf;
  assert(((long)buf & 3) == 0);
  for (i = 0; i < 16384 / 4; i++) {
    if (lbuf[i] != seed) {
      printf("Buffer comparison mismatch\n");
      exit(1);
    }
    if (seed & 1)
      seed = (seed >> 1) ^ 0x80000057;
    else
      seed >>= 1;
  }
}


x86 assembly (clang, -O0):
<check_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x1000,-0x10(%rbp)
jge    11dc <check_pattern+0xac>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0xc(%rbp),%eax
je     119e <check_pattern+0x6e>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11c0 <check_pattern+0x90>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
xor    $0x80000057,%eax
mov    %eax,-0xc(%rbp)
jmp    11c9 <check_pattern+0x99>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ce <check_pattern+0x9e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1167 <check_pattern+0x37>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pattern>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
test   $0x3,%bl
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
cmp    %ebp,(%rbx,%rax,4)
jne    1193 <check_pattern+0x63>
mov    %ebp,%edx
shr    %edx
mov    %edx,%ecx
xor    $0x80000057,%ecx
test   $0x1,%bpl
cmove  %edx,%ecx
cmp    %ecx,0x4(%rbx,%rax,4)
jne    1193 <check_pattern+0x63>
mov    %ecx,%edx
shr    %edx
mov    %edx,%ebp
xor    $0x80000057,%ebp
test   $0x1,%cl
cmove  %edx,%ebp
add    $0x2,%rax
cmp    $0x1000,%rax
jne    1150 <check_pattern+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Buffer comparison mismatch\0A\00"
define void @check_pattern(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %6
%9 = load i8*, i8** %3
%10 = ptrtoint i8* %9 to i64
%11 = and i64 %10, 3
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i32 0, i32* %5
br label %15
15: ; preds = %41, %2
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 4096
br i1 %17, label %18, label %44
18: ; preds = %15
%19 = load i32*, i32** %6
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32, i32* %4
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %18
%30 = load i32, i32* %4
%31 = and i32 %30, 1
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* %4
%35 = lshr i32 %34, 1
%36 = xor i32 %35, -2147483561
store i32 %36, i32* %4
br label %40
37: ; preds = %29
%38 = load i32, i32* %4
%39 = lshr i32 %38, 1
store i32 %39, i32* %4
br label %40
40: ; preds = %37, %33
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %15
44: ; preds = %15
ret void
}

LLVM IR (-O2):
@str = [27 x i8] c"Buffer comparison mismatch\00"
define void @check_pattern(i8* %0, i32 %1) {
%3 = bitcast i8* %0 to i32*
%4 = ptrtoint i8* %0 to i64
%5 = and i64 %4, 3
%6 = icmp eq i64 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
br label %9
9: ; preds = %28, %2
%10 = phi i64 [ 0, %2 ], [ %34, %28 ]
%11 = phi i32 [ %1, %2 ], [ %33, %28 ]
%12 = getelementptr inbounds i32, i32* %3, i64 %10
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, %11
br i1 %14, label %18, label %15
15: ; preds = %18, %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = and i32 %11, 1
%20 = icmp eq i32 %19, 0
%21 = lshr i32 %11, 1
%22 = xor i32 %21, -2147483561
%23 = select i1 %20, i32 %21, i32 %22
%24 = or i64 %10, 1
%25 = getelementptr inbounds i32, i32* %3, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, %23
br i1 %27, label %28, label %15
28: ; preds = %18
%29 = and i32 %23, 1
%30 = icmp eq i32 %29, 0
%31 = lshr i32 %23, 1
%32 = xor i32 %31, -2147483561
%33 = select i1 %30, i32 %31, i32 %32
%34 = add nuw nsw i64 %10, 2
%35 = icmp eq i64 %34, 4096
br i1 %35, label %36, label %9
36: ; preds = %28
ret void
}