#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ RTC_SET_TIME;
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, struct rtc_time *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ real_time_2_tm(int, int, int, int, int, int,
                                  struct rtc_time *);
char *strerror(int /*<<< orphan*/);
int test_set_time(int fd) {
  int ret;
  struct rtc_time time;
  printf("==== set time ====\n");
  real_time_2_tm(2017, 2, 27, 12, 30, 15, &time);
  ret = ioctl(fd, RTC_SET_TIME, &time);
  if (ret) {
    printf("set time failed: %s\n", strerror(errno));
    return ret;
  }
  printf("\tset time OK.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_set_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x7e1,%edi
mov    $0x2,%esi
mov    $0x1b,%edx
mov    $0xc,%ecx
mov    $0x1e,%r8d
mov    $0xf,%r9d
lea    -0x10(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <real_time_2_tm@plt>
mov    -0x8(%rbp),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11d2 <test_set_time+0x92>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <test_set_time+0xa7>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_set_time>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%r14
mov    %r14,(%rsp)
mov    $0x7e1,%edi
mov    $0x2,%esi
mov    $0x1b,%edx
mov    $0xc,%ecx
mov    $0x1e,%r8d
mov    $0xf,%r9d
call   1060 <real_time_2_tm@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11cd <test_set_time+0x7d>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d9 <test_set_time+0x89>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rtc_time = type { i32 }
@.str = [20 x i8] c"==== set time ====\0A\00"
@RTC_SET_TIME = global i32 0
@.str.1 = [21 x i8] c"set time failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [15 x i8] c"\09set time OK.\0A\00"
define i32 @test_set_time(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.rtc_time
store i32 %0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @real_time_2_tm(i32 2017, i32 2, i32 27, i32 12, i32 30, i32 15, %struct.rtc_time* %5)
%8 = load i32, i32* %3
%9 = load i32, i32* @RTC_SET_TIME
%10 = call i32 @ioctl(i32 %8, i32 %9, %struct.rtc_time* %5)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %20
18: ; preds = %1
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.rtc_time = type { i32 }
@RTC_SET_TIME = global i32 0
@.str.1 = [21 x i8] c"set time failed: %s\0A\00"
@errno = global i32 0
@str = [19 x i8] c"==== set time ====\00"
@str.3 = [14 x i8] c"\09set time OK.\00"
define i32 @test_set_time(i32 %0) {
%2 = alloca %struct.rtc_time
%3 = bitcast %struct.rtc_time* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = call i32 @real_time_2_tm(i32 2017, i32 2, i32 27, i32 12, i32 30, i32 15, %struct.rtc_time* %2)
%6 = load i32, i32* @RTC_SET_TIME
%7 = call i32 @ioctl(i32 %0, i32 %6, %struct.rtc_time* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %15
13: ; preds = %1
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
ret i32 %7
}