#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 dummy;
};
typedef int /*<<< orphan*/ pthread_condattr_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int clock_getres(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *);
int pthread_condattr_init(int /*<<< orphan*/ *);
int pthread_condattr_setclock(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  pthread_condattr_t condattr;
  struct timespec ts;
  int rc;
  rc = clock_getres(CLOCK_MONOTONIC, &ts);
  if (rc != 0) {
    printf("UNSUPPORTED: CLOCK_MONOTONIC is unsupported\n");
    return 4;
  }
  if ((rc = pthread_condattr_init(&condattr)) != 0) {
    fprintf(stderr, "Error at pthread_condattr_init(), rc=%d\n", rc);
    printf("Test FAILED\n");
    return 1;
  }
  rc = pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
  if (rc != 0) {
    printf("Test FAILED: Could not set clock to CLOCK_MONOTONIC\n");
    return 1;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <clock_getres@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1196 <main+0x46>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1225 <main+0xd5>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_condattr_init@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11db <main+0x8b>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1225 <main+0xd5>
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1040 <pthread_condattr_setclock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1212 <main+0xc2>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1225 <main+0xd5>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <clock_getres@plt>
test   %eax,%eax
je     117a <main+0x2a>
mov    $0x4,%ebx
lea    0xefd(%rip),%rdi
jmp    11d2 <main+0x82>
lea    0x4(%rsp),%rdi
call   1070 <pthread_condattr_init@plt>
test   %eax,%eax
je     11ad <main+0x5d>
mov    0x2e49(%rip),%rcx
mov    (%rcx),%edi
lea    0xe68(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    $0x1,%ebx
lea    0xebe(%rip),%rdi
jmp    11d2 <main+0x82>
mov    (%rbx),%esi
lea    0x4(%rsp),%rdi
call   1040 <pthread_condattr_setclock@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
lea    0xe62(%rip),%rax
lea    0xe67(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [45 x i8] c"UNSUPPORTED: CLOCK_MONOTONIC is unsupported\0A\00"
@stderr = global i32 0
@.str.1 = [41 x i8] c"Error at pthread_condattr_init(), rc=%d\0A\00"
@.str.2 = [13 x i8] c"Test FAILED\0A\00"
@.str.3 = [53 x i8] c"Test FAILED: Could not set clock to CLOCK_MONOTONIC\0A\00"
@.str.4 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i32 @clock_getres(i32 %5, %struct.timespec* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 4, i32* %1
br label %28
11: ; preds = %0
%12 = call i32 @pthread_condattr_init(i32* %2)
store i32 %12, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32, i32* %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %28
19: ; preds = %11
%20 = load i32, i32* @CLOCK_MONOTONIC
%21 = call i32 @pthread_condattr_setclock(i32* %2, i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %28
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %28
28: ; preds = %26, %24, %14, %9
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Error at pthread_condattr_init(), rc=%d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.5 = [52 x i8] c"Test FAILED: Could not set clock to CLOCK_MONOTONIC\00"
@str.6 = [12 x i8] c"Test FAILED\00"
@str.7 = [44 x i8] c"UNSUPPORTED: CLOCK_MONOTONIC is unsupported\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i32 @clock_getres(i32 %5, %struct.timespec* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %0
%9 = call i32 @pthread_condattr_init(i32* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %21
14: ; preds = %8
%15 = load i32, i32* @CLOCK_MONOTONIC
%16 = call i32 @pthread_condattr_setclock(i32* %1, i32 %15)
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @str.5, i64 0, i64 0)
%19 = xor i1 %17, true
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %14, %0, %11
%22 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0), %11 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.7, i64 0, i64 0), %0 ], [ %18, %14 ]
%23 = phi i32 [ 1, %11 ], [ 4, %0 ], [ %20, %14 ]
%24 = call i32 @puts(i8* dereferenceable(1) %22)
ret i32 %23
}