#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;
struct tm {
  int tm_min;
  int tm_sec;
  int tm_mon;
  int tm_mday;
  int tm_wday;
  int tm_year;
  int tm_hour;
};

/* Variables and functions */
int HibernateCalendarGet(struct tm *psTime) {
  uint32_t ui32Date, ui32Time;
  ;
  do {
    ui32Date = (*((volatile unsigned long *)(0x400FC314)));
  } while ((ui32Date & 0x80000000) == 0);
  do {
    ui32Time = (*((volatile unsigned long *)(0x400FC310)));
  } while ((ui32Time & 0x80000000) == 0);
  if (ui32Date != (*((volatile unsigned long *)(0x400FC314)))) {
    return (-1);
  }
  psTime->tm_min = (ui32Time & 0x00003F00) >> 8;
  psTime->tm_sec = (ui32Time & 0x0000003F) >> 0;
  psTime->tm_mon = (((ui32Date & 0x00000F00) >> 8) - 1);
  psTime->tm_mday = (ui32Date & 0x0000001F) >> 0;
  psTime->tm_wday = (ui32Date & 0x07000000) >> 24;
  psTime->tm_year = ((ui32Date & 0x007F0000) >> 16) + 100;
  psTime->tm_hour = (ui32Time & 0x001F0000) >> 16;
  if ((((*((volatile unsigned long *)(0x400FC300))) & 0x00000004) == 0) &&
      (ui32Time & 0x00400000)) {
    psTime->tm_hour += 12;
  }
  return (0);
}


x86 assembly (clang, -O0):
<HibernateCalendarGet>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    $0x400fc314,%eax
mov    (%rax),%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1108 <HibernateCalendarGet+0x8>
jmp    1129 <HibernateCalendarGet+0x29>
mov    $0x400fc310,%eax
mov    (%rax),%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1129 <HibernateCalendarGet+0x29>
movslq -0x14(%rbp),%rax
mov    $0x400fc314,%ecx
mov    (%rcx),%rcx
cmp    %rcx,%rax
je     1166 <HibernateCalendarGet+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    1225 <HibernateCalendarGet+0x125>
mov    -0x18(%rbp),%ecx
and    $0x3f00,%ecx
sar    $0x8,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%ecx
and    $0x3f,%ecx
sar    $0x0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%ecx
and    $0xf00,%ecx
sar    $0x8,%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%ecx
and    $0x1f,%ecx
sar    $0x0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x14(%rbp),%ecx
and    $0x7000000,%ecx
sar    $0x18,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x14(%rbp),%ecx
and    $0x7f0000,%ecx
sar    $0x10,%ecx
add    $0x64,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x18(%rbp),%ecx
and    $0x1f0000,%ecx
sar    $0x10,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    $0x400fc300,%eax
mov    (%rax),%rax
and    $0x4,%rax
cmp    $0x0,%rax
jne    121e <HibernateCalendarGet+0x11e>
mov    -0x18(%rbp),%eax
and    $0x400000,%eax
cmp    $0x0,%eax
je     121e <HibernateCalendarGet+0x11e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%ecx
add    $0xc,%ecx
mov    %ecx,0x18(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<HibernateCalendarGet>:
mov    0x400fc314,%rdx
40
test   $0x80000000,%edx
je     1100 <HibernateCalendarGet>
mov    0x400fc310,%rcx
40
test   $0x80000000,%ecx
je     1110 <HibernateCalendarGet+0x10>
movslq %edx,%rsi
mov    $0xffffffff,%eax
cmp    0x400fc314,%rsi
40
jne    119a <HibernateCalendarGet+0x9a>
mov    %ecx,%eax
shr    $0x8,%eax
and    $0x3f,%eax
mov    %eax,(%rdi)
mov    %ecx,%eax
and    $0x3f,%eax
mov    %eax,0x4(%rdi)
mov    %edx,%eax
shr    $0x8,%eax
and    $0xf,%eax
add    $0xffffffff,%eax
mov    %eax,0x8(%rdi)
mov    %edx,%eax
and    $0x1f,%eax
mov    %eax,0xc(%rdi)
mov    %edx,%eax
shr    $0x18,%eax
and    $0x7,%eax
mov    %eax,0x10(%rdi)
shr    $0x10,%edx
and    $0x7f,%edx
add    $0x64,%edx
mov    %edx,0x14(%rdi)
mov    %ecx,%edx
shr    $0x10,%edx
and    $0x1f,%edx
mov    %edx,0x18(%rdi)
xor    %eax,%eax
testq  $0x4,0x400fc300
jne    119a <HibernateCalendarGet+0x9a>
and    $0x400000,%ecx
je     119a <HibernateCalendarGet+0x9a>
add    $0xc,%edx
mov    %edx,0x18(%rdi)
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define i32 @HibernateCalendarGet(%struct.tm* %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca i32
%5 = alloca i32
store %struct.tm* %0, %struct.tm** %3
br label %6
6: ; preds = %9, %1
%7 = load volatile i64, i64* inttoptr (i64 1074774804 to i64*)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %4
br label %9
9: ; preds = %6
%10 = load i32, i32* %4
%11 = and i32 %10, -2147483648
%12 = icmp eq i32 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %9
br label %14
14: ; preds = %17, %13
%15 = load volatile i64, i64* inttoptr (i64 1074774800 to i64*)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %5
br label %17
17: ; preds = %14
%18 = load i32, i32* %5
%19 = and i32 %18, -2147483648
%20 = icmp eq i32 %19, 0
br i1 %20, label %14, label %21
21: ; preds = %17
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = load volatile i64, i64* inttoptr (i64 1074774804 to i64*)
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %2
br label %78
27: ; preds = %21
%28 = load i32, i32* %5
%29 = and i32 %28, 16128
%30 = ashr i32 %29, 8
%31 = load %struct.tm*, %struct.tm** %3
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = load i32, i32* %5
%34 = and i32 %33, 63
%35 = ashr i32 %34, 0
%36 = load %struct.tm*, %struct.tm** %3
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 1
store i32 %35, i32* %37
%38 = load i32, i32* %4
%39 = and i32 %38, 3840
%40 = ashr i32 %39, 8
%41 = sub nsw i32 %40, 1
%42 = load %struct.tm*, %struct.tm** %3
%43 = getelementptr inbounds %struct.tm, %struct.tm* %42, i32 0, i32 2
store i32 %41, i32* %43
%44 = load i32, i32* %4
%45 = and i32 %44, 31
%46 = ashr i32 %45, 0
%47 = load %struct.tm*, %struct.tm** %3
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i32 0, i32 3
store i32 %46, i32* %48
%49 = load i32, i32* %4
%50 = and i32 %49, 117440512
%51 = ashr i32 %50, 24
%52 = load %struct.tm*, %struct.tm** %3
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 4
store i32 %51, i32* %53
%54 = load i32, i32* %4
%55 = and i32 %54, 8323072
%56 = ashr i32 %55, 16
%57 = add nsw i32 %56, 100
%58 = load %struct.tm*, %struct.tm** %3
%59 = getelementptr inbounds %struct.tm, %struct.tm* %58, i32 0, i32 5
store i32 %57, i32* %59
%60 = load i32, i32* %5
%61 = and i32 %60, 2031616
%62 = ashr i32 %61, 16
%63 = load %struct.tm*, %struct.tm** %3
%64 = getelementptr inbounds %struct.tm, %struct.tm* %63, i32 0, i32 6
store i32 %62, i32* %64
%65 = load volatile i64, i64* inttoptr (i64 1074774784 to i64*)
%66 = and i64 %65, 4
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %77
68: ; preds = %27
%69 = load i32, i32* %5
%70 = and i32 %69, 4194304
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %68
%73 = load %struct.tm*, %struct.tm** %3
%74 = getelementptr inbounds %struct.tm, %struct.tm* %73, i32 0, i32 6
%75 = load i32, i32* %74
%76 = add nsw i32 %75, 12
store i32 %76, i32* %74
br label %77
77: ; preds = %72, %68, %27
store i32 0, i32* %2
br label %78
78: ; preds = %77, %26
%79 = load i32, i32* %2
ret i32 %79
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define i32 @HibernateCalendarGet(%struct.tm* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = load volatile i64, i64* inttoptr (i64 1074774804 to i64*)
%4 = and i64 %3, 2147483648
%5 = icmp eq i64 %4, 0
br i1 %5, label %2, label %6
6: ; preds = %2, %6
%7 = load volatile i64, i64* inttoptr (i64 1074774800 to i64*)
%8 = and i64 %7, 2147483648
%9 = icmp eq i64 %8, 0
br i1 %9, label %6, label %10
10: ; preds = %6
%11 = trunc i64 %3 to i32
%12 = trunc i64 %7 to i32
%13 = shl i64 %3, 32
%14 = ashr exact i64 %13, 32
%15 = load volatile i64, i64* inttoptr (i64 1074774804 to i64*)
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %47
17: ; preds = %10
%18 = lshr i32 %12, 8
%19 = and i32 %18, 63
%20 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
store i32 %19, i32* %20
%21 = and i32 %12, 63
%22 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
store i32 %21, i32* %22
%23 = lshr i32 %11, 8
%24 = and i32 %23, 15
%25 = add nsw i32 %24, -1
%26 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
store i32 %25, i32* %26
%27 = and i32 %11, 31
%28 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
store i32 %27, i32* %28
%29 = lshr i32 %11, 24
%30 = and i32 %29, 7
%31 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
store i32 %30, i32* %31
%32 = lshr i32 %11, 16
%33 = and i32 %32, 127
%34 = add nuw nsw i32 %33, 100
%35 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
store i32 %34, i32* %35
%36 = lshr i32 %12, 16
%37 = and i32 %36, 31
%38 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 6
store i32 %37, i32* %38
%39 = load volatile i64, i64* inttoptr (i64 1074774784 to i64*)
%40 = and i64 %39, 4
%41 = icmp ne i64 %40, 0
%42 = and i32 %12, 4194304
%43 = icmp eq i32 %42, 0
%44 = select i1 %41, i1 true, i1 %43
br i1 %44, label %47, label %45
45: ; preds = %17
%46 = add nuw nsw i32 %37, 12
store i32 %46, i32* %38
br label %47
47: ; preds = %17, %45, %10
%48 = phi i32 [ -1, %10 ], [ 0, %45 ], [ 0, %17 ]
ret i32 %48
}