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

/* Variables and functions */
int /*<<< orphan*/ PRIO_PROCESS;
#define SCHED_FIFO 130
#define SCHED_OTHER 129
#define SCHED_RR 128
int getpriority(int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sched_get_priority_max(int);
int sched_get_priority_min(int);
int /*<<< orphan*/ sched_getparam(int, struct sched_param *);
int sched_getscheduler(int);
void print_prio(pid_t pid) {
  int sched;
  struct sched_param sp;
  printf("pid %d's priority: %d\n", pid, getpriority(PRIO_PROCESS, pid));
  printf("scheduling class: ");
  sched = sched_getscheduler(pid);
  switch (sched) {
  case SCHED_FIFO:
    printf("FIFO\n");
    break;
  case SCHED_RR:
    printf("RR\n");
    break;
  case SCHED_OTHER:
    printf("Normal\n");
    break;
  case -1:
    perror("sched_getscheduler");
    break;
  default:
    printf("Unknown\n");
  }
  sched_getparam(pid, &sp);
  printf("RT prio: %d (of %d to %d)\n", sp.sched_priority,
         sched_get_priority_min(sched), sched_get_priority_max(sched));
}


x86 assembly (clang, -O0):
<print_prio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    %esi,-0x1c(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1040 <getpriority@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe65(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1050 <printf@plt>
mov    -0x15(%rbp),%al
lea    0xe68(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xffffffff,%eax
je     1245 <print_prio+0xd5>
jmp    11d3 <print_prio+0x63>
mov    -0x14(%rbp),%eax
sub    $0x80,%eax
je     121f <print_prio+0xaf>
jmp    11e6 <print_prio+0x76>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     1232 <print_prio+0xc2>
jmp    11f9 <print_prio+0x89>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
jne    1256 <print_prio+0xe6>
jmp    120c <print_prio+0x9c>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1264 <print_prio+0xf4>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1264 <print_prio+0xf4>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1264 <print_prio+0xf4>
lea    0xdf0(%rip),%rdi
call   1080 <perror@plt>
jmp    1264 <print_prio+0xf4>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <sched_getparam@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <sched_get_priority_min@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <sched_get_priority_max@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_prio>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
call   1040 <getpriority@plt>
lea    0xe5f(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,%ebp
cmp    $0x80,%eax
jle    11e3 <print_prio+0x63>
cmp    $0x81,%ebp
je     11ee <print_prio+0x6e>
cmp    $0x82,%ebp
jne    11fc <print_prio+0x7c>
lea    0xe81(%rip),%rdi
jmp    1203 <print_prio+0x83>
jne    11f7 <print_prio+0x77>
lea    0xe73(%rip),%rdi
jmp    1203 <print_prio+0x83>
lea    0xe63(%rip),%rdi
jmp    1203 <print_prio+0x83>
cmp    $0xffffffff,%ebp
je     1247 <print_prio+0xc7>
lea    0xe64(%rip),%rdi
call   1050 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1070 <sched_getparam@plt>
mov    0x8(%rsp),%r14d
mov    %ebp,%edi
call   1080 <sched_get_priority_min@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   10a0 <sched_get_priority_max@plt>
lea    0xe0d(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xddc(%rip),%rdi
call   1090 <perror@plt>
jmp    1208 <print_prio+0x88>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [23 x i8] c"pid %d's priority: %d\0A\00"
@PRIO_PROCESS = global i32 0
@.str.1 = [19 x i8] c"scheduling class: \00"
@.str.2 = [6 x i8] c"FIFO\0A\00"
@.str.3 = [4 x i8] c"RR\0A\00"
@.str.4 = [8 x i8] c"Normal\0A\00"
@.str.5 = [19 x i8] c"sched_getscheduler\00"
@.str.6 = [9 x i8] c"Unknown\0A\00"
@.str.7 = [27 x i8] c"RT prio: %d (of %d to %d)\0A\00"
define void @print_prio(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sched_param
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @PRIO_PROCESS
%7 = load i32, i32* %2
%8 = call i32 @getpriority(i32 %6, i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = call i32 @sched_getscheduler(i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
switch i32 %13, label %22 [
i32 130, label %14
i32 128, label %16
i32 129, label %18
i32 -1, label %20
]
14: ; preds = %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %24
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %24
18: ; preds = %1
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %24
20: ; preds = %1
%21 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %24
22: ; preds = %1
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %18, %16, %14
%25 = load i32, i32* %2
%26 = call i32 @sched_getparam(i32 %25, %struct.sched_param* %4)
%27 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* %3
%30 = call i32 @sched_get_priority_min(i32 %29)
%31 = load i32, i32* %3
%32 = call i32 @sched_get_priority_max(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %28, i32 %30, i32 %32)
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [23 x i8] c"pid %d's priority: %d\0A\00"
@PRIO_PROCESS = global i32 0
@.str.1 = [19 x i8] c"scheduling class: \00"
@.str.5 = [19 x i8] c"sched_getscheduler\00"
@.str.7 = [27 x i8] c"RT prio: %d (of %d to %d)\0A\00"
@str = [7 x i8] c"Normal\00"
@str.8 = [3 x i8] c"RR\00"
@str.9 = [5 x i8] c"FIFO\00"
@str.10 = [8 x i8] c"Unknown\00"
define void @print_prio(i32 %0) {
%2 = alloca %struct.sched_param
%3 = bitcast %struct.sched_param* %2 to i8*
%4 = load i32, i32* @PRIO_PROCESS
%5 = tail call i32 @getpriority(i32 %4, i32 %0)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @sched_getscheduler(i32 %0)
switch i32 %8, label %17 [
i32 130, label %9
i32 128, label %11
i32 129, label %13
i32 -1, label %15
]
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.9, i64 0, i64 0))
br label %19
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.8, i64 0, i64 0))
br label %19
13: ; preds = %1
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %19
15: ; preds = %1
%16 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %19
17: ; preds = %1
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
br label %19
19: ; preds = %17, %15, %13, %11, %9
%20 = call i32 @sched_getparam(i32 %0, %struct.sched_param* %2)
%21 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @sched_get_priority_min(i32 %8)
%24 = call i32 @sched_get_priority_max(i32 %8)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %22, i32 %23, i32 %24)
ret void
}