#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 {
  void *sched_priority;
};
typedef int /*<<< orphan*/ schp;

/* Variables and functions */
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
void *sched_get_priority_max(int /*<<< orphan*/);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param *);
int set_realtime_priority(int max) {
  struct sched_param schp;
  memset(&schp, 0, sizeof(schp));
  if (max)
    schp.sched_priority = sched_get_priority_max(SCHED_FIFO);
  else
    schp.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
  if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<set_realtime_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
cmpl   $0x0,-0x8(%rbp)
je     116c <set_realtime_priority+0x3c>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_max@plt>
mov    %rax,-0x10(%rbp)
jmp    1182 <set_realtime_priority+0x52>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_max@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     11ac <set_realtime_priority+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <set_realtime_priority+0x83>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_realtime_priority>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e92(%rip),%r15
mov    (%r15),%edi
call   1050 <sched_get_priority_max@plt>
cmp    $0x1,%ebx
sbb    $0x0,%rax
mov    %rax,0x8(%rsp)
mov    (%r15),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <sched_setscheduler@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sched_param = type { i8* }
@SCHED_FIFO = global i32 0
define i32 @set_realtime_priority(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sched_param
store i32 %0, i32* %3
%5 = call i32 @memset(%struct.sched_param* %4, i32 0, i32 8)
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @SCHED_FIFO
%10 = call i8* @sched_get_priority_max(i32 %9)
%11 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i8* %10, i8** %11
br label %17
12: ; preds = %1
%13 = load i32, i32* @SCHED_FIFO
%14 = call i8* @sched_get_priority_max(i32 %13)
%15 = getelementptr i8, i8* %14, i64 -1
%16 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i8* %15, i8** %16
br label %17
17: ; preds = %12, %8
%18 = load i32, i32* @SCHED_FIFO
%19 = call i64 @sched_setscheduler(i32 0, i32 %18, %struct.sched_param* %4)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 0, i32* %2
br label %23
22: ; preds = %17
store i32 1, i32* %2
br label %23
23: ; preds = %22, %21
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.sched_param = type { i8* }
@SCHED_FIFO = global i32 0
define i32 @set_realtime_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 8)
%5 = icmp eq i32 %0, 0
%6 = load i32, i32* @SCHED_FIFO
%7 = call i8* @sched_get_priority_max(i32 %6)
%8 = sext i1 %5 to i64
%9 = getelementptr i8, i8* %7, i64 %8
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i8* %9, i8** %10
%11 = load i32, i32* @SCHED_FIFO
%12 = call i64 @sched_setscheduler(i32 0, i32 %11, %struct.sched_param* %2)
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
ret i32 %14
}