#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 {
  unsigned int sched_priority;
};
typedef int /*<<< orphan*/ sched_param;
typedef int /*<<< orphan*/ pthread_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
int pthread_setschedparam(int /*<<< orphan*/, unsigned int,
                          struct sched_param *);
int set_priority(pthread_t pid, unsigned policy, unsigned prio) {
  struct sched_param sched_param;
  memset(&sched_param, 0, sizeof(sched_param));
  sched_param.sched_priority = prio;
  if (pthread_setschedparam(pid, policy, &sched_param) == -1) {
    printf("Can't set policy to %d and prio to %d\n", policy, prio);
    exit(2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   1030 <pthread_setschedparam@plt>
cmp    $0xffffffff,%eax
jne    119b <set_priority+0x5b>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_priority>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %r14d,(%rsp)
mov    %ebx,%edi
mov    %r15d,%esi
mov    %rbp,%rdx
call   1030 <pthread_setschedparam@plt>
cmp    $0xffffffff,%eax
je     1184 <set_priority+0x44>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe75(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1040 <printf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [39 x i8] c"Can't set policy to %d and prio to %d\0A\00"
define i32 @set_priority(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sched_param
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = call i32 @memset(%struct.sched_param* %7, i32 0, i32 4)
%9 = load i32, i32* %6
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %7, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = call i32 @pthread_setschedparam(i32 %11, i32 %12, %struct.sched_param* %7)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %3
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [39 x i8] c"Can't set policy to %d and prio to %d\0A\00"
define i32 @set_priority(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sched_param
%5 = bitcast %struct.sched_param* %4 to i8*
%6 = call i32 @memset(%struct.sched_param* %4, i32 0, i32 4)
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i64 0, i32 0
store i32 %2, i32* %7
%8 = call i32 @pthread_setschedparam(i32 %0, i32 %1, %struct.sched_param* %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%12 = call i32 @exit(i32 2)
unreachable
13: ; preds = %3
ret i32 0
}