#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 */
int /*<<< orphan*/ SCHED_RR;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int sched_get_priority_max(int /*<<< orphan*/);
scalar_t__ sched_getparam(int /*<<< orphan*/, struct sched_param *);
int /*<<< orphan*/ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                                      struct sched_param *);
int /*<<< orphan*/ stdout;
void setscheduler(void) {
  struct sched_param sched_param;
  if (sched_getparam(0, &sched_param) < 0) {
    printf("Scheduler getparam failed...\n");
    return;
  }
  sched_param.sched_priority = sched_get_priority_max(SCHED_RR);
  if (!sched_setscheduler(0, SCHED_RR, &sched_param)) {
    printf("Scheduler set to Round Robin with priority %i...\n",
           sched_param.sched_priority);
    fflush(stdout);
    return;
  }
  printf("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n",
         sched_param.sched_priority);
}


x86 assembly (clang, -O0):
<setscheduler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1040 <sched_getparam@plt>
cmp    $0x0,%rax
jge    1180 <setscheduler+0x30>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e3 <setscheduler+0x93>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1070 <sched_get_priority_max@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1050 <sched_setscheduler@plt>
cmp    $0x0,%eax
jne    11d2 <setscheduler+0x82>
mov    -0x8(%rbp),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    11e3 <setscheduler+0x93>
mov    -0x8(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setscheduler>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1050 <sched_getparam@plt>
test   %rax,%rax
js     11ae <setscheduler+0x4e>
mov    0x2e53(%rip),%rbx
mov    (%rbx),%edi
call   1080 <sched_get_priority_max@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1060 <sched_setscheduler@plt>
mov    0x8(%rsp),%esi
test   %eax,%eax
je     11bc <setscheduler+0x5c>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d8 <setscheduler+0x78>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
jmp    11d8 <setscheduler+0x78>
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [30 x i8] c"Scheduler getparam failed...\0A\00"
@SCHED_RR = global i32 0
@.str.1 = [50 x i8] c"Scheduler set to Round Robin with priority %i...\0A\00"
@stdout = global i32 0
@.str.2 = [60 x i8] c"!!!Scheduler set to Round Robin with priority %i FAILED!!!\0A\00"
define void @setscheduler() {
%1 = alloca %struct.sched_param
%2 = call i64 @sched_getparam(i32 0, %struct.sched_param* %1)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %23
6: ; preds = %0
%7 = load i32, i32* @SCHED_RR
%8 = call i32 @sched_get_priority_max(i32 %7)
%9 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* @SCHED_RR
%11 = call i32 @sched_setscheduler(i32 0, i32 %10, %struct.sched_param* %1)
%12 = icmp ne i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %6
%14 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
br label %23
19: ; preds = %6
%20 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %13, %4
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str.1 = [50 x i8] c"Scheduler set to Round Robin with priority %i...\0A\00"
@stdout = global i32 0
@.str.2 = [60 x i8] c"!!!Scheduler set to Round Robin with priority %i FAILED!!!\0A\00"
@str = [29 x i8] c"Scheduler getparam failed...\00"
define void @setscheduler() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = call i64 @sched_getparam(i32 0, %struct.sched_param* %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %21
7: ; preds = %0
%8 = load i32, i32* @SCHED_RR
%9 = call i32 @sched_get_priority_max(i32 %8)
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @SCHED_RR
%12 = call i32 @sched_setscheduler(i32 0, i32 %11, %struct.sched_param* %1)
%13 = icmp eq i32 %12, 0
%14 = load i32, i32* %10
br i1 %13, label %15, label %19
15: ; preds = %7
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
br label %21
19: ; preds = %7
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %21
21: ; preds = %19, %15, %5
ret void
}