#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 rtc_time {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ RTC_RD_TIME;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct rtc_time *);
int /*<<< orphan*/ memset(struct rtc_time *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read_rtc() {
  int rtc;
  struct rtc_time tm;
  rtc = open("/dev/rtc0", O_RDONLY);
  if (!rtc) {
    printf("Could not access RTC\n");
  }
  memset(&tm, 0, sizeof(struct rtc_time));
  if (ioctl(rtc, RTC_RD_TIME, &tm))
    printf("Could not read time from RTC\n");
  printf("read the rtc time: year = %d; mon = %d; mday = %d;            hour = "
         "%d; min = %d; hour = %d. \n",
         tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_hour);
  close(rtc);
  return 0;
}


x86 assembly (clang, -O0):
<read_rtc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1188 <read_rtc+0x38>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     11c5 <read_rtc+0x75>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x8(%rbp),%r9d
mov    -0xc(%rbp),%eax
lea    0xe5e(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_rtc>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    118e <read_rtc+0x2e>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
je     11c6 <read_rtc+0x66>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
mov    0x20(%rsp),%r9d
mov    %r8d,(%rsp)
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rtc_time = type { i32, i32, i32, i32, i32 }
@.str = [10 x i8] c"/dev/rtc0\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Could not access RTC\0A\00"
@RTC_RD_TIME = global i32 0
@.str.2 = [30 x i8] c"Could not read time from RTC\0A\00"
@.str.3 = [96 x i8] c"read the rtc time: year = %d; mon = %d; mday = %d; hour = %d; min = %d; hour = %d. \0A\00"
define i32 @read_rtc() {
%1 = alloca i32
%2 = alloca %struct.rtc_time
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @memset(%struct.rtc_time* %2, i32 0, i32 20)
%11 = load i32, i32* %1
%12 = load i32, i32* @RTC_RD_TIME
%13 = call i64 @ioctl(i32 %11, i32 %12, %struct.rtc_time* %2)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 2
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 3
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 4
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 3
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %21, i32 %23, i32 %25, i32 %27, i32 %29)
%31 = load i32, i32* %1
%32 = call i32 @close(i32 %31)
ret i32 0
}

LLVM IR (-O2):
%struct.rtc_time = type { i32, i32, i32, i32, i32 }
@.str = [10 x i8] c"/dev/rtc0\00"
@O_RDONLY = global i32 0
@RTC_RD_TIME = global i32 0
@.str.3 = [96 x i8] c"read the rtc time: year = %d; mon = %d; mday = %d; hour = %d; min = %d; hour = %d. \0A\00"
@str = [21 x i8] c"Could not access RTC\00"
@str.4 = [29 x i8] c"Could not read time from RTC\00"
define i32 @read_rtc() {
%1 = alloca %struct.rtc_time
%2 = bitcast %struct.rtc_time* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @memset(%struct.rtc_time* %1, i32 0, i32 20)
%10 = load i32, i32* @RTC_RD_TIME
%11 = call i64 @ioctl(i32 %4, i32 %10, %struct.rtc_time* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 4
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %19, i32 %21, i32 %23, i32 %25, i32 %23)
%27 = call i32 @close(i32 %4)
ret i32 0
}