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

/* Variables and functions */
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int sched_get_priority_max(int /*<<< orphan*/);
int sched_get_priority_min(int /*<<< orphan*/);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int set_process_priority(int priority) {
  struct sched_param params;
  memset(&params, 0, sizeof(params));
  switch (priority) {
  case 0:
    params.sched_priority = 0;
    break;
  case 99:
    params.sched_priority = sched_get_priority_max(SCHED_FIFO);
    break;
  case 1:
    params.sched_priority = sched_get_priority_min(SCHED_FIFO);
    break;
  default:
    params.sched_priority = priority;
    break;
  }
  return sched_setscheduler(0, SCHED_FIFO, &params);
}


x86 assembly (clang, -O0):
<set_process_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
test   %eax,%eax
je     1190 <set_process_priority+0x50>
jmp    116e <set_process_priority+0x2e>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
je     11b2 <set_process_priority+0x72>
jmp    117f <set_process_priority+0x3f>
mov    -0xc(%rbp),%eax
sub    $0x63,%eax
je     119c <set_process_priority+0x5c>
jmp    11c8 <set_process_priority+0x88>
movl   $0x0,-0x8(%rbp)
jmp    11ce <set_process_priority+0x8e>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <sched_get_priority_max@plt>
mov    %eax,-0x8(%rbp)
jmp    11ce <set_process_priority+0x8e>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_min@plt>
mov    %eax,-0x8(%rbp)
jmp    11ce <set_process_priority+0x8e>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_process_priority>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
cmp    $0x63,%ebx
je     1170 <set_process_priority+0x30>
cmp    $0x1,%ebx
je     1184 <set_process_priority+0x44>
test   %ebx,%ebx
jne    1198 <set_process_priority+0x58>
movl   $0x0,0x8(%rsp)
jmp    119c <set_process_priority+0x5c>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1060 <sched_get_priority_max@plt>
mov    %eax,0x8(%rsp)
jmp    119c <set_process_priority+0x5c>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_min@plt>
mov    %eax,0x8(%rsp)
jmp    119c <set_process_priority+0x5c>
mov    %ebx,0x8(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
define i32 @set_process_priority(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sched_param
store i32 %0, i32* %2
%4 = call i32 @memset(%struct.sched_param* %3, i32 0, i32 4)
%5 = load i32, i32* %2
switch i32 %5, label %16 [
i32 0, label %6
i32 99, label %8
i32 1, label %12
]
6: ; preds = %1
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 0, i32* %7
br label %19
8: ; preds = %1
%9 = load i32, i32* @SCHED_FIFO
%10 = call i32 @sched_get_priority_max(i32 %9)
%11 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 %10, i32* %11
br label %19
12: ; preds = %1
%13 = load i32, i32* @SCHED_FIFO
%14 = call i32 @sched_get_priority_min(i32 %13)
%15 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 %14, i32* %15
br label %19
16: ; preds = %1
%17 = load i32, i32* %2
%18 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 %17, i32* %18
br label %19
19: ; preds = %16, %12, %8, %6
%20 = load i32, i32* @SCHED_FIFO
%21 = call i32 @sched_setscheduler(i32 0, i32 %20, %struct.sched_param* %3)
ret i32 %21
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
define i32 @set_process_priority(i32 %0) {
%2 = alloca %struct.sched_param
%3 = bitcast %struct.sched_param* %2 to i8*
%4 = call i32 @memset(%struct.sched_param* %2, i32 0, i32 4)
switch i32 %0, label %15 [
i32 0, label %5
i32 99, label %7
i32 1, label %11
]
5: ; preds = %1
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 0, i32* %6
br label %17
7: ; preds = %1
%8 = load i32, i32* @SCHED_FIFO
%9 = call i32 @sched_get_priority_max(i32 %8)
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %9, i32* %10
br label %17
11: ; preds = %1
%12 = load i32, i32* @SCHED_FIFO
%13 = call i32 @sched_get_priority_min(i32 %12)
%14 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %13, i32* %14
br label %17
15: ; preds = %1
%16 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %0, i32* %16
br label %17
17: ; preds = %15, %11, %7, %5
%18 = load i32, i32* @SCHED_FIFO
%19 = call i32 @sched_setscheduler(i32 0, i32 %18, %struct.sched_param* %2)
ret i32 %19
}