#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*/ _HibernateWriteComplete();
void _HibernateCalendarSet(uint32_t ui32Reg, struct tm *psTime) {
  uint32_t ui32Time, ui32Date;
  ;
  ui32Time = (((psTime->tm_min << 8) & 0x00003F00) |
              ((psTime->tm_sec << 0) & 0x0000003F));
  if ((*((volatile unsigned long *)(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 unsigned long *)(0x400FC360))) = 0xA3359554;
    _HibernateWriteComplete();
  }
  if (ui32Reg == 0x400FC310) {
    (*((volatile unsigned long *)(0x400FC320))) = ui32Time;
    _HibernateWriteComplete();
    (*((volatile unsigned long *)(0x400FC324))) = ui32Date;
    _HibernateWriteComplete();
  } else {
    (*((volatile unsigned long *)(0x400FC330))) = ui32Time;
    _HibernateWriteComplete();
    (*((volatile unsigned long *)(0x400FC334))) = ui32Date;
    _HibernateWriteComplete();
  }
  if (ui32Reg == 0x400FC310) {
    (*((volatile unsigned long *)(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    -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),%rax
and    $0x4,%rax
cmp    $0x0,%rax
je     1193 <_HibernateCalendarSet+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x400fc330,-0x4(%rbp)
jne    118e <_HibernateCalendarSet+0x7e>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0x8(%rax)
jne    118e <_HibernateCalendarSet+0x7e>
mov    -0x14(%rbp),%eax
and    $0xffbfffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11f9 <_HibernateCalendarSet+0xe9>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0x8(%rax)
jne    11b4 <_HibernateCalendarSet+0xa4>
mov    -0x14(%rbp),%eax
or     $0x1f0000,%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <_HibernateCalendarSet+0xe4>
mov    -0x10(%rbp),%rax
cmpl   $0xc,0x8(%rax)
jl     11df <_HibernateCalendarSet+0xcf>
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    11ef <_HibernateCalendarSet+0xdf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <_HibernateCalendarSet+0xe4>
jmp    11f9 <_HibernateCalendarSet+0xe9>
cmpl   $0x400fc310,-0x4(%rbp)
jne    1242 <_HibernateCalendarSet+0x132>
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    1271 <_HibernateCalendarSet+0x161>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0xc(%rax)
jne    125f <_HibernateCalendarSet+0x14f>
movl   $0x0,-0x18(%rbp)
jmp    126c <_HibernateCalendarSet+0x15c>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
shl    $0x0,%eax
mov    %eax,-0x18(%rbp)
jmp    1271 <_HibernateCalendarSet+0x161>
cmpl   $0x400fc310,-0x4(%rbp)
jne    1292 <_HibernateCalendarSet+0x182>
mov    $0x400fc360,%eax
mov    $0xa3359554,%ecx
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
cmpl   $0x400fc310,-0x4(%rbp)
jne    12ca <_HibernateCalendarSet+0x1ba>
movslq -0x14(%rbp),%rcx
mov    $0x400fc320,%eax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
movslq -0x18(%rbp),%rcx
mov    $0x400fc324,%eax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
jmp    12f0 <_HibernateCalendarSet+0x1e0>
movslq -0x14(%rbp),%rcx
mov    $0x400fc330,%eax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
movslq -0x18(%rbp),%rcx
mov    $0x400fc334,%eax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
cmpl   $0x400fc310,-0x4(%rbp)
jne    1310 <_HibernateCalendarSet+0x200>
mov    $0x400fc360,%eax
movq   $0x0,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_HibernateCalendarSet>:
push   %rbp
push   %rbx
push   %rax
mov    (%rsi),%eax
mov    0x4(%rsi),%ebx
and    $0x3f,%eax
shl    $0x8,%eax
and    $0x3f,%ebx
or     %eax,%ebx
testq  $0x4,0x400fc300
mov    0x8(%rsi),%eax
jne    1143 <_HibernateCalendarSet+0x33>
cmp    $0xff,%eax
jne    1166 <_HibernateCalendarSet+0x56>
or     $0x1f0000,%ebx
jmp    1182 <_HibernateCalendarSet+0x72>
mov    %eax,%ecx
shl    $0x10,%ecx
or     %ebx,%ecx
mov    %edi,%edx
xor    $0x400fc330,%edx
xor    $0xff,%eax
mov    %ecx,%ebx
and    $0xffbf3f3f,%ebx
or     %edx,%eax
cmovne %ecx,%ebx
jmp    1182 <_HibernateCalendarSet+0x72>
mov    %eax,%ecx
shl    $0x10,%ecx
cmp    $0xc,%eax
jl     1180 <_HibernateCalendarSet+0x70>
add    $0xfff40000,%ecx
or     %ecx,%ebx
or     $0x400000,%ebx
jmp    1182 <_HibernateCalendarSet+0x72>
or     %ecx,%ebx
mov    0xc(%rsi),%ebp
cmp    $0x400fc310,%edi
jne    11f6 <_HibernateCalendarSet+0xe6>
mov    0x10(%rsi),%eax
mov    0x14(%rsi),%ecx
shl    $0x8,%eax
add    $0x100,%eax
or     %ebp,%eax
shl    $0x18,%ecx
mov    0x18(%rsi),%ebp
shl    $0x10,%ebp
add    $0xff9c0000,%ebp
or     %ecx,%ebp
or     %eax,%ebp
mov    $0xa3359554,%eax
mov    %rax,0x400fc360
40
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
movslq %ebx,%rax
mov    %rax,0x400fc320
40
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
movslq %ebp,%rax
mov    %rax,0x400fc324
40
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
movq   $0x0,0x400fc360
jmp    121e <_HibernateCalendarSet+0x10e>
xor    %eax,%eax
cmp    $0xff,%ebp
cmove  %eax,%ebp
movslq %ebx,%rax
mov    %rax,0x400fc330
40
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
movslq %ebp,%rax
mov    %rax,0x400fc334
40
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
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 %struct.tm*, %struct.tm** %4
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = shl i32 %9, 8
%11 = and i32 %10, 16128
%12 = load %struct.tm*, %struct.tm** %4
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = shl i32 %14, 0
%16 = and i32 %15, 63
%17 = or i32 %11, %16
store i32 %17, i32* %5
%18 = load volatile i64, i64* inttoptr (i64 1074774784 to i64*)
%19 = and i64 %18, 4
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %2
%22 = load %struct.tm*, %struct.tm** %4
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = shl i32 %24, 16
%26 = load i32, i32* %5
%27 = or i32 %26, %25
store i32 %27, i32* %5
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 1074774832
br i1 %29, label %30, label %38
30: ; preds = %21
%31 = load %struct.tm*, %struct.tm** %4
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 2
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 255
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* %5
%37 = and i32 %36, -4194305
store i32 %37, i32* %5
br label %38
38: ; preds = %35, %30, %21
br label %70
39: ; preds = %2
%40 = load %struct.tm*, %struct.tm** %4
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 2
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 255
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32, i32* %5
%46 = or i32 %45, 2031616
store i32 %46, i32* %5
br label %69
47: ; preds = %39
%48 = load %struct.tm*, %struct.tm** %4
%49 = getelementptr inbounds %struct.tm, %struct.tm* %48, i32 0, i32 2
%50 = load i32, i32* %49
%51 = icmp sge i32 %50, 12
br i1 %51, label %52, label %61
52: ; preds = %47
%53 = load %struct.tm*, %struct.tm** %4
%54 = getelementptr inbounds %struct.tm, %struct.tm* %53, i32 0, i32 2
%55 = load i32, i32* %54
%56 = sub nsw i32 %55, 12
%57 = shl i32 %56, 16
%58 = or i32 %57, 4194304
%59 = load i32, i32* %5
%60 = or i32 %59, %58
store i32 %60, i32* %5
br label %68
61: ; preds = %47
%62 = load %struct.tm*, %struct.tm** %4
%63 = getelementptr inbounds %struct.tm, %struct.tm* %62, i32 0, i32 2
%64 = load i32, i32* %63
%65 = shl i32 %64, 16
%66 = load i32, i32* %5
%67 = or i32 %66, %65
store i32 %67, i32* %5
br label %68
68: ; preds = %61, %52
br label %69
69: ; preds = %68, %44
br label %70
70: ; preds = %69, %38
%71 = load i32, i32* %3
%72 = icmp eq i32 %71, 1074774800
br i1 %72, label %73, label %95
73: ; preds = %70
%74 = load %struct.tm*, %struct.tm** %4
%75 = getelementptr inbounds %struct.tm, %struct.tm* %74, i32 0, i32 3
%76 = load i32, i32* %75
%77 = shl i32 %76, 0
%78 = load %struct.tm*, %struct.tm** %4
%79 = getelementptr inbounds %struct.tm, %struct.tm* %78, i32 0, i32 4
%80 = load i32, i32* %79
%81 = add nsw i32 %80, 1
%82 = shl i32 %81, 8
%83 = or i32 %77, %82
%84 = load %struct.tm*, %struct.tm** %4
%85 = getelementptr inbounds %struct.tm, %struct.tm* %84, i32 0, i32 5
%86 = load i32, i32* %85
%87 = shl i32 %86, 24
%88 = or i32 %83, %87
%89 = load %struct.tm*, %struct.tm** %4
%90 = getelementptr inbounds %struct.tm, %struct.tm* %89, i32 0, i32 6
%91 = load i32, i32* %90
%92 = sub nsw i32 %91, 100
%93 = shl i32 %92, 16
%94 = or i32 %88, %93
store i32 %94, i32* %6
br label %107
95: ; preds = %70
%96 = load %struct.tm*, %struct.tm** %4
%97 = getelementptr inbounds %struct.tm, %struct.tm* %96, i32 0, i32 3
%98 = load i32, i32* %97
%99 = icmp eq i32 %98, 255
br i1 %99, label %100, label %101
100: ; preds = %95
store i32 0, i32* %6
br label %106
101: ; preds = %95
%102 = load %struct.tm*, %struct.tm** %4
%103 = getelementptr inbounds %struct.tm, %struct.tm* %102, i32 0, i32 3
%104 = load i32, i32* %103
%105 = shl i32 %104, 0
store i32 %105, i32* %6
br label %106
106: ; preds = %101, %100
br label %107
107: ; preds = %106, %73
%108 = load i32, i32* %3
%109 = icmp eq i32 %108, 1074774800
br i1 %109, label %110, label %112
110: ; preds = %107
store volatile i64 2738197844, i64* inttoptr (i64 1074774880 to i64*)
%111 = call i32 (...) @_HibernateWriteComplete()
br label %112
112: ; preds = %110, %107
%113 = load i32, i32* %3
%114 = icmp eq i32 %113, 1074774800
br i1 %114, label %115, label %122
115: ; preds = %112
%116 = load i32, i32* %5
%117 = sext i32 %116 to i64
store volatile i64 %117, i64* inttoptr (i64 1074774816 to i64*)
%118 = call i32 (...) @_HibernateWriteComplete()
%119 = load i32, i32* %6
%120 = sext i32 %119 to i64
store volatile i64 %120, i64* inttoptr (i64 1074774820 to i64*)
%121 = call i32 (...) @_HibernateWriteComplete()
br label %129
122: ; preds = %112
%123 = load i32, i32* %5
%124 = sext i32 %123 to i64
store volatile i64 %124, i64* inttoptr (i64 1074774832 to i64*)
%125 = call i32 (...) @_HibernateWriteComplete()
%126 = load i32, i32* %6
%127 = sext i32 %126 to i64
store volatile i64 %127, i64* inttoptr (i64 1074774836 to i64*)
%128 = call i32 (...) @_HibernateWriteComplete()
br label %129
129: ; preds = %122, %115
%130 = load i32, i32* %3
%131 = icmp eq i32 %130, 1074774800
br i1 %131, label %132, label %134
132: ; preds = %129
store volatile i64 0, i64* inttoptr (i64 1074774880 to i64*)
%133 = call i32 (...) @_HibernateWriteComplete()
br label %134
134: ; preds = %132, %129
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 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = shl i32 %4, 8
%6 = and i32 %5, 16128
%7 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%8 = load i32, i32* %7
%9 = and i32 %8, 63
%10 = or i32 %6, %9
%11 = load volatile i64, i64* inttoptr (i64 1074774784 to i64*)
%12 = and i64 %11, 4
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
%15 = load i32, i32* %14
br i1 %13, label %24, label %16
16: ; preds = %2
%17 = shl i32 %15, 16
%18 = or i32 %17, %10
%19 = icmp eq i32 %0, 1074774832
%20 = icmp eq i32 %15, 255
%21 = select i1 %19, i1 %20, i1 false
%22 = and i32 %18, -4243649
%23 = select i1 %21, i32 %22, i32 %18
br label %37
24: ; preds = %2
%25 = icmp eq i32 %15, 255
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = or i32 %10, 2031616
br label %37
28: ; preds = %24
%29 = icmp sgt i32 %15, 11
%30 = shl i32 %15, 16
br i1 %29, label %31, label %35
31: ; preds = %28
%32 = add i32 %30, -786432
%33 = or i32 %10, %32
%34 = or i32 %33, 4194304
br label %37
35: ; preds = %28
%36 = or i32 %30, %10
br label %37
37: ; preds = %16, %26, %35, %31
%38 = phi i32 [ %27, %26 ], [ %34, %31 ], [ %36, %35 ], [ %23, %16 ]
%39 = icmp eq i32 %0, 1074774800
%40 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 3
%41 = load i32, i32* %40
br i1 %39, label %48, label %42
42: ; preds = %37
%43 = icmp eq i32 %41, 255
%44 = select i1 %43, i32 0, i32 %41
%45 = sext i32 %38 to i64
store volatile i64 %45, i64* inttoptr (i64 1074774832 to i64*)
%46 = tail call i32 (...) @_HibernateWriteComplete()
%47 = sext i32 %44 to i64
store volatile i64 %47, i64* inttoptr (i64 1074774836 to i64*)
br label %68
48: ; preds = %37
%49 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 4
%50 = load i32, i32* %49
%51 = shl i32 %50, 8
%52 = add i32 %51, 256
%53 = or i32 %52, %41
%54 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 5
%55 = load i32, i32* %54
%56 = shl i32 %55, 24
%57 = or i32 %53, %56
%58 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 6
%59 = load i32, i32* %58
%60 = shl i32 %59, 16
%61 = add i32 %60, -6553600
%62 = or i32 %57, %61
store volatile i64 2738197844, i64* inttoptr (i64 1074774880 to i64*)
%63 = tail call i32 (...) @_HibernateWriteComplete()
%64 = sext i32 %38 to i64
store volatile i64 %64, i64* inttoptr (i64 1074774816 to i64*)
%65 = tail call i32 (...) @_HibernateWriteComplete()
%66 = sext i32 %62 to i64
store volatile i64 %66, i64* inttoptr (i64 1074774820 to i64*)
%67 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i64 0, i64* inttoptr (i64 1074774880 to i64*)
br label %68
68: ; preds = %42, %48
%69 = tail call i32 (...) @_HibernateWriteComplete()
ret void
}