#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_hour;
  int tm_mday;
  int tm_mon;
  int tm_wday;
  int tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ ASSERT(int volatile);
int /*<<< orphan*/ _HibernateWriteComplete();
void _HibernateCalendarSet(uint32_t ui32Reg, struct tm *psTime) {
  uint32_t ui32Time, ui32Date;
  ASSERT((*((volatile uint32_t *)(0x400FC300))) & 0x00000001);
  ui32Time = (((psTime->tm_min << 8) & 0x00003F00) |
              ((psTime->tm_sec << 0) & 0x0000003F));
  if ((*((volatile uint32_t *)(0x400FC300))) & 0x00000004) {
    ui32Time |= (psTime->tm_hour << 16);
    if ((ui32Reg == 0x400FC330) && (psTime->tm_hour == 0xFF)) {
      ui32Time &= ~0x00400000;
    }
  } else {
    if (psTime->tm_hour == 0xFF) {
      ui32Time |= 0x001F0000;
    } else if (psTime->tm_hour >= 12) {
      ui32Time |= (((psTime->tm_hour - 12) << 16) | 0x00400000);
    } else {
      ui32Time |= (psTime->tm_hour << 16);
    }
  }
  if (ui32Reg == 0x400FC310) {
    ui32Date = ((psTime->tm_mday << 0) | ((psTime->tm_mon + 1) << 8) |
                (psTime->tm_wday << 24) | ((psTime->tm_year - 100) << 16));
  } else {
    if (psTime->tm_mday == 0xFF) {
      ui32Date = 0 << 0x0000001F;
    } else {
      ui32Date = (psTime->tm_mday << 0);
    }
  }
  if (ui32Reg == 0x400FC310) {
    (*((volatile uint32_t *)(0x400FC360))) = 0xA3359554;
    _HibernateWriteComplete();
  }
  if (ui32Reg == 0x400FC310) {
    (*((volatile uint32_t *)(0x400FC320))) = ui32Time;
    _HibernateWriteComplete();
    (*((volatile uint32_t *)(0x400FC324))) = ui32Date;
    _HibernateWriteComplete();
  } else {
    (*((volatile uint32_t *)(0x400FC330))) = ui32Time;
    _HibernateWriteComplete();
    (*((volatile uint32_t *)(0x400FC334))) = ui32Date;
    _HibernateWriteComplete();
  }
  if (ui32Reg == 0x400FC310) {
    (*((volatile uint32_t *)(0x400FC360))) = 0;
    _HibernateWriteComplete();
  }
}


x86 assembly (clang, -O0):
<_HibernateCalendarSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x400fc300,%eax
mov    (%rax),%edi
and    $0x1,%edi
call   1040 <ASSERT@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
shl    $0x8,%eax
and    $0x3f00,%eax
mov    -0x10(%rbp),%rcx
mov    0x4(%rcx),%ecx
shl    $0x0,%ecx
and    $0x3f,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0x400fc300,%eax
mov    (%rax),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11af <_HibernateCalendarSet+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x400fc330,-0x4(%rbp)
jne    11aa <_HibernateCalendarSet+0x8a>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0x8(%rax)
jne    11aa <_HibernateCalendarSet+0x8a>
mov    -0x14(%rbp),%eax
and    $0xffbfffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1215 <_HibernateCalendarSet+0xf5>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0x8(%rax)
jne    11d0 <_HibernateCalendarSet+0xb0>
mov    -0x14(%rbp),%eax
or     $0x1f0000,%eax
mov    %eax,-0x14(%rbp)
jmp    1210 <_HibernateCalendarSet+0xf0>
mov    -0x10(%rbp),%rax
cmpl   $0xc,0x8(%rax)
jl     11fb <_HibernateCalendarSet+0xdb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
sub    $0xc,%eax
shl    $0x10,%eax
or     $0x400000,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    120b <_HibernateCalendarSet+0xeb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1210 <_HibernateCalendarSet+0xf0>
jmp    1215 <_HibernateCalendarSet+0xf5>
cmpl   $0x400fc310,-0x4(%rbp)
jne    125e <_HibernateCalendarSet+0x13e>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
shl    $0x0,%eax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%ecx
add    $0x1,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x14(%rcx),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x18(%rcx),%ecx
sub    $0x64,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    128d <_HibernateCalendarSet+0x16d>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0xc(%rax)
jne    127b <_HibernateCalendarSet+0x15b>
movl   $0x0,-0x18(%rbp)
jmp    1288 <_HibernateCalendarSet+0x168>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
shl    $0x0,%eax
mov    %eax,-0x18(%rbp)
jmp    128d <_HibernateCalendarSet+0x16d>
cmpl   $0x400fc310,-0x4(%rbp)
jne    12ac <_HibernateCalendarSet+0x18c>
mov    $0x400fc360,%eax
movl   $0xa3359554,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
cmpl   $0x400fc310,-0x4(%rbp)
jne    12e0 <_HibernateCalendarSet+0x1c0>
mov    -0x14(%rbp),%ecx
mov    $0x400fc320,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
mov    -0x18(%rbp),%ecx
mov    $0x400fc324,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
jmp    1302 <_HibernateCalendarSet+0x1e2>
mov    -0x14(%rbp),%ecx
mov    $0x400fc330,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
mov    -0x18(%rbp),%ecx
mov    $0x400fc334,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
cmpl   $0x400fc310,-0x4(%rbp)
jne    1321 <_HibernateCalendarSet+0x201>
mov    $0x400fc360,%eax
movl   $0x0,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_HibernateCalendarSet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x400fc300,%edi
and    $0x1,%edi
call   1040 <ASSERT@plt>
mov    (%r15),%eax
mov    0x4(%r15),%ebp
and    $0x3f,%eax
shl    $0x8,%eax
and    $0x3f,%ebp
or     %eax,%ebp
testl  $0x4,0x400fc300
mov    0x8(%r15),%eax
jne    116e <_HibernateCalendarSet+0x4e>
cmp    $0xff,%eax
jne    1192 <_HibernateCalendarSet+0x72>
or     $0x1f0000,%ebp
jmp    11ae <_HibernateCalendarSet+0x8e>
mov    %eax,%ecx
shl    $0x10,%ecx
or     %ebp,%ecx
mov    %r14d,%edx
xor    $0x400fc330,%edx
xor    $0xff,%eax
mov    %ecx,%ebp
and    $0xffbf3f3f,%ebp
or     %edx,%eax
cmovne %ecx,%ebp
jmp    11ae <_HibernateCalendarSet+0x8e>
mov    %eax,%ecx
shl    $0x10,%ecx
cmp    $0xc,%eax
jl     11ac <_HibernateCalendarSet+0x8c>
add    $0xfff40000,%ecx
or     %ecx,%ebp
or     $0x400000,%ebp
jmp    11ae <_HibernateCalendarSet+0x8e>
or     %ecx,%ebp
mov    0xc(%r15),%ebx
cmp    $0x400fc310,%r14d
jne    121c <_HibernateCalendarSet+0xfc>
mov    0x10(%r15),%eax
mov    0x14(%r15),%ecx
shl    $0x8,%eax
add    $0x100,%eax
or     %ebx,%eax
shl    $0x18,%ecx
mov    0x18(%r15),%ebx
shl    $0x10,%ebx
add    $0xff9c0000,%ebx
or     %ecx,%ebx
or     %eax,%ebx
movl   $0xa3359554,0x400fc360
54 95 35 a3
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
mov    %ebp,0x400fc320
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
mov    %ebx,0x400fc324
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
movl   $0x0,0x400fc360
jmp    123c <_HibernateCalendarSet+0x11c>
xor    %eax,%eax
cmp    $0xff,%ebx
cmove  %eax,%ebx
mov    %ebp,0x400fc330
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
mov    %ebx,0x400fc334
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_HibernateWriteComplete@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define void @_HibernateCalendarSet(i32 %0, %struct.tm* %1) {
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store %struct.tm* %1, %struct.tm** %4
%7 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%8 = and i32 %7, 1
%9 = call i32 @ASSERT(i32 %8)
%10 = load %struct.tm*, %struct.tm** %4
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = shl i32 %12, 8
%14 = and i32 %13, 16128
%15 = load %struct.tm*, %struct.tm** %4
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = shl i32 %17, 0
%19 = and i32 %18, 63
%20 = or i32 %14, %19
store i32 %20, i32* %5
%21 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%22 = and i32 %21, 4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %2
%25 = load %struct.tm*, %struct.tm** %4
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 2
%27 = load i32, i32* %26
%28 = shl i32 %27, 16
%29 = load i32, i32* %5
%30 = or i32 %29, %28
store i32 %30, i32* %5
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, 1074774832
br i1 %32, label %33, label %41
33: ; preds = %24
%34 = load %struct.tm*, %struct.tm** %4
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 255
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %5
%40 = and i32 %39, -4194305
store i32 %40, i32* %5
br label %41
41: ; preds = %38, %33, %24
br label %73
42: ; preds = %2
%43 = load %struct.tm*, %struct.tm** %4
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 2
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 255
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i32, i32* %5
%49 = or i32 %48, 2031616
store i32 %49, i32* %5
br label %72
50: ; preds = %42
%51 = load %struct.tm*, %struct.tm** %4
%52 = getelementptr inbounds %struct.tm, %struct.tm* %51, i32 0, i32 2
%53 = load i32, i32* %52
%54 = icmp sge i32 %53, 12
br i1 %54, label %55, label %64
55: ; preds = %50
%56 = load %struct.tm*, %struct.tm** %4
%57 = getelementptr inbounds %struct.tm, %struct.tm* %56, i32 0, i32 2
%58 = load i32, i32* %57
%59 = sub nsw i32 %58, 12
%60 = shl i32 %59, 16
%61 = or i32 %60, 4194304
%62 = load i32, i32* %5
%63 = or i32 %62, %61
store i32 %63, i32* %5
br label %71
64: ; preds = %50
%65 = load %struct.tm*, %struct.tm** %4
%66 = getelementptr inbounds %struct.tm, %struct.tm* %65, i32 0, i32 2
%67 = load i32, i32* %66
%68 = shl i32 %67, 16
%69 = load i32, i32* %5
%70 = or i32 %69, %68
store i32 %70, i32* %5
br label %71
71: ; preds = %64, %55
br label %72
72: ; preds = %71, %47
br label %73
73: ; preds = %72, %41
%74 = load i32, i32* %3
%75 = icmp eq i32 %74, 1074774800
br i1 %75, label %76, label %98
76: ; preds = %73
%77 = load %struct.tm*, %struct.tm** %4
%78 = getelementptr inbounds %struct.tm, %struct.tm* %77, i32 0, i32 3
%79 = load i32, i32* %78
%80 = shl i32 %79, 0
%81 = load %struct.tm*, %struct.tm** %4
%82 = getelementptr inbounds %struct.tm, %struct.tm* %81, i32 0, i32 4
%83 = load i32, i32* %82
%84 = add nsw i32 %83, 1
%85 = shl i32 %84, 8
%86 = or i32 %80, %85
%87 = load %struct.tm*, %struct.tm** %4
%88 = getelementptr inbounds %struct.tm, %struct.tm* %87, i32 0, i32 5
%89 = load i32, i32* %88
%90 = shl i32 %89, 24
%91 = or i32 %86, %90
%92 = load %struct.tm*, %struct.tm** %4
%93 = getelementptr inbounds %struct.tm, %struct.tm* %92, i32 0, i32 6
%94 = load i32, i32* %93
%95 = sub nsw i32 %94, 100
%96 = shl i32 %95, 16
%97 = or i32 %91, %96
store i32 %97, i32* %6
br label %110
98: ; preds = %73
%99 = load %struct.tm*, %struct.tm** %4
%100 = getelementptr inbounds %struct.tm, %struct.tm* %99, i32 0, i32 3
%101 = load i32, i32* %100
%102 = icmp eq i32 %101, 255
br i1 %102, label %103, label %104
103: ; preds = %98
store i32 0, i32* %6
br label %109
104: ; preds = %98
%105 = load %struct.tm*, %struct.tm** %4
%106 = getelementptr inbounds %struct.tm, %struct.tm* %105, i32 0, i32 3
%107 = load i32, i32* %106
%108 = shl i32 %107, 0
store i32 %108, i32* %6
br label %109
109: ; preds = %104, %103
br label %110
110: ; preds = %109, %76
%111 = load i32, i32* %3
%112 = icmp eq i32 %111, 1074774800
br i1 %112, label %113, label %115
113: ; preds = %110
store volatile i32 -1556769452, i32* inttoptr (i64 1074774880 to i32*)
%114 = call i32 (...) @_HibernateWriteComplete()
br label %115
115: ; preds = %113, %110
%116 = load i32, i32* %3
%117 = icmp eq i32 %116, 1074774800
br i1 %117, label %118, label %123
118: ; preds = %115
%119 = load i32, i32* %5
store volatile i32 %119, i32* inttoptr (i64 1074774816 to i32*)
%120 = call i32 (...) @_HibernateWriteComplete()
%121 = load i32, i32* %6
store volatile i32 %121, i32* inttoptr (i64 1074774820 to i32*)
%122 = call i32 (...) @_HibernateWriteComplete()
br label %128
123: ; preds = %115
%124 = load i32, i32* %5
store volatile i32 %124, i32* inttoptr (i64 1074774832 to i32*)
%125 = call i32 (...) @_HibernateWriteComplete()
%126 = load i32, i32* %6
store volatile i32 %126, i32* inttoptr (i64 1074774836 to i32*)
%127 = call i32 (...) @_HibernateWriteComplete()
br label %128
128: ; preds = %123, %118
%129 = load i32, i32* %3
%130 = icmp eq i32 %129, 1074774800
br i1 %130, label %131, label %133
131: ; preds = %128
store volatile i32 0, i32* inttoptr (i64 1074774880 to i32*)
%132 = call i32 (...) @_HibernateWriteComplete()
br label %133
133: ; preds = %131, %128
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define void @_HibernateCalendarSet(i32 %0, %struct.tm* nocapture %1) {
%3 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%4 = and i32 %3, 1
%5 = tail call i32 @ASSERT(i32 %4)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = shl i32 %7, 8
%9 = and i32 %8, 16128
%10 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%11 = load i32, i32* %10
%12 = and i32 %11, 63
%13 = or i32 %9, %12
%14 = load volatile i32, i32* inttoptr (i64 1074774784 to i32*)
%15 = and i32 %14, 4
%16 = icmp eq i32 %15, 0
%17 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
%18 = load i32, i32* %17
br i1 %16, label %27, label %19
19: ; preds = %2
%20 = shl i32 %18, 16
%21 = or i32 %20, %13
%22 = icmp eq i32 %0, 1074774832
%23 = icmp eq i32 %18, 255
%24 = select i1 %22, i1 %23, i1 false
%25 = and i32 %21, -4243649
%26 = select i1 %24, i32 %25, i32 %21
br label %40
27: ; preds = %2
%28 = icmp eq i32 %18, 255
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = or i32 %13, 2031616
br label %40
31: ; preds = %27
%32 = icmp sgt i32 %18, 11
%33 = shl i32 %18, 16
br i1 %32, label %34, label %38
34: ; preds = %31
%35 = add i32 %33, -786432
%36 = or i32 %13, %35
%37 = or i32 %36, 4194304
br label %40
38: ; preds = %31
%39 = or i32 %33, %13
br label %40
40: ; preds = %19, %29, %38, %34
%41 = phi i32 [ %30, %29 ], [ %37, %34 ], [ %39, %38 ], [ %26, %19 ]
%42 = icmp eq i32 %0, 1074774800
%43 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 3
%44 = load i32, i32* %43
br i1 %42, label %49, label %45
45: ; preds = %40
%46 = icmp eq i32 %44, 255
%47 = select i1 %46, i32 0, i32 %44
store volatile i32 %41, i32* inttoptr (i64 1074774832 to i32*)
%48 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 %47, i32* inttoptr (i64 1074774836 to i32*)
br label %67
49: ; preds = %40
%50 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 4
%51 = load i32, i32* %50
%52 = shl i32 %51, 8
%53 = add i32 %52, 256
%54 = or i32 %53, %44
%55 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 5
%56 = load i32, i32* %55
%57 = shl i32 %56, 24
%58 = or i32 %54, %57
%59 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 6
%60 = load i32, i32* %59
%61 = shl i32 %60, 16
%62 = add i32 %61, -6553600
%63 = or i32 %58, %62
store volatile i32 -1556769452, i32* inttoptr (i64 1074774880 to i32*)
%64 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 %41, i32* inttoptr (i64 1074774816 to i32*)
%65 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 %63, i32* inttoptr (i64 1074774820 to i32*)
%66 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 0, i32* inttoptr (i64 1074774880 to i32*)
br label %67
67: ; preds = %45, %49
%68 = tail call i32 (...) @_HibernateWriteComplete()
ret void
}