#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 uint32_t *)(0x400FC314)));
  } while ((ui32Date & 0x80000000) == 0);
  do {
    ui32Time = (*((volatile uint32_t *)(0x400FC310)));
  } while ((ui32Time & 0x80000000) == 0);
  if (ui32Date != (*((volatile uint32_t *)(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 uint32_t *)(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),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1108 <HibernateCalendarGet+0x8>
jmp    1128 <HibernateCalendarGet+0x28>
mov    $0x400fc310,%eax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1128 <HibernateCalendarGet+0x28>
mov    -0x14(%rbp),%eax
mov    $0x400fc314,%ecx
mov    (%rcx),%ecx
cmp    %ecx,%eax
je     1161 <HibernateCalendarGet+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <HibernateCalendarGet+0x11d>
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),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    1216 <HibernateCalendarGet+0x116>
mov    -0x18(%rbp),%eax
and    $0x400000,%eax
cmp    $0x0,%eax
je     1216 <HibernateCalendarGet+0x116>
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,%edx
test   %edx,%edx
jns    1100 <HibernateCalendarGet>
nopl   0x0(%rax,%rax,1)
mov    0x400fc310,%ecx
test   %ecx,%ecx
jns    1110 <HibernateCalendarGet+0x10>
mov    $0xffffffff,%eax
cmp    0x400fc314,%edx
jne    1190 <HibernateCalendarGet+0x90>
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
testl  $0x4,0x400fc300
jne    1190 <HibernateCalendarGet+0x90>
and    $0x400000,%ecx
je     1190 <HibernateCalendarGet+0x90>
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 = %8, %1
%7 = load volatile i32, i32* inttoptr (i64 1074774804 to i32*)
store i32 %7, i32* %4
br label %8
8: ; preds = %6
%9 = load i32, i32* %4
%10 = and i32 %9, -2147483648
%11 = icmp eq i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %8
br label %13
13: ; preds = %15, %12
%14 = load volatile i32, i32* inttoptr (i64 1074774800 to i32*)
store i32 %14, i32* %5
br label %15
15: ; preds = %13
%16 = load i32, i32* %5
%17 = and i32 %16, -2147483648
%18 = icmp eq i32 %17, 0
br i1 %18, label %13, label %19
19: ; preds = %15
%20 = load i32, i32* %4
%21 = load volatile i32, i32* inttoptr (i64 1074774804 to i32*)
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %2
br label %75
24: ; preds = %19
%25 = load i32, i32* %5
%26 = and i32 %25, 16128
%27 = ashr i32 %26, 8
%28 = load %struct.tm*, %struct.tm** %3
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %5
%31 = and i32 %30, 63
%32 = ashr i32 %31, 0
%33 = load %struct.tm*, %struct.tm** %3
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 1
store i32 %32, i32* %34
%35 = load i32, i32* %4
%36 = and i32 %35, 3840
%37 = ashr i32 %36, 8
%38 = sub nsw i32 %37, 1
%39 = load %struct.tm*, %struct.tm** %3
%40 = getelementptr inbounds %struct.tm, %struct.tm* %39, i32 0, i32 2
store i32 %38, i32* %40
%41 = load i32, i32* %4
%42 = and i32 %41, 31
%43 = ashr i32 %42, 0
%44 = load %struct.tm*, %struct.tm** %3
%45 = getelementptr inbounds %struct.tm, %struct.tm* %44, i32 0, i32 3
store i32 %43, i32* %45
%46 = load i32, i32* %4
%47 = and i32 %46, 117440512
%48 = ashr i32 %47, 24
%49 = load %struct.tm*, %struct.tm** %3
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 4
store i32 %48, i32* %50
%51 = load i32, i32* %4
%52 = and i32 %51, 8323072
%53 = ashr i32 %52, 16
%54 = add nsw i32 %53, 100
%55 = load %struct.tm*, %struct.tm** %3
%56 = getelementptr inbounds %struct.tm, %struct.tm* %55, i32 0, i32 5
store i32 %54, i32* %56
%57 = load i32, i32* %5
%58 = and i32 %57, 2031616
%59 = ashr i32 %58, 16
%60 = load %struct.tm*, %struct.tm** %3
%61 = getelementptr inbounds %struct.tm, %struct.tm* %60, i32 0, i32 6
store i32 %59, i32* %61
%62 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%63 = and i32 %62, 4
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %74
65: ; preds = %24
%66 = load i32, i32* %5
%67 = and i32 %66, 4194304
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %65
%70 = load %struct.tm*, %struct.tm** %3
%71 = getelementptr inbounds %struct.tm, %struct.tm* %70, i32 0, i32 6
%72 = load i32, i32* %71
%73 = add nsw i32 %72, 12
store i32 %73, i32* %71
br label %74
74: ; preds = %69, %65, %24
store i32 0, i32* %2
br label %75
75: ; preds = %74, %23
%76 = load i32, i32* %2
ret i32 %76
}

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 i32, i32* inttoptr (i64 1074774804 to i32*)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %2, label %5
5: ; preds = %2, %5
%6 = load volatile i32, i32* inttoptr (i64 1074774800 to i32*)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %5, label %8
8: ; preds = %5
%9 = load volatile i32, i32* inttoptr (i64 1074774804 to i32*)
%10 = icmp eq i32 %3, %9
br i1 %10, label %11, label %41
11: ; preds = %8
%12 = lshr i32 %6, 8
%13 = and i32 %12, 63
%14 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
store i32 %13, i32* %14
%15 = and i32 %6, 63
%16 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
store i32 %15, i32* %16
%17 = lshr i32 %3, 8
%18 = and i32 %17, 15
%19 = add nsw i32 %18, -1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
store i32 %19, i32* %20
%21 = and i32 %3, 31
%22 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
store i32 %21, i32* %22
%23 = lshr i32 %3, 24
%24 = and i32 %23, 7
%25 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
store i32 %24, i32* %25
%26 = lshr i32 %3, 16
%27 = and i32 %26, 127
%28 = add nuw nsw i32 %27, 100
%29 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
store i32 %28, i32* %29
%30 = lshr i32 %6, 16
%31 = and i32 %30, 31
%32 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 6
store i32 %31, i32* %32
%33 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%34 = and i32 %33, 4
%35 = icmp ne i32 %34, 0
%36 = and i32 %6, 4194304
%37 = icmp eq i32 %36, 0
%38 = select i1 %35, i1 true, i1 %37
br i1 %38, label %41, label %39
39: ; preds = %11
%40 = add nuw nsw i32 %31, 12
store i32 %40, i32* %32
br label %41
41: ; preds = %11, %39, %8
%42 = phi i32 [ -1, %8 ], [ 0, %39 ], [ 0, %11 ]
ret i32 %42
}