#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*/ assert(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_getschedparam(int /*<<< orphan*/, int *,
                                         struct sched_param *);
int /*<<< orphan*/ pthread_self();
int sched_get_priority_max(int);
int sched_get_priority_min(int);
void show_thread_priority(pthread_attr_t *attr, int policy) {
  int priority = sched_get_priority_max(policy);
  assert(priority != -1);
  printf("max_priority=%d\n", priority);
  priority = sched_get_priority_min(policy);
  assert(priority != -1);
  printf("min_priority=%d\n", priority);
  struct sched_param param;
  pthread_getschedparam(pthread_self(), &policy, &param);
  printf("Current thread's priority:%d\n", param.__sched_priority);
}


x86 assembly (clang, -O0):
<show_thread_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <sched_get_priority_max@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <sched_get_priority_min@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%esi
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
lea    -0xc(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <pthread_getschedparam@plt>
mov    -0x18(%rbp),%esi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_thread_priority>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %esi,0x4(%rsp)
mov    %esi,%edi
call   1080 <sched_get_priority_max@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1040 <assert@plt>
lea    0xe79(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1060 <sched_get_priority_min@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1040 <assert@plt>
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %eax,%edi
call   1050 <pthread_getschedparam@plt>
mov    (%rsp),%esi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [17 x i8] c"max_priority=%d\0A\00"
@.str.1 = [17 x i8] c"min_priority=%d\0A\00"
@.str.2 = [30 x i8] c"Current thread's priority:%d\0A\00"
define void @show_thread_priority(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sched_param
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @sched_get_priority_max(i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, -1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %5
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %4
%16 = call i32 @sched_get_priority_min(i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, -1
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i32 (...) @pthread_self()
%24 = call i32 @pthread_getschedparam(i32 %23, i32* %4, %struct.sched_param* %6)
%25 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %26)
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [17 x i8] c"max_priority=%d\0A\00"
@.str.1 = [17 x i8] c"min_priority=%d\0A\00"
@.str.2 = [30 x i8] c"Current thread's priority:%d\0A\00"
define void @show_thread_priority(i32* nocapture readnone %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sched_param
store i32 %1, i32* %3
%5 = tail call i32 @sched_get_priority_max(i32 %1)
%6 = icmp ne i32 %5, -1
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %5)
%10 = tail call i32 @sched_get_priority_min(i32 %1)
%11 = icmp ne i32 %10, -1
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%15 = bitcast %struct.sched_param* %4 to i8*
%16 = tail call i32 (...) @pthread_self()
%17 = call i32 @pthread_getschedparam(i32 %16, i32* %3, %struct.sched_param* %4)
%18 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %19)
ret void
}