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

/* Variables and functions */
int /*<<< orphan*/ RTC_RD_TIME;
int ioctl(int, int /*<<< orphan*/, struct rtc_time *);
int /*<<< orphan*/ printf(char *, ...);
void read_time(int fd) {
  int i, retval;
  unsigned long tmp, data;
  struct rtc_time rtc_tm;
  int scale_type = 1;
  struct rtc_wkalrm rtc_alarmtm;
  retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
  if (retval < 0) {
    printf("ioctl RTC_RD_TIME  faild!!!\n");
    return;
  }
  printf("Read current RTC time is: %04d-%02d-%02d %02d:%02d:%02d\n\n",
         rtc_tm.tm_year + 1900, rtc_tm.tm_mon + 1, rtc_tm.tm_mday,
         rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
  printf("Read current RTC time test OK!\n");
}


x86 assembly (clang, -O0):
<read_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1167 <read_time+0x47>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a3 <read_time+0x83>
mov    -0x38(%rbp),%esi
add    $0x76c,%esi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x24(%rbp),%eax
lea    0xe92(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_time>:
sub    $0x28,%rsp
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1050 <ioctl@plt>
test   %eax,%eax
js     1187 <read_time+0x57>
mov    $0x76c,%esi
add    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
add    $0x1,%edx
mov    0x1c(%rsp),%r8d
mov    0x20(%rsp),%r9d
mov    0x24(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
jmp    118e <read_time+0x5e>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.rtc_time = type { i32, i32, i32, i32, i32, i32 }
%struct.rtc_wkalrm = type { i32 }
@RTC_RD_TIME = global i32 0
@.str = [29 x i8] c"ioctl RTC_RD_TIME faild!!!\0A\00"
@.str.1 = [58 x i8] c"Read current RTC time is: %04d-%02d-%02d %02d:%02d:%02d\0A\0A\00"
@.str.2 = [32 x i8] c"Read current RTC time test OK!\0A\00"
define void @read_time(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.rtc_time
%8 = alloca i32
%9 = alloca %struct.rtc_wkalrm
store i32 %0, i32* %2
store i32 1, i32* %8
%10 = load i32, i32* %2
%11 = load i32, i32* @RTC_RD_TIME
%12 = call i32 @ioctl(i32 %10, i32 %11, %struct.rtc_time* %7)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %34
17: ; preds = %1
%18 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %7, i32 0, i32 0
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1900
%21 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %7, i32 0, i32 1
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
%24 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %7, i32 0, i32 2
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %7, i32 0, i32 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %7, i32 0, i32 4
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %7, i32 0, i32 5
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %17, %15
ret void
}

LLVM IR (-O2):
%struct.rtc_time = type { i32, i32, i32, i32, i32, i32 }
@RTC_RD_TIME = global i32 0
@.str.1 = [58 x i8] c"Read current RTC time is: %04d-%02d-%02d %02d:%02d:%02d\0A\0A\00"
@str = [31 x i8] c"Read current RTC time test OK!\00"
@str.3 = [28 x i8] c"ioctl RTC_RD_TIME faild!!!\00"
define void @read_time(i32 %0) {
%2 = alloca %struct.rtc_time
%3 = bitcast %struct.rtc_time* %2 to i8*
%4 = load i32, i32* @RTC_RD_TIME
%5 = call i32 @ioctl(i32 %0, i32 %4, %struct.rtc_time* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %1
%8 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1900
%11 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 5
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21)
br label %23
23: ; preds = %1, %7
%24 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.3, i64 0, i64 0), %1 ]
%25 = call i32 @puts(i8* dereferenceable(1) %24)
ret void
}