#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_mday;
  int tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ RTC_RD_TIME;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int, int, int,
                           int);
int ioctl(int, int /*<<< orphan*/, struct rtc_time *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int fd;
  int retval;
  struct rtc_time rtc_tm;
  fd = open("/dev/rtc0", O_RDONLY);
  if (!fd) {
    perror("Real Time Clock: Device could not be opened!");
    _exit(errno);
  }
  retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
  if (retval) {
    perror("Real Time Clock: RTC_RD_TIME ioctl error!\n");
    _exit(errno);
  }
  fprintf(stdout, "Real Time Clock: Date %d-%d-%d <> Time %02d:%02d:%02d\n",
          rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
          rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
  fflush(stdout);
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11d2 <main+0x52>
lea    0xe4b(%rip),%rdi
call   1090 <perror@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     120e <main+0x8e>
lea    0xe3c(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%r8d
add    $0x76c,%r8d
mov    -0x24(%rbp),%r9d
mov    -0x20(%rbp),%r10d
mov    -0x1c(%rbp),%eax
lea    0xe25(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <fprintf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
jne    11a9 <main+0x29>
lea    0xe63(%rip),%rdi
jmp    121f <main+0x9f>
mov    %eax,%ebx
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %eax,%eax
jne    1218 <main+0x98>
mov    0x2e07(%rip),%r14
mov    (%r14),%edi
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    $0x76c,%r8d
add    0x8(%rsp),%r8d
add    $0x1,%ecx
mov    0xc(%rsp),%r9d
mov    0x10(%rsp),%r10d
mov    0x14(%rsp),%eax
lea    0xe6c(%rip),%rsi
push   %rax
push   %r10
call   1060 <fprintf@plt>
add    $0x10,%rsp
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xe18(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.rtc_time = type { i32, i32, i32, i32, i32, i32 }
@.str = [10 x i8] c"/dev/rtc0\00"
@O_RDONLY = global i32 0
@.str.1 = [45 x i8] c"Real Time Clock: Device could not be opened!\00"
@errno = global i32 0
@RTC_RD_TIME = global i32 0
@.str.2 = [43 x i8] c"Real Time Clock: RTC_RD_TIME ioctl error!\0A\00"
@stdout = global i32 0
@.str.3 = [55 x i8] c"Real Time Clock: Date %d-%d-%d <> Time %02d:%02d:%02d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.rtc_time
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @errno
%16 = call i32 @_exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32, i32* %6
%19 = load i32, i32* @RTC_RD_TIME
%20 = call i32 @ioctl(i32 %18, i32 %19, %struct.rtc_time* %8)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @errno
%26 = call i32 @_exit(i32 %25)
unreachable
27: ; preds = %17
%28 = load i32, i32* @stdout
%29 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %8, i32 0, i32 1
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 1
%34 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %8, i32 0, i32 2
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1900
%37 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %8, i32 0, i32 3
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %8, i32 0, i32 4
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %8, i32 0, i32 5
%42 = load i32, i32* %41
%43 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %33, i32 %36, i32 %38, i32 %40, i32 %42)
%44 = load i32, i32* @stdout
%45 = call i32 @fflush(i32 %44)
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.rtc_time = type { i32, i32, i32, i32, i32, i32 }
@.str = [10 x i8] c"/dev/rtc0\00"
@O_RDONLY = global i32 0
@.str.1 = [45 x i8] c"Real Time Clock: Device could not be opened!\00"
@errno = global i32 0
@RTC_RD_TIME = global i32 0
@.str.2 = [43 x i8] c"Real Time Clock: RTC_RD_TIME ioctl error!\0A\00"
@stdout = global i32 0
@.str.3 = [55 x i8] c"Real Time Clock: Date %d-%d-%d <> Time %02d:%02d:%02d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.rtc_time
%4 = bitcast %struct.rtc_time* %3 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @errno
%11 = tail call i32 @_exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @RTC_RD_TIME
%14 = call i32 @ioctl(i32 %6, i32 %13, %struct.rtc_time* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @errno
%19 = call i32 @_exit(i32 %18)
unreachable
20: ; preds = %12
%21 = load i32, i32* @stdout
%22 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %3, i64 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %3, i64 0, i32 1
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
%27 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %3, i64 0, i32 2
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1900
%30 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %3, i64 0, i32 3
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %3, i64 0, i32 4
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %3, i64 0, i32 5
%35 = load i32, i32* %34
%36 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %26, i32 %29, i32 %31, i32 %33, i32 %35)
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
%39 = call i32 @close(i32 %6)
%40 = call i32 @exit(i32 0)
unreachable
}