#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 {
  scalar_t__ sched_priority;
};

/* Variables and functions */
int MCL_CURRENT;
int MCL_FUTURE;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ exit(int);
scalar_t__ mlockall(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sched_get_priority_max(int /*<<< orphan*/);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param *);
void realtimize(void) {
  struct sched_param prm;
  if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) {
    perror("mlockall");
    exit(1);
  }
  prm.sched_priority = sched_get_priority_max(SCHED_FIFO);
  if (prm.sched_priority < 0) {
    perror("sched_get_priority_max SCHED_FIFO");
    exit(1);
  }
  if (sched_setscheduler(0, SCHED_FIFO, &prm) < 0) {
    perror("sched_setscheduler SCHED_FIFO");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<realtimize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
or     (%rax),%edi
call   1040 <mlockall@plt>
cmp    $0x0,%rax
jge    118f <realtimize+0x3f>
lea    0xe80(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <sched_get_priority_max@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    11c2 <realtimize+0x72>
lea    0xe56(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0x0,%rax
jge    11f6 <realtimize+0xa6>
lea    0xe44(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realtimize>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e74(%rip),%rax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   1040 <mlockall@plt>
test   %rax,%rax
js     11a2 <realtimize+0x52>
mov    0x2e68(%rip),%rbx
mov    (%rbx),%edi
call   1070 <sched_get_priority_max@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
js     11ab <realtimize+0x5b>
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
test   %rax,%rax
js     11b4 <realtimize+0x64>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe57(%rip),%rdi
jmp    11bb <realtimize+0x6b>
lea    0xe57(%rip),%rdi
jmp    11bb <realtimize+0x6b>
lea    0xe70(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i64 }
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str = [9 x i8] c"mlockall\00"
@SCHED_FIFO = global i32 0
@.str.1 = [34 x i8] c"sched_get_priority_max SCHED_FIFO\00"
@.str.2 = [30 x i8] c"sched_setscheduler SCHED_FIFO\00"
define void @realtimize() {
%1 = alloca %struct.sched_param
%2 = load i32, i32* @MCL_CURRENT
%3 = load i32, i32* @MCL_FUTURE
%4 = or i32 %2, %3
%5 = call i64 @mlockall(i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @SCHED_FIFO
%12 = call i64 @sched_get_priority_max(i32 %11)
%13 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
store i64 %12, i64* %13
%14 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
%15 = load i64, i64* %14
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = load i32, i32* @SCHED_FIFO
%22 = call i64 @sched_setscheduler(i32 0, i32 %21, %struct.sched_param* %1)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i64 }
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str = [9 x i8] c"mlockall\00"
@SCHED_FIFO = global i32 0
@.str.1 = [34 x i8] c"sched_get_priority_max SCHED_FIFO\00"
@.str.2 = [30 x i8] c"sched_setscheduler SCHED_FIFO\00"
define void @realtimize() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = load i32, i32* @MCL_CURRENT
%4 = load i32, i32* @MCL_FUTURE
%5 = or i32 %4, %3
%6 = tail call i64 @mlockall(i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @SCHED_FIFO
%13 = tail call i64 @sched_get_priority_max(i32 %12)
%14 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i64 %13, i64* %14
%15 = icmp slt i64 %13, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = load i32, i32* @SCHED_FIFO
%21 = call i64 @sched_setscheduler(i32 0, i32 %20, %struct.sched_param* %1)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
ret void
}