#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 */
struct tm {
  int tm_sec;
  int tm_min;
  int tm_hour;
  unsigned char tm_wday;
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_isdst;
  scalar_t__ tm_yday;
};

/* Variables and functions */
int bcd2bin(unsigned short volatile);
void rtc_gettime(struct tm *t) {
  do {
    (*(unsigned char volatile *)0xa413fedc) =
        (*(unsigned char volatile *)0xa413fedc) & 0x6f;
    t->tm_sec = bcd2bin((*(unsigned char volatile *)0xa413fec2));
    t->tm_min = bcd2bin((*(unsigned char volatile *)0xa413fec4));
    t->tm_hour = bcd2bin((*(unsigned char volatile *)0xa413fec6));
    t->tm_wday = (*(unsigned char volatile *)0xa413fec8);
    t->tm_mday = bcd2bin((*(unsigned char volatile *)0xa413feca));
    t->tm_mon = bcd2bin((*(unsigned char volatile *)0xa413fecc));
    t->tm_year =
        (bcd2bin((*(unsigned short volatile *)0xa413fece) >> 8) * 100) |
        bcd2bin((*(unsigned short volatile *)0xa413fece) & 0xff);
  } while ((*(unsigned char volatile *)0xa413fedc) & 0x80);
  t->tm_yday = 0;
  t->tm_isdst = -1;
}


x86 assembly (clang, -O0):
<rtc_gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xa413fedc,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x6f,%eax
mov    %al,%cl
mov    $0xa413fedc,%eax
mov    %cl,(%rax)
mov    $0xa413fec2,%eax
mov    (%rax),%al
movzbl %al,%eax
movzwl %ax,%edi
call   1030 <bcd2bin@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    $0xa413fec4,%eax
mov    (%rax),%al
movzbl %al,%eax
movzwl %ax,%edi
call   1030 <bcd2bin@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0xa413fec6,%eax
mov    (%rax),%al
movzbl %al,%eax
movzwl %ax,%edi
call   1030 <bcd2bin@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    $0xa413fec8,%eax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xc(%rax)
mov    $0xa413feca,%eax
mov    (%rax),%al
movzbl %al,%eax
movzwl %ax,%edi
call   1030 <bcd2bin@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    $0xa413fecc,%eax
mov    (%rax),%al
movzbl %al,%eax
movzwl %ax,%edi
call   1030 <bcd2bin@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    $0xa413fece,%eax
mov    (%rax),%ax
movzwl %ax,%eax
sar    $0x8,%eax
movzwl %ax,%edi
call   1030 <bcd2bin@plt>
imul   $0x64,%eax,%eax
mov    %eax,-0xc(%rbp)
mov    $0xa413fece,%eax
mov    (%rax),%ax
movzwl %ax,%eax
and    $0xff,%eax
movzwl %ax,%edi
call   1030 <bcd2bin@plt>
mov    -0xc(%rbp),%ecx
or     %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    $0xa413fedc,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    111c <rtc_gettime+0xc>
mov    -0x8(%rbp),%rax
movq   $0x0,0x20(%rax)
mov    -0x8(%rbp),%rax
movl   $0xffffffff,0x1c(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtc_gettime>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0xa413fedc,%r14d
nopl   (%rax)
andb   $0x6f,(%r14)
movzbl -0x1a(%r14),%edi
call   1030 <bcd2bin@plt>
mov    %eax,(%rbx)
movzbl -0x18(%r14),%edi
call   1030 <bcd2bin@plt>
mov    %eax,0x4(%rbx)
movzbl -0x16(%r14),%edi
call   1030 <bcd2bin@plt>
mov    %eax,0x8(%rbx)
movzbl -0x14(%r14),%eax
mov    %al,0xc(%rbx)
movzbl -0x12(%r14),%edi
call   1030 <bcd2bin@plt>
mov    %eax,0x10(%rbx)
movzbl -0x10(%r14),%edi
call   1030 <bcd2bin@plt>
mov    %eax,0x14(%rbx)
movzwl -0xe(%r14),%edi
shr    $0x8,%edi
call   1030 <bcd2bin@plt>
imul   $0x64,%eax,%ebp
movzwl -0xe(%r14),%eax
movzbl %al,%edi
call   1030 <bcd2bin@plt>
or     %ebp,%eax
mov    %eax,0x18(%rbx)
cmpb   $0x0,(%r14)
js     1120 <rtc_gettime+0x10>
movq   $0x0,0x20(%rbx)
movl   $0xffffffff,0x1c(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i8, i32, i32, i32, i32, i64 }
define void @rtc_gettime(%struct.tm* %0) {
%2 = alloca %struct.tm*
store %struct.tm* %0, %struct.tm** %2
br label %3
3: ; preds = %50, %1
%4 = load volatile i8, i8* inttoptr (i64 2752773852 to i8*)
%5 = zext i8 %4 to i32
%6 = and i32 %5, 111
%7 = trunc i32 %6 to i8
store volatile i8 %7, i8* inttoptr (i64 2752773852 to i8*)
%8 = load volatile i8, i8* inttoptr (i64 2752773826 to i8*)
%9 = zext i8 %8 to i16
%10 = call i32 @bcd2bin(i16 zeroext %9)
%11 = load %struct.tm*, %struct.tm** %2
%12 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load volatile i8, i8* inttoptr (i64 2752773828 to i8*)
%14 = zext i8 %13 to i16
%15 = call i32 @bcd2bin(i16 zeroext %14)
%16 = load %struct.tm*, %struct.tm** %2
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 1
store i32 %15, i32* %17
%18 = load volatile i8, i8* inttoptr (i64 2752773830 to i8*)
%19 = zext i8 %18 to i16
%20 = call i32 @bcd2bin(i16 zeroext %19)
%21 = load %struct.tm*, %struct.tm** %2
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 2
store i32 %20, i32* %22
%23 = load volatile i8, i8* inttoptr (i64 2752773832 to i8*)
%24 = load %struct.tm*, %struct.tm** %2
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 3
store i8 %23, i8* %25
%26 = load volatile i8, i8* inttoptr (i64 2752773834 to i8*)
%27 = zext i8 %26 to i16
%28 = call i32 @bcd2bin(i16 zeroext %27)
%29 = load %struct.tm*, %struct.tm** %2
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 4
store i32 %28, i32* %30
%31 = load volatile i8, i8* inttoptr (i64 2752773836 to i8*)
%32 = zext i8 %31 to i16
%33 = call i32 @bcd2bin(i16 zeroext %32)
%34 = load %struct.tm*, %struct.tm** %2
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 5
store i32 %33, i32* %35
%36 = load volatile i16, i16* inttoptr (i64 2752773838 to i16*)
%37 = zext i16 %36 to i32
%38 = ashr i32 %37, 8
%39 = trunc i32 %38 to i16
%40 = call i32 @bcd2bin(i16 zeroext %39)
%41 = mul nsw i32 %40, 100
%42 = load volatile i16, i16* inttoptr (i64 2752773838 to i16*)
%43 = zext i16 %42 to i32
%44 = and i32 %43, 255
%45 = trunc i32 %44 to i16
%46 = call i32 @bcd2bin(i16 zeroext %45)
%47 = or i32 %41, %46
%48 = load %struct.tm*, %struct.tm** %2
%49 = getelementptr inbounds %struct.tm, %struct.tm* %48, i32 0, i32 6
store i32 %47, i32* %49
br label %50
50: ; preds = %3
%51 = load volatile i8, i8* inttoptr (i64 2752773852 to i8*)
%52 = zext i8 %51 to i32
%53 = and i32 %52, 128
%54 = icmp ne i32 %53, 0
br i1 %54, label %3, label %55
55: ; preds = %50
%56 = load %struct.tm*, %struct.tm** %2
%57 = getelementptr inbounds %struct.tm, %struct.tm* %56, i32 0, i32 8
store i64 0, i64* %57
%58 = load %struct.tm*, %struct.tm** %2
%59 = getelementptr inbounds %struct.tm, %struct.tm* %58, i32 0, i32 7
store i32 -1, i32* %59
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i8, i32, i32, i32, i32, i64 }
define void @rtc_gettime(%struct.tm* nocapture writeonly %0) {
%2 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%3 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%4 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%5 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
%6 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
%7 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
%8 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 6
br label %9
9: ; preds = %9, %1
%10 = load volatile i8, i8* inttoptr (i64 2752773852 to i8*)
%11 = and i8 %10, 111
store volatile i8 %11, i8* inttoptr (i64 2752773852 to i8*)
%12 = load volatile i8, i8* inttoptr (i64 2752773826 to i8*)
%13 = zext i8 %12 to i16
%14 = tail call i32 @bcd2bin(i16 zeroext %13)
store i32 %14, i32* %2
%15 = load volatile i8, i8* inttoptr (i64 2752773828 to i8*)
%16 = zext i8 %15 to i16
%17 = tail call i32 @bcd2bin(i16 zeroext %16)
store i32 %17, i32* %3
%18 = load volatile i8, i8* inttoptr (i64 2752773830 to i8*)
%19 = zext i8 %18 to i16
%20 = tail call i32 @bcd2bin(i16 zeroext %19)
store i32 %20, i32* %4
%21 = load volatile i8, i8* inttoptr (i64 2752773832 to i8*)
store i8 %21, i8* %5
%22 = load volatile i8, i8* inttoptr (i64 2752773834 to i8*)
%23 = zext i8 %22 to i16
%24 = tail call i32 @bcd2bin(i16 zeroext %23)
store i32 %24, i32* %6
%25 = load volatile i8, i8* inttoptr (i64 2752773836 to i8*)
%26 = zext i8 %25 to i16
%27 = tail call i32 @bcd2bin(i16 zeroext %26)
store i32 %27, i32* %7
%28 = load volatile i16, i16* inttoptr (i64 2752773838 to i16*)
%29 = lshr i16 %28, 8
%30 = tail call i32 @bcd2bin(i16 zeroext %29)
%31 = mul nsw i32 %30, 100
%32 = load volatile i16, i16* inttoptr (i64 2752773838 to i16*)
%33 = and i16 %32, 255
%34 = tail call i32 @bcd2bin(i16 zeroext %33)
%35 = or i32 %34, %31
store i32 %35, i32* %8
%36 = load volatile i8, i8* inttoptr (i64 2752773852 to i8*)
%37 = icmp sgt i8 %36, -1
br i1 %37, label %38, label %9
38: ; preds = %9
%39 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 8
store i64 0, i64* %39
%40 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 7
store i32 -1, i32* %40
ret void
}