#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_second() {
  int second;
  int last_second;
  while (rtc_update_in_progress())
    ;
  second = get_RTC_register(0x00);
  do {
    last_second = second;
    while (rtc_update_in_progress())
      ;
    second = get_RTC_register(0x00);
  } while (last_second != second);
  unsigned char registerB = get_RTC_register(0x0B);
  if (!(registerB & 0x04)) {
    second = (second & 0x0F) + ((second / 16) * 10);
  }
  return second;
}


x86 assembly (clang, -O0):
<rtc_get_second>:
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_second+0x1e>
jmp    1128 <rtc_get_second+0x8>
xor    %edi,%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     1164 <rtc_get_second+0x44>
jmp    114e <rtc_get_second+0x2e>
xor    %edi,%edi
call   1040 <get_RTC_register@plt>
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1148 <rtc_get_second+0x28>
mov    $0xb,%edi
call   1040 <get_RTC_register@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    11b8 <rtc_get_second+0x98>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
imul   $0xa,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtc_get_second>:
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_second+0x10>
xor    %edi,%edi
call   1040 <get_RTC_register@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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_second+0x40>
xor    %edi,%edi
call   1040 <get_RTC_register@plt>
cmp    %eax,%ebx
jne    1150 <rtc_get_second+0x30>
mov    $0xb,%edi
call   1040 <get_RTC_register@plt>
test   $0x4,%al
jne    119b <rtc_get_second+0x7b>
mov    %ebx,%eax
and    $0xf,%eax
lea    0xf(%rbx),%ecx
test   %ebx,%ebx
cmovns %ebx,%ecx
sar    $0x4,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rax,%rcx,2),%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @rtc_get_second() {
%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 0)
%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 0)
%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 %38, label %31
31: ; preds = %24
%32 = load i32, i32* %1
%33 = and i32 %32, 15
%34 = load i32, i32* %1
%35 = sdiv i32 %34, 16
%36 = mul nsw i32 %35, 10
%37 = add nsw i32 %33, %36
store i32 %37, i32* %1
br label %38
38: ; preds = %31, %24
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
define i32 @rtc_get_second() {
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 0)
%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 0)
%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 = and i64 %20, 4
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = and i32 %9, 15
%25 = sdiv i32 %9, 16
%26 = mul nsw i32 %25, 10
%27 = add nsw i32 %26, %24
br label %28
28: ; preds = %23, %18
%29 = phi i32 [ %9, %18 ], [ %27, %23 ]
ret i32 %29
}