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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ eprintf(char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *gmtime(int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ weprintf(char *);
int /*<<< orphan*/ writertctm(struct tm *, int);
void systohc(char *dev) {
  struct timeval tv;
  struct tm *tm;
  time_t t;
  int fd;
  fd = open(dev, O_WRONLY);
  if (fd < 0)
    eprintf("open %s:", dev);
  gettimeofday(&tv, NULL);
  t = tv.tv_sec;
  tm = gmtime(&t);
  weprintf("warning: assuming UTC for systohc\n");
  writertctm(tm, fd);
  close(fd);
}


x86 assembly (clang, -O0):
<systohc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11ab <systohc+0x3b>
mov    -0x8(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1070 <eprintf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1090 <gmtime@plt>
mov    %rax,-0x18(%rbp)
lea    0xe37(%rip),%rdi
call   1060 <weprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <writertctm@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<systohc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    119a <systohc+0x2a>
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
call   1070 <eprintf@plt>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %r14,%rdi
call   1090 <gmtime@plt>
mov    %rax,%r14
lea    0xe4e(%rip),%rdi
call   1060 <weprintf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <writertctm@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@O_WRONLY = global i32 0
@.str = [9 x i8] c"open %s:\00"
@.str.1 = [35 x i8] c"warning: assuming UTC for systohc\0A\00"
define void @systohc(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_WRONLY
%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 @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 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %5
%19 = call %struct.tm* @gmtime(i32* %5)
store %struct.tm* %19, %struct.tm** %4
%20 = call i32 @weprintf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%21 = load %struct.tm*, %struct.tm** %4
%22 = load i32, i32* %6
%23 = call i32 @writertctm(%struct.tm* %21, i32 %22)
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@O_WRONLY = global i32 0
@.str = [9 x i8] c"open %s:\00"
@.str.1 = [35 x i8] c"warning: assuming UTC for systohc\0A\00"
define void @systohc(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @eprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %1
%10 = bitcast i32* %2 to %struct.timeval*
%11 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%12 = call %struct.tm* @gmtime(i32* %2)
%13 = call i32 @weprintf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @writertctm(%struct.tm* %12, i32 %5)
%15 = call i32 @close(i32 %5)
ret void
}