#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 */
int /*<<< orphan*/ kprintf(char *, ...);
void __kern_rtc_init(void) {
  char c1, c2, c3;
  unsigned char *reg = (unsigned char *)0x1020;
  c1 = *(reg + 0x0e) | 0x0f;
  c2 = 0x56;
  *(reg + 0x0f) = c2;
  c2 = *(reg + 0x0f);
  c3 = *(reg + 0x0d) & 0x01;
  kprintf("RTC:   ");
  if (c1 == 0x0f && c2 == 0) {
    kprintf("found at 0x%04x (battery ", 0x1020);
    if (c3)
      kprintf("OK)");
    else
      kprintf("invalid)");
    kprintf("\n");
    *(reg + 0x0e) = 0x04 | 0x02;
  } else {
    kprintf("not found\n");
  }
}


x86 assembly (clang, -O0):
<__kern_rtc_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1020,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0xe(%rax),%eax
or     $0xf,%eax
mov    %al,-0x1(%rbp)
movb   $0x56,-0x2(%rbp)
mov    -0x2(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0xf(%rax)
mov    -0x10(%rbp),%rax
mov    0xf(%rax),%al
mov    %al,-0x2(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0xd(%rax),%eax
and    $0x1,%eax
mov    %al,-0x3(%rbp)
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <kprintf@plt>
movsbl -0x1(%rbp),%eax
cmp    $0xf,%eax
jne    11d6 <__kern_rtc_init+0xc6>
movsbl -0x2(%rbp),%eax
cmp    $0x0,%eax
jne    11d6 <__kern_rtc_init+0xc6>
lea    0xe84(%rip),%rdi
mov    $0x1020,%esi
mov    $0x0,%al
call   1030 <kprintf@plt>
cmpb   $0x0,-0x3(%rbp)
je     11ad <__kern_rtc_init+0x9d>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <kprintf@plt>
jmp    11bb <__kern_rtc_init+0xab>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <kprintf@plt>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <kprintf@plt>
mov    -0x10(%rbp),%rax
movb   $0x6,0xe(%rax)
jmp    11e4 <__kern_rtc_init+0xd4>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <kprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__kern_rtc_init>:
push   %rax
movb   $0x56,0x102f
56
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1030 <kprintf@plt>
lea    0xeda(%rip),%rdi
xor    %eax,%eax
pop    %rcx
jmp    1030 <kprintf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"RTC: \00"
@.str.1 = [26 x i8] c"found at 0x%04x (battery \00"
@.str.2 = [4 x i8] c"OK)\00"
@.str.3 = [9 x i8] c"invalid)\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [11 x i8] c"not found\0A\00"
define void @__kern_rtc_init() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8*
store i8* inttoptr (i64 4128 to i8*), i8** %4
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8, i8* %5, i64 14
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = or i32 %8, 15
%10 = trunc i32 %9 to i8
store i8 %10, i8* %1
store i8 86, i8* %2
%11 = load i8, i8* %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 15
store i8 %11, i8* %13
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 15
%16 = load i8, i8* %15
store i8 %16, i8* %2
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 13
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = and i32 %20, 1
%22 = trunc i32 %21 to i8
store i8 %22, i8* %3
%23 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%24 = load i8, i8* %1
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 15
br i1 %26, label %27, label %43
27: ; preds = %0
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 4128)
%33 = load i8, i8* %3
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %39
37: ; preds = %31
%38 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
%40 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 14
store i8 6, i8* %42
br label %45
43: ; preds = %27, %0
%44 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"RTC: \00"
@.str.5 = [11 x i8] c"not found\0A\00"
define void @__kern_rtc_init() {
store i8 86, i8* inttoptr (i64 4143 to i8*)
%1 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
ret void
}