#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;
};
typedef int /*<<< orphan*/ param;

/* Variables and functions */
int SCHED_FIFO;
int SCHED_RR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sched_get_priority_max(int);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int, struct sched_param *);
int /*<<< orphan*/ stderr;
int set_sched(int policy, int load) {
  struct sched_param param;
  if ((policy == SCHED_RR || policy == SCHED_FIFO) &&
      (load == 0 || load > 90)) {
    fprintf(stderr,
            "\nERROR: unsuitable %d load (random or >90) selected for "
            "real-time scheduling.\n",
            load);
    return 0;
  }
  memset(&param, 0, sizeof(param));
  param.sched_priority = sched_get_priority_max(policy);
  if (sched_setscheduler(0, policy, &param) < 0)
    perror("\nWARNING: setting scheduler failed failed: operating with "
           "default.\nReason");
  return 1;
}


x86 assembly (clang, -O0):
<set_sched>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
je     1182 <set_sched+0x32>
mov    -0x8(%rbp),%eax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%eax
jne    11ba <set_sched+0x6a>
cmpl   $0x0,-0xc(%rbp)
je     1196 <set_sched+0x46>
cmpl   $0x5a,-0xc(%rbp)
jle    11ba <set_sched+0x6a>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1200 <set_sched+0xb0>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
call   1070 <sched_get_priority_max@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0x0,%rax
jge    11f9 <set_sched+0xa9>
lea    0xe5b(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sched>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%edx
mov    %edi,%ebx
mov    0x2e69(%rip),%rax
cmp    %edi,(%rax)
je     116e <set_sched+0x1e>
mov    0x2e7e(%rip),%rax
cmp    %ebx,(%rax)
jne    1177 <set_sched+0x27>
test   %edx,%edx
je     11b7 <set_sched+0x67>
cmp    $0x5b,%edx
jge    11b7 <set_sched+0x67>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %ebx,%edi
call   1070 <sched_get_priority_max@plt>
mov    %eax,(%rsp)
xor    %edi,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <sched_setscheduler@plt>
mov    $0x1,%ebx
test   %rax,%rax
jns    11ce <set_sched+0x7e>
lea    0xe9f(%rip),%rdi
call   1060 <perror@plt>
jmp    11ce <set_sched+0x7e>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@SCHED_FIFO = global i32 0
@stderr = global i32 0
@.str = [79 x i8] c"\0AERROR: unsuitable %d load (random or >90) selected for real-time scheduling.\0A\00"
@.str.1 = [74 x i8] c"\0AWARNING: setting scheduler failed failed: operating with default.\0AReason\00"
define i32 @set_sched(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sched_param
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = load i32, i32* @SCHED_RR
%9 = icmp eq i32 %7, %8
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i32, i32* @SCHED_FIFO
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10, %2
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 90
br i1 %19, label %20, label %24
20: ; preds = %17, %14
%21 = load i32, i32* @stderr
%22 = load i32, i32* %5
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 0, i32* %3
br label %35
24: ; preds = %17, %10
%25 = call i32 @memset(%struct.sched_param* %6, i32 0, i32 4)
%26 = load i32, i32* %4
%27 = call i32 @sched_get_priority_max(i32 %26)
%28 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %6, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* %4
%30 = call i64 @sched_setscheduler(i32 0, i32 %29, %struct.sched_param* %6)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @perror(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %24
store i32 1, i32* %3
br label %35
35: ; preds = %34, %20
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@SCHED_FIFO = global i32 0
@stderr = global i32 0
@.str = [79 x i8] c"\0AERROR: unsuitable %d load (random or >90) selected for real-time scheduling.\0A\00"
@.str.1 = [74 x i8] c"\0AWARNING: setting scheduler failed failed: operating with default.\0AReason\00"
define i32 @set_sched(i32 %0, i32 %1) {
%3 = alloca %struct.sched_param
%4 = bitcast %struct.sched_param* %3 to i8*
%5 = load i32, i32* @SCHED_RR
%6 = icmp eq i32 %5, %0
%7 = load i32, i32* @SCHED_FIFO
%8 = icmp eq i32 %7, %0
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = icmp eq i32 %1, 0
%12 = icmp sgt i32 %1, 90
%13 = or i1 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %25
17: ; preds = %2, %10
%18 = call i32 @memset(%struct.sched_param* %3, i32 0, i32 4)
%19 = call i32 @sched_get_priority_max(i32 %0)
%20 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i32 %19, i32* %20
%21 = call i64 @sched_setscheduler(i32 0, i32 %0, %struct.sched_param* %3)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %17, %23, %14
%26 = phi i32 [ 0, %14 ], [ 1, %23 ], [ 1, %17 ]
ret i32 %26
}