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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int __settimeofday(struct timeval *, struct timezone *);
int stime(const time_t *when) {
  struct timeval tv;
  if (when == NULL) {
    __set_errno(EINVAL);
    return -1;
  }
  tv.tv_sec = *when;
  tv.tv_usec = 0;
  return __settimeofday(&tv, (struct timezone *)0);
}


x86 assembly (clang, -O0):
<stime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1151 <stime+0x31>
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1172 <stime+0x52>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <__settimeofday@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stime>:
sub    $0x18,%rsp
test   %rdi,%rdi
je     1149 <stime+0x29>
mov    (%rdi),%eax
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <__settimeofday@plt>
add    $0x18,%rsp
ret
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.timezone = type { i32 }
@EINVAL = global i32 0
define i32 @stime(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.timeval
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @EINVAL
%9 = call i32 @__set_errno(i32 %8)
store i32 -1, i32* %2
br label %16
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i64 0, i64* %14
%15 = call i32 @__settimeofday(%struct.timeval* %4, %struct.timezone* null)
store i32 %15, i32* %2
br label %16
16: ; preds = %10, %7
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.timezone = type { i32 }
@EINVAL = global i32 0
define i32 @stime(i32* %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = icmp eq i32* %0, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @EINVAL
%7 = tail call i32 @__set_errno(i32 %6)
br label %13
8: ; preds = %1
%9 = load i32, i32* %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i64 0, i64* %11
%12 = call i32 @__settimeofday(%struct.timeval* %2, %struct.timezone* null)
br label %13
13: ; preds = %8, %5
%14 = phi i32 [ -1, %5 ], [ %12, %8 ]
ret i32 %14
}