#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 uint32_t;

/* Variables and functions */
bool HibernateTamperEventsGet(uint32_t ui32Index, uint32_t *pui32RTC,
                              uint32_t *pui32Event) {
  uint32_t ui32Reg;
  ;
  ;
  ;
  ui32Reg = (*((volatile uint32_t *)(0x400FC4E0 + ((ui32Index << 3) + 4))));
  if (ui32Reg == 0) {
    return (false);
  }
  *pui32Event = ui32Reg;
  *pui32RTC = (*((volatile uint32_t *)(0x400FC4E0 + (ui32Index << 3))));
  if (((*((volatile uint32_t *)(0x400FC300))) & (0x00000001 | 0x00000004)) ==
      (0x00000001 | 0x00000004)) {
    if ((*((volatile uint32_t *)(0x400FC310))) & 0x00400000) {
      ui32Reg = ((*pui32RTC & 0X0001f000) + (12 << 12)) & 0X0001f000;
      *pui32RTC &= ~0X0001f000;
      *pui32RTC |= ui32Reg;
    }
  }
  return (true);
}


x86 assembly (clang, -O0):
<HibernateTamperEventsGet>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x3,%eax
add    $0x4,%eax
add    $0x400fc4e0,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    113a <HibernateTamperEventsGet+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    11bd <HibernateTamperEventsGet+0xbd>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
shl    $0x3,%eax
add    $0x400fc4e0,%eax
cltq
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x400fc300,%eax
mov    (%rax),%eax
and    $0x5,%eax
cmp    $0x5,%eax
jne    11b6 <HibernateTamperEventsGet+0xb6>
mov    $0x400fc310,%eax
mov    (%rax),%eax
and    $0x400000,%eax
cmp    $0x0,%eax
je     11b1 <HibernateTamperEventsGet+0xb1>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x1f000,%eax
add    $0xc000,%eax
and    $0x1f000,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffe0fff,%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    11b6 <HibernateTamperEventsGet+0xb6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<HibernateTamperEventsGet>:
lea    0x400fc4e4(,%rdi,8),%eax
cltq
mov    (%rax),%eax
test   %eax,%eax
je     115e <HibernateTamperEventsGet+0x5e>
shl    $0x3,%edi
mov    %eax,(%rdx)
movslq %edi,%rax
mov    0x400fc4e0(%rax),%ecx
mov    %ecx,(%rsi)
mov    0x400fc300,%edx
not    %edx
mov    $0x1,%eax
test   $0x5,%dl
jne    115d <HibernateTamperEventsGet+0x5d>
testl  $0x400000,0x400fc310
je     115d <HibernateTamperEventsGet+0x5d>
mov    %ecx,%edx
and    $0x1f000,%edx
add    $0xc000,%edx
and    $0x1f000,%edx
and    $0xfffe0fff,%ecx
or     %edx,%ecx
mov    %ecx,(%rsi)
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @HibernateTamperEventsGet(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%9 = load i32, i32* %5
%10 = shl i32 %9, 3
%11 = add nsw i32 %10, 4
%12 = add nsw i32 1074775264, %11
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = load volatile i32, i32* %14
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 0, i32* %4
br label %51
19: ; preds = %3
%20 = load i32, i32* %8
%21 = load i32*, i32** %7
store i32 %20, i32* %21
%22 = load i32, i32* %5
%23 = shl i32 %22, 3
%24 = add nsw i32 1074775264, %23
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
%27 = load volatile i32, i32* %26
%28 = load i32*, i32** %6
store i32 %27, i32* %28
%29 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%30 = and i32 %29, 5
%31 = icmp eq i32 %30, 5
br i1 %31, label %32, label %50
32: ; preds = %19
%33 = load volatile i32, i32* inttoptr (i64 1074774800 to i32*)
%34 = and i32 %33, 4194304
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %49
36: ; preds = %32
%37 = load i32*, i32** %6
%38 = load i32, i32* %37
%39 = and i32 %38, 126976
%40 = add nsw i32 %39, 49152
%41 = and i32 %40, 126976
store i32 %41, i32* %8
%42 = load i32*, i32** %6
%43 = load i32, i32* %42
%44 = and i32 %43, -126977
store i32 %44, i32* %42
%45 = load i32, i32* %8
%46 = load i32*, i32** %6
%47 = load i32, i32* %46
%48 = or i32 %47, %45
store i32 %48, i32* %46
br label %49
49: ; preds = %36, %32
br label %50
50: ; preds = %49, %19
store i32 1, i32* %4
br label %51
51: ; preds = %50, %18
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
define i32 @HibernateTamperEventsGet(i32 %0, i32* nocapture %1, i32* nocapture writeonly %2) {
%4 = shl i32 %0, 3
%5 = add i32 %4, 1074775268
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = load volatile i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %3
store i32 %8, i32* %2
%11 = add nsw i32 %4, 1074775264
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = load volatile i32, i32* %13
store i32 %14, i32* %1
%15 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%16 = and i32 %15, 5
%17 = icmp eq i32 %16, 5
br i1 %17, label %18, label %28
18: ; preds = %10
%19 = load volatile i32, i32* inttoptr (i64 1074774800 to i32*)
%20 = and i32 %19, 4194304
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %18
%23 = and i32 %14, 126976
%24 = add nuw nsw i32 %23, 49152
%25 = and i32 %24, 126976
%26 = and i32 %14, -126977
%27 = or i32 %25, %26
store i32 %27, i32* %1
br label %28
28: ; preds = %10, %22, %18, %3
%29 = phi i32 [ 0, %3 ], [ 1, %18 ], [ 1, %22 ], [ 1, %10 ]
ret i32 %29
}