#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;
  case 3:
    printf("SCHED_BATCH\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    $0x3,%eax
je     1271 <show_rt_info+0x101>
jmp    11ff <show_rt_info+0x8f>
mov    -0x18(%rbp),%eax
sub    $0x80,%eax
je     125e <show_rt_info+0xee>
jmp    1212 <show_rt_info+0xa2>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
je     1238 <show_rt_info+0xc8>
jmp    1225 <show_rt_info+0xb5>
mov    -0x18(%rbp),%eax
sub    $0x82,%eax
je     124b <show_rt_info+0xdb>
jmp    1284 <show_rt_info+0x114>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1292 <show_rt_info+0x122>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1292 <show_rt_info+0x122>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1292 <show_rt_info+0x122>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1292 <show_rt_info+0x122>
lea    0xdf7(%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     12d6 <show_rt_info+0x166>
lea    0xddc(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xdd3(%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    0xdd6(%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     1245 <show_rt_info+0xc5>
mov    %eax,%ebp
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x80,%ebp
jg     11dd <show_rt_info+0x5d>
cmp    $0x3,%ebp
je     11f6 <show_rt_info+0x76>
cmp    $0x80,%ebp
jne    1208 <show_rt_info+0x88>
lea    0xeda(%rip),%rdi
jmp    120f <show_rt_info+0x8f>
cmp    $0x81,%ebp
je     11ff <show_rt_info+0x7f>
cmp    $0x82,%ebp
jne    1208 <show_rt_info+0x88>
lea    0xeca(%rip),%rdi
jmp    120f <show_rt_info+0x8f>
lea    0xeac(%rip),%rdi
jmp    120f <show_rt_info+0x8f>
lea    0xec3(%rip),%rdi
jmp    120f <show_rt_info+0x8f>
lea    0xec6(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1070 <sched_getparam@plt>
test   %rax,%rax
jne    1263 <show_rt_info+0xe3>
mov    0x8(%rsp),%ecx
lea    0xe54(%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    0xdb4(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
jmp    127f <show_rt_info+0xff>
lea    0xde8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%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 = [13 x i8] c"SCHED_BATCH\0A\00"
@.str.7 = [9 x i8] c"unknown\0A\00"
@.str.8 = [15 x i8] c"sched_getparam\00"
@.str.9 = [35 x i8] c"failed to get pid %d's attributes\0A\00"
@.str.10 = [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 %35 [
i32 129, label %27
i32 130, label %29
i32 128, label %31
i32 3, label %33
]
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 %37
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 %37
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 %37
33: ; preds = %22
%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 = %22
%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
%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 %47
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = load i32, i32* %4
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %37
%48 = load i32, i32* %4
%49 = load i8*, i8** %3
%50 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %48, i8* %49, i32 %51)
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.8 = [15 x i8] c"sched_getparam\00"
@.str.9 = [35 x i8] c"failed to get pid %d's attributes\0A\00"
@.str.10 = [37 x i8] c"pid %d's %s scheduling priority: %d\0A\00"
@str = [12 x i8] c"SCHED_BATCH\00"
@str.11 = [9 x i8] c"SCHED_RR\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 %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)
switch i32 %10, label %22 [
i32 129, label %23
i32 130, label %19
i32 128, label %20
i32 3, label %21
]
19: ; preds = %17
br label %23
20: ; preds = %17
br label %23
21: ; preds = %17
br label %23
22: ; preds = %17
br label %23
23: ; preds = %17, %22, %21, %20, %19
%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.11, i64 0, i64 0), %20 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.12, i64 0, i64 0), %19 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0), %17 ]
%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 %33, label %28
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i32 %9)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %9, i8* %0, i32 %35)
ret void
}