#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 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    -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     1190 <_HibernateCalendarSet+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x400fc330,-0x4(%rbp)
jne    118b <_HibernateCalendarSet+0x7b>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0x8(%rax)
jne    118b <_HibernateCalendarSet+0x7b>
mov    -0x14(%rbp),%eax
and    $0xffbfffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11f6 <_HibernateCalendarSet+0xe6>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0x8(%rax)
jne    11b1 <_HibernateCalendarSet+0xa1>
mov    -0x14(%rbp),%eax
or     $0x1f0000,%eax
mov    %eax,-0x14(%rbp)
jmp    11f1 <_HibernateCalendarSet+0xe1>
mov    -0x10(%rbp),%rax
cmpl   $0xc,0x8(%rax)
jl     11dc <_HibernateCalendarSet+0xcc>
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    11ec <_HibernateCalendarSet+0xdc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11f1 <_HibernateCalendarSet+0xe1>
jmp    11f6 <_HibernateCalendarSet+0xe6>
cmpl   $0x400fc310,-0x4(%rbp)
jne    123f <_HibernateCalendarSet+0x12f>
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    126e <_HibernateCalendarSet+0x15e>
mov    -0x10(%rbp),%rax
cmpl   $0xff,0xc(%rax)
jne    125c <_HibernateCalendarSet+0x14c>
movl   $0x0,-0x18(%rbp)
jmp    1269 <_HibernateCalendarSet+0x159>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
shl    $0x0,%eax
mov    %eax,-0x18(%rbp)
jmp    126e <_HibernateCalendarSet+0x15e>
cmpl   $0x400fc310,-0x4(%rbp)
jne    128d <_HibernateCalendarSet+0x17d>
mov    $0x400fc360,%eax
movl   $0xa3359554,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
cmpl   $0x400fc310,-0x4(%rbp)
jne    12c1 <_HibernateCalendarSet+0x1b1>
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    12e3 <_HibernateCalendarSet+0x1d3>
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    1302 <_HibernateCalendarSet+0x1f2>
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   %rbx
push   %rax
mov    (%rsi),%eax
mov    0x4(%rsi),%ebx
and    $0x3f,%eax
shl    $0x8,%eax
and    $0x3f,%ebx
or     %eax,%ebx
testl  $0x4,0x400fc300
mov    0x8(%rsi),%eax
jne    1142 <_HibernateCalendarSet+0x32>
cmp    $0xff,%eax
jne    1165 <_HibernateCalendarSet+0x55>
or     $0x1f0000,%ebx
jmp    1181 <_HibernateCalendarSet+0x71>
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    1181 <_HibernateCalendarSet+0x71>
mov    %eax,%ecx
shl    $0x10,%ecx
cmp    $0xc,%eax
jl     117f <_HibernateCalendarSet+0x6f>
add    $0xfff40000,%ecx
or     %ecx,%ebx
or     $0x400000,%ebx
jmp    1181 <_HibernateCalendarSet+0x71>
or     %ecx,%ebx
mov    0xc(%rsi),%ebp
cmp    $0x400fc310,%edi
jne    11ea <_HibernateCalendarSet+0xda>
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
movl   $0xa3359554,0x400fc360
54 95 35 a3
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
mov    %ebx,0x400fc320
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
mov    %ebp,0x400fc324
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
movl   $0x0,0x400fc360
jmp    120a <_HibernateCalendarSet+0xfa>
xor    %eax,%eax
cmp    $0xff,%ebp
cmove  %eax,%ebp
mov    %ebx,0x400fc330
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
mov    %ebp,0x400fc334
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 i32, i32* inttoptr (i64 1074774784 to i32*)
%19 = and i32 %18, 4
%20 = icmp ne i32 %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 i32 -1556769452, i32* inttoptr (i64 1074774880 to i32*)
%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 %120
115: ; preds = %112
%116 = load i32, i32* %5
store volatile i32 %116, i32* inttoptr (i64 1074774816 to i32*)
%117 = call i32 (...) @_HibernateWriteComplete()
%118 = load i32, i32* %6
store volatile i32 %118, i32* inttoptr (i64 1074774820 to i32*)
%119 = call i32 (...) @_HibernateWriteComplete()
br label %125
120: ; preds = %112
%121 = load i32, i32* %5
store volatile i32 %121, i32* inttoptr (i64 1074774832 to i32*)
%122 = call i32 (...) @_HibernateWriteComplete()
%123 = load i32, i32* %6
store volatile i32 %123, i32* inttoptr (i64 1074774836 to i32*)
%124 = call i32 (...) @_HibernateWriteComplete()
br label %125
125: ; preds = %120, %115
%126 = load i32, i32* %3
%127 = icmp eq i32 %126, 1074774800
br i1 %127, label %128, label %130
128: ; preds = %125
store volatile i32 0, i32* inttoptr (i64 1074774880 to i32*)
%129 = call i32 (...) @_HibernateWriteComplete()
br label %130
130: ; preds = %128, %125
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 i32, i32* inttoptr (i64 1074774784 to i32*)
%12 = and i32 %11, 4
%13 = icmp eq i32 %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 %46, label %42
42: ; preds = %37
%43 = icmp eq i32 %41, 255
%44 = select i1 %43, i32 0, i32 %41
store volatile i32 %38, i32* inttoptr (i64 1074774832 to i32*)
%45 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 %44, i32* inttoptr (i64 1074774836 to i32*)
br label %64
46: ; preds = %37
%47 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 4
%48 = load i32, i32* %47
%49 = shl i32 %48, 8
%50 = add i32 %49, 256
%51 = or i32 %50, %41
%52 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 5
%53 = load i32, i32* %52
%54 = shl i32 %53, 24
%55 = or i32 %51, %54
%56 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 6
%57 = load i32, i32* %56
%58 = shl i32 %57, 16
%59 = add i32 %58, -6553600
%60 = or i32 %55, %59
store volatile i32 -1556769452, i32* inttoptr (i64 1074774880 to i32*)
%61 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 %38, i32* inttoptr (i64 1074774816 to i32*)
%62 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 %60, i32* inttoptr (i64 1074774820 to i32*)
%63 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 0, i32* inttoptr (i64 1074774880 to i32*)
br label %64
64: ; preds = %42, %46
%65 = tail call i32 (...) @_HibernateWriteComplete()
ret void
}