#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 */

/* Variables and functions */
void *get_RTC_register(int);
scalar_t__ rtc_update_in_progress();
int rtc_get_hour() {
  int hour;
  int last_hour;
  while (rtc_update_in_progress())
    ;
  hour = get_RTC_register(0x04);
  do {
    last_hour = hour;
    while (rtc_update_in_progress())
      ;
    hour = get_RTC_register(0x04);
  } while (last_hour != hour);
  unsigned char registerB = get_RTC_register(0x0B);
  if (!(registerB & 0x04)) {
    hour = ((hour & 0x0F) + (((hour & 0x70) / 16) * 10)) | (hour & 0x80);
  }
  if (!(registerB & 0x02) && (hour & 0x80)) {
    hour = ((hour & 0x7F) + 12) % 24;
  }
  return hour;
}


x86 assembly (clang, -O0):
<rtc_get_hour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <rtc_update_in_progress@plt>
cmp    $0x0,%rax
je     113e <rtc_get_hour+0x1e>
jmp    1128 <rtc_get_hour+0x8>
mov    $0x4,%edi
call   1040 <get_RTC_register@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rtc_update_in_progress@plt>
cmp    $0x0,%rax
je     1167 <rtc_get_hour+0x47>
jmp    1151 <rtc_get_hour+0x31>
mov    $0x4,%edi
call   1040 <get_RTC_register@plt>
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    114b <rtc_get_hour+0x2b>
mov    $0xb,%edi
call   1040 <get_RTC_register@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    11cc <rtc_get_hour+0xac>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0x70,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
imul   $0xa,%ecx,%ecx
add    %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x80,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    1201 <rtc_get_hour+0xe1>
mov    -0x4(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1201 <rtc_get_hour+0xe1>
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
add    $0xc,%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtc_get_hour>:
push   %rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rtc_update_in_progress@plt>
test   %rax,%rax
jne    1130 <rtc_get_hour+0x10>
mov    $0x4,%edi
call   1040 <get_RTC_register@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rtc_update_in_progress@plt>
test   %rax,%rax
jne    1160 <rtc_get_hour+0x40>
mov    $0x4,%edi
call   1040 <get_RTC_register@plt>
cmp    %eax,%ebx
jne    1150 <rtc_get_hour+0x30>
mov    $0xb,%edi
call   1040 <get_RTC_register@plt>
test   $0x4,%al
jne    11a3 <rtc_get_hour+0x83>
mov    %ebx,%ecx
and    $0xf,%ecx
mov    %ebx,%edx
shr    $0x4,%edx
and    $0x7,%edx
lea    (%rdx,%rdx,4),%edx
lea    (%rcx,%rdx,2),%ecx
and    $0x80,%ebx
or     %ecx,%ebx
test   $0x2,%al
jne    11cd <rtc_get_hour+0xad>
mov    %ebx,%eax
and    $0x80,%eax
je     11cd <rtc_get_hour+0xad>
and    $0x7f,%bl
add    $0xc,%bl
movzbl %bl,%eax
imul   $0xab,%eax,%ecx
shr    $0x9,%ecx
and    $0xfffffff8,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %cl,%al
movzbl %al,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @rtc_get_hour() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
br label %4
4: ; preds = %7, %0
%5 = call i64 (...) @rtc_update_in_progress()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %4
br label %4
8: ; preds = %4
%9 = call i8* @get_RTC_register(i32 4)
%10 = ptrtoint i8* %9 to i32
store i32 %10, i32* %1
br label %11
11: ; preds = %20, %8
%12 = load i32, i32* %1
store i32 %12, i32* %2
br label %13
13: ; preds = %16, %11
%14 = call i64 (...) @rtc_update_in_progress()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
br label %13
17: ; preds = %13
%18 = call i8* @get_RTC_register(i32 4)
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %1
br label %20
20: ; preds = %17
%21 = load i32, i32* %2
%22 = load i32, i32* %1
%23 = icmp ne i32 %21, %22
br i1 %23, label %11, label %24
24: ; preds = %20
%25 = call i8* @get_RTC_register(i32 11)
%26 = ptrtoint i8* %25 to i8
store i8 %26, i8* %3
%27 = load i8, i8* %3
%28 = zext i8 %27 to i32
%29 = and i32 %28, 4
%30 = icmp ne i32 %29, 0
br i1 %30, label %42, label %31
31: ; preds = %24
%32 = load i32, i32* %1
%33 = and i32 %32, 15
%34 = load i32, i32* %1
%35 = and i32 %34, 112
%36 = sdiv i32 %35, 16
%37 = mul nsw i32 %36, 10
%38 = add nsw i32 %33, %37
%39 = load i32, i32* %1
%40 = and i32 %39, 128
%41 = or i32 %38, %40
store i32 %41, i32* %1
br label %42
42: ; preds = %31, %24
%43 = load i8, i8* %3
%44 = zext i8 %43 to i32
%45 = and i32 %44, 2
%46 = icmp ne i32 %45, 0
br i1 %46, label %56, label %47
47: ; preds = %42
%48 = load i32, i32* %1
%49 = and i32 %48, 128
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i32, i32* %1
%53 = and i32 %52, 127
%54 = add nsw i32 %53, 12
%55 = srem i32 %54, 24
store i32 %55, i32* %1
br label %56
56: ; preds = %51, %47, %42
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
define i32 @rtc_get_hour() {
br label %1
1: ; preds = %1, %0
%2 = tail call i64 (...) @rtc_update_in_progress()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %1
4: ; preds = %1
%5 = tail call i8* @get_RTC_register(i32 4)
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
br label %8
8: ; preds = %13, %4
%9 = phi i32 [ %7, %4 ], [ %16, %13 ]
br label %10
10: ; preds = %10, %8
%11 = tail call i64 (...) @rtc_update_in_progress()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %10
13: ; preds = %10
%14 = tail call i8* @get_RTC_register(i32 4)
%15 = ptrtoint i8* %14 to i64
%16 = trunc i64 %15 to i32
%17 = icmp eq i32 %9, %16
br i1 %17, label %18, label %8
18: ; preds = %13
%19 = tail call i8* @get_RTC_register(i32 11)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i32
%22 = and i32 %21, 4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %18
%25 = and i32 %9, 15
%26 = lshr i32 %9, 4
%27 = and i32 %26, 7
%28 = mul nuw nsw i32 %27, 10
%29 = add nuw nsw i32 %28, %25
%30 = and i32 %9, 128
%31 = or i32 %29, %30
br label %32
32: ; preds = %24, %18
%33 = phi i32 [ %9, %18 ], [ %31, %24 ]
%34 = and i32 %21, 2
%35 = icmp ne i32 %34, 0
%36 = and i32 %33, 128
%37 = icmp eq i32 %36, 0
%38 = select i1 %35, i1 true, i1 %37
br i1 %38, label %45, label %39
39: ; preds = %32
%40 = trunc i32 %33 to i8
%41 = and i8 %40, 127
%42 = add nuw i8 %41, 12
%43 = urem i8 %42, 24
%44 = zext i8 %43 to i32
br label %45
45: ; preds = %39, %32
%46 = phi i32 [ %33, %32 ], [ %44, %39 ]
ret i32 %46
}