#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 /*<<< orphan*/ __sched_priority;
};

/* Variables and functions */
int /*<<< orphan*/ SCHED_RR;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sched_get_priority_max(int /*<<< orphan*/);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
void scheduler_realtime() {
  struct sched_param p;
  p.__sched_priority = sched_get_priority_max(SCHED_RR);
  if (sched_setscheduler(0, SCHED_RR, &p) == -1) {
    perror("Failed to switch to realtime scheduler.");
  }
}


x86 assembly (clang, -O0):
<scheduler_realtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_max@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    1172 <scheduler_realtime+0x42>
lea    0xe93(%rip),%rdi
call   1040 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scheduler_realtime>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rbx
mov    (%rbx),%edi
call   1050 <sched_get_priority_max@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
je     1160 <scheduler_realtime+0x30>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
jmp    115a <scheduler_realtime+0x2a>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [40 x i8] c"Failed to switch to realtime scheduler.\00"
define void @scheduler_realtime() {
%1 = alloca %struct.sched_param
%2 = load i32, i32* @SCHED_RR
%3 = call i32 @sched_get_priority_max(i32 %2)
%4 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
store i32 %3, i32* %4
%5 = load i32, i32* @SCHED_RR
%6 = call i32 @sched_setscheduler(i32 0, i32 %5, %struct.sched_param* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str = [40 x i8] c"Failed to switch to realtime scheduler.\00"
define void @scheduler_realtime() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = load i32, i32* @SCHED_RR
%4 = tail call i32 @sched_get_priority_max(i32 %3)
%5 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %4, i32* %5
%6 = load i32, i32* @SCHED_RR
%7 = call i32 @sched_setscheduler(i32 0, i32 %6, %struct.sched_param* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
ret void
}