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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ _SC_CPUTIME;
scalar_t__ clock_getres(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *);
int sysconf(int /*<<< orphan*/);
int main(void) {
  struct timespec res;
  if (sysconf(_SC_CPUTIME) == -1) {
    printf("_POSIX_CPUTIME not supported\n");
    return 4;
  }
  res.tv_sec = 100000;
  res.tv_nsec = 100000;
  if (clock_getres(CLOCK_PROCESS_CPUTIME_ID, &res) == 0) {
    if (res.tv_sec != 100000) {
      printf("Test PASSED\n");
      return 0;
    } else {
      printf("clock_getres() success, but res not filled\n");
    }
  } else {
    printf("clock_getres() failed\n");
  }
  printf("Test FAILED\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
cmp    $0xffffffff,%eax
jne    116e <main+0x3e>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    11ed <main+0xbd>
movl   $0x186a0,-0x10(%rbp)
movl   $0x186a0,-0xc(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <clock_getres@plt>
cmp    $0x0,%rax
jne    11ce <main+0x9e>
cmpl   $0x186a0,-0x10(%rbp)
je     11bd <main+0x8d>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ed <main+0xbd>
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
jmp    11da <main+0xaa>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
cmp    $0xffffffff,%eax
je     1171 <main+0x41>
movabs $0x186a0000186a0,%rax
mov    %rax,(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <clock_getres@plt>
test   %rax,%rax
je     1184 <main+0x54>
lea    0xe91(%rip),%rdi
jmp    1194 <main+0x64>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x4,%eax
pop    %rcx
ret
cmpl   $0x186a0,(%rsp)
jne    11ac <main+0x7c>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@_SC_CPUTIME = global i32 0
@.str = [30 x i8] c"_POSIX_CPUTIME not supported\0A\00"
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [44 x i8] c"clock_getres() success, but res not filled\0A\00"
@.str.3 = [23 x i8] c"clock_getres() failed\0A\00"
@.str.4 = [13 x i8] c"Test FAILED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
store i32 0, i32* %1
%3 = load i32, i32* @_SC_CPUTIME
%4 = call i32 @sysconf(i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 4, i32* %1
br label %27
8: ; preds = %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 100000, i32* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 100000, i32* %10
%11 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%12 = call i64 @clock_getres(i32 %11, %struct.timespec* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %8
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%16 = load i32, i32* %15
%17 = icmp ne i32 %16, 100000
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = 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 %27
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20
br label %25
23: ; preds = %8
%24 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %22
%26 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %27
27: ; preds = %25, %18, %6
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@_SC_CPUTIME = global i32 0
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@str = [22 x i8] c"clock_getres() failed\00"
@str.5 = [12 x i8] c"Test FAILED\00"
@str.6 = [43 x i8] c"clock_getres() success, but res not filled\00"
@str.7 = [12 x i8] c"Test PASSED\00"
@str.8 = [29 x i8] c"_POSIX_CPUTIME not supported\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @_SC_CPUTIME
%4 = tail call i32 @sysconf(i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.8, i64 0, i64 0))
br label %23
8: ; preds = %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 100000, i32* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 100000, i32* %10
%11 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%12 = call i64 @clock_getres(i32 %11, %struct.timespec* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* %9
%16 = icmp eq i32 %15, 100000
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %23
19: ; preds = %8, %14
%20 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @str.6, i64 0, i64 0), %14 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0), %8 ]
%21 = call i32 @puts(i8* dereferenceable(1) %20)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
br label %23
23: ; preds = %19, %17, %6
%24 = phi i32 [ 4, %6 ], [ 0, %17 ], [ 1, %19 ]
ret i32 %24
}