#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 */
typedef int tilerfeatures;
typedef int l3features;
typedef int l2features;
typedef int /*<<< orphan*/ gpuid;

/* Variables and functions */
int Mali_RdReg(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printk(char *, int, int, ...);
void Mali_Identify(void) {
  int gpuid = Mali_RdReg(0x20, 0, 0);
  int l2features, l3features, tilerfeatures, memfeatures;
  int mmufeatures, aspresent, jspresent;
  printk(
      "GPU ID=0x%08x ProductID=0x%04x, Version=r%1dp%1d Version_status=%1d\n",
      (gpuid)&0XFFFFFFFF, (gpuid >> 16) & 0xFFFF, (gpuid >> 12) & 0xF,
      (gpuid >> 4) & 0xFF, (gpuid)&0xF);
  l2features = Mali_RdReg(0x20, 0, 0x4);
  printk("L2. LineSize=%2d Associativity=%2d CacheSize=%dkB BusWidth=%3d\n",
         1 << ((l2features)&0xFF), 1 << ((l2features >> 8) & 0xFF),
         (1 << ((l2features >> 16) & 0xFF)) >> 10,
         1 << ((l2features >> 24) & 0xFF));
  l3features = Mali_RdReg(0x20, 0, 0x8);
  if (l3features != 0) {
    printk("L3. LineSize=%3d Associativity=%3d CacheSize=%dkB BusWidth=%3d\n",
           1 << ((l3features)&0xFF), 1 << ((l3features >> 8) & 0xFF),
           (1 << ((l3features >> 16) & 0xFF)) >> 10,
           1 << ((l3features >> 24) & 0xFF));
  };
  tilerfeatures = Mali_RdReg(0x20, 0, 0xC);
  printk("Tiler. BinSize=%4d MaxActiveLevels=%4d\n",
         1 << ((tilerfeatures)&0x3F), 1 << ((tilerfeatures >> 8) & 0xF));
  memfeatures = Mali_RdReg(0x20, 0, 0x10);
  printk(
      "MemFeatures. CoherentCoreGroup=%d CoherentSuperGroup=%d L2 Slices=%d\n",
      memfeatures & 0x1, (memfeatures > 1) & 0x1,
      (((memfeatures >> 8) & 0xf) + 1));
  mmufeatures = Mali_RdReg(0x20, 0, 0x14);
  printk("MMUFeatures. VA_BITS=%d PA_BITS=%d\n", mmufeatures & 0xFF,
         (mmufeatures >> 8) & 0xFF);
  aspresent = Mali_RdReg(0x20, 0, 0x18);
  jspresent = Mali_RdReg(0x20, 0, 0x1C);
  printk("ASPresent=%08x JSPresent=%08x\n", aspresent, jspresent);
}


x86 assembly (clang, -O0):
<Mali_Identify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x20,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
and    $0xffffffff,%esi
mov    -0x4(%rbp),%edx
sar    $0x10,%edx
and    $0xffff,%edx
mov    -0x4(%rbp),%ecx
sar    $0xc,%ecx
and    $0xf,%ecx
mov    -0x4(%rbp),%r8d
sar    $0x4,%r8d
and    $0xff,%r8d
mov    -0x4(%rbp),%r9d
and    $0xf,%r9d
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
and    $0xff,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x8(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sar    $0xa,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    $0x1,%r8d
shl    %cl,%r8d
mov    -0x24(%rbp),%ecx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     126f <Mali_Identify+0x14f>
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0xc(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sar    $0xa,%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    $0x1,%r8d
shl    %cl,%r8d
mov    -0x28(%rbp),%ecx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
and    $0x3f,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x10(%rbp),%ecx
sar    $0x8,%ecx
and    $0xf,%ecx
mov    $0x1,%edx
shl    %cl,%edx
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
and    $0x1,%esi
cmpl   $0x1,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edx
and    $0x1,%edx
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
and    $0xf,%ecx
add    $0x1,%ecx
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
and    $0xff,%esi
mov    -0x18(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x1c,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mali_Identify>:
push   %rbp
push   %rbx
push   %rax
mov    $0x20,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,%edx
shr    $0x10,%edx
mov    %eax,%ecx
shr    $0xc,%ecx
and    $0xf,%ecx
mov    %eax,%esi
shr    $0x4,%esi
movzbl %sil,%r8d
mov    %eax,%r9d
and    $0xf,%r9d
lea    0xeab(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <Mali_RdReg@plt>
mov    $0x1,%esi
mov    %eax,%ecx
shl    %cl,%esi
mov    %eax,%ecx
shr    $0x8,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %eax,%ecx
shr    $0x10,%ecx
mov    $0x1,%ebx
shl    %cl,%ebx
mov    $0x1,%ebp
sar    $0xa,%ebx
shr    $0x18,%eax
mov    $0x1,%r8d
mov    %eax,%ecx
shl    %cl,%r8d
lea    0xe98(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <Mali_RdReg@plt>
test   %eax,%eax
je     120d <Mali_Identify+0xed>
mov    $0x1,%esi
mov    %eax,%ecx
shl    %cl,%esi
mov    %eax,%ecx
shr    $0x8,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %eax,%ecx
shr    $0x10,%ecx
mov    $0x1,%ebx
shl    %cl,%ebx
sar    $0xa,%ebx
shr    $0x18,%eax
mov    $0x1,%r8d
mov    %eax,%ecx
shl    %cl,%r8d
lea    0xe81(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,%ecx
mov    $0x1,%esi
shl    %cl,%esi
shr    $0x8,%ecx
and    $0xf,%cl
shl    %cl,%ebp
lea    0xe8f(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,%esi
and    $0x1,%esi
xor    %edx,%edx
cmp    $0x2,%eax
setge  %dl
shr    $0x8,%eax
and    $0xf,%eax
lea    0x1(%rax),%ecx
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <Mali_RdReg@plt>
movzbl %al,%esi
movzbl %ah,%edx
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1030 <printk@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,%ebx
mov    $0x20,%edi
xor    %esi,%esi
mov    $0x1c,%edx
call   1040 <Mali_RdReg@plt>
lea    0xe93(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printk@plt>

LLVM IR (-O0):
@.str = [69 x i8] c"GPU ID=0x%08x ProductID=0x%04x, Version=r%1dp%1d Version_status=%1d\0A\00"
@.str.1 = [64 x i8] c"L2. LineSize=%2d Associativity=%2d CacheSize=%dkB BusWidth=%3d\0A\00"
@.str.2 = [64 x i8] c"L3. LineSize=%3d Associativity=%3d CacheSize=%dkB BusWidth=%3d\0A\00"
@.str.3 = [40 x i8] c"Tiler. BinSize=%4d MaxActiveLevels=%4d\0A\00"
@.str.4 = [70 x i8] c"MemFeatures. CoherentCoreGroup=%d CoherentSuperGroup=%d L2 Slices=%d\0A\00"
@.str.5 = [36 x i8] c"MMUFeatures. VA_BITS=%d PA_BITS=%d\0A\00"
@.str.6 = [31 x i8] c"ASPresent=%08x JSPresent=%08x\0A\00"
define void @Mali_Identify() {
%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 @Mali_RdReg(i32 32, i32 0, i32 0)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = and i32 %10, -1
%12 = load i32, i32* %1
%13 = ashr i32 %12, 16
%14 = and i32 %13, 65535
%15 = load i32, i32* %1
%16 = ashr i32 %15, 12
%17 = and i32 %16, 15
%18 = load i32, i32* %1
%19 = ashr i32 %18, 4
%20 = and i32 %19, 255
%21 = load i32, i32* %1
%22 = and i32 %21, 15
%23 = call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14, i32 %17, i32 %20, i32 %22)
%24 = call i32 @Mali_RdReg(i32 32, i32 0, i32 4)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = and i32 %25, 255
%27 = shl i32 1, %26
%28 = load i32, i32* %2
%29 = ashr i32 %28, 8
%30 = and i32 %29, 255
%31 = shl i32 1, %30
%32 = load i32, i32* %2
%33 = ashr i32 %32, 16
%34 = and i32 %33, 255
%35 = shl i32 1, %34
%36 = ashr i32 %35, 10
%37 = load i32, i32* %2
%38 = ashr i32 %37, 24
%39 = and i32 %38, 255
%40 = shl i32 1, %39
%41 = call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %31, i32 %36, i32 %40)
%42 = call i32 @Mali_RdReg(i32 32, i32 0, i32 8)
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %63
45: ; preds = %0
%46 = load i32, i32* %3
%47 = and i32 %46, 255
%48 = shl i32 1, %47
%49 = load i32, i32* %3
%50 = ashr i32 %49, 8
%51 = and i32 %50, 255
%52 = shl i32 1, %51
%53 = load i32, i32* %3
%54 = ashr i32 %53, 16
%55 = and i32 %54, 255
%56 = shl i32 1, %55
%57 = ashr i32 %56, 10
%58 = load i32, i32* %3
%59 = ashr i32 %58, 24
%60 = and i32 %59, 255
%61 = shl i32 1, %60
%62 = call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %52, i32 %57, i32 %61)
br label %63
63: ; preds = %45, %0
%64 = call i32 @Mali_RdReg(i32 32, i32 0, i32 12)
store i32 %64, i32* %4
%65 = load i32, i32* %4
%66 = and i32 %65, 63
%67 = shl i32 1, %66
%68 = load i32, i32* %4
%69 = ashr i32 %68, 8
%70 = and i32 %69, 15
%71 = shl i32 1, %70
%72 = call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %67, i32 %71)
%73 = call i32 @Mali_RdReg(i32 32, i32 0, i32 16)
store i32 %73, i32* %5
%74 = load i32, i32* %5
%75 = and i32 %74, 1
%76 = load i32, i32* %5
%77 = icmp sgt i32 %76, 1
%78 = zext i1 %77 to i32
%79 = and i32 %78, 1
%80 = load i32, i32* %5
%81 = ashr i32 %80, 8
%82 = and i32 %81, 15
%83 = add nsw i32 %82, 1
%84 = call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.4, i64 0, i64 0), i32 %75, i32 %79, i32 %83)
%85 = call i32 @Mali_RdReg(i32 32, i32 0, i32 20)
store i32 %85, i32* %6
%86 = load i32, i32* %6
%87 = and i32 %86, 255
%88 = load i32, i32* %6
%89 = ashr i32 %88, 8
%90 = and i32 %89, 255
%91 = call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %87, i32 %90)
%92 = call i32 @Mali_RdReg(i32 32, i32 0, i32 24)
store i32 %92, i32* %7
%93 = call i32 @Mali_RdReg(i32 32, i32 0, i32 28)
store i32 %93, i32* %8
%94 = load i32, i32* %7
%95 = load i32, i32* %8
%96 = call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %94, i32 %95)
ret void
}

LLVM IR (-O2):
@.str = [69 x i8] c"GPU ID=0x%08x ProductID=0x%04x, Version=r%1dp%1d Version_status=%1d\0A\00"
@.str.1 = [64 x i8] c"L2. LineSize=%2d Associativity=%2d CacheSize=%dkB BusWidth=%3d\0A\00"
@.str.2 = [64 x i8] c"L3. LineSize=%3d Associativity=%3d CacheSize=%dkB BusWidth=%3d\0A\00"
@.str.3 = [40 x i8] c"Tiler. BinSize=%4d MaxActiveLevels=%4d\0A\00"
@.str.4 = [70 x i8] c"MemFeatures. CoherentCoreGroup=%d CoherentSuperGroup=%d L2 Slices=%d\0A\00"
@.str.5 = [36 x i8] c"MMUFeatures. VA_BITS=%d PA_BITS=%d\0A\00"
@.str.6 = [31 x i8] c"ASPresent=%08x JSPresent=%08x\0A\00"
define void @Mali_Identify() {
%1 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 0)
%2 = lshr i32 %1, 16
%3 = lshr i32 %1, 12
%4 = and i32 %3, 15
%5 = lshr i32 %1, 4
%6 = and i32 %5, 255
%7 = and i32 %1, 15
%8 = tail call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %4, i32 %6, i32 %7)
%9 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 4)
%10 = and i32 %9, 255
%11 = shl nuw i32 1, %10
%12 = lshr i32 %9, 8
%13 = and i32 %12, 255
%14 = shl nuw i32 1, %13
%15 = lshr i32 %9, 16
%16 = and i32 %15, 255
%17 = shl nuw i32 1, %16
%18 = ashr i32 %17, 10
%19 = lshr i32 %9, 24
%20 = shl nuw i32 1, %19
%21 = tail call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14, i32 %18, i32 %20)
%22 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 8)
%23 = icmp eq i32 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %0
%25 = and i32 %22, 255
%26 = shl nuw i32 1, %25
%27 = lshr i32 %22, 8
%28 = and i32 %27, 255
%29 = shl nuw i32 1, %28
%30 = lshr i32 %22, 16
%31 = and i32 %30, 255
%32 = shl nuw i32 1, %31
%33 = ashr i32 %32, 10
%34 = lshr i32 %22, 24
%35 = shl nuw i32 1, %34
%36 = tail call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %29, i32 %33, i32 %35)
br label %37
37: ; preds = %24, %0
%38 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 12)
%39 = and i32 %38, 63
%40 = shl nuw i32 1, %39
%41 = lshr i32 %38, 8
%42 = and i32 %41, 15
%43 = shl nuw nsw i32 1, %42
%44 = tail call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %43)
%45 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 16)
%46 = and i32 %45, 1
%47 = icmp sgt i32 %45, 1
%48 = zext i1 %47 to i32
%49 = lshr i32 %45, 8
%50 = and i32 %49, 15
%51 = add nuw nsw i32 %50, 1
%52 = tail call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %48, i32 %51)
%53 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 20)
%54 = and i32 %53, 255
%55 = lshr i32 %53, 8
%56 = and i32 %55, 255
%57 = tail call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %54, i32 %56)
%58 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 24)
%59 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 28)
%60 = tail call i32 (i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %58, i32 %59)
ret void
}