#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int sched_get_priority_max(int /*<<< orphan*/);
int sched_getparam(int /*<<< orphan*/, struct sched_param *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int set_max_priority() {
  struct sched_param sch_par;
  int return_val = 0;
  return_val = sched_getparam(0, &sch_par);
  if (return_val == -1) {
    perror("Error getting schedule params");
    return return_val;
  }
  printf("current priority=%i\n", sch_par.sched_priority);
  int priority = sched_get_priority_max(SCHED_FIFO);
  printf("max priority=%i\n", priority);
  if (priority != -1) {
    sch_par.sched_priority = priority;
  } else {
    perror("Error getting max priority");
    return return_val;
  }
  return_val = sched_setscheduler(0, SCHED_FIFO, &sch_par);
  if (return_val == -1) {
    perror("Error setting schedule params");
    return return_val;
  }
  return return_val;
}


x86 assembly (clang, -O0):
<set_max_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1040 <sched_getparam@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    118e <set_max_priority+0x3e>
lea    0xe82(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <set_max_priority+0xd7>
mov    -0x8(%rbp),%esi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <sched_get_priority_max@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0xffffffff,-0x10(%rbp)
je     11d2 <set_max_priority+0x82>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11e9 <set_max_priority+0x99>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <set_max_priority+0xd7>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1050 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1221 <set_max_priority+0xd1>
lea    0xe4e(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <set_max_priority+0xd7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_max_priority>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rsi
xor    %edi,%edi
call   1040 <sched_getparam@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11c1 <set_max_priority+0x71>
mov    %eax,%ebx
mov    (%rsp),%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e64(%rip),%r15
mov    (%r15),%edi
call   1070 <sched_get_priority_max@plt>
mov    %eax,%ebp
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
cmp    $0xffffffff,%ebp
je     11ca <set_max_priority+0x7a>
mov    %ebp,(%rsp)
mov    (%r15),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1050 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
je     11d6 <set_max_priority+0x86>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe38(%rip),%rdi
jmp    11dd <set_max_priority+0x8d>
lea    0xe73(%rip),%rdi
mov    %ebx,%r14d
jmp    11dd <set_max_priority+0x8d>
lea    0xe82(%rip),%rdi
call   1060 <perror@plt>
mov    %r14d,%eax
jmp    11b6 <set_max_priority+0x66>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [30 x i8] c"Error getting schedule params\00"
@.str.1 = [21 x i8] c"current priority=%i\0A\00"
@SCHED_FIFO = global i32 0
@.str.2 = [17 x i8] c"max priority=%i\0A\00"
@.str.3 = [27 x i8] c"Error getting max priority\00"
@.str.4 = [30 x i8] c"Error setting schedule params\00"
define i32 @set_max_priority() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
%5 = call i32 @sched_getparam(i32 0, %struct.sched_param* %2)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %3
store i32 %10, i32* %1
br label %37
11: ; preds = %0
%12 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @SCHED_FIFO
%16 = call i32 @sched_get_priority_max(i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* %4
%23 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
store i32 %22, i32* %23
br label %27
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* %3
store i32 %26, i32* %1
br label %37
27: ; preds = %21
%28 = load i32, i32* @SCHED_FIFO
%29 = call i32 @sched_setscheduler(i32 0, i32 %28, %struct.sched_param* %2)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* %3
store i32 %34, i32* %1
br label %37
35: ; preds = %27
%36 = load i32, i32* %3
store i32 %36, i32* %1
br label %37
37: ; preds = %35, %32, %24, %8
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [30 x i8] c"Error getting schedule params\00"
@.str.1 = [21 x i8] c"current priority=%i\0A\00"
@SCHED_FIFO = global i32 0
@.str.2 = [17 x i8] c"max priority=%i\0A\00"
@.str.3 = [27 x i8] c"Error getting max priority\00"
@.str.4 = [30 x i8] c"Error setting schedule params\00"
define i32 @set_max_priority() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = call i32 @sched_getparam(i32 0, %struct.sched_param* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @SCHED_FIFO
%10 = call i32 @sched_get_priority_max(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %10, -1
br i1 %12, label %17, label %13
13: ; preds = %5
store i32 %10, i32* %6
%14 = load i32, i32* @SCHED_FIFO
%15 = call i32 @sched_setscheduler(i32 0, i32 %14, %struct.sched_param* %1)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %13, %5, %0
%18 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), %13 ]
%19 = phi i32 [ -1, %0 ], [ %3, %5 ], [ -1, %13 ]
%20 = call i32 @perror(i8* %18)
br label %21
21: ; preds = %17, %13
%22 = phi i32 [ %15, %13 ], [ %19, %17 ]
ret i32 %22
}