#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*/ maintest();
int /*<<< orphan*/ report_subtest(int);
int rsysreg(int);
int /*<<< orphan*/ wsysreg(int, int);
void cachetest4(void) {
  int i = 0;
  report_subtest(6);
  if (((rsysreg(8) >> 28) & 3) != 3) {
    i = 3;
  }
  if (((rsysreg(12) >> 28) & 3) != 3) {
    i = 3;
  }
  while (i >= 0) {
    wsysreg(8, (rsysreg(8) & ~(3 << 28)) | (i << 28));
    wsysreg(12, (rsysreg(12) & ~(3 << 28)) | (i << 28));
    maintest();
    i--;
  }
  wsysreg(8, (rsysreg(8) & ~(3 << 28)) | (1 << 28));
  wsysreg(12, (rsysreg(12) & ~(3 << 28)) | (1 << 28));
  wsysreg(0, 0x0081000f);
}


x86 assembly (clang, -O0):
<cachetest4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x6,%edi
call   1040 <report_subtest@plt>
mov    $0x8,%edi
call   1030 <rsysreg@plt>
sar    $0x1c,%eax
and    $0x3,%eax
cmp    $0x3,%eax
je     1179 <cachetest4+0x39>
movl   $0x3,-0x4(%rbp)
mov    $0xc,%edi
call   1030 <rsysreg@plt>
sar    $0x1c,%eax
and    $0x3,%eax
cmp    $0x3,%eax
je     1199 <cachetest4+0x59>
movl   $0x3,-0x4(%rbp)
jmp    119e <cachetest4+0x5e>
cmpl   $0x0,-0x4(%rbp)
jl     1205 <cachetest4+0xc5>
mov    $0x8,%edi
call   1030 <rsysreg@plt>
mov    %eax,%esi
and    $0xcfffffff,%esi
mov    -0x4(%rbp),%eax
shl    $0x1c,%eax
or     %eax,%esi
mov    $0x8,%edi
call   1050 <wsysreg@plt>
mov    $0xc,%edi
call   1030 <rsysreg@plt>
mov    %eax,%esi
and    $0xcfffffff,%esi
mov    -0x4(%rbp),%eax
shl    $0x1c,%eax
or     %eax,%esi
mov    $0xc,%edi
call   1050 <wsysreg@plt>
mov    $0x0,%al
call   1060 <maintest@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    119e <cachetest4+0x5e>
mov    $0x8,%edi
call   1030 <rsysreg@plt>
mov    %eax,%esi
and    $0xcfffffff,%esi
or     $0x10000000,%esi
mov    $0x8,%edi
call   1050 <wsysreg@plt>
mov    $0xc,%edi
call   1030 <rsysreg@plt>
mov    %eax,%esi
and    $0xcfffffff,%esi
or     $0x10000000,%esi
mov    $0xc,%edi
call   1050 <wsysreg@plt>
xor    %edi,%edi
mov    $0x81000f,%esi
call   1050 <wsysreg@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cachetest4>:
push   %rbx
mov    $0x6,%edi
call   1040 <report_subtest@plt>
mov    $0x8,%edi
call   1030 <rsysreg@plt>
mov    %eax,%ebx
not    %ebx
mov    $0xc,%edi
call   1030 <rsysreg@plt>
not    %eax
or     %ebx,%eax
and    $0x30000000,%eax
mov    $0x30000000,%ebx
cmove  %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x8,%edi
call   1030 <rsysreg@plt>
and    $0xcfffffff,%eax
or     %ebx,%eax
mov    $0x8,%edi
mov    %eax,%esi
call   1050 <wsysreg@plt>
mov    $0xc,%edi
call   1030 <rsysreg@plt>
and    $0xcfffffff,%eax
or     %ebx,%eax
mov    $0xc,%edi
mov    %eax,%esi
call   1050 <wsysreg@plt>
xor    %eax,%eax
call   1060 <maintest@plt>
add    $0xf0000000,%ebx
cmp    $0xf0000000,%ebx
jne    1180 <cachetest4+0x40>
mov    $0x8,%edi
call   1030 <rsysreg@plt>
and    $0xcfffffff,%eax
lea    0x10000000(%rax),%esi
mov    $0x8,%edi
call   1050 <wsysreg@plt>
mov    $0xc,%edi
call   1030 <rsysreg@plt>
and    $0xcfffffff,%eax
lea    0x10000000(%rax),%esi
mov    $0xc,%edi
call   1050 <wsysreg@plt>
xor    %edi,%edi
mov    $0x81000f,%esi
pop    %rbx
jmp    1050 <wsysreg@plt>

LLVM IR (-O0):
define void @cachetest4() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @report_subtest(i32 6)
%3 = call i32 @rsysreg(i32 8)
%4 = ashr i32 %3, 28
%5 = and i32 %4, 3
%6 = icmp ne i32 %5, 3
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 3, i32* %1
br label %8
8: ; preds = %7, %0
%9 = call i32 @rsysreg(i32 12)
%10 = ashr i32 %9, 28
%11 = and i32 %10, 3
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 3, i32* %1
br label %14
14: ; preds = %13, %8
br label %15
15: ; preds = %18, %14
%16 = load i32, i32* %1
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = call i32 @rsysreg(i32 8)
%20 = and i32 %19, -805306369
%21 = load i32, i32* %1
%22 = shl i32 %21, 28
%23 = or i32 %20, %22
%24 = call i32 @wsysreg(i32 8, i32 %23)
%25 = call i32 @rsysreg(i32 12)
%26 = and i32 %25, -805306369
%27 = load i32, i32* %1
%28 = shl i32 %27, 28
%29 = or i32 %26, %28
%30 = call i32 @wsysreg(i32 12, i32 %29)
%31 = call i32 (...) @maintest()
%32 = load i32, i32* %1
%33 = add nsw i32 %32, -1
store i32 %33, i32* %1
br label %15
34: ; preds = %15
%35 = call i32 @rsysreg(i32 8)
%36 = and i32 %35, -805306369
%37 = or i32 %36, 268435456
%38 = call i32 @wsysreg(i32 8, i32 %37)
%39 = call i32 @rsysreg(i32 12)
%40 = and i32 %39, -805306369
%41 = or i32 %40, 268435456
%42 = call i32 @wsysreg(i32 12, i32 %41)
%43 = call i32 @wsysreg(i32 0, i32 8454159)
ret void
}

LLVM IR (-O2):
define void @cachetest4() {
%1 = tail call i32 @report_subtest(i32 6)
%2 = tail call i32 @rsysreg(i32 8)
%3 = and i32 %2, 805306368
%4 = icmp eq i32 %3, 805306368
%5 = tail call i32 @rsysreg(i32 12)
%6 = and i32 %5, 805306368
%7 = icmp eq i32 %6, 805306368
%8 = select i1 %7, i1 %4, i1 false
%9 = select i1 %8, i32 0, i32 3
br label %10
10: ; preds = %0, %10
%11 = phi i32 [ %22, %10 ], [ %9, %0 ]
%12 = tail call i32 @rsysreg(i32 8)
%13 = and i32 %12, -805306369
%14 = shl i32 %11, 28
%15 = or i32 %13, %14
%16 = tail call i32 @wsysreg(i32 8, i32 %15)
%17 = tail call i32 @rsysreg(i32 12)
%18 = and i32 %17, -805306369
%19 = or i32 %18, %14
%20 = tail call i32 @wsysreg(i32 12, i32 %19)
%21 = tail call i32 (...) @maintest()
%22 = add nsw i32 %11, -1
%23 = icmp eq i32 %11, 0
br i1 %23, label %24, label %10
24: ; preds = %10
%25 = tail call i32 @rsysreg(i32 8)
%26 = and i32 %25, -805306369
%27 = or i32 %26, 268435456
%28 = tail call i32 @wsysreg(i32 8, i32 %27)
%29 = tail call i32 @rsysreg(i32 12)
%30 = and i32 %29, -805306369
%31 = or i32 %30, 268435456
%32 = tail call i32 @wsysreg(i32 12, i32 %31)
%33 = tail call i32 @wsysreg(i32 0, i32 8454159)
ret void
}