#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*/ O_RDONLY;
int /*<<< orphan*/ RTC_ALM_READ;
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 get_alarm() {
  int rtc;
  struct rtc_time alrm;
  rtc = open("/dev/rtc0", O_RDONLY);
  if (!rtc) {
    printf("Could not access RTC\n");
  }
  memset(&alrm, 0, sizeof(struct rtc_time));
  if (ioctl(rtc, RTC_ALM_READ, &alrm))
    printf("Could not get alrm\n");
  close(rtc);
  return 0;
}


x86 assembly (clang, -O0):
<get_alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%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    1186 <get_alarm+0x36>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     11c1 <get_alarm+0x71>
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_alarm>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    117b <get_alarm+0x2b>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
je     11b1 <get_alarm+0x61>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rtc_time = type { 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_ALM_READ = global i32 0
@.str.2 = [20 x i8] c"Could not get alrm\0A\00"
define i32 @get_alarm() {
%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 @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 4)
%11 = load i32, i32* %1
%12 = load i32, i32* @RTC_ALM_READ
%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 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = load i32, i32* %1
%19 = call i32 @close(i32 %18)
ret i32 0
}

LLVM IR (-O2):
%struct.rtc_time = type { i32 }
@.str = [10 x i8] c"/dev/rtc0\00"
@O_RDONLY = global i32 0
@RTC_ALM_READ = global i32 0
@str = [21 x i8] c"Could not access RTC\00"
@str.3 = [19 x i8] c"Could not get alrm\00"
define i32 @get_alarm() {
%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 4)
%10 = load i32, i32* @RTC_ALM_READ
%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 ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = call i32 @close(i32 %4)
ret i32 0
}