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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ settimeofday(struct timeval *, struct timezone *);
void set_wall_clock(struct timespec ts, struct timezone tz) {
  struct timeval tv;
  {
    (&tv)->tv_sec = (&ts)->tv_sec;
    (&tv)->tv_usec = (&ts)->tv_nsec / 1000;
  };
  if (0 != settimeofday(&tv, &tz)) {
    perror("settimeofday");
    exit(2);
  }
}


x86 assembly (clang, -O0):
<set_wall_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <settimeofday@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1184 <set_wall_clock+0x54>
lea    0xe8b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_wall_clock>:
sub    $0x18,%rsp
movslq %edi,%rax
shr    $0x20,%rdi
mov    %esi,0x8(%rsp)
mov    %edi,0x14(%rsp)
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <settimeofday@plt>
test   %rax,%rax
jne    1174 <set_wall_clock+0x44>
add    $0x18,%rsp
ret
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"settimeofday\00"
define void @set_wall_clock(i64 %0, i32 %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timezone
%5 = alloca %struct.timeval
%6 = bitcast %struct.timespec* %3 to i64*
store i64 %0, i64* %6
%7 = getelementptr inbounds %struct.timezone, %struct.timezone* %4, i32 0, i32 0
store i32 %1, i32* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 %13, i32* %14
%15 = call i64 @settimeofday(%struct.timeval* %5, %struct.timezone* %4)
%16 = icmp ne i64 0, %15
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.timezone = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"settimeofday\00"
define void @set_wall_clock(i64 %0, i32 %1) {
%3 = alloca %struct.timezone
%4 = alloca %struct.timeval
%5 = trunc i64 %0 to i32
%6 = lshr i64 %0, 32
%7 = trunc i64 %6 to i32
%8 = getelementptr inbounds %struct.timezone, %struct.timezone* %3, i64 0, i32 0
store i32 %1, i32* %8
%9 = bitcast %struct.timeval* %4 to i8*
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i32 %7, i32* %10
%11 = sdiv i32 %5, 1000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %11, i32* %12
%13 = call i64 @settimeofday(%struct.timeval* %4, %struct.timezone* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %2
ret void
}