#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 timespec {
  int /*<<< orphan*/ tv_sec;
};
typedef int clockid_t;

/* Variables and functions */
#define CLOCK_MONOTONIC 129
#define CLOCK_REALTIME 128
int /*<<< orphan*/ EINVAL;
int EPERM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ stime(int /*<<< orphan*/ *);
int clock_settime(clockid_t clk_id, const struct timespec *tp) {
  switch (clk_id) {
  case CLOCK_REALTIME:
    stime(&tp->tv_sec);
    return 0;
  case CLOCK_MONOTONIC:
    return -EPERM;
  default:
    errno = EINVAL;
  }
  return -1;
}


x86 assembly (clang, -O0):
<clock_settime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     1148 <clock_settime+0x38>
jmp    1135 <clock_settime+0x25>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     115d <clock_settime+0x4d>
jmp    1170 <clock_settime+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <stime@plt>
movl   $0x0,-0x4(%rbp)
jmp    1189 <clock_settime+0x79>
xor    %eax,%eax
mov    0x2e62(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <clock_settime+0x79>
mov    0x2e61(%rip),%rax
mov    (%rax),%ecx
mov    0x2e60(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_settime>:
push   %rax
cmp    $0x81,%edi
je     112d <clock_settime+0x1d>
cmp    $0x80,%edi
jne    113a <clock_settime+0x2a>
mov    %rsi,%rdi
call   1030 <stime@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e94(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    0x2e96(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@EPERM = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
define i32 @clock_settime(i32 %0, %struct.timespec* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec*
store i32 %0, i32* %4
store %struct.timespec* %1, %struct.timespec** %5
%6 = load i32, i32* %4
switch i32 %6, label %14 [
i32 128, label %7
i32 129, label %11
]
7: ; preds = %2
%8 = load %struct.timespec*, %struct.timespec** %5
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%10 = call i32 @stime(i32* %9)
store i32 0, i32* %3
br label %17
11: ; preds = %2
%12 = load i32, i32* @EPERM
%13 = sub nsw i32 0, %12
store i32 %13, i32* %3
br label %17
14: ; preds = %2
%15 = load i32, i32* @EINVAL
store i32 %15, i32* @errno
br label %16
16: ; preds = %14
store i32 -1, i32* %3
br label %17
17: ; preds = %16, %11, %7
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@EPERM = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
define i32 @clock_settime(i32 %0, %struct.timespec* %1) {
switch i32 %0, label %9 [
i32 128, label %3
i32 129, label %6
]
3: ; preds = %2
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%5 = tail call i32 @stime(i32* %4)
br label %11
6: ; preds = %2
%7 = load i32, i32* @EPERM
%8 = sub nsw i32 0, %7
br label %11
9: ; preds = %2
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
br label %11
11: ; preds = %9, %6, %3
%12 = phi i32 [ -1, %9 ], [ %8, %6 ], [ 0, %3 ]
ret i32 %12
}