#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;
};
typedef int /*<<< orphan*/ sched;

/* Variables and functions */
int /*<<< orphan*/ SCHED_RR;
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int sched_get_priority_max(int /*<<< orphan*/);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int piHiPri(int pri) {
  struct sched_param sched;
  memset(&sched, 0, sizeof(sched));
  if (pri > sched_get_priority_max(SCHED_RR))
    pri = sched_get_priority_max(SCHED_RR);
  sched.sched_priority = pri;
  return sched_setscheduler(0, SCHED_RR, &sched);
}


x86 assembly (clang, -O0):
<piHiPri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_max@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
jle    117d <piHiPri+0x4d>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_max@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<piHiPri>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e8c(%rip),%r14
mov    (%r14),%edi
call   1050 <sched_get_priority_max@plt>
cmp    %ebx,%eax
jge    1162 <piHiPri+0x32>
mov    (%r14),%edi
call   1050 <sched_get_priority_max@plt>
mov    %eax,%ebx
mov    %ebx,(%rsp)
mov    (%r14),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
define i32 @piHiPri(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sched_param
store i32 %0, i32* %2
%4 = call i32 @memset(%struct.sched_param* %3, i32 0, i32 4)
%5 = load i32, i32* %2
%6 = load i32, i32* @SCHED_RR
%7 = call i32 @sched_get_priority_max(i32 %6)
%8 = icmp sgt i32 %5, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @SCHED_RR
%11 = call i32 @sched_get_priority_max(i32 %10)
store i32 %11, i32* %2
br label %12
12: ; preds = %9, %1
%13 = load i32, i32* %2
%14 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @SCHED_RR
%16 = call i32 @sched_setscheduler(i32 0, i32 %15, %struct.sched_param* %3)
ret i32 %16
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
define i32 @piHiPri(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 4)
%5 = load i32, i32* @SCHED_RR
%6 = call i32 @sched_get_priority_max(i32 %5)
%7 = icmp slt i32 %6, %0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @SCHED_RR
%10 = call i32 @sched_get_priority_max(i32 %9)
br label %11
11: ; preds = %8, %1
%12 = phi i32 [ %10, %8 ], [ %0, %1 ]
%13 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @SCHED_RR
%15 = call i32 @sched_setscheduler(i32 0, i32 %14, %struct.sched_param* %2)
ret i32 %15
}