#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 /*<<< orphan*/ ASSERT(int volatile);
int HibernateCalendarGet(struct tm *psTime) {
  uint32_t ui32Date, ui32Time;
  ASSERT((*((volatile uint32_t *)(0x400FC300))) & 0x00000001);
  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
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x400fc300,%eax
mov    (%rax),%edi
and    $0x1,%edi
call   1030 <ASSERT@plt>
mov    $0x400fc314,%eax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     112b <HibernateCalendarGet+0x1b>
jmp    114b <HibernateCalendarGet+0x3b>
mov    $0x400fc310,%eax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     114b <HibernateCalendarGet+0x3b>
mov    -0x14(%rbp),%eax
mov    $0x400fc314,%ecx
mov    (%rcx),%ecx
cmp    %ecx,%eax
je     1184 <HibernateCalendarGet+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    1240 <HibernateCalendarGet+0x130>
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    1239 <HibernateCalendarGet+0x129>
mov    -0x18(%rbp),%eax
and    $0x400000,%eax
cmp    $0x0,%eax
je     1239 <HibernateCalendarGet+0x129>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%ecx
add    $0xc,%ecx
mov    %ecx,0x18(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HibernateCalendarGet>:
push   %rbx
mov    %rdi,%rbx
mov    0x400fc300,%edi
and    $0x1,%edi
call   1030 <ASSERT@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x400fc314,%edx
test   %edx,%edx
jns    1130 <HibernateCalendarGet+0x20>
nopl   0x0(%rax,%rax,1)
mov    0x400fc310,%ecx
test   %ecx,%ecx
jns    1140 <HibernateCalendarGet+0x30>
mov    $0xffffffff,%eax
cmp    0x400fc314,%edx
jne    11c0 <HibernateCalendarGet+0xb0>
mov    %ecx,%eax
shr    $0x8,%eax
and    $0x3f,%eax
mov    %eax,(%rbx)
mov    %ecx,%eax
and    $0x3f,%eax
mov    %eax,0x4(%rbx)
mov    %edx,%eax
shr    $0x8,%eax
and    $0xf,%eax
add    $0xffffffff,%eax
mov    %eax,0x8(%rbx)
mov    %edx,%eax
and    $0x1f,%eax
mov    %eax,0xc(%rbx)
mov    %edx,%eax
shr    $0x18,%eax
and    $0x7,%eax
mov    %eax,0x10(%rbx)
shr    $0x10,%edx
and    $0x7f,%edx
add    $0x64,%edx
mov    %edx,0x14(%rbx)
mov    %ecx,%edx
shr    $0x10,%edx
and    $0x1f,%edx
mov    %edx,0x18(%rbx)
xor    %eax,%eax
testl  $0x4,0x400fc300
jne    11c0 <HibernateCalendarGet+0xb0>
and    $0x400000,%ecx
je     11c0 <HibernateCalendarGet+0xb0>
add    $0xc,%edx
mov    %edx,0x18(%rbx)
pop    %rbx
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
%6 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%7 = and i32 %6, 1
%8 = call i32 @ASSERT(i32 %7)
br label %9
9: ; preds = %11, %1
%10 = load volatile i32, i32* inttoptr (i64 1074774804 to i32*)
store i32 %10, i32* %4
br label %11
11: ; preds = %9
%12 = load i32, i32* %4
%13 = and i32 %12, -2147483648
%14 = icmp eq i32 %13, 0
br i1 %14, label %9, label %15
15: ; preds = %11
br label %16
16: ; preds = %18, %15
%17 = load volatile i32, i32* inttoptr (i64 1074774800 to i32*)
store i32 %17, i32* %5
br label %18
18: ; preds = %16
%19 = load i32, i32* %5
%20 = and i32 %19, -2147483648
%21 = icmp eq i32 %20, 0
br i1 %21, label %16, label %22
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load volatile i32, i32* inttoptr (i64 1074774804 to i32*)
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %2
br label %78
27: ; preds = %22
%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 i32, i32* inttoptr (i64 1074774784 to i32*)
%66 = and i32 %65, 4
%67 = icmp eq i32 %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) {
%2 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%3 = and i32 %2, 1
%4 = tail call i32 @ASSERT(i32 %3)
br label %5
5: ; preds = %5, %1
%6 = load volatile i32, i32* inttoptr (i64 1074774804 to i32*)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %5, label %8
8: ; preds = %5, %8
%9 = load volatile i32, i32* inttoptr (i64 1074774800 to i32*)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %8, label %11
11: ; preds = %8
%12 = load volatile i32, i32* inttoptr (i64 1074774804 to i32*)
%13 = icmp eq i32 %6, %12
br i1 %13, label %14, label %44
14: ; preds = %11
%15 = lshr i32 %9, 8
%16 = and i32 %15, 63
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
store i32 %16, i32* %17
%18 = and i32 %9, 63
%19 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
store i32 %18, i32* %19
%20 = lshr i32 %6, 8
%21 = and i32 %20, 15
%22 = add nsw i32 %21, -1
%23 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
store i32 %22, i32* %23
%24 = and i32 %6, 31
%25 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
store i32 %24, i32* %25
%26 = lshr i32 %6, 24
%27 = and i32 %26, 7
%28 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
store i32 %27, i32* %28
%29 = lshr i32 %6, 16
%30 = and i32 %29, 127
%31 = add nuw nsw i32 %30, 100
%32 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
store i32 %31, i32* %32
%33 = lshr i32 %9, 16
%34 = and i32 %33, 31
%35 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 6
store i32 %34, i32* %35
%36 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%37 = and i32 %36, 4
%38 = icmp ne i32 %37, 0
%39 = and i32 %9, 4194304
%40 = icmp eq i32 %39, 0
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %44, label %42
42: ; preds = %14
%43 = add nuw nsw i32 %34, 12
store i32 %43, i32* %35
br label %44
44: ; preds = %14, %42, %11
%45 = phi i32 [ -1, %11 ], [ 0, %42 ], [ 0, %14 ]
ret i32 %45
}