#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 nice(int);
int /*<<< orphan*/ perror(char *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
void set_priority(int priority) {
  struct sched_param p;
  int ret;
  switch (priority) {
  case 1:
    p.sched_priority = 1;
    ret = sched_setscheduler(0, SCHED_FIFO, &p);
    if (ret == -1)
      perror("FAIL: sched_setscheduler");
    break;
  case 2:
    ret = nice(-20);
    if (ret == -1)
      perror("FAIL: nice");
    break;
  case 0:
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<set_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     11d1 <set_priority+0xa1>
jmp    114e <set_priority+0x1e>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     1170 <set_priority+0x40>
jmp    115f <set_priority+0x2f>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     11a9 <set_priority+0x79>
jmp    11d6 <set_priority+0xa6>
movl   $0x1,-0x8(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a4 <set_priority+0x74>
lea    0xe61(%rip),%rdi
call   1050 <perror@plt>
jmp    11db <set_priority+0xab>
mov    $0xffffffec,%edi
call   1040 <nice@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11cc <set_priority+0x9c>
lea    0xe52(%rip),%rdi
call   1050 <perror@plt>
jmp    11db <set_priority+0xab>
jmp    11d6 <set_priority+0xa6>
jmp    11db <set_priority+0xab>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_priority>:
push   %rax
cmp    $0x2,%edi
je     1168 <set_priority+0x38>
cmp    $0x1,%edi
jne    1177 <set_priority+0x47>
movl   $0x1,(%rsp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    1177 <set_priority+0x47>
lea    0xe9f(%rip),%rdi
call   1050 <perror@plt>
pop    %rax
ret
mov    $0xffffffec,%edi
call   1040 <nice@plt>
cmp    $0xffffffff,%eax
je     1179 <set_priority+0x49>
pop    %rax
ret
lea    0xe99(%rip),%rdi
pop    %rax
jmp    1050 <perror@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [25 x i8] c"FAIL: sched_setscheduler\00"
@.str.1 = [11 x i8] c"FAIL: nice\00"
define void @set_priority(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sched_param
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
switch i32 %5, label %23 [
i32 1, label %6
i32 2, label %15
i32 0, label %22
]
6: ; preds = %1
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 1, i32* %7
%8 = load i32, i32* @SCHED_FIFO
%9 = call i32 @sched_setscheduler(i32 0, i32 %8, %struct.sched_param* %3)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %6
br label %24
15: ; preds = %1
%16 = call i32 @nice(i32 -20)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
br label %24
22: ; preds = %1
br label %23
23: ; preds = %1, %22
br label %24
24: ; preds = %23, %21, %14
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [25 x i8] c"FAIL: sched_setscheduler\00"
@.str.1 = [11 x i8] c"FAIL: nice\00"
define void @set_priority(i32 %0) {
%2 = alloca %struct.sched_param
%3 = bitcast %struct.sched_param* %2 to i8*
switch i32 %0, label %16 [
i32 1, label %4
i32 2, label %11
]
4: ; preds = %1
%5 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 1, 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 %16
9: ; preds = %4
%10 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %16
11: ; preds = %1
%12 = tail call i32 @nice(i32 -20)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %1, %11, %14, %4, %9
ret void
}