#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*/ L2_cache_set_mode(int);
int /*<<< orphan*/ flush_and_invalidate();
void cache_control(unsigned int command) {
  unsigned int cfg;
  unsigned int *mar =
      (unsigned int *)0x01848000 + ((unsigned int)0x80000000 >> 24);
  unsigned int *mar_e =
      (unsigned int *)0x01848000 + ((unsigned int)0xFFFFFFFF >> 24);
  if (command == 0) {
    cfg = 7;
    L2_cache_set_mode(0x7);
  } else {
    cfg = 0;
    L2_cache_set_mode(0x0);
  }
  do {
    *((volatile unsigned int *)(0x01840020)) = (cfg);
    (cfg) = *((volatile unsigned int *)(0x01840020));
  } while (0);
  do {
    *((volatile unsigned int *)(0x01840040)) = (cfg);
    (cfg) = *((volatile unsigned int *)(0x01840040));
  } while (0);
  ;
  flush_and_invalidate();
  for (; mar <= mar_e; mar++) {
    if (command == 0)
      *mar |= (1 << 0);
    else
      *mar &= ~(1 << 0);
  };
}


x86 assembly (clang, -O0):
<cache_control>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1848000,%eax
add    $0x200,%rax
mov    %rax,-0x10(%rbp)
mov    $0x1848000,%eax
add    $0x3fc,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1169 <cache_control+0x49>
movl   $0x7,-0x8(%rbp)
mov    $0x7,%edi
call   1040 <L2_cache_set_mode@plt>
jmp    1177 <cache_control+0x57>
movl   $0x0,-0x8(%rbp)
xor    %edi,%edi
call   1040 <L2_cache_set_mode@plt>
jmp    117c <cache_control+0x5c>
mov    -0x8(%rbp),%ecx
mov    $0x1840020,%eax
mov    %ecx,(%rax)
mov    $0x1840020,%eax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1195 <cache_control+0x75>
mov    -0x8(%rbp),%ecx
mov    $0x1840040,%eax
mov    %ecx,(%rax)
mov    $0x1840040,%eax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <flush_and_invalidate@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
ja     11f9 <cache_control+0xd9>
cmpl   $0x0,-0x4(%rbp)
jne    11d8 <cache_control+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
jmp    11e3 <cache_control+0xc3>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffffffe,%ecx
mov    %ecx,(%rax)
jmp    11e8 <cache_control+0xc8>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    11b0 <cache_control+0x90>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_control>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1848230,%ebx
xor    %ebp,%ebp
xor    %r15d,%r15d
test   %edi,%edi
sete   %r15b
mov    $0x7,%r14d
cmovne %ebp,%r14d
mov    %r14d,%edi
call   1040 <L2_cache_set_mode@plt>
mov    %r14d,0x1840020
01
mov    0x1840020,%eax
mov    %eax,0x1840040
mov    0x1840040,%eax
xor    %eax,%eax
call   1030 <flush_and_invalidate@plt>
movd   %r15d,%xmm0
pshufd $0x0,%xmm0,%xmm0
pand   0xe81(%rip),%xmm0
movdqa 0xe89(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
movdqa -0x30(%rbx,%rbp,4),%xmm2
pand   %xmm1,%xmm2
movdqa -0x20(%rbx,%rbp,4),%xmm3
pand   %xmm1,%xmm3
por    %xmm0,%xmm2
por    %xmm0,%xmm3
movdqa %xmm2,-0x30(%rbx,%rbp,4)
movdqa %xmm3,-0x20(%rbx,%rbp,4)
movdqa -0x10(%rbx,%rbp,4),%xmm2
pand   %xmm1,%xmm2
movdqa (%rbx,%rbp,4),%xmm3
pand   %xmm1,%xmm3
por    %xmm0,%xmm2
por    %xmm0,%xmm3
movdqa %xmm2,-0x10(%rbx,%rbp,4)
movdqa %xmm3,(%rbx,%rbp,4)
add    $0x10,%rbp
cmp    $0x80,%rbp
jne    1190 <cache_control+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cache_control(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 %0, i32* %2
store i32* getelementptr inbounds (i32, i32* inttoptr (i64 25460736 to i32*), i64 128), i32** %4
store i32* getelementptr inbounds (i32, i32* inttoptr (i64 25460736 to i32*), i64 255), i32** %5
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
store i32 7, i32* %3
%9 = call i32 @L2_cache_set_mode(i32 7)
br label %12
10: ; preds = %1
store i32 0, i32* %3
%11 = call i32 @L2_cache_set_mode(i32 0)
br label %12
12: ; preds = %10, %8
br label %13
13: ; preds = %12
%14 = load i32, i32* %3
store volatile i32 %14, i32* inttoptr (i64 25428000 to i32*)
%15 = load volatile i32, i32* inttoptr (i64 25428000 to i32*)
store i32 %15, i32* %3
br label %16
16: ; preds = %13
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
store volatile i32 %18, i32* inttoptr (i64 25428032 to i32*)
%19 = load volatile i32, i32* inttoptr (i64 25428032 to i32*)
store i32 %19, i32* %3
br label %20
20: ; preds = %17
%21 = call i32 (...) @flush_and_invalidate()
br label %22
22: ; preds = %38, %20
%23 = load i32*, i32** %4
%24 = load i32*, i32** %5
%25 = icmp ule i32* %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = or i32 %31, 1
store i32 %32, i32* %30
br label %37
33: ; preds = %26
%34 = load i32*, i32** %4
%35 = load i32, i32* %34
%36 = and i32 %35, -2
store i32 %36, i32* %34
br label %37
37: ; preds = %33, %29
br label %38
38: ; preds = %37
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i32 1
store i32* %40, i32** %4
br label %22
41: ; preds = %22
ret void
}

LLVM IR (-O2):
define void @cache_control(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = select i1 %2, i32 7, i32 0
%4 = tail call i32 @L2_cache_set_mode(i32 %3)
store volatile i32 %3, i32* inttoptr (i64 25428000 to i32*)
%5 = load volatile i32, i32* inttoptr (i64 25428000 to i32*)
store volatile i32 %5, i32* inttoptr (i64 25428032 to i32*)
%6 = load volatile i32, i32* inttoptr (i64 25428032 to i32*)
%7 = tail call i32 (...) @flush_and_invalidate()
%8 = insertelement <4 x i1> poison, i1 %2, i64 0
%9 = shufflevector <4 x i1> %8, <4 x i1> poison, <4 x i32> zeroinitializer
%10 = insertelement <4 x i1> poison, i1 %2, i64 0
%11 = shufflevector <4 x i1> %10, <4 x i1> poison, <4 x i32> zeroinitializer
%12 = zext <4 x i1> %9 to <4 x i32>
%13 = zext <4 x i1> %11 to <4 x i32>
%14 = zext <4 x i1> %9 to <4 x i32>
%15 = zext <4 x i1> %11 to <4 x i32>
br label %16
16: ; preds = %16, %1
%17 = phi i64 [ 0, %1 ], [ %43, %16 ]
%18 = getelementptr i32, i32* inttoptr (i64 25461248 to i32*), i64 %17
%19 = bitcast i32* %18 to <4 x i32>*
%20 = load <4 x i32>, <4 x i32>* %19
%21 = getelementptr i32, i32* %18, i64 4
%22 = bitcast i32* %21 to <4 x i32>*
%23 = load <4 x i32>, <4 x i32>* %22
%24 = and <4 x i32> %20, <i32 -2, i32 -2, i32 -2, i32 -2>
%25 = and <4 x i32> %23, <i32 -2, i32 -2, i32 -2, i32 -2>
%26 = or <4 x i32> %24, %12
%27 = or <4 x i32> %25, %13
%28 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %28
%29 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %29
%30 = or i64 %17, 8
%31 = getelementptr i32, i32* inttoptr (i64 25461248 to i32*), i64 %30
%32 = bitcast i32* %31 to <4 x i32>*
%33 = load <4 x i32>, <4 x i32>* %32
%34 = getelementptr i32, i32* %31, i64 4
%35 = bitcast i32* %34 to <4 x i32>*
%36 = load <4 x i32>, <4 x i32>* %35
%37 = and <4 x i32> %33, <i32 -2, i32 -2, i32 -2, i32 -2>
%38 = and <4 x i32> %36, <i32 -2, i32 -2, i32 -2, i32 -2>
%39 = or <4 x i32> %37, %14
%40 = or <4 x i32> %38, %15
%41 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %39, <4 x i32>* %41
%42 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %42
%43 = add nuw nsw i64 %17, 16
%44 = icmp eq i64 %43, 128
br i1 %44, label %45, label %16
45: ; preds = %16
ret void
}