#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 rsysreg(int);
ramfill() {
  int dbytes, ibytes, isets, dsets;
  int icconf, dcconf;
  int cachectrl;
  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;
  cache_disable();
  ifill(ibytes);
  dfill(dbytes);
  flush();
  cache_enable();
}


x86 assembly (clang, -O0):
<ramfill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x8,%edi
call   1040 <rsysreg@plt>
mov    %eax,-0x18(%rbp)
mov    $0xc,%edi
call   1040 <rsysreg@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x18,%eax
and    $0x3,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x18,%eax
and    $0x3,%eax
add    $0x1,%eax
mov    %eax,-0x14(%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,-0xc(%rbp)
mov    -0x1c(%rbp),%ecx
sar    $0x14,%ecx
and    $0xf,%ecx
add    $0xa,%ecx
mov    $0x1,%eax
shl    %cl,%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <cache_disable@plt>
mov    -0xc(%rbp),%edi
call   1070 <ifill@plt>
mov    -0x8(%rbp),%edi
call   1080 <dfill@plt>
mov    $0x0,%al
call   1030 <flush@plt>
mov    $0x0,%al
call   1050 <cache_enable@plt>
mov    -0x4(%rbp),%eax
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,%edx
shr    $0x18,%edx
and    $0x3,%edx
add    $0x1,%edx
mov    %eax,%esi
shr    $0x18,%esi
and    $0x3,%esi
add    $0x1,%esi
shr    $0x14,%ebx
and    $0xf,%bl
mov    $0x400,%ebp
mov    %ebx,%ecx
shl    %cl,%ebp
mov    $0x400,%ebx
imul   %edx,%ebp
shr    $0x14,%eax
and    $0xf,%al
mov    %eax,%ecx
shl    %cl,%ebx
imul   %esi,%ebx
xor    %eax,%eax
call   1060 <cache_disable@plt>
mov    %ebp,%edi
call   1070 <ifill@plt>
mov    %ebx,%edi
call   1080 <dfill@plt>
xor    %eax,%eax
call   1030 <flush@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <cache_enable@plt>

LLVM IR (-O0):
define i32 @ramfill() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = call i32 @rsysreg(i32 8)
store i32 %9, i32* %6
%10 = call i32 @rsysreg(i32 12)
store i32 %10, i32* %7
%11 = load i32, i32* %6
%12 = ashr i32 %11, 24
%13 = and i32 %12, 3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = load i32, i32* %7
%16 = ashr i32 %15, 24
%17 = and i32 %16, 3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
%19 = load i32, i32* %6
%20 = ashr i32 %19, 20
%21 = and i32 %20, 15
%22 = add nsw i32 %21, 10
%23 = shl i32 1, %22
%24 = load i32, i32* %4
%25 = mul nsw i32 %23, %24
store i32 %25, i32* %3
%26 = load i32, i32* %7
%27 = ashr i32 %26, 20
%28 = and i32 %27, 15
%29 = add nsw i32 %28, 10
%30 = shl i32 1, %29
%31 = load i32, i32* %5
%32 = mul nsw i32 %30, %31
store i32 %32, i32* %2
%33 = call i32 (...) @cache_disable()
%34 = load i32, i32* %3
%35 = call i32 @ifill(i32 %34)
%36 = load i32, i32* %2
%37 = call i32 @dfill(i32 %36)
%38 = call i32 (...) @flush()
%39 = call i32 (...) @cache_enable()
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
define i32 @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 (...) @cache_disable()
%18 = tail call i32 @ifill(i32 %12)
%19 = tail call i32 @dfill(i32 %16)
%20 = tail call i32 (...) @flush()
%21 = tail call i32 (...) @cache_enable()
ret i32 undef
}