#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 MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_NORESERVE;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ assert(int);
char *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
void _cacheflush(void) {
  long unsigned i;
  char *ptr = mmap(NULL, 1 << 28, PROT_READ | PROT_WRITE,
                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
  if (MAP_FAILED != ptr) {
    for (i = 0; i < 1 << 28; ++i)
      ptr[i] = (char)i;
    for (i = 0; i < 1 << 28; ++i)
      assert((char)i == ptr[i]);
    munmap(ptr, 1 << 28);
  }
}


x86 assembly (clang, -O0):
<_cacheflush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edx
mov    0x2e80(%rip),%rax
or     (%rax),%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7e(%rip),%rax
or     (%rax),%ecx
mov    0x2e7d(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x10000000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
je     1223 <_cacheflush+0xf3>
movq   $0x0,-0x8(%rbp)
cmpq   $0x10000000,-0x8(%rbp)
10
jae    11cc <_cacheflush+0x9c>
mov    -0x8(%rbp),%rax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119c <_cacheflush+0x6c>
movq   $0x0,-0x8(%rbp)
cmpq   $0x10000000,-0x8(%rbp)
10
jae    1215 <_cacheflush+0xe5>
mov    -0x8(%rbp),%rax
movsbl %al,%eax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <_cacheflush+0xa4>
mov    -0x10(%rbp),%rdi
mov    $0x10000000,%esi
call   1050 <munmap@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cacheflush>:
push   %r15
push   %r14
push   %rbx
mov    0x2ebc(%rip),%rax
mov    0x2e85(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e72(%rip),%rax
mov    0x2e83(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e80(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x10000000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r14
mov    0x2e37(%rip),%rax
cmp    %r14,(%rax)
je     12ae <_cacheflush+0x17e>
movdqa 0xe6e(%rip),%xmm2
mov    $0x70,%eax
movdqa 0xe70(%rip),%xmm8
movdqa 0xe77(%rip),%xmm9
movdqa 0xe7f(%rip),%xmm3
movdqa 0xe87(%rip),%xmm4
movdqa 0xe8f(%rip),%xmm5
movdqa 0xe97(%rip),%xmm6
movdqa 0xe9f(%rip),%xmm7
movdqa 0xea7(%rip),%xmm1
nopl   0x0(%rax)
movdqu %xmm2,-0x70(%r14,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm8,%xmm0
movdqu %xmm0,-0x60(%r14,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm9,%xmm0
movdqu %xmm0,-0x50(%r14,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm3,%xmm0
movdqu %xmm0,-0x40(%r14,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm4,%xmm0
movdqu %xmm0,-0x30(%r14,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm5,%xmm0
movdqu %xmm0,-0x20(%r14,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm6,%xmm0
movdqu %xmm0,-0x10(%r14,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm7,%xmm0
movdqu %xmm0,(%r14,%rax,1)
pxor   %xmm1,%xmm2
sub    $0xffffffffffffff80,%rax
cmp    $0x10000070,%rax
jne    11e0 <_cacheflush+0xb0>
xor    %r15d,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%eax
sar    $0x18,%eax
movsbl (%r14,%rbx,1),%ecx
xor    %edi,%edi
cmp    %ecx,%eax
sete   %dil
call   1040 <assert@plt>
add    $0x1,%rbx
add    $0x1000000,%r15d
cmp    $0x10000000,%rbx
jne    1270 <_cacheflush+0x140>
mov    %r14,%rdi
mov    $0x10000000,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <munmap@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_FAILED = global i8* null
define void @_cacheflush() {
%1 = alloca i64
%2 = alloca i8*
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %3, %4
%6 = load i32, i32* @MAP_PRIVATE
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = or i32 %6, %7
%9 = load i32, i32* @MAP_NORESERVE
%10 = or i32 %8, %9
%11 = call i8* @mmap(i32* null, i32 268435456, i32 %5, i32 %10, i32 -1, i32 0)
store i8* %11, i8** %2
%12 = load i8*, i8** @MAP_FAILED
%13 = load i8*, i8** %2
%14 = icmp ne i8* %12, %13
br i1 %14, label %15, label %50
15: ; preds = %0
store i64 0, i64* %1
br label %16
16: ; preds = %25, %15
%17 = load i64, i64* %1
%18 = icmp ult i64 %17, 268435456
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i64, i64* %1
%21 = trunc i64 %20 to i8
%22 = load i8*, i8** %2
%23 = load i64, i64* %1
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 %21, i8* %24
br label %25
25: ; preds = %19
%26 = load i64, i64* %1
%27 = add i64 %26, 1
store i64 %27, i64* %1
br label %16
28: ; preds = %16
store i64 0, i64* %1
br label %29
29: ; preds = %44, %28
%30 = load i64, i64* %1
%31 = icmp ult i64 %30, 268435456
br i1 %31, label %32, label %47
32: ; preds = %29
%33 = load i64, i64* %1
%34 = trunc i64 %33 to i8
%35 = sext i8 %34 to i32
%36 = load i8*, i8** %2
%37 = load i64, i64* %1
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %35, %40
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
br label %44
44: ; preds = %32
%45 = load i64, i64* %1
%46 = add i64 %45, 1
store i64 %46, i64* %1
br label %29
47: ; preds = %29
%48 = load i8*, i8** %2
%49 = call i32 @munmap(i8* %48, i32 268435456)
br label %50
50: ; preds = %47, %0
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_FAILED = global i8* null
define void @_cacheflush() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_PRIVATE
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = or i32 %5, %4
%7 = load i32, i32* @MAP_NORESERVE
%8 = or i32 %6, %7
%9 = tail call i8* @mmap(i32* null, i32 268435456, i32 %3, i32 %8, i32 -1, i32 0)
%10 = load i8*, i8** @MAP_FAILED
%11 = icmp eq i8* %10, %9
br i1 %11, label %63, label %12
12: ; preds = %0, %12
%13 = phi i64 [ %45, %12 ], [ 0, %0 ]
%14 = phi <16 x i8> [ %46, %12 ], [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %0 ]
%15 = getelementptr inbounds i8, i8* %9, i64 %13
%16 = bitcast i8* %15 to <16 x i8>*
store <16 x i8> %14, <16 x i8>* %16
%17 = or i64 %13, 16
%18 = add <16 x i8> %14, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%19 = getelementptr inbounds i8, i8* %9, i64 %17
%20 = bitcast i8* %19 to <16 x i8>*
store <16 x i8> %18, <16 x i8>* %20
%21 = or i64 %13, 32
%22 = add <16 x i8> %14, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%23 = getelementptr inbounds i8, i8* %9, i64 %21
%24 = bitcast i8* %23 to <16 x i8>*
store <16 x i8> %22, <16 x i8>* %24
%25 = or i64 %13, 48
%26 = add <16 x i8> %14, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%27 = getelementptr inbounds i8, i8* %9, i64 %25
%28 = bitcast i8* %27 to <16 x i8>*
store <16 x i8> %26, <16 x i8>* %28
%29 = or i64 %13, 64
%30 = add <16 x i8> %14, <i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64>
%31 = getelementptr inbounds i8, i8* %9, i64 %29
%32 = bitcast i8* %31 to <16 x i8>*
store <16 x i8> %30, <16 x i8>* %32
%33 = or i64 %13, 80
%34 = add <16 x i8> %14, <i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80>
%35 = getelementptr inbounds i8, i8* %9, i64 %33
%36 = bitcast i8* %35 to <16 x i8>*
store <16 x i8> %34, <16 x i8>* %36
%37 = or i64 %13, 96
%38 = add <16 x i8> %14, <i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96>
%39 = getelementptr inbounds i8, i8* %9, i64 %37
%40 = bitcast i8* %39 to <16 x i8>*
store <16 x i8> %38, <16 x i8>* %40
%41 = or i64 %13, 112
%42 = add <16 x i8> %14, <i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112>
%43 = getelementptr inbounds i8, i8* %9, i64 %41
%44 = bitcast i8* %43 to <16 x i8>*
store <16 x i8> %42, <16 x i8>* %44
%45 = add nuw nsw i64 %13, 128
%46 = xor <16 x i8> %14, <i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128>
%47 = icmp eq i64 %45, 268435456
br i1 %47, label %48, label %12
48: ; preds = %12, %48
%49 = phi i64 [ %59, %48 ], [ 0, %12 ]
%50 = trunc i64 %49 to i32
%51 = shl i32 %50, 24
%52 = ashr exact i32 %51, 24
%53 = getelementptr inbounds i8, i8* %9, i64 %49
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %52, %55
%57 = zext i1 %56 to i32
%58 = tail call i32 @assert(i32 %57)
%59 = add nuw nsw i64 %49, 1
%60 = icmp eq i64 %59, 268435456
br i1 %60, label %61, label %48
61: ; preds = %48
%62 = tail call i32 @munmap(i8* %9, i32 268435456)
br label %63
63: ; preds = %61, %0
ret void
}