#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ perror(char *);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param const *);
int pt_setup_sched_prio(int priority) {
  if (priority) {
    const struct sched_param parm = {.sched_priority = priority};
    if (sched_setscheduler(getpid(), SCHED_FIFO, &parm)) {
      perror("Failed set scheduling policy");
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<pt_setup_sched_prio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1192 <pt_setup_sched_prio+0x62>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     118d <pt_setup_sched_prio+0x5d>
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119e <pt_setup_sched_prio+0x6e>
jmp    1192 <pt_setup_sched_prio+0x62>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pt_setup_sched_prio>:
push   %rax
test   %edi,%edi
je     1157 <pt_setup_sched_prio+0x27>
mov    %edi,(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1040 <sched_setscheduler@plt>
test   %rax,%rax
jne    1162 <pt_setup_sched_prio+0x32>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe97(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e63(%rip),%rax
jmp    115e <pt_setup_sched_prio+0x2e>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [29 x i8] c"Failed set scheduling policy\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @pt_setup_sched_prio(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 ne i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i32 0, i32 0
%9 = load i32, i32* %3
store i32 %9, i32* %8
%10 = call i32 (...) @getpid()
%11 = load i32, i32* @SCHED_FIFO
%12 = call i64 @sched_setscheduler(i32 %10, i32 %11, %struct.sched_param* %4)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %2
br label %20
17: ; preds = %7
br label %18
18: ; preds = %17, %1
%19 = load i32, i32* @EXIT_SUCCESS
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [29 x i8] c"Failed set scheduling policy\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @pt_setup_sched_prio(i32 %0) {
%2 = alloca %struct.sched_param
%3 = icmp eq i32 %0, 0
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = bitcast %struct.sched_param* %2 to i8*
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %0, i32* %6
%7 = tail call i32 (...) @getpid()
%8 = load i32, i32* @SCHED_FIFO
%9 = call i64 @sched_setscheduler(i32 %7, i32 %8, %struct.sched_param* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %4
br label %15
12: ; preds = %4
%13 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
br label %17
15: ; preds = %11, %1
%16 = load i32, i32* @EXIT_SUCCESS
br label %17
17: ; preds = %12, %15
%18 = phi i32 [ %14, %12 ], [ %16, %15 ]
ret i32 %18
}