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

/* Variables and functions */
#define SCHED_FIFO 130
#define SCHED_OTHER 129
#define SCHED_RR 128
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int sched_get_priority_max(int);
int sched_get_priority_min(int);
int /*<<< orphan*/ sched_getparam(int /*<<< orphan*/, struct sched_param *);
int sched_getscheduler(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i = sched_getscheduler(0);
  char *sched;
  switch (i) {
  case SCHED_FIFO:
    sched = "SCHED_FIFO";
    break;
  case SCHED_RR:
    sched = "SCHED_RR";
    break;
  case SCHED_OTHER:
    sched = "SCHED_OTHER";
    break;
  default:
    sched = "OTRA";
    break;
  }
  int my_pid = getpid();
  printf("%i scheduling policy: %s\n", my_pid, sched);
  struct sched_param p;
  sched_getparam(0, &p);
  printf("%i scheduling priority: %i\n", my_pid, p.sched_priority);
  printf("Priotiry maximun value: %i\n", sched_get_priority_max(i));
  printf("Priority minimum value: %i\n", sched_get_priority_min(i));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x80,%eax
je     11cc <main+0x6c>
jmp    1196 <main+0x36>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
je     11dc <main+0x7c>
jmp    11a9 <main+0x49>
mov    -0x2c(%rbp),%eax
sub    $0x82,%eax
jne    11ec <main+0x8c>
jmp    11bc <main+0x5c>
lea    0xe3d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f7 <main+0x97>
lea    0xe38(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f7 <main+0x97>
lea    0xe31(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f7 <main+0x97>
lea    0xe2d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
lea    -0x28(%rbp),%rsi
call   1060 <sched_getparam@plt>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <sched_get_priority_max@plt>
mov    %eax,%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <sched_get_priority_min@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,%r14d
add    $0xffffff80,%eax
cmp    $0x2,%eax
ja     118c <main+0x2c>
cltq
lea    0xf11(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1193 <main+0x33>
lea    0xe8d(%rip),%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
lea    0xe82(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1060 <sched_getparam@plt>
mov    0x8(%rsp),%edx
lea    0xe79(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1080 <sched_get_priority_max@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1070 <sched_get_priority_min@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [11 x i8] c"SCHED_FIFO\00"
@.str.1 = [9 x i8] c"SCHED_RR\00"
@.str.2 = [12 x i8] c"SCHED_OTHER\00"
@.str.3 = [5 x i8] c"OTRA\00"
@.str.4 = [26 x i8] c"%i scheduling policy: %s\0A\00"
@.str.5 = [28 x i8] c"%i scheduling priority: %i\0A\00"
@.str.6 = [28 x i8] c"Priotiry maximun value: %i\0A\00"
@.str.7 = [28 x i8] c"Priority minimum value: %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sched_param
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @sched_getscheduler(i32 0)
store i32 %10, i32* %6
%11 = load i32, i32* %6
switch i32 %11, label %15 [
i32 130, label %12
i32 128, label %13
i32 129, label %14
]
12: ; preds = %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %7
br label %16
13: ; preds = %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %16
14: ; preds = %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %16
15: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %16
16: ; preds = %15, %14, %13, %12
%17 = call i32 (...) @getpid()
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = load i8*, i8** %7
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %18, i8* %19)
%21 = call i32 @sched_getparam(i32 0, %struct.sched_param* %9)
%22 = load i32, i32* %8
%23 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %9, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %22, i32 %24)
%26 = load i32, i32* %6
%27 = call i32 @sched_get_priority_max(i32 %26)
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = call i32 @sched_get_priority_min(i32 %29)
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [11 x i8] c"SCHED_FIFO\00"
@.str.1 = [9 x i8] c"SCHED_RR\00"
@.str.2 = [12 x i8] c"SCHED_OTHER\00"
@.str.3 = [5 x i8] c"OTRA\00"
@.str.4 = [26 x i8] c"%i scheduling policy: %s\0A\00"
@.str.5 = [28 x i8] c"%i scheduling priority: %i\0A\00"
@.str.6 = [28 x i8] c"Priotiry maximun value: %i\0A\00"
@.str.7 = [28 x i8] c"Priority minimum value: %i\0A\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sched_param
%4 = tail call i32 @sched_getscheduler(i32 0)
%5 = add i32 %4, -128
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %9)
br label %11
11: ; preds = %2, %7
%12 = phi i8* [ %10, %7 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %2 ]
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %13, i8* %12)
%15 = bitcast %struct.sched_param* %3 to i8*
%16 = call i32 @sched_getparam(i32 0, %struct.sched_param* %3)
%17 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %13, i32 %18)
%20 = call i32 @sched_get_priority_max(i32 %4)
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %20)
%22 = call i32 @sched_get_priority_min(i32 %4)
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %22)
ret i32 0
}