#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 SCHED_FIFO;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_self();
scalar_t__ pthread_setschedparam(int /*<<< orphan*/, int, struct sched_param *);
int set_priority(int priority) {
  int policy = SCHED_FIFO;
  struct sched_param param;
  param.sched_priority = priority;
  if (0 != pthread_setschedparam(pthread_self(), policy, &param)) {
    printf("pthread_setschedparam failed: %m\n");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<set_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   1030 <pthread_setschedparam@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1188 <set_priority+0x58>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <set_priority+0x5f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_priority>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rax
mov    (%rax),%ebx
mov    %edi,0x8(%rsp)
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    %ebx,%esi
call   1030 <pthread_setschedparam@plt>
test   %rax,%rax
je     116f <set_priority+0x3f>
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    1174 <set_priority+0x44>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [34 x i8] c"pthread_setschedparam failed: %m\0A\00"
define i32 @set_priority(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sched_param
store i32 %0, i32* %3
%6 = load i32, i32* @SCHED_FIFO
store i32 %6, i32* %4
%7 = load i32, i32* %3
%8 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %5, i32 0, i32 0
store i32 %7, i32* %8
%9 = call i32 (...) @pthread_self()
%10 = load i32, i32* %4
%11 = call i64 @pthread_setschedparam(i32 %9, i32 %10, %struct.sched_param* %5)
%12 = icmp ne i64 0, %11
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %16
15: ; preds = %1
store i32 1, i32* %2
br label %16
16: ; preds = %15, %13
%17 = load i32, i32* %2
ret i32 %17
}

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