#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 /*<<< orphan*/ perror(char *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int set_my_prio(int priority) {
  struct sched_param sp;
  sp.sched_priority = priority;
  if (sched_setscheduler(0, SCHED_FIFO, &sp) == -1) {
    perror("sched_setscheduler()");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_my_prio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    1166 <set_my_prio+0x46>
lea    0xeab(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    116d <set_my_prio+0x4d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_my_prio>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0x8(%rsp)
mov    0x2eb8(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
je     114d <set_my_prio+0x2d>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xeac(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1145 <set_my_prio+0x25>

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

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [21 x i8] c"sched_setscheduler()\00"
define i32 @set_my_prio(i32 %0) {
%2 = alloca %struct.sched_param
%3 = bitcast %struct.sched_param* %2 to i8*
%4 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 %0, i32* %4
%5 = load i32, i32* @SCHED_FIFO
%6 = call i32 @sched_setscheduler(i32 0, i32 %5, %struct.sched_param* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %1, %8
%11 = phi i32 [ -1, %8 ], [ 0, %1 ]
ret i32 %11
}