#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 tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
scalar_t__ EINVAL;
int clock_settime(int, struct timespec *);
scalar_t__ errno;
scalar_t__ geteuid();
int /*<<< orphan*/ printf(char *);
int main(void) {
  struct timespec tpset;
  tpset.tv_sec = 1037128358;
  tpset.tv_nsec = 0;
  if (geteuid() != 0) {
    printf("This test must be run as superuser\n");
    return 2;
  }
  if (clock_settime(9999, &tpset) == -1) {
    if (EINVAL == errno) {
      printf("Test PASSED\n");
      return 0;
    } else {
      printf("errno != EINVAL\n");
      return 1;
    }
  } else {
    printf("clock_settime() did not return -1\n");
    return 2;
  }
  printf("This test should not be executed.\n");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3dd152a6,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
cmp    $0x0,%rax
je     1177 <main+0x47>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11eb <main+0xbb>
mov    $0x270f,%edi
lea    -0x18(%rbp),%rsi
call   1050 <clock_settime@plt>
cmp    $0xffffffff,%eax
jne    11d8 <main+0xa8>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <main+0x90>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11eb <main+0xbb>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11eb <main+0xbb>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movl   $0x3dd152a6,0x8(%rsp)
3d
movq   $0x0,0x10(%rsp)
xor    %eax,%eax
call   1040 <geteuid@plt>
test   %rax,%rax
je     115a <main+0x2a>
lea    0xee6(%rip),%rdi
jmp    1175 <main+0x45>
lea    0x8(%rsp),%rsi
mov    $0x270f,%edi
call   1050 <clock_settime@plt>
cmp    $0xffffffff,%eax
je     1184 <main+0x54>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
add    $0x18,%rsp
ret
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
jne    11ad <main+0x7d>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [36 x i8] c"This test must be run as superuser\0A\00"
@EINVAL = global i64 0
@errno = global i64 0
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [17 x i8] c"errno != EINVAL\0A\00"
@.str.3 = [35 x i8] c"clock_settime() did not return -1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
store i32 0, i32* %1
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 1037128358, i32* %3
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %4
%5 = call i64 (...) @geteuid()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %22
9: ; preds = %0
%10 = call i32 @clock_settime(i32 9999, %struct.timespec* %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i64, i64* @EINVAL
%14 = load i64, i64* @errno
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %22
18: ; preds = %12
%19 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %22
20: ; preds = %9
%21 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %22
22: ; preds = %20, %18, %16, %7
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@EINVAL = global i64 0
@errno = global i64 0
@str = [34 x i8] c"clock_settime() did not return -1\00"
@str.4 = [16 x i8] c"errno != EINVAL\00"
@str.5 = [12 x i8] c"Test PASSED\00"
@str.6 = [35 x i8] c"This test must be run as superuser\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 1037128358, i32* %3
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i64 0, i64* %4
%5 = tail call i64 (...) @geteuid()
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
br label %22
9: ; preds = %0
%10 = call i32 @clock_settime(i32 9999, %struct.timespec* %1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i64, i64* @EINVAL
%14 = load i64, i64* @errno
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
br label %22
18: ; preds = %12
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
br label %22
20: ; preds = %9
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %20, %18, %16, %7
%23 = phi i32 [ 2, %7 ], [ 0, %16 ], [ 1, %18 ], [ 2, %20 ]
ret i32 %23
}