#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(pid_t pid, int isnew) {
  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);
  if (isnew)
    printf(("pid %d's new scheduling policy: "), pid);
  else
    printf(("pid %d's current scheduling policy: "), pid);
  switch (policy) {
  case SCHED_OTHER:
    printf("SCHED_OTHER\n");
    break;
  case SCHED_FIFO:
    printf("SCHED_FIFO\n");
    break;
  case SCHED_FIFO | 0x40000000:
    printf("SCHED_FIFO|SCHED_RESET_ON_FORK\n");
    break;
  case 5:
    printf("SCHED_IDLE\n");
    break;
  case SCHED_RR:
    printf("SCHED_RR\n");
    break;
  case SCHED_RR | 0x40000000:
    printf("SCHED_RR|SCHED_RESET_ON_FORK\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);
  if (isnew)
    printf(("pid %d's new scheduling priority: %d\n"), pid, sp.sched_priority);
  else
    printf(("pid %d's current scheduling priority: %d\n"), pid,
           sp.sched_priority);
}


x86 assembly (clang, -O0):
<show_rt_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1172 <show_rt_info+0x22>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    119f <show_rt_info+0x4f>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe66(%rip),%rsi
call   1070 <err@plt>
cmpl   $0x0,-0x8(%rbp)
je     11bf <show_rt_info+0x6f>
mov    -0x4(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d0 <show_rt_info+0x80>
mov    -0x4(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x3,%eax
je     12c6 <show_rt_info+0x176>
jmp    11e4 <show_rt_info+0x94>
mov    -0x18(%rbp),%eax
sub    $0x5,%eax
je     128d <show_rt_info+0x13d>
jmp    11f5 <show_rt_info+0xa5>
mov    -0x18(%rbp),%eax
sub    $0x80,%eax
je     12a0 <show_rt_info+0x150>
jmp    1208 <show_rt_info+0xb8>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
je     1254 <show_rt_info+0x104>
jmp    121b <show_rt_info+0xcb>
mov    -0x18(%rbp),%eax
sub    $0x82,%eax
je     1267 <show_rt_info+0x117>
jmp    122e <show_rt_info+0xde>
mov    -0x18(%rbp),%eax
sub    $0x40000080,%eax
je     12b3 <show_rt_info+0x163>
jmp    1241 <show_rt_info+0xf1>
mov    -0x18(%rbp),%eax
sub    $0x40000082,%eax
je     127a <show_rt_info+0x12a>
jmp    12d9 <show_rt_info+0x189>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e7 <show_rt_info+0x197>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e7 <show_rt_info+0x197>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e7 <show_rt_info+0x197>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e7 <show_rt_info+0x197>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e7 <show_rt_info+0x197>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e7 <show_rt_info+0x197>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e7 <show_rt_info+0x197>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <sched_getparam@plt>
cmp    $0x0,%rax
je     1315 <show_rt_info+0x1c5>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xdd7(%rip),%rsi
call   1070 <err@plt>
cmpl   $0x0,-0x8(%rbp)
je     1338 <show_rt_info+0x1e8>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    134c <show_rt_info+0x1fc>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xdea(%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,%r14d
mov    %edi,%ebx
test   %edi,%edi
jne    117a <show_rt_info+0x1a>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebx
mov    %ebx,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    119f <show_rt_info+0x3f>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    %ebx,%edx
call   1080 <err@plt>
test   %r14d,%r14d
lea    0xe96(%rip),%rax
lea    0xe6e(%rip),%rdi
cmove  %rax,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x80,%ebp
jle    11e6 <show_rt_info+0x86>
cmp    $0x4000007f,%ebp
jg     1201 <show_rt_info+0xa1>
cmp    $0x81,%ebp
je     121a <show_rt_info+0xba>
cmp    $0x82,%ebp
jne    1235 <show_rt_info+0xd5>
lea    0xf4e(%rip),%rdi
jmp    1245 <show_rt_info+0xe5>
cmp    $0x3,%ebp
je     1223 <show_rt_info+0xc3>
cmp    $0x5,%ebp
je     123e <show_rt_info+0xde>
cmp    $0x80,%ebp
jne    1235 <show_rt_info+0xd5>
lea    0xf00(%rip),%rdi
jmp    1245 <show_rt_info+0xe5>
cmp    $0x40000080,%ebp
je     122c <show_rt_info+0xcc>
cmp    $0x40000082,%ebp
jne    1235 <show_rt_info+0xd5>
lea    0xefb(%rip),%rdi
jmp    1245 <show_rt_info+0xe5>
lea    0xf1c(%rip),%rdi
jmp    1245 <show_rt_info+0xe5>
lea    0xeac(%rip),%rdi
jmp    1245 <show_rt_info+0xe5>
lea    0xeaf(%rip),%rdi
jmp    1245 <show_rt_info+0xe5>
lea    0xf0d(%rip),%rdi
jmp    1245 <show_rt_info+0xe5>
lea    0xec3(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1070 <sched_getparam@plt>
test   %rax,%rax
je     1272 <show_rt_info+0x112>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
mov    %ebx,%edx
call   1080 <err@plt>
test   %r14d,%r14d
mov    0x8(%rsp),%edx
lea    0xe2c(%rip),%rax
lea    0xdff(%rip),%rdi
cmove  %rax,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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 = [33 x i8] c"pid %d's new scheduling policy: \00"
@.str.2 = [37 x i8] c"pid %d's current 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 = [32 x i8] c"SCHED_FIFO|SCHED_RESET_ON_FORK\0A\00"
@.str.6 = [12 x i8] c"SCHED_IDLE\0A\00"
@.str.7 = [10 x i8] c"SCHED_RR\0A\00"
@.str.8 = [30 x i8] c"SCHED_RR|SCHED_RESET_ON_FORK\0A\00"
@.str.9 = [13 x i8] c"SCHED_BATCH\0A\00"
@.str.10 = [9 x i8] c"unknown\0A\00"
@.str.11 = [34 x i8] c"failed to get pid %d's attributes\00"
@.str.12 = [38 x i8] c"pid %d's new scheduling priority: %d\0A\00"
@.str.13 = [42 x i8] c"pid %d's current scheduling priority: %d\0A\00"
define void @show_rt_info(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sched_param
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 (...) @getpid()
store i32 %10, i32* %3
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* %3
%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* %3
%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 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %29
26: ; preds = %20
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %6
switch i32 %30, label %45 [
i32 129, label %31
i32 130, label %33
i32 1073741954, label %35
i32 5, label %37
i32 128, label %39
i32 1073741952, label %41
i32 3, label %43
]
31: ; preds = %29
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %47
33: ; preds = %29
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %47
35: ; preds = %29
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %47
37: ; preds = %29
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %47
39: ; preds = %29
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %47
41: ; preds = %29
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %47
43: ; preds = %29
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %47
45: ; preds = %29
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
br label %47
47: ; preds = %45, %43, %41, %39, %37, %35, %33, %31
%48 = load i32, i32* %3
%49 = call i64 @sched_getparam(i32 %48, %struct.sched_param* %5)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* @EXIT_FAILURE
%53 = load i32, i32* %3
%54 = call i32 @err(i32 %52, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %51, %47
%56 = load i32, i32* %4
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i32, i32* %3
%60 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i32 %59, i32 %61)
br label %68
63: ; preds = %55
%64 = load i32, i32* %3
%65 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i32 %64, i32 %66)
br label %68
68: ; preds = %63, %58
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 = [33 x i8] c"pid %d's new scheduling policy: \00"
@.str.2 = [37 x i8] c"pid %d's current scheduling policy: \00"
@.str.11 = [34 x i8] c"failed to get pid %d's attributes\00"
@.str.12 = [38 x i8] c"pid %d's new scheduling priority: %d\0A\00"
@.str.13 = [42 x i8] c"pid %d's current scheduling priority: %d\0A\00"
@str = [12 x i8] c"SCHED_BATCH\00"
@str.14 = [29 x i8] c"SCHED_RR|SCHED_RESET_ON_FORK\00"
@str.15 = [9 x i8] c"SCHED_RR\00"
@str.16 = [11 x i8] c"SCHED_IDLE\00"
@str.17 = [31 x i8] c"SCHED_FIFO|SCHED_RESET_ON_FORK\00"
@str.18 = [11 x i8] c"SCHED_FIFO\00"
@str.19 = [12 x i8] c"SCHED_OTHER\00"
@str.20 = [8 x i8] c"unknown\00"
define void @show_rt_info(i32 %0, i32 %1) {
%3 = alloca %struct.sched_param
%4 = bitcast %struct.sched_param* %3 to i8*
%5 = icmp eq i32 %0, 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 [ %0, %2 ], [ %7, %6 ]
%10 = tail call i32 @sched_getscheduler(i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
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)
br label %15
15: ; preds = %12, %8
%16 = icmp eq i32 %1, 0
%17 = select i1 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %17, i32 %9)
switch i32 %10, label %25 [
i32 129, label %26
i32 130, label %19
i32 1073741954, label %20
i32 5, label %21
i32 128, label %22
i32 1073741952, label %23
i32 3, label %24
]
19: ; preds = %15
br label %26
20: ; preds = %15
br label %26
21: ; preds = %15
br label %26
22: ; preds = %15
br label %26
23: ; preds = %15
br label %26
24: ; preds = %15
br label %26
25: ; preds = %15
br label %26
26: ; preds = %15, %25, %24, %23, %22, %21, %20, %19
%27 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.20, i64 0, i64 0), %25 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), %24 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.14, i64 0, i64 0), %23 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.15, i64 0, i64 0), %22 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.16, i64 0, i64 0), %21 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @str.17, i64 0, i64 0), %20 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.18, i64 0, i64 0), %19 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.19, i64 0, i64 0), %15 ]
%28 = tail call i32 @puts(i8* dereferenceable(1) %27)
%29 = call i64 @sched_getparam(i32 %9, %struct.sched_param* %3)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @err(i32 %32, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i32 %9)
br label %34
34: ; preds = %31, %26
%35 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
%36 = load i32, i32* %35
%37 = select i1 %16, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %37, i32 %9, i32 %36)
ret void
}