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

/* Variables and functions */
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sched_get_priority_max(int /*<<< orphan*/);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int /*<<< orphan*/ stderr;
int set_max_priority(void) {
  struct sched_param sched;
  memset(&sched, 0, sizeof(sched));
  sched.sched_priority = sched_get_priority_max(SCHED_FIFO);
  if (-1 == sched_setscheduler(0, SCHED_FIFO, &sched)) {
    fprintf(stderr, "Unable to set SCHED_FIFO priority to the thread\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_max_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1060 <sched_get_priority_max@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ad <set_max_priority+0x6d>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <set_max_priority+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_max_priority>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e83(%rip),%rbx
mov    (%rbx),%edi
call   1060 <sched_get_priority_max@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    119b <set_max_priority+0x5b>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Unable to set SCHED_FIFO priority to the thread\0A\00"
define i32 @set_max_priority() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = call i32 @memset(%struct.sched_param* %2, i32 0, i32 4)
%4 = load i32, i32* @SCHED_FIFO
%5 = call i32 @sched_get_priority_max(i32 %4)
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* @SCHED_FIFO
%8 = call i32 @sched_setscheduler(i32 0, i32 %7, %struct.sched_param* %2)
%9 = icmp eq i32 -1, %8
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %14
13: ; preds = %0
store i32 0, i32* %1
br label %14
14: ; preds = %13, %10
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Unable to set SCHED_FIFO priority to the thread\0A\00"
define i32 @set_max_priority() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = call i32 @memset(%struct.sched_param* %1, i32 0, i32 4)
%4 = load i32, i32* @SCHED_FIFO
%5 = call i32 @sched_get_priority_max(i32 %4)
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* @SCHED_FIFO
%8 = call i32 @sched_setscheduler(i32 0, i32 %7, %struct.sched_param* %1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %0, %10
%14 = phi i32 [ -1, %10 ], [ 0, %0 ]
ret i32 %14
}