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

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ _SC_CPUTIME;
scalar_t__ clock_getcpuclockid(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ printf(char *, ...);
int pthread_condattr_init(int /*<<< orphan*/ *);
int pthread_condattr_setclock(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int sysconf(int /*<<< orphan*/);
int main(void) {
  pthread_condattr_t condattr;
  clockid_t clockid;
  int rc;
  if (sysconf(_SC_CPUTIME) == -1) {
    printf("_POSIX_CPUTIME 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;
  }
  if (clock_getcpuclockid(getpid(), &clockid) != 0) {
    printf("clock_getcpuclockid() failed\n");
    return 1;
  }
  rc = pthread_condattr_setclock(&condattr, clockid);
  if (rc != EINVAL) {
    printf("Test FAILED: Expected EINVAL when passing a cpu clock id, instead "
           "it returned: %d \n",
           rc);
    return 1;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x40>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1280 <main+0x110>
lea    -0x8(%rbp),%rdi
call   1080 <pthread_condattr_init@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     11f7 <main+0x87>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe44(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1280 <main+0x110>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
lea    -0xc(%rbp),%rsi
call   1060 <clock_getcpuclockid@plt>
cmp    $0x0,%rax
je     122d <main+0xbd>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1280 <main+0x110>
mov    -0xc(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1050 <pthread_condattr_setclock@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2d8a(%rip),%rcx
cmp    (%rcx),%eax
je     126b <main+0xfb>
mov    -0x10(%rbp),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1280 <main+0x110>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
cmp    $0xffffffff,%eax
je     11c2 <main+0x42>
lea    0x4(%rsp),%rdi
call   1090 <pthread_condattr_init@plt>
test   %eax,%eax
je     11d5 <main+0x55>
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%edi
lea    0xe4e(%rip),%rsi
mov    %eax,%edx
call   1080 <fprintf@plt>
lea    0xee6(%rip),%rdi
jmp    11f2 <main+0x72>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x4,%eax
pop    %rcx
ret
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <clock_getcpuclockid@plt>
test   %rax,%rax
je     11fe <main+0x7e>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    (%rsp),%esi
lea    0x4(%rsp),%rdi
call   1060 <pthread_condattr_setclock@plt>
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%eax
jne    1226 <main+0xa6>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xdfc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f7 <main+0x77>

LLVM IR (-O0):
@_SC_CPUTIME = global i32 0
@.str = [28 x i8] c"_POSIX_CPUTIME 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 = [30 x i8] c"clock_getcpuclockid() failed\0A\00"
@EINVAL = global i32 0
@.str.4 = [84 x i8] c"Test FAILED: Expected EINVAL when passing a cpu clock id, instead it returned: %d \0A\00"
@.str.5 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @_SC_CPUTIME
%6 = call i32 @sysconf(i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 4, i32* %1
br label %35
10: ; preds = %0
%11 = call i32 @pthread_condattr_init(i32* %2)
store i32 %11, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i32, i32* %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %35
18: ; preds = %10
%19 = call i32 (...) @getpid()
%20 = call i64 @clock_getcpuclockid(i32 %19, i32* %3)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %35
24: ; preds = %18
%25 = load i32, i32* %3
%26 = call i32 @pthread_condattr_setclock(i32* %2, i32 %25)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = load i32, i32* @EINVAL
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.4, i64 0, i64 0), i32 %31)
store i32 1, i32* %1
br label %35
33: ; preds = %24
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %35
35: ; preds = %33, %30, %22, %13, %8
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@_SC_CPUTIME = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Error at pthread_condattr_init(), rc=%d\0A\00"
@EINVAL = global i32 0
@.str.4 = [84 x i8] c"Test FAILED: Expected EINVAL when passing a cpu clock id, instead it returned: %d \0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.6 = [29 x i8] c"clock_getcpuclockid() failed\00"
@str.7 = [12 x i8] c"Test FAILED\00"
@str.8 = [27 x i8] c"_POSIX_CPUTIME unsupported\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @_SC_CPUTIME
%6 = tail call i32 @sysconf(i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0))
br label %32
10: ; preds = %0
%11 = call i32 @pthread_condattr_init(i32* %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %32
17: ; preds = %10
%18 = call i32 (...) @getpid()
%19 = call i64 @clock_getcpuclockid(i32 %18, i32* %2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
br label %32
23: ; preds = %17
%24 = load i32, i32* %2
%25 = call i32 @pthread_condattr_setclock(i32* %1, i32 %24)
%26 = load i32, i32* @EINVAL
%27 = icmp eq i32 %25, %26
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %32
30: ; preds = %23
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %28, %21, %13, %8
%33 = phi i32 [ 4, %8 ], [ 1, %13 ], [ 1, %21 ], [ 1, %28 ], [ 0, %30 ]
ret i32 %33
}