#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 /*<<< orphan*/ SCHED_FIFO;
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_setschedparam(int /*<<< orphan*/ *, struct sched_param *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sched_get_priority_max(int /*<<< orphan*/);
int /*<<< orphan*/ verify_param(int /*<<< orphan*/ *, int);
int main(void) {
  int rc = 0;
  pthread_attr_t attr;
  struct sched_param param;
  int priority;
  rc = pthread_attr_init(&attr);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "pthread_attr_init\n");
    exit(2);
  }
  rc = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "pthread_attr_setschedpolicy\n");
    exit(2);
  }
  priority = sched_get_priority_max(SCHED_FIFO);
  if (priority == -1) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "sched_get_priority_max\n");
    exit(2);
  }
  param.sched_priority = priority;
  rc = pthread_attr_setschedparam(&attr, &param);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "pthread_attr_setschedparam\n");
    exit(2);
  }
  verify_param(&attr, priority);
  rc = pthread_attr_setschedpolicy(&attr, SCHED_RR);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "pthread_attr_setschedpolicy\n");
    exit(2);
  }
  priority = sched_get_priority_max(SCHED_RR);
  if (priority == -1) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "sched_get_priority_max\n");
    exit(2);
  }
  param.sched_priority = priority;
  rc = pthread_attr_setschedparam(&attr, &param);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "pthread_attr_setschedparam\n");
    exit(2);
  }
  verify_param(&attr, priority);
  rc = pthread_attr_destroy(&attr);
  if (rc != 0) {
    printf("unexpected error: "
           "pthread_attr_getschedparam"
           " "
           "1-1"
           ": "
           "pthread_attr_destroy\n");
    exit(2);
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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     11c2 <main+0x42>
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11f7 <main+0x77>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1228 <main+0xa8>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     125e <main+0xde>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1060 <verify_param@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     129f <main+0x11f>
lea    0xdb5(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   10a0 <sched_get_priority_max@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12d0 <main+0x150>
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1306 <main+0x186>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1060 <verify_param@plt>
lea    -0xc(%rbp),%rdi
call   1070 <pthread_attr_destroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     133e <main+0x1be>
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xc(%rsp),%rdi
call   1050 <pthread_attr_init@plt>
test   %eax,%eax
jne    1276 <main+0xf6>
mov    0x2e48(%rip),%rbx
mov    (%rbx),%esi
lea    0xc(%rsp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
jne    125b <main+0xdb>
mov    (%rbx),%edi
call   10a0 <sched_get_priority_max@plt>
cmp    $0xffffffff,%eax
je     1264 <main+0xe4>
mov    %eax,%ebx
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
test   %eax,%eax
jne    126d <main+0xed>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <verify_param@plt>
mov    0x2dd9(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
jne    125b <main+0xdb>
mov    (%rbx),%edi
call   10a0 <sched_get_priority_max@plt>
cmp    $0xffffffff,%eax
je     1264 <main+0xe4>
mov    %eax,%ebx
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
test   %eax,%eax
jne    126d <main+0xed>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <verify_param@plt>
mov    %r14,%rdi
call   1070 <pthread_attr_destroy@plt>
test   %eax,%eax
jne    127f <main+0xff>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe87(%rip),%rdi
jmp    1286 <main+0x106>
lea    0xe35(%rip),%rdi
jmp    1286 <main+0x106>
lea    0xddf(%rip),%rdi
jmp    1286 <main+0x106>
lea    0xeba(%rip),%rdi
jmp    1286 <main+0x106>
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [69 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_init\0A\00"
@SCHED_FIFO = global i32 0
@.str.1 = [79 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_setschedpolicy\0A\00"
@.str.2 = [74 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: sched_get_priority_max\0A\00"
@.str.3 = [78 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_setschedparam\0A\00"
@SCHED_RR = global i32 0
@.str.4 = [72 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_destroy\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 %struct.sched_param
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32 @pthread_attr_init(i32* %3)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 2)
unreachable
12: ; preds = %0
%13 = load i32, i32* @SCHED_FIFO
%14 = call i32 @pthread_attr_setschedpolicy(i32* %3, i32 %13)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %12
%21 = load i32, i32* @SCHED_FIFO
%22 = call i32 @sched_get_priority_max(i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %20
%29 = load i32, i32* %5
%30 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %29, i32* %30
%31 = call i32 @pthread_attr_setschedparam(i32* %3, %struct.sched_param* %4)
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 2)
unreachable
37: ; preds = %28
%38 = load i32, i32* %5
%39 = call i32 @verify_param(i32* %3, i32 %38)
%40 = load i32, i32* @SCHED_RR
%41 = call i32 @pthread_attr_setschedpolicy(i32* %3, i32 %40)
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 = %37
%45 = call i32 @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @exit(i32 2)
unreachable
47: ; preds = %37
%48 = load i32, i32* @SCHED_RR
%49 = call i32 @sched_get_priority_max(i32 %48)
store i32 %49, i32* %5
%50 = load i32, i32* %5
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 @exit(i32 2)
unreachable
55: ; preds = %47
%56 = load i32, i32* %5
%57 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %56, i32* %57
%58 = call i32 @pthread_attr_setschedparam(i32* %3, %struct.sched_param* %4)
store i32 %58, i32* %2
%59 = load i32, i32* %2
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %55
%62 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @exit(i32 2)
unreachable
64: ; preds = %55
%65 = load i32, i32* %5
%66 = call i32 @verify_param(i32* %3, i32 %65)
%67 = call i32 @pthread_attr_destroy(i32* %3)
store i32 %67, i32* %2
%68 = load i32, i32* %2
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 2)
unreachable
73: ; preds = %64
%74 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@SCHED_RR = global i32 0
@str = [12 x i8] c"Test PASSED\00"
@str.6 = [71 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_destroy\00"
@str.10 = [77 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_setschedparam\00"
@str.11 = [73 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: sched_get_priority_max\00"
@str.12 = [78 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_setschedpolicy\00"
@str.13 = [68 x i8] c"unexpected error: pthread_attr_getschedparam 1-1: pthread_attr_init\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.sched_param* %2 to i8*
%5 = call i32 @pthread_attr_init(i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.13, 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* %1, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.12, i64 0, i64 0))
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %10
%18 = load i32, i32* @SCHED_FIFO
%19 = call i32 @sched_get_priority_max(i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.11, i64 0, i64 0))
%23 = call i32 @exit(i32 2)
unreachable
24: ; preds = %17
%25 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %19, i32* %25
%26 = call i32 @pthread_attr_setschedparam(i32* %1, %struct.sched_param* %2)
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.10, i64 0, i64 0))
%30 = call i32 @exit(i32 2)
unreachable
31: ; preds = %24
%32 = call i32 @verify_param(i32* %1, i32 %19)
%33 = load i32, i32* @SCHED_RR
%34 = call i32 @pthread_attr_setschedpolicy(i32* %1, i32 %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.12, i64 0, i64 0))
%38 = call i32 @exit(i32 2)
unreachable
39: ; preds = %31
%40 = load i32, i32* @SCHED_RR
%41 = call i32 @sched_get_priority_max(i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.11, i64 0, i64 0))
%45 = call i32 @exit(i32 2)
unreachable
46: ; preds = %39
store i32 %41, i32* %25
%47 = call i32 @pthread_attr_setschedparam(i32* %1, %struct.sched_param* %2)
%48 = icmp eq i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %46
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.10, i64 0, i64 0))
%51 = call i32 @exit(i32 2)
unreachable
52: ; preds = %46
%53 = call i32 @verify_param(i32* %1, i32 %41)
%54 = call i32 @pthread_attr_destroy(i32* %1)
%55 = icmp eq i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %52
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.6, i64 0, i64 0))
%58 = call i32 @exit(i32 2)
unreachable
59: ; preds = %52
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret i32 0
}