#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*/ EXIT_FAILURE;
#define SCHED_FIFO 130
#define SCHED_OTHER 129
#define SCHED_RR 128
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, int);
int getpid();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sched_getparam(int, struct sched_param *);
int sched_getscheduler(int);
void show_rt_info(const char *what, pid_t pid) {
  struct sched_param sp;
  int policy;
  if (!pid)
    pid = getpid();
  policy = sched_getscheduler(pid);
  if (policy == -1)
    err(EXIT_FAILURE, ("failed to get pid %d's policy"), pid);
  printf(("pid %d's %s scheduling policy: "), pid, what);
  switch (policy) {
  case SCHED_OTHER:
    printf("SCHED_OTHER\n");
    break;
  case SCHED_FIFO:
    printf("SCHED_FIFO\n");
    break;
  case 5:
    printf("SCHED_IDLE\n");
    break;
  case SCHED_RR:
    printf("SCHED_RR\n");
    break;
  case 3:
    printf("SCHED_BATCH\n");
    break;
  default:
    printf(("unknown\n"));
  }
  if (sched_getparam(pid, &sp))
    err(EXIT_FAILURE, ("failed to get pid %d's attributes"), pid);
  printf(("pid %d's %s scheduling priority: %d\n"), pid, what,
         sp.sched_priority);
}


x86 assembly (clang, -O0):
<show_rt_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1173 <show_rt_info+0x23>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a0 <show_rt_info+0x50>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe65(%rip),%rsi
call   1070 <err@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x3,%eax
je     125f <show_rt_info+0x10f>
jmp    11c9 <show_rt_info+0x79>
mov    -0x18(%rbp),%eax
sub    $0x5,%eax
je     1239 <show_rt_info+0xe9>
jmp    11da <show_rt_info+0x8a>
mov    -0x18(%rbp),%eax
sub    $0x80,%eax
je     124c <show_rt_info+0xfc>
jmp    11ed <show_rt_info+0x9d>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
je     1213 <show_rt_info+0xc3>
jmp    1200 <show_rt_info+0xb0>
mov    -0x18(%rbp),%eax
sub    $0x82,%eax
je     1226 <show_rt_info+0xd6>
jmp    1272 <show_rt_info+0x122>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1280 <show_rt_info+0x130>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1280 <show_rt_info+0x130>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1280 <show_rt_info+0x130>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1280 <show_rt_info+0x130>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1280 <show_rt_info+0x130>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <sched_getparam@plt>
cmp    $0x0,%rax
je     12ae <show_rt_info+0x15e>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xdda(%rip),%rsi
call   1070 <err@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_rt_info>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
jne    117a <show_rt_info+0x1a>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebp
mov    %ebp,%edi
call   1030 <sched_getscheduler@plt>
cmp    $0xffffffff,%eax
je     11cd <show_rt_info+0x6d>
mov    %eax,%ebx
lea    0xe8f(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x7f,%ebx
jle    124b <show_rt_info+0xeb>
cmp    $0x80,%ebx
je     125e <show_rt_info+0xfe>
cmp    $0x81,%ebx
je     1267 <show_rt_info+0x107>
cmp    $0x82,%ebx
jne    11f7 <show_rt_info+0x97>
lea    0xeda(%rip),%rdi
jmp    11fe <show_rt_info+0x9e>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
mov    %ebp,%edx
call   1080 <err@plt>
lea    0xe33(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xebe(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1070 <sched_getparam@plt>
test   %rax,%rax
je     122b <show_rt_info+0xcb>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    %ebp,%edx
call   1080 <err@plt>
mov    0x8(%rsp),%ecx
lea    0xe2a(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x3,%ebx
je     1270 <show_rt_info+0x110>
cmp    $0x5,%ebx
jne    11f7 <show_rt_info+0x97>
lea    0xe3e(%rip),%rdi
jmp    11fe <show_rt_info+0x9e>
lea    0xe2c(%rip),%rdi
jmp    11fe <show_rt_info+0x9e>
lea    0xe42(%rip),%rdi
jmp    11fe <show_rt_info+0x9e>
lea    0xe0e(%rip),%rdi
jmp    11fe <show_rt_info+0x9e>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [30 x i8] c"failed to get pid %d's policy\00"
@.str.1 = [32 x i8] c"pid %d's %s scheduling policy: \00"
@.str.2 = [13 x i8] c"SCHED_OTHER\0A\00"
@.str.3 = [12 x i8] c"SCHED_FIFO\0A\00"
@.str.4 = [12 x i8] c"SCHED_IDLE\0A\00"
@.str.5 = [10 x i8] c"SCHED_RR\0A\00"
@.str.6 = [13 x i8] c"SCHED_BATCH\0A\00"
@.str.7 = [9 x i8] c"unknown\0A\00"
@.str.8 = [34 x i8] c"failed to get pid %d's attributes\00"
@.str.9 = [37 x i8] c"pid %d's %s scheduling priority: %d\0A\00"
define void @show_rt_info(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sched_param
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 (...) @getpid()
store i32 %10, i32* %4
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* %4
%13 = call i32 @sched_getscheduler(i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @EXIT_FAILURE
%18 = load i32, i32* %4
%19 = call i32 @err(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %11
%21 = load i32, i32* %4
%22 = load i8*, i8** %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %22)
%24 = load i32, i32* %6
switch i32 %24, label %35 [
i32 129, label %25
i32 130, label %27
i32 5, label %29
i32 128, label %31
i32 3, label %33
]
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %37
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %37
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %37
31: ; preds = %20
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %37
33: ; preds = %20
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %37
35: ; preds = %20
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %35, %33, %31, %29, %27, %25
%38 = load i32, i32* %4
%39 = call i64 @sched_getparam(i32 %38, %struct.sched_param* %5)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* @EXIT_FAILURE
%43 = load i32, i32* %4
%44 = call i32 @err(i32 %42, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %37
%46 = load i32, i32* %4
%47 = load i8*, i8** %3
%48 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i32 %46, i8* %47, i32 %49)
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [30 x i8] c"failed to get pid %d's policy\00"
@.str.1 = [32 x i8] c"pid %d's %s scheduling policy: \00"
@.str.8 = [34 x i8] c"failed to get pid %d's attributes\00"
@.str.9 = [37 x i8] c"pid %d's %s scheduling priority: %d\0A\00"
@str = [12 x i8] c"SCHED_BATCH\00"
@str.10 = [9 x i8] c"SCHED_RR\00"
@str.11 = [11 x i8] c"SCHED_IDLE\00"
@str.12 = [11 x i8] c"SCHED_FIFO\00"
@str.13 = [12 x i8] c"SCHED_OTHER\00"
@str.14 = [8 x i8] c"unknown\00"
define void @show_rt_info(i8* %0, i32 %1) {
%3 = alloca %struct.sched_param
%4 = bitcast %struct.sched_param* %3 to i8*
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @getpid()
br label %8
8: ; preds = %6, %2
%9 = phi i32 [ %1, %2 ], [ %7, %6 ]
%10 = tail call i32 @sched_getscheduler(i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @err(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %9)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %0)
br label %22
16: ; preds = %8
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %0)
switch i32 %10, label %22 [
i32 129, label %23
i32 130, label %18
i32 5, label %19
i32 128, label %20
i32 3, label %21
]
18: ; preds = %16
br label %23
19: ; preds = %16
br label %23
20: ; preds = %16
br label %23
21: ; preds = %16
br label %23
22: ; preds = %12, %16
br label %23
23: ; preds = %16, %22, %21, %20, %19, %18
%24 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.14, i64 0, i64 0), %22 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), %21 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.10, i64 0, i64 0), %20 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.11, i64 0, i64 0), %19 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.12, i64 0, i64 0), %18 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0), %16 ]
%25 = tail call i32 @puts(i8* dereferenceable(1) %24)
%26 = call i64 @sched_getparam(i32 %9, %struct.sched_param* %3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @err(i32 %29, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %9)
br label %31
31: ; preds = %28, %23
%32 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i32 %9, i8* %0, i32 %33)
ret void
}