#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, int *, int);
int main() {
  int xfd = open("/dev/cmos/0", O_RDONLY);
  if (xfd < 0) {
    perror("open cmos");
    goto error;
  }
  if (lseek(xfd, 0x09 * 8, SEEK_SET) < 0) {
    perror("lseek year");
    goto error;
  }
  uint8_t year;
  if (read(xfd, &year, 8) < 0) {
    perror("lseek year");
    goto error;
  }
  printf("year is %x\n", year);
  return 0;
error:
  close(xfd);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a2 <main+0x42>
lea    0xe74(%rip),%rdi
call   1080 <perror@plt>
jmp    121a <main+0xba>
mov    -0x8(%rbp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    $0x48,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    11d3 <main+0x73>
lea    0xe4d(%rip),%rdi
call   1080 <perror@plt>
jmp    121a <main+0xba>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jge    11ff <main+0x9f>
lea    0xe21(%rip),%rdi
call   1080 <perror@plt>
jmp    121a <main+0xba>
mov    -0xc(%rbp),%esi
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1229 <main+0xc9>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11d0 <main+0x70>
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x48,%esi
call   1040 <lseek@plt>
lea    0xe7b(%rip),%r14
test   %rax,%rax
js     11d7 <main+0x77>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1060 <read@plt>
test   %rax,%rax
js     11d7 <main+0x77>
mov    0x4(%rsp),%esi
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe35(%rip),%r14
mov    %r14,%rdi
call   1080 <perror@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
jmp    11c8 <main+0x68>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/cmos/0\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"open cmos\00"
@SEEK_SET = global i32 0
@.str.2 = [11 x i8] c"lseek year\00"
@.str.3 = [12 x i8] c"year is %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %26
10: ; preds = %0
%11 = load i32, i32* %2
%12 = load i32, i32* @SEEK_SET
%13 = call i64 @lseek(i32 %11, i32 72, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %26
17: ; preds = %10
%18 = load i32, i32* %2
%19 = call i64 @read(i32 %18, i32* %3, i32 8)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %26
23: ; preds = %17
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %24)
store i32 0, i32* %1
br label %29
26: ; preds = %21, %15, %8
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %1
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/cmos/0\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"open cmos\00"
@SEEK_SET = global i32 0
@.str.2 = [11 x i8] c"lseek year\00"
@.str.3 = [12 x i8] c"year is %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %0
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @lseek(i32 %3, i32 72, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = call i64 @read(i32 %3, i32* %1, i32 8)
%11 = icmp slt i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %19
15: ; preds = %9, %5, %0
%16 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %9 ]
%17 = tail call i32 @perror(i8* %16)
%18 = tail call i32 @close(i32 %3)
br label %19
19: ; preds = %15, %12
%20 = phi i32 [ -1, %15 ], [ 0, %12 ]
ret i32 %20
}