#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_attr_t;

/* Variables and functions */
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ SCHED_OTHER;
int /*<<< orphan*/ SCHED_RR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int pthread_attr_destroy(int /*<<< orphan*/ *);
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ verify_policy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(void) {
  int rc = 0;
  pthread_attr_t attr;
  rc = pthread_attr_init(&attr);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedpolicy"
           " "
           "2-1"
           ": "
           "pthread_attr_init\n");
    exit(2);
  }
  rc = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedpolicy"
           " "
           "2-1"
           ": "
           "pthread_attr_setschedpolicy\n");
    exit(2);
  }
  verify_policy(&attr, SCHED_FIFO);
  rc = pthread_attr_setschedpolicy(&attr, SCHED_RR);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedpolicy"
           " "
           "2-1"
           ": "
           "pthread_attr_setschedpolicy\n");
    exit(2);
  }
  verify_policy(&attr, SCHED_RR);
  rc = pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedpolicy"
           " "
           "2-1"
           ": "
           "pthread_attr_setschedpolicy\n");
    exit(2);
  }
  verify_policy(&attr, SCHED_OTHER);
  rc = pthread_attr_destroy(&attr);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedpolicy"
           " "
           "2-1"
           ": "
           "pthread_attr_destroy\n");
    exit(2);
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11a2 <main+0x42>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d7 <main+0x77>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1070 <verify_policy@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     121e <main+0xbe>
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1070 <verify_policy@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1265 <main+0x105>
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1070 <verify_policy@plt>
lea    -0xc(%rbp),%rdi
call   1060 <pthread_attr_destroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12a3 <main+0x143>
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rdi
call   1050 <pthread_attr_init@plt>
test   %eax,%eax
jne    1213 <main+0xb3>
mov    0x2e6b(%rip),%rbx
mov    (%rbx),%esi
lea    0x4(%rsp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
jne    120a <main+0xaa>
mov    (%rbx),%esi
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <verify_policy@plt>
mov    0x2e25(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
jne    120a <main+0xaa>
mov    (%r14),%esi
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <verify_policy@plt>
mov    0x2e0f(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
jne    120a <main+0xaa>
mov    (%r14),%esi
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <verify_policy@plt>
mov    %rbx,%rdi
call   1060 <pthread_attr_destroy@plt>
test   %eax,%eax
jne    121c <main+0xbc>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe43(%rip),%rdi
jmp    1223 <main+0xc3>
lea    0xe89(%rip),%rdi
jmp    1223 <main+0xc3>
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [70 x i8] c"unexpected error: pthread_attr_getschedpolicy 2-1: pthread_attr_init\0A\00"
@SCHED_FIFO = global i32 0
@.str.1 = [80 x i8] c"unexpected error: pthread_attr_getschedpolicy 2-1: pthread_attr_setschedpolicy\0A\00"
@SCHED_RR = global i32 0
@SCHED_OTHER = global i32 0
@.str.2 = [73 x i8] c"unexpected error: pthread_attr_getschedpolicy 2-1: pthread_attr_destroy\0A\00"
@.str.3 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 @pthread_attr_init(i32* %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 2)
unreachable
10: ; preds = %0
%11 = load i32, i32* @SCHED_FIFO
%12 = call i32 @pthread_attr_setschedpolicy(i32* %3, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %10
%19 = load i32, i32* @SCHED_FIFO
%20 = call i32 @verify_policy(i32* %3, i32 %19)
%21 = load i32, i32* @SCHED_RR
%22 = call i32 @pthread_attr_setschedpolicy(i32* %3, i32 %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %18
%29 = load i32, i32* @SCHED_RR
%30 = call i32 @verify_policy(i32* %3, i32 %29)
%31 = load i32, i32* @SCHED_OTHER
%32 = call i32 @pthread_attr_setschedpolicy(i32* %3, i32 %31)
store i32 %32, i32* %2
%33 = load i32, i32* %2
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = call i32 @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 2)
unreachable
38: ; preds = %28
%39 = load i32, i32* @SCHED_OTHER
%40 = call i32 @verify_policy(i32* %3, i32 %39)
%41 = call i32 @pthread_attr_destroy(i32* %3)
store i32 %41, i32* %2
%42 = load i32, i32* %2
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 2)
unreachable
47: ; preds = %38
%48 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@SCHED_FIFO = global i32 0
@SCHED_RR = global i32 0
@SCHED_OTHER = global i32 0
@str = [12 x i8] c"Test PASSED\00"
@str.4 = [72 x i8] c"unexpected error: pthread_attr_getschedpolicy 2-1: pthread_attr_destroy\00"
@str.7 = [79 x i8] c"unexpected error: pthread_attr_getschedpolicy 2-1: pthread_attr_setschedpolicy\00"
@str.8 = [69 x i8] c"unexpected error: pthread_attr_getschedpolicy 2-1: pthread_attr_init\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_attr_init(i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str.8, i64 0, i64 0))
%7 = call i32 @exit(i32 2)
unreachable
8: ; preds = %0
%9 = load i32, i32* @SCHED_FIFO
%10 = call i32 @pthread_attr_setschedpolicy(i32* %1, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str.7, i64 0, i64 0))
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %8
%16 = load i32, i32* @SCHED_FIFO
%17 = call i32 @verify_policy(i32* %1, i32 %16)
%18 = load i32, i32* @SCHED_RR
%19 = call i32 @pthread_attr_setschedpolicy(i32* %1, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str.7, i64 0, i64 0))
%23 = call i32 @exit(i32 2)
unreachable
24: ; preds = %15
%25 = load i32, i32* @SCHED_RR
%26 = call i32 @verify_policy(i32* %1, i32 %25)
%27 = load i32, i32* @SCHED_OTHER
%28 = call i32 @pthread_attr_setschedpolicy(i32* %1, i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %24
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str.7, i64 0, i64 0))
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %24
%34 = load i32, i32* @SCHED_OTHER
%35 = call i32 @verify_policy(i32* %1, i32 %34)
%36 = call i32 @pthread_attr_destroy(i32* %1)
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.4, i64 0, i64 0))
%40 = call i32 @exit(i32 2)
unreachable
41: ; preds = %33
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret i32 0
}