#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 Mali_RdReg(int, int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ printk(char *, unsigned int, char *, unsigned int,
                          unsigned int, ...);
unsigned int Mali_PollReg(unsigned int unit, unsigned int core,
                          unsigned int regnum, unsigned int bit_location,
                          unsigned int val, char *name_str) {
  int regnum_value = Mali_RdReg(0x20, 0, regnum);
  printk("Polling (for %d) of register %s 0x%x bit %d started\n", val, name_str,
         regnum, bit_location);
  if (val) {
    while ((regnum_value & (1 << bit_location)) != (1 << bit_location)) {
      regnum_value = Mali_RdReg(0x20, 0, regnum);
    }
  } else {
    while ((regnum_value & (1 << bit_location)) == (1 << bit_location)) {
      regnum_value = Mali_RdReg(0x20, 0, regnum);
    }
  }
  printk("Polling (for %d) of register %s 0x%x bit %d ended   current "
         "value=0x%x \n",
         val, name_str, regnum, bit_location, regnum_value);
  return regnum_value;
}


x86 assembly (clang, -O0):
<Mali_PollReg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0xc(%rbp),%edx
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
cmpl   $0x0,-0x14(%rbp)
je     11ba <Mali_PollReg+0x9a>
jmp    1179 <Mali_PollReg+0x59>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
je     11b5 <Mali_PollReg+0x95>
mov    -0xc(%rbp),%edx
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x24(%rbp)
jmp    1179 <Mali_PollReg+0x59>
jmp    1200 <Mali_PollReg+0xe0>
jmp    11bf <Mali_PollReg+0x9f>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jne    11fb <Mali_PollReg+0xdb>
mov    -0xc(%rbp),%edx
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <Mali_RdReg@plt>
mov    %eax,-0x24(%rbp)
jmp    11bf <Mali_PollReg+0x9f>
jmp    1200 <Mali_PollReg+0xe0>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mali_PollReg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %edx,%r13d
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <Mali_RdReg@plt>
mov    %eax,%ebx
lea    0xeb4(%rip),%rdi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %r13d,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1030 <printk@plt>
mov    $0x1,%ebp
mov    %r15d,%ecx
shl    %cl,%ebp
mov    %ebx,%eax
and    %ebp,%eax
test   %r12d,%r12d
je     1199 <Mali_PollReg+0x79>
cmp    %ebp,%eax
je     11b7 <Mali_PollReg+0x97>
cs nopw 0x0(%rax,%rax,1)
mov    $0x20,%edi
xor    %esi,%esi
mov    %r13d,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,%ebx
not    %eax
test   %eax,%ebp
jne    1180 <Mali_PollReg+0x60>
jmp    11b7 <Mali_PollReg+0x97>
cmp    %ebp,%eax
jne    11b7 <Mali_PollReg+0x97>
nopl   (%rax)
mov    $0x20,%edi
xor    %esi,%esi
mov    %r13d,%edx
call   1040 <Mali_RdReg@plt>
mov    %eax,%ebx
not    %eax
test   %eax,%ebp
je     11a0 <Mali_PollReg+0x80>
lea    0xe77(%rip),%rdi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %r13d,%ecx
mov    %r15d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1030 <printk@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Polling (for %d) of register %s 0x%x bit %d started\0A\00"
@.str.1 = [73 x i8] c"Polling (for %d) of register %s 0x%x bit %d ended current value=0x%x \0A\00"
define i32 @Mali_PollReg(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%14 = load i32, i32* %9
%15 = call i32 @Mali_RdReg(i32 32, i32 0, i32 %14)
store i32 %15, i32* %13
%16 = load i32, i32* %11
%17 = load i8*, i8** %12
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = call i32 (i8*, i32, i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %17, i32 %18, i32 %19)
%21 = load i32, i32* %11
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %6
br label %24
24: ; preds = %32, %23
%25 = load i32, i32* %13
%26 = load i32, i32* %10
%27 = shl i32 1, %26
%28 = and i32 %25, %27
%29 = load i32, i32* %10
%30 = shl i32 1, %29
%31 = icmp ne i32 %28, %30
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* %9
%34 = call i32 @Mali_RdReg(i32 32, i32 0, i32 %33)
store i32 %34, i32* %13
br label %24
35: ; preds = %24
br label %49
36: ; preds = %6
br label %37
37: ; preds = %45, %36
%38 = load i32, i32* %13
%39 = load i32, i32* %10
%40 = shl i32 1, %39
%41 = and i32 %38, %40
%42 = load i32, i32* %10
%43 = shl i32 1, %42
%44 = icmp eq i32 %41, %43
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = load i32, i32* %9
%47 = call i32 @Mali_RdReg(i32 32, i32 0, i32 %46)
store i32 %47, i32* %13
br label %37
48: ; preds = %37
br label %49
49: ; preds = %48, %35
%50 = load i32, i32* %11
%51 = load i8*, i8** %12
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = load i32, i32* %13
%55 = call i32 (i8*, i32, i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i32 %50, i8* %51, i32 %52, i32 %53, i32 %54)
%56 = load i32, i32* %13
ret i32 %56
}

LLVM IR (-O2):
@.str = [53 x i8] c"Polling (for %d) of register %s 0x%x bit %d started\0A\00"
@.str.1 = [73 x i8] c"Polling (for %d) of register %s 0x%x bit %d ended current value=0x%x \0A\00"
define i32 @Mali_PollReg(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5) {
%7 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 %2)
%8 = tail call i32 (i8*, i32, i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %5, i32 %2, i32 %3)
%9 = icmp eq i32 %4, 0
%10 = shl nuw i32 1, %3
%11 = and i32 %7, %10
%12 = icmp eq i32 %11, %10
br i1 %9, label %14, label %13
13: ; preds = %6
br i1 %12, label %23, label %15
14: ; preds = %6
br i1 %12, label %19, label %23
15: ; preds = %13, %15
%16 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 %2)
%17 = and i32 %16, %10
%18 = icmp eq i32 %17, %10
br i1 %18, label %23, label %15
19: ; preds = %14, %19
%20 = tail call i32 @Mali_RdReg(i32 32, i32 0, i32 %2)
%21 = and i32 %20, %10
%22 = icmp eq i32 %21, %10
br i1 %22, label %19, label %23
23: ; preds = %15, %19, %13, %14
%24 = phi i32 [ %7, %14 ], [ %7, %13 ], [ %20, %19 ], [ %16, %15 ]
%25 = tail call i32 (i8*, i32, i8*, i32, i32, ...) @printk(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i32 %4, i8* %5, i32 %2, i32 %3, i32 %24)
ret i32 %24
}