#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 sched_param {
  int sched_priority;
};
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int EINVAL;
int ENOTSUP;
int SCHED_RR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setschedparam(int /*<<< orphan*/ *, struct sched_param *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int);
int sched_get_priority_max(int);
int main(void) {
  pthread_attr_t attr;
  int rc = 0;
  int policy = SCHED_RR;
  struct sched_param param;
  int priority;
  rc = pthread_attr_init(&attr);
  if (rc != 0) {
    perror("unexpected error: "
           "pthread_attr_setschedparam"
           " "
           "3-2"
           ": "
           "pthread_attr_init");
    exit(2);
  }
  rc = pthread_attr_setschedpolicy(&attr, policy);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_setschedparam"
           " "
           "3-2"
           ": "
           "pthread_attr_setschedpolicy");
    exit(1);
  }
  priority = sched_get_priority_max(policy);
  if (priority == -1) {
    perror("unexpected error: "
           "pthread_attr_setschedparam"
           " "
           "3-2"
           ": "
           "sched_priority_get_max");
    exit(1);
  }
  param.sched_priority = priority + 1000;
  rc = pthread_attr_setschedparam(&attr, &param);
  if ((rc != EINVAL) && (rc != ENOTSUP)) {
    printf("unexpected error: "
           "pthread_attr_setschedparam"
           " "
           "3-2"
           ": "
           "pthread_attr_setschedparam did not fail\n");
    exit(1);
  }
  printf("Test PASSED\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11be <main+0x4e>
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11ed <main+0x7d>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%edi
call   1090 <sched_get_priority_max@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1218 <main+0xa8>
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x3e8,%eax
mov    %eax,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <pthread_attr_setschedparam@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2d9b(%rip),%rcx
cmp    (%rcx),%eax
je     126d <main+0xfd>
mov    -0xc(%rbp),%eax
mov    0x2d99(%rip),%rcx
cmp    (%rcx),%eax
je     126d <main+0xfd>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e3c(%rip),%rax
mov    (%rax),%ebx
lea    0x4(%rsp),%rdi
call   1060 <pthread_attr_init@plt>
test   %eax,%eax
jne    11ce <main+0x4e>
lea    0x4(%rsp),%rdi
mov    %ebx,%esi
call   1050 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
jne    11e4 <main+0x64>
mov    %ebx,%edi
call   10a0 <sched_get_priority_max@plt>
cmp    $0xffffffff,%eax
jne    11fa <main+0x7a>
lea    0xed3(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe2b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x3e8,%eax
mov    %eax,0x8(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%eax
je     123e <main+0xbe>
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%eax
je     123e <main+0xbe>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [68 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: pthread_attr_init\00"
@.str.1 = [78 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: pthread_attr_setschedpolicy\00"
@.str.2 = [73 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: sched_priority_get_max\00"
@EINVAL = global i32 0
@ENOTSUP = global i32 0
@.str.3 = [91 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: pthread_attr_setschedparam did not fail\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
%5 = alloca %struct.sched_param
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%7 = load i32, i32* @SCHED_RR
store i32 %7, i32* %4
%8 = call i32 @pthread_attr_init(i32* %2)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %0
%15 = load i32, i32* %4
%16 = call i32 @pthread_attr_setschedpolicy(i32* %2, i32 %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* %4
%24 = call i32 @sched_get_priority_max(i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1000
%33 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i32 0, i32 0
store i32 %32, i32* %33
%34 = call i32 @pthread_attr_setschedparam(i32* %2, %struct.sched_param* %5)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = load i32, i32* @EINVAL
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %30
%39 = load i32, i32* %3
%40 = load i32, i32* @ENOTSUP
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %38, %30
%46 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [68 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: pthread_attr_init\00"
@.str.1 = [78 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: pthread_attr_setschedpolicy\00"
@.str.2 = [73 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: sched_priority_get_max\00"
@EINVAL = global i32 0
@ENOTSUP = global i32 0
@str = [12 x i8] c"Test PASSED\00"
@str.5 = [90 x i8] c"unexpected error: pthread_attr_setschedparam 3-2: pthread_attr_setschedparam did not fail\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = bitcast i32* %1 to i8*
%4 = load i32, i32* @SCHED_RR
%5 = bitcast %struct.sched_param* %2 to i8*
%6 = call i32 @pthread_attr_init(i32* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 2)
unreachable
11: ; preds = %0
%12 = call i32 @pthread_attr_setschedpolicy(i32* %1, i32 %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = call i32 @sched_get_priority_max(i32 %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = add nsw i32 %18, 1000
%25 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %24, i32* %25
%26 = call i32 @pthread_attr_setschedparam(i32* %1, %struct.sched_param* %2)
%27 = load i32, i32* @EINVAL
%28 = icmp eq i32 %26, %27
%29 = load i32, i32* @ENOTSUP
%30 = icmp eq i32 %26, %29
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %35, label %32
32: ; preds = %23
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str.5, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %23
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
}