#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 /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int pthread_condattr_getclock(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int pthread_condattr_init(int /*<<< orphan*/ *);
int pthread_condattr_setclock(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  pthread_condattr_t condattr;
  clockid_t clockid;
  int rc;
  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_REALTIME);
  if (rc != 0) {
    perror("Error: Could not set clock to CLOCK_REALTIME\n");
    return 2;
  }
  rc = pthread_condattr_getclock(&condattr, &clockid);
  if (rc != 0) {
    printf("Test FAILED: Could not get the clock attribute\n");
    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)
lea    -0x8(%rbp),%rdi
call   1070 <pthread_condattr_init@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     11b4 <main+0x54>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1230 <main+0xd0>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1050 <pthread_condattr_setclock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11eb <main+0x8b>
lea    0xe5c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1230 <main+0xd0>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <pthread_condattr_getclock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     121d <main+0xbd>
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1230 <main+0xd0>
lea    0xe70(%rip),%rdi
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    %rsp,%rdi
call   1070 <pthread_condattr_init@plt>
test   %eax,%eax
je     118d <main+0x2d>
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%edi
lea    0xe83(%rip),%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
lea    0xf07(%rip),%rdi
jmp    11ba <main+0x5a>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1050 <pthread_condattr_setclock@plt>
test   %eax,%eax
jne    11d6 <main+0x76>
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   1030 <pthread_condattr_getclock@plt>
test   %eax,%eax
je     11c6 <main+0x66>
lea    0xea9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Error at pthread_condattr_init(), rc=%d\0A\00"
@.str.1 = [13 x i8] c"Test FAILED\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [46 x i8] c"Error: Could not set clock to CLOCK_REALTIME\0A\00"
@.str.3 = [48 x i8] c"Test FAILED: Could not get the clock attribute\0A\00"
@.str.4 = [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 = call i32 @pthread_condattr_init(i32* %2)
store i32 %5, i32* %4
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* %4
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %27
12: ; preds = %0
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i32 @pthread_condattr_setclock(i32* %2, i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %27
19: ; preds = %12
%20 = call i32 @pthread_condattr_getclock(i32* %2, i32* %3)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %27
25: ; preds = %19
%26 = 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 %27
27: ; preds = %25, %23, %17, %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Error at pthread_condattr_init(), rc=%d\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [46 x i8] c"Error: Could not set clock to CLOCK_REALTIME\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.5 = [47 x i8] c"Test FAILED: Could not get the clock attribute\00"
@str.6 = [12 x i8] c"Test FAILED\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @pthread_condattr_init(i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %24
11: ; preds = %0
%12 = load i32, i32* @CLOCK_REALTIME
%13 = call i32 @pthread_condattr_setclock(i32* %1, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %24
17: ; preds = %11
%18 = call i32 @pthread_condattr_getclock(i32* %1, i32* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.5, i64 0, i64 0))
br label %24
22: ; preds = %17
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %15, %7
%25 = phi i32 [ 1, %7 ], [ 2, %15 ], [ 1, %20 ], [ 0, %22 ]
ret i32 %25
}