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

/* Variables and functions */
int SCHED_OTHER;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int sched_get_priority_max(int);
int /*<<< orphan*/ sched_setscheduler(int /*<<< orphan*/, int,
                                      struct sched_param *);
void set_priority(void) {
  int max;
  struct sched_param param;
  int sched;
  sched = SCHED_OTHER;
  if ((max = sched_get_priority_max(sched)) < 0)
    return;
  (void)memset(&param, 0, sizeof(param));
  param.sched_priority = max;
  (void)sched_setscheduler(getpid(), sched, &param);
}


x86 assembly (clang, -O0):
<set_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <sched_get_priority_max@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    116d <set_priority+0x2d>
jmp    1198 <set_priority+0x58>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
lea    -0x8(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_priority>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1060 <sched_get_priority_max@plt>
test   %eax,%eax
js     1189 <set_priority+0x49>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %ebp,0x8(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1040 <sched_setscheduler@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_OTHER = global i32 0
define void @set_priority() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = load i32, i32* @SCHED_OTHER
%4 = tail call i32 @sched_get_priority_max(i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = call i32 @memset(%struct.sched_param* %1, i32 0, i32 4)
%8 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %4, i32* %8
%9 = call i32 (...) @getpid()
%10 = call i32 @sched_setscheduler(i32 %9, i32 %3, %struct.sched_param* %1)
br label %11
11: ; preds = %0, %6
ret void
}