#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 PRCMHIBRegRead(int);
unsigned long PRCMSysResetCauseGet() {
  unsigned long ulWakeupStatus;
  ulWakeupStatus =
      ((*((volatile unsigned long *)(0x4402D000 + 0x0000000C))) & 0xFF);
  if (ulWakeupStatus == 0x00000000) {
    if (PRCMHIBRegRead(0x4402F800 + 0x00000468) & 0x1) {
      ulWakeupStatus = 0x00000007;
      if (((*((volatile unsigned long *)(0x4402E000 + 0x00000188))) &
           (0x00000280)) == 0x00000280) {
        ulWakeupStatus = 0x00000005;
      }
    }
  } else if ((ulWakeupStatus == 0x00000001) &&
             !((*((volatile unsigned long *)(0x4402D000 + 0x00000C7C))) &
               (1 << 2))) {
    if ((*((volatile unsigned long *)(0x4402E000 + 0x00000188))) & (0x1 << 8)) {
      ulWakeupStatus = 0x00000000;
    }
  }
  return ulWakeupStatus;
}


x86 assembly (clang, -O0):
<PRCMSysResetCauseGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x4402d00c,%eax
mov    (%rax),%rax
and    $0xff,%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117f <PRCMSysResetCauseGet+0x6f>
mov    $0x4402fc68,%edi
call   1030 <PRCMHIBRegRead@plt>
and    $0x1,%eax
cmp    $0x0,%eax
je     117a <PRCMSysResetCauseGet+0x6a>
movq   $0x7,-0x8(%rbp)
mov    $0x4402e188,%eax
mov    (%rax),%rax
and    $0x280,%rax
cmp    $0x280,%rax
jne    1175 <PRCMSysResetCauseGet+0x65>
movq   $0x5,-0x8(%rbp)
jmp    117a <PRCMSysResetCauseGet+0x6a>
jmp    11ca <PRCMSysResetCauseGet+0xba>
cmpq   $0x1,-0x8(%rbp)
jne    11c5 <PRCMSysResetCauseGet+0xb5>
mov    $0x4402dc7c,%eax
mov    (%rax),%rax
and    $0x4,%rax
cmp    $0x0,%rax
jne    11c5 <PRCMSysResetCauseGet+0xb5>
mov    $0x4402e188,%eax
mov    (%rax),%rax
and    $0x100,%rax
cmp    $0x0,%rax
je     11c0 <PRCMSysResetCauseGet+0xb0>
movq   $0x0,-0x8(%rbp)
jmp    11c5 <PRCMSysResetCauseGet+0xb5>
jmp    11ca <PRCMSysResetCauseGet+0xba>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PRCMSysResetCauseGet>:
push   %rax
mov    0x4402d00c,%rax
44
cmp    $0x1,%al
je     1133 <PRCMSysResetCauseGet+0x23>
test   %al,%al
jne    1159 <PRCMSysResetCauseGet+0x49>
mov    $0x4402fc68,%edi
call   1030 <PRCMHIBRegRead@plt>
test   $0x1,%al
jne    115e <PRCMSysResetCauseGet+0x4e>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x1,%eax
testq  $0x4,0x4402dc7c
jne    1157 <PRCMSysResetCauseGet+0x47>
xor    %eax,%eax
testq  $0x100,0x4402e188
sete   %al
pop    %rcx
ret
movzbl %al,%eax
pop    %rcx
ret
mov    0x4402e188,%rax
44
not    %eax
xor    %ecx,%ecx
test   $0x280,%eax
setne  %cl
lea    (%rcx,%rcx,1),%rax
add    $0x5,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @PRCMSysResetCauseGet() {
%1 = alloca i64
%2 = load volatile i64, i64* inttoptr (i64 1141035020 to i64*)
%3 = and i64 %2, 255
store i64 %3, i64* %1
%4 = load i64, i64* %1
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %0
%7 = call i32 @PRCMHIBRegRead(i32 1141046376)
%8 = and i32 %7, 1
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %6
store i64 7, i64* %1
%11 = load volatile i64, i64* inttoptr (i64 1141039496 to i64*)
%12 = and i64 %11, 640
%13 = icmp eq i64 %12, 640
br i1 %13, label %14, label %15
14: ; preds = %10
store i64 5, i64* %1
br label %15
15: ; preds = %14, %10
br label %16
16: ; preds = %15, %6
br label %31
17: ; preds = %0
%18 = load i64, i64* %1
%19 = icmp eq i64 %18, 1
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load volatile i64, i64* inttoptr (i64 1141038204 to i64*)
%22 = and i64 %21, 4
%23 = icmp ne i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %20
%25 = load volatile i64, i64* inttoptr (i64 1141039496 to i64*)
%26 = and i64 %25, 256
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i64 0, i64* %1
br label %29
29: ; preds = %28, %24
br label %30
30: ; preds = %29, %20, %17
br label %31
31: ; preds = %30, %16
%32 = load i64, i64* %1
ret i64 %32
}

LLVM IR (-O2):
define i64 @PRCMSysResetCauseGet() {
%1 = load volatile i64, i64* inttoptr (i64 1141035020 to i64*)
%2 = and i64 %1, 255
%3 = trunc i64 %1 to i8
switch i8 %3, label %22 [
i8 0, label %4
i8 1, label %13
]
4: ; preds = %0
%5 = tail call i32 @PRCMHIBRegRead(i32 1141046376)
%6 = and i32 %5, 1
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %4
%9 = load volatile i64, i64* inttoptr (i64 1141039496 to i64*)
%10 = and i64 %9, 640
%11 = icmp eq i64 %10, 640
%12 = select i1 %11, i64 5, i64 7
br label %22
13: ; preds = %0
%14 = load volatile i64, i64* inttoptr (i64 1141038204 to i64*)
%15 = and i64 %14, 4
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load volatile i64, i64* inttoptr (i64 1141039496 to i64*)
%19 = lshr i64 %18, 8
%20 = and i64 %19, 1
%21 = xor i64 %20, 1
br label %22
22: ; preds = %17, %8, %0, %13, %4
%23 = phi i64 [ 0, %4 ], [ 1, %13 ], [ %12, %8 ], [ %2, %0 ], [ %21, %17 ]
ret i64 %23
}