#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*/ cache_disable();
int /*<<< orphan*/ cache_enable();
int /*<<< orphan*/ dfill(int);
int /*<<< orphan*/ flush();
int /*<<< orphan*/ ifill(int);
int /*<<< orphan*/ printf(char *, ...);
int rsysreg(int);
void ramfill(void) {
  int dbytes, ibytes, isets, dsets;
  int icconf, dcconf;
  icconf = rsysreg(8);
  dcconf = rsysreg(12);
  isets = ((icconf >> 24) & 3) + 1;
  dsets = ((dcconf >> 24) & 3) + 1;
  ibytes = (1 << (((icconf >> 20) & 0xF) + 10)) * isets;
  dbytes = (1 << (((dcconf >> 20) & 0xF) + 10)) * dsets;
  printf("isets: %i dsets: %i ibytes: %i dbytes: %i\n", isets, dsets, ibytes,
         dbytes);
  printf("Disable Cache\n");
  cache_disable();
  ifill(ibytes);
  dfill(dbytes);
  printf("Flush Cache\n");
  flush();
  printf("Enable Cache\n");
  cache_enable();
}


x86 assembly (clang, -O0):
<ramfill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x8,%edi
call   1040 <rsysreg@plt>
mov    %eax,-0x14(%rbp)
mov    $0xc,%edi
call   1040 <rsysreg@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x18,%eax
and    $0x3,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x18,%eax
and    $0x3,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
sar    $0x14,%ecx
and    $0xf,%ecx
add    $0xa,%ecx
mov    $0x1,%eax
shl    %cl,%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%ecx
sar    $0x14,%ecx
and    $0xf,%ecx
add    $0xa,%ecx
mov    $0x1,%eax
shl    %cl,%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%r8d
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1060 <cache_disable@plt>
mov    -0x8(%rbp),%edi
call   1080 <ifill@plt>
mov    -0x4(%rbp),%edi
call   1090 <dfill@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1030 <flush@plt>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1050 <cache_enable@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ramfill>:
push   %rbp
push   %rbx
push   %rax
mov    $0x8,%edi
call   1040 <rsysreg@plt>
mov    %eax,%ebx
mov    $0xc,%edi
call   1040 <rsysreg@plt>
mov    %ebx,%esi
shr    $0x18,%esi
and    $0x3,%esi
add    $0x1,%esi
mov    %eax,%edx
shr    $0x18,%edx
and    $0x3,%edx
add    $0x1,%edx
shr    $0x14,%ebx
and    $0xf,%bl
mov    $0x400,%ebp
mov    %ebx,%ecx
shl    %cl,%ebp
mov    $0x400,%ebx
imul   %esi,%ebp
shr    $0x14,%eax
and    $0xf,%al
mov    %eax,%ecx
shl    %cl,%ebx
imul   %edx,%ebx
lea    0xe27(%rip),%rdi
mov    %ebp,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe3f(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1070 <cache_disable@plt>
mov    %ebp,%edi
call   1090 <ifill@plt>
mov    %ebx,%edi
call   10a0 <dfill@plt>
lea    0xe2c(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1030 <flush@plt>
lea    0xe25(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <cache_enable@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"isets: %i dsets: %i ibytes: %i dbytes: %i\0A\00"
@.str.1 = [15 x i8] c"Disable Cache\0A\00"
@.str.2 = [13 x i8] c"Flush Cache\0A\00"
@.str.3 = [14 x i8] c"Enable Cache\0A\00"
define void @ramfill() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 @rsysreg(i32 8)
store i32 %7, i32* %5
%8 = call i32 @rsysreg(i32 12)
store i32 %8, i32* %6
%9 = load i32, i32* %5
%10 = ashr i32 %9, 24
%11 = and i32 %10, 3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = load i32, i32* %6
%14 = ashr i32 %13, 24
%15 = and i32 %14, 3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
%17 = load i32, i32* %5
%18 = ashr i32 %17, 20
%19 = and i32 %18, 15
%20 = add nsw i32 %19, 10
%21 = shl i32 1, %20
%22 = load i32, i32* %3
%23 = mul nsw i32 %21, %22
store i32 %23, i32* %2
%24 = load i32, i32* %6
%25 = ashr i32 %24, 20
%26 = and i32 %25, 15
%27 = add nsw i32 %26, 10
%28 = shl i32 1, %27
%29 = load i32, i32* %4
%30 = mul nsw i32 %28, %29
store i32 %30, i32* %1
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = load i32, i32* %2
%34 = load i32, i32* %1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32, i32 %33, i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 (...) @cache_disable()
%38 = load i32, i32* %2
%39 = call i32 @ifill(i32 %38)
%40 = load i32, i32* %1
%41 = call i32 @dfill(i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 (...) @flush()
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 (...) @cache_enable()
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"isets: %i dsets: %i ibytes: %i dbytes: %i\0A\00"
@str = [14 x i8] c"Disable Cache\00"
@str.4 = [12 x i8] c"Flush Cache\00"
@str.5 = [13 x i8] c"Enable Cache\00"
define void @ramfill() {
%1 = tail call i32 @rsysreg(i32 8)
%2 = tail call i32 @rsysreg(i32 12)
%3 = lshr i32 %1, 24
%4 = and i32 %3, 3
%5 = add nuw nsw i32 %4, 1
%6 = lshr i32 %2, 24
%7 = and i32 %6, 3
%8 = add nuw nsw i32 %7, 1
%9 = lshr i32 %1, 20
%10 = and i32 %9, 15
%11 = shl nuw nsw i32 1024, %10
%12 = mul nuw nsw i32 %11, %5
%13 = lshr i32 %2, 20
%14 = and i32 %13, 15
%15 = shl nuw nsw i32 1024, %14
%16 = mul nuw nsw i32 %15, %8
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8, i32 %12, i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 (...) @cache_disable()
%20 = tail call i32 @ifill(i32 %12)
%21 = tail call i32 @dfill(i32 %16)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
%23 = tail call i32 (...) @flush()
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%25 = tail call i32 (...) @cache_enable()
ret void
}