#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;
typedef int clockid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int CLOCK_MONOTONIC;
int CLOCK_MONOTONIC_COARSE;
int CLOCK_MONOTONIC_RAW;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ksft_test_result_error(char *);
int open(char *, int /*<<< orphan*/);
int snprintf(char *, int, char *, int, int /*<<< orphan*/);
int write(int, char *, int);
int _settime(clockid_t clk_id, time_t offset) {
  int fd, len;
  char buf[4096];
  if (clk_id == CLOCK_MONOTONIC_COARSE || clk_id == CLOCK_MONOTONIC_RAW)
    clk_id = CLOCK_MONOTONIC;
  len = snprintf(buf, sizeof(buf), "%d %ld 0", clk_id, offset);
  fd = open("/proc/self/timens_offsets", O_WRONLY);
  if (fd < 0)
    return ({
      ksft_test_result_error("/proc/self/timens_offsets"
                             ": %m"
                             "\n");
      -1;
    });
  if (write(fd, buf, len) != len)
    return ({
      ksft_test_result_error("/proc/self/timens_offsets"
                             ": %m"
                             "\n");
      -1;
    });
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<_settime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%eax
je     1185 <_settime+0x35>
mov    -0x8(%rbp),%eax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
jne    1191 <_settime+0x41>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    $0x1000,%esi
lea    0xe55(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11f9 <_settime+0xa9>
lea    0xe47(%rip),%rdi
call   1060 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x1024(%rbp)
ff ff ff
mov    -0x1024(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <_settime+0xf7>
mov    -0x10(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
je     1238 <_settime+0xe8>
lea    0xe08(%rip),%rdi
call   1060 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x1028(%rbp)
ff ff ff
mov    -0x1028(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <_settime+0xf7>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_settime>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%r8d
mov    0x2e7d(%rip),%rax
mov    0x2e6e(%rip),%rcx
cmp    %edi,(%rcx)
mov    0x2e75(%rip),%rcx
mov    (%rcx),%edx
mov    %edi,%ecx
cmove  %edx,%ecx
cmp    %edi,(%rax)
cmove  %edx,%ecx
lea    0xe7a(%rip),%rdx
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1040 <snprintf@plt>
mov    %eax,%ebx
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11cb <_settime+0x7b>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
jne    11cb <_settime+0x7b>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11dc <_settime+0x8c>
lea    0xe51(%rip),%rdi
call   1060 <ksft_test_result_error@plt>
mov    $0xffffffff,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@CLOCK_MONOTONIC_COARSE = global i32 0
@CLOCK_MONOTONIC_RAW = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str = [9 x i8] c"%d %ld 0\00"
@.str.1 = [26 x i8] c"/proc/self/timens_offsets\00"
@O_WRONLY = global i32 0
@.str.2 = [31 x i8] c"/proc/self/timens_offsets: %m\0A\00"
define i32 @_settime(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%11 = load i32, i32* %4
%12 = load i32, i32* @CLOCK_MONOTONIC_COARSE
%13 = icmp eq i32 %11, %12
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = load i32, i32* @CLOCK_MONOTONIC_RAW
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14, %2
%19 = load i32, i32* @CLOCK_MONOTONIC
store i32 %19, i32* %4
br label %20
20: ; preds = %18, %14
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @snprintf(i8* %21, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* @O_WRONLY
%26 = call i32 @open(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %9
%31 = load i32, i32* %9
store i32 %31, i32* %3
br label %45
32: ; preds = %20
%33 = load i32, i32* %6
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%35 = load i32, i32* %7
%36 = call i32 @write(i32 %33, i8* %34, i32 %35)
%37 = load i32, i32* %7
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %10
%41 = load i32, i32* %10
store i32 %41, i32* %3
br label %45
42: ; preds = %32
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %42, %39, %29
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@CLOCK_MONOTONIC_COARSE = global i32 0
@CLOCK_MONOTONIC_RAW = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str = [9 x i8] c"%d %ld 0\00"
@.str.1 = [26 x i8] c"/proc/self/timens_offsets\00"
@O_WRONLY = global i32 0
@.str.2 = [31 x i8] c"/proc/self/timens_offsets: %m\0A\00"
define i32 @_settime(i32 %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @CLOCK_MONOTONIC_COARSE
%6 = icmp eq i32 %5, %0
%7 = load i32, i32* @CLOCK_MONOTONIC_RAW
%8 = icmp eq i32 %7, %0
%9 = select i1 %6, i1 true, i1 %8
%10 = load i32, i32* @CLOCK_MONOTONIC
%11 = select i1 %9, i32 %10, i32 %0
%12 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %1)
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %25
18: ; preds = %2
%19 = call i32 @write(i32 %14, i8* %4, i32 %12)
%20 = icmp eq i32 %19, %12
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %18
%24 = call i32 @close(i32 %14)
br label %25
25: ; preds = %23, %21, %16
%26 = phi i32 [ -1, %16 ], [ -1, %21 ], [ 0, %23 ]
ret i32 %26
}