#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 unsigned long long uint64_t;

/* Variables and functions */
int /*<<< orphan*/ fill64(void *, size_t, unsigned long long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long long, ...);
int /*<<< orphan*/ stderr;
unsigned long long xora64(void *, size_t);
int test(void *ptr, size_t size) {
  int s;
  size_t size64;
  size_t i;
  uint64_t pattern;
  fprintf(stderr, "memory: %lu MiB -- locked\n", (unsigned long)(size >> 20));
  size64 = size / 64;
  for (s = 0; s < 64; ++s) {
    int j;
    uint64_t r[3];
    pattern = ~0;
    pattern ^= (1ULL << s);
    for (j = 0; j < 3; ++j) {
      fill64(ptr, size64, pattern);
    }
    for (j = 0; j < 3; ++j) {
      r[j] = xora64(ptr, size64);
    }
    fprintf(stderr, "%016lX %016lX %016lX\n", r[0], r[1], r[2]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
shr    $0x14,%rdx
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
shr    $0x6,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x40,-0x14(%rbp)
jge    1232 <test+0x102>
movq   $0xffffffffffffffff,-0x30(%rbp)
ff
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
xor    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
jge    11c9 <test+0x99>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <fill64@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a0 <test+0x70>
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
jge    1201 <test+0xd1>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <xora64@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
mov    %rcx,-0x50(%rbp,%rax,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d0 <test+0xa0>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <test+0x42>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
mov    %rsi,%rdx
shr    $0x14,%rdx
lea    0xea8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
shr    $0x6,%r12
lea    0xeb1(%rip),%r15
xor    %r13d,%r13d
nopl   (%rax)
mov    $0xfffffffffffffffe,%rbx
mov    %r13d,%ecx
rol    %cl,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fill64@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fill64@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fill64@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <xora64@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <xora64@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <xora64@plt>
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r13
cmp    $0x40,%r13
jne    1170 <test+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"memory: %lu MiB -- locked\0A\00"
@.str.1 = [22 x i8] c"%016lX %016lX %016lX\0A\00"
define i32 @test(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca [3 x i64]
store i8* %0, i8** %3
store i64 %1, i64* %4
%11 = load i32, i32* @stderr
%12 = load i64, i64* %4
%13 = lshr i64 %12, 20
%14 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = load i64, i64* %4
%16 = udiv i64 %15, 64
store i64 %16, i64* %6
store i32 0, i32* %5
br label %17
17: ; preds = %60, %2
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 64
br i1 %19, label %20, label %63
20: ; preds = %17
store i64 -1, i64* %8
%21 = load i32, i32* %5
%22 = zext i32 %21 to i64
%23 = shl i64 1, %22
%24 = load i64, i64* %8
%25 = xor i64 %24, %23
store i64 %25, i64* %8
store i32 0, i32* %9
br label %26
26: ; preds = %34, %20
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 3
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = load i64, i64* %6
%32 = load i64, i64* %8
%33 = call i32 @fill64(i8* %30, i64 %31, i64 %32)
br label %34
34: ; preds = %29
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %26
37: ; preds = %26
store i32 0, i32* %9
br label %38
38: ; preds = %48, %37
%39 = load i32, i32* %9
%40 = icmp slt i32 %39, 3
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = load i8*, i8** %3
%43 = load i64, i64* %6
%44 = call i64 @xora64(i8* %42, i64 %43)
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 %46
store i64 %44, i64* %47
br label %48
48: ; preds = %41
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %38
51: ; preds = %38
%52 = load i32, i32* @stderr
%53 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 0
%54 = load i64, i64* %53
%55 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 1
%56 = load i64, i64* %55
%57 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 2
%58 = load i64, i64* %57
%59 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %54, i64 %56, i64 %58)
br label %60
60: ; preds = %51
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %17
63: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"memory: %lu MiB -- locked\0A\00"
@.str.1 = [22 x i8] c"%016lX %016lX %016lX\0A\00"
define i32 @test(i8* %0, i64 %1) {
%3 = load i32, i32* @stderr
%4 = lshr i64 %1, 20
%5 = tail call i32 (i32, i8*, i64, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = lshr i64 %1, 6
br label %7
7: ; preds = %2, %7
%8 = phi i64 [ 0, %2 ], [ %19, %7 ]
%9 = shl nuw i64 1, %8
%10 = xor i64 %9, -1
%11 = tail call i32 @fill64(i8* %0, i64 %6, i64 %10)
%12 = tail call i32 @fill64(i8* %0, i64 %6, i64 %10)
%13 = tail call i32 @fill64(i8* %0, i64 %6, i64 %10)
%14 = tail call i64 @xora64(i8* %0, i64 %6)
%15 = tail call i64 @xora64(i8* %0, i64 %6)
%16 = tail call i64 @xora64(i8* %0, i64 %6)
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, i64, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %14, i64 %15, i64 %16)
%19 = add nuw nsw i64 %8, 1
%20 = icmp eq i64 %19, 64
br i1 %20, label %21, label %7
21: ; preds = %7
ret i32 0
}