#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 /*<<< orphan*/ perror(char *);
int sched_get_priority_max(int /*<<< orphan*/);
scalar_t__ sched_getparam(int /*<<< orphan*/, struct sched_param *);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param *);
int /*<<< orphan*/ stderr;
int raise_priority() {
  int max_pri;
  struct sched_param sp;
  fprintf(stderr, "Setting scheduler priority...\n");
  if (sched_getparam(0, &sp)) {
    perror("sched_getparam");
    return -1;
  }
  max_pri = sched_get_priority_max(SCHED_FIFO);
  sp.sched_priority = 80;
  if (sp.sched_priority > max_pri) {
    fprintf(stderr, "Invalid scheduling priority (maximum %d).\n", max_pri);
    return -1;
  }
  if (sched_setscheduler(0, SCHED_FIFO, &sp)) {
    perror("sched_setscheduler");
    fprintf(stderr, "Failed to set scheduler. Run as root otherwise you "
                    "may get wow and skips!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<raise_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1030 <sched_getparam@plt>
cmp    $0x0,%rax
je     119c <raise_priority+0x4c>
lea    0xe94(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <raise_priority+0xde>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <sched_get_priority_max@plt>
mov    %eax,-0x8(%rbp)
movl   $0x50,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11e6 <raise_priority+0x96>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <raise_priority+0xde>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     1227 <raise_priority+0xd7>
lea    0xe4e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raise_priority>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%r14
mov    (%r14),%edi
lea    0xe9b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rsp,%rsi
xor    %edi,%edi
call   1030 <sched_getparam@plt>
test   %rax,%rax
jne    11cc <raise_priority+0x7c>
mov    0x2e66(%rip),%rbx
mov    (%rbx),%edi
call   1070 <sched_get_priority_max@plt>
movl   $0x50,(%rsp)
cmp    $0x4f,%eax
jg     11af <raise_priority+0x5f>
mov    (%r14),%edi
lea    0xe8f(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    11c2 <raise_priority+0x72>
mov    (%rbx),%esi
xor    %ebx,%ebx
mov    %rsp,%rdx
xor    %edi,%edi
call   1040 <sched_setscheduler@plt>
test   %rax,%rax
jne    11df <raise_priority+0x8f>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4c(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11c2 <raise_priority+0x72>
lea    0xe73(%rip),%rdi
call   1060 <perror@plt>
mov    (%r14),%edi
lea    0xe77(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11c2 <raise_priority+0x72>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Setting scheduler priority...\0A\00"
@.str.1 = [15 x i8] c"sched_getparam\00"
@SCHED_FIFO = global i32 0
@.str.2 = [43 x i8] c"Invalid scheduling priority (maximum %d).\0A\00"
@.str.3 = [19 x i8] c"sched_setscheduler\00"
@.str.4 = [75 x i8] c"Failed to set scheduler. Run as root otherwise you may get wow and skips!\0A\00"
define i32 @raise_priority() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sched_param
%4 = load i32, i32* @stderr
%5 = call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @sched_getparam(i32 0, %struct.sched_param* %3)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
10: ; preds = %0
%11 = load i32, i32* @SCHED_FIFO
%12 = call i32 @sched_get_priority_max(i32 %11)
store i32 %12, i32* %2
%13 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 80, i32* %13
%14 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* %2
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = load i32, i32* %2
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 -1, i32* %1
br label %31
22: ; preds = %10
%23 = load i32, i32* @SCHED_FIFO
%24 = call i64 @sched_setscheduler(i32 0, i32 %23, %struct.sched_param* %3)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %26, %22
store i32 0, i32* %1
br label %31
31: ; preds = %30, %18, %8
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Setting scheduler priority...\0A\00"
@.str.1 = [15 x i8] c"sched_getparam\00"
@SCHED_FIFO = global i32 0
@.str.2 = [43 x i8] c"Invalid scheduling priority (maximum %d).\0A\00"
@.str.3 = [19 x i8] c"sched_setscheduler\00"
@.str.4 = [75 x i8] c"Failed to set scheduler. Run as root otherwise you may get wow and skips!\0A\00"
define i32 @raise_priority() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @sched_getparam(i32 0, %struct.sched_param* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %25
9: ; preds = %0
%10 = load i32, i32* @SCHED_FIFO
%11 = call i32 @sched_get_priority_max(i32 %10)
%12 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 80, i32* %12
%13 = icmp slt i32 %11, 80
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %25
17: ; preds = %9
%18 = load i32, i32* @SCHED_FIFO
%19 = call i64 @sched_setscheduler(i32 0, i32 %18, %struct.sched_param* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %17, %21, %14, %7
%26 = phi i32 [ -1, %7 ], [ -1, %14 ], [ 0, %21 ], [ 0, %17 ]
ret i32 %26
}