#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 */
#define SCHED_FIFO 130
#define SCHED_OTHER 129
#define SCHED_RR 128
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sched_getparam(int, struct sched_param *);
int sched_getscheduler(int);
int /*<<< orphan*/ stderr;
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) {
    perror("sched_getscheduler");
    fprintf(stderr, "failed to get pid %d's policy\n", pid);
    exit(1);
  }
  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 SCHED_RR:
    printf("SCHED_RR\n");
    break;
  default:
    printf("unknown\n");
  }
  if (sched_getparam(pid, &sp)) {
    perror("sched_getparam");
    fprintf(stderr, "failed to get pid %d's attributes\n", pid);
    exit(1);
  }
  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    1193 <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    11d6 <show_rt_info+0x66>
lea    0xe51(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe4c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x80,%eax
je     124d <show_rt_info+0xdd>
jmp    1201 <show_rt_info+0x91>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
je     1227 <show_rt_info+0xb7>
jmp    1214 <show_rt_info+0xa4>
mov    -0x18(%rbp),%eax
sub    $0x82,%eax
je     123a <show_rt_info+0xca>
jmp    1260 <show_rt_info+0xf0>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126e <show_rt_info+0xfe>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126e <show_rt_info+0xfe>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126e <show_rt_info+0xfe>
lea    0xe0e(%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     12b2 <show_rt_info+0x142>
lea    0xdf3(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xdea(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xded(%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,%ebx
mov    %rdi,%r14
test   %esi,%esi
jne    119a <show_rt_info+0x1a>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebx
mov    %ebx,%edi
call   1030 <sched_getscheduler@plt>
cmp    $0xffffffff,%eax
je     1213 <show_rt_info+0x93>
mov    %eax,%ebp
lea    0xe83(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffff80,%ebp
cmp    $0x2,%ebp
ja     11d6 <show_rt_info+0x56>
movslq %ebp,%rax
lea    0xf07(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    11dd <show_rt_info+0x5d>
lea    0xeec(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1070 <sched_getparam@plt>
test   %rax,%rax
jne    1231 <show_rt_info+0xb1>
mov    0x8(%rsp),%ecx
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde6(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
jmp    124d <show_rt_info+0xcd>
lea    0xe1a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    %ebx,%edx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [19 x i8] c"sched_getscheduler\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"failed to get pid %d's policy\0A\00"
@.str.2 = [32 x i8] c"pid %d's %s scheduling policy: \00"
@.str.3 = [13 x i8] c"SCHED_OTHER\0A\00"
@.str.4 = [12 x i8] c"SCHED_FIFO\0A\00"
@.str.5 = [10 x i8] c"SCHED_RR\0A\00"
@.str.6 = [9 x i8] c"unknown\0A\00"
@.str.7 = [15 x i8] c"sched_getparam\00"
@.str.8 = [35 x i8] c"failed to get pid %d's attributes\0A\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 %22
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = load i32, i32* %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %11
%23 = load i32, i32* %4
%24 = load i8*, i8** %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %24)
%26 = load i32, i32* %6
switch i32 %26, label %33 [
i32 129, label %27
i32 130, label %29
i32 128, label %31
]
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %35
29: ; preds = %22
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %35
31: ; preds = %22
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %35
33: ; preds = %22
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %31, %29, %27
%36 = load i32, i32* %4
%37 = call i64 @sched_getparam(i32 %36, %struct.sched_param* %5)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = load i32, i32* %4
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %35
%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 }
@.str = [19 x i8] c"sched_getscheduler\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"failed to get pid %d's policy\0A\00"
@.str.2 = [32 x i8] c"pid %d's %s scheduling policy: \00"
@.str.7 = [15 x i8] c"sched_getparam\00"
@.str.8 = [35 x i8] c"failed to get pid %d's attributes\0A\00"
@.str.9 = [37 x i8] c"pid %d's %s scheduling priority: %d\0A\00"
@str = [9 x i8] c"SCHED_RR\00"
@str.10 = [11 x i8] c"SCHED_FIFO\00"
@str.11 = [12 x i8] c"SCHED_OTHER\00"
@str.12 = [8 x i8] c"unknown\00"
@reltable.show_rt_info = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @str to i64), i64 ptrtoint ([3 x i32]* @reltable.show_rt_info to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.11 to i64), i64 ptrtoint ([3 x i32]* @reltable.show_rt_info to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.10 to i64), i64 ptrtoint ([3 x i32]* @reltable.show_rt_info to i64)) to i32)]
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 %17
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %9, i8* %0)
%19 = add i32 %10, -128
%20 = icmp ult i32 %19, 3
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = sext i32 %19 to i64
%23 = shl i64 %22, 2
%24 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.show_rt_info to i8*), i64 %23)
br label %25
25: ; preds = %17, %21
%26 = phi i8* [ %24, %21 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.12, i64 0, i64 0), %17 ]
%27 = tail call i32 @puts(i8* dereferenceable(1) %26)
%28 = call i64 @sched_getparam(i32 %9, %struct.sched_param* %3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 %9)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %25
%36 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
%37 = load i32, i32* %36
%38 = 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 %37)
ret void
}