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

/* Variables and functions */
int SCHED_FIFO;
int SCHED_OTHER;
int SCHED_RR;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pthread_getschedparam(int /*<<< orphan*/, int *,
                                 struct sched_param *);
int /*<<< orphan*/ pthread_self();
int get_priority() {
  int policy;
  struct sched_param param;
  if (0 != pthread_getschedparam(pthread_self(), &policy, &param)) {
    printf("pthread_getschedparam faild: %m\n");
    return -1;
  }
  printf("thread priority: %s/%d\n",
         (policy == SCHED_FIFO
              ? "FIFO"
              : (policy == SCHED_RR
                     ? "RR"
                     : (policy == SCHED_OTHER ? "OTHER" : "unknown"))),
         param.sched_priority);
  return 0;
}


x86 assembly (clang, -O0):
<get_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <pthread_getschedparam@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1176 <get_priority+0x46>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1202 <get_priority+0xd2>
mov    -0x8(%rbp),%eax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%eax
jne    1198 <get_priority+0x68>
lea    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11e6 <get_priority+0xb6>
mov    -0x8(%rbp),%eax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%eax
jne    11ba <get_priority+0x8a>
lea    0xe8d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11de <get_priority+0xae>
mov    -0x8(%rbp),%edx
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rax
lea    0xe6d(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_priority>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1040 <pthread_getschedparam@plt>
test   %rax,%rax
je     1167 <get_priority+0x37>
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11c2 <get_priority+0x92>
mov    0xc(%rsp),%eax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%eax
jne    117f <get_priority+0x4f>
lea    0xebc(%rip),%rsi
jmp    11ae <get_priority+0x7e>
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
jne    1193 <get_priority+0x63>
lea    0xead(%rip),%rsi
jmp    11ae <get_priority+0x7e>
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
lea    0xe9e(%rip),%rax
lea    0xe9d(%rip),%rsi
cmove  %rax,%rsi
mov    0x8(%rsp),%edx
lea    0xe68(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [33 x i8] c"pthread_getschedparam faild: %m\0A\00"
@.str.1 = [24 x i8] c"thread priority: %s/%d\0A\00"
@SCHED_FIFO = global i32 0
@.str.2 = [5 x i8] c"FIFO\00"
@SCHED_RR = global i32 0
@.str.3 = [3 x i8] c"RR\00"
@SCHED_OTHER = global i32 0
@.str.4 = [6 x i8] c"OTHER\00"
@.str.5 = [8 x i8] c"unknown\00"
define i32 @get_priority() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sched_param
%4 = call i32 (...) @pthread_self()
%5 = call i64 @pthread_getschedparam(i32 %4, i32* %2, %struct.sched_param* %3)
%6 = icmp ne i64 0, %5
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %32
9: ; preds = %0
%10 = load i32, i32* %2
%11 = load i32, i32* @SCHED_FIFO
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
br label %27
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* @SCHED_RR
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %25
19: ; preds = %14
%20 = load i32, i32* %2
%21 = load i32, i32* @SCHED_OTHER
%22 = icmp eq i32 %20, %21
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0)
br label %25
25: ; preds = %19, %18
%26 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %18 ], [ %24, %19 ]
br label %27
27: ; preds = %25, %13
%28 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %13 ], [ %26, %25 ]
%29 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %30)
store i32 0, i32* %1
br label %32
32: ; preds = %27, %7
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [33 x i8] c"pthread_getschedparam faild: %m\0A\00"
@.str.1 = [24 x i8] c"thread priority: %s/%d\0A\00"
@SCHED_FIFO = global i32 0
@.str.2 = [5 x i8] c"FIFO\00"
@SCHED_RR = global i32 0
@.str.3 = [3 x i8] c"RR\00"
@SCHED_OTHER = global i32 0
@.str.4 = [6 x i8] c"OTHER\00"
@.str.5 = [8 x i8] c"unknown\00"
define i32 @get_priority() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.sched_param* %2 to i8*
%5 = tail call i32 (...) @pthread_self()
%6 = call i64 @pthread_getschedparam(i32 %5, i32* %1, %struct.sched_param* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %26
10: ; preds = %0
%11 = load i32, i32* %1
%12 = load i32, i32* @SCHED_FIFO
%13 = icmp eq i32 %11, %12
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = load i32, i32* @SCHED_RR
%16 = icmp eq i32 %11, %15
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i32, i32* @SCHED_OTHER
%19 = icmp eq i32 %11, %18
%20 = select i1 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0)
br label %21
21: ; preds = %17, %14, %10
%22 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %10 ], [ %20, %17 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %14 ]
%23 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %24)
br label %26
26: ; preds = %21, %8
%27 = phi i32 [ -1, %8 ], [ 0, %21 ]
ret i32 %27
}