#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 MCL_CURRENT;
int MCL_FUTURE;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int mlockall(int);
int /*<<< orphan*/ perror(char *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int /*<<< orphan*/ stack_prefault();
int main(int argc, char *argv[]) {
  struct sched_param param;
  param.sched_priority = (99);
  if (sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
    perror("sched_setscheduler failed");
    exit(-1);
  }
  if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
    perror("mlockall failed");
    exit(-2);
  }
  stack_prefault();
  while (1) {
    fork();
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x63,-0x18(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x50>
lea    0xe5f(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
or     (%rax),%edi
call   1050 <mlockall@plt>
cmp    $0xffffffff,%eax
jne    11e6 <main+0x86>
lea    0xe43(%rip),%rdi
call   1060 <perror@plt>
mov    $0xfffffffe,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1040 <stack_prefault@plt>
mov    $0x0,%al
call   1080 <fork@plt>
jmp    11ed <main+0x8d>

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x63,(%rsp)
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
je     11b9 <main+0x59>
mov    0x2e49(%rip),%rax
mov    0x2e62(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   1050 <mlockall@plt>
cmp    $0xffffffff,%eax
je     11cf <main+0x6f>
xor    %eax,%eax
call   1040 <stack_prefault@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1080 <fork@plt>
jmp    11b0 <main+0x50>
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe44(%rip),%rdi
call   1060 <perror@plt>
mov    $0xfffffffe,%edi
call   1070 <exit@plt>

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

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