#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_sec;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
};

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ RTC_ALM_SET;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct rtc_time *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int set_alarm() {
  int rtc;
  struct rtc_time alrm;
  rtc = open("/dev/rtc0", O_WRONLY);
  if (!rtc) {
    printf("Could not access RTC\n");
  }
  alrm.tm_mday = 1;
  alrm.tm_hour = 0;
  alrm.tm_min = 0;
  alrm.tm_sec = 20;
  if (ioctl(rtc, RTC_ALM_SET, &alrm))
    printf("Could not set alrm\n");
  close(rtc);
  return 0;
}


x86 assembly (clang, -O0):
<set_alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1176 <set_alarm+0x36>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x14,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     11bf <set_alarm+0x7f>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_alarm>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    116c <set_alarm+0x2c>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
movabs $0x1400000001,%rax
mov    %rax,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
je     11a9 <set_alarm+0x69>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rtc_time = type { i32, i32, i64, i64 }
@.str = [10 x i8] c"/dev/rtc0\00"
@O_WRONLY = global i32 0
@.str.1 = [22 x i8] c"Could not access RTC\0A\00"
@RTC_ALM_SET = global i32 0
@.str.2 = [20 x i8] c"Could not set alrm\0A\00"
define i32 @set_alarm() {
%1 = alloca i32
%2 = alloca %struct.rtc_time
%3 = load i32, i32* @O_WRONLY
%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 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 0
store i32 1, i32* %10
%11 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 3
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 2
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i32 0, i32 1
store i32 20, i32* %13
%14 = load i32, i32* %1
%15 = load i32, i32* @RTC_ALM_SET
%16 = call i64 @ioctl(i32 %14, i32 %15, %struct.rtc_time* %2)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %9
%21 = load i32, i32* %1
%22 = call i32 @close(i32 %21)
ret i32 0
}

LLVM IR (-O2):
%struct.rtc_time = type { i32, i32, i64, i64 }
@.str = [10 x i8] c"/dev/rtc0\00"
@O_WRONLY = global i32 0
@RTC_ALM_SET = global i32 0
@str = [21 x i8] c"Could not access RTC\00"
@str.3 = [19 x i8] c"Could not set alrm\00"
define i32 @set_alarm() {
%1 = alloca %struct.rtc_time
%2 = bitcast %struct.rtc_time* %1 to i8*
%3 = load i32, i32* @O_WRONLY
%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 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 0
store i32 1, i32* %9
%10 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 2
%11 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %1, i64 0, i32 1
%12 = bitcast i64* %10 to i8*
store i32 20, i32* %11
%13 = load i32, i32* @RTC_ALM_SET
%14 = call i64 @ioctl(i32 %4, i32 %13, %struct.rtc_time* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %8
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
%19 = call i32 @close(i32 %4)
ret i32 0
}