#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 tm {
  int dummy;
};
struct timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ eprintf(char *, ...);
int /*<<< orphan*/ mktime(struct tm *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ readrtctm(struct tm *, int);
int settimeofday(struct timeval *, int /*<<< orphan*/ *);
void hctosys(char *dev) {
  struct timeval tv;
  struct tm tm;
  int r;
  int fd;
  fd = open(dev, O_RDONLY);
  if (fd < 0)
    eprintf("open %s:", dev);
  readrtctm(&tm, fd);
  tv.tv_sec = mktime(&tm);
  tv.tv_usec = 0;
  r = settimeofday(&tv, NULL);
  if (r < 0)
    eprintf("settimeofday:");
  close(fd);
}


x86 assembly (clang, -O0):
<hctosys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    119d <hctosys+0x3d>
mov    -0x8(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1070 <eprintf@plt>
mov    -0x28(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1060 <readrtctm@plt>
lea    -0x20(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <settimeofday@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11e5 <hctosys+0x85>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1070 <eprintf@plt>
mov    -0x28(%rbp),%edi
call   1030 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hctosys>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    118e <hctosys+0x2e>
lea    0xe7c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <eprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <readrtctm@plt>
mov    %rbx,%rdi
call   1050 <mktime@plt>
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <settimeofday@plt>
test   %eax,%eax
jns    11ce <hctosys+0x6e>
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1070 <eprintf@plt>
mov    %ebp,%edi
call   1030 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@O_RDONLY = global i32 0
@.str = [9 x i8] c"open %s:\00"
@.str.1 = [14 x i8] c"settimeofday:\00"
define void @hctosys(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca %struct.tm
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %1
%16 = load i32, i32* %6
%17 = call i32 @readrtctm(%struct.tm* %4, i32 %16)
%18 = call i32 @mktime(%struct.tm* %4)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i64 0, i64* %20
%21 = call i32 @settimeofday(%struct.timeval* %3, i32* null)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %15
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@O_RDONLY = global i32 0
@.str = [9 x i8] c"open %s:\00"
@.str.1 = [14 x i8] c"settimeofday:\00"
define void @hctosys(i8* %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.tm
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.tm* %3 to i8*
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %1
%12 = call i32 @readrtctm(%struct.tm* %3, i32 %7)
%13 = call i32 @mktime(%struct.tm* %3)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i64 0, i64* %15
%16 = call i32 @settimeofday(%struct.timeval* %2, i32* null)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 (i8*, ...) @eprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = call i32 @close(i32 %7)
ret void
}