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

/* Variables and functions */
int MCL_CURRENT;
int MCL_FUTURE;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ SCHED_OTHER;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mlockall(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param *);
void make_realtime(int priority) {
  char prefault[(8 * 1024)];
  memset(prefault, 0, sizeof(prefault));
  if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
    perror("Couldn't lock pages in memory");
  }
  struct sched_param sp;
  sp.sched_priority = priority;
  if (sched_setscheduler(0, priority ? SCHED_FIFO : SCHED_OTHER, &sp) < 0) {
    perror("Couldn't set scheduling priority");
  }
}


x86 assembly (clang, -O0):
<make_realtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
or     (%rax),%edi
call   1050 <mlockall@plt>
cmp    $0x0,%rax
je     118e <make_realtime+0x4e>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2018(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11b5 <make_realtime+0x75>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x201c(%rbp)
jmp    11c4 <make_realtime+0x84>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x201c(%rbp)
mov    -0x201c(%rbp),%esi
xor    %edi,%edi
lea    -0x2018(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0x0,%rax
jge    11ee <make_realtime+0xae>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_realtime>:
push   %rbx
sub    $0x2010,%rsp
mov    %edi,%ebx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
mov    0x2e66(%rip),%rax
mov    0x2e87(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   1050 <mlockall@plt>
test   %rax,%rax
jne    11ab <make_realtime+0x6b>
mov    %ebx,0x8(%rsp)
test   %ebx,%ebx
jne    1188 <make_realtime+0x48>
mov    0x2e4a(%rip),%rax
jmp    118f <make_realtime+0x4f>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
test   %rax,%rax
js     11b9 <make_realtime+0x79>
add    $0x2010,%rsp
pop    %rbx
ret
lea    0xe4e(%rip),%rdi
call   1060 <perror@plt>
jmp    1177 <make_realtime+0x37>
lea    0xe5e(%rip),%rdi
call   1060 <perror@plt>
jmp    11a2 <make_realtime+0x62>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str = [30 x i8] c"Couldn't lock pages in memory\00"
@SCHED_FIFO = global i32 0
@SCHED_OTHER = global i32 0
@.str.1 = [33 x i8] c"Couldn't set scheduling priority\00"
define void @make_realtime(i32 %0) {
%2 = alloca i32
%3 = alloca [8192 x i8]
%4 = alloca %struct.sched_param
store i32 %0, i32* %2
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 8192)
%7 = load i32, i32* @MCL_CURRENT
%8 = load i32, i32* @MCL_FUTURE
%9 = or i32 %7, %8
%10 = call i64 @mlockall(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i32, i32* %2
%16 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i32, i32* @SCHED_FIFO
br label %23
21: ; preds = %14
%22 = load i32, i32* @SCHED_OTHER
br label %23
23: ; preds = %21, %19
%24 = phi i32 [ %20, %19 ], [ %22, %21 ]
%25 = call i64 @sched_setscheduler(i32 0, i32 %24, %struct.sched_param* %4)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str = [30 x i8] c"Couldn't lock pages in memory\00"
@SCHED_FIFO = global i32 0
@SCHED_OTHER = global i32 0
@.str.1 = [33 x i8] c"Couldn't set scheduling priority\00"
define void @make_realtime(i32 %0) {
%2 = alloca [8192 x i8]
%3 = alloca %struct.sched_param
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 8192)
%6 = load i32, i32* @MCL_CURRENT
%7 = load i32, i32* @MCL_FUTURE
%8 = or i32 %7, %6
%9 = call i64 @mlockall(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = bitcast %struct.sched_param* %3 to i8*
%15 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i32 %0, i32* %15
%16 = icmp eq i32 %0, 0
%17 = load i32, i32* @SCHED_FIFO
%18 = load i32, i32* @SCHED_OTHER
%19 = select i1 %16, i32 %18, i32 %17
%20 = call i64 @sched_setscheduler(i32 0, i32 %19, %struct.sched_param* %3)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %13
ret void
}