#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 unsigned long *)(0x400FC4E0 + ((ui32Index << 3) + 4))));
  if (ui32Reg == 0) {
    return (0);
  }
  *pui32Event = ui32Reg;
  *pui32RTC = (*((volatile unsigned long *)(0x400FC4E0 + (ui32Index << 3))));
  if (((*((volatile unsigned long *)(0x400FC300))) &
       (0x00000001 | 0x00000004)) == (0x00000001 | 0x00000004)) {
    if ((*((volatile unsigned long *)(0x400FC310))) & 0x00400000) {
      ui32Reg = ((*pui32RTC & 0X0001f000) + (12 << 12)) & 0X0001f000;
      *pui32RTC &= ~0X0001f000;
      *pui32RTC |= ui32Reg;
    }
  }
  return (1);
}


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),%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    113b <HibernateTamperEventsGet+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <HibernateTamperEventsGet+0xc7>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
shl    $0x3,%eax
add    $0x400fc4e0,%eax
cltq
mov    (%rax),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x400fc300,%eax
mov    (%rax),%rax
and    $0x5,%rax
cmp    $0x5,%rax
jne    11c0 <HibernateTamperEventsGet+0xc0>
mov    $0x400fc310,%eax
mov    (%rax),%rax
and    $0x400000,%rax
cmp    $0x0,%rax
je     11bb <HibernateTamperEventsGet+0xbb>
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    11c0 <HibernateTamperEventsGet+0xc0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<HibernateTamperEventsGet>:
lea    0x400fc4e4(,%rdi,8),%eax
cltq
mov    (%rax),%rax
test   %eax,%eax
je     1162 <HibernateTamperEventsGet+0x62>
shl    $0x3,%edi
mov    %eax,(%rdx)
movslq %edi,%rax
mov    0x400fc4e0(%rax),%rcx
mov    %ecx,(%rsi)
mov    0x400fc300,%rdx
40
not    %edx
mov    $0x1,%eax
test   $0x5,%dl
jne    1161 <HibernateTamperEventsGet+0x61>
testq  $0x400000,0x400fc310
je     1161 <HibernateTamperEventsGet+0x61>
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 i64*
%15 = load volatile i64, i64* %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 0, i32* %4
br label %53
20: ; preds = %3
%21 = load i32, i32* %8
%22 = load i32*, i32** %7
store i32 %21, i32* %22
%23 = load i32, i32* %5
%24 = shl i32 %23, 3
%25 = add nsw i32 1074775264, %24
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i64*
%28 = load volatile i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = load i32*, i32** %6
store i32 %29, i32* %30
%31 = load volatile i64, i64* inttoptr (i64 1074774784 to i64*)
%32 = and i64 %31, 5
%33 = icmp eq i64 %32, 5
br i1 %33, label %34, label %52
34: ; preds = %20
%35 = load volatile i64, i64* inttoptr (i64 1074774800 to i64*)
%36 = and i64 %35, 4194304
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %51
38: ; preds = %34
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = and i32 %40, 126976
%42 = add nsw i32 %41, 49152
%43 = and i32 %42, 126976
store i32 %43, i32* %8
%44 = load i32*, i32** %6
%45 = load i32, i32* %44
%46 = and i32 %45, -126977
store i32 %46, i32* %44
%47 = load i32, i32* %8
%48 = load i32*, i32** %6
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
br label %51
51: ; preds = %38, %34
br label %52
52: ; preds = %51, %20
store i32 1, i32* %4
br label %53
53: ; preds = %52, %19
%54 = load i32, i32* %4
ret i32 %54
}

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 i64*
%8 = load volatile i64, i64* %7
%9 = trunc i64 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %3
store i32 %9, i32* %2
%12 = add nsw i32 %4, 1074775264
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i64*
%15 = load volatile i64, i64* %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %1
%17 = load volatile i64, i64* inttoptr (i64 1074774784 to i64*)
%18 = and i64 %17, 5
%19 = icmp eq i64 %18, 5
br i1 %19, label %20, label %30
20: ; preds = %11
%21 = load volatile i64, i64* inttoptr (i64 1074774800 to i64*)
%22 = and i64 %21, 4194304
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %20
%25 = and i32 %16, 126976
%26 = add nuw nsw i32 %25, 49152
%27 = and i32 %26, 126976
%28 = and i32 %16, -126977
%29 = or i32 %27, %28
store i32 %29, i32* %1
br label %30
30: ; preds = %11, %24, %20, %3
%31 = phi i32 [ 0, %3 ], [ 1, %20 ], [ 1, %24 ], [ 1, %11 ]
ret i32 %31
}