#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;
};

/* Variables and functions */
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int /*<<< orphan*/ stderr;
int hubo_rt_prioritize(int priority) {
  if (priority >= 50) {
    fprintf(stderr,
            "You requested an unreasonably high priority of %d\n"
            " -- The maximum you should use is 49\n"
            " -- Most real-time applications should be from 30 - 40\n",
            priority);
    return -1;
  }
  if (priority >= 0) {
    struct sched_param param;
    param.sched_priority = priority;
    if (sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
      fprintf(stderr,
              "Failed to set the scheduling for real-time prioritization!\n");
      return -2;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<hubo_rt_prioritize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x32,-0x8(%rbp)
jl     115b <hubo_rt_prioritize+0x3b>
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <hubo_rt_prioritize+0x97>
cmpl   $0x0,-0x8(%rbp)
jl     11b0 <hubo_rt_prioritize+0x90>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    11ab <hubo_rt_prioritize+0x8b>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xef7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b7 <hubo_rt_prioritize+0x97>
jmp    11b0 <hubo_rt_prioritize+0x90>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hubo_rt_prioritize>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%edx
cmp    $0x32,%edi
jl     114a <hubo_rt_prioritize+0x2a>
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    118d <hubo_rt_prioritize+0x6d>
mov    $0x1,%ebx
test   %edx,%edx
js     118d <hubo_rt_prioritize+0x6d>
mov    %edx,0x8(%rsp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    118d <hubo_rt_prioritize+0x6d>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xf0e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [143 x i8] c"You requested an unreasonably high priority of %d\0A -- The maximum you should use is 49\0A -- Most real-time applications should be from 30 - 40\0A\00"
@SCHED_FIFO = global i32 0
@.str.1 = [60 x i8] c"Failed to set the scheduling for real-time prioritization!\0A\00"
define i32 @hubo_rt_prioritize(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sched_param
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 50
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* %3
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 -1, i32* %2
br label %25
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i32, i32* %3
%16 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @SCHED_FIFO
%18 = call i32 @sched_setscheduler(i32 0, i32 %17, %struct.sched_param* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %2
br label %25
23: ; preds = %14
br label %24
24: ; preds = %23, %11
store i32 1, i32* %2
br label %25
25: ; preds = %24, %20, %7
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [143 x i8] c"You requested an unreasonably high priority of %d\0A -- The maximum you should use is 49\0A -- Most real-time applications should be from 30 - 40\0A\00"
@SCHED_FIFO = global i32 0
@.str.1 = [60 x i8] c"Failed to set the scheduling for real-time prioritization!\0A\00"
define i32 @hubo_rt_prioritize(i32 %0) {
%2 = alloca %struct.sched_param
%3 = icmp sgt i32 %0, 49
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %19
7: ; preds = %1
%8 = icmp sgt i32 %0, -1
br i1 %8, label %9, label %19
9: ; preds = %7
%10 = bitcast %struct.sched_param* %2 to i8*
%11 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %0, i32* %11
%12 = load i32, i32* @SCHED_FIFO
%13 = call i32 @sched_setscheduler(i32 0, i32 %12, %struct.sched_param* %2)
%14 = icmp eq i32 %13, -1
br i1 %14, label %16, label %15
15: ; preds = %9
br label %19
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %7, %15, %16, %4
%20 = phi i32 [ -1, %4 ], [ -2, %16 ], [ 1, %15 ], [ 1, %7 ]
ret i32 %20
}