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

/* Variables and functions */
scalar_t__ EPERM;
int /*<<< orphan*/ SCHED_FIFO;
scalar_t__ errno;
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int /*<<< orphan*/ terminal_error(char *);
void set_fifo(int prio) {
  struct sched_param sp;
  memset(&sp, 0, sizeof(sp));
  sp.sched_priority = prio;
  if (sched_setscheduler(0, SCHED_FIFO, &sp) == -1) {
    if (errno != EPERM)
      terminal_error("sched_setscheduler");
  }
}


x86 assembly (clang, -O0):
<set_fifo>:
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,-0x8(%rbp)
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    1199 <set_fifo+0x69>
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%rax
je     1194 <set_fifo+0x64>
lea    0xe71(%rip),%rdi
call   1050 <terminal_error@plt>
jmp    1199 <set_fifo+0x69>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_fifo>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %ebx,(%rsp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    1185 <set_fifo+0x55>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
je     1185 <set_fifo+0x55>
lea    0xe80(%rip),%rdi
call   1050 <terminal_error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@.str = [19 x i8] c"sched_setscheduler\00"
define void @set_fifo(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 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* @SCHED_FIFO
%8 = call i32 @sched_setscheduler(i32 0, i32 %7, %struct.sched_param* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = load i64, i64* @EPERM
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @terminal_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
br label %17
17: ; preds = %16, %1
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@.str = [19 x i8] c"sched_setscheduler\00"
define void @set_fifo(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 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %0, i32* %5
%6 = load i32, i32* @SCHED_FIFO
%7 = call i32 @sched_setscheduler(i32 0, i32 %6, %struct.sched_param* %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @EPERM
%12 = icmp eq i64 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @terminal_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %9, %13, %1
ret void
}