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

/* Variables and functions */
int SCHED_RR;
int /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
int /*<<< orphan*/ die_perror(char *);
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int sched_get_priority_min(int);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int, struct sched_param *);
int sysconf(int /*<<< orphan*/);
void set_scheduling_priority(void) {
  int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
  if (num_cpus < 0)
    die_perror("sysconf(_SC_NPROCESSORS_ONLN)");
  if (num_cpus <= 1)
    return;
  int policy = SCHED_RR;
  int priority = sched_get_priority_min(policy);
  if (priority < 0)
    die_perror("sched_get_priority_min");
  struct sched_param param;
  memset(&param, 0, sizeof(param));
  param.sched_priority = priority;
  if (sched_setscheduler(0, policy, &param))
    die_perror("sched_setscheduler");
}


x86 assembly (clang, -O0):
<set_scheduling_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    117f <set_scheduling_priority+0x2f>
lea    0xe86(%rip),%rdi
call   1060 <die_perror@plt>
cmpl   $0x1,-0x4(%rbp)
jg     118e <set_scheduling_priority+0x3e>
jmp    11f5 <set_scheduling_priority+0xa5>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <sched_get_priority_min@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11bb <set_scheduling_priority+0x6b>
lea    0xe68(%rip),%rdi
call   1060 <die_perror@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     11f5 <set_scheduling_priority+0xa5>
lea    0xe45(%rip),%rdi
call   1060 <die_perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_scheduling_priority>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
test   %eax,%eax
js     11cf <set_scheduling_priority+0x7f>
cmp    $0x2,%eax
jb     11c6 <set_scheduling_priority+0x76>
mov    0x2e5a(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1050 <sched_get_priority_min@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1191 <set_scheduling_priority+0x41>
lea    0xe92(%rip),%rdi
call   1060 <die_perror@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %ebp,0x8(%rsp)
xor    %edi,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <sched_setscheduler@plt>
test   %rax,%rax
je     11c6 <set_scheduling_priority+0x76>
lea    0xe74(%rip),%rdi
call   1060 <die_perror@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe2a(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <die_perror@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@_SC_NPROCESSORS_ONLN = global i32 0
@.str = [30 x i8] c"sysconf(_SC_NPROCESSORS_ONLN)\00"
@SCHED_RR = global i32 0
@.str.1 = [23 x i8] c"sched_get_priority_min\00"
@.str.2 = [19 x i8] c"sched_setscheduler\00"
define void @set_scheduling_priority() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sched_param
%5 = load i32, i32* @_SC_NPROCESSORS_ONLN
%6 = call i32 @sysconf(i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @die_perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = load i32, i32* %1
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %11
br label %32
15: ; preds = %11
%16 = load i32, i32* @SCHED_RR
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = call i32 @sched_get_priority_min(i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @die_perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
%24 = call i32 @memset(%struct.sched_param* %4, i32 0, i32 4)
%25 = load i32, i32* %3
%26 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* %2
%28 = call i64 @sched_setscheduler(i32 0, i32 %27, %struct.sched_param* %4)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @die_perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %14, %30, %23
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@_SC_NPROCESSORS_ONLN = global i32 0
@.str = [30 x i8] c"sysconf(_SC_NPROCESSORS_ONLN)\00"
@SCHED_RR = global i32 0
@.str.1 = [23 x i8] c"sched_get_priority_min\00"
@.str.2 = [19 x i8] c"sched_setscheduler\00"
define void @set_scheduling_priority() {
%1 = alloca %struct.sched_param
%2 = load i32, i32* @_SC_NPROCESSORS_ONLN
%3 = tail call i32 @sysconf(i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @die_perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %24
7: ; preds = %0
%8 = icmp ult i32 %3, 2
br i1 %8, label %24, label %9
9: ; preds = %7
%10 = load i32, i32* @SCHED_RR
%11 = tail call i32 @sched_get_priority_min(i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @die_perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = bitcast %struct.sched_param* %1 to i8*
%17 = call i32 @memset(%struct.sched_param* %1, i32 0, i32 4)
%18 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %11, i32* %18
%19 = call i64 @sched_setscheduler(i32 0, i32 %10, %struct.sched_param* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = call i32 @die_perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
br label %24
24: ; preds = %5, %7, %23
ret void
}